CuraApplication.py 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. # Copyright (c) 2015 Ultimaker B.V.
  2. # Cura is released under the terms of the AGPLv3 or higher.
  3. from UM.Qt.QtApplication import QtApplication
  4. from UM.Scene.SceneNode import SceneNode
  5. from UM.Scene.Camera import Camera
  6. from UM.Math.Vector import Vector
  7. from UM.Math.Quaternion import Quaternion
  8. from UM.Math.AxisAlignedBox import AxisAlignedBox
  9. from UM.Math.Matrix import Matrix
  10. from UM.Resources import Resources
  11. from UM.Scene.ToolHandle import ToolHandle
  12. from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
  13. from UM.Mesh.ReadMeshJob import ReadMeshJob
  14. from UM.Logger import Logger
  15. from UM.Preferences import Preferences
  16. from UM.JobQueue import JobQueue
  17. from UM.SaveFile import SaveFile
  18. from UM.Scene.Selection import Selection
  19. from UM.Scene.GroupDecorator import GroupDecorator
  20. from UM.Settings.Validator import Validator
  21. from UM.Message import Message
  22. from UM.i18n import i18nCatalog
  23. from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
  24. from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation
  25. from UM.Operations.GroupedOperation import GroupedOperation
  26. from UM.Operations.SetTransformOperation import SetTransformOperation
  27. from UM.Operations.TranslateOperation import TranslateOperation
  28. from cura.SetParentOperation import SetParentOperation
  29. from cura.SliceableObjectDecorator import SliceableObjectDecorator
  30. from cura.BlockSlicingDecorator import BlockSlicingDecorator
  31. from UM.Settings.SettingDefinition import SettingDefinition, DefinitionPropertyType
  32. from UM.Settings.ContainerRegistry import ContainerRegistry
  33. from UM.Settings.SettingFunction import SettingFunction
  34. from . import PlatformPhysics
  35. from . import BuildVolume
  36. from . import CameraAnimation
  37. from . import PrintInformation
  38. from . import CuraActions
  39. from . import ZOffsetDecorator
  40. from . import CuraSplashScreen
  41. from . import CameraImageProvider
  42. from . import MachineActionManager
  43. import cura.Settings
  44. from PyQt5.QtCore import QUrl, pyqtSignal, pyqtProperty, QEvent, Q_ENUMS
  45. from UM.FlameProfiler import pyqtSlot
  46. from PyQt5.QtGui import QColor, QIcon
  47. from PyQt5.QtWidgets import QMessageBox
  48. from PyQt5.QtQml import qmlRegisterUncreatableType, qmlRegisterSingletonType, qmlRegisterType
  49. import sys
  50. import os.path
  51. import numpy
  52. import copy
  53. import urllib.parse
  54. import os
  55. numpy.seterr(all="ignore")
  56. try:
  57. from cura.CuraVersion import CuraVersion, CuraBuildType
  58. except ImportError:
  59. CuraVersion = "master" # [CodeStyle: Reflecting imported value]
  60. CuraBuildType = ""
  61. class CuraApplication(QtApplication):
  62. class ResourceTypes:
  63. QmlFiles = Resources.UserType + 1
  64. Firmware = Resources.UserType + 2
  65. QualityInstanceContainer = Resources.UserType + 3
  66. MaterialInstanceContainer = Resources.UserType + 4
  67. VariantInstanceContainer = Resources.UserType + 5
  68. UserInstanceContainer = Resources.UserType + 6
  69. MachineStack = Resources.UserType + 7
  70. ExtruderStack = Resources.UserType + 8
  71. Q_ENUMS(ResourceTypes)
  72. def __init__(self):
  73. Resources.addSearchPath(os.path.join(QtApplication.getInstallPrefix(), "share", "cura", "resources"))
  74. if not hasattr(sys, "frozen"):
  75. Resources.addSearchPath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "resources"))
  76. self._open_file_queue = [] # Files to open when plug-ins are loaded.
  77. # Need to do this before ContainerRegistry tries to load the machines
  78. SettingDefinition.addSupportedProperty("settable_per_mesh", DefinitionPropertyType.Any, default = True, read_only = True)
  79. SettingDefinition.addSupportedProperty("settable_per_extruder", DefinitionPropertyType.Any, default = True, read_only = True)
  80. # this setting can be changed for each group in one-at-a-time mode
  81. SettingDefinition.addSupportedProperty("settable_per_meshgroup", DefinitionPropertyType.Any, default = True, read_only = True)
  82. SettingDefinition.addSupportedProperty("settable_globally", DefinitionPropertyType.Any, default = True, read_only = True)
  83. # From which stack the setting would inherit if not defined per object (handled in the engine)
  84. # AND for settings which are not settable_per_mesh:
  85. # which extruder is the only extruder this setting is obtained from
  86. SettingDefinition.addSupportedProperty("limit_to_extruder", DefinitionPropertyType.Function, default = "-1")
  87. # For settings which are not settable_per_mesh and not settable_per_extruder:
  88. # A function which determines the glabel/meshgroup value by looking at the values of the setting in all (used) extruders
  89. SettingDefinition.addSupportedProperty("resolve", DefinitionPropertyType.Function, default = None, depends_on = "value")
  90. SettingDefinition.addSettingType("extruder", None, str, Validator)
  91. SettingFunction.registerOperator("extruderValues", cura.Settings.ExtruderManager.getExtruderValues)
  92. SettingFunction.registerOperator("extruderValue", cura.Settings.ExtruderManager.getExtruderValue)
  93. SettingFunction.registerOperator("resolveOrValue", cura.Settings.ExtruderManager.getResolveOrValue)
  94. ## Add the 4 types of profiles to storage.
  95. Resources.addStorageType(self.ResourceTypes.QualityInstanceContainer, "quality")
  96. Resources.addStorageType(self.ResourceTypes.VariantInstanceContainer, "variants")
  97. Resources.addStorageType(self.ResourceTypes.MaterialInstanceContainer, "materials")
  98. Resources.addStorageType(self.ResourceTypes.UserInstanceContainer, "user")
  99. Resources.addStorageType(self.ResourceTypes.ExtruderStack, "extruders")
  100. Resources.addStorageType(self.ResourceTypes.MachineStack, "machine_instances")
  101. ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.QualityInstanceContainer)
  102. ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.VariantInstanceContainer)
  103. ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.MaterialInstanceContainer)
  104. ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.UserInstanceContainer)
  105. ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.ExtruderStack)
  106. ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.MachineStack)
  107. ## Initialise the version upgrade manager with Cura's storage paths.
  108. import UM.VersionUpgradeManager #Needs to be here to prevent circular dependencies.
  109. UM.VersionUpgradeManager.VersionUpgradeManager.getInstance().setCurrentVersions(
  110. {
  111. ("quality", UM.Settings.InstanceContainer.Version): (self.ResourceTypes.QualityInstanceContainer, "application/x-uranium-instancecontainer"),
  112. ("machine_stack", UM.Settings.ContainerStack.Version): (self.ResourceTypes.MachineStack, "application/x-uranium-containerstack"),
  113. ("extruder_train", UM.Settings.ContainerStack.Version): (self.ResourceTypes.ExtruderStack, "application/x-uranium-extruderstack"),
  114. ("preferences", UM.Preferences.Version): (Resources.Preferences, "application/x-uranium-preferences"),
  115. ("user", UM.Settings.InstanceContainer.Version): (self.ResourceTypes.UserInstanceContainer, "application/x-uranium-instancecontainer")
  116. }
  117. )
  118. self._currently_loading_files = []
  119. self._non_sliceable_extensions = []
  120. self._machine_action_manager = MachineActionManager.MachineActionManager()
  121. self._machine_manager = None # This is initialized on demand.
  122. self._setting_inheritance_manager = None
  123. self._additional_components = {} # Components to add to certain areas in the interface
  124. super().__init__(name = "cura", version = CuraVersion, buildtype = CuraBuildType)
  125. self.setWindowIcon(QIcon(Resources.getPath(Resources.Images, "cura-icon.png")))
  126. self.setRequiredPlugins([
  127. "CuraEngineBackend",
  128. "MeshView",
  129. "LayerView",
  130. "STLReader",
  131. "SelectionTool",
  132. "CameraTool",
  133. "GCodeWriter",
  134. "LocalFileOutputDevice"
  135. ])
  136. self._physics = None
  137. self._volume = None
  138. self._output_devices = {}
  139. self._print_information = None
  140. self._previous_active_tool = None
  141. self._platform_activity = False
  142. self._scene_bounding_box = AxisAlignedBox.Null
  143. self._job_name = None
  144. self._center_after_select = False
  145. self._camera_animation = None
  146. self._cura_actions = None
  147. self._started = False
  148. self._message_box_callback = None
  149. self._message_box_callback_arguments = []
  150. self._i18n_catalog = i18nCatalog("cura")
  151. self.getController().getScene().sceneChanged.connect(self.updatePlatformActivity)
  152. self.getController().toolOperationStopped.connect(self._onToolOperationStopped)
  153. Resources.addType(self.ResourceTypes.QmlFiles, "qml")
  154. Resources.addType(self.ResourceTypes.Firmware, "firmware")
  155. self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Loading machines..."))
  156. # Add empty variant, material and quality containers.
  157. # Since they are empty, they should never be serialized and instead just programmatically created.
  158. # We need them to simplify the switching between materials.
  159. empty_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
  160. empty_variant_container = copy.deepcopy(empty_container)
  161. empty_variant_container._id = "empty_variant"
  162. empty_variant_container.addMetaDataEntry("type", "variant")
  163. ContainerRegistry.getInstance().addContainer(empty_variant_container)
  164. empty_material_container = copy.deepcopy(empty_container)
  165. empty_material_container._id = "empty_material"
  166. empty_material_container.addMetaDataEntry("type", "material")
  167. ContainerRegistry.getInstance().addContainer(empty_material_container)
  168. empty_quality_container = copy.deepcopy(empty_container)
  169. empty_quality_container._id = "empty_quality"
  170. empty_quality_container.setName("Not supported")
  171. empty_quality_container.addMetaDataEntry("quality_type", "normal")
  172. empty_quality_container.addMetaDataEntry("type", "quality")
  173. ContainerRegistry.getInstance().addContainer(empty_quality_container)
  174. empty_quality_changes_container = copy.deepcopy(empty_container)
  175. empty_quality_changes_container._id = "empty_quality_changes"
  176. empty_quality_changes_container.addMetaDataEntry("type", "quality_changes")
  177. ContainerRegistry.getInstance().addContainer(empty_quality_changes_container)
  178. with ContainerRegistry.getInstance().lockFile():
  179. ContainerRegistry.getInstance().load()
  180. Preferences.getInstance().addPreference("cura/active_mode", "simple")
  181. Preferences.getInstance().addPreference("cura/recent_files", "")
  182. Preferences.getInstance().addPreference("cura/categories_expanded", "")
  183. Preferences.getInstance().addPreference("cura/jobname_prefix", True)
  184. Preferences.getInstance().addPreference("view/center_on_select", False)
  185. Preferences.getInstance().addPreference("mesh/scale_to_fit", False)
  186. Preferences.getInstance().addPreference("mesh/scale_tiny_meshes", True)
  187. Preferences.getInstance().addPreference("cura/dialog_on_project_save", True)
  188. Preferences.getInstance().addPreference("cura/asked_dialog_on_project_save", False)
  189. Preferences.getInstance().addPreference("cura/currency", "€")
  190. Preferences.getInstance().addPreference("cura/material_settings", "{}")
  191. for key in [
  192. "dialog_load_path", # dialog_save_path is in LocalFileOutputDevicePlugin
  193. "dialog_profile_path",
  194. "dialog_material_path"]:
  195. Preferences.getInstance().addPreference("local_file/%s" % key, os.path.expanduser("~/"))
  196. Preferences.getInstance().setDefault("local_file/last_used_type", "text/x-gcode")
  197. Preferences.getInstance().setDefault("general/visible_settings", """
  198. machine_settings
  199. resolution
  200. layer_height
  201. shell
  202. wall_thickness
  203. top_bottom_thickness
  204. z_seam_x
  205. z_seam_y
  206. infill
  207. infill_sparse_density
  208. material
  209. material_print_temperature
  210. material_bed_temperature
  211. material_diameter
  212. material_flow
  213. retraction_enable
  214. speed
  215. speed_print
  216. speed_travel
  217. acceleration_print
  218. acceleration_travel
  219. jerk_print
  220. jerk_travel
  221. travel
  222. cooling
  223. cool_fan_enabled
  224. support
  225. support_enable
  226. support_extruder_nr
  227. support_type
  228. support_interface_density
  229. platform_adhesion
  230. adhesion_type
  231. adhesion_extruder_nr
  232. brim_width
  233. raft_airgap
  234. layer_0_z_overlap
  235. raft_surface_layers
  236. dual
  237. prime_tower_enable
  238. prime_tower_size
  239. prime_tower_position_x
  240. prime_tower_position_y
  241. meshfix
  242. blackmagic
  243. print_sequence
  244. infill_mesh
  245. experimental
  246. """.replace("\n", ";").replace(" ", ""))
  247. JobQueue.getInstance().jobFinished.connect(self._onJobFinished)
  248. self.applicationShuttingDown.connect(self.saveSettings)
  249. self.engineCreatedSignal.connect(self._onEngineCreated)
  250. self._recent_files = []
  251. files = Preferences.getInstance().getValue("cura/recent_files").split(";")
  252. for f in files:
  253. if not os.path.isfile(f):
  254. continue
  255. self._recent_files.append(QUrl.fromLocalFile(f))
  256. def _onEngineCreated(self):
  257. self._engine.addImageProvider("camera", CameraImageProvider.CameraImageProvider())
  258. ## A reusable dialogbox
  259. #
  260. showMessageBox = pyqtSignal(str, str, str, str, int, int, arguments = ["title", "text", "informativeText", "detailedText", "buttons", "icon"])
  261. def messageBox(self, title, text, informativeText = "", detailedText = "", buttons = QMessageBox.Ok, icon = QMessageBox.NoIcon, callback = None, callback_arguments = []):
  262. self._message_box_callback = callback
  263. self._message_box_callback_arguments = callback_arguments
  264. self.showMessageBox.emit(title, text, informativeText, detailedText, buttons, icon)
  265. @pyqtSlot(int)
  266. def messageBoxClosed(self, button):
  267. if self._message_box_callback:
  268. self._message_box_callback(button, *self._message_box_callback_arguments)
  269. self._message_box_callback = None
  270. self._message_box_callback_arguments = []
  271. showPrintMonitor = pyqtSignal(bool, arguments = ["show"])
  272. def setViewLegendItems(self, items):
  273. self.viewLegendItemsChanged.emit(items)
  274. viewLegendItemsChanged = pyqtSignal("QVariantList", arguments = ["items"])
  275. ## Cura has multiple locations where instance containers need to be saved, so we need to handle this differently.
  276. #
  277. # Note that the AutoSave plugin also calls this method.
  278. def saveSettings(self):
  279. if not self._started: # Do not do saving during application start
  280. return
  281. # Lock file for "more" atomically loading and saving to/from config dir.
  282. with ContainerRegistry.getInstance().lockFile():
  283. for instance in ContainerRegistry.getInstance().findInstanceContainers():
  284. if not instance.isDirty():
  285. continue
  286. try:
  287. data = instance.serialize()
  288. except NotImplementedError:
  289. continue
  290. except Exception:
  291. Logger.logException("e", "An exception occurred when serializing container %s", instance.getId())
  292. continue
  293. mime_type = ContainerRegistry.getMimeTypeForContainer(type(instance))
  294. file_name = urllib.parse.quote_plus(instance.getId()) + "." + mime_type.preferredSuffix
  295. instance_type = instance.getMetaDataEntry("type")
  296. path = None
  297. if instance_type == "material":
  298. path = Resources.getStoragePath(self.ResourceTypes.MaterialInstanceContainer, file_name)
  299. elif instance_type == "quality" or instance_type == "quality_changes":
  300. path = Resources.getStoragePath(self.ResourceTypes.QualityInstanceContainer, file_name)
  301. elif instance_type == "user":
  302. path = Resources.getStoragePath(self.ResourceTypes.UserInstanceContainer, file_name)
  303. elif instance_type == "variant":
  304. path = Resources.getStoragePath(self.ResourceTypes.VariantInstanceContainer, file_name)
  305. elif instance_type == "definition_changes":
  306. path = Resources.getStoragePath(self.ResourceTypes.MachineStack, file_name)
  307. if path:
  308. instance.setPath(path)
  309. with SaveFile(path, "wt") as f:
  310. f.write(data)
  311. for stack in ContainerRegistry.getInstance().findContainerStacks():
  312. self.saveStack(stack)
  313. def saveStack(self, stack):
  314. if not stack.isDirty():
  315. return
  316. try:
  317. data = stack.serialize()
  318. except NotImplementedError:
  319. return
  320. except Exception:
  321. Logger.logException("e", "An exception occurred when serializing container %s", stack.getId())
  322. return
  323. mime_type = ContainerRegistry.getMimeTypeForContainer(type(stack))
  324. file_name = urllib.parse.quote_plus(stack.getId()) + "." + mime_type.preferredSuffix
  325. stack_type = stack.getMetaDataEntry("type", None)
  326. path = None
  327. if not stack_type or stack_type == "machine":
  328. path = Resources.getStoragePath(self.ResourceTypes.MachineStack, file_name)
  329. elif stack_type == "extruder_train":
  330. path = Resources.getStoragePath(self.ResourceTypes.ExtruderStack, file_name)
  331. if path:
  332. stack.setPath(path)
  333. with SaveFile(path, "wt") as f:
  334. f.write(data)
  335. @pyqtSlot(str, result = QUrl)
  336. def getDefaultPath(self, key):
  337. default_path = Preferences.getInstance().getValue("local_file/%s" % key)
  338. return QUrl.fromLocalFile(default_path)
  339. @pyqtSlot(str, str)
  340. def setDefaultPath(self, key, default_path):
  341. Preferences.getInstance().setValue("local_file/%s" % key, QUrl(default_path).toLocalFile())
  342. ## Handle loading of all plugin types (and the backend explicitly)
  343. # \sa PluginRegistery
  344. def _loadPlugins(self):
  345. self._plugin_registry.addType("profile_reader", self._addProfileReader)
  346. self._plugin_registry.addType("profile_writer", self._addProfileWriter)
  347. self._plugin_registry.addPluginLocation(os.path.join(QtApplication.getInstallPrefix(), "lib", "cura"))
  348. if not hasattr(sys, "frozen"):
  349. self._plugin_registry.addPluginLocation(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "plugins"))
  350. self._plugin_registry.loadPlugin("ConsoleLogger")
  351. self._plugin_registry.loadPlugin("CuraEngineBackend")
  352. self._plugin_registry.loadPlugins()
  353. if self.getBackend() == None:
  354. raise RuntimeError("Could not load the backend plugin!")
  355. self._plugins_loaded = True
  356. def addCommandLineOptions(self, parser):
  357. super().addCommandLineOptions(parser)
  358. parser.add_argument("file", nargs="*", help="Files to load after starting the application.")
  359. def run(self):
  360. self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Setting up scene..."))
  361. controller = self.getController()
  362. controller.setActiveView("SolidView")
  363. controller.setCameraTool("CameraTool")
  364. controller.setSelectionTool("SelectionTool")
  365. t = controller.getTool("TranslateTool")
  366. if t:
  367. t.setEnabledAxis([ToolHandle.XAxis, ToolHandle.YAxis,ToolHandle.ZAxis])
  368. Selection.selectionChanged.connect(self.onSelectionChanged)
  369. root = controller.getScene().getRoot()
  370. # The platform is a child of BuildVolume
  371. self._volume = BuildVolume.BuildVolume(root)
  372. self.getRenderer().setBackgroundColor(QColor(245, 245, 245))
  373. self._physics = PlatformPhysics.PlatformPhysics(controller, self._volume)
  374. camera = Camera("3d", root)
  375. camera.setPosition(Vector(-80, 250, 700))
  376. camera.setPerspective(True)
  377. camera.lookAt(Vector(0, 0, 0))
  378. controller.getScene().setActiveCamera("3d")
  379. self.getController().getTool("CameraTool").setOrigin(Vector(0, 100, 0))
  380. self._camera_animation = CameraAnimation.CameraAnimation()
  381. self._camera_animation.setCameraTool(self.getController().getTool("CameraTool"))
  382. self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Loading interface..."))
  383. # Initialise extruder so as to listen to global container stack changes before the first global container stack is set.
  384. cura.Settings.ExtruderManager.getInstance()
  385. qmlRegisterSingletonType(cura.Settings.MachineManager, "Cura", 1, 0, "MachineManager", self.getMachineManager)
  386. qmlRegisterSingletonType(cura.Settings.SettingInheritanceManager, "Cura", 1, 0, "SettingInheritanceManager", self.getSettingInheritanceManager)
  387. qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager)
  388. self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
  389. self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles))
  390. self.initializeEngine()
  391. if self._engine.rootObjects:
  392. self.closeSplash()
  393. for file in self.getCommandLineOption("file", []):
  394. self._openFile(file)
  395. for file_name in self._open_file_queue: #Open all the files that were queued up while plug-ins were loading.
  396. self._openFile(file_name)
  397. self._started = True
  398. self.exec_()
  399. def getMachineManager(self, *args):
  400. if self._machine_manager is None:
  401. self._machine_manager = cura.Settings.MachineManager.createMachineManager()
  402. return self._machine_manager
  403. def getSettingInheritanceManager(self, *args):
  404. if self._setting_inheritance_manager is None:
  405. self._setting_inheritance_manager = cura.Settings.SettingInheritanceManager.createSettingInheritanceManager()
  406. return self._setting_inheritance_manager
  407. ## Get the machine action manager
  408. # We ignore any *args given to this, as we also register the machine manager as qml singleton.
  409. # It wants to give this function an engine and script engine, but we don't care about that.
  410. def getMachineActionManager(self, *args):
  411. return self._machine_action_manager
  412. ## Handle Qt events
  413. def event(self, event):
  414. if event.type() == QEvent.FileOpen:
  415. if self._plugins_loaded:
  416. self._openFile(event.file())
  417. else:
  418. self._open_file_queue.append(event.file())
  419. return super().event(event)
  420. ## Get print information (duration / material used)
  421. def getPrintInformation(self):
  422. return self._print_information
  423. ## Registers objects for the QML engine to use.
  424. #
  425. # \param engine The QML engine.
  426. def registerObjects(self, engine):
  427. engine.rootContext().setContextProperty("Printer", self)
  428. engine.rootContext().setContextProperty("CuraApplication", self)
  429. self._print_information = PrintInformation.PrintInformation()
  430. engine.rootContext().setContextProperty("PrintInformation", self._print_information)
  431. self._cura_actions = CuraActions.CuraActions(self)
  432. engine.rootContext().setContextProperty("CuraActions", self._cura_actions)
  433. qmlRegisterUncreatableType(CuraApplication, "Cura", 1, 0, "ResourceTypes", "Just an Enum type")
  434. qmlRegisterType(cura.Settings.ExtrudersModel, "Cura", 1, 0, "ExtrudersModel")
  435. qmlRegisterType(cura.Settings.ContainerSettingsModel, "Cura", 1, 0, "ContainerSettingsModel")
  436. qmlRegisterSingletonType(cura.Settings.ProfilesModel, "Cura", 1, 0, "ProfilesModel", cura.Settings.ProfilesModel.createProfilesModel)
  437. qmlRegisterType(cura.Settings.QualityAndUserProfilesModel, "Cura", 1, 0, "QualityAndUserProfilesModel")
  438. qmlRegisterType(cura.Settings.UserProfilesModel, "Cura", 1, 0, "UserProfilesModel")
  439. qmlRegisterType(cura.Settings.MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler")
  440. qmlRegisterType(cura.Settings.QualitySettingsModel, "Cura", 1, 0, "QualitySettingsModel")
  441. qmlRegisterType(cura.Settings.MachineNameValidator, "Cura", 1, 0, "MachineNameValidator")
  442. qmlRegisterSingletonType(cura.Settings.ContainerManager, "Cura", 1, 0, "ContainerManager", cura.Settings.ContainerManager.createContainerManager)
  443. # As of Qt5.7, it is necessary to get rid of any ".." in the path for the singleton to work.
  444. actions_url = QUrl.fromLocalFile(os.path.abspath(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")))
  445. qmlRegisterSingletonType(actions_url, "Cura", 1, 0, "Actions")
  446. engine.rootContext().setContextProperty("ExtruderManager", cura.Settings.ExtruderManager.getInstance())
  447. for path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.QmlFiles):
  448. type_name = os.path.splitext(os.path.basename(path))[0]
  449. if type_name in ("Cura", "Actions"):
  450. continue
  451. qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name)
  452. def onSelectionChanged(self):
  453. if Selection.hasSelection():
  454. if self.getController().getActiveTool():
  455. # If the tool has been disabled by the new selection
  456. if not self.getController().getActiveTool().getEnabled():
  457. # Default
  458. self.getController().setActiveTool("TranslateTool")
  459. else:
  460. if self._previous_active_tool:
  461. self.getController().setActiveTool(self._previous_active_tool)
  462. if not self.getController().getActiveTool().getEnabled():
  463. self.getController().setActiveTool("TranslateTool")
  464. self._previous_active_tool = None
  465. else:
  466. # Default
  467. self.getController().setActiveTool("TranslateTool")
  468. if Preferences.getInstance().getValue("view/center_on_select"):
  469. self._center_after_select = True
  470. else:
  471. if self.getController().getActiveTool():
  472. self._previous_active_tool = self.getController().getActiveTool().getPluginId()
  473. self.getController().setActiveTool(None)
  474. def _onToolOperationStopped(self, event):
  475. if self._center_after_select:
  476. self._center_after_select = False
  477. self._camera_animation.setStart(self.getController().getTool("CameraTool").getOrigin())
  478. self._camera_animation.setTarget(Selection.getSelectedObject(0).getWorldPosition())
  479. self._camera_animation.start()
  480. requestAddPrinter = pyqtSignal()
  481. activityChanged = pyqtSignal()
  482. sceneBoundingBoxChanged = pyqtSignal()
  483. @pyqtProperty(bool, notify = activityChanged)
  484. def getPlatformActivity(self):
  485. return self._platform_activity
  486. @pyqtProperty(str, notify = sceneBoundingBoxChanged)
  487. def getSceneBoundingBoxString(self):
  488. return self._i18n_catalog.i18nc("@info", "%(width).1f x %(depth).1f x %(height).1f mm") % {'width' : self._scene_bounding_box.width.item(), 'depth': self._scene_bounding_box.depth.item(), 'height' : self._scene_bounding_box.height.item()}
  489. def updatePlatformActivity(self, node = None):
  490. count = 0
  491. scene_bounding_box = None
  492. is_block_slicing_node = False
  493. for node in DepthFirstIterator(self.getController().getScene().getRoot()):
  494. if type(node) is not SceneNode or (not node.getMeshData() and not node.callDecoration("getLayerData")):
  495. continue
  496. if node.callDecoration("isBlockSlicing"):
  497. is_block_slicing_node = True
  498. count += 1
  499. if not scene_bounding_box:
  500. scene_bounding_box = node.getBoundingBox()
  501. else:
  502. other_bb = node.getBoundingBox()
  503. if other_bb is not None:
  504. scene_bounding_box = scene_bounding_box + node.getBoundingBox()
  505. print_information = self.getPrintInformation()
  506. if print_information:
  507. print_information.setPreSliced(is_block_slicing_node)
  508. if not scene_bounding_box:
  509. scene_bounding_box = AxisAlignedBox.Null
  510. if repr(self._scene_bounding_box) != repr(scene_bounding_box) and scene_bounding_box.isValid():
  511. self._scene_bounding_box = scene_bounding_box
  512. self.sceneBoundingBoxChanged.emit()
  513. self._platform_activity = True if count > 0 else False
  514. self.activityChanged.emit()
  515. # Remove all selected objects from the scene.
  516. @pyqtSlot()
  517. def deleteSelection(self):
  518. if not self.getController().getToolsEnabled():
  519. return
  520. removed_group_nodes = []
  521. op = GroupedOperation()
  522. nodes = Selection.getAllSelectedObjects()
  523. for node in nodes:
  524. op.addOperation(RemoveSceneNodeOperation(node))
  525. group_node = node.getParent()
  526. if group_node and group_node.callDecoration("isGroup") and group_node not in removed_group_nodes:
  527. remaining_nodes_in_group = list(set(group_node.getChildren()) - set(nodes))
  528. if len(remaining_nodes_in_group) == 1:
  529. removed_group_nodes.append(group_node)
  530. op.addOperation(SetParentOperation(remaining_nodes_in_group[0], group_node.getParent()))
  531. op.addOperation(RemoveSceneNodeOperation(group_node))
  532. op.push()
  533. ## Remove an object from the scene.
  534. # Note that this only removes an object if it is selected.
  535. @pyqtSlot("quint64")
  536. def deleteObject(self, object_id):
  537. if not self.getController().getToolsEnabled():
  538. return
  539. node = self.getController().getScene().findObject(object_id)
  540. if not node and object_id != 0: # Workaround for tool handles overlapping the selected object
  541. node = Selection.getSelectedObject(0)
  542. if node:
  543. op = GroupedOperation()
  544. op.addOperation(RemoveSceneNodeOperation(node))
  545. group_node = node.getParent()
  546. if group_node:
  547. # Note that at this point the node has not yet been deleted
  548. if len(group_node.getChildren()) <= 2 and group_node.callDecoration("isGroup"):
  549. op.addOperation(SetParentOperation(group_node.getChildren()[0], group_node.getParent()))
  550. op.addOperation(RemoveSceneNodeOperation(group_node))
  551. op.push()
  552. ## Create a number of copies of existing object.
  553. @pyqtSlot("quint64", int)
  554. def multiplyObject(self, object_id, count):
  555. node = self.getController().getScene().findObject(object_id)
  556. if not node and object_id != 0: # Workaround for tool handles overlapping the selected object
  557. node = Selection.getSelectedObject(0)
  558. if node:
  559. current_node = node
  560. # Find the topmost group
  561. while current_node.getParent() and current_node.getParent().callDecoration("isGroup"):
  562. current_node = current_node.getParent()
  563. op = GroupedOperation()
  564. for _ in range(count):
  565. new_node = copy.deepcopy(current_node)
  566. op.addOperation(AddSceneNodeOperation(new_node, current_node.getParent()))
  567. op.push()
  568. ## Center object on platform.
  569. @pyqtSlot("quint64")
  570. def centerObject(self, object_id):
  571. node = self.getController().getScene().findObject(object_id)
  572. if not node and object_id != 0: # Workaround for tool handles overlapping the selected object
  573. node = Selection.getSelectedObject(0)
  574. if not node:
  575. return
  576. if node.getParent() and node.getParent().callDecoration("isGroup"):
  577. node = node.getParent()
  578. if node:
  579. op = SetTransformOperation(node, Vector())
  580. op.push()
  581. ## Select all nodes containing mesh data in the scene.
  582. @pyqtSlot()
  583. def selectAll(self):
  584. if not self.getController().getToolsEnabled():
  585. return
  586. Selection.clear()
  587. for node in DepthFirstIterator(self.getController().getScene().getRoot()):
  588. if type(node) is not SceneNode:
  589. continue
  590. if not node.getMeshData() and not node.callDecoration("isGroup"):
  591. continue # Node that doesnt have a mesh and is not a group.
  592. if node.getParent() and node.getParent().callDecoration("isGroup"):
  593. continue # Grouped nodes don't need resetting as their parent (the group) is resetted)
  594. if not node.isSelectable():
  595. continue # i.e. node with layer data
  596. Selection.add(node)
  597. ## Delete all nodes containing mesh data in the scene.
  598. @pyqtSlot()
  599. def deleteAll(self):
  600. Logger.log("i", "Clearing scene")
  601. if not self.getController().getToolsEnabled():
  602. return
  603. nodes = []
  604. for node in DepthFirstIterator(self.getController().getScene().getRoot()):
  605. if type(node) is not SceneNode:
  606. continue
  607. if (not node.getMeshData() and not node.callDecoration("getLayerData")) and not node.callDecoration("isGroup"):
  608. continue # Node that doesnt have a mesh and is not a group.
  609. if node.getParent() and node.getParent().callDecoration("isGroup"):
  610. continue # Grouped nodes don't need resetting as their parent (the group) is resetted)
  611. nodes.append(node)
  612. if nodes:
  613. op = GroupedOperation()
  614. for node in nodes:
  615. op.addOperation(RemoveSceneNodeOperation(node))
  616. op.push()
  617. Selection.clear()
  618. ## Reset all translation on nodes with mesh data.
  619. @pyqtSlot()
  620. def resetAllTranslation(self):
  621. Logger.log("i", "Resetting all scene translations")
  622. nodes = []
  623. for node in DepthFirstIterator(self.getController().getScene().getRoot()):
  624. if type(node) is not SceneNode:
  625. continue
  626. if not node.getMeshData() and not node.callDecoration("isGroup"):
  627. continue # Node that doesnt have a mesh and is not a group.
  628. if node.getParent() and node.getParent().callDecoration("isGroup"):
  629. continue # Grouped nodes don't need resetting as their parent (the group) is resetted)
  630. if not node.isSelectable():
  631. continue # i.e. node with layer data
  632. nodes.append(node)
  633. if nodes:
  634. op = GroupedOperation()
  635. for node in nodes:
  636. # Ensure that the object is above the build platform
  637. node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator)
  638. if node.getBoundingBox():
  639. center_y = node.getWorldPosition().y - node.getBoundingBox().bottom
  640. else:
  641. center_y = 0
  642. op.addOperation(SetTransformOperation(node, Vector(0, center_y, 0)))
  643. op.push()
  644. ## Reset all transformations on nodes with mesh data.
  645. @pyqtSlot()
  646. def resetAll(self):
  647. Logger.log("i", "Resetting all scene transformations")
  648. nodes = []
  649. for node in DepthFirstIterator(self.getController().getScene().getRoot()):
  650. if type(node) is not SceneNode:
  651. continue
  652. if not node.getMeshData() and not node.callDecoration("isGroup"):
  653. continue # Node that doesnt have a mesh and is not a group.
  654. if node.getParent() and node.getParent().callDecoration("isGroup"):
  655. continue # Grouped nodes don't need resetting as their parent (the group) is resetted)
  656. if not node.isSelectable():
  657. continue # i.e. node with layer data
  658. nodes.append(node)
  659. if nodes:
  660. op = GroupedOperation()
  661. for node in nodes:
  662. # Ensure that the object is above the build platform
  663. node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator)
  664. if node.getBoundingBox():
  665. center_y = node.getWorldPosition().y - node.getBoundingBox().bottom
  666. else:
  667. center_y = 0
  668. op.addOperation(SetTransformOperation(node, Vector(0, center_y, 0), Quaternion(), Vector(1, 1, 1)))
  669. op.push()
  670. ## Reload all mesh data on the screen from file.
  671. @pyqtSlot()
  672. def reloadAll(self):
  673. Logger.log("i", "Reloading all loaded mesh data.")
  674. nodes = []
  675. for node in DepthFirstIterator(self.getController().getScene().getRoot()):
  676. if type(node) is not SceneNode or not node.getMeshData():
  677. continue
  678. nodes.append(node)
  679. if not nodes:
  680. return
  681. for node in nodes:
  682. file_name = node.getMeshData().getFileName()
  683. if file_name:
  684. job = ReadMeshJob(file_name)
  685. job._node = node
  686. job.finished.connect(self._reloadMeshFinished)
  687. job.start()
  688. else:
  689. Logger.log("w", "Unable to reload data because we don't have a filename.")
  690. ## Get logging data of the backend engine
  691. # \returns \type{string} Logging data
  692. @pyqtSlot(result = str)
  693. def getEngineLog(self):
  694. log = ""
  695. for entry in self.getBackend().getLog():
  696. log += entry.decode()
  697. return log
  698. recentFilesChanged = pyqtSignal()
  699. @pyqtProperty("QVariantList", notify = recentFilesChanged)
  700. def recentFiles(self):
  701. return self._recent_files
  702. @pyqtSlot("QStringList")
  703. def setExpandedCategories(self, categories):
  704. categories = list(set(categories))
  705. categories.sort()
  706. joined = ";".join(categories)
  707. if joined != Preferences.getInstance().getValue("cura/categories_expanded"):
  708. Preferences.getInstance().setValue("cura/categories_expanded", joined)
  709. self.expandedCategoriesChanged.emit()
  710. expandedCategoriesChanged = pyqtSignal()
  711. @pyqtProperty("QStringList", notify = expandedCategoriesChanged)
  712. def expandedCategories(self):
  713. return Preferences.getInstance().getValue("cura/categories_expanded").split(";")
  714. @pyqtSlot()
  715. def mergeSelected(self):
  716. self.groupSelected()
  717. try:
  718. group_node = Selection.getAllSelectedObjects()[0]
  719. except Exception as e:
  720. Logger.log("d", "mergeSelected: Exception:", e)
  721. return
  722. meshes = [node.getMeshData() for node in group_node.getAllChildren() if node.getMeshData()]
  723. # Compute the center of the objects
  724. object_centers = []
  725. # Forget about the translation that the original objects have
  726. zero_translation = Matrix(data=numpy.zeros(3))
  727. for mesh, node in zip(meshes, group_node.getChildren()):
  728. transformation = node.getLocalTransformation()
  729. transformation.setTranslation(zero_translation)
  730. transformed_mesh = mesh.getTransformed(transformation)
  731. center = transformed_mesh.getCenterPosition()
  732. object_centers.append(center)
  733. if object_centers and len(object_centers) > 0:
  734. middle_x = sum([v.x for v in object_centers]) / len(object_centers)
  735. middle_y = sum([v.y for v in object_centers]) / len(object_centers)
  736. middle_z = sum([v.z for v in object_centers]) / len(object_centers)
  737. offset = Vector(middle_x, middle_y, middle_z)
  738. else:
  739. offset = Vector(0, 0, 0)
  740. # Move each node to the same position.
  741. for mesh, node in zip(meshes, group_node.getChildren()):
  742. transformation = node.getLocalTransformation()
  743. transformation.setTranslation(zero_translation)
  744. transformed_mesh = mesh.getTransformed(transformation)
  745. # Align the object around its zero position
  746. # and also apply the offset to center it inside the group.
  747. node.setPosition(-transformed_mesh.getZeroPosition() - offset)
  748. # Use the previously found center of the group bounding box as the new location of the group
  749. group_node.setPosition(group_node.getBoundingBox().center)
  750. @pyqtSlot()
  751. def groupSelected(self):
  752. # Create a group-node
  753. group_node = SceneNode()
  754. group_decorator = GroupDecorator()
  755. group_node.addDecorator(group_decorator)
  756. group_node.setParent(self.getController().getScene().getRoot())
  757. group_node.setSelectable(True)
  758. center = Selection.getSelectionCenter()
  759. group_node.setPosition(center)
  760. group_node.setCenterPosition(center)
  761. # Move selected nodes into the group-node
  762. Selection.applyOperation(SetParentOperation, group_node)
  763. # Deselect individual nodes and select the group-node instead
  764. for node in group_node.getChildren():
  765. Selection.remove(node)
  766. Selection.add(group_node)
  767. @pyqtSlot()
  768. def ungroupSelected(self):
  769. selected_objects = Selection.getAllSelectedObjects().copy()
  770. for node in selected_objects:
  771. if node.callDecoration("isGroup"):
  772. op = GroupedOperation()
  773. group_parent = node.getParent()
  774. children = node.getChildren().copy()
  775. for child in children:
  776. # Set the parent of the children to the parent of the group-node
  777. op.addOperation(SetParentOperation(child, group_parent))
  778. # Add all individual nodes to the selection
  779. Selection.add(child)
  780. op.push()
  781. # Note: The group removes itself from the scene once all its children have left it,
  782. # see GroupDecorator._onChildrenChanged
  783. def _createSplashScreen(self):
  784. return CuraSplashScreen.CuraSplashScreen()
  785. def _onActiveMachineChanged(self):
  786. pass
  787. fileLoaded = pyqtSignal(str)
  788. def _onFileLoaded(self, job):
  789. nodes = job.getResult()
  790. for node in nodes:
  791. if node is not None:
  792. self.fileLoaded.emit(job.getFileName())
  793. node.setSelectable(True)
  794. node.setName(os.path.basename(job.getFileName()))
  795. op = AddSceneNodeOperation(node, self.getController().getScene().getRoot())
  796. op.push()
  797. self.getController().getScene().sceneChanged.emit(node) #Force scene change.
  798. def _onJobFinished(self, job):
  799. if type(job) is not ReadMeshJob or not job.getResult():
  800. return
  801. f = QUrl.fromLocalFile(job.getFileName())
  802. if f in self._recent_files:
  803. self._recent_files.remove(f)
  804. self._recent_files.insert(0, f)
  805. if len(self._recent_files) > 10:
  806. del self._recent_files[10]
  807. pref = ""
  808. for path in self._recent_files:
  809. pref += path.toLocalFile() + ";"
  810. Preferences.getInstance().setValue("cura/recent_files", pref)
  811. self.recentFilesChanged.emit()
  812. def _reloadMeshFinished(self, job):
  813. # TODO; This needs to be fixed properly. We now make the assumption that we only load a single mesh!
  814. mesh_data = job.getResult()[0].getMeshData()
  815. if mesh_data:
  816. job._node.setMeshData(mesh_data)
  817. else:
  818. Logger.log("w", "Could not find a mesh in reloaded node.")
  819. def _openFile(self, file):
  820. job = ReadMeshJob(os.path.abspath(file))
  821. job.finished.connect(self._onFileLoaded)
  822. job.start()
  823. def _addProfileReader(self, profile_reader):
  824. # TODO: Add the profile reader to the list of plug-ins that can be used when importing profiles.
  825. pass
  826. def _addProfileWriter(self, profile_writer):
  827. pass
  828. @pyqtSlot("QSize")
  829. def setMinimumWindowSize(self, size):
  830. self.getMainWindow().setMinimumSize(size)
  831. def getBuildVolume(self):
  832. return self._volume
  833. additionalComponentsChanged = pyqtSignal(str, arguments = ["areaId"])
  834. @pyqtProperty("QVariantMap", notify = additionalComponentsChanged)
  835. def additionalComponents(self):
  836. return self._additional_components
  837. ## Add a component to a list of components to be reparented to another area in the GUI.
  838. # The actual reparenting is done by the area itself.
  839. # \param area_id \type{str} Identifying name of the area to which the component should be reparented
  840. # \param component \type{QQuickComponent} The component that should be reparented
  841. @pyqtSlot(str, "QVariant")
  842. def addAdditionalComponent(self, area_id, component):
  843. if area_id not in self._additional_components:
  844. self._additional_components[area_id] = []
  845. self._additional_components[area_id].append(component)
  846. self.additionalComponentsChanged.emit(area_id)
  847. @pyqtSlot(str)
  848. def log(self, msg):
  849. Logger.log("d", msg)
  850. @pyqtSlot(QUrl)
  851. def readLocalFile(self, file):
  852. if not file.isValid():
  853. return
  854. scene = self.getController().getScene()
  855. for node in DepthFirstIterator(scene.getRoot()):
  856. if node.callDecoration("isBlockSlicing"):
  857. self.deleteAll()
  858. break
  859. f = file.toLocalFile()
  860. extension = os.path.splitext(f)[1]
  861. filename = os.path.basename(f)
  862. if len(self._currently_loading_files) > 0:
  863. # If a non-slicable file is already being loaded, we prevent loading of any further non-slicable files
  864. if extension.lower() in self._non_sliceable_extensions:
  865. message = Message(
  866. self._i18n_catalog.i18nc("@info:status",
  867. "Only one G-code file can be loaded at a time. Skipped importing {0}",
  868. filename))
  869. message.show()
  870. return
  871. # If file being loaded is non-slicable file, then prevent loading of any other files
  872. extension = os.path.splitext(self._currently_loading_files[0])[1]
  873. if extension.lower() in self._non_sliceable_extensions:
  874. message = Message(
  875. self._i18n_catalog.i18nc("@info:status",
  876. "Can't open any other file if G-code is loading. Skipped importing {0}",
  877. filename))
  878. message.show()
  879. return
  880. self._currently_loading_files.append(f)
  881. if extension in self._non_sliceable_extensions:
  882. self.deleteAll()
  883. job = ReadMeshJob(f)
  884. job.finished.connect(self._readMeshFinished)
  885. job.start()
  886. def _readMeshFinished(self, job):
  887. nodes = job.getResult()
  888. filename = job.getFileName()
  889. self._currently_loading_files.remove(filename)
  890. for node in nodes:
  891. node.setSelectable(True)
  892. node.setName(os.path.basename(filename))
  893. extension = os.path.splitext(filename)[1]
  894. if extension.lower() in self._non_sliceable_extensions:
  895. self.getController().setActiveView("LayerView")
  896. view = self.getController().getActiveView()
  897. view.resetLayerData()
  898. view.setLayer(9999999)
  899. view.calculateMaxLayers()
  900. block_slicing_decorator = BlockSlicingDecorator()
  901. node.addDecorator(block_slicing_decorator)
  902. else:
  903. sliceable_decorator = SliceableObjectDecorator()
  904. node.addDecorator(sliceable_decorator)
  905. scene = self.getController().getScene()
  906. op = AddSceneNodeOperation(node, scene.getRoot())
  907. op.push()
  908. scene.sceneChanged.emit(node)
  909. def addNonSliceableExtension(self, extension):
  910. self._non_sliceable_extensions.append(extension)