Salome HOME
Use the prefix std:: instead of the directive using namespace std;
[modules/geom.git] / src / GEOM_I / GEOM_IBooleanOperations_i.cc
1 //  Copyright (C) 2007-2008  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 #include <Standard_Stream.hxx>
23
24 #include "GEOM_IBooleanOperations_i.hh"
25
26 #include "utilities.h"
27 #include "OpUtil.hxx"
28
29 #include "GEOM_Engine.hxx"
30 #include "GEOM_Object.hxx"
31
32 #include <TColStd_HArray1OfInteger.hxx>
33
34 //=============================================================================
35 /*!
36  *   constructor:
37  */
38 //=============================================================================
39 GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i (PortableServer::POA_ptr thePOA,
40                                                       GEOM::GEOM_Gen_ptr theEngine,
41                                                       ::GEOMImpl_IBooleanOperations* theImpl)
42 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
43 {
44   MESSAGE("GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i");
45 }
46
47 //=============================================================================
48 /*!
49  *  destructor
50  */
51 //=============================================================================
52 GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i()
53 {
54   MESSAGE("GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i");
55 }
56
57
58 //=============================================================================
59 /*!
60  *  MakeBoolean
61  */
62 //=============================================================================
63 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBoolean
64                                                  (GEOM::GEOM_Object_ptr theShape1,
65                                                   GEOM::GEOM_Object_ptr theShape2,
66                                                   CORBA::Long           theOp)
67 {
68   GEOM::GEOM_Object_var aGEOMObject;
69
70   //Set a not done flag
71   GetOperations()->SetNotDone();
72
73   //Get the reference shapes
74   Handle(GEOM_Object) aSh1 = GetObjectImpl(theShape1);
75   Handle(GEOM_Object) aSh2 = GetObjectImpl(theShape2);
76
77   if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
78
79   // Make Boolean
80   Handle(GEOM_Object) anObject = GetOperations()->MakeBoolean(aSh1, aSh2, theOp);
81   if (!GetOperations()->IsDone() || anObject.IsNull())
82     return aGEOMObject._retn();
83
84   return GetObject(anObject);
85 }
86
87 //=============================================================================
88 /*!
89  *  MakePartition
90  */
91 //=============================================================================
92 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
93                                       (const GEOM::ListOfGO&   theShapes,
94                                        const GEOM::ListOfGO&   theTools,
95                                        const GEOM::ListOfGO&   theKeepIns,
96                                        const GEOM::ListOfGO&   theRemoveIns,
97                                        CORBA::Short            theLimit,
98                                        CORBA::Boolean          theRemoveWebs,
99                                        const GEOM::ListOfLong& theMaterials,
100                                        CORBA::Short theKeepNonlimitShapes)
101 {
102   GEOM::GEOM_Object_var aGEOMObject;
103
104   //Set a not done flag
105   GetOperations()->SetNotDone();
106
107   int ind, aLen;
108   Handle(TColStd_HSequenceOfTransient) aShapes  = new TColStd_HSequenceOfTransient;
109   Handle(TColStd_HSequenceOfTransient) aTools   = new TColStd_HSequenceOfTransient;
110   Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
111   Handle(TColStd_HSequenceOfTransient) aRemIns  = new TColStd_HSequenceOfTransient;
112   Handle(TColStd_HArray1OfInteger) aMaterials;
113
114   //Get the shapes
115   aLen = theShapes.length();
116   for (ind = 0; ind < aLen; ind++) {
117     Handle(GEOM_Object) aSh = GetObjectImpl(theShapes[ind]);
118     if (aSh.IsNull()) return aGEOMObject._retn();
119     aShapes->Append(aSh);
120   }
121
122   //Get the tools
123   aLen = theTools.length();
124   for (ind = 0; ind < aLen; ind++) {
125     Handle(GEOM_Object) aSh = GetObjectImpl(theTools[ind]);
126     if (aSh.IsNull()) return aGEOMObject._retn();
127     aTools->Append(aSh);
128   }
129
130   //Get the keep inside shapes
131   aLen = theKeepIns.length();
132   for (ind = 0; ind < aLen; ind++) {
133     Handle(GEOM_Object) aSh = GetObjectImpl(theKeepIns[ind]);
134     if (aSh.IsNull()) return aGEOMObject._retn();
135     aKeepIns->Append(aSh);
136   }
137
138   //Get the remove inside shapes
139   aLen = theRemoveIns.length();
140   for (ind = 0; ind < aLen; ind++) {
141     Handle(GEOM_Object) aSh = GetObjectImpl(theRemoveIns[ind]);
142     if (aSh.IsNull()) return aGEOMObject._retn();
143     aRemIns->Append(aSh);
144   }
145
146   //Get the materials
147   aLen = theMaterials.length();
148   if ( aLen ) {
149     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
150     for (ind = 0; ind < aLen; ind++) {
151       aMaterials->SetValue(ind+1, theMaterials[ind]);
152     }
153   }
154
155   // Make Partition
156   Handle(GEOM_Object) anObject =
157     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
158                                    theLimit, theRemoveWebs, aMaterials,
159                                    theKeepNonlimitShapes,
160                                    /*PerformSelfIntersections*/Standard_True);
161   if (!GetOperations()->IsDone() || anObject.IsNull())
162     return aGEOMObject._retn();
163
164   return GetObject(anObject);
165 }
166
167 //=============================================================================
168 /*!
169  *  MakePartitionNonSelfIntersectedShape
170  */
171 //=============================================================================
172 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
173                                       (const GEOM::ListOfGO&   theShapes,
174                                        const GEOM::ListOfGO&   theTools,
175                                        const GEOM::ListOfGO&   theKeepIns,
176                                        const GEOM::ListOfGO&   theRemoveIns,
177                                        CORBA::Short            theLimit,
178                                        CORBA::Boolean          theRemoveWebs,
179                                        const GEOM::ListOfLong& theMaterials,
180                                        CORBA::Short theKeepNonlimitShapes)
181 {
182   GEOM::GEOM_Object_var aGEOMObject;
183
184   //Set a not done flag
185   GetOperations()->SetNotDone();
186
187   int ind, aLen;
188   Handle(TColStd_HSequenceOfTransient) aShapes  = new TColStd_HSequenceOfTransient;
189   Handle(TColStd_HSequenceOfTransient) aTools   = new TColStd_HSequenceOfTransient;
190   Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
191   Handle(TColStd_HSequenceOfTransient) aRemIns  = new TColStd_HSequenceOfTransient;
192   Handle(TColStd_HArray1OfInteger) aMaterials;
193
194   //Get the shapes
195   aLen = theShapes.length();
196   for (ind = 0; ind < aLen; ind++) {
197     Handle(GEOM_Object) aSh = GetObjectImpl(theShapes[ind]);
198     if (aSh.IsNull()) return aGEOMObject._retn();
199     aShapes->Append(aSh);
200   }
201
202   //Get the tools
203   aLen = theTools.length();
204   for (ind = 0; ind < aLen; ind++) {
205     Handle(GEOM_Object) aSh = GetObjectImpl(theTools[ind]);
206     if (aSh.IsNull()) return aGEOMObject._retn();
207     aTools->Append(aSh);
208   }
209
210   //Get the keep inside shapes
211   aLen = theKeepIns.length();
212   for (ind = 0; ind < aLen; ind++) {
213     Handle(GEOM_Object) aSh = GetObjectImpl(theKeepIns[ind]);
214     if (aSh.IsNull()) return aGEOMObject._retn();
215     aKeepIns->Append(aSh);
216   }
217
218   //Get the remove inside shapes
219   aLen = theRemoveIns.length();
220   for (ind = 0; ind < aLen; ind++) {
221     Handle(GEOM_Object) aSh = GetObjectImpl(theRemoveIns[ind]);
222     if (aSh.IsNull()) return aGEOMObject._retn();
223     aRemIns->Append(aSh);
224   }
225
226   //Get the materials
227   aLen = theMaterials.length();
228   if ( aLen ) {
229     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
230     for (ind = 0; ind < aLen; ind++) {
231       aMaterials->SetValue(ind+1, theMaterials[ind]);
232     }
233   }
234
235   // Make Partition
236   Handle(GEOM_Object) anObject =
237     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
238                                    theLimit, theRemoveWebs, aMaterials,
239                                    theKeepNonlimitShapes,
240                                    /*PerformSelfIntersections*/Standard_False);
241   if (!GetOperations()->IsDone() || anObject.IsNull())
242     return aGEOMObject._retn();
243
244   return GetObject(anObject);
245 }
246
247 //=============================================================================
248 /*!
249  *  MakeHalfPartition
250  */
251 //=============================================================================
252 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
253                                                  (GEOM::GEOM_Object_ptr theShape,
254                                                   GEOM::GEOM_Object_ptr thePlane)
255 {
256   GEOM::GEOM_Object_var aGEOMObject;
257
258   //Set a not done flag
259   GetOperations()->SetNotDone();
260
261   //Get the reference shapes
262   Handle(GEOM_Object) aSh = GetObjectImpl(theShape);
263   Handle(GEOM_Object) aPl = GetObjectImpl(thePlane);
264
265   if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
266
267   // Make Half Partition
268   Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
269   if (!GetOperations()->IsDone() || anObject.IsNull())
270     return aGEOMObject._retn();
271
272   return GetObject(anObject);
273 }