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.
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"
37 #define PARENT_CLASS ((GObjectClass *) adg_model_parent_class)
55 static void finalize (GObject
*object
);
56 static void get_property (GObject
*object
,
60 static void set_property (GObject
*object
,
64 static void set_name (AdgModel
*model
,
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
);
78 adg_model_class_init (AdgModelClass
*klass
)
80 GObjectClass
*gobject_class
;
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",
93 P_("Descriptive name of this part"),
96 g_object_class_install_property (gobject_class
, PROP_NAME
, param
);
98 param
= g_param_spec_string ("material",
100 P_("Material this part is done with"),
103 g_object_class_install_property (gobject_class
, PROP_MATERIAL
, param
);
105 param
= g_param_spec_string ("treatment",
107 P_("Treatment this part must receive"),
110 g_object_class_install_property (gobject_class
, PROP_TREATMENT
, param
);
114 adg_model_init (AdgModel
*model
)
116 AdgModelPrivate
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (model
, ADG_TYPE_MODEL
,
119 priv
->material
= NULL
;
120 priv
->treatment
= NULL
;
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
);
139 get_property (GObject
*object
,
144 AdgModelPrivate
*priv
= ((AdgModel
*) object
)->priv
;
149 g_value_set_string (value
, priv
->name
);
152 g_value_set_string (value
, priv
->material
);
155 g_value_set_string (value
, priv
->treatment
);
158 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
164 set_property (GObject
*object
,
169 AdgModel
*model
= ADG_MODEL (object
);
174 set_name (model
, g_value_get_string (value
));
177 set_material (model
, g_value_get_string (value
));
180 set_treatment (model
, g_value_get_string (value
));
183 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
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
);
198 adg_model_set_name (AdgModel
*model
,
201 g_return_if_fail (ADG_IS_MODEL (model
));
203 set_name (model
, name
);
204 g_object_notify ((GObject
*) model
, "name");
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
);
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");
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
);
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");
246 set_name (AdgModel
*model
,
249 g_free (model
->priv
->name
);
250 model
->priv
->name
= g_strdup (name
);
254 set_material (AdgModel
*model
,
255 const gchar
*material
)
257 g_free (model
->priv
->material
);
258 model
->priv
->material
= g_strdup (material
);
262 set_treatment (AdgModel
*model
,
263 const gchar
*treatment
)
265 g_free (model
->priv
->treatment
);
266 model
->priv
->treatment
= g_strdup (treatment
);