]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_IGroupOperations_i.cc
Salome HOME
60a26e129bece1f5fd8fdf3bfe7d60900f3aead4
[modules/geom.git] / src / GEOM_I / GEOM_IGroupOperations_i.cc
1 // Copyright (C) 2007-2012  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_IGroupOperations_i.hh"
25
26 #include "utilities.h"
27 #include "OpUtil.hxx"
28 #include "Utils_ExceptHandlers.hxx"
29
30 #include "GEOM_Engine.hxx"
31 #include "GEOM_Object.hxx"
32
33 #include <TColStd_HArray1OfInteger.hxx>
34 #include <TopAbs.hxx>
35
36 //=============================================================================
37 /*!
38  *   constructor:
39  */
40 //=============================================================================
41 GEOM_IGroupOperations_i::GEOM_IGroupOperations_i (PortableServer::POA_ptr thePOA,
42                                                   GEOM::GEOM_Gen_ptr theEngine,
43                                                   ::GEOMImpl_IGroupOperations* theImpl)
44      :GEOM_IOperations_i(thePOA, theEngine, theImpl)
45 {
46   MESSAGE("GEOM_IGroupOperations_i::GEOM_IGroupOperations_i");
47 }
48
49 //=============================================================================
50 /*!
51  *  destructor
52  */
53 //=============================================================================
54 GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i()
55 {
56   MESSAGE("GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i");
57 }
58
59
60 //=============================================================================
61 /*!
62  *  CreateGroup
63  */
64 //=============================================================================
65 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CreateGroup(GEOM::GEOM_Object_ptr theMainShape,
66                                                            CORBA::Long theShapeType)
67 {
68   GEOM::GEOM_Object_var aGEOMObject;
69
70   //Set a not done flag
71   GetOperations()->SetNotDone();
72
73   if (theShapeType < 0) return aGEOMObject._retn();
74
75   //Get the reference shape
76   Handle(GEOM_Object) aShapeRef = GetObjectImpl(theMainShape);
77   if (aShapeRef.IsNull()) return aGEOMObject._retn();
78
79   //Create the Fillet
80   Handle(GEOM_Object) anObject = GetOperations()->CreateGroup(aShapeRef, (TopAbs_ShapeEnum)theShapeType);
81   if (!GetOperations()->IsDone() || anObject.IsNull())
82     return aGEOMObject._retn();
83
84   return GetObject(anObject);
85 }
86
87 //=============================================================================
88 /*!
89  *  AddObject
90  */
91 //=============================================================================
92 void GEOM_IGroupOperations_i::AddObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
93 {
94   //Set a not done flag
95   GetOperations()->SetNotDone();
96
97   //Get the reference group
98   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
99   if (aGroupRef.IsNull()) return;
100
101   GetOperations()->AddObject(aGroupRef, theSubShapeId);
102 }
103
104 //=============================================================================
105 /*!
106  *  RemoveObject
107  */
108 //=============================================================================
109 void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
110 {
111   //Set a not done flag
112   GetOperations()->SetNotDone();
113
114   //Get the reference group
115   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
116   if (aGroupRef.IsNull()) return;
117
118   GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
119 }
120
121 //=============================================================================
122 /*!
123  *  UnionList
124  */
125 //=============================================================================
126 void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
127                                          const GEOM::ListOfGO& theSubShapes)
128 {
129   //Set a not done flag
130   GetOperations()->SetNotDone();
131
132   //Get the reference group
133   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
134   if (aGroupRef.IsNull()) return;
135
136   //Get sub-shape to add
137   Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
138
139   int ind, aLen = theSubShapes.length();
140   for (ind = 0; ind < aLen; ind++) {
141     Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
142     if (aSh.IsNull()) return;
143     aSubShapes->Append(aSh);
144   }
145
146   //Perform the operation
147   GetOperations()->UnionList(aGroupRef, aSubShapes);
148 }
149
150 //=============================================================================
151 /*!
152  *  DifferenceList
153  */
154 //=============================================================================
155 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
156                                               const GEOM::ListOfGO& theSubShapes)
157 {
158   //Set a not done flag
159   GetOperations()->SetNotDone();
160
161   //Get the reference group
162   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
163   if (aGroupRef.IsNull()) return;
164
165   //Get sub-shape to remove
166   Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
167
168   int ind, aLen = theSubShapes.length();
169   for (ind = 0; ind < aLen; ind++) {
170     Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
171     if (aSh.IsNull()) return;
172     aSubShapes->Append(aSh);
173   }
174
175   //Perform the operation
176   GetOperations()->DifferenceList(aGroupRef, aSubShapes);
177 }
178
179 //=============================================================================
180 /*!
181  *  UnionIDs
182  */
183 //=============================================================================
184 void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr   theGroup,
185                                         const GEOM::ListOfLong& theSubShapes)
186 {
187   //Set a not done flag
188   GetOperations()->SetNotDone();
189
190   //Get the reference group
191   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
192   if (aGroupRef.IsNull()) return;
193
194   //Get sub-shape to add
195   Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
196
197   int ind, aLen = theSubShapes.length();
198   for (ind = 0; ind < aLen; ind++) {
199     aSubShapes->Append(theSubShapes[ind]);
200   }
201
202   //Perform the operation
203   GetOperations()->UnionIDs(aGroupRef, aSubShapes);
204 }
205
206 //=============================================================================
207 /*!
208  *  DifferenceIDs
209  */
210 //=============================================================================
211 void GEOM_IGroupOperations_i::DifferenceIDs (GEOM::GEOM_Object_ptr   theGroup,
212                                              const GEOM::ListOfLong& theSubShapes)
213 {
214   //Set a not done flag
215   GetOperations()->SetNotDone();
216
217   //Get the reference group
218   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
219   if (aGroupRef.IsNull()) return;
220
221   //Get sub-shape to remove
222   Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
223
224   int ind, aLen = theSubShapes.length();
225   for (ind = 0; ind < aLen; ind++) {
226     aSubShapes->Append(theSubShapes[ind]);
227   }
228
229   //Perform the operation
230   GetOperations()->DifferenceIDs(aGroupRef, aSubShapes);
231 }
232
233 //=============================================================================
234 /*!
235  *  UnionGroups
236  */
237 //=============================================================================
238 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::UnionGroups (GEOM::GEOM_Object_ptr theGroup1,
239                                                             GEOM::GEOM_Object_ptr theGroup2)
240 {
241   GEOM::GEOM_Object_var aGEOMObject;
242
243   //Set a not done flag
244   GetOperations()->SetNotDone();
245
246   //Get the reference groups
247   Handle(GEOM_Object) aGroupRef1 = GetObjectImpl(theGroup1);
248   Handle(GEOM_Object) aGroupRef2 = GetObjectImpl(theGroup2);
249   if (aGroupRef1.IsNull() || aGroupRef2.IsNull()) return aGEOMObject._retn();
250
251   //Perform the operation
252   Handle(GEOM_Object) anObject = GetOperations()->UnionGroups(aGroupRef1, aGroupRef2);
253   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
254
255   return GetObject(anObject);
256 }
257
258 //=============================================================================
259 /*!
260  *  IntersectGroups
261  */
262 //=============================================================================
263 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::IntersectGroups (GEOM::GEOM_Object_ptr theGroup1,
264                                                                 GEOM::GEOM_Object_ptr theGroup2)
265 {
266   GEOM::GEOM_Object_var aGEOMObject;
267
268   //Set a not done flag
269   GetOperations()->SetNotDone();
270
271   //Get the reference groups
272   Handle(GEOM_Object) aGroupRef1 = GetObjectImpl(theGroup1);
273   Handle(GEOM_Object) aGroupRef2 = GetObjectImpl(theGroup2);
274   if (aGroupRef1.IsNull() || aGroupRef2.IsNull()) return aGEOMObject._retn();
275
276   //Perform the operation
277   Handle(GEOM_Object) anObject = GetOperations()->IntersectGroups(aGroupRef1, aGroupRef2);
278   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
279
280   return GetObject(anObject);
281 }
282
283 //=============================================================================
284 /*!
285  *  CutGroups
286  */
287 //=============================================================================
288 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CutGroups (GEOM::GEOM_Object_ptr theGroup1,
289                                                           GEOM::GEOM_Object_ptr theGroup2)
290 {
291   GEOM::GEOM_Object_var aGEOMObject;
292
293   //Set a not done flag
294   GetOperations()->SetNotDone();
295
296   //Get the reference groups
297   Handle(GEOM_Object) aGroupRef1 = GetObjectImpl(theGroup1);
298   Handle(GEOM_Object) aGroupRef2 = GetObjectImpl(theGroup2);
299   if (aGroupRef1.IsNull() || aGroupRef2.IsNull()) return aGEOMObject._retn();
300
301   //Perform the operation
302   Handle(GEOM_Object) anObject = GetOperations()->CutGroups(aGroupRef1, aGroupRef2);
303   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
304
305   return GetObject(anObject);
306 }
307
308 //=============================================================================
309 /*!
310  *  UnionListOfGroups
311  */
312 //=============================================================================
313 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::UnionListOfGroups (const GEOM::ListOfGO& theGList)
314 {
315   GEOM::GEOM_Object_var aGEOMObject;
316
317   //Set a not done flag
318   GetOperations()->SetNotDone();
319
320   //Get the reference groups
321   Handle(TColStd_HSequenceOfTransient) aGroups = new TColStd_HSequenceOfTransient;
322
323   int ind, aLen = theGList.length();
324   for (ind = 0; ind < aLen; ind++) {
325     Handle(GEOM_Object) aGr = GetObjectImpl(theGList[ind]);
326     if (aGr.IsNull()) return aGEOMObject._retn();
327     aGroups->Append(aGr);
328   }
329
330   //Perform the operation
331   Handle(GEOM_Object) anObject = GetOperations()->UnionListOfGroups(aGroups);
332   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
333
334   return GetObject(anObject);
335 }
336
337 //=============================================================================
338 /*!
339  *  IntersectListOfGroups
340  */
341 //=============================================================================
342 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::IntersectListOfGroups (const GEOM::ListOfGO& theGList)
343 {
344   GEOM::GEOM_Object_var aGEOMObject;
345
346   //Set a not done flag
347   GetOperations()->SetNotDone();
348
349   //Get the reference groups
350   Handle(TColStd_HSequenceOfTransient) aGroups = new TColStd_HSequenceOfTransient;
351
352   int ind, aLen = theGList.length();
353   for (ind = 0; ind < aLen; ind++) {
354     Handle(GEOM_Object) aGr = GetObjectImpl(theGList[ind]);
355     if (aGr.IsNull()) return aGEOMObject._retn();
356     aGroups->Append(aGr);
357   }
358
359   //Perform the operation
360   Handle(GEOM_Object) anObject = GetOperations()->IntersectListOfGroups(aGroups);
361   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
362
363   return GetObject(anObject);
364 }
365
366 //=============================================================================
367 /*!
368  *  CutListOfGroups
369  */
370 //=============================================================================
371 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CutListOfGroups (const GEOM::ListOfGO& theGList1,
372                                                                 const GEOM::ListOfGO& theGList2)
373 {
374   GEOM::GEOM_Object_var aGEOMObject;
375
376   //Set a not done flag
377   GetOperations()->SetNotDone();
378
379   //Get the reference groups
380   Handle(TColStd_HSequenceOfTransient) aGroups1 = new TColStd_HSequenceOfTransient;
381   Handle(TColStd_HSequenceOfTransient) aGroups2 = new TColStd_HSequenceOfTransient;
382
383   int ind, aLen = theGList1.length();
384   for (ind = 0; ind < aLen; ind++) {
385     Handle(GEOM_Object) aGr = GetObjectImpl(theGList1[ind]);
386     if (aGr.IsNull()) return aGEOMObject._retn();
387     aGroups1->Append(aGr);
388   }
389   aLen = theGList2.length();
390   for (ind = 0; ind < aLen; ind++) {
391     Handle(GEOM_Object) aGr = GetObjectImpl(theGList2[ind]);
392     if (aGr.IsNull()) return aGEOMObject._retn();
393     aGroups2->Append(aGr);
394   }
395
396   //Perform the operation
397   Handle(GEOM_Object) anObject = GetOperations()->CutListOfGroups(aGroups1, aGroups2);
398   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
399
400   return GetObject(anObject);
401 }
402
403 //=============================================================================
404 /*!
405  *  GetType
406  */
407 //=============================================================================
408 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
409 {
410   //Set a not done flag
411   GetOperations()->SetNotDone();
412
413   //Get the reference group
414   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
415   if (aGroupRef.IsNull()) return -1;
416
417   return GetOperations()->GetType(aGroupRef);
418 }
419
420 //=============================================================================
421 /*!
422  *  GetMainShape
423  */
424 //=============================================================================
425 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
426 {
427   GEOM::GEOM_Object_var aGEOMObject;
428
429   //Set a not done flag
430   GetOperations()->SetNotDone();
431
432   //Get the reference group
433   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
434   if (aGroupRef.IsNull()) return aGEOMObject._retn();
435
436   Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
437   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
438
439   return GetObject(anObject);
440 }
441
442 //=============================================================================
443 /*!
444  *  GetObjects
445  */
446 //=============================================================================
447 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
448 {
449   GEOM::ListOfLong_var aList;
450
451   //Set a not done flag
452   GetOperations()->SetNotDone();
453
454   //Get the reference group
455   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
456   if (aGroupRef.IsNull()) return aList._retn();
457
458   aList = new GEOM::ListOfLong;
459
460   Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
461   if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
462
463   aList->length(aSeq->Length());
464   for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
465
466   return aList._retn();
467 }