summaryrefslogtreecommitdiff
path: root/src/model/schematic.c
diff options
context:
space:
mode:
authorRuben Undheim <ruben.undheim@gmail.com>2018-07-12 23:10:08 +0200
committerRuben Undheim <ruben.undheim@gmail.com>2018-07-12 23:10:08 +0200
commite1fffcb07ce0d8b0db9e0b4b5e1e0c1128197af5 (patch)
tree850eead23d896c80df8c02ab0231164a07e8356e /src/model/schematic.c
parent1eb59a5d9eedcb2fde4cfcd8f3cf87edf18e71e4 (diff)
New upstream version 0.82
Diffstat (limited to 'src/model/schematic.c')
-rw-r--r--src/model/schematic.c403
1 files changed, 188 insertions, 215 deletions
diff --git a/src/model/schematic.c b/src/model/schematic.c
index 9736398..7329441 100644
--- a/src/model/schematic.c
+++ b/src/model/schematic.c
@@ -6,11 +6,13 @@
* Richard Hult <rhult@hem.passagen.se>
* Ricardo Markiewicz <rmarkie@fi.uba.ar>
* Andres de Barbara <adebarbara@fi.uba.ar>
+ * Marc Lorber <lorber.marc@wanadoo.fr>
*
- * Web page: http://arrakis.lug.fi.uba.ar/
+ * Web page: https://github.com/marc-lorber/oregano
*
* Copyright (C) 1999-2001 Richard Hult
* Copyright (C) 2003,2006 Ricardo Markiewicz
+ * Copyright (C) 2009-2012 Marc Lorber
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -29,8 +31,11 @@
*/
#include <gtk/gtk.h>
+#include <string.h>
#include <glib.h>
-#include <glade/glade.h>
+#include <glib/gi18n.h>
+#include <math.h>
+
#include "schematic.h"
#include "node-store.h"
#include "file-manager.h"
@@ -40,6 +45,7 @@
#include "errors.h"
#include "schematic-print-context.h"
+#define NG_DEBUG(s) if (0) g_print ("%s\n", s)
typedef struct _SchematicsPrintOptions {
GtkColorButton *components;
GtkColorButton *labels;
@@ -49,34 +55,32 @@ typedef struct _SchematicsPrintOptions {
} SchematicPrintOptions;
struct _SchematicPriv {
- char *title;
- char *filename;
- char *author;
- char *comments;
- char *netlist_filename;
+ 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;
+ // Data for various dialogs.
+ gpointer settings;
+ gpointer sim_settings;
+ gpointer simulation;
- GList *items;
+ GList *current_items;
- NodeStore *store;
- GHashTable *symbols;
- GHashTable *refdes_values;
+ NodeStore *store;
+ GHashTable *symbols;
+ GHashTable *refdes_values;
- double zoom;
+ double zoom;
- gboolean dirty;
+ gboolean dirty;
- GtkTextBuffer *log;
- GtkTextTag *tag_error;
+ GtkTextBuffer *log;
+ GtkTextTag *tag_error;
};
typedef enum {
@@ -98,23 +102,25 @@ enum {
TITLE_CHANGED,
ITEM_DATA_ADDED,
LOG_UPDATED,
- DOT_ADDED,
- DOT_REMOVED,
+ NODE_DOT_ADDED,
+ NODE_DOT_REMOVED,
LAST_SCHEMATIC_DESTROYED,
LAST_SIGNAL
};
-static void schematic_init(Schematic *schematic);
-static void schematic_class_init(SchematicClass *klass);
-static void schematic_finalize(GObject *object);
-static void schematic_dispose(GObject *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_finalize (GObject *object);
+static void schematic_dispose (GObject *object);
static void item_data_destroy_callback (gpointer s, GObject *data);
-static void part_moved_callback (ItemData *data, SheetPos *pos, Schematic *sm);
+static void item_moved_callback (ItemData *data, SheetPos *pos, Schematic *sm);
static int schematic_get_lowest_available_refdes (Schematic *schematic,
- char *prefix);
+ char *prefix);
static void schematic_set_lowest_available_refdes (Schematic *schematic,
- char *prefix, int num);
+ char *prefix, int num);
static GObjectClass *parent_class = NULL;
static guint schematic_signals[LAST_SIGNAL] = { 0 };
@@ -122,45 +128,18 @@ static guint schematic_signals[LAST_SIGNAL] = { 0 };
static GList *schematic_list = NULL;
static int schematic_count_ = 0;
-GType
-schematic_get_type (void)
-{
- static GType schematic_type = 0;
-
- if (!schematic_type) {
- static const GTypeInfo schematic_info = {
- sizeof (SchematicClass),
- NULL,
- NULL,
- (GClassInitFunc) schematic_class_init,
- NULL,
- NULL,
- sizeof (Schematic),
- 0,
- (GInstanceInitFunc) schematic_init,
- NULL
- };
-
- schematic_type =
- g_type_register_static (G_TYPE_OBJECT, "Schematic",
- &schematic_info,0);
- }
-
- return schematic_type;
-}
-
static void
schematic_class_init (SchematicClass *klass)
{
GObjectClass *object_class;
- object_class = G_OBJECT_CLASS(klass);
- parent_class = g_type_class_peek_parent(klass);
+ 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),
+ G_STRUCT_OFFSET (SchematicClass, title_changed),
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1,
@@ -169,7 +148,7 @@ schematic_class_init (SchematicClass *klass)
schematic_signals[LAST_SCHEMATIC_DESTROYED] = g_signal_new ("last_schematic_destroyed",
TYPE_SCHEMATIC,
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET(SchematicClass,last_schematic_destroyed),
+ G_STRUCT_OFFSET (SchematicClass, last_schematic_destroyed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
@@ -177,31 +156,31 @@ schematic_class_init (SchematicClass *klass)
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);
+ G_STRUCT_OFFSET (SchematicClass, item_data_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
- schematic_signals[DOT_ADDED] = g_signal_new ("dot_added",
+ schematic_signals[NODE_DOT_ADDED] = g_signal_new ("node_dot_added",
TYPE_SCHEMATIC,
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET(SchematicClass,dot_added),
+ G_STRUCT_OFFSET (SchematicClass, node_dot_added),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
- schematic_signals[DOT_REMOVED] = g_signal_new ("dot_removed",
+ schematic_signals[NODE_DOT_REMOVED] = g_signal_new ("node_dot_removed",
TYPE_SCHEMATIC,
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET(SchematicClass,dot_removed),
+ 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),
+ G_STRUCT_OFFSET (SchematicClass, log_updated),
NULL, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,0);
@@ -210,32 +189,32 @@ schematic_class_init (SchematicClass *klass)
}
static void
-dot_added_callback (NodeStore *store, SheetPos *pos, Schematic *schematic)
+node_dot_added_callback (NodeStore *store, SheetPos *pos, Schematic *schematic)
{
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
- g_signal_emit_by_name (G_OBJECT(schematic), "dot_added", pos);
+ g_signal_emit_by_name (schematic, "node_dot_added", pos);
}
static void
-dot_removed_callback (NodeStore *store, SheetPos *pos, Schematic *schematic)
+node_dot_removed_callback (NodeStore *store, SheetPos *pos, Schematic *schematic)
{
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
- g_signal_emit_by_name (G_OBJECT(schematic), "dot_removed", pos);
+ g_signal_emit_by_name (schematic, "node_dot_removed", pos);
}
static void
-schematic_init(Schematic *schematic)
+schematic_init (Schematic *schematic)
{
SchematicPriv *priv;
priv = schematic->priv = g_new0 (SchematicPriv, 1);
priv->printoptions = NULL;
- /* Colors */
+ // Colors
priv->colors.components.red = 65535;
priv->colors.components.green = 0;
priv->colors.components.blue = 0;
@@ -250,26 +229,21 @@ schematic_init(Schematic *schematic)
priv->colors.text.blue = 0;
priv->symbols = g_hash_table_new (g_str_hash, g_str_equal);
- /* FIXME: use own str_equal (lib::sym)*/
priv->refdes_values = g_hash_table_new (g_str_hash, g_str_equal);
priv->store = node_store_new ();
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);
+ "foreground", "red",
+ "weight", PANGO_WEIGHT_BOLD,
+ NULL);
- g_signal_connect_object (
- G_OBJECT (priv->store),
- "dot_added",
- G_CALLBACK(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 (
- G_OBJECT (priv->store),
- "dot_removed",
- G_CALLBACK(dot_removed_callback),
- G_OBJECT (schematic),
+ g_signal_connect_object (priv->store, "node_dot_removed",
+ G_CALLBACK (node_dot_removed_callback), G_OBJECT (schematic),
G_CONNECT_AFTER);
priv->sim_settings = sim_settings_new (schematic);
@@ -287,7 +261,7 @@ schematic_new (void)
{
Schematic *schematic;
- schematic = SCHEMATIC(g_object_new (TYPE_SCHEMATIC, NULL));
+ schematic = SCHEMATIC (g_object_new (TYPE_SCHEMATIC, NULL));
schematic_count_++;
schematic_list = g_list_prepend (schematic_list, schematic);
@@ -301,12 +275,12 @@ schematic_dispose (GObject *object)
Schematic *schematic;
GList *list;
- schematic = SCHEMATIC(object);
+ schematic = SCHEMATIC (object);
- /* Disconnect weak item signal */
- for(list=schematic->priv->items; list; list=list->next)
- g_object_weak_unref(G_OBJECT(list->data),
- item_data_destroy_callback, G_OBJECT(schematic));
+ // 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));
g_object_unref (G_OBJECT (schematic->priv->log));
@@ -314,36 +288,36 @@ schematic_dispose (GObject *object)
schematic_list = g_list_remove (schematic_list, schematic);
if (schematic_count_ == 0) {
- g_signal_emit_by_name(G_OBJECT (schematic),
- "last_schematic_destroyed", NULL);
+ g_signal_emit_by_name (schematic, "last_schematic_destroyed", NULL);
}
- G_OBJECT_CLASS(parent_class)->dispose(G_OBJECT(schematic));
+ g_list_free_full (list, g_object_unref);
+
+ G_OBJECT_CLASS (parent_class)->dispose (G_OBJECT (schematic));
}
static void
-schematic_finalize(GObject *object)
+schematic_finalize (GObject *object)
{
Schematic *sm;
- sm = SCHEMATIC(object);
+ 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);
+ 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);
+ g_free (sm->priv);
sm->priv = NULL;
}
- G_OBJECT_CLASS(parent_class)->finalize(G_OBJECT(sm));
+ G_OBJECT_CLASS (parent_class)->finalize (G_OBJECT (sm));
}
-/*
- * Get/set functions.
- */
+// Get/set functions.
+// ***************** /
char *
schematic_get_title (Schematic *schematic)
@@ -384,8 +358,7 @@ schematic_set_title (Schematic *schematic, const gchar *title)
g_free (schematic->priv->title);
schematic->priv->title = g_strdup (title);
- g_signal_emit_by_name (G_OBJECT (schematic),
- "title_changed", schematic->priv->title);
+ g_signal_emit_by_name (schematic, "title_changed", schematic->priv->title);
}
void
@@ -461,9 +434,6 @@ schematic_get_zoom (Schematic *schematic)
return schematic->priv->zoom;
}
-/*
- * FIXME: different zoom level on views...
- */
void
schematic_set_zoom (Schematic *schematic, double zoom)
{
@@ -542,21 +512,17 @@ schematic_log_show (Schematic *schematic)
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
- g_signal_emit_by_name (G_OBJECT(schematic),
- "log_updated", schematic->priv->log);
+ g_signal_emit_by_name (schematic, "log_updated", schematic->priv->log);
}
void
schematic_log_clear (Schematic *schematic)
{
- GList *log;
-
g_return_if_fail (schematic != NULL);
g_return_if_fail (IS_SCHEMATIC (schematic));
gtk_text_buffer_set_text (
- schematic->priv->log,
- "", -1);
+ schematic->priv->log, "", -1);
}
GtkTextBuffer*
@@ -601,7 +567,7 @@ schematic_read (char *name, GError **out_error)
return NULL;
}
- /* Get File Handler */
+ // Get File Handler
ft = file_manager_get_handler (fname);
if (ft == NULL) {
g_set_error (out_error, OREGANO_ERROR, OREGANO_SCHEMATIC_FILE_NOT_FOUND,
@@ -616,16 +582,17 @@ schematic_read (char *name, GError **out_error)
if (error != NULL) {
g_propagate_error (out_error, error);
- g_object_unref(G_OBJECT(new_sm));
+ g_object_unref (G_OBJECT (new_sm));
return NULL;
}
if (ret) {
- g_object_unref(G_OBJECT(new_sm));
+ g_object_unref (G_OBJECT (new_sm));
new_sm = NULL;
g_set_error (out_error, OREGANO_ERROR, OREGANO_SCHEMATIC_FILE_NOT_FOUND,
- _("Load fails!."), fname);
- } else
+ _("Load fails!."));
+ }
+ else
schematic_set_dirty (new_sm, FALSE);
return new_sm;
@@ -663,7 +630,7 @@ void
schematic_add_item (Schematic *sm, ItemData *data)
{
NodeStore *store;
- char *prefix, *refdes;
+ char *prefix = NULL, *refdes = NULL;
int num;
g_return_if_fail (sm != NULL);
@@ -672,16 +639,15 @@ schematic_add_item (Schematic *sm, ItemData *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_object_unref (G_OBJECT (data));
+ g_object_set (G_OBJECT (data),
+ "store", store,
+ NULL);
+
+ if (item_data_register (data) == -1)
+ // Item does not be added
return;
- }
- /*
- * Some items need a reference designator. Find a good one.
- */
+ // Some items need a reference designator. Find a good one.
prefix = item_data_get_refdes_prefix (data);
if (prefix != NULL) {
num = schematic_get_lowest_available_refdes (sm, prefix);
@@ -689,23 +655,21 @@ schematic_add_item (Schematic *sm, ItemData *data)
item_data_set_property (data, "refdes", refdes);
schematic_set_lowest_available_refdes (sm, prefix, num + 1);
-
- g_free (prefix);
- g_free (refdes);
}
+ g_free (prefix);
+ g_free (refdes);
- sm->priv->items = g_list_prepend(sm->priv->items, data);
- g_object_weak_ref(G_OBJECT(data), item_data_destroy_callback, G_OBJECT(sm));
+ 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(G_OBJECT(data),
- "moved",
- G_CALLBACK(part_moved_callback),
- sm,
- 0);
+ g_signal_connect_object (data, "moved", G_CALLBACK (item_moved_callback),
+ sm, 0);
sm->priv->dirty = TRUE;
- g_signal_emit_by_name(G_OBJECT(sm), "item_data_added", data);
+ g_signal_emit_by_name (sm,
+ "item_data_added", data);
}
void
@@ -723,6 +687,7 @@ 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
@@ -740,6 +705,7 @@ 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
@@ -754,9 +720,10 @@ schematic_items_foreach (Schematic *schematic,
if (func == NULL)
return;
- for (list = schematic->priv->items; list; list = list->next) {
+ for (list = schematic->priv->current_items; list; list = list->next) {
func (list->data, user_data);
}
+ g_list_free_full (list, g_object_unref);
}
GList *
@@ -765,16 +732,16 @@ schematic_get_items (Schematic *sm)
g_return_val_if_fail (sm != NULL, NULL);
g_return_val_if_fail (IS_SCHEMATIC (sm), NULL);
- return sm->priv->items;
+ return sm->priv->current_items;
}
static void
item_data_destroy_callback (gpointer s, GObject *data)
{
- Schematic *sm = SCHEMATIC(s);
+ Schematic *sm = SCHEMATIC (s);
schematic_set_dirty (sm, TRUE);
if (sm->priv) {
- sm->priv->items = g_list_remove (sm->priv->items, data);
+ sm->priv->current_items = g_list_remove (sm->priv->current_items, data);
}
}
@@ -790,7 +757,8 @@ schematic_get_lowest_available_refdes (Schematic *schematic, char *prefix)
if ( g_hash_table_lookup_extended (schematic->priv->refdes_values,
prefix, &key, &value) ) {
return GPOINTER_TO_INT (value);
- } else {
+ }
+ else {
return 1;
}
}
@@ -805,9 +773,8 @@ schematic_set_lowest_available_refdes (Schematic *schematic,
g_return_if_fail (IS_SCHEMATIC (schematic));
g_return_if_fail (prefix != NULL);
- /* If there already is a key, use it, otherwise copy the prefix and
- * use as key.
- */
+ // 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))
key = g_strdup (prefix);
@@ -817,7 +784,7 @@ schematic_set_lowest_available_refdes (Schematic *schematic,
}
gboolean
-schematic_is_dirty(Schematic *sm)
+schematic_is_dirty (Schematic *sm)
{
g_return_val_if_fail (sm != NULL, FALSE);
g_return_val_if_fail (IS_SCHEMATIC (sm), FALSE);
@@ -826,7 +793,7 @@ schematic_is_dirty(Schematic *sm)
}
void
-schematic_set_dirty(Schematic *sm, gboolean b)
+schematic_set_dirty (Schematic *sm, gboolean b)
{
g_return_if_fail (sm != NULL);
g_return_if_fail (IS_SCHEMATIC (sm));
@@ -835,7 +802,7 @@ schematic_set_dirty(Schematic *sm, gboolean b)
}
static void
-part_moved_callback (ItemData *data, SheetPos *pos, Schematic *sm)
+item_moved_callback (ItemData *data, SheetPos *pos, Schematic *sm)
{
g_return_if_fail (data != NULL);
g_return_if_fail (IS_ITEM_DATA (data));
@@ -847,17 +814,15 @@ 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);
- node_store_print_labels (store, cr, NULL);
}
GdkColor
-convert_to_grayscale(GdkColor *source)
+convert_to_grayscale (GdkColor *source)
{
GdkColor color;
int factor;
@@ -866,6 +831,7 @@ convert_to_grayscale(GdkColor *source)
color.red = factor;
color.green = factor;
color.blue = factor;
+ color.pixel = source->pixel;
return color;
}
@@ -874,11 +840,10 @@ void
schematic_export (Schematic *sm, const gchar *filename,
gint img_w, gint img_h, int bg, int color, int format)
{
- ArtDRect bbox;
+ NodeRect bbox;
NodeStore *store;
cairo_surface_t *surface;
cairo_t *cr;
- gdouble w, h;
gdouble graph_w, graph_h;
gdouble scale, scalew, scaleh;
SchematicColors colors;
@@ -895,9 +860,6 @@ schematic_export (Schematic *sm, const gchar *filename,
store = schematic_get_store (sm);
node_store_get_bounds (store, &bbox);
- w = bbox.x1 - bbox.x0;
- h = bbox.y1 - bbox.y0;
-
switch (format) {
#ifdef CAIRO_HAS_SVG_SURFACE
case 0:
@@ -919,14 +881,14 @@ schematic_export (Schematic *sm, const gchar *filename,
}
cr = cairo_create (surface);
- /* Background */
+ // Background
switch (bg) {
- case 1: /* White */
+ 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 */
+ 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);
@@ -941,20 +903,20 @@ schematic_export (Schematic *sm, const gchar *filename,
else
scale = scaleh;
- /* Preparing ...*/
+ // 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, -bbox.x0, -bbox.y0);
cairo_set_line_width (cr, 0.5);
- /* Render ... */
+ // Render...
schematic_render (sm, cr);
cairo_restore (cr);
cairo_show_page (cr);
- /* Saving ... */
+ // Saving...
if (format >= 3)
cairo_surface_write_to_png (surface, filename);
cairo_destroy (cr);
@@ -982,22 +944,16 @@ static void
draw_page (GtkPrintOperation *operation,
GtkPrintContext *context, int page_nr, Schematic *sm)
{
- PangoLayout *layout;
- PangoFontDescription *desc;
NodeStore *store;
- ArtDRect bbox;
+ NodeRect bbox;
gdouble page_w, page_h;
- gdouble circuit_w, circuit_h;
page_w = gtk_print_context_get_width (context);
page_h = gtk_print_context_get_height (context);
- circuit_w = page_w * 0.8;
- circuit_h = page_h * 0.8;
-
cairo_t *cr = gtk_print_context_get_cairo_context (context);
- /* Draw a red rectangle, as wide as the paper (inside the margins) */
+ // 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);
@@ -1018,9 +974,8 @@ draw_page (GtkPrintOperation *operation,
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
- */
+ // 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);
@@ -1030,45 +985,60 @@ draw_page (GtkPrintOperation *operation,
static GObject*
print_options (GtkPrintOperation *operation, Schematic *sm)
{
- GladeXML *gui;
+ 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_GLADEDIR "/print-options.glade", G_FILE_TEST_EXISTS)) {
- return G_OBJECT (gtk_label_new (_("Error loading print-options.glade")));
+ if (!g_file_test (OREGANO_UIDIR "/print-options.ui", G_FILE_TEST_EXISTS)) {
+ return G_OBJECT (gtk_label_new (_("Error loading print-options.ui")));
}
- gui = glade_xml_new (OREGANO_GLADEDIR "/print-options.glade",
- "widget", GETTEXT_PACKAGE);
- if (!gui) {
- return G_OBJECT (gtk_label_new (_("Error loading print-options.glade")));
+ 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")));
}
if (sm->priv->printoptions)
g_free (sm->priv->printoptions);
- sm->priv->printoptions = g_new0(SchematicPrintOptions, 1);
-
- sm->priv->printoptions->components = GTK_COLOR_BUTTON (glade_xml_get_widget (gui, "color_components"));
- sm->priv->printoptions->labels = GTK_COLOR_BUTTON (glade_xml_get_widget (gui, "color_labels"));
- sm->priv->printoptions->wires = GTK_COLOR_BUTTON (glade_xml_get_widget (gui, "color_wires"));
- sm->priv->printoptions->text = GTK_COLOR_BUTTON (glade_xml_get_widget (gui, "color_text"));
- sm->priv->printoptions->background = GTK_COLOR_BUTTON (glade_xml_get_widget (gui, "color_background"));
-
- /* Set default colors */
- gtk_color_button_set_color (GTK_COLOR_BUTTON (glade_xml_get_widget (gui, "color_components")),
- &sm->priv->colors.components);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (glade_xml_get_widget (gui, "color_labels")),
- &sm->priv->colors.labels);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (glade_xml_get_widget (gui, "color_wires")),
- &sm->priv->colors.wires);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (glade_xml_get_widget (gui, "color_text")),
- &sm->priv->colors.text);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (glade_xml_get_widget (gui, "color_background")),
- &sm->priv->colors.background);
-
- return (GObject *) (glade_xml_get_widget (gui, "widget"));
+ 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"));
+
+ // 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);
+
+ return gtk_builder_get_object (gui, "widget");
}
static void
-read_print_options(GtkPrintOperation *operation, GtkWidget *widget, Schematic *sm)
+read_print_options (GtkPrintOperation *operation, GtkWidget *widget, Schematic *sm)
{
SchematicPrintOptions *colors = sm->priv->printoptions;
@@ -1096,9 +1066,12 @@ schematic_print (Schematic *sm, GtkPageSetup *page, GtkPrintSettings *settings,
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"));