From: dbv Date: Fri, 5 Jun 2015 16:55:25 +0000 (+0300) Subject: Feature #534: 5.01. Body placement by 3D rotation in respect to axis X-Git-Tag: V_1.3.0~270 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2ba159c01a53a7810d82ec5795b4b3be96308fdf;p=modules%2Fshaper.git Feature #534: 5.01. Body placement by 3D rotation in respect to axis --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp index 8493688f1..154e5cfa4 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp @@ -8,8 +8,14 @@ #include #include +#include #include +#include +#include + +#define _ROTATED_TAG 1 + //================================================================================================= FeaturesPlugin_Rotation::FeaturesPlugin_Rotation() { @@ -20,16 +26,93 @@ void FeaturesPlugin_Rotation::initAttributes() { AttributeSelectionListPtr aSelection = std::dynamic_pointer_cast(data()->addAttribute( - FeaturesPlugin_Rotation::LIST_ID(), ModelAPI_AttributeSelectionList::typeId())); + FeaturesPlugin_Rotation::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId())); // revolution works with faces always aSelection->setSelectionType("SOLID"); data()->addAttribute(FeaturesPlugin_Rotation::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(FeaturesPlugin_Rotation::ANGLE_ID(), ModelAPI_AttributeDouble::typeId()); } //================================================================================================= void FeaturesPlugin_Rotation::execute() { + // Getting objects. + ListOfShape anObjects; + AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Rotation::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()) { + return; + } + anObjects.push_back(anObject); + } + + //Getting axe. + std::shared_ptr anAxis; + std::shared_ptr anEdge; + std::shared_ptr anObjRef = selection(FeaturesPlugin_Rotation::AXIS_OBJECT_ID()); + if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->value())); + } + if(anEdge) { + anAxis = std::shared_ptr(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction())); + } + + // Getting angle. + double anAngle = real(FeaturesPlugin_Rotation::ANGLE_ID())->value(); + + // Rotating each object. + int aResultIndex = 0; + for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) { + std::shared_ptr aBaseShape = *anObjectsIt; + GeomAlgoAPI_Rotation aRotationAlgo(aBaseShape, anAxis, anAngle); + + // Checking that the algorithm worked properly. + if(!aRotationAlgo.isDone()) { + static const std::string aFeatureError = "Rotation algorithm failed"; + setError(aFeatureError); + break; + } + if(aRotationAlgo.shape()->isNull()) { + static const std::string aShapeError = "Resulting shape is Null"; + setError(aShapeError); + break; + } + if(!aRotationAlgo.isValid()) { + std::string aFeatureError = "Warning: resulting shape is not valid"; + setError(aFeatureError); + break; + } + + // Setting result. + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + LoadNamingDS(aRotationAlgo, aResultBody, aBaseShape); + setResult(aResultBody, aResultIndex); + aResultIndex++; + } + + // Remove the rest results if there were produced in the previous pass. + removeResults(aResultIndex); +} + +void FeaturesPlugin_Rotation::LoadNamingDS(const GeomAlgoAPI_Rotation& theRotaionAlgo, + std::shared_ptr theResultBody, + std::shared_ptr theBaseShape) +{ + // Store result. + theResultBody->storeModified(theBaseShape, theRotaionAlgo.shape()); + + std::shared_ptr aSubShapes = theRotaionAlgo.mapOfShapes(); + + int aRotatedTag = 1; + std::string aRotatedName = "Rotated"; + theResultBody->loadAndOrientModifiedShapes(theRotaionAlgo.makeShape().get(), + theBaseShape, GeomAPI_Shape::FACE, + aRotatedTag, aRotatedName, *aSubShapes.get()); + } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Rotation.h b/src/FeaturesPlugin/FeaturesPlugin_Rotation.h index b8a65d6ff..573163166 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Rotation.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Rotation.h @@ -11,42 +11,41 @@ #include +#include + /** \class FeaturesPlugin_Rotation * \ingroup Plugins - * \brief Feature for creation of revolution from the planar face. - * Revolution creates the lateral faces based on edges of the base face and - * the start and end faces and/or start and end angles. + * \brief Feature for rotation objects around the axis. */ class FeaturesPlugin_Rotation : public ModelAPI_Feature { public: - /// Revolution kind. + /// Rotation kind. inline static const std::string& ID() { - static const std::string MY_REVOLUTION_ID("Rotation"); - return MY_REVOLUTION_ID; + static const std::string MY_ROTATION_ID("Rotation"); + return MY_ROTATION_ID; } - /// Attribute name of references sketch entities list, it should contain a sketch result or - /// a pair a sketch result to sketch face. - inline static const std::string& LIST_ID() + /// Attribute name of referenced objects. + inline static const std::string& OBJECTS_LIST_ID() { - static const std::string MY_GROUP_LIST_ID("base"); - return MY_GROUP_LIST_ID; + static const std::string MY_OBJECTS_LIST_ID("main_objects"); + return MY_OBJECTS_LIST_ID; } - /// Attribute name of an object to which the extrusion grows. + /// Attribute name of an axis. inline static const std::string& AXIS_OBJECT_ID() { - static const std::string MY_TO_OBJECT_ID("axis_object"); - return MY_TO_OBJECT_ID; + static const std::string MY_AXIS_OBJECT_ID("axis_object"); + return MY_AXIS_OBJECT_ID; } - /// Attribute name of revolution angle. + /// Attribute name of angle. inline static const std::string& ANGLE_ID() { - static const std::string MY_TO_ANGLE_ID("angle"); - return MY_TO_ANGLE_ID; + static const std::string MY_ANGLE_ID("angle"); + return MY_ANGLE_ID; } /// \return the kind of a feature. @@ -64,6 +63,11 @@ class FeaturesPlugin_Rotation : public ModelAPI_Feature /// Use plugin manager for features creation. FeaturesPlugin_Rotation(); + +private: + void LoadNamingDS(const GeomAlgoAPI_Rotation& theRotaionAlgo, + std::shared_ptr theResultBody, + std::shared_ptr theBaseShape); }; #endif diff --git a/src/FeaturesPlugin/boolean_widget.xml b/src/FeaturesPlugin/boolean_widget.xml index 76c854b46..22d958cca 100644 --- a/src/FeaturesPlugin/boolean_widget.xml +++ b/src/FeaturesPlugin/boolean_widget.xml @@ -2,9 +2,9 @@ @@ -19,21 +19,6 @@ - - diff --git a/src/FeaturesPlugin/rotation_widget.xml b/src/FeaturesPlugin/rotation_widget.xml index 2b38c9a7c..367f3bb0a 100755 --- a/src/FeaturesPlugin/rotation_widget.xml +++ b/src/FeaturesPlugin/rotation_widget.xml @@ -1,11 +1,12 @@ - + tooltip="Select a solid objects" + type_choice="Solids" + concealment="true"> + theSou std::shared_ptr theAxis, double theAngle) : myDone(false), - myShape(new GeomAPI_Shape()) + myShape(new GeomAPI_Shape()), + myMap(new GeomAPI_DataMapOfShapeShape()), + myMkShape(new GeomAlgoAPI_MakeShape()) { build(theSourceShape, theAxis, theAngle); } @@ -48,7 +50,6 @@ void GeomAlgoAPI_Rotation::build(std::shared_ptr theSourceShape, return; } - setImpl(aBuilder); myDone = aBuilder->IsDone() == Standard_True; if(!myDone) { @@ -60,11 +61,11 @@ void GeomAlgoAPI_Rotation::build(std::shared_ptr theSourceShape, for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) { std::shared_ptr aCurrentShape(new GeomAPI_Shape()); aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current())); - myMap.bind(aCurrentShape, aCurrentShape); + myMap->bind(aCurrentShape, aCurrentShape); } myShape->setImpl(new TopoDS_Shape(aResult)); - myMkShape = new GeomAlgoAPI_MakeShape(aBuilder); + myMkShape->setImpl(aBuilder); } //================================================================================================= @@ -91,21 +92,13 @@ const std::shared_ptr& GeomAlgoAPI_Rotation::shape() const } //================================================================================================= -void GeomAlgoAPI_Rotation::mapOfShapes(GeomAPI_DataMapOfShapeShape& theMap) const +std::shared_ptr GeomAlgoAPI_Rotation::mapOfShapes() const { - theMap = myMap; + return myMap; } //================================================================================================= -GeomAlgoAPI_MakeShape* GeomAlgoAPI_Rotation::makeShape() const +std::shared_ptr GeomAlgoAPI_Rotation::makeShape() const { return myMkShape; } - -//================================================================================================= -GeomAlgoAPI_Rotation::~GeomAlgoAPI_Rotation() -{ - if (myImpl) { - myMap.clear(); - } -} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.h b/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.h index 3f77f2159..079fe75aa 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.h @@ -43,13 +43,10 @@ public: GEOMALGOAPI_EXPORT const std::shared_ptr& shape() const; /// \return map of sub-shapes of the result. To be used for History keeping. - GEOMALGOAPI_EXPORT void mapOfShapes(GeomAPI_DataMapOfShapeShape& theMap) const; + GEOMALGOAPI_EXPORT std::shared_ptr mapOfShapes() const; /// \return interface for for History processing. - GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape* makeShape() const; - - /// Destructor. - GEOMALGOAPI_EXPORT virtual ~GeomAlgoAPI_Rotation(); + GEOMALGOAPI_EXPORT std::shared_ptr makeShape() const; private: /// Builds resulting shape. @@ -61,8 +58,8 @@ private: /// Fields. bool myDone; std::shared_ptr myShape; - GeomAPI_DataMapOfShapeShape myMap; - GeomAlgoAPI_MakeShape* myMkShape; + std::shared_ptr myMap; + std::shared_ptr myMkShape; }; #endif diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index 1f679d324..89a55518b 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -53,5 +53,6 @@ icons/activate.png icons/deactivate.png icons/edit.png + icons/rotation.png diff --git a/src/PartSet/icons/rotation.png b/src/PartSet/icons/rotation.png new file mode 100644 index 000000000..7905fa1a0 Binary files /dev/null and b/src/PartSet/icons/rotation.png differ