summaryrefslogtreecommitdiff
path: root/src/model/schematic.c
diff options
context:
space:
mode:
authorRuben Undheim <ruben.undheim@gmail.com>2018-07-13 06:17:58 +0000
committerRuben Undheim <ruben.undheim@gmail.com>2018-07-13 06:17:58 +0000
commit9e0bd16a997e55d6b9c2e80734ea8e61794c7602 (patch)
treed73377e0368b0c730d5a14019b1eee53897505bf /src/model/schematic.c
parente1fffcb07ce0d8b0db9e0b4b5e1e0c1128197af5 (diff)
New upstream version 0.84.22
Diffstat (limited to 'src/model/schematic.c')
-rw-r--r--src/model/schematic.c806
1 files changed, 391 insertions, 415 deletions
diff --git a/src/model/schematic.c b/src/model/schematic.c
index 7329441..2cf6294 100644
--- a/src/model/schematic.c
+++ b/src/model/schematic.c
@@ -7,12 +7,16 @@
* Ricardo Markiewicz <rmarkie@fi.uba.ar>
* Andres de Barbara <adebarbara@fi.uba.ar>
* Marc Lorber <lorber.marc@wanadoo.fr>
+ * Bernhard Schuster <bernhard@ahoi.io>
+ * Guido Trentalancia <guido@trentalancia.com>
*
- * Web page: https://github.com/marc-lorber/oregano
+ * Web page: https://ahoi.io/project/oregano
*
* Copyright (C) 1999-2001 Richard Hult
* Copyright (C) 2003,2006 Ricardo Markiewicz
* Copyright (C) 2009-2012 Marc Lorber
+ * Copyright (C) 2013 Bernhard Schuster
+ * Copyright (C) 2017 Guido Trentalancia
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -26,8 +30,8 @@
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
#include <gtk/gtk.h>
@@ -40,13 +44,15 @@
#include "node-store.h"
#include "file-manager.h"
#include "settings.h"
-#include "sim-settings.h"
+#include "../sim-settings-gui.h"
#include "simulation.h"
#include "errors.h"
#include "schematic-print-context.h"
+#include "log.h"
-#define NG_DEBUG(s) if (0) g_print ("%s\n", s)
-typedef struct _SchematicsPrintOptions {
+#include "debug.h"
+typedef struct _SchematicsPrintOptions
+{
GtkColorButton *components;
GtkColorButton *labels;
GtkColorButton *wires;
@@ -54,49 +60,41 @@ typedef struct _SchematicsPrintOptions {
GtkColorButton *background;
} SchematicPrintOptions;
-struct _SchematicPriv {
- char *title;
- char *filename;
- char *author;
- char *comments;
- char *netlist_filename;
+struct _SchematicPriv
+{
+ char *oregano_version;
+ char *title;
+ char *filename;
+ char *author;
+ char *comments;
+ char *netlist_filename;
- SchematicColors colors;
- SchematicPrintOptions *printoptions;
+ SchematicColors colors;
+ SchematicPrintOptions *printoptions;
// Data for various dialogs.
- gpointer settings;
- gpointer sim_settings;
- gpointer simulation;
+ gpointer settings;
+ SimSettingsGui *sim_settings;
+ gpointer simulation;
- GList *current_items;
+ GList *current_items;
- NodeStore *store;
- GHashTable *symbols;
- GHashTable *refdes_values;
+ NodeStore *store;
+ GHashTable *symbols;
+ GHashTable *refdes_values;
- double zoom;
+ guint width;
+ guint height;
- gboolean dirty;
+ double zoom;
- GtkTextBuffer *log;
- GtkTextTag *tag_error;
-};
+ gboolean dirty;
+
+ Log *logstore;
-typedef enum {
- REFDATA_SINGLE,
- REFDATA_RANGE,
- REFDATA_MIN,
- REFDATA_MAX
-} RefDataType;
-
-typedef struct {
- RefDataType type;
- union {
- int nr;
- struct { int min; int max; } range;
- } u;
-} RefData;
+ GtkTextBuffer *log;
+ GtkTextTag *tag_error;
+};
enum {
TITLE_CHANGED,
@@ -108,88 +106,66 @@ enum {
LAST_SIGNAL
};
-G_DEFINE_TYPE (Schematic, schematic, G_TYPE_OBJECT)
+G_DEFINE_TYPE (Schematic, schematic, G_TYPE_OBJECT);
static void schematic_init (Schematic *schematic);
-static void schematic_class_init (SchematicClass *klass);
+static void schematic_class_init (SchematicClass *klass);
static void schematic_finalize (GObject *object);
static void schematic_dispose (GObject *object);
static void item_data_destroy_callback (gpointer s, GObject *data);
-static void item_moved_callback (ItemData *data, SheetPos *pos, Schematic *sm);
+static void item_moved_callback (ItemData *data, Coords *pos, Schematic *sm);
-static int schematic_get_lowest_available_refdes (Schematic *schematic,
- char *prefix);
-static void schematic_set_lowest_available_refdes (Schematic *schematic,
- char *prefix, int num);
+static int schematic_get_lowest_available_refdes (Schematic *schematic, char *prefix);
+static void schematic_set_lowest_available_refdes (Schematic *schematic, char *prefix, int num);
static GObjectClass *parent_class = NULL;
-static guint schematic_signals[LAST_SIGNAL] = { 0 };
+static guint schematic_signals[LAST_SIGNAL] = {0};
static GList *schematic_list = NULL;
static int schematic_count_ = 0;
-static void
-schematic_class_init (SchematicClass *klass)
+static void schematic_class_init (SchematicClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
- schematic_signals[TITLE_CHANGED] = g_signal_new ("title_changed",
- TYPE_SCHEMATIC,
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (SchematicClass, title_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1,
- G_TYPE_STRING );
-
- schematic_signals[LAST_SCHEMATIC_DESTROYED] = g_signal_new ("last_schematic_destroyed",
- TYPE_SCHEMATIC,
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (SchematicClass, last_schematic_destroyed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- schematic_signals[ITEM_DATA_ADDED] = g_signal_new ("item_data_added",
- TYPE_SCHEMATIC,
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (SchematicClass, item_data_added),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
-
- schematic_signals[NODE_DOT_ADDED] = g_signal_new ("node_dot_added",
- TYPE_SCHEMATIC,
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (SchematicClass, node_dot_added),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
-
- schematic_signals[NODE_DOT_REMOVED] = g_signal_new ("node_dot_removed",
- TYPE_SCHEMATIC,
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (SchematicClass, node_dot_removed),
- NULL, NULL, g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
-
- schematic_signals[LOG_UPDATED] = g_signal_new ("log_updated",
- TYPE_SCHEMATIC,
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (SchematicClass, log_updated),
- NULL, NULL, g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,0);
+ schematic_signals[TITLE_CHANGED] =
+ g_signal_new ("title_changed", TYPE_SCHEMATIC, G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (SchematicClass, title_changed), NULL, NULL,
+ g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
+
+ schematic_signals[LAST_SCHEMATIC_DESTROYED] =
+ g_signal_new ("last_schematic_destroyed", TYPE_SCHEMATIC, G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (SchematicClass, last_schematic_destroyed), NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+ schematic_signals[ITEM_DATA_ADDED] =
+ g_signal_new ("item_data_added", TYPE_SCHEMATIC, G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (SchematicClass, item_data_added), NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
+
+ schematic_signals[NODE_DOT_ADDED] =
+ g_signal_new ("node_dot_added", TYPE_SCHEMATIC, G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (SchematicClass, node_dot_added), NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
+
+ schematic_signals[NODE_DOT_REMOVED] =
+ g_signal_new ("node_dot_removed", TYPE_SCHEMATIC, G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (SchematicClass, node_dot_removed), NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
+
+ schematic_signals[LOG_UPDATED] =
+ g_signal_new ("log_updated", TYPE_SCHEMATIC, G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (SchematicClass, log_updated), NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
object_class->finalize = schematic_finalize;
object_class->dispose = schematic_dispose;
}
-static void
-node_dot_added_callback (NodeStore *store, SheetPos *pos, Schematic *schematic)
+static void node_dot_added_callback (NodeStore *store, Coords *pos, Schematic *schematic)
{
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
@@ -197,8 +173,7 @@ node_dot_added_callback (NodeStore *store, SheetPos *pos, Schematic *schematic)
g_signal_emit_by_name (schematic, "node_dot_added", pos);
}
-static void
-node_dot_removed_callback (NodeStore *store, SheetPos *pos, Schematic *schematic)
+static void node_dot_removed_callback (NodeStore *store, Coords *pos, Schematic *schematic)
{
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
@@ -206,8 +181,7 @@ node_dot_removed_callback (NodeStore *store, SheetPos *pos, Schematic *schematic
g_signal_emit_by_name (schematic, "node_dot_removed", pos);
}
-static void
-schematic_init (Schematic *schematic)
+static void schematic_init (Schematic *schematic)
{
SchematicPriv *priv;
@@ -215,49 +189,52 @@ schematic_init (Schematic *schematic)
priv->printoptions = NULL;
// Colors
- priv->colors.components.red = 65535;
+ priv->colors.components.red = 1.0;
priv->colors.components.green = 0;
priv->colors.components.blue = 0;
+ priv->colors.components.alpha = 1.0;
priv->colors.labels.red = 0;
- priv->colors.labels.green = 35723;
- priv->colors.labels.blue = 35723;
+ priv->colors.labels.green = 0.5451;
+ priv->colors.labels.blue = 0.5451;
+ priv->colors.labels.alpha = 1.0;
priv->colors.wires.red = 0;
priv->colors.wires.green = 0;
- priv->colors.wires.blue = 65535;
- priv->colors.text.red = 0;
- priv->colors.text.green = 0;
- priv->colors.text.blue = 0;
+ priv->colors.wires.blue = 1.0;
+ priv->colors.wires.alpha = 1.0;
+ priv->colors.text.red = 1.0;
+ priv->colors.text.green = 1.0;
+ priv->colors.text.blue = 1.0;
+ priv->colors.text.alpha = 1.0;
priv->symbols = g_hash_table_new (g_str_hash, g_str_equal);
priv->refdes_values = g_hash_table_new (g_str_hash, g_str_equal);
priv->store = node_store_new ();
+ priv->width = 0;
+ priv->height = 0;
priv->dirty = FALSE;
- priv->log = gtk_text_buffer_new (NULL);
- priv->tag_error = gtk_text_buffer_create_tag (priv->log, "error",
- "foreground", "red",
- "weight", PANGO_WEIGHT_BOLD,
- NULL);
+ priv->logstore = log_new ();
+ priv->log = gtk_text_buffer_new (NULL); // LEGACY
+ priv->tag_error = gtk_text_buffer_create_tag (priv->log, "error", "foreground", "red", "weight",
+ PANGO_WEIGHT_BOLD, NULL);
- g_signal_connect_object (priv->store, "node_dot_added",
- G_CALLBACK (node_dot_added_callback), G_OBJECT (schematic),
- G_CONNECT_AFTER);
+ g_signal_connect_object (priv->store, "node_dot_added", G_CALLBACK (node_dot_added_callback),
+ G_OBJECT (schematic), G_CONNECT_AFTER);
g_signal_connect_object (priv->store, "node_dot_removed",
- G_CALLBACK (node_dot_removed_callback), G_OBJECT (schematic),
- G_CONNECT_AFTER);
+ G_CALLBACK (node_dot_removed_callback), G_OBJECT (schematic),
+ G_CONNECT_AFTER);
- priv->sim_settings = sim_settings_new (schematic);
+ priv->sim_settings = sim_settings_gui_new (schematic);
priv->settings = settings_new (schematic);
- priv->simulation = simulation_new (schematic);
+ priv->simulation = simulation_new (schematic, priv->logstore);
priv->filename = NULL;
priv->netlist_filename = NULL;
- priv->author = g_strdup ("");
+ priv->author = g_strdup (g_get_user_name ());
priv->comments = g_strdup ("");
}
-Schematic *
-schematic_new (void)
+Schematic *schematic_new (void)
{
Schematic *schematic;
@@ -269,8 +246,7 @@ schematic_new (void)
return schematic;
}
-static void
-schematic_dispose (GObject *object)
+static void schematic_dispose (GObject *object)
{
Schematic *schematic;
GList *list;
@@ -278,11 +254,11 @@ schematic_dispose (GObject *object)
schematic = SCHEMATIC (object);
// Disconnect weak item signal
- for (list=schematic->priv->current_items; list; list=list->next)
- g_object_weak_unref (G_OBJECT (list->data),
- item_data_destroy_callback, G_OBJECT (schematic));
+ for (list = schematic->priv->current_items; list; list = list->next)
+ g_object_weak_unref (G_OBJECT (list->data), item_data_destroy_callback,
+ G_OBJECT (schematic));
- g_object_unref (G_OBJECT (schematic->priv->log));
+ g_clear_object (&schematic->priv->log);
schematic_count_--;
schematic_list = g_list_remove (schematic_list, schematic);
@@ -296,31 +272,29 @@ schematic_dispose (GObject *object)
G_OBJECT_CLASS (parent_class)->dispose (G_OBJECT (schematic));
}
-static void
-schematic_finalize (GObject *object)
+static void schematic_finalize (GObject *object)
{
- Schematic *sm;
-
- sm = SCHEMATIC (object);
- if (sm->priv) {
- g_free (sm->priv->simulation);
- g_hash_table_destroy (sm->priv->symbols);
- g_hash_table_destroy (sm->priv->refdes_values);
- if (sm->priv->netlist_filename)
- g_free (sm->priv->netlist_filename);
-
- g_free (sm->priv);
- sm->priv = NULL;
+ Schematic *sm = SCHEMATIC (object);
+ SchematicPriv *priv = sm->priv;
+ if (priv) {
+ g_free (priv->simulation);
+ g_hash_table_destroy (priv->symbols);
+ g_hash_table_destroy (priv->refdes_values);
+ g_clear_object (&priv->store);
+ g_clear_object (&priv->logstore);
+ g_free (priv->netlist_filename);
+ g_free (priv->comments);
+ g_free (priv->author);
+ g_free (priv->filename);
+ g_free (priv->settings);
+ sim_settings_gui_finalize(priv->sim_settings);
+ g_free (priv);
}
G_OBJECT_CLASS (parent_class)->finalize (G_OBJECT (sm));
}
-// Get/set functions.
-// ***************** /
-
-char *
-schematic_get_title (Schematic *schematic)
+char *schematic_get_title (Schematic *schematic)
{
g_return_val_if_fail (schematic != NULL, NULL);
g_return_val_if_fail (IS_SCHEMATIC (schematic), NULL);
@@ -328,8 +302,7 @@ schematic_get_title (Schematic *schematic)
return schematic->priv->title;
}
-char *
-schematic_get_author (Schematic *schematic)
+char *schematic_get_author (Schematic *schematic)
{
g_return_val_if_fail (schematic != NULL, NULL);
g_return_val_if_fail (IS_SCHEMATIC (schematic), NULL);
@@ -337,8 +310,15 @@ schematic_get_author (Schematic *schematic)
return schematic->priv->author;
}
-char *
-schematic_get_comments (Schematic *schematic)
+char *schematic_get_version (Schematic *schematic)
+{
+ g_return_val_if_fail (schematic != NULL, NULL);
+ g_return_val_if_fail (IS_SCHEMATIC (schematic), NULL);
+
+ return schematic->priv->oregano_version;
+}
+
+char *schematic_get_comments (Schematic *schematic)
{
g_return_val_if_fail (schematic != NULL, NULL);
g_return_val_if_fail (IS_SCHEMATIC (schematic), NULL);
@@ -346,47 +326,54 @@ schematic_get_comments (Schematic *schematic)
return schematic->priv->comments;
}
-void
-schematic_set_title (Schematic *schematic, const gchar *title)
+void schematic_set_title (Schematic *schematic, const gchar *title)
{
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
- if (!title) return;
+ if (!title)
+ return;
- if (schematic->priv->title)
- g_free (schematic->priv->title);
+ g_free (schematic->priv->title);
schematic->priv->title = g_strdup (title);
g_signal_emit_by_name (schematic, "title_changed", schematic->priv->title);
}
-void
-schematic_set_author (Schematic *schematic, const gchar *author)
+void schematic_set_author (Schematic *schematic, const gchar *author)
{
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
- if (!author) return;
+ if (!author)
+ return;
- if (schematic->priv->author)
- g_free (schematic->priv->author);
+ g_free (schematic->priv->author);
schematic->priv->author = g_strdup (author);
}
-void
-schematic_set_comments (Schematic *schematic, const gchar *comments)
+void schematic_set_version (Schematic *schematic, const gchar *oregano_version)
+{
+ g_return_if_fail (schematic != NULL);
+ g_return_if_fail (IS_SCHEMATIC (schematic));
+
+ if (!oregano_version)
+ return;
+
+ g_free (schematic->priv->oregano_version);
+ schematic->priv->oregano_version = g_strdup (oregano_version);
+}
+
+void schematic_set_comments (Schematic *schematic, const gchar *comments)
{
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
- if (schematic->priv->comments)
- g_free (schematic->priv->comments);
+ g_free (schematic->priv->comments);
schematic->priv->comments = g_strdup (comments);
}
-char *
-schematic_get_filename (Schematic *schematic)
+char *schematic_get_filename (Schematic *schematic)
{
g_return_val_if_fail (schematic != NULL, NULL);
g_return_val_if_fail (IS_SCHEMATIC (schematic), NULL);
@@ -394,8 +381,7 @@ schematic_get_filename (Schematic *schematic)
return schematic->priv->filename;
}
-void
-schematic_set_filename (Schematic *schematic, const gchar *filename)
+void schematic_set_filename (Schematic *schematic, const gchar *filename)
{
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
@@ -404,8 +390,7 @@ schematic_set_filename (Schematic *schematic, const gchar *filename)
schematic->priv->filename = g_strdup (filename);
}
-char *
-schematic_get_netlist_filename (Schematic *schematic)
+char *schematic_get_netlist_filename (Schematic *schematic)
{
g_return_val_if_fail (schematic != NULL, NULL);
g_return_val_if_fail (IS_SCHEMATIC (schematic), NULL);
@@ -413,20 +398,49 @@ schematic_get_netlist_filename (Schematic *schematic)
return schematic->priv->netlist_filename;
}
-void
-schematic_set_netlist_filename (Schematic *schematic, char *filename)
+void schematic_set_netlist_filename (Schematic *schematic, char *filename)
{
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
- if (schematic->priv->netlist_filename)
- g_free (schematic->priv->netlist_filename);
+ g_free (schematic->priv->netlist_filename);
schematic->priv->netlist_filename = g_strdup (filename);
}
-double
-schematic_get_zoom (Schematic *schematic)
+guint schematic_get_width (const Schematic *schematic)
+{
+ g_return_val_if_fail (schematic != NULL, 0.);
+ g_return_val_if_fail (IS_SCHEMATIC (schematic), 0.);
+
+ return schematic->priv->width;
+}
+
+void schematic_set_width (Schematic *schematic, const guint width)
+{
+ g_return_if_fail (schematic != NULL);
+ g_return_if_fail (IS_SCHEMATIC (schematic));
+
+ schematic->priv->width = width;
+}
+
+guint schematic_get_height (const Schematic *schematic)
+{
+ g_return_val_if_fail (schematic != NULL, 0.);
+ g_return_val_if_fail (IS_SCHEMATIC (schematic), 0.);
+
+ return schematic->priv->height;
+}
+
+void schematic_set_height (Schematic *schematic, const guint height)
+{
+ g_return_if_fail (schematic != NULL);
+ g_return_if_fail (IS_SCHEMATIC (schematic));
+
+ schematic->priv->height = height;
+}
+
+double schematic_get_zoom (Schematic *schematic)
{
g_return_val_if_fail (schematic != NULL, 1.0);
g_return_val_if_fail (IS_SCHEMATIC (schematic), 1.0);
@@ -434,8 +448,7 @@ schematic_get_zoom (Schematic *schematic)
return schematic->priv->zoom;
}
-void
-schematic_set_zoom (Schematic *schematic, double zoom)
+void schematic_set_zoom (Schematic *schematic, double zoom)
{
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
@@ -443,8 +456,7 @@ schematic_set_zoom (Schematic *schematic, double zoom)
schematic->priv->zoom = zoom;
}
-NodeStore *
-schematic_get_store (Schematic *schematic)
+NodeStore *schematic_get_store (Schematic *schematic)
{
g_return_val_if_fail (schematic != NULL, NULL);
g_return_val_if_fail (IS_SCHEMATIC (schematic), NULL);
@@ -452,8 +464,7 @@ schematic_get_store (Schematic *schematic)
return schematic->priv->store;
}
-gpointer
-schematic_get_settings (Schematic *schematic)
+gpointer schematic_get_settings (Schematic *schematic)
{
g_return_val_if_fail (schematic != NULL, NULL);
g_return_val_if_fail (IS_SCHEMATIC (schematic), NULL);
@@ -461,8 +472,15 @@ schematic_get_settings (Schematic *schematic)
return schematic->priv->settings;
}
-gpointer
-schematic_get_sim_settings (Schematic *schematic)
+SimSettings *schematic_get_sim_settings (Schematic *schematic)
+{
+ g_return_val_if_fail (schematic != NULL, NULL);
+ g_return_val_if_fail (IS_SCHEMATIC (schematic), NULL);
+
+ return schematic->priv->sim_settings->sim_settings;
+}
+
+SimSettingsGui *schematic_get_sim_settings_gui (Schematic *schematic)
{
g_return_val_if_fail (schematic != NULL, NULL);
g_return_val_if_fail (IS_SCHEMATIC (schematic), NULL);
@@ -470,8 +488,7 @@ schematic_get_sim_settings (Schematic *schematic)
return schematic->priv->sim_settings;
}
-gpointer
-schematic_get_simulation (Schematic *schematic)
+gpointer schematic_get_simulation (Schematic *schematic)
{
g_return_val_if_fail (schematic != NULL, NULL);
g_return_val_if_fail (IS_SCHEMATIC (schematic), NULL);
@@ -479,19 +496,26 @@ schematic_get_simulation (Schematic *schematic)
return schematic->priv->simulation;
}
-void
-schematic_log_append (Schematic *schematic, const char *message)
+Log *schematic_get_log_store (Schematic *schematic)
+{
+ g_return_val_if_fail (schematic != NULL, NULL);
+ g_return_val_if_fail (IS_SCHEMATIC (schematic), NULL);
+
+ return schematic->priv->logstore;
+}
+
+void schematic_log_append (Schematic *schematic, const char *message)
{
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
- gtk_text_buffer_insert_at_cursor (
- schematic->priv->log,
- message, strlen (message));
+ log_append (schematic->priv->logstore, "Schematic Info", message);
+
+ // LEGACY
+ gtk_text_buffer_insert_at_cursor (schematic->priv->log, message, strlen (message));
}
-void
-schematic_log_append_error (Schematic *schematic, const char *message)
+void schematic_log_append_error (Schematic *schematic, const char *message)
{
GtkTextIter iter;
SchematicPriv *priv;
@@ -501,13 +525,14 @@ schematic_log_append_error (Schematic *schematic, const char *message)
priv = schematic->priv;
+ log_append (schematic->priv->logstore, "simulation engine Error", message);
+
+ // LEGACY
gtk_text_buffer_get_end_iter (priv->log, &iter);
- gtk_text_buffer_insert_with_tags (priv->log, &iter, message,
- -1, priv->tag_error, NULL);
+ gtk_text_buffer_insert_with_tags (priv->log, &iter, message, -1, priv->tag_error, NULL);
}
-void
-schematic_log_show (Schematic *schematic)
+void schematic_log_show (Schematic *schematic)
{
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
@@ -515,18 +540,15 @@ schematic_log_show (Schematic *schematic)
g_signal_emit_by_name (schematic, "log_updated", schematic->priv->log);
}
-void
-schematic_log_clear (Schematic *schematic)
+void schematic_log_clear (Schematic *schematic)
{
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
- gtk_text_buffer_set_text (
- schematic->priv->log, "", -1);
+ gtk_text_buffer_set_text (schematic->priv->log, "", -1);
}
-GtkTextBuffer*
-schematic_get_log_text (Schematic *schematic)
+GtkTextBuffer *schematic_get_log_text (Schematic *schematic)
{
g_return_val_if_fail (schematic != NULL, NULL);
g_return_val_if_fail (IS_SCHEMATIC (schematic), NULL);
@@ -534,75 +556,56 @@ schematic_get_log_text (Schematic *schematic)
return schematic->priv->log;
}
-int
-schematic_count (void)
-{
- return schematic_count_;
-}
+int schematic_count (void) { return schematic_count_; }
-Schematic *
-schematic_read (char *name, GError **out_error)
+Schematic *schematic_read (const char *name, GError **error)
{
Schematic *new_sm;
- int ret;
- char *fname;
- GError *error = NULL;
+ const char *fname;
+ GError *e = NULL;
FileType *ft;
g_return_val_if_fail (name != NULL, NULL);
- fname = g_filename_from_uri (name, NULL, &error);
+ fname = g_filename_from_uri (name, NULL, &e);
if (!fname) {
fname = name;
- if (error) {
- g_error_free (error);
- error = NULL;
- }
+ g_clear_error (&e);
}
if (!g_file_test (fname, G_FILE_TEST_EXISTS)) {
- g_set_error (out_error, OREGANO_ERROR, OREGANO_SCHEMATIC_FILE_NOT_FOUND,
- _("File %s does not exists."), fname);
+ g_set_error (error, OREGANO_ERROR, OREGANO_SCHEMATIC_FILE_NOT_FOUND,
+ _ ("File %s does not exist."), fname);
return NULL;
}
// Get File Handler
ft = file_manager_get_handler (fname);
if (ft == NULL) {
- g_set_error (out_error, OREGANO_ERROR, OREGANO_SCHEMATIC_FILE_NOT_FOUND,
- _("Unknown file format for %s."), fname);
+ g_set_error (error, OREGANO_ERROR, OREGANO_SCHEMATIC_FILE_NOT_FOUND,
+ _ ("Unknown file format for %s."), fname);
return NULL;
}
new_sm = schematic_new ();
- /* TODO : Add GError-like error reporting! */
- ret = ft->load_func (new_sm, fname, &error);
-
- if (error != NULL) {
- g_propagate_error (out_error, error);
- g_object_unref (G_OBJECT (new_sm));
+ ft->load_func (new_sm, fname, &e);
+ if (e) {
+ g_propagate_error (error, e);
+ g_clear_object (&new_sm);
return NULL;
}
- if (ret) {
- g_object_unref (G_OBJECT (new_sm));
- new_sm = NULL;
- g_set_error (out_error, OREGANO_ERROR, OREGANO_SCHEMATIC_FILE_NOT_FOUND,
- _("Load fails!."));
- }
- else
- schematic_set_dirty (new_sm, FALSE);
+ schematic_set_dirty (new_sm, FALSE);
return new_sm;
}
-gint
-schematic_save_file (Schematic *sm, GError **error)
+gint schematic_save_file (Schematic *sm, GError **error)
{
FileType *ft;
- GError *internal_error = NULL;
+ GError *e = NULL;
g_return_val_if_fail (sm != NULL, FALSE);
@@ -610,44 +613,52 @@ schematic_save_file (Schematic *sm, GError **error)
if (ft == NULL) {
g_set_error (error, OREGANO_ERROR, OREGANO_SCHEMATIC_FILE_NOT_FOUND,
- _("Unknown file format for %s."), schematic_get_filename (sm));
+ _ ("Unknown file format for %s."), schematic_get_filename (sm));
return FALSE;
}
- if (ft->save_func (sm, &internal_error)) {
+ if (ft->save_func (sm, &e)) {
schematic_set_title (sm, g_path_get_basename (sm->priv->filename));
schematic_set_dirty (sm, FALSE);
return TRUE;
}
- g_propagate_error (error, internal_error);
+ g_propagate_error (error, e);
- g_error_free (internal_error);
return FALSE; // Save fails!
}
-void
-schematic_add_item (Schematic *sm, ItemData *data)
+/**
+ * \brief add an ItemData object to a Schematic
+ *
+ * @param sm the schematic the item will be added to
+ * @param data fully initilalized ItemData object
+ */
+void schematic_add_item (Schematic *sm, ItemData *data)
{
NodeStore *store;
char *prefix = NULL, *refdes = NULL;
int num;
- g_return_if_fail (sm != NULL);
+ g_return_if_fail (sm);
g_return_if_fail (IS_SCHEMATIC (sm));
- g_return_if_fail (data != NULL);
+ g_return_if_fail (data);
g_return_if_fail (IS_ITEM_DATA (data));
store = sm->priv->store;
- g_object_set (G_OBJECT (data),
- "store", store,
- NULL);
-
- if (item_data_register (data) == -1)
- // Item does not be added
+ g_assert (store);
+ g_assert (IS_NODE_STORE (store));
+
+ g_object_set (G_OBJECT (data), "store", store, NULL);
+
+ // item data will call the child register function
+ // for parts e.g. this ends up in <node_store_add_part>
+ // which requires a valid position to add the node dots
+ if (item_data_register (data) == -1) {
return;
+ }
- // Some items need a reference designator. Find a good one.
+ // Some items need a reference designator, so get a good one
prefix = item_data_get_refdes_prefix (data);
if (prefix != NULL) {
num = schematic_get_lowest_available_refdes (sm, prefix);
@@ -660,21 +671,18 @@ schematic_add_item (Schematic *sm, ItemData *data)
g_free (refdes);
sm->priv->current_items = g_list_prepend (sm->priv->current_items, data);
- g_object_weak_ref (G_OBJECT (data), item_data_destroy_callback,
- G_OBJECT (sm));
-
- g_signal_connect_object (data, "moved", G_CALLBACK (item_moved_callback),
- sm, 0);
+ g_object_weak_ref (G_OBJECT (data), item_data_destroy_callback, G_OBJECT (sm));
sm->priv->dirty = TRUE;
- g_signal_emit_by_name (sm,
- "item_data_added", data);
+ // if the item gets moved mark the schematic as dirty
+ g_signal_connect_object (data, "moved", G_CALLBACK (item_moved_callback), sm, 0);
+
+ // causes a canvas item (view) to be generated
+ g_signal_emit_by_name (sm, "item_data_added", data);
}
-void
-schematic_parts_foreach (Schematic *schematic,
- ForeachItemDataFunc func, gpointer user_data)
+void schematic_parts_foreach (Schematic *schematic, ForeachItemDataFunc func, gpointer user_data)
{
GList *list;
@@ -687,12 +695,9 @@ schematic_parts_foreach (Schematic *schematic,
for (list = node_store_get_parts (schematic->priv->store); list; list = list->next) {
func (list->data, user_data);
}
- g_list_free_full (list, g_object_unref);
}
-void
-schematic_wires_foreach (Schematic *schematic,
- ForeachItemDataFunc func, gpointer user_data)
+void schematic_wires_foreach (Schematic *schematic, ForeachItemDataFunc func, gpointer user_data)
{
GList *list;
@@ -705,12 +710,9 @@ schematic_wires_foreach (Schematic *schematic,
for (list = node_store_get_wires (schematic->priv->store); list; list = list->next) {
func (list->data, user_data);
}
- g_list_free_full (list, g_object_unref);
}
-void
-schematic_items_foreach (Schematic *schematic,
- ForeachItemDataFunc func, gpointer user_data)
+void schematic_items_foreach (Schematic *schematic, ForeachItemDataFunc func, gpointer user_data)
{
GList *list;
@@ -723,11 +725,9 @@ schematic_items_foreach (Schematic *schematic,
for (list = schematic->priv->current_items; list; list = list->next) {
func (list->data, user_data);
}
- g_list_free_full (list, g_object_unref);
}
-GList *
-schematic_get_items (Schematic *sm)
+GList *schematic_get_items (Schematic *sm)
{
g_return_val_if_fail (sm != NULL, NULL);
g_return_val_if_fail (IS_SCHEMATIC (sm), NULL);
@@ -735,8 +735,7 @@ schematic_get_items (Schematic *sm)
return sm->priv->current_items;
}
-static void
-item_data_destroy_callback (gpointer s, GObject *data)
+static void item_data_destroy_callback (gpointer s, GObject *data)
{
Schematic *sm = SCHEMATIC (s);
schematic_set_dirty (sm, TRUE);
@@ -745,8 +744,7 @@ item_data_destroy_callback (gpointer s, GObject *data)
}
}
-static int
-schematic_get_lowest_available_refdes (Schematic *schematic, char *prefix)
+static int schematic_get_lowest_available_refdes (Schematic *schematic, char *prefix)
{
gpointer key, value;
@@ -754,18 +752,14 @@ schematic_get_lowest_available_refdes (Schematic *schematic, char *prefix)
g_return_val_if_fail (IS_SCHEMATIC (schematic), -1);
g_return_val_if_fail (prefix != NULL, -1);
- if ( g_hash_table_lookup_extended (schematic->priv->refdes_values,
- prefix, &key, &value) ) {
+ if (g_hash_table_lookup_extended (schematic->priv->refdes_values, prefix, &key, &value)) {
return GPOINTER_TO_INT (value);
- }
- else {
+ } else {
return 1;
}
}
-static void
-schematic_set_lowest_available_refdes (Schematic *schematic,
- char *prefix, int num)
+static void schematic_set_lowest_available_refdes (Schematic *schematic, char *prefix, int num)
{
gpointer key, value;
@@ -775,16 +769,13 @@ schematic_set_lowest_available_refdes (Schematic *schematic,
// If there already is a key, use it, otherwise copy the prefix and
// use as key.
- if (!g_hash_table_lookup_extended (schematic->priv->refdes_values,
- prefix, &key, &value))
+ if (!g_hash_table_lookup_extended (schematic->priv->refdes_values, prefix, &key, &value))
key = g_strdup (prefix);
- g_hash_table_insert (schematic->priv->refdes_values,
- key, GINT_TO_POINTER (num));
+ g_hash_table_insert (schematic->priv->refdes_values, key, GINT_TO_POINTER (num));
}
-gboolean
-schematic_is_dirty (Schematic *sm)
+gboolean schematic_is_dirty (Schematic *sm)
{
g_return_val_if_fail (sm != NULL, FALSE);
g_return_val_if_fail (IS_SCHEMATIC (sm), FALSE);
@@ -792,8 +783,7 @@ schematic_is_dirty (Schematic *sm)
return sm->priv->dirty;
}
-void
-schematic_set_dirty (Schematic *sm, gboolean b)
+void schematic_set_dirty (Schematic *sm, gboolean b)
{
g_return_if_fail (sm != NULL);
g_return_if_fail (IS_SCHEMATIC (sm));
@@ -801,8 +791,7 @@ schematic_set_dirty (Schematic *sm, gboolean b)
sm->priv->dirty = b;
}
-static void
-item_moved_callback (ItemData *data, SheetPos *pos, Schematic *sm)
+static void item_moved_callback (ItemData *data, Coords *pos, Schematic *sm)
{
g_return_if_fail (data != NULL);
g_return_if_fail (IS_ITEM_DATA (data));
@@ -810,35 +799,33 @@ item_moved_callback (ItemData *data, SheetPos *pos, Schematic *sm)
schematic_set_dirty (sm, TRUE);
}
-static void
-schematic_render (Schematic *sm, cairo_t *cr)
+static void schematic_render (Schematic *sm, cairo_t *cr)
{
NodeStore *store;
SchematicPrintContext schematic_print_context;
schematic_print_context.colors = sm->priv->colors;
store = schematic_get_store (sm);
-
+
node_store_print_items (store, cr, &schematic_print_context);
}
-GdkColor
-convert_to_grayscale (GdkColor *source)
+GdkRGBA convert_to_grayscale (GdkRGBA *source)
{
- GdkColor color;
- int factor;
+ GdkRGBA color;
+ gdouble factor;
+
+ factor = source->red * 0.299 + source->green * 0.587 + source->blue * 0.114;
- factor = (source->red + source->green + source->blue)/3;
color.red = factor;
color.green = factor;
color.blue = factor;
- color.pixel = source->pixel;
+ color.alpha = source->alpha;
return color;
}
-void
-schematic_export (Schematic *sm, const gchar *filename,
- gint img_w, gint img_h, int bg, int color, int format)
+void schematic_export (Schematic *sm, const gchar *filename, gint img_w, gint img_h, int bg,
+ int color, int format)
{
NodeRect bbox;
NodeStore *store;
@@ -862,36 +849,36 @@ schematic_export (Schematic *sm, const gchar *filename,
switch (format) {
#ifdef CAIRO_HAS_SVG_SURFACE
- case 0:
- surface = cairo_svg_surface_create (filename, img_w, img_h);
+ case 0:
+ surface = cairo_svg_surface_create (filename, img_w, img_h);
break;
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
- case 1:
- surface = cairo_pdf_surface_create (filename, img_w, img_h);
+ case 1:
+ surface = cairo_pdf_surface_create (filename, img_w, img_h);
break;
#endif
#ifdef CAIRO_HAS_PS_SURFACE
- case 2:
- surface = cairo_ps_surface_create (filename, img_w, img_h);
+ case 2:
+ surface = cairo_ps_surface_create (filename, img_w, img_h);
break;
#endif
- default:
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, img_w, img_h);
+ default:
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, img_w, img_h);
}
cr = cairo_create (surface);
// Background
switch (bg) {
- case 1: // White
- cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
- cairo_rectangle (cr, 0, 0, img_w, img_h);
- cairo_fill (cr);
- break;
- case 2: // Black
- cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
- cairo_rectangle (cr, 0, 0, img_w, img_h);
- cairo_fill (cr);
+ case 1: // White
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+ cairo_rectangle (cr, 0, 0, img_w, img_h);
+ cairo_fill (cr);
+ break;
+ case 2: // Black
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+ cairo_rectangle (cr, 0, 0, img_w, img_h);
+ cairo_fill (cr);
}
graph_w = img_w * 0.8;
@@ -905,8 +892,8 @@ schematic_export (Schematic *sm, const gchar *filename,
// Preparing...
cairo_save (cr);
- cairo_translate (cr, (img_w - graph_w)/2.0, (img_h - graph_h) / 2.0);
- cairo_scale (cr, scale, scale);
+ cairo_translate (cr, (img_w - graph_w) / 2.0, (img_h - graph_h) / 2.0);
+ cairo_scale (cr, scale, scale);
cairo_translate (cr, -bbox.x0, -bbox.y0);
cairo_set_line_width (cr, 0.5);
@@ -928,26 +915,24 @@ schematic_export (Schematic *sm, const gchar *filename,
}
}
-static void
-draw_rotule (Schematic *sm, cairo_t *cr)
+static void draw_rotule (Schematic *sm, cairo_t *cr)
{
cairo_save (cr);
- cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
- cairo_set_line_width (cr, 0.5);
- cairo_rectangle (cr, 0, 0, 180, 20);
- cairo_rectangle (cr, 0, 20, 180, 10);
- cairo_stroke (cr);
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+ cairo_set_line_width (cr, 0.5);
+ cairo_rectangle (cr, 0, 0, 180, 20);
+ cairo_rectangle (cr, 0, 20, 180, 10);
+ cairo_stroke (cr);
cairo_restore (cr);
}
-static void
-draw_page (GtkPrintOperation *operation,
- GtkPrintContext *context, int page_nr, Schematic *sm)
+static void draw_page (GtkPrintOperation *operation, GtkPrintContext *context, int page_nr,
+ Schematic *sm)
{
NodeStore *store;
NodeRect bbox;
gdouble page_w, page_h;
-
+
page_w = gtk_print_context_get_width (context);
page_h = gtk_print_context_get_height (context);
@@ -955,15 +940,15 @@ draw_page (GtkPrintOperation *operation,
// Draw a red rectangle, as wide as the paper (inside the margins)
cairo_save (cr);
- cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
- cairo_set_line_width (cr, 0.5);
- cairo_rectangle (cr, 20, 10, page_w-30, page_h-20);
- cairo_stroke (cr);
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+ cairo_set_line_width (cr, 0.5);
+ cairo_rectangle (cr, 20, 10, page_w - 30, page_h - 20);
+ cairo_stroke (cr);
cairo_restore (cr);
cairo_save (cr);
- cairo_translate (cr, page_w-190, page_h-40);
- draw_rotule (sm, cr);
+ cairo_translate (cr, page_w - 190, page_h - 40);
+ draw_rotule (sm, cr);
cairo_restore (cr);
store = schematic_get_store (sm);
@@ -971,117 +956,108 @@ draw_page (GtkPrintOperation *operation,
node_store_get_bounds (store, &bbox);
cairo_save (cr);
- cairo_set_line_width (cr, 0.5);
- cairo_set_source_rgb (cr, 0, 0, 0);
- cairo_translate (cr, page_w * 0.1, page_h * 0.1);
- // 0.4 is the convert factor between Model unit and
- // milimeters, unit used in printing
- cairo_scale (cr, 0.4, 0.4);
- cairo_translate (cr, -bbox.x0, -bbox.y0);
- schematic_render (sm, cr);
+ cairo_set_line_width (cr, 0.5);
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_translate (cr, page_w * 0.1, page_h * 0.1);
+ // 0.4 is the convert factor between Model unit and
+ // milimeters, unit used in printing
+ cairo_scale (cr, 0.4, 0.4);
+ cairo_translate (cr, -bbox.x0, -bbox.y0);
+ schematic_render (sm, cr);
cairo_restore (cr);
}
-static GObject*
-print_options (GtkPrintOperation *operation, Schematic *sm)
+static GObject *print_options (GtkPrintOperation *operation, Schematic *sm)
{
GtkBuilder *gui;
GError *perror = NULL;
-
- if ((gui = gtk_builder_new ()) == NULL) {
- return G_OBJECT (gtk_label_new (_("Error loading print-options.ui")));
- }
- if (!g_file_test (OREGANO_UIDIR "/print-options.ui", G_FILE_TEST_EXISTS)) {
- return G_OBJECT (gtk_label_new (_("Error loading print-options.ui")));
+ if ((gui = gtk_builder_new ()) == NULL) {
+ return G_OBJECT (gtk_label_new (_ ("Error loading print-options.ui")));
}
- if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/print-options.ui",
- &perror) <= 0) {
+ if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/print-options.ui", &perror) <= 0) {
g_error_free (perror);
- return G_OBJECT (gtk_label_new (_("Error loading print-options.ui")));
+ return G_OBJECT (gtk_label_new (_ ("Error loading print-options.ui")));
}
- if (sm->priv->printoptions)
- g_free (sm->priv->printoptions);
+ g_free (sm->priv->printoptions);
sm->priv->printoptions = g_new0 (SchematicPrintOptions, 1);
- sm->priv->printoptions->components = GTK_COLOR_BUTTON (
- gtk_builder_get_object (gui, "color_components"));
- sm->priv->printoptions->labels = GTK_COLOR_BUTTON (
- gtk_builder_get_object (gui, "color_labels"));
- sm->priv->printoptions->wires = GTK_COLOR_BUTTON (
- gtk_builder_get_object (gui, "color_wires"));
- sm->priv->printoptions->text = GTK_COLOR_BUTTON (
- gtk_builder_get_object (gui, "color_text"));
- sm->priv->printoptions->background = GTK_COLOR_BUTTON (
- gtk_builder_get_object (gui, "color_background"));
+ sm->priv->printoptions->components =
+ GTK_COLOR_BUTTON (gtk_builder_get_object (gui, "color_components"));
+ sm->priv->printoptions->labels =
+ GTK_COLOR_BUTTON (gtk_builder_get_object (gui, "color_labels"));
+ sm->priv->printoptions->wires = GTK_COLOR_BUTTON (gtk_builder_get_object (gui, "color_wires"));
+ sm->priv->printoptions->text = GTK_COLOR_BUTTON (gtk_builder_get_object (gui, "color_text"));
+ sm->priv->printoptions->background =
+ GTK_COLOR_BUTTON (gtk_builder_get_object (gui, "color_background"));
// Set default colors
- gtk_color_button_set_color (GTK_COLOR_BUTTON (
- gtk_builder_get_object (gui, "color_components")),
- &sm->priv->colors.components);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (
- gtk_builder_get_object (gui, "color_labels")),
- &sm->priv->colors.labels);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (
- gtk_builder_get_object (gui, "color_wires")),
- &sm->priv->colors.wires);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (
- gtk_builder_get_object (gui, "color_text")),
- &sm->priv->colors.text);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (
- gtk_builder_get_object (gui, "color_background")),
- &sm->priv->colors.background);
+ gtk_color_chooser_set_rgba (
+ GTK_COLOR_CHOOSER (gtk_builder_get_object (gui, "color_components")),
+ &sm->priv->colors.components);
+ gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (gtk_builder_get_object (gui, "color_labels")),
+ &sm->priv->colors.labels);
+ gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (gtk_builder_get_object (gui, "color_wires")),
+ &sm->priv->colors.wires);
+ gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (gtk_builder_get_object (gui, "color_text")),
+ &sm->priv->colors.text);
+ gtk_color_chooser_set_rgba (
+ GTK_COLOR_CHOOSER (gtk_builder_get_object (gui, "color_background")),
+ &sm->priv->colors.background);
return gtk_builder_get_object (gui, "widget");
}
-static void
-read_print_options (GtkPrintOperation *operation, GtkWidget *widget, Schematic *sm)
+static void read_print_options (GtkPrintOperation *operation, GtkWidget *widget, Schematic *sm)
{
SchematicPrintOptions *colors = sm->priv->printoptions;
- gtk_color_button_get_color (colors->components, &sm->priv->colors.components);
- gtk_color_button_get_color (colors->labels, &sm->priv->colors.labels);
- gtk_color_button_get_color (colors->wires, &sm->priv->colors.wires);
- gtk_color_button_get_color (colors->text, &sm->priv->colors.text);
- gtk_color_button_get_color (colors->background, &sm->priv->colors.background);
+ gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (colors->components),
+ &sm->priv->colors.components);
+ gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (colors->labels), &sm->priv->colors.labels);
+ gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (colors->wires), &sm->priv->colors.wires);
+ gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (colors->text), &sm->priv->colors.text);
+ gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (colors->background),
+ &sm->priv->colors.background);
g_free (sm->priv->printoptions);
sm->priv->printoptions = NULL;
}
-void
-schematic_print (Schematic *sm, GtkPageSetup *page, GtkPrintSettings *settings, gboolean preview)
+void schematic_print (Schematic *sm, GtkPageSetup *page, GtkPrintSettings *settings,
+ gboolean preview)
{
GtkPrintOperation *op;
GtkPrintOperationResult res;
op = gtk_print_operation_new ();
- gtk_print_operation_set_print_settings (op, settings);
+ if (settings != NULL)
+ gtk_print_operation_set_print_settings (op, settings);
gtk_print_operation_set_default_page_setup (op, page);
gtk_print_operation_set_n_pages (op, 1);
gtk_print_operation_set_unit (op, GTK_UNIT_MM);
gtk_print_operation_set_use_full_page (op, TRUE);
- g_signal_connect (op, "create-custom-widget",
- G_CALLBACK (print_options), sm);
- g_signal_connect (op, "custom-widget-apply",
- G_CALLBACK (read_print_options), sm);
- g_signal_connect (op, "draw_page",
- G_CALLBACK (draw_page), sm);
+ g_signal_connect (op, "create-custom-widget", G_CALLBACK (print_options), sm);
+ g_signal_connect (op, "custom-widget-apply", G_CALLBACK (read_print_options), sm);
+ g_signal_connect (op, "draw_page", G_CALLBACK (draw_page), sm);
- gtk_print_operation_set_custom_tab_label (op, _("Schematic"));
+ gtk_print_operation_set_custom_tab_label (op, _ ("Schematic"));
if (preview)
- res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PREVIEW,
- NULL, NULL);
+ res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PREVIEW, NULL, NULL);
else
- res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
- NULL, NULL);
+ res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL);
if (res == GTK_PRINT_OPERATION_RESULT_CANCEL) {
+ } else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
+ if (settings != NULL)
+ g_object_unref (settings);
+ settings = g_object_ref (gtk_print_operation_get_print_settings (op));
}
+
+ g_object_unref (op);
}