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)
63 static void dispose (GObject
*object
);
64 static void finalize (GObject
*object
);
65 static void get_property (GObject
*object
,
69 static void set_property (GObject
*object
,
73 static void global_changed (AdgEntity
*entity
);
74 static void local_changed (AdgEntity
*entity
);
75 static void invalidate (AdgEntity
*entity
);
76 static void arrange (AdgEntity
*entity
);
77 static gchar
* default_value (AdgDim
*dim
);
78 static gdouble
quote_angle (gdouble angle
);
79 static gboolean
set_dim_dress (AdgDim
*dim
,
81 static gboolean
set_outside (AdgDim
*dim
,
82 AdgThreeState outside
);
83 static gboolean
set_detached (AdgDim
*dim
,
84 AdgThreeState detached
);
85 static gboolean
set_value (AdgDim
*dim
,
87 static gboolean
set_min (AdgDim
*dim
,
89 static gboolean
set_max (AdgDim
*dim
,
93 G_DEFINE_ABSTRACT_TYPE(AdgDim
, adg_dim
, ADG_TYPE_ENTITY
);
97 adg_dim_class_init(AdgDimClass
*klass
)
99 GObjectClass
*gobject_class
;
100 AdgEntityClass
*entity_class
;
103 gobject_class
= (GObjectClass
*) klass
;
104 entity_class
= (AdgEntityClass
*) klass
;
106 g_type_class_add_private(klass
, sizeof(AdgDimPrivate
));
108 gobject_class
->dispose
= dispose
;
109 gobject_class
->finalize
= finalize
;
110 gobject_class
->get_property
= get_property
;
111 gobject_class
->set_property
= set_property
;
113 entity_class
->global_changed
= global_changed
;
114 entity_class
->local_changed
= local_changed
;
115 entity_class
->invalidate
= invalidate
;
116 entity_class
->arrange
= arrange
;
118 klass
->quote_angle
= quote_angle
;
119 klass
->default_value
= default_value
;
121 param
= adg_param_spec_dress("dim-dress",
122 P_("Dimension Dress"),
123 P_("The dress to use for rendering this dimension"),
126 g_object_class_install_property(gobject_class
, PROP_DIM_DRESS
, param
);
128 param
= g_param_spec_boxed("ref1",
129 P_("First Reference"),
130 P_("First reference point of the dimension"),
133 g_object_class_install_property(gobject_class
, PROP_REF1
, param
);
135 param
= g_param_spec_boxed("ref2",
136 P_("Second Reference"),
137 P_("Second reference point of the dimension"),
140 g_object_class_install_property(gobject_class
, PROP_REF2
, param
);
142 param
= g_param_spec_boxed("pos",
144 P_("The reference position of the quote: it will be combined with \"level\" to get the real quote position"),
147 g_object_class_install_property(gobject_class
, PROP_POS
, param
);
149 param
= g_param_spec_double("level",
151 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"),
152 -G_MAXDOUBLE
, G_MAXDOUBLE
, 1.0,
154 g_object_class_install_property(gobject_class
, PROP_LEVEL
, param
);
156 param
= g_param_spec_enum("outside",
158 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"),
159 ADG_TYPE_THREE_STATE
, ADG_THREE_STATE_UNKNOWN
,
161 g_object_class_install_property(gobject_class
, PROP_OUTSIDE
, param
);
163 param
= g_param_spec_enum("detached",
164 P_("Detached Quote"),
165 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"),
166 ADG_TYPE_THREE_STATE
, ADG_THREE_STATE_UNKNOWN
,
168 g_object_class_install_property(gobject_class
, PROP_DETACHED
, param
);
170 param
= g_param_spec_string("value",
172 P_("The theoretically exact value for this quote: set to NULL to automatically get the default value"),
175 g_object_class_install_property(gobject_class
, PROP_VALUE
, param
);
177 param
= g_param_spec_string("min",
178 P_("Minimum Value or Low Tolerance"),
179 P_("The minimum value allowed or the lowest tolerance from value (depending of the dimension style): set to NULL to suppress"),
182 g_object_class_install_property(gobject_class
, PROP_MIN
, param
);
184 param
= g_param_spec_string("max",
185 P_("Maximum Value or High Tolerance"),
186 P_("The maximum value allowed or the highest tolerance from value (depending of the dimension style): set to NULL to suppress"),
189 g_object_class_install_property(gobject_class
, PROP_MAX
, param
);
193 adg_dim_init(AdgDim
*dim
)
195 AdgDimPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(dim
, ADG_TYPE_DIM
,
198 data
->dim_dress
= ADG_DRESS_DIMENSION
;
203 data
->outside
= ADG_THREE_STATE_UNKNOWN
;
204 data
->detached
= ADG_THREE_STATE_UNKNOWN
;
213 dispose(GObject
*object
)
215 AdgDimPrivate
*data
= ((AdgDim
*) object
)->data
;
217 if (data
->quote
.entity
!= NULL
) {
218 g_object_unref(data
->quote
.entity
);
219 data
->quote
.entity
= NULL
;
221 if (data
->ref1
!= NULL
) {
222 adg_point_destroy(data
->ref1
);
225 if (data
->ref2
!= NULL
) {
226 adg_point_destroy(data
->ref2
);
229 if (data
->pos
!= NULL
) {
230 adg_point_destroy(data
->pos
);
234 if (PARENT_OBJECT_CLASS
->dispose
)
235 PARENT_OBJECT_CLASS
->dispose(object
);
239 finalize(GObject
*object
)
241 AdgDimPrivate
*data
= ((AdgDim
*) object
)->data
;
247 if (PARENT_OBJECT_CLASS
->finalize
)
248 PARENT_OBJECT_CLASS
->finalize(object
);
252 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
254 AdgDimPrivate
*data
= ((AdgDim
*) object
)->data
;
258 g_value_set_int(value
, data
->dim_dress
);
261 g_value_set_boxed(value
, data
->ref1
);
264 g_value_set_boxed(value
, data
->ref2
);
267 g_value_set_boxed(value
, data
->pos
);
270 g_value_set_double(value
, data
->level
);
273 g_value_set_enum(value
, data
->outside
);
276 g_value_set_enum(value
, data
->detached
);
279 g_value_set_string(value
, data
->value
);
282 g_value_set_string(value
, data
->min
);
285 g_value_set_string(value
, data
->max
);
288 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
294 set_property(GObject
*object
, guint prop_id
,
295 const GValue
*value
, GParamSpec
*pspec
)
300 dim
= (AdgDim
*) object
;
305 set_dim_dress(dim
, g_value_get_int(value
));
308 adg_point_set(&data
->ref1
, g_value_get_boxed(value
));
311 adg_point_set(&data
->ref2
, g_value_get_boxed(value
));
314 adg_point_set(&data
->pos
, g_value_get_boxed(value
));
317 data
->level
= g_value_get_double(value
);
320 set_outside(dim
, g_value_get_enum(value
));
323 set_detached(dim
, g_value_get_enum(value
));
326 set_value(dim
, g_value_get_string(value
));
329 set_min(dim
, g_value_get_string(value
));
332 set_max(dim
, g_value_get_string(value
));
335 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
342 * adg_dim_set_dim_dress:
344 * @dress: the new #AdgDress to use
346 * Sets a new dimension dress to @dim. The new dress must be
347 * related to the original dress for this property: you cannot
348 * set a dress used for line styles to a dress managing fonts.
350 * The check is done by calling adg_dress_are_related() with
351 * @dress and the previous dress as arguments. Check out its
352 * documentation for details on what is a related dress.
355 adg_dim_set_dim_dress(AdgDim
*dim
, AdgDress dress
)
357 g_return_if_fail(ADG_IS_DIM(dim
));
359 if (set_dim_dress(dim
, dress
))
360 g_object_notify((GObject
*) dim
, "dim-dress");
364 * adg_dim_get_dim_dress:
367 * Gets the dimension dress to be used in rendering @dim.
369 * Returns: the current dimension dress
372 adg_dim_get_dim_dress(AdgDim
*dim
)
376 g_return_val_if_fail(ADG_IS_DIM(dim
), ADG_DRESS_UNDEFINED
);
380 return data
->dim_dress
;
386 * @ref1: the new point to use as first reference
388 * Sets the #AdgDim:ref1 property to @ref1. The old point
389 * is silently discarded, unreferencing its model if that
390 * point was bound to a named pair (hence, possibly destroying
391 * the model if this was the last reference).
393 * @ref1 can be %NULL, in which case the point is unset.
396 adg_dim_set_ref1(AdgDim
*dim
, const AdgPoint
*ref1
)
400 g_return_if_fail(ADG_IS_DIM(dim
));
404 if (adg_point_set(&data
->ref1
, ref1
))
405 g_object_notify((GObject
*) dim
, "ref1");
409 * adg_dim_set_ref1_explicit:
411 * @x: x coordinate of the first reference point
412 * @y: y coordinate of the first reference point
414 * Sets the #AdgDim:ref1 property to the (@x, @y) explicit
415 * coordinates. The old point is silently discarded,
416 * unreferencing its model if that point was bound to a named
417 * pair (hence, possibly destroying the model if this was the
421 adg_dim_set_ref1_explicit(AdgDim
*dim
, gdouble x
, gdouble y
)
423 AdgPoint
*point
= adg_point_new();
425 adg_point_set_pair_explicit(point
, x
, y
);
426 adg_dim_set_ref1(dim
, point
);
428 adg_point_destroy(point
);
432 * adg_dim_set_ref1_from_pair:
434 * @ref1: the coordinates pair of the first reference point
436 * Convenient function to set the #AdgDim:ref1 property using a
437 * pair instead of explicit coordinates.
440 adg_dim_set_ref1_from_pair(AdgDim
*dim
, const AdgPair
*ref1
)
442 g_return_if_fail(ref1
!= NULL
);
444 adg_dim_set_ref1_explicit(dim
, ref1
->x
, ref1
->y
);
448 * adg_dim_set_ref1_from_model:
450 * @model: the source #AdgModel
451 * @ref1: a named pair in @model
453 * Binds #AdgDim:ref1 to the @ref1 named pair of @model. If @model
454 * is %NULL, the point will be unset. In any case, the old point
455 * is silently discarded, unreferencing its model if that point
456 * was bound to a named pair (hence, possibly destroying the model
457 * if this was the last reference).
459 * The assignment is lazy so @ref1 could be not be present in @model.
460 * Anyway, at the first access to this point an error will be raised
461 * if the named pair is still missing.
464 adg_dim_set_ref1_from_model(AdgDim
*dim
, AdgModel
*model
, const gchar
*ref1
)
466 AdgPoint
*point
= adg_point_new();
468 adg_point_set_pair_from_model(point
, model
, ref1
);
469 adg_dim_set_ref1(dim
, point
);
471 adg_point_destroy(point
);
478 * Gets the #AdgDim:ref1 point. The returned point is internally owned
479 * and must not be freed or modified. Anyway, it is not const because
480 * adg_point_get_pair() must be able to modify the internal cache of
481 * the returned point.
483 * Returns: the first reference point
486 adg_dim_get_ref1(AdgDim
*dim
)
490 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
500 * @ref2: the new point to use as second reference
502 * Sets the #AdgDim:ref2 property to @ref2. The old point
503 * is silently discarded, unreferencing its model if that
504 * point was bound to a named pair (hence, possibly destroying
505 * the model if it was the last reference).
507 * @ref2 can be %NULL, in which case the point is unset.
510 adg_dim_set_ref2(AdgDim
*dim
, const AdgPoint
*ref2
)
514 g_return_if_fail(ADG_IS_DIM(dim
));
518 if (adg_point_set(&data
->ref2
, ref2
))
519 g_object_notify((GObject
*) dim
, "ref2");
523 * adg_dim_set_ref2_explicit:
525 * @x: x coordinate of the second reference point
526 * @y: y coordinate of the second reference point
528 * Sets the #AdgDim:ref2 property to the (@x, @y) explicit
529 * coordinates. The old point is silently discarded,
530 * unreferencing its model if that point was bound to a named
531 * pair (hence, possibly destroying the model if this was the
535 adg_dim_set_ref2_explicit(AdgDim
*dim
, gdouble x
, gdouble y
)
537 AdgPoint
*point
= adg_point_new();
539 adg_point_set_pair_explicit(point
, x
, y
);
540 adg_dim_set_ref2(dim
, point
);
542 adg_point_destroy(point
);
546 * adg_dim_set_ref2_from_pair:
548 * @ref2: the coordinates pair of the second reference point
550 * Convenient function to set the #AdgDim:ref2 property using a
551 * pair instead of explicit coordinates.
554 adg_dim_set_ref2_from_pair(AdgDim
*dim
, const AdgPair
*ref2
)
556 g_return_if_fail(ref2
!= NULL
);
558 adg_dim_set_ref2_explicit(dim
, ref2
->x
, ref2
->y
);
562 * adg_dim_set_ref2_from_model:
564 * @model: the source #AdgModel
565 * @ref2: a named pair in @model
567 * Binds #AdgDim:ref2 to the @ref2 named pair of @model. If @model
568 * is %NULL, the point will be unset. In any case, the old point
569 * is silently discarded, unreferencing its model if that point
570 * was bound to a named pair (hence, possibly destroying the model
571 * if this was the last reference).
573 * The assignment is lazy so @ref2 could be not be present in @model.
574 * Anyway, at the first access to this point an error will be raised
575 * if the named pair is still missing.
578 adg_dim_set_ref2_from_model(AdgDim
*dim
, AdgModel
*model
, const gchar
*ref2
)
580 AdgPoint
*point
= adg_point_new();
582 adg_point_set_pair_from_model(point
, model
, ref2
);
583 adg_dim_set_ref2(dim
, point
);
585 adg_point_destroy(point
);
592 * Gets the #AdgDim:ref2 point. The returned point is internally owned
593 * and must not be freed or modified. Anyway, it is not const because
594 * adg_point_get_pair() must be able to modify the internal cache of
595 * the returned point.
597 * Returns: the second reference point
600 adg_dim_get_ref2(AdgDim
*dim
)
604 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
614 * @pos: the new point to use as position
616 * Sets the #AdgDim:pos property to @pos. The old point
617 * is silently discarded, unreferencing its model if that
618 * point was bound to a named pair (hence, possibly destroying
619 * the model if it was the last reference).
621 * @pos can be %NULL, in which case the point is unset.
624 adg_dim_set_pos(AdgDim
*dim
, const AdgPoint
*pos
)
628 g_return_if_fail(ADG_IS_DIM(dim
));
632 if (adg_point_set(&data
->pos
, pos
))
633 g_object_notify((GObject
*) dim
, "pos");
637 * adg_dim_set_pos_explicit:
639 * @x: x coordinate of the position
640 * @y: y coordinate of the position
642 * Sets the #AdgDim:pos property to the (@x, @y) explicit
643 * coordinates. The old point is silently discarded,
644 * unreferencing its model if that point was bound to a named
645 * pair (hence, possibly destroying the model if this was the
649 adg_dim_set_pos_explicit(AdgDim
*dim
, gdouble x
, gdouble y
)
651 AdgPoint
*point
= adg_point_new();
653 adg_point_set_pair_explicit(point
, x
, y
);
654 adg_dim_set_pos(dim
, point
);
656 adg_point_destroy(point
);
660 * adg_dim_set_pos_from_pair:
662 * @pos: the coordinates pair of the position point
664 * Convenient function to set the #AdgDim:pos property using a
665 * pair instead of explicit coordinates.
668 adg_dim_set_pos_from_pair(AdgDim
*dim
, const AdgPair
*pos
)
670 g_return_if_fail(pos
!= NULL
);
672 adg_dim_set_pos_explicit(dim
, pos
->x
, pos
->y
);
676 * adg_dim_set_pos_from_model:
678 * @model: the source #AdgModel
679 * @pos: a named pair in @model
681 * Binds #AdgDim:pos to the @pos named pair of @model. If @model
682 * is %NULL, the point will be unset. In any case, the old point
683 * is silently discarded, unreferencing its model if that point
684 * was bound to a named pair (hence, possibly destroying the model
685 * if this was the last reference).
687 * The assignment is lazy so @pos could be not be present in @model.
688 * Anyway, at the first access to this point an error will be raised
689 * if the named pair is still missing.
692 adg_dim_set_pos_from_model(AdgDim
*dim
, AdgModel
*model
, const gchar
*pos
)
694 AdgPoint
*point
= adg_point_new();
696 adg_point_set_pair_from_model(point
, model
, pos
);
697 adg_dim_set_pos(dim
, point
);
699 adg_point_destroy(point
);
706 * Gets the #AdgDim:pos point. The returned point is internally owned
707 * and must not be freed or modified. Anyway, it is not const because
708 * adg_point_get_pair() must be able to modify the internal cache of
709 * the returned point.
711 * Returns: the position point
714 adg_dim_get_pos(AdgDim
*dim
)
718 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
728 * @level: the new level
730 * Sets a new level for this dimension. The level is used to
731 * stack the quotes using a spacing value from dim_style
732 * (specified in global space).
735 adg_dim_set_level(AdgDim
*dim
, gdouble level
)
739 g_return_if_fail(ADG_IS_DIM(dim
));
744 g_object_notify((GObject
*) dim
, "level");
751 * Gets the level of this dimension.
753 * Returns: the level value
756 adg_dim_get_level(AdgDim
*dim
)
760 g_return_val_if_fail(ADG_IS_DIM(dim
), 0);
768 * adg_dim_set_outside:
770 * @outside: the new outside state
772 * Sets a new state for the #AdgDim:outside flag: check the property
773 * documentation for further details.
776 adg_dim_set_outside(AdgDim
*dim
, AdgThreeState outside
)
778 g_return_if_fail(ADG_IS_DIM(dim
));
780 if (set_outside(dim
, outside
))
781 g_object_notify((GObject
*) dim
, "outside");
785 * adg_dim_get_outside:
788 * Gets the state of the #AdgDim:outside property: check the property
789 * documentation for further details.
791 * Returns: the current flag state
794 adg_dim_get_outside(AdgDim
*dim
)
798 g_return_val_if_fail(ADG_IS_DIM(dim
), ADG_THREE_STATE_UNKNOWN
);
802 return data
->outside
;
806 * adg_dim_set_detached:
808 * @detached: the new detached state
810 * Sets a new state for the #AdgDim:detached flag: check the property
811 * documentation for further details.
813 * This is used only by dimensions where detaching has meaning.
814 * In some cases, such as with #AdgRDim dimensions, this property is
818 adg_dim_set_detached(AdgDim
*dim
, AdgThreeState detached
)
820 g_return_if_fail(ADG_IS_DIM(dim
));
822 if (set_detached(dim
, detached
))
823 g_object_notify((GObject
*) dim
, "detached");
827 * adg_dim_get_detached:
830 * Gets the state of the #AdgDim:detached property: check the property
831 * documentation for further details.
833 * Returns: the current flag state
836 adg_dim_get_detached(AdgDim
*dim
)
840 g_return_val_if_fail(ADG_IS_DIM(dim
), ADG_THREE_STATE_UNKNOWN
);
844 return data
->detached
;
850 * @value: the value text
852 * Explicitely sets the text to use as value. If @value is %NULL or
853 * was never set, an automatic text is calculated using the format
854 * specified in the current #AdgDimStyle and getting its value by
855 * calling the default_value() virtual method.
858 adg_dim_set_value(AdgDim
*dim
, const gchar
*value
)
860 g_return_if_fail(ADG_IS_DIM(dim
));
862 if (set_value(dim
, value
))
863 g_object_notify((GObject
*) dim
, "value");
870 * Gets the value text. The string is internally owned and
871 * must not be freed or modified.
873 * Returns: the value text
876 adg_dim_get_value(AdgDim
*dim
)
880 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
888 * adg_dim_set_limits:
890 * @min: the new minumum value
891 * @max: the new maximum value
893 * Shortcut to set both the limits at once.
896 adg_dim_set_limits(AdgDim
*dim
, const gchar
*min
, const gchar
*max
)
898 g_return_if_fail(ADG_IS_DIM(dim
));
900 g_object_freeze_notify((GObject
*) dim
);
901 adg_dim_set_min(dim
, min
);
902 adg_dim_set_max(dim
, max
);
903 g_object_thaw_notify((GObject
*) dim
);
909 * @min: the new minimum limit
911 * Sets the minimum value. Use %NULL as @min to disable it.
914 adg_dim_set_min(AdgDim
*dim
, const gchar
*min
)
916 g_return_if_fail(ADG_IS_DIM(dim
));
918 if (set_min(dim
, min
))
919 g_object_notify((GObject
*) dim
, "min");
926 * Gets the minimum value text or %NULL on minimum value disabled.
927 * The string is internally owned and must not be freed or modified.
929 * Returns: the mimimum value text
932 adg_dim_get_min(AdgDim
*dim
)
936 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
946 * @max: the new maximum value
948 * Sets the maximum value. Use %NULL as @max to disable it.
951 adg_dim_set_max(AdgDim
*dim
, const gchar
*max
)
953 g_return_if_fail(ADG_IS_DIM(dim
));
955 if (set_max(dim
, max
))
956 g_object_notify((GObject
*) dim
, "max");
963 * Gets the maximum value text or %NULL on maximum value disabled.
964 * The string is internally owned and must not be freed or modified.
966 * Returns: the maximum value text
969 adg_dim_get_max(AdgDim
*dim
)
973 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
985 * This function is only useful in new dimension implementations.
988 * Gets the quote entity, if any. This function is valid only after
989 * the #AdgDim implementation of the arrange() virtual method has
992 * Returns: the quote entity
995 adg_dim_get_quote(AdgDim
*dim
)
999 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
1003 return data
->quote
.entity
;
1007 * adg_dim_quote_angle:
1009 * @angle: an angle (in radians)
1012 * This function is only useful in new dimension implementations.
1015 * Converts @angle accordling to the style of @dim. Any quote angle
1016 * should be validated by this method because every dimensioning
1017 * style has its own convention regardling the text rotation.
1019 * Returns: the angle to use (always in radians)
1022 adg_dim_quote_angle(AdgDim
*dim
, gdouble angle
)
1026 g_return_val_if_fail(ADG_IS_DIM(dim
), angle
);
1028 klass
= ADG_DIM_GET_CLASS(dim
);
1030 if (klass
->quote_angle
== NULL
)
1033 return klass
->quote_angle(angle
);
1038 global_changed(AdgEntity
*entity
)
1040 AdgDimPrivate
*data
= ((AdgDim
*) entity
)->data
;
1042 if (PARENT_ENTITY_CLASS
->global_changed
)
1043 PARENT_ENTITY_CLASS
->global_changed(entity
);
1045 if (data
->quote
.entity
!= NULL
)
1046 adg_entity_global_changed((AdgEntity
*) data
->quote
.entity
);
1050 local_changed(AdgEntity
*entity
)
1052 AdgDimPrivate
*data
= ((AdgDim
*) entity
)->data
;
1054 if (PARENT_ENTITY_CLASS
->local_changed
)
1055 PARENT_ENTITY_CLASS
->local_changed(entity
);
1057 if (data
->quote
.entity
!= NULL
)
1058 adg_entity_local_changed((AdgEntity
*) data
->quote
.entity
);
1062 invalidate(AdgEntity
*entity
)
1064 AdgDimPrivate
*data
= ((AdgDim
*) entity
)->data
;
1066 if (PARENT_ENTITY_CLASS
->invalidate
)
1067 PARENT_ENTITY_CLASS
->invalidate(entity
);
1069 if (data
->quote
.entity
!= NULL
)
1070 adg_entity_invalidate((AdgEntity
*) data
->quote
.entity
);
1072 adg_point_invalidate(data
->ref1
);
1073 adg_point_invalidate(data
->ref2
);
1074 adg_point_invalidate(data
->pos
);
1078 arrange(AdgEntity
*entity
)
1081 AdgDimPrivate
*data
;
1082 AdgEntity
*quote_entity
;
1083 AdgContainer
*quote_container
;
1084 AdgEntity
*value_entity
;
1085 AdgEntity
*min_entity
;
1086 AdgEntity
*max_entity
;
1087 const AdgPair
*shift
;
1090 dim
= (AdgDim
*) entity
;
1093 /* Resolve the dim style */
1094 if (data
->dim_style
== NULL
)
1095 data
->dim_style
= (AdgDimStyle
*)
1096 adg_entity_style(entity
, data
->dim_dress
);
1098 if (data
->quote
.entity
== NULL
)
1099 data
->quote
.entity
= g_object_new(ADG_TYPE_ALIGNMENT
,
1100 "local-method", ADG_MIX_NONE
,
1101 "parent", dim
, NULL
);
1103 quote_entity
= (AdgEntity
*) data
->quote
.entity
;
1104 quote_container
= (AdgContainer
*) data
->quote
.entity
;
1106 if (data
->quote
.value
== NULL
) {
1107 AdgDress dress
= adg_dim_style_get_value_dress(data
->dim_style
);
1109 data
->quote
.value
= g_object_new(ADG_TYPE_TOY_TEXT
,
1110 "local-method", ADG_MIX_PARENT
,
1111 "font-dress", dress
, NULL
);
1113 adg_container_add(quote_container
, (AdgEntity
*) data
->quote
.value
);
1116 adg_toy_text_set_label(data
->quote
.value
, data
->value
);
1118 AdgDimClass
*klass
= ADG_DIM_GET_CLASS(dim
);
1120 if (klass
->default_value
) {
1121 /* Automatically generate the value text */
1122 gchar
*text
= klass
->default_value(dim
);
1123 adg_toy_text_set_label(data
->quote
.value
, text
);
1129 if (data
->quote
.min
== NULL
&& data
->min
!= NULL
) {
1130 AdgDress dress
= adg_dim_style_get_min_dress(data
->dim_style
);
1132 data
->quote
.min
= g_object_new(ADG_TYPE_TOY_TEXT
,
1133 "local-method", ADG_MIX_PARENT
,
1134 "font-dress", dress
, NULL
);
1136 adg_container_add(quote_container
, (AdgEntity
*) data
->quote
.min
);
1137 adg_toy_text_set_label(data
->quote
.min
, data
->min
);
1140 if (data
->quote
.max
== NULL
&& data
->max
!= NULL
) {
1141 AdgDress dress
= adg_dim_style_get_max_dress(data
->dim_style
);
1143 data
->quote
.max
= g_object_new(ADG_TYPE_TOY_TEXT
,
1144 "local-method", ADG_MIX_PARENT
,
1145 "font-dress", dress
, NULL
);
1147 adg_container_add(quote_container
, (AdgEntity
*) data
->quote
.max
);
1148 adg_toy_text_set_label(data
->quote
.max
, data
->max
);
1151 value_entity
= (AdgEntity
*) data
->quote
.value
;
1152 min_entity
= (AdgEntity
*) data
->quote
.min
;
1153 max_entity
= (AdgEntity
*) data
->quote
.max
;
1154 shift
= adg_dim_style_get_quote_shift(data
->dim_style
);
1156 adg_entity_set_global_map(quote_entity
, adg_matrix_identity());
1157 adg_entity_global_changed(quote_entity
);
1159 cairo_matrix_init_translate(&map
, shift
->x
, shift
->y
);
1160 adg_entity_set_global_map(value_entity
, &map
);
1161 adg_entity_arrange(value_entity
);
1163 /* Limit values (min and max) */
1164 if (min_entity
!= NULL
|| max_entity
!= NULL
) {
1165 const CpmlExtents
*extents
= adg_entity_get_extents(value_entity
);
1166 //CpmlExtents min_extents = { 0 };
1167 //CpmlExtents max_extents = { 0 };
1168 const AdgPair
*limits_shift
= adg_dim_style_get_limits_shift(data
->dim_style
);
1171 if (min_entity
!= NULL
)
1172 cpml_extents_copy(&min_extents
, adg_entity_get_extents(min_entity
));
1174 if (max_entity
!= NULL
)
1175 cpml_extents_copy(&max_extents
, adg_entity_get_extents(max_entity
));
1177 if (min_entity
!= NULL
&& max_entity
!= NULL
)
1178 spacing
= adg_dim_style_get_limits_spacing(data
->dim_style
);
1180 cairo_matrix_init_translate(&map
,
1182 shift
->x
+ limit_shift
->x
,
1183 (spacing
+ min_extents
.size
.y
+
1184 max_extents
.size
.y
- extents
->size
.y
) / 2 +
1185 shift
->y
+ limit_shift
->y
);
1187 cairo_matrix_init_translate(&map
, extents
->size
.x
+ limits_shift
->x
,
1188 -extents
->size
.y
/ 2 + limits_shift
->y
);
1190 if (min_entity
!= NULL
) {
1191 adg_entity_set_global_map(min_entity
, &map
);
1192 adg_entity_arrange(min_entity
);
1193 extents
= adg_entity_get_extents(min_entity
);
1194 map
.y0
-= extents
->size
.y
+
1195 adg_dim_style_get_limits_spacing(data
->dim_style
);
1198 if (max_entity
!= NULL
) {
1199 adg_entity_set_global_map(max_entity
, &map
);
1200 adg_entity_arrange(max_entity
);
1204 adg_entity_arrange(quote_entity
);
1208 default_value(AdgDim
*dim
)
1210 g_warning("AdgDim::default_value not implemented for `%s'",
1211 g_type_name(G_TYPE_FROM_INSTANCE(dim
)));
1212 return g_strdup("undef");
1216 quote_angle(gdouble angle
)
1218 angle
= cpml_angle(angle
);
1220 if (angle
> G_PI_4
* 4 / 3 || angle
<= -G_PI_4
* 3)
1221 angle
= cpml_angle(angle
+ G_PI
);
1227 set_dim_dress(AdgDim
*dim
, AdgDress dress
)
1229 AdgDimPrivate
*data
= dim
->data
;
1231 if (adg_dress_set(&data
->dim_dress
, dress
)) {
1232 data
->dim_style
= NULL
;
1240 set_outside(AdgDim
*dim
, AdgThreeState outside
)
1242 AdgDimPrivate
*data
;
1244 g_return_val_if_fail(adg_is_enum_value(outside
, ADG_TYPE_THREE_STATE
),
1249 if (data
->outside
== outside
)
1252 data
->outside
= outside
;
1258 set_detached(AdgDim
*dim
, AdgThreeState detached
)
1260 AdgDimPrivate
*data
;
1262 g_return_val_if_fail(adg_is_enum_value(detached
, ADG_TYPE_THREE_STATE
),
1267 if (data
->detached
== detached
)
1270 data
->detached
= detached
;
1276 set_value(AdgDim
*dim
, const gchar
*value
)
1278 AdgDimPrivate
*data
;
1282 if (adg_strcmp(value
, data
->value
) == 0)
1285 g_free(data
->value
);
1286 data
->value
= g_strdup(value
);
1288 if (data
->quote
.value
!= NULL
) {
1289 g_object_unref(data
->quote
.value
);
1290 data
->quote
.value
= NULL
;
1297 set_min(AdgDim
*dim
, const gchar
*min
)
1299 AdgDimPrivate
*data
= dim
->data
;
1301 if (adg_strcmp(min
, data
->min
) == 0)
1305 data
->min
= g_strdup(min
);
1307 if (data
->quote
.min
!= NULL
) {
1308 g_object_unref(data
->quote
.min
);
1309 data
->quote
.min
= NULL
;
1316 set_max(AdgDim
*dim
, const gchar
*max
)
1318 AdgDimPrivate
*data
= dim
->data
;
1320 if (adg_strcmp(max
, data
->max
) == 0)
1324 data
->max
= g_strdup(max
);
1326 if (data
->quote
.max
!= NULL
) {
1327 g_object_unref(data
->quote
.max
);
1328 data
->quote
.max
= NULL
;