OCC22150 Problem with GetWindowLong function on 64-bit platform
[occt.git] / src / OpenGl / OpenGl_execstruct.cxx
1 /***********************************************************************
2
3 FONCTION :
4 ----------
5 File OpenGl_execstruct :
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 22-04-96 : FMN ; Suppression prototype inutile.
18 30-06-97 : FMN ; Appel de la toolkit OpenGl_LightBox.
19 18-07-97 : FMN ; Meilleure gestion de la desactivation des lights
20 10-09-97 : FMN ; Meilleure gestion de la desactivation des lights
21 05-08-97 : PCT ; ajout descativation texture sur line etc...
22 19-08-97 : PCT ; ajout pourcentage de reflexion des objets avec textues environnante
23 22-12-97 : FMN ; Correction PRO10217 sur le mode Transient
24 13-03-98 : FMN ; Suppression variable externe TglUpdateView0
25 17-03-98 : FMN ; Ajout mode animation
26 - deplacement TelSetViewIndex vers OpenGl_execstruct.c.
27 - gestion du mode animation.
28 16-06-2000 : ATS,GG : G005 : Some conditions for execution of PARRAY  primitives
29
30 ************************************************************************/
31 #ifdef DEBUG
32 #define TRACE
33 #define TRACE_EXEC
34 #endif
35
36 #define G003  /* EUG 16-09-99 G003 ZBufferAuto treatment 
37 */
38
39 #define BUC60742  /* GG 18/09/00 Enable to use both animation and
40 graphic structure transformation
41 */
42
43 #define G005  /* ATS,GG 11/01/00 Using arrays of primitives
44 */
45
46 #define IMP051001 /* GG Enable/Disable polygon offset for
47 highlighted graphic structures
48 */
49
50 /*----------------------------------------------------------------------*/
51 /*
52 * Includes
53 */ 
54
55 #include <OpenGl_tgl_all.hxx>
56
57 #include <OpenGl_tgl_subrvis.hxx>
58
59 #include <stddef.h>
60 #include <stdio.h>
61 #include <stdlib.h>
62
63 #include <OpenGl_cmn_varargs.hxx>
64 #include <OpenGl_telem_attri.hxx>
65 #include <OpenGl_telem_filters.hxx>
66 #include <OpenGl_tsm.hxx>
67 #include <OpenGl_telem.hxx>
68 #include <OpenGl_LightBox.hxx>
69 #include <OpenGl_TextureBox.hxx>
70 #include <OpenGl_telem_view.hxx>
71 #include <OpenGl_telem_pick.hxx>
72 #include <OpenGl_telem_inquire.hxx>
73 #include <OpenGl_telem_util.hxx> /* for matcpy */
74
75 #include <OpenGl_tsm_ws.hxx>
76 #include <OpenGl_cmn_varargs.hxx>
77 #include <OpenGl_TextureBox.hxx>
78
79 #include <OpenGl_trsf_stack.hxx>
80
81 #ifdef G003
82 # include <OpenGl_degeneration.hxx>
83 #endif  /* G003 */
84 #ifdef G005
85 #include <InterfaceGraphic_PrimitiveArray.hxx>
86 #endif
87
88 /*----------------------------------------------------------------------*/
89 /*
90 * Variables externes
91 */
92
93 extern tsm_trsf_stack cur_trsf_stack;
94 #ifdef G003
95 #define D_MODE( d )  ( int   )(   (  ( PDEGENERATION )( d.data.pdata )  ) -> mode        )
96 #define S_RATIO( d ) ( float )(   (  ( PDEGENERATION )( d.data.pdata )  ) -> skipRatio   )
97 extern GLboolean g_fAnimation;
98 extern GLboolean g_fDegeneration;
99 int       g_nDegenerateModel;
100 float     g_fSkipRatio;
101 #endif  /* G003 */
102
103 /*----------------------------------------------------------------------*/
104 /*
105 * Constantes
106 */
107
108 static TEL_PACKED_NAME pn;
109
110 #define PUSHNAME( a )  pn.i = a, glPushName( pn.s[0] ), glPushName( pn.s[1] )
111 #define LOADNAME( a )  pn.i = a, glPopName(), glLoadName( pn.s[0] ), \
112   glPushName( pn.s[1] )
113 #define POPNAME()      glPopName(), glPopName()
114
115 #define NO_TRACE_LIGHT 
116 #define NO_TRACE_EXEC 
117
118 /*----------------------------------------------------------------------*/
119 /*
120 * Prototypes fonctions
121 */
122
123 static  TStatus  ExecuteStructurePick( TSM_ELEM_DATA, Tint, cmn_key* );
124 static  TStatus  ExecuteStructureDisplay( TSM_ELEM_DATA, Tint, cmn_key* );
125 static  TStatus  ExecuteStructureAdd( TSM_ELEM_DATA, Tint, cmn_key* );
126 static  TStatus  ExecuteStructurePrint( TSM_ELEM_DATA, Tint, cmn_key* );
127 static  TStatus  ExecuteStructureInquire( TSM_ELEM_DATA, Tint, cmn_key* );
128
129 /*----------------------------------------------------------------------*/
130 /*
131 * Variables locales
132 */
133
134 static  TStatus  (*MtdTbl[])( TSM_ELEM_DATA, Tint, cmn_key* ) =
135 {
136   ExecuteStructurePick,
137     ExecuteStructureDisplay,
138     ExecuteStructureAdd,
139     0,             /* Delete : may be provided for deleting structure
140                    network */
141                    ExecuteStructurePrint,
142                    ExecuteStructureInquire
143 };
144
145 /*----------------------------------------------------------------------*/
146
147 MtblPtr
148 TelExecuteStructureInitClass( TelType *el )
149 {
150   *el = TelExecuteStructure;
151   return MtdTbl;
152 }
153
154 /*----------------------------------------------------------------------*/
155
156 static  TStatus
157 ExecuteStructureAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k )
158 {
159   ((tsm_elem_data)(d.pdata))->ldata = k[0]->data.ldata;
160
161   return TSuccess;
162 }
163
164 /*----------------------------------------------------------------------*/
165
166 static TStatus
167 ExecuteStructurePick( TSM_ELEM_DATA data, Tint n, cmn_key *k )
168 {
169   Tint              i, num;
170   tsm_node          node;
171   register Tint     display = 1;
172   register Tint     pickfl = 0;
173   register TelType  elem;
174   Tint              vp;
175   Tint              view = 0;
176   CMN_KEY           key;
177
178   if( TsmGetStructure( data.ldata, &num, &node ) == TFailure )
179     return TFailure;
180
181   if( !num )
182     return TSuccess;
183
184   PUSHNAME( data.ldata );  /* Struct id */
185   PUSHNAME( -1 );          /* Pick id; dummy */
186   PUSHNAME( -1 );          /* Elem no.; dummy */
187
188   TsmPushAttri(); /* save previous graphics context */
189   TglNamesetPush();
190   if( TglFilterNameset( k[0]->id, InvisFilter ) == TSuccess )
191     display = 0;
192   if( TglFilterNameset( k[0]->id, PickFilter ) == TSuccess )
193     pickfl = 1;
194   key.id = TelViewIndex;
195   TsmGetAttri( 1, &key );
196   vp = key.data.ldata;
197   if( TglVpBeingPicked == vp )
198     view = 1;
199   for( i = 0; i < num; i++, node = node->next )
200   {
201     elem = node->elem.el;
202     switch( elem )
203     {
204     case TelAddNameset:
205     case TelRemoveNameset:
206       {
207         TsmSendMessage( elem, PickTraverse, node->elem.data, 0 );
208         if( TglFilterNameset( k[0]->id, InvisFilter ) == TSuccess )
209           display = 0;
210         else
211           display = 1;
212         if( TglFilterNameset( k[0]->id, PickFilter ) == TSuccess )
213           pickfl = 1;
214         else
215           pickfl = 0;
216         break;
217       }
218     case TelExecuteStructure:
219       {
220         LOADNAME( i+1 ); /* Elem no. */
221         TsmSendMessage( elem, PickTraverse, node->elem.data, -1, k );
222         break;
223       }
224     case TelPickId:
225       {
226         POPNAME();                        /* Elem no. */
227         LOADNAME( node->elem.data.ldata );      /* Pick id */
228         PUSHNAME( -1 );                   /* Elem no.; dummy */
229         break;
230       }
231     case TelViewIndex:
232       {
233         vp = node->elem.data.ldata;
234         if( vp == TglVpBeingPicked )
235         {
236           view = 1;
237           key.id = TOn;
238         }
239         else
240         {
241           view = 0;
242           key.id = TOff;
243         }
244         TsmSendMessage( elem, PickTraverse, node->elem.data, 1, &key );
245         break;
246       }
247     case TelCurve:
248     case TelPolygon:
249     case TelPolygonSet:
250     case TelPolygonHoles:
251     case TelPolygonIndices:
252     case TelQuadrangle:
253     case TelPolyline:
254     case TelMarker:
255     case TelMarkerSet:
256     case TelText:
257     case TelTriangleMesh:
258 #ifdef G005
259     case TelParray:
260       /* do not send Pick message to */
261       {                        /* primitives if they are not pickable */
262         if( pickfl && view && display )
263         {
264           key.id = TOff; /* dummy key for highlight flag */
265           LOADNAME( i+1 ); /* Elem no. */
266           TsmSendMessage( elem, PickTraverse, node->elem.data, 1, &key );
267         }
268         break;
269       }
270 #endif
271
272     default:
273       {
274         TsmSendMessage( elem, PickTraverse, node->elem.data, 0 );
275         break;
276       }
277     }
278   }
279   TglNamesetPop();
280   TsmPopAttri(); /* restore previous graphics context */
281
282   POPNAME();  /* Elem no. */
283   POPNAME();  /* Pick id */
284   POPNAME();  /* Struct id */
285
286   return TSuccess;
287 }
288
289 /*----------------------------------------------------------------------*/
290
291 static  TStatus
292 ExecuteStructureDisplay( TSM_ELEM_DATA data, Tint n, cmn_key *k )
293 {
294   Tint              i, num;
295   tsm_node          node;
296   register Tint     display = 1;
297   register Tint     highl = TOff;
298   register TelType  elem;
299   Tint              vp;
300   CMN_KEY           key;
301 #ifdef G003
302   static GLboolean s_fWire            = GL_FALSE;
303   static Tint      s_depth            = 0;
304   static Tint      save_texture_state = 0;
305   static CMN_KEY   s_kLineWidth;
306   static CMN_KEY   s_kPolyType;
307   TStatus   retVal             = TSuccess;
308 #else
309   int               save_texture_state;
310 #endif
311
312   if( TsmGetStructure( data.ldata, &num, &node ) == TFailure )
313 #ifdef G003
314   { retVal = TFailure; goto ret; }
315 #else
316     return TFailure;
317 #endif
318
319   if( !num )
320 #ifdef G003
321     goto ret;
322 #else
323     return TSuccess;
324 #endif
325
326 #ifdef G003
327   ++s_depth;
328 #ifdef TRACE  
329   printf(" .. ExecuteStructureDisplay.s_depth = %d\n",s_depth); 
330 #endif
331 #endif /*G003*/
332
333   TsmPushAttri(); /* save previous graphics context */
334   TglNamesetPush();
335   if( TglFilterNameset( k[0]->id, InvisFilter ) == TSuccess )
336     display = 0;
337   if( TglFilterNameset( k[0]->id, HighlFilter ) == TSuccess )
338     highl = TOn;
339   key.id = TelViewIndex;
340   TsmGetAttri( 1, &key );
341 #ifdef G003
342   if ( s_depth == 1 ) {
343     glPushAttrib ( GL_DEPTH_BUFFER_BIT );
344     s_kLineWidth.id = TelPolylineWidth;
345     s_kPolyType.id  = TelPolylineType;
346 #ifdef BUG
347     TsmGetAttri ( 1, &s_kLineWidth, &s_kPolyType );
348 #else
349     TsmGetAttri ( 2, &s_kLineWidth, &s_kPolyType );
350 #endif
351     g_nDegenerateModel = 0;
352     g_fSkipRatio       = 0.0F;
353   }  /* end if */
354 #endif  /* G003 */
355
356   vp = key.data.ldata;
357   for( i = 0; i < num; i++, node = node->next )
358   {
359     elem = node->elem.el;
360 #ifdef TRACE_EXEC 
361 #include <OpenGl_traces.hxx>
362 #endif
363     switch( elem )
364     {
365 #ifdef G003
366             case TelDegenerationMode:
367
368       if ( g_fDegeneration )
369
370         switch (  g_nDegenerateModel = D_MODE( node->elem )  ) 
371       {
372
373         case 0:
374
375           break;
376
377         default:
378
379           glLineWidth ( 1.0 );
380           glDisable   ( GL_LINE_STIPPLE );
381
382         case 1:
383
384           g_fSkipRatio = S_RATIO( node->elem );
385
386       }  /* end switch */
387
388     break;
389 #endif  /* G003 */
390     case TelAddNameset:
391     case TelRemoveNameset:
392       {
393       TsmSendMessage( elem, DisplayTraverse, node->elem.data, 0 );
394       if( TglFilterNameset( k[0]->id, InvisFilter ) == TSuccess )
395         display = 0;
396       else
397         display = 1;
398       if( TglFilterNameset( k[0]->id, HighlFilter ) == TSuccess )
399         highl = TOn;
400       else
401         highl = TOff;
402       break;
403       }
404     case TelExecuteStructure:
405       {
406         tsm_trsf_stack new_trsf_stack = NULL;
407
408         new_trsf_stack = (tsm_trsf_stack) malloc (sizeof (TSM_TRSF_STACK));
409         cur_trsf_stack->next = new_trsf_stack;
410         new_trsf_stack->prev = cur_trsf_stack;
411         new_trsf_stack->next = NULL;
412         matcpy(new_trsf_stack->LocalTran3, cur_trsf_stack->LocalTran3);
413         cur_trsf_stack = new_trsf_stack;
414
415 #ifdef TRACE    
416         printf(" .. ExecuteStructureDisplay.TelExecuteStructure.s_depth = %d\n",s_depth); 
417 #endif
418 #ifdef BUC60742   
419         glMatrixMode (GL_MODELVIEW);
420         glPushMatrix();
421 #endif
422         TsmSendMessage( elem, DisplayTraverse, node->elem.data, -1, k );
423 #ifdef BUC60742   
424         glMatrixMode (GL_MODELVIEW);
425         glPopMatrix();
426 #endif
427         cur_trsf_stack = new_trsf_stack->prev;
428         cur_trsf_stack->next = NULL;
429         free (new_trsf_stack);
430         break;
431       }
432     case TelViewIndex:
433       {
434         break;
435       } 
436
437     case TelPolyline:
438     case TelMarker:
439     case TelMarkerSet:
440     case TelText:
441       {                        /* primitives if they are invisible */
442         if( display )
443         {
444           LightOff();
445 #ifdef G003
446           if ( g_fAnimation && !s_fWire && g_nDegenerateModel ) {
447             glDisable ( GL_DEPTH_TEST );
448 #endif  /* G003 */
449             save_texture_state = IsTextureEnabled();
450             if( save_texture_state ) DisableTexture();
451 #ifdef G003
452             s_fWire = GL_TRUE;
453           }  /* end if */
454 #endif  /* G003 */
455
456           key.id = highl;
457           TsmSendMessage( elem, DisplayTraverse, node->elem.data, 1, &key );
458           if (save_texture_state) EnableTexture();
459         }
460         break;
461       }
462     case TelCurve:
463     case TelPolygon:
464     case TelPolygonSet:
465     case TelPolygonIndices:
466     case TelQuadrangle:
467     case TelTriangleMesh:
468     case TelPolygonHoles:    /* do not send Display message to */
469       {                        /* primitives if they are invisible */
470         if( display )
471         {
472 #ifdef G003
473           if ( g_fAnimation && s_fWire && g_nDegenerateModel < 2 ) {
474             if ( save_texture_state ) EnableTexture ();
475             glEnable ( GL_DEPTH_TEST );
476             s_fWire = GL_FALSE;
477           }  /* end if */
478 #endif  /* G003 */
479 #ifdef IMP051001
480           if( highl )
481             call_subr_disable_polygon_offset();
482 #endif
483           key.id = highl;
484           TsmSendMessage( elem, DisplayTraverse, node->elem.data, 1, &key );
485 #ifdef IMP051001
486           if( highl )
487             call_subr_enable_polygon_offset();
488 #endif
489         }
490         break;
491       }
492 #ifdef G005
493     case TelParray:
494       if( display ) {
495         CALL_DEF_PARRAY *pa = (CALL_DEF_PARRAY *)node->elem.data.pdata;
496         switch ( pa->type )
497         {
498         case TelPointsArrayType:
499         case TelPolylinesArrayType:
500         case TelSegmentsArrayType:
501           LightOff();
502 #ifdef G003
503           if ( g_fAnimation && !s_fWire && g_nDegenerateModel ) {
504             glDisable ( GL_DEPTH_TEST );
505 #endif  /* G003 */
506             save_texture_state = IsTextureEnabled();
507             if( save_texture_state ) DisableTexture();
508 #ifdef G003
509             s_fWire = GL_TRUE;
510           }  /* end if */
511 #endif  /* G003 */
512
513           key.id = highl;
514           TsmSendMessage( elem, DisplayTraverse, node->elem.data, 1, &key );
515           if (save_texture_state) EnableTexture();
516           break;
517         case TelPolygonsArrayType:
518         case TelTrianglesArrayType:
519         case TelQuadranglesArrayType:
520         case TelTriangleStripsArrayType:
521         case TelTriangleFansArrayType:
522         case TelQuadrangleStripsArrayType:
523 #ifdef G003
524           if ( g_fAnimation && s_fWire && g_nDegenerateModel < 2 ) {
525             if ( save_texture_state ) EnableTexture ();
526             glEnable ( GL_DEPTH_TEST );
527             s_fWire = GL_FALSE;
528           }  /* end if */
529 #endif  /* G003 */
530           key.id = highl;
531           TsmSendMessage( elem, DisplayTraverse, node->elem.data, 1, &key );
532           break;
533         default:
534           break;
535         }
536       }
537       break;
538 #endif  /*G005*/
539       /* ABD 29/10/04  Transform Persistence of Presentation( pan, zoom, rotate ) */
540     case TelTransformPersistence:
541       {
542         /*CALL_DEF_TRANSFORM_PERSISTENCE*/
543         TEL_TRANSFORM_PERSISTENCE *tp 
544           = (tel_transform_persistence)node->elem.data.pdata;
545         if( tp->mode != 0 )
546           TsmSendMessage (elem, DisplayTraverse, node->elem.data, 1, &key);
547         break;
548       }
549       /*ABD 29/10/04  Transform Persistence of Presentation( pan, zoom, rotate ) */
550     case TelUserdraw:
551       {
552         if( display )
553         {
554           key.id = highl;
555           TsmSendMessage( elem, DisplayTraverse, node->elem.data, 1, &key );
556         }
557         break;
558       }
559     default:
560       {
561         TsmSendMessage( elem, DisplayTraverse, node->elem.data, 0 );
562         break;
563       }
564     }
565   }
566   TglNamesetPop();
567   TsmPopAttri(); /* restore previous graphics context; before update lights */
568 #ifdef G003
569 ret: 
570   if ( s_depth == 1 ) {
571     s_fWire = GL_FALSE;
572
573     if ( g_nDegenerateModel > 1 ) {
574       glLineWidth ( s_kLineWidth.data.fdata );
575       if ( s_kPolyType.data.ldata != TEL_LS_SOLID ) glEnable ( GL_LINE_STIPPLE );
576     }  /* end if */
577
578     glPopAttrib ();
579   }  /* end if */
580
581   --s_depth;
582   return retVal;
583 #else
584   return TSuccess;
585 #endif
586 }
587
588 /*----------------------------------------------------------------------*/
589
590 static  TStatus
591 ExecuteStructurePrint( TSM_ELEM_DATA data, Tint n, cmn_key *k )
592 {
593   fprintf( stdout, "TelExecuteStructure. Value = %d\n", data.ldata);
594   fprintf( stdout, "\n" );
595
596   return TSuccess;
597 }
598
599 /*----------------------------------------------------------------------*/
600
601 static TStatus
602 ExecuteStructureInquire( TSM_ELEM_DATA data, Tint n, cmn_key *k )
603 {
604   Tint i;
605
606   for( i = 0; i < n; i++ )
607   {
608     switch( k[i]->id )
609     {
610     case INQ_GET_SIZE_ID:
611       {
612         k[i]->data.ldata = sizeof( Tint );
613         break;
614       }
615     case INQ_GET_CONTENT_ID:
616       {
617         TEL_INQ_CONTENT *c;
618         Teldata         *w;
619
620         c = (tel_inq_content)k[i]->data.pdata;
621         w = c->data;
622         c->act_size = 0;
623         w->idata = data.ldata;
624         break;
625       }
626     }
627   }
628
629   return TSuccess;
630 }
631
632 /*----------------------------------------------------------------------*/