cow_pn_gsdml_attrnav.cpp 154 KB
Newer Older
Claes Sjofors's avatar
Claes Sjofors committed
1
/* 
Claes Sjofors's avatar
Claes Sjofors committed
2
 * Proview   Open Source Process Control.
3
 * Copyright (C) 2005-2017 SSAB EMEA AB.
Claes Sjofors's avatar
Claes Sjofors committed
4 5
 *
 * This file is part of Proview.
Claes Sjofors's avatar
Claes Sjofors committed
6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License as 
 * published by the Free Software Foundation, either version 2 of 
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License 
Claes Sjofors's avatar
Claes Sjofors committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
 * along with Proview. If not, see <http://www.gnu.org/licenses/>
 *
 * Linking Proview statically or dynamically with other modules is
 * making a combined work based on Proview. Thus, the terms and 
 * conditions of the GNU General Public License cover the whole 
 * combination.
 *
 * In addition, as a special exception, the copyright holders of
 * Proview give you permission to, from the build function in the
 * Proview Configurator, combine Proview with modules generated by the
 * Proview PLC Editor to a PLC program, regardless of the license
 * terms of these modules. You may copy and distribute the resulting
 * combined work under the terms of your choice, provided that every 
 * copy of the combined work is accompanied by a complete copy of 
 * the source code of Proview (the version used to produce the 
 * combined work), being distributed under the terms of the GNU 
 * General Public License plus this exception.
Claes Sjofors's avatar
Claes Sjofors committed
35 36
 **/

37
/* cow_pn_gsdml_attrnav.cpp -- Display gsd attributes */
Claes Sjofors's avatar
Claes Sjofors committed
38 39 40 41 42 43 44 45

#include "glow_std.h"

#include <vector>
#include <stdio.h>
#include <stdlib.h>

#include "co_cdh.h"
46
#include "co_dcli.h"
Claes Sjofors's avatar
Claes Sjofors committed
47
#include "co_time.h"
48
#include "cow_wow.h"
Claes Sjofors's avatar
Claes Sjofors committed
49 50 51 52 53 54 55 56 57 58
#include "flow.h"
#include "flow_browctx.h"
#include "flow_browapi.h"
#include "flow_msg.h"

#include "glow.h"
#include "glow_growctx.h"
#include "glow_growapi.h"


59 60 61
#include "cow_pn_gsdml.h"
#include "cow_pn_gsdml_attr.h"
#include "cow_pn_gsdml_attrnav.h"
Claes Sjofors's avatar
Claes Sjofors committed
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
#include "rt_pb_msg.h"

#include "xnav_bitmap_leaf8.h"
#include "xnav_bitmap_leaf10.h"
#include "xnav_bitmap_leaf12.h"
#include "xnav_bitmap_leaf14.h"
#include "xnav_bitmap_leaf16.h"
#include "xnav_bitmap_leaf18.h"
#include "xnav_bitmap_leaf20.h"
#include "xnav_bitmap_leaf24.h"
#include "xnav_bitmap_map8.h"
#include "xnav_bitmap_map10.h"
#include "xnav_bitmap_map12.h"
#include "xnav_bitmap_map14.h"
#include "xnav_bitmap_map16.h"
#include "xnav_bitmap_map18.h"
#include "xnav_bitmap_map20.h"
#include "xnav_bitmap_map24.h"
#include "xnav_bitmap_openmap8.h"
#include "xnav_bitmap_openmap10.h"
#include "xnav_bitmap_openmap12.h"
#include "xnav_bitmap_openmap14.h"
#include "xnav_bitmap_openmap16.h"
#include "xnav_bitmap_openmap18.h"
#include "xnav_bitmap_openmap20.h"
#include "xnav_bitmap_openmap24.h"
#include "xnav_bitmap_attr8.h"
#include "xnav_bitmap_attr10.h"
#include "xnav_bitmap_attr12.h"
#include "xnav_bitmap_attr14.h"
#include "xnav_bitmap_attr16.h"
#include "xnav_bitmap_attr18.h"
#include "xnav_bitmap_attr20.h"
#include "xnav_bitmap_attr24.h"
#include "xnav_bitmap_attrarra8.h"
#include "xnav_bitmap_attrarra10.h"
#include "xnav_bitmap_attrarra12.h"
#include "xnav_bitmap_attrarra14.h"
#include "xnav_bitmap_attrarra16.h"
#include "xnav_bitmap_attrarra18.h"
#include "xnav_bitmap_attrarra20.h"
#include "xnav_bitmap_attrarra24.h"
#include "xnav_bitmap_attrenum8.h"
#include "xnav_bitmap_attrenum10.h"
#include "xnav_bitmap_attrenum12.h"
#include "xnav_bitmap_attrenum14.h"
#include "xnav_bitmap_attrenum16.h"
#include "xnav_bitmap_attrenum18.h"
#include "xnav_bitmap_attrenum20.h"
#include "xnav_bitmap_attrenum24.h"

#define ATTRNAV__INPUT_SYNTAX 2
#define ATTRNAV__OBJNOTFOUND 4
#define ATTRNAV__STRINGTOLONG 6
#define ATTRNAV__ITEM_NOCREA 8
#define ATTRNAV__SUCCESS 1

static char null_str[] = "";


//
// Convert attribute string to value
//
int GsdmlAttrNav::attr_string_to_value( int type_id, char *value_str, 
				      void *buffer_ptr, int buff_size, int attr_size)
{

  switch ( type_id ) {
  case pwr_eType_Boolean: {
    if ( sscanf( value_str, "%d", (pwr_tBoolean *)buffer_ptr) != 1)
      return ATTRNAV__INPUT_SYNTAX;
    if ( *(pwr_tBoolean *)buffer_ptr > 1)
      return ATTRNAV__INPUT_SYNTAX;
    break;
  }
  case pwr_eType_Float32: {
    pwr_tFloat32 f;
    if ( sscanf( value_str, "%f", &f) != 1)
      return ATTRNAV__INPUT_SYNTAX;
    memcpy( buffer_ptr, (char *) &f, sizeof(f));
    
    break;
  }
  case pwr_eType_Int32: {
    if ( sscanf( value_str, "%d", (int *)buffer_ptr) != 1)
      return ATTRNAV__INPUT_SYNTAX;
    break;
  }
  case pwr_eType_UInt32: {
    if ( sscanf( value_str, "%u", (int *)buffer_ptr) != 1)
      return ATTRNAV__INPUT_SYNTAX;
    break;
  }
  case pwr_eType_String: {
    if ( (int) strlen( value_str) >= attr_size)
      return ATTRNAV__STRINGTOLONG;
    strncpy( (char *)buffer_ptr, value_str, min(attr_size, buff_size));
    break;
  }
  }
  return 1;
}

//
// Convert attribute value to string
//
void GsdmlAttrNav::attrvalue_to_string( int type_id, void *value_ptr, 
				      char *str, int size, int *len, char *format)
{

  if ( value_ptr == 0)  {
    strcpy( str, "UNDEFINED");
    return;
  }

  switch ( type_id ) {
  case pwr_eType_Boolean: {
    if ( !format)
      *len = sprintf( str, "%d", *(pwr_tBoolean *)value_ptr);
    else
      *len = sprintf( str, format, *(pwr_tBoolean *)value_ptr);
    break;
  }
  case pwr_eType_Float32:{
    if ( !format)
      *len = sprintf( str, "%f", *(float *)value_ptr);
    else
        *len = sprintf( str, format, *(float *)value_ptr);
    break;
  }
Claes Sjofors's avatar
Claes Sjofors committed
192 193 194 195 196 197 198
  case pwr_eType_UInt8: {
    if ( !format)
      *len = sprintf( str, "%hhu", *(pwr_tUInt8 *)value_ptr);
    else
      *len = sprintf( str, format, *(pwr_tUInt8 *)value_ptr);
    break;
  }
Claes Sjofors's avatar
Claes Sjofors committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212
  case pwr_eType_UInt16: {
    if ( !format)
      *len = sprintf( str, "%hu", *(pwr_tUInt16 *)value_ptr);
    else
      *len = sprintf( str, format, *(pwr_tUInt16 *)value_ptr);
    break;
  }
  case pwr_eType_UInt32: {
    if ( !format)
      *len = sprintf( str, "%u", *(int *)value_ptr);
    else
      *len = sprintf( str, format, *(int *)value_ptr);
    break;
  }
Claes Sjofors's avatar
Claes Sjofors committed
213 214 215 216 217 218 219
  case pwr_eType_Int8: {
    if ( !format)
      *len = sprintf( str, "%hhd", *(pwr_tInt8 *)value_ptr);
    else
      *len = sprintf( str, format, *(pwr_tInt8 *)value_ptr);
    break;
  }
Claes Sjofors's avatar
Claes Sjofors committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
  case pwr_eType_Int16: {
    if ( !format)
      *len = sprintf( str, "%hd", *(pwr_tInt16 *)value_ptr);
    else
      *len = sprintf( str, format, *(pwr_tInt16 *)value_ptr);
    break;
  }
  case pwr_eType_Int32: {
    if ( !format)
      *len = sprintf( str, "%d", *(int *)value_ptr);
    else
      *len = sprintf( str, format, *(int *)value_ptr);
    break;
  }
  case pwr_eType_String: {
    strncpy( str, (char *)value_ptr, size);
    str[size-1] = 0;
    *len = strlen(str);
    break;
  }
Claes Sjofors's avatar
Claes Sjofors committed
240 241 242
  default:
    *len = 0;
    str[0] = 0;
Claes Sjofors's avatar
Claes Sjofors committed
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
  }
}

void GsdmlAttrNav::message( char sev, const char *text)
{
  (message_cb)( parent_ctx, sev, text);
}

//
//  Free pixmaps
//
void GsdmlAttrNavBrow::free_pixmaps()
{
  brow_FreeAnnotPixmap( ctx, pixmap_leaf);
  brow_FreeAnnotPixmap( ctx, pixmap_map);
  brow_FreeAnnotPixmap( ctx, pixmap_openmap);
  brow_FreeAnnotPixmap( ctx, pixmap_attr);
  brow_FreeAnnotPixmap( ctx, pixmap_attrarray);
  brow_FreeAnnotPixmap( ctx, pixmap_attrenum);
}

//
//  Create pixmaps for leaf, closed map and open map
//
void GsdmlAttrNavBrow::allocate_pixmaps()
{
  flow_sPixmapData pixmap_data;
  int i;

  i = 0;
  pixmap_data[i].width =xnav_bitmap_leaf8_width;
  pixmap_data[i].height =xnav_bitmap_leaf8_height;
Claes Sjofors's avatar
Claes Sjofors committed
275
  pixmap_data[i++].bits = xnav_bitmap_leaf8_bits;
Claes Sjofors's avatar
Claes Sjofors committed
276 277
  pixmap_data[i].width =xnav_bitmap_leaf10_width;
  pixmap_data[i].height =xnav_bitmap_leaf10_height;
Claes Sjofors's avatar
Claes Sjofors committed
278
  pixmap_data[i++].bits = xnav_bitmap_leaf10_bits;
Claes Sjofors's avatar
Claes Sjofors committed
279 280
  pixmap_data[i].width =xnav_bitmap_leaf12_width;
  pixmap_data[i].height =xnav_bitmap_leaf12_height;
Claes Sjofors's avatar
Claes Sjofors committed
281
  pixmap_data[i++].bits = xnav_bitmap_leaf12_bits;
Claes Sjofors's avatar
Claes Sjofors committed
282 283
  pixmap_data[i].width =xnav_bitmap_leaf14_width;
  pixmap_data[i].height =xnav_bitmap_leaf14_height;
Claes Sjofors's avatar
Claes Sjofors committed
284
  pixmap_data[i++].bits = xnav_bitmap_leaf14_bits;
Claes Sjofors's avatar
Claes Sjofors committed
285 286
  pixmap_data[i].width =xnav_bitmap_leaf16_width;
  pixmap_data[i].height =xnav_bitmap_leaf16_height;
Claes Sjofors's avatar
Claes Sjofors committed
287
  pixmap_data[i++].bits = xnav_bitmap_leaf16_bits;
Claes Sjofors's avatar
Claes Sjofors committed
288 289
  pixmap_data[i].width =xnav_bitmap_leaf18_width;
  pixmap_data[i].height =xnav_bitmap_leaf18_height;
Claes Sjofors's avatar
Claes Sjofors committed
290
  pixmap_data[i++].bits = xnav_bitmap_leaf18_bits;
Claes Sjofors's avatar
Claes Sjofors committed
291 292
  pixmap_data[i].width =xnav_bitmap_leaf20_width;
  pixmap_data[i].height =xnav_bitmap_leaf20_height;
Claes Sjofors's avatar
Claes Sjofors committed
293
  pixmap_data[i++].bits = xnav_bitmap_leaf20_bits;
Claes Sjofors's avatar
Claes Sjofors committed
294 295
  pixmap_data[i].width =xnav_bitmap_leaf20_width;
  pixmap_data[i].height =xnav_bitmap_leaf20_height;
Claes Sjofors's avatar
Claes Sjofors committed
296
  pixmap_data[i++].bits = xnav_bitmap_leaf20_bits;
Claes Sjofors's avatar
Claes Sjofors committed
297 298
  pixmap_data[i].width =xnav_bitmap_leaf24_width;
  pixmap_data[i].height =xnav_bitmap_leaf24_height;
Claes Sjofors's avatar
Claes Sjofors committed
299
  pixmap_data[i++].bits = xnav_bitmap_leaf24_bits;
Claes Sjofors's avatar
Claes Sjofors committed
300 301 302 303 304 305

  brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_leaf);
  
  i = 0;
  pixmap_data[i].width =xnav_bitmap_map8_width;
  pixmap_data[i].height =xnav_bitmap_map8_height;
Claes Sjofors's avatar
Claes Sjofors committed
306
  pixmap_data[i++].bits = xnav_bitmap_map8_bits;
Claes Sjofors's avatar
Claes Sjofors committed
307 308
  pixmap_data[i].width =xnav_bitmap_map10_width;
  pixmap_data[i].height =xnav_bitmap_map10_height;
Claes Sjofors's avatar
Claes Sjofors committed
309
  pixmap_data[i++].bits = xnav_bitmap_map10_bits;
Claes Sjofors's avatar
Claes Sjofors committed
310 311
  pixmap_data[i].width =xnav_bitmap_map12_width;
  pixmap_data[i].height =xnav_bitmap_map12_height;
Claes Sjofors's avatar
Claes Sjofors committed
312
  pixmap_data[i++].bits = xnav_bitmap_map12_bits;
Claes Sjofors's avatar
Claes Sjofors committed
313 314
  pixmap_data[i].width =xnav_bitmap_map14_width;
  pixmap_data[i].height =xnav_bitmap_map14_height;
Claes Sjofors's avatar
Claes Sjofors committed
315
  pixmap_data[i++].bits = xnav_bitmap_map14_bits;
Claes Sjofors's avatar
Claes Sjofors committed
316 317
  pixmap_data[i].width =xnav_bitmap_map16_width;
  pixmap_data[i].height =xnav_bitmap_map16_height;
Claes Sjofors's avatar
Claes Sjofors committed
318
  pixmap_data[i++].bits = xnav_bitmap_map16_bits;
Claes Sjofors's avatar
Claes Sjofors committed
319 320
  pixmap_data[i].width =xnav_bitmap_map18_width;
  pixmap_data[i].height =xnav_bitmap_map18_height;
Claes Sjofors's avatar
Claes Sjofors committed
321
  pixmap_data[i++].bits = xnav_bitmap_map18_bits;
Claes Sjofors's avatar
Claes Sjofors committed
322 323
  pixmap_data[i].width =xnav_bitmap_map20_width;
  pixmap_data[i].height =xnav_bitmap_map20_height;
Claes Sjofors's avatar
Claes Sjofors committed
324
  pixmap_data[i++].bits = xnav_bitmap_map20_bits;
Claes Sjofors's avatar
Claes Sjofors committed
325 326
  pixmap_data[i].width =xnav_bitmap_map20_width;
  pixmap_data[i].height =xnav_bitmap_map20_height;
Claes Sjofors's avatar
Claes Sjofors committed
327
  pixmap_data[i++].bits = xnav_bitmap_map20_bits;
Claes Sjofors's avatar
Claes Sjofors committed
328 329
  pixmap_data[i].width =xnav_bitmap_map24_width;
  pixmap_data[i].height =xnav_bitmap_map24_height;
Claes Sjofors's avatar
Claes Sjofors committed
330
  pixmap_data[i++].bits = xnav_bitmap_map24_bits;
Claes Sjofors's avatar
Claes Sjofors committed
331 332 333 334 335 336
  
  brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_map);

  i = 0;
  pixmap_data[i].width =xnav_bitmap_openmap8_width;
  pixmap_data[i].height =xnav_bitmap_openmap8_height;
Claes Sjofors's avatar
Claes Sjofors committed
337
  pixmap_data[i++].bits = xnav_bitmap_openmap8_bits;
Claes Sjofors's avatar
Claes Sjofors committed
338 339
  pixmap_data[i].width =xnav_bitmap_openmap10_width;
  pixmap_data[i].height =xnav_bitmap_openmap10_height;
Claes Sjofors's avatar
Claes Sjofors committed
340
  pixmap_data[i++].bits = xnav_bitmap_openmap10_bits;
Claes Sjofors's avatar
Claes Sjofors committed
341 342
  pixmap_data[i].width =xnav_bitmap_openmap12_width;
  pixmap_data[i].height =xnav_bitmap_openmap12_height;
Claes Sjofors's avatar
Claes Sjofors committed
343
  pixmap_data[i++].bits = xnav_bitmap_openmap12_bits;
Claes Sjofors's avatar
Claes Sjofors committed
344 345
  pixmap_data[i].width =xnav_bitmap_openmap14_width;
  pixmap_data[i].height =xnav_bitmap_openmap14_height;
Claes Sjofors's avatar
Claes Sjofors committed
346
  pixmap_data[i++].bits = xnav_bitmap_openmap14_bits;
Claes Sjofors's avatar
Claes Sjofors committed
347 348
  pixmap_data[i].width =xnav_bitmap_openmap16_width;
  pixmap_data[i].height =xnav_bitmap_openmap16_height;
Claes Sjofors's avatar
Claes Sjofors committed
349
  pixmap_data[i++].bits = xnav_bitmap_openmap16_bits;
Claes Sjofors's avatar
Claes Sjofors committed
350 351
  pixmap_data[i].width =xnav_bitmap_openmap18_width;
  pixmap_data[i].height =xnav_bitmap_openmap18_height;
Claes Sjofors's avatar
Claes Sjofors committed
352
  pixmap_data[i++].bits = xnav_bitmap_openmap18_bits;
Claes Sjofors's avatar
Claes Sjofors committed
353 354
  pixmap_data[i].width =xnav_bitmap_openmap20_width;
  pixmap_data[i].height =xnav_bitmap_openmap20_height;
Claes Sjofors's avatar
Claes Sjofors committed
355
  pixmap_data[i++].bits = xnav_bitmap_openmap20_bits;
Claes Sjofors's avatar
Claes Sjofors committed
356 357
  pixmap_data[i].width =xnav_bitmap_openmap20_width;
  pixmap_data[i].height =xnav_bitmap_openmap20_height;
Claes Sjofors's avatar
Claes Sjofors committed
358
  pixmap_data[i++].bits = xnav_bitmap_openmap20_bits;
Claes Sjofors's avatar
Claes Sjofors committed
359 360
  pixmap_data[i].width =xnav_bitmap_openmap24_width;
  pixmap_data[i].height =xnav_bitmap_openmap24_height;
Claes Sjofors's avatar
Claes Sjofors committed
361
  pixmap_data[i++].bits = xnav_bitmap_openmap24_bits;
Claes Sjofors's avatar
Claes Sjofors committed
362 363 364 365 366 367
  
  brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_openmap);
  
  i = 0;
  pixmap_data[i].width =xnav_bitmap_attr8_width;
  pixmap_data[i].height =xnav_bitmap_attr8_height;
Claes Sjofors's avatar
Claes Sjofors committed
368
  pixmap_data[i++].bits = xnav_bitmap_attr8_bits;
Claes Sjofors's avatar
Claes Sjofors committed
369 370
  pixmap_data[i].width =xnav_bitmap_attr10_width;
  pixmap_data[i].height =xnav_bitmap_attr10_height;
Claes Sjofors's avatar
Claes Sjofors committed
371
  pixmap_data[i++].bits = xnav_bitmap_attr10_bits;
Claes Sjofors's avatar
Claes Sjofors committed
372 373
  pixmap_data[i].width =xnav_bitmap_attr12_width;
  pixmap_data[i].height =xnav_bitmap_attr12_height;
Claes Sjofors's avatar
Claes Sjofors committed
374
  pixmap_data[i++].bits = xnav_bitmap_attr12_bits;
Claes Sjofors's avatar
Claes Sjofors committed
375 376
  pixmap_data[i].width =xnav_bitmap_attr14_width;
  pixmap_data[i].height =xnav_bitmap_attr14_height;
Claes Sjofors's avatar
Claes Sjofors committed
377
  pixmap_data[i++].bits = xnav_bitmap_attr14_bits;
Claes Sjofors's avatar
Claes Sjofors committed
378 379
  pixmap_data[i].width =xnav_bitmap_attr16_width;
  pixmap_data[i].height =xnav_bitmap_attr16_height;
Claes Sjofors's avatar
Claes Sjofors committed
380
  pixmap_data[i++].bits = xnav_bitmap_attr16_bits;
Claes Sjofors's avatar
Claes Sjofors committed
381 382
  pixmap_data[i].width =xnav_bitmap_attr18_width;
  pixmap_data[i].height =xnav_bitmap_attr18_height;
Claes Sjofors's avatar
Claes Sjofors committed
383
  pixmap_data[i++].bits = xnav_bitmap_attr18_bits;
Claes Sjofors's avatar
Claes Sjofors committed
384 385
  pixmap_data[i].width =xnav_bitmap_attr20_width;
  pixmap_data[i].height =xnav_bitmap_attr20_height;
Claes Sjofors's avatar
Claes Sjofors committed
386
  pixmap_data[i++].bits = xnav_bitmap_attr20_bits;
Claes Sjofors's avatar
Claes Sjofors committed
387 388
  pixmap_data[i].width =xnav_bitmap_attr20_width;
  pixmap_data[i].height =xnav_bitmap_attr20_height;
Claes Sjofors's avatar
Claes Sjofors committed
389
  pixmap_data[i++].bits = xnav_bitmap_attr20_bits;
Claes Sjofors's avatar
Claes Sjofors committed
390 391
  pixmap_data[i].width =xnav_bitmap_attr24_width;
  pixmap_data[i].height =xnav_bitmap_attr24_height;
Claes Sjofors's avatar
Claes Sjofors committed
392
  pixmap_data[i++].bits = xnav_bitmap_attr24_bits;
Claes Sjofors's avatar
Claes Sjofors committed
393 394 395 396 397 398
  
  brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_attr);
  
  i = 0;
  pixmap_data[i].width =xnav_bitmap_attrarra8_width;
  pixmap_data[i].height =xnav_bitmap_attrarra8_height;
Claes Sjofors's avatar
Claes Sjofors committed
399
  pixmap_data[i++].bits = xnav_bitmap_attrarra8_bits;
Claes Sjofors's avatar
Claes Sjofors committed
400 401
  pixmap_data[i].width =xnav_bitmap_attrarra10_width;
  pixmap_data[i].height =xnav_bitmap_attrarra10_height;
Claes Sjofors's avatar
Claes Sjofors committed
402
  pixmap_data[i++].bits = xnav_bitmap_attrarra10_bits;
Claes Sjofors's avatar
Claes Sjofors committed
403 404
  pixmap_data[i].width =xnav_bitmap_attrarra12_width;
  pixmap_data[i].height =xnav_bitmap_attrarra12_height;
Claes Sjofors's avatar
Claes Sjofors committed
405
  pixmap_data[i++].bits = xnav_bitmap_attrarra12_bits;
Claes Sjofors's avatar
Claes Sjofors committed
406 407
  pixmap_data[i].width =xnav_bitmap_attrarra14_width;
  pixmap_data[i].height =xnav_bitmap_attrarra14_height;
Claes Sjofors's avatar
Claes Sjofors committed
408
  pixmap_data[i++].bits = xnav_bitmap_attrarra14_bits;
Claes Sjofors's avatar
Claes Sjofors committed
409 410
  pixmap_data[i].width =xnav_bitmap_attrarra16_width;
  pixmap_data[i].height =xnav_bitmap_attrarra16_height;
Claes Sjofors's avatar
Claes Sjofors committed
411
  pixmap_data[i++].bits = xnav_bitmap_attrarra16_bits;
Claes Sjofors's avatar
Claes Sjofors committed
412 413
  pixmap_data[i].width =xnav_bitmap_attrarra18_width;
  pixmap_data[i].height =xnav_bitmap_attrarra18_height;
Claes Sjofors's avatar
Claes Sjofors committed
414
  pixmap_data[i++].bits = xnav_bitmap_attrarra18_bits;
Claes Sjofors's avatar
Claes Sjofors committed
415 416
  pixmap_data[i].width =xnav_bitmap_attrarra20_width;
  pixmap_data[i].height =xnav_bitmap_attrarra20_height;
Claes Sjofors's avatar
Claes Sjofors committed
417
  pixmap_data[i++].bits = xnav_bitmap_attrarra20_bits;
Claes Sjofors's avatar
Claes Sjofors committed
418 419
  pixmap_data[i].width =xnav_bitmap_attrarra20_width;
  pixmap_data[i].height =xnav_bitmap_attrarra20_height;
Claes Sjofors's avatar
Claes Sjofors committed
420
  pixmap_data[i++].bits = xnav_bitmap_attrarra20_bits;
Claes Sjofors's avatar
Claes Sjofors committed
421 422
  pixmap_data[i].width =xnav_bitmap_attrarra24_width;
  pixmap_data[i].height =xnav_bitmap_attrarra24_height;
Claes Sjofors's avatar
Claes Sjofors committed
423
  pixmap_data[i++].bits = xnav_bitmap_attrarra24_bits;
Claes Sjofors's avatar
Claes Sjofors committed
424 425 426 427 428 429
  
  brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_attrarray);
  
  i = 0;
  pixmap_data[i].width =xnav_bitmap_attrenum8_width;
  pixmap_data[i].height =xnav_bitmap_attrenum8_height;
Claes Sjofors's avatar
Claes Sjofors committed
430
  pixmap_data[i++].bits = xnav_bitmap_attrenum8_bits;
Claes Sjofors's avatar
Claes Sjofors committed
431 432
  pixmap_data[i].width =xnav_bitmap_attrenum10_width;
  pixmap_data[i].height =xnav_bitmap_attrenum10_height;
Claes Sjofors's avatar
Claes Sjofors committed
433
  pixmap_data[i++].bits = xnav_bitmap_attrenum10_bits;
Claes Sjofors's avatar
Claes Sjofors committed
434 435
  pixmap_data[i].width =xnav_bitmap_attrenum12_width;
  pixmap_data[i].height =xnav_bitmap_attrenum12_height;
Claes Sjofors's avatar
Claes Sjofors committed
436
  pixmap_data[i++].bits = xnav_bitmap_attrenum12_bits;
Claes Sjofors's avatar
Claes Sjofors committed
437 438
  pixmap_data[i].width =xnav_bitmap_attrenum14_width;
  pixmap_data[i].height =xnav_bitmap_attrenum14_height;
Claes Sjofors's avatar
Claes Sjofors committed
439
  pixmap_data[i++].bits = xnav_bitmap_attrenum14_bits;
Claes Sjofors's avatar
Claes Sjofors committed
440 441
  pixmap_data[i].width =xnav_bitmap_attrenum16_width;
  pixmap_data[i].height =xnav_bitmap_attrenum16_height;
Claes Sjofors's avatar
Claes Sjofors committed
442
  pixmap_data[i++].bits = xnav_bitmap_attrenum16_bits;
Claes Sjofors's avatar
Claes Sjofors committed
443 444
  pixmap_data[i].width =xnav_bitmap_attrenum18_width;
  pixmap_data[i].height =xnav_bitmap_attrenum18_height;
Claes Sjofors's avatar
Claes Sjofors committed
445
  pixmap_data[i++].bits = xnav_bitmap_attrenum18_bits;
Claes Sjofors's avatar
Claes Sjofors committed
446 447
  pixmap_data[i].width =xnav_bitmap_attrenum20_width;
  pixmap_data[i].height =xnav_bitmap_attrenum20_height;
Claes Sjofors's avatar
Claes Sjofors committed
448
  pixmap_data[i++].bits = xnav_bitmap_attrenum20_bits;
Claes Sjofors's avatar
Claes Sjofors committed
449 450
  pixmap_data[i].width =xnav_bitmap_attrenum20_width;
  pixmap_data[i].height =xnav_bitmap_attrenum20_height;
Claes Sjofors's avatar
Claes Sjofors committed
451
  pixmap_data[i++].bits = xnav_bitmap_attrenum20_bits;
Claes Sjofors's avatar
Claes Sjofors committed
452 453
  pixmap_data[i].width =xnav_bitmap_attrenum24_width;
  pixmap_data[i].height =xnav_bitmap_attrenum24_height;
Claes Sjofors's avatar
Claes Sjofors committed
454
  pixmap_data[i++].bits = xnav_bitmap_attrenum24_bits;
Claes Sjofors's avatar
Claes Sjofors committed
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
  
  brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_attrenum);
}


//
// Create the navigator widget
//
GsdmlAttrNav::GsdmlAttrNav(
	void *xn_parent_ctx,
	const char *xn_name,
	pn_gsdml  *xn_gsdml,
	int xn_edit_mode,
	pwr_tStatus *status) :
  parent_ctx(xn_parent_ctx),
  gsdml(xn_gsdml), edit_mode(xn_edit_mode), trace_started(0),
  message_cb(0), change_value_cb(0), device_num(0), device_item(0), 
472 473
  device_confirm_active(0), device_read(0), viewio(0), time_ratio(1), send_clock(32), phase(1),
  order_moduletype( attr_eOrderModuleType_Default)
Claes Sjofors's avatar
Claes Sjofors committed
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
{
  strcpy( name, xn_name);

  *status = 1;
}

//
//  Delete a nav context
//
GsdmlAttrNav::~GsdmlAttrNav()
{
}

GsdmlAttrNavBrow::~GsdmlAttrNavBrow()
{
  free_pixmaps();
}

//
//  Get current zoom factor
//
void GsdmlAttrNav::get_zoom( double *zoom_factor)
{
  brow_GetZoom( brow->ctx, zoom_factor);
}

//
//  Zoom
//
void GsdmlAttrNav::zoom( double zoom_factor)
{
  brow_Zoom( brow->ctx, zoom_factor);
}

//
//  Return to base zoom factor
//
void GsdmlAttrNav::unzoom()
{
  brow_UnZoom( brow->ctx);
}

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
//
// Collapse
//
void GsdmlAttrNav::collapse()
{
  brow_tObject *olist;
  int ocnt;
  ItemPn *item;

  brow_SetNodraw( brow->ctx);

  brow_GetObjectList( brow->ctx, &olist, &ocnt);
  for ( int i = ocnt - 1; i >= 0; i--) {
    if ( brow_GetObjectLevel( olist[i]) == 0) {
      brow_GetUserData( olist[i], (void **)&item);

      item->close( this, 0, 0);
    }
  }

  brow_CenterObject( brow->ctx, olist[0], 0);

  brow_ResetNodraw( brow->ctx);
  brow_Redraw( brow->ctx, 0);
}

//
// Expand all items
//
void GsdmlAttrNav::expand_all()
{
  brow_tObject *olist;
  int ocnt;
  ItemPn *item;

  brow_SetNodraw( brow->ctx);

  collapse();

  brow_GetObjectList( brow->ctx, &olist, &ocnt);
  for ( int i = 0; i < ocnt; i++) {
    brow_GetUserData( olist[i], (void **)&item);

    if ( !( item->type == attrnav_eItemType_PnParEnum ||
	    item->type == attrnav_eItemType_PnDevice ||
	    item->type == attrnav_eItemType_PnModuleType ||
562
	    item->type == attrnav_eItemType_PnSubmoduleType ||
563 564 565 566 567 568 569 570 571 572 573 574 575
	    item->type == attrnav_eItemType_PnDataItem ||
	    item->type == attrnav_eItemType_PnModuleClass ||
	    item->type == attrnav_eItemType_PnEnumByteOrder ||
	    item->type == attrnav_eItemType_PnEnumTimeRatio ||
	    item->type == attrnav_eItemType_PnEnumSendClock))
      item->open_children( this, 0, 0);
    brow_GetObjectList( brow->ctx, &olist, &ocnt);
  }

  brow_ResetNodraw( brow->ctx);
  brow_Redraw( brow->ctx, 0);
}

Claes Sjofors's avatar
Claes Sjofors committed
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
// Get selected item
int GsdmlAttrNav::get_select( ItemPn **item)
{
  brow_tNode	*node_list;
  int		node_count;
  ItemPn	*base_item;
  
  brow_GetSelectedNodes( brow->ctx, &node_list, &node_count);
  if ( !node_count)
    return 0;

  brow_GetUserData( node_list[0], (void **)&base_item);
  free( node_list);

  *item = base_item;
  return 1;
}

//
// Set attribute value
//
int GsdmlAttrNav::set_attr_value( char *value_str)
{
  brow_tNode	*node_list;
  int		node_count;
  ItemPn	*base_item;
  
  brow_GetSelectedNodes( brow->ctx, &node_list, &node_count);
  if ( !node_count)
    return 0;

  brow_GetUserData( node_list[0], (void **)&base_item);
  free( node_list);

Claes Sjofors's avatar
Claes Sjofors committed
610
  base_item->value_changed( this, value_str);
Claes Sjofors's avatar
Claes Sjofors committed
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

  return 1;
}

//
// Check that the current selected item is valid for change
//
int GsdmlAttrNav::check_attr_value( char **value)
{
  brow_tNode	*node_list;
  int		node_count;
  ItemPn	*base_item;
  static char   buf[200];
  int           len;
  
  brow_GetSelectedNodes( brow->ctx, &node_list, &node_count);
  if ( !node_count)
    return PB__NOATTRSEL;

  brow_GetUserData( node_list[0], (void **)&base_item);
  free( node_list);

  switch( base_item->type) {
    case attrnav_eItemType_PnBase: {
      ItemPnBase	*item = (ItemPnBase *)base_item;

      if ( item->noedit) {
        *value = 0;
        return PB__ATTRNOEDIT;
      }
      attrvalue_to_string( item->type_id, item->value_p, buf, 
			   sizeof(buf), &len, NULL);
      *value = buf;
      return PB__SUCCESS;
    }
    case attrnav_eItemType_PnParValue: {
Claes Sjofors's avatar
Claes Sjofors committed
647 648 649 650
      ItemPnParValue *item = (ItemPnParValue *)base_item;
      int sts;

      if ( item->noedit)
Claes Sjofors's avatar
Claes Sjofors committed
651
        return PB__ATTRNOEDIT;
Claes Sjofors's avatar
Claes Sjofors committed
652 653 654 655 656

      sts = gsdml->datavalue_to_string( item->datatype, &item->data[item->byte_offset], 
				  item->size, buf, sizeof(buf));
      if ( EVEN(sts))
	strcpy( buf, "");
Claes Sjofors's avatar
Claes Sjofors committed
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
      *value = buf;
      return PB__SUCCESS;
    }
    default:
      return PB__ATTRNOEDIT;
  }
  return PB__SUCCESS;
}


//
// Callbacks from brow
//
int GsdmlAttrNav::brow_cb( FlowCtx *ctx, flow_tEvent event)
{
  GsdmlAttrNav		*attrnav;
  ItemPn 		*item;

  if ( event->event == flow_eEvent_ObjectDeleted) {
    brow_GetUserData( event->object.object, (void **)&item);
    delete item;
    return 1;
  }

  brow_GetCtxUserData( (BrowCtx *)ctx, (void **) &attrnav);
  attrnav->message( ' ', null_str);
  switch ( event->event) {
  case flow_eEvent_Key_Up: {
    brow_tNode	*node_list;
    int		node_count;
    brow_tObject	object;
    int		sts;

    brow_GetSelectedNodes( attrnav->brow->ctx, &node_list, &node_count);
    if ( !node_count) {
      sts = brow_GetLastVisible( attrnav->brow->ctx, &object);
      if ( EVEN(sts)) return 1;
    }
    else {
      if ( !brow_IsVisible( attrnav->brow->ctx, node_list[0], flow_eVisible_Partial)) {
	sts = brow_GetLastVisible( attrnav->brow->ctx, &object);
	if ( EVEN(sts)) return 1;
      }
      else {
	sts = brow_GetPrevious( attrnav->brow->ctx, node_list[0], &object);
	if ( EVEN(sts)) {
	  if ( node_count)
	    free( node_list);
	  return 1;
	}
      }
    }
    brow_SelectClear( attrnav->brow->ctx);
    brow_SetInverse( object, 1);
    brow_SelectInsert( attrnav->brow->ctx, object);
    if ( !brow_IsVisible( attrnav->brow->ctx, object, flow_eVisible_Full))
      brow_CenterObject( attrnav->brow->ctx, object, 0.25);
    if ( node_count)
      free( node_list);
    break;
  }
  case flow_eEvent_Key_Down: {
    brow_tNode	*node_list;
    int		node_count;
    brow_tObject	object;
    int		sts;

    brow_GetSelectedNodes( attrnav->brow->ctx, &node_list, &node_count);
    if ( !node_count) {
      sts = brow_GetFirstVisible( attrnav->brow->ctx, &object);
      if ( EVEN(sts)) return 1;
    }
    else {
      if ( !brow_IsVisible( attrnav->brow->ctx, node_list[0], flow_eVisible_Partial)) {
	sts = brow_GetFirstVisible( attrnav->brow->ctx, &object);
	if ( EVEN(sts)) return 1;
      }
      else {
	sts = brow_GetNext( attrnav->brow->ctx, node_list[0], &object);
	if ( EVEN(sts)) {
	  if ( node_count)
	    free( node_list);
	  return 1;
	}
      }
    }
    brow_SelectClear( attrnav->brow->ctx);
    brow_SetInverse( object, 1);
    brow_SelectInsert( attrnav->brow->ctx, object);
    if ( !brow_IsVisible( attrnav->brow->ctx, object, flow_eVisible_Full))
      brow_CenterObject( attrnav->brow->ctx, object, 0.75);
    if ( node_count)
      free( node_list);
    break;
  }
  case flow_eEvent_SelectClear:
    brow_ResetSelectInverse( attrnav->brow->ctx);
    break;
  case flow_eEvent_MB1Click:
    // Select
    double ll_x, ll_y, ur_x, ur_y;
    int		sts;

    switch ( event->object.object_type) {
    case flow_eObjectType_Node:
      brow_MeasureNode( event->object.object, &ll_x, &ll_y,
			&ur_x, &ur_y);
      if ( event->object.x < ll_x + 1.0) {
	// Simulate doubleclick
	flow_tEvent doubleclick_event;

	doubleclick_event = (flow_tEvent) calloc( 1, sizeof(*doubleclick_event));
	memcpy( doubleclick_event, event, sizeof(*doubleclick_event));
	doubleclick_event->event = flow_eEvent_MB1DoubleClick;
	sts = brow_cb( ctx, doubleclick_event);
	free( (char *) doubleclick_event);
	return sts;
      }

      if ( brow_FindSelectedObject( attrnav->brow->ctx, event->object.object)) {
	brow_SelectClear( attrnav->brow->ctx);
      }
      else {
	brow_SelectClear( attrnav->brow->ctx);
	brow_SetInverse( event->object.object, 1);
	brow_SelectInsert( attrnav->brow->ctx, event->object.object);
      }
      break;
    default:
      brow_SelectClear( attrnav->brow->ctx);
    }
    break;
  case flow_eEvent_MB2Click: {
    // Select
    brow_tNode	*node_list;
    int		node_count;

    if ( !attrnav->edit_mode) {
      attrnav->message('E', "Not in edit mode");
      break;
    }

    switch ( event->object.object_type) {
    case flow_eObjectType_Node:
      brow_GetSelectedNodes( attrnav->brow->ctx, &node_list, &node_count);
      if ( !node_count) {
Claes Sjofors's avatar
Claes Sjofors committed
803
	attrnav->message('E', "Select a slot");
Claes Sjofors's avatar
Claes Sjofors committed
804 805 806
	break;
      }
      else if ( node_count > 1) {
Claes Sjofors's avatar
Claes Sjofors committed
807
	attrnav->message('E', "Select one slot");
Claes Sjofors's avatar
Claes Sjofors committed
808 809 810 811
	free( node_list);
	break;
      }
	  
Claes Sjofors's avatar
Claes Sjofors committed
812
      ItemPnSlot *item_dest, *item_src;
Claes Sjofors's avatar
Claes Sjofors committed
813 814 815
      brow_GetUserData( node_list[0], (void **)&item_src);
      brow_GetUserData( event->object.object, (void **)&item_dest);
	  
Claes Sjofors's avatar
Claes Sjofors committed
816
      if ( item_src->type != attrnav_eItemType_PnSlot) {
Claes Sjofors's avatar
Claes Sjofors committed
817 818 819 820
	attrnav->message('E', "Unable to move this object");
	free( node_list);
	break;
      }
Claes Sjofors's avatar
Claes Sjofors committed
821
      if ( item_dest->type != attrnav_eItemType_PnSlot) {
Claes Sjofors's avatar
Claes Sjofors committed
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
	attrnav->message('E', "Invalid destination");
	free( node_list);
	break;
      }

      free( node_list);

      break;
    default:
      brow_SelectClear( attrnav->brow->ctx);
    }
    break;
  }
  case flow_eEvent_Key_Left: {
    brow_tNode	*node_list;
    int		node_count;
    brow_tObject	object;
    int		sts;

    brow_GetSelectedNodes( attrnav->brow->ctx, &node_list, &node_count);
    if ( !node_count)
      return 1;

    if ( brow_IsOpen( node_list[0]))
      // Close this node
      object = node_list[0];
    else {
      // Close parent
      sts = brow_GetParent( attrnav->brow->ctx, node_list[0], &object);
      if ( EVEN(sts)) {
	free( node_list);
	return 1;
      }
    }
    brow_GetUserData( object, (void **)&item);
    item->close( attrnav, 0, 0);

    brow_SelectClear( attrnav->brow->ctx);
    brow_SetInverse( object, 1);
    brow_SelectInsert( attrnav->brow->ctx, object);
    if ( !brow_IsVisible( attrnav->brow->ctx, object, flow_eVisible_Full))
      brow_CenterObject( attrnav->brow->ctx, object, 0.25);
    free( node_list);
    break;
  }
  case flow_eEvent_Key_Right: {
    brow_tNode	*node_list;
    int		node_count;

    brow_GetSelectedNodes( attrnav->brow->ctx, &node_list, &node_count);
    if ( !node_count)
      return 1;

    brow_GetUserData( node_list[0], (void **)&item);
    switch( item->type) {
    case attrnav_eItemType_PnBase:
    case attrnav_eItemType_PnParValue:
      if ( ((ItemPnBase *)item)->parent)
	item->open_children( attrnav, 0, 0);
      else if ( !((ItemPnBase *)item)->parent && attrnav->change_value_cb)
	(attrnav->change_value_cb) ( attrnav->parent_ctx);
      break;
    case attrnav_eItemType_PnEnumByteOrder:
      item->open_children( attrnav, 0, 0);
      break;
    case attrnav_eItemType_PnEnumValue: {
      int value;
      if ( !attrnav->edit_mode) {
	attrnav->message('E', "Not in edit mode");
	break;
      }
	
      brow_GetRadiobutton( node_list[0], 0, &value);
      if ( !value) {
	brow_SetRadiobutton( node_list[0], 0, 1);
	*(int *)((ItemPnEnumValue *)item)->value_p = ((ItemPnEnumValue *)item)->num;
	attrnav->set_modified(1);
      }
      break;
    }
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
    case attrnav_eItemType_PnEnumValueMType: {
      int value;
      if ( !attrnav->edit_mode) {
	attrnav->message('E', "Not in edit mode");
	break;
      }
	
      brow_GetRadiobutton( node_list[0], 0, &value);
      if ( !value) {
	brow_SetRadiobutton( node_list[0], 0, 1);
	*(int *)((ItemPnEnumValueMType *)item)->value_p = ((ItemPnEnumValueMType *)item)->num;
	attrnav->set_modified(1);
      }
      break;
    }
Claes Sjofors's avatar
Claes Sjofors committed
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
    case attrnav_eItemType_PnParEnumBit: 
      if ( !attrnav->edit_mode) {
	attrnav->message('E', "Not in edit mode");
	break;
      }
      item->update( attrnav);
      break;
    default:
      item->open_children( attrnav, 0, 0);	    
    }
    break;
  }
  case flow_eEvent_MB1DoubleClick:
    switch ( event->object.object_type) {
    case flow_eObjectType_Node:
      brow_GetUserData( event->object.object, (void **)&item);
      item->open_children( attrnav, event->object.x, event->object.y);
      break;
    default:
      ;
    }
    break;
  case flow_eEvent_MB1DoubleClickCtrl:
    break;
  case flow_eEvent_Radiobutton: {
    if ( !attrnav->edit_mode) {
      attrnav->message('E', "Not in edit mode");
      break;
    }
    switch ( event->object.object_type) {
    case flow_eObjectType_Node:
      brow_GetUserData( event->object.object, (void **)&item);
      switch( item->type) {
      case attrnav_eItemType_PnEnumValue: 
	if ( !event->radiobutton.value) {
	  brow_SetRadiobutton( event->radiobutton.object, 
			       event->radiobutton.number, !event->radiobutton.value);
	  *(int *)((ItemPnEnumValue *)item)->value_p = ((ItemPnEnumValue *)item)->num;
	  attrnav->set_modified( 1);	    
	}
	break;
958 959 960 961 962 963 964 965
      case attrnav_eItemType_PnEnumValueMType: 
	if ( !event->radiobutton.value) {
	  brow_SetRadiobutton( event->radiobutton.object, 
			       event->radiobutton.number, !event->radiobutton.value);
	  *(int *)((ItemPnEnumValueMType *)item)->value_p = ((ItemPnEnumValueMType *)item)->num;
	  attrnav->set_modified( 1);	    
	}
	break;
Claes Sjofors's avatar
Claes Sjofors committed
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
      case attrnav_eItemType_PnParEnumBit: 
	item->update( attrnav);
	break;
      default:
	;
      }
      break;
    default:
      ;
    }

    break;
  }
  case flow_eEvent_Key_PageDown: {
    brow_Page( attrnav->brow->ctx, 0.8);
    break;
  }
  case flow_eEvent_Key_PageUp: {
    brow_Page( attrnav->brow->ctx, -0.8);
    break;
  }
  case flow_eEvent_ScrollDown: {
    brow_Page( attrnav->brow->ctx, 0.1);
    break;
  }
  case flow_eEvent_ScrollUp: {
    brow_Page( attrnav->brow->ctx, -0.1);
    break;
  }
  default:
    ;
  }
  return 1;
}

void GsdmlAttrNav::trace_scan( void *data)
{
  GsdmlAttrNav *attrnav = (GsdmlAttrNav *)data;
  int time = 200;

  if ( attrnav->trace_started) {
    brow_TraceScan( attrnav->brow->ctx);

    attrnav->trace_timerid->add( time, trace_scan, attrnav);
  }
}

void GsdmlAttrNav::force_trace_scan()
{
  if ( trace_started)
    brow_TraceScan( brow->ctx);
}

void GsdmlAttrNav::device_changed_ok( void *ctx, void *data)
{
  GsdmlAttrNav *attrnav = (GsdmlAttrNav *)ctx;

  brow_DeleteAll( attrnav->brow->ctx);
Claes Sjofors's avatar
Claes Sjofors committed
1024
  if ( !attrnav->device_read)
Claes Sjofors's avatar
Claes Sjofors committed
1025 1026 1027
    attrnav->dev_data.device_reset();
  attrnav->object_attr();
  attrnav->device_confirm_active = 0;
Claes Sjofors's avatar
Claes Sjofors committed
1028 1029 1030 1031 1032
  if ( attrnav->device_read)
    attrnav->device_read = 0;
  else
    attrnav->set_modified(1);

Claes Sjofors's avatar
Claes Sjofors committed
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 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
void GsdmlAttrNav::device_update_change( void *ctx)
{
  GsdmlAttrNav *attrnav = (GsdmlAttrNav *)ctx;

  // Get new item
  attrnav->device_item = attrnav->gsdml->ApplicationProcess->DeviceAccessPointList->DeviceAccessPointItem[attrnav->device_num - 1];

  gsdml_UseableModules *um = attrnav->device_item->UseableModules;

  // Save the enum numbers for the slots
  for ( unsigned int ii = 0; ii < attrnav->dev_data.slot_data.size(); ii++) {

    if (ii == 0) {
      attrnav->dev_data.slot_data[ii]->slot_reset();
      attrnav->dev_data.slot_data[ii]->module_ident_number = attrnav->device_item->Body.ModuleIdentNumber;
      continue;
    }

    if (attrnav->dev_data.slot_data[ii]->module_enum_number == 0) {
      break;
    }

    for ( unsigned int jj = 0; jj < um->ModuleItemRef.size(); jj++) {
      gsdml_ModuleItem *mi = (gsdml_ModuleItem *)um->ModuleItemRef[jj]->Body.ModuleItemTarget.p;

      if (attrnav->dev_data.slot_data[ii]->module_ident_number == mi->Body.ModuleIdentNumber) {
	attrnav->dev_data.slot_data[ii]->module_enum_number = jj + 1;
	break;
      }
    }
  }
}

pwr_tBoolean GsdmlAttrNav::device_check_change_ok( void *ctx)
{
  GsdmlAttrNav *attrnav = (GsdmlAttrNav *)ctx;
  pwr_tBoolean found, check_ok;


  gsdml_UseableModules *um = attrnav->gsdml->ApplicationProcess->DeviceAccessPointList->DeviceAccessPointItem[attrnav->device_num - 1]->UseableModules;

  check_ok = true;

  for ( unsigned int ii = 0; ii < attrnav->dev_data.slot_data.size(); ii++) {

    if (ii == 0) {
      continue;
    }

    if (attrnav->dev_data.slot_data[ii]->module_enum_number == 0) {
      break;
    }

    found = FALSE;
    for ( unsigned int jj = 0; jj < um->ModuleItemRef.size(); jj++) {
      if ( um->ModuleItemRef[jj]->Body.AllowedInSlots.list &&
	   um->ModuleItemRef[jj]->Body.AllowedInSlots.list->in_list(ii)) {
	gsdml_ModuleItem *mi = (gsdml_ModuleItem *)um->
	  ModuleItemRef[jj]->Body.ModuleItemTarget.p;

	if (attrnav->dev_data.slot_data[ii]->module_ident_number == mi->Body.ModuleIdentNumber) {
	  found = TRUE;
	  break;
	}
      }
    }

    if (!found) {
      check_ok = FALSE;
      break;
    }
  }

  return check_ok;


}


Claes Sjofors's avatar
Claes Sjofors committed
1114 1115
void GsdmlAttrNav::device_changed_cancel( void *ctx, void *data)
{
claes's avatar
claes committed
1116
  long int old_device = (long int )data;
Claes Sjofors's avatar
Claes Sjofors committed
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
  GsdmlAttrNav *attrnav = (GsdmlAttrNav *)ctx;
  attrnav->device_num = old_device;
  attrnav->device_confirm_active = 0;
}

void GsdmlAttrNav::redraw()
{
  brow_DeleteAll( brow->ctx);
  object_attr();
}

int GsdmlAttrNav::trace_scan_bc( brow_tObject object, void *p)
{
  ItemPn       	*base_item;
  GsdmlAttrNav	*attrnav;

  brow_GetUserData( object, (void **)&base_item);
  brow_GetCtxUserData( brow_GetCtx( object), (void **) &attrnav);

  base_item->scan( attrnav, p);

  return 1;
}

int GsdmlAttrNav::trace_connect_bc( brow_tObject object, char *name, char *attr, 
				  flow_eTraceType type, void **p)
{
  ItemPn 		*base_item;
  GsdmlAttrNav		*attrnav;

  /*  printf( "Connecting %s.%s\n", name, attr);  */

  if ( strcmp(name,"") == 0)
    return 1;

  brow_GetCtxUserData( brow_GetCtx( object), (void **) &attrnav);

  brow_GetUserData( object, (void **)&base_item);
  switch( base_item->type) {
    case attrnav_eItemType_PnBase:
    case attrnav_eItemType_PnEnumByteOrder: {
      ItemPnBase	*item = (ItemPnBase *) base_item;
      if (item->size == 0)
	break;

      *p = item->value_p;
      break;
    }
    case attrnav_eItemType_PnDevice: {
      *p = &attrnav->device_num;
      break;
    }
    case attrnav_eItemType_PnSlot: {
      ItemPnSlot	*item = (ItemPnSlot *) base_item;

      *p = &item->slotdata->module_enum_number;
      break;
    }
    case attrnav_eItemType_PnModuleType: {
      ItemPnModuleType	*item = (ItemPnModuleType *) base_item;

      *p = &attrnav->dev_data.slot_data[item->slot_idx]->module_enum_number;
      break;
    }
1181 1182 1183 1184 1185 1186
    case attrnav_eItemType_PnSubmoduleType: {
      ItemPnSubmoduleType	*item = (ItemPnSubmoduleType *) base_item;

      *p = &attrnav->dev_data.slot_data[item->slot_idx]->subslot_data[item->subslot_idx]->submodule_enum_number;
      break;
    }
Claes Sjofors's avatar
Claes Sjofors committed
1187 1188 1189 1190 1191 1192
    case attrnav_eItemType_PnModuleClass: {
      ItemPnModuleClass	*item = (ItemPnModuleClass *) base_item;

      *p = &item->slotdata->module_class;
      break;
    }
Claes Sjofors's avatar
Claes Sjofors committed
1193 1194 1195
    case attrnav_eItemType_PnEnumValue:
      *p = ((ItemPnEnumValue *)base_item)->value_p;
      break;
1196 1197 1198
    case attrnav_eItemType_PnEnumValueMType:
      *p = ((ItemPnEnumValueMType *)base_item)->value_p;
      break;
Claes Sjofors's avatar
Claes Sjofors committed
1199 1200
    case attrnav_eItemType_PnEnumTimeRatio:
      *p = ((ItemPnEnumTimeRatio *)base_item)->value_p;
Claes Sjofors's avatar
Claes Sjofors committed
1201
      break;
1202 1203 1204
    case attrnav_eItemType_PnEnumSendClock:
      *p = ((ItemPnEnumSendClock *)base_item)->value_p;
      break;
Claes Sjofors's avatar
Claes Sjofors committed
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
    case attrnav_eItemType_PnParEnum:
    case attrnav_eItemType_PnParEnumBit:
    case attrnav_eItemType_PnParValue:
      *p = (void *)1;
      break;
    default:
      ;
  }      
  return 1;
}

int GsdmlAttrNav::trace_disconnect_bc( brow_tObject object)
{
  ItemPn 		*base_item;

  brow_GetUserData( object, (void **)&base_item);
  switch( base_item->type) {
    default:
      ;
  }
  return 1;
}


//
// Create nodeclasses
//
void GsdmlAttrNavBrow::create_nodeclasses()
{
  allocate_pixmaps();

  // Create common-class

  brow_CreateNodeClass( ctx, "NavigatorDefault", 
		flow_eNodeGroup_Common, &nc_object);
  brow_AddAnnotPixmap( nc_object, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
  brow_AddAnnotPixmap( nc_object, 1, 1.1, 0.1, flow_eDrawType_Line, 2, 0);
  brow_AddAnnot( nc_object, 2, 0.6, 0,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_object, 7, 0.6, 1,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
  brow_AddAnnot( nc_object, 12, 0.6, 2,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
  brow_AddFrame( nc_object, 0, 0, 20, 0.83, flow_eDrawType_LineGray, -1, 1);

  // Create attribute nodeclass

  brow_CreateNodeClass( ctx, "NavigatorGsdmlAttr", 
		flow_eNodeGroup_Common, &nc_attr);
  brow_AddAnnotPixmap( nc_attr, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
  brow_AddAnnot( nc_attr, 2, 0.6, 0,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_attr, 12, 0.6, 1,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
1264 1265 1266
  brow_AddAnnot( nc_attr, 24, 0.6, 2,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
Claes Sjofors's avatar
Claes Sjofors committed
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292
  brow_AddFrame( nc_attr, 0, 0, 20, 0.83, flow_eDrawType_LineGray, -1, 1);

  // Create multiline attribute nodeclass

  brow_CreateNodeClass( ctx, "NavigatorGsdmlAttrMultiLine", 
		flow_eNodeGroup_Common, &nc_attr_multiline);
  brow_AddAnnotPixmap( nc_attr_multiline, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
  brow_AddAnnot( nc_attr_multiline, 2, 0.6, 0,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_attr_multiline, 8, 0.6, 1,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_MultiLine, 
		1);
  brow_AddFrame( nc_attr_multiline, 0, 0, 20, 0.83, flow_eDrawType_LineGray, -1, 1);

  // Create attribute nodeclass

  brow_CreateNodeClass( ctx, "NavigatorEnum", 
		flow_eNodeGroup_Common, &nc_enum);
  brow_AddRadiobutton( nc_enum, 18, 0.03, 0.7, 0.7, 0, flow_eDrawType_Line, 1);
  brow_AddAnnotPixmap( nc_enum, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
  brow_AddAnnot( nc_enum, 2, 0.6, 0,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddFrame( nc_enum, 0, 0, 20, 0.83, flow_eDrawType_LineGray, -1, 1);
 
1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304
  brow_CreateNodeClass( ctx, "NavigatorEnumMType", 
		flow_eNodeGroup_Common, &nc_enum_mtype);
  brow_AddRadiobutton( nc_enum_mtype, 24, 0.03, 0.7, 0.7, 0, flow_eDrawType_Line, 1);
  brow_AddAnnotPixmap( nc_enum_mtype, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
  brow_AddAnnot( nc_enum_mtype, 2, 0.6, 0,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_enum_mtype, 12, 0.6, 1,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
  brow_AddFrame( nc_enum_mtype, 0, 0, 20, 0.83, flow_eDrawType_LineGray, -1, 1);
 
Claes Sjofors's avatar
Claes Sjofors committed
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547
  // Create table nodeclass

  brow_CreateNodeClass( ctx, "NavigatorTable", 
		flow_eNodeGroup_Common, &nc_table);
  brow_AddAnnotPixmap( nc_table, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
  brow_AddAnnotPixmap( nc_table, 1, 1.1, 0.1, flow_eDrawType_Line, 2, 0);
  brow_AddAnnot( nc_table, 2, 0.6, 0,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_table, 8, 0.6, 1,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
  brow_AddAnnot( nc_table, 12, 0.6, 2,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
  brow_AddAnnot( nc_table, 16, 0.6, 3,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
  brow_AddAnnot( nc_table, 20, 0.6, 4,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
  brow_AddAnnot( nc_table, 24, 0.6, 5,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
  brow_AddAnnot( nc_table, 28, 0.6, 6,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
  brow_AddAnnot( nc_table, 32, 0.6, 7,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
  brow_AddAnnot( nc_table, 35, 0.6, 8,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
  brow_AddAnnot( nc_table, 38, 0.6, 9,
		flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine, 
		1);
  brow_AddFrame( nc_table, 0, 0, 20, 0.83, flow_eDrawType_LineGray, -1, 1);

  // Create Header

  brow_CreateNodeClass( ctx, "NavigatorHead", 
		flow_eNodeGroup_Common, &nc_header);
  brow_AddAnnotPixmap( nc_header, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
  brow_AddAnnot( nc_header, 2, 0.6, 0,
		flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_header, 8, 0.6, 1,
		flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine, 
		1);
  brow_AddFrame( nc_header, 0, 0, 20, 0.83, flow_eDrawType_LineGray, 2, 1);

  // Create TableHeader

  brow_CreateNodeClass( ctx, "NavigatorTableHead", 
		flow_eNodeGroup_Common, &nc_table_header);
  brow_AddAnnotPixmap( nc_table_header, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
  brow_AddAnnot( nc_table_header, 2, 0.6, 0,
		flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_table_header, 8, 0.6, 1,
		flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_table_header, 12, 0.6, 2,
		flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_table_header, 16, 0.6, 3,
		flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_table_header, 20, 0.6, 4,
		flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_table_header, 24, 0.6, 5,
		flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_table_header, 28, 0.6, 6,
		flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_table_header, 32, 0.6, 7,
		flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_table_header, 35, 0.6, 8,
		flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddAnnot( nc_table_header, 38, 0.6, 9,
		flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine, 
		0);
  brow_AddFrame( nc_table_header, 0, 0, 20, 0.83, flow_eDrawType_LineGray, 2, 1);

}

void GsdmlAttrNav::print( char *filename)
{
  brow_Print( brow->ctx, filename);
}

int	GsdmlAttrNav::object_attr()
{
  if ( device_num == 0)
    device_item = 0;
  else
    device_item = gsdml->ApplicationProcess->DeviceAccessPointList->
      DeviceAccessPointItem[device_num-1];

  brow_SetNodraw( brow->ctx);

  new ItemPnNetwork( this, "NetworkSettings", NULL, flow_eDest_IntoLast);

  new ItemPnEnumByteOrder( this, "ByteOrdering", "LocalGsdAttr", 
			   pwr_eType_Int32, sizeof(pwr_tInt32), (void *)&gsdml->byte_order, 0,
			   NULL, flow_eDest_IntoLast);

  new ItemPnDeviceInfo( this, "DeviceInfo", NULL, flow_eDest_IntoLast);
  new ItemPnDevice( this, "Device", NULL, flow_eDest_IntoLast);

  if ( device_num) {
    unsigned int slot_cnt = 0;

    GsdmlSlotData *sd;
    if ( dev_data.slot_data.size() <= slot_cnt) {
      sd = new GsdmlSlotData();
      sd->slot_number = 0;
      sd->slot_idx = slot_cnt;
      dev_data.slot_data.push_back(sd);
    }
    else {
      sd = dev_data.slot_data[slot_cnt];
      sd->slot_idx = slot_cnt;
    }

    new ItemPnDAP( this, "DAP", sd, NULL, flow_eDest_IntoLast);

    slot_cnt++;

    gsdml_ValuelistIterator iter( gsdml->ApplicationProcess->DeviceAccessPointList->
				  DeviceAccessPointItem[device_num-1]->Body.PhysicalSlots.list);
    for ( unsigned int i = iter.begin(); i != iter.end(); i = iter.next()) {
      if ( i == 0)
	// DAP already created
	continue;
      char name[80];
      sprintf( name, "Slot %u", i);

      if ( dev_data.slot_data.size() <= slot_cnt) {
	sd = new GsdmlSlotData();
	sd->slot_number = i;
	sd->slot_idx = slot_cnt;
	dev_data.slot_data.push_back(sd);
      }
      else {
	sd = dev_data.slot_data[slot_cnt];
	sd->slot_idx = slot_cnt;
	if ( i != sd->slot_number) {
	  printf( "GSML-Error, datafile corrupt, unexpected slot number\n");
	}
      }

      new ItemPnSlot( this, name, sd, NULL, flow_eDest_IntoLast);
      slot_cnt++;
    }    
  }

  brow_ResetNodraw( brow->ctx);
  brow_Redraw( brow->ctx, 0);
  force_trace_scan();
  return PB__SUCCESS;
}

void GsdmlAttrNavBrow::brow_setup()
{
  brow_sAttributes brow_attr;
  unsigned long mask;

  mask = 0;
  mask |= brow_eAttr_indentation;
  brow_attr.indentation = 0.5;
  mask |= brow_eAttr_annotation_space;
  brow_attr.annotation_space = 0.5;
  brow_SetAttributes( ctx, &brow_attr, mask); 
  brow_SetCtxUserData( ctx, attrnav);

  brow_EnableEvent( ctx, flow_eEvent_MB1Click, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_MB2Click, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_MB1DoubleClick, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_MB1DoubleClickCtrl, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_SelectClear, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_ObjectDeleted, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_Key_Up, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_Key_Down, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_Key_Right, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_Key_Left, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_Key_PF3, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_Radiobutton, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_Key_PageUp, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_Key_PageDown, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_ScrollUp, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
  brow_EnableEvent( ctx, flow_eEvent_ScrollDown, flow_eEventType_CallBack, 
	GsdmlAttrNav::brow_cb);
}

//
// Backcall routine called at creation of the brow widget
// Enable event, create nodeclasses and insert the root objects.
//
int GsdmlAttrNav::init_brow_cb( FlowCtx *fctx, void *client_data)
{
  GsdmlAttrNav *attrnav = (GsdmlAttrNav *) client_data;
  BrowCtx *ctx = (BrowCtx *)fctx;
  int		sts;

  attrnav->brow = new GsdmlAttrNavBrow( ctx, (void *)attrnav);

  attrnav->brow->brow_setup();
  attrnav->brow->create_nodeclasses();

  // Create the root item
  attrnav->object_attr();

  sts = brow_TraceInit( ctx, trace_connect_bc, 
			trace_disconnect_bc, trace_scan_bc);
  attrnav->trace_started = 1;

  trace_scan( attrnav);

  return 1;
}

int GsdmlAttrNav::save( const char *filename)
{
1548
  int sts;
Claes Sjofors's avatar
Claes Sjofors committed
1549

Claes Sjofors's avatar
Claes Sjofors committed
1550
  dev_data.device_num = device_num;
Claes Sjofors's avatar
Claes Sjofors committed
1551 1552 1553 1554

  if ( device_num == 0)
    return PB__NODEVICE;

1555 1556 1557 1558
  // Be sure all items are initialized, expand all
  brow_SetNodraw( brow->ctx);
  expand_all();

Claes Sjofors's avatar
Claes Sjofors committed
1559 1560 1561 1562 1563
  strncpy( dev_data.device_text, (char *)device_item->ModuleInfo->Body.Name.p, sizeof(dev_data.device_text));
  dev_data.vendor_id = gsdml->DeviceIdentity->Body.VendorID;
  dev_data.device_id = gsdml->DeviceIdentity->Body.DeviceID;
  strncpy( dev_data.version, gsdml->ProfileHeader->Body.ProfileRevision, sizeof(dev_data.version));
  dev_data.byte_order = gsdml->byte_order;
1564
  dev_data.instance = device_item->Body.ObjectUUID_LocalIndex;
Claes Sjofors's avatar
Claes Sjofors committed
1565

1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
  // Store ModuleIdentNumber
  gsdml_UseableModules *um = device_item->UseableModules;

  for ( unsigned int i = 0; i < dev_data.slot_data.size(); i++) {
    if ( i == 0) {
      dev_data.slot_data[i]->module_ident_number = device_item->Body.ModuleIdentNumber;
    }
    else {
      if ( dev_data.slot_data[i]->module_enum_number != 0) {
	gsdml_ModuleItem *mi = (gsdml_ModuleItem *)um->
	  ModuleItemRef[dev_data.slot_data[i]->module_enum_number-1]->Body.ModuleItemTarget.p;
	dev_data.slot_data[i]->module_ident_number = mi->Body.ModuleIdentNumber;
      }
1579
      else {
1580
	dev_data.slot_data[i]->module_ident_number = 0;
1581 1582
	dev_data.slot_data[i]->module_class = 0;
      }
1583 1584 1585
    }
  }

Claes Sjofors's avatar
Claes Sjofors committed
1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597
  // Create IOCR data
  if ( dev_data.iocr_data.size() < 1) {
    GsdmlIOCRData *iod = new GsdmlIOCRData();
    dev_data.iocr_data.push_back( iod);
  }
  if ( dev_data.iocr_data.size() < 2) {
    GsdmlIOCRData *iod = new GsdmlIOCRData();
    dev_data.iocr_data.push_back( iod);
  }

  dev_data.iocr_data[0]->type = 1; // Input ?
  dev_data.iocr_data[0]->properties = 1; // Class 1
1598 1599
  dev_data.iocr_data[0]->send_clock_factor = send_clock;
  dev_data.iocr_data[0]->reduction_ratio = time_ratio; // send_time = 8 * 31.2 us * send_clock
1600
  dev_data.iocr_data[0]->phase = phase;
Claes Sjofors's avatar
Claes Sjofors committed
1601 1602 1603 1604 1605 1606
  dev_data.iocr_data[0]->api = 0;

  dev_data.iocr_data[1]->type = 2; // Output ?
  dev_data.iocr_data[1]->properties = dev_data.iocr_data[0]->properties;
  dev_data.iocr_data[1]->send_clock_factor = dev_data.iocr_data[0]->send_clock_factor;
  dev_data.iocr_data[1]->reduction_ratio = dev_data.iocr_data[0]->reduction_ratio;
1607
  dev_data.iocr_data[1]->phase = dev_data.iocr_data[0]->phase;
Claes Sjofors's avatar
Claes Sjofors committed
1608 1609
  dev_data.iocr_data[1]->api = dev_data.iocr_data[0]->api;

Claes Sjofors's avatar
Claes Sjofors committed
1610 1611 1612 1613 1614 1615 1616 1617 1618
  // Load channel diag
  dev_data.channel_diag_reset();
  if ( gsdml->ApplicationProcess->ChannelDiagList) {
    for ( unsigned int i = 0; i < gsdml->ApplicationProcess->ChannelDiagList->ChannelDiagItem.size(); i++) {
      GsdmlChannelDiag *cd = new GsdmlChannelDiag();

      cd->error_type = gsdml->ApplicationProcess->ChannelDiagList->ChannelDiagItem[i]->Body.ErrorType;
      strncpy( cd->name, (char *)gsdml->ApplicationProcess->ChannelDiagList->ChannelDiagItem[i]->
	       Body.Name.p, sizeof(cd->name));
1619 1620 1621
      if ( gsdml->ApplicationProcess->ChannelDiagList->ChannelDiagItem[i]->Body.Help.p)
	strncpy( cd->help, (char *)gsdml->ApplicationProcess->ChannelDiagList->ChannelDiagItem[i]->
		 Body.Help.p, sizeof(cd->help));
Claes Sjofors's avatar
Claes Sjofors committed
1622 1623 1624 1625
      dev_data.channel_diag.push_back( cd);
    }
  }

1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656
  // Calculate subslot IO length
  for ( unsigned int i = 0; i < dev_data.slot_data.size(); i++) {
    if ( i == 0) {
      // Device access point
      gsdml_DeviceAccessPointItem *mi = device_item;

      for ( unsigned int j = 0; j < dev_data.slot_data[i]->subslot_data.size(); j++) {
	GsdmlSubslotData *ssd = dev_data.slot_data[i]->subslot_data[j];

	ssd->io_input_length = 0;
	ssd->io_output_length = 0;

	if ( mi->VirtualSubmoduleList->VirtualSubmoduleItem.size() == 0)
	  continue;

	gsdml_VirtualSubmoduleItem *vsd = 0;
	if ( mi->VirtualSubmoduleList->VirtualSubmoduleItem.size() == 1)
	  vsd = mi->VirtualSubmoduleList->VirtualSubmoduleItem[0];
	else {
	  for ( unsigned int k = 0; k < mi->VirtualSubmoduleList->VirtualSubmoduleItem.size(); k++) {
	    if ( mi->VirtualSubmoduleList->VirtualSubmoduleItem[k]->Body.SubmoduleIdentNumber == 
		 ssd->submodule_ident_number) {
	      vsd = mi->VirtualSubmoduleList->VirtualSubmoduleItem[k];	      
	      break;
	    }
	  }
	}
	if ( !vsd) {
	  continue;
	}

Claes Sjofors's avatar
Claes Sjofors committed
1657 1658
	ssd->api = vsd->Body.API;

1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707
	if ( !vsd->IOData)
	  continue;

	if ( vsd->IOData->Input) {
	  for ( unsigned k = 0; k < vsd->IOData->Input->DataItem.size(); k++) {

	    gsdml_DataItem *di = vsd->IOData->Input->DataItem[k];
	    gsdml_eValueDataType datatype;
	  
	    gsdml->string_to_value_datatype( di->Body.DataType, &datatype);
	    unsigned int len;

	    sts = gsdml->get_datavalue_length( datatype, di->Body.Length, &len);
	    if ( EVEN(sts)) printf( "GSDML-Error, Datatype %s not yet implemented\n", di->Body.DataType);
	  
	    ssd->io_input_length += len;	    
	  }
	}
	if ( vsd->IOData->Output) {
	  for ( unsigned k = 0; k < vsd->IOData->Output->DataItem.size(); k++) {
	  
	    gsdml_DataItem *di = vsd->IOData->Output->DataItem[k];
	    gsdml_eValueDataType datatype;
	  
	    gsdml->string_to_value_datatype( di->Body.DataType, &datatype);
	    unsigned int len;
	  
	    sts = gsdml->get_datavalue_length( datatype, di->Body.Length, &len);
	    if ( EVEN(sts)) printf( "GSDML-Error, Datatype %s not yet implemented\n", di->Body.DataType);
	  
	    ssd->io_output_length += len;	    
	  }
	}
      }
    }
    else {

      if ( dev_data.slot_data[i]->module_enum_number == 0)
	continue;

      gsdml_UseableModules *um = device_item->UseableModules;
      if ( !um)
	continue;

      gsdml_ModuleItem *mi = (gsdml_ModuleItem *)um->
	ModuleItemRef[dev_data.slot_data[i]->module_enum_number-1]->Body.ModuleItemTarget.p;

      for ( unsigned int j = 0; j < dev_data.slot_data[i]->subslot_data.size(); j++) {
	GsdmlSubslotData *ssd = dev_data.slot_data[i]->subslot_data[j];
1708 1709
	unsigned int io_input_length = 0;
	unsigned int io_output_length = 0;
1710 1711

	gsdml_VirtualSubmoduleItem *vsd = 0;
1712 1713 1714 1715
	if ( ssd->submodule_enum_number) {
	  // Physical subslot
	  vsd = gsdml->ApplicationProcess->SubmoduleList->SubmoduleItem[ssd->submodule_enum_number - 1];
	}
1716
	else {
1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728
	  if ( mi->VirtualSubmoduleList->VirtualSubmoduleItem.size() == 0)
	    continue;

	  if ( mi->VirtualSubmoduleList->VirtualSubmoduleItem.size() == 1)
	    vsd = mi->VirtualSubmoduleList->VirtualSubmoduleItem[0];
	  else {
	    for ( unsigned int k = 0; k < mi->VirtualSubmoduleList->VirtualSubmoduleItem.size(); k++) {
	      if ( mi->VirtualSubmoduleList->VirtualSubmoduleItem[k]->Body.SubmoduleIdentNumber == 
		   ssd->submodule_ident_number) {
		vsd = mi->VirtualSubmoduleList->VirtualSubmoduleItem[k];	      
		break;
	      }
1729 1730 1731 1732 1733 1734 1735 1736
	    }
	  }
	}
	if ( !vsd) {
	  printf( "GSDML-Error, subslot number not found\n");
	  continue;
	}

Claes Sjofors's avatar
Claes Sjofors committed
1737
	ssd->api = vsd->Body.API;
1738
        ssd->submodule_ident_number = vsd->Body.SubmoduleIdentNumber;
Claes Sjofors's avatar
Claes Sjofors committed
1739

1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754
	if ( !vsd->IOData)
	  continue;

	if ( vsd->IOData->Input) {
	  for ( unsigned k = 0; k < vsd->IOData->Input->DataItem.size(); k++) {

	    gsdml_DataItem *di = vsd->IOData->Input->DataItem[k];
	    gsdml_eValueDataType datatype;
      
	    gsdml->string_to_value_datatype( di->Body.DataType, &datatype);
	    unsigned int len;

	    sts = gsdml->get_datavalue_length( datatype, di->Body.Length, &len);
	    if ( EVEN(sts)) printf( "GSDML-Error, Datatype %s not yet implemented\n", di->Body.DataType);

1755
	    io_input_length += len;	    
1756
	  }
1757 1758 1759 1760
	  if ( ssd->io_input_length == 0)
	    ssd->io_input_length = io_input_length;
	  else if ( ssd->io_input_length > io_input_length)
	    ssd->io_input_length = io_input_length;
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773
	}
	if ( vsd->IOData->Output) {
	  for ( unsigned k = 0; k < vsd->IOData->Output->DataItem.size(); k++) {

	    gsdml_DataItem *di = vsd->IOData->Output->DataItem[k];
	    gsdml_eValueDataType datatype;
      
	    gsdml->string_to_value_datatype( di->Body.DataType, &datatype);
	    unsigned int len;
	    
	    sts = gsdml->get_datavalue_length( datatype, di->Body.Length, &len);
	    if ( EVEN(sts)) printf( "GSDML-Error, Datatype %s not yet implemented\n", di->Body.DataType);

1774
	    io_output_length += len;	    
1775
	  }
1776 1777 1778 1779
	  if ( ssd->io_output_length == 0)
	    ssd->io_output_length = io_output_length;
	  else if ( ssd->io_output_length > io_output_length)
	    ssd->io_output_length = io_output_length;
1780 1781 1782 1783 1784
	}
      }
    }
  }

1785 1786 1787 1788
  collapse();
  brow_ResetNodraw( brow->ctx);
  brow_Redraw( brow->ctx, 0);

1789
  sts = dev_data.print( filename);
Claes Sjofors's avatar
Claes Sjofors committed
1790 1791 1792

  // Unload channel diag
  dev_data.channel_diag_reset();
1793 1794

  return sts;
Claes Sjofors's avatar
Claes Sjofors committed
1795 1796 1797 1798 1799 1800
}

int GsdmlAttrNav::open( const char *filename)
{
  int sts;

Claes Sjofors's avatar
Claes Sjofors committed
1801 1802
  strncpy( dev_data.gsdmlfile, gsdml->gsdmlfile, sizeof(dev_data.gsdmlfile));

Claes Sjofors's avatar
Claes Sjofors committed
1803
  sts = dev_data.read( filename);
1804 1805
  if ( sts == PB__GSDMLFILEMISMATCH) {
    char msg[300];
Claes Sjofors's avatar
Claes Sjofors committed
1806
    printf( "GSDML-Error, Gsdmlfile doesn't match original filename\n");
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825

    sprintf( msg, "Gsdmlfile doesn't match original filename.\n\nIf the new file is not compatible with the old, configuration data might be corrupt,\nand you should clear the data. The configuration will then be lost.\n\nIf the files are compatible, you should keep the data.");
    int res = wow->CreateModalDialog( "New gsdml filename detected", msg, "Clear Data", 
				      "Keep Data", "Cancel", 0);
    switch( res) {
    case wow_eModalDialogReturn_Button1:
      return sts;
    case wow_eModalDialogReturn_Button2:
      // Keep data
      sts = dev_data.read( filename, 1);      
      if ( EVEN(sts)) return sts;
      break;
    case wow_eModalDialogReturn_Deleted:
    case wow_eModalDialogReturn_Button3:
    case wow_eModalDialogReturn_NYI:
      return PB__CONFIGABORTED;
    }	      
  }
  else if ( EVEN(sts)) return sts;
Claes Sjofors's avatar
Claes Sjofors committed
1826 1827 1828

  device_num = dev_data.device_num;
  gsdml->byte_order = dev_data.byte_order;
Claes Sjofors's avatar
Claes Sjofors committed
1829
  time_ratio = dev_data.iocr_data[0]->reduction_ratio;
1830
  send_clock = dev_data.iocr_data[0]->send_clock_factor;
1831
  phase = dev_data.iocr_data[0]->phase;
Claes Sjofors's avatar
Claes Sjofors committed
1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849
  if ( device_num > 0) {
    if ( device_num > gsdml->ApplicationProcess->DeviceAccessPointList->
	 DeviceAccessPointItem.size()) {
      printf( "GSDML-Read Error: Device number out of range: %d\n", dev_data.device_num);
      return 0;
    }
    device_item = gsdml->ApplicationProcess->DeviceAccessPointList->
      DeviceAccessPointItem[device_num-1];

    // Check text
    if ( strcmp( dev_data.device_text, (char *)device_item->ModuleInfo->Body.Name.p) != 0)
      printf( "GSDML-Read Error: Device name differs \"%s\" \"%s\"\n", dev_data.device_text,
	      (char *)device_item->ModuleInfo->Body.Name.p);
    device_read = 1;
  }
  return 1;
}

1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890
int GsdmlAttrNav::search_class( const char *filename, const char *model, 
				const char *module, char *mclass)
{
  char line[200];
  char itemv[2][200];
  pwr_tFileName fname;
  int num;
  ifstream	fp;
  int in_model = 0;
  int in_par = 0;
  char lmodel[200];
  char lmodule[200];

  dcli_trim( lmodel, (char *)model);
  dcli_trim( lmodule, (char *)module);

  dcli_translate_filename( fname, filename);

  fp.open( fname);
  if ( !fp)
    return 0;

  while ( fp.getline( line, sizeof(line)) ) {
    if ( line[0] == '#')
      continue;

    num = dcli_parse( line, " 	", "",
		      (char *) itemv, sizeof( itemv)/sizeof( itemv[0]), 
		      sizeof( itemv[0]), 0);
    if ( num < 1)
      continue;

    dcli_trim( itemv[0], itemv[0]);
    if ( num >= 2)
      dcli_trim( itemv[1], itemv[1]);

    if ( cdh_NoCaseStrcmp( itemv[0], "Device") == 0) {
      if ( num < 2)
	continue;

      if ( in_model)
1891
	continue;
1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923

      if ( cdh_NoCaseStrcmp( itemv[1], lmodel) == 0)
	in_model = 1;
    }

    if ( in_model) {
      if ( strcmp( itemv[0], "{") == 0)
	in_par = 1;
    }

    if ( in_par) {
      if ( num < 2)
	continue;

      if ( strcmp( itemv[0], "}") == 0)
	break;

      if ( strcmp( itemv[1], "-") == 0 || strcmp( itemv[1], "") == 0)
	continue;

      if ( cdh_NoCaseStrcmp( itemv[0], lmodule) == 0) {
	strncpy( mclass, itemv[1], sizeof( pwr_tObjName));
	fp.close();
	return 1;
      }
    }
  }

  fp.close();
  return 0;
}

Claes Sjofors's avatar
Claes Sjofors committed
1924 1925
ItemPnBase::ItemPnBase( GsdmlAttrNav *attrnav, const char *item_name, const char *attr, 
	int attr_type, int attr_size, double attr_min_limit, 
Claes Sjofors's avatar
Claes Sjofors committed
1926
	double attr_max_limit, void *attr_value_p, int attr_noedit,
Claes Sjofors's avatar
Claes Sjofors committed
1927 1928 1929 1930
	brow_tNode dest, flow_eDest dest_code) :
	value_p(attr_value_p), first_scan(1), 
	type_id(attr_type), size(attr_size), 
	min_limit(attr_min_limit), max_limit(attr_max_limit),
Claes Sjofors's avatar
Claes Sjofors committed
1931
	noedit(attr_noedit), subgraph(0)
Claes Sjofors's avatar
Claes Sjofors committed
1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979
{

  type = attrnav_eItemType_PnBase;

  strcpy( name, item_name);
  memset( old_value, 0, sizeof(old_value));

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		dest, dest_code, (void *) this, 1, &node);

  if ( parent)
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);
  else
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attr);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
  brow_SetTraceAttr( node, attr, "", flow_eTraceType_User);
}

int ItemPnBase::scan( GsdmlAttrNav *attrnav, void *p)
{
  char buf[200];
  int len;

  if ( size == 0)
    return 1;

  if ( !first_scan) {
    if ( size > (int) sizeof(old_value) && 
	 type_id == glow_eType_String &&
	 strlen((char *)p) < sizeof(old_value) && 
	 strcmp( (char *)p, old_value) == 0)
      // No change since last time
      return 1;
    else if ( memcmp( old_value, p, size) == 0)
      // No change since last time
      return 1;
  }
  else
    first_scan = 0;

  attrnav->attrvalue_to_string( type_id, p, buf, sizeof(buf), &len, NULL);
  brow_SetAnnotation( node, 1, buf, len);
  memcpy( old_value, p, min(size, (int) sizeof(old_value)));

  return 1;
}

Claes Sjofors's avatar
Claes Sjofors committed
1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007
void ItemPnBase::value_changed( GsdmlAttrNav *attrnav, char *value_str)
{
  char buffer[1024];
  int sts;

  sts = attrnav->attr_string_to_value( type_id, value_str, 
				       buffer, sizeof(buffer), size);
  if ( EVEN(sts)) {
    attrnav->message( 'E', "Syntax error");
    return;
  }
  
  if ( max_limit != 0 || min_limit != 0) {
    switch ( type_id) {
    case pwr_eType_Int32:
    case pwr_eType_UInt32:
      if ( *(int *)&buffer < min_limit ||
	   *(int *)&buffer > max_limit) {
	attrnav->message( 'E', "Min or maxvalue exceeded");
	return;
      }
      break;
    default: ;
    }
  }
  memcpy( value_p, buffer, size);
  attrnav->set_modified(1);
}
Claes Sjofors's avatar
Claes Sjofors committed
2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023
int ItemPn::close( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Attributes)
      brow_RemoveAnnotPixmap( node, 1);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children) {
      switch ( type) {
      case attrnav_eItemType_PnDevice:
      case attrnav_eItemType_PnParEnum:
2024 2025 2026
      case attrnav_eItemType_PnEnumByteOrder:
      case attrnav_eItemType_PnEnumTimeRatio:
      case attrnav_eItemType_PnEnumSendClock:
Claes Sjofors's avatar
Claes Sjofors committed
2027
      case attrnav_eItemType_PnModuleType:
2028
      case attrnav_eItemType_PnSubmoduleType:
Claes Sjofors's avatar
Claes Sjofors committed
2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089
      case attrnav_eItemType_PnModuleClass:
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);
	break;
      case attrnav_eItemType_PnSlot:
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
	break;
      default:
	if ( parent)
	  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
	else
	  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);
      }
    }
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

ItemPnEnumValue::ItemPnEnumValue( GsdmlAttrNav *attrnav, const char *item_name, int item_num, 
	int item_type_id, void *attr_value_p, 
	brow_tNode dest, flow_eDest dest_code) :
	num(item_num), type_id(item_type_id), value_p(attr_value_p), first_scan(1)
{

  type = attrnav_eItemType_PnEnumValue;

  strcpy( name, item_name);

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_enum, 
		dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attr);
  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
  if ( *(int *)value_p == num)
    brow_SetRadiobutton( node, 0, 1);
  else
    brow_SetRadiobutton( node, 0, 0);
  brow_SetTraceAttr( node, name, "", flow_eTraceType_User);
}

int ItemPnEnumValue::scan( GsdmlAttrNav *attrnav, void *p)
{
  if ( !first_scan) {
    if ( old_value == *(int *)p)
      // No change since last time
      return 1;
  }
  else
    first_scan = 0;

  if ( *(int *)p == num)
    brow_SetRadiobutton( node, 0, 1);
  else
    brow_SetRadiobutton( node, 0, 0);

  old_value = *(int *) p;
  return 1;
}

2090 2091 2092 2093 2094 2095 2096 2097 2098 2099
ItemPnEnumValueMType::ItemPnEnumValueMType( GsdmlAttrNav *attrnav, const char *item_name, 
					    const char *item_number, int item_num, 
					    int item_type_id, void *attr_value_p, 
					    brow_tNode dest, flow_eDest dest_code) :
  num(item_num), type_id(item_type_id), value_p(attr_value_p), first_scan(1)
{

  type = attrnav_eItemType_PnEnumValueMType;

  strcpy( name, item_name);
2100
  strcpy( number, item_number);
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_enum_mtype, 
		dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attr);
  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
  brow_SetAnnotation( node, 1, item_number, strlen(item_number));
  if ( *(int *)value_p == num)
    brow_SetRadiobutton( node, 0, 1);
  else
    brow_SetRadiobutton( node, 0, 0);
  brow_SetTraceAttr( node, name, "", flow_eTraceType_User);
}

int ItemPnEnumValueMType::scan( GsdmlAttrNav *attrnav, void *p)
{
  if ( !first_scan) {
    if ( old_value == *(int *)p)
      // No change since last time
      return 1;
  }
  else
    first_scan = 0;

  if ( *(int *)p == num)
    brow_SetRadiobutton( node, 0, 1);
  else
    brow_SetRadiobutton( node, 0, 0);

  old_value = *(int *) p;
  return 1;
}

Claes Sjofors's avatar
Claes Sjofors committed
2134 2135
ItemPnDevice::ItemPnDevice( GsdmlAttrNav *attrnav, const char *item_name, 
			    brow_tNode dest, flow_eDest dest_code):
Claes Sjofors's avatar
Claes Sjofors committed
2136
  old_value(0), first_scan(1)
Claes Sjofors's avatar
Claes Sjofors committed
2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195
{
  type = attrnav_eItemType_PnDevice;

  strcpy( name, item_name);

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
  brow_SetTraceAttr( node, name, "", flow_eTraceType_User);
}

int ItemPnDevice::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Attributes)
      //brow_RemoveAnnotPixmap( node, 1);
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    int idx = 0;
    new ItemPnEnumValue( attrnav, "No", idx++, pwr_eType_UInt32, 
			 &attrnav->device_num, node, flow_eDest_IntoLast);
    
    for ( unsigned int i = 0; i < attrnav->gsdml->ApplicationProcess->DeviceAccessPointList->DeviceAccessPointItem.size(); i++) {
      char name[80];
      strncpy( name, (char *)attrnav->gsdml->ApplicationProcess->DeviceAccessPointList->DeviceAccessPointItem[i]->ModuleInfo->Body.Name.p, sizeof(name));
      new ItemPnEnumValue( attrnav, name, idx++, pwr_eType_UInt32, 
			   &attrnav->device_num, node, flow_eDest_IntoLast);
    }

    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

int ItemPnDevice::scan( GsdmlAttrNav *attrnav, void *p)
{
  char buf[200];

Claes Sjofors's avatar
Claes Sjofors committed
2196
  // Note, first scan is set the two first scans to detect load from data file
Claes Sjofors's avatar
Claes Sjofors committed
2197 2198 2199 2200 2201 2202 2203 2204 2205
  if ( !first_scan) {
    if ( old_value == *(int *)p)
      // No change since last time
      return 1;
  }

  if ( attrnav->device_confirm_active)
    return 1;

Claes Sjofors's avatar
Claes Sjofors committed
2206

Claes Sjofors's avatar
Claes Sjofors committed
2207 2208
  if ( !first_scan) {
    if (old_value == 0) {
Claes Sjofors's avatar
Claes Sjofors committed
2209
      GsdmlAttrNav::device_changed_ok( attrnav, (void *)((long int)old_value));
Claes Sjofors's avatar
Claes Sjofors committed
2210 2211 2212
      return 1;
    }
    else {
2213 2214 2215 2216 2217 2218 2219 2220 2221

      if (GsdmlAttrNav::device_check_change_ok( attrnav)) {
	GsdmlAttrNav::device_update_change(attrnav);
      }
      else {
	attrnav->wow->DisplayQuestion( attrnav, "Device Changed", 
				       "All configuration data will be lost when changing the device.\n"
				       "Do you really want to change the device ?",
				       GsdmlAttrNav::device_changed_ok, GsdmlAttrNav::device_changed_cancel, 
Claes Sjofors's avatar
Claes Sjofors committed
2222
				       (void *)((long int)old_value));
2223 2224 2225
	attrnav->device_confirm_active = 1;
	return 1;
      }
Claes Sjofors's avatar
Claes Sjofors committed
2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250
    }
  }

  if ( *(int *)p == 0)
    strcpy( buf, "No");
  else {
    if ( attrnav->device_num == 0)
      strcpy( buf, "No");
    else {
      strncpy( buf, (char *)attrnav->gsdml->ApplicationProcess->DeviceAccessPointList->
	       DeviceAccessPointItem[attrnav->device_num-1]->ModuleInfo->Body.Name.p, 
	       sizeof(buf));
    }
  }
  brow_SetAnnotation( node, 1, buf, strlen(buf));
  old_value = attrnav->device_num;

  if ( first_scan)
    first_scan = 0;

  return 1;
}

ItemPnSlot::ItemPnSlot( GsdmlAttrNav *attrnav, const char *item_name,
			GsdmlSlotData *item_slotdata, brow_tNode dest, flow_eDest dest_code) :
Claes Sjofors's avatar
Claes Sjofors committed
2251
  slotdata(item_slotdata), old_value(0), first_scan(1)
Claes Sjofors's avatar
Claes Sjofors committed
2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294
{
  type = attrnav_eItemType_PnSlot;

  strcpy( name, item_name);

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
  brow_SetTraceAttr( node, name, "", flow_eTraceType_User);
}

int ItemPnSlot::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Attributes)
      brow_RemoveAnnotPixmap( node, 1);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    new ItemPnModuleType( attrnav, "ModuleType", slotdata->slot_number, slotdata->slot_idx,
			  node, flow_eDest_IntoLast);
    if ( slotdata->module_enum_number != 0) {
      new ItemPnModuleClass( attrnav, "ModuleClass", slotdata, node, flow_eDest_IntoLast);

      gsdml_UseableModules *um = attrnav->gsdml->ApplicationProcess->DeviceAccessPointList->
	DeviceAccessPointItem[attrnav->device_num-1]->UseableModules;
      if ( um) {
Claes Sjofors's avatar
Claes Sjofors committed
2295 2296
	unsigned int subslot_number = 0;
	unsigned int subslot_index = 0;
Claes Sjofors's avatar
Claes Sjofors committed
2297 2298
	gsdml_ModuleItem *mi = (gsdml_ModuleItem *)um->
	  ModuleItemRef[slotdata->module_enum_number-1]->Body.ModuleItemTarget.p;
Claes Sjofors's avatar
Claes Sjofors committed
2299

Claes Sjofors's avatar
Claes Sjofors committed
2300 2301 2302 2303 2304 2305 2306
	if ( mi && mi->ModuleInfo) {
	  new ItemPnModuleInfo( attrnav, "ModuleInfo", mi->ModuleInfo,
				node, flow_eDest_IntoLast);
	}
	if ( mi->VirtualSubmoduleList) {
	  char subslot_name[80];

Claes Sjofors's avatar
Claes Sjofors committed
2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317
	  for ( unsigned int i = 0; i < mi->VirtualSubmoduleList->VirtualSubmoduleItem.size();
		i++) {
	    if ( strcmp( mi->VirtualSubmoduleList->VirtualSubmoduleItem[i]->Body.FixedInSubslots.str, "") == 0) {
	      // FixedInSubslots not supplied, default subslot number is 1 

	      if ( mi->VirtualSubmoduleList->VirtualSubmoduleItem.size() == 1)
		subslot_number = 1;
	      else
		subslot_number++;

	      sprintf( subslot_name, "Subslot %d", subslot_number);
Claes Sjofors's avatar
Claes Sjofors committed
2318
	    
Claes Sjofors's avatar
Claes Sjofors committed
2319 2320 2321 2322 2323
	      GsdmlSubslotData *ssd;
	      if ( slotdata->subslot_data.size() <= subslot_index) {
		ssd = new GsdmlSubslotData();
		ssd->subslot_number = subslot_number;
		ssd->subslot_idx = subslot_index;
2324 2325
		ssd->submodule_ident_number = 
		    mi->VirtualSubmoduleList->VirtualSubmoduleItem[i]->Body.SubmoduleIdentNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2326 2327 2328 2329 2330
		slotdata->subslot_data.push_back(ssd);
	      }
	      else {
		ssd = slotdata->subslot_data[subslot_index];
		ssd->subslot_idx = subslot_index;
2331 2332
		ssd->submodule_ident_number = 
		    mi->VirtualSubmoduleList->VirtualSubmoduleItem[i]->Body.SubmoduleIdentNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2333
		if ( ssd->subslot_number != subslot_number) {
2334
		  ssd->subslot_number = subslot_number;
Claes Sjofors's avatar
Claes Sjofors committed
2335 2336 2337 2338 2339
		  printf( "GSML-Error, datafile corrupt, unexpected subslot number\n");
		}
	      }
	      
	      new ItemPnSubslot( attrnav, subslot_name, ssd,
2340
				 mi->VirtualSubmoduleList->VirtualSubmoduleItem[0], slotdata->slot_idx,
Claes Sjofors's avatar
Claes Sjofors committed
2341 2342
				 node, flow_eDest_IntoLast);
		
Claes Sjofors's avatar
Claes Sjofors committed
2343 2344
	    }
	    else {
Claes Sjofors's avatar
Claes Sjofors committed
2345 2346
	      // FixedInSubslots supplied, create all fixed subslots

2347
 	      gsdml_Valuelist *vl = new gsdml_Valuelist(  mi->VirtualSubmoduleList->
Claes Sjofors's avatar
Claes Sjofors committed
2348 2349 2350 2351
			    VirtualSubmoduleItem[i]->Body.FixedInSubslots.str);
	      gsdml_ValuelistIterator iter( vl);

	      for ( unsigned int j = iter.begin(); j != iter.end(); j = iter.next()) {
2352

Claes Sjofors's avatar
Claes Sjofors committed
2353 2354 2355 2356 2357 2358 2359 2360
		subslot_number = j;
		sprintf( subslot_name, "Subslot %d", subslot_number);
	    
		GsdmlSubslotData *ssd;
		if ( slotdata->subslot_data.size() <= subslot_index) {
		  ssd = new GsdmlSubslotData();
		  ssd->subslot_number = subslot_number;
		  ssd->subslot_idx = subslot_index;
2361 2362
		  ssd->submodule_ident_number = 
		    mi->VirtualSubmoduleList->VirtualSubmoduleItem[i]->Body.SubmoduleIdentNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2363 2364 2365 2366 2367
		  slotdata->subslot_data.push_back(ssd);
		}
		else {
		  ssd = slotdata->subslot_data[subslot_index];
		  ssd->subslot_idx = subslot_index;
2368 2369
		  ssd->submodule_ident_number = 
		    mi->VirtualSubmoduleList->VirtualSubmoduleItem[i]->Body.SubmoduleIdentNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2370
		  if ( ssd->subslot_number != subslot_number) {
2371
		    ssd->subslot_number = subslot_number;
Claes Sjofors's avatar
Claes Sjofors committed
2372 2373 2374 2375 2376
		    printf( "GSML-Error, datafile corrupt, unexpected subslot number\n");
		  }
		}
		
		new ItemPnSubslot( attrnav, subslot_name, ssd,
2377
				   mi->VirtualSubmoduleList->VirtualSubmoduleItem[i], slotdata->slot_idx,
Claes Sjofors's avatar
Claes Sjofors committed
2378 2379
				   node, flow_eDest_IntoLast);
		subslot_index++;
Claes Sjofors's avatar
Claes Sjofors committed
2380
	      }
Claes Sjofors's avatar
Claes Sjofors committed
2381
	      delete vl;
Claes Sjofors's avatar
Claes Sjofors committed
2382 2383 2384
	    }
	  }
	}
2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465
	if ( mi->UseableSubmodules  && strcmp( mi->Body.PhysicalSubslots.str, "") != 0) {
	  gsdml_Valuelist *vl = new gsdml_Valuelist(  mi->Body.PhysicalSubslots.str);
	  gsdml_ValuelistIterator iter( vl);
	  char subslot_name[80];

	  for ( unsigned int j = iter.begin(); j != iter.end(); j = iter.next()) {

	    // Check that there is an useable module for this slot
	    int fixed_found = 0;
	    int fixed_enum = 0;
	    gsdml_VirtualSubmoduleItem *fixed_si = 0;
	    int used_found = 0;
	    int used_enum = 0;
	    gsdml_VirtualSubmoduleItem *used_si = 0;

	    for ( unsigned int i = 0; i < mi->UseableSubmodules->SubmoduleItemRef.size(); i++) {
	      gsdml_Valuelist *vl_allowed = new gsdml_Valuelist( mi->UseableSubmodules->SubmoduleItemRef[i]->Body.AllowedInSubslots.str);
	      gsdml_Valuelist *vl_fixed = new gsdml_Valuelist( mi->UseableSubmodules->SubmoduleItemRef[i]->Body.FixedInSubslots.str);
	      gsdml_Valuelist *vl_used = new gsdml_Valuelist( mi->UseableSubmodules->SubmoduleItemRef[i]->Body.UsedInSubslots.str);

	      if ( vl_allowed->in_list( j)) {

		// Check if fixed
		if ( vl_fixed->in_list(j)) {
		  // Fixed in subslot, insert the submodule directly
		  fixed_found = 1;
		  fixed_si = (gsdml_VirtualSubmoduleItem *)mi->UseableSubmodules->SubmoduleItemRef[i]->Body.SubmoduleItemTarget.p;
		  for ( unsigned int k = 0; 
			k < attrnav->gsdml->ApplicationProcess->SubmoduleList->SubmoduleItem.size();
			k++) {
		    if ( attrnav->gsdml->ApplicationProcess->SubmoduleList->SubmoduleItem[k] == fixed_si) {
		      fixed_enum = k + 1;
		      break;
		    }
		  }		    
		}

		// Check if used
		if ( vl_used->in_list(j)) {
		  used_found = 1;
		  used_si = (gsdml_VirtualSubmoduleItem *)mi->UseableSubmodules->SubmoduleItemRef[i]->Body.SubmoduleItemTarget.p;
		  for ( unsigned int k = 0; 
			k < attrnav->gsdml->ApplicationProcess->SubmoduleList->SubmoduleItem.size();
			k++) {
		    if ( attrnav->gsdml->ApplicationProcess->SubmoduleList->SubmoduleItem[k] == used_si) {
		      used_enum = k + 1;
		      break;
		    }
		  }		    
		}
	      }
	      delete vl_allowed;
	      delete vl_used;
	      delete vl_fixed;
	    }

	    subslot_number = j;
	    sprintf( subslot_name, "Subslot %d", subslot_number);

	    if ( fixed_found ) {
	    
	      GsdmlSubslotData *ssd;
	      if ( slotdata->subslot_data.size() <= subslot_index) {
		ssd = new GsdmlSubslotData();
		ssd->subslot_number = subslot_number;
		ssd->subslot_idx = subslot_index;
		ssd->submodule_ident_number = fixed_si->Body.SubmoduleIdentNumber;
		ssd->submodule_enum_number = fixed_enum;
		slotdata->subslot_data.push_back(ssd);
	      }
	      else {
		ssd = slotdata->subslot_data[subslot_index];
		ssd->subslot_idx = subslot_index;
		ssd->submodule_ident_number = fixed_si->Body.SubmoduleIdentNumber;
		ssd->submodule_enum_number = fixed_enum;
		if ( ssd->subslot_number != subslot_number) {
		  ssd->subslot_number = subslot_number;
		  printf( "GSML-Error, datafile corrupt, unexpected subslot number\n");
		}
	      }
		
2466
	      new ItemPnSubslot( attrnav, subslot_name, ssd, fixed_si, slotdata->slot_idx,
2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505
				     node, flow_eDest_IntoLast);
	      subslot_index++;
	    }
	    else {

	      // Add selectable subslot
	      GsdmlSubslotData *ssd;

	      if ( slotdata->subslot_data.size() <= subslot_index) {
		ssd = new GsdmlSubslotData();
		ssd->subslot_number = subslot_number;
		ssd->subslot_idx = subslot_index;
		if ( used_found) {
		  ssd->submodule_ident_number = used_si->Body.SubmoduleIdentNumber;
		  ssd->submodule_enum_number = used_enum;
		}
		slotdata->subslot_data.push_back(ssd);
	      }
	      else {
		ssd = slotdata->subslot_data[subslot_index];
		ssd->subslot_idx = subslot_index;
		if ( ssd->subslot_number != subslot_number) {
		  ssd->subslot_number = subslot_number;
		  printf( "GSML-Error, datafile corrupt, unexpected subslot number\n");
		}
		else if ( used_found) {
		  ssd->submodule_ident_number = used_si->Body.SubmoduleIdentNumber;
		  ssd->submodule_enum_number = used_enum;
		}
	      }

	      new ItemPnSubslotPhys( attrnav, subslot_name, ssd, used_si, slotdata->slot_idx,
				     mi->UseableSubmodules,
				     node, flow_eDest_IntoLast);
	      subslot_index++;
	    }
	  }
	  delete vl;
	}	
Claes Sjofors's avatar
Claes Sjofors committed
2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549
      }
    }
    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

int ItemPnSlot::scan( GsdmlAttrNav *attrnav, void *p)
{
  char buf[200];

  if ( !first_scan) {
    if ( old_value == *(int *)p)
      // No change since last time
      return 1;
  }

  if ( *(int *)p == 0)
    strcpy( buf, "No");
  else {
    gsdml_UseableModules *um = attrnav->gsdml->ApplicationProcess->DeviceAccessPointList->
      DeviceAccessPointItem[attrnav->device_num-1]->UseableModules;
    if ( !um)
      return 1;
    gsdml_ModuleItem *mi = (gsdml_ModuleItem *)um->
      ModuleItemRef[slotdata->module_enum_number-1]->Body.ModuleItemTarget.p;
    if ( !mi || !mi->ModuleInfo->Body.Name.p)
      return 1;
    strncpy( buf, (char *) mi->ModuleInfo->Body.Name.p, sizeof(buf));
  }
  brow_SetAnnotation( node, 1, buf, strlen(buf));
  old_value = *(int *)p;

  if ( first_scan)
    first_scan = 0;

  return 1;
}

ItemPnSubslot::ItemPnSubslot( GsdmlAttrNav *attrnav, const char *item_name, 
			      GsdmlSubslotData *item_subslotdata, 
2550
			      gsdml_VirtualSubmoduleItem *item_virtualsubmodule, int item_slot_idx,
Claes Sjofors's avatar
Claes Sjofors committed
2551
			      brow_tNode dest, flow_eDest dest_code) :
2552
  subslotdata(item_subslotdata), virtualsubmodule(item_virtualsubmodule), slot_idx(item_slot_idx)
Claes Sjofors's avatar
Claes Sjofors committed
2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618
{
  type = attrnav_eItemType_PnSubslot;

  strcpy( name, item_name);

  if ( virtualsubmodule && virtualsubmodule->RecordDataList)
    parent = 1;

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  if ( parent)
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
  else
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
}

int ItemPnSubslot::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children) {
      if ( parent)
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
      else
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);
    }
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    unsigned int record_index = 0;
    if ( virtualsubmodule) {      
      gsdml_RecordDataList *rl = virtualsubmodule->RecordDataList;
      if ( rl) {
	GsdmlDataRecord *dr;

	for ( unsigned int j = 0; j < rl->ParameterRecordDataItem.size(); j++) {
	  if ( subslotdata->data_record.size() <= record_index) {
	    dr = new GsdmlDataRecord();
	    dr->record_idx = record_index;
	    subslotdata->data_record.push_back(dr);
	  }
	  else {
	    dr = subslotdata->data_record[record_index];
	    dr->record_idx = record_index;
	  }

	  new ItemPnParRecord( attrnav, "", rl->ParameterRecordDataItem[j], dr,
			       node, flow_eDest_IntoLast);
	  record_index++;
	}
      }
    }

Claes Sjofors's avatar
Claes Sjofors committed
2619
    if ( attrnav->viewio && virtualsubmodule->IOData) {
2620
      new ItemPnIOData( attrnav, "IOData", virtualsubmodule->IOData, subslotdata->subslot_idx, slot_idx,
Claes Sjofors's avatar
Claes Sjofors committed
2621 2622
			node, flow_eDest_IntoLast);
    }
Claes Sjofors's avatar
Claes Sjofors committed
2623 2624 2625 2626 2627 2628 2629 2630
    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718
ItemPnSubslotPhys::ItemPnSubslotPhys( GsdmlAttrNav *attrnav, const char *item_name, 
				      GsdmlSubslotData *item_subslotdata,
				      gsdml_VirtualSubmoduleItem *item_virtualsubmodule,
				      int item_slot_idx,
				      gsdml_UseableSubmodules *item_us,
				      brow_tNode dest, flow_eDest dest_code) :
  subslotdata(item_subslotdata), virtualsubmodule(item_virtualsubmodule), 
  us(item_us), slot_idx(item_slot_idx)
{
  type = attrnav_eItemType_PnSubslotPhys;

  strcpy( name, item_name);

  parent = 1;

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  if ( parent)
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
  else
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
}

int ItemPnSubslotPhys::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children) {
      if ( parent)
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
      else
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);
    }
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    new ItemPnSubmoduleType( attrnav, "SubmoduleType", subslotdata->subslot_number, slot_idx,
			     subslotdata->subslot_idx, us,
			     node, flow_eDest_IntoLast);

    gsdml_VirtualSubmoduleItem *subm = 0;
    if ( subslotdata->submodule_enum_number) {
      subm = attrnav->gsdml->ApplicationProcess->SubmoduleList->SubmoduleItem[subslotdata->submodule_enum_number - 1];
    }
    
    if ( subm && subm->ModuleInfo) {
      new ItemPnModuleInfo( attrnav, "SubmoduleInfo", subm->ModuleInfo,
			    node, flow_eDest_IntoLast);
    }

    unsigned int record_index = 0;
    if ( subm) {      
      gsdml_RecordDataList *rl = subm->RecordDataList;
      if ( rl) {
	GsdmlDataRecord *dr;

	for ( unsigned int j = 0; j < rl->ParameterRecordDataItem.size(); j++) {
	  if ( subslotdata->data_record.size() <= record_index) {
	    dr = new GsdmlDataRecord();
	    dr->record_idx = record_index;
	    subslotdata->data_record.push_back(dr);
	  }
	  else {
	    dr = subslotdata->data_record[record_index];
	    dr->record_idx = record_index;
	  }

	  new ItemPnParRecord( attrnav, "", rl->ParameterRecordDataItem[j], dr,
			       node, flow_eDest_IntoLast);
	  record_index++;
	}
      }
    }

    if ( attrnav->viewio && subm && subm->IOData) {
2719
      new ItemPnIOData( attrnav, "IOData", subm->IOData, subslotdata->subslot_idx, slot_idx,
2720 2721 2722 2723 2724 2725 2726 2727 2728 2729
			node, flow_eDest_IntoLast);
    }
    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

Claes Sjofors's avatar
Claes Sjofors committed
2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765
ItemPnDAP::ItemPnDAP( GsdmlAttrNav *attrnav, const char *item_name, GsdmlSlotData *item_slotdata,
		      brow_tNode dest, flow_eDest dest_code) : slotdata(item_slotdata)
{
  type = attrnav_eItemType_PnDAP;

  strcpy( name, item_name);
  parent = 1;

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_object, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
}

int ItemPnDAP::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    if ( attrnav->device_num) {
Claes Sjofors's avatar
Claes Sjofors committed
2766
      gsdml_DeviceAccessPointItem *mi = attrnav->device_item;
Claes Sjofors's avatar
Claes Sjofors committed
2767
      unsigned int subslot_index = 0;
Claes Sjofors's avatar
Claes Sjofors committed
2768
      unsigned int subslot_number = 0;
Claes Sjofors's avatar
Claes Sjofors committed
2769 2770 2771 2772 2773 2774

      if ( attrnav->device_item->ModuleInfo) {
	new ItemPnModuleInfo( attrnav, "ModuleInfo", attrnav->device_item->ModuleInfo,
			      node, flow_eDest_IntoLast);
      }

Claes Sjofors's avatar
Claes Sjofors committed
2775 2776
      if ( mi->VirtualSubmoduleList) {
	char subslot_name[80];
Claes Sjofors's avatar
Claes Sjofors committed
2777

Claes Sjofors's avatar
Claes Sjofors committed
2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794
	for ( unsigned int i = 0; i < mi->VirtualSubmoduleList->VirtualSubmoduleItem.size();
	      i++) {
	  if ( strcmp( mi->VirtualSubmoduleList->VirtualSubmoduleItem[i]->Body.FixedInSubslots.str, "") == 0) {
	    // FixedInSubslots not supplied, default subslot number is 1 

	    if ( mi->VirtualSubmoduleList->VirtualSubmoduleItem.size() == 1)
	      subslot_number = 1;
	    else
	      subslot_number++;
	    
	    sprintf( subslot_name, "Subslot %d", subslot_number);
	    
	    GsdmlSubslotData *ssd;
	    if ( slotdata->subslot_data.size() <= subslot_index) {
	      ssd = new GsdmlSubslotData();
	      ssd->subslot_number = subslot_number;
	      ssd->subslot_idx = subslot_index;
2795 2796
	      ssd->submodule_ident_number = 
		mi->VirtualSubmoduleList->VirtualSubmoduleItem[i]->Body.SubmoduleIdentNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2797 2798 2799 2800 2801
	      slotdata->subslot_data.push_back(ssd);
	    }
	    else {
	      ssd = slotdata->subslot_data[subslot_index];
	      ssd->subslot_idx = subslot_index;
2802 2803
	      ssd->submodule_ident_number = 
		mi->VirtualSubmoduleList->VirtualSubmoduleItem[i]->Body.SubmoduleIdentNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2804
	      if ( ssd->subslot_number != subslot_number) {
2805
		ssd->subslot_number = subslot_number;
Claes Sjofors's avatar
Claes Sjofors committed
2806 2807 2808 2809 2810
		printf( "GSML-Error, datafile corrupt, unexpected subslot number\n");
	      }
	    }
	    
	    new ItemPnSubslot( attrnav, subslot_name, ssd,
2811
			       mi->VirtualSubmoduleList->VirtualSubmoduleItem[0], slotdata->slot_idx,
Claes Sjofors's avatar
Claes Sjofors committed
2812 2813 2814
			       node, flow_eDest_IntoLast);
		
	    subslot_index++;
Claes Sjofors's avatar
Claes Sjofors committed
2815 2816
	  }
	  else {
Claes Sjofors's avatar
Claes Sjofors committed
2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831
	    // FixedInSubslots supplied, create all fixed subslots

	    gsdml_Valuelist *vl = new gsdml_Valuelist(  mi->VirtualSubmoduleList->
			    VirtualSubmoduleItem[i]->Body.FixedInSubslots.str);
	    gsdml_ValuelistIterator iter( vl);

	    for ( unsigned int j = iter.begin(); j != iter.end(); j = iter.next()) {
	      subslot_number = j;
	      sprintf( subslot_name, "Subslot %d", subslot_number);
	      
	      GsdmlSubslotData *ssd;
	      if ( slotdata->subslot_data.size() <= subslot_index) {
		ssd = new GsdmlSubslotData();
		ssd->subslot_number = subslot_number;
		ssd->subslot_idx = subslot_index;
2832 2833
		ssd->submodule_ident_number = 
		  mi->VirtualSubmoduleList->VirtualSubmoduleItem[i]->Body.SubmoduleIdentNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2834 2835 2836 2837 2838
		slotdata->subslot_data.push_back(ssd);
	      }
	      else {
		ssd = slotdata->subslot_data[subslot_index];
		ssd->subslot_idx = subslot_index;
2839 2840
		ssd->submodule_ident_number = 
		    mi->VirtualSubmoduleList->VirtualSubmoduleItem[i]->Body.SubmoduleIdentNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2841
		if ( ssd->subslot_number != subslot_number) {
2842
		  ssd->subslot_number = subslot_number;
Claes Sjofors's avatar
Claes Sjofors committed
2843 2844 2845 2846 2847
		  printf( "GSML-Error, datafile corrupt, unexpected subslot number\n");
		}
	      }
		
	      new ItemPnSubslot( attrnav, subslot_name, ssd,
2848
				 mi->VirtualSubmoduleList->VirtualSubmoduleItem[i], slotdata->slot_idx,
Claes Sjofors's avatar
Claes Sjofors committed
2849 2850
				 node, flow_eDest_IntoLast);
	      subslot_index++;
Claes Sjofors's avatar
Claes Sjofors committed
2851
	    }
Claes Sjofors's avatar
Claes Sjofors committed
2852
	    delete vl;
Claes Sjofors's avatar
Claes Sjofors committed
2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877
	  }
	}
      }
      if ( attrnav->device_item->SystemDefinedSubmoduleList) {
	if ( attrnav->device_item->SystemDefinedSubmoduleList->InterfaceSubmoduleItem) {
	  gsdml_InterfaceSubmoduleItem *ii = attrnav->device_item->SystemDefinedSubmoduleList->
	    InterfaceSubmoduleItem;
	  char name[200] = "Interface ";

	  if ( attrnav->device_item->SubslotList) {
	    for ( unsigned int i = 0; i < attrnav->device_item->SubslotList->SubslotItem.size(); i++) {
	      if ( ii->Body.SubslotNumber == 
		   attrnav->device_item->SubslotList->SubslotItem[i]->Body.SubslotNumber) {
		strncat( name, (char *)attrnav->device_item->SubslotList->SubslotItem[i]->Body.TextId.p, sizeof(name)-strlen(name));
		strncat( name, " ", sizeof(name)-strlen(name));
		sprintf( &name[strlen(name)], "%hu", ii->Body.SubslotNumber);
	      }
	    }
	  }

	  GsdmlSubslotData *ssd;
	  if ( slotdata->subslot_data.size() <= subslot_index) {
	    ssd = new GsdmlSubslotData();
	    ssd->subslot_number = ii->Body.SubslotNumber;
	    ssd->subslot_idx = subslot_index;
2878
	    ssd->submodule_ident_number = ii->Body.SubmoduleIdentNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2879 2880 2881 2882 2883
	    slotdata->subslot_data.push_back(ssd);
	  }
	  else {
	    ssd = slotdata->subslot_data[subslot_index];
	    ssd->subslot_idx = subslot_index;
2884
	    ssd->submodule_ident_number = ii->Body.SubmoduleIdentNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2885
	    if ( ssd->subslot_number != ii->Body.SubslotNumber) {
2886
	      ssd->subslot_number = ii->Body.SubslotNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913
	      printf( "GSML-Error, datafile corrupt, unexpected subslot number\n");
	    }
	  }

	  new ItemPnInterfaceSubmodule( attrnav, name, ii, ssd, node, flow_eDest_IntoLast);
 	  subslot_index++;
	}
        for ( unsigned int j = 0; 
	      j < attrnav->device_item->SystemDefinedSubmoduleList->PortSubmoduleItem.size(); 
	      j++) {
	  gsdml_PortSubmoduleItem *pi = attrnav->device_item->SystemDefinedSubmoduleList->
	    PortSubmoduleItem[j];
	  char name[80] = "Port ";
	  
	  for ( unsigned int i = 0; i < attrnav->device_item->SubslotList->SubslotItem.size(); i++) {
	    if ( pi->Body.SubslotNumber == attrnav->device_item->SubslotList->SubslotItem[i]->Body.SubslotNumber) {
		strncat( name, (char *)attrnav->device_item->SubslotList->SubslotItem[i]->Body.TextId.p, sizeof(name)-strlen(name));
		strncat( name, " ", sizeof(name)-strlen(name));
		sprintf( &name[strlen(name)], "%hu", pi->Body.SubslotNumber);
	    }
	  }

	  GsdmlSubslotData *ssd;
	  if ( slotdata->subslot_data.size() <= subslot_index) {
	    ssd = new GsdmlSubslotData();
	    ssd->subslot_number = pi->Body.SubslotNumber;
	    ssd->subslot_idx = subslot_index;
2914
	    ssd->submodule_ident_number = pi->Body.SubmoduleIdentNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2915 2916 2917 2918 2919
	    slotdata->subslot_data.push_back(ssd);
	  }
	  else {
	    ssd = slotdata->subslot_data[subslot_index];
	    ssd->subslot_idx = subslot_index;
2920
	    ssd->submodule_ident_number = pi->Body.SubmoduleIdentNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2921
	    if ( ssd->subslot_number != pi->Body.SubslotNumber) {
2922
	      ssd->subslot_number = pi->Body.SubslotNumber;
Claes Sjofors's avatar
Claes Sjofors committed
2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978
	      printf( "GSML-Error, datafile corrupt, unexpected subslot number\n");
	    }
	  }

	  new ItemPnPortSubmodule( attrnav, name, pi, ssd, node, flow_eDest_IntoLast);
 	  subslot_index++;
	}
      }
    }

    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

ItemPnNetwork::ItemPnNetwork( GsdmlAttrNav *attrnav, const char *item_name, 
			      brow_tNode dest, flow_eDest dest_code)
{
  type = attrnav_eItemType_PnNetwork;

  strcpy( name, item_name);
  parent = 1;

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_object, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
}

int ItemPnNetwork::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    void *p = (void *) attrnav->dev_data.device_name;
    new ItemPnBase( attrnav, "DeviceName", "LocalGsdmlAttr", 
		    pwr_eType_String, sizeof(attrnav->dev_data.device_name), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
2979
		    p, 0, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
2980 2981 2982 2983

    p = (void *) attrnav->dev_data.ip_address;
    new ItemPnBase( attrnav, "IP Address", "LocalGsdmlAttr", 
		    pwr_eType_String, sizeof(attrnav->dev_data.ip_address), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
2984
		    p, 0, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
2985 2986 2987 2988

    p = (void *) attrnav->dev_data.subnet_mask;
    new ItemPnBase( attrnav, "Subnet Mask", "LocalGsdmlAttr", 
		    pwr_eType_String, sizeof(attrnav->dev_data.subnet_mask), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
2989
		    p, 0, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
2990 2991 2992 2993

    p = (void *) attrnav->dev_data.mac_address;
    new ItemPnBase( attrnav, "MAC Address", "LocalGsdmlAttr", 
		    pwr_eType_String, sizeof(attrnav->dev_data.mac_address), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
2994 2995 2996
		    p, 0, node, flow_eDest_IntoLast);

    if ( attrnav->device_item && attrnav->device_item->SystemDefinedSubmoduleList &&
2997 2998 2999 3000 3001 3002
	 attrnav->device_item->SystemDefinedSubmoduleList->InterfaceSubmoduleItem) {
      p = (void *) &attrnav->send_clock;
      new ItemPnEnumSendClock( attrnav, "SendClock", 
			       attrnav->device_item->SystemDefinedSubmoduleList->InterfaceSubmoduleItem,
			       p, node, flow_eDest_IntoLast);

Claes Sjofors's avatar
Claes Sjofors committed
3003
      p = (void *) &attrnav->time_ratio;
3004
      new ItemPnEnumTimeRatio( attrnav, "ReductionRatio", 
Claes Sjofors's avatar
Claes Sjofors committed
3005 3006
			       attrnav->device_item->SystemDefinedSubmoduleList->InterfaceSubmoduleItem,
			       p, node, flow_eDest_IntoLast);
3007 3008 3009 3010 3011

      p = (void *) &attrnav->phase;
      new ItemPnBase( attrnav, "Phase", "LocalGsdmlAttr", 
		    pwr_eType_UInt32, sizeof(pwr_tUInt32), 0, 0,
		    p, 0, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3012
    }
3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026
    else {
      p = (void *) &attrnav->send_clock;
       new ItemPnEnumSendClock( attrnav, "SendClock", 
			       0, p, node, flow_eDest_IntoLast);

      p = (void *) &attrnav->time_ratio;
      new ItemPnEnumTimeRatio( attrnav, "ReductionRatio", 
			       0, p, node, flow_eDest_IntoLast);

      p = (void *) &attrnav->phase;
      new ItemPnBase( attrnav, "Phase", "LocalGsdmlAttr", 
		    pwr_eType_UInt32, sizeof(pwr_tUInt32), 0, 0,
		    p, 0, node, flow_eDest_IntoLast);
    }
Claes Sjofors's avatar
Claes Sjofors committed
3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072
    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

ItemPnDeviceInfo::ItemPnDeviceInfo( GsdmlAttrNav *attrnav, const char *item_name, 
				    brow_tNode dest, flow_eDest dest_code)
{
  type = attrnav_eItemType_PnDeviceInfo;

  strcpy( name, item_name);
  parent = 1;

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_object, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
}

int ItemPnDeviceInfo::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    void *p = (void *) attrnav->gsdml->DeviceIdentity->Body.VendorName;
    new ItemPnBase( attrnav, "Vendor", "LocalGsdmlAttr", 
		    pwr_eType_String, sizeof(pwr_tString80), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3073
		    p, 1,
Claes Sjofors's avatar
Claes Sjofors committed
3074 3075 3076 3077 3078
		    node, flow_eDest_IntoLast);
    
    p = (void *) attrnav->gsdml->DeviceIdentity->Body.InfoText.p;
    new ItemPnBase( attrnav, "Text", "LocalGsdmlAttr", 
		    pwr_eType_String, sizeof(pwr_tString80), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3079
		    p, 1,
Claes Sjofors's avatar
Claes Sjofors committed
3080 3081 3082 3083 3084
		    node, flow_eDest_IntoLast);

    p = (void *) attrnav->gsdml->DeviceFunction->Body.MainFamily;
    new ItemPnBase( attrnav, "MainFamily", "LocalGsdmlAttr", 
		    pwr_eType_String, sizeof(pwr_tString80), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3085
		    p, 1,
Claes Sjofors's avatar
Claes Sjofors committed
3086 3087 3088 3089 3090
		    node, flow_eDest_IntoLast);

    p = (void *) attrnav->gsdml->DeviceFunction->Body.ProductFamily;
    new ItemPnBase( attrnav, "ProductFamily", "LocalGsdmlAttr", 
		    pwr_eType_String, sizeof(pwr_tString80), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3091
		    p, 1,
Claes Sjofors's avatar
Claes Sjofors committed
3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142
		    node, flow_eDest_IntoLast);
    
    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

ItemPnInterfaceSubmodule::ItemPnInterfaceSubmodule( GsdmlAttrNav *attrnav, const char *item_name, 
						    gsdml_InterfaceSubmoduleItem *item_ii,
						    GsdmlSubslotData *item_subslotdata,
						    brow_tNode dest, flow_eDest dest_code) :
  ii(item_ii), subslotdata(item_subslotdata)
{
  type = attrnav_eItemType_PnInterfaceSubmodule;

  strcpy( name, item_name);
  parent = 1;

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_object, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
}

int ItemPnInterfaceSubmodule::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    char *p = (char *)ii->Body.TextId.p;
    new ItemPnBase( attrnav, "Text", "LocalGsdmlAttr", 
		  pwr_eType_String, sizeof(pwr_tString80), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3143
		  p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3144 3145 3146 3147
    
    p = ii->Body.SupportedRT_Class;
    new ItemPnBase( attrnav, "SupportedRT_Class", "LocalGsdmlAttr", 
		  pwr_eType_String, sizeof(pwr_tString80), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3148
		  p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3149 3150 3151 3152
    
    p = ii->Body.SupportedRT_Classes;
    new ItemPnBase( attrnav, "SupportedRT_Classes", "LocalGsdmlAttr", 
		  pwr_eType_String, sizeof(pwr_tString80), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3153
 		  p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3154 3155 3156 3157
    
    p = (char *) &ii->Body.IsochroneModeSupported;
    new ItemPnBase( attrnav, "IsochroneModeSupported", "LocalGsdmlAttr", 
		    pwr_eType_Boolean, sizeof(pwr_tBoolean), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3158
		    p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3159 3160 3161 3162 3163

    if ( *(pwr_tBoolean *)p) {
      p = ii->Body.IsochroneModeInRT_Classes;
      new ItemPnBase( attrnav, "IsochroneModeSupported", "LocalGsdmlAttr", 
		      pwr_eType_String, sizeof(pwr_tString80), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3164
		      p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3165 3166 3167 3168 3169
    }    

    p = ii->Body.SupportedProtocols;
    new ItemPnBase( attrnav, "SupportedProtocols", "LocalGsdmlAttr", 
		    pwr_eType_String, sizeof(pwr_tString80), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3170
		    p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3171 3172 3173 3174

    p = ii->Body.SupportedMibs;
    new ItemPnBase( attrnav, "SupportedMibs", "LocalGsdmlAttr", 
		    pwr_eType_String, sizeof(pwr_tString80), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3175
		    p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3176 3177 3178 3179

    p = (char *) &ii->Body.NetworkComponentDiagnosisSupported;
    new ItemPnBase( attrnav, "NetworkComponentDiagnosisSupported", "LocalGsdmlAttr", 
		    pwr_eType_Boolean, sizeof(pwr_tBoolean), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3180
		    p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253

    gsdml_RecordDataList *rl = ii->RecordDataList;
    if ( rl) {
      unsigned int record_index = 0;
      GsdmlDataRecord *dr;

      for ( unsigned int j = 0; j < rl->ParameterRecordDataItem.size(); j++) {

	if ( subslotdata->data_record.size() <= record_index) {
	  dr = new GsdmlDataRecord();
	  dr->record_idx = record_index;
	  subslotdata->data_record.push_back(dr);
	}
	else {
	  dr = subslotdata->data_record[record_index];
	  dr->record_idx = record_index;
	}
	
	new ItemPnParRecord( attrnav, "", rl->ParameterRecordDataItem[j], dr,
			     node, flow_eDest_IntoLast);
	record_index++;
      }
    }

    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

ItemPnPortSubmodule::ItemPnPortSubmodule( GsdmlAttrNav *attrnav, const char *item_name, 
					  gsdml_PortSubmoduleItem *item_pi,
					  GsdmlSubslotData *item_subslotdata,			    
					  brow_tNode dest, flow_eDest dest_code) :
  pi(item_pi), subslotdata(item_subslotdata)
{
  type = attrnav_eItemType_PnPortSubmodule;

  strcpy( name, item_name);
  parent = 1;

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_object, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
}

int ItemPnPortSubmodule::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    char *p = (char *)pi->Body.TextId.p;
    new ItemPnBase( attrnav, "Text", "LocalGsdmlAttr", 
		  pwr_eType_String, sizeof(pwr_tString80), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3254
		  p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3255 3256 3257 3258
    
    p = pi->Body.MAUType;
    new ItemPnBase( attrnav, "MAUType", "LocalGsdmlAttr", 
		  pwr_eType_String, sizeof(pwr_tString80), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3259
		  p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3260 3261 3262 3263 3264
    

    p = (char *) &pi->Body.MaxPortTxDelay;
    new ItemPnBase( attrnav, "MaxPortTxDelay", "LocalGsdmlAttr", 
		  pwr_eType_UInt16, sizeof(pwr_tUInt16), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3265
		  p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3266 3267 3268 3269
    
    p = (char *) &pi->Body.MaxPortRxDelay;
    new ItemPnBase( attrnav, "MaxPortRxDelay", "LocalGsdmlAttr", 
		  pwr_eType_UInt16, sizeof(pwr_tUInt16), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3270
		  p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3271 3272 3273 3274
    
    p = (char *) &pi->Body.PortDeactivationSupported;
    new ItemPnBase( attrnav, "PortDeactivationSupported", "LocalGsdmlAttr", 
		    pwr_eType_Boolean, sizeof(pwr_tBoolean), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3275
		    p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3276 3277 3278 3279

    p = pi->Body.LinkStateDiagnosisCapability;
    new ItemPnBase( attrnav, "LinkStateDiagnosisCapability", "LocalGsdmlAttr", 
		    pwr_eType_String, sizeof(pwr_tString80), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3280
		    p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3281 3282 3283 3284

    p = (char *) &pi->Body.PowerBudgetControlSupported;
    new ItemPnBase( attrnav, "PowerBudgetControlSupported", "LocalGsdmlAttr", 
		    pwr_eType_Boolean, sizeof(pwr_tBoolean), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3285
		    p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3286 3287 3288 3289

    p = (char *) &pi->Body.SupportsRingportConfig;
    new ItemPnBase( attrnav, "SupportsRingportConfig", "LocalGsdmlAttr", 
		    pwr_eType_Boolean, sizeof(pwr_tBoolean), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3290
		    p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3291 3292 3293 3294

    p = (char *) &pi->Body.IsDefaultRingport;
    new ItemPnBase( attrnav, "IsDefaultRingport", "LocalGsdmlAttr", 
		    pwr_eType_Boolean, sizeof(pwr_tBoolean), 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3295
		    p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366

    gsdml_RecordDataList *rl = pi->RecordDataList;
    if ( rl) {
      GsdmlDataRecord *dr;
      unsigned int record_index = 0;

      for ( unsigned int j = 0; j < rl->ParameterRecordDataItem.size(); j++) {
	if ( subslotdata->data_record.size() <= record_index) {
	  dr = new GsdmlDataRecord();
	  dr->record_idx = record_index;
	  subslotdata->data_record.push_back(dr);
	}
	else {
	  dr = subslotdata->data_record[record_index];
	  dr->record_idx = record_index;
	}
	
	new ItemPnParRecord( attrnav, "", rl->ParameterRecordDataItem[j], dr,
			     node, flow_eDest_IntoLast);
	record_index++;
      }
    }

    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

ItemPnModuleInfo::ItemPnModuleInfo( GsdmlAttrNav *attrnav, const char *item_name, 
			    gsdml_ModuleInfo *item_info,
			    brow_tNode dest, flow_eDest dest_code):
  info(item_info)
{
  type = attrnav_eItemType_PnModuleInfo;

  strcpy( name, item_name);
  parent = 1;

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_object, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
}

int ItemPnModuleInfo::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Attributes)
      brow_RemoveAnnotPixmap( node, 1);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    new ItemPnBase( attrnav, "Name", "LocalGsdmlAttr", pwr_eType_String, 32, 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3367
		    info->Body.Name.p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3368
    new ItemPnBase( attrnav, "Text", "LocalGsdmlAttr", pwr_eType_String, 32, 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3369
		    info->Body.InfoText.p, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3370 3371
    if ( strcmp( info->Body.VendorName, "") != 0)
      new ItemPnBase( attrnav, "VendorName", "LocalGsdmlAttr", pwr_eType_String, 32, 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3372
		      info->Body.VendorName, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3373 3374
    if ( strcmp( info->Body.OrderNumber, "") != 0)
      new ItemPnBase( attrnav, "OrderNumber", "LocalGsdmlAttr", pwr_eType_String, 32, 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3375
		      info->Body.OrderNumber, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3376 3377
    if ( strcmp( info->Body.HardwareRelease, "") != 0)
      new ItemPnBase( attrnav, "HardwareRelease", "LocalGsdmlAttr", pwr_eType_String, 32, 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3378
		      info->Body.HardwareRelease, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3379 3380
    if ( strcmp( info->Body.SoftwareRelease, "") != 0)
      new ItemPnBase( attrnav, "SoftwareRelease", "LocalGsdmlAttr", pwr_eType_String, 32, 0, 0,
Claes Sjofors's avatar
Claes Sjofors committed
3381
		      info->Body.SoftwareRelease, 1, node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392
    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

ItemPnModuleType::ItemPnModuleType( GsdmlAttrNav *attrnav, const char *item_name, 
				    int item_slot_number, int item_slot_idx,
				    brow_tNode dest, flow_eDest dest_code):
Claes Sjofors's avatar
Claes Sjofors committed
3393
  slot_number(item_slot_number), slot_idx(item_slot_idx), old_value(0), first_scan(1)
Claes Sjofors's avatar
Claes Sjofors committed
3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407
{
  type = attrnav_eItemType_PnModuleType;

  strcpy( name, item_name);

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
  brow_SetTraceAttr( node, name, "", flow_eTraceType_User);
}

3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433
static int gsdml_comp_nodes_name( const void *n1, const void *n2)
{
  ItemPnEnumValueMType *item1;
  ItemPnEnumValueMType *item2;
  brow_tObject o1 = *(brow_tObject *)n1;
  brow_tObject o2 = *(brow_tObject *)n2;

  brow_GetUserData( o1, (void **)&item1);
  brow_GetUserData( o2, (void **)&item2);

  return strcmp( item1->name, item2->name);
}

static int gsdml_comp_nodes_number( const void *n1, const void *n2)
{
  ItemPnEnumValueMType *item1;
  ItemPnEnumValueMType *item2;
  brow_tObject o1 = *(brow_tObject *)n1;
  brow_tObject o2 = *(brow_tObject *)n2;

  brow_GetUserData( o1, (void **)&item1);
  brow_GetUserData( o2, (void **)&item2);

  return strcmp( item1->number, item2->number);
}

Claes Sjofors's avatar
Claes Sjofors committed
3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455
int ItemPnModuleType::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Attributes)
      brow_RemoveAnnotPixmap( node, 1);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    int idx = 0;
3456 3457
    new ItemPnEnumValueMType( attrnav, "No", "", idx++, pwr_eType_UInt32, 
			      &attrnav->dev_data.slot_data[slot_idx]->module_enum_number, 
Claes Sjofors's avatar
Claes Sjofors committed
3458 3459 3460
			 node, flow_eDest_IntoLast);
    
    gsdml_UseableModules *um = attrnav->gsdml->ApplicationProcess->DeviceAccessPointList->DeviceAccessPointItem[attrnav->device_num-1]->UseableModules;
3461 3462 3463
    if ( !um) {
      brow_ResetNodraw( attrnav->brow->ctx);
      brow_Redraw( attrnav->brow->ctx, node_y);
Claes Sjofors's avatar
Claes Sjofors committed
3464
      return 1;
3465
    }
Claes Sjofors's avatar
Claes Sjofors committed
3466 3467 3468 3469 3470 3471 3472 3473
    for ( unsigned int i = 0; i < um->ModuleItemRef.size(); i++) {
      if ( um->ModuleItemRef[i]->Body.AllowedInSlots.list &&
	   um->ModuleItemRef[i]->Body.AllowedInSlots.list->in_list(slot_number)) {
	char mname[160] = "ModuleName";
	gsdml_ModuleItem *mi = (gsdml_ModuleItem *)um->ModuleItemRef[i]->Body.ModuleItemTarget.p;
	if ( !mi || !mi->ModuleInfo->Body.Name.p)
	  continue;
	strncpy( mname, (char *) mi->ModuleInfo->Body.Name.p, sizeof(mname));
3474 3475 3476 3477
	new ItemPnEnumValueMType( attrnav, mname, mi->ModuleInfo->Body.OrderNumber, idx, 
				  pwr_eType_UInt32, 
				  &attrnav->dev_data.slot_data[slot_idx]->module_enum_number, 
				  node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3478
      }
Claes Sjofors's avatar
Claes Sjofors committed
3479 3480 3481 3482 3483 3484 3485
      else if ( um->ModuleItemRef[i]->Body.FixedInSlots.list &&
		um->ModuleItemRef[i]->Body.FixedInSlots.list->in_list(slot_number)) {
	char mname[160] = "ModuleName";
	gsdml_ModuleItem *mi = (gsdml_ModuleItem *)um->ModuleItemRef[i]->Body.ModuleItemTarget.p;
	if ( !mi || !mi->ModuleInfo->Body.Name.p)
	  continue;
	strncpy( mname, (char *) mi->ModuleInfo->Body.Name.p, sizeof(mname));
3486 3487 3488 3489
	new ItemPnEnumValueMType( attrnav, mname, mi->ModuleInfo->Body.OrderNumber, idx, 
				  pwr_eType_UInt32, 
				  &attrnav->dev_data.slot_data[slot_idx]->module_enum_number, 
				  node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
3490 3491
      }
      idx++;
Claes Sjofors's avatar
Claes Sjofors committed
3492
    }
3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504

    // Sort
    switch ( attrnav->order_moduletype) {
    case attr_eOrderModuleType_Name:
      brow_SortChildren( attrnav->brow->ctx, node, 1, gsdml_comp_nodes_name);
      break;
    case attr_eOrderModuleType_Number:
      brow_SortChildren( attrnav->brow->ctx, node, 1, gsdml_comp_nodes_number);
      break;
    default: ;
    }

Claes Sjofors's avatar
Claes Sjofors committed
3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515
    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

int ItemPnModuleType::scan( GsdmlAttrNav *attrnav, void *p)
{
  char buf[200];
3516
  char buf2[200];
Claes Sjofors's avatar
Claes Sjofors committed
3517 3518 3519 3520 3521 3522 3523

  if ( !first_scan) {
    if ( old_value == *(int *)p)
      // No change since last time
      return 1;
  }

3524
  if ( *(int *)p == 0) {
Claes Sjofors's avatar
Claes Sjofors committed
3525
    strcpy( buf, "No");
3526 3527
    strcpy( buf2, "");
  }
Claes Sjofors's avatar
Claes Sjofors committed
3528 3529 3530 3531 3532 3533 3534
  else {
    gsdml_UseableModules *um = attrnav->gsdml->ApplicationProcess->DeviceAccessPointList->
      DeviceAccessPointItem[attrnav->device_num-1]->UseableModules;
    if ( !um)
      return 1;
    gsdml_ModuleItem *mi = (gsdml_ModuleItem *)um->
      ModuleItemRef[attrnav->dev_data.slot_data[slot_idx]->module_enum_number-1]->Body.ModuleItemTarget.p;
3535
    if ( !mi || !mi->ModuleInfo || !mi->ModuleInfo->Body.Name.p)
Claes Sjofors's avatar
Claes Sjofors committed
3536 3537
      return 1;
    strncpy( buf, (char *) mi->ModuleInfo->Body.Name.p, sizeof(buf));
3538
    strncpy( buf2, mi->ModuleInfo->Body.OrderNumber, sizeof(buf2));
Claes Sjofors's avatar
Claes Sjofors committed
3539 3540
  }
  brow_SetAnnotation( node, 1, buf, strlen(buf));
3541
  brow_SetAnnotation( node, 2, buf2, strlen(buf2));
Claes Sjofors's avatar
Claes Sjofors committed
3542 3543 3544 3545 3546 3547 3548 3549 3550 3551
  old_value = *(int *)p;

  if ( !first_scan) {
    int sts;
    brow_tObject parentnode;
    sts = brow_GetParent( attrnav->brow->ctx, node, &parentnode);
    if ( EVEN(sts)) return 1;
	
    ItemPnSlot *parentitem;
    brow_GetUserData( parentnode, (void **)&parentitem);
Claes Sjofors's avatar
Claes Sjofors committed
3552 3553

    // Note, this object is deleted here !
Claes Sjofors's avatar
Claes Sjofors committed
3554
    parentitem->close( attrnav, 0, 0);
Claes Sjofors's avatar
Claes Sjofors committed
3555 3556 3557 3558 3559

    // Remove old subslot data
    if ( parentitem->slotdata)
      parentitem->slotdata->slot_reset();

Claes Sjofors's avatar
Claes Sjofors committed
3560 3561 3562 3563 3564
    parentitem->open_children( attrnav, 0, 0);

    brow_SelectClear( attrnav->brow->ctx);
    brow_SetInverse( parentnode, 1);
    brow_SelectInsert( attrnav->brow->ctx, parentnode);
3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599
    brow_CenterObject( attrnav->brow->ctx, parentnode, 0.25);

    // Search for a default module class
    char devname[200];
    pwr_tObjName mclass;
    pwr_tCid mcid = 0;
    brow_tObject next;
    pwr_tCid *datap;

    strncpy( devname, (char *)attrnav->gsdml->ApplicationProcess->DeviceAccessPointList->
	     DeviceAccessPointItem[attrnav->device_num-1]->ModuleInfo->Body.Name.p, 
	     sizeof(devname));

    sts = attrnav->search_class( pn_cModuleClassFile, devname,  buf, mclass);
    if ( ODD(sts)) {
      for ( int i = 0; attrnav->gsdml->module_classlist[i].cid; i++) {
	if ( cdh_NoCaseStrcmp( mclass, attrnav->gsdml->module_classlist[i].name) == 0) {
	  mcid = attrnav->gsdml->module_classlist[i].cid;
	  break;
	}
      }
    }
    
    sts = brow_GetNext( attrnav->brow->ctx, parentnode, &next);
    if ( ODD(sts))
      sts = brow_GetNext( attrnav->brow->ctx, next, &next);
    if ( ODD(sts)) {
      ItemPn *item;

      brow_GetUserData( next, (void **)&item);
      if ( item->type == attrnav_eItemType_PnModuleClass) {	
	brow_GetTraceData( next, (void **)&datap);
	*datap = mcid;
      }
    }
Claes Sjofors's avatar
Claes Sjofors committed
3600
  }
Claes Sjofors's avatar
Claes Sjofors committed
3601
  else
Claes Sjofors's avatar
Claes Sjofors committed
3602 3603 3604 3605 3606
    first_scan = 0;

  return 1;
}

3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647
ItemPnSubmoduleType::ItemPnSubmoduleType( GsdmlAttrNav *attrnav, const char *item_name, 
					  int item_subslot_number, int item_slot_idx,
					  int item_subslot_idx, gsdml_UseableSubmodules *item_us,
					  brow_tNode dest, flow_eDest dest_code):
  subslot_number(item_subslot_number), slot_idx(item_slot_idx), subslot_idx(item_subslot_idx),
  us(item_us), old_value(0), first_scan(1)
{
  type = attrnav_eItemType_PnSubmoduleType;

  strcpy( name, item_name);

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
  brow_SetTraceAttr( node, name, "", flow_eTraceType_User);
}

int ItemPnSubmoduleType::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Attributes)
      brow_RemoveAnnotPixmap( node, 1);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

3648
    new ItemPnEnumValueMType( attrnav, "No", "", 0, pwr_eType_UInt32, 
3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670
			      &attrnav->dev_data.slot_data[slot_idx]->subslot_data[subslot_idx]->submodule_enum_number, 
			      node, flow_eDest_IntoLast);
    
    if ( !us)
      return 1;


    for ( unsigned int i = 0; i < us->SubmoduleItemRef.size(); i++) {
      gsdml_Valuelist *vl_allowed = new gsdml_Valuelist( us->SubmoduleItemRef[i]->Body.AllowedInSubslots.str);
      gsdml_Valuelist *vl_fixed = new gsdml_Valuelist( us->SubmoduleItemRef[i]->Body.FixedInSubslots.str);

      if ( vl_allowed->in_list(subslot_number)) {
	if ( vl_fixed->in_list(subslot_number)) {
	  delete vl_allowed;
	  delete vl_fixed;
	  continue;
	}
	char mname[160] = "ModuleName";
	gsdml_VirtualSubmoduleItem *mi = (gsdml_VirtualSubmoduleItem *)us->SubmoduleItemRef[i]->Body.SubmoduleItemTarget.p;
	if ( !mi || !mi->ModuleInfo || !mi->ModuleInfo->Body.Name.p)
	  continue;
	strncpy( mname, (char *) mi->ModuleInfo->Body.Name.p, sizeof(mname));
3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683

	// Find index in submodule list
	int idx = 0;
	for ( unsigned int j = 0; j < attrnav->gsdml->ApplicationProcess->SubmoduleList->SubmoduleItem.size(); j++) {
	  gsdml_VirtualSubmoduleItem *si = (gsdml_VirtualSubmoduleItem *)attrnav->gsdml->ApplicationProcess->SubmoduleList->SubmoduleItem[j];
	  if ( si->ModuleInfo == mi->ModuleInfo) {
	    idx = j + 1;
	    break;
	  }
	}
	if ( idx == 0)
	  continue;

3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715
	new ItemPnEnumValueMType( attrnav, mname, mi->ModuleInfo->Body.OrderNumber, idx, 
				  pwr_eType_UInt32, 
				  &attrnav->dev_data.slot_data[slot_idx]->subslot_data[subslot_idx]->submodule_enum_number, 
				  node, flow_eDest_IntoLast);
      }
      delete vl_allowed;
      delete vl_fixed;
    }

    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

int ItemPnSubmoduleType::scan( GsdmlAttrNav *attrnav, void *p)
{
  char buf[200];

  if ( !first_scan) {
    if ( old_value == *(int *)p)
      // No change since last time
      return 1;
  }

  if ( *(int *)p == 0)
    strcpy( buf, "No");
  else {
    if ( !us)
      return 1;
3716 3717

    // gsdml_VirtualSubmoduleItem *si = (gsdml_VirtualSubmoduleItem *)us->SubmoduleItemRef[attrnav->dev_data.slot_data[slot_idx]->subslot_data[subslot_idx]->submodule_enum_number-1]->Body.SubmoduleItemTarget.p;
3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756
    gsdml_VirtualSubmoduleItem *si = (gsdml_VirtualSubmoduleItem *)attrnav->gsdml->ApplicationProcess->SubmoduleList->
      SubmoduleItem[attrnav->dev_data.slot_data[slot_idx]->subslot_data[subslot_idx]->submodule_enum_number-1];
    if ( !si || !si->ModuleInfo->Body.Name.p)
      return 1;
    strncpy( buf, (char *) si->ModuleInfo->Body.Name.p, sizeof(buf));
  }
  brow_SetAnnotation( node, 1, buf, strlen(buf));
  old_value = *(int *)p;

  if ( !first_scan) {
    int sts;
    brow_tObject parentnode;
    sts = brow_GetParent( attrnav->brow->ctx, node, &parentnode);
    if ( EVEN(sts)) return 1;
	
    ItemPnSubslot *parentitem;
    brow_GetUserData( parentnode, (void **)&parentitem);

    // Note, this object is deleted here !
    parentitem->close( attrnav, 0, 0);

    // Remove old subslot data
    // if ( parentitem->slotdata)
    //  parentitem->slotdata->slot_reset();

    parentitem->open_children( attrnav, 0, 0);

    brow_SelectClear( attrnav->brow->ctx);
    brow_SetInverse( parentnode, 1);
    brow_SelectInsert( attrnav->brow->ctx, parentnode);
    brow_CenterObject( attrnav->brow->ctx, parentnode, 0.25);
    
  }
  else
    first_scan = 0;

  return 1;
}

Claes Sjofors's avatar
Claes Sjofors committed
3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779
ItemPnParRecord::ItemPnParRecord( GsdmlAttrNav *attrnav, const char *item_name, 
				  gsdml_ParameterRecordDataItem *item_par_record,
				  GsdmlDataRecord *item_datarecord, brow_tNode dest, 
				  flow_eDest dest_code) :
  par_record(item_par_record), datarecord(item_datarecord)
{
  type = attrnav_eItemType_PnParRecord;
  if ( par_record->Ref.size() == 0)
    parent = 0;
  else
    parent = 1;
  strncpy( name, (char *)par_record->Body.Name.p, sizeof(name));

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  if ( parent)
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
  else
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);

  brow_SetAnnotation( node, 0, name, strlen(name));

Claes Sjofors's avatar
Claes Sjofors committed
3780

Claes Sjofors's avatar
Claes Sjofors committed
3781 3782 3783 3784 3785
  if ( !datarecord->data) {
    datarecord->data = (unsigned char *) calloc( 1, par_record->Body.Length);
    datarecord->data_length = par_record->Body.Length;
    datarecord->index = par_record->Body.Index;
    datarecord->transfer_sequence = par_record->Body.TransferSequence;
Claes Sjofors's avatar
Claes Sjofors committed
3786 3787 3788 3789

    attrnav->gsdml->set_par_record_default( datarecord->data, par_record->Body.Length, 
    					    par_record);

Claes Sjofors's avatar
Claes Sjofors committed
3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829
    for ( unsigned int i = 0; i < par_record->Const.size(); i++) {
      void *const_data;
      int len;
      gsdml_Const *con = par_record->Const[i];

      attrnav->gsdml->ostring_to_data( (unsigned char **)&const_data, con->Body.Data, 
				       par_record->Body.Length - con->Body.ByteOffset, &len);
      if ( len > (int)(par_record->Body.Length - con->Body.ByteOffset))
	len = par_record->Body.Length - con->Body.ByteOffset;
      memcpy( (char *)datarecord->data + con->Body.ByteOffset, const_data, len);
      free( const_data);
    }
  }
}


int ItemPnParRecord::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Attributes)
      brow_RemoveAnnotPixmap( node, 1);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    for ( unsigned int i = 0; i < par_record->Ref.size(); i++) {
      gsdml_eValueDataType datatype;

Claes Sjofors's avatar
Claes Sjofors committed
3830 3831
      if ( !par_record->Ref[i]->Body.Visible)
	continue;
Claes Sjofors's avatar
Claes Sjofors committed
3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001

      attrnav->gsdml->string_to_value_datatype( par_record->Ref[i]->Body.DataType, &datatype);
      switch ( datatype) {
      case gsdml_eValueDataType_:
	break;
      case gsdml_eValueDataType_Bit:
      case gsdml_eValueDataType_BitArea:
	new ItemPnParEnum( attrnav, "", par_record->Ref[i], datatype, datarecord->data, node, 
			   flow_eDest_IntoLast);
	break;
      case gsdml_eValueDataType_Integer8:
      case gsdml_eValueDataType_Unsigned8:
	if ( strcmp( par_record->Ref[i]->Body.ValueItemTarget.ref, "") == 0)
	  new ItemPnParValue( attrnav, "", par_record->Ref[i], datatype, datarecord->data, node, 
			      flow_eDest_IntoLast);
	else
	  new ItemPnParEnum( attrnav, "", par_record->Ref[i], datatype, datarecord->data, node, 
			     flow_eDest_IntoLast);
	break;
      default:
	new ItemPnParValue( attrnav, "", par_record->Ref[i], datatype, datarecord->data, node, 
			    flow_eDest_IntoLast);
      }
    }
    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

ItemPnParValue::ItemPnParValue( GsdmlAttrNav *attrnav, const char *item_name, 
				gsdml_Ref *item_value_ref, gsdml_eValueDataType item_datatype, 
				unsigned char *item_data, brow_tNode dest, flow_eDest dest_code) :
  value_ref(item_value_ref), datatype( item_datatype), data(item_data), first_scan(1),
  noedit(1)
{
  type = attrnav_eItemType_PnParValue;
  strncpy( name, (char *)value_ref->Body.TextId.p, sizeof(name));
  byte_offset = value_ref->Body.ByteOffset;
  noedit = !value_ref->Body.Changeable;

  switch ( datatype) {
  case gsdml_eValueDataType_Integer8:
  case gsdml_eValueDataType_Unsigned8:
    size = 1;
    break;
  case gsdml_eValueDataType_Integer16:
  case gsdml_eValueDataType_Unsigned16:
    size = 2;
    break;
  case gsdml_eValueDataType_Integer32:
  case gsdml_eValueDataType_Unsigned32:
  case gsdml_eValueDataType_Float32:
    size = 4;
    break;
  case gsdml_eValueDataType_Integer64:
  case gsdml_eValueDataType_Unsigned64:
  case gsdml_eValueDataType_Float64:
    size = 8;
    break;
  case gsdml_eValueDataType_VisibleString:
  case gsdml_eValueDataType_OctetString:
    size = value_ref->Body.Length;
    break;
  case gsdml_eValueDataType_Date:
  case gsdml_eValueDataType_TimeOfDayWithDate:
  case gsdml_eValueDataType_TimeOfDayWithoutDate:
  case gsdml_eValueDataType_TimeDiffWithDate:
  case gsdml_eValueDataType_TimeDiffWithoutDate:
  case gsdml_eValueDataType_NetworkTime:
  case gsdml_eValueDataType_NetworkTimeDiff:
    size = 8;
    break;
  default:
    size = 0;
  }
  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attr);

  brow_SetAnnotation( node, 0, name, strlen(name));
  brow_SetTraceAttr( node, name, "", flow_eTraceType_User);
}

int ItemPnParValue::scan( GsdmlAttrNav *attrnav, void *p)
{
  if ( !first_scan) {
    if ( memcmp( &data[byte_offset], old_value, size) == 0)
      // No change since last time
      return 1;
  }
  else
    first_scan = 0;
  
  char buf[80];
  attrnav->gsdml->datavalue_to_string( datatype, &data[byte_offset], size, buf, sizeof(buf));
  brow_SetAnnotation( node, 1, buf, strlen(buf));

  memcpy( old_value, &data[byte_offset], size);
  return 1;
}

void ItemPnParValue::value_changed( GsdmlAttrNav *attrnav, char *value_str)
{
  int sts;

  unsigned char *buf = (unsigned char *)calloc( 1, size);

  sts = attrnav->gsdml->string_to_datavalue( datatype, buf,
					     size, value_str);
  if ( sts == PB__NYI) {
    attrnav->message('E', "Not yet implemented");
    return;
  }
  else if ( EVEN(sts)) {
    attrnav->message('E', "Input syntax error");
    return;
  }  

  // Check allowed values
  switch ( datatype) {
  case gsdml_eValueDataType_Integer8: {
    char val = *(char *)buf;
    if ( strcmp( value_ref->Body.AllowedValues, "") != 0) {
      gsdml_SValuelist *vl = new gsdml_SValuelist( value_ref->Body.AllowedValues);
      if ( ODD(vl->sts())) {
	
	if ( !vl->in_list( val)) {
	  attrnav->message('E', "Value not allowed");
	  return;
	}
      }
      delete vl;
    }
    break;
  }
  case gsdml_eValueDataType_Integer16: {
    short val = *(short *)buf;
    if ( strcmp( value_ref->Body.AllowedValues, "") != 0) {
      gsdml_SValuelist *vl = new gsdml_SValuelist( value_ref->Body.AllowedValues);
      if ( ODD(vl->sts())) {
	
	if ( !vl->in_list( val)) {
	  attrnav->message('E', "Value not allowed");
	  return;
	}
      }
      delete vl;
    }
    break;
  }
  case gsdml_eValueDataType_Integer32: {
    int val = *(int *)buf;
    if ( strcmp( value_ref->Body.AllowedValues, "") != 0) {
      gsdml_SValuelist *vl = new gsdml_SValuelist( value_ref->Body.AllowedValues);
      if ( ODD(vl->sts())) {
	
	if ( !vl->in_list( val)) {
	  attrnav->message('E', "Value not allowed");
	  return;
	}
      }
      delete vl;
    }
    break;
  }
  case gsdml_eValueDataType_Integer64: {
Claes Sjofors's avatar
Claes Sjofors committed
4002
    pwr_tInt64 val = *(pwr_tInt64 *)buf;
Claes Sjofors's avatar
Claes Sjofors committed
4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061
    if ( strcmp( value_ref->Body.AllowedValues, "") != 0) {
      gsdml_SValuelist *vl = new gsdml_SValuelist( value_ref->Body.AllowedValues);
      if ( ODD(vl->sts())) {
	
	if ( !vl->in_list( val)) {
	  attrnav->message('E', "Value not allowed");
	  return;
	}
      }
      delete vl;
    }
    break;
  }
  case gsdml_eValueDataType_Unsigned8: {
    unsigned char val = *(unsigned char *)buf;
    if ( strcmp( value_ref->Body.AllowedValues, "") != 0) {
      gsdml_Valuelist *vl = new gsdml_Valuelist( value_ref->Body.AllowedValues);
      if ( ODD(vl->sts())) {
	
	if ( !vl->in_list( val)) {
	  attrnav->message('E', "Value not allowed");
	  return;
	}
      }
      delete vl;
    }
    break;
  }
  case gsdml_eValueDataType_Unsigned16: {
    unsigned short val = *(unsigned short *)buf;
    if ( strcmp( value_ref->Body.AllowedValues, "") != 0) {
      gsdml_Valuelist *vl = new gsdml_Valuelist( value_ref->Body.AllowedValues);
      if ( ODD(vl->sts())) {
	
	if ( !vl->in_list( val)) {
	  attrnav->message('E', "Value not allowed");
	  return;
	}
      }
      delete vl;
    }
    break;
  }
  case gsdml_eValueDataType_Unsigned32: {
    unsigned int val = *(unsigned int *)buf;
    if ( strcmp( value_ref->Body.AllowedValues, "") != 0) {
      gsdml_Valuelist *vl = new gsdml_Valuelist( value_ref->Body.AllowedValues);
      if ( ODD(vl->sts())) {
	
	if ( !vl->in_list( val)) {
	  attrnav->message('E', "Value not allowed");
	  return;
	}
      }
      delete vl;
    }
    break;
  }
  case gsdml_eValueDataType_Unsigned64: {
Claes Sjofors's avatar
Claes Sjofors committed
4062
    pwr_tUInt64 val = *(pwr_tUInt64 *)buf;
Claes Sjofors's avatar
Claes Sjofors committed
4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111
    if ( strcmp( value_ref->Body.AllowedValues, "") != 0) {
      gsdml_Valuelist *vl = new gsdml_Valuelist( value_ref->Body.AllowedValues);
      if ( ODD(vl->sts())) {
	
	if ( !vl->in_list( val)) {
	  attrnav->message('E', "Value not allowed");
	  return;
	}
      }
      delete vl;
    }
    break;
  }
  case gsdml_eValueDataType_Float32: {
    float val = *(float *)buf;
    if ( strcmp( value_ref->Body.AllowedValues, "") != 0) {
      gsdml_FValuelist *vl = new gsdml_FValuelist( value_ref->Body.AllowedValues);
      if ( ODD(vl->sts())) {
	
	if ( !vl->in_list( val)) {
	  attrnav->message('E', "Value not allowed");
	  return;
	}
      }
      delete vl;
    }
    break;
  }
  case gsdml_eValueDataType_Float64: {
    double val = *(double *)buf;
    if ( strcmp( value_ref->Body.AllowedValues, "") != 0) {
      gsdml_FValuelist *vl = new gsdml_FValuelist( value_ref->Body.AllowedValues);
      if ( ODD(vl->sts())) {
	
	if ( !vl->in_list( val)) {
	  attrnav->message('E', "Value not allowed");
	  return;
	}
      }
      delete vl;
    }
    break;
  }
  default: ;
  }

  memcpy( &data[byte_offset], buf, size);

  free( buf);
Claes Sjofors's avatar
Claes Sjofors committed
4112
  attrnav->set_modified(1);
Claes Sjofors's avatar
Claes Sjofors committed
4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144
}

ItemPnParEnum::ItemPnParEnum( GsdmlAttrNav *attrnav, const char *item_name, 
			      gsdml_Ref *item_value_ref, gsdml_eValueDataType item_datatype, 
			      unsigned char *item_data, brow_tNode dest, flow_eDest dest_code) :
  value_ref(item_value_ref), datatype(item_datatype), data(item_data), mask(0), old_value(0),
  first_scan(1), noedit(1)
{
  type = attrnav_eItemType_PnParEnum;
  strncpy( name, (char *)value_ref->Body.TextId.p, sizeof(name));
  byte_offset = value_ref->Body.ByteOffset;
  bit_offset = value_ref->Body.BitOffset;
  switch ( datatype) {
  case gsdml_eValueDataType_Bit:
    bit_length = 1;
    break;
  case gsdml_eValueDataType_BitArea:
    bit_length = value_ref->Body.BitLength;
    break;
  case gsdml_eValueDataType_Integer8:
  case gsdml_eValueDataType_Unsigned8:
    bit_length = 8;
    break;
  default: ;
  }
  for ( unsigned int i = 0; i < bit_length; i++)
    mask |= (mask << 1) | 1; 
  mask <<= bit_offset;
  noedit = !value_ref->Body.Changeable;

  // Get the values and corresponding texts
  gsdml_ValueItem *vi = (gsdml_ValueItem *)value_ref->Body.ValueItemTarget.p;
4145

Claes Sjofors's avatar
Claes Sjofors committed
4146 4147 4148 4149 4150 4151 4152 4153
  gsdml_Valuelist *allowed_values = 0; 
  if ( strcmp( value_ref->Body.AllowedValues, "") != 0)
    allowed_values = new gsdml_Valuelist( value_ref->Body.AllowedValues);

  if ( vi && vi->Assignments) {
    for ( unsigned int i = 0; i < vi->Assignments->Assign.size(); i++) {
      ParEnumValue eval;
      int num;
4154

Claes Sjofors's avatar
Claes Sjofors committed
4155
      num = sscanf( vi->Assignments->Assign[i]->Body.Content, "%u", &eval.value);
4156

Claes Sjofors's avatar
Claes Sjofors committed
4157 4158
      if ( num != 1)
	continue;
4159

Claes Sjofors's avatar
Claes Sjofors committed
4160 4161 4162 4163 4164 4165 4166 4167 4168
      if ( allowed_values && !allowed_values->in_list( eval.value))
	continue;

      strncpy( eval.text, (char *)vi->Assignments->Assign[i]->Body.TextId.p, sizeof(eval.text));
      eval.value <<= bit_offset;

      values.push_back( eval);
    }
  }
4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182
  else if (datatype == gsdml_eValueDataType_Bit)
  {
    ParEnumValue eval;

    eval.value = 1;
    strncpy( eval.text, "On", sizeof(eval.text));
    eval.value <<= bit_offset;
    values.push_back( eval);

    eval.value = 0;
    strncpy( eval.text, "Off", sizeof(eval.text));
    values.push_back( eval);
  }

Claes Sjofors's avatar
Claes Sjofors committed
4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237
  if ( allowed_values)
    delete allowed_values;

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);
  brow_SetAnnotation( node, 0, name, strlen(name));
  brow_SetTraceAttr( node, name, "", flow_eTraceType_User);
}


int ItemPnParEnum::scan( GsdmlAttrNav *attrnav, void *p)
{
  if ( !first_scan) {
    if ( (*(unsigned int *)&data[byte_offset] & mask) == old_value)
      // No change since last time
      return 1;
  }
  else
    first_scan = 0;
  
  unsigned int value = *(unsigned int *)&data[byte_offset] & mask;
  for ( unsigned int i = 0; i < values.size(); i++) {
    if ( values[i].value == value) {
      brow_SetAnnotation( node, 1, values[i].text, strlen(values[i].text));
      break;
    }
  }

  old_value = value;
  return 1;
}

int ItemPnParEnum::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Attributes)
      brow_RemoveAnnotPixmap( node, 1);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

4238 4239 4240 4241
    for ( unsigned int i = 0; i < values.size(); i++) {
      new ItemPnParEnumBit( attrnav, values[i].text, datatype, data,
                            byte_offset, values[i].value, mask, noedit,
                            node, flow_eDest_IntoLast);
Claes Sjofors's avatar
Claes Sjofors committed
4242
    }
4243

Claes Sjofors's avatar
Claes Sjofors committed
4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390
    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

ItemPnParEnumBit::ItemPnParEnumBit( GsdmlAttrNav *attrnav, const char *item_name, 
				    gsdml_eValueDataType item_datatype, 
				    unsigned char *item_data, unsigned int item_byte_offset, 
				    unsigned int item_value, unsigned int item_mask,
				    int item_noedit, brow_tNode dest, flow_eDest dest_code) :
  datatype(item_datatype), data(item_data),
  byte_offset(item_byte_offset), value(item_value), mask(item_mask), first_scan(1),
  old_value(0), noedit(item_noedit)
{
  type = attrnav_eItemType_PnParEnumBit;
  strncpy( name, (char *)item_name, sizeof(name));

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_enum, 
		   dest, dest_code, (void *) this, 1, &node);
  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attr);

  brow_SetAnnotation( node, 0, name, strlen(name));
  brow_SetTraceAttr( node, name, "", flow_eTraceType_User);
}

int ItemPnParEnumBit::scan( GsdmlAttrNav *attrnav, void *p)
{
  if ( !first_scan) {
    if ( (*(unsigned int *)&data[byte_offset] & mask) == old_value)
      // No change since last time
      return 1;
  }
  else
    first_scan = 0;
  
  unsigned int current_value = *(unsigned int *)&data[byte_offset] & mask;
  if ( current_value == value)
    brow_SetRadiobutton( node, 0, 1);
  else
    brow_SetRadiobutton( node, 0, 0);

  old_value = current_value;
  return 1;
}

void ItemPnParEnumBit::update( GsdmlAttrNav *attrnav)
{
  if ( noedit) {
    attrnav->message( 'E', "Parameter is not changeable");
    return;
  }  
  *(unsigned int *)&data[byte_offset] &= ~mask;
  *(unsigned int *)&data[byte_offset] |= value;
  attrnav->set_modified( 1);	    
}

ItemPnModuleClass::ItemPnModuleClass( GsdmlAttrNav *attrnav, const char *item_name, 
				    GsdmlSlotData *item_slotdata,
				    brow_tNode dest, flow_eDest dest_code):
  slotdata(item_slotdata), first_scan(1)
{
  type = attrnav_eItemType_PnModuleClass;

  strcpy( name, item_name);

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
  brow_SetTraceAttr( node, name, "", flow_eTraceType_User);
}

int ItemPnModuleClass::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Attributes)
      brow_RemoveAnnotPixmap( node, 1);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    for ( int i = 0; attrnav->gsdml->module_classlist[i].cid; i++) {
      new ItemPnEnumValue( attrnav, attrnav->gsdml->module_classlist[i].name, 
			   attrnav->gsdml->module_classlist[i].cid, pwr_eType_UInt32, 
			   &slotdata->module_class, node, flow_eDest_IntoLast);
    }

    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

int ItemPnModuleClass::scan( GsdmlAttrNav *attrnav, void *p)
{
  char buf[200];

  if ( !first_scan) {
    if ( old_value == *(int *)p)
      // No change since last time
      return 1;
  }

  if ( *(int *)p == 0)
    strcpy( buf, "No");
  else {
    int found = 0;

    int i;
    for ( i = 0; attrnav->gsdml->module_classlist[i].cid; i++) {
      if ( attrnav->gsdml->module_classlist[i].cid == *(pwr_tCid *)p) {
	found = 1;
	break;
      }
    }
    if ( !found)
      strcpy( buf, "Unknown class");
    else
      strcpy( buf, attrnav->gsdml->module_classlist[i].name);
  }
  brow_SetAnnotation( node, 1, buf, strlen(buf));
  old_value = *(int *)p;      

  if ( first_scan)
    first_scan = 0;
  return 1;
}

Claes Sjofors's avatar
Claes Sjofors committed
4391 4392
ItemPnIOData::ItemPnIOData( GsdmlAttrNav *attrnav, const char *item_name, 
			    gsdml_IOData *item_iodata,
4393
			    int item_subslot_idx, int item_slot_idx,
Claes Sjofors's avatar
Claes Sjofors committed
4394
			    brow_tNode dest, flow_eDest dest_code) :
4395
  iodata(item_iodata), subslot_idx(item_subslot_idx), slot_idx(item_slot_idx)
Claes Sjofors's avatar
Claes Sjofors committed
4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446
{
  type = attrnav_eItemType_PnIOData;

  strcpy( name, item_name);

  if ( iodata->Input || iodata->Output)
    parent = 1;

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  if ( parent)
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
  else
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
}

int ItemPnIOData::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children) {
      if ( parent)
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
      else
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);
    }
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    if ( iodata->Input) {
      new ItemPnInput( attrnav, "Input", iodata->Input,
		       node, flow_eDest_IntoLast);
    }
    if ( iodata->Output) {
      new ItemPnOutput( attrnav, "Output", iodata->Output,
		       node, flow_eDest_IntoLast);
    }

4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461
    GsdmlSubslotData *ssd = attrnav->dev_data.slot_data[slot_idx]->subslot_data[subslot_idx];
    if ( iodata->Input) {

      void *p = (void *) &ssd->io_input_length;
      new ItemPnBase( attrnav, "InputLength", "LocalGsdmlAttr", 
		      pwr_eType_UInt32, sizeof(ssd->io_input_length), 0, 0,
		      p, 0, node, flow_eDest_IntoLast);
    }
    if ( iodata->Output) {
      void *p = (void *) &ssd->io_output_length;
      new ItemPnBase( attrnav, "OutputLength", "LocalGsdmlAttr", 
		      pwr_eType_UInt32, sizeof(ssd->io_output_length), 0, 0,
		      p, 0, node, flow_eDest_IntoLast);
    }

Claes Sjofors's avatar
Claes Sjofors committed
4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720
    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

ItemPnInput::ItemPnInput( GsdmlAttrNav *attrnav, const char *item_name, 
			  gsdml_Input *item_input,
			  brow_tNode dest, flow_eDest dest_code) :
  input(item_input)
{
  type = attrnav_eItemType_PnInput;

  strcpy( name, item_name);

  if ( input->DataItem.size())
    parent = 1;

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  if ( parent)
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
  else
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
}

int ItemPnInput::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children) {
      if ( parent)
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
      else
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);
    }
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    for ( unsigned int i = 0; i < input->DataItem.size(); i++) {
      new ItemPnDataItem( attrnav, (char *)input->DataItem[i]->Body.TextId.p, input->DataItem[i],
			  node, flow_eDest_IntoLast);      
    }

    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

ItemPnOutput::ItemPnOutput( GsdmlAttrNav *attrnav, const char *item_name, 
			  gsdml_Output *item_output,
			  brow_tNode dest, flow_eDest dest_code) :
  output(item_output)
{
  type = attrnav_eItemType_PnOutput;

  strcpy( name, item_name);

  if ( output->DataItem.size())
    parent = 1;

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  if ( parent)
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
  else
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
}

int ItemPnOutput::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children) {
      if ( parent)
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
      else
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);
    }
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    for ( unsigned int i = 0; i < output->DataItem.size(); i++) {
      new ItemPnDataItem( attrnav, (char *)output->DataItem[i]->Body.TextId.p, output->DataItem[i],
			  node, flow_eDest_IntoLast);      
    }

    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}


ItemPnDataItem::ItemPnDataItem( GsdmlAttrNav *attrnav, const char *item_name, 
			  gsdml_DataItem *item_dataitem,
			  brow_tNode dest, flow_eDest dest_code) :
  dataitem(item_dataitem)
{
  type = attrnav_eItemType_PnDataItem;

  strcpy( name, item_name);

  if ( dataitem->BitDataItem.size())
    parent = 1;

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  if ( parent)
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
  else
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
  brow_SetAnnotation( node, 1, dataitem->Body.DataType, strlen(dataitem->Body.DataType));
}

int ItemPnDataItem::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children) {
      if ( parent)
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
      else
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);
    }
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    void *p;
    if ( strcmp( dataitem->Body.DataType, "OctetString") == 0 ||
	 strcmp( dataitem->Body.DataType, "VisibleString") == 0) {
      p = (void *) &dataitem->Body.Length;
      new ItemPnBase( attrnav, "Length", "LocalGsdmlAttr", 
		      pwr_eType_UInt16, sizeof(dataitem->Body.Length), 0, 0,
		      p, 1, node, flow_eDest_IntoLast);
    }
    p = (void *) dataitem->Body.DataType;
    new ItemPnBase( attrnav, "Type", "LocalGsdmlAttr", 
		    pwr_eType_String, sizeof(dataitem->Body.DataType), 0, 0,
		    p, 1, node, flow_eDest_IntoLast);

    p = (void *) &dataitem->Body.UseAsBits;
    new ItemPnBase( attrnav, "UseAsBits", "LocalGsdmlAttr", 
		    pwr_eType_Boolean, sizeof(dataitem->Body.UseAsBits), 0, 0,
		    p, 1, node, flow_eDest_IntoLast);

    for ( unsigned int i = 0; i < dataitem->BitDataItem.size(); i++) {
      new ItemPnBitDataItem( attrnav, (char *)dataitem->BitDataItem[i]->Body.TextId.p, 
			  dataitem->BitDataItem[i], node, flow_eDest_IntoLast);      
    }
    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

ItemPnBitDataItem::ItemPnBitDataItem( GsdmlAttrNav *attrnav, const char *item_name, 
			  gsdml_BitDataItem *item_bitdataitem,
			  brow_tNode dest, flow_eDest dest_code) :
  bitdataitem(item_bitdataitem)
{
  type = attrnav_eItemType_PnBitDataItem;

  strcpy( name, item_name);

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
}

int ItemPnBitDataItem::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children) {
      if ( parent)
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_map);
      else
	brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_leaf);
    }
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    brow_SetNodraw( attrnav->brow->ctx);

    void *p = (void *) &bitdataitem->Body.BitOffset;
    new ItemPnBase( attrnav, "BitOffset", "LocalGsdmlAttr", 
		    pwr_eType_UInt8, sizeof(bitdataitem->Body.BitOffset), 0, 0,
		    p, 1, node, flow_eDest_IntoLast);

    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}



Claes Sjofors's avatar
Claes Sjofors committed
4721 4722 4723 4724 4725 4726
ItemPnEnumByteOrder::ItemPnEnumByteOrder( GsdmlAttrNav *attrnav, const char *item_name, 
					  const char *attr,  int attr_type, int attr_size, 
					  void *attr_value_p, int attr_noedit,
					  brow_tNode dest, flow_eDest dest_code) :
  ItemPnBase( attrnav, item_name, attr, attr_type, attr_size, 0,
	      0, attr_value_p, attr_noedit,
Claes Sjofors's avatar
Claes Sjofors committed
4727
	      dest, dest_code)
Claes Sjofors's avatar
Claes Sjofors committed
4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789
{
  type = attrnav_eItemType_PnEnumByteOrder;
  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);
}

int ItemPnEnumByteOrder::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Attributes)
      brow_RemoveAnnotPixmap( node, 1);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else if ( !noedit) {
    int				found;

    found = 0;
    brow_SetNodraw( attrnav->brow->ctx);
    new ItemPnEnumValue( attrnav, "LittleEndian", 0, pwr_eType_UInt32, 
		this->value_p, node, flow_eDest_IntoLast);
    new ItemPnEnumValue( attrnav, "BigEndian", 1, pwr_eType_UInt32, 
		this->value_p, node, flow_eDest_IntoLast);
    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

int ItemPnEnumByteOrder::scan( GsdmlAttrNav *attrnav, void *p)
{
  char buf[80];

  if ( !first_scan) {
    if ( old_value == *(int *)p)
      // No change since last time
      return 1;
  }
  else
    first_scan = 0;
  
  if ( *(int *)p == 0)
    strcpy( buf, "LittleEndian");
  else
    strcpy( buf, "BigEndian");
  
  brow_SetAnnotation( node, 1, buf, strlen(buf));
  old_value = *(int *)p;

  return 1;
}
Claes Sjofors's avatar
Claes Sjofors committed
4790 4791 4792 4793 4794 4795 4796 4797 4798

ItemPnEnumTimeRatio::ItemPnEnumTimeRatio( GsdmlAttrNav *attrnav, const char *item_name, 
					  gsdml_InterfaceSubmoduleItem *item_interfacesubmodule,
					  void *attr_value_p, brow_tNode dest, flow_eDest dest_code) :
  interfacesubmodule(item_interfacesubmodule), value_p(attr_value_p), first_scan(1), old_value(0)
{
  type = attrnav_eItemType_PnEnumTimeRatio;
  strcpy( name, item_name);

4799
  if ( interfacesubmodule && interfacesubmodule->ApplicationRelations &&
4800 4801 4802 4803 4804 4805 4806 4807
       interfacesubmodule->ApplicationRelations->TimingProperties &&
       strcmp( interfacesubmodule->ApplicationRelations->TimingProperties->Body.ReductionRatio.str,
	       "") != 0)
    strncpy( valuelist_str, interfacesubmodule->ApplicationRelations->TimingProperties->Body.ReductionRatio.str,
	     sizeof(valuelist_str));
  else
    strcpy( valuelist_str, "1 2 4 8 16 32 64 128 256 512");

Claes Sjofors's avatar
Claes Sjofors committed
4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841
  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
  brow_SetTraceAttr( node, name, "", flow_eTraceType_User);
}

int ItemPnEnumTimeRatio::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Attributes)
      brow_RemoveAnnotPixmap( node, 1);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    int				found;

    found = 0;

    brow_SetNodraw( attrnav->brow->ctx);

4842
    gsdml_Valuelist *vl = new gsdml_Valuelist( valuelist_str);
Claes Sjofors's avatar
Claes Sjofors committed
4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873
    gsdml_ValuelistIterator iter( vl);

    for ( unsigned int j = iter.begin(); j != iter.end(); j = iter.next()) {
      char enumtext[20];
      sprintf( enumtext, "%d", j);
		
      new ItemPnEnumValue( attrnav, enumtext, j, pwr_eType_UInt32, 
			   this->value_p, node, flow_eDest_IntoLast);
    }
    delete vl;

    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

int ItemPnEnumTimeRatio::scan( GsdmlAttrNav *attrnav, void *p)
{
  char buf[80];

  if ( !first_scan) {
    if ( old_value == *(int *)p)
      // No change since last time
      return 1;
  }
  else {
    if ( *(int *)p == 0) {
      // Set initial value
4874 4875
      gsdml_Valuelist *vl = new gsdml_Valuelist( valuelist_str);
      gsdml_ValuelistIterator iter( vl);
Claes Sjofors's avatar
Claes Sjofors committed
4876
	
4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899
      *(int *)p = iter.begin();
      delete vl;
    }
    first_scan = 0;
  }
  
  sprintf( buf, "%d", *(int *)p);
  
  brow_SetAnnotation( node, 1, buf, strlen(buf));
  old_value = *(int *)p;

  return 1;
}


ItemPnEnumSendClock::ItemPnEnumSendClock( GsdmlAttrNav *attrnav, const char *item_name, 
					  gsdml_InterfaceSubmoduleItem *item_interfacesubmodule,
					  void *attr_value_p, brow_tNode dest, flow_eDest dest_code) :
  interfacesubmodule(item_interfacesubmodule), value_p(attr_value_p), first_scan(1), old_value(0)
{
  type = attrnav_eItemType_PnEnumSendClock;
  strcpy( name, item_name);

4900
  if ( interfacesubmodule && interfacesubmodule->ApplicationRelations &&
4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979
       interfacesubmodule->ApplicationRelations->TimingProperties &&
       strcmp( interfacesubmodule->ApplicationRelations->TimingProperties->Body.SendClock.str,
	       "") != 0)
    strncpy( valuelist_str, interfacesubmodule->ApplicationRelations->TimingProperties->Body.SendClock.str,
	     sizeof( valuelist_str));
  else
    strcpy( valuelist_str, "1 2 4 8 16 32 64 128");

  brow_CreateNode( attrnav->brow->ctx, item_name, attrnav->brow->nc_attr, 
		   dest, dest_code, (void *) this, 1, &node);

  brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);

  brow_SetAnnotation( node, 0, item_name, strlen(item_name));
  brow_SetTraceAttr( node, name, "", flow_eTraceType_User);
}

int ItemPnEnumSendClock::open_children( GsdmlAttrNav *attrnav, double x, double y)
{
  double	node_x, node_y;

  brow_GetNodePosition( node, &node_x, &node_y);

  if ( brow_IsOpen( node)) {
    // Close
    brow_SetNodraw( attrnav->brow->ctx);
    brow_CloseNode( attrnav->brow->ctx, node);
    if ( brow_IsOpen( node) & attrnav_mOpen_Attributes)
      brow_RemoveAnnotPixmap( node, 1);
    if ( brow_IsOpen( node) & attrnav_mOpen_Children)
      brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrenum);
    brow_ResetOpen( node, attrnav_mOpen_All);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  else {
    int				found;

    found = 0;

    brow_SetNodraw( attrnav->brow->ctx);

    gsdml_Valuelist *vl = new gsdml_Valuelist( valuelist_str);
    gsdml_ValuelistIterator iter( vl);

    for ( unsigned int j = iter.begin(); j != iter.end(); j = iter.next()) {
      char enumtext[20];
      sprintf( enumtext, "%d", j);
		
      new ItemPnEnumValue( attrnav, enumtext, j, pwr_eType_UInt32, 
			   this->value_p, node, flow_eDest_IntoLast);
    }
    delete vl;

    brow_SetOpen( node, attrnav_mOpen_Children);
    brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_openmap);
    brow_ResetNodraw( attrnav->brow->ctx);
    brow_Redraw( attrnav->brow->ctx, node_y);
  }
  return 1;
}

int ItemPnEnumSendClock::scan( GsdmlAttrNav *attrnav, void *p)
{
  char buf[80];

  if ( !first_scan) {
    if ( old_value == *(int *)p)
      // No change since last time
      return 1;
  }
  else {
    if ( *(int *)p == 0) {
      // Set initial value
      gsdml_Valuelist *vl = new gsdml_Valuelist( valuelist_str);
      gsdml_ValuelistIterator iter( vl);
      
      *(int *)p = iter.begin();
      delete vl;
Claes Sjofors's avatar
Claes Sjofors committed
4980 4981 4982 4983 4984 4985 4986 4987 4988 4989
    }
    first_scan = 0;
  }
  
  sprintf( buf, "%d", *(int *)p);
  
  brow_SetAnnotation( node, 1, buf, strlen(buf));
  old_value = *(int *)p;

  return 1;
4990
}