[AdgTitleBlock] Hidden private struct
[adg.git] / adg / adg-title-block.c
blobcf7edcdd9c3c2c0bf46a5db4a9e903bf43491584
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"
48 enum {
49 PROP_0,
50 PROP_NAME,
51 PROP_MATERIAL,
52 PROP_TREATMENT
56 static void finalize (GObject *object);
57 static void get_property (GObject *object,
58 guint prop_id,
59 GValue *value,
60 GParamSpec *pspec);
61 static void set_property (GObject *object,
62 guint prop_id,
63 const GValue *value,
64 GParamSpec *pspec);
67 G_DEFINE_TYPE(AdgTitleBlock, adg_title_block, ADG_TYPE_ENTITY);
70 static void
71 adg_title_block_class_init(AdgTitleBlockClass *klass)
73 GObjectClass *gobject_class;
74 GParamSpec *param;
76 gobject_class = (GObjectClass *) klass;
78 g_type_class_add_private(klass, sizeof(AdgTitleBlockPrivate));
80 gobject_class->set_property = set_property;
81 gobject_class->get_property = get_property;
82 gobject_class->finalize = finalize;
84 param = g_param_spec_string("name",
85 P_("Part Name"),
86 P_("Descriptive name of this part"),
87 NULL, G_PARAM_READWRITE);
88 g_object_class_install_property(gobject_class, PROP_NAME, param);
90 param = g_param_spec_string("material",
91 P_("Material"),
92 P_("Material this part is done with"),
93 NULL, G_PARAM_READWRITE);
94 g_object_class_install_property(gobject_class, PROP_MATERIAL, param);
96 param = g_param_spec_string("treatment",
97 P_("Treatment"),
98 P_("Treatment this part must receive"),
99 NULL, G_PARAM_READWRITE);
100 g_object_class_install_property(gobject_class, PROP_TREATMENT, param);
103 static void
104 adg_title_block_init(AdgTitleBlock *title_block)
106 AdgTitleBlockPrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(title_block,
107 ADG_TYPE_TITLE_BLOCK,
108 AdgTitleBlockPrivate);
109 data->name = NULL;
110 data->material = NULL;
111 data->treatment = NULL;
113 title_block->data = data;
116 static void
117 finalize(GObject *object)
119 AdgTitleBlock *title_block;
120 AdgTitleBlockPrivate *data;
121 GObjectClass *object_class;
123 title_block = (AdgTitleBlock *) object;
124 data = title_block->data;
125 object_class = (GObjectClass *) adg_title_block_parent_class;
127 g_free(data->name);
128 g_free(data->material);
129 g_free(data->treatment);
131 if (object_class->finalize != NULL)
132 object_class->finalize(object);
136 static void
137 get_property(GObject *object,
138 guint prop_id, GValue *value, GParamSpec *pspec)
140 AdgTitleBlockPrivate *data = ((AdgTitleBlock *) object)->data;
142 switch (prop_id) {
143 case PROP_NAME:
144 g_value_set_string(value, data->name);
145 break;
146 case PROP_MATERIAL:
147 g_value_set_string(value, data->material);
148 break;
149 case PROP_TREATMENT:
150 g_value_set_string(value, data->treatment);
151 break;
152 default:
153 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
154 break;
158 static void
159 set_property(GObject *object,
160 guint prop_id, const GValue *value, GParamSpec *pspec)
162 AdgTitleBlockPrivate *data = ((AdgTitleBlock *) object)->data;
164 switch (prop_id) {
165 case PROP_NAME:
166 g_free(data->name);
167 data->name = g_value_dup_string(value);
168 break;
169 case PROP_MATERIAL:
170 g_free(data->material);
171 data->material = g_value_dup_string(value);
172 break;
173 case PROP_TREATMENT:
174 g_free(data->treatment);
175 data->treatment = g_value_dup_string(value);
176 break;
177 default:
178 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
179 break;
185 * adg_title_block_get_name:
186 * @title_block: an #AdgTitleBlock entity
188 * Gets the descriptive name associated to this title block.
189 * The title block name usually represents what is commonly
190 * referred as "title of the drawing".
192 * Return value: a copy of the title block name: it must be freed
193 * with g_free() when no longer needed
195 gchar *
196 adg_title_block_get_name(AdgTitleBlock *title_block)
198 AdgTitleBlockPrivate *data;
200 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block), NULL);
202 data = title_block->data;
204 return g_strdup(data->name);
208 * adg_title_block_set_name:
209 * @title_block: an #AdgTitleBlock entity
210 * @name: the new name
212 * Sets a new name on the title block.
214 void
215 adg_title_block_set_name(AdgTitleBlock *title_block, const gchar *name)
217 AdgTitleBlockPrivate *data;
219 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block));
221 data = title_block->data;
222 g_free(data->name);
223 data->name = g_strdup(name);
225 g_object_notify((GObject *) title_block, "name");
230 * adg_title_block_get_material:
231 * @title_block: an #AdgTitleBlock entity
233 * Gets the material (a descriptive name) associated to this title
234 * block. This property is not always significative: on drawings
235 * representing more than one part (such as assemblies) the material
236 * item has no meaning.
238 * Return value: a copy of the material name: it must be freed
239 * with g_free() when no longer needed
241 gchar *
242 adg_title_block_get_material(AdgTitleBlock *title_block)
244 AdgTitleBlockPrivate *data;
246 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block), NULL);
248 data = title_block->data;
250 return g_strdup(data->material);
254 * adg_title_block_set_material:
255 * @title_block: an #AdgTitleBlock entity
256 * @name: the new material
258 * Sets a new material on the title block.
260 void
261 adg_title_block_set_material(AdgTitleBlock *title_block,
262 const gchar *material)
264 AdgTitleBlockPrivate *data;
266 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block));
268 data = title_block->data;
269 g_free(data->material);
270 data->material = g_strdup(material);
271 g_object_notify((GObject *) title_block, "material");
276 * adg_title_block_get_treatment:
277 * @title_block: an #AdgTitleBlock entity
279 * Gets the treatment (a descriptive name) associated to this title
280 * block. As for :material property, also the treatment
281 * should be set only when applicable.
283 * Return value: a copy of the treatment description: it must be freed
284 * with g_free() when no longer needed
286 gchar *
287 adg_title_block_get_treatment(AdgTitleBlock *title_block)
289 AdgTitleBlockPrivate *data;
291 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block), NULL);
293 data = title_block->data;
295 return g_strdup(data->treatment);
299 * adg_title_block_set_treatment:
300 * @title_block: an #AdgTitleBlock entity
301 * @name: the new treatment
303 * Sets a new treatment on the title block.
305 void
306 adg_title_block_set_treatment(AdgTitleBlock *title_block,
307 const gchar *treatment)
309 AdgTitleBlockPrivate *data;
311 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block));
313 data = title_block->data;
314 g_free(data->treatment);
315 data->treatment = g_strdup(treatment);
316 g_object_notify((GObject *) title_block, "treatment");