Skip to content

Commit

Permalink
[Draft] Dimension style object
Browse files Browse the repository at this point in the history
still have to split viewprovider from object.
[Draft] Dimension Style code cleanup

thx @vocx-fc for reviewing
further cleanup


[Draft] Dimension Style improvements

Added a property to the dimension object to link the dimension style.
Improved the update of dimensions when style changes. This can be done in 2 different ways: by setting AutoUpdate property to True or by activating Update function from the viewprovider context menu.
  • Loading branch information
carlopav authored and yorikvanhavre committed Apr 16, 2020
1 parent 0e097ae commit 34cf981
Show file tree
Hide file tree
Showing 5 changed files with 416 additions and 14 deletions.
77 changes: 63 additions & 14 deletions src/Mod/Draft/Draft.py
Expand Up @@ -3372,27 +3372,75 @@ class _Dimension(_DraftObject):
"""The Draft Dimension object"""
def __init__(self, obj):
_DraftObject.__init__(self,obj,"Dimension")
obj.addProperty("App::PropertyVectorDistance","Start","Draft",QT_TRANSLATE_NOOP("App::Property","Startpoint of dimension"))
obj.addProperty("App::PropertyVectorDistance","End","Draft",QT_TRANSLATE_NOOP("App::Property","Endpoint of dimension"))
obj.addProperty("App::PropertyVector","Normal","Draft",QT_TRANSLATE_NOOP("App::Property","The normal direction of this dimension"))
obj.addProperty("App::PropertyVector","Direction","Draft",QT_TRANSLATE_NOOP("App::Property","The normal direction of this dimension"))
obj.addProperty("App::PropertyVectorDistance","Dimline","Draft",QT_TRANSLATE_NOOP("App::Property","Point through which the dimension line passes"))
obj.addProperty("App::PropertyLink","Support","Draft",QT_TRANSLATE_NOOP("App::Property","The object measured by this dimension"))
obj.addProperty("App::PropertyLinkSubList","LinkedGeometry","Draft",QT_TRANSLATE_NOOP("App::Property","The geometry this dimension is linked to"))
obj.addProperty("App::PropertyLength","Distance","Draft",QT_TRANSLATE_NOOP("App::Property","The measurement of this dimension"))
obj.addProperty("App::PropertyBool","Diameter","Draft",QT_TRANSLATE_NOOP("App::Property","For arc/circle measurements, false = radius, true = diameter"))

# Annotation
obj.addProperty("App::PropertyLink","DimensionStyle",
"Annotation",
QT_TRANSLATE_NOOP("App::Property",
"Link dimension style"))

# Draft
obj.addProperty("App::PropertyVectorDistance","Start",
"Draft",
QT_TRANSLATE_NOOP("App::Property",
"Startpoint of dimension"))

obj.addProperty("App::PropertyVectorDistance","End",
"Draft",
QT_TRANSLATE_NOOP("App::Property",
"Endpoint of dimension"))

obj.addProperty("App::PropertyVector","Normal",
"Draft",
QT_TRANSLATE_NOOP("App::Property",
"The normal direction of this dimension"))

obj.addProperty("App::PropertyVector","Direction",
"Draft",
QT_TRANSLATE_NOOP("App::Property",
"The normal direction of this dimension"))

obj.addProperty("App::PropertyVectorDistance","Dimline",
"Draft",
QT_TRANSLATE_NOOP("App::Property",
"Point through which the dimension line passes"))

obj.addProperty("App::PropertyLink","Support",
"Draft",
QT_TRANSLATE_NOOP("App::Property",
"The object measured by this dimension"))

obj.addProperty("App::PropertyLinkSubList","LinkedGeometry",
"Draft",
QT_TRANSLATE_NOOP("App::Property",
"The geometry this dimension is linked to"))

obj.addProperty("App::PropertyLength","Distance",
"Draft",
QT_TRANSLATE_NOOP("App::Property",
"The measurement of this dimension"))

obj.addProperty("App::PropertyBool","Diameter",
"Draft",
QT_TRANSLATE_NOOP("App::Property",
"For arc/circle measurements, false = radius, true = diameter"))
obj.Start = FreeCAD.Vector(0,0,0)
obj.End = FreeCAD.Vector(1,0,0)
obj.Dimline = FreeCAD.Vector(0,1,0)
obj.Normal = FreeCAD.Vector(0,0,1)

def onChanged(self,obj,prop):
if hasattr(obj,"Distance"):
obj.setEditorMode('Distance',1)
if hasattr(obj, "Distance"):
obj.setEditorMode('Distance', 1)
#if hasattr(obj,"Normal"):
# obj.setEditorMode('Normal',2)
if hasattr(obj,"Support"):
obj.setEditorMode('Support',2)
# obj.setEditorMode('Normal', 2)
if hasattr(obj, "Support"):
obj.setEditorMode('Support', 2)
if prop == "DimensionStyle":
if hasattr(obj, "DimensionStyle"):
from draftutils import gui_utils
gui_utils.format_object(target = obj, origin = obj.DimensionStyle)


def execute(self, obj):
import DraftGeomUtils
Expand Down Expand Up @@ -3503,6 +3551,7 @@ def __init__(self, obj):
obj.addProperty("App::PropertyFloat","ScaleMultiplier",
"Annotation",QT_TRANSLATE_NOOP("App::Property",
"Dimension size overall multiplier"))

# text properties
obj.addProperty("App::PropertyFont","FontName",
"Text",QT_TRANSLATE_NOOP("App::Property","Font name"))
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Draft/InitGui.py
Expand Up @@ -86,6 +86,7 @@ def QT_TRANSLATE_NOOP(context, text):
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:
Expand Down
68 changes: 68 additions & 0 deletions src/Mod/Draft/draftguitools/gui_style_dimension.py
@@ -0,0 +1,68 @@
# ***************************************************************************
# * (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.style_dimension import make_dimension_style

class GuiCommandDimensionStyle(gui_base.GuiCommandBase):
"""
The command creates a dimension style object
"""

def GetResources(self):
_msg = ("Creates a new dimension style.\n"
"The object stores dimension preferences into the document."
)
return {'Pixmap' : 'Draft_AutoGroup',
'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 self.finish()

make_dimension_style()
return self.finish()


Gui.addCommand('Draft_DimensionStyle', GuiCommandDimensionStyle())
54 changes: 54 additions & 0 deletions src/Mod/Draft/draftobjects/style_dimension.py
@@ -0,0 +1,54 @@
# ***************************************************************************
# * (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 object code for Draft DimensionStyle.
"""
## @package style_dimension
# \ingroup DRAFT
# \brief This module provides the object code for Draft DimensionStyle.

import FreeCAD as App
import Draft
from Draft import _DraftObject
from PySide.QtCore import QT_TRANSLATE_NOOP

if App.GuiUp:
import FreeCADGui as Gui
from draftviewproviders.view_style_dimension import ViewProviderDraftDimensionStyle

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:
ViewProviderDraftDimensionStyle(obj.ViewObject, existing_dimension)
return obj

class DimensionStyle(_DraftObject):
def __init__(self, obj):
_DraftObject.__init__(self, obj, "DimensionStyle")

0 comments on commit 34cf981

Please sign in to comment.