Salome HOME
Update copyrights
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Placement.cpp
1 // Copyright (C) 2014-2019  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 "FeaturesAPI_Placement.h"
21
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
24
25 //==================================================================================================
26 FeaturesAPI_Placement::FeaturesAPI_Placement(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
28 {
29   initialize();
30 }
31
32 //==================================================================================================
33 FeaturesAPI_Placement::FeaturesAPI_Placement(const std::shared_ptr<ModelAPI_Feature>& theFeature,
34                                              const std::list<ModelHighAPI_Selection>& theObjects,
35                                              const ModelHighAPI_Selection& theStartShape,
36                                              const ModelHighAPI_Selection& theEndShape,
37                                              const bool theReverseDirection,
38                                              const bool theCentering)
39 : ModelHighAPI_Interface(theFeature)
40 {
41   if(initialize()) {
42     fillAttribute(theObjects, myobjects);
43     fillAttribute(theStartShape, mystartShape);
44     fillAttribute(theEndShape, myendShape);
45     fillAttribute(theReverseDirection, myreverseDirection);
46     setCentering(theCentering);
47   }
48 }
49
50 //==================================================================================================
51 FeaturesAPI_Placement::~FeaturesAPI_Placement()
52 {
53
54 }
55
56 //==================================================================================================
57 void FeaturesAPI_Placement::setObjects(const std::list<ModelHighAPI_Selection>& theObjects)
58 {
59   fillAttribute(theObjects, myobjects);
60
61   execute();
62 }
63
64 //==================================================================================================
65 void FeaturesAPI_Placement::setStartShape(const ModelHighAPI_Selection& theStartShape)
66 {
67   fillAttribute(theStartShape, mystartShape);
68
69   execute();
70 }
71
72 //==================================================================================================
73 void FeaturesAPI_Placement::setEndShape(const ModelHighAPI_Selection& theEndShape)
74 {
75   fillAttribute(theEndShape, myendShape);
76
77   execute();
78 }
79
80 //==================================================================================================
81 void FeaturesAPI_Placement::setReverseDirection(const bool theReverseDirection)
82 {
83   fillAttribute(theReverseDirection, myreverseDirection);
84
85   execute();
86 }
87
88 //==================================================================================================
89 void FeaturesAPI_Placement::setCentering(const bool theCentering)
90 {
91   fillAttribute(theCentering, mycentering);
92
93   execute();
94 }
95
96 //==================================================================================================
97 void FeaturesAPI_Placement::dump(ModelHighAPI_Dumper& theDumper) const
98 {
99   FeaturePtr aBase = feature();
100   const std::string& aDocName = theDumper.name(aBase->document());
101
102   AttributeSelectionListPtr anAttrObjects =
103     aBase->selectionList(FeaturesPlugin_Placement::OBJECTS_LIST_ID());
104   AttributeSelectionPtr anAttrStartShape =
105     aBase->selection(FeaturesPlugin_Placement::START_SHAPE_ID());
106   AttributeSelectionPtr anAttrEndShape = aBase->selection(FeaturesPlugin_Placement::END_SHAPE_ID());
107   AttributeBooleanPtr anAttrReverse = aBase->boolean(FeaturesPlugin_Placement::REVERSE_ID());
108   AttributeBooleanPtr anAttrCentering = aBase->boolean(FeaturesPlugin_Placement::CENTERING_ID());
109
110   theDumper << aBase << " = model.addPlacement(" << aDocName << ", "
111             << anAttrObjects << ", " << anAttrStartShape << ", " << anAttrEndShape << ", "
112             << anAttrReverse << ", " << anAttrCentering << ")" << std::endl;
113 }
114
115 //==================================================================================================
116 PlacementPtr addPlacement(const std::shared_ptr<ModelAPI_Document>& thePart,
117                           const std::list<ModelHighAPI_Selection>& theObjects,
118                           const ModelHighAPI_Selection& theStartShape,
119                           const ModelHighAPI_Selection& theEndShape,
120                           const bool theReverseDirection,
121                           const bool theCentering)
122 {
123   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Placement::ID());
124   return PlacementPtr(new FeaturesAPI_Placement(aFeature,
125                                                 theObjects,
126                                                 theStartShape,
127                                                 theEndShape,
128                                                 theReverseDirection,
129                                                 theCentering));
130 }