mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Re-build container tree if has_materials changes during runtime
A bit of a hack and it'll be very slow. But it should work. Right now this crashes though because it still calls the Material Manager. Contributes to issue CURA-6600.
This commit is contained in:
parent
9b341cf604
commit
977beb8dbb
2 changed files with 17 additions and 1 deletions
|
@ -5,7 +5,6 @@ from typing import Any, Dict, List, Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot
|
from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot
|
||||||
|
|
||||||
from UM.Logger import Logger
|
|
||||||
from UM.Util import parseBool
|
from UM.Util import parseBool
|
||||||
from UM.Settings.InstanceContainer import InstanceContainer
|
from UM.Settings.InstanceContainer import InstanceContainer
|
||||||
from UM.Decorators import deprecated
|
from UM.Decorators import deprecated
|
||||||
|
|
|
@ -11,7 +11,9 @@ from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
from UM.Settings.DefinitionContainer import DefinitionContainer
|
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||||
from UM.Util import parseBool
|
from UM.Util import parseBool
|
||||||
|
|
||||||
|
import cura.CuraApplication # Imported like this to prevent circular dependencies.
|
||||||
from cura.MachineAction import MachineAction
|
from cura.MachineAction import MachineAction
|
||||||
|
from cura.Machines.ContainerTree import ContainerTree # To re-build the machine node when hasMaterials changes.
|
||||||
from cura.Settings.CuraStackBuilder import CuraStackBuilder
|
from cura.Settings.CuraStackBuilder import CuraStackBuilder
|
||||||
from cura.Settings.cura_empty_instance_containers import isEmptyContainer
|
from cura.Settings.cura_empty_instance_containers import isEmptyContainer
|
||||||
|
|
||||||
|
@ -41,6 +43,9 @@ class MachineSettingsAction(MachineAction):
|
||||||
self._backend = self._application.getBackend()
|
self._backend = self._application.getBackend()
|
||||||
self.onFinished.connect(self._onFinished)
|
self.onFinished.connect(self._onFinished)
|
||||||
|
|
||||||
|
# If the g-code flavour changes between UltiGCode and another flavour, we need to update the container tree.
|
||||||
|
self._application.globalContainerStackChanged.connect(self._updateHasMaterialsInContainerTree)
|
||||||
|
|
||||||
# Which container index in a stack to store machine setting changes.
|
# Which container index in a stack to store machine setting changes.
|
||||||
@pyqtProperty(int, constant = True)
|
@pyqtProperty(int, constant = True)
|
||||||
def storeContainerIndex(self) -> int:
|
def storeContainerIndex(self) -> int:
|
||||||
|
@ -51,6 +56,16 @@ class MachineSettingsAction(MachineAction):
|
||||||
if isinstance(container, DefinitionContainer) and container.getMetaDataEntry("type") == "machine":
|
if isinstance(container, DefinitionContainer) and container.getMetaDataEntry("type") == "machine":
|
||||||
self._application.getMachineActionManager().addSupportedAction(container.getId(), self.getKey())
|
self._application.getMachineActionManager().addSupportedAction(container.getId(), self.getKey())
|
||||||
|
|
||||||
|
## Triggered when the global container stack changes or when the g-code
|
||||||
|
# flavour setting is changed.
|
||||||
|
def _updateHasMaterialsInContainerTree(self) -> None:
|
||||||
|
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
||||||
|
machine_node = ContainerTree.getInstance().machines[global_stack.definition.getId()]
|
||||||
|
|
||||||
|
if machine_node.has_materials != parseBool(global_stack.getMetaDataEntry("has_materials")): # May have changed due to the g-code flavour.
|
||||||
|
machine_node.has_materials = parseBool(global_stack.getMetaDataEntry("has_materials"))
|
||||||
|
machine_node._loadAll()
|
||||||
|
|
||||||
def _reset(self):
|
def _reset(self):
|
||||||
global_stack = self._application.getMachineManager().activeMachine
|
global_stack = self._application.getMachineManager().activeMachine
|
||||||
if not global_stack:
|
if not global_stack:
|
||||||
|
@ -111,6 +126,8 @@ class MachineSettingsAction(MachineAction):
|
||||||
if "has_materials" in global_stack.getMetaData():
|
if "has_materials" in global_stack.getMetaData():
|
||||||
global_stack.removeMetaDataEntry("has_materials")
|
global_stack.removeMetaDataEntry("has_materials")
|
||||||
|
|
||||||
|
self._updateHasMaterialsInContainerTree()
|
||||||
|
|
||||||
# set materials
|
# set materials
|
||||||
for position in extruder_positions:
|
for position in extruder_positions:
|
||||||
if has_materials:
|
if has_materials:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue