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