Salome HOME
Issue #1834: Fix length of lines
[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(false);
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(
74       FeaturesPlugin_Boolean::TYPE_ID())->value();
75
76   theDumper << aBase << " = model.add";
77
78   switch(aType) {
79     case FeaturesPlugin_Boolean::BOOL_CUT:    theDumper << "Cut";    break;
80     case FeaturesPlugin_Boolean::BOOL_FUSE:   theDumper << "Fuse";   break;
81     case FeaturesPlugin_Boolean::BOOL_COMMON: theDumper << "Common"; break;
82     case FeaturesPlugin_Boolean::BOOL_FILL:   theDumper << "Fill";   break;
83     case FeaturesPlugin_Boolean::BOOL_SMASH:  theDumper << "Smash";  break;
84   }
85
86   const std::string& aDocName = theDumper.name(aBase->document());
87   AttributeSelectionListPtr anObjects = 
88     aBase->selectionList(FeaturesPlugin_Boolean::OBJECT_LIST_ID());
89   AttributeSelectionListPtr aTools = aBase->selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID());
90
91   theDumper << "(" << aDocName << ", " << anObjects << ", " << aTools << ")" << std::endl;
92 }
93
94 //==================================================================================================
95 BooleanPtr addCut(const std::shared_ptr<ModelAPI_Document>& thePart,
96                   const std::list<ModelHighAPI_Selection>& theMainObjects,
97                   const std::list<ModelHighAPI_Selection>& theToolObjects)
98 {
99   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
100   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
101                                             FeaturesPlugin_Boolean::BOOL_CUT,
102                                             theMainObjects,
103                                             theToolObjects));
104 }
105
106 //==================================================================================================
107 BooleanPtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
108                    const std::list<ModelHighAPI_Selection>& theObjects)
109 {
110   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
111   std::list<ModelHighAPI_Selection> aToolObjects;
112   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
113                                             FeaturesPlugin_Boolean::BOOL_FUSE,
114                                             theObjects,
115                                             aToolObjects));
116 }
117
118 //==================================================================================================
119 BooleanPtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
120                    const std::list<ModelHighAPI_Selection>& theMainObjects,
121                    const std::list<ModelHighAPI_Selection>& theToolObjects)
122 {
123   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
124   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
125                                             FeaturesPlugin_Boolean::BOOL_FUSE,
126                                             theMainObjects,
127                                             theToolObjects));
128 }
129
130 //==================================================================================================
131 BooleanPtr addCommon(const std::shared_ptr<ModelAPI_Document>& thePart,
132                      const std::list<ModelHighAPI_Selection>& theMainObjects,
133                      const std::list<ModelHighAPI_Selection>& theToolObjects)
134 {
135   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
136   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
137                                             FeaturesPlugin_Boolean::BOOL_COMMON,
138                                             theMainObjects,
139                                             theToolObjects));
140 }
141
142 //==================================================================================================
143 BooleanPtr addSmash(const std::shared_ptr<ModelAPI_Document>& thePart,
144                     const std::list<ModelHighAPI_Selection>& theMainObjects,
145                     const std::list<ModelHighAPI_Selection>& theToolObjects)
146 {
147   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
148   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
149                                             FeaturesPlugin_Boolean::BOOL_SMASH,
150                                             theMainObjects,
151                                             theToolObjects));
152 }
153
154 //==================================================================================================
155 BooleanPtr addFill(const std::shared_ptr<ModelAPI_Document>& thePart,
156                    const std::list<ModelHighAPI_Selection>& theMainObjects,
157                    const std::list<ModelHighAPI_Selection>& theToolObjects)
158 {
159   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
160   return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
161                                             FeaturesPlugin_Boolean::BOOL_FILL,
162                                             theMainObjects,
163                                             theToolObjects));
164 }