Salome HOME
Update of the ExportToGEOM test
[modules/shaper.git] / src / PrimitivesAPI / PrimitivesAPI_Box.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 "PrimitivesAPI_Box.h"
22
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
25
26 //==================================================================================================
27 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : ModelHighAPI_Interface(theFeature)
29 {
30   initialize();
31 }
32
33 //==================================================================================================
34 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
35                                      const ModelHighAPI_Double & theDx,
36                                      const ModelHighAPI_Double & theDy,
37                                      const ModelHighAPI_Double & theDz)
38 : ModelHighAPI_Interface(theFeature)
39 {
40   if (initialize())
41     setDimensions(theDx, theDy, theDz);
42 }
43
44 //==================================================================================================
45 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
46                                      const ModelHighAPI_Selection& theFirstPoint,
47                                      const ModelHighAPI_Selection& theSecondPoint)
48 : ModelHighAPI_Interface(theFeature)
49 {
50   if (initialize())
51     setPoints(theFirstPoint, theSecondPoint);
52 }
53
54 //==================================================================================================
55 PrimitivesAPI_Box::~PrimitivesAPI_Box()
56 {
57
58 }
59
60 //==================================================================================================
61 void PrimitivesAPI_Box::setDimensions(const ModelHighAPI_Double& theDx,
62                                       const ModelHighAPI_Double& theDy,
63                                       const ModelHighAPI_Double& theDz)
64 {
65   fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
66   fillAttribute(theDx, dx());
67   fillAttribute(theDy, dy());
68   fillAttribute(theDz, dz());
69
70   execute();
71 }
72
73 //==================================================================================================
74 void PrimitivesAPI_Box::setPoints(const ModelHighAPI_Selection& theFirstPoint,
75                                   const ModelHighAPI_Selection& theSecondPoint)
76 {
77   fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
78   fillAttribute(theFirstPoint, firstPoint());
79   fillAttribute(theSecondPoint, secondPoint());
80
81   execute();
82 }
83
84 //==================================================================================================
85 void PrimitivesAPI_Box::dump(ModelHighAPI_Dumper& theDumper) const
86 {
87   FeaturePtr aBase = feature();
88   const std::string& aDocName = theDumper.name(aBase->document());
89
90   theDumper << aBase << " = model.addBox(" << aDocName;
91
92   std::string aCreationMethod = aBase->string(PrimitivesPlugin_Box::CREATION_METHOD())->value();
93
94   if(aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS()) {
95     AttributeDoublePtr anAttrDx = aBase->real(PrimitivesPlugin_Box::DX_ID());
96     AttributeDoublePtr anAttrDy = aBase->real(PrimitivesPlugin_Box::DY_ID());
97     AttributeDoublePtr anAttrDz = aBase->real(PrimitivesPlugin_Box::DZ_ID());
98     theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
99   } else if (aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS()) {
100     AttributeSelectionPtr anAttrFirstPnt =
101       aBase->selection(PrimitivesPlugin_Box::POINT_FIRST_ID());
102     AttributeSelectionPtr anAttrSecondPnt =
103       aBase->selection(PrimitivesPlugin_Box::POINT_SECOND_ID());
104     theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
105   }
106
107   theDumper << ")" << std::endl;
108 }
109
110 //==================================================================================================
111 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
112               const ModelHighAPI_Double& theDx,
113               const ModelHighAPI_Double& theDy,
114               const ModelHighAPI_Double& theDz)
115 {
116   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
117   return BoxPtr(new PrimitivesAPI_Box(aFeature, theDx, theDy, theDz));
118 }
119
120 //==================================================================================================
121 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
122               const ModelHighAPI_Selection& theFirstPoint,
123               const ModelHighAPI_Selection& theSecondPoint)
124 {
125   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
126   return BoxPtr(new PrimitivesAPI_Box(aFeature, theFirstPoint, theSecondPoint));
127 }