[AdgDim] Changed "ref1", "ref2" and "pos" to AdgPoint
[adg.git] / adg / adg-ldim.c
blob599af920c218573599990b1b715dc2adc188b03d
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-ldim
23 * @short_description: Linear dimensions
25 * The #AdgLDim entity represents a linear dimension.
26 **/
28 /**
29 * AdgLDim:
31 * All fields are private and should not be used directly.
32 * Use its public methods instead.
33 **/
36 #include "adg-ldim.h"
37 #include "adg-ldim-private.h"
38 #include "adg-dim-private.h"
39 #include "adg-dim-style.h"
40 #include "adg-intl.h"
42 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_ldim_parent_class)
43 #define PARENT_ENTITY_CLASS ((AdgEntityClass *) adg_ldim_parent_class)
46 enum {
47 PROP_0,
48 PROP_DIRECTION,
49 PROP_HAS_EXTENSION1,
50 PROP_HAS_EXTENSION2
54 static void dispose (GObject *object);
55 static void get_property (GObject *object,
56 guint param_id,
57 GValue *value,
58 GParamSpec *pspec);
59 static void set_property (GObject *object,
60 guint param_id,
61 const GValue *value,
62 GParamSpec *pspec);
63 static void local_changed (AdgEntity *entity);
64 static void invalidate (AdgEntity *entity);
65 static void arrange (AdgEntity *entity);
66 static void render (AdgEntity *entity,
67 cairo_t *cr);
68 static gchar * default_value (AdgDim *dim);
69 static void update_geometry (AdgLDim *ldim);
70 static void update_shift (AdgLDim *ldim);
71 static void update_entities (AdgLDim *ldim);
72 static gboolean choose_outside (AdgLDim *ldim);
73 static void unset_trail (AdgLDim *ldim);
74 static void dispose_markers (AdgLDim *ldim);
75 static CpmlPath * trail_callback (AdgTrail *trail,
76 gpointer user_data);
79 G_DEFINE_TYPE(AdgLDim, adg_ldim, ADG_TYPE_DIM);
82 static void
83 adg_ldim_class_init(AdgLDimClass *klass)
85 GObjectClass *gobject_class;
86 AdgEntityClass *entity_class;
87 AdgDimClass *dim_class;
88 GParamSpec *param;
90 gobject_class = (GObjectClass *) klass;
91 entity_class = (AdgEntityClass *) klass;
92 dim_class = (AdgDimClass *) klass;
94 g_type_class_add_private(klass, sizeof(AdgLDimPrivate));
96 gobject_class->dispose = dispose;
97 gobject_class->get_property = get_property;
98 gobject_class->set_property = set_property;
100 entity_class->local_changed = local_changed;
101 entity_class->invalidate = invalidate;
102 entity_class->arrange = arrange;
103 entity_class->render = render;
105 dim_class->default_value = default_value;
107 param = g_param_spec_double("direction",
108 P_("Direction"),
109 P_("The inclination angle of the extension lines"),
110 -G_MAXDOUBLE, G_MAXDOUBLE, ADG_DIR_RIGHT,
111 G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
112 g_object_class_install_property(gobject_class, PROP_DIRECTION, param);
114 param = g_param_spec_boolean("has-extension1",
115 P_("Has First Extension Line flag"),
116 P_("Show (TRUE) or hide (FALSE) the first extension line"),
117 TRUE, G_PARAM_READWRITE);
118 g_object_class_install_property(gobject_class, PROP_HAS_EXTENSION1, param);
120 param = g_param_spec_boolean("has-extension2",
121 P_("Has Second Extension Line flag"),
122 P_("Show (TRUE) or hide (FALSE) the second extension line"),
123 TRUE, G_PARAM_READWRITE);
124 g_object_class_install_property(gobject_class, PROP_HAS_EXTENSION2, param);
127 static void
128 adg_ldim_init(AdgLDim *ldim)
130 AdgLDimPrivate *data;
131 cairo_path_data_t move_to, line_to;
133 data = G_TYPE_INSTANCE_GET_PRIVATE(ldim, ADG_TYPE_LDIM, AdgLDimPrivate);
134 move_to.header.type = CAIRO_PATH_MOVE_TO;
135 move_to.header.length = 2;
136 line_to.header.type = CAIRO_PATH_LINE_TO;
137 line_to.header.length = 2;
139 data->direction = 0;
140 data->has_extension1 = TRUE;
141 data->has_extension2 = TRUE;
143 data->cpml.path.status = CAIRO_STATUS_INVALID_PATH_DATA;
144 data->cpml.path.data = data->cpml.data;
145 data->cpml.path.num_data = G_N_ELEMENTS(data->cpml.data);
146 data->cpml.path.data[0] = move_to;
147 data->cpml.path.data[2] = line_to;
148 data->cpml.path.data[4] = move_to;
149 data->cpml.path.data[6] = line_to;
150 data->cpml.path.data[8] = move_to;
151 data->cpml.path.data[10] = line_to;
152 data->cpml.path.data[12] = move_to;
153 data->cpml.path.data[14] = line_to;
154 data->cpml.path.data[16] = move_to;
155 data->cpml.path.data[18] = line_to;
157 data->trail = NULL;
158 data->marker1 = NULL;
159 data->marker2 = NULL;
161 data->geometry.is_arranged = FALSE;
162 data->shift.is_arranged = FALSE;
164 ldim->data = data;
167 static void
168 dispose(GObject *object)
170 dispose_markers((AdgLDim *) object);
172 if (PARENT_OBJECT_CLASS->dispose != NULL)
173 PARENT_OBJECT_CLASS->dispose(object);
176 static void
177 get_property(GObject *object,
178 guint prop_id, GValue *value, GParamSpec *pspec)
180 AdgLDimPrivate *data = ((AdgLDim *) object)->data;
182 switch (prop_id) {
183 case PROP_DIRECTION:
184 g_value_set_double(value, data->direction);
185 break;
186 case PROP_HAS_EXTENSION1:
187 g_value_set_boolean(value, data->has_extension1);
188 break;
189 case PROP_HAS_EXTENSION2:
190 g_value_set_boolean(value, data->has_extension2);
191 break;
192 default:
193 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
194 break;
198 static void
199 set_property(GObject *object,
200 guint prop_id, const GValue *value, GParamSpec *pspec)
202 AdgLDimPrivate *data = ((AdgLDim *) object)->data;
204 switch (prop_id) {
205 case PROP_DIRECTION:
206 data->direction = g_value_get_double(value);
207 break;
208 case PROP_HAS_EXTENSION1:
209 data->has_extension1 = g_value_get_boolean(value);
210 break;
211 case PROP_HAS_EXTENSION2:
212 data->has_extension2 = g_value_get_boolean(value);
213 break;
214 default:
215 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
216 break;
222 * adg_ldim_new:
224 * Creates a new - undefined - linear dimension. You must, at least,
225 * define the reference points with adg_dim_set_ref(), the dimension
226 * direction with adg_ldim_set_direction() and the position reference
227 * using adg_dim_set_pos().
229 * Returns: the newly created linear dimension entity
231 AdgLDim *
232 adg_ldim_new(void)
234 return g_object_new(ADG_TYPE_LDIM, NULL);
238 * adg_ldim_new_full:
239 * @ref1: the first reference point
240 * @ref2: the second reference point
241 * @direction: angle where to extend the dimension
242 * @pos: the position reference
244 * Creates a new linear dimension, specifing all the needed properties in
245 * one shot.
247 * Returns: the newly created linear dimension entity
249 AdgLDim *
250 adg_ldim_new_full(const AdgPair *ref1, const AdgPair *ref2,
251 gdouble direction, const AdgPair *pos)
253 AdgLDim *ldim;
254 AdgDim *dim;
256 ldim = g_object_new(ADG_TYPE_LDIM, "direction", direction, NULL);
257 dim = (AdgDim *) ldim;
259 adg_dim_set_ref(dim, ref1, ref2);
260 adg_dim_set_pos(dim, pos);
262 return ldim;
266 * adg_ldim_new_full_explicit:
267 * @ref1_x: the x coordinate of the first reference point
268 * @ref1_y: the y coordinate of the first reference point
269 * @ref2_x: the x coordinate of the second reference point
270 * @ref2_y: the y coordinate of the second reference point
271 * @direction: angle where to extend the dimension
272 * @pos_x: the x coordinate of the position reference
273 * @pos_y: the y coordinate of the position reference
275 * Wrappes adg_ldim_new_full() with explicit values.
277 * Returns: the newly created linear dimension entity
279 AdgLDim *
280 adg_ldim_new_full_explicit(gdouble ref1_x, gdouble ref1_y,
281 gdouble ref2_x, gdouble ref2_y,
282 gdouble direction, gdouble pos_x, gdouble pos_y)
284 AdgPair ref1;
285 AdgPair ref2;
286 AdgPair pos;
288 ref1.x = ref1_x;
289 ref1.y = ref1_y;
290 ref2.x = ref2_x;
291 ref2.y = ref2_y;
292 pos.x = pos_x;
293 pos.y = pos_y;
295 return adg_ldim_new_full(&ref1, &ref2, direction, &pos);
299 * adg_ldim_get_direction:
300 * @ldim: an #AdgLDim entity
302 * Gets the direction where @ldim will extend.
304 * Returns: the direction angle in radians
306 gdouble
307 adg_ldim_get_direction(AdgLDim *ldim)
309 AdgLDimPrivate *data;
311 g_return_val_if_fail(ADG_IS_LDIM(ldim), 0);
313 data = ldim->data;
315 return data->direction;
319 * adg_ldim_set_direction:
320 * @ldim: an #AdgLDim entity
321 * @direction: an angle value, in radians
323 * Sets the direction angle where to extend @ldim.
325 void
326 adg_ldim_set_direction(AdgLDim *ldim, gdouble direction)
328 AdgLDimPrivate *data;
330 g_return_if_fail(ADG_IS_LDIM(ldim));
332 data = ldim->data;
333 data->direction = direction;
335 g_object_notify((GObject *) ldim, "direction");
339 * adg_ldim_has_extension1:
340 * @ldim: an #AdgLDim entity
342 * Checks if @ldim should render also the first extension line.
344 * Returns: %TRUE on first extension line presents, %FALSE otherwise
346 gboolean
347 adg_ldim_has_extension1(AdgLDim *ldim)
349 AdgLDimPrivate *data;
351 g_return_val_if_fail(ADG_IS_LDIM(ldim), FALSE);
353 data = ldim->data;
355 return data->has_extension1;
359 * adg_ldim_switch_extension1:
360 * @ldim: an #AdgLDim entity
361 * @state: the new state
363 * Shows (if @state is %TRUE) or hide (if @state is %FALSE) the first
364 * extension line of @ldim.
366 void
367 adg_ldim_switch_extension1(AdgLDim *ldim, gboolean state)
369 AdgLDimPrivate *data;
371 g_return_if_fail(ADG_IS_LDIM(ldim));
373 data = ldim->data;
375 data->has_extension1 = state;
376 g_object_notify((GObject *) ldim, "has-extension1");
380 * adg_ldim_has_extension2:
381 * @ldim: an #AdgLDim entity
383 * Checks if @ldim should render also the second extension line.
385 * Returns: %TRUE on first extension line presents, %FALSE otherwise
387 gboolean
388 adg_ldim_has_extension2(AdgLDim *ldim)
390 AdgLDimPrivate *data;
392 g_return_val_if_fail(ADG_IS_LDIM(ldim), FALSE);
394 data = ldim->data;
396 return data->has_extension2;
400 * adg_ldim_switch_extension2:
401 * @ldim: an #AdgLDim entity
402 * @state: the new state
404 * Shows (if @state is %TRUE) or hide (if @state is %FALSE) the second
405 * extension line of @ldim.
407 void
408 adg_ldim_switch_extension2(AdgLDim *ldim, gboolean state)
410 AdgLDimPrivate *data;
412 g_return_if_fail(ADG_IS_LDIM(ldim));
414 data = ldim->data;
416 data->has_extension2 = state;
417 g_object_notify((GObject *) ldim, "has-extension2");
421 static void
422 local_changed(AdgEntity *entity)
424 unset_trail((AdgLDim *) entity);
426 PARENT_ENTITY_CLASS->local_changed(entity);
429 static void
430 invalidate(AdgEntity *entity)
432 AdgLDim *ldim;
433 AdgLDimPrivate *data;
435 ldim = (AdgLDim *) entity;
436 data = ldim->data;
438 dispose_markers(ldim);
439 data->geometry.is_arranged = FALSE;
440 data->shift.is_arranged = FALSE;
441 unset_trail(ldim);
443 if (PARENT_ENTITY_CLASS->invalidate != NULL)
444 PARENT_ENTITY_CLASS->invalidate(entity);
447 static void
448 arrange(AdgEntity *entity)
450 AdgLDim *ldim;
451 AdgDim *dim;
452 AdgLDimPrivate *data;
453 AdgContainer *quote;
454 AdgDimStyle *dim_style;
455 gboolean outside;
456 const AdgMatrix *local;
457 AdgPair ref1, ref2, base1, base2;
458 AdgPair pair;
459 gint n;
461 PARENT_ENTITY_CLASS->arrange(entity);
463 ldim = (AdgLDim *) entity;
464 dim = (AdgDim *) ldim;
465 data = ldim->data;
466 quote = adg_dim_get_quote(dim);
468 update_geometry(ldim);
469 update_shift(ldim);
470 update_entities(ldim);
472 if (data->cpml.path.status == CAIRO_STATUS_SUCCESS) {
473 AdgEntity *quote_entity = (AdgEntity *) quote;
474 adg_entity_set_global_map(quote_entity, &data->quote.global_map);
475 adg_entity_set_local_map(quote_entity, &data->quote.local_map);
476 return;
479 dim_style = GET_DIM_STYLE(dim);
481 switch (adg_dim_get_outside(dim)) {
482 case ADG_THREE_STATE_OFF:
483 outside = FALSE;
484 break;
485 case ADG_THREE_STATE_ON:
486 outside = TRUE;
487 break;
488 case ADG_THREE_STATE_UNKNOWN:
489 default:
490 outside = choose_outside(ldim);
491 break;
494 local = adg_entity_local_matrix(entity);
495 cpml_pair_copy(&ref1, adg_dim_get_ref1(dim));
496 cpml_pair_copy(&ref2, adg_dim_get_ref2(dim));
497 cpml_pair_copy(&base1, &data->geometry.base1);
498 cpml_pair_copy(&base2, &data->geometry.base2);
500 cpml_pair_transform(&ref1, local);
501 cpml_pair_transform(&ref2, local);
502 cpml_pair_transform(&base1, local);
503 cpml_pair_transform(&base2, local);
505 cpml_pair_add(cpml_pair_copy(&pair, &ref1), &data->shift.from);
506 cpml_pair_to_cairo(&pair, &data->cpml.data[13]);
508 cpml_pair_copy(&pair, &base1);
509 cpml_pair_add(&pair, &data->shift.base);
510 cpml_pair_to_cairo(&pair, &data->cpml.data[1]);
512 cpml_pair_add(&pair, &data->shift.to);
513 cpml_pair_to_cairo(&pair, &data->cpml.data[15]);
515 cpml_pair_add(cpml_pair_copy(&pair, &ref2), &data->shift.from);
516 cpml_pair_to_cairo(&pair, &data->cpml.data[17]);
518 cpml_pair_copy(&pair, &base2);
519 cpml_pair_add(&pair, &data->shift.base);
520 cpml_pair_to_cairo(&pair, &data->cpml.data[3]);
522 cpml_pair_add(&pair, &data->shift.to);
523 cpml_pair_to_cairo(&pair, &data->cpml.data[19]);
525 /* Calculate the outside segments */
526 if (outside) {
527 gdouble beyond;
528 CpmlVector vector;
530 beyond = adg_dim_style_get_beyond(dim_style);
531 cpml_pair_from_cairo(&pair, &data->cpml.data[1]);
533 cpml_pair_from_cairo(&vector, &data->cpml.data[3]);
534 cpml_pair_sub(&vector, &pair);
535 cpml_vector_set_length(&vector, beyond);
537 cpml_pair_from_cairo(&pair, &data->cpml.data[1]);
538 cpml_pair_to_cairo(&pair, &data->cpml.data[5]);
540 cpml_pair_sub(&pair, &vector);
541 cpml_pair_to_cairo(&pair, &data->cpml.data[7]);
543 cpml_pair_from_cairo(&pair, &data->cpml.data[3]);
544 cpml_pair_to_cairo(&pair, &data->cpml.data[11]);
546 cpml_pair_add(&pair, &vector);
547 cpml_pair_to_cairo(&pair, &data->cpml.data[9]);
549 data->cpml.data[2].header.length = 2;
550 data->cpml.data[10].header.length = 2;
551 n = 10;
552 } else {
553 data->cpml.data[2].header.length = 10;
554 n = 2;
557 /* Play with header lengths to show or hide the extension lines */
558 if (data->has_extension1) {
559 data->cpml.data[14].header.length = data->has_extension2 ? 2 : 6;
560 } else {
561 data->cpml.data[n].header.length += 4;
562 if (!data->has_extension2)
563 data->cpml.data[n].header.length += 4;
566 data->cpml.path.status = CAIRO_STATUS_SUCCESS;
568 if (quote != NULL) {
569 /* Update global and local map of the quote container */
570 AdgEntity *quote_entity;
571 gdouble angle;
572 AdgMatrix matrix;
574 quote_entity = (AdgEntity *) quote;
575 angle = adg_dim_quote_angle(dim, data->direction + G_PI_2);
576 adg_matrix_copy(&matrix, local);
577 cairo_matrix_invert(&matrix);
579 pair.x = (data->cpml.data[1].point.x + data->cpml.data[3].point.x) / 2;
580 pair.y = (data->cpml.data[1].point.y + data->cpml.data[3].point.y) / 2;
581 cairo_matrix_transform_point(&matrix, &pair.x, &pair.y);
582 cairo_matrix_init_translate(&matrix, pair.x, pair.y);
583 adg_entity_set_local_map(quote_entity, &matrix);
585 cairo_matrix_init_rotate(&matrix, angle);
586 adg_entity_transform_global_map(quote_entity, &matrix, ADG_TRANSFORM_BEFORE);
588 adg_entity_get_global_map(quote_entity, &data->quote.global_map);
589 adg_entity_get_local_map(quote_entity, &data->quote.local_map);
592 if (data->marker1 != NULL) {
593 adg_marker_set_segment(data->marker1, data->trail, outside ? 2 : 1);
594 adg_entity_local_changed((AdgEntity *) data->marker1);
597 if (data->marker2 != NULL) {
598 adg_marker_set_segment(data->marker2, data->trail, outside ? 3 : 1);
599 adg_entity_local_changed((AdgEntity *) data->marker2);
602 /* TODO: compute the extents */
605 static void
606 render(AdgEntity *entity, cairo_t *cr)
608 AdgLDim *ldim;
609 AdgDim *dim;
610 AdgLDimPrivate *data;
611 AdgDimStyle *dim_style;
612 AdgDress dress;
613 const cairo_path_t *cairo_path;
615 ldim = (AdgLDim *) entity;
616 dim = (AdgDim *) entity;
617 data = ldim->data;
618 dim_style = GET_DIM_STYLE(dim);
620 adg_style_apply((AdgStyle *) dim_style, entity, cr);
622 if (data->marker1 != NULL)
623 adg_entity_render((AdgEntity *) data->marker1, cr);
625 if (data->marker2 != NULL)
626 adg_entity_render((AdgEntity *) data->marker2, cr);
628 adg_entity_render((AdgEntity *) adg_dim_get_quote(dim), cr);
630 dress = adg_dim_style_get_line_dress(dim_style);
631 adg_entity_apply_dress(entity, dress, cr);
633 cairo_path = adg_trail_get_cairo_path(data->trail);
634 cairo_append_path(cr, cairo_path);
635 cairo_stroke(cr);
638 static gchar *
639 default_value(AdgDim *dim)
641 AdgLDim *ldim;
642 AdgLDimPrivate *data;
643 AdgDimStyle *dim_style;
644 const gchar *format;
646 ldim = (AdgLDim *) dim;
647 data = ldim->data;
648 dim_style = GET_DIM_STYLE(dim);
649 format = adg_dim_style_get_number_format(dim_style);
651 update_geometry(ldim);
653 return g_strdup_printf(format, data->geometry.distance);
656 static void
657 update_geometry(AdgLDim *ldim)
659 AdgLDimPrivate *data;
660 AdgDim *dim;
661 const AdgPair *ref1, *ref2;
662 const AdgPair *pos;
663 CpmlVector baseline, extension;
664 gdouble d, k;
666 data = ldim->data;
668 if (data->geometry.is_arranged)
669 return;
671 dim = (AdgDim *) ldim;
672 ref1 = adg_dim_get_ref1(dim);
673 ref2 = adg_dim_get_ref2(dim);
674 pos = adg_dim_get_pos(dim);
675 cpml_vector_from_angle(&extension, data->direction);
676 cpml_pair_copy(&baseline, &extension);
677 cpml_vector_normal(&baseline);
679 d = extension.y * baseline.x -
680 extension.x * baseline.y;
681 g_return_if_fail(d != 0);
683 k = ((pos->y - ref1->y) * baseline.x -
684 (pos->x - ref1->x) * baseline.y) / d;
685 data->geometry.base1.x = ref1->x + k * extension.x;
686 data->geometry.base1.y = ref1->y + k * extension.y;
688 k = ((pos->y - ref2->y) * baseline.x -
689 (pos->x - ref2->x) * baseline.y) / d;
690 data->geometry.base2.x = ref2->x + k * extension.x;
691 data->geometry.base2.y = ref2->y + k * extension.y;
693 data->geometry.distance = cpml_pair_distance(&data->geometry.base1,
694 &data->geometry.base2);
696 data->geometry.is_arranged = TRUE;
699 static void
700 update_shift(AdgLDim *ldim)
702 AdgLDimPrivate *data;
703 AdgDimStyle *dim_style;
704 gdouble from_offset, to_offset;
705 gdouble baseline_spacing, level;
706 CpmlVector vector;
708 data = ldim->data;
710 if (data->shift.is_arranged)
711 return;
713 dim_style = GET_DIM_STYLE(ldim);
714 from_offset = adg_dim_style_get_from_offset(dim_style);
715 to_offset = adg_dim_style_get_to_offset(dim_style);
716 baseline_spacing = adg_dim_style_get_baseline_spacing(dim_style);
717 level = adg_dim_get_level((AdgDim *) ldim);
719 cpml_vector_from_angle(&vector, data->direction);
721 cpml_vector_set_length(&vector, from_offset);
722 cpml_pair_copy(&data->shift.from, &vector);
724 cpml_vector_set_length(&vector, to_offset);
725 cpml_pair_copy(&data->shift.to, &vector);
727 cpml_vector_set_length(&vector, level * baseline_spacing);
728 cpml_pair_copy(&data->shift.base, &vector);
730 data->shift.is_arranged = TRUE;
733 static void
734 update_entities(AdgLDim *ldim)
736 AdgLDimPrivate *data;
737 AdgDimStyle *dim_style;
739 data = ldim->data;
740 dim_style = GET_DIM_STYLE(ldim);
742 if (data->trail == NULL)
743 data->trail = adg_trail_new(trail_callback, ldim);
745 if (data->marker1 == NULL)
746 data->marker1 = adg_dim_style_marker1_new(dim_style);
748 if (data->marker2 == NULL)
749 data->marker2 = adg_dim_style_marker2_new(dim_style);
752 static gboolean
753 choose_outside(AdgLDim *ldim)
755 AdgLDimPrivate *data;
756 AdgContainer *quote;
757 const AdgMatrix *local;
758 CpmlExtents extents;
759 gdouble marker1, marker2;
760 gdouble needed, available;
762 data = ldim->data;
763 quote = adg_dim_get_quote((AdgDim *) ldim);
764 local = adg_entity_local_matrix((AdgEntity *) ldim);
765 adg_entity_get_extents((AdgEntity *) quote, &extents);
766 marker1 = data->marker1 == NULL ? 0 : adg_marker_get_size(data->marker1);
767 marker2 = data->marker2 == NULL ? 0 : adg_marker_get_size(data->marker2);
769 needed = extents.size.x + marker1 + marker2;
770 available = data->geometry.distance * local->xx;
772 return needed > available;
775 static void
776 unset_trail(AdgLDim *ldim)
778 AdgLDimPrivate *data = ldim->data;
780 if (data->trail != NULL)
781 adg_model_clear((AdgModel *) data->trail);
783 data->cpml.path.status = CAIRO_STATUS_INVALID_PATH_DATA;
786 static void
787 dispose_markers(AdgLDim *ldim)
789 AdgLDimPrivate *data = ldim->data;
791 if (data->trail != NULL) {
792 g_object_unref(data->trail);
793 data->trail = NULL;
796 if (data->marker1 != NULL) {
797 g_object_unref(data->marker1);
798 data->marker1 = NULL;
801 if (data->marker2 != NULL) {
802 g_object_unref(data->marker2);
803 data->marker2 = NULL;
807 static CpmlPath *
808 trail_callback(AdgTrail *trail, gpointer user_data)
810 AdgLDim *ldim;
811 AdgLDimPrivate *data;
813 ldim = (AdgLDim *) user_data;
814 data = ldim->data;
816 return &data->cpml.path;