From: Clarisse Genrault Date: Tue, 4 Apr 2017 12:08:44 +0000 (+0200) Subject: Added multirotation feature. X-Git-Tag: V_2.9.0~43 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3d360f22b8a281a22799c2781cc2f69467e1a838;p=modules%2Fshaper.git Added multirotation feature. --- diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 193d513e4..e88a18c53 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -32,6 +32,7 @@ SET(PROJECT_HEADERS FeaturesPlugin_Symmetry.h FeaturesPlugin_Scale.h FeaturesPlugin_MultiTranslation.h + FeaturesPlugin_MultiRotation.h ) SET(PROJECT_SOURCES @@ -62,6 +63,7 @@ SET(PROJECT_SOURCES FeaturesPlugin_Symmetry.cpp FeaturesPlugin_Scale.cpp FeaturesPlugin_MultiTranslation.cpp + FeaturesPlugin_MultiRotation.cpp ) SET(XML_RESOURCES @@ -85,6 +87,7 @@ SET(XML_RESOURCES symmetry_widget.xml scale_widget.xml multitranslation_widget.xml + multirotation_widget.xml ) SET(TEXT_RESOURCES diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp index 4c1d8470e..3bd55a63a 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp @@ -111,14 +111,14 @@ void FeaturesPlugin_MultiRotation::performRotation1D() // Getting number of copies. int nbCopies = integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID())->value(); - + if (nbCopies <=0) { std::string aFeatureError = "Multirotation builder "; aFeatureError+=":: the number of copies for the angular direction is null or negative."; setError(aFeatureError); return; } - + // Getting angle double anAngle; std::string useAngularStep = @@ -128,7 +128,7 @@ void FeaturesPlugin_MultiRotation::performRotation1D() } else { anAngle = 360./nbCopies; } - + // Moving each object. int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); @@ -235,29 +235,29 @@ void FeaturesPlugin_MultiRotation::performRotation2D() anAxis = std::shared_ptr(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction())); } - + // Getting number of copies int he angular direction. int nbAngular = integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID())->value(); - + if (nbAngular <=0) { std::string aFeatureError = "Multirotation builder "; aFeatureError+=":: the number of copies for the angular direction is null or negative."; setError(aFeatureError); return; } - + // Getting number of copies int he radial direction. int nbRadial = integer(FeaturesPlugin_MultiRotation::NB_COPIES_RADIAL_ID())->value(); - + if (nbRadial <=0) { std::string aFeatureError = "Multirotation builder "; aFeatureError+=":: the number of copies for the radial direction is null or negative."; setError(aFeatureError); return; } - + // Getting angle double anAngle; std::string useAngularStep = @@ -267,8 +267,8 @@ void FeaturesPlugin_MultiRotation::performRotation2D() } else { anAngle = 360./nbAngular; } - - // + + // Getting step double aStep = real(FeaturesPlugin_MultiRotation::STEP_RADIAL_ID())->value(); // Moving each object. @@ -278,8 +278,9 @@ void FeaturesPlugin_MultiRotation::performRotation2D() anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); - - std::shared_ptr aDir = GeomAlgoAPI_ShapeTools::makeToto(aBaseShape, anAxis); + + std::shared_ptr aDir = + GeomAlgoAPI_ShapeTools::buildDirFromAxisAndShape(aBaseShape, anAxis); double x = aDir->x(); double y = aDir->y(); double z = aDir->z(); @@ -369,7 +370,7 @@ void FeaturesPlugin_MultiRotation::performRotation2D() GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); aResultBody->storeModified(aBaseShape, aCompound); - + loadNamingDS2(aListOfTranslationAlgo, aResultBody, aBaseShape); loadNamingDS3(aListOfRotationAlgo, aResultBody, aBaseShape, nbRadial); setResult(aResultBody, aResultIndex); @@ -430,7 +431,7 @@ void FeaturesPlugin_MultiRotation::loadNamingDS3( for (std::list >::const_iterator anIt = theListOfRotationAlgo.begin(); anIt != theListOfRotationAlgo.cend(); ++anIt) { - + // naming of faces int numFace = 1; GeomAPI_ShapeExplorer anExp((*anIt)->shape(), GeomAPI_Shape::FACE); diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.h b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.h index b39d4b441..32746de99 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.h +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.h @@ -16,8 +16,9 @@ /** \class FeaturesPlugin_MultiRotation * \ingroup Plugins - * \brief Feature for movement objects along one or two axes an arbitary number of times, - * making a copy every time. + * \brief Feature that rotaes object around an axis an number of times. + * The 2D version also makes translated copies of the object and performs the rotation + * on these as well. */ class FeaturesPlugin_MultiRotation : public ModelAPI_Feature { @@ -50,35 +51,35 @@ class FeaturesPlugin_MultiRotation : public ModelAPI_Feature return MY_USE_ANGULAR_STEP_ID; } - /// Attribute name of step for the first direction. + /// Attribute name of step for the angular. inline static const std::string& STEP_ANGULAR_ID() { static const std::string MY_STEP_ANGULAR_ID("step_angular"); return MY_STEP_ANGULAR_ID; } - /// Attribute name of number of copies for the first direction. + /// Attribute name of number of copies for angular. inline static const std::string& NB_COPIES_ANGULAR_ID() { static const std::string MY_NB_COPIES_ANGULAR_ID("nb_angular"); return MY_NB_COPIES_ANGULAR_ID; } - /// Attribute name for use second dir. + /// Attribute name for use radial dir. inline static const std::string& USE_RADIAL_DIR_ID() { static const std::string MY_USE_RADIAL_DIR_ID("use_radial_dir"); return MY_USE_RADIAL_DIR_ID; } - /// Attribute name of step for the second direction. + /// Attribute name of radial step. inline static const std::string& STEP_RADIAL_ID() { static const std::string MY_STEP_RADIAL_ID("step_radial"); return MY_STEP_RADIAL_ID; } - /// Attribute name of number of copies for the second direction. + /// Attribute name of number of copies for radial. inline static const std::string& NB_COPIES_RADIAL_ID() { static const std::string MY_NB_COPIES_RADIAL_ID("nb_radial"); @@ -102,10 +103,10 @@ class FeaturesPlugin_MultiRotation : public ModelAPI_Feature FeaturesPlugin_MultiRotation(); private: - /// Perform the multi translation in one direction. + /// Perform the multi rotation in one direction. void performRotation1D(); - /// Perform the multi translation in two directions. + /// Perform the multi totation in two directions. void performRotation2D(); void loadNamingDS2(std::list > theListOfTranslationAlgo, diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h index 876644239..36b9f0df4 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h @@ -21,7 +21,7 @@ class FeaturesPlugin_MultiTranslation : public ModelAPI_Feature { public: - /// Translation kind. + /// Multi-translation kind. inline static const std::string& ID() { static const std::string MY_MULTITRANSLATION_ID("MultiTranslation"); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index 1509e6c77..563e2ce62 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -108,6 +109,8 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(std::string theFeatureID) return FeaturePtr(new FeaturesPlugin_Scale); } else if (theFeatureID == FeaturesPlugin_MultiTranslation::ID()) { return FeaturePtr(new FeaturesPlugin_MultiTranslation); + } else if (theFeatureID == FeaturesPlugin_MultiRotation::ID()) { + return FeaturePtr(new FeaturesPlugin_MultiRotation); } // feature of such kind is not found diff --git a/src/FeaturesPlugin/icons/SVG/multirotation.svg b/src/FeaturesPlugin/icons/SVG/multirotation.svg new file mode 100644 index 000000000..b84eaa91f --- /dev/null +++ b/src/FeaturesPlugin/icons/SVG/multirotation.svg @@ -0,0 +1,495 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/src/FeaturesPlugin/icons/multirotation.png b/src/FeaturesPlugin/icons/multirotation.png new file mode 100644 index 000000000..fb82a1e7c Binary files /dev/null and b/src/FeaturesPlugin/icons/multirotation.png differ diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index 07e9f9e06..2f75ff443 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -79,6 +79,9 @@ + + + diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp index 1df2c7f87..55dfedee5 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp @@ -8,6 +8,7 @@ #include "GeomAlgoAPI_SketchBuilder.h" +#include #include #include #include @@ -33,7 +34,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -814,3 +817,20 @@ std::shared_ptr GeomAlgoAPI_ShapeTools::findShape( return aResultShape; } + +//================================================================================================== +std::shared_ptr GeomAlgoAPI_ShapeTools::buildDirFromAxisAndShape( + const std::shared_ptr theBaseShape, + const std::shared_ptr theAxis) +{ + gp_Pnt aCentreOfMassPoint = + GeomAlgoAPI_ShapeTools::centreOfMass(theBaseShape)->impl(); + Handle(Geom_Line) aLine = new Geom_Line(theAxis->impl()); + GeomAPI_ProjectPointOnCurve aPrjTool(aCentreOfMassPoint, aLine); + gp_Pnt aPoint = aPrjTool.NearestPoint(); + + std::shared_ptr aDir(new GeomAPI_Dir(aCentreOfMassPoint.X()-aPoint.X(), + aCentreOfMassPoint.Y()-aPoint.Y(), + aCentreOfMassPoint.Z()-aPoint.Z())); + return aDir; +} \ No newline at end of file diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h index d3b712585..a45e54d4a 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h @@ -15,6 +15,7 @@ #include #include +class GeomAPI_Ax1; class GeomAPI_Edge; class GeomAPI_Dir; class GeomAPI_Face; @@ -142,6 +143,13 @@ public: const std::list >& thePoints, const std::set >& theShapes); + /// \brief Returns a dir from a shape and an axis. + /// \param[in] theBaseShape shape whose center of mass serves as the starting point of the dir. + /// \param[in] theAxis axis that serves as a direction for the dir + /// \return dir that builds from center of mass of the base shape and the axis + GEOMALGOAPI_EXPORT static std::shared_ptr buildDirFromAxisAndShape( + const std::shared_ptr theBaseShape, + const std::shared_ptr theAxis); }; #endif