7 static AdgCanvas
* sample_canvas (void);
8 static AdgCanvas
* operations_canvas (void);
9 static AdgCanvas
* mapping_canvas (void);
10 static void to_pdf (AdgWidget
*widget
,
12 static void to_png (AdgWidget
*widget
,
14 static void to_ps (AdgWidget
*widget
,
19 main(gint argc
, gchar
**argv
)
26 GtkWidget
*operations
;
29 gtk_init(&argc
, &argv
);
31 path
= demo_find_data_file("adg-demo.ui");
33 g_print("adg-demo.ui not found!\n");
37 builder
= gtk_builder_new();
40 gtk_builder_add_from_file(builder
, path
, &error
);
42 g_print("%s\n", error
->message
);
46 window
= (GtkWidget
*) gtk_builder_get_object(builder
, "wndMain");
48 sample
= (GtkWidget
*) gtk_builder_get_object(builder
, "areaSample");
49 adg_widget_set_canvas(ADG_WIDGET(sample
), sample_canvas());
51 operations
= (GtkWidget
*) gtk_builder_get_object(builder
, "areaOperations");
52 adg_widget_set_canvas(ADG_WIDGET(operations
), operations_canvas());
54 mapping
= (GtkWidget
*) gtk_builder_get_object(builder
, "areaMapping");
55 adg_widget_set_canvas(ADG_WIDGET(mapping
), mapping_canvas());
58 g_signal_connect(window
, "delete-event",
59 G_CALLBACK(gtk_main_quit
), NULL
);
60 g_signal_connect(gtk_builder_get_object(builder
, "btnQuit"),
61 "clicked", G_CALLBACK(gtk_main_quit
), NULL
);
62 g_signal_connect_swapped(gtk_builder_get_object(builder
, "btnPng"),
63 "clicked", G_CALLBACK(to_png
), sample
);
64 g_signal_connect_swapped(gtk_builder_get_object(builder
, "btnPdf"),
65 "clicked", G_CALLBACK(to_pdf
), sample
);
66 g_signal_connect_swapped(gtk_builder_get_object(builder
, "btnPs"),
67 "clicked", G_CALLBACK(to_ps
), sample
);
69 g_object_unref(builder
);
71 gtk_widget_show_all(window
);
78 static AdgPath
* non_trivial_model (void);
81 /**********************************************
82 * A sample mechanical part example
83 **********************************************/
85 #define SQRT3 1.732050808
88 typedef struct _SampleData SampleData
;
92 gdouble D1
, D2
, D3
, D4
, D5
, D6
, D7
;
94 gdouble LD2
, LD3
, LD5
, LD6
, LD7
;
97 static void sample_get (SampleData
*data
);
98 static AdgPath
*sample_path (const SampleData
*data
);
99 static void sample_add_dimensions (AdgCanvas
*canvas
,
101 const SampleData
*data
);
102 static void sample_add_stuff (AdgCanvas
*canvas
,
103 const SampleData
*data
);
104 static void reverse_pair (const gchar
*name
,
114 AdgContainer
*container
;
115 AdgTrail
*shape
, *edges
;
120 canvas
= adg_canvas_new();
121 container
= (AdgContainer
*) canvas
;
122 shape
= ADG_TRAIL(sample_path(&data
));
123 edges
= ADG_TRAIL(adg_edges_new_with_source(shape
));
125 entity
= ADG_ENTITY(adg_stroke_new(shape
));
126 adg_container_add(container
, entity
);
128 entity
= ADG_ENTITY(adg_hatch_new(shape
));
129 adg_container_add(container
, entity
);
131 entity
= ADG_ENTITY(adg_stroke_new(edges
));
132 adg_container_add(container
, entity
);
134 sample_add_dimensions(canvas
, ADG_MODEL(shape
), &data
);
135 sample_add_stuff(canvas
, &data
);
137 cairo_matrix_init_translate(&map
, 100, 70);
138 cairo_matrix_scale(&map
, 6.883, 6.883);
139 cairo_matrix_translate(&map
, 0, 10);
140 adg_entity_set_local_map(ADG_ENTITY(container
), &map
);
146 sample_get(SampleData
*data
)
167 sample_path(const SampleData
*data
)
173 AdgSegment
*dup_segment
;
174 const AdgPrimitive
*primitive
;
175 cairo_matrix_t matrix
;
177 path
= adg_path_new();
178 model
= ADG_MODEL(path
);
181 pair
.y
= data
->D1
/ 2;
182 adg_path_move_to(path
, pair
.x
, pair
.y
);
183 adg_model_set_named_pair(model
, "D1I", &pair
);
185 pair
.x
= data
->A
- data
->B
- data
->LD2
;
186 adg_path_line_to(path
, pair
.x
, pair
.y
);
187 adg_model_set_named_pair(model
, "D1F", &pair
);
189 pair
.x
+= (data
->D1
- data
->D2
) * SQRT3
/ 2;
190 pair
.y
-= (data
->D1
- data
->D2
) / 2;
191 adg_path_line_to(path
, pair
.x
, pair
.y
);
192 adg_model_set_named_pair(model
, "D2I", &pair
);
194 adg_path_line_to(path
, data
->A
- data
->B
, data
->D2
/ 2);
195 adg_path_fillet(path
, 0.4);
197 pair
.x
= data
->A
- data
->B
;
198 pair
.y
= data
->D3
/ 2;
199 adg_path_line_to(path
, pair
.x
, pair
.y
);
200 adg_model_set_named_pair(model
, "D3I", &pair
);
202 adg_path_chamfer(path
, CHAMFER
, CHAMFER
);
204 pair
.x
= data
->A
- data
->B
+ data
->LD3
;
205 pair
.y
= data
->D3
/ 2;
206 adg_path_line_to(path
, pair
.x
, pair
.y
);
208 primitive
= adg_path_over_primitive(path
);
209 cpml_pair_from_cairo(&pair
, cpml_primitive_get_point(primitive
, 0));
210 adg_model_set_named_pair(model
, "D3I_X", &pair
);
212 adg_path_chamfer(path
, CHAMFER
, CHAMFER
);
213 adg_path_line_to(path
, data
->A
- data
->B
+ data
->LD3
, data
->D4
/ 2);
215 primitive
= adg_path_over_primitive(path
);
216 cpml_pair_from_cairo(&pair
, cpml_primitive_get_point(primitive
, 0));
217 adg_model_set_named_pair(model
, "D3F_Y", &pair
);
218 cpml_pair_from_cairo(&pair
, cpml_primitive_get_point(primitive
, -1));
219 adg_model_set_named_pair(model
, "D3F_X", &pair
);
221 adg_path_fillet(path
, data
->RD34
);
223 pair
.x
= data
->A
- data
->C
- data
->LD5
;
224 pair
.y
= data
->D4
/ 2;
225 adg_path_line_to(path
, pair
.x
, pair
.y
);
226 adg_model_set_named_pair(model
, "D4F", &pair
);
228 pair
.y
= (data
->D4
- data
->D5
) / 2;
229 adg_path_line_to(path
, data
->A
- data
->C
- data
->LD5
+ pair
.y
, data
->D4
/ 2 - pair
.y
);
230 adg_path_line_to(path
, data
->A
- data
->C
, data
->D5
/ 2);
232 adg_path_fillet(path
, 0.2);
234 adg_path_line_to(path
, data
->A
- data
->C
, data
->D6
/ 2);
236 primitive
= adg_path_over_primitive(path
);
237 cpml_pair_from_cairo(&pair
, cpml_primitive_get_point(primitive
, 0));
238 adg_model_set_named_pair(model
, "D5F", &pair
);
240 adg_path_fillet(path
, 0.1);
242 pair
.x
= data
->A
- data
->C
+ data
->LD6
;
243 pair
.y
= data
->D6
/ 2;
244 adg_path_line_to(path
, pair
.x
, pair
.y
);
245 adg_model_set_named_pair(model
, "D6F", &pair
);
247 primitive
= adg_path_over_primitive(path
);
248 cpml_pair_from_cairo(&pair
, cpml_primitive_get_point(primitive
, -1));
249 adg_model_set_named_pair(model
, "D6I_Y", &pair
);
251 pair
.x
= data
->A
- data
->LD7
;
252 pair
.y
= data
->D6
/ 2 - (data
->C
- data
->LD7
- data
->LD6
) / SQRT3
;
253 adg_path_line_to(path
, pair
.x
, pair
.y
);
254 adg_model_set_named_pair(model
, "D67", &pair
);
256 adg_path_line_to(path
, data
->A
- data
->LD7
, data
->D7
/ 2);
259 pair
.y
= data
->D7
/ 2;
260 adg_path_line_to(path
, pair
.x
, pair
.y
);
261 adg_model_set_named_pair(model
, "D7F", &pair
);
263 /* Reflect the shape by duplicating the first segment of
264 * the current path, applying a -1 y scale (that is
265 * mirroring it on the y=0 axis), reversing the resulting
266 * path and appending it to the original one */
267 adg_trail_get_segment(ADG_TRAIL(path
), &segment
, 1);
268 dup_segment
= adg_segment_deep_dup(&segment
);
269 cpml_segment_reverse(dup_segment
);
270 cairo_matrix_init(&matrix
, 1, 0, 0, -1, 0, 0);
271 cpml_segment_transform(dup_segment
, &matrix
);
272 dup_segment
->data
[0].header
.type
= CAIRO_PATH_LINE_TO
;
274 adg_path_append_segment(path
, dup_segment
);
278 adg_model_foreach_named_pair(model
, (AdgNamedPairCallback
) reverse_pair
,
281 adg_path_close(path
);
286 sample_add_dimensions(AdgCanvas
*canvas
, AdgModel
*model
,
287 const SampleData
*data
)
296 ldim
= adg_ldim_new_full_from_model(model
, "-D1F", "-D3I_X", "-D3F_Y",
298 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(ldim
));
300 ldim
= adg_ldim_new_full_from_model(model
, "-D3I_X", "-D3F_X", "-D3F_Y",
302 adg_ldim_switch_extension1(ldim
, FALSE
);
303 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(ldim
));
307 ldim
= adg_ldim_new_full_from_model(model
, "D3I_X", "D7F", "D3F_Y",
309 adg_dim_set_limits(ADG_DIM(ldim
), NULL
, "+0.1");
310 adg_ldim_switch_extension2(ldim
, FALSE
);
311 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(ldim
));
313 ldim
= adg_ldim_new_full_from_model(model
, "D1I", "D7F", "D3F_Y",
315 adg_dim_set_limits(ADG_DIM(ldim
), "-0.05", "+0.05");
316 adg_dim_set_level(ADG_DIM(ldim
), 2);
317 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(ldim
));
320 adim
= adg_adim_new_full_from_model(model
, "D6F", "D6I_Y", "D67",
322 adg_dim_set_level(ADG_DIM(adim
), 2);
323 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(adim
));
326 x
= data
->A
- data
->B
+ data
->LD3
+ data
->RD34
;
327 y
= data
->D4
/ 2 + data
->RD34
;
328 rdim
= adg_rdim_new_full_explicit(x
, y
,
329 x
- cos(G_PI_4
) * data
->RD34
,
330 y
- sin(G_PI_4
) * data
->RD34
,
331 x
+ cos(G_PI_4
) * data
->RD34
,
332 y
+ sin(G_PI_4
) * data
->RD34
);
333 adg_dim_set_level(ADG_DIM(rdim
), 1);
334 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(rdim
));
338 ldim
= adg_ldim_new_full_from_model(model
, "D3F_Y", "-D3F_Y", "D7F",
340 adg_dim_set_limits(ADG_DIM(ldim
), "-0.25", NULL
);
341 adg_dim_set_level(ADG_DIM(ldim
), 5);
342 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(ldim
));
344 ldim
= adg_ldim_new_full_from_model(model
, "D6F", "-D6F", "D7F",
346 adg_dim_set_limits(ADG_DIM(ldim
), "-0.1", NULL
);
347 adg_dim_set_level(ADG_DIM(ldim
), 4);
348 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(ldim
));
350 ldim
= adg_ldim_new_full_from_model(model
, "D4F", "-D4F", "D7F",
352 adg_dim_set_level(ADG_DIM(ldim
), 3);
353 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(ldim
));
355 ldim
= adg_ldim_new_full_from_model(model
, "D5F", "-D5F", "D7F",
357 adg_dim_set_limits(ADG_DIM(ldim
), "-0.1", NULL
);
358 adg_dim_set_level(ADG_DIM(ldim
), 2);
359 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(ldim
));
361 ldim
= adg_ldim_new_full_from_model(model
, "D7F", "-D7F", "D7F",
363 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(ldim
));
367 ldim
= adg_ldim_new_full_from_model(model
, "D1I", "-D1I", "D1I",
369 adg_dim_set_limits(ADG_DIM(ldim
), "+0.05", "-0.05");
370 adg_dim_set_level(ADG_DIM(ldim
), 2);
371 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(ldim
));
373 ldim
= adg_ldim_new_full_from_model(model
, "D2I", "-D2I", "D1I",
375 adg_dim_set_limits(ADG_DIM(ldim
), "-0.1", NULL
);
376 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(ldim
));
380 sample_add_stuff(AdgCanvas
*canvas
, const SampleData
*data
)
382 AdgToyText
*toy_text
;
385 toy_text
= adg_toy_text_new("Rotate the mouse wheel to zoom in and out");
386 cairo_matrix_init_translate(&map
, 0, data
->D3
/ 2);
387 adg_entity_set_local_map(ADG_ENTITY(toy_text
), &map
);
388 cairo_matrix_translate(&map
, 10, 30 + 30 * 2);
389 adg_entity_set_global_map(ADG_ENTITY(toy_text
), &map
);
390 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(toy_text
));
392 toy_text
= adg_toy_text_new("Keep the wheel pressed while dragging the mouse to translate");
393 cairo_matrix_init_translate(&map
, 0, data
->D3
/ 2);
394 adg_entity_set_local_map(ADG_ENTITY(toy_text
), &map
);
395 cairo_matrix_init_translate(&map
, 10, 50 + 30 * 2);
396 adg_entity_set_global_map(ADG_ENTITY(toy_text
), &map
);
397 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(toy_text
));
401 #if defined(CAIRO_HAS_PNG_FUNCTIONS) || defined(CAIRO_HAS_PDF_SURFACE) || defined(CAIRO_HAS_PS_SURFACE)
403 /* Only needed if there is at least one supported surface */
405 file_generated(GtkWidget
*caller
, const gchar
*file
)
410 window
= (GtkWindow
*) gtk_widget_get_toplevel(caller
);
411 dialog
= gtk_message_dialog_new_with_markup(window
, GTK_DIALOG_MODAL
,
414 "The requested operation generated\n"
415 "<b>%s</b> in the current directory.",
417 gtk_window_set_title(GTK_WINDOW(dialog
), "Operation completed");
418 gtk_dialog_run(GTK_DIALOG(dialog
));
419 gtk_widget_destroy(dialog
);
424 #if !defined(CAIRO_HAS_PNG_FUNCTIONS) || !defined(CAIRO_HAS_PDF_SURFACE) || !defined(CAIRO_HAS_PS_SURFACE)
426 /* Only needed if there is a missing surface */
428 missing_feature(GtkWidget
*caller
, const gchar
*feature
)
433 window
= (GtkWindow
*) gtk_widget_get_toplevel(caller
);
434 dialog
= gtk_message_dialog_new(window
, GTK_DIALOG_MODAL
,
437 "The provided cairo library\n"
438 "was compiled with no %s support!",
440 gtk_window_set_title(GTK_WINDOW(dialog
), "Missing feature");
441 gtk_dialog_run(GTK_DIALOG(dialog
));
442 gtk_widget_destroy(dialog
);
448 #ifdef CAIRO_HAS_PNG_FUNCTIONS
451 to_png(AdgWidget
*widget
, GtkWidget
*caller
)
453 cairo_surface_t
*surface
;
456 surface
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32
, 800, 600);
457 cr
= cairo_create(surface
);
458 cairo_surface_destroy(surface
);
460 /* Rendering process */
461 adg_entity_render(ADG_ENTITY(adg_widget_get_canvas(widget
)), cr
);
464 cairo_surface_write_to_png(surface
, "test.png");
467 file_generated(caller
, "test.png");
473 to_png(AdgWidget
*widget
, GtkWidget
*caller
)
475 missing_feature(caller
, "PNG");
480 #ifdef CAIRO_HAS_PDF_SURFACE
482 #include <cairo-pdf.h>
485 to_pdf(AdgWidget
*widget
, GtkWidget
*caller
)
487 cairo_surface_t
*surface
;
490 surface
= cairo_pdf_surface_create("test.pdf", 841, 595);
491 cr
= cairo_create(surface
);
492 cairo_surface_destroy(surface
);
494 adg_entity_render(ADG_ENTITY(adg_widget_get_canvas(widget
)), cr
);
499 file_generated(caller
, "test.pdf");
505 to_pdf(AdgWidget
*widget
, GtkWidget
*caller
)
507 missing_feature(caller
, "PDF");
512 #ifdef CAIRO_HAS_PS_SURFACE
514 #include <cairo-ps.h>
517 to_ps(AdgWidget
*widget
, GtkWidget
*caller
)
519 cairo_surface_t
*surface
;
522 /* Surface creation: A4 size */
523 surface
= cairo_ps_surface_create("test.ps", 841, 595);
524 cairo_ps_surface_dsc_comment(surface
,
525 "%%Title: Automatic Drawing Generation (ADG) demo");
526 cairo_ps_surface_dsc_comment(surface
,
527 "%%Copyright: Copyright (C) 2006-2009 Fontana Nicola");
528 cairo_ps_surface_dsc_comment(surface
, "%%Orientation: Portrait");
530 cairo_ps_surface_dsc_begin_setup(surface
);
532 cairo_ps_surface_dsc_begin_page_setup(surface
);
533 cairo_ps_surface_dsc_comment(surface
,
534 "%%IncludeFeature: *PageSize A4");
536 cr
= cairo_create(surface
);
537 cairo_surface_destroy(surface
);
539 adg_entity_render(ADG_ENTITY(adg_widget_get_canvas(widget
)), cr
);
544 file_generated(caller
, "test.ps");
550 to_ps(AdgWidget
*widget
, GtkWidget
*caller
)
552 missing_feature(caller
, "PostScript");
558 /**********************************************
559 * Test case for basic operations,
560 * such as chamfer and fillet
561 **********************************************/
563 static AdgPath
* operations_chamfer (const AdgPath
*path
,
566 static AdgPath
* operations_fillet (const AdgPath
*path
,
570 operations_canvas(void)
572 AdgPath
*path
, *chamfer_path
, *fillet_path
;
574 AdgContainer
*container
;
578 path
= non_trivial_model();
579 chamfer_path
= operations_chamfer(path
, 0.25, 0.25);
580 fillet_path
= operations_fillet(path
, 0.20);
581 canvas
= adg_canvas_new();
583 /* Add the original shape */
584 container
= adg_container_new();
585 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(container
));
587 entity
= ADG_ENTITY(adg_stroke_new(ADG_TRAIL(path
)));
588 adg_container_add(container
, entity
);
590 entity
= ADG_ENTITY(adg_toy_text_new("Original shape"));
591 cairo_matrix_init_translate(&map
, 5, 10);
592 adg_entity_set_local_map(entity
, &map
);
593 cairo_matrix_init_translate(&map
, -50, 20);
594 adg_entity_set_global_map(entity
, &map
);
595 adg_container_add(ADG_CONTAINER(canvas
), entity
);
597 /* Add the shape with 0.25x0.25 chamfer */
598 container
= adg_container_new();
599 cairo_matrix_init_translate(&map
, 15, 0);
600 adg_entity_set_local_map(ADG_ENTITY(container
), &map
);
601 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(container
));
603 entity
= ADG_ENTITY(adg_stroke_new(ADG_TRAIL(chamfer_path
)));
604 adg_container_add(container
, entity
);
606 entity
= ADG_ENTITY(adg_toy_text_new("Shape with 0.25x0.25 chamfer"));
607 cairo_matrix_init_translate(&map
, 5, 10);
608 adg_entity_set_local_map(entity
, &map
);
609 cairo_matrix_init_translate(&map
, -120, 20);
610 adg_entity_set_global_map(entity
, &map
);
611 adg_container_add(container
, entity
);
613 /* Add the shape with fillets with 0.20 of radius */
614 container
= adg_container_new();
615 cairo_matrix_init_translate(&map
, 30, 0);
616 adg_entity_set_local_map(ADG_ENTITY(container
), &map
);
617 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(container
));
619 entity
= ADG_ENTITY(adg_stroke_new(ADG_TRAIL(fillet_path
)));
620 adg_container_add(container
, entity
);
622 entity
= ADG_ENTITY(adg_toy_text_new("Shape with R=20 fillet"));
623 cairo_matrix_init_translate(&map
, 5, 10);
624 adg_entity_set_local_map(entity
, &map
);
625 cairo_matrix_init_translate(&map
, -90, 20);
626 adg_entity_set_global_map(entity
, &map
);
627 adg_container_add(container
, entity
);
629 /* Set a decent start position and zoom */
630 cairo_matrix_init_translate(&map
, 10, -140);
631 cairo_matrix_scale(&map
, 15, 15);
632 cairo_matrix_translate(&map
, 0, 10);
633 adg_entity_set_local_map(ADG_ENTITY(canvas
), &map
);
639 operations_chamfer(const AdgPath
*model
, gdouble delta1
, gdouble delta2
)
643 CpmlPrimitive primitive
;
645 path
= adg_path_new();
646 adg_trail_get_segment(ADG_TRAIL(model
), &segment
, 1);
647 cpml_primitive_from_segment(&primitive
, &segment
);
649 adg_path_move_to(path
, (primitive
.org
)->point
.x
, (primitive
.org
)->point
.y
);
652 adg_path_append_primitive(path
, &primitive
);
653 if (primitive
.data
[0].header
.type
== CAIRO_PATH_LINE_TO
)
654 adg_path_chamfer(path
, delta1
, delta2
);
655 } while (cpml_primitive_next(&primitive
));
661 operations_fillet(const AdgPath
*model
, gdouble radius
)
665 CpmlPrimitive primitive
;
667 path
= adg_path_new();
668 adg_trail_get_segment(ADG_TRAIL(model
), &segment
, 1);
669 cpml_primitive_from_segment(&primitive
, &segment
);
671 adg_path_move_to(path
, (primitive
.org
)->point
.x
, (primitive
.org
)->point
.y
);
674 adg_path_append_primitive(path
, &primitive
);
675 if (primitive
.data
[0].header
.type
== CAIRO_PATH_LINE_TO
)
676 adg_path_fillet(path
, radius
);
677 } while (cpml_primitive_next(&primitive
));
683 /**********************************************
684 * Test case for mapping transformations,
685 * either on the local and global map
686 **********************************************/
693 AdgContainer
*container
;
697 path
= non_trivial_model();
698 canvas
= adg_canvas_new();
700 /* Add the original shape */
701 container
= adg_container_new();
702 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(container
));
704 entity
= ADG_ENTITY(adg_stroke_new(ADG_TRAIL(path
)));
705 adg_container_add(container
, entity
);
707 entity
= ADG_ENTITY(adg_toy_text_new("Original shape"));
708 cairo_matrix_init_translate(&map
, -50, 20);
709 adg_entity_set_global_map(entity
, &map
);
710 cairo_matrix_init_translate(&map
, 5, 10);
711 adg_entity_set_local_map(entity
, &map
);
712 adg_container_add(ADG_CONTAINER(canvas
), entity
);
714 /* Original shape with global rotated by 90 and local translated x+=10 */
715 container
= adg_container_new();
716 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(container
));
717 cairo_matrix_init_translate(&map
, 15, 0);
718 adg_entity_set_local_map(ADG_ENTITY(container
), &map
);
720 entity
= ADG_ENTITY(adg_stroke_new(ADG_TRAIL(path
)));
721 cairo_matrix_init_rotate(&map
, M_PI_2
);
722 adg_entity_set_global_map(entity
, &map
);
723 cairo_matrix_init_translate(&map
, 10, 0);
724 adg_entity_set_local_map(entity
, &map
);
725 adg_container_add(container
, entity
);
727 entity
= ADG_ENTITY(adg_toy_text_new("Global map rotated by 90"));
728 cairo_matrix_init_translate(&map
, -120, 20);
729 adg_entity_set_global_map(entity
, &map
);
730 cairo_matrix_init_translate(&map
, 5, 10);
731 adg_entity_set_local_map(entity
, &map
);
732 adg_container_add(container
, entity
);
734 /* Original shape with local translated x+=10 and rotated by 90 */
735 container
= adg_container_new();
736 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(container
));
737 cairo_matrix_init_translate(&map
, 30, 0);
738 adg_entity_set_local_map(ADG_ENTITY(container
), &map
);
740 entity
= ADG_ENTITY(adg_stroke_new(ADG_TRAIL(path
)));
741 cairo_matrix_init_translate(&map
, 10, 0);
742 cairo_matrix_rotate(&map
, M_PI_2
);
743 adg_entity_set_local_map(entity
, &map
);
744 adg_container_add(container
, entity
);
746 entity
= ADG_ENTITY(adg_toy_text_new("Local map rotated by 90"));
747 cairo_matrix_init_translate(&map
, -120, 20);
748 adg_entity_set_global_map(entity
, &map
);
749 cairo_matrix_init_translate(&map
, 5, 10);
750 adg_entity_set_local_map(entity
, &map
);
751 adg_container_add(container
, entity
);
753 /* Original shape with global map scaled by 0.5 */
754 container
= adg_container_new();
755 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(container
));
756 cairo_matrix_init_translate(&map
, 3.5, 15);
757 adg_entity_set_local_map(ADG_ENTITY(container
), &map
);
759 entity
= ADG_ENTITY(adg_stroke_new(ADG_TRAIL(path
)));
760 cairo_matrix_init_scale(&map
, 0.5, 0.5);
761 adg_entity_set_global_map(entity
, &map
);
762 adg_container_add(container
, entity
);
764 entity
= ADG_ENTITY(adg_toy_text_new("Global map scaled by 0.5"));
765 cairo_matrix_init_translate(&map
, -100, 20);
766 adg_entity_set_global_map(entity
, &map
);
767 cairo_matrix_init_translate(&map
, 2.5, 5);
768 adg_entity_set_local_map(entity
, &map
);
769 adg_container_add(container
, entity
);
771 /* Original shape with local map scaled by 0.5 */
772 container
= adg_container_new();
773 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(container
));
774 cairo_matrix_init_translate(&map
, 18, 15);
775 adg_entity_set_local_map(ADG_ENTITY(container
), &map
);
777 entity
= ADG_ENTITY(adg_stroke_new(ADG_TRAIL(path
)));
778 cairo_matrix_init_scale(&map
, 0.5, 0.5);
779 adg_entity_set_local_map(entity
, &map
);
780 adg_container_add(container
, entity
);
782 entity
= ADG_ENTITY(adg_toy_text_new("Local map scaled by 0.5"));
783 cairo_matrix_init_translate(&map
, -100, 20);
784 adg_entity_set_global_map(entity
, &map
);
785 cairo_matrix_init_translate(&map
, 2.5, 5);
786 adg_entity_set_local_map(entity
, &map
);
787 adg_container_add(container
, entity
);
789 /* Original shape with global and local maps scaled by 0.5 */
790 container
= adg_container_new();
791 adg_container_add(ADG_CONTAINER(canvas
), ADG_ENTITY(container
));
792 cairo_matrix_init_translate(&map
, 33, 15);
793 adg_entity_set_local_map(ADG_ENTITY(container
), &map
);
795 entity
= ADG_ENTITY(adg_stroke_new(ADG_TRAIL(path
)));
796 cairo_matrix_init_scale(&map
, 0.5, 0.5);
797 adg_entity_set_global_map(entity
, &map
);
798 adg_entity_set_local_map(entity
, &map
);
799 adg_container_add(container
, entity
);
801 entity
= ADG_ENTITY(adg_toy_text_new("Local&global scaled by 0.5"));
802 cairo_matrix_init_translate(&map
, -130, 20);
803 adg_entity_set_global_map(entity
, &map
);
804 cairo_matrix_init_translate(&map
, 2.5, 5);
805 adg_entity_set_local_map(entity
, &map
);
806 adg_container_add(container
, entity
);
808 /* Set a decent start position and zoom */
809 cairo_matrix_init_translate(&map
, 10, -140);
810 cairo_matrix_scale(&map
, 15, 15);
811 cairo_matrix_translate(&map
, 0, 10);
812 adg_entity_set_local_map(ADG_ENTITY(canvas
), &map
);
818 /**********************************************
819 * Non specific test related stuff
820 **********************************************/
825 AdgPath
*path
= adg_path_new();
827 adg_path_move_to(path
, 2, 0);
828 adg_path_line_to(path
, 0, 5);
829 adg_path_line_to(path
, 2, 2);
830 adg_path_line_to(path
, 0, 8);
831 adg_path_line_to(path
, 2, 8);
832 adg_path_line_to(path
, 2, 10);
833 adg_path_line_to(path
, 3, 10);
834 adg_path_line_to(path
, 10, 9);
835 adg_path_line_to(path
, 5, 5);
836 adg_path_line_to(path
, 3, 0);
837 adg_path_close(path
);
843 reverse_pair(const gchar
*name
, AdgPair
*pair
, AdgModel
*model
)
848 new_name
= g_strdup_printf("-%s", name
);
849 cpml_pair_copy(&new_pair
, pair
);
850 new_pair
.y
= -new_pair
.y
;
852 adg_model_set_named_pair(model
, new_name
, &new_pair
);