0022792: Globally defined symbol PI conflicts with VTK definition (Intel compiler)
[occt.git] / src / DrawTrSurf / DrawTrSurf_Curve.cxx
1 #include <DrawTrSurf_Curve.ixx>
2 #include <GeomAdaptor_Curve.hxx>
3 #include <GeomTools_CurveSet.hxx>
4 #include <GeomLProp_CLProps.hxx>
5 #include <Precision.hxx>
6 #include <gp.hxx>
7 #include <gp_Pnt2d.hxx>
8 #include <gp_Dir2d.hxx>
9 #include <gp_Vec.hxx>
10 #include <gp_Vec2d.hxx>
11 #include <TColStd_Array1OfReal.hxx>
12
13 Standard_Real DrawTrSurf_CurveLimit = 400;
14 extern Standard_Boolean Draw_Bounds;
15
16
17 //=======================================================================
18 //function : DrawTrSurf_Curve
19 //purpose  : 
20 //=======================================================================
21
22 DrawTrSurf_Curve::DrawTrSurf_Curve (const Handle(Geom_Curve)& C,
23                                     const Standard_Boolean DispOrigin) :
24        DrawTrSurf_Drawable (16, 0.01, 1),
25        curv(C),
26        look(Draw_vert),
27        disporigin(DispOrigin),
28        dispcurvradius(Standard_False),
29        radiusmax(1.0e3),
30        radiusratio(0.1)
31 {
32 }
33
34
35
36 //=======================================================================
37 //function : DrawTrSurf_Curve
38 //purpose  : 
39 //=======================================================================
40
41 DrawTrSurf_Curve::DrawTrSurf_Curve (const Handle(Geom_Curve)& C, 
42                                     const Draw_Color& aColor, 
43                                     const Standard_Integer Discret,
44                                     const Standard_Real Deflection, 
45                                     const Standard_Integer DrawMode,
46                                     const Standard_Boolean DispOrigin,
47                                     const Standard_Boolean DispCurvRadius,
48                                     const Standard_Real  RadiusMax,
49                                     const Standard_Real  RadiusRatio) :
50        DrawTrSurf_Drawable (Discret,Deflection, DrawMode),
51        curv(C),
52        look(aColor),
53        disporigin(DispOrigin),
54        dispcurvradius(DispCurvRadius),
55        radiusmax(RadiusMax),
56        radiusratio(RadiusRatio)
57 {
58 }
59
60
61 //=======================================================================
62 //function : DrawOn
63 //purpose  : 
64 //=======================================================================
65
66 void DrawTrSurf_Curve::DrawOn (Draw_Display& dis) const 
67 {
68   Standard_Real First = curv->FirstParameter();
69   Standard_Real Last  = curv->LastParameter();
70   Standard_Boolean firstInf = Precision::IsNegativeInfinite(First);
71   Standard_Boolean lastInf  = Precision::IsPositiveInfinite(Last);
72
73   if (firstInf || lastInf) {
74     gp_Pnt P1,P2;
75     Standard_Real delta = 1;
76     if (firstInf && lastInf) {
77       do {
78         delta *= 2;
79         First = - delta;
80         Last  =   delta;
81         curv->D0(First,P1);
82         curv->D0(Last,P2);
83       } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
84     }
85     else if (firstInf) {
86       curv->D0(Last,P2);
87       do {
88         delta *= 2;
89         First = Last - delta;
90         curv->D0(First,P1);
91       } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
92     }
93     else if (lastInf) {
94       curv->D0(First,P1);
95       do {
96         delta *= 2;
97         Last = First + delta;
98         curv->D0(Last,P2);
99       } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
100     }
101   }    
102   
103   dis.SetColor (look);
104   GeomAdaptor_Curve C(curv,First,Last);
105   DrawCurveOn(C,dis);
106
107   // mark the orientation
108   if (disporigin) {
109     Draw_Bounds = Standard_False;
110     gp_Pnt P;
111     gp_Vec V;
112     C.D1(Last,P,V);
113     gp_Pnt2d p1,p2;
114     dis.Project(P,p1);
115     P.Translate(V);
116     dis.Project(P,p2);
117     gp_Vec2d v(p1,p2);
118     if (v.Magnitude() > gp::Resolution()) {
119       Standard_Real L = 20 / dis.Zoom();
120       Standard_Real H = 10 / dis.Zoom();
121       gp_Dir2d d(v);
122       p2.SetCoord(p1.X() - L*d.X() - H*d.Y(), p1.Y() - L*d.Y() + H*d.X());
123       dis.MoveTo(p2);
124       p2.SetCoord(p1.X() - L*d.X() + H*d.Y(), p1.Y() - L*d.Y() - H*d.X());
125       dis.DrawTo(p1);
126       dis.DrawTo(p2);
127     }
128     Draw_Bounds = Standard_True;
129   }
130 // Draw the curvature Radius      
131   if (dispcurvradius && (C.GetType() != GeomAbs_Line)) {
132     Standard_Integer ii;
133     Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN);
134     TColStd_Array1OfReal TI(1,nbintv+1);
135     C.Intervals(TI,GeomAbs_CN);
136     Standard_Real Resolution = 1.0e-9, Curvature;
137     GeomLProp_CLProps LProp(curv, 2, Resolution);
138     gp_Pnt P1, P2;    
139
140     for (intrv = 1; intrv <= nbintv; intrv++) {
141         Standard_Real t = TI(intrv);
142         Standard_Real step = (TI(intrv+1) - t) / GetDiscretisation();
143         Standard_Real LRad, ratio;
144         for (ii = 1; ii <= GetDiscretisation(); ii++) {  
145           LProp.SetParameter(t);
146           if (LProp.IsTangentDefined()) {
147              Curvature = Abs(LProp.Curvature());
148              if ( Curvature >  Resolution) {
149                curv->D0(t, P1);
150                dis.MoveTo(P1);
151                LRad = 1./Curvature;
152                ratio = ( (  LRad > radiusmax) ? radiusmax/LRad : 1 );
153                ratio *= radiusratio;
154                LProp.CentreOfCurvature(P2);
155                gp_Vec V(P1, P2);
156                dis.DrawTo(P1.Translated(ratio*V));
157             }
158            }
159            t += step;
160         }
161       }
162   }
163 }
164
165
166 //=======================================================================
167 //function : Copy
168 //purpose  : 
169 //=======================================================================
170
171 Handle(Draw_Drawable3D)  DrawTrSurf_Curve::Copy()const 
172 {
173   Handle(DrawTrSurf_Curve) DC = new DrawTrSurf_Curve
174     (Handle(Geom_Curve)::DownCast(curv->Copy()),
175      look,
176      GetDiscretisation(),GetDeflection(),GetDrawMode());
177      
178   return DC;
179 }
180
181
182 //=======================================================================
183 //function : Dump
184 //purpose  : 
185 //=======================================================================
186
187 void  DrawTrSurf_Curve::Dump(Standard_OStream& S)const 
188 {
189   GeomTools_CurveSet::PrintCurve(curv,S);
190 }
191
192
193 //=======================================================================
194 //function : Whatis
195 //purpose  : 
196 //=======================================================================
197
198 void  DrawTrSurf_Curve::Whatis(Draw_Interpretor& S)const 
199 {
200   S << " a 3d curve";
201 }