Salome HOME
46a766b3f31b7f7826ff6b5ceb0ba15a36b0d536
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_BooleanSmash.cpp
1 // Copyright (C) 2014-2022  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_BooleanSmash.h"
21
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Selection.h>
24 #include <ModelHighAPI_Tools.h>
25
26
27 static const double DEFAULT_FUZZY = 1.e-5;
28
29
30 //==================================================================================================
31 FeaturesAPI_BooleanSmash::FeaturesAPI_BooleanSmash(
32   const std::shared_ptr<ModelAPI_Feature>& theFeature)
33 : ModelHighAPI_Interface(theFeature)
34 {
35   initialize();
36 }
37
38 //==================================================================================================
39 FeaturesAPI_BooleanSmash::FeaturesAPI_BooleanSmash(
40   const std::shared_ptr<ModelAPI_Feature>& theFeature,
41   const std::list<ModelHighAPI_Selection>& theMainObjects,
42   const std::list<ModelHighAPI_Selection>& theToolObjects,
43   const ModelHighAPI_Double& theFuzzy)
44 : ModelHighAPI_Interface(theFeature)
45 {
46   if(initialize()) {
47     fillAttribute(theMainObjects, VAR_NAME(mainObjects));
48     fillAttribute(theToolObjects, VAR_NAME(toolObjects));
49     fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
50
51     // Get the evaluated fuzzy parameter from the attribute!!
52     bool aUseFuzzy = (fuzzyParam()->value() > 0);
53     fillAttribute(aUseFuzzy, VAR_NAME(useFuzzy));
54     if (!aUseFuzzy) {
55       ModelHighAPI_Double aFuzzy(DEFAULT_FUZZY);
56       fillAttribute(aFuzzy, VAR_NAME(fuzzyParam));
57     }
58
59     execute(false);
60   }
61 }
62
63 //==================================================================================================
64 FeaturesAPI_BooleanSmash::~FeaturesAPI_BooleanSmash()
65 {
66 }
67
68
69 //==================================================================================================
70 void FeaturesAPI_BooleanSmash::setMainObjects(
71   const std::list<ModelHighAPI_Selection>& theMainObjects)
72 {
73   fillAttribute(theMainObjects, VAR_NAME(mainObjects));
74
75   execute();
76 }
77
78 //==================================================================================================
79 void FeaturesAPI_BooleanSmash::setToolObjects(
80   const std::list<ModelHighAPI_Selection>& theToolObjects)
81 {
82   fillAttribute(theToolObjects, VAR_NAME(toolObjects));
83
84   execute();
85 }
86
87 //==================================================================================================
88 void FeaturesAPI_BooleanSmash::setUseFuzzy(bool theUseFuzzy)
89 {
90   fillAttribute(theUseFuzzy, VAR_NAME(useFuzzy));
91
92   execute();
93 }
94
95 //==================================================================================================
96 void FeaturesAPI_BooleanSmash::setFuzzyValue(const ModelHighAPI_Double& theFuzzy)
97 {
98   fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
99
100   execute();
101 }
102
103 //==================================================================================================
104 void FeaturesAPI_BooleanSmash::dump(ModelHighAPI_Dumper& theDumper) const
105 {
106   FeaturePtr aBase = feature();
107
108   theDumper << aBase << " = model.addSmash";
109
110   const std::string& aDocName = theDumper.name(aBase->document());
111   AttributeSelectionListPtr anObjects =
112     aBase->selectionList(FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID());
113   AttributeSelectionListPtr aTools =
114     aBase->selectionList(FeaturesPlugin_BooleanSmash::TOOL_LIST_ID());
115   bool aUseFuzzy = aBase->boolean(FeaturesPlugin_BooleanSmash::USE_FUZZY_ID())->value();
116   AttributeDoublePtr aFuzzy = aBase->real(FeaturesPlugin_BooleanSmash::FUZZY_PARAM_ID());
117
118   theDumper << "(" << aDocName << ", " << anObjects << ", " << aTools;
119
120   if (aUseFuzzy)
121     theDumper << ", fuzzyParam = " << aFuzzy;
122
123   if (!aBase->data()->version().empty())
124     theDumper << ", keepSubResults = True";
125
126   theDumper << ")" << std::endl;
127 }
128
129 //==================================================================================================
130 BooleanSmashPtr addSmash(const std::shared_ptr<ModelAPI_Document>& thePart,
131                          const std::list<ModelHighAPI_Selection>& theMainObjects,
132                          const std::list<ModelHighAPI_Selection>& theToolObjects,
133                          const ModelHighAPI_Double& theFuzzy,
134                          const bool keepSubResults)
135 {
136   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanSmash::ID());
137   if (!keepSubResults)
138     aFeature->data()->setVersion("");
139   return BooleanSmashPtr(new FeaturesAPI_BooleanSmash(aFeature, theMainObjects, theToolObjects, theFuzzy));
140 }