Commit c2635224 authored by Claes Sjöfors's avatar Claes Sjöfors

Ge curve, unit wasn't displayed, show description, save scale min/max

parent bc33b8d2
......@@ -375,6 +375,28 @@ void GeCurveGtk::activate_minmax_ok( GtkWidget *w, gpointer data)
g_object_set( ((GeCurveGtk *)curve)->minmax_widget, "visible", FALSE, NULL);
}
void GeCurveGtk::activate_minmax_save( GtkWidget *w, gpointer data)
{
GeCurve *curve = (GeCurve *)data;
char *value;
double min_value, max_value;
int nr;
value = gtk_editable_get_chars( GTK_EDITABLE(((GeCurveGtk *)curve)->minmax_textmin_widget), 0, -1);
nr = sscanf( value, "%lf", &min_value);
g_free( value);
if ( nr != 1)
return;
value = gtk_editable_get_chars( GTK_EDITABLE(((GeCurveGtk *)curve)->minmax_textmax_widget), 0, -1);
nr = sscanf( value, "%lf", &max_value);
g_free( value);
if ( nr != 1)
return;
curve->activate_minmax_save( min_value, max_value);
}
void GeCurveGtk::activate_minmax_cancel( GtkWidget *w, gpointer data)
{
GeCurve *curve = (GeCurve *)data;
......@@ -396,12 +418,16 @@ void GeCurveGtk::activate_export_ok( GtkWidget *w, gpointer data)
value = gtk_combo_box_get_active_text( GTK_COMBO_BOX(((GeCurveGtk *)curve)->export_attrcombo_widget));
if ( !value) return;
if ( strcmp( value, CoWowGtk::translate_utf8("All Attributes")) == 0)
idx = -1;
else {
for ( int i = 0; i < curve->cd->cols; i++) {
if ( strcmp( value, CoWowGtk::convert_utf8(curve->cd->y_name[i])) == 0) {
idx = i;
break;
}
}
}
g_free( value);
value = gtk_editable_get_chars( GTK_EDITABLE(((GeCurveGtk *)curve)->export_fromtime_widget), 0, -1);
......@@ -627,6 +653,21 @@ void GeCurveGtk::set_inputfocus()
gtk_widget_grab_focus( growcurve_main_widget);
}
void GeCurveGtk::set_clock_cursor()
{
if ( !clock_cursor)
clock_cursor = gdk_cursor_new_for_display( gtk_widget_get_display( toplevel),
GDK_WATCH);
gdk_window_set_cursor( toplevel->window, clock_cursor);
gdk_display_flush( gtk_widget_get_display( toplevel));
}
void GeCurveGtk::reset_cursor()
{
gdk_window_set_cursor( toplevel->window, NULL);
}
GeCurveGtk::~GeCurveGtk()
{
delete wow;
......@@ -666,7 +707,7 @@ GeCurveGtk::GeCurveGtk( void *gc_parent_ctx,
GeCurveData *curve_data,
int pos_right) :
GeCurve( gc_parent_ctx, curve_name, filename, curve_data, pos_right),
minmax_widget(0), export_widget(0), disable_timecombo_callback(0)
minmax_widget(0), export_widget(0), disable_timecombo_callback(0), clock_cursor(0)
{
const int window_width = 900;
......@@ -1081,6 +1122,11 @@ void GeCurveGtk::create_minmax_dialog()
g_signal_connect( minmax_cancel, "clicked",
G_CALLBACK(activate_minmax_cancel), this);
GtkWidget *minmax_save = gtk_button_new_with_label( CoWowGtk::translate_utf8("Save"));
gtk_widget_set_size_request( minmax_cancel, 70, 25);
g_signal_connect( minmax_save, "clicked",
G_CALLBACK(activate_minmax_save), this);
GtkWidget *minmax_hbox1 = gtk_hbox_new( FALSE, 0);
gtk_box_pack_start( GTK_BOX(minmax_hbox1), min_label, FALSE, FALSE, 15);
gtk_box_pack_start( GTK_BOX(minmax_hbox1), minmax_textmin_widget, TRUE, TRUE, 30);
......@@ -1091,7 +1137,8 @@ void GeCurveGtk::create_minmax_dialog()
GtkWidget *minmax_hboxbuttons = gtk_hbox_new( TRUE, 40);
gtk_box_pack_start( GTK_BOX(minmax_hboxbuttons), minmax_ok, FALSE, FALSE, 0);
gtk_box_pack_end( GTK_BOX(minmax_hboxbuttons), minmax_cancel, FALSE, FALSE, 0);
gtk_box_pack_start( GTK_BOX(minmax_hboxbuttons), minmax_cancel, FALSE, FALSE, 0);
gtk_box_pack_end( GTK_BOX(minmax_hboxbuttons), minmax_save, FALSE, FALSE, 0);
GtkWidget *minmax_vbox = gtk_vbox_new( FALSE, 0);
gtk_box_pack_start( GTK_BOX(minmax_vbox), minmax_hbox1, FALSE, FALSE, 15);
......@@ -1127,6 +1174,7 @@ void GeCurveGtk::create_export_dialog()
GtkWidget *attr_label = gtk_label_new(CoWowGtk::translate_utf8("Attribute"));
gtk_widget_set_size_request( attr_label, 90, -1);
export_attrcombo_widget = gtk_combo_box_new_text();
gtk_combo_box_append_text( GTK_COMBO_BOX(export_attrcombo_widget), CoWowGtk::translate_utf8("All Attributes"));
for ( int i = 0; i < cd->cols; i++) {
gtk_combo_box_append_text( GTK_COMBO_BOX(export_attrcombo_widget), CoWowGtk::convert_utf8(cd->y_name[i]));
}
......
......@@ -91,6 +91,7 @@ class GeCurveGtk : public GeCurve {
GtkWidget *timebox_timecombo;
CoWowFocusTimerGtk focustimer;
int disable_timecombo_callback;
GdkCursor *clock_cursor;
void pop();
void write_title( char *str);
......@@ -107,6 +108,8 @@ class GeCurveGtk : public GeCurve {
pwr_tStatus get_times( pwr_tTime *from, pwr_tTime *to);
int get_period( time_ePeriod *period);
void set_period( time_ePeriod period, int nocallback);
void set_clock_cursor();
void reset_cursor();
~GeCurveGtk();
......@@ -140,6 +143,7 @@ class GeCurveGtk : public GeCurve {
static void activate_help( GtkWidget *w, gpointer data);
static void activate_minmax_ok( GtkWidget *w, gpointer data);
static void activate_minmax_cancel( GtkWidget *w, gpointer data);
static void activate_minmax_save( GtkWidget *w, gpointer data);
static void activate_export_ok( GtkWidget *w, gpointer data);
static void activate_export_cancel( GtkWidget *w, gpointer data);
static void activate_export_browse( GtkWidget *w, gpointer data);
......
......@@ -265,6 +265,52 @@ void GeCurve::activate_minmax_ok( double min_value, double max_value)
}
void GeCurve::activate_minmax_save( double min_value, double max_value)
{
FILE *fp;
int i = minmax_idx;
fp = fopen( minmax_filename(cd->y_name[i]), "w");
if ( !fp)
return;
fprintf( fp, "%lf %lf\n", min_value, max_value);
fclose( fp);
}
int GeCurve::get_saved_minmax( char *name, double *min_value, double *max_value)
{
FILE *fp;
fp = fopen( minmax_filename( name), "r");
if ( !fp)
return 0;
fscanf( fp, "%lf %lf\n", min_value, max_value);
fclose( fp);
return 1;
}
char *GeCurve::minmax_filename( char *aname)
{
static pwr_tFileName fname;
pwr_tAName attrname;
strcpy( attrname, aname);
cdh_ToLower( attrname, attrname);
for ( char *s = attrname; *s; s++) {
if ( *s == '-')
*s = '_';
if ( *s == '.')
*s = '_';
}
strcpy( fname, "$HOME/pwr_curve_");
strcat( fname, attrname);
strcat( fname, ".dat");
dcli_translate_filename( fname, fname);
return fname;
}
//
// Callbacks from growcurve
......@@ -820,6 +866,12 @@ int GeCurve::config_names()
glow_eDrawType_Line, 2, glow_eFont_LucidaSans,
glow_mDisplayLevel_1, NULL, &o1);
x += 14;
grow_CreateGrowText( grownames_ctx, "", Lng::translate("Description"),
x, 0.6, glow_eDrawType_TextHelvetica,
glow_eDrawType_Line, 2, glow_eFont_LucidaSans,
glow_mDisplayLevel_1, NULL, &o1);
for ( int i = 0; i < cd->cols; i++) {
// Draw shadowed frame
grow_CreateGrowRect( grownames_ctx, "", 0, (i+0.8), 60, 1,
......@@ -873,6 +925,23 @@ int GeCurve::config_names()
x, (i+0.8) + 0.75, glow_eDrawType_TextHelvetica,
glow_eDrawType_Line, 2, glow_eFont_LucidaSans,
glow_mDisplayLevel_1, NULL, &t1);
if ( strcmp( cd->y_description[i], "") != 0) {
double w, h, descent;
grow_GetTextExtent( grownames_ctx, cd->y_name[i], strlen(cd->y_name[i]),
glow_eDrawType_TextHelvetica, 2, glow_eFont_LucidaSans, &w, &h, &descent);
if ( w < 13)
x += 14;
else
x += w + 1;
grow_CreateGrowText( grownames_ctx, "", cd->y_description[i],
x, (i+0.8) + 0.75, glow_eDrawType_TextHelvetica,
glow_eDrawType_Line, 2, glow_eFont_LucidaSans,
glow_mDisplayLevel_1, NULL, &t1);
}
grow_SetAnnotation( cursor_annot[i], 0, "0", 1);
grow_SetAnnotation( mark1_annot[i], 0, "0", 1);
grow_SetAnnotation( mark2_annot[i], 0, "0", 1);
......@@ -1443,6 +1512,7 @@ GeCurveData::GeCurveData( curve_eDataType datatype) :
strcpy( y_unit[i], "");
strcpy( y_format[i], "");
strcpy( y_name[i], "");
strcpy( y_description[i], "");
rows[i] = 0;
y_max_value[i] = 0;
y_min_value[i] = 0;
......@@ -1533,9 +1603,15 @@ void GeCurveData::get_borders()
void GeCurveData::get_default_axis()
{
double min_value, max_value;
for ( int i = 0; i < cols; i++) {
if ( GeCurve::get_saved_minmax( y_name[i], &min_value, &max_value))
scale( y_axis_type[i], y_value_type[i], min_value, max_value,
&y_min_value_axis[i], &y_max_value_axis[i], &y_trend_lines[i], &y_axis_lines[i],
&y_axis_linelongq[i], &y_axis_valueq[i], y_format[i],
&y_axis_width[i], 0, 0);
else
scale( y_axis_type[i], y_value_type[i], y_min_value[i], y_max_value[i],
&y_min_value_axis[i], &y_max_value_axis[i], &y_trend_lines[i], &y_axis_lines[i],
&y_axis_linelongq[i], &y_axis_valueq[i], y_format[i],
......
......@@ -78,6 +78,7 @@ class GeCurveData {
int cols;
pwr_tAName y_name[CURVE_MAX_COLS];
pwr_tAName x_name;
char y_description[CURVE_MAX_COLS][80];
char y_unit[CURVE_MAX_COLS][16];
char x_unit[CURVE_MAX_COLS][16];
double *y_data[CURVE_MAX_COLS];
......@@ -198,6 +199,8 @@ class GeCurve {
virtual pwr_tStatus get_times( pwr_tTime *from, pwr_tTime *to) {return 0;}
virtual int get_period( time_ePeriod *period) {return 0;}
virtual void set_period( time_ePeriod period, int nocallback) {}
virtual void set_clock_cursor() {}
virtual void reset_cursor() {}
void set_inputfocus() {}
int read_file( char *filename);
......@@ -224,6 +227,7 @@ class GeCurve {
void activate_period( time_ePeriod);
void activate_edit();
void activate_minmax_ok( double min_value, double max_value);
void activate_minmax_save( double min_value, double max_value);
void set_curvedata( GeCurveData *curve_data);
void redraw();
void x_to_points( double x, double *time, double *values);
......@@ -236,6 +240,8 @@ class GeCurve {
static int grownames_cb( GlowCtx *ctx, glow_tEvent event);
static int init_growaxis_cb( GlowCtx *fctx, void *client_data);
static int init_grownames_cb( GlowCtx *fctx, void *client_data);
static int get_saved_minmax( char *name, double *min_value, double *max_value);
static char *minmax_filename( char *aname);
};
/*@}*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment