1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "GDMLAPI_Ellipsoid.h"
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
26 GDMLAPI_Ellipsoid::GDMLAPI_Ellipsoid(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
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)
39 setSizes(theAX, theBY, theCZ);
40 fillAttribute("", useZCut1());
41 fillAttribute("", useZCut1());
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)
54 setSizes(theAX, theBY, theCZ);
60 GDMLAPI_Ellipsoid::~GDMLAPI_Ellipsoid()
64 void GDMLAPI_Ellipsoid::setSizes(const ModelHighAPI_Double& theAX,
65 const ModelHighAPI_Double& theBY,
66 const ModelHighAPI_Double& theCZ)
68 fillAttribute(theAX, ax());
69 fillAttribute(theBY, by());
70 fillAttribute(theCZ, cz());
75 void GDMLAPI_Ellipsoid::setZCut1(const ModelHighAPI_Double& theZCut1)
77 fillAttribute("true", useZCut1());
78 fillAttribute(theZCut1, zCut1());
83 void GDMLAPI_Ellipsoid::setZCut2(const ModelHighAPI_Double& theZCut2)
85 fillAttribute("true", useZCut2());
86 fillAttribute(theZCut2, zCut2());
92 //==================================================================================================
93 void GDMLAPI_Ellipsoid::dump(ModelHighAPI_Dumper& theDumper) const
95 FeaturePtr aBase = feature();
96 const std::string& aDocName = theDumper.name(aBase->document());
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());
102 theDumper << aBase << " = model.addEllipsoid(" << aDocName << ", "
103 << anAttrAX << ", " << anAttrBY << ", " << anAttrCZ;
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());
110 bool isZCut1 = !anAttrUseZCut1->value().empty();
111 bool isZCut2 = !anAttrUseZCut2->value().empty();
112 if (isZCut1 && isZCut2)
113 theDumper << ", " << anAttrZCut1 << ", " << anAttrZCut2 << ")" << std::endl;
115 theDumper << ")" << std::endl;
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;
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)
131 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(GDMLAPI_Ellipsoid::ID());
132 return EllipsoidPtr(new GDMLAPI_Ellipsoid(aFeature, theAX, theBY, theCZ));
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)
142 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(GDMLAPI_Ellipsoid::ID());
143 return EllipsoidPtr(new GDMLAPI_Ellipsoid(aFeature, theAX, theBY, theCZ, theZCut1, theZCut2));