0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / DrawTrSurf / DrawTrSurf_Drawable.cxx
CommitLineData
b311480e 1// Created on: 1991-07-16
2// Created by: Christophe MARION
3// Copyright (c) 1991-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
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>
7fd59977 23#include <GCPnts_UniformDeflection.hxx>
7fd59977 24#include <Geom_BezierCurve.hxx>
25#include <Geom_BSplineCurve.hxx>
42cf5bc1 26#include <GeomAdaptor_Curve.hxx>
27#include <gp_Pnt.hxx>
28#include <gp_Pnt2d.hxx>
7fd59977 29#include <Precision.hxx>
42cf5bc1 30#include <Standard_Type.hxx>
31#include <TColStd_Array1OfReal.hxx>
7fd59977 32
92efcf78 33IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Drawable,Draw_Drawable3D)
34
7fd59977 35//=======================================================================
36//function : DrawTrSurf_Drawable
37//purpose : initialise the discretisation
38//=======================================================================
7fd59977 39DrawTrSurf_Drawable::DrawTrSurf_Drawable (
40
41const Standard_Integer discret,
42const Standard_Real deflection,
43const Standard_Integer DrawMode ) :
44 myDrawMode (DrawMode),
45 myDiscret(discret),
46 myDeflection(deflection)
47{
48}
49
50//=======================================================================
51//function : DrawCurve2dOn
52//purpose : draw a 2D curve
53//=======================================================================
54
55void DrawTrSurf_Drawable::DrawCurve2dOn (Adaptor2d_Curve2d& C,
56 Draw_Display& aDisplay) const
57{
58 gp_Pnt P;
59
60 gp_Pnt2d aPoint2d,
61 *aPoint2dPtr ;
62 if (myDrawMode == 1) {
63 Standard_Real Fleche = myDeflection/aDisplay.Zoom();
64 GCPnts_UniformDeflection LineVu(C,Fleche);
65 if (LineVu.IsDone()) {
66 P = LineVu.Value(1) ;
67 aPoint2dPtr = (gp_Pnt2d *) &P ;
68 aDisplay.MoveTo(*aPoint2dPtr);
69 for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++) {
70 P = LineVu.Value(i) ;
71 aPoint2dPtr = (gp_Pnt2d *) &P ;
72 aDisplay.DrawTo(*aPoint2dPtr);
73 }
74 }
75 }
76 else {
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++) {
87 t += step;
88 C.D0(t,aPoint2d);
89 aDisplay.DrawTo(aPoint2d);
90 }
91 }
92 C.D0(TI(intrv+1),aPoint2d);
93 aDisplay.DrawTo(aPoint2d);
94 }
95 }
96}
97
98//=======================================================================
99//static function : PlotCurve
100//purpose : draw a 3D curve
101//=======================================================================
102static 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)
108{
109 Standard_Real IsoRatio = 1.001;
110 gp_Pnt Pm;
111
112 C.D0 (theFirstParam + theHalfStep, Pm);
113
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);
118 } else {
119 PlotCurve (aDisplay, C, theFirstParam, theHalfStep/2., theFirstPnt, Pm);
120 Standard_Real aLocalF = theFirstParam + theHalfStep;
121 PlotCurve (aDisplay, C, aLocalF, theHalfStep/2., Pm, theLastPnt);
122 }
123}
124//=======================================================================
125//function : DrawCurveOn
126//purpose : draw a 3D curve
127//=======================================================================
128
129void DrawTrSurf_Drawable::DrawCurveOn (Adaptor3d_Curve& C,
32ca7a51 130 Draw_Display& aDisplay) const
7fd59977 131{
132 gp_Pnt P;
32ca7a51 133 if (myDrawMode == 1)
134 {
7fd59977 135 Standard_Real Fleche = myDeflection/aDisplay.Zoom();
136 GCPnts_UniformDeflection LineVu(C,Fleche);
32ca7a51 137 if (LineVu.IsDone())
138 {
7fd59977 139 aDisplay.MoveTo(LineVu.Value(1));
32ca7a51 140 for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++)
141 {
142 aDisplay.DrawTo(LineVu.Value(i));
7fd59977 143 }
32ca7a51 144 }
7fd59977 145 }
32ca7a51 146 else
147 {
148 Standard_Integer j;
7fd59977 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);
153 aDisplay.MoveTo(P);
154 GeomAbs_CurveType CurvType = C.GetType();
155 gp_Pnt aPPnt=P, aNPnt;
156
32ca7a51 157 for (intrv = 1; intrv <= nbintv; intrv++)
158 {
7fd59977 159 Standard_Real t = TI(intrv);
160 Standard_Real step = (TI(intrv+1) - t) / myDiscret;
161
32ca7a51 162 switch (CurvType)
163 {
164 case GeomAbs_Line:
165 break;
166 case GeomAbs_Circle:
167 case GeomAbs_Ellipse:
168 for (j = 1; j < myDiscret; j++)
169 {
170 t += step;
171 C.D0(t,P);
172 aDisplay.DrawTo(P);
173 }
174 break;
175 case GeomAbs_Parabola:
176 case GeomAbs_Hyperbola:
177 case GeomAbs_BezierCurve:
178 case GeomAbs_BSplineCurve:
1aec3320 179 case GeomAbs_OffsetCurve:
32ca7a51 180 case GeomAbs_OtherCurve:
181 const Standard_Integer nIter = myDiscret/2;
182 for (j = 1; j < nIter; j++)
183 {
184 const Standard_Real t1 = t+step*2.;
185 C.D0 (t1, aNPnt);
7fd59977 186 PlotCurve (aDisplay, C, t, step, aPPnt, aNPnt);
32ca7a51 187 aPPnt = aNPnt;
188 t = t1;
189 }
190
191 break;
7fd59977 192 }
193
194 C.D0(TI(intrv+1),P);
32ca7a51 195 PlotCurve (aDisplay, C, t, step, aPPnt, P);
7fd59977 196 aDisplay.DrawTo(P);
197 }
198 }
199}
200
201
202//=======================================================================
203//function : DrawIsoCurveOn
204//purpose :
205//=======================================================================
206
207void 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
213{
214 C.Load(T,P,F,L);
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);
220 else
221 GC.Load(C.BSpline(),F,L);
222
223 DrawCurveOn(GC,dis);
224 }
225 else
226 DrawCurveOn(C,dis);
227
228}