Skip to content

Commit

Permalink
Merge pull request FreeCAD#18558 from Roy-043/Draft-Fix-handling-of-c…
Browse files Browse the repository at this point in the history
…oin-nodes

Draft: Fix handling of coin nodes
  • Loading branch information
Roy-043 authored Dec 17, 2024
2 parents 1289997 + db12b31 commit d507cf3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
30 changes: 16 additions & 14 deletions src/Mod/Draft/draftguitools/gui_subelements.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
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

Expand Down Expand Up @@ -124,20 +124,22 @@ def get_editable_objects_from_selection(self):
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."""
Expand Down
14 changes: 7 additions & 7 deletions src/Mod/Draft/draftguitools/gui_trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
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
Expand Down Expand Up @@ -775,13 +776,12 @@ def getNodeFull(self, obj):
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
Expand Down
8 changes: 8 additions & 0 deletions src/Mod/Draft/draftutils/gui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 5 additions & 4 deletions src/Mod/Draft/draftviewproviders/view_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,12 @@ def onChanged(self, vobj, prop):
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)
Expand Down

0 comments on commit d507cf3

Please sign in to comment.