1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010 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: Root abstract class for all dimension entities
25 * The #AdgDim class is the base stub of all the dimension entities.
31 * All fields are private and should not be used directly.
32 * Use its public methods instead.
36 #include "adg-internal.h"
38 #include "adg-dim-private.h"
39 #include "adg-dim-style.h"
40 #include "adg-dress-builtins.h"
41 #include "adg-toy-text.h"
42 #include "adg-type-builtins.h"
44 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_dim_parent_class)
45 #define PARENT_ENTITY_CLASS ((AdgEntityClass *) adg_dim_parent_class)
48 G_DEFINE_ABSTRACT_TYPE(AdgDim
, adg_dim
, ADG_TYPE_ENTITY
);
65 static void _adg_dispose (GObject
*object
);
66 static void _adg_finalize (GObject
*object
);
67 static void _adg_get_property (GObject
*object
,
71 static void _adg_set_property (GObject
*object
,
75 static void _adg_global_changed (AdgEntity
*entity
);
76 static void _adg_local_changed (AdgEntity
*entity
);
77 static void _adg_invalidate (AdgEntity
*entity
);
78 static void _adg_arrange (AdgEntity
*entity
);
79 static gchar
* _adg_default_value (AdgDim
*dim
);
80 static gdouble
_adg_quote_angle (gdouble angle
);
81 static gboolean
_adg_set_outside (AdgDim
*dim
,
82 AdgThreeState outside
);
83 static gboolean
_adg_set_detached (AdgDim
*dim
,
84 AdgThreeState detached
);
85 static gboolean
_adg_set_value (AdgDim
*dim
,
87 static gboolean
_adg_set_min (AdgDim
*dim
,
89 static gboolean
_adg_set_max (AdgDim
*dim
,
94 adg_dim_class_init(AdgDimClass
*klass
)
96 GObjectClass
*gobject_class
;
97 AdgEntityClass
*entity_class
;
100 gobject_class
= (GObjectClass
*) klass
;
101 entity_class
= (AdgEntityClass
*) klass
;
103 g_type_class_add_private(klass
, sizeof(AdgDimPrivate
));
105 gobject_class
->dispose
= _adg_dispose
;
106 gobject_class
->finalize
= _adg_finalize
;
107 gobject_class
->get_property
= _adg_get_property
;
108 gobject_class
->set_property
= _adg_set_property
;
110 entity_class
->global_changed
= _adg_global_changed
;
111 entity_class
->local_changed
= _adg_local_changed
;
112 entity_class
->invalidate
= _adg_invalidate
;
113 entity_class
->arrange
= _adg_arrange
;
115 klass
->quote_angle
= _adg_quote_angle
;
116 klass
->default_value
= _adg_default_value
;
118 param
= adg_param_spec_dress("dim-dress",
119 P_("Dimension Dress"),
120 P_("The dress to use for rendering this dimension"),
123 g_object_class_install_property(gobject_class
, PROP_DIM_DRESS
, param
);
125 param
= g_param_spec_boxed("ref1",
126 P_("First Reference"),
127 P_("First reference point of the dimension"),
130 g_object_class_install_property(gobject_class
, PROP_REF1
, param
);
132 param
= g_param_spec_boxed("ref2",
133 P_("Second Reference"),
134 P_("Second reference point of the dimension"),
137 g_object_class_install_property(gobject_class
, PROP_REF2
, param
);
139 param
= g_param_spec_boxed("pos",
141 P_("The reference position of the quote: it will be combined with \"level\" to get the real quote position"),
144 g_object_class_install_property(gobject_class
, PROP_POS
, param
);
146 param
= g_param_spec_double("level",
148 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"),
149 -G_MAXDOUBLE
, G_MAXDOUBLE
, 1.0,
151 g_object_class_install_property(gobject_class
, PROP_LEVEL
, param
);
153 param
= g_param_spec_enum("outside",
155 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"),
156 ADG_TYPE_THREE_STATE
, ADG_THREE_STATE_UNKNOWN
,
158 g_object_class_install_property(gobject_class
, PROP_OUTSIDE
, param
);
160 param
= g_param_spec_enum("detached",
161 P_("Detached Quote"),
162 P_("Where the quote must be positioned: in the middle of the base line (ADG_THREE_STATE_OFF), near the pos point (ADG_THREE_STATE_ON) or should be automatically deducted depending on the available space"),
163 ADG_TYPE_THREE_STATE
, ADG_THREE_STATE_UNKNOWN
,
165 g_object_class_install_property(gobject_class
, PROP_DETACHED
, param
);
167 param
= g_param_spec_string("value",
169 P_("The theoretically exact value for this quote: set to NULL to automatically get the default value"),
172 g_object_class_install_property(gobject_class
, PROP_VALUE
, param
);
174 param
= g_param_spec_string("min",
175 P_("Minimum Value or Low Tolerance"),
176 P_("The minimum value allowed or the lowest tolerance from value (depending of the dimension style): set to NULL to suppress"),
179 g_object_class_install_property(gobject_class
, PROP_MIN
, param
);
181 param
= g_param_spec_string("max",
182 P_("Maximum Value or High Tolerance"),
183 P_("The maximum value allowed or the highest tolerance from value (depending of the dimension style): set to NULL to suppress"),
186 g_object_class_install_property(gobject_class
, PROP_MAX
, param
);
190 adg_dim_init(AdgDim
*dim
)
192 AdgDimPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(dim
, ADG_TYPE_DIM
,
195 data
->dim_dress
= ADG_DRESS_DIMENSION
;
200 data
->outside
= ADG_THREE_STATE_UNKNOWN
;
201 data
->detached
= ADG_THREE_STATE_UNKNOWN
;
210 _adg_dispose(GObject
*object
)
215 entity
= (AdgEntity
*) object
;
216 data
= ((AdgDim
*) object
)->data
;
218 if (data
->quote
.entity
!= NULL
) {
219 g_object_unref(data
->quote
.entity
);
220 data
->quote
.entity
= NULL
;
223 if (data
->ref1
!= NULL
)
224 data
->ref1
= adg_entity_point(entity
, data
->ref1
, NULL
);
226 if (data
->ref2
!= NULL
)
227 data
->ref2
= adg_entity_point(entity
, data
->ref2
, NULL
);
229 if (data
->pos
!= NULL
)
230 data
->pos
= adg_entity_point(entity
, data
->pos
, NULL
);
232 if (PARENT_OBJECT_CLASS
->dispose
)
233 PARENT_OBJECT_CLASS
->dispose(object
);
237 _adg_finalize(GObject
*object
)
239 AdgDimPrivate
*data
= ((AdgDim
*) object
)->data
;
245 if (PARENT_OBJECT_CLASS
->finalize
)
246 PARENT_OBJECT_CLASS
->finalize(object
);
250 _adg_get_property(GObject
*object
, guint prop_id
,
251 GValue
*value
, GParamSpec
*pspec
)
253 AdgDimPrivate
*data
= ((AdgDim
*) object
)->data
;
257 g_value_set_int(value
, data
->dim_dress
);
260 g_value_set_boxed(value
, data
->ref1
);
263 g_value_set_boxed(value
, data
->ref2
);
266 g_value_set_boxed(value
, data
->pos
);
269 g_value_set_double(value
, data
->level
);
272 g_value_set_enum(value
, data
->outside
);
275 g_value_set_enum(value
, data
->detached
);
278 g_value_set_string(value
, data
->value
);
281 g_value_set_string(value
, data
->min
);
284 g_value_set_string(value
, data
->max
);
287 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
293 _adg_set_property(GObject
*object
, guint prop_id
,
294 const GValue
*value
, GParamSpec
*pspec
)
300 entity
= (AdgEntity
*) object
;
301 dim
= (AdgDim
*) object
;
306 data
->dim_dress
= g_value_get_int(value
);
309 data
->ref1
= adg_entity_point(entity
, data
->ref1
,
310 g_value_get_boxed(value
));
313 data
->ref2
= adg_entity_point(entity
, data
->ref2
,
314 g_value_get_boxed(value
));
317 data
->pos
= adg_entity_point(entity
, data
->pos
,
318 g_value_get_boxed(value
));
321 data
->level
= g_value_get_double(value
);
324 _adg_set_outside(dim
, g_value_get_enum(value
));
327 _adg_set_detached(dim
, g_value_get_enum(value
));
330 _adg_set_value(dim
, g_value_get_string(value
));
333 _adg_set_min(dim
, g_value_get_string(value
));
336 _adg_set_max(dim
, g_value_get_string(value
));
339 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
346 * adg_dim_set_dim_dress:
348 * @dress: the new #AdgDress to use
350 * Sets a new dimension dress to @dim. The new dress must be
351 * related to the original dress for this property: you cannot
352 * set a dress used for line styles to a dress managing fonts.
354 * The check is done by calling adg_dress_are_related() with
355 * @dress and the previous dress as arguments. Check out its
356 * documentation for details on what is a related dress.
359 adg_dim_set_dim_dress(AdgDim
*dim
, AdgDress dress
)
361 g_return_if_fail(ADG_IS_DIM(dim
));
362 g_object_set((GObject
*) dim
, "dim-dress", dress
, NULL
);
366 * adg_dim_get_dim_dress:
369 * Gets the dimension dress to be used in rendering @dim.
371 * Returns: the current dimension dress
374 adg_dim_get_dim_dress(AdgDim
*dim
)
378 g_return_val_if_fail(ADG_IS_DIM(dim
), ADG_DRESS_UNDEFINED
);
382 return data
->dim_dress
;
388 * @ref1: the new point to use as first reference
390 * Sets the #AdgDim:ref1 property to @ref1. The old point
391 * is silently discarded, unreferencing its model if that
392 * point was bound to a named pair (hence, possibly destroying
393 * the model if this was the last reference).
395 * @ref1 can be %NULL, in which case the point is destroyed.
398 adg_dim_set_ref1(AdgDim
*dim
, const AdgPoint
*ref1
)
400 g_return_if_fail(ADG_IS_DIM(dim
));
401 g_object_set((GObject
*) dim
, "ref1", ref1
, NULL
);
405 * adg_dim_set_ref1_explicit:
407 * @x: x coordinate of the first reference point
408 * @y: y coordinate of the first reference point
410 * Sets the #AdgDim:ref1 property to the (@x, @y) explicit
411 * coordinates. The old point is silently discarded,
412 * unreferencing its model if that point was bound to a named
413 * pair (hence, possibly destroying the model if this was the
417 adg_dim_set_ref1_explicit(AdgDim
*dim
, gdouble x
, gdouble y
)
419 AdgPoint
*point
= adg_point_new();
421 adg_point_set_pair_explicit(point
, x
, y
);
422 adg_dim_set_ref1(dim
, point
);
424 adg_point_destroy(point
);
428 * adg_dim_set_ref1_from_pair:
430 * @ref1: the coordinates pair of the first reference point
432 * Convenient function to set the #AdgDim:ref1 property using a
433 * pair instead of explicit coordinates.
436 adg_dim_set_ref1_from_pair(AdgDim
*dim
, const AdgPair
*ref1
)
438 g_return_if_fail(ref1
!= NULL
);
440 adg_dim_set_ref1_explicit(dim
, ref1
->x
, ref1
->y
);
444 * adg_dim_set_ref1_from_model:
446 * @model: the source #AdgModel
447 * @ref1: a named pair in @model
449 * Binds #AdgDim:ref1 to the @ref1 named pair of @model. If @model
450 * is %NULL, the point will be unset. In any case, the old point
451 * is silently discarded, unreferencing its model if that point
452 * was bound to a named pair (hence, possibly destroying the model
453 * if this was the last reference).
455 * The assignment is lazy so @ref1 could be not be present in @model.
456 * Anyway, at the first access to this point an error will be raised
457 * if the named pair is still missing.
460 adg_dim_set_ref1_from_model(AdgDim
*dim
, AdgModel
*model
, const gchar
*ref1
)
462 AdgPoint
*point
= adg_point_new();
464 adg_point_set_pair_from_model(point
, model
, ref1
);
465 adg_dim_set_ref1(dim
, point
);
467 adg_point_destroy(point
);
474 * Gets the #AdgDim:ref1 point. The returned point is internally owned
475 * and must not be freed or modified. Anyway, it is not const because
476 * adg_point_get_pair() must be able to modify the internal cache of
477 * the returned point.
479 * Returns: the first reference point
482 adg_dim_get_ref1(AdgDim
*dim
)
486 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
496 * @ref2: the new point to use as second reference
498 * Sets the #AdgDim:ref2 property to @ref2. The old point
499 * is silently discarded, unreferencing its model if that
500 * point was bound to a named pair (hence, possibly destroying
501 * the model if it was the last reference).
503 * @ref2 can be %NULL, in which case the point is destroyed.
506 adg_dim_set_ref2(AdgDim
*dim
, const AdgPoint
*ref2
)
508 g_return_if_fail(ADG_IS_DIM(dim
));
509 g_object_set((GObject
*) dim
, "ref2", ref2
, NULL
);
513 * adg_dim_set_ref2_explicit:
515 * @x: x coordinate of the second reference point
516 * @y: y coordinate of the second reference point
518 * Sets the #AdgDim:ref2 property to the (@x, @y) explicit
519 * coordinates. The old point is silently discarded,
520 * unreferencing its model if that point was bound to a named
521 * pair (hence, possibly destroying the model if this was the
525 adg_dim_set_ref2_explicit(AdgDim
*dim
, gdouble x
, gdouble y
)
527 AdgPoint
*point
= adg_point_new();
529 adg_point_set_pair_explicit(point
, x
, y
);
530 adg_dim_set_ref2(dim
, point
);
532 adg_point_destroy(point
);
536 * adg_dim_set_ref2_from_pair:
538 * @ref2: the coordinates pair of the second reference point
540 * Convenient function to set the #AdgDim:ref2 property using a
541 * pair instead of explicit coordinates.
544 adg_dim_set_ref2_from_pair(AdgDim
*dim
, const AdgPair
*ref2
)
546 g_return_if_fail(ref2
!= NULL
);
548 adg_dim_set_ref2_explicit(dim
, ref2
->x
, ref2
->y
);
552 * adg_dim_set_ref2_from_model:
554 * @model: the source #AdgModel
555 * @ref2: a named pair in @model
557 * Binds #AdgDim:ref2 to the @ref2 named pair of @model. If @model
558 * is %NULL, the point will be unset. In any case, the old point
559 * is silently discarded, unreferencing its model if that point
560 * was bound to a named pair (hence, possibly destroying the model
561 * if this was the last reference).
563 * The assignment is lazy so @ref2 could be not be present in @model.
564 * Anyway, at the first access to this point an error will be raised
565 * if the named pair is still missing.
568 adg_dim_set_ref2_from_model(AdgDim
*dim
, AdgModel
*model
, const gchar
*ref2
)
570 AdgPoint
*point
= adg_point_new();
572 adg_point_set_pair_from_model(point
, model
, ref2
);
573 adg_dim_set_ref2(dim
, point
);
575 adg_point_destroy(point
);
582 * Gets the #AdgDim:ref2 point. The returned point is internally owned
583 * and must not be freed or modified. Anyway, it is not const because
584 * adg_point_get_pair() must be able to modify the internal cache of
585 * the returned point.
587 * Returns: the second reference point
590 adg_dim_get_ref2(AdgDim
*dim
)
594 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
604 * @pos: the new point to use as position
606 * Sets the #AdgDim:pos property to @pos. The old point
607 * is silently discarded, unreferencing its model if that
608 * point was bound to a named pair (hence, possibly destroying
609 * the model if it was the last reference).
611 * @pos can be %NULL, in which case the point is destroyed.
614 adg_dim_set_pos(AdgDim
*dim
, const AdgPoint
*pos
)
616 g_return_if_fail(ADG_IS_DIM(dim
));
617 g_object_set((GObject
*) dim
, "pos", pos
, NULL
);
621 * adg_dim_set_pos_explicit:
623 * @x: x coordinate of the position
624 * @y: y coordinate of the position
626 * Sets the #AdgDim:pos property to the (@x, @y) explicit
627 * coordinates. The old point is silently discarded,
628 * unreferencing its model if that point was bound to a named
629 * pair (hence, possibly destroying the model if this was the
633 adg_dim_set_pos_explicit(AdgDim
*dim
, gdouble x
, gdouble y
)
635 AdgPoint
*point
= adg_point_new();
637 adg_point_set_pair_explicit(point
, x
, y
);
638 adg_dim_set_pos(dim
, point
);
640 adg_point_destroy(point
);
644 * adg_dim_set_pos_from_pair:
646 * @pos: the coordinates pair of the position point
648 * Convenient function to set the #AdgDim:pos property using a
649 * pair instead of explicit coordinates.
652 adg_dim_set_pos_from_pair(AdgDim
*dim
, const AdgPair
*pos
)
654 g_return_if_fail(pos
!= NULL
);
656 adg_dim_set_pos_explicit(dim
, pos
->x
, pos
->y
);
660 * adg_dim_set_pos_from_model:
662 * @model: the source #AdgModel
663 * @pos: a named pair in @model
665 * Binds #AdgDim:pos to the @pos named pair of @model. If @model
666 * is %NULL, the point will be unset. In any case, the old point
667 * is silently discarded, unreferencing its model if that point
668 * was bound to a named pair (hence, possibly destroying the model
669 * if this was the last reference).
671 * The assignment is lazy so @pos could be not be present in @model.
672 * Anyway, at the first access to this point an error will be raised
673 * if the named pair is still missing.
676 adg_dim_set_pos_from_model(AdgDim
*dim
, AdgModel
*model
, const gchar
*pos
)
678 AdgPoint
*point
= adg_point_new();
680 adg_point_set_pair_from_model(point
, model
, pos
);
681 adg_dim_set_pos(dim
, point
);
683 adg_point_destroy(point
);
690 * Gets the #AdgDim:pos point. The returned point is internally owned
691 * and must not be freed or modified. Anyway, it is not const because
692 * adg_point_get_pair() must be able to modify the internal cache of
693 * the returned point.
695 * Returns: the position point
698 adg_dim_get_pos(AdgDim
*dim
)
702 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
712 * @level: the new level
714 * Sets a new level for this dimension. The level is used to
715 * stack the quotes using a spacing value from dim_style
716 * (specified in global space).
719 adg_dim_set_level(AdgDim
*dim
, gdouble level
)
723 g_return_if_fail(ADG_IS_DIM(dim
));
728 g_object_notify((GObject
*) dim
, "level");
735 * Gets the level of this dimension.
737 * Returns: the level value
740 adg_dim_get_level(AdgDim
*dim
)
744 g_return_val_if_fail(ADG_IS_DIM(dim
), 0);
752 * adg_dim_set_outside:
754 * @outside: the new outside state
756 * Sets a new state for the #AdgDim:outside flag: check the property
757 * documentation for further details.
760 adg_dim_set_outside(AdgDim
*dim
, AdgThreeState outside
)
762 g_return_if_fail(ADG_IS_DIM(dim
));
764 if (_adg_set_outside(dim
, outside
))
765 g_object_notify((GObject
*) dim
, "outside");
769 * adg_dim_get_outside:
772 * Gets the state of the #AdgDim:outside property: check the property
773 * documentation for further details.
775 * Returns: the current flag state
778 adg_dim_get_outside(AdgDim
*dim
)
782 g_return_val_if_fail(ADG_IS_DIM(dim
), ADG_THREE_STATE_UNKNOWN
);
786 return data
->outside
;
790 * adg_dim_set_detached:
792 * @detached: the new detached state
794 * Sets a new state for the #AdgDim:detached flag: check the property
795 * documentation for further details.
797 * This is used only by dimensions where detaching has meaning.
798 * In some cases, such as with #AdgRDim dimensions, this property is
802 adg_dim_set_detached(AdgDim
*dim
, AdgThreeState detached
)
804 g_return_if_fail(ADG_IS_DIM(dim
));
806 if (_adg_set_detached(dim
, detached
))
807 g_object_notify((GObject
*) dim
, "detached");
811 * adg_dim_get_detached:
814 * Gets the state of the #AdgDim:detached property: check the property
815 * documentation for further details.
817 * Returns: the current flag state
820 adg_dim_get_detached(AdgDim
*dim
)
824 g_return_val_if_fail(ADG_IS_DIM(dim
), ADG_THREE_STATE_UNKNOWN
);
828 return data
->detached
;
834 * @value: the value text
836 * Explicitely sets the text to use as value. If @value is %NULL or
837 * was never set, an automatic text is calculated using the format
838 * specified in the current #AdgDimStyle and getting its value by
839 * calling the default_value() virtual method.
842 adg_dim_set_value(AdgDim
*dim
, const gchar
*value
)
844 g_return_if_fail(ADG_IS_DIM(dim
));
846 if (_adg_set_value(dim
, value
))
847 g_object_notify((GObject
*) dim
, "value");
854 * Gets the value text. The string is internally owned and
855 * must not be freed or modified.
857 * Returns: the value text
860 adg_dim_get_value(AdgDim
*dim
)
864 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
872 * adg_dim_set_limits:
874 * @min: the new minumum value
875 * @max: the new maximum value
877 * Shortcut to set both the limits at once.
880 adg_dim_set_limits(AdgDim
*dim
, const gchar
*min
, const gchar
*max
)
882 g_return_if_fail(ADG_IS_DIM(dim
));
884 g_object_freeze_notify((GObject
*) dim
);
885 adg_dim_set_min(dim
, min
);
886 adg_dim_set_max(dim
, max
);
887 g_object_thaw_notify((GObject
*) dim
);
893 * @min: the new minimum limit
895 * Sets the minimum value. Use %NULL as @min to disable it.
898 adg_dim_set_min(AdgDim
*dim
, const gchar
*min
)
900 g_return_if_fail(ADG_IS_DIM(dim
));
902 if (_adg_set_min(dim
, min
))
903 g_object_notify((GObject
*) dim
, "min");
910 * Gets the minimum value text or %NULL on minimum value disabled.
911 * The string is internally owned and must not be freed or modified.
913 * Returns: the mimimum value text
916 adg_dim_get_min(AdgDim
*dim
)
920 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
930 * @max: the new maximum value
932 * Sets the maximum value. Use %NULL as @max to disable it.
935 adg_dim_set_max(AdgDim
*dim
, const gchar
*max
)
937 g_return_if_fail(ADG_IS_DIM(dim
));
939 if (_adg_set_max(dim
, max
))
940 g_object_notify((GObject
*) dim
, "max");
947 * Gets the maximum value text or %NULL on maximum value disabled.
948 * The string is internally owned and must not be freed or modified.
950 * Returns: the maximum value text
953 adg_dim_get_max(AdgDim
*dim
)
957 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
969 * This function is only useful in new dimension implementations.
972 * Gets the quote entity, if any. This function is valid only after
973 * the #AdgDim implementation of the arrange() virtual method has
976 * Returns: the quote entity
979 adg_dim_get_quote(AdgDim
*dim
)
983 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
987 return data
->quote
.entity
;
991 * adg_dim_quote_angle:
993 * @angle: an angle (in radians)
996 * This function is only useful in new dimension implementations.
999 * Converts @angle accordling to the style of @dim. Any quote angle
1000 * should be validated by this method because every dimensioning
1001 * style has its own convention regardling the text rotation.
1003 * Returns: the angle to use (always in radians)
1006 adg_dim_quote_angle(AdgDim
*dim
, gdouble angle
)
1010 g_return_val_if_fail(ADG_IS_DIM(dim
), angle
);
1012 klass
= ADG_DIM_GET_CLASS(dim
);
1014 if (klass
->quote_angle
== NULL
)
1017 return klass
->quote_angle(angle
);
1022 _adg_global_changed(AdgEntity
*entity
)
1024 AdgDimPrivate
*data
= ((AdgDim
*) entity
)->data
;
1026 if (PARENT_ENTITY_CLASS
->global_changed
)
1027 PARENT_ENTITY_CLASS
->global_changed(entity
);
1029 if (data
->quote
.entity
!= NULL
)
1030 adg_entity_global_changed((AdgEntity
*) data
->quote
.entity
);
1034 _adg_local_changed(AdgEntity
*entity
)
1036 AdgDimPrivate
*data
= ((AdgDim
*) entity
)->data
;
1038 if (PARENT_ENTITY_CLASS
->local_changed
)
1039 PARENT_ENTITY_CLASS
->local_changed(entity
);
1041 if (data
->quote
.entity
!= NULL
)
1042 adg_entity_local_changed((AdgEntity
*) data
->quote
.entity
);
1046 _adg_invalidate(AdgEntity
*entity
)
1048 AdgDimPrivate
*data
= ((AdgDim
*) entity
)->data
;
1050 if (PARENT_ENTITY_CLASS
->invalidate
)
1051 PARENT_ENTITY_CLASS
->invalidate(entity
);
1053 if (data
->quote
.entity
!= NULL
)
1054 adg_entity_invalidate((AdgEntity
*) data
->quote
.entity
);
1056 adg_point_invalidate(data
->ref1
);
1057 adg_point_invalidate(data
->ref2
);
1058 adg_point_invalidate(data
->pos
);
1062 _adg_arrange(AdgEntity
*entity
)
1065 AdgDimPrivate
*data
;
1066 AdgEntity
*quote_entity
;
1067 AdgContainer
*quote_container
;
1068 AdgEntity
*value_entity
;
1069 AdgEntity
*min_entity
;
1070 AdgEntity
*max_entity
;
1071 const AdgPair
*shift
;
1074 dim
= (AdgDim
*) entity
;
1077 /* Resolve the dim style */
1078 if (data
->dim_style
== NULL
)
1079 data
->dim_style
= (AdgDimStyle
*)
1080 adg_entity_style(entity
, data
->dim_dress
);
1082 if (data
->quote
.entity
== NULL
)
1083 data
->quote
.entity
= g_object_new(ADG_TYPE_ALIGNMENT
,
1084 "local-method", ADG_MIX_NONE
,
1085 "parent", dim
, NULL
);
1087 quote_entity
= (AdgEntity
*) data
->quote
.entity
;
1088 quote_container
= (AdgContainer
*) data
->quote
.entity
;
1090 if (data
->quote
.value
== NULL
) {
1091 AdgDress dress
= adg_dim_style_get_value_dress(data
->dim_style
);
1093 data
->quote
.value
= g_object_new(ADG_TYPE_TOY_TEXT
,
1094 "local-method", ADG_MIX_PARENT
,
1095 "font-dress", dress
, NULL
);
1097 adg_container_add(quote_container
, (AdgEntity
*) data
->quote
.value
);
1100 adg_toy_text_set_label(data
->quote
.value
, data
->value
);
1102 AdgDimClass
*klass
= ADG_DIM_GET_CLASS(dim
);
1104 if (klass
->default_value
) {
1105 /* Automatically generate the value text */
1106 gchar
*text
= klass
->default_value(dim
);
1107 adg_toy_text_set_label(data
->quote
.value
, text
);
1113 if (data
->quote
.min
== NULL
&& data
->min
!= NULL
) {
1114 AdgDress dress
= adg_dim_style_get_min_dress(data
->dim_style
);
1116 data
->quote
.min
= g_object_new(ADG_TYPE_TOY_TEXT
,
1117 "local-method", ADG_MIX_PARENT
,
1118 "font-dress", dress
, NULL
);
1120 adg_container_add(quote_container
, (AdgEntity
*) data
->quote
.min
);
1121 adg_toy_text_set_label(data
->quote
.min
, data
->min
);
1124 if (data
->quote
.max
== NULL
&& data
->max
!= NULL
) {
1125 AdgDress dress
= adg_dim_style_get_max_dress(data
->dim_style
);
1127 data
->quote
.max
= g_object_new(ADG_TYPE_TOY_TEXT
,
1128 "local-method", ADG_MIX_PARENT
,
1129 "font-dress", dress
, NULL
);
1131 adg_container_add(quote_container
, (AdgEntity
*) data
->quote
.max
);
1132 adg_toy_text_set_label(data
->quote
.max
, data
->max
);
1135 value_entity
= (AdgEntity
*) data
->quote
.value
;
1136 min_entity
= (AdgEntity
*) data
->quote
.min
;
1137 max_entity
= (AdgEntity
*) data
->quote
.max
;
1138 shift
= adg_dim_style_get_quote_shift(data
->dim_style
);
1140 adg_entity_set_global_map(quote_entity
, adg_matrix_identity());
1141 adg_entity_global_changed(quote_entity
);
1143 cairo_matrix_init_translate(&map
, shift
->x
, shift
->y
);
1144 adg_entity_set_global_map(value_entity
, &map
);
1145 adg_entity_arrange(value_entity
);
1147 /* Limit values (min and max) */
1148 if (min_entity
!= NULL
|| max_entity
!= NULL
) {
1149 const CpmlExtents
*extents
;
1150 const AdgPair
*limits_shift
;
1153 extents
= adg_entity_get_extents(value_entity
);
1154 limits_shift
= adg_dim_style_get_limits_shift(data
->dim_style
);
1156 cairo_matrix_init_translate(&map
, extents
->size
.x
+ limits_shift
->x
,
1157 -extents
->size
.y
/ 2 + limits_shift
->y
);
1159 adg_matrix_copy(&unglobal
, adg_entity_get_global_matrix(entity
));
1160 cairo_matrix_invert(&unglobal
);
1161 cairo_matrix_transform_distance(&unglobal
, &map
.x0
, &map
.y0
);
1163 if (min_entity
!= NULL
) {
1166 adg_entity_set_global_map(min_entity
, &map
);
1167 adg_entity_arrange(min_entity
);
1168 extents
= adg_entity_get_extents(min_entity
);
1171 offset
.y
= -extents
->size
.y
- adg_dim_style_get_limits_spacing(data
->dim_style
);
1172 cairo_matrix_transform_distance(&unglobal
, &offset
.x
, &offset
.y
);
1178 if (max_entity
!= NULL
) {
1179 adg_entity_set_global_map(max_entity
, &map
);
1180 adg_entity_arrange(max_entity
);
1184 adg_entity_arrange(quote_entity
);
1188 _adg_default_value(AdgDim
*dim
)
1190 g_warning("AdgDim::default_value not implemented for `%s'",
1191 g_type_name(G_TYPE_FROM_INSTANCE(dim
)));
1192 return g_strdup("undef");
1196 _adg_quote_angle(gdouble angle
)
1198 angle
= cpml_angle(angle
);
1200 if (angle
> G_PI_4
* 4 / 3 || angle
<= -G_PI_4
* 3)
1201 angle
= cpml_angle(angle
+ G_PI
);
1207 _adg_set_outside(AdgDim
*dim
, AdgThreeState outside
)
1209 AdgDimPrivate
*data
;
1211 g_return_val_if_fail(adg_is_enum_value(outside
, ADG_TYPE_THREE_STATE
),
1216 if (data
->outside
== outside
)
1219 data
->outside
= outside
;
1225 _adg_set_detached(AdgDim
*dim
, AdgThreeState detached
)
1227 AdgDimPrivate
*data
;
1229 g_return_val_if_fail(adg_is_enum_value(detached
, ADG_TYPE_THREE_STATE
),
1234 if (data
->detached
== detached
)
1237 data
->detached
= detached
;
1243 _adg_set_value(AdgDim
*dim
, const gchar
*value
)
1245 AdgDimPrivate
*data
;
1249 if (g_strcmp0(value
, data
->value
) == 0)
1252 g_free(data
->value
);
1253 data
->value
= g_strdup(value
);
1255 if (data
->quote
.value
!= NULL
) {
1256 g_object_unref(data
->quote
.value
);
1257 data
->quote
.value
= NULL
;
1264 _adg_set_min(AdgDim
*dim
, const gchar
*min
)
1266 AdgDimPrivate
*data
= dim
->data
;
1268 if (g_strcmp0(min
, data
->min
) == 0)
1272 data
->min
= g_strdup(min
);
1274 if (data
->quote
.min
!= NULL
) {
1275 g_object_unref(data
->quote
.min
);
1276 data
->quote
.min
= NULL
;
1283 _adg_set_max(AdgDim
*dim
, const gchar
*max
)
1285 AdgDimPrivate
*data
= dim
->data
;
1287 if (g_strcmp0(max
, data
->max
) == 0)
1291 data
->max
= g_strdup(max
);
1293 if (data
->quote
.max
!= NULL
) {
1294 g_object_unref(data
->quote
.max
);
1295 data
->quote
.max
= NULL
;