From 4e8d93ee720a4c2a6afe81dd9d837c7790946525 Mon Sep 17 00:00:00 2001 From: Russell Johnson <47639332+Russ4262@users.noreply.github.com> Date: Sat, 12 Mar 2022 20:36:41 -0600 Subject: [PATCH 1/3] Path: Extend Job integrity check to GUI side, issue #6207 [Bug] This commit adds a simple `_jobIntegrityCheck()` method to verify that a model and tool exists within the Job object, when interacting with the Task Panel. If either is missing, the appropriate tab is activated in the task window, and the appropriate edit window is opened for the user, with messages printed in the report view window. Add check for existence of `SetupSheet` property of empty Job object. These changes improve upon fixes in PR #5008 and related bug fixes. --- src/Mod/Path/PathScripts/PathJob.py | 21 +++++++++++---------- src/Mod/Path/PathScripts/PathJobGui.py | 13 +++++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathJob.py b/src/Mod/Path/PathScripts/PathJob.py index 77bdfa3e22..8af6f934df 100644 --- a/src/Mod/Path/PathScripts/PathJob.py +++ b/src/Mod/Path/PathScripts/PathJob.py @@ -284,7 +284,7 @@ class ObjectJob: # ops = FreeCAD.ActiveDocument.addObject( # "Path::FeatureCompoundPython", "Operations" # ) - ops = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup","Operations") + ops = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", "Operations") if ops.ViewObject: # ops.ViewObject.Proxy = 0 ops.ViewObject.Visibility = True @@ -295,14 +295,15 @@ class ObjectJob: def setupSetupSheet(self, obj): if not getattr(obj, "SetupSheet", None): - obj.addProperty( - "App::PropertyLink", - "SetupSheet", - "Base", - QT_TRANSLATE_NOOP( - "App::Property", "SetupSheet holding the settings for this job" - ), - ) + if not hasattr(obj, "SetupSheet"): + obj.addProperty( + "App::PropertyLink", + "SetupSheet", + "Base", + QT_TRANSLATE_NOOP( + "App::Property", "SetupSheet holding the settings for this job" + ), + ) obj.SetupSheet = PathSetupSheet.Create() if obj.SetupSheet.ViewObject: import PathScripts.PathIconViewProvider @@ -659,7 +660,7 @@ class ObjectJob: def execute(self, obj): if getattr(obj, "Operations", None): - #obj.Path = obj.Operations.Path + # obj.Path = obj.Operations.Path self.getCycleTime() def getCycleTime(self): diff --git a/src/Mod/Path/PathScripts/PathJobGui.py b/src/Mod/Path/PathScripts/PathJobGui.py index 78359a947e..46de1cf3ed 100644 --- a/src/Mod/Path/PathScripts/PathJobGui.py +++ b/src/Mod/Path/PathScripts/PathJobGui.py @@ -694,6 +694,7 @@ class TaskPanel: def accept(self, resetEdit=True): PathLog.track() + self._jobIntegrityCheck() # Check existance of Model and Tools self.preCleanup() self.getFields() self.setupGlobal.accept() @@ -1569,6 +1570,18 @@ class TaskPanel: def open(self): FreeCADGui.Selection.addObserver(self) + def _jobIntegrityCheck(self): + """_jobIntegrityCheck() ... Check Job object for existance of Model and Tools + If either Model or Tools is empty, change GUI tab and open appropriate selection window.""" + if len(self.obj.Model.Group) == 0: + PathLog.info(translate("Path_Job", "Please select a model for this job.")) + self.form.setCurrentIndex(0) # Change tab to General tab + self.jobModelEdit() + if len(self.obj.Tools.Group) == 0: + PathLog.info(translate("Path_Job", "Please add a tool to this job.")) + self.form.setCurrentIndex(3) # Change tab to Tools tab + self.toolControllerAdd() + # SelectionObserver interface def addSelection(self, doc, obj, sub, pnt): self.updateSelection() From b2ab3d7c48e61d038f6b4d558acbb407bdfdf7f1 Mon Sep 17 00:00:00 2001 From: Russell Johnson <47639332+Russ4262@users.noreply.github.com> Date: Sat, 12 Mar 2022 23:10:09 -0600 Subject: [PATCH 2/3] Path: Correct comment spelling --- src/Mod/Path/PathScripts/PathJobGui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathJobGui.py b/src/Mod/Path/PathScripts/PathJobGui.py index 46de1cf3ed..8e18c2df41 100644 --- a/src/Mod/Path/PathScripts/PathJobGui.py +++ b/src/Mod/Path/PathScripts/PathJobGui.py @@ -694,7 +694,7 @@ class TaskPanel: def accept(self, resetEdit=True): PathLog.track() - self._jobIntegrityCheck() # Check existance of Model and Tools + self._jobIntegrityCheck() # Check existence of Model and Tools self.preCleanup() self.getFields() self.setupGlobal.accept() @@ -1571,7 +1571,7 @@ class TaskPanel: FreeCADGui.Selection.addObserver(self) def _jobIntegrityCheck(self): - """_jobIntegrityCheck() ... Check Job object for existance of Model and Tools + """_jobIntegrityCheck() ... Check Job object for existence of Model and Tools If either Model or Tools is empty, change GUI tab and open appropriate selection window.""" if len(self.obj.Model.Group) == 0: PathLog.info(translate("Path_Job", "Please select a model for this job.")) From 61888959e26e6e02e8668bed35bcb418bca7a216 Mon Sep 17 00:00:00 2001 From: Russell Johnson <47639332+Russ4262@users.noreply.github.com> Date: Wed, 16 Mar 2022 11:47:51 -0500 Subject: [PATCH 3/3] Path: Change action to warning with option for action. --- src/Mod/Path/PathScripts/PathJobGui.py | 32 ++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathJobGui.py b/src/Mod/Path/PathScripts/PathJobGui.py index 8e18c2df41..15294360d4 100644 --- a/src/Mod/Path/PathScripts/PathJobGui.py +++ b/src/Mod/Path/PathScripts/PathJobGui.py @@ -1572,15 +1572,37 @@ class TaskPanel: def _jobIntegrityCheck(self): """_jobIntegrityCheck() ... Check Job object for existence of Model and Tools - If either Model or Tools is empty, change GUI tab and open appropriate selection window.""" + If either Model or Tools is empty, change GUI tab, issue appropriate warning, + and offer chance to add appropriate item.""" + + def _displayWarningWindow(msg): + """Display window with warning message and Add action button. + Return action state.""" + txtHeader = translate("Path_Job", "Warning") + txtPleaseAddOne = translate("Path_Job", "Please add one.") + txtOk = translate("Path_Job", "Ok") + txtAdd = translate("Path_Job", "Add") + + msgbox = QtGui.QMessageBox( + QtGui.QMessageBox.Warning, txtHeader, msg + " " + txtPleaseAddOne + ) + msgbox.addButton(txtOk, QtGui.QMessageBox.AcceptRole) # Add 'Ok' button + msgbox.addButton(txtAdd, QtGui.QMessageBox.ActionRole) # Add 'Add' button + return msgbox.exec_() + + # Check if at least on base model is present if len(self.obj.Model.Group) == 0: - PathLog.info(translate("Path_Job", "Please select a model for this job.")) self.form.setCurrentIndex(0) # Change tab to General tab - self.jobModelEdit() + no_model_txt = translate("Path_Job", "This job has no base model.") + if _displayWarningWindow(no_model_txt) == 1: + self.jobModelEdit() + + # Check if at least one tool is present if len(self.obj.Tools.Group) == 0: - PathLog.info(translate("Path_Job", "Please add a tool to this job.")) self.form.setCurrentIndex(3) # Change tab to Tools tab - self.toolControllerAdd() + no_tool_txt = translate("Path_Job", "This job has no tool.") + if _displayWarningWindow(no_tool_txt) == 1: + self.toolControllerAdd() # SelectionObserver interface def addSelection(self, doc, obj, sub, pnt):