summaryrefslogtreecommitdiff
path: root/src/OpenGl/OpenGl_togl_contextstructure.cxx
blob: d4b20c00efe5547d0d020ac8a8396838e4482051 (plain)
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
/***********************************************************************

FONCTION :
----------
File OpenGl_contextstructure.c :


REMARQUES:
---------- 


HISTORIQUE DES MODIFICATIONS   :
--------------------------------
05-08-97 : PCT ; Support texture mapping
23-12-97 : FMN ; Suppression TelBackInteriorStyle, TelBackInteriorStyleIndex
30-12-97 : FMN ; CTS18312: Correction back material
15-01-98 : FMN ; Ajout Hidden line
03-03-98 : CAL ; Modification des structures CALL_DEF_GROUP et STRUCTURE
08-04-98 : FGU ; Ajout Emission
30-11-98 : FMN ; S4069 : Textes toujours visibles
02.14.100 : JR : Warnings on WNT #include ,stdio.h>
22-03-04 : SAN ; OCC4895 High-level interface for controlling polygon offsets

************************************************************************/

#define OCC1174 /* SAV 08/01/03 : Added back face interior color management*/


/*----------------------------------------------------------------------*/
/*
* Includes
*/

#include <stdio.h>

#include <OpenGl_tgl_all.hxx>

#include <InterfaceGraphic_Labels.hxx>
#include <InterfaceGraphic_Graphic3d.hxx>

#include <OpenGl_tgl.hxx>
#include <OpenGl_tgl_funcs.hxx>
#include <OpenGl_tgl_subrs.hxx>

#include <OSD_FontAspect.hxx>


void EXPORT
call_togl_contextstructure
(
 CALL_DEF_STRUCTURE * astructure
 )
{
  Tfloat liner, lineg, lineb;
  Tfloat fillr, fillg, fillb;
#ifdef OCC1174
  Tfloat fillBackr, fillBackg, fillBackb;
#endif
  Tint   linetype=0;
  Tint   intstyle=0;
  Tfloat linewidth;
  Tint   hatch=0;
  /* OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets */
  Tint   polyOffsetMode;
  Tfloat polyOffsetFactor, polyOffsetUnits;
  /* OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets */

  Tfloat markr, markg, markb;
  Tint   markertype=0;
  Tfloat markerscale;

  Tchar  *fontid=NULL;
  Tfloat textr, textg, textb;
  Tfloat textrs, textgs, textbs;
  Tfloat textspace;
  Tfloat textexpan;
  int    textstyle, textdisplaytype;
  Tint   textzoomable;
  Tfloat textangle;
  OSD_FontAspect textfontaspect;
  /* Flag de mise a jour des composants materiel */
  Tint lightbool = 0x0;
  CALL_DEF_TRANSFORM_PERSISTENCE transPers =  astructure->TransformPersistence;

  /* Destruction */
  if( astructure->ContextLine.IsDef == -1 )
  {
  }
  if( astructure->ContextFillArea.IsDef == -1 )
  {
  }
  if( astructure->ContextMarker.IsDef == -1 )
  {
  }
  if( astructure->ContextText.IsDef == -1 )
  {
  }
  call_func_open_struct( astructure->Id );
  call_func_set_elem_ptr( 0 );
  call_func_set_elem_ptr_label( Structure_LABTransPersistence );
  if( astructure->TransformPersistence.IsSet == 1 )
  {
    call_func_set_edit_mode( CALL_PHIGS_EDIT_REPLACE );
    call_func_offset_elem_ptr( 1 );
  }
  else
    call_func_set_edit_mode( CALL_PHIGS_EDIT_INSERT );
  /*call_func_set_transform_persistence( transPersFlag );*/
  call_func_set_transform_persistence( transPers.Flag, transPers.Point.x, transPers.Point.y, transPers.Point.z );
  call_func_close_struct();
  /* }*/
  /* ABD 29/10/04  Transform Persistence of Presentation( pan, zoom, rotate ) */
  if( astructure->ContextLine.IsDef == 1 )
  {
    liner = astructure->ContextLine.Color.r;
    lineg = astructure->ContextLine.Color.g;
    lineb = astructure->ContextLine.Color.b;

    switch( astructure->ContextLine.LineType )
    {
    case 0 : /* Aspect_TOL_SOLID */
      linetype = CALL_PHIGS_LINE_SOLID;
      break;
    case 1 : /* Aspect_TOL_DASH */
      linetype = CALL_PHIGS_LINE_DASH;
      break;
    case 2 : /* Aspect_TOL_DOT */
      linetype = CALL_PHIGS_LINE_DOT;
      break;
    case 3 : /* Aspect_TOL_DOTDASH */
      linetype = CALL_PHIGS_LINE_DASH_DOT;
      break;
    default :
      break;
    }

    linewidth = (Tfloat)astructure->ContextLine.Width;

    if( astructure->ContextLine.IsSet )
      call_func_set_edit_mode( CALL_PHIGS_EDIT_REPLACE );
    else
      call_func_set_edit_mode( CALL_PHIGS_EDIT_INSERT );
    call_func_open_struct( astructure->Id );
    call_func_set_elem_ptr( 0 );
    call_func_set_elem_ptr_label( Structure_LABContextLine );

    if( astructure->ContextLine.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_subr_set_line_colr( liner, lineg, lineb );
    if( astructure->ContextLine.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_linetype( linetype );
    if( astructure->ContextLine.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_linewidth( linewidth );
    call_func_close_struct();
  }

  if( astructure->ContextFillArea.IsDef == 1 )
  {
    switch( astructure->ContextFillArea.Style )
    {
    case 0 : /* Aspect_IS_EMPTY */
      intstyle = CALL_PHIGS_STYLE_EMPTY;
      break;
    case 1 : /* Aspect_IS_HOLLOW */
      intstyle = CALL_PHIGS_STYLE_HOLLOW;
      break;
    case 2 : /* Aspect_IS_HATCH */
      intstyle = CALL_PHIGS_STYLE_HATCH;
      break;
    case 3 : /* Aspect_IS_SOLID */
      intstyle = CALL_PHIGS_STYLE_SOLID;
      break;
    case 4 : /* Aspect_IS_HIDDENLINE */
      intstyle = CALL_PHIGS_STYLE_HIDDENLINE;
      break;
    default :
      break;
    }

    switch( astructure->ContextFillArea.Hatch )
    {
    case 0 : /* Aspect_HS_HORIZONTAL */
      hatch = CALL_PHIGS_HATCH_HORIZ;
      break;
    case 1 : /* Aspect_HS_HORIZONTAL_WIDE */
      hatch = CALL_PHIGS_HATCH_HORIZ_DBL;
      break;
    case 2 : /* Aspect_HS_VERTICAL */
      hatch = CALL_PHIGS_HATCH_VERT;
      break;
    case 3 : /* Aspect_HS_VERTICAL_WIDE */
      hatch = CALL_PHIGS_HATCH_VERT_DBL;
      break;
    case 4 : /* Aspect_HS_DIAGONAL_45 */
      hatch = CALL_PHIGS_HATCH_DIAG_45;
      break;
    case 5 : /* Aspect_HS_DIAGONAL_45_WIDE */
      hatch = CALL_PHIGS_HATCH_DIAG_45_DBL;
      break;
    case 6 : /* Aspect_HS_DIAGONAL_135 */
      hatch = CALL_PHIGS_HATCH_DIAG_135;
      break;
    case 7 : /* Aspect_HS_DIAGONAL_135_WIDE */
      hatch = CALL_PHIGS_HATCH_DIAG_135_DBL;
      break;
    case 8 : /* Aspect_HS_GRID */
      hatch = CALL_PHIGS_HATCH_GRID_R;
      break;
    case 9 : /* Aspect_HS_GRID_WIDE */
      hatch = CALL_PHIGS_HATCH_GRID_R_DBL;
      break;
    case 10 : /* Aspect_HS_GRID_DIAGONAL */
      hatch = CALL_PHIGS_HATCH_GRID_D;
      break;
    case 11 : /* Aspect_HS_GRID_DIAGONAL_WIDE */
      hatch = CALL_PHIGS_HATCH_GRID_D_DBL;
      break;
    default :
      break;
    }

    fillr = astructure->ContextFillArea.IntColor.r;
    fillg = astructure->ContextFillArea.IntColor.g;
    fillb = astructure->ContextFillArea.IntColor.b;

#ifdef OCC1174
    fillBackr = astructure->ContextFillArea.BackIntColor.r;
    fillBackg = astructure->ContextFillArea.BackIntColor.g;
    fillBackb = astructure->ContextFillArea.BackIntColor.b;
#endif

    liner = astructure->ContextFillArea.EdgeColor.r;
    lineg = astructure->ContextFillArea.EdgeColor.g;
    lineb = astructure->ContextFillArea.EdgeColor.b;

    /* OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets */
    polyOffsetMode   = astructure->ContextFillArea.PolygonOffsetMode;
    polyOffsetFactor = astructure->ContextFillArea.PolygonOffsetFactor;
    polyOffsetUnits  = astructure->ContextFillArea.PolygonOffsetUnits;
    /* OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets */

    switch( astructure->ContextFillArea.LineType )
    {
    case 0 : /* Aspect_TOL_SOLID */
      linetype = CALL_PHIGS_LINE_SOLID;
      break;
    case 1 : /* Aspect_TOL_DASH */
      linetype = CALL_PHIGS_LINE_DASH;
      break;
    case 2 : /* Aspect_TOL_DOT */
      linetype = CALL_PHIGS_LINE_DOT;
      break;
    case 3 : /* Aspect_TOL_DOTDASH */
      linetype = CALL_PHIGS_LINE_DASH_DOT;
      break;
    default :
      break;
    }

    linewidth = (Tfloat)astructure->ContextFillArea.Width;

    if( astructure->ContextFillArea.IsSet )
      call_func_set_edit_mode( CALL_PHIGS_EDIT_REPLACE );
    else
      call_func_set_edit_mode( CALL_PHIGS_EDIT_INSERT );
    call_func_open_struct( astructure->Id );
    call_func_set_elem_ptr( 0 );
    call_func_set_elem_ptr_label( Structure_LABContextFillArea );

    /* interior */
    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_int_style( intstyle );
    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_subr_set_int_colr( fillr, fillg, fillb, ( float )1.0 );
    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
#ifdef OCC1174
    call_subr_set_back_int_colr( fillBackr, fillBackg, fillBackb, ( float )1.0 );
#else
    call_subr_set_back_int_colr( fillr, fillg, fillb, ( float )1.0 );
#endif
    /* edge */
    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    if( astructure->ContextFillArea.Edge )
      call_func_set_edge_flag( CALL_PHIGS_EDGE_ON );
    else
      call_func_set_edge_flag( CALL_PHIGS_EDGE_OFF );
    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_subr_set_edge_colr( liner, lineg, lineb );
    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_edge_type( linetype );
    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_edgewidth( linewidth );
    /* hatch */
    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    if( intstyle == CALL_PHIGS_STYLE_HATCH )
      call_func_set_int_style_ind( hatch );
    else
      call_func_appl_data( 0 );
    /* front and back face */
    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    if( astructure->ContextFillArea.Distinguish )
      call_func_set_face_disting_mode(CALL_PHIGS_DISTING_YES);
    else
      call_func_set_face_disting_mode(CALL_PHIGS_DISTING_NO);
    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    if( astructure->ContextFillArea.BackFace )
      call_func_set_face_cull_mode(CALL_PHIGS_CULL_BACKFACE);
    else
      call_func_set_face_cull_mode( CALL_PHIGS_CULL_NONE );
    /* front face */
    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );

    /* Front face */
    /* Gestion Lumiere */
    if( astructure->ContextFillArea.Front.IsAmbient ) 
      lightbool = lightbool | AMBIENT_MASK;                

    if( astructure->ContextFillArea.Front.IsDiffuse )
      lightbool = lightbool | DIFFUSE_MASK;        

    if( astructure->ContextFillArea.Front.IsSpecular )
      lightbool = lightbool | SPECULAR_MASK;          

    if( astructure->ContextFillArea.Front.IsEmission )
      lightbool = lightbool | EMISSIVE_MASK;                                       

    if( !lightbool )
      call_func_set_refl_eqn( CALL_PHIGS_REFL_NONE );
    else
      call_func_set_refl_eqn( lightbool );

    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_subr_set_refl_props( &astructure->ContextFillArea.Front, 0 );

    /* back face */
    /* Gestion lumiere */
    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );

    if( astructure->ContextFillArea.Back.IsAmbient )
      lightbool = lightbool | AMBIENT_MASK;           

    if( astructure->ContextFillArea.Back.IsDiffuse )
      lightbool = lightbool | DIFFUSE_MASK;           

    if( astructure->ContextFillArea.Back.IsSpecular )
      lightbool = lightbool | SPECULAR_MASK;         

    if( astructure->ContextFillArea.Back.IsEmission )
      lightbool = lightbool | EMISSIVE_MASK;          

    if( !lightbool ) 
      call_func_set_back_refl_eqn( CALL_PHIGS_REFL_NONE );
    else
      call_func_set_back_refl_eqn( lightbool );

    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_subr_set_refl_props( &astructure->ContextFillArea.Back, 1 );

    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_do_texturemap(astructure->ContextFillArea.Texture.doTextureMap);

    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_texture_id(astructure->ContextFillArea.Texture.TexId);

    /* OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets */
    if( astructure->ContextFillArea.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_polygon_offset_params( polyOffsetMode, polyOffsetFactor, polyOffsetUnits );
    /* OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets */
    call_func_close_struct();
  }

  if( astructure->ContextMarker.IsDef == 1 )
  {
    markr = astructure->ContextMarker.Color.r;
    markg = astructure->ContextMarker.Color.g;
    markb = astructure->ContextMarker.Color.b;

    switch( astructure->ContextMarker.MarkerType )
    {
    case 0 : /* Aspect_TOM_POINT */
      markertype = CALL_PHIGS_MARKER_DOT;
      break;
    case 1 : /* Aspect_TOM_PLUS */
      markertype = CALL_PHIGS_MARKER_PLUS;
      break;
    case 2 : /* Aspect_TOM_STAR */
      markertype = CALL_PHIGS_MARKER_ASTERISK;
      break;
    case 3 : /* Aspect_TOM_O */
      markertype = CALL_PHIGS_MARKER_CIRCLE;
      break;
    case 4 : /* Aspect_TOM_X */
      markertype = CALL_PHIGS_MARKER_CROSS;
      break;
    case 5 : /* Aspect_TOM_USERDEFINED*/
      markertype = CALL_PHIGS_MARKER_USER_DEFINED;
      break;
    default :
      printf( "\n\tINVALID MARKER TYPE %d",
        astructure->ContextMarker.MarkerType );
      break;
    }

    markerscale = (Tfloat)astructure->ContextMarker.Scale;

    if( astructure->ContextMarker.IsSet )
      call_func_set_edit_mode( CALL_PHIGS_EDIT_REPLACE );
    else
      call_func_set_edit_mode( CALL_PHIGS_EDIT_INSERT );
    call_func_open_struct( astructure->Id );
    call_func_set_elem_ptr( 0 );
    call_func_set_elem_ptr_label( Structure_LABContextMarker );
    if( astructure->ContextMarker.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_subr_set_marker_colr( markr, markg, markb );
    if( astructure->ContextMarker.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_marker_type( markertype );
    if( astructure->ContextMarker.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_marker_size( markerscale );
    call_func_close_struct();
  }

#ifdef TRACE     
  cout << "TKOpenGl::OpenGl_togl_contextstructure"
    << "\t is defined : " << astructure->ContextText.IsDef << endl; 
#endif    
  if( astructure->ContextText.IsDef == 1 )
  {
    textr = astructure->ContextText.Color.r;
    textg = astructure->ContextText.Color.g;
    textb = astructure->ContextText.Color.b;

    textrs = astructure->ContextText.ColorSubTitle.r;
    textgs = astructure->ContextText.ColorSubTitle.g;
    textbs = astructure->ContextText.ColorSubTitle.b;

    fontid = new Tchar[strlen((char*)astructure->ContextText.Font)+1];
    strcpy((char*)fontid,(char*)astructure->ContextText.Font);

    textspace = (Tfloat)astructure->ContextText.Space;
    textexpan = (Tfloat)astructure->ContextText.Expan;
    textstyle = (int) astructure->ContextText.Style;
    textdisplaytype = (int) astructure->ContextText.DisplayType;    
    textzoomable = (int) astructure->ContextText.TextZoomable;
    textangle = (float) astructure->ContextText.TextAngle;
    textfontaspect = (OSD_FontAspect)astructure->ContextText.TextFontAspect;

    if( astructure->ContextText.IsSet )
      call_func_set_edit_mode( CALL_PHIGS_EDIT_REPLACE );
    else
      call_func_set_edit_mode( CALL_PHIGS_EDIT_INSERT );
    call_func_open_struct( astructure->Id );
    call_func_set_elem_ptr( 0 );
    call_func_set_elem_ptr_label( Structure_LABContextText );
    if( astructure->ContextText.IsSet )
      call_func_offset_elem_ptr( 1 );              
    call_func_set_text_zoomable( textzoomable );
    call_func_set_text_angle( textangle );
    call_func_set_text_fontaspect( textfontaspect );

    if( astructure->ContextText.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_text_font( fontid );
    if( astructure->ContextText.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_char_space( textspace );
    if( astructure->ContextText.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_char_expan( textexpan );
    if( astructure->ContextText.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_subr_set_text_colr( textr, textg, textb );
    if( astructure->ContextText.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_text_style( textstyle );
    if( astructure->ContextText.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_func_set_text_display_type( textdisplaytype );
    if( astructure->ContextText.IsSet )
      call_func_offset_elem_ptr( 1 );
    call_subr_set_text_colr_subtitle( textrs, textgs, textbs );

    call_func_close_struct();
  }
  return;
}