Example #1
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)))
Example #2
0
 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)))
Example #3
0
 def RunOrTest(self, b_run):
     import FreeCADGui as Gui
     if Gui.ActiveDocument is None:
         raise CommandError(self, "No open project")
     if not hasattr(Gui.ActiveDocument.ActiveView, 'getCameraOrientation'):
         raise CommandError(self, "Not 3d view")
     if b_run:
         Gui.addModule('PartOMagic.Gui.View.SnapView')
         Gui.doCommand('PartOMagic.Gui.View.SnapView.snapView()')
Example #4
0
 def RunOrTest(self, b_run):
     from PartOMagic.Base.Containers import activeContainer
     ac = activeContainer()
     if ac is None:
         raise CommandError(self, "No active container!")
     if not ac.isDerivedFrom('PartDesign::Body'):
         raise CommandError(self, "Active container is not a PartDesign Body. Please activate a PartDesign Body, first.")
     if ac.Tip is None and self.add_sub_type != 'Additive':
         raise CommandError(self, "There is no material to subtract from. Either use additive shape feature instead, or add some material to the body.")
     if b_run: CreatePDShapeFeature('{Additive}Shape'.format(Additive= self.add_sub_type), self.add_sub_type)
Example #5
0
    def RunOrTest(self, b_run):
        sel = Gui.Selection.getSelection()
        if not 2 <= len(sel) <= 3:
            raise CommandError(
                self,
                u"Please select two or three objects. Currently selected {n}".
                format(n=len(sel)))
        if b_run:
            old = sel[0]
            new = sel[1]
            parent = sel[2] if len(sel) > 2 else None

            from PartOMagic.Base import LinkTools as LT
            rels = LT.findLinksTo(old)
            avoid = LT.getAllDependencyObjects(new)
            avoid.add(new)
            repls = [LT.Replacement(rel, new) for rel in rels]

            n_checked = 0
            for repl in repls:
                if repl.relation.linking_object in avoid:
                    repl.disable("dependency loop")
                repl.checked = not (repl.disabled)
                if parent:
                    if repl.relation.linking_object is not parent:
                        repl.checked = False
                if repl.relation.kind == 'Child':
                    repl.checked = False
                if repl.checked:
                    n_checked += 1

            if len(repls) == 0:
                raise CommandError(
                    self,
                    u"Nothing depends on {old}, nothing to replace.".format(
                        old=old.Label))

            if n_checked == 0 and len(repls) > 0:
                msgbox(
                    "Replace",
                    u"No regular replacable dependencies found, nothing uses {old}. Please pick wanted replacements manually in the dialog."
                    .format(old=old.Label))

            import TaskReplace
            task = TaskReplace.TaskReplace(
                repls,
                old.Document,
                message=u"Replacing {old} with {new}".format(old=old.Label,
                                                             new=new.Label))
Example #6
0
 def RunOrTest(self, b_run):
     import FreeCADGui as Gui
     if len(Gui.Selection.getSelectionEx(App.ActiveDocument.Name)) == 0:
         raise CommandError(
             self,
             "Please select one or more objects, first. Instances of these objects will be created."
         )
     if b_run: CreateInstance()
Example #7
0
 def RunOrTest(self, b_run):
     if len(Gui.Selection.getSelection()) == 1:
         if b_run: CreateExporter('Exporter')
     else:
         raise CommandError(
             self,
             "Creates an exporter feature, which will automatically export an object whenever it changes.\n\nPlease select an object, then invoke this command."
         )
Example #8
0
 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())
Example #9
0
 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:
             (full_list, top_list,
              implicit_list) = Containers.expandList(sel)
             select(implicit_list)
Example #10
0
 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)))
Example #11
0
 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())
Example #12
0
    def RunOrTest(self, b_run):
        sel = Gui.Selection.getSelection()
        if len(sel) != 1:
            raise CommandError(
                self,
                u"Please select one object. Currently selected {n}".format(
                    n=len(sel)))
        if b_run:
            from PartOMagic.Base import LinkTools as LT
            uses = LT.findLinksTo(sel[0])
            uses_str = '\n'.join([
                (rel.linking_object.Name + '.' + rel.linking_property + ' (' +
                 rel.kind + ')') for rel in uses
            ])
            if len(uses_str) == 0: uses_str = "(nothing)"

            links = LT.getDependencies(sel[0])
            links_str = '\n'.join([
                (rel.linked_object.Name + " as " + rel.linking_property +
                 ' (' + rel.kind + ')') for rel in links
            ])
            if len(links_str) == 0: links_str = "(nothing)"

            msg = (u"==== {obj} uses: ====\n"
                   "{links_str}\n\n"
                   "====Links to {obj}:====\n"
                   "{uses_str}").format(obj=sel[0].Label,
                                        uses_str=uses_str,
                                        links_str=links_str)

            from PySide import QtGui
            mb = QtGui.QMessageBox()
            mb.setIcon(mb.Icon.Information)
            mb.setText(msg)
            mb.setWindowTitle("Used by who?")
            btnClose = mb.addButton(QtGui.QMessageBox.StandardButton.Close)
            btnCopy = mb.addButton("Copy to clipboard",
                                   QtGui.QMessageBox.ButtonRole.ActionRole)
            btnSelect = mb.addButton("Select dependent objects",
                                     QtGui.QMessageBox.ButtonRole.ActionRole)
            mb.setDefaultButton(btnClose)
            mb.exec_()

            if mb.clickedButton() is btnCopy:
                cb = QtGui.QClipboard()
                cb.setText(msg)
            if mb.clickedButton() is btnSelect:
                objs = set([rel.linking_object for rel in uses])
                Gui.Selection.clearSelection()
                for obj in objs:
                    Gui.Selection.addSelection(obj)
Example #13
0
 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)
Example #14
0
 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)))
Example #15
0
 def containerAdded(self):
     App.removeDocumentObserver(self)
     for obj in self.new_objects:
         if Containers.canBeActive(obj):
             if self.target_container is not None:
                 raise CommandError(
                     self.command,
                     "More than one container was created. I have no idea what to do! --Part-o-Magic"
                 )
             self.target_container = obj  #if multiple objects had been created, pick one that is a container
     if self.target_container is None:
         self.target_container = self.new_objects[
             0]  #return something... so that an error message is displayed.
     self.is_done = True
     self.command.Activated()
Example #16
0
 def RunOrTest(self, b_run):
     import FreeCADGui as Gui
     sel = Gui.Selection.getSelectionEx()
     global library
     if len(sel) == 0 and len(library) == 0:
         raise CommandError(
             self,
             "Please select an object to make transparent, and invoke this command."
         )
     if b_run:
         if len(sel) == 0:
             XRay(None)
         else:
             for selobj in sel:
                 XRay(selobj.Object)
             Gui.Selection.clearSelection()
             Gui.Selection.clearPreselection()
Example #17
0
 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?
Example #18
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)))