[demo] Added "Mapping" page to adg-demo
[adg.git] / adg / adg-adim.c
blob69fbe471ea466dc158db47b90cfefffa0e3c07f9
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-util.h"
40 #include "adg-intl.h"
43 enum {
44 PROP_0,
45 PROP_ANGLE1,
46 PROP_ANGLE2
50 static void finalize (GObject *object);
51 static void get_property (GObject *object,
52 guint param_id,
53 GValue *value,
54 GParamSpec *pspec);
55 static void set_property (GObject *object,
56 guint param_id,
57 const GValue *value,
58 GParamSpec *pspec);
59 static gboolean render (AdgEntity *entity,
60 cairo_t *cr);
61 static gchar * default_quote (AdgDim *dim);
62 static void set_angle1 (AdgADim *adim,
63 gdouble angle);
64 static void set_angle2 (AdgADim *adim,
65 gdouble angle2);
68 G_DEFINE_TYPE(AdgADim, adg_adim, ADG_TYPE_DIM);
71 static void
72 adg_adim_class_init(AdgADimClass *klass)
74 GObjectClass *gobject_class;
75 AdgEntityClass *entity_class;
76 AdgDimClass *dim_class;
77 GParamSpec *param;
79 gobject_class = (GObjectClass *) klass;
80 entity_class = (AdgEntityClass *) klass;
81 dim_class = (AdgDimClass *) klass;
83 g_type_class_add_private(klass, sizeof(AdgADimPrivate));
85 gobject_class->finalize = finalize;
86 gobject_class->get_property = get_property;
87 gobject_class->set_property = set_property;
89 entity_class->render = render;
91 dim_class->default_quote = default_quote;
93 param = g_param_spec_double("angle1",
94 P_("Angle 1"),
95 P_("Angle of the first reference line"),
96 -G_MAXDOUBLE, G_MAXDOUBLE, 0,
97 G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
98 g_object_class_install_property(gobject_class, PROP_ANGLE1, param);
100 param = g_param_spec_double("angle2",
101 P_("Angle 2"),
102 P_("Angle of the second reference line"),
103 -G_MAXDOUBLE, G_MAXDOUBLE, 0,
104 G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
105 g_object_class_install_property(gobject_class, PROP_ANGLE2, param);
108 static void
109 adg_adim_init(AdgADim *adim)
111 AdgADimPrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(adim, ADG_TYPE_ADIM,
112 AdgADimPrivate);
114 data->extension1.status = CAIRO_STATUS_SUCCESS;
115 data->extension1.data = NULL;
116 data->extension1.num_data = 4;
118 data->extension2.status = CAIRO_STATUS_SUCCESS;
119 data->extension2.data = NULL;
120 data->extension2.num_data = 4;
122 data->arrow_path.status = CAIRO_STATUS_SUCCESS;
123 data->arrow_path.data = NULL;
124 data->arrow_path.num_data = 4;
126 data->baseline.status = CAIRO_STATUS_SUCCESS;
127 data->baseline.data = NULL;
128 data->baseline.num_data = 4;
130 adim->data = data;
133 static void
134 finalize(GObject *object)
136 AdgADimPrivate *data = ((AdgADim *) object)->data;
138 g_free(data->extension1.data);
139 g_free(data->extension2.data);
140 g_free(data->arrow_path.data);
141 g_free(data->baseline.data);
144 static void
145 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
147 AdgADimPrivate *data = ((AdgADim *) object)->data;
149 switch (prop_id) {
150 case PROP_ANGLE1:
151 g_value_set_double(value, data->angle1);
152 break;
153 case PROP_ANGLE2:
154 g_value_set_double(value, data->angle2);
155 break;
156 default:
157 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
158 break;
162 static void
163 set_property(GObject *object, guint prop_id,
164 const GValue *value, GParamSpec *pspec)
166 AdgADim *adim = (AdgADim *) object;
168 switch (prop_id) {
169 case PROP_ANGLE1:
170 set_angle1(adim, g_value_get_double(value));
171 break;
172 case PROP_ANGLE2:
173 set_angle2(adim, g_value_get_double(value));
174 break;
175 default:
176 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
177 break;
181 static gboolean
182 render(AdgEntity *entity, cairo_t *cr)
184 /* TODO */
185 return FALSE;
188 static gchar *
189 default_quote(AdgDim *dim)
191 /* TODO */
192 return g_strdup("TODO");
198 * adg_adim_new:
200 * Creates a new - unreferenced - angular dimension. You must, at least, define
201 * the reference points with adg_dim_set_ref() and the position reference using
202 * adg_dim_set_pos().
204 * Return value: the new entity
206 AdgEntity *
207 adg_adim_new(void)
209 return (AdgEntity *) g_object_new(ADG_TYPE_ADIM, NULL);
213 * adg_adim_get_angle1:
214 * @adim: an #AdgADim
216 * Gets the angle of the first reference line of @adim.
218 * Returns: an angle in radians or %0 on errors
220 gdouble
221 adg_adim_get_angle1(AdgADim *adim)
223 AdgADimPrivate *data;
225 g_return_val_if_fail(ADG_IS_ADIM(adim), 0);
227 data = adim->data;
229 return data->angle1;
233 * adg_adim_set_angle1:
234 * @adim: an #AdgADim
235 * @angle: the new angle (in radians)
237 * Sets the angle of the first reference line of @adim to @angle.
239 void
240 adg_adim_set_angle1(AdgADim *adim, gdouble angle)
242 g_return_if_fail(ADG_IS_ADIM(adim));
244 set_angle1(adim, angle);
246 g_object_notify((GObject *) adim, "angle1");
250 * adg_adim_get_angle2:
251 * @adim: an #AdgADim
253 * Gets the angle of the second reference line of @adim.
255 * Returns: an angle in radians or %0 on errors
257 gdouble
258 adg_adim_get_angle2(AdgADim *adim)
260 AdgADimPrivate *data;
262 g_return_val_if_fail(ADG_IS_ADIM(adim), 0);
264 data = adim->data;
266 return data->angle2;
270 * adg_adim_set_angle2:
271 * @adim: an #AdgADim
272 * @angle: the new angle (in radians)
274 * Sets the angle of the first reference line of @adim to @angle.
276 void
277 adg_adim_set_angle2(AdgADim *adim, gdouble angle)
279 g_return_if_fail(ADG_IS_ADIM(adim));
281 set_angle2(adim, angle);
283 g_object_notify((GObject *) adim, "angle2");
287 static void
288 set_angle1(AdgADim *adim, gdouble angle)
290 AdgADimPrivate *data = adim->data;
292 data->angle1 = angle;
295 static void
296 set_angle2(AdgADim *adim, gdouble angle)
298 AdgADimPrivate *data = adim->data;
300 data->angle2 = angle;