Draft: small improvements to units system in dimensions

This commit is contained in:
Yorik van Havre 2014-05-09 17:47:08 -03:00
parent a5efc53bfc
commit 392cf965af
4 changed files with 47 additions and 13 deletions

View File

@ -112,7 +112,8 @@ def getParamType(param):
return "float"
elif param in ["selectBaseObjects","alwaysSnap","grid","fillmode","saveonexit","maxSnap",
"SvgLinesBlack","dxfStdSize","showSnapBar","hideSnapBar","alwaysShowGrid",
"renderPolylineWidth","showPlaneTracker","UsePartPrimitives","DiscretizeEllipses"]:
"renderPolylineWidth","showPlaneTracker","UsePartPrimitives","DiscretizeEllipses",
"showUnit"]:
return "bool"
elif param in ["color","constructioncolor","snapcolor"]:
return "unsigned"
@ -3031,6 +3032,7 @@ class _ViewProviderDimension(_ViewProviderDraft):
obj.addProperty("App::PropertyColor","LineColor","Draft","Line color")
obj.addProperty("App::PropertyLength","ExtLines","Draft","Length of the extension lines")
obj.addProperty("App::PropertyBool","FlipArrows","Draft","Rotate the dimension arrows 180 degrees")
obj.addProperty("App::PropertyBool","ShowUnit","Draft","Show the unit suffix")
obj.addProperty("App::PropertyVector","TextPosition","Draft","The position of the text. Leave (0,0,0) for automatic position")
obj.addProperty("App::PropertyString","Override","Draft","Text override. Use $dim to insert the dimension length")
obj.FontSize = getParam("textheight",0.20)
@ -3041,6 +3043,7 @@ class _ViewProviderDimension(_ViewProviderDraft):
obj.ArrowType = arrowtypes[getParam("dimsymbol",0)]
obj.ExtLines = getParam("extlines",0.3)
obj.Decimals = getParam("dimPrecision",2)
obj.ShowUnit = getParam("showUnit",True)
_ViewProviderDraft.__init__(self,obj)
def attach(self, vobj):
@ -3197,13 +3200,16 @@ class _ViewProviderDimension(_ViewProviderDraft):
tbase = obj.ViewObject.TextPosition
self.textpos.translation.setValue([tbase.x,tbase.y,tbase.z])
self.textpos.rotation = coin.SbRotation(rot1[0],rot1[1],rot1[2],rot1[3])
su = True
if hasattr(obj.ViewObject,"ShowUnit"):
su = obj.ViewObject.ShowUnit
# set text value
l = self.p3.sub(self.p2).Length
if hasattr(obj.ViewObject,"Decimals"):
self.string = DraftGui.displayExternal(l,obj.ViewObject.Decimals,'Length')
self.string = DraftGui.displayExternal(l,obj.ViewObject.Decimals,'Length',su)
else:
self.string = DraftGui.displayExternal(l,getParam("dimPrecision",2),'Length')
self.string = DraftGui.displayExternal(l,getParam("dimPrecision",2),'Length',su)
if hasattr(obj.ViewObject,"Override"):
if obj.ViewObject.Override:
try:
@ -3390,6 +3396,7 @@ class _ViewProviderAngularDimension(_ViewProviderDraft):
obj.addProperty("App::PropertyFloat","LineWidth","Draft","Line width")
obj.addProperty("App::PropertyColor","LineColor","Draft","Line color")
obj.addProperty("App::PropertyBool","FlipArrows","Draft","Rotate the dimension arrows 180 degrees")
obj.addProperty("App::PropertyBool","ShowUnit","Draft","Show the unit suffix")
obj.addProperty("App::PropertyVector","TextPosition","Draft","The position of the text. Leave (0,0,0) for automatic position")
obj.addProperty("App::PropertyString","Override","Draft","Text override. Use 'dim' to insert the dimension length")
obj.FontSize = getParam("textheight",0.20)
@ -3400,6 +3407,7 @@ class _ViewProviderAngularDimension(_ViewProviderDraft):
obj.ArrowType = arrowtypes[getParam("dimsymbol",0)]
obj.Override = ''
obj.Decimals = getParam("dimPrecision",2)
obj.ShowUnit = getParam("showUnit",True)
_ViewProviderDraft.__init__(self,obj)
def attach(self, vobj):
@ -3478,14 +3486,15 @@ class _ViewProviderAngularDimension(_ViewProviderDraft):
a = obj.LastAngle.Value - obj.FirstAngle.Value
else:
a = (360 - obj.FirstAngle.Value) + obj.LastAngle.Value
su = True
if hasattr(obj.ViewObject,"ShowUnit"):
su = obj.ViewObject.ShowUnit
if hasattr(obj.ViewObject,"Decimals"):
fstring = "%." + str(obj.ViewObject.Decimals) + "f"
self.string = DraftGui.displayExternal(a,obj.ViewObject.Decimals,'Angle',su)
else:
fstring = "%." + str(getParam("dimPrecision",2)) + "f"
self.string = (fstring % a)
self.string += " d"
self.string = DraftGui.displayExternal(a,getParam("dimPrecision",2),'Angle',su)
if obj.ViewObject.Override:
self.string = unicode(obj.ViewObject.Override).encode("latin1").replace("$dim",self.string)
self.string = obj.ViewObject.Override.decode("utf8").encode("latin1").replace("$dim",self.string)
self.text.string = self.text3d.string = self.string
# check display mode

View File

@ -129,7 +129,7 @@ def makeFormatSpec(decimals=4,dim='Length'):
fmtSpec = "%." + str(decimals) + "f " + "??"
return fmtSpec
def displayExternal(internValue,decimals=4,dim='Length'):
def displayExternal(internValue,decimals=4,dim='Length',showUnit=True):
'''return an internal value (ie mm) Length or Angle converted for display according
to Units Schema in use.'''
from FreeCAD import Units
@ -146,6 +146,8 @@ def displayExternal(internValue,decimals=4,dim='Length'):
else:
conversion = 1.0
uom = "??"
if not showUnit:
uom = ""
fmt = "{0:."+ str(decimals) + "f} "+ uom
displayExt = fmt.format(float(internValue) / float(conversion))
return displayExt
@ -525,7 +527,7 @@ class DraftToolBar:
self.facecolorButton.setIcon(QtGui.QIcon(self.facecolorPix))
self.widthButton = self._spinbox("widthButton", self.bottomtray, val=self.linewidth,hide=False,size=(50,22))
self.widthButton.setSuffix("px")
self.fontsizeButton = self._spinbox("fontsizeButton",self.bottomtray, val=self.fontsize,hide=False,double=True,size=(50,22))
self.fontsizeButton = self._spinbox("fontsizeButton",self.bottomtray, val=self.fontsize,vmax=999, hide=False,double=True,size=(65,22))
self.applyButton = self._pushbutton("applyButton", self.toptray, hide=False, icon='Draft_Apply',width=22)
QtCore.QObject.connect(self.wplabel,QtCore.SIGNAL("pressed()"),self.selectplane)

File diff suppressed because one or more lines are too long

View File

@ -440,6 +440,9 @@ such as &quot;Arial:Bold&quot;</string>
<property name="toolTip">
<string>Default height for texts and dimensions</string>
</property>
<property name="maximum">
<double>999.990000000000009</double>
</property>
<property name="value">
<double>0.200000000000000</double>
</property>
@ -689,6 +692,26 @@ such as &quot;Arial:Bold&quot;</string>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox">
<property name="text">
<string>Show the unit suffix in dimensions</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>showUnit</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_23">
<item>