Salome HOME
Merge from V6_main_20120808 08Aug12
[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
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
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   //Get the reference group
116   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
117   if (aGroupRef.IsNull()) return;
118
119   GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
120 }
121
122 //=============================================================================
123 /*!
124  *  UnionList
125  */
126 //=============================================================================
127 void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
128                                          const GEOM::ListOfGO& theSubShapes)
129 {
130   //Set a not done flag
131   GetOperations()->SetNotDone();
132
133   //Get the reference group
134   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
135   if (aGroupRef.IsNull()) return;
136
137   //Get sub-shape to add
138   Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
139
140   int ind, aLen = theSubShapes.length();
141   for (ind = 0; ind < aLen; ind++) {
142     Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
143     if (aSh.IsNull()) return;
144     aSubShapes->Append(aSh);
145   }
146
147   //Perform the operation
148   GetOperations()->UnionList(aGroupRef, aSubShapes);
149 }
150
151 //=============================================================================
152 /*!
153  *  DifferenceList
154  */
155 //=============================================================================
156 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
157                                               const GEOM::ListOfGO& theSubShapes)
158 {
159   //Set a not done flag
160   GetOperations()->SetNotDone();
161
162   //Get the reference group
163   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
164   if (aGroupRef.IsNull()) return;
165
166   //Get sub-shape to remove
167   Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
168
169   int ind, aLen = theSubShapes.length();
170   for (ind = 0; ind < aLen; ind++) {
171     Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
172     if (aSh.IsNull()) return;
173     aSubShapes->Append(aSh);
174   }
175
176   //Perform the operation
177   GetOperations()->DifferenceList(aGroupRef, aSubShapes);
178 }
179
180 //=============================================================================
181 /*!
182  *  UnionIDs
183  */
184 //=============================================================================
185 void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr   theGroup,
186                                         const GEOM::ListOfLong& theSubShapes)
187 {
188   //Set a not done flag
189   GetOperations()->SetNotDone();
190
191   //Get the reference group
192   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
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   //Get the reference group
220   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
221   if (aGroupRef.IsNull()) return;
222
223   //Get sub-shape to remove
224   Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
225
226   int ind, aLen = theSubShapes.length();
227   for (ind = 0; ind < aLen; ind++) {
228     aSubShapes->Append(theSubShapes[ind]);
229   }
230
231   //Perform the operation
232   GetOperations()->DifferenceIDs(aGroupRef, aSubShapes);
233   return;
234 }
235
236 //=============================================================================
237 /*!
238  *  GetType
239  */
240 //=============================================================================
241 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
242 {
243   //Set a not done flag
244   GetOperations()->SetNotDone();
245
246   //Get the reference group
247   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
248   if (aGroupRef.IsNull()) return -1;
249
250   return GetOperations()->GetType(aGroupRef);
251 }
252
253 //=============================================================================
254 /*!
255  *  GetMainShape
256  */
257 //=============================================================================
258 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
259 {
260   GEOM::GEOM_Object_var aGEOMObject;
261
262   //Set a not done flag
263   GetOperations()->SetNotDone();
264
265   //Get the reference group
266   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
267   if (aGroupRef.IsNull()) return aGEOMObject._retn();
268
269   Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
270   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
271
272   return GetObject(anObject);
273 }
274
275 //=============================================================================
276 /*!
277  *  GetObjects
278  */
279 //=============================================================================
280 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
281 {
282   GEOM::ListOfLong_var aList;
283
284   //Set a not done flag
285   GetOperations()->SetNotDone();
286
287   //Get the reference group
288   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
289   if (aGroupRef.IsNull()) return aList._retn();
290
291   aList = new GEOM::ListOfLong;
292
293   Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
294   if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
295
296   aList->length(aSeq->Length());
297   for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
298
299   return aList._retn();
300 }