[AdgPath] Added adg_path_dup_cpml_path()
[adg.git] / adg / adg-model.c
blob3f6286e22d991058cf404de957e7a39527be2109
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 /**
22 * SECTION:model
23 * @title: AdgModel
24 * @short_description: The base class of the ADG model infrastructure
26 * A model is a conceptual representation of something. From an ADG
27 * user point of view, it is a collection of data and rules that
28 * defines how an object should be represented on a drawing.
30 * Because #AdgModel instances are only a conceptual idea, they are
31 * not renderable (that is, #AdgModel is not derived from #AdgEntity).
32 * Instead, it must be passed as subject to entities such as AdgStroke
33 * or AdgHatch.
34 **/
36 /**
37 * AdgModel:
39 * All fields are private and should not be used directly.
40 * Use its public methods instead.
41 **/
44 #include "adg-model.h"
45 #include "adg-model-private.h"
46 #include "adg-intl.h"
48 #define PARENT_CLASS ((GObjectClass *) adg_model_parent_class)
51 enum {
52 PROP_0
55 enum {
56 CHANGED,
57 LAST_SIGNAL
61 static void finalize (GObject *object);
62 static void get_property (GObject *object,
63 guint prop_id,
64 GValue *value,
65 GParamSpec *pspec);
66 static void set_property (GObject *object,
67 guint prop_id,
68 const GValue *value,
69 GParamSpec *pspec);
70 static void changed (AdgModel *model);
72 static guint signals[LAST_SIGNAL] = { 0 };
75 G_DEFINE_ABSTRACT_TYPE(AdgModel, adg_model, G_TYPE_OBJECT);
78 static void
79 adg_model_class_init(AdgModelClass *klass)
81 GObjectClass *gobject_class;
83 gobject_class = (GObjectClass *) klass;
85 g_type_class_add_private(klass, sizeof(AdgModelPrivate));
87 gobject_class->finalize = finalize;
88 gobject_class->get_property = get_property;
89 gobject_class->set_property = set_property;
91 klass->changed = changed;
93 /**
94 * AdgModel::changed:
95 * @model: an #AdgModel
97 * Notificates that the model has changed. By default, the model
98 * cache is invalidated.
99 **/
100 signals[CHANGED] = g_signal_new("changed", ADG_TYPE_MODEL,
101 G_SIGNAL_RUN_LAST|G_SIGNAL_NO_RECURSE,
102 G_STRUCT_OFFSET(AdgModelClass, changed),
103 NULL, NULL,
104 g_cclosure_marshal_VOID__VOID,
105 G_TYPE_NONE, 0);
108 static void
109 adg_model_init(AdgModel *model)
111 AdgModelPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE(model, ADG_TYPE_MODEL,
112 AdgModelPrivate);
113 model->priv = priv;
116 static void
117 finalize(GObject *object)
119 /* TODO: this is only a placeholder */
121 PARENT_CLASS->finalize(object);
125 static void
126 get_property(GObject *object,
127 guint prop_id, GValue *value, GParamSpec *pspec)
129 /* TODO: this is only a placeholder */
131 switch (prop_id) {
132 default:
133 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
134 break;
138 static void
139 set_property(GObject *object,
140 guint prop_id, const GValue *value, GParamSpec *pspec)
142 /* TODO: this is only a placeholder */
144 switch (prop_id) {
145 default:
146 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
147 break;
153 * adg_model_changed:
154 * @model: an #AdgModel
156 * Emits the "changed" signal on @model.
158 * This function is only useful in model implementations.
160 void
161 adg_model_changed(AdgModel *model)
163 g_return_if_fail(ADG_IS_MODEL(model));
165 g_signal_emit(model, signals[CHANGED], 0);
169 static void
170 changed(AdgModel *model)