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