Back to index

salome-geom  6.5.0
Public Member Functions | Public Attributes
GEOMImpl_IGroupOperations Class Reference

#include <GEOMImpl_IGroupOperations.hxx>

Inheritance diagram for GEOMImpl_IGroupOperations:
Inheritance graph
[legend]
Collaboration diagram for GEOMImpl_IGroupOperations:
Collaboration graph
[legend]

List of all members.

Public Member Functions

Standard_EXPORT GEOMImpl_IGroupOperations (GEOM_Engine *theEngine, int theDocID)
 constructor:
Standard_EXPORT ~GEOMImpl_IGroupOperations ()
 destructor
Standard_EXPORT Handle (GEOM_Object) CreateGroup(Handle(GEOM_Object) theMainShape
Standard_EXPORT void AddObject (Handle(GEOM_Object) theGroup, int theSubShapeID)
 AddObject.
Standard_EXPORT void RemoveObject (Handle(GEOM_Object) theGroup, int theSubShapeID)
 RemoveObject.
Standard_EXPORT void UnionList (Handle(GEOM_Object) theGroup, const Handle(TColStd_HSequenceOfTransient)&theSubShapes)
 UnionList.
Standard_EXPORT void DifferenceList (Handle(GEOM_Object) theGroup, const Handle(TColStd_HSequenceOfTransient)&theSubShapes)
 DifferenceList.
Standard_EXPORT void UnionIDs (Handle(GEOM_Object) theGroup, const Handle(TColStd_HSequenceOfInteger)&theSubShapes)
 UnionIDs.
Standard_EXPORT void DifferenceIDs (Handle(GEOM_Object) theGroup, const Handle(TColStd_HSequenceOfInteger)&theSubShapes)
 DifferenceIDs.
Standard_EXPORT TopAbs_ShapeEnum GetType (Handle(GEOM_Object) theGroup)
 GetType.
Standard_EXPORT Handle (GEOM_Object) GetMainShape(Handle(GEOM_Object) theGroup)
Standard_EXPORT Handle (TColStd_HArray1OfInteger) GetObjects(Handle(GEOM_Object) theGroup)
Standard_EXPORT void StartOperation ()
 StartOperation.
Standard_EXPORT void FinishOperation ()
 FinishOperation.
Standard_EXPORT void AbortOperation ()
 AbortOperation.
Standard_EXPORT bool IsDone ()
 IsDone.
Standard_EXPORT void SetNotDone ()
Standard_EXPORT void SetErrorCode (const TCollection_AsciiString &theErrorCode)
Standard_EXPORT char * GetErrorCode ()
Standard_EXPORT GEOM_EngineGetEngine ()
Standard_EXPORT GEOM_SolverGetSolver ()
Standard_EXPORT int GetDocID ()

Public Attributes

Standard_EXPORT TopAbs_ShapeEnum theShapeType

Detailed Description

Definition at line 35 of file GEOMImpl_IGroupOperations.hxx.


Constructor & Destructor Documentation

constructor:

Definition at line 57 of file GEOMImpl_IGroupOperations.cxx.

: GEOM_IOperations(theEngine, theDocID)
{
  MESSAGE("GEOMImpl_IGroupOperations::GEOMImpl_IGroupOperations");
}

destructor

Definition at line 68 of file GEOMImpl_IGroupOperations.cxx.

{
  MESSAGE("GEOMImpl_IGroupOperations::~GEOMImpl_IGroupOperations");
}

Member Function Documentation

void GEOM_IOperations::AbortOperation ( ) [inherited]

AbortOperation.

Definition at line 89 of file GEOM_IOperations.cxx.

{
  Handle(TDocStd_Document) aDoc = _engine->GetDocument(_docID);
  aDoc->AbortCommand();
}

Here is the call graph for this function:

void GEOMImpl_IGroupOperations::AddObject ( Handle(GEOM_Object theGroup,
int  theSubShapeID 
)

AddObject.

Definition at line 112 of file GEOMImpl_IGroupOperations.cxx.

{
  SetErrorCode(KO);
  if(theGroup.IsNull()) return;

  Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
  if(aFunction.IsNull()) return;

  GEOM_ISubShape aSSI (aFunction);

  // Check sub-shape index validity
  TDF_Label aLabel = aSSI.GetMainShape()->GetOwnerEntry();
  if (aLabel.IsRoot()) return;
  Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
  if (aMainObj.IsNull()) return;
  TopoDS_Shape aMainShape = aMainObj->GetValue();
  if (aMainShape.IsNull()) return;

  TopTools_IndexedMapOfShape aMapOfShapes;
  TopExp::MapShapes(aMainShape, aMapOfShapes);

  if (theSubShapeID < 1 || aMapOfShapes.Extent() < theSubShapeID) {
    SetErrorCode("Invalid sub-shape index: out of range");
    return;
  }

  // Add sub-shape index
  Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
  if(aSeq.IsNull()) return;
  if(aSeq->Length() == 1 && aSeq->Value(1) == -1) {
    aSeq->SetValue(1, theSubShapeID);
  }
  else {
    Standard_Integer aLength = aSeq->Length();
    Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aLength+1);
    for(Standard_Integer i = 1; i<=aLength; i++) {
      aNewSeq->SetValue(i, aSeq->Value(i));
      if(aSeq->Value(i) == theSubShapeID) {
        SetErrorCode(ALREADY_PRESENT);
        return; //
      }
    }
    aNewSeq->SetValue(aLength+1, theSubShapeID);
    aSSI.SetIndices(aNewSeq);
  }

  // As we do not recompute here our group, lets mark it as Modified
  Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape
  theGroup->SetTic(aTic - 1);

  //Make a Python command
  GEOM::TPythonDump(aFunction, /*append=*/true)
    << "geompy.AddObject(" << theGroup << ", " << theSubShapeID << ")";

  SetErrorCode(OK);
  return;
}

Here is the call graph for this function:

void GEOMImpl_IGroupOperations::DifferenceIDs ( Handle(GEOM_Object theGroup,
const Handle(TColStd_HSequenceOfInteger)&  theSubShapes 
)

DifferenceIDs.

Definition at line 628 of file GEOMImpl_IGroupOperations.cxx.

{
  SetErrorCode(KO);
  if (theGroup.IsNull()) return;

  Standard_Integer aLen = theSubShapes->Length();
  if (aLen < 1) {
    //SetErrorCode("The list is empty");
    SetErrorCode(OK);
    return;
  }

  Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
  if (aFunction.IsNull()) return;

  GEOM_ISubShape aSSI (aFunction);

  // Map of IDs to be removed
  TColStd_MapOfInteger mapIDsToRemove;

  // Map of current IDs
  Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
  if (aSeq.IsNull()) return;
  Standard_Integer aLength = aSeq->Length();

  // VSR 28/04/2011 commented to allow operation even for empty group
  //   if (aLength == 1 && aSeq->Value(1) == -1) // empty group
  //     return;

  TColStd_MapOfInteger mapIDsCurrent;
  Standard_Integer j = 1;
  for (; j <= aLength; j++) {
    mapIDsCurrent.Add(aSeq->Value(j));
  }

  // Get Main Shape
  Handle(GEOM_Function) aMainShapeFunc = aSSI.GetMainShape();
  if (aMainShapeFunc.IsNull()) return;
  TDF_Label aLabel = aMainShapeFunc->GetOwnerEntry();
  if (aLabel.IsRoot()) return;
  Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
  if (aMainObj.IsNull()) return;
  TopoDS_Shape aMainShape = aMainObj->GetValue();
  if (aMainShape.IsNull()) return;

  TopTools_IndexedMapOfShape mapIndices;
  TopExp::MapShapes(aMainShape, mapIndices);

  // Get IDs of sub-shapes to be removed
  Standard_Integer i, rem_id;
  for (i = 1; i <= aLen; i++) {
    rem_id = theSubShapes->Value(i);
    if (rem_id > 0 && mapIDsCurrent.Contains(rem_id)) {
      mapIDsToRemove.Add(rem_id);
    }
  }

  if (mapIDsToRemove.Extent() > 0) {
    Standard_Integer k = 1, aRemLength = mapIDsToRemove.Extent();
    Handle(TColStd_HArray1OfInteger) aNewSeq;
    if ( aLength - aRemLength > 0 ) {
      aNewSeq = new TColStd_HArray1OfInteger(1, aLength - aRemLength);
      for (j = 1; j <= aLength; j++) {
       if (!mapIDsToRemove.Contains(aSeq->Value(j))) {
         aNewSeq->SetValue(k, aSeq->Value(j));
         k++;
       }
      }
    }
    else {
      aNewSeq = new TColStd_HArray1OfInteger(1,1);
      aNewSeq->SetValue(1, -1);
    }

    aSSI.SetIndices(aNewSeq);

    // As we do not recompute here our group, lets mark it as Modified
    Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape
    theGroup->SetTic(aTic - 1);
  }

  //Make a Python command
  GEOM::TPythonDump pd (aFunction, /*append=*/true);
  pd << "geompy.DifferenceIDs(" << theGroup << ", [";
  for (i = 1; i < aLen; i++)
    pd << theSubShapes->Value(i) << ", ";
  pd << theSubShapes->Value(aLen) << "])";

  SetErrorCode(OK);
}

Here is the call graph for this function:

void GEOMImpl_IGroupOperations::DifferenceList ( Handle(GEOM_Object theGroup,
const Handle(TColStd_HSequenceOfTransient)&  theSubShapes 
)

DifferenceList.

Definition at line 393 of file GEOMImpl_IGroupOperations.cxx.

{
  SetErrorCode(KO);
  if (theGroup.IsNull()) return;

  Standard_Integer aLen = theSubShapes->Length();
  if (aLen < 1) {
    //SetErrorCode("The list is empty");
    SetErrorCode(OK);
    return;
  }

  Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
  if (aFunction.IsNull()) return;

  GEOM_ISubShape aSSI (aFunction);

  // Map of IDs to be removed
  TColStd_MapOfInteger mapIDsToRemove;

  // Map of current IDs
  Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
  if (aSeq.IsNull()) return;
  Standard_Integer aLength = aSeq->Length();

  // VSR 28/04/2011 commented to allow operation even for empty group
  //   if (aLength == 1 && aSeq->Value(1) == -1) // empty group
  //     return;

  TColStd_MapOfInteger mapIDsCurrent;
  Standard_Integer j = 1;
  for (; j <= aLength; j++) {
    mapIDsCurrent.Add(aSeq->Value(j));
  }

  // Get Main Shape
  Handle(GEOM_Function) aMainShapeFunc = aSSI.GetMainShape();
  if (aMainShapeFunc.IsNull()) return;
  TDF_Label aLabel = aMainShapeFunc->GetOwnerEntry();
  if (aLabel.IsRoot()) return;
  Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
  if (aMainObj.IsNull()) return;
  TopoDS_Shape aMainShape = aMainObj->GetValue();
  if (aMainShape.IsNull()) return;

  TopTools_IndexedMapOfShape mapIndices;
  TopExp::MapShapes(aMainShape, mapIndices);

  // Get group type
  TopAbs_ShapeEnum aType = GetType(theGroup);

  // Get IDs of sub-shapes to be removed
  Standard_Integer i, rem_id;
  for (i = 1; i <= aLen; i++) {
    Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theSubShapes->Value(i));

    TopoDS_Shape aShape_i = anObj_i->GetValue();

    // 1. If aShape_i is sub-shape of aMainShape - remove it
    if (mapIndices.Contains(aShape_i)) {
      rem_id = mapIndices.FindIndex(aShape_i);
      if (rem_id > 0 && mapIDsCurrent.Contains(rem_id)) {
        mapIDsToRemove.Add(rem_id);
      }
    }
    // 2. If type of group is not defined - remove all sub-shapes of aShape_i
    else if (aType == TopAbs_SHAPE || aType == TopAbs_COMPOUND) {
      TopTools_IndexedMapOfShape mapIndices_i;
      TopExp::MapShapes(aShape_i, mapIndices_i);
      Standard_Integer nbSubSh = mapIndices_i.Extent();
      Standard_Integer ii = 1;
      for (; ii <= nbSubSh; ii++) {
        TopoDS_Shape aSubShape_i = mapIndices_i.FindKey(ii);
        if (mapIndices.Contains(aSubShape_i)) {
          rem_id = mapIndices.FindIndex(aSubShape_i);
          if (rem_id > 0 && mapIDsCurrent.Contains(rem_id)) {
            mapIDsToRemove.Add(rem_id);
          }
        }
      }
    }
    // 3. If type of group is defined - remove all sub-shapes of aShape_i of that type
    else {
      TopExp_Explorer aSubShapes_i (aShape_i, aType);
      for (; aSubShapes_i.More(); aSubShapes_i.Next()) {
        TopoDS_Shape aSubShape_i = aSubShapes_i.Current();
        if (mapIndices.Contains(aSubShape_i)) {
          rem_id = mapIndices.FindIndex(aSubShape_i);
          if (rem_id > 0 && mapIDsCurrent.Contains(rem_id)) {
            mapIDsToRemove.Add(rem_id);
          }
        }
      }
    }
  }

  if (mapIDsToRemove.Extent() > 0) {
    Standard_Integer k = 1, aRemLength = mapIDsToRemove.Extent();
    Handle(TColStd_HArray1OfInteger) aNewSeq;
    if ( aLength - aRemLength > 0 ) {
      aNewSeq = new TColStd_HArray1OfInteger(1, aLength - aRemLength);
      for (j = 1; j <= aLength; j++) {
       if (!mapIDsToRemove.Contains(aSeq->Value(j))) {
         aNewSeq->SetValue(k, aSeq->Value(j));
         k++;
       }
      }
    }
    else {
      aNewSeq = new TColStd_HArray1OfInteger(1,1);
      aNewSeq->SetValue(1, -1);
    }

    aSSI.SetIndices(aNewSeq);

    // As we do not recompute here our group, lets mark it as Modified
    Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape
    theGroup->SetTic(aTic - 1);
  }

  //Make a Python command
  Handle(GEOM_Object) aLatest = GEOM::GetCreatedLast(theSubShapes);
  aLatest = GEOM::GetCreatedLast(aLatest, theGroup);
  Handle(GEOM_Function) aLastFunc = aLatest->GetLastFunction();

  GEOM::TPythonDump pd (aLastFunc, /*append=*/true);
  pd << "geompy.DifferenceList(" << theGroup << ", [";

  for (i = 1; i <= aLen; i++) {
    Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theSubShapes->Value(i));
    pd << anObj_i << (( i < aLen ) ? ", " : "])");
  }

  SetErrorCode(OK);
}

Here is the call graph for this function:

void GEOM_IOperations::FinishOperation ( ) [inherited]

FinishOperation.

Definition at line 77 of file GEOM_IOperations.cxx.

{
  Handle(TDocStd_Document) aDoc = _engine->GetDocument(_docID);
  if(aDoc->GetUndoLimit() > 0) 
    aDoc->CommitCommand();
}

Here is the call graph for this function:

Standard_EXPORT int GEOM_IOperations::GetDocID ( ) [inline, inherited]

Definition at line 77 of file GEOM_IOperations.hxx.

{ return _docID; }

Here is the caller graph for this function:

Definition at line 71 of file GEOM_IOperations.hxx.

{ return _engine; }

Here is the caller graph for this function:

Standard_EXPORT char* GEOM_IOperations::GetErrorCode ( ) [inline, inherited]

Definition at line 66 of file GEOM_IOperations.hxx.

                                       {
    return (char*) _errorCode.ToCString();    
  }

Here is the caller graph for this function:

Definition at line 74 of file GEOM_IOperations.hxx.

{ return _solver; }
TopAbs_ShapeEnum GEOMImpl_IGroupOperations::GetType ( Handle(GEOM_Object theGroup)

GetType.

Definition at line 725 of file GEOMImpl_IGroupOperations.cxx.

{
  SetErrorCode(KO);

  TDF_Label aFreeLabel = theGroup->GetFreeLabel();
  Handle(TDataStd_Integer) anAttrib;
  if(!aFreeLabel.FindAttribute(TDataStd_Integer::GetID(), anAttrib)) return TopAbs_SHAPE;

  SetErrorCode(OK);
  return (TopAbs_ShapeEnum) anAttrib->Get();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Here is the caller graph for this function:

Standard_EXPORT GEOMImpl_IGroupOperations::Handle ( TColStd_HArray1OfInteger  )
bool GEOM_IOperations::IsDone ( ) [inherited]

IsDone.

Definition at line 101 of file GEOM_IOperations.cxx.

{
  return (_errorCode == OK);
}  
void GEOMImpl_IGroupOperations::RemoveObject ( Handle(GEOM_Object theGroup,
int  theSubShapeID 
)

RemoveObject.

Definition at line 175 of file GEOMImpl_IGroupOperations.cxx.

{
  SetErrorCode(KO);
  if(theGroup.IsNull()) return;

  Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
  if(aFunction.IsNull()) return;

  GEOM_ISubShape aSSI(aFunction);
  Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
  if(aSeq.IsNull()) return;

  if(aSeq->Length() == 1 && aSeq->Value(1) == -1) {
    SetErrorCode(NOT_EXISTS);
    return;
  }

  Handle(TColStd_HArray1OfInteger) aNewSeq;
  Standard_Integer aLength = aSeq->Length();
  if(aLength == 1) {
    if(aSeq->Value(1) != theSubShapeID) {
      SetErrorCode(NOT_EXISTS);
      return;
    }
    aNewSeq = new TColStd_HArray1OfInteger(1,1);
    aNewSeq->SetValue(1, -1);
  }
  else {
    aNewSeq = new TColStd_HArray1OfInteger(1, aLength-1);
    Standard_Boolean isFound = Standard_False;
    for (Standard_Integer i = 1, k = 1; i <= aLength; i++) {
      if (aSeq->Value(i) == theSubShapeID) {
        isFound = Standard_True;
      } else {
        if (k < aLength) { // this check is to avoid sequence <aNewSeq> overflow
          aNewSeq->SetValue(k, aSeq->Value(i));
          k++;
        }
      }
    }

    if (!isFound) {
      SetErrorCode(NOT_EXISTS);
      return;
    }
  }

  aSSI.SetIndices(aNewSeq);

  // As we do not recompute here our group, lets mark it as Modified
  TDF_Label aLabel = aSSI.GetMainShape()->GetOwnerEntry();
  if (aLabel.IsRoot()) return;
  Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
  if (aMainObj.IsNull()) return;
  Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape
  theGroup->SetTic(aTic - 1);

  //Make a Python command
  GEOM::TPythonDump(aFunction, /*append=*/true)
    << "geompy.RemoveObject(" << theGroup << ", " << theSubShapeID << ")";

  SetErrorCode(OK);
  return;
}

Here is the call graph for this function:

Standard_EXPORT void GEOM_IOperations::SetErrorCode ( const TCollection_AsciiString &  theErrorCode) [inline, inherited]

Definition at line 61 of file GEOM_IOperations.hxx.

                                                                                 {
    _errorCode = theErrorCode;    
  } 

Here is the caller graph for this function:

Standard_EXPORT void GEOM_IOperations::SetNotDone ( ) [inline, inherited]

Definition at line 58 of file GEOM_IOperations.hxx.

{ _errorCode = KO; }
void GEOM_IOperations::StartOperation ( ) [inherited]

StartOperation.

Definition at line 65 of file GEOM_IOperations.cxx.

{
  Handle(TDocStd_Document) aDoc = _engine->GetDocument(_docID);
  if(aDoc->GetUndoLimit() > 0) 
    aDoc->NewCommand();
}

Here is the call graph for this function:

void GEOMImpl_IGroupOperations::UnionIDs ( Handle(GEOM_Object theGroup,
const Handle(TColStd_HSequenceOfInteger)&  theSubShapes 
)

UnionIDs.

Definition at line 535 of file GEOMImpl_IGroupOperations.cxx.

{
  SetErrorCode(KO);
  if (theGroup.IsNull()) return;

  Standard_Integer aLen = theSubShapes->Length();
  if (aLen < 1) {
    //SetErrorCode("The list is empty");
    SetErrorCode(OK);
    return;
  }

  Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
  if (aFunction.IsNull()) return;

  GEOM_ISubShape aSSI (aFunction);

  // New contents of the group
  TColStd_ListOfInteger aNewIDs;
  TColStd_MapOfInteger mapIDs;

  // Add current IDs to the list
  Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
  if (aSeq.IsNull()) return;
  Standard_Integer val_j, aLength = aSeq->Length();

  for (Standard_Integer j = 1; j <= aLength; j++) {
    val_j = aSeq->Value(j);
    if (val_j > 0 && mapIDs.Add(val_j)) {
      aNewIDs.Append(val_j);
    }
  }

  // Get Main Shape
  Handle(GEOM_Function) aMainShapeFunc = aSSI.GetMainShape();
  if (aMainShapeFunc.IsNull()) return;
  TDF_Label aLabel = aMainShapeFunc->GetOwnerEntry();
  if (aLabel.IsRoot()) return;
  Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
  if (aMainObj.IsNull()) return;
  TopoDS_Shape aMainShape = aMainObj->GetValue();
  if (aMainShape.IsNull()) return;

  TopTools_IndexedMapOfShape mapIndices;
  TopExp::MapShapes(aMainShape, mapIndices);

  // Get group type
  TopAbs_ShapeEnum aType = GetType(theGroup);

  // Get IDs of sub-shapes to add
  Standard_Integer i, new_id;
  for (i = 1; i <= aLen; i++) {
    new_id = theSubShapes->Value(i);

    if (0 < new_id && new_id <= mapIndices.Extent()) {
      //if (mapIDs.Add(new_id)) { IPAL21297. Why we ignore invalid ids silently?
      if (mapIDs.Add(new_id) && mapIndices(new_id).ShapeType()==aType ) {
        aNewIDs.Append(new_id);
      }
    }
  }

  if (aNewIDs.Extent() > 0) {
    Standard_Integer k = 1;
    TColStd_ListIteratorOfListOfInteger aNewIDsIter (aNewIDs);
    Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aNewIDs.Extent());
    for (; aNewIDsIter.More(); aNewIDsIter.Next(), k++) {
      aNewSeq->SetValue(k, aNewIDsIter.Value());
    }

    aSSI.SetIndices(aNewSeq);

    // As we do not recompute here our group, lets mark it as Modified
    Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape
    theGroup->SetTic(aTic - 1);
  }

  //Make a Python command
  GEOM::TPythonDump pd (aFunction, /*append=*/true);
  pd << "geompy.UnionIDs(" << theGroup << ", [";
  for (i = 1; i < aLen; i++)
    pd << theSubShapes->Value(i) << ", ";
  pd << theSubShapes->Value(aLen) << "])";

  SetErrorCode(OK);
}

Here is the call graph for this function:

void GEOMImpl_IGroupOperations::UnionList ( Handle(GEOM_Object theGroup,
const Handle(TColStd_HSequenceOfTransient)&  theSubShapes 
)

UnionList.

Definition at line 245 of file GEOMImpl_IGroupOperations.cxx.

{
  SetErrorCode(KO);
  if (theGroup.IsNull()) return;

  Standard_Integer aLen = theSubShapes->Length();
  if (aLen < 1) {
    //SetErrorCode("The list is empty");
    SetErrorCode(OK);
    return;
  }

  Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
  if (aFunction.IsNull()) return;

  GEOM_ISubShape aSSI (aFunction);

  // New contents of the group
  TColStd_ListOfInteger aNewIDs;
  TColStd_MapOfInteger mapIDs;

  // Add current IDs to the list
  Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
  if (aSeq.IsNull()) return;
  Standard_Integer val_j, aLength = aSeq->Length();

  for (Standard_Integer j = 1; j <= aLength; j++) {
    val_j = aSeq->Value(j);
    if (val_j > 0 && mapIDs.Add(val_j)) {
      aNewIDs.Append(val_j);
    }
  }

  // Get Main Shape
  Handle(GEOM_Function) aMainShapeFunc = aSSI.GetMainShape();
  if (aMainShapeFunc.IsNull()) return;
  TDF_Label aLabel = aMainShapeFunc->GetOwnerEntry();
  if (aLabel.IsRoot()) return;
  Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
  if (aMainObj.IsNull()) return;
  TopoDS_Shape aMainShape = aMainObj->GetValue();
  if (aMainShape.IsNull()) return;

  TopTools_IndexedMapOfShape mapIndices;
  TopExp::MapShapes(aMainShape, mapIndices);

  // Get group type
  TopAbs_ShapeEnum aType = GetType(theGroup);

  // Get IDs of sub-shapes to add
  Standard_Integer i, new_id;
  for (i = 1; i <= aLen; i++) {
    Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theSubShapes->Value(i));

    TopoDS_Shape aShape_i = anObj_i->GetValue();
    if ( aShape_i.IsNull() ) continue;
    TopAbs_ShapeEnum aType_i = aShape_i.ShapeType();

    // 1. If aShape_i is sub-shape of aMainShape - add it
    if (anObj_i->IsMainShape()) {
      if (aType_i != aType && aType != TopAbs_SHAPE && aType != TopAbs_COMPOUND) {
        SetErrorCode("Operation aborted: one of given objects has a wrong type");
        return;
      }
      if (!mapIndices.Contains(aShape_i)) {
        SetErrorCode("Operation aborted: not a sub-shape given");
        return;
      }
      new_id = mapIndices.FindIndex(aShape_i);
      if (mapIDs.Add(new_id)) {
        aNewIDs.Append(new_id);
      }
    }
    // 2. If type of group is not defined - add all sub-shapes of aShape_i
    else if (aType == TopAbs_SHAPE || aType == TopAbs_COMPOUND) {
      TopTools_IndexedMapOfShape mapIndices_i;
      TopExp::MapShapes(aShape_i, mapIndices_i);
      Standard_Integer ii = 1, nbSubSh = mapIndices_i.Extent();
      Standard_Boolean someGood = Standard_False;
      for (; ii <= nbSubSh; ii++) {
        TopoDS_Shape aSubShape_i = mapIndices_i.FindKey(ii);
        if (mapIndices.Contains(aSubShape_i)) {
          someGood = Standard_True;
          new_id = mapIndices.FindIndex(aSubShape_i);
          if (mapIDs.Add(new_id)) {
            aNewIDs.Append(new_id);
          }
        }
      }
      if (!someGood) {
        SetErrorCode("Operation aborted: not a sub-shape given");
        return;
      }
    }
    // 3. If type of group is defined - add all sub-shapes of aShape_i of that type
    else {
      TopExp_Explorer aSubShapes_i (aShape_i, aType);
      for (; aSubShapes_i.More(); aSubShapes_i.Next()) {
        TopoDS_Shape aSubShape_i = aSubShapes_i.Current();
        if (!mapIndices.Contains(aSubShape_i)) {
          SetErrorCode("Operation aborted: not a sub-shape given");
          return;
        }
        new_id = mapIndices.FindIndex(aSubShape_i);
        if (mapIDs.Add(new_id)) {
          aNewIDs.Append(new_id);
        }
      }
    }
  }

  if (aNewIDs.Extent() > 0) {
    Standard_Integer k = 1;
    TColStd_ListIteratorOfListOfInteger aNewIDsIter (aNewIDs);
    Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aNewIDs.Extent());
    for (; aNewIDsIter.More(); aNewIDsIter.Next(), k++) {
      aNewSeq->SetValue(k, aNewIDsIter.Value());
    }

    aSSI.SetIndices(aNewSeq);

    // As we do not recompute here our group, lets mark it as Modified
    Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape
    theGroup->SetTic(aTic - 1);
  }

  //Make a Python command
  Handle(GEOM_Object) aLatest = GEOM::GetCreatedLast(theSubShapes);
  aLatest = GEOM::GetCreatedLast(aLatest, theGroup);
  Handle(GEOM_Function) aLastFunc = aLatest->GetLastFunction();

  GEOM::TPythonDump pd (aLastFunc, /*append=*/true);
  pd << "geompy.UnionList(" << theGroup << ", [";

  for (i = 1; i <= aLen; i++) {
    Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theSubShapes->Value(i));
    pd << anObj_i << (( i < aLen ) ? ", " : "])");
  }

  SetErrorCode(OK);
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 40 of file GEOMImpl_IGroupOperations.hxx.


The documentation for this class was generated from the following files: