Arch: small bugfixes in Drawing projection stuff
This commit is contained in:
parent
fedbd2fc2e
commit
d0288deabb
|
@ -253,13 +253,145 @@ class _ArchDrawingView:
|
|||
obj.FontSize = 12
|
||||
|
||||
def execute(self, obj):
|
||||
if obj.Source:
|
||||
obj.ViewResult = self.updateSVG(obj)
|
||||
if hasattr(obj,"Source"):
|
||||
if obj.Source:
|
||||
if not hasattr(self,"svg"):
|
||||
self.onChanged(obj,"Source")
|
||||
else:
|
||||
if not self.svg:
|
||||
self.onChanged(obj,"Source")
|
||||
if not hasattr(self,"svg"):
|
||||
return ''
|
||||
linewidth = obj.LineWidth/obj.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 = self.svg.replace('LWPlaceholder', str(linewidth) + 'px')
|
||||
svg = svg.replace('SWPlaceholder', str(linewidth*st) + 'px')
|
||||
svg = svg.replace('DAPlaceholder', str(da))
|
||||
if hasattr(self,"spaces"):
|
||||
if round(self.direction.getAngle(FreeCAD.Vector(0,0,1)),Draft.precision()) in [0,round(math.pi,Draft.precision())]:
|
||||
for s in self.spaces:
|
||||
svg += Draft.getSVG(s,scale=obj.Scale,fontsize=obj.FontSize.Value,direction=self.direction)
|
||||
result = ''
|
||||
result += '<g id="' + obj.Name + '"'
|
||||
result += ' transform="'
|
||||
result += 'rotate('+str(obj.Rotation)+','+str(obj.X)+','+str(obj.Y)+') '
|
||||
result += 'translate('+str(obj.X)+','+str(obj.Y)+') '
|
||||
result += 'scale('+str(obj.Scale)+','+str(obj.Scale)+')'
|
||||
result += '">\n'
|
||||
result += svg
|
||||
result += '</g>\n'
|
||||
# print "complete node:",result
|
||||
obj.ViewResult = result
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
if prop in ["Source","RenderingMode"]:
|
||||
self.buildSVG(obj)
|
||||
obj.ViewResult = self.updateSVG(obj)
|
||||
if prop in ["Source","RenderingMode","ShowCut"]:
|
||||
import Part, DraftGeomUtils
|
||||
if hasattr(obj,"Source"):
|
||||
if obj.Source:
|
||||
if obj.Source.Objects:
|
||||
objs = Draft.getGroupContents(obj.Source.Objects,walls=True)
|
||||
objs = Draft.removeHidden(objs)
|
||||
# separate spaces
|
||||
self.spaces = []
|
||||
os = []
|
||||
for o in objs:
|
||||
if Draft.getType(o) == "Space":
|
||||
self.spaces.append(o)
|
||||
else:
|
||||
os.append(o)
|
||||
objs = os
|
||||
self.svg = ''
|
||||
|
||||
# generating SVG
|
||||
if obj.RenderingMode == "Solid":
|
||||
# render using the Arch Vector Renderer
|
||||
import ArchVRM
|
||||
render = ArchVRM.Renderer()
|
||||
render.setWorkingPlane(obj.Source.Placement)
|
||||
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")
|
||||
if hasattr(obj,"ShowCut"):
|
||||
if obj.ShowCut:
|
||||
self.svg += render.getHiddenSVG(linewidth="LWPlaceholder")
|
||||
# print render.info()
|
||||
|
||||
else:
|
||||
# render using the Drawing module
|
||||
import Drawing, Part
|
||||
shapes = []
|
||||
hshapes = []
|
||||
sshapes = []
|
||||
p = FreeCAD.Placement(obj.Source.Placement)
|
||||
self.direction = p.Rotation.multVec(FreeCAD.Vector(0,0,1))
|
||||
for o in objs:
|
||||
if o.isDerivedFrom("Part::Feature"):
|
||||
if o.Shape.isNull():
|
||||
pass
|
||||
#FreeCAD.Console.PrintWarning(translate("Arch","Skipping empty object: ")+o.Name)
|
||||
elif o.Shape.isValid():
|
||||
if hasattr(obj.Source,"OnlySolids"):
|
||||
if obj.Source.OnlySolids:
|
||||
shapes.extend(o.Shape.Solids)
|
||||
else:
|
||||
shapes.append(o.Shape)
|
||||
else:
|
||||
shapes.extend(o.Shape.Solids)
|
||||
else:
|
||||
FreeCAD.Console.PrintWarning(translate("Arch","Skipping invalid object: ")+o.Name)
|
||||
cutface,cutvolume,invcutvolume = ArchCommands.getCutVolume(obj.Source.Shape.copy(),shapes)
|
||||
if cutvolume:
|
||||
nsh = []
|
||||
for sh in shapes:
|
||||
for sol in sh.Solids:
|
||||
if sol.Volume < 0:
|
||||
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"):
|
||||
if obj.ShowCut:
|
||||
c = sol.cut(invcutvolume)
|
||||
hshapes.append(c)
|
||||
shapes = nsh
|
||||
if shapes:
|
||||
self.shapes = shapes
|
||||
self.baseshape = Part.makeCompound(shapes)
|
||||
svgf = Drawing.projectToSVG(self.baseshape,self.direction)
|
||||
if svgf:
|
||||
svgf = svgf.replace('stroke-width="0.35"','stroke-width="LWPlaceholder"')
|
||||
svgf = svgf.replace('stroke-width="1"','stroke-width="LWPlaceholder"')
|
||||
svgf = svgf.replace('stroke-width:0.01','stroke-width:LWPlaceholder')
|
||||
self.svg += svgf
|
||||
if hshapes:
|
||||
hshapes = Part.makeCompound(hshapes)
|
||||
svgh = Drawing.projectToSVG(hshapes,self.direction)
|
||||
if svgh:
|
||||
svgh = svgh.replace('stroke-width="0.35"','stroke-width="LWPlaceholder"')
|
||||
svgh = svgh.replace('stroke-width="1"','stroke-width="LWPlaceholder"')
|
||||
svgh = svgh.replace('stroke-width:0.01','stroke-width:LWPlaceholder')
|
||||
svgh = svgh.replace('fill="none"','fill="none"\nstroke-dasharray="DAPlaceholder"')
|
||||
self.svg += svgh
|
||||
if sshapes:
|
||||
sshapes = Part.makeCompound(sshapes)
|
||||
svgs = Drawing.projectToSVG(sshapes,self.direction)
|
||||
if svgs:
|
||||
svgs = svgs.replace('stroke-width="0.35"','stroke-width="SWPlaceholder"')
|
||||
svgs = svgs.replace('stroke-width="1"','stroke-width="SWPlaceholder"')
|
||||
svgs = svgs.replace('stroke-width:0.01','stroke-width:SWPlaceholder')
|
||||
self.svg += svgs
|
||||
|
||||
def __getstate__(self):
|
||||
return self.Type
|
||||
|
@ -296,142 +428,5 @@ class _ArchDrawingView:
|
|||
FreeCAD.Console.PrintMessage(translate("Arch","No shape has been computed yet, select wireframe rendering and render again"))
|
||||
return None
|
||||
|
||||
def buildSVG(self, obj,join=False):
|
||||
"creates a svg representation"
|
||||
import Part, DraftGeomUtils
|
||||
if hasattr(obj,"Source"):
|
||||
if obj.Source:
|
||||
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
|
||||
if obj.RenderingMode == "Solid":
|
||||
# render using the Arch Vector Renderer
|
||||
import ArchVRM
|
||||
render = ArchVRM.Renderer()
|
||||
render.setWorkingPlane(obj.Source.Placement)
|
||||
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")
|
||||
if hasattr(obj,"ShowCut"):
|
||||
if obj.ShowCut:
|
||||
self.svg += render.getHiddenSVG(linewidth="LWPlaceholder")
|
||||
# print render.info()
|
||||
|
||||
else:
|
||||
# render using the Drawing module
|
||||
import Drawing, Part
|
||||
shapes = []
|
||||
hshapes = []
|
||||
sshapes = []
|
||||
p = FreeCAD.Placement(obj.Source.Placement)
|
||||
self.direction = p.Rotation.multVec(FreeCAD.Vector(0,0,1))
|
||||
for o in objs:
|
||||
if o.isDerivedFrom("Part::Feature"):
|
||||
if o.Shape.isNull():
|
||||
pass
|
||||
#FreeCAD.Console.PrintWarning(translate("Arch","Skipping empty object: ")+o.Name)
|
||||
elif o.Shape.isValid():
|
||||
if hasattr(obj.Source,"OnlySolids"):
|
||||
if obj.Source.OnlySolids:
|
||||
shapes.extend(o.Shape.Solids)
|
||||
else:
|
||||
shapes.append(o.Shape)
|
||||
else:
|
||||
shapes.extend(o.Shape.Solids)
|
||||
else:
|
||||
FreeCAD.Console.PrintWarning(translate("Arch","Skipping invalid object: ")+o.Name)
|
||||
cutface,cutvolume,invcutvolume = ArchCommands.getCutVolume(obj.Source.Shape.copy(),shapes)
|
||||
if cutvolume:
|
||||
nsh = []
|
||||
for sh in shapes:
|
||||
for sol in sh.Solids:
|
||||
if sol.Volume < 0:
|
||||
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"):
|
||||
if obj.ShowCut:
|
||||
c = sol.cut(invcutvolume)
|
||||
hshapes.append(c)
|
||||
shapes = nsh
|
||||
if shapes:
|
||||
self.shapes = shapes
|
||||
self.baseshape = Part.makeCompound(shapes)
|
||||
svgf = Drawing.projectToSVG(self.baseshape,self.direction)
|
||||
if svgf:
|
||||
svgf = svgf.replace('stroke-width="0.35"','stroke-width="LWPlaceholder"')
|
||||
svgf = svgf.replace('stroke-width="1"','stroke-width="LWPlaceholder"')
|
||||
svgf = svgf.replace('stroke-width:0.01','stroke-width:LWPlaceholder')
|
||||
self.svg += svgf
|
||||
if hshapes:
|
||||
hshapes = Part.makeCompound(hshapes)
|
||||
svgh = Drawing.projectToSVG(hshapes,self.direction)
|
||||
if svgh:
|
||||
svgh = svgh.replace('stroke-width="0.35"','stroke-width="LWPlaceholder"')
|
||||
svgh = svgh.replace('stroke-width="1"','stroke-width="LWPlaceholder"')
|
||||
svgh = svgh.replace('stroke-width:0.01','stroke-width:LWPlaceholder')
|
||||
svgh = svgh.replace('fill="none"','fill="none"\nstroke-dasharray="0.09,0.05"')
|
||||
self.svg += svgh
|
||||
if sshapes:
|
||||
sshapes = Part.makeCompound(sshapes)
|
||||
svgs = Drawing.projectToSVG(sshapes,self.direction)
|
||||
if svgs:
|
||||
svgs = svgs.replace('stroke-width="0.35"','stroke-width="SWPlaceholder"')
|
||||
svgs = svgs.replace('stroke-width="1"','stroke-width="SWPlaceholder"')
|
||||
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"):
|
||||
self.buildSVG(obj)
|
||||
else:
|
||||
if not self.svg:
|
||||
self.buildSVG(obj)
|
||||
if not hasattr(self,"svg"):
|
||||
return ''
|
||||
linewidth = obj.LineWidth/obj.Scale
|
||||
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')
|
||||
|
||||
result = ''
|
||||
result += '<g id="' + obj.Name + '"'
|
||||
result += ' transform="'
|
||||
result += 'rotate('+str(obj.Rotation)+','+str(obj.X)+','+str(obj.Y)+') '
|
||||
result += 'translate('+str(obj.X)+','+str(obj.Y)+') '
|
||||
result += 'scale('+str(obj.Scale)+','+str(obj.Scale)+')'
|
||||
result += '">\n'
|
||||
result += svg
|
||||
result += '</g>\n'
|
||||
# print "complete node:",result
|
||||
return result
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
FreeCADGui.addCommand('Arch_SectionPlane',_CommandSectionPlane())
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -284,6 +284,65 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Preferred</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Hidden geomety pattern</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::PrefLineEdit" name="lineEdit">
|
||||
<property name="toolTip">
|
||||
<string>This is the SVG stroke-dasharray property to apply to projections of hidden objects.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>30, 10</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>archHiddenPattern</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Arch</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -310,6 +369,11 @@
|
|||
<extends>QCheckBox</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefDoubleSpinBox</class>
|
||||
<extends>QDoubleSpinBox</extends>
|
||||
|
|
|
@ -1774,7 +1774,10 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
svg += 'font-family:'+ fontname +'" '
|
||||
svg += 'transform="rotate('+str(math.degrees(angle))
|
||||
svg += ','+ str(base.x) + ',' + str(base.y) + ') '
|
||||
svg += 'translate(' + str(base.x) + ',' + str(base.y) + ') '
|
||||
if flip:
|
||||
svg += 'translate(' + str(base.x) + ',' + str(base.y) + ') '
|
||||
else:
|
||||
svg += 'translate(' + str(base.x) + ',' + str(-base.y) + ') '
|
||||
#svg += 'scale('+str(tmod/2000)+',-'+str(tmod/2000)+') '
|
||||
if flip:
|
||||
svg += 'scale(1,-1) '
|
||||
|
@ -1818,7 +1821,10 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
p3 = getProj(prx.p3)
|
||||
p4 = getProj(prx.p4)
|
||||
tbase = getProj(prx.tbase)
|
||||
angle = -DraftVecUtils.angle(p3.sub(p2))
|
||||
r = prx.textpos.rotation.getValue().getValue()
|
||||
rv = FreeCAD.Rotation(r[0],r[1],r[2],r[3]).multVec(FreeCAD.Vector(1,0,0))
|
||||
angle = -DraftVecUtils.angle(getProj(rv))
|
||||
#angle = -DraftVecUtils.angle(p3.sub(p2))
|
||||
|
||||
# drawing lines
|
||||
svg = '<path '
|
||||
|
@ -1826,8 +1832,8 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
tangle = angle
|
||||
if tangle > math.pi/2:
|
||||
tangle = tangle-math.pi
|
||||
elif (tangle <= -math.pi/2) or (tangle > math.pi/2):
|
||||
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))
|
||||
svg += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
|
||||
svg += 'L '+str(p2.x)+' '+str(p2.y)+' '
|
||||
|
@ -1958,11 +1964,15 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
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())
|
||||
scale = obj.ViewObject.FirstLine.Value/obj.ViewObject.FontSize.Value
|
||||
f1 = fontsize*scale
|
||||
p2 = FreeCAD.Vector(obj.ViewObject.Proxy.coords.translation.getValue().getValue())
|
||||
p1 = p2.add(FreeCAD.Vector(obj.ViewObject.Proxy.header.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)
|
||||
svg += getText(c,f1,n,a,getProj(p1),t1,l,j,flip=False)
|
||||
if t2:
|
||||
svg += getText(c,fontsize,n,a,getProj(p2),t2,l,j,flip=False)
|
||||
|
||||
elif obj.isDerivedFrom('Part::Feature'):
|
||||
if obj.Shape.isNull():
|
||||
|
|
Loading…
Reference in New Issue
Block a user