[Draft] Cleanup splitted annotatation objects
- corrected super() methods to be Py2 compatible - further cleanup of the code. further cleanup changed again to avoid super method updated super() functions updated to correct the parent classess targeted by super()
This commit is contained in:
committed by
Yorik van Havre
parent
00c0de6871
commit
db9134630a
@@ -22,7 +22,6 @@
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
|
||||
"""This module provides the object code for Draft Dimension.
|
||||
"""
|
||||
## @package dimension
|
||||
@@ -167,9 +166,10 @@ class DimensionBase(DraftAnnotation):
|
||||
"""
|
||||
|
||||
def __init__(self, obj, tp = "Dimension"):
|
||||
"Initialize common properties for dimension objects"
|
||||
DraftAnnotation.__init__(self,obj, tp)
|
||||
"""Add common dimension properties to the object and set them"""
|
||||
|
||||
super(DimensionBase, self).__init__(obj, tp)
|
||||
|
||||
# Draft
|
||||
obj.addProperty("App::PropertyVector",
|
||||
"Normal",
|
||||
@@ -195,17 +195,22 @@ class DimensionBase(DraftAnnotation):
|
||||
QT_TRANSLATE_NOOP("App::Property",
|
||||
"Point on which the dimension \n"
|
||||
"line is placed."))
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
|
||||
return
|
||||
|
||||
obj.Dimline = App.Vector(0,1,0)
|
||||
obj.Normal = App.Vector(0,0,1)
|
||||
|
||||
|
||||
def execute(self, obj):
|
||||
'''Do something when recompute object'''
|
||||
|
||||
return
|
||||
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
'''Do something when a property has changed'''
|
||||
|
||||
return
|
||||
|
||||
|
||||
class LinearDimension(DimensionBase):
|
||||
"""
|
||||
@@ -213,8 +218,17 @@ class LinearDimension(DimensionBase):
|
||||
"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super().__init__(obj, "Dimension")
|
||||
|
||||
|
||||
super(LinearDimension, self).__init__(obj, "LinearDimension")
|
||||
|
||||
obj.Proxy = self
|
||||
|
||||
self.init_properties(obj)
|
||||
|
||||
|
||||
def init_properties(self, obj):
|
||||
"""Add Linear Dimension specific properties to the object and set them"""
|
||||
|
||||
# Draft
|
||||
obj.addProperty("App::PropertyVectorDistance",
|
||||
"Start",
|
||||
@@ -248,10 +262,9 @@ class LinearDimension(DimensionBase):
|
||||
|
||||
obj.Start = App.Vector(0,0,0)
|
||||
obj.End = App.Vector(1,0,0)
|
||||
obj.Dimline = App.Vector(0,1,0)
|
||||
obj.Normal = App.Vector(0,0,1)
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
'''Do something when a property has changed'''
|
||||
if hasattr(obj, "Distance"):
|
||||
obj.setEditorMode('Distance', 1)
|
||||
#if hasattr(obj,"Normal"):
|
||||
@@ -261,7 +274,7 @@ class LinearDimension(DimensionBase):
|
||||
|
||||
|
||||
def execute(self, obj):
|
||||
# set start point and end point according to the linked geometry
|
||||
""" Set start point and end point according to the linked geometry"""
|
||||
if obj.LinkedGeometry:
|
||||
if len(obj.LinkedGeometry) == 1:
|
||||
lobj = obj.LinkedGeometry[0][0]
|
||||
@@ -324,7 +337,15 @@ class AngularDimension(DimensionBase):
|
||||
|
||||
def __init__(self, obj):
|
||||
|
||||
super().__init__(obj,"AngularDimension")
|
||||
super(AngularDimension, self).__init__(obj, "AngularDimension")
|
||||
|
||||
self.init_properties(obj)
|
||||
|
||||
obj.Proxy = self
|
||||
|
||||
|
||||
def init_properties(self, obj):
|
||||
"""Add Angular Dimension specific properties to the object and set them"""
|
||||
|
||||
obj.addProperty("App::PropertyAngle",
|
||||
"FirstAngle",
|
||||
@@ -356,7 +377,15 @@ class AngularDimension(DimensionBase):
|
||||
obj.Center = App.Vector(0,0,0)
|
||||
obj.Normal = App.Vector(0,0,1)
|
||||
|
||||
|
||||
def execute(self, fp):
|
||||
'''Do something when recompute object'''
|
||||
if fp.ViewObject:
|
||||
fp.ViewObject.update()
|
||||
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
'''Do something when a property has changed'''
|
||||
super().onChanged(obj, prop)
|
||||
if hasattr(obj,"Angle"):
|
||||
obj.setEditorMode('Angle',1)
|
||||
@@ -365,6 +394,4 @@ class AngularDimension(DimensionBase):
|
||||
if hasattr(obj,"Support"):
|
||||
obj.setEditorMode('Support',2)
|
||||
|
||||
def execute(self, fp):
|
||||
if fp.ViewObject:
|
||||
fp.ViewObject.update()
|
||||
|
||||
|
||||
@@ -31,57 +31,34 @@ import FreeCAD as App
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
from draftutils import gui_utils
|
||||
|
||||
class DraftAnnotation:
|
||||
class DraftAnnotation(object):
|
||||
"""The Draft Annotation Base object
|
||||
This class is not used directly, but inherited by all annotation
|
||||
objects.
|
||||
"""
|
||||
def __init__(self, obj, tp="Unknown"):
|
||||
if obj:
|
||||
obj.Proxy = self
|
||||
def __init__(self, obj, tp="Annotation"):
|
||||
"""Add general Annotation properties to the object"""
|
||||
|
||||
self.Type = tp
|
||||
|
||||
|
||||
def __getstate__(self):
|
||||
return self.Type
|
||||
|
||||
|
||||
def __setstate__(self,state):
|
||||
if state:
|
||||
self.Type = state
|
||||
|
||||
|
||||
def execute(self,obj):
|
||||
pass
|
||||
'''Do something when recompute object'''
|
||||
|
||||
return
|
||||
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
pass
|
||||
|
||||
class StylesContainerBase:
|
||||
"""The Base class for Annotation Containers"""
|
||||
|
||||
def __init__(self, obj, tp = "AnnotationContainer"):
|
||||
|
||||
self.Type = tp
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, obj):
|
||||
|
||||
g = obj.Group
|
||||
g.sort(key=lambda o: o.Label)
|
||||
obj.Group = g
|
||||
|
||||
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
|
||||
|
||||
|
||||
class AnnotationStylesContainer(StylesContainerBase):
|
||||
"""The Annotation Container"""
|
||||
|
||||
def __init__(self, obj):
|
||||
|
||||
self.Type = "AnnotationContainer"
|
||||
obj.Proxy = self
|
||||
'''Do something when a property has changed'''
|
||||
|
||||
return
|
||||
|
||||
|
||||
@@ -106,9 +106,17 @@ def make_label(targetpoint=None, target=None, direction=None,
|
||||
class Label(DraftAnnotation):
|
||||
"""The Draft Label object"""
|
||||
|
||||
def __init__(self,obj):
|
||||
def __init__(self, obj):
|
||||
|
||||
super().__init__(obj, "Label")
|
||||
super(Label, self).__init__(obj, "Label")
|
||||
|
||||
self.init_properties(obj)
|
||||
|
||||
obj.Proxy = self
|
||||
|
||||
|
||||
def init_properties(self, obj):
|
||||
"""Add properties to the object and set them"""
|
||||
|
||||
obj.addProperty("App::PropertyPlacement",
|
||||
"Placement",
|
||||
@@ -174,6 +182,7 @@ class Label(DraftAnnotation):
|
||||
|
||||
|
||||
def execute(self,obj):
|
||||
'''Do something when recompute object'''
|
||||
|
||||
if obj.StraightDirection != "Custom":
|
||||
p1 = obj.Placement.Base
|
||||
@@ -223,12 +232,8 @@ class Label(DraftAnnotation):
|
||||
if hasattr(obj.Target[0].Shape,"Volume"):
|
||||
obj.Text = [App.Units.Quantity(obj.Target[0].Shape.Volume,App.Units.Volume).UserString.replace("^3","³")]
|
||||
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
pass
|
||||
'''Do something when a property has changed'''
|
||||
|
||||
def __getstate__(self):
|
||||
return self.Type
|
||||
|
||||
def __setstate__(self,state):
|
||||
if state:
|
||||
self.Type = state
|
||||
return
|
||||
@@ -42,7 +42,7 @@ if App.GuiUp:
|
||||
|
||||
|
||||
def make_text(stringslist, point=App.Vector(0,0,0), screen=False):
|
||||
"""makeText(strings,[point],[screen])
|
||||
"""makeText(strings, point, screen)
|
||||
|
||||
Creates a Text object containing the given strings.
|
||||
The current color and text height and font
|
||||
@@ -51,22 +51,24 @@ def make_text(stringslist, point=App.Vector(0,0,0), screen=False):
|
||||
Parameters
|
||||
----------
|
||||
stringlist : List
|
||||
Given list of strings, one string by line (strings can also
|
||||
be one single string)
|
||||
Given list of strings, one string by line (strings can also
|
||||
be one single string)
|
||||
|
||||
point : App::Vector
|
||||
|
||||
insert point of the text
|
||||
|
||||
screen : Bool
|
||||
If screen is True, the text always faces the view direction.
|
||||
If screen is True, the text always faces the view direction.
|
||||
|
||||
"""
|
||||
|
||||
if not App.ActiveDocument:
|
||||
App.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
|
||||
utils.type_check([(point, App.Vector)], "makeText")
|
||||
if not isinstance(stringslist,list): stringslist = [stringslist]
|
||||
|
||||
obj = App.ActiveDocument.addObject("App::FeaturePython","Text")
|
||||
Text(obj)
|
||||
obj.Text = stringslist
|
||||
@@ -92,9 +94,17 @@ def make_text(stringslist, point=App.Vector(0,0,0), screen=False):
|
||||
class Text(DraftAnnotation):
|
||||
"""The Draft Text object"""
|
||||
|
||||
def __init__(self,obj):
|
||||
def __init__(self, obj):
|
||||
|
||||
super().__init__(obj, "Text")
|
||||
super(Text, self).__init__(obj, "Text")
|
||||
|
||||
self.init_properties(obj)
|
||||
|
||||
obj.Proxy = self
|
||||
|
||||
|
||||
def init_properties(self, obj):
|
||||
"""Add Text specific properties to the object and set them"""
|
||||
|
||||
obj.addProperty("App::PropertyPlacement",
|
||||
"Placement",
|
||||
@@ -108,6 +118,14 @@ class Text(DraftAnnotation):
|
||||
QT_TRANSLATE_NOOP("App::Property",
|
||||
"The text displayed by this object"))
|
||||
|
||||
def execute(self,obj):
|
||||
|
||||
pass
|
||||
def execute(self,obj):
|
||||
'''Do something when recompute object'''
|
||||
|
||||
return
|
||||
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
'''Do something when a property has changed'''
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user