[Arch] [TD] Fix #4392: ArchView invisible objects should be show for Coin* render modes
This commit is contained in:
@@ -282,6 +282,30 @@ def isOriented(obj,plane):
|
||||
return True
|
||||
return False
|
||||
|
||||
def update_svg_cache(source, renderMode, showHidden, showFill, fillSpaces, joinArch, allOn, objs):
|
||||
"""
|
||||
Returns None or cached SVG, clears shape cache if required
|
||||
"""
|
||||
svgcache = None
|
||||
if hasattr(source,"Proxy"):
|
||||
if hasattr(source.Proxy,"svgcache") and source.Proxy.svgcache:
|
||||
# TODO check array bounds
|
||||
svgcache = source.Proxy.svgcache[0]
|
||||
# empty caches if we want to force-recalculate for certain properties
|
||||
if (source.Proxy.svgcache[1] != renderMode
|
||||
or source.Proxy.svgcache[2] != showHidden
|
||||
or source.Proxy.svgcache[3] != showFill
|
||||
or source.Proxy.svgcache[4] != fillSpaces
|
||||
or source.Proxy.svgcache[5] != joinArch
|
||||
or source.Proxy.svgcache[6] != allOn
|
||||
or source.Proxy.svgcache[7] != set(objs)):
|
||||
svgcache = None
|
||||
if (source.Proxy.svgcache[4] != fillSpaces
|
||||
or source.Proxy.svgcache[5] != joinArch
|
||||
or source.Proxy.svgcache[6] != allOn
|
||||
or source.Proxy.svgcache[7] != set(objs)):
|
||||
source.Proxy.shapecache = None
|
||||
return svgcache
|
||||
|
||||
def getSVG(source,
|
||||
renderMode="Wireframe",
|
||||
@@ -364,47 +388,25 @@ def getSVG(source,
|
||||
svgLineColor = Draft.getrgb(lineColor)
|
||||
svg = ''
|
||||
# reading cached version
|
||||
svgcache = None
|
||||
if hasattr(source,"Proxy"):
|
||||
if hasattr(source.Proxy,"svgcache") and source.Proxy.svgcache:
|
||||
svgcache = source.Proxy.svgcache[0]
|
||||
# empty caches if we want to force-recalculate for certain properties
|
||||
if source.Proxy.svgcache[1] != renderMode:
|
||||
svgcache = None
|
||||
if source.Proxy.svgcache[2] != showHidden:
|
||||
svgcache = None
|
||||
if source.Proxy.svgcache[3] != showFill:
|
||||
svgcache = None
|
||||
if source.Proxy.svgcache[4] != fillSpaces:
|
||||
svgcache = None
|
||||
source.Proxy.shapecache = None
|
||||
if source.Proxy.svgcache[5] != joinArch:
|
||||
svgcache = None
|
||||
source.Proxy.shapecache = None
|
||||
# TODO check array bounds
|
||||
if source.Proxy.svgcache[6] != allOn:
|
||||
svgcache = None
|
||||
source.Proxy.shapecache = None
|
||||
if source.Proxy.svgcache[7] != set(objs):
|
||||
svgcache = None
|
||||
source.Proxy.shapecache = None
|
||||
svgcache = update_svg_cache(source, renderMode, showHidden, showFill, fillSpaces, joinArch, allOn, objs)
|
||||
should_update_svg_cache = False
|
||||
if not svgcache:
|
||||
should_update_svg_cache = True
|
||||
|
||||
# generating SVG
|
||||
if renderMode in ["Coin",2,"Coin mono",3]:
|
||||
# render using a coin viewer
|
||||
if hasattr(source.ViewObject,"ViewData") and source.ViewObject.ViewData:
|
||||
cameradata = getCameraData(source.ViewObject.ViewData)
|
||||
cameradata = None#getCameraData(source.ViewObject.ViewData)
|
||||
else:
|
||||
cameradata = None
|
||||
if not svgcache:
|
||||
if should_update_svg_cache:
|
||||
if renderMode in ["Coin mono",3]:
|
||||
svgcache = getCoinSVG(cutplane,objs,cameradata,linewidth="SVGLINEWIDTH",facecolor="#ffffff")
|
||||
else:
|
||||
svgcache = getCoinSVG(cutplane,objs,cameradata,linewidth="SVGLINEWIDTH")
|
||||
if hasattr(source,"Proxy"):
|
||||
source.Proxy.svgcache = [svgcache,renderMode,showHidden,showFill,fillSpaces,joinArch,allOn,set(objs)]
|
||||
elif renderMode in ["Solid",1]:
|
||||
if not svgcache:
|
||||
if should_update_svg_cache:
|
||||
svgcache = ''
|
||||
# render using the Arch Vector Renderer
|
||||
import ArchVRM, WorkingPlane
|
||||
@@ -432,8 +434,6 @@ def getSVG(source,
|
||||
svgcache += render.getHiddenSVG(linewidth="SVGLINEWIDTH")
|
||||
svgcache += '</g>\n'
|
||||
# print(render.info())
|
||||
if hasattr(source,"Proxy"):
|
||||
source.Proxy.svgcache = [svgcache,renderMode,showHidden,showFill,fillSpaces,joinArch,allOn,set(objs)]
|
||||
else:
|
||||
# Wireframe (0) mode
|
||||
|
||||
@@ -453,7 +453,7 @@ def getSVG(source,
|
||||
objectSshapes = []
|
||||
source.Proxy.shapecache = [vshapes,hshapes,sshapes,cutface,cutvolume,invcutvolume,objectSshapes]
|
||||
|
||||
if not svgcache:
|
||||
if should_update_svg_cache:
|
||||
svgcache = ""
|
||||
# render using the Drawing module
|
||||
import Drawing, Part
|
||||
@@ -496,8 +496,9 @@ def getSVG(source,
|
||||
sshapes, direction,
|
||||
hStyle=style, h0Style=style, h1Style=style,
|
||||
vStyle=style, v0Style=style, v1Style=style)
|
||||
if hasattr(source,"Proxy"):
|
||||
source.Proxy.svgcache = [svgcache,renderMode,showHidden,showFill,fillSpaces,joinArch,allOn,set(objs)]
|
||||
if should_update_svg_cache:
|
||||
if hasattr(source,"Proxy"):
|
||||
source.Proxy.svgcache = [svgcache,renderMode,showHidden,showFill,fillSpaces,joinArch,allOn,set(objs)]
|
||||
|
||||
svgcache = svgcache.replace("SVGLINECOLOR",svgLineColor)
|
||||
svgcache = svgcache.replace("SVGLINEWIDTH",svgLineWidth)
|
||||
@@ -660,12 +661,20 @@ def getCoinSVG(cutplane,objs,cameradata=None,linewidth=0.2,singleface=False,face
|
||||
obj.ViewObject.Lighting = "One side"
|
||||
|
||||
# get nodes to render
|
||||
rn = coin.SoSeparator()
|
||||
root_node = coin.SoSeparator()
|
||||
boundbox = FreeCAD.BoundBox()
|
||||
for obj in objs:
|
||||
if hasattr(obj.ViewObject,"RootNode") and obj.ViewObject.RootNode:
|
||||
ncopy = obj.ViewObject.RootNode.copy()
|
||||
rn.addChild(ncopy)
|
||||
old_visibility = obj.ViewObject.isVisible()
|
||||
# ignore visibility as only visible objects are passed here
|
||||
obj.ViewObject.show()
|
||||
node_copy = obj.ViewObject.RootNode.copy()
|
||||
root_node.addChild(node_copy)
|
||||
if(old_visibility):
|
||||
obj.ViewObject.show()
|
||||
else:
|
||||
obj.ViewObject.hide()
|
||||
|
||||
if hasattr(obj,"Shape") and hasattr(obj.Shape,"BoundBox"):
|
||||
boundbox.add(obj.Shape.BoundBox)
|
||||
|
||||
@@ -676,13 +685,13 @@ def getCoinSVG(cutplane,objs,cameradata=None,linewidth=0.2,singleface=False,face
|
||||
obj.ViewObject.Lighting = ldict[obj.Name]
|
||||
|
||||
# create viewer
|
||||
v = FreeCADGui.createViewer()
|
||||
viewername = "Temp" + str(uuid.uuid4().hex[:8])
|
||||
v.setName(viewername)
|
||||
view_window = FreeCADGui.createViewer()
|
||||
view_window_name = "Temp" + str(uuid.uuid4().hex[:8])
|
||||
view_window.setName(view_window_name)
|
||||
inventor_view = view_window.getViewer()
|
||||
|
||||
vv = v.getViewer()
|
||||
vv.setBackgroundColor(1,1,1)
|
||||
v.redraw()
|
||||
inventor_view.setBackgroundColor(1,1,1)
|
||||
view_window.redraw()
|
||||
|
||||
# set clip plane
|
||||
clip = coin.SoClipPlane()
|
||||
@@ -694,7 +703,7 @@ def getCoinSVG(cutplane,objs,cameradata=None,linewidth=0.2,singleface=False,face
|
||||
clip.on = True
|
||||
plane = coin.SbPlane(coin.SbVec3f(norm.x,norm.y,norm.z),dist) #dir, position on dir
|
||||
clip.plane.setValue(plane)
|
||||
rn.insertChild(clip,0)
|
||||
root_node.insertChild(clip,0)
|
||||
|
||||
# add white marker at scene bound box corner
|
||||
markervec = FreeCAD.Vector(10,10,10)
|
||||
@@ -713,28 +722,28 @@ def getCoinSVG(cutplane,objs,cameradata=None,linewidth=0.2,singleface=False,face
|
||||
lset = coin.SoIndexedLineSet()
|
||||
lset.coordIndex.setValues(0,2,[0,1])
|
||||
sep.addChild(lset)
|
||||
rn.insertChild(sep,0)
|
||||
root_node.insertChild(sep,0)
|
||||
|
||||
# set scenegraph
|
||||
vv.setSceneGraph(rn)
|
||||
inventor_view.setSceneGraph(root_node)
|
||||
|
||||
# set camera
|
||||
if cameradata:
|
||||
v.setCamera(cameradata)
|
||||
view_window.setCamera(cameradata)
|
||||
else:
|
||||
v.setCameraType("Orthographic")
|
||||
view_window.setCameraType("Orthographic")
|
||||
#rot = FreeCAD.Rotation(FreeCAD.Vector(0,0,1),cutplane.normalAt(0,0))
|
||||
vx = cutplane.Placement.Rotation.multVec(FreeCAD.Vector(1,0,0))
|
||||
vy = cutplane.Placement.Rotation.multVec(FreeCAD.Vector(0,1,0))
|
||||
vz = cutplane.Placement.Rotation.multVec(FreeCAD.Vector(0,0,1))
|
||||
rot = FreeCAD.Rotation(vx,vy,vz,"ZXY")
|
||||
v.setCameraOrientation(rot.Q)
|
||||
view_window.setCameraOrientation(rot.Q)
|
||||
# this is needed to set correct focal depth, otherwise saving doesn't work properly
|
||||
v.fitAll()
|
||||
view_window.fitAll()
|
||||
|
||||
# save view
|
||||
#print("saving to",svgfile)
|
||||
v.saveVectorGraphic(svgfile,1) # number is pixel size
|
||||
view_window.saveVectorGraphic(svgfile,1) # number is pixel size
|
||||
|
||||
# set linewidth placeholder
|
||||
f = open(svgfile,"r")
|
||||
@@ -793,7 +802,7 @@ def getCoinSVG(cutplane,objs,cameradata=None,linewidth=0.2,singleface=False,face
|
||||
svg = svg.replace("</svg>","</g>\n</svg>")
|
||||
|
||||
# trigger viewer close
|
||||
QtCore.QTimer.singleShot(1,lambda: closeViewer(viewername))
|
||||
QtCore.QTimer.singleShot(1,lambda: closeViewer(view_window_name))
|
||||
|
||||
# strip svg tags (needed for TD Arch view)
|
||||
svg = re.sub("<\?xml.*?>","",svg,flags=re.MULTILINE|re.DOTALL)
|
||||
|
||||
Reference in New Issue
Block a user