Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/geom.git] / src / GEOM_I / GEOM_IGroupOperations_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 #include <Standard_Stream.hxx>
21
22 #include "GEOM_IGroupOperations_i.hh"
23
24 #include "utilities.h"
25 #include "OpUtil.hxx"
26 #include "Utils_ExceptHandlers.hxx"
27
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
30
31 #include <TColStd_HArray1OfInteger.hxx>
32 #include <TopAbs.hxx>
33
34 //=============================================================================
35 /*!
36  *   constructor:
37  */
38 //=============================================================================
39 GEOM_IGroupOperations_i::GEOM_IGroupOperations_i (PortableServer::POA_ptr thePOA,
40                                                   GEOM::GEOM_Gen_ptr theEngine,
41                                                   ::GEOMImpl_IGroupOperations* theImpl)
42      :GEOM_IOperations_i(thePOA, theEngine, theImpl)
43 {
44   MESSAGE("GEOM_IGroupOperations_i::GEOM_IGroupOperations_i");
45 }
46
47 //=============================================================================
48 /*!
49  *  destructor
50  */
51 //=============================================================================
52 GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i()
53 {
54   MESSAGE("GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i");
55 }
56
57
58 //=============================================================================
59 /*!
60  *  CreateGroup
61  */
62 //============================================================================= 
63 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CreateGroup(GEOM::GEOM_Object_ptr theMainShape, CORBA::Long theShapeType)
64 {
65   GEOM::GEOM_Object_var aGEOMObject;
66
67   //Set a not done flag
68   GetOperations()->SetNotDone();
69
70   if (theMainShape == NULL || theShapeType < 0) return aGEOMObject._retn();
71
72   //Get the reference shape
73   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
74
75   if (aShapeRef.IsNull()) return aGEOMObject._retn();
76
77   //Create the Fillet
78   Handle(GEOM_Object) anObject = GetOperations()->CreateGroup(aShapeRef, (TopAbs_ShapeEnum)theShapeType);
79   if (!GetOperations()->IsDone() || anObject.IsNull())
80     return aGEOMObject._retn();
81
82   return GetObject(anObject);
83 }
84
85 //=============================================================================
86 /*!
87  *  AddObject
88  */
89 //=============================================================================
90 void GEOM_IGroupOperations_i::AddObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId) 
91 {
92   //Set a not done flag
93   GetOperations()->SetNotDone();
94
95   if (theGroup == NULL) return;
96
97   //Get the reference group
98   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
99   if (aGroupRef.IsNull()) return;
100
101   GetOperations()->AddObject(aGroupRef, theSubShapeId);
102   return;
103 }
104
105 //=============================================================================
106 /*!
107  *  RemoveObject
108  */
109 //============================================================================= 
110 void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId) 
111 {
112   //Set a not done flag
113   GetOperations()->SetNotDone();
114
115   if (theGroup == NULL) return;
116
117   //Get the reference group
118   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
119   if (aGroupRef.IsNull()) return;
120
121   GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
122
123   return;
124 }
125
126 //=============================================================================
127 /*!
128  *  UnionList
129  */
130 //=============================================================================
131 void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
132                                          const GEOM::ListOfGO& theSubShapes) 
133 {
134   //Set a not done flag
135   GetOperations()->SetNotDone();
136
137   if (theGroup == NULL) return;
138
139   //Get the reference group
140   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
141     (theGroup->GetStudyID(), theGroup->GetEntry());
142   if (aGroupRef.IsNull()) return;
143
144   //Get sub-shape to add
145   Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
146
147   int ind, aLen = theSubShapes.length();
148   for (ind = 0; ind < aLen; ind++) {
149     if (theSubShapes[ind] == NULL) return;
150     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
151       (theSubShapes[ind]->GetStudyID(), theSubShapes[ind]->GetEntry());
152     if (aSh.IsNull()) return;
153     aSubShapes->Append(aSh);
154   }
155
156   //Perform the operation
157   GetOperations()->UnionList(aGroupRef, aSubShapes);
158   return;
159 }
160
161 //=============================================================================
162 /*!
163  *  DifferenceList
164  */
165 //=============================================================================
166 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
167                                               const GEOM::ListOfGO& theSubShapes) 
168 {
169   //Set a not done flag
170   GetOperations()->SetNotDone();
171
172   if (theGroup == NULL) return;
173
174   //Get the reference group
175   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
176     (theGroup->GetStudyID(), theGroup->GetEntry());
177   if (aGroupRef.IsNull()) return;
178
179   //Get sub-shape to remove
180   Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
181
182   int ind, aLen = theSubShapes.length();
183   for (ind = 0; ind < aLen; ind++) {
184     if (theSubShapes[ind] == NULL) return;
185     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
186       (theSubShapes[ind]->GetStudyID(), theSubShapes[ind]->GetEntry());
187     if (aSh.IsNull()) return;
188     aSubShapes->Append(aSh);
189   }
190
191   //Perform the operation
192   GetOperations()->DifferenceList(aGroupRef, aSubShapes);
193   return;
194 }
195
196 //=============================================================================
197 /*!
198  *  UnionIDs
199  */
200 //=============================================================================
201 void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr   theGroup,
202                                         const GEOM::ListOfLong& theSubShapes) 
203 {
204   //Set a not done flag
205   GetOperations()->SetNotDone();
206
207   if (theGroup == NULL) return;
208
209   //Get the reference group
210   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
211     (theGroup->GetStudyID(), theGroup->GetEntry());
212   if (aGroupRef.IsNull()) return;
213
214   //Get sub-shape to add
215   Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
216
217   int ind, aLen = theSubShapes.length();
218   for (ind = 0; ind < aLen; ind++) {
219     aSubShapes->Append(theSubShapes[ind]);
220   }
221
222   //Perform the operation
223   GetOperations()->UnionIDs(aGroupRef, aSubShapes);
224   return;
225 }
226
227 //=============================================================================
228 /*!
229  *  DifferenceIDs
230  */
231 //=============================================================================
232 void GEOM_IGroupOperations_i::DifferenceIDs (GEOM::GEOM_Object_ptr   theGroup,
233                                              const GEOM::ListOfLong& theSubShapes) 
234 {
235   //Set a not done flag
236   GetOperations()->SetNotDone();
237
238   if (theGroup == NULL) return;
239
240   //Get the reference group
241   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
242     (theGroup->GetStudyID(), theGroup->GetEntry());
243   if (aGroupRef.IsNull()) return;
244
245   //Get sub-shape to remove
246   Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
247
248   int ind, aLen = theSubShapes.length();
249   for (ind = 0; ind < aLen; ind++) {
250     aSubShapes->Append(theSubShapes[ind]);
251   }
252
253   //Perform the operation
254   GetOperations()->DifferenceIDs(aGroupRef, aSubShapes);
255   return;
256 }
257
258 //=============================================================================
259 /*!
260  *  GetType
261  */
262 //============================================================================= 
263 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
264 {
265   //Set a not done flag
266   GetOperations()->SetNotDone();
267
268   if (theGroup == NULL) return -1;
269
270   //Get the reference group
271   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
272
273   if (aGroupRef.IsNull()) return -1;
274
275   return GetOperations()->GetType(aGroupRef);
276 }
277
278 //=============================================================================
279 /*!
280  *  GetMainShape
281  */
282 //============================================================================= 
283 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
284 {
285   GEOM::GEOM_Object_var aGEOMObject;
286
287   //Set a not done flag
288   GetOperations()->SetNotDone();
289
290   if (theGroup == NULL) return aGEOMObject._retn();
291
292   //Get the reference group
293   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
294   if (aGroupRef.IsNull()) return aGEOMObject._retn();
295
296   Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
297   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
298
299   return GetObject(anObject);
300 }
301
302 //=============================================================================
303 /*!
304  *  GetObjects
305  */
306 //============================================================================= 
307 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
308 {
309   GEOM::ListOfLong_var aList;
310
311   //Set a not done flag
312   GetOperations()->SetNotDone();
313
314   if (theGroup == NULL) return aList._retn();
315
316   //Get the reference group
317   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
318   if (aGroupRef.IsNull()) return aList._retn();
319
320   aList = new GEOM::ListOfLong;    
321
322   Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
323   if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
324     
325   aList->length(aSeq->Length());
326   for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
327
328   return aList._retn();
329 }
330