0022962: Invalid realization of reading and writing material in STEP.
[occt.git] / src / OpenGl / OpenGl_curve.cxx
1
2 #include <OpenGl_tgl_all.hxx>
3
4 #include <stddef.h>
5 #include <stdio.h>
6
7 #include <OpenGl_cmn_varargs.hxx>
8 #include <OpenGl_telem_attri.hxx>
9 #include <OpenGl_telem_highlight.hxx>
10 #include <OpenGl_tsm.hxx>
11 #include <OpenGl_telem.hxx>
12 #include <OpenGl_telem_inquire.hxx>
13
14 static  TStatus  CurveDisplay( TSM_ELEM_DATA, Tint, cmn_key* );
15 static  TStatus  CurveAdd( TSM_ELEM_DATA, Tint, cmn_key* );
16 static  TStatus  CurveDelete( TSM_ELEM_DATA, Tint, cmn_key* );
17 static  TStatus  CurvePrint( TSM_ELEM_DATA, Tint, cmn_key* );
18 static  TStatus  CurveInquire( TSM_ELEM_DATA, Tint, cmn_key* );
19
20 static  TStatus  (*MtdTbl[])( TSM_ELEM_DATA, Tint, cmn_key* ) =
21 {
22   CurveDisplay,
23   CurveDisplay,
24   CurveAdd,
25   CurveDelete,
26   CurvePrint,
27   CurveInquire
28 };
29
30 struct TEL_CURVE_DATA
31 {
32   TelCurveType type;          /* curve type : Bezier, Cardinal, BSpline */
33   Tint         num_points;
34   TEL_POINT    vertices[4];   /* vertices array */
35   IMPLEMENT_MEMORY_OPERATORS
36 };
37
38 typedef TEL_CURVE_DATA* tel_curve_data;
39
40 MtblPtr
41 TelCurveInitClass( TelType* el )
42 {
43   *el = TelCurve;
44   return MtdTbl;
45 }
46
47 static  TStatus
48 CurveAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k )
49 /* accepts the keys CURVE_TYPE_ID,
50 CURVE_VERTICES_ID */
51 {
52   Tint i, j;
53   tel_curve_data p;
54
55   /* Recherche du type de la courbe. Presence obligatoire. */
56   for( i = 0; i < n; i++ )
57   {
58     if( k[i]->id == CURVE_TYPE_ID )
59       break;
60   }
61
62   /* Type de la courbe non fourni. */
63   if( i == n )
64     return TFailure;
65
66   /* Recherche du nombre de points par courbe. Presence obligatoire. */
67   for( j = 0; j < n; j++ )
68   {
69     if( k[j]->id == CURVE_NUM_POINTS_ID )
70       break;
71   }
72
73   /* Nombre de points par courbe non fourni. */
74   if( j == n )
75     return TFailure;
76
77   /* Nombre de points par courbe ridicule */
78   if( k[j]->data.ldata < 2 )
79     return TFailure;
80
81   //cmn_memreserve( p, 1, 1 );
82   p = new TEL_CURVE_DATA();
83   p->type = (TelCurveType)k[i]->data.ldata;
84   p->num_points = (TelCurveType)k[j]->data.ldata;
85
86   for( i = 0; i < n; i++ )
87   {
88     switch( k[i]->id )
89     {
90     case CURVE_VERTICES_ID:
91       //cmn_memcpy<TEL_POINT>(p->vertices, k[i]->data.pdata, 4);
92       memcpy(p->vertices, k[i]->data.pdata, 4*sizeof(TEL_POINT));
93       break;
94     }
95   }
96
97   ((tsm_elem_data)(d.pdata))->pdata = p;
98
99   return TSuccess;
100 }
101
102
103 static  TStatus
104 CurveDisplay( TSM_ELEM_DATA data, Tint n, cmn_key *k )
105 {
106   tel_curve_data d;
107   CMN_KEY        key;
108   TEL_COLOUR     colour;
109   int            i, j;
110   GLfloat          reseau[4][3];
111
112   d = (tel_curve_data)data.pdata;
113
114   /* Mode highlight en cours */
115   if( k[0]->id == TOn )
116   {                           /* Use highlight colours */
117     TEL_HIGHLIGHT  hrep;
118
119     key.id = TelHighlightIndex;
120     TsmGetAttri( 1, &key );
121     if( TelGetHighlightRep( TglActiveWs, key.data.ldata, &hrep )
122       == TSuccess )
123       colour = hrep.col;
124     else
125     {
126       TelGetHighlightRep( TglActiveWs, 0, &hrep );
127       colour = hrep.col;
128     }
129   }
130   else
131   {
132     key.id = TelPolylineColour;
133     key.data.pdata = &colour;
134     TsmGetAttri( 1, &key );
135   }
136
137   /* Recopie des points du reseau : Pb prototypage en c ansi */
138   for( i = 0; i < 4; i++ )
139     for( j = 0; i < 3; i++ )
140       reseau[i][j] = d->vertices[i].xyz[j];
141
142   /* Determination du type de courbe */
143   switch( d->type )
144   {
145   case TelBezierCurve:
146     /* OGLXXX curvebasis: see man pages
147     glMap1();glMap2();glMapGrid();
148     */
149     break;
150   case TelCardinalCurve:
151     /* OGLXXX curvebasis: see man pages
152     glMap1();glMap2();glMapGrid();
153     */
154     break;
155   case TelBSplineCurve:
156     /* OGLXXX curvebasis: see man pages
157     glMap1();glMap2();glMapGrid();
158     */
159     break;
160   default:
161     printf( "\n\tCurveDisplay : INVALID KEY" );
162     break;
163   }
164
165   /* Determination du type de courbe */
166   /* OGLXXX curveprecision:see man pages
167   glMap1();glMap2();glMapGrid();
168   */
169
170   /* Couleur */
171   glColor3fv( colour.rgb );
172   /* OGLXXX replace u with domain coordinate
173   glEvalCoord1f( u );
174   */
175
176   return TSuccess;
177 }
178
179
180 static  TStatus
181 CurveDelete( TSM_ELEM_DATA data, Tint n, cmn_key *k )
182 {
183   tel_curve_data p = (tel_curve_data)data.pdata;
184   //cmn_freemem( p );
185   delete p;
186
187   return TSuccess;
188 }
189
190
191
192
193 static  TStatus
194 CurvePrint( TSM_ELEM_DATA data, Tint n, cmn_key *k )
195 {
196   Tint           i;
197   tel_curve_data  p = (tel_curve_data)data.pdata;
198
199   fprintf( stdout, "TelCurve. \n" );
200
201   fprintf( stdout, "\n\t\tVertices : " );
202   for( i = 0; i < 4; i++ )
203     fprintf( stdout, "\n\t\t v[%d] = %g %g %g", i, p->vertices[i].xyz[0],
204     p->vertices[i].xyz[1],
205     p->vertices[i].xyz[2] );
206
207   fprintf( stdout, "\n" );
208
209   return TSuccess;
210 }
211
212 static TStatus
213 CurveInquire( TSM_ELEM_DATA data, Tint n, cmn_key *k )
214 {
215   Tint           i;
216   tel_curve_data d;
217   Tint           size_reqd=0;
218   TStatus        status = TSuccess;
219
220   d = (tel_curve_data)data.pdata;
221
222   size_reqd  = sizeof( TEL_CURVE_DATA );
223
224   for( i = 0; i < n; i++ )
225   {
226     switch( k[i]->id )
227     {
228     case INQ_GET_SIZE_ID:
229       {
230         k[i]->data.ldata = size_reqd;
231         break;
232       }
233
234     case INQ_GET_CONTENT_ID:
235       {
236         TEL_INQ_CONTENT *c;
237         Teldata         *w;
238
239         c = (tel_inq_content)k[i]->data.pdata;
240         c->act_size = size_reqd;
241         w = c->data;
242
243         if( c->size >= size_reqd )
244         {
245           w->pts3 = (tel_point) c->buf;
246           //cmn_memcpy<TEL_POINT>( w->pts3, d->vertices, 4 );
247           memcpy( w->pts3, d->vertices, 4*sizeof(TEL_POINT) );
248           status = TSuccess;
249         }
250         else
251           status = TFailure;
252         break;
253       }
254     }
255   }
256   return status;
257 }