OCC22354 Bug in Overlay Text rendering
[occt.git] / src / OpenGl / OpenGl_mrkr.cxx
1 /***********************************************************************
2
3 FONCTION :
4 ----------
5 File OpenGl_mrkr :
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 08-07-96 : BGN ; (PRO4768) suppression du cas particulier TEL_PM_DOT.
18 21-10-96 : FMN ; Suppression LMC_COLOR fait dans OpenGl_execstruct.c
19 19-10-96 : CAL ; Restauration du cas particulier TEL_PM_DOT mais
20 avec la correction sur la mise a jour du pointSize.
21
22 ************************************************************************/
23
24 /*----------------------------------------------------------------------*/
25 /*
26 * Includes
27 */ 
28
29
30 #include <OpenGl_tgl_all.hxx>
31
32 #include <stddef.h>
33 #include <stdio.h>
34 #include <string.h>
35
36 #include <GL/gl.h>
37 #include <GL/glu.h>
38
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
46 extern GLuint GetListIndex(int);
47
48
49 static  TStatus  MarkerDisplay( TSM_ELEM_DATA, Tint, cmn_key* );
50 static  TStatus  MarkerAdd( TSM_ELEM_DATA, Tint, cmn_key* );
51 static  TStatus  MarkerDelete( TSM_ELEM_DATA, Tint, cmn_key* );
52 static  TStatus  MarkerPrint( TSM_ELEM_DATA, Tint, cmn_key* );
53 static  TStatus  MarkerInquire( TSM_ELEM_DATA, Tint, cmn_key* );
54
55 /*static  GLboolean         lighting_mode;*/
56
57 static  TStatus  (*MtdTbl[])( TSM_ELEM_DATA, Tint, cmn_key* ) =
58 {
59   MarkerDisplay,             /* PickTraverse */
60     MarkerDisplay,
61     MarkerAdd,
62     MarkerDelete,
63     MarkerPrint,
64     MarkerInquire
65 };
66
67
68 MtblPtr
69 TelMarkerInitClass( TelType *el )
70 {
71   *el = TelMarker;
72   return MtdTbl;
73 }
74
75 static  TStatus
76 MarkerAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k )
77 {
78   tel_point data = new TEL_POINT;
79
80   if( !data )
81     return TFailure;
82
83   *data = *(tel_point)(k[0]->data.pdata);
84
85   ((tsm_elem_data)(d.pdata))->pdata = data;
86
87   return TSuccess;
88 }
89
90 extern GLuint markerBase;
91 static  TStatus
92 MarkerDisplay( TSM_ELEM_DATA data, Tint n, cmn_key *k )
93 {
94   tel_point  p;
95   CMN_KEY    key1, key2, key3;
96   TEL_COLOUR colour;
97   Tchar      *str;
98
99   key1.id         = TelPolymarkerColour;
100   key1.data.pdata = &colour;
101
102   key2.id = TelPolymarkerType;
103   key3.id = TelPolymarkerSize;
104
105   TsmGetAttri( 3, &key1, &key2, &key3 );
106
107   if( k[0]->id == TOn )
108   {                          /* Use highlight colours */
109     TEL_HIGHLIGHT  hrep;
110
111     key1.id = TelHighlightIndex;
112     TsmGetAttri( 1, &key1 );
113     if( TelGetHighlightRep( TglActiveWs, key1.data.ldata, &hrep )
114       == TSuccess )
115       colour = hrep.col;
116     else
117     {
118       TelGetHighlightRep( TglActiveWs, 0, &hrep );
119       colour = hrep.col;
120     }
121   }
122
123   glColor3fv( colour.rgb );
124   p = (tel_point)data.pdata;
125   if( key2.data.ldata == TEL_PM_DOT )
126   {
127     glPointSize( key3.data.fdata );
128     glBegin( GL_POINTS );
129     glVertex3fv( p->xyz );
130     glEnd();
131   }
132   else
133   {
134     GLint mode;
135     glGetIntegerv( GL_RENDER_MODE, &mode );
136     if( key2.data.ldata == TEL_PM_USERDEFINED )
137     {       
138       glRasterPos3f( (GLfloat)(p->xyz[0]),  
139         (GLfloat)(p->xyz[1]),
140         (GLfloat)(p->xyz[2]) );
141       glCallList( GetListIndex( (int)key3.data.fdata ) );       
142     }
143     else
144     {
145       str = TelGetStringForPM( key2.data.ldata, key3.data.fdata );
146       glRasterPos3f( (GLfloat)(p->xyz[0]),  (GLfloat)(p->xyz[1]),
147         (GLfloat)(p->xyz[2]) );
148       glListBase(markerBase);
149       glCallLists(strlen( (char*)str ), GL_UNSIGNED_BYTE, (GLubyte *) str );
150     }
151
152     if( mode==GL_FEEDBACK )
153     {
154       glBegin( GL_POINTS );
155       glVertex3f( p->xyz[0], p->xyz[1], p->xyz[2] );
156       glEnd();
157       /* it is necessary to indicate end of marker information*/
158     }
159   }
160
161   return TSuccess;
162 }
163
164
165 static  TStatus
166 MarkerDelete( TSM_ELEM_DATA data, Tint n, cmn_key *k )
167 {
168   if (data.pdata)
169     delete data.pdata;
170   return TSuccess;
171 }
172
173
174
175
176 static  TStatus
177 MarkerPrint( TSM_ELEM_DATA data, Tint n, cmn_key *k )
178 {
179   tel_point p;
180
181   p = (tel_point)data.pdata;
182
183   fprintf( stdout, "TelMarker. Value = %g, %g, %g\n",
184     p->xyz[0], p->xyz[1], p->xyz[2] );
185   fprintf( stdout, "\n" );
186
187   return TSuccess;
188 }
189
190
191 static TStatus
192 MarkerInquire( TSM_ELEM_DATA data, Tint n, cmn_key *k )
193 {
194   Tint          i;
195   tel_point     d;
196   Tint          size_reqd=0;
197   TStatus       status = TSuccess;
198
199   d = (tel_point)data.pdata;
200
201   size_reqd = sizeof( TEL_POINT );
202
203   for( i = 0; i < n; i++ )
204   {
205     switch( k[i]->id )
206     {
207     case INQ_GET_SIZE_ID:
208       {
209         k[i]->data.ldata = size_reqd;
210         break;
211       }
212
213     case INQ_GET_CONTENT_ID:
214       {
215         TEL_INQ_CONTENT *c;
216         Teldata         *w;
217
218         c = (tel_inq_content)k[i]->data.pdata;
219         c->act_size = size_reqd;
220         w = c->data;
221
222         if( c->size >= size_reqd )
223         {
224           w->pts3 = (tel_point)(c->buf);
225           *(w->pts3) = *d;
226           status = TSuccess;
227         }
228         else
229           status = TFailure;
230         break;
231       }
232     }
233   }
234   return status;
235 }