void double_slide_holder:: set_values ( value_type val , value_type min , value_type max , value_type ss // -1 means use existing value , value_type ps // -1 means use existing value ) { d_assert( ! is_setting( )); // We generate our own signals instead of relying on the inner object. while_setting_value_wrapper_type wrapper( this, false); d_assert( is_setting( )); // Remember the old values. value_type const old_val = get_value( ); value_type const old_min = get_min_value( ); value_type const old_max = get_max_value( ); value_type const old_ss = get_single_step( ); value_type const old_ps = get_page_step( ); // Must do this before the conversions that follow. setup_conversions( min, max); // Send the values to the inner holder. p_inner_holder_-> set_values ( convert_outer_to_inner( val) , convert_outer_to_inner( min) , convert_outer_to_inner( max) , convert_outer_to_inner_distance( ss) , convert_outer_to_inner_distance( ps) ); // Find the new values. These may be slightly different due to rounding etc. value_type const new_val = get_value( ); value_type const new_min = get_min_value( ); value_type const new_max = get_max_value( ); value_type const new_ss = get_single_step( ); value_type const new_ps = get_page_step( ); // Emit the value signals. if ( (new_ss != old_ss) || (new_ps != old_ps) ) { emit has_changed__steps( new_ss, new_ps); wrapper.request_signal( ); } if ( (new_min != old_min) || (new_max != old_max) ) { emit has_changed__range( new_min, new_max); wrapper.request_signal( ); } if ( new_val != old_val ) { emit has_changed( new_val); wrapper.request_signal( ); } // The wrapper dtor will signal has_changed( ) if appropriate. wrapper.done_with_no_throws( ); }
/* ctor */ double_slide_holder:: double_slide_holder ( QObject * p_parent , value_type outer_init // = 0.0 , value_type outer_lo // = -1.0 , value_type outer_hi // = +1.0 ) : holder_base_type( p_parent) , p_inner_holder_ ( 0) , outer_lo_ ( 0) , inner_to_outer_ ( 0) , outer_to_inner_ ( 0) { setup_conversions( outer_lo, outer_hi); // Now that conversions are set up, create the inner holder. // Should we use the global lo/hi limits, or the calculated limits? We'll use the // calculated limits for now. p_inner_holder_ = new inner_holder_type ( this , convert_outer_to_inner( outer_init) , convert_outer_to_inner( outer_lo) , convert_outer_to_inner( outer_hi) ); d_assert( p_inner_holder_); // Relay all the signals from the inner holder. d_verify( connect( p_inner_holder_, SIGNAL( has_changed( )), this, SLOT( intercept__has_changed( )) )); d_verify( connect( p_inner_holder_, SIGNAL( has_changed( int)), this, SLOT( intercept__has_changed( int)) )); d_verify( connect( p_inner_holder_, SIGNAL( has_changed__range( int, int)), this, SLOT( intercept__has_changed__range( int, int)) )); d_verify( connect( p_inner_holder_, SIGNAL( has_changed__steps( int, int)), this, SLOT( intercept__has_changed__steps( int, int)) )); // Should always be true when outside class methods. d_assert( is_valid( )); }
int zvpinit( void *parb /* Pointer to start of the par block */ ) { int i, status; struct VARIABLE *current_parm; /* Pointer to current parameter */ int line; /* line increment in file I/O */ int nl; /* Number of lines in image */ int ns; /* Number of bytes per line */ int count; /* TCL count of parms */ int unit; /* File unit number */ int oldtype; /* TRUE if old fixed len recs (PARAM) */ int oldhead; /* TRUE if old header (PARM or PARAM) */ int eof; /* TRUE if at end of file */ char filename[MAX_FILE_NAME_SIZE+1]; /* Name of param file */ char stype[10]; /* File type as string */ char *data_ptr; /* pointer to value data */ char **str_ptr; /* pointer to data_ptr for str. */ char *buff = NULL; /* ptr to line buf (oldtype) */ char *buf = NULL; /* ptr to data (inside buff for old) */ char tae_type; /* p_type made to agree with v_type */ char msgbuf[80]; /* Message buffer */ struct OLD_PARM_LINE old_header; struct PARM_LINE header; char parm_name[STRINGSIZ+1]; /* Check for the existence of a parameter data set */ zvp("PARMS",filename,&count); if (count == 0) return SUCCESS; /* return if no pds */ zvunit(&unit,"XX",1,"U_NAME",filename, NULL); /* Open it */ zvopen(unit,"OPEN_ACT","SA","IO_ACT","SA","LAB_ACT","SA", NULL); zlget(unit,"system","type",stype, NULL); if (EQUAL(stype, "PARMS")) { /* new format, new header */ oldtype = FALSE; oldhead = FALSE; } else if (EQUAL(stype, "PARM")) { /* new format, old header */ oldtype = FALSE; oldhead = TRUE; } else if (EQUAL(stype, "PARAM")) { /* old, fixed-length records format */ oldtype = TRUE; oldhead = TRUE; } else ERROR(NOT_PARAMETER_FILE); status = setup_conversions(unit); if (status != SUCCESS) ERROR(status); /* Parm files have a header, followed by header.val_len bytes of data, */ /* followed immediately by another header. The buffer allocated to */ /* read the data becomes the actual buffer used by the par block, */ /* except for real*4 data, which gets copied to a real*8 buffer. */ /* The old format (if oldtype == TRUE), had one header and data area */ /* per record. The difference in processing is that a record-sized */ /* buffer is allocated to read the data, then it is always copied to a */ /* new buffer of the correct size. */ /* The new-style header has the header, followed by header.name_len */ /* bytes of name, and header.val_len bytes of data, as above. */ if (oldtype) { zvget(unit,"NL",&nl,"NS",&ns, NULL); /* Get number of parms */ /* and record length */ buff = (char *)malloc(ns); if (buff == NULL) ERROR(INSUFFICIENT_MEMORY); buf = buff + sizeof(header); } else { status = v2_parm_init(unit); if (status != SUCCESS) return status; } /* Loop through all the parameters in the file */ line = 0; eof = FALSE; while (!eof) { if (oldtype) { /* get line from file */ if (line++ >= nl) { eof = TRUE; continue; } zvread(unit, buff, NULL); convert_old_parm_header((struct OLD_PARM_LINE *)buff, &header, parm_name); data_ptr = buf; } else { if (oldhead) { v2_parm_read((char*) &old_header, sizeof(old_header)); /* read header */ if ((char)old_header.p_type == (char)PARM_V_EOF) { eof = TRUE; continue; } convert_old_parm_header(&old_header, &header, parm_name); } else { /* new header */ v2_parm_read((char*) &header, sizeof(header)); /* read header */ if ((char)header.p_type == (char)PARM_V_EOF) { eof = TRUE; continue; } convert_parm_header(&header); if (header.version != 0) /* whoops, new version! */ ERROR(PARM_FILE_VERSION); v2_parm_read(parm_name, header.name_len); } buf = (char *)malloc(header.val_len); if (buf == 0) ERROR(INSUFFICIENT_MEMORY); data_ptr = buf; v2_parm_read(buf, header.val_len); } /* Find the currently named parameter in the par block */ current_parm = p_fvar((struct PARBLK*) parb, parm_name); if (current_parm == 0) { /* Current parameter not in par block */ sprintf(msgbuf,"XVPINIT -- Parameter %s not found", parm_name); zvmessage(msgbuf,"VIC2-GENERR"); zabend(); } /* Make sure parameter was defaulted (allow explicit interactive parm */ /* to override parm file entry) */ if (current_parm->vu_class.vs_parm.V_default == FALSE) continue; /* Make sure type agrees */ tae_type = (header.p_type==PARM_V_REAL8) ? PARM_V_REAL : header.p_type; if (current_parm->v_type != tae_type) { sprintf(msgbuf,"XVPINIT -- Data type of %s does not agree with PDF", current_parm->v_name); zvmessage(msgbuf,"VIC2-GENERR"); zabend(); } /* Fill in VARIABLE structure at current_parm */ current_parm->vu_class.vs_parm.V_default = FALSE; /* clear def flag */ current_parm->vu_value.vs_direct.V_count = header.p_count;/* TCL count */ current_parm->vu_value.vs_direct.V_size = header.p_size; /* max string size */ if (header.p_type == PARM_V_REAL) { /* Transfer real*4 to real*8 buf */ data_ptr = (char *)malloc((header.val_len)*2); /* Allocate a place */ if (data_ptr == 0) ERROR(INSUFFICIENT_MEMORY); /* to store data */ zvtrans((int *)&real_conv, buf, data_ptr, header.p_count); /* real->doub */ if (!oldtype) free(buf); } else { /* store directly as is (with host conversion if needed) */ if (oldtype) { /* old style needs buffer copied */ data_ptr = (char *)malloc(header.val_len); /* Allocate a */ if (data_ptr == 0) ERROR(INSUFFICIENT_MEMORY); /* place to */ /* store data */ if (header.p_type == PARM_V_INTEGER) zvtrans((int *)&int_conv, buf, data_ptr, header.p_count); else if (header.p_type == PARM_V_REAL) zvtrans((int *)&doub_conv, buf, data_ptr, header.p_count); else /* PARM_V_STRING */ memcpy(data_ptr,buf, header.val_len); } else { /* new style may need types converted */ if (header.p_type == PARM_V_INTEGER && int_conv.transfn != 0) { data_ptr = (char *)malloc(header.val_len); if (data_ptr == 0) ERROR(INSUFFICIENT_MEMORY); zvtrans((int *)&int_conv, buf, data_ptr, header.p_count); free(buf); } else if (header.p_type == PARM_V_REAL && doub_conv.transfn != 0) { data_ptr = (char *)malloc(header.val_len); if (data_ptr == 0) ERROR(INSUFFICIENT_MEMORY); zvtrans((int *)&doub_conv, buf, data_ptr, header.p_count); free(buf); } /* Strings don't need to be converted */ } } /* Store pointer to data*/ if (current_parm->v_type == PARM_V_STRING) { /* For strings, store array of pointers to data */ i = sizeof(char *) * header.p_count; str_ptr = (char **)malloc (i); /* array of ptrs to actual data */ if (str_ptr == 0) ERROR(INSUFFICIENT_MEMORY); current_parm->vu_value.vs_direct.V_cvp = (GENPTR)str_ptr; for (i = 0; i < header.p_count; i++) { /* Fill in array of ptrs */ *str_ptr = data_ptr; str_ptr++; data_ptr += strlen(data_ptr) + 1; } } else { current_parm->vu_value.vs_direct.V_cvp = data_ptr; } } if (oldtype) free(buff); else v2_parm_close(); zvclose(unit,NULL); /* close the file */ return SUCCESS; }