[AdgPath] Added adg_path_append_{primitive,segment}()
[adg.git] / adg / adg-title-block.c
blob2376b01c1c657e642487f92a6cc468214785ad0f
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 *priv =
107 G_TYPE_INSTANCE_GET_PRIVATE(title_block, ADG_TYPE_TITLE_BLOCK,
108 AdgTitleBlockPrivate);
109 priv->name = NULL;
110 priv->material = NULL;
111 priv->treatment = NULL;
113 title_block->priv = priv;
116 static void
117 finalize(GObject *object)
119 AdgTitleBlock *title_block;
120 GObjectClass *object_class;
122 title_block = (AdgTitleBlock *) object;
123 object_class = (GObjectClass *) adg_title_block_parent_class;
125 g_free(title_block->priv->name);
126 g_free(title_block->priv->material);
127 g_free(title_block->priv->treatment);
129 if (object_class->finalize != NULL)
130 object_class->finalize(object);
134 static void
135 get_property(GObject *object,
136 guint prop_id, GValue *value, GParamSpec *pspec)
138 AdgTitleBlockPrivate *priv = ((AdgTitleBlock *) object)->priv;
140 switch (prop_id) {
141 case PROP_NAME:
142 g_value_set_string(value, priv->name);
143 break;
144 case PROP_MATERIAL:
145 g_value_set_string(value, priv->material);
146 break;
147 case PROP_TREATMENT:
148 g_value_set_string(value, priv->treatment);
149 break;
150 default:
151 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
152 break;
156 static void
157 set_property(GObject *object,
158 guint prop_id, const GValue *value, GParamSpec *pspec)
160 AdgTitleBlock *title_block = ADG_TITLE_BLOCK(object);
162 switch (prop_id) {
163 case PROP_NAME:
164 g_free(title_block->priv->name);
165 title_block->priv->name = g_value_dup_string(value);
166 break;
167 case PROP_MATERIAL:
168 g_free(title_block->priv->material);
169 title_block->priv->material = g_value_dup_string(value);
170 break;
171 case PROP_TREATMENT:
172 g_free(title_block->priv->treatment);
173 title_block->priv->treatment = g_value_dup_string(value);
174 break;
175 default:
176 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
177 break;
183 * adg_title_block_get_name:
184 * @title_block: an #AdgTitleBlock entity
186 * Gets the descriptive name associated to this title block.
187 * The title block name usually represents what is commonly
188 * referred as "title of the drawing".
190 * Return value: a copy of the title block name: it must be freed
191 * with g_free() when no longer needed
193 gchar *
194 adg_title_block_get_name(AdgTitleBlock *title_block)
196 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block), NULL);
198 return g_strdup(title_block->priv->name);
202 * adg_title_block_set_name:
203 * @title_block: an #AdgTitleBlock entity
204 * @name: the new name
206 * Sets a new name on the title block.
208 void
209 adg_title_block_set_name(AdgTitleBlock *title_block, const gchar *name)
211 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block));
213 g_free(title_block->priv->name);
214 title_block->priv->name = g_strdup(name);
215 g_object_notify((GObject *) title_block, "name");
220 * adg_title_block_get_material:
221 * @title_block: an #AdgTitleBlock entity
223 * Gets the material (a descriptive name) associated to this title
224 * block. This property is not always significative: on drawings
225 * representing more than one part (such as assemblies) the material
226 * item has no meaning.
228 * Return value: a copy of the material name: it must be freed
229 * with g_free() when no longer needed
231 gchar *
232 adg_title_block_get_material(AdgTitleBlock *title_block)
234 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block), NULL);
236 return g_strdup(title_block->priv->material);
240 * adg_title_block_set_material:
241 * @title_block: an #AdgTitleBlock entity
242 * @name: the new material
244 * Sets a new material on the title block.
246 void
247 adg_title_block_set_material(AdgTitleBlock *title_block,
248 const gchar *material)
250 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block));
252 g_free(title_block->priv->material);
253 title_block->priv->material = g_strdup(material);
254 g_object_notify((GObject *) title_block, "material");
259 * adg_title_block_get_treatment:
260 * @title_block: an #AdgTitleBlock entity
262 * Gets the treatment (a descriptive name) associated to this title
263 * block. As for :material property, also the treatment
264 * should be set only when applicable.
266 * Return value: a copy of the treatment description: it must be freed
267 * with g_free() when no longer needed
269 gchar *
270 adg_title_block_get_treatment(AdgTitleBlock *title_block)
272 g_return_val_if_fail(ADG_IS_TITLE_BLOCK(title_block), NULL);
274 return g_strdup(title_block->priv->treatment);
278 * adg_title_block_set_treatment:
279 * @title_block: an #AdgTitleBlock entity
280 * @name: the new treatment
282 * Sets a new treatment on the title block.
284 void
285 adg_title_block_set_treatment(AdgTitleBlock *title_block,
286 const gchar *treatment)
288 g_return_if_fail(ADG_IS_TITLE_BLOCK(title_block));
290 g_free(title_block->priv->treatment);
291 title_block->priv->treatment = g_strdup(treatment);
292 g_object_notify((GObject *) title_block, "treatment");