+ if (aFunction.IsNull()) return NULL;
+
+ //Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
+
+ GEOMImpl_IOffset aTI (aFunction);
+ aTI.SetShape(anOriginal);
+ aTI.SetValue(theOffset);
+ aTI.SetParam(theInside);
+
+ if (theFacesIDs.IsNull() == Standard_False) {
+ aTI.SetFaceIDs(theFacesIDs);
+ }
+
+ //Compute the offset
+ try {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Offset driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
+ return NULL;
+ }
+
+ //Make a Python command
+ GEOM::TPythonDump pd (aFunction);
+ Handle(GEOM_Object) aResult;
+
+ if (isCopy) {
+ pd << aCopy << " = geompy.MakeThickSolid("
+ << theObject << ", " << theOffset;
+ aResult = aCopy;
+ } else {
+ pd << "geompy.Thicken(" << theObject << ", " << theOffset;
+ aResult = theObject;
+ }
+
+ pd << ", [";
+ if (theFacesIDs.IsNull() == Standard_False) {
+ // Dump faces IDs.
+ Standard_Integer i;
+
+ for (i = theFacesIDs->Lower(); i < theFacesIDs->Upper(); ++i) {
+ pd << theFacesIDs->Value(i) << ", ";
+ }
+ // Dump the last value.
+ pd << theFacesIDs->Value(i);
+ }
+ pd << "]";
+
+ if (theInside)
+ pd << ", " << theInside;
+
+ pd << ")";
+ SetErrorCode(OK);
+
+ return aResult;
+}
+
+//=============================================================================
+/*!
+ * RestorePath
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::RestorePath (Handle(GEOM_Object) theShape,
+ Handle(GEOM_Object) theBase1,
+ Handle(GEOM_Object) theBase2)
+{
+ SetErrorCode(KO);
+
+ if (theShape.IsNull() || theBase1.IsNull() || theBase2.IsNull()) return NULL;
+
+ // Add a new Path object
+ Handle(GEOM_Object) aPath = GetEngine()->AddObject(GEOM_PIPE_PATH);
+
+ // Add a new Path function
+ Handle(GEOM_Function) aFunction =
+ aPath->AddFunction(GEOMImpl_PipePathDriver::GetID(), PIPE_PATH_TWO_BASES);
+ if (aFunction.IsNull()) return NULL;
+
+ // Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_PipePathDriver::GetID()) return NULL;
+
+ GEOMImpl_IPipePath aCI (aFunction);
+
+ Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
+ Handle(GEOM_Function) aRefBase1 = theBase1->GetLastFunction();
+ Handle(GEOM_Function) aRefBase2 = theBase2->GetLastFunction();
+
+ if (aRefShape.IsNull() || aRefBase1.IsNull() || aRefBase2.IsNull()) return NULL;
+
+ aCI.SetShape(aRefShape);
+ aCI.SetBase1(aRefBase1);
+ aCI.SetBase2(aRefBase2);
+
+ // Compute the Path value
+ try {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("PipePath driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ SetErrorCode("RestorePath: inappropriate arguments given");
+ return NULL;
+ }
+
+ // Make a Python command
+ GEOM::TPythonDump(aFunction) << aPath << " = geompy.RestorePath("
+ << theShape << ", " << theBase1 << ", " << theBase2 << ")";
+
+ SetErrorCode(OK);
+ return aPath;
+}
+
+//=============================================================================
+/*!
+ * RestorePath
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::RestorePath
+ (Handle(GEOM_Object) theShape,
+ const Handle(TColStd_HSequenceOfTransient)& theBase1,
+ const Handle(TColStd_HSequenceOfTransient)& theBase2)
+{
+ SetErrorCode(KO);
+
+ if (theShape.IsNull() || theBase1.IsNull() || theBase2.IsNull()) return NULL;
+
+ Standard_Integer nbBases1 = theBase1->Length();
+ Standard_Integer nbBases2 = theBase2->Length();
+
+ if (!nbBases1 || !nbBases2)
+ return NULL;
+
+ // Add a new Path object
+ Handle(GEOM_Object) aPath = GetEngine()->AddObject(GEOM_PIPE_PATH);
+
+ // Add a new Path function
+ Handle(GEOM_Function) aFunction =
+ aPath->AddFunction(GEOMImpl_PipePathDriver::GetID(), PIPE_PATH_TWO_SEQS);
+ if (aFunction.IsNull()) return NULL;
+
+ // Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_PipePathDriver::GetID()) return NULL;
+
+ GEOMImpl_IPipePath aCI (aFunction);
+
+ Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
+ if (aRefShape.IsNull()) return NULL;
+
+ Handle(TColStd_HSequenceOfTransient) aSeqBases1 = new TColStd_HSequenceOfTransient;
+ Handle(TColStd_HSequenceOfTransient) aSeqBases2 = new TColStd_HSequenceOfTransient;
+
+ Standard_Integer i;
+ for (i = 1; i <= nbBases1; i++) {
+ Handle(Standard_Transient) anItem = theBase1->Value(i);
+ if (!anItem.IsNull()) {
+ Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
+ if (!aBase.IsNull()) {
+ Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
+ if (!aRefBase.IsNull())
+ aSeqBases1->Append(aRefBase);
+ }
+ }
+ }
+ for (i = 1; i <= nbBases2; i++) {
+ Handle(Standard_Transient) anItem = theBase2->Value(i);
+ if (!anItem.IsNull()) {
+ Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
+ if (!aBase.IsNull()) {
+ Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
+ if (!aRefBase.IsNull())
+ aSeqBases2->Append(aRefBase);
+ }
+ }
+ }
+ if (!aSeqBases1->Length() || !aSeqBases2->Length()) return NULL;
+
+ aCI.SetShape(aRefShape);
+ aCI.SetBaseSeq1(aSeqBases1);
+ aCI.SetBaseSeq2(aSeqBases2);
+
+ // Compute the Path value
+ try {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("PipePath driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ SetErrorCode("RestorePath: inappropriate arguments given");
+ return NULL;
+ }
+
+ // Make a Python command
+ GEOM::TPythonDump pyDump (aFunction);
+ pyDump << aPath << " = geompy.RestorePathEdges(" << theShape << ", [";
+ for (i = 1; i <= nbBases1; i++) {
+ Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theBase1->Value(i));
+ if (!anObj.IsNull()) {
+ pyDump << anObj;
+ if (i < nbBases1)
+ pyDump << ", ";
+ }
+ }
+ pyDump<< "], [";
+ for (i = 1; i <= nbBases2; i++) {
+ Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theBase2->Value(i));
+ if (!anObj.IsNull()) {
+ pyDump << anObj;
+ if (i < nbBases2)
+ pyDump << ", ";
+ }
+ }
+ pyDump << "])";
+
+ SetErrorCode(OK);
+ return aPath;
+}
+
+//=============================================================================
+/*!
+ * 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]);
+ }
+ }