Browse Source

CURA-4557 setting up plugin

Jack Ha 7 years ago
parent
commit
50f9548da0

+ 38 - 0
plugins/ModelChecker/ModelChecker.py

@@ -0,0 +1,38 @@
+# Copyright (c) 2018 Ultimaker B.V.
+# Cura is released under the terms of the LGPLv3 or higher.
+
+from PyQt5.QtCore import QTimer
+from cura.Scene.CuraSceneNode import CuraSceneNode
+
+from UM.Application import Application
+from UM.Extension import Extension
+from UM.Logger import Logger
+
+
+class ModelChecker(Extension):
+    def __init__(self):
+        super().__init__()
+
+        self._update_timer = QTimer()
+        self._update_timer.setInterval(2000)
+        self._update_timer.setSingleShot(True)
+        self._update_timer.timeout.connect(self.checkObjects)
+
+        self._nodes_to_check = set()
+
+        ## Reacting to an event. ##
+        Application.getInstance().mainWindowChanged.connect(self.logMessage) #When the main window is created, log a message.
+        Application.getInstance().getController().getScene().sceneChanged.connect(self._onSceneChanged)
+
+    ##  Adds a message to the log, as an example of how to listen to events.
+    def logMessage(self):
+        Logger.log("i", "This is an example log message. yeaaa")
+
+    def checkObjects(self):
+        Logger.log("d", "############# checking....")
+
+    def _onSceneChanged(self, source):
+        if isinstance(source, CuraSceneNode) and source.callDecoration("isSliceable"):
+            Logger.log("d", "triggurrrr")
+            self._nodes_to_check.add(source)
+            self._update_timer.start()

+ 23 - 0
plugins/ModelChecker/__init__.py

@@ -0,0 +1,23 @@
+# Copyright (c) 2017 Ultimaker B.V.
+# This example is released under the terms of the AGPLv3 or higher.
+
+from . import ModelChecker
+
+##  Defines additional metadata for the plug-in.
+#
+#   Some types of plug-ins require additional metadata, such as which file types
+#   they are able to read or the name of the tool they define. In the case of
+#   the "Extension" type plug-in, there is no additional metadata though.
+def getMetaData():
+    return {}
+
+##  Lets Uranium know that this plug-in exists.
+#
+#   This is called when starting the application to find out which plug-ins
+#   exist and what their types are. We need to return a dictionary mapping from
+#   strings representing plug-in types (in this case "extension") to objects
+#   that inherit from PluginObject.
+#
+#   \param app The application that the plug-in needs to register with.
+def register(app):
+    return {"extension": ModelChecker.ModelChecker()}

+ 8 - 0
plugins/ModelChecker/plugin.json

@@ -0,0 +1,8 @@
+{
+    "name": "Model Checker",
+    "author": "Ultimaker",
+    "version": "0.1",
+    "api": 4,
+    "description": "Checks models for possible printing issues and give suggestions.",
+    "catalog": "cura"
+}