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 IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Drawable,Draw_Drawable3D)
35 //=======================================================================
36 //function : DrawTrSurf_Drawable
37 //purpose : initialise the discretisation
38 //=======================================================================
39 DrawTrSurf_Drawable::DrawTrSurf_Drawable (
41 const Standard_Integer discret,
42 const Standard_Real deflection,
43 const Standard_Integer DrawMode ) :
44 myDrawMode (DrawMode),
46 myDeflection(deflection)
50 //=======================================================================
51 //function : DrawCurve2dOn
52 //purpose : draw a 2D curve
53 //=======================================================================
55 void DrawTrSurf_Drawable::DrawCurve2dOn (Adaptor2d_Curve2d& C,
56 Draw_Display& aDisplay) const
62 if (myDrawMode == 1) {
63 Standard_Real Fleche = myDeflection/aDisplay.Zoom();
64 GCPnts_UniformDeflection LineVu(C,Fleche);
65 if (LineVu.IsDone()) {
67 aPoint2dPtr = (gp_Pnt2d *) &P ;
68 aDisplay.MoveTo(*aPoint2dPtr);
69 for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++) {
71 aPoint2dPtr = (gp_Pnt2d *) &P ;
72 aDisplay.DrawTo(*aPoint2dPtr);
77 Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN);
78 TColStd_Array1OfReal TI(1,nbintv+1);
79 C.Intervals(TI,GeomAbs_CN);
80 C.D0(C.FirstParameter(),aPoint2d);
81 aDisplay.MoveTo(aPoint2d);
82 for (intrv = 1; intrv <= nbintv; intrv++) {
83 if (C.GetType() != GeomAbs_Line) {
84 Standard_Real t = TI(intrv);
85 Standard_Real step = (TI(intrv+1) - t) / myDiscret;
86 for (Standard_Integer i = 1; i < myDiscret; i++) {
89 aDisplay.DrawTo(aPoint2d);
92 C.D0(TI(intrv+1),aPoint2d);
93 aDisplay.DrawTo(aPoint2d);
98 //=======================================================================
99 //static function : PlotCurve
100 //purpose : draw a 3D curve
101 //=======================================================================
102 static void PlotCurve (Draw_Display& aDisplay,
103 const Adaptor3d_Curve& C,
104 Standard_Real& theFirstParam,
105 Standard_Real theHalfStep,
106 const gp_Pnt& theFirstPnt,
107 const gp_Pnt& theLastPnt)
109 Standard_Real IsoRatio = 1.001;
112 C.D0 (theFirstParam + theHalfStep, Pm);
114 Standard_Real dfLength = theFirstPnt.Distance(theLastPnt);
115 if (dfLength < Precision::Confusion() ||
116 Pm.Distance(theFirstPnt) + Pm.Distance(theLastPnt) <= IsoRatio*dfLength) {
117 aDisplay.DrawTo (theLastPnt);
119 PlotCurve (aDisplay, C, theFirstParam, theHalfStep/2., theFirstPnt, Pm);
120 Standard_Real aLocalF = theFirstParam + theHalfStep;
121 PlotCurve (aDisplay, C, aLocalF, theHalfStep/2., Pm, theLastPnt);
124 //=======================================================================
125 //function : DrawCurveOn
126 //purpose : draw a 3D curve
127 //=======================================================================
129 void DrawTrSurf_Drawable::DrawCurveOn (Adaptor3d_Curve& C,
130 Draw_Display& aDisplay) const
135 Standard_Real Fleche = myDeflection/aDisplay.Zoom();
136 GCPnts_UniformDeflection LineVu(C,Fleche);
139 aDisplay.MoveTo(LineVu.Value(1));
140 for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++)
142 aDisplay.DrawTo(LineVu.Value(i));
149 Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN);
150 TColStd_Array1OfReal TI(1,nbintv+1);
151 C.Intervals(TI,GeomAbs_CN);
152 C.D0(C.FirstParameter(),P);
154 GeomAbs_CurveType CurvType = C.GetType();
155 gp_Pnt aPPnt=P, aNPnt;
157 for (intrv = 1; intrv <= nbintv; intrv++)
159 Standard_Real t = TI(intrv);
160 Standard_Real step = (TI(intrv+1) - t) / myDiscret;
167 case GeomAbs_Ellipse:
168 for (j = 1; j < myDiscret; j++)
175 case GeomAbs_Parabola:
176 case GeomAbs_Hyperbola:
177 case GeomAbs_BezierCurve:
178 case GeomAbs_BSplineCurve:
179 case GeomAbs_OffsetCurve:
180 case GeomAbs_OtherCurve:
181 const Standard_Integer nIter = myDiscret/2;
182 for (j = 1; j < nIter; j++)
184 const Standard_Real t1 = t+step*2.;
186 PlotCurve (aDisplay, C, t, step, aPPnt, aNPnt);
195 PlotCurve (aDisplay, C, t, step, aPPnt, P);
202 //=======================================================================
203 //function : DrawIsoCurveOn
205 //=======================================================================
207 void DrawTrSurf_Drawable::DrawIsoCurveOn(Adaptor3d_IsoCurve& C,
208 const GeomAbs_IsoType T,
209 const Standard_Real P,
210 const Standard_Real F,
211 const Standard_Real L,
212 Draw_Display& dis) const
215 if ((C.GetType() == GeomAbs_BezierCurve) ||
216 (C.GetType() == GeomAbs_BSplineCurve)) {
217 GeomAdaptor_Curve GC;
218 if (C.GetType() == GeomAbs_BezierCurve)
219 GC.Load(C.Bezier(),F,L);
221 GC.Load(C.BSpline(),F,L);