Salome HOME
0022490: [CEA 1057] Default tick of "Detect self-intersections" in Partition
[modules/geom.git] / src / GEOM_I / GEOM_IBooleanOperations_i.cc
1 // Copyright (C) 2007-2014  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  *  MakeFuseList
93  */
94 //=============================================================================
95 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeFuseList
96                                     (const GEOM::ListOfGO& theShapes,
97                                      CORBA::Boolean        IsCheckSelfInte)
98 {
99   GEOM::GEOM_Object_var aGEOMObject;
100
101   //Set a not done flag
102   GetOperations()->SetNotDone();
103
104   Handle(TColStd_HSequenceOfTransient) aShapes =
105     GetListOfObjectsImpl(theShapes);
106
107   if (aShapes.IsNull()) {
108     return aGEOMObject._retn();
109   }
110
111   // Make fusion
112   Handle(GEOM_Object) anObject =
113     GetOperations()->MakeFuseList(aShapes, IsCheckSelfInte);
114
115   if (!GetOperations()->IsDone() || anObject.IsNull())
116     return aGEOMObject._retn();
117
118   return GetObject(anObject);
119 }
120
121 //=============================================================================
122 /*!
123  *  MakeCommonList
124  */
125 //=============================================================================
126 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeCommonList
127                                     (const GEOM::ListOfGO& theShapes,
128                                      CORBA::Boolean        IsCheckSelfInte)
129 {
130   GEOM::GEOM_Object_var aGEOMObject;
131
132   //Set a not done flag
133   GetOperations()->SetNotDone();
134
135   Handle(TColStd_HSequenceOfTransient) aShapes =
136     GetListOfObjectsImpl(theShapes);
137
138   if (aShapes.IsNull()) {
139     return aGEOMObject._retn();
140   }
141
142   // Make fusion
143   Handle(GEOM_Object) anObject =
144     GetOperations()->MakeCommonList(aShapes, IsCheckSelfInte);
145
146   if (!GetOperations()->IsDone() || anObject.IsNull())
147     return aGEOMObject._retn();
148
149   return GetObject(anObject);
150 }
151
152 //=============================================================================
153 /*!
154  *  MakeCutList
155  */
156 //=============================================================================
157 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeCutList
158                                     (GEOM::GEOM_Object_ptr theMainShape,
159                                      const GEOM::ListOfGO& theShapes,
160                                      CORBA::Boolean        IsCheckSelfInte)
161 {
162   GEOM::GEOM_Object_var aGEOMObject;
163
164   //Set a not done flag
165   GetOperations()->SetNotDone();
166
167   Handle(GEOM_Object) aMainShape = GetObjectImpl(theMainShape);
168
169   if (aMainShape.IsNull()) {
170     return aGEOMObject._retn();
171   }
172
173   Handle(TColStd_HSequenceOfTransient) aShapes =
174     GetListOfObjectsImpl(theShapes);
175
176   if (aShapes.IsNull()) {
177     return aGEOMObject._retn();
178   }
179
180   // Make fusion
181   Handle(GEOM_Object) anObject =
182     GetOperations()->MakeCutList(aMainShape, aShapes, IsCheckSelfInte);
183
184   if (!GetOperations()->IsDone() || anObject.IsNull())
185     return aGEOMObject._retn();
186
187   return GetObject(anObject);
188 }
189
190 //=============================================================================
191 /*!
192  *  MakePartition
193  */
194 //=============================================================================
195 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
196                                       (const GEOM::ListOfGO&   theShapes,
197                                        const GEOM::ListOfGO&   theTools,
198                                        const GEOM::ListOfGO&   theKeepIns,
199                                        const GEOM::ListOfGO&   theRemoveIns,
200                                        CORBA::Short            theLimit,
201                                        CORBA::Boolean          theRemoveWebs,
202                                        const GEOM::ListOfLong& theMaterials,
203                                        CORBA::Short theKeepNonlimitShapes)
204 {
205   GEOM::GEOM_Object_var aGEOMObject;
206
207   //Set a not done flag
208   GetOperations()->SetNotDone();
209
210   Handle(TColStd_HSequenceOfTransient) aShapes  = GetListOfObjectsImpl(theShapes);
211   Handle(TColStd_HSequenceOfTransient) aTools   = GetListOfObjectsImpl(theTools);
212   Handle(TColStd_HSequenceOfTransient) aKeepIns = GetListOfObjectsImpl(theKeepIns);
213   Handle(TColStd_HSequenceOfTransient) aRemIns  = GetListOfObjectsImpl(theRemoveIns);
214   Handle(TColStd_HArray1OfInteger) aMaterials;
215
216   if (aShapes.IsNull() || aTools.IsNull() ||
217       aKeepIns.IsNull() || aRemIns.IsNull()) {
218     return aGEOMObject._retn();
219   }
220
221   //Get the materials
222   int ind;
223   int aLen = theMaterials.length();
224   if ( aLen ) {
225     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
226     for (ind = 0; ind < aLen; ind++) {
227       aMaterials->SetValue(ind+1, theMaterials[ind]);
228     }
229   }
230
231   // Make Partition
232   Handle(GEOM_Object) anObject =
233     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
234                                    theLimit, theRemoveWebs, aMaterials,
235                                    theKeepNonlimitShapes,
236                                    /*PerformSelfIntersections*/Standard_True,
237                                    /*IsCheckSelfInte*/Standard_False);
238   if (!GetOperations()->IsDone() || anObject.IsNull())
239     return aGEOMObject._retn();
240
241   return GetObject(anObject);
242 }
243
244 //=============================================================================
245 /*!
246  *  MakePartitionNonSelfIntersectedShape
247  */
248 //=============================================================================
249 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
250                                       (const GEOM::ListOfGO&   theShapes,
251                                        const GEOM::ListOfGO&   theTools,
252                                        const GEOM::ListOfGO&   theKeepIns,
253                                        const GEOM::ListOfGO&   theRemoveIns,
254                                        CORBA::Short            theLimit,
255                                        CORBA::Boolean          theRemoveWebs,
256                                        const GEOM::ListOfLong& theMaterials,
257                                        CORBA::Short theKeepNonlimitShapes,
258                                        CORBA::Boolean          IsCheckSelfInte)
259 {
260   GEOM::GEOM_Object_var aGEOMObject;
261
262   //Set a not done flag
263   GetOperations()->SetNotDone();
264
265   Handle(TColStd_HSequenceOfTransient) aShapes  = GetListOfObjectsImpl(theShapes);
266   Handle(TColStd_HSequenceOfTransient) aTools   = GetListOfObjectsImpl(theTools);
267   Handle(TColStd_HSequenceOfTransient) aKeepIns = GetListOfObjectsImpl(theKeepIns);
268   Handle(TColStd_HSequenceOfTransient) aRemIns  = GetListOfObjectsImpl(theRemoveIns);
269   Handle(TColStd_HArray1OfInteger) aMaterials;
270
271   if (aShapes.IsNull() || aTools.IsNull() ||
272       aKeepIns.IsNull() || aRemIns.IsNull()) {
273     return aGEOMObject._retn();
274   }
275
276   //Get the materials
277   int ind;
278   int aLen = theMaterials.length();
279   if ( aLen ) {
280     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
281     for (ind = 0; ind < aLen; ind++) {
282       aMaterials->SetValue(ind+1, theMaterials[ind]);
283     }
284   }
285
286   // Make Partition
287   Handle(GEOM_Object) anObject =
288     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
289                                    theLimit, theRemoveWebs, aMaterials,
290                                    theKeepNonlimitShapes,
291                                    /*PerformSelfIntersections*/Standard_False,
292                                    IsCheckSelfInte);
293   if (!GetOperations()->IsDone() || anObject.IsNull())
294     return aGEOMObject._retn();
295
296   return GetObject(anObject);
297 }
298
299 //=============================================================================
300 /*!
301  *  MakeHalfPartition
302  */
303 //=============================================================================
304 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
305                                                  (GEOM::GEOM_Object_ptr theShape,
306                                                   GEOM::GEOM_Object_ptr thePlane)
307 {
308   GEOM::GEOM_Object_var aGEOMObject;
309
310   //Set a not done flag
311   GetOperations()->SetNotDone();
312
313   //Get the reference shapes
314   Handle(GEOM_Object) aSh = GetObjectImpl(theShape);
315   Handle(GEOM_Object) aPl = GetObjectImpl(thePlane);
316
317   if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
318
319   // Make Half Partition
320   Handle(GEOM_Object) anObject =
321     GetOperations()->MakeHalfPartition(aSh, aPl);
322   if (!GetOperations()->IsDone() || anObject.IsNull())
323     return aGEOMObject._retn();
324
325   return GetObject(anObject);
326 }