Debian Codegraph @

pencil/include/pencil_classifier_2d_layouter.h

raw
1 /* File: pencil_classifier_2d_layouter.h; Copyright and License: see below */
2
3 #ifndef PENCIL_CLASSIFIER_2D_LAYOUTER_H
4 #define PENCIL_CLASSIFIER_2D_LAYOUTER_H
5
6 /* public file for the doxygen documentation: */
7 /*!
8 * \file
9 * \brief Calculates positions of classifiers and features in a 2-dimensional diagram
10 */
11
12 #include "pencil_classifier_composer.h"
13 #include "pencil_size.h"
14 #include "pencil_error.h"
15 #include "layout/layout_visible_set.h"
16 #include "layout/layout_visible_classifier_iter.h"
17 #include "pencil_feature_layouter.h"
18 #include "geometry/geometry_rectangle.h"
19 #include "geometry/geometry_dimensions.h"
20 #include "geometry/geometry_grid.h"
21 #include "geometry/geometry_offset.h"
22 #include "set/data_profile_part.h"
23 #include "set/data_small_set.h"
24 #include "set/data_visible_set.h"
25 #include "entity/data_diagram.h"
26 #include "entity/data_id.h"
27 #include "u8list/universal_array_index_sorter.h"
28 #include <cairo.h>
29 #include <stdint.h>
30
31 /*!
32 * \brief attributes of the 2d-classifier layouter
33 *
34 * \note It may either be instantiated once and used many times or be instantiated per use.
35 */
36 struct pencil_classifier_2d_layouter_struct {
37 layout_visible_set_t *layout_data; /* pointer to external layout data */
38 const data_profile_part_t *profile; /*!< pointer to an external stereotype-image cache */
39
40 const pencil_size_t *pencil_size; /*!< pointer to an external pencil_size_t object, */
41 /*!< defining pen sizes, gap sizes, font sizes and colors */
42 const geometry_rectangle_t *diagram_draw_area; /*!< pointer to an external drawing rectangle */
43 /*!< containing inner contents of the diagram */
44 const geometry_grid_t *grid; /*!< pointer to an external pair of scale objects to calculate positions from order numbers */
45 geometry_dimensions_t *default_classifier_size; /*!< pointer to an external classifier default size rectangle */
46
47 pencil_classifier_composer_t classifier_composer; /*!< own instance of a composer object to ask for display dimensions */
48
49 pencil_feature_layouter_t *feature_layouter; /*!< pointer or an external helper to layout features */
50 };
51
52 typedef struct pencil_classifier_2d_layouter_struct pencil_classifier_2d_layouter_t;
53
54 /*!
55 * \brief initializes the classifier layouter
56 *
57 * \param this_ pointer to own object attributes
58 * \param layout_data pointer to the layout information to be used and modified
59 * \param profile pointer to the profile-part that provides the stereotypes of the elements to be layouted
60 * \param pencil_size pointer to the pencil_size_t object
61 * \param default_classifier_size pointer to the default size of a classifier
62 * \param grid pointer to an external pair of scale objects to calculate positions from order numbers
63 * \param feature_layouter pointer to a feature layout helper
64 */
65 void pencil_classifier_2d_layouter_init( pencil_classifier_2d_layouter_t *this_,
66 layout_visible_set_t *layout_data,
67 const data_profile_part_t *profile,
68 const pencil_size_t *pencil_size,
69 geometry_dimensions_t *default_classifier_size,
70 const geometry_grid_t *grid,
71 pencil_feature_layouter_t *feature_layouter
72 );
73
74 /*!
75 * \brief destroys the layouter
76 *
77 * \param this_ pointer to own object attributes
78 */
79 void pencil_classifier_2d_layouter_destroy( pencil_classifier_2d_layouter_t *this_ );
80
81 /* ================================ INITIAL LAYOUT ================================ */
82
83 /*!
84 * \brief estimates classifier bounds for each classifier
85 *
86 * \param this_ pointer to own object attributes
87 * \param font_layout pango layout object to determine the font metrics in the current cairo drawing context
88 */
89 void pencil_classifier_2d_layouter_estimate_bounds ( pencil_classifier_2d_layouter_t *this_, PangoLayout *font_layout );
90
91 /* ================================ MOVE TO AVOID OVERLAPS ================================ */
92
93 /*!
94 * \brief move classifiers to avoid overlaps
95 *
96 * \param this_ pointer to own object attributes
97 */
98 void pencil_classifier_2d_layouter_move_to_avoid_overlaps ( pencil_classifier_2d_layouter_t *this_ );
99
100 /*!
101 * \brief determine order by which to move classifiers
102 *
103 * \param this_ pointer to own object attributes
104 * \param out_sorted sorting order by which to move classifiers; must not be NULL, shall be initialized to empty.
105 */
106 void pencil_classifier_2d_layouter_private_propose_move_processing_order ( pencil_classifier_2d_layouter_t *this_,
107 universal_array_index_sorter_t *out_sorted
108 );
109
110 /*!
111 * \brief propose multiple solutions to move one classifier up/down/left/right
112 *
113 * \param this_ pointer to own object attributes
114 * \param the_classifier the current classifier for which to propose solutions
115 * \param already_processed a copy of an iterator to process the already processed visible_classifiers again
116 * \param solutions_max maximum number (array size) of solutions to propose
117 * \param out_solution array of solutions: proposal to move in x/y direction
118 * \param out_solution_count number of proposed solutions; 1 &lt;= out_solution_count &lt; solutions_max
119 */
120 void pencil_classifier_2d_layouter_private_propose_4dir_move_solutions ( pencil_classifier_2d_layouter_t *this_,
121 const layout_visible_classifier_t *the_classifier,
122 layout_visible_classifier_iter_t already_processed,
123 uint32_t solutions_max,
124 geometry_offset_t (*out_solution)[],
125 uint32_t *out_solution_count
126 );
127
128 /*!
129 * \brief propose another solution to move one classifier based on another algorithm
130 *
131 * \param this_ pointer to own object attributes
132 * \param the_classifier the current classifier for which to propose solutions
133 * \param already_processed a copy of an iterator to process the already processed visible_classifiers again
134 * \param out_solution proposal to move in x/y direction
135 */
136 void pencil_classifier_2d_layouter_private_propose_anchored_solution ( pencil_classifier_2d_layouter_t *this_,
137 const layout_visible_classifier_t *the_classifier,
138 layout_visible_classifier_iter_t already_processed,
139 geometry_offset_t *out_solution
140 );
141
142 /*!
143 * \brief selects one solution to move a classifier
144 *
145 * \param this_ pointer to own object attributes
146 * \param the_classifier the current classifier for which to select a solution
147 * \param sorted sorting order by which to move classifiers; must not be NULL.
148 * \param out_solution_count number of proposed solutions; 1 &lt;= out_solution_count
149 * \param solution array of solutions: proposal to move in x/y direction
150 * \param out_index_of_best index (of solution) of the best solution; must not be NULL.
151 */
152 void pencil_classifier_2d_layouter_private_select_move_solution ( pencil_classifier_2d_layouter_t *this_,
153 const layout_visible_classifier_t *the_classifier,
154 const universal_array_index_sorter_t *sorted,
155 uint32_t out_solution_count,
156 geometry_offset_t (*solution)[],
157 uint32_t *out_index_of_best
158 );
159
160 /* ================================ EMBRACE CHILDREN STEP BY STEP ================================ */
161
162 /*!
163 * \brief resize classifiers so that they embrace their children
164 *
165 * \param this_ pointer to own object attributes
166 * \param font_layout pango layout object to determine the font metrics if re-layouting titles
167 */
168 void pencil_classifier_2d_layouter_embrace_children( pencil_classifier_2d_layouter_t *this_, PangoLayout *font_layout );
169
170 /*!
171 * \brief determine order by which to embrace classifiers
172 *
173 * \param this_ pointer to own object attributes
174 * \param out_sorted sorting order of relationships by which to adapt classifiers; must not be NULL, shall be initialized to empty.
175 */
176 void pencil_classifier_2d_layouter_private_propose_embracing_order ( pencil_classifier_2d_layouter_t *this_,
177 universal_array_index_sorter_t *out_sorted
178 );
179
180 /*!
181 * \brief try to resize classifiers so that they embrace their children
182 *
183 * \param this_ pointer to own object attributes
184 * \param the_relationship the relationship to process: the parent tries to embrace the child
185 * \param move true if the containing parent classifier may move to the child, false if it shall expand only
186 * \param font_layout pango layout object to determine the font metrics if re-layouting titles
187 * \return PENCIL_ERROR_NONE in case of success, PENCIL_ERROR_OUT_OF_BOUNDS if embracing was not possible
188 */
189 pencil_error_t pencil_classifier_2d_layouter_private_try_embrace_child ( pencil_classifier_2d_layouter_t *this_,
190 layout_relationship_t *the_relationship,
191 bool move,
192 PangoLayout *font_layout
193 );
194
195 /* ================================ EMBRACE CHILDREN COMMON ================================ */
196
197 /*!
198 * \brief hides containment relationships if parents embrace their children
199 *
200 * \param this_ pointer to own object attributes
201 */
202 void pencil_classifier_2d_layouter_hide_relations_of_embraced_children( pencil_classifier_2d_layouter_t *this_ );
203
204 /* ================================ EMBRACE AND MOVE CHILDREN TOGETHER ================================ */
205
206 /*!
207 * \brief move and embrace child classifiers so that they have nice distances to neighbours and parent
208 *
209 * \param this_ pointer to own object attributes
210 * \param font_layout pango layout object to determine the font metrics if re-layouting titles
211 */
212 void pencil_classifier_2d_layouter_move_and_embrace_children( pencil_classifier_2d_layouter_t *this_, PangoLayout *font_layout );
213
214 /*!
215 * \brief determine order by which to move and embrace child classifiers
216 *
217 * \param this_ pointer to own object attributes
218 * \param out_sorted sorting order by which to grow classifiers; must not be NULL, shall be initialized to empty.
219 */
220 void pencil_classifier_2d_layouter_private_propose_move_embrace_order ( pencil_classifier_2d_layouter_t *this_, universal_array_index_sorter_t *out_sorted );
221
222 /*!
223 * \brief calculates the envelope hull of all descendants (excluding self).
224 *
225 * If there are not children, the envelope of ancestor_classifier is returned.
226 *
227 * \param this_ pointer to own object attributes
228 * \param ancestor_classifier the classifier of whichs children to determine the envelope
229 */
230 static inline geometry_rectangle_t pencil_classifier_2d_layouter_private_calc_descendant_envelope( pencil_classifier_2d_layouter_t *this_,
231 const layout_visible_classifier_t *ancestor_classifier
232 );
233
234 /*!
235 * \brief calculates the outer space around a given rectangle ignoring descendants, ancesters and self.
236 *
237 * \param this_ pointer to own object attributes
238 * \param start_rect rectangle for which to explore and determine the outer space
239 * \param the_classifier the classifier of which descendants, ancesters and self shall be ignored
240 */
241 static inline geometry_rectangle_t pencil_classifier_2d_layouter_private_calc_outer_space( pencil_classifier_2d_layouter_t *this_,
242 const geometry_rectangle_t *start_rect,
243 const layout_visible_classifier_t *the_classifier
244 );
245
246 /*!
247 * \brief moves all descendants of a classifier
248 *
249 * \param this_ pointer to own object attributes
250 * \param ancestor_classifier the ancestor classifier
251 * \param offset distance to move all children/descendants
252 */
253 static inline void pencil_classifier_2d_layouter_private_move_descendants( pencil_classifier_2d_layouter_t *this_,
254 const layout_visible_classifier_t *ancestor_classifier,
255 const geometry_offset_t *offset
256 );
257
258
259 #include "pencil_classifier_2d_layouter.inl"
260
261 #endif /* PENCIL_CLASSIFIER_2D_LAYOUTER_H */
262
263
264 /*
265 Copyright 2017-2026 Andreas Warnke
266
267 Licensed under the Apache License, Version 2.0 (the "License");
268 you may not use this file except in compliance with the License.
269 You may obtain a copy of the License at
270
271 http://www.apache.org/licenses/LICENSE-2.0
272
273 Unless required by applicable law or agreed to in writing, software
274 distributed under the License is distributed on an "AS IS" BASIS,
275 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
276 See the License for the specific language governing permissions and
277 limitations under the License.
278 */