Salome HOME
3b116738ae2652ddff24fa873dbd77eaf9c631a6
[modules/geom.git] / src / GEOM_I / GEOM_IBooleanOperations_i.cc
1 // Copyright (C) 2007-2023  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, or (at your option) any later version.
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                                      CORBA::Boolean        IsCheckSelfInte)
69 {
70   GEOM::GEOM_Object_var aGEOMObject;
71
72   //Set a not done flag
73   GetOperations()->SetNotDone();
74
75   //Get the reference shapes
76   Handle(::GEOM_Object) aSh1 = GetObjectImpl(theShape1);
77   Handle(::GEOM_Object) aSh2 = GetObjectImpl(theShape2);
78
79   if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
80
81   // Make Boolean
82   Handle(::GEOM_Object) anObject =
83     GetOperations()->MakeBoolean(aSh1, aSh2, theOp, IsCheckSelfInte);
84   if (!GetOperations()->IsDone() || anObject.IsNull())
85     return aGEOMObject._retn();
86
87   return GetObject(anObject);
88 }
89
90 //=============================================================================
91 /*!
92  *  MakeFuse
93  */
94 //=============================================================================
95 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeFuse
96                                     (GEOM::GEOM_Object_ptr theShape1,
97                                      GEOM::GEOM_Object_ptr theShape2,
98                                      CORBA::Boolean        IsCheckSelfInte,
99                                      CORBA::Boolean        IsRmExtraEdges)
100 {
101   GEOM::GEOM_Object_var aGEOMObject;
102
103   //Set a not done flag
104   GetOperations()->SetNotDone();
105
106   //Get the reference shapes
107   Handle(::GEOM_Object) aSh1 = GetObjectImpl(theShape1);
108   Handle(::GEOM_Object) aSh2 = GetObjectImpl(theShape2);
109
110   if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
111
112   // Make Boolean
113   Handle(::GEOM_Object) anObject = GetOperations()->MakeFuse
114     (aSh1, aSh2, IsCheckSelfInte, IsRmExtraEdges);
115
116   if (!GetOperations()->IsDone() || anObject.IsNull())
117     return aGEOMObject._retn();
118
119   return GetObject(anObject);
120 }
121
122 //=============================================================================
123 /*!
124  *  MakeFuseList
125  */
126 //=============================================================================
127 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeFuseList
128                                     (const GEOM::ListOfGO& theShapes,
129                                      CORBA::Boolean        IsCheckSelfInte,
130                                      CORBA::Boolean        IsRmExtraEdges)
131 {
132   GEOM::GEOM_Object_var aGEOMObject;
133
134   //Set a not done flag
135   GetOperations()->SetNotDone();
136
137   Handle(TColStd_HSequenceOfTransient) aShapes =
138     GetListOfObjectsImpl(theShapes);
139
140   if (aShapes.IsNull()) {
141     return aGEOMObject._retn();
142   }
143
144   // Make fusion
145   Handle(::GEOM_Object) anObject =
146     GetOperations()->MakeFuseList(aShapes, IsCheckSelfInte, IsRmExtraEdges);
147
148   if (!GetOperations()->IsDone() || anObject.IsNull())
149     return aGEOMObject._retn();
150
151   return GetObject(anObject);
152 }
153
154 //=============================================================================
155 /*!
156  *  MakeCommonList
157  */
158 //=============================================================================
159 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeCommonList
160                                     (const GEOM::ListOfGO& theShapes,
161                                      CORBA::Boolean        IsCheckSelfInte)
162 {
163   GEOM::GEOM_Object_var aGEOMObject;
164
165   //Set a not done flag
166   GetOperations()->SetNotDone();
167
168   Handle(TColStd_HSequenceOfTransient) aShapes =
169     GetListOfObjectsImpl(theShapes);
170
171   if (aShapes.IsNull()) {
172     return aGEOMObject._retn();
173   }
174
175   // Make fusion
176   Handle(::GEOM_Object) anObject =
177     GetOperations()->MakeCommonList(aShapes, IsCheckSelfInte);
178
179   if (!GetOperations()->IsDone() || anObject.IsNull())
180     return aGEOMObject._retn();
181
182   return GetObject(anObject);
183 }
184
185 //=============================================================================
186 /*!
187  *  MakeCutList
188  */
189 //=============================================================================
190 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeCutList
191                                     (GEOM::GEOM_Object_ptr theMainShape,
192                                      const GEOM::ListOfGO& theShapes,
193                                      CORBA::Boolean        IsCheckSelfInte)
194 {
195   GEOM::GEOM_Object_var aGEOMObject;
196
197   //Set a not done flag
198   GetOperations()->SetNotDone();
199
200   Handle(::GEOM_Object) aMainShape = GetObjectImpl(theMainShape);
201
202   if (aMainShape.IsNull()) {
203     return aGEOMObject._retn();
204   }
205
206   Handle(TColStd_HSequenceOfTransient) aShapes =
207     GetListOfObjectsImpl(theShapes);
208
209   if (aShapes.IsNull()) {
210     return aGEOMObject._retn();
211   }
212
213   // Make fusion
214   Handle(::GEOM_Object) anObject =
215     GetOperations()->MakeCutList(aMainShape, aShapes, IsCheckSelfInte);
216
217   if (!GetOperations()->IsDone() || anObject.IsNull())
218     return aGEOMObject._retn();
219
220   return GetObject(anObject);
221 }
222
223 //=============================================================================
224 /*!
225  *  MakePartition
226  */
227 //=============================================================================
228 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
229                                       (const GEOM::ListOfGO&   theShapes,
230                                        const GEOM::ListOfGO&   theTools,
231                                        const GEOM::ListOfGO&   theKeepIns,
232                                        const GEOM::ListOfGO&   theRemoveIns,
233                                        CORBA::Short            theLimit,
234                                        CORBA::Boolean          theRemoveWebs,
235                                        const GEOM::ListOfLong& theMaterials,
236                                        CORBA::Short theKeepNonlimitShapes)
237 {
238   GEOM::GEOM_Object_var aGEOMObject;
239
240   //Set a not done flag
241   GetOperations()->SetNotDone();
242
243   Handle(TColStd_HSequenceOfTransient) aShapes  = GetListOfObjectsImpl(theShapes);
244   Handle(TColStd_HSequenceOfTransient) aTools   = GetListOfObjectsImpl(theTools);
245   Handle(TColStd_HSequenceOfTransient) aKeepIns = GetListOfObjectsImpl(theKeepIns);
246   Handle(TColStd_HSequenceOfTransient) aRemIns  = GetListOfObjectsImpl(theRemoveIns);
247   Handle(TColStd_HArray1OfInteger) aMaterials;
248
249   if (aShapes.IsNull() || aTools.IsNull() ||
250       aKeepIns.IsNull() || aRemIns.IsNull()) {
251     return aGEOMObject._retn();
252   }
253
254   //Get the materials
255   int ind;
256   int aLen = theMaterials.length();
257   if ( aLen ) {
258     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
259     for (ind = 0; ind < aLen; ind++) {
260       aMaterials->SetValue(ind+1, theMaterials[ind]);
261     }
262   }
263
264   // Make Partition
265   Handle(::GEOM_Object) anObject =
266     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
267                                    theLimit, theRemoveWebs, aMaterials,
268                                    theKeepNonlimitShapes,
269                                    /*PerformSelfIntersections*/Standard_True,
270                                    /*IsCheckSelfInte*/Standard_False);
271   if (!GetOperations()->IsDone() || anObject.IsNull())
272     return aGEOMObject._retn();
273
274   return GetObject(anObject);
275 }
276
277 //=============================================================================
278 /*!
279  *  MakePartitionNonSelfIntersectedShape
280  */
281 //=============================================================================
282 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
283                                       (const GEOM::ListOfGO&   theShapes,
284                                        const GEOM::ListOfGO&   theTools,
285                                        const GEOM::ListOfGO&   theKeepIns,
286                                        const GEOM::ListOfGO&   theRemoveIns,
287                                        CORBA::Short            theLimit,
288                                        CORBA::Boolean          theRemoveWebs,
289                                        const GEOM::ListOfLong& theMaterials,
290                                        CORBA::Short theKeepNonlimitShapes,
291                                        CORBA::Boolean          IsCheckSelfInte)
292 {
293   GEOM::GEOM_Object_var aGEOMObject;
294
295   //Set a not done flag
296   GetOperations()->SetNotDone();
297
298   Handle(TColStd_HSequenceOfTransient) aShapes  = GetListOfObjectsImpl(theShapes);
299   Handle(TColStd_HSequenceOfTransient) aTools   = GetListOfObjectsImpl(theTools);
300   Handle(TColStd_HSequenceOfTransient) aKeepIns = GetListOfObjectsImpl(theKeepIns);
301   Handle(TColStd_HSequenceOfTransient) aRemIns  = GetListOfObjectsImpl(theRemoveIns);
302   Handle(TColStd_HArray1OfInteger) aMaterials;
303
304   if (aShapes.IsNull() || aTools.IsNull() ||
305       aKeepIns.IsNull() || aRemIns.IsNull()) {
306     return aGEOMObject._retn();
307   }
308
309   //Get the materials
310   int ind;
311   int aLen = theMaterials.length();
312   if ( aLen ) {
313     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
314     for (ind = 0; ind < aLen; ind++) {
315       aMaterials->SetValue(ind+1, theMaterials[ind]);
316     }
317   }
318
319   // Make Partition
320   Handle(::GEOM_Object) anObject =
321     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
322                                    theLimit, theRemoveWebs, aMaterials,
323                                    theKeepNonlimitShapes,
324                                    /*PerformSelfIntersections*/Standard_False,
325                                    IsCheckSelfInte);
326   if (!GetOperations()->IsDone() || anObject.IsNull())
327     return aGEOMObject._retn();
328
329   return GetObject(anObject);
330 }
331
332 //=============================================================================
333 /*!
334  *  MakeHalfPartition
335  */
336 //=============================================================================
337 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
338                                                  (GEOM::GEOM_Object_ptr theShape,
339                                                   GEOM::GEOM_Object_ptr thePlane)
340 {
341   GEOM::GEOM_Object_var aGEOMObject;
342
343   //Set a not done flag
344   GetOperations()->SetNotDone();
345
346   //Get the reference shapes
347   Handle(::GEOM_Object) aSh = GetObjectImpl(theShape);
348   Handle(::GEOM_Object) aPl = GetObjectImpl(thePlane);
349
350   if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
351
352   // Make Half Partition
353   Handle(::GEOM_Object) anObject =
354     GetOperations()->MakeHalfPartition(aSh, aPl);
355   if (!GetOperations()->IsDone() || anObject.IsNull())
356     return aGEOMObject._retn();
357
358   return GetObject(anObject);
359 }