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