Arch: Misc improvements to section planes
This commit is contained in:
parent
92382edbc9
commit
a9b5970512
|
@ -107,7 +107,8 @@ class _SectionPlane:
|
|||
|
||||
def execute(self,obj):
|
||||
import Part
|
||||
l = obj.ViewObject.DisplaySize.Value
|
||||
l = obj.ViewObject.DisplayLength.Value
|
||||
h = obj.ViewObject.DisplayHeight.Value
|
||||
p = Part.makePlane(l,l,Vector(l/2,-l/2,0),Vector(0,0,-1))
|
||||
# make sure the normal direction is pointing outwards, you never know what OCC will decide...
|
||||
if p.normalAt(0,0).getAngle(obj.Placement.Rotation.multVec(FreeCAD.Vector(0,0,1))) > 1:
|
||||
|
@ -131,11 +132,15 @@ class _SectionPlane:
|
|||
class _ViewProviderSectionPlane:
|
||||
"A View Provider for Section Planes"
|
||||
def __init__(self,vobj):
|
||||
vobj.addProperty("App::PropertyLength","DisplaySize","Arch",translate("Arch","The display size of this section plane"))
|
||||
vobj.addProperty("App::PropertyLength","DisplayLength","Arch",translate("Arch","The display length of this section plane"))
|
||||
vobj.addProperty("App::PropertyLength","DisplayHeight","Arch",translate("Arch","The display height of this section plane"))
|
||||
vobj.addProperty("App::PropertyLength","ArrowSize","Arch",translate("Arch","The size of the arrows of this section plane"))
|
||||
vobj.addProperty("App::PropertyPercent","Transparency","Base","")
|
||||
vobj.addProperty("App::PropertyFloat","LineWidth","Base","")
|
||||
vobj.addProperty("App::PropertyColor","LineColor","Base","")
|
||||
vobj.DisplaySize = 1
|
||||
vobj.DisplayLength = 1
|
||||
vobj.DisplayHeight = 1
|
||||
vobj.ArrowSize = 1
|
||||
vobj.Transparency = 85
|
||||
vobj.LineWidth = 1
|
||||
vobj.LineColor = (0.0,0.0,0.4,1.0)
|
||||
|
@ -174,7 +179,7 @@ class _ViewProviderSectionPlane:
|
|||
sep.addChild(fsep)
|
||||
sep.addChild(psep)
|
||||
vobj.addDisplayMode(sep,"Default")
|
||||
self.onChanged(vobj,"DisplaySize")
|
||||
self.onChanged(vobj,"DisplayLength")
|
||||
self.onChanged(vobj,"LineColor")
|
||||
self.onChanged(vobj,"Transparency")
|
||||
|
||||
|
@ -189,7 +194,7 @@ class _ViewProviderSectionPlane:
|
|||
|
||||
def updateData(self,obj,prop):
|
||||
if prop in ["Placement"]:
|
||||
self.onChanged(obj.ViewObject,"DisplaySize")
|
||||
self.onChanged(obj.ViewObject,"DisplayLength")
|
||||
return
|
||||
|
||||
def onChanged(self,vobj,prop):
|
||||
|
@ -200,12 +205,13 @@ class _ViewProviderSectionPlane:
|
|||
elif prop == "Transparency":
|
||||
if hasattr(vobj,"Transparency"):
|
||||
self.mat2.transparency.setValue(vobj.Transparency/100.0)
|
||||
elif prop == "DisplaySize":
|
||||
hd = vobj.DisplaySize.Value/2
|
||||
elif prop in ["DisplayLength","DisplayHeight","ArrowSize"]:
|
||||
ld = vobj.DisplayLength.Value/2
|
||||
hd = vobj.DisplayHeight.Value/2
|
||||
verts = []
|
||||
fverts = []
|
||||
for v in [[-hd,-hd],[hd,-hd],[hd,hd],[-hd,hd]]:
|
||||
l1 = hd/3
|
||||
for v in [[-ld,-hd],[ld,-hd],[ld,hd],[-ld,hd]]:
|
||||
l1 = vobj.ArrowSize.Value if vobj.ArrowSize.Value > 0 else 0.1
|
||||
l2 = l1/3
|
||||
pl = FreeCAD.Placement(vobj.Object.Placement)
|
||||
p1 = pl.multVec(Vector(v[0],v[1],0))
|
||||
|
@ -234,15 +240,17 @@ class _ViewProviderSectionPlane:
|
|||
class _ArchDrawingView:
|
||||
def __init__(self, obj):
|
||||
obj.addProperty("App::PropertyLink","Source","Base","The linked object")
|
||||
obj.addProperty("App::PropertyEnumeration","RenderingMode","Drawing View","The rendering mode to use")
|
||||
obj.addProperty("App::PropertyBool","ShowCut","Drawing View","If cut geometry is shown or not")
|
||||
obj.addProperty("App::PropertyFloat","LineWidth","Drawing View","The line width of the rendered objects")
|
||||
obj.addProperty("App::PropertyEnumeration","RenderingMode","Drawing view","The rendering mode to use")
|
||||
obj.addProperty("App::PropertyBool","ShowCut","Drawing view","If cut geometry is shown 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.RenderingMode = ["Solid","Wireframe"]
|
||||
obj.RenderingMode = "Wireframe"
|
||||
obj.LineWidth = 0.35
|
||||
obj.ShowCut = False
|
||||
obj.Proxy = self
|
||||
self.Type = "ArchSectionView"
|
||||
obj.FontSize = 12
|
||||
|
||||
def execute(self, obj):
|
||||
if obj.Source:
|
||||
|
@ -296,6 +304,15 @@ class _ArchDrawingView:
|
|||
if obj.Source.Objects:
|
||||
objs = Draft.getGroupContents(obj.Source.Objects,walls=True)
|
||||
objs = Draft.removeHidden(objs)
|
||||
# separate spaces
|
||||
spaces = []
|
||||
os = []
|
||||
for o in objs:
|
||||
if Draft.getType(o) == "Space":
|
||||
spaces.append(o)
|
||||
else:
|
||||
os.append(o)
|
||||
objs = os
|
||||
self.svg = ''
|
||||
|
||||
# generating SVG
|
||||
|
@ -348,6 +365,11 @@ class _ArchDrawingView:
|
|||
sol.reverse()
|
||||
c = sol.cut(cutvolume)
|
||||
s = sol.section(cutface)
|
||||
try:
|
||||
s = Part.Wire(s.Edges)
|
||||
s = Part.Face(s)
|
||||
except:
|
||||
pass
|
||||
nsh.extend(c.Solids)
|
||||
sshapes.append(s)
|
||||
if hasattr(obj,"ShowCut"):
|
||||
|
@ -374,15 +396,7 @@ class _ArchDrawingView:
|
|||
svgh = svgh.replace('fill="none"','fill="none"\nstroke-dasharray="0.09,0.05"')
|
||||
self.svg += svgh
|
||||
if sshapes:
|
||||
edges = []
|
||||
for s in sshapes:
|
||||
edges.extend(s.Edges)
|
||||
wires = DraftGeomUtils.findWires(edges)
|
||||
faces = []
|
||||
for w in wires:
|
||||
if (w.ShapeType == "Wire") and w.isClosed():
|
||||
faces.append(Part.Face(w))
|
||||
sshapes = Part.makeCompound(faces)
|
||||
sshapes = Part.makeCompound(sshapes)
|
||||
svgs = Drawing.projectToSVG(sshapes,self.direction)
|
||||
if svgs:
|
||||
svgs = svgs.replace('stroke-width="0.35"','stroke-width="SWPlaceholder"')
|
||||
|
@ -390,6 +404,9 @@ class _ArchDrawingView:
|
|||
svgs = svgs.replace('stroke-width:0.01','stroke-width:SWPlaceholder')
|
||||
self.svg += svgs
|
||||
|
||||
for s in spaces:
|
||||
self.svg += Draft.getSVG(s,scale=1/obj.Scale,fontsize=obj.FontSize,direction=self.direction)
|
||||
|
||||
def updateSVG(self, obj):
|
||||
"Formats and places the calculated svg stuff on the page"
|
||||
if not hasattr(self,"svg"):
|
||||
|
@ -400,9 +417,7 @@ class _ArchDrawingView:
|
|||
if not hasattr(self,"svg"):
|
||||
return ''
|
||||
linewidth = obj.LineWidth/obj.Scale
|
||||
st = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetFloat("CutLineThickness")
|
||||
if not st:
|
||||
st = 2
|
||||
st = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetFloat("CutLineThickness",2)
|
||||
svg = self.svg.replace('LWPlaceholder', str(linewidth) + 'px')
|
||||
svg = svg.replace('SWPlaceholder', str(linewidth*st) + 'px')
|
||||
|
||||
|
|
|
@ -254,7 +254,7 @@ class Renderer:
|
|||
shapes.append([c]+sh[1:])
|
||||
for f in c.Faces:
|
||||
faces.append([f]+sh[1:])
|
||||
print "iscoplanar:",f.Vertexes[0].Point,f.normalAt(0,0),cutface.Vertexes[0].Point,cutface.normalAt(0,0)
|
||||
#print "iscoplanar:",f.Vertexes[0].Point,f.normalAt(0,0),cutface.Vertexes[0].Point,cutface.normalAt(0,0)
|
||||
if DraftGeomUtils.isCoplanar([f,cutface]):
|
||||
print "COPLANAR"
|
||||
sections.append([f,fill])
|
||||
|
|
|
@ -1758,7 +1758,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
print "getSVG: arrow type not implemented"
|
||||
return svg
|
||||
|
||||
def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="center"):
|
||||
def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="center",flip=True):
|
||||
if not isinstance(text,list):
|
||||
text = text.split("\n")
|
||||
if align.lower() == "center":
|
||||
|
@ -1776,7 +1776,10 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
svg += ','+ str(base.x) + ',' + str(base.y) + ') '
|
||||
svg += 'translate(' + str(base.x) + ',' + str(base.y) + ') '
|
||||
#svg += 'scale('+str(tmod/2000)+',-'+str(tmod/2000)+') '
|
||||
svg += 'scale(1,-1) '
|
||||
if flip:
|
||||
svg += 'scale(1,-1) '
|
||||
else:
|
||||
svg += 'scale(1,1) '
|
||||
svg += '" freecad:skip="1"'
|
||||
svg += '>\n'
|
||||
if len(text) == 1:
|
||||
|
@ -1814,7 +1817,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
p2 = getProj(prx.p2)
|
||||
p3 = getProj(prx.p3)
|
||||
p4 = getProj(prx.p4)
|
||||
tbase = p2.add(p3.sub(p2).multiply(0.5))
|
||||
tbase = getProj(prx.tbase)
|
||||
angle = -DraftVecUtils.angle(p3.sub(p2))
|
||||
|
||||
# drawing lines
|
||||
|
@ -1825,7 +1828,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
tangle = tangle-math.pi
|
||||
elif (tangle <= -math.pi/2) or (tangle > math.pi/2):
|
||||
tangle = tangle+math.pi
|
||||
tbase = tbase.add(DraftVecUtils.rotate(Vector(0,2/scale,0),tangle))
|
||||
#tbase = tbase.add(DraftVecUtils.rotate(Vector(0,2/scale,0),tangle))
|
||||
svg += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
|
||||
svg += 'L '+str(p2.x)+' '+str(p2.y)+' '
|
||||
svg += 'L '+str(p3.x)+' '+str(p3.y)+' '
|
||||
|
@ -1948,6 +1951,19 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
svg += '</text>\n'
|
||||
n += 1
|
||||
|
||||
elif getType(obj) == "Space":
|
||||
"returns an SVG fragment for the text of a space"
|
||||
c = getrgb(obj.ViewObject.TextColor)
|
||||
n = obj.ViewObject.FontName
|
||||
a = 0
|
||||
t1 = obj.ViewObject.Proxy.text1.string.getValues()
|
||||
t2 = obj.ViewObject.Proxy.text2.string.getValues()
|
||||
t = t1 + t2
|
||||
p = FreeCAD.Vector(obj.ViewObject.Proxy.coords.translation.getValue().getValue())
|
||||
l = obj.ViewObject.LineSpacing/2
|
||||
j = obj.ViewObject.TextAlign
|
||||
svg += getText(c,fontsize,n,a,getProj(p),t,l,j,flip=False)
|
||||
|
||||
elif obj.isDerivedFrom('Part::Feature'):
|
||||
if obj.Shape.isNull():
|
||||
return ''
|
||||
|
@ -3244,11 +3260,11 @@ class _ViewProviderDimension(_ViewProviderDraft):
|
|||
m = ["2D","3D"][getParam("dimstyle",0)]
|
||||
if m== "3D":
|
||||
offset = offset.negative()
|
||||
tbase = (self.p2.add((self.p3.sub(self.p2).multiply(0.5)))).add(offset)
|
||||
self.tbase = (self.p2.add((self.p3.sub(self.p2).multiply(0.5)))).add(offset)
|
||||
if hasattr(obj.ViewObject,"TextPosition"):
|
||||
if not DraftVecUtils.isNull(obj.ViewObject.TextPosition):
|
||||
tbase = obj.ViewObject.TextPosition
|
||||
self.textpos.translation.setValue([tbase.x,tbase.y,tbase.z])
|
||||
self.tbase = obj.ViewObject.TextPosition
|
||||
self.textpos.translation.setValue([self.tbase.x,self.tbase.y,self.tbase.z])
|
||||
self.textpos.rotation = coin.SbRotation(rot1[0],rot1[1],rot1[2],rot1[3])
|
||||
su = True
|
||||
if hasattr(obj.ViewObject,"ShowUnit"):
|
||||
|
|
|
@ -906,7 +906,7 @@ def offset(edge,vector):
|
|||
elif geomType(edge) == "Circle":
|
||||
rad = edge.Vertexes[0].Point.sub(edge.Curve.Center)
|
||||
newrad = Vector.add(rad,vector).Length
|
||||
return Part.Circle(edge.Curve.Center,edge.Curve.Axis,newrad).toShape()
|
||||
return Part.Circle(edge.Curve.Center,NORM,newrad).toShape()
|
||||
else:
|
||||
return None
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user