From ea0c7694cd21868b46ae81acff222fdbd01bb7ac Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Fri, 19 Apr 2019 18:20:33 -0300 Subject: [PATCH] Arch/TechDraw: TD Arch views now have a 'fillSpaces' property to show Arch spaces as color-filled areas --- src/Mod/Arch/ArchSectionPlane.py | 11 ++++++---- src/Mod/Arch/ArchSpace.py | 29 ++++++++++++++------------- src/Mod/Draft/getSVG.py | 25 ++++++++++++++++++----- src/Mod/TechDraw/App/DrawViewArch.cpp | 4 +++- src/Mod/TechDraw/App/DrawViewArch.h | 1 + 5 files changed, 46 insertions(+), 24 deletions(-) diff --git a/src/Mod/Arch/ArchSectionPlane.py b/src/Mod/Arch/ArchSectionPlane.py index 076b123380..5c89227ba4 100644 --- a/src/Mod/Arch/ArchSectionPlane.py +++ b/src/Mod/Arch/ArchSectionPlane.py @@ -180,10 +180,10 @@ def getFillForObject(o, defaultFill, section): return defaultFill -def getSVG(section, renderMode="Wireframe", allOn=False, showHidden=False, scale=1, rotation=0, linewidth=1, lineColor=(0.0,0.0,0.0), fontsize=1, showFill=False, fillColor=(0.8,0.8,0.8), techdraw=False): +def getSVG(section, renderMode="Wireframe", allOn=False, showHidden=False, scale=1, rotation=0, linewidth=1, lineColor=(0.0,0.0,0.0), fontsize=1, showFill=False, fillColor=(0.8,0.8,0.8), techdraw=False,fillSpaces=False): """getSVG(section, [renderMode, allOn, showHidden, scale, rotation, - linewidth, lineColor, fontsize, showFill, fillColor, techdraw]): + linewidth, lineColor, fontsize, showFill, fillColor, techdraw, fillSpaces]): returns an SVG fragment from an Arch section plane. If allOn is True, all cut objects are shown, regardless if they are visible or not. @@ -193,6 +193,7 @@ def getSVG(section, renderMode="Wireframe", allOn=False, showHidden=False, scale lineColor -- Color of lines for the renderMode "Wireframe". fillColor -- If showFill is True and renderMode is "Wireframe", the cut areas are filled with fillColor. + fillSpaces - If True, shows space objects as filled surfaces """ if not section.Objects: @@ -251,6 +252,8 @@ def getSVG(section, renderMode="Wireframe", allOn=False, showHidden=False, scale svgcache = None if section.Proxy.svgcache[3] != showFill: svgcache = None + if section.Proxy.svgcache[4] != fillSpaces: + svgcache = None # generating SVG if renderMode in ["Solid",1]: @@ -327,7 +330,7 @@ def getSVG(section, renderMode="Wireframe", allOn=False, showHidden=False, scale sshapes, direction, hStyle=style, h0Style=style, h1Style=style, vStyle=style, v0Style=style, v1Style=style) - section.Proxy.svgcache = [svgcache,renderMode,showHidden,showFill] + section.Proxy.svgcache = [svgcache,renderMode,showHidden,showFill,fillSpaces] svgcache = svgcache.replace("SVGLINECOLOR",svgLineColor) svgcache = svgcache.replace("SVGLINEWIDTH",svgLineWidth) svgcache = svgcache.replace("SVGHIDDENPATTERN",svgHiddenPattern) @@ -353,7 +356,7 @@ def getSVG(section, renderMode="Wireframe", allOn=False, showHidden=False, scale for s in spaces: svg += Draft.getSVG(s, scale=scale, linewidth=svgSymbolLineWidth, fontsize=fontsize, direction=direction, color=lineColor, - techdraw=techdraw, rotation=rotation) + techdraw=techdraw, rotation=rotation, fillSpaces=fillSpaces) if not techdraw: svg += '' diff --git a/src/Mod/Arch/ArchSpace.py b/src/Mod/Arch/ArchSpace.py index b4f6e7ae2b..8d709a64bf 100644 --- a/src/Mod/Arch/ArchSpace.py +++ b/src/Mod/Arch/ArchSpace.py @@ -429,7 +429,7 @@ class _Space(ArchComponent.Component): print("Arch: error computing space boundary") - def getArea(self,obj): + def getArea(self,obj,notouch=False): "returns the horizontal area at the center of the space" @@ -444,23 +444,24 @@ class _Space(ArchComponent.Component): e = sh.section(cutplane) e = Part.__sortEdges__(e.Edges) w = Part.Wire(e) - f = Part.Face(w) + self.face = Part.Face(w) except Part.OCCError: return 0 else: - if hasattr(obj,"PerimeterLength"): - if w.Length != obj.PerimeterLength.Value: - obj.PerimeterLength = w.Length - if hasattr(obj,"VerticalArea"): - a = 0 - for f in sh.Faces: - ang = f.normalAt(0,0).getAngle(FreeCAD.Vector(0,0,1)) - if (ang > 1.57) and (ang < 1.571): - a += f.Area - if a != obj.VerticalArea.Value: - obj.VerticalArea = a + if not notouch: + if hasattr(obj,"PerimeterLength"): + if w.Length != obj.PerimeterLength.Value: + obj.PerimeterLength = w.Length + if hasattr(obj,"VerticalArea"): + a = 0 + for f in sh.Faces: + ang = f.normalAt(0,0).getAngle(FreeCAD.Vector(0,0,1)) + if (ang > 1.57) and (ang < 1.571): + a += f.Area + if a != obj.VerticalArea.Value: + obj.VerticalArea = a #print "area of ",obj.Label," : ",f.Area - return f.Area + return self.face.Area class _ViewProviderSpace(ArchComponent.ViewProviderComponent): diff --git a/src/Mod/Draft/getSVG.py b/src/Mod/Draft/getSVG.py index 2f9b802c53..43589c0631 100644 --- a/src/Mod/Draft/getSVG.py +++ b/src/Mod/Draft/getSVG.py @@ -68,7 +68,7 @@ def getPattern(pat): return '' -def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direction=None,linestyle=None,color=None,linespacing=None,techdraw=False,rotation=0): +def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direction=None,linestyle=None,color=None,linespacing=None,techdraw=False,rotation=0,fillSpaces=False): '''getSVG(object,[scale], [linewidth],[fontsize],[fillstyle],[direction],[linestyle],[color],[linespacing]): returns a string containing a SVG representation of the given object, with the given linewidth and fontsize (used if the given object contains @@ -732,6 +732,19 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct if not obj.ViewObject: print ("export of spaces to SVG is only available in GUI mode") else: + if fillSpaces: + if hasattr(obj,"Proxy"): + if not hasattr(obj.Proxy,"face"): + obj.Proxy.getArea(obj,notouch=True) + if hasattr(obj.Proxy,"face"): + # setting fill + if gui: + fill = getrgb(obj.ViewObject.ShapeColor,testbw=False) + fill_opacity = 1 - (obj.ViewObject.Transparency / 100.0) + else: + fill = "#888888" + lstyle = getLineStyle(linestyle, scale) + svg += getPath(wires=[obj.Proxy.face.OuterWire]) c = getrgb(obj.ViewObject.TextColor) n = obj.ViewObject.FontName a = 0 @@ -741,16 +754,18 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct t2 = obj.ViewObject.Proxy.text2.string.getValues() scale = obj.ViewObject.FirstLine.Value/obj.ViewObject.FontSize.Value f1 = fontsize*scale - p2 = FreeCAD.Vector(obj.ViewObject.Proxy.coords.translation.getValue().getValue()) + p2 = obj.Placement.multVec(FreeCAD.Vector(obj.ViewObject.Proxy.coords.translation.getValue().getValue())) lspc = FreeCAD.Vector(obj.ViewObject.Proxy.header.translation.getValue().getValue()) p1 = p2.add(lspc) j = obj.ViewObject.TextAlign - svg += getText(c,f1,n,a,getProj(p1, plane),t1,linespacing,j,flip=True) + t3 = getText(c,f1,n,a,getProj(p1, plane),t1,linespacing,j,flip=True) + svg += t3 if t2: - ofs = FreeCAD.Vector(0,lspc.Length,0) + ofs = FreeCAD.Vector(0,-lspc.Length,0) if a: ofs = FreeCAD.Rotation(FreeCAD.Vector(0,0,1),-rotation).multVec(ofs) - svg += getText(c,fontsize,n,a,getProj(p1, plane).add(ofs),t2,linespacing,j,flip=True) + t4 = getText(c,fontsize,n,a,getProj(p1, plane).add(ofs),t2,linespacing,j,flip=True) + svg += t4 elif obj.isDerivedFrom('Part::Feature'): if obj.Shape.isNull(): diff --git a/src/Mod/TechDraw/App/DrawViewArch.cpp b/src/Mod/TechDraw/App/DrawViewArch.cpp index fa602dcfb4..4dca98553a 100644 --- a/src/Mod/TechDraw/App/DrawViewArch.cpp +++ b/src/Mod/TechDraw/App/DrawViewArch.cpp @@ -59,6 +59,7 @@ DrawViewArch::DrawViewArch(void) ADD_PROPERTY_TYPE(AllOn ,(false),group,App::Prop_None,"If hidden objects must be shown or not"); RenderMode.setEnums(RenderModeEnums); ADD_PROPERTY_TYPE(RenderMode, ((long)0),group,App::Prop_None,"The render mode to use"); + ADD_PROPERTY_TYPE(FillSpaces ,(false),group,App::Prop_None,"If True, Arch Spaces are shown as a colored area"); ADD_PROPERTY_TYPE(ShowHidden ,(false),group,App::Prop_None,"If the hidden geometry behind the section plane is shown or not"); ADD_PROPERTY_TYPE(ShowFill ,(false),group,App::Prop_None,"If cut areas must be filled with a hatch pattern or not"); ADD_PROPERTY_TYPE(LineWidth,(0.35),group,App::Prop_None,"Line width of this view"); @@ -113,7 +114,8 @@ App::DocumentObjectExecReturn *DrawViewArch::execute(void) << ",linewidth=" << LineWidth.getValue() << ",fontsize=" << FontSize.getValue() << ",techdraw=True" - << ",rotation=" << Rotation.getValue(); + << ",rotation=" << Rotation.getValue() + << ",fillSpaces=" << (FillSpaces.getValue() ? "True" : "False"); Base::Interpreter().runString("import ArchSectionPlane"); Base::Interpreter().runStringArg("svgBody = ArchSectionPlane.getSVG(App.activeDocument().%s %s)", diff --git a/src/Mod/TechDraw/App/DrawViewArch.h b/src/Mod/TechDraw/App/DrawViewArch.h index b02b9cf0a3..e430216e34 100644 --- a/src/Mod/TechDraw/App/DrawViewArch.h +++ b/src/Mod/TechDraw/App/DrawViewArch.h @@ -45,6 +45,7 @@ public: App::PropertyLink Source; App::PropertyBool AllOn; App::PropertyEnumeration RenderMode; // "Wireframe","Solid" + App::PropertyBool FillSpaces; App::PropertyBool ShowHidden; App::PropertyBool ShowFill; App::PropertyFloat LineWidth;