Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

29 wrong flowtower script begins whit 115 soll 85 #37

Merged
merged 2 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 43 additions & 88 deletions AutoTowersGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,61 +313,38 @@ def _removeAutoTower(self, message = None)->None:

# Stop listening for callbacks
self._towerControllerPostProcessingCallback = None
Application.getInstance().getOutputDeviceManager().writeStarted.disconnect(self._postProcessCallback)
# BAK: 25 Nov 2022 - Removing these callbacks for now, because they're giving me trouble...
# CuraApplication.getInstance().getMachineManager().activeMachine.propertyChanged.disconnect(self._onPrintSettingChanged)
# ExtruderManager.getInstance().getActiveExtruderStack().propertiesChanged.disconnect(self._onExtruderPrintSettingChanged)
CuraApplication.getInstance().getController().getScene().getRoot().childrenChanged.disconnect(self._onSceneChanged)
try:
Application.getInstance().getOutputDeviceManager().writeStarted.disconnect(self._postProcessCallback)
except TypeError:
# Thrown if the callback wasn't connected - can be ignored
pass
try:
CuraApplication.getInstance().getMachineManager().activeMachine.propertyChanged.disconnect(self._onPrintSettingChanged)
except TypeError:
# Thrown if the callback wasn't connected - can be ignored
pass
try:
ExtruderManager.getInstance().activeExtruderChanged.disconnect(self._onActiveExtruderChanged)
except TypeError:
# Thrown if the callback wasn't connected - can be ignored
pass
try:
ExtruderManager.getInstance().getActiveExtruderStack().propertiesChanged.disconnect(self._onExtruderPrintSettingChanged)
except TypeError:
# Thrown if the callback wasn't connected - can be ignored
pass
try:
CuraApplication.getInstance().getController().getScene().getRoot().childrenChanged.disconnect(self._onSceneChanged)
except TypeError:
# Thrown if the callback wasn't connected - can be ignored
pass
try:
# Stop listening for machine changes
CuraApplication.getInstance().getMachineManager().globalContainerChanged.disconnect(self._onMachineChanged)
except TypeError as e:
# This exception is expected during Cura shutdown
pass

# Clean up after the AutoTower
if not self._currentTowerController is None:
restoredSettings = self._currentTowerController.cleanup()
if len(restoredSettings) > 0:
restoredMessage = '\n'.join([f'Restored {entry[0]} to {entry[1]}' for entry in restoredSettings])
restoredMessage = 'The following settings were restored:\n' + restoredMessage
Message(restoredMessage, title=self._pluginName).show()
self._currentTowerController = None

# Remove the Auto Tower itself
if not self._autoTowerOperation is None:
self._autoTowerOperation.undo()
self._autoTowerOperation = None
CuraApplication.getInstance().deleteAll()

# Clear the job name
CuraApplication.getInstance().getPrintInformation().setJobName('')

# Indicate that there is no longer an Auto Tower in the scene
self.autoTowerGeneratedChanged.emit()

# Display the requested message
if message != None:
Message(message, title=self._pluginName).show()

# Clean up after the AutoTower
if not self._currentTowerController is None:
restoredSettings = self._currentTowerController.cleanup()
if len(restoredSettings) > 0:
restoredMessage = message + '\n' if not message is None else ''
restoredMessage += 'The following settings were restored:\n'
restoredMessage += '\n'.join([f'Restored {entry[0]} to {entry[1]}' for entry in restoredSettings])
Message(restoredMessage, title=self._pluginName).show()
self._currentTowerController = None

CuraApplication.getInstance().processEvents()

Expand Down Expand Up @@ -398,22 +375,6 @@ def _displayPluginSettingsDialog(self)->None:



def _correctPrintSettingsForTower(self):
# Allow the tower controller to update Cura's settings to ensure it can be generated correctly
recommendedSettings = self._currentTowerController.checkPrintSettings(self.correctPrintSettings)
if len(recommendedSettings) > 0:
message = '\n'.join([f'Changed {entry[0]} from {entry[1]} to {entry[2]}' for entry in recommendedSettings])
if self.correctPrintSettings:
message = 'The following settings were changed:\n' + message
Message(message, title=self._pluginName).show()
else:
message = 'The following settings changes are recommended\n' + message
Message(message, title=self._pluginName, message_type=Message.MessageType.WARNING).show()

CuraApplication.getInstance().processEvents()



def _loadStlCallback(self, controller, towerName, stlFilePath, postProcessingCallback)->None:
''' This callback is called by the tower model controller if a preset tower is requested '''

Expand All @@ -424,39 +385,17 @@ def _loadStlCallback(self, controller, towerName, stlFilePath, postProcessingCal
Message(errorMessage, title = self._pluginName, message_type=Message.MessageType.ERROR).show()
return

# Make sure any previous auto towers are removed
self._removeAutoTower()

# Record the new tower controller
self._currentTowerController = controller

# Ensure print settings are correct
self._correctPrintSettingsForTower()

# Import the STL file into the scene
self._importStl(towerName, stlFilePath, postProcessingCallback)
self._importStl(controller, towerName, stlFilePath, postProcessingCallback)



def _generateAndLoadStlCallback(self, controller, towerName, openScadFilename, openScadParameters, postProcessingCallback)->None:
''' This callback is called by the tower model controller after a tower has been configured to generate an STL model from an OpenSCAD file '''

# Make sure any previous auto towers are removed
self._removeAutoTower()

# Record the new tower controller
self._currentTowerController = controller

# Ensure print settings are correct
self._correctPrintSettingsForTower()

# This could take up to a couple of minutes...
self._waitDialog.show()
CuraApplication.getInstance().processEvents() # Allow Cura to update itself periodically through this method

# Remove all models from the scene
CuraApplication.getInstance().deleteAll()
CuraApplication.getInstance().processEvents()

# Compile the STL file name
openScadFilePath = os.path.join(self._openScadSourcePath, openScadFilename)
Expand All @@ -483,13 +422,30 @@ def _generateAndLoadStlCallback(self, controller, towerName, openScadFilename, o
return

# Import the STL file into the scene
self._importStl(towerName, stlFilePath, postProcessingCallback)
self._importStl(controller, towerName, stlFilePath, postProcessingCallback)



def _importStl(self, towerName, stlFilePath, postProcessingCallback)->None:
def _importStl(self, controller, towerName, stlFilePath, postProcessingCallback)->None:
''' Imports an STL file into the scene '''

# Make sure any previous auto towers are removed
self._removeAutoTower()

# Allow the tower controller to update Cura's settings to ensure it can be generated correctly
recommendedSettings = controller.checkPrintSettings(self.correctPrintSettings)
if len(recommendedSettings) > 0:
message = '\n'.join([f'Changed {entry[0]} from {entry[1]} to {entry[2]}' for entry in recommendedSettings])
if self.correctPrintSettings:
message = 'The following settings were changed:\n' + message
Message(message, title=self._pluginName).show()
else:
message = 'The following setting changes are recommended\n' + message
Message(message, title=self._pluginName, message_type=Message.MessageType.WARNING).show()

# Record the new tower controller
self._currentTowerController = controller

# Import the STL file into the scene
self._autoTowerOperation = MeshImporter.ImportMesh(stlFilePath, name=self._pluginName)
CuraApplication.getInstance().processEvents()
Expand All @@ -507,16 +463,15 @@ def _importStl(self, towerName, stlFilePath, postProcessingCallback)->None:
Application.getInstance().getOutputDeviceManager().writeStarted.connect(self._postProcessCallback)
self._towerControllerPostProcessingCallback = postProcessingCallback

# Remove the model if the machine is changed
CuraApplication.getInstance().getMachineManager().globalContainerChanged.connect(self._onMachineChanged)

# BAK: 25 Nov 2022 - Removing these callbacks for now, because they're giving me trouble...
# Remove the model if critical print settings (settings that are important for the AutoTower) are changed
CuraApplication.getInstance().getMachineManager().activeMachine.propertyChanged.connect(self._onPrintSettingChanged)
# CuraApplication.getInstance().getMachineManager().activeMachine.propertyChanged.connect(self._onPrintSettingChanged)

# Remove the model if the active extruder is changed
ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderChanged)

# Remove the model if critical print settings (settings that are important for the AutoTower) are changed
ExtruderManager.getInstance().getActiveExtruderStack().propertiesChanged.connect(self._onExtruderPrintSettingChanged)
# # Remove the model if critical print settings (settings that are important for the AutoTower) are changed
# ExtruderManager.getInstance().getActiveExtruderStack().propertiesChanged.connect(self._onExtruderPrintSettingChanged)

# Remove the model if it is deleted or another model is added to the scene
CuraApplication.getInstance().getController().getScene().getRoot().childrenChanged.connect(self._onSceneChanged)
Expand All @@ -536,7 +491,7 @@ def _onPrintSettingChanged(self, settingKey, propertyName)->None:

# Remove the tower in response to changes to critical print settings
if not self._currentTowerController is None:
if settingKey in self._currentTowerController.criticalSettingsList:
if self._currentTowerController.settingIsCritical(settingKey):
settingLabel = CuraApplication.getInstance().getMachineManager().activeMachine.getProperty(settingKey, 'label')
self._removeAutoTower(f'The Auto Tower was removed because the Cura setting "{settingLabel}" has changed since the tower was generated')

Expand All @@ -554,7 +509,7 @@ def _onExtruderPrintSettingChanged(self, settingKey, propertyName)->None:

# Remove the tower in response to changes to critical print settings
if not self._currentTowerController is None:
if settingKey in self._currentTowerController.criticalSettingsList:
if self._currentTowerController.settingIsCritical(settingKey):
settingLabel = ExtruderManager.getInstance().getActiveExtruderStack().getProperty(settingKey, 'label')
self._removeAutoTower(f'The Auto Tower was removed because the Cura setting "{settingLabel}" has changed since the tower was generated')

Expand Down
14 changes: 7 additions & 7 deletions Controllers/BedLevelPatternContoller.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class BedLevelPatternController(ControllerBase):
_presetsTable = {}

_criticalPropertiesTable = {
'adaptive_layer_height_enabled': ('global', False),
'adhesion_type': ('global', 'none'),
'layer_height': ('global', None),
'line_width': ('extruder', None),
'machine_width': ('global', None),
'machine_depth': ('global', None),
'meshfix_union_all_remove_holes': ('extruder', False),
'adaptive_layer_height_enabled': (ControllerBase.ContainerId.GLOBAL_CONTAINER_STACK, False),
'adhesion_type': (ControllerBase.ContainerId.GLOBAL_CONTAINER_STACK, 'none'),
'layer_height': (ControllerBase.ContainerId.GLOBAL_CONTAINER_STACK, None),
'line_width': (ControllerBase.ContainerId.ACTIVE_EXTRUDER_STACK, None),
'machine_width': (ControllerBase.ContainerId.GLOBAL_CONTAINER_STACK, None),
'machine_depth': (ControllerBase.ContainerId.GLOBAL_CONTAINER_STACK, None),
'meshfix_union_all_remove_holes': (ControllerBase.ContainerId.ACTIVE_EXTRUDER_STACK, False),
}

_bedLevelPatternTypesModel = [
Expand Down
46 changes: 18 additions & 28 deletions Controllers/ControllerBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
except ImportError:
from PyQt5.QtCore import QObject

from enum import IntEnum

from cura.CuraApplication import CuraApplication
from cura.Settings.ExtruderManager import ExtruderManager
Expand All @@ -16,6 +17,12 @@


class ControllerBase(QObject):

class ContainerId(IntEnum):
GLOBAL_CONTAINER_STACK = 0
ACTIVE_EXTRUDER_STACK = 1



def __init__(self, name, guiPath, stlPath, loadStlCallback, generateAndLoadStlCallback, openScadFilename, qmlFilename, presetsTable, criticalSettingsTable):
super().__init__()
Expand All @@ -37,12 +44,6 @@ def __init__(self, name, guiPath, stlPath, loadStlCallback, generateAndLoadStlCa



@property
def criticalSettingsList(self)->list:
return list(self._criticalSettingsTable.keys())



@property
def presetNames(self)->list:
return list(self._presetsTable.keys())
Expand All @@ -60,8 +61,13 @@ def _dialog(self)->QObject:

return self._cachedDialog



def settingIsCritical(self, settingKey)->bool:
return settingKey in self._criticalSettingsTable.keys()



def checkPrintSettings(self, correctPrintSettings = False)->None:
''' Checks the current print settings and warns or changes them if they are not compatible with the tower '''

Expand All @@ -75,7 +81,7 @@ def checkPrintSettings(self, correctPrintSettings = False)->None:
if not recommendedValue is None:

# Get the source object for this setting
containerStack = self._getcontainerStack(containerStackDescription)
containerStack = self._getContainerStack(containerStackDescription)

# Look up the current value of the setting
currentValue = containerStack.getProperty(settingName, 'value')
Expand All @@ -102,22 +108,6 @@ def checkPrintSettings(self, correctPrintSettings = False)->None:



def _lookupStackValue(self, stack, settingName)->list:
containerList = []

# Iterate over each container in the stack
for container in stack.getContainers():

# Check if this container contains the setting
result = container.hasProperty(settingName, 'value')
if container.hasProperty(settingName, 'value'):
currentValue = container.getProperty(settingName, 'value')
containerList.append((container, currentValue))

return containerList



def generate(self, preset='')->None:
''' Generate a tower - either a preset tower or a custom tower '''
# If a preset was requested, load it
Expand Down Expand Up @@ -151,18 +141,18 @@ def cleanup(self)->tuple:



def _getcontainerStack(self, sourceDescription):
def _getContainerStack(self, sourceDescription: ContainerId):
''' Retieves and returns a property source based on a description string '''

containerStack = None

if sourceDescription == 'global':
if sourceDescription == ControllerBase.ContainerId.GLOBAL_CONTAINER_STACK:
containerStack = Application.getInstance().getGlobalContainerStack()
elif sourceDescription == 'extruder':
# BAK: Try getActiveExtruderStack()
elif sourceDescription == ControllerBase.ContainerId.ACTIVE_EXTRUDER_STACK:
containerStack = ExtruderManager.getInstance().getActiveExtruderStack()
else:
Logger.log('e', message)
message = f'Unrecognized container stack descriptor "{sourceDescription}"'
raise TypeError(message)

return containerStack

Expand Down
8 changes: 4 additions & 4 deletions Controllers/FanTowerController.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class FanTowerController(ControllerBase):
}

_criticalPropertiesTable = {
'adaptive_layer_height_enabled': ('global', False),
'layer_height': ('global', None),
'meshfix_union_all_remove_holes': ('extruder', False),
'support_enable': ('global', False),
'adaptive_layer_height_enabled': (ControllerBase.ContainerId.GLOBAL_CONTAINER_STACK, False),
'layer_height': (ControllerBase.ContainerId.GLOBAL_CONTAINER_STACK, None),
'meshfix_union_all_remove_holes': (ControllerBase.ContainerId.ACTIVE_EXTRUDER_STACK, False),
'support_enable': (ControllerBase.ContainerId.GLOBAL_CONTAINER_STACK, False),
}

_nominalBaseHeight = 0.8
Expand Down
14 changes: 7 additions & 7 deletions Controllers/FlowTowerController.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class FlowTowerController(ControllerBase):
}

_criticalPropertiesTable = {
'adaptive_layer_height_enabled': ('global', False),
'infill_sparse_density': ('extruder', 0),
'layer_height': ('global', None),
'meshfix_union_all_remove_holes': ('extruder', False),
'support_enable': ('global', False),
'adaptive_layer_height_enabled': (ControllerBase.ContainerId.GLOBAL_CONTAINER_STACK, False),
'infill_sparse_density': (ControllerBase.ContainerId.ACTIVE_EXTRUDER_STACK, 0),
'layer_height': (ControllerBase.ContainerId.GLOBAL_CONTAINER_STACK, None),
'meshfix_union_all_remove_holes': (ControllerBase.ContainerId.ACTIVE_EXTRUDER_STACK, False),
'support_enable': (ControllerBase.ContainerId.GLOBAL_CONTAINER_STACK, False),
}


Expand All @@ -50,7 +50,7 @@ def __init__(self, guiPath, stlPath, loadStlCallback, generateAndLoadStlCallback


# The starting value for the tower
_startValueStr = '85'
_startValueStr = '115'

startValueStrChanged = pyqtSignal()

Expand All @@ -65,7 +65,7 @@ def startValueStr(self)->str:


# The ending value for the tower
_endValueStr = '115'
_endValueStr = '85'

endValueStrChanged = pyqtSignal()

Expand Down
Loading