1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <Standard_Stream.hxx>
24 #include "GEOM_IGroupOperations_i.hh"
26 #include "utilities.h"
28 #include "Utils_ExceptHandlers.hxx"
30 #include "GEOM_Engine.hxx"
31 #include "GEOM_Object.hxx"
33 #include <TColStd_HArray1OfInteger.hxx>
36 //=============================================================================
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)
46 MESSAGE("GEOM_IGroupOperations_i::GEOM_IGroupOperations_i");
49 //=============================================================================
53 //=============================================================================
54 GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i()
56 MESSAGE("GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i");
60 //=============================================================================
64 //=============================================================================
65 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CreateGroup(GEOM::GEOM_Object_ptr theMainShape,
66 CORBA::Long theShapeType)
68 GEOM::GEOM_Object_var aGEOMObject;
71 GetOperations()->SetNotDone();
73 if (theShapeType < 0) return aGEOMObject._retn();
75 //Get the reference shape
76 Handle(GEOM_Object) aShapeRef = GetObjectImpl(theMainShape);
77 if (aShapeRef.IsNull()) return aGEOMObject._retn();
80 Handle(GEOM_Object) anObject = GetOperations()->CreateGroup(aShapeRef, (TopAbs_ShapeEnum)theShapeType);
81 if (!GetOperations()->IsDone() || anObject.IsNull())
82 return aGEOMObject._retn();
84 return GetObject(anObject);
87 //=============================================================================
91 //=============================================================================
92 void GEOM_IGroupOperations_i::AddObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
95 GetOperations()->SetNotDone();
97 //Get the reference group
98 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
99 if (aGroupRef.IsNull()) return;
101 GetOperations()->AddObject(aGroupRef, theSubShapeId);
104 //=============================================================================
108 //=============================================================================
109 void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
111 //Set a not done flag
112 GetOperations()->SetNotDone();
114 //Get the reference group
115 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
116 if (aGroupRef.IsNull()) return;
118 GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
121 //=============================================================================
125 //=============================================================================
126 void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
127 const GEOM::ListOfGO& theSubShapes)
129 //Set a not done flag
130 GetOperations()->SetNotDone();
132 //Get the reference group
133 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
134 if (aGroupRef.IsNull()) return;
136 //Get sub-shape to add
137 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
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);
146 //Perform the operation
147 GetOperations()->UnionList(aGroupRef, aSubShapes);
150 //=============================================================================
154 //=============================================================================
155 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
156 const GEOM::ListOfGO& theSubShapes)
158 //Set a not done flag
159 GetOperations()->SetNotDone();
161 //Get the reference group
162 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
163 if (aGroupRef.IsNull()) return;
165 //Get sub-shape to remove
166 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
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);
175 //Perform the operation
176 GetOperations()->DifferenceList(aGroupRef, aSubShapes);
179 //=============================================================================
183 //=============================================================================
184 void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr theGroup,
185 const GEOM::ListOfLong& theSubShapes)
187 //Set a not done flag
188 GetOperations()->SetNotDone();
190 //Get the reference group
191 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
192 if (aGroupRef.IsNull()) return;
194 //Get sub-shape to add
195 Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
197 int ind, aLen = theSubShapes.length();
198 for (ind = 0; ind < aLen; ind++) {
199 aSubShapes->Append(theSubShapes[ind]);
202 //Perform the operation
203 GetOperations()->UnionIDs(aGroupRef, aSubShapes);
206 //=============================================================================
210 //=============================================================================
211 void GEOM_IGroupOperations_i::DifferenceIDs (GEOM::GEOM_Object_ptr theGroup,
212 const GEOM::ListOfLong& theSubShapes)
214 //Set a not done flag
215 GetOperations()->SetNotDone();
217 //Get the reference group
218 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
219 if (aGroupRef.IsNull()) return;
221 //Get sub-shape to remove
222 Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
224 int ind, aLen = theSubShapes.length();
225 for (ind = 0; ind < aLen; ind++) {
226 aSubShapes->Append(theSubShapes[ind]);
229 //Perform the operation
230 GetOperations()->DifferenceIDs(aGroupRef, aSubShapes);
233 //=============================================================================
237 //=============================================================================
238 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::UnionGroups (GEOM::GEOM_Object_ptr theGroup1,
239 GEOM::GEOM_Object_ptr theGroup2)
241 GEOM::GEOM_Object_var aGEOMObject;
243 //Set a not done flag
244 GetOperations()->SetNotDone();
246 //Get the reference groups
247 Handle(GEOM_Object) aGroupRef1 = GetObjectImpl(theGroup1);
248 Handle(GEOM_Object) aGroupRef2 = GetObjectImpl(theGroup2);
249 if (aGroupRef1.IsNull() || aGroupRef2.IsNull()) return aGEOMObject._retn();
251 //Perform the operation
252 Handle(GEOM_Object) anObject = GetOperations()->UnionGroups(aGroupRef1, aGroupRef2);
253 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
255 return GetObject(anObject);
258 //=============================================================================
262 //=============================================================================
263 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::IntersectGroups (GEOM::GEOM_Object_ptr theGroup1,
264 GEOM::GEOM_Object_ptr theGroup2)
266 GEOM::GEOM_Object_var aGEOMObject;
268 //Set a not done flag
269 GetOperations()->SetNotDone();
271 //Get the reference groups
272 Handle(GEOM_Object) aGroupRef1 = GetObjectImpl(theGroup1);
273 Handle(GEOM_Object) aGroupRef2 = GetObjectImpl(theGroup2);
274 if (aGroupRef1.IsNull() || aGroupRef2.IsNull()) return aGEOMObject._retn();
276 //Perform the operation
277 Handle(GEOM_Object) anObject = GetOperations()->IntersectGroups(aGroupRef1, aGroupRef2);
278 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
280 return GetObject(anObject);
283 //=============================================================================
287 //=============================================================================
288 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CutGroups (GEOM::GEOM_Object_ptr theGroup1,
289 GEOM::GEOM_Object_ptr theGroup2)
291 GEOM::GEOM_Object_var aGEOMObject;
293 //Set a not done flag
294 GetOperations()->SetNotDone();
296 //Get the reference groups
297 Handle(GEOM_Object) aGroupRef1 = GetObjectImpl(theGroup1);
298 Handle(GEOM_Object) aGroupRef2 = GetObjectImpl(theGroup2);
299 if (aGroupRef1.IsNull() || aGroupRef2.IsNull()) return aGEOMObject._retn();
301 //Perform the operation
302 Handle(GEOM_Object) anObject = GetOperations()->CutGroups(aGroupRef1, aGroupRef2);
303 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
305 return GetObject(anObject);
308 //=============================================================================
312 //=============================================================================
313 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::UnionListOfGroups (const GEOM::ListOfGO& theGList)
315 GEOM::GEOM_Object_var aGEOMObject;
317 //Set a not done flag
318 GetOperations()->SetNotDone();
320 //Get the reference groups
321 Handle(TColStd_HSequenceOfTransient) aGroups = new TColStd_HSequenceOfTransient;
323 int ind, aLen = theGList.length();
324 for (ind = 0; ind < aLen; ind++) {
325 Handle(GEOM_Object) aGr = GetObjectImpl(theGList[ind]);
326 if (aGr.IsNull()) return aGEOMObject._retn();
327 aGroups->Append(aGr);
330 //Perform the operation
331 Handle(GEOM_Object) anObject = GetOperations()->UnionListOfGroups(aGroups);
332 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
334 return GetObject(anObject);
337 //=============================================================================
339 * IntersectListOfGroups
341 //=============================================================================
342 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::IntersectListOfGroups (const GEOM::ListOfGO& theGList)
344 GEOM::GEOM_Object_var aGEOMObject;
346 //Set a not done flag
347 GetOperations()->SetNotDone();
349 //Get the reference groups
350 Handle(TColStd_HSequenceOfTransient) aGroups = new TColStd_HSequenceOfTransient;
352 int ind, aLen = theGList.length();
353 for (ind = 0; ind < aLen; ind++) {
354 Handle(GEOM_Object) aGr = GetObjectImpl(theGList[ind]);
355 if (aGr.IsNull()) return aGEOMObject._retn();
356 aGroups->Append(aGr);
359 //Perform the operation
360 Handle(GEOM_Object) anObject = GetOperations()->IntersectListOfGroups(aGroups);
361 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
363 return GetObject(anObject);
366 //=============================================================================
370 //=============================================================================
371 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CutListOfGroups (const GEOM::ListOfGO& theGList1,
372 const GEOM::ListOfGO& theGList2)
374 GEOM::GEOM_Object_var aGEOMObject;
376 //Set a not done flag
377 GetOperations()->SetNotDone();
379 //Get the reference groups
380 Handle(TColStd_HSequenceOfTransient) aGroups1 = new TColStd_HSequenceOfTransient;
381 Handle(TColStd_HSequenceOfTransient) aGroups2 = new TColStd_HSequenceOfTransient;
383 int ind, aLen = theGList1.length();
384 for (ind = 0; ind < aLen; ind++) {
385 Handle(GEOM_Object) aGr = GetObjectImpl(theGList1[ind]);
386 if (aGr.IsNull()) return aGEOMObject._retn();
387 aGroups1->Append(aGr);
389 aLen = theGList2.length();
390 for (ind = 0; ind < aLen; ind++) {
391 Handle(GEOM_Object) aGr = GetObjectImpl(theGList2[ind]);
392 if (aGr.IsNull()) return aGEOMObject._retn();
393 aGroups2->Append(aGr);
396 //Perform the operation
397 Handle(GEOM_Object) anObject = GetOperations()->CutListOfGroups(aGroups1, aGroups2);
398 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
400 return GetObject(anObject);
403 //=============================================================================
407 //=============================================================================
408 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
410 //Set a not done flag
411 GetOperations()->SetNotDone();
413 //Get the reference group
414 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
415 if (aGroupRef.IsNull()) return -1;
417 return GetOperations()->GetType(aGroupRef);
420 //=============================================================================
424 //=============================================================================
425 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
427 GEOM::GEOM_Object_var aGEOMObject;
429 //Set a not done flag
430 GetOperations()->SetNotDone();
432 //Get the reference group
433 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
434 if (aGroupRef.IsNull()) return aGEOMObject._retn();
436 Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
437 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
439 return GetObject(anObject);
442 //=============================================================================
446 //=============================================================================
447 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
449 GEOM::ListOfLong_var aList;
451 //Set a not done flag
452 GetOperations()->SetNotDone();
454 //Get the reference group
455 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
456 if (aGroupRef.IsNull()) return aList._retn();
458 aList = new GEOM::ListOfLong;
460 Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
461 if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
463 aList->length(aSeq->Length());
464 for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
466 return aList._retn();