1 // Copyright (C) 2007-2008 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 <GEOMImpl_IGroupOperations.hxx>
26 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
29 #include <GEOM_ISubShape.hxx>
30 #include <GEOM_PythonDump.hxx>
32 #include "utilities.h"
34 #include <Utils_ExceptHandlers.hxx>
36 #include <TFunction_DriverTable.hxx>
37 #include <TFunction_Driver.hxx>
38 #include <TFunction_Logbook.hxx>
39 #include <TDF_Tool.hxx>
40 #include <TDataStd_Integer.hxx>
43 #include <TopExp_Explorer.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <TColStd_HArray1OfInteger.hxx>
47 #include <TColStd_MapOfInteger.hxx>
48 #include <TColStd_ListOfInteger.hxx>
49 #include <TColStd_ListIteratorOfListOfInteger.hxx>
51 //=============================================================================
55 //=============================================================================
56 GEOMImpl_IGroupOperations::GEOMImpl_IGroupOperations (GEOM_Engine* theEngine, int theDocID)
57 : GEOM_IOperations(theEngine, theDocID)
59 MESSAGE("GEOMImpl_IGroupOperations::GEOMImpl_IGroupOperations");
62 //=============================================================================
66 //=============================================================================
67 GEOMImpl_IGroupOperations::~GEOMImpl_IGroupOperations()
69 MESSAGE("GEOMImpl_IGroupOperations::~GEOMImpl_IGroupOperations");
73 //=============================================================================
77 //=============================================================================
78 Handle(GEOM_Object) GEOMImpl_IGroupOperations::CreateGroup
79 (Handle(GEOM_Object) theMainShape, TopAbs_ShapeEnum theShapeType)
83 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1,1);
84 anArray->SetValue(1, -1);
86 //Add a new Sub-shape object
87 Handle(GEOM_Object) aGroup = GetEngine()->AddSubShape(theMainShape, anArray);
90 aGroup->SetType(GEOM_GROUP);
92 //Set a sub shape type
93 TDF_Label aFreeLabel = aGroup->GetFreeLabel();
94 TDataStd_Integer::Set(aFreeLabel, (Standard_Integer)theShapeType);
96 //Make a Python command
97 Handle(GEOM_Function) aFunction = aGroup->GetFunction(1);
99 GEOM::TPythonDump(aFunction) << aGroup
100 << " = geompy.CreateGroup(" << theMainShape << ", " << theShapeType << ")";
106 //=============================================================================
110 //=============================================================================
111 void GEOMImpl_IGroupOperations::AddObject(Handle(GEOM_Object) theGroup, int theSubShapeID)
114 if(theGroup.IsNull()) return;
116 Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
117 if(aFunction.IsNull()) return;
119 GEOM_ISubShape aSSI (aFunction);
121 // Check sub-shape index validity
122 TDF_Label aLabel = aSSI.GetMainShape()->GetOwnerEntry();
123 if (aLabel.IsRoot()) return;
124 Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
125 if (aMainObj.IsNull()) return;
126 TopoDS_Shape aMainShape = aMainObj->GetValue();
127 if (aMainShape.IsNull()) return;
129 TopTools_IndexedMapOfShape aMapOfShapes;
130 TopExp::MapShapes(aMainShape, aMapOfShapes);
132 if (theSubShapeID < 1 || aMapOfShapes.Extent() < theSubShapeID) {
133 SetErrorCode("Invalid sub-shape index: out of range");
137 // Add sub-shape index
138 Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
139 if(aSeq.IsNull()) return;
140 if(aSeq->Length() == 1 && aSeq->Value(1) == -1) {
141 aSeq->SetValue(1, theSubShapeID);
144 Standard_Integer aLength = aSeq->Length();
145 Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aLength+1);
146 for(Standard_Integer i = 1; i<=aLength; i++) {
147 aNewSeq->SetValue(i, aSeq->Value(i));
148 if(aSeq->Value(i) == theSubShapeID) {
149 SetErrorCode(ALREADY_PRESENT);
153 aNewSeq->SetValue(aLength+1, theSubShapeID);
154 aSSI.SetIndices(aNewSeq);
157 // As we do not recompute here our group, lets mark it as Modified
158 Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape
159 theGroup->SetTic(aTic - 1);
161 //Make a Python command
162 GEOM::TPythonDump(aFunction, /*append=*/true)
163 << "geompy.AddObject(" << theGroup << ", " << theSubShapeID << ")";
169 //=============================================================================
173 //=============================================================================
174 void GEOMImpl_IGroupOperations::RemoveObject (Handle(GEOM_Object) theGroup, int theSubShapeID)
177 if(theGroup.IsNull()) return;
179 Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
180 if(aFunction.IsNull()) return;
182 GEOM_ISubShape aSSI(aFunction);
183 Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
184 if(aSeq.IsNull()) return;
186 if(aSeq->Length() == 1 && aSeq->Value(1) == -1) {
187 SetErrorCode(NOT_EXISTS);
191 Handle(TColStd_HArray1OfInteger) aNewSeq;
192 Standard_Integer aLength = aSeq->Length();
194 if(aSeq->Value(1) != theSubShapeID) {
195 SetErrorCode(NOT_EXISTS);
198 aNewSeq = new TColStd_HArray1OfInteger(1,1);
199 aNewSeq->SetValue(1, -1);
202 aNewSeq = new TColStd_HArray1OfInteger(1, aLength-1);
203 Standard_Boolean isFound = Standard_False;
204 for (Standard_Integer i = 1, k = 1; i <= aLength; i++) {
205 if (aSeq->Value(i) == theSubShapeID) {
206 isFound = Standard_True;
208 if (k < aLength) { // this check is to avoid sequence <aNewSeq> overflow
209 aNewSeq->SetValue(k, aSeq->Value(i));
216 SetErrorCode(NOT_EXISTS);
221 aSSI.SetIndices(aNewSeq);
223 // As we do not recompute here our group, lets mark it as Modified
224 TDF_Label aLabel = aSSI.GetMainShape()->GetOwnerEntry();
225 if (aLabel.IsRoot()) return;
226 Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
227 if (aMainObj.IsNull()) return;
228 Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape
229 theGroup->SetTic(aTic - 1);
231 //Make a Python command
232 GEOM::TPythonDump(aFunction, /*append=*/true)
233 << "geompy.RemoveObject(" << theGroup << ", " << theSubShapeID << ")";
239 //=============================================================================
243 //=============================================================================
244 void GEOMImpl_IGroupOperations::UnionList (Handle(GEOM_Object) theGroup,
245 const Handle(TColStd_HSequenceOfTransient)& theSubShapes)
248 if (theGroup.IsNull()) return;
250 Standard_Integer aLen = theSubShapes->Length();
252 SetErrorCode("The list is empty");
256 Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
257 if (aFunction.IsNull()) return;
259 GEOM_ISubShape aSSI (aFunction);
261 // New contents of the group
262 TColStd_ListOfInteger aNewIDs;
263 TColStd_MapOfInteger mapIDs;
265 // Add current IDs to the list
266 Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
267 if (aSeq.IsNull()) return;
268 Standard_Integer val_j, aLength = aSeq->Length();
270 for (Standard_Integer j = 1; j <= aLength; j++) {
271 val_j = aSeq->Value(j);
272 if (val_j > 0 && mapIDs.Add(val_j)) {
273 aNewIDs.Append(val_j);
278 Handle(GEOM_Function) aMainShapeFunc = aSSI.GetMainShape();
279 if (aMainShapeFunc.IsNull()) return;
280 TDF_Label aLabel = aMainShapeFunc->GetOwnerEntry();
281 if (aLabel.IsRoot()) return;
282 Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
283 if (aMainObj.IsNull()) return;
284 TopoDS_Shape aMainShape = aMainObj->GetValue();
285 if (aMainShape.IsNull()) return;
287 TopTools_IndexedMapOfShape mapIndices;
288 TopExp::MapShapes(aMainShape, mapIndices);
291 TopAbs_ShapeEnum aType = GetType(theGroup);
293 // Get IDs of sub-shapes to add
294 Standard_Integer i, new_id;
295 for (i = 1; i <= aLen; i++) {
296 Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theSubShapes->Value(i));
298 TopoDS_Shape aShape_i = anObj_i->GetValue();
299 TopAbs_ShapeEnum aType_i = aShape_i.ShapeType();
301 // 1. If aShape_i is sub-shape of aMainShape - add it
302 if (anObj_i->IsMainShape()) {
303 if (aType_i != aType && aType != TopAbs_SHAPE && aType != TopAbs_COMPOUND) {
304 SetErrorCode("Operation aborted: one of given objects has a wrong type");
307 if (!mapIndices.Contains(aShape_i)) {
308 SetErrorCode("Operation aborted: not a sub-shape given");
311 new_id = mapIndices.FindIndex(aShape_i);
312 if (mapIDs.Add(new_id)) {
313 aNewIDs.Append(new_id);
316 // 2. If type of group is not defined - add all sub-shapes of aShape_i
317 else if (aType == TopAbs_SHAPE || aType == TopAbs_COMPOUND) {
318 TopTools_IndexedMapOfShape mapIndices_i;
319 TopExp::MapShapes(aShape_i, mapIndices_i);
320 Standard_Integer ii = 1, nbSubSh = mapIndices_i.Extent();
321 Standard_Boolean someGood = Standard_False;
322 for (; ii <= nbSubSh; ii++) {
323 TopoDS_Shape aSubShape_i = mapIndices_i.FindKey(ii);
324 if (mapIndices.Contains(aSubShape_i)) {
325 someGood = Standard_True;
326 new_id = mapIndices.FindIndex(aSubShape_i);
327 if (mapIDs.Add(new_id)) {
328 aNewIDs.Append(new_id);
333 SetErrorCode("Operation aborted: not a sub-shape given");
337 // 3. If type of group is defined - add all sub-shapes of aShape_i of that type
339 TopExp_Explorer aSubShapes_i (aShape_i, aType);
340 for (; aSubShapes_i.More(); aSubShapes_i.Next()) {
341 TopoDS_Shape aSubShape_i = aSubShapes_i.Current();
342 if (!mapIndices.Contains(aSubShape_i)) {
343 SetErrorCode("Operation aborted: not a sub-shape given");
346 new_id = mapIndices.FindIndex(aSubShape_i);
347 if (mapIDs.Add(new_id)) {
348 aNewIDs.Append(new_id);
354 if (aNewIDs.Extent() > 0) {
355 Standard_Integer k = 1;
356 TColStd_ListIteratorOfListOfInteger aNewIDsIter (aNewIDs);
357 Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aNewIDs.Extent());
358 for (; aNewIDsIter.More(); aNewIDsIter.Next(), k++) {
359 aNewSeq->SetValue(k, aNewIDsIter.Value());
362 aSSI.SetIndices(aNewSeq);
364 // As we do not recompute here our group, lets mark it as Modified
365 Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape
366 theGroup->SetTic(aTic - 1);
369 //Make a Python command
370 Handle(GEOM_Object) aLatest = GEOM::GetCreatedLast(theSubShapes);
371 aLatest = GEOM::GetCreatedLast(aLatest, theGroup);
372 Handle(GEOM_Function) aLastFunc = aLatest->GetLastFunction();
374 GEOM::TPythonDump pd (aLastFunc, /*append=*/true);
375 pd << "geompy.UnionList(" << theGroup << ", [";
377 for (i = 1; i <= aLen; i++) {
378 Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theSubShapes->Value(i));
379 pd << anObj_i << (( i < aLen ) ? ", " : "])");
385 //=============================================================================
389 //=============================================================================
390 void GEOMImpl_IGroupOperations::DifferenceList (Handle(GEOM_Object) theGroup,
391 const Handle(TColStd_HSequenceOfTransient)& theSubShapes)
394 if (theGroup.IsNull()) return;
396 Standard_Integer aLen = theSubShapes->Length();
398 SetErrorCode("The list is empty");
402 Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
403 if (aFunction.IsNull()) return;
405 GEOM_ISubShape aSSI (aFunction);
407 // Map of IDs to be removed
408 TColStd_MapOfInteger mapIDsToRemove;
410 // Map of current IDs
411 Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
412 if (aSeq.IsNull()) return;
413 Standard_Integer aLength = aSeq->Length();
415 if (aLength == 1 && aSeq->Value(1) == -1) // empty group
418 TColStd_MapOfInteger mapIDsCurrent;
419 Standard_Integer j = 1;
420 for (; j <= aLength; j++) {
421 mapIDsCurrent.Add(aSeq->Value(j));
425 Handle(GEOM_Function) aMainShapeFunc = aSSI.GetMainShape();
426 if (aMainShapeFunc.IsNull()) return;
427 TDF_Label aLabel = aMainShapeFunc->GetOwnerEntry();
428 if (aLabel.IsRoot()) return;
429 Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
430 if (aMainObj.IsNull()) return;
431 TopoDS_Shape aMainShape = aMainObj->GetValue();
432 if (aMainShape.IsNull()) return;
434 TopTools_IndexedMapOfShape mapIndices;
435 TopExp::MapShapes(aMainShape, mapIndices);
438 TopAbs_ShapeEnum aType = GetType(theGroup);
440 // Get IDs of sub-shapes to be removed
441 Standard_Integer i, rem_id;
442 for (i = 1; i <= aLen; i++) {
443 Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theSubShapes->Value(i));
445 TopoDS_Shape aShape_i = anObj_i->GetValue();
447 // 1. If aShape_i is sub-shape of aMainShape - remove it
448 if (mapIndices.Contains(aShape_i)) {
449 rem_id = mapIndices.FindIndex(aShape_i);
450 if (mapIDsCurrent.Contains(rem_id)) {
451 mapIDsToRemove.Add(rem_id);
454 // 2. If type of group is not defined - remove all sub-shapes of aShape_i
455 else if (aType == TopAbs_SHAPE || aType == TopAbs_COMPOUND) {
456 TopTools_IndexedMapOfShape mapIndices_i;
457 TopExp::MapShapes(aShape_i, mapIndices_i);
458 Standard_Integer nbSubSh = mapIndices_i.Extent();
459 Standard_Integer ii = 1;
460 for (; ii <= nbSubSh; ii++) {
461 TopoDS_Shape aSubShape_i = mapIndices_i.FindKey(ii);
462 if (mapIndices.Contains(aSubShape_i)) {
463 rem_id = mapIndices.FindIndex(aSubShape_i);
464 if (mapIDsCurrent.Contains(rem_id)) {
465 mapIDsToRemove.Add(rem_id);
470 // 3. If type of group is defined - remove all sub-shapes of aShape_i of that type
472 TopExp_Explorer aSubShapes_i (aShape_i, aType);
473 for (; aSubShapes_i.More(); aSubShapes_i.Next()) {
474 TopoDS_Shape aSubShape_i = aSubShapes_i.Current();
475 if (mapIndices.Contains(aSubShape_i)) {
476 rem_id = mapIndices.FindIndex(aSubShape_i);
477 if (mapIDsCurrent.Contains(rem_id)) {
478 mapIDsToRemove.Add(rem_id);
485 if (mapIDsToRemove.Extent() > 0) {
486 Standard_Integer k = 1, aRemLength = mapIDsToRemove.Extent();
487 Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aLength - aRemLength);
489 for (j = 1; j <= aLength; j++) {
490 if (!mapIDsToRemove.Contains(aSeq->Value(j))) {
491 aNewSeq->SetValue(k, aSeq->Value(j));
496 aSSI.SetIndices(aNewSeq);
498 // As we do not recompute here our group, lets mark it as Modified
499 Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape
500 theGroup->SetTic(aTic - 1);
503 //Make a Python command
504 Handle(GEOM_Object) aLatest = GEOM::GetCreatedLast(theSubShapes);
505 aLatest = GEOM::GetCreatedLast(aLatest, theGroup);
506 Handle(GEOM_Function) aLastFunc = aLatest->GetLastFunction();
508 GEOM::TPythonDump pd (aLastFunc, /*append=*/true);
509 pd << "geompy.DifferenceList(" << theGroup << ", [";
511 for (i = 1; i <= aLen; i++) {
512 Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theSubShapes->Value(i));
513 pd << anObj_i << (( i < aLen ) ? ", " : "])");
519 //=============================================================================
523 //=============================================================================
524 void GEOMImpl_IGroupOperations::UnionIDs (Handle(GEOM_Object) theGroup,
525 const Handle(TColStd_HSequenceOfInteger)& theSubShapes)
528 if (theGroup.IsNull()) return;
530 Standard_Integer aLen = theSubShapes->Length();
532 SetErrorCode("The list is empty");
536 Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
537 if (aFunction.IsNull()) return;
539 GEOM_ISubShape aSSI (aFunction);
541 // New contents of the group
542 TColStd_ListOfInteger aNewIDs;
543 TColStd_MapOfInteger mapIDs;
545 // Add current IDs to the list
546 Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
547 if (aSeq.IsNull()) return;
548 Standard_Integer val_j, aLength = aSeq->Length();
550 for (Standard_Integer j = 1; j <= aLength; j++) {
551 val_j = aSeq->Value(j);
552 if (val_j > 0 && mapIDs.Add(val_j)) {
553 aNewIDs.Append(val_j);
558 Handle(GEOM_Function) aMainShapeFunc = aSSI.GetMainShape();
559 if (aMainShapeFunc.IsNull()) return;
560 TDF_Label aLabel = aMainShapeFunc->GetOwnerEntry();
561 if (aLabel.IsRoot()) return;
562 Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
563 if (aMainObj.IsNull()) return;
564 TopoDS_Shape aMainShape = aMainObj->GetValue();
565 if (aMainShape.IsNull()) return;
567 TopTools_IndexedMapOfShape mapIndices;
568 TopExp::MapShapes(aMainShape, mapIndices);
571 TopAbs_ShapeEnum aType = GetType(theGroup);
573 // Get IDs of sub-shapes to add
574 Standard_Integer i, new_id;
575 for (i = 1; i <= aLen; i++) {
576 new_id = theSubShapes->Value(i);
578 if (0 < new_id && new_id <= mapIndices.Extent()) {
579 //if (mapIDs.Add(new_id)) { IPAL21297. Why we ignore invalid ids silently?
580 if (mapIDs.Add(new_id) && mapIndices(new_id).ShapeType()==aType ) {
581 aNewIDs.Append(new_id);
586 if (aNewIDs.Extent() > 0) {
587 Standard_Integer k = 1;
588 TColStd_ListIteratorOfListOfInteger aNewIDsIter (aNewIDs);
589 Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aNewIDs.Extent());
590 for (; aNewIDsIter.More(); aNewIDsIter.Next(), k++) {
591 aNewSeq->SetValue(k, aNewIDsIter.Value());
594 aSSI.SetIndices(aNewSeq);
596 // As we do not recompute here our group, lets mark it as Modified
597 Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape
598 theGroup->SetTic(aTic - 1);
601 //Make a Python command
602 GEOM::TPythonDump pd (aFunction, /*append=*/true);
603 pd << "geompy.UnionIDs(" << theGroup << ", [";
604 for (i = 1; i < aLen; i++)
605 pd << theSubShapes->Value(i) << ", ";
606 pd << theSubShapes->Value(aLen) << "])";
611 //=============================================================================
615 //=============================================================================
616 void GEOMImpl_IGroupOperations::DifferenceIDs (Handle(GEOM_Object) theGroup,
617 const Handle(TColStd_HSequenceOfInteger)& theSubShapes)
620 if (theGroup.IsNull()) return;
622 Standard_Integer aLen = theSubShapes->Length();
624 SetErrorCode("The list is empty");
628 Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
629 if (aFunction.IsNull()) return;
631 GEOM_ISubShape aSSI (aFunction);
633 // Map of IDs to be removed
634 TColStd_MapOfInteger mapIDsToRemove;
636 // Map of current IDs
637 Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
638 if (aSeq.IsNull()) return;
639 Standard_Integer aLength = aSeq->Length();
641 if (aLength == 1 && aSeq->Value(1) == -1) // empty group
644 TColStd_MapOfInteger mapIDsCurrent;
645 Standard_Integer j = 1;
646 for (; j <= aLength; j++) {
647 mapIDsCurrent.Add(aSeq->Value(j));
651 Handle(GEOM_Function) aMainShapeFunc = aSSI.GetMainShape();
652 if (aMainShapeFunc.IsNull()) return;
653 TDF_Label aLabel = aMainShapeFunc->GetOwnerEntry();
654 if (aLabel.IsRoot()) return;
655 Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
656 if (aMainObj.IsNull()) return;
657 TopoDS_Shape aMainShape = aMainObj->GetValue();
658 if (aMainShape.IsNull()) return;
660 TopTools_IndexedMapOfShape mapIndices;
661 TopExp::MapShapes(aMainShape, mapIndices);
663 // Get IDs of sub-shapes to be removed
664 Standard_Integer i, rem_id;
665 for (i = 1; i <= aLen; i++) {
666 rem_id = theSubShapes->Value(i);
667 if (mapIDsCurrent.Contains(rem_id)) {
668 mapIDsToRemove.Add(rem_id);
672 if (mapIDsToRemove.Extent() > 0) {
673 Standard_Integer k = 1, aRemLength = mapIDsToRemove.Extent();
674 Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aLength - aRemLength);
676 for (j = 1; j <= aLength; j++) {
677 if (!mapIDsToRemove.Contains(aSeq->Value(j))) {
678 aNewSeq->SetValue(k, aSeq->Value(j));
683 aSSI.SetIndices(aNewSeq);
685 // As we do not recompute here our group, lets mark it as Modified
686 Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape
687 theGroup->SetTic(aTic - 1);
690 //Make a Python command
691 GEOM::TPythonDump pd (aFunction, /*append=*/true);
692 pd << "geompy.DifferenceIDs(" << theGroup << ", [";
693 for (i = 1; i < aLen; i++)
694 pd << theSubShapes->Value(i) << ", ";
695 pd << theSubShapes->Value(aLen) << "])";
700 //=============================================================================
704 //=============================================================================
705 TopAbs_ShapeEnum GEOMImpl_IGroupOperations::GetType(Handle(GEOM_Object) theGroup)
709 TDF_Label aFreeLabel = theGroup->GetFreeLabel();
710 Handle(TDataStd_Integer) anAttrib;
711 if(!aFreeLabel.FindAttribute(TDataStd_Integer::GetID(), anAttrib)) return TopAbs_SHAPE;
714 return (TopAbs_ShapeEnum) anAttrib->Get();
717 //=============================================================================
721 //=============================================================================
722 Handle(GEOM_Object) GEOMImpl_IGroupOperations::GetMainShape (Handle(GEOM_Object) theGroup)
726 if(theGroup.IsNull()) return NULL;
728 Handle(GEOM_Function) aGroupFunction = theGroup->GetFunction(1);
729 if (aGroupFunction.IsNull()) return NULL;
731 GEOM_ISubShape aSSI (aGroupFunction);
732 Handle(GEOM_Function) aMainShapeFunction = aSSI.GetMainShape();
733 if (aMainShapeFunction.IsNull()) return NULL;
735 TDF_Label aLabel = aMainShapeFunction->GetOwnerEntry();
736 Handle(GEOM_Object) aMainShape = GEOM_Object::GetObject(aLabel);
737 if (aMainShape.IsNull()) return NULL;
739 //Make a Python command
740 //GEOM::TPythonDump(aGroupFunction, /*append=*/true)
741 // << aMainShape << " = geompy.GetMainShape(" << theGroup << ")";
747 //=============================================================================
751 //=============================================================================
752 Handle(TColStd_HArray1OfInteger) GEOMImpl_IGroupOperations::GetObjects(Handle(GEOM_Object) theGroup)
756 if(theGroup.IsNull()) return NULL;
758 Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
759 if(aFunction.IsNull()) return NULL;
761 GEOM_ISubShape aSSI(aFunction);
762 Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
763 if(aSeq.IsNull()) return NULL;
765 if(aSeq->Length() == 1 && aSeq->Value(1) == -1) {