From a7d8192df8726f03ccffad3e0d754a760841882e Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 21 Nov 2017 14:32:18 +0300 Subject: [PATCH] Fix for the issue #2289: Naming of vertices incorrect after extrusion --- src/Config/Config_ModuleReader.cpp | 2 +- src/FeaturesPlugin/CMakeLists.txt | 1 + .../FeaturesPlugin_CompositeSketch.cpp | 5 ++ src/FeaturesPlugin/Test/Test2289.py | 56 +++++++++++++++++++ src/PythonAPI/model/tests/tests.py | 45 ++++++++++++++- 5 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 src/FeaturesPlugin/Test/Test2289.py diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index 67b4ee990..452fc4ca3 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -104,7 +104,7 @@ void Config_ModuleReader::processNode(xmlNodePtr theNode) std::string aPluginScript = getProperty(theNode, PLUGIN_SCRIPT); std::string aPluginName = addPlugin(aPluginLibrary, aPluginScript, aPluginConf); std::string aUsesPlugin = getProperty(theNode, PLUGIN_USES); - if (!aUsesPlugin.empty()) { // send information about hte plugin dependencies + if (!aUsesPlugin.empty()) { // send information about the plugin dependencies std::shared_ptr aMess(new Config_PluginMessage( Events_Loop::loop()->eventByName(Config_PluginMessage::EVENT_ID()), aPluginName)); aMess->setUses(aUsesPlugin); diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 53b6ad50e..9fc5d6d3f 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -185,4 +185,5 @@ ADD_UNIT_TESTS(TestExtrusion.py Test2248.py Test2251.py Test2255.py + Test2289.py ) diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp index adde95a0b..a3018be53 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp @@ -506,6 +506,11 @@ void FeaturesPlugin_CompositeSketch::storeShapes(ResultBodyPtr theResultBody, std::string aName = theName + aShapeTypeStr; storeSubShape(theResultBody, aShape, aShapeTypeToExplore, theMapOfSubShapes, aName, aShapeIndex, theTag); + if (theBaseShapeType == GeomAPI_Shape::WIRE) { // issue 2289: special names also for vertices + aName = theName + "Vertex"; + storeSubShape(theResultBody, aShape, GeomAPI_Shape::VERTEX, + theMapOfSubShapes, aName, aShapeIndex, theTag); + } } } } diff --git a/src/FeaturesPlugin/Test/Test2289.py b/src/FeaturesPlugin/Test/Test2289.py new file mode 100644 index 000000000..7597676a7 --- /dev/null +++ b/src/FeaturesPlugin/Test/Test2289.py @@ -0,0 +1,56 @@ +## Copyright (C) 2014-2017 CEA/DEN, EDF R&D +## +## This library is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## This library is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with this library; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +## +## See http:##www.salome-platform.org/ or +## email : webmaster.salome@opencascade.com +## + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_1.addLine(55.30809111108014, 52.50335568234566, -47.4076783683968, 52.50335568234566) +SketchLine_2 = Sketch_1.addLine(-47.4076783683968, 52.50335568234566, -77.7205049049542, 0) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(-77.7205049049542, 0, -47.4076783683968, -52.50335568234565) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchLine_4 = Sketch_1.addLine(-47.4076783683968, -52.50335568234565, 55.30809111108014, -52.50335568234565) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchLine_5 = Sketch_1.addLine(55.30809111108014, -52.50335568234565, 55.30809111108014, 52.50335568234566) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_5.endPoint()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_5.result()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_4.result()) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False) +SketchLine_6 = SketchProjection_1.createdFeature() +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_6.result(), SketchLine_3.startPoint()) +SketchConstraintAngle_1 = Sketch_1.setAngleBackward(SketchLine_2.result(), SketchLine_3.result(), 120) +SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_2.result(), SketchLine_3.result()) +SketchConstraintEqual_2 = Sketch_1.setEqual(SketchLine_1.result(), SketchLine_4.result()) +model.do() +Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/Edge-SketchLine_3"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_2"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_4"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_1"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_5")]) +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection(), 10, 0) +model.do() + +model.testHaveNamingVertices(Extrusion_1, model, Part_1_doc) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py index ce6c39332..49fdcdd13 100644 --- a/src/PythonAPI/model/tests/tests.py +++ b/src/PythonAPI/model/tests/tests.py @@ -166,7 +166,7 @@ def testHaveNamingFaces(theFeature, theModel, thePartDoc) : assert(name != ""), "String empty" def testHaveNamingEdges(theFeature, theModel, thePartDoc) : - """ Tests if all faces of result have a name + """ Tests if all edges of result have a name :param theFeature: feature to test. """ # Get feature result/sub-result @@ -198,6 +198,49 @@ def testHaveNamingEdges(theFeature, theModel, thePartDoc) : assert(shape.isEdge()) assert(name != ""), "String empty" +def testHaveNamingVertices(theFeature, theModel, thePartDoc) : + """ Tests if all vertices of result have a unique name + :param theFeature: feature to test. + """ + # Get feature result/sub-result + aResult = theFeature.results()[0].resultSubShapePair()[0] + # Get result/sub-result shape + shape = aResult.shape() + # Create shape explorer with desired shape type + shapeExplorer = GeomAPI_ShapeExplorer(shape, GeomAPI_Shape.VERTEX) + # Create list, and store selections in it + selectionList = [] + shapesList = [] # to append only unique shapes (not isSame) + while shapeExplorer.more(): + aDuplicate = False + for alreadyThere in shapesList: + if alreadyThere.isSame(shapeExplorer.current()): + aDuplicate = True + if aDuplicate: + shapeExplorer.next() + continue + shapesList.append(shapeExplorer.current()) + selection = theModel.selection(aResult, shapeExplorer.current()) # First argument should be result/sub-result, second is sub-shape on this result/sub-result + selectionList.append(selection) + shapeExplorer.next() + # Create group with this selection list + Group_1 = theModel.addGroup(thePartDoc, selectionList) + theModel.do() + + # Check that all selected shapes in group have right shape type and unique name. + groupFeature = Group_1.feature() + groupSelectionList = groupFeature.selectionList("group_list") + assert(groupSelectionList.size() == len(selectionList)) + presented_names = set() + for index in range(0, groupSelectionList.size()): + attrSelection = groupSelectionList.value(index) + shape = attrSelection.value() + name = attrSelection.namingName() + assert(shape.isVertex()) + assert(name != ""), "String empty" + presented_names.add(name) + assert(len(presented_names) == groupSelectionList.size()), "Some names are not unique" + def testNbSubFeatures(theComposite, theKindOfSub, theExpectedCount): """ Tests number of sub-features of the given type -- 2.39.2