Salome HOME
03fd6b9d39e88c91624ba0d6f20dadb4fa920684
[modules/shaper.git] / 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     theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
85   } else if (aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS()) {
86     AttributeSelectionPtr anAttrFirstPnt =
87       aBase->selection(PrimitivesPlugin_Box::POINT_FIRST_ID());
88     AttributeSelectionPtr anAttrSecondPnt =
89       aBase->selection(PrimitivesPlugin_Box::POINT_SECOND_ID());
90     theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
91   }
92
93   theDumper << ")" << std::endl;
94 }
95
96 //==================================================================================================
97 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
98               const ModelHighAPI_Double& theDx,
99               const ModelHighAPI_Double& theDy,
100               const ModelHighAPI_Double& theDz)
101 {
102   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
103   return BoxPtr(new PrimitivesAPI_Box(aFeature, theDx, theDy, theDz));
104 }
105
106 //==================================================================================================
107 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
108               const ModelHighAPI_Selection& theFirstPoint,
109               const ModelHighAPI_Selection& theSecondPoint)
110 {
111   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
112   return BoxPtr(new PrimitivesAPI_Box(aFeature, theFirstPoint, theSecondPoint));
113 }