Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / PrimitivesAPI / PrimitivesAPI_Box.cpp
1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D -->
2
3 // File:        PrimitivesAPI_Box.cpp
4 // Created:     28 June 2016
5 // Author:      Clarisse Genrault
6
7 #include "PrimitivesAPI_Box.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
11
12 //==================================================================================================
13 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature)
14 : ModelHighAPI_Interface(theFeature)
15 {
16   initialize();
17 }
18
19 //==================================================================================================
20 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
21                                      const ModelHighAPI_Double & theDx,
22                                      const ModelHighAPI_Double & theDy,
23                                      const ModelHighAPI_Double & theDz)
24 : ModelHighAPI_Interface(theFeature)
25 {
26   if (initialize())
27     setDimensions(theDx, theDy, theDz);
28 }
29
30 //==================================================================================================
31 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
32                                      const ModelHighAPI_Selection& theFirstPoint,
33                                      const ModelHighAPI_Selection& theSecondPoint)
34 : ModelHighAPI_Interface(theFeature)
35 {
36   if (initialize())
37     setPoints(theFirstPoint, theSecondPoint);
38 }
39
40 //==================================================================================================
41 PrimitivesAPI_Box::~PrimitivesAPI_Box()
42 {
43
44 }
45
46 //==================================================================================================
47 void PrimitivesAPI_Box::setDimensions(const ModelHighAPI_Double& theDx,
48                                       const ModelHighAPI_Double& theDy,
49                                       const ModelHighAPI_Double& theDz)
50 {
51   fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
52   fillAttribute(theDx, dx());
53   fillAttribute(theDy, dy());
54   fillAttribute(theDz, dz());
55
56   execute();
57 }
58
59 //==================================================================================================
60 void PrimitivesAPI_Box::setPoints(const ModelHighAPI_Selection& theFirstPoint,
61                                   const ModelHighAPI_Selection& theSecondPoint)
62 {
63   fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
64   fillAttribute(theFirstPoint, firstPoint());
65   fillAttribute(theSecondPoint, secondPoint());
66
67   execute();
68 }
69
70 //==================================================================================================
71 void PrimitivesAPI_Box::dump(ModelHighAPI_Dumper& theDumper) const
72 {
73   FeaturePtr aBase = feature();
74   const std::string& aDocName = theDumper.name(aBase->document());
75
76   theDumper << aBase << " = model.addBox(" << aDocName;
77
78   std::string aCreationMethod = aBase->string(PrimitivesPlugin_Box::CREATION_METHOD())->value();
79   
80   if(aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS()) {
81     AttributeDoublePtr anAttrDx = aBase->real(PrimitivesPlugin_Box::DX_ID());
82     AttributeDoublePtr anAttrDy = aBase->real(PrimitivesPlugin_Box::DY_ID());
83     AttributeDoublePtr anAttrDz = aBase->real(PrimitivesPlugin_Box::DZ_ID());
84     
85     theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
86   } else if (aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS()) {
87     AttributeSelectionPtr anAttrFirstPnt =
88       aBase->selection(PrimitivesPlugin_Box::POINT_FIRST_ID());
89     AttributeSelectionPtr anAttrSecondPnt =
90       aBase->selection(PrimitivesPlugin_Box::POINT_SECOND_ID());
91
92     theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
93   }
94
95   theDumper << ")" << std::endl;
96 }
97
98 //==================================================================================================
99 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
100               const ModelHighAPI_Double& theDx,
101               const ModelHighAPI_Double& theDy,
102               const ModelHighAPI_Double& theDz)
103 {
104   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
105   return BoxPtr(new PrimitivesAPI_Box(aFeature, theDx, theDy, theDz));
106 }
107
108 //==================================================================================================
109 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
110               const ModelHighAPI_Selection& theFirstPoint,
111               const ModelHighAPI_Selection& theSecondPoint)
112 {
113   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
114   return BoxPtr(new PrimitivesAPI_Box(aFeature, theFirstPoint, theSecondPoint));
115 }