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