[AdgLDim] Removed PARENT_CLASS define
[adg.git] / adg / adg-title-block.c
blob76d08a95c963c990def3383a30f58ebe8580627f
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:title-block
23 * @title: AdgTitleBlock
24 * @short_description: A title block entity
26 * Title blocks are commonly used in technical drawings to include
27 * additional information not strictly related to physical dimensions,
28 * such as title, material of the represented part, special treatments,
29 * date and scale etc.
31 * Actually this entity is only a place-holder: it will be implemented
32 * properly in a 0.6.x release, after having AdgToyTable in place.
33 **/
35 /**
36 * AdgTitleBlock:
38 * All fields are private and should not be used directly.
39 * Use its public methods instead.
40 **/
43 #include "adg-title-block.h"
44 #include "adg-title-block-private.h"
45 #include "adg-intl.h"
47 #define PARENT_CLASS ((GObjectClass *) adg_title_block_parent_class)
50 enum {
51 PROP_0,
52 PROP_NAME,
53 PROP_MATERIAL,
54 PROP_TREATMENT
58 static void finalize (GObject *object);
59 static void get_property (GObject *object,
60 guint prop_id,
61 GValue *value,
62 GParamSpec *pspec);
63 static void set_property (GObject *object,
64 guint prop_id,
65 const GValue *value,
66 GParamSpec *pspec);
69 G_DEFINE_TYPE(AdgTitleBlock, adg_title_block, ADG_TYPE_ENTITY);
72 static void
73 adg_title_block_class_init(AdgTitleBlockClass *klass)
75 GObjectClass *gobject_class;
76 GParamSpec *param;
78 gobject_class = (GObjectClass *) klass;
80 g_type_class_add_private(klass, sizeof(AdgTitleBlockPrivate));
82 gobject_class->set_property = set_property;
83 gobject_class->get_property = get_property;
84 gobject_class->finalize = finalize;
86 param = g_param_spec_string("name",
87 P_("Part Name"),
88 P_("Descriptive name of this part"),
89 NULL, G_PARAM_READWRITE);
90 g_object_class_install_property(gobject_class, PROP_NAME, param);
92 param = g_param_spec_string("material",
93 P_("Material"),
94 P_("Material this part is done with"),
95 NULL, G_PARAM_READWRITE);
96 g_object_class_install_property(gobject_class, PROP_MATERIAL, param);
98 param = g_param_spec_string("treatment",
99 P_("Treatment"),
100 P_("Treatment this part must receive"),
101 NULL, G_PARAM_READWRITE);
102 g_object_class_install_property(gobject_class, PROP_TREATMENT, param);
105 static void
106 adg_title_block_init(AdgTitleBlock *title_block)
108 AdgTitleBlockPrivate *priv =
109 G_TYPE_INSTANCE_GET_PRIVATE(title_block, ADG_TYPE_TITLE_BLOCK,
110 AdgTitleBlockPrivate);
111 priv->name = NULL;
112 priv->material = NULL;
113 priv->treatment = NULL;
115 title_block->priv = priv;
118 static void
119 finalize(GObject *object)
121 AdgTitleBlock *title_block = (AdgTitleBlock *) object;
123 g_free(title_block->priv->name);
124 g_free(title_block->priv->material);
125 g_free(title_block->priv->treatment);
127 PARENT_CLASS->finalize(object);
131 static void
132 get_property(GObject *object,
133 guint prop_id, GValue *value, GParamSpec *pspec)
135 AdgTitleBlockPrivate *priv = ((AdgTitleBlock *) object)->priv;
137 switch (prop_id) {
138 case PROP_NAME:
139 g_value_set_string(value, priv->name);
140 break;
141 case PROP_MATERIAL:
142 g_value_set_string(value, priv->material);
143 break;
144 case PROP_TREATMENT:
145 g_value_set_string(value, priv->treatment);
146 break;
147 default:
148 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
149 break;
153 static void
154 set_property(GObject *object,
155 guint prop_id, const GValue *value, GParamSpec *pspec)
157 AdgTitleBlock *title_block = ADG_TITLE_BLOCK(object);
159 switch (prop_id) {
160 case PROP_NAME:
161 g_free(title_block->priv->name);
162 title_block->priv->name = g_value_dup_string(value);
163 break;
164 case PROP_MATERIAL:
165 g_free(title_block->priv->material);
166 title_block->priv->material = g_value_dup_string(value);
167 break;
168 case PROP_TREATMENT:
169 g_free(title_block->priv->treatment);
170 title_block->priv->treatment = g_value_dup_string(value);
171 break;
172 default:
173 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
174 break;
180 * adg_title_block_get_name:
181 * @title_block: an #AdgTitleBlock entity
183 * Gets the descriptive name associated to this title block.
184 * The title block name usually represents what is commonly
185 * referred as "title of the drawing".
187 * Return value: a copy of the title block name: it must be freed
188 * with g_free() when no longer needed
190 gchar *
191 adg_title_block_get_name(AdgTitleBlock *title_block)
193 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block), NULL);
195 return g_strdup(title_block->priv->name);
199 * adg_title_block_set_name:
200 * @title_block: an #AdgTitleBlock entity
201 * @name: the new name
203 * Sets a new name on the title block.
205 void
206 adg_title_block_set_name(AdgTitleBlock *title_block, const gchar *name)
208 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block));
210 g_free(title_block->priv->name);
211 title_block->priv->name = g_strdup(name);
212 g_object_notify((GObject *) title_block, "name");
217 * adg_title_block_get_material:
218 * @title_block: an #AdgTitleBlock entity
220 * Gets the material (a descriptive name) associated to this title
221 * block. This property is not always significative: on drawings
222 * representing more than one part (such as assemblies) the material
223 * item has no meaning.
225 * Return value: a copy of the material name: it must be freed
226 * with g_free() when no longer needed
228 gchar *
229 adg_title_block_get_material(AdgTitleBlock *title_block)
231 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block), NULL);
233 return g_strdup(title_block->priv->material);
237 * adg_title_block_set_material:
238 * @title_block: an #AdgTitleBlock entity
239 * @name: the new material
241 * Sets a new material on the title block.
243 void
244 adg_title_block_set_material(AdgTitleBlock *title_block,
245 const gchar *material)
247 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block));
249 g_free(title_block->priv->material);
250 title_block->priv->material = g_strdup(material);
251 g_object_notify((GObject *) title_block, "material");
256 * adg_title_block_get_treatment:
257 * @title_block: an #AdgTitleBlock entity
259 * Gets the treatment (a descriptive name) associated to this title
260 * block. As for :material property, also the treatment
261 * should be set only when applicable.
263 * Return value: a copy of the treatment description: it must be freed
264 * with g_free() when no longer needed
266 gchar *
267 adg_title_block_get_treatment(AdgTitleBlock *title_block)
269 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block), NULL);
271 return g_strdup(title_block->priv->treatment);
275 * adg_title_block_set_treatment:
276 * @title_block: an #AdgTitleBlock entity
277 * @name: the new treatment
279 * Sets a new treatment on the title block.
281 void
282 adg_title_block_set_treatment(AdgTitleBlock *title_block,
283 const gchar *treatment)
285 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block));
287 g_free(title_block->priv->treatment);
288 title_block->priv->treatment = g_strdup(treatment);
289 g_object_notify((GObject *) title_block, "treatment");