[Draft] Dimension styles improvements
Dimension style property is auto-set on dimension creation. Further improvementes in DimensionStyleContainer. .
This commit is contained in:
committed by
Yorik van Havre
parent
a4f7bc43f6
commit
78f740807c
@@ -112,8 +112,17 @@ def make_dimension(p1,p2,p3=None,p4=None):
|
||||
if vnorm.getAngle(normal) < math.pi/2:
|
||||
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:
|
||||
gui_utils.format_object(obj)
|
||||
if not _style_applied:
|
||||
gui_utils.format_object(obj)
|
||||
gui_utils.select(obj)
|
||||
|
||||
return obj
|
||||
@@ -129,6 +138,8 @@ def make_angular_dimension(center,angles,p3,normal=None):
|
||||
return
|
||||
obj = App.ActiveDocument.addObject("App::FeaturePython","Dimension")
|
||||
AngularDimension(obj)
|
||||
if App.GuiUp:
|
||||
ViewProviderAngularDimension(obj.ViewObject)
|
||||
obj.Center = center
|
||||
for a in range(len(angles)):
|
||||
if angles[a] > 2*math.pi:
|
||||
@@ -146,10 +157,20 @@ def make_angular_dimension(center,angles,p3,normal=None):
|
||||
vnorm = gui_utils.get3DView().getViewDirection()
|
||||
if vnorm.getAngle(normal) < math.pi/2:
|
||||
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:
|
||||
ViewProviderAngularDimension(obj.ViewObject)
|
||||
gui_utils.format_object(obj)
|
||||
if not _style_applied:
|
||||
gui_utils.format_object(obj)
|
||||
gui_utils.select(obj)
|
||||
|
||||
return obj
|
||||
@@ -365,6 +386,7 @@ class AngularDimension(DimensionBase):
|
||||
obj.Normal = App.Vector(0,0,1)
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
super().onChanged(obj, prop)
|
||||
if hasattr(obj,"Angle"):
|
||||
obj.setEditorMode('Angle',1)
|
||||
if hasattr(obj,"Normal"):
|
||||
|
||||
@@ -27,13 +27,13 @@
|
||||
# \brief This module provides the object code for Draft DimensionStyle.
|
||||
|
||||
import FreeCAD as App
|
||||
from draftobjects.draft_annotation import DraftAnnotation
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
from draftobjects.draft_annotation import AnnotationStylesContainer
|
||||
from draftobjects.draft_annotation import DraftAnnotation
|
||||
from draftobjects.draft_annotation import StylesContainerBase
|
||||
|
||||
if App.GuiUp:
|
||||
import FreeCADGui as Gui
|
||||
from draftviewproviders.view_dimensionstyle import ViewProviderDraftDimensionStyle
|
||||
from draftviewproviders.view_dimensionstyle import ViewProviderDimensionStyle
|
||||
from draftviewproviders.view_dimensionstyle import ViewProviderDimensionStylesContainer
|
||||
|
||||
def make_dimension_style(existing_dimension = None):
|
||||
@@ -46,16 +46,16 @@ def make_dimension_style(existing_dimension = None):
|
||||
obj = App.ActiveDocument.addObject("App::FeaturePython","DimensionStyle")
|
||||
DimensionStyle(obj)
|
||||
if App.GuiUp:
|
||||
ViewProviderDraftDimensionStyle(obj.ViewObject, existing_dimension)
|
||||
get_dimension_style_container().addObject(obj)
|
||||
ViewProviderDimensionStyle(obj.ViewObject, existing_dimension)
|
||||
get_dimension_styles_container().addObject(obj)
|
||||
return obj
|
||||
|
||||
def get_dimension_style_container():
|
||||
"""get_dimension_style_container(): returns a group object to put dimensions in"""
|
||||
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 == "DimensionStyleContainer":
|
||||
if obj.Name == "DimensionStyles":
|
||||
return obj
|
||||
obj = App.ActiveDocument.addObject("App::DocumentObjectGroupPython", "DimensionStyleContainer")
|
||||
obj = App.ActiveDocument.addObject("App::DocumentObjectGroupPython", "DimensionStyles")
|
||||
obj.Label = QT_TRANSLATE_NOOP("draft", "Dimension Styles")
|
||||
DimensionStylesContainer(obj)
|
||||
if App.GuiUp:
|
||||
@@ -63,29 +63,61 @@ def get_dimension_style_container():
|
||||
return obj
|
||||
|
||||
|
||||
class DimensionStylesContainer(AnnotationStylesContainer):
|
||||
class DimensionStylesContainer(StylesContainerBase):
|
||||
"""The Dimension Container"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super().__init__(obj)
|
||||
self.Type = "DimensionStyleContainer"
|
||||
obj.Proxy = self
|
||||
super().__init__(obj, tp = "DimensionStyles")
|
||||
|
||||
def execute(self, obj):
|
||||
# init properties
|
||||
|
||||
g = obj.Group
|
||||
g.sort(key=lambda o: o.Label)
|
||||
obj.Group = g
|
||||
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):
|
||||
"turn non visible all the concurrent styles"
|
||||
for o in get_dimension_style_container().Group:
|
||||
if hasattr(o, "Visibility"):
|
||||
o.Visibility = False
|
||||
if hasattr(obj, "Visibility"):
|
||||
obj.Visibility = True
|
||||
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
|
||||
|
||||
@@ -54,12 +54,12 @@ class DraftAnnotation:
|
||||
def onChanged(self, obj, prop):
|
||||
pass
|
||||
|
||||
class AnnotationStylesContainer:
|
||||
"""The Annotation Container"""
|
||||
class StylesContainerBase:
|
||||
"""The Base class for Annotation Containers"""
|
||||
|
||||
def __init__(self, obj):
|
||||
def __init__(self, obj, tp = "AnnotationContainer"):
|
||||
|
||||
self.Type = "AnnotationContainer"
|
||||
self.Type = tp
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, obj):
|
||||
@@ -68,12 +68,20 @@ class AnnotationStylesContainer:
|
||||
g.sort(key=lambda o: o.Label)
|
||||
obj.Group = g
|
||||
|
||||
def __getstate__(self):
|
||||
def make_unique_visible(self, obj, active_style):
|
||||
"turn non visible all the concurrent styles"
|
||||
if hasattr(active_style, "Visibility"):
|
||||
for o in obj.Group:
|
||||
if o.Name != active_style.Name:
|
||||
if hasattr(o, "Visibility"):
|
||||
o.Visibility = False
|
||||
|
||||
if hasattr(self, "Type"):
|
||||
return self.Type
|
||||
|
||||
def __setstate__(self, state):
|
||||
class AnnotationStylesContainer(StylesContainerBase):
|
||||
"""The Annotation Container"""
|
||||
|
||||
def __init__(self, obj):
|
||||
|
||||
self.Type = "AnnotationContainer"
|
||||
obj.Proxy = self
|
||||
|
||||
if state:
|
||||
self.Type = state
|
||||
Reference in New Issue
Block a user