Salome HOME
Merge remote-tracking branch 'remotes/origin/HigherLevelObjectsHistory'
[modules/shaper.git] / src / GDMLAPI / GDMLAPI_Ellipsoid.cpp
1 // Copyright (C) 2014-2019  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 email : webmaster.salome@opencascade.com
18 //
19
20 #include "GDMLAPI_Ellipsoid.h"
21
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
24
25 GDMLAPI_Ellipsoid::GDMLAPI_Ellipsoid(const std::shared_ptr<ModelAPI_Feature>& theFeature)
26   : ModelHighAPI_Interface(theFeature)
27 {
28   initialize();
29 }
30
31 GDMLAPI_Ellipsoid::GDMLAPI_Ellipsoid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
32                                      const ModelHighAPI_Double& theAX,
33                                      const ModelHighAPI_Double& theBY,
34                                      const ModelHighAPI_Double& theCZ)
35   : ModelHighAPI_Interface(theFeature)
36 {
37   if (initialize()) {
38     setSizes(theAX, theBY, theCZ);
39     fillAttribute("", useZCut1());
40     fillAttribute("", useZCut2());
41   }
42 }
43
44 GDMLAPI_Ellipsoid::GDMLAPI_Ellipsoid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
45                                      const ModelHighAPI_Double& theAX,
46                                      const ModelHighAPI_Double& theBY,
47                                      const ModelHighAPI_Double& theCZ,
48                                      const ModelHighAPI_Double& theZCut1,
49                                      const ModelHighAPI_Double& theZCut2)
50   : ModelHighAPI_Interface(theFeature)
51 {
52   if (initialize()) {
53     setSizes(theAX, theBY, theCZ);
54     setZCut1(theZCut1);
55     setZCut2(theZCut2);
56   }
57 }
58
59 GDMLAPI_Ellipsoid::~GDMLAPI_Ellipsoid()
60 {
61 }
62
63 void GDMLAPI_Ellipsoid::setSizes(const ModelHighAPI_Double& theAX,
64                                  const ModelHighAPI_Double& theBY,
65                                  const ModelHighAPI_Double& theCZ)
66 {
67   fillAttribute(theAX, ax());
68   fillAttribute(theBY, by());
69   fillAttribute(theCZ, cz());
70
71   execute();
72 }
73
74 void GDMLAPI_Ellipsoid::setZCut1(const ModelHighAPI_Double& theZCut1)
75 {
76   fillAttribute("true", useZCut1());
77   fillAttribute(theZCut1, zCut1());
78
79   execute();
80 }
81
82 void GDMLAPI_Ellipsoid::setZCut2(const ModelHighAPI_Double& theZCut2)
83 {
84   fillAttribute("true", useZCut2());
85   fillAttribute(theZCut2, zCut2());
86
87   execute();
88 }
89
90
91 //==================================================================================================
92 void GDMLAPI_Ellipsoid::dump(ModelHighAPI_Dumper& theDumper) const
93 {
94   FeaturePtr aBase = feature();
95   const std::string& aDocName = theDumper.name(aBase->document());
96
97   AttributeDoublePtr anAttrAX = aBase->real(GDMLPlugin_Ellipsoid::AX_ID());
98   AttributeDoublePtr anAttrBY = aBase->real(GDMLPlugin_Ellipsoid::BY_ID());
99   AttributeDoublePtr anAttrCZ = aBase->real(GDMLPlugin_Ellipsoid::CZ_ID());
100
101   theDumper << aBase << " = model.addEllipsoid(" << aDocName << ", "
102             << anAttrAX << ", " << anAttrBY << ", " << anAttrCZ;
103
104   AttributeStringPtr anAttrUseZCut1 = aBase->string(GDMLPlugin_Ellipsoid::USE_ZCUT1_ID());
105   AttributeDoublePtr anAttrZCut1 = aBase->real(GDMLPlugin_Ellipsoid::ZCUT1_ID());
106   AttributeStringPtr anAttrUseZCut2 = aBase->string(GDMLPlugin_Ellipsoid::USE_ZCUT2_ID());
107   AttributeDoublePtr anAttrZCut2 = aBase->real(GDMLPlugin_Ellipsoid::ZCUT2_ID());
108
109   bool isZCut1 = !anAttrUseZCut1->value().empty();
110   bool isZCut2 = !anAttrUseZCut2->value().empty();
111   if (isZCut1 && isZCut2)
112     theDumper << ", " << anAttrZCut1 << ", " << anAttrZCut2 << ")" << std::endl;
113   else {
114     theDumper << ")" << std::endl;
115
116     if (isZCut1 && !isZCut2)
117       theDumper << theDumper.name(aBase) << ".setZCut1(" << anAttrZCut1 << ")" << std::endl;
118     else if (!isZCut1 && isZCut2)
119       theDumper << theDumper.name(aBase) << ".setZCut2(" << anAttrZCut2 << ")" << std::endl;
120   }
121 }
122
123
124 //==================================================================================================
125 EllipsoidPtr addEllipsoid(const std::shared_ptr<ModelAPI_Document>& thePart,
126                           const ModelHighAPI_Double& theAX,
127                           const ModelHighAPI_Double& theBY,
128                           const ModelHighAPI_Double& theCZ)
129 {
130   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(GDMLAPI_Ellipsoid::ID());
131   return EllipsoidPtr(new GDMLAPI_Ellipsoid(aFeature, theAX, theBY, theCZ));
132 }
133
134 EllipsoidPtr addEllipsoid(const std::shared_ptr<ModelAPI_Document>& thePart,
135                           const ModelHighAPI_Double& theAX,
136                           const ModelHighAPI_Double& theBY,
137                           const ModelHighAPI_Double& theCZ,
138                           const ModelHighAPI_Double& theZCut1,
139                           const ModelHighAPI_Double& theZCut2)
140 {
141   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(GDMLAPI_Ellipsoid::ID());
142   return EllipsoidPtr(new GDMLAPI_Ellipsoid(aFeature, theAX, theBY, theCZ, theZCut1, theZCut2));
143 }