Merging OCC22105, OCC22354, OCC22150 , OCC22199 , OCC22391 and OCC22108
[occt.git] / src / OpenGl / OpenGl_addnames.cxx
1
2 #include <OpenGl_tgl_all.hxx>
3
4 #include <stddef.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7
8 #include <OpenGl_cmn_varargs.hxx>
9 #include <OpenGl_telem_attri.hxx>
10 #include <OpenGl_telem_filters.hxx>
11 #include <OpenGl_tsm.hxx>
12 #include <OpenGl_telem.hxx>
13 #include <OpenGl_telem_inquire.hxx>
14
15 static  TStatus  AddNamesetDisplay( TSM_ELEM_DATA, Tint, cmn_key* );
16 static  TStatus  AddNamesetAdd( TSM_ELEM_DATA, Tint, cmn_key* );
17 static  TStatus  AddNamesetDelete( TSM_ELEM_DATA, Tint, cmn_key* );
18 static  TStatus  AddNamesetPrint( TSM_ELEM_DATA, Tint, cmn_key* );
19 static  TStatus  AddNamesetInquire( TSM_ELEM_DATA, Tint, cmn_key* );
20
21 static  TStatus  (*MtdTbl[])( TSM_ELEM_DATA, Tint, cmn_key* ) =
22 {
23   AddNamesetDisplay,             /* PickTraverse */
24   AddNamesetDisplay,
25   AddNamesetAdd,
26   AddNamesetDelete,
27   AddNamesetPrint,
28   AddNamesetInquire
29 };
30
31 MtblPtr
32 TelAddNamesetInitClass( TelType* el )
33 {
34   *el = TelAddNameset;
35   return MtdTbl;
36 }
37
38 static  TStatus
39 AddNamesetAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k )
40 {
41   Tint  i, num, *ptr;
42   tel_tint_data  data;
43
44   num = k[0]->id;
45   data = new TEL_TINT_DATA();
46   if( !data )
47     return TFailure;
48
49   data->data  = new int[num];
50   if( !data->data )
51     return TFailure;
52
53   for( i=0, ptr=(Tint*)(k[0]->data.pdata); i<num; i++ )
54   {
55     data->data[i] = ptr[i];
56   }
57   data->num = num;
58
59   ((tsm_elem_data)(d.pdata))->pdata = data;
60
61   return TSuccess;
62 }
63
64
65 static  TStatus
66 AddNamesetDisplay( TSM_ELEM_DATA data, Tint n, cmn_key *k )
67 {
68   tel_tint_data d;
69
70   d = (tel_tint_data)data.pdata;
71   TglNamesetAdd( d->num, d->data );
72   return  TSuccess;
73 }
74
75 static  TStatus
76 AddNamesetDelete( TSM_ELEM_DATA data, Tint n, cmn_key *k )
77 {
78   if (data.pdata)
79     delete data.pdata;
80   return TSuccess;
81 }
82
83
84
85
86 static  TStatus
87 AddNamesetPrint( TSM_ELEM_DATA data, Tint n, cmn_key *k )
88 {
89   Tint           i;
90   tel_tint_data  p;
91
92   p = (tel_tint_data)data.pdata;
93
94   fprintf( stdout, "TelAddNameset. Number: %d\n", p->num );
95   for( i = 0; i < p->num; i++ )
96   {
97     fprintf( stdout, "\n\t\t v[%d] = %d", i, p->data[i] );
98   }
99   fprintf( stdout, "\n" );
100
101   return TSuccess;
102 }
103
104
105 static TStatus
106 AddNamesetInquire( TSM_ELEM_DATA data, Tint n, cmn_key *k )
107 {
108   Tint          i;
109   tel_tint_data d;
110   Tint          size_reqd = 0;
111   TStatus       status = TSuccess;
112
113   d = (tel_tint_data)data.pdata;
114
115   size_reqd = d->num * sizeof( Tint );
116
117   for( i = 0; i < n; i++ )
118   {
119     switch( k[i]->id )
120     {
121     case INQ_GET_SIZE_ID:
122       {
123         k[i]->data.ldata = size_reqd;
124         break;
125       }
126
127     case INQ_GET_CONTENT_ID:
128       {
129         TEL_INQ_CONTENT *c;
130         Teldata         *w;
131
132         c = (tel_inq_content)k[i]->data.pdata;
133         c->act_size = size_reqd;
134         w = c->data;
135
136         w->name_set.number = d->num;
137         if( c->size >= size_reqd )
138         {
139           w->name_set.integers = (Tint *)(c->buf);
140           //cmn_memcpy(w->name_set.integers, d->data, d->num);
141           memcpy( w->name_set.integers, d->data, d->num*sizeof(int) );
142           status = TSuccess;
143         }
144         else
145           status = TFailure;
146         break;
147       }
148     }
149   }
150   return status;
151 }