[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
@@ -63,6 +63,7 @@ class GuiCommandDimensionStyle(gui_base.GuiCommandSimplest):
|
||||
if len(sel) == 1:
|
||||
if utils.get_type(sel[0]) == 'Dimension':
|
||||
make_dimension_style(sel[0])
|
||||
return
|
||||
|
||||
make_dimension_style()
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -29,25 +29,25 @@
|
||||
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 ViewProviderAnnotationStylesContainer
|
||||
from draftviewproviders.view_draft_annotation import ViewProviderStylesContainerBase
|
||||
from draftviewproviders.view_dimension import ViewProviderDimensionBase
|
||||
|
||||
|
||||
class ViewProviderDimensionStylesContainer(ViewProviderAnnotationStylesContainer):
|
||||
"""A View Provider for the Dimension Style Container"""
|
||||
class ViewProviderDimensionStylesContainer(ViewProviderStylesContainerBase):
|
||||
"""A View Provider for the Dimension Styles Container"""
|
||||
|
||||
def __init__(self, vobj):
|
||||
super().__init__(vobj)
|
||||
vobj.Proxy = self
|
||||
|
||||
def getIcon(self):
|
||||
|
||||
return ":/icons/Draft_Annotation_Style.svg"
|
||||
|
||||
|
||||
class ViewProviderDraftDimensionStyle(ViewProviderDimensionBase):
|
||||
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.
|
||||
@@ -93,10 +93,11 @@ class ViewProviderDraftDimensionStyle(ViewProviderDimensionBase):
|
||||
|
||||
if existing_dimension and hasattr(existing_dimension, "ViewObject"):
|
||||
# get the style from given dimension
|
||||
from draftutils import gui_utils
|
||||
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)
|
||||
@@ -131,18 +132,17 @@ class ViewProviderDraftDimensionStyle(ViewProviderDimensionBase):
|
||||
|
||||
App.Console.PrintMessage("Current dimension style set to " + str(vobj.Object.Label) + "\n")
|
||||
|
||||
vobj.Object.Proxy.set_current(vobj.Object)
|
||||
vobj.Object.Proxy.set_visible(vobj.Object)
|
||||
|
||||
def update_related_dimensions(self, vobj):
|
||||
"""
|
||||
Apply the style to the related dimensions
|
||||
"""
|
||||
from draftutils import gui_utils
|
||||
for dim in vobj.Object.InList:
|
||||
gui_utils.format_object(target = dim, origin = vobj.Object)
|
||||
|
||||
def getIcon(self):
|
||||
import Draft_rc
|
||||
|
||||
return ":/icons/Draft_Dimension_Tree_Style.svg"
|
||||
|
||||
def attach(self, vobj):
|
||||
|
||||
@@ -32,8 +32,8 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
if App.GuiUp:
|
||||
import FreeCADGui as Gui
|
||||
|
||||
class ViewProviderAnnotationStylesContainer:
|
||||
"""A View Provider for the Layer Container"""
|
||||
class ViewProviderStylesContainerBase:
|
||||
"""A Base View Provider for Annotation Styles Containers"""
|
||||
|
||||
def __init__(self, vobj):
|
||||
|
||||
@@ -56,6 +56,20 @@ class ViewProviderAnnotationStylesContainer:
|
||||
return None
|
||||
|
||||
|
||||
class ViewProviderAnnotationStylesContainer(ViewProviderStylesContainerBase):
|
||||
"""A View Provider for the Annotation Styles Container"""
|
||||
|
||||
def __init__(self, vobj):
|
||||
super().__init__(vobj)
|
||||
|
||||
def getIcon(self):
|
||||
|
||||
return ":/icons/Draft_Annotation_Style.svg"
|
||||
|
||||
def attach(self, vobj):
|
||||
|
||||
self.Object = vobj.Object
|
||||
|
||||
|
||||
class ViewProviderDraftAnnotation:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user