Browse Source

CURA-4972 Moved validation to `SettingOverrideDecorator.py`

**The diagnosis:**
The issue arrises from the fact that while the original object is subscribed to be validated, that subscription is only created by setting it as a settings override object. A clone of that object, while still a settings-override object, never gets subscribed because it's not explicitly set with the tool.

**The solution (?):**
I moved all the validation stuff over to SettingOverrideDecorator.py, and use its onSettingChanged() function to trigger the validation. Unfortunately, I can't use the timer because of some limitation with QTTimer and threads. So it's _a bit laggy in some places, and I'd be open to tips about how to fix this. It does work reliably though.
Ian Paschal 7 years ago
parent
commit
1f403f815d

+ 22 - 4
cura/Settings/SettingOverrideDecorator.py

@@ -3,12 +3,14 @@
 
 import copy
 
+from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
 from UM.Scene.SceneNodeDecorator import SceneNodeDecorator
 from UM.Signal import Signal, signalemitter
 from UM.Settings.InstanceContainer import InstanceContainer
 from UM.Settings.ContainerRegistry import ContainerRegistry
 from UM.Logger import Logger
-
+from UM.Settings.Validator import ValidatorState
+from PyQt5.QtCore import QTimer
 from UM.Application import Application
 
 from cura.Settings.PerObjectContainerStack import PerObjectContainerStack
@@ -38,6 +40,10 @@ class SettingOverrideDecorator(SceneNodeDecorator):
         self._extruder_stack = ExtruderManager.getInstance().getExtruderStack(0).getId()
 
         self._is_non_printing_mesh = False
+        self._error_check_timer = QTimer()
+        self._error_check_timer.setInterval(250)
+        self._error_check_timer.setSingleShot(True)
+        self._error_check_timer.timeout.connect(self._checkStackForErrors)
 
         self._stack.propertyChanged.connect(self._onSettingChanged)
 
@@ -93,9 +99,21 @@ class SettingOverrideDecorator(SceneNodeDecorator):
         # Trigger slice/need slicing if the value has changed.
         if property_name == "value":
             self._is_non_printing_mesh = any(bool(self._stack.getProperty(setting, "value")) for setting in self._non_printing_mesh_settings)
-
-            Application.getInstance().getBackend().needsSlicing()
-            Application.getInstance().getBackend().tickle()
+            if not self._is_non_printing_mesh:
+                # self._error_check_timer.start()
+                self._checkStackForErrors()
+        Application.getInstance().getBackend().needsSlicing()
+        Application.getInstance().getBackend().tickle()
+
+    def _checkStackForErrors(self):
+        hasErrors = False;
+        for key in self._stack.getAllKeys():
+            validation_state = self._stack.getProperty(key, "validationState")
+            if validation_state in (ValidatorState.Exception, ValidatorState.MaximumError, ValidatorState.MinimumError):
+                Logger.log("w", "Setting Per Object %s is not valid.", key)
+                hasErrors = True
+                break
+        Application.getInstance().getObjectsModel().setStacksHaveErrors(hasErrors)
 
     ##  Makes sure that the stack upon which the container stack is placed is
     #   kept up to date.

+ 5 - 3
plugins/PerObjectSettingsTool/PerObjectSettingsTool.py

@@ -44,7 +44,6 @@ class PerObjectSettingsTool(Tool):
         self._error_check_timer.setSingleShot(True)
         self._error_check_timer.timeout.connect(self._updateStacksHaveErrors)
 
-
     def event(self, event):
         super().event(event)
         if event.type == Event.MousePressEvent and self._controller.getToolsEnabled():
@@ -156,10 +155,12 @@ class PerObjectSettingsTool(Tool):
 
     def _onPropertyChanged(self, key: str, property_name: str) -> None:
         if property_name == "validationState":
-            self._error_check_timer.start()
+            # self._error_check_timer.start()
+            return
 
     def _updateStacksHaveErrors(self) -> None:
-        self._checkStacksHaveErrors()
+        return
+        # self._checkStacksHaveErrors()
 
 
     def _checkStacksHaveErrors(self):
@@ -180,6 +181,7 @@ class PerObjectSettingsTool(Tool):
 
 
     def _checkStackForErrors(self, stack):
+        print("checking for errors")
         if stack is None:
             return False