Salome HOME
0022081: EDF 2386 GEOM: Union of a list of objects
[modules/geom.git] / src / GEOM_I / GEOM_IBooleanOperations_i.cc
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <Standard_Stream.hxx>
24
25 #include "GEOM_IBooleanOperations_i.hh"
26
27 #include "utilities.h"
28 #include "OpUtil.hxx"
29
30 #include "GEOM_Engine.hxx"
31 #include "GEOM_Object.hxx"
32
33 #include <TColStd_HArray1OfInteger.hxx>
34
35 //=============================================================================
36 /*!
37  *   constructor:
38  */
39 //=============================================================================
40 GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i (PortableServer::POA_ptr thePOA,
41                                                       GEOM::GEOM_Gen_ptr theEngine,
42                                                       ::GEOMImpl_IBooleanOperations* theImpl)
43 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
44 {
45   MESSAGE("GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i");
46 }
47
48 //=============================================================================
49 /*!
50  *  destructor
51  */
52 //=============================================================================
53 GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i()
54 {
55   MESSAGE("GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i");
56 }
57
58
59 //=============================================================================
60 /*!
61  *  MakeBoolean
62  */
63 //=============================================================================
64 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBoolean
65                                                  (GEOM::GEOM_Object_ptr theShape1,
66                                                   GEOM::GEOM_Object_ptr theShape2,
67                                                   CORBA::Long           theOp)
68 {
69   GEOM::GEOM_Object_var aGEOMObject;
70
71   //Set a not done flag
72   GetOperations()->SetNotDone();
73
74   //Get the reference shapes
75   Handle(GEOM_Object) aSh1 = GetObjectImpl(theShape1);
76   Handle(GEOM_Object) aSh2 = GetObjectImpl(theShape2);
77
78   if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
79
80   // Make Boolean
81   Handle(GEOM_Object) anObject = GetOperations()->MakeBoolean(aSh1, aSh2, theOp);
82   if (!GetOperations()->IsDone() || anObject.IsNull())
83     return aGEOMObject._retn();
84
85   return GetObject(anObject);
86 }
87
88 //=============================================================================
89 /*!
90  *  MakeFuseList
91  */
92 //=============================================================================
93 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeFuseList
94                                     (const GEOM::ListOfGO& theShapes)
95 {
96   GEOM::GEOM_Object_var aGEOMObject;
97
98   //Set a not done flag
99   GetOperations()->SetNotDone();
100
101   Handle(TColStd_HSequenceOfTransient) aShapes =
102     GetListOfObjectsImpl(theShapes);
103
104   if (aShapes.IsNull()) {
105     return aGEOMObject._retn();
106   }
107
108   // Make fusion
109   Handle(GEOM_Object) anObject = GetOperations()->MakeFuseList(aShapes);
110
111   if (!GetOperations()->IsDone() || anObject.IsNull())
112     return aGEOMObject._retn();
113
114   return GetObject(anObject);
115 }
116
117 //=============================================================================
118 /*!
119  *  MakeCommonList
120  */
121 //=============================================================================
122 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeCommonList
123                                     (const GEOM::ListOfGO& theShapes)
124 {
125   GEOM::GEOM_Object_var aGEOMObject;
126
127   //Set a not done flag
128   GetOperations()->SetNotDone();
129
130   Handle(TColStd_HSequenceOfTransient) aShapes =
131     GetListOfObjectsImpl(theShapes);
132
133   if (aShapes.IsNull()) {
134     return aGEOMObject._retn();
135   }
136
137   // Make fusion
138   Handle(GEOM_Object) anObject = GetOperations()->MakeCommonList(aShapes);
139
140   if (!GetOperations()->IsDone() || anObject.IsNull())
141     return aGEOMObject._retn();
142
143   return GetObject(anObject);
144 }
145
146 //=============================================================================
147 /*!
148  *  MakeCutList
149  */
150 //=============================================================================
151 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeCutList
152                                     (GEOM::GEOM_Object_ptr theMainShape,
153                                      const GEOM::ListOfGO& theShapes)
154 {
155   GEOM::GEOM_Object_var aGEOMObject;
156
157   //Set a not done flag
158   GetOperations()->SetNotDone();
159
160   Handle(GEOM_Object) aMainShape = GetObjectImpl(theMainShape);
161
162   if (aMainShape.IsNull()) {
163     return aGEOMObject._retn();
164   }
165
166   Handle(TColStd_HSequenceOfTransient) aShapes =
167     GetListOfObjectsImpl(theShapes);
168
169   if (aShapes.IsNull()) {
170     return aGEOMObject._retn();
171   }
172
173   // Make fusion
174   Handle(GEOM_Object) anObject = GetOperations()->MakeCutList(aMainShape, aShapes);
175
176   if (!GetOperations()->IsDone() || anObject.IsNull())
177     return aGEOMObject._retn();
178
179   return GetObject(anObject);
180 }
181
182 //=============================================================================
183 /*!
184  *  MakePartition
185  */
186 //=============================================================================
187 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
188                                       (const GEOM::ListOfGO&   theShapes,
189                                        const GEOM::ListOfGO&   theTools,
190                                        const GEOM::ListOfGO&   theKeepIns,
191                                        const GEOM::ListOfGO&   theRemoveIns,
192                                        CORBA::Short            theLimit,
193                                        CORBA::Boolean          theRemoveWebs,
194                                        const GEOM::ListOfLong& theMaterials,
195                                        CORBA::Short theKeepNonlimitShapes)
196 {
197   GEOM::GEOM_Object_var aGEOMObject;
198
199   //Set a not done flag
200   GetOperations()->SetNotDone();
201
202   Handle(TColStd_HSequenceOfTransient) aShapes  = GetListOfObjectsImpl(theShapes);
203   Handle(TColStd_HSequenceOfTransient) aTools   = GetListOfObjectsImpl(theTools);
204   Handle(TColStd_HSequenceOfTransient) aKeepIns = GetListOfObjectsImpl(theKeepIns);
205   Handle(TColStd_HSequenceOfTransient) aRemIns  = GetListOfObjectsImpl(theRemoveIns);
206   Handle(TColStd_HArray1OfInteger) aMaterials;
207
208   if (aShapes.IsNull() || aTools.IsNull() ||
209       aKeepIns.IsNull() || aRemIns.IsNull()) {
210     return aGEOMObject._retn();
211   }
212
213   //Get the materials
214   int ind;
215   int aLen = theMaterials.length();
216   if ( aLen ) {
217     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
218     for (ind = 0; ind < aLen; ind++) {
219       aMaterials->SetValue(ind+1, theMaterials[ind]);
220     }
221   }
222
223   // Make Partition
224   Handle(GEOM_Object) anObject =
225     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
226                                    theLimit, theRemoveWebs, aMaterials,
227                                    theKeepNonlimitShapes,
228                                    /*PerformSelfIntersections*/Standard_True);
229   if (!GetOperations()->IsDone() || anObject.IsNull())
230     return aGEOMObject._retn();
231
232   return GetObject(anObject);
233 }
234
235 //=============================================================================
236 /*!
237  *  MakePartitionNonSelfIntersectedShape
238  */
239 //=============================================================================
240 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
241                                       (const GEOM::ListOfGO&   theShapes,
242                                        const GEOM::ListOfGO&   theTools,
243                                        const GEOM::ListOfGO&   theKeepIns,
244                                        const GEOM::ListOfGO&   theRemoveIns,
245                                        CORBA::Short            theLimit,
246                                        CORBA::Boolean          theRemoveWebs,
247                                        const GEOM::ListOfLong& theMaterials,
248                                        CORBA::Short theKeepNonlimitShapes)
249 {
250   GEOM::GEOM_Object_var aGEOMObject;
251
252   //Set a not done flag
253   GetOperations()->SetNotDone();
254
255   Handle(TColStd_HSequenceOfTransient) aShapes  = GetListOfObjectsImpl(theShapes);
256   Handle(TColStd_HSequenceOfTransient) aTools   = GetListOfObjectsImpl(theTools);
257   Handle(TColStd_HSequenceOfTransient) aKeepIns = GetListOfObjectsImpl(theKeepIns);
258   Handle(TColStd_HSequenceOfTransient) aRemIns  = GetListOfObjectsImpl(theRemoveIns);
259   Handle(TColStd_HArray1OfInteger) aMaterials;
260
261   if (aShapes.IsNull() || aTools.IsNull() ||
262       aKeepIns.IsNull() || aRemIns.IsNull()) {
263     return aGEOMObject._retn();
264   }
265
266   //Get the materials
267   int ind;
268   int aLen = theMaterials.length();
269   if ( aLen ) {
270     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
271     for (ind = 0; ind < aLen; ind++) {
272       aMaterials->SetValue(ind+1, theMaterials[ind]);
273     }
274   }
275
276   // Make Partition
277   Handle(GEOM_Object) anObject =
278     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
279                                    theLimit, theRemoveWebs, aMaterials,
280                                    theKeepNonlimitShapes,
281                                    /*PerformSelfIntersections*/Standard_False);
282   if (!GetOperations()->IsDone() || anObject.IsNull())
283     return aGEOMObject._retn();
284
285   return GetObject(anObject);
286 }
287
288 //=============================================================================
289 /*!
290  *  MakeHalfPartition
291  */
292 //=============================================================================
293 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
294                                                  (GEOM::GEOM_Object_ptr theShape,
295                                                   GEOM::GEOM_Object_ptr thePlane)
296 {
297   GEOM::GEOM_Object_var aGEOMObject;
298
299   //Set a not done flag
300   GetOperations()->SetNotDone();
301
302   //Get the reference shapes
303   Handle(GEOM_Object) aSh = GetObjectImpl(theShape);
304   Handle(GEOM_Object) aPl = GetObjectImpl(thePlane);
305
306   if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
307
308   // Make Half Partition
309   Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
310   if (!GetOperations()->IsDone() || anObject.IsNull())
311     return aGEOMObject._retn();
312
313   return GetObject(anObject);
314 }