Salome HOME
Dump Python in the High Level Parameterized Geometry API (issue #1648)
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Boolean.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_Boolean.cpp
4 // Created:     07 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "FeaturesAPI_Boolean.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Integer.h>
11 #include <ModelHighAPI_Selection.h>
12 #include <ModelHighAPI_Tools.h>
13
14 //==================================================================================================
15 FeaturesAPI_Boolean::FeaturesAPI_Boolean(const std::shared_ptr<ModelAPI_Feature>& theFeature)
16 : ModelHighAPI_Interface(theFeature)
17 {
18   initialize();
19 }
20
21 //==================================================================================================
22 FeaturesAPI_Boolean::FeaturesAPI_Boolean(const std::shared_ptr<ModelAPI_Feature>& theFeature,
23                                          const ModelHighAPI_Integer& theBoolType,
24                                          const std::list<ModelHighAPI_Selection>& theMainObjects,
25                                          const std::list<ModelHighAPI_Selection>& theToolObjects)
26 : ModelHighAPI_Interface(theFeature)
27 {
28   if(initialize()) {
29     fillAttribute(theBoolType, myboolType);
30     fillAttribute(theMainObjects, mymainObjects);
31     fillAttribute(theToolObjects, mytoolObjects);
32
33     execute();
34   }
35 }
36
37 //==================================================================================================
38 FeaturesAPI_Boolean::~FeaturesAPI_Boolean()
39 {
40
41 }
42
43 //==================================================================================================
44 void FeaturesAPI_Boolean::setBoolType(const ModelHighAPI_Integer& theBoolType)
45 {
46   fillAttribute(theBoolType, myboolType);
47
48   execute();
49 }
50
51 //==================================================================================================
52 void FeaturesAPI_Boolean::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
53 {
54   fillAttribute(theMainObjects, mymainObjects);
55
56   execute();
57 }
58
59 //==================================================================================================
60 void FeaturesAPI_Boolean::setToolObjects(const std::list<ModelHighAPI_Selection>& theToolObjects)
61 {
62   fillAttribute(theToolObjects, mytoolObjects);
63
64   execute();
65 }
66
67 //==================================================================================================
68 void FeaturesAPI_Boolean::dump(ModelHighAPI_Dumper& theDumper) const
69 {
70   FeaturePtr aBase = feature();
71
72   FeaturesPlugin_Boolean::OperationType aType =
73       (FeaturesPlugin_Boolean::OperationType)aBase->integer(FeaturesPlugin_Boolean::TYPE_ID())->value();
74
75   theDumper << aBase << " = model.add";
76
77   switch(aType) {
78     case FeaturesPlugin_Boolean::BOOL_CUT:    theDumper << "Cut";    break;
79     case FeaturesPlugin_Boolean::BOOL_FUSE:   theDumper << "Fuse";   break;
80     case FeaturesPlugin_Boolean::BOOL_COMMON: theDumper << "Common"; break;
81     case FeaturesPlugin_Boolean::BOOL_FILL:   theDumper << "Fill";   break;
82     case FeaturesPlugin_Boolean::BOOL_SMASH:  theDumper << "Smash";  break;
83   }
84
85   const std::string& aDocName = theDumper.name(aBase->document());
86   AttributeSelectionListPtr anObjects = aBase->selectionList(FeaturesPlugin_Boolean::OBJECT_LIST_ID());
87   AttributeSelectionListPtr aTools = aBase->selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID());
88
89   theDumper << "(" << aDocName << ", " << anObjects << ", " << aTools << ")" << std::endl;
90 }
91
92 //==================================================================================================
93 BooleanPtr addCut(const std::shared_ptr<ModelAPI_Document>& thePart,
94                   const std::list<ModelHighAPI_Selection>& theMainObjects,
95                   const std::list<ModelHighAPI_Selection>& theToolObjects)
96 {
97   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
98   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
99                                             FeaturesPlugin_Boolean::BOOL_CUT,
100                                             theMainObjects,
101                                             theToolObjects));
102 }
103
104 //==================================================================================================
105 BooleanPtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
106                    const std::list<ModelHighAPI_Selection>& theObjects)
107 {
108   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
109   std::list<ModelHighAPI_Selection> aToolObjects;
110   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
111                                             FeaturesPlugin_Boolean::BOOL_FUSE,
112                                             theObjects,
113                                             aToolObjects));
114 }
115
116 //==================================================================================================
117 BooleanPtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
118                    const std::list<ModelHighAPI_Selection>& theMainObjects,
119                    const std::list<ModelHighAPI_Selection>& theToolObjects)
120 {
121   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
122   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
123                                             FeaturesPlugin_Boolean::BOOL_FUSE,
124                                             theMainObjects,
125                                             theToolObjects));
126 }
127
128 //==================================================================================================
129 BooleanPtr addCommon(const std::shared_ptr<ModelAPI_Document>& thePart,
130                      const std::list<ModelHighAPI_Selection>& theMainObjects,
131                      const std::list<ModelHighAPI_Selection>& theToolObjects)
132 {
133   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
134   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
135                                             FeaturesPlugin_Boolean::BOOL_COMMON,
136                                             theMainObjects,
137                                             theToolObjects));
138 }
139
140 //==================================================================================================
141 BooleanPtr addSmash(const std::shared_ptr<ModelAPI_Document>& thePart,
142                     const std::list<ModelHighAPI_Selection>& theMainObjects,
143                     const std::list<ModelHighAPI_Selection>& theToolObjects)
144 {
145   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
146   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
147                                             FeaturesPlugin_Boolean::BOOL_SMASH,
148                                             theMainObjects,
149                                             theToolObjects));
150 }
151
152 //==================================================================================================
153 BooleanPtr addFill(const std::shared_ptr<ModelAPI_Document>& thePart,
154                    const std::list<ModelHighAPI_Selection>& theMainObjects,
155                    const std::list<ModelHighAPI_Selection>& theToolObjects)
156 {
157   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
158   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
159                                             FeaturesPlugin_Boolean::BOOL_FILL,
160                                             theMainObjects,
161                                             theToolObjects));
162 }