def callSolveConstraints(self): from a2p_solversystem import autoSolveConstraints autoSolveConstraints( FreeCAD.activeDocument(), cache = None, callingFuncName = "ConstraintObjectProxy::callSolveConstraints" )
def updateImportedParts(doc): objectCache.cleanUp(doc) for obj in doc.Objects: if hasattr(obj, 'sourceFile'): if not hasattr( obj, 'timeLastImport'): obj.addProperty("App::PropertyFloat", "timeLastImport","importPart") #should default to zero which will force update. obj.setEditorMode("timeLastImport",1) if not hasattr( obj, 'a2p_Version'): obj.addProperty("App::PropertyString", "a2p_Version","importPart").a2p_Version = 'V0.0' obj.setEditorMode("a2p_Version",1) if not hasattr( obj, 'muxInfo'): obj.addProperty("App::PropertyStringList","muxInfo","importPart").muxInfo = [] 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", "update of %s aborted!\nUnable to find %s" % ( obj.Name, obj.sourceFile ) ) else: obj.sourceFile = replacement # update Filepath, perhaps location changed ! if os.path.exists( obj.sourceFile ): newPartCreationTime = os.path.getmtime( obj.sourceFile ) if ( newPartCreationTime > obj.timeLastImport or obj.a2p_Version != A2P_VERSION ): if not objectCache.isCached(obj.sourceFile): # Load every changed object one time to cache importPartFromFile(doc, obj.sourceFile, importToCache=True) # the version is now in the cache newObject = objectCache.get(obj.sourceFile) obj.timeLastImport = newPartCreationTime if hasattr(newObject, 'a2p_Version'): obj.a2p_Version = newObject.a2p_Version importUpdateConstraintSubobjects( doc, obj, newObject )# do this before changing shape and mux if hasattr(newObject, 'muxInfo'): obj.muxInfo = newObject.muxInfo # save Placement becaause following newObject.Shape.copy() ist resetting it to zeroes... savedPlacement = obj.Placement 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() sub.showMaximized() objectCache.cleanUp(doc) a2p_solversystem.autoSolveConstraints(doc) doc.recompute()
def a2p_FlipConstraintDirection(): ''' updating constraints, deactivated at moment''' constraints = [ obj for obj in FreeCAD.ActiveDocument.Objects if 'ConstraintInfo' in obj.Content ] if len(constraints) == 0: QtGui.QMessageBox.information( QtGui.qApp.activeWindow(), "Command Aborted", 'Flip aborted since no a2p constraints in active document.') return lastConstraintAdded = constraints[-1] try: if lastConstraintAdded.directionConstraint == 'aligned': lastConstraintAdded.directionConstraint = 'opposed' else: lastConstraintAdded.directionConstraint = 'aligned' a2p_solversystem.autoSolveConstraints( FreeCAD.activeDocument(), callingFuncName="a2p_FlipConstraintDirection") except: pass
def callSolveConstraints(self): from a2p_solversystem import autoSolveConstraints autoSolveConstraints( FreeCAD.activeDocument(), cache = None )
def updateImportedParts(doc): if doc == None: QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "No active document found!", "Before updating parts, you have to open an assembly file.") return # modififying object's subelements causes solving of the assembly, disable autosolve here autoSolveState = a2plib.getAutoSolveState() a2plib.setAutoSolve(False) doc.openTransaction("updateImportParts") objectCache.cleanUp(doc) for obj in doc.Objects: if hasattr(obj, 'sourceFile'): if not hasattr(obj, 'timeLastImport'): obj.addProperty( "App::PropertyFloat", "timeLastImport", "importPart" ) #should default to zero which will force update. obj.setEditorMode("timeLastImport", 1) if not hasattr(obj, 'a2p_Version'): obj.addProperty("App::PropertyString", "a2p_Version", "importPart").a2p_Version = 'V0.0' obj.setEditorMode("a2p_Version", 1) if not hasattr(obj, 'muxInfo'): obj.addProperty("App::PropertyStringList", "muxInfo", "importPart").muxInfo = [] assemblyPath = os.path.normpath(os.path.split(doc.FileName)[0]) absPath = a2plib.findSourceFileInProject(obj.sourceFile, assemblyPath) if absPath == None: QtGui.QMessageBox.critical( QtGui.QApplication.activeWindow(), u"Source file not found", u"Unable to find {}".format(obj.sourceFile)) if absPath != None and os.path.exists(absPath): newPartCreationTime = os.path.getmtime(absPath) if (newPartCreationTime > obj.timeLastImport or obj.a2p_Version != A2P_VERSION): if not objectCache.isCached( absPath ): # Load every changed object one time to cache importPartFromFile(doc, absPath, importToCache=True ) # the version is now in the cache newObject = objectCache.get(absPath) obj.timeLastImport = newPartCreationTime if hasattr(newObject, 'a2p_Version'): obj.a2p_Version = A2P_VERSION importUpdateConstraintSubobjects( doc, obj, newObject) # do this before changing shape and mux if hasattr(newObject, 'muxInfo'): obj.muxInfo = newObject.muxInfo # save Placement because following newObject.Shape.copy() isn't resetting it to zeroes... savedPlacement = obj.Placement obj.Shape = newObject.Shape.copy() obj.ViewObject.DiffuseColor = copy.copy( newObject.ViewObject.DiffuseColor) obj.ViewObject.Transparency = newObject.ViewObject.Transparency obj.Placement = savedPlacement # restore the old placement mw = FreeCADGui.getMainWindow() mdi = mw.findChild(QtGui.QMdiArea) sub = mdi.activeSubWindow() if sub != None: sub.showMaximized() objectCache.cleanUp(doc) a2plib.setAutoSolve(autoSolveState) if not a2plib.getUseTopoNaming(): # This is only needed when not using toponames. # Otherwise updating constraints.subelements triggers this. a2p_solversystem.autoSolveConstraints( doc, useTransaction=False, callingFuncName="updateImportedParts" ) #transaction is already open... doc.recompute() doc.commitTransaction()