From 805f2d295f215730fb68e10a0fc0dd910cff557f Mon Sep 17 00:00:00 2001 From: Clarisse Genrault Date: Tue, 14 Feb 2017 10:47:30 +0100 Subject: [PATCH] Added "Multitranslation" feature. --- src/FeaturesAPI/CMakeLists.txt | 2 + .../FeaturesAPI_MultiTranslation.cpp | 178 ++++++++++ .../FeaturesAPI_MultiTranslation.h | 125 +++++++ src/FeaturesPlugin/CMakeLists.txt | 3 + .../FeaturesPlugin_MultiTranslation.cpp | 328 ++++++++++++++++++ .../FeaturesPlugin_MultiTranslation.h | 115 ++++++ src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp | 5 +- src/FeaturesPlugin/icons/multitranslation.png | Bin 0 -> 642 bytes .../multitranslation_widget.xml | 60 ++++ src/FeaturesPlugin/plugin-Features.xml | 9 +- src/PythonAPI/model/features/__init__.py | 1 + 11 files changed, 823 insertions(+), 3 deletions(-) create mode 100644 src/FeaturesAPI/FeaturesAPI_MultiTranslation.cpp create mode 100644 src/FeaturesAPI/FeaturesAPI_MultiTranslation.h create mode 100644 src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp create mode 100644 src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h create mode 100644 src/FeaturesPlugin/icons/multitranslation.png create mode 100644 src/FeaturesPlugin/multitranslation_widget.xml diff --git a/src/FeaturesAPI/CMakeLists.txt b/src/FeaturesAPI/CMakeLists.txt index af088777a..b8ad3fe09 100644 --- a/src/FeaturesAPI/CMakeLists.txt +++ b/src/FeaturesAPI/CMakeLists.txt @@ -9,6 +9,7 @@ SET(PROJECT_HEADERS FeaturesAPI_Extrusion.h FeaturesAPI_ExtrusionBoolean.h FeaturesAPI_Intersection.h + FeaturesAPI_MultiTranslation.h FeaturesAPI_Partition.h FeaturesAPI_Pipe.h FeaturesAPI_Placement.h @@ -28,6 +29,7 @@ SET(PROJECT_SOURCES FeaturesAPI_Extrusion.cpp FeaturesAPI_ExtrusionBoolean.cpp FeaturesAPI_Intersection.cpp + FeaturesAPI_MultiTranslation.cpp FeaturesAPI_Partition.cpp FeaturesAPI_Pipe.cpp FeaturesAPI_Placement.cpp diff --git a/src/FeaturesAPI/FeaturesAPI_MultiTranslation.cpp b/src/FeaturesAPI/FeaturesAPI_MultiTranslation.cpp new file mode 100644 index 000000000..6754b0f48 --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_MultiTranslation.cpp @@ -0,0 +1,178 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: FeaturesAPI_MultiTranslation.cpp +// Created: 09 Feb 2017 +// Author: Clarisse Genrault (CEA) + +#include + +#include +#include + +//================================================================================================== +FeaturesAPI_MultiTranslation::FeaturesAPI_MultiTranslation( + const std::shared_ptr& theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +//================================================================================================== +FeaturesAPI_MultiTranslation::FeaturesAPI_MultiTranslation( + const std::shared_ptr& theFeature, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theStep, + const ModelHighAPI_Integer& theNumber) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + fillAttribute(theMainObjects, mainObjects()); + fillAttribute(theAxisObject, firstAxisObject()); + fillAttribute(theStep, firstStep()); + fillAttribute("",useSecondDir()); + setFirstNumber(theNumber); + } +} + +//================================================================================================== +FeaturesAPI_MultiTranslation::FeaturesAPI_MultiTranslation( + const std::shared_ptr& theFeature, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theFirstAxisObject, + const ModelHighAPI_Double& theFirstStep, + const ModelHighAPI_Integer& theFirstNumber, + const ModelHighAPI_Selection& theSecondAxisObject, + const ModelHighAPI_Double& theSecondStep, + const ModelHighAPI_Integer& theSecondNumber) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + fillAttribute(theMainObjects, mainObjects()); + fillAttribute(theFirstAxisObject, firstAxisObject()); + fillAttribute(theFirstStep, firstStep()); + fillAttribute(theFirstNumber, firstNumber()); + fillAttribute(theSecondAxisObject, secondAxisObject()); + fillAttribute(theSecondStep, secondStep()); + fillAttribute("true",useSecondDir()); + setSecondNumber(theSecondNumber); + } +} + +//================================================================================================== +FeaturesAPI_MultiTranslation::~FeaturesAPI_MultiTranslation() +{ +} + +//================================================================================================== +void FeaturesAPI_MultiTranslation::setMainObjects( + const std::list& theMainObjects) +{ + fillAttribute(theMainObjects, mainObjects()); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_MultiTranslation::setFirstAxisAndDistance( + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theDistance) +{ + fillAttribute(theAxisObject, firstAxisObject()); + fillAttribute(theDistance, firstStep()); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_MultiTranslation::setSecondAxisAndDistance( + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theDistance) +{ + fillAttribute(theAxisObject, secondAxisObject()); + fillAttribute(theDistance, secondStep()); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_MultiTranslation::setFirstNumber(const ModelHighAPI_Integer& theFirstNumber) +{ + fillAttribute(theFirstNumber, firstNumber()); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_MultiTranslation::setSecondNumber(const ModelHighAPI_Integer& theSecondNumber) +{ + fillAttribute(theSecondNumber, secondNumber()); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_MultiTranslation::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + AttributeSelectionListPtr anAttrObjects = + aBase->selectionList(FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID()); + theDumper << aBase << " = model.addMultiTranslation(" << aDocName << ", " << anAttrObjects; + + AttributeSelectionPtr anAttrFirstAxis = + aBase->selection(FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID()); + AttributeDoublePtr anAttrFirstStep = + aBase->real(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID()); + AttributeIntegerPtr anAttrFirstNumber = + aBase->integer(FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID()); + theDumper << ", " << anAttrFirstAxis << ", " << anAttrFirstStep; + theDumper << ", " << anAttrFirstNumber; + + if (aBase->string(FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID())->isInitialized() + && !aBase->string(FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID())->value().empty()) { + AttributeSelectionPtr anAttrSecondAxis = + aBase->selection(FeaturesPlugin_MultiTranslation::AXIS_SECOND_DIR_ID()); + AttributeDoublePtr anAttrSecondStep = + aBase->real(FeaturesPlugin_MultiTranslation::STEP_SECOND_DIR_ID()); + AttributeIntegerPtr anAttrSecondNumber = + aBase->integer(FeaturesPlugin_MultiTranslation::NB_COPIES_SECOND_DIR_ID()); + theDumper << ", " << anAttrSecondAxis << ", " << anAttrSecondStep; + theDumper << ", " << anAttrSecondStep; + } + + theDumper << ")" << std::endl; +} + +//================================================================================================== +MultiTranslationPtr addMultiTranslation(const std::shared_ptr& thePart, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theStep, + const ModelHighAPI_Integer& theNumber) +{ + std::shared_ptr aFeature = + thePart->addFeature(FeaturesAPI_MultiTranslation::ID()); + return MultiTranslationPtr(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects, + theAxisObject, theStep, theNumber)); +} + +//================================================================================================== +MultiTranslationPtr addMultiTranslation(const std::shared_ptr& thePart, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theFirstAxisObject, + const ModelHighAPI_Double& theFirstStep, + const ModelHighAPI_Integer& theFirstNumber, + const ModelHighAPI_Selection& theSecondAxisObject, + const ModelHighAPI_Double& theSecondStep, + const ModelHighAPI_Integer& theSecondNumber) +{ + std::shared_ptr aFeature = + thePart->addFeature(FeaturesAPI_MultiTranslation::ID()); + return MultiTranslationPtr(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects, + theFirstAxisObject, theFirstStep, + theFirstNumber, + theSecondAxisObject, theSecondStep, + theSecondNumber)); +} diff --git a/src/FeaturesAPI/FeaturesAPI_MultiTranslation.h b/src/FeaturesAPI/FeaturesAPI_MultiTranslation.h new file mode 100644 index 000000000..a06c71f2f --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_MultiTranslation.h @@ -0,0 +1,125 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: FeaturesAPI_MultiTranslation.h +// Created: 09 Feb 2017 +// Author: Clarisse Genrault (CEA) + +#ifndef FEATURESAPI_MULTITRANSLATION_H_ +#define FEATURESAPI_MULTITRANSLATION_H_ + +#include "FeaturesAPI.h" + +#include + +#include +#include + +class ModelHighAPI_Double; +class ModelHighAPI_Dumper; +class ModelHighAPI_Integer; +class ModelHighAPI_Selection; + +/// \class FeaturesAPI_MultiTranslation +/// \ingroup CPPHighAPI +/// \brief Interface for Translation feature. +class FeaturesAPI_MultiTranslation: public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + FEATURESAPI_EXPORT + explicit FeaturesAPI_MultiTranslation(const std::shared_ptr& theFeature); + + /// Constructor with values. + FEATURESAPI_EXPORT + explicit FeaturesAPI_MultiTranslation(const std::shared_ptr& theFeature, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theStep, + const ModelHighAPI_Integer& theNumber); + + /// Constructor with values. + FEATURESAPI_EXPORT + explicit FeaturesAPI_MultiTranslation(const std::shared_ptr& theFeature, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theFirstAxisObject, + const ModelHighAPI_Double& theFirstStep, + const ModelHighAPI_Integer& theFirstNumber, + const ModelHighAPI_Selection& theSecondAxisObject, + const ModelHighAPI_Double& theSecondStep, + const ModelHighAPI_Integer& theSecondNumber); + + /// Destructor. + FEATURESAPI_EXPORT + virtual ~FeaturesAPI_MultiTranslation(); + + INTERFACE_8(FeaturesPlugin_MultiTranslation::ID(), + mainObjects, FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID(), + ModelAPI_AttributeSelectionList, /** Main objects */, + firstAxisObject, FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID(), + ModelAPI_AttributeSelection, /** First axis object */, + firstStep, FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID(), + ModelAPI_AttributeDouble, /** First step */, + firstNumber, FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID(), + ModelAPI_AttributeInteger, /** First number of copies */, + useSecondDir, FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID(), + ModelAPI_AttributeString, /** Use the second dir */, + secondAxisObject, FeaturesPlugin_MultiTranslation::AXIS_SECOND_DIR_ID(), + ModelAPI_AttributeSelection, /** Second axis object */, + secondStep, FeaturesPlugin_MultiTranslation::STEP_SECOND_DIR_ID(), + ModelAPI_AttributeDouble, /** Second step */, + secondNumber, FeaturesPlugin_MultiTranslation::NB_COPIES_SECOND_DIR_ID(), + ModelAPI_AttributeInteger, /** Second number of copies */ + ) + + /// Set main objects. + FEATURESAPI_EXPORT + void setMainObjects(const std::list& theMainObjects); + + /// Modify CreationMethod, axis_first_dir, step_first_dir attributes of the feature. + FEATURESAPI_EXPORT + void setFirstAxisAndDistance(const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theDistance); + + /// Modify CreationMethod, axis_second_dir, step_second_dir attributes of the feature. + FEATURESAPI_EXPORT + void setSecondAxisAndDistance(const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theDistance); + + /// Modify CreationMethod, nb_first_dir attribute of the feature. + FEATURESAPI_EXPORT + void setFirstNumber(const ModelHighAPI_Integer& theFirstNumber); + + /// Modify CreationMethod, nb_second_dir attribute of the feature. + FEATURESAPI_EXPORT + void setSecondNumber(const ModelHighAPI_Integer& theSecondNumber); + + /// Dump wrapped feature + FEATURESAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; +}; + +/// Pointer on Translation object. +typedef std::shared_ptr MultiTranslationPtr; + +/// \ingroup CPPHighAPI +/// \brief Create MultiTranslation feature. +FEATURESAPI_EXPORT +MultiTranslationPtr addMultiTranslation(const std::shared_ptr& thePart, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theStep, + const ModelHighAPI_Integer& theNumber); + +/// \ingroup CPPHighAPI +/// \brief Create MultiTranslation feature. +FEATURESAPI_EXPORT +MultiTranslationPtr addMultiTranslation(const std::shared_ptr& thePart, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theFirstAxisObject, + const ModelHighAPI_Double& theFirstStep, + const ModelHighAPI_Integer& theFirstNumber, + const ModelHighAPI_Selection& theSecondAxisObject, + const ModelHighAPI_Double& theSecondStep, + const ModelHighAPI_Integer& theSecondNumber); + +#endif // FEATURESAPI_MULTITRANSLATION_H_ diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index cf821fd9e..b36b59ff0 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -31,6 +31,7 @@ SET(PROJECT_HEADERS FeaturesPlugin_Tools.h FeaturesPlugin_Symmetry.h FeaturesPlugin_Scale.h + FeaturesPlugin_MultiTranslation.h ) SET(PROJECT_SOURCES @@ -60,6 +61,7 @@ SET(PROJECT_SOURCES FeaturesPlugin_Tools.cpp FeaturesPlugin_Symmetry.cpp FeaturesPlugin_Scale.cpp + FeaturesPlugin_MultiTranslation.cpp ) SET(XML_RESOURCES @@ -82,6 +84,7 @@ SET(XML_RESOURCES union_widget.xml symmetry_widget.xml scale_widget.xml + multitranslation_widget.xml ) SET(TEXT_RESOURCES diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp new file mode 100644 index 000000000..d92efbab6 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp @@ -0,0 +1,328 @@ +// Copyright (C) 2014-201x CEA/DEN, EDF R&D + +// File: FeaturesPlugin_MultiTranslation.cpp +// Created: 30 Jan 2017 +// Author: Clarisse Genrault (CEA) + +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +//================================================================================================= +FeaturesPlugin_MultiTranslation::FeaturesPlugin_MultiTranslation() +{ +} + +//================================================================================================= +void FeaturesPlugin_MultiTranslation::initAttributes() +{ + AttributeSelectionListPtr aSelection = + std::dynamic_pointer_cast(data()->addAttribute( + FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID(), + ModelAPI_AttributeSelectionList::typeId())); + + data()->addAttribute(FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID(), + ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID(), + ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID(), + ModelAPI_AttributeInteger::typeId()); + + data()->addAttribute(FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID(), + ModelAPI_AttributeString::typeId()); + data()->addAttribute(FeaturesPlugin_MultiTranslation::AXIS_SECOND_DIR_ID(), + ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(FeaturesPlugin_MultiTranslation::STEP_SECOND_DIR_ID(), + ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(FeaturesPlugin_MultiTranslation::NB_COPIES_SECOND_DIR_ID(), + ModelAPI_AttributeInteger::typeId()); +} + +//================================================================================================= +void FeaturesPlugin_MultiTranslation::execute() +{ + std::string useSecondDir = string(FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID())->value(); + if(!useSecondDir.empty()) { + performTwoDirection(); + } else { + performOneDirection(); + } +} + +//================================================================================================= +void FeaturesPlugin_MultiTranslation::performOneDirection() +{ + // Getting objects. + ListOfShape anObjects; + std::list aContextes; + AttributeSelectionListPtr anObjectsSelList = + selectionList(FeaturesPlugin_MultiTranslation::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 + eraseResults(); + return; + } + anObjects.push_back(anObject); + aContextes.push_back(anObjectAttr->context()); + } + + //Getting axis. + std::shared_ptr anAxis; + std::shared_ptr anEdge; + std::shared_ptr anObjRef = + selection(FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID()); + if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->value())); + } else if (anObjRef && !anObjRef->value() && anObjRef->context() && + anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->context()->shape())); + } + if(anEdge) { + anAxis = std::shared_ptr(new GeomAPI_Ax1(anEdge->line()->location(), + anEdge->line()->direction())); + } + + // Getting step. + double aStep = real(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID())->value(); + + // Getting number of copies. + int nbCopies = + integer(FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID())->value(); + + // Moving each object. + + int aResultIndex = 0; + std::list::iterator aContext = aContextes.begin(); + for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); + anObjectsIt++, aContext++) { + std::shared_ptr aBaseShape = *anObjectsIt; + + ListOfShape aListOfShape; + std::list > aListOfTranslationAlgo; + + for (int i=0; i aTranslationAlgo( + new GeomAlgoAPI_Translation(aBaseShape, anAxis, i*aStep)); + + if (!aTranslationAlgo->check()) { + setError(aTranslationAlgo->getError()); + break; + } + + aTranslationAlgo->build(); + + // Checking that the algorithm worked properly. + if (!aTranslationAlgo->isDone()) { + static const std::string aFeatureError = "Error : Multitranslation algorithm failed."; + setError(aFeatureError); + break; + } + if (aTranslationAlgo->shape()->isNull()) { + static const std::string aShapeError = "Error : Resulting shape is null."; + setError(aShapeError); + break; + } + if (!aTranslationAlgo->isValid()) { + static const std::string aFeatureError = "Error : Resulting shape in not valid."; + setError(aFeatureError); + break; + } + aListOfShape.push_back(aTranslationAlgo->shape()); + aListOfTranslationAlgo.push_back(aTranslationAlgo); + } + std::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + aResultBody->storeModified(aBaseShape, aCompound); + loadNamingDS(aListOfTranslationAlgo, aResultBody, aBaseShape); + + setResult(aResultBody, aResultIndex); + aResultIndex++; + } + + // Remove the rest results if there were produced in the previous pass. + removeResults(aResultIndex); +} + +//================================================================================================= +void FeaturesPlugin_MultiTranslation::performTwoDirection() +{ + // Getting objects. + ListOfShape anObjects; + std::list aContextes; + AttributeSelectionListPtr anObjectsSelList = + selectionList(FeaturesPlugin_MultiTranslation::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 + eraseResults(); + return; + } + anObjects.push_back(anObject); + aContextes.push_back(anObjectAttr->context()); + } + + //Getting axis. + std::shared_ptr aFirstAxis; + std::shared_ptr anEdge; + std::shared_ptr anObjRef = + selection(FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID()); + if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->value())); + } else if (anObjRef && !anObjRef->value() && anObjRef->context() && + anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->context()->shape())); + } + if(anEdge) { + aFirstAxis = std::shared_ptr(new GeomAPI_Ax1(anEdge->line()->location(), + anEdge->line()->direction())); + } + std::shared_ptr aSecondAxis; + anObjRef = selection(FeaturesPlugin_MultiTranslation::AXIS_SECOND_DIR_ID()); + if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->value())); + } else if (anObjRef && !anObjRef->value() && anObjRef->context() && + anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->context()->shape())); + } + if(anEdge) { + aSecondAxis = std::shared_ptr(new GeomAPI_Ax1(anEdge->line()->location(), + anEdge->line()->direction())); + } + + // Getting step. + double aFirstStep = real(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID())->value(); + double aSecondStep = real(FeaturesPlugin_MultiTranslation::STEP_SECOND_DIR_ID())->value(); + + // Getting number of copies. + int aFirstNbCopies = + integer(FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID())->value(); + int aSecondNbCopies = + integer(FeaturesPlugin_MultiTranslation::NB_COPIES_SECOND_DIR_ID())->value(); + + // Coord aFirstAxis + double x1 = aFirstAxis->dir()->x(); + double y1 = aFirstAxis->dir()->y(); + double z1 = aFirstAxis->dir()->z(); + double norm1 = sqrt(x1*x1 + y1*y1 + z1*z1); + + // Coord aSecondAxis + double x2 = aSecondAxis->dir()->x(); + double y2 = aSecondAxis->dir()->y(); + double z2 = aSecondAxis->dir()->z(); + double norm2 = sqrt(x2*x2 + y2*y2 + z2*z2); + + // Moving each object. + int aResultIndex = 0; + std::list::iterator aContext = aContextes.begin(); + for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); + anObjectsIt++, aContext++) { + std::shared_ptr aBaseShape = *anObjectsIt; + + ListOfShape aListOfShape; + std::list > aListOfTranslationAlgo; + + for (int j=0; j aTranslationAlgo( + new GeomAlgoAPI_Translation(aBaseShape, dx, dy, dz)); + + if (!aTranslationAlgo->check()) { + setError(aTranslationAlgo->getError()); + break; + } + + aTranslationAlgo->build(); + + // Checking that the algorithm worked properly. + if (!aTranslationAlgo->isDone()) { + static const std::string aFeatureError = "Error : Multitranslation algorithm failed."; + setError(aFeatureError); + break; + } + if (aTranslationAlgo->shape()->isNull()) { + static const std::string aShapeError = "Error : Resulting shape is null."; + setError(aShapeError); + break; + } + if (!aTranslationAlgo->isValid()) { + static const std::string aFeatureError = "Error : Resulting shape in not valid."; + setError(aFeatureError); + break; + } + aListOfShape.push_back(aTranslationAlgo->shape()); + aListOfTranslationAlgo.push_back(aTranslationAlgo); + } + } + std::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + aResultBody->storeModified(aBaseShape, aCompound); + loadNamingDS(aListOfTranslationAlgo, aResultBody, aBaseShape); + setResult(aResultBody, aResultIndex); + aResultIndex++; + } + + // Remove the rest results if there were produced in the previous pass. + removeResults(aResultIndex); +} + +//================================================================================================= +void FeaturesPlugin_MultiTranslation::loadNamingDS( + std::list > theListOfTranslationAlgo, + std::shared_ptr theResultBody, + std::shared_ptr theBaseShape) +{ + int aTag = 1; + int anIndex = 1; + std::string aTranslatedName; + + for (std::list >::const_iterator anIt = + theListOfTranslationAlgo.begin(); anIt != theListOfTranslationAlgo.cend(); ++anIt) { + std::shared_ptr aSubShapes = (*anIt)->mapOfSubShapes(); + + // naming of faces + aTranslatedName = "Translated_Face_" + std::to_string((long long) anIndex); + theResultBody->loadAndOrientModifiedShapes((*anIt).get(), theBaseShape, GeomAPI_Shape::FACE, + aTag++, aTranslatedName, *aSubShapes.get(), + false, true); + + // naming of edges + aTranslatedName = "Translated_Edge_" + std::to_string((long long) anIndex); + theResultBody->loadAndOrientModifiedShapes((*anIt).get(), theBaseShape, GeomAPI_Shape::EDGE, + aTag++, aTranslatedName, *aSubShapes.get(), + false, true); + + // naming of vertex + aTranslatedName = "Translated_Vertex_" + std::to_string((long long) anIndex); + theResultBody->loadAndOrientModifiedShapes((*anIt).get(), theBaseShape, GeomAPI_Shape::VERTEX, + aTag++, aTranslatedName, *aSubShapes.get(), + false, true); + + ++anIndex; + } +} \ No newline at end of file diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h new file mode 100644 index 000000000..876644239 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h @@ -0,0 +1,115 @@ +// Copyright (C) 2014-201x CEA/DEN, EDF R&D + +// File: FeaturesPlugin_MultiTranslation.h +// Created: 30 Jan 2017 +// Author: Clarisse Genrault (CEA) + +#ifndef FEATURESPLUGIN_MULTITRANSLATION_H_ +#define FEATURESPLUGIN_MULTITRANSLATION_H_ + +#include + +#include + +#include + +/** \class FeaturesPlugin_MultiTranslation + * \ingroup Plugins + * \brief Feature for movement objects along one or two axes an arbitary number of times, + * making a copy every time. + */ +class FeaturesPlugin_MultiTranslation : public ModelAPI_Feature +{ + public: + /// Translation kind. + inline static const std::string& ID() + { + static const std::string MY_MULTITRANSLATION_ID("MultiTranslation"); + return MY_MULTITRANSLATION_ID; + } + + /// Attribute name of referenced objects. + inline static const std::string& OBJECTS_LIST_ID() + { + static const std::string MY_OBJECTS_LIST_ID("main_objects"); + return MY_OBJECTS_LIST_ID; + } + + /// Attribute name of a first direction. + inline static const std::string& AXIS_FIRST_DIR_ID() + { + static const std::string MY_AXIS_FIRST_DIR_ID("axis_first_dir"); + return MY_AXIS_FIRST_DIR_ID; + } + + /// Attribute name of step for the first direction. + inline static const std::string& STEP_FIRST_DIR_ID() + { + static const std::string MY_STEP_FIRST_DIR_ID("step_first_dir"); + return MY_STEP_FIRST_DIR_ID; + } + + /// Attribute name of number of copies for the first direction. + inline static const std::string& NB_COPIES_FIRST_DIR_ID() + { + static const std::string MY_NB_COPIES_FIRST_DIR_ID("nb_first_dir"); + return MY_NB_COPIES_FIRST_DIR_ID; + } + + /// Attribute name for use second dir. + inline static const std::string& USE_SECOND_DIR_ID() + { + static const std::string MY_USE_SECOND_DIR_ID("use_second_dir"); + return MY_USE_SECOND_DIR_ID; + } + + /// Attribute name of a second direction. + inline static const std::string& AXIS_SECOND_DIR_ID() + { + static const std::string MY_AXIS_SECOND_DIR_ID("axis_second_dir"); + return MY_AXIS_SECOND_DIR_ID; + } + + /// Attribute name of step for the second direction. + inline static const std::string& STEP_SECOND_DIR_ID() + { + static const std::string MY_STEP_SECOND_DIR_ID("step_second_dir"); + return MY_STEP_SECOND_DIR_ID; + } + + /// Attribute name of number of copies for the second direction. + inline static const std::string& NB_COPIES_SECOND_DIR_ID() + { + static const std::string MY_NB_COPIES_SECOND_DIR_ID("nb_second_dir"); + return MY_NB_COPIES_SECOND_DIR_ID; + } + + /// \return the kind of a feature. + FEATURESPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = FeaturesPlugin_MultiTranslation::ID(); + return MY_KIND; + } + + /// Creates a new part document if needed. + FEATURESPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes. + FEATURESPLUGIN_EXPORT virtual void initAttributes(); + + /// Use plugin manager for features creation. + FeaturesPlugin_MultiTranslation(); + +private: + /// Perform the multi translation in one direction. + void performOneDirection(); + + /// Perform the multi translation in two directions. + void performTwoDirection(); + + void loadNamingDS(std::list > theListOfTranslationAlgo, + std::shared_ptr theResultBody, + std::shared_ptr theBaseShape); +}; + +#endif // FEATURESPLUGIN_MULTITRANSLATION_H_ \ No newline at end of file diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index 4f1344b1d..1509e6c77 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -105,6 +106,8 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(std::string theFeatureID) return FeaturePtr(new FeaturesPlugin_Symmetry); } else if (theFeatureID == FeaturesPlugin_Scale::ID()) { return FeaturePtr(new FeaturesPlugin_Scale); + } else if (theFeatureID == FeaturesPlugin_MultiTranslation::ID()) { + return FeaturePtr(new FeaturesPlugin_MultiTranslation); } // feature of such kind is not found diff --git a/src/FeaturesPlugin/icons/multitranslation.png b/src/FeaturesPlugin/icons/multitranslation.png new file mode 100644 index 0000000000000000000000000000000000000000..d0d9c157b300366145025a8d3b658f18bf85fa94 GIT binary patch literal 642 zcmV-|0)737P)-m`C~wK?;sXFqIb%cW56V%n^(y4Xcg z1W|cWEUFt3%1ToMg&?oGsV<_c=%O1T>~EL5vOsY~#K;zvV&ugbOhiQY=UnIO>XdG$ z6Fu<4_x?Q3`vV_A9|5luy%sZ$WtQRTx->MAU0FE<0Qp?LAsv6#_7~o7C{jIg-(CrP zkC$fRb4y$^|H+t8=Ds6F>^NQ_u_(G*hpoH!i6jUGn1sd0_aAoab-y+`^qB#m zIvXZhJvicX)6Na|*{6rkTwnmy#QV2}PhY=u8m%Azur}J!5;;KD`9)qh*Lyt^4s`^> zp^jj{9}vL#4gg%w98JwrOmSf9bcBL0CV66Y4c}c}e-Zpo2hO>xXQ1x~01z;qjz7P> z{fLD5m#_I+I*X$KHUZqyl3ktqeHM%O4glsB7Rt%gY;*MrtfhNoIlGi;+e@ZIE}v@z z@I*^GWm$2`5d{FG2I*rmHCuB7HrhXURdX&64 + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index 65488474b..07e9f9e06 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -2,6 +2,11 @@ + + + + + @@ -71,8 +76,8 @@ - - + + diff --git a/src/PythonAPI/model/features/__init__.py b/src/PythonAPI/model/features/__init__.py index 4632e171a..7f678f5d3 100644 --- a/src/PythonAPI/model/features/__init__.py +++ b/src/PythonAPI/model/features/__init__.py @@ -2,6 +2,7 @@ """ from FeaturesAPI import addPlacement, addRotation, addScale, addSymmetry, addTranslation +from FeaturesAPI import addMultiTranslation from FeaturesAPI import addExtrusion, addExtrusionCut, addExtrusionFuse from FeaturesAPI import addRevolution, addRevolutionCut, addRevolutionFuse from FeaturesAPI import addPipe -- 2.30.2