def getTopLevelObjects(self): #------------------------------------------- # Create treenodes of the importable Objects with a shape #------------------------------------------- self.treeNodes = {} shapeObs = a2plib.filterShapeObs(self.doc.Objects) S = set(shapeObs) for ob in S: self.treeNodes[ob.Name] = ( a2plib.filterShapeObs(ob.InList), a2plib.filterShapeObs(ob.OutList) ) #------------------------------------------- # nodes with empty inList are top level shapes for sure # (cloned objects could be missing) #------------------------------------------- self.topLevelShapes = [] for objName in self.treeNodes.keys(): inList,dummy = self.treeNodes[objName] if self.isTopLevelInList(inList): self.topLevelShapes.append(objName) else: #------------------------------------------- # search for missing non top-level clone-basefeatures # Maybe a clone as basefeature of a body.. #------------------------------------------- numBodies = 0 numClones = 0 invalidObjects = False if len(inList) % 2 == 0: # pairs of Clone/Bodies for o in inList: if o.Name.startswith('Clone'): numClones += 1 elif o.Name.startswith('Body'): numBodies += 1 else: invalidObjects = True break if not invalidObjects: if numBodies == numClones: self.topLevelShapes.append(objName) #------------------------------------------- # Got some shapes created by PathWB? filter out... # also filter out invisible shapes... #------------------------------------------- tmp = [] for n in self.topLevelShapes: if self.addedByPathWB(n): continue # if a2plib.doNotImportInvisibleShapes(): ob = self.doc.getObject(n) if hasattr(ob,"ViewObject"): if hasattr(ob.ViewObject,"Visibility"): if ob.ViewObject.Visibility == False: print( "Import ignored invisible shape! {}".format( ob.Name ) ) continue tmp.append(n) self.topLevelShapes = tmp #------------------------------------------- # return complete topLevel document objects for external use #------------------------------------------- outObs = [] for objName in self.topLevelShapes: outObs.append(self.doc.getObject(objName)) return outObs
def DOF_info_to_console(self): doc = FreeCAD.activeDocument() dofGroup = doc.getObject("dofLabels") if dofGroup == None: dofGroup = doc.addObject("App::DocumentObjectGroup", "dofLabels") else: for lbl in dofGroup.Group: doc.removeObject(lbl.Name) doc.removeObject("dofLabels") dofGroup = doc.addObject("App::DocumentObjectGroup", "dofLabels") self.loadSystem(doc) #look for unconstrained objects and label them solverObjectNames = [] for rig in self.rigids: solverObjectNames.append(rig.objectName) shapeObs = a2plib.filterShapeObs(doc.Objects) for so in shapeObs: if so.Name not in solverObjectNames: ob = doc.getObject(so.Name) if ob.ViewObject.Visibility == True: bbCenter = ob.Shape.BoundBox.Center dofLabel = doc.addObject("App::AnnotationLabel", "dofLabel") dofLabel.LabelText = "FREE" dofLabel.BasePosition.x = bbCenter.x dofLabel.BasePosition.y = bbCenter.y dofLabel.BasePosition.z = bbCenter.z # dofLabel.ViewObject.BackgroundColor = a2plib.BLUE dofLabel.ViewObject.TextColor = a2plib.WHITE dofGroup.addObject(dofLabel) numdep = 0 self.retrieveDOFInfo( ) #function only once used here at this place in whole program for rig in self.rigids: dofCount = rig.currentDOF() ob = doc.getObject(rig.objectName) if ob.ViewObject.Visibility == True: bbCenter = ob.Shape.BoundBox.Center dofLabel = doc.addObject("App::AnnotationLabel", "dofLabel") if rig.fixed: dofLabel.LabelText = "Fixed" else: dofLabel.LabelText = "DOFs: {}".format(dofCount) dofLabel.BasePosition.x = bbCenter.x dofLabel.BasePosition.y = bbCenter.y dofLabel.BasePosition.z = bbCenter.z if rig.fixed: dofLabel.ViewObject.BackgroundColor = a2plib.RED dofLabel.ViewObject.TextColor = a2plib.BLACK elif dofCount == 0: dofLabel.ViewObject.BackgroundColor = a2plib.RED dofLabel.ViewObject.TextColor = a2plib.BLACK elif dofCount < 6: dofLabel.ViewObject.BackgroundColor = a2plib.YELLOW dofLabel.ViewObject.TextColor = a2plib.BLACK dofGroup.addObject(dofLabel) rig.beautyDOFPrint() numdep += rig.countDependencies() Msg('there are {} dependencies\n'.format(numdep / 2))
def getTopLevelObjects(self, allowSketches=False): #------------------------------------------- # Create treenodes of the importable Objects with a shape #------------------------------------------- self.treeNodes = {} shapeObs = a2plib.filterShapeObs(self.doc.Objects,allowSketches) S = set(shapeObs) for ob in S: inList = a2plib.filterShapeObs(ob.InList,allowSketches) outList = a2plib.filterShapeObs(ob.OutList,allowSketches) self.treeNodes[ob.Name] = ( inList, outList ) #------------------------------------------- # nodes with empty inList are top level shapes for sure # (cloned objects could be missing) #------------------------------------------- self.topLevelShapes = [] for objName in self.treeNodes.keys(): inList,dummy = self.treeNodes[objName] if self.isTopLevelInList(inList): self.topLevelShapes.append(objName) elif allowSketches==True and objName.startswith('Sketch'): # want to have all sketches self.topLevelShapes.append(objName) else: #------------------------------------------- # search for missing non top-level clone-basefeatures # Maybe a clone as basefeature of a body.. #------------------------------------------- numBodies = 0 numClones = 0 invalidObjects = False if len(inList) % 2 == 0: # pairs of Clone/Bodies for o in inList: if o.Name.startswith('Clone'): numClones += 1 elif o.Name.startswith('Body'): numBodies += 1 else: invalidObjects = True break if not invalidObjects: if numBodies == numClones: self.topLevelShapes.append(objName) #------------------------------------------- # search for missing non top-level objects, # as they are referenced by fasteners WB objects #------------------------------------------- allObjectsAreFasteners = True for o in inList: if not a2plib.isFastenerObject(o): allObjectsAreFasteners = False break if allObjectsAreFasteners == True: self.topLevelShapes.append(objName) #------------------------------------------- # Got some shapes used by sections? # collect them to a blacklist # InLists of objects used by section are empty, therefore they # are recognized falsely as topLevelShapes # # 2020-02-23: "Group" added to blackList #------------------------------------------- blackList = [] for ob in self.doc.Objects: if ob.Name.startswith("Group"): blackList.append(ob.Name) elif ob.Name.startswith("Section"): if hasattr(ob,"Base"): if ob.Base is not None: blackList.append(ob.Base.Name) if hasattr(ob,"Tool"): if ob.Tool is not None: blackList.append(ob.Tool.Name) #------------------------------------------- # Got some shapes created by PathWB? filter out... # also filter out invisible shapes... # also filter out the blackList #------------------------------------------- tmp = [] for n in self.topLevelShapes: if self.addedByPathWB(n): continue if n in blackList: continue # if a2plib.doNotImportInvisibleShapes(): ob = self.doc.getObject(n) if hasattr(ob,"ViewObject"): if hasattr(ob.ViewObject,"Visibility"): if ob.ViewObject.Visibility == False or not a2plib.isGlobalVisible(ob): print( "Import ignored invisible shape! {}".format( ob.Name ) ) continue tmp.append(n) self.topLevelShapes = tmp #------------------------------------------- # return complete topLevel document objects for external use #------------------------------------------- outObs = [] for objName in self.topLevelShapes: outObs.append(self.doc.getObject(objName)) return outObs