Salome HOME
f21a9ee7283e83893c46cb383b56111cbd2de039
[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                                      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                                        CORBA::Boolean          IsCheckSelfInte)
205 {
206   GEOM::GEOM_Object_var aGEOMObject;
207
208   //Set a not done flag
209   GetOperations()->SetNotDone();
210
211   Handle(TColStd_HSequenceOfTransient) aShapes  = GetListOfObjectsImpl(theShapes);
212   Handle(TColStd_HSequenceOfTransient) aTools   = GetListOfObjectsImpl(theTools);
213   Handle(TColStd_HSequenceOfTransient) aKeepIns = GetListOfObjectsImpl(theKeepIns);
214   Handle(TColStd_HSequenceOfTransient) aRemIns  = GetListOfObjectsImpl(theRemoveIns);
215   Handle(TColStd_HArray1OfInteger) aMaterials;
216
217   if (aShapes.IsNull() || aTools.IsNull() ||
218       aKeepIns.IsNull() || aRemIns.IsNull()) {
219     return aGEOMObject._retn();
220   }
221
222   //Get the materials
223   int ind;
224   int aLen = theMaterials.length();
225   if ( aLen ) {
226     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
227     for (ind = 0; ind < aLen; ind++) {
228       aMaterials->SetValue(ind+1, theMaterials[ind]);
229     }
230   }
231
232   // Make Partition
233   Handle(GEOM_Object) anObject =
234     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
235                                    theLimit, theRemoveWebs, aMaterials,
236                                    theKeepNonlimitShapes,
237                                    /*PerformSelfIntersections*/Standard_True,
238                                    IsCheckSelfInte);
239   if (!GetOperations()->IsDone() || anObject.IsNull())
240     return aGEOMObject._retn();
241
242   return GetObject(anObject);
243 }
244
245 //=============================================================================
246 /*!
247  *  MakePartitionNonSelfIntersectedShape
248  */
249 //=============================================================================
250 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
251                                       (const GEOM::ListOfGO&   theShapes,
252                                        const GEOM::ListOfGO&   theTools,
253                                        const GEOM::ListOfGO&   theKeepIns,
254                                        const GEOM::ListOfGO&   theRemoveIns,
255                                        CORBA::Short            theLimit,
256                                        CORBA::Boolean          theRemoveWebs,
257                                        const GEOM::ListOfLong& theMaterials,
258                                        CORBA::Short theKeepNonlimitShapes,
259                                        CORBA::Boolean          IsCheckSelfInte)
260 {
261   GEOM::GEOM_Object_var aGEOMObject;
262
263   //Set a not done flag
264   GetOperations()->SetNotDone();
265
266   Handle(TColStd_HSequenceOfTransient) aShapes  = GetListOfObjectsImpl(theShapes);
267   Handle(TColStd_HSequenceOfTransient) aTools   = GetListOfObjectsImpl(theTools);
268   Handle(TColStd_HSequenceOfTransient) aKeepIns = GetListOfObjectsImpl(theKeepIns);
269   Handle(TColStd_HSequenceOfTransient) aRemIns  = GetListOfObjectsImpl(theRemoveIns);
270   Handle(TColStd_HArray1OfInteger) aMaterials;
271
272   if (aShapes.IsNull() || aTools.IsNull() ||
273       aKeepIns.IsNull() || aRemIns.IsNull()) {
274     return aGEOMObject._retn();
275   }
276
277   //Get the materials
278   int ind;
279   int aLen = theMaterials.length();
280   if ( aLen ) {
281     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
282     for (ind = 0; ind < aLen; ind++) {
283       aMaterials->SetValue(ind+1, theMaterials[ind]);
284     }
285   }
286
287   // Make Partition
288   Handle(GEOM_Object) anObject =
289     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
290                                    theLimit, theRemoveWebs, aMaterials,
291                                    theKeepNonlimitShapes,
292                                    /*PerformSelfIntersections*/Standard_False,
293                                    IsCheckSelfInte);
294   if (!GetOperations()->IsDone() || anObject.IsNull())
295     return aGEOMObject._retn();
296
297   return GetObject(anObject);
298 }
299
300 //=============================================================================
301 /*!
302  *  MakeHalfPartition
303  */
304 //=============================================================================
305 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
306                                                  (GEOM::GEOM_Object_ptr theShape,
307                                                   GEOM::GEOM_Object_ptr thePlane,
308                                                   CORBA::Boolean        IsCheckSelfInte)
309 {
310   GEOM::GEOM_Object_var aGEOMObject;
311
312   //Set a not done flag
313   GetOperations()->SetNotDone();
314
315   //Get the reference shapes
316   Handle(GEOM_Object) aSh = GetObjectImpl(theShape);
317   Handle(GEOM_Object) aPl = GetObjectImpl(thePlane);
318
319   if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
320
321   // Make Half Partition
322   Handle(GEOM_Object) anObject =
323     GetOperations()->MakeHalfPartition(aSh, aPl, IsCheckSelfInte);
324   if (!GetOperations()->IsDone() || anObject.IsNull())
325     return aGEOMObject._retn();
326
327   return GetObject(anObject);
328 }