1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
|
/***********************************************************************
FONCTION :
----------
file OpenGl_togl_begin_immediat_mode.c :
REMARQUES:
----------
HISTORIQUE DES MODIFICATIONS :
--------------------------------
xx-xx-xx : CAL ; Creation.
08-03-96 : FMN ; - Ajout include manquant
01-04-96 : CAL ; Integration MINSK portage WNT
15-04-96 : CAL ; Integration travail PIXMAP de Jim ROTH
07-05-96 : CAL ; Gestion du minmax calcule en C++
voir call_togl_set_minmax
Debug temporaire pour ROB, TelRobSetRGB ()
12-06-96 : CAL ; Recuperation des attributs lors d'un draw_structure
22-07-96 : GG ; Faire fonctionner correctement le highlight
des polygones en mode immediat
11-09-96 : FMN ; Ajout appel a TxglWinset dans call_togl_begin_immediat_mode
04-11-96 : CAL : Retrait du mode simule, ajout du higlight
dans togl_draw_structure
06-11-96 : CAL : Retrait du test sur doublebuffer PRO5949
16-12-96 : CAL : Ajout d'un glFinish () dans end_immediat_mode
21-01-97 : CAL : Gestion du flag <partial> differente pour
eviter les comparaisons avec shortrealfirst ou last
22-04-97 : FMN ; Correction faute i a la place de j dans util_transform_pt
22-04-97 : FMN ; Correction appel util_transform_pt dans togl_set_minmax
24-04-97 : FMN ; (PRO4063) Ajout displaylist pour le mode transient
25-07-97 : CAL ; Portage WNT (Bool, False, True)
30-07-97 : FMN ; Meilleure gestion de la desactivation des lights
10-09-97 : FMN ; Meilleure gestion de la desactivation des lights
07-10-97 : FMN ; Simplification WNT
Ajout glFlush dans call_togl_clear_immediat_mode()
26-11-97 : FMN ; Ajout mode Ajout et xor
Meilleure gestion display list pour le RetainMode
19-12-97 : FMN ; Oublie return dans le call_togl_begin_ajout_mode()
22-12-97 : FMN ; Suppression DEBUG_TEMPO_FOR_ROB
Correction PRO10217
Ajout affichage cadre TelCopyBuffer
Ajout LightOff sur le redraw.
02-02-98 : CAL ; Correction du bug sur les transformations de structure
tracees en mode transient. (PRO10217) (PRO12283)
05-02-98 : CAL ; Perfs : mise en place d'un flag identity pour savoir
si la matrice de transformation est l'identite.
08-04-98 : FMN ; Mailleur traitement du reaffichage d'une vue. Remplacement
de TsmDisplayStructure() par call_func_redraw_all_structs().
08-07-98 : FMN ; PRO14399: Desactivation animationFlag quand on debute
le mode immediat (Transient et Ajout).
30-09-98 : CAL ; Optimisation pour eviter de charger inutilement
les matrices de la vue.
27-11-98 : CAL ; S4062. Ajout des layers.
02.14.100 : JR : Warnings on WNT truncations from double to float
IMP190100 : GG
// -> Preserve current attributes because
// attributes can be changed between
// begin_immediate_mode() end end_immediate_mode()
// -> Optimize transformations computation.
// -> Optimize REDRAW in immediat mode.
// 19/09/00 -> Avoid to raise in set_linetype() & set_linewith()
// due to a bad call to TsmPutAttri() function.
BUC60726 GG_040900 Clear the last temporary detected in any case
BUC60900 GG_180501 Unhilight entity more earlier
when clear() is call instead at the next begin().
************************************************************************/
#define BUC60863 /*GG_100401 After any view update, made identical
// the front and back buffer to avoid ghost drawing.
// Minimize flicking.
*/
#define IMP150501 /*GG_150501 CADPAK_V2 Enable/Disable Zbuffer
NOTE that the previous and unused "double-buffer"
arg is changed to "zbuffer" and enable/disable
to use the OpenGl zbuffer capabilities during immediat
drawing
*/
#define IMP260601 /*GG Enable correct backing store between 2 different views.
*/
#define IMP051001 /*GG Activates the polygon offset for polygon
// selection fill mode.
*/
/*----------------------------------------------------------------------*/
#define RIC120302 /* GG Enable to use the application display
// callback at end of traversal
*/
/*
* Includes
*/
#include <OpenGl_tgl_all.hxx>
#ifdef IMP051001
#include <OpenGl_Extension.hxx>
#endif
#include <math.h>
#include <GL/gl.h>
#include <stdio.h>
#include <InterfaceGraphic_Labels.hxx>
#include <InterfaceGraphic_Graphic3d.hxx>
#include <InterfaceGraphic_Visual3d.hxx>
#include <OpenGl_tsm_ws.hxx>
#include <OpenGl_txgl.hxx>
#include <OpenGl_tgl_tox.hxx>
#include <OpenGl_tgl_funcs.hxx>
#include <OpenGl_telem_filters.hxx>
#include <OpenGl_telem.hxx>
#include <OpenGl_telem_util.hxx>
#include <OpenGl_telem_view.hxx>
#include <OpenGl_LightBox.hxx>
#include <OpenGl_animation.hxx>
#include <OpenGl_telem_attri.hxx>
#include <OpenGl_tgl.hxx>
#include <OpenGl_tgl_subrvis.hxx>
int call_util_osd_getenv( const char * , char * , int ) ;
/*----------------------------------------------------------------------*/
/*
* Constantes
*/
#define xCOPY
#define xTRACE 0
#if TRACE > 0
#include <OpenGl_traces.h>
#endif
/*----------------------------------------------------------------------*/
/*
* Variables externes
*/
/*----------------------------------------------------------------------*/
/*
* Prototypes fonctions
*/
/*----------------------------------------------------------------------*/
/*
* Prototypes Private functions
*/
static void call_util_transform_pt (float *x, float *y, float *z);
static int call_util_is_identity ();
static void call_util_transpose_mat (float tmat[16], float mat[4][4]);
/*----------------------------------------------------------------------*/
/*
* Variables statiques
*/
static int openglNumberOfPoints = 0;
static GLint openglViewId = 0;
static GLint openglWsId = 0;
static int identity = 1;
static int partial = -1; /* -1 init, 0 complete, 1 partielle */
static float xm, ym, zm, XM, YM, ZM;
static float openglMat[4][4] = {
{1., 0., 0., 0.},
{0., 1., 0., 0.},
{0., 0., 1., 0.},
{0., 0., 0., 1.},
};
static GLboolean transientOpen = GL_FALSE;
/*----------------------------------------------------------------------*/
/* Mode Ajout */
/*----------------------------------------------------------------------*/
int EXPORT call_togl_begin_ajout_mode (
CALL_DEF_VIEW *aview
)
{
CMN_KEY_DATA data;
TsmGetWSAttri (aview->WsId, WSWindow, &data);
#ifdef IMP260601
if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) != TSuccess) return (0);
#else
if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) == TSuccess)
#endif
if (aview->ViewId == -1) return (0);
openglWsId = aview->WsId;
openglViewId = aview->ViewId;
/* mise en place des matrices de projection et de mapping */
/* TelSetViewIndex (aview->WsId, aview->ViewId); */
#ifdef TRACE
printf ("call_togl_begin_ajout_mode %d %d\n", openglViewId, openglWsId);
#endif
TelMakeFrontAndBackBufCurrent (aview->WsId);
TsmPushAttri();
return (1);
}
/*----------------------------------------------------------------------*/
void EXPORT call_togl_end_ajout_mode ()
{
#ifdef TRACE
printf ("call_togl_end_ajout_mode %d %d\n", openglViewId, openglWsId);
#endif
if (openglViewId != 0) {
TelMakeBackBufCurrent (openglWsId);
}
openglViewId = 0;
openglWsId = 0;
identity = 1;
/* FMN necessaire pour l'affichage sur WNT */
glFlush();
TsmPopAttri();
}
/*----------------------------------------------------------------------*/
/* Mode Transient */
/*----------------------------------------------------------------------*/
void EXPORT call_togl_clear_immediat_mode (
CALL_DEF_VIEW *aview, Tint aFlush
)
{
CMN_KEY_DATA data;
GLuint listIndex = 0;
GLuint retainmode = 0;
if( transientOpen ) {
call_togl_end_immediat_mode(0);
}
#ifdef IMP260601
TsmGetWSAttri (aview->WsId, WSWindow, &data);
if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) != TSuccess) return;
#endif
TsmGetWSAttri( aview->WsId, WSRetainMode, &data );
retainmode = data.ldata;
#ifdef TRACE
printf("call_togl_clear_immediat_mode. xm %f, ym %f, zm %f, XM %f, YM %f, ZM %f, partial %d retainmode %d\n",xm, ym, zm, XM, YM, ZM, partial, retainmode);
#endif
if ( TelBackBufferRestored () == TOff ) {
call_togl_erase_animation_mode();
call_func_redraw_all_structs_begin (aview->WsId);
if( aview->ptrUnderLayer)
call_togl_redraw_layer2d (aview, (CALL_DEF_LAYER *)aview->ptrUnderLayer);
call_func_redraw_all_structs_proc (aview->WsId);
if( aview->ptrOverLayer)
call_togl_redraw_layer2d (aview, (CALL_DEF_LAYER *)aview->ptrOverLayer);
#ifdef RIC120302
call_subr_displayCB(aview,OCC_REDRAW_WINDOW);
#endif
call_func_redraw_all_structs_end (aview->WsId, aFlush);
// After a redraw,
// Made the back identical to the front buffer.
// Always perform full copy (partial update optimization is useless on mordern hardware)!
if (retainmode)
TelCopyBuffers (aview->WsId, GL_FRONT, GL_BACK, xm, ym, zm, XM, YM, ZM, 0);
#ifdef TRACE
printf(" $$$ REDRAW\n");
#endif
TelSetBackBufferRestored (TOn);
} else if( partial >= 0 ) {
// Restore pixels from the back buffer.
// Always perform full copy (partial update optimization is useless on mordern hardware)!
TelCopyBuffers (aview->WsId, GL_BACK, GL_FRONT, xm, ym, zm, XM, YM, ZM, 0);
}
TsmGetWSAttri (aview->WsId, WSTransient, &data);
listIndex = (GLuint) data.ldata;
if( listIndex != 0 ) { /* Clear current list contents */
glNewList( listIndex, GL_COMPILE_AND_EXECUTE);
glEndList();
}
partial = -1;
XM = YM = ZM = (float ) shortrealfirst ();
xm = ym = zm = (float ) shortreallast ();
}
/*----------------------------------------------------------------------*/
void call_togl_redraw_immediat_mode(
CALL_DEF_VIEW * aview
)
{
CMN_KEY_DATA data;
GLuint listIndex = 0;
int retainmode = 0;
#ifndef IMP150501
GLboolean flag_zbuffer = GL_FALSE;
#endif
TsmGetWSAttri( aview->WsId, WSRetainMode, &data );
retainmode = data.ldata;
TsmGetWSAttri (aview->WsId, WSTransient, &data);
listIndex = (GLuint) data.ldata;
if (retainmode != 0) {
if (listIndex != 0) {
TelMakeFrontBufCurrent (aview->WsId);
LightOff();
/* mise en place des matrices de projection et de mapping */
/* TelSetViewIndex (aview->WsId, aview->ViewId); */
#ifdef TRACE
printf("call_togl_redraw_immediat_mode::call displaylist(%d) \n",
listIndex);
#endif
#ifdef IMP150501
glCallList(listIndex);
#else
flag_zbuffer = glIsEnabled(GL_DEPTH_TEST);
if (flag_zbuffer) glDisable(GL_DEPTH_TEST);
glCallList(listIndex);
if (flag_zbuffer) glEnable(GL_DEPTH_TEST);
#endif
/* FMN necessaire pour l'affichage sur WNT */
glFlush();
TelMakeBackBufCurrent (aview->WsId);
}
}
}
/*----------------------------------------------------------------------*/
int EXPORT
call_togl_begin_immediat_mode
(
CALL_DEF_VIEW * aview,
CALL_DEF_LAYER * anunderlayer,
CALL_DEF_LAYER * anoverlayer,
#ifdef IMP150501
int zbuffer,
#else
int doublebuffer,
#endif
int retainmode
)
{
CMN_KEY_DATA data;
GLuint listIndex = 0;
if (aview->ViewId == -1) return (0);
TsmGetWSAttri (aview->WsId, WSWindow, &data);
#ifdef IMP260601
if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) != TSuccess) return (0);
#else
if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) == TSuccess)
#endif
openglWsId = aview->WsId;
openglViewId = aview->ViewId;
data.ldata = retainmode;
TsmSetWSAttri( aview->WsId, WSRetainMode, &data );
#ifdef TRACE
printf ("call_togl_begin_immediat_mode %d %d RetainMode %d zbuffer %d partial %d\n", openglViewId, openglWsId, retainmode, zbuffer, partial);
#endif
call_togl_clear_immediat_mode(aview,1);
TelMakeFrontBufCurrent (aview->WsId);
TsmPushAttri();
#ifdef COPY
if (partial == 1) {
glColor3f (1., 0., 0.);
glBegin(GL_LINE_LOOP);
glVertex3f (xm, ym, zm);
glVertex3f (XM, ym, zm);
glVertex3f (XM, YM, zm);
glVertex3f (xm, YM, zm);
glEnd();
}
#endif
/*
* RetainMode
*/
if( retainmode ) {
TsmGetWSAttri (aview->WsId, WSTransient, &data);
listIndex = (GLuint) data.ldata;
if (listIndex == 0) {
listIndex = glGenLists(1);
#ifdef TRACE
printf("call_togl_begin_immediat_mode::init displaylist() %d \n", listIndex);
#endif
data.ldata = listIndex;
TsmSetWSAttri( aview->WsId, WSTransient, &data );
}
if (listIndex == 0) return(0);
#ifdef TRACE
printf("call_togl_begin_immediat_mode::glNewList() %d \n", listIndex);
#endif
glNewList(listIndex, GL_COMPILE_AND_EXECUTE);
transientOpen = GL_TRUE;
}
#ifdef IMP150501
if( zbuffer ) {
glEnable(GL_DEPTH_TEST);
} else glDisable(GL_DEPTH_TEST);
#endif
return (1);
}
/*----------------------------------------------------------------------*/
/*
call_togl_end_immediat_mode (synchronize)
GLboolean synchronize
End of immediate graphic primitives in the view.
*/
void EXPORT
call_togl_end_immediat_mode
(
int synchronize
)
{
#ifdef TRACE
printf ("call_togl_end_immediat_mode %d %d %d\n",
synchronize, openglViewId, openglWsId);
#endif
#ifndef BUC60863 /* Don't modify the current minmax !!*/
/* Mise ajout MinMax */
if ((xm > shortreallast ()) ||
(ym > shortreallast ()) ||
(zm > shortreallast ()) ||
(XM > shortreallast ()) ||
(YM > shortreallast ()) ||
(ZM > shortreallast ()) ||
(xm < shortrealfirst ()) ||
(ym < shortrealfirst ()) ||
(zm < shortrealfirst ()) ||
(XM < shortrealfirst ()) ||
(YM < shortrealfirst ()) ||
(ZM < shortrealfirst ())) {
XM = YM = ZM = (float ) shortreallast ();
xm = ym = zm = (float ) shortrealfirst ();
partial = 0;
}
else {
if (partial != 0) partial = 1;
}
#endif /*BUC60863*/
if (openglViewId != 0) {
#ifdef COPY
if (partial == 1) {
glColor3f (0., 1., 0.);
glBegin(GL_LINE_LOOP);
glVertex3f (xm, ym, zm);
glVertex3f (XM, ym, zm);
glVertex3f (XM, YM, zm);
glVertex3f (xm, YM, zm);
glEnd();
}
#endif
if (transientOpen) {
glEndList();
#ifdef TRACE
printf("--->glEndList() \n");
#endif
transientOpen = GL_FALSE;
}
TelMakeBackBufCurrent (openglWsId);
}
/*
* Ajout CAL : pour voir quelque chose
* avant le prochain begin_immediat_mode
*/
glFinish ();
openglViewId = 0;
openglWsId = 0;
identity = 1;
TsmPopAttri();
}
/*----------------------------------------------------------------------*/
/*
call_togl_transform (amatrix, mode)
float amatrix[4][4]
GLboolean mode
Set the local transformation for All primitives
REPLACE the existante if mode is True or POSTCONCATENATE if GL_FALSE
*/
void EXPORT
call_togl_transform ( float amatrix[4][4], int mode )
{
int i, j;
if (mode || identity) {
for (i=0; i<4; i++)
for (j=0; j<4; j++)
openglMat[i][j] = amatrix[i][j];
} else
TelMultiplymat3 (openglMat, openglMat, amatrix);
identity = call_util_is_identity ();
}
/*
call_togl_begin_polyline ()
Sets the graphic library ready to receive a polyline.
*/
void EXPORT
call_togl_begin_polyline ()
{
openglNumberOfPoints = 0;
LightOff();
glBegin (GL_LINE_STRIP);
}
/*----------------------------------------------------------------------*/
/*
call_togl_end_polyline ()
End of the polyline.
*/
void EXPORT
call_togl_end_polyline ()
{
#ifdef TRACE
printf ("call_togl_end_polyline %d %d\n", openglViewId, openglWsId);
#endif
if (openglViewId != 0) glEnd ();
}
/*----------------------------------------------------------------------*/
/*
call_togl_draw (x, y, z)
float x;
float y;
float z;
Defines a new point in the current primitive.
*/
void EXPORT
call_togl_draw
(
float x,
float y,
float z
)
{
#ifdef TRACE
printf ("call_togl_draw %d %d\n", openglViewId, openglWsId);
#endif
if (openglViewId != 0) {
openglNumberOfPoints ++;
call_util_transform_pt (&x, &y, &z);
if (x > XM) XM = x;
if (y > YM) YM = y;
if (z > ZM) ZM = z;
if (x < xm) xm = x;
if (y < ym) ym = y;
if (z < zm) zm = z;
glVertex3f (x, y, z);
partial = 1;
}
}
/*----------------------------------------------------------------------*/
/*
call_togl_move (x, y, z)
float x;
float y;
float z;
Defines a new point in the current primitive.
*/
void EXPORT
call_togl_move
(
float x,
float y,
float z
)
{
#ifdef TRACE
printf ("call_togl_move %d %d\n", openglViewId, openglWsId);
#endif
if (openglViewId != 0) {
if (openglNumberOfPoints != 0) {
call_togl_end_polyline ();
call_togl_begin_polyline ();
}
openglNumberOfPoints ++;
call_util_transform_pt (&x, &y, &z);
if (x > XM) XM = x;
if (y > YM) YM = y;
if (z > ZM) ZM = z;
if (x < xm) xm = x;
if (y < ym) ym = y;
if (z < zm) zm = z;
glVertex3f (x, y, z);
partial = 1;
}
}
/*----------------------------------------------------------------------*/
/*
call_togl_set_linecolor (r, g, b)
float r;
float g;
float b;
Sets a new color in the current primitive.
*/
void EXPORT
call_togl_set_linecolor
(
float r,
float g,
float b
)
{
#ifdef TRACE
printf ("call_togl_set_linecolor %d %d\n", openglViewId, openglWsId);
#endif
if (openglViewId != 0) {
TEL_COLOUR color;
CMN_KEY key;
key.id = TelPolylineColour;
color.rgb[0] = r; color.rgb[1] = g; color.rgb[2] = b;
key.data.pdata = &color;
TsmSetAttri( 1, &key );
}
}
/*----------------------------------------------------------------------*/
/*
call_togl_set_linetype (type)
long type;
Sets a new line type in the current primitive.
*/
void EXPORT
call_togl_set_linetype
(
long type
)
{
#ifdef TRACE
printf ("call_togl_set_linetype %d %d\n", openglViewId, openglWsId);
#endif
if (openglViewId != 0) {
CMN_KEY key;
key.id = TelPolylineType;
key.data.ldata = type;
TsmSetAttri( 1, &key);
}
}
/*----------------------------------------------------------------------*/
/*
call_togl_set_linewidth (width)
float width;
Sets a new line width in the current primitive.
*/
void EXPORT
call_togl_set_linewidth
(
float width
)
{
#ifdef TRACE
printf ("call_togl_set_linewidth %d %d\n", openglViewId, openglWsId);
#endif
if (openglViewId != 0) {
CMN_KEY key;
key.id = TelPolylineWidth;
key.data.fdata = width;
TsmSetAttri( 1, &key);
}
}
/*----------------------------------------------------------------------*/
/*
call_togl_draw_structure (aStructureId)
int aStructureId
Draw a structure in the transient view space
*/
void EXPORT
call_togl_draw_structure
(
int aStructureId
)
{
Tint i, num;
tsm_node node;
register Tint istrsfed = 0;
register Tint display = 1;
register Tint highl = TOff;
register TelType telem;
CMN_KEY key;
float mat16[16];
GLint mode1;
GLint mode2;
#ifdef TRACE
printf ("call_togl_draw_structure %d %d %d\n", openglViewId, openglWsId);
#endif
if (openglViewId == 0) return;
if (TsmGetStructure (aStructureId, &num, &node) == TFailure || !num) return;
/*transform_persistence_end();*/
TsmPushAttriLight ();
TsmPushAttri();
TglNamesetPush();
/* mise en place de la matrice de transformation du trace transient */
if (! identity) {
call_util_transpose_mat (mat16, openglMat);
glGetIntegerv (GL_MATRIX_MODE, &mode1);
glMatrixMode (GL_MODELVIEW);
glPushMatrix ();
glScalef (1., 1., 1.);
glMultMatrixf (mat16);
}
for (i = 0; i < num; i++, node = node->next) {
telem = node->elem.el;
#if TRACE > 0
TelTrace(telem,node->elem.data.ldata);
#endif
switch (telem) {
case TelAddNameset:
case TelRemoveNameset: {
TsmSendMessage (telem, DisplayTraverse, node->elem.data, 0);
if( TglFilterNameset( openglWsId, InvisFilter ) == TSuccess )
display = 0;
if( TglFilterNameset( openglWsId, HighlFilter ) == TSuccess )
highl = TOn;
break;
}
case TelCurve:
case TelMarker:
case TelMarkerSet:
case TelPolyline:
case TelText: {
/* do not send Display message to */
/* primitives if they are invisible */
if (display)
{
LightOff();
#ifdef IMP150501
glDepthMask(GL_FALSE);
#endif
key.id = highl;
TsmSendMessage (telem, DisplayTraverse, node->elem.data, 1, &key);
}
}
break;
case TelPolygon:
case TelPolygonSet:
case TelPolygonHoles:
case TelPolygonIndices:
case TelQuadrangle:
case TelParray:
case TelTriangleMesh: {
/* do not send Display message to */
/* primitives if they are invisible */
if (display)
{
/* LightOn(); */
#ifdef IMP150501
glDepthMask(GL_FALSE);
#endif
#ifdef IMP051001
if( highl ) {
call_subr_disable_polygon_offset();
}
#endif
key.id = highl;
TsmSendMessage (telem, DisplayTraverse, node->elem.data, 1, &key);
#ifdef IMP051001
if( highl ) {
call_subr_enable_polygon_offset();
}
#endif
}
}
break;
case TelLocalTran3: {
tel_matrix3_data d = ((tel_matrix3_data)(node->elem.data.pdata));
istrsfed = 1;
call_util_transpose_mat (mat16, d->mat);
glGetIntegerv (GL_MATRIX_MODE, &mode2);
glMatrixMode (GL_MODELVIEW);
glPushMatrix ();
glScalef (1., 1., 1.);
glMultMatrixf (mat16);
}
break;
/* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
case TelTransformPersistence:
{
key.id = openglWsId;
TsmSendMessage (telem, DisplayTraverse, node->elem.data, 1, &key);
break;
}
/*ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
default: {
key.id = openglWsId;
TsmSendMessage (telem, DisplayTraverse, node->elem.data, 0, &key);
}
}
}
TglNamesetPop();
TsmPopAttri();
TsmPopAttriLight ();
if (istrsfed) {
glPopMatrix ();
glMatrixMode (mode2);
}
if (! identity) {
glPopMatrix ();
glMatrixMode (mode1);
}
return;
}
/*----------------------------------------------------------------------*/
/*
call_togl_set_minmax (x1, y1, z1, x2, y2, z2)
float x1;
float y1;
float z1;
float x2;
float y2;
float z2;
Give the boundary box of the transient graphic
*/
void EXPORT
call_togl_set_minmax (
float x1,
float y1,
float z1,
float x2,
float y2,
float z2
)
{
#ifdef TRACE
printf("call_togl_set_minmax. x1 %f, y1 %f, z1 %f, x2 %f, y2 %f, z2 %f\n",x1, y1, z1, x2, y2, z2);
#endif
if ((x1 > shortreallast ()) ||
(y1 > shortreallast ()) ||
(z1 > shortreallast ()) ||
(x2 > shortreallast ()) ||
(y2 > shortreallast ()) ||
(z2 > shortreallast ()) ||
(x1 < shortrealfirst ()) ||
(y1 < shortrealfirst ()) ||
(z1 < shortrealfirst ()) ||
(x2 < shortrealfirst ()) ||
(y2 < shortrealfirst ()) ||
(z2 < shortrealfirst ())) {
XM = YM = ZM = (float ) shortreallast ();
xm = ym = zm = (float ) shortrealfirst ();
partial = 0;
}
else {
call_util_transform_pt (&x1, &y1, &z1);
call_util_transform_pt (&x2, &y2, &z2);
if (x1 > XM) XM = x1;
if (x1 < xm) xm = x1;
if (y1 > YM) YM = y1;
if (y1 < ym) ym = y1;
if (z1 > ZM) ZM = z1;
if (z1 < zm) zm = z1;
if (x2 > XM) XM = x2;
if (x2 < xm) xm = x2;
if (y2 > YM) YM = y2;
if (y2 < ym) ym = y2;
if (z2 > ZM) ZM = z2;
if (z2 < zm) zm = z2;
if (partial != 0) partial = 1;
}
}
/*----------------------------------------------------------------------*/
/*
* Private functions
*/
/*----------------------------------------------------------------------*/
/*
call_util_transform_pt (x, y, z)
float *x;
float *y;
float *z;
Transform the point pt
*/
static void call_util_transform_pt
(
float *x,
float *y,
float *z
)
{
int i, j;
float sum = 0.;
float tpt[4], pt[4];
if (! identity) {
pt[0] = *x, pt[1] = *y, pt[2] = *z, pt[3] = 1.0;
for (i = 0; i < 4; i++) {
for (j = 0, sum = 0.0; j < 4; j++)
sum += openglMat[i][j] * pt[j];
tpt[i] = sum;
}
*x = tpt[0], *y = tpt[1], *z = tpt[2];
}
}
/*----------------------------------------------------------------------*/
/*
int call_util_is_identity ()
Returns 1 if openglMat is the identity
*/
static int call_util_is_identity
(
)
{
int i, j;
int res = 1;
for (i = 0; res && i < 4; i++)
for (j = 0; res && j < 4; j++)
if (i == j) res = (openglMat[i][j] == 1.);
else res = (openglMat[i][j] == 0.);
#ifdef TRACE
printf ("La matrice suivante :\n");
for (i = 0; i < 4; i++) {
printf ("\t");
for (j = 0; j < 4; j++)
printf ("%f ", openglMat[i][j]);
printf ("\n");
}
if (res)
printf ("est la matrice identite\n");
else
printf ("n'est pas la matrice identite\n");
#endif
return (res);
}
/*----------------------------------------------------------------------*/
/*
void call_util_transpose_mat (tmat, mat)
float tmat[16];
float mat[4][4];
Transpose mat and returns tmat.
*/
static void call_util_transpose_mat (float tmat[16], float mat[4][4]) {
int i, j;
for (i=0; i<4; i++)
for (j=0; j<4; j++)
tmat[j*4+i] = mat[i][j];
#ifdef TRACE
printf ("Transposee :\n");
for (i = 0; i < 4; i++) {
printf ("\t");
for (j = 0; j < 4; j++)
printf ("%f ", tmat[i*4+j]);
printf ("\n");
}
#endif
}
|