[Feature Request] [Draft] [UI/UX] Allow to turn dimension arrows on/off individually (#11941)

* Update additional files

* The LineColor and LineWidth properties are removed from Text objects.
* Arrow properties are added by the ViewProviderDraftAnnotation class only. This avoids code duplication.

* gui_annotationstyleeditor.py fix except

* view_draft_annotation.py fix except

---------

Co-authored-by: Roy-043 <info@b-k-g.nl>
Co-authored-by: Roy-043 <70520633+Roy-043@users.noreply.github.com>
This commit is contained in:
Vincenzo Calligaro
2025-08-14 10:44:49 +02:00
committed by GitHub
parent 0eb155ebc9
commit 439cb2122e
20 changed files with 838 additions and 364 deletions

View File

@@ -307,12 +307,12 @@ class LinearDimension(DimensionBase):
obj, vp_module="view_dimension", vp_class="ViewProviderLinearDimension"
)
if not getattr(obj, "ViewObject", None):
vobj = getattr(obj, "ViewObject", None)
if vobj is None:
return
vobj = obj.ViewObject
if hasattr(vobj, "TextColor"):
return
super().update_properties_0v21(obj, vobj)
if not hasattr(vobj, "TextColor"):
self.update_properties_0v21(obj, vobj)
def loads(self, state):
self.Type = "LinearDimension"
@@ -586,12 +586,12 @@ class AngularDimension(DimensionBase):
obj, vp_module="view_dimension", vp_class="ViewProviderAngularDimension"
)
if not getattr(obj, "ViewObject", None):
vobj = getattr(obj, "ViewObject", None)
if vobj is None:
return
vobj = obj.ViewObject
if hasattr(vobj, "TextColor"):
return
super().update_properties_0v21(obj, vobj)
if not hasattr(vobj, "TextColor"):
self.update_properties_0v21(obj, vobj)
def loads(self, state):
self.Type = "AngularDimension"

View File

@@ -59,16 +59,19 @@ class DraftAnnotation(object):
Check if new properties are present after the object is restored
in order to migrate older objects.
"""
if not getattr(obj, "ViewObject", None):
vobj = getattr(obj, "ViewObject", None)
if vobj is None:
return
vobj = obj.ViewObject
if not getattr(vobj, "Proxy", None):
# Object was saved without GUI.
# onDocumentRestored in the object class should restore the ViewObject.
return
if hasattr(vobj, "ScaleMultiplier") and hasattr(vobj, "AnnotationStyle"):
return
self.add_missing_properties_0v19(obj, vobj)
if not hasattr(vobj, "ScaleMultiplier") or not hasattr(vobj, "AnnotationStyle"):
self.add_missing_properties_0v19(obj, vobj)
if hasattr(vobj, "ArrowType") or hasattr(vobj, "ArrowSize"):
self.update_properties_1v1(obj, vobj)
def add_missing_properties_0v19(self, obj, vobj):
"""Provide missing annotation properties."""
@@ -84,6 +87,38 @@ class DraftAnnotation(object):
if multiplier is not None:
vobj.ScaleMultiplier = multiplier
def update_properties_1v1(self, obj, vobj):
"""Update view properties."""
vobj.Proxy.set_graphics_properties(vobj, vobj.PropertiesList)
if hasattr(vobj, "ArrowType"):
typ = obj.Proxy.Type
if typ == "Label":
vobj.ArrowTypeStart = vobj.ArrowType
elif typ == "AngularDimension" \
or obj.Diameter \
or not vobj.Proxy.is_linked_to_circle():
vobj.ArrowTypeStart = vobj.ArrowType
vobj.ArrowTypeEnd = vobj.ArrowType
else: # Radial dimension
vobj.ArrowTypeStart = "None"
vobj.ArrowTypeEnd = vobj.ArrowType
vobj.setPropertyStatus("ArrowType", "-LockDynamic")
vobj.removeProperty("ArrowType")
if hasattr(vobj, "ArrowSize"):
vobj.ArrowSizeStart = vobj.ArrowSize
if hasattr(vobj, "ArrowSizeEnd"):
# Label objects do not have this property
vobj.ArrowSizeEnd = vobj.ArrowSize
vobj.setPropertyStatus("ArrowSize", "-LockDynamic")
vobj.removeProperty("ArrowSize")
_wrn(
"v1.1, "
+ obj.Label
+ ", "
+ translate("draft", "migrated view properties")
)
def dumps(self):
return

View File

@@ -235,12 +235,12 @@ class Label(DraftAnnotation):
super().onDocumentRestored(obj)
gui_utils.restore_view_object(obj, vp_module="view_label", vp_class="ViewProviderLabel")
if not getattr(obj, "ViewObject", None):
vobj = getattr(obj, "ViewObject", None)
if vobj is None:
return
vobj = obj.ViewObject
if hasattr(vobj, "FontName") and hasattr(vobj, "FontSize"):
return
self.update_properties_0v21(obj, vobj)
if not hasattr(vobj, "FontName") or not hasattr(vobj, "FontSize"):
self.update_properties_0v21(obj, vobj)
def loads(self, state):
self.Type = "Label"

View File

@@ -77,12 +77,17 @@ class Text(DraftAnnotation):
"""Execute code when the document is restored."""
super().onDocumentRestored(obj)
gui_utils.restore_view_object(obj, vp_module="view_text", vp_class="ViewProviderText")
vobj = getattr(obj, "ViewObject", None)
if vobj is None:
return
# See loads:
if self.stored_type is None:
return
if not getattr(obj, "ViewObject", None):
return
self.update_properties_0v21(obj, obj.ViewObject)
if self.stored_type is not None:
self.update_properties_0v21(obj, vobj)
if hasattr(vobj, "LineWidth") or hasattr(vobj, "LineColor"):
self.update_properties_1v1(obj, vobj)
def update_properties_0v21(self, obj, vobj):
"""Update view properties."""
@@ -93,6 +98,20 @@ class Text(DraftAnnotation):
_wrn("v0.21, " + obj.Label + ", "
+ translate("draft", "renamed 'DisplayMode' options to 'World/Screen'"))
def update_properties_1v1(self, obj, vobj):
if hasattr(vobj, "LineWidth"):
vobj.setPropertyStatus("LineWidth", "-LockDynamic")
vobj.removeProperty("LineWidth")
if hasattr(vobj, "LineColor"):
vobj.setPropertyStatus("LineColor", "-LockDynamic")
vobj.removeProperty("LineColor")
_wrn(
"v1.1, "
+ obj.Label
+ ", "
+ translate("draft", "removed view properties")
)
def loads(self, state):
# Before update_properties_0v21 the self.Type value was stored.
# We use this to identify older objects that need to be updated.

View File

@@ -36,6 +36,8 @@ import DraftVecUtils
from draftobjects.base import DraftObject
from draftutils import gui_utils
from draftutils import params
from draftutils.messages import _wrn
from draftutils.translate import translate
class Wire(DraftObject):
@@ -99,6 +101,36 @@ class Wire(DraftObject):
super().onDocumentRestored(obj)
gui_utils.restore_view_object(obj, vp_module="view_wire", vp_class="ViewProviderWire")
vobj = getattr(obj, "ViewObject", None)
if vobj is None:
return
if hasattr(vobj, "ArrowSize") or hasattr(vobj, "ArrowType") or hasattr(vobj, "EndArrow"):
self.update_properties_1v1(obj, vobj)
def update_properties_1v1(self, obj, vobj):
"""Update view properties."""
vobj.Proxy._set_properties(vobj)
if getattr(vobj, "EndArrow", False) and hasattr(vobj, "ArrowType"):
vobj.ArrowTypeEnd = vobj.ArrowType
if hasattr(vobj, "ArrowSize"):
vobj.ArrowSizeStart = vobj.ArrowSize
vobj.ArrowSizeEnd = vobj.ArrowSize
vobj.setPropertyStatus("ArrowSize", "-LockDynamic")
vobj.removeProperty("ArrowSize")
if hasattr(vobj, "ArrowType"):
vobj.setPropertyStatus("ArrowType", "-LockDynamic")
vobj.removeProperty("ArrowType")
if hasattr(vobj, "EndArrow"):
vobj.setPropertyStatus("EndArrow", "-LockDynamic")
vobj.removeProperty("EndArrow")
_wrn(
"v1.1, "
+ obj.Label
+ ", "
+ translate("draft", "migrated view properties")
)
def execute(self, obj):
if self.props_changed_placement_only(obj): # Supplying obj is required because of `Base` and `Tool`.
obj.positionBySupport()