[AdgADim] Removed useless G_PARAM_CONSTRUCT
[adg.git] / adg / adg-adim.c
blob51701f9ca9698a10925ddad78c1a2ab34437eca9
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-adim
23 * @short_description: Angular dimensions
25 * The #AdgADim entity represents an angular dimension.
28 /**
29 * AdgADim:
31 * All fields are privates and should not be used directly.
32 * Use its public methods instead.
33 **/
36 #include "adg-adim.h"
37 #include "adg-adim-private.h"
38 #include "adg-container.h"
39 #include "adg-intl.h"
42 enum {
43 PROP_0,
44 PROP_ANGLE1,
45 PROP_ANGLE2
49 static void finalize (GObject *object);
50 static void get_property (GObject *object,
51 guint param_id,
52 GValue *value,
53 GParamSpec *pspec);
54 static void set_property (GObject *object,
55 guint param_id,
56 const GValue *value,
57 GParamSpec *pspec);
58 static gboolean render (AdgEntity *entity,
59 cairo_t *cr);
60 static gchar * default_value (AdgDim *dim);
61 static void set_angle1 (AdgADim *adim,
62 gdouble angle);
63 static void set_angle2 (AdgADim *adim,
64 gdouble angle2);
67 G_DEFINE_TYPE(AdgADim, adg_adim, ADG_TYPE_DIM);
70 static void
71 adg_adim_class_init(AdgADimClass *klass)
73 GObjectClass *gobject_class;
74 AdgEntityClass *entity_class;
75 AdgDimClass *dim_class;
76 GParamSpec *param;
78 gobject_class = (GObjectClass *) klass;
79 entity_class = (AdgEntityClass *) klass;
80 dim_class = (AdgDimClass *) klass;
82 g_type_class_add_private(klass, sizeof(AdgADimPrivate));
84 gobject_class->finalize = finalize;
85 gobject_class->get_property = get_property;
86 gobject_class->set_property = set_property;
88 entity_class->render = render;
90 dim_class->default_value = default_value;
92 param = g_param_spec_double("angle1",
93 P_("Angle 1"),
94 P_("Angle of the first reference line"),
95 -G_MAXDOUBLE, G_MAXDOUBLE, 0,
96 G_PARAM_READWRITE);
97 g_object_class_install_property(gobject_class, PROP_ANGLE1, param);
99 param = g_param_spec_double("angle2",
100 P_("Angle 2"),
101 P_("Angle of the second reference line"),
102 -G_MAXDOUBLE, G_MAXDOUBLE, 0,
103 G_PARAM_READWRITE);
104 g_object_class_install_property(gobject_class, PROP_ANGLE2, param);
107 static void
108 adg_adim_init(AdgADim *adim)
110 AdgADimPrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(adim, ADG_TYPE_ADIM,
111 AdgADimPrivate);
113 data->extension1.status = CAIRO_STATUS_SUCCESS;
114 data->extension1.data = NULL;
115 data->extension1.num_data = 4;
117 data->extension2.status = CAIRO_STATUS_SUCCESS;
118 data->extension2.data = NULL;
119 data->extension2.num_data = 4;
121 data->arrow_path.status = CAIRO_STATUS_SUCCESS;
122 data->arrow_path.data = NULL;
123 data->arrow_path.num_data = 4;
125 data->baseline.status = CAIRO_STATUS_SUCCESS;
126 data->baseline.data = NULL;
127 data->baseline.num_data = 4;
129 adim->data = data;
132 static void
133 finalize(GObject *object)
135 AdgADimPrivate *data = ((AdgADim *) object)->data;
137 g_free(data->extension1.data);
138 g_free(data->extension2.data);
139 g_free(data->arrow_path.data);
140 g_free(data->baseline.data);
143 static void
144 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
146 AdgADimPrivate *data = ((AdgADim *) object)->data;
148 switch (prop_id) {
149 case PROP_ANGLE1:
150 g_value_set_double(value, data->angle1);
151 break;
152 case PROP_ANGLE2:
153 g_value_set_double(value, data->angle2);
154 break;
155 default:
156 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
157 break;
161 static void
162 set_property(GObject *object, guint prop_id,
163 const GValue *value, GParamSpec *pspec)
165 AdgADim *adim = (AdgADim *) object;
167 switch (prop_id) {
168 case PROP_ANGLE1:
169 set_angle1(adim, g_value_get_double(value));
170 break;
171 case PROP_ANGLE2:
172 set_angle2(adim, g_value_get_double(value));
173 break;
174 default:
175 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
176 break;
180 static gboolean
181 render(AdgEntity *entity, cairo_t *cr)
183 /* TODO */
184 return FALSE;
187 static gchar *
188 default_value(AdgDim *dim)
190 /* TODO */
191 return g_strdup("TODO");
197 * adg_adim_new:
199 * Creates a new - unreferenced - angular dimension. You must, at least, define
200 * the reference points with adg_dim_set_ref() and the position reference using
201 * adg_dim_set_pos().
203 * Returns: the newly created angular dimension entity
205 AdgADim *
206 adg_adim_new(void)
208 return g_object_new(ADG_TYPE_ADIM, NULL);
212 * adg_adim_get_angle1:
213 * @adim: an #AdgADim
215 * Gets the angle of the first reference line of @adim.
217 * Returns: an angle in radians or %0 on errors
219 gdouble
220 adg_adim_get_angle1(AdgADim *adim)
222 AdgADimPrivate *data;
224 g_return_val_if_fail(ADG_IS_ADIM(adim), 0);
226 data = adim->data;
228 return data->angle1;
232 * adg_adim_set_angle1:
233 * @adim: an #AdgADim
234 * @angle: the new angle (in radians)
236 * Sets the angle of the first reference line of @adim to @angle.
238 void
239 adg_adim_set_angle1(AdgADim *adim, gdouble angle)
241 g_return_if_fail(ADG_IS_ADIM(adim));
243 set_angle1(adim, angle);
245 g_object_notify((GObject *) adim, "angle1");
249 * adg_adim_get_angle2:
250 * @adim: an #AdgADim
252 * Gets the angle of the second reference line of @adim.
254 * Returns: an angle in radians or %0 on errors
256 gdouble
257 adg_adim_get_angle2(AdgADim *adim)
259 AdgADimPrivate *data;
261 g_return_val_if_fail(ADG_IS_ADIM(adim), 0);
263 data = adim->data;
265 return data->angle2;
269 * adg_adim_set_angle2:
270 * @adim: an #AdgADim
271 * @angle: the new angle (in radians)
273 * Sets the angle of the first reference line of @adim to @angle.
275 void
276 adg_adim_set_angle2(AdgADim *adim, gdouble angle)
278 g_return_if_fail(ADG_IS_ADIM(adim));
280 set_angle2(adim, angle);
282 g_object_notify((GObject *) adim, "angle2");
286 static void
287 set_angle1(AdgADim *adim, gdouble angle)
289 AdgADimPrivate *data = adim->data;
291 data->angle1 = angle;
294 static void
295 set_angle2(AdgADim *adim, gdouble angle)
297 AdgADimPrivate *data = adim->data;
299 data->angle2 = angle;