Salome HOME
Issue #2562: CEA 2018-1 Fuse
[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 std::list<ModelHighAPI_Selection>& theToolObjects,
40   const bool theRemoveEdges)
41 : ModelHighAPI_Interface(theFeature)
42 {
43   if(initialize()) {
44     if (theToolObjects.empty()) {
45       fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
46     } else {
47       fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
48     }
49
50     fillAttribute(theMainObjects, mymainObjects);
51     fillAttribute(theToolObjects, mytoolObjects);
52     fillAttribute(theRemoveEdges, myremoveEdges);
53
54     execute(false);
55   }
56 }
57
58 //==================================================================================================
59 FeaturesAPI_BooleanFuse::~FeaturesAPI_BooleanFuse()
60 {
61 }
62
63
64 //==================================================================================================
65 void FeaturesAPI_BooleanFuse::setMainObjects(
66   const std::list<ModelHighAPI_Selection>& theMainObjects)
67 {
68   fillAttribute(theMainObjects, mymainObjects);
69
70   execute();
71 }
72
73 //==================================================================================================
74 void FeaturesAPI_BooleanFuse::setToolObjects(
75   const std::list<ModelHighAPI_Selection>& theToolObjects)
76 {
77   fillAttribute(theToolObjects, mytoolObjects);
78
79   if (theToolObjects.empty()) {
80     fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
81   } else {
82     fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
83   }
84
85   execute();
86 }
87
88 //==================================================================================================
89 void FeaturesAPI_BooleanFuse::setRemoveEdges(const bool theRemoveEdges)
90 {
91   fillAttribute(theRemoveEdges, myremoveEdges);
92
93   execute();
94 }
95
96 //==================================================================================================
97 void FeaturesAPI_BooleanFuse::dump(ModelHighAPI_Dumper& theDumper) const
98 {
99   FeaturePtr aBase = feature();
100
101   theDumper << aBase << " = model.addFuse";
102
103   const std::string& aDocName = theDumper.name(aBase->document());
104   AttributeSelectionListPtr anObjects =
105     aBase->selectionList(FeaturesPlugin_BooleanFuse::OBJECT_LIST_ID());
106   AttributeSelectionListPtr aTools =
107     aBase->selectionList(FeaturesPlugin_BooleanFuse::TOOL_LIST_ID());
108   AttributeBooleanPtr aRemoveEdges =
109     aBase->boolean(FeaturesPlugin_BooleanFuse::REMOVE_INTERSECTION_EDGES_ID());
110
111   theDumper << "(" << aDocName << ", " << anObjects;
112
113   if (aTools->size() > 0) {
114     theDumper << ", " << aTools;
115   }
116
117   if (aRemoveEdges->value()) {
118     theDumper << ", " << true;
119   }
120
121   theDumper << ")" << std::endl;
122 }
123
124 //==================================================================================================
125 BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
126                        const std::list<ModelHighAPI_Selection>& theObjects,
127                        const bool theRemoveEdges)
128 {
129   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
130   std::list<ModelHighAPI_Selection> aToolObjects;
131   return BooleanFusePtr(new FeaturesAPI_BooleanFuse(aFeature,
132                                                     theObjects,
133                                                     aToolObjects,
134                                                     theRemoveEdges));
135 }
136
137 //==================================================================================================
138 BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
139                    const std::list<ModelHighAPI_Selection>& theMainObjects,
140                    const std::list<ModelHighAPI_Selection>& theToolObjects,
141                    const bool theRemoveEdges)
142 {
143   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
144   return BooleanFusePtr(new FeaturesAPI_BooleanFuse(aFeature,
145                                                     theMainObjects,
146                                                     theToolObjects,
147                                                     theRemoveEdges));
148 }