From 9fad078ba2e350279b9b807cfbdc4683548b2dd3 Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Mon, 21 Jun 2021 21:07:41 +0200 Subject: [PATCH 1/2] Fix 3 issues with the Draft Tray layer list Fix 3 issues with the Draft Tray layer list: The layer list should display even if there are no layers so that the "Add new Layer" option can be selected. "Project" and "BuildingPart" objects should be added to the list (depending on "AutogroupAddGroups" of course). The "LayerContainer" object should not be added to the list. Although it is in fact a group, it is just too confusing. Added is_group function. This function can also be used in gui_groups.py. --- src/Mod/Draft/draftutils/groups.py | 39 ++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/Mod/Draft/draftutils/groups.py b/src/Mod/Draft/draftutils/groups.py index 25118adc94..e58c557721 100644 --- a/src/Mod/Draft/draftutils/groups.py +++ b/src/Mod/Draft/draftutils/groups.py @@ -41,6 +41,34 @@ from draftutils.translate import _tr from draftutils.messages import _msg, _err +def is_group(obj): + """Return True if the given object is considered a group. + + Parameters + ---------- + obj : App::DocumentObject + The object to check. + + Returns + ------- + bool + Returns `True` if `obj` is considered a group: + + The object is derived from `App::DocumentObjectGroup` but not + a `'LayerContainer'`. + + Or the object is of the type `'Project'`, `'Site'`, `'Building'`, + `'Floor'` or `'BuildingPart'` from the Arch Workbench. + + Otherwise returns `False`. + """ + + return ((obj.isDerivedFrom("App::DocumentObjectGroup") + and obj.Name != "LayerContainer") + or utils.get_type(obj) in ("Project", "Site", "Building", + "Floor", "BuildingPart")) + + def get_group_names(doc=None): """Return a list of names of existing groups in the document. @@ -54,12 +82,10 @@ def get_group_names(doc=None): Returns ------- list of str - A list of names of objects that are "groups". - These are objects derived from `App::DocumentObjectGroup` - or which are of types `'Floor'`, `'Building'`, or `'Site'` - from the Arch Workbench. + A list of names of objects that are considered groups. + See the is_group function. - Otherwise, return an empty list. + Otherwise returns an empty list. """ if not doc: found, doc = utils.find_doc(App.activeDocument()) @@ -71,8 +97,7 @@ def get_group_names(doc=None): glist = [] for obj in doc.Objects: - if (obj.isDerivedFrom("App::DocumentObjectGroup") - or utils.get_type(obj) in ("Floor", "Building", "Site")): + if is_group(obj): glist.append(obj.Name) return glist From 3401a63d682ceb4aa72405d49e3cf884cf258e7e Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Mon, 21 Jun 2021 21:11:52 +0200 Subject: [PATCH 2/2] Fix 3 issues with the Draft Tray layer list Fix 3 issues with the Draft Tray layer list: The layer list should display even if there are no layers so that the "Add new Layer" option can be selected. "Project" and "BuildingPart" objects should be added to the list (depending on "AutogroupAddGroups" of course). The "LayerContainer" object should not be added to the list. Although it is in fact a group, it is just too confusing. --- src/Mod/Draft/draftguitools/gui_groups.py | 46 +++++++++++------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/Mod/Draft/draftguitools/gui_groups.py b/src/Mod/Draft/draftguitools/gui_groups.py index a5d2b22988..cbb4d46774 100644 --- a/src/Mod/Draft/draftguitools/gui_groups.py +++ b/src/Mod/Draft/draftguitools/gui_groups.py @@ -254,14 +254,13 @@ class SetAutoGroup(gui_base.GuiCommandSimplest): # and globally initialized in the `Gui` namespace to run # some actions. # If there is only a group selected, it runs the `AutoGroup` method. + params = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft") 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/Draft").GetBool("AutogroupAddGroups", False) - and (s[0].isDerivedFrom("App::DocumentObjectGroup") - or utils.get_type(s[0]) in ["Site", "Building", - "Floor", "BuildingPart"])): + if (utils.get_type(s[0]) == "Layer" + or (params.GetBool("AutogroupAddGroups", False) + and groups.is_group(s[0]))): self.ui.setAutoGroup(s[0].Name) return @@ -269,27 +268,26 @@ class SetAutoGroup(gui_base.GuiCommandSimplest): # 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/Draft").GetBool("AutogroupAddGroups", False): + if params.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")) + 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) + # 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) def proceed(self, labelname): """Set the defined autogroup, or create a new layer.