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