[AdgDim] Changed "ref1", "ref2" and "pos" to AdgPoint
[adg.git] / adg / adg-dim.c
blob4ad1ec35316bb57d452a8e682885b341d3592bf2
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-dim
23 * @short_description: Root abstract class for all dimension entities
25 * The #AdgDim class is the base stub of all the dimension entities.
26 **/
28 /**
29 * AdgDim:
31 * All fields are private and should not be used directly.
32 * Use its public methods instead.
33 **/
36 #include "adg-dim.h"
37 #include "adg-dim-private.h"
38 #include "adg-dim-style.h"
39 #include "adg-dress-builtins.h"
40 #include "adg-toy-text.h"
41 #include "adg-type-builtins.h"
42 #include "adg-intl.h"
44 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_dim_parent_class)
45 #define PARENT_ENTITY_CLASS ((AdgEntityClass *) adg_dim_parent_class)
48 enum {
49 PROP_0,
50 PROP_DIM_DRESS,
51 PROP_REF1,
52 PROP_REF2,
53 PROP_POS,
54 PROP_LEVEL,
55 PROP_OUTSIDE,
56 PROP_VALUE,
57 PROP_MIN,
58 PROP_MAX
62 static void dispose (GObject *object);
63 static void finalize (GObject *object);
64 static void get_property (GObject *object,
65 guint param_id,
66 GValue *value,
67 GParamSpec *pspec);
68 static void set_property (GObject *object,
69 guint param_id,
70 const GValue *value,
71 GParamSpec *pspec);
72 static void global_changed (AdgEntity *entity);
73 static void local_changed (AdgEntity *entity);
74 static void invalidate (AdgEntity *entity);
75 static void arrange (AdgEntity *entity);
76 static gchar * default_value (AdgDim *dim);
77 static gdouble quote_angle (gdouble angle);
78 static gboolean set_dim_dress (AdgDim *dim,
79 AdgDress dress);
80 static gboolean set_value (AdgDim *dim,
81 const gchar *value);
82 static gboolean set_min (AdgDim *dim,
83 const gchar *min);
84 static gboolean set_max (AdgDim *dim,
85 const gchar *max);
88 G_DEFINE_ABSTRACT_TYPE(AdgDim, adg_dim, ADG_TYPE_ENTITY);
91 static void
92 adg_dim_class_init(AdgDimClass *klass)
94 GObjectClass *gobject_class;
95 AdgEntityClass *entity_class;
96 GParamSpec *param;
98 gobject_class = (GObjectClass *) klass;
99 entity_class = (AdgEntityClass *) klass;
101 g_type_class_add_private(klass, sizeof(AdgDimPrivate));
103 gobject_class->dispose = dispose;
104 gobject_class->finalize = finalize;
105 gobject_class->get_property = get_property;
106 gobject_class->set_property = set_property;
108 entity_class->global_changed = global_changed;
109 entity_class->local_changed = local_changed;
110 entity_class->invalidate = invalidate;
111 entity_class->arrange = arrange;
113 klass->quote_angle = quote_angle;
114 klass->default_value = default_value;
116 param = adg_param_spec_dress("dim-dress",
117 P_("Dress Style"),
118 P_("The dress to use for rendering this dimension"),
119 ADG_DRESS_DIMENSION,
120 G_PARAM_READWRITE);
121 g_object_class_install_property(gobject_class, PROP_DIM_DRESS, param);
123 param = g_param_spec_boxed("ref1",
124 P_("Reference 1"),
125 P_("First reference point of the dimension"),
126 ADG_TYPE_POINT,
127 G_PARAM_READWRITE);
128 g_object_class_install_property(gobject_class, PROP_REF1, param);
130 param = g_param_spec_boxed("ref2",
131 P_("Reference 2"),
132 P_("Second reference point of the dimension"),
133 ADG_TYPE_POINT,
134 G_PARAM_READWRITE);
135 g_object_class_install_property(gobject_class, PROP_REF2, param);
137 param = g_param_spec_boxed("pos",
138 P_("Position"),
139 P_("The reference position in local space of the quote: it will be combined with \"level\" to get the real quote position"),
140 ADG_TYPE_POINT,
141 G_PARAM_READWRITE);
142 g_object_class_install_property(gobject_class, PROP_POS, param);
144 param = g_param_spec_double("level",
145 P_("Level"),
146 P_("The dimension level, that is the factor to multiply the baseline spacing (defined in the dimension style) to get the offset from pos where the quote should be rendered"),
147 -G_MAXDOUBLE, G_MAXDOUBLE, 1.0,
148 G_PARAM_READWRITE);
149 g_object_class_install_property(gobject_class, PROP_LEVEL, param);
151 param = g_param_spec_enum("outside",
152 P_("Outside"),
153 P_("Whether the arrows must be inside the extension lines (ADG_THREE_STATE_OFF), must be extended outside the extension lines (ADG_THREE_STATE_ON) or should be automatically handled depending on the available space"),
154 ADG_TYPE_THREE_STATE, ADG_THREE_STATE_UNKNOWN,
155 G_PARAM_READWRITE);
156 g_object_class_install_property(gobject_class, PROP_OUTSIDE, param);
158 param = g_param_spec_string("value",
159 P_("Basic Value"),
160 P_("The theoretically exact value for this quote: set to NULL to automatically get the default value"),
161 NULL,
162 G_PARAM_READWRITE);
163 g_object_class_install_property(gobject_class, PROP_VALUE, param);
165 param = g_param_spec_string("value-min",
166 P_("Minimum Value or Low Tolerance"),
167 P_("The minimum value allowed or the lowest tolerance from value (depending of the dimension style): set to NULL to suppress"),
168 NULL,
169 G_PARAM_READWRITE);
170 g_object_class_install_property(gobject_class, PROP_MIN, param);
172 param = g_param_spec_string("value-max",
173 P_("Maximum Value or High Tolerance"),
174 P_("The maximum value allowed or the highest tolerance from value (depending of the dimension style): set to NULL to suppress"),
175 NULL,
176 G_PARAM_READWRITE);
177 g_object_class_install_property(gobject_class, PROP_MAX, param);
180 static void
181 adg_dim_init(AdgDim *dim)
183 AdgDimPrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(dim, ADG_TYPE_DIM,
184 AdgDimPrivate);
186 data->dim_dress = ADG_DRESS_DIMENSION;
187 data->ref1 = NULL;
188 data->ref2 = NULL;
189 data->pos = NULL;
190 data->level = 1;
191 data->outside = ADG_THREE_STATE_UNKNOWN;
192 data->value = NULL;
193 data->min = NULL;
194 data->max = NULL;
196 dim->data = data;
199 static void
200 dispose(GObject *object)
202 AdgDimPrivate *data = ((AdgDim *) object)->data;
204 if (data->quote.container != NULL) {
205 g_object_unref(data->quote.container);
206 data->quote.container = NULL;
208 if (data->ref1 != NULL) {
209 adg_point_destroy(data->ref1);
210 data->ref1 = NULL;
212 if (data->ref2 != NULL) {
213 adg_point_destroy(data->ref2);
214 data->ref2 = NULL;
216 if (data->pos != NULL) {
217 adg_point_destroy(data->pos);
218 data->pos = NULL;
221 if (PARENT_OBJECT_CLASS->dispose != NULL)
222 PARENT_OBJECT_CLASS->dispose(object);
225 static void
226 finalize(GObject *object)
228 AdgDimPrivate *data = ((AdgDim *) object)->data;
230 g_free(data->value);
231 g_free(data->min);
232 g_free(data->max);
234 if (PARENT_OBJECT_CLASS->finalize != NULL)
235 PARENT_OBJECT_CLASS->finalize(object);
238 static void
239 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
241 AdgDimPrivate *data = ((AdgDim *) object)->data;
243 switch (prop_id) {
244 case PROP_DIM_DRESS:
245 g_value_set_int(value, data->dim_dress);
246 break;
247 case PROP_REF1:
248 g_value_set_boxed(value, data->ref1);
249 break;
250 case PROP_REF2:
251 g_value_set_boxed(value, data->ref2);
252 break;
253 case PROP_POS:
254 g_value_set_boxed(value, data->pos);
255 break;
256 case PROP_LEVEL:
257 g_value_set_double(value, data->level);
258 break;
259 case PROP_OUTSIDE:
260 g_value_set_enum(value, data->outside);
261 break;
262 case PROP_VALUE:
263 g_value_set_string(value, data->value);
264 break;
265 case PROP_MIN:
266 g_value_set_string(value, data->min);
267 break;
268 case PROP_MAX:
269 g_value_set_string(value, data->max);
270 break;
271 default:
272 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
273 break;
277 static void
278 set_property(GObject *object, guint prop_id,
279 const GValue *value, GParamSpec *pspec)
281 AdgDim *dim;
282 AdgDimPrivate *data;
284 dim = (AdgDim *) object;
285 data = dim->data;
287 switch (prop_id) {
288 case PROP_DIM_DRESS:
289 set_dim_dress(dim, g_value_get_int(value));
290 break;
291 case PROP_REF1:
292 if (data->ref1 != NULL)
293 adg_point_destroy(data->ref1);
294 data->ref1 = g_value_dup_boxed(value);
295 break;
296 case PROP_REF2:
297 if (data->ref2 != NULL)
298 adg_point_destroy(data->ref2);
299 data->ref2 = g_value_dup_boxed(value);
300 break;
301 case PROP_POS:
302 if (data->pos != NULL)
303 adg_point_destroy(data->pos);
304 data->pos = g_value_dup_boxed(value);
305 break;
306 case PROP_LEVEL:
307 data->level = g_value_get_double(value);
308 break;
309 case PROP_OUTSIDE:
310 data->outside = g_value_get_enum(value);
311 break;
312 case PROP_VALUE:
313 set_value(dim, g_value_get_string(value));
314 break;
315 case PROP_MIN:
316 set_min(dim, g_value_get_string(value));
317 break;
318 case PROP_MAX:
319 set_max(dim, g_value_get_string(value));
320 break;
321 default:
322 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
323 break;
329 * adg_dim_get_dim_dress:
330 * @dim: an #AdgDim
332 * Gets the dimension dress to be used in rendering @dim.
334 * Returns: the current dimension dress
336 AdgDress
337 adg_dim_get_dim_dress(AdgDim *dim)
339 AdgDimPrivate *data;
341 g_return_val_if_fail(ADG_IS_DIM(dim), ADG_DRESS_UNDEFINED);
343 data = dim->data;
345 return data->dim_dress;
349 * adg_dim_set_dim_dress:
350 * @dim: an #AdgDim
351 * @dress: the new #AdgDress to use
353 * Sets a new dimension dress to @dim. The new dress must be
354 * related to the original dress for this property: you cannot
355 * set a dress used for line styles to a dress managing fonts.
357 * The check is done by calling adg_dress_are_related() with
358 * @dress and the previous dress as arguments. Check out its
359 * documentation for details on what is a related dress.
361 void
362 adg_dim_set_dim_dress(AdgDim *dim, AdgDress dress)
364 g_return_if_fail(ADG_IS_DIM(dim));
366 if (set_dim_dress(dim, dress))
367 g_object_notify((GObject *) dim, "dim-dress");
371 * adg_dim_get_ref1:
372 * @dim: an #AdgDim
374 * Gets the ref1 coordinates. The returned pair is internally owned
375 * and must not be freed or modified.
377 * Returns: the ref1 coordinates
379 const AdgPair *
380 adg_dim_get_ref1(AdgDim *dim)
382 AdgDimPrivate *data;
384 g_return_val_if_fail(ADG_IS_DIM(dim), NULL);
386 data = dim->data;
388 return ADG_POINT_PAIR(data->ref1);
392 * adg_dim_get_ref2:
393 * @dim: an #AdgDim
395 * Gets the ref2 coordinates. The returned pair is internally owned
396 * and must not be freed or modified.
398 * Returns: the ref2 coordinates
400 const AdgPair *
401 adg_dim_get_ref2(AdgDim *dim)
403 AdgDimPrivate *data;
405 g_return_val_if_fail(ADG_IS_DIM(dim), NULL);
407 data = dim->data;
409 return ADG_POINT_PAIR(data->ref2);
413 * adg_dim_set_ref:
414 * @dim: an #AdgDim
415 * @ref1: the ref1 coordinates
416 * @ref2: the ref2 coordinates
418 * Shortcut to set ref1 and ref2 points at once.
420 void
421 adg_dim_set_ref(AdgDim *dim, const AdgPair *ref1, const AdgPair *ref2)
423 g_return_if_fail(ADG_IS_DIM(dim));
425 if (ref1 != NULL || ref2 != NULL) {
426 GObject *object;
427 AdgDimPrivate *data;
429 data = dim->data;
430 object = (GObject *) dim;
432 g_object_freeze_notify(object);
434 if (ref1 != NULL) {
435 if (data->ref1 == NULL)
436 data->ref1 = adg_point_new();
438 adg_point_set(data->ref1, ref1);
440 g_object_notify(object, "ref1");
443 if (ref2 != NULL) {
444 if (data->ref2 == NULL)
445 data->ref2 = adg_point_new();
447 adg_point_set(data->ref2, ref2);
449 g_object_notify(object, "ref2");
452 g_object_thaw_notify(object);
457 * adg_dim_set_ref_explicit:
458 * @dim: an #AdgDim
459 * @ref1_x: x coordinate of ref1
460 * @ref1_y: y coordinate of ref1
461 * @ref2_x: x coordinate of ref2
462 * @ref2_y: y coordinate of ref2
464 * Shortcut to set ref1 and ref2 points at once,
465 * using explicit coordinates.
467 void
468 adg_dim_set_ref_explicit(AdgDim *dim,
469 gdouble ref1_x, gdouble ref1_y,
470 gdouble ref2_x, gdouble ref2_y)
472 AdgPair ref1;
473 AdgPair ref2;
475 ref1.x = ref1_x;
476 ref1.y = ref1_y;
477 ref2.x = ref2_x;
478 ref2.y = ref2_y;
480 adg_dim_set_ref(dim, &ref1, &ref2);
484 * adg_dim_get_pos:
485 * @dim: an #AdgDim
487 * Gets the position coordinates. The returned pair is internally owned
488 * and must not be freed or modified.
490 * Returns: the pos coordinates
492 const AdgPair *
493 adg_dim_get_pos(AdgDim *dim)
495 AdgDimPrivate *data;
497 g_return_val_if_fail(ADG_IS_DIM(dim), NULL);
499 data = dim->data;
501 return ADG_POINT_PAIR(data->pos);
505 * adg_dim_set_pos:
506 * @dim: an #AdgDim
507 * @pos: the pos coordinates
509 * Sets a new #AdgDim:pos position.
511 void
512 adg_dim_set_pos(AdgDim *dim, const AdgPair *pos)
514 AdgDimPrivate *data;
516 g_return_if_fail(ADG_IS_DIM(dim));
517 g_return_if_fail(pos != NULL);
519 data = dim->data;
521 if (data->pos == NULL)
522 data->pos = adg_point_new();
524 adg_point_set(data->pos, pos);
526 g_object_notify((GObject *) dim, "pos");
530 * adg_dim_set_pos_explicit:
531 * @dim: an #AdgDim
532 * @pos_x: x coordinate of pos
533 * @pos_y: y coordinate of pos
535 * Shortcut to set #AdgDim:pos using explicit coordinates.
537 void
538 adg_dim_set_pos_explicit(AdgDim *dim, gdouble x, gdouble y)
540 AdgPair pos;
542 pos.x = x;
543 pos.y = y;
545 adg_dim_set_pos(dim, &pos);
549 * adg_dim_get_level:
550 * @dim: an #AdgDim
552 * Gets the level of this dimension.
554 * Returns: the level value
556 gdouble
557 adg_dim_get_level(AdgDim *dim)
559 AdgDimPrivate *data;
561 g_return_val_if_fail(ADG_IS_DIM(dim), 0);
563 data = dim->data;
565 return data->level;
569 * adg_dim_set_level:
570 * @dim: an #AdgDim
571 * @level: the new level
573 * Sets a new level for this dimension. The level is used to
574 * stack the quotes using a spacing value from dim_style
575 * (specified in global space).
577 void
578 adg_dim_set_level(AdgDim *dim, gdouble level)
580 AdgDimPrivate *data;
582 g_return_if_fail(ADG_IS_DIM(dim));
584 data = dim->data;
585 data->level = level;
587 g_object_notify((GObject *) dim, "level");
591 * adg_dim_get_outside:
592 * @dim: an #AdgDim
594 * Gets the state of the #AdgDim:outside property: check the property
595 * documentation for further details.
597 * Returns: the current flag state
599 AdgThreeState
600 adg_dim_get_outside(AdgDim *dim)
602 AdgDimPrivate *data;
604 g_return_val_if_fail(ADG_IS_DIM(dim), ADG_THREE_STATE_UNKNOWN);
606 data = dim->data;
608 return data->outside;
612 * adg_dim_set_outside:
613 * @dim: an #AdgDim
614 * @outside: the new outside state
616 * Sets a new state for the #AdgDim:outside flag: check the property
617 * documentation for further details.
619 void
620 adg_dim_set_outside(AdgDim *dim, AdgThreeState outside)
622 AdgDimPrivate *data;
624 g_return_if_fail(ADG_IS_DIM(dim));
626 data = dim->data;
627 data->outside = outside;
629 g_object_notify((GObject *) dim, "outside");
633 * adg_dim_get_value:
634 * @dim: an #AdgDim
636 * Gets the value text. The string is internally owned and
637 * must not be freed or modified.
639 * Returns: the value text
641 const gchar *
642 adg_dim_get_value(AdgDim *dim)
644 AdgDimPrivate *data;
646 g_return_val_if_fail(ADG_IS_DIM(dim), NULL);
648 data = dim->data;
650 return data->value;
654 * adg_dim_set_value:
655 * @dim: an #AdgDim
656 * @value: the value text
658 * Explicitely sets the text to use as value. If @value is %NULL or
659 * was never set, an automatic text is calculated using the format
660 * specified in the current #AdgDimStyle and getting its value by
661 * calling the default_value() virtual method.
663 void
664 adg_dim_set_value(AdgDim *dim, const gchar *value)
666 g_return_if_fail(ADG_IS_DIM(dim));
668 if (set_value(dim, value))
669 g_object_notify((GObject *) dim, "value");
673 * adg_dim_get_min:
674 * @dim: an #AdgDim
676 * Gets the minimum value text or %NULL on minimum value disabled.
677 * The string is internally owned and must not be freed or modified.
679 * Returns: the mimimum value text
681 const gchar *
682 adg_dim_get_min(AdgDim *dim)
684 AdgDimPrivate *data;
686 g_return_val_if_fail(ADG_IS_DIM(dim), NULL);
688 data = dim->data;
690 return data->min;
694 * adg_dim_set_min:
695 * @dim: an #AdgDim
696 * @min: the new minimum limit
698 * Sets the minimum value. Use %NULL as @min to disable it.
700 void
701 adg_dim_set_min(AdgDim *dim, const gchar *min)
703 g_return_if_fail(ADG_IS_DIM(dim));
705 if (set_min(dim, min))
706 g_object_notify((GObject *) dim, "value-min");
710 * adg_dim_get_max:
711 * @dim: an #AdgDim
713 * Gets the maximum value text or %NULL on maximum value disabled.
714 * The string is internally owned and must not be freed or modified.
716 * Returns: the maximum value text
718 const gchar *
719 adg_dim_get_max(AdgDim *dim)
721 AdgDimPrivate *data;
723 g_return_val_if_fail(ADG_IS_DIM(dim), NULL);
725 data = dim->data;
727 return data->max;
731 * adg_dim_set_max:
732 * @dim: an #AdgDim
733 * @max: the new maximum value
735 * Sets the maximum value. Use %NULL as @max to disable it.
737 void
738 adg_dim_set_max(AdgDim *dim, const gchar *max)
740 g_return_if_fail(ADG_IS_DIM(dim));
742 if (set_max(dim, max))
743 g_object_notify((GObject *) dim, "value-max");
747 * adg_dim_set_limits:
748 * @dim: an #AdgDim
749 * @min: the new minumum value
750 * @max: the new maximum value
752 * Shortcut to set both the limits at once.
754 void
755 adg_dim_set_limits(AdgDim *dim, const gchar *min, const gchar *max)
757 g_return_if_fail(ADG_IS_DIM(dim));
759 g_object_freeze_notify((GObject *) dim);
760 adg_dim_set_min(dim, min);
761 adg_dim_set_max(dim, max);
762 g_object_thaw_notify((GObject *) dim);
766 * adg_dim_get_quote:
767 * @dim: an #AdgDim
769 * <note><para>
770 * This function is only useful in new dimension implementations.
771 * </para></note>
773 * Gets the quote container, if any. This function is valid only
774 * after the #AdgDim implementation of the arrange() virtual method
775 * has been called.
777 * Returns: the quote container
779 AdgContainer *
780 adg_dim_get_quote(AdgDim *dim)
782 AdgDimPrivate *data;
784 g_return_val_if_fail(ADG_IS_DIM(dim), NULL);
786 data = dim->data;
788 return data->quote.container;
792 * adg_dim_quote_angle:
793 * @dim: an #AdgDim
794 * @angle: an angle (in radians)
796 * <note><para>
797 * This function is only useful in new dimension implementations.
798 * </para></note>
800 * Converts @angle accordling to the style of @dim. Any quote angle
801 * should be validated by this method because every dimensioning
802 * style has its own convention regardling the text rotation.
804 * Returns: the angle to use (always in radians)
806 gdouble
807 adg_dim_quote_angle(AdgDim *dim, gdouble angle)
809 AdgDimClass *klass;
811 g_return_val_if_fail(ADG_IS_DIM(dim), angle);
813 klass = ADG_DIM_GET_CLASS(dim);
815 if (klass->quote_angle == NULL)
816 return angle;
818 return klass->quote_angle(angle);
822 * _adg_dim_get_dim_style:
823 * @dim: an #AdgDim entity
825 * Gets the #AdgDimStyle associated to @dim. The dress to style
826 * resolution is done in the arrange() method so this value is
827 * typically available in render() or in a derived arrange()
828 * method, after the #AdgDim arrange() function has been chained up.
830 * Returns: the dim style of @entity
832 AdgDimStyle *
833 _adg_dim_get_dim_style(AdgDim *dim)
835 AdgDimPrivate *data;
837 g_return_val_if_fail(ADG_IS_DIM(dim), NULL);
839 data = dim->data;
841 return data->dim_style;
845 static void
846 arrange(AdgEntity *entity)
848 AdgDim *dim;
849 AdgDimPrivate *data;
850 AdgEntity *container_entity;
851 AdgEntity *value_entity;
852 AdgEntity *min_entity;
853 AdgEntity *max_entity;
854 CpmlExtents extents;
855 AdgMatrix map;
856 const AdgPair *shift;
858 dim = (AdgDim *) entity;
859 data = dim->data;
861 /* Resolve the dim style */
862 if (data->dim_style == NULL)
863 data->dim_style = (AdgDimStyle *) adg_entity_style(entity,
864 data->dim_dress);
866 if (data->quote.container == NULL)
867 data->quote.container = g_object_new(ADG_TYPE_CONTAINER,
868 "parent", dim, NULL);
870 if (data->quote.value == NULL) {
871 AdgDress dress = adg_dim_style_get_value_dress(data->dim_style);
873 data->quote.value = g_object_new(ADG_TYPE_TOY_TEXT,
874 "font-dress", dress, NULL);
876 adg_container_add(data->quote.container,
877 (AdgEntity *) data->quote.value);
879 if (data->value == NULL) {
880 /* Automatically generate the value text */
881 gchar *text = ADG_DIM_GET_CLASS(dim)->default_value(dim);
882 adg_toy_text_set_label(data->quote.value, text);
883 g_free(text);
884 } else {
885 adg_toy_text_set_label(data->quote.value, data->value);
889 if (data->quote.min == NULL && data->min != NULL) {
890 AdgDress dress = adg_dim_style_get_min_dress(data->dim_style);
892 data->quote.min = g_object_new(ADG_TYPE_TOY_TEXT,
893 "font-dress", dress, NULL);
895 adg_container_add(data->quote.container, (AdgEntity *) data->quote.min);
896 adg_toy_text_set_label(data->quote.min, data->min);
899 if (data->quote.max == NULL && data->max != NULL) {
900 AdgDress dress = adg_dim_style_get_max_dress(data->dim_style);
902 data->quote.max = g_object_new(ADG_TYPE_TOY_TEXT,
903 "font-dress", dress, NULL);
905 adg_container_add(data->quote.container, (AdgEntity *) data->quote.max);
906 adg_toy_text_set_label(data->quote.max, data->max);
909 container_entity = (AdgEntity *) data->quote.container;
910 value_entity = (AdgEntity *) data->quote.value;
911 min_entity = (AdgEntity *) data->quote.min;
912 max_entity = (AdgEntity *) data->quote.max;
914 /* Propagate the arrange signal to the quote container */
915 adg_entity_arrange(container_entity);
917 /* Basic value */
918 adg_entity_get_extents(value_entity, &extents);
920 /* Limit values (min and max) */
921 if (min_entity != NULL || max_entity != NULL) {
922 CpmlExtents min_extents = { 0 };
923 CpmlExtents max_extents = { 0 };
924 gdouble spacing = 0;
926 /* Minimum limit */
927 if (min_entity != NULL)
928 adg_entity_get_extents(min_entity, &min_extents);
930 /* Maximum limit */
931 if (max_entity != NULL)
932 adg_entity_get_extents(max_entity, &max_extents);
934 shift = adg_dim_style_get_limits_shift(data->dim_style);
935 if (min_entity != NULL && max_entity != NULL)
936 spacing = adg_dim_style_get_limits_spacing(data->dim_style);
938 cairo_matrix_init_translate(&map, extents.size.x + shift->x,
939 (spacing + min_extents.size.y +
940 max_extents.size.y) / 2 +
941 shift->y - extents.size.y / 2);
943 if (min_entity != NULL)
944 adg_entity_set_global_map(min_entity, &map);
946 if (max_entity != NULL) {
947 cairo_matrix_translate(&map, 0, -min_extents.size.y - spacing);
948 adg_entity_set_global_map(max_entity, &map);
951 extents.size.x += shift->x + MAX(min_extents.size.x, max_extents.size.x);
954 /* Center and apply the style displacements */
955 shift = adg_dim_style_get_quote_shift(data->dim_style);
956 cairo_matrix_init_translate(&map, shift->x - extents.size.x / 2, shift->y);
957 adg_entity_set_global_map(container_entity, &map);
959 adg_entity_arrange(container_entity);
962 static void
963 global_changed(AdgEntity *entity)
965 AdgDimPrivate *data = ((AdgDim *) entity)->data;
967 PARENT_ENTITY_CLASS->global_changed(entity);
969 if (data->quote.container != NULL)
970 adg_entity_global_changed((AdgEntity *) data->quote.container);
973 static void
974 local_changed(AdgEntity *entity)
976 AdgDimPrivate *data = ((AdgDim *) entity)->data;
978 PARENT_ENTITY_CLASS->local_changed(entity);
980 if (data->quote.container != NULL)
981 adg_entity_local_changed((AdgEntity *) data->quote.container);
984 static void
985 invalidate(AdgEntity *entity)
987 AdgDimPrivate *data = ((AdgDim *) entity)->data;
989 if (data->quote.container != NULL)
990 adg_entity_invalidate((AdgEntity *) data->quote.container);
993 static gchar *
994 default_value(AdgDim *dim)
996 g_warning("AdgDim::default_value not implemented for `%s'",
997 g_type_name(G_TYPE_FROM_INSTANCE(dim)));
998 return g_strdup("undef");
1001 static gdouble
1002 quote_angle(gdouble angle)
1004 angle = cpml_angle(angle);
1006 if (angle > G_PI_4 * 4 / 3 || angle <= -G_PI_4 * 3)
1007 angle = cpml_angle(angle + G_PI);
1009 return angle;
1012 static gboolean
1013 set_dim_dress(AdgDim *dim, AdgDress dress)
1015 AdgDimPrivate *data = dim->data;
1017 if (adg_dress_set(&data->dim_dress, dress)) {
1018 data->dim_style = NULL;
1019 return TRUE;
1022 return FALSE;
1025 static gboolean
1026 set_value(AdgDim *dim, const gchar *value)
1028 AdgDimPrivate *data;
1030 data = dim->data;
1032 if (adg_strcmp(value, data->value) == 0)
1033 return FALSE;
1035 g_free(data->value);
1036 data->value = g_strdup(value);
1038 if (data->quote.value != NULL) {
1039 g_object_unref(data->quote.value);
1040 data->quote.value = NULL;
1043 return TRUE;
1046 static gboolean
1047 set_min(AdgDim *dim, const gchar *min)
1049 AdgDimPrivate *data = dim->data;
1051 if (adg_strcmp(min, data->min) == 0)
1052 return FALSE;
1054 g_free(data->min);
1055 data->min = g_strdup(min);
1057 if (data->quote.min != NULL) {
1058 g_object_unref(data->quote.min);
1059 data->quote.min = NULL;
1062 return TRUE;
1065 static gboolean
1066 set_max(AdgDim *dim, const gchar *max)
1068 AdgDimPrivate *data = dim->data;
1070 if (adg_strcmp(max, data->max) == 0)
1071 return FALSE;
1073 g_free(data->max);
1074 data->max = g_strdup(max);
1076 if (data->quote.max != NULL) {
1077 g_object_unref(data->quote.max);
1078 data->quote.max = NULL;
1081 return TRUE;