From 82dc8c3c6f84775d1bc9c335eb0cedb62cd90c2c Mon Sep 17 00:00:00 2001 From: "luz.paz" Date: Fri, 3 Aug 2018 07:02:28 -0400 Subject: [PATCH] Fix all trailing whitespace This PR removes all trailing whitespace. Best to do this now before project gets further developed. --- InitGui.py | 20 ++--- README.md | 46 +++++----- a2p_AxialConnection.py | 105 +++++------------------ a2p_CircularEdgeConnection.py | 75 +++++------------ a2p_MuxAssembly.py | 98 +++++---------------- a2p_angleConnection.py | 97 ++++++--------------- a2p_importpart.py | 129 ++++++++++------------------ a2p_libDOF.py | 145 ++++++++++++++++---------------- a2p_planeConstraint.py | 102 +++++----------------- a2p_planesParallelConstraint.py | 104 +++++------------------ a2p_pointIdentityConnection.py | 109 +++++------------------- a2p_pointOnPlaneConstraint.py | 106 ++++++----------------- a2p_sphericalConnection.py | 91 +++++--------------- a2p_versionmanagement.py | 120 ++++++-------------------- a2p_viewProviderProxies.py | 111 ++++++++---------------- a2plib.py | 120 +++++++------------------- observers.py | 2 +- 17 files changed, 446 insertions(+), 1134 deletions(-) diff --git a/InitGui.py b/InitGui.py index 984a688a..417122f4 100644 --- a/InitGui.py +++ b/InitGui.py @@ -27,16 +27,16 @@ -class a2pWorkbench (Workbench): - +class a2pWorkbench (Workbench): + def __init__(self): import a2plib self.__class__.Icon = a2plib.pathOfModule() + "/icons/a2p_workbench.svg" self.__class__.MenuText = 'A2plus' self.__class__.ToolTip = 'An other assembly workbench for FreeCAD' - + def Initialize(self): - + import a2plib #QtCore.QResource.registerResource happens in assembly2lib import a2p_importpart import a2p_CircularEdgeConnection @@ -84,7 +84,7 @@ def Initialize(self): commandslist ) self.appendMenu( - 'A2p', + 'A2p', menuEntries ) #FreeCADGui.addPreferencePage( a2plib.pathOfModule() + '/GuiA2p/ui/a2p_prefs.ui','A2plus' ) @@ -92,12 +92,12 @@ def Initialize(self): a2plib.pathOfModule() + '/GuiA2p/Resources/ui/a2p_prefs.ui','A2plus' ) - + def Activated(self): import observers FreeCAD.addDocumentObserver(observers.redoUndoObserver) - + def Deactivated(self): import observers FreeCAD.removeDocumentObserver(observers.redoUndoObserver) @@ -108,9 +108,9 @@ def ContextMenu(self, recipient): if len(selection) == 1: obj = selection[0] if 'sourceFile' in obj.Content: - self.appendContextMenu( - "A2p", - [ + self.appendContextMenu( + "A2p", + [ 'a2p_movePart', 'a2p_duplicatePart', 'a2p_editImportedPart', diff --git a/README.md b/README.md index 53c43a7e..ba766fda 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Similar is: Different is: * A new designed solving algorithm, able to solve some more complicated relations. -* Different and in future more constraints, internally with different names. +* Different and in future more constraints, internally with different names. * No animation for degrees of freedom, as difficult for new solver type. * No parts list at moment. Export to office spreadsheats planned for future versions. * No collision check of parts at moment. Planned for future versions @@ -107,48 +107,48 @@ As your first steps learning this workbench, please have look at tutorials relat You can follow the tool-tips in the workbench's toolbar. They describe exactly what to do in which order. Current Features like shown in the workbench's toolbar: -* Add a part from external file (Shift+A) - +* Add a part from external file (Shift+A) - Begin and continue here with adding (importing existing files) .fcstd parts -* Update parts imported into the assembly - +* Update parts imported into the assembly - Use this to refresh changed parts already assembled * Move part - Just move selected part -* Duplicate part - +* Duplicate part - Adds one or more previously imported part into assembly -* Edit - +* Edit - Opens the selected assembly part to be changed in a new tab -* Add a point-to-point identity {pointIdentityConstraint} - +* Add a point-to-point identity {pointIdentityConstraint} - Fix a point vertex to another point vertex -* Add a point-on-line match {pointOnLineConstraint} - +* Add a point-on-line match {pointOnLineConstraint} - Fix a point vertex to a line vertex -* Add a point-on-plane match {pointOnPlaneConstraint} - +* Add a point-on-plane match {pointOnPlaneConstraint} - Fix a point vertex to be on a plane -* Add a circular-to-circular edge match {circularEdgeConstraint} - - Fix one circular edge to another. You can choose a special direction (aligned, opposed or none). +* Add a circular-to-circular edge match {circularEdgeConstraint} - + Fix one circular edge to another. You can choose a special direction (aligned, opposed or none). An offset can be applied -* Add a plane-to-plane parallelism {planeParallel} - +* Add a plane-to-plane parallelism {planeParallel} - Adjust selected planes to be parallel. You can choose a special direction (aligned, opposed) -* Add a plane-to-plane offset {planeConstraint} - +* Add a plane-to-plane offset {planeConstraint} - Makes planes parallel and offers to give an offset value and direction (aligned, opposed,none) -* Add an axis-to-axis identity {axialConstraint} - +* Add an axis-to-axis identity {axialConstraint} - Makes cylindrical objects or two axes to be axially aligned -* Add an angle between planes {angledPlanesConstraint} - +* Add an angle between planes {angledPlanesConstraint} - Selected planes make the latter object to be rotated by your edited 'angle' value. - Keep the angle between aprox 0.1° and 179.9° or use workarounds. -* Add a spherical constraint between objects - + Keep the angle between aprox 0.1° and 179.9° or use workarounds. +* Add a spherical constraint between objects - Select spheres to be aligned or vertex/sphere or vertex/vertex -* Solve A2plus constraints - +* Solve A2plus constraints - Manually invoke the A2pus solver (especially when AutoSolve is OFF) -* Delete constraints - +* Delete constraints - Remove all constraints of selected part in one step -* View constrained element - +* View constrained element - Show all elements for a Tree view selected constraint -* SAS Create or refresh simple shape of complete assembly - +* SAS Create or refresh simple shape of complete assembly - the newly created compound can be found in tree vies -* Toggle transparency of assembly - +* Toggle transparency of assembly - The whole assembly will get transparent -* Show only selected items (or all if none selected) - +* Show only selected items (or all if none selected) - Just another visibility helper -* Toggle AutoSolve - +* Toggle AutoSolve - Normally the solver defaults to and works with AutoSolve, but for larger assemblies one may chose OFF and solve manually, as it saves computation time. diff --git a/a2p_AxialConnection.py b/a2p_AxialConnection.py index 97500200..267770cf 100644 --- a/a2p_AxialConnection.py +++ b/a2p_AxialConnection.py @@ -46,11 +46,11 @@ def parseSelection(selection, objectToUpdate=None): [s2.ObjectName, s2.SubElementNames[0], s2.Object.Label ] ] if not validSelection: msg = ''' - To add an axial constraint select two cylindrical surfaces or two + To add an axial constraint select two cylindrical surfaces or two straight lines, each from a different part. Selection made:%s ''' % printSelection(selection) QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return + return if objectToUpdate == None: cName = findUnusedObjectName('axialConstraint') @@ -60,15 +60,15 @@ def parseSelection(selection, objectToUpdate=None): c.addProperty("App::PropertyString","SubElement1","ConstraintInfo").SubElement1 = cParms[0][1] c.addProperty("App::PropertyString","Object2","ConstraintInfo").Object2 = cParms[1][0] c.addProperty("App::PropertyString","SubElement2","ConstraintInfo").SubElement2 = cParms[1][1] - + c.addProperty("App::PropertyEnumeration","directionConstraint", "ConstraintInfo") c.directionConstraint = ["none","aligned","opposed"] c.addProperty("App::PropertyBool","lockRotation","ConstraintInfo") - + c.setEditorMode('Type',1) for prop in ["Object1","Object2","SubElement1","SubElement2"]: - c.setEditorMode(prop, 1) - + c.setEditorMode(prop, 1) + #------------------------------------------- # Group correctly under ParentObject in tree #------------------------------------------- @@ -79,11 +79,11 @@ def parseSelection(selection, objectToUpdate=None): #------------------------------------------- c.Proxy = ConstraintObjectProxy() - c.ViewObject.Proxy = ConstraintViewProviderProxy( - c, - path_a2p + '/icons/a2p_axialConstraint.svg', - True, - cParms[1][2], + c.ViewObject.Proxy = ConstraintViewProviderProxy( + c, + path_a2p + '/icons/a2p_axialConstraint.svg', + True, + cParms[1][2], cParms[0][2] ) else: @@ -93,7 +93,7 @@ def parseSelection(selection, objectToUpdate=None): c.Object2 = cParms[1][0] c.SubElement2 = cParms[1][1] updateObjectProperties(c) - + c.purgeTouched() c.Proxy.callSolveConstraints() @@ -121,83 +121,18 @@ def Activated(self): parseSelection( selection ) else: FreeCADGui.Selection.clearSelection() - ConstraintSelectionObserver( - AxialSelectionGate(), + ConstraintSelectionObserver( + AxialSelectionGate(), parseSelection, - taskDialog_title ='add axial constraint', - taskDialog_iconPath = self.GetResources()['Pixmap'], + taskDialog_title ='add axial constraint', + taskDialog_iconPath = self.GetResources()['Pixmap'], taskDialog_text = selection_text ) - def GetResources(self): + def GetResources(self): return { - 'Pixmap' : path_a2p + '/icons/a2p_axialConstraint.svg', - 'MenuText': 'Add axial constraint', + 'Pixmap' : path_a2p + '/icons/a2p_axialConstraint.svg', + 'MenuText': 'Add axial constraint', 'ToolTip': toolTipText - } + } FreeCADGui.addCommand('a2p_AxialConnection', a2p_AxialConnectionCommand()) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/a2p_CircularEdgeConnection.py b/a2p_CircularEdgeConnection.py index 6ad889a8..77c2c718 100644 --- a/a2p_CircularEdgeConnection.py +++ b/a2p_CircularEdgeConnection.py @@ -54,27 +54,27 @@ def parseSelection(selection, objectToUpdate=None, callSolveConstraints=True, lo if not validSelection: msg = '''Please select two circular edges from different parts. But election made is:%s''' % printSelection(selection) QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return + return if objectToUpdate == None: cName = findUnusedObjectName('circularEdgeConstraint') c = FreeCAD.ActiveDocument.addObject("App::FeaturePython", cName) - + c.addProperty("App::PropertyString","Type","ConstraintInfo").Type = 'circularEdge' c.addProperty("App::PropertyString","Object1","ConstraintInfo").Object1 = cParms[0][0] c.addProperty("App::PropertyString","SubElement1","ConstraintInfo").SubElement1 = cParms[0][1] c.addProperty("App::PropertyString","Object2","ConstraintInfo").Object2 = cParms[1][0] c.addProperty("App::PropertyString","SubElement2","ConstraintInfo").SubElement2 = cParms[1][1] - + c.addProperty("App::PropertyEnumeration","directionConstraint", "ConstraintInfo") c.directionConstraint = ["none","aligned","opposed"] c.addProperty("App::PropertyDistance","offset","ConstraintInfo") c.addProperty("App::PropertyBool","lockRotation","ConstraintInfo").lockRotation = lockRotation - + c.setEditorMode('Type',1) for prop in ["Object1","Object2","SubElement1","SubElement2"]: - c.setEditorMode(prop, 1) - + c.setEditorMode(prop, 1) + #------------------------------------------- # Group correctly under ParentObject in tree #------------------------------------------- @@ -85,11 +85,11 @@ def parseSelection(selection, objectToUpdate=None, callSolveConstraints=True, lo #------------------------------------------- c.Proxy = ConstraintObjectProxy() - c.ViewObject.Proxy = ConstraintViewProviderProxy( - c, - path_a2p + '/icons/a2p_circularEdgeConstraint.svg', - True, - cParms[1][2], + c.ViewObject.Proxy = ConstraintViewProviderProxy( + c, + path_a2p + '/icons/a2p_circularEdgeConstraint.svg', + True, + cParms[1][2], cParms[0][2] ) else: @@ -102,7 +102,7 @@ def parseSelection(selection, objectToUpdate=None, callSolveConstraints=True, lo c.purgeTouched() if callSolveConstraints: - c.Proxy.callSolveConstraints() + c.Proxy.callSolveConstraints() #FreeCADGui.Selection.clearSelection() #FreeCADGui.Selection.addSelection(c) return c @@ -121,7 +121,7 @@ def parseSelection(selection, objectToUpdate=None, callSolveConstraints=True, lo 1.) select circular edge on first importPart 2.) select circular edge on other importPart ''' - + class a2p_CircularEdgeConnectionCommand: def Activated(self): @@ -130,51 +130,20 @@ def Activated(self): parseSelection( selection ) else: FreeCADGui.Selection.clearSelection() - ConstraintSelectionObserver( - CircularEdgeSelectionGate(), + ConstraintSelectionObserver( + CircularEdgeSelectionGate(), parseSelection, - taskDialog_title ='add circular edge constraint', - taskDialog_iconPath = self.GetResources()['Pixmap'], + taskDialog_title ='add circular edge constraint', + taskDialog_iconPath = self.GetResources()['Pixmap'], taskDialog_text = selection_text, - secondSelectionGate = CircularEdgeSelectionGate2() + secondSelectionGate = CircularEdgeSelectionGate2() ) - def GetResources(self): + def GetResources(self): return { - 'Pixmap' : path_a2p + '/icons/a2p_circularEdgeConstraint.svg' , - 'MenuText': 'Add circular edge connection', + 'Pixmap' : path_a2p + '/icons/a2p_circularEdgeConstraint.svg' , + 'MenuText': 'Add circular edge connection', 'ToolTip': toolTipText - } + } FreeCADGui.addCommand('a2p_CircularEdgeConnection', a2p_CircularEdgeConnectionCommand()) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/a2p_MuxAssembly.py b/a2p_MuxAssembly.py index 5f0237c6..02b0e1eb 100644 --- a/a2p_MuxAssembly.py +++ b/a2p_MuxAssembly.py @@ -48,11 +48,11 @@ def muxObjectsWithKeys(doc, withColor=False): faces = [] faceColors = [] muxInfo = [] # List of keys, not used at moment... - + visibleObjects = [ obj for obj in doc.Objects if hasattr(obj,'ViewObject') and obj.ViewObject.isVisible() and hasattr(obj,'Shape') and len(obj.Shape.Faces) > 0 and 'Body' not in obj.Name] - + for obj in visibleObjects: # Save Computing time, store this before the for..enumerate loop later... colorFlag = ( len(obj.ViewObject.DiffuseColor) < len(obj.Shape.Faces) ) @@ -67,9 +67,9 @@ def muxObjectsWithKeys(doc, withColor=False): faceColors.append(shapeCol) else: faceColors.append(diffuseCol[i]) - + shell = Part.makeShell(faces) - if withColor: + if withColor: return muxInfo, shell, faceColors else: return muxInfo, shell @@ -93,7 +93,7 @@ def __init__(self, obj): obj.addProperty("App::PropertyString", "type").type = 'SimpleAssemblyShape' obj.addProperty("App::PropertyFloat", "timeOfGenerating").timeOfGenerating = time.time() obj.Proxy = self - + def onChanged(self, fp, prop): pass @@ -107,20 +107,20 @@ def __init__(self,obj): def onDelete(self, viewObject, subelements): return True - + def __getstate__(self): return None def __setstate__(self, state): return None - + def getIcon(self): return a2plib.path_a2p + '/icons/simpleAssemblyShape.svg' - + def attach(self, obj): self.object_Name = obj.Object.Name self.Object = obj.Object - + def getDisplayModes(self,obj): "Return a list of display modes." modes=[] @@ -128,32 +128,32 @@ def getDisplayModes(self,obj): modes.append("Wireframe") modes.append("Flat Lines") return modes - + def getDefaultDisplayMode(self): "Return the name of the default display mode. It must be defined in getDisplayModes." return "Flat Lines" - + def setDisplayMode(self,mode): return mode - + def createOrUpdateSimpleAssemblyShape(doc): visibleImportObjects = [ obj for obj in doc.Objects if 'importPart' in obj.Content - and hasattr(obj,'ViewObject') + and hasattr(obj,'ViewObject') and obj.ViewObject.isVisible() - and hasattr(obj,'Shape') - and len(obj.Shape.Faces) > 0 + and hasattr(obj,'Shape') + and len(obj.Shape.Faces) > 0 ] - + if len(visibleImportObjects) == 0: - QtGui.QMessageBox.critical( QtGui.QApplication.activeWindow(), - "Cannot create SimpleAssemblyShape", - "No visible ImportParts found" + QtGui.QMessageBox.critical( QtGui.QApplication.activeWindow(), + "Cannot create SimpleAssemblyShape", + "No visible ImportParts found" ) return - - sas = doc.getObject('SimpleAssemblyShape') + + sas = doc.getObject('SimpleAssemblyShape') if sas == None: sas = doc.addObject("Part::FeaturePython","SimpleAssemblyShape") SimpleAssemblyShape(sas) @@ -172,7 +172,7 @@ class a2p_SimpleAssemblyShapeCommand(): def GetResources(self): import a2plib - return {'Pixmap' : a2plib.path_a2p +'/icons/a2p_simpleAssemblyShape.svg', + return {'Pixmap' : a2plib.path_a2p +'/icons/a2p_simpleAssemblyShape.svg', 'MenuText': "create or refresh simple Shape of complete Assembly", 'ToolTip': "create or refresh simple Shape of complete Assembly" } @@ -185,57 +185,5 @@ def Activated(self): def IsActive(self): return True - -FreeCADGui.addCommand('a2p_SimpleAssemblyShapeCommand',a2p_SimpleAssemblyShapeCommand()) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +FreeCADGui.addCommand('a2p_SimpleAssemblyShapeCommand',a2p_SimpleAssemblyShapeCommand()) diff --git a/a2p_angleConnection.py b/a2p_angleConnection.py index 4982df23..89c3e7a1 100644 --- a/a2p_angleConnection.py +++ b/a2p_angleConnection.py @@ -49,13 +49,13 @@ def parseSelection(selection, objectToUpdate=None): [s2.ObjectName, s2.SubElementNames[0], s2.Object.Label ] ] if not validSelection: msg = ''' - Angle constraint requires a selection of 2 planes + Angle constraint requires a selection of 2 planes each on different objects. Selection made: %s ''' % printSelection(selection) QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return - + return + # calculate recent angle here to be stored in property "angle" ob1 = FreeCAD.activeDocument().getObject(s1.ObjectName) ob2 = FreeCAD.activeDocument().getObject(s2.ObjectName) @@ -64,7 +64,7 @@ def parseSelection(selection, objectToUpdate=None): normal1 = plane1.Surface.Axis normal2 = plane2.Surface.Axis angle = normal2.getAngle(normal1) / 2.0 / math.pi * 360.0 - + if objectToUpdate == None: cName = findUnusedObjectName('angledPlanesContraint') c = FreeCAD.ActiveDocument.addObject("App::FeaturePython", cName) @@ -79,8 +79,8 @@ def parseSelection(selection, objectToUpdate=None): c.Object2 = cParms[1][0] c.SubElement2 = cParms[1][1] for prop in ["Object1","Object2","SubElement1","SubElement2","Type"]: - c.setEditorMode(prop, 1) - + c.setEditorMode(prop, 1) + #------------------------------------------- # Group correctly under ParentObject in tree #------------------------------------------- @@ -89,13 +89,13 @@ def parseSelection(selection, objectToUpdate=None): c.setEditorMode('ParentTreeObject',1) parent.Label = parent.Label # this is needed to trigger an update #------------------------------------------- - + c.Proxy = ConstraintObjectProxy() - c.ViewObject.Proxy = ConstraintViewProviderProxy( - c, - path_a2p +'/icons/a2p_angleConstraint.svg', - True, - cParms[1][2], + c.ViewObject.Proxy = ConstraintViewProviderProxy( + c, + path_a2p +'/icons/a2p_angleConstraint.svg', + True, + cParms[1][2], cParms[0][2] ) else: @@ -105,10 +105,10 @@ def parseSelection(selection, objectToUpdate=None): c.Object2 = cParms[1][0] c.SubElement2 = cParms[1][1] updateObjectProperties(c) - + c.purgeTouched() c.Proxy.callSolveConstraints() - + selection_text = \ ''' @@ -146,69 +146,20 @@ def Activated(self): parseSelection( selection ) else: FreeCADGui.Selection.clearSelection() - ConstraintSelectionObserver( - PlanesAngleSelectionGate(), + ConstraintSelectionObserver( + PlanesAngleSelectionGate(), parseSelection, - taskDialog_title ='add angle between planes constraint', - taskDialog_iconPath = self.GetResources()['Pixmap'], + taskDialog_title ='add angle between planes constraint', + taskDialog_iconPath = self.GetResources()['Pixmap'], taskDialog_text = selection_text, - secondSelectionGate = PlanesAngleSelectionGate2() + secondSelectionGate = PlanesAngleSelectionGate2() ) - - def GetResources(self): + + def GetResources(self): return { - 'Pixmap' : path_a2p + '/icons/a2p_angleConstraint.svg', - 'MenuText': 'angle between planes constraint', + 'Pixmap' : path_a2p + '/icons/a2p_angleConstraint.svg', + 'MenuText': 'angle between planes constraint', 'ToolTip': toolTipText, - } + } FreeCADGui.addCommand('a2p_AngledPlanesCommand', a2p_AngledPlanesCommand()) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/a2p_importpart.py b/a2p_importpart.py index cb58292f..07b37330 100644 --- a/a2p_importpart.py +++ b/a2p_importpart.py @@ -55,23 +55,23 @@ def cleanUp(self,doc): def add(self,fileName,obj): # pi_obj = PartInformation-Object self.objects[fileName] = obj - + def get(self,fileName): obj = self.objects.get(fileName,None) if obj: return obj else: return None - + def isCached(self,fileName): if fileName in self.objects.keys(): return True else: return False - + def len(self): return len(self.objects.keys()) - + objectCache = ObjectCache() @@ -98,16 +98,16 @@ def importPartFromFile(_doc, filename, importToCache=False): visibleObjects = [ obj for obj in importDoc.Objects if hasattr(obj,'ViewObject') and obj.ViewObject.isVisible() and hasattr(obj,'Shape') and len(obj.Shape.Faces) > 0 and 'Body' not in obj.Name] - + if visibleObjects == None or len(visibleObjects) == 0: msg = "No visible Part to import found. Aborting operation" QtGui.QMessageBox.information( - QtGui.QApplication.activeWindow(), - "Import Error", + QtGui.QApplication.activeWindow(), + "Import Error", msg ) return - + #------------------------------------------- # Discover whether we are importing a subassembly or a single part #------------------------------------------- @@ -115,7 +115,7 @@ def importPartFromFile(_doc, filename, importToCache=False): subAssemblyImport = False if len(visibleObjects) > 1: subAssemblyImport = True - + #------------------------------------------- # create new object #------------------------------------------- @@ -128,8 +128,8 @@ def importPartFromFile(_doc, filename, importToCache=False): partLabel = a2plib.findUnusedObjectLabel( importDoc.Label, document=doc ) newObj = doc.addObject("Part::FeaturePython",partName.encode('utf-8')) newObj.Label = partLabel - - + + newObj.addProperty("App::PropertyString", "a2p_Version","importPart").a2p_Version = A2P_VERSION newObj.addProperty("App::PropertyFile", "sourceFile", "importPart").sourceFile = filename newObj.addProperty("App::PropertyStringList","muxInfo","importPart") @@ -152,7 +152,7 @@ def importPartFromFile(_doc, filename, importToCache=False): if appVersionStr() <= '000.016': #FC0.17: DiffuseColor overrides ShapeColor ! newObj.ViewObject.DiffuseColor = tmpObj.ViewObject.DiffuseColor newObj.muxInfo = createTopoInfo(tmpObj) - + newObj.Proxy = Proxy_muxAssemblyObj() newObj.ViewObject.Proxy = ImportedPartViewProviderProxy() @@ -160,10 +160,10 @@ def importPartFromFile(_doc, filename, importToCache=False): if importToCache: objectCache.add(newObj.sourceFile, newObj) - + if not importDocIsOpen: FreeCAD.closeDocument(importDoc.Name) - + return newObj @@ -171,7 +171,7 @@ class a2p_ImportPartCommand(): def GetResources(self): import a2plib - return {'Pixmap' : a2plib.pathOfModule()+'/icons/a2p_ImportPart.svg', + return {'Pixmap' : a2plib.pathOfModule()+'/icons/a2p_ImportPart.svg', 'Accel' : "Shift+A", # a default shortcut (optional) 'MenuText': "add Part from external file", 'ToolTip' : "add Part from external file" @@ -197,26 +197,26 @@ def Activated(self): if not a2plib.checkFileIsInProjectFolder(filename): msg = \ ''' -The part you try to import is +The part you try to import is outside of your project-folder ! Check your settings of A2plus preferences. ''' QtGui.QMessageBox.information( - QtGui.QApplication.activeWindow(), - "Import Error", + QtGui.QApplication.activeWindow(), + "Import Error", msg ) return importedObject = importPartFromFile(doc, filename) - + mw = FreeCADGui.getMainWindow() mdi = mw.findChild(QtGui.QMdiArea) sub = mdi.activeSubWindow() if sub != None: sub.showMaximized() - - + + if not importedObject.fixedPosition: #will be true for the first imported part PartMover( view, importedObject ) else: @@ -230,13 +230,13 @@ def IsActive(self): """Here you can define if the command must be active or not (greyed) if certain conditions are met or not. This function is optional.""" return True - + def GuiViewFit(self): FreeCADGui.SendMsgToActiveView("ViewFit") self.timer.stop() -FreeCADGui.addCommand('a2p_ImportPart',a2p_ImportPartCommand()) +FreeCADGui.addCommand('a2p_ImportPart',a2p_ImportPartCommand()) @@ -253,19 +253,19 @@ def updateImportedParts(doc): obj.setEditorMode("a2p_Version",1) if not hasattr( obj, 'muxInfo'): obj.addProperty("App::PropertyStringList","muxInfo","importPart").muxInfo = [] - - if a2plib.USE_PROJECTFILE: + + if a2plib.USE_PROJECTFILE: replacement = a2plib.findSourceFileInProject(obj.sourceFile) # work in any case with files within projectFolder! else: replacement = obj.sourceFile - + if replacement == None: - QtGui.QMessageBox.critical( QtGui.QApplication.activeWindow(), - "Source file not found", + QtGui.QMessageBox.critical( QtGui.QApplication.activeWindow(), + "Source file not found", "update of %s aborted!\nUnable to find %s" % ( - obj.Name, + obj.Name, obj.sourceFile - ) + ) ) else: obj.sourceFile = replacement # update Filepath, perhaps location changed ! @@ -289,7 +289,7 @@ def updateImportedParts(doc): obj.Shape = newObject.Shape.copy() obj.ViewObject.DiffuseColor = copy.copy(newObject.ViewObject.DiffuseColor) obj.Placement = savedPlacement # restore the old placement - + mw = FreeCADGui.getMainWindow() mdi = mw.findChild(QtGui.QMdiArea) sub = mdi.activeSubWindow() @@ -298,10 +298,10 @@ def updateImportedParts(doc): objectCache.cleanUp(doc) solversystem.solveConstraints(doc) doc.recompute() - + class a2p_UpdateImportedPartsCommand: - + def Activated(self): doc = FreeCAD.ActiveDocument updateImportedParts(doc) @@ -312,7 +312,7 @@ def GetResources(self): 'MenuText': 'Update parts imported into the assembly', 'ToolTip': 'Update parts imported into the assembly' } - + FreeCADGui.addCommand('a2p_updateImportedParts', a2p_UpdateImportedPartsCommand()) @@ -389,8 +389,8 @@ def Activated(self): "Use project Folder" ''' QtGui.QMessageBox.critical( - QtGui.QApplication.activeWindow(), - "File error ! ", + QtGui.QApplication.activeWindow(), + "File error ! ", msg ) return @@ -403,7 +403,7 @@ def Activated(self): FreeCAD.setActiveDocument( name ) FreeCAD.ActiveDocument=FreeCAD.getDocument( name ) FreeCADGui.ActiveDocument=FreeCADGui.getDocument( name ) - + def GetResources(self): return { 'Pixmap' : a2plib.pathOfModule()+'/icons/a2p_EditPart.svg', @@ -495,7 +495,7 @@ def Activated(self): response = QtGui.QMessageBox.critical(QtGui.QApplication.activeWindow(), "Delete constraints?", msg, flags ) if response == QtGui.QMessageBox.Yes: for c in deleteList: - a2plib.removeConstraint(c) + a2plib.removeConstraint(c) def GetResources(self): return { 'Pixmap' : a2plib.pathOfModule()+'/icons/a2p_deleteConnections.svg', @@ -534,9 +534,9 @@ def GetResources(self): 'MenuText': 'show connected elements', 'ToolTip': 'show connected elements', } - + FreeCADGui.addCommand('a2p_ViewConnectionsCommand', ViewConnectionsCommand()) - + class ViewConnectionsObserver: def __init__(self): self.ignoreClear = False @@ -585,14 +585,14 @@ def Activated(self): obj.ViewObject.Visibility = True else: obj.ViewObject.Visibility = False - + def GetResources(self): return { 'Pixmap' : a2plib.pathOfModule()+'/icons/a2p_isolate.svg', 'MenuText': 'show only selected elements, or all if none is selected', 'ToolTip': 'show only selected elements, or all if none is selected' } - + FreeCADGui.addCommand('a2p_isolateCommand', a2p_isolateCommand()) @@ -675,7 +675,7 @@ def GetResources(self): def a2p_repairTreeView(): doc = FreeCAD.activeDocument() if doc == None: return - + constraints = [ obj for obj in doc.Objects if 'ConstraintInfo' in obj.Content] for c in constraints: if c.Proxy != None: @@ -735,46 +735,3 @@ def GetResources(self): def importUpdateConstraintSubobjects( doc, oldObject, newObject ): ''' updating constraints, deactivated at moment''' return - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/a2p_libDOF.py b/a2p_libDOF.py index c21ce7bd..80cdc99b 100644 --- a/a2p_libDOF.py +++ b/a2p_libDOF.py @@ -34,7 +34,7 @@ This code was possible only after the reading of the Hamish's code on His wonderful Assembly2 Workbench for FreeCAD This code was possible only after the reading of the code of the wonderful WorkFeature Macro for FreeCAD -This code was possible only after the reading of Wikipedia pages on vector math +This code was possible only after the reading of Wikipedia pages on vector math ''' #define some reference axis @@ -71,7 +71,7 @@ def create_Axis(_base, _direction): return axis -#create an axis that has Base in the first vector argument and direction defined by _start to _end shifted at SystemOrigin +#create an axis that has Base in the first vector argument and direction defined by _start to _end shifted at SystemOrigin def create_Axis2Points(_start, _end): axis=FreeCAD.Axis() axis.Base = _start @@ -81,8 +81,8 @@ def create_Axis2Points(_start, _end): def copynorm_AxisToOrigin(axisa, dbg=False): _offset = SystemOrigin.sub(axisa.Base) - axisb = FreeCAD.Axis(axisa) - if dbg: print axisa, axisb + axisb = FreeCAD.Axis(axisa) + if dbg: print axisa, axisb axisb.move(_offset) if dbg: print axisa, axisb #axisb.Base = SystemOrigin @@ -95,19 +95,19 @@ def copynorm_AxisToOrigin(axisa, dbg=False): def normal_2Axis(axisa,axisb,dbg=False): #move vectors to origin and normalize axis1 = copynorm_AxisToOrigin(axisa) - axis2 = copynorm_AxisToOrigin(axisb) + axis2 = copynorm_AxisToOrigin(axisb) - #create an axis with base at SystemOrigin + #create an axis with base at SystemOrigin axisN = FreeCAD.Axis() - #set the right direction - axisN.Direction = axis1.Direction.cross(axis2.Direction) - if dbg: print axis1, axis2, axisN + #set the right direction + axisN.Direction = axis1.Direction.cross(axis2.Direction) + if dbg: print axis1, axis2, axisN return axisN -#create a plane normal to the given axis, return the 2 axis which define that plane +#create a plane normal to the given axis, return the 2 axis which define that plane def make_planeNormal(axisa,dbg=False): axis1 = copynorm_AxisToOrigin(axisa) - + planenormal = Part.makePlane(1.0,1.0, axis1.Base, axis1.Direction) freeAx1 = FreeCAD.Axis() freeAx2 = FreeCAD.Axis() @@ -137,8 +137,8 @@ def check_ifPerpendicular(axisa,axisb,dbg=False): #shift edges to the origin and normalize them #move vectors to origin and normalize axis1 = copynorm_AxisToOrigin(axisa) - axis2 = copynorm_AxisToOrigin(axisb) - + axis2 = copynorm_AxisToOrigin(axisb) + if abs(axis1.Direction.dot(axis2.Direction)) <= tolerance: if dbg:print("Perpendicular Edges" , axis1, axis2 ) return True @@ -157,15 +157,15 @@ def check_ifCollinear(axisa,axisb,dbg=False): if check_ifParallel(axis1,axis2): return True else: - return False - baseMove = SystemOrigin.sub(axis1.Base) + return False + baseMove = SystemOrigin.sub(axis1.Base) axis1.Base = SystemOrigin axis2.move(baseMove) axis1.Direction = axis1.Direction.normalize() #useless? axis2.Direction = axis2.Direction.normalize() #useless? axis3 = FreeCAD.Axis() - axis3.Direction = axis2.Base #create an axis with direction base1 to base2 - + axis3.Direction = axis2.Base #create an axis with direction base1 to base2 + if check_ifParallel(axis1,axis3) and check_ifParallel(axis2,axis3): if dbg:print("Collinear Edges" , axis1, axis2 ) return True @@ -185,7 +185,7 @@ def check_ifCoincident(Vertex1, Vertex2, dbg=False): if dbg: print "Vertexes Coincident", Vertex1, Vertex2 return True else: - if dbg: print "Vertexes Not Coincident", Vertex1, Vertex2 + if dbg: print "Vertexes Not Coincident", Vertex1, Vertex2 return False #check if a point is on an axis @@ -193,15 +193,15 @@ def check_ifPointOnAxis(vertexa, axisa, dbg=False): #shift edges to the origin and normalize them #move vectors to origin and normalize axis1 = copy_AxisToOrigin(axisa) - vertex1 = FreeCAD.Vector(vertexa) - _offset = SystemOrigin.sub(axis1.Base) + vertex1 = FreeCAD.Vector(vertexa) + _offset = SystemOrigin.sub(axis1.Base) vertex1 = vertex1.sub(axis1.Base) #apply the same offset to the point if abs((axis1.Direction.cross(vertex1)).Length) <= tolerance: if dbg:print("Point on Axis" , vertex1, axis1 ) return True else: if dbg:print("Point not on Axis", vertex1, axis1 ) - return False + return False @@ -211,7 +211,7 @@ def check_ifPointOnAxis(vertexa, axisa, dbg=False): #start with Axis Alignment which takes an axis as arguments and operates according to the remaining dof #this basic constraint affects only rotation DOF def AxisAlignment(axisa , dofrot, dbg=True): - currentDOFROTnum = len(dofrot) + currentDOFROTnum = len(dofrot) if currentDOFROTnum == 0 : #already locked on rotation so ignore it return [] elif currentDOFROTnum == 1 : #partially locked on rotation so compare to the given axis @@ -225,7 +225,7 @@ def AxisAlignment(axisa , dofrot, dbg=True): return [axisa] else: #this shouldn't happens...ignore it and return the current dofrot - return dofrot + return dofrot #then Lock Rotation which locks the remaining rotation axis when enabled @@ -236,13 +236,13 @@ def LockRotation(enabled, dofrot, dbg=True): return [] else: #nothing to do return the given dofrot - return dofrot + return dofrot #then Angle Alignment which takes an axis as arguments and operates according to the remaining dof #the axis is the normal of the angled plane, that said it acts exaclty as axis alignment, meybe I'll remove it #this basic constraint affects only rotation DOF def AngleAlignment(axisa , dofrot, dbg=True): - currentDOFROTnum = len(dofrot) + currentDOFROTnum = len(dofrot) if currentDOFROTnum == 0 : #already locked on rotation so ignore it return dofrot elif currentDOFROTnum == 1 : #partially locked on rotation so compare to the given axis @@ -256,7 +256,7 @@ def AngleAlignment(axisa , dofrot, dbg=True): return [axisa] else: #this shouldn't happens...ignore it and return the current dofrot - return dofrot + return dofrot @@ -265,9 +265,9 @@ def AngleAlignment(axisa , dofrot, dbg=True): #the first is axis normal on plane to plane distance #arguments are #axisa which the axis used in constraint (axial, circular edge, etc...) -#dofpos which is the array of left free positional axes +#dofpos which is the array of left free positional axes def AxisDistance(axisa, dofpos, dbg=False): - currentDOFPOSnum = len(dofpos) + currentDOFPOSnum = len(dofpos) if currentDOFPOSnum == 0 : #already locked on position so ignore it return [] elif currentDOFPOSnum == 1 : #partially locked on position so compare axis free to the given axis @@ -281,28 +281,28 @@ def AxisDistance(axisa, dofpos, dbg=False): #calculate the axis normal to the plane defined by the 2 axes left free tempNormAxis = normal_2Axis(dofpos[0], dofpos[1]) #now compare it to the given axis - - if check_ifPerpendicular(axisa,tempNormAxis): + + if check_ifPerpendicular(axisa,tempNormAxis): #axes are perpendicular so the axis left free is the normal to the plane defined by given axis and tempNormAxis DOFPOS=1 return [ normal_2Axis(axisa, tempNormAxis)] - else: + else: #the object is fully constrained DOFPOS=0 return [] - + elif currentDOFPOSnum == 3 : # there are no constraints on position, so the rigid can slides along the given axis, DOFPOS=1 return [axisa] - - else: + + else: #this shouldn't happens...ignore it and return the current dofrot - return dofpos + return dofpos + - #then plane to plane constraint #arguments are #axisa which the axis normal to the plane constrained -#dofpos which is the array of left free positional axes +#dofpos which is the array of left free positional axes def planeOffset(axisa, dofpos, dbg=False): - currentDOFPOSnum = len(dofpos) + currentDOFPOSnum = len(dofpos) if currentDOFPOSnum == 0 : #already locked on position so ignore it return [] elif currentDOFPOSnum == 1 : #partially locked on position so compare to the given axis @@ -319,17 +319,17 @@ def planeOffset(axisa, dofpos, dbg=False): if check_ifParallel(axisa,tempNormAxis): #the plane is parallel to the plane where it can slide, so the constraint is redundant, return dofpos as is DOFPOS=2 return dofpos - else: + else: #now calculate the axis normal to the plane create by the given axis and the tempNormAxis - #and return it as last free DOFPOS=1 + #and return it as last free DOFPOS=1 return [ normal_2Axis(axisa, tempNormAxis) ] - + elif currentDOFPOSnum == 3 : # there are no constraints on position, so the left axes free are the two axes which define a plane normal to the given axis DOFPOS=2 return make_planeNormal(axisa) - - else: + + else: #this shouldn't happens...ignore it and return the current dofrot - return dofpos + return dofpos #this is very tricky... @@ -338,25 +338,25 @@ def PointIdentityPos(pointA, rigidCenterpoint, dofpos, pointconstraints, dbg=Tru #the center of rigid is coincident to the point constrained, the obj can't move anymore DOFPOS=0 return [] else: - #check how many DOF - currentDOFPOSnum = len(dofpos) + #check how many DOF + currentDOFPOSnum = len(dofpos) for a in len(pointconstraints): if check_ifCoincident(pointA,pointconstraints[a]): #the same point is already constrained so skip it , redundant return dofpos - + if currentDOFPOSnum == 0 : #already locked on position so ignore it return [] - + elif currentDOFPOSnum == 1 : #already partially locked, an additional point identity locks the object return [] #if the point isn't already constrained, the obj is now fully constrained DOFPOS=0 - elif currentDOFPOSnum == 2 : + elif currentDOFPOSnum == 2 : return [] #if the point isn't already constrained, the obj is now fully constrained DOFPOS=0 - elif currentDOFPOSnum == 3 : + elif currentDOFPOSnum == 3 : #if there is only 1 pointidentity do nothing, as single point constraint doesn't lock anything just store the point - if len(pointconstraints) == 0: + if len(pointconstraints) == 0: pointconstraints.append(pointA) #in this way I should modify the array outside the function return dofpos else: #add the point to the pointconstraint array @@ -371,66 +371,66 @@ def PointIdentityPos(pointA, rigidCenterpoint, dofpos, pointconstraints, dbg=Tru return [] else: #this shouldn't happens...ignore it and return the current dofrot - return dofpos + return dofpos #this is very tricky...call it always after PointIdentityPos as pointconstraints is handled only there def PointIdentityRot(pointA, dofrot, pointconstraints, dbg=True): - currentDOFROTnum = len(dofrot) + currentDOFROTnum = len(dofrot) for a in len(pointconstraints): if check_ifCoincident(pointA,pointconstraints[a]): #the same point is already constrained so skip it , redundant - return dofrot + return dofrot if currentDOFROTnum == 0 : #already locked on rotation so ignore it return [] elif currentDOFROTnum == 1 : #already partially locked, an additional point identity locks the object if check_ifPointOnAxis(pointA,dofrot[0]): #check if the point is on the same direction of the axis left free #the point is on the rotation axis left free, it doesn't lock anything - return dofrot + return dofrot else: #the pointidentity locks permanently return [] elif currentDOFROTnum == 3 : #no constraints on rotation the point identity does nothing on its own - #here I have to insert the point on pointconstraint, only if the point is not coincident to some point already stored in pointconstraint - #return back here + #here I have to insert the point on pointconstraint, only if the point is not coincident to some point already stored in pointconstraint + #return back here #if there is only 1 pointidentity do nothing, as single point constraint doesn't lock anything just store the point - if len(pointconstraints) == 1: + if len(pointconstraints) == 1: return dofrot - elif len(pointconstraints) >= 3: + elif len(pointconstraints) >= 3: #there are 3 unique points so the object is fully constrained DOFROT=0 return [] elif len(pointconstraints) == 2: #this is a circularedge constraint with an axis with Base on pointA and Direction pointconstraint[0] to pointconstraints[1] #so DOFROT as circular edge always locks all 3 axes in position - tmpAxis = create_Axis2Points(pointconstraints[0],pointconstraints[1]) + tmpAxis = create_Axis2Points(pointconstraints[0],pointconstraints[1]) tmpAxis = copy_AxisToOrigin(tmpAxis) - return AxisAlignment(tmpAxis, dofrot) - + return AxisAlignment(tmpAxis, dofrot) + else: #this shouldn't happens...ignore it and return the current dofrot - return dofrot + return dofrot #in the end there are the toolbar constraints, those are simply a combination of the ones above #PointIdentity, PointOnLine, PointOnPlane, Spherical Constraints: -# PointIdentityPos() needs to know the point constrained as vector, the dofpos array, the rigid center point as vector and -# the pointconstraints which stores all point constraints of the rigid -# PointIdentityRot() needs to know the point constrained as vector, the dofrot array, and -# the pointconstraints which stores all point constraints of the rigid +# PointIdentityPos() needs to know the point constrained as vector, the dofpos array, the rigid center point as vector and +# the pointconstraints which stores all point constraints of the rigid +# PointIdentityRot() needs to know the point constrained as vector, the dofrot array, and +# the pointconstraints which stores all point constraints of the rigid # These constraint have to be the last evaluated in the chain of constraints. #CircularEdgeConstraint: # AxisAlignment() needs to know the axis normal to circle (stored in dep as refpoint and refAxisEnd) and the dofrot array -# AxisDistance() needs to know the axis normal to circle (stored in dep as refpoint and refAxisEnd) and the dofpos array -# PlaneOffset() needs to know the axis normal to circle (stored in dep as refpoint and refAxisEnd) and the dofpos array +# AxisDistance() needs to know the axis normal to circle (stored in dep as refpoint and refAxisEnd) and the dofpos array +# PlaneOffset() needs to know the axis normal to circle (stored in dep as refpoint and refAxisEnd) and the dofpos array # LockRotation() need to know if LockRotation is True or False and the array dofrot # # honestly speaking this would be simplified like this: # if LockRotation: # dofpos = [] -# dofrot = [] +# dofrot = [] # else: # dofpos = [] # dofrot = AxisAlignment(ConstraintAxis, dofrot) @@ -441,11 +441,11 @@ def PointIdentityRot(pointA, dofrot, pointconstraints, dbg=True): #PlaneCoincident: # AxisAlignment() needs to know the axis normal to the plane constrained (stored in dep as refpoint and refAxisEnd) and the dofrot array -# PlaneOffset() needs to know the axis normal to the plane constrained (stored in dep as refpoint and refAxisEnd) and the dofpos array +# PlaneOffset() needs to know the axis normal to the plane constrained (stored in dep as refpoint and refAxisEnd) and the dofpos array #AxialConstraint: # AxisAlignment() needs to know the axis normal to circle (stored in dep as refpoint and refAxisEnd) and the dofrot array -# AxisDistance() needs to know the axis normal to circle (stored in dep as refpoint and refAxisEnd) and the dofpos array +# AxisDistance() needs to know the axis normal to circle (stored in dep as refpoint and refAxisEnd) and the dofpos array # LockRotation() need to know if LockRotation is True or False and the array dofrot #AngleBetweenPlanesConstraint @@ -474,4 +474,3 @@ def PointIdentityRot(pointA, dofrot, pointconstraints, dbg=True): dfdfdf = create_Axis(FreeCAD.Vector(12.0,33.5,12.7), FreeCAD.Vector(23.5,22.0,99.0)) print copynorm_AxisToOrigin(dfdfdf) print create_Axis2Points(FreeCAD.Vector(1.0,1.0,1.0), FreeCAD.Vector(3,3,3)) - diff --git a/a2p_planeConstraint.py b/a2p_planeConstraint.py index c4f89005..cce4f626 100644 --- a/a2p_planeConstraint.py +++ b/a2p_planeConstraint.py @@ -56,7 +56,7 @@ def parseSelection(selection, objectToUpdate=None): ''' % printSelection(selection) QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return + return if objectToUpdate == None: extraText = '' @@ -68,13 +68,13 @@ def parseSelection(selection, objectToUpdate=None): c.addProperty("App::PropertyString","Object2","ConstraintInfo").Object2 = cParms[1][0] c.addProperty("App::PropertyString","SubElement2","ConstraintInfo").SubElement2 = cParms[1][1] c.addProperty('App::PropertyDistance','offset',"ConstraintInfo") - + c.addProperty("App::PropertyEnumeration","directionConstraint", "ConstraintInfo") c.directionConstraint = ["none","aligned","opposed"] - + c.setEditorMode('Type',1) for prop in ["Object1","Object2","SubElement1","SubElement2"]: - c.setEditorMode(prop, 1) + c.setEditorMode(prop, 1) #------------------------------------------- # Group correctly under ParentObject in tree @@ -84,15 +84,15 @@ def parseSelection(selection, objectToUpdate=None): c.setEditorMode('ParentTreeObject',1) parent.Label = parent.Label # this is needed to trigger an update #------------------------------------------- - + c.Proxy = ConstraintObjectProxy() - c.ViewObject.Proxy = ConstraintViewProviderProxy( - c, - path_a2p + '/icons/a2p_planeConstraint.svg', - True, cParms[1][2], - cParms[0][2], + c.ViewObject.Proxy = ConstraintViewProviderProxy( + c, + path_a2p + '/icons/a2p_planeConstraint.svg', + True, cParms[1][2], + cParms[0][2], extraText - ) + ) else: c = objectToUpdate c.Object1 = cParms[0][0] @@ -103,7 +103,7 @@ def parseSelection(selection, objectToUpdate=None): c.purgeTouched() c.Proxy.callSolveConstraints() - + selection_text = \ '''1.) select Plane on first importPart @@ -127,77 +127,19 @@ def Activated(self): parseSelection( selection ) else: FreeCADGui.Selection.clearSelection() - ConstraintSelectionObserver( - PlaneSelectionGate(), - parseSelection, - taskDialog_title ='add planeCoincident constraint', - taskDialog_iconPath = self.GetResources()['Pixmap'], + ConstraintSelectionObserver( + PlaneSelectionGate(), + parseSelection, + taskDialog_title ='add planeCoincident constraint', + taskDialog_iconPath = self.GetResources()['Pixmap'], taskDialog_text = selection_text, secondSelectionGate = PlaneSelectionGate2() ) - - def GetResources(self): + + def GetResources(self): return { - 'Pixmap' : path_a2p + '/icons/a2p_planeConstraint.svg', - 'MenuText': 'Add plane constraint', + 'Pixmap' : path_a2p + '/icons/a2p_planeConstraint.svg', + 'MenuText': 'Add plane constraint', 'ToolTip': toolTipText - } + } FreeCADGui.addCommand('a2p_PlaneConnection', a2p_PlaneConnectionCommand()) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/a2p_planesParallelConstraint.py b/a2p_planesParallelConstraint.py index b6236bbd..25523e6c 100644 --- a/a2p_planesParallelConstraint.py +++ b/a2p_planesParallelConstraint.py @@ -57,7 +57,7 @@ def parseSelection(selection, objectToUpdate=None): ''' % printSelection(selection) QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return + return if objectToUpdate == None: extraText = '' @@ -68,14 +68,14 @@ def parseSelection(selection, objectToUpdate=None): c.addProperty("App::PropertyString","SubElement1","ConstraintInfo").SubElement1 = cParms[0][1] c.addProperty("App::PropertyString","Object2","ConstraintInfo").Object2 = cParms[1][0] c.addProperty("App::PropertyString","SubElement2","ConstraintInfo").SubElement2 = cParms[1][1] - + c.addProperty("App::PropertyEnumeration","directionConstraint", "ConstraintInfo") c.directionConstraint = ["none","aligned","opposed"] - + c.setEditorMode('Type',1) for prop in ["Object1","Object2","SubElement1","SubElement2"]: - c.setEditorMode(prop, 1) - + c.setEditorMode(prop, 1) + #------------------------------------------- # Group correctly under ParentObject in tree #------------------------------------------- @@ -84,15 +84,15 @@ def parseSelection(selection, objectToUpdate=None): c.setEditorMode('ParentTreeObject',1) parent.Label = parent.Label # this is needed to trigger an update #------------------------------------------- - + c.Proxy = ConstraintObjectProxy() - c.ViewObject.Proxy = ConstraintViewProviderProxy( - c, - path_a2p + '/icons/a2p_planesParallelConstraint.svg', - True, cParms[1][2], - cParms[0][2], + c.ViewObject.Proxy = ConstraintViewProviderProxy( + c, + path_a2p + '/icons/a2p_planesParallelConstraint.svg', + True, cParms[1][2], + cParms[0][2], extraText - ) + ) else: c = objectToUpdate c.Object1 = cParms[0][0] @@ -103,7 +103,7 @@ def parseSelection(selection, objectToUpdate=None): c.purgeTouched() c.Proxy.callSolveConstraints() - + selection_text = \ ''' @@ -130,77 +130,19 @@ def Activated(self): parseSelection( selection ) else: FreeCADGui.Selection.clearSelection() - ConstraintSelectionObserver( - PlanesParallelSelectionGate(), - parseSelection, - taskDialog_title ='add planesParallel constraint', - taskDialog_iconPath = self.GetResources()['Pixmap'], + ConstraintSelectionObserver( + PlanesParallelSelectionGate(), + parseSelection, + taskDialog_title ='add planesParallel constraint', + taskDialog_iconPath = self.GetResources()['Pixmap'], taskDialog_text = selection_text, secondSelectionGate = PlanesParallelSelectionGate2() ) - - def GetResources(self): + + def GetResources(self): return { - 'Pixmap' : path_a2p + '/icons/a2p_planesParallelConstraint.svg', - 'MenuText': 'Add planesParallel constraint', + 'Pixmap' : path_a2p + '/icons/a2p_planesParallelConstraint.svg', + 'MenuText': 'Add planesParallel constraint', 'ToolTip': toolTipText - } + } FreeCADGui.addCommand('a2p_PlanesParallelConnectionCommand', a2p_PlanesParallelConnectionCommand()) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/a2p_pointIdentityConnection.py b/a2p_pointIdentityConnection.py index 574892aa..baa0b10b 100644 --- a/a2p_pointIdentityConnection.py +++ b/a2p_pointIdentityConnection.py @@ -44,10 +44,10 @@ def parseSelection(selection, objectToUpdate=None): [s2.ObjectName, s2.SubElementNames[0], s2.Object.Label ] ] if not validSelection: msg = ''' - To add a point Identity constraint select exactly two vertexes! + To add a point Identity constraint select exactly two vertexes! ''' QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return + return if objectToUpdate == None: cName = findUnusedObjectName('pointIdentity') @@ -57,10 +57,10 @@ def parseSelection(selection, objectToUpdate=None): c.addProperty("App::PropertyString","SubElement1","ConstraintInfo").SubElement1 = cParms[0][1] c.addProperty("App::PropertyString","Object2","ConstraintInfo").Object2 = cParms[1][0] c.addProperty("App::PropertyString","SubElement2","ConstraintInfo").SubElement2 = cParms[1][1] - + c.setEditorMode('Type',1) for prop in ["Object1","Object2","SubElement1","SubElement2"]: - c.setEditorMode(prop, 1) + c.setEditorMode(prop, 1) #------------------------------------------- # Group correctly under ParentObject in tree @@ -70,13 +70,13 @@ def parseSelection(selection, objectToUpdate=None): c.setEditorMode('ParentTreeObject',1) parent.Label = parent.Label # this is needed to trigger an update #------------------------------------------- - + c.Proxy = ConstraintObjectProxy() - c.ViewObject.Proxy = ConstraintViewProviderProxy( - c, - path_a2p + '/icons/a2p_pointIdentity.svg', - True, - cParms[1][2], + c.ViewObject.Proxy = ConstraintViewProviderProxy( + c, + path_a2p + '/icons/a2p_pointIdentity.svg', + True, + cParms[1][2], cParms[0][2] ) else: @@ -86,7 +86,7 @@ def parseSelection(selection, objectToUpdate=None): c.Object2 = cParms[1][0] c.SubElement2 = cParms[1][1] updateObjectProperties(c) - + c.purgeTouched() c.Proxy.callSolveConstraints() @@ -96,14 +96,14 @@ def parseSelection(selection, objectToUpdate=None): - 1. vertex on a part - 2. vertex on another part ''' - + toolTipText = \ ''' Add PointIdentity Constraint: selection: 1.) select a vertex on a part 2.) select a vertex on another part -''' +''' class a2p_PointIdentityConnectionCommand: def Activated(self): @@ -112,84 +112,19 @@ def Activated(self): parseSelection( selection ) else: FreeCADGui.Selection.clearSelection() - ConstraintSelectionObserver( - PointIdentitySelectionGate(), + ConstraintSelectionObserver( + PointIdentitySelectionGate(), parseSelection, - taskDialog_title ='add point Identity constraint', - #taskDialog_iconPath = self.GetResources()['Pixmap'], - taskDialog_iconPath = path_a2p + '/icons/a2p_pointIdentity.svg', + taskDialog_title ='add point Identity constraint', + #taskDialog_iconPath = self.GetResources()['Pixmap'], + taskDialog_iconPath = path_a2p + '/icons/a2p_pointIdentity.svg', taskDialog_text = selection_text ) - def GetResources(self): + def GetResources(self): return { - 'Pixmap' : path_a2p + '/icons/a2p_pointIdentity.svg', - 'MenuText': 'Add PointIdentity Constraint', + 'Pixmap' : path_a2p + '/icons/a2p_pointIdentity.svg', + 'MenuText': 'Add PointIdentity Constraint', 'ToolTip': toolTipText - } + } FreeCADGui.addCommand('a2p_PointIdentityConnectionCommand', a2p_PointIdentityConnectionCommand()) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/a2p_pointOnPlaneConstraint.py b/a2p_pointOnPlaneConstraint.py index f8916f30..b10f102b 100644 --- a/a2p_pointOnPlaneConstraint.py +++ b/a2p_pointOnPlaneConstraint.py @@ -49,13 +49,13 @@ def parseSelection(selection, objectToUpdate=None): msg = ''' for Point on Plane constraint select in this order: 1.) a vertex - 2.) a plane + 2.) a plane Selection made: %s ''' % printSelection(selection) QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return + return if objectToUpdate == None: extraText = '' @@ -66,11 +66,11 @@ def parseSelection(selection, objectToUpdate=None): c.addProperty("App::PropertyString","SubElement1","ConstraintInfo").SubElement1 = cParms[0][1] c.addProperty("App::PropertyString","Object2","ConstraintInfo").Object2 = cParms[1][0] c.addProperty("App::PropertyString","SubElement2","ConstraintInfo").SubElement2 = cParms[1][1] - + c.setEditorMode('Type',1) for prop in ["Object1","Object2","SubElement1","SubElement2"]: - c.setEditorMode(prop, 1) - + c.setEditorMode(prop, 1) + #------------------------------------------- # Group correctly under ParentObject in tree #------------------------------------------- @@ -79,16 +79,16 @@ def parseSelection(selection, objectToUpdate=None): c.setEditorMode('ParentTreeObject',1) parent.Label = parent.Label # this is needed to trigger an update #------------------------------------------- - + c.Proxy = ConstraintObjectProxy() - c.ViewObject.Proxy = ConstraintViewProviderProxy( - c, - path_a2p + '/icons/a2p_pointOnPlaneConstraint.svg', - True, - cParms[1][2], - cParms[0][2], + c.ViewObject.Proxy = ConstraintViewProviderProxy( + c, + path_a2p + '/icons/a2p_pointOnPlaneConstraint.svg', + True, + cParms[1][2], + cParms[0][2], extraText - ) + ) else: c = objectToUpdate c.Object1 = cParms[0][0] @@ -99,7 +99,7 @@ def parseSelection(selection, objectToUpdate=None): c.purgeTouched() c.Proxy.callSolveConstraints() - + selection_text = \ '''for Point on Plane constraint select in this order: @@ -121,77 +121,19 @@ def Activated(self): parseSelection( selection ) else: FreeCADGui.Selection.clearSelection() - ConstraintSelectionObserver( - PointOnPlaneSelectionGate(), - parseSelection, - taskDialog_title ='add pointOnPlane constraint', - taskDialog_iconPath = path_a2p + '/icons/a2p_pointOnPlaneConstraint.svg', + ConstraintSelectionObserver( + PointOnPlaneSelectionGate(), + parseSelection, + taskDialog_title ='add pointOnPlane constraint', + taskDialog_iconPath = path_a2p + '/icons/a2p_pointOnPlaneConstraint.svg', taskDialog_text = selection_text, secondSelectionGate = PointOnPlaneSelectionGate2() ) - - def GetResources(self): + + def GetResources(self): return { - 'Pixmap' : path_a2p + '/icons/a2p_pointOnPlaneConstraint.svg', - 'MenuText': 'Add PointOnPlane constraint', + 'Pixmap' : path_a2p + '/icons/a2p_pointOnPlaneConstraint.svg', + 'MenuText': 'Add PointOnPlane constraint', 'ToolTip': toolTipText - } + } FreeCADGui.addCommand('a2p_PointOnPlaneConstraintCommand', a2p_PointOnPlaneConstraintCommand()) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/a2p_sphericalConnection.py b/a2p_sphericalConnection.py index d44f92a6..04dc827c 100644 --- a/a2p_sphericalConnection.py +++ b/a2p_sphericalConnection.py @@ -26,7 +26,7 @@ #from lib3D import * from pivy import coin from PySide import QtGui - + class SphericalSurfaceSelectionGate: def allow(self, doc, obj, sub): if sub.startswith('Face'): @@ -51,27 +51,27 @@ def parseSelection(selection, objectToUpdate=None): if not validSelection: msg = ''' - To add a spherical surface constraint select two - spherical surfaces (or vertexs), - each from a different part. + To add a spherical surface constraint select two + spherical surfaces (or vertexs), + each from a different part. Selection made: %s ''' % printSelection(selection) QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return + return if objectToUpdate == None: cName = findUnusedObjectName('sphericalConstraint') c = FreeCAD.ActiveDocument.addObject("App::FeaturePython", cName) - + c.addProperty("App::PropertyString","Type","ConstraintInfo").Type = 'sphereCenterIdent' c.addProperty("App::PropertyString","Object1","ConstraintInfo").Object1 = cParms[0][0] c.addProperty("App::PropertyString","SubElement1","ConstraintInfo").SubElement1 = cParms[0][1] c.addProperty("App::PropertyString","Object2","ConstraintInfo").Object2 = cParms[1][0] c.addProperty("App::PropertyString","SubElement2","ConstraintInfo").SubElement2 = cParms[1][1] - + c.setEditorMode('Type',1) for prop in ["Object1","Object2","SubElement1","SubElement2"]: - c.setEditorMode(prop, 1) + c.setEditorMode(prop, 1) #------------------------------------------- # Group correctly under ParentObject in tree @@ -81,12 +81,12 @@ def parseSelection(selection, objectToUpdate=None): c.setEditorMode('ParentTreeObject',1) parent.Label = parent.Label # this is needed to trigger an update #------------------------------------------- - + c.Proxy = ConstraintObjectProxy() - c.ViewObject.Proxy = ConstraintViewProviderProxy( - c, - path_a2p + '/icons/a2p_sphericalSurfaceConstraint.svg', - True, cParms[1][2], + c.ViewObject.Proxy = ConstraintViewProviderProxy( + c, + path_a2p + '/icons/a2p_sphericalSurfaceConstraint.svg', + True, cParms[1][2], cParms[0][2] ) else: @@ -98,8 +98,8 @@ def parseSelection(selection, objectToUpdate=None): updateObjectProperties(c) c.purgeTouched() - c.Proxy.callSolveConstraints() - + c.Proxy.callSolveConstraints() + selection_text = \ ''' Selection options: @@ -123,64 +123,19 @@ def Activated(self): parseSelection( selection ) else: FreeCADGui.Selection.clearSelection() - ConstraintSelectionObserver( - SphericalSurfaceSelectionGate(), + ConstraintSelectionObserver( + SphericalSurfaceSelectionGate(), parseSelection, - taskDialog_title ='add spherical surface constraint', - taskDialog_iconPath = self.GetResources()['Pixmap'], + taskDialog_title ='add spherical surface constraint', + taskDialog_iconPath = self.GetResources()['Pixmap'], taskDialog_text = selection_text ) - def GetResources(self): + def GetResources(self): return { - 'Pixmap' : path_a2p + '/icons/a2p_sphericalSurfaceConstraint.svg', - 'MenuText': 'Add a spherical constraint', + 'Pixmap' : path_a2p + '/icons/a2p_sphericalSurfaceConstraint.svg', + 'MenuText': 'Add a spherical constraint', 'ToolTip': toolTipText - } + } FreeCADGui.addCommand('a2p_SphericalConnection', a2p_SphericalSurfaceConnectionCommand()) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/a2p_versionmanagement.py b/a2p_versionmanagement.py index 4b82c58c..ad61b549 100644 --- a/a2p_versionmanagement.py +++ b/a2p_versionmanagement.py @@ -34,22 +34,22 @@ class SubAssemblyWalk(): ''' - Class for walking through subassemblies, + Class for walking through subassemblies, creating missing properties, checking for necessary update of importparts... - + start it with method executeWalk(self) ''' - + def __init__(self,startFile): self.startFile = startFile self.docsToBeClosed = [] - + def checkForSubAssembly(self,subFileName): filename = findSourceFileInProject(subFileName) # path within subfile will be ignored.. if filename == None: FreeCAD.Console.PrintMessage( - "SubassemblyCheck failed for {} ".format( subFileName ) + "SubassemblyCheck failed for {} ".format( subFileName ) ) return False @@ -58,40 +58,40 @@ def checkForSubAssembly(self,subFileName): doc = [ d for d in FreeCAD.listDocuments().values() if d.FileName == filename][0] else: doc = FreeCAD.openDocument(filename) - + for obj in doc.Objects: if hasattr(obj, 'sourceFile'): if not doc_already_open: FreeCAD.closeDocument(doc.Name) return True - + if not doc_already_open: FreeCAD.closeDocument(doc.Name) return False - + def openSubAssembly(self,subFile): #recursive func!! This can consumpt the total memory of your computer filename = findSourceFileInProject(subFile) # path within subfile will be ignored.. if filename == None: FreeCAD.Console.PrintMessage( "Missing file {} ignored".format(subFile) ) return False - + doc_already_open = filename in [ d.FileName for d in FreeCAD.listDocuments().values() ] if doc_already_open: doc = [ d for d in FreeCAD.listDocuments().values() if d.FileName == filename][0] else: doc = FreeCAD.openDocument(filename) - + needUpdate = False - + for obj in doc.Objects: if hasattr(obj, 'sourceFile'): - + # This Section: Add missing but necessary properties of this Version if not hasattr( obj, 'a2p_Version'): obj.addProperty("App::PropertyString", "a2p_Version","importPart").a2p_Version = 'V0.0' obj.setEditorMode("a2p_Version",1) needUpdate = True - + if not hasattr( obj, 'muxInfo'): obj.addProperty("App::PropertyStringList", "muxInfo","importPart").muxInfo = [] needUpdate = True @@ -101,17 +101,17 @@ def openSubAssembly(self,subFile): #recursive func!! This can consumpt the total obj.setEditorMode("subassemblyImport",1) obj.subassemblyImport = self.checkForSubAssembly(obj.sourceFile) needUpdate = True - + if obj.subassemblyImport == True: - # This Section: Open subassemblies which this assembly depends on... + # This Section: Open subassemblies which this assembly depends on... replacement = findSourceFileInProject(obj.sourceFile) # work in any case with files within projectFolder! if replacement == None: - QtGui.QMessageBox.critical( QtGui.QApplication.activeWindow(), - "Source file not found", + QtGui.QMessageBox.critical( QtGui.QApplication.activeWindow(), + "Source file not found", "update of %s aborted!\nUnable to find %s" % ( - obj.Name, + obj.Name, obj.sourceFile - ) + ) ) else: if obj.sourceFile != replacement: @@ -119,91 +119,25 @@ def openSubAssembly(self,subFile): #recursive func!! This can consumpt the total result = self.openSubAssembly(obj.sourceFile) if result == True: needUpdate = True - + if obj.a2p_Version != A2P_VERSION: needUpdate = True - + if os.path.getmtime( obj.sourceFile ) > obj.timeLastImport: needUpdate = True - + if not needUpdate: if doc not in self.docsToBeClosed: self.docsToBeClosed.append(doc) - + return needUpdate - - - - + + + + def executeWalk(self): self.docsToBeClosed = [] self.openSubAssembly(self.startFile) for doc in self.docsToBeClosed: if doc.FileName != self.startFile: FreeCAD.closeDocument(doc.Name) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/a2p_viewProviderProxies.py b/a2p_viewProviderProxies.py index a71b9fcd..3602aeed 100644 --- a/a2p_viewProviderProxies.py +++ b/a2p_viewProviderProxies.py @@ -39,21 +39,21 @@ def group_constraints_under_parts(): def allow_deletetion_when_activice_doc_ne_object_doc(): return False -class ImportedPartViewProviderProxy: - +class ImportedPartViewProviderProxy: + def claimChildren(self): if hasattr(self,'Object'): return self.Object.InList else: return [] - + def onDelete(self, viewObject, subelements): # subelements is a tuple of strings if FreeCAD.activeDocument() != viewObject.Object.Document: return False # only delete objects in the active Document anytime !! - + obj = viewObject.Object doc = obj.Document - + deleteList = [] for c in doc.Objects: if 'ConstraintInfo' in c.Content: # a related Constraint @@ -62,11 +62,11 @@ def onDelete(self, viewObject, subelements): # subelements is a tuple of strings if 'ConstraintNfo' in c.Content: # a related mirror-Constraint if obj.Name in [ c.Object1, c.Object2 ]: deleteList.append(c) - + if len(deleteList) > 0: for c in deleteList: doc.removeObject(c.Name) - + return True # If False is returned the object won't be deleted def __getstate__(self): @@ -74,7 +74,7 @@ def __getstate__(self): def __setstate__(self, state): return None - + def attach(self, vobj): self.object_Name = vobj.Object.Name self.Object = vobj.Object @@ -97,30 +97,30 @@ def execute( self ): class ConstraintViewProviderProxy: - def __init__( - self, - constraintObj, - iconPath, - createMirror=True, - origLabel = '', - mirrorLabel = '', - extraLabel = '' + def __init__( + self, + constraintObj, + iconPath, + createMirror=True, + origLabel = '', + mirrorLabel = '', + extraLabel = '' ): self.iconPath = iconPath self.constraintObj_name = constraintObj.Name constraintObj.purgeTouched() if createMirror: self.mirror_name = create_constraint_mirror( - constraintObj, - iconPath, - origLabel, - mirrorLabel, - extraLabel + constraintObj, + iconPath, + origLabel, + mirrorLabel, + extraLabel ) - + def getIcon(self): return self.iconPath - + def attach(self, vobj): #attach to what document? vobj.addDisplayMode( coin.SoGroup(),"Standard" ) @@ -141,7 +141,7 @@ def onDelete(self, viewObject, subelements): # subelements is a tuple of strings doc.removeObject( obj.Proxy.constraintObj_name ) # also delete the original constraint which obj mirrors except: pass # bloede Fehlermeldung weg, wenn Original fehlt! (Klaus) - elif hasattr( obj.Proxy, 'mirror_name'): # the original constraint, #isinstance( obj.Proxy, ConstraintObjectProxy ) not done since ConstraintObjectProxy not defined in namespace + elif hasattr( obj.Proxy, 'mirror_name'): # the original constraint, #isinstance( obj.Proxy, ConstraintObjectProxy ) not done since ConstraintObjectProxy not defined in namespace doc.removeObject( obj.Proxy.mirror_name ) # also delete mirror return True @@ -166,7 +166,7 @@ def create_constraint_mirror( constraintObj, iconPath, origLabel= '', mirrorLabe if extraLabel != '': cMirror.Label += '__' + extraLabel constraintObj.Label += '__' + extraLabel - + for pName in constraintObj.PropertiesList: if pName == "ParentTreeObject": continue #causes problems with fc0.16 if constraintObj.getGroupOfProperty( pName ) == 'ConstraintInfo': @@ -188,27 +188,27 @@ def create_constraint_mirror( constraintObj, iconPath, origLabel= '', mirrorLabe setattr( cMirror, pName, getattr( constraintObj, pName) ) if constraintObj.getEditorMode(pName) == ['ReadOnly']: cMirror.setEditorMode( pName, 1 ) - + cMirror.addProperty("App::PropertyLink","ParentTreeObject","ConstraintNfo") # this was not copied because fc0.16 parent = FreeCAD.ActiveDocument.getObject(constraintObj.Object2) cMirror.ParentTreeObject = parent cMirror.setEditorMode('ParentTreeObject',1) parent.Label = parent.Label # this is needed to trigger an update - + ConstraintMirrorObjectProxy( cMirror, constraintObj ) cMirror.ViewObject.Proxy = ConstraintMirrorViewProviderProxy( constraintObj, iconPath ) return cMirror.Name - + class ConstraintObjectProxy: def __init__(self,obj=None): self.disable_onChanged = False - + def execute(self, obj): global a2p_NeedToSolveSystem if a2p_NeedToSolveSystem: a2p_NeedToSolveSystem = False # Solve only once after editing a constraints property self.callSolveConstraints() - + def onChanged(self, obj, prop): # Add new property "disable_onChanged" if not already existing... if not hasattr(self, 'disable_onChanged'): @@ -233,19 +233,19 @@ def reduceDirectionChoices( self, obj, value): cMirror.directionConstraint = ["aligned","opposed"] #value should be updated in onChanged call due to assignment in 2 lines obj.directionConstraint = ["aligned","opposed"] obj.directionConstraint = value - + def callSolveConstraints(self): from solversystem import autoSolveConstraints autoSolveConstraints( FreeCAD.activeDocument(), cache = None ) - - + + class ConstraintMirrorObjectProxy: def __init__(self, obj, constraintObj ): self.constraintObj_name = constraintObj.Name constraintObj.Proxy.mirror_name = obj.Name self.disable_onChanged = False obj.Proxy = self - + def execute(self, obj): return #no work required in onChanged causes touched in original constraint ... @@ -256,7 +256,7 @@ def onChanged(self, obj, prop): ''' #FreeCAD.Console.PrintMessage("%s.%s property changed\n" % (obj.Name, prop)) if getattr( self, 'disable_onChanged', True): - return + return if obj.getGroupOfProperty( prop ) == 'ConstraintNfo': if hasattr( self, 'constraintObj_name' ): constraintObj = obj.Document.getObject( self.constraintObj_name ) @@ -265,44 +265,3 @@ def onChanged(self, obj, prop): setattr( constraintObj, prop, getattr( obj, prop) ) except: pass #loading issues... - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/a2plib.py b/a2plib.py index 7e7becdd..694f8cc1 100644 --- a/a2plib.py +++ b/a2plib.py @@ -93,7 +93,7 @@ def setTransparency(): if hasattr(obj,'ViewObject'): if hasattr(obj.ViewObject,'Transparency'): SAVED_TRANSPARENCY.append((obj.Name, obj.ViewObject.Transparency)) - obj.ViewObject.Transparency = 80 + obj.ViewObject.Transparency = 80 #------------------------------------------------------------------------------ def restoreTransparency(): global SAVED_TRANSPARENCY @@ -118,7 +118,7 @@ def getSelectedConstraint(): doc = FreeCAD.ActiveDocument connectionToView = selection[0] - if not 'ConstraintInfo' in connectionToView.Content and not 'ConstraintNfo' in connectionToView.Content: + if not 'ConstraintInfo' in connectionToView.Content and not 'ConstraintNfo' in connectionToView.Content: return None return connectionToView @@ -136,14 +136,14 @@ def isLine(param): #------------------------------------------------------------------------------ def getObjectFaceFromName( obj, faceName ): assert faceName.startswith('Face') - ind = int( faceName[4:]) -1 + ind = int( faceName[4:]) -1 return obj.Shape.Faces[ind] #------------------------------------------------------------------------------ def getProjectFolder(): ''' #------------------------------------------------------------------------------------ # A new Parameter is required: projectFolder... - # All Parts will be searched below this projectFolder-Value... + # All Parts will be searched below this projectFolder-Value... #------------------------------------------------------------------------------------ ''' preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/A2plus") @@ -152,7 +152,7 @@ def getProjectFolder(): #------------------------------------------------------------------------------ def findSourceFileInProject(fullPath): - ''' + ''' #------------------------------------------------------------------------------------ # function to find filename in projectFolder # The path stored in an imported Part will be ignored @@ -165,8 +165,8 @@ def findSourceFileInProject(fullPath): def findFile(name, path): for root, dirs, files in os.walk(path): if name in files: - return os.path.join(root, name) - + return os.path.join(root, name) + projectFolder = os.path.abspath(getProjectFolder()) # get normalized path fileName = os.path.basename(fullPath) retval = findFile(fileName,projectFolder) @@ -193,17 +193,17 @@ def pathOfModule(): #------------------------------------------------------------------------------ def Msg(tx): FreeCAD.Console.PrintMessage(tx) - + #------------------------------------------------------------------------------ def DebugMsg(level, tx): if A2P_DEBUG_LEVEL >= level: FreeCAD.Console.PrintMessage(tx) #------------------------------------------------------------------------------ -def drawVector(fromPoint,toPoint, color): +def drawVector(fromPoint,toPoint, color): if fromPoint == toPoint: return doc = FreeCAD.ActiveDocument - + l = Part.Line(fromPoint,toPoint) line = doc.addObject("Part::Feature","ArrowTail") line.Shape = l.toShape() @@ -221,16 +221,16 @@ def drawVector(fromPoint,toPoint, color): cent = Base.Vector(0,0,0) conePlacement = FreeCAD.Placement(mov,rot,cent) cone.Placement = conePlacement.multiply(cone.Placement) - cone.Placement.move(toPoint) + cone.Placement.move(toPoint) doc.recompute() - + #------------------------------------------------------------------------------ def findUnusedObjectName(base, counterStart=1, fmt='%03i', document=None): if document == None: document = FreeCAD.ActiveDocument i = counterStart - usedNames = [ obj.Name for obj in document.Objects ] - + usedNames = [ obj.Name for obj in document.Objects ] + if base[-4:-3] == '_': base2 = base[:-4] else: @@ -248,8 +248,8 @@ def findUnusedObjectLabel(base, counterStart=1, fmt='%03i', document=None): if document == None: document = FreeCAD.ActiveDocument i = counterStart - usedLabels = [ obj.Label for obj in document.Objects ] - + usedLabels = [ obj.Label for obj in document.Objects ] + if base[-4:-3] == '_': base2 = base[:-4] else: @@ -264,14 +264,14 @@ def findUnusedObjectLabel(base, counterStart=1, fmt='%03i', document=None): #------------------------------------------------------------------------------ class ConstraintSelectionObserver: - - def __init__(self, selectionGate, parseSelectionFunction, + + def __init__(self, selectionGate, parseSelectionFunction, taskDialog_title, taskDialog_iconPath, taskDialog_text, secondSelectionGate=None): self.selections = [] self.parseSelectionFunction = parseSelectionFunction self.secondSelectionGate = secondSelectionGate - FreeCADGui.Selection.addObserver(self) + FreeCADGui.Selection.addObserver(self) FreeCADGui.Selection.removeSelectionGate() FreeCADGui.Selection.addSelectionGate( selectionGate ) wb_globals['selectionObserver'] = self @@ -289,7 +289,7 @@ def addSelection( self, docName, objName, sub, pnt ): FreeCADGui.Selection.addSelectionGate( self.secondSelectionGate ) def stopSelectionObservation(self): - FreeCADGui.Selection.removeObserver(self) + FreeCADGui.Selection.removeObserver(self) del wb_globals['selectionObserver'] FreeCADGui.Selection.removeSelectionGate() FreeCADGui.Control.closeDialog() @@ -301,35 +301,35 @@ def __init__(self, docName, objName, sub): self.ObjectName = objName self.Object = self.Document.getObject(objName) self.SubElementNames = [sub] - + #------------------------------------------------------------------------------ class SelectionTaskDialog: - + def __init__(self, title, iconPath, textLines ): self.form = SelectionTaskDialogForm( textLines ) - self.form.setWindowTitle( title ) + self.form.setWindowTitle( title ) if iconPath != None: self.form.setWindowIcon( QtGui.QIcon( iconPath ) ) - + def reject(self): wb_globals['selectionObserver'].stopSelectionObservation() def getStandardButtons(self): #http://forum.freecadweb.org/viewtopic.php?f=10&t=11801 return 0x00400000 #cancel button #------------------------------------------------------------------------------ -class SelectionTaskDialogForm(QtGui.QWidget): - +class SelectionTaskDialogForm(QtGui.QWidget): + def __init__(self, textLines ): super(SelectionTaskDialogForm, self).__init__() - self.textLines = textLines + self.textLines = textLines self.initUI() - + def initUI(self): vbox = QtGui.QVBoxLayout() for line in self.textLines.split('\n'): vbox.addWidget( QtGui.QLabel(line) ) self.setLayout(vbox) - + #------------------------------------------------------------------------------ class SelectionExObject: 'allows for selection gate functions to interface with classification functions below' @@ -341,7 +341,7 @@ def __init__(self, doc, Object, subElementName): #------------------------------------------------------------------------------ def getObjectEdgeFromName( obj, name ): assert name.startswith('Edge') - ind = int( name[4:]) -1 + ind = int( name[4:]) -1 return obj.Shape.Edges[ind] #------------------------------------------------------------------------------ def CircularEdgeSelected( selection ): @@ -370,7 +370,7 @@ def printSelection(selection): for e in s.SubElementNames: entries.append(' - %s:%s' % (s.ObjectName, e)) if e.startswith('Face'): - ind = int( e[4:]) -1 + ind = int( e[4:]) -1 face = s.Object.Shape.Faces[ind] entries[-1] = entries[-1] + ' %s' % str(face.Surface) return '\n'.join( entries[:5] ) @@ -429,7 +429,7 @@ def sphericalSurfaceSelected( selection ): #------------------------------------------------------------------------------ def getObjectVertexFromName( obj, name ): assert name.startswith('Vertex') - ind = int( name[6:]) -1 + ind = int( name[6:]) -1 return obj.Shape.Vertexes[ind] #------------------------------------------------------------------------------ def removeConstraint( constraint ): @@ -482,59 +482,3 @@ def getAxis(obj, subElementName): axis = edge.Curve.Axis return axis # may be none! #------------------------------------------------------------------------------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/observers.py b/observers.py index d074169b..b1706a9b 100644 --- a/observers.py +++ b/observers.py @@ -33,5 +33,5 @@ def slotRedoDocument(self,doc): a2p_importpart.a2p_repairTreeView() def slotUndoDocument(self,doc): a2p_importpart.a2p_repairTreeView() - + redoUndoObserver = RedoUndoObserver()