Updated docs for slots related changes
[adg.git] / adg / adg-model.c
blob7e20976bdf53d11091e142d9cdd11ab007b8218c
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2008, 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 Library 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 * Library 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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 /**
22 * SECTION:model
23 * @title: AdgModel
24 * @short_description: The data model
26 * Every drawing is a representation of a part: the #AdgModel contains all the
27 * data needed by the drawing (overall, quotes).
29 * Because the #AdgModel instances are only a data collection, they are not
30 * renderable, so the class is not derived from #AdgEntity.
33 #include "adg-model.h"
34 #include "adg-model-private.h"
35 #include "adg-intl.h"
37 #define PARENT_CLASS ((GObjectClass *) adg_model_parent_class)
40 enum
42 PROP_0,
43 PROP_NAME,
44 PROP_MATERIAL,
45 PROP_TREATMENT
48 enum
50 MODIFIED,
51 LAST_SIGNAL
55 static void finalize (GObject *object);
56 static void get_property (GObject *object,
57 guint prop_id,
58 GValue *value,
59 GParamSpec *pspec);
60 static void set_property (GObject *object,
61 guint prop_id,
62 const GValue *value,
63 GParamSpec *pspec);
64 static void set_name (AdgModel *model,
65 const gchar *name);
66 static void set_material (AdgModel *model,
67 const gchar *material);
68 static void set_treatment (AdgModel *model,
69 const gchar *treatment);
71 static guint model_signals[LAST_SIGNAL] = { 0 };
74 G_DEFINE_TYPE (AdgModel, adg_model, G_TYPE_OBJECT);
77 static void
78 adg_model_class_init (AdgModelClass *klass)
80 GObjectClass *gobject_class;
81 GParamSpec *param;
83 gobject_class = (GObjectClass *) klass;
85 g_type_class_add_private (klass, sizeof (AdgModelPrivate));
87 gobject_class->set_property = set_property;
88 gobject_class->get_property = get_property;
89 gobject_class->finalize = finalize;
91 param = g_param_spec_string ("name",
92 P_("Part Name"),
93 P_("Descriptive name of this part"),
94 NULL,
95 G_PARAM_READWRITE);
96 g_object_class_install_property (gobject_class, PROP_NAME, param);
98 param = g_param_spec_string ("material",
99 P_("Material"),
100 P_("Material this part is done with"),
101 NULL,
102 G_PARAM_READWRITE);
103 g_object_class_install_property (gobject_class, PROP_MATERIAL, param);
105 param = g_param_spec_string ("treatment",
106 P_("Treatment"),
107 P_("Treatment this part must receive"),
108 NULL,
109 G_PARAM_READWRITE);
110 g_object_class_install_property (gobject_class, PROP_TREATMENT, param);
113 static void
114 adg_model_init (AdgModel *model)
116 AdgModelPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (model, ADG_TYPE_MODEL,
117 AdgModelPrivate);
118 priv->name = NULL;
119 priv->material = NULL;
120 priv->treatment = NULL;
122 model->priv = priv;
125 static void
126 finalize (GObject *object)
128 AdgModel *model = (AdgModel *) object;
130 g_free (model->priv->name);
131 g_free (model->priv->material);
132 g_free (model->priv->treatment);
134 PARENT_CLASS->finalize (object);
138 static void
139 get_property (GObject *object,
140 guint prop_id,
141 GValue *value,
142 GParamSpec *pspec)
144 AdgModelPrivate *priv = ((AdgModel *) object)->priv;
146 switch (prop_id)
148 case PROP_NAME:
149 g_value_set_string (value, priv->name);
150 break;
151 case PROP_MATERIAL:
152 g_value_set_string (value, priv->material);
153 break;
154 case PROP_TREATMENT:
155 g_value_set_string (value, priv->treatment);
156 break;
157 default:
158 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
159 break;
163 static void
164 set_property (GObject *object,
165 guint prop_id,
166 const GValue *value,
167 GParamSpec *pspec)
169 AdgModel *model = ADG_MODEL (object);
171 switch (prop_id)
173 case PROP_NAME:
174 set_name (model, g_value_get_string (value));
175 break;
176 case PROP_MATERIAL:
177 set_material (model, g_value_get_string (value));
178 break;
179 case PROP_TREATMENT:
180 set_treatment (model, g_value_get_string (value));
181 break;
182 default:
183 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
184 break;
189 gchar *
190 adg_model_get_name (AdgModel *model)
192 g_return_val_if_fail (ADG_IS_MODEL (model), NULL);
194 return g_strdup (model->priv->name);
197 void
198 adg_model_set_name (AdgModel *model,
199 const gchar *name)
201 g_return_if_fail (ADG_IS_MODEL (model));
203 set_name (model, name);
204 g_object_notify ((GObject *) model, "name");
208 gchar *
209 adg_model_get_material (AdgModel *model)
211 g_return_val_if_fail (ADG_IS_MODEL (model), NULL);
213 return g_strdup (model->priv->material);
216 void
217 adg_model_set_material (AdgModel *model,
218 const gchar *material)
220 g_return_if_fail (ADG_IS_MODEL (model));
222 set_material (model, material);
223 g_object_notify ((GObject *) model, "material");
227 gchar *
228 adg_model_get_treatment (AdgModel *model)
230 g_return_val_if_fail (ADG_IS_MODEL (model), NULL);
232 return g_strdup (model->priv->treatment);
235 void
236 adg_model_set_treatment (AdgModel *model,
237 const gchar *treatment)
239 g_return_if_fail (ADG_IS_MODEL (model));
241 set_treatment (model, treatment);
242 g_object_notify ((GObject *) model, "treatment");
245 static void
246 set_name (AdgModel *model,
247 const gchar *name)
249 g_free (model->priv->name);
250 model->priv->name = g_strdup (name);
253 static void
254 set_material (AdgModel *model,
255 const gchar *material)
257 g_free (model->priv->material);
258 model->priv->material = g_strdup (material);
261 static void
262 set_treatment (AdgModel *model,
263 const gchar *treatment)
265 g_free (model->priv->treatment);
266 model->priv->treatment = g_strdup (treatment);