8 #define G_SQRT3 1.732050808
14 typedef struct _Piston Piston
;
18 gdouble D1
, D2
, D3
, D4
, D5
, D6
, D7
;
20 gdouble LD2
, LD3
, LD5
, LD6
, LD7
;
24 static void fill_piston_model (Piston
*piston
);
25 static void add_piston_path (AdgCanvas
*canvas
,
27 static void add_piston_dimensions (AdgCanvas
*canvas
,
29 static void add_sample_stuff (AdgCanvas
*canvas
);
30 static void piston_path_extern (AdgEntity
*entity
,
32 static void piston_expose (GtkWidget
*widget
,
33 GdkEventExpose
*event
,
35 static void piston_to_ps (AdgCanvas
*canvas
);
39 main(gint argc
, gchar
**argv
)
43 GtkWidget
*button_box
;
48 gtk_init(&argc
, &argv
);
50 /* Fill the model structure with some data */
51 fill_piston_model(&model
);
53 /* Create the canvas and populate it */
54 canvas
= adg_canvas_new();
55 add_piston_path(canvas
, &model
);
56 add_piston_dimensions(canvas
, &model
);
57 add_sample_stuff(canvas
);
59 /* User interface stuff */
60 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
61 g_signal_connect(window
, "delete-event", G_CALLBACK(gtk_main_quit
), NULL
);
63 vbox
= gtk_vbox_new(FALSE
, 0);
65 widget
= gtk_drawing_area_new();
66 gtk_widget_set_size_request(widget
, 790, 240);
67 g_signal_connect(widget
, "expose-event", G_CALLBACK(piston_expose
),
69 gtk_container_add(GTK_CONTAINER(vbox
), widget
);
71 button_box
= gtk_hbutton_box_new();
72 gtk_container_set_border_width(GTK_CONTAINER(button_box
), 5);
73 gtk_box_set_spacing(GTK_BOX(button_box
), 5);
74 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box
), GTK_BUTTONBOX_END
);
75 gtk_box_pack_end(GTK_BOX(vbox
), button_box
, FALSE
, TRUE
, 0);
77 widget
= gtk_button_new_from_stock(GTK_STOCK_SAVE
);
78 gtk_container_add(GTK_CONTAINER(button_box
), widget
);
80 widget
= gtk_button_new_from_stock(GTK_STOCK_PRINT
);
81 g_signal_connect_swapped(widget
, "clicked", G_CALLBACK(piston_to_ps
),
83 gtk_container_add(GTK_CONTAINER(button_box
), widget
);
85 widget
= gtk_button_new_from_stock(GTK_STOCK_QUIT
);
86 g_signal_connect(widget
, "clicked", G_CALLBACK(gtk_main_quit
), NULL
);
87 gtk_container_add(GTK_CONTAINER(button_box
), widget
);
89 gtk_container_add(GTK_CONTAINER(window
), vbox
);
90 gtk_widget_show_all(window
);
99 fill_piston_model(Piston
*piston
)
120 add_piston_path(AdgCanvas
*canvas
, Piston
*piston
)
124 entity
= adg_path_new(ADG_CALLBACK(piston_path_extern
), piston
);
126 adg_container_add(ADG_CONTAINER(canvas
), entity
);
130 add_piston_dimensions(AdgCanvas
*canvas
, Piston
*piston
)
133 double D1
, D2
, D3
, D4
, D5
, D6
, D7
;
134 double LD2
, LD3
, LD5
, LD6
, LD7
;
162 adg_ldim_new_full_explicit(A
- B
- LD2
, -D1
/ 2.0, A
- B
,
163 -D3
/ 2.0 + CHAMFER
, CPML_DIR_UP
, 0.0,
165 adg_container_add(ADG_CONTAINER(canvas
), entity
);
169 adg_ldim_new_full_explicit(A
- B
, -D3
/ 2.0 + CHAMFER
, A
- B
+ LD3
,
170 -D3
/ 2.0 + CHAMFER
, CPML_DIR_UP
, 0.0,
172 adg_container_add(ADG_CONTAINER(canvas
), entity
);
179 adg_ldim_new_full_explicit(A
- B
, D3
/ 2.0 - CHAMFER
, A
, D7
/ 2.0,
180 CPML_DIR_DOWN
, 0.0, D3
/ 2.0);
181 adg_dim_set_tolerances(ADG_DIM(entity
), "+0.1", NULL
);
182 adg_container_add(ADG_CONTAINER(canvas
), entity
);
186 adg_ldim_new_full_explicit(0.0, D1
/ 2.0, A
, D7
/ 2.0,
187 CPML_DIR_DOWN
, 0.0, D3
/ 2.0);
188 adg_dim_set_tolerances(ADG_DIM(entity
), "+0.05", "-0.05");
189 adg_dim_set_level(ADG_DIM(entity
), 2.0);
190 adg_container_add(ADG_CONTAINER(canvas
), entity
);
196 x
= A
- B
+ LD3
- CHAMFER
;
198 adg_ldim_new_full_explicit(x
, -D3
/ 2.0, x
, D3
/ 2.0,
199 CPML_DIR_RIGHT
, A
, 0.0);
200 adg_dim_set_tolerances(ADG_DIM(entity
), "-0.25", NULL
);
201 adg_dim_set_level(ADG_DIM(entity
), 5.0);
202 adg_container_add(ADG_CONTAINER(canvas
), entity
);
207 adg_ldim_new_full_explicit(x
, -D6
/ 2.0, x
, D6
/ 2.0,
208 CPML_DIR_RIGHT
, A
, 0.0);
209 adg_dim_set_tolerances(ADG_DIM(entity
), "-0.1", NULL
);
210 adg_dim_set_level(ADG_DIM(entity
), 4.0);
211 adg_container_add(ADG_CONTAINER(canvas
), entity
);
216 adg_ldim_new_full_explicit(x
, -D4
/ 2.0, x
, D4
/ 2.0,
217 CPML_DIR_RIGHT
, A
, 0.0);
218 adg_dim_set_level(ADG_DIM(entity
), 3.0);
219 adg_container_add(ADG_CONTAINER(canvas
), entity
);
224 adg_ldim_new_full_explicit(x
, -D5
/ 2.0, x
, D5
/ 2.0,
225 CPML_DIR_RIGHT
, A
, 0.0);
226 adg_dim_set_tolerances(ADG_DIM(entity
), "-0.1", NULL
);
227 adg_dim_set_level(ADG_DIM(entity
), 2.0);
228 adg_container_add(ADG_CONTAINER(canvas
), entity
);
232 adg_ldim_new_full_explicit(A
, -D7
/ 2.0, A
, D7
/ 2.0,
233 CPML_DIR_RIGHT
, A
, 0.0);
234 adg_container_add(ADG_CONTAINER(canvas
), entity
);
241 adg_ldim_new_full_explicit(0.0, -D1
/ 2.0, 0.0, D1
/ 2.0,
242 CPML_DIR_LEFT
, 0.0, 0.0);
243 adg_dim_set_tolerances(ADG_DIM(entity
), "+0.05", "-0.05");
244 adg_dim_set_level(ADG_DIM(entity
), 2.0);
245 adg_container_add(ADG_CONTAINER(canvas
), entity
);
249 x
= A
- B
- LD2
+ y
* G_SQRT3
;
251 adg_ldim_new_full_explicit(x
, -D2
/ 2.0, x
, D2
/ 2.0,
252 CPML_DIR_LEFT
, 0.0, 0.0);
253 adg_dim_set_tolerances(ADG_DIM(entity
), "-0.1", NULL
);
254 adg_container_add(ADG_CONTAINER(canvas
), entity
);
258 add_sample_stuff(AdgCanvas
*canvas
)
262 toy_text
= adg_toy_text_new("Test script near the piston");
263 adg_positionable_set_org_explicit(ADG_POSITIONABLE(toy_text
),
266 adg_container_add(ADG_CONTAINER(canvas
), toy_text
);
270 piston_path_extern(AdgEntity
*entity
, Piston
*piston
)
273 double D1
, D2
, D3
, D4
, D5
, D6
, D7
;
274 double LD2
, LD3
, LD5
, LD6
, LD7
;
297 path
= ADG_PATH(entity
);
299 adg_path_move_to(path
, 0, D1
/ 2.0);
300 adg_path_line_to(path
, A
- B
- LD2
, D1
/ 2.0);
302 adg_path_line_to(path
, A
- B
- LD2
+ y
* G_SQRT3
, D1
/ 2.0 - y
);
303 adg_path_line_to(path
, A
- B
, D2
/ 2.0);
304 adg_path_line_to(path
, A
- B
, D3
/ 2.0 - CHAMFER
);
305 adg_path_line_to(path
, A
- B
+ CHAMFER
, D3
/ 2.0);
306 adg_path_line_to(path
, A
- B
+ LD3
- CHAMFER
, D3
/ 2.0);
307 adg_path_line_to(path
, A
- B
+ LD3
, D3
/ 2.0 - CHAMFER
);
308 x
= A
- B
+ LD3
+ RD34
;
310 adg_path_arc(path
, x
, y
, RD34
, G_PI
, 3.0 * G_PI_2
);
311 adg_path_line_to(path
, A
- C
- LD5
, D4
/ 2.0);
313 adg_path_line_to(path
, A
- C
- LD5
+ y
, D4
/ 2.0 - y
);
314 adg_path_line_to(path
, A
- C
, D5
/ 2.0);
315 adg_path_line_to(path
, A
- C
, D6
/ 2.0);
316 adg_path_line_to(path
, A
- C
+ LD6
, D6
/ 2.0);
319 adg_path_line_to(path
, A
- C
+ LD6
+ x
, D6
/ 2.0 - y
);
320 adg_path_line_to(path
, A
- LD7
, D7
/ 2.0);
321 adg_path_line_to(path
, A
, D7
/ 2.0);
323 adg_path_chain_ymirror(path
);
324 adg_path_close(path
);
328 piston_expose(GtkWidget
*widget
, GdkEventExpose
*event
, AdgCanvas
*canvas
)
335 cr
= gdk_cairo_create(widget
->window
);
336 width
= widget
->allocation
.width
;
337 height
= widget
->allocation
.height
;
338 scale
= (double) (width
- 80.0) / 80.0;
340 cairo_matrix_init(&matrix
, scale
, 0.0, 0.0, scale
, scale
+ 71.0,
342 adg_container_set_model_transformation(ADG_CONTAINER(canvas
), &matrix
);
344 /* Rendering process */
345 adg_entity_render(ADG_ENTITY(canvas
), cr
);
351 piston_to_ps(AdgCanvas
*canvas
)
353 cairo_surface_t
*surface
;
358 /* Surface creation: A4 size */
359 surface
= cairo_ps_surface_create("test.ps", 595, 842);
360 cairo_ps_surface_dsc_comment(surface
,
361 "%%Title: Automatic Drawing Generation (Adg) demo");
362 cairo_ps_surface_dsc_comment(surface
,
363 "%%Copyright: Copyright (C) 2006 Fontana Nicola");
364 cairo_ps_surface_dsc_comment(surface
, "%%Orientation: Portrait");
366 cairo_ps_surface_dsc_begin_setup(surface
);
368 cairo_ps_surface_dsc_begin_page_setup(surface
);
369 cairo_ps_surface_dsc_comment(surface
,
370 "%%IncludeFeature: *PageSize A4");
372 cr
= cairo_create(surface
);
373 cairo_surface_destroy(surface
);
376 cairo_matrix_init(&matrix
, scale
, 0.0, 0.0, scale
, 100.0,
377 4.5 * scale
+ 100.0);
378 adg_container_set_model_transformation(ADG_CONTAINER(canvas
), &matrix
);
379 cairo_scale(cr
, 70.0, 70.0);
381 /* Rendering process */
382 adg_entity_render(ADG_ENTITY(canvas
), cr
);