Skip to content

Commit

Permalink
Arch: Section planes can now also include Draft stuff (dimensions, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Oct 31, 2016
1 parent 23c4faf commit 4ee8a2a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 26 deletions.
40 changes: 28 additions & 12 deletions src/Mod/Arch/ArchSectionPlane.py
Expand Up @@ -75,7 +75,7 @@ def makeSectionView(section,name="View"):
return view


def getSVG(section,allOn=False,renderMode="Wireframe",showHidden=False,showFill=False,scale=1,linewidth=1,fontsize=1):
def getSVG(section,allOn=False,renderMode="Wireframe",showHidden=False,showFill=False,scale=1,linewidth=1,fontsize=1,techdraw=False):
"""getSVG(section,[allOn,renderMode,showHidden,showFill,scale,linewidth,fontsize]) :
returns an SVG fragment from an Arch section plane. If
allOn is True, all cut objects are shown, regardless if they are visible or not.
Expand All @@ -91,12 +91,17 @@ def getSVG(section,allOn=False,renderMode="Wireframe",showHidden=False,showFill=
objs = Draft.getGroupContents(section.Objects,walls=True,addgroups=True)
if not allOn:
objs = Draft.removeHidden(objs)
# separate spaces
# separate spaces and Draft objects
spaces = []
nonspaces = []
drafts = []
for o in objs:
if Draft.getType(o) == "Space":
spaces.append(o)
elif Draft.getType(o) in ["Dimension","Annotation"]:
drafts.append(o)
elif o.isDerivedFrom("Part::Part2DObject"):
drafts.append(o)
else:
nonspaces.append(o)
objs = nonspaces
Expand Down Expand Up @@ -191,11 +196,13 @@ def getSVG(section,allOn=False,renderMode="Wireframe",showHidden=False,showFill=
if sshapes:
svgs = ""
if showFill:
svgs += fillpattern
#svgs += fillpattern
svgs += '<g transform="rotate(180)">\n'
for s in sshapes:
if s.Edges:
f = Draft.getSVG(s,direction=direction.negative(),linewidth=0,fillstyle="sectionfill",color=(0,0,0))
#f = Draft.getSVG(s,direction=direction.negative(),linewidth=0,fillstyle="sectionfill",color=(0,0,0))
# temporarily disabling fill patterns
f = Draft.getSVG(s,direction=direction.negative(),linewidth=0,fillstyle="#aaaaaa",color=(0,0,0))
svgs += f
svgs += "</g>\n"
sshapes = Part.makeCompound(sshapes)
Expand All @@ -208,19 +215,28 @@ def getSVG(section,allOn=False,renderMode="Wireframe",showHidden=False,showFill=
svgs = svgs.replace('stroke-width:0.35','stroke-width:SWPlaceholder')
svg += svgs

linewidth = linewidth/scale
scaledlinewidth = linewidth/scale
st = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetFloat("CutLineThickness",2)
da = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetString("archHiddenPattern","30,10")
da = da.replace(" ","")
svg = svg.replace('LWPlaceholder', str(linewidth) + 'px')
svg = svg.replace('SWPlaceholder', str(linewidth*st) + 'px')
svg = svg.replace('LWPlaceholder', str(scaledlinewidth) + 'px')
svg = svg.replace('SWPlaceholder', str(scaledlinewidth*st) + 'px')
svg = svg.replace('DAPlaceholder', str(da))
if spaces and round(direction.getAngle(FreeCAD.Vector(0,0,1)),Draft.precision()) in [0,round(math.pi,Draft.precision())]:
svg += '<g transform="scale(1,-1)">'
if drafts:
if not techdraw:
svg += '<g transform="scale(1,-1)">'
for d in drafts:
svg += Draft.getSVG(d,scale=scale,linewidth=linewidth,fontsize=fontsize,direction=direction,techdraw=techdraw)
if not techdraw:
svg += '</g>'
if spaces:
if not techdraw:
svg += '<g transform="scale(1,-1)">'
for s in spaces:
svg += Draft.getSVG(s,scale=scale,fontsize=fontsize,direction=direction)
svg += '</g>'
# print "complete node:",svg
svg += Draft.getSVG(s,scale=scale,linewidth=linewidth,fontsize=fontsize,direction=direction,techdraw=techdraw)
if not techdraw:
svg += '</g>'
#print "complete node:",svg
return svg


Expand Down
32 changes: 19 additions & 13 deletions src/Mod/Draft/Draft.py
Expand Up @@ -1731,11 +1731,12 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
scale parameter allows to scale linewidths down, so they are resolution-independant.'''

# if this is a group, gather all the svg views of its children
if obj.isDerivedFrom("App::DocumentObjectGroup"):
svg = ""
for child in obj.Group:
svg += getSVG(child,scale,linewidth,fontsize,fillstyle,direction,linestyle,color,linespacing,techdraw)
return svg
if hasattr(obj,"isDerivedFrom"):
if obj.isDerivedFrom("App::DocumentObjectGroup"):
svg = ""
for child in obj.Group:
svg += getSVG(child,scale,linewidth,fontsize,fillstyle,direction,linestyle,color,linespacing,techdraw)
return svg

import Part, DraftGeomUtils
pathdata = []
Expand Down Expand Up @@ -2019,9 +2020,9 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
svg += 'font-family:'+ fontname +'" '
svg += 'transform="rotate('+str(math.degrees(angle))
svg += ','+ str(base.x) + ',' + str(base.y+linespacing*i) + ') '
svg += 'translate(' + str(base.x) + ',' + str(base.y+linespacing*i) + ') '
svg += '" freecad:skip="1"'
svg += '>\n' + text[i] + '</text>\n'
svg += 'translate(' + str(base.x) + ',' + str(base.y+linespacing*i) + ')" '
#svg += '" freecad:skip="1"'
svg += '>\n' + text[i] + '</text>\n'
else:
svg = '<text fill="'
svg += color +'" font-size="'
Expand All @@ -2031,14 +2032,14 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
svg += 'transform="rotate('+str(math.degrees(angle))
svg += ','+ str(base.x) + ',' + str(base.y) + ') '
if flip:
svg += 'translate(' + str(base.x) + ',' + str(base.y) + ') '
svg += 'translate(' + str(base.x) + ',' + str(base.y) + ')'
else:
svg += 'translate(' + str(base.x) + ',' + str(-base.y) + ') '
svg += 'translate(' + str(base.x) + ',' + str(-base.y) + ')'
#svg += 'scale('+str(tmod/2000)+',-'+str(tmod/2000)+') '
if flip and (not techdraw):
svg += 'scale(1,-1) '
svg += ' scale(1,-1) '
else:
svg += 'scale(1,1) '
svg += ' scale(1,1) '
svg += '" freecad:skip="1"'
svg += '>\n'
if len(text) == 1:
Expand All @@ -2065,7 +2066,12 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
pass

elif isinstance(obj,Part.Shape):
fill = 'url(#'+fillstyle+')'
if "#" in fillstyle:
fill = fillstyle
elif fillstyle == "shape color":
fill = "#888888"
else:
fill = 'url(#'+fillstyle+')'
lstyle = getLineStyle()
svg += getPath(obj.Edges,pathname="")

Expand Down
5 changes: 4 additions & 1 deletion src/Mod/TechDraw/App/DrawViewArch.cpp
Expand Up @@ -106,8 +106,11 @@ App::DocumentObjectExecReturn *DrawViewArch::execute(void)
<< ",renderMode=\"" << RenderMode.getValue() << "\""
<< ",showHidden=" << (ShowHidden.getValue() ? "True" : "False")
<< ",showFill=" << (ShowFill.getValue() ? "True" : "False")
<< ",scale=" << Scale.getValue()
<< ",linewidth=" << LineWidth.getValue()
<< ",fontsize=" << FontSize.getValue();
<< ",fontsize=" << FontSize.getValue()
<< ",techdraw=True";

Base::Interpreter().runString("import ArchSectionPlane");
Base::Interpreter().runStringArg("svgBody = ArchSectionPlane.getSVG(App.activeDocument().%s %s)",
SourceName.c_str(),paramStr.str().c_str());
Expand Down

0 comments on commit 4ee8a2a

Please sign in to comment.