1 /***********************************************************************
5 File OpenGl_highlight :
12 HISTORIQUE DES MODIFICATIONS :
13 --------------------------------
14 xx-xx-xx : xxx ; Creation.
15 11-03-96 : FMN ; Correction warning compilation
16 01-04-96 : CAL ; Integration MINSK portage WNT
18 ************************************************************************/
20 /*----------------------------------------------------------------------*/
25 #include <OpenGl_tgl_all.hxx>
31 #include <OpenGl_cmn_varargs.hxx>
32 #include <OpenGl_telem.hxx>
33 #include <OpenGl_tsm_ws.hxx>
34 #include <OpenGl_telem_highlight.hxx>
35 #include <OpenGl_Memory.hxx>
37 struct TEL_HIGHLIGHT_DATA
41 IMPLEMENT_MEMORY_OPERATORS
43 typedef TEL_HIGHLIGHT_DATA* tel_highlight_data;
45 struct TEL_WS_HIGHLIGHTS
47 Tint num; /* number of highlights for a workstation */
48 Tint siz; /* size allocated */
49 TEL_HIGHLIGHT_DATA* data; /* highlight definitions for the workstation */
50 IMPLEMENT_MEMORY_OPERATORS
52 typedef TEL_WS_HIGHLIGHTS* tel_ws_highlights;
56 static tel_ws_highlights ws_hlights;
59 b_s( Tint id, tel_highlight_data tbl, Tint low, Tint high )
66 mid = low+high, mid /= 2;
67 i = id - tbl[mid].hid;
69 return i == 0 ? mid : i < 0 ? b_s( id, tbl, low, mid-1 ) :
70 b_s( id, tbl, mid+1, high );
75 lnumcomp( const void* a, const void* b )
77 return *( Tint* )a - *( Tint* )b;
82 TelSetHighlightRep( Tint Wsid, Tint hid, tel_highlight highl )
87 tel_highlight_data hptr;
90 TsmGetWSAttri( Wsid, WSHighlights, &key );
91 ws_hlights = key.pdata ; /* Obtain list of defined highlights */
93 if( !ws_hlights ) /* no highlights defined yet */
95 //cmn_memreserve( ws_hlights, 1, 0 );
96 ws_hlights = new TEL_WS_HIGHLIGHTS();
99 //cmn_memreserve( ws_hlights->data, GROW_SIZE, 0 );
100 ws_hlights->data = new TEL_HIGHLIGHT_DATA[GROW_SIZE];
104 ws_hlights->siz = GROW_SIZE;
107 key.pdata = ws_hlights;/* Set list for the workstation */
108 TsmSetWSAttri( Wsid, WSHighlights, &key );
111 else if( ws_hlights->num == ws_hlights->siz ) /* insufficient memory */
113 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)
114 ws_hlights->data = (TEL_HIGHLIGHT_DATA*)realloc( ws_hlights->data, (ws_hlights->siz
115 + GROW_SIZE)*sizeof(TEL_HIGHLIGHT_DATA) );
117 ws_hlights->data = cmn_resizemem<TEL_HIGHLIGHT_DATA>( ws_hlights->data, ws_hlights->siz
123 ws_hlights->siz += GROW_SIZE;
125 key.pdata = ws_hlights; /* Reset list for the workstation */
126 TsmSetWSAttri( Wsid, WSHighlights, &key );
129 hptr = 0; /* Locate highlight if already defined */
130 i = b_s( hid, ws_hlights->data, 0, ws_hlights->num-1 );
133 hptr = &ws_hlights->data[i]; /* highlight already defined */
134 hptr->highl = *highl; /* copy highlight definition */
137 if( !hptr ) /* new highlight */
139 hptr = &ws_hlights->data[ws_hlights->num];
140 hptr->highl = *highl; /* copy highlight definition */
141 hptr->hid = hid; /* highlights for the workstation */
142 ws_hlights->num++; /* and sort the entries */
143 qsort( ws_hlights->data, ws_hlights->num,
144 sizeof(TEL_HIGHLIGHT_DATA), lnumcomp );
153 TelGetHighlightRep( Tint Wsid, Tint hid, tel_highlight highl )
158 tel_highlight_data hptr;
161 TsmGetWSAttri( Wsid, WSHighlights, &key );
162 ws_hlights = key.pdata ; /* Obtain list of defined highlights */
165 return TFailure; /* no highlights defined */
167 hptr = 0; /* Locate highlight if already defined */
168 i = b_s( hid, ws_hlights->data, 0, ws_hlights->num-1 );
170 return TFailure; /* hid undefined */
172 hptr = &ws_hlights->data[i];
173 *highl = hptr->highl;
180 TelPrintHighlightRep( Tint Wsid, Tint hid )
185 tel_highlight_data hptr;
189 TsmGetWSAttri( Wsid, WSHighlights, &key );
190 ws_hlights = key.pdata ; /* Obtain list of defined highlights */
193 return; /* no highlights defined */
195 hptr = 0; /* Locate highlight if already defined */
196 i = b_s( hid, ws_hlights->data, 0, ws_hlights->num-1 );
199 fprintf( stdout, "\nBad Highlight %d\n", hid );
200 return; /* hid undefined */
203 hptr = &ws_hlights->data[i];
204 fprintf( stdout, "\nHighlight Id: %d", hid );
205 switch( hptr->highl.type )
208 fprintf( stdout, "\nHighlight type: TelHLColour" );
209 fprintf( stdout, "\n\tColour: %f %f %f",
210 hptr->highl.col.rgb[0],
211 hptr->highl.col.rgb[1],
212 hptr->highl.col.rgb[2] );
215 case TelHLForcedColour:
216 fprintf( stdout, "\nHighlight type: TelHLForcedColour" );
217 fprintf( stdout, "\n\tColour: %f %f %f",
218 hptr->highl.col.rgb[0],
219 hptr->highl.col.rgb[1],
220 hptr->highl.col.rgb[2] );
223 fprintf( stdout, "\n" );
229 TelDeleteHighlightsForWS( Tint wsid )
234 TsmGetWSAttri( wsid, WSHighlights, &key );
235 h = (tel_ws_highlights)key.pdata;