Salome HOME
Unit test for moving group after BuildPlugin_Face feature
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_BooleanFuse.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_BooleanFuse.h"
22
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Selection.h>
25 #include <ModelHighAPI_Tools.h>
26
27 //==================================================================================================
28 FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
29   const std::shared_ptr<ModelAPI_Feature>& theFeature)
30 : ModelHighAPI_Interface(theFeature)
31 {
32   initialize();
33 }
34
35 //==================================================================================================
36 FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
37   const std::shared_ptr<ModelAPI_Feature>& theFeature,
38   const std::list<ModelHighAPI_Selection>& theMainObjects,
39   const bool theRemoveEdges)
40   : ModelHighAPI_Interface(theFeature)
41 {
42   if (initialize()) {
43     fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
44     fillAttribute(theMainObjects, mymainObjects);
45     fillAttribute(theRemoveEdges, myremoveEdges);
46
47     execute(false);
48   }
49 }
50
51 //==================================================================================================
52 FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
53   const std::shared_ptr<ModelAPI_Feature>& theFeature,
54   const std::list<ModelHighAPI_Selection>& theMainObjects,
55   const std::list<ModelHighAPI_Selection>& theToolObjects,
56   const bool theRemoveEdges)
57 : ModelHighAPI_Interface(theFeature)
58 {
59   if(initialize()) {
60     fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
61     fillAttribute(theMainObjects, mymainObjects);
62     fillAttribute(theToolObjects, mytoolObjects);
63     fillAttribute(theRemoveEdges, myremoveEdges);
64
65     execute(false);
66   }
67 }
68
69 //==================================================================================================
70 FeaturesAPI_BooleanFuse::~FeaturesAPI_BooleanFuse()
71 {
72 }
73
74
75 //==================================================================================================
76 void FeaturesAPI_BooleanFuse::setMainObjects(
77   const std::list<ModelHighAPI_Selection>& theMainObjects)
78 {
79   fillAttribute(theMainObjects, mymainObjects);
80
81   execute();
82 }
83
84 //==================================================================================================
85 void FeaturesAPI_BooleanFuse::setToolObjects(
86   const std::list<ModelHighAPI_Selection>& theToolObjects)
87 {
88   fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
89   fillAttribute(theToolObjects, mytoolObjects);
90
91   execute();
92 }
93
94 //==================================================================================================
95 void FeaturesAPI_BooleanFuse::setRemoveEdges(const bool theRemoveEdges)
96 {
97   fillAttribute(theRemoveEdges, myremoveEdges);
98
99   execute();
100 }
101
102 //==================================================================================================
103 void FeaturesAPI_BooleanFuse::setAdvancedMode(const bool theMode)
104 {
105   if (theMode) {
106     fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
107   } else {
108     fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
109   }
110
111   execute();
112 }
113
114 //==================================================================================================
115 void FeaturesAPI_BooleanFuse::dump(ModelHighAPI_Dumper& theDumper) const
116 {
117   FeaturePtr aBase = feature();
118
119   theDumper << aBase << " = model.addFuse";
120
121   const std::string& aDocName = theDumper.name(aBase->document());
122   AttributeStringPtr aMode = aBase->string(FeaturesPlugin_BooleanFuse::CREATION_METHOD());
123   AttributeSelectionListPtr anObjects =
124     aBase->selectionList(FeaturesPlugin_BooleanFuse::OBJECT_LIST_ID());
125   AttributeSelectionListPtr aTools =
126     aBase->selectionList(FeaturesPlugin_BooleanFuse::TOOL_LIST_ID());
127   AttributeBooleanPtr aRemoveEdges =
128     aBase->boolean(FeaturesPlugin_BooleanFuse::REMOVE_INTERSECTION_EDGES_ID());
129
130   theDumper << "(" << aDocName << ", " << anObjects;
131
132   if (aMode->value() == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
133     theDumper << ", " << aTools;
134   }
135
136   if (aRemoveEdges->value()) {
137     theDumper << ", " << true;
138   }
139
140   theDumper << ")" << std::endl;
141 }
142
143 //==================================================================================================
144 BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
145                        const std::list<ModelHighAPI_Selection>& theObjects,
146                        const bool theRemoveEdges)
147 {
148   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
149   return BooleanFusePtr(new FeaturesAPI_BooleanFuse(aFeature,
150                                                     theObjects,
151                                                     theRemoveEdges));
152 }
153
154 //==================================================================================================
155 BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
156                    const std::list<ModelHighAPI_Selection>& theMainObjects,
157                    const std::list<ModelHighAPI_Selection>& theToolObjects,
158                    const bool theRemoveEdges)
159 {
160   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
161   return BooleanFusePtr(new FeaturesAPI_BooleanFuse(aFeature,
162                                                     theMainObjects,
163                                                     theToolObjects,
164                                                     theRemoveEdges));
165 }