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