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)
53 static void finalize (GObject
*object
);
54 static void get_property (GObject
*object
,
58 static void set_property (GObject
*object
,
62 static void set_name (AdgModel
*model
,
64 static void set_material (AdgModel
*model
,
65 const gchar
*material
);
66 static void set_treatment (AdgModel
*model
,
67 const gchar
*treatment
);
69 static guint model_signals
[LAST_SIGNAL
] = { 0 };
72 G_DEFINE_TYPE(AdgModel
, adg_model
, G_TYPE_OBJECT
);
76 adg_model_class_init(AdgModelClass
*klass
)
78 GObjectClass
*gobject_class
;
81 gobject_class
= (GObjectClass
*) klass
;
83 g_type_class_add_private(klass
, sizeof(AdgModelPrivate
));
85 gobject_class
->set_property
= set_property
;
86 gobject_class
->get_property
= get_property
;
87 gobject_class
->finalize
= finalize
;
89 param
= g_param_spec_string("name",
91 P_("Descriptive name of this part"),
92 NULL
, G_PARAM_READWRITE
);
93 g_object_class_install_property(gobject_class
, PROP_NAME
, param
);
95 param
= g_param_spec_string("material",
97 P_("Material this part is done with"),
98 NULL
, G_PARAM_READWRITE
);
99 g_object_class_install_property(gobject_class
, PROP_MATERIAL
, param
);
101 param
= g_param_spec_string("treatment",
103 P_("Treatment this part must receive"),
104 NULL
, G_PARAM_READWRITE
);
105 g_object_class_install_property(gobject_class
, PROP_TREATMENT
, param
);
109 adg_model_init(AdgModel
*model
)
111 AdgModelPrivate
*priv
=
112 G_TYPE_INSTANCE_GET_PRIVATE(model
, ADG_TYPE_MODEL
,
115 priv
->material
= NULL
;
116 priv
->treatment
= NULL
;
122 finalize(GObject
*object
)
124 AdgModel
*model
= (AdgModel
*) object
;
126 g_free(model
->priv
->name
);
127 g_free(model
->priv
->material
);
128 g_free(model
->priv
->treatment
);
130 PARENT_CLASS
->finalize(object
);
135 get_property(GObject
*object
,
136 guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
138 AdgModelPrivate
*priv
= ((AdgModel
*) object
)->priv
;
142 g_value_set_string(value
, priv
->name
);
145 g_value_set_string(value
, priv
->material
);
148 g_value_set_string(value
, priv
->treatment
);
151 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
157 set_property(GObject
*object
,
158 guint prop_id
, const GValue
*value
, GParamSpec
*pspec
)
160 AdgModel
*model
= ADG_MODEL(object
);
164 set_name(model
, g_value_get_string(value
));
167 set_material(model
, g_value_get_string(value
));
170 set_treatment(model
, g_value_get_string(value
));
173 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
180 adg_model_get_name(AdgModel
*model
)
182 g_return_val_if_fail(ADG_IS_MODEL(model
), NULL
);
184 return g_strdup(model
->priv
->name
);
188 adg_model_set_name(AdgModel
*model
, const gchar
*name
)
190 g_return_if_fail(ADG_IS_MODEL(model
));
192 set_name(model
, name
);
193 g_object_notify((GObject
*) model
, "name");
198 adg_model_get_material(AdgModel
*model
)
200 g_return_val_if_fail(ADG_IS_MODEL(model
), NULL
);
202 return g_strdup(model
->priv
->material
);
206 adg_model_set_material(AdgModel
*model
, const gchar
*material
)
208 g_return_if_fail(ADG_IS_MODEL(model
));
210 set_material(model
, material
);
211 g_object_notify((GObject
*) model
, "material");
216 adg_model_get_treatment(AdgModel
*model
)
218 g_return_val_if_fail(ADG_IS_MODEL(model
), NULL
);
220 return g_strdup(model
->priv
->treatment
);
224 adg_model_set_treatment(AdgModel
*model
, const gchar
*treatment
)
226 g_return_if_fail(ADG_IS_MODEL(model
));
228 set_treatment(model
, treatment
);
229 g_object_notify((GObject
*) model
, "treatment");
233 set_name(AdgModel
*model
, const gchar
*name
)
235 g_free(model
->priv
->name
);
236 model
->priv
->name
= g_strdup(name
);
240 set_material(AdgModel
*model
, const gchar
*material
)
242 g_free(model
->priv
->material
);
243 model
->priv
->material
= g_strdup(material
);
247 set_treatment(AdgModel
*model
, const gchar
*treatment
)
249 g_free(model
->priv
->treatment
);
250 model
->priv
->treatment
= g_strdup(treatment
);