def RunOrTest(self, b_run): sel = Gui.Selection.getSelection() if len(sel)==0 : raise CommandError(self,"No object selected. Please select an object from another container, first.") elif len(sel)==1: sel = sel[0] cnt = Containers.getContainer(sel) if cnt is Containers.activeContainer(): raise CommandError(self, "This object is already in active container. Please select an object that is not in active container, or activate another container.") if b_run: TransferObject([sel], Containers.activeContainer()) else: # multiple selection. Checking is involved. Let's just assume it's correct. if b_run: TransferObject(sel, Containers.activeContainer())
def RunOrTest(self, b_run): # outline. # 0. user click calls Activated(). # 1. set up self.waiter, which waits for new object to be created # 2. waiter calls Activated() of this command, and knows what object was created # 3. command removes waiter, and calls morphContainer if self.waiter is not None: if self.waiter.is_done: waiter = self.waiter self.waiter = None assert(b_run) #enforce PoM observer to put feature into appropriate container from PartOMagic.Gui import Observer as pomObserver if pomObserver.isRunning(): pomObserver.observerInstance.poll() #check if not Containers.isContainer(waiter.target_container): raise CommandError(self, u"You created {obj}, which isn't a container. Can't morph {src} into {objt}. Morphing canceled." .format(obj= waiter.target_container, objt= waiter.target_container, src= waiter.source_container)) #make sure active container is not being messed with... ac = Containers.activeContainer() if waiter.source_container in Containers.getContainerChain(ac)+[ac]: pomObserver.activateContainer(Containers.getContainer(waiter.source_container)) if waiter.target_container in Containers.getContainerChain(ac)+[ac]: pomObserver.activateContainer(Containers.getContainer(waiter.target_container)) # do it! with Transaction("Morph container"): morphContainer(waiter.source_container, waiter.target_container) return else: raise CommandError(self, "(waiting for new container to be created...)") sel = Gui.Selection.getSelection() if len(sel)==0 : raise CommandError(self, self.GetResources()['ToolTip']) elif len(sel)==1: sel = sel[0] if not Containers.isContainer(sel): raise CommandError(self, "Selected object is not a container") ac = Containers.activeContainer() if sel in Containers.getContainerChain(ac)+[ac]: raise CommandError(self, "Deactivate the container to be morphed first, please.") if b_run: self.waiter = WaitForNewContainer(self, sel) if b_run: Gui.Selection.clearSelection() else: raise CommandError(self, u"You need to select exactly one object (you selected {num}), ad it must be a container.".format(num= len(sel)))
def RunOrTest(self, b_run): if Gui.ActiveDocument: in_edit = Gui.ActiveDocument.getInEdit() if in_edit is not None: raise CommandError( self, u"{object} is currently being edited. Can't enter anything." .format(object=in_edit.Object.Label)) sel = Gui.Selection.getSelection() if len(sel) == 0: raise CommandError( self, "Enter Object command. Please select an object to enter, first. It can be a container, or a sketch." ) elif len(sel) == 1: sel = screen(sel[0]) ac = Containers.activeContainer() if Containers.isContainer(sel): if sel in Containers.getContainerChain(ac) + [ac]: raise CommandError(self, "Already inside this object") if b_run: Containers.setActiveContainer(sel) if b_run: Gui.Selection.clearSelection() else: cnt = Containers.getContainer(sel) if ac is cnt: if b_run: Gui.ActiveDocument.setEdit(sel) else: if b_run: Containers.setActiveContainer(cnt) else: raise CommandError( self, u"Enter Object 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 : 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 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: 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 RunOrTest(self, b_run): sel = Gui.Selection.getSelection() if len(sel)==0 : raise CommandError(self,"No object selected. Please select objects to duplicate, first.") else: if b_run: (full_list, top_list, implicit_list) = Containers.expandList(sel) duplicateObjects(full_list, top_list, Containers.activeContainer())
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 an object from another container, first." ) elif len(sel) == 1: sel = sel[0] cnt = Containers.getContainer(sel) if cnt is Containers.activeContainer(): raise CommandError( self, "This object is already in active container. Please select an object that is not in active container, or activate another container." ) if b_run: TransferObject([sel], Containers.activeContainer()) else: # multiple selection. Checking is involved. Let's just assume it's correct. if b_run: TransferObject(sel, Containers.activeContainer())
def RunOrTest(self, b_run): sel = Gui.Selection.getSelection() if len(sel) == 0: raise CommandError( self, "No object selected. Please select objects to duplicate, first." ) else: if b_run: (full_list, top_list, implicit_list) = Containers.expandList(sel) duplicateObjects(full_list, top_list, Containers.activeContainer())
def RunOrTest(self, b_run): sel = Gui.Selection.getSelection() if len(sel)==0 : raise CommandError(self, "MUX Assembly command. Please select a Part container, then invoke the tool. A mux object will be created, a compound of all features of Part.") elif len(sel)==1: sel = sel[0] ac = Containers.activeContainer() if b_run: if sel in (Containers.getAllDependent(ac)+ [ac]): raise CommandError(self, "Can't create MUX here, because a circular dependency will result.") Create(sel) else: raise CommandError(self, u"MUX Assembly 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, "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 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): if Gui.ActiveDocument.getInEdit() is not None: if b_run: Gui.ActiveDocument.resetEdit() App.ActiveDocument.recompute() App.ActiveDocument.commitTransaction() elif Gui.Control.activeDialog(): if b_run: Gui.Control.closeDialog() App.ActiveDocument.recompute() App.ActiveDocument.commitTransaction() else: ac = Containers.activeContainer() if ac.isDerivedFrom("App::Document"): raise CommandError(self, "Nothing to leave.") if b_run: Containers.setActiveContainer(Containers.getContainer(ac)) if b_run: Gui.Selection.clearSelection() if b_run: Gui.Selection.addSelection(ac) if b_run: App.ActiveDocument.recompute() #fixme: scoped recompute, maybe?
def RunOrTest(self, b_run): if Gui.ActiveDocument.getInEdit() is not None: if b_run: Gui.ActiveDocument.resetEdit() App.ActiveDocument.recompute() App.ActiveDocument.commitTransaction() elif Gui.Control.activeDialog(): if b_run: Gui.Control.closeDialog() App.ActiveDocument.recompute() App.ActiveDocument.commitTransaction() else: ac = Containers.activeContainer() if ac.isDerivedFrom("App::Document"): raise CommandError(self, "Nothing to leave.") if b_run: Containers.setActiveContainer(Containers.getContainer(ac)) if b_run: Gui.Selection.clearSelection() if b_run: Gui.Selection.addSelection(ac) if b_run: App.ActiveDocument.recompute() #fixme: scoped recompute, maybe?
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 RunOrTest(self, b_run): sel = Gui.Selection.getSelection() if len(sel) == 0: raise CommandError( self, "MUX Assembly command. Please select a Part container, then invoke the tool. A mux object will be created, a compound of all features of Part." ) elif len(sel) == 1: sel = sel[0] ac = Containers.activeContainer() if b_run: if sel in (Containers.getAllDependent(ac) + [ac]): raise CommandError( self, "Can't create MUX here, because a circular dependency will result." ) Create(sel) else: raise CommandError( self, u"MUX Assembly command. You need to select exactly one object (you selected {num})." .format(num=len(sel)))
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 RunOrTest(self, b_run): if Gui.ActiveDocument: in_edit = Gui.ActiveDocument.getInEdit() if in_edit is not None: raise CommandError(self, u"{object} is currently being edited. Can't enter anything.".format(object= in_edit.Object.Label)) sel = Gui.Selection.getSelection() if len(sel)==0 : raise CommandError(self, "Enter Object command. Please select an object to enter, first. It can be a container, or a sketch.") elif len(sel)==1: sel = screen(sel[0]) ac = Containers.activeContainer() if Containers.isContainer(sel): if sel in Containers.getContainerChain(ac) + [ac]: raise CommandError(self, "Already inside this object") if b_run: Containers.setActiveContainer(sel) if b_run: Gui.Selection.clearSelection() else: cnt = Containers.getContainer(sel) if ac is cnt: if b_run: Gui.ActiveDocument.setEdit(sel) else: if b_run: Containers.setActiveContainer(cnt) else: raise CommandError(self, u"Enter Object command. You need to select exactly one object (you selected {num}).".format(num= len(sel)))
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)
def expandednessChanged(self, old_state, new_state): ac = Containers.activeContainer() activeChain = Containers.getContainerChain(ac) + [ac] self.call( self.doDisplayModeAutomation, ac, ac, +1 if new_state == True else (0 if self.selfobj in activeChain else -1))
def expandednessChanged(self, old_state, new_state): ac = Containers.activeContainer() activeChain = Containers.getContainerChain(ac)+[ac] self.call(self.doDisplayModeAutomation, ac, ac, +1 if new_state == True else (0 if self.selfobj in activeChain else -1))
def RunOrTest(self, b_run): # outline. # 0. user click calls Activated(). # 1. set up self.waiter, which waits for new object to be created # 2. waiter calls Activated() of this command, and knows what object was created # 3. command removes waiter, and calls morphContainer if self.waiter is not None: if self.waiter.is_done: waiter = self.waiter self.waiter = None assert (b_run) #enforce PoM observer to put feature into appropriate container from PartOMagic.Gui import Observer as pomObserver if pomObserver.isRunning(): pomObserver.observerInstance.poll() #check if not Containers.isContainer(waiter.target_container): raise CommandError( self, u"You created {obj}, which isn't a container. Can't morph {src} into {objt}. Morphing canceled." .format(obj=waiter.target_container, objt=waiter.target_container, src=waiter.source_container)) #make sure active container is not being messed with... ac = Containers.activeContainer() if waiter.source_container in Containers.getContainerChain( ac) + [ac]: pomObserver.activateContainer( Containers.getContainer(waiter.source_container)) if waiter.target_container in Containers.getContainerChain( ac) + [ac]: pomObserver.activateContainer( Containers.getContainer(waiter.target_container)) # do it! with Transaction("Morph container"): morphContainer(waiter.source_container, waiter.target_container) return else: raise CommandError( self, "(waiting for new container to be created...)") sel = Gui.Selection.getSelection() if len(sel) == 0: raise CommandError(self, self.GetResources()['ToolTip']) elif len(sel) == 1: sel = sel[0] if not Containers.isContainer(sel): raise CommandError(self, "Selected object is not a container") ac = Containers.activeContainer() if sel in Containers.getContainerChain(ac) + [ac]: raise CommandError( self, "Deactivate the container to be morphed first, please.") if b_run: self.waiter = WaitForNewContainer(self, sel) if b_run: Gui.Selection.clearSelection() else: raise CommandError( self, u"You need to select exactly one object (you selected {num}), ad it must be a container." .format(num=len(sel)))