Draft: update ViewProviderWire properties

The improvements are done to `ViewProviderWire` which propagates
to many objects like Line, Wire (polyline), BSpline, BezCurve,
Fillet, etc.

The initialization of the properties is moved to a method
`_set_properties`. The properties `EndArrow`, `ArrowSize`,
`ArrowType` are created only if they do not exist.

This allows calling `ViewProviderWire(obj.ViewObject)`
to migrate an older object to this viewprovider
but without adding duplicated properties.

In particular, this is done to support the migration of the older
`Fillet` object.
This commit is contained in:
vocx-fc
2020-05-06 00:58:01 -05:00
committed by Yorik van Havre
parent 87f9c45cae
commit 31792151c7

View File

@@ -20,18 +20,18 @@
# * USA *
# * *
# ***************************************************************************
"""This module provides the view provider code for Draft wire related objects.
"""Provides the viewprovider code for polyline and similar objects.
This viewprovider is also used by simple lines, B-splines, bezier curves,
and similar objects.
"""
## @package view_base
# \ingroup DRAFT
# \brief This module provides the view provider code for Draft objects like\
# Line, Polyline, BSpline, BezCurve.
from pivy import coin
from PySide import QtCore
from PySide import QtGui
# \brief Provides the viewprovider code for polyline and similar objects.
import pivy.coin as coin
import PySide.QtCore as QtCore
import PySide.QtGui as QtGui
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD as App
@@ -41,30 +41,46 @@ import draftutils.utils as utils
import draftutils.gui_utils as gui_utils
import DraftVecUtils
import DraftGeomUtils
from draftutils.messages import _msg
from draftviewproviders.view_base import ViewProviderDraft
class ViewProviderWire(ViewProviderDraft):
"""A base View Provider for the Wire object"""
"""A base View Provider for the Wire object."""
def __init__(self, vobj):
super(ViewProviderWire, self).__init__(vobj)
self._set_properties(vobj)
_tip = "Displays a Dimension symbol at the end of the wire"
vobj.addProperty("App::PropertyBool", "EndArrow",
"Draft", QT_TRANSLATE_NOOP("App::Property", _tip))
def _set_properties(self, vobj):
"""Set the properties of objects if they don't exist."""
super(ViewProviderWire, self)._set_properties(vobj)
_tip = "Arrow size"
vobj.addProperty("App::PropertyLength", "ArrowSize",
"Draft", QT_TRANSLATE_NOOP("App::Property", _tip))
if not hasattr(vobj, "EndArrow"):
_tip = "Displays a Dimension symbol at the end of the wire."
vobj.addProperty("App::PropertyBool",
"EndArrow",
"Draft",
QT_TRANSLATE_NOOP("App::Property", _tip))
vobj.EndArrow = False
_tip = "Arrow type"
vobj.addProperty("App::PropertyEnumeration", "ArrowType",
"Draft", QT_TRANSLATE_NOOP("App::Property", _tip))
if not hasattr(vobj, "ArrowSize"):
_tip = "Arrow size"
vobj.addProperty("App::PropertyLength",
"ArrowSize",
"Draft",
QT_TRANSLATE_NOOP("App::Property", _tip))
vobj.ArrowSize = utils.get_param("arrowsize", 0.1)
vobj.ArrowSize = utils.get_param("arrowsize",0.1)
vobj.ArrowType = utils.ARROW_TYPES
vobj.ArrowType = utils.ARROW_TYPES[utils.get_param("dimsymbol",0)]
if not hasattr(vobj, "ArrowType"):
_tip = "Arrow type"
vobj.addProperty("App::PropertyEnumeration",
"ArrowType",
"Draft",
QT_TRANSLATE_NOOP("App::Property", _tip))
vobj.ArrowType = utils.ARROW_TYPES
vobj.ArrowType = utils.ARROW_TYPES[utils.get_param("dimsymbol", 0)]
def attach(self, vobj):
self.Object = vobj.Object
@@ -153,8 +169,8 @@ class ViewProviderWire(ViewProviderDraft):
App.ActiveDocument.commitTransaction()
else:
_msg = "This Wire is already flat"
App.Console.PrintMessage(QT_TRANSLATE_NOOP("Draft", _msg) + "\n")
_flat = "This Wire is already flat"
_msg(QT_TRANSLATE_NOOP("Draft", _flat))
_ViewProviderWire = ViewProviderWire
_ViewProviderWire = ViewProviderWire