Skip to content

Commit

Permalink
Draft: dimension and extension lines overshoots
Browse files Browse the repository at this point in the history
  • Loading branch information
xanderdin authored and wwmayer committed Apr 10, 2018
1 parent 8aba6f1 commit 2400fe6
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 9 deletions.
133 changes: 124 additions & 9 deletions src/Mod/Draft/Draft.py
Expand Up @@ -101,7 +101,8 @@ def getParamType(param):
elif param in ["constructiongroupname","textfont","patternFile","template",
"snapModes","FontFile","ClonePrefix","labeltype"]:
return "string"
elif param in ["textheight","tolerance","gridSpacing","arrowsize","extlines","dimspacing"]:
elif param in ["textheight","tolerance","gridSpacing","arrowsize","extlines","dimspacing",
"dimovershoot","extovershoot"]:
return "float"
elif param in ["selectBaseObjects","alwaysSnap","grid","fillmode","saveonexit","maxSnap",
"SvgLinesBlack","dxfStdSize","showSnapBar","hideSnapBar","alwaysShowGrid",
Expand Down Expand Up @@ -304,18 +305,25 @@ def dimSymbol(symbol=None,invert=False):
marker.addChild(f)
return marker
elif symbol == 4:
marker = coin.SoSeparator()
v = coin.SoVertexProperty()
v.vertex.set1Value(0, -1.5,-1.5,0)
v.vertex.set1Value(1, 1.5,1.5,0)
l = coin.SoLineSet()
l.vertexProperty = v
marker.addChild(l)
return marker
return dimDash((-1.5,-1.5,0),(1.5,1.5,0))
else:
print("Draft.dimsymbol: Not implemented")
return coin.SoSphere()

def dimDash(p1, p2):
'''dimDash(p1, p2): returns pivy SoSeparator.
Used for making Tick-2, DimOvershoot, ExtOvershoot dashes.
'''
from pivy import coin
dash = coin.SoSeparator()
v = coin.SoVertexProperty()
v.vertex.set1Value(0, p1)
v.vertex.set1Value(1, p2)
l = coin.SoLineSet()
l.vertexProperty = v
dash.addChild(l)
return dash

def shapify(obj):
'''shapify(object): transforms a parametric shape object into
non-parametric and returns the new object'''
Expand Down Expand Up @@ -2169,6 +2177,18 @@ def getArrow(arrowtype,point,arrowsize,color,linewidth,angle=0):
print("getSVG: arrow type not implemented")
return svg

def getOvershoot(point,shootsize,color,linewidth,angle=0):
svg = '<line transform="rotate('+str(math.degrees(angle))
svg += ','+ str(point.x) + ',' + str(point.y) + ') '
svg += 'translate(' + str(point.x) + ',' + str(point.y) + ') '
svg += '" freecad:skip="1" '
svg += 'fill="none" stroke="'+ color +'" '
svg += 'style="stroke-dasharray:none;stroke-linecap:square;'
svg += 'stroke-width:'+ str(linewidth) +'" '
svg += 'x1="0" y1="0" '
svg += 'x2="'+ str(shootsize*-1) +'" y2="0" />\n'
return svg

def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="center",flip=True):
if not isinstance(text,list):
text = text.split("\n")
Expand Down Expand Up @@ -2309,6 +2329,17 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
svg += 'freecad:dimpoint="'+str(p2.x)+' '+str(p2.y)+'"'
svg += '/>\n'

# drawing dimension and extension lines overshoots
if hasattr(obj.ViewObject,"DimOvershoot") and obj.ViewObject.DimOvershoot.Value:
shootsize = obj.ViewObject.DimOvershoot.Value/pointratio
svg += getOvershoot(p2,shootsize,stroke,linewidth,angle)
svg += getOvershoot(p3,shootsize,stroke,linewidth,angle+math.pi)
if hasattr(obj.ViewObject,"ExtOvershoot") and obj.ViewObject.ExtOvershoot.Value:
shootsize = obj.ViewObject.ExtOvershoot.Value/pointratio
shootangle = -DraftVecUtils.angle(p1.sub(p2))
svg += getOvershoot(p2,shootsize,stroke,linewidth,shootangle)
svg += getOvershoot(p3,shootsize,stroke,linewidth,shootangle)

# drawing arrows
if hasattr(obj.ViewObject,"ArrowType"):
arrowsize = obj.ViewObject.ArrowSize.Value/pointratio
Expand Down Expand Up @@ -3970,6 +4001,8 @@ def __init__(self, obj):
obj.addProperty("App::PropertyFloat","LineWidth","Draft",QT_TRANSLATE_NOOP("App::Property","Line width"))
obj.addProperty("App::PropertyColor","LineColor","Draft",QT_TRANSLATE_NOOP("App::Property","Line color"))
obj.addProperty("App::PropertyDistance","ExtLines","Draft",QT_TRANSLATE_NOOP("App::Property","Length of the extension lines"))
obj.addProperty("App::PropertyDistance","DimOvershoot","Draft",QT_TRANSLATE_NOOP("App::Property","The distance the dimension line is extended past the extension lines"))
obj.addProperty("App::PropertyDistance","ExtOvershoot","Draft",QT_TRANSLATE_NOOP("App::Property","Length of the extension line above the dimension line"))
obj.addProperty("App::PropertyBool","FlipArrows","Draft",QT_TRANSLATE_NOOP("App::Property","Rotate the dimension arrows 180 degrees"))
obj.addProperty("App::PropertyBool","FlipText","Draft",QT_TRANSLATE_NOOP("App::Property","Rotate the dimension text 180 degrees"))
obj.addProperty("App::PropertyBool","ShowUnit","Draft",QT_TRANSLATE_NOOP("App::Property","Show the unit suffix"))
Expand All @@ -3983,6 +4016,8 @@ def __init__(self, obj):
obj.ArrowType = arrowtypes
obj.ArrowType = arrowtypes[getParam("dimsymbol",0)]
obj.ExtLines = getParam("extlines",0.3)
obj.DimOvershoot = getParam("dimovershoot",0)
obj.ExtOvershoot = getParam("extovershoot",0)
obj.Decimals = getParam("dimPrecision",2)
obj.ShowUnit = getParam("showUnit",True)
_ViewProviderDraft.__init__(self,obj)
Expand Down Expand Up @@ -4014,7 +4049,13 @@ def attach(self, vobj):
self.trans1 = coin.SoTransform()
self.coord2 = coin.SoCoordinate3()
self.trans2 = coin.SoTransform()
self.transDimOvershoot1 = coin.SoTransform()
self.transDimOvershoot2 = coin.SoTransform()
self.transExtOvershoot1 = coin.SoTransform()
self.transExtOvershoot2 = coin.SoTransform()
self.marks = coin.SoSeparator()
self.marksDimOvershoot = coin.SoSeparator()
self.marksExtOvershoot = coin.SoSeparator()
self.drawstyle = coin.SoDrawStyle()
self.line = coin.SoType.fromName("SoBrepEdgeSet").createInstance()
self.coords = coin.SoCoordinate3()
Expand All @@ -4024,13 +4065,17 @@ def attach(self, vobj):
self.node.addChild(self.coords)
self.node.addChild(self.line)
self.node.addChild(self.marks)
self.node.addChild(self.marksDimOvershoot)
self.node.addChild(self.marksExtOvershoot)
self.node.addChild(label)
self.node3d = coin.SoGroup()
self.node3d.addChild(self.color)
self.node3d.addChild(self.drawstyle)
self.node3d.addChild(self.coords)
self.node3d.addChild(self.line)
self.node3d.addChild(self.marks)
self.node3d.addChild(self.marksDimOvershoot)
self.node3d.addChild(self.marksExtOvershoot)
self.node3d.addChild(label3d)
vobj.addDisplayMode(self.node,"2D")
vobj.addDisplayMode(self.node3d,"3D")
Expand All @@ -4039,6 +4084,8 @@ def attach(self, vobj):
self.onChanged(vobj,"FontName")
self.onChanged(vobj,"ArrowType")
self.onChanged(vobj,"LineColor")
self.onChanged(vobj,"DimOvershoot")
self.onChanged(vobj,"ExtOvershoot")

def updateData(self, obj, prop):
"called when the base object is changed"
Expand Down Expand Up @@ -4107,6 +4154,12 @@ def updateData(self, obj, prop):
self.trans2.translation.setValue((self.p3.x,self.p3.y,self.p3.z))
self.coord2.point.setValue((self.p3.x,self.p3.y,self.p3.z))

# calculate dimension and extension lines overshoots positions
self.transDimOvershoot1.translation.setValue((self.p2.x,self.p2.y,self.p2.z))
self.transDimOvershoot2.translation.setValue((self.p3.x,self.p3.y,self.p3.z))
self.transExtOvershoot1.translation.setValue((self.p2.x,self.p2.y,self.p2.z))
self.transExtOvershoot2.translation.setValue((self.p3.x,self.p3.y,self.p3.z))

# calculate the text position and orientation
if hasattr(obj,"Normal"):
if DraftVecUtils.isNull(obj.Normal):
Expand All @@ -4127,13 +4180,21 @@ def updateData(self, obj, prop):
u.normalize()
v1 = norm.cross(u)
rot1 = FreeCAD.Placement(DraftVecUtils.getPlaneRotation(u,v1,norm)).Rotation.Q
self.transDimOvershoot1.rotation.setValue((rot1[0],rot1[1],rot1[2],rot1[3]))
self.transDimOvershoot2.rotation.setValue((rot1[0],rot1[1],rot1[2],rot1[3]))
if hasattr(obj.ViewObject,"FlipArrows"):
if obj.ViewObject.FlipArrows:
u = u.negative()
v2 = norm.cross(u)
rot2 = FreeCAD.Placement(DraftVecUtils.getPlaneRotation(u,v2,norm)).Rotation.Q
self.trans1.rotation.setValue((rot2[0],rot2[1],rot2[2],rot2[3]))
self.trans2.rotation.setValue((rot2[0],rot2[1],rot2[2],rot2[3]))
u3 = self.p1.sub(self.p2)
u3.normalize()
v3 = norm.cross(u3)
rot3 = FreeCAD.Placement(DraftVecUtils.getPlaneRotation(u3,v3,norm)).Rotation.Q
self.transExtOvershoot1.rotation.setValue((rot3[0],rot3[1],rot3[2],rot3[3]))
self.transExtOvershoot2.rotation.setValue((rot3[0],rot3[1],rot3[2],rot3[3]))
if hasattr(obj.ViewObject,"TextSpacing"):
offset = DraftVecUtils.scaleTo(v1,obj.ViewObject.TextSpacing.Value)
else:
Expand Down Expand Up @@ -4267,6 +4328,60 @@ def onChanged(self, vobj, prop):
self.node.insertChild(self.marks,2)
self.node3d.insertChild(self.marks,2)
vobj.Object.touch()
elif (prop == "DimOvershoot") and hasattr(vobj,"DimOvershoot"):
from pivy import coin

# set scale
s = vobj.DimOvershoot.Value
self.transDimOvershoot1.scaleFactor.setValue((s,s,s))
self.transDimOvershoot2.scaleFactor.setValue((s,s,s))

# remove existing nodes
self.node.removeChild(self.marksDimOvershoot)
self.node3d.removeChild(self.marksDimOvershoot)

# set new nodes
self.marksDimOvershoot = coin.SoSeparator()
if vobj.DimOvershoot.Value:
self.marksDimOvershoot.addChild(self.color)
s1 = coin.SoSeparator()
s1.addChild(self.transDimOvershoot1)
s1.addChild(dimDash((-1,0,0),(0,0,0)))
self.marksDimOvershoot.addChild(s1)
s2 = coin.SoSeparator()
s2.addChild(self.transDimOvershoot2)
s2.addChild(dimDash((0,0,0),(1,0,0)))
self.marksDimOvershoot.addChild(s2)
self.node.insertChild(self.marksDimOvershoot,2)
self.node3d.insertChild(self.marksDimOvershoot,2)
vobj.Object.touch()
elif (prop == "ExtOvershoot") and hasattr(vobj,"ExtOvershoot"):
from pivy import coin

# set scale
s = vobj.ExtOvershoot.Value
self.transExtOvershoot1.scaleFactor.setValue((s,s,s))
self.transExtOvershoot2.scaleFactor.setValue((s,s,s))

# remove existing nodes
self.node.removeChild(self.marksExtOvershoot)
self.node3d.removeChild(self.marksExtOvershoot)

# set new nodes
self.marksExtOvershoot = coin.SoSeparator()
if vobj.ExtOvershoot.Value:
self.marksExtOvershoot.addChild(self.color)
s1 = coin.SoSeparator()
s1.addChild(self.transExtOvershoot1)
s1.addChild(dimDash((0,0,0),(-1,0,0)))
self.marksExtOvershoot.addChild(s1)
s2 = coin.SoSeparator()
s2.addChild(self.transExtOvershoot2)
s2.addChild(dimDash((0,0,0),(-1,0,0)))
self.marksExtOvershoot.addChild(s2)
self.node.insertChild(self.marksExtOvershoot,2)
self.node3d.insertChild(self.marksExtOvershoot,2)
vobj.Object.touch()
else:
self.updateData(vobj.Object,"Start")

Expand Down
72 changes: 72 additions & 0 deletions src/Mod/Draft/Resources/ui/preferences-drafttexts.ui
Expand Up @@ -229,6 +229,78 @@ such as &quot;Arial:Bold&quot;</string>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_extovershoot">
<item>
<widget class="QLabel" name="label_extovershoot">
<property name="text">
<string>Extension line overshoot</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefDoubleSpinBox" name="gui::prefdoublespinbox_extovershoot">
<property name="toolTip">
<string>The default length of extension line above dimension line</string>
</property>
<property name="suffix">
<string>mm</string>
</property>
<property name="minimum">
<double>-9999.989999999999782</double>
</property>
<property name="maximum">
<double>9999.989999999999782</double>
</property>
<property name="value">
<double>0.000000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<cstring>extovershoot</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_dimovershoot">
<item>
<widget class="QLabel" name="label_dimovershoot">
<property name="text">
<string>Dimension line overshoot</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefDoubleSpinBox" name="gui::prefdoublespinbox_dimovershoot">
<property name="toolTip">
<string>The default distance the dimension line is extended past extension lines</string>
</property>
<property name="suffix">
<string>mm</string>
</property>
<property name="minimum">
<double>-9999.989999999999782</double>
</property>
<property name="maximum">
<double>9999.989999999999782</double>
</property>
<property name="value">
<double>0.000000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<cstring>dimovershoot</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
Expand Down

0 comments on commit 2400fe6

Please sign in to comment.