1. Unify behavior of UnionList, DifferentList, UnionIDs, DifferenceIDs functions when empty list is passed as parameter - no exception should be raised in this case.

2. Avoid raising exception in DifferenceList, DifferenceIDs functions if the group is empty
3. Fix bug in DifferenceIDs function - bad list of IDs is contained when the group is cleared.
This commit is contained in:
vsr 2011-04-28 12:47:26 +00:00
parent 8e9aa9b888
commit 88ffbe62e8

View File

@ -397,7 +397,8 @@ void GEOMImpl_IGroupOperations::DifferenceList (Handle(GEOM_Object) theGroup,
Standard_Integer aLen = theSubShapes->Length(); Standard_Integer aLen = theSubShapes->Length();
if (aLen < 1) { if (aLen < 1) {
SetErrorCode("The list is empty"); //SetErrorCode("The list is empty");
SetErrorCode(OK);
return; return;
} }
@ -414,8 +415,9 @@ void GEOMImpl_IGroupOperations::DifferenceList (Handle(GEOM_Object) theGroup,
if (aSeq.IsNull()) return; if (aSeq.IsNull()) return;
Standard_Integer aLength = aSeq->Length(); Standard_Integer aLength = aSeq->Length();
if (aLength == 1 && aSeq->Value(1) == -1) // empty group // VSR 28/04/2011 commented to allow operation even for empty group
return; // if (aLength == 1 && aSeq->Value(1) == -1) // empty group
// return;
TColStd_MapOfInteger mapIDsCurrent; TColStd_MapOfInteger mapIDsCurrent;
Standard_Integer j = 1; Standard_Integer j = 1;
@ -449,7 +451,7 @@ void GEOMImpl_IGroupOperations::DifferenceList (Handle(GEOM_Object) theGroup,
// 1. If aShape_i is sub-shape of aMainShape - remove it // 1. If aShape_i is sub-shape of aMainShape - remove it
if (mapIndices.Contains(aShape_i)) { if (mapIndices.Contains(aShape_i)) {
rem_id = mapIndices.FindIndex(aShape_i); rem_id = mapIndices.FindIndex(aShape_i);
if (mapIDsCurrent.Contains(rem_id)) { if (rem_id > 0 && mapIDsCurrent.Contains(rem_id)) {
mapIDsToRemove.Add(rem_id); mapIDsToRemove.Add(rem_id);
} }
} }
@ -463,7 +465,7 @@ void GEOMImpl_IGroupOperations::DifferenceList (Handle(GEOM_Object) theGroup,
TopoDS_Shape aSubShape_i = mapIndices_i.FindKey(ii); TopoDS_Shape aSubShape_i = mapIndices_i.FindKey(ii);
if (mapIndices.Contains(aSubShape_i)) { if (mapIndices.Contains(aSubShape_i)) {
rem_id = mapIndices.FindIndex(aSubShape_i); rem_id = mapIndices.FindIndex(aSubShape_i);
if (mapIDsCurrent.Contains(rem_id)) { if (rem_id > 0 && mapIDsCurrent.Contains(rem_id)) {
mapIDsToRemove.Add(rem_id); mapIDsToRemove.Add(rem_id);
} }
} }
@ -476,7 +478,7 @@ void GEOMImpl_IGroupOperations::DifferenceList (Handle(GEOM_Object) theGroup,
TopoDS_Shape aSubShape_i = aSubShapes_i.Current(); TopoDS_Shape aSubShape_i = aSubShapes_i.Current();
if (mapIndices.Contains(aSubShape_i)) { if (mapIndices.Contains(aSubShape_i)) {
rem_id = mapIndices.FindIndex(aSubShape_i); rem_id = mapIndices.FindIndex(aSubShape_i);
if (mapIDsCurrent.Contains(rem_id)) { if (rem_id > 0 && mapIDsCurrent.Contains(rem_id)) {
mapIDsToRemove.Add(rem_id); mapIDsToRemove.Add(rem_id);
} }
} }
@ -537,7 +539,8 @@ void GEOMImpl_IGroupOperations::UnionIDs (Handle(GEOM_Object) theGroup,
Standard_Integer aLen = theSubShapes->Length(); Standard_Integer aLen = theSubShapes->Length();
if (aLen < 1) { if (aLen < 1) {
SetErrorCode("The list is empty"); //SetErrorCode("The list is empty");
SetErrorCode(OK);
return; return;
} }
@ -629,7 +632,8 @@ void GEOMImpl_IGroupOperations::DifferenceIDs (Handle(GEOM_Object) theGroup,
Standard_Integer aLen = theSubShapes->Length(); Standard_Integer aLen = theSubShapes->Length();
if (aLen < 1) { if (aLen < 1) {
SetErrorCode("The list is empty"); //SetErrorCode("The list is empty");
SetErrorCode(OK);
return; return;
} }
@ -646,8 +650,9 @@ void GEOMImpl_IGroupOperations::DifferenceIDs (Handle(GEOM_Object) theGroup,
if (aSeq.IsNull()) return; if (aSeq.IsNull()) return;
Standard_Integer aLength = aSeq->Length(); Standard_Integer aLength = aSeq->Length();
if (aLength == 1 && aSeq->Value(1) == -1) // empty group // VSR 28/04/2011 commented to allow operation even for empty group
return; // if (aLength == 1 && aSeq->Value(1) == -1) // empty group
// return;
TColStd_MapOfInteger mapIDsCurrent; TColStd_MapOfInteger mapIDsCurrent;
Standard_Integer j = 1; Standard_Integer j = 1;
@ -672,21 +677,27 @@ void GEOMImpl_IGroupOperations::DifferenceIDs (Handle(GEOM_Object) theGroup,
Standard_Integer i, rem_id; Standard_Integer i, rem_id;
for (i = 1; i <= aLen; i++) { for (i = 1; i <= aLen; i++) {
rem_id = theSubShapes->Value(i); rem_id = theSubShapes->Value(i);
if (mapIDsCurrent.Contains(rem_id)) { if (rem_id > 0 && mapIDsCurrent.Contains(rem_id)) {
mapIDsToRemove.Add(rem_id); mapIDsToRemove.Add(rem_id);
} }
} }
if (mapIDsToRemove.Extent() > 0) { if (mapIDsToRemove.Extent() > 0) {
Standard_Integer k = 1, aRemLength = mapIDsToRemove.Extent(); Standard_Integer k = 1, aRemLength = mapIDsToRemove.Extent();
Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aLength - aRemLength); Handle(TColStd_HArray1OfInteger) aNewSeq;
if ( aLength - aRemLength > 0 ) {
for (j = 1; j <= aLength; j++) { aNewSeq = new TColStd_HArray1OfInteger(1, aLength - aRemLength);
if (!mapIDsToRemove.Contains(aSeq->Value(j))) { for (j = 1; j <= aLength; j++) {
aNewSeq->SetValue(k, aSeq->Value(j)); if (!mapIDsToRemove.Contains(aSeq->Value(j))) {
k++; aNewSeq->SetValue(k, aSeq->Value(j));
k++;
}
} }
} }
else {
aNewSeq = new TColStd_HArray1OfInteger(1,1);
aNewSeq->SetValue(1, -1);
}
aSSI.SetIndices(aNewSeq); aSSI.SetIndices(aNewSeq);