int main (int argc, char **argv) { GtkWidget *window = NULL; GtkWidget *curve = NULL; MtxCurveCoord points[11]; gint timeout = 0; gint i = 0; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_size_request(GTK_WIDGET(window),320,320); curve = mtx_curve_new (); gtk_container_add (GTK_CONTAINER (window), curve); for (i=0;i<11;i++) { /*points[i].x=i*1000; points[i].y=(i*1000)-5000;*/ points[i].x=i-6; points[i].y=powf(2.0,(gfloat)i); /*points[i].y=exp(i/2.0);*/ } gtk_widget_show(curve); mtx_curve_set_coords(MTX_CURVE(curve),11,points); mtx_curve_set_title(MTX_CURVE(curve),"Curve Demo"); mtx_curve_set_auto_hide_vertexes(MTX_CURVE(curve),FALSE); mtx_curve_set_show_x_marker(MTX_CURVE(curve),TRUE); /* mtx_curve_set_show_y_marker(MTX_CURVE(curve),TRUE);*/ mtx_curve_set_show_vertexes(MTX_CURVE(curve),TRUE); mtx_curve_set_x_axis_label(MTX_CURVE(curve),"X Axis"); mtx_curve_set_y_axis_label(MTX_CURVE(curve),"This is the Y Axis"); mtx_curve_set_hard_limits(MTX_CURVE(curve),-7.0,7.0,0.0,1200.0); /*mtx_curve_set_hard_limits(MTX_CURVE(curve),-2000.0,12000.0,-6000.0,7000.0);*/ mtx_curve_set_x_precision(MTX_CURVE(curve),2); mtx_curve_set_y_precision(MTX_CURVE(curve),2); g_signal_connect(G_OBJECT(curve), "coords-changed", G_CALLBACK(coords_changed),NULL); g_signal_connect(G_OBJECT(curve), "vertex-proximity", G_CALLBACK(vertex_proximity),NULL); g_signal_connect(G_OBJECT(curve), "marker-proximity", G_CALLBACK(marker_proximity),NULL); timeout = g_timeout_add(40,(GSourceFunc)update_curve_marker,(gpointer)curve); gtk_widget_show_all (window); g_signal_connect (window, "delete_event", G_CALLBACK (close_demo), GINT_TO_POINTER(timeout)); g_signal_connect (window, "destroy_event", G_CALLBACK (close_demo), GINT_TO_POINTER(timeout)); gtk_main (); return 0; }
/*! \brief Creates a group of 2D Table Editors packed into a GtkNotebook \param button is a pointer to the widget the user click on, which has bound to is a list of the TE Table ID's which we need to create on-screen representations for \returns TRUE on success, FALSE otherwise */ G_MODULE_EXPORT gboolean create_2d_table_editor_group(GtkWidget *button) { GladeXML *main_xml = NULL; GladeXML *xml = NULL; GtkWidget *widget = NULL; GtkWidget *window = NULL; GtkWidget *notebook = NULL; GtkWidget *curve = NULL; GtkWidget *x_parent = NULL; GtkWidget *y_parent = NULL; GtkWidget *x_table = NULL; GtkWidget *y_table = NULL; GtkWidget *label = NULL; GtkWidget *entry = NULL; GtkWidget *dummy = NULL; GtkWidget *gauge = NULL; GtkWidget *parent = NULL; GtkWidget *curve_parent = NULL; CurveData *cdata = NULL; GArray *x_entries = NULL; GArray *y_entries = NULL; GList *widget_list = NULL; GList *curve_list = NULL; GList *gauge_list = NULL; gchar * tmpbuf = NULL; gchar * filename = NULL; gchar **vector = NULL; GList ***ecu_widgets = NULL; gint num_tabs = 0; gint x_mult = 0; gint y_mult = 0; gint page = 0; gint offset = 0; gint i = 0; gint j = 0; gfloat tmpf = 0.0; guint32 id = 0; gint rows = 0; gint table_num = 0; Firmware_Details *firmware = NULL; firmware = DATA_GET(global_data,"firmware"); ecu_widgets = DATA_GET(global_data,"ecu_widgets"); main_xml = (GladeXML *)DATA_GET(global_data,"main_xml"); if (!main_xml) return FALSE; xml = glade_xml_new(main_xml->filename,"table_editor_window",NULL); window = glade_xml_get_widget(xml,"table_editor_window"); glade_xml_signal_autoconnect(xml); g_signal_connect(G_OBJECT(window),"destroy_event", G_CALLBACK(close_2d_editor),NULL); g_signal_connect(G_OBJECT(window),"delete_event", G_CALLBACK(close_2d_editor),NULL); gtk_window_set_title(GTK_WINDOW(window),_("2D Table Group Editor")); gtk_window_resize(GTK_WINDOW(window),800,530); widget = glade_xml_get_widget(xml,"2d_close_button"); g_signal_connect_swapped(G_OBJECT(widget),"clicked", G_CALLBACK(close_2d_editor),window); widget = glade_xml_get_widget(xml,"get_data_button"); OBJ_SET(widget,"handler",GINT_TO_POINTER(READ_VE_CONST)); OBJ_SET_FULL(widget,"bind_to_list",g_strdup("get_data_buttons"),g_free); bind_to_lists_f(widget,"get_data_buttons"); widget_list = g_list_prepend(widget_list,(gpointer)widget); widget = glade_xml_get_widget(xml,"burn_data_button"); OBJ_SET(widget,"handler",GINT_TO_POINTER(BURN_FLASH)); OBJ_SET_FULL(widget,"bind_to_list",g_strdup("burners"),g_free); bind_to_lists_f(widget,"burners"); widget_list = g_list_prepend(widget_list,(gpointer)widget); /* widget = glade_xml_get_widget(xml,"curve_editor_menuitem"); gtk_widget_set_sensitive(GTK_WIDGET(widget), FALSE); */ widget = glade_xml_get_widget(xml,"close_menuitem"); OBJ_SET(widget,"window",(gpointer)window); widget = glade_xml_get_widget(xml,"te_layout_hbox1"); gtk_widget_destroy(widget); widget = glade_xml_get_widget(xml,"te_layout_vbox"); tmpbuf = OBJ_GET(button,"te_tables"); vector = parse_keys_f(tmpbuf,&num_tabs,","); notebook = gtk_notebook_new(); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook),GTK_POS_LEFT); gtk_box_pack_start(GTK_BOX(widget),notebook,TRUE,TRUE,0); for (j = 0;j < num_tabs;j++) { table_num = (gint)strtod(vector[j],NULL); if (table_num >= firmware->total_te_tables) { warn_user_f("Requested to create 2D table editor window for an undefined (out of range) table ID"); return FALSE; } if (!firmware->te_params) { warn_user_f("No 2D table Editor tables (te_tables) defined in interrogation profile, yet told to create a graph for a table... BUG detected!"); continue; } if (!firmware->te_params[table_num]) { warn_user_f("Requested to create a 2D table editor window for an undefined table!"); continue; } xml = glade_xml_new(main_xml->filename,"te_layout_hbox1",NULL); widget = glade_xml_get_widget(xml,"te_layout_hbox1"); label = gtk_label_new(firmware->te_params[table_num]->title); gtk_misc_set_alignment(GTK_MISC(label),0,0.5); if (firmware->te_params[table_num]->bind_to_list) { OBJ_SET_FULL(widget,"bind_to_list", g_strdup(firmware->te_params[table_num]->bind_to_list),g_free); OBJ_SET(widget,"match_type", GINT_TO_POINTER(firmware->te_params[table_num]->match_type)); bind_to_lists_f(widget,firmware->te_params[table_num]->bind_to_list); widget_list = g_list_prepend(widget_list,(gpointer)widget); OBJ_SET_FULL(label,"bind_to_list", g_strdup(firmware->te_params[table_num]->bind_to_list),g_free); OBJ_SET(label,"match_type", GINT_TO_POINTER(firmware->te_params[table_num]->match_type)); bind_to_lists_f(label,firmware->te_params[table_num]->bind_to_list); widget_list = g_list_prepend(widget_list,(gpointer)label); } if (firmware->te_params[table_num]->gauge || firmware->te_params[table_num]->c_gauge || firmware->te_params[table_num]->f_gauge) { parent = glade_xml_get_widget(xml,"te_gaugeframe"); gauge = mtx_gauge_face_new(); gauge_list = g_list_prepend(gauge_list,(gpointer)gauge); OBJ_SET(window,"gauge",gauge); if (firmware->te_params[table_num]->gauge_temp_dep) { if ((GINT)DATA_GET(global_data,"mtx_temp_units") == CELSIUS) tmpbuf = g_strdelimit(firmware->te_params[table_num]->c_gauge,"\\",'/'); else if ((GINT)DATA_GET(global_data,"mtx_temp_units") == KELVIN) tmpbuf = g_strdelimit(firmware->te_params[table_num]->c_gauge,"\\",'/'); else tmpbuf = g_strdelimit(firmware->te_params[table_num]->f_gauge,"\\",'/'); } else tmpbuf = g_strdelimit(firmware->te_params[table_num]->gauge,"\\",'/'); filename = get_file(g_strconcat(GAUGES_DATA_DIR,PSEP,tmpbuf,NULL),NULL); mtx_gauge_face_import_xml(MTX_GAUGE_FACE(gauge),filename); lookup_current_value_f(firmware->te_params[table_num]->gauge_datasource, &tmpf); mtx_gauge_face_set_value(MTX_GAUGE_FACE(gauge),tmpf); g_free(filename); id = create_rtv_value_change_watch_f(firmware->te_params[table_num]->gauge_datasource,FALSE,"update_misc_gauge",(gpointer)gauge); OBJ_SET(gauge,"gauge_id",GINT_TO_POINTER(id)); gtk_container_add(GTK_CONTAINER(parent),gauge); } gtk_notebook_append_page(GTK_NOTEBOOK(notebook),widget,label); curve_parent = glade_xml_get_widget(xml,"te_right_frame"); curve = mtx_curve_new(); curve_list = g_list_prepend(curve_list,(gpointer)curve); mtx_curve_set_title(MTX_CURVE(curve),_(firmware->te_params[table_num]->title)); mtx_curve_set_x_axis_label(MTX_CURVE(curve),_(firmware->te_params[table_num]->x_axis_label)); mtx_curve_set_y_axis_label(MTX_CURVE(curve),_(firmware->te_params[table_num]->y_axis_label)); cdata = g_new0(CurveData, 1); cdata->curve = curve; cdata->axis = _X_; cdata->source = firmware->te_params[table_num]->x_source; id = create_rtv_value_change_watch_f(cdata->source,FALSE,"update_curve_marker",(gpointer)cdata); mtx_curve_set_show_x_marker(MTX_CURVE(curve),TRUE); OBJ_SET(curve,"cdata",(gpointer)cdata); OBJ_SET(curve,"marker_id",GINT_TO_POINTER(id)); mtx_curve_set_auto_hide_vertexes(MTX_CURVE(curve),TRUE); g_signal_connect(G_OBJECT(curve),"coords-changed", G_CALLBACK(coords_changed), NULL); g_signal_connect(G_OBJECT(curve),"vertex-proximity", G_CALLBACK(vertex_proximity), NULL); g_signal_connect(G_OBJECT(curve),"marker-proximity", G_CALLBACK(marker_proximity), NULL); label = glade_xml_get_widget(xml,"x_units"); gtk_label_set_markup(GTK_LABEL(label),firmware->te_params[table_num]->x_units); label = glade_xml_get_widget(xml,"y_units"); gtk_label_set_markup(GTK_LABEL(label),firmware->te_params[table_num]->y_units); label = glade_xml_get_widget(xml,"x_title"); gtk_label_set_markup(GTK_LABEL(label),firmware->te_params[table_num]->x_name); label = glade_xml_get_widget(xml,"y_title"); gtk_label_set_markup(GTK_LABEL(label),firmware->te_params[table_num]->y_name); rows = firmware->te_params[table_num]->bincount; mtx_curve_set_empty_array(MTX_CURVE(curve),rows); x_table = gtk_table_new(rows+1,1,FALSE); y_table = gtk_table_new(rows+1,1,FALSE); x_parent = glade_xml_get_widget(xml,"te_x_frame"); y_parent = glade_xml_get_widget(xml,"te_y_frame"); gtk_container_set_border_width(GTK_CONTAINER(x_table),5); gtk_container_set_border_width(GTK_CONTAINER(y_table),5); gtk_container_add(GTK_CONTAINER(x_parent),x_table); gtk_container_add(GTK_CONTAINER(y_parent),y_table); x_mult = get_multiplier_f(firmware->te_params[table_num]->x_size); y_mult = get_multiplier_f(firmware->te_params[table_num]->y_size); x_entries = g_array_new(FALSE,TRUE,sizeof(GtkWidget *)); y_entries = g_array_new(FALSE,TRUE,sizeof(GtkWidget *)); for (i=0;i<rows;i++) { /* X Column */ entry = gtk_entry_new(); OBJ_SET(entry,"last_value",GINT_TO_POINTER(-G_MAXINT)); gtk_entry_set_width_chars(GTK_ENTRY(entry),7); OBJ_SET(entry,"curve_index",GINT_TO_POINTER(i)); g_array_insert_val(x_entries,i,entry); OBJ_SET(entry,"curve_axis",GINT_TO_POINTER(_X_)); OBJ_SET(entry,"dl_type",GINT_TO_POINTER(IMMEDIATE)); OBJ_SET(entry,"handler",GINT_TO_POINTER(GENERIC)); OBJ_SET_FULL(entry,"raw_lower",g_strdup_printf("%i",(firmware->te_params[table_num]->x_raw_lower)),g_free); OBJ_SET_FULL(entry,"raw_upper",g_strdup_printf("%i",(firmware->te_params[table_num]->x_raw_upper)),g_free); OBJ_SET(entry,"fromecu_mult",firmware->te_params[table_num]->x_fromecu_mult); OBJ_SET(entry,"fromecu_add",firmware->te_params[table_num]->x_fromecu_add); OBJ_SET(entry,"precision",GINT_TO_POINTER(firmware->te_params[table_num]->x_precision)); OBJ_SET(entry,"size",GINT_TO_POINTER(firmware->te_params[table_num]->x_size)); OBJ_SET(entry,"page",GINT_TO_POINTER(firmware->te_params[table_num]->x_page)); OBJ_SET(entry,"temp_dep",GINT_TO_POINTER(firmware->te_params[table_num]->x_temp_dep)); OBJ_SET(entry,"use_color",GINT_TO_POINTER(firmware->te_params[table_num]->x_use_color)); if(firmware->te_params[table_num]->x_temp_dep) { OBJ_SET(entry,"widget_temp",DATA_GET(global_data,"mtx_temp_units")); OBJ_SET_FULL(entry,"bind_to_list", g_strdup("temperature"),g_free); bind_to_lists_f(entry,"temperature"); } offset = (i*x_mult) + firmware->te_params[table_num]->x_base; OBJ_SET(entry,"offset",GINT_TO_POINTER(offset)); g_signal_connect(G_OBJECT(entry),"changed", G_CALLBACK(update_2d_curve),curve); g_signal_connect(G_OBJECT(entry),"changed", G_CALLBACK(entry_changed_handler_f),NULL); g_signal_connect(G_OBJECT(entry),"key_press_event", G_CALLBACK(key_event_f),NULL); g_signal_connect(G_OBJECT(entry),"key_release_event", G_CALLBACK(key_event_f),NULL); g_signal_connect(G_OBJECT(entry),"focus_out_event", G_CALLBACK(focus_out_handler_f),NULL); g_signal_connect(G_OBJECT(entry),"activate", G_CALLBACK(std_entry_handler_f),NULL); if (firmware->te_params[table_num]->reversed) gtk_table_attach(GTK_TABLE(x_table),entry, 0,1,rows-i-1,rows-i, GTK_SHRINK,GTK_SHRINK,0,0); else gtk_table_attach(GTK_TABLE(x_table),entry, 0,1,i,i+1, GTK_SHRINK,GTK_SHRINK,0,0); page = firmware->te_params[table_num]->x_page; ecu_widgets[page][offset] = g_list_prepend(ecu_widgets[page][offset],(gpointer)entry); widget_list = g_list_prepend(widget_list,(gpointer)entry); update_widget(G_OBJECT(entry),NULL); /* Y Column */ entry = gtk_entry_new(); OBJ_SET(entry,"last_value",GINT_TO_POINTER(-G_MAXINT)); gtk_entry_set_width_chars(GTK_ENTRY(entry),7); OBJ_SET(entry,"curve_index",GINT_TO_POINTER(i)); g_array_insert_val(y_entries,i,entry); OBJ_SET(entry,"curve_axis",GINT_TO_POINTER(_Y_)); OBJ_SET(entry,"dl_type",GINT_TO_POINTER(IMMEDIATE)); OBJ_SET(entry,"handler",GINT_TO_POINTER(GENERIC)); OBJ_SET_FULL(entry,"raw_lower",g_strdup_printf("%i",(firmware->te_params[table_num]->y_raw_lower)),g_free); OBJ_SET_FULL(entry,"raw_upper",g_strdup_printf("%i",(firmware->te_params[table_num]->y_raw_upper)),g_free); OBJ_SET(entry,"fromecu_mult",firmware->te_params[table_num]->y_fromecu_mult); OBJ_SET(entry,"fromecu_add",firmware->te_params[table_num]->y_fromecu_add); OBJ_SET(entry,"precision",GINT_TO_POINTER(firmware->te_params[table_num]->y_precision)); OBJ_SET(entry,"size",GINT_TO_POINTER(firmware->te_params[table_num]->y_size)); OBJ_SET(entry,"page",GINT_TO_POINTER(firmware->te_params[table_num]->y_page)); OBJ_SET(entry,"temp_dep",GINT_TO_POINTER(firmware->te_params[table_num]->y_temp_dep)); OBJ_SET(entry,"use_color",GINT_TO_POINTER(firmware->te_params[table_num]->y_use_color)); if(firmware->te_params[table_num]->y_temp_dep) { OBJ_SET(entry,"widget_temp",DATA_GET(global_data,"mtx_temp_units")); OBJ_SET_FULL(entry,"bind_to_list", g_strdup("temperature"),g_free); bind_to_lists_f(entry,"temperature"); } offset = (i*y_mult) + firmware->te_params[table_num]->y_base; OBJ_SET(entry,"offset",GINT_TO_POINTER(offset)); g_signal_connect(G_OBJECT(entry),"changed", G_CALLBACK(update_2d_curve),curve); g_signal_connect(G_OBJECT(entry),"changed", G_CALLBACK(entry_changed_handler_f),NULL); g_signal_connect(G_OBJECT(entry),"key_press_event", G_CALLBACK(key_event_f),NULL); g_signal_connect(G_OBJECT(entry),"key_release_event", G_CALLBACK(key_event_f),NULL); g_signal_connect(G_OBJECT(entry),"focus_out_event", G_CALLBACK(focus_out_handler_f),NULL); g_signal_connect(G_OBJECT(entry),"activate", G_CALLBACK(std_entry_handler_f),NULL); if (firmware->te_params[table_num]->reversed) gtk_table_attach(GTK_TABLE(y_table),entry, 0,1,rows-i-1,rows-i, GTK_SHRINK,GTK_SHRINK,0,0); else gtk_table_attach(GTK_TABLE(y_table),entry, 0,1,i,i+1, GTK_SHRINK,GTK_SHRINK,0,0); page = firmware->te_params[table_num]->y_page; ecu_widgets[page][offset] = g_list_prepend(ecu_widgets[page][offset],(gpointer)entry); widget_list = g_list_prepend(widget_list,(gpointer)entry); update_widget(G_OBJECT(entry),NULL); } /* Create the "LOCK" buttons */ dummy = gtk_toggle_button_new_with_label("Unlocked"); OBJ_SET(dummy,"axis",GINT_TO_POINTER(_X_)); g_signal_connect(G_OBJECT(dummy),"toggled", G_CALLBACK(set_axis_locking),curve); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dummy),firmware->te_params[table_num]->x_lock); gtk_table_attach(GTK_TABLE(x_table),dummy, 0,1,i,i+1, GTK_EXPAND|GTK_FILL,0,0,0); dummy = gtk_toggle_button_new_with_label("Unlocked"); OBJ_SET(dummy,"axis",GINT_TO_POINTER(_Y_)); g_signal_connect(G_OBJECT(dummy),"toggled", G_CALLBACK(set_axis_locking),curve); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dummy),firmware->te_params[table_num]->y_lock); gtk_table_attach(GTK_TABLE(y_table),dummy, 0,1,i,i+1, GTK_EXPAND|GTK_FILL,0,0,0); mtx_curve_set_x_precision(MTX_CURVE(curve),firmware->te_params[table_num]->x_precision); mtx_curve_set_y_precision(MTX_CURVE(curve),firmware->te_params[table_num]->y_precision); mtx_curve_set_hard_limits(MTX_CURVE(curve), (gfloat)firmware->te_params[table_num]->x_raw_lower, (gfloat)firmware->te_params[table_num]->x_raw_upper, (gfloat)firmware->te_params[table_num]->y_raw_lower, (gfloat)firmware->te_params[table_num]->y_raw_upper); OBJ_SET(curve,"x_entries",x_entries); OBJ_SET(curve,"y_entries",y_entries); if (firmware->te_params[table_num]->bind_to_list) g_list_foreach(get_list_f(firmware->te_params[table_num]->bind_to_list),alter_widget_state_f,NULL); create_rtv_value_change_watch_f(cdata->source,TRUE,"update_curve_marker",(gpointer)cdata); gtk_container_add(GTK_CONTAINER(curve_parent),curve); } OBJ_SET(window,"widget_list",widget_list); OBJ_SET(window,"curve_list",curve_list); OBJ_SET(window,"gauge_list",gauge_list); gtk_widget_show_all(window); return TRUE; }