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