+
+//=============================================================================
+/*!
+ * createGroup
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::createGroup
+ (const Handle(GEOM_Object) &theBaseObject,
+ const Handle(TColStd_HArray1OfInteger) &theGroupIDs,
+ const TCollection_AsciiString &theName,
+ const TopTools_IndexedMapOfShape &theIndices)
+{
+ if (theBaseObject.IsNull() || theGroupIDs.IsNull()) {
+ return NULL;
+ }
+
+ // Get the Shape type.
+ const Standard_Integer anID = theGroupIDs->Value(theGroupIDs->Lower());
+ const Standard_Integer aNbShapes = theIndices.Extent();
+
+ if (anID < 1 || anID > aNbShapes) {
+ return NULL;
+ }
+
+ const TopoDS_Shape aSubShape = theIndices.FindKey(anID);
+
+ if (aSubShape.IsNull()) {
+ return NULL;
+ }
+
+ // Create a group.
+ const TopAbs_ShapeEnum aGroupType = aSubShape.ShapeType();
+ Handle(GEOM_Object) aGroup =
+ myGroupOperations->CreateGroup(theBaseObject, aGroupType);
+
+ if (aGroup.IsNull() == Standard_False) {
+ aGroup->GetLastFunction()->SetDescription("");
+ aGroup->SetName(theName.ToCString());
+
+ Handle(TColStd_HSequenceOfInteger) aSeqIDs = new TColStd_HSequenceOfInteger;
+ Standard_Integer i;
+
+ for (i = theGroupIDs->Lower(); i <= theGroupIDs->Upper(); ++i) {
+ // Get and check the index.
+ const Standard_Integer anIndex = theGroupIDs->Value(i);
+
+ if (anIndex < 1 || anIndex > aNbShapes) {
+ return NULL;
+ }
+
+ // Get and check the sub-shape.
+ const TopoDS_Shape aSubShape = theIndices.FindKey(anIndex);
+
+ if (aSubShape.IsNull()) {
+ return NULL;
+ }
+
+ // Check the shape type.
+ if (aSubShape.ShapeType() != aGroupType) {
+ return NULL;
+ }
+
+ aSeqIDs->Append(anIndex);
+ }
+
+ myGroupOperations->UnionIDs(aGroup, aSeqIDs);
+ aGroup->GetLastFunction()->SetDescription("");
+ }
+
+ return aGroup;
+}
+
+//=============================================================================
+/*!
+ * createGroups
+ */
+//=============================================================================
+void GEOMImpl_I3DPrimOperations::createGroups
+ (const Handle(GEOM_Object) &theBaseObject,
+ GEOMImpl_IPipe *thePipe,
+ Handle(TColStd_HSequenceOfTransient) &theSequence)
+{
+ if (theBaseObject.IsNull() || thePipe == NULL || theSequence.IsNull()) {
+ return;
+ }
+
+ TopoDS_Shape aShape = theBaseObject->GetValue();
+
+ if (aShape.IsNull()) {
+ return;
+ }
+
+ TopTools_IndexedMapOfShape anIndices;
+ Handle(TColStd_HArray1OfInteger) aGroupIDs;
+ TopoDS_Shape aShapeType;
+ const Standard_Integer aNbGroups = 5;
+ Handle(GEOM_Object) aGrps[aNbGroups];
+ Standard_Integer i;
+
+ TopExp::MapShapes(aShape, anIndices);
+
+ // Create groups.
+ aGroupIDs = thePipe->GetGroupDown();
+ aGrps[0] = createGroup(theBaseObject, aGroupIDs, "GROUP_DOWN", anIndices);
+ aGroupIDs = thePipe->GetGroupUp();
+ aGrps[1] = createGroup(theBaseObject, aGroupIDs, "GROUP_UP", anIndices);
+ aGroupIDs = thePipe->GetGroupSide1();
+ aGrps[2] = createGroup(theBaseObject, aGroupIDs, "GROUP_SIDE1", anIndices);
+ aGroupIDs = thePipe->GetGroupSide2();
+ aGrps[3] = createGroup(theBaseObject, aGroupIDs, "GROUP_SIDE2", anIndices);
+ aGroupIDs = thePipe->GetGroupOther();
+ aGrps[4] = createGroup(theBaseObject, aGroupIDs, "GROUP_OTHER", anIndices);
+
+ for (i = 0; i < aNbGroups; ++i) {
+ if (aGrps[i].IsNull() == Standard_False) {
+ theSequence->Append(aGrps[i]);
+ }
+ }
+}