assembly: use AxisOrigin for axis rendering and picking

This commit is contained in:
Zheng, Lei 2019-05-09 20:12:20 +08:00
parent e4a8423fa1
commit d23f34247d

View File

@ -1009,9 +1009,7 @@ class ViewProviderAsmElement(ViewProviderAsmOnTop):
elif prop in ('Placement','Shape'): elif prop in ('Placement','Shape'):
self.setupAxis() self.setupAxis()
_AxisGroup = None _AxisOrigin = None
_Axis = None
_AxisMap = {'X':0,'Y':1,'Z':2}
def showCS(self): def showCS(self):
if self.ViewObject.ShowCS or gui.AsmCmdManager.ShowElementCS: if self.ViewObject.ShowCS or gui.AsmCmdManager.ShowElementCS:
@ -1020,85 +1018,43 @@ class ViewProviderAsmElement(ViewProviderAsmOnTop):
def getElementPicked(self,pp): def getElementPicked(self,pp):
vobj = self.ViewObject vobj = self.ViewObject
det = pp.getDetail() if self.showCS():
if self.isCSVisible() and self._Axis and det: axis = self._AxisOrigin
idx = pp.getPath().findNode(self._Axis) if axis:
if idx >= 0: sub = axis.getElementPicked(pp)
try: if sub:
from pivy import coin return sub
ldx = coin.cast(det,'SoLineDetail').getLineIndex()
if ldx==0:
return 'X';
if ldx==1:
return 'Y';
if ldx==2:
return 'Z';
return None
except Exception:
pass
return vobj.getElementPicked(pp) return vobj.getElementPicked(pp)
def getDetailPath(self,subname,path,append): def getDetailPath(self,subname,path,append):
vobj = self.ViewObject vobj = self.ViewObject
node = getattr(self,'axisNode',None) node = getattr(self,'axisNode',None)
idx = self._AxisMap.get(subname,None) if node:
if idx is not None and node:
cdx = vobj.RootNode.findChild(node) cdx = vobj.RootNode.findChild(node)
if cdx >= 0: if cdx >= 0:
length = path.getLength()
if append: if append:
path.append(vobj.RootNode) path.append(vobj.RootNode)
elif path.getLength(): elif path.getLength():
# pop the mode switch node, because we have our onw switch
# to control axis visibility
path.truncate(path.getLength()-1) path.truncate(path.getLength()-1)
path.append(node) path.append(node)
path.append(node.getChild(0)) path.append(node.getChild(0))
path.append(self._AxisGroup) ret = self._AxisOrigin.getDetailPath(subname,path)
path.append(self._Axis) if ret:
from pivy import coin return ret;
detail = coin.SoLineDetail() path.truncate(length)
detail.setLineIndex(idx)
return detail
return vobj.getDetailPath(subname,path,append) return vobj.getDetailPath(subname,path,append)
@classmethod @classmethod
def getAxis(cls): def getAxis(cls):
if cls._AxisGroup: axis = cls._AxisOrigin
return cls._AxisGroup if not axis:
from pivy import coin axis = FreeCADGui.AxisOrigin()
autoZoom = coin.SoType.fromName( axis.Labels = {'X':'','Y':'','Z':''}
'SoAutoZoomTranslation').createInstance() cls._AxisOrigin = axis
mat = coin.SoMaterial() return axis.Node
mat.diffuseColor.setValues([[1.0, 0.0, 0.0],
[0.0, 0.6, 0.0],
[0.0, 0.0, 1.0]])
binding = coin.SoMaterialBinding()
binding.value = coin.SoMaterialBinding.PER_FACE_INDEXED
coords = coin.SoCoordinate3()
coords.point.setValues([[0.0, 0.0, 0.0],
[6.0, 0.0, 0.0],
[0.0, 6.0, 0.0],
[0.0, 0.0, 6.0]])
line = coin.SoType.fromName("SoBrepEdgeSet").createInstance()
line.coordIndex.setValues(0,9,[0,1,-1,0,2,-1,0,3,-1])
line.materialIndex.setValues([0,1,2])
draw = coin.SoDrawStyle()
draw.lineWidth = 2.0
group = coin.SoGroup()
group.addChild(autoZoom)
group.addChild(binding)
group.addChild(mat)
group.addChild(coords)
group.addChild(draw)
group.addChild(line)
cls._AxisGroup = group
cls._Axis = line
return group
def setupAxis(self): def setupAxis(self):
vobj = self.ViewObject vobj = self.ViewObject