From: lucasjerome Date: Thu, 4 Feb 2021 11:07:12 +0000 (+0100) Subject: Add Unit test, Traduction and doumentation X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ad1a2e89dfd56f1c9a026958767a4ce07209b4aa;p=modules%2Fshaper.git Add Unit test, Traduction and doumentation --- diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 766fde58f..404914009 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -691,4 +691,5 @@ ADD_UNIT_TESTS(TestExtrusion.py Test20245_2.py Test20245_3.py Test20247.py + TestLoft.py ) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Loft.cpp b/src/FeaturesPlugin/FeaturesPlugin_Loft.cpp index 0c30c0176..769494534 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Loft.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Loft.cpp @@ -148,43 +148,6 @@ void FeaturesPlugin_Loft::execute() } } } -/*================================================================================================= -GeomShapePtr FeaturesPlugin_Loft::getShape(const std::string& anID) -{ - AttributeSelectionPtr theSelection = selection(anID); - if (!theSelection.get()) { - setError("Error: One of the selected base objects is empty."); - return; - } - - GeomShapePtr aShape = theSelection->value(); - - if (aShape.get() && !aShape->isNull()) { - std::cout<<"C'est un shape"<(theSelection->context()); - if(!aConstruction.get()) { - setError("Error: One of selected sketches does not have results."); - return; - } - int aFacesNum = aConstruction->facesNum(); - if(aFacesNum == 0) { - // Probably it can be construction. - aShape = aConstruction->shape(); - if(aShape.get() && !aShape->isNull()) { - std::cout<<"C'est un aConstruction"< theFirstShape, - const std::shared_ptr theSecondShape, - const std::shared_ptr theLoftAlgo, - const int theResultIndex) -{ - // Create result body. - ResultBodyPtr aResultBody = document()->createBody(data(), theResultIndex); - - // Store generated shape. - aResultBody->storeGenerated(theFirstShape, theLoftAlgo->shape()); - aResultBody->storeGenerated(theSecondShape, theLoftAlgo->shape()); - - // Store generated edges/faces. - GeomAPI_Shape::ShapeType aBaseShapeType = theFirstShape->shapeType(); - GeomAPI_Shape::ShapeType aShapeTypeToExplode = GeomAPI_Shape::SHAPE; - - switch(aBaseShapeType) { - case GeomAPI_Shape::VERTEX: { - aShapeTypeToExplode = GeomAPI_Shape::VERTEX; - break; - } - case GeomAPI_Shape::EDGE: - case GeomAPI_Shape::WIRE: { - std::shared_ptr aV1, aV2; - GeomAlgoAPI_ShapeTools::findBounds(theFirstShape, aV1, aV2); - ListOfShape aV1History, aV2History; - theLoftAlgo->generated(aV1, aV1History); - theLoftAlgo->generated(aV2, aV2History); - if(!aV1History.empty()) { - aResultBody->generated(aV1, aV1History.front()); - } - if(!aV2History.empty()) { - aResultBody->generated(aV2, aV2History.front()); - } - GeomAlgoAPI_ShapeTools::findBounds(theSecondShape, aV1, aV2); - theLoftAlgo->generated(aV1, aV1History); - theLoftAlgo->generated(aV2, aV2History); - if(!aV1History.empty()) { - aResultBody->generated(aV1, aV1History.front()); - } - if(!aV2History.empty()) { - aResultBody->generated(aV2, aV2History.front()); - } - } - case GeomAPI_Shape::FACE: - case GeomAPI_Shape::SHELL: { - aShapeTypeToExplode = GeomAPI_Shape::EDGE; - break; - } - case GeomAPI_Shape::COMPOUND: { - aShapeTypeToExplode = GeomAPI_Shape::COMPOUND; - break; - } - default: - return; // unsupported type of shape - } - - if(aShapeTypeToExplode == GeomAPI_Shape::VERTEX || - aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) { - aResultBody->loadGeneratedShapes(theLoftAlgo, theFirstShape, GeomAPI_Shape::VERTEX); - aResultBody->loadGeneratedShapes(theLoftAlgo, theSecondShape, GeomAPI_Shape::VERTEX); - } - if(aShapeTypeToExplode == GeomAPI_Shape::EDGE || - aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) { - aResultBody->loadGeneratedShapes(theLoftAlgo, theFirstShape, GeomAPI_Shape::EDGE); - aResultBody->loadGeneratedShapes(theLoftAlgo, theSecondShape, GeomAPI_Shape::EDGE); - } - - // Store from shapes. - storeShapes(aResultBody, aBaseShapeType, theLoftAlgo->fromShapes(), "From_"); - - // Store to shapes. - storeShapes(aResultBody, aBaseShapeType, theLoftAlgo->toShapes(), "To_"); - - setResult(aResultBody, theResultIndex); -} - -//================================================================================================== -void FeaturesPlugin_Loft::storeShapes(ResultBodyPtr theResultBody, - const GeomAPI_Shape::ShapeType theBaseShapeType, - const ListOfShape& theShapes, - const std::string theName) -{ - GeomAPI_Shape::ShapeType aShapeTypeToExplore = GeomAPI_Shape::FACE; - std::string aShapeTypeStr = "Face"; - switch(theBaseShapeType) { - case GeomAPI_Shape::VERTEX: { - aShapeTypeToExplore = GeomAPI_Shape::VERTEX; - aShapeTypeStr = "Vertex"; - break; - } - case GeomAPI_Shape::EDGE: - case GeomAPI_Shape::WIRE: { - aShapeTypeToExplore = GeomAPI_Shape::EDGE; - aShapeTypeStr = "Edge"; - break; - } - case GeomAPI_Shape::FACE: - case GeomAPI_Shape::SHELL: { - aShapeTypeToExplore = GeomAPI_Shape::FACE; - aShapeTypeStr = "Face"; - break; - } - case GeomAPI_Shape::COMPOUND: { - aShapeTypeToExplore = GeomAPI_Shape::COMPOUND; - break; - } - default: - return; // unsupported type of shape - } - - // Store shapes. - int aShapeIndex = 1; - int aFaceIndex = 1; - for(ListOfShape::const_iterator anIt = theShapes.cbegin(); anIt != theShapes.cend(); ++anIt) { - GeomShapePtr aShape = *anIt; - - if(aShapeTypeToExplore == GeomAPI_Shape::COMPOUND) { - std::string aName = theName + (aShape->shapeType() == GeomAPI_Shape::EDGE ? "Edge" : "Face"); - storeSubShapeTT(theResultBody, aShape, - aShape->shapeType(), - aName, - aShape->shapeType() == GeomAPI_Shape::EDGE ? aShapeIndex : aFaceIndex); - } else { - std::string aName = theName + aShapeTypeStr; - storeSubShapeTT(theResultBody, aShape, aShapeTypeToExplore, aName, aShapeIndex); - } - } -} - -//================================================================================================== -void storeSubShapeTT(ResultBodyPtr theResultBody, - const GeomShapePtr theShape, - const GeomAPI_Shape::ShapeType theType, - const std::string theName, - int& theShapeIndex) -{ - for(GeomAPI_ShapeExplorer anExp(theShape, theType); anExp.more(); anExp.next()) { - GeomShapePtr aSubShape = anExp.current(); - std::ostringstream aStr; - aStr << theName << "_" << theShapeIndex++; - theResultBody->generated(aSubShape, aStr.str()); - } -} -*/ \ No newline at end of file diff --git a/src/FeaturesPlugin/FeaturesPlugin_msg_fr.ts b/src/FeaturesPlugin/FeaturesPlugin_msg_fr.ts index 66977d71f..a6aa36754 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_msg_fr.ts +++ b/src/FeaturesPlugin/FeaturesPlugin_msg_fr.ts @@ -65,6 +65,10 @@ Pipe Tuyau + + Loft + Lissage + Recover Récupérer @@ -1348,6 +1352,28 @@ + + + Loft + + Loft + Lissage + + + + Loft:first_object + + First object: + Premier objet: + + + + Loft:second_object + + Second object: + Deuxième objet: + + Recover diff --git a/src/FeaturesPlugin/Test/TestLoft.py b/src/FeaturesPlugin/Test/TestLoft.py new file mode 100644 index 000000000..31769d441 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestLoft.py @@ -0,0 +1,143 @@ +# Copyright (C) 2018-2020 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() + +### Create Part +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() + +### Create Sketch +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) + +### Create SketchLine +SketchLine_1 = Sketch_1.addLine(65.56914119359536, 34.84279475982533, -62.33478893740904, 34.84279475982533) + +### Create SketchLine +SketchLine_2 = Sketch_1.addLine(-62.33478893740904, 34.84279475982533, -62.33478893740904, -28.08005822416302) + +### Create SketchLine +SketchLine_3 = Sketch_1.addLine(-62.33478893740904, -28.08005822416302, 65.56914119359536, -28.08005822416302) + +### Create SketchLine +SketchLine_4 = Sketch_1.addLine(65.56914119359536, -28.08005822416302, 65.56914119359536, 34.84279475982533) +Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint()) +Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +Sketch_1.setHorizontal(SketchLine_1.result()) +Sketch_1.setVertical(SketchLine_2.result()) +Sketch_1.setHorizontal(SketchLine_3.result()) +Sketch_1.setVertical(SketchLine_4.result()) +model.do() + +### Create Plane +Plane_4 = model.addPlane(Part_1_doc, model.selection("EDGE", "Sketch_1/SketchLine_4"), model.selection("VERTEX", "Sketch_1/SketchLine_3_StartVertex"), False) + +### Create Plane +Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f"), 100, False) + +### Create Sketch +Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("YOZ")) + +### Create SketchCircle +SketchCircle_1 = Sketch_2.addCircle(60.9581866489876, 39.76685108527785, 26.86156014153439) +model.do() + +### Create Plane +Plane_6 = model.addPlane(Part_1_doc, model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r"), 100, False) + +### Create Box +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) + +### Create Box +Box_2 = model.addBox(Part_1_doc, 10, 10, 10) + +### Create Translation +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "all-in-Box_2")], axis = model.selection("EDGE", "PartSet/OY"), distance = 100, keepSubResults = True) + +### Create Wire +Wire_1_objects = [model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Right]"), + model.selection("EDGE", "[Box_1_1/Right][Box_1_1/Top]"), + model.selection("EDGE", "[Box_1_1/Back][Box_1_1/Right]"), + model.selection("EDGE", "[Box_1_1/Right][Box_1_1/Bottom]")] +Wire_1 = model.addWire(Part_1_doc, Wire_1_objects, False) + +### Create Wire +Wire_2_objects = [model.selection("EDGE", "[Translation_1_1_1/MF:Translated&Box_2_1/Left][Translation_1_1_1/MF:Translated&Box_2_1/Top]"), + model.selection("EDGE", "[Translation_1_1_1/MF:Translated&Box_2_1/Front][Translation_1_1_1/MF:Translated&Box_2_1/Left]"), + model.selection("EDGE", "[Translation_1_1_1/MF:Translated&Box_2_1/Left][Translation_1_1_1/MF:Translated&Box_2_1/Bottom]"), + model.selection("EDGE", "[Translation_1_1_1/MF:Translated&Box_2_1/Back][Translation_1_1_1/MF:Translated&Box_2_1/Left]")] +Wire_2 = model.addWire(Part_1_doc, Wire_2_objects, False) + +### Create Box +Box_3 = model.addBox(Part_1_doc, 10, 10, 10) + +### Create Wire +Wire_3 = model.addWire(Part_1_doc, [model.selection("EDGE", "[Box_3_1/Left][Box_3_1/Top]"), model.selection("EDGE", "[Box_3_1/Front][Box_3_1/Left]")], False) + +### Create Box +Box_4 = model.addBox(Part_1_doc, 10, 10, 10) + +### Create Translation +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "all-in-Box_4")], axis = model.selection("EDGE", "PartSet/OY"), distance = 40, keepSubResults = True) + +### Create Wire +Wire_4 = model.addWire(Part_1_doc, [model.selection("EDGE", "[Translation_2_1_1/MF:Translated&Box_4_1/Left][Translation_2_1_1/MF:Translated&Box_4_1/Top]"), model.selection("EDGE", "[Translation_2_1_1/MF:Translated&Box_4_1/Front][Translation_2_1_1/MF:Translated&Box_4_1/Left]")], False) + +### Create Loft +Loft_1 = model.addLoft(Part_1_doc, model.selection("FACE", "Plane_2"), model.selection("FACE", "Plane_1")) + +### Create Loft +Loft_2 = model.addLoft(Part_1_doc, model.selection("WIRE", "Wire_2_1"), model.selection("WIRE", "Wire_1_1")) + +### Create Loft +Loft_3 = model.addLoft(Part_1_doc, model.selection("WIRE", "Wire_3_1"), model.selection("WIRE", "Wire_4_1")) + +### Create Loft +Loft_4 = model.addLoft(Part_1_doc, model.selection("EDGE", "Sketch_1/SketchLine_2"), model.selection("EDGE", "Sketch_1/SketchLine_4")) + +model.end() + +from GeomAPI import GeomAPI_Shape + +#test loft with two face +model.testNbResults(Loft_1, 1) +model.testNbSubResults(Loft_1, [0]) +model.testNbSubShapes(Loft_1, GeomAPI_Shape.SOLID, [1]) + + +#test loft with two wire +model.testNbResults(Loft_2, 1) +model.testNbSubResults(Loft_2, [0]) +model.testNbSubShapes(Loft_2, GeomAPI_Shape.SHELL, [1]) + +#test loft with two wire +model.testNbResults(Loft_3, 1) +model.testNbSubResults(Loft_3, [0]) +model.testNbSubShapes(Loft_3, GeomAPI_Shape.SHELL, [1]) + +#test loft with two edge +model.testNbResults(Loft_4, 1) +model.testNbSubResults(Loft_4, [0]) +model.testNbSubShapes(Loft_4, GeomAPI_Shape.FACE, [1]) + diff --git a/src/FeaturesPlugin/doc/FeaturesPlugin.rst b/src/FeaturesPlugin/doc/FeaturesPlugin.rst index d3d384b68..348e5e365 100644 --- a/src/FeaturesPlugin/doc/FeaturesPlugin.rst +++ b/src/FeaturesPlugin/doc/FeaturesPlugin.rst @@ -23,6 +23,7 @@ Features plug-in provides a set of common topological operations. It implements fuseFeatureFaces.rst importResultFeature.rst linearCopyFeature.rst + loftFeature.rst measurementFeature.rst pipeFeature.rst placementFeature.rst diff --git a/src/FeaturesPlugin/doc/TUI_loftFeature.rst b/src/FeaturesPlugin/doc/TUI_loftFeature.rst new file mode 100644 index 000000000..c97cf3fc9 --- /dev/null +++ b/src/FeaturesPlugin/doc/TUI_loftFeature.rst @@ -0,0 +1,11 @@ + + .. _tui_loft: + +loft +==== + +.. literalinclude:: examples/loft.py + :linenos: + :language: python + +:download:`Download this script ` diff --git a/src/FeaturesPlugin/doc/examples/loft.py b/src/FeaturesPlugin/doc/examples/loft.py new file mode 100644 index 000000000..f3f9dfebe --- /dev/null +++ b/src/FeaturesPlugin/doc/examples/loft.py @@ -0,0 +1,45 @@ +from SketchAPI import * + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() + +### Create Part +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() + +### Create Sketch +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) + +### Create SketchLine +SketchLine_1 = Sketch_1.addLine(65.56914119359536, 34.84279475982533, -62.33478893740904, 34.84279475982533) + +### Create SketchLine +SketchLine_2 = Sketch_1.addLine(-62.33478893740904, 34.84279475982533, -62.33478893740904, -28.08005822416302) + +### Create SketchLine +SketchLine_3 = Sketch_1.addLine(-62.33478893740904, -28.08005822416302, 65.56914119359536, -28.08005822416302) + +### Create SketchLine +SketchLine_4 = Sketch_1.addLine(65.56914119359536, -28.08005822416302, 65.56914119359536, 34.84279475982533) +Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint()) +Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +Sketch_1.setHorizontal(SketchLine_1.result()) +Sketch_1.setVertical(SketchLine_2.result()) +Sketch_1.setHorizontal(SketchLine_3.result()) +Sketch_1.setVertical(SketchLine_4.result()) +model.do() + +### Create Plane +Plane_1 = model.addPlane(Part_1_doc, model.selection("EDGE", "Sketch_1/SketchLine_4"), model.selection("VERTEX", "Sketch_1/SketchLine_3_StartVertex"), False) + +### Create Plane +Plane_2 = model.addPlane(Part_1_doc, model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f"), 100, False) + +### Create Loft +Loft_1 = model.addLoft(Part_1_doc, model.selection("FACE", "Plane_1"), model.selection("FACE", "Plane_2")) + +model.end() diff --git a/src/FeaturesPlugin/doc/images/loft.png b/src/FeaturesPlugin/doc/images/loft.png new file mode 100644 index 000000000..892ead927 Binary files /dev/null and b/src/FeaturesPlugin/doc/images/loft.png differ diff --git a/src/FeaturesPlugin/doc/images/loftPropertyPanel.png b/src/FeaturesPlugin/doc/images/loftPropertyPanel.png new file mode 100644 index 000000000..760244331 Binary files /dev/null and b/src/FeaturesPlugin/doc/images/loftPropertyPanel.png differ diff --git a/src/FeaturesPlugin/doc/images/resultLoft.png b/src/FeaturesPlugin/doc/images/resultLoft.png new file mode 100644 index 000000000..acf0013cd Binary files /dev/null and b/src/FeaturesPlugin/doc/images/resultLoft.png differ diff --git a/src/FeaturesPlugin/doc/loftFeature.rst b/src/FeaturesPlugin/doc/loftFeature.rst new file mode 100644 index 000000000..dd017a948 --- /dev/null +++ b/src/FeaturesPlugin/doc/loftFeature.rst @@ -0,0 +1,45 @@ +.. |loft.icon| image:: images/loft.png + +Loft +==== + +**Loft** feature is used to create a face, shell or a solid shape from two or more objects. +The two objects can be edges, wires or faces. + +To create a Loft in the active part: + +#. select in the Main Menu *Features - > Loft* item or +#. click |loft.icon| **Loft** button in the toolbar + +The following property panel appears. + +.. figure:: images/loftPropertyPanel.png + :align: center + + Loft property panel + +Input fields: + +- **First object** defines the first shape (edge, wire, face) selected in 3D OCC viewer or object browser; +- **Second object** defines the second shape (edge, wire, face) selected in 3D OCC viewer or object browser; + +**TUI Command**: + +.. py:function:: model.addLoft(Part_doc, [shape], [shape]) + + :param part: The current part object. + :param object: A shape in format *model.selection(TYPE, shape)*. + :param object: A shape in format *model.selection(TYPE, shape)*. + :return: Created object. + +Result +"""""" + +Result of loft between two faces. + +.. figure:: images/resultLoft.png + :align: center + + Loft between two faces + +**See Also** a sample TUI Script of :ref:`tui_loft` operation. \ No newline at end of file diff --git a/src/FeaturesPlugin/loft_widget.xml b/src/FeaturesPlugin/loft_widget.xml index e88c48b55..21dc390d6 100644 --- a/src/FeaturesPlugin/loft_widget.xml +++ b/src/FeaturesPlugin/loft_widget.xml @@ -3,6 +3,7 @@ label="First object:" tooltip="Select a object" shape_types="edge face wire" + concealment="true" default=""> @@ -10,6 +11,7 @@ label="Second object:" tooltip="Select a object" shape_types="edge face wire" + concealment="true" default=""> diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index 6c2d309c1..4c5a102bf 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -40,7 +40,7 @@ + icon="icons/Features/loft.png" helpfile="loftFeature.html">