def slotStartEditing(self, feature): print(u"Start Editing {f}".format(f=feature.Name)) cnt = GT.getContainer(feature) if GT.activeContainer() is not cnt: print( u"Feature being edited is not in active container. Activating {cnt}..." .format(cnt=cnt.Name)) Gui.ActiveDocument.resetEdit() GT.setActiveContainer(cnt) return if feature.isDerivedFrom("PartDesign::Boolean"): # show all bodies nearby... part = GT.getContainer(cnt) children = GT.getDirectChildren(part) children = [ child for child in children if child.isDerivedFrom("Part::BodyBase") ] children = set(children) children.remove(cnt) for obj in GT.getAllDependent(cnt): if obj in children: children.remove(obj) tv = TempoVis(feature.Document) tv.show(children) self.edit_TVs[feature.Document.Name] = tv
def RunOrTest(self, b_run): sel = Gui.Selection.getSelection() if len(sel)==0 : ac = Containers.activeContainer() if not hasattr(ac, "Tip"): raise CommandError(self,u"{cnt} can't have Tip object (it is not a module or a body).".format(cnt= ac.Label)) if type(ac.Tip) is list: if Gui.ActiveDocument.getInEdit() is not None: raise CommandError(self,"Please leave editing mode.") if b_run: Gui.ActiveDocument.setEdit(ac, 0) return raise CommandError(self, "Set as Tip command. Please select an object to become Tip, first. The object must be geometry. ") elif len(sel)==1: sel = screen(sel[0]) ac = Containers.getContainer(sel) if not hasattr(ac, "Tip"): raise CommandError(self,u"{cnt} can't have Tip object (it is not a module or a body).".format(cnt= ac.Label)) if type(ac.Tip) is list: if Gui.ActiveDocument.getInEdit() is not None: raise CommandError(self,"Please leave editing mode.") if b_run: Gui.ActiveDocument.setEdit(ac, 0) else: if not sel in Containers.getDirectChildren(ac): raise CommandError(self, u"{feat} is not from active container ({cnt}). Please select an object belonging to active container.".format(feat= sel.Label, cnt= ac.Label)) if screen(ac.Tip) is sel: raise CommandError(self, u"{feat} is already a Tip of ({cnt}).".format(feat= sel.Label, cnt= ac.Label)) if b_run: ac.Tip = sel else: raise CommandError(self, u"Set as Tip command. You need to select exactly one object (you selected {num}).".format(num= len(sel)))
def RunOrTest(self, b_run): sel = Gui.Selection.getSelection() if len(sel) == 0: raise CommandError( self, "Make Ghost command. Please select an object to import to active container, first. The object must be geometry." ) elif len(sel) == 1: sel = sel[0] ac = Containers.activeContainer() if sel in Containers.getDirectChildren(ac): raise CommandError( self, u"{feat} is from active container ({cnt}). Please select an object belonging to another container." .format(feat=sel.Label, cnt=ac.Label)) if sel in (Containers.getAllDependent(ac) + [ac]): raise CommandError( self, "Can't create a ghost here, because a circular dependency will result." ) if b_run: CreateGhost('Ghost', sel) else: raise CommandError( self, u"Make Ghost command. You need to select exactly one object (you selected {num})." .format(num=len(sel)))
def compoundFromAssembly(root, flatten, exclude, recursive = True, visit_set = None): if visit_set is None: visit_set = set() #recursion guard if root in visit_set: raise ValueError("Circular dependency") visit_set.add(root) if hasattr(root, 'Shape'): return root.Shape else: children = Containers.getDirectChildren(root) shapes = [] for child in children: if child in exclude: continue if child.isDerivedFrom('App::Origin'): continue #otherwise, origins create empty compounds - undesirable. if hasattr(child, 'Shape'): shapes.append(child.Shape) elif Containers.isContainer(child) and recursive: cmp = compoundFromAssembly(child, flatten, exclude, recursive, visit_set) if flatten: shapes.extend(cmp.childShapes()) else: shapes.append(cmp) transform = root.Placement if hasattr(root, 'Placement') else None ret = Part.makeCompound(shapes) if transform is not None: ret.Placement = transform return ret
def RunOrTest(self, b_run): if b_run: sel = set(Gui.Selection.getSelection()) children = Containers.getDirectChildren(Containers.activeContainer()) for child in children: if child in sel: Gui.Selection.removeSelection(child) else: Gui.Selection.addSelection(child)
def RunOrTest(self, b_run): if b_run: sel = set(Gui.Selection.getSelection()) children = Containers.getDirectChildren( Containers.activeContainer()) for child in children: if child in sel: Gui.Selection.removeSelection(child) else: Gui.Selection.addSelection(child)
def RunOrTest(self, b_run): sel = Gui.Selection.getSelection() if len(sel)==0 : raise CommandError(self,"No object selected. Please select something, first.") else: if b_run: new_sel = [] for obj in sel: if Containers.isContainer(obj): new_sel.extend(Containers.getDirectChildren(obj)) else: new_sel.extend(obj.ViewObject.claimChildren()) select(new_sel)
def RunOrTest(self, b_run): sel = Gui.Selection.getSelection() if len(sel) == 0: raise CommandError( self, "No object selected. Please select something, first.") else: if b_run: new_sel = [] for obj in sel: if Containers.isContainer(obj): new_sel.extend(Containers.getDirectChildren(obj)) else: new_sel.extend(obj.ViewObject.claimChildren()) select(new_sel)
def enterContainer(self, cnt): '''enterContainer(self, cnt): when cnt either directly is being activated, or one of its child containers is being activated. Assumes container of cnt is already entered.''' if cnt.isDerivedFrom("App::Document"): # may happen when creating new document. Ignoring. return key = cnt.Document.Name+"."+cnt.Name if key in self.TVs: # just in case old tempovis associated with the container wasn't removed for some reason. self.TVs[key].forget() tv = TempoVis(cnt.Document) self.TVs[key] = tv list_hiding = [o for o in GT.getDirectChildren(GT.getContainer(cnt)) if not o is cnt] list_hiding = [o for o in list_hiding if not o.isDerivedFrom('App::DocumentObjectGroup')] # don't touch visibility of groups just yet... tv.hide(list_hiding) tv.show(cnt)
def RunOrTest(self, b_run): sel = Gui.Selection.getSelection() if len(sel)==0 : raise CommandError(self, "Shapebinder command. Please select an object to import to active container, first. The object must be geometry.") elif len(sel)==1: sel = screen(sel[0]) ac = Containers.activeContainer() if sel in Containers.getDirectChildren(ac): raise CommandError(self, u"{feat} is from active container ({cnt}). Please select an object belonging to another container.".format(feat= sel.Label, cnt= ac.Label)) if sel in (Containers.getAllDependent(ac)+ [ac]): raise CommandError(self, "Can't create a shapebinder, because a circular dependency will result.") if b_run: CreateShapeBinder(sel) else: raise CommandError(self, u"Shapebinder command. You need to select exactly one object (you selected {num}).".format(num= len(sel)))
def enterContainer(self, cnt): '''enterContainer(self, cnt): when cnt either directly is being activated, or one of its child containers is being activated. Assumes container of cnt is already entered.''' print ("entering "+cnt.Name) if cnt.isDerivedFrom("App::Document"): # may happen when creating new document. Ignoring. return key = cnt.Document.Name+"."+cnt.Name if key in self.TVs: # just in case old tempovis associated with the container wasn't removed for some reason. self.TVs[key].forget() tv = TempoVis(cnt.Document) self.TVs[key] = tv list_hiding = [o for o in GT.getDirectChildren(GT.getContainer(cnt)) if not o is cnt] list_hiding = [o for o in list_hiding if not o.isDerivedFrom('App::DocumentObjectGroup')] # don't touch visibility of groups just yet... tv.hide(list_hiding) tv.show(cnt)
def updateVPs(self): '''updates many viewprovider properties (except visibility, which is handled by TempoVis objets)''' ac = activeContainer() if ac.isDerivedFrom("App::Document"): objects_in = set(App.ActiveDocument.Objects) else: objects_in = set( GT.getDirectChildren(ac) ) objects_out = set(App.ActiveDocument.Objects) - objects_in # make all object in context selectable. This is mainly to undo consequences of old behavior of making everything out-of-context non-selectable for o in objects_in: if hasattr(o.ViewObject, "Selectable"): o.ViewObject.Selectable = True for o in App.ActiveDocument.findObjects("App::Origin"): o.ViewObject.Visibility = GT.getContainer(o) is ac
def RunOrTest(self, b_run): sel = Gui.Selection.getSelection() if len(sel) == 0: ac = Containers.activeContainer() if not hasattr(ac, "Tip"): raise CommandError( self, u"{cnt} can't have Tip object (it is not a module or a body)." .format(cnt=ac.Label)) if type(ac.Tip) is list: if Gui.ActiveDocument.getInEdit() is not None: raise CommandError(self, "Please leave editing mode.") if b_run: Gui.ActiveDocument.setEdit(ac, 0) return raise CommandError( self, "Set as Tip command. Please select an object to become Tip, first. The object must be geometry. " ) elif len(sel) == 1: sel = screen(sel[0]) ac = Containers.getContainer(sel) if not hasattr(ac, "Tip"): raise CommandError( self, u"{cnt} can't have Tip object (it is not a module or a body)." .format(cnt=ac.Label)) if type(ac.Tip) is list: if Gui.ActiveDocument.getInEdit() is not None: raise CommandError(self, "Please leave editing mode.") if b_run: Gui.ActiveDocument.setEdit(ac, 0) else: if not sel in Containers.getDirectChildren(ac): raise CommandError( self, u"{feat} is not from active container ({cnt}). Please select an object belonging to active container." .format(feat=sel.Label, cnt=ac.Label)) if screen(ac.Tip) is sel: raise CommandError( self, u"{feat} is already a Tip of ({cnt}).".format( feat=sel.Label, cnt=ac.Label)) if b_run: ac.Tip = sel else: raise CommandError( self, u"Set as Tip command. You need to select exactly one object (you selected {num})." .format(num=len(sel)))
def updateVPs(self): '''updates many viewprovider properties (except visibility, which is handled by TempoVis objects)''' ac = activeContainer() if ac.isDerivedFrom("App::Document"): objects_in = set(App.ActiveDocument.Objects) else: objects_in = set( GT.getDirectChildren(ac) ) objects_out = set(App.ActiveDocument.Objects) - objects_in # make all object in context selectable. This is mainly to undo consequences of old behavior of making everything out-of-context non-selectable for o in objects_in: if hasattr(o.ViewObject, "Selectable"): o.ViewObject.Selectable = True for o in App.ActiveDocument.findObjects("App::Origin"): o.ViewObject.Visibility = GT.getContainer(o) is ac
def compoundFromAssembly(root, flatten, exclude, recursive=True, visit_set=None): if visit_set is None: visit_set = set() #recursion guard if root in visit_set: raise ValueError("Circular dependency") visit_set.add(root) if has_property(root, 'Shape'): return root.Shape else: children = Containers.getDirectChildren(root) shapes = [] for child in children: if child in exclude: continue if child.isDerivedFrom('App::Origin'): continue #otherwise, origins create empty compounds - undesirable. if has_property( child, 'Shape' ): #since realthunder, Part has Shape attribute, but not Shape property. We want to process Parts ourselves. if not child.Shape.isNull(): shapes.append(child.Shape) elif Containers.isContainer(child) and recursive: cmp = compoundFromAssembly(child, flatten, exclude, recursive, visit_set) if flatten: shapes.extend(cmp.childShapes()) else: shapes.append(cmp) elif hasattr( obj, 'Shape' ): #App::Link may have attribute but not property, and we totally want to include it. if not child.Shape.isNull(): shapes.append(child.Shape) transform = root.Placement if hasattr(root, 'Placement') else None ret = Part.makeCompound(shapes) if transform is not None: ret.Placement = transform return ret
def setEdit(self, selfvp, mode): if mode == 0: try: selfobj = selfvp.Object #ensure right container is active from PartOMagic.Base import Containers container = Containers.getContainer(selfobj) if Containers.activeContainer() is not Containers.getContainer( selfobj): from PartOMagic.Gui import Observer Observer.activateContainer(container) selfobj.Document.openTransaction( u'Edit Tip of {sg}'.format(sg=selfobj.Label)) #prepare scene from PartOMagic.Gui.TempoVis import TempoVis self.tv = TempoVis(selfobj.Document) tv = self.tv #update visibilities of children to match what's in tip children = selfobj.Group tip = selfobj.Tip for child in children: tv.modifyVPProperty(child, 'Visibility', child in tip) #ensure children are visible, and nothing else... tv.modifyVPProperty(selfobj, 'DisplayMode', 'Group') tv.show(selfobj) for child in Containers.getDirectChildren(container): if child is not selfobj: tv.hide(child) #start editing self.observer = VisibilityObserver(selfobj.Group, self.editCallback) except Exception as err: App.Console.PrintError( u"Error in ShapeGroup setEdit: {err}\n".format( err=err.message)) return False return True raise NotImplementedError()
def slotStartEditing(self, feature): print(u"Start Editing {f}".format(f= feature.Name)) cnt = GT.getContainer(feature) if GT.activeContainer() is not cnt: print(u"Feature being edited is not in active container. Activating {cnt}...".format(cnt= cnt.Name)) Gui.ActiveDocument.resetEdit() GT.setActiveContainer(cnt) return if feature.isDerivedFrom("PartDesign::Boolean"): # show all bodies nearby... part = GT.getContainer(cnt) children = GT.getDirectChildren(part) children = [child for child in children if child.isDerivedFrom("Part::BodyBase")] children = set(children) children.remove(cnt) for obj in GT.getAllDependent(cnt): if obj in children: children.remove(obj) tv = TempoVis(feature.Document) tv.show(children) self.edit_TVs[feature.Document.Name] = tv
def setEdit(self, selfvp, mode): print("ShapeGroup enter edit mode {num}".format(num= mode)) if mode == 0: try: selfobj = selfvp.Object #ensure right container is active from PartOMagic.Base import Containers container = Containers.getContainer(selfobj) if Containers.activeContainer() is not Containers.getContainer(selfobj): from PartOMagic.Gui import Observer Observer.activateContainer(container) selfobj.Document.openTransaction(u'Edit Tip of {sg}'.format(sg= selfobj.Label)) #prepare scene from PartOMagic.Gui.TempoVis import TempoVis self.tv = TempoVis(selfobj.Document) tv = self.tv #update visibilities of children to match what's in tip children = selfobj.Group tip = selfobj.Tip for child in children: tv.modifyVPProperty(child, 'Visibility', child in tip) #ensure children are visible, and nothing else... tv.modifyVPProperty(selfobj, 'DisplayMode','Group') tv.show(selfobj) for child in Containers.getDirectChildren(container): if child is not selfobj: tv.hide(child) #start editing self.observer = VisibilityObserver(selfobj.Group, self.editCallback) except Exception as err: App.Console.PrintError(u"Error in ShapeGroup setEdit: {err}\n".format(err= err.message)) return False return True raise NotImplementedError()
def compoundFromAssembly(root, flatten, exclude, recursive=True, visit_set=None): if visit_set is None: visit_set = set() #recursion guard if root in visit_set: raise ValueError("Circular dependency") visit_set.add(root) if hasattr(root, 'Shape'): return root.Shape else: children = Containers.getDirectChildren(root) shapes = [] for child in children: if child in exclude: continue if child.isDerivedFrom('App::Origin'): continue #otherwise, origins create empty compounds - undesirable. if hasattr(child, 'Shape'): shapes.append(child.Shape) elif Containers.isContainer(child) and recursive: cmp = compoundFromAssembly(child, flatten, exclude, recursive, visit_set) if flatten: shapes.extend(cmp.childShapes()) else: shapes.append(cmp) transform = root.Placement if hasattr(root, 'Placement') else None ret = Part.makeCompound(shapes) if transform is not None: ret.Placement = transform return ret
def RunOrTest(self, b_run): if b_run: children = Containers.getDirectChildren(Containers.activeContainer()) select(children)
def RunOrTest(self, b_run): if b_run: children = Containers.getDirectChildren( Containers.activeContainer()) select(children)