Arch: improvements to section plane wireframe rendering
This commit is contained in:
parent
78cbe72dee
commit
bdc926c704
|
@ -262,6 +262,52 @@ def closeHole(shape):
|
|||
else:
|
||||
return solid
|
||||
|
||||
def getCutVolume(cutplane,shapes):
|
||||
"""getCutVolume(cutplane,shapes): returns a cut face and a cut volume
|
||||
from the given shapes and the given cutting plane"""
|
||||
import Part
|
||||
placement = FreeCAD.Placement(cutplane.Placement)
|
||||
# building boundbox
|
||||
bb = shapes[0].BoundBox
|
||||
for sh in shapes[1:]:
|
||||
bb.add(sh.BoundBox)
|
||||
bb.enlarge(1)
|
||||
um = vm = wm = 0
|
||||
ax = placement.Rotation.multVec(FreeCAD.Vector(0,0,1))
|
||||
u = placement.Rotation.multVec(FreeCAD.Vector(1,0,0))
|
||||
v = placement.Rotation.multVec(FreeCAD.Vector(0,1,0))
|
||||
if not bb.isCutPlane(placement.Base,ax):
|
||||
print "No objects are cut by the plane"
|
||||
return None,None
|
||||
else:
|
||||
corners = [FreeCAD.Vector(bb.XMin,bb.YMin,bb.ZMin),
|
||||
FreeCAD.Vector(bb.XMin,bb.YMax,bb.ZMin),
|
||||
FreeCAD.Vector(bb.XMax,bb.YMin,bb.ZMin),
|
||||
FreeCAD.Vector(bb.XMax,bb.YMax,bb.ZMin),
|
||||
FreeCAD.Vector(bb.XMin,bb.YMin,bb.ZMax),
|
||||
FreeCAD.Vector(bb.XMin,bb.YMax,bb.ZMax),
|
||||
FreeCAD.Vector(bb.XMax,bb.YMin,bb.ZMax),
|
||||
FreeCAD.Vector(bb.XMax,bb.YMax,bb.ZMax)]
|
||||
for c in corners:
|
||||
dv = c.sub(placement.Base)
|
||||
um1 = DraftVecUtils.project(dv,u).Length
|
||||
um = max(um,um1)
|
||||
vm1 = DraftVecUtils.project(dv,v).Length
|
||||
vm = max(vm,vm1)
|
||||
wm1 = DraftVecUtils.project(dv,ax).Length
|
||||
wm = max(wm,wm1)
|
||||
p1 = FreeCAD.Vector(-um,vm,0)
|
||||
p2 = FreeCAD.Vector(um,vm,0)
|
||||
p3 = FreeCAD.Vector(um,-vm,0)
|
||||
p4 = FreeCAD.Vector(-um,-vm,0)
|
||||
cutface = Part.makePolygon([p1,p2,p3,p4,p1])
|
||||
cutface = Part.Face(cutface)
|
||||
cutface.Placement = placement
|
||||
cutnormal = DraftVecUtils.scaleTo(ax,wm)
|
||||
cutvolume = cutface.extrude(cutnormal)
|
||||
return cutface,cutvolume
|
||||
|
||||
|
||||
def meshToShape(obj,mark=True):
|
||||
'''meshToShape(object,[mark]): turns a mesh into a shape, joining coplanar facets. If
|
||||
mark is True (default), non-solid objects will be marked in red'''
|
||||
|
|
|
@ -186,7 +186,7 @@ class _ArchDrawingView:
|
|||
obj.addProperty("App::PropertyEnumeration","RenderingMode","Drawing View","The rendering mode to use")
|
||||
obj.addProperty("App::PropertyFloat","LineWidth","Drawing View","The line width of the rendered objects")
|
||||
obj.RenderingMode = ["Solid","Wireframe"]
|
||||
obj.RenderingMode = "Solid"
|
||||
obj.RenderingMode = "Wireframe"
|
||||
obj.LineWidth = 0.35
|
||||
obj.Proxy = self
|
||||
self.Type = "DrawingView"
|
||||
|
@ -224,18 +224,33 @@ class _ArchDrawingView:
|
|||
|
||||
else:
|
||||
# render using the Drawing module
|
||||
import Drawing
|
||||
import Drawing, Part
|
||||
shapes = []
|
||||
p = FreeCAD.Placement(obj.Source.Placement)
|
||||
direction = p.Rotation.multVec(FreeCAD.Vector(0,0,1))
|
||||
for o in objs:
|
||||
if o.isDerivedFrom("Part::Feature"):
|
||||
shapes.append(o.Shape)
|
||||
if shapes:
|
||||
base = shapes.pop()
|
||||
for sh in shapes:
|
||||
base = base.fuse(sh)
|
||||
svgf = Drawing.projectToSVG(base,DraftVecUtils.neg(direction))
|
||||
shapes.extend(o.Shape.Solids)
|
||||
cutface,cutvolume = ArchCommands.getCutVolume(obj.Source.Shape.copy(),shapes)
|
||||
if cutvolume:
|
||||
nsh = []
|
||||
for sh in shapes:
|
||||
for sol in sh.Solids:
|
||||
c = sol.cut(cutvolume)
|
||||
nsh.append(c)
|
||||
shapes = nsh
|
||||
base = Part.makeCompound(shapes)
|
||||
#if shapes:
|
||||
# base = shapes.pop().copy()
|
||||
#for sh in shapes:
|
||||
# try:
|
||||
# base = base.fuse(sh)
|
||||
# except:
|
||||
# print "unable to fuse, passing..."
|
||||
svgf = Drawing.projectToSVG(base,direction)
|
||||
if svgf:
|
||||
svgf = svgf.replace('stroke-width="0.35"','stroke-width="' + str(linewidth) + 'px"')
|
||||
svgf = svgf.replace('stroke-width="1"','stroke-width="' + str(linewidth) + 'px"')
|
||||
svgf = svgf.replace('stroke-width:0.01','stroke-width:' + str(linewidth) + 'px')
|
||||
svg += svgf
|
||||
|
||||
|
|
|
@ -228,42 +228,11 @@ class Renderer:
|
|||
if DEBUG: print "No objects to make sections"
|
||||
else:
|
||||
fill = (1.0,1.0,1.0,1.0)
|
||||
placement = FreeCAD.Placement(cutplane.Placement)
|
||||
|
||||
# building boundbox
|
||||
bb = self.shapes[0][0].BoundBox
|
||||
for sh in self.shapes[1:]:
|
||||
bb.add(sh[0].BoundBox)
|
||||
bb.enlarge(1)
|
||||
um = vm = wm = 0
|
||||
if not bb.isCutPlane(placement.Base,self.wp.axis):
|
||||
if DEBUG: print "No objects are cut by the plane"
|
||||
else:
|
||||
corners = [FreeCAD.Vector(bb.XMin,bb.YMin,bb.ZMin),
|
||||
FreeCAD.Vector(bb.XMin,bb.YMax,bb.ZMin),
|
||||
FreeCAD.Vector(bb.XMax,bb.YMin,bb.ZMin),
|
||||
FreeCAD.Vector(bb.XMax,bb.YMax,bb.ZMin),
|
||||
FreeCAD.Vector(bb.XMin,bb.YMin,bb.ZMax),
|
||||
FreeCAD.Vector(bb.XMin,bb.YMax,bb.ZMax),
|
||||
FreeCAD.Vector(bb.XMax,bb.YMin,bb.ZMax),
|
||||
FreeCAD.Vector(bb.XMax,bb.YMax,bb.ZMax)]
|
||||
for c in corners:
|
||||
dv = c.sub(placement.Base)
|
||||
um1 = DraftVecUtils.project(dv,self.wp.u).Length
|
||||
um = max(um,um1)
|
||||
vm1 = DraftVecUtils.project(dv,self.wp.v).Length
|
||||
vm = max(vm,vm1)
|
||||
wm1 = DraftVecUtils.project(dv,self.wp.axis).Length
|
||||
wm = max(wm,wm1)
|
||||
p1 = FreeCAD.Vector(-um,vm,0)
|
||||
p2 = FreeCAD.Vector(um,vm,0)
|
||||
p3 = FreeCAD.Vector(um,-vm,0)
|
||||
p4 = FreeCAD.Vector(-um,-vm,0)
|
||||
cutface = Part.makePolygon([p1,p2,p3,p4,p1])
|
||||
cutface = Part.Face(cutface)
|
||||
cutface.Placement = placement
|
||||
cutnormal = DraftVecUtils.scaleTo(self.wp.axis,wm)
|
||||
cutvolume = cutface.extrude(cutnormal)
|
||||
shps = []
|
||||
for sh in self.shapes:
|
||||
shps.append(sh[0])
|
||||
cutface,cutvolume = ArchCommands.getCutVolume(cutplane,shps)
|
||||
if cutface and cutvolume:
|
||||
shapes = []
|
||||
faces = []
|
||||
sections = []
|
||||
|
|
Loading…
Reference in New Issue
Block a user