1 // Created on: 1991-07-16
2 // Created by: Christophe MARION
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor2d_Curve2d.hxx>
19 #include <Adaptor3d_Curve.hxx>
20 #include <Adaptor3d_IsoCurve.hxx>
21 #include <Draw_Display.hxx>
22 #include <DrawTrSurf_Drawable.hxx>
23 #include <GCPnts_UniformDeflection.hxx>
24 #include <Geom_BezierCurve.hxx>
25 #include <Geom_BSplineCurve.hxx>
26 #include <GeomAdaptor_Curve.hxx>
28 #include <gp_Pnt2d.hxx>
29 #include <Precision.hxx>
30 #include <Standard_Type.hxx>
31 #include <TColStd_Array1OfReal.hxx>
33 //=======================================================================
34 //function : DrawTrSurf_Drawable
35 //purpose : initialise the discretisation
36 //=======================================================================
37 DrawTrSurf_Drawable::DrawTrSurf_Drawable (
39 const Standard_Integer discret,
40 const Standard_Real deflection,
41 const Standard_Integer DrawMode ) :
42 myDrawMode (DrawMode),
44 myDeflection(deflection)
48 //=======================================================================
49 //function : DrawCurve2dOn
50 //purpose : draw a 2D curve
51 //=======================================================================
53 void DrawTrSurf_Drawable::DrawCurve2dOn (Adaptor2d_Curve2d& C,
54 Draw_Display& aDisplay) const
60 if (myDrawMode == 1) {
61 Standard_Real Fleche = myDeflection/aDisplay.Zoom();
62 GCPnts_UniformDeflection LineVu(C,Fleche);
63 if (LineVu.IsDone()) {
65 aPoint2dPtr = (gp_Pnt2d *) &P ;
66 aDisplay.MoveTo(*aPoint2dPtr);
67 for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++) {
69 aPoint2dPtr = (gp_Pnt2d *) &P ;
70 aDisplay.DrawTo(*aPoint2dPtr);
75 Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN);
76 TColStd_Array1OfReal TI(1,nbintv+1);
77 C.Intervals(TI,GeomAbs_CN);
78 C.D0(C.FirstParameter(),aPoint2d);
79 aDisplay.MoveTo(aPoint2d);
80 for (intrv = 1; intrv <= nbintv; intrv++) {
81 if (C.GetType() != GeomAbs_Line) {
82 Standard_Real t = TI(intrv);
83 Standard_Real step = (TI(intrv+1) - t) / myDiscret;
84 for (Standard_Integer i = 1; i < myDiscret; i++) {
87 aDisplay.DrawTo(aPoint2d);
90 C.D0(TI(intrv+1),aPoint2d);
91 aDisplay.DrawTo(aPoint2d);
96 //=======================================================================
97 //static function : PlotCurve
98 //purpose : draw a 3D curve
99 //=======================================================================
100 static void PlotCurve (Draw_Display& aDisplay,
101 const Adaptor3d_Curve& C,
102 Standard_Real& theFirstParam,
103 Standard_Real theHalfStep,
104 const gp_Pnt& theFirstPnt,
105 const gp_Pnt& theLastPnt)
107 Standard_Real IsoRatio = 1.001;
110 C.D0 (theFirstParam + theHalfStep, Pm);
112 Standard_Real dfLength = theFirstPnt.Distance(theLastPnt);
113 if (dfLength < Precision::Confusion() ||
114 Pm.Distance(theFirstPnt) + Pm.Distance(theLastPnt) <= IsoRatio*dfLength) {
115 aDisplay.DrawTo (theLastPnt);
117 PlotCurve (aDisplay, C, theFirstParam, theHalfStep/2., theFirstPnt, Pm);
118 Standard_Real aLocalF = theFirstParam + theHalfStep;
119 PlotCurve (aDisplay, C, aLocalF, theHalfStep/2., Pm, theLastPnt);
122 //=======================================================================
123 //function : DrawCurveOn
124 //purpose : draw a 3D curve
125 //=======================================================================
127 void DrawTrSurf_Drawable::DrawCurveOn (Adaptor3d_Curve& C,
128 Draw_Display& aDisplay) const
133 Standard_Real Fleche = myDeflection/aDisplay.Zoom();
134 GCPnts_UniformDeflection LineVu(C,Fleche);
137 aDisplay.MoveTo(LineVu.Value(1));
138 for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++)
140 aDisplay.DrawTo(LineVu.Value(i));
147 Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN);
148 TColStd_Array1OfReal TI(1,nbintv+1);
149 C.Intervals(TI,GeomAbs_CN);
150 C.D0(C.FirstParameter(),P);
152 GeomAbs_CurveType CurvType = C.GetType();
153 gp_Pnt aPPnt=P, aNPnt;
155 for (intrv = 1; intrv <= nbintv; intrv++)
157 Standard_Real t = TI(intrv);
158 Standard_Real step = (TI(intrv+1) - t) / myDiscret;
165 case GeomAbs_Ellipse:
166 for (j = 1; j < myDiscret; j++)
173 case GeomAbs_Parabola:
174 case GeomAbs_Hyperbola:
175 case GeomAbs_BezierCurve:
176 case GeomAbs_BSplineCurve:
177 case GeomAbs_OffsetCurve:
178 case GeomAbs_OtherCurve:
179 const Standard_Integer nIter = myDiscret/2;
180 for (j = 1; j < nIter; j++)
182 const Standard_Real t1 = t+step*2.;
184 PlotCurve (aDisplay, C, t, step, aPPnt, aNPnt);
193 PlotCurve (aDisplay, C, t, step, aPPnt, P);
200 //=======================================================================
201 //function : DrawIsoCurveOn
203 //=======================================================================
205 void DrawTrSurf_Drawable::DrawIsoCurveOn(Adaptor3d_IsoCurve& C,
206 const GeomAbs_IsoType T,
207 const Standard_Real P,
208 const Standard_Real F,
209 const Standard_Real L,
210 Draw_Display& dis) const
213 if ((C.GetType() == GeomAbs_BezierCurve) ||
214 (C.GetType() == GeomAbs_BSplineCurve)) {
215 GeomAdaptor_Curve GC;
216 if (C.GetType() == GeomAbs_BezierCurve)
217 GC.Load(C.Bezier(),F,L);
219 GC.Load(C.BSpline(),F,L);