예제 #1
0
 def slotDeletedObject(self, feature):
     print (u"deleted {feat}. container chain: {chain}"
             .format(feat= feature.Name, chain= ".".join([cnt.Name for cnt in GT.getContainerChain(feature)])))
     ac = activeContainer()
     if feature in GT.getContainerChain(ac)+[ac]:
         # active container was deleted. Need to leave it ASAP, as long as we can access the chain
         setActiveContainer(GT.getContainer(feature))
         self.poll()
예제 #2
0
 def slotDeletedObject(self, feature):
     print(u"deleted {feat}. container chain: {chain}".format(
         feat=feature.Name,
         chain=".".join([cnt.Name
                         for cnt in GT.getContainerChain(feature)])))
     ac = activeContainer()
     if feature in GT.getContainerChain(ac) + [ac]:
         # active container was deleted. Need to leave it ASAP, as long as we can access the chain
         setActiveContainer(GT.getContainer(feature))
         self.poll()
예제 #3
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)))
예제 #4
0
 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)))
예제 #5
0
 def fillList(self):
     lw = self.form.treeR
     lw.clear()
     lw.setColumnCount(len(self.columns))
     lw.setHeaderLabels(self.column_titles)
     for repl in self.replacements:
         item = QtGui.QTreeWidgetItem(lw)
         
         item.setText(self.column['Kind'], repl.relation.kind)
         item.setText(self.column['Object'], repl.relation.linking_object.Label)
         item.setText(self.column['Property'], repl.relation.linking_property)
         try:
             chain = Containers.getContainerChain(repl.relation.linking_object)[1:] + [repl.relation.linking_object] #[1:] strips off project name, to unclutter the column.
             path = '.'.join([cnt.Name for cnt in chain])
         except Exception as err:
             import traceback
             tb = traceback.format_exc()
             App.Console.PrintError(tb+'\n\n')
             path = "!" + str(err)
         item.setText(self.column['Path'], path)
         item.setText(self.column['Value'], str(repl.relation.value_repr))
         
         repl.gui_item = item
         item.setData(0,256,repl)
         flags = Qt.ItemIsUserCheckable | Qt.ItemIsSelectable
         if not repl.disabled:
             flags = flags | Qt.ItemIsEnabled
         item.setFlags(flags)
         item.setCheckState(0, Qt.Checked if repl.checked else Qt.Unchecked)
         if repl.disabled:
             item.setText(self.column['State'], repl.disabled_reason)
예제 #6
0
    def fillList(self):
        lw = self.form.treeR
        lw.clear()
        lw.setColumnCount(len(self.columns))
        lw.setHeaderLabels(self.column_titles)
        for repl in self.replacements:
            item = QtGui.QTreeWidgetItem(lw)

            item.setText(self.column['Kind'], repl.relation.kind)
            item.setText(self.column['Object'],
                         repl.relation.linking_object.Label)
            item.setText(self.column['Property'],
                         repl.relation.linking_property)
            try:
                chain = Containers.getContainerChain(
                    repl.relation.linking_object)[1:] + [
                        repl.relation.linking_object
                    ]  #[1:] strips off project name, to unclutter the column.
                path = '.'.join([cnt.Name for cnt in chain])
            except Exception as err:
                import traceback
                tb = traceback.format_exc()
                App.Console.PrintError(tb + '\n\n')
                path = "!" + str(err)
            item.setText(self.column['Path'], path)
            item.setText(self.column['Value'], str(repl.relation.value_repr))

            repl.gui_item = item
            item.setData(0, 256, repl)
            flags = Qt.ItemIsUserCheckable | Qt.ItemIsSelectable
            if not repl.disabled:
                flags = flags | Qt.ItemIsEnabled
            item.setFlags(flags)
            item.setCheckState(0, Qt.Checked if repl.checked else Qt.Unchecked)
            if repl.disabled:
                item.setText(self.column['State'], repl.disabled_reason)
예제 #7
0
 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)))            
예제 #8
0
 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))
예제 #9
0
def getPartOf(feature):
    chain = GT.getContainerChain(feature)
    for cnt in chain[::-1]:
        if not cnt.isDerivedFrom("PartDesign::Body"):
            return cnt
    assert(False)
예제 #10
0
 def slotDeletedObject(self, feature):
     ac = activeContainer()
     if feature in GT.getContainerChain(ac)+[ac]:
         # active container was deleted. Need to leave it ASAP, as long as we can access the chain
         setActiveContainer(GT.getContainer(feature))
         self.poll()
예제 #11
0
def morphContainer(src_container, dst_container):
    if not Containers.isContainer(src_container):
        raise TypeError(u"{obj} is not a container".format(obj= src_container.Label))
    if not Containers.isContainer(dst_container):
        raise TypeError(u"{obj} is not a container".format(obj= dst_container.Label))
    if src_container in Containers.getContainerChain(dst_container):
        raise Containers.ContainerTreeError(u"Cannot morph {src} into {dst}, because {src} contains {dst}"
                                            .format(src= src_container.Label, dst= dst_container.Label))
    
    doc = dst_container.Document

    #origin...
    if hasattr(src_container, "Origin") and hasattr(dst_container, "Origin"):
        if dst_container.Origin is not None: 
            doc.removeObject(dst_container.Origin.Name)
        dst_container.Origin = src_container.Origin; src_container.Origin = None
    
    #content
    assert(len(dst_container.Group) == 0)
    g = src_container.Group
    src_container.Group = [] #withdraw first, add last - otherwise, error is thrown
    dst_container.Group = g 
    if hasattr(dst_container, 'Origin'):
        if hasattr(dst_container, 'Proxy') and dst_container.Origin is not None:
            #workaround for origin not being claimed as child on Py-powered containers
            dst_container.Group = [dst_container.Origin] + dst_container.Group 
        elif dst_container.Origin is not None and dst_container.Origin in dst_container.Group:
            #if converting Py cotainer into c++-one, undo the workaround
            content = dst_container.Group 
            content.remove(dst_container.Origin)
    
    #Tip
    if hasattr(src_container, "Tip") and hasattr(dst_container, "Tip"):
        tip_list = src_container.Tip
        if type(tip_list) is not list:
            tip_list = [tip_list] if tip_list is not None else []
        if type(dst_container.Tip) is list:
            dst_container.Tip = tip_list
        else:
            if len(tip_list) == 0:
                dst_container.Tip = None
            elif len(tip_list) == 1:
                dst_container.Tip = tip_list[0]
            else:
                App.Console.PrintWarning(u"Target Tip can only point to one object. Source Tip points to {num}. Last object from source tip was taken.\n"
                                         .format(num= len(tip_list)))
                dst_container.Tip = tip_list[-1]
    
    #other properties...
    
    properties_to_avoid = set([
        # these are avoided because they need manual treatment...
        'Group',
        'Origin',
        'ExpressionEngine',
        'Tip',
        'Label',
        #.. and these should never be copied at all
        'ExtensionProxy',
        'Proxy',
    ])
    
    properties_to_copy = []
    for prop in src_container.PropertiesList:
        if len(src_container.getEditorMode(prop)) == 0: # screen out read-only and hidden properties
            if not prop in properties_to_avoid:
                properties_to_copy.append(prop)
    
    print("copying properties")
    for prop in properties_to_copy:
        print("  "+prop)
        copyProperty(src_container, dst_container, prop)
        
    #Copy expressions
    for expr in src_container.ExpressionEngine:
        dst_container.setExpression(*expr)
        
    #redirect links
    substituteObjectInProperties(src_container, dst_container, doc.Objects)
    substituteObjectInExpressions(src_container, dst_container, doc.Objects)
    substituteObjectInSpreadsheets(src_container, dst_container, doc.Objects)
    
    label = src_container.Label
    label = label.replace(src_container.Name, dst_container.Name)
    
    Containers.withdrawObject(src_container)
    doc.removeObject(src_container.Name)
    
    #copy Label last, because otherwise it gets "001" at the end...
    dst_container.Label = label
예제 #12
0
def morphContainer(src_container, dst_container):
    if not Containers.isContainer(src_container):
        raise TypeError(
            u"{obj} is not a container".format(obj=src_container.Label))
    if not Containers.isContainer(dst_container):
        raise TypeError(
            u"{obj} is not a container".format(obj=dst_container.Label))
    if src_container in Containers.getContainerChain(dst_container):
        raise Containers.ContainerTreeError(
            u"Cannot morph {src} into {dst}, because {src} contains {dst}".
            format(src=src_container.Label, dst=dst_container.Label))

    doc = dst_container.Document

    #origin...
    if hasattr(src_container, "Origin") and hasattr(dst_container, "Origin"):
        if dst_container.Origin is not None:
            doc.removeObject(dst_container.Origin.Name)
        dst_container.Origin = src_container.Origin
        src_container.Origin = None

    #content
    assert (len(dst_container.Group) == 0)
    g = src_container.Group
    src_container.Group = [
    ]  #withdraw first, add last - otherwise, error is thrown
    dst_container.Group = g
    if hasattr(dst_container, 'Origin'):
        if hasattr(dst_container,
                   'Proxy') and dst_container.Origin is not None:
            #workaround for origin not being claimed as child on Py-powered containers
            dst_container.Group = [dst_container.Origin] + dst_container.Group
        elif dst_container.Origin is not None and dst_container.Origin in dst_container.Group:
            #if converting Py cotainer into c++-one, undo the workaround
            content = dst_container.Group
            content.remove(dst_container.Origin)

    #Tip
    if hasattr(src_container, "Tip") and hasattr(dst_container, "Tip"):
        tip_list = src_container.Tip
        if type(tip_list) is not list:
            tip_list = [tip_list] if tip_list is not None else []
        if type(dst_container.Tip) is list:
            dst_container.Tip = tip_list
        else:
            if len(tip_list) == 0:
                dst_container.Tip = None
            elif len(tip_list) == 1:
                dst_container.Tip = tip_list[0]
            else:
                App.Console.PrintWarning(
                    u"Target Tip can only point to one object. Source Tip points to {num}. Last object from source tip was taken.\n"
                    .format(num=len(tip_list)))
                dst_container.Tip = tip_list[-1]

    #other properties...

    properties_to_avoid = set([
        # these are avoided because they need manual treatment...
        'Group',
        'Origin',
        'ExpressionEngine',
        'Tip',
        'Label',
        #.. and these should never be copied at all
        'ExtensionProxy',
        'Proxy',
    ])

    properties_to_copy = []
    for prop in src_container.PropertiesList:
        if len(src_container.getEditorMode(
                prop)) == 0:  # screen out read-only and hidden properties
            if not prop in properties_to_avoid:
                properties_to_copy.append(prop)

    print("copying properties")
    for prop in properties_to_copy:
        print("  " + prop)
        copyProperty(src_container, dst_container, prop)

    #Copy expressions
    for expr in src_container.ExpressionEngine:
        dst_container.setExpression(*expr)

    #redirect links
    substituteObjectInProperties(src_container, dst_container, doc.Objects)
    substituteObjectInExpressions(src_container, dst_container, doc.Objects)
    substituteObjectInSpreadsheets(src_container, dst_container, doc.Objects)

    label = src_container.Label
    label = label.replace(src_container.Name, dst_container.Name)

    Containers.withdrawObject(src_container)
    doc.removeObject(src_container.Name)

    #copy Label last, because otherwise it gets "001" at the end...
    dst_container.Label = label
예제 #13
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)))
예제 #14
0
def getPartOf(feature):
    chain = GT.getContainerChain(feature)
    for cnt in chain[::-1]:
        if not cnt.isDerivedFrom("PartDesign::Body"):
            return cnt
    assert(False)
예제 #15
0
 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))