From e10669216571fb33f2fedf304ff5bd284c24a79d Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 8 Aug 2019 17:30:24 +0200 Subject: [PATCH] Make ContainerTree singleton but construct in run() of application We want to make sure that this tree is constructed during start-up after all containers have been registered, so we call getInstance() there once. If you need the tree before that, the tree will not yet have been filled and you won't get complete information, so you'd need to listen for updates. The singleton is there so you don't need to go via CuraApplication. Contributes to issue CURA-6600. --- cura/CuraApplication.py | 4 ++++ cura/Machines/ContainerTree.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 23ae2f8796..e764e10fec 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -70,6 +70,7 @@ from cura.Scene.CuraSceneNode import CuraSceneNode from cura.Scene.SliceableObjectDecorator import SliceableObjectDecorator from cura.Scene import ZOffsetDecorator +from cura.Machines.ContainerTree import ContainerTree from cura.Machines.MachineErrorChecker import MachineErrorChecker import cura.Machines.MaterialManager #Imported like this to prevent circular imports. import cura.Machines.QualityManager #Imported like this to prevent circular imports. @@ -731,6 +732,9 @@ class CuraApplication(QtApplication): def run(self): super().run() + Logger.log("i", "Building container tree.") + ContainerTree.getInstance() + Logger.log("i", "Initializing machine manager") self._machine_manager = MachineManager(self, parent = self) diff --git a/cura/Machines/ContainerTree.py b/cura/Machines/ContainerTree.py index 14c54459a3..4aca86c393 100644 --- a/cura/Machines/ContainerTree.py +++ b/cura/Machines/ContainerTree.py @@ -14,6 +14,14 @@ from typing import Dict # The tree starts at the machine definitions. For every distinct definition # there will be one machine node here. class ContainerTree: + __instance = None + + @classmethod + def getInstance(cls): + if cls.__instance is None: + cls.__instance = ContainerTree() + return cls.__instance + def __init__(self) -> None: self.machines = {} # type: Dict[str, MachineNode] # Mapping from definition ID to machine nodes. container_registry = ContainerRegistry.getInstance()