1 /***********************************************************************
12 HISTORIQUE DES MODIFICATIONS :
13 --------------------------------
14 xx-xx-xx : xxx ; Creation.
15 21-10-96 : FMN ; Suppression LMC_COLOR fait dans OpenGl_execstruct.c
17 ************************************************************************/
19 #define G003 /* EUG 07-10-99 Degeneration mode support
22 #define IMP190602 /* GG Avoid memory leaks after creating a polyline
23 // with vertex colors primitive.
24 // Thanks to Ivan Fontaine (SAMTECH) for this improvment
27 /*----------------------------------------------------------------------*/
32 #include <OpenGl_tgl_all.hxx>
39 #include <OpenGl_cmn_varargs.hxx>
40 #include <OpenGl_telem_attri.hxx>
41 #include <OpenGl_telem_highlight.hxx>
42 #include <OpenGl_tsm.hxx>
43 #include <OpenGl_telem.hxx>
44 #include <OpenGl_telem_inquire.hxx>
45 #include <OpenGl_Memory.hxx>
48 extern int g_nDegenerateModel;
51 static TStatus PolylineDisplay( TSM_ELEM_DATA, Tint, cmn_key* );
52 static TStatus PolylineAdd( TSM_ELEM_DATA, Tint, cmn_key* );
53 static TStatus PolylineDelete( TSM_ELEM_DATA, Tint, cmn_key* );
54 static TStatus PolylinePrint( TSM_ELEM_DATA, Tint, cmn_key* );
55 static TStatus PolylineInquire( TSM_ELEM_DATA, Tint, cmn_key* );
57 /*static GLboolean lighting_mode;*/
59 static TStatus (*MtdTbl[])( TSM_ELEM_DATA, Tint, cmn_key* ) =
71 Tint num_lines; /* Number of polylines */
72 Tint num_vertices; /* Number of vertices in vertices array */
73 Tint *bounds; /* Array of number of points in each polyline */
74 tel_colour vcolours; /* vertex colour values for each vertex */
75 tel_point vertices; /* vertices array of length num_vertices */
76 IMPLEMENT_MEMORY_OPERATORS
78 typedef TEL_LINE_DATA* tel_line_data;
81 TelPolylineInitClass( TelType* el )
88 PolylineAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k )
94 for( i = 0; i < n; i++ )
96 if( k[i]->id == NUM_LINES_ID )
103 if( !(k[i]->data.ldata) )
106 for( j = 0; j < n; j++ )
108 if( k[j]->id == BOUNDS_DATA_ID )
115 p = new TEL_LINE_DATA();
116 p->num_lines = k[i]->data.ldata;
117 p->bounds = new Tint[p->num_lines];
118 memcpy( p->bounds, k[j]->data.pdata, p->num_lines*sizeof(Tint) );
121 for( i = 0; i < p->num_lines; i++ )
123 p->num_vertices += p->bounds[i];
126 for( i = 0; i < n; i++ )
130 case VERTEX_COLOUR_VALS_ID:
131 p->vcolours = new TEL_COLOUR[p->num_vertices];
132 memcpy( p->vcolours, k[i]->data.pdata, p->num_vertices*sizeof(TEL_COLOUR) );
136 p->vertices = new TEL_POINT[p->num_vertices];
137 memcpy( p->vertices, k[i]->data.pdata, p->num_vertices*sizeof(TEL_POINT) );
142 ((tsm_elem_data)(d.pdata))->pdata = p;
149 PolylineDisplay( TSM_ELEM_DATA data, Tint n, cmn_key *k )
156 d = (tel_line_data)data.pdata;
158 /* OCC11904 -- Temporarily disable environment mapping */
159 glPushAttrib(GL_ENABLE_BIT);
160 glDisable(GL_TEXTURE_1D);
161 glDisable(GL_TEXTURE_2D);
163 if( k[0]->id == TOn )
164 { /* Use highlight colours */
167 key.id = TelHighlightIndex;
168 TsmGetAttri( 1, &key );
169 if( TelGetHighlightRep( TglActiveWs, key.data.ldata, &hrep )
174 TelGetHighlightRep( TglActiveWs, 0, &hrep );
180 key.id = TelPolylineColour;
181 key.data.pdata = &colour;
182 TsmGetAttri( 1, &key );
187 glColor3fv( colour.rgb );
188 for( i = 0, j = 0, a = 0; i < d->num_lines; i++ )
190 a = j + d->bounds[i];
192 glBegin ( g_nDegenerateModel != 3 ? GL_LINE_STRIP : GL_POINTS );
194 glBegin(GL_LINE_STRIP);
197 glVertex3fv( d->vertices[j].xyz );
203 for( i = 0, j = 0, a = 0; i < d->num_lines; i++ )
205 a = j + d->bounds[i];
207 glBegin ( g_nDegenerateModel != 3 ? GL_LINE_STRIP : GL_POINTS );
209 glBegin(GL_LINE_STRIP);
213 glColor3fv( d->vcolours[j].rgb );
214 glVertex3fv( d->vertices[j].xyz );
227 PolylineDelete( TSM_ELEM_DATA data, Tint n, cmn_key *k )
229 tel_line_data p = (tel_line_data)data.pdata;
233 delete[] p->vertices;
236 delete[] p->vcolours;
248 PolylinePrint( TSM_ELEM_DATA data, Tint n, cmn_key *k )
251 tel_line_data p = (tel_line_data)data.pdata;
253 fprintf( stdout, "TelPolyline. Number of Lines: %d\n", p->num_lines );
256 fprintf( stdout, "\t\tVertex Flag : COLOUR\n" );
258 fprintf( stdout, "\t\tVertex Flag : NONE\n" );
262 fprintf( stdout, "\t\tLengths array :\n" );
263 for( i = 0; i < p->num_lines; i++ )
264 fprintf( stdout, "\t\tL[%d] %d \n", i, p->bounds[i] );
269 fprintf( stdout, "\n\t\tVertices : " );
270 for( i = 0; i < p->num_vertices; i++ )
271 fprintf( stdout, "\n\t\t v[%d] = %g %g %g", i,
272 p->vertices[i].xyz[0],
273 p->vertices[i].xyz[1],
274 p->vertices[i].xyz[2] ); }
276 fprintf( stdout, "\n" );
280 fprintf( stdout, "\n\t\tVertex Colours : " );
281 for( i = 0; i < p->num_vertices; i++ )
282 fprintf( stdout, "\n\t\t v[%d] = %g %g %g", i,
283 p->vcolours[i].rgb[0],
284 p->vcolours[i].rgb[1],
285 p->vcolours[i].rgb[2] ); }
287 fprintf( stdout, "\n\t\tVertex Colours not specified\n" );
289 fprintf( stdout, "\n" );
295 PolylineInquire( TSM_ELEM_DATA data, Tint n, cmn_key *k )
300 TStatus status = TSuccess;
302 d = (tel_line_data)data.pdata;
304 size_reqd = d->num_lines * sizeof( Tint );
305 size_reqd += ( d->num_vertices * sizeof( TEL_POINT ) );
308 size_reqd += ( d->num_vertices * sizeof( TEL_COLOUR ) );
311 for( i = 0; i < n; i++ )
315 case INQ_GET_SIZE_ID:
317 k[i]->data.ldata = size_reqd;
321 case INQ_GET_CONTENT_ID:
326 c = (tel_inq_content)k[i]->data.pdata;
327 c->act_size = size_reqd;
329 w->lineset3data.num_bounds = d->num_lines;
332 w->lineset3data.vrtflag = TEL_VTFLAG_COLOUR;
334 w->lineset3data.vrtflag = TEL_VTFLAG_NONE;
336 if( c->size >= size_reqd )
338 w->lineset3data.bounds = (Tint *)(c->buf);
339 memcpy( w->lineset3data.bounds, d->bounds, d->num_lines*sizeof(Tint) );
341 w->lineset3data.points =
342 (tel_point)(c->buf + d->num_lines * sizeof( Tint ) );
344 memcpy( w->lineset3data.points, d->vertices, d->num_vertices*sizeof(TEL_POINT) );
347 w->lineset3data.colours = (tel_colour)( c->buf +
348 d->num_lines * sizeof( Tint ) +
349 d->num_vertices * sizeof( TEL_POINT ));
350 memcpy( w->lineset3data.colours, d->vcolours, d->num_vertices*sizeof(TEL_COLOUR) );
353 w->lineset3data.colours = 0;