Merge pull request #26577 from Roy-043/Draft-fix-regression-in-Pattern-display

Draft: fix regression in Pattern display
This commit is contained in:
Chris Hennes
2026-01-04 10:44:41 -09:00
committed by GitHub
2 changed files with 58 additions and 47 deletions

View File

@@ -939,14 +939,25 @@ def get_bbox(obj, debug=False):
return App.BoundBox(xmin, ymin, zmin, xmax, ymax, zmax)
# Code by Yorik van Havre.
# Code by Yorik van Havre (adapted).
def find_coin_node(parent, nodetype):
if not hasattr(parent, "getNumChildren"):
return None
for i in range(parent.getNumChildren()):
if isinstance(parent.getChild(i), nodetype):
return parent.getChild(i)
return None
def find_coin_node_by_name(parent, name):
if not hasattr(parent, "getNumChildren"):
return None
for i in range(parent.getNumChildren()):
if parent.getChild(i).getName() == name:
return parent.getChild(i)
return None
# Code by Chris Hennes (chennes).
# See https://forum.freecad.org/viewtopic.php?p=656362#p656362.
# Used to fix https://github.com/FreeCAD/FreeCAD/issues/10469.

View File

@@ -283,52 +283,52 @@ class ViewProviderDraft(object):
"""
# treatment of patterns and image textures
if prop in ("TextureImage", "Pattern", "ShapeAppearance"):
if hasattr(self.Object, "Shape"):
if self.Object.Shape.Faces:
path = None
if hasattr(vobj, "TextureImage"):
if vobj.TextureImage:
path = vobj.TextureImage
if not path:
if hasattr(vobj, "Pattern"):
if str(vobj.Pattern) in utils.svg_patterns():
path = utils.svg_patterns()[vobj.Pattern][1]
else:
path = "None"
if path and vobj.RootNode:
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 = switch.getChild(0).getChild(innodes - 1)
i = QtCore.QFileInfo(path)
if self.texture:
r.removeChild(self.texture)
self.texture = None
if self.texcoords:
r.removeChild(self.texcoords)
self.texcoords = None
if i.exists():
size = None
if ".SVG" in path.upper():
size = params.get_param("HatchPatternResolution")
if not size:
size = 128
im = gui_utils.load_texture(path, size)
if im:
self.texture = coin.SoTexture2()
self.texture.image = im
r.insertChild(self.texture, 1)
if size:
s = 1
if hasattr(vobj, "PatternSize"):
if vobj.PatternSize:
s = vobj.PatternSize
self.texcoords = coin.SoTextureCoordinatePlane()
self.texcoords.directionS.setValue(s, 0, 0)
self.texcoords.directionT.setValue(0, s, 0)
r.insertChild(self.texcoords, 2)
if hasattr(self.Object, "Shape") and self.Object.Shape.Faces:
path = None
if hasattr(vobj, "TextureImage"):
if vobj.TextureImage:
path = vobj.TextureImage
if not path:
if hasattr(vobj, "Pattern"):
if str(vobj.Pattern) in utils.svg_patterns():
path = utils.svg_patterns()[vobj.Pattern][1]
else:
path = "None"
if path and vobj.RootNode:
switch = gui_utils.find_coin_node(vobj.RootNode, coin.SoSwitch)
if switch is not None and switch.getChildren().getLength() > 0:
flat_lines_node = switch.getChild(0)
# Get the Shaded sub-node of the Flat Lines node. The name in
# Std_SceneInspector is "Shaded", but the actual name is "FlatRoot")
shaded_node = gui_utils.find_coin_node_by_name(flat_lines_node, "FlatRoot")
if shaded_node is not None:
i = QtCore.QFileInfo(path)
if self.texture:
shaded_node.removeChild(self.texture)
self.texture = None
if self.texcoords:
shaded_node.removeChild(self.texcoords)
self.texcoords = None
if i.exists():
size = None
if ".SVG" in path.upper():
size = params.get_param("HatchPatternResolution")
if not size:
size = 128
im = gui_utils.load_texture(path, size)
if im:
self.texture = coin.SoTexture2()
self.texture.image = im
shaded_node.insertChild(self.texture, 1)
if size:
s = 1
if hasattr(vobj, "PatternSize"):
if vobj.PatternSize:
s = vobj.PatternSize
self.texcoords = coin.SoTextureCoordinatePlane()
self.texcoords.directionS.setValue(s, 0, 0)
self.texcoords.directionT.setValue(0, s, 0)
shaded_node.insertChild(self.texcoords, 2)
elif prop == "PatternSize":
if hasattr(self, "texcoords"):
if self.texcoords: