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