Merge pull request #18558 from Roy-043/Draft-Fix-handling-of-coin-nodes
Draft: Fix handling of coin nodes
This commit is contained in:
@@ -37,9 +37,9 @@ import pivy.coin as coin
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCADGui as Gui
|
||||
import draftguitools.gui_base_original as gui_base_original
|
||||
import draftguitools.gui_tool_utils as gui_tool_utils
|
||||
|
||||
from draftguitools import gui_base_original
|
||||
from draftguitools import gui_tool_utils
|
||||
from draftutils import gui_utils
|
||||
from draftutils.messages import _msg
|
||||
from draftutils.translate import translate
|
||||
|
||||
@@ -124,20 +124,22 @@ class SubelementHighlight(gui_base_original.Modifier):
|
||||
def highlight_editable_objects(self):
|
||||
"""Highlight editable Draft objects from the selection."""
|
||||
for obj in self.editable_objects:
|
||||
vobj = obj.ViewObject
|
||||
self.original_view_settings[obj.Name] = {
|
||||
'Visibility': obj.ViewObject.Visibility,
|
||||
'PointSize': obj.ViewObject.PointSize,
|
||||
'PointColor': obj.ViewObject.PointColor,
|
||||
'LineColor': obj.ViewObject.LineColor}
|
||||
obj.ViewObject.Visibility = True
|
||||
obj.ViewObject.PointSize = 10
|
||||
obj.ViewObject.PointColor = (1.0, 0.0, 0.0)
|
||||
obj.ViewObject.LineColor = (1.0, 0.0, 0.0)
|
||||
'Visibility': vobj.Visibility,
|
||||
'PointSize': vobj.PointSize,
|
||||
'PointColor': vobj.PointColor,
|
||||
'LineColor': vobj.LineColor}
|
||||
vobj.Visibility = True
|
||||
vobj.PointSize = 10
|
||||
vobj.PointColor = (1.0, 0.0, 0.0)
|
||||
vobj.LineColor = (1.0, 0.0, 0.0)
|
||||
xray = coin.SoAnnotation()
|
||||
if obj.ViewObject.RootNode.getNumChildren() > 2:
|
||||
xray.addChild(obj.ViewObject.RootNode.getChild(2).getChild(0))
|
||||
switch = gui_utils.find_coin_node(vobj.RootNode, coin.SoSwitch)
|
||||
if switch is not None:
|
||||
xray.addChild(switch.getChild(0))
|
||||
xray.setName("xray")
|
||||
obj.ViewObject.RootNode.addChild(xray)
|
||||
vobj.RootNode.addChild(xray)
|
||||
|
||||
def restore_editable_objects_graphics(self):
|
||||
"""Restore the editable objects' appearance."""
|
||||
|
||||
@@ -43,6 +43,7 @@ import FreeCADGui
|
||||
import Draft
|
||||
import DraftVecUtils
|
||||
from FreeCAD import Vector
|
||||
from draftutils import gui_utils
|
||||
from draftutils import params
|
||||
from draftutils import utils
|
||||
from draftutils.messages import _msg
|
||||
@@ -775,13 +776,12 @@ class ghostTracker(Tracker):
|
||||
try:
|
||||
sep.addChild(obj.ViewObject.RootNode.copy())
|
||||
# add Part container offset
|
||||
if hasattr(obj, "getGlobalPlacement"):
|
||||
if obj.Placement != obj.getGlobalPlacement():
|
||||
if sep.getChild(0).getNumChildren() > 0:
|
||||
if isinstance(sep.getChild(0).getChild(0),coin.SoTransform):
|
||||
gpl = obj.getGlobalPlacement()
|
||||
sep.getChild(0).getChild(0).translation.setValue(tuple(gpl.Base))
|
||||
sep.getChild(0).getChild(0).rotation.setValue(gpl.Rotation.Q)
|
||||
if hasattr(obj, "getGlobalPlacement") and obj.Placement != obj.getGlobalPlacement():
|
||||
transform = gui_utils.find_coin_node(sep.getChild(0), coin.SoTransform)
|
||||
if transform is not None:
|
||||
gpl = obj.getGlobalPlacement()
|
||||
transform.translation.setValue(tuple(gpl.Base))
|
||||
transform.rotation.setValue(gpl.Rotation.Q)
|
||||
except Exception:
|
||||
_msg("ghostTracker: Error retrieving coin node (full)")
|
||||
return sep
|
||||
|
||||
@@ -896,6 +896,14 @@ def get_bbox(obj, debug=False):
|
||||
return App.BoundBox(xmin, ymin, zmin, xmax, ymax, zmax)
|
||||
|
||||
|
||||
# Code by Yorik van Havre.
|
||||
def find_coin_node(parent, nodetype):
|
||||
for i in range(parent.getNumChildren()):
|
||||
if isinstance(parent.getChild(i), nodetype):
|
||||
return parent.getChild(i)
|
||||
return None
|
||||
|
||||
|
||||
# Code by Chris Hennes (chennes).
|
||||
# See https://forum.freecadweb.org/viewtopic.php?p=656362#p656362.
|
||||
# Used to fix https://github.com/FreeCAD/FreeCAD/issues/10469.
|
||||
|
||||
@@ -289,11 +289,12 @@ class ViewProviderDraft(object):
|
||||
else:
|
||||
path = "None"
|
||||
if path and vobj.RootNode:
|
||||
if vobj.RootNode.getChildren().getLength() > 2:
|
||||
if vobj.RootNode.getChild(2).getChildren().getLength() > 0:
|
||||
innodes = vobj.RootNode.getChild(2).getChild(0).getChildren().getLength()
|
||||
switch = gui_utils.find_coin_node(vobj.RootNode, coin.SoSwitch)
|
||||
if switch is not None:
|
||||
if switch.getChildren().getLength() > 0:
|
||||
innodes = switch.getChild(0).getChildren().getLength()
|
||||
if innodes > 2:
|
||||
r = vobj.RootNode.getChild(2).getChild(0).getChild(innodes-1)
|
||||
r = switch.getChild(0).getChild(innodes-1)
|
||||
i = QtCore.QFileInfo(path)
|
||||
if self.texture:
|
||||
r.removeChild(self.texture)
|
||||
|
||||
Reference in New Issue
Block a user