Skip to content

Commit

Permalink
Draft: Improvement to Draft Drawing views
Browse files Browse the repository at this point in the history
* Property to specify if the view must appear even if the Source obj is off
* Property to set the line spacing for multiline texts
  • Loading branch information
yorikvanhavre committed May 30, 2016
1 parent c73602b commit affbed1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/Mod/Arch/ArchSectionPlane.py
Expand Up @@ -314,6 +314,7 @@ def __init__(self, obj):
obj.addProperty("App::PropertyBool","ShowFill","Drawing view","If cut geometry is filled or not")
obj.addProperty("App::PropertyFloat","LineWidth","Drawing view","The line width of the rendered objects")
obj.addProperty("App::PropertyLength","FontSize","Drawing view","The size of the texts inside this object")
obj.addProperty("App::PropertyBool","AlwaysOn","Drawing view","If checked, source objects are displayed regardless of being visible in the 3D model")
obj.RenderingMode = ["Solid","Wireframe"]
obj.RenderingMode = "Wireframe"
obj.LineWidth = 0.35
Expand Down Expand Up @@ -367,7 +368,11 @@ def onChanged(self, obj, prop):
if obj.Source:
if obj.Source.Objects:
objs = Draft.getGroupContents(obj.Source.Objects,walls=True,addgroups=True)
objs = Draft.removeHidden(objs)
if hasattr(obj,"AlwaysOn"):
if not obj.AlwaysOn:
objs = Draft.removeHidden(objs)
else:
objs = Draft.removeHidden(objs)
# separate spaces
self.spaces = []
os = []
Expand Down
32 changes: 22 additions & 10 deletions src/Mod/Draft/Draft.py
Expand Up @@ -1705,8 +1705,8 @@ def getProj(vec):
return result


def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direction=None,linestyle=None,color=None):
'''getSVG(object,[scale], [linewidth],[fontsize],[fillstyle],[direction],[linestyle],[color]):
def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direction=None,linestyle=None,color=None,linespacing=None):
'''getSVG(object,[scale], [linewidth],[fontsize],[fillstyle],[direction],[linestyle],[color],[linespacing]):
returns a string containing a SVG representation of the given object,
with the given linewidth and fontsize (used if the given object contains
any text). You can also supply an arbitrary projection vector. the
Expand All @@ -1715,6 +1715,10 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
svg = ""
linewidth = float(linewidth)/scale
fontsize = (float(fontsize)/scale)/2
if linespacing:
linespacing = float(linespacing)/scale
else:
linespacing = 0.5
pointratio = .75 # the number of times the dots are smaller than the arrow size
plane = None
if direction:
Expand Down Expand Up @@ -2108,9 +2112,8 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
n = obj.ViewObject.FontName
a = obj.ViewObject.Rotation.getValueAs("rad")
t = obj.LabelText
l = obj.ViewObject.LineSpacing/2.0
j = obj.ViewObject.Justification
svg += getText(stroke,fontsize,n,a,getProj(obj.Position),t,l,j)
svg += getText(stroke,fontsize,n,a,getProj(obj.Position),t,linespacing,j)

elif getType(obj) == "Axis":
"returns the SVG representation of an Arch Axis system"
Expand Down Expand Up @@ -2164,11 +2167,10 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
f1 = fontsize*scale
p2 = FreeCAD.Vector(obj.ViewObject.Proxy.coords.translation.getValue().getValue())
p1 = p2.add(FreeCAD.Vector(obj.ViewObject.Proxy.header.translation.getValue().getValue()))
l = obj.ViewObject.LineSpacing/2.0
j = obj.ViewObject.TextAlign
svg += getText(c,f1,n,a,getProj(p1),t1,l,j,flip=True)
svg += getText(c,f1,n,a,getProj(p1),t1,linespacing,j,flip=True)
if t2:
svg += getText(c,fontsize,n,a,getProj(p2),t2,l,j,flip=True)
svg += getText(c,fontsize,n,a,getProj(p2),t2,linespacing,j,flip=True)

elif obj.isDerivedFrom('Part::Feature'):
if obj.Shape.isNull():
Expand Down Expand Up @@ -4528,10 +4530,12 @@ def __init__(self, obj):
obj.addProperty("App::PropertyVector","Direction","Shape View","Projection direction")
obj.addProperty("App::PropertyFloat","LineWidth","View Style","The width of the lines inside this object")
obj.addProperty("App::PropertyLength","FontSize","View Style","The size of the texts inside this object")
obj.addProperty("App::PropertyLength","LineSpacing","View Style","The spacing between lines of text")
obj.addProperty("App::PropertyColor","LineColor","View Style","The color of the projected objects")
obj.addProperty("App::PropertyLink","Source","Base","The linked object")
obj.addProperty("App::PropertyEnumeration","FillStyle","View Style","Shape Fill Style")
obj.addProperty("App::PropertyEnumeration","LineStyle","View Style","Line Style")
obj.addProperty("App::PropertyBool","AlwaysOn","View Style","If checked, source objects are displayed regardless of being visible in the 3D model")
obj.FillStyle = ['shape color'] + list(svgpatterns().keys())
obj.LineStyle = ['Solid','Dashed','Dotted','Dashdot']
obj.LineWidth = 0.35
Expand All @@ -4549,16 +4553,24 @@ def execute(self, obj):
lc = obj.LineColor
else:
lc = None
if hasattr(obj,"LineSpacing"):
lp = obj.LineSpacing
else:
lp = None
if obj.Source.isDerivedFrom("App::DocumentObjectGroup"):
svg = ""
shapes = []
others = []
objs = getGroupContents([obj.Source])
for o in objs:
if o.ViewObject.isVisible():
svg += getSVG(o,obj.Scale,obj.LineWidth,obj.FontSize.Value,obj.FillStyle,obj.Direction,ls,lc)
v = o.ViewObject.isVisible()
if hasattr(obj,"AlwaysOn"):
if obj.AlwaysOn:
v = True
if v:
svg += getSVG(o,obj.Scale,obj.LineWidth,obj.FontSize.Value,obj.FillStyle,obj.Direction,ls,lc,lp)
else:
svg = getSVG(obj.Source,obj.Scale,obj.LineWidth,obj.FontSize.Value,obj.FillStyle,obj.Direction,ls,lc)
svg = getSVG(obj.Source,obj.Scale,obj.LineWidth,obj.FontSize.Value,obj.FillStyle,obj.Direction,ls,lc,lp)
result += '<g id="' + obj.Name + '"'
result += ' transform="'
result += 'rotate('+str(obj.Rotation)+','+str(obj.X)+','+str(obj.Y)+') '
Expand Down

0 comments on commit affbed1

Please sign in to comment.