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

FONCTION :
----------
File OpenGl_mrkr :


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_telem_highlight.hxx>
#include <OpenGl_tsm.hxx>
#include <OpenGl_telem.hxx>
#include <OpenGl_telem_inquire.hxx>

extern GLuint GetListIndex(int);


static  TStatus  MarkerDisplay( TSM_ELEM_DATA, Tint, cmn_key* );
static  TStatus  MarkerAdd( TSM_ELEM_DATA, Tint, cmn_key* );
static  TStatus  MarkerDelete( TSM_ELEM_DATA, Tint, cmn_key* );
static  TStatus  MarkerPrint( TSM_ELEM_DATA, Tint, cmn_key* );
static  TStatus  MarkerInquire( TSM_ELEM_DATA, Tint, cmn_key* );

/*static  GLboolean         lighting_mode;*/

static  TStatus  (*MtdTbl[])( TSM_ELEM_DATA, Tint, cmn_key* ) =
{
  MarkerDisplay,             /* PickTraverse */
    MarkerDisplay,
    MarkerAdd,
    MarkerDelete,
    MarkerPrint,
    MarkerInquire
};


MtblPtr
TelMarkerInitClass( TelType *el )
{
  *el = TelMarker;
  return MtdTbl;
}

static  TStatus
MarkerAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k )
{
  tel_point data = new TEL_POINT;

  if( !data )
    return TFailure;

  *data = *(tel_point)(k[0]->data.pdata);

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

  return TSuccess;
}

extern GLuint markerBase;
static  TStatus
MarkerDisplay( TSM_ELEM_DATA data, Tint n, cmn_key *k )
{
  tel_point  p;
  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 );
  p = (tel_point)data.pdata;
  if( key2.data.ldata == TEL_PM_DOT )
  {
    glPointSize( key3.data.fdata );
    glBegin( GL_POINTS );
    glVertex3fv( p->xyz );
    glEnd();
  }
  else
  {
    GLint mode;
    glGetIntegerv( GL_RENDER_MODE, &mode );
    if( key2.data.ldata == TEL_PM_USERDEFINED )
    {       
      glRasterPos3f( (GLfloat)(p->xyz[0]),  
        (GLfloat)(p->xyz[1]),
        (GLfloat)(p->xyz[2]) );
      glCallList( GetListIndex( (int)key3.data.fdata ) );       
    }
    else
    {
      str = TelGetStringForPM( key2.data.ldata, key3.data.fdata );
      glRasterPos3f( (GLfloat)(p->xyz[0]),  (GLfloat)(p->xyz[1]),
        (GLfloat)(p->xyz[2]) );
      glListBase(markerBase);
      glCallLists(strlen( (char*)str ), GL_UNSIGNED_BYTE, (GLubyte *) str );
    }

    if( mode==GL_FEEDBACK )
    {
      glBegin( GL_POINTS );
      glVertex3f( p->xyz[0], p->xyz[1], p->xyz[2] );
      glEnd();
      /* it is necessary to indicate end of marker information*/
    }
  }

  return TSuccess;
}


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




static  TStatus
MarkerPrint( TSM_ELEM_DATA data, Tint n, cmn_key *k )
{
  tel_point p;

  p = (tel_point)data.pdata;

  fprintf( stdout, "TelMarker. Value = %g, %g, %g\n",
    p->xyz[0], p->xyz[1], p->xyz[2] );
  fprintf( stdout, "\n" );

  return TSuccess;
}


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

  d = (tel_point)data.pdata;

  size_reqd = 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);
          *(w->pts3) = *d;
          status = TSuccess;
        }
        else
          status = TFailure;
        break;
      }
    }
  }
  return status;
}