From 3f568ed5700f5bcfe6347c1bc62d168fa9b6cdc0 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Sat, 1 Apr 2017 19:09:12 +0300 Subject: [PATCH] Py3: fix syntax errors --- lattice2BaseFeature.py | 8 +- lattice2CompoundExplorer.py | 1 + lattice2Inspect.py | 14 ++-- lattice2RecomputeLocker.py | 149 ++++++++---------------------------- lattice2ShapeCopy.py | 18 ++--- lattice2Subsequencer.py | 16 ++-- 6 files changed, 59 insertions(+), 147 deletions(-) diff --git a/lattice2BaseFeature.py b/lattice2BaseFeature.py index 4c62c41..ed41f98 100644 --- a/lattice2BaseFeature.py +++ b/lattice2BaseFeature.py @@ -42,10 +42,10 @@ def getDefShapeColor(): #convert color in int to color in tuple of 4 floats. #This is probably implemented already somewhere, but I couldn't find, so I rolled my own --DeepSOIC # clr in hex looks like this: 0xRRGGBBOO (r,g,b,o = red, green, blue, opacity) - o = clr & 0x000000FFL - b = (clr >> 8) & 0x000000FFL - g = (clr >> 16) & 0x000000FFL - r = (clr >> 24) & 0x000000FFL + o = clr & 0x000000FF + b = (clr >> 8) & 0x000000FF + g = (clr >> 16) & 0x000000FF + r = (clr >> 24) & 0x000000FF return (r/255.0, g/255.0, b/255.0, (255-o)/255.0) diff --git a/lattice2CompoundExplorer.py b/lattice2CompoundExplorer.py index 93689d4..05e8307 100644 --- a/lattice2CompoundExplorer.py +++ b/lattice2CompoundExplorer.py @@ -130,6 +130,7 @@ class CompoundExplorer: assert(msg != 0) self.lastMsg = msg return (sh, msg, self) + __next__ = next def CalculateNumberOfLeaves(compound): diff --git a/lattice2Inspect.py b/lattice2Inspect.py index 4e719f4..09d3515 100644 --- a/lattice2Inspect.py +++ b/lattice2Inspect.py @@ -73,7 +73,7 @@ class _CommandInspect: strStructure = [""] else: if sel.Object.Shape.isNull(): - strStructure.append(unicode("")) + strStructure.append("") else: for (child, msg, it) in LCE.CompoundExplorer(sel.Object.Shape): #child is a shape. @@ -88,8 +88,8 @@ class _CommandInspect: if msg == LCE.CompoundExplorer.MSG_DIVEDOWN: strMsg += ":" except Exception as err: - strMsg = "ERROR: " + err.message - strStructure.append(unicode(strMsg)) + strMsg = "ERROR: " + str(err) + strStructure.append(strMsg) strSubInfo = [] if sel.HasSubObjects: @@ -102,8 +102,8 @@ class _CommandInspect: try: strMsg += shapeInfoString(child) except Exception as err: - strMsg += "ERROR: " + err.message - strSubInfo.append(unicode(strMsg)) + strMsg += "ERROR: " + str(err) + strSubInfo.append(strMsg) allText = u'' if sel.HasSubObjects: @@ -111,9 +111,9 @@ class _CommandInspect: allText += u'\n'.join(strSubInfo) + u'\n\n' allText += u'Selected document object:\n' - allText += u' Name = ' + unicode(sel.Object.Name) + u'\n' + allText += u' Name = ' + sel.Object.Name + u'\n' allText += u' Label = ' + sel.Object.Label + u'\n' - allText += u' Is placement/array = ' + unicode(repr(isLattice)) + u'\n' + allText += u' Is placement/array = ' + repr(isLattice) + u'\n' allText += u'Structure: \n' allText += u'\n'.join(strStructure) mb = QtGui.QMessageBox() diff --git a/lattice2RecomputeLocker.py b/lattice2RecomputeLocker.py index 672a019..4a5d5e3 100644 --- a/lattice2RecomputeLocker.py +++ b/lattice2RecomputeLocker.py @@ -63,6 +63,28 @@ def touchEverything(doc): if touch_count == 0: raise ValueError("forceRecompute: failed to touch any object!") +def recomputeFeature(featureToRecompute, bUndoable = True): + doc = featureToRecompute.Document + if bUndoable: + doc.openTransaction("Recompute "+featureToRecompute.Name) + if hasattr(featureToRecompute, 'Recomputing'): + if featureToRecompute.Recomputing == 'Disabled': #toposeries, paraseries... + featureToRecompute.Recomputing = 'Recompute Once' + if hasattr(featureToRecompute, "recompute"): + # new FreeCAD! yay! + featureToRecompute.recompute() + elif hasattr(featureToRecompute, "Proxy"): + #Python feature - easy! + featureToRecompute.Proxy.execute(featureToRecompute) + else: + infoMessage("RecomputeFeature","Selected feature is a C++ feature. Recomputing them with this command was temporarily disabled, because it is known to break dependencies. The command will be frozen, till a reliable way of recomputing c++ feature gets exposed.") + return + featureToRecompute.purgeTouched() + for docobj in featureToRecompute.InList: + touch(docobj) + if bUndoable: + doc.commitTransaction() + def makeRecomputeLocker(name): '''makeRecomputeLocker(name): makes a RecomputeLocker document object.''' obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython",name) @@ -101,61 +123,7 @@ class LatticeRecomputeLocker: if bUndoable: doc.commitTransaction() obj.LockRecomputes = oldState - - def RecomputeFeature(self, selfobj, featureToRecompute, bUndoable = True): - oldState = selfobj.LockRecomputes - doc = selfobj.Document - if bUndoable: - doc.openTransaction("Recompute "+featureToRecompute.Name) - if hasattr(featureToRecompute, "Proxy"): - #Python feature - easy! - featureToRecompute.Proxy.execute(featureToRecompute) - featureToRecompute.purgeTouched() - for docobj in featureToRecompute.InList: - touch(docobj) - else: - infoMessage("RecomputeFeature","Selected feature is a C++ feature. Recomputing them with this command was temporarily disabled, because it is known to break dependencies. The command will be frozen, till a reliable way of recomputing c++ feature gets exposed.") - return - #non-Py feature. Hard. - #overview: FreeCAD will recompute just one feature, if it is the - #only one that is touched, and no other features depend on it. So - #that's what we are to do: untouch all other features, and remove - #all links. - #save touched flags, to restore them later - touched_dict = self.collectTouchedDict(selfobj) - try: - #temporarily remove all links to the object - unlinker = Unlinker() - unlinker.unlinkObject(featureToRecompute) - try: - #set desired document touched state - for docobj in doc.Objects: - if docobj is not featureToRecompute: - docobj.purgeTouched() - else: - touch(docobj) - try: - #do the business =) - selfobj.LockRecomputes = False - doc.recompute() - #and restore the mess we've created... - finally: - selfobj.LockRecomputes = oldState - - finally: - unlinker.restoreLinks() - finally: - self.restoreTouched(selfobj,touched_dict) - - #feature recomputed - purge its touched - featureToRecompute.purgeTouched() - #feature should have changed, so mark all dependent stuff as touched - for docobj in featureToRecompute.InList: - touch(docobj) - if bUndoable: - doc.commitTransaction() - def collectTouchedDict(self, selfobj): doc = selfobj.Document dict = {} @@ -173,58 +141,6 @@ class LatticeRecomputeLocker: docobj.purgeTouched() -class Unlinker: - '''An object to temporarily unlink an object, and to restore the links afterwards''' - def __init__(self): - #List of actions for restoring the links is going to be saved here. It - # is a list tuples: (object, 'property name', oldvalue). - self.actionList = [] - - def unlinkObject(self, featureToUnlink): - '''Redirects all links to this object, to make it possible to recompute it individually. TODO: expressions!!''' - doc = featureToUnlink.Document - ListOfDependentObjects = featureToUnlink.InList # naming list of objects that are dependent on the feature as InList is bullshit. InList should have been list of inputs - that is, list of objects this feature depends on. But it's back-to-front. =< - if len(self.actionList) > 0: - raise ValueError("unlinker hasn't restored the changes it did previously. Can't unlink another object.") - for obj in ListOfDependentObjects: - for propname in obj.PropertiesList: - try: - typ = obj.getTypeIdOfProperty(propname) - val = getattr(obj,propname) - bool_changed = True - if typ == 'App::PropertyLink': - setattr(obj,propname,None) - elif typ == 'App::PropertyLinkSub': - #val is (feature,["Edge1","Face2"]) - setattr(obj,propname,None) - elif typ == 'App::PropertyLinkList': - setattr(obj,propname,[]) - elif typ == 'App::PropertyLinkSubList': - setattr(obj,propname,[]) - else: - bool_changed = False - - if bool_changed: - self.actionList.append((obj,propname,val)) - except Exception as err: - LE.error(None, "While temporarily removing all links to an object, an error occured.\n" + - "Error:"+err.message+"\n" + - "object = "+obj.Name+"\n" + - "property = "+propname+"\n" + - "value to be restored = "+repr(value)) - - def restoreLinks(self): - for (obj, propname, value) in self.actionList: - try: - setattr(obj,propname,value) - except Exception as err: - LE.error(None, "An error occured while restoring links.\n" + - "Error:"+err.message+"\n" + - "object = "+obj.Name+"\n" + - "property = "+propname+"\n" + - "value to be restored = "+repr(value)) - self.actionList = [] - class ViewProviderLatticeRecomputeLocker: "A View Provider for LatticeRecomputeLocker object" @@ -256,6 +172,8 @@ class ViewProviderLatticeRecomputeLocker: # --------------------------------/document object------------------------------ + + # --------------------------------Gui commands---------------------------------- def getLocker(): @@ -286,7 +204,7 @@ class _CommandMakeLockerObj: mb.exec_() def IsActive(self): - return bool(App.ActiveDocument) and getLocker() is None + return (bool(App.ActiveDocument) and getLocker() is None) and not USE_FC_RECOMPUTE FreeCADGui.addCommand('Lattice2_RecomputeLocker_MakeFeature', _CommandMakeLockerObj()) @@ -343,7 +261,7 @@ class _CommandUnlockRecomputes: FreeCADGui.addCommand('Lattice2_RecomputeLocker_UnlockRecomputes', _CommandUnlockRecomputes()) class _CommandRecomputeFeature: - "Command to unlock automatic recomputes" + "Command to recompute single object" def GetResources(self): return {'Pixmap' : getIconPath("Lattice2_RecomputeLocker_RecomputeFeature.svg"), 'MenuText': QtCore.QT_TRANSLATE_NOOP("Lattice2_RecomputeLocker","Recompute feature"), @@ -353,19 +271,12 @@ class _CommandRecomputeFeature: def Activated(self): sel = FreeCADGui.Selection.getSelectionEx() - if getLocker() is not None: - FreeCADGui.addModule("lattice2RecomputeLocker") - for selobj in sel: - FreeCADGui.doCommand("lattice2RecomputeLocker.getLocker().Proxy.RecomputeFeature(lattice2RecomputeLocker.getLocker(), App.ActiveDocument."+selobj.ObjectName+")") - else: - mb = QtGui.QMessageBox() - mb.setIcon(mb.Icon.Warning) - mb.setText(translate("Lattice2_RecomputeLocker", "There is no recompute locker object in the document. Please create one, first.", None)) - mb.setWindowTitle(translate("Lattice2_RecomputeLocker","fail", None)) - mb.exec_() + FreeCADGui.addModule("lattice2RecomputeLocker") + for selobj in sel: + FreeCADGui.doCommand("lattice2RecomputeLocker.recomputeFeature(App.ActiveDocument."+selobj.ObjectName+")") def IsActive(self): - return getLocker() is not None and len(FreeCADGui.Selection.getSelectionEx()) > 0 + return len(FreeCADGui.Selection.getSelectionEx()) > 0 FreeCADGui.addCommand('Lattice2_RecomputeLocker_RecomputeFeature', _CommandRecomputeFeature()) diff --git a/lattice2ShapeCopy.py b/lattice2ShapeCopy.py index 1d84f6f..6757dcd 100644 --- a/lattice2ShapeCopy.py +++ b/lattice2ShapeCopy.py @@ -34,18 +34,18 @@ def shallowCopy(shape, extra_placement = None): copy will match by isSame/isEqual/isPartner tests, but will have an independent placement.""" copiers = { - "Vertex": lambda(sh): sh.Vertexes[0], - "Edge": lambda(sh): sh.Edges[0], - "Wire": lambda(sh): sh.Wires[0], - "Face": lambda(sh): sh.Faces[0], - "Shell": lambda(sh): sh.Shells[0], - "Solid": lambda(sh): sh.Solids[0], - "CompSolid": lambda(sh): sh.CompSolids[0], - "Compound": lambda(sh): sh.Compounds[0], + "Vertex": lambda sh: sh.Vertexes[0], + "Edge": lambda sh: sh.Edges[0], + "Wire": lambda sh: sh.Wires[0], + "Face": lambda sh: sh.Faces[0], + "Shell": lambda sh: sh.Shells[0], + "Solid": lambda sh: sh.Solids[0], + "CompSolid": lambda sh: sh.CompSolids[0], + "Compound": lambda sh: sh.Compounds[0], } copier = copiers.get(shape.ShapeType) if copier is None: - copier = lambda(sh): sh.copy() + copier = lambda sh: sh.copy() FreeCAD.Console.PrintWarning("Lattice2: shallowCopy: unexpected shape type '{typ}'. Using deep copy instead.\n".format(typ= shape.ShapeType)) ret = copier(shape) if extra_placement is not None: diff --git a/lattice2Subsequencer.py b/lattice2Subsequencer.py index 18ae860..cb5682c 100644 --- a/lattice2Subsequencer.py +++ b/lattice2Subsequencer.py @@ -71,14 +71,14 @@ def traverseCompound(compound, traversal): return LCE.allLeaves(compound) element_extractors = { - "Vertex": (lambda(sh): sh.Vertexes), - "Edge": (lambda(sh): sh.Edges), - "Wire": (lambda(sh): sh.Wires), - "Face": (lambda(sh): sh.Faces), - "Shell": (lambda(sh): sh.Shells), - "Solid": (lambda(sh): sh.Solids), - "CompSolid": (lambda(sh): sh.CompSolids), - "Compound": (lambda(sh): sh.Compounds), + "Vertex": (lambda sh: sh.Vertexes), + "Edge": (lambda sh: sh.Edges), + "Wire": (lambda sh: sh.Wires), + "Face": (lambda sh: sh.Faces), + "Shell": (lambda sh: sh.Shells), + "Solid": (lambda sh: sh.Solids), + "CompSolid": (lambda sh: sh.CompSolids), + "Compound": (lambda sh: sh.Compounds), } def getIndexesIntoList(element, list_of_shapes):