#include "stdafx.h" #include #include "..\\GeometryApp.h" IMPLEMENT_STANDARD_HANDLE(ISession2D_Curve,AIS_InteractiveObject) IMPLEMENT_STANDARD_RTTI(ISession2D_Curve,AIS_InteractiveObject) // // Foreach ancestors, we added a IMPLEMENT_STANDARD_SUPERTYPE and // a IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY macro. // We must respect the order: from the direct ancestor class // to the base class. // IMPLEMENT_STANDARD_TYPE(ISession2D_Curve) IMPLEMENT_STANDARD_SUPERTYPE(AIS_InteractiveObject) IMPLEMENT_STANDARD_SUPERTYPE(SelectMgr_SelectableObject) IMPLEMENT_STANDARD_SUPERTYPE(PrsMgr_PresentableObject) IMPLEMENT_STANDARD_SUPERTYPE(MMgt_TShared) IMPLEMENT_STANDARD_SUPERTYPE(Standard_Transient) IMPLEMENT_STANDARD_SUPERTYPE_ARRAY() IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(AIS_InteractiveObject) IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(SelectMgr_SelectableObject) IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(PrsMgr_PresentableObject) IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(MMgt_TShared) IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(Standard_Transient) IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END() IMPLEMENT_STANDARD_TYPE_END(ISession2D_Curve) #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 ISession2D_Curve::ISession2D_Curve(const Handle_Geom2d_Curve aGeom2dCurve, const Aspect_TypeOfLine aTypeOfLine, const Aspect_WidthOfLine aWidthOfLine, const Standard_Integer aColorIndex) :AIS_InteractiveObject() { myGeom2dCurve = aGeom2dCurve; myTypeOfLine = aTypeOfLine ; myWidthOfLine = aWidthOfLine; myColorIndex = aColorIndex ; myDisplayPole = Standard_True; myDisplayCurbure = Standard_False; myDiscretisation = 20; myradiusmax = 10; myradiusratio = 1; } void ISession2D_Curve::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager, const Handle(Graphic2d_GraphicObject)& aGrObj, const Standard_Integer aMode) { Handle(Graphic2d_SetOfCurves) segment; segment = new Graphic2d_SetOfCurves(aGrObj); segment->Add(myGeom2dCurve); segment->SetColorIndex (myColorIndex); segment->SetWidthIndex (myWidthOfLine + 1); segment->SetTypeIndex (myTypeOfLine + 1); Geom2dAdaptor_Curve anAdaptor(myGeom2dCurve); if (myDisplayPole) { if (anAdaptor.GetType() == GeomAbs_BezierCurve ) { Handle(Geom2d_BezierCurve) aBezier = anAdaptor.Bezier(); Graphic2d_Array1OfVertex anArrayOfVertex(1,aBezier->NbPoles()); for(int i=1;i<=aBezier->NbPoles();i++) { gp_Pnt2d CurrentPoint = aBezier->Pole(i); Graphic2d_Vertex aVertex(CurrentPoint.X(),CurrentPoint.Y()); anArrayOfVertex(i)=aVertex; } Handle(Graphic2d_Polyline) aPolyline = new Graphic2d_Polyline(aGrObj,anArrayOfVertex); } if (anAdaptor.GetType() == GeomAbs_BSplineCurve ) { Handle(Geom2d_BSplineCurve) aBSpline = anAdaptor.BSpline(); Graphic2d_Array1OfVertex anArrayOfVertex(1,aBSpline->NbPoles()); for(int i=1;i<=aBSpline->NbPoles();i++) { gp_Pnt2d CurrentPoint = aBSpline->Pole(i); Graphic2d_Vertex aVertex(CurrentPoint.X(),CurrentPoint.Y()); anArrayOfVertex(i)=aVertex; } Handle(Graphic2d_Polyline) aPolyline = new Graphic2d_Polyline(aGrObj,anArrayOfVertex); } } if (myDisplayCurbure && (anAdaptor.GetType() != GeomAbs_Line)) { Standard_Integer ii; Standard_Integer intrv, nbintv = anAdaptor.NbIntervals(GeomAbs_CN); TColStd_Array1OfReal TI(1,nbintv+1); anAdaptor.Intervals(TI,GeomAbs_CN); Standard_Real Resolution = 1.0e-9, Curvature; Geom2dLProp_CLProps2d LProp(myGeom2dCurve, 2, Resolution); gp_Pnt2d P1, P2; for (intrv = 1; intrv <= nbintv; intrv++) { Standard_Real t = TI(intrv); Standard_Real step = (TI(intrv+1) - t) / GetDiscretisation(); Standard_Real LRad, ratio; for (ii = 1; ii <= myDiscretisation; ii++) { LProp.SetParameter(t); if (LProp.IsTangentDefined()) { Curvature = Abs(LProp.Curvature()); if ( Curvature > Resolution) { myGeom2dCurve->D0(t, P1); LRad = 1./Curvature; ratio = ( ( LRad > myradiusmax) ? myradiusmax/LRad : 1 ); ratio *= myradiusratio; LProp.CentreOfCurvature(P2); gp_Vec2d V(P1, P2); gp_Pnt2d P3 = P1.Translated(ratio*V); Handle(Graphic2d_Segment) aSegment = new Graphic2d_Segment(aGrObj,P1.X(),P1.Y(),P3.X(),P3.Y()); } } t += step; } } } } void ISession2D_Curve::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) { }