Thread: [Gpredict-svn] SF.net SVN: gpredict: [3] trunk/src
Real time satellite tracking and orbit prediction
Status: Beta
Brought to you by:
csete
From: <cs...@us...> - 2008-01-12 13:15:07
|
Revision: 3 http://gpredict.svn.sourceforge.net/gpredict/?rev=3&view=rev Author: csete Date: 2008-01-12 05:15:12 -0800 (Sat, 12 Jan 2008) Log Message: ----------- Added parameter for radio type (RX, TX, TRX, FULL_DUP). Modified Paths: -------------- trunk/src/radio-conf.c trunk/src/radio-conf.h Modified: trunk/src/radio-conf.c =================================================================== --- trunk/src/radio-conf.c 2008-01-08 22:51:02 UTC (rev 2) +++ trunk/src/radio-conf.c 2008-01-12 13:15:12 UTC (rev 3) @@ -38,6 +38,7 @@ #define KEY_MFG "Company" #define KEY_MODEL "Model" #define KEY_ID "ID" +#define KEY_TYPE "Type" #define KEY_PORT "Port" #define KEY_SPEED "Speed" #define KEY_CIV "CIV" @@ -45,12 +46,13 @@ #define KEY_RTS "RTS" -/** \brief REad radio configuration. +/** \brief Read radio configuration. * \param conf Pointer to a radio_conf_t structure where the data will be * stored. * + * This function reads a radio configuration from a .rig file into conf. * conf->name must contain the file name of the configuration (no path, just - * file). + * file name). */ gboolean radio_conf_read (radio_conf_t *conf) { @@ -87,6 +89,7 @@ conf->company = g_key_file_get_string (cfg, GROUP, KEY_MFG, NULL); conf->model = g_key_file_get_string (cfg, GROUP, KEY_MODEL, NULL); conf->id = g_key_file_get_integer (cfg, GROUP, KEY_ID, NULL); + conf->type = g_key_file_get_integer (cfg, GROUP, KEY_TYPE, NULL); conf->port = g_key_file_get_string (cfg, GROUP, KEY_PORT, NULL); conf->speed = g_key_file_get_integer (cfg, GROUP, KEY_SPEED, NULL); conf->civ = g_key_file_get_integer (cfg, GROUP, KEY_CIV, NULL); @@ -99,6 +102,13 @@ } +/** \brief Save radio configuration. + * \param conf Pointer to the radio configuration. + * + * This function saves the radio configuration stored in conf to a + * .rig file. conf->name must contain the file name of the configuration + * (no path, just file name). + */ void radio_conf_save (radio_conf_t *conf) { GKeyFile *cfg = NULL; @@ -115,7 +125,8 @@ g_key_file_set_string (cfg, GROUP, KEY_MFG, conf->company); g_key_file_set_string (cfg, GROUP, KEY_MODEL, conf->model); - g_key_file_set_integer (cfg, GROUP, KEY_MFG, conf->id); + g_key_file_set_integer (cfg, GROUP, KEY_ID, conf->id); + g_key_file_set_integer (cfg, GROUP, KEY_TYPE, conf->type); g_key_file_set_string (cfg, GROUP, KEY_PORT, conf->port); g_key_file_set_integer (cfg, GROUP, KEY_SPEED, conf->speed); g_key_file_set_integer (cfg, GROUP, KEY_CIV, conf->civ); Modified: trunk/src/radio-conf.h =================================================================== --- trunk/src/radio-conf.h 2008-01-08 22:51:02 UTC (rev 2) +++ trunk/src/radio-conf.h 2008-01-12 13:15:12 UTC (rev 3) @@ -34,24 +34,35 @@ - +/** \brief RS232 control line usage definitions. */ typedef enum { - LINE_OFF = 0, - LINE_ON, - LINE_PTT, - LINE_CW + LINE_OFF = 0, /*!< Line should be permanently OFF. */ + LINE_ON, /*!< Line should be permanently ON. */ + LINE_PTT, /*!< Line used for PTT control. */ + LINE_CW /*!< Line used for CW keying. */ } ctrl_stat_t; + +/** \brief Radio type definitions. */ +typedef enum { + RADIO_TYPE_RX = 0, /*!< Radio used as receiver only. */ + RADIO_TYPE_TX, /*!< Radio used as TX only. */ + RADIO_TYPE_TRX, /*!< Radio use as both TX and RX. */ + RADIO_TYPE_FULL_DUP /*!< Full duplex radio. */ +} radio_type_t; + +/** \brief Radio configuration. */ typedef struct { - gchar *name; - gchar *company; - gchar *model; - guint id; - gchar *port; - guint speed; - guint civ; - ctrl_stat_t dtr; - ctrl_stat_t rts; + gchar *name; /*!< Configuration file name. */ + gchar *company; /*!< Manufacturer, e.g. ICOM. */ + gchar *model; /*!< Radio model, e.g. IC-910H. */ + guint id; /*!< Hamlib ID. */ + radio_type_t type; /*!< Radio type. */ + gchar *port; /*!< Device name, e.g. /dev/ttyS0. */ + guint speed; /*!< Serial speed. */ + guint civ; /*!< ICOM CI-V address. */ + ctrl_stat_t dtr; /*!< DTR line usage. */ + ctrl_stat_t rts; /*!< PTT line usage. */ } radio_conf_t; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-01-12 22:55:41
|
Revision: 5 http://gpredict.svn.sourceforge.net/gpredict/?rev=5&view=rev Author: csete Date: 2008-01-12 14:55:47 -0800 (Sat, 12 Jan 2008) Log Message: ----------- Added files. Modified Paths: -------------- trunk/src/Makefile.am Added Paths: ----------- trunk/src/sat-pref-rig-editor.c trunk/src/sat-pref-rig-editor.h Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2008-01-12 15:49:06 UTC (rev 4) +++ trunk/src/Makefile.am 2008-01-12 22:55:47 UTC (rev 5) @@ -90,6 +90,7 @@ sat-pref-single-sat.c sat-pref-single-sat.h \ sat-pref-interfaces.c sat-pref-interfaces.h \ sat-pref-rig.c sat-pref-rig.h sat-pref-rig-data.h \ + sat-pref-rig-editor.c sat-pref-rig-editor.h \ sat-pref-rot.c sat-pref-rot.h \ sat-pref-predict.c sat-pref-predict.h \ sat-pref-conditions.c sat-pref-conditions.h \ Added: trunk/src/sat-pref-rig-editor.c =================================================================== --- trunk/src/sat-pref-rig-editor.c (rev 0) +++ trunk/src/sat-pref-rig-editor.c 2008-01-12 22:55:47 UTC (rev 5) @@ -0,0 +1,293 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + Gpredict: Real-time satellite tracking and orbit prediction program + + Copyright (C) 2001-2007 Alexandru Csete, OZ9AEC. + + Authors: Alexandru Csete <oz...@gm...> + + Comments, questions and bugreports should be submitted via + http://sourceforge.net/projects/groundstation/ + More details can be found at the project home page: + + http://groundstation.sourceforge.net/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, visit http://www.fsf.org/ +*/ + +/** \brief Edit radio configuration. + * + */ + +#include <gtk/gtk.h> +#include <glib/gi18n.h> +#include <glib/gstdio.h> +#include <math.h> +#ifdef HAVE_CONFIG_H +# include <build-config.h> +#endif +#include "gpredict-utils.h" +#include "sat-cfg.h" +#include "sat-log.h" +#include "radio-conf.h" +#include "sat-pref-rig-editor.h" + + + + +extern GtkWidget *window; /* dialog window defined in sat-pref.c */ + + + +/* private widgets */ +static GtkWidget *dialog; /* dialog window */ +static GtkWidget *name; /* Configuration name */ + + + +static GtkWidget *create_editor_widgets (radio_conf_t *conf); +static void update_widgets (radio_conf_t *conf); +static void clear_widgets (void); +static gboolean apply_changes (radio_conf_t *conf); +static void name_changed (GtkWidget *widget, gpointer data); + +/** \brief Add or edit a radio configuration. + * \param conf Pointer to a radio configuration. + * + * Of conf->name is not NULL the widgets will be populated with the data. + */ +void +sat_pref_rig_editor_run (radio_conf_t *conf) +{ + gint response; + gboolean finished = FALSE; + + + /* crate dialog and add contents */ + dialog = gtk_dialog_new_with_buttons (_("Edit radio configuration"), + GTK_WINDOW (window), + GTK_DIALOG_MODAL | + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CLEAR, + GTK_RESPONSE_REJECT, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, + GTK_RESPONSE_OK, + NULL); + + /* disable OK button to begin with */ + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), + GTK_RESPONSE_OK, + FALSE); + + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), + create_editor_widgets (conf)); + + /* this hacky-thing is to keep the dialog running in case the + CLEAR button is plressed. OK and CANCEL will exit the loop + */ + while (!finished) { + + response = gtk_dialog_run (GTK_DIALOG (dialog)); + + switch (response) { + + /* OK */ + case GTK_RESPONSE_OK: + if (apply_changes (conf)) { + finished = TRUE; + } + else { + finished = FALSE; + } + break; + + /* CLEAR */ + case GTK_RESPONSE_REJECT: + clear_widgets (); + break; + + /* Everything else is considered CANCEL */ + default: + finished = TRUE; + break; + } + } + + gtk_widget_destroy (dialog); +} + + +/** \brief Create and initialise widgets */ +static GtkWidget * +create_editor_widgets (radio_conf_t *conf) +{ + GtkWidget *table; + GtkWidget *label; + + + table = gtk_table_new (6, 4, FALSE); + gtk_container_set_border_width (GTK_CONTAINER (table), 5); + gtk_table_set_col_spacings (GTK_TABLE (table), 5); + gtk_table_set_row_spacings (GTK_TABLE (table), 5); + + /* Config name */ + label = gtk_label_new (_("Name")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 0, 1); + + name = gtk_entry_new (); + gtk_entry_set_max_length (GTK_ENTRY (name), 25); + gtk_widget_set_tooltip_text (name, + _("Enter a short name for this configuration, e.g. IC910-1.\n"\ + "Allowed charachters: 0..9, a..z, A..Z, - and _")); + gtk_table_attach_defaults (GTK_TABLE (table), name, 1, 4, 0, 1); + + /* attach changed signal so that we can enable OK button when + a proper name has been entered + */ + g_signal_connect (name, "changed", G_CALLBACK (name_changed), NULL); + + /* Manufacturer */ + label = gtk_label_new (_("Manufacturer")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2); + + //gtk_table_attach_defaults (GTK_TABLE (table), desc, 1, 4, 1, 2); + + /* Model */ + label = gtk_label_new (_("Model")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 2, 3); + + + + /* Type */ + label = gtk_label_new (_("Type")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 3, 4); + + /* Port */ + label = gtk_label_new (_("Port")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 4, 5); + + /* Speed */ + label = gtk_label_new (_("Rate")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 5, 6); + + if (conf->name != NULL) + update_widgets (conf); + + gtk_widget_show_all (table); + + return table; +} + + +/** \brief Update widgets from the currently selected row in the treeview + */ +static void +update_widgets (radio_conf_t *conf) +{ +} + + + +/** \brief Clear the contents of all widgets. + * + * This function is usually called when the user clicks on the CLEAR button + * + */ +static void +clear_widgets () +{ +} + + +/** \brief Apply changes. + * \return TRUE if things are ok, FALSE otherwise. + * + * This function is usually called when the user clicks the OK button. + */ +static gboolean +apply_changes (radio_conf_t *conf) +{ + + return TRUE; +} + + + +/** \brief Manage name changes. + * + * This function is called when the contents of the name entry changes. + * The primary purpose of this function is to check whether the char length + * of the name is greater than zero, if yes enable the OK button of the dialog. + */ +static void +name_changed (GtkWidget *widget, gpointer data) +{ + const gchar *text; + gchar *entry, *end, *j; + gint len, pos; + + + /* step 1: ensure that only valid characters are entered + (stolen from xlog, tnx pg4i) + */ + entry = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1); + if ((len = g_utf8_strlen (entry, -1)) > 0) + { + end = entry + g_utf8_strlen (entry, -1); + for (j = entry; j < end; ++j) + { + switch (*j) + { + case '0' ... '9': + case 'a' ... 'z': + case 'A' ... 'Z': + case '-': + case '_': + break; + default: + gdk_beep (); + pos = gtk_editable_get_position (GTK_EDITABLE (widget)); + gtk_editable_delete_text (GTK_EDITABLE (widget), + pos, pos+1); + break; + } + } + } + + + /* step 2: if name seems all right, enable OK button */ + text = gtk_entry_get_text (GTK_ENTRY (widget)); + + if (g_utf8_strlen (text, -1) > 0) { + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), + GTK_RESPONSE_OK, + TRUE); + } + else { + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), + GTK_RESPONSE_OK, + FALSE); + } +} + + + Added: trunk/src/sat-pref-rig-editor.h =================================================================== --- trunk/src/sat-pref-rig-editor.h (rev 0) +++ trunk/src/sat-pref-rig-editor.h 2008-01-12 22:55:47 UTC (rev 5) @@ -0,0 +1,38 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + Gpredict: Real-time satellite tracking and orbit prediction program + + Copyright (C) 2001-2007 Alexandru Csete, OZ9AEC. + + Authors: Alexandru Csete <oz...@gm...> + + Comments, questions and bugreports should be submitted via + http://sourceforge.net/projects/groundstation/ + More details can be found at the project home page: + + http://groundstation.sourceforge.net/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, visit http://www.fsf.org/ +*/ +#ifndef SAT_PREF_RIG_EDITOR_H +#define SAT_PREF_RIG_EDITOR_H 1 + +#include <gtk/gtk.h> +#include "radio-conf.h" + + +void sat_pref_rig_editor_run (radio_conf_t *conf); + + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-01-24 18:29:34
|
Revision: 12 http://gpredict.svn.sourceforge.net/gpredict/?rev=12&view=rev Author: csete Date: 2008-01-24 10:29:33 -0800 (Thu, 24 Jan 2008) Log Message: ----------- Finished rig configuration editor. Modified Paths: -------------- trunk/src/sat-pref-rig-editor.c trunk/src/sat-pref-rig-editor.h Modified: trunk/src/sat-pref-rig-editor.c =================================================================== --- trunk/src/sat-pref-rig-editor.c 2008-01-22 23:13:00 UTC (rev 11) +++ trunk/src/sat-pref-rig-editor.c 2008-01-24 18:29:33 UTC (rev 12) @@ -43,10 +43,10 @@ #include "radio-conf.h" #include "sat-pref-rig-editor.h" +#ifdef HAVE_HAMLIB +# include <hamlib/rig.h> -#include <hamlib/rig.h> - extern GtkWidget *window; /* dialog window defined in sat-pref.c */ @@ -55,6 +55,7 @@ static GtkWidget *dialog; /* dialog window */ static GtkWidget *name; /* Configuration name */ static GtkWidget *model; /* radio model, e.g. TS-2000 */ +static GtkWidget *civ; /* Icom CI-V address */ static GtkWidget *type; /* radio type */ static GtkWidget *port; /* port selector */ static GtkWidget *speed; /* serial speed selector */ @@ -75,6 +76,7 @@ GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data); +static void select_rig (guint rigid); /** \brief Add or edit a radio configuration. @@ -153,6 +155,8 @@ GtkWidget *label; GtkTreeModel *riglist; GtkCellRenderer *renderer; + gchar *buff; + guint i; table = gtk_table_new (5, 5, FALSE); @@ -197,8 +201,31 @@ is_rig_model, NULL, NULL); gtk_widget_set_tooltip_text (model, _("Click to select a radio.")); + select_rig (1); + /* ICOM CI-V adress */ + label = gtk_label_new (_("ICOM CI-V")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 3, 4, 1, 2); + + civ = gtk_combo_box_new_text (); + gtk_widget_set_tooltip_text (civ, + _("Select ICOM CI-V address of the radio.")); + + /* works, but pretty lame... */ + gtk_combo_box_append_text (GTK_COMBO_BOX (civ), _("Default")); + for (i = 1; i < 0xF0; i++) { + if (i < 0x10) + buff = g_strdup_printf ("0x0%X", i); + else + buff = g_strdup_printf ("0x%X", i); + gtk_combo_box_append_text (GTK_COMBO_BOX (civ), buff); + g_free (buff); + } + gtk_combo_box_set_active (GTK_COMBO_BOX (civ), 0); + gtk_table_attach_defaults (GTK_TABLE (table), civ, 4, 5, 1, 2); + /* Type */ label = gtk_label_new (_("Type")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); @@ -282,7 +309,7 @@ gtk_table_attach_defaults (GTK_TABLE (table), rts, 4, 5, 4, 5); /* separator between port/speed and DTR/RTS */ - gtk_table_attach (GTK_TABLE (table), gtk_vseparator_new(), 2, 3, 3, 5, + gtk_table_attach (GTK_TABLE (table), gtk_vseparator_new(), 2, 3, 1, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 5, 0); if (conf->name != NULL) @@ -304,10 +331,15 @@ gtk_entry_set_text (GTK_ENTRY (name), conf->name); /* model */ + select_rig (conf->id); /* type */ gtk_combo_box_set_active (GTK_COMBO_BOX (type), conf->type); + /* port */ + gtk_combo_box_prepend_text (GTK_COMBO_BOX (port), conf->port); + gtk_combo_box_set_active (GTK_COMBO_BOX (port), 0); + /*serial speed */ switch (conf->speed) { case 300: @@ -339,6 +371,9 @@ break; } + /* CI-V */ + gtk_combo_box_set_active (GTK_COMBO_BOX (civ), conf->civ); + /* DTR and RTS lines */ gtk_combo_box_set_active (GTK_COMBO_BOX (dtr), conf->dtr); gtk_combo_box_set_active (GTK_COMBO_BOX (rts), conf->rts); @@ -354,6 +389,14 @@ static void clear_widgets () { + gtk_entry_set_text (GTK_ENTRY (name), ""); + select_rig (1); + gtk_combo_box_set_active (GTK_COMBO_BOX (type), 0); + gtk_combo_box_set_active (GTK_COMBO_BOX (port), 0); + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 4); + gtk_combo_box_set_active (GTK_COMBO_BOX (civ), 0); + gtk_combo_box_set_active (GTK_COMBO_BOX (dtr), 0); + gtk_combo_box_set_active (GTK_COMBO_BOX (rts), 0); } @@ -365,7 +408,86 @@ static gboolean apply_changes (radio_conf_t *conf) { + GtkTreeIter iter1,iter2; + GtkTreeModel *riglist; + gchar *b1,*b2; + guint id; + + + /* name */ + if (conf->name) + g_free (conf->name); + /* model */ + if (conf->model) + g_free (conf->model); + + /* iter1 is needed to construct full model name */ + gtk_combo_box_get_active_iter (GTK_COMBO_BOX (model), &iter2); + riglist = gtk_combo_box_get_model (GTK_COMBO_BOX (model)); + gtk_tree_model_iter_parent (riglist, &iter1, &iter2); + + /* build model string */ + gtk_tree_model_get (riglist, &iter1, 0, &b1, -1); + gtk_tree_model_get (riglist, &iter2, 0, &b2, -1); + conf->model = g_strconcat (b1, " ", b2, NULL); + g_free (b1); + g_free (b2); + + /* ID */ + gtk_tree_model_get (riglist, &iter2, 1, &id, -1); + conf->id = id; + + /* radio type */ + conf->type = gtk_combo_box_get_active (GTK_COMBO_BOX (type)); + + /* port / device */ + if (conf->port) + g_free (conf->port); + + conf->port = gtk_combo_box_get_active_text (GTK_COMBO_BOX (port)); + + /* CI-V */ + conf->civ = gtk_combo_box_get_active (GTK_COMBO_BOX (civ)); + + /* serial speed */ + switch (gtk_combo_box_get_active (GTK_COMBO_BOX (speed))) { + case 0: + conf->speed = 300; + break; + case 1: + conf->speed = 1200; + break; + case 2: + conf->speed = 2400; + break; + case 3: + conf->speed = 4800; + break; + case 4: + conf->speed = 9600; + break; + case 5: + conf->speed = 19200; + break; + case 6: + conf->speed = 38400; + break; + case 7: + conf->speed = 57600; + break; + case 8: + conf->speed = 115200; + break; + default: + conf->speed = 9600; + break; + } + + /* DTR and RTS */ + conf->dtr = gtk_combo_box_get_active (GTK_COMBO_BOX (dtr)); + conf->rts = gtk_combo_box_get_active (GTK_COMBO_BOX (rts)); + return TRUE; } @@ -631,3 +753,68 @@ g_object_set (cell, "sensitive", sensitive, NULL); } + + +/** \brief Select a radio in the combo box. + * \param rigid The hamlib id of the radio. + * + * This function selects the specified radio in the combobox. This is done + * by looping over all items in the tree model until a match is reached + * (or there are no more items left). + */ +static void +select_rig (guint rigid) +{ + GtkTreeIter iter1,iter2; + GtkTreeModel *riglist; + guint i,j,n,m; + guint thisrig = 0; + + + /* get the tree model */ + riglist = gtk_combo_box_get_model (GTK_COMBO_BOX (model)); + + /* get the number of toplevel nodes */ + n = gtk_tree_model_iter_n_children (riglist, NULL); + for (i = 0; i < n; i++) { + + /* get the i'th toplevel node */ + if (gtk_tree_model_iter_nth_child (riglist, &iter1, NULL, i)) { + + /* get the number of children */ + m = gtk_tree_model_iter_n_children (riglist, &iter1); + for (j = 0; j < m; j++) { + + /* get the j'th child */ + if (gtk_tree_model_iter_nth_child (riglist, &iter2, &iter1, j)) { + + /* get ID of this model */ + gtk_tree_model_get (riglist, &iter2, 1, &thisrig, -1); + + if (thisrig == rigid) { + /* select this rig and terminate loop */ + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (model), &iter2); + j = m; + i = n; + } + } + else { + sat_log_log (SAT_LOG_LEVEL_BUG, + _("%s:%s: NULL child node at index %d:%d"), + __FILE__, __FUNCTION__, i, j); + + } + } + + } + else { + sat_log_log (SAT_LOG_LEVEL_BUG, + _("%s:%s: NULL toplevel node at index %d"), + __FILE__, __FUNCTION__, i); + } + } + + +} + +#endif Modified: trunk/src/sat-pref-rig-editor.h =================================================================== --- trunk/src/sat-pref-rig-editor.h 2008-01-22 23:13:00 UTC (rev 11) +++ trunk/src/sat-pref-rig-editor.h 2008-01-24 18:29:33 UTC (rev 12) @@ -31,8 +31,8 @@ #include <gtk/gtk.h> #include "radio-conf.h" - +#ifdef HAVE_HAMLIB void sat_pref_rig_editor_run (radio_conf_t *conf); +#endif - #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-01-24 21:39:31
|
Revision: 19 http://gpredict.svn.sourceforge.net/gpredict/?rev=19&view=rev Author: csete Date: 2008-01-24 13:39:25 -0800 (Thu, 24 Jan 2008) Log Message: ----------- Added files with functions to read and save rotator configuration. Added Paths: ----------- trunk/src/rotor-conf.c trunk/src/rotor-conf.h Added: trunk/src/rotor-conf.c =================================================================== --- trunk/src/rotor-conf.c (rev 0) +++ trunk/src/rotor-conf.c 2008-01-24 21:39:25 UTC (rev 19) @@ -0,0 +1,138 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + Gpredict: Real-time satellite tracking and orbit prediction program + + Copyright (C) 2001-2007 Alexandru Csete. + + Authors: Alexandru Csete <oz...@gm...> + + Comments, questions and bugreports should be submitted via + http://sourceforge.net/projects/groundstation/ + More details can be found at the project home page: + + http://groundstation.sourceforge.net/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, visit http://www.fsf.org/ + +*/ + +#include <gtk/gtk.h> +#include <glib/gi18n.h> +#include "sat-log.h" +#include "compat.h" + +#include "rotor-conf.h" + +#define GROUP "Rotator" +#define KEY_MODEL "Model" +#define KEY_ID "ID" +#define KEY_TYPE "Type" +#define KEY_PORT "Port" +#define KEY_SPEED "Speed" + + +/** \brief Read rotator configuration. + * \param conf Pointer to a rotor_conf_t structure where the data will be + * stored. + * + * This function reads a rotoator configuration from a .rot file into conf. + * conf->name must contain the file name of the configuration (no path, just + * file name and without the .rot extension). + */ +gboolean rotor_conf_read (rotor_conf_t *conf) +{ + GKeyFile *cfg = NULL; + gchar *confdir; + gchar *fname; + + + if (conf->name == NULL) + return FALSE; + + confdir = get_conf_dir(); + fname = g_strconcat (confdir, G_DIR_SEPARATOR_S, + "hwconf", G_DIR_SEPARATOR_S, + conf->name, ".rot", NULL); + g_free (confdir); + + /* open .grc file */ + cfg = g_key_file_new (); + g_key_file_load_from_file(cfg, fname, 0, NULL); + + if (cfg == NULL) { + sat_log_log (SAT_LOG_LEVEL_ERROR, + _("%s: Could not load file %s\n"), + __FUNCTION__, fname); + g_free (fname); + + return FALSE; + } + + g_free (fname); + + /* read parameters */ + conf->model = g_key_file_get_string (cfg, GROUP, KEY_MODEL, NULL); + conf->id = g_key_file_get_integer (cfg, GROUP, KEY_ID, NULL); + conf->type = g_key_file_get_integer (cfg, GROUP, KEY_TYPE, NULL); + conf->port = g_key_file_get_string (cfg, GROUP, KEY_PORT, NULL); + conf->speed = g_key_file_get_integer (cfg, GROUP, KEY_SPEED, NULL); + + g_key_file_free (cfg); + + return TRUE; +} + + +/** \brief Save rotator configuration. + * \param conf Pointer to the rotator configuration. + * + * This function saves the rotator configuration stored in conf to a + * .rig file. conf->name must contain the file name of the configuration + * (no path, just file name and without the .rot extension). + */ +void rotor_conf_save (radio_conf_t *conf) +{ + GKeyFile *cfg = NULL; + gchar *confdir; + gchar *fname; + gchar *data; + gsize len; + + if (conf->name == NULL) + return; + + /* create a config structure */ + cfg = g_key_file_new(); + + g_key_file_set_string (cfg, GROUP, KEY_MODEL, conf->model); + g_key_file_set_integer (cfg, GROUP, KEY_ID, conf->id); + g_key_file_set_integer (cfg, GROUP, KEY_TYPE, conf->type); + g_key_file_set_string (cfg, GROUP, KEY_PORT, conf->port); + g_key_file_set_integer (cfg, GROUP, KEY_SPEED, conf->speed); + + /* convert to text sdata */ + data = g_key_file_to_data (cfg, &len, NULL); + + confdir = get_conf_dir(); + fname = g_strconcat (confdir, G_DIR_SEPARATOR_S, + "hwconf", G_DIR_SEPARATOR_S, + conf->name, ".rot", NULL); + g_free (confdir); + + g_file_set_contents (fname, data, len, NULL); + + g_free (fname); + g_free (data); + g_key_file_free (cfg); +} Added: trunk/src/rotor-conf.h =================================================================== --- trunk/src/rotor-conf.h (rev 0) +++ trunk/src/rotor-conf.h 2008-01-24 21:39:25 UTC (rev 19) @@ -0,0 +1,60 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + Gpredict: Real-time satellite tracking and orbit prediction program + + Copyright (C) 2001-2007 Alexandru Csete. + + Authors: Alexandru Csete <oz...@gm...> + + Comments, questions and bugreports should be submitted via + http://sourceforge.net/projects/groundstation/ + More details can be found at the project home page: + + http://groundstation.sourceforge.net/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, visit http://www.fsf.org/ + + +*/ +#ifndef ROTOR_CONF_H +#define ROTOR_CONF_H 1 + +#include <glib.h> + + + + +/** \brief Rotator type definitions. */ +typedef enum { + ROTOR_TYPE_AZ = 1, /*!< Azimuth rotator. */ + ROTOR_TYPE_EL = 2, /*!< Elevation rotator. */ + ROTOR_TYPE_AZEL = 3 /*!< Both azimuth and elevation rotator. */ +} rotor_type_t; + + +/** \brief Rotator configuration. */ +typedef struct { + gchar *name; /*!< Configuration file name, less .rot */ + gchar *model; /*!< Rotator model. */ + guint id; /*!< Hamlib ID. */ + rotor_type_t type; /*!< Rotator type. */ + gchar *port; /*!< Device name, e.g. /dev/ttyS0. */ + guint speed; /*!< Serial speed. */ +} rotor_conf_t; + + +gboolean rotor_conf_read (rotor_conf_t *conf); +void rotor_conf_save (rtor_conf_t *conf); + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-01-24 22:58:38
|
Revision: 21 http://gpredict.svn.sourceforge.net/gpredict/?rev=21&view=rev Author: csete Date: 2008-01-24 14:58:40 -0800 (Thu, 24 Jan 2008) Log Message: ----------- Added files. Added Paths: ----------- trunk/src/sat-pref-rot-editor.c trunk/src/sat-pref-rot-editor.h Added: trunk/src/sat-pref-rot-editor.c =================================================================== --- trunk/src/sat-pref-rot-editor.c (rev 0) +++ trunk/src/sat-pref-rot-editor.c 2008-01-24 22:58:40 UTC (rev 21) @@ -0,0 +1,822 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + Gpredict: Real-time satellite tracking and orbit prediction program + + Copyright (C) 2001-2007 Alexandru Csete, OZ9AEC. + + Authors: Alexandru Csete <oz...@gm...> + + Comments, questions and bugreports should be submitted via + http://sourceforge.net/projects/groundstation/ + More details can be found at the project home page: + + http://groundstation.sourceforge.net/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, visit http://www.fsf.org/ +*/ + +/** \brief Edit radio configuration. + * + */ + +#include <gtk/gtk.h> +#include <glib/gi18n.h> +#include <glib/gstdio.h> +#include <math.h> +#ifdef HAVE_CONFIG_H +# include <build-config.h> +#endif +#include "gpredict-utils.h" +#include "sat-cfg.h" +#include "sat-log.h" +#include "radio-conf.h" +#include "sat-pref-rig-editor.h" + +#ifdef HAVE_HAMLIB +# include <hamlib/rig.h> + + +extern GtkWidget *window; /* dialog window defined in sat-pref.c */ + + + +/* private widgets */ +static GtkWidget *dialog; /* dialog window */ +static GtkWidget *name; /* Configuration name */ +static GtkWidget *model; /* radio model, e.g. TS-2000 */ +static GtkWidget *civ; /* Icom CI-V address */ +static GtkWidget *type; /* radio type */ +static GtkWidget *port; /* port selector */ +static GtkWidget *speed; /* serial speed selector */ +static GtkWidget *dtr,*rts; /* DTR and RTS line states */ + + +static GtkWidget *create_editor_widgets (radio_conf_t *conf); +static void update_widgets (radio_conf_t *conf); +static void clear_widgets (void); +static gboolean apply_changes (radio_conf_t *conf); +static void name_changed (GtkWidget *widget, gpointer data); +static GtkTreeModel *create_rig_model (void); +static gint rig_list_add (const struct rig_caps *, void *); +static gint rig_list_compare_mfg (gconstpointer, gconstpointer); +static gint rig_list_compare_mod (gconstpointer, gconstpointer); +static void is_rig_model (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + GtkTreeModel *tree_model, + GtkTreeIter *iter, + gpointer data); +static void select_rig (guint rigid); + + +/** \brief Add or edit a radio configuration. + * \param conf Pointer to a radio configuration. + * + * Of conf->name is not NULL the widgets will be populated with the data. + */ +void +sat_pref_rig_editor_run (radio_conf_t *conf) +{ + gint response; + gboolean finished = FALSE; + + + /* crate dialog and add contents */ + dialog = gtk_dialog_new_with_buttons (_("Edit radio configuration"), + GTK_WINDOW (window), + GTK_DIALOG_MODAL | + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CLEAR, + GTK_RESPONSE_REJECT, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, + GTK_RESPONSE_OK, + NULL); + + /* disable OK button to begin with */ + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), + GTK_RESPONSE_OK, + FALSE); + + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), + create_editor_widgets (conf)); + + /* this hacky-thing is to keep the dialog running in case the + CLEAR button is plressed. OK and CANCEL will exit the loop + */ + while (!finished) { + + response = gtk_dialog_run (GTK_DIALOG (dialog)); + + switch (response) { + + /* OK */ + case GTK_RESPONSE_OK: + if (apply_changes (conf)) { + finished = TRUE; + } + else { + finished = FALSE; + } + break; + + /* CLEAR */ + case GTK_RESPONSE_REJECT: + clear_widgets (); + break; + + /* Everything else is considered CANCEL */ + default: + finished = TRUE; + break; + } + } + + gtk_widget_destroy (dialog); +} + + +/** \brief Create and initialise widgets */ +static GtkWidget * +create_editor_widgets (radio_conf_t *conf) +{ + GtkWidget *table; + GtkWidget *label; + GtkTreeModel *riglist; + GtkCellRenderer *renderer; + gchar *buff; + guint i; + + + table = gtk_table_new (5, 5, FALSE); + gtk_container_set_border_width (GTK_CONTAINER (table), 5); + gtk_table_set_col_spacings (GTK_TABLE (table), 5); + gtk_table_set_row_spacings (GTK_TABLE (table), 5); + + /* Config name */ + label = gtk_label_new (_("Name")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 4, 0, 1); + + name = gtk_entry_new (); + gtk_entry_set_max_length (GTK_ENTRY (name), 25); + gtk_widget_set_tooltip_text (name, + _("Enter a short name for this configuration, e.g. IC910-1.\n"\ + "Allowed charachters: 0..9, a..z, A..Z, - and _")); + gtk_table_attach_defaults (GTK_TABLE (table), name, 1, 4, 0, 1); + + /* attach changed signal so that we can enable OK button when + a proper name has been entered + */ + g_signal_connect (name, "changed", G_CALLBACK (name_changed), NULL); + + /* Model */ + label = gtk_label_new (_("Model")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2); + + riglist = create_rig_model (); + model = gtk_combo_box_new_with_model (riglist); + g_object_unref (riglist); + gtk_table_attach_defaults (GTK_TABLE (table), model, 1, 2, 1, 2); + + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (model), renderer, TRUE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (model), renderer, + "text", 0, + NULL); + gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (model), + renderer, + is_rig_model, + NULL, NULL); + gtk_widget_set_tooltip_text (model, _("Click to select a radio.")); + select_rig (1); + + /* ICOM CI-V adress */ + label = gtk_label_new (_("ICOM CI-V")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 3, 4, 1, 2); + + civ = gtk_combo_box_new_text (); + gtk_widget_set_tooltip_text (civ, + _("Select ICOM CI-V address of the radio.")); + + /* works, but pretty lame... */ + gtk_combo_box_append_text (GTK_COMBO_BOX (civ), _("Default")); + for (i = 1; i < 0xF0; i++) { + if (i < 0x10) + buff = g_strdup_printf ("0x0%X", i); + else + buff = g_strdup_printf ("0x%X", i); + gtk_combo_box_append_text (GTK_COMBO_BOX (civ), buff); + g_free (buff); + } + gtk_combo_box_set_active (GTK_COMBO_BOX (civ), 0); + gtk_table_attach_defaults (GTK_TABLE (table), civ, 4, 5, 1, 2); + + + /* Type */ + label = gtk_label_new (_("Type")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 2, 3); + type = gtk_combo_box_new_text (); + gtk_combo_box_append_text (GTK_COMBO_BOX (type), _("Receiver")); + gtk_combo_box_append_text (GTK_COMBO_BOX (type), _("Transmitter")); + gtk_combo_box_append_text (GTK_COMBO_BOX (type), _("RX + TX")); + gtk_combo_box_append_text (GTK_COMBO_BOX (type), _("Full Duplex")); + gtk_combo_box_set_active (GTK_COMBO_BOX (type), 0); + gtk_widget_set_tooltip_text (type, + _("Select radio type. Consult the user manual, if unsure")); + gtk_table_attach_defaults (GTK_TABLE (table), type, 1, 2, 2, 3); + + /* Port */ + label = gtk_label_new (_("Port")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 3, 4); + + port = gtk_combo_box_entry_new_text (); + if (conf->port != NULL) { + gtk_combo_box_append_text (GTK_COMBO_BOX (port), conf->port); + } + gtk_combo_box_append_text (GTK_COMBO_BOX (port), "/dev/ttyS0"); + gtk_combo_box_append_text (GTK_COMBO_BOX (port), "/dev/ttyS1"); + gtk_combo_box_append_text (GTK_COMBO_BOX (port), "/dev/ttyS2"); + gtk_combo_box_append_text (GTK_COMBO_BOX (port), "/dev/ttyUSB0"); + gtk_combo_box_append_text (GTK_COMBO_BOX (port), "/dev/ttyUSB1"); + gtk_combo_box_append_text (GTK_COMBO_BOX (port), "/dev/ttyUSB2"); + gtk_combo_box_set_active (GTK_COMBO_BOX (port), 0); + gtk_widget_set_tooltip_text (port, _("Select or enter communication port")); + gtk_table_attach_defaults (GTK_TABLE (table), port, 1, 2, 3, 4); + + /* DTR State */ + label = gtk_label_new (_("DTR Line")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 3, 4, 3, 4); + + dtr = gtk_combo_box_new_text (); + gtk_combo_box_append_text (GTK_COMBO_BOX (dtr), _("Undefined")); + gtk_combo_box_append_text (GTK_COMBO_BOX (dtr), _("OFF")); + gtk_combo_box_append_text (GTK_COMBO_BOX (dtr), _("ON")); + gtk_combo_box_append_text (GTK_COMBO_BOX (dtr), _("PTT")); + gtk_combo_box_append_text (GTK_COMBO_BOX (dtr), _("CW")); + gtk_combo_box_set_active (GTK_COMBO_BOX (dtr), 0); + gtk_widget_set_tooltip_text (dtr, _("Select status and use of DTR line")); + gtk_table_attach_defaults (GTK_TABLE (table), dtr, 4, 5, 3, 4); + + + /* Speed */ + label = gtk_label_new (_("Rate")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 4, 5); + speed = gtk_combo_box_new_text (); + gtk_combo_box_append_text (GTK_COMBO_BOX (speed), "300"); + gtk_combo_box_append_text (GTK_COMBO_BOX (speed), "1200"); + gtk_combo_box_append_text (GTK_COMBO_BOX (speed), "2400"); + gtk_combo_box_append_text (GTK_COMBO_BOX (speed), "4800"); + gtk_combo_box_append_text (GTK_COMBO_BOX (speed), "9600"); + gtk_combo_box_append_text (GTK_COMBO_BOX (speed), "19200"); + gtk_combo_box_append_text (GTK_COMBO_BOX (speed), "38400"); + gtk_combo_box_append_text (GTK_COMBO_BOX (speed), "57600"); + gtk_combo_box_append_text (GTK_COMBO_BOX (speed), "115200"); + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 4); + gtk_widget_set_tooltip_text (speed, _("Select serial port speed")); + gtk_table_attach_defaults (GTK_TABLE (table), speed, 1, 2, 4, 5); + + /* RTS State */ + label = gtk_label_new (_("RTS Line")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 3, 4, 4, 5); + + rts = gtk_combo_box_new_text (); + gtk_combo_box_append_text (GTK_COMBO_BOX (rts), _("Undefined")); + gtk_combo_box_append_text (GTK_COMBO_BOX (rts), _("OFF")); + gtk_combo_box_append_text (GTK_COMBO_BOX (rts), _("ON")); + gtk_combo_box_append_text (GTK_COMBO_BOX (rts), _("PTT")); + gtk_combo_box_append_text (GTK_COMBO_BOX (rts), _("CW")); + gtk_combo_box_set_active (GTK_COMBO_BOX (rts), 0); + gtk_widget_set_tooltip_text (rts, _("Select status and use of RTS line")); + gtk_table_attach_defaults (GTK_TABLE (table), rts, 4, 5, 4, 5); + + /* separator between port/speed and DTR/RTS */ + gtk_table_attach (GTK_TABLE (table), gtk_vseparator_new(), 2, 3, 1, 5, + GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 5, 0); + + if (conf->name != NULL) + update_widgets (conf); + + gtk_widget_show_all (table); + + return table; +} + + +/** \brief Update widgets from the currently selected row in the treeview + */ +static void +update_widgets (radio_conf_t *conf) +{ + + /* configuration name */ + gtk_entry_set_text (GTK_ENTRY (name), conf->name); + + /* model */ + select_rig (conf->id); + + /* type */ + gtk_combo_box_set_active (GTK_COMBO_BOX (type), conf->type); + + /* port */ + gtk_combo_box_prepend_text (GTK_COMBO_BOX (port), conf->port); + gtk_combo_box_set_active (GTK_COMBO_BOX (port), 0); + + /*serial speed */ + switch (conf->speed) { + case 300: + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 0); + break; + case 1200: + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 1); + break; + case 2400: + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 2); + break; + case 9600: + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 3); + break; + case 19200: + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 4); + break; + case 38400: + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 5); + break; + case 57600: + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 6); + break; + case 115200: + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 7); + break; + default: + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 4); + break; + } + + /* CI-V */ + gtk_combo_box_set_active (GTK_COMBO_BOX (civ), conf->civ); + + /* DTR and RTS lines */ + gtk_combo_box_set_active (GTK_COMBO_BOX (dtr), conf->dtr); + gtk_combo_box_set_active (GTK_COMBO_BOX (rts), conf->rts); +} + + + +/** \brief Clear the contents of all widgets. + * + * This function is usually called when the user clicks on the CLEAR button + * + */ +static void +clear_widgets () +{ + gtk_entry_set_text (GTK_ENTRY (name), ""); + select_rig (1); + gtk_combo_box_set_active (GTK_COMBO_BOX (type), 0); + gtk_combo_box_set_active (GTK_COMBO_BOX (port), 0); + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 4); + gtk_combo_box_set_active (GTK_COMBO_BOX (civ), 0); + gtk_combo_box_set_active (GTK_COMBO_BOX (dtr), 0); + gtk_combo_box_set_active (GTK_COMBO_BOX (rts), 0); +} + + +/** \brief Apply changes. + * \return TRUE if things are ok, FALSE otherwise. + * + * This function is usually called when the user clicks the OK button. + */ +static gboolean +apply_changes (radio_conf_t *conf) +{ + GtkTreeIter iter1,iter2; + GtkTreeModel *riglist; + gchar *b1,*b2; + guint id; + + + /* name */ + if (conf->name) + g_free (conf->name); + + conf->name = g_strdup (gtk_entry_get_text (GTK_ENTRY (name))); + + /* model */ + if (conf->model) + g_free (conf->model); + + /* iter1 is needed to construct full model name */ + gtk_combo_box_get_active_iter (GTK_COMBO_BOX (model), &iter2); + riglist = gtk_combo_box_get_model (GTK_COMBO_BOX (model)); + gtk_tree_model_iter_parent (riglist, &iter1, &iter2); + + /* build model string */ + gtk_tree_model_get (riglist, &iter1, 0, &b1, -1); + gtk_tree_model_get (riglist, &iter2, 0, &b2, -1); + conf->model = g_strconcat (b1, " ", b2, NULL); + g_free (b1); + g_free (b2); + + /* ID */ + gtk_tree_model_get (riglist, &iter2, 1, &id, -1); + conf->id = id; + + /* radio type */ + conf->type = gtk_combo_box_get_active (GTK_COMBO_BOX (type)); + + /* port / device */ + if (conf->port) + g_free (conf->port); + + conf->port = gtk_combo_box_get_active_text (GTK_COMBO_BOX (port)); + + /* CI-V */ + conf->civ = gtk_combo_box_get_active (GTK_COMBO_BOX (civ)); + + /* serial speed */ + switch (gtk_combo_box_get_active (GTK_COMBO_BOX (speed))) { + case 0: + conf->speed = 300; + break; + case 1: + conf->speed = 1200; + break; + case 2: + conf->speed = 2400; + break; + case 3: + conf->speed = 4800; + break; + case 4: + conf->speed = 9600; + break; + case 5: + conf->speed = 19200; + break; + case 6: + conf->speed = 38400; + break; + case 7: + conf->speed = 57600; + break; + case 8: + conf->speed = 115200; + break; + default: + conf->speed = 9600; + break; + } + + /* DTR and RTS */ + conf->dtr = gtk_combo_box_get_active (GTK_COMBO_BOX (dtr)); + conf->rts = gtk_combo_box_get_active (GTK_COMBO_BOX (rts)); + + return TRUE; +} + + + +/** \brief Manage name changes. + * + * This function is called when the contents of the name entry changes. + * The primary purpose of this function is to check whether the char length + * of the name is greater than zero, if yes enable the OK button of the dialog. + */ +static void +name_changed (GtkWidget *widget, gpointer data) +{ + const gchar *text; + gchar *entry, *end, *j; + gint len, pos; + + + /* step 1: ensure that only valid characters are entered + (stolen from xlog, tnx pg4i) + */ + entry = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1); + if ((len = g_utf8_strlen (entry, -1)) > 0) + { + end = entry + g_utf8_strlen (entry, -1); + for (j = entry; j < end; ++j) + { + switch (*j) + { + case '0' ... '9': + case 'a' ... 'z': + case 'A' ... 'Z': + case '-': + case '_': + break; + default: + gdk_beep (); + pos = gtk_editable_get_position (GTK_EDITABLE (widget)); + gtk_editable_delete_text (GTK_EDITABLE (widget), + pos, pos+1); + break; + } + } + } + + + /* step 2: if name seems all right, enable OK button */ + text = gtk_entry_get_text (GTK_ENTRY (widget)); + + if (g_utf8_strlen (text, -1) > 0) { + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), + GTK_RESPONSE_OK, + TRUE); + } + else { + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), + GTK_RESPONSE_OK, + FALSE); + } +} + + +/** \brief Radio info to be used when building the rig model */ +typedef struct { + gint id; /*!< Model ID. */ + gchar *mfg; /*!< Manufacurer name (eg. KENWOOD). */ + gchar *model; /*!< Radio model (eg. TS-440). */ +} rig_info_t; + + +/** \brief Build tree model containing radios. + * \return A tree model where the radios are ordered according to + * manufacturer. + * + */ +static GtkTreeModel *create_rig_model () +{ + GArray *array; + rig_info_t *info; + GtkTreeIter iter1; /* iter used for manufacturer */ + GtkTreeIter iter2; /* iter used for model */ + GtkTreeStore *store; + gchar *buff; + gint status; + gint i; + + + /* create araay containing rigs */ + array = g_array_new (FALSE, FALSE, sizeof (rig_info_t)); + rig_load_all_backends(); + + /* fill list using rig_list_foreach */ + status = rig_list_foreach (rig_list_add, (void *) array); + + /* sort the array, first by model then by mfg */ + g_array_sort (array, rig_list_compare_mod); + g_array_sort (array, rig_list_compare_mfg); + + sat_log_log (SAT_LOG_LEVEL_DEBUG, + _("%s:%d: Read %d distinct radios into array."), + __FILE__, __LINE__, array->len); + + /* create a tree store with two cols (name and ID) */ + store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_INT); + + /* add array contents to treestore */ + for (i = 0; i < array->len; i++) { + + /* get rig info struct */ + info = &g_array_index (array, rig_info_t, i); + + if (gtk_tree_store_iter_is_valid (store, &iter1)) { + /* iter1 is valid, i.e. we already have a manufacturer */ + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter1, + 0, &buff, + -1); + if (g_ascii_strcasecmp (buff, info->mfg)) { + /* mfg different, add new mfg */ + gtk_tree_store_append (store, &iter1, NULL); + gtk_tree_store_set (store, &iter1, 0, info->mfg, -1); + } + /* else: mfg are identical; nothing to do */ + } + else { + /* iter1 is not valid, so add the first manufacturer */ + gtk_tree_store_append (store, &iter1, NULL); + gtk_tree_store_set (store, &iter1, 0, info->mfg, -1); + } + + /* iter1 points to the parent mfg; insert this rig */ + gtk_tree_store_append (store, &iter2, &iter1); + gtk_tree_store_set (store, &iter2, + 0, info->model, + 1, info->id, + -1); + + /* done with this model */ + g_free (info->mfg); + g_free (info->model); + } + + g_array_free (array,TRUE); + + return GTK_TREE_MODEL (store); +} + + +/** \brief Add new entry to list of radios. + * \param caps Structure with the capablities of thecurrent radio. + * \param array Pointer to the GArray into which the new entry should be + * stored. + * \return Always 1 to keep rig_list_foreach running. + * + * This function is called by the rig_list_foreach hamlib function for each + * supported radio. It copies the relevant data into a grig_rig_info_t + * structure and adds the new entry to the GArray containing the list of + * supported radios. + * + * \sa rig_list_compare + */ +static gint +rig_list_add (const struct rig_caps *caps, void *array) +{ + rig_info_t *info; + + /* create new entry */ + info = g_malloc (sizeof (rig_info_t)); + + /* fill values */ + info->id = caps->rig_model; + info->mfg = g_strdup (caps->mfg_name); + info->model = g_strdup (caps->model_name); + + /* append new element to array */ + array = (void *) g_array_append_vals ((GArray *) array, info, 1); + + /* keep on running */ + return 1; +} + + + +/** \brief Compare two rig info entries. + * \param a Pointer to the first entry. + * \param b Pointer to the second entry. + * \return Negative value if a < b; zero if a = b; positive value if a > b. + * + * This function is used to compare two rig entries in the list of radios + * when the list is sorted. It compares the manufacturer of the two radios. + * + * \sa rig_list_add + */ +static gint +rig_list_compare_mfg (gconstpointer a, gconstpointer b) +{ + gchar *ida, *idb; + + ida = ((rig_info_t *) a)->mfg; + idb = ((rig_info_t *) b)->mfg; + + if (g_ascii_strcasecmp(ida,idb) < 0) { + return -1; + } + else if (g_ascii_strcasecmp(ida,idb) > 0) { + return 1; + } + else { + return 0; + } + +} + + + +/** \brief Compare two rig info entries. + * \param a Pointer to the first entry. + * \param b Pointer to the second entry. + * \return Negative value if a < b; zero if a = b; positive value if a > b. + * + * This function is used to compare two rig entries in the list of radios + * when the list is sorted. It compares the model of the two radios. + * + * \sa rig_list_add + */ +static gint +rig_list_compare_mod (gconstpointer a, gconstpointer b) +{ + gchar *ida, *idb; + + ida = ((rig_info_t *) a)->model; + idb = ((rig_info_t *) b)->model; + + if (g_ascii_strcasecmp(ida,idb) < 0) { + return -1; + } + else if (g_ascii_strcasecmp(ida,idb) > 0) { + return 1; + } + else { + return 0; + } + +} + + +/** \brief Set cell sensitivity. + * + * This function is used to disable the sensitive of manifacturer entries + * as children. Otherwise, the manufacturer would appear as the first entry + * in a submenu. + * */ +static void +is_rig_model (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + GtkTreeModel *tree_model, + GtkTreeIter *iter, + gpointer data) +{ + gboolean sensitive; + + sensitive = !gtk_tree_model_iter_has_child (tree_model, iter); + + g_object_set (cell, "sensitive", sensitive, NULL); +} + + +/** \brief Select a radio in the combo box. + * \param rigid The hamlib id of the radio. + * + * This function selects the specified radio in the combobox. This is done + * by looping over all items in the tree model until a match is reached + * (or there are no more items left). + */ +static void +select_rig (guint rigid) +{ + GtkTreeIter iter1,iter2; + GtkTreeModel *riglist; + guint i,j,n,m; + guint thisrig = 0; + + + /* get the tree model */ + riglist = gtk_combo_box_get_model (GTK_COMBO_BOX (model)); + + /* get the number of toplevel nodes */ + n = gtk_tree_model_iter_n_children (riglist, NULL); + for (i = 0; i < n; i++) { + + /* get the i'th toplevel node */ + if (gtk_tree_model_iter_nth_child (riglist, &iter1, NULL, i)) { + + /* get the number of children */ + m = gtk_tree_model_iter_n_children (riglist, &iter1); + for (j = 0; j < m; j++) { + + /* get the j'th child */ + if (gtk_tree_model_iter_nth_child (riglist, &iter2, &iter1, j)) { + + /* get ID of this model */ + gtk_tree_model_get (riglist, &iter2, 1, &thisrig, -1); + + if (thisrig == rigid) { + /* select this rig and terminate loop */ + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (model), &iter2); + j = m; + i = n; + } + } + else { + sat_log_log (SAT_LOG_LEVEL_BUG, + _("%s:%s: NULL child node at index %d:%d"), + __FILE__, __FUNCTION__, i, j); + + } + } + + } + else { + sat_log_log (SAT_LOG_LEVEL_BUG, + _("%s:%s: NULL toplevel node at index %d"), + __FILE__, __FUNCTION__, i); + } + } + + +} + +#endif Added: trunk/src/sat-pref-rot-editor.h =================================================================== --- trunk/src/sat-pref-rot-editor.h (rev 0) +++ trunk/src/sat-pref-rot-editor.h 2008-01-24 22:58:40 UTC (rev 21) @@ -0,0 +1,38 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + Gpredict: Real-time satellite tracking and orbit prediction program + + Copyright (C) 2001-2007 Alexandru Csete, OZ9AEC. + + Authors: Alexandru Csete <oz...@gm...> + + Comments, questions and bugreports should be submitted via + http://sourceforge.net/projects/groundstation/ + More details can be found at the project home page: + + http://groundstation.sourceforge.net/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, visit http://www.fsf.org/ +*/ +#ifndef SAT_PREF_ROT_EDITOR_H +#define SAT_PREF_ROT_EDITOR_H 1 + +#include <gtk/gtk.h> +#include "rotor-conf.h" + +#ifdef HAVE_HAMLIB +void sat_pref_rot_editor_run (rotor_conf_t *conf); +#endif + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-04-22 20:15:36
|
Revision: 34 http://gpredict.svn.sourceforge.net/gpredict/?rev=34&view=rev Author: csete Date: 2008-04-22 13:15:34 -0700 (Tue, 22 Apr 2008) Log Message: ----------- First fully functional implementation. Modified Paths: -------------- trunk/src/gtk-rot-ctrl.c trunk/src/gtk-rot-ctrl.h Modified: trunk/src/gtk-rot-ctrl.c =================================================================== --- trunk/src/gtk-rot-ctrl.c 2008-04-20 13:28:01 UTC (rev 33) +++ trunk/src/gtk-rot-ctrl.c 2008-04-22 20:15:34 UTC (rev 34) @@ -26,6 +26,7 @@ along with this program; if not, visit http://www.fsf.org/ */ /** \brief ROTOR control. + * \ingroup widgets * * More info... * @@ -34,20 +35,25 @@ */ #include <gtk/gtk.h> #include <glib/gi18n.h> +#include <math.h> #include "gtk-rot-ctrl.h" #ifdef HAVE_CONFIG_H # include <build-config.h> #endif +#define FMTSTR "<span size='xx-large'>%c</span>" + static void gtk_rot_ctrl_class_init (GtkRotCtrlClass *class); static void gtk_rot_ctrl_init (GtkRotCtrl *list); static void gtk_rot_ctrl_destroy (GtkObject *object); static void gtk_rot_ctrl_update (GtkRotCtrl *ctrl); +static void button_clicked_cb (GtkWidget *button, gpointer data); + static GtkHBoxClass *parent_class = NULL; @@ -128,20 +134,162 @@ { GtkWidget *widget; GtkWidget *table; + guint i; - widget = g_object_new (GTK_TYPE_ROT_CTRL, NULL); GTK_ROT_CTRL(widget)->min = min; GTK_ROT_CTRL(widget)->max = max; GTK_ROT_CTRL(widget)->value = val; + /* create table */ + table = gtk_table_new (3, 7, FALSE); + + /* create buttons */ + /* +100 deg */ + GTK_ROT_CTRL(widget)->buttons[0] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[0]), + gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_NONE)); + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[0]), + GTK_RELIEF_NONE); + g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[0]), + "delta", GINT_TO_POINTER(10000)); + gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[0], + 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); + g_signal_connect (GTK_ROT_CTRL(widget)->buttons[0], "clicked", + G_CALLBACK (button_clicked_cb), widget); + + /* +10 deg */ + GTK_ROT_CTRL(widget)->buttons[1] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[1]), + gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_NONE)); + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[1]), + GTK_RELIEF_NONE); + g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[1]), + "delta", GINT_TO_POINTER(1000)); + gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[1], + 2, 3, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); + g_signal_connect (GTK_ROT_CTRL(widget)->buttons[1], "clicked", + G_CALLBACK (button_clicked_cb), widget); + + /* +1 deg */ + GTK_ROT_CTRL(widget)->buttons[2] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[2]), + gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_NONE)); + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[2]), + GTK_RELIEF_NONE); + g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[2]), + "delta", GINT_TO_POINTER(100)); + gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[2], + 3, 4, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); + g_signal_connect (GTK_ROT_CTRL(widget)->buttons[2], "clicked", + G_CALLBACK (button_clicked_cb), widget); + + /* +0.1 deg */ + GTK_ROT_CTRL(widget)->buttons[3] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[3]), + gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_NONE)); + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[3]), + GTK_RELIEF_NONE); + g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[3]), + "delta", GINT_TO_POINTER(10)); + gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[3], + 5, 6, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); + g_signal_connect (GTK_ROT_CTRL(widget)->buttons[3], "clicked", + G_CALLBACK (button_clicked_cb), widget); + + /* +0.01 deg */ + GTK_ROT_CTRL(widget)->buttons[4] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[4]), + gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_NONE)); + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[4]), + GTK_RELIEF_NONE); + g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[4]), + "delta", GINT_TO_POINTER(1)); + gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[4], + 6, 7, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); + g_signal_connect (GTK_ROT_CTRL(widget)->buttons[4], "clicked", + G_CALLBACK (button_clicked_cb), widget); + + /* -100 deg */ + GTK_ROT_CTRL(widget)->buttons[5] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[5]), + gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE)); + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[5]), + GTK_RELIEF_NONE); + g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[5]), + "delta", GINT_TO_POINTER(-10000)); + gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[5], + 1, 2, 2, 3, GTK_SHRINK, GTK_SHRINK, 0, 0); + g_signal_connect (GTK_ROT_CTRL(widget)->buttons[5], "clicked", + G_CALLBACK (button_clicked_cb), widget); + + /* -10 deg */ + GTK_ROT_CTRL(widget)->buttons[6] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[6]), + gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE)); + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[6]), + GTK_RELIEF_NONE); + g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[6]), + "delta", GINT_TO_POINTER(-1000)); + gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[6], + 2, 3, 2, 3, GTK_SHRINK, GTK_SHRINK, 0, 0); + g_signal_connect (GTK_ROT_CTRL(widget)->buttons[6], "clicked", + G_CALLBACK (button_clicked_cb), widget); + + /* -1 deg */ + GTK_ROT_CTRL(widget)->buttons[7] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[7]), + gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE)); + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[7]), + GTK_RELIEF_NONE); + g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[7]), + "delta", GINT_TO_POINTER(-100)); + gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[7], + 3, 4, 2, 3, GTK_SHRINK, GTK_SHRINK, 0, 0); + g_signal_connect (GTK_ROT_CTRL(widget)->buttons[7], "clicked", + G_CALLBACK (button_clicked_cb), widget); + + /* -0.1 deg */ + GTK_ROT_CTRL(widget)->buttons[8] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[8]), + gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE)); + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[8]), + GTK_RELIEF_NONE); + g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[8]), + "delta", GINT_TO_POINTER(-10)); + gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[8], + 5, 6, 2, 3, GTK_SHRINK, GTK_SHRINK, 0, 0); + g_signal_connect (GTK_ROT_CTRL(widget)->buttons[8], "clicked", + G_CALLBACK (button_clicked_cb), widget); + + /* -0.01 deg */ + GTK_ROT_CTRL(widget)->buttons[9] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[9]), + gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE)); + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[9]), + GTK_RELIEF_NONE); + g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[9]), + "delta", GINT_TO_POINTER(-1)); + gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[9], + 6, 7, 2, 3, GTK_SHRINK, GTK_SHRINK, 0, 0); + g_signal_connect (GTK_ROT_CTRL(widget)->buttons[9], "clicked", + G_CALLBACK (button_clicked_cb), widget); + + /* create labels */ + for (i = 0; i < 7; i++) { + GTK_ROT_CTRL(widget)->digits[i] = gtk_label_new (NULL); + gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->digits[i], + i, i+1, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0); + } + gtk_rot_ctrl_update (GTK_ROT_CTRL(widget)); + + gtk_container_add (GTK_CONTAINER (widget), table); gtk_widget_show_all (widget); - return widget; } @@ -179,11 +327,54 @@ /** \brief Update rotor display widget. - * \param[in] ctrl The rottor control widget. + * \param[in] ctrl The rotor control widget. * */ static void gtk_rot_ctrl_update (GtkRotCtrl *ctrl) { + gchar b[7]; + gchar *buff; + guint i; + g_ascii_formatd (b, 8, "%6.2f", fabs(ctrl->value)); + + /* set label markups */ + for (i = 0; i < 6; i++) { + buff = g_strdup_printf (FMTSTR, b[i]); + gtk_label_set_markup (GTK_LABEL(ctrl->digits[i+1]), buff); + g_free (buff); + } + + if (ctrl->value <= 0) + buff = g_strdup_printf (FMTSTR, '-'); + else + buff = g_strdup_printf (FMTSTR, ' '); + + gtk_label_set_markup (GTK_LABEL(ctrl->digits[0]), buff); + g_free (buff); } + + +/** \brief Button clicked event. + * \param button The button that was clicked. + * \param data Pointer to the GtkRotCtrl widget. + * + */ +static void +button_clicked_cb (GtkWidget *button, gpointer data) +{ + GtkRotCtrl *ctrl = GTK_ROT_CTRL (data); + gfloat delta = GPOINTER_TO_INT(g_object_get_data (G_OBJECT (button), "delta")) / 100.0; + + if ((delta > 0.0) && ((ctrl->value + delta) <= ctrl->max)) { + ctrl->value += delta; + } + else if ((delta < 0.0) && ((ctrl->value + delta) >= ctrl->min)) { + ctrl->value += delta; + } + + gtk_rot_ctrl_update (ctrl); + + g_print ("VAL: %.2f\n", ctrl->value); +} Modified: trunk/src/gtk-rot-ctrl.h =================================================================== --- trunk/src/gtk-rot-ctrl.h 2008-04-20 13:28:01 UTC (rev 33) +++ trunk/src/gtk-rot-ctrl.h 2008-04-22 20:15:34 UTC (rev 34) @@ -60,6 +60,9 @@ struct _gtk_rot_ctrl { GtkVBox vbox; + + GtkWidget *digits[7]; /*!< Labels for the digits */ + GtkWidget *buttons[10]; /*!< Buttons; 0..4 up; 5..9 down */ gfloat min; gfloat max; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-01-21 22:33:21
|
Revision: 7 http://gpredict.svn.sourceforge.net/gpredict/?rev=7&view=rev Author: csete Date: 2008-01-21 14:33:25 -0800 (Mon, 21 Jan 2008) Log Message: ----------- Removed manufacturer field. Will be part of the model. Modified Paths: -------------- trunk/src/radio-conf.c trunk/src/radio-conf.h trunk/src/sat-pref-rig.c Modified: trunk/src/radio-conf.c =================================================================== --- trunk/src/radio-conf.c 2008-01-13 23:07:04 UTC (rev 6) +++ trunk/src/radio-conf.c 2008-01-21 22:33:25 UTC (rev 7) @@ -35,7 +35,6 @@ #include "radio-conf.h" #define GROUP "Radio" -#define KEY_MFG "Company" #define KEY_MODEL "Model" #define KEY_ID "ID" #define KEY_TYPE "Type" @@ -86,7 +85,6 @@ g_free (fname); /* read parameters */ - conf->company = g_key_file_get_string (cfg, GROUP, KEY_MFG, NULL); conf->model = g_key_file_get_string (cfg, GROUP, KEY_MODEL, NULL); conf->id = g_key_file_get_integer (cfg, GROUP, KEY_ID, NULL); conf->type = g_key_file_get_integer (cfg, GROUP, KEY_TYPE, NULL); @@ -123,7 +121,6 @@ /* create a config structure */ cfg = g_key_file_new(); - g_key_file_set_string (cfg, GROUP, KEY_MFG, conf->company); g_key_file_set_string (cfg, GROUP, KEY_MODEL, conf->model); g_key_file_set_integer (cfg, GROUP, KEY_ID, conf->id); g_key_file_set_integer (cfg, GROUP, KEY_TYPE, conf->type); Modified: trunk/src/radio-conf.h =================================================================== --- trunk/src/radio-conf.h 2008-01-13 23:07:04 UTC (rev 6) +++ trunk/src/radio-conf.h 2008-01-21 22:33:25 UTC (rev 7) @@ -55,8 +55,7 @@ /** \brief Radio configuration. */ typedef struct { gchar *name; /*!< Configuration file name. */ - gchar *company; /*!< Manufacturer, e.g. ICOM. */ - gchar *model; /*!< Radio model, e.g. IC-910H. */ + gchar *model; /*!< Radio model, e.g. ICOM IC-910H. */ guint id; /*!< Hamlib ID. */ radio_type_t type; /*!< Radio type. */ gchar *port; /*!< Device name, e.g. /dev/ttyS0. */ Modified: trunk/src/sat-pref-rig.c =================================================================== --- trunk/src/sat-pref-rig.c 2008-01-13 23:07:04 UTC (rev 6) +++ trunk/src/sat-pref-rig.c 2008-01-21 22:33:25 UTC (rev 7) @@ -129,13 +129,6 @@ NULL); gtk_tree_view_insert_column (GTK_TREE_VIEW (riglist), column, -1); - /* Company */ - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (_("Company"), renderer, - "text", RIG_LIST_COL_COMP, - NULL); - gtk_tree_view_insert_column (GTK_TREE_VIEW (riglist), column, -1); - /* Model */ renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes (_("Model"), renderer, @@ -220,7 +213,6 @@ /* create a new list store */ liststore = gtk_list_store_new (RIG_LIST_COL_NUM, G_TYPE_STRING, // name - G_TYPE_STRING, // company G_TYPE_STRING, // model G_TYPE_INT, // hamlib id G_TYPE_INT, // radio type @@ -250,7 +242,6 @@ gtk_list_store_append (liststore, &item); gtk_list_store_set (liststore, &item, RIG_LIST_COL_NAME, conf.name, - RIG_LIST_COL_COMP, conf.company, RIG_LIST_COL_MODEL, conf.model, RIG_LIST_COL_ID, conf.id, RIG_LIST_COL_TYPE, conf.type, @@ -268,9 +259,6 @@ if (conf.name) g_free (conf.name); - if (conf.company) - g_free (conf.company); - if (conf.model) g_free (conf.model); @@ -376,8 +364,19 @@ */ static void add_cb (GtkWidget *button, gpointer data) { - radio_conf_t conf; + radio_conf_t conf = { + .name = NULL, + .model = NULL, + .id = 0, + .type = RADIO_TYPE_RX, + .port = NULL, + .speed = 0, + .civ = 0, + .dtr = LINE_UNDEF, + .rts = LINE_UNDEF, + }; + sat_pref_rig_editor_run (&conf); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-01-24 20:48:43
|
Revision: 15 http://gpredict.svn.sourceforge.net/gpredict/?rev=15&view=rev Author: csete Date: 2008-01-24 12:48:48 -0800 (Thu, 24 Jan 2008) Log Message: ----------- Changed radio conf structure so that configuration name doe not include file extension. Modified Paths: -------------- trunk/src/radio-conf.c trunk/src/radio-conf.h Modified: trunk/src/radio-conf.c =================================================================== --- trunk/src/radio-conf.c 2008-01-24 18:41:41 UTC (rev 14) +++ trunk/src/radio-conf.c 2008-01-24 20:48:48 UTC (rev 15) @@ -66,7 +66,7 @@ confdir = get_conf_dir(); fname = g_strconcat (confdir, G_DIR_SEPARATOR_S, "hwconf", G_DIR_SEPARATOR_S, - conf->name, NULL); + conf->name, ".rig", NULL); g_free (confdir); /* open .grc file */ @@ -136,7 +136,7 @@ confdir = get_conf_dir(); fname = g_strconcat (confdir, G_DIR_SEPARATOR_S, "hwconf", G_DIR_SEPARATOR_S, - conf->name, NULL); + conf->name, ".rig", NULL); g_free (confdir); g_file_set_contents (fname, data, len, NULL); Modified: trunk/src/radio-conf.h =================================================================== --- trunk/src/radio-conf.h 2008-01-24 18:41:41 UTC (rev 14) +++ trunk/src/radio-conf.h 2008-01-24 20:48:48 UTC (rev 15) @@ -54,7 +54,7 @@ /** \brief Radio configuration. */ typedef struct { - gchar *name; /*!< Configuration file name. */ + gchar *name; /*!< Configuration file name, less .rig. */ gchar *model; /*!< Radio model, e.g. ICOM IC-910H. */ guint id; /*!< Hamlib ID. */ radio_type_t type; /*!< Radio type. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-01-24 23:38:50
|
Revision: 23 http://gpredict.svn.sourceforge.net/gpredict/?rev=23&view=rev Author: csete Date: 2008-01-24 15:38:45 -0800 (Thu, 24 Jan 2008) Log Message: ----------- Added missing 4800 rate. Modified Paths: -------------- trunk/src/sat-pref-rig-editor.c trunk/src/sat-pref-rot-editor.c Modified: trunk/src/sat-pref-rig-editor.c =================================================================== --- trunk/src/sat-pref-rig-editor.c 2008-01-24 23:34:50 UTC (rev 22) +++ trunk/src/sat-pref-rig-editor.c 2008-01-24 23:38:45 UTC (rev 23) @@ -351,21 +351,24 @@ case 2400: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 2); break; - case 9600: + case 4800: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 3); break; - case 19200: + case 9600: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 4); break; - case 38400: + case 19200: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 5); break; - case 57600: + case 38400: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 6); break; - case 115200: + case 57600: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 7); break; + case 115200: + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 8); + break; default: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 4); break; Modified: trunk/src/sat-pref-rot-editor.c =================================================================== --- trunk/src/sat-pref-rot-editor.c 2008-01-24 23:34:50 UTC (rev 22) +++ trunk/src/sat-pref-rot-editor.c 2008-01-24 23:38:45 UTC (rev 23) @@ -290,21 +290,24 @@ case 2400: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 2); break; - case 9600: + case 4800: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 3); break; - case 19200: + case 9600: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 4); break; - case 38400: + case 19200: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 5); break; - case 57600: + case 38400: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 6); break; - case 115200: + case 57600: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 7); break; + case 115200: + gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 8); + break; default: gtk_combo_box_set_active (GTK_COMBO_BOX (speed), 4); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-03-30 11:52:18
|
Revision: 31 http://gpredict.svn.sourceforge.net/gpredict/?rev=31&view=rev Author: csete Date: 2008-03-30 04:52:23 -0700 (Sun, 30 Mar 2008) Log Message: ----------- Added ranges and initial values. Modified Paths: -------------- trunk/src/gtk-freq-ctrl.c trunk/src/gtk-freq-ctrl.h trunk/src/gtk-rot-ctrl.c trunk/src/gtk-rot-ctrl.h Modified: trunk/src/gtk-freq-ctrl.c =================================================================== --- trunk/src/gtk-freq-ctrl.c 2008-03-30 10:37:53 UTC (rev 30) +++ trunk/src/gtk-freq-ctrl.c 2008-03-30 11:52:23 UTC (rev 31) @@ -117,11 +117,12 @@ /** \brief Create a new Frequency control widget. + * \param[in] val The initial value of the control. * \return A new frequency control widget. * */ GtkWidget * -gtk_freq_ctrl_new () +gtk_freq_ctrl_new (gdouble val) { GtkWidget *widget; GtkWidget *table; @@ -129,8 +130,9 @@ widget = g_object_new (GTK_TYPE_FREQ_CTRL, NULL); + GTK_FREQ_CTRL(widget)->value = val; + gtk_freq_ctrl_update (GTK_FREQ_CTRL(widget)); - gtk_widget_show_all (widget); return widget; Modified: trunk/src/gtk-freq-ctrl.h =================================================================== --- trunk/src/gtk-freq-ctrl.h 2008-03-30 10:37:53 UTC (rev 30) +++ trunk/src/gtk-freq-ctrl.h 2008-03-30 11:52:23 UTC (rev 31) @@ -72,7 +72,7 @@ GtkType gtk_freq_ctrl_get_type (void); -GtkWidget* gtk_freq_ctrl_new (void); +GtkWidget* gtk_freq_ctrl_new (gdouble val); void gtk_freq_ctrl_set_value (GtkFreqCtrl *ctrl, gdouble val); gdouble gtk_freq_ctrl_get_value (GtkFreqCtrl *ctrl); Modified: trunk/src/gtk-rot-ctrl.c =================================================================== --- trunk/src/gtk-rot-ctrl.c 2008-03-30 10:37:53 UTC (rev 30) +++ trunk/src/gtk-rot-ctrl.c 2008-03-30 11:52:23 UTC (rev 31) @@ -119,11 +119,12 @@ /** \brief Create a new rotor control widget. * \param[in] min The lower limit in decimal degrees. * \param[in] max The upper limit in decimal degrees. + * \param[in] val The initial value of the control. * \return A new rotor control widget. * */ GtkWidget * -gtk_rot_ctrl_new (gfloat min, gfloat max) +gtk_rot_ctrl_new (gfloat min, gfloat max, gfloat val) { GtkWidget *widget; GtkWidget *table; @@ -131,10 +132,16 @@ widget = g_object_new (GTK_TYPE_ROT_CTRL, NULL); + GTK_ROT_CTRL(widget)->min = min; + GTK_ROT_CTRL(widget)->max = max; + GTK_ROT_CTRL(widget)->value = val; + + gtk_rot_ctrl_update (GTK_ROT_CTRL(widget)); - gtk_widget_show_all (widget); + + return widget; } @@ -148,7 +155,8 @@ gtk_rot_ctrl_set_value (GtkRotCtrl *ctrl, gfloat val) { /* set the new value */ - ctrl->value = val; + if ((val >= ctrl->min) && (val <= ctrl->max)) + ctrl->value = val; /* update the display */ gtk_rot_ctrl_update (ctrl); Modified: trunk/src/gtk-rot-ctrl.h =================================================================== --- trunk/src/gtk-rot-ctrl.h 2008-03-30 10:37:53 UTC (rev 30) +++ trunk/src/gtk-rot-ctrl.h 2008-03-30 11:52:23 UTC (rev 31) @@ -61,6 +61,8 @@ { GtkVBox vbox; + gfloat min; + gfloat max; gfloat value; }; @@ -72,7 +74,7 @@ GtkType gtk_rot_ctrl_get_type (void); -GtkWidget* gtk_rot_ctrl_new (gfloat min, gfloat max); +GtkWidget* gtk_rot_ctrl_new (gfloat min, gfloat max, gfloat val); void gtk_rot_ctrl_set_value (GtkRotCtrl *ctrl, gfloat val); gfloat gtk_rot_ctrl_get_value (GtkRotCtrl *ctrl); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-04-24 20:48:31
|
Revision: 35 http://gpredict.svn.sourceforge.net/gpredict/?rev=35&view=rev Author: csete Date: 2008-04-24 13:48:32 -0700 (Thu, 24 Apr 2008) Log Message: ----------- Added files. Added Paths: ----------- trunk/src/rot-ctrl-window.c trunk/src/rot-ctrl-window.h Added: trunk/src/rot-ctrl-window.c =================================================================== --- trunk/src/rot-ctrl-window.c (rev 0) +++ trunk/src/rot-ctrl-window.c 2008-04-24 20:48:32 UTC (rev 35) @@ -0,0 +1,65 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + Gpredict: Real-time satellite tracking and orbit prediction program + + Copyright (C) 2001-2007 Alexandru Csete, OZ9AEC. + + Authors: Alexandru Csete <oz...@gm...> + + Comments, questions and bugreports should be submitted via + http://sourceforge.net/projects/groundstation/ + More details can be found at the project home page: + + http://groundstation.sourceforge.net/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, visit http://www.fsf.org/ +*/ +#include <gtk/gtk.h> +#include <glib/gi18n.h> +#include "sat-log.h" + +#ifdef HAVE_CONFIG_H +# include <build-config.h> +#endif + +#incude "rot-ctrl-window.h" + + +/** \brief Open rotator control window */ +void rot_ctrl_window_open () +{ + if (window_is_open) { + /* window may be hidden so bring it to front */ + + return; + } + + /* create the window */ + +} + +/** \brief Close rotator control window */ +void rot_ctrl_window_close (void); +{ + if (window_is_open) { + + } + else { + sat_log_log (SAT_LOG_LEVEL_BUG, + _("%s: Rotor control window is not open!"), + __FUNCTION__); + } +} + + Added: trunk/src/rot-ctrl-window.h =================================================================== --- trunk/src/rot-ctrl-window.h (rev 0) +++ trunk/src/rot-ctrl-window.h 2008-04-24 20:48:32 UTC (rev 35) @@ -0,0 +1,34 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + Gpredict: Real-time satellite tracking and orbit prediction program + + Copyright (C) 2001-2007 Alexandru Csete, OZ9AEC. + + Authors: Alexandru Csete <oz...@gm...> + + Comments, questions and bugreports should be submitted via + http://sourceforge.net/projects/groundstation/ + More details can be found at the project home page: + + http://groundstation.sourceforge.net/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, visit http://www.fsf.org/ +*/ +#ifndef ROT_CTRL_WINDOW_H +#define ROT_CTRL_WINDOW_H 1 + +void rot_ctrl_window_open (void); +void rot_ctrl_window_close (void); + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-05-01 14:01:12
|
Revision: 47 http://gpredict.svn.sourceforge.net/gpredict/?rev=47&view=rev Author: csete Date: 2008-05-01 07:01:17 -0700 (Thu, 01 May 2008) Log Message: ----------- Change GtkRotCtrl to GtkRotKnob. Modified Paths: -------------- trunk/src/gtk-rot-knob.c trunk/src/gtk-rot-knob.h Modified: trunk/src/gtk-rot-knob.c =================================================================== --- trunk/src/gtk-rot-knob.c 2008-05-01 13:52:15 UTC (rev 46) +++ trunk/src/gtk-rot-knob.c 2008-05-01 14:01:17 UTC (rev 47) @@ -36,7 +36,7 @@ #include <gtk/gtk.h> #include <glib/gi18n.h> #include <math.h> -#include "gtk-rot-ctrl.h" +#include "gtk-rot-knob.h" #ifdef HAVE_CONFIG_H # include <build-config.h> #endif @@ -45,11 +45,11 @@ #define FMTSTR "<span size='xx-large'>%c</span>" -static void gtk_rot_ctrl_class_init (GtkRotCtrlClass *class); -static void gtk_rot_ctrl_init (GtkRotCtrl *list); -static void gtk_rot_ctrl_destroy (GtkObject *object); +static void gtk_rot_knob_class_init (GtkRotKnobClass *class); +static void gtk_rot_knob_init (GtkRotKnob *list); +static void gtk_rot_knob_destroy (GtkObject *object); -static void gtk_rot_ctrl_update (GtkRotCtrl *ctrl); +static void gtk_rot_knob_update (GtkRotKnob *knob); static void button_clicked_cb (GtkWidget *button, gpointer data); @@ -58,36 +58,36 @@ GType -gtk_rot_ctrl_get_type () +gtk_rot_knob_get_type () { - static GType gtk_rot_ctrl_type = 0; + static GType gtk_rot_knob_type = 0; - if (!gtk_rot_ctrl_type) { + if (!gtk_rot_knob_type) { - static const GTypeInfo gtk_rot_ctrl_info = { - sizeof (GtkRotCtrlClass), + static const GTypeInfo gtk_rot_knob_info = { + sizeof (GtkRotKnobClass), NULL, /* base_init */ NULL, /* base_finalize */ - (GClassInitFunc) gtk_rot_ctrl_class_init, + (GClassInitFunc) gtk_rot_knob_class_init, NULL, /* class_finalize */ NULL, /* class_data */ - sizeof (GtkRotCtrl), + sizeof (GtkRotKnob), 5, /* n_preallocs */ - (GInstanceInitFunc) gtk_rot_ctrl_init, + (GInstanceInitFunc) gtk_rot_knob_init, }; - gtk_rot_ctrl_type = g_type_register_static (GTK_TYPE_VBOX, - "GtkRotCtrl", - >k_rot_ctrl_info, + gtk_rot_knob_type = g_type_register_static (GTK_TYPE_VBOX, + "GtkRotKnob", + >k_rot_knob_info, 0); } - return gtk_rot_ctrl_type; + return gtk_rot_knob_type; } static void -gtk_rot_ctrl_class_init (GtkRotCtrlClass *class) +gtk_rot_knob_class_init (GtkRotKnobClass *class) { GObjectClass *gobject_class; GtkObjectClass *object_class; @@ -101,21 +101,21 @@ parent_class = g_type_class_peek_parent (class); - object_class->destroy = gtk_rot_ctrl_destroy; + object_class->destroy = gtk_rot_knob_destroy; } static void -gtk_rot_ctrl_init (GtkRotCtrl *ctrl) +gtk_rot_knob_init (GtkRotKnob *knob) { } static void -gtk_rot_ctrl_destroy (GtkObject *object) +gtk_rot_knob_destroy (GtkObject *object) { (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } @@ -130,160 +130,160 @@ * */ GtkWidget * -gtk_rot_ctrl_new (gfloat min, gfloat max, gfloat val) +gtk_rot_knob_new (gfloat min, gfloat max, gfloat val) { GtkWidget *widget; GtkWidget *table; guint i; - widget = g_object_new (GTK_TYPE_ROT_CTRL, NULL); + widget = g_object_new (GTK_TYPE_ROT_KNOB, NULL); - GTK_ROT_CTRL(widget)->min = min; - GTK_ROT_CTRL(widget)->max = max; - GTK_ROT_CTRL(widget)->value = val; + GTK_ROT_KNOB(widget)->min = min; + GTK_ROT_KNOB(widget)->max = max; + GTK_ROT_KNOB(widget)->value = val; /* create table */ table = gtk_table_new (3, 7, FALSE); /* create buttons */ /* +100 deg */ - GTK_ROT_CTRL(widget)->buttons[0] = gtk_button_new (); - gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[0]), + GTK_ROT_KNOB(widget)->buttons[0] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_KNOB(widget)->buttons[0]), gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_NONE)); - gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[0]), + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_KNOB(widget)->buttons[0]), GTK_RELIEF_NONE); - g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[0]), + g_object_set_data (G_OBJECT (GTK_ROT_KNOB(widget)->buttons[0]), "delta", GINT_TO_POINTER(10000)); - gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[0], + gtk_table_attach (GTK_TABLE (table), GTK_ROT_KNOB(widget)->buttons[0], 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); - g_signal_connect (GTK_ROT_CTRL(widget)->buttons[0], "clicked", + g_signal_connect (GTK_ROT_KNOB(widget)->buttons[0], "clicked", G_CALLBACK (button_clicked_cb), widget); /* +10 deg */ - GTK_ROT_CTRL(widget)->buttons[1] = gtk_button_new (); - gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[1]), + GTK_ROT_KNOB(widget)->buttons[1] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_KNOB(widget)->buttons[1]), gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_NONE)); - gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[1]), + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_KNOB(widget)->buttons[1]), GTK_RELIEF_NONE); - g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[1]), + g_object_set_data (G_OBJECT (GTK_ROT_KNOB(widget)->buttons[1]), "delta", GINT_TO_POINTER(1000)); - gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[1], + gtk_table_attach (GTK_TABLE (table), GTK_ROT_KNOB(widget)->buttons[1], 2, 3, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); - g_signal_connect (GTK_ROT_CTRL(widget)->buttons[1], "clicked", + g_signal_connect (GTK_ROT_KNOB(widget)->buttons[1], "clicked", G_CALLBACK (button_clicked_cb), widget); /* +1 deg */ - GTK_ROT_CTRL(widget)->buttons[2] = gtk_button_new (); - gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[2]), + GTK_ROT_KNOB(widget)->buttons[2] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_KNOB(widget)->buttons[2]), gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_NONE)); - gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[2]), + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_KNOB(widget)->buttons[2]), GTK_RELIEF_NONE); - g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[2]), + g_object_set_data (G_OBJECT (GTK_ROT_KNOB(widget)->buttons[2]), "delta", GINT_TO_POINTER(100)); - gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[2], + gtk_table_attach (GTK_TABLE (table), GTK_ROT_KNOB(widget)->buttons[2], 3, 4, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); - g_signal_connect (GTK_ROT_CTRL(widget)->buttons[2], "clicked", + g_signal_connect (GTK_ROT_KNOB(widget)->buttons[2], "clicked", G_CALLBACK (button_clicked_cb), widget); /* +0.1 deg */ - GTK_ROT_CTRL(widget)->buttons[3] = gtk_button_new (); - gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[3]), + GTK_ROT_KNOB(widget)->buttons[3] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_KNOB(widget)->buttons[3]), gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_NONE)); - gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[3]), + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_KNOB(widget)->buttons[3]), GTK_RELIEF_NONE); - g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[3]), + g_object_set_data (G_OBJECT (GTK_ROT_KNOB(widget)->buttons[3]), "delta", GINT_TO_POINTER(10)); - gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[3], + gtk_table_attach (GTK_TABLE (table), GTK_ROT_KNOB(widget)->buttons[3], 5, 6, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); - g_signal_connect (GTK_ROT_CTRL(widget)->buttons[3], "clicked", + g_signal_connect (GTK_ROT_KNOB(widget)->buttons[3], "clicked", G_CALLBACK (button_clicked_cb), widget); /* +0.01 deg */ - GTK_ROT_CTRL(widget)->buttons[4] = gtk_button_new (); - gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[4]), + GTK_ROT_KNOB(widget)->buttons[4] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_KNOB(widget)->buttons[4]), gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_NONE)); - gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[4]), + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_KNOB(widget)->buttons[4]), GTK_RELIEF_NONE); - g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[4]), + g_object_set_data (G_OBJECT (GTK_ROT_KNOB(widget)->buttons[4]), "delta", GINT_TO_POINTER(1)); - gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[4], + gtk_table_attach (GTK_TABLE (table), GTK_ROT_KNOB(widget)->buttons[4], 6, 7, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); - g_signal_connect (GTK_ROT_CTRL(widget)->buttons[4], "clicked", + g_signal_connect (GTK_ROT_KNOB(widget)->buttons[4], "clicked", G_CALLBACK (button_clicked_cb), widget); /* -100 deg */ - GTK_ROT_CTRL(widget)->buttons[5] = gtk_button_new (); - gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[5]), + GTK_ROT_KNOB(widget)->buttons[5] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_KNOB(widget)->buttons[5]), gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE)); - gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[5]), + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_KNOB(widget)->buttons[5]), GTK_RELIEF_NONE); - g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[5]), + g_object_set_data (G_OBJECT (GTK_ROT_KNOB(widget)->buttons[5]), "delta", GINT_TO_POINTER(-10000)); - gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[5], + gtk_table_attach (GTK_TABLE (table), GTK_ROT_KNOB(widget)->buttons[5], 1, 2, 2, 3, GTK_SHRINK, GTK_SHRINK, 0, 0); - g_signal_connect (GTK_ROT_CTRL(widget)->buttons[5], "clicked", + g_signal_connect (GTK_ROT_KNOB(widget)->buttons[5], "clicked", G_CALLBACK (button_clicked_cb), widget); /* -10 deg */ - GTK_ROT_CTRL(widget)->buttons[6] = gtk_button_new (); - gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[6]), + GTK_ROT_KNOB(widget)->buttons[6] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_KNOB(widget)->buttons[6]), gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE)); - gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[6]), + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_KNOB(widget)->buttons[6]), GTK_RELIEF_NONE); - g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[6]), + g_object_set_data (G_OBJECT (GTK_ROT_KNOB(widget)->buttons[6]), "delta", GINT_TO_POINTER(-1000)); - gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[6], + gtk_table_attach (GTK_TABLE (table), GTK_ROT_KNOB(widget)->buttons[6], 2, 3, 2, 3, GTK_SHRINK, GTK_SHRINK, 0, 0); - g_signal_connect (GTK_ROT_CTRL(widget)->buttons[6], "clicked", + g_signal_connect (GTK_ROT_KNOB(widget)->buttons[6], "clicked", G_CALLBACK (button_clicked_cb), widget); /* -1 deg */ - GTK_ROT_CTRL(widget)->buttons[7] = gtk_button_new (); - gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[7]), + GTK_ROT_KNOB(widget)->buttons[7] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_KNOB(widget)->buttons[7]), gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE)); - gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[7]), + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_KNOB(widget)->buttons[7]), GTK_RELIEF_NONE); - g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[7]), + g_object_set_data (G_OBJECT (GTK_ROT_KNOB(widget)->buttons[7]), "delta", GINT_TO_POINTER(-100)); - gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[7], + gtk_table_attach (GTK_TABLE (table), GTK_ROT_KNOB(widget)->buttons[7], 3, 4, 2, 3, GTK_SHRINK, GTK_SHRINK, 0, 0); - g_signal_connect (GTK_ROT_CTRL(widget)->buttons[7], "clicked", + g_signal_connect (GTK_ROT_KNOB(widget)->buttons[7], "clicked", G_CALLBACK (button_clicked_cb), widget); /* -0.1 deg */ - GTK_ROT_CTRL(widget)->buttons[8] = gtk_button_new (); - gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[8]), + GTK_ROT_KNOB(widget)->buttons[8] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_KNOB(widget)->buttons[8]), gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE)); - gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[8]), + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_KNOB(widget)->buttons[8]), GTK_RELIEF_NONE); - g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[8]), + g_object_set_data (G_OBJECT (GTK_ROT_KNOB(widget)->buttons[8]), "delta", GINT_TO_POINTER(-10)); - gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[8], + gtk_table_attach (GTK_TABLE (table), GTK_ROT_KNOB(widget)->buttons[8], 5, 6, 2, 3, GTK_SHRINK, GTK_SHRINK, 0, 0); - g_signal_connect (GTK_ROT_CTRL(widget)->buttons[8], "clicked", + g_signal_connect (GTK_ROT_KNOB(widget)->buttons[8], "clicked", G_CALLBACK (button_clicked_cb), widget); /* -0.01 deg */ - GTK_ROT_CTRL(widget)->buttons[9] = gtk_button_new (); - gtk_container_add (GTK_CONTAINER(GTK_ROT_CTRL(widget)->buttons[9]), + GTK_ROT_KNOB(widget)->buttons[9] = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(GTK_ROT_KNOB(widget)->buttons[9]), gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE)); - gtk_button_set_relief (GTK_BUTTON(GTK_ROT_CTRL(widget)->buttons[9]), + gtk_button_set_relief (GTK_BUTTON(GTK_ROT_KNOB(widget)->buttons[9]), GTK_RELIEF_NONE); - g_object_set_data (G_OBJECT (GTK_ROT_CTRL(widget)->buttons[9]), + g_object_set_data (G_OBJECT (GTK_ROT_KNOB(widget)->buttons[9]), "delta", GINT_TO_POINTER(-1)); - gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->buttons[9], + gtk_table_attach (GTK_TABLE (table), GTK_ROT_KNOB(widget)->buttons[9], 6, 7, 2, 3, GTK_SHRINK, GTK_SHRINK, 0, 0); - g_signal_connect (GTK_ROT_CTRL(widget)->buttons[9], "clicked", + g_signal_connect (GTK_ROT_KNOB(widget)->buttons[9], "clicked", G_CALLBACK (button_clicked_cb), widget); /* create labels */ for (i = 0; i < 7; i++) { - GTK_ROT_CTRL(widget)->digits[i] = gtk_label_new (NULL); - gtk_table_attach (GTK_TABLE (table), GTK_ROT_CTRL(widget)->digits[i], + GTK_ROT_KNOB(widget)->digits[i] = gtk_label_new (NULL); + gtk_table_attach (GTK_TABLE (table), GTK_ROT_KNOB(widget)->digits[i], i, i+1, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0); } - gtk_rot_ctrl_update (GTK_ROT_CTRL(widget)); + gtk_rot_knob_update (GTK_ROT_KNOB(widget)); gtk_container_add (GTK_CONTAINER (widget), table); @@ -295,86 +295,86 @@ /** \brief Set the value of the rotor control widget. - * \param[in] ctrl The rotor control widget. + * \param[in] knob The rotor control widget. * \param[in] val The new value. * */ void -gtk_rot_ctrl_set_value (GtkRotCtrl *ctrl, gfloat val) +gtk_rot_knob_set_value (GtkRotKnob *knob, gfloat val) { /* set the new value */ - if ((val >= ctrl->min) && (val <= ctrl->max)) - ctrl->value = val; + if ((val >= knob->min) && (val <= knob->max)) + knob->value = val; /* update the display */ - gtk_rot_ctrl_update (ctrl); + gtk_rot_knob_update (knob); } /** \brief Get the current value of the rotor control widget. - * \param[in] ctrl The rotor control widget. + * \param[in] knob The rotor control widget. * \return The current value. * - * Hint: For reading the value you can also access ctrl->value. + * Hint: For reading the value you can also access knob->value. * */ gfloat -gtk_rot_ctrl_get_value (GtkRotCtrl *ctrl) +gtk_rot_knob_get_value (GtkRotKnob *knob) { - return ctrl->value; + return knob->value; } /** \brief Update rotor display widget. - * \param[in] ctrl The rotor control widget. + * \param[in] knob The rotor control widget. * */ static void -gtk_rot_ctrl_update (GtkRotCtrl *ctrl) +gtk_rot_knob_update (GtkRotKnob *knob) { gchar b[7]; gchar *buff; guint i; - g_ascii_formatd (b, 8, "%6.2f", fabs(ctrl->value)); + g_ascii_formatd (b, 8, "%6.2f", fabs(knob->value)); /* set label markups */ for (i = 0; i < 6; i++) { buff = g_strdup_printf (FMTSTR, b[i]); - gtk_label_set_markup (GTK_LABEL(ctrl->digits[i+1]), buff); + gtk_label_set_markup (GTK_LABEL(knob->digits[i+1]), buff); g_free (buff); } - if (ctrl->value <= 0) + if (knob->value <= 0) buff = g_strdup_printf (FMTSTR, '-'); else buff = g_strdup_printf (FMTSTR, ' '); - gtk_label_set_markup (GTK_LABEL(ctrl->digits[0]), buff); + gtk_label_set_markup (GTK_LABEL(knob->digits[0]), buff); g_free (buff); } /** \brief Button clicked event. * \param button The button that was clicked. - * \param data Pointer to the GtkRotCtrl widget. + * \param data Pointer to the GtkRotKnob widget. * */ static void button_clicked_cb (GtkWidget *button, gpointer data) { - GtkRotCtrl *ctrl = GTK_ROT_CTRL (data); + GtkRotKnob *knob = GTK_ROT_KNOB (data); gfloat delta = GPOINTER_TO_INT(g_object_get_data (G_OBJECT (button), "delta")) / 100.0; - if ((delta > 0.0) && ((ctrl->value + delta) <= ctrl->max)) { - ctrl->value += delta; + if ((delta > 0.0) && ((knob->value + delta) <= knob->max)) { + knob->value += delta; } - else if ((delta < 0.0) && ((ctrl->value + delta) >= ctrl->min)) { - ctrl->value += delta; + else if ((delta < 0.0) && ((knob->value + delta) >= knob->min)) { + knob->value += delta; } - gtk_rot_ctrl_update (ctrl); + gtk_rot_knob_update (knob); - g_print ("VAL: %.2f\n", ctrl->value); + g_print ("VAL: %.2f\n", knob->value); } Modified: trunk/src/gtk-rot-knob.h =================================================================== --- trunk/src/gtk-rot-knob.h 2008-05-01 13:52:15 UTC (rev 46) +++ trunk/src/gtk-rot-knob.h 2008-05-01 14:01:17 UTC (rev 47) @@ -25,8 +25,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, visit http://www.fsf.org/ */ -#ifndef __GTK_ROT_CTRL_H__ -#define __GTK_ROT_CTRL_H__ 1 +#ifndef __GTK_ROT_KNOB_H__ +#define __GTK_ROT_KNOB_H__ 1 #include <glib.h> #include <glib/gi18n.h> @@ -40,24 +40,24 @@ -#define GTK_TYPE_ROT_CTRL (gtk_rot_ctrl_get_type ()) -#define GTK_ROT_CTRL(obj) GTK_CHECK_CAST (obj,\ - gtk_rot_ctrl_get_type (),\ - GtkRotCtrl) +#define GTK_TYPE_ROT_KNOB (gtk_rot_knob_get_type ()) +#define GTK_ROT_KNOB(obj) GTK_CHECK_CAST (obj,\ + gtk_rot_knob_get_type (),\ + GtkRotKnob) -#define GTK_ROT_CTRL_CLASS(klass) GTK_CHECK_CLASS_CAST (klass,\ - gtk_rot_ctrl_get_type (),\ - GtkRotCtrlClass) +#define GTK_ROT_KNOB_CLASS(klass) GTK_CHECK_CLASS_CAST (klass,\ + gtk_rot_knob_get_type (),\ + GtkRotKnobClass) -#define IS_GTK_ROT_CTRL(obj) GTK_CHECK_TYPE (obj, gtk_rot_ctrl_get_type ()) +#define IS_GTK_ROT_KNOB(obj) GTK_CHECK_TYPE (obj, gtk_rot_knob_get_type ()) -typedef struct _gtk_rot_ctrl GtkRotCtrl; -typedef struct _GtkRotCtrlClass GtkRotCtrlClass; +typedef struct _gtk_rot_knob GtkRotKnob; +typedef struct _GtkRotKnobClass GtkRotKnobClass; -struct _gtk_rot_ctrl +struct _gtk_rot_knob { GtkVBox vbox; @@ -69,17 +69,17 @@ gfloat value; }; -struct _GtkRotCtrlClass +struct _GtkRotKnobClass { GtkVBoxClass parent_class; }; -GtkType gtk_rot_ctrl_get_type (void); -GtkWidget* gtk_rot_ctrl_new (gfloat min, gfloat max, gfloat val); -void gtk_rot_ctrl_set_value (GtkRotCtrl *ctrl, gfloat val); -gfloat gtk_rot_ctrl_get_value (GtkRotCtrl *ctrl); +GtkType gtk_rot_knob_get_type (void); +GtkWidget* gtk_rot_knob_new (gfloat min, gfloat max, gfloat val); +void gtk_rot_knob_set_value (GtkRotKnob *knob, gfloat val); +gfloat gtk_rot_knob_get_value (GtkRotKnob *knob); @@ -88,4 +88,4 @@ } #endif /* __cplusplus */ -#endif /* __GTK_ROT_CTRL_H__ */ +#endif /* __GTK_ROT_knob_H__ */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-05-01 14:10:41
|
Revision: 49 http://gpredict.svn.sourceforge.net/gpredict/?rev=49&view=rev Author: csete Date: 2008-05-01 07:10:48 -0700 (Thu, 01 May 2008) Log Message: ----------- Change GtkFreqCtrl to GtkFreqKnob. Modified Paths: -------------- trunk/src/gtk-freq-knob.c trunk/src/gtk-freq-knob.h Modified: trunk/src/gtk-freq-knob.c =================================================================== --- trunk/src/gtk-freq-knob.c 2008-05-01 14:04:46 UTC (rev 48) +++ trunk/src/gtk-freq-knob.c 2008-05-01 14:10:48 UTC (rev 49) @@ -34,54 +34,54 @@ */ #include <gtk/gtk.h> #include <glib/gi18n.h> -#include "gtk-freq-ctrl.h" +#include "gtk-freq-knob.h" #ifdef HAVE_CONFIG_H # include <build-config.h> #endif -static void gtk_freq_ctrl_class_init (GtkFreqCtrlClass *class); -static void gtk_freq_ctrl_init (GtkFreqCtrl *list); -static void gtk_freq_ctrl_destroy (GtkObject *object); +static void gtk_freq_knob_class_init (GtkFreqKnobClass *class); +static void gtk_freq_knob_init (GtkFreqKnob *list); +static void gtk_freq_knob_destroy (GtkObject *object); -static void gtk_freq_ctrl_update (GtkFreqCtrl *ctrl); +static void gtk_freq_knob_update (GtkFreqKnob *knob); static GtkHBoxClass *parent_class = NULL; GType -gtk_freq_ctrl_get_type () +gtk_freq_knob_get_type () { - static GType gtk_freq_ctrl_type = 0; + static GType gtk_freq_knob_type = 0; - if (!gtk_freq_ctrl_type) { + if (!gtk_freq_knob_type) { - static const GTypeInfo gtk_freq_ctrl_info = { - sizeof (GtkFreqCtrlClass), + static const GTypeInfo gtk_freq_knob_info = { + sizeof (GtkFreqKnobClass), NULL, /* base_init */ NULL, /* base_finalize */ - (GClassInitFunc) gtk_freq_ctrl_class_init, + (GClassInitFunc) gtk_freq_knob_class_init, NULL, /* class_finalize */ NULL, /* class_data */ - sizeof (GtkFreqCtrl), + sizeof (GtkFreqKnob), 5, /* n_preallocs */ - (GInstanceInitFunc) gtk_freq_ctrl_init, + (GInstanceInitFunc) gtk_freq_knob_init, }; - gtk_freq_ctrl_type = g_type_register_static (GTK_TYPE_VBOX, - "GtkFreqCtrl", - >k_freq_ctrl_info, + gtk_freq_knob_type = g_type_register_static (GTK_TYPE_VBOX, + "GtkFreqKnob", + >k_freq_knob_info, 0); } - return gtk_freq_ctrl_type; + return gtk_freq_knob_type; } static void -gtk_freq_ctrl_class_init (GtkFreqCtrlClass *class) +gtk_freq_knob_class_init (GtkFreqKnobClass *class) { GObjectClass *gobject_class; GtkObjectClass *object_class; @@ -95,21 +95,21 @@ parent_class = g_type_class_peek_parent (class); - object_class->destroy = gtk_freq_ctrl_destroy; + object_class->destroy = gtk_freq_knob_destroy; } static void -gtk_freq_ctrl_init (GtkFreqCtrl *ctrl) +gtk_freq_knob_init (GtkFreqKnob *knob) { } static void -gtk_freq_ctrl_destroy (GtkObject *object) +gtk_freq_knob_destroy (GtkObject *object) { (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } @@ -122,16 +122,16 @@ * */ GtkWidget * -gtk_freq_ctrl_new (gdouble val) +gtk_freq_knob_new (gdouble val) { GtkWidget *widget; GtkWidget *table; - widget = g_object_new (GTK_TYPE_FREQ_CTRL, NULL); + widget = g_object_new (GTK_TYPE_FREQ_KNOB, NULL); - GTK_FREQ_CTRL(widget)->value = val; - gtk_freq_ctrl_update (GTK_FREQ_CTRL(widget)); + GTK_FREQ_KNOB(widget)->value = val; + gtk_freq_knob_update (GTK_FREQ_KNOB(widget)); gtk_widget_show_all (widget); @@ -140,42 +140,42 @@ /** \brief Set the value of the frequency control widget. - * \param[in] ctrl THe frequency control widget. + * \param[in] knob THe frequency control widget. * \param[in] val The new value. * */ void -gtk_freq_ctrl_set_value (GtkFreqCtrl *ctrl, gdouble val) +gtk_freq_knob_set_value (GtkFreqKnob *knob, gdouble val) { /* set the new value */ - ctrl->value = val; + knob->value = val; /* update the display */ - gtk_freq_ctrl_update (ctrl); + gtk_freq_knob_update (knob); } /** \brief Get the current value of the frequency control widget. - * \param[in] ctrl The frequency control widget. + * \param[in] knob The frequency control widget. * \return The current value. * - * Hint: For reading the value you can also access ctrl->value. + * Hint: For reading the value you can also access knob->value. * */ gdouble -gtk_freq_ctrl_get_value (GtkFreqCtrl *ctrl) +gtk_freq_knob_get_value (GtkFreqKnob *knob) { - return ctrl->value; + return knob->value; } /** \brief Update frequency display widget. - * \param[in] ctrl The frequency control widget. + * \param[in] knob The frequency control widget. * */ static void -gtk_freq_ctrl_update (GtkFreqCtrl *ctrl) +gtk_freq_knob_update (GtkFreqKnob *knob) { } Modified: trunk/src/gtk-freq-knob.h =================================================================== --- trunk/src/gtk-freq-knob.h 2008-05-01 14:04:46 UTC (rev 48) +++ trunk/src/gtk-freq-knob.h 2008-05-01 14:10:48 UTC (rev 49) @@ -25,8 +25,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, visit http://www.fsf.org/ */ -#ifndef __GTK_FREQ_CTRL_H__ -#define __GTK_FREQ_CTRL_H__ 1 +#ifndef __GTK_FREQ_KNOB_H__ +#define __GTK_FREQ_KNOB_H__ 1 #include <glib.h> #include <glib/gi18n.h> @@ -40,41 +40,41 @@ -#define GTK_TYPE_FREQ_CTRL (gtk_freq_ctrl_get_type ()) -#define GTK_FREQ_CTRL(obj) GTK_CHECK_CAST (obj,\ - gtk_freq_ctrl_get_type (),\ - GtkFreqCtrl) +#define GTK_TYPE_FREQ_KNOB (gtk_freq_knob_get_type ()) +#define GTK_FREQ_KNOB(obj) GTK_CHECK_CAST (obj,\ + gtk_freq_knob_get_type (),\ + GtkFreqKnob) -#define GTK_FREQ_CTRL_CLASS(klass) GTK_CHECK_CLASS_CAST (klass,\ - gtk_freq_ctrl_get_type (),\ - GtkFreqCtrlClass) +#define GTK_FREQ_KNOB_CLASS(klass) GTK_CHECK_CLASS_CAST (klass,\ + gtk_freq_knob_get_type (),\ + GtkFreqKnobClass) -#define IS_GTK_FREQ_CTRL(obj) GTK_CHECK_TYPE (obj, gtk_freq_ctrl_get_type ()) +#define IS_GTK_FREQ_KNOB(obj) GTK_CHECK_TYPE (obj, gtk_freq_knob_get_type ()) -typedef struct _gtk_freq_ctrl GtkFreqCtrl; -typedef struct _GtkFreqCtrlClass GtkFreqCtrlClass; +typedef struct _gtk_freq_knob GtkFreqKnob; +typedef struct _GtkFreqKnobClass GtkFreqKnobClass; -struct _gtk_freq_ctrl +struct _gtk_freq_knob { GtkVBox vbox; gdouble value; }; -struct _GtkFreqCtrlClass +struct _GtkFreqKnobClass { GtkVBoxClass parent_class; }; -GtkType gtk_freq_ctrl_get_type (void); -GtkWidget* gtk_freq_ctrl_new (gdouble val); -void gtk_freq_ctrl_set_value (GtkFreqCtrl *ctrl, gdouble val); -gdouble gtk_freq_ctrl_get_value (GtkFreqCtrl *ctrl); +GtkType gtk_freq_knob_get_type (void); +GtkWidget* gtk_freq_knob_new (gdouble val); +void gtk_freq_knob_set_value (GtkFreqKnob *knob, gdouble val); +gdouble gtk_freq_knob_get_value (GtkFreqKnob *knob); @@ -83,4 +83,4 @@ } #endif /* __cplusplus */ -#endif /* __GTK_FREQ_CTRL_H__ */ +#endif /* __GTK_FREQ_KNOB_H__ */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-05-02 23:35:16
|
Revision: 54 http://gpredict.svn.sourceforge.net/gpredict/?rev=54&view=rev Author: csete Date: 2008-05-02 16:35:22 -0700 (Fri, 02 May 2008) Log Message: ----------- Done some work on the rotator control widget and its integration into GtkSatModule. Modified Paths: -------------- trunk/src/gtk-rot-ctrl.c trunk/src/gtk-rot-ctrl.h trunk/src/gtk-sat-module-popup.c trunk/src/gtk-sat-module.c trunk/src/gtk-sat-module.h Modified: trunk/src/gtk-rot-ctrl.c =================================================================== --- trunk/src/gtk-rot-ctrl.c 2008-05-02 07:09:58 UTC (rev 53) +++ trunk/src/gtk-rot-ctrl.c 2008-05-02 23:35:22 UTC (rev 54) @@ -37,26 +37,44 @@ #include <gtk/gtk.h> #include <glib/gi18n.h> #include <math.h> +#include "sat-log.h" #include "gtk-rot-ctrl.h" #ifdef HAVE_CONFIG_H # include <build-config.h> #endif +#define FMTSTR "%7.2f\302\260" + static void gtk_rot_ctrl_class_init (GtkRotCtrlClass *class); static void gtk_rot_ctrl_init (GtkRotCtrl *list); static void gtk_rot_ctrl_destroy (GtkObject *object); -static GtkWidget *create_status_widgets (void); -static GtkWidget *create_setup_widgets (void); -static GtkWidget *create_control_widgets (void); +static GtkWidget *create_az_widgets (GtkRotCtrl *ctrl); +static GtkWidget *create_el_widgets (GtkRotCtrl *ctrl); +static GtkWidget *create_target_widgets (GtkRotCtrl *ctrl); +static GtkWidget *create_conf_widgets (GtkRotCtrl *ctrl); +static GtkWidget *create_plot_widget (GtkRotCtrl *ctrl); +static void store_sats (gpointer key, gpointer value, gpointer user_data); +static void sat_selected_cb (GtkComboBox *satsel, gpointer data); +static void track_toggle_cb (GtkToggleButton *button, gpointer data); +static void delay_changed_cb (GtkSpinButton *spin, gpointer data); +static void toler_changed_cb (GtkSpinButton *spin, gpointer data); +static gboolean rot_ctrl_timeout_cb (gpointer data); + + static GtkVBoxClass *parent_class = NULL; +static GdkColor ColBlack = { 0, 0, 0, 0}; +static GdkColor ColWhite = { 0, 0xFFFF, 0xFFFF, 0xFFFF}; +static GdkColor ColRed = { 0, 0xFFFF, 0, 0}; +static GdkColor ColGreen = {0, 0, 0xFFFF, 0}; + GType gtk_rot_ctrl_get_type () { @@ -110,13 +128,27 @@ static void gtk_rot_ctrl_init (GtkRotCtrl *ctrl) { - + ctrl->sats = NULL; + ctrl->target = NULL; + ctrl->tracking = FALSE; + ctrl->busy = FALSE; + ctrl->delay = 1000; + ctrl->timerid = 0; + ctrl->tolerance = 1.0; } static void gtk_rot_ctrl_destroy (GtkObject *object) { + GtkRotCtrl *ctrl = GTK_ROT_CTRL (object); + + + /* stop timer */ + if (ctrl->timerid > 0) + g_source_remove (ctrl->timerid); + + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } @@ -127,89 +159,364 @@ * */ GtkWidget * -gtk_rot_ctrl_new () +gtk_rot_ctrl_new (GtkSatModule *module) { GtkWidget *widget; GtkWidget *table; - guint i; widget = g_object_new (GTK_TYPE_ROT_CTRL, NULL); + + /* store satellites */ + g_hash_table_foreach (module->satellites, store_sats, widget); + + GTK_ROT_CTRL (widget)->target = SAT (g_slist_nth_data (GTK_ROT_CTRL (widget)->sats, 0)); + + /* initialise custom colors */ + gdk_rgb_find_color (gtk_widget_get_colormap (widget), &ColBlack); + gdk_rgb_find_color (gtk_widget_get_colormap (widget), &ColWhite); + gdk_rgb_find_color (gtk_widget_get_colormap (widget), &ColRed); + gdk_rgb_find_color (gtk_widget_get_colormap (widget), &ColGreen); /* create contents */ - table = gtk_table_new (2, 2, FALSE); - gtk_table_attach (GTK_TABLE (table), create_status_widgets (), - 0, 2, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 5, 5); - gtk_table_attach (GTK_TABLE (table), create_setup_widgets (), - 0, 1, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 5, 5); - gtk_table_attach (GTK_TABLE (table), create_control_widgets (), - 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 5, 5); + table = gtk_table_new (3, 2, TRUE); + gtk_table_set_row_spacings (GTK_TABLE (table), 5); + gtk_table_set_col_spacings (GTK_TABLE (table), 5); + gtk_container_set_border_width (GTK_CONTAINER (table), 10); + gtk_table_attach (GTK_TABLE (table), create_az_widgets (GTK_ROT_CTRL (widget)), + 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach (GTK_TABLE (table), create_el_widgets (GTK_ROT_CTRL (widget)), + 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach (GTK_TABLE (table), create_target_widgets (GTK_ROT_CTRL (widget)), + 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach (GTK_TABLE (table), create_conf_widgets (GTK_ROT_CTRL (widget)), + 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach (GTK_TABLE (table), create_plot_widget (GTK_ROT_CTRL (widget)), + 1, 2, 1, 3, GTK_FILL, GTK_FILL, 0, 0); gtk_container_add (GTK_CONTAINER (widget), table); + GTK_ROT_CTRL (widget)->timerid = g_timeout_add (GTK_ROT_CTRL (widget)->delay, + rot_ctrl_timeout_cb, + GTK_ROT_CTRL (widget)); + return widget; } -/** \brief Create status widgets. */ -static GtkWidget *create_status_widgets () +/** \brief Update rotator control state. + * \param ctrl Pointer to the GtkRotCtrl. + * + * This function is called by the parent, i.e. GtkSatModule, indicating that + * the satellite data has been updated. The function updates the internal state + * of the controller and the rotator. + */ +void +gtk_rot_ctrl_update (GtkRotCtrl *ctrl, gdouble t) { - GtkWidget *frame,*table,*label,*ctrbut; + gchar *buff; - table = gtk_table_new (3,7, TRUE); + if (ctrl->target) { + /* update target displays */ + buff = g_strdup_printf (FMTSTR, ctrl->target->az); + gtk_label_set_text (GTK_LABEL (ctrl->AzSat), buff); + g_free (buff); + buff = g_strdup_printf (FMTSTR, ctrl->target->el); + gtk_label_set_text (GTK_LABEL (ctrl->ElSat), buff); + g_free (buff); + } +} + + +/** \brief Create azimuth control widgets. + * \param ctrl Pointer to the GtkRotCtrl widget. + * + * This function creates and initialises the widgets for controlling the + * azimuth of the the rotator. + */ +static +GtkWidget *create_az_widgets (GtkRotCtrl *ctrl) +{ + GtkWidget *frame; - /* table header */ - label = gtk_label_new (NULL); - gtk_label_set_markup (GTK_LABEL (label), "<b>SAT</b>"); - gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, 0, 1); + frame = gtk_frame_new (_("Azimuth")); - label = gtk_label_new (NULL); - gtk_label_set_markup (GTK_LABEL (label), "<b>\316\224</b>"); - gtk_table_attach_defaults (GTK_TABLE (table), label, 2, 3, 0, 1); + return frame; +} + + +/** \brief Create elevation control widgets. + * \param ctrl Pointer to the GtkRotCtrl widget. + * + * This function creates and initialises the widgets for controlling the + * elevation of the the rotator. + */ +static +GtkWidget *create_el_widgets (GtkRotCtrl *ctrl) +{ + GtkWidget *frame; - label = gtk_label_new (NULL); - gtk_label_set_markup (GTK_LABEL (label), "<b>SET</b>"); - gtk_table_attach_defaults (GTK_TABLE (table), label, 4, 5, 0, 1); + frame = gtk_frame_new (_("Elevation")); - label = gtk_label_new (NULL); - gtk_label_set_markup (GTK_LABEL (label), "<b>READ</b>"); - gtk_table_attach_defaults (GTK_TABLE (table), label, 5, 6, 0, 1); + return frame; +} + +/** \brief Create target widgets. + * \param ctrl Pointer to the GtkRotCtrl widget. + */ +static +GtkWidget *create_target_widgets (GtkRotCtrl *ctrl) +{ + GtkWidget *frame,*table,*label,*satsel,*track; + gchar *buff; + guint i, n; + sat_t *sat = NULL; - /* Azimuth widgets */ - label = gtk_label_new (NULL); - gtk_label_set_markup (GTK_LABEL (label), "<b>AZ:</b>"); + + buff = g_strdup_printf (FMTSTR, 0.0); + + table = gtk_table_new (4, 3, FALSE); + gtk_table_set_col_spacings (GTK_TABLE (table), 5); + + /* sat selector */ + satsel = gtk_combo_box_new_text (); + n = g_slist_length (ctrl->sats); + for (i = 0; i < n; i++) { + sat = SAT (g_slist_nth_data (ctrl->sats, i)); + if (sat) { + gtk_combo_box_append_text (GTK_COMBO_BOX (satsel), sat->tle.sat_name); + } + } + gtk_combo_box_set_active (GTK_COMBO_BOX (satsel), 0); + gtk_widget_set_tooltip_text (satsel, _("Select target object")); + g_signal_connect (satsel, "changed", G_CALLBACK (sat_selected_cb), ctrl); + gtk_table_attach (GTK_TABLE (table), satsel, 0, 2, 0, 1, + GTK_FILL, GTK_FILL, 5, 5); + + /* tracking button */ + track = gtk_toggle_button_new_with_label (_("Track")); + gtk_widget_set_tooltip_text (track, _("Track the satellite when it is within range")); + gtk_table_attach (GTK_TABLE (table), track, 2, 3, 0, 1, + GTK_SHRINK, GTK_SHRINK, 5, 0); + g_signal_connect (track, "toggled", G_CALLBACK (track_toggle_cb), ctrl); + + /* Azimuth */ + label = gtk_label_new (_("Az:")); + gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2); - /* Eevation widgets */ - label = gtk_label_new (NULL); - gtk_label_set_markup (GTK_LABEL (label), "<b>EL:</b>"); + ctrl->AzSat = gtk_label_new (buff); + gtk_misc_set_alignment (GTK_MISC (ctrl->AzSat), 1.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), ctrl->AzSat, 1, 2, 1, 2); + + + /* Elevation */ + label = gtk_label_new (_("El:")); + gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 2, 3); - frame = gtk_frame_new (_("STATUS")); + ctrl->ElSat = gtk_label_new (buff); + gtk_misc_set_alignment (GTK_MISC (ctrl->ElSat), 1.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), ctrl->ElSat, 1, 2, 2, 3); + + /* count down */ + label = gtk_label_new (_("Time:")); + gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 3, 4); + + frame = gtk_frame_new (_("Target")); + //gtk_container_set_border_width (GTK_CONTAINER (frame), 5); gtk_container_add (GTK_CONTAINER (frame), table); - gtk_frame_set_label_align (GTK_FRAME (frame), 0.5, 0.5); + g_free (buff); + return frame; } -/** \brief Create setup widgets. */ -static GtkWidget *create_setup_widgets () +static GtkWidget * +create_conf_widgets (GtkRotCtrl *ctrl) { - GtkWidget *frame; + GtkWidget *frame,*table,*label,*timer,*toler; - frame = gtk_frame_new (_("SETUP")); - gtk_frame_set_label_align (GTK_FRAME (frame), 0.5, 0.5); + table = gtk_table_new (2, 3, TRUE); + gtk_table_set_col_spacings (GTK_TABLE (table), 5); + /* Timeout */ + label = gtk_label_new (_("Cycle:")); + gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 0, 1); + + timer = gtk_spin_button_new_with_range (100, 5000, 10); + gtk_spin_button_set_digits (GTK_SPIN_BUTTON (timer), 0); + gtk_widget_set_tooltip_text (timer, + _("This parameter controls the delay between "\ + "commands sent to the rotator.")); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (timer), ctrl->delay); + g_signal_connect (timer, "value-changed", G_CALLBACK (delay_changed_cb), ctrl); + gtk_table_attach (GTK_TABLE (table), timer, 1, 2, 0, 1, + GTK_FILL, GTK_FILL, 0, 0); + + label = gtk_label_new (_("msec")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 2, 3, 0, 1); + + /* Tolerance */ + label = gtk_label_new (_("Tolerance:")); + gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2); + + toler = gtk_spin_button_new_with_range (0.0, 10.0, 0.1); + gtk_spin_button_set_digits (GTK_SPIN_BUTTON (toler), 1); + gtk_widget_set_tooltip_text (toler, + _("This parameter controls the tolerance between "\ + "the target and rotator values for the rotator.\n"\ + "If the difference between the target and rotator values "\ + "is smaller than the tolerance, no new commands are sent")); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (toler), ctrl->tolerance); + g_signal_connect (toler, "value-changed", G_CALLBACK (toler_changed_cb), ctrl); + gtk_table_attach (GTK_TABLE (table), toler, 1, 2, 1, 2, + GTK_FILL, GTK_FILL, 0, 0); + + + label = gtk_label_new (_("deg")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach_defaults (GTK_TABLE (table), label, 2, 3, 1, 2); + + + frame = gtk_frame_new (_("Settings")); + gtk_container_add (GTK_CONTAINER (frame), table); + return frame; } -/** \brief Create control buttons. */ -static GtkWidget *create_control_widgets () + +/** \brief Create target widgets. + * \param ctrl Pointer to the GtkRotCtrl widget. + */ +static +GtkWidget *create_plot_widget (GtkRotCtrl *ctrl) { GtkWidget *frame; - frame = gtk_frame_new (_("CONTROL")); - gtk_frame_set_label_align (GTK_FRAME (frame), 0.5, 0.5); + frame = gtk_frame_new (NULL); return frame; } + + +/** \brief Copy satellite from hash table to singly linked list. + */ +static void +store_sats (gpointer key, gpointer value, gpointer user_data) +{ + GtkRotCtrl *ctrl = GTK_ROT_CTRL( user_data); + sat_t *sat = SAT (value); + + ctrl->sats = g_slist_append (ctrl->sats, sat); +} + + +/** \brief Manage satellite selections + * \param satsel Pointer to the GtkComboBox. + * \param data Pointer to the GtkRotCtrl widget. + * + * This function is called when the user selects a new satellite. + */ +static void +sat_selected_cb (GtkComboBox *satsel, gpointer data) +{ + GtkRotCtrl *ctrl = GTK_ROT_CTRL (data); + gint i; + + i = gtk_combo_box_get_active (satsel); + if (i >= 0) { + ctrl->target = SAT (g_slist_nth_data (ctrl->sats, i)); + } + else { + sat_log_log (SAT_LOG_LEVEL_ERROR, + _("%s:%s: Invalid satellite selection: %d"), + __FILE__, __FUNCTION__, i); + } +} + + +/** \brief Manage toggle signals (tracking) + * \param button Pointer to the GtkToggle button. + * \param data Pointer to the GtkRotCtrl widget. + */ +static void +track_toggle_cb (GtkToggleButton *button, gpointer data) +{ + GtkRotCtrl *ctrl = GTK_ROT_CTRL (data); + + ctrl->tracking = gtk_toggle_button_get_active (button); +} + + +/** \brief Manage cycle delay changes. + * \param spin Pointer to the spin button. + * \param data Pointer to the GtkRotCtrl widget. + * + * This function is called when the user changes the value of the + * cycle delay. + */ +static void +delay_changed_cb (GtkSpinButton *spin, gpointer data) +{ + GtkRotCtrl *ctrl = GTK_ROT_CTRL (data); + + + ctrl->delay = (guint) gtk_spin_button_get_value (spin); + + if (ctrl->timerid > 0) + g_source_remove (ctrl->timerid); + + ctrl->timerid = g_timeout_add (ctrl->delay, rot_ctrl_timeout_cb, ctrl); +} + + + +/** \brief Manage tolerance changes. + * \param spin Pointer to the spin button. + * \param data Pointer to the GtkRotCtrl widget. + * + * This function is called when the user changes the value of the + * tolerance. + */ +static void +toler_changed_cb (GtkSpinButton *spin, gpointer data) +{ + GtkRotCtrl *ctrl = GTK_ROT_CTRL (data); + + ctrl->tolerance = gtk_spin_button_get_value (spin); +} + + + + +/** \brief Rotator controller timeout function + * \param data Pointer to the GtkRotCtrl widget. + * \return Always TRUE to let the timer continue. + */ +static gboolean +rot_ctrl_timeout_cb (gpointer data) +{ + GtkRotCtrl *ctrl = GTK_ROT_CTRL (data); + + if (ctrl->busy) { + sat_log_log (SAT_LOG_LEVEL_ERROR,_("%s missed the deadline"),__FUNCTION__); + return TRUE; + } + + ctrl->busy = TRUE; + + /* do something */ + + ctrl->busy = FALSE; + + return TRUE; +} + + + + Modified: trunk/src/gtk-rot-ctrl.h =================================================================== --- trunk/src/gtk-rot-ctrl.h 2008-05-02 07:09:58 UTC (rev 53) +++ trunk/src/gtk-rot-ctrl.h 2008-05-02 23:35:22 UTC (rev 54) @@ -31,8 +31,9 @@ #include <glib.h> #include <glib/gi18n.h> #include <gtk/gtk.h> +#include "sgpsdp/sgp4sdp4.h" +#include "gtk-sat-module.h" - #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -66,7 +67,19 @@ /* Elevation labels */ GtkWidget *ElSat,*ElDelta,*ElLock,*ElSet,*ElRead; + + /* other widgets */ + + /* satellites */ + GSList *sats; + sat_t *target; + guint delay; /*!< Timeout delay. */ + guint timerid; /*!< Timer ID */ + gdouble tolerance; /*!< Error tolerance */ + + gboolean tracking; + gboolean busy; }; struct _GtkRotCtrlClass @@ -77,7 +90,8 @@ GtkType gtk_rot_ctrl_get_type (void); -GtkWidget* gtk_rot_ctrl_new (void); +GtkWidget* gtk_rot_ctrl_new (GtkSatModule *module); +void gtk_rot_ctrl_update (GtkRotCtrl *ctrl, gdouble t); #ifdef __cplusplus Modified: trunk/src/gtk-sat-module-popup.c =================================================================== --- trunk/src/gtk-sat-module-popup.c 2008-05-02 07:09:58 UTC (rev 53) +++ trunk/src/gtk-sat-module-popup.c 2008-05-02 23:35:22 UTC (rev 54) @@ -59,6 +59,8 @@ static void delete_cb (GtkWidget *menuitem, gpointer data); static void close_cb (GtkWidget *menuitem, gpointer data); static void name_changed (GtkWidget *widget, gpointer data); +static void destroy_rotctrl (GtkWidget *window, gpointer data); +static void destroy_rigctrl (GtkWidget *window, gpointer data); static gint window_delete (GtkWidget *widget, GdkEvent *event, gpointer data); @@ -243,7 +245,24 @@ static void config_cb (GtkWidget *menuitem, gpointer data) { - gtk_sat_module_config_cb (menuitem, data); + GtkSatModule *module = GTK_SAT_MODULE (data); + + if (module->rigctrlwin || module->rotctrlwin) { + GtkWidget *dialog; + /* FIXME: should offer option to close controllers */ + dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + _("A module can not be configured while the "\ + "radio or rotator controller is active.\n\n"\ + "Please close the radio and rotator controllers "\ + "and try again.")); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } + else { + gtk_sat_module_config_cb (menuitem, data); + } } @@ -848,30 +867,54 @@ rigctrl_cb (GtkWidget *menuitem, gpointer data) { GtkSatModule *module = GTK_SAT_MODULE (data); - GtkWidget *window; GtkWidget *rigctrl; gchar *buff; + if (module->rigctrlwin != NULL) { + /* there is already a roto controller for this module */ + gtk_window_present (GTK_WINDOW (module->rigctrlwin)); + return; + } - //rigctrl = gtk_rig_ctrl_new (); + //rigctrl = gtk_rot_ctrl_new (); /* create a window */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - buff = g_strdup_printf (_("Gpredict Radio Control (%s)"), module->name); - gtk_window_set_title (GTK_WINDOW (window), buff); + module->rigctrlwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); + buff = g_strdup_printf (_("Gpredict Radio Control: %s"), module->name); + gtk_window_set_title (GTK_WINDOW (module->rigctrlwin), buff); g_free (buff); - g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (window_delete), NULL); + g_signal_connect (G_OBJECT (module->rigctrlwin), "delete_event", + G_CALLBACK (window_delete), NULL); + g_signal_connect (G_OBJECT (module->rigctrlwin), "destroy", + G_CALLBACK (destroy_rigctrl), module); /* window icon */ buff = icon_file_name ("gpredict-oscilloscope.png"); - gtk_window_set_icon_from_file (GTK_WINDOW (window), buff, NULL); + gtk_window_set_icon_from_file (GTK_WINDOW (module->rigctrlwin), buff, NULL); g_free (buff); - //gtk_container_add (GTK_CONTAINER (window), rigctrl); + //gtk_container_add (GTK_CONTAINER (module->rigctrlwin), rigctrl); - gtk_widget_show_all (window); + gtk_widget_show_all (module->rigctrlwin); + } + +/** \brief Destroy radio control window. + * \param window Pointer to the radio control window. + * \param data Pointer to the GtkSatModule to which this controller is attached. + * + * This function is called automatically when the window is destroyed. + */ +static void +destroy_rigctrl (GtkWidget *window, gpointer data) +{ + GtkSatModule *module = GTK_SAT_MODULE (data); + + module->rigctrlwin = NULL; +} + + /** \brief Open antenna rotator control window. * \param menuitem The menuitem that was selected. * \param data Pointer the GtkSatModule. @@ -880,34 +923,65 @@ rotctrl_cb (GtkWidget *menuitem, gpointer data) { GtkSatModule *module = GTK_SAT_MODULE (data); - GtkWidget *window; GtkWidget *rotctrl; gchar *buff; + if (module->rotctrlwin != NULL) { + /* there is already a roto controller for this module */ + gtk_window_present (GTK_WINDOW (module->rotctrlwin)); + return; + } - rotctrl = gtk_rot_ctrl_new (); + rotctrl = gtk_rot_ctrl_new (module); + module->rotctrl = rotctrl; /* create a window */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - buff = g_strdup_printf (_("Gpredict Rotator Control (%s)"), module->name); - gtk_window_set_title (GTK_WINDOW (window), buff); + module->rotctrlwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); + buff = g_strdup_printf (_("Gpredict Rotator Control: %s"), module->name); + gtk_window_set_title (GTK_WINDOW (module->rotctrlwin), buff); g_free (buff); - g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (window_delete), NULL); + g_signal_connect (G_OBJECT (module->rotctrlwin), "delete_event", + G_CALLBACK (window_delete), module); + g_signal_connect (G_OBJECT (module->rotctrlwin), "destroy", + G_CALLBACK (destroy_rotctrl), module); /* window icon */ buff = icon_file_name ("gpredict-antenna.png"); - gtk_window_set_icon_from_file (GTK_WINDOW (window), buff, NULL); + gtk_window_set_icon_from_file (GTK_WINDOW (module->rotctrlwin), buff, NULL); g_free (buff); - gtk_container_add (GTK_CONTAINER (window), rotctrl); + gtk_container_add (GTK_CONTAINER (module->rotctrlwin), rotctrl); - /* store pointer to window */ + gtk_widget_show_all (module->rotctrlwin); +} + + +/** \brief Destroy rotator control window. + * \param window Pointer to the rotator control window. + * \param data Pointer to the GtkSatModule to which this controller is attached. + * + * This function is called automatically when the window is destroyed. + */ +static void +destroy_rotctrl (GtkWidget *window, gpointer data) +{ + GtkSatModule *module = GTK_SAT_MODULE (data); - gtk_widget_show_all (window); + module->rotctrlwin = NULL; + module->rotctrl = NULL; } +/* ensure that deleted top-level windows are destroyed */ +static gint +window_delete (GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + return FALSE; +} + /** \brief Close module. * * This function is called when the user selects the close menu @@ -1040,17 +1114,7 @@ -/* ensure that deleted top-level windows are destroyed */ -static gint -window_delete (GtkWidget *widget, - GdkEvent *event, - gpointer data) -{ - return FALSE; -} - - /** \brief Snoop window position and size when main window receives configure event. * \param widget Pointer to the module window. * \param event Pointer to the event structure. Modified: trunk/src/gtk-sat-module.c =================================================================== --- trunk/src/gtk-sat-module.c 2008-05-02 07:09:58 UTC (rev 53) +++ trunk/src/gtk-sat-module.c 2008-05-02 23:35:22 UTC (rev 54) @@ -64,6 +64,7 @@ #include "gtk-polar-view.h" #include "gtk-single-sat.h" #include "gtk-met.h" +#include "gtk-rot-ctrl.h" //#ifdef G_OS_WIN32 //# include "libc_internal.h" @@ -96,7 +97,6 @@ static void reload_sats_in_child (GtkWidget *widget, GtkSatModule *module); -static void destroy_gtk_widget (gpointer data); static GtkVBoxClass *parent_class = NULL; @@ -168,17 +168,10 @@ g_free, g_free); - module->rotctrl = g_hash_table_new_full (g_int_hash, - g_int_equal, - g_free, - destroy_gtk_widget); - - module->rigctrl = g_hash_table_new_full (g_int_hash, - g_int_equal, - g_free, - destroy_gtk_widget); + module->rotctrlwin = NULL; + module->rotctrl = NULL; + module->rigctrlwin = NULL; - module->state = GTK_SAT_MOD_STATE_DOCKED; module->busy = FALSE; @@ -190,6 +183,8 @@ module->vpanedpos = -1; module->hpanedpos = -1; + module->timerid = 0; + module->throttle = 1; module->rtNow = 0.0; module->rtPrev = 0.0; @@ -208,7 +203,7 @@ /* stop timeout */ - if (module->timerid != -1) + if (module->timerid > 0) g_source_remove (module->timerid); /* destroy time controller */ @@ -216,19 +211,15 @@ gtk_widget_destroy (module->tmgWin); module->tmgActive = FALSE; } - - /* destroy radio controllers */ - if (module->rigctrl) { - g_hash_table_destroy (module->rigctrl); - module->rigctrl = NULL; - } - /* destroy rotator controllers */ - if (module->rotctrl) { - g_hash_table_destroy (module->rotctrl); - module->rotctrl = NULL; + /* destroy radio and rotator controllers */ + if (module->rigctrlwin) { + gtk_widget_destroy (module->rigctrlwin); } - + if (module->rotctrlwin) { + gtk_widget_destroy (module->rotctrlwin); + } + /* clean up QTH */ if (module->qth) { gtk_sat_data_free_qth (module->qth); @@ -877,6 +868,10 @@ if (mod->child_3 != NULL) update_child (mod->child_3, mod->tmgCdnum); + /* send notice to radio and rotator controller */ + if (mod->rotctrl) + gtk_rot_ctrl_update (GTK_ROT_CTRL (mod->rotctrl), mod->tmgCdnum); + mod->event_count++; @@ -1545,7 +1540,8 @@ if (GTK_SAT_MODULE (module)->child_3 != NULL) reload_sats_in_child (GTK_SAT_MODULE (module)->child_3, GTK_SAT_MODULE (module)); - + /* FIXME: radio and rotator controller */ + /* unlock module */ module->busy = FALSE; @@ -1597,15 +1593,3 @@ { } - -/** \brief Destroy a Gtk+ widget. - * \param data Pointer to the widget to destroy. - * - * This function is a simple wrapper for gtk_widget_destroy. The difference is - * in the parameter types; this wrapper can be used as a GDestroyNotify callback. - */ -static void -destroy_gtk_widget (gpointer data) -{ - gtk_widget_destroy (GTK_WIDGET (data)); -} Modified: trunk/src/gtk-sat-module.h =================================================================== --- trunk/src/gtk-sat-module.h 2008-05-02 07:09:58 UTC (rev 53) +++ trunk/src/gtk-sat-module.h 2008-05-02 23:35:22 UTC (rev 54) @@ -93,6 +93,10 @@ GtkWidget *win; /*!< Window when module is not docked */ + GtkWidget *rotctrlwin; /*!< Rotator controller window */ + GtkWidget *rotctrl; + GtkWidget *rigctrlwin; /*!< Radio controller window */ + GtkWidget *header; guint head_count; guint head_timeout; @@ -116,8 +120,6 @@ qth_t *qth; /*!< QTH information. */ GHashTable *satellites; /*!< Satellites. */ - GHashTable *rotctrl; /*!< Rotator controllers. */ - GHashTable *rigctrl; /*!< Radio controllers. */ guint32 timeout; /*!< Timeout value [msec] */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |