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"
50 static void finalize (GObject
*object
);
51 static void get_property (GObject
*object
,
55 static void set_property (GObject
*object
,
59 static gboolean
render (AdgEntity
*entity
,
61 static gchar
* default_quote (AdgDim
*dim
);
62 static void set_angle1 (AdgADim
*adim
,
64 static void set_angle2 (AdgADim
*adim
,
68 G_DEFINE_TYPE(AdgADim
, adg_adim
, ADG_TYPE_DIM
);
72 adg_adim_class_init(AdgADimClass
*klass
)
74 GObjectClass
*gobject_class
;
75 AdgEntityClass
*entity_class
;
76 AdgDimClass
*dim_class
;
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",
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",
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
);
109 adg_adim_init(AdgADim
*adim
)
111 AdgADimPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(adim
, ADG_TYPE_ADIM
,
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;
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
);
145 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
147 AdgADimPrivate
*data
= ((AdgADim
*) object
)->data
;
151 g_value_set_double(value
, data
->angle1
);
154 g_value_set_double(value
, data
->angle2
);
157 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
163 set_property(GObject
*object
, guint prop_id
,
164 const GValue
*value
, GParamSpec
*pspec
)
166 AdgADim
*adim
= (AdgADim
*) object
;
170 set_angle1(adim
, g_value_get_double(value
));
173 set_angle2(adim
, g_value_get_double(value
));
176 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
182 render(AdgEntity
*entity
, cairo_t
*cr
)
189 default_quote(AdgDim
*dim
)
192 return g_strdup("TODO");
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
204 * Return value: the new entity
209 return (AdgEntity
*) g_object_new(ADG_TYPE_ADIM
, NULL
);
213 * adg_adim_get_angle1:
216 * Gets the angle of the first reference line of @adim.
218 * Returns: an angle in radians or %0 on errors
221 adg_adim_get_angle1(AdgADim
*adim
)
223 AdgADimPrivate
*data
;
225 g_return_val_if_fail(ADG_IS_ADIM(adim
), 0);
233 * adg_adim_set_angle1:
235 * @angle: the new angle (in radians)
237 * Sets the angle of the first reference line of @adim to @angle.
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:
253 * Gets the angle of the second reference line of @adim.
255 * Returns: an angle in radians or %0 on errors
258 adg_adim_get_angle2(AdgADim
*adim
)
260 AdgADimPrivate
*data
;
262 g_return_val_if_fail(ADG_IS_ADIM(adim
), 0);
270 * adg_adim_set_angle2:
272 * @angle: the new angle (in radians)
274 * Sets the angle of the first reference line of @adim to @angle.
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");
288 set_angle1(AdgADim
*adim
, gdouble angle
)
290 AdgADimPrivate
*data
= adim
->data
;
292 data
->angle1
= angle
;
296 set_angle2(AdgADim
*adim
, gdouble angle
)
298 AdgADimPrivate
*data
= adim
->data
;
300 data
->angle2
= angle
;