summaryrefslogtreecommitdiff
path: root/src/DrawTrSurf/DrawTrSurf_Drawable.cxx
blob: 3ffcbf129713453e2ad754f82dd9eab58e1b5c77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// File:	DrawTrSurf_Drawable.cxx
// Created:	Tue Jul 16 09:22:44 1991
// Author:	Christophe MARION
//		<cma@sdsun1>


#include <DrawTrSurf_Drawable.ixx>
#include <GCPnts_UniformDeflection.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Precision.hxx>


//=======================================================================
//function : DrawTrSurf_Drawable
//purpose  : initialise the discretisation
//=======================================================================

DrawTrSurf_Drawable::DrawTrSurf_Drawable (

const Standard_Integer discret,
const Standard_Real    deflection,
const Standard_Integer DrawMode ) :
       myDrawMode (DrawMode),
       myDiscret(discret),
       myDeflection(deflection)
{
}

//=======================================================================
//function : DrawCurve2dOn
//purpose  : draw a 2D curve
//=======================================================================

void DrawTrSurf_Drawable::DrawCurve2dOn (Adaptor2d_Curve2d&   C, 
					 Draw_Display& aDisplay) const
{
  gp_Pnt P;
  
  gp_Pnt2d aPoint2d,
  *aPoint2dPtr ;
  if (myDrawMode == 1) {
    Standard_Real Fleche = myDeflection/aDisplay.Zoom();
    GCPnts_UniformDeflection LineVu(C,Fleche);
    if (LineVu.IsDone()) {
      P = LineVu.Value(1) ;
      aPoint2dPtr = (gp_Pnt2d *) &P ;
      aDisplay.MoveTo(*aPoint2dPtr);
      for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++) {
        P = LineVu.Value(i) ;
        aPoint2dPtr = (gp_Pnt2d *) &P ;
	aDisplay.DrawTo(*aPoint2dPtr);
      }
    }  
  }
  else {
    Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN);
    TColStd_Array1OfReal TI(1,nbintv+1);
    C.Intervals(TI,GeomAbs_CN);
    C.D0(C.FirstParameter(),aPoint2d);
    aDisplay.MoveTo(aPoint2d);
    for (intrv = 1; intrv <= nbintv; intrv++) {
      if (C.GetType() != GeomAbs_Line) {
	Standard_Real t = TI(intrv);
	Standard_Real step = (TI(intrv+1) - t) / myDiscret;
	for (Standard_Integer i = 1; i < myDiscret; i++) {
	  t += step;
	  C.D0(t,aPoint2d);
	  aDisplay.DrawTo(aPoint2d);
	}
      }
      C.D0(TI(intrv+1),aPoint2d);
      aDisplay.DrawTo(aPoint2d);
    }
  }
}

//=======================================================================
//static function : PlotCurve
//purpose  : draw a 3D curve
//=======================================================================
static void PlotCurve (Draw_Display& aDisplay,
		       const Adaptor3d_Curve& C, 
		       Standard_Real& theFirstParam, 
		       Standard_Real  theHalfStep,
		       const gp_Pnt&  theFirstPnt,
		       const gp_Pnt&  theLastPnt)
{
  Standard_Real IsoRatio = 1.001;
  gp_Pnt Pm;

  C.D0 (theFirstParam + theHalfStep, Pm);
  
  Standard_Real dfLength = theFirstPnt.Distance(theLastPnt);
  if (dfLength < Precision::Confusion() || 
      Pm.Distance(theFirstPnt) + Pm.Distance(theLastPnt) <= IsoRatio*dfLength) {
    aDisplay.DrawTo (theLastPnt);
  } else {
    PlotCurve (aDisplay, C, theFirstParam, theHalfStep/2., theFirstPnt, Pm);
    Standard_Real aLocalF = theFirstParam + theHalfStep;
    PlotCurve (aDisplay, C, aLocalF, theHalfStep/2., Pm, theLastPnt);
  }
}
//=======================================================================
//function : DrawCurveOn
//purpose  : draw a 3D curve
//=======================================================================

void DrawTrSurf_Drawable::DrawCurveOn (Adaptor3d_Curve&   C, 
				       Draw_Display& aDisplay) const
{
  gp_Pnt P;
  if (myDrawMode == 1) {
    Standard_Real Fleche = myDeflection/aDisplay.Zoom();
    GCPnts_UniformDeflection LineVu(C,Fleche);
    if (LineVu.IsDone()) {
      aDisplay.MoveTo(LineVu.Value(1));
      for (Standard_Integer i = 2; i <= LineVu.NbPoints(); i++) {
	aDisplay.DrawTo(LineVu.Value(i));
      }
    }  
  }
  else {
    Standard_Real j;
    Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN);
    TColStd_Array1OfReal TI(1,nbintv+1);
    C.Intervals(TI,GeomAbs_CN);
    C.D0(C.FirstParameter(),P);
    aDisplay.MoveTo(P);
    GeomAbs_CurveType CurvType = C.GetType();
    gp_Pnt aPPnt=P, aNPnt;

    for (intrv = 1; intrv <= nbintv; intrv++) {
      Standard_Real t = TI(intrv);
      Standard_Real step = (TI(intrv+1) - t) / myDiscret;

      switch (CurvType) {
      case GeomAbs_Line :
	break;
      case GeomAbs_Circle :
      case GeomAbs_Ellipse :
	for (j = 1; j < myDiscret; j++) {
	  t += step;
	  C.D0(t,P);
	  aDisplay.DrawTo(P);
	}
	break;
      case GeomAbs_Parabola :
      case GeomAbs_Hyperbola :
      case GeomAbs_BezierCurve :
      case GeomAbs_BSplineCurve :
      case GeomAbs_OtherCurve :
	for (j = 1; j <= myDiscret/2; j++) {
	  C.D0 (t+step*2., aNPnt);
          PlotCurve (aDisplay, C, t, step, aPPnt, aNPnt);
	  aPPnt = aNPnt;
	  t += step*2.;
	}
	break;
      }

      C.D0(TI(intrv+1),P);
      aDisplay.DrawTo(P);
    }
  }
}


//=======================================================================
//function : DrawIsoCurveOn
//purpose  : 
//=======================================================================

void DrawTrSurf_Drawable::DrawIsoCurveOn(Adaptor3d_IsoCurve& C,
					 const GeomAbs_IsoType T,
					 const Standard_Real P,
					 const Standard_Real F,
					 const Standard_Real L,
					 Draw_Display& dis) const 
{
  C.Load(T,P,F,L);
  if ((C.GetType() == GeomAbs_BezierCurve) || 
      (C.GetType() == GeomAbs_BSplineCurve)) {
    GeomAdaptor_Curve GC;
    if (C.GetType() == GeomAbs_BezierCurve) 
      GC.Load(C.Bezier(),F,L);
    else
      GC.Load(C.BSpline(),F,L);
    
    DrawCurveOn(GC,dis);
  }
  else
    DrawCurveOn(C,dis);
  
}