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 void model_matrix_changed (AdgEntity
*entity
,
60 AdgMatrix
*parent_matrix
);
61 static void render (AdgEntity
*entity
,
63 static gchar
* default_quote (AdgDim
*dim
);
64 static void set_angle1 (AdgADim
*adim
,
66 static void set_angle2 (AdgADim
*adim
,
70 G_DEFINE_TYPE(AdgADim
, adg_adim
, ADG_TYPE_DIM
);
74 adg_adim_class_init(AdgADimClass
*klass
)
76 GObjectClass
*gobject_class
;
77 AdgEntityClass
*entity_class
;
78 AdgDimClass
*dim_class
;
81 gobject_class
= (GObjectClass
*) klass
;
82 entity_class
= (AdgEntityClass
*) klass
;
83 dim_class
= (AdgDimClass
*) klass
;
85 g_type_class_add_private(klass
, sizeof(AdgADimPrivate
));
87 gobject_class
->finalize
= finalize
;
88 gobject_class
->get_property
= get_property
;
89 gobject_class
->set_property
= set_property
;
91 entity_class
->model_matrix_changed
= model_matrix_changed
;
92 entity_class
->render
= render
;
94 dim_class
->default_quote
= default_quote
;
96 param
= g_param_spec_double("angle1",
98 P_("Angle of the first reference line"),
99 -G_MAXDOUBLE
, G_MAXDOUBLE
, 0,
100 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
101 g_object_class_install_property(gobject_class
, PROP_ANGLE1
, param
);
103 param
= g_param_spec_double("angle2",
105 P_("Angle of the second reference line"),
106 -G_MAXDOUBLE
, G_MAXDOUBLE
, 0,
107 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
108 g_object_class_install_property(gobject_class
, PROP_ANGLE2
, param
);
112 adg_adim_init(AdgADim
*adim
)
114 AdgADimPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(adim
, ADG_TYPE_ADIM
,
117 data
->extension1
.status
= CAIRO_STATUS_SUCCESS
;
118 data
->extension1
.data
= NULL
;
119 data
->extension1
.num_data
= 4;
121 data
->extension2
.status
= CAIRO_STATUS_SUCCESS
;
122 data
->extension2
.data
= NULL
;
123 data
->extension2
.num_data
= 4;
125 data
->arrow_path
.status
= CAIRO_STATUS_SUCCESS
;
126 data
->arrow_path
.data
= NULL
;
127 data
->arrow_path
.num_data
= 4;
129 data
->baseline
.status
= CAIRO_STATUS_SUCCESS
;
130 data
->baseline
.data
= NULL
;
131 data
->baseline
.num_data
= 4;
137 finalize(GObject
*object
)
139 AdgADimPrivate
*data
= ((AdgADim
*) object
)->data
;
141 g_free(data
->extension1
.data
);
142 g_free(data
->extension2
.data
);
143 g_free(data
->arrow_path
.data
);
144 g_free(data
->baseline
.data
);
148 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
150 AdgADimPrivate
*data
= ((AdgADim
*) object
)->data
;
154 g_value_set_double(value
, data
->angle1
);
157 g_value_set_double(value
, data
->angle2
);
160 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
166 set_property(GObject
*object
, guint prop_id
,
167 const GValue
*value
, GParamSpec
*pspec
)
169 AdgADim
*adim
= (AdgADim
*) object
;
173 set_angle1(adim
, g_value_get_double(value
));
176 set_angle2(adim
, g_value_get_double(value
));
179 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
185 model_matrix_changed(AdgEntity
*entity
, AdgMatrix
*parent_matrix
)
187 AdgEntityClass
*entity_class
= (AdgEntityClass
*) adg_adim_parent_class
;
191 if (entity_class
->model_matrix_changed
!= NULL
)
192 entity_class
->model_matrix_changed(entity
, parent_matrix
);
196 render(AdgEntity
*entity
, cairo_t
*cr
)
202 default_quote(AdgDim
*dim
)
205 return g_strdup("TODO");
213 * Creates a new - unreferenced - angular dimension. You must, at least, define
214 * the reference points with adg_dim_set_ref() and the position reference using
217 * Return value: the new entity
222 return (AdgEntity
*) g_object_new(ADG_TYPE_ADIM
, NULL
);
226 * adg_adim_get_angle1:
229 * Gets the angle of the first reference line of @adim.
231 * Returns: an angle in radians or %0 on errors
234 adg_adim_get_angle1(AdgADim
*adim
)
236 AdgADimPrivate
*data
;
238 g_return_val_if_fail(ADG_IS_ADIM(adim
), 0);
246 * adg_adim_set_angle1:
248 * @angle: the new angle (in radians)
250 * Sets the angle of the first reference line of @adim to @angle.
253 adg_adim_set_angle1(AdgADim
*adim
, gdouble angle
)
255 g_return_if_fail(ADG_IS_ADIM(adim
));
257 set_angle1(adim
, angle
);
259 g_object_notify((GObject
*) adim
, "angle1");
263 * adg_adim_get_angle2:
266 * Gets the angle of the second reference line of @adim.
268 * Returns: an angle in radians or %0 on errors
271 adg_adim_get_angle2(AdgADim
*adim
)
273 AdgADimPrivate
*data
;
275 g_return_val_if_fail(ADG_IS_ADIM(adim
), 0);
283 * adg_adim_set_angle2:
285 * @angle: the new angle (in radians)
287 * Sets the angle of the first reference line of @adim to @angle.
290 adg_adim_set_angle2(AdgADim
*adim
, gdouble angle
)
292 g_return_if_fail(ADG_IS_ADIM(adim
));
294 set_angle2(adim
, angle
);
296 g_object_notify((GObject
*) adim
, "angle2");
301 set_angle1(AdgADim
*adim
, gdouble angle
)
303 AdgADimPrivate
*data
= adim
->data
;
305 data
->angle1
= angle
;
309 set_angle2(AdgADim
*adim
, gdouble angle
)
311 AdgADimPrivate
*data
= adim
->data
;
313 data
->angle2
= angle
;