From 3d360f22b8a281a22799c2781cc2f69467e1a838 Mon Sep 17 00:00:00 2001 From: Clarisse Genrault Date: Tue, 4 Apr 2017 14:08:44 +0200 Subject: [PATCH] Added multirotation feature. --- src/FeaturesPlugin/CMakeLists.txt | 3 + .../FeaturesPlugin_MultiRotation.cpp | 29 +- .../FeaturesPlugin_MultiRotation.h | 19 +- .../FeaturesPlugin_MultiTranslation.h | 2 +- src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp | 3 + .../icons/SVG/multirotation.svg | 495 ++++++++++++++++++ src/FeaturesPlugin/icons/multirotation.png | Bin 0 -> 758 bytes src/FeaturesPlugin/plugin-Features.xml | 3 + src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp | 20 + src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h | 8 + 10 files changed, 558 insertions(+), 24 deletions(-) create mode 100644 src/FeaturesPlugin/icons/SVG/multirotation.svg create mode 100644 src/FeaturesPlugin/icons/multirotation.png 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 0000000000000000000000000000000000000000..fb82a1e7c95225c809e9b41caf671ed9c1603ba3 GIT binary patch literal 758 zcmVSzd$~=1mdWuR|+> ztw7L=5eAAENkSMRky!`^V!|jFf)^o%sJRUzO3Xw^%D^nw%!zZ_Qm|n;{q#HC_`%Y` zJU8b#&w1X5_c=e5QB?Y9>1XgzXhn#T@u4hlXXhezGF;;U<{A&MGuNv6_U09+cT^03 z+fLB&cItH6C2Nl%*L)QK{nJ3HP%=hh-=6%-Bl=uR1pqj|%xWTbMYh&e*PKc*CKnh? z=3AQ$cnOqPi?abB82qtNUUgFq0K~Xv00}(LBec4*CX#6X?+7mU_hK+Q4*;Ex?$`b~ zzkSx(F}1w`5sqXYo(5y}5;f{}Gm)`uO}0g~MgGk1j|wN2*Vmb9Sy@gDHQ{{k%ja*} zySs!LS9?x4&!5xlfBhxF9p~r3I1y|BVgbPG^9cl2x21!PSp{HeGj@CoXgMBs_vA#< z{l*4I(_LGwEJCn=v7&no^}&g+o*M)pS);~)f=6RWz?dlFv9OAZOCj_Fz^lp02(K?_ zP0(m_i0A?UIRFfgynknFvG;SDXtX`4C7tOQT~FVSheIt~j9iX3Nw_RTRchmPO+;jt zIInNoGcYt51i?T6bVfY}U)nh1ZWVC+iulbvjkAJ)4*<~Po==l8aZJiwdAoWjFu(9Z z9jM%93COCx*CFYY9 zZ7LIIOl6|yL?)tFS5PRmyK&U55t<807*qoM6N<$f^$Sj%>V!Z literal 0 HcmV?d00001 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 -- 2.39.2