Salome HOME
Merge from V6_main 01/04/2013
[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 {
69   GEOM::GEOM_Object_var aGEOMObject;
70
71   //Set a not done flag
72   GetOperations()->SetNotDone();
73
74   //Get the reference shapes
75   Handle(GEOM_Object) aSh1 = GetObjectImpl(theShape1);
76   Handle(GEOM_Object) aSh2 = GetObjectImpl(theShape2);
77
78   if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
79
80   // Make Boolean
81   Handle(GEOM_Object) anObject = GetOperations()->MakeBoolean(aSh1, aSh2, theOp);
82   if (!GetOperations()->IsDone() || anObject.IsNull())
83     return aGEOMObject._retn();
84
85   return GetObject(anObject);
86 }
87
88 //=============================================================================
89 /*!
90  *  MakePartition
91  */
92 //=============================================================================
93 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
94                                       (const GEOM::ListOfGO&   theShapes,
95                                        const GEOM::ListOfGO&   theTools,
96                                        const GEOM::ListOfGO&   theKeepIns,
97                                        const GEOM::ListOfGO&   theRemoveIns,
98                                        CORBA::Short            theLimit,
99                                        CORBA::Boolean          theRemoveWebs,
100                                        const GEOM::ListOfLong& theMaterials,
101                                        CORBA::Short theKeepNonlimitShapes)
102 {
103   GEOM::GEOM_Object_var aGEOMObject;
104
105   //Set a not done flag
106   GetOperations()->SetNotDone();
107
108   int ind, aLen;
109   Handle(TColStd_HSequenceOfTransient) aShapes  = new TColStd_HSequenceOfTransient;
110   Handle(TColStd_HSequenceOfTransient) aTools   = new TColStd_HSequenceOfTransient;
111   Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
112   Handle(TColStd_HSequenceOfTransient) aRemIns  = new TColStd_HSequenceOfTransient;
113   Handle(TColStd_HArray1OfInteger) aMaterials;
114
115   //Get the shapes
116   aLen = theShapes.length();
117   for (ind = 0; ind < aLen; ind++) {
118     Handle(GEOM_Object) aSh = GetObjectImpl(theShapes[ind]);
119     if (aSh.IsNull()) return aGEOMObject._retn();
120     aShapes->Append(aSh);
121   }
122
123   //Get the tools
124   aLen = theTools.length();
125   for (ind = 0; ind < aLen; ind++) {
126     Handle(GEOM_Object) aSh = GetObjectImpl(theTools[ind]);
127     if (aSh.IsNull()) return aGEOMObject._retn();
128     aTools->Append(aSh);
129   }
130
131   //Get the keep inside shapes
132   aLen = theKeepIns.length();
133   for (ind = 0; ind < aLen; ind++) {
134     Handle(GEOM_Object) aSh = GetObjectImpl(theKeepIns[ind]);
135     if (aSh.IsNull()) return aGEOMObject._retn();
136     aKeepIns->Append(aSh);
137   }
138
139   //Get the remove inside shapes
140   aLen = theRemoveIns.length();
141   for (ind = 0; ind < aLen; ind++) {
142     Handle(GEOM_Object) aSh = GetObjectImpl(theRemoveIns[ind]);
143     if (aSh.IsNull()) return aGEOMObject._retn();
144     aRemIns->Append(aSh);
145   }
146
147   //Get the materials
148   aLen = theMaterials.length();
149   if ( aLen ) {
150     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
151     for (ind = 0; ind < aLen; ind++) {
152       aMaterials->SetValue(ind+1, theMaterials[ind]);
153     }
154   }
155
156   // Make Partition
157   Handle(GEOM_Object) anObject =
158     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
159                                    theLimit, theRemoveWebs, aMaterials,
160                                    theKeepNonlimitShapes,
161                                    /*PerformSelfIntersections*/Standard_True);
162   if (!GetOperations()->IsDone() || anObject.IsNull())
163     return aGEOMObject._retn();
164
165   return GetObject(anObject);
166 }
167
168 //=============================================================================
169 /*!
170  *  MakePartitionNonSelfIntersectedShape
171  */
172 //=============================================================================
173 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
174                                       (const GEOM::ListOfGO&   theShapes,
175                                        const GEOM::ListOfGO&   theTools,
176                                        const GEOM::ListOfGO&   theKeepIns,
177                                        const GEOM::ListOfGO&   theRemoveIns,
178                                        CORBA::Short            theLimit,
179                                        CORBA::Boolean          theRemoveWebs,
180                                        const GEOM::ListOfLong& theMaterials,
181                                        CORBA::Short theKeepNonlimitShapes)
182 {
183   GEOM::GEOM_Object_var aGEOMObject;
184
185   //Set a not done flag
186   GetOperations()->SetNotDone();
187
188   int ind, aLen;
189   Handle(TColStd_HSequenceOfTransient) aShapes  = new TColStd_HSequenceOfTransient;
190   Handle(TColStd_HSequenceOfTransient) aTools   = new TColStd_HSequenceOfTransient;
191   Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
192   Handle(TColStd_HSequenceOfTransient) aRemIns  = new TColStd_HSequenceOfTransient;
193   Handle(TColStd_HArray1OfInteger) aMaterials;
194
195   //Get the shapes
196   aLen = theShapes.length();
197   for (ind = 0; ind < aLen; ind++) {
198     Handle(GEOM_Object) aSh = GetObjectImpl(theShapes[ind]);
199     if (aSh.IsNull()) return aGEOMObject._retn();
200     aShapes->Append(aSh);
201   }
202
203   //Get the tools
204   aLen = theTools.length();
205   for (ind = 0; ind < aLen; ind++) {
206     Handle(GEOM_Object) aSh = GetObjectImpl(theTools[ind]);
207     if (aSh.IsNull()) return aGEOMObject._retn();
208     aTools->Append(aSh);
209   }
210
211   //Get the keep inside shapes
212   aLen = theKeepIns.length();
213   for (ind = 0; ind < aLen; ind++) {
214     Handle(GEOM_Object) aSh = GetObjectImpl(theKeepIns[ind]);
215     if (aSh.IsNull()) return aGEOMObject._retn();
216     aKeepIns->Append(aSh);
217   }
218
219   //Get the remove inside shapes
220   aLen = theRemoveIns.length();
221   for (ind = 0; ind < aLen; ind++) {
222     Handle(GEOM_Object) aSh = GetObjectImpl(theRemoveIns[ind]);
223     if (aSh.IsNull()) return aGEOMObject._retn();
224     aRemIns->Append(aSh);
225   }
226
227   //Get the materials
228   aLen = theMaterials.length();
229   if ( aLen ) {
230     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
231     for (ind = 0; ind < aLen; ind++) {
232       aMaterials->SetValue(ind+1, theMaterials[ind]);
233     }
234   }
235
236   // Make Partition
237   Handle(GEOM_Object) anObject =
238     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
239                                    theLimit, theRemoveWebs, aMaterials,
240                                    theKeepNonlimitShapes,
241                                    /*PerformSelfIntersections*/Standard_False);
242   if (!GetOperations()->IsDone() || anObject.IsNull())
243     return aGEOMObject._retn();
244
245   return GetObject(anObject);
246 }
247
248 //=============================================================================
249 /*!
250  *  MakeHalfPartition
251  */
252 //=============================================================================
253 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
254                                                  (GEOM::GEOM_Object_ptr theShape,
255                                                   GEOM::GEOM_Object_ptr thePlane)
256 {
257   GEOM::GEOM_Object_var aGEOMObject;
258
259   //Set a not done flag
260   GetOperations()->SetNotDone();
261
262   //Get the reference shapes
263   Handle(GEOM_Object) aSh = GetObjectImpl(theShape);
264   Handle(GEOM_Object) aPl = GetObjectImpl(thePlane);
265
266   if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
267
268   // Make Half Partition
269   Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
270   if (!GetOperations()->IsDone() || anObject.IsNull())
271     return aGEOMObject._retn();
272
273   return GetObject(anObject);
274 }