Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Boolean.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_Boolean.h"
22
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Integer.h>
25 #include <ModelHighAPI_Selection.h>
26 #include <ModelHighAPI_Tools.h>
27
28 //==================================================================================================
29 FeaturesAPI_Boolean::FeaturesAPI_Boolean(const std::shared_ptr<ModelAPI_Feature>& theFeature)
30 : ModelHighAPI_Interface(theFeature)
31 {
32   initialize();
33 }
34
35 //==================================================================================================
36 FeaturesAPI_Boolean::FeaturesAPI_Boolean(const std::shared_ptr<ModelAPI_Feature>& theFeature,
37                                          const ModelHighAPI_Integer& theBoolType,
38                                          const std::list<ModelHighAPI_Selection>& theMainObjects,
39                                          const std::list<ModelHighAPI_Selection>& theToolObjects)
40 : ModelHighAPI_Interface(theFeature)
41 {
42   if(initialize()) {
43     fillAttribute(theBoolType, myboolType);
44     fillAttribute(theMainObjects, mymainObjects);
45     fillAttribute(theToolObjects, mytoolObjects);
46
47     execute(false);
48   }
49 }
50
51 //==================================================================================================
52 FeaturesAPI_Boolean::~FeaturesAPI_Boolean()
53 {
54
55 }
56
57 //==================================================================================================
58 void FeaturesAPI_Boolean::setBoolType(const ModelHighAPI_Integer& theBoolType)
59 {
60   fillAttribute(theBoolType, myboolType);
61
62   execute();
63 }
64
65 //==================================================================================================
66 void FeaturesAPI_Boolean::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
67 {
68   fillAttribute(theMainObjects, mymainObjects);
69
70   execute();
71 }
72
73 //==================================================================================================
74 void FeaturesAPI_Boolean::setToolObjects(const std::list<ModelHighAPI_Selection>& theToolObjects)
75 {
76   fillAttribute(theToolObjects, mytoolObjects);
77
78   execute();
79 }
80
81 //==================================================================================================
82 void FeaturesAPI_Boolean::dump(ModelHighAPI_Dumper& theDumper) const
83 {
84   FeaturePtr aBase = feature();
85
86   FeaturesPlugin_Boolean::OperationType aType =
87       (FeaturesPlugin_Boolean::OperationType)aBase->integer(
88       FeaturesPlugin_Boolean::TYPE_ID())->value();
89
90   theDumper << aBase << " = model.add";
91
92   switch(aType) {
93     case FeaturesPlugin_Boolean::BOOL_CUT:    theDumper << "Cut";    break;
94     case FeaturesPlugin_Boolean::BOOL_FUSE:   theDumper << "Fuse";   break;
95     case FeaturesPlugin_Boolean::BOOL_COMMON: theDumper << "Common"; break;
96     case FeaturesPlugin_Boolean::BOOL_FILL:   theDumper << "Fill";   break;
97     case FeaturesPlugin_Boolean::BOOL_SMASH:  theDumper << "Smash";  break;
98   }
99
100   const std::string& aDocName = theDumper.name(aBase->document());
101   AttributeSelectionListPtr anObjects =
102     aBase->selectionList(FeaturesPlugin_Boolean::OBJECT_LIST_ID());
103   AttributeSelectionListPtr aTools = aBase->selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID());
104
105   theDumper << "(" << aDocName << ", " << anObjects << ", " << aTools << ")" << std::endl;
106 }
107
108 //==================================================================================================
109 BooleanPtr addCut(const std::shared_ptr<ModelAPI_Document>& thePart,
110                   const std::list<ModelHighAPI_Selection>& theMainObjects,
111                   const std::list<ModelHighAPI_Selection>& theToolObjects)
112 {
113   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
114   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
115                                             FeaturesPlugin_Boolean::BOOL_CUT,
116                                             theMainObjects,
117                                             theToolObjects));
118 }
119
120 //==================================================================================================
121 BooleanPtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
122                    const std::list<ModelHighAPI_Selection>& theObjects)
123 {
124   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
125   std::list<ModelHighAPI_Selection> aToolObjects;
126   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
127                                             FeaturesPlugin_Boolean::BOOL_FUSE,
128                                             theObjects,
129                                             aToolObjects));
130 }
131
132 //==================================================================================================
133 BooleanPtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
134                    const std::list<ModelHighAPI_Selection>& theMainObjects,
135                    const std::list<ModelHighAPI_Selection>& theToolObjects)
136 {
137   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
138   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
139                                             FeaturesPlugin_Boolean::BOOL_FUSE,
140                                             theMainObjects,
141                                             theToolObjects));
142 }
143
144 //==================================================================================================
145 BooleanPtr addCommon(const std::shared_ptr<ModelAPI_Document>& thePart,
146                      const std::list<ModelHighAPI_Selection>& theMainObjects,
147                      const std::list<ModelHighAPI_Selection>& theToolObjects)
148 {
149   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
150   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
151                                             FeaturesPlugin_Boolean::BOOL_COMMON,
152                                             theMainObjects,
153                                             theToolObjects));
154 }
155
156 //==================================================================================================
157 BooleanPtr addSmash(const std::shared_ptr<ModelAPI_Document>& thePart,
158                     const std::list<ModelHighAPI_Selection>& theMainObjects,
159                     const std::list<ModelHighAPI_Selection>& theToolObjects)
160 {
161   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
162   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
163                                             FeaturesPlugin_Boolean::BOOL_SMASH,
164                                             theMainObjects,
165                                             theToolObjects));
166 }
167
168 //==================================================================================================
169 BooleanPtr addFill(const std::shared_ptr<ModelAPI_Document>& thePart,
170                    const std::list<ModelHighAPI_Selection>& theMainObjects,
171                    const std::list<ModelHighAPI_Selection>& theToolObjects)
172 {
173   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
174   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
175                                             FeaturesPlugin_Boolean::BOOL_FILL,
176                                             theMainObjects,
177                                             theToolObjects));
178 }