From e672aa26b4937489ffcb10f53aa8a2a63d489666 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Tue, 15 Dec 2020 16:43:33 +0100 Subject: [PATCH] Draft: Small layer improvements - Added 'Print Line Color' property - Added 'Add new layer' context menu action to layers group --- src/Mod/Draft/Resources/Draft.qrc | 1 + .../Draft/Resources/icons/Draft_NewLayer.svg | 720 ++++++++++++++++++ src/Mod/Draft/draftfunctions/svg.py | 18 +- .../Draft/draftviewproviders/view_layer.py | 32 + 4 files changed, 770 insertions(+), 1 deletion(-) create mode 100644 src/Mod/Draft/Resources/icons/Draft_NewLayer.svg diff --git a/src/Mod/Draft/Resources/Draft.qrc b/src/Mod/Draft/Resources/Draft.qrc index f914187b7f..e403999a49 100644 --- a/src/Mod/Draft/Resources/Draft.qrc +++ b/src/Mod/Draft/Resources/Draft.qrc @@ -105,6 +105,7 @@ icons/Snap_Perpendicular.svg icons/Snap_Special.svg icons/Snap_WorkingPlane.svg + icons/Draft_NewLayer.svg patterns/aluminium.svg patterns/brick01.svg patterns/concrete.svg diff --git a/src/Mod/Draft/Resources/icons/Draft_NewLayer.svg b/src/Mod/Draft/Resources/icons/Draft_NewLayer.svg new file mode 100644 index 0000000000..eb0fa91ea4 --- /dev/null +++ b/src/Mod/Draft/Resources/icons/Draft_NewLayer.svg @@ -0,0 +1,720 @@ + + + Draft_Layer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Draft_Layer + + Tue Jun 10 10:21:01 2014 -0300 + + + [Yorik van Havre] + + + + + FreeCAD LGPL2+ + + + + + FreeCAD + + + FreeCAD/src/Mod/Draft/Resources/icons/Draft_Layer.svg + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + [agryson] Alexander Gryson + + + + + page + pages + rectangles + stack + + + Three pages or rectangles stacked on top of each other. Previously VisGroup. + + + + + diff --git a/src/Mod/Draft/draftfunctions/svg.py b/src/Mod/Draft/draftfunctions/svg.py index e8f68fd604..02c13031d5 100644 --- a/src/Mod/Draft/draftfunctions/svg.py +++ b/src/Mod/Draft/draftfunctions/svg.py @@ -478,7 +478,12 @@ def get_svg(obj, else: stroke = utils.get_rgb(color) elif App.GuiUp: - if hasattr(obj, "ViewObject"): + # find print color + pc = get_print_color(obj) + if pc: + stroke = utils.get_rgb(pc) + # get line color + elif hasattr(obj, "ViewObject"): if hasattr(obj.ViewObject, "LineColor"): stroke = utils.get_rgb(obj.ViewObject.LineColor) elif hasattr(obj.ViewObject, "TextColor"): @@ -918,6 +923,17 @@ def get_svg(obj, return svg +def get_print_color(obj): + """returns the print color of the parent layer, if available""" + for parent in obj.InListRecursive: + if (hasattr(parent,"ViewObject") + and hasattr(parent.ViewObject,"UsePrintColor") + and parent.ViewObject.UsePrintColor): + if hasattr(parent.ViewObject,"LinePrintColor"): + return parent.ViewObject.LinePrintColor + return None + + def getSVG(obj, scale=1, linewidth=0.35, fontsize=12, fillstyle="shape color", direction=None, diff --git a/src/Mod/Draft/draftviewproviders/view_layer.py b/src/Mod/Draft/draftviewproviders/view_layer.py index 740cb77a83..897380827a 100644 --- a/src/Mod/Draft/draftviewproviders/view_layer.py +++ b/src/Mod/Draft/draftviewproviders/view_layer.py @@ -80,6 +80,17 @@ class ViewProviderLayer: _tip) vobj.OverrideShapeColorChildren = True + if "UsePrintColor" not in properties: + _tip = QT_TRANSLATE_NOOP("App::Property", + "If it is true, the print color " + "will be used when objects in this " + "layer are placed on a TechDraw page") + vobj.addProperty("App::PropertyBool", + "UsePrintColor", + "Print", + _tip) + + def set_visual_properties(self, vobj, properties): """Set visual properties only if they don't already exist.""" view_group = App.ParamGet("User parameter:BaseApp/Preferences/View") @@ -145,6 +156,16 @@ class ViewProviderLayer: _tip) vobj.Transparency = 0 + if "LinePrintColor" not in properties: + _tip = QT_TRANSLATE_NOOP("App::Property", + "The line color of the objects " + "contained within this layer, " + "when used on a TechDraw page") + vobj.addProperty("App::PropertyColor", + "LinePrintColor", + "Print", + _tip) + def getIcon(self): """Return the path to the icon used by the viewprovider. @@ -382,6 +403,11 @@ class ViewProviderLayerContainer: menu) action1.triggered.connect(self.merge_by_name) menu.addAction(action1) + action2 = QtGui.QAction(QtGui.QIcon(":/icons/Draft_NewLayer.svg"), + translate("Draft", "Add new layer"), + menu) + action2.triggered.connect(self.add_layer) + menu.addAction(action2) def merge_by_name(self): """Merge the layers that have the same name.""" @@ -442,6 +468,12 @@ class ViewProviderLayerContainer: _msg("InList not empty. " "Unable to delete layer: " + layer.Label) + def add_layer(self): + """Creates a new layer""" + import Draft + Draft.make_layer() + App.ActiveDocument.recompute() + def __getstate__(self): """Return a tuple of objects to save or None.""" return None