From: azv Date: Fri, 21 Feb 2020 09:12:19 +0000 (+0300) Subject: Task 3.2. To keep compounds’ sub-shapes for all operations (issue #3139) X-Git-Tag: V9_5_0a1^2~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=68cdca74771f85658ce633f1e2504f0c741ab078;p=modules%2Fshaper.git Task 3.2. To keep compounds’ sub-shapes for all operations (issue #3139) Refactor the Scale feature. --- diff --git a/src/FeaturesAPI/FeaturesAPI.i b/src/FeaturesAPI/FeaturesAPI.i index 965d8b33f..2dfba2c48 100644 --- a/src/FeaturesAPI/FeaturesAPI.i +++ b/src/FeaturesAPI/FeaturesAPI.i @@ -44,6 +44,7 @@ %feature("kwargs") addPartition; %feature("kwargs") addPlacement; %feature("kwargs") addRotation; +%feature("kwargs") addScale; %feature("kwargs") addSplit; %feature("kwargs") addSmash; %feature("kwargs") addSymmetry; diff --git a/src/FeaturesAPI/FeaturesAPI_Scale.cpp b/src/FeaturesAPI/FeaturesAPI_Scale.cpp index fcb4d331a..0190ce2d5 100644 --- a/src/FeaturesAPI/FeaturesAPI_Scale.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Scale.cpp @@ -130,17 +130,10 @@ void FeaturesAPI_Scale::dump(ModelHighAPI_Dumper& theDumper) const theDumper << ", " << anAttrScaleFactorZ; } - theDumper << ")" << std::endl; -} + if (!aBase->data()->version().empty()) + theDumper << ", keepSubResults = True"; -//================================================================================================== -ScalePtr addScale(const std::shared_ptr& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Selection& theCenterPoint, - const ModelHighAPI_Double& theScaleFactor) -{ - std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Scale::ID()); - return ScalePtr(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint, theScaleFactor)); + theDumper << ")" << std::endl; } //================================================================================================== @@ -149,9 +142,17 @@ ScalePtr addScale(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theCenterPoint, const ModelHighAPI_Double& theScaleFactorX, const ModelHighAPI_Double& theScaleFactorY, - const ModelHighAPI_Double& theScaleFactorZ) + const ModelHighAPI_Double& theScaleFactorZ, + const bool keepSubResults) { std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Scale::ID()); - return ScalePtr(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint, - theScaleFactorX, theScaleFactorY, theScaleFactorZ)); + if (!keepSubResults) + aFeature->data()->setVersion(""); + ScalePtr aScale; + if (theScaleFactorY.value() == 0 && theScaleFactorZ.value() == 0) + aScale.reset(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint, theScaleFactorX)); + else + aScale.reset(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint, + theScaleFactorX, theScaleFactorY, theScaleFactorZ)); + return aScale; } \ No newline at end of file diff --git a/src/FeaturesAPI/FeaturesAPI_Scale.h b/src/FeaturesAPI/FeaturesAPI_Scale.h index 0ea718acc..298ff8e30 100644 --- a/src/FeaturesAPI/FeaturesAPI_Scale.h +++ b/src/FeaturesAPI/FeaturesAPI_Scale.h @@ -24,10 +24,10 @@ #include +#include #include #include -class ModelHighAPI_Double; class ModelHighAPI_Dumper; class ModelHighAPI_Selection; @@ -104,14 +104,6 @@ public: /// Pointer on Scale object. typedef std::shared_ptr ScalePtr; -/// \ingroup CPPHighAPI -/// \brief Create Scale feature. -FEATURESAPI_EXPORT -ScalePtr addScale(const std::shared_ptr& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Selection& theCenterPoint, - const ModelHighAPI_Double& theScaleFactor); - /// \ingroup CPPHighAPI /// \brief Create Scale feature. FEATURESAPI_EXPORT @@ -119,7 +111,8 @@ ScalePtr addScale(const std::shared_ptr& thePart, const std::list& theMainObjects, const ModelHighAPI_Selection& theCenterPoint, const ModelHighAPI_Double& theScaleFactorX, - const ModelHighAPI_Double& theScaleFactorY, - const ModelHighAPI_Double& theScaleFactorZ); + const ModelHighAPI_Double& theScaleFactorY = ModelHighAPI_Double(0.0), + const ModelHighAPI_Double& theScaleFactorZ = ModelHighAPI_Double(0.0), + const bool keepSubResults = false); #endif // FEATURESAPI_SCALE_H_ \ No newline at end of file diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index e479b26f0..1b06f51f8 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -609,4 +609,12 @@ ADD_UNIT_TESTS(TestExtrusion.py TestSymmetry_MultiLevelCompound_v95_3.py TestSymmetry_MultiLevelCompound_v95_4.py TestSymmetry_MultiLevelCompound_v95_5.py + TestScale_MultiLevelCompound_v0_1.py + TestScale_MultiLevelCompound_v0_2.py + TestScale_MultiLevelCompound_v0_3.py + TestScale_MultiLevelCompound_v0_4.py + TestScale_MultiLevelCompound_v95_1.py + TestScale_MultiLevelCompound_v95_2.py + TestScale_MultiLevelCompound_v95_3.py + TestScale_MultiLevelCompound_v95_4.py ) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp b/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp index cb7a85686..bfadf37c1 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp @@ -18,8 +18,13 @@ // #include +#include + +#include +#include #include +#include #include #include @@ -28,7 +33,8 @@ #include #include -#include +static const std::string SCALE_VERSION_1("v9.5"); + //================================================================================================= FeaturesPlugin_Scale::FeaturesPlugin_Scale() @@ -57,6 +63,11 @@ void FeaturesPlugin_Scale::initAttributes() ModelAPI_AttributeDouble::typeId()); data()->addAttribute(FeaturesPlugin_Scale::SCALE_FACTOR_Z_ID(), ModelAPI_AttributeDouble::typeId()); + + if (!aSelection->isInitialized()) { + // new feature, not read from file + data()->setVersion(SCALE_VERSION_1); + } } //================================================================================================= @@ -68,8 +79,7 @@ void FeaturesPlugin_Scale::execute() if (aMethodType == FeaturesPlugin_Scale::CREATION_METHOD_BY_FACTOR()) { performScaleByFactor(); } - - if (aMethodType == FeaturesPlugin_Scale::CREATION_METHOD_BY_DIMENSIONS()) { + else if (aMethodType == FeaturesPlugin_Scale::CREATION_METHOD_BY_DIMENSIONS()) { performScaleByDimensions(); } } @@ -77,24 +87,15 @@ void FeaturesPlugin_Scale::execute() //================================================================================================= void FeaturesPlugin_Scale::performScaleByFactor() { + bool isKeepSubShapes = data()->version() == SCALE_VERSION_1; + // Getting objects. - ListOfShape anObjects; - std::list aContextes; - AttributeSelectionListPtr anObjectsSelList = - selectionList(FeaturesPlugin_Scale::OBJECTS_LIST_ID()); - if (anObjectsSelList->size() == 0) { + GeomAPI_ShapeHierarchy anObjects; + std::list aParts; + AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID()); + if (!FeaturesPlugin_Tools::shapesFromSelectionList( + anObjSelList, isKeepSubShapes, anObjects, aParts)) return; - } - for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { - std::shared_ptr anObjectAttr = - anObjectsSelList->value(anObjectsIndex); - std::shared_ptr anObject = anObjectAttr->value(); - if(!anObject.get()) { // may be for not-activated parts - return; - } - anObjects.push_back(anObject); - aContextes.push_back(anObjectAttr->context()); - } // Getting the center point std::shared_ptr aCenterPoint; @@ -113,15 +114,14 @@ void FeaturesPlugin_Scale::performScaleByFactor() // Getting scale factor double aScaleFactor = real(FeaturesPlugin_Scale::SCALE_FACTOR_ID())->value(); - // Moving each object. + // Collect transformation for each object std::string anError; - int aResultIndex = 0; - std::list::iterator aContext = aContextes.begin(); - for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); - anObjectsIt++, aContext++) { + std::shared_ptr aMakeShapeList(new GeomAlgoAPI_MakeShapeList); + for (GeomAPI_ShapeHierarchy::iterator anObjectsIt = anObjects.begin(); + anObjectsIt != anObjects.end(); ++anObjectsIt) { std::shared_ptr aBaseShape = *anObjectsIt; std::shared_ptr aScaleAlgo( - new GeomAlgoAPI_Scale(aBaseShape, aCenterPoint, aScaleFactor)); + new GeomAlgoAPI_Scale(aBaseShape, aCenterPoint, aScaleFactor)); // Checking that the algorithm worked properly. if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aScaleAlgo, getKind(), anError)) { @@ -129,18 +129,20 @@ void FeaturesPlugin_Scale::performScaleByFactor() break; } - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + anObjects.markModified(aBaseShape, aScaleAlgo->shape()); + aMakeShapeList->appendAlgo(aScaleAlgo); + } - ListOfShape aShapes; - aShapes.push_back(aBaseShape); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, - aShapes, - ListOfShape(), - aScaleAlgo, - aScaleAlgo->shape(), - "Scaled"); - setResult(aResultBody, aResultIndex); - aResultIndex++; + // Build results of the scaling + int aResultIndex = 0; + const ListOfShape& anOriginalShapes = anObjects.objects(); + ListOfShape aTopLevel; + anObjects.topLevelObjects(aTopLevel); + for (ListOfShape::iterator anIt = aTopLevel.begin(); anIt != aTopLevel.end(); ++anIt) { + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(), + aMakeShapeList, *anIt, "Scaled"); + setResult(aResultBody, aResultIndex++); } // Remove the rest results if there were produced in the previous pass. @@ -150,24 +152,15 @@ void FeaturesPlugin_Scale::performScaleByFactor() //================================================================================================= void FeaturesPlugin_Scale::performScaleByDimensions() { + bool isKeepSubShapes = data()->version() == SCALE_VERSION_1; + // Getting objects. - ListOfShape anObjects; - std::list aContextes; - AttributeSelectionListPtr anObjectsSelList = - selectionList(FeaturesPlugin_Scale::OBJECTS_LIST_ID()); - if (anObjectsSelList->size() == 0) { + GeomAPI_ShapeHierarchy anObjects; + std::list aParts; + AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID()); + if (!FeaturesPlugin_Tools::shapesFromSelectionList( + anObjSelList, isKeepSubShapes, anObjects, aParts)) return; - } - for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { - std::shared_ptr anObjectAttr = - anObjectsSelList->value(anObjectsIndex); - std::shared_ptr anObject = anObjectAttr->value(); - if(!anObject.get()) { // may be for not-activated parts - return; - } - anObjects.push_back(anObject); - aContextes.push_back(anObjectAttr->context()); - } // Getting the center point std::shared_ptr aCenterPoint; @@ -188,12 +181,11 @@ void FeaturesPlugin_Scale::performScaleByDimensions() double aScaleFactorY = real(FeaturesPlugin_Scale::SCALE_FACTOR_Y_ID())->value(); double aScaleFactorZ = real(FeaturesPlugin_Scale::SCALE_FACTOR_Z_ID())->value(); - // Moving each object. + // Collect transformation for each object std::string anError; - int aResultIndex = 0; - std::list::iterator aContext = aContextes.begin(); - for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); - anObjectsIt++, aContext++) { + std::shared_ptr aMakeShapeList(new GeomAlgoAPI_MakeShapeList); + for (GeomAPI_ShapeHierarchy::iterator anObjectsIt = anObjects.begin(); + anObjectsIt != anObjects.end(); ++anObjectsIt) { std::shared_ptr aBaseShape = *anObjectsIt; std::shared_ptr aScaleAlgo(new GeomAlgoAPI_Scale(aBaseShape, aCenterPoint, @@ -207,18 +199,20 @@ void FeaturesPlugin_Scale::performScaleByDimensions() break; } - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + anObjects.markModified(aBaseShape, aScaleAlgo->shape()); + aMakeShapeList->appendAlgo(aScaleAlgo); + } - ListOfShape aShapes; - aShapes.push_back(aBaseShape); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, - aShapes, - ListOfShape(), - aScaleAlgo, - aScaleAlgo->shape(), - "Scaled"); - setResult(aResultBody, aResultIndex); - aResultIndex++; + // Build results of the scaling + int aResultIndex = 0; + const ListOfShape& anOriginalShapes = anObjects.objects(); + ListOfShape aTopLevel; + anObjects.topLevelObjects(aTopLevel); + for (ListOfShape::iterator anIt = aTopLevel.begin(); anIt != aTopLevel.end(); ++anIt) { + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(), + aMakeShapeList, *anIt, "Scaled"); + setResult(aResultBody, aResultIndex++); } // Remove the rest results if there were produced in the previous pass. diff --git a/src/FeaturesPlugin/FeaturesPlugin_Scale.h b/src/FeaturesPlugin/FeaturesPlugin_Scale.h index a679a0cf8..d08062170 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Scale.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Scale.h @@ -24,8 +24,6 @@ #include -#include - /** \class FeaturesPlugin_Scale * \ingroup Plugins * \brief Feature for changing the scale of an object. @@ -123,7 +121,7 @@ private: /// Perform scale using a central point and a value of the scale. void performScaleByFactor(); - /// Perform symmetry using a central point and three dimensions + /// Perform scale using a central point and three dimensions void performScaleByDimensions(); }; diff --git a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp index 9656fc0e8..6cdd8a92c 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp @@ -44,7 +44,7 @@ #include -static const std::string SCALE_VERSION_1("v9.5"); +static const std::string SYMMETRY_VERSION_1("v9.5"); //================================================================================================= FeaturesPlugin_Symmetry::FeaturesPlugin_Symmetry() @@ -75,7 +75,7 @@ void FeaturesPlugin_Symmetry::initAttributes() if (!aSelection->isInitialized()) { // new feature, not read from file - data()->setVersion(SCALE_VERSION_1); + data()->setVersion(SYMMETRY_VERSION_1); } } @@ -274,7 +274,7 @@ void FeaturesPlugin_Symmetry::performSymmetry(GeomTrsfPtr theTrsf) } bool isKeepOriginal = boolean(KEEP_ORIGINAL_RESULT())->value(); - bool isKeepSubShapes = data()->version() == SCALE_VERSION_1; + bool isKeepSubShapes = data()->version() == SYMMETRY_VERSION_1; // Getting objects. GeomAPI_ShapeHierarchy anObjects; diff --git a/src/FeaturesPlugin/Test/TestScale2.py b/src/FeaturesPlugin/Test/TestScale2.py index 9dedd36dd..cfe9ea2ce 100644 --- a/src/FeaturesPlugin/Test/TestScale2.py +++ b/src/FeaturesPlugin/Test/TestScale2.py @@ -47,7 +47,7 @@ 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) +checkMiddlePoint(Shape, 0, 0, 0) model.end() diff --git a/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v0_1.py b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v0_1.py new file mode 100644 index 000000000..705c343df --- /dev/null +++ b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v0_1.py @@ -0,0 +1,136 @@ +# Copyright (C) 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 + +from GeomAPI import * +from SketchAPI import * + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.standardPlane("XOY")) +SketchEllipse_1 = Sketch_1.addEllipse(11.18033988749894, -50, 22.36067977499789, -50, 10) +[SketchPoint_1, SketchPoint_2, SketchPoint_3, SketchPoint_4, SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchLine_1, SketchLine_2] = SketchEllipse_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) +SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 30) +SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), 20) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False) +SketchLine_3 = SketchProjection_1.createdFeature() +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_3.result()) +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Line(SketchLine_3).startPoint(), SketchAPI_Point(SketchPoint_3).coordinates(), 50, True) +SketchCircle_1 = Sketch_1.addCircle(41.18033988749897, -50, 5) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_1.result()) +SketchConstraintDistance_2 = Sketch_1.setDistance(SketchEllipse_1.majorAxisPositive(), SketchCircle_1.center(), 15, True) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 5) +SketchMultiRotation_1 = Sketch_1.addRotation([SketchEllipse_1.result(), SketchCircle_1.results()[1]], SketchAPI_Point(SketchPoint_3).coordinates(), 360, 3, True) +[SketchEllipse_2, SketchEllipse_3, SketchCircle_2, SketchCircle_3] = SketchMultiRotation_1.rotated() +model.do() +Sketch_1.changeFacesOrder([[SketchEllipse_1.result(), SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()], + [SketchCircle_1.results()[1]], + [SketchEllipse_2.result(), SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_1.result()], + [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()], + [SketchEllipse_3.result(), SketchEllipse_2.result(), SketchEllipse_1.result()], + [SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()], + [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()], + [SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_3.result(), SketchEllipse_1.result()], + [SketchCircle_2.results()[1]], + [SketchCircle_3.results()[1]] + ]) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 10, 0) +Compound_1 = model.addCompound(Part_1_doc, [model.selection("SOLID", "Extrusion_1_2"), model.selection("SOLID", "Extrusion_1_3")]) +Compound_2_objects = [model.selection("COMPSOLID", "Extrusion_1_1"), model.selection("COMPOUND", "Compound_1_1"), model.selection("SOLID", "Extrusion_1_4")] +Compound_2 = model.addCompound(Part_1_doc, Compound_2_objects) +model.end() + +SCALE = 2 +TOLERANCE = 1.e-7 + + +model.begin() +Scale_1 = model.addScale(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_1, 1) +model.testNbSubResults(Scale_1, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.FACE, [5]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.EDGE, [18]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.VERTEX, [36]) +model.testResultsVolumes(Scale_1, [542.746463956 * (SCALE**3)]) + +refPoint = Extrusion_1.results()[0].subResult(4).resultSubShapePair()[0].shape().middlePoint() +refPoint = GeomAPI_Pnt(refPoint.xyz().multiplied(SCALE)) +midPoint = Scale_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_1 = model.addRecover(Part_1_doc, Scale_1, [Compound_2.result()], True) +Scale_2 = model.addScale(Part_1_doc, [model.selection("SOLID", "Recover_1_1_2_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_2, 1) +model.testNbSubResults(Scale_2, [0]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.FACE, [3]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.EDGE, [6]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.VERTEX, [12]) +model.testResultsVolumes(Scale_2, [785.39816339745 * (SCALE**3)]) + +refPoint = Recover_1.result().subResult(1).subResult(0).resultSubShapePair()[0].shape().middlePoint() +refPoint = GeomAPI_Pnt(refPoint.xyz().multiplied(SCALE)) +midPoint = Scale_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_2 = model.addRecover(Part_1_doc, Scale_2, [Recover_1.result()], True) +Scale_3 = model.addScale(Part_1_doc, [model.selection("SOLID", "Recover_2_1_3")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_3, 1) +model.testNbSubResults(Scale_3, [0]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.FACE, [3]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.EDGE, [6]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.VERTEX, [12]) +model.testResultsVolumes(Scale_3, [785.39816339745 * (SCALE**3)]) + +refPoint = Recover_2.result().subResult(2).resultSubShapePair()[0].shape().middlePoint() +refPoint = GeomAPI_Pnt(refPoint.xyz().multiplied(SCALE)) +midPoint = Scale_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_3 = model.addRecover(Part_1_doc, Scale_3, [Recover_2.result()], True) +Scale_4 = model.addScale(Part_1_doc, [model.selection("SOLID", "Recover_3_1_1_1"), model.selection("SOLID", "Recover_3_1_2_2"), model.selection("SOLID", "Recover_3_1_3")], model.selection("VERTEX", "PartSet/Origin"), 1 / SCALE) +model.testNbResults(Scale_4, 3) +model.testNbSubResults(Scale_4, [0, 0, 0]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.SOLID, [1, 1, 1]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.FACE, [6, 3, 3]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.EDGE, [24, 6, 6]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.VERTEX, [48, 12, 12]) +model.testResultsVolumes(Scale_4, [3444.394198615 / (SCALE**3), 785.39816339745 / (SCALE**3), 785.39816339745 / (SCALE**3)]) + +REFERENCE = [Recover_3.result().subResult(0).subResult(0).resultSubShapePair()[0].shape().middlePoint(), + Recover_3.result().subResult(1).subResult(1).resultSubShapePair()[0].shape().middlePoint(), + Recover_3.result().subResult(2).resultSubShapePair()[0].shape().middlePoint()] +for res, ref in zip(Scale_4.results(), REFERENCE): + ref = GeomAPI_Pnt(ref.xyz().multiplied(1 / SCALE)) + midPoint = res.resultSubShapePair()[0].shape().middlePoint() + assert(midPoint.distance(ref) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v0_2.py b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v0_2.py new file mode 100644 index 000000000..de0b6831a --- /dev/null +++ b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v0_2.py @@ -0,0 +1,138 @@ +# Copyright (C) 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 + +from GeomAPI import * +from SketchAPI import * + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.standardPlane("XOY")) +SketchEllipse_1 = Sketch_1.addEllipse(11.18033988749894, -50, 22.36067977499789, -50, 10) +[SketchPoint_1, SketchPoint_2, SketchPoint_3, SketchPoint_4, SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchLine_1, SketchLine_2] = SketchEllipse_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) +SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 30) +SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), 20) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False) +SketchLine_3 = SketchProjection_1.createdFeature() +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_3.result()) +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Line(SketchLine_3).startPoint(), SketchAPI_Point(SketchPoint_3).coordinates(), 50, True) +SketchCircle_1 = Sketch_1.addCircle(41.18033988749897, -50, 5) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_1.result()) +SketchConstraintDistance_2 = Sketch_1.setDistance(SketchEllipse_1.majorAxisPositive(), SketchCircle_1.center(), 15, True) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 5) +SketchMultiRotation_1 = Sketch_1.addRotation([SketchEllipse_1.result(), SketchCircle_1.results()[1]], SketchAPI_Point(SketchPoint_3).coordinates(), 360, 3, True) +[SketchEllipse_2, SketchEllipse_3, SketchCircle_2, SketchCircle_3] = SketchMultiRotation_1.rotated() +model.do() +Sketch_1.changeFacesOrder([[SketchEllipse_1.result(), SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()], + [SketchCircle_1.results()[1]], + [SketchEllipse_2.result(), SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_1.result()], + [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()], + [SketchEllipse_3.result(), SketchEllipse_2.result(), SketchEllipse_1.result()], + [SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()], + [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()], + [SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_3.result(), SketchEllipse_1.result()], + [SketchCircle_2.results()[1]], + [SketchCircle_3.results()[1]] + ]) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 10, 0) +Compound_1 = model.addCompound(Part_1_doc, [model.selection("SOLID", "Extrusion_1_2"), model.selection("SOLID", "Extrusion_1_3")]) +Compound_2_objects = [model.selection("COMPSOLID", "Extrusion_1_1"), model.selection("COMPOUND", "Compound_1_1"), model.selection("SOLID", "Extrusion_1_4")] +Compound_2 = model.addCompound(Part_1_doc, Compound_2_objects) +model.end() + +SCALE_X = 1 +SCALE_Y = 2 +SCALE_Z = 3 +TOLERANCE = 1.e-3 + + +model.begin() +Scale_1 = model.addScale(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("VERTEX", "PartSet/Origin"), SCALE_X, SCALE_Y, SCALE_Z) +model.testNbResults(Scale_1, 1) +model.testNbSubResults(Scale_1, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.FACE, [5]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.EDGE, [18]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.VERTEX, [36]) +model.testResultsVolumes(Scale_1, [542.746463956 * SCALE_X * SCALE_Y * SCALE_Z]) + +refPoint = Extrusion_1.results()[0].subResult(4).resultSubShapePair()[0].shape().middlePoint() +refPoint = GeomAPI_Pnt(refPoint.x() * SCALE_X, refPoint.y() * SCALE_Y, refPoint.z() * SCALE_Z) +midPoint = Scale_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_1 = model.addRecover(Part_1_doc, Scale_1, [Compound_2.result()], True) +Scale_2 = model.addScale(Part_1_doc, [model.selection("SOLID", "Recover_1_1_2_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE_X, SCALE_Y, SCALE_Z) +model.testNbResults(Scale_2, 1) +model.testNbSubResults(Scale_2, [0]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.FACE, [3]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.EDGE, [6]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.VERTEX, [12]) +model.testResultsVolumes(Scale_2, [785.3997 * SCALE_X * SCALE_Y * SCALE_Z]) + +refPoint = Recover_1.result().subResult(1).subResult(0).resultSubShapePair()[0].shape().middlePoint() +refPoint = GeomAPI_Pnt(refPoint.x() * SCALE_X, refPoint.y() * SCALE_Y, refPoint.z() * SCALE_Z) +midPoint = Scale_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_2 = model.addRecover(Part_1_doc, Scale_2, [Recover_1.result()], True) +Scale_3 = model.addScale(Part_1_doc, [model.selection("SOLID", "Recover_2_1_3")], model.selection("VERTEX", "PartSet/Origin"), SCALE_X, SCALE_Y, SCALE_Z) +model.testNbResults(Scale_3, 1) +model.testNbSubResults(Scale_3, [0]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.FACE, [3]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.EDGE, [6]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.VERTEX, [12]) +model.testResultsVolumes(Scale_3, [785.3997 * SCALE_X * SCALE_Y * SCALE_Z]) + +refPoint = Recover_2.result().subResult(2).resultSubShapePair()[0].shape().middlePoint() +refPoint = GeomAPI_Pnt(refPoint.x() * SCALE_X, refPoint.y() * SCALE_Y, refPoint.z() * SCALE_Z) +midPoint = Scale_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_3 = model.addRecover(Part_1_doc, Scale_3, [Recover_2.result()], True) +Scale_4 = model.addScale(Part_1_doc, [model.selection("SOLID", "Recover_3_1_1_1"), model.selection("SOLID", "Recover_3_1_2_2"), model.selection("SOLID", "Recover_3_1_3")], model.selection("VERTEX", "PartSet/Origin"), 1 / SCALE_X, 1 / SCALE_Y, 1 / SCALE_Z) +model.testNbResults(Scale_4, 3) +model.testNbSubResults(Scale_4, [0, 0, 0]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.SOLID, [1, 1, 1]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.FACE, [6, 3, 3]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.EDGE, [24, 6, 6]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.VERTEX, [48, 12, 12]) +model.testResultsVolumes(Scale_4, [3444.39814733 / (SCALE_X * SCALE_Y * SCALE_Z), 785.3997 / (SCALE_X * SCALE_Y * SCALE_Z), 785.3997 / (SCALE_X * SCALE_Y * SCALE_Z)]) + +REFERENCE = [Recover_3.result().subResult(0).subResult(0).resultSubShapePair()[0].shape().middlePoint(), + Recover_3.result().subResult(1).subResult(1).resultSubShapePair()[0].shape().middlePoint(), + Recover_3.result().subResult(2).resultSubShapePair()[0].shape().middlePoint()] +for res, ref in zip(Scale_4.results(), REFERENCE): + ref = GeomAPI_Pnt(ref.x() / SCALE_X, ref.y() / SCALE_Y, ref.z() / SCALE_Z) + midPoint = res.resultSubShapePair()[0].shape().middlePoint() + assert(midPoint.distance(ref) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v0_3.py b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v0_3.py new file mode 100644 index 000000000..4ac842d05 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v0_3.py @@ -0,0 +1,180 @@ +# Copyright (C) 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 +from GeomAPI import * + +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")) +SketchPoint_1 = Sketch_1.addPoint(44.29784155360136, 17.09942588468031) +SketchArc_1 = Sketch_1.addArc(44.29784155360136, 17.09942588468031, 47.1668727423061, 12.27945348765633, 45.38299232715926, 22.60269052200972, False) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchArc_1.center()) +SketchLine_1 = Sketch_1.addLine(42.5764228403785, 22.14892077680068, 39.70739165167375, 16.41085839939117) +SketchLine_2 = Sketch_1.addLine(39.70739165167375, 16.41085839939117, 43.03546783057126, 12.04993099255995) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(28.57555063949931, 12.96802097294547, 15.72229091410204, 12.96802097294547) +SketchLine_4 = Sketch_1.addLine(15.72229091410204, 12.96802097294547, 15.72229091410204, 21.46035329151154) +SketchLine_5 = Sketch_1.addLine(15.72229091410204, 21.46035329151154, 28.57555063949931, 21.46035329151154) +SketchLine_6 = Sketch_1.addLine(28.57555063949931, 21.46035329151154, 28.57555063949931, 12.96802097294547) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_4.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_5.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_6.result()) +SketchLine_7 = Sketch_1.addLine(-10.67279602198167, 14.78814178154371, -28.34602814440294, 14.78814178154371) +SketchLine_8 = Sketch_1.addLine(-28.34602814440294, 14.78814178154371, -28.34602814440294, 25.13271321305362) +SketchLine_9 = Sketch_1.addLine(-28.34602814440294, 25.13271321305362, -10.67279602198167, 25.13271321305362) +SketchLine_10 = Sketch_1.addLine(-10.67279602198167, 25.13271321305362, -10.67279602198167, 14.78814178154371) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_10.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint()) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint()) +SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_7.result()) +SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_8.result()) +SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_9.result()) +SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_10.result()) +SketchLine_11 = Sketch_1.addLine(-17.67323212242127, 25.13271321305362, -21.80463703415611, 14.78814178154371) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_11.startPoint(), SketchLine_9.result()) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_11.endPoint(), SketchLine_7.result()) +model.do() +Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchArc_1")], False) +Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchArc_1_2")], False) +Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1"), model.selection("EDGE", "Sketch_1/SketchLine_2")], False) +Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_6r-SketchLine_5r-SketchLine_4r-SketchLine_3r")]) +Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_10r-SketchLine_9r-SketchLine_11f-SketchLine_7r"), model.selection("FACE", "Sketch_1/Face-SketchLine_11r-SketchLine_9r-SketchLine_8r-SketchLine_7r")]) +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 50) +Box_2 = model.addBox(Part_1_doc, 10, 10, 10) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10) +Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_2_1"), model.selection("SOLID", "Cylinder_1_1")]) +Box_3 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OY"), 50) +AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Translation_2_1")], model.selection("EDGE", "PartSet/OZ"), 30, 3) +model.end() + +TOLERANCE = 1.e-7 +SCALE = 2 + + +model.begin() +Scale_1 = model.addScale(Part_1_doc, [model.selection("VERTEX", "Vertex_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_1, 1) +model.testNbSubResults(Scale_1, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.EDGE, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.VERTEX, [1]) +model.testResultsVolumes(Scale_1, [0]) +refPoint = GeomAPI_Pnt(Vertex_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_2 = model.addScale(Part_1_doc, [model.selection("EDGE", "Edge_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_2, 1) +model.testNbSubResults(Scale_2, [0]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.EDGE, [1]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.VERTEX, [2]) +model.testResultsVolumes(Scale_2, [0]) +refPoint = GeomAPI_Pnt(Edge_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_3 = model.addScale(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_3, 1) +model.testNbSubResults(Scale_3, [0]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.EDGE, [2]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.VERTEX, [4]) +model.testResultsVolumes(Scale_3, [0]) +refPoint = GeomAPI_Pnt(Wire_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_4 = model.addScale(Part_1_doc, [model.selection("FACE", "Face_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_4, 1) +model.testNbSubResults(Scale_4, [0]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.FACE, [1]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.EDGE, [4]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.VERTEX, [8]) +model.testResultsVolumes(Scale_4, [109.154152964914914 * (SCALE**2)]) +refPoint = GeomAPI_Pnt(Face_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_4.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_5 = model.addScale(Part_1_doc, [model.selection("SHELL", "Shell_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_5, 1) +model.testNbSubResults(Scale_5, [0]) +model.testNbSubShapes(Scale_5, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_5, GeomAPI_Shape.FACE, [2]) +model.testNbSubShapes(Scale_5, GeomAPI_Shape.EDGE, [8]) +model.testNbSubShapes(Scale_5, GeomAPI_Shape.VERTEX, [16]) +model.testResultsVolumes(Scale_5, [182.822012116 * (SCALE**2)]) +refPoint = GeomAPI_Pnt(Shell_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_5.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_6 = model.addScale(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_6, 1) +model.testNbSubResults(Scale_6, [0]) +model.testNbSubShapes(Scale_6, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Scale_6, GeomAPI_Shape.FACE, [6]) +model.testNbSubShapes(Scale_6, GeomAPI_Shape.EDGE, [24]) +model.testNbSubShapes(Scale_6, GeomAPI_Shape.VERTEX, [48]) +model.testResultsVolumes(Scale_6, [1000 * (SCALE**3)]) +refPoint = GeomAPI_Pnt(Translation_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_6.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_7 = model.addScale(Part_1_doc, [model.selection("COMPSOLID", "Partition_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_7, 1) +model.testNbSubResults(Scale_7, [3]) +model.testNbSubShapes(Scale_7, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Scale_7, GeomAPI_Shape.FACE, [17]) +model.testNbSubShapes(Scale_7, GeomAPI_Shape.EDGE, [66]) +model.testNbSubShapes(Scale_7, GeomAPI_Shape.VERTEX, [132]) +model.testResultsVolumes(Scale_7, [1589.0486226 * (SCALE**3)]) +refPoint = GeomAPI_Pnt(Partition_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_7.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_8 = model.addScale(Part_1_doc, [model.selection("COMPOUND", "AngularCopy_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_8, 1) +model.testNbSubResults(Scale_8, [3]) +model.testNbSubShapes(Scale_8, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Scale_8, GeomAPI_Shape.FACE, [18]) +model.testNbSubShapes(Scale_8, GeomAPI_Shape.EDGE, [72]) +model.testNbSubShapes(Scale_8, GeomAPI_Shape.VERTEX, [144]) +model.testResultsVolumes(Scale_8, [3000 * (SCALE**3)]) +refPoint = GeomAPI_Pnt(AngularCopy_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_8.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v0_4.py b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v0_4.py new file mode 100644 index 000000000..23cf7c5c4 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v0_4.py @@ -0,0 +1,189 @@ +# Copyright (C) 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 +from GeomAPI import * + +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")) +SketchPoint_1 = Sketch_1.addPoint(44.29784155360136, 17.09942588468031) +SketchArc_1 = Sketch_1.addArc(44.29784155360136, 17.09942588468031, 47.1668727423061, 12.27945348765633, 45.38299232715926, 22.60269052200972, False) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchArc_1.center()) +SketchLine_1 = Sketch_1.addLine(42.5764228403785, 22.14892077680068, 39.70739165167375, 16.41085839939117) +SketchLine_2 = Sketch_1.addLine(39.70739165167375, 16.41085839939117, 43.03546783057126, 12.04993099255995) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(28.57555063949931, 12.96802097294547, 15.72229091410204, 12.96802097294547) +SketchLine_4 = Sketch_1.addLine(15.72229091410204, 12.96802097294547, 15.72229091410204, 21.46035329151154) +SketchLine_5 = Sketch_1.addLine(15.72229091410204, 21.46035329151154, 28.57555063949931, 21.46035329151154) +SketchLine_6 = Sketch_1.addLine(28.57555063949931, 21.46035329151154, 28.57555063949931, 12.96802097294547) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_4.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_5.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_6.result()) +SketchLine_7 = Sketch_1.addLine(-10.67279602198167, 14.78814178154371, -28.34602814440294, 14.78814178154371) +SketchLine_8 = Sketch_1.addLine(-28.34602814440294, 14.78814178154371, -28.34602814440294, 25.13271321305362) +SketchLine_9 = Sketch_1.addLine(-28.34602814440294, 25.13271321305362, -10.67279602198167, 25.13271321305362) +SketchLine_10 = Sketch_1.addLine(-10.67279602198167, 25.13271321305362, -10.67279602198167, 14.78814178154371) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_10.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint()) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint()) +SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_7.result()) +SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_8.result()) +SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_9.result()) +SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_10.result()) +SketchLine_11 = Sketch_1.addLine(-17.67323212242127, 25.13271321305362, -21.80463703415611, 14.78814178154371) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_11.startPoint(), SketchLine_9.result()) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_11.endPoint(), SketchLine_7.result()) +model.do() +Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchArc_1")], False) +Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchArc_1_2")], False) +Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1"), model.selection("EDGE", "Sketch_1/SketchLine_2")], False) +Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_6r-SketchLine_5r-SketchLine_4r-SketchLine_3r")]) +Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_10r-SketchLine_9r-SketchLine_11f-SketchLine_7r"), model.selection("FACE", "Sketch_1/Face-SketchLine_11r-SketchLine_9r-SketchLine_8r-SketchLine_7r")]) +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 50) +Box_2 = model.addBox(Part_1_doc, 10, 10, 10) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10) +Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_2_1"), model.selection("SOLID", "Cylinder_1_1")]) +Box_3 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OY"), 50) +AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Translation_2_1")], model.selection("EDGE", "PartSet/OZ"), 30, 3) +Compound_1_objects = [model.selection("VERTEX", "Vertex_1_1"), model.selection("EDGE", "Edge_1_1"), model.selection("WIRE", "Wire_1_1"), model.selection("FACE", "Face_1_1"), model.selection("SHELL", "Shell_1_1"), model.selection("SOLID", "Translation_1_1"), model.selection("COMPSOLID", "Partition_1_1"), model.selection("COMPOUND", "AngularCopy_1_1")] +Compound_1 = model.addCompound(Part_1_doc, Compound_1_objects) +model.end() + +TOLERANCE = 1.e-7 +SCALE = 2 + + +model.begin() +Scale_1 = model.addScale(Part_1_doc, [model.selection("VERTEX", "Compound_1_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_1, 1) +model.testNbSubResults(Scale_1, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.EDGE, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.VERTEX, [1]) +model.testResultsVolumes(Scale_1, [0]) +refPoint = GeomAPI_Pnt(Compound_1.result().subResult(0).resultSubShapePair()[0].shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_1 = model.addRecover(Part_1_doc, Scale_1, [Compound_1.result()], True) +Scale_2 = model.addScale(Part_1_doc, [model.selection("EDGE", "Recover_1_1_2")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_2, 1) +model.testNbSubResults(Scale_2, [0]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.EDGE, [1]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.VERTEX, [2]) +model.testResultsVolumes(Scale_2, [0]) +refPoint = GeomAPI_Pnt(Compound_1.result().subResult(1).resultSubShapePair()[0].shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_2 = model.addRecover(Part_1_doc, Scale_2, [Recover_1.result()]) +Scale_3 = model.addScale(Part_1_doc, [model.selection("WIRE", "Recover_2_1_3")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_3, 1) +model.testNbSubResults(Scale_3, [0]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.EDGE, [2]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.VERTEX, [4]) +model.testResultsVolumes(Scale_3, [0]) +refPoint = GeomAPI_Pnt(Compound_1.result().subResult(2).resultSubShapePair()[0].shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_3 = model.addRecover(Part_1_doc, Scale_3, [Recover_2.result()]) +Scale_4 = model.addScale(Part_1_doc, [model.selection("FACE", "Recover_3_1_4")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_4, 1) +model.testNbSubResults(Scale_4, [0]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.FACE, [1]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.EDGE, [4]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.VERTEX, [8]) +model.testResultsVolumes(Scale_4, [109.154152964914914 * (SCALE**2)]) +refPoint = GeomAPI_Pnt(Compound_1.result().subResult(3).resultSubShapePair()[0].shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_4.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_4 = model.addRecover(Part_1_doc, Scale_4, [Recover_3.result()]) +Scale_5 = model.addScale(Part_1_doc, [model.selection("SHELL", "Recover_4_1_5")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_5, 1) +model.testNbSubResults(Scale_5, [0]) +model.testNbSubShapes(Scale_5, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_5, GeomAPI_Shape.FACE, [2]) +model.testNbSubShapes(Scale_5, GeomAPI_Shape.EDGE, [8]) +model.testNbSubShapes(Scale_5, GeomAPI_Shape.VERTEX, [16]) +model.testResultsVolumes(Scale_5, [182.822012116 * (SCALE**2)]) +refPoint = GeomAPI_Pnt(Compound_1.result().subResult(4).resultSubShapePair()[0].shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_5.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_5 = model.addRecover(Part_1_doc, Scale_5, [Recover_4.result()]) +Scale_6 = model.addScale(Part_1_doc, [model.selection("SOLID", "Recover_5_1_6")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_6, 1) +model.testNbSubResults(Scale_6, [0]) +model.testNbSubShapes(Scale_6, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Scale_6, GeomAPI_Shape.FACE, [6]) +model.testNbSubShapes(Scale_6, GeomAPI_Shape.EDGE, [24]) +model.testNbSubShapes(Scale_6, GeomAPI_Shape.VERTEX, [48]) +model.testResultsVolumes(Scale_6, [1000 * (SCALE**3)]) +refPoint = GeomAPI_Pnt(Compound_1.result().subResult(5).resultSubShapePair()[0].shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_6.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_6 = model.addRecover(Part_1_doc, Scale_6, [Recover_5.result()]) +Scale_7 = model.addScale(Part_1_doc, [model.selection("COMPSOLID", "Recover_6_1_7")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_7, 1) +model.testNbSubResults(Scale_7, [3]) +model.testNbSubShapes(Scale_7, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Scale_7, GeomAPI_Shape.FACE, [17]) +model.testNbSubShapes(Scale_7, GeomAPI_Shape.EDGE, [66]) +model.testNbSubShapes(Scale_7, GeomAPI_Shape.VERTEX, [132]) +model.testResultsVolumes(Scale_7, [1589.0486226 * (SCALE**3)]) +refPoint = GeomAPI_Pnt(Compound_1.result().subResult(6).resultSubShapePair()[0].shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_7.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_7 = model.addRecover(Part_1_doc, Scale_7, [Recover_6.result()]) +Scale_8 = model.addScale(Part_1_doc, [model.selection("COMPOUND", "Recover_7_1_8")], model.selection("VERTEX", "PartSet/Origin"), SCALE) +model.testNbResults(Scale_8, 1) +model.testNbSubResults(Scale_8, [3]) +model.testNbSubShapes(Scale_8, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Scale_8, GeomAPI_Shape.FACE, [18]) +model.testNbSubShapes(Scale_8, GeomAPI_Shape.EDGE, [72]) +model.testNbSubShapes(Scale_8, GeomAPI_Shape.VERTEX, [144]) +model.testResultsVolumes(Scale_8, [3000 * (SCALE**3)]) +refPoint = GeomAPI_Pnt(Compound_1.result().subResult(7).resultSubShapePair()[0].shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_8.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_1.py b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_1.py new file mode 100644 index 000000000..1439fa72f --- /dev/null +++ b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_1.py @@ -0,0 +1,136 @@ +# Copyright (C) 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 + +from GeomAPI import * +from SketchAPI import * + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.standardPlane("XOY")) +SketchEllipse_1 = Sketch_1.addEllipse(11.18033988749894, -50, 22.36067977499789, -50, 10) +[SketchPoint_1, SketchPoint_2, SketchPoint_3, SketchPoint_4, SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchLine_1, SketchLine_2] = SketchEllipse_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) +SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 30) +SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), 20) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False) +SketchLine_3 = SketchProjection_1.createdFeature() +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_3.result()) +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Line(SketchLine_3).startPoint(), SketchAPI_Point(SketchPoint_3).coordinates(), 50, True) +SketchCircle_1 = Sketch_1.addCircle(41.18033988749897, -50, 5) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_1.result()) +SketchConstraintDistance_2 = Sketch_1.setDistance(SketchEllipse_1.majorAxisPositive(), SketchCircle_1.center(), 15, True) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 5) +SketchMultiRotation_1 = Sketch_1.addRotation([SketchEllipse_1.result(), SketchCircle_1.results()[1]], SketchAPI_Point(SketchPoint_3).coordinates(), 360, 3, True) +[SketchEllipse_2, SketchEllipse_3, SketchCircle_2, SketchCircle_3] = SketchMultiRotation_1.rotated() +model.do() +Sketch_1.changeFacesOrder([[SketchEllipse_1.result(), SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()], + [SketchCircle_1.results()[1]], + [SketchEllipse_2.result(), SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_1.result()], + [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()], + [SketchEllipse_3.result(), SketchEllipse_2.result(), SketchEllipse_1.result()], + [SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()], + [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()], + [SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_3.result(), SketchEllipse_1.result()], + [SketchCircle_2.results()[1]], + [SketchCircle_3.results()[1]] + ]) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 10, 0) +Compound_1 = model.addCompound(Part_1_doc, [model.selection("SOLID", "Extrusion_1_2"), model.selection("SOLID", "Extrusion_1_3")]) +Compound_2_objects = [model.selection("COMPSOLID", "Extrusion_1_1"), model.selection("COMPOUND", "Compound_1_1"), model.selection("SOLID", "Extrusion_1_4")] +Compound_2 = model.addCompound(Part_1_doc, Compound_2_objects) +model.end() + +SCALE = 2 +TOLERANCE = 1.e-7 + +def average(thePoints): + x = 0; y = 0; z = 0 + for p in thePoints: + x += p.x(); y += p.y(); z+= p.z() + x /= len(thePoints) + y /= len(thePoints) + z /= len(thePoints) + return GeomAPI_Pnt(x, y, z) + +def subsRefPoints(theResult): + res = [] + for ind in range(0, theResult.numberOfSubs()): + res.append( theResult.subResult(ind).resultSubShapePair()[0].shape().middlePoint()) + return res + +REFERENCE = subsRefPoints(Compound_2.result()) + +def assertResult(theFeature, theVolume): + model.testNbResults(theFeature, 1) + model.testNbSubResults(theFeature, [3]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.SOLID, [10]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [47]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [162]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [324]) + model.testResultsVolumes(theFeature, [theVolume]) + + for ind in range(0, theFeature.result().numberOfSubs()): + ref = REFERENCE[ind] + midPoint = theFeature.result().subResult(ind).resultSubShapePair()[0].shape().middlePoint() + assert(midPoint.distance(ref) < TOLERANCE), "Sub-result {}; actual ({}, {}, {}) != expected ({}, {}, {})".format(ind, midPoint.x(), midPoint.y(), midPoint.z(), ref.x(), ref.y(), ref.z()) + + +model.begin() +Scale_1 = model.addScale(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(Scale_1.feature().error() != "") + +model.begin() +Scale_1.setMainObjects([model.selection("COMPSOLID", "Compound_2_1_1")]) +REFERENCE[0] = GeomAPI_Pnt(REFERENCE[0].xyz().multiplied(SCALE)) +assertResult(Scale_1, 98066.606782594) + +Scale_2 = model.addScale(Part_1_doc, [model.selection("SOLID", "Scale_1_1_2_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +subs = subsRefPoints(Compound_2.result().subResult(1)) +subs[0] = GeomAPI_Pnt(subs[0].xyz().added(GeomAPI_XYZ(5, -5, 5)).multiplied(SCALE)) +subs[1] = GeomAPI_Pnt(subs[1].xyz().added(GeomAPI_XYZ(-5, 5, -5))) +REFERENCE[1] = average(subs) +assertResult(Scale_2, 103564.3939263762) + +Scale_3 = model.addScale(Part_1_doc, [model.selection("SOLID", "Scale_2_1_3")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +REFERENCE[2] = GeomAPI_Pnt(REFERENCE[2].xyz().multiplied(SCALE)) +assertResult(Scale_3, 109062.18107) + +Scale_4 = model.addScale(Part_1_doc, [model.selection("SOLID", "Scale_3_1_1_1"), model.selection("SOLID", "Scale_3_1_2_2"), model.selection("SOLID", "Scale_3_1_3")], model.selection("VERTEX", "PartSet/Origin"), 1 / SCALE, keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(Scale_4.feature().error() != "") + +model.begin() +Scale_4.setMainObjects([model.selection("COMPSOLID", "Scale_3_1_1"), model.selection("SOLID", "Scale_3_1_2_2"), model.selection("SOLID", "Scale_3_1_3")]) +REFERENCE[0] = GeomAPI_Pnt(REFERENCE[0].xyz().multiplied(1 / SCALE)) +subs[1] = GeomAPI_Pnt(subs[1].xyz().multiplied(1 / SCALE)) +REFERENCE[1] = average(subs) +REFERENCE[2] = GeomAPI_Pnt(REFERENCE[2].xyz().multiplied(1 / SCALE)) +assertResult(Scale_4, 19130.55977755) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_2.py b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_2.py new file mode 100644 index 000000000..7975a6792 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_2.py @@ -0,0 +1,144 @@ +# Copyright (C) 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 + +from GeomAPI import * +from SketchAPI import * + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.standardPlane("XOY")) +SketchEllipse_1 = Sketch_1.addEllipse(11.18033988749894, -50, 22.36067977499789, -50, 10) +[SketchPoint_1, SketchPoint_2, SketchPoint_3, SketchPoint_4, SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchLine_1, SketchLine_2] = SketchEllipse_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) +SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 30) +SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), 20) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False) +SketchLine_3 = SketchProjection_1.createdFeature() +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_3.result()) +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Line(SketchLine_3).startPoint(), SketchAPI_Point(SketchPoint_3).coordinates(), 50, True) +SketchCircle_1 = Sketch_1.addCircle(41.18033988749897, -50, 5) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_1.result()) +SketchConstraintDistance_2 = Sketch_1.setDistance(SketchEllipse_1.majorAxisPositive(), SketchCircle_1.center(), 15, True) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 5) +SketchMultiRotation_1 = Sketch_1.addRotation([SketchEllipse_1.result(), SketchCircle_1.results()[1]], SketchAPI_Point(SketchPoint_3).coordinates(), 360, 3, True) +[SketchEllipse_2, SketchEllipse_3, SketchCircle_2, SketchCircle_3] = SketchMultiRotation_1.rotated() +model.do() +Sketch_1.changeFacesOrder([[SketchEllipse_1.result(), SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()], + [SketchCircle_1.results()[1]], + [SketchEllipse_2.result(), SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_1.result()], + [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()], + [SketchEllipse_3.result(), SketchEllipse_2.result(), SketchEllipse_1.result()], + [SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()], + [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()], + [SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_3.result(), SketchEllipse_1.result()], + [SketchCircle_2.results()[1]], + [SketchCircle_3.results()[1]] + ]) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 10, 0) +Compound_1 = model.addCompound(Part_1_doc, [model.selection("SOLID", "Extrusion_1_2"), model.selection("SOLID", "Extrusion_1_3")]) +Compound_2_objects = [model.selection("COMPSOLID", "Extrusion_1_1"), model.selection("COMPOUND", "Compound_1_1"), model.selection("SOLID", "Extrusion_1_4")] +Compound_2 = model.addCompound(Part_1_doc, Compound_2_objects) +model.end() + +SCALE_X = 1 +SCALE_Y = 2 +SCALE_Z = 3 +TOLERANCE = 1.e-4 + +def average(thePoints): + x = 0; y = 0; z = 0 + for p in thePoints: + x += p.x(); y += p.y(); z+= p.z() + x /= len(thePoints) + y /= len(thePoints) + z /= len(thePoints) + return GeomAPI_Pnt(x, y, z) + +def subsRefPoints(theResult): + res = [] + for ind in range(0, theResult.numberOfSubs()): + res.append(theResult.subResult(ind).resultSubShapePair()[0].shape().middlePoint()) + return res + +REFERENCE = subsRefPoints(Compound_2.result()) + +def assertResult(theFeature, theVolume): + model.testNbResults(theFeature, 1) + model.testNbSubResults(theFeature, [3]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.SOLID, [10]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [47]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [162]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [324]) + model.testResultsVolumes(theFeature, [theVolume]) + + for ind in range(0, theFeature.result().numberOfSubs()): + ref = REFERENCE[ind] + midPoint = theFeature.result().subResult(ind).resultSubShapePair()[0].shape().middlePoint() + assert(midPoint.distance(ref) < TOLERANCE), "Sub-result {}; actual ({}, {}, {}) != expected ({}, {}, {})".format(ind, midPoint.x(), midPoint.y(), midPoint.z(), ref.x(), ref.y(), ref.z()) + + +model.begin() +Scale_1 = model.addScale(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("VERTEX", "PartSet/Origin"), SCALE_X, SCALE_Y, SCALE_Z, keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(Scale_1.feature().error() != "") + +model.begin() +Scale_1.setMainObjects([model.selection("COMPSOLID", "Compound_2_1_1")]) +REFERENCE[0] = GeomAPI_Pnt(REFERENCE[0].x() * SCALE_X, REFERENCE[0].y() * SCALE_Y, REFERENCE[0].z() * SCALE_Z) +REFERENCE[0].setX(0) # <= B-spline poles are used to calculate the bounding box and thus the middle point +assertResult(Scale_1, 74139.07479) + +Scale_2 = model.addScale(Part_1_doc, [model.selection("SOLID", "Scale_1_1_2_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE_X, SCALE_Y, SCALE_Z, keepSubResults = True) +subs = subsRefPoints(Compound_2.result().subResult(1)) +subs[0] = GeomAPI_Pnt(subs[0].xyz().added(GeomAPI_XYZ(5, -5, 5))) +subs[0] = GeomAPI_Pnt(subs[0].x() * SCALE_X, subs[0].y() * SCALE_Y, subs[0].z() * SCALE_Z) +subs[0].setY(-117.3204876) # <= B-spline poles are used to calculate the bounding box and thus the middle point +subs[1] = GeomAPI_Pnt(subs[1].xyz().added(GeomAPI_XYZ(-5, 5, -5))) +REFERENCE[1] = average(subs) +assertResult(Scale_2, 78066.07487341) + +Scale_3 = model.addScale(Part_1_doc, [model.selection("SOLID", "Scale_2_1_3")], model.selection("VERTEX", "PartSet/Origin"), SCALE_X, SCALE_Y, SCALE_Z, keepSubResults = True) +REFERENCE[2] = GeomAPI_Pnt(REFERENCE[2].x() * SCALE_X, REFERENCE[2].y() * SCALE_Y, REFERENCE[2].z() * SCALE_Z) +assertResult(Scale_3, 81993.0749561) + +Scale_4 = model.addScale(Part_1_doc, [model.selection("SOLID", "Scale_3_1_1_1"), model.selection("SOLID", "Scale_3_1_2_2"), model.selection("SOLID", "Scale_3_1_3")], model.selection("VERTEX", "PartSet/Origin"), 1 / SCALE_X, 1 / SCALE_Y, 1 / SCALE_Z, keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(Scale_4.feature().error() != "") + +model.begin() +Scale_4.setMainObjects([model.selection("COMPSOLID", "Scale_3_1_1"), model.selection("SOLID", "Scale_3_1_2_2"), model.selection("SOLID", "Scale_3_1_3")]) +REFERENCE[0] = GeomAPI_Pnt(REFERENCE[0].x() / SCALE_X, REFERENCE[0].y() / SCALE_Y, REFERENCE[0].z() / SCALE_Z) +subs[1] = GeomAPI_Pnt(subs[1].x() / SCALE_X, subs[1].y() / SCALE_Y, subs[1].z() / SCALE_Z) +# B-spline poles are used to calculate the bounding box and thus the middle point +subs[1].setX(-30.59017) +subs[1].setY(-2.83826244) +REFERENCE[1] = average(subs) +REFERENCE[2] = GeomAPI_Pnt(REFERENCE[2].x() / SCALE_X, REFERENCE[2].y() / SCALE_Y, REFERENCE[2].z() / SCALE_Z) +assertResult(Scale_4, 17592.5112883) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_3.py b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_3.py new file mode 100644 index 000000000..f87072313 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_3.py @@ -0,0 +1,180 @@ +# Copyright (C) 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 +from GeomAPI import * + +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")) +SketchPoint_1 = Sketch_1.addPoint(44.29784155360136, 17.09942588468031) +SketchArc_1 = Sketch_1.addArc(44.29784155360136, 17.09942588468031, 47.1668727423061, 12.27945348765633, 45.38299232715926, 22.60269052200972, False) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchArc_1.center()) +SketchLine_1 = Sketch_1.addLine(42.5764228403785, 22.14892077680068, 39.70739165167375, 16.41085839939117) +SketchLine_2 = Sketch_1.addLine(39.70739165167375, 16.41085839939117, 43.03546783057126, 12.04993099255995) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(28.57555063949931, 12.96802097294547, 15.72229091410204, 12.96802097294547) +SketchLine_4 = Sketch_1.addLine(15.72229091410204, 12.96802097294547, 15.72229091410204, 21.46035329151154) +SketchLine_5 = Sketch_1.addLine(15.72229091410204, 21.46035329151154, 28.57555063949931, 21.46035329151154) +SketchLine_6 = Sketch_1.addLine(28.57555063949931, 21.46035329151154, 28.57555063949931, 12.96802097294547) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_4.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_5.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_6.result()) +SketchLine_7 = Sketch_1.addLine(-10.67279602198167, 14.78814178154371, -28.34602814440294, 14.78814178154371) +SketchLine_8 = Sketch_1.addLine(-28.34602814440294, 14.78814178154371, -28.34602814440294, 25.13271321305362) +SketchLine_9 = Sketch_1.addLine(-28.34602814440294, 25.13271321305362, -10.67279602198167, 25.13271321305362) +SketchLine_10 = Sketch_1.addLine(-10.67279602198167, 25.13271321305362, -10.67279602198167, 14.78814178154371) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_10.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint()) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint()) +SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_7.result()) +SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_8.result()) +SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_9.result()) +SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_10.result()) +SketchLine_11 = Sketch_1.addLine(-17.67323212242127, 25.13271321305362, -21.80463703415611, 14.78814178154371) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_11.startPoint(), SketchLine_9.result()) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_11.endPoint(), SketchLine_7.result()) +model.do() +Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchArc_1")], False) +Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchArc_1_2")], False) +Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1"), model.selection("EDGE", "Sketch_1/SketchLine_2")], False) +Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_6r-SketchLine_5r-SketchLine_4r-SketchLine_3r")]) +Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_10r-SketchLine_9r-SketchLine_11f-SketchLine_7r"), model.selection("FACE", "Sketch_1/Face-SketchLine_11r-SketchLine_9r-SketchLine_8r-SketchLine_7r")]) +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 50) +Box_2 = model.addBox(Part_1_doc, 10, 10, 10) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10) +Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_2_1"), model.selection("SOLID", "Cylinder_1_1")], keepSubResults = True) +Box_3 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OY"), 50) +AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Translation_2_1")], model.selection("EDGE", "PartSet/OZ"), 30, 3) +model.end() + +TOLERANCE = 1.e-7 +SCALE = 2 + + +model.begin() +Scale_1 = model.addScale(Part_1_doc, [model.selection("VERTEX", "Vertex_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +model.testNbResults(Scale_1, 1) +model.testNbSubResults(Scale_1, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.EDGE, [0]) +model.testNbSubShapes(Scale_1, GeomAPI_Shape.VERTEX, [1]) +model.testResultsVolumes(Scale_1, [0]) +refPoint = GeomAPI_Pnt(Vertex_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_2 = model.addScale(Part_1_doc, [model.selection("EDGE", "Edge_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +model.testNbResults(Scale_2, 1) +model.testNbSubResults(Scale_2, [0]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.EDGE, [1]) +model.testNbSubShapes(Scale_2, GeomAPI_Shape.VERTEX, [2]) +model.testResultsVolumes(Scale_2, [0]) +refPoint = GeomAPI_Pnt(Edge_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_3 = model.addScale(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +model.testNbResults(Scale_3, 1) +model.testNbSubResults(Scale_3, [0]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.EDGE, [2]) +model.testNbSubShapes(Scale_3, GeomAPI_Shape.VERTEX, [4]) +model.testResultsVolumes(Scale_3, [0]) +refPoint = GeomAPI_Pnt(Wire_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_4 = model.addScale(Part_1_doc, [model.selection("FACE", "Face_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +model.testNbResults(Scale_4, 1) +model.testNbSubResults(Scale_4, [0]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.FACE, [1]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.EDGE, [4]) +model.testNbSubShapes(Scale_4, GeomAPI_Shape.VERTEX, [8]) +model.testResultsVolumes(Scale_4, [109.154152964914914 * (SCALE**2)]) +refPoint = GeomAPI_Pnt(Face_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_4.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_5 = model.addScale(Part_1_doc, [model.selection("SHELL", "Shell_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +model.testNbResults(Scale_5, 1) +model.testNbSubResults(Scale_5, [0]) +model.testNbSubShapes(Scale_5, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Scale_5, GeomAPI_Shape.FACE, [2]) +model.testNbSubShapes(Scale_5, GeomAPI_Shape.EDGE, [8]) +model.testNbSubShapes(Scale_5, GeomAPI_Shape.VERTEX, [16]) +model.testResultsVolumes(Scale_5, [182.822012116 * (SCALE**2)]) +refPoint = GeomAPI_Pnt(Shell_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_5.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_6 = model.addScale(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +model.testNbResults(Scale_6, 1) +model.testNbSubResults(Scale_6, [0]) +model.testNbSubShapes(Scale_6, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Scale_6, GeomAPI_Shape.FACE, [6]) +model.testNbSubShapes(Scale_6, GeomAPI_Shape.EDGE, [24]) +model.testNbSubShapes(Scale_6, GeomAPI_Shape.VERTEX, [48]) +model.testResultsVolumes(Scale_6, [1000 * (SCALE**3)]) +refPoint = GeomAPI_Pnt(Translation_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_6.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_7 = model.addScale(Part_1_doc, [model.selection("COMPSOLID", "Partition_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +model.testNbResults(Scale_7, 1) +model.testNbSubResults(Scale_7, [3]) +model.testNbSubShapes(Scale_7, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Scale_7, GeomAPI_Shape.FACE, [17]) +model.testNbSubShapes(Scale_7, GeomAPI_Shape.EDGE, [66]) +model.testNbSubShapes(Scale_7, GeomAPI_Shape.VERTEX, [132]) +model.testResultsVolumes(Scale_7, [1589.0486226 * (SCALE**3)]) +refPoint = GeomAPI_Pnt(Partition_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_7.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Scale_8 = model.addScale(Part_1_doc, [model.selection("COMPOUND", "AngularCopy_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +model.testNbResults(Scale_8, 1) +model.testNbSubResults(Scale_8, [3]) +model.testNbSubShapes(Scale_8, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Scale_8, GeomAPI_Shape.FACE, [18]) +model.testNbSubShapes(Scale_8, GeomAPI_Shape.EDGE, [72]) +model.testNbSubShapes(Scale_8, GeomAPI_Shape.VERTEX, [144]) +model.testResultsVolumes(Scale_8, [3000 * (SCALE**3)]) +refPoint = GeomAPI_Pnt(AngularCopy_1.defaultResult().shape().middlePoint().xyz().multiplied(SCALE)) +midPoint = Scale_8.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_4.py b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_4.py new file mode 100644 index 000000000..cdb117c07 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_4.py @@ -0,0 +1,136 @@ +# Copyright (C) 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 +from GeomAPI import * + +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")) +SketchPoint_1 = Sketch_1.addPoint(44.29784155360136, 17.09942588468031) +SketchArc_1 = Sketch_1.addArc(44.29784155360136, 17.09942588468031, 47.1668727423061, 12.27945348765633, 45.38299232715926, 22.60269052200972, False) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchArc_1.center()) +SketchLine_1 = Sketch_1.addLine(42.5764228403785, 22.14892077680068, 39.70739165167375, 16.41085839939117) +SketchLine_2 = Sketch_1.addLine(39.70739165167375, 16.41085839939117, 43.03546783057126, 12.04993099255995) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(28.57555063949931, 12.96802097294547, 15.72229091410204, 12.96802097294547) +SketchLine_4 = Sketch_1.addLine(15.72229091410204, 12.96802097294547, 15.72229091410204, 21.46035329151154) +SketchLine_5 = Sketch_1.addLine(15.72229091410204, 21.46035329151154, 28.57555063949931, 21.46035329151154) +SketchLine_6 = Sketch_1.addLine(28.57555063949931, 21.46035329151154, 28.57555063949931, 12.96802097294547) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_4.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_5.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_6.result()) +SketchLine_7 = Sketch_1.addLine(-10.67279602198167, 14.78814178154371, -28.34602814440294, 14.78814178154371) +SketchLine_8 = Sketch_1.addLine(-28.34602814440294, 14.78814178154371, -28.34602814440294, 25.13271321305362) +SketchLine_9 = Sketch_1.addLine(-28.34602814440294, 25.13271321305362, -10.67279602198167, 25.13271321305362) +SketchLine_10 = Sketch_1.addLine(-10.67279602198167, 25.13271321305362, -10.67279602198167, 14.78814178154371) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_10.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint()) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint()) +SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_7.result()) +SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_8.result()) +SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_9.result()) +SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_10.result()) +SketchLine_11 = Sketch_1.addLine(-17.67323212242127, 25.13271321305362, -21.80463703415611, 14.78814178154371) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_11.startPoint(), SketchLine_9.result()) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_11.endPoint(), SketchLine_7.result()) +model.do() +Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchArc_1")], False) +Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchArc_1_2")], False) +Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1"), model.selection("EDGE", "Sketch_1/SketchLine_2")], False) +Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_6r-SketchLine_5r-SketchLine_4r-SketchLine_3r")]) +Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_10r-SketchLine_9r-SketchLine_11f-SketchLine_7r"), model.selection("FACE", "Sketch_1/Face-SketchLine_11r-SketchLine_9r-SketchLine_8r-SketchLine_7r")]) +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 50) +Box_2 = model.addBox(Part_1_doc, 10, 10, 10) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10) +Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_2_1"), model.selection("SOLID", "Cylinder_1_1")], keepSubResults = True) +Box_3 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OY"), 50) +AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Translation_2_1")], model.selection("EDGE", "PartSet/OZ"), 30, 3) +Compound_1_objects = [model.selection("VERTEX", "Vertex_1_1"), model.selection("EDGE", "Edge_1_1"), model.selection("WIRE", "Wire_1_1"), model.selection("FACE", "Face_1_1"), model.selection("SHELL", "Shell_1_1"), model.selection("SOLID", "Translation_1_1"), model.selection("COMPSOLID", "Partition_1_1"), model.selection("COMPOUND", "AngularCopy_1_1")] +Compound_1 = model.addCompound(Part_1_doc, Compound_1_objects) +model.end() + +SCALE = 2 +VOLUME = 5589.0486226 +TOLERANCE = 1.e-7 + +# collect reference data +REFERENCE = [] +for ind in range(0, Compound_1.result().numberOfSubs()): + p = Compound_1.result().subResult(ind).resultSubShapePair()[1].middlePoint() + REFERENCE.append(p) + +def assertResult(theFeature, theNbMoved): + model.testNbResults(theFeature, 1) + model.testNbSubResults(theFeature, [8]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.SOLID, [7]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [44]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [177]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [355]) + model.testResultsVolumes(theFeature, [VOLUME]) + + for ind in range(0, theFeature.result().numberOfSubs()): + ref = GeomAPI_Pnt(REFERENCE[ind].x(), REFERENCE[ind].y(), REFERENCE[ind].z()) + if ind < theNbMoved: + ref = GeomAPI_Pnt(ref.xyz().multiplied(SCALE)) + midPoint = theFeature.result().subResult(ind).resultSubShapePair()[0].shape().middlePoint() + assert(midPoint.distance(ref) < TOLERANCE), "Sub-result {}; actual ({}, {}, {}) != expected ({}, {}, {})".format(ind, midPoint.x(), midPoint.y(), midPoint.z(), ref.x(), ref.y(), ref.z()) + + +model.begin() +Scale_1 = model.addScale(Part_1_doc, [model.selection("VERTEX", "Compound_1_1_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +assertResult(Scale_1, 1) + +Scale_2 = model.addScale(Part_1_doc, [model.selection("EDGE", "Scale_1_1_2")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +assertResult(Scale_2, 2) + +Scale_3 = model.addScale(Part_1_doc, [model.selection("WIRE", "Scale_2_1_3")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +assertResult(Scale_3, 3) + +Scale_4 = model.addScale(Part_1_doc, [model.selection("FACE", "Scale_3_1_4")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +assertResult(Scale_4, 4) + +Scale_5 = model.addScale(Part_1_doc, [model.selection("SHELL", "Scale_4_1_5")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +assertResult(Scale_5, 5) + +Scale_6 = model.addScale(Part_1_doc, [model.selection("SOLID", "Scale_5_1_6")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +VOLUME += 1000 * (SCALE**3 - 1) +assertResult(Scale_6, 6) + +Scale_7 = model.addScale(Part_1_doc, [model.selection("COMPSOLID", "Scale_6_1_7")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +VOLUME += 1589.0486226 * (SCALE**3 - 1) +assertResult(Scale_7, 7) + +Scale_8 = model.addScale(Part_1_doc, [model.selection("COMPOUND", "Scale_7_1_8")], model.selection("VERTEX", "PartSet/Origin"), SCALE, keepSubResults = True) +VOLUME += 3000 * (SCALE**3 - 1) +assertResult(Scale_8, 8) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/GeomAPI/GeomAPI_Solid.cpp b/src/GeomAPI/GeomAPI_Solid.cpp index cc8dc6d04..86b8ea80d 100644 --- a/src/GeomAPI/GeomAPI_Solid.cpp +++ b/src/GeomAPI/GeomAPI_Solid.cpp @@ -310,7 +310,7 @@ GeomPointPtr GeomAPI_Solid::middlePoint() const return anInnerPoint; GProp_GProps aProps; - BRepGProp::SurfaceProperties(aSolid, aProps, 1.e-4); + BRepGProp::VolumeProperties(aSolid, aProps, 1.e-4); gp_Pnt aPnt = aProps.CentreOfMass(); anInnerPoint = GeomPointPtr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));