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)))
Beispiel #2
0
    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()
Beispiel #3
0
def duplicateObjects(objects, top_objects, target_cnt):
    with Transaction("PoM Duplicate"):
        keeper = Observer.suspend()
        
        objset = set(objects)
        doc = objects[0].Document
        namelist = [obj.Name for obj in doc.TopologicalSortedObjects if obj in objset][::-1]
        
        tmp_prj = FCProject.fromFC(doc, namelist)
        map = tmp_prj.mergeToFC(doc)
        for obj in top_objects:
            new_top_obj = doc.getObject(map[obj.Name])
            Containers.addObjectTo(target_cnt, new_top_obj, b_advance_tip= True)
        keeper.release()
Beispiel #4
0
    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()
Beispiel #5
0
def duplicateObjects(objects, top_objects, target_cnt):
    with Transaction("PoM Duplicate"):
        keeper = Observer.suspend()

        objset = set(objects)
        doc = objects[0].Document
        namelist = [
            obj.Name for obj in doc.TopologicalSortedObjects if obj in objset
        ][::-1]

        tmp_prj = FCProject.fromFC(doc, namelist)
        map = tmp_prj.mergeToFC(doc)
        for obj in top_objects:
            new_top_obj = doc.getObject(map[obj.Name])
            Containers.addObjectTo(target_cnt, new_top_obj, b_advance_tip=True)
        keeper.release()
Beispiel #6
0
    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)))
Beispiel #7
0
 def IsActive(self):
     import PartOMagic.Gui.Observer as Observer
     return Observer.isRunning()
Beispiel #8
0
 def Activated(self):
     import PartOMagic.Gui.Observer as Observer
     if Observer.isRunning():
         Observer.stop()
     Params.EnableObserver.set_volatile(False)
Beispiel #9
0
 def Activated(self):
     import PartOMagic.Gui.Observer as Observer
     if not Observer.isRunning():
         Observer.start()
     Params.EnableObserver.set(True)
Beispiel #10
0
 def Activated(self):
     import PartOMagic.Gui.Observer as Observer
     if Observer.isRunning():
         Observer.stop()
     Params.EnableObserver.set(False)
Beispiel #11
0
 def IsActive(self):
     import PartOMagic.Gui.Observer as Observer
     return Observer.isRunning()
Beispiel #12
0
 def Activated(self):
     import PartOMagic.Gui.Observer as Observer
     if not Observer.isRunning():
         Observer.start()
     Params.EnableObserver.set(True)