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.
This commit is contained in:
DeepSOIC 2015-10-31 22:39:55 +03:00
parent 3c882f0035
commit a8c89eb45b
11 changed files with 95 additions and 25 deletions

View File

@ -198,6 +198,7 @@ def CreateCompoundFilter(name):
sel = FreeCADGui.Selection.getSelection() sel = FreeCADGui.Selection.getSelection()
FreeCAD.ActiveDocument.openTransaction("Create CompoundFilter") FreeCAD.ActiveDocument.openTransaction("Create CompoundFilter")
FreeCADGui.addModule("CompoundFilter") FreeCADGui.addModule("CompoundFilter")
FreeCADGui.addModule("latticeExecuter")
FreeCADGui.doCommand("f = CompoundFilter.makeCompoundFilter(name = '"+name+"')") FreeCADGui.doCommand("f = CompoundFilter.makeCompoundFilter(name = '"+name+"')")
FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].Name) FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].Name)
FreeCADGui.doCommand("f.Base.ViewObject.hide()") FreeCADGui.doCommand("f.Base.ViewObject.hide()")
@ -207,8 +208,7 @@ def CreateCompoundFilter(name):
FreeCADGui.doCommand("f.FilterType = 'collision-pass'") FreeCADGui.doCommand("f.FilterType = 'collision-pass'")
else: else:
FreeCADGui.doCommand("f.FilterType = 'window-volume'") FreeCADGui.doCommand("f.FilterType = 'window-volume'")
FreeCADGui.doCommand("f.Proxy.execute(f)") FreeCADGui.doCommand("latticeExecuter.executeFeature(f)")
FreeCADGui.doCommand("f.purgeTouched()")
FreeCADGui.doCommand("f = None") FreeCADGui.doCommand("f = None")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()

View File

@ -103,10 +103,10 @@ class _ViewProviderFuseCompound:
def CreateFuseCompound(name): def CreateFuseCompound(name):
FreeCAD.ActiveDocument.openTransaction("Create FuseCompound") FreeCAD.ActiveDocument.openTransaction("Create FuseCompound")
FreeCADGui.addModule("FuseCompound") FreeCADGui.addModule("FuseCompound")
FreeCADGui.addModule("latticeExecuter")
FreeCADGui.doCommand("f = FuseCompound.makeFuseCompound(name = '"+name+"')") FreeCADGui.doCommand("f = FuseCompound.makeFuseCompound(name = '"+name+"')")
FreeCADGui.doCommand("f.Base = FreeCADGui.Selection.getSelection()[0]") FreeCADGui.doCommand("f.Base = FreeCADGui.Selection.getSelection()[0]")
FreeCADGui.doCommand("f.Proxy.execute(f)") FreeCADGui.doCommand("latticeExecuter.executeFeature(f)")
FreeCADGui.doCommand("f.purgeTouched()")
FreeCADGui.doCommand("f.Base.ViewObject.hide()") FreeCADGui.doCommand("f.Base.ViewObject.hide()")
FreeCADGui.doCommand("f = None") FreeCADGui.doCommand("f = None")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()

View File

@ -33,6 +33,7 @@ import Part
from latticeCommon import * from latticeCommon import *
import latticeBaseFeature import latticeBaseFeature
import latticeCompoundExplorer as LCE import latticeCompoundExplorer as LCE
import latticeExecuter
# -------------------------- document object -------------------------------------------------- # -------------------------- document object --------------------------------------------------
@ -71,7 +72,7 @@ class LatticeApply(latticeBaseFeature.LatticeFeature):
# validity logic # validity logic
if not latticeBaseFeature.isObjectLattice(obj.Tool): 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) outputIsLattice = latticeBaseFeature.isObjectLattice(obj.Base)
plmMatcher = App.Placement() #extra placement, that makes first item to preserve its original placement 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() sel = FreeCADGui.Selection.getSelectionEx()
FreeCAD.ActiveDocument.openTransaction("Create LatticeApply") FreeCAD.ActiveDocument.openTransaction("Create LatticeApply")
FreeCADGui.addModule("latticeApply") FreeCADGui.addModule("latticeApply")
FreeCADGui.addModule("latticeExecuter")
FreeCADGui.doCommand("f = latticeApply.makeLatticeApply(name='"+name+"')") FreeCADGui.doCommand("f = latticeApply.makeLatticeApply(name='"+name+"')")
FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName) FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName)
FreeCADGui.doCommand("f.Tool = App.ActiveDocument."+sel[1].ObjectName) FreeCADGui.doCommand("f.Tool = App.ActiveDocument."+sel[1].ObjectName)
FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+ FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+
" child.ViewObject.hide()") " child.ViewObject.hide()")
FreeCADGui.doCommand("f.Proxy.execute(f)") FreeCADGui.doCommand("latticeExecuter.executeFeature(f)")
FreeCADGui.doCommand("f.purgeTouched()")
FreeCADGui.doCommand("f = None") FreeCADGui.doCommand("f = None")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()

View File

@ -181,12 +181,12 @@ def CreateLatticeArrayFromShape(name):
sel = FreeCADGui.Selection.getSelectionEx() sel = FreeCADGui.Selection.getSelectionEx()
FreeCAD.ActiveDocument.openTransaction("Create LatticeArrayFromShape") FreeCAD.ActiveDocument.openTransaction("Create LatticeArrayFromShape")
FreeCADGui.addModule("latticeArrayFromShape") FreeCADGui.addModule("latticeArrayFromShape")
FreeCADGui.addModule("latticeExecuter")
FreeCADGui.doCommand("f = latticeArrayFromShape.makeLatticeArrayFromShape(name='"+name+"')") FreeCADGui.doCommand("f = latticeArrayFromShape.makeLatticeArrayFromShape(name='"+name+"')")
FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName) FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName)
FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+ FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+
" child.ViewObject.hide()") " child.ViewObject.hide()")
FreeCADGui.doCommand("f.Proxy.execute(f)") FreeCADGui.doCommand("latticeExecuter.executeFeature(f)")
FreeCADGui.doCommand("f.purgeTouched()")
FreeCADGui.doCommand("f = None") FreeCADGui.doCommand("f = None")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()

View File

@ -180,10 +180,10 @@ class _ViewProviderBoundBox:
def CreateBoundBox(name): def CreateBoundBox(name):
FreeCAD.ActiveDocument.openTransaction("Create BoundBox") FreeCAD.ActiveDocument.openTransaction("Create BoundBox")
FreeCADGui.addModule("latticeBoundBox") FreeCADGui.addModule("latticeBoundBox")
FreeCADGui.addModule("latticeExecuter")
FreeCADGui.doCommand("f = latticeBoundBox.makeBoundBox(name='"+name+"')") FreeCADGui.doCommand("f = latticeBoundBox.makeBoundBox(name='"+name+"')")
FreeCADGui.doCommand("f.Base = FreeCADGui.Selection.getSelection()[0]") FreeCADGui.doCommand("f.Base = FreeCADGui.Selection.getSelection()[0]")
FreeCADGui.doCommand("f.Proxy.execute(f)") FreeCADGui.doCommand("latticeExecuter.executeFeature(f)")
FreeCADGui.doCommand("f.purgeTouched()")
FreeCADGui.doCommand("f = None") FreeCADGui.doCommand("f = None")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()

View File

@ -33,6 +33,7 @@ import Part
from latticeCommon import * from latticeCommon import *
import latticeBaseFeature import latticeBaseFeature
import latticeCompoundExplorer as LCE import latticeCompoundExplorer as LCE
import latticeExecuter
# -------------------------- document object -------------------------------------------------- # -------------------------- document object --------------------------------------------------
@ -94,10 +95,10 @@ class Compose(latticeBaseFeature.LatticeFeature):
#mode validity logic #mode validity logic
if not latticeBaseFeature.isObjectLattice(obj.Tool): 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) outputIsLattice = latticeBaseFeature.isObjectLattice(obj.Base)
if isOverride and outputIsLattice: 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 outputIsLattice = False
# initialize output containers and loop variables # initialize output containers and loop variables
@ -180,13 +181,13 @@ def CreateCompose(name):
sel = FreeCADGui.Selection.getSelectionEx() sel = FreeCADGui.Selection.getSelectionEx()
FreeCAD.ActiveDocument.openTransaction("Create Compose") FreeCAD.ActiveDocument.openTransaction("Create Compose")
FreeCADGui.addModule("latticeCompose") FreeCADGui.addModule("latticeCompose")
FreeCADGui.addModule("latticeExecuter")
FreeCADGui.doCommand("f = latticeCompose.makeCompose(name='"+name+"')") FreeCADGui.doCommand("f = latticeCompose.makeCompose(name='"+name+"')")
FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName) FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName)
FreeCADGui.doCommand("f.Tool = App.ActiveDocument."+sel[1].ObjectName) FreeCADGui.doCommand("f.Tool = App.ActiveDocument."+sel[1].ObjectName)
FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+ FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+
" child.ViewObject.hide()") " child.ViewObject.hide()")
FreeCADGui.doCommand("f.Proxy.execute(f)") FreeCADGui.doCommand("latticeExecuter.executeFeature(f)")
FreeCADGui.doCommand("f.purgeTouched()")
FreeCADGui.doCommand("f = None") FreeCADGui.doCommand("f = None")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()

View File

@ -150,6 +150,7 @@ class _ViewProviderLatticeDowngrade:
def CreateLatticeDowngrade(name, mode = "Wires"): def CreateLatticeDowngrade(name, mode = "Wires"):
FreeCAD.ActiveDocument.openTransaction("Create latticeDowngrade") FreeCAD.ActiveDocument.openTransaction("Create latticeDowngrade")
FreeCADGui.addModule("latticeDowngrade") FreeCADGui.addModule("latticeDowngrade")
FreeCADGui.addModule("latticeExecuter")
FreeCADGui.doCommand("f = latticeDowngrade.makeLatticeDowngrade(name = '"+name+"')") FreeCADGui.doCommand("f = latticeDowngrade.makeLatticeDowngrade(name = '"+name+"')")
FreeCADGui.doCommand("f.Base = FreeCADGui.Selection.getSelection()[0]") FreeCADGui.doCommand("f.Base = FreeCADGui.Selection.getSelection()[0]")
FreeCADGui.doCommand("f.Mode = '"+mode+"'") FreeCADGui.doCommand("f.Mode = '"+mode+"'")
@ -158,8 +159,7 @@ def CreateLatticeDowngrade(name, mode = "Wires"):
FreeCADGui.doCommand("f.Base.ViewObject.hide()") FreeCADGui.doCommand("f.Base.ViewObject.hide()")
else: else:
FreeCADGui.doCommand("f.ViewObject.LineWidth = 6.0") FreeCADGui.doCommand("f.ViewObject.LineWidth = 6.0")
FreeCADGui.doCommand("f.Proxy.execute(f)") FreeCADGui.doCommand("latticeExecuter.executeFeature(f)")
FreeCADGui.doCommand("f.purgeTouched()")
FreeCADGui.doCommand("f = None") FreeCADGui.doCommand("f = None")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()

66
latticeExecuter.py Normal file
View File

@ -0,0 +1,66 @@
#***************************************************************************
#* *
#* Copyright (c) 2015 - Victor Titov (DeepSOIC) *
#* <vv.titov@gmail.com> *
#* *
#* 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)

View File

@ -34,6 +34,7 @@ from latticeCommon import *
import latticeBaseFeature import latticeBaseFeature
import latticeCompoundExplorer as LCE import latticeCompoundExplorer as LCE
import latticeGeomUtils as Utils import latticeGeomUtils as Utils
import latticeExecuter
# -------------------------- document object -------------------------------------------------- # -------------------------- document object --------------------------------------------------
@ -61,7 +62,7 @@ class LatticeInvert(latticeBaseFeature.LatticeFeature):
# cache stuff # cache stuff
base = obj.Base.Shape base = obj.Base.Shape
if not latticeBaseFeature.isObjectLattice(obj.Base): 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) baseChildren = LCE.AllLeaves(base)
#cache mode comparisons, for speed #cache mode comparisons, for speed
@ -113,12 +114,12 @@ def CreateLatticeInvert(name):
sel = FreeCADGui.Selection.getSelectionEx() sel = FreeCADGui.Selection.getSelectionEx()
FreeCAD.ActiveDocument.openTransaction("Create LatticeInvert") FreeCAD.ActiveDocument.openTransaction("Create LatticeInvert")
FreeCADGui.addModule("latticeInvert") FreeCADGui.addModule("latticeInvert")
FreeCADGui.addModule("latticeExecuter")
FreeCADGui.doCommand("f = latticeInvert.makeLatticeInvert(name='"+name+"')") FreeCADGui.doCommand("f = latticeInvert.makeLatticeInvert(name='"+name+"')")
FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName) FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName)
FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+ FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+
" child.ViewObject.hide()") " child.ViewObject.hide()")
FreeCADGui.doCommand("f.Proxy.execute(f)") FreeCADGui.doCommand("latticeExecuter.executeFeature(f)")
FreeCADGui.doCommand("f.purgeTouched()")
FreeCADGui.doCommand("f = None") FreeCADGui.doCommand("f = None")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()

View File

@ -101,10 +101,10 @@ def CreateLatticePlacement(name,mode = 'Custom'):
sel = FreeCADGui.Selection.getSelectionEx() sel = FreeCADGui.Selection.getSelectionEx()
FreeCAD.ActiveDocument.openTransaction("Create Lattice Placement") FreeCAD.ActiveDocument.openTransaction("Create Lattice Placement")
FreeCADGui.addModule("latticePlacement") FreeCADGui.addModule("latticePlacement")
FreeCADGui.addModule("latticeExecuter")
FreeCADGui.doCommand("f = latticePlacement.makeLatticePlacement(name='"+name+"')") FreeCADGui.doCommand("f = latticePlacement.makeLatticePlacement(name='"+name+"')")
FreeCADGui.doCommand("f.PlacementChoice = '"+mode+"'") FreeCADGui.doCommand("f.PlacementChoice = '"+mode+"'")
FreeCADGui.doCommand("f.Proxy.execute(f)") FreeCADGui.doCommand("latticeExecuter.executeFeature(f)")
FreeCADGui.doCommand("f.purgeTouched()")
FreeCADGui.doCommand("f = None") FreeCADGui.doCommand("f = None")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()

View File

@ -32,6 +32,7 @@ import Part
from latticeCommon import * from latticeCommon import *
import latticeBaseFeature import latticeBaseFeature
import latticeExecuter
def makePolarArray(name): def makePolarArray(name):
'''makePolarArray(name): makes a PolarArray object.''' '''makePolarArray(name): makes a PolarArray object.'''
@ -119,7 +120,7 @@ class PolarArray(latticeBaseFeature.LatticeFeature):
if len(edges) < 1: if len(edges) < 1:
raise ValueError('There are no edges in axis link shape!') raise ValueError('There are no edges in axis link shape!')
elif len(edges) > 1: 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] edge = edges[0]
#prepare #prepare
@ -204,11 +205,11 @@ def CreatePolarArray(name):
sel = FreeCADGui.Selection.getSelectionEx() sel = FreeCADGui.Selection.getSelectionEx()
FreeCAD.ActiveDocument.openTransaction("Create PolarArray") FreeCAD.ActiveDocument.openTransaction("Create PolarArray")
FreeCADGui.addModule("latticePolarArray") FreeCADGui.addModule("latticePolarArray")
FreeCADGui.addModule("latticeExecuter")
FreeCADGui.doCommand("f = latticePolarArray.makePolarArray(name='"+name+"')") FreeCADGui.doCommand("f = latticePolarArray.makePolarArray(name='"+name+"')")
if len(sel) == 1: if len(sel) == 1:
FreeCADGui.doCommand("f.AxisLink = App.ActiveDocument."+sel[0].ObjectName) FreeCADGui.doCommand("f.AxisLink = App.ActiveDocument."+sel[0].ObjectName)
FreeCADGui.doCommand("f.Proxy.execute(f)") FreeCADGui.doCommand("latticeExecuter.executeFeature(f)")
FreeCADGui.doCommand("f.purgeTouched()")
FreeCADGui.doCommand("f = None") FreeCADGui.doCommand("f = None")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()