OCC22354 Bug in Overlay Text rendering
[occt.git] / src / OpenGl / OpenGl_togl_markercontextgroup.cxx
1 /***********************************************************************
2
3 FONCTION :
4 ----------
5 File OpenGl_togl_markercontextgroup.c :
6
7
8 REMARQUES:
9 ---------- 
10
11 HISTORIQUE DES MODIFICATIONS   :
12 --------------------------------
13 xx-xx-xx : xxx ; Creation.
14 03-03-98 : CAL ; Modification des structures CALL_DEF_GROUP et STRUCTURE
15
16 ************************************************************************/
17
18
19 /*----------------------------------------------------------------------*/
20 /*
21 * Includes
22 */ 
23
24 #include <OpenGl_tgl_all.hxx>
25 #include <InterfaceGraphic_Graphic3d.hxx>
26 #include <OpenGl_context.hxx>
27 #include <OpenGl_tgl.hxx>
28 #include <OpenGl_tgl_funcs.hxx>
29 #include <OpenGl_tgl_subrs.hxx>
30 #include <OpenGl_tgl_utilgr.hxx>
31
32 /*----------------------------------------------------------------------*/
33
34 /*--------------------------------generate USERDEFINED marker--------begin-------*/
35 #ifdef WNT
36 #include <windows.h>
37 #endif
38
39 #include <GL/gl.h>
40 #include <GL/glu.h>
41
42 #ifdef HAVE_CONFIG_H
43 #include <config.h>
44 #endif
45 #ifdef HAVE_STDLIB_H
46 #include <stdlib.h>
47 #endif
48 #if defined(HAVE_MALLOC_H) || defined(WNT)
49 #include <malloc.h>
50 #endif
51
52 typedef struct
53 {
54   int*      IdList;
55   GLuint*   DisplayIdList;
56   int       Quantity; 
57 } UserDefineMarkerStruct;
58
59 static UserDefineMarkerStruct UDMS_Marker = { NULL, NULL, 0 };
60
61 int EXPORT GenerateMarkerBitmap( int theId, unsigned int theWidth, unsigned int theHeight, unsigned char* theArray )
62 {
63   int i = 0;
64   int anIndex = -1;
65   GLint w, h, size, k, l;
66
67   for( ; i < UDMS_Marker.Quantity; i++ )
68   {
69     if( UDMS_Marker.IdList[i] == theId )
70     {
71       anIndex = i;
72       glDeleteLists( UDMS_Marker.DisplayIdList[i], 1 ); 
73       if ( glGetError() != GL_NO_ERROR ) 
74         return -1;
75       break;
76     } 
77   }
78   if( anIndex == -1 )
79   {
80     anIndex = UDMS_Marker.Quantity;
81     if( anIndex == 0 )
82     {
83       UDMS_Marker.IdList = (int*)malloc( sizeof( int ) );
84       UDMS_Marker.DisplayIdList = (GLuint*)malloc( sizeof( GLuint ) );
85     }
86     else
87     {
88       UDMS_Marker.IdList = (int*) realloc( UDMS_Marker.IdList, (UDMS_Marker.Quantity + 1)*sizeof( int ) );
89       UDMS_Marker.DisplayIdList = (GLuint*) realloc( UDMS_Marker.DisplayIdList, (UDMS_Marker.Quantity + 1)*sizeof( GLuint ) );
90     }
91     UDMS_Marker.Quantity++;    
92   } 
93
94   UDMS_Marker.IdList[anIndex] = theId;
95   UDMS_Marker.DisplayIdList[anIndex] = glGenLists( 1 );
96   glNewList( UDMS_Marker.DisplayIdList[anIndex], GL_COMPILE );
97
98   w = ( GLsizei ) theWidth;
99   h = ( GLsizei ) theHeight;
100   glBitmap( w, h,
101     ( float )theWidth / ( float )2.0,
102     ( float )theHeight / ( float )2.0,
103     ( float )30.0, ( float )30.0, 
104     ( GLubyte* )theArray );
105
106   glEndList();
107
108   return 0;
109 }
110
111 GLuint EXPORT GetListIndex( int theId )
112 {
113   int i = 0;
114   for( ; i < UDMS_Marker.Quantity; i++ )
115   {
116     if( UDMS_Marker.IdList[i] == theId )
117       return UDMS_Marker.DisplayIdList[i];
118   }
119   return -1;
120 }
121
122 /*--------------------------------generate USERDEFINED marker---------end--------*/
123
124
125 void EXPORT
126 call_togl_markercontextgroup
127 (
128  CALL_DEF_GROUP * agroup,
129  int noinsert
130  )
131 {
132   /* for the group */
133   Tfloat        markr, markg, markb;
134   Tint        markertype;
135   Tfloat        markerscale;
136
137   /* for the structure */
138   Tfloat        Markr, Markg, Markb;
139   Tint        Markertype;
140   Tfloat        Markerscale;
141
142   /*
143   * Si le groupe est ouvert cela signifie que BeginPrimitives
144   * a ete utilise.
145   * Dans le cas des markers composes, il faut refermer temporairement
146   * le groupe pour eviter des insertions d'attributs aleatoires.
147   */
148   if (agroup->IsOpen) call_togl_closegroup (agroup);
149
150   if( agroup->ContextMarker.IsDef )
151   {
152     markr = agroup->ContextMarker.Color.r;
153     markg = agroup->ContextMarker.Color.g;
154     markb = agroup->ContextMarker.Color.b;
155     markertype = CALL_PHIGS_MARKER_CROSS;
156     switch( agroup->ContextMarker.MarkerType )
157     {
158     case 0 : /* Aspect_TOM_POINT */
159       markertype = CALL_PHIGS_MARKER_DOT;
160       break;
161     case 1 : /* Aspect_TOM_PLUS */
162       markertype = CALL_PHIGS_MARKER_PLUS;
163       break;
164     case 2 : /* Aspect_TOM_STAR */
165       markertype = CALL_PHIGS_MARKER_ASTERISK;
166       break;
167     case 3 : /* Aspect_TOM_O */
168       markertype = CALL_PHIGS_MARKER_CIRCLE;
169       break;
170     case 4 : /* Aspect_TOM_X */
171       markertype = CALL_PHIGS_MARKER_CROSS;
172       break;
173     case 13 : /* Aspect_TOM_USERDEFINED */
174       markertype = CALL_PHIGS_MARKER_USER_DEFINED;
175       break;
176     default :
177       break;
178     }
179     markerscale = (Tfloat)agroup->ContextMarker.Scale;
180
181     Markr = agroup->Struct->ContextMarker.Color.r;
182     Markg = agroup->Struct->ContextMarker.Color.g;
183     Markb = agroup->Struct->ContextMarker.Color.b;
184     Markertype = CALL_PHIGS_MARKER_CROSS;
185     switch( agroup->Struct->ContextMarker.MarkerType )
186     {
187     case 0 : /* Aspect_TOM_POINT */
188       Markertype = CALL_PHIGS_MARKER_DOT;
189       break;
190     case 1 : /* Aspect_TOM_PLUS */
191       Markertype = CALL_PHIGS_MARKER_PLUS;
192       break;
193     case 2 : /* Aspect_TOM_STAR */
194       Markertype = CALL_PHIGS_MARKER_ASTERISK;
195       break;
196     case 3 : /* Aspect_TOM_O */
197       Markertype = CALL_PHIGS_MARKER_CIRCLE;
198       break;
199     case 4 : /* Aspect_TOM_X */
200       Markertype = CALL_PHIGS_MARKER_CROSS;
201       break;
202     case 13 : /* Aspect_TOM_USERDEFINED*/
203       markertype = CALL_PHIGS_MARKER_USER_DEFINED;
204       break;
205     default :
206       break;
207     }
208     Markerscale = (Tfloat)agroup->Struct->ContextMarker.Scale;
209
210     if( noinsert )
211     {
212       if( agroup->ContextMarker.IsSet )
213         call_func_set_edit_mode( CALL_PHIGS_EDIT_REPLACE );
214       else
215         call_func_set_edit_mode( CALL_PHIGS_EDIT_INSERT );
216       call_func_open_struct( agroup->Struct->Id );
217
218       call_func_set_elem_ptr( 0 );
219       call_func_set_elem_ptr_label( agroup->LabelBegin );
220       if( agroup->PickId.IsSet )
221         call_func_offset_elem_ptr( 1 );
222       if( agroup->ContextLine.IsSet )
223         call_func_offset_elem_ptr( CALL_DEF_CONTEXTLINE_SIZE );
224       if( agroup->ContextFillArea.IsSet )
225         call_func_offset_elem_ptr( CALL_DEF_CONTEXTFILLAREA_SIZE );
226       if( agroup->ContextMarker.IsSet )
227         call_func_offset_elem_ptr( 1 );
228       call_subr_set_marker_colr( markr, markg, markb );
229       if( agroup->ContextMarker.IsSet )
230         call_func_offset_elem_ptr( 1 );
231       call_func_set_marker_type( markertype );
232       if( agroup->ContextMarker.IsSet )
233         call_func_offset_elem_ptr( 1 );
234       call_func_set_marker_size( markerscale );
235
236       call_func_set_elem_ptr_label( agroup->LabelEnd );
237       call_func_offset_elem_ptr(-call_util_context_group_place(agroup)-1);
238       if( agroup->ContextLine.IsSet )
239         call_func_offset_elem_ptr( CALL_DEF_CONTEXTLINE_SIZE );
240       if( agroup->ContextFillArea.IsSet )
241         call_func_offset_elem_ptr( CALL_DEF_CONTEXTFILLAREA_SIZE );
242       if( agroup->ContextMarker.IsSet )
243         call_func_offset_elem_ptr( 1 );
244       call_subr_set_marker_colr( Markr, Markg, Markb );
245       if( agroup->ContextMarker.IsSet )
246         call_func_offset_elem_ptr( 1 );
247       call_func_set_marker_type( Markertype );
248       if( agroup->ContextMarker.IsSet )
249         call_func_offset_elem_ptr( 1 );
250       call_func_set_marker_size( Markerscale );
251
252       call_func_close_struct();
253     } /* no insert */
254
255     if( noinsert == 0 )
256     {
257       call_func_set_edit_mode( CALL_PHIGS_EDIT_INSERT );
258       call_func_open_struct( agroup->Struct->Id );
259
260       call_func_set_elem_ptr( 0 );
261       call_func_set_elem_ptr_label( agroup->LabelEnd );
262       call_func_offset_elem_ptr(-call_util_context_group_place(agroup)-1);
263       call_subr_set_marker_colr( markr, markg, markb );
264       call_func_set_marker_type( markertype );
265       call_func_set_marker_size( markerscale );
266
267       if( agroup->ContextLine.IsSet )
268         call_func_offset_elem_ptr( CALL_DEF_CONTEXTLINE_SIZE );
269       if( agroup->ContextFillArea.IsSet )
270         call_func_offset_elem_ptr( CALL_DEF_CONTEXTFILLAREA_SIZE );
271       if( !agroup->ContextMarker.IsSet )
272       {
273         call_subr_set_marker_colr( Markr, Markg, Markb );
274         call_func_set_marker_type( Markertype );
275         call_func_set_marker_size( Markerscale );
276       }
277       call_func_close_struct();
278     } /* insert */
279   }
280   /* Voir commentaire en debut de fonction */
281   if (agroup->IsOpen) call_togl_opengroup (agroup);
282   return;
283 }