summaryrefslogtreecommitdiff
path: root/src/OpenGl/OpenGl_mrkrset.cxx
blob: d95a9d987c4f8cbb1744065cca899b18e5c363a7 (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
/***********************************************************************

FONCTION :
----------
File OpenGl_mrkrset :


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


HISTORIQUE DES MODIFICATIONS   :
--------------------------------
xx-xx-xx : xxx ; Creation.
11-03-96 : FMN ; Correction warning compilation
01-04-96 : CAL ; Integration MINSK portage WNT
08-07-96 : BGN ; (PRO4768) suppression du cas particulier TEL_PM_DOT.
21-10-96 : FMN ; Suppression LMC_COLOR fait dans OpenGl_execstruct.c
19-10-96 : CAL ; Restauration du cas particulier TEL_PM_DOT mais
avec la correction sur la mise a jour du pointSize.

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

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


#include <OpenGl_tgl_all.hxx>

#include <stddef.h>
#include <stdio.h>
#include <string.h>

#include <GL/gl.h>
#include <GL/glu.h>

#include <OpenGl_cmn_varargs.hxx>
#include <OpenGl_telem_attri.hxx>
#include <OpenGl_tsm.hxx>
#include <OpenGl_telem.hxx>
#include <OpenGl_telem_highlight.hxx>
#include <OpenGl_telem_inquire.hxx>

static  TStatus  MarkerSetDisplay( TSM_ELEM_DATA, Tint, cmn_key* );
static  TStatus  MarkerSetAdd( TSM_ELEM_DATA, Tint, cmn_key* );
static  TStatus  MarkerSetDelete( TSM_ELEM_DATA, Tint, cmn_key* );
static  TStatus  MarkerSetPrint( TSM_ELEM_DATA, Tint, cmn_key* );
static  TStatus  MarkerSetInquire( TSM_ELEM_DATA, Tint, cmn_key* );


extern GLuint GetListIndex(int);

static  TStatus  (*MtdTbl[])( TSM_ELEM_DATA, Tint, cmn_key* ) =
{
  MarkerSetDisplay,             /* PickTraverse */
  MarkerSetDisplay,
  MarkerSetAdd,
  MarkerSetDelete,
  MarkerSetPrint,
  MarkerSetInquire
};


MtblPtr
TelMarkerSetInitClass( TelType* el )
{
  *el = TelMarkerSet;
  return MtdTbl;
}

extern GLuint markerBase;
static  TStatus
MarkerSetAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k )
{
  Tint  i, num;
  tel_point_data  data;
  tel_point       ptr;

  num = k[0]->id;
  data = new TEL_POINT_DATA();
  if( !data )
    return TFailure;

  data->data = new TEL_POINT[num];
  if( !data->data )
    return TFailure;

  for( i=0, ptr=(tel_point)(k[0]->data.pdata); i<num; i++ )
  {
    data->data[i] = ptr[i];
  }
  data->num = num;

  ((tsm_elem_data)(d.pdata))->pdata = data;

  return TSuccess;
}


static  TStatus
MarkerSetDisplay( TSM_ELEM_DATA data, Tint n, cmn_key *k )
{
  tel_point_data  d;
  tel_point       ptr;
  Tint            i;
  CMN_KEY         key1, key2, key3;
  TEL_COLOUR      colour;
  Tchar           *str;

  key1.id         = TelPolymarkerColour;
  key1.data.pdata = &colour;

  key2.id = TelPolymarkerType;
  key3.id = TelPolymarkerSize;
  TsmGetAttri( 3, &key1, &key2, &key3 );

  if( k[0]->id == TOn )
  {                          /* Use highlight colours */
    TEL_HIGHLIGHT  hrep;

    key1.id = TelHighlightIndex;
    TsmGetAttri( 1, &key1 );
    if( TelGetHighlightRep( TglActiveWs, key1.data.ldata, &hrep )
      == TSuccess )
      colour = hrep.col;
    else
    {
      TelGetHighlightRep( TglActiveWs, 0, &hrep );
      colour = hrep.col;
    }
  }

  glColor3fv( colour.rgb );
  d = (tel_point_data)data.pdata;
  ptr = d->data;

  if( key2.data.ldata == TEL_PM_DOT )
  {
    glPointSize( key3.data.fdata );
    glBegin( GL_POINTS );
    for( i=0; i<d->num; i++, ptr++ )
      glVertex3f( ptr->xyz[0],  ptr->xyz[1],  ptr->xyz[2] );
    glEnd();
  }
  else
  {
    GLint mode;
    glGetIntegerv( GL_RENDER_MODE, &mode );

    if( key2.data.ldata == TEL_PM_USERDEFINED )
    {       
      for( i=0; i<d->num; i++, ptr++ )
      {
        glRasterPos3f( ptr->xyz[0],  ptr->xyz[1],  ptr->xyz[2] );
        glCallList( GetListIndex( (int)key3.data.fdata ) );
        if( mode==GL_FEEDBACK )
        {
          glBegin( GL_POINTS );
          glVertex3f( ptr->xyz[0], ptr->xyz[1], ptr->xyz[2] );
          glEnd();
          /* it is necessary to indicate end of marker information */
        }
      }
    }
    else
    {
      str = TelGetStringForPM( key2.data.ldata, key3.data.fdata );
      glListBase(markerBase);
      for( i=0; i<d->num; i++, ptr++ )
      {
        glRasterPos3f( ptr->xyz[0],  ptr->xyz[1],  ptr->xyz[2] );
        glCallLists(strlen( (char*)str ), GL_UNSIGNED_BYTE, (GLubyte *) str );

        if( mode==GL_FEEDBACK )
        {
          glBegin( GL_POINTS );
          glVertex3f( ptr->xyz[0], ptr->xyz[1], ptr->xyz[2] );
          glEnd();
        }
      }
    }
  }

  return TSuccess;
}


static  TStatus
MarkerSetDelete( TSM_ELEM_DATA data, Tint n, cmn_key *k )
{
  if (data.pdata)
    free(data.pdata);
  return TSuccess;
}




static  TStatus
MarkerSetPrint( TSM_ELEM_DATA data, Tint n, cmn_key *k )
{
  Tint           i;
  tel_point_data p;

  p = (tel_point_data)data.pdata;

  fprintf( stdout, "TelMarkerSet. Number of points: %d\n", p->num );
  for( i = 0; i < p->num; i++ )
  {
    fprintf( stdout, "\n\t\t v[%d] = %g %g %g", i, p->data[i].xyz[0],
      p->data[i].xyz[1], p->data[i].xyz[2] );
  }
  fprintf( stdout, "\n" );

  return TSuccess;
}


static TStatus
MarkerSetInquire( TSM_ELEM_DATA data, Tint n, cmn_key *k )
{
  Tint           i, j;
  tel_point_data d;
  Tint           size_reqd=0;
  TStatus        status = TSuccess;

  d = (tel_point_data)data.pdata;

  size_reqd  = d->num * sizeof( TEL_POINT );

  for( i = 0; i < n; i++ )
  {
    switch( k[i]->id )
    {
    case INQ_GET_SIZE_ID:
      {
        k[i]->data.ldata = size_reqd;
        break;
      }

    case INQ_GET_CONTENT_ID:
      {
        TEL_INQ_CONTENT *c;
        Teldata         *w;

        c = (tel_inq_content)k[i]->data.pdata;
        c->act_size = size_reqd;
        w = c->data;

        if( c->size >= size_reqd )
        {
          w->pts3 = (tel_point)(c->buf);

          for( j = 0; j < d->num; j++ )
            w->pts3[j] = d->data[j];

          status = TSuccess;
        }
        else
          status = TFailure;
        break;
      }
    }
  }
  return status;
}