From 0745f760a028651a1dfc5bfc10fad3f494aa1824 Mon Sep 17 00:00:00 2001 From: carlopav Date: Fri, 10 Apr 2020 17:39:32 +0200 Subject: [PATCH] [Draft] Removed annotation styles objects Removed Annotation styles current implementation. As pointed out by yorik, in https://forum.freecadweb.org/viewtopic.php?f=23&t=44051&p=385710#p385179, this feature will be added using document Meta property. --- src/Mod/Draft/CMakeLists.txt | 3 - src/Mod/Draft/InitGui.py | 1 - src/Mod/Draft/Resources/Draft.qrc | 2 - .../Resources/icons/Draft_Dimension_Style.svg | 404 ------------- .../icons/Draft_Dimension_Style_Tree.svg | 542 ------------------ .../Draft/draftguitools/gui_dimensionstyle.py | 71 --- src/Mod/Draft/draftobjects/dimension.py | 37 +- src/Mod/Draft/draftobjects/dimensionstyle.py | 123 ---- .../draftviewproviders/view_dimensionstyle.py | 158 ----- 9 files changed, 4 insertions(+), 1337 deletions(-) delete mode 100644 src/Mod/Draft/Resources/icons/Draft_Dimension_Style.svg delete mode 100644 src/Mod/Draft/Resources/icons/Draft_Dimension_Style_Tree.svg delete mode 100644 src/Mod/Draft/draftguitools/gui_dimensionstyle.py delete mode 100644 src/Mod/Draft/draftobjects/dimensionstyle.py delete mode 100644 src/Mod/Draft/draftviewproviders/view_dimensionstyle.py diff --git a/src/Mod/Draft/CMakeLists.txt b/src/Mod/Draft/CMakeLists.txt index 10ca81f2c4..40687f5a31 100644 --- a/src/Mod/Draft/CMakeLists.txt +++ b/src/Mod/Draft/CMakeLists.txt @@ -67,7 +67,6 @@ SET(Draft_objects draftobjects/draft_annotation.py draftobjects/label.py draftobjects/dimension.py - draftobjects/dimensionstyle.py draftobjects/text.py draftobjects/README.md ) @@ -80,7 +79,6 @@ SET(Draft_view_providers draftviewproviders/view_draft_annotation.py draftviewproviders/view_label.py draftviewproviders/view_dimension.py - draftviewproviders/view_dimensionstyle.py draftviewproviders/view_text.py draftviewproviders/README.md ) @@ -89,7 +87,6 @@ SET(Draft_GUI_tools draftguitools/__init__.py draftguitools/gui_base.py draftguitools/gui_circulararray.py - draftguitools/gui_dimensionstyle.py draftguitools/gui_orthoarray.py draftguitools/gui_polararray.py draftguitools/gui_planeproxy.py diff --git a/src/Mod/Draft/InitGui.py b/src/Mod/Draft/InitGui.py index 7513c3d3fe..0178ec4978 100644 --- a/src/Mod/Draft/InitGui.py +++ b/src/Mod/Draft/InitGui.py @@ -86,7 +86,6 @@ class DraftWorkbench(FreeCADGui.Workbench): from draftguitools import gui_polararray from draftguitools import gui_orthoarray from draftguitools import gui_arrays - from draftguitools import gui_style_dimension FreeCADGui.addLanguagePath(":/translations") FreeCADGui.addIconPath(":/icons") except Exception as exc: diff --git a/src/Mod/Draft/Resources/Draft.qrc b/src/Mod/Draft/Resources/Draft.qrc index 06c8ea3b8c..5e0c16a03b 100644 --- a/src/Mod/Draft/Resources/Draft.qrc +++ b/src/Mod/Draft/Resources/Draft.qrc @@ -25,8 +25,6 @@ icons/Draft_DelPoint.svg icons/Draft_Dimension.svg icons/Draft_Dimension_Tree.svg - icons/Draft_Dimension_Style.svg - icons/Draft_Dimension_Style_Tree.svg icons/Draft_DimensionAngular.svg icons/Draft_DimensionRadius.svg icons/Draft_Dot.svg diff --git a/src/Mod/Draft/Resources/icons/Draft_Dimension_Style.svg b/src/Mod/Draft/Resources/icons/Draft_Dimension_Style.svg deleted file mode 100644 index 5e6f485bf6..0000000000 --- a/src/Mod/Draft/Resources/icons/Draft_Dimension_Style.svg +++ /dev/null @@ -1,404 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - Mon Oct 10 13:44:52 2011 +0000 - - - [wmayer] - - - - - FreeCAD LGPL2+ - - - - - FreeCAD - - - FreeCAD/src/Mod/Draft/Resources/icons/Draft_Dimension.svg - http://www.freecadweb.org/wiki/index.php?title=Artwork - - - [agryson] Alexander Gryson - - - - - line - dot - number - - - A number floating above a line corresponding to the upper three sides of a rectangle with a dot at each endpoint and corner - - - - diff --git a/src/Mod/Draft/Resources/icons/Draft_Dimension_Style_Tree.svg b/src/Mod/Draft/Resources/icons/Draft_Dimension_Style_Tree.svg deleted file mode 100644 index 0b13bf93db..0000000000 --- a/src/Mod/Draft/Resources/icons/Draft_Dimension_Style_Tree.svg +++ /dev/null @@ -1,542 +0,0 @@ - - - Draft_Dimension_Tree - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - Draft_Dimension_Tree - - Wed Oct 6 12:19:00 2019 -0600 - - - [vocx] - - - - - FreeCAD LGPL2+ - - - - - FreeCAD - - - FreeCAD/src/Mod/Draft/Resources/icons/Draft_Dimenstion_Tree - http://www.freecadweb.org/wiki/index.php?title=Artwork - - - [agryson] Alexander Gryson, [yorikvanhavre] - - - - - triangle - arrows - - - Two triangles, one pointing left, the other right, with a small line between the two - - - - - - - - - - - - - - - - diff --git a/src/Mod/Draft/draftguitools/gui_dimensionstyle.py b/src/Mod/Draft/draftguitools/gui_dimensionstyle.py deleted file mode 100644 index 71155f30b8..0000000000 --- a/src/Mod/Draft/draftguitools/gui_dimensionstyle.py +++ /dev/null @@ -1,71 +0,0 @@ -# *************************************************************************** -# * (c) 2020 Carlo Pavan * -# * * -# * This file is part of the FreeCAD CAx development system. * -# * * -# * This program is free software; you can redistribute it and/or modify * -# * it under the terms of the GNU Lesser General Public License (LGPL) * -# * as published by the Free Software Foundation; either version 2 of * -# * the License, or (at your option) any later version. * -# * for detail see the LICENCE text file. * -# * * -# * FreeCAD is distributed in the hope that it will be useful, * -# * but WITHOUT ANY WARRANTY; without even the implied warranty of * -# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -# * GNU Library General Public License for more details. * -# * * -# * You should have received a copy of the GNU Library General Public * -# * License along with FreeCAD; if not, write to the Free Software * -# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -# * USA * -# * * -# *************************************************************************** - -"""This module provides the Draft Dimension Style tool. -""" -## @package gui_style_dimension -# \ingroup DRAFT -# \brief This module provides the Draft Dimension Style tool. - -import FreeCAD as App -import FreeCADGui as Gui -from PySide import QtCore -from . import gui_base -from draftutils import utils -from draftobjects.dimensionstyle import make_dimension_style - - - -class GuiCommandDimensionStyle(gui_base.GuiCommandSimplest): - """ - The command creates a dimension style object - """ - def __init__(self): - super().__init__(name="Dimension style") - - def GetResources(self): - _msg = ("Creates a new dimension style.\n" - "The object stores dimension preferences into the document." - ) - return {'Pixmap' : 'Draft_Annotation_Style', - 'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft", "Dimension Style"), - 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Draft", _msg)} - - def IsActive(self): - if Gui.ActiveDocument: - return True - else: - return False - - def Activated(self): - sel = Gui.Selection.getSelection() - - if len(sel) == 1: - if utils.get_type(sel[0]) == 'Dimension': - make_dimension_style(sel[0]) - return - - make_dimension_style() - - -Gui.addCommand('Draft_DimensionStyle', GuiCommandDimensionStyle()) diff --git a/src/Mod/Draft/draftobjects/dimension.py b/src/Mod/Draft/draftobjects/dimension.py index e78d949cbd..6ee342c5aa 100644 --- a/src/Mod/Draft/draftobjects/dimension.py +++ b/src/Mod/Draft/draftobjects/dimension.py @@ -32,7 +32,7 @@ import FreeCAD as App import math from PySide.QtCore import QT_TRANSLATE_NOOP -import DraftGeomUtils +import DraftGeomUtils, DraftVecUtils import draftutils.gui_utils as gui_utils import draftutils.utils as utils from draftobjects.draft_annotation import DraftAnnotation @@ -113,22 +113,13 @@ def make_dimension(p1,p2,p3=None,p4=None): normal = normal.negative() obj.Normal = normal - # format dimension according to ActiveDimensionStyle or user Preferences - _style_applied = False - if hasattr(App.ActiveDocument, "DimensionStyles"): - active_style = App.ActiveDocument.DimensionStyles.ActiveDimensionStyle - if active_style is not None: - obj.DimensionStyle = active_style - _style_applied = True if App.GuiUp: - if not _style_applied: - gui_utils.format_object(obj) + gui_utils.format_object(obj) gui_utils.select(obj) return obj - def make_angular_dimension(center,angles,p3,normal=None): """makeAngularDimension(center,angle1,angle2,p3,[normal]): creates an angular Dimension from the given center, with the given list of angles, passing through p3. @@ -159,18 +150,9 @@ def make_angular_dimension(center,angles,p3,normal=None): normal = normal.negative() obj.Normal = normal - - # format dimension according to ActiveDimensionStyle or user Preferences - _style_applied = False - if hasattr(App.ActiveDocument, "DimensionStyles"): - active_style = App.ActiveDocument.DimensionStyles.ActiveDimensionStyle - if active_style is not None: - obj.DimensionStyle = active_style - _style_applied = True if App.GuiUp: - if not _style_applied: - gui_utils.format_object(obj) + gui_utils.format_object(obj) gui_utils.select(obj) return obj @@ -188,12 +170,6 @@ class DimensionBase(DraftAnnotation): "Initialize common properties for dimension objects" DraftAnnotation.__init__(self,obj, tp) - # Annotation - obj.addProperty("App::PropertyLink","DimensionStyle", - "Annotation", - QT_TRANSLATE_NOOP("App::Property", - "Link dimension style")) - # Draft obj.addProperty("App::PropertyVector", "Normal", @@ -222,9 +198,7 @@ class DimensionBase(DraftAnnotation): def onChanged(self,obj,prop): - if prop == "DimensionStyle": - if hasattr(obj, "DimensionStyle"): - gui_utils.format_object(target = obj, origin = obj.DimensionStyle) + return def execute(self, obj): @@ -284,9 +258,6 @@ class LinearDimension(DimensionBase): # obj.setEditorMode('Normal', 2) if hasattr(obj, "Support"): obj.setEditorMode('Support', 2) - if prop == "DimensionStyle": - if hasattr(obj, "DimensionStyle"): - gui_utils.format_object(target = obj, origin = obj.DimensionStyle) def execute(self, obj): diff --git a/src/Mod/Draft/draftobjects/dimensionstyle.py b/src/Mod/Draft/draftobjects/dimensionstyle.py deleted file mode 100644 index daa602c913..0000000000 --- a/src/Mod/Draft/draftobjects/dimensionstyle.py +++ /dev/null @@ -1,123 +0,0 @@ -# *************************************************************************** -# * * -# * This file is part of the FreeCAD CAx development system. * -# * * -# * This program is free software; you can redistribute it and/or modify * -# * it under the terms of the GNU Lesser General Public License (LGPL) * -# * as published by the Free Software Foundation; either version 2 of * -# * the License, or (at your option) any later version. * -# * for detail see the LICENCE text file. * -# * * -# * FreeCAD is distributed in the hope that it will be useful, * -# * but WITHOUT ANY WARRANTY; without even the implied warranty of * -# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -# * GNU Library General Public License for more details. * -# * * -# * You should have received a copy of the GNU Library General Public * -# * License along with FreeCAD; if not, write to the Free Software * -# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -# * USA * -# * * -# *************************************************************************** - -"""This module provides the object code for Draft DimensionStyle. -""" -## @package dimensionstyle -# \ingroup DRAFT -# \brief This module provides the object code for Draft DimensionStyle. - -import FreeCAD as App -from PySide.QtCore import QT_TRANSLATE_NOOP -from draftobjects.draft_annotation import DraftAnnotation -from draftobjects.draft_annotation import StylesContainerBase - -if App.GuiUp: - import FreeCADGui as Gui - from draftviewproviders.view_dimensionstyle import ViewProviderDimensionStyle - from draftviewproviders.view_dimensionstyle import ViewProviderDimensionStylesContainer - -def make_dimension_style(existing_dimension = None): - """ - Make dimension style - """ - if not App.ActiveDocument: - App.Console.PrintError("No active document. Aborting\n") - return - obj = App.ActiveDocument.addObject("App::FeaturePython","DimensionStyle") - DimensionStyle(obj) - if App.GuiUp: - ViewProviderDimensionStyle(obj.ViewObject, existing_dimension) - get_dimension_styles_container().addObject(obj) - return obj - -def get_dimension_styles_container(): - """get_dimension_styles_container(): returns a group object to put dimensions in""" - for obj in App.ActiveDocument.Objects: - if obj.Name == "DimensionStyles": - return obj - obj = App.ActiveDocument.addObject("App::DocumentObjectGroupPython", "DimensionStyles") - obj.Label = QT_TRANSLATE_NOOP("draft", "Dimension Styles") - DimensionStylesContainer(obj) - if App.GuiUp: - ViewProviderDimensionStylesContainer(obj.ViewObject) - return obj - - -class DimensionStylesContainer(StylesContainerBase): - """The Dimension Container""" - - def __init__(self, obj): - super().__init__(obj, tp = "DimensionStyles") - - # init properties - - obj.addProperty("App::PropertyLink","ActiveDimensionStyle", - "Annotation", - QT_TRANSLATE_NOOP("App::Property", - "Active dimension style")) - - # sets properties read only - obj.setEditorMode("Visibility", 1) - obj.setEditorMode("ActiveDimensionStyle", 1) - - - def onChanged(self, obj, prop): - if prop == "Visibility" and hasattr(obj, "Visibility"): - if obj.Visibility == False: - obj.Visibility = True - if hasattr(obj, "ActiveDimensionStyle"): - if obj.ActiveDimensionStyle: - super().make_unique_visible(obj, obj.ActiveDimensionStyle) - - if prop == "ActiveDimensionStyle" and hasattr(obj, "ActiveDimensionStyle"): - super().make_unique_visible(obj, obj.ActiveDimensionStyle) - - -class DimensionStyle(DraftAnnotation): - def __init__(self, obj): - - super().__init__(obj, "DimensionStyle") - - obj.setEditorMode("Visibility", 1) # sets visibility read only - - - def onChanged(self, obj, prop): - """ visibility property controls setting the activeDimensionStyle - so the only visible style is the current one - """ - if prop == "Visibility" and hasattr(obj, "Visibility"): - if obj.Visibility == True: - self.set_current(obj) - elif obj.Visibility == False: - self.remove_from_current(obj) - - def set_visible(self, obj): - obj.Visibility = True - - def set_current(self, obj): - get_dimension_styles_container().ActiveDimensionStyle = obj - - def remove_from_current(self, obj): - if get_dimension_styles_container().ActiveDimensionStyle: - if get_dimension_styles_container().ActiveDimensionStyle.Name == obj.Name: - get_dimension_styles_container().ActiveDimensionStyle = None diff --git a/src/Mod/Draft/draftviewproviders/view_dimensionstyle.py b/src/Mod/Draft/draftviewproviders/view_dimensionstyle.py deleted file mode 100644 index f5026bd7ca..0000000000 --- a/src/Mod/Draft/draftviewproviders/view_dimensionstyle.py +++ /dev/null @@ -1,158 +0,0 @@ -# *************************************************************************** -# * * -# * This file is part of the FreeCAD CAx development system. * -# * * -# * This program is free software; you can redistribute it and/or modify * -# * it under the terms of the GNU Lesser General Public License (LGPL) * -# * as published by the Free Software Foundation; either version 2 of * -# * the License, or (at your option) any later version. * -# * for detail see the LICENCE text file. * -# * * -# * FreeCAD is distributed in the hope that it will be useful, * -# * but WITHOUT ANY WARRANTY; without even the implied warranty of * -# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -# * GNU Library General Public License for more details. * -# * * -# * You should have received a copy of the GNU Library General Public * -# * License along with FreeCAD; if not, write to the Free Software * -# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -# * USA * -# * * -# *************************************************************************** - -"""This module provides the view provider code for Draft DimensionStyle. -""" -## @package dimensionstyle -# \ingroup DRAFT -# \brief This module provides the view provider code for Draft DimensionStyle. - -import FreeCAD as App -from Draft import _ViewProviderDraft -from PySide.QtCore import QT_TRANSLATE_NOOP -import draftutils.gui_utils as gui_utils -import draftutils.utils as utils -from pivy import coin -from draftviewproviders.view_draft_annotation import ViewProviderStylesContainerBase -from draftviewproviders.view_dimension import ViewProviderDimensionBase - - -class ViewProviderDimensionStylesContainer(ViewProviderStylesContainerBase): - """A View Provider for the Dimension Styles Container""" - - def __init__(self, vobj): - super().__init__(vobj) - - def getIcon(self): - - return ":/icons/Draft_Annotation_Style.svg" - - -class ViewProviderDimensionStyle(ViewProviderDimensionBase): - """ - Dimension style dont have a proper object but just a viewprovider. - It stores inside a document object dimension settings and restore them on demand. - """ - def __init__(self, vobj, existing_dimension = None): - super().__init__(vobj) - - vobj.addProperty("App::PropertyBool","AutoUpdate", - "Annotation", - QT_TRANSLATE_NOOP("App::Property", - "Auto update associated dimensions")) - - self.init_properties(vobj, existing_dimension) - - # Visibility is True only if the style is active - vobj.Visibility = False - - def init_properties(self, vobj, existing_dimension): - """ - Initializes Dimension Style properties - """ - # get the style from FreeCAD Draft Parameters - param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft") - annotation_scale = param.GetFloat("DraftAnnotationScale", 1.0) - - vobj.ScaleMultiplier = 1 / annotation_scale - vobj.AutoUpdate = True - - vobj.FontName = utils.get_param("textfont","") - vobj.FontSize = utils.get_param("textheight",0.20) - vobj.TextSpacing = utils.get_param("dimspacing",0.05) - - vobj.Decimals = utils.get_param("dimPrecision",2) - vobj.ShowUnit = utils.get_param("showUnit",True) - - vobj.ArrowSize = utils.get_param("arrowsize",0.1) - vobj.ArrowType = utils.ARROW_TYPES - vobj.ArrowType = utils.ARROW_TYPES[utils.get_param("dimsymbol",0)] - vobj.DimOvershoot = utils.get_param("dimovershoot",0) - vobj.ExtLines = utils.get_param("extlines",0.3) - vobj.ExtOvershoot = utils.get_param("extovershoot",0) - vobj.ShowLine = True - - if existing_dimension and hasattr(existing_dimension, "ViewObject"): - # get the style from given dimension - gui_utils.format_object(target = vobj.Object, origin = existing_dimension) - - def onChanged(self, vobj, prop): - if prop == "Visibility": - return - if hasattr(vobj, "AutoUpdate"): - if vobj.AutoUpdate: - self.update_related_dimensions(vobj) - - def doubleClicked(self,vobj): - self.set_current(vobj) - - def setupContextMenu(self,vobj,menu): - action1 = menu.addAction("Set current") - action1.triggered.connect(lambda f=self.set_current, arg=vobj:f(arg)) - action2 = menu.addAction("Update dimensions") - action2.triggered.connect(lambda f=self.update_related_dimensions, arg=vobj:f(arg)) - - def set_current(self, vobj): - """ - Sets the current dimension style as default for new created dimensions - """ - param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft") - param.SetFloat("DraftAnnotationScale", 1 / vobj.ScaleMultiplier) - - param.SetString("textfont", vobj.FontName) - param.SetFloat("textheight", vobj.FontSize) - param.SetFloat("dimspacing", vobj.TextSpacing) - - param.SetInt("dimPrecision", vobj.Decimals) - - param.SetFloat("arrowsize", vobj.ArrowSize) - param.SetInt("dimsymbol", utils.ARROW_TYPES.index(vobj.ArrowType)) - param.SetFloat("dimovershoot", vobj.DimOvershoot) - param.SetFloat("extlines", vobj.ExtLines) - param.SetFloat("extovershoot", vobj.ExtOvershoot) - - App.Console.PrintMessage("Current dimension style set to " + str(vobj.Object.Label) + "\n") - - vobj.Object.Proxy.set_visible(vobj.Object) - - def update_related_dimensions(self, vobj): - """ - Apply the style to the related dimensions - """ - for dim in vobj.Object.InList: - gui_utils.format_object(target = dim, origin = vobj.Object) - - def getIcon(self): - - return ":/icons/Draft_Dimension_Tree_Style.svg" - - def attach(self, vobj): - self.standard = coin.SoGroup() - vobj.addDisplayMode(self.standard,"Standard") - - def getDisplayModes(self,obj): - "'''Return a list of display modes.'''" - return ["Standard"] - - def getDefaultDisplayMode(self): - "'''Return the name of the default display mode. It must be defined in getDisplayModes.'''" - return "Standard" \ No newline at end of file