7fd59977 |
1 | /*********************************************************************** |
2 | |
3 | FONCTION : |
4 | ---------- |
5 | File OpenGl_highlight : |
6 | |
7 | |
8 | REMARQUES: |
9 | ---------- |
10 | |
11 | |
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 |
17 | |
18 | ************************************************************************/ |
19 | |
20 | /*----------------------------------------------------------------------*/ |
21 | /* |
22 | * Includes |
23 | */ |
24 | |
25 | #include <OpenGl_tgl_all.hxx> |
26 | |
27 | #include <stdio.h> |
28 | #include <stddef.h> |
29 | #include <stdlib.h> |
30 | |
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> |
36 | |
37 | struct TEL_HIGHLIGHT_DATA |
38 | { |
39 | Tint hid; |
40 | TEL_HIGHLIGHT highl; |
41 | IMPLEMENT_MEMORY_OPERATORS |
42 | }; |
43 | typedef TEL_HIGHLIGHT_DATA* tel_highlight_data; |
44 | |
45 | struct TEL_WS_HIGHLIGHTS |
46 | { |
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 |
51 | }; |
52 | typedef TEL_WS_HIGHLIGHTS* tel_ws_highlights; |
53 | |
54 | #define GROW_SIZE 25 |
55 | |
56 | static tel_ws_highlights ws_hlights; |
57 | |
58 | static Tint |
59 | b_s( Tint id, tel_highlight_data tbl, Tint low, Tint high ) |
60 | { |
61 | register Tint mid, i; |
62 | |
63 | if( low > high ) |
64 | return -1; |
65 | |
66 | mid = low+high, mid /= 2; |
67 | i = id - tbl[mid].hid; |
68 | |
69 | return i == 0 ? mid : i < 0 ? b_s( id, tbl, low, mid-1 ) : |
70 | b_s( id, tbl, mid+1, high ); |
71 | } |
72 | |
73 | |
74 | static int |
75 | lnumcomp( const void* a, const void* b ) |
76 | { |
77 | return *( Tint* )a - *( Tint* )b; |
78 | } |
79 | |
80 | |
81 | TStatus |
82 | TelSetHighlightRep( Tint Wsid, Tint hid, tel_highlight highl ) |
83 | { |
84 | #if 0 |
85 | CMN_KEY_DATA key; |
86 | #endif |
87 | tel_highlight_data hptr; |
88 | register Tint i; |
89 | #if 0 |
90 | TsmGetWSAttri( Wsid, WSHighlights, &key ); |
91 | ws_hlights = key.pdata ; /* Obtain list of defined highlights */ |
92 | #endif |
93 | if( !ws_hlights ) /* no highlights defined yet */ |
94 | { /* allocate */ |
95 | //cmn_memreserve( ws_hlights, 1, 0 ); |
96 | ws_hlights = new TEL_WS_HIGHLIGHTS(); |
97 | if( !ws_hlights ) |
98 | return TFailure; |
99 | //cmn_memreserve( ws_hlights->data, GROW_SIZE, 0 ); |
100 | ws_hlights->data = new TEL_HIGHLIGHT_DATA[GROW_SIZE]; |
101 | if( !ws_hlights ) |
102 | return TFailure; |
103 | |
104 | ws_hlights->siz = GROW_SIZE; |
105 | ws_hlights->num = 0; |
106 | #if 0 |
107 | key.pdata = ws_hlights;/* Set list for the workstation */ |
108 | TsmSetWSAttri( Wsid, WSHighlights, &key ); |
109 | #endif |
110 | } |
111 | else if( ws_hlights->num == ws_hlights->siz ) /* insufficient memory */ |
112 | { /* realloc */ |
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) ); |
116 | #else |
117 | ws_hlights->data = cmn_resizemem<TEL_HIGHLIGHT_DATA>( ws_hlights->data, ws_hlights->siz |
118 | + GROW_SIZE ); |
119 | #endif |
120 | if( !ws_hlights ) |
121 | return TFailure; |
122 | |
123 | ws_hlights->siz += GROW_SIZE; |
124 | #if 0 |
125 | key.pdata = ws_hlights; /* Reset list for the workstation */ |
126 | TsmSetWSAttri( Wsid, WSHighlights, &key ); |
127 | #endif |
128 | } |
129 | hptr = 0; /* Locate highlight if already defined */ |
130 | i = b_s( hid, ws_hlights->data, 0, ws_hlights->num-1 ); |
131 | if( i != -1 ) |
132 | { |
133 | hptr = &ws_hlights->data[i]; /* highlight already defined */ |
134 | hptr->highl = *highl; /* copy highlight definition */ |
135 | } |
136 | |
137 | if( !hptr ) /* new highlight */ |
138 | { |
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 ); |
145 | } |
146 | |
147 | |
148 | return TSuccess; |
149 | } |
150 | |
151 | |
152 | TStatus |
153 | TelGetHighlightRep( Tint Wsid, Tint hid, tel_highlight highl ) |
154 | { |
155 | #if 0 |
156 | CMN_KEY_DATA key; |
157 | #endif |
158 | tel_highlight_data hptr; |
159 | register Tint i; |
160 | #if 0 |
161 | TsmGetWSAttri( Wsid, WSHighlights, &key ); |
162 | ws_hlights = key.pdata ; /* Obtain list of defined highlights */ |
163 | #endif |
164 | if( !ws_hlights ) |
165 | return TFailure; /* no highlights defined */ |
166 | |
167 | hptr = 0; /* Locate highlight if already defined */ |
168 | i = b_s( hid, ws_hlights->data, 0, ws_hlights->num-1 ); |
169 | if( i == -1 ) |
170 | return TFailure; /* hid undefined */ |
171 | |
172 | hptr = &ws_hlights->data[i]; |
173 | *highl = hptr->highl; |
174 | |
175 | return TSuccess; |
176 | } |
177 | |
178 | |
179 | void |
180 | TelPrintHighlightRep( Tint Wsid, Tint hid ) |
181 | { |
182 | #if 0 |
183 | CMN_KEY_DATA key; |
184 | #endif |
185 | tel_highlight_data hptr; |
186 | register Tint i; |
187 | |
188 | #if 0 |
189 | TsmGetWSAttri( Wsid, WSHighlights, &key ); |
190 | ws_hlights = key.pdata ; /* Obtain list of defined highlights */ |
191 | #endif |
192 | if( !ws_hlights ) |
193 | return; /* no highlights defined */ |
194 | |
195 | hptr = 0; /* Locate highlight if already defined */ |
196 | i = b_s( hid, ws_hlights->data, 0, ws_hlights->num-1 ); |
197 | if( i == -1 ) |
198 | { |
199 | fprintf( stdout, "\nBad Highlight %d\n", hid ); |
200 | return; /* hid undefined */ |
201 | } |
202 | |
203 | hptr = &ws_hlights->data[i]; |
204 | fprintf( stdout, "\nHighlight Id: %d", hid ); |
205 | switch( hptr->highl.type ) |
206 | { |
207 | case TelHLColour: |
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] ); |
213 | break; |
214 | |
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] ); |
221 | break; |
222 | } |
223 | fprintf( stdout, "\n" ); |
224 | |
225 | return; |
226 | } |
227 | |
228 | TStatus |
229 | TelDeleteHighlightsForWS( Tint wsid ) |
230 | { |
231 | CMN_KEY_DATA key; |
232 | tel_ws_highlights h; |
233 | |
234 | TsmGetWSAttri( wsid, WSHighlights, &key ); |
235 | h = (tel_ws_highlights)key.pdata; |
236 | |
237 | if( !h ) |
238 | return TSuccess; |
239 | |
240 | //cmn_freemem( h ); |
241 | if ( h->data ) |
242 | delete[] h->data; |
243 | delete h; |
244 | return TSuccess; |
245 | } |