Salome HOME
Suppression of warnings, application launching problems in different cases (on Window...
[modules/shaper.git] / src / PrimitivesPlugin / PrimitivesPlugin_Tube.cpp
1 // version 2.1 of the License, or (at your option) any later version.
2 //
3 // This library is distributed in the hope that it will be useful,
4 // but WITHOUT ANY WARRANTY; without even the implied warranty of
5 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
6 // Lesser General Public License for more details.
7 //
8 // You should have received a copy of the GNU Lesser General Public
9 // License along with this library; if not, write to the Free Software
10 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
11 //
12 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
13 //
14
15 #include <PrimitivesPlugin_Tube.h>
16
17 #include <ModelAPI_AttributeDouble.h>
18 #include <ModelAPI_ResultBody.h>
19
20 //=================================================================================================
21 PrimitivesPlugin_Tube::PrimitivesPlugin_Tube() // Nothing to do during instantiation
22 {
23 }
24
25 //=================================================================================================
26 void PrimitivesPlugin_Tube::initAttributes()
27 {
28   data()->addAttribute(PrimitivesPlugin_Tube::RMIN_ID(), ModelAPI_AttributeDouble::typeId());
29   data()->addAttribute(PrimitivesPlugin_Tube::RMAX_ID(), ModelAPI_AttributeDouble::typeId());
30   data()->addAttribute(PrimitivesPlugin_Tube::HEIGHT_ID(), ModelAPI_AttributeDouble::typeId());
31 }
32
33 //=================================================================================================
34 void PrimitivesPlugin_Tube::execute()
35 {
36   double aRMin = real(PrimitivesPlugin_Tube::RMIN_ID())->value();
37   double aRMax = real(PrimitivesPlugin_Tube::RMAX_ID())->value();
38   double aZ = real(PrimitivesPlugin_Tube::HEIGHT_ID())->value();
39
40   std::shared_ptr<GeomAlgoAPI_Tube> aTubeAlgo(new GeomAlgoAPI_Tube(aRMin,aRMax,aZ));
41
42   // These checks should be made to the GUI for the feature but
43   // the corresponding validator does not exist yet.
44   if (!aTubeAlgo->check()) {
45     setError(aTubeAlgo->getError());
46     return;
47   }
48
49   // Build the tube
50   aTubeAlgo->build();
51
52   int aResultIndex = 0;
53   ResultBodyPtr aResultTube = document()->createBody(data(), aResultIndex);
54   loadNamingDS(aTubeAlgo, aResultTube);
55   setResult(aResultTube, aResultIndex);
56 }
57
58 //=================================================================================================
59 void PrimitivesPlugin_Tube::loadNamingDS(std::shared_ptr<GeomAlgoAPI_Tube> theTubeAlgo,
60                                          std::shared_ptr<ModelAPI_ResultBody> theResultTube)
61 {
62   // Load the result
63   theResultTube->store(theTubeAlgo->shape());
64
65   // Prepare the naming
66   theTubeAlgo->prepareNamingFaces();
67
68   // Insert to faces
69   std::map< std::string, std::shared_ptr<GeomAPI_Shape> > listOfFaces =
70     theTubeAlgo->getCreatedFaces();
71   for (std::map< std::string, std::shared_ptr<GeomAPI_Shape> >::iterator it = listOfFaces.begin();
72        it != listOfFaces.end();
73        ++it)
74   {
75     theResultTube->generated((*it).second, (*it).first);
76   }
77 }