diff --git a/src/Prs3d/FILES b/src/Prs3d/FILES index f4b414ec97..4ac2bf0632 100755 --- a/src/Prs3d/FILES +++ b/src/Prs3d/FILES @@ -1,4 +1,5 @@ Prs3d_NListIteratorOfListOfSequenceOfPnt.hxx Prs3d_NListOfSequenceOfPnt.hxx Prs3d_Point.hxx -Prs3d_WFShape.hxx \ No newline at end of file +Prs3d_WFShape.hxx +Prs3d_WFShape.cxx diff --git a/src/Prs3d/Prs3d_WFShape.cxx b/src/Prs3d/Prs3d_WFShape.cxx new file mode 100644 index 0000000000..5cafc11abe --- /dev/null +++ b/src/Prs3d/Prs3d_WFShape.cxx @@ -0,0 +1,783 @@ +// Copyright (c) 2013 OPEN CASCADE SAS +// +// The content of this file is subject to the Open CASCADE Technology Public +// License Version 6.5 (the "License"). You may not use the content of this file +// except in compliance with the License. Please obtain a copy of the License +// at http://www.opencascade.org and read it completely before using this file. +// +// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its +// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. +// +// The Original Code and all software distributed under the License is +// distributed on an "AS IS" basis, without warranty of any kind, and the +// Initial Developer hereby disclaims all such warranties, including without +// limitation, any warranties of merchantability, fitness for a particular +// purpose or non-infringement. Please see the License for the specific terms +// and conditions governing the rights and limitations under the License. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + + //! Compare two aspects + inline Standard_Boolean IsSame (const Handle(Graphic3d_AspectLine3d)& theUAspect, + const Handle(Graphic3d_AspectLine3d)& theVAspect) + { + Quantity_Color aCU, aCV; + Aspect_TypeOfLine aTlU, aTlV; + Standard_Real aWU, aWV; + theUAspect->Values (aCU, aTlU, aWU); + theVAspect->Values (aCV, aTlV, aWV); + return aCU == aCV + && aTlU == aTlV + && aWU == aWV; + } + +}; + +// ========================================================================= +// function: AddPolygon +// purpose : +// ========================================================================= +Standard_Boolean Prs3d_WFShape::AddPolygon (const TopoDS_Edge& theEdge, + const Standard_Real theDeflection, + TColgp_SequenceOfPnt& thePoints) +{ + TopLoc_Location aLocation; + Standard_Real aFirst, aLast; + Handle(Geom_Curve) aCurve3d = BRep_Tool::Curve (theEdge, aFirst, aLast); + Handle(Poly_Polygon3D) aPolygon = BRep_Tool::Polygon3D (theEdge, aLocation); + if (!aPolygon.IsNull()) + { + if ((aPolygon->Deflection() <= theDeflection) || aCurve3d.IsNull()) + { + const TColgp_Array1OfPnt& aPoints = aPolygon->Nodes(); + Standard_Integer anIndex = aPoints.Lower(); + if (aLocation.IsIdentity()) + { + for (; anIndex <= aPoints.Upper(); ++anIndex) + { + thePoints.Append (aPoints.Value (anIndex)); + } + } + else + { + for (; anIndex <= aPoints.Upper(); ++anIndex) + { + thePoints.Append (aPoints.Value (anIndex).Transformed (aLocation)); + } + } + return Standard_True; + } + } + + Handle(Poly_Triangulation) aTriangulation; + Handle(Poly_PolygonOnTriangulation) aHIndices; + BRep_Tool::PolygonOnTriangulation (theEdge, aHIndices, aTriangulation, aLocation); + if (!aHIndices.IsNull()) + { + if ((aHIndices->Deflection() <= theDeflection) || aCurve3d.IsNull()) + { + const TColStd_Array1OfInteger& anIndices = aHIndices->Nodes(); + const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); + + Standard_Integer anIndex = anIndices.Lower(); + if (aLocation.IsIdentity()) + { + for (; anIndex <= anIndices.Upper(); ++anIndex) + { + thePoints.Append (aNodes (anIndices (anIndex))); + } + } + else + { + for (; anIndex <= anIndices.Upper(); ++anIndex) + { + thePoints.Append (aNodes (anIndices (anIndex)).Transformed (aLocation)); + } + } + return Standard_True; + } + } + return Standard_False; +} + +// ========================================================================= +// function: Add +// purpose : +// ========================================================================= +void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation, + const TopoDS_Shape& theShape, + const Handle (Prs3d_Drawer)& theDrawer) +{ + if (theShape.IsNull()) + { + return; + } + + Prs3d_ShapeTool aTool (theShape); + TopTools_ListOfShape aLFree, aLUnFree, aLWire; + for (aTool.InitCurve(); aTool.MoreCurve(); aTool.NextCurve()) + { + const TopoDS_Edge& anEdge = aTool.GetCurve(); + switch (aTool.Neighbours()) + { + case 0: aLWire.Append (anEdge); break; + case 1: aLFree.Append (anEdge); break; + default: aLUnFree.Append (anEdge); break; + } + } + + Standard_Real aDeflection = theDrawer->MaximalChordialDeviation(); + if (theDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) + { + // The arrow calculation is based on the global min max + Bnd_Box aBndBox; + BRepBndLib::Add (theShape, aBndBox); + if (!aBndBox.IsVoid()) + { + Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; + aBndBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + aDeflection = Max (aXmax-aXmin, Max (aYmax-aYmin, aZmax-aZmin)) + * theDrawer->DeviationCoefficient(); + } + } + + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation); + + Prs3d_NListOfSequenceOfPnt anUIsoCurves; + Prs3d_NListOfSequenceOfPnt aVIsoCurves; + Prs3d_NListOfSequenceOfPnt aWireCurves; + Prs3d_NListOfSequenceOfPnt aFreeCurves; + Prs3d_NListOfSequenceOfPnt anUnFreeCurves; + TColgp_SequenceOfPnt aShapePoints; + + const Standard_Integer anIsoU = theDrawer->UIsoAspect()->Number(); + const Standard_Integer anIsoV = theDrawer->VIsoAspect()->Number(); + + Standard_Boolean hasIsoU = anIsoU > 0; + Standard_Boolean hasIsoV = anIsoV > 0; + + if (IsSame (theDrawer->UIsoAspect()->Aspect(), + theDrawer->VIsoAspect()->Aspect())) + { + if (hasIsoU || hasIsoV) + { + BRepAdaptor_Surface aSurface; + for (aTool.InitFace(); aTool.MoreFace(); aTool.NextFace()) + { + if (aTool.HasSurface()) + { + if (!aTool.IsPlanarFace() || theDrawer->IsoOnPlane()) + { + aSurface.Initialize (aTool.GetFace()); + Handle(BRepAdaptor_HSurface) aHSurface = new BRepAdaptor_HSurface (aSurface); + try + { + OCC_CATCH_SIGNALS + Prs3d_NListOfSequenceOfPnt aCurUIsoCurves; + myFaceAlgo.Add (thePresentation, aHSurface, + hasIsoU, hasIsoV, + aDeflection, + anIsoU, anIsoV, + theDrawer, + aCurUIsoCurves); + Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; + for (anIt.Init (aCurUIsoCurves); anIt.More(); anIt.Next()) + { + anUIsoCurves.Append (anIt.Value()); + } + } + catch (Standard_Failure) + { + } + } + } + } + } + } + else + { + if (hasIsoU) + { + BRepAdaptor_Surface aSurface; + for (aTool.InitFace(); aTool.MoreFace(); aTool.NextFace()) + { + if (aTool.HasSurface()) + { + if (!aTool.IsPlanarFace() || theDrawer->IsoOnPlane()) + { + aSurface.Initialize (aTool.GetFace()); + Handle(BRepAdaptor_HSurface) aHSurface = new BRepAdaptor_HSurface (aSurface); + try + { + OCC_CATCH_SIGNALS + Prs3d_NListOfSequenceOfPnt aCurUIsoCurves; + myFaceAlgo.Add (thePresentation, aHSurface, + hasIsoU, Standard_False, + aDeflection, + anIsoU, 0, + theDrawer, + aCurUIsoCurves); + } + catch (Standard_Failure) + { + #ifdef DEB + const TopoDS_Face& aFace = aSurface.Face(); + std::cout << "Problem with the face " << (void* ) &(*(aFace).TShape()) << std::endl; + #endif + } + } + } + } + } + if (hasIsoV) + { + BRepAdaptor_Surface aSurface; + for (aTool.InitFace(); aTool.MoreFace(); aTool.NextFace()) + { + if (aTool.HasSurface()) + { + if (!aTool.IsPlanarFace() || theDrawer->IsoOnPlane()) + { + aSurface.Initialize (aTool.GetFace()); + Handle(BRepAdaptor_HSurface) aHSurface = new BRepAdaptor_HSurface (aSurface); + try + { + OCC_CATCH_SIGNALS + Prs3d_NListOfSequenceOfPnt aCurUIsoCurves; + myFaceAlgo.Add (thePresentation, aHSurface, + Standard_False, hasIsoV, + aDeflection, + 0, anIsoV, + theDrawer, + aCurUIsoCurves); + } + catch (Standard_Failure) + { + #ifdef DEB + const TopoDS_Face& aFace = aSurface.Face(); + std::cout << "Problem with the face " << (void* ) &(*(aFace).TShape()) << std::endl; + #endif + } + } + } + } + } + } + + Standard_Integer aNbVertices = 0, aNbBounds = 0; + if (anUIsoCurves.Size() > 0) + { + aNbBounds = anUIsoCurves.Size(); + Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; + for (anIt.Init (anUIsoCurves); anIt.More(); anIt.Next()) + { + aNbVertices += anIt.Value().Length(); + } + Handle(Graphic3d_ArrayOfPolylines) anUIsoArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds); + for (anIt.Init (anUIsoCurves); anIt.More(); anIt.Next()) + { + TColgp_SequenceOfPnt aPoints; + aPoints.Assign (anIt.Value()); + anUIsoArray->AddBound (aPoints.Length()); + for (Standard_Integer anI = 1; anI <= aPoints.Length(); ++anI) + { + anUIsoArray->AddVertex (aPoints.Value (anI)); + } + } + Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); + aGroup->SetPrimitivesAspect (theDrawer->UIsoAspect()->Aspect()); + aGroup->AddPrimitiveArray (anUIsoArray); + } + + if (aVIsoCurves.Size() > 0) + { + aNbBounds = aVIsoCurves.Size(); + Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; + for (anIt.Init (aVIsoCurves); anIt.More(); anIt.Next()) + { + aNbVertices += anIt.Value().Length(); + } + Handle(Graphic3d_ArrayOfPolylines) VIsoArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds); + for (anIt.Init (aVIsoCurves); anIt.More(); anIt.Next()) + { + TColgp_SequenceOfPnt aPoints; + aPoints.Assign (anIt.Value()); + VIsoArray->AddBound (aPoints.Length()); + for (int anI = 1; anI <= aPoints.Length(); anI++) + { + VIsoArray->AddVertex (aPoints.Value (anI)); + } + } + Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); + aGroup->SetPrimitivesAspect (theDrawer->VIsoAspect()->Aspect()); + aGroup->AddPrimitiveArray (VIsoArray); + } + + TopLoc_Location aLocation; + Standard_Integer anI, aJ, aN[3]; + + Standard_Boolean isDispTriangles = Standard_False; + const char* anEnvVar = getenv ("DEBUG_TRIANGLES"); + if (anEnvVar != NULL) + { + isDispTriangles = (atol (anEnvVar) != 0); + } + + TColgp_SequenceOfPnt aSurfPoints; + for (aTool.InitFace(); aTool.MoreFace(); aTool.NextFace()) + { + if (!aTool.HasSurface() || isDispTriangles) + { + Handle(Poly_Triangulation) T = aTool.CurrentTriangulation (aLocation); + if (!T.IsNull()) + { + const TColgp_Array1OfPnt& aNodes = T->Nodes(); + // Build the connect tool + Poly_Connect aPolyConnect (T); + + Standard_Integer aNbTriangles = T->NbTriangles(); + Standard_Integer aT[3]; + + // Count the free edges + Standard_Integer aNbFree = 0; + for (anI = 1; anI <= aNbTriangles; ++anI) + { + aPolyConnect.Triangles (anI, aT[0], aT[1], aT[2]); + for (aJ = 0; aJ < 3; ++aJ) + { + if (aT[aJ] == 0) + { + ++aNbFree; + } + } + } + + // Allocate the arrays + TColStd_Array1OfInteger aFree (1, 2 * aNbFree); + Standard_Integer aNbInternal = (3 * aNbTriangles - aNbFree) / 2; + TColStd_Array1OfInteger anInternal (0, 2 * aNbInternal); + + Standard_Integer aFreeIndex = 1, anIntIndex = 1; + const Poly_Array1OfTriangle& aTriangles = T->Triangles(); + for (anI = 1; anI <= aNbTriangles; ++anI) + { + aPolyConnect.Triangles (anI, aT[0], aT[1], aT[2]); + aTriangles (anI).Get (aN[0], aN[1], aN[2]); + for (aJ = 0; aJ < 3; aJ++) + { + Standard_Integer k = (aJ + 1) % 3; + if (aT[aJ] == 0) + { + aFree (aFreeIndex) = aN[aJ]; + aFree (aFreeIndex + 1) = aN[k]; + aFreeIndex += 2; + } + // internal edge if this triangle has a lower index than the adjacent + else if (anI < aT[aJ]) + { + anInternal (anIntIndex) = aN[aJ]; + anInternal (anIntIndex + 1) = aN[k]; + anIntIndex += 2; + } + } + } + + if (!aTool.HasSurface()) + { + // free edges + Standard_Integer aFreeHalfNb = aFree.Length() / 2; + for (anI = 1; anI <= aFreeHalfNb; ++anI) + { + gp_Pnt aPoint1 = aNodes (aFree (2 * anI - 1)).Transformed (aLocation); + gp_Pnt aPoint2 = aNodes (aFree (2 * anI )).Transformed (aLocation); + aSurfPoints.Append (aPoint1); + aSurfPoints.Append (aPoint2); + } + } + if (isDispTriangles) + { + for (anI = 1; anI <= aNbInternal; ++anI) + { + gp_Pnt aPoint1 = aNodes (anInternal (2 * anI - 1)).Transformed (aLocation); + gp_Pnt aPoint2 = aNodes (anInternal (2 * anI )).Transformed (aLocation); + aSurfPoints.Append (aPoint1); + aSurfPoints.Append (aPoint2); + } + } + } + } + } + if (aSurfPoints.Length() > 0) + { + aNbVertices = aSurfPoints.Length(); + aNbBounds = (Standard_Integer)aNbVertices / 2; + Handle(Graphic3d_ArrayOfPolylines) aSurfArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds); + for (anI = 1; anI <= aNbVertices; anI += 2) + { + aSurfArray->AddBound (2); + aSurfArray->AddVertex (aSurfPoints.Value (anI)); + aSurfArray->AddVertex (aSurfPoints.Value (anI + 1)); + } + Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); + aGroup->SetPrimitivesAspect ((isDispTriangles && aTool.HasSurface()) + ? theDrawer->UIsoAspect()->Aspect() + : theDrawer->FreeBoundaryAspect()->Aspect()); + aGroup->AddPrimitiveArray (aSurfArray); + } + + TopTools_ListIteratorOfListOfShape anIt; + if (theDrawer->WireDraw()) + { + // Wire (without any neighbour) + aGroup->SetPrimitivesAspect (theDrawer->WireAspect()->Aspect()); + for (anIt.Initialize(aLWire); anIt.More(); anIt.Next()) + { + const TopoDS_Edge& anEdge = TopoDS::Edge (anIt.Value()); + try + { + OCC_CATCH_SIGNALS + TColgp_SequenceOfPnt aPoints; + if (!AddPolygon (anEdge, aDeflection, aPoints)) + { + if (BRep_Tool::IsGeometric (anEdge)) + { + BRepAdaptor_Curve aCurve (anEdge); + myCurveAlgo.Add (thePresentation, aCurve, aDeflection, theDrawer, + aPoints, Standard_False); + aWireCurves.Append (aPoints); + } + } + else + { + aWireCurves.Append (aPoints); + } + } + catch (Standard_Failure) + { + #ifdef DEB + std::cout << "probleme sur aLocation'edge " << (void* ) &(*(anEdge).TShape()) << std::endl; + #endif + } + } + } + + if (theDrawer->FreeBoundaryDraw()) + { + // aFree boundaries; + for (anIt.Initialize (aLFree); anIt.More(); anIt.Next()) + { + const TopoDS_Edge& anEdge = TopoDS::Edge (anIt.Value()); + if (!BRep_Tool::Degenerated (anEdge)) + { + try + { + OCC_CATCH_SIGNALS + TColgp_SequenceOfPnt aPoints; + if (!AddPolygon (anEdge, aDeflection, aPoints)) + { + if (BRep_Tool::IsGeometric (anEdge)) + { + BRepAdaptor_Curve aCurve (anEdge); + myCurveAlgo.Add (thePresentation, aCurve, aDeflection, theDrawer, + aPoints, Standard_False); + aFreeCurves.Append (aPoints); + } + } + else + { + aFreeCurves.Append (aPoints); + } + } + catch (Standard_Failure) + { + #ifdef DEB + std::cout << "probleme sur aLocation'edge " << (void* ) &(*(anEdge).TShape()) << std::endl; + #endif + } + } + } + } + + if (theDrawer->UnFreeBoundaryDraw()) + { + // Unfree boundaries; + for (anIt.Initialize (aLUnFree); anIt.More(); anIt.Next()) + { + const TopoDS_Edge& anEdge = TopoDS::Edge (anIt.Value()); + try + { + OCC_CATCH_SIGNALS + TColgp_SequenceOfPnt aPoints; + if (!AddPolygon (anEdge, aDeflection, aPoints)) + { + if (BRep_Tool::IsGeometric (anEdge)) + { + BRepAdaptor_Curve aCurve (anEdge); + myCurveAlgo.Add (thePresentation, aCurve, aDeflection, theDrawer, aPoints, Standard_False); + anUnFreeCurves.Append (aPoints); + } + } + else + { + anUnFreeCurves.Append (aPoints); + } + } + catch (Standard_Failure) + { + #ifdef DEB + std::cout << "probleme sur aLocation'edge " << (void* ) &(*(anEdge).TShape()) << std::endl; + #endif + } + } + } + + if (aWireCurves.Size() > 0) + { + aNbBounds = aWireCurves.Size(); + Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; + for (anIt.Init (aWireCurves); anIt.More(); anIt.Next()) + { + aNbVertices += anIt.Value().Length(); + } + Handle(Graphic3d_ArrayOfPolylines) WireArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds); + for (anIt.Init (aWireCurves); anIt.More(); anIt.Next()) + { + TColgp_SequenceOfPnt aPoints; + aPoints.Assign (anIt.Value()); + WireArray->AddBound (aPoints.Length()); + for (anI = 1; anI <= aPoints.Length(); ++anI) + { + WireArray->AddVertex (aPoints.Value (anI)); + } + } + Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); + aGroup->SetPrimitivesAspect (theDrawer->WireAspect()->Aspect()); + aGroup->AddPrimitiveArray (WireArray); + } + + if (aFreeCurves.Size() > 0) + { + aNbBounds = aFreeCurves.Size(); + Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; + for (anIt.Init (aFreeCurves); anIt.More(); anIt.Next()) + { + aNbVertices += anIt.Value().Length(); + } + Handle(Graphic3d_ArrayOfPolylines) aFreeArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds); + for (anIt.Init(aFreeCurves); anIt.More(); anIt.Next()) + { + TColgp_SequenceOfPnt aPoints; + aPoints.Assign (anIt.Value()); + aFreeArray->AddBound (aPoints.Length()); + for (anI = 1; anI <= aPoints.Length(); ++anI) + { + aFreeArray->AddVertex (aPoints.Value (anI)); + } + } + Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); + aGroup->SetPrimitivesAspect (theDrawer->FreeBoundaryAspect()->Aspect()); + aGroup->AddPrimitiveArray (aFreeArray); + } + + if (anUnFreeCurves.Size() > 0) + { + aNbBounds = anUnFreeCurves.Size(); + Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; + for (anIt.Init (anUnFreeCurves); anIt.More(); anIt.Next()) + { + aNbVertices += anIt.Value().Length(); + } + Handle(Graphic3d_ArrayOfPolylines) anUnFreeArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds); + for (anIt.Init (anUnFreeCurves); anIt.More(); anIt.Next()) + { + TColgp_SequenceOfPnt aPoints; + aPoints.Assign (anIt.Value()); + anUnFreeArray->AddBound (aPoints.Length()); + for (anI = 1; anI <= aPoints.Length(); ++anI) + { + anUnFreeArray->AddVertex (aPoints.Value (anI)); + } + } + Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); + aGroup->SetPrimitivesAspect (theDrawer->UnFreeBoundaryAspect()->Aspect()); + aGroup->AddPrimitiveArray (anUnFreeArray); + } + + // Points + for (aTool.InitVertex(); aTool.MoreVertex(); aTool.NextVertex()) + { + aShapePoints.Append (BRep_Tool::Pnt (aTool.GetVertex())); + } + + aNbVertices = aShapePoints.Length(); + if (aNbVertices > 0) + { + Graphic3d_Array1OfVertex aPointArray (1, aNbVertices); + for (anI = 1; anI <= aNbVertices; ++anI) + { + aPointArray.SetValue (anI, Graphic3d_Vertex (aShapePoints.Value (anI).X(), + aShapePoints.Value (anI).Y(), + aShapePoints.Value (anI).Z())); + } + + Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); + aGroup->SetPrimitivesAspect (theDrawer->PointAspect()->Aspect()); + aGroup->MarkerSet (aPointArray); + } +} + +// ========================================================================= +// function: PickCurve +// purpose : +// ========================================================================= +Handle(TopTools_HSequenceOfShape) Prs3d_WFShape::PickCurve + (const Quantity_Length theX, + const Quantity_Length theY, + const Quantity_Length theZ, + const Quantity_Length theDistance, + const TopoDS_Shape& theShape, + const Handle (Prs3d_Drawer)& theDrawer) +{ + Handle(TopTools_HSequenceOfShape) aSeq = new TopTools_HSequenceOfShape(); + Prs3d_ShapeTool aTool (theShape); + for (aTool.InitCurve(); aTool.MoreCurve(); aTool.NextCurve()) + { + Bnd_Box aBndBox = aTool.CurveBound(); + aBndBox.Enlarge (theDistance); + if (!aBndBox.IsOut (gp_Pnt (theX, theY, theZ))) + { + if (myCurveAlgo.Match (theX, theY, theZ, theDistance, + BRepAdaptor_Curve (aTool.GetCurve()), theDrawer)) + { + Standard_Boolean isContain = Standard_False; + for (Standard_Integer anI = 1; anI <= aSeq->Length(); ++anI) + { + if (aSeq->Value (anI) == (aTool.GetCurve())) + { + isContain = Standard_True; + break; + } + } + if (!isContain) + { + aSeq->Append (aTool.GetCurve()); + } + } + } + } + return aSeq; +} + +// ========================================================================= +// function: PickPatch +// purpose : +// ========================================================================= +Handle(TopTools_HSequenceOfShape) Prs3d_WFShape::PickPatch + (const Quantity_Length theX, + const Quantity_Length theY, + const Quantity_Length theZ, + const Quantity_Length theDistance, + const TopoDS_Shape& theShape, + const Handle(Prs3d_Drawer)& theDrawer) +{ + Handle(TopTools_HSequenceOfShape) aSeq = new TopTools_HSequenceOfShape(); + Prs3d_ShapeTool aTool (theShape); + + Standard_Boolean aRba1 = theDrawer->UIsoAspect()->Number() != 0; + Standard_Boolean aRba2 = theDrawer->VIsoAspect()->Number() != 0; + Standard_Boolean isContain; + + if (aRba1 || aRba2) + { + BRepAdaptor_Surface aSurface; + for (aTool.InitFace(); aTool.MoreFace(); aTool.NextFace()) + { + Bnd_Box aBndBox = aTool.FaceBound(); + aBndBox.Enlarge (theDistance); + if (!aBndBox.IsOut (gp_Pnt (theX, theY, theZ))) + { + aSurface.Initialize (aTool.GetFace()); + Handle(BRepAdaptor_HSurface) aHSurface = new BRepAdaptor_HSurface (aSurface); + if (myFaceAlgo.Match (theX, theY, theZ, theDistance, aHSurface, theDrawer)) + { + isContain = Standard_False; + for (Standard_Integer anI = 1; anI <= aSeq->Length(); ++anI) + { + if (aSeq->Value (anI) == (aTool.GetFace())) + { + isContain = Standard_True; + break; + } + } + if (!isContain) + { + aSeq->Append (aTool.GetFace()); + } + } + } + } + } + + for (aTool.InitCurve(); aTool.MoreCurve(); aTool.NextCurve()) + { + Bnd_Box aBndBox = aTool.CurveBound(); + aBndBox.Enlarge (theDistance); + if (!aBndBox.IsOut (gp_Pnt (theX, theY, theZ))) + { + if (myCurveAlgo.Match (theX, theY, theZ, theDistance, + BRepAdaptor_Curve(aTool.GetCurve()), theDrawer)) + { + Handle(TopTools_HSequenceOfShape) aSurface = aTool.FacesOfEdge(); + for (Standard_Integer anI = 1; anI <= aSurface->Length(); ++anI) + { + isContain = Standard_False; + for (Standard_Integer aJ = 1; aJ <= aSeq->Length(); ++aJ) + { + if (aSeq->Value (aJ) == (aSurface->Value (anI))) + { + isContain = Standard_True; + break; + } + } + if (!isContain) + { + aSeq->Append (aSurface->Value (anI)); + } + } + } + } + } + return aSeq; +} diff --git a/src/Prs3d/Prs3d_WFShape.hxx b/src/Prs3d/Prs3d_WFShape.hxx index 3e2d4bb014..8c036c4d09 100644 --- a/src/Prs3d/Prs3d_WFShape.hxx +++ b/src/Prs3d/Prs3d_WFShape.hxx @@ -18,731 +18,110 @@ #ifndef _Prs3d_WFShape_H__ #define _Prs3d_WFShape_H__ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include +#include + +class Adaptor3d_Curve; +class TopoDS_Edge; +class TopoDS_Shape; +class TColgp_SequenceOfPnt; +class Handle(BRepAdaptor_HSurface); +class Handle(Prs3d_Drawer); -template class Prs3d_WFShape : Prs3d_Root { + public: DEFINE_STANDARD_ALLOC -private: +public: - //========================================================================= -// function: IsSame -// purpose -//========================================================================= - -Standard_EXPORT static Standard_Boolean IsSame (const Handle(Graphic3d_AspectLine3d)& theUAspect, - const Handle(Graphic3d_AspectLine3d)& theVAspect) -{ - Standard_Boolean isSame = Standard_True; - Quantity_Color aCU, aCV; - Aspect_TypeOfLine aTlU, aTlV; - Standard_Real aWU, aWV; - - theUAspect->Values(aCU, aTlU, aWU); - theVAspect->Values(aCV, aTlV, aWV); - - if (aCU != aCV || aTlU != aTlV || aWU != aWV) + class Face { - isSame = Standard_False; - } + public: + virtual void Add (const Handle(Prs3d_Presentation)& thePrs, + const Handle(BRepAdaptor_HSurface)& theFace, + const Standard_Boolean theToDrawUIso, + const Standard_Boolean theToDrawVIso, + const Quantity_Length theDeflection, + const Standard_Integer theNBUiso, + const Standard_Integer theNBViso, + const Handle(Prs3d_Drawer)& theDrawer, + Prs3d_NListOfSequenceOfPnt& theCurves) const = 0; - return isSame; -} + virtual Standard_Boolean Match (const Quantity_Length theX, + const Quantity_Length theY, + const Quantity_Length theZ, + const Quantity_Length theDistance, + const Handle(BRepAdaptor_HSurface)& theFace, + const Handle(Prs3d_Drawer)& theDrawer) const = 0; + }; -//========================================================================= -// function: AddPolygon -// purpose -//========================================================================= - -Standard_EXPORT static Standard_Boolean AddPolygon (const TopoDS_Edge& theEdge, - Handle(Graphic3d_Group)& , - const Standard_Real theDeflection, - const Handle (Prs3d_Drawer)& , - TColgp_SequenceOfPnt& thePoints) -{ - TopLoc_Location aLocation; - Standard_Real aFirst, aLast; - Handle(Geom_Curve) aCurve3d = BRep_Tool::Curve(theEdge, aFirst, aLast); - Handle(Poly_Polygon3D) aPolygon = BRep_Tool::Polygon3D(theEdge, aLocation); - - if (!aPolygon.IsNull()) + class Curve { - if ((aPolygon->Deflection() <= theDeflection) || aCurve3d.IsNull()) - { - const TColgp_Array1OfPnt& aPoints = aPolygon->Nodes(); - Standard_Integer anIndex = aPoints.Lower(); - if (aLocation.IsIdentity()) - { - for (; anIndex <= aPoints.Upper(); anIndex++) - thePoints.Append(aPoints.Value(anIndex)); - } - else - { - for (; anIndex <= aPoints.Upper(); anIndex++) - thePoints.Append(aPoints.Value(anIndex).Transformed(aLocation)); - } - return Standard_True; - } - } + public: + virtual void Add (const Handle(Prs3d_Presentation)& thePrs, + Adaptor3d_Curve& theCurve, + const Quantity_Length theDeflection, + const Handle(Prs3d_Drawer)& theDrawer, + TColgp_SequenceOfPnt& thePoints, + const Standard_Boolean theToDrawCurve) const = 0; - Handle(Poly_Triangulation) aTriangulation; - Handle(Poly_PolygonOnTriangulation) aHIndices; - BRep_Tool::PolygonOnTriangulation(theEdge, aHIndices, aTriangulation, aLocation); - if (!aHIndices.IsNull()) - { - if ((aHIndices->Deflection() <= theDeflection) || aCurve3d.IsNull()) - { - const TColStd_Array1OfInteger& anIndices = aHIndices->Nodes(); - const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); + virtual Standard_Boolean Match (const Quantity_Length theX, + const Quantity_Length theY, + const Quantity_Length theZ, + const Quantity_Length theDistance, + const Adaptor3d_Curve& theCurve, + const Handle(Prs3d_Drawer)& theDrawer) const = 0; + }; - Standard_Integer anIndex = anIndices.Lower(); - if (aLocation.IsIdentity()) - { - for (; anIndex <= anIndices.Upper(); anIndex++) - thePoints.Append(aNodes(anIndices(anIndex))); - } - else - { - for (; anIndex <= anIndices.Upper(); anIndex++) - thePoints.Append(aNodes(anIndices(anIndex)).Transformed(aLocation)); - } - return Standard_True; - } - } - return Standard_False; -} + inline Prs3d_WFShape (const Face& theFace, + const Curve& theCurve) + : myFaceAlgo (theFace), + myCurveAlgo (theCurve) {} public: -//========================================================================= -// function: Add -// purpose -//========================================================================= + //! Add shape to presentation + Standard_EXPORT void Add (const Handle (Prs3d_Presentation)& thePresentation, + const TopoDS_Shape& theShape, + const Handle (Prs3d_Drawer)& theDrawer); -Standard_EXPORT static void Add (const Handle (Prs3d_Presentation)& thePresentation, - const TopoDS_Shape& theShape, - const Handle (Prs3d_Drawer)& theDrawer) -{ - if (theShape.IsNull()) return; - - Prs3d_ShapeTool aTool(theShape); - TopTools_ListOfShape aLFree, aLUnFree, aLWire; - for (aTool.InitCurve(); aTool.MoreCurve(); aTool.NextCurve()) - { - const TopoDS_Edge& anEdge = aTool.GetCurve(); - switch (aTool.Neighbours()) - { - case 0: aLWire.Append(anEdge); break; - case 1: aLFree.Append(anEdge); break; - default: aLUnFree.Append(anEdge); - } - } - - Standard_Real aDeflection; - if (theDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) - { - // The arrow calculation is based on the global min max - Bnd_Box aBndBox; - BRepBndLib::Add(theShape, aBndBox); - if (! aBndBox.IsVoid()) - { - Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; - aBndBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - aDeflection = Max (aXmax-aXmin, Max (aYmax-aYmin, aZmax-aZmin)) * - theDrawer->DeviationCoefficient(); - } - else - aDeflection = theDrawer->MaximalChordialDeviation(); - } - else - aDeflection = theDrawer->MaximalChordialDeviation(); - - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); - - Prs3d_NListOfSequenceOfPnt anUIsoCurves; - Prs3d_NListOfSequenceOfPnt aVIsoCurves; - Prs3d_NListOfSequenceOfPnt aWireCurves; - Prs3d_NListOfSequenceOfPnt aFreeCurves; - Prs3d_NListOfSequenceOfPnt anUnFreeCurves; - TColgp_SequenceOfPnt aShapePoints; - - if (IsSame(theDrawer->UIsoAspect()->Aspect(), theDrawer->VIsoAspect()->Aspect())) - { - const Standard_Integer anIsoU = theDrawer->UIsoAspect()->Number(); - const Standard_Integer anIsoV = theDrawer->VIsoAspect()->Number(); - if (anIsoU || anIsoV) - { - BRepAdaptor_Surface aSurface; - for (aTool.InitFace();aTool.MoreFace();aTool.NextFace()) - { - if (aTool.HasSurface()) - { - if (!aTool.IsPlanarFace() || theDrawer->IsoOnPlane()) - { - aSurface.Initialize(aTool.GetFace()); - Handle(BRepAdaptor_HSurface) aHSurface = new BRepAdaptor_HSurface(aSurface); - try { - OCC_CATCH_SIGNALS - Prs3d_NListOfSequenceOfPnt aCurUIsoCurves; - FacePresentation::Add(thePresentation, aHSurface, - anIsoU, anIsoV, - aDeflection, - anIsoU, anIsoV, - theDrawer, - aCurUIsoCurves); - Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; - for( anIt.Init(aCurUIsoCurves); anIt.More(); anIt.Next()) - anUIsoCurves.Append(anIt.Value()); - } - catch (Standard_Failure) - { - } - } - } - } - } - } - else - { - const Standard_Integer anIsoU = theDrawer->UIsoAspect()->Number(); - const Standard_Integer anIsoV = theDrawer->VIsoAspect()->Number(); - if (anIsoU) - { - BRepAdaptor_Surface aSurface; - for (aTool.InitFace();aTool.MoreFace();aTool.NextFace()) - { - if (aTool.HasSurface()) - { - if (!aTool.IsPlanarFace() || theDrawer->IsoOnPlane()) - { - aSurface.Initialize(aTool.GetFace()); - Handle(BRepAdaptor_HSurface) aHSurface = new BRepAdaptor_HSurface(aSurface); - try - { - OCC_CATCH_SIGNALS - Prs3d_NListOfSequenceOfPnt aCurUIsoCurves; - FacePresentation::Add(thePresentation, aHSurface, - anIsoU, Standard_False, - aDeflection, - anIsoU, 0, - theDrawer, - aCurUIsoCurves); - } - catch (Standard_Failure) - { -#ifdef DEB - const TopoDS_Face& aFace = aSurface.Face(); - cout <<"Problem with the face "<< (void*) &(*(aFace).TShape()) << endl; -#endif - } - } - } - } - } - if (anIsoV) - { - BRepAdaptor_Surface aSurface; - for (aTool.InitFace();aTool.MoreFace();aTool.NextFace()) - { - if (aTool.HasSurface()) - { - if (!aTool.IsPlanarFace() || theDrawer->IsoOnPlane()) - { - aSurface.Initialize(aTool.GetFace()); - Handle(BRepAdaptor_HSurface) aHSurface = new BRepAdaptor_HSurface(aSurface); - try - { - OCC_CATCH_SIGNALS - Prs3d_NListOfSequenceOfPnt aCurUIsoCurves; - FacePresentation::Add(thePresentation, aHSurface, - Standard_False, anIsoV, - aDeflection, - 0, anIsoV, - theDrawer, - aCurUIsoCurves); - } - catch (Standard_Failure) - { -#ifdef DEB - const TopoDS_Face& aFace = aSurface.Face(); - cout <<"Problem with the face "<< (void*) &(*(aFace).TShape()) << endl; -#endif - } - } - } - } - } - } - Standard_Integer aNbVertices = 0, aNbBounds = 0; - - if(anUIsoCurves.Size() > 0) { - aNbBounds = anUIsoCurves.Size(); - Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; - for( anIt.Init(anUIsoCurves); anIt.More(); anIt.Next()) - aNbVertices += anIt.Value().Length(); - Handle(Graphic3d_ArrayOfPolylines) anUIsoArray = - new Graphic3d_ArrayOfPolylines(aNbVertices,aNbBounds); - for( anIt.Init(anUIsoCurves); anIt.More(); anIt.Next()) { - TColgp_SequenceOfPnt aPoints; - aPoints.Assign(anIt.Value()); - anUIsoArray->AddBound(aPoints.Length()); - for(Standard_Integer anI = 1; anI <= aPoints.Length(); ++anI) - anUIsoArray->AddVertex(aPoints.Value(anI)); - } - Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePresentation); - aGroup->SetPrimitivesAspect(theDrawer->UIsoAspect()->Aspect()); - aGroup->AddPrimitiveArray(anUIsoArray); - } - - if(aVIsoCurves.Size() > 0) { - aNbBounds = aVIsoCurves.Size(); - Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; - for( anIt.Init(aVIsoCurves); anIt.More(); anIt.Next()) - aNbVertices += anIt.Value().Length(); - Handle(Graphic3d_ArrayOfPolylines) VIsoArray = - new Graphic3d_ArrayOfPolylines(aNbVertices,aNbBounds); - for( anIt.Init(aVIsoCurves); anIt.More(); anIt.Next()) { - TColgp_SequenceOfPnt aPoints; - aPoints.Assign(anIt.Value()); - VIsoArray->AddBound(aPoints.Length()); - for(int anI=1; anI<=aPoints.Length(); anI++) - VIsoArray->AddVertex(aPoints.Value(anI)); - } - Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePresentation); - aGroup->SetPrimitivesAspect(theDrawer->VIsoAspect()->Aspect()); - aGroup->AddPrimitiveArray(VIsoArray); - } - - TopLoc_Location aLocation; - Standard_Integer anI, aJ, aN[3]; - - Standard_Boolean isDispTriangles = Standard_False; - const char* anEnvVar = getenv("DEBUG_TRIANGLES"); - if (anEnvVar != 0L) { - isDispTriangles = (atol(anEnvVar) != 0); - } - - TColgp_SequenceOfPnt aSurfPoints; - for (aTool.InitFace();aTool.MoreFace();aTool.NextFace()) - { - if (!aTool.HasSurface() || isDispTriangles) - { - Handle(Poly_Triangulation) T = aTool.CurrentTriangulation(aLocation); - if (!T.IsNull()) - { - const TColgp_Array1OfPnt& aNodes = T->Nodes(); - // Build the connect tool - Poly_Connect aPolyConnect(T); - - Standard_Integer aNbFree, aNbInternal, aNbTriangles = T->NbTriangles(); - Standard_Integer aT[3]; - - // Count the free edges - aNbFree = 0; - for (anI = 1; anI <= aNbTriangles; anI++) { - aPolyConnect.Triangles(anI,aT[0],aT[1],aT[2]); - for (aJ = 0; aJ < 3; aJ++) - if (aT[aJ] == 0) aNbFree++; - } - - // Allocate the arrays - TColStd_Array1OfInteger aFree(1,2*aNbFree); - aNbInternal = (3*aNbTriangles - aNbFree) / 2; - TColStd_Array1OfInteger anInternal(0,2*aNbInternal); - - Standard_Integer aFreeIndex = 1, anIntIndex = 1; - const Poly_Array1OfTriangle& aTriangles = T->Triangles(); - for (anI = 1; anI <= aNbTriangles; anI++) { - aPolyConnect.Triangles(anI,aT[0],aT[1],aT[2]); - aTriangles(anI).Get(aN[0],aN[1],aN[2]); - for (aJ = 0; aJ < 3; aJ++) { - Standard_Integer k = (aJ+1) % 3; - if (aT[aJ] == 0) { - aFree(aFreeIndex) = aN[aJ]; - aFree(aFreeIndex+1) = aN[k]; - aFreeIndex += 2; - } - // internal edge if this triangle has a lower index than the adjacent - else if (anI < aT[aJ]) { - anInternal(anIntIndex) = aN[aJ]; - anInternal(anIntIndex+1) = aN[k]; - anIntIndex += 2; - } - } - } - - if(!aTool.HasSurface()) - { - // free edges - Standard_Integer aFreeHalfNb = aFree.Length() / 2; - for (anI = 1; anI <= aFreeHalfNb; anI++) { - gp_Pnt aPoint1 = aNodes(aFree(2*anI-1)).Transformed(aLocation); - gp_Pnt aPoint2 = aNodes(aFree(2*anI)).Transformed(aLocation); - aSurfPoints.Append(aPoint1); - aSurfPoints.Append(aPoint2); - } - } - if(isDispTriangles) - { - for (anI = 1; anI <= aNbInternal; anI++) { - gp_Pnt aPoint1 = aNodes(anInternal(2*anI-1)).Transformed(aLocation); - gp_Pnt aPoint2 = aNodes(anInternal(2*anI)).Transformed(aLocation); - aSurfPoints.Append(aPoint1); - aSurfPoints.Append(aPoint2); - } - } - } - } - } - if(aSurfPoints.Length()>0){ - aNbVertices = aSurfPoints.Length(); - aNbBounds = (Standard_Integer)aNbVertices / 2; - Handle(Graphic3d_ArrayOfPolylines) aSurfArray = - new Graphic3d_ArrayOfPolylines(aNbVertices,aNbBounds); - for(anI=1; anI<=aNbVertices; anI+=2) { - aSurfArray->AddBound(2); - aSurfArray->AddVertex(aSurfPoints.Value(anI)); - aSurfArray->AddVertex(aSurfPoints.Value(anI+1)); - } - Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePresentation); - if(isDispTriangles && aTool.HasSurface()) - aGroup->SetPrimitivesAspect(theDrawer->UIsoAspect()->Aspect()); - else - aGroup->SetPrimitivesAspect(theDrawer->FreeBoundaryAspect()->Aspect()); - aGroup->AddPrimitiveArray(aSurfArray); - } - TopTools_ListIteratorOfListOfShape anIt; - - if (theDrawer->WireDraw()) - { - // Wire (without any neighbour) - aGroup->SetPrimitivesAspect(theDrawer->WireAspect()->Aspect()); - for (anIt.Initialize(aLWire); anIt.More(); anIt.Next()) { - const TopoDS_Edge& anEdge = TopoDS::Edge(anIt.Value()); - try - { - OCC_CATCH_SIGNALS - TColgp_SequenceOfPnt aPoints; - if (!AddPolygon(anEdge, aGroup, aDeflection, theDrawer, aPoints)) - { - if (BRep_Tool::IsGeometric(anEdge)) - { - BRepAdaptor_Curve aCurve(anEdge); - CurvePresentation::Add(thePresentation, aCurve, aDeflection, theDrawer, - aPoints, Standard_False); - aWireCurves.Append(aPoints); - } - } - else - aWireCurves.Append(aPoints); - } - catch(Standard_Failure) - { -#ifdef DEB - cout <<"probleme sur aLocation'edge "<< (void*) &(*(anEdge).TShape()) << endl; -#endif - } - } - } - - if (theDrawer->FreeBoundaryDraw()) - { - // aFree boundaries; - for (anIt.Initialize(aLFree); anIt.More(); anIt.Next()) - { - const TopoDS_Edge& anEdge = TopoDS::Edge(anIt.Value()); - if (!BRep_Tool::Degenerated(anEdge)) - { - try { - OCC_CATCH_SIGNALS - TColgp_SequenceOfPnt aPoints; - if (!AddPolygon(anEdge, aGroup, aDeflection, theDrawer, aPoints)) { - if (BRep_Tool::IsGeometric(anEdge)) { - BRepAdaptor_Curve aCurve(anEdge); - CurvePresentation::Add(thePresentation, aCurve, aDeflection, theDrawer, - aPoints, Standard_False); - aFreeCurves.Append(aPoints); - } - } - else - aFreeCurves.Append(aPoints); - } - catch(Standard_Failure) - { -#ifdef DEB - cout <<"probleme sur aLocation'edge "<< (void*) &(*(anEdge).TShape()) << endl; -#endif - } - } - } - } - - if (theDrawer->UnFreeBoundaryDraw()) - { - // Unfree boundaries; - - for (anIt.Initialize(aLUnFree); anIt.More(); anIt.Next()) - { - const TopoDS_Edge& anEdge = TopoDS::Edge(anIt.Value()); - try - { - OCC_CATCH_SIGNALS - TColgp_SequenceOfPnt aPoints; - if (!AddPolygon(anEdge, aGroup, aDeflection, theDrawer, aPoints)) { - if (BRep_Tool::IsGeometric(anEdge)) { - BRepAdaptor_Curve aCurve(anEdge); - CurvePresentation::Add(thePresentation, aCurve, aDeflection, theDrawer, aPoints, Standard_False); - anUnFreeCurves.Append(aPoints); - } - } - else - anUnFreeCurves.Append(aPoints); - } - catch(Standard_Failure) - { -#ifdef DEB - cout <<"probleme sur aLocation'edge "<< (void*) &(*(anEdge).TShape()) << endl; -#endif - } - } - } - - if(aWireCurves.Size() > 0) - { - aNbBounds = aWireCurves.Size(); - Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; - for( anIt.Init(aWireCurves); anIt.More(); anIt.Next()) - aNbVertices += anIt.Value().Length(); - Handle(Graphic3d_ArrayOfPolylines) WireArray = - new Graphic3d_ArrayOfPolylines(aNbVertices,aNbBounds); - for( anIt.Init(aWireCurves); anIt.More(); anIt.Next()) { - TColgp_SequenceOfPnt aPoints; - aPoints.Assign(anIt.Value()); - WireArray->AddBound(aPoints.Length()); - for(anI=1; anI<=aPoints.Length(); ++anI) - WireArray->AddVertex(aPoints.Value(anI)); - } - Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePresentation); - aGroup->SetPrimitivesAspect(theDrawer->WireAspect()->Aspect()); - aGroup->AddPrimitiveArray(WireArray); - } - if(aFreeCurves.Size() > 0) { - aNbBounds = aFreeCurves.Size(); - Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; - for( anIt.Init(aFreeCurves); anIt.More(); anIt.Next()) - aNbVertices += anIt.Value().Length(); - Handle(Graphic3d_ArrayOfPolylines) aFreeArray = - new Graphic3d_ArrayOfPolylines(aNbVertices,aNbBounds); - for( anIt.Init(aFreeCurves); anIt.More(); anIt.Next()) { - TColgp_SequenceOfPnt aPoints; - aPoints.Assign(anIt.Value()); - aFreeArray->AddBound(aPoints.Length()); - for(anI=1; anI<=aPoints.Length(); anI++) - aFreeArray->AddVertex(aPoints.Value(anI)); - } - Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePresentation); - aGroup->SetPrimitivesAspect(theDrawer->FreeBoundaryAspect()->Aspect()); - aGroup->AddPrimitiveArray(aFreeArray); - } - if(anUnFreeCurves.Size() > 0) { - aNbBounds = anUnFreeCurves.Size(); - Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; - for( anIt.Init(anUnFreeCurves); anIt.More(); anIt.Next()) - aNbVertices += anIt.Value().Length(); - Handle(Graphic3d_ArrayOfPolylines) anUnFreeArray = - new Graphic3d_ArrayOfPolylines(aNbVertices,aNbBounds); - for( anIt.Init(anUnFreeCurves); anIt.More(); anIt.Next()) { - TColgp_SequenceOfPnt aPoints; - aPoints.Assign(anIt.Value()); - anUnFreeArray->AddBound(aPoints.Length()); - for(anI=1; anI<=aPoints.Length(); anI++) - anUnFreeArray->AddVertex(aPoints.Value(anI)); - } - Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePresentation); - aGroup->SetPrimitivesAspect(theDrawer->UnFreeBoundaryAspect()->Aspect()); - aGroup->AddPrimitiveArray(anUnFreeArray); - } - - // Points - for(aTool.InitVertex();aTool.MoreVertex();aTool.NextVertex()) - aShapePoints.Append(BRep_Tool::Pnt(aTool.GetVertex())); - - aNbVertices = aShapePoints.Length(); - if(aNbVertices > 0) { - Graphic3d_Array1OfVertex aPointArray(1, aNbVertices); - for(anI=1; anI<=aNbVertices; anI++) - aPointArray.SetValue(anI, Graphic3d_Vertex(aShapePoints.Value(anI).X(), aShapePoints.Value(anI).Y(), aShapePoints.Value(anI).Z())); - - Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePresentation); - aGroup->SetPrimitivesAspect(theDrawer->PointAspect()->Aspect()); - aGroup->MarkerSet(aPointArray); - } -} - -//========================================================================= -// function: PickCurve -// purpose -//========================================================================= - -Standard_EXPORT static Handle(TopTools_HSequenceOfShape) PickCurve + Standard_EXPORT Handle(TopTools_HSequenceOfShape) PickCurve (const Quantity_Length theX, const Quantity_Length theY, const Quantity_Length theZ, const Quantity_Length theDistance, const TopoDS_Shape& theShape, - const Handle (Prs3d_Drawer)& theDrawer) -{ - Handle(TopTools_HSequenceOfShape) aSeq = new TopTools_HSequenceOfShape; - Prs3d_ShapeTool aTool(theShape); - Standard_Boolean isContain; + const Handle (Prs3d_Drawer)& theDrawer); - for (aTool.InitCurve(); aTool.MoreCurve(); aTool.NextCurve()) - { - Bnd_Box aBndBox = aTool.CurveBound(); - aBndBox.Enlarge(theDistance); - if (! aBndBox.IsOut(gp_Pnt(theX, theY, theZ))) - { - if (CurvePresentation::Match(theX, theY, theZ, theDistance, - BRepAdaptor_Curve(aTool.GetCurve()), theDrawer)) - { - isContain = Standard_False; - for (Standard_Integer anI = 1; anI <= aSeq->Length(); ++anI) - { - if (aSeq->Value(anI) == (aTool.GetCurve())) - { - isContain = Standard_True; - break; - } - } - if (!isContain) aSeq->Append(aTool.GetCurve()); - } - } - } - return aSeq; -} - - -//========================================================================= -// function: PickPatch -// purpose -//========================================================================= - -Standard_EXPORT static Handle(TopTools_HSequenceOfShape) PickPatch + Standard_EXPORT Handle(TopTools_HSequenceOfShape) PickPatch (const Quantity_Length theX, const Quantity_Length theY, const Quantity_Length theZ, const Quantity_Length theDistance, const TopoDS_Shape& theShape, - const Handle(Prs3d_Drawer)& theDrawer) -{ + const Handle(Prs3d_Drawer)& theDrawer); - Handle(TopTools_HSequenceOfShape) aSeq = new TopTools_HSequenceOfShape; - Prs3d_ShapeTool aTool(theShape); +private: - Standard_Boolean aRba1 = theDrawer->UIsoAspect()->Number() != 0; - Standard_Boolean aRba2 = theDrawer->VIsoAspect()->Number() != 0; - Standard_Boolean isContain; + static Standard_Boolean AddPolygon (const TopoDS_Edge& theEdge, + const Standard_Real theDeflection, + TColgp_SequenceOfPnt& thePoints); - if (aRba1 || aRba2) - { - BRepAdaptor_Surface aSurface; - for (aTool.InitFace(); aTool.MoreFace(); aTool.NextFace()) - { - Bnd_Box aBndBox = aTool.FaceBound(); - aBndBox.Enlarge(theDistance); - if (!aBndBox.IsOut(gp_Pnt(theX, theY, theZ))) - { - aSurface.Initialize(aTool.GetFace()); - Handle(BRepAdaptor_HSurface) aHSurface = new BRepAdaptor_HSurface(aSurface); - if (FacePresentation::Match(theX, theY, theZ, theDistance, aHSurface, theDrawer)) - { - isContain = Standard_False; - for (Standard_Integer anI = 1; anI <= aSeq->Length(); ++anI) - { - if (aSeq->Value(anI) == (aTool.GetFace())) - { - isContain = Standard_True; - break; - } - } - if (!isContain) - aSeq->Append(aTool.GetFace()); - } - } - } - } +private: - for (aTool.InitCurve(); aTool.MoreCurve(); aTool.NextCurve()) - { - Bnd_Box aBndBox = aTool.CurveBound(); - aBndBox.Enlarge(theDistance); - if (!aBndBox.IsOut(gp_Pnt(theX, theY, theZ))) - { - if(CurvePresentation::Match(theX, theY, theZ, theDistance, - BRepAdaptor_Curve(aTool.GetCurve()), theDrawer)) - { - Handle(TopTools_HSequenceOfShape) aSurface = aTool.FacesOfEdge(); - for (Standard_Integer anI = 1; anI <= aSurface->Length(); ++anI) - { - isContain = Standard_False; - for (Standard_Integer aJ = 1; aJ <= aSeq->Length(); ++aJ) - { - if (aSeq->Value(aJ) == (aSurface->Value(anI))) - { - isContain = Standard_True; - break; - } - } - if (!isContain) - aSeq->Append(aSurface->Value(anI)); - } - } - } - } - return aSeq; -} + const Face& myFaceAlgo; + const Curve& myCurveAlgo; + +private: + + Prs3d_WFShape (const Prs3d_WFShape& ); + Prs3d_WFShape& operator= (const Prs3d_WFShape& ); }; -#endif +#endif // _Prs3d_WFShape_H__ diff --git a/src/StdPrs/StdPrs_WFDeflectionShape.hxx b/src/StdPrs/StdPrs_WFDeflectionShape.hxx index 1e753c1bcd..9311624e66 100644 --- a/src/StdPrs/StdPrs_WFDeflectionShape.hxx +++ b/src/StdPrs/StdPrs_WFDeflectionShape.hxx @@ -28,5 +28,104 @@ #include #include -typedef Prs3d_WFShape StdPrs_WFDeflectionShape; -#endif +class StdPrs_WFDeflectionShape : public Prs3d_Root +{ + +public: + + //! Add shape to presentation + static inline void Add (const Handle (Prs3d_Presentation)& thePrs, + const TopoDS_Shape& theShape, + const Handle (Prs3d_Drawer)& theDrawer) + { + Face aFaceAlgo; + Curve aCurveAlgo; + Prs3d_WFShape anAlgo (aFaceAlgo, aCurveAlgo); + anAlgo.Add (thePrs, theShape, theDrawer); + } + + static inline Handle(TopTools_HSequenceOfShape) PickCurve + (const Quantity_Length theX, + const Quantity_Length theY, + const Quantity_Length theZ, + const Quantity_Length theDistance, + const TopoDS_Shape& theShape, + const Handle (Prs3d_Drawer)& theDrawer) + { + Face aFaceAlgo; + Curve aCurveAlgo; + Prs3d_WFShape anAlgo (aFaceAlgo, aCurveAlgo); + return anAlgo.PickCurve (theX, theY, theZ, theDistance, theShape, theDrawer); + } + + static inline Handle(TopTools_HSequenceOfShape) PickPatch + (const Quantity_Length theX, + const Quantity_Length theY, + const Quantity_Length theZ, + const Quantity_Length theDistance, + const TopoDS_Shape& theShape, + const Handle(Prs3d_Drawer)& theDrawer) + { + Face aFaceAlgo; + Curve aCurveAlgo; + Prs3d_WFShape anAlgo (aFaceAlgo, aCurveAlgo); + return anAlgo.PickPatch (theX, theY, theZ, theDistance, theShape, theDrawer); + } + +private: + + class Face : public Prs3d_WFShape::Face + { + public: + virtual void Add (const Handle(Prs3d_Presentation)& thePrs, + const Handle(BRepAdaptor_HSurface)& theFace, + const Standard_Boolean theToDrawUIso, + const Standard_Boolean theToDrawVIso, + const Quantity_Length theDeflection, + const Standard_Integer theNBUiso, + const Standard_Integer theNBViso, + const Handle(Prs3d_Drawer)& theDrawer, + Prs3d_NListOfSequenceOfPnt& theCurves) const + { + StdPrs_WFDeflectionRestrictedFace::Add (thePrs, theFace, theToDrawUIso, theToDrawVIso, theDeflection, + theNBUiso, theNBViso, theDrawer, theCurves); + } + + virtual Standard_Boolean Match (const Quantity_Length theX, + const Quantity_Length theY, + const Quantity_Length theZ, + const Quantity_Length theDistance, + const Handle(BRepAdaptor_HSurface)& theFace, + const Handle(Prs3d_Drawer)& theDrawer) const + { + return StdPrs_WFDeflectionRestrictedFace::Match (theX, theY, theZ, theDistance, theFace, theDrawer); + } + }; + + class Curve : public Prs3d_WFShape::Curve + { + public: + virtual void Add (const Handle(Prs3d_Presentation)& thePrs, + Adaptor3d_Curve& theCurve, + const Quantity_Length theDeflection, + const Handle(Prs3d_Drawer)& theDrawer, + TColgp_SequenceOfPnt& thePoints, + const Standard_Boolean theToDrawCurve) const + { + StdPrs_DeflectionCurve::Add (thePrs, theCurve, theDeflection, theDrawer, thePoints, theToDrawCurve); + } + + virtual Standard_Boolean Match (const Quantity_Length theX, + const Quantity_Length theY, + const Quantity_Length theZ, + const Quantity_Length theDistance, + const Adaptor3d_Curve& theCurve, + const Handle(Prs3d_Drawer)& theDrawer) const + { + return StdPrs_DeflectionCurve::Match (theX, theY, theZ, theDistance, theCurve, theDrawer); + } + }; + +}; + +#endif // _StdPrs_WFDeflectionShape_H__ diff --git a/src/StdPrs/StdPrs_WFShape.hxx b/src/StdPrs/StdPrs_WFShape.hxx index 91937f5141..0b0b99301c 100644 --- a/src/StdPrs/StdPrs_WFShape.hxx +++ b/src/StdPrs/StdPrs_WFShape.hxx @@ -28,5 +28,104 @@ #include #include -typedef Prs3d_WFShape StdPrs_WFShape; -#endif \ No newline at end of file +class StdPrs_WFShape : public Prs3d_Root +{ + +public: + + //! Add shape to presentation + static inline void Add (const Handle (Prs3d_Presentation)& thePrs, + const TopoDS_Shape& theShape, + const Handle (Prs3d_Drawer)& theDrawer) + { + Face aFaceAlgo; + Curve aCurveAlgo; + Prs3d_WFShape anAlgo (aFaceAlgo, aCurveAlgo); + anAlgo.Add (thePrs, theShape, theDrawer); + } + + static inline Handle(TopTools_HSequenceOfShape) PickCurve + (const Quantity_Length theX, + const Quantity_Length theY, + const Quantity_Length theZ, + const Quantity_Length theDistance, + const TopoDS_Shape& theShape, + const Handle (Prs3d_Drawer)& theDrawer) + { + Face aFaceAlgo; + Curve aCurveAlgo; + Prs3d_WFShape anAlgo (aFaceAlgo, aCurveAlgo); + return anAlgo.PickCurve (theX, theY, theZ, theDistance, theShape, theDrawer); + } + + static inline Handle(TopTools_HSequenceOfShape) PickPatch + (const Quantity_Length theX, + const Quantity_Length theY, + const Quantity_Length theZ, + const Quantity_Length theDistance, + const TopoDS_Shape& theShape, + const Handle(Prs3d_Drawer)& theDrawer) + { + Face aFaceAlgo; + Curve aCurveAlgo; + Prs3d_WFShape anAlgo (aFaceAlgo, aCurveAlgo); + return anAlgo.PickPatch (theX, theY, theZ, theDistance, theShape, theDrawer); + } + +private: + + class Face : public Prs3d_WFShape::Face + { + public: + virtual void Add (const Handle(Prs3d_Presentation)& thePrs, + const Handle(BRepAdaptor_HSurface)& theFace, + const Standard_Boolean theToDrawUIso, + const Standard_Boolean theToDrawVIso, + const Quantity_Length theDeflection, + const Standard_Integer theNBUiso, + const Standard_Integer theNBViso, + const Handle(Prs3d_Drawer)& theDrawer, + Prs3d_NListOfSequenceOfPnt& theCurves) const + { + StdPrs_WFRestrictedFace::Add (thePrs, theFace, theToDrawUIso, theToDrawVIso, theDeflection, + theNBUiso, theNBViso, theDrawer, theCurves); + } + + virtual Standard_Boolean Match (const Quantity_Length theX, + const Quantity_Length theY, + const Quantity_Length theZ, + const Quantity_Length theDistance, + const Handle(BRepAdaptor_HSurface)& theFace, + const Handle(Prs3d_Drawer)& theDrawer) const + { + return StdPrs_WFRestrictedFace::Match (theX, theY, theZ, theDistance, theFace, theDrawer); + } + }; + + class Curve : public Prs3d_WFShape::Curve + { + public: + virtual void Add (const Handle(Prs3d_Presentation)& thePrs, + Adaptor3d_Curve& theCurve, + const Quantity_Length theDeflection, + const Handle(Prs3d_Drawer)& theDrawer, + TColgp_SequenceOfPnt& thePoints, + const Standard_Boolean theToDrawCurve) const + { + StdPrs_Curve::Add (thePrs, theCurve, theDeflection, theDrawer, thePoints, theToDrawCurve); + } + + virtual Standard_Boolean Match (const Quantity_Length theX, + const Quantity_Length theY, + const Quantity_Length theZ, + const Quantity_Length theDistance, + const Adaptor3d_Curve& theCurve, + const Handle(Prs3d_Drawer)& theDrawer) const + { + return StdPrs_Curve::Match (theX, theY, theZ, theDistance, theCurve, theDrawer); + } + }; + +}; + +#endif // _StdPrs_WFShape_H__ diff --git a/tests/heal/data/advanced/ZA1 b/tests/heal/data/advanced/ZA1 index 01c1be2f11..fdbb10cb2a 100644 --- a/tests/heal/data/advanced/ZA1 +++ b/tests/heal/data/advanced/ZA1 @@ -1,5 +1,5 @@ if {[string compare $command "SplitAngle"] == 0 } { - puts "TODO OCC23127 ALL: Faulty shapes in variables faulty_1 to faulty_2 " + puts "TODO OCC23127 ALL: Faulty shapes in variables faulty_1 to faulty_" } restore [locate_data_file PLANCHER.brep] a