Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / GDMLPlugin / GDMLPlugin_Ellipsoid.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <GDMLPlugin_Ellipsoid.h>
22
23 #include <ModelAPI_Data.h>
24 #include <ModelAPI_ResultBody.h>
25 #include <ModelAPI_AttributeDouble.h>
26 #include <ModelAPI_AttributeString.h>
27
28 //=================================================================================================
29 GDMLPlugin_Ellipsoid::GDMLPlugin_Ellipsoid() // Nothing to do during instantiation
30 {
31 }
32
33 //=================================================================================================
34 void GDMLPlugin_Ellipsoid::initAttributes()
35 {
36   data()->addAttribute(GDMLPlugin_Ellipsoid::AX_ID(), ModelAPI_AttributeDouble::typeId());
37   data()->addAttribute(GDMLPlugin_Ellipsoid::BY_ID(), ModelAPI_AttributeDouble::typeId());
38   data()->addAttribute(GDMLPlugin_Ellipsoid::CZ_ID(), ModelAPI_AttributeDouble::typeId());
39   data()->addAttribute(GDMLPlugin_Ellipsoid::USE_ZCUT1_ID(), ModelAPI_AttributeString::typeId());
40   data()->addAttribute(GDMLPlugin_Ellipsoid::ZCUT1_ID(), ModelAPI_AttributeDouble::typeId());
41   data()->addAttribute(GDMLPlugin_Ellipsoid::USE_ZCUT2_ID(), ModelAPI_AttributeString::typeId());
42   data()->addAttribute(GDMLPlugin_Ellipsoid::ZCUT2_ID(), ModelAPI_AttributeDouble::typeId());
43 }
44
45 //=================================================================================================
46 void GDMLPlugin_Ellipsoid::execute()
47 {
48   std::shared_ptr<GeomAlgoAPI_Ellipsoid> anEllipsoidAlgo;
49
50   double aAx = real(AX_ID())->value();
51   double aBy = real(BY_ID())->value();
52   double aCz = real(CZ_ID())->value();
53
54   std::string useZCut1 = string(USE_ZCUT1_ID())->value();
55   std::string useZCut2 = string(USE_ZCUT2_ID())->value();
56
57   double aZCut1 = 0.;
58   if (useZCut1.empty()) {
59     aZCut1 = aCz /2.;
60   } else {
61     aZCut1 = real(ZCUT1_ID())->value();
62   }
63   double aZCut2 = 0.;
64   if (useZCut2.empty()) {
65     aZCut2 = aCz /2.;
66   } else {
67     aZCut2 = real(ZCUT2_ID())->value();
68   }
69
70   anEllipsoidAlgo = std::shared_ptr<GeomAlgoAPI_Ellipsoid>(
71     new GeomAlgoAPI_Ellipsoid(aAx, aBy, aCz, aZCut1, aZCut2));
72
73   // Check with that the arguments for anEllipsoidAlgo are correct
74   if (!anEllipsoidAlgo->check()) {
75     setError(anEllipsoidAlgo->getError(), false);
76     return;
77   }
78
79   anEllipsoidAlgo->build();
80
81   // Check if the creation of the ellipsoid is correct
82   if (!anEllipsoidAlgo->isDone()) {
83     setError(anEllipsoidAlgo->getError(), false);
84     return;
85   }
86
87   // Check if the created ellipsoid is valid
88   if (!anEllipsoidAlgo->checkValid("Ellipsoid builder")) {
89     setError(anEllipsoidAlgo->getError(), false);
90     return;
91   }
92
93   int aResultIndex = 0;
94   ResultBodyPtr aResultEllipsoid = document()->createBody(data(), aResultIndex);
95   loadNamingDS(anEllipsoidAlgo, aResultEllipsoid);
96   setResult(aResultEllipsoid, aResultIndex);
97
98 }
99
100 //=================================================================================================
101 void GDMLPlugin_Ellipsoid::loadNamingDS(std::shared_ptr<GeomAlgoAPI_Ellipsoid> theEllipsoidAlgo,
102                                         std::shared_ptr<ModelAPI_ResultBody> theResultEllipsoid)
103 {
104   // Load the result
105   theResultEllipsoid->store(theEllipsoidAlgo->shape());
106
107   // Prepare the naming
108   theEllipsoidAlgo->prepareNamingFaces();
109
110   // Insert to faces
111   int num = 1;
112   std::map< std::string, std::shared_ptr<GeomAPI_Shape> > listOfFaces =
113     theEllipsoidAlgo->getCreatedFaces();
114   for (std::map< std::string, std::shared_ptr<GeomAPI_Shape> >::iterator
115     it=listOfFaces.begin(); it!=listOfFaces.end(); ++it) {
116     std::shared_ptr<GeomAPI_Shape> aFace = (*it).second;
117     theResultEllipsoid->generated(aFace, (*it).first, num++);
118   }
119 }
120