Debian Codegraph @

pencil/source/pencil_relationship_1d_layouter.c

raw
1 /* File: pencil_relationship_1d_layouter.c; Copyright and License: see below */
2
3 #include "pencil_relationship_1d_layouter.h"
4 #include "u8/u8_trace.h"
5 #include <pango/pangocairo.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <math.h>
9 #include <stdint.h>
10
11 void pencil_relationship_1d_layouter_init( pencil_relationship_1d_layouter_t *this_,
12 layout_visible_set_t *layout_data,
13 const data_profile_part_t *profile,
14 const pencil_size_t *pencil_size )
15 {
16 U8_TRACE_BEGIN();
17 assert( NULL != layout_data );
18 assert( NULL != profile );
19 assert( NULL != pencil_size );
20
21 (*this_).layout_data = layout_data;
22 (*this_).profile = profile;
23 (*this_).pencil_size = pencil_size;
24
25 pencil_relationship_painter_init( &((*this_).relationship_painter) );
26
27 U8_TRACE_END();
28 }
29
30 void pencil_relationship_1d_layouter_destroy( pencil_relationship_1d_layouter_t *this_ )
31 {
32 U8_TRACE_BEGIN();
33
34 pencil_relationship_painter_destroy( &((*this_).relationship_painter) );
35
36 U8_TRACE_END();
37 }
38
39 void pencil_relationship_1d_layouter_private_make_all_visible ( pencil_relationship_1d_layouter_t *this_ )
40 {
41 U8_TRACE_BEGIN();
42
43 /* determine visibility */
44 const uint32_t count_relations = layout_visible_set_get_relationship_count ( (*this_).layout_data );
45 for ( uint32_t index = 0; index < count_relations; index ++ )
46 {
47 layout_relationship_t *const the_relation = layout_visible_set_get_relationship_ptr ( (*this_).layout_data, index );
48 const layout_visible_classifier_t *const from_layout = layout_relationship_get_from_classifier_ptr ( the_relation );
49 const layout_visible_classifier_t *const to_layout = layout_relationship_get_to_classifier_ptr ( the_relation );
50 assert( from_layout != NULL );
51 assert( to_layout != NULL );
52 const data_visible_classifier_t *const from_data = layout_visible_classifier_get_data_const( from_layout );
53 const data_visible_classifier_t *const to_data = layout_visible_classifier_get_data_const( to_layout );
54 const data_diagramelement_t *const from_diagele = data_visible_classifier_get_diagramelement_const( from_data );
55 const data_diagramelement_t *const to_diagele = data_visible_classifier_get_diagramelement_const( to_data );
56 const data_diagramelement_flag_t from_flags = data_diagramelement_get_display_flags ( from_diagele );
57 const data_diagramelement_flag_t to_flags = data_diagramelement_get_display_flags ( to_diagele );
58 if (( 0 != ( DATA_DIAGRAMELEMENT_FLAG_GRAY_OUT & from_flags ))
59 || ( 0 != ( DATA_DIAGRAMELEMENT_FLAG_GRAY_OUT & to_flags )))
60 {
61 layout_relationship_set_visibility ( the_relation, PENCIL_VISIBILITY_GRAY_OUT );
62 }
63 else
64 {
65 layout_relationship_set_visibility ( the_relation, PENCIL_VISIBILITY_SHOW );
66 }
67 }
68
69 U8_TRACE_END();
70 }
71
72 void pencil_relationship_1d_layouter_layout_for_sequence( pencil_relationship_1d_layouter_t *this_ )
73 {
74 U8_TRACE_BEGIN();
75
76 pencil_relationship_1d_layouter_private_make_all_visible( this_ );
77
78 /* get draw area */
79 const layout_diagram_t *const diagram_layout
80 = layout_visible_set_get_diagram_const( (*this_).layout_data );
81 const geometry_rectangle_t *const diagram_draw_area
82 = layout_diagram_get_draw_area_const( diagram_layout );
83
84 /* layout the relationships */
85 const uint32_t count_relations
86 = layout_visible_set_get_relationship_count( (*this_).layout_data );
87 U8_TRACE_INFO_INT( "count_relations:", count_relations );
88 for ( uint32_t index = 0; index < count_relations; index ++ )
89 {
90 /* get the relationship to layout */
91 layout_relationship_t *const the_relationship
92 = layout_visible_set_get_relationship_ptr( (*this_).layout_data, index );
93
94 /* adjust visibility */
95 if ( ( NULL == layout_relationship_get_from_feature_ptr( the_relationship ) )
96 && ( NULL == layout_relationship_get_to_feature_ptr( the_relationship ) ) )
97 {
98 /* this is a globally visible relation, not local/scenario-based */
99 layout_visible_set_set_relationship_visibility( (*this_).layout_data, index, PENCIL_VISIBILITY_IMPLICIT );
100 }
101
102 /* calculate layout */
103 {
104 /* determine y-coordinate */
105 const data_relationship_t *const the_relationdata
106 = layout_relationship_get_data_const( the_relationship );
107 int32_t list_order = data_relationship_get_list_order( the_relationdata );
108 const double y_value_rel = (list_order/((double)UINT32_MAX))+0.5;
109 const double draw_top = geometry_rectangle_get_top(diagram_draw_area);
110 const double draw_bottom = geometry_rectangle_get_bottom(diagram_draw_area);
111 const double y_value = ( (draw_bottom - draw_top) * y_value_rel ) + draw_top;
112
113 /* get source and destination rectangles */
114 const geometry_rectangle_t *const source_rect
115 = layout_relationship_get_from_box_const ( the_relationship );
116 const geometry_rectangle_t *const dest_rect
117 = layout_relationship_get_to_box_const ( the_relationship );
118
119 /* calculate coordinates */
120 const double src_left = geometry_rectangle_get_left(source_rect);
121 const double src_center_x = geometry_rectangle_get_center_x(source_rect);
122 const double src_right = geometry_rectangle_get_right(source_rect);
123 const double src_top = geometry_rectangle_get_top(source_rect);
124 /*const double src_center_y = geometry_rectangle_get_center_y(source_rect);*/
125 const double src_bottom = geometry_rectangle_get_bottom(source_rect);
126
127 const double dst_left = geometry_rectangle_get_left(dest_rect);
128 const double dst_center_x = geometry_rectangle_get_center_x(dest_rect);
129 const double dst_right = geometry_rectangle_get_right(dest_rect);
130 const double dst_top = geometry_rectangle_get_top(dest_rect);
131 /*const double dst_center_y = geometry_rectangle_get_center_y(dest_rect);*/
132 const double dst_bottom = geometry_rectangle_get_bottom(dest_rect);
133
134 /* is interaction relation */
135 /*
136 const data_relationship_type_t rel_type
137 = data_relationship_get_main_type( the_relationdata );
138 const bool is_interaction
139 = ( rel_type == DATA_RELATIONSHIP_TYPE_UML_ASYNC_CALL )
140 || ( rel_type == DATA_RELATIONSHIP_TYPE_UML_SYNC_CALL )
141 || ( rel_type == DATA_RELATIONSHIP_TYPE_UML_RETURN_CALL )
142 || ( rel_type == DATA_RELATIONSHIP_TYPE_UML_CONTROL_FLOW )
143 || ( rel_type == DATA_RELATIONSHIP_TYPE_UML_OBJECT_FLOW )
144 || ( rel_type == DATA_RELATIONSHIP_TYPE_UML_ASYNC_CALL );
145 */
146
147 const double src_from_y
148 = ( y_value < src_top ) ? src_top : ( y_value > src_bottom ) ? src_bottom : y_value;
149 const double dst_to_y
150 = ( y_value < dst_top ) ? dst_top : ( y_value > dst_bottom ) ? dst_bottom : y_value;
151 const double src_from_x
152 = (( y_value < src_top )||( y_value > src_bottom ) /*|| is_interaction*/ )
153 ? src_center_x /* activity bars are assumed to have depth 1 */
154 : ( src_center_x < dst_center_x )
155 ? src_right
156 : src_left;
157 const double dst_to_x
158 = (( y_value < dst_top )||( y_value > dst_bottom ) /*|| is_interaction*/ )
159 ? dst_center_x /* activity bars are assumed to have depth 1 */
160 : ( src_center_x < dst_center_x )
161 ? dst_left
162 : dst_right;
163
164 /* determine minimum arrow size for message/call to self */
165 const double good_dist = pencil_size_get_preferred_object_distance( (*this_).pencil_size );
166
167 /* define relation */
168 geometry_connector_t relationship_shape;
169 if ( fabs( src_center_x - dst_center_x ) < 0.0001 )
170 {
171 /* message/call to self */
172 geometry_connector_init_vertical ( &relationship_shape,
173 src_center_x,
174 src_from_y - (good_dist/2.0),
175 dst_center_x,
176 dst_to_y + (good_dist/2.0),
177 src_center_x + good_dist /* the main connector shall be right to the start/end points */
178 );
179 }
180 else
181 {
182 /* normal message/call */
183 geometry_connector_init_horizontal ( &relationship_shape,
184 src_from_x,
185 src_from_y,
186 dst_to_x,
187 dst_to_y,
188 y_value
189 );
190 }
191 layout_relationship_set_shape( the_relationship, &relationship_shape );
192 geometry_connector_destroy( &relationship_shape );
193
194 /* initialize also the label (to empty), this is updated later */
195 {
196 geometry_rectangle_t void_rect;
197 geometry_rectangle_init_empty( &void_rect );
198 layout_relationship_set_label_box( the_relationship, &void_rect );
199 geometry_rectangle_destroy( &void_rect );
200 }
201 }
202 }
203
204 U8_TRACE_END();
205 }
206
207 void pencil_relationship_1d_layouter_layout_for_timing( pencil_relationship_1d_layouter_t *this_ )
208 {
209 U8_TRACE_BEGIN();
210
211 pencil_relationship_1d_layouter_private_make_all_visible( this_ );
212
213 /* get draw area */
214 const layout_diagram_t *const diagram_layout
215 = layout_visible_set_get_diagram_ptr( (*this_).layout_data );
216 const geometry_rectangle_t *const diagram_draw_area
217 = layout_diagram_get_draw_area_const( diagram_layout );
218
219 /* layout the relationships */
220 const uint32_t count_relations
221 = layout_visible_set_get_relationship_count( (*this_).layout_data );
222 U8_TRACE_INFO_INT( "count_relations:", count_relations );
223 for ( uint32_t index = 0; index < count_relations; index ++ )
224 {
225 /* get the relationship to layout */
226 layout_relationship_t *const the_relationship
227 = layout_visible_set_get_relationship_ptr( (*this_).layout_data, index );
228
229 /* adjust visibility */
230 if ( ( NULL == layout_relationship_get_from_feature_ptr( the_relationship ) )
231 && ( NULL == layout_relationship_get_to_feature_ptr( the_relationship ) ) )
232 {
233 /* this is a globally visible relation, not local/scenario-based */
234 layout_visible_set_set_relationship_visibility( (*this_).layout_data, index, PENCIL_VISIBILITY_IMPLICIT );
235 }
236
237 /* calculate layout */
238 {
239 /* determine x-coordinate */
240 const data_relationship_t *const the_relationdata
241 = layout_relationship_get_data_const( the_relationship );
242 const int32_t list_order = data_relationship_get_list_order ( the_relationdata );
243 const double x_value_rel = (list_order/((double)UINT32_MAX))+0.5;
244 const double draw_left = geometry_rectangle_get_left(diagram_draw_area);
245 const double draw_right = geometry_rectangle_get_right(diagram_draw_area);
246 const double x_value = ( (draw_right - draw_left) * x_value_rel ) + draw_left;
247
248 /* get source and destination rectangles */
249 const geometry_rectangle_t *const source_rect
250 = layout_relationship_get_from_box_const( the_relationship );
251 const geometry_rectangle_t *const dest_rect
252 = layout_relationship_get_to_box_const( the_relationship );
253
254 /* calculate coordinates */
255 const double src_left = geometry_rectangle_get_left(source_rect);
256 /*const double src_center_x = geometry_rectangle_get_center_x(source_rect);*/
257 const double src_right = geometry_rectangle_get_right(source_rect);
258 const double src_top = geometry_rectangle_get_top(source_rect);
259 const double src_center_y = geometry_rectangle_get_center_y(source_rect);
260 const double src_bottom = geometry_rectangle_get_bottom(source_rect);
261
262 const double dst_left = geometry_rectangle_get_left(dest_rect);
263 /*const double dst_center_x = geometry_rectangle_get_center_x(dest_rect);*/
264 const double dst_right = geometry_rectangle_get_right(dest_rect);
265 const double dst_top = geometry_rectangle_get_top(dest_rect);
266 const double dst_center_y = geometry_rectangle_get_center_y(dest_rect);
267 const double dst_bottom = geometry_rectangle_get_bottom(dest_rect);
268
269 /* is interaction relation */
270 const data_relationship_type_t rel_type
271 = data_relationship_get_main_type( the_relationdata );
272 const bool is_interaction
273 = ( rel_type == DATA_RELATIONSHIP_TYPE_UML_ASYNC_CALL )
274 || ( rel_type == DATA_RELATIONSHIP_TYPE_UML_SYNC_CALL )
275 || ( rel_type == DATA_RELATIONSHIP_TYPE_UML_RETURN_CALL )
276 || ( rel_type == DATA_RELATIONSHIP_TYPE_UML_CONTROL_FLOW )
277 || ( rel_type == DATA_RELATIONSHIP_TYPE_UML_OBJECT_FLOW )
278 || ( rel_type == DATA_RELATIONSHIP_TYPE_UML_ASYNC_CALL );
279
280 const double src_from_x
281 = ( x_value < src_left ) ? src_left : ( x_value > src_right ) ? src_right : x_value;
282 const double dst_to_x
283 = ( x_value < dst_left ) ? dst_left : ( x_value > dst_right ) ? dst_right : x_value;
284 const double src_from_y
285 = (( x_value < src_left )||( x_value > src_right )|| is_interaction )
286 ? src_center_y
287 : ( src_center_y < dst_center_y )
288 ? src_bottom
289 : src_top;
290 const double dst_to_y
291 = (( x_value < dst_left )||( x_value > dst_right )|| is_interaction )
292 ? dst_center_y
293 : ( src_center_y < dst_center_y )
294 ? dst_top
295 : dst_bottom;
296
297 /* determine minimum arrow size for self transition */
298 const double good_dist = pencil_size_get_preferred_object_distance( (*this_).pencil_size );
299
300 /* define relation */
301 geometry_connector_t relationship_shape;
302 if ( fabs( src_center_y - dst_center_y ) < 0.0001 )
303 {
304 /* transition to self */
305 geometry_connector_init_horizontal ( &relationship_shape,
306 src_from_x - (good_dist/2.0),
307 src_center_y,
308 dst_to_x + (good_dist/2.0),
309 dst_center_y,
310 src_center_y - good_dist /* the main connector shall be above the start/end points */
311 );
312 }
313 else
314 {
315 /* normal transition */
316 geometry_connector_init_vertical ( &relationship_shape,
317 src_from_x,
318 src_from_y,
319 dst_to_x,
320 dst_to_y,
321 x_value
322 );
323 }
324 layout_relationship_set_shape( the_relationship, &relationship_shape );
325 geometry_connector_destroy( &relationship_shape );
326
327 /* initialize also the label (to empty), this is updated later */
328 {
329 geometry_rectangle_t void_rect;
330 geometry_rectangle_init_empty( &void_rect );
331 layout_relationship_set_label_box( the_relationship, &void_rect );
332 geometry_rectangle_destroy( &void_rect );
333 }
334 }
335 }
336
337 U8_TRACE_END();
338 }
339
340
341 /*
342 Copyright 2017-2026 Andreas Warnke
343
344 Licensed under the Apache License, Version 2.0 (the "License");
345 you may not use this file except in compliance with the License.
346 You may obtain a copy of the License at
347
348 http://www.apache.org/licenses/LICENSE-2.0
349
350 Unless required by applicable law or agreed to in writing, software
351 distributed under the License is distributed on an "AS IS" BASIS,
352 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
353 See the License for the specific language governing permissions and
354 limitations under the License.
355 */