Salome HOME
Join modifications from V3_2_0_maintainance (V3_2_6pre4 - T32x_16Aug2007_16h00m)
[modules/geom.git] / src / GEOM_I / GEOM_IBooleanOperations_i.cc
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
8 //
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include <Standard_Stream.hxx>
22
23 #include "GEOM_IBooleanOperations_i.hh"
24
25 #include "utilities.h"
26 #include "OpUtil.hxx"
27
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
30
31 #include <TColStd_HArray1OfInteger.hxx>
32
33 //=============================================================================
34 /*!
35  *   constructor:
36  */
37 //=============================================================================
38 GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i (PortableServer::POA_ptr thePOA,
39                                                       GEOM::GEOM_Gen_ptr theEngine,
40                                                       ::GEOMImpl_IBooleanOperations* theImpl)
41 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
42 {
43   MESSAGE("GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i");
44 }
45
46 //=============================================================================
47 /*!
48  *  destructor
49  */
50 //=============================================================================
51 GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i()
52 {
53   MESSAGE("GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i");
54 }
55
56
57 //=============================================================================
58 /*!
59  *  MakeBoolean
60  */
61 //=============================================================================
62 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBoolean
63                                                  (GEOM::GEOM_Object_ptr theShape1,
64                                                   GEOM::GEOM_Object_ptr theShape2,
65                                                   CORBA::Long           theOp)
66 {
67   GEOM::GEOM_Object_var aGEOMObject;
68
69   //Set a not done flag
70   GetOperations()->SetNotDone();
71
72   if (theShape1 == NULL || theShape2 == NULL) return aGEOMObject._retn();
73
74   //Get the reference shapes
75   Handle(GEOM_Object) aSh1 = GetOperations()->GetEngine()->GetObject
76     (theShape1->GetStudyID(), theShape1->GetEntry());
77   Handle(GEOM_Object) aSh2 = GetOperations()->GetEngine()->GetObject
78     (theShape2->GetStudyID(), theShape2->GetEntry());
79
80   if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
81
82   // Make Boolean
83   Handle(GEOM_Object) anObject = GetOperations()->MakeBoolean(aSh1, aSh2, theOp);
84   if (!GetOperations()->IsDone() || anObject.IsNull())
85     return aGEOMObject._retn();
86
87   return GetObject(anObject);
88 }
89
90 //=============================================================================
91 /*!
92  *  MakePartition
93  */
94 //=============================================================================
95 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
96                                       (const GEOM::ListOfGO&   theShapes,
97                                        const GEOM::ListOfGO&   theTools,
98                                        const GEOM::ListOfGO&   theKeepIns,
99                                        const GEOM::ListOfGO&   theRemoveIns,
100                                        CORBA::Short            theLimit,
101                                        CORBA::Boolean          theRemoveWebs,
102                                        const GEOM::ListOfLong& theMaterials,
103                                        CORBA::Short theKeepNonlimitShapes)
104 {
105   GEOM::GEOM_Object_var aGEOMObject;
106
107   //Set a not done flag
108   GetOperations()->SetNotDone();
109
110   int ind, aLen;
111   Handle(TColStd_HSequenceOfTransient) aShapes  = new TColStd_HSequenceOfTransient;
112   Handle(TColStd_HSequenceOfTransient) aTools   = new TColStd_HSequenceOfTransient;
113   Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
114   Handle(TColStd_HSequenceOfTransient) aRemIns  = new TColStd_HSequenceOfTransient;
115   Handle(TColStd_HArray1OfInteger) aMaterials;
116
117   //Get the shapes
118   aLen = theShapes.length();
119   for (ind = 0; ind < aLen; ind++) {
120     if (theShapes[ind] == NULL) return aGEOMObject._retn();
121     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
122       (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
123     if (aSh.IsNull()) return aGEOMObject._retn();
124     aShapes->Append(aSh);
125   }
126
127   //Get the tools
128   aLen = theTools.length();
129   for (ind = 0; ind < aLen; ind++) {
130     if (theTools[ind] == NULL) return aGEOMObject._retn();
131     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
132       (theTools[ind]->GetStudyID(), theTools[ind]->GetEntry());
133     if (aSh.IsNull()) return aGEOMObject._retn();
134     aTools->Append(aSh);
135   }
136
137   //Get the keep inside shapes
138   aLen = theKeepIns.length();
139   for (ind = 0; ind < aLen; ind++) {
140     if (theKeepIns[ind] == NULL) return aGEOMObject._retn();
141     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
142       (theKeepIns[ind]->GetStudyID(), theKeepIns[ind]->GetEntry());
143     if (aSh.IsNull()) return aGEOMObject._retn();
144     aKeepIns->Append(aSh);
145   }
146
147   //Get the remove inside shapes
148   aLen = theRemoveIns.length();
149   for (ind = 0; ind < aLen; ind++) {
150     if (theRemoveIns[ind] == NULL) return aGEOMObject._retn();
151     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
152       (theRemoveIns[ind]->GetStudyID(), theRemoveIns[ind]->GetEntry());
153     if (aSh.IsNull()) return aGEOMObject._retn();
154     aRemIns->Append(aSh);
155   }
156
157   //Get the materials
158   aLen = theMaterials.length();
159   if ( aLen ) {
160     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
161     for (ind = 0; ind < aLen; ind++) {
162       aMaterials->SetValue(ind+1, theMaterials[ind]);
163     }
164   }
165
166   // Make Partition
167   Handle(GEOM_Object) anObject =
168     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
169                                    theLimit, theRemoveWebs, aMaterials,
170                                    theKeepNonlimitShapes,
171                                    /*PerformSelfIntersections*/Standard_True);
172   if (!GetOperations()->IsDone() || anObject.IsNull())
173     return aGEOMObject._retn();
174
175   return GetObject(anObject);
176 }
177
178 //=============================================================================
179 /*!
180  *  MakePartitionNonSelfIntersectedShape
181  */
182 //=============================================================================
183 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
184                                       (const GEOM::ListOfGO&   theShapes,
185                                        const GEOM::ListOfGO&   theTools,
186                                        const GEOM::ListOfGO&   theKeepIns,
187                                        const GEOM::ListOfGO&   theRemoveIns,
188                                        CORBA::Short            theLimit,
189                                        CORBA::Boolean          theRemoveWebs,
190                                        const GEOM::ListOfLong& theMaterials,
191                                        CORBA::Short theKeepNonlimitShapes)
192 {
193   GEOM::GEOM_Object_var aGEOMObject;
194
195   //Set a not done flag
196   GetOperations()->SetNotDone();
197
198   int ind, aLen;
199   Handle(TColStd_HSequenceOfTransient) aShapes  = new TColStd_HSequenceOfTransient;
200   Handle(TColStd_HSequenceOfTransient) aTools   = new TColStd_HSequenceOfTransient;
201   Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
202   Handle(TColStd_HSequenceOfTransient) aRemIns  = new TColStd_HSequenceOfTransient;
203   Handle(TColStd_HArray1OfInteger) aMaterials;
204
205   //Get the shapes
206   aLen = theShapes.length();
207   for (ind = 0; ind < aLen; ind++) {
208     if (theShapes[ind] == NULL) return aGEOMObject._retn();
209     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
210       (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
211     if (aSh.IsNull()) return aGEOMObject._retn();
212     aShapes->Append(aSh);
213   }
214
215   //Get the tools
216   aLen = theTools.length();
217   for (ind = 0; ind < aLen; ind++) {
218     if (theTools[ind] == NULL) return aGEOMObject._retn();
219     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
220       (theTools[ind]->GetStudyID(), theTools[ind]->GetEntry());
221     if (aSh.IsNull()) return aGEOMObject._retn();
222     aTools->Append(aSh);
223   }
224
225   //Get the keep inside shapes
226   aLen = theKeepIns.length();
227   for (ind = 0; ind < aLen; ind++) {
228     if (theKeepIns[ind] == NULL) return aGEOMObject._retn();
229     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
230       (theKeepIns[ind]->GetStudyID(), theKeepIns[ind]->GetEntry());
231     if (aSh.IsNull()) return aGEOMObject._retn();
232     aKeepIns->Append(aSh);
233   }
234
235   //Get the remove inside shapes
236   aLen = theRemoveIns.length();
237   for (ind = 0; ind < aLen; ind++) {
238     if (theRemoveIns[ind] == NULL) return aGEOMObject._retn();
239     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
240       (theRemoveIns[ind]->GetStudyID(), theRemoveIns[ind]->GetEntry());
241     if (aSh.IsNull()) return aGEOMObject._retn();
242     aRemIns->Append(aSh);
243   }
244
245   //Get the materials
246   aLen = theMaterials.length();
247   if ( aLen ) {
248     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
249     for (ind = 0; ind < aLen; ind++) {
250       aMaterials->SetValue(ind+1, theMaterials[ind]);
251     }
252   }
253
254   // Make Partition
255   Handle(GEOM_Object) anObject =
256     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
257                                    theLimit, theRemoveWebs, aMaterials,
258                                    theKeepNonlimitShapes,
259                                    /*PerformSelfIntersections*/Standard_False);
260   if (!GetOperations()->IsDone() || anObject.IsNull())
261     return aGEOMObject._retn();
262
263   return GetObject(anObject);
264 }
265
266 //=============================================================================
267 /*!
268  *  MakeHalfPartition
269  */
270 //=============================================================================
271 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
272                                                  (GEOM::GEOM_Object_ptr theShape,
273                                                   GEOM::GEOM_Object_ptr thePlane)
274 {
275   GEOM::GEOM_Object_var aGEOMObject;
276
277   //Set a not done flag
278   GetOperations()->SetNotDone();
279
280   if (theShape == NULL || thePlane == NULL) return aGEOMObject._retn();
281
282   //Get the reference shapes
283   Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
284     (theShape->GetStudyID(), theShape->GetEntry());
285   Handle(GEOM_Object) aPl = GetOperations()->GetEngine()->GetObject
286     (thePlane->GetStudyID(), thePlane->GetEntry());
287
288   if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
289
290   // Make Half Partition
291   Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
292   if (!GetOperations()->IsDone() || anObject.IsNull())
293     return aGEOMObject._retn();
294
295   return GetObject(anObject);
296 }