GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Aug 29, 2014 8:03 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Temperature and humidity graph
PostPosted: Wed Apr 08, 2009 5:19 pm 
Offline
Familiar Face

Joined: Fri Feb 20, 2009 2:09 pm
Posts: 7
Hi to all. I'm a spanish student working on his finall project. I'm a begginer programming, so don't be rude with me.

We have a dsPIC reading temperatures and humidity, saving it into a .txt. As this is hard to manage, I have the purpose of writing a gtk aplication that reads the file, takes 2 dates, and show the data contained in the file and it's between the 2 dates with a graph.
I have used a GTK assistant, a gtk_file_chooser, 2 gtk calendars and a gtk curve because of it's easyness- but the problem is that when i set the curve as a spline or linear, only interpolates 9 points, and that's not a good way to show the data :( So i think i will have to draw it by my own, but due my lack of experience and knowledgement, i can't even put a drawnable area. every single example i have seen does not compile under codeblocks (I hope someone can help with this)

But here is my example:

main.cpp

Code:
/*INCLUDES*/
#include <cairo/cairo.h>
#include <pango/pango.h>
#include <string.h>
#include <gtk/gtk.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>

//#include "demo-common.h"
#include <gtk/gtkwindow.h>
//#include "func.c"

GtkWidget* do_assistant (GtkWidget *do_widget);

gchar *parametro_1, *parametro_2, *parametro_3=NULL;

/***************************************************************************************/
/*DEFINICION DE FUNCIONES*/
/***************************************************************************************/

static GtkWidget *window = NULL;

/***************************************************************************************/
/*FUNCION PRINCIPAL*/
/***************************************************************************************/

int main(int argc, char *argv[])
{
    unsigned int i=0;
    gtk_init(&argc, &argv);

if (argc>=3)
{
    for (i=0;argv[i];i++)
    {
        printf("argumento %u: %s\n",i,argv[i]);
    }
    parametro_1 = argv[1];
    parametro_2 = argv[2];
    parametro_3 = argv[3];

    printf("hay %d argumentos\n",argc);
    printf("path encontrado %s\n",parametro_3);
}
    window = do_assistant(window);
    gtk_widget_show_all(window);
    gtk_main();
    return 0;
}

func.cpp

/***************************************************************************************/
/*INCLUDES*/
/***************************************************************************************/

#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gtk/gtkwindow.h>

struct reg_sensor {

    char nombremaquina[3];
    char fecha[12];
    char hora[12];

    double temp1,  temp2;
    double humedad1, humedad2;
    double reservado1, reservado2, reservado3, reservado4;
    double luminosidad1;
    double reservado5, reservado6, reservado7;
};

typedef struct reg_sensor registro_sensor;

unsigned int nregistro = 0;
unsigned int arraytemp[500000][3];
unsigned int fecha_inicial[3];
unsigned int fecha_final[3];
unsigned int fecha3[3];

gchar date_start[16], date_end[16];

registro_sensor *arrayRegistros=NULL;

/***************************************************************************************/
/*DEFINICION DE FUNCIONES*/
/***************************************************************************************/
gfloat vector1[30];

static void on_assistant_apply (GtkWidget *widget, gpointer data);

static void on_assistant_close_cancel (GtkWidget *widget, gpointer data);

static void on_assistant_prepare (GtkWidget *widget, GtkWidget *page, gpointer data);

static void on_entry_changed (GtkWidget *widget, gpointer data);

static void create_page1 (GtkWidget *assistant);
static void create_page2 (GtkWidget *assistant);
static void create_page3 (GtkWidget *assistant);
static void create_page4 (GtkWidget *assistant);
static void create_page5 (GtkWidget *assistant);

void seleccion(GtkCalendar *calendar,gpointer user_data);

void seleccion2(GtkCalendar *calendar,gpointer user_data);

static void curva_temp1();
static void curva_temp2();
static void curva_hume1();
static void curva_hume2();
static void curva_linear ();
static void curva_spline ();
static void curva_free ();

GtkWidget* do_assistant (GtkWidget *do_widget);

GtkWidget *assistant,*label1, *label2, *label3, *label4;

//GtkWidget*  lookup_widget              (GtkWidget       *widget,

//                                        const gchar     *widget_name);

static GtkWidget *entry  = NULL;
static GtkWidget *entry1 = NULL;
static GtkWidget *entry2 = NULL;
static GtkWidget *curva = NULL;

static gchar *path;

extern gchar *parametro_1, *parametro_2, *parametro_3;

void abrir_archivo();
void seleccionar_fecha_1();
void leer_archivo(const gchar *selected_filename);
//void ver_archivo(GtkWidget *pFileSelection, char *pFileContent);
void about();

/***************************************************************************************/
/*CREACION DEL ASISTENTE*/
/*************************************************************************************/

GtkWidget* do_assistant (GtkWidget *do_widget)
{
    entry = gtk_entry_new();

    gchar fetemp1[16], fetemp2[16], fetemp3[16];

    if (!assistant)
    {
        assistant = gtk_assistant_new ();

        gtk_window_set_default_size (GTK_WINDOW (assistant), 480, 300);
        gtk_window_set_position(GTK_WINDOW(assistant), GTK_WIN_POS_CENTER);
        //gtk_window_set_screen (GTK_WINDOW (assistant), gtk_widget_get_screen (do_widget));

        create_page1 (assistant);
        create_page2 (assistant);
        create_page3 (assistant);
        create_page4 (assistant);
        create_page5 (assistant);

        g_signal_connect (G_OBJECT (assistant), "cancel", G_CALLBACK (on_assistant_close_cancel), &assistant);
        g_signal_connect (G_OBJECT (assistant), "close", G_CALLBACK (on_assistant_close_cancel), &assistant);
        g_signal_connect (G_OBJECT (assistant), "apply", G_CALLBACK (on_assistant_apply), NULL);
        g_signal_connect (G_OBJECT (assistant), "prepare", G_CALLBACK (on_assistant_prepare), NULL);

        if (parametro_3 != NULL)
        {
            gtk_entry_set_text(GTK_ENTRY(entry), parametro_3);
            g_signal_connect (G_OBJECT (entry), "changed", G_CALLBACK (on_entry_changed), assistant);
            }
    }

       if (parametro_1 != NULL)
       {
            gtk_entry_set_text(GTK_ENTRY(entry1), parametro_1);

            fetemp1[0]=parametro_1[0];
            fetemp1[1]=parametro_1[1];
            fetemp1[2]='\0';

            fecha_inicial[0]=atoi(fetemp1);

            printf("el dia inicial pasado por parametro es: %d\n",fecha_inicial[0]);

            fetemp2[0]=parametro_1[3];
            fetemp2[1]=parametro_1[4];
            fetemp2[2]='\0';

            fecha_inicial[1]=(atoi(fetemp2));

            printf("el mes inicial pasado por parametro es: %d",fecha_inicial[1]);

            fetemp3[0] = parametro_1[6];
            fetemp3[1] = parametro_1[7];
            fetemp3[2] = parametro_1[8];
            fetemp3[3] = parametro_1[9];
            fetemp3[4] = '\0';

            fecha_inicial[2]=(atoi(fetemp3));
            printf("el anno inicial pasado por parametro es: %d\n",fecha_inicial[2]);
       }

       if (parametro_2 != NULL)
       {
            gtk_entry_set_text(GTK_ENTRY(entry2), parametro_2);

            fetemp1[0]=parametro_2[0];
            fetemp1[1]=parametro_2[1];
            fetemp1[2]='\0';

            fecha_final[0]=atoi(fetemp1);

            printf("el dia inicial pasado por parametro es: %d\n",fecha_final[0]);

            fetemp2[0]=parametro_2[3];
            fetemp2[1]=parametro_2[4];
            fetemp2[2]='\0';

            fecha_final[1]=(atoi(fetemp2));

            printf("el mes inicial pasado por parametro es: %d",fecha_final[1]);

            fetemp3[0]=parametro_2[6];
            fetemp3[1]=parametro_2[7];
            fetemp3[2]=parametro_2[8];
            fetemp3[3]=parametro_2[9];
            fetemp3[4]='\0';

            fecha_final[2]=(atoi(fetemp3));
            printf("el anno inicial pasado por parametro es: %d\n",fecha_final[2]);
       }

    if (!GTK_WIDGET_VISIBLE (assistant))
    {
        gtk_widget_show (assistant);
    }

    else
    {
        gtk_widget_destroy (assistant);
        assistant = NULL;
    }
    return assistant;
}

/***************************************************************************************/
/*ULTIMA VENTANA DEL ASISTENTE*/
/***************************************************************************************/

static void on_assistant_apply (GtkWidget *widget, gpointer data)
{
    GtkWidget *dialog;

    dialog = gtk_message_dialog_new(GTK_WINDOW(assistant),
                                    GTK_DIALOG_MODAL,
                                    GTK_MESSAGE_INFO,
                                    GTK_BUTTONS_OK,

                                    "Asistente Completado.\n\nDibujar Gr\u00E1fico");

    gtk_window_set_title(GTK_WINDOW(dialog), "Finalizar");
    gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);

    switch(gtk_dialog_run(GTK_DIALOG(dialog)))
    {
        case GTK_RESPONSE_OK: // Selección del botón "Si"

            g_print("Aceptar\n\n");
            gtk_widget_destroy(GTK_WIDGET(assistant));
            break;

        default: // Selección del botón cerrar "X"
            g_print("Cerrar\n\n");
            break;
    }
    gtk_widget_destroy(GTK_WIDGET(dialog));
}

/***************************************************************************************/
/*CERRAMOS EL ASISTENTE ANTES DE HORA*/
/***************************************************************************************/

static void on_assistant_close_cancel (GtkWidget *widget, gpointer data)
{
    GtkWidget *dialog;

    dialog = gtk_message_dialog_new(GTK_WINDOW(assistant),
                                    GTK_DIALOG_MODAL,
                                    GTK_MESSAGE_WARNING,
                                    GTK_BUTTONS_YES_NO,

                                    "\u00BFDesea salir de la aplicaci\u00F3n?");

    gtk_window_set_title(GTK_WINDOW(dialog), "Advertencia");
    gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);

    switch(gtk_dialog_run(GTK_DIALOG(dialog)))
    {
        case GTK_RESPONSE_YES: // Selección del botón "Si"
            g_print("Si\n");
            gtk_widget_destroy(GTK_WIDGET(assistant));
            break;

        case GTK_RESPONSE_NO: // Selección del botón "No"
            g_print("No \n\n");
            break;

        default: // Selección del botón cerrar "X"
            g_print("Cerrar\n\n");
            break;
    }
    gtk_widget_destroy(GTK_WIDGET(dialog));
}

/***************************************************************************************/
/*TITULO DE LA VENTANA*/
/***************************************************************************************/

static void on_assistant_prepare (GtkWidget *widget, GtkWidget *page, gpointer data)
{
    gint current_page, n_pages;
    gchar *title;

    current_page = gtk_assistant_get_current_page (GTK_ASSISTANT (widget));

    n_pages = gtk_assistant_get_n_pages (GTK_ASSISTANT (widget));

    title = g_strdup_printf ("Asistente (%d de %d)", current_page + 1, n_pages);

    gtk_window_set_title (GTK_WINDOW (widget), title);
    g_free (title);
}

/**************************************************************************************/
/***************************************************************************************/

static void on_entry_changed (GtkWidget *widget, gpointer data)
{
    GtkAssistant *assistant = GTK_ASSISTANT (data);
    GtkWidget *current_page;
    gint page_number;
    const gchar *text;

//    page_number = gtk_assistant_get_current_page (assistant);

    page_number = 1;
    current_page = gtk_assistant_get_nth_page (assistant, page_number);
    text = gtk_entry_get_text (GTK_ENTRY (widget));

    if (text && text[0])
    {
        gtk_assistant_set_page_complete (assistant, current_page, TRUE);
    }
    else
    {
        gtk_assistant_set_page_complete (assistant, current_page, FALSE);
    }
}

/***************************************************************************************/
/***************************************************************************************/

static void create_page1 (GtkWidget *assistant)
{
    GtkWidget *label;
    GdkPixbuf *pixbuf;

    label = gtk_label_new ("Este asistente le ayudar\u00E1 a mostrar gr\u00E1ficamente\nlas estad\u00EDsticas obtenidas con sus sensores.\n\nPulse adelante para continuar.");

    gtk_widget_show (label);

    gtk_assistant_append_page (GTK_ASSISTANT (assistant), label);

    gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), label, TRUE);

    gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), label, "P\u00E1gina 1: Bienvenido");

    gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), label, GTK_ASSISTANT_PAGE_INTRO);

    pixbuf = gtk_widget_render_icon (assistant, GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG, NULL);

    gtk_assistant_set_page_header_image (GTK_ASSISTANT (assistant), label, pixbuf);

    g_object_unref (pixbuf);
}


/***************************************************************************************/

/***************************************************************************************/

static void create_page2 (GtkWidget *assistant)
{
    GtkWidget *box, *label, *button, *table;

    GdkPixbuf *pixbuf;

  box = gtk_hbox_new (FALSE, 12);

  table = gtk_table_new (4, 4, FALSE);

  //gtk_table_set_col_spacing (GTK_TABLE (table), 10, 10);

  gtk_table_set_row_spacings (GTK_TABLE (table), 40);

  gtk_container_add (GTK_CONTAINER (box), table);

  gtk_container_border_width(GTK_CONTAINER (table), 24);

  label = gtk_label_new ("Seleccione el archivo:");

  g_signal_connect (G_OBJECT (entry), "changed", G_CALLBACK (on_entry_changed), assistant);

  button = gtk_button_new_with_label ("Examinar...");

  g_signal_connect (G_OBJECT(button), "clicked", G_CALLBACK(abrir_archivo), (gpointer) assistant);

  gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 2, 3);
  gtk_table_attach_defaults (GTK_TABLE (table), entry, 1, 2, 2, 3);
  gtk_table_attach_defaults (GTK_TABLE (table), button, 2, 3, 2, 3);

    gtk_widget_show_all (box);

    gtk_assistant_append_page (GTK_ASSISTANT (assistant), box);

    gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), box, "P\u00E1gina 2: Selecciona el fichero");

    gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), box, GTK_ASSISTANT_PAGE_CONTENT);
    pixbuf = gtk_widget_render_icon (assistant, GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_DIALOG, NULL);

    gtk_assistant_set_page_header_image (GTK_ASSISTANT (assistant), box, pixbuf);

    g_object_unref (pixbuf);
}

/***************************************************************************************/

/***************************************************************************************/

static void create_page3 (GtkWidget *assistant)
{
  GtkWidget *box, *calendar1, *calendar2, *table,*label1, *label2;

  GdkPixbuf *pixbuf;

  box = gtk_hbox_new (FALSE, 12);

  table = gtk_table_new (4, 4, FALSE);

  gtk_table_set_row_spacings (GTK_TABLE (table), 40);

  gtk_container_add (GTK_CONTAINER (box), table);

  gtk_container_border_width(GTK_CONTAINER (table), 24);

  label1 = gtk_label_new ("Seleccione la fecha inicial");
  label2 = gtk_label_new ("Seleccione la fecha final");

  entry1 = gtk_entry_new ();
  entry2 = gtk_entry_new ();

  g_signal_connect (G_OBJECT (entry), "changed", G_CALLBACK (on_entry_changed), assistant);

  calendar1 = gtk_calendar_new ();

  gtk_widget_set_size_request (calendar1, 241, 186);

  gtk_calendar_display_options (GTK_CALENDAR (calendar1),
                                (GtkCalendarDisplayOptions) (GTK_CALENDAR_SHOW_HEADING | GTK_CALENDAR_SHOW_DAY_NAMES) );

  g_signal_connect (G_OBJECT (calendar1), "day_selected", G_CALLBACK (seleccion), assistant);

    calendar2 = gtk_calendar_new ();

    gtk_widget_set_size_request (calendar2, 241, 186);

    gtk_calendar_display_options (GTK_CALENDAR (calendar2),
                                (GtkCalendarDisplayOptions) (GTK_CALENDAR_SHOW_HEADING | GTK_CALENDAR_SHOW_DAY_NAMES) );

    g_signal_connect ((gpointer) calendar2, "day_selected",
                    G_CALLBACK (seleccion2),   NULL);

  gtk_table_attach_defaults (GTK_TABLE (table), label1, 0, 1, 0, 1);
  gtk_table_attach_defaults (GTK_TABLE (table), label2, 1, 2, 0, 1);
  gtk_table_attach_defaults (GTK_TABLE (table), entry1, 0, 1, 1, 2);
  gtk_table_attach_defaults (GTK_TABLE (table), entry2, 1, 2, 1, 2);
  gtk_table_attach_defaults (GTK_TABLE (table), calendar1, 0, 1, 2, 3);
   gtk_table_attach_defaults (GTK_TABLE (table), calendar2, 1, 2, 2, 3);

  gtk_assistant_append_page (GTK_ASSISTANT (assistant), box);

  gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), box, TRUE);

  gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), box, "P\u00E1gina 3: Selecciona los datos");

  gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), box, GTK_ASSISTANT_PAGE_CONTENT);

  pixbuf = gtk_widget_render_icon (assistant, GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_DIALOG, NULL);

  gtk_assistant_set_page_header_image (GTK_ASSISTANT (assistant), box, pixbuf);

  g_object_unref (pixbuf);
}

/***************************************************************************************/

/***************************************************************************************/

static void create_page4_prepare (GtkWidget *assistant);


static void create_page4 (GtkWidget *assistant)
{
    GtkWidget *box, *table, *boton1, *boton2, *boton3, *boton4, *boton5, *boton6, *boton7;

    GdkPixbuf *pixbuf;

    box = gtk_vbox_new (FALSE, 12);

    table = gtk_table_new (6, 6, FALSE);

    gtk_table_set_row_spacings (GTK_TABLE (table), 40);

    gtk_container_add (GTK_CONTAINER (box), table);

    gtk_container_border_width(GTK_CONTAINER (table), 24);

    curva = gtk_curve_new();

    gtk_curve_set_range (GTK_CURVE(curva), -2, 2, -2, 2);

    label1 = gtk_label_new ("valor maximo: ");
    label2 = gtk_label_new ("valor minimo: ");
    label3 = gtk_label_new ("Fecha inicial: ");
    label4 = gtk_label_new ("Fecha final: ");

    //gtk_label_set_text (GTK_LABEL (label1), "valor maximo 2:");

    boton1 =   gtk_button_new_with_label ("Temperaturas 1");

    g_signal_connect (G_OBJECT(boton1), "clicked", G_CALLBACK(curva_temp1), (gpointer) assistant);

    boton2 =   gtk_button_new_with_label ("Temperaturas 2");

    g_signal_connect (G_OBJECT(boton2), "clicked", G_CALLBACK(curva_temp2), (gpointer) assistant);

    boton3 =   gtk_button_new_with_label ("Humedad 1");

    g_signal_connect (G_OBJECT(boton3), "clicked", G_CALLBACK(curva_hume1), (gpointer) assistant);

    boton4 =   gtk_button_new_with_label ("Humedad 2");

    g_signal_connect (G_OBJECT(boton4), "clicked", G_CALLBACK(curva_hume2), (gpointer) assistant);

    boton5 =   gtk_button_new_with_label ("linear");

    g_signal_connect (G_OBJECT(boton5), "clicked", G_CALLBACK(curva_linear), (gpointer) assistant);

    boton6 =   gtk_button_new_with_label ("spline");

    g_signal_connect (G_OBJECT(boton6), "clicked", G_CALLBACK(curva_spline), (gpointer) assistant);

    boton7 =   gtk_button_new_with_label ("free");

    g_signal_connect (G_OBJECT(boton7), "clicked", G_CALLBACK(curva_free), (gpointer) assistant);

    gtk_table_attach_defaults (GTK_TABLE (table), curva, 1, 5, 0, 4);
    gtk_table_attach_defaults (GTK_TABLE (table), label1, 0, 1, 0, 1);
    gtk_table_attach_defaults (GTK_TABLE (table), label2, 0, 1, 3, 4);
    gtk_table_attach_defaults (GTK_TABLE (table), label3, 1, 2, 4, 5);
    gtk_table_attach_defaults (GTK_TABLE (table), label4, 4, 5, 4, 5);
    gtk_table_attach_defaults (GTK_TABLE (table), boton1, 1, 2, 5, 6);
    gtk_table_attach_defaults (GTK_TABLE (table), boton2, 2, 3, 5, 6);
    gtk_table_attach_defaults (GTK_TABLE (table), boton3, 3, 4, 5, 6);
    gtk_table_attach_defaults (GTK_TABLE (table), boton4, 4, 5, 5, 6);
    gtk_table_attach_defaults (GTK_TABLE (table), boton5, 1, 2, 6, 7);
    gtk_table_attach_defaults (GTK_TABLE (table), boton6, 2, 3, 6, 7);
    gtk_table_attach_defaults (GTK_TABLE (table), boton7, 3, 4, 6, 7);

/*static void curva_linear ();

static void curva_spline ();
static void curva_interpolated ();
static void curva_free ();
*/

    g_signal_connect (G_OBJECT(assistant), "prepare", G_CALLBACK(create_page4_prepare), (gpointer) assistant);

/*
checkbutton = gtk_check_button_new_with_label ("This is optional data, you may continue even if you do not check this");

gtk_box_pack_start (GTK_BOX (box), checkbutton, FALSE, FALSE, 0);

*/
    gtk_widget_show_all (box);

    gtk_assistant_append_page (GTK_ASSISTANT (assistant), box);

    gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), box, TRUE);

    gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), box, "P\u00E1gina 4: Selecciona fechas");

    gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), box, GTK_ASSISTANT_PAGE_CONTENT);

    pixbuf = gtk_widget_render_icon (assistant, GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG, NULL);

    gtk_assistant_set_page_header_image (GTK_ASSISTANT (assistant), box, pixbuf);

    g_object_unref (pixbuf);
}

static void create_page4_prepare (GtkWidget *assistant)
{
    int page_number = gtk_assistant_get_current_page((GtkAssistant *)assistant);

    if (page_number!=3) return;

    leer_archivo(gtk_entry_get_text(GTK_ENTRY(entry)));

    curva_temp1();
}

/***************************************************************************************/

/***************************************************************************************/

static void create_page5 (GtkWidget *assistant)

{
    GtkWidget *label;
    GdkPixbuf *pixbuf;

    label = gtk_label_new ("This is a confirmation page, press 'Apply' to apply changes");

    gtk_widget_show (label);

    gtk_assistant_append_page (GTK_ASSISTANT (assistant), label);

    gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), label, TRUE);

    gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), label, "P\u00E1gina 5: Confirmaci\u00F3n");

    gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), label, GTK_ASSISTANT_PAGE_CONFIRM);

    pixbuf = gtk_widget_render_icon (assistant, GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG, NULL);

    gtk_assistant_set_page_header_image (GTK_ASSISTANT (assistant), label, pixbuf);

    g_object_unref (pixbuf);
}

/***************************************************************************************/
/* Función que muestra una explorador para seleccionar el archivo a leer */
/***************************************************************************************/

void abrir_archivo()
{
    GtkWidget *pFileSelection;

    printf("abriendo archivo %s\n",path);

    pFileSelection = gtk_file_chooser_dialog_new("Abrir archivo...",
                                                 GTK_WINDOW(assistant),
                                                 GTK_FILE_CHOOSER_ACTION_OPEN,
                                                 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                                 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
                                                 NULL);

    gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE); // Limitar las acciones a esta ventana

    //gtk_window_set_default_size(GTK_WINDOW(pFileSelection), 300, 300);

    gtk_window_position(GTK_WINDOW(pFileSelection), GTK_WIN_POS_CENTER);

    switch(gtk_dialog_run(GTK_DIALOG(pFileSelection)))
    {
        case GTK_RESPONSE_ACCEPT: // Selección del botón "Abrir"
            g_print("Abrir\n\n");
            path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection));
            gtk_entry_set_text(GTK_ENTRY(entry), path);
            break;

        case GTK_RESPONSE_CANCEL: // Selección del botón "Cancelar"
            g_print("Cancelar\n\n");
            break;

        default: // Selección del botón cerrar "X"
            g_print("Cerrar\n\n");
            break;
    }
    gtk_widget_destroy(pFileSelection);
}


double number2double(const gchar *number)
{
    double d=0;
    gchar *n = (gchar *) number;
    int i;

    for (i=0;n[i];i++)
    {
        if (n[i] == '+') n[i]='0';
        if (n[i] == ',') n[i]='.';
    }

    d=atof(n); // Espera un número de la forma 11.11 o -11.11 o 1111

    return d;
}


void procesar_campoN(const gchar *field, int ncolumna, registro_sensor *registro)
{

/*
    char nombremaquina[3];
    char fecha[12];
    char hora[12];

    double temp1, temp2;
    double humedad1, humedad2;
    double reservado1, reservado2, reservado3, reservado4;
    double luminosidad1;
    double reservado5, reservado6, reservado7;
*/
    // printf("Campo %d: %s\n",ncolumna,field);

    switch(ncolumna)
    {
        case 0:
            // registro->nombremaquina
            strcpy(registro->nombremaquina, field);
        break;

        case 1:
            // registro->fecha
            strcpy(registro->fecha, field);
        break;

        case 2:
            // registro->hora
            strcpy(registro->hora, field);
        break;

        case 3:
            registro->temp1 = number2double(field);
        break;

        case 4:
            registro->temp2 = number2double(field);
        break;

        case 5:
            registro->humedad1 = number2double(field);
        break;

        case 6:
            registro->humedad2 = number2double(field);
        break;

        case 11:
            registro->luminosidad1 = number2double(field);
        break;
    }
}


void crear_registro_sensor(const gchar *linea, registro_sensor *registro)
{
    int i, j;
    char field[25];
    int c = 0;
    int modo = 0; // 0 - texto; 1 - columna nueva.
    char cr;
    j=0;

    for (i=0;linea[i];i++)
    {
        cr = linea[i];

        if (modo == 1 && cr == ' ') continue; else modo = 0;

        // Leyendo texto

        if (cr == ' ')
        {
            // Procesar texto en var field.

            field[j] = '\0';

            procesar_campoN(field, c, registro);

            //////////////////////////////////////////

            c+=1;
            modo = 1;
            j = 0;

            continue;
        }

        // Leer texto.

        field[j++] = cr;
    }

    // Procesar texto en var field.

    field[j] = '\0';

    procesar_campoN(field, c, registro);
}


/***************************************************************************************/
/* Función que lee el formato del contenido del archivo abierto */
/***************************************************************************************/

void leer_archivo(const gchar *selected_filename)
{
    FILE *archivo;
    gchar caracter;
    gchar contenido[1024];
    static gint contador;
    registro_sensor registro;

    gchar chartemp[16], fetemp1[16], fetemp2[16], fetemp3[16];
    unsigned int i,j=0;

    if (arrayRegistros) {delete arrayRegistros;arrayRegistros=NULL;}

    arrayRegistros = new registro_sensor[200000];

    printf("Array creado");

    archivo = fopen(selected_filename, "r"); // abrir archivo como lectura "r"

    if (archivo)
    {
        g_print("Archivo seleccionado: %s\n\n", selected_filename);

        while(!feof(archivo))
        {
            caracter = getc(archivo);

            if ((caracter == '\r') || (caracter == '\n'))
            {
                contenido[contador] = '\0';
                crear_registro_sensor(contenido,&registro);
                arrayRegistros[nregistro++] = registro;

                contador = 0;
                continue;
            }
            contenido[contador] = caracter;
            contador++;
        }

        for (i=0; i <= nregistro-1; i++)
        {
            for (j=0; arrayRegistros[i].fecha[j]; j++)
            {
                chartemp[j]=arrayRegistros[i].fecha[j];
            }

/*            for (k=0;k<=1;k++)
            {
                fetemp1[k]=chartemp[k];
            }

*/
            fetemp1[0] = chartemp[0];
            fetemp1[1] = chartemp[1];
            fetemp1[2] = '\0';
            arraytemp[i][0] = atoi(fetemp1);
            fetemp2[0] = chartemp[3];
            fetemp2[1] = chartemp[4];
            fetemp2[2] = '\0';

            arraytemp[i][1] = (atoi(fetemp2));

            fetemp3[0] = chartemp[6];
            fetemp3[1] = chartemp[7];
            fetemp3[2] = chartemp[8];
            fetemp3[3] = chartemp[9];
            fetemp3[4] = '\0';

            arraytemp[i][2] = (atoi(fetemp3));
        }
    }

    else
    {
        g_print("Error al abrir el archivo: %s.\n\n", selected_filename);
    }
    g_print("Fecha inicial del archivo: %d/%2d/%d\n",arraytemp[0][0],arraytemp[0][1],arraytemp[0][2]);

    g_print("Fecha final del archivo: %d/%2d/%d\n",arraytemp[nregistro-1][0],arraytemp[nregistro-1][1],arraytemp[nregistro-1][2]);

    fclose(archivo);
}


/***************************************************************************************/
/* Función que muestra un dialogo de "Acerca de..."  */
/***************************************************************************************/

void about()
{
    GtkWidget *dialog;

    dialog = gtk_dialog_new_with_buttons("Acerca del Asistente",
                                         GTK_WINDOW (assistant),
                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                         GTK_STOCK_OK,
                                         GTK_RESPONSE_OK,
                                         NULL);

    gtk_window_set_default_size(GTK_WINDOW(dialog), 300, 300);

    gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);

    switch(gtk_dialog_run(GTK_DIALOG (dialog)))

    {
        case GTK_RESPONSE_OK: // Selección del botón "Aceptar"
            g_print("Aceptar\n\n");
            break;

        default: // Selección del botón cerrar "X"
            g_print("Cerrar\n\n");
            break;
    }

    gtk_widget_destroy(dialog);
}


/***************************************************************************************/
/* Función que lee la fecha 1 */
/***************************************************************************************/

void seleccion (GtkCalendar  *calendar,   gpointer         user_data)
{
    unsigned int anno, mes, dia;

    gtk_calendar_get_date(GTK_CALENDAR(calendar),&anno,&mes,&dia);

    sprintf(date_start, "%02d/%02d/%04d", dia,mes+1,anno);

    gtk_label_set_text (GTK_LABEL (label3), date_start);

    fecha_inicial[0]=dia;
    fecha_inicial[1]=mes+1;
    fecha_inicial[2]=anno;

    g_print("\nfecha inicial: %s\n",date_start);

    gtk_entry_set_text(GTK_ENTRY(entry1), date_start);
}

/***************************************************************************************/
/* Función que lee la fecha 2 */
/***************************************************************************************/

void seleccion2                             (GtkCalendar     *calendar,
                                        gpointer         user_data)
{
   unsigned int anno, mes, dia;

   gtk_calendar_get_date(GTK_CALENDAR(calendar),&anno,&mes,&dia);

   sprintf(date_end, "%02d/%02d/%04d", dia,mes+1,anno);

    gtk_label_set_text (GTK_LABEL (label4), date_end);

    fecha_final[0]=dia;
    fecha_final[1]=mes+1;
    fecha_final[2]=anno;

        g_print("\nfecha final: %s\n",date_end);
        gtk_entry_set_text(GTK_ENTRY(entry2), date_end);
}

void curva_temp1 ()
{
    unsigned int i, k=0;
    gfloat vector_T1[nregistro];
    gfloat valor_maximo, valor_minimo;
    char cadena_temporal[30];

    g_print("CURVA (Temperatura 1):\n\nFecha Inicial: %s\nFecha Final  : %s\n\n", date_start, date_end);

    for (i=0; i < nregistro; i++)
    {
        if ((arraytemp[i][2] >= fecha_inicial[2]) && (arraytemp[i][2] <= fecha_final[2]))
        {
            if ((arraytemp[i][1] >= fecha_inicial[1]) && (arraytemp[i][1] <= fecha_final[1]))
            {
                if ((arraytemp[i][0] >= fecha_inicial[0]) && (arraytemp[i][0] <= fecha_final[0]))
                {
                    vector_T1[k] = arrayRegistros[i].temp1;
                    k++;
                }
            }
        }
    }


    valor_maximo=vector_T1[0];
    valor_minimo=vector_T1[0];
    g_print("valor maximo: %f\n",valor_maximo);
    g_print("valor minimo: %f\n",valor_minimo);

    for (i=0;i<=k-1;i++)
    {
     if(vector_T1[i]>=valor_maximo) {valor_maximo=vector_T1[i];}
     if(vector_T1[i]<=valor_minimo) {valor_minimo=vector_T1[i];}
    }

    g_print("valor maximo: %f\n",valor_maximo);
    g_print("valor minimo: %f\n",valor_minimo);

    sprintf(cadena_temporal,"Valor maximo: %2.2f",valor_maximo);

    gtk_label_set_text (GTK_LABEL (label1), cadena_temporal);

    sprintf(cadena_temporal,"Valor minimo: %2.2f",valor_minimo);

    gtk_label_set_text (GTK_LABEL (label2), cadena_temporal);

    gtk_curve_set_range (GTK_CURVE(curva), 0, k-1, valor_minimo, valor_maximo);

    gtk_curve_set_vector (GTK_CURVE(curva), k-1, vector_T1);
}

void curva_temp2 ()
{
    unsigned int i,k=0;
    gfloat vector_T2[nregistro];
    gfloat valor_maximo, valor_minimo;
    char cadena_temporal[30];

    g_print("CURVA (Temperatura 1):\n\nFecha Inicial: %s\nFecha Final  : %s\n\n", date_start, date_end);

    for (i=0; i < nregistro; i++)
    {
        if ((arraytemp[i][2] >= fecha_inicial[2]) && (arraytemp[i][2] <= fecha_final[2]))
        {
            if ((arraytemp[i][1] >= fecha_inicial[1]) && (arraytemp[i][1] <= fecha_final[1]))
            {
                if ((arraytemp[i][0] >= fecha_inicial[0]) && (arraytemp[i][0] <= fecha_final[0]))
                {
                    vector_T2[k] = arrayRegistros[i].temp2;
                    k++;
                }
            }
        }
    }

    valor_maximo=vector_T2[0];
    valor_minimo=vector_T2[0];

    g_print("valor maximo: %f\n",valor_maximo);
    g_print("valor minimo: %f\n",valor_minimo);

    for (i=0;i<=k-1;i++)
    {
     if(vector_T2[i]>=valor_maximo) {valor_maximo=vector_T2[i];}
     if(vector_T2[i]<=valor_minimo) {valor_minimo=vector_T2[i];}
    }

    g_print("valor maximo: %f\n",valor_maximo);
    g_print("valor minimo: %f\n",valor_minimo);

    sprintf(cadena_temporal,"Valor minimo: %2.2f",valor_maximo);

    gtk_label_set_text (GTK_LABEL (label1), cadena_temporal);

    sprintf(cadena_temporal,"Valor minimo: %2.2f",valor_minimo);

    gtk_label_set_text (GTK_LABEL (label2), cadena_temporal);

    gtk_curve_set_range (GTK_CURVE(curva), 0, k-1, valor_minimo, valor_maximo);

    gtk_curve_set_vector (GTK_CURVE(curva), k-1, vector_T2);
}

void curva_hume1 ()
{
    unsigned int i,k=0;
    gfloat vector_H1[nregistro];
    gfloat valor_maximo, valor_minimo;
    char cadena_temporal[30];

    g_print("CURVA (Temperatura 1):\n\nFecha Inicial: %s\nFecha Final  : %s\n\n", date_start, date_end);

    for (i=0; i < nregistro; i++)
    {
        if ((arraytemp[i][2] >= fecha_inicial[2]) && (arraytemp[i][2] <= fecha_final[2]))
        {
            if ((arraytemp[i][1] >= fecha_inicial[1]) && (arraytemp[i][1] <= fecha_final[1]))
            {
                if ((arraytemp[i][0] >= fecha_inicial[0]) && (arraytemp[i][0] <= fecha_final[0]))
                {
                    vector_H1[k] = arrayRegistros[i].humedad1;
                    k++;
                }
            }
        }
    }

    valor_maximo=vector_H1[0];
    valor_minimo=vector_H1[0];
    g_print("valor maximo: %f\n",valor_maximo);
    g_print("valor minimo: %f\n",valor_minimo);

    for (i=0;i<=k-1;i++)
    {
     if(vector_H1[i]>=valor_maximo) {valor_maximo=vector_H1[i];}
     if(vector_H1[i]<=valor_minimo) {valor_minimo=vector_H1[i];}
    }

    g_print("valor maximo: %f\n",valor_maximo);
    g_print("valor minimo: %f\n",valor_minimo);

    sprintf(cadena_temporal,"Valor minimo: %2.2f",valor_maximo);

    gtk_label_set_text (GTK_LABEL (label1), cadena_temporal);

    sprintf(cadena_temporal,"Valor minimo: %2.2f",valor_minimo);

    gtk_label_set_text (GTK_LABEL (label2), cadena_temporal);

    gtk_curve_set_range (GTK_CURVE(curva), 0, k-1, valor_minimo, valor_maximo);

    gtk_curve_set_vector (GTK_CURVE(curva), k-1, vector_H1);
}


void curva_hume2 ()
{
    unsigned int i, k=0;
    gfloat vector_H2[nregistro];
    gfloat valor_maximo, valor_minimo;
    char cadena_temporal[30];
    g_print("CURVA (Temperatura 1):\n\nFecha Inicial: %s\nFecha Final  : %s\n\n", date_start, date_end);

    for (i=0; i < nregistro; i++)
    {
        if ((arraytemp[i][2] >= fecha_inicial[2]) && (arraytemp[i][2] <= fecha_final[2]))
        {
            if ((arraytemp[i][1] >= fecha_inicial[1]) && (arraytemp[i][1] <= fecha_final[1]))
            {
                if ((arraytemp[i][0] >= fecha_inicial[0]) && (arraytemp[i][0] <= fecha_final[0]))
                {
                    vector_H2[k] = arrayRegistros[i].humedad2;
                    k++;
                }
            }
        }
    }

    valor_maximo=vector_H2[0];
    valor_minimo=vector_H2[0];

    g_print("valor maximo: %f\n",valor_maximo);
    g_print("valor minimo: %f\n",valor_minimo);

    for (i=0;i<=k-1;i++)
    {
     if(vector_H2[i]>=valor_maximo) {valor_maximo=vector_H2[i];}
     if(vector_H2[i]<=valor_minimo) {valor_minimo=vector_H2[i];}
    }

    g_print("valor maximo: %f\n",valor_maximo);
    g_print("valor minimo: %f\n",valor_minimo);

    sprintf(cadena_temporal,"Valor minimo: %2.2f",valor_maximo);

    gtk_label_set_text (GTK_LABEL (label1), cadena_temporal);

    sprintf(cadena_temporal,"Valor minimo: %2.2f",valor_minimo);

    gtk_label_set_text (GTK_LABEL (label2), cadena_temporal);

    gtk_curve_set_range (GTK_CURVE(curva), 0, k-1, valor_minimo, valor_maximo);

    gtk_curve_set_vector (GTK_CURVE(curva), k-1, vector_H2);
}

//linear, spline interpolated, or free

void curva_linear ()
{
    gtk_curve_set_curve_type(GTK_CURVE(curva), GTK_CURVE_TYPE_LINEAR);
}

void curva_spline ()
{
    gtk_curve_set_curve_type(GTK_CURVE(curva), GTK_CURVE_TYPE_SPLINE);
}

void curva_free ()
{
    gtk_curve_set_curve_type(GTK_CURVE(curva), GTK_CURVE_TYPE_FREE);
}


Any sugestions about the curve???


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 09, 2009 4:03 am 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
Hi

can i have complete code.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 09, 2009 2:16 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello.

GtkCurve widget is considered too specialized to be included in Gtk+ and is not maintained properly (it waits to be added to some 3rd party package).

I'm not sure why would this widget interpolate only first 9 points, but I didn't manage to get it working on my machine at all, so I cannot investigate it further.

And to assist you with writing your display widget, I created simple application that will show you how to create your own graphs using cairo library. I didn't comment it, since I'm really short with spare time, but if you have any questions, post back.

Usage instructons: Clicking on a drawing area will place points there. Shift clicking on a point will remove it. And that's it.

Code:
#include <gtk/gtk.h>

enum
{
   SPLINE_NONE = 0,
   SPLINE_LINE,
   SPLINE_CATMULL_ROM,
   NO_TYPES
};

typedef struct _Data Data;
struct _Data
{
   GArray    *points;
   gboolean   visible[NO_TYPES];
   gdouble    spline_factor;
   GtkWidget *draw;
};

static void
cb_value( GtkSpinButton *button,
        Data          *data )
{
   data->spline_factor = gtk_spin_button_get_value( button );
   gtk_widget_queue_draw( data->draw );
}

static void
cb_toggled( GtkToggleButton *button,
         Data            *data )
{
   gint index =
      GPOINTER_TO_INT( g_object_get_data( G_OBJECT( button ), "type" ) );

   data->visible[index] = gtk_toggle_button_get_active( button );

   gtk_widget_queue_draw( data->draw );
}

static void
draw_points( cairo_t *cr,
          gdouble *coords,
          gint     size )
{
   gint i;

   cairo_set_source_rgb( cr, 1, 0, 0 );
   for( i = 0; i < size; i += 2 )
   {
      cairo_move_to( cr, coords[i], coords[i + 1] );
      cairo_arc( cr, coords[i], coords[i + 1], 2, 0, 2 * G_PI );
   }
   cairo_stroke( cr );
}

static void
draw_line( cairo_t *cr,
         gdouble *coords,
         gint     size )
{
   gint i;

   cairo_set_source_rgb( cr, 0, 0, 1 );
   cairo_move_to( cr, coords[0], coords[1] );
   for( i = 2; i < size; i += 2 )
   {
      cairo_line_to( cr, coords[i], coords[i + 1] );
   }
   cairo_stroke( cr );
}

static void
draw_catmull_rom( cairo_t *cr,
              gdouble *coords,
              gint     size,
              double   spline_factor )
{
   gint i;
   gdouble ctrl_points[4];

   /* Initial calculations */
   ctrl_points[2] = ( coords[2] - coords[0] ) / spline_factor;
   ctrl_points[3] = ( coords[3] - coords[1] ) / spline_factor;

   cairo_set_source_rgb( cr, 0, 1, 0 );
   cairo_move_to( cr, coords[0], coords[1] );
   for( i = 2; i < size - 2; i += 2 )
   {
      ctrl_points[0] = ctrl_points[2];
      ctrl_points[1] = ctrl_points[3];
      ctrl_points[2] = ( coords[i + 2] - coords[i - 2] ) / spline_factor;
      ctrl_points[3] = ( coords[i + 3] - coords[i - 1] ) / spline_factor;

      cairo_curve_to( cr, coords[i - 2] + ctrl_points[0],
                     coords[i - 1] + ctrl_points[1],
                     coords[i]     - ctrl_points[2],
                     coords[i + 1] - ctrl_points[3],
                     coords[i],
                     coords[i + 1] );
   }

   /* Draw the last segment */
   ctrl_points[0] = ctrl_points[2];
   ctrl_points[1] = ctrl_points[3];
   ctrl_points[2] = ( coords[i] - coords[i - 2] ) / spline_factor;
   ctrl_points[3] = ( coords[i + 1] - coords[i - 1] ) / spline_factor;

   cairo_curve_to( cr, coords[i - 2] + ctrl_points[0],
                  coords[i - 1] + ctrl_points[1],
                  coords[i]     - ctrl_points[2],
                  coords[i + 1] - ctrl_points[3],
                  coords[i],
                  coords[i + 1] );

   cairo_stroke( cr );
}

static gboolean
cb_expose( GtkWidget      *draw,
         GdkEventExpose *expose,
         Data           *data )
{
   cairo_t  *cr;
   gdouble  *coords;
   gint      i;

   if( data->points->len == 0 )
      return( FALSE );

   /* Draw spline */
   cr = gdk_cairo_create( draw->window );
   cairo_set_line_width( cr, 5 );

   coords = (gdouble *)data->points->data;

   /* Special case - if only one point is present, draw it no matter what
    * spline type is set. */
   if( data->points->len == 2 && data->visible[SPLINE_NONE] )
   {
      draw_points( cr, coords, data->points->len );
      cairo_destroy( cr );
      return( FALSE );
   }

   if( data->visible[SPLINE_LINE] )
      draw_line( cr, coords, data->points->len );

   if( data->visible[SPLINE_CATMULL_ROM] )
      draw_catmull_rom( cr, coords, data->points->len, data->spline_factor );

   if( data->visible[SPLINE_NONE] )
      draw_points( cr, coords, data->points->len );
   
   cairo_destroy( cr );

   return( FALSE );
}

static gboolean
cb_press( GtkWidget      *draw,
        GdkEventButton *event,
        Data           *data )
{
   if( event->state & GDK_SHIFT_MASK )
   {
      gint     i;
      gdouble *coords = (gdouble *)data->points->data;

      for( i = 0; i < data->points->len - 1; i += 2 )
      {
         if( event->x > ( coords[i] - 5 ) &&
            event->x < ( coords[i] + 5 ) )
         {
            if( event->y > ( coords[i + 1] - 5 ) &&
               event->y < ( coords[i + 1] + 5 ) )
            {
               g_print( "Delete point at (%f, %f)\n", event->x, event->y );
               g_array_remove_range( data->points, i, 2 );
               break;
            }
         }
      }
   }
   else
   {
      gdouble point[] = { event->x, event->y };

      g_print( "Create point at (%f, %f)\n", event->x, event->y );
      g_array_append_vals( data->points, (gconstpointer)point, 2 );
   }

   gtk_widget_queue_draw( draw );

   return( TRUE );
}

int
main( int    argc,
     char **argv )
{
   GtkWidget *window;
   GtkWidget *hbox;
   GtkWidget *vbox, *vbox_main;
   GtkWidget *frame;
   GtkWidget *button;
   GtkWidget *draw;
   Data       data;


   data.points = g_array_sized_new( FALSE, FALSE, sizeof( gdouble ), 10 );
   data.spline_factor = 5;
   data.visible[0] = TRUE;
   data.visible[1] = TRUE;
   data.visible[2] = FALSE;

   gtk_init( &argc, &argv );

   window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
   gtk_window_set_default_size( GTK_WINDOW( window ), 400, 300 );
   g_signal_connect( G_OBJECT( window ), "destroy",
                 G_CALLBACK( gtk_main_quit ), NULL );

   hbox = gtk_hbox_new( FALSE, 6 );
   gtk_container_add( GTK_CONTAINER( window ), hbox );

   frame = gtk_frame_new( "Drawing area" );
   gtk_box_pack_start( GTK_BOX( hbox ), frame, TRUE, TRUE, 0 );

   draw = gtk_drawing_area_new();
   data.draw = draw;
   gtk_widget_add_events( draw, GDK_BUTTON_PRESS_MASK );
   g_signal_connect( G_OBJECT( draw ), "expose-event",
                 G_CALLBACK( cb_expose ), &data );
   g_signal_connect( G_OBJECT( draw ), "button-press-event",
                 G_CALLBACK( cb_press ), &data );
   gtk_container_add( GTK_CONTAINER( frame ), draw );

   vbox_main = gtk_vbox_new( FALSE, 6 );
   gtk_box_pack_start( GTK_BOX( hbox ), vbox_main, FALSE, FALSE, 0 );

   /* Interpolation type */
   frame = gtk_frame_new( "Interpolation" );
   gtk_box_pack_start( GTK_BOX( vbox_main ), frame, FALSE, FALSE, 0 );

   vbox = gtk_vbox_new( TRUE, 6 );
   gtk_container_add( GTK_CONTAINER( frame ), vbox );

   button = gtk_check_button_new_with_label( "Points" );
   gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), TRUE );
   g_object_set_data( G_OBJECT( button ), "type",
                  GINT_TO_POINTER( SPLINE_NONE ) );
   g_signal_connect( G_OBJECT( button ), "toggled",
                 G_CALLBACK( cb_toggled ), &data );
   gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );

   button = gtk_check_button_new_with_label( "Lines" );
   gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), TRUE );
   g_object_set_data( G_OBJECT( button ), "type",
                  GINT_TO_POINTER( SPLINE_LINE ) );
   g_signal_connect( G_OBJECT( button ), "toggled",
                 G_CALLBACK( cb_toggled ), &data );
   gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );

   button = gtk_check_button_new_with_label( "Cardinal spline" );
   g_object_set_data( G_OBJECT( button ), "type",
                  GINT_TO_POINTER( SPLINE_CATMULL_ROM ) );
   g_signal_connect( G_OBJECT( button ), "toggled",
                 G_CALLBACK( cb_toggled ), &data );
   gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );

   /* Spline factor */
   frame = gtk_frame_new( "Cardinal spline factor" );
   gtk_box_pack_start( GTK_BOX( vbox_main ), frame, FALSE, FALSE, 0 );

   button = gtk_spin_button_new_with_range( 0.1, 100, 0.1 );
   gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( button ), TRUE );
   gtk_spin_button_set_value( GTK_SPIN_BUTTON( button ), 5. );
   g_signal_connect( G_OBJECT( button ), "value-changed",
                 G_CALLBACK( cb_value ), &data );
   gtk_container_add( GTK_CONTAINER( frame ), button );


   gtk_widget_show_all( window );

   gtk_main();

   g_array_free( data.points, TRUE );

   return( 0 );
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 17, 2009 7:23 pm 
Offline
Familiar Face

Joined: Fri Feb 20, 2009 2:09 pm
Posts: 7
If you want my newest code, just email me to psaval@hotmail.com

And thanks for your code, is impressive, i will make good use of it. Thanks again, i'm gratefull.

P.D.: Sorry for my english, but i'm spanish


Top
 Profile  
 
 Post subject: Re: Temperature and humidity graph
PostPosted: Thu Mar 24, 2011 3:07 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
For graphing there is some plotting widgets contained in GtkExtra. I have also developed a few plotting widgets customised for scientific publication quality graphing that you nick, modify as need be and link into if your code is GPL. You'll have to do the interpolation of the data beforehand. One warning though is that the code is a bit on the heavy side, but it runs fast. I think it leaks memory a bit but am working on cleaning that up. You can get the data and a sample program at https://github.com/pchilds/GtkPlot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group