From: azv Date: Tue, 18 Dec 2018 07:57:44 +0000 (+0300) Subject: [Code coverage FeaturesAPI]: Improve coverage of Scale, Rotation, Revolution and... X-Git-Tag: End2018~50 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=16d69b8d41275b598e0fb9c215181de7926d8c05;p=modules%2Fshaper.git [Code coverage FeaturesAPI]: Improve coverage of Scale, Rotation, Revolution and Extrusion features --- diff --git a/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp b/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp index 5e2975ac3..746637b5c 100644 --- a/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp @@ -175,11 +175,7 @@ void FeaturesAPI_Extrusion::setSizes(const ModelHighAPI_Double& theToSize, //================================================================================================== void FeaturesAPI_Extrusion::setSize(const ModelHighAPI_Double& theSize) { - fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod); - fillAttribute(theSize, mytoSize); - fillAttribute(ModelHighAPI_Double(), myfromSize); - - execIfBaseNotEmpty(); + setSizes(theSize, ModelHighAPI_Double()); } //================================================================================================== diff --git a/src/FeaturesAPI/FeaturesAPI_ExtrusionBoolean.cpp b/src/FeaturesAPI/FeaturesAPI_ExtrusionBoolean.cpp index 1b16e2aff..c78fe3a47 100644 --- a/src/FeaturesAPI/FeaturesAPI_ExtrusionBoolean.cpp +++ b/src/FeaturesAPI/FeaturesAPI_ExtrusionBoolean.cpp @@ -89,11 +89,7 @@ void FeaturesAPI_ExtrusionBoolean::setSizes(const ModelHighAPI_Double& theToSize //================================================================================================== void FeaturesAPI_ExtrusionBoolean::setSize(const ModelHighAPI_Double& theSize) { - fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod); - fillAttribute(theSize, mytoSize); - fillAttribute(ModelHighAPI_Double(), myfromSize); - - execIfBaseNotEmpty(); + setSizes(theSize, ModelHighAPI_Double()); } //================================================================================================== @@ -198,9 +194,7 @@ FeaturesAPI_ExtrusionCut::FeaturesAPI_ExtrusionCut( { if(initialize()) { fillAttribute(theBaseObjects, mybaseObjects); - fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod); - fillAttribute(theSize, mytoSize); - fillAttribute(ModelHighAPI_Double(), myfromSize); + setSize(theSize); setBooleanObjects(theBooleanObjects); } } @@ -217,9 +211,7 @@ FeaturesAPI_ExtrusionCut::FeaturesAPI_ExtrusionCut( if(initialize()) { fillAttribute(theBaseObjects, mybaseObjects); fillAttribute(theDirection, mydirection); - fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod); - fillAttribute(theSize, mytoSize); - fillAttribute(ModelHighAPI_Double(), myfromSize); + setSize(theSize); setBooleanObjects(theBooleanObjects); } } @@ -235,9 +227,7 @@ FeaturesAPI_ExtrusionCut::FeaturesAPI_ExtrusionCut( { if(initialize()) { fillAttribute(theBaseObjects, mybaseObjects); - fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod); - fillAttribute(theToSize, mytoSize); - fillAttribute(theFromSize, myfromSize); + setSizes(theToSize, theFromSize); setBooleanObjects(theBooleanObjects); } } @@ -255,9 +245,7 @@ FeaturesAPI_ExtrusionCut::FeaturesAPI_ExtrusionCut( if(initialize()) { fillAttribute(theBaseObjects, mybaseObjects); fillAttribute(theDirection, mydirection); - fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod); - fillAttribute(theToSize, mytoSize); - fillAttribute(theFromSize, myfromSize); + setSizes(theToSize, theFromSize); setBooleanObjects(theBooleanObjects); } } @@ -425,9 +413,7 @@ FeaturesAPI_ExtrusionFuse::FeaturesAPI_ExtrusionFuse( { if(initialize()) { fillAttribute(theBaseObjects, mybaseObjects); - fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod); - fillAttribute(theSize, mytoSize); - fillAttribute(ModelHighAPI_Double(), myfromSize); + setSize(theSize); setBooleanObjects(theBooleanObjects); } } @@ -444,9 +430,7 @@ FeaturesAPI_ExtrusionFuse::FeaturesAPI_ExtrusionFuse( if(initialize()) { fillAttribute(theBaseObjects, mybaseObjects); fillAttribute(theDirection, mydirection); - fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod); - fillAttribute(theSize, mytoSize); - fillAttribute(ModelHighAPI_Double(), myfromSize); + setSize(theSize); setBooleanObjects(theBooleanObjects); } } @@ -462,9 +446,7 @@ FeaturesAPI_ExtrusionFuse::FeaturesAPI_ExtrusionFuse( { if(initialize()) { fillAttribute(theBaseObjects, mybaseObjects); - fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod); - fillAttribute(theToSize, mytoSize); - fillAttribute(theFromSize, myfromSize); + setSizes(theToSize, theFromSize); setBooleanObjects(theBooleanObjects); } } @@ -482,9 +464,7 @@ FeaturesAPI_ExtrusionFuse::FeaturesAPI_ExtrusionFuse( if(initialize()) { fillAttribute(theBaseObjects, mybaseObjects); fillAttribute(theDirection, mydirection); - fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod); - fillAttribute(theToSize, mytoSize); - fillAttribute(theFromSize, myfromSize); + setSizes(theToSize, theFromSize); setBooleanObjects(theBooleanObjects); } } diff --git a/src/FeaturesAPI/FeaturesAPI_Revolution.cpp b/src/FeaturesAPI/FeaturesAPI_Revolution.cpp index 47a1ffc22..ef0320ce7 100644 --- a/src/FeaturesAPI/FeaturesAPI_Revolution.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Revolution.cpp @@ -139,11 +139,7 @@ void FeaturesAPI_Revolution::setAngles(const ModelHighAPI_Double& theToAngle, //================================================================================================== void FeaturesAPI_Revolution::setAngle(const ModelHighAPI_Double& theAngle) { - fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod); - fillAttribute(theAngle, mytoAngle); - fillAttribute(ModelHighAPI_Double(), myfromAngle); - - execIfBaseNotEmpty(); + setAngles(theAngle, ModelHighAPI_Double()); } //================================================================================================== diff --git a/src/FeaturesAPI/FeaturesAPI_RevolutionBoolean.cpp b/src/FeaturesAPI/FeaturesAPI_RevolutionBoolean.cpp index 030de04c9..c31bafc87 100644 --- a/src/FeaturesAPI/FeaturesAPI_RevolutionBoolean.cpp +++ b/src/FeaturesAPI/FeaturesAPI_RevolutionBoolean.cpp @@ -89,11 +89,7 @@ void FeaturesAPI_RevolutionBoolean::setAngles(const ModelHighAPI_Double& theToAn //================================================================================================== void FeaturesAPI_RevolutionBoolean::setAngle(const ModelHighAPI_Double& theAngle) { - fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod); - fillAttribute(theAngle, mytoAngle); - fillAttribute(ModelHighAPI_Double(), myfromAngle); - - execIfBaseNotEmpty(); + setAngles(theAngle, ModelHighAPI_Double()); } //================================================================================================== @@ -202,9 +198,7 @@ FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut( if(initialize()) { fillAttribute(theBaseObjects, mybaseObjects); fillAttribute(theAxis, myaxis); - fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod); - fillAttribute(theSize, mytoAngle); - fillAttribute(ModelHighAPI_Double(), myfromAngle); + setAngle(theSize); setBooleanObjects(theBooleanObjects); } } diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 35459c7f3..7460a5b38 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -170,12 +170,21 @@ INSTALL(FILES ${TEXT_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}) ADD_UNIT_TESTS(TestExtrusion.py TestExtrusionCut.py + TestExtrusionCut_BySize.py + TestExtrusionCut_ByPlanesAndOffsets.py TestExtrusionFuse.py + TestExtrusionFuse_BySize.py + TestExtrusionFuse_ByPlanesAndOffsets.py TestExtrusion_ErrorMsg.py TestExtrusion_ZeroOffsetError.py TestRevolution.py + TestRevolution_ByAngle.py TestRevolutionCut.py + TestRevolutionCut_ByAngle.py + TestRevolutionCut_ByPlanesAndOffsets.py TestRevolutionFuse.py + TestRevolutionFuse_ByAngle.py + TestRevolutionFuse_ByPlanesAndOffsets.py TestCompositeFeaturesOnCompSolids.py TestPartition.py TestPartition_ErrorMsg.py @@ -191,6 +200,8 @@ ADD_UNIT_TESTS(TestExtrusion.py TestTranslation.py TestTranslation_Part.py TestRotation.py + TestRotation_ByAxis.py + TestRotation_ByPoints.py TestRotation_ErrorMsg.py TestMultiRotation_Part.py TestMultiRotation_ErrorMsg.py @@ -414,6 +425,8 @@ ADD_UNIT_TESTS(TestExtrusion.py TestFillet.py TestFillet1.py TestFillet_ErrorMsg.py + TestScale1.py + TestScale2.py Test1816.py Test2631.py Test2650.py diff --git a/src/FeaturesPlugin/Test/TestExtrusionCut_ByPlanesAndOffsets.py b/src/FeaturesPlugin/Test/TestExtrusionCut_ByPlanesAndOffsets.py new file mode 100644 index 000000000..6c118349a --- /dev/null +++ b/src/FeaturesPlugin/Test/TestExtrusionCut_ByPlanesAndOffsets.py @@ -0,0 +1,65 @@ +## Copyright (C) 2018-20xx 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 +from GeomAPI import * +from SketchAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Axis_4 = model.addAxis(Part_1_doc, 10, 10, 10) + +ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [], model.selection(), model.selection("FACE", "Box_1_1/Right"), 0, model.selection(), 0, [model.selection("SOLID", "Box_1_1")]) +Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Left")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchCircle_1 = Sketch_1.addCircle(5, 10, 2) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchCircle_1.center()) +ExtrusionCut_1.setNestedSketch(Sketch_1) +model.do() +Shape = ExtrusionCut_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5, 5, 4.97049494) + +ExtrusionCut_2 = model.addExtrusionCut(Part_1_doc, [], model.selection("EDGE", "Axis_1"), model.selection(), 0, model.selection("FACE", "ExtrusionCut_1_1/Modified_Face&Box_1_1/Left"), 0, [model.selection("SOLID", "ExtrusionCut_1_1")]) +Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Front")) +SketchCircle_2 = Sketch_2.addCircle(10, 10, 2.040695131136049) +SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "[ExtrusionCut_1_1/Modified_Face&Box_1_1/Right][Box_1_1/Front][ExtrusionCut_1_1/Modified_Face&Box_1_1/Top&weak_name_2]"), False) +SketchPoint_1 = SketchProjection_2.createdFeature() +SketchConstraintCoincidence_2 = Sketch_2.setCoincident(SketchCircle_2.center(), SketchAPI_Point(SketchPoint_1).coordinates()) +ExtrusionCut_2.setNestedSketch(Sketch_2) +model.do() +Shape = ExtrusionCut_2.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5.00107093476, 4.96064972557, 4.9770664027) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestExtrusionCut_BySize.py b/src/FeaturesPlugin/Test/TestExtrusionCut_BySize.py new file mode 100644 index 000000000..907d22b0a --- /dev/null +++ b/src/FeaturesPlugin/Test/TestExtrusionCut_BySize.py @@ -0,0 +1,58 @@ +## Copyright (C) 2018-20xx 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 +from GeomAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Axis_1 = model.addAxis(Part_1_doc, 0, -10, 10) + +ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [], model.selection(), -5, [model.selection("SOLID", "Box_1_1")]) +Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Left")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchCircle_1 = Sketch_1.addCircle(5, 10, 2) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchCircle_1.center()) +ExtrusionCut_1.setNestedSketch(Sketch_1) +model.do() +Shape = ExtrusionCut_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5, 5.004704015828, 5.02793455788) + +ExtrusionCut_1.setDirection(model.selection("EDGE", "Axis_1")) +model.do() +Shape = ExtrusionCut_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5.00027719467643, 4.861055360637628, 5.101882685002874) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestExtrusionFuse_ByPlanesAndOffsets.py b/src/FeaturesPlugin/Test/TestExtrusionFuse_ByPlanesAndOffsets.py new file mode 100644 index 000000000..941f6bacf --- /dev/null +++ b/src/FeaturesPlugin/Test/TestExtrusionFuse_ByPlanesAndOffsets.py @@ -0,0 +1,65 @@ +## Copyright (C) 2018-20xx 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 +from GeomAPI import * +from SketchAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Axis_4 = model.addAxis(Part_1_doc, 10, 10, 10) + +ExtrusionFuse_1 = model.addExtrusionFuse(Part_1_doc, [], model.selection(), model.selection("FACE", "Box_1_1/Right"), 0, model.selection(), 0, [model.selection("SOLID", "Box_1_1")]) +Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Left")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchCircle_1 = Sketch_1.addCircle(5, 10, 2) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchCircle_1.center()) +ExtrusionFuse_1.setNestedSketch(Sketch_1) +model.do() +Shape = ExtrusionFuse_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5, 5, 5.421244124) + +ExtrusionFuse_2 = model.addExtrusionFuse(Part_1_doc, [], model.selection("EDGE", "Axis_1"), model.selection(), 0, model.selection("FACE", "ExtrusionFuse_1_1/Modified_Face&Box_1_1/Left&ExtrusionFuse_1_1/From_Face"), 0, [model.selection("SOLID", "ExtrusionFuse_1_1")]) +Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Front")) +SketchCircle_2 = Sketch_2.addCircle(10, 10, 2.040695131136049) +SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "[(Box_1_1/Back)(Box_1_1/Bottom)(Box_1_1/Front)(ExtrusionFuse_1_1/Modified_Face&Box_1_1/Right&ExtrusionFuse_1_1/To_Face)][Box_1_1/Bottom][Box_1_1/Front]"), False) +SketchPoint_1 = SketchProjection_2.createdFeature() +SketchConstraintCoincidence_2 = Sketch_2.setCoincident(SketchCircle_2.center(), SketchAPI_Point(SketchPoint_1).coordinates()) +ExtrusionFuse_2.setNestedSketch(Sketch_2) +model.do() +Shape = ExtrusionFuse_2.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 4.88886637164, 4.89804988224, 2.94104936673) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestExtrusionFuse_BySize.py b/src/FeaturesPlugin/Test/TestExtrusionFuse_BySize.py new file mode 100644 index 000000000..3d7ce1a85 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestExtrusionFuse_BySize.py @@ -0,0 +1,58 @@ +## Copyright (C) 2018-20xx 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 +from GeomAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Axis_1 = model.addAxis(Part_1_doc, 0, 10, -10) + +ExtrusionFuse_1 = model.addExtrusionFuse(Part_1_doc, [], model.selection(), -5, [model.selection("SOLID", "Box_1_1")]) +Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Left")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchCircle_1 = Sketch_1.addCircle(5, 10, 2) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchCircle_1.center()) +ExtrusionFuse_1.setNestedSketch(Sketch_1) +model.do() +Shape = ExtrusionFuse_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5, 4.903914353, 5.273370165) + +ExtrusionFuse_1.setDirection(model.selection("EDGE", "Axis_1")) +model.do() +Shape = ExtrusionFuse_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5, 4.299736969, 5.70604613) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestRevolutionCut_ByAngle.py b/src/FeaturesPlugin/Test/TestRevolutionCut_ByAngle.py new file mode 100644 index 000000000..54382546b --- /dev/null +++ b/src/FeaturesPlugin/Test/TestRevolutionCut_ByAngle.py @@ -0,0 +1,57 @@ +## Copyright (C) 2018-20xx 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 +from GeomAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) + +RevolutionCut_1 = model.addRevolutionCut(Part_1_doc, [], model.selection("EDGE", "PartSet/OZ"), 45, [model.selection("SOLID", "Box_1_1")]) +Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Left")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchCircle_1 = Sketch_1.addCircle(5, 10, 2) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchCircle_1.center()) +RevolutionCut_1.setNestedSketch(Sketch_1) +model.do() +Shape = RevolutionCut_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 4.985950242219446, 4.993794269643578, 5.022028013265849) + +RevolutionCut_1.setAxis(model.selection("EDGE", "PartSet/OX")) +model.do() +Shape = RevolutionCut_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5, 5, 5) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestRevolutionCut_ByPlanesAndOffsets.py b/src/FeaturesPlugin/Test/TestRevolutionCut_ByPlanesAndOffsets.py new file mode 100644 index 000000000..ff24745af --- /dev/null +++ b/src/FeaturesPlugin/Test/TestRevolutionCut_ByPlanesAndOffsets.py @@ -0,0 +1,57 @@ +## Copyright (C) 2018-20xx 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 +from GeomAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) + +RevolutionCut_1 = model.addRevolutionCut(Part_1_doc, [], model.selection("EDGE", "PartSet/OX"), model.selection("FACE", "Box_1_1/Right"), 0, model.selection(), 0, [model.selection("SOLID", "Box_1_1")]) +Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Left")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchCircle_1 = Sketch_1.addCircle(5, 10, 2) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchCircle_1.center()) +RevolutionCut_1.setNestedSketch(Sketch_1) +model.do() +Shape = RevolutionCut_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5, 5.15948561, 5.15948561) + +RevolutionCut_1.setPlanesAndOffsets(model.selection(), 0, model.selection("FACE", "Box_1_1/Bottom"), 3) +model.do() +Shape = RevolutionCut_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5, 5.23264, 5.07457446) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestRevolutionFuse_ByAngle.py b/src/FeaturesPlugin/Test/TestRevolutionFuse_ByAngle.py new file mode 100644 index 000000000..5fe7a3493 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestRevolutionFuse_ByAngle.py @@ -0,0 +1,57 @@ +## Copyright (C) 2018-20xx 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 +from GeomAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) + +RevolutionFuse_1 = model.addRevolutionFuse(Part_1_doc, [], model.selection("EDGE", "PartSet/OZ"), 45, [model.selection("SOLID", "Box_1_1")]) +Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Left")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchCircle_1 = Sketch_1.addCircle(5, 10, 2) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchCircle_1.center()) +RevolutionFuse_1.setNestedSketch(Sketch_1) +model.do() +Shape = RevolutionFuse_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 4.98623430526137, 4.892827903704557, 5.240928197091025) + +RevolutionFuse_1.setAxis(model.selection("EDGE", "PartSet/OX")) +model.do() +Shape = RevolutionFuse_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5, 3.5650977446, 5.63206191645) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestRevolutionFuse_ByPlanesAndOffsets.py b/src/FeaturesPlugin/Test/TestRevolutionFuse_ByPlanesAndOffsets.py new file mode 100644 index 000000000..0e6588904 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestRevolutionFuse_ByPlanesAndOffsets.py @@ -0,0 +1,57 @@ +## Copyright (C) 2018-20xx 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 +from GeomAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) + +RevolutionFuse_1 = model.addRevolutionFuse(Part_1_doc, [], model.selection("EDGE", "PartSet/OX"), model.selection("FACE", "Box_1_1/Right"), 0, model.selection(), 0, [model.selection("SOLID", "Box_1_1")]) +Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Left")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchCircle_1 = Sketch_1.addCircle(5, 10, 2) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchCircle_1.center()) +RevolutionFuse_1.setNestedSketch(Sketch_1) +model.do() +Shape = RevolutionFuse_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5, 1.31869538592, 1.538946730649) + +RevolutionFuse_1.setPlanesAndOffsets(model.selection(), 0, model.selection("FACE", "Box_1_1/Bottom"), 0) +model.do() +Shape = RevolutionFuse_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5, 1.98775395252, 5.352665608174) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestRevolution_ByAngle.py b/src/FeaturesPlugin/Test/TestRevolution_ByAngle.py new file mode 100644 index 000000000..bd565e28c --- /dev/null +++ b/src/FeaturesPlugin/Test/TestRevolution_ByAngle.py @@ -0,0 +1,53 @@ +## Copyright (C) 2018-20xx 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 +from GeomAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() + +Revolution_1 = model.addRevolution(Part_1_doc, [], model.selection("EDGE", "PartSet/OZ"), 90) +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("YOZ")) +SketchCircle_1 = Sketch_1.addCircle(30, 20, 15) +Revolution_1.setNestedSketch(Sketch_1) +model.do() +Shape = Revolution_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, -19.9197187127138, 19.9197187127138, 20) + +Revolution_1.setAxis(model.selection("EDGE", "PartSet/OY")) +model.do() +Shape = Revolution_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 14.2731178230633, 30, 14.2731178230633) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestRotation_ByAxis.py b/src/FeaturesPlugin/Test/TestRotation_ByAxis.py new file mode 100644 index 000000000..95329c92c --- /dev/null +++ b/src/FeaturesPlugin/Test/TestRotation_ByAxis.py @@ -0,0 +1,54 @@ +## Copyright (C) 2018-20xx 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 +from GeomAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 5) + +Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "[Box_1_1/Back][Box_1_1/Left]"), 45) +Shape = Rotation_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 0, 7.071067811865, 5) + +Rotation_1.setAxisObject(model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Left]")) +Shape = Rotation_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 2.928932188135, 0, 5) + +Rotation_1.setMainObjects([model.selection("SOLID", "Sphere_1_1")]) +Shape = Rotation_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 2.928932188135, -7.071067811865, 0) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestRotation_ByPoints.py b/src/FeaturesPlugin/Test/TestRotation_ByPoints.py new file mode 100644 index 000000000..b23c47e7d --- /dev/null +++ b/src/FeaturesPlugin/Test/TestRotation_ByPoints.py @@ -0,0 +1,46 @@ +## Copyright (C) 2018-20xx 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 +from GeomAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 5) + +Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("VERTEX", "[Box_1_1/Back][Box_1_1/Left][Box_1_1/Bottom]"), model.selection("VERTEX", "[Box_1_1/Front][Box_1_1/Left][Box_1_1/Bottom]"), model.selection("VERTEX", "[Box_1_1/Front][Box_1_1/Right][Box_1_1/Bottom]")) +Shape = Rotation_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 0, 7.071067811865, 5) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestScale1.py b/src/FeaturesPlugin/Test/TestScale1.py new file mode 100644 index 000000000..b1f6b0469 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestScale1.py @@ -0,0 +1,55 @@ +## Copyright (C) 2018-20xx 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 +from GeomAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 5) + +Scale_1 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_1_1")] , model.selection("VERTEX", "[Box_1_1/Back][Box_1_1/Left][Box_1_1/Bottom]"), 2) +Shape = Scale_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 10, 10, 10) + +Scale_1.setCenterPoint(model.selection("VERTEX", "[Box_1_1/Front][Box_1_1/Left][Box_1_1/Bottom]")) +Shape = Scale_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 0, 10, 10) + +Scale_1.setMainObjects([model.selection("SOLID", "Sphere_1_1")]) +Shape = Scale_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, -10, 0, 0) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestScale2.py b/src/FeaturesPlugin/Test/TestScale2.py new file mode 100644 index 000000000..8046c2129 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestScale2.py @@ -0,0 +1,55 @@ +## Copyright (C) 2018-20xx 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 +from GeomAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 5) + +Scale_1 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_1_1")] , model.selection("VERTEX", "[Box_1_1/Back][Box_1_1/Left][Box_1_1/Bottom]"), 1 , 2, 4) +model.do() +Shape = Scale_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5, 10, 20) + +Scale_1.setCenterPoint(model.selection("VERTEX", "[Box_1_1/Front][Box_1_1/Left][Box_1_1/Bottom]")) +Shape = Scale_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 5, 10, 20) + +Scale_1.setMainObjects([model.selection("SOLID", "Sphere_1_1")]) +Shape = Scale_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 0.0058892, 0, 0) + +model.end() + +assert(model.checkPythonDump())