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