Debian Codegraph @

pencil/source/draw/draw_classifier_contour.c

raw
1 /* File: draw_classifier_contour.c; Copyright and License: see below */
2
3 #include "draw/draw_classifier_contour.h"
4 #include "draw/draw_classifier_icon.h"
5 #include "u8/u8_trace.h"
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <assert.h>
9 #include <math.h>
10
11 /*! where to place the control points of a bezier curve to get a good approximation for a 90 degree curve */
12 const static double BEZIER_CTRL_POINT_FOR_90_DEGREE_CIRCLE = 0.552284749831;
13
14 const static double SINUS_OF_45_DEGREE = 0.707106781;
15
16 geometry_rectangle_t draw_classifier_contour_calc_inner_area ( const draw_classifier_contour_t *this_,
17 data_classifier_type_t classifier_type,
18 const geometry_rectangle_t *outer_bounds,
19 const pencil_size_t *pencil_size )
20 {
21 U8_TRACE_BEGIN();
22 assert ( NULL != outer_bounds );
23 assert ( NULL != pencil_size );
24
25 geometry_rectangle_t result;
26 geometry_rectangle_init_empty( &result );
27
28 double gap = pencil_size_get_standard_object_border( pencil_size );
29 double double_gap = 2.0 * gap; /* a line has the gap distance on both sides to the next object */
30
31 switch ( classifier_type )
32 {
33 case DATA_CLASSIFIER_TYPE_USE_CASE:
34 {
35 /* within a use case, space is limited (double_gap is the border on each side): */
36 double inner_x_radius = 0.5 * geometry_rectangle_get_width( outer_bounds ) - double_gap;
37 double inner_y_radius = 0.5 * geometry_rectangle_get_height( outer_bounds ) - double_gap;
38 double h_offset = (1.0 - SINUS_OF_45_DEGREE) * inner_x_radius;
39 double v_offset = (1.0 - SINUS_OF_45_DEGREE) * inner_y_radius;
40
41 geometry_rectangle_replace( &result, outer_bounds );
42 geometry_rectangle_expand_4dir( &result, -double_gap - h_offset, -double_gap - v_offset );
43 }
44 break;
45
46 case DATA_CLASSIFIER_TYPE_NODE:
47 {
48 /* the 3d border of a node shrinks the space */
49 double offset_3d = double_gap;
50
51 geometry_rectangle_replace( &result, outer_bounds );
52 geometry_rectangle_enlarge( &result, -2.0 * double_gap - offset_3d, -2.0 * double_gap - offset_3d );
53 geometry_rectangle_shift( &result, double_gap, double_gap + offset_3d );
54 }
55 break;
56
57 case DATA_CLASSIFIER_TYPE_ACTOR:
58 case DATA_CLASSIFIER_TYPE_DYN_INITIAL_NODE:
59 case DATA_CLASSIFIER_TYPE_DYN_FINAL_NODE:
60 case DATA_CLASSIFIER_TYPE_DYN_FORK_NODE:
61 case DATA_CLASSIFIER_TYPE_DYN_JOIN_NODE:
62 case DATA_CLASSIFIER_TYPE_DYN_SHALLOW_HISTORY:
63 case DATA_CLASSIFIER_TYPE_DYN_DEEP_HISTORY:
64 case DATA_CLASSIFIER_TYPE_DYN_ACCEPT_TIME_EVENT:
65 case DATA_CLASSIFIER_TYPE_IMAGE:
66 {
67 /* the symbol icon height is part of the shape border */
68 double symbol_icon_height = pencil_size_get_classifier_symbol_height( pencil_size );
69
70 geometry_rectangle_replace( &result, outer_bounds );
71 geometry_rectangle_enlarge( &result, -2.0 * double_gap, -2.0 * double_gap - symbol_icon_height );
72 geometry_rectangle_shift( &result, double_gap, double_gap + symbol_icon_height );
73 }
74 break;
75
76 case DATA_CLASSIFIER_TYPE_INTERACTION_USE: /* and */
77 case DATA_CLASSIFIER_TYPE_INTERACTION: /* and */
78 case DATA_CLASSIFIER_TYPE_PACKAGE: /* and */
79 case DATA_CLASSIFIER_TYPE_COMMENT:
80 {
81 double top_ornament_height = pencil_size_get_standard_font_size( pencil_size );
82
83 geometry_rectangle_replace( &result, outer_bounds );
84 geometry_rectangle_enlarge( &result, -2.0 * double_gap, -2.0 * double_gap - top_ornament_height );
85 geometry_rectangle_shift( &result, double_gap, double_gap + top_ornament_height );
86 }
87 break;
88
89 case DATA_CLASSIFIER_TYPE_BLOCK:
90 case DATA_CLASSIFIER_TYPE_REQUIREMENT:
91 case DATA_CLASSIFIER_TYPE_SUBSYSTEM:
92 case DATA_CLASSIFIER_TYPE_ACTIVITY:
93 case DATA_CLASSIFIER_TYPE_STATE:
94 case DATA_CLASSIFIER_TYPE_COMPONENT:
95 case DATA_CLASSIFIER_TYPE_PART:
96 case DATA_CLASSIFIER_TYPE_INTERFACE:
97 case DATA_CLASSIFIER_TYPE_CLASS:
98 case DATA_CLASSIFIER_TYPE_OBJECT:
99 case DATA_CLASSIFIER_TYPE_ARTIFACT:
100 case DATA_CLASSIFIER_TYPE_CONSTRAINT_BLOCK:
101 case DATA_CLASSIFIER_TYPE_DYN_INTERRUPTABLE_REGION:
102 case DATA_CLASSIFIER_TYPE_STEREOTYPE:
103 {
104 /* standard size */
105 geometry_rectangle_replace( &result, outer_bounds );
106 geometry_rectangle_expand_4dir( &result, -double_gap, -double_gap );
107 }
108 break;
109
110 case DATA_CLASSIFIER_TYPE_DYN_DECISION_NODE:
111 {
112 /* within a decision rhombus, space is limited by factor 2 per dimension: */
113 double half_outer_width = 0.5 * geometry_rectangle_get_width( outer_bounds ) - double_gap;
114 double half_outer_height = 0.5 * geometry_rectangle_get_height( outer_bounds ) - double_gap;
115 double h_offset = 0.5 * half_outer_width;
116 double v_offset = 0.5 * half_outer_height;
117
118 geometry_rectangle_replace( &result, outer_bounds );
119 geometry_rectangle_expand_4dir( &result, -double_gap - h_offset, -double_gap - v_offset );
120 }
121 break;
122
123 case DATA_CLASSIFIER_TYPE_DYN_ACCEPT_EVENT :
124 {
125 /* within an accept event, space is limited (double_gap is the border on each side): */
126 double half_outer_height = 0.5 * geometry_rectangle_get_height( outer_bounds ) - double_gap;
127 double horizontal_offset = half_outer_height;
128
129 geometry_rectangle_replace( &result, outer_bounds );
130 geometry_rectangle_enlarge( &result, -2.0 * double_gap - horizontal_offset, -2.0 * double_gap );
131 geometry_rectangle_shift( &result, double_gap + horizontal_offset, double_gap );
132 }
133 break;
134
135 case DATA_CLASSIFIER_TYPE_DYN_SEND_SIGNAL:
136 {
137 /* within a send signal, space is limited (double_gap is the border on each side): */
138 double half_outer_height = 0.5 * geometry_rectangle_get_height( outer_bounds ) - double_gap;
139 double horizontal_offset = half_outer_height;
140
141 geometry_rectangle_replace( &result, outer_bounds );
142 geometry_rectangle_enlarge( &result, -2.0 * double_gap - horizontal_offset, -2.0 * double_gap );
143 geometry_rectangle_shift( &result, double_gap, double_gap );
144 }
145 break;
146
147 default:
148 {
149 /* this case can happen if a model file of a new cfu version is opened with an older version of cfu */
150 U8_LOG_ANOMALY("unknown data_classifier_type_t in draw_classifier_contour_calc_inner_area()");
151 /* assume standard size */
152 geometry_rectangle_replace( &result, outer_bounds );
153 geometry_rectangle_expand_4dir( &result, -double_gap, -double_gap );
154 }
155 break;
156 }
157
158 U8_TRACE_END();
159 return result;
160 }
161
162 geometry_rectangle_t draw_classifier_contour_calc_outer_bounds ( const draw_classifier_contour_t *this_,
163 data_classifier_type_t classifier_type,
164 const geometry_rectangle_t *inner_area,
165 const pencil_size_t *pencil_size )
166 {
167 U8_TRACE_BEGIN();
168 assert ( NULL != inner_area );
169 assert ( NULL != pencil_size );
170
171 geometry_rectangle_t result;
172 geometry_rectangle_init_empty( &result );
173
174 double gap = pencil_size_get_standard_object_border( pencil_size );
175 double double_gap = 2.0 * gap; /* a line has the gap distance on both sides to the next object */
176
177 switch ( classifier_type )
178 {
179 case DATA_CLASSIFIER_TYPE_USE_CASE:
180 {
181 /* within a use case, space is limited (double_gap is the border on each side): */
182 double half_inner_width = 0.5 * geometry_rectangle_get_width( inner_area );
183 double half_inner_height = 0.5 * geometry_rectangle_get_height( inner_area );
184 double h_offset = half_inner_width * ( 1.0 / SINUS_OF_45_DEGREE - 1.0 );
185 double v_offset = half_inner_height * ( 1.0 / SINUS_OF_45_DEGREE - 1.0 );
186
187 geometry_rectangle_replace( &result, inner_area );
188 geometry_rectangle_expand_4dir( &result, +double_gap + h_offset, +double_gap + v_offset );
189 }
190 break;
191
192 case DATA_CLASSIFIER_TYPE_NODE:
193 {
194 /* the 3d border of a node shrinks the space */
195 double offset_3d = double_gap;
196
197 geometry_rectangle_replace( &result, inner_area );
198 geometry_rectangle_enlarge( &result, +2.0 * double_gap + offset_3d, +2.0 * double_gap + offset_3d );
199 geometry_rectangle_shift( &result, -double_gap, -double_gap - offset_3d );
200 }
201 break;
202
203 case DATA_CLASSIFIER_TYPE_ACTOR:
204 case DATA_CLASSIFIER_TYPE_DYN_INITIAL_NODE:
205 case DATA_CLASSIFIER_TYPE_DYN_FINAL_NODE:
206 case DATA_CLASSIFIER_TYPE_DYN_FORK_NODE:
207 case DATA_CLASSIFIER_TYPE_DYN_JOIN_NODE:
208 case DATA_CLASSIFIER_TYPE_DYN_SHALLOW_HISTORY:
209 case DATA_CLASSIFIER_TYPE_DYN_DEEP_HISTORY:
210 case DATA_CLASSIFIER_TYPE_DYN_ACCEPT_TIME_EVENT:
211 case DATA_CLASSIFIER_TYPE_IMAGE:
212 {
213 /* the symbol icon height is part of the shape border */
214 double symbol_icon_height = pencil_size_get_classifier_symbol_height( pencil_size );
215
216 geometry_rectangle_replace( &result, inner_area );
217 geometry_rectangle_enlarge( &result, +2.0 * double_gap, +2.0 * double_gap + symbol_icon_height );
218 geometry_rectangle_shift( &result, -double_gap, -double_gap - symbol_icon_height );
219 }
220 break;
221
222 case DATA_CLASSIFIER_TYPE_INTERACTION_USE: /* and */
223 case DATA_CLASSIFIER_TYPE_INTERACTION: /* and */
224 case DATA_CLASSIFIER_TYPE_PACKAGE: /* and */
225 case DATA_CLASSIFIER_TYPE_COMMENT:
226 {
227 double top_ornament_height = pencil_size_get_standard_font_size( pencil_size );
228
229 geometry_rectangle_replace( &result, inner_area );
230 geometry_rectangle_enlarge( &result, +2.0 * double_gap, +2.0 * double_gap + top_ornament_height );
231 geometry_rectangle_shift( &result, -double_gap, -double_gap - top_ornament_height );
232 }
233 break;
234
235 case DATA_CLASSIFIER_TYPE_BLOCK:
236 case DATA_CLASSIFIER_TYPE_REQUIREMENT:
237 case DATA_CLASSIFIER_TYPE_SUBSYSTEM:
238 case DATA_CLASSIFIER_TYPE_ACTIVITY:
239 case DATA_CLASSIFIER_TYPE_STATE:
240 case DATA_CLASSIFIER_TYPE_COMPONENT:
241 case DATA_CLASSIFIER_TYPE_PART:
242 case DATA_CLASSIFIER_TYPE_INTERFACE:
243 case DATA_CLASSIFIER_TYPE_CLASS:
244 case DATA_CLASSIFIER_TYPE_OBJECT:
245 case DATA_CLASSIFIER_TYPE_ARTIFACT:
246 case DATA_CLASSIFIER_TYPE_CONSTRAINT_BLOCK:
247 case DATA_CLASSIFIER_TYPE_DYN_INTERRUPTABLE_REGION:
248 case DATA_CLASSIFIER_TYPE_STEREOTYPE:
249 {
250 /* standard size */
251 geometry_rectangle_replace( &result, inner_area );
252 geometry_rectangle_expand_4dir( &result, +double_gap, +double_gap );
253 }
254 break;
255
256 case DATA_CLASSIFIER_TYPE_DYN_DECISION_NODE:
257 {
258 /* within a decision rhombus, space is limited by factor 2 per dimension: */
259 double half_inner_width = 0.5 * geometry_rectangle_get_width( inner_area );
260 double half_inner_height = 0.5 * geometry_rectangle_get_height( inner_area );
261 double h_offset = half_inner_width;
262 double v_offset = half_inner_height;
263
264 geometry_rectangle_replace( &result, inner_area );
265 geometry_rectangle_expand_4dir( &result, +double_gap + h_offset, +double_gap + v_offset );
266 }
267 break;
268
269 case DATA_CLASSIFIER_TYPE_DYN_ACCEPT_EVENT :
270 {
271 /* within an accept event, space is limited (double_gap is the border on each side): */
272 double half_inner_height = 0.5 * geometry_rectangle_get_height( inner_area );
273 double horizontal_offset = half_inner_height;
274
275 geometry_rectangle_replace( &result, inner_area );
276 geometry_rectangle_enlarge( &result, +2.0 * double_gap + horizontal_offset, +2.0 * double_gap );
277 geometry_rectangle_shift( &result, -double_gap - horizontal_offset, -double_gap );
278 }
279 break;
280
281 case DATA_CLASSIFIER_TYPE_DYN_SEND_SIGNAL:
282 {
283 /* within a send signal, space is limited (double_gap is the border on each side): */
284 double half_inner_height = 0.5 * geometry_rectangle_get_height( inner_area );
285 double horizontal_offset = half_inner_height;
286
287 geometry_rectangle_replace( &result, inner_area );
288 geometry_rectangle_enlarge( &result, +2.0 * double_gap + horizontal_offset, +2.0 * double_gap );
289 geometry_rectangle_shift( &result, -double_gap, -double_gap );
290 }
291 break;
292
293 default:
294 {
295 /* this case can happen if a model file of a new cfu version is opened with an older version of cfu */
296 U8_LOG_ANOMALY("unknown data_classifier_type_t in draw_classifier_contour_calc_outer_bounds()");
297 /* assume standard size */
298 geometry_rectangle_replace( &result, inner_area );
299 geometry_rectangle_expand_4dir( &result, +double_gap, +double_gap );
300 }
301 break;
302 }
303
304 U8_TRACE_END();
305 return result;
306 }
307
308 void draw_classifier_contour_draw_rounded_rect ( const draw_classifier_contour_t *this_,
309 const geometry_rectangle_t *outer_bounds,
310 bool dashed_line,
311 const pencil_size_t *pencil_size,
312 cairo_t *cr )
313 {
314 U8_TRACE_BEGIN();
315 assert ( NULL != outer_bounds );
316 assert ( NULL != pencil_size );
317 assert ( NULL != cr );
318 const double gap = pencil_size_get_standard_object_border( pencil_size );
319 const double border_left = geometry_rectangle_get_left ( outer_bounds ) + gap;
320 const double border_top = geometry_rectangle_get_top ( outer_bounds ) + gap;
321 const double border_width = geometry_rectangle_get_width ( outer_bounds ) - gap - gap;
322 const double border_height = geometry_rectangle_get_height ( outer_bounds ) - gap - gap;
323 const double border_bottom = border_top + border_height;
324 const double border_right = border_left + border_width;
325 const double corner_radius = 6.0 * gap;
326 const double ctrl_offset = corner_radius * (1.0-BEZIER_CTRL_POINT_FOR_90_DEGREE_CIRCLE);
327
328 /* set dashes */
329 if ( dashed_line )
330 {
331 double dashes[2];
332 dashes[0] = 2.0 * pencil_size_get_line_dash_length( pencil_size );
333 dashes[1] = 1.0 * pencil_size_get_line_dash_length( pencil_size );
334 cairo_set_dash ( cr, dashes, 2, 0.0 );
335 }
336
337 cairo_move_to ( cr, border_right - corner_radius, border_bottom );
338 cairo_line_to ( cr, border_left + corner_radius, border_bottom );
339 cairo_curve_to ( cr, border_left + ctrl_offset, border_bottom, border_left, border_bottom - ctrl_offset, border_left /* end point x */, border_bottom - corner_radius /* end point y */ );
340 cairo_line_to ( cr, border_left, border_top + corner_radius );
341 cairo_curve_to ( cr, border_left, border_top + ctrl_offset, border_left + ctrl_offset, border_top, border_left + corner_radius /* end point x */, border_top /* end point y */ );
342 cairo_line_to ( cr, border_right - corner_radius, border_top );
343 cairo_curve_to ( cr, border_right - ctrl_offset, border_top, border_right, border_top + ctrl_offset, border_right /* end point x */, border_top + corner_radius /* end point y */ );
344 cairo_line_to ( cr, border_right, border_bottom - corner_radius );
345 cairo_curve_to ( cr, border_right, border_bottom - ctrl_offset, border_right - ctrl_offset, border_bottom, border_right - corner_radius /* end point x */, border_bottom /* end point y */ );
346 cairo_stroke (cr);
347
348 /* reset dashes */
349 if ( dashed_line )
350 {
351 cairo_set_dash ( cr, NULL, 0, 0.0 );
352 }
353
354 U8_TRACE_END();
355 }
356
357 void draw_classifier_contour_draw_ellipse ( const draw_classifier_contour_t *this_,
358 const geometry_rectangle_t *outer_bounds,
359 const pencil_size_t *pencil_size,
360 cairo_t *cr )
361 {
362 U8_TRACE_BEGIN();
363 assert ( NULL != outer_bounds );
364 assert ( NULL != pencil_size );
365 assert ( NULL != cr );
366 const double gap = pencil_size_get_standard_object_border( pencil_size );
367 const double border_left = geometry_rectangle_get_left ( outer_bounds ) + gap;
368 const double border_top = geometry_rectangle_get_top ( outer_bounds ) + gap;
369 const double border_width = geometry_rectangle_get_width ( outer_bounds ) - gap - gap;
370 const double border_height = geometry_rectangle_get_height ( outer_bounds ) - gap - gap;
371 const double border_bottom = border_top + border_height;
372 const double border_right = border_left + border_width;
373 const double half_width = 0.5 * border_width;
374 const double half_height = 0.5 * border_height;
375 const double center_x = border_left + half_width;
376 const double center_y = border_top + half_height;
377 const double ctrl_xoffset = half_width * (1.0-BEZIER_CTRL_POINT_FOR_90_DEGREE_CIRCLE);
378 const double ctrl_yoffset = half_height * (1.0-BEZIER_CTRL_POINT_FOR_90_DEGREE_CIRCLE);
379
380 cairo_move_to ( cr, center_x, border_bottom );
381 cairo_curve_to ( cr, border_left + ctrl_xoffset, border_bottom, border_left, border_bottom - ctrl_yoffset, border_left /* end point x */, center_y /* end point y */ );
382 cairo_curve_to ( cr, border_left, border_top + ctrl_yoffset, border_left + ctrl_xoffset, border_top, center_x /* end point x */, border_top /* end point y */ );
383 cairo_curve_to ( cr, border_right - ctrl_xoffset, border_top, border_right, border_top + ctrl_yoffset, border_right /* end point x */, center_y /* end point y */ );
384 cairo_curve_to ( cr, border_right, border_bottom - ctrl_yoffset, border_right - ctrl_xoffset, border_bottom, center_x /* end point x */, border_bottom /* end point y */ );
385 cairo_stroke (cr);
386
387 U8_TRACE_END();
388 }
389
390 void draw_classifier_contour_draw_rhombus ( const draw_classifier_contour_t *this_,
391 const geometry_rectangle_t *outer_bounds,
392 const pencil_size_t *pencil_size,
393 cairo_t *cr )
394 {
395 U8_TRACE_BEGIN();
396 assert ( NULL != outer_bounds );
397 assert ( NULL != pencil_size );
398 assert ( NULL != cr );
399 const double gap = pencil_size_get_standard_object_border( pencil_size );
400 const double border_left = geometry_rectangle_get_left ( outer_bounds ) + gap;
401 const double border_top = geometry_rectangle_get_top ( outer_bounds ) + gap;
402 const double border_width = geometry_rectangle_get_width ( outer_bounds ) - gap - gap;
403 const double border_height = geometry_rectangle_get_height ( outer_bounds ) - gap - gap;
404 const double border_bottom = border_top + border_height;
405 const double border_right = border_left + border_width;
406 const double center_x = geometry_rectangle_get_center_x ( outer_bounds );
407 const double center_y = geometry_rectangle_get_center_y ( outer_bounds );
408
409 cairo_move_to ( cr, center_x, border_bottom );
410 cairo_line_to ( cr, border_left, center_y );
411 cairo_line_to ( cr, center_x, border_top );
412 cairo_line_to ( cr, border_right, center_y );
413 cairo_line_to ( cr, center_x, border_bottom );
414 cairo_stroke (cr);
415
416 U8_TRACE_END();
417 }
418
419 void draw_classifier_contour_draw_3d_box ( const draw_classifier_contour_t *this_,
420 const geometry_rectangle_t *outer_bounds,
421 const pencil_size_t *pencil_size,
422 cairo_t *cr )
423 {
424 U8_TRACE_BEGIN();
425 assert ( NULL != outer_bounds );
426 assert ( NULL != pencil_size );
427 assert ( NULL != cr );
428 const double gap = pencil_size_get_standard_object_border( pencil_size );
429 const double border_left = geometry_rectangle_get_left ( outer_bounds ) + gap;
430 const double border_top = geometry_rectangle_get_top ( outer_bounds ) + gap;
431 const double border_width = geometry_rectangle_get_width ( outer_bounds ) - gap - gap;
432 const double border_height = geometry_rectangle_get_height ( outer_bounds ) - gap - gap;
433 const double border_bottom = border_top + border_height;
434 const double border_right = border_left + border_width;
435 const double offset_3d = 2.0*gap;
436
437 cairo_rectangle ( cr, border_left, border_top+offset_3d, border_width-offset_3d, border_height-offset_3d );
438 cairo_stroke (cr);
439
440 cairo_move_to ( cr, border_left, border_top+offset_3d );
441 cairo_line_to ( cr, border_left+offset_3d, border_top );
442 cairo_line_to ( cr, border_right, border_top );
443 cairo_line_to ( cr, border_right, border_bottom-offset_3d );
444 cairo_line_to ( cr, border_right-offset_3d, border_bottom );
445 cairo_stroke (cr);
446 cairo_move_to ( cr, border_right, border_top );
447 cairo_line_to ( cr, border_right-offset_3d, border_top+offset_3d );
448 cairo_stroke (cr);
449
450 U8_TRACE_END();
451 }
452
453 void draw_classifier_contour_draw_accept_event ( const draw_classifier_contour_t *this_,
454 const geometry_rectangle_t *outer_bounds,
455 const pencil_size_t *pencil_size,
456 cairo_t *cr )
457 {
458 U8_TRACE_BEGIN();
459 assert ( NULL != outer_bounds );
460 assert ( NULL != pencil_size );
461 assert ( NULL != cr );
462 const double gap = pencil_size_get_standard_object_border( pencil_size );
463 const double border_left = geometry_rectangle_get_left ( outer_bounds ) + gap;
464 const double border_top = geometry_rectangle_get_top ( outer_bounds ) + gap;
465 const double border_width = geometry_rectangle_get_width ( outer_bounds ) - gap - gap;
466 const double border_height = geometry_rectangle_get_height ( outer_bounds ) - gap - gap;
467 const double border_bottom = border_top + border_height;
468 const double border_right = border_left + border_width;
469 const double center_y = geometry_rectangle_get_center_y ( outer_bounds );
470 const double x_indent = border_height / 2.0;
471
472 cairo_move_to ( cr, border_right, border_bottom );
473 cairo_line_to ( cr, border_right, border_top );
474 cairo_line_to ( cr, border_left, border_top );
475 cairo_line_to ( cr, border_left + x_indent, center_y );
476 cairo_line_to ( cr, border_left, border_bottom );
477 cairo_line_to ( cr, border_right, border_bottom );
478 cairo_stroke (cr);
479
480 U8_TRACE_END();
481 }
482
483 void draw_classifier_contour_draw_send_signal ( const draw_classifier_contour_t *this_,
484 const geometry_rectangle_t *outer_bounds,
485 const pencil_size_t *pencil_size,
486 cairo_t *cr )
487 {
488 U8_TRACE_BEGIN();
489 assert ( NULL != outer_bounds );
490 assert ( NULL != pencil_size );
491 assert ( NULL != cr );
492 const double gap = pencil_size_get_standard_object_border( pencil_size );
493 const double border_left = geometry_rectangle_get_left ( outer_bounds ) + gap;
494 const double border_top = geometry_rectangle_get_top ( outer_bounds ) + gap;
495 const double border_width = geometry_rectangle_get_width ( outer_bounds ) - gap - gap;
496 const double border_height = geometry_rectangle_get_height ( outer_bounds ) - gap - gap;
497 const double border_bottom = border_top + border_height;
498 const double border_right = border_left + border_width;
499 const double center_y = geometry_rectangle_get_center_y ( outer_bounds );
500 const double x_indent = border_height / 2.0;
501
502 cairo_move_to ( cr, border_right - x_indent, border_bottom );
503 cairo_line_to ( cr, border_right, center_y );
504 cairo_line_to ( cr, border_right - x_indent, border_top );
505 cairo_line_to ( cr, border_left, border_top );
506 cairo_line_to ( cr, border_left, border_bottom );
507 cairo_line_to ( cr, border_right - x_indent, border_bottom );
508 cairo_stroke (cr);
509
510 U8_TRACE_END();
511 }
512
513 void draw_classifier_contour_draw_package ( const draw_classifier_contour_t *this_,
514 const geometry_rectangle_t *outer_bounds,
515 const geometry_rectangle_t *label_box,
516 const pencil_size_t *pencil_size,
517 cairo_t *cr )
518 {
519 U8_TRACE_BEGIN();
520 assert ( NULL != outer_bounds );
521 assert ( NULL != pencil_size );
522 assert ( NULL != cr );
523 const double gap = pencil_size_get_standard_object_border( pencil_size );
524 const double border_left = geometry_rectangle_get_left ( outer_bounds ) + gap;
525 const double border_top = geometry_rectangle_get_top ( outer_bounds ) + gap;
526 const double border_width = geometry_rectangle_get_width ( outer_bounds ) - gap - gap;
527 const double border_height = geometry_rectangle_get_height ( outer_bounds ) - gap - gap;
528
529 double tab_width;
530 double tab_height;
531 const bool label_in_tab = ( geometry_rectangle_get_top( label_box ) < ( border_top + gap + gap ) );
532 if ( label_in_tab )
533 {
534 tab_width = geometry_rectangle_get_width ( label_box ) + gap + gap;
535 tab_height = geometry_rectangle_get_height ( label_box ) + gap;
536 }
537 else
538 {
539 tab_width = border_width/3.0;
540 tab_height = pencil_size_get_standard_font_size( pencil_size );
541 }
542 cairo_rectangle ( cr, border_left, border_top, tab_width, tab_height );
543 cairo_rectangle ( cr, border_left, border_top+tab_height, border_width, border_height-tab_height );
544 cairo_stroke (cr);
545
546 U8_TRACE_END();
547 }
548
549 void draw_classifier_contour_draw_diagram_ref ( const draw_classifier_contour_t *this_,
550 const geometry_rectangle_t *outer_bounds,
551 const pencil_size_t *pencil_size,
552 cairo_t *cr )
553 {
554 U8_TRACE_BEGIN();
555 assert ( NULL != outer_bounds );
556 assert ( NULL != pencil_size );
557 assert ( NULL != cr );
558 const double gap = pencil_size_get_standard_object_border( pencil_size );
559 const double border_left = geometry_rectangle_get_left ( outer_bounds ) + gap;
560 const double border_top = geometry_rectangle_get_top ( outer_bounds ) + gap;
561 const double border_width = geometry_rectangle_get_width ( outer_bounds ) - gap - gap;
562 const double border_height = geometry_rectangle_get_height ( outer_bounds ) - gap - gap;
563 const double title_corner_height = pencil_size_get_standard_font_size( pencil_size );
564 const double title_corner_edge45 = 0.4 * title_corner_height;
565 const double title_corner_width = border_width/5.0;
566
567 cairo_rectangle ( cr, border_left, border_top, border_width, border_height );
568 cairo_move_to ( cr, border_left, border_top+title_corner_height );
569 cairo_line_to ( cr, border_left+title_corner_width - title_corner_edge45, border_top+title_corner_height );
570 cairo_line_to ( cr, border_left+title_corner_width, border_top+title_corner_height-title_corner_edge45 );
571 cairo_line_to ( cr, border_left+title_corner_width, border_top );
572 cairo_stroke (cr);
573
574 U8_TRACE_END();
575 }
576
577 void draw_classifier_contour_draw_comment ( const draw_classifier_contour_t *this_,
578 const geometry_rectangle_t *outer_bounds,
579 const pencil_size_t *pencil_size,
580 cairo_t *cr )
581 {
582 U8_TRACE_BEGIN();
583 assert ( NULL != outer_bounds );
584 assert ( NULL != pencil_size );
585 assert ( NULL != cr );
586 const double gap = pencil_size_get_standard_object_border( pencil_size );
587 const double border_left = geometry_rectangle_get_left ( outer_bounds ) + gap;
588 const double border_top = geometry_rectangle_get_top ( outer_bounds ) + gap;
589 const double border_width = geometry_rectangle_get_width ( outer_bounds ) - gap - gap;
590 const double border_height = geometry_rectangle_get_height ( outer_bounds ) - gap - gap;
591 const double corner_edge = pencil_size_get_standard_font_size( pencil_size );
592 const double border_bottom = border_top + border_height;
593 const double border_right = border_left + border_width;
594
595 cairo_move_to ( cr, border_right, border_top + corner_edge );
596 cairo_line_to ( cr, border_right - corner_edge, border_top + corner_edge );
597 cairo_line_to ( cr, border_right - corner_edge, border_top );
598 cairo_line_to ( cr, border_left, border_top );
599 cairo_line_to ( cr, border_left, border_bottom );
600 cairo_line_to ( cr, border_right, border_bottom );
601 cairo_line_to ( cr, border_right, border_top + corner_edge );
602 cairo_line_to ( cr, border_right - corner_edge, border_top );
603 cairo_stroke (cr);
604
605 U8_TRACE_END();
606 }
607
608 void draw_classifier_contour_draw_compartment_line ( const draw_classifier_contour_t *this_,
609 data_classifier_type_t classifier_type,
610 const geometry_rectangle_t *outer_bounds,
611 double y_coordinate,
612 const pencil_size_t *pencil_size,
613 cairo_t *cr )
614 {
615 U8_TRACE_BEGIN();
616 assert ( NULL != outer_bounds );
617 assert ( NULL != pencil_size );
618 assert ( NULL != cr );
619
620 const double bounds_left = geometry_rectangle_get_left( outer_bounds );
621 const double bounds_width = geometry_rectangle_get_width( outer_bounds );
622 const double bounds_height = geometry_rectangle_get_height( outer_bounds );
623 const double gap = pencil_size_get_standard_object_border( pencil_size );
624
625 double left = bounds_left + gap;
626 double right = bounds_left + bounds_width - gap;
627 switch ( classifier_type )
628 {
629 case DATA_CLASSIFIER_TYPE_USE_CASE:
630 {
631 const double center_x = geometry_rectangle_get_center_x( outer_bounds );
632 const double center_y = geometry_rectangle_get_center_y( outer_bounds );
633 const double radius_x = ( bounds_width / 2.0 ) - gap; /* there is 1.0*gap around the ellipsis */
634 const double radius_y = ( bounds_height / 2.0 ) - gap; /* there is 1.0*gap around the ellipsis */
635 const double norm_dy = ( y_coordinate - center_y ) / radius_y;
636 const double sqr_norm_dx = 1.0 - ( norm_dy * norm_dy );
637 if ( sqr_norm_dx >= 0.0 )
638 {
639 const double dx = sqrt( sqr_norm_dx ) * radius_x;
640 left = center_x - dx;
641 right = center_x + dx;
642 }
643 else
644 {
645 left = bounds_left + gap;
646 right = bounds_left + bounds_width - gap;
647 }
648 }
649 break;
650
651 case DATA_CLASSIFIER_TYPE_NODE:
652 {
653 /* the 3d border of a node shrinks the space */
654 const double offset_3d = 2.0 * gap;
655 left = bounds_left + gap;
656 right = bounds_left + bounds_width - offset_3d - gap;
657 }
658 break;
659
660 default:
661 {
662 /* for all other cases; this switch is not exhaustive */
663 left = bounds_left + gap;
664 right = bounds_left + bounds_width - gap;
665 }
666 break;
667 }
668
669 cairo_move_to ( cr, left, y_coordinate );
670 cairo_line_to ( cr, right, y_coordinate );
671 cairo_stroke (cr);
672
673 U8_TRACE_END();
674 }
675
676
677 /*
678 Copyright 2016-2026 Andreas Warnke
679 http://www.apache.org/licenses/LICENSE-2.0
680
681 Licensed under the Apache License, Version 2.0 (the "License");
682 you may not use this file except in compliance with the License.
683 You may obtain a copy of the License at
684
685
686 Unless required by applicable law or agreed to in writing, software
687 distributed under the License is distributed on an "AS IS" BASIS,
688 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
689 See the License for the specific language governing permissions and
690 limitations under the License.
691 */