Draft: Fixed broken backwards compatibility with annotations

This commit is contained in:
Yorik van Havre
2020-04-21 12:20:10 +02:00
parent 1090da622a
commit dc742e8523
2 changed files with 52 additions and 39 deletions

View File

@@ -225,6 +225,10 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
def attach(self, vobj):
'''Setup the scene sub-graph of the view provider'''
# backwards compatibility
self.ScaleMultiplier = 1.00
self.Object = vobj.Object
self.color = coin.SoBaseColor()
self.font = coin.SoFont()
@@ -341,8 +345,8 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
self.p2 = self.p1
self.p3 = self.p4
if proj:
if hasattr(obj.ViewObject,"ExtLines") and hasattr(obj.ViewObject,"ScaleMultiplier"):
dmax = obj.ViewObject.ExtLines.Value * obj.ViewObject.ScaleMultiplier
if hasattr(obj.ViewObject,"ExtLines"):
dmax = obj.ViewObject.ExtLines.Value * self.ScaleMultiplier
if dmax and (proj.Length > dmax):
if (dmax > 0):
self.p1 = self.p2.add(DraftVecUtils.scaleTo(proj,dmax))
@@ -402,8 +406,8 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
rot3 = App.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") and hasattr(obj.ViewObject,"ScaleMultiplier"):
ts = obj.ViewObject.TextSpacing.Value * obj.ViewObject.ScaleMultiplier
if hasattr(obj.ViewObject,"TextSpacing"):
ts = obj.ViewObject.TextSpacing.Value * self.ScaleMultiplier
offset = DraftVecUtils.scaleTo(v1,ts)
else:
offset = DraftVecUtils.scaleTo(v1,0.05)
@@ -474,11 +478,13 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
def onChanged(self, vobj, prop):
"""called when a view property has changed"""
if prop == "ScaleMultiplier" and hasattr(vobj,"ScaleMultiplier"):
if vobj.ScaleMultiplier: # don't set if zero
self.ScaleMultiplier = vobj.ScaleMultiplier
# update all dimension values
if hasattr(self,"font"):
self.font.size = vobj.FontSize.Value*vobj.ScaleMultiplier
self.font.size = vobj.FontSize.Value * self.ScaleMultiplier
if hasattr(self,"font3d"):
self.font3d.size = vobj.FontSize.Value*100*vobj.ScaleMultiplier
self.font3d.size = vobj.FontSize.Value * 100 * self.ScaleMultiplier
if hasattr(self,"node") and hasattr(self,"p2") and hasattr(vobj,"ArrowSize"):
self.remove_dim_arrows()
self.draw_dim_arrows(vobj)
@@ -492,10 +498,10 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
vobj.Object.touch()
elif (prop == "FontSize") and hasattr(vobj,"FontSize"):
if hasattr(self,"font") and hasattr(vobj,"ScaleMultiplier"):
self.font.size = vobj.FontSize.Value*vobj.ScaleMultiplier
if hasattr(self,"font3d") and hasattr(vobj,"ScaleMultiplier"):
self.font3d.size = vobj.FontSize.Value*100*vobj.ScaleMultiplier
if hasattr(self,"font"):
self.font.size = vobj.FontSize.Value * self.ScaleMultiplier
if hasattr(self,"font3d"):
self.font3d.size = vobj.FontSize.Value * 100 * self.ScaleMultiplier
vobj.Object.touch()
elif (prop == "FontName") and hasattr(vobj,"FontName"):
@@ -514,22 +520,19 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
elif (prop in ["ArrowSize","ArrowType"]) and hasattr(vobj,"ArrowSize"):
if hasattr(self,"node") and hasattr(self,"p2"):
if hasattr(vobj,"ScaleMultiplier"):
self.remove_dim_arrows()
self.draw_dim_arrows(vobj)
vobj.Object.touch()
self.remove_dim_arrows()
self.draw_dim_arrows(vobj)
vobj.Object.touch()
elif (prop == "DimOvershoot") and hasattr(vobj,"DimOvershoot"):
if hasattr(vobj,"ScaleMultiplier"):
self.remove_dim_overshoot()
self.draw_dim_overshoot(vobj)
vobj.Object.touch()
self.remove_dim_overshoot()
self.draw_dim_overshoot(vobj)
vobj.Object.touch()
elif (prop == "ExtOvershoot") and hasattr(vobj,"ExtOvershoot"):
if hasattr(vobj,"ScaleMultiplier"):
self.remove_ext_overshoot()
self.draw_ext_overshoot(vobj)
vobj.Object.touch()
self.remove_ext_overshoot()
self.draw_ext_overshoot(vobj)
vobj.Object.touch()
elif (prop == "ShowLine") and hasattr(vobj,"ShowLine"):
if vobj.ShowLine:
@@ -559,7 +562,7 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
# set scale
symbol = utils.ARROW_TYPES.index(vobj.ArrowType)
s = vobj.ArrowSize.Value * vobj.ScaleMultiplier
s = vobj.ArrowSize.Value * self.ScaleMultiplier
self.trans1.scaleFactor.setValue((s,s,s))
self.trans2.scaleFactor.setValue((s,s,s))
@@ -593,7 +596,7 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
from pivy import coin
# set scale
s = vobj.DimOvershoot.Value * vobj.ScaleMultiplier
s = vobj.DimOvershoot.Value * self.ScaleMultiplier
self.transDimOvershoot1.scaleFactor.setValue((s,s,s))
self.transDimOvershoot2.scaleFactor.setValue((s,s,s))
@@ -624,7 +627,7 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
from pivy import coin
# set scale
s = vobj.ExtOvershoot.Value * vobj.ScaleMultiplier
s = vobj.ExtOvershoot.Value * self.ScaleMultiplier
self.transExtOvershoot1.scaleFactor.setValue((s,s,s))
self.transExtOvershoot2.scaleFactor.setValue((s,s,s))
@@ -728,6 +731,8 @@ class ViewProviderAngularDimension(ViewProviderDimensionBase):
self.onChanged(vobj,"FontName")
self.onChanged(vobj,"ArrowType")
self.onChanged(vobj,"LineColor")
# backwards compatibility
self.ScaleMultiplier = 1.00
def updateData(self, obj, prop):
if hasattr(self,"arc"):
@@ -853,21 +858,23 @@ class ViewProviderAngularDimension(ViewProviderDimensionBase):
def onChanged(self, vobj, prop):
if prop == "ScaleMultiplier" and hasattr(vobj,"ScaleMultiplier"):
if vobj.ScaleMultiplier:
self.ScaleMultiplier = vobj.ScaleMultiplier
# update all dimension values
if hasattr(self,"font"):
self.font.size = vobj.FontSize.Value*vobj.ScaleMultiplier
self.font.size = vobj.FontSize.Value * self.ScaleMultiplier
if hasattr(self,"font3d"):
self.font3d.size = vobj.FontSize.Value*100*vobj.ScaleMultiplier
self.font3d.size = vobj.FontSize.Value * 100 * self.ScaleMultiplier
if hasattr(self,"node") and hasattr(self,"p2") and hasattr(vobj,"ArrowSize"):
self.remove_dim_arrows()
self.draw_dim_arrows(vobj)
self.updateData(vobj.Object,"Start")
vobj.Object.touch()
elif prop == "FontSize" and hasattr(vobj,"ScaleMultiplier"):
elif prop == "FontSize":
if hasattr(self,"font"):
self.font.size = vobj.FontSize.Value*vobj.ScaleMultiplier
self.font.size = vobj.FontSize.Value * self.ScaleMultiplier
if hasattr(self,"font3d"):
self.font3d.size = vobj.FontSize.Value*100*vobj.ScaleMultiplier
self.font3d.size = vobj.FontSize.Value * 100 * self.ScaleMultiplier
vobj.Object.touch()
elif prop == "FontName":
if hasattr(self,"font") and hasattr(self,"font3d"):
@@ -880,7 +887,7 @@ class ViewProviderAngularDimension(ViewProviderDimensionBase):
elif prop == "LineWidth":
if hasattr(self,"drawstyle"):
self.drawstyle.lineWidth = vobj.LineWidth
elif prop in ["ArrowSize","ArrowType"] and hasattr(vobj,"ScaleMultiplier"):
elif prop in ["ArrowSize","ArrowType"]:
if hasattr(self,"node") and hasattr(self,"p2"):
self.remove_dim_arrows()
self.draw_dim_arrows(vobj)
@@ -901,7 +908,7 @@ class ViewProviderAngularDimension(ViewProviderDimensionBase):
# set scale
symbol = utils.ARROW_TYPES.index(vobj.ArrowType)
s = vobj.ArrowSize.Value * vobj.ScaleMultiplier
s = vobj.ArrowSize.Value * self.ScaleMultiplier
self.trans1.scaleFactor.setValue((s,s,s))
self.trans2.scaleFactor.setValue((s,s,s))
@@ -926,4 +933,4 @@ class ViewProviderAngularDimension(ViewProviderDimensionBase):
self.node3d.insertChild(self.marks,2)
def getIcon(self):
return ":/icons/Draft_DimensionAngular.svg"
return ":/icons/Draft_DimensionAngular.svg"

View File

@@ -93,6 +93,10 @@ class ViewProviderText(ViewProviderDraftAnnotation):
def attach(self,vobj):
'''Setup the scene sub-graph of the view provider'''
# backwards compatibility
self.ScaleMultiplier = 1.00
self.mattext = coin.SoMaterial()
textdrawstyle = coin.SoDrawStyle()
textdrawstyle.style = coin.SoDrawStyle.FILLED
@@ -123,7 +127,6 @@ class ViewProviderText(ViewProviderDraftAnnotation):
self.onChanged(vobj,"Justification")
self.onChanged(vobj,"LineSpacing")
def getDisplayModes(self,vobj):
return ["2D text","3D text"]
@@ -148,8 +151,11 @@ class ViewProviderText(ViewProviderDraftAnnotation):
def onChanged(self,vobj,prop):
if prop == "ScaleMultiplier":
if "ScaleMultiplier" in vobj.PropertiesList and "FontSize" in vobj.PropertiesList:
self.font.size = vobj.FontSize.Value * vobj.ScaleMultiplier
if "ScaleMultiplier" in vobj.PropertiesList:
if vobj.ScaleMultiplier:
self.ScaleMultiplier = vobj.ScaleMultiplier
if "FontSize" in vobj.PropertiesList:
self.font.size = vobj.FontSize.Value * self.ScaleMultiplier
elif prop == "TextColor":
if "TextColor" in vobj.PropertiesList:
l = vobj.TextColor
@@ -158,8 +164,8 @@ class ViewProviderText(ViewProviderDraftAnnotation):
if "FontName" in vobj.PropertiesList:
self.font.name = vobj.FontName.encode("utf8")
elif prop == "FontSize":
if "FontSize" in vobj.PropertiesList and "ScaleMultiplier" in vobj.PropertiesList:
self.font.size = vobj.FontSize.Value * vobj.ScaleMultiplier
if "FontSize" in vobj.PropertiesList:
self.font.size = vobj.FontSize.Value * self.ScaleMultiplier
elif prop == "Justification":
try:
if getattr(vobj, "Justification", None) is not None:
@@ -177,4 +183,4 @@ class ViewProviderText(ViewProviderDraftAnnotation):
elif prop == "LineSpacing":
if "LineSpacing" in vobj.PropertiesList:
self.text2d.spacing = vobj.LineSpacing
self.text3d.spacing = vobj.LineSpacing
self.text3d.spacing = vobj.LineSpacing