From a8c89eb45b8b71a0f4589221d7f192c3619e6a2a Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Sat, 31 Oct 2015 22:39:55 +0300 Subject: [PATCH] New execute and warning logic Now, when executing a newly created feature fails, an error message is displayed. Moreover, messages are going to be displayed where only warnings were dumped to console, previously. --- CompoundFilter.py | 4 +-- FuseCompound.py | 4 +-- latticeApply.py | 7 +++-- latticeArrayFromShape.py | 4 +-- latticeBoundBox.py | 4 +-- latticeCompose.py | 9 +++--- latticeDowngrade.py | 4 +-- latticeExecuter.py | 66 ++++++++++++++++++++++++++++++++++++++++ latticeInvert.py | 7 +++-- latticePlacement.py | 4 +-- latticePolarArray.py | 7 +++-- 11 files changed, 95 insertions(+), 25 deletions(-) create mode 100644 latticeExecuter.py diff --git a/CompoundFilter.py b/CompoundFilter.py index fe65fe4..5dbf1d8 100644 --- a/CompoundFilter.py +++ b/CompoundFilter.py @@ -198,6 +198,7 @@ def CreateCompoundFilter(name): sel = FreeCADGui.Selection.getSelection() FreeCAD.ActiveDocument.openTransaction("Create CompoundFilter") FreeCADGui.addModule("CompoundFilter") + FreeCADGui.addModule("latticeExecuter") FreeCADGui.doCommand("f = CompoundFilter.makeCompoundFilter(name = '"+name+"')") FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].Name) FreeCADGui.doCommand("f.Base.ViewObject.hide()") @@ -207,8 +208,7 @@ def CreateCompoundFilter(name): FreeCADGui.doCommand("f.FilterType = 'collision-pass'") else: FreeCADGui.doCommand("f.FilterType = 'window-volume'") - FreeCADGui.doCommand("f.Proxy.execute(f)") - FreeCADGui.doCommand("f.purgeTouched()") + FreeCADGui.doCommand("latticeExecuter.executeFeature(f)") FreeCADGui.doCommand("f = None") FreeCAD.ActiveDocument.commitTransaction() diff --git a/FuseCompound.py b/FuseCompound.py index 460f49c..116909b 100644 --- a/FuseCompound.py +++ b/FuseCompound.py @@ -103,10 +103,10 @@ class _ViewProviderFuseCompound: def CreateFuseCompound(name): FreeCAD.ActiveDocument.openTransaction("Create FuseCompound") FreeCADGui.addModule("FuseCompound") + FreeCADGui.addModule("latticeExecuter") FreeCADGui.doCommand("f = FuseCompound.makeFuseCompound(name = '"+name+"')") FreeCADGui.doCommand("f.Base = FreeCADGui.Selection.getSelection()[0]") - FreeCADGui.doCommand("f.Proxy.execute(f)") - FreeCADGui.doCommand("f.purgeTouched()") + FreeCADGui.doCommand("latticeExecuter.executeFeature(f)") FreeCADGui.doCommand("f.Base.ViewObject.hide()") FreeCADGui.doCommand("f = None") FreeCAD.ActiveDocument.commitTransaction() diff --git a/latticeApply.py b/latticeApply.py index cfa0cad..a1335e5 100644 --- a/latticeApply.py +++ b/latticeApply.py @@ -33,6 +33,7 @@ import Part from latticeCommon import * import latticeBaseFeature import latticeCompoundExplorer as LCE +import latticeExecuter # -------------------------- document object -------------------------------------------------- @@ -71,7 +72,7 @@ class LatticeApply(latticeBaseFeature.LatticeFeature): # validity logic if not latticeBaseFeature.isObjectLattice(obj.Tool): - FreeCAD.Console.PrintWarning(obj.Name+': Tool is not a lattice object. Results may be unexpected.\n') + latticeExecuter.warning(obj, 'Tool is not a lattice object. Results may be unexpected.\n') outputIsLattice = latticeBaseFeature.isObjectLattice(obj.Base) plmMatcher = App.Placement() #extra placement, that makes first item to preserve its original placement @@ -125,13 +126,13 @@ def CreateLatticeApply(name): sel = FreeCADGui.Selection.getSelectionEx() FreeCAD.ActiveDocument.openTransaction("Create LatticeApply") FreeCADGui.addModule("latticeApply") + FreeCADGui.addModule("latticeExecuter") FreeCADGui.doCommand("f = latticeApply.makeLatticeApply(name='"+name+"')") FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName) FreeCADGui.doCommand("f.Tool = App.ActiveDocument."+sel[1].ObjectName) FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+ " child.ViewObject.hide()") - FreeCADGui.doCommand("f.Proxy.execute(f)") - FreeCADGui.doCommand("f.purgeTouched()") + FreeCADGui.doCommand("latticeExecuter.executeFeature(f)") FreeCADGui.doCommand("f = None") FreeCAD.ActiveDocument.commitTransaction() diff --git a/latticeArrayFromShape.py b/latticeArrayFromShape.py index 104c723..82abc8a 100644 --- a/latticeArrayFromShape.py +++ b/latticeArrayFromShape.py @@ -181,12 +181,12 @@ def CreateLatticeArrayFromShape(name): sel = FreeCADGui.Selection.getSelectionEx() FreeCAD.ActiveDocument.openTransaction("Create LatticeArrayFromShape") FreeCADGui.addModule("latticeArrayFromShape") + FreeCADGui.addModule("latticeExecuter") FreeCADGui.doCommand("f = latticeArrayFromShape.makeLatticeArrayFromShape(name='"+name+"')") FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName) FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+ " child.ViewObject.hide()") - FreeCADGui.doCommand("f.Proxy.execute(f)") - FreeCADGui.doCommand("f.purgeTouched()") + FreeCADGui.doCommand("latticeExecuter.executeFeature(f)") FreeCADGui.doCommand("f = None") FreeCAD.ActiveDocument.commitTransaction() diff --git a/latticeBoundBox.py b/latticeBoundBox.py index 6486ff8..10d0bf2 100644 --- a/latticeBoundBox.py +++ b/latticeBoundBox.py @@ -180,10 +180,10 @@ class _ViewProviderBoundBox: def CreateBoundBox(name): FreeCAD.ActiveDocument.openTransaction("Create BoundBox") FreeCADGui.addModule("latticeBoundBox") + FreeCADGui.addModule("latticeExecuter") FreeCADGui.doCommand("f = latticeBoundBox.makeBoundBox(name='"+name+"')") FreeCADGui.doCommand("f.Base = FreeCADGui.Selection.getSelection()[0]") - FreeCADGui.doCommand("f.Proxy.execute(f)") - FreeCADGui.doCommand("f.purgeTouched()") + FreeCADGui.doCommand("latticeExecuter.executeFeature(f)") FreeCADGui.doCommand("f = None") FreeCAD.ActiveDocument.commitTransaction() diff --git a/latticeCompose.py b/latticeCompose.py index e388104..b011bc7 100644 --- a/latticeCompose.py +++ b/latticeCompose.py @@ -33,6 +33,7 @@ import Part from latticeCommon import * import latticeBaseFeature import latticeCompoundExplorer as LCE +import latticeExecuter # -------------------------- document object -------------------------------------------------- @@ -94,10 +95,10 @@ class Compose(latticeBaseFeature.LatticeFeature): #mode validity logic if not latticeBaseFeature.isObjectLattice(obj.Tool): - FreeCAD.Console.PrintWarning(obj.Name+': Tool is not a lattice object. Results may be unexpected.\n') + latticeExecuter.warning(obj, 'Tool is not a lattice object. Results may be unexpected.\n') outputIsLattice = latticeBaseFeature.isObjectLattice(obj.Base) if isOverride and outputIsLattice: - FreeCAD.Console.PrintWarning(obj.Name+': Base is a lattice object. OverrideBasePlacements operation requires a generic compound as Base. So, the lattice is being treated as a generic compound.\n') + latticeExecuter.warning(obj, 'Base is a lattice object. OverrideBasePlacements operation requires a generic compound as Base. So, the lattice is being treated as a generic compound.\n') outputIsLattice = False # initialize output containers and loop variables @@ -180,13 +181,13 @@ def CreateCompose(name): sel = FreeCADGui.Selection.getSelectionEx() FreeCAD.ActiveDocument.openTransaction("Create Compose") FreeCADGui.addModule("latticeCompose") + FreeCADGui.addModule("latticeExecuter") FreeCADGui.doCommand("f = latticeCompose.makeCompose(name='"+name+"')") FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName) FreeCADGui.doCommand("f.Tool = App.ActiveDocument."+sel[1].ObjectName) FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+ " child.ViewObject.hide()") - FreeCADGui.doCommand("f.Proxy.execute(f)") - FreeCADGui.doCommand("f.purgeTouched()") + FreeCADGui.doCommand("latticeExecuter.executeFeature(f)") FreeCADGui.doCommand("f = None") FreeCAD.ActiveDocument.commitTransaction() diff --git a/latticeDowngrade.py b/latticeDowngrade.py index 4206391..4662d6a 100644 --- a/latticeDowngrade.py +++ b/latticeDowngrade.py @@ -150,6 +150,7 @@ class _ViewProviderLatticeDowngrade: def CreateLatticeDowngrade(name, mode = "Wires"): FreeCAD.ActiveDocument.openTransaction("Create latticeDowngrade") FreeCADGui.addModule("latticeDowngrade") + FreeCADGui.addModule("latticeExecuter") FreeCADGui.doCommand("f = latticeDowngrade.makeLatticeDowngrade(name = '"+name+"')") FreeCADGui.doCommand("f.Base = FreeCADGui.Selection.getSelection()[0]") FreeCADGui.doCommand("f.Mode = '"+mode+"'") @@ -158,8 +159,7 @@ def CreateLatticeDowngrade(name, mode = "Wires"): FreeCADGui.doCommand("f.Base.ViewObject.hide()") else: FreeCADGui.doCommand("f.ViewObject.LineWidth = 6.0") - FreeCADGui.doCommand("f.Proxy.execute(f)") - FreeCADGui.doCommand("f.purgeTouched()") + FreeCADGui.doCommand("latticeExecuter.executeFeature(f)") FreeCADGui.doCommand("f = None") FreeCAD.ActiveDocument.commitTransaction() diff --git a/latticeExecuter.py b/latticeExecuter.py new file mode 100644 index 0000000..c2c5cdb --- /dev/null +++ b/latticeExecuter.py @@ -0,0 +1,66 @@ +#*************************************************************************** +#* * +#* Copyright (c) 2015 - Victor Titov (DeepSOIC) * +#* * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the GNU Lesser General Public License (LGPL) * +#* as published by the Free Software Foundation; either version 2 of * +#* the License, or (at your option) any later version. * +#* for detail see the LICENCE text file. * +#* * +#* This program is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* GNU Library General Public License for more details. * +#* * +#* You should have received a copy of the GNU Library General Public * +#* License along with this program; if not, write to the Free Software * +#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +#* USA * +#* * +#*************************************************************************** + +__title__="A helper module for execution of features of Lattice workbench" +__author__ = "DeepSOIC" +__url__ = "" + +import FreeCAD +from PySide import QtGui + +globalIsCreatingLatticeFeature = False + +def executeFeature(obj): + global globalIsCreatingLatticeFeature + globalIsCreatingLatticeFeature = True + try: + obj.Proxy.execute(obj) + obj.purgeTouched() + except Exception as err: + mb = QtGui.QMessageBox() + mb.setIcon(mb.Icon.Warning) + mb.setText("While excuting feature '"+obj.Name+"', an error occured:\n" + err.message) + mb.setWindowTitle("Error") + mb.exec_() + finally: + globalIsCreatingLatticeFeature = False + + +def warning(obj,message): + ''' + warning(obj,message): smart warning message function. If feature is being + created, a warning message pops up. If otherwise, the warning is printed + into console. + ''' + global globalIsCreatingLatticeFeature + if globalIsCreatingLatticeFeature: + mb = QtGui.QMessageBox() + mb.setIcon(mb.Icon.Warning) + mb.setText(u"Warning: \n" + message) + mb.setWindowTitle("Warning") + mb.exec_() + else: + if obj is not None: + FreeCAD.Console.PrintWarning(obj.Name + ": " + message) + else: + FreeCAD.Console.PrintWarning(message) diff --git a/latticeInvert.py b/latticeInvert.py index 8963df7..14d1cf7 100644 --- a/latticeInvert.py +++ b/latticeInvert.py @@ -34,6 +34,7 @@ from latticeCommon import * import latticeBaseFeature import latticeCompoundExplorer as LCE import latticeGeomUtils as Utils +import latticeExecuter # -------------------------- document object -------------------------------------------------- @@ -61,7 +62,7 @@ class LatticeInvert(latticeBaseFeature.LatticeFeature): # cache stuff base = obj.Base.Shape if not latticeBaseFeature.isObjectLattice(obj.Base): - App.Console.PrintWarning(obj.Name+": Base is not a lattice, but lattice is expected. Results may be unexpected.\n") + latticeExecuter.warning(obj, "Base is not a lattice, but lattice is expected. Results may be unexpected.\n") baseChildren = LCE.AllLeaves(base) #cache mode comparisons, for speed @@ -113,12 +114,12 @@ def CreateLatticeInvert(name): sel = FreeCADGui.Selection.getSelectionEx() FreeCAD.ActiveDocument.openTransaction("Create LatticeInvert") FreeCADGui.addModule("latticeInvert") + FreeCADGui.addModule("latticeExecuter") FreeCADGui.doCommand("f = latticeInvert.makeLatticeInvert(name='"+name+"')") FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName) FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+ " child.ViewObject.hide()") - FreeCADGui.doCommand("f.Proxy.execute(f)") - FreeCADGui.doCommand("f.purgeTouched()") + FreeCADGui.doCommand("latticeExecuter.executeFeature(f)") FreeCADGui.doCommand("f = None") FreeCAD.ActiveDocument.commitTransaction() diff --git a/latticePlacement.py b/latticePlacement.py index d958ea5..d914a8c 100644 --- a/latticePlacement.py +++ b/latticePlacement.py @@ -101,10 +101,10 @@ def CreateLatticePlacement(name,mode = 'Custom'): sel = FreeCADGui.Selection.getSelectionEx() FreeCAD.ActiveDocument.openTransaction("Create Lattice Placement") FreeCADGui.addModule("latticePlacement") + FreeCADGui.addModule("latticeExecuter") FreeCADGui.doCommand("f = latticePlacement.makeLatticePlacement(name='"+name+"')") FreeCADGui.doCommand("f.PlacementChoice = '"+mode+"'") - FreeCADGui.doCommand("f.Proxy.execute(f)") - FreeCADGui.doCommand("f.purgeTouched()") + FreeCADGui.doCommand("latticeExecuter.executeFeature(f)") FreeCADGui.doCommand("f = None") FreeCAD.ActiveDocument.commitTransaction() diff --git a/latticePolarArray.py b/latticePolarArray.py index 5c6f468..a68adc3 100644 --- a/latticePolarArray.py +++ b/latticePolarArray.py @@ -32,6 +32,7 @@ import Part from latticeCommon import * import latticeBaseFeature +import latticeExecuter def makePolarArray(name): '''makePolarArray(name): makes a PolarArray object.''' @@ -119,7 +120,7 @@ class PolarArray(latticeBaseFeature.LatticeFeature): if len(edges) < 1: raise ValueError('There are no edges in axis link shape!') elif len(edges) > 1: - App.Console.PrintWarning('There is more than one edge in shape linked as an axis. The first edge will be used, but the shape link was probably added mistakenly.') + latticeExecuter.warning(obj,'There is more than one edge in shape linked as an axis. The first edge will be used, but the shape link was probably added mistakenly.') edge = edges[0] #prepare @@ -204,11 +205,11 @@ def CreatePolarArray(name): sel = FreeCADGui.Selection.getSelectionEx() FreeCAD.ActiveDocument.openTransaction("Create PolarArray") FreeCADGui.addModule("latticePolarArray") + FreeCADGui.addModule("latticeExecuter") FreeCADGui.doCommand("f = latticePolarArray.makePolarArray(name='"+name+"')") if len(sel) == 1: FreeCADGui.doCommand("f.AxisLink = App.ActiveDocument."+sel[0].ObjectName) - FreeCADGui.doCommand("f.Proxy.execute(f)") - FreeCADGui.doCommand("f.purgeTouched()") + FreeCADGui.doCommand("latticeExecuter.executeFeature(f)") FreeCADGui.doCommand("f = None") FreeCAD.ActiveDocument.commitTransaction()