Draft: Fix handling of coin nodes

Fixes #18523.
This commit is contained in:
Roy-043
2024-12-16 18:24:36 +01:00
parent 23354b57cb
commit db12b31b76
4 changed files with 36 additions and 25 deletions

View File

@@ -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."""

View File

@@ -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

View File

@@ -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.

View File

@@ -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)