Esempio n. 1
0
int write_ssd(const Quark *ssd, unsigned int ncols, const int *cols, FILE *fp)
{
    char *sep = "\t";
    unsigned int nrows = ssd_get_nrows(ssd), i, j;

    unsigned int prec = project_get_prec(get_parent_project(ssd));

    fputs("# ", fp);
    for (j = 0; j < ncols; j++) {
        char *lab = ssd_get_col_label(ssd, cols[j]);
        if (j != 0) {
            fputs(sep, fp);
        }
        fputs(lab ? lab:"?", fp);
    }
    fputs("\n", fp);

    for (i = 0; i < nrows; i++) {
        for (j = 0; j < ncols; j++) {
            unsigned int col = cols[j];
            ss_column *scol = ssd_get_col(ssd, col);
            if (!scol) {
                return RETURN_FAILURE;
            }
            
            if (j != 0) {
                fputs(sep, fp);
            }
            
            if (scol->format == FFORMAT_STRING) {
                char **s = ((char **) scol->data);
                fprintf(fp, " \"%s\"", escapequotes(s[i]));
            } else {
                double *x = ((double *) scol->data);
                fprintf(fp, "%.*g", prec, x[i]);
            }
        }
        fputs("\n", fp);
    }
    fputs("\n", fp);
    return RETURN_SUCCESS;
}
Esempio n. 2
0
static char *get_cell_content(SSDataUI *ui, int row, int column, int *format)
{
    static char buf[STACKLEN][32];
    static int stackp = 0;
    
    int nrows = ssd_get_nrows(ui->q);
    ss_column *col = ssd_get_col(ui->q, column);
    char *s;

    if (col && row >= 0 && row < nrows) {
        unsigned int prec;
        *format = col->format;
        switch (col->format) {
        case FFORMAT_STRING:
            s = ((char **) col->data)[row];
            break;
        default:
            prec = project_get_prec(get_parent_project(ui->q));
            sprintf(buf[stackp], "%.*g", prec, ((double *) col->data)[row]);
            s = buf[stackp];
            stackp++;
            stackp %= STACKLEN;
            
            /* get rid of spaces */
            while (s && *s == ' ') {
                s++;
            }
            
            break;
        }
    } else {
        s = "";
    }
    
    return s;
}
Esempio n. 3
0
static int leaveCB(TableEvent *event)
{
    SSDataUI *ui = (SSDataUI *) event->anydata;

    int nrows = ssd_get_nrows(ui->q);
    int ncols = ssd_get_ncols(ui->q);
    int format;
    double value;
    
    int changed = FALSE;
    
    GraceApp *gapp = gapp_from_quark(ui->q);
    
    if (event->row < 0 || event->col < 0 || event->col > ncols) {
        return TRUE;
    }
    
    if (event->row >= nrows && !string_is_empty(event->value)) {
        if (ssd_set_nrows(ui->q, event->row + 1) == RETURN_SUCCESS) {
            changed = TRUE;
        }
    }
    
    if (event->col == ncols && !string_is_empty(event->value)) {
        if (parse_date_or_number(get_parent_project(ui->q),
            event->value, FALSE, get_date_hint(gapp), &value) == RETURN_SUCCESS) {
            format = FFORMAT_NUMBER;
        } else {
            format = FFORMAT_STRING;
        }
        if (ssd_add_col(ui->q, format)) {
            ncols++;
            changed = TRUE;
        }
    }
    
    if (event->col < ncols) {
        char *old_value = get_cell_content(ui, event->row, event->col, &format);
        if (!strings_are_equal(old_value, event->value)) {
            switch (format) {
            case FFORMAT_STRING:
                if (ssd_set_string(ui->q, event->row, event->col, event->value) ==
                    RETURN_SUCCESS) {
                    quark_dirtystate_set(ui->q, TRUE);
                    changed = TRUE;
                }
                break;    
            default:
                if (graal_eval_expr(grace_get_graal(gapp->grace),
                    event->value, &value, gproject_get_top(gapp->gp)) == RETURN_SUCCESS) {

                    unsigned int prec;
                    char buf[32];
                    double val;

                    prec = project_get_prec(get_parent_project(ui->q));
                    sprintf(buf, "%.*g", prec, value);

                    if (parse_date_or_number(get_parent_project(ui->q),
                        buf, FALSE, get_date_hint(gapp), &val) == RETURN_SUCCESS) {

                        if (ssd_set_value(ui->q, event->row, event->col, val) == RETURN_SUCCESS) {
                            quark_dirtystate_set(ui->q, TRUE);
                            changed = TRUE;
                        }
                    }
                } else {
                    errmsg("Can't parse input value");
                    return FALSE;
                }
                break;
            }
        }
    }
    
    if (changed) {
        snapshot_and_update(gapp->gp, FALSE);
    }

    return TRUE;
}
Esempio n. 4
0
void update_project_ui(ProjectUI *ui, Quark *q)
{
    Project *pr = project_get_data(q);
    if (pr) {
        int y, m, d, h, mm, sec;
        char date_string[64], wrap_year_string[64], buf[32];
        double factor;
        int format;

        SetSpinChoice(ui->prec, project_get_prec(q));
        TextSetString(ui->description, project_get_description(q));

        switch (GetOptionChoice(ui->page_size_unit)) {
        case PAGE_UNITS_IN:
            factor = 1.0/72.0;
            break;
        case PAGE_UNITS_CM:
            factor = CM_PER_INCH/72.0;
            break;
        default:
            factor = 1.0;
        }

        sprintf (buf, "%.2f", factor*pr->page_wpp); 
        TextSetString(ui->page_x, buf);
        sprintf (buf, "%.2f", factor*pr->page_hpp); 
        TextSetString(ui->page_y, buf);

        if ((pr->page_wpp == 612 && pr->page_hpp == 792) ||
            (pr->page_hpp == 612 && pr->page_wpp == 792)) {
            format = PAGE_FORMAT_USLETTER;
        } else
        if ((pr->page_wpp == 595 && pr->page_hpp == 842) ||
            (pr->page_hpp == 595 && pr->page_wpp == 842)) {
            format = PAGE_FORMAT_A4;
        } else {
            format = PAGE_FORMAT_CUSTOM;
        }
        if (format == PAGE_FORMAT_CUSTOM) {
            WidgetSetSensitive(ui->page_x->form, TRUE);
            WidgetSetSensitive(ui->page_y->form, TRUE);
            WidgetSetSensitive(ui->page_orient->menu, FALSE);
        } else {
            WidgetSetSensitive(ui->page_x->form, FALSE);
            WidgetSetSensitive(ui->page_y->form, FALSE);
            WidgetSetSensitive(ui->page_orient->menu, TRUE);
        }
        SetOptionChoice(ui->page_format, format);
        
        if (pr->page_wpp > pr->page_hpp) {
            SetOptionChoice(ui->page_orient, PAGE_ORIENT_LANDSCAPE);
        } else {
            SetOptionChoice(ui->page_orient, PAGE_ORIENT_PORTRAIT);
        }

        SetOptionChoice(ui->bg_color, pr->bgcolor);
        SetToggleButtonState(ui->bg_fill, pr->bgfill);

        SetSpinChoice(ui->fsize_scale, pr->fscale);
        SetSpinChoice(ui->lwidth_scale, pr->lscale);

	    jdate_to_datetime(q, 0.0, ROUND_SECOND, &y, &m, &d, &h, &mm, &sec);
        sprintf(date_string, "%d-%02d-%02d %02d:%02d:%02d",
            y, m, d, h, mm, sec);
        TextSetString(ui->refdate, date_string);
        SetToggleButtonState(ui->two_digits_years, pr->two_digits_years);
        sprintf(wrap_year_string, "%04d", pr->wrap_year);
        TextSetString(ui->wrap_year, wrap_year_string);
        WidgetSetSensitive(ui->wrap_year->form, pr->two_digits_years ? TRUE:FALSE);
    }
}