Preliminary section support for Arch section planes

This commit is contained in:
Yorik van Havre 2012-04-05 18:05:25 -03:00
parent 5ff29e2b5c
commit de50ac9eca
2 changed files with 72 additions and 13 deletions

View File

@ -205,6 +205,7 @@ def getCutVolume(objects,placement):
in the list fits into it, and an extrusion vector, that can be used to extrude the in the list fits into it, and an extrusion vector, that can be used to extrude the
plane so it includes all objects in the list.''' plane so it includes all objects in the list.'''
import Part import Part
placement = FreeCAD.Placement(placement)
if not objects: if not objects:
return None return None
bb = objects[0].Shape.BoundBox bb = objects[0].Shape.BoundBox

View File

@ -21,7 +21,7 @@
#* * #* *
#*************************************************************************** #***************************************************************************
import FreeCAD,FreeCADGui,ArchComponent,WorkingPlane,Drawing,math,Draft import FreeCAD,FreeCADGui,ArchComponent,WorkingPlane,Drawing,math,Draft,ArchCommands
from FreeCAD import Vector from FreeCAD import Vector
from PyQt4 import QtCore from PyQt4 import QtCore
from pivy import coin from pivy import coin
@ -173,13 +173,34 @@ class _ArchDrawingView:
def updateSVG(self, obj): def updateSVG(self, obj):
"encapsulates a svg fragment into a transformation node" "encapsulates a svg fragment into a transformation node"
import Part
from draftlibs import fcgeo
if obj.Source: if obj.Source:
if obj.Source.Objects: if obj.Source.Objects:
svg = '' svg = ''
cp = ArchCommands.getCutVolume(obj.Source.Objects,obj.Source.Placement)
print "cp:",cp
sections = []
if cp:
cutvolume = cp[0].extrude(cp[1])
shapes = []
for o in obj.Source.Objects:
if cp:
shapes.append(o.Shape.cut(cutvolume))
sec = o.Shape.section(cp[0])
if sec.Edges:
sec = Part.Wire(fcgeo.sortEdges(sec.Edges))
sec = Part.Face(sec)
sections.append(sec)
else:
shapes.append(o.Shape)
if obj.RenderingMode == "Solid": if obj.RenderingMode == "Solid":
svg += self.renderVRM(obj.Source.Objects,obj.Source.Placement) svg += self.renderVRM(shapes,obj.Source.Placement)
else: else:
svg += self.renderOCC(obj.Source.Objects,obj.Source.Proxy.getNormal(obj.Source)) svg += self.renderOCC(shapes,obj.Source.Proxy.getNormal(obj.Source))
print "sections:",sections
for s in sections:
svg += self.renderSection(s,obj.Source.Placement)
result = '' result = ''
result += '<g id="' + obj.Name + '"' result += '<g id="' + obj.Name + '"'
result += ' transform="' result += ' transform="'
@ -193,27 +214,64 @@ class _ArchDrawingView:
return result return result
return '' return ''
def renderOCC(self,objs,direction): def renderOCC(self,shapes,direction):
"renders an SVG fragment with the OCC method" "renders an SVG fragment with the OCC method"
os = objs[:] shapes = shapes[:]
if os: if shapes:
sh = os.pop().Shape base = shape.pop()
for o in os: for sh in shapes:
sh = sh.fuse(o.Shape) base = base.fuse(sh)
result = Drawing.projectToSVG(sh,fcvec.neg(direction)) result = Drawing.projectToSVG(base,fcvec.neg(direction))
if result: if result:
result = result.replace('stroke-width="0.35"','stroke-width="0.01 px"') result = result.replace('stroke-width="0.35"','stroke-width="0.01 px"')
return result return result
return '' return ''
def renderVRM(self,objs,placement): def renderVRM(self,shapes,placement):
"renders an SVG fragment with the ArchVRM method" "renders an SVG fragment with the ArchVRM method"
import ArchVRM import ArchVRM
render = ArchVRM.Renderer() render = ArchVRM.Renderer()
render.setWorkingPlane(FreeCAD.Placement(placement)) render.setWorkingPlane(FreeCAD.Placement(placement))
for o in objs: for s in shapes:
render.add(o) render.add(s)
svg = render.getSVG() svg = render.getSVG()
return svg return svg
def renderSection(self,shape,placement):
"renders a plane parallel to the section plane"
placement = FreeCAD.Placement(placement)
u = placement.Rotation.multVec(FreeCAD.Vector(1,0,0))
v = placement.Rotation.multVec(FreeCAD.Vector(0,1,0))
pts = []
for vt in shape.Vertexes:
vu = fcvec.project(vt.Point,u)
if vu.getAngle(u) > 1:
x = -vu.Length
else:
x = vu.Length
vv = fcvec.project(vt.Point,v)
if vv.getAngle(v) > 1:
y = -vv.Length
else:
y = vv.Length
pts.append([x,y])
svg ='<path '
svg += 'd="M '+ str(pts[0][0]) +' '+ str(pts[0][1]) + ' '
for p in pts[1:]:
svg += 'L '+ str(p[0]) +' '+ str(p[1]) + ' '
svg += 'z '
svg += '" '
svg += 'stroke="#000000" '
svg += 'stroke-width="0.02 px" '
svg += 'style="stroke-width:0.01;'
svg += 'stroke-miterlimit:1;'
svg += 'stroke-linejoin:round;'
svg += 'stroke-dasharray:none;'
svg += 'fill:#ffffff;'
svg += 'fill-rule: evenodd'
svg += '"/>\n'
return svg
FreeCADGui.addCommand('Arch_SectionPlane',_CommandSectionPlane()) FreeCADGui.addCommand('Arch_SectionPlane',_CommandSectionPlane())