Merge pull request #10783 from Roy-043/Draft-ShapeString-add-ObliqueAngle-property
Draft: ShapeString: add ObliqueAngle property
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
|
||||
## \addtogroup draftobjects
|
||||
# @{
|
||||
import math
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
@@ -88,6 +89,10 @@ class ShapeString(DraftObject):
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property", "Inter-character spacing")
|
||||
obj.addProperty("App::PropertyDistance", "Tracking", "Draft", _tip)
|
||||
|
||||
if "ObliqueAngle" not in properties:
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property", "Oblique (slant) angle")
|
||||
obj.addProperty("App::PropertyAngle", "ObliqueAngle", "Draft", _tip)
|
||||
|
||||
if "MakeFace" not in properties:
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property", "Fill letters with faces")
|
||||
obj.addProperty("App::PropertyBool", "MakeFace", "Draft", _tip).MakeFace = True
|
||||
@@ -98,7 +103,7 @@ class ShapeString(DraftObject):
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
if hasattr(obj, "Justification"): # several more properties were added
|
||||
if hasattr(obj, "ObliqueAngle"): # several more properties were added
|
||||
return
|
||||
self.update_properties_0v22(obj)
|
||||
|
||||
@@ -111,7 +116,7 @@ class ShapeString(DraftObject):
|
||||
obj.ScaleToSize = False
|
||||
obj.Tracking = old_tracking
|
||||
_wrn("v0.22, " + obj.Label + ", "
|
||||
+ translate("draft", "added 'Justification', 'JustificationReference', 'KeepLeftMargin', 'ScaleToSize' and 'Fuse' properties"))
|
||||
+ translate("draft", "added 'Fuse', 'Justification', 'JustificationReference', 'KeepLeftMargin', 'ObliqueAngle' and 'ScaleToSize' properties"))
|
||||
_wrn("v0.22, " + obj.Label + ", "
|
||||
+ translate("draft", "changed 'Tracking' property type"))
|
||||
|
||||
@@ -159,11 +164,23 @@ class ShapeString(DraftObject):
|
||||
if obj.ScaleToSize:
|
||||
ss_shape.scale(obj.Size / cap_height)
|
||||
cap_height = obj.Size
|
||||
obj.Shape = self.justification(ss_shape,
|
||||
cap_height,
|
||||
obj.Justification,
|
||||
obj.JustificationReference,
|
||||
obj.KeepLeftMargin)
|
||||
just_vec = self.justification_vector(ss_shape,
|
||||
cap_height,
|
||||
obj.Justification,
|
||||
obj.JustificationReference,
|
||||
obj.KeepLeftMargin)
|
||||
if obj.ObliqueAngle:
|
||||
if -80 <= obj.ObliqueAngle <= 80:
|
||||
mtx = App.Matrix()
|
||||
mtx.A12 = math.tan(math.radians(obj.ObliqueAngle))
|
||||
ss_shape = ss_shape.transformGeometry(mtx)
|
||||
else:
|
||||
wrn = translate("draft", "ShapeString: oblique angle must be in the -80 to +80 degree range") + "\n"
|
||||
App.Console.PrintWarning(wrn)
|
||||
shapes = ss_shape.SubShapes
|
||||
for shape in shapes:
|
||||
shape.translate(just_vec)
|
||||
obj.Shape = Part.Compound(shapes)
|
||||
else:
|
||||
App.Console.PrintWarning(translate("draft", "ShapeString: string has no wires") + "\n")
|
||||
|
||||
@@ -176,10 +193,9 @@ class ShapeString(DraftObject):
|
||||
def onChanged(self, obj, prop):
|
||||
self.props_changed_store(prop)
|
||||
|
||||
def justification(self, ss_shape, cap_height, just, just_ref, keep_left_margin): # ss_shape is a compound
|
||||
shapes = ss_shape.SubShapes
|
||||
def justification_vector(self, ss_shape, cap_height, just, just_ref, keep_left_margin): # ss_shape is a compound
|
||||
box = ss_shape.BoundBox
|
||||
if keep_left_margin is True:
|
||||
if keep_left_margin is True and "Left" in just:
|
||||
vec = App.Vector(0, 0, 0)
|
||||
else:
|
||||
vec = App.Vector(-box.XMin, 0, 0) # remove left margin caused by kerning and white space characters
|
||||
@@ -197,9 +213,7 @@ class ShapeString(DraftObject):
|
||||
vec = vec + App.Vector(-width, 0, 0)
|
||||
elif "Center" in just:
|
||||
vec = vec + App.Vector(-width/2, 0, 0)
|
||||
for shape in shapes:
|
||||
shape.translate(vec)
|
||||
return Part.Compound(shapes)
|
||||
return vec
|
||||
|
||||
def make_faces(self, wireChar):
|
||||
wrn = translate("draft", "ShapeString: face creation failed for one character") + "\n"
|
||||
|
||||
Reference in New Issue
Block a user