Browse Source

Clean up code in SliceInfo

CURA-5204

 - Remove some unused imports
 - Do not depend on ExtruderManager
Lipu Fei 7 years ago
parent
commit
0fbb067508
1 changed files with 28 additions and 31 deletions
  1. 28 31
      plugins/SliceInfoPlugin/SliceInfo.py

+ 28 - 31
plugins/SliceInfoPlugin/SliceInfo.py

@@ -1,8 +1,9 @@
 # Copyright (c) 2015 Ultimaker B.V.
 # Cura is released under the terms of the LGPLv3 or higher.
 
-from cura.CuraApplication import CuraApplication
-from cura.Settings.ExtruderManager import ExtruderManager
+import json
+import platform
+import time
 
 from UM.Extension import Extension
 from UM.Application import Application
@@ -11,18 +12,10 @@ from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
 from UM.Message import Message
 from UM.i18n import i18nCatalog
 from UM.Logger import Logger
-
-import time
-
 from UM.Qt.Duration import DurationFormat
 
 from .SliceInfoJob import SliceInfoJob
 
-import platform
-import math
-import urllib.request
-import urllib.parse
-import json
 
 catalog = i18nCatalog("cura")
 
@@ -57,7 +50,7 @@ class SliceInfo(Extension):
     def messageActionTriggered(self, message_id, action_id):
         Preferences.getInstance().setValue("info/asked_send_slice_info", True)
         if action_id == "Disable":
-            Preferences.getInstance().addPreference("info/send_slice_info", False)
+            Application.getInstance().showPreferences()
         self.send_slice_info_message.hide()
 
     def _onWriteStarted(self, output_device):
@@ -66,13 +59,16 @@ class SliceInfo(Extension):
                 Logger.log("d", "'info/send_slice_info' is turned off.")
                 return  # Do nothing, user does not want to send data
 
-            global_container_stack = Application.getInstance().getGlobalContainerStack()
-            print_information = Application.getInstance().getPrintInformation()
+            application = Application.getInstance()
+            machine_manager = application.getMachineManager()
+            print_information = application.getPrintInformation()
+
+            global_stack = machine_manager.activeMachine
 
             data = dict()  # The data that we're going to submit.
             data["time_stamp"] = time.time()
             data["schema_version"] = 0
-            data["cura_version"] = Application.getInstance().getVersion()
+            data["cura_version"] = application.getVersion()
 
             active_mode = Preferences.getInstance().getValue("cura/active_mode")
             if active_mode == 0:
@@ -80,7 +76,7 @@ class SliceInfo(Extension):
             else:
                 data["active_mode"] = "custom"
 
-            definition_changes = global_container_stack.definitionChanges
+            definition_changes = global_stack.definitionChanges
             machine_settings_changed_by_user = False
             if definition_changes.getId() != "empty":
                 # Now a definition_changes container will always be created for a stack,
@@ -92,16 +88,17 @@ class SliceInfo(Extension):
             data["language"] = Preferences.getInstance().getValue("general/language")
             data["os"] = {"type": platform.system(), "version": platform.version()}
 
-            data["active_machine"] = {"definition_id": global_container_stack.definition.getId(), "manufacturer": global_container_stack.definition.getMetaData().get("manufacturer","")}
+            data["active_machine"] = {"definition_id": global_stack.definition.getId(),
+                                      "manufacturer": global_stack.definition.getMetaDataEntry("manufacturer", "")}
 
             # add extruder specific data to slice info
             data["extruders"] = []
-            extruders = list(ExtruderManager.getInstance().getMachineExtruders(global_container_stack.getId()))
+            extruders = list(global_stack.extruders.values())
             extruders = sorted(extruders, key = lambda extruder: extruder.getMetaDataEntry("position"))
 
             for extruder in extruders:
                 extruder_dict = dict()
-                extruder_dict["active"] = ExtruderManager.getInstance().getActiveExtruderStack() == extruder
+                extruder_dict["active"] = machine_manager.activeStack == extruder
                 extruder_dict["material"] = {"GUID": extruder.material.getMetaData().get("GUID", ""),
                                              "type": extruder.material.getMetaData().get("material", ""),
                                              "brand": extruder.material.getMetaData().get("brand", "")
@@ -123,11 +120,11 @@ class SliceInfo(Extension):
                 extruder_dict["extruder_settings"] = extruder_settings
                 data["extruders"].append(extruder_dict)
 
-            data["quality_profile"] = global_container_stack.quality.getMetaData().get("quality_type")
+            data["quality_profile"] = global_stack.quality.getMetaData().get("quality_type")
 
             data["models"] = []
             # Listing all files placed on the build plate
-            for node in DepthFirstIterator(CuraApplication.getInstance().getController().getScene().getRoot()):
+            for node in DepthFirstIterator(application.getController().getScene().getRoot()):
                 if node.callDecoration("isSliceable"):
                     model = dict()
                     model["hash"] = node.getMeshData().getHash()
@@ -173,28 +170,28 @@ class SliceInfo(Extension):
                                    "total": int(print_information.currentPrintTime.getDisplayString(DurationFormat.Format.Seconds))}
 
             print_settings = dict()
-            print_settings["layer_height"] = global_container_stack.getProperty("layer_height", "value")
+            print_settings["layer_height"] = global_stack.getProperty("layer_height", "value")
 
             # Support settings
-            print_settings["support_enabled"] = global_container_stack.getProperty("support_enable", "value")
-            print_settings["support_extruder_nr"] = int(global_container_stack.getExtruderPositionValueWithDefault("support_extruder_nr"))
+            print_settings["support_enabled"] = global_stack.getProperty("support_enable", "value")
+            print_settings["support_extruder_nr"] = int(global_stack.getExtruderPositionValueWithDefault("support_extruder_nr"))
 
             # Platform adhesion settings
-            print_settings["adhesion_type"] = global_container_stack.getProperty("adhesion_type", "value")
+            print_settings["adhesion_type"] = global_stack.getProperty("adhesion_type", "value")
 
             # Shell settings
-            print_settings["wall_line_count"] = global_container_stack.getProperty("wall_line_count", "value")
-            print_settings["retraction_enable"] = global_container_stack.getProperty("retraction_enable", "value")
+            print_settings["wall_line_count"] = global_stack.getProperty("wall_line_count", "value")
+            print_settings["retraction_enable"] = global_stack.getProperty("retraction_enable", "value")
 
             # Prime tower settings
-            print_settings["prime_tower_enable"] = global_container_stack.getProperty("prime_tower_enable", "value")
+            print_settings["prime_tower_enable"] = global_stack.getProperty("prime_tower_enable", "value")
 
             # Infill settings
-            print_settings["infill_sparse_density"] = global_container_stack.getProperty("infill_sparse_density", "value")
-            print_settings["infill_pattern"] = global_container_stack.getProperty("infill_pattern", "value")
-            print_settings["gradual_infill_steps"] = global_container_stack.getProperty("gradual_infill_steps", "value")
+            print_settings["infill_sparse_density"] = global_stack.getProperty("infill_sparse_density", "value")
+            print_settings["infill_pattern"] = global_stack.getProperty("infill_pattern", "value")
+            print_settings["gradual_infill_steps"] = global_stack.getProperty("gradual_infill_steps", "value")
 
-            print_settings["print_sequence"] = global_container_stack.getProperty("print_sequence", "value")
+            print_settings["print_sequence"] = global_stack.getProperty("print_sequence", "value")
 
             data["print_settings"] = print_settings