Skip to content

Commit

Permalink
Arch: Better output of ArchVRM renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Apr 20, 2015
1 parent 01480a1 commit bab894b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 47 deletions.
3 changes: 2 additions & 1 deletion src/Mod/Arch/ArchMaterial.py
Expand Up @@ -219,6 +219,7 @@ def accept(self):
self.obj.Material = self.material
self.obj.Label = self.material['Name']
FreeCADGui.ActiveDocument.resetEdit()
FreeCADGui.Control.closeDialog()

def chooseMat(self, card):
"sets self.material from a card"
Expand Down Expand Up @@ -247,7 +248,7 @@ def fillMaterialCombo(self):
if e.upper() == ".FCMAT":
self.cards[b] = p + os.sep + f
if self.cards:
for k,i in self.cards.items():
for k in sorted(self.cards.keys()):
self.form.comboBox_MaterialsInDir.addItem(k)

def openEditor(self):
Expand Down
19 changes: 12 additions & 7 deletions src/Mod/Arch/ArchSectionPlane.py
Expand Up @@ -357,20 +357,28 @@ def onChanged(self, obj, prop):
os.append(o)
objs = os
self.svg = ''
fillpattern = '<pattern id="sectionfill" patternUnits="userSpaceOnUse" patternTransform="matrix(5,0,0,5,0,0)"'
fillpattern += ' x="0" y="0" width="10" height="10">'
fillpattern += '<g>'
fillpattern += '<rect width="10" height="10" style="stroke:none; fill:#ffffff" /><path style="stroke:#000000; stroke-width:1" d="M0,0 l10,10" /></g></pattern>'

# generating SVG
if obj.RenderingMode == "Solid":
# render using the Arch Vector Renderer
import ArchVRM
import ArchVRM, WorkingPlane
wp = WorkingPlane.plane()
wp.setFromPlacement(obj.Source.Placement)
wp.inverse()
render = ArchVRM.Renderer()
render.setWorkingPlane(obj.Source.Placement)
render.setWorkingPlane(wp)
render.addObjects(objs)
if hasattr(obj,"ShowCut"):
render.cut(obj.Source.Shape,obj.ShowCut)
else:
render.cut(obj.Source.Shape)
self.svg += render.getViewSVG(linewidth="LWPlaceholder")
self.svg += render.getSectionSVG(linewidth="SWPLaceholder")
self.svg += fillpattern
self.svg += render.getSectionSVG(linewidth="SWPlaceholder",fillpattern="sectionfill")
if hasattr(obj,"ShowCut"):
if obj.ShowCut:
self.svg += render.getHiddenSVG(linewidth="LWPlaceholder")
Expand Down Expand Up @@ -448,11 +456,8 @@ def onChanged(self, obj, prop):
svgs = ""
if hasattr(obj,"ShowFill"):
if obj.ShowFill:
svgs += fillpattern
svgs += '<g transform="rotate(180)">\n'
svgs += '<pattern id="sectionfill" patternUnits="userSpaceOnUse" patternTransform="matrix(5,0,0,5,0,0)"'
svgs += ' x="0" y="0" width="10" height="10">'
svgs += '<g style="fill:none; stroke:#000000; stroke-width:1">'
svgs += '<path d="M0,0 l10,10" /></g></pattern>'
for s in sshapes:
if s.Edges:
f = Draft.getSVG(s,direction=self.direction.negative(),linewidth=0,fillstyle="sectionfill",color=(0,0,0))
Expand Down
65 changes: 27 additions & 38 deletions src/Mod/Arch/ArchVRM.py
Expand Up @@ -521,13 +521,16 @@ def sort(self):
notfoundstack = 0
break
elif r == 31:
faces.remove(f1)
if f1 in faces:
faces.remove(f1)
elif r == 32:
faces.remove(f2)
if f2 in faces:
faces.remove(f2)
else:
# nothing found, move the face to the end of the pile
faces.remove(f1)
faces.append(f1)
if f1 in faces:
faces.remove(f1)
faces.append(f1)
loopcount += 1
if loopcount == MAXLOOP * len(self.faces):
if DEBUG: print "Too many loops, aborting."
Expand Down Expand Up @@ -586,70 +589,56 @@ def getViewSVG(self,linewidth=0.01):
if DEBUG: print "Printing ", len(self.faces), " faces"
if not self.sorted:
self.sort()
svg = ''
svg = '<g stroke="#000000" stroke-width="' + str(linewidth) + '" style="stroke-width:' + str(linewidth)
svg += ';stroke-miterlimit:1;stroke-linejoin:round;stroke-dasharray:none;">\n'
for f in self.faces:
if f:
fill = self.getFill(f[1])
svg +='<path '
svg +=' <path '
svg += 'd="'
for w in f[0].Wires:
svg += self.getPathData(w)
svg += '" '
svg += 'stroke="#000000" '
svg += 'stroke-width="' + str(linewidth) + '" '
svg += 'style="stroke-width:' + str(linewidth) + ';'
svg += 'stroke-miterlimit:1;'
svg += 'stroke-linejoin:round;'
svg += 'stroke-dasharray:none;'
svg += 'fill:' + fill + ';'
svg += 'fill-rule: evenodd'
svg += '"/>\n'
svg += '" style="fill:' + fill + ';fill-rule: evenodd;"/>\n'
svg += '</g>\n'
return svg

def getSectionSVG(self,linewidth=0.02):
def getSectionSVG(self,linewidth=0.02,fillpattern=None):
"Returns a SVG fragment from cut faces"
if DEBUG: print "Printing ", len(self.sections), " sections"
if not self.oriented:
self.reorient()
svg = ''
svg = '<g stroke="#000000" stroke-width="' + str(linewidth) + '" style="stroke-width:' + str(linewidth)
svg += ';stroke-miterlimit:1;stroke-linejoin:round;stroke-dasharray:none;">\n'
for f in self.sections:
if f:
fill = self.getFill(f[1])
if fillpattern:
if "#" in fillpattern: # color
fill = fillpattern
else:
fill="url(#"+fillpattern+")" # pattern name
else:
fill = 'none' # none
svg +='<path '
svg += 'd="'
for w in f[0].Wires:
#print "wire with ",len(w.Vertexes)," verts"
svg += self.getPathData(w)
svg += '" '
svg += 'stroke="#000000" '
svg += 'stroke-width="' + str(linewidth) + '" '
svg += 'style="stroke-width:' + str(linewidth) + ';'
svg += 'stroke-miterlimit:1;'
svg += 'stroke-linejoin:round;'
svg += 'stroke-dasharray:none;'
svg += 'fill:' + fill + ';'
svg += 'fill-rule: evenodd'
svg += '"/>\n'
svg += '" style="fill:' + fill + ';fill-rule: evenodd;"/>\n'
svg += '</g>\n'
return svg

def getHiddenSVG(self,linewidth=0.02):
"Returns a SVG fragment from cut geometry"
if DEBUG: print "Printing ", len(self.sections), " hidden faces"
if not self.oriented:
self.reorient()
svg = ''
svg = '<g stroke="#000000" stroke-width="' + str(linewidth) + '" style="stroke-width:' + str(linewidth)
svg += ';stroke-miterlimit:1;stroke-linejoin:round;stroke-dasharray:0.09,0.05;fill:none;">\n'
for e in self.hiddenEdges:
svg +='<path '
svg += 'd="'
svg += self.getPathData(e)
svg += '" '
svg += 'stroke="#000000" '
svg += 'stroke-width="' + str(linewidth) + '" '
svg += 'style="stroke-width:' + str(linewidth) + ';'
svg += 'stroke-miterlimit:1;'
svg += 'stroke-linejoin:round;'
svg += 'stroke-dasharray:0.09,0.05;'
svg += 'fill:none;'
svg += '"/>\n'
svg += '</g>\n'
return svg

3 changes: 2 additions & 1 deletion src/Mod/Draft/Draft.py
Expand Up @@ -4237,7 +4237,8 @@ def onChanged(self, obj, prop):
if len(obj.Points) > 2:
obj.setEditorMode('Start',2)
obj.setEditorMode('End',2)
obj.setEditorMode('Length',2)
if hasattr(obj,"Length"):
obj.setEditorMode('Length',2)


class _ViewProviderWire(_ViewProviderDraft):
Expand Down
5 changes: 5 additions & 0 deletions src/Mod/Draft/WorkingPlane.py
Expand Up @@ -302,6 +302,11 @@ def setFromPlacement(self,pl):
self.u = rot.multVec(FreeCAD.Vector(1,0,0))
self.v = rot.multVec(FreeCAD.Vector(0,1,0))
self.axis = rot.multVec(FreeCAD.Vector(0,0,1))

def inverse(self):
"inverts the direction of the working plane"
self.u = self.u.negative()
self.axis = self.axis.negative()

def save(self):
"stores the current plane state"
Expand Down

0 comments on commit bab894b

Please sign in to comment.