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.
23 * @short_description: Angular dimensions
25 * The #AdgADim entity represents an angular dimension.
31 * All fields are privates and should not be used directly.
32 * Use its public methods instead.
37 #include "adg-adim-private.h"
38 #include "adg-container.h"
49 static void finalize (GObject
*object
);
50 static void get_property (GObject
*object
,
54 static void set_property (GObject
*object
,
58 static gboolean
render (AdgEntity
*entity
,
60 static gchar
* default_value (AdgDim
*dim
);
61 static void set_angle1 (AdgADim
*adim
,
63 static void set_angle2 (AdgADim
*adim
,
67 G_DEFINE_TYPE(AdgADim
, adg_adim
, ADG_TYPE_DIM
);
71 adg_adim_class_init(AdgADimClass
*klass
)
73 GObjectClass
*gobject_class
;
74 AdgEntityClass
*entity_class
;
75 AdgDimClass
*dim_class
;
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",
94 P_("Angle of the first reference line"),
95 -G_MAXDOUBLE
, G_MAXDOUBLE
, 0,
97 g_object_class_install_property(gobject_class
, PROP_ANGLE1
, param
);
99 param
= g_param_spec_double("angle2",
101 P_("Angle of the second reference line"),
102 -G_MAXDOUBLE
, G_MAXDOUBLE
, 0,
104 g_object_class_install_property(gobject_class
, PROP_ANGLE2
, param
);
108 adg_adim_init(AdgADim
*adim
)
110 AdgADimPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(adim
, ADG_TYPE_ADIM
,
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;
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
);
144 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
146 AdgADimPrivate
*data
= ((AdgADim
*) object
)->data
;
150 g_value_set_double(value
, data
->angle1
);
153 g_value_set_double(value
, data
->angle2
);
156 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
162 set_property(GObject
*object
, guint prop_id
,
163 const GValue
*value
, GParamSpec
*pspec
)
165 AdgADim
*adim
= (AdgADim
*) object
;
169 set_angle1(adim
, g_value_get_double(value
));
172 set_angle2(adim
, g_value_get_double(value
));
175 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
181 render(AdgEntity
*entity
, cairo_t
*cr
)
188 default_value(AdgDim
*dim
)
191 return g_strdup("TODO");
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
203 * Returns: the newly created angular dimension entity
208 return g_object_new(ADG_TYPE_ADIM
, NULL
);
212 * adg_adim_get_angle1:
215 * Gets the angle of the first reference line of @adim.
217 * Returns: an angle in radians or %0 on errors
220 adg_adim_get_angle1(AdgADim
*adim
)
222 AdgADimPrivate
*data
;
224 g_return_val_if_fail(ADG_IS_ADIM(adim
), 0);
232 * adg_adim_set_angle1:
234 * @angle: the new angle (in radians)
236 * Sets the angle of the first reference line of @adim to @angle.
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:
252 * Gets the angle of the second reference line of @adim.
254 * Returns: an angle in radians or %0 on errors
257 adg_adim_get_angle2(AdgADim
*adim
)
259 AdgADimPrivate
*data
;
261 g_return_val_if_fail(ADG_IS_ADIM(adim
), 0);
269 * adg_adim_set_angle2:
271 * @angle: the new angle (in radians)
273 * Sets the angle of the first reference line of @adim to @angle.
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");
287 set_angle1(AdgADim
*adim
, gdouble angle
)
289 AdgADimPrivate
*data
= adim
->data
;
291 data
->angle1
= angle
;
295 set_angle2(AdgADim
*adim
, gdouble angle
)
297 AdgADimPrivate
*data
= adim
->data
;
299 data
->angle2
= angle
;