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