+
+ if (theMainShape.IsNull()) return NULL;
+ TopoDS_Shape aShape = theMainShape->GetValue();
+ if (aShape.IsNull()) return NULL;
+
+ Handle(GEOM_Function) aMainShape = theMainShape->GetLastFunction();
+
+ TopTools_IndexedMapOfShape anIndices;
+ TopExp::MapShapes(aShape, anIndices);
+
+ Handle(TColStd_HArray1OfInteger) anArray;
+ Handle(GEOM_Object) anObj;
+
+ TCollection_AsciiString anAsciiList, anEntry;
+ Standard_Integer i, low = theIndices->Lower(), up = theIndices->Upper();
+ for (i = low; i <= up; i++) {
+ int id = theIndices->Value(i);
+ if (1 <= id && id <= anIndices.Extent()) {
+ TopoDS_Shape aValue = anIndices.FindKey(id);
+ anArray = new TColStd_HArray1OfInteger(1,1);
+ anArray->SetValue(1, id);
+
+ anObj = GetEngine()->AddObject(GetDocID(), GEOM_SUBSHAPE);
+ if (!anObj.IsNull()) {
+ Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
+ if (aFunction.IsNull()) return aSeq;
+
+ GEOM_ISubShape aSSI (aFunction);
+ aSSI.SetMainShape(aMainShape);
+ aSSI.SetIndices(anArray);
+
+ // Set function value directly, as we know it.
+ // Usage of Solver here would lead to significant loss of time,
+ // because GEOM_SubShapeDriver will build TopTools_IndexedMapOfShape
+ // on the main shape for each being calculated sub-shape separately.
+ aFunction->SetValue(aValue);
+
+ // Put this sub-shape in the list of sub-shapes of theMainShape
+ aMainShape->AddSubShapeReference(aFunction);
+
+ aSeq->Append(anObj);
+
+ // for python command
+ TDF_Tool::Entry(anObj->GetEntry(), anEntry);
+ anAsciiList += anEntry;
+ anAsciiList += ",";
+ }
+ }
+ }
+
+ //Make a Python command
+ anAsciiList.Trunc(anAsciiList.Length() - 1);
+
+ GEOM::TPythonDump pd (aMainShape, /*append=*/true);
+ pd << "[" << anAsciiList.ToCString() << "] = geompy.SubShapes("
+ << theMainShape << ", [" ;
+ for (i = low; i <= up - 1; i++) {
+ pd << theIndices->Value(i) << ", ";
+ }
+ pd << theIndices->Value(up) << "])";
+
+ SetErrorCode(OK);
+
+ return aSeq;
+}
+
+//=============================================================================
+/*!
+ * GetSubShapeIndex
+ */
+//=============================================================================
+Standard_Integer GEOMImpl_IShapesOperations::GetSubShapeIndex (Handle(GEOM_Object) theMainShape,
+ Handle(GEOM_Object) theSubShape)
+{
+ SetErrorCode(KO);
+
+ TopoDS_Shape aMainShape = theMainShape->GetValue();
+ TopoDS_Shape aSubShape = theSubShape->GetValue();
+
+ if (aMainShape.IsNull() || aSubShape.IsNull()) return -1;
+
+ TopTools_IndexedMapOfShape anIndices;
+ TopExp::MapShapes(aMainShape, anIndices);
+ if (anIndices.Contains(aSubShape)) {
+ SetErrorCode(OK);
+ return anIndices.FindIndex(aSubShape);
+ }
+
+ return -1;
+}
+
+//=============================================================================
+/*!
+ * GetTopologyIndex
+ */
+//=============================================================================
+Standard_Integer GEOMImpl_IShapesOperations::GetTopologyIndex (Handle(GEOM_Object) theMainShape,
+ Handle(GEOM_Object) theSubShape)
+{
+ SetErrorCode(OK);
+
+ TopoDS_Shape aMainShape = theMainShape->GetValue();
+ TopoDS_Shape aSubShape = theSubShape->GetValue();
+
+ if (aMainShape.IsNull() || aSubShape.IsNull()) {
+ SetErrorCode("Null argument shape given");
+ return -1;
+ }
+
+ int index = 1;
+ if (aSubShape.ShapeType() == TopAbs_COMPOUND) {
+ TopoDS_Iterator it;
+ TopTools_ListOfShape CL;
+ CL.Append(aMainShape);
+ TopTools_ListIteratorOfListOfShape itC;
+ for (itC.Initialize(CL); itC.More(); itC.Next()) {
+ for (it.Initialize(itC.Value()); it.More(); it.Next()) {
+ if (it.Value().ShapeType() == TopAbs_COMPOUND) {
+ if (it.Value().IsSame(aSubShape))
+ return index;
+ else
+ index++;
+ CL.Append(it.Value());
+ }
+ }
+ }
+ } else {
+ TopExp_Explorer anExp (aMainShape, aSubShape.ShapeType());
+ TopTools_MapOfShape M;
+ for (; anExp.More(); anExp.Next()) {
+ if (M.Add(anExp.Current())) {
+ if (anExp.Current().IsSame(aSubShape))
+ return index;
+ index++;
+ }
+ }
+ }
+
+ SetErrorCode("The sub-shape does not belong to the main shape");
+ return -1;
+}
+
+//=============================================================================
+/*!
+ * GetShapeTypeString
+ */
+//=============================================================================
+TCollection_AsciiString GEOMImpl_IShapesOperations::GetShapeTypeString (Handle(GEOM_Object) theShape)
+{
+ SetErrorCode(KO);
+
+ TCollection_AsciiString aTypeName ("Null Shape");
+
+ TopoDS_Shape aShape = theShape->GetValue();
+ if (aShape.IsNull())
+ return aTypeName;
+
+ switch (aShape.ShapeType() )
+ {
+ case TopAbs_COMPOUND:
+ aTypeName = "Compound";
+ break;
+ case TopAbs_COMPSOLID:
+ aTypeName = "Compound Solid";
+ break;
+ case TopAbs_SOLID:
+ aTypeName = "Solid";
+ break;
+ case TopAbs_SHELL:
+ aTypeName = "Shell";
+ break;
+ case TopAbs_FACE:
+ {
+ BRepAdaptor_Surface surf (TopoDS::Face(aShape));
+ if (surf.GetType() == GeomAbs_Plane)
+ aTypeName = "Plane";
+ else if (surf.GetType() == GeomAbs_Cylinder)
+ aTypeName = "Cylindrical Face";
+ else if (surf.GetType() == GeomAbs_Sphere)
+ aTypeName = "Spherical Face";
+ else if (surf.GetType() == GeomAbs_Torus)
+ aTypeName = "Toroidal Face";
+ else if (surf.GetType() == GeomAbs_Cone)
+ aTypeName = "Conical Face";
+ else
+ aTypeName = "GEOM::FACE";
+ }
+ break;
+ case TopAbs_WIRE:
+ aTypeName = "Wire";
+ break;
+ case TopAbs_EDGE:
+ {
+ BRepAdaptor_Curve curv (TopoDS::Edge(aShape));
+ if (curv.GetType() == GeomAbs_Line) {
+ if ((Abs(curv.FirstParameter()) >= 1E6) ||
+ (Abs(curv.LastParameter()) >= 1E6))
+ aTypeName = "Line";
+ else
+ aTypeName = "Edge";
+ } else if (curv.GetType() == GeomAbs_Circle) {
+ if (curv.IsClosed())
+ aTypeName = "Circle";
+ else
+ aTypeName = "Arc";
+ } else {
+ aTypeName = "Edge";
+ }
+ }
+ break;
+ case TopAbs_VERTEX:
+ aTypeName = "Vertex";
+ break;
+ case TopAbs_SHAPE:
+ aTypeName = "Shape";
+ break;
+ default:
+ aTypeName = "Shape of unknown type";
+ }
+
+ return aTypeName;
+}
+
+//=============================================================================
+/*!
+ * NumberOfSubShapes
+ */
+//=============================================================================
+Standard_Integer GEOMImpl_IShapesOperations::NumberOfSubShapes
+ (Handle(GEOM_Object) theShape,
+ const Standard_Integer theShapeType)
+{
+ SetErrorCode(KO);
+ Standard_Integer nbShapes = 0;
+
+ if (theShape.IsNull()) return -1;
+ TopoDS_Shape aShape = theShape->GetValue();
+ if (aShape.IsNull()) return -1;
+
+ /*
+ TopTools_MapOfShape mapShape;
+
+ if (aShape.ShapeType() == TopAbs_COMPOUND &&
+ (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
+ TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPSOLID ||
+ TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND)) {
+ TopoDS_Iterator It (aShape, Standard_True, Standard_True);
+ for (; It.More(); It.Next()) {
+ if (mapShape.Add(It.Value())) {
+ if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
+ TopAbs_ShapeEnum(theShapeType) == It.Value().ShapeType()) {
+ nbShapes++;
+ }
+ }
+ }
+ } else {
+ TopExp_Explorer exp (aShape, TopAbs_ShapeEnum(theShapeType));
+ for (; exp.More(); exp.Next())
+ if (mapShape.Add(exp.Current()))
+ nbShapes++;
+ }
+ */
+
+ try {
+#if OCC_VERSION_LARGE > 0x06010000
+ OCC_CATCH_SIGNALS;
+#endif
+ int iType, nbTypes [TopAbs_SHAPE];
+ for (iType = 0; iType < TopAbs_SHAPE; ++iType)
+ nbTypes[iType] = 0;
+ nbTypes[aShape.ShapeType()]++;
+
+ TopTools_MapOfShape aMapOfShape;
+ aMapOfShape.Add(aShape);
+ TopTools_ListOfShape aListOfShape;
+ aListOfShape.Append(aShape);
+
+ TopTools_ListIteratorOfListOfShape itL (aListOfShape);
+ for (; itL.More(); itL.Next()) {
+ TopoDS_Iterator it (itL.Value());
+ for (; it.More(); it.Next()) {
+ TopoDS_Shape s = it.Value();
+ if (aMapOfShape.Add(s)) {
+ aListOfShape.Append(s);
+ nbTypes[s.ShapeType()]++;
+ }
+ }
+ }
+
+ if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE)
+ nbShapes = aMapOfShape.Extent();
+ else
+ nbShapes = nbTypes[theShapeType];
+ }
+ catch (Standard_Failure) {
+ Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+ SetErrorCode(aFail->GetMessageString());
+ return -1;
+ }
+
+ SetErrorCode(OK);
+ return nbShapes;
+}
+
+//=============================================================================
+/*!
+ * ReverseShape
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_IShapesOperations::ReverseShape(Handle(GEOM_Object) theShape)
+{
+ SetErrorCode(KO);
+
+ if (theShape.IsNull()) return NULL;
+
+ /*
+ //Add a new reversed object
+ Handle(GEOM_Object) aReversed = GetEngine()->AddObject(GetDocID(), theShape->GetType());
+
+ //Add a new Revese function
+ Handle(GEOM_Function) aFunction;
+ aFunction = aReversed->AddFunction(GEOMImpl_ShapeDriver::GetID(), REVERSE_ORIENTATION);
+ if (aFunction.IsNull()) return NULL;
+
+ //Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
+
+ GEOMImpl_IShapes aSI (aFunction);
+
+ Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
+ if (aRefShape.IsNull()) return NULL;
+
+ aSI.SetBase(aRefShape);
+
+ //Compute the sub-shape value
+ try {
+#if OCC_VERSION_LARGE > 0x06010000
+ OCC_CATCH_SIGNALS;
+#endif
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Shape driver failed to reverse shape");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure) {
+ Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+ SetErrorCode(aFail->GetMessageString());
+ return NULL;
+ }
+
+ //Make a Python command
+ GEOM::TPythonDump(aFunction) << aReversed
+ << " = geompy.ChangeOrientation(" << theShape << ")";
+
+ SetErrorCode(OK);
+ */
+
+ Handle(GEOM_Object) aReversed;
+
+ GEOM_Engine* anEngine = GetEngine();
+ //GEOMImpl_Gen* aGen = dynamic_cast<GEOMImpl_Gen*>(anEngine);
+ GEOMImpl_Gen* aGen = (GEOMImpl_Gen*)anEngine;
+
+ if (aGen) {
+ GEOMImpl_IHealingOperations* anIHealingOperations =
+ aGen->GetIHealingOperations(GetDocID());
+ aReversed = anIHealingOperations->ChangeOrientationCopy(theShape);
+ SetErrorCode(anIHealingOperations->GetErrorCode());
+ }
+
+ return aReversed;
+}
+
+//=============================================================================
+/*!
+ * GetFreeFacesIDs
+ */
+//=============================================================================
+Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetFreeFacesIDs
+ (Handle(GEOM_Object) theShape)
+{
+ SetErrorCode(KO);
+
+ if (theShape.IsNull()) return NULL;
+ TopoDS_Shape aShape = theShape->GetValue();
+ if (aShape.IsNull()) return NULL;
+
+ Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
+
+ TopTools_IndexedDataMapOfShapeListOfShape mapFaceBlocks;
+ GEOMImpl_Block6Explorer::MapShapesAndAncestors
+ (aShape, TopAbs_FACE, TopAbs_SOLID, mapFaceBlocks);
+
+ Standard_Integer ind = 1, nbFaces = mapFaceBlocks.Extent();
+
+ if (nbFaces == 0) {
+ SetErrorCode("The given shape has no faces");
+ return aSeq;
+ }
+
+ TopTools_IndexedMapOfShape anIndices;
+ TopExp::MapShapes(aShape, anIndices);
+
+ Standard_Integer id;
+ for (; ind <= nbFaces; ind++) {
+ if (mapFaceBlocks.FindFromIndex(ind).Extent() != 2) {
+ id = anIndices.FindIndex(mapFaceBlocks.FindKey(ind));
+ aSeq->Append(id);
+ }
+ }
+
+ //The explode doesn't change object so no new function is required.
+ Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
+
+ //Make a Python command
+ GEOM::TPythonDump(aFunction, /*append=*/true)
+ << "listFreeFacesIDs = geompy.GetFreeFacesIDs(" << theShape << ")";
+
+ SetErrorCode(OK);
+ return aSeq;
+}
+
+//=======================================================================
+//function : GetSharedShapes
+//purpose :
+//=======================================================================
+Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
+ (Handle(GEOM_Object) theShape1,
+ Handle(GEOM_Object) theShape2,
+ const Standard_Integer theShapeType)
+{
+ SetErrorCode(KO);
+
+ if (theShape1.IsNull() || theShape2.IsNull()) return NULL;
+
+ TopoDS_Shape aShape1 = theShape1->GetValue();
+ TopoDS_Shape aShape2 = theShape2->GetValue();
+
+ if (aShape1.IsNull() || aShape2.IsNull()) return NULL;
+
+ TopTools_IndexedMapOfShape anIndices;
+ TopExp::MapShapes(aShape1, anIndices);
+ Handle(TColStd_HArray1OfInteger) anArray;
+
+ TopTools_IndexedMapOfShape mapShape1;
+ TopExp::MapShapes(aShape1, TopAbs_ShapeEnum(theShapeType), mapShape1);
+
+ Handle(GEOM_Object) anObj;
+ Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
+ TCollection_AsciiString anAsciiList, anEntry;
+
+ TopTools_MapOfShape mapShape2;
+ TopExp_Explorer exp (aShape2, TopAbs_ShapeEnum(theShapeType));
+ for (; exp.More(); exp.Next()) {
+ TopoDS_Shape aSS = exp.Current();
+ if (mapShape2.Add(aSS) && mapShape1.Contains(aSS)) {
+ anArray = new TColStd_HArray1OfInteger(1,1);
+ anArray->SetValue(1, anIndices.FindIndex(aSS));
+ anObj = GetEngine()->AddSubShape(theShape1, anArray);
+ aSeq->Append(anObj);
+
+ // for python command
+ TDF_Tool::Entry(anObj->GetEntry(), anEntry);
+ anAsciiList += anEntry;
+ anAsciiList += ",";
+ }
+ }
+
+ if (aSeq->IsEmpty()) {
+ SetErrorCode("The given shapes have no shared sub-shapes of the requested type");
+ return aSeq;
+ }
+
+ //Make a Python command
+ anAsciiList.Trunc(anAsciiList.Length() - 1);
+
+ Handle(GEOM_Function) aFunction = anObj->GetLastFunction();
+
+ GEOM::TPythonDump(aFunction) << "[" << anAsciiList.ToCString()
+ << "] = geompy.GetSharedShapes(" << theShape1 << ", "
+ << theShape2 << ", " << TopAbs_ShapeEnum(theShapeType) << ")";
+
+ SetErrorCode(OK);
+ return aSeq;
+}
+
+//=======================================================================
+//function : GetSharedShapes
+//purpose :
+//=======================================================================
+Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
+ (std::list<Handle(GEOM_Object)> theShapes,
+ const Standard_Integer theShapeType)
+{
+ SetErrorCode(KO);
+
+ int aLen = theShapes.size();
+ if (aLen < 1) return NULL;
+
+ int ind = 1;
+ std::list<Handle(GEOM_Object)>::iterator it = theShapes.begin();
+
+ Handle(GEOM_Object) aMainObj = (*it++);
+ Handle(GEOM_Function) aMainShape = aMainObj->GetLastFunction();
+ if (aMainShape.IsNull()) {
+ SetErrorCode("NULL shape for GetSharedShapes");
+ return NULL;
+ }
+
+ TopoDS_Shape aShape1 = aMainShape->GetValue();
+ if (aShape1.IsNull()) return NULL;
+
+ TopTools_IndexedMapOfShape anIndices;
+ TopExp::MapShapes(aShape1, anIndices);
+
+ TopTools_IndexedMapOfShape mapSelected;
+ TopExp::MapShapes(aShape1, TopAbs_ShapeEnum(theShapeType), mapSelected);
+
+ // Find shared shapes
+ BRep_Builder B;
+ TopoDS_Compound aCurrSelection;
+
+ for (; it != theShapes.end(); it++, ind++) {
+ Handle(GEOM_Function) aRefShape = (*it)->GetLastFunction();
+ if (aRefShape.IsNull()) {
+ SetErrorCode("NULL shape for GetSharedShapes");
+ return NULL;
+ }
+
+ TopoDS_Compound aCompound;
+ B.MakeCompound(aCompound);
+
+ TopoDS_Shape aShape2 = aRefShape->GetValue();
+ if (aShape2.IsNull()) return NULL;
+
+ TopTools_MapOfShape mapShape2;
+ TopExp_Explorer exp (aShape2, TopAbs_ShapeEnum(theShapeType));
+ for (; exp.More(); exp.Next()) {
+ TopoDS_Shape aSS = exp.Current();
+ if (mapShape2.Add(aSS) && mapSelected.Contains(aSS)) {
+ B.Add(aCompound, aSS);
+ }
+ }
+
+ mapSelected.Clear();
+ TopExp::MapShapes(aCompound, TopAbs_ShapeEnum(theShapeType), mapSelected);
+ aCurrSelection = aCompound;
+ }
+
+ // Create GEOM_Object for each found shared shape (collected in aCurrSelection)
+ Handle(GEOM_Object) anObj;
+ Handle(TColStd_HArray1OfInteger) anArray;
+ Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
+ TCollection_AsciiString anAsciiList, anEntry;
+
+ TopoDS_Iterator itSel (aCurrSelection, Standard_True, Standard_True);
+ for (; itSel.More(); itSel.Next()) {
+ anArray = new TColStd_HArray1OfInteger(1,1);
+ anArray->SetValue(1, anIndices.FindIndex(itSel.Value()));
+ anObj = GetEngine()->AddSubShape(aMainObj, anArray);
+ aSeq->Append(anObj);
+
+ // for python command
+ TDF_Tool::Entry(anObj->GetEntry(), anEntry);
+ anAsciiList += anEntry;
+ anAsciiList += ",";
+ }
+
+ if (aSeq->IsEmpty()) {
+ SetErrorCode("The given shapes have no shared sub-shapes of the requested type");
+ return aSeq;
+ }
+
+ // Make a Python command
+ anAsciiList.Trunc(anAsciiList.Length() - 1);
+
+ // IPAL22904: TC6.5.0: order of python commands is wrong after dump study
+ Handle(TColStd_HSequenceOfTransient) anObjects = new TColStd_HSequenceOfTransient;
+ for( it = theShapes.begin(); it != theShapes.end(); it++ )
+ {
+ Handle(GEOM_Object) anObj = *it;
+ if( !anObj.IsNull() )
+ anObjects->Append( anObj );
+ }
+
+ // Get the function of the latest published object
+ Handle(GEOM_Function) aFunction = GEOM::GetCreatedLast( anObjects )->GetLastFunction();
+ if( aFunction.IsNull() ) // just in case
+ aFunction = aMainShape;
+
+ GEOM::TPythonDump pd (aFunction, /*append=*/true);
+ pd << "[" << anAsciiList.ToCString()
+ << "] = geompy.GetSharedShapesMulti([";
+
+ it = theShapes.begin();
+ pd << (*it++);
+ while (it != theShapes.end()) {
+ pd << ", " << (*it++);
+ }
+
+ pd << "], " << TopAbs_ShapeEnum(theShapeType) << ")";
+
+ SetErrorCode(OK);
+ return aSeq;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+static GEOM::TPythonDump& operator<< (GEOM::TPythonDump& theDump,
+ const GEOMAlgo_State theState)
+{
+ switch (theState) {
+ case GEOMAlgo_ST_IN:
+ theDump << "geompy.GEOM.ST_IN";
+ break;
+ case GEOMAlgo_ST_OUT:
+ theDump << "geompy.GEOM.ST_OUT";
+ break;
+ case GEOMAlgo_ST_ON:
+ theDump << "geompy.GEOM.ST_ON";
+ break;
+ case GEOMAlgo_ST_ONIN:
+ theDump << "geompy.GEOM.ST_ONIN";
+ break;
+ case GEOMAlgo_ST_ONOUT:
+ theDump << "geompy.GEOM.ST_ONOUT";
+ break;
+ default:
+ theDump << "geompy.GEOM.ST_UNKNOWN";
+ break;
+ }
+ return theDump;
+}
+
+//=======================================================================
+//function : checkTypeShapesOn
+/*!
+ * \brief Checks if theShapeType parameter of GetShapesOnXXX() is OK
+ * \param theShapeType - the shape type to check
+ * \retval bool - result of the check
+ */
+//=======================================================================
+bool GEOMImpl_IShapesOperations::checkTypeShapesOn(const Standard_Integer theShapeType)
+{
+ if (theShapeType != TopAbs_VERTEX &&
+ theShapeType != TopAbs_EDGE &&
+ theShapeType != TopAbs_FACE &&
+ theShapeType != TopAbs_SOLID) {
+ SetErrorCode("Only solids, vertices, edges or faces can be found by this method");
+ return false;
+ }
+ return true;
+}
+
+//=======================================================================
+//function : makePlane
+ /*!
+ * \brief Creates Geom_Plane
+ * \param theAx1 - shape object defining plane parameters
+ * \retval Handle(Geom_Surface) - resulting surface
+ */
+//=======================================================================
+Handle(Geom_Surface) GEOMImpl_IShapesOperations::makePlane(const TopoDS_Shape& anAx1)
+{
+ if (anAx1.ShapeType() != TopAbs_EDGE) return NULL;
+ TopoDS_Edge anEdge = TopoDS::Edge(anAx1);
+ TopoDS_Vertex V1, V2;
+ TopExp::Vertices(anEdge, V1, V2, Standard_True);
+ if (V1.IsNull() || V2.IsNull()) {
+ SetErrorCode("Bad edge given for the plane normal vector");
+ return NULL;
+ }
+ gp_Pnt aLoc = BRep_Tool::Pnt(V1);
+ gp_Vec aVec (aLoc, BRep_Tool::Pnt(V2));
+ if (aVec.Magnitude() < Precision::Confusion()) {
+ SetErrorCode("Vector with null magnitude given");
+ return NULL;
+ }
+ return new Geom_Plane(aLoc, aVec);
+}
+
+//=======================================================================
+//function : makeCylinder
+ /*!
+ * \brief Creates Geom_CylindricalSurface
+ * \param theAx1 - edge defining cylinder axis
+ * \param theRadius - cylinder radius
+ * \retval Handle(Geom_Surface) - resulting surface
+ */
+//=======================================================================
+Handle(Geom_Surface) GEOMImpl_IShapesOperations::makeCylinder(const TopoDS_Shape& anAxis,
+ const Standard_Real theRadius)
+{
+ //Axis of the cylinder
+ if (anAxis.ShapeType() != TopAbs_EDGE) {
+ SetErrorCode("Not an edge given for the axis");
+ return NULL;
+ }
+ TopoDS_Edge anEdge = TopoDS::Edge(anAxis);
+ TopoDS_Vertex V1, V2;
+ TopExp::Vertices(anEdge, V1, V2, Standard_True);
+ if (V1.IsNull() || V2.IsNull()) {
+ SetErrorCode("Bad edge given for the axis");
+ return NULL;
+ }
+ gp_Pnt aLoc = BRep_Tool::Pnt(V1);
+ gp_Vec aVec (aLoc, BRep_Tool::Pnt(V2));
+ if (aVec.Magnitude() < Precision::Confusion()) {
+ SetErrorCode("Vector with null magnitude given");
+ return NULL;
+ }
+
+ gp_Ax3 anAx3 (aLoc, aVec);
+ return new Geom_CylindricalSurface(anAx3, theRadius);
+}
+
+//=======================================================================
+//function : getShapesOnBoxIDs
+ /*!
+ * \brief Find IDs of sub-shapes complying with given status about surface
+ * \param theBox - the box to check state of sub-shapes against
+ * \param theShape - the shape to explore
+ * \param theShapeType - type of sub-shape of theShape
+ * \param theState - required state
+ * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found sub-shapes
+ */
+//=======================================================================
+Handle(TColStd_HSequenceOfInteger)
+ GEOMImpl_IShapesOperations::getShapesOnBoxIDs(const Handle(GEOM_Object)& theBox,
+ const Handle(GEOM_Object)& theShape,
+ const Standard_Integer theShapeType,
+ GEOMAlgo_State theState)
+{
+ Handle(TColStd_HSequenceOfInteger) aSeqOfIDs;
+
+ TopoDS_Shape aBox = theBox->GetValue();
+ TopoDS_Shape aShape = theShape->GetValue();
+
+ // Check presence of triangulation, build if need
+ if (!CheckTriangulation(aShape)) {
+ SetErrorCode("Cannot build triangulation on the shape");
+ return aSeqOfIDs;
+ }
+
+ // Call algo
+ GEOMAlgo_FinderShapeOn2 aFinder;
+ Standard_Real aTol = 0.0001; // default value
+
+ Handle(GEOMAlgo_ClsfBox) aClsfBox = new GEOMAlgo_ClsfBox;
+ aClsfBox->SetBox(aBox);
+
+ aFinder.SetShape(aShape);
+ aFinder.SetTolerance(aTol);
+ aFinder.SetClsf(aClsfBox);
+ aFinder.SetShapeType( (TopAbs_ShapeEnum)theShapeType );
+ aFinder.SetState(theState);
+ aFinder.Perform();
+
+ // Interprete results
+ Standard_Integer iErr = aFinder.ErrorStatus();
+ // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
+ if (iErr) {
+ MESSAGE(" iErr : " << iErr);
+ TCollection_AsciiString aMsg (" iErr : ");
+ aMsg += TCollection_AsciiString(iErr);
+ SetErrorCode(aMsg);
+ return aSeqOfIDs;
+ }
+ Standard_Integer iWrn = aFinder.WarningStatus();
+ // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx
+ if (iWrn) {
+ MESSAGE(" *** iWrn : " << iWrn);
+ }
+
+ const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
+
+ if (listSS.Extent() < 1) {
+ //SetErrorCode("Not a single sub-shape of the requested type found on the given surface");
+ SetErrorCode(NOT_FOUND_ANY); // NPAL18017
+ return aSeqOfIDs;
+ }
+
+ // Fill sequence of object IDs
+ aSeqOfIDs = new TColStd_HSequenceOfInteger;
+
+ TopTools_IndexedMapOfShape anIndices;
+ TopExp::MapShapes(aShape, anIndices);
+
+ TopTools_ListIteratorOfListOfShape itSub (listSS);
+ for (int index = 1; itSub.More(); itSub.Next(), ++index) {
+ int id = anIndices.FindIndex(itSub.Value());
+ aSeqOfIDs->Append(id);
+ }
+
+ return aSeqOfIDs;
+}
+
+//=======================================================================
+//function : GetShapesOnBoxIDs
+/*!
+ * \brief Find sub-shapes complying with given status about surface
+ * \param theBox - the box to check state of sub-shapes against
+ * \param theShape - the shape to explore
+ * \param theShapeType - type of sub-shape of theShape
+ * \param theState - required state
+ * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found sub-shapes
+ */
+//=======================================================================
+Handle(TColStd_HSequenceOfInteger)
+ GEOMImpl_IShapesOperations::GetShapesOnBoxIDs(const Handle(GEOM_Object)& theBox,
+ const Handle(GEOM_Object)& theShape,
+ const Standard_Integer theShapeType,
+ GEOMAlgo_State theState)
+{
+ // Find sub-shapes ids
+ Handle(TColStd_HSequenceOfInteger) aSeqOfIDs =
+ getShapesOnBoxIDs (theBox, theShape, theShapeType, theState);
+ if ( aSeqOfIDs.IsNull() || aSeqOfIDs->Length() == 0 )
+ return NULL;
+
+ // The GetShapesOnBox() doesn't change object so no new function is required.
+ Handle(GEOM_Function) aFunction = GEOM::GetCreatedLast(theShape,theBox)->GetLastFunction();
+
+ // Make a Python command
+ GEOM::TPythonDump(aFunction)
+ << "listShapesOnBoxIDs = geompy.GetShapesOnBoxIDs("
+ << theBox << ", "
+ << theShape << ", "
+ << TopAbs_ShapeEnum(theShapeType) << ", "
+ << theState << ")";
+
+ SetErrorCode(OK);
+ return aSeqOfIDs;
+}
+
+//=======================================================================
+//function : GetShapesOnBox
+/*!
+ * \brief Find sub-shapes complying with given status about surface
+ * \param theBox - the box to check state of sub-shapes against
+ * \param theShape - the shape to explore
+ * \param theShapeType - type of sub-shape of theShape
+ * \param theState - required state
+ * \retval Handle(TColStd_HSequenceOfTransient) - found sub-shapes
+ */
+//=======================================================================
+Handle(TColStd_HSequenceOfTransient)
+ GEOMImpl_IShapesOperations::GetShapesOnBox(const Handle(GEOM_Object)& theBox,
+ const Handle(GEOM_Object)& theShape,
+ const Standard_Integer theShapeType,
+ GEOMAlgo_State theState)
+{
+ // Find sub-shapes ids
+ Handle(TColStd_HSequenceOfInteger) aSeqOfIDs =
+ getShapesOnBoxIDs (theBox, theShape, theShapeType, theState);
+ if ( aSeqOfIDs.IsNull() || aSeqOfIDs->Length() == 0 )
+ return NULL;
+
+ // Find objects by indices
+ TCollection_AsciiString anAsciiList;
+ Handle(TColStd_HSequenceOfTransient) aSeq;
+ aSeq = getObjectsShapesOn( theShape, aSeqOfIDs, anAsciiList );
+ if ( aSeq.IsNull() || aSeq->IsEmpty() )
+ return NULL;
+
+ // Make a Python command
+
+ Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast( aSeq->Value( 1 ));
+ Handle(GEOM_Function) aFunction = anObj->GetLastFunction();
+
+ GEOM::TPythonDump(aFunction)
+ << "[" << anAsciiList.ToCString() << "] = geompy.GetShapesOnBox("
+ << theBox << ", "
+ << theShape << ", "
+ << TopAbs_ShapeEnum(theShapeType) << ", "
+ << theState << ")";
+
+ SetErrorCode(OK);
+ return aSeq;
+}
+
+//=======================================================================
+//function : getShapesOnShapeIDs
+/*!
+ * \brief Find IDs of sub-shapes complying with given status about surface
+ * \param theCheckShape - the shape to check state of sub-shapes against
+ * \param theShape - the shape to explore
+ * \param theShapeType - type of sub-shape of theShape
+ * \param theState - required state
+ * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found sub-shapes
+ */
+//=======================================================================
+Handle(TColStd_HSequenceOfInteger)
+ GEOMImpl_IShapesOperations::getShapesOnShapeIDs
+ (const Handle(GEOM_Object)& theCheckShape,
+ const Handle(GEOM_Object)& theShape,
+ const Standard_Integer theShapeType,
+ GEOMAlgo_State theState)
+{
+ Handle(TColStd_HSequenceOfInteger) aSeqOfIDs;
+
+ TopoDS_Shape aCheckShape = theCheckShape->GetValue();
+ TopoDS_Shape aShape = theShape->GetValue();
+ TopTools_ListOfShape res;
+
+ // Check presence of triangulation, build if need
+ if (!CheckTriangulation(aShape)) {
+ SetErrorCode("Cannot build triangulation on the shape");
+ return aSeqOfIDs;
+ }
+
+ // Call algo
+ GEOMAlgo_FinderShapeOn2 aFinder;
+ Standard_Real aTol = 0.0001; // default value
+
+ Handle(GEOMAlgo_ClsfSolid) aClsfSolid = new GEOMAlgo_ClsfSolid;
+ aClsfSolid->SetShape(aCheckShape);
+
+ aFinder.SetShape(aShape);
+ aFinder.SetTolerance(aTol);
+ aFinder.SetClsf(aClsfSolid);
+ aFinder.SetShapeType( (TopAbs_ShapeEnum)theShapeType );
+ aFinder.SetState(theState);
+ aFinder.Perform();
+
+ // Interprete results
+ Standard_Integer iErr = aFinder.ErrorStatus();
+ // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
+ if (iErr) {
+ if (iErr == 41) {
+ SetErrorCode("theCheckShape must be a solid");
+ }
+ else {
+ MESSAGE(" iErr : " << iErr);
+ TCollection_AsciiString aMsg (" iErr : ");
+ aMsg += TCollection_AsciiString(iErr);
+ SetErrorCode(aMsg);
+ }
+ return aSeqOfIDs;
+ }
+ Standard_Integer iWrn = aFinder.WarningStatus();
+ // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx
+ if (iWrn) {
+ MESSAGE(" *** iWrn : " << iWrn);
+ }
+
+ const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
+
+ if (listSS.Extent() < 1) {
+ //SetErrorCode("Not a single sub-shape of the requested type found on the given surface");
+ SetErrorCode(NOT_FOUND_ANY); // NPAL18017
+ }
+
+ // Fill sequence of object IDs
+ aSeqOfIDs = new TColStd_HSequenceOfInteger;
+
+ TopTools_IndexedMapOfShape anIndices;
+ TopExp::MapShapes(aShape, anIndices);
+
+ TopTools_ListIteratorOfListOfShape itSub (listSS);
+ for (int index = 1; itSub.More(); itSub.Next(), ++index) {
+ int id = anIndices.FindIndex(itSub.Value());
+ aSeqOfIDs->Append(id);
+ }
+
+ return aSeqOfIDs;
+}
+
+//=======================================================================
+//function : GetShapesOnShapeIDs
+/*!
+ * \brief Find sub-shapes complying with given status about surface
+ * \param theCheckShape - the shape to check state of sub-shapes against
+ * \param theShape - the shape to explore
+ * \param theShapeType - type of sub-shape of theShape
+ * \param theState - required state
+ * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found sub-shapes
+ */
+//=======================================================================
+Handle(TColStd_HSequenceOfInteger)
+ GEOMImpl_IShapesOperations::GetShapesOnShapeIDs
+ (const Handle(GEOM_Object)& theCheckShape,
+ const Handle(GEOM_Object)& theShape,
+ const Standard_Integer theShapeType,
+ GEOMAlgo_State theState)
+{
+ Handle(TColStd_HSequenceOfInteger) aSeqOfIDs =
+ getShapesOnShapeIDs (theCheckShape, theShape, theShapeType, theState);
+
+ if ( aSeqOfIDs.IsNull() || aSeqOfIDs->Length() == 0 )
+ return NULL;
+
+ // The GetShapesOnShape() doesn't change object so no new function is required.
+ Handle(GEOM_Function) aFunction =
+ GEOM::GetCreatedLast(theShape,theCheckShape)->GetLastFunction();
+
+ // Make a Python command
+ GEOM::TPythonDump(aFunction)
+ << "listShapesOnBoxIDs = geompy.GetShapesOnShapeIDs("
+ << theCheckShape << ", "
+ << theShape << ", "
+ << TopAbs_ShapeEnum(theShapeType) << ", "
+ << theState << ")";
+
+ SetErrorCode(OK);
+ return aSeqOfIDs;