From: azv Date: Sun, 16 Feb 2020 12:16:49 +0000 (+0300) Subject: Task 3.2. To keep compounds’ sub-shapes for all operations (issue #3139) X-Git-Tag: V9_5_0a1^2~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dc31f8675dba96df59f15d4dca3ab11e7f95051f;p=modules%2Fshaper.git Task 3.2. To keep compounds’ sub-shapes for all operations (issue #3139) Refactor the Translation feature. --- diff --git a/src/FeaturesAPI/FeaturesAPI.i b/src/FeaturesAPI/FeaturesAPI.i index 01ca8e21a..1d3b9358b 100644 --- a/src/FeaturesAPI/FeaturesAPI.i +++ b/src/FeaturesAPI/FeaturesAPI.i @@ -45,6 +45,7 @@ %feature("kwargs") addPlacement; %feature("kwargs") addSplit; %feature("kwargs") addSmash; +%feature("kwargs") addTranslation; %feature("kwargs") addUnion; // shared pointers @@ -144,6 +145,48 @@ // fix compilation error: 'res*' was not declared in this scope %typemap(freearg) const std::pair, bool> & {} + +%typecheck(SWIG_TYPECHECK_POINTER) std::pair, const std::pair & { + ModelHighAPI_Selection* temp_selection; + int newmem = 0; + if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (temp_selection) { + $1 = 1; + } else { + $1 = 0; + } + } else { + $1 = ((PyFloat_Check($input) || PyLong_Check($input) || PyUnicode_Check($input)) && !PyBool_Check($input)) ? 1 : 0; + } +} + +%typemap(in) const std::pair & (std::pair temp) { + ModelHighAPI_Selection* temp_selection; + int newmem = 0; + if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (temp_selection) { + temp = std::pair(*temp_selection, ModelHighAPI_Double(0.0)); + if (newmem & SWIG_CAST_NEW_MEMORY) { + delete temp_selection; + } + } + } else if (PyFloat_Check($input) || PyLong_Check($input)) { + temp = std::pair(ModelHighAPI_Selection(), ModelHighAPI_Double(PyFloat_AsDouble($input))); + } else if (PyUnicode_Check($input)) { + temp = std::pair(ModelHighAPI_Selection(), ModelHighAPI_Double(PyUnicode_AsUTF8($input))); + } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) { + temp = std::pair($1->first, $1->second); + } else { + PyErr_SetString(PyExc_ValueError, "argument must be selection, ModelHighAPI_Double, float, int or string."); + return NULL; + } + $1 = &temp; +} + +// fix compilation error: 'res*' was not declared in this scope +%typemap(freearg) const std::pair & {} + + // all supported interfaces %include "FeaturesAPI_BooleanCut.h" %include "FeaturesAPI_BooleanFuse.h" diff --git a/src/FeaturesAPI/FeaturesAPI_Translation.cpp b/src/FeaturesAPI/FeaturesAPI_Translation.cpp index 35090f202..0c98c3181 100644 --- a/src/FeaturesAPI/FeaturesAPI_Translation.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Translation.cpp @@ -141,52 +141,91 @@ void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const aBase->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID()); AttributeDoublePtr anAttrDistance = aBase->real(FeaturesPlugin_Translation::DISTANCE_ID()); - theDumper << ", " << anAttrAxis << ", " << anAttrDistance; + theDumper << ", axis = " << anAttrAxis << ", distance = " << anAttrDistance; } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS()) { AttributeDoublePtr anAttrDx = aBase->real(FeaturesPlugin_Translation::DX_ID()); AttributeDoublePtr anAttrDy = aBase->real(FeaturesPlugin_Translation::DY_ID()); AttributeDoublePtr anAttrDz = aBase->real(FeaturesPlugin_Translation::DZ_ID()); - theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz; + theDumper << ", vector = [" << anAttrDx << ", " << anAttrDy << ", " << anAttrDz << "]"; } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS()) { AttributeSelectionPtr anAttrStartPoint = aBase->selection(FeaturesPlugin_Translation::START_POINT_ID()); AttributeSelectionPtr anAttrEndPoint = aBase->selection(FeaturesPlugin_Translation::END_POINT_ID()); - theDumper << ", " << anAttrStartPoint << ", " << anAttrEndPoint; + theDumper << ", startPoint = " << anAttrStartPoint << ", endPoint = " << anAttrEndPoint; } + if (!aBase->data()->version().empty()) + theDumper << ", keepSubResults = True"; + theDumper << ")" << std::endl; } //================================================================================================== -TranslationPtr addTranslation(const std::shared_ptr& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Selection& theAxisObject, - const ModelHighAPI_Double& theDistance) +TranslationPtr addTranslation( + const std::shared_ptr& part, + const std::list& objects, + const std::pair& deprecated1, + const std::pair& deprecated2, + const std::pair& deprecated3, + const ModelHighAPI_Selection& axis, const ModelHighAPI_Double& distance, + const std::list& vector, + const ModelHighAPI_Selection& startPoint, const ModelHighAPI_Selection& endPoint, + const bool keepSubResults) { - std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Translation::ID()); - return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, - theAxisObject, theDistance)); -} + std::shared_ptr aFeature = part->addFeature(FeaturesAPI_Translation::ID()); + if (!keepSubResults) + aFeature->data()->setVersion(""); + + static const int VEC_SIZE = 3; + + bool byAxis = axis.variantType() != ModelHighAPI_Selection::VT_Empty; + bool byVector = vector.size() == VEC_SIZE; + bool byPoints = startPoint.variantType() != ModelHighAPI_Selection::VT_Empty && + endPoint.variantType() != ModelHighAPI_Selection::VT_Empty; + + ModelHighAPI_Selection firstSel, secondSel; + ModelHighAPI_Double values[VEC_SIZE]; + if (byAxis) { + firstSel = axis; + values[0] = distance; + } + else if (byVector) { + std::list::const_iterator it = vector.begin(); + for (ModelHighAPI_Double* vIt = values; it != vector.end(); ++vIt, ++it) + *vIt = *it; + } + else if (byPoints) { + firstSel = startPoint; + secondSel = endPoint; + } + else { + byVector = deprecated1.first.variantType() == ModelHighAPI_Selection::VT_Empty; + if (byVector) { + values[0] = deprecated1.second; + values[1] = deprecated2.second; + values[2] = deprecated3.second; + } + else { + firstSel = deprecated1.first; + secondSel = deprecated2.first; + values[0] = deprecated2.second; + if (secondSel.variantType() == ModelHighAPI_Selection::VT_Empty) + byAxis = true; + else + byPoints = true; + } + } -//================================================================================================== -TranslationPtr addTranslation(const std::shared_ptr& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Double& theDx, - const ModelHighAPI_Double& theDy, - const ModelHighAPI_Double& theDz) -{ - std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Translation::ID()); - return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theDx, theDy, theDz)); -} + TranslationPtr aTranslation; + if (byAxis) + aTranslation.reset(new FeaturesAPI_Translation(aFeature, objects, firstSel, values[0])); + else if (byVector) { + aTranslation.reset(new FeaturesAPI_Translation(aFeature, objects, + values[0], values[1], values[2])); + } + else if (byPoints) + aTranslation.reset(new FeaturesAPI_Translation(aFeature, objects, firstSel, secondSel)); -//================================================================================================== -TranslationPtr addTranslation(const std::shared_ptr& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Selection& theStartPoint, - const ModelHighAPI_Selection& theEndPoint) -{ - std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Translation::ID()); - return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, - theStartPoint, theEndPoint)); + return aTranslation; } diff --git a/src/FeaturesAPI/FeaturesAPI_Translation.h b/src/FeaturesAPI/FeaturesAPI_Translation.h index 10e20a368..2f6a43b3a 100644 --- a/src/FeaturesAPI/FeaturesAPI_Translation.h +++ b/src/FeaturesAPI/FeaturesAPI_Translation.h @@ -24,12 +24,12 @@ #include +#include #include #include +#include -class ModelHighAPI_Double; class ModelHighAPI_Dumper; -class ModelHighAPI_Selection; /// \class FeaturesAPI_Translation /// \ingroup CPPHighAPI @@ -116,29 +116,21 @@ public: /// Pointer on Translation object. typedef std::shared_ptr TranslationPtr; -/// \ingroup CPPHighAPI -/// \brief Create Translation feature. -FEATURESAPI_EXPORT -TranslationPtr addTranslation(const std::shared_ptr& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Selection& theAxisObject, - const ModelHighAPI_Double& theDistance); - -/// \ingroup CPPHighAPI -/// \brief Create Translation feature. -FEATURESAPI_EXPORT -TranslationPtr addTranslation(const std::shared_ptr& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Double& theDx, - const ModelHighAPI_Double& theDy, - const ModelHighAPI_Double& theDz); +#define DUMMY std::pair() /// \ingroup CPPHighAPI /// \brief Create Translation feature. -FEATURESAPI_EXPORT -TranslationPtr addTranslation(const std::shared_ptr& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Selection& theStartPoint, - const ModelHighAPI_Selection& theEndPoint); +FEATURESAPI_EXPORT TranslationPtr addTranslation( + const std::shared_ptr& part, + const std::list& objects, + const std::pair& deprecated1 = DUMMY, + const std::pair& deprecated2 = DUMMY, + const std::pair& deprecated3 = DUMMY, + const ModelHighAPI_Selection& axis = ModelHighAPI_Selection(), + const ModelHighAPI_Double& distance = ModelHighAPI_Double(0.0), + const std::list& vector = std::list(), + const ModelHighAPI_Selection& startPoint = ModelHighAPI_Selection(), + const ModelHighAPI_Selection& endPoint = ModelHighAPI_Selection(), + const bool keepSubResults = false ); #endif // FeaturesAPI_Translation_H_ diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 69defc8b5..2ccf72390 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -581,4 +581,14 @@ ADD_UNIT_TESTS(TestExtrusion.py TestPlacement_MultiLevelCompound_v95_4.py TestPlacement_MultiLevelCompound_v95_5.py TestPlacement_MultiLevelCompound_v95_6.py + TestTranslation_MultiLevelCompound_v0_1.py + TestTranslation_MultiLevelCompound_v0_2.py + TestTranslation_MultiLevelCompound_v0_3.py + TestTranslation_MultiLevelCompound_v0_4.py + TestTranslation_MultiLevelCompound_v0_5.py + TestTranslation_MultiLevelCompound_v95_1.py + TestTranslation_MultiLevelCompound_v95_2.py + TestTranslation_MultiLevelCompound_v95_3.py + TestTranslation_MultiLevelCompound_v95_4.py + TestTranslation_MultiLevelCompound_v95_5.py ) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp index df5d532ab..737598a19 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp @@ -72,26 +72,9 @@ void FeaturesPlugin_Placement::execute() GeomAPI_ShapeHierarchy anObjects; std::list aParts; AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECTS_LIST_ID()); - if(anObjectsSelList->size() == 0) { + if (!FeaturesPlugin_Tools::shapesFromSelectionList( + anObjectsSelList, isKeepSubShapes, anObjects, aParts)) return; - } - for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { - std::shared_ptr anObjectAttr = - anObjectsSelList->value(anObjectsIndex); - std::shared_ptr anObject = anObjectAttr->value(); - if(!anObject.get()) { // may be for not-activated parts - return; - } - ResultPtr aContext = anObjectAttr->context(); - if (aContext->groupName() == ModelAPI_ResultPart::group()) - aParts.push_back(aContext); - else { - // store full shape hierarchy for the corresponding version only - anObjects.addObject(anObject); - if (isKeepSubShapes) - ModelAPI_Tools::fillShapeHierarchy(anObject, aContext, anObjects); - } - } // Verify the start shape AttributeSelectionPtr anObjRef = selection(START_SHAPE_ID()); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp b/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp index 55a173842..9880565de 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include @@ -241,3 +243,30 @@ bool FeaturesPlugin_Tools::getShape(const AttributeSelectionListPtr theSelection } return true; } + +//================================================================================================== +bool FeaturesPlugin_Tools::shapesFromSelectionList( + const std::shared_ptr theSelectionList, + const bool theStoreFullHierarchy, + GeomAPI_ShapeHierarchy& theHierarchy, + std::list& theParts) +{ + int aSize = theSelectionList->size(); + for (int anObjectsIndex = 0; anObjectsIndex < aSize; anObjectsIndex++) { + AttributeSelectionPtr anObjectAttr = theSelectionList->value(anObjectsIndex); + std::shared_ptr anObject = anObjectAttr->value(); + if (!anObject.get()) { // may be for not-activated parts + return false; + } + ResultPtr aContext = anObjectAttr->context(); + if (aContext->groupName() == ModelAPI_ResultPart::group()) + theParts.push_back(aContext); + else { + // store full shape hierarchy for the corresponding version only + theHierarchy.addObject(anObject); + if (theStoreFullHierarchy) + ModelAPI_Tools::fillShapeHierarchy(anObject, aContext, theHierarchy); + } + } + return true; +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_Tools.h b/src/FeaturesPlugin/FeaturesPlugin_Tools.h index 36ad73bdd..6fe514aa9 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Tools.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Tools.h @@ -21,6 +21,7 @@ #define FeaturesPlugin_Tools_H_ #include +#include #include #include @@ -62,6 +63,13 @@ public: const bool theShareTopology, ListOfShape& theShapesList, std::string& theError); + + /// Collect shapes from the attribute and fill the hierarchy or a list of parts + static bool shapesFromSelectionList( + const std::shared_ptr theSelectionList, + const bool theStoreFullHierarchy, + GeomAPI_ShapeHierarchy& theHierarchy, + std::list& theParts); }; #endif /* FeaturesPlugin_Tools_H_ */ diff --git a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp index 9894901e4..3eeaac0fa 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp @@ -31,13 +31,18 @@ #include #include #include +#include #include +#include #include #include +#include #include +static const std::string TRANSLATION_VERSION_1("v9.5"); + //================================================================================================= FeaturesPlugin_Translation::FeaturesPlugin_Translation() { @@ -69,6 +74,11 @@ void FeaturesPlugin_Translation::initAttributes() ModelAPI_AttributeSelection::typeId()); data()->addAttribute(FeaturesPlugin_Translation::END_POINT_ID(), ModelAPI_AttributeSelection::typeId()); + + if (!aSelection->isInitialized()) { + // new feature, not read from file + data()->setVersion(TRANSLATION_VERSION_1); + } } //================================================================================================= @@ -77,41 +87,20 @@ void FeaturesPlugin_Translation::execute() AttributeStringPtr aMethodTypeAttr = string(FeaturesPlugin_Translation::CREATION_METHOD()); std::string aMethodType = aMethodTypeAttr->value(); - if (aMethodType == CREATION_METHOD_BY_DISTANCE()) { - performTranslationByAxisAndDistance(); - } - - if (aMethodType == CREATION_METHOD_BY_DIMENSIONS()) { - performTranslationByDimensions(); - } + GeomTrsfPtr aTrsf; + if (aMethodType == CREATION_METHOD_BY_DISTANCE()) + aTrsf = translationByAxisAndDistance(); + else if (aMethodType == CREATION_METHOD_BY_DIMENSIONS()) + aTrsf = translationByDimensions(); + else if (aMethodType == CREATION_METHOD_BY_TWO_POINTS()) + aTrsf = translationByTwoPoints(); - if (aMethodType == CREATION_METHOD_BY_TWO_POINTS()) { - performTranslationByTwoPoints(); - } + performTranslation(aTrsf); } //================================================================================================= -void FeaturesPlugin_Translation::performTranslationByAxisAndDistance() +GeomTrsfPtr FeaturesPlugin_Translation::translationByAxisAndDistance() { - // Getting objects. - ListOfShape anObjects; - std::list aContextes; - AttributeSelectionListPtr anObjectsSelList = - selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID()); - if (anObjectsSelList->size() == 0) { - 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_OBJECT_ID()); @@ -123,7 +112,7 @@ void FeaturesPlugin_Translation::performTranslationByAxisAndDistance() } if (!aShape.get()) { setError(aSelectionError); - return; + return GeomTrsfPtr(); } GeomEdgePtr anEdge; @@ -140,156 +129,36 @@ void FeaturesPlugin_Translation::performTranslationByAxisAndDistance() if (!anEdge.get()) { setError(aSelectionError); - return; + return GeomTrsfPtr(); } std::shared_ptr anAxis(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction())); - // Getting distance. double aDistance = real(FeaturesPlugin_Translation::DISTANCE_ID())->value(); - // 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(); - - // Setting result. - if (isPart) { - std::shared_ptr aTrsf(new GeomAPI_Trsf()); - aTrsf->setTranslation(anAxis, aDistance); - ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); - ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); - aResultPart->setTrsf(*aContext, aTrsf); - setResult(aResultPart, aResultIndex); - } else { - std::shared_ptr aTranslationAlgo( - new GeomAlgoAPI_Translation(aBaseShape, anAxis, aDistance)); - // Checking that the algorithm worked properly. - if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) { - setError(anError); - break; - } - - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - - ListOfShape aShapes; - aShapes.push_back(aBaseShape); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, - aShapes, - ListOfShape(), - aTranslationAlgo, - aTranslationAlgo->shape(), - "Translated"); - setResult(aResultBody, aResultIndex); - } - aResultIndex++; - } - - // Remove the rest results if there were produced in the previous pass. - removeResults(aResultIndex); + GeomTrsfPtr aTrsf(new GeomAPI_Trsf); + aTrsf->setTranslation(anAxis, aDistance); + return aTrsf; } //================================================================================================= -void FeaturesPlugin_Translation::performTranslationByDimensions() +GeomTrsfPtr FeaturesPlugin_Translation::translationByDimensions() { - // Getting objects. - ListOfShape anObjects; - std::list aContextes; - AttributeSelectionListPtr anObjectsSelList = - selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID()); - if (anObjectsSelList->size() == 0) { - 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 dimensions in X, in Y and in Z double aDX = real(FeaturesPlugin_Translation::DX_ID())->value(); double aDY = real(FeaturesPlugin_Translation::DY_ID())->value(); double aDZ = real(FeaturesPlugin_Translation::DZ_ID())->value(); - // 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(); - - // Setting result. - if (isPart) { - std::shared_ptr aTrsf(new GeomAPI_Trsf()); - aTrsf->setTranslation(aDX, aDY, aDZ); - ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); - ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); - aResultPart->setTrsf(*aContext, aTrsf); - setResult(aResultPart, aResultIndex); - } else { - std::shared_ptr aTranslationAlgo( - new GeomAlgoAPI_Translation(aBaseShape, aDX, aDY, aDZ)); - - // Checking that the algorithm worked properly. - if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) { - setError(anError); - break; - } - - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - - ListOfShape aShapes; - aShapes.push_back(aBaseShape); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, - aShapes, - ListOfShape(), - aTranslationAlgo, - aTranslationAlgo->shape(), - "Translated"); - setResult(aResultBody, aResultIndex); - } - aResultIndex++; - } - - // Remove the rest results if there were produced in the previous pass. - removeResults(aResultIndex); + GeomTrsfPtr aTrsf(new GeomAPI_Trsf); + aTrsf->setTranslation(aDX, aDY, aDZ); + return aTrsf; } //================================================================================================= -void FeaturesPlugin_Translation::performTranslationByTwoPoints() +GeomTrsfPtr FeaturesPlugin_Translation::translationByTwoPoints() { - // Getting objects. - ListOfShape anObjects; - std::list aContextes; - AttributeSelectionListPtr anObjectsSelList = - selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID()); - if (anObjectsSelList->size() == 0) { - return; - } - for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { - std::shared_ptr anObjectAttr = - anObjectsSelList->value(anObjectsIndex); - std::shared_ptr anObject = anObjectAttr->value(); - if(!anObject.get()) { // may be for not-activated parts - return; - } - anObjects.push_back(anObject); - aContextes.push_back(anObjectAttr->context()); - } - // Getting the start point and the end point AttributeSelectionPtr aRef1 = data()->selection(FeaturesPlugin_Translation::START_POINT_ID()); AttributeSelectionPtr aRef2 = data()->selection(FeaturesPlugin_Translation::END_POINT_ID()); @@ -308,46 +177,66 @@ void FeaturesPlugin_Translation::performTranslationByTwoPoints() } } - // Moving each object. + GeomTrsfPtr aTrsf(new GeomAPI_Trsf); + aTrsf->setTranslation(aFirstPoint, aSecondPoint); + return aTrsf; +} + +//================================================================================================= +void FeaturesPlugin_Translation::performTranslation(const GeomTrsfPtr& theTrsf) +{ + if (!theTrsf) + return; + + bool isKeepSubShapes = data()->version() == TRANSLATION_VERSION_1; + + // Getting objects. + GeomAPI_ShapeHierarchy anObjects; + std::list aParts; + AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECTS_LIST_ID()); + if (!FeaturesPlugin_Tools::shapesFromSelectionList( + anObjectsSelList, isKeepSubShapes, anObjects, aParts)) + return; + std::string anError; int aResultIndex = 0; - std::list::iterator aContext = aContextes.begin(); - for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); - anObjectsIt++, aContext++) { + // Moving each part. + for (std::list::iterator aPRes = aParts.begin(); aPRes != aParts.end(); ++aPRes) { + ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aPRes); + ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); + aResultPart->setTrsf(anOrigin, theTrsf); + setResult(aResultPart, aResultIndex++); + } + + // 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; - bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); - - // Setting result. - if (isPart) { - std::shared_ptr aTrsf(new GeomAPI_Trsf()); - aTrsf->setTranslation(aFirstPoint, aSecondPoint); - ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); - ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); - aResultPart->setTrsf(*aContext, aTrsf); - setResult(aResultPart, aResultIndex); - } else { - std::shared_ptr aTranslationAlgo( - new GeomAlgoAPI_Translation(aBaseShape, aFirstPoint, aSecondPoint)); - - // Checking that the algorithm worked properly. - if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) { - setError(anError); - break; - } - - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - - ListOfShape aShapes; - aShapes.push_back(aBaseShape); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, - aShapes, - ListOfShape(), - aTranslationAlgo, - aTranslationAlgo->shape(), - "Translated"); - setResult(aResultBody, aResultIndex); + std::shared_ptr aTransformAlgo( + new GeomAlgoAPI_Transform(aBaseShape, theTrsf)); + + // Checking that the algorithm worked properly. + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTransformAlgo, getKind(), anError)) { + setError(anError); + break; } - aResultIndex++; + + anObjects.markModified(aBaseShape, aTransformAlgo->shape()); + aMakeShapeList->appendAlgo(aTransformAlgo); + } + + // 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) { + //LoadNamingDS + 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. diff --git a/src/FeaturesPlugin/FeaturesPlugin_Translation.h b/src/FeaturesPlugin/FeaturesPlugin_Translation.h index 3437c5be6..c9869afb9 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Translation.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Translation.h @@ -24,7 +24,7 @@ #include -#include +class GeomAPI_Trsf; /// \class FeaturesPlugin_Translation /// \ingroup Plugins @@ -140,14 +140,17 @@ class FeaturesPlugin_Translation : public ModelAPI_Feature FeaturesPlugin_Translation(); private: - ///Perform the translation using an axis and a distance. - void performTranslationByAxisAndDistance(); + /// Calculate the translation using an axis and a distance. + std::shared_ptr translationByAxisAndDistance(); - ///Perform the translation using three dimensions X, Y and Z - void performTranslationByDimensions(); + /// Calculate the translation using three dimensions X, Y and Z + std::shared_ptr translationByDimensions(); - ///Perform the translation usind two points - void performTranslationByTwoPoints(); + /// Calculate the translation usind two points + std::shared_ptr translationByTwoPoints(); + + /// Perform the translation + void performTranslation(const std::shared_ptr& theTrsf); }; #endif diff --git a/src/FeaturesPlugin/Test/TestPlacement_MultiLevelCompound_v95_3.py b/src/FeaturesPlugin/Test/TestPlacement_MultiLevelCompound_v95_3.py index bbede85d9..9c615c830 100644 --- a/src/FeaturesPlugin/Test/TestPlacement_MultiLevelCompound_v95_3.py +++ b/src/FeaturesPlugin/Test/TestPlacement_MultiLevelCompound_v95_3.py @@ -65,7 +65,7 @@ Placement_1 = model.addPlacement(Part_1_doc, [model.selection("SOLID", "Compound model.end() -# selection of a compound part is prohibited +# selection of a compsolid part is prohibited assert(Placement_1.feature().error() != "") # change the placement arguments diff --git a/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_1.py b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_1.py new file mode 100644 index 000000000..09c1d9bad --- /dev/null +++ b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_1.py @@ -0,0 +1,135 @@ +# 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 = 10 +TOLERANCE = 1.e-7 + +model.begin() +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("EDGE", "PartSet/OX"), DISTANCE) +model.testNbResults(Translation_1, 1) +model.testNbSubResults(Translation_1, [0]) +model.testNbSubShapes(Translation_1, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Translation_1, GeomAPI_Shape.FACE, [5]) +model.testNbSubShapes(Translation_1, GeomAPI_Shape.EDGE, [18]) +model.testNbSubShapes(Translation_1, GeomAPI_Shape.VERTEX, [36]) +model.testResultsVolumes(Translation_1, [542.746463956]) + +refPoint = Extrusion_1.results()[0].subResult(4).resultSubShapePair()[0].shape().middlePoint() +refPoint.setX(refPoint.x() + DISTANCE) +midPoint = Translation_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_1 = model.addRecover(Part_1_doc, Translation_1, [Compound_2.result()], True) +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Recover_1_1_2_1")], model.selection("EDGE", "PartSet/OY"), DISTANCE) +model.testNbResults(Translation_2, 1) +model.testNbSubResults(Translation_2, [0]) +model.testNbSubShapes(Translation_2, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Translation_2, GeomAPI_Shape.FACE, [3]) +model.testNbSubShapes(Translation_2, GeomAPI_Shape.EDGE, [6]) +model.testNbSubShapes(Translation_2, GeomAPI_Shape.VERTEX, [12]) +model.testResultsVolumes(Translation_2, [785.39816339745]) + +refPoint = Recover_1.result().subResult(1).subResult(0).resultSubShapePair()[0].shape().middlePoint() +refPoint.setY(refPoint.y() + DISTANCE) +midPoint = Translation_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_2 = model.addRecover(Part_1_doc, Translation_2, [Recover_1.result()], True) +Translation_3 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Recover_2_1_3")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_3, 1) +model.testNbSubResults(Translation_3, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.FACE, [3]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.EDGE, [6]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.VERTEX, [12]) +model.testResultsVolumes(Translation_3, [785.39816339745]) + +refPoint = Recover_2.result().subResult(2).resultSubShapePair()[0].shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_3 = model.addRecover(Part_1_doc, Translation_3, [Recover_2.result()], True) +Translation_4 = model.addTranslation(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) +model.testNbResults(Translation_4, 3) +model.testNbSubResults(Translation_4, [0, 0, 0]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.SOLID, [1, 1, 1]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.FACE, [6, 3, 3]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.EDGE, [24, 6, 6]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.VERTEX, [48, 12, 12]) +model.testResultsVolumes(Translation_4, [3444.394198615, 785.39816339745, 785.39816339745]) + +REFERENCE = [Recover_3.result().subResult(0).subResult(0).resultSubShapePair()[0].shape().middlePoint(), + Recover_3.result().subResult(1).subResult(1).resultSubShapePair()[0].shape().middlePoint(), + Recover_3.result().subResult(2).resultSubShapePair()[0].shape().middlePoint()] +for res, ref in zip(Translation_4.results(), REFERENCE): + ref.setZ(ref.z() - DISTANCE) + midPoint = res.resultSubShapePair()[0].shape().middlePoint() + assert(midPoint.distance(ref) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_2.py b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_2.py new file mode 100644 index 000000000..bc1ef0744 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_2.py @@ -0,0 +1,139 @@ +# 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() + +DX = 15 +DY = 20 +DZ = 25 +TOLERANCE = 1.e-7 + +model.begin() +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], DX, 0, 0) +model.testNbResults(Translation_1, 1) +model.testNbSubResults(Translation_1, [0]) +model.testNbSubShapes(Translation_1, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Translation_1, GeomAPI_Shape.FACE, [5]) +model.testNbSubShapes(Translation_1, GeomAPI_Shape.EDGE, [18]) +model.testNbSubShapes(Translation_1, GeomAPI_Shape.VERTEX, [36]) +model.testResultsVolumes(Translation_1, [542.746463956]) + +refPoint = Extrusion_1.results()[0].subResult(4).resultSubShapePair()[0].shape().middlePoint() +refPoint.setX(refPoint.x() + DX) +midPoint = Translation_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_1 = model.addRecover(Part_1_doc, Translation_1, [Compound_2.result()], True) +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Recover_1_1_2_1")], 0, DY, 0) +model.testNbResults(Translation_2, 1) +model.testNbSubResults(Translation_2, [0]) +model.testNbSubShapes(Translation_2, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Translation_2, GeomAPI_Shape.FACE, [3]) +model.testNbSubShapes(Translation_2, GeomAPI_Shape.EDGE, [6]) +model.testNbSubShapes(Translation_2, GeomAPI_Shape.VERTEX, [12]) +model.testResultsVolumes(Translation_2, [785.39816339745]) + +refPoint = Recover_1.result().subResult(1).subResult(0).resultSubShapePair()[0].shape().middlePoint() +refPoint.setY(refPoint.y() + DY) +midPoint = Translation_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_2 = model.addRecover(Part_1_doc, Translation_2, [Recover_1.result()], True) +Translation_3 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Recover_2_1_3")], 0, 0, DZ) +model.testNbResults(Translation_3, 1) +model.testNbSubResults(Translation_3, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.FACE, [3]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.EDGE, [6]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.VERTEX, [12]) +model.testResultsVolumes(Translation_3, [785.39816339745]) + +refPoint = Recover_2.result().subResult(2).resultSubShapePair()[0].shape().middlePoint() +refPoint.setZ(refPoint.z() + DZ) +midPoint = Translation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_3 = model.addRecover(Part_1_doc, Translation_3, [Recover_2.result()], True) +Translation_4 = model.addTranslation(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")], DX, DY, DZ) +model.testNbResults(Translation_4, 3) +model.testNbSubResults(Translation_4, [0, 0, 0]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.SOLID, [1, 1, 1]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.FACE, [6, 3, 3]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.EDGE, [24, 6, 6]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.VERTEX, [48, 12, 12]) +model.testResultsVolumes(Translation_4, [3444.394198615, 785.39816339745, 785.39816339745]) + +REFERENCE = [Recover_3.result().subResult(0).subResult(0).resultSubShapePair()[0].shape().middlePoint(), + Recover_3.result().subResult(1).subResult(1).resultSubShapePair()[0].shape().middlePoint(), + Recover_3.result().subResult(2).resultSubShapePair()[0].shape().middlePoint()] +for res, ref in zip(Translation_4.results(), REFERENCE): + ref.setX(ref.x() + DX) + ref.setY(ref.y() + DY) + ref.setZ(ref.z() + DZ) + midPoint = res.resultSubShapePair()[0].shape().middlePoint() + assert(midPoint.distance(ref) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_3.py b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_3.py new file mode 100644 index 000000000..e1db0e5eb --- /dev/null +++ b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_3.py @@ -0,0 +1,136 @@ +# Copyright (C) 2020 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from salome.shaper import model + +from GeomAPI import * +from SketchAPI import * + +MAJOR_AXIS = 30 + +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(), MAJOR_AXIS) +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 + +model.begin() +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("VERTEX", "Sketch_1/SketchEllipse_1_ellipse_major_axis_start_point"), model.selection("VERTEX", "Sketch_1/SketchEllipse_1_major_axis_EndVertex")) +model.testNbResults(Translation_1, 1) +model.testNbSubResults(Translation_1, [0]) +model.testNbSubShapes(Translation_1, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Translation_1, GeomAPI_Shape.FACE, [5]) +model.testNbSubShapes(Translation_1, GeomAPI_Shape.EDGE, [18]) +model.testNbSubShapes(Translation_1, GeomAPI_Shape.VERTEX, [36]) +model.testResultsVolumes(Translation_1, [542.746463956]) + +refPoint = Extrusion_1.results()[0].subResult(4).resultSubShapePair()[0].shape().middlePoint() +refPoint.setX(refPoint.x() + MAJOR_AXIS) +midPoint = Translation_1.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_1 = model.addRecover(Part_1_doc, Translation_1, [Compound_2.result()], True) +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Recover_1_1_2_1")], model.selection("VERTEX", "Sketch_1/SketchEllipse_1_ellipse_major_axis_start_point"), model.selection("VERTEX", "Sketch_1/SketchEllipse_1_major_axis_EndVertex")) +model.testNbResults(Translation_2, 1) +model.testNbSubResults(Translation_2, [0]) +model.testNbSubShapes(Translation_2, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Translation_2, GeomAPI_Shape.FACE, [3]) +model.testNbSubShapes(Translation_2, GeomAPI_Shape.EDGE, [6]) +model.testNbSubShapes(Translation_2, GeomAPI_Shape.VERTEX, [12]) +model.testResultsVolumes(Translation_2, [785.39816339745]) + +refPoint = Recover_1.result().subResult(1).subResult(0).resultSubShapePair()[0].shape().middlePoint() +refPoint.setX(refPoint.x() + MAJOR_AXIS) +midPoint = Translation_2.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_2 = model.addRecover(Part_1_doc, Translation_2, [Recover_1.result()], True) +Translation_3 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Recover_2_1_3")], model.selection("VERTEX", "Sketch_1/SketchEllipse_1_ellipse_major_axis_start_point"), model.selection("VERTEX", "Sketch_1/SketchEllipse_1_major_axis_EndVertex")) +model.testNbResults(Translation_3, 1) +model.testNbSubResults(Translation_3, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.FACE, [3]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.EDGE, [6]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.VERTEX, [12]) +model.testResultsVolumes(Translation_3, [785.39816339745]) + +refPoint = Recover_2.result().subResult(2).resultSubShapePair()[0].shape().middlePoint() +refPoint.setX(refPoint.x() + MAJOR_AXIS) +midPoint = Translation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + + +Recover_3 = model.addRecover(Part_1_doc, Translation_3, [Recover_2.result()], True) +Translation_4 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Recover_3_1_1_1"), model.selection("SOLID", "Recover_3_1_2_2"), model.selection("SOLID", "Recover_3_1_3")], model.selection("VERTEX", "Sketch_1/SketchEllipse_1_ellipse_major_axis_start_point"), model.selection("VERTEX", "Sketch_1/SketchEllipse_1_major_axis_EndVertex")) +model.testNbResults(Translation_4, 3) +model.testNbSubResults(Translation_4, [0, 0, 0]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.SOLID, [1, 1, 1]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.FACE, [6, 3, 3]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.EDGE, [24, 6, 6]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.VERTEX, [48, 12, 12]) +model.testResultsVolumes(Translation_4, [3444.394198615, 785.39816339745, 785.39816339745]) + +REFERENCE = [Recover_3.result().subResult(0).subResult(0).resultSubShapePair()[0].shape().middlePoint(), + Recover_3.result().subResult(1).subResult(1).resultSubShapePair()[0].shape().middlePoint(), + Recover_3.result().subResult(2).resultSubShapePair()[0].shape().middlePoint()] +for res, ref in zip(Translation_4.results(), REFERENCE): + ref.setX(ref.x() + MAJOR_AXIS) + midPoint = res.resultSubShapePair()[0].shape().middlePoint() + assert(midPoint.distance(ref) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump(model.CHECK_NAMING)) diff --git a/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_4.py b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_4.py new file mode 100644 index 000000000..61d29899d --- /dev/null +++ b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_4.py @@ -0,0 +1,187 @@ +# Copyright (C) 2020 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from salome.shaper import model +from GeomAPI import * + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchPoint_1 = Sketch_1.addPoint(44.29784155360136, 17.09942588468031) +SketchArc_1 = Sketch_1.addArc(44.29784155360136, 17.09942588468031, 47.1668727423061, 12.27945348765633, 45.38299232715926, 22.60269052200972, False) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchArc_1.center()) +SketchLine_1 = Sketch_1.addLine(42.5764228403785, 22.14892077680068, 39.70739165167375, 16.41085839939117) +SketchLine_2 = Sketch_1.addLine(39.70739165167375, 16.41085839939117, 43.03546783057126, 12.04993099255995) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(28.57555063949931, 12.96802097294547, 15.72229091410204, 12.96802097294547) +SketchLine_4 = Sketch_1.addLine(15.72229091410204, 12.96802097294547, 15.72229091410204, 21.46035329151154) +SketchLine_5 = Sketch_1.addLine(15.72229091410204, 21.46035329151154, 28.57555063949931, 21.46035329151154) +SketchLine_6 = Sketch_1.addLine(28.57555063949931, 21.46035329151154, 28.57555063949931, 12.96802097294547) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_4.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_5.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_6.result()) +SketchLine_7 = Sketch_1.addLine(-10.67279602198167, 14.78814178154371, -28.34602814440294, 14.78814178154371) +SketchLine_8 = Sketch_1.addLine(-28.34602814440294, 14.78814178154371, -28.34602814440294, 25.13271321305362) +SketchLine_9 = Sketch_1.addLine(-28.34602814440294, 25.13271321305362, -10.67279602198167, 25.13271321305362) +SketchLine_10 = Sketch_1.addLine(-10.67279602198167, 25.13271321305362, -10.67279602198167, 14.78814178154371) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_10.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint()) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint()) +SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_7.result()) +SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_8.result()) +SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_9.result()) +SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_10.result()) +SketchLine_11 = Sketch_1.addLine(-17.67323212242127, 25.13271321305362, -21.80463703415611, 14.78814178154371) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_11.startPoint(), SketchLine_9.result()) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_11.endPoint(), SketchLine_7.result()) +model.do() +Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchArc_1")], False) +Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchArc_1_2")], False) +Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1"), model.selection("EDGE", "Sketch_1/SketchLine_2")], False) +Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_6r-SketchLine_5r-SketchLine_4r-SketchLine_3r")]) +Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_10r-SketchLine_9r-SketchLine_11f-SketchLine_7r"), model.selection("FACE", "Sketch_1/Face-SketchLine_11r-SketchLine_9r-SketchLine_8r-SketchLine_7r")]) +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 50) +Box_2 = model.addBox(Part_1_doc, 10, 10, 10) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10) +Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_2_1"), model.selection("SOLID", "Cylinder_1_1")]) +Box_3 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OY"), 50) +AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Translation_2_1")], model.selection("EDGE", "PartSet/OZ"), 30, 3) +model.end() + +DISTANCE = 10 +TOLERANCE = 1.e-7 + +model.begin() +Translation_3 = model.addTranslation(Part_1_doc, [model.selection("VERTEX", "Vertex_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_3, 1) +model.testNbSubResults(Translation_3, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.EDGE, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.VERTEX, [1]) +model.testResultsVolumes(Translation_3, [0]) +refPoint = Vertex_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_4 = model.addTranslation(Part_1_doc, [model.selection("EDGE", "Edge_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_4, 1) +model.testNbSubResults(Translation_4, [0]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.EDGE, [1]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.VERTEX, [2]) +model.testResultsVolumes(Translation_4, [0]) +refPoint = Edge_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_4.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_5 = model.addTranslation(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_5, 1) +model.testNbSubResults(Translation_5, [0]) +model.testNbSubShapes(Translation_5, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_5, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Translation_5, GeomAPI_Shape.EDGE, [2]) +model.testNbSubShapes(Translation_5, GeomAPI_Shape.VERTEX, [4]) +model.testResultsVolumes(Translation_5, [0]) +refPoint = Wire_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_5.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_6 = model.addTranslation(Part_1_doc, [model.selection("FACE", "Face_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_6, 1) +model.testNbSubResults(Translation_6, [0]) +model.testNbSubShapes(Translation_6, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_6, GeomAPI_Shape.FACE, [1]) +model.testNbSubShapes(Translation_6, GeomAPI_Shape.EDGE, [4]) +model.testNbSubShapes(Translation_6, GeomAPI_Shape.VERTEX, [8]) +model.testResultsVolumes(Translation_6, [109.154152964914914]) +refPoint = Face_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_6.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_7 = model.addTranslation(Part_1_doc, [model.selection("SHELL", "Shell_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_7, 1) +model.testNbSubResults(Translation_7, [0]) +model.testNbSubShapes(Translation_7, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_7, GeomAPI_Shape.FACE, [2]) +model.testNbSubShapes(Translation_7, GeomAPI_Shape.EDGE, [8]) +model.testNbSubShapes(Translation_7, GeomAPI_Shape.VERTEX, [16]) +model.testResultsVolumes(Translation_7, [182.822012116]) +refPoint = Shell_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_7.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_8 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_8, 1) +model.testNbSubResults(Translation_8, [0]) +model.testNbSubShapes(Translation_8, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Translation_8, GeomAPI_Shape.FACE, [6]) +model.testNbSubShapes(Translation_8, GeomAPI_Shape.EDGE, [24]) +model.testNbSubShapes(Translation_8, GeomAPI_Shape.VERTEX, [48]) +model.testResultsVolumes(Translation_8, [1000]) +refPoint = Translation_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_8.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_9 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_9, 1) +model.testNbSubResults(Translation_9, [3]) +model.testNbSubShapes(Translation_9, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Translation_9, GeomAPI_Shape.FACE, [17]) +model.testNbSubShapes(Translation_9, GeomAPI_Shape.EDGE, [66]) +model.testNbSubShapes(Translation_9, GeomAPI_Shape.VERTEX, [132]) +model.testResultsVolumes(Translation_9, [1589.0486226]) +refPoint = Partition_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_9.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_10 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "AngularCopy_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_10, 1) +model.testNbSubResults(Translation_10, [3]) +model.testNbSubShapes(Translation_10, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Translation_10, GeomAPI_Shape.FACE, [18]) +model.testNbSubShapes(Translation_10, GeomAPI_Shape.EDGE, [72]) +model.testNbSubShapes(Translation_10, GeomAPI_Shape.VERTEX, [144]) +model.testResultsVolumes(Translation_10, [3000]) +refPoint = AngularCopy_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_10.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_5.py b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_5.py new file mode 100644 index 000000000..1b33ecb7a --- /dev/null +++ b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v0_5.py @@ -0,0 +1,195 @@ +# Copyright (C) 2020 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from salome.shaper import model +from GeomAPI import * + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchPoint_1 = Sketch_1.addPoint(44.29784155360136, 17.09942588468031) +SketchArc_1 = Sketch_1.addArc(44.29784155360136, 17.09942588468031, 47.1668727423061, 12.27945348765633, 45.38299232715926, 22.60269052200972, False) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchArc_1.center()) +SketchLine_1 = Sketch_1.addLine(42.5764228403785, 22.14892077680068, 39.70739165167375, 16.41085839939117) +SketchLine_2 = Sketch_1.addLine(39.70739165167375, 16.41085839939117, 43.03546783057126, 12.04993099255995) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(28.57555063949931, 12.96802097294547, 15.72229091410204, 12.96802097294547) +SketchLine_4 = Sketch_1.addLine(15.72229091410204, 12.96802097294547, 15.72229091410204, 21.46035329151154) +SketchLine_5 = Sketch_1.addLine(15.72229091410204, 21.46035329151154, 28.57555063949931, 21.46035329151154) +SketchLine_6 = Sketch_1.addLine(28.57555063949931, 21.46035329151154, 28.57555063949931, 12.96802097294547) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_4.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_5.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_6.result()) +SketchLine_7 = Sketch_1.addLine(-10.67279602198167, 14.78814178154371, -28.34602814440294, 14.78814178154371) +SketchLine_8 = Sketch_1.addLine(-28.34602814440294, 14.78814178154371, -28.34602814440294, 25.13271321305362) +SketchLine_9 = Sketch_1.addLine(-28.34602814440294, 25.13271321305362, -10.67279602198167, 25.13271321305362) +SketchLine_10 = Sketch_1.addLine(-10.67279602198167, 25.13271321305362, -10.67279602198167, 14.78814178154371) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_10.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint()) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint()) +SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_7.result()) +SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_8.result()) +SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_9.result()) +SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_10.result()) +SketchLine_11 = Sketch_1.addLine(-17.67323212242127, 25.13271321305362, -21.80463703415611, 14.78814178154371) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_11.startPoint(), SketchLine_9.result()) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_11.endPoint(), SketchLine_7.result()) +model.do() +Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchArc_1")], False) +Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchArc_1_2")], False) +Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1"), model.selection("EDGE", "Sketch_1/SketchLine_2")], False) +Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_6r-SketchLine_5r-SketchLine_4r-SketchLine_3r")]) +Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_10r-SketchLine_9r-SketchLine_11f-SketchLine_7r"), model.selection("FACE", "Sketch_1/Face-SketchLine_11r-SketchLine_9r-SketchLine_8r-SketchLine_7r")]) +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 50) +Box_2 = model.addBox(Part_1_doc, 10, 10, 10) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10) +Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_2_1"), model.selection("SOLID", "Cylinder_1_1")]) +Box_3 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OY"), 50) +AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Translation_2_1")], model.selection("EDGE", "PartSet/OZ"), 30, 3) +Compound_1_objects = [model.selection("VERTEX", "Vertex_1_1"), model.selection("EDGE", "Edge_1_1"), model.selection("WIRE", "Wire_1_1"), model.selection("FACE", "Face_1_1"), model.selection("SHELL", "Shell_1_1"), model.selection("SOLID", "Translation_1_1"), model.selection("COMPSOLID", "Partition_1_1"), model.selection("COMPOUND", "AngularCopy_1_1")] +Compound_1 = model.addCompound(Part_1_doc, Compound_1_objects) +model.end() + +# collect reference data +DISTANCE = 10 +REFERENCE = [] +TOLERANCE = 1.e-7 +for ind in range(0, Compound_1.result().numberOfSubs()): + p = Compound_1.result().subResult(ind).resultSubShapePair()[1].middlePoint() + p.setZ(p.z() + DISTANCE) + REFERENCE.append(p) + +index = 0 + +model.begin() +Translation_3 = model.addTranslation(Part_1_doc, [model.selection("VERTEX", "Compound_1_1_1")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_3, 1) +model.testNbSubResults(Translation_3, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.EDGE, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.VERTEX, [1]) +model.testResultsVolumes(Translation_3, [0]) +midPoint = Translation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(REFERENCE[index]) < TOLERANCE) +index += 1 + +Recover_1 = model.addRecover(Part_1_doc, Translation_3, [Compound_1.result()], True) +Translation_4 = model.addTranslation(Part_1_doc, [model.selection("EDGE", "Recover_1_1_2")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_4, 1) +model.testNbSubResults(Translation_4, [0]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.EDGE, [1]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.VERTEX, [2]) +model.testResultsVolumes(Translation_4, [0]) +midPoint = Translation_4.defaultResult().shape().middlePoint() +assert(midPoint.distance(REFERENCE[index]) < TOLERANCE) +index += 1 + +Recover_2 = model.addRecover(Part_1_doc, Translation_4, [Recover_1.result()]) +Translation_5 = model.addTranslation(Part_1_doc, [model.selection("WIRE", "Recover_2_1_3")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_5, 1) +model.testNbSubResults(Translation_5, [0]) +model.testNbSubShapes(Translation_5, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_5, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Translation_5, GeomAPI_Shape.EDGE, [2]) +model.testNbSubShapes(Translation_5, GeomAPI_Shape.VERTEX, [4]) +model.testResultsVolumes(Translation_5, [0]) +midPoint = Translation_5.defaultResult().shape().middlePoint() +assert(midPoint.distance(REFERENCE[index]) < TOLERANCE) +index += 1 + +Recover_3 = model.addRecover(Part_1_doc, Translation_5, [Recover_2.result()]) +Translation_6 = model.addTranslation(Part_1_doc, [model.selection("FACE", "Recover_3_1_4")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_6, 1) +model.testNbSubResults(Translation_6, [0]) +model.testNbSubShapes(Translation_6, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_6, GeomAPI_Shape.FACE, [1]) +model.testNbSubShapes(Translation_6, GeomAPI_Shape.EDGE, [4]) +model.testNbSubShapes(Translation_6, GeomAPI_Shape.VERTEX, [8]) +model.testResultsVolumes(Translation_6, [109.154152964914914]) +midPoint = Translation_6.defaultResult().shape().middlePoint() +assert(midPoint.distance(REFERENCE[index]) < TOLERANCE) +index += 1 + +Recover_4 = model.addRecover(Part_1_doc, Translation_6, [Recover_3.result()]) +Translation_7 = model.addTranslation(Part_1_doc, [model.selection("SHELL", "Recover_4_1_5")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_7, 1) +model.testNbSubResults(Translation_7, [0]) +model.testNbSubShapes(Translation_7, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_7, GeomAPI_Shape.FACE, [2]) +model.testNbSubShapes(Translation_7, GeomAPI_Shape.EDGE, [8]) +model.testNbSubShapes(Translation_7, GeomAPI_Shape.VERTEX, [16]) +model.testResultsVolumes(Translation_7, [182.822012116]) +midPoint = Translation_7.defaultResult().shape().middlePoint() +assert(midPoint.distance(REFERENCE[index]) < TOLERANCE) +index += 1 + +Recover_5 = model.addRecover(Part_1_doc, Translation_7, [Recover_4.result()]) +Translation_8 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Recover_5_1_6")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_8, 1) +model.testNbSubResults(Translation_8, [0]) +model.testNbSubShapes(Translation_8, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Translation_8, GeomAPI_Shape.FACE, [6]) +model.testNbSubShapes(Translation_8, GeomAPI_Shape.EDGE, [24]) +model.testNbSubShapes(Translation_8, GeomAPI_Shape.VERTEX, [48]) +model.testResultsVolumes(Translation_8, [1000]) +midPoint = Translation_8.defaultResult().shape().middlePoint() +assert(midPoint.distance(REFERENCE[index]) < TOLERANCE) +index += 1 + +Recover_6 = model.addRecover(Part_1_doc, Translation_8, [Recover_5.result()]) +Translation_9 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Recover_6_1_7")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_9, 1) +model.testNbSubResults(Translation_9, [3]) +model.testNbSubShapes(Translation_9, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Translation_9, GeomAPI_Shape.FACE, [17]) +model.testNbSubShapes(Translation_9, GeomAPI_Shape.EDGE, [66]) +model.testNbSubShapes(Translation_9, GeomAPI_Shape.VERTEX, [132]) +model.testResultsVolumes(Translation_9, [1589.0486226]) +midPoint = Translation_9.defaultResult().shape().middlePoint() +assert(midPoint.distance(REFERENCE[index]) < TOLERANCE) +index += 1 + +Recover_7 = model.addRecover(Part_1_doc, Translation_9, [Recover_6.result()]) +Translation_10 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Recover_7_1_8")], model.selection("EDGE", "PartSet/OZ"), DISTANCE) +model.testNbResults(Translation_10, 1) +model.testNbSubResults(Translation_10, [3]) +model.testNbSubShapes(Translation_10, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Translation_10, GeomAPI_Shape.FACE, [18]) +model.testNbSubShapes(Translation_10, GeomAPI_Shape.EDGE, [72]) +model.testNbSubShapes(Translation_10, GeomAPI_Shape.VERTEX, [144]) +model.testResultsVolumes(Translation_10, [3000]) +midPoint = Translation_10.defaultResult().shape().middlePoint() +assert(midPoint.distance(REFERENCE[index]) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_1.py b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_1.py new file mode 100644 index 000000000..8287a389e --- /dev/null +++ b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_1.py @@ -0,0 +1,119 @@ +# 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 = 10 +TOLERANCE = 1.e-7 +REFERENCE = [] +for ind in range(0, Compound_2.result().numberOfSubs()): + p = Compound_2.result().subResult(ind).resultSubShapePair()[0].shape().middlePoint() + REFERENCE.append(p) + +def assertResult(theFeature): + model.testNbResults(theFeature, 1) + model.testNbSubResults(theFeature, [3]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.SOLID, [10]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [47]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [162]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [324]) + model.testResultsVolumes(theFeature, [14319.99602674256]) + + 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() +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], axis = model.selection("EDGE", "PartSet/OX"), distance = DISTANCE, keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(Translation_1.feature().error() != "") + +model.begin() +Translation_1.setMainObjects([model.selection("COMPSOLID", "Compound_2_1_1")]) +REFERENCE[0].setX(REFERENCE[0].x() + DISTANCE) +assertResult(Translation_1) + +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_1_1_2_1")], axis = model.selection("EDGE", "PartSet/OY"), distance = DISTANCE, keepSubResults = True) +REFERENCE[1].setY(REFERENCE[1].y() + DISTANCE / 2) +assertResult(Translation_2) + +Translation_3 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_2_1_3")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +REFERENCE[2].setZ(REFERENCE[2].z() + DISTANCE) +assertResult(Translation_3) + +Translation_4 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_3_1_1_1"), model.selection("SOLID", "Translation_3_1_2_2"), model.selection("SOLID", "Translation_3_1_3")], axis = model.selection("EDGE", "PartSet/OZ"), distance = -DISTANCE, keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(Translation_4.feature().error() != "") + +model.begin() +Translation_4.setMainObjects([model.selection("COMPSOLID", "Translation_3_1_1"), model.selection("SOLID", "Translation_3_1_2_2"), model.selection("SOLID", "Translation_3_1_3")]) +REFERENCE[0].setZ(REFERENCE[0].z() - DISTANCE) +REFERENCE[1].setZ(REFERENCE[1].z() - DISTANCE / 2) +REFERENCE[2].setZ(REFERENCE[2].z() - DISTANCE) +assertResult(Translation_4) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_2.py b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_2.py new file mode 100644 index 000000000..9456c5482 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_2.py @@ -0,0 +1,121 @@ +# 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() + +DX = 15 +DY = 20 +DZ = 25 +TOLERANCE = 1.e-7 +REFERENCE = [] +for ind in range(0, Compound_2.result().numberOfSubs()): + p = Compound_2.result().subResult(ind).resultSubShapePair()[0].shape().middlePoint() + REFERENCE.append(p) + +def assertResult(theFeature): + model.testNbResults(theFeature, 1) + model.testNbSubResults(theFeature, [3]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.SOLID, [10]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [47]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [162]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [324]) + model.testResultsVolumes(theFeature, [14319.99602674256]) + + 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() +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], vector = [DX, 0, 0], keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(Translation_1.feature().error() != "") + +model.begin() +Translation_1.setMainObjects([model.selection("COMPSOLID", "Compound_2_1_1")]) +REFERENCE[0].setX(REFERENCE[0].x() + DX) +assertResult(Translation_1) + +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_1_1_2_1")], vector = [0, DY, 0], keepSubResults = True) +REFERENCE[1].setY(REFERENCE[1].y() + DY / 2) +assertResult(Translation_2) + +Translation_3 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_2_1_3")], vector = [0, 0, DZ], keepSubResults = True) +REFERENCE[2].setZ(REFERENCE[2].z() + DZ) +assertResult(Translation_3) + +Translation_4 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_3_1_1_1"), model.selection("SOLID", "Translation_3_1_2_2"), model.selection("SOLID", "Translation_3_1_3")], vector = [DX, DY, DZ], keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(Translation_4.feature().error() != "") + +model.begin() +Translation_4.setMainObjects([model.selection("COMPSOLID", "Translation_3_1_1"), model.selection("SOLID", "Translation_3_1_2_2"), model.selection("SOLID", "Translation_3_1_3")]) +REFERENCE = [GeomAPI_Pnt(REFERENCE[0].x() + DX, REFERENCE[0].y() + DY, REFERENCE[0].z() + DZ), + GeomAPI_Pnt(REFERENCE[1].x() + DX / 2, REFERENCE[1].y() + DY / 2, REFERENCE[1].z() + DZ / 2), + GeomAPI_Pnt(REFERENCE[2].x() + DX, REFERENCE[2].y() + DY, REFERENCE[2].z() + DZ)] +assertResult(Translation_4) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_3.py b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_3.py new file mode 100644 index 000000000..eef06201d --- /dev/null +++ b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_3.py @@ -0,0 +1,120 @@ +# 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 * + +MAJOR_AXIS = 30 + +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(), MAJOR_AXIS) +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 +REFERENCE = [] +for ind in range(0, Compound_2.result().numberOfSubs()): + p = Compound_2.result().subResult(ind).resultSubShapePair()[0].shape().middlePoint() + REFERENCE.append(p) + +def assertResult(theFeature): + model.testNbResults(theFeature, 1) + model.testNbSubResults(theFeature, [3]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.SOLID, [10]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [47]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [162]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [324]) + model.testResultsVolumes(theFeature, [14319.99602674256]) + + 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() +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], startPoint = model.selection("VERTEX", "Sketch_1/SketchEllipse_1_ellipse_major_axis_start_point"), endPoint = model.selection("VERTEX", "Sketch_1/SketchEllipse_1_major_axis_EndVertex"), keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(Translation_1.feature().error() != "") + +model.begin() +Translation_1.setMainObjects([model.selection("COMPSOLID", "Compound_2_1_1")]) +REFERENCE[0].setX(REFERENCE[0].x() + MAJOR_AXIS) +assertResult(Translation_1) + +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_1_1_2_1")], startPoint = model.selection("VERTEX", "Sketch_1/SketchEllipse_1_ellipse_major_axis_start_point"), endPoint = model.selection("VERTEX", "Sketch_1/SketchEllipse_1_major_axis_EndVertex"), keepSubResults = True) +REFERENCE[1].setX(REFERENCE[1].x() + MAJOR_AXIS / 2) +assertResult(Translation_2) + +Translation_3 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_2_1_3")], startPoint = model.selection("VERTEX", "Sketch_1/SketchEllipse_1_ellipse_major_axis_start_point"), endPoint = model.selection("VERTEX", "Sketch_1/SketchEllipse_1_major_axis_EndVertex"), keepSubResults = True) +REFERENCE[2].setX(REFERENCE[2].x() + MAJOR_AXIS) +assertResult(Translation_3) + +Translation_4 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_3_1_1_1"), model.selection("SOLID", "Translation_3_1_2_2"), model.selection("SOLID", "Translation_3_1_3")], startPoint = model.selection("VERTEX", "Sketch_1/SketchEllipse_1_major_axis_EndVertex"), endPoint = model.selection("VERTEX", "Sketch_1/SketchEllipse_1_ellipse_major_axis_start_point"), keepSubResults = True) +model.end() +# selection of a compsolid part is prohibited +assert(Translation_4.feature().error() != "") + +model.begin() +Translation_4.setMainObjects([model.selection("COMPSOLID", "Translation_3_1_1"), model.selection("SOLID", "Translation_3_1_2_2"), model.selection("SOLID", "Translation_3_1_3")]) +REFERENCE[0].setX(REFERENCE[0].x() - MAJOR_AXIS) +REFERENCE[1].setX(REFERENCE[1].x() - MAJOR_AXIS / 2) +REFERENCE[2].setX(REFERENCE[2].x() - MAJOR_AXIS) +assertResult(Translation_4) + +model.end() + +assert(model.checkPythonDump(model.CHECK_NAMING)) diff --git a/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_4.py b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_4.py new file mode 100644 index 000000000..37a86e7a6 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_4.py @@ -0,0 +1,187 @@ +# Copyright (C) 2020 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from salome.shaper import model +from GeomAPI import * + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchPoint_1 = Sketch_1.addPoint(44.29784155360136, 17.09942588468031) +SketchArc_1 = Sketch_1.addArc(44.29784155360136, 17.09942588468031, 47.1668727423061, 12.27945348765633, 45.38299232715926, 22.60269052200972, False) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchArc_1.center()) +SketchLine_1 = Sketch_1.addLine(42.5764228403785, 22.14892077680068, 39.70739165167375, 16.41085839939117) +SketchLine_2 = Sketch_1.addLine(39.70739165167375, 16.41085839939117, 43.03546783057126, 12.04993099255995) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(28.57555063949931, 12.96802097294547, 15.72229091410204, 12.96802097294547) +SketchLine_4 = Sketch_1.addLine(15.72229091410204, 12.96802097294547, 15.72229091410204, 21.46035329151154) +SketchLine_5 = Sketch_1.addLine(15.72229091410204, 21.46035329151154, 28.57555063949931, 21.46035329151154) +SketchLine_6 = Sketch_1.addLine(28.57555063949931, 21.46035329151154, 28.57555063949931, 12.96802097294547) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_4.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_5.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_6.result()) +SketchLine_7 = Sketch_1.addLine(-10.67279602198167, 14.78814178154371, -28.34602814440294, 14.78814178154371) +SketchLine_8 = Sketch_1.addLine(-28.34602814440294, 14.78814178154371, -28.34602814440294, 25.13271321305362) +SketchLine_9 = Sketch_1.addLine(-28.34602814440294, 25.13271321305362, -10.67279602198167, 25.13271321305362) +SketchLine_10 = Sketch_1.addLine(-10.67279602198167, 25.13271321305362, -10.67279602198167, 14.78814178154371) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_10.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint()) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint()) +SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_7.result()) +SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_8.result()) +SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_9.result()) +SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_10.result()) +SketchLine_11 = Sketch_1.addLine(-17.67323212242127, 25.13271321305362, -21.80463703415611, 14.78814178154371) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_11.startPoint(), SketchLine_9.result()) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_11.endPoint(), SketchLine_7.result()) +model.do() +Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchArc_1")], False) +Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchArc_1_2")], False) +Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1"), model.selection("EDGE", "Sketch_1/SketchLine_2")], False) +Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_6r-SketchLine_5r-SketchLine_4r-SketchLine_3r")]) +Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_10r-SketchLine_9r-SketchLine_11f-SketchLine_7r"), model.selection("FACE", "Sketch_1/Face-SketchLine_11r-SketchLine_9r-SketchLine_8r-SketchLine_7r")]) +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 50) +Box_2 = model.addBox(Part_1_doc, 10, 10, 10) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10) +Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_2_1"), model.selection("SOLID", "Cylinder_1_1")], keepSubResults = True) +Box_3 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OY"), 50) +AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Translation_2_1")], model.selection("EDGE", "PartSet/OZ"), 30, 3) +model.end() + +DISTANCE = 10 +TOLERANCE = 1.e-7 + +model.begin() +Translation_3 = model.addTranslation(Part_1_doc, [model.selection("VERTEX", "Vertex_1_1")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +model.testNbResults(Translation_3, 1) +model.testNbSubResults(Translation_3, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.EDGE, [0]) +model.testNbSubShapes(Translation_3, GeomAPI_Shape.VERTEX, [1]) +model.testResultsVolumes(Translation_3, [0]) +refPoint = Vertex_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_3.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_4 = model.addTranslation(Part_1_doc, [model.selection("EDGE", "Edge_1_1")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +model.testNbResults(Translation_4, 1) +model.testNbSubResults(Translation_4, [0]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.EDGE, [1]) +model.testNbSubShapes(Translation_4, GeomAPI_Shape.VERTEX, [2]) +model.testResultsVolumes(Translation_4, [0]) +refPoint = Edge_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_4.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_5 = model.addTranslation(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +model.testNbResults(Translation_5, 1) +model.testNbSubResults(Translation_5, [0]) +model.testNbSubShapes(Translation_5, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_5, GeomAPI_Shape.FACE, [0]) +model.testNbSubShapes(Translation_5, GeomAPI_Shape.EDGE, [2]) +model.testNbSubShapes(Translation_5, GeomAPI_Shape.VERTEX, [4]) +model.testResultsVolumes(Translation_5, [0]) +refPoint = Wire_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_5.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_6 = model.addTranslation(Part_1_doc, [model.selection("FACE", "Face_1_1")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +model.testNbResults(Translation_6, 1) +model.testNbSubResults(Translation_6, [0]) +model.testNbSubShapes(Translation_6, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_6, GeomAPI_Shape.FACE, [1]) +model.testNbSubShapes(Translation_6, GeomAPI_Shape.EDGE, [4]) +model.testNbSubShapes(Translation_6, GeomAPI_Shape.VERTEX, [8]) +model.testResultsVolumes(Translation_6, [109.154152964914914]) +refPoint = Face_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_6.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_7 = model.addTranslation(Part_1_doc, [model.selection("SHELL", "Shell_1_1")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +model.testNbResults(Translation_7, 1) +model.testNbSubResults(Translation_7, [0]) +model.testNbSubShapes(Translation_7, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Translation_7, GeomAPI_Shape.FACE, [2]) +model.testNbSubShapes(Translation_7, GeomAPI_Shape.EDGE, [8]) +model.testNbSubShapes(Translation_7, GeomAPI_Shape.VERTEX, [16]) +model.testResultsVolumes(Translation_7, [182.822012116]) +refPoint = Shell_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_7.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_8 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +model.testNbResults(Translation_8, 1) +model.testNbSubResults(Translation_8, [0]) +model.testNbSubShapes(Translation_8, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Translation_8, GeomAPI_Shape.FACE, [6]) +model.testNbSubShapes(Translation_8, GeomAPI_Shape.EDGE, [24]) +model.testNbSubShapes(Translation_8, GeomAPI_Shape.VERTEX, [48]) +model.testResultsVolumes(Translation_8, [1000]) +refPoint = Translation_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_8.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_9 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_1_1")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +model.testNbResults(Translation_9, 1) +model.testNbSubResults(Translation_9, [3]) +model.testNbSubShapes(Translation_9, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Translation_9, GeomAPI_Shape.FACE, [17]) +model.testNbSubShapes(Translation_9, GeomAPI_Shape.EDGE, [66]) +model.testNbSubShapes(Translation_9, GeomAPI_Shape.VERTEX, [132]) +model.testResultsVolumes(Translation_9, [1589.0486226]) +refPoint = Partition_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_9.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +Translation_10 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "AngularCopy_1_1")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +model.testNbResults(Translation_10, 1) +model.testNbSubResults(Translation_10, [3]) +model.testNbSubShapes(Translation_10, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Translation_10, GeomAPI_Shape.FACE, [18]) +model.testNbSubShapes(Translation_10, GeomAPI_Shape.EDGE, [72]) +model.testNbSubShapes(Translation_10, GeomAPI_Shape.VERTEX, [144]) +model.testResultsVolumes(Translation_10, [3000]) +refPoint = AngularCopy_1.defaultResult().shape().middlePoint() +refPoint.setZ(refPoint.z() + DISTANCE) +midPoint = Translation_10.defaultResult().shape().middlePoint() +assert(midPoint.distance(refPoint) < TOLERANCE) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_5.py b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_5.py new file mode 100644 index 000000000..eef8f5f46 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestTranslation_MultiLevelCompound_v95_5.py @@ -0,0 +1,131 @@ +# 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() + +# collect reference data +DISTANCE = 10 +REFERENCE = [] +TOLERANCE = 1.e-7 +for ind in range(0, Compound_1.result().numberOfSubs()): + p = Compound_1.result().subResult(ind).resultSubShapePair()[1].middlePoint() + REFERENCE.append(p) + +def assertResult(theFeature, theNbMoved): + model.testNbResults(theFeature, 1) + model.testNbSubResults(theFeature, [8]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.SOLID, [7]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.FACE, [44]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.EDGE, [177]) + model.testNbSubShapes(theFeature, GeomAPI_Shape.VERTEX, [355]) + model.testResultsVolumes(theFeature, [5589.0486226]) + + 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) + 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() +Translation_3 = model.addTranslation(Part_1_doc, [model.selection("VERTEX", "Compound_1_1_1")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +assertResult(Translation_3, 1) + +Translation_4 = model.addTranslation(Part_1_doc, [model.selection("EDGE", "Translation_3_1_2")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +assertResult(Translation_4, 2) + +Translation_5 = model.addTranslation(Part_1_doc, [model.selection("WIRE", "Translation_4_1_3")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +assertResult(Translation_5, 3) + +Translation_6 = model.addTranslation(Part_1_doc, [model.selection("FACE", "Translation_5_1_4")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +assertResult(Translation_6, 4) + +Translation_7 = model.addTranslation(Part_1_doc, [model.selection("SHELL", "Translation_6_1_5")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +assertResult(Translation_7, 5) + +Translation_8 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_7_1_6")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +assertResult(Translation_8, 6) + +Translation_9 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Translation_8_1_7")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +assertResult(Translation_9, 7) + +Translation_10 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Translation_9_1_8")], axis = model.selection("EDGE", "PartSet/OZ"), distance = DISTANCE, keepSubResults = True) +assertResult(Translation_10, 8) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.cpp index 35411e405..34aced8d6 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.cpp @@ -42,7 +42,7 @@ GeomAlgoAPI_Rotation::GeomAlgoAPI_Rotation(std::shared_ptr theSou } GeomTrsfPtr aTrsf(new GeomAPI_Trsf); - aTrsf->setRotation(theAxis, theAngle / 180.0 * M_PI); + aTrsf->setRotation(theAxis, theAngle); build(theSourceShape, aTrsf); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Transform.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Transform.cpp index 389f87e05..1c3aefa09 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Transform.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Transform.cpp @@ -38,7 +38,7 @@ void GeomAlgoAPI_Transform::build(std::shared_ptr theSourceShape, std::shared_ptr theTrsf) { if (!theSourceShape || !theTrsf) { - myError = "Transformation :: incorrect input data"; + myError = "Transformation :: incorrect input data."; return; } diff --git a/test.API/SHAPER/Transformations/TestAPI_Translation.py b/test.API/SHAPER/Transformations/TestAPI_Translation.py index 02bd31618..c9c0f4c3e 100644 --- a/test.API/SHAPER/Transformations/TestAPI_Translation.py +++ b/test.API/SHAPER/Transformations/TestAPI_Translation.py @@ -122,19 +122,19 @@ except myExcept as ec: try: Translation_22 = shaperpy.makeTranslation(None, ax1, 15.) except myExcept as ec: - assert(ec.what() == "Translation builder :: source shape is not valid.") + assert(ec.what() == "Transformation :: incorrect input data.") try: Translation_23 = shaperpy.makeTranslation(None, 10., 20., 15.) except myExcept as ec: - assert(ec.what() == "Translation builder :: source shape is not valid.") + assert(ec.what() == "Transformation :: incorrect input data.") try: Translation_24 = shaperpy.makeTranslation(None, pnt1, pnt2) except myExcept as ec: - assert(ec.what() == "Translation builder :: source shape is invalid.") + assert(ec.what() == "Transformation :: incorrect input data.") try: Translation_25 = shaperpy.makeTranslation(shape(), ax1, 15.) except myExcept as ec: - assert(ec.what() == "Translation builder :: source shape does not contain any actual shape.") + assert(ec.what() == "Transformation :: source shape does not contain any actual shape.")