Commit 84ac065b authored by Claes Sjofors's avatar Claes Sjofors

Trend curves with circular buffer remote protocol added

parent a41fe692
......@@ -285,7 +285,7 @@ void CoWowGtk::CreateInputDialog( void *ctx, const char *title, const char *text
gint pos = 0;
if ( init_text && strcmp( init_text, "") != 0) {
char *textutf8 = g_convert( text, -1, "UTF-8", "ISO8859-1", NULL, NULL, NULL);
char *textutf8 = g_convert( init_text, -1, "UTF-8", "ISO8859-1", NULL, NULL, NULL);
gtk_editable_insert_text( GTK_EDITABLE(textinput), textutf8,
strlen(textutf8), &pos);
g_free( textutf8);
......
......@@ -310,6 +310,27 @@ void GeCurveGtk::activate_xlimits( GtkWidget *w, gpointer data)
curve->open_minmax(0);
}
void GeCurveGtk::activate_new( GtkWidget *w, gpointer data)
{
GeCurve *curve = (GeCurve *)data;
curve->activate_new();
}
void GeCurveGtk::activate_save( GtkWidget *w, gpointer data)
{
GeCurve *curve = (GeCurve *)data;
curve->activate_save();
}
void GeCurveGtk::activate_open( GtkWidget *w, gpointer data)
{
GeCurve *curve = (GeCurve *)data;
curve->activate_open();
}
void GeCurveGtk::activate_snapshot( GtkWidget *w, gpointer data)
{
GeCurve *curve = (GeCurve *)data;
......@@ -446,20 +467,24 @@ void GeCurveGtk::export_file_selected_cb( void *ctx, char *filename, wow_eFileSe
filename, strlen(filename), &pos);
}
void GeCurveGtk::enable_timebox()
{
g_object_set( sea_timebox, "visible", TRUE, NULL);
}
void GeCurveGtk::enable_export()
void GeCurveGtk::enable( unsigned int mask)
{
g_object_set( menu_export, "visible", TRUE, NULL);
if ( mask & curve_mEnable_New)
g_object_set( menu_new, "visible", TRUE, NULL);
if ( mask & curve_mEnable_Save)
g_object_set( menu_save, "visible", TRUE, NULL);
if ( mask & curve_mEnable_Open)
g_object_set( menu_open, "visible", TRUE, NULL);
if ( mask & curve_mEnable_Snapshot) {
g_object_set( menu_snapshot, "visible", TRUE, NULL);
g_object_set( tools_snapshot, "visible", TRUE, NULL);
}
if ( mask & curve_mEnable_Export)
g_object_set( menu_export, "visible", TRUE, NULL);
if ( mask & curve_mEnable_Timebox)
g_object_set( sea_timebox, "visible", TRUE, NULL);
}
void GeCurveGtk::enable_snapshot()
{
g_object_set( menu_snapshot, "visible", TRUE, NULL);
}
void GeCurveGtk::pop()
{
......@@ -688,6 +713,17 @@ GeCurveGtk::GeCurveGtk( void *gc_parent_ctx,
menu_export = gtk_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("_Export"));
g_signal_connect(menu_export, "activate", G_CALLBACK(activate_export), this);
menu_new = gtk_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("_New"));
g_signal_connect(menu_new, "activate", G_CALLBACK(activate_new), this);
menu_save = gtk_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("S_ave"));
g_signal_connect(menu_save, "activate", G_CALLBACK(activate_save), this);
gtk_widget_add_accelerator( menu_save, "activate", accel_g,'s',
GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE);
menu_open = gtk_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("_Open"));
g_signal_connect(menu_open, "activate", G_CALLBACK(activate_open), this);
menu_snapshot = gtk_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("_Snapshot"));
g_signal_connect(menu_snapshot, "activate", G_CALLBACK(activate_snapshot), this);
gtk_widget_add_accelerator( menu_snapshot, "activate", accel_g,'n',
......@@ -703,6 +739,9 @@ GeCurveGtk::GeCurveGtk( void *gc_parent_ctx,
GtkMenu *file_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_refresh);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_print);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), menu_new);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), menu_open);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), menu_save);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), menu_snapshot);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), menu_export);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_close);
......@@ -837,6 +876,14 @@ GeCurveGtk::GeCurveGtk( void *gc_parent_ctx,
g_object_set( tools_page_right, "can-focus", FALSE, NULL);
gtk_toolbar_append_widget( tools, tools_page_right, CoWowGtk::translate_utf8("Page right"), "");
tools_snapshot = gtk_button_new();
dcli_translate_filename( fname, "$pwr_exe/xtt_snapshot.png");
gtk_container_add( GTK_CONTAINER(tools_snapshot),
gtk_image_new_from_file( fname));
g_signal_connect(tools_snapshot, "clicked", G_CALLBACK(activate_snapshot), this);
g_object_set( tools_snapshot, "can-focus", FALSE, NULL);
gtk_toolbar_append_widget( tools, tools_snapshot, CoWowGtk::translate_utf8("Snapshot"), "");
// Time box
GtkToolbar *timetools = (GtkToolbar *) g_object_new(GTK_TYPE_TOOLBAR, NULL);
......@@ -982,8 +1029,12 @@ GeCurveGtk::GeCurveGtk( void *gc_parent_ctx,
gtk_paned_set_position( GTK_PANED(vpaned1), names_height);
gtk_paned_set_position( GTK_PANED(vpaned2), window_height - names_height - nav_height - 50);
g_object_set( sea_timebox, "visible", FALSE, NULL);
g_object_set( menu_new, "visible", FALSE, NULL);
g_object_set( menu_save, "visible", FALSE, NULL);
g_object_set( menu_open, "visible", FALSE, NULL);
g_object_set( menu_snapshot, "visible", FALSE, NULL);
g_object_set( menu_export, "visible", FALSE, NULL);
g_object_set( tools_snapshot, "visible", FALSE, NULL);
wow = new CoWowGtk( toplevel);
......
......@@ -45,6 +45,15 @@
#include "cow_wow_gtk.h"
typedef enum {
curve_mEnable_New = 1 << 0,
curve_mEnable_Save = 1 << 1,
curve_mEnable_Open = 1 << 2,
curve_mEnable_Snapshot = 1 << 3,
curve_mEnable_Export = 1 << 4,
curve_mEnable_Timebox = 1 << 5
} curve_mEnable;
class GeCurveGtk : public GeCurve {
public:
GeCurveGtk( void *gc_parent_ctx, GtkWidget *parent_widget, char *curve_name,
......@@ -64,8 +73,12 @@ class GeCurveGtk : public GeCurve {
GtkWidget *minmax_widget;
GtkWidget *minmax_textmin_widget;
GtkWidget *minmax_textmax_widget;
GtkWidget *menu_new;
GtkWidget *menu_save;
GtkWidget *menu_open;
GtkWidget *menu_snapshot;
GtkWidget *menu_export;
GtkWidget *tools_snapshot;
GtkWidget *export_widget;
GtkWidget *export_attrcombo_widget;
GtkWidget *export_fromtime_widget;
......@@ -88,9 +101,7 @@ class GeCurveGtk : public GeCurve {
void create_minmax_dialog();
void create_export_dialog();
void set_inputfocus();
void enable_timebox();
void enable_export();
void enable_snapshot();
void enable( unsigned int mask);
void set_times( pwr_tTime *from, pwr_tTime *to);
void set_times_sensitivity( int sensitive);
pwr_tStatus get_times( pwr_tTime *from, pwr_tTime *to);
......@@ -102,6 +113,9 @@ class GeCurveGtk : public GeCurve {
static void activate_exit( GtkWidget *w, gpointer data);
static void activate_configure( GtkWidget *w, gpointer data);
static void activate_print( GtkWidget *w, gpointer data);
static void activate_new( GtkWidget *w, gpointer data);
static void activate_save( GtkWidget *w, gpointer data);
static void activate_open( GtkWidget *w, gpointer data);
static void activate_snapshot( GtkWidget *w, gpointer data);
static void activate_export( GtkWidget *w, gpointer data);
static void activate_zoomin( GtkWidget *w, gpointer data);
......
......@@ -80,6 +80,24 @@ void GeCurve::activate_configure()
configure_axes();
}
void GeCurve::activate_new()
{
if ( new_cb)
(new_cb)( parent_ctx);
}
void GeCurve::activate_save()
{
if ( save_cb)
(save_cb)( parent_ctx);
}
void GeCurve::activate_open()
{
if ( open_cb)
(open_cb)( parent_ctx);
}
void GeCurve::activate_snapshot()
{
if ( snapshot_cb)
......@@ -402,6 +420,9 @@ int GeCurve::growcurve_cb( GlowCtx *ctx, glow_tEvent event)
double time;
double values[CURVE_MAX_COLS];
if ( curve->cd->cols == 0)
return 1;
curve->last_cursor_x = event->any.x;
curve->x_to_points( event->any.x, &time, values);
......@@ -1378,7 +1399,8 @@ GeCurve::GeCurve( void *gc_parent_ctx,
border_bright(glow_eDrawType_Color22),
cd(0), axis_window_width(0), auto_refresh(1), axis_displayed(1),
minmax_idx(0), close_cb(0), help_cb(0), increase_period_cb(0), decrease_period_cb(0), reload_cb(0),
prev_period_cb(0), next_period_cb(0), add_cb(0), remove_cb(0), export_cb(0), snapshot_cb(0),
prev_period_cb(0), next_period_cb(0), add_cb(0), remove_cb(0), export_cb(0), new_cb(0),
save_cb(0), open_cb(0), snapshot_cb(0),
initial_right_position(pos_right), last_cursor_x(0), last_mark1_x(0), last_mark2_x(0),
deferred_configure_axes(0), center_from_window(0)
{
......
......@@ -170,6 +170,9 @@ class GeCurve {
void (*add_cb)( void *);
void (*remove_cb)( void *);
int (*export_cb)( void *, pwr_tTime *, pwr_tTime *, int, int, char *);
void (*new_cb)( void *);
void (*save_cb)( void *);
void (*open_cb)( void *);
void (*snapshot_cb)( void *);
int initial_right_position;
char title[300];
......@@ -189,9 +192,7 @@ class GeCurve {
virtual void open_minmax( int idx) {}
virtual void open_export( pwr_tTime *from, pwr_tTime *to, int rows, char *filename) {}
virtual void axis_set_width( int width) {}
virtual void enable_timebox() {}
virtual void enable_snapshot() {}
virtual void enable_export() {}
virtual void enable( unsigned int mask) {}
virtual void set_times( pwr_tTime *from, pwr_tTime *to) {}
virtual void set_times_sensitivity( int sensitive) {}
virtual pwr_tStatus get_times( pwr_tTime *from, pwr_tTime *to) {return 0;}
......@@ -211,6 +212,9 @@ class GeCurve {
void measure_window( double *ll_x, double *ll_y, double *ur_x, double *ur_y);
void activate_exit();
void activate_configure();
void activate_new();
void activate_save();
void activate_open();
void activate_snapshot();
void activate_export();
void activate_print();
......@@ -224,6 +228,7 @@ class GeCurve {
void redraw();
void x_to_points( double x, double *time, double *values);
void set_center_from_window( int val) { center_from_window = val;}
void set_title( const char *str);
static int growcurve_cb( GlowCtx *ctx, glow_tEvent event);
static int init_growcurve_cb( GlowCtx *fctx, void *client_data);
......
......@@ -94,8 +94,7 @@ XttSevHistGtk::XttSevHistGtk( void *parent_ctx,
curve->add_cb = sevhist_add_cb;
curve->remove_cb = sevhist_remove_cb;
curve->export_cb = sevhist_export_cb;
curve->enable_timebox();
curve->enable_export();
curve->enable( curve_mEnable_Timebox | curve_mEnable_Export);
wow = new CoWowGtk( parent_widget);
timerid = wow->timer_new();
......
......@@ -88,10 +88,13 @@ XttTCurveGtk::XttTCurveGtk( void *parent_ctx,
curve->prev_period_cb = tcurve_prev_period_cb;
curve->next_period_cb = tcurve_next_period_cb;
curve->add_cb = tcurve_add_cb;
curve->new_cb = tcurve_new_cb;
curve->open_cb = tcurve_open_cb;
curve->save_cb = tcurve_save_cb;
curve->remove_cb = tcurve_remove_cb;
curve->export_cb = tcurve_export_cb;
curve->enable_timebox();
curve->enable_export();
curve->enable( curve_mEnable_Timebox | curve_mEnable_Export | curve_mEnable_New |
curve_mEnable_Open | curve_mEnable_Save);
wow = new CoWowGtk( parent_widget);
timerid = wow->timer_new();
......
......@@ -79,7 +79,7 @@ XttTrendGtk::XttTrendGtk( void *parent_ctx,
curve->snapshot_cb = trend_snapshot_cb;
if ( trend_tid == pwr_cClass_DsTrendCurve)
curve->enable_snapshot();
curve->enable( curve_mEnable_Snapshot);
wow = new CoWowGtk( parent_widget);
timerid = wow->timer_new();
......
......@@ -77,6 +77,7 @@ XttTCurve::XttTCurve( void *parent_ctx,
if ( xn_arefv == 0 || xn_arefv[0].Objid.vid == 0) {
aref_cnt = 0;
gcd = new GeCurveData( curve_eDataType_DsTrend);
*sts = 1;
return;
}
......@@ -474,6 +475,44 @@ void XttTCurve::tcurve_close_cb( void *ctx)
delete tcurve;
}
void XttTCurve::tcurve_new_cb( void *ctx)
{
XttTCurve *tcurve = (XttTCurve *) ctx;
if ( tcurve->command_cb)
(tcurve->command_cb)( tcurve->xnav, "open tcurve /new");
}
void XttTCurve::tcurve_file_selected_cb( void *ctx, void *data, char *text)
{
XttTCurve *tcurve = (XttTCurve *)ctx;
tcurve->save( text);
}
void XttTCurve::tcurve_save_cb( void *ctx)
{
XttTCurve *tcurve = (XttTCurve *) ctx;
tcurve->curve->wow->CreateInputDialog( tcurve, "Save as", "Enter filename",
tcurve_file_selected_cb, 0, 40, tcurve->title, 0);
}
void XttTCurve::tcurve_open_file_cb( void *ctx, char *text)
{
XttTCurve *tcurve = (XttTCurve *)ctx;
tcurve->open( text);
}
void XttTCurve::tcurve_open_cb( void *ctx)
{
XttTCurve *tcurve = (XttTCurve *) ctx;
tcurve->curve->wow->CreateFileList( "Open trend data", "$pwrp_load", "*", "rtt_trd",
tcurve_open_file_cb, 0, tcurve, 1);
}
void XttTCurve::tcurve_decrease_period_cb( void *ctx)
{
XttTCurve *tcurve = (XttTCurve *) ctx;
......@@ -879,9 +918,86 @@ int XttTCurve::load_data( pwr_tStatus *sts, pwr_tAttrRef *aref)
return 0;
}
}
else
*sts = 1;
return 1;
}
void XttTCurve::save( char *filename)
{
pwr_tFileName fname;
strcpy( fname, filename);
if ( !( strlen(filename) < 9 &&
strcmp( &filename[strlen(filename)-9], ".rtt_trd") == 0))
strncat( fname, ".rtt_trd", sizeof(fname));
dcli_translate_filename( fname, fname);
ofstream fp(fname);
if ( !fp) {
printf( "Unable to open file\n");
return;
}
fp.write( (char *)&aref_cnt, sizeof(aref_cnt));
fp.write( (char *)arefv, aref_cnt * sizeof(arefv[0]));
fp.write( (char *)&tc, sizeof(tc));
fp.write( tc.tbuf, tc.timebuf_bsize);
for ( int i = 0; i < tc.bufcnt; i++)
fp.write( tc.vbuf[i], tc.buf_bsize[i]);
fp.close();
}
void XttTCurve::open( char *filename)
{
pwr_tFileName fname;
pwr_tStatus sts;
strcpy( fname, filename);
if ( !( strlen(filename) < 9 &&
strcmp( &filename[strlen(filename)-9], ".rtt_trd") == 0))
strncat( fname, ".rtt_trd", sizeof(fname));
dcli_translate_filename( fname, fname);
ifstream fp(fname);
if ( !fp) {
printf( "Unable to open file\n");
return;
}
// Free old data
free( tc.tbuf);
for ( int i = 0; i < tc.bufcnt; i++)
free( tc.vbuf[i]);
fp.read( (char *)&aref_cnt, sizeof(aref_cnt));
fp.read( (char *)arefv, aref_cnt * sizeof(arefv[0]));
fp.read( (char *)&tc, sizeof(tc));
tc.tbuf = (char *)calloc( 1, tc.timebuf_bsize);
fp.read( tc.tbuf, tc.timebuf_bsize);
for ( int i = 0; i < tc.bufcnt; i++) {
tc.vbuf[i] = (char *)calloc( 1, tc.buf_bsize[i]);
fp.read( tc.vbuf[i], tc.buf_bsize[i]);
}
fp.close();
pwr_tTime from = pwr_cNTime;
pwr_tTime to = {0xEFFFFFFF, 0};
get_data( &sts, from, to);
if ( curve)
curve->config_names();
set_title( filename);
}
void XttTCurve::set_title( const char *str)
{
strncpy( title, str, sizeof(title));
curve->write_title( title);
}
......@@ -104,6 +104,7 @@ class XttTCurve {
void (*close_cb)( void *, XttTCurve *); //!< Close callback to parent.
void (*help_cb)( void *, const char *); //!< Open help window.
int (*get_select_cb)( void *, pwr_tOid *, char *, char *); //!< Get selected TCurve object.
void (*command_cb)( void *, const char *); //!< Command callback to parent.
bool first_scan; //!< Indicates that this is the first scan.
char title[250]; //!< Window title
pwr_tAttrRef arefv[XTT_TCURVE_MAX];
......@@ -128,8 +129,14 @@ class XttTCurve {
int get_multidata( pwr_tStatus *sts, pwr_tTime from, pwr_tTime to);
void curve_add( pwr_tAttrRef aref);
int load_data( pwr_tStatus *sts, pwr_tAttrRef *aref);
void save( char *filename);
void open( char *filename);
void set_title( const char *str);
static void tcurve_close_cb( void *ctx);
static void tcurve_new_cb( void *ctx);
static void tcurve_save_cb( void *ctx);
static void tcurve_open_cb( void *ctx);
static void tcurve_increase_period_cb( void *ctx);
static void tcurve_decrease_period_cb( void *ctx);
static void tcurve_reload_cb( void *ctx);
......@@ -140,6 +147,8 @@ class XttTCurve {
static int tcurve_export_cb( void *ctx, pwr_tTime *from, pwr_tTime *to,
int rows, int idx, char *filename);
static void tcurve_help_cb( void *ctx);
static void tcurve_file_selected_cb( void *ctx, void *data, char *text);
static void tcurve_open_file_cb( void *ctx, char *text);
static void tcurve_scan( void *data);
};
......
......@@ -457,7 +457,7 @@ void XttTrend::trend_snapshot_cb( void *ctx)
XttTrend *trend = (XttTrend *) ctx;
pwr_tCmd cmd;
sprintf( cmd, "open tcurve %s", trend->trend_name[0]);
sprintf( cmd, "open tcurve %s/title=%s", trend->trend_name[0], trend->trend_name[0]);
if ( trend->command_cb)
(trend->command_cb)( trend->xnav, cmd);
......
......@@ -3186,6 +3186,20 @@ static int xnav_open_func( void *client_data,
pwr_tStatus sts;
char title_str[80];
if ( EVEN( dcli_get_qualifier( "/TITLE", title_str, sizeof(title_str)))) {
strcpy( title_str, "Trend");
}
if ( ODD( dcli_get_qualifier( "/NEW", 0, 0))) {
XttTCurve *tcurve = xnav->xtttcurve_new( title_str, 0, &sts);
if ( ODD(sts)) {
tcurve->close_cb = xnav_tcurve_close_cb;
tcurve->command_cb = xnav_trend_command_cb;
tcurve->help_cb = xnav_tcurve_help_cb;
}
return XNAV__SUCCESS;
}
/* Get the name qualifier */
if ( ODD( dcli_get_qualifier( "dcli_arg2", name_str, sizeof(name_str)))) {
if ( name_str[0] != '/')
......@@ -3211,10 +3225,6 @@ static int xnav_open_func( void *client_data,
}
}
if ( EVEN( dcli_get_qualifier( "/TITLE", title_str, sizeof(title_str)))) {
strcpy( title_str, "Trend");
}
memset( aref_vect, 0, sizeof(aref_vect));
sts = gdh_NameToAttrref( pwr_cNObjid, name_str, &aref_vect[0]);
if (EVEN(sts)) {
......@@ -3224,6 +3234,7 @@ static int xnav_open_func( void *client_data,
XttTCurve *tcurve = xnav->xtttcurve_new( title_str, aref_vect, &sts);
if ( ODD(sts)) {
tcurve->close_cb = xnav_tcurve_close_cb;
tcurve->command_cb = xnav_trend_command_cb;
tcurve->help_cb = xnav_tcurve_help_cb;
}
return XNAV__SUCCESS;
......
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