Salome HOME
[bos #40619][CEA] Add Fuzzy parameter to partition and boolean operators
[modules/geom.git] / src / GEOM_I / GEOM_IBooleanOperations_i.cc
1 // Copyright (C) 2007-2024  CEA, EDF, 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   return MakeBooleanWithFuzzy(theShape1, theShape2, theOp, IsCheckSelfInte, -1.0);
71 }
72
73 //=============================================================================
74 /*!
75  *  MakeFuse
76  */
77 //=============================================================================
78 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeFuse
79                                     (GEOM::GEOM_Object_ptr theShape1,
80                                      GEOM::GEOM_Object_ptr theShape2,
81                                      CORBA::Boolean        IsCheckSelfInte,
82                                      CORBA::Boolean        IsRmExtraEdges)
83 {
84   return MakeFuseWithFuzzy(theShape1, theShape2, IsCheckSelfInte, IsRmExtraEdges, -1.0);
85 }
86
87 //=============================================================================
88 /*!
89  *  MakeFuseList
90  */
91 //=============================================================================
92 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeFuseList
93                                     (const GEOM::ListOfGO& theShapes,
94                                      CORBA::Boolean        IsCheckSelfInte,
95                                      CORBA::Boolean        IsRmExtraEdges)
96 {
97   return MakeFuseListWithFuzzy(theShapes, IsCheckSelfInte, IsRmExtraEdges, -1.0);
98 }
99
100 //=============================================================================
101 /*!
102  *  MakeCommonList
103  */
104 //=============================================================================
105 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeCommonList
106                                     (const GEOM::ListOfGO& theShapes,
107                                      CORBA::Boolean        IsCheckSelfInte)
108 {
109   return MakeCommonListWithFuzzy(theShapes, IsCheckSelfInte, -1.0);
110 }
111
112 //=============================================================================
113 /*!
114  *  MakeCutList
115  */
116 //=============================================================================
117 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeCutList
118                                     (GEOM::GEOM_Object_ptr theMainShape,
119                                      const GEOM::ListOfGO& theShapes,
120                                      CORBA::Boolean        IsCheckSelfInte)
121 {
122   return MakeCutListWithFuzzy(theMainShape, theShapes, IsCheckSelfInte, -1.0);
123 }
124
125 //=============================================================================
126 /*!
127  *  MakePartition
128  */
129 //=============================================================================
130 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
131                                       (const GEOM::ListOfGO&   theShapes,
132                                        const GEOM::ListOfGO&   theTools,
133                                        const GEOM::ListOfGO&   theKeepIns,
134                                        const GEOM::ListOfGO&   theRemoveIns,
135                                        CORBA::Short            theLimit,
136                                        CORBA::Boolean          theRemoveWebs,
137                                        const GEOM::ListOfLong& theMaterials,
138                                        CORBA::Short            theKeepNonlimitShapes)
139 {
140   return MakePartitionWithFuzzy(theShapes, theTools, theKeepIns, theRemoveIns, theLimit,
141                                 theRemoveWebs, theMaterials, theKeepNonlimitShapes, -1.0);
142 }
143
144 //=============================================================================
145 /*!
146  *  MakePartitionNonSelfIntersectedShape
147  */
148 //=============================================================================
149 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
150                                       (const GEOM::ListOfGO&   theShapes,
151                                        const GEOM::ListOfGO&   theTools,
152                                        const GEOM::ListOfGO&   theKeepIns,
153                                        const GEOM::ListOfGO&   theRemoveIns,
154                                        CORBA::Short            theLimit,
155                                        CORBA::Boolean          theRemoveWebs,
156                                        const GEOM::ListOfLong& theMaterials,
157                                        CORBA::Short            theKeepNonlimitShapes,
158                                        CORBA::Boolean          IsCheckSelfInte)
159 {
160   return MakePartitionNonSelfIntersectedShapeWithFuzzy(theShapes, theTools, theKeepIns, theRemoveIns,
161                                                        theLimit, theRemoveWebs, theMaterials,
162                                                        theKeepNonlimitShapes, IsCheckSelfInte, -1.0);
163 }
164
165 //=============================================================================
166 /*!
167  *  MakeHalfPartition
168  */
169 //=============================================================================
170 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
171                                                  (GEOM::GEOM_Object_ptr theShape,
172                                                   GEOM::GEOM_Object_ptr thePlane)
173 {
174   return MakeHalfPartitionWithFuzzy(theShape, thePlane, -1.0);
175 }
176
177
178
179 //=============================================================================
180 /*!
181  *  MakeBooleanWithFuzzy
182  */
183 //=============================================================================
184 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBooleanWithFuzzy
185                                     (GEOM::GEOM_Object_ptr theShape1,
186                                      GEOM::GEOM_Object_ptr theShape2,
187                                      CORBA::Long           theOp,
188                                      CORBA::Boolean        IsCheckSelfInte,
189                                      CORBA::Double         theFuzzyParam)
190 {
191   GEOM::GEOM_Object_var aGEOMObject;
192
193   //Set a not done flag
194   GetOperations()->SetNotDone();
195
196   //Get the reference shapes
197   Handle(::GEOM_Object) aSh1 = GetObjectImpl(theShape1);
198   Handle(::GEOM_Object) aSh2 = GetObjectImpl(theShape2);
199
200   if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
201
202   // Make Boolean
203   Handle(::GEOM_Object) anObject =
204     GetOperations()->MakeBoolean(aSh1, aSh2, theOp, IsCheckSelfInte, theFuzzyParam);
205   if (!GetOperations()->IsDone() || anObject.IsNull())
206     return aGEOMObject._retn();
207
208   return GetObject(anObject);
209 }
210
211 //=============================================================================
212 /*!
213  *  MakeFuseWithFuzzy
214  */
215 //=============================================================================
216 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeFuseWithFuzzy
217                                     (GEOM::GEOM_Object_ptr theShape1,
218                                      GEOM::GEOM_Object_ptr theShape2,
219                                      CORBA::Boolean        IsCheckSelfInte,
220                                      CORBA::Boolean        IsRmExtraEdges,
221                                      CORBA::Double         theFuzzyParam)
222 {
223   GEOM::GEOM_Object_var aGEOMObject;
224
225   //Set a not done flag
226   GetOperations()->SetNotDone();
227
228   //Get the reference shapes
229   Handle(::GEOM_Object) aSh1 = GetObjectImpl(theShape1);
230   Handle(::GEOM_Object) aSh2 = GetObjectImpl(theShape2);
231
232   if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
233
234   // Make Boolean
235   Handle(::GEOM_Object) anObject = GetOperations()->MakeFuse
236     (aSh1, aSh2, IsCheckSelfInte, IsRmExtraEdges, theFuzzyParam);
237
238   if (!GetOperations()->IsDone() || anObject.IsNull())
239     return aGEOMObject._retn();
240
241   return GetObject(anObject);
242 }
243
244 //=============================================================================
245 /*!
246  *  MakeFuseListWithFuzzy
247  */
248 //=============================================================================
249 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeFuseListWithFuzzy
250                                     (const GEOM::ListOfGO& theShapes,
251                                      CORBA::Boolean        IsCheckSelfInte,
252                                      CORBA::Boolean        IsRmExtraEdges,
253                                      CORBA::Double         theFuzzyParam)
254 {
255   GEOM::GEOM_Object_var aGEOMObject;
256
257   //Set a not done flag
258   GetOperations()->SetNotDone();
259
260   Handle(TColStd_HSequenceOfTransient) aShapes =
261     GetListOfObjectsImpl(theShapes);
262
263   if (aShapes.IsNull()) {
264     return aGEOMObject._retn();
265   }
266
267   // Make fusion
268   Handle(::GEOM_Object) anObject =
269     GetOperations()->MakeFuseList(aShapes, IsCheckSelfInte, IsRmExtraEdges, theFuzzyParam);
270
271   if (!GetOperations()->IsDone() || anObject.IsNull())
272     return aGEOMObject._retn();
273
274   return GetObject(anObject);
275 }
276
277 //=============================================================================
278 /*!
279  *  MakeCommonListWithFuzzy
280  */
281 //=============================================================================
282 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeCommonListWithFuzzy
283                                     (const GEOM::ListOfGO& theShapes,
284                                      CORBA::Boolean        IsCheckSelfInte,
285                                      CORBA::Double         theFuzzyParam)
286 {
287   GEOM::GEOM_Object_var aGEOMObject;
288
289   //Set a not done flag
290   GetOperations()->SetNotDone();
291
292   Handle(TColStd_HSequenceOfTransient) aShapes =
293     GetListOfObjectsImpl(theShapes);
294
295   if (aShapes.IsNull()) {
296     return aGEOMObject._retn();
297   }
298
299   // Make fusion
300   Handle(::GEOM_Object) anObject =
301     GetOperations()->MakeCommonList(aShapes, IsCheckSelfInte, theFuzzyParam);
302
303   if (!GetOperations()->IsDone() || anObject.IsNull())
304     return aGEOMObject._retn();
305
306   return GetObject(anObject);
307 }
308
309 //=============================================================================
310 /*!
311  *  MakeCutListWithFuzzy
312  */
313 //=============================================================================
314 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeCutListWithFuzzy
315                                     (GEOM::GEOM_Object_ptr theMainShape,
316                                      const GEOM::ListOfGO& theShapes,
317                                      CORBA::Boolean        IsCheckSelfInte,
318                                      CORBA::Double         theFuzzyParam)
319 {
320   GEOM::GEOM_Object_var aGEOMObject;
321
322   //Set a not done flag
323   GetOperations()->SetNotDone();
324
325   Handle(::GEOM_Object) aMainShape = GetObjectImpl(theMainShape);
326
327   if (aMainShape.IsNull()) {
328     return aGEOMObject._retn();
329   }
330
331   Handle(TColStd_HSequenceOfTransient) aShapes =
332     GetListOfObjectsImpl(theShapes);
333
334   if (aShapes.IsNull()) {
335     return aGEOMObject._retn();
336   }
337
338   // Make fusion
339   Handle(::GEOM_Object) anObject =
340     GetOperations()->MakeCutList(aMainShape, aShapes, IsCheckSelfInte, theFuzzyParam);
341
342   if (!GetOperations()->IsDone() || anObject.IsNull())
343     return aGEOMObject._retn();
344
345   return GetObject(anObject);
346 }
347
348 //=============================================================================
349 /*!
350  *  MakePartitionWithFuzzy
351  */
352 //=============================================================================
353 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionWithFuzzy
354                                       (const GEOM::ListOfGO&   theShapes,
355                                        const GEOM::ListOfGO&   theTools,
356                                        const GEOM::ListOfGO&   theKeepIns,
357                                        const GEOM::ListOfGO&   theRemoveIns,
358                                        CORBA::Short            theLimit,
359                                        CORBA::Boolean          theRemoveWebs,
360                                        const GEOM::ListOfLong& theMaterials,
361                                        CORBA::Short            theKeepNonlimitShapes,
362                                        CORBA::Double           theFuzzyParam)
363 {
364   GEOM::GEOM_Object_var aGEOMObject;
365
366   //Set a not done flag
367   GetOperations()->SetNotDone();
368
369   Handle(TColStd_HSequenceOfTransient) aShapes  = GetListOfObjectsImpl(theShapes);
370   Handle(TColStd_HSequenceOfTransient) aTools   = GetListOfObjectsImpl(theTools);
371   Handle(TColStd_HSequenceOfTransient) aKeepIns = GetListOfObjectsImpl(theKeepIns);
372   Handle(TColStd_HSequenceOfTransient) aRemIns  = GetListOfObjectsImpl(theRemoveIns);
373   Handle(TColStd_HArray1OfInteger) aMaterials;
374
375   if (aShapes.IsNull() || aTools.IsNull() ||
376       aKeepIns.IsNull() || aRemIns.IsNull()) {
377     return aGEOMObject._retn();
378   }
379
380   //Get the materials
381   int ind;
382   int aLen = theMaterials.length();
383   if ( aLen ) {
384     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
385     for (ind = 0; ind < aLen; ind++) {
386       aMaterials->SetValue(ind+1, theMaterials[ind]);
387     }
388   }
389
390   // Make Partition
391   Handle(::GEOM_Object) anObject =
392     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
393                                    theLimit, theRemoveWebs, aMaterials,
394                                    theKeepNonlimitShapes,
395                                    /*PerformSelfIntersections*/Standard_True,
396                                    /*IsCheckSelfInte*/Standard_False,
397                                    theFuzzyParam);
398   if (!GetOperations()->IsDone() || anObject.IsNull())
399     return aGEOMObject._retn();
400
401   return GetObject(anObject);
402 }
403
404 //=============================================================================
405 /*!
406  *  MakePartitionNonSelfIntersectedShapeWithFuzzy
407  */
408 //=============================================================================
409 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShapeWithFuzzy
410                                       (const GEOM::ListOfGO&   theShapes,
411                                        const GEOM::ListOfGO&   theTools,
412                                        const GEOM::ListOfGO&   theKeepIns,
413                                        const GEOM::ListOfGO&   theRemoveIns,
414                                        CORBA::Short            theLimit,
415                                        CORBA::Boolean          theRemoveWebs,
416                                        const GEOM::ListOfLong& theMaterials,
417                                        CORBA::Short theKeepNonlimitShapes,
418                                        CORBA::Boolean          IsCheckSelfInte,
419                                        CORBA::Double           theFuzzyParam)
420 {
421   GEOM::GEOM_Object_var aGEOMObject;
422
423   //Set a not done flag
424   GetOperations()->SetNotDone();
425
426   Handle(TColStd_HSequenceOfTransient) aShapes  = GetListOfObjectsImpl(theShapes);
427   Handle(TColStd_HSequenceOfTransient) aTools   = GetListOfObjectsImpl(theTools);
428   Handle(TColStd_HSequenceOfTransient) aKeepIns = GetListOfObjectsImpl(theKeepIns);
429   Handle(TColStd_HSequenceOfTransient) aRemIns  = GetListOfObjectsImpl(theRemoveIns);
430   Handle(TColStd_HArray1OfInteger) aMaterials;
431
432   if (aShapes.IsNull() || aTools.IsNull() ||
433       aKeepIns.IsNull() || aRemIns.IsNull()) {
434     return aGEOMObject._retn();
435   }
436
437   //Get the materials
438   int ind;
439   int aLen = theMaterials.length();
440   if ( aLen ) {
441     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
442     for (ind = 0; ind < aLen; ind++) {
443       aMaterials->SetValue(ind+1, theMaterials[ind]);
444     }
445   }
446
447   // Make Partition
448   Handle(::GEOM_Object) anObject =
449     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
450                                    theLimit, theRemoveWebs, aMaterials,
451                                    theKeepNonlimitShapes,
452                                    /*PerformSelfIntersections*/Standard_False,
453                                    IsCheckSelfInte,
454                                    theFuzzyParam);
455   if (!GetOperations()->IsDone() || anObject.IsNull())
456     return aGEOMObject._retn();
457
458   return GetObject(anObject);
459 }
460
461 //=============================================================================
462 /*!
463  *  MakeHalfPartitionWithFuzzy
464  */
465 //=============================================================================
466 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartitionWithFuzzy
467                                                  (GEOM::GEOM_Object_ptr theShape,
468                                                   GEOM::GEOM_Object_ptr thePlane,
469                                                   CORBA::Double         theFuzzyParam)
470 {
471   GEOM::GEOM_Object_var aGEOMObject;
472
473   //Set a not done flag
474   GetOperations()->SetNotDone();
475
476   //Get the reference shapes
477   Handle(::GEOM_Object) aSh = GetObjectImpl(theShape);
478   Handle(::GEOM_Object) aPl = GetObjectImpl(thePlane);
479
480   if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
481
482   // Make Half Partition
483   Handle(::GEOM_Object) anObject =
484     GetOperations()->MakeHalfPartition(aSh, aPl, theFuzzyParam);
485   if (!GetOperations()->IsDone() || anObject.IsNull())
486     return aGEOMObject._retn();
487
488   return GetObject(anObject);
489 }