1 // Created on: 1991-07-16
2 // Created by: Christophe MARION
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <DrawTrSurf_Drawable.ixx>
24 #include <GCPnts_UniformDeflection.hxx>
26 #include <gp_Pnt2d.hxx>
27 #include <TColStd_Array1OfReal.hxx>
28 #include <GeomAdaptor_Curve.hxx>
29 #include <Geom_BezierCurve.hxx>
30 #include <Geom_BSplineCurve.hxx>
31 #include <Precision.hxx>
34 //=======================================================================
35 //function : DrawTrSurf_Drawable
36 //purpose : initialise the discretisation
37 //=======================================================================
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
133 if (myDrawMode == 1) {
134 Standard_Real Fleche = myDeflection/aDisplay.Zoom();
135 GCPnts_UniformDeflection LineVu(C,Fleche);
136 if (LineVu.IsDone()) {
137 aDisplay.MoveTo(LineVu.Value(1));
138 for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++) {
139 aDisplay.DrawTo(LineVu.Value(i));
145 Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN);
146 TColStd_Array1OfReal TI(1,nbintv+1);
147 C.Intervals(TI,GeomAbs_CN);
148 C.D0(C.FirstParameter(),P);
150 GeomAbs_CurveType CurvType = C.GetType();
151 gp_Pnt aPPnt=P, aNPnt;
153 for (intrv = 1; intrv <= nbintv; intrv++) {
154 Standard_Real t = TI(intrv);
155 Standard_Real step = (TI(intrv+1) - t) / myDiscret;
160 case GeomAbs_Circle :
161 case GeomAbs_Ellipse :
162 for (j = 1; j < myDiscret; j++) {
168 case GeomAbs_Parabola :
169 case GeomAbs_Hyperbola :
170 case GeomAbs_BezierCurve :
171 case GeomAbs_BSplineCurve :
172 case GeomAbs_OtherCurve :
173 for (j = 1; j <= myDiscret/2; j++) {
174 C.D0 (t+step*2., aNPnt);
175 PlotCurve (aDisplay, C, t, step, aPPnt, aNPnt);
189 //=======================================================================
190 //function : DrawIsoCurveOn
192 //=======================================================================
194 void DrawTrSurf_Drawable::DrawIsoCurveOn(Adaptor3d_IsoCurve& C,
195 const GeomAbs_IsoType T,
196 const Standard_Real P,
197 const Standard_Real F,
198 const Standard_Real L,
199 Draw_Display& dis) const
202 if ((C.GetType() == GeomAbs_BezierCurve) ||
203 (C.GetType() == GeomAbs_BSplineCurve)) {
204 GeomAdaptor_Curve GC;
205 if (C.GetType() == GeomAbs_BezierCurve)
206 GC.Load(C.Bezier(),F,L);
208 GC.Load(C.BSpline(),F,L);