1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "FeaturesAPI_BooleanSmash.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Selection.h>
24 #include <ModelHighAPI_Tools.h>
27 static const double DEFAULT_FUZZY = 1.e-5;
30 //==================================================================================================
31 FeaturesAPI_BooleanSmash::FeaturesAPI_BooleanSmash(
32 const std::shared_ptr<ModelAPI_Feature>& theFeature)
33 : ModelHighAPI_Interface(theFeature)
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)
47 bool aUseFuzzy = (theFuzzy.value() > 0);
48 ModelHighAPI_Double aFuzzy = (aUseFuzzy ? theFuzzy : ModelHighAPI_Double(DEFAULT_FUZZY));
49 fillAttribute(theMainObjects, mymainObjects);
50 fillAttribute(theToolObjects, mytoolObjects);
51 fillAttribute(aUseFuzzy, myuseFuzzy);
52 fillAttribute(aFuzzy, myfuzzyParam);
58 //==================================================================================================
59 FeaturesAPI_BooleanSmash::~FeaturesAPI_BooleanSmash()
64 //==================================================================================================
65 void FeaturesAPI_BooleanSmash::setMainObjects(
66 const std::list<ModelHighAPI_Selection>& theMainObjects)
68 fillAttribute(theMainObjects, mymainObjects);
73 //==================================================================================================
74 void FeaturesAPI_BooleanSmash::setToolObjects(
75 const std::list<ModelHighAPI_Selection>& theToolObjects)
77 fillAttribute(theToolObjects, mytoolObjects);
82 //==================================================================================================
83 void FeaturesAPI_BooleanSmash::setUseFuzzy(bool theUseFuzzy)
85 fillAttribute(theUseFuzzy, myuseFuzzy);
90 //==================================================================================================
91 void FeaturesAPI_BooleanSmash::setFuzzyValue(const ModelHighAPI_Double& theFuzzy)
93 fillAttribute(theFuzzy, myfuzzyParam);
98 //==================================================================================================
99 void FeaturesAPI_BooleanSmash::dump(ModelHighAPI_Dumper& theDumper) const
101 FeaturePtr aBase = feature();
103 theDumper << aBase << " = model.addSmash";
105 const std::string& aDocName = theDumper.name(aBase->document());
106 AttributeSelectionListPtr anObjects =
107 aBase->selectionList(FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID());
108 AttributeSelectionListPtr aTools =
109 aBase->selectionList(FeaturesPlugin_BooleanSmash::TOOL_LIST_ID());
110 bool aUseFuzzy = aBase->boolean(FeaturesPlugin_BooleanSmash::USE_FUZZY_ID())->value();
111 double aFuzzy = aBase->real(FeaturesPlugin_BooleanSmash::FUZZY_PARAM_ID())->value();
113 theDumper << "(" << aDocName << ", " << anObjects << ", " << aTools;
116 theDumper << ", fuzzyParam = " << aFuzzy;
118 if (!aBase->data()->version().empty())
119 theDumper << ", keepSubResults = True";
121 theDumper << ")" << std::endl;
124 //==================================================================================================
125 BooleanSmashPtr addSmash(const std::shared_ptr<ModelAPI_Document>& thePart,
126 const std::list<ModelHighAPI_Selection>& theMainObjects,
127 const std::list<ModelHighAPI_Selection>& theToolObjects,
128 const ModelHighAPI_Double& fuzzyParam,
129 const bool keepSubResults)
131 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanSmash::ID());
133 aFeature->data()->setVersion("");
134 return BooleanSmashPtr(new FeaturesAPI_BooleanSmash(aFeature, theMainObjects, theToolObjects, fuzzyParam));