From 034b8bf579a039bcac65ff121025590d3269d3a2 Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 16 Jun 2025 17:40:32 +0200 Subject: [PATCH] CAM: Show abbreviations next to properly labels in the toolbit editor (#21887) --- src/Mod/CAM/CAMTests/TestPathToolShapeIcon.py | 4 ++-- src/Mod/CAM/Path/Tool/shape/models/icon.py | 16 ++++++++++++---- src/Mod/CAM/Path/Tool/toolbit/ui/editor.py | 4 +++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Mod/CAM/CAMTests/TestPathToolShapeIcon.py b/src/Mod/CAM/CAMTests/TestPathToolShapeIcon.py index 0b70cb683b..de46d04eb8 100644 --- a/src/Mod/CAM/CAMTests/TestPathToolShapeIcon.py +++ b/src/Mod/CAM/CAMTests/TestPathToolShapeIcon.py @@ -183,8 +183,8 @@ class TestToolBitShapeSvgIcon(TestToolBitShapeIconBase): svg_content = self.test_svg.data abbr = ToolBitShapeSvgIcon.get_abbreviations_from_svg(svg_content) # Assuming the test_svg data has 'diameter' and 'length' ids - self.assertIn("diameter", abbr) - self.assertIn("length", abbr) + self.assertIn("Diameter", abbr) + self.assertIn("Length", abbr) # Test with invalid SVG invalid_svg = b"A1" # Missing closing tag diff --git a/src/Mod/CAM/Path/Tool/shape/models/icon.py b/src/Mod/CAM/Path/Tool/shape/models/icon.py index 702f7e448a..8d1100e431 100644 --- a/src/Mod/CAM/Path/Tool/shape/models/icon.py +++ b/src/Mod/CAM/Path/Tool/shape/models/icon.py @@ -20,6 +20,7 @@ # * * # *************************************************************************** import pathlib +import re import xml.etree.ElementTree as ET from typing import Mapping, Optional from functools import cached_property @@ -235,8 +236,7 @@ class ToolBitShapeSvgIcon(ToolBitShapeIcon): Returns: The abbreviation string, or None if not found. """ - normalized_param_name = param_name.lower().replace(" ", "_") - return self.abbreviations.get(normalized_param_name) + return self.abbreviations.get(param_name) @staticmethod def get_abbreviations_from_svg(svg: bytes) -> Mapping[str, str]: @@ -254,15 +254,23 @@ class ToolBitShapeSvgIcon(ToolBitShapeIcon): if id is None or not isinstance(id, str): continue + # Backward compatibility: Normalize to match FreeCAD property + # name structure: + # Old: property_name New: PropertyName + def _upper(match): + return match.group(1).upper() + + id = re.sub(r"_(\w)", _upper, id.capitalize()) + abbr = text_elem.text if abbr is not None: - result[id.lower()] = abbr + result[id] = abbr span_elem = text_elem.find(".//s:tspan", _svg_ns) if span_elem is None: continue abbr = span_elem.text - result[id.lower()] = abbr + result[id] = abbr return result diff --git a/src/Mod/CAM/Path/Tool/toolbit/ui/editor.py b/src/Mod/CAM/Path/Tool/toolbit/ui/editor.py index eb4d77065c..73b3f40dbd 100644 --- a/src/Mod/CAM/Path/Tool/toolbit/ui/editor.py +++ b/src/Mod/CAM/Path/Tool/toolbit/ui/editor.py @@ -49,7 +49,9 @@ class ToolBitPropertiesWidget(QtGui.QWidget): self._id_label = QtGui.QLabel() # Read-only ID self._id_label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) - self._property_editor = DocumentObjectEditorWidget() + theicon = toolbit.get_icon() if toolbit else None + abbr = theicon.abbreviations if theicon else {} + self._property_editor = DocumentObjectEditorWidget(property_suffixes=abbr) self._property_editor.setSizePolicy( QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding )