From 4c3fc869feadfd8cc9feab0588d5e5b6c981e624 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Sat, 22 Jun 2024 12:49:47 -0400 Subject: [PATCH] Toponaming: Check for selection mapped element name --- src/Gui/SoFCUnifiedSelection.cpp | 3 +- src/Gui/View3DInventorSelection.cpp | 3 +- .../TestTopologicalNamingProblem.py | 31 ++++++++++++++++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/Gui/SoFCUnifiedSelection.cpp b/src/Gui/SoFCUnifiedSelection.cpp index 6cefc9ae42..62e2f5e15c 100644 --- a/src/Gui/SoFCUnifiedSelection.cpp +++ b/src/Gui/SoFCUnifiedSelection.cpp @@ -401,7 +401,8 @@ void SoFCUnifiedSelection::doAction(SoAction *action) #ifdef FC_USE_TNP_FIX std::pair elementName; App::GeoFeature::resolveElement(obj, subName, elementName); - if (!elementName.second.empty()) { // If we have a shortened element name + if (Data::isMappedElement(subName) + && !elementName.second.empty()) { // If we have a shortened element name subName = elementName.second.c_str(); // use it. } #endif diff --git a/src/Gui/View3DInventorSelection.cpp b/src/Gui/View3DInventorSelection.cpp index 52a81206a7..6999d090f3 100644 --- a/src/Gui/View3DInventorSelection.cpp +++ b/src/Gui/View3DInventorSelection.cpp @@ -117,7 +117,8 @@ void View3DInventorSelection::checkGroupOnTop(const SelectionChanges &Reason) #ifdef FC_USE_TNP_FIX std::pair element; App::GeoFeature::resolveElement(obj, Reason.pSubName, element); - if (!element.second.empty()) { // If we have a shortened element name + if (Data::isMappedElement(subname) + && !element.second.empty()) { // If we have a shortened element name subname = element.second.c_str(); // use if } #endif diff --git a/src/Mod/PartDesign/PartDesignTests/TestTopologicalNamingProblem.py b/src/Mod/PartDesign/PartDesignTests/TestTopologicalNamingProblem.py index 159b8adfa0..cf591042c6 100644 --- a/src/Mod/PartDesign/PartDesignTests/TestTopologicalNamingProblem.py +++ b/src/Mod/PartDesign/PartDesignTests/TestTopologicalNamingProblem.py @@ -120,13 +120,13 @@ class TestTopologicalNamingProblem(unittest.TestCase): if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023. return reverseMap = sketch.Shape.ElementReverseMap - faces = [name for name in reverseMap.keys() if name.startswith("Face")] + reverseFaces = [name for name in reverseMap.keys() if name.startswith("Face")] edges = [name for name in reverseMap.keys() if name.startswith("Edge")] vertexes = [name for name in reverseMap.keys() if name.startswith("Vertex")] # Assert - self.assertEqual(sketch.Shape.ElementMapSize,9) - self.assertEqual(len(reverseMap),9) - self.assertEqual(len(faces),1) + self.assertEqual(sketch.Shape.ElementMapSize,12) + self.assertEqual(len(reverseMap),8) + self.assertEqual(len(reverseFaces),0) self.assertEqual(len(edges),4) self.assertEqual(len(vertexes),4) @@ -969,7 +969,7 @@ class TestTopologicalNamingProblem(unittest.TestCase): self.assertEqual(self.Body.Shape.BoundBox.XMax,31.37) self.assertAlmostEqual(self.Body.Shape.BoundBox.YMax,25.2) self.assertEqual(self.Body.Shape.BoundBox.ZMax,20) - self.assertNotEquals(area1, area2) + self.assertNotEqual(area1, area2) def testShapeBinder(self): doc = self.Doc @@ -1442,6 +1442,27 @@ class TestTopologicalNamingProblem(unittest.TestCase): self.assertAlmostEqual(volume3, boxVolume - 3 * filletVolume - cutVolume, 4) self.assertAlmostEqual(volume4, boxVolume - 2 * filletVolume - cutVolume, 4) + def testSubelementNames(self): + # Arrange + doc = App.ActiveDocument + plane = doc.addObject("Part::Plane", "Plane") + plane.Length = 10 + plane.Width = 10 + extrude = doc.addObject("Part::Extrusion", "Extrude") + extrude.Base = plane + extrude.LengthFwd = 10 + doc.recompute() + if not App.GuiUp: + return + # Act + App.Gui.Selection.addSelection("", extrude.Name, "Face2") + # Assert + self.assertEqual(len(App.Gui.Selection.getSelectionEx("", 0)[0].SubElementNames),1) + if extrude.ElementMapVersion == "": # Should be '4' as of Mar 2023. + self.assertEqual(App.Gui.Selection.getSelectionEx("", 0)[0].SubElementNames[0],"Face2") + else: + self.assertEqual(App.Gui.Selection.getSelectionEx("", 0)[0].SubElementNames[0][-8:],",F.Face2") + def create_t_sketch(self): self.Doc.getObject('Body').newObject('Sketcher::SketchObject', 'Sketch') geo_list = [