示例#1
0
    def Activated(self):
        """Execute when the command is called.

        It calls the `setAutogroup` method of the `DraftToolBar` class
        installed inside the global `Gui` namespace.
        """
        super(SetAutoGroup, self).Activated()

        if not hasattr(Gui, "draftToolBar"):
            return

        # It uses the `DraftToolBar` class defined in the `DraftGui` module
        # and globally initialized in the `Gui` namespace to run
        # some actions.
        # If there is only a group selected, it runs the `AutoGroup` method.
        self.ui = Gui.draftToolBar
        s = Gui.Selection.getSelection()
        if len(s) == 1:
            if (utils.get_type(s[0]) == "Layer") or \
-               (App.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").GetBool("AutogroupAddGroups", False)
             and (s[0].isDerivedFrom("App::DocumentObjectGroup")
                  or utils.get_type(s[0]) in ["Site", "Building",
                                              "Floor", "BuildingPart"])):
                self.ui.setAutoGroup(s[0].Name)
                return

        # Otherwise it builds a list of layers, with names and icons,
        # including the options "None" and "Add new layer".
        self.groups = ["None"]
        gn = [o.Name for o in self.doc.Objects if utils.get_type(o) == "Layer"]
        if App.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").GetBool(
                "AutogroupAddGroups", False):
            gn.extend(groups.get_group_names())
        if gn:
            self.groups.extend(gn)
            self.labels = [translate("draft", "None")]
            self.icons = [self.ui.getIcon(":/icons/button_invalid.svg")]
            for g in gn:
                o = self.doc.getObject(g)
                if o:
                    self.labels.append(o.Label)
                    self.icons.append(o.ViewObject.Icon)
            self.labels.append(translate("draft", "Add new Layer"))
            self.icons.append(self.ui.getIcon(":/icons/document-new.svg"))

            # With the lists created is uses the interface
            # to pop up a menu with layer options.
            # Once the desired option is chosen
            # it launches the `proceed` method.
            self.ui.sourceCmd = self
            pos = self.ui.autoGroupButton.mapToGlobal(
                QtCore.QPoint(0,
                              self.ui.autoGroupButton.geometry().height()))
            self.ui.popupMenu(self.labels, self.icons, pos)
示例#2
0
    def Activated(self):
        """Execute when the command is called."""
        super(AddToGroup, self).Activated()

        self.groups = [self.ungroup]
        self.groups.extend(groups.get_group_names())

        self.labels = [self.ungroup]
        for group in self.groups:
            obj = self.doc.getObject(group)
            if obj:
                self.labels.append(obj.Label)

        # It uses the `DraftToolBar` class defined in the `DraftGui` module
        # and globally initialized in the `Gui` namespace,
        # in order to pop up a menu with group labels
        # or the default `Ungroup` text.
        # Once the desired option is chosen
        # it launches the `proceed` method.
        self.ui = Gui.draftToolBar
        self.ui.sourceCmd = self
        self.ui.popupMenu(self.labels)