Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/geom.git] / src / GEOM_I / GEOM_IGroupOperations_i.cc
1 //  Copyright (C) 2007-2008  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, CORBA::Long theShapeType)
66 {
67   GEOM::GEOM_Object_var aGEOMObject;
68
69   //Set a not done flag
70   GetOperations()->SetNotDone();
71
72   if (theMainShape == NULL || theShapeType < 0) return aGEOMObject._retn();
73
74   //Get the reference shape
75   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
76
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   if (theGroup == NULL) return;
98
99   //Get the reference group
100   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
101   if (aGroupRef.IsNull()) return;
102
103   GetOperations()->AddObject(aGroupRef, theSubShapeId);
104   return;
105 }
106
107 //=============================================================================
108 /*!
109  *  RemoveObject
110  */
111 //============================================================================= 
112 void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId) 
113 {
114   //Set a not done flag
115   GetOperations()->SetNotDone();
116
117   if (theGroup == NULL) return;
118
119   //Get the reference group
120   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
121   if (aGroupRef.IsNull()) return;
122
123   GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
124
125   return;
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   if (theGroup == NULL) return;
140
141   //Get the reference group
142   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
143     (theGroup->GetStudyID(), theGroup->GetEntry());
144   if (aGroupRef.IsNull()) return;
145
146   //Get sub-shape to add
147   Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
148
149   int ind, aLen = theSubShapes.length();
150   for (ind = 0; ind < aLen; ind++) {
151     if (theSubShapes[ind] == NULL) return;
152     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
153       (theSubShapes[ind]->GetStudyID(), theSubShapes[ind]->GetEntry());
154     if (aSh.IsNull()) return;
155     aSubShapes->Append(aSh);
156   }
157
158   //Perform the operation
159   GetOperations()->UnionList(aGroupRef, aSubShapes);
160   return;
161 }
162
163 //=============================================================================
164 /*!
165  *  DifferenceList
166  */
167 //=============================================================================
168 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
169                                               const GEOM::ListOfGO& theSubShapes) 
170 {
171   //Set a not done flag
172   GetOperations()->SetNotDone();
173
174   if (theGroup == NULL) return;
175
176   //Get the reference group
177   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
178     (theGroup->GetStudyID(), theGroup->GetEntry());
179   if (aGroupRef.IsNull()) return;
180
181   //Get sub-shape to remove
182   Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
183
184   int ind, aLen = theSubShapes.length();
185   for (ind = 0; ind < aLen; ind++) {
186     if (theSubShapes[ind] == NULL) return;
187     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
188       (theSubShapes[ind]->GetStudyID(), theSubShapes[ind]->GetEntry());
189     if (aSh.IsNull()) return;
190     aSubShapes->Append(aSh);
191   }
192
193   //Perform the operation
194   GetOperations()->DifferenceList(aGroupRef, aSubShapes);
195   return;
196 }
197
198 //=============================================================================
199 /*!
200  *  UnionIDs
201  */
202 //=============================================================================
203 void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr   theGroup,
204                                         const GEOM::ListOfLong& theSubShapes) 
205 {
206   //Set a not done flag
207   GetOperations()->SetNotDone();
208
209   if (theGroup == NULL) return;
210
211   //Get the reference group
212   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
213     (theGroup->GetStudyID(), theGroup->GetEntry());
214   if (aGroupRef.IsNull()) return;
215
216   //Get sub-shape to add
217   Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
218
219   int ind, aLen = theSubShapes.length();
220   for (ind = 0; ind < aLen; ind++) {
221     aSubShapes->Append(theSubShapes[ind]);
222   }
223
224   //Perform the operation
225   GetOperations()->UnionIDs(aGroupRef, aSubShapes);
226   return;
227 }
228
229 //=============================================================================
230 /*!
231  *  DifferenceIDs
232  */
233 //=============================================================================
234 void GEOM_IGroupOperations_i::DifferenceIDs (GEOM::GEOM_Object_ptr   theGroup,
235                                              const GEOM::ListOfLong& theSubShapes) 
236 {
237   //Set a not done flag
238   GetOperations()->SetNotDone();
239
240   if (theGroup == NULL) return;
241
242   //Get the reference group
243   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
244     (theGroup->GetStudyID(), theGroup->GetEntry());
245   if (aGroupRef.IsNull()) return;
246
247   //Get sub-shape to remove
248   Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
249
250   int ind, aLen = theSubShapes.length();
251   for (ind = 0; ind < aLen; ind++) {
252     aSubShapes->Append(theSubShapes[ind]);
253   }
254
255   //Perform the operation
256   GetOperations()->DifferenceIDs(aGroupRef, aSubShapes);
257   return;
258 }
259
260 //=============================================================================
261 /*!
262  *  GetType
263  */
264 //============================================================================= 
265 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
266 {
267   //Set a not done flag
268   GetOperations()->SetNotDone();
269
270   if (theGroup == NULL) return -1;
271
272   //Get the reference group
273   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
274
275   if (aGroupRef.IsNull()) return -1;
276
277   return GetOperations()->GetType(aGroupRef);
278 }
279
280 //=============================================================================
281 /*!
282  *  GetMainShape
283  */
284 //============================================================================= 
285 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
286 {
287   GEOM::GEOM_Object_var aGEOMObject;
288
289   //Set a not done flag
290   GetOperations()->SetNotDone();
291
292   if (theGroup == NULL) return aGEOMObject._retn();
293
294   //Get the reference group
295   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
296   if (aGroupRef.IsNull()) return aGEOMObject._retn();
297
298   Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
299   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
300
301   return GetObject(anObject);
302 }
303
304 //=============================================================================
305 /*!
306  *  GetObjects
307  */
308 //============================================================================= 
309 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
310 {
311   GEOM::ListOfLong_var aList;
312
313   //Set a not done flag
314   GetOperations()->SetNotDone();
315
316   if (theGroup == NULL) return aList._retn();
317
318   //Get the reference group
319   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
320   if (aGroupRef.IsNull()) return aList._retn();
321
322   aList = new GEOM::ListOfLong;    
323
324   Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
325   if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
326     
327   aList->length(aSeq->Length());
328   for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
329
330   return aList._retn();
331 }
332