1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
23 #include <Standard_Stream.hxx>
25 #include "GEOM_IGroupOperations_i.hh"
27 #include "utilities.h"
29 #include "Utils_ExceptHandlers.hxx"
31 #include "GEOM_Engine.hxx"
32 #include "GEOM_Object.hxx"
34 #include <TColStd_HArray1OfInteger.hxx>
37 //=============================================================================
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)
47 MESSAGE("GEOM_IGroupOperations_i::GEOM_IGroupOperations_i");
50 //=============================================================================
54 //=============================================================================
55 GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i()
57 MESSAGE("GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i");
61 //=============================================================================
65 //=============================================================================
66 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CreateGroup(GEOM::GEOM_Object_ptr theMainShape,
67 CORBA::Long theShapeType)
69 GEOM::GEOM_Object_var aGEOMObject;
72 GetOperations()->SetNotDone();
74 if (theShapeType < 0) return aGEOMObject._retn();
76 //Get the reference shape
77 HANDLE_NAMESPACE(GEOM_Object) aShapeRef = GetObjectImpl(theMainShape);
78 if (aShapeRef.IsNull()) return aGEOMObject._retn();
81 HANDLE_NAMESPACE(GEOM_Object) anObject = GetOperations()->CreateGroup(aShapeRef, (TopAbs_ShapeEnum)theShapeType);
82 if (!GetOperations()->IsDone() || anObject.IsNull())
83 return aGEOMObject._retn();
85 return GetObject(anObject);
88 //=============================================================================
92 //=============================================================================
93 void GEOM_IGroupOperations_i::AddObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
96 GetOperations()->SetNotDone();
98 //Get the reference group
99 HANDLE_NAMESPACE(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
100 if (aGroupRef.IsNull()) return;
102 GetOperations()->AddObject(aGroupRef, theSubShapeId);
105 UpdateGUIForObject(theGroup);
108 //=============================================================================
112 //=============================================================================
113 void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
115 //Set a not done flag
116 GetOperations()->SetNotDone();
118 //Get the reference group
119 HANDLE_NAMESPACE(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
120 if (aGroupRef.IsNull()) return;
122 GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
125 UpdateGUIForObject(theGroup);
128 //=============================================================================
132 //=============================================================================
133 void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
134 const GEOM::ListOfGO& theSubShapes)
136 //Set a not done flag
137 GetOperations()->SetNotDone();
139 //Get the reference group
140 HANDLE_NAMESPACE(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
141 if (aGroupRef.IsNull()) return;
143 //Get sub-shape to add
144 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
146 int ind, aLen = theSubShapes.length();
147 for (ind = 0; ind < aLen; ind++) {
148 HANDLE_NAMESPACE(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
149 if (aSh.IsNull()) return;
150 aSubShapes->Append(aSh);
153 //Perform the operation
154 GetOperations()->UnionList(aGroupRef, aSubShapes);
157 //=============================================================================
161 //=============================================================================
162 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
163 const GEOM::ListOfGO& theSubShapes)
165 //Set a not done flag
166 GetOperations()->SetNotDone();
168 //Get the reference group
169 HANDLE_NAMESPACE(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
170 if (aGroupRef.IsNull()) return;
172 //Get sub-shape to remove
173 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
175 int ind, aLen = theSubShapes.length();
176 for (ind = 0; ind < aLen; ind++) {
177 HANDLE_NAMESPACE(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
178 if (aSh.IsNull()) return;
179 aSubShapes->Append(aSh);
182 //Perform the operation
183 GetOperations()->DifferenceList(aGroupRef, aSubShapes);
186 //=============================================================================
190 //=============================================================================
191 void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr theGroup,
192 const GEOM::ListOfLong& theSubShapes)
194 //Set a not done flag
195 GetOperations()->SetNotDone();
197 //Get the reference group
198 HANDLE_NAMESPACE(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
199 if (aGroupRef.IsNull()) return;
201 //Get sub-shape to add
202 Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
204 int ind, aLen = theSubShapes.length();
205 for (ind = 0; ind < aLen; ind++) {
206 aSubShapes->Append(theSubShapes[ind]);
209 //Perform the operation
210 GetOperations()->UnionIDs(aGroupRef, aSubShapes);
213 //=============================================================================
217 //=============================================================================
218 void GEOM_IGroupOperations_i::DifferenceIDs (GEOM::GEOM_Object_ptr theGroup,
219 const GEOM::ListOfLong& theSubShapes)
221 //Set a not done flag
222 GetOperations()->SetNotDone();
224 //Get the reference group
225 HANDLE_NAMESPACE(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
226 if (aGroupRef.IsNull()) return;
228 //Get sub-shape to remove
229 Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
231 int ind, aLen = theSubShapes.length();
232 for (ind = 0; ind < aLen; ind++) {
233 aSubShapes->Append(theSubShapes[ind]);
236 //Perform the operation
237 GetOperations()->DifferenceIDs(aGroupRef, aSubShapes);
240 //=============================================================================
244 //=============================================================================
245 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::UnionGroups (GEOM::GEOM_Object_ptr theGroup1,
246 GEOM::GEOM_Object_ptr theGroup2)
248 GEOM::GEOM_Object_var aGEOMObject;
250 //Set a not done flag
251 GetOperations()->SetNotDone();
253 //Get the reference groups
254 HANDLE_NAMESPACE(GEOM_Object) aGroupRef1 = GetObjectImpl(theGroup1);
255 HANDLE_NAMESPACE(GEOM_Object) aGroupRef2 = GetObjectImpl(theGroup2);
256 if (aGroupRef1.IsNull() || aGroupRef2.IsNull()) return aGEOMObject._retn();
258 //Perform the operation
259 HANDLE_NAMESPACE(GEOM_Object) anObject = GetOperations()->UnionGroups(aGroupRef1, aGroupRef2);
260 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
262 return GetObject(anObject);
265 //=============================================================================
269 //=============================================================================
270 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::IntersectGroups (GEOM::GEOM_Object_ptr theGroup1,
271 GEOM::GEOM_Object_ptr theGroup2)
273 GEOM::GEOM_Object_var aGEOMObject;
275 //Set a not done flag
276 GetOperations()->SetNotDone();
278 //Get the reference groups
279 HANDLE_NAMESPACE(GEOM_Object) aGroupRef1 = GetObjectImpl(theGroup1);
280 HANDLE_NAMESPACE(GEOM_Object) aGroupRef2 = GetObjectImpl(theGroup2);
281 if (aGroupRef1.IsNull() || aGroupRef2.IsNull()) return aGEOMObject._retn();
283 //Perform the operation
284 HANDLE_NAMESPACE(GEOM_Object) anObject = GetOperations()->IntersectGroups(aGroupRef1, aGroupRef2);
285 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
287 return GetObject(anObject);
290 //=============================================================================
294 //=============================================================================
295 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CutGroups (GEOM::GEOM_Object_ptr theGroup1,
296 GEOM::GEOM_Object_ptr theGroup2)
298 GEOM::GEOM_Object_var aGEOMObject;
300 //Set a not done flag
301 GetOperations()->SetNotDone();
303 //Get the reference groups
304 HANDLE_NAMESPACE(GEOM_Object) aGroupRef1 = GetObjectImpl(theGroup1);
305 HANDLE_NAMESPACE(GEOM_Object) aGroupRef2 = GetObjectImpl(theGroup2);
306 if (aGroupRef1.IsNull() || aGroupRef2.IsNull()) return aGEOMObject._retn();
308 //Perform the operation
309 HANDLE_NAMESPACE(GEOM_Object) anObject = GetOperations()->CutGroups(aGroupRef1, aGroupRef2);
310 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
312 return GetObject(anObject);
315 //=============================================================================
319 //=============================================================================
320 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::UnionListOfGroups (const GEOM::ListOfGO& theGList)
322 GEOM::GEOM_Object_var aGEOMObject;
324 //Set a not done flag
325 GetOperations()->SetNotDone();
327 //Get the reference groups
328 Handle(TColStd_HSequenceOfTransient) aGroups = new TColStd_HSequenceOfTransient;
330 int ind, aLen = theGList.length();
331 for (ind = 0; ind < aLen; ind++) {
332 HANDLE_NAMESPACE(GEOM_Object) aGr = GetObjectImpl(theGList[ind]);
333 if (aGr.IsNull()) return aGEOMObject._retn();
334 aGroups->Append(aGr);
337 //Perform the operation
338 HANDLE_NAMESPACE(GEOM_Object) anObject = GetOperations()->UnionListOfGroups(aGroups);
339 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
341 return GetObject(anObject);
344 //=============================================================================
346 * IntersectListOfGroups
348 //=============================================================================
349 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::IntersectListOfGroups (const GEOM::ListOfGO& theGList)
351 GEOM::GEOM_Object_var aGEOMObject;
353 //Set a not done flag
354 GetOperations()->SetNotDone();
356 //Get the reference groups
357 Handle(TColStd_HSequenceOfTransient) aGroups = new TColStd_HSequenceOfTransient;
359 int ind, aLen = theGList.length();
360 for (ind = 0; ind < aLen; ind++) {
361 HANDLE_NAMESPACE(GEOM_Object) aGr = GetObjectImpl(theGList[ind]);
362 if (aGr.IsNull()) return aGEOMObject._retn();
363 aGroups->Append(aGr);
366 //Perform the operation
367 HANDLE_NAMESPACE(GEOM_Object) anObject = GetOperations()->IntersectListOfGroups(aGroups);
368 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
370 return GetObject(anObject);
373 //=============================================================================
377 //=============================================================================
378 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CutListOfGroups (const GEOM::ListOfGO& theGList1,
379 const GEOM::ListOfGO& theGList2)
381 GEOM::GEOM_Object_var aGEOMObject;
383 //Set a not done flag
384 GetOperations()->SetNotDone();
386 //Get the reference groups
387 Handle(TColStd_HSequenceOfTransient) aGroups1 = new TColStd_HSequenceOfTransient;
388 Handle(TColStd_HSequenceOfTransient) aGroups2 = new TColStd_HSequenceOfTransient;
390 int ind, aLen = theGList1.length();
391 for (ind = 0; ind < aLen; ind++) {
392 HANDLE_NAMESPACE(GEOM_Object) aGr = GetObjectImpl(theGList1[ind]);
393 if (aGr.IsNull()) return aGEOMObject._retn();
394 aGroups1->Append(aGr);
396 aLen = theGList2.length();
397 for (ind = 0; ind < aLen; ind++) {
398 HANDLE_NAMESPACE(GEOM_Object) aGr = GetObjectImpl(theGList2[ind]);
399 if (aGr.IsNull()) return aGEOMObject._retn();
400 aGroups2->Append(aGr);
403 //Perform the operation
404 HANDLE_NAMESPACE(GEOM_Object) anObject = GetOperations()->CutListOfGroups(aGroups1, aGroups2);
405 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
407 return GetObject(anObject);
410 //=============================================================================
414 //=============================================================================
415 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
417 //Set a not done flag
418 GetOperations()->SetNotDone();
420 //Get the reference group
421 HANDLE_NAMESPACE(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
422 if (aGroupRef.IsNull()) return -1;
424 return GetOperations()->GetType(aGroupRef);
427 //=============================================================================
431 //=============================================================================
432 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
434 GEOM::GEOM_Object_var aGEOMObject;
436 //Set a not done flag
437 GetOperations()->SetNotDone();
439 //Get the reference group
440 HANDLE_NAMESPACE(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
441 if (aGroupRef.IsNull()) return aGEOMObject._retn();
443 HANDLE_NAMESPACE(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
444 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
446 return GetObject(anObject);
449 //=============================================================================
453 //=============================================================================
454 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
456 GEOM::ListOfLong_var aList;
458 //Set a not done flag
459 GetOperations()->SetNotDone();
461 //Get the reference group
462 HANDLE_NAMESPACE(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
463 if (aGroupRef.IsNull()) return aList._retn();
465 aList = new GEOM::ListOfLong;
467 Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
468 if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
470 aList->length(aSeq->Length());
471 for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
473 return aList._retn();