From: azv Date: Sun, 23 Feb 2020 11:10:48 +0000 (+0300) Subject: Task 3.2. To keep compounds’ sub-shapes for all operations (issue #3139) X-Git-Tag: V9_5_0a1^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6501b9ab5d3c4d76af5e7628582a7716f8354cd7;p=modules%2Fshaper.git Task 3.2. To keep compounds’ sub-shapes for all operations (issue #3139) Refactor the Linear Copy and the Angular Copy features. --- diff --git a/src/FeaturesAPI/FeaturesAPI.i b/src/FeaturesAPI/FeaturesAPI.i index 2dfba2c48..7d1505907 100644 --- a/src/FeaturesAPI/FeaturesAPI.i +++ b/src/FeaturesAPI/FeaturesAPI.i @@ -41,6 +41,8 @@ %feature("kwargs") addCommon; %feature("kwargs") addCut; %feature("kwargs") addFuse; +%feature("kwargs") addMultiRotation; +%feature("kwargs") addMultiTranslation; %feature("kwargs") addPartition; %feature("kwargs") addPlacement; %feature("kwargs") addRotation; diff --git a/src/FeaturesAPI/FeaturesAPI_MultiRotation.cpp b/src/FeaturesAPI/FeaturesAPI_MultiRotation.cpp index 8e59da5f2..44bbd0b2b 100644 --- a/src/FeaturesAPI/FeaturesAPI_MultiRotation.cpp +++ b/src/FeaturesAPI/FeaturesAPI_MultiRotation.cpp @@ -23,6 +23,7 @@ #include +#include #include #include @@ -132,19 +133,10 @@ void FeaturesAPI_MultiRotation::dump(ModelHighAPI_Dumper& theDumper) const aBase->integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID()); theDumper << ", " << anAttrNumberAngular; - theDumper << ")" << std::endl; -} + if (!aBase->data()->version().empty()) + theDumper << ", keepSubResults = True"; -//================================================================================================== -MultiRotationPtr addMultiRotation(const std::shared_ptr& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Selection& theAxis, - const ModelHighAPI_Integer& theNumber) -{ - std::shared_ptr aFeature = - thePart->addFeature(FeaturesAPI_MultiRotation::ID()); - return MultiRotationPtr(new FeaturesAPI_MultiRotation(aFeature, theMainObjects, - theAxis, theNumber)); + theDumper << ")" << std::endl; } //================================================================================================== @@ -152,10 +144,30 @@ MultiRotationPtr addMultiRotation(const std::shared_ptr& theP const std::list& theMainObjects, const ModelHighAPI_Selection& theAxis, const ModelHighAPI_Double& theStep, - const ModelHighAPI_Integer& theNumber) + const ModelHighAPI_Integer& theNumber, + const bool keepSubResults) { std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_MultiRotation::ID()); - return MultiRotationPtr(new FeaturesAPI_MultiRotation(aFeature, theMainObjects, - theAxis, theStep, theNumber)); + if (!keepSubResults) + aFeature->data()->setVersion(""); + + MultiRotationPtr aResult; + if (theNumber.string().empty()) { + // rotate for the whole circle + double aStepVal = theStep.value(); + std::string aStepStr = theStep.string(); + std::ostringstream aStepValAsStr; + aStepValAsStr << aStepVal; + + ModelHighAPI_Integer aNumber = aStepStr == aStepValAsStr.str() + ? ModelHighAPI_Integer(aStepVal) + : ModelHighAPI_Integer(aStepStr); + aResult.reset(new FeaturesAPI_MultiRotation(aFeature, theMainObjects, theAxis, aNumber)); + } + else { + aResult.reset(new FeaturesAPI_MultiRotation(aFeature, theMainObjects, + theAxis, theStep, theNumber)); + } + return aResult; } diff --git a/src/FeaturesAPI/FeaturesAPI_MultiRotation.h b/src/FeaturesAPI/FeaturesAPI_MultiRotation.h index 6c33affb0..0b87f76f2 100644 --- a/src/FeaturesAPI/FeaturesAPI_MultiRotation.h +++ b/src/FeaturesAPI/FeaturesAPI_MultiRotation.h @@ -28,12 +28,12 @@ #include +#include #include #include class ModelHighAPI_Double; class ModelHighAPI_Dumper; -class ModelHighAPI_Integer; class ModelHighAPI_Selection; /// \class FeaturesAPI_MultiRotation @@ -102,14 +102,6 @@ public: /// Pointer on Multirotation object. typedef std::shared_ptr MultiRotationPtr; -/// \ingroup CPPHighAPI -/// \brief Create MultiRotation feature. -FEATURESAPI_EXPORT -MultiRotationPtr addMultiRotation(const std::shared_ptr& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Selection& theAxis, - const ModelHighAPI_Integer& theNumber); - /// \ingroup CPPHighAPI /// \brief Create MultiRotation feature. FEATURESAPI_EXPORT @@ -117,6 +109,7 @@ MultiRotationPtr addMultiRotation(const std::shared_ptr& theP const std::list& theMainObjects, const ModelHighAPI_Selection& theAxis, const ModelHighAPI_Double& theStep, - const ModelHighAPI_Integer& theNumber); + const ModelHighAPI_Integer& theNumber = ModelHighAPI_Integer(""), + const bool keepSubResults = false); #endif // FEATURESAPI_MULTIROTATION_H_ diff --git a/src/FeaturesAPI/FeaturesAPI_MultiTranslation.cpp b/src/FeaturesAPI/FeaturesAPI_MultiTranslation.cpp index c5afd8444..9885ed33e 100644 --- a/src/FeaturesAPI/FeaturesAPI_MultiTranslation.cpp +++ b/src/FeaturesAPI/FeaturesAPI_MultiTranslation.cpp @@ -155,20 +155,10 @@ void FeaturesAPI_MultiTranslation::dump(ModelHighAPI_Dumper& theDumper) const theDumper << ", " << anAttrSecondNumber; } - theDumper << ")" << std::endl; -} + if (!aBase->data()->version().empty()) + theDumper << ", keepSubResults = True"; -//================================================================================================== -MultiTranslationPtr addMultiTranslation(const std::shared_ptr& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Selection& theAxisObject, - const ModelHighAPI_Double& theStep, - const ModelHighAPI_Integer& theNumber) -{ - std::shared_ptr aFeature = - thePart->addFeature(FeaturesAPI_MultiTranslation::ID()); - return MultiTranslationPtr(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects, - theAxisObject, theStep, theNumber)); + theDumper << ")" << std::endl; } //================================================================================================== @@ -179,13 +169,22 @@ MultiTranslationPtr addMultiTranslation(const std::shared_ptr const ModelHighAPI_Integer& theFirstNumber, const ModelHighAPI_Selection& theSecondAxisObject, const ModelHighAPI_Double& theSecondStep, - const ModelHighAPI_Integer& theSecondNumber) + const ModelHighAPI_Integer& theSecondNumber, + const bool keepSubResults) { std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_MultiTranslation::ID()); - return MultiTranslationPtr(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects, - theFirstAxisObject, theFirstStep, - theFirstNumber, - theSecondAxisObject, theSecondStep, - theSecondNumber)); + if (!keepSubResults) + aFeature->data()->setVersion(""); + MultiTranslationPtr aMT; + if (theSecondAxisObject.variantType() == ModelHighAPI_Selection::VT_Empty) { + aMT.reset(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects, + theFirstAxisObject, theFirstStep, theFirstNumber)); + } + else { + aMT.reset(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects, + theFirstAxisObject, theFirstStep, theFirstNumber, + theSecondAxisObject, theSecondStep, theSecondNumber)); + } + return aMT; } diff --git a/src/FeaturesAPI/FeaturesAPI_MultiTranslation.h b/src/FeaturesAPI/FeaturesAPI_MultiTranslation.h index d62314116..489f66d7e 100644 --- a/src/FeaturesAPI/FeaturesAPI_MultiTranslation.h +++ b/src/FeaturesAPI/FeaturesAPI_MultiTranslation.h @@ -24,13 +24,13 @@ #include +#include +#include #include #include +#include -class ModelHighAPI_Double; class ModelHighAPI_Dumper; -class ModelHighAPI_Integer; -class ModelHighAPI_Selection; /// \class FeaturesAPI_MultiTranslation /// \ingroup CPPHighAPI @@ -116,23 +116,15 @@ typedef std::shared_ptr MultiTranslationPtr; /// \ingroup CPPHighAPI /// \brief Create MultiTranslation feature. -FEATURESAPI_EXPORT -MultiTranslationPtr addMultiTranslation(const std::shared_ptr& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Selection& theAxisObject, - const ModelHighAPI_Double& theStep, - const ModelHighAPI_Integer& theNumber); - -/// \ingroup CPPHighAPI -/// \brief Create MultiTranslation feature. -FEATURESAPI_EXPORT -MultiTranslationPtr addMultiTranslation(const std::shared_ptr& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Selection& theFirstAxisObject, - const ModelHighAPI_Double& theFirstStep, - const ModelHighAPI_Integer& theFirstNumber, - const ModelHighAPI_Selection& theSecondAxisObject, - const ModelHighAPI_Double& theSecondStep, - const ModelHighAPI_Integer& theSecondNumber); +FEATURESAPI_EXPORT MultiTranslationPtr addMultiTranslation( + const std::shared_ptr& thePart, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theFirstAxisObject, + const ModelHighAPI_Double& theFirstStep, + const ModelHighAPI_Integer& theFirstNumber, + const ModelHighAPI_Selection& theSecondAxisObject = ModelHighAPI_Selection(), + const ModelHighAPI_Double& theSecondStep = ModelHighAPI_Double(), + const ModelHighAPI_Integer& theSecondNumber = ModelHighAPI_Integer(), + const bool keepSubResults = false); #endif // FEATURESAPI_MULTITRANSLATION_H_ diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 1b06f51f8..4aff68961 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -617,4 +617,20 @@ ADD_UNIT_TESTS(TestExtrusion.py TestScale_MultiLevelCompound_v95_2.py TestScale_MultiLevelCompound_v95_3.py TestScale_MultiLevelCompound_v95_4.py + TestMultiTranslation_MultiLevelCompound_v0_1.py + TestMultiTranslation_MultiLevelCompound_v0_2.py + TestMultiTranslation_MultiLevelCompound_v0_3.py + TestMultiTranslation_MultiLevelCompound_v0_4.py + TestMultiTranslation_MultiLevelCompound_v95_1.py + TestMultiTranslation_MultiLevelCompound_v95_2.py + TestMultiTranslation_MultiLevelCompound_v95_3.py + TestMultiTranslation_MultiLevelCompound_v95_4.py + TestMultiRotation_MultiLevelCompound_v0_1.py + TestMultiRotation_MultiLevelCompound_v0_2.py + TestMultiRotation_MultiLevelCompound_v0_3.py + TestMultiRotation_MultiLevelCompound_v0_4.py + TestMultiRotation_MultiLevelCompound_v95_1.py + TestMultiRotation_MultiLevelCompound_v95_2.py + TestMultiRotation_MultiLevelCompound_v95_3.py + TestMultiRotation_MultiLevelCompound_v95_4.py ) diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp index 68151d9c6..07cdcd7a9 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp @@ -48,6 +48,8 @@ #include #include +static const std::string MULTIROTATION_VERSION_1("v9.5"); + //================================================================================================= FeaturesPlugin_MultiRotation::FeaturesPlugin_MultiRotation() { @@ -78,6 +80,11 @@ void FeaturesPlugin_MultiRotation::initAttributes() data()->addAttribute(FeaturesPlugin_MultiRotation::NB_COPIES_RADIAL_ID(), ModelAPI_AttributeInteger::typeId()); #endif + + if (!aSelection->isInitialized()) { + // new feature, not read from file + data()->setVersion(MULTIROTATION_VERSION_1); + } } //================================================================================================= @@ -96,132 +103,128 @@ void FeaturesPlugin_MultiRotation::execute() } //================================================================================================= -void FeaturesPlugin_MultiRotation::performRotation1D() +bool FeaturesPlugin_MultiRotation::paramsOfRotation(std::shared_ptr& theAxis, + double& theAngle, + int& theQuantity) { - // Getting objects. - ListOfShape anObjects; - std::list aContextes; - AttributeSelectionListPtr anObjectsSelList = - selectionList(FeaturesPlugin_MultiRotation::OBJECTS_LIST_ID()); - if (anObjectsSelList->size() == 0) { - setError("Error: empty selection list"); - 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 axis. static const std::string aSelectionError = "Error: The axis shape selection is bad."; AttributeSelectionPtr anObjRef = selection(AXIS_ANGULAR_ID()); GeomShapePtr aShape = anObjRef->value(); - if (!aShape.get()) { - if (anObjRef->context().get()) { - aShape = anObjRef->context()->shape(); - } - } + if (!aShape.get() && anObjRef->context().get()) + aShape = anObjRef->context()->shape(); if (!aShape.get()) { setError(aSelectionError); - return; + return false; } GeomEdgePtr anEdge; if (aShape->isEdge()) - { anEdge = aShape->edge(); - } - else if (aShape->isCompound()) - { + else if (aShape->isCompound()) { GeomAPI_ShapeIterator anIt(aShape); anEdge = anIt.current()->edge(); } - if (!anEdge.get()) - { + if (!anEdge.get()) { setError(aSelectionError); - return; + return false; } - std::shared_ptr anAxis(new GeomAPI_Ax1(anEdge->line()->location(), - anEdge->line()->direction())); + theAxis.reset(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction())); // Getting number of copies. - int nbCopies = - integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID())->value(); - - if (nbCopies <=0) { + theQuantity = integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID())->value(); + if (theQuantity <= 0) { std::string aFeatureError = "Multirotation builder "; - aFeatureError+=":: the number of copies for the angular direction is null or negative."; + aFeatureError += ":: the number of copies for the angular direction is null or negative."; setError(aFeatureError); - return; + return false; } // Getting angle - double anAngle; std::string useAngularStep = string(FeaturesPlugin_MultiRotation::USE_ANGULAR_STEP_ID())->value(); - if (!useAngularStep.empty()) { - anAngle = real(FeaturesPlugin_MultiRotation::STEP_ANGULAR_ID())->value(); - } else { - anAngle = 360./nbCopies; + if (!useAngularStep.empty()) + theAngle = real(FeaturesPlugin_MultiRotation::STEP_ANGULAR_ID())->value(); + else + theAngle = 360. / theQuantity; + return true; +} + +//================================================================================================= +void FeaturesPlugin_MultiRotation::performRotation1D() +{ + bool isKeepSubShapes = data()->version() == MULTIROTATION_VERSION_1; + + // Getting objects. + AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECTS_LIST_ID()); + if (anObjectsSelList->size() == 0) { + setError("Error: empty selection list"); + return; } - // Moving each object. + GeomAPI_ShapeHierarchy anObjects; + std::list aParts; + if (!FeaturesPlugin_Tools::shapesFromSelectionList( + anObjectsSelList, isKeepSubShapes, anObjects, aParts)) + return; + + // Parameters of rotation. + std::shared_ptr anAxis; + double anAngle = 0.0; + int nbCopies = 0; + if (!paramsOfRotation(anAxis, anAngle, nbCopies)) + return; + + + 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 aBaseShape = *anObjectsIt; - bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); + // Moving each part. + for (std::list::iterator aPRes = aParts.begin(); aPRes != aParts.end(); ++aPRes) { + ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aPRes); + std::shared_ptr aTrsf(new GeomAPI_Trsf()); + for (int i = 0; i < nbCopies; ++i) { + aTrsf->setRotation(anAxis, i * anAngle); + ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); + aResultPart->setTrsf(anOrigin, aTrsf); + setResult(aResultPart, aResultIndex++); + } + } - // Setting result. - if (isPart) { - ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); - std::shared_ptr aTrsf(new GeomAPI_Trsf()); - for (int i=0; isetRotation(anAxis, i*anAngle); - ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); - aResultPart->setTrsf(*aContext, aTrsf); - setResult(aResultPart, aResultIndex); - aResultIndex++; - } - } else { - std::string anError; - ListOfShape aListOfShape; - std::shared_ptr - aListOfRotationAlgo(new GeomAlgoAPI_MakeShapeList); + // Collect transformations for each object in a part. + std::shared_ptr aMakeShapeList(new GeomAlgoAPI_MakeShapeList); + for (GeomAPI_ShapeHierarchy::iterator anObjectsIt = anObjects.begin(); + anObjectsIt != anObjects.end(); anObjectsIt++) { + std::shared_ptr aBaseShape = *anObjectsIt; + ListOfShape aListOfShape; - for (int i=0; i aRotationnAlgo( - new GeomAlgoAPI_Rotation(aBaseShape, anAxis, i*anAngle)); + for (int i = 0; i < nbCopies; i++) { + std::shared_ptr aRotationnAlgo( + new GeomAlgoAPI_Rotation(aBaseShape, anAxis, i * anAngle)); - // Checking that the algorithm worked properly. - if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationnAlgo, getKind(), anError)) { - setError(anError); - break; - } - aListOfShape.push_back(aRotationnAlgo->shape()); - aListOfRotationAlgo->appendAlgo(aRotationnAlgo); + // Checking that the algorithm worked properly. + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationnAlgo, getKind(), anError)) { + setError(anError); + break; } - std::shared_ptr aCompound = - GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + aListOfShape.push_back(aRotationnAlgo->shape()); + aMakeShapeList->appendAlgo(aRotationnAlgo); + } - ListOfShape aBaseShapes; - aBaseShapes.push_back(aBaseShape); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, aBaseShapes, ListOfShape(), - aListOfRotationAlgo, aCompound, "Rotated"); + GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); + anObjects.markModified(aBaseShape, aCompound); + } - setResult(aResultBody, aResultIndex); - aResultIndex++; - } + // Build results of the operation. + 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, "Rotated"); + setResult(aResultBody, aResultIndex++); } // Remove the rest results if there were produced in the previous pass. @@ -251,32 +254,13 @@ void FeaturesPlugin_MultiRotation::performRotation2D() aContextes.push_back(anObjectAttr->context()); } - //Getting axis. + // Parameters of rotation. std::shared_ptr anAxis; - std::shared_ptr anEdge; - std::shared_ptr anObjRef = - selection(FeaturesPlugin_MultiRotation::AXIS_ANGULAR_ID()); - if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) { - anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->value())); - } else if (anObjRef && !anObjRef->value() && anObjRef->context() && - anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) { - anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->context()->shape())); - } - if(anEdge) { - anAxis = std::shared_ptr(new GeomAPI_Ax1(anEdge->line()->location(), - anEdge->line()->direction())); - } - - // Getting number of copies int he angular direction. - int nbAngular = - integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID())->value(); - - if (nbAngular <=0) { - std::string aFeatureError = "Multirotation builder "; - aFeatureError+=":: the number of copies for the angular direction is null or negative."; - setError(aFeatureError); + double anAngle = 0.0; + int nbCopies = 0; + if (!paramsOfRotation(anAxis, anAngle, nbCopies)) return; - } + // Getting number of copies int he radial direction. int nbRadial = @@ -289,16 +273,6 @@ void FeaturesPlugin_MultiRotation::performRotation2D() return; } - // Getting angle - double anAngle; - std::string useAngularStep = - string(FeaturesPlugin_MultiRotation::USE_ANGULAR_STEP_ID())->value(); - if (!useAngularStep.empty()) { - anAngle = real(FeaturesPlugin_MultiRotation::STEP_ANGULAR_ID())->value(); - } else { - anAngle = 360./nbAngular; - } - // Getting step double aStep = real(FeaturesPlugin_MultiRotation::STEP_RADIAL_ID())->value(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.h b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.h index 4b3cb965d..6c81a130b 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.h +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.h @@ -120,6 +120,10 @@ class FeaturesPlugin_MultiRotation : public ModelAPI_Feature FeaturesPlugin_MultiRotation(); private: + /// Fill axis, number of copies and angle of the rotation. + /// \returns \c false in case of errors. + bool paramsOfRotation(std::shared_ptr& theAxis, double& theAngle, int& theQuantity); + /// Perform the multi rotation in one direction. void performRotation1D(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp index 51e96cd4a..d8b030f14 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -39,6 +40,8 @@ #include +static const std::string MULTITRANSLATION_VERSION_1("v9.5"); + //================================================================================================= FeaturesPlugin_MultiTranslation::FeaturesPlugin_MultiTranslation() { @@ -67,117 +70,83 @@ void FeaturesPlugin_MultiTranslation::initAttributes() ModelAPI_AttributeDouble::typeId()); data()->addAttribute(FeaturesPlugin_MultiTranslation::NB_COPIES_SECOND_DIR_ID(), ModelAPI_AttributeInteger::typeId()); -} -//================================================================================================= -void FeaturesPlugin_MultiTranslation::execute() -{ - std::string useSecondDir = string(FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID())->value(); - if(!useSecondDir.empty()) { - performTwoDirection(); - } else { - performOneDirection(); + if (!aSelection->isInitialized()) { + // new feature, not read from file + data()->setVersion(MULTITRANSLATION_VERSION_1); } } //================================================================================================= -void FeaturesPlugin_MultiTranslation::performOneDirection() +void FeaturesPlugin_MultiTranslation::execute() { + bool isKeepSubShapes = data()->version() == MULTITRANSLATION_VERSION_1; + // Getting objects. - ListOfShape anObjects; - std::list aContextes; - AttributeSelectionListPtr anObjectsSelList = - selectionList(FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID()); + AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECTS_LIST_ID()); if (anObjectsSelList->size() == 0) { setError("Error: empty selection list"); 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 axis. - static const std::string aSelectionError = "Error: The axis shape selection is bad."; - AttributeSelectionPtr anObjRef = selection(AXIS_FIRST_DIR_ID()); - GeomShapePtr aShape = anObjRef->value(); - if (!aShape.get()) { - if (anObjRef->context().get()) { - aShape = anObjRef->context()->shape(); - } - } - if (!aShape.get()) { - setError(aSelectionError); + GeomAPI_ShapeHierarchy anObjects; + std::list aParts; + if (!FeaturesPlugin_Tools::shapesFromSelectionList( + anObjectsSelList, isKeepSubShapes, anObjects, aParts)) return; - } - - GeomEdgePtr anEdge; - if (aShape->isEdge()) - { - anEdge = aShape->edge(); - } - else if (aShape->isCompound()) - { - GeomAPI_ShapeIterator anIt(aShape); - anEdge = anIt.current()->edge(); - } - if (!anEdge.get()) - { - setError(aSelectionError); + std::shared_ptr aFirstDir, aSecondDir; + double aFirstStep, aSecondStep; + int aFirstNbCopies, aSecondNbCopies; + if (!paramsAlongDirection(0, aFirstDir, aFirstStep, aFirstNbCopies)) return; - } - std::shared_ptr anAxis (new GeomAPI_Ax1(anEdge->line()->location(), - anEdge->line()->direction())); - - // Getting step. - double aStep = real(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID())->value(); - - // Getting number of copies. - int nbCopies = - integer(FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID())->value(); - - if (nbCopies <=0) { - std::string aFeatureError = "Multitranslation builder "; - aFeatureError+=":: the number of copies for the first direction is null or negative."; - setError(aFeatureError); - return; + bool useSecondDir = !string(USE_SECOND_DIR_ID())->value().empty(); + if (useSecondDir) { + if (!paramsAlongDirection(1, aSecondDir, aSecondStep, aSecondNbCopies)) + return; + } + else { + aSecondDir = aFirstDir; // direction does not matter + aSecondStep = 0.0; + aSecondNbCopies = 1; } - // Moving 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 aBaseShape = *anObjectsIt; - bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); + // Moving each part. + for (std::list::iterator aPRes = aParts.begin(); aPRes != aParts.end(); ++aPRes) { + ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aPRes); + std::shared_ptr aTrsf(new GeomAPI_Trsf()); + for (int j = 0; j < aSecondNbCopies; j++) { + for (int i = 0; i < aFirstNbCopies; i++) { + double dx = i * aFirstStep * aFirstDir->x() + j * aSecondStep * aSecondDir->x(); + double dy = i * aFirstStep * aFirstDir->y() + j * aSecondStep * aSecondDir->y(); + double dz = i * aFirstStep * aFirstDir->z() + j * aSecondStep * aSecondDir->z(); + aTrsf->setTranslation(dx, dy, dz); - // Setting result. - if (isPart) { - ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); - std::shared_ptr aTrsf(new GeomAPI_Trsf()); - for (int i=0; isetTranslation(anAxis, i*aStep); ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); - aResultPart->setTrsf(*aContext, aTrsf); + aResultPart->setTrsf(anOrigin, aTrsf); setResult(aResultPart, aResultIndex); aResultIndex++; } - } else { - std::string anError; - ListOfShape aListOfShape; - ListOfMakeShape aMakeShapeList; + } + } - for (int i=0; i aMakeShapeList(new GeomAlgoAPI_MakeShapeList); + for (GeomAPI_ShapeHierarchy::iterator anObjectsIt = anObjects.begin(); + anObjectsIt != anObjects.end(); anObjectsIt++) { + std::shared_ptr aBaseShape = *anObjectsIt; + ListOfShape aListOfShape; + + for (int j = 0; j < aSecondNbCopies; j++) { + for (int i = 0; i < aFirstNbCopies; i++) { + double dx = i * aFirstStep * aFirstDir->x() + j * aSecondStep * aSecondDir->x(); + double dy = i * aFirstStep * aFirstDir->y() + j * aSecondStep * aSecondDir->y(); + double dz = i * aFirstStep * aFirstDir->z() + j * aSecondStep * aSecondDir->z(); std::shared_ptr aTranslationAlgo( - new GeomAlgoAPI_Translation(aBaseShape, anAxis, i*aStep)); + new GeomAlgoAPI_Translation(aBaseShape, dx, dy, dz)); // Checking that the algorithm worked properly. if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed( @@ -186,24 +155,22 @@ void FeaturesPlugin_MultiTranslation::performOneDirection() break; } aListOfShape.push_back(aTranslationAlgo->shape()); - aMakeShapeList.push_back(aTranslationAlgo); + aMakeShapeList->appendAlgo(aTranslationAlgo); } - - std::shared_ptr - aListOfTranslationAlgo(new GeomAlgoAPI_MakeShapeList(aMakeShapeList)); - - std::shared_ptr aCompound = - GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - - ListOfShape aBaseShapes; - aBaseShapes.push_back(aBaseShape); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, aBaseShapes, ListOfShape(), - aListOfTranslationAlgo, aCompound, "Translated"); - - setResult(aResultBody, aResultIndex); - aResultIndex++; } + GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); + anObjects.markModified(aBaseShape, aCompound); + } + + // Build results of the operation. + 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, "Translated"); + setResult(aResultBody, aResultIndex++); } // Remove the rest results if there were produced in the previous pass. @@ -211,195 +178,48 @@ void FeaturesPlugin_MultiTranslation::performOneDirection() } //================================================================================================= -void FeaturesPlugin_MultiTranslation::performTwoDirection() +bool FeaturesPlugin_MultiTranslation::paramsAlongDirection(const int theIndex, + std::shared_ptr& theDir, + double& theDistance, + int& theQuantity) { - // Getting objects. - ListOfShape anObjects; - std::list aContextes; - AttributeSelectionListPtr anObjectsSelList = - selectionList(FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID()); - if (anObjectsSelList->size() == 0) { - setError("Error: empty selection list"); - 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()); - } + static std::string THE_AXIS_DIR[2] = { AXIS_FIRST_DIR_ID(), AXIS_SECOND_DIR_ID() }; + static std::string THE_STEP[2] = { STEP_FIRST_DIR_ID(), STEP_SECOND_DIR_ID() }; + static std::string THE_COPIES[2] = { NB_COPIES_FIRST_DIR_ID(), NB_COPIES_SECOND_DIR_ID() }; + static std::string THE_INDEX_ID[2] = { "first", "second" }; //Getting axis. static const std::string aSelectionError = "Error: The axis shape selection is bad."; - AttributeSelectionPtr anObjRef = selection(AXIS_FIRST_DIR_ID()); + AttributeSelectionPtr anObjRef = selection(THE_AXIS_DIR[theIndex]); GeomShapePtr aShape = anObjRef->value(); - if (!aShape.get()) { - if (anObjRef->context().get()) { - aShape = anObjRef->context()->shape(); - } - } + if (!aShape.get() && anObjRef->context().get()) + aShape = anObjRef->context()->shape(); if (!aShape.get()) { setError(aSelectionError); - return; + return false; } GeomEdgePtr anEdge; if (aShape->isEdge()) - { - anEdge = aShape->edge(); - } - else if (aShape->isCompound()) - { - GeomAPI_ShapeIterator anIt(aShape); - anEdge = anIt.current()->edge(); - } - - if (!anEdge.get()) - { - setError(aSelectionError); - return; - } - - std::shared_ptr aFirstAxis(new GeomAPI_Ax1(anEdge->line()->location(), - anEdge->line()->direction())); - - //Getting axis. - anObjRef = selection(AXIS_SECOND_DIR_ID()); - aShape = anObjRef->value(); - if (!aShape.get()) { - if (anObjRef->context().get()) { - aShape = anObjRef->context()->shape(); - } - } - if (!aShape.get()) { - setError(aSelectionError); - return; - } - - if (aShape->isEdge()) - { anEdge = aShape->edge(); - } - else if (aShape->isCompound()) - { + else if (aShape->isCompound()) { GeomAPI_ShapeIterator anIt(aShape); anEdge = anIt.current()->edge(); } - if (!anEdge.get()) - { + if (!anEdge.get()) { setError(aSelectionError); - return; - } - - std::shared_ptr aSecondAxis(new GeomAPI_Ax1(anEdge->line()->location(), - anEdge->line()->direction())); - - // Getting step. - double aFirstStep = real(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID())->value(); - double aSecondStep = real(FeaturesPlugin_MultiTranslation::STEP_SECOND_DIR_ID())->value(); - - // Getting number of copies. - int aFirstNbCopies = - integer(FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID())->value(); - int aSecondNbCopies = - integer(FeaturesPlugin_MultiTranslation::NB_COPIES_SECOND_DIR_ID())->value(); - - if (aFirstNbCopies <=0) { - std::string aFeatureError = "Multitranslation builder "; - aFeatureError+=":: the number of copies for the first direction is null or negative."; - setError(aFeatureError); - return; + return false; } - if (aSecondNbCopies <=0) { - std::string aFeatureError = "Multitranslation builder "; - aFeatureError+=":: the number of copies for the second direction is null or negative."; + theDir = anEdge->line()->direction(); + theDistance = real(THE_STEP[theIndex])->value(); + theQuantity = integer(THE_COPIES[theIndex])->value(); + if (theQuantity <= 0) { + std::string aFeatureError = "Multitranslation builder :: the number of copies for the "; + aFeatureError += THE_INDEX_ID[theIndex] + " direction is null or negative."; setError(aFeatureError); - return; - } - - // Coord aFirstAxis - double x1 = aFirstAxis->dir()->x(); - double y1 = aFirstAxis->dir()->y(); - double z1 = aFirstAxis->dir()->z(); - double norm1 = sqrt(x1*x1 + y1*y1 + z1*z1); - - // Coord aSecondAxis - double x2 = aSecondAxis->dir()->x(); - double y2 = aSecondAxis->dir()->y(); - double z2 = aSecondAxis->dir()->z(); - double norm2 = sqrt(x2*x2 + y2*y2 + z2*z2); - - // Moving each object. - int aResultIndex = 0; - std::list::iterator aContext = aContextes.begin(); - for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); - anObjectsIt++, aContext++) { - std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); - - // Setting result. - if (isPart) { - ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); - std::shared_ptr aTrsf(new GeomAPI_Trsf()); - for (int j=0; jsetTranslation(dx, dy, dz); - ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); - aResultPart->setTrsf(*aContext, aTrsf); - setResult(aResultPart, aResultIndex); - aResultIndex++; - } - } - } else { - std::string anError; - ListOfShape aListOfShape; - ListOfMakeShape aMakeShapeList; - - for (int j=0; j aTranslationAlgo( - new GeomAlgoAPI_Translation(aBaseShape, dx, dy, dz)); - - // Checking that the algorithm worked properly. - if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed( - aTranslationAlgo, getKind(), anError)) { - setError(anError); - break; - } - aListOfShape.push_back(aTranslationAlgo->shape()); - aMakeShapeList.push_back(aTranslationAlgo); - } - } - - std::shared_ptr - aListOfTranslationAlgo(new GeomAlgoAPI_MakeShapeList(aMakeShapeList)); - - std::shared_ptr aCompound = - GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - - ListOfShape aBaseShapes; - aBaseShapes.push_back(aBaseShape); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, aBaseShapes, ListOfShape(), - aListOfTranslationAlgo, aCompound, "Translated"); - - setResult(aResultBody, aResultIndex); - aResultIndex++; - } + return false; } - - // Remove the rest results if there were produced in the previous pass. - removeResults(aResultIndex); + return true; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h index 6f817ce41..be2329880 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h @@ -22,10 +22,10 @@ #include -#include - #include +class GeomAPI_Dir; + /** \class FeaturesPlugin_MultiTranslation * \ingroup Plugins * \brief Feature for movement objects along one or two axes an arbitary number of times, @@ -114,11 +114,12 @@ class FeaturesPlugin_MultiTranslation : public ModelAPI_Feature FeaturesPlugin_MultiTranslation(); private: - /// Perform the multi translation in one direction. - void performOneDirection(); - - /// Perform the multi translation in two directions. - void performTwoDirection(); + /// Fill axis, number of copies and distance for the given direction. + /// \returns \c false in case of errors. + bool paramsAlongDirection(const int theIndex, + std::shared_ptr& theDir, + double& theDistance, + int& theQuantity); }; #endif // FEATURESPLUGIN_MULTITRANSLATION_H_ \ No newline at end of file diff --git a/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v0_1.py b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v0_1.py new file mode 100644 index 000000000..674650d46 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v0_1.py @@ -0,0 +1,134 @@ +# 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 GeomAlgoAPI 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() + +ANGLE = 60 +COPIES = 3 +TOLERANCE = 1.e-7 + + +model.begin() +MultiRotation_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("EDGE", "PartSet/OZ"), ANGLE, COPIES) +model.testNbResults(MultiRotation_1, 1) +model.testNbSubResults(MultiRotation_1, [COPIES]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.SOLID, [1 * COPIES]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.FACE, [5 * COPIES]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.EDGE, [18 * COPIES]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.VERTEX, [36 * COPIES]) +model.testResultsVolumes(MultiRotation_1, [542.746463956 * COPIES]) + +refPoint = GeomAPI_Pnt(22.16914827868, -12.5, 5) +midPoint = MultiRotation_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_1 = model.addRecover(Part_1_doc, MultiRotation_1, [Compound_2.result()], True) +MultiRotation_2 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Recover_1_1_2_1")], model.selection("EDGE", "PartSet/OZ"), ANGLE, COPIES) +model.testNbResults(MultiRotation_2, 1) +model.testNbSubResults(MultiRotation_2, [COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.SOLID, [1 * COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.FACE, [3 * COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.EDGE, [6 * COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.VERTEX, [12 * COPIES]) +model.testResultsVolumes(MultiRotation_2, [785.39816339745 * COPIES]) + +refPoint = GeomAPI_Pnt(43.301270189, 5.3316102395, 5) +midPoint = MultiRotation_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_2 = model.addRecover(Part_1_doc, MultiRotation_2, [Recover_1.result()], True) +MultiRotation_3 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Recover_2_1_3")], model.selection("EDGE", "PartSet/OZ"), ANGLE, COPIES) +model.testNbResults(MultiRotation_3, 1) +model.testNbSubResults(MultiRotation_3, [COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.SOLID, [1 * COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.FACE, [3 * COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.EDGE, [6 * COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.VERTEX, [12 * COPIES]) +model.testResultsVolumes(MultiRotation_3, [785.39816339745 * COPIES]) + +refPoint = GeomAPI_Pnt(31.94572, -30.33161024, 5) +midPoint = MultiRotation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_3 = model.addRecover(Part_1_doc, MultiRotation_3, [Recover_2.result()], True) +MultiRotation_4 = model.addMultiRotation(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("EDGE", "PartSet/OZ"), ANGLE, COPIES) +model.testNbResults(MultiRotation_4, 3) +model.testNbSubResults(MultiRotation_4, [COPIES, COPIES, COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.SOLID, [1 * COPIES, 1 * COPIES, 1 * COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.FACE, [6 * COPIES, 3 * COPIES, 3 * COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.EDGE, [24 * COPIES, 6 * COPIES, 6 * COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.VERTEX, [48 * COPIES, 12 * COPIES, 12 * COPIES]) +model.testResultsVolumes(MultiRotation_4, [3444.394198615 * COPIES, 785.39816339745 * COPIES, 785.39816339745 * COPIES]) + +REFERENCE = [GeomAPI_Pnt(32.6022829255, -5.6990653637, 5), + GeomAPI_Pnt(1.06046515086, -17.8316102395, 5), + GeomAPI_Pnt(31.945720066, -30.3316102395, 5)] +for res, ref in zip(MultiRotation_4.results(), REFERENCE): + midPoint = res.resultSubShapePair()[0].shape().middlePoint() + assert(midPoint.distance(ref) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v0_2.py b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v0_2.py new file mode 100644 index 000000000..5779ece5e --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v0_2.py @@ -0,0 +1,133 @@ +# 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 GeomAlgoAPI 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() + +COPIES = 3 +TOLERANCE = 1.e-7 + + +model.begin() +MultiRotation_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("EDGE", "PartSet/OZ"), COPIES) +model.testNbResults(MultiRotation_1, 1) +model.testNbSubResults(MultiRotation_1, [COPIES]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.SOLID, [1 * COPIES]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.FACE, [5 * COPIES]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.EDGE, [18 * COPIES]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.VERTEX, [36 * COPIES]) +model.testResultsVolumes(MultiRotation_1, [542.746463956 * COPIES]) + +refPoint = GeomAPI_Pnt(0.518513184, -12.5, 5) +midPoint = MultiRotation_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_1 = model.addRecover(Part_1_doc, MultiRotation_1, [Compound_2.result()], True) +MultiRotation_2 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Recover_1_1_2_1")], model.selection("EDGE", "PartSet/OZ"), COPIES) +model.testNbResults(MultiRotation_2, 1) +model.testNbSubResults(MultiRotation_2, [COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.SOLID, [1 * COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.FACE, [3 * COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.EDGE, [6 * COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.VERTEX, [12 * COPIES]) +model.testResultsVolumes(MultiRotation_2, [785.39816339745 * COPIES]) + +refPoint = GeomAPI_Pnt(-11.355550122, 5.3316102, 5) +midPoint = MultiRotation_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_2 = model.addRecover(Part_1_doc, MultiRotation_2, [Recover_1.result()], True) +MultiRotation_3 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Recover_2_1_3")], model.selection("EDGE", "PartSet/OZ"), COPIES) +model.testNbResults(MultiRotation_3, 1) +model.testNbSubResults(MultiRotation_3, [COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.SOLID, [1 * COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.FACE, [3 * COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.EDGE, [6 * COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.VERTEX, [12 * COPIES]) +model.testResultsVolumes(MultiRotation_3, [785.39816339745 * COPIES]) + +refPoint = GeomAPI_Pnt(10.29508497, -12.5, 5) +midPoint = MultiRotation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_3 = model.addRecover(Part_1_doc, MultiRotation_3, [Recover_2.result()], True) +MultiRotation_4 = model.addMultiRotation(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("EDGE", "PartSet/OZ"), COPIES) +model.testNbResults(MultiRotation_4, 3) +model.testNbSubResults(MultiRotation_4, [COPIES, COPIES, COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.SOLID, [1 * COPIES, 1 * COPIES, 1 * COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.FACE, [6 * COPIES, 3 * COPIES, 3 * COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.EDGE, [24 * COPIES, 6 * COPIES, 6 * COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.VERTEX, [48 * COPIES, 12 * COPIES, 12 * COPIES]) +model.testResultsVolumes(MultiRotation_4, [3444.394198615 * COPIES, 785.39816339745 * COPIES, 785.39816339745 * COPIES]) + +REFERENCE = [GeomAPI_Pnt(-5.8665084688, -5.6990653637, 5), + GeomAPI_Pnt(1.06046515086, 5.3316102395, 5), + GeomAPI_Pnt(10.29508497, -12.5, 5)] +for res, ref in zip(MultiRotation_4.results(), REFERENCE): + midPoint = res.resultSubShapePair()[0].shape().middlePoint() + assert(midPoint.distance(ref) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v0_3.py b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v0_3.py new file mode 100644 index 000000000..7442e963f --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v0_3.py @@ -0,0 +1,199 @@ +# 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 GeomAlgoAPI 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 +COPIES = 4 + + +model.begin() +MultiRotation_1 = model.addMultiRotation(Part_1_doc, [model.selection("VERTEX", "Vertex_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_1, 1) +model.testNbSubResults(MultiRotation_1, [COPIES]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.EDGE, [0]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.VERTEX, [COPIES]) +model.testResultsVolumes(MultiRotation_1, [0]) +refPoint = Vertex_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_2 = model.addMultiRotation(Part_1_doc, [model.selection("EDGE", "Edge_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_2, 1) +model.testNbSubResults(MultiRotation_2, [COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.EDGE, [COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.VERTEX, [2 * COPIES]) +model.testResultsVolumes(MultiRotation_2, [0]) +comp = GeomAlgoAPI_CompoundBuilder.compound([Edge_1.defaultResult().shape()]) +refPoint = comp.middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_3 = model.addMultiRotation(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_3, 1) +model.testNbSubResults(MultiRotation_3, [COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.EDGE, [2 * COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.VERTEX, [4 * COPIES]) +model.testResultsVolumes(MultiRotation_3, [0]) +comp = GeomAlgoAPI_CompoundBuilder.compound([Wire_1.defaultResult().shape()]) +refPoint = comp.middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_4 = model.addMultiRotation(Part_1_doc, [model.selection("FACE", "Face_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_4, 1) +model.testNbSubResults(MultiRotation_4, [COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.FACE, [COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.EDGE, [4 * COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.VERTEX, [8 * COPIES]) +model.testResultsVolumes(MultiRotation_4, [109.154152964914914 * COPIES]) +refPoint = Face_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_4.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_5 = model.addMultiRotation(Part_1_doc, [model.selection("SHELL", "Shell_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_5, 1) +model.testNbSubResults(MultiRotation_5, [COPIES]) +model.testNbSubShapes(MultiRotation_5, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_5, GeomAPI_Shape.FACE, [2 * COPIES]) +model.testNbSubShapes(MultiRotation_5, GeomAPI_Shape.EDGE, [8 * COPIES]) +model.testNbSubShapes(MultiRotation_5, GeomAPI_Shape.VERTEX, [16 * COPIES]) +model.testResultsVolumes(MultiRotation_5, [182.822012116 * COPIES]) +refPoint = Shell_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_5.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_6 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_6, 1) +model.testNbSubResults(MultiRotation_6, [COPIES]) +model.testNbSubShapes(MultiRotation_6, GeomAPI_Shape.SOLID, [COPIES]) +model.testNbSubShapes(MultiRotation_6, GeomAPI_Shape.FACE, [6 * COPIES]) +model.testNbSubShapes(MultiRotation_6, GeomAPI_Shape.EDGE, [24 * COPIES]) +model.testNbSubShapes(MultiRotation_6, GeomAPI_Shape.VERTEX, [48 * COPIES]) +model.testResultsVolumes(MultiRotation_6, [1000 * COPIES]) +refPoint = Translation_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_6.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_7 = model.addMultiRotation(Part_1_doc, [model.selection("COMPSOLID", "Partition_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_7, 1) +model.testNbSubResults(MultiRotation_7, [COPIES]) +model.testNbSubShapes(MultiRotation_7, GeomAPI_Shape.SOLID, [3 * COPIES]) +model.testNbSubShapes(MultiRotation_7, GeomAPI_Shape.FACE, [17 * COPIES]) +model.testNbSubShapes(MultiRotation_7, GeomAPI_Shape.EDGE, [66 * COPIES]) +model.testNbSubShapes(MultiRotation_7, GeomAPI_Shape.VERTEX, [132 * COPIES]) +model.testResultsVolumes(MultiRotation_7, [1589.0486226 * COPIES]) +refPoint = Partition_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_7.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_8 = model.addMultiRotation(Part_1_doc, [model.selection("COMPOUND", "AngularCopy_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_8, 1) +model.testNbSubResults(MultiRotation_8, [COPIES]) +model.testNbSubShapes(MultiRotation_8, GeomAPI_Shape.SOLID, [3 * COPIES]) +model.testNbSubShapes(MultiRotation_8, GeomAPI_Shape.FACE, [18 * COPIES]) +model.testNbSubShapes(MultiRotation_8, GeomAPI_Shape.EDGE, [72 * COPIES]) +model.testNbSubShapes(MultiRotation_8, GeomAPI_Shape.VERTEX, [144 * COPIES]) +model.testResultsVolumes(MultiRotation_8, [3000 * COPIES]) +refPoint = AngularCopy_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_8.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v0_4.py b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v0_4.py new file mode 100644 index 000000000..fb3623c8f --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v0_4.py @@ -0,0 +1,208 @@ +# 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 GeomAlgoAPI 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 +COPIES = 4 + + +model.begin() +MultiRotation_1 = model.addMultiRotation(Part_1_doc, [model.selection("VERTEX", "Compound_1_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_1, 1) +model.testNbSubResults(MultiRotation_1, [COPIES]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.EDGE, [0]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.VERTEX, [COPIES]) +model.testResultsVolumes(MultiRotation_1, [0]) +refPoint = Vertex_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_1 = model.addRecover(Part_1_doc, MultiRotation_1, [Compound_1.result()], True) +MultiRotation_2 = model.addMultiRotation(Part_1_doc, [model.selection("EDGE", "Recover_1_1_2")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_2, 1) +model.testNbSubResults(MultiRotation_2, [COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.EDGE, [COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.VERTEX, [2 * COPIES]) +model.testResultsVolumes(MultiRotation_2, [0]) +comp = GeomAlgoAPI_CompoundBuilder.compound([Edge_1.defaultResult().shape()]) +refPoint = comp.middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_2 = model.addRecover(Part_1_doc, MultiRotation_2, [Recover_1.result()]) +MultiRotation_3 = model.addMultiRotation(Part_1_doc, [model.selection("WIRE", "Recover_2_1_3")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_3, 1) +model.testNbSubResults(MultiRotation_3, [COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.EDGE, [2 * COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.VERTEX, [4 * COPIES]) +model.testResultsVolumes(MultiRotation_3, [0]) +comp = GeomAlgoAPI_CompoundBuilder.compound([Wire_1.defaultResult().shape()]) +refPoint = comp.middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_3 = model.addRecover(Part_1_doc, MultiRotation_3, [Recover_2.result()]) +MultiRotation_4 = model.addMultiRotation(Part_1_doc, [model.selection("FACE", "Recover_3_1_4")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_4, 1) +model.testNbSubResults(MultiRotation_4, [COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.FACE, [COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.EDGE, [4 * COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.VERTEX, [8 * COPIES]) +model.testResultsVolumes(MultiRotation_4, [109.154152964914914 * COPIES]) +refPoint = Face_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_4.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_4 = model.addRecover(Part_1_doc, MultiRotation_4, [Recover_3.result()]) +MultiRotation_5 = model.addMultiRotation(Part_1_doc, [model.selection("SHELL", "Recover_4_1_5")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_5, 1) +model.testNbSubResults(MultiRotation_5, [COPIES]) +model.testNbSubShapes(MultiRotation_5, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_5, GeomAPI_Shape.FACE, [2 * COPIES]) +model.testNbSubShapes(MultiRotation_5, GeomAPI_Shape.EDGE, [8 * COPIES]) +model.testNbSubShapes(MultiRotation_5, GeomAPI_Shape.VERTEX, [16 * COPIES]) +model.testResultsVolumes(MultiRotation_5, [182.822012116 * COPIES]) +refPoint = Shell_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_5.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_5 = model.addRecover(Part_1_doc, MultiRotation_5, [Recover_4.result()]) +MultiRotation_6 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Recover_5_1_6")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_6, 1) +model.testNbSubResults(MultiRotation_6, [COPIES]) +model.testNbSubShapes(MultiRotation_6, GeomAPI_Shape.SOLID, [COPIES]) +model.testNbSubShapes(MultiRotation_6, GeomAPI_Shape.FACE, [6 * COPIES]) +model.testNbSubShapes(MultiRotation_6, GeomAPI_Shape.EDGE, [24 * COPIES]) +model.testNbSubShapes(MultiRotation_6, GeomAPI_Shape.VERTEX, [48 * COPIES]) +model.testResultsVolumes(MultiRotation_6, [1000 * COPIES]) +refPoint = Translation_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_6.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_6 = model.addRecover(Part_1_doc, MultiRotation_6, [Recover_5.result()]) +MultiRotation_7 = model.addMultiRotation(Part_1_doc, [model.selection("COMPSOLID", "Recover_6_1_7")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_7, 1) +model.testNbSubResults(MultiRotation_7, [COPIES]) +model.testNbSubShapes(MultiRotation_7, GeomAPI_Shape.SOLID, [3 * COPIES]) +model.testNbSubShapes(MultiRotation_7, GeomAPI_Shape.FACE, [17 * COPIES]) +model.testNbSubShapes(MultiRotation_7, GeomAPI_Shape.EDGE, [66 * COPIES]) +model.testNbSubShapes(MultiRotation_7, GeomAPI_Shape.VERTEX, [132 * COPIES]) +model.testResultsVolumes(MultiRotation_7, [1589.0486226 * COPIES]) +refPoint = Partition_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_7.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_7 = model.addRecover(Part_1_doc, MultiRotation_7, [Recover_6.result()]) +MultiRotation_8 = model.addMultiRotation(Part_1_doc, [model.selection("COMPOUND", "Recover_7_1_8")], model.selection("EDGE", "PartSet/OX"), COPIES) +model.testNbResults(MultiRotation_8, 1) +model.testNbSubResults(MultiRotation_8, [COPIES]) +model.testNbSubShapes(MultiRotation_8, GeomAPI_Shape.SOLID, [3 * COPIES]) +model.testNbSubShapes(MultiRotation_8, GeomAPI_Shape.FACE, [18 * COPIES]) +model.testNbSubShapes(MultiRotation_8, GeomAPI_Shape.EDGE, [72 * COPIES]) +model.testNbSubShapes(MultiRotation_8, GeomAPI_Shape.VERTEX, [144 * COPIES]) +model.testResultsVolumes(MultiRotation_8, [3000 * COPIES]) +refPoint = AngularCopy_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_8.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v95_1.py b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v95_1.py new file mode 100644 index 000000000..0b47113e4 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v95_1.py @@ -0,0 +1,118 @@ +# 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() + +ANGLE = 60 +COPIES = 3 +TOLERANCE = 1.e-7 + +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, theNbSolids, theNbFaces, theNbEdges, theNbVertices, theVolume): + model.testNbResults(theFeature, 1) + model.testNbSubResults(theFeature, [3]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.SOLID, [theNbSolids]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [theNbFaces]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [theNbEdges]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [theNbVertices]) + 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() +MultiRotation_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("EDGE", "PartSet/OZ"), ANGLE, COPIES, keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(MultiRotation_1.feature().error() != "") + +model.begin() +MultiRotation_1.setMainObjects([model.selection("COMPSOLID", "Compound_2_1_1")]) +REFERENCE[0] = GeomAPI_Pnt(26.21750044779, -12.5, 5) +assertResult(MultiRotation_1, 24, 123, 450, 900, 38247.599) + +MultiRotation_2 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "AngularCopy_1_1_2_1")], model.selection("EDGE", "PartSet/OZ"), ANGLE, COPIES, keepSubResults = True) +REFERENCE[1] = GeomAPI_Pnt(21.6506350946, 5.3316102, 5) +assertResult(MultiRotation_2, 26, 129, 462, 924, 39818.3954) + +MultiRotation_3 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "AngularCopy_2_1_3")], model.selection("EDGE", "PartSet/OZ"), ANGLE, COPIES, keepSubResults = True) +REFERENCE[2] = GeomAPI_Pnt(31.94572, -30.3316102, 5) +assertResult(MultiRotation_3, 28, 135, 474, 948, 41389.19175) + +MultiRotation_4 = model.addMultiRotation(Part_1_doc, [model.selection("COMPSOLID", "AngularCopy_3_1_1_1"), model.selection("SOLID", "AngularCopy_3_1_2_2"), model.selection("COMPOUND", "AngularCopy_3_1_3")], model.selection("EDGE", "PartSet/OZ"), -ANGLE, COPIES, keepSubResults = True) +REFERENCE[0] = GeomAPI_Pnt(0, -12.5, 5) +REFERENCE[1] = GeomAPI_Pnt(20.59016994, 5.3316102, 5) +REFERENCE[2] = GeomAPI_Pnt(0, -12.5, 5) +assertResult(MultiRotation_4, 50, 235, 810, 1620, 71599.98) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v95_2.py b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v95_2.py new file mode 100644 index 000000000..34d6b00f6 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v95_2.py @@ -0,0 +1,114 @@ +# 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() + +COPIES = 3 +TOLERANCE = 1.e-7 + +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, theNbSolids, theNbFaces, theNbEdges, theNbVertices, theVolume): + model.testNbResults(theFeature, 1) + model.testNbSubResults(theFeature, [3]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.SOLID, [theNbSolids]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [theNbFaces]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [theNbEdges]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [theNbVertices]) + 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() +MultiRotation_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("EDGE", "PartSet/OZ"), COPIES, keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(MultiRotation_1.feature().error() != "") + +model.begin() +MultiRotation_1.setMainObjects([model.selection("COMPSOLID", "Compound_2_1_1")]) +REFERENCE[0] = GeomAPI_Pnt(4.566865353, -12.5, 5) +assertResult(MultiRotation_1, 24, 123, 450, 900, 38247.599) + +MultiRotation_2 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "AngularCopy_1_1_2_1")], model.selection("EDGE", "PartSet/OZ"), COPIES, keepSubResults = True) +REFERENCE[1] = GeomAPI_Pnt(-11.35555012, 5.3316102, 5) +assertResult(MultiRotation_2, 26, 129, 462, 924, 39818.3954) + +MultiRotation_3 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "AngularCopy_2_1_3")], model.selection("EDGE", "PartSet/OZ"), COPIES, keepSubResults = True) +REFERENCE[2] = GeomAPI_Pnt(10.29508497, -12.5, 5) +assertResult(MultiRotation_3, 28, 135, 474, 948, 41389.19175) + +MultiRotation_4 = model.addMultiRotation(Part_1_doc, [model.selection("COMPSOLID", "AngularCopy_3_1_1_1"), model.selection("SOLID", "AngularCopy_3_1_2_2"), model.selection("COMPOUND", "AngularCopy_3_1_3")], model.selection("EDGE", "PartSet/OZ"), COPIES, keepSubResults = True) +assertResult(MultiRotation_4, 50, 235, 810, 1620, 71599.98) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v95_3.py b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v95_3.py new file mode 100644 index 000000000..f416272c7 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v95_3.py @@ -0,0 +1,199 @@ +# 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 GeomAlgoAPI 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 +COPIES = 4 + + +model.begin() +MultiRotation_1 = model.addMultiRotation(Part_1_doc, [model.selection("VERTEX", "Vertex_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +model.testNbResults(MultiRotation_1, 1) +model.testNbSubResults(MultiRotation_1, [COPIES]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.EDGE, [0]) +model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.VERTEX, [COPIES]) +model.testResultsVolumes(MultiRotation_1, [0]) +refPoint = Vertex_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_2 = model.addMultiRotation(Part_1_doc, [model.selection("EDGE", "Edge_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +model.testNbResults(MultiRotation_2, 1) +model.testNbSubResults(MultiRotation_2, [COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.EDGE, [COPIES]) +model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.VERTEX, [2 * COPIES]) +model.testResultsVolumes(MultiRotation_2, [0]) +comp = GeomAlgoAPI_CompoundBuilder.compound([Edge_1.defaultResult().shape()]) +refPoint = comp.middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_3 = model.addMultiRotation(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +model.testNbResults(MultiRotation_3, 1) +model.testNbSubResults(MultiRotation_3, [COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.EDGE, [2 * COPIES]) +model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.VERTEX, [4 * COPIES]) +model.testResultsVolumes(MultiRotation_3, [0]) +comp = GeomAlgoAPI_CompoundBuilder.compound([Wire_1.defaultResult().shape()]) +refPoint = comp.middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_4 = model.addMultiRotation(Part_1_doc, [model.selection("FACE", "Face_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +model.testNbResults(MultiRotation_4, 1) +model.testNbSubResults(MultiRotation_4, [COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.FACE, [COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.EDGE, [4 * COPIES]) +model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.VERTEX, [8 * COPIES]) +model.testResultsVolumes(MultiRotation_4, [109.154152964914914 * COPIES]) +refPoint = Face_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_4.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_5 = model.addMultiRotation(Part_1_doc, [model.selection("SHELL", "Shell_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +model.testNbResults(MultiRotation_5, 1) +model.testNbSubResults(MultiRotation_5, [COPIES]) +model.testNbSubShapes(MultiRotation_5, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiRotation_5, GeomAPI_Shape.FACE, [2 * COPIES]) +model.testNbSubShapes(MultiRotation_5, GeomAPI_Shape.EDGE, [8 * COPIES]) +model.testNbSubShapes(MultiRotation_5, GeomAPI_Shape.VERTEX, [16 * COPIES]) +model.testResultsVolumes(MultiRotation_5, [182.822012116 * COPIES]) +refPoint = Shell_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_5.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_6 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +model.testNbResults(MultiRotation_6, 1) +model.testNbSubResults(MultiRotation_6, [COPIES]) +model.testNbSubShapes(MultiRotation_6, GeomAPI_Shape.SOLID, [COPIES]) +model.testNbSubShapes(MultiRotation_6, GeomAPI_Shape.FACE, [6 * COPIES]) +model.testNbSubShapes(MultiRotation_6, GeomAPI_Shape.EDGE, [24 * COPIES]) +model.testNbSubShapes(MultiRotation_6, GeomAPI_Shape.VERTEX, [48 * COPIES]) +model.testResultsVolumes(MultiRotation_6, [1000 * COPIES]) +refPoint = Translation_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_6.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_7 = model.addMultiRotation(Part_1_doc, [model.selection("COMPSOLID", "Partition_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +model.testNbResults(MultiRotation_7, 1) +model.testNbSubResults(MultiRotation_7, [COPIES]) +model.testNbSubShapes(MultiRotation_7, GeomAPI_Shape.SOLID, [3 * COPIES]) +model.testNbSubShapes(MultiRotation_7, GeomAPI_Shape.FACE, [17 * COPIES]) +model.testNbSubShapes(MultiRotation_7, GeomAPI_Shape.EDGE, [66 * COPIES]) +model.testNbSubShapes(MultiRotation_7, GeomAPI_Shape.VERTEX, [132 * COPIES]) +model.testResultsVolumes(MultiRotation_7, [1589.0486226 * COPIES]) +refPoint = Partition_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_7.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiRotation_8 = model.addMultiRotation(Part_1_doc, [model.selection("COMPOUND", "AngularCopy_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +model.testNbResults(MultiRotation_8, 1) +model.testNbSubResults(MultiRotation_8, [COPIES]) +model.testNbSubShapes(MultiRotation_8, GeomAPI_Shape.SOLID, [3 * COPIES]) +model.testNbSubShapes(MultiRotation_8, GeomAPI_Shape.FACE, [18 * COPIES]) +model.testNbSubShapes(MultiRotation_8, GeomAPI_Shape.EDGE, [72 * COPIES]) +model.testNbSubShapes(MultiRotation_8, GeomAPI_Shape.VERTEX, [144 * COPIES]) +model.testResultsVolumes(MultiRotation_8, [3000 * COPIES]) +refPoint = AngularCopy_1.defaultResult().shape().middlePoint() +refPoint.setY(0) +refPoint.setZ(0) +midPoint = MultiRotation_8.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v95_4.py b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v95_4.py new file mode 100644 index 000000000..6f4691354 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiRotation_MultiLevelCompound_v95_4.py @@ -0,0 +1,169 @@ +# 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() + +TOLERANCE = 1.e-7 +COPIES = 4 + +NB_SOLIDS = 7 +NB_FACES = 44 +NB_EDGES = 177 +NB_VERTICES = 355 +VOLUME = 5589.0486226 + +# 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, [NB_SOLIDS]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [NB_FACES]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [NB_EDGES]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [NB_VERTICES]) + 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.setY(0) + ref.setZ(0) + 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() +MultiRotation_1 = model.addMultiRotation(Part_1_doc, [model.selection("VERTEX", "Compound_1_1_1")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +NB_VERTICES += COPIES - 1 +assertResult(MultiRotation_1, 1) + +MultiRotation_2 = model.addMultiRotation(Part_1_doc, [model.selection("EDGE", "AngularCopy_2_1_2")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +c = GeomAlgoAPI_CompoundBuilder.compound([Edge_1.defaultResult().shape()]) +REFERENCE[1] = c.middlePoint() +NB_EDGES += COPIES - 1 +NB_VERTICES += 2 * (COPIES - 1) +assertResult(MultiRotation_2, 2) + +MultiRotation_3 = model.addMultiRotation(Part_1_doc, [model.selection("WIRE", "AngularCopy_3_1_3")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +c = GeomAlgoAPI_CompoundBuilder.compound([Wire_1.defaultResult().shape()]) +REFERENCE[2] = c.middlePoint() +NB_EDGES += 2 * (COPIES - 1) +NB_VERTICES += 4 * (COPIES - 1) +assertResult(MultiRotation_3, 3) + +MultiRotation_4 = model.addMultiRotation(Part_1_doc, [model.selection("FACE", "AngularCopy_4_1_4")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +NB_FACES += COPIES - 1 +NB_EDGES += 4 * (COPIES - 1) +NB_VERTICES += 8 * (COPIES - 1) +assertResult(MultiRotation_4, 4) + +MultiRotation_5 = model.addMultiRotation(Part_1_doc, [model.selection("SHELL", "AngularCopy_5_1_5")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +NB_FACES += 2 * (COPIES - 1) +NB_EDGES += 8 * (COPIES - 1) +NB_VERTICES += 16 * (COPIES - 1) +assertResult(MultiRotation_5, 5) + +MultiRotation_6 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "AngularCopy_6_1_6")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +NB_SOLIDS += COPIES - 1 +NB_FACES += 6 * (COPIES - 1) +NB_EDGES += 24 * (COPIES - 1) +NB_VERTICES += 48 * (COPIES - 1) +VOLUME += 1000 * (COPIES - 1) +assertResult(MultiRotation_6, 6) + +MultiRotation_7 = model.addMultiRotation(Part_1_doc, [model.selection("COMPSOLID", "AngularCopy_7_1_7")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +NB_SOLIDS += 3 * (COPIES - 1) +NB_FACES += 17 * (COPIES - 1) +NB_EDGES += 66 * (COPIES - 1) +NB_VERTICES += 132 * (COPIES - 1) +VOLUME += 1589.0486226 * (COPIES - 1) +assertResult(MultiRotation_7, 7) + +MultiRotation_8 = model.addMultiRotation(Part_1_doc, [model.selection("COMPOUND", "AngularCopy_8_1_8")], model.selection("EDGE", "PartSet/OX"), COPIES, keepSubResults = True) +NB_SOLIDS += 3 * (COPIES - 1) +NB_FACES += 18 * (COPIES - 1) +NB_EDGES += 72 * (COPIES - 1) +NB_VERTICES += 144 * (COPIES - 1) +VOLUME += 3000 * (COPIES - 1) +assertResult(MultiRotation_8, 8) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v0_1.py b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v0_1.py new file mode 100644 index 000000000..08b4fcd5d --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v0_1.py @@ -0,0 +1,140 @@ +# 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 GeomAlgoAPI 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() + +DISTANCE = 20 +COPIES = 3 +TOLERANCE = 1.e-7 + + +model.begin() +MultiTranslation_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_1, 1) +model.testNbSubResults(MultiTranslation_1, [COPIES]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.SOLID, [1 * COPIES]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.FACE, [5 * COPIES]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.EDGE, [18 * COPIES]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.VERTEX, [36 * COPIES]) +model.testResultsVolumes(MultiTranslation_1, [542.746463956 * COPIES]) + +comp = GeomAlgoAPI_CompoundBuilder.compound([Extrusion_1.results()[0].subResult(4).resultSubShapePair()[0].shape()]) +refPoint = comp.middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_1 = model.addRecover(Part_1_doc, MultiTranslation_1, [Compound_2.result()], True) +MultiTranslation_2 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Recover_1_1_2_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_2, 1) +model.testNbSubResults(MultiTranslation_2, [COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.SOLID, [1 * COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.FACE, [3 * COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.EDGE, [6 * COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.VERTEX, [12 * COPIES]) +model.testResultsVolumes(MultiTranslation_2, [785.39816339745 * COPIES]) + +refPoint = Recover_1.result().subResult(1).subResult(0).resultSubShapePair()[0].shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_2 = model.addRecover(Part_1_doc, MultiTranslation_2, [Recover_1.result()], True) +MultiTranslation_3 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Recover_2_1_3")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_3, 1) +model.testNbSubResults(MultiTranslation_3, [COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.SOLID, [1 * COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.FACE, [3 * COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.EDGE, [6 * COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.VERTEX, [12 * COPIES]) +model.testResultsVolumes(MultiTranslation_3, [785.39816339745 * COPIES]) + +refPoint = Recover_2.result().subResult(2).resultSubShapePair()[0].shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_3 = model.addRecover(Part_1_doc, MultiTranslation_3, [Recover_2.result()], True) +MultiTranslation_4 = model.addMultiTranslation(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("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_4, 3) +model.testNbSubResults(MultiTranslation_4, [COPIES, COPIES, COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.SOLID, [1 * COPIES, 1 * COPIES, 1 * COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.FACE, [6 * COPIES, 3 * COPIES, 3 * COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.EDGE, [24 * COPIES, 6 * COPIES, 6 * COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.VERTEX, [48 * COPIES, 12 * COPIES, 12 * COPIES]) +model.testResultsVolumes(MultiTranslation_4, [3444.394198615 * COPIES, 785.39816339745 * COPIES, 785.39816339745 * COPIES]) + +comp = GeomAlgoAPI_CompoundBuilder.compound([Recover_3.result().subResult(0).subResult(0).resultSubShapePair()[0].shape()]) +REFERENCE = [comp.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(MultiTranslation_4.results(), REFERENCE): + ref.setZ(ref.z() + DISTANCE / 2 * (COPIES - 1)) + midPoint = res.resultSubShapePair()[0].shape().middlePoint() + assert(midPoint.distance(ref) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v0_2.py b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v0_2.py new file mode 100644 index 000000000..90180fd76 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v0_2.py @@ -0,0 +1,146 @@ +# 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 GeomAlgoAPI 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() + +TOLERANCE = 1.e-7 +DISTANCE_1 = 20 +COPIES_1 = 3 +DISTANCE_2 = 100 +COPIES_2 = 2 +COPIES = COPIES_1 * COPIES_2 + +model.begin() +MultiTranslation_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("EDGE", "PartSet/OZ"), DISTANCE_1, COPIES_1, model.selection("EDGE", "PartSet/OY"), DISTANCE_2, COPIES_2) +model.testNbResults(MultiTranslation_1, 1) +model.testNbSubResults(MultiTranslation_1, [COPIES]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.SOLID, [1 * COPIES]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.FACE, [5 * COPIES]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.EDGE, [18 * COPIES]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.VERTEX, [36 * COPIES]) +model.testResultsVolumes(MultiTranslation_1, [542.746463956 * COPIES]) + +comp = GeomAlgoAPI_CompoundBuilder.compound([Extrusion_1.results()[0].subResult(4).resultSubShapePair()[0].shape()]) +refPoint = comp.middlePoint() +refPoint.setY(refPoint.y() + DISTANCE_2 / 2 * (COPIES_2 - 1)) +refPoint.setZ(refPoint.z() + DISTANCE_1 / 2 * (COPIES_1 - 1)) +midPoint = MultiTranslation_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_1 = model.addRecover(Part_1_doc, MultiTranslation_1, [Compound_2.result()], True) +MultiTranslation_2 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Recover_1_1_2_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE_1, COPIES_1, model.selection("EDGE", "PartSet/OY"), DISTANCE_2, COPIES_2) +model.testNbResults(MultiTranslation_2, 1) +model.testNbSubResults(MultiTranslation_2, [COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.SOLID, [1 * COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.FACE, [3 * COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.EDGE, [6 * COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.VERTEX, [12 * COPIES]) +model.testResultsVolumes(MultiTranslation_2, [785.39816339745 * COPIES]) + +refPoint = Recover_1.result().subResult(1).subResult(0).resultSubShapePair()[0].shape().middlePoint() +refPoint.setY(refPoint.y() + DISTANCE_2 / 2 * (COPIES_2 - 1)) +refPoint.setZ(refPoint.z() + DISTANCE_1 / 2 * (COPIES_1 - 1)) +midPoint = MultiTranslation_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_2 = model.addRecover(Part_1_doc, MultiTranslation_2, [Recover_1.result()], True) +MultiTranslation_3 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Recover_2_1_3")], model.selection("EDGE", "PartSet/OZ"), DISTANCE_1, COPIES_1, model.selection("EDGE", "PartSet/OY"), DISTANCE_2, COPIES_2) +model.testNbResults(MultiTranslation_3, 1) +model.testNbSubResults(MultiTranslation_3, [COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.SOLID, [1 * COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.FACE, [3 * COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.EDGE, [6 * COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.VERTEX, [12 * COPIES]) +model.testResultsVolumes(MultiTranslation_3, [785.39816339745 * COPIES]) + +refPoint = Recover_2.result().subResult(2).resultSubShapePair()[0].shape().middlePoint() +refPoint.setY(refPoint.y() + DISTANCE_2 / 2 * (COPIES_2 - 1)) +refPoint.setZ(refPoint.z() + DISTANCE_1 / 2 * (COPIES_1 - 1)) +midPoint = MultiTranslation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_3 = model.addRecover(Part_1_doc, MultiTranslation_3, [Recover_2.result()], True) +MultiTranslation_4 = model.addMultiTranslation(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("EDGE", "PartSet/OZ"), DISTANCE_1, COPIES_1, model.selection("EDGE", "PartSet/OY"), DISTANCE_2, COPIES_2) +model.testNbResults(MultiTranslation_4, 3) +model.testNbSubResults(MultiTranslation_4, [COPIES, COPIES, COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.SOLID, [1 * COPIES, 1 * COPIES, 1 * COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.FACE, [6 * COPIES, 3 * COPIES, 3 * COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.EDGE, [24 * COPIES, 6 * COPIES, 6 * COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.VERTEX, [48 * COPIES, 12 * COPIES, 12 * COPIES]) +model.testResultsVolumes(MultiTranslation_4, [3444.394198615 * COPIES, 785.39816339745 * COPIES, 785.39816339745 * COPIES]) + +comp = GeomAlgoAPI_CompoundBuilder.compound([Recover_3.result().subResult(0).subResult(0).resultSubShapePair()[0].shape()]) +REFERENCE = [comp.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(MultiTranslation_4.results(), REFERENCE): + ref.setY(ref.y() + DISTANCE_2 / 2 * (COPIES_2 - 1)) + ref.setZ(ref.z() + DISTANCE_1 / 2 * (COPIES_1 - 1)) + midPoint = res.resultSubShapePair()[0].shape().middlePoint() + assert(midPoint.distance(ref) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v0_3.py b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v0_3.py new file mode 100644 index 000000000..199af9d66 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v0_3.py @@ -0,0 +1,192 @@ +# 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 GeomAlgoAPI 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 +DISTANCE = 20 +COPIES = 2 + + +model.begin() +MultiTranslation_1 = model.addMultiTranslation(Part_1_doc, [model.selection("VERTEX", "Vertex_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_1, 1) +model.testNbSubResults(MultiTranslation_1, [COPIES]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.EDGE, [0]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.VERTEX, [COPIES]) +model.testResultsVolumes(MultiTranslation_1, [0]) +refPoint = Vertex_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_2 = model.addMultiTranslation(Part_1_doc, [model.selection("EDGE", "Edge_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_2, 1) +model.testNbSubResults(MultiTranslation_2, [COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.EDGE, [COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.VERTEX, [2 * COPIES]) +model.testResultsVolumes(MultiTranslation_2, [0]) +comp = GeomAlgoAPI_CompoundBuilder.compound([Edge_1.defaultResult().shape()]) +refPoint = comp.middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_3 = model.addMultiTranslation(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_3, 1) +model.testNbSubResults(MultiTranslation_3, [COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.EDGE, [2 * COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.VERTEX, [4 * COPIES]) +model.testResultsVolumes(MultiTranslation_3, [0]) +comp = GeomAlgoAPI_CompoundBuilder.compound([Wire_1.defaultResult().shape()]) +refPoint = comp.middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_4 = model.addMultiTranslation(Part_1_doc, [model.selection("FACE", "Face_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_4, 1) +model.testNbSubResults(MultiTranslation_4, [COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.FACE, [COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.EDGE, [4 * COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.VERTEX, [8 * COPIES]) +model.testResultsVolumes(MultiTranslation_4, [109.154152964914914 * COPIES]) +refPoint = Face_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_4.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_5 = model.addMultiTranslation(Part_1_doc, [model.selection("SHELL", "Shell_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_5, 1) +model.testNbSubResults(MultiTranslation_5, [COPIES]) +model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.FACE, [2 * COPIES]) +model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.EDGE, [8 * COPIES]) +model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.VERTEX, [16 * COPIES]) +model.testResultsVolumes(MultiTranslation_5, [182.822012116 * COPIES]) +refPoint = Shell_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_5.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_6 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_6, 1) +model.testNbSubResults(MultiTranslation_6, [COPIES]) +model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.SOLID, [COPIES]) +model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.FACE, [6 * COPIES]) +model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.EDGE, [24 * COPIES]) +model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.VERTEX, [48 * COPIES]) +model.testResultsVolumes(MultiTranslation_6, [1000 * COPIES]) +refPoint = Translation_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_6.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_7 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_7, 1) +model.testNbSubResults(MultiTranslation_7, [COPIES]) +model.testNbSubShapes(MultiTranslation_7, GeomAPI_Shape.SOLID, [3 * COPIES]) +model.testNbSubShapes(MultiTranslation_7, GeomAPI_Shape.FACE, [17 * COPIES]) +model.testNbSubShapes(MultiTranslation_7, GeomAPI_Shape.EDGE, [66 * COPIES]) +model.testNbSubShapes(MultiTranslation_7, GeomAPI_Shape.VERTEX, [132 * COPIES]) +model.testResultsVolumes(MultiTranslation_7, [1589.0486226 * COPIES]) +refPoint = Partition_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_7.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_8 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPOUND", "AngularCopy_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_8, 1) +model.testNbSubResults(MultiTranslation_8, [COPIES]) +model.testNbSubShapes(MultiTranslation_8, GeomAPI_Shape.SOLID, [3 * COPIES]) +model.testNbSubShapes(MultiTranslation_8, GeomAPI_Shape.FACE, [18 * COPIES]) +model.testNbSubShapes(MultiTranslation_8, GeomAPI_Shape.EDGE, [72 * COPIES]) +model.testNbSubShapes(MultiTranslation_8, GeomAPI_Shape.VERTEX, [144 * COPIES]) +model.testResultsVolumes(MultiTranslation_8, [3000 * COPIES]) +refPoint = AngularCopy_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_8.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v0_4.py b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v0_4.py new file mode 100644 index 000000000..2c627b964 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v0_4.py @@ -0,0 +1,201 @@ +# 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 GeomAlgoAPI 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 +DISTANCE = 20 +COPIES = 2 + + +model.begin() +MultiTranslation_1 = model.addMultiTranslation(Part_1_doc, [model.selection("VERTEX", "Compound_1_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_1, 1) +model.testNbSubResults(MultiTranslation_1, [COPIES]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.EDGE, [0]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.VERTEX, [COPIES]) +model.testResultsVolumes(MultiTranslation_1, [0]) +refPoint = Vertex_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_1 = model.addRecover(Part_1_doc, MultiTranslation_1, [Compound_1.result()], True) +MultiTranslation_2 = model.addMultiTranslation(Part_1_doc, [model.selection("EDGE", "Recover_1_1_2")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_2, 1) +model.testNbSubResults(MultiTranslation_2, [COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.EDGE, [COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.VERTEX, [2 * COPIES]) +model.testResultsVolumes(MultiTranslation_2, [0]) +comp = GeomAlgoAPI_CompoundBuilder.compound([Edge_1.defaultResult().shape()]) +refPoint = comp.middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_2 = model.addRecover(Part_1_doc, MultiTranslation_2, [Recover_1.result()]) +MultiTranslation_3 = model.addMultiTranslation(Part_1_doc, [model.selection("WIRE", "Recover_2_1_3")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_3, 1) +model.testNbSubResults(MultiTranslation_3, [COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.EDGE, [2 * COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.VERTEX, [4 * COPIES]) +model.testResultsVolumes(MultiTranslation_3, [0]) +comp = GeomAlgoAPI_CompoundBuilder.compound([Wire_1.defaultResult().shape()]) +refPoint = comp.middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_3 = model.addRecover(Part_1_doc, MultiTranslation_3, [Recover_2.result()]) +MultiTranslation_4 = model.addMultiTranslation(Part_1_doc, [model.selection("FACE", "Recover_3_1_4")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_4, 1) +model.testNbSubResults(MultiTranslation_4, [COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.FACE, [COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.EDGE, [4 * COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.VERTEX, [8 * COPIES]) +model.testResultsVolumes(MultiTranslation_4, [109.154152964914914 * COPIES]) +refPoint = Face_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_4.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_4 = model.addRecover(Part_1_doc, MultiTranslation_4, [Recover_3.result()]) +MultiTranslation_5 = model.addMultiTranslation(Part_1_doc, [model.selection("SHELL", "Recover_4_1_5")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_5, 1) +model.testNbSubResults(MultiTranslation_5, [COPIES]) +model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.FACE, [2 * COPIES]) +model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.EDGE, [8 * COPIES]) +model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.VERTEX, [16 * COPIES]) +model.testResultsVolumes(MultiTranslation_5, [182.822012116 * COPIES]) +refPoint = Shell_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_5.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_5 = model.addRecover(Part_1_doc, MultiTranslation_5, [Recover_4.result()]) +MultiTranslation_6 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Recover_5_1_6")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_6, 1) +model.testNbSubResults(MultiTranslation_6, [COPIES]) +model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.SOLID, [COPIES]) +model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.FACE, [6 * COPIES]) +model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.EDGE, [24 * COPIES]) +model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.VERTEX, [48 * COPIES]) +model.testResultsVolumes(MultiTranslation_6, [1000 * COPIES]) +refPoint = Translation_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_6.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_6 = model.addRecover(Part_1_doc, MultiTranslation_6, [Recover_5.result()]) +MultiTranslation_7 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPSOLID", "Recover_6_1_7")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_7, 1) +model.testNbSubResults(MultiTranslation_7, [COPIES]) +model.testNbSubShapes(MultiTranslation_7, GeomAPI_Shape.SOLID, [3 * COPIES]) +model.testNbSubShapes(MultiTranslation_7, GeomAPI_Shape.FACE, [17 * COPIES]) +model.testNbSubShapes(MultiTranslation_7, GeomAPI_Shape.EDGE, [66 * COPIES]) +model.testNbSubShapes(MultiTranslation_7, GeomAPI_Shape.VERTEX, [132 * COPIES]) +model.testResultsVolumes(MultiTranslation_7, [1589.0486226 * COPIES]) +refPoint = Partition_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_7.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Recover_7 = model.addRecover(Part_1_doc, MultiTranslation_7, [Recover_6.result()]) +MultiTranslation_8 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPOUND", "Recover_7_1_8")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES) +model.testNbResults(MultiTranslation_8, 1) +model.testNbSubResults(MultiTranslation_8, [COPIES]) +model.testNbSubShapes(MultiTranslation_8, GeomAPI_Shape.SOLID, [3 * COPIES]) +model.testNbSubShapes(MultiTranslation_8, GeomAPI_Shape.FACE, [18 * COPIES]) +model.testNbSubShapes(MultiTranslation_8, GeomAPI_Shape.EDGE, [72 * COPIES]) +model.testNbSubShapes(MultiTranslation_8, GeomAPI_Shape.VERTEX, [144 * COPIES]) +model.testResultsVolumes(MultiTranslation_8, [3000 * COPIES]) +refPoint = AngularCopy_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_8.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v95_1.py b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v95_1.py new file mode 100644 index 000000000..f2a808b66 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v95_1.py @@ -0,0 +1,118 @@ +# 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() + +DISTANCE = 50 +COPIES = 3 +TOLERANCE = 1.e-7 + +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, theNbSolids, theNbFaces, theNbEdges, theNbVertices, theVolume): + model.testNbResults(theFeature, 1) + model.testNbSubResults(theFeature, [3]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.SOLID, [theNbSolids]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [theNbFaces]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [theNbEdges]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [theNbVertices]) + 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() +MultiTranslation_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(MultiTranslation_1.feature().error() != "") + +model.begin() +MultiTranslation_1.setMainObjects([model.selection("COMPSOLID", "Compound_2_1_1")]) +REFERENCE[0].setZ(REFERENCE[0].z() + DISTANCE / 2 * (COPIES - 1)) +assertResult(MultiTranslation_1, 24, 123, 450, 900, 38247.599) + +MultiTranslation_2 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "LinearCopy_1_1_2_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +REFERENCE[1].setZ(REFERENCE[1].z() + DISTANCE / 2 * (COPIES - 1)) +assertResult(MultiTranslation_2, 26, 129, 462, 924, 39818.3954) + +MultiTranslation_3 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "LinearCopy_2_1_3")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +REFERENCE[2].setZ(REFERENCE[2].z() + DISTANCE / 2 * (COPIES - 1)) +assertResult(MultiTranslation_3, 28, 135, 474, 948, 41389.19175) + +MultiTranslation_4 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPSOLID", "LinearCopy_3_1_1_1"), model.selection("SOLID", "LinearCopy_3_1_2_2"), model.selection("COMPOUND", "LinearCopy_3_1_3")], model.selection("EDGE", "PartSet/OY"), DISTANCE, COPIES, keepSubResults = True) +REFERENCE[0].setY(REFERENCE[0].y() + DISTANCE / 2 * (COPIES - 1)) +REFERENCE[1].setY(REFERENCE[1].y() + DISTANCE / 2 * (COPIES - 1)) +REFERENCE[2].setY(REFERENCE[2].y() + DISTANCE / 2 * (COPIES - 1)) +assertResult(MultiTranslation_4, 50, 235, 810, 1620, 71599.98) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v95_2.py b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v95_2.py new file mode 100644 index 000000000..42a6853ef --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v95_2.py @@ -0,0 +1,129 @@ +# 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() + +TOLERANCE = 1.e-7 +DISTANCE_1 = 100 +COPIES_1 = 2 +DISTANCE_2 = 50 +COPIES_2 = 3 +COPIES = COPIES_1 * COPIES_2 + + +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, theNbSolids, theNbFaces, theNbEdges, theNbVertices, theVolume): + model.testNbResults(theFeature, 1) + model.testNbSubResults(theFeature, [3]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.SOLID, [theNbSolids]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [theNbFaces]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [theNbEdges]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [theNbVertices]) + 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() +MultiTranslation_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("EDGE", "PartSet/OY"), DISTANCE_1, COPIES_1, model.selection("EDGE", "PartSet/OZ"), DISTANCE_2, COPIES_2, keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(MultiTranslation_1.feature().error() != "") + +model.begin() +MultiTranslation_1.setMainObjects([model.selection("COMPSOLID", "Compound_2_1_1")]) +REFERENCE[0].setY(REFERENCE[0].y() + DISTANCE_1 / 2 * (COPIES_1 - 1)) +REFERENCE[0].setZ(REFERENCE[0].z() + DISTANCE_2 / 2 * (COPIES_2 - 1)) +assertResult(MultiTranslation_1, 45, 237, 882, 1764, 74139.0037) + +MultiTranslation_2 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "LinearCopy_1_1_2_1")], model.selection("EDGE", "PartSet/OY"), DISTANCE_1, COPIES_1, model.selection("EDGE", "PartSet/OZ"), DISTANCE_2, COPIES_2, keepSubResults = True) +ref1Ycopy = REFERENCE[1].y() +REFERENCE[1].setY(0) +REFERENCE[1].setZ(REFERENCE[1].z() + DISTANCE_2 / 2 * (COPIES_2 - 1)) +assertResult(MultiTranslation_2, 50, 252, 912, 1824, 78065.9945) + +MultiTranslation_3 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "LinearCopy_2_1_3")], model.selection("EDGE", "PartSet/OY"), DISTANCE_1, COPIES_1, model.selection("EDGE", "PartSet/OZ"), DISTANCE_2, COPIES_2, keepSubResults = True) +REFERENCE[2].setY(REFERENCE[2].y() + DISTANCE_1 / 2 * (COPIES_1 - 1)) +REFERENCE[2].setZ(REFERENCE[2].z() + DISTANCE_2 / 2 * (COPIES_2 - 1)) +assertResult(MultiTranslation_3, 55, 267, 942, 1884, 81992.9853) + +MultiTranslation_4 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPSOLID", "LinearCopy_3_1_1_5"), model.selection("SOLID", "LinearCopy_3_1_2_2"), model.selection("COMPOUND", "LinearCopy_3_1_3")], model.selection("EDGE", "PartSet/OX"), -DISTANCE_2, COPIES_2, model.selection("EDGE", "PartSet/OY"), -DISTANCE_1, COPIES_1, keepSubResults = True) +REFERENCE[0].setX(REFERENCE[0].x() - DISTANCE_2 / 2 * (COPIES_2 - 1)) +REFERENCE[0].setY(REFERENCE[0].y() - DISTANCE_1 / 2 * (COPIES_1 - 1)) +REFERENCE[1].setX(REFERENCE[1].x() - DISTANCE_2 / 2 * (COPIES_2 - 1)) +REFERENCE[1].setY(ref1Ycopy) +REFERENCE[2].setX(REFERENCE[2].x() - DISTANCE_2 / 2 * (COPIES_2 - 1)) +REFERENCE[2].setY(REFERENCE[2].y() - DISTANCE_1 / 2 * (COPIES_1 - 1)) +assertResult(MultiTranslation_4, 125, 562, 1872, 3744, 169300.9287) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v95_3.py b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v95_3.py new file mode 100644 index 000000000..4b851506b --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v95_3.py @@ -0,0 +1,192 @@ +# 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 GeomAlgoAPI 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 +DISTANCE = 20 +COPIES = 2 + + +model.begin() +MultiTranslation_1 = model.addMultiTranslation(Part_1_doc, [model.selection("VERTEX", "Vertex_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +model.testNbResults(MultiTranslation_1, 1) +model.testNbSubResults(MultiTranslation_1, [COPIES]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.EDGE, [0]) +model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.VERTEX, [COPIES]) +model.testResultsVolumes(MultiTranslation_1, [0]) +refPoint = Vertex_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_2 = model.addMultiTranslation(Part_1_doc, [model.selection("EDGE", "Edge_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +model.testNbResults(MultiTranslation_2, 1) +model.testNbSubResults(MultiTranslation_2, [COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.EDGE, [COPIES]) +model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.VERTEX, [2 * COPIES]) +model.testResultsVolumes(MultiTranslation_2, [0]) +comp = GeomAlgoAPI_CompoundBuilder.compound([Edge_1.defaultResult().shape()]) +refPoint = comp.middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_3 = model.addMultiTranslation(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +model.testNbResults(MultiTranslation_3, 1) +model.testNbSubResults(MultiTranslation_3, [COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.EDGE, [2 * COPIES]) +model.testNbSubShapes(MultiTranslation_3, GeomAPI_Shape.VERTEX, [4 * COPIES]) +model.testResultsVolumes(MultiTranslation_3, [0]) +comp = GeomAlgoAPI_CompoundBuilder.compound([Wire_1.defaultResult().shape()]) +refPoint = comp.middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_4 = model.addMultiTranslation(Part_1_doc, [model.selection("FACE", "Face_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +model.testNbResults(MultiTranslation_4, 1) +model.testNbSubResults(MultiTranslation_4, [COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.FACE, [COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.EDGE, [4 * COPIES]) +model.testNbSubShapes(MultiTranslation_4, GeomAPI_Shape.VERTEX, [8 * COPIES]) +model.testResultsVolumes(MultiTranslation_4, [109.154152964914914 * COPIES]) +refPoint = Face_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_4.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_5 = model.addMultiTranslation(Part_1_doc, [model.selection("SHELL", "Shell_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +model.testNbResults(MultiTranslation_5, 1) +model.testNbSubResults(MultiTranslation_5, [COPIES]) +model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.FACE, [2 * COPIES]) +model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.EDGE, [8 * COPIES]) +model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.VERTEX, [16 * COPIES]) +model.testResultsVolumes(MultiTranslation_5, [182.822012116 * COPIES]) +refPoint = Shell_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_5.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_6 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +model.testNbResults(MultiTranslation_6, 1) +model.testNbSubResults(MultiTranslation_6, [COPIES]) +model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.SOLID, [COPIES]) +model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.FACE, [6 * COPIES]) +model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.EDGE, [24 * COPIES]) +model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.VERTEX, [48 * COPIES]) +model.testResultsVolumes(MultiTranslation_6, [1000 * COPIES]) +refPoint = Translation_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_6.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_7 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +model.testNbResults(MultiTranslation_7, 1) +model.testNbSubResults(MultiTranslation_7, [COPIES]) +model.testNbSubShapes(MultiTranslation_7, GeomAPI_Shape.SOLID, [3 * COPIES]) +model.testNbSubShapes(MultiTranslation_7, GeomAPI_Shape.FACE, [17 * COPIES]) +model.testNbSubShapes(MultiTranslation_7, GeomAPI_Shape.EDGE, [66 * COPIES]) +model.testNbSubShapes(MultiTranslation_7, GeomAPI_Shape.VERTEX, [132 * COPIES]) +model.testResultsVolumes(MultiTranslation_7, [1589.0486226 * COPIES]) +refPoint = Partition_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_7.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +MultiTranslation_8 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPOUND", "AngularCopy_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +model.testNbResults(MultiTranslation_8, 1) +model.testNbSubResults(MultiTranslation_8, [COPIES]) +model.testNbSubShapes(MultiTranslation_8, GeomAPI_Shape.SOLID, [3 * COPIES]) +model.testNbSubShapes(MultiTranslation_8, GeomAPI_Shape.FACE, [18 * COPIES]) +model.testNbSubShapes(MultiTranslation_8, GeomAPI_Shape.EDGE, [72 * COPIES]) +model.testNbSubShapes(MultiTranslation_8, GeomAPI_Shape.VERTEX, [144 * COPIES]) +model.testResultsVolumes(MultiTranslation_8, [3000 * COPIES]) +refPoint = AngularCopy_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE / 2 * (COPIES - 1)) +midPoint = MultiTranslation_8.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v95_4.py b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v95_4.py new file mode 100644 index 000000000..4c87612e6 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMultiTranslation_MultiLevelCompound_v95_4.py @@ -0,0 +1,169 @@ +# 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() + +TOLERANCE = 1.e-7 +DISTANCE = 20 +COPIES = 2 + +NB_SOLIDS = 7 +NB_FACES = 44 +NB_EDGES = 177 +NB_VERTICES = 355 +VOLUME = 5589.0486226 + +# 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, [NB_SOLIDS]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [NB_FACES]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [NB_EDGES]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [NB_VERTICES]) + 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.setZ(ref.z() + DISTANCE / 2 * (COPIES - 1)) + 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() +MultiTranslation_1 = model.addMultiTranslation(Part_1_doc, [model.selection("VERTEX", "Compound_1_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +NB_VERTICES += COPIES - 1 +assertResult(MultiTranslation_1, 1) + +MultiTranslation_2 = model.addMultiTranslation(Part_1_doc, [model.selection("EDGE", "LinearCopy_1_1_2")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +c = GeomAlgoAPI_CompoundBuilder.compound([Edge_1.defaultResult().shape()]) +REFERENCE[1] = c.middlePoint() +NB_EDGES += COPIES - 1 +NB_VERTICES += 2 * (COPIES - 1) +assertResult(MultiTranslation_2, 2) + +MultiTranslation_3 = model.addMultiTranslation(Part_1_doc, [model.selection("WIRE", "LinearCopy_2_1_3")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +c = GeomAlgoAPI_CompoundBuilder.compound([Wire_1.defaultResult().shape()]) +REFERENCE[2] = c.middlePoint() +NB_EDGES += 2 * (COPIES - 1) +NB_VERTICES += 4 * (COPIES - 1) +assertResult(MultiTranslation_3, 3) + +MultiTranslation_4 = model.addMultiTranslation(Part_1_doc, [model.selection("FACE", "LinearCopy_3_1_4")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +NB_FACES += COPIES - 1 +NB_EDGES += 4 * (COPIES - 1) +NB_VERTICES += 8 * (COPIES - 1) +assertResult(MultiTranslation_4, 4) + +MultiTranslation_5 = model.addMultiTranslation(Part_1_doc, [model.selection("SHELL", "LinearCopy_4_1_5")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +NB_FACES += 2 * (COPIES - 1) +NB_EDGES += 8 * (COPIES - 1) +NB_VERTICES += 16 * (COPIES - 1) +assertResult(MultiTranslation_5, 5) + +MultiTranslation_6 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "LinearCopy_5_1_6")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +NB_SOLIDS += COPIES - 1 +NB_FACES += 6 * (COPIES - 1) +NB_EDGES += 24 * (COPIES - 1) +NB_VERTICES += 48 * (COPIES - 1) +VOLUME += 1000 * (COPIES - 1) +assertResult(MultiTranslation_6, 6) + +MultiTranslation_7 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPSOLID", "LinearCopy_6_1_7")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +NB_SOLIDS += 3 * (COPIES - 1) +NB_FACES += 17 * (COPIES - 1) +NB_EDGES += 66 * (COPIES - 1) +NB_VERTICES += 132 * (COPIES - 1) +VOLUME += 1589.0486226 * (COPIES - 1) +assertResult(MultiTranslation_7, 7) + +MultiTranslation_8 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPOUND", "LinearCopy_7_1_8")], model.selection("EDGE", "PartSet/OZ"), DISTANCE, COPIES, keepSubResults = True) +NB_SOLIDS += 3 * (COPIES - 1) +NB_FACES += 18 * (COPIES - 1) +NB_EDGES += 72 * (COPIES - 1) +NB_VERTICES += 144 * (COPIES - 1) +VOLUME += 3000 * (COPIES - 1) +assertResult(MultiTranslation_8, 8) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp b/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp index ce706bb9a..7594a8e8a 100644 --- a/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp +++ b/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp @@ -131,15 +131,18 @@ namespace ModelGeomAlgo_Shape aSR.mySubshape = theSubshape; aSR.myCenterType = theCenterType; // compound subshapes from other compounds should be processed as whole results - if (aSR.mySubshape && aSR.mySubshape->shapeType() == GeomAPI_Shape::COMPOUND && - !theResult->shape()->isEqual(theSubshape)) { - ResultBodyPtr aResult = std::dynamic_pointer_cast(theResult); - for (int i = 0; aResult && i < aResult->numberOfSubs(); ++i) { - ResultBodyPtr aSub = aResult->subResult(i); - if (aSub->shape()->isEqual(theSubshape)) { - aSR.myResult = aSub; - aSR.mySubshape = GeomShapePtr(); - break; + if (aSR.mySubshape && aSR.mySubshape->shapeType() <= GeomAPI_Shape::COMPSOLID) { + if (theResult->shape()->isEqual(theSubshape)) + aSR.mySubshape = GeomShapePtr(); + else { + ResultBodyPtr aResult = std::dynamic_pointer_cast(theResult); + for (int i = 0; aResult && i < aResult->numberOfSubs(); ++i) { + ResultBodyPtr aSub = aResult->subResult(i); + if (aSub->shape()->isEqual(theSubshape)) { + aSR.myResult = aSub; + aSR.mySubshape = GeomShapePtr(); + break; + } } } } diff --git a/src/ModelHighAPI/ModelHighAPI_Double.cpp b/src/ModelHighAPI/ModelHighAPI_Double.cpp index 33c52647d..0f0078a3a 100644 --- a/src/ModelHighAPI/ModelHighAPI_Double.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Double.cpp @@ -21,6 +21,8 @@ #include #include + +#include //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- @@ -52,6 +54,16 @@ double ModelHighAPI_Double::value() const return myDouble; } +std::string ModelHighAPI_Double::string() const +{ + if (myVariantType == VT_STRING) + return myString; + + std::ostringstream anOut; + anOut << myDouble; + return anOut.str(); +} + //-------------------------------------------------------------------------------------- void ModelHighAPI_Double::fillAttribute( const std::shared_ptr & theAttribute) const diff --git a/src/ModelHighAPI/ModelHighAPI_Double.h b/src/ModelHighAPI/ModelHighAPI_Double.h index 9fe5df536..7aef756b9 100644 --- a/src/ModelHighAPI/ModelHighAPI_Double.h +++ b/src/ModelHighAPI/ModelHighAPI_Double.h @@ -63,6 +63,9 @@ public: /// Value of the attribute MODELHIGHAPI_EXPORT double value() const; + /// Returns a string representation of the value + MODELHIGHAPI_EXPORT virtual std::string string() const; + private: enum VariantType { VT_DOUBLE, VT_STRING } myVariantType; double myDouble; diff --git a/src/ModelHighAPI/ModelHighAPI_Integer.cpp b/src/ModelHighAPI/ModelHighAPI_Integer.cpp index 8691146f9..c76a3a963 100644 --- a/src/ModelHighAPI/ModelHighAPI_Integer.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Integer.cpp @@ -20,6 +20,8 @@ #include "ModelHighAPI_Integer.h" #include + +#include //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- @@ -60,3 +62,13 @@ int ModelHighAPI_Integer::intValue() const // needed for array of integer, which supports no text return myInt; } + +std::string ModelHighAPI_Integer::string() const +{ + if (myVariantType == VT_STRING) + return myString; + + std::ostringstream anOut; + anOut << myInt; + return anOut.str(); +} diff --git a/src/ModelHighAPI/ModelHighAPI_Integer.h b/src/ModelHighAPI/ModelHighAPI_Integer.h index 8fadf9010..d45c63b76 100644 --- a/src/ModelHighAPI/ModelHighAPI_Integer.h +++ b/src/ModelHighAPI/ModelHighAPI_Integer.h @@ -55,6 +55,9 @@ public: /// Returns a value (must be used only for attributes which support no text) MODELHIGHAPI_EXPORT virtual int intValue() const; + /// Returns a string representation of the value + MODELHIGHAPI_EXPORT virtual std::string string() const; + private: enum VariantType { VT_INT, VT_STRING } myVariantType; int myInt;