]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_IBooleanOperations_i.cc
Salome HOME
Replace deprecated WNT macro definition by WIN32.
[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 {
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   if (!GetOperations()->IsDone() || anObject.IsNull())
238     return aGEOMObject._retn();
239
240   return GetObject(anObject);
241 }
242
243 //=============================================================================
244 /*!
245  *  MakePartitionNonSelfIntersectedShape
246  */
247 //=============================================================================
248 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
249                                       (const GEOM::ListOfGO&   theShapes,
250                                        const GEOM::ListOfGO&   theTools,
251                                        const GEOM::ListOfGO&   theKeepIns,
252                                        const GEOM::ListOfGO&   theRemoveIns,
253                                        CORBA::Short            theLimit,
254                                        CORBA::Boolean          theRemoveWebs,
255                                        const GEOM::ListOfLong& theMaterials,
256                                        CORBA::Short theKeepNonlimitShapes)
257 {
258   GEOM::GEOM_Object_var aGEOMObject;
259
260   //Set a not done flag
261   GetOperations()->SetNotDone();
262
263   Handle(TColStd_HSequenceOfTransient) aShapes  = GetListOfObjectsImpl(theShapes);
264   Handle(TColStd_HSequenceOfTransient) aTools   = GetListOfObjectsImpl(theTools);
265   Handle(TColStd_HSequenceOfTransient) aKeepIns = GetListOfObjectsImpl(theKeepIns);
266   Handle(TColStd_HSequenceOfTransient) aRemIns  = GetListOfObjectsImpl(theRemoveIns);
267   Handle(TColStd_HArray1OfInteger) aMaterials;
268
269   if (aShapes.IsNull() || aTools.IsNull() ||
270       aKeepIns.IsNull() || aRemIns.IsNull()) {
271     return aGEOMObject._retn();
272   }
273
274   //Get the materials
275   int ind;
276   int aLen = theMaterials.length();
277   if ( aLen ) {
278     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
279     for (ind = 0; ind < aLen; ind++) {
280       aMaterials->SetValue(ind+1, theMaterials[ind]);
281     }
282   }
283
284   // Make Partition
285   Handle(GEOM_Object) anObject =
286     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
287                                    theLimit, theRemoveWebs, aMaterials,
288                                    theKeepNonlimitShapes,
289                                    /*PerformSelfIntersections*/Standard_False);
290   if (!GetOperations()->IsDone() || anObject.IsNull())
291     return aGEOMObject._retn();
292
293   return GetObject(anObject);
294 }
295
296 //=============================================================================
297 /*!
298  *  MakeHalfPartition
299  */
300 //=============================================================================
301 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
302                                                  (GEOM::GEOM_Object_ptr theShape,
303                                                   GEOM::GEOM_Object_ptr thePlane)
304 {
305   GEOM::GEOM_Object_var aGEOMObject;
306
307   //Set a not done flag
308   GetOperations()->SetNotDone();
309
310   //Get the reference shapes
311   Handle(GEOM_Object) aSh = GetObjectImpl(theShape);
312   Handle(GEOM_Object) aPl = GetObjectImpl(thePlane);
313
314   if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
315
316   // Make Half Partition
317   Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
318   if (!GetOperations()->IsDone() || anObject.IsNull())
319     return aGEOMObject._retn();
320
321   return GetObject(anObject);
322 }