[AdgRuledFill] Improved ruled creation algorithm
[adg.git] / adg / adg-title-block.c
blob997ee65ff55d6249c3e74a04af1633e83b5f55d5
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:adg-title-block
23 * @short_description: A title block entity
25 * Title blocks are commonly used in technical drawings to include
26 * additional information not strictly related to physical dimensions,
27 * such as title, material of the represented part, special treatments,
28 * date and scale etc.
30 * Actually this entity is only a place-holder: it will be implemented
31 * properly in a 0.6.x release, after having AdgToyTable in place.
32 **/
34 /**
35 * AdgTitleBlock:
37 * All fields are privates and should not be used directly.
38 * Use its public methods instead.
39 **/
42 #include "adg-title-block.h"
43 #include "adg-title-block-private.h"
44 #include "adg-intl.h"
47 enum {
48 PROP_0,
49 PROP_NAME,
50 PROP_MATERIAL,
51 PROP_TREATMENT
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);
66 G_DEFINE_TYPE(AdgTitleBlock, adg_title_block, ADG_TYPE_ENTITY);
69 static void
70 adg_title_block_class_init(AdgTitleBlockClass *klass)
72 GObjectClass *gobject_class;
73 GParamSpec *param;
75 gobject_class = (GObjectClass *) klass;
77 g_type_class_add_private(klass, sizeof(AdgTitleBlockPrivate));
79 gobject_class->set_property = set_property;
80 gobject_class->get_property = get_property;
81 gobject_class->finalize = finalize;
83 param = g_param_spec_string("name",
84 P_("Part Name"),
85 P_("Descriptive name of this part"),
86 NULL, G_PARAM_READWRITE);
87 g_object_class_install_property(gobject_class, PROP_NAME, param);
89 param = g_param_spec_string("material",
90 P_("Material"),
91 P_("Material this part is done with"),
92 NULL, G_PARAM_READWRITE);
93 g_object_class_install_property(gobject_class, PROP_MATERIAL, param);
95 param = g_param_spec_string("treatment",
96 P_("Treatment"),
97 P_("Treatment this part must receive"),
98 NULL, G_PARAM_READWRITE);
99 g_object_class_install_property(gobject_class, PROP_TREATMENT, param);
102 static void
103 adg_title_block_init(AdgTitleBlock *title_block)
105 AdgTitleBlockPrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(title_block,
106 ADG_TYPE_TITLE_BLOCK,
107 AdgTitleBlockPrivate);
108 data->name = NULL;
109 data->material = NULL;
110 data->treatment = NULL;
112 title_block->data = data;
115 static void
116 finalize(GObject *object)
118 AdgTitleBlock *title_block;
119 AdgTitleBlockPrivate *data;
120 GObjectClass *object_class;
122 title_block = (AdgTitleBlock *) object;
123 data = title_block->data;
124 object_class = (GObjectClass *) adg_title_block_parent_class;
126 g_free(data->name);
127 g_free(data->material);
128 g_free(data->treatment);
130 if (object_class->finalize != NULL)
131 object_class->finalize(object);
135 static void
136 get_property(GObject *object,
137 guint prop_id, GValue *value, GParamSpec *pspec)
139 AdgTitleBlockPrivate *data = ((AdgTitleBlock *) object)->data;
141 switch (prop_id) {
142 case PROP_NAME:
143 g_value_set_string(value, data->name);
144 break;
145 case PROP_MATERIAL:
146 g_value_set_string(value, data->material);
147 break;
148 case PROP_TREATMENT:
149 g_value_set_string(value, data->treatment);
150 break;
151 default:
152 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
153 break;
157 static void
158 set_property(GObject *object,
159 guint prop_id, const GValue *value, GParamSpec *pspec)
161 AdgTitleBlockPrivate *data = ((AdgTitleBlock *) object)->data;
163 switch (prop_id) {
164 case PROP_NAME:
165 g_free(data->name);
166 data->name = g_value_dup_string(value);
167 break;
168 case PROP_MATERIAL:
169 g_free(data->material);
170 data->material = g_value_dup_string(value);
171 break;
172 case PROP_TREATMENT:
173 g_free(data->treatment);
174 data->treatment = g_value_dup_string(value);
175 break;
176 default:
177 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
178 break;
184 * adg_title_block_get_name:
185 * @title_block: an #AdgTitleBlock entity
187 * Gets the descriptive name associated to this title block.
188 * The title block name usually represents what is commonly
189 * referred as "title of the drawing".
191 * Returns: a copy of the title block name: it must be freed
192 * with g_free() when no longer needed
194 gchar *
195 adg_title_block_get_name(AdgTitleBlock *title_block)
197 AdgTitleBlockPrivate *data;
199 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block), NULL);
201 data = title_block->data;
203 return g_strdup(data->name);
207 * adg_title_block_set_name:
208 * @title_block: an #AdgTitleBlock entity
209 * @name: the new name
211 * Sets a new name on the title block.
213 void
214 adg_title_block_set_name(AdgTitleBlock *title_block, const gchar *name)
216 AdgTitleBlockPrivate *data;
218 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block));
220 data = title_block->data;
221 g_free(data->name);
222 data->name = g_strdup(name);
224 g_object_notify((GObject *) title_block, "name");
229 * adg_title_block_get_material:
230 * @title_block: an #AdgTitleBlock entity
232 * Gets the material (a descriptive name) associated to this title
233 * block. This property is not always significative: on drawings
234 * representing more than one part (such as assemblies) the material
235 * item has no meaning.
237 * Returns: a copy of the material name: it must be freed
238 * with g_free() when no longer needed
240 gchar *
241 adg_title_block_get_material(AdgTitleBlock *title_block)
243 AdgTitleBlockPrivate *data;
245 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block), NULL);
247 data = title_block->data;
249 return g_strdup(data->material);
253 * adg_title_block_set_material:
254 * @title_block: an #AdgTitleBlock entity
255 * @name: the new material
257 * Sets a new material on the title block.
259 void
260 adg_title_block_set_material(AdgTitleBlock *title_block,
261 const gchar *material)
263 AdgTitleBlockPrivate *data;
265 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block));
267 data = title_block->data;
268 g_free(data->material);
269 data->material = g_strdup(material);
270 g_object_notify((GObject *) title_block, "material");
275 * adg_title_block_get_treatment:
276 * @title_block: an #AdgTitleBlock entity
278 * Gets the treatment (a descriptive name) associated to this title
279 * block. As for :material property, also the treatment
280 * should be set only when applicable.
282 * Returns: a copy of the treatment description: it must be freed
283 * with g_free() when no longer needed
285 gchar *
286 adg_title_block_get_treatment(AdgTitleBlock *title_block)
288 AdgTitleBlockPrivate *data;
290 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block), NULL);
292 data = title_block->data;
294 return g_strdup(data->treatment);
298 * adg_title_block_set_treatment:
299 * @title_block: an #AdgTitleBlock entity
300 * @name: the new treatment
302 * Sets a new treatment on the title block.
304 void
305 adg_title_block_set_treatment(AdgTitleBlock *title_block,
306 const gchar *treatment)
308 AdgTitleBlockPrivate *data;
310 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block));
312 data = title_block->data;
313 g_free(data->treatment);
314 data->treatment = g_strdup(treatment);
315 g_object_notify((GObject *) title_block, "treatment");