| 1 |
/* File: pencil_relationship_2d_layouter.h; Copyright and License: see below */ |
| 2 |
|
| 3 |
#ifndef PENCIL_RELATIONSHIP_2D_LAYOUTER_H |
| 4 |
#define PENCIL_RELATIONSHIP_2D_LAYOUTER_H |
| 5 |
|
| 6 |
/* public file for the doxygen documentation: */ |
| 7 |
/*! |
| 8 |
* \file |
| 9 |
* \brief Calculates positions of relationships in a diagram |
| 10 |
*/ |
| 11 |
|
| 12 |
#include "pencil_size.h" |
| 13 |
#include "layout/layout_visible_set.h" |
| 14 |
#include "layout/layout_relationship_iter.h" |
| 15 |
#include "pencil_relationship_painter.h" |
| 16 |
#include "geometry/geometry_rectangle.h" |
| 17 |
#include "geometry/geometry_non_linear_scale.h" |
| 18 |
#include "set/data_profile_part.h" |
| 19 |
#include "set/data_small_set.h" |
| 20 |
#include "set/data_visible_set.h" |
| 21 |
#include "entity/data_diagram.h" |
| 22 |
#include "entity/data_id.h" |
| 23 |
#include "u8list/universal_array_index_sorter.h" |
| 24 |
#include "u8/u8_error.h" |
| 25 |
#include <cairo.h> |
| 26 |
#include <stdint.h> |
| 27 |
|
| 28 |
/*! |
| 29 |
* \brief attributes of the relationship layouter |
| 30 |
* |
| 31 |
* \note It may either be instantiated once and used many times or be instantiated per use. |
| 32 |
*/ |
| 33 |
struct pencil_relationship_2d_layouter_struct { |
| 34 |
layout_visible_set_t *layout_data; /*!< pointer to an instance of layout data */ |
| 35 |
const data_profile_part_t *profile; /*!< pointer to an external stereotype-image cache */ |
| 36 |
|
| 37 |
universal_array_index_sorter_t sorted_relationships; /*!< a sorted list of relationships, ordered by processing order, */ |
| 38 |
/*!< empty if layouting algorithm finished */ |
| 39 |
layout_relationship_iter_t already_processed; /*!< already processed relationships of the sorted list of relationships */ |
| 40 |
|
| 41 |
const pencil_size_t *pencil_size; /*!< pointer to an instance of a pencil_size_t object, defining pen sizes, gap sizes, */ |
| 42 |
/*!< font sizes and colors */ |
| 43 |
pencil_relationship_painter_t relationship_painter; /*!< own instance of a painter object to ask for display dimensions */ |
| 44 |
}; |
| 45 |
|
| 46 |
typedef struct pencil_relationship_2d_layouter_struct pencil_relationship_2d_layouter_t; |
| 47 |
|
| 48 |
/*! |
| 49 |
* \brief initializes the layouter |
| 50 |
* |
| 51 |
* \param this_ pointer to own object attributes |
| 52 |
* \param layout_data pointer to the layout information to be used and modified |
| 53 |
* \param profile pointer to the profile-part that provides the stereotypes of the elements to be layouted |
| 54 |
* \param pencil_size pointer to the pencil_size_t object |
| 55 |
*/ |
| 56 |
void pencil_relationship_2d_layouter_init( pencil_relationship_2d_layouter_t *this_, |
| 57 |
layout_visible_set_t *layout_data, |
| 58 |
const data_profile_part_t *profile, |
| 59 |
const pencil_size_t *pencil_size |
| 60 |
); |
| 61 |
|
| 62 |
/*! |
| 63 |
* \brief destroys the layouter |
| 64 |
* |
| 65 |
* \param this_ pointer to own object attributes |
| 66 |
*/ |
| 67 |
void pencil_relationship_2d_layouter_destroy( pencil_relationship_2d_layouter_t *this_ ); |
| 68 |
|
| 69 |
/*! |
| 70 |
* \brief determines the shapes of the relationships |
| 71 |
* |
| 72 |
* \param this_ pointer to own object attributes |
| 73 |
*/ |
| 74 |
void pencil_relationship_2d_layouter_private_do_layout ( pencil_relationship_2d_layouter_t *this_ ); |
| 75 |
|
| 76 |
/*! |
| 77 |
* \brief determine order by which to shape relationships |
| 78 |
* |
| 79 |
* Relationships that are not visible are ignored. Therefore this_.sorted_relationships may contain fewer relationships than (*this_).layout_data. |
| 80 |
* |
| 81 |
* \param this_ pointer to own object attributes, &((this_).sorted_relationships) is initialized |
| 82 |
*/ |
| 83 |
void pencil_relationship_2d_layouter_private_propose_processing_order ( pencil_relationship_2d_layouter_t *this_ ); |
| 84 |
|
| 85 |
/*! |
| 86 |
* \brief propose multiple solutions to shape one relationship |
| 87 |
* |
| 88 |
* \param this_ pointer to own object attributes |
| 89 |
* \param current_relation current relationship for which to propose solutions |
| 90 |
* \param solutions_max maximum number (array size) of solutions to propose |
| 91 |
* \param out_solutions array of solutions |
| 92 |
* \param out_solutions_count number of proposed solutions; 1 <= out_solutions_count < solutions_max |
| 93 |
*/ |
| 94 |
void pencil_relationship_2d_layouter_private_propose_solutions ( pencil_relationship_2d_layouter_t *this_, |
| 95 |
const layout_relationship_t *current_relation, |
| 96 |
uint32_t solutions_max, |
| 97 |
geometry_connector_t out_solutions[], |
| 98 |
uint32_t *out_solutions_count |
| 99 |
); |
| 100 |
|
| 101 |
/*! |
| 102 |
* \brief selects one solution to shape a relationship |
| 103 |
* |
| 104 |
* \param this_ pointer to own object attributes |
| 105 |
* \param current_relation current relationship for which to propose solutions |
| 106 |
* \param solutions_count number of proposed solutions; 1 <= out_solutions_count < solutions_max |
| 107 |
* \param solutions array of solutions |
| 108 |
* \param out_index_of_best index (of solution) of the best solution; must not be NULL. |
| 109 |
*/ |
| 110 |
void pencil_relationship_2d_layouter_private_select_solution ( pencil_relationship_2d_layouter_t *this_, |
| 111 |
const layout_relationship_t *current_relation, |
| 112 |
uint32_t solutions_count, |
| 113 |
const geometry_connector_t solutions[], |
| 114 |
uint32_t *out_index_of_best |
| 115 |
); |
| 116 |
|
| 117 |
/*! |
| 118 |
* \brief layouts a connection from one rectangle to another in shape of - or I |
| 119 |
* |
| 120 |
* \param this_ pointer to own object attributes |
| 121 |
* \param source_rect pointer to the source rectangle |
| 122 |
* \param dest_rect pointer to the destination rectangle |
| 123 |
* \param solutions_max maximum number (array size) of solutions to propose |
| 124 |
* \param out_solutions array of solutions |
| 125 |
* \param out_solutions_count number of proposed solutions; 1 <= out_solutions_count < solutions_max |
| 126 |
*/ |
| 127 |
void pencil_relationship_2d_layouter_private_connect_rectangles_by_I ( pencil_relationship_2d_layouter_t *this_, |
| 128 |
const geometry_rectangle_t *source_rect, |
| 129 |
const geometry_rectangle_t *dest_rect, |
| 130 |
uint32_t solutions_max, |
| 131 |
geometry_connector_t out_solutions[], |
| 132 |
uint32_t *out_solutions_count |
| 133 |
); |
| 134 |
|
| 135 |
/*! |
| 136 |
* \brief layouts a connection from one rectangle to another in shape of Z or N |
| 137 |
* |
| 138 |
* \param this_ pointer to own object attributes |
| 139 |
* \param source_rect pointer to the source rectangle |
| 140 |
* \param dest_rect pointer to the destination rectangle |
| 141 |
* \param solutions_max maximum number (array size) of solutions to propose |
| 142 |
* \param out_solutions array of solutions |
| 143 |
* \param out_solutions_count number of proposed solutions; 1 <= out_solutions_count < solutions_max |
| 144 |
*/ |
| 145 |
void pencil_relationship_2d_layouter_private_connect_rectangles_by_ZN ( pencil_relationship_2d_layouter_t *this_, |
| 146 |
const geometry_rectangle_t *source_rect, |
| 147 |
const geometry_rectangle_t *dest_rect, |
| 148 |
uint32_t solutions_max, |
| 149 |
geometry_connector_t out_solutions[], |
| 150 |
uint32_t *out_solutions_count |
| 151 |
); |
| 152 |
|
| 153 |
/*! |
| 154 |
* \brief layouts a connection from one rectangle to another in shape of U or C |
| 155 |
* |
| 156 |
* \param this_ pointer to own object attributes |
| 157 |
* \param source_rect pointer to the source rectangle |
| 158 |
* \param dest_rect pointer to the destination rectangle |
| 159 |
* \param solutions_max maximum number (array size) of solutions to propose |
| 160 |
* \param out_solutions array of solutions |
| 161 |
* \param out_solutions_count number of proposed solutions; 1 <= out_solutions_count < solutions_max |
| 162 |
*/ |
| 163 |
void pencil_relationship_2d_layouter_private_connect_rectangles_by_UC ( pencil_relationship_2d_layouter_t *this_, |
| 164 |
const geometry_rectangle_t *source_rect, |
| 165 |
const geometry_rectangle_t *dest_rect, |
| 166 |
uint32_t solutions_max, |
| 167 |
geometry_connector_t out_solutions[], |
| 168 |
uint32_t *out_solutions_count |
| 169 |
); |
| 170 |
|
| 171 |
/*! |
| 172 |
* \brief layouts a connection from one rectangle to another in shape of L or 7 |
| 173 |
* |
| 174 |
* \param this_ pointer to own object attributes |
| 175 |
* \param source_rect pointer to the source rectangle |
| 176 |
* \param dest_rect pointer to the destination rectangle |
| 177 |
* \param solutions_max maximum number (array size) of solutions to propose |
| 178 |
* \param out_solutions array of solutions |
| 179 |
* \param out_solutions_count number of proposed solutions; 1 <= out_solutions_count < solutions_max |
| 180 |
*/ |
| 181 |
void pencil_relationship_2d_layouter_private_connect_rectangles_by_L7 ( pencil_relationship_2d_layouter_t *this_, |
| 182 |
const geometry_rectangle_t *source_rect, |
| 183 |
const geometry_rectangle_t *dest_rect, |
| 184 |
uint32_t solutions_max, |
| 185 |
geometry_connector_t out_solutions[], |
| 186 |
uint32_t *out_solutions_count |
| 187 |
); |
| 188 |
|
| 189 |
/*! |
| 190 |
* \brief finds an empty, unused line in a rectangle |
| 191 |
* |
| 192 |
* In case there are several options, the one closer to the center is chosen. |
| 193 |
* |
| 194 |
* Touching a rectangle at the border of search_rect is allowed since this may be the source or destination |
| 195 |
* |
| 196 |
* \param this_ pointer to own object attributes |
| 197 |
* \param search_rect pointer to the rectangle within which to search |
| 198 |
* \param horizontal_line true if space for a horizontal line is searched for, false for vertical line |
| 199 |
* \param min_gap minimum distance to other objects on the diagram |
| 200 |
* \param io_coordinate ordinate (y-coordinate) or abscissa (x-coordinate) value of the line |
| 201 |
* for which to search space. Input value is the default; in case U8_ERROR_NONE is returned |
| 202 |
* this value is updated to the position where space is available. |
| 203 |
* \return U8_ERROR_NONE if a space was found, U8_ERROR_NOT_FOUND otherwise |
| 204 |
*/ |
| 205 |
u8_error_t pencil_relationship_2d_layouter_private_find_space_for_line ( pencil_relationship_2d_layouter_t *this_, |
| 206 |
const geometry_rectangle_t *search_rect, |
| 207 |
bool horizontal_line, |
| 208 |
double min_gap, |
| 209 |
double *io_coordinate |
| 210 |
); |
| 211 |
|
| 212 |
/*! |
| 213 |
* \brief finds an empty, unused line in a rectangle |
| 214 |
* |
| 215 |
* In case there are several options, the one closer to the initial value of io_ordinate is chosen. |
| 216 |
* |
| 217 |
* Touching a rectangle at the border of search_rect is allowed since this may be the source or destination |
| 218 |
* |
| 219 |
* \param this_ pointer to own object attributes |
| 220 |
* \param search_rect pointer to the rectangle within which to search |
| 221 |
* \param min_gap minimum distance to other objects on the diagram |
| 222 |
* \param io_ordinate ordinate (y-coordinate) of the line for which to search space. |
| 223 |
* Input value is the default; in case U8_ERROR_NONE is returned |
| 224 |
* this value is updated to the position where where space is available. |
| 225 |
* \return U8_ERROR_NONE if a space was found, U8_ERROR_NOT_FOUND otherwise |
| 226 |
*/ |
| 227 |
static inline u8_error_t pencil_relationship_2d_layouter_private_find_space_for_h_line ( pencil_relationship_2d_layouter_t *this_, |
| 228 |
const geometry_rectangle_t *search_rect, |
| 229 |
double min_gap, |
| 230 |
double *io_ordinate |
| 231 |
); |
| 232 |
|
| 233 |
/*! |
| 234 |
* \brief finds an empty, unused line in a rectangle |
| 235 |
* |
| 236 |
* In case there are several options, the one closer to the initial value of io_ordinate is chosen. |
| 237 |
* |
| 238 |
* Touching a rectangle at the border of search_rect is allowed since this may be the source or destination |
| 239 |
* |
| 240 |
* \param this_ pointer to own object attributes |
| 241 |
* \param search_rect pointer to the rectangle within which to search |
| 242 |
* \param min_gap minimum distance to other objects on the diagram |
| 243 |
* \param io_abscissa abscissa (x-coordinate) of the line for which to search space. |
| 244 |
* Input value is the default; in case U8_ERROR_NONE is returned |
| 245 |
* this value is updated to the position where where space is available. |
| 246 |
* \return U8_ERROR_NONE if a space was found, U8_ERROR_NOT_FOUND otherwise |
| 247 |
*/ |
| 248 |
static inline u8_error_t pencil_relationship_2d_layouter_private_find_space_for_v_line ( pencil_relationship_2d_layouter_t *this_, |
| 249 |
const geometry_rectangle_t *search_rect, |
| 250 |
double min_gap, |
| 251 |
double *io_abscissa |
| 252 |
); |
| 253 |
|
| 254 |
/*! |
| 255 |
* \brief make all relationships visible. |
| 256 |
* |
| 257 |
* Sets either normal visibility or grayed out status. |
| 258 |
* |
| 259 |
* \param this_ pointer to own object attributes |
| 260 |
*/ |
| 261 |
void pencil_relationship_2d_layouter_private_make_all_visible ( pencil_relationship_2d_layouter_t *this_ ); |
| 262 |
|
| 263 |
/*! |
| 264 |
* \brief layouts all relationships. |
| 265 |
* |
| 266 |
* This function performs a standard layouting of relationships |
| 267 |
* suitable for most diagram types. |
| 268 |
* Exceptions are LIST, BOX, SEQUENCE, TIMING, COMMUNICATION |
| 269 |
* |
| 270 |
* \param this_ pointer to own object attributes |
| 271 |
*/ |
| 272 |
void pencil_relationship_2d_layouter_layout_standard( pencil_relationship_2d_layouter_t *this_ ); |
| 273 |
|
| 274 |
/*! |
| 275 |
* \brief hides all relationships. |
| 276 |
* |
| 277 |
* Relationships are not visible in simple list and box diagrams. |
| 278 |
* |
| 279 |
* \param this_ pointer to own object attributes |
| 280 |
*/ |
| 281 |
void pencil_relationship_2d_layouter_layout_void( pencil_relationship_2d_layouter_t *this_ ); |
| 282 |
|
| 283 |
/*! |
| 284 |
* \brief defines the shapes of relationships in communication diagrams. |
| 285 |
* |
| 286 |
* Shows only relationships that are associated to a lifeline because a communication diagram |
| 287 |
* shows only an example sequence of messages, not all dependencies. |
| 288 |
* |
| 289 |
* \param this_ pointer to own object attributes |
| 290 |
*/ |
| 291 |
void pencil_relationship_2d_layouter_layout_for_communication( pencil_relationship_2d_layouter_t *this_ ); |
| 292 |
|
| 293 |
#include "pencil_relationship_2d_layouter.inl" |
| 294 |
|
| 295 |
#endif /* PENCIL_RELATIONSHIP_2D_LAYOUTER_H */ |
| 296 |
|
| 297 |
|
| 298 |
/* |
| 299 |
Copyright 2017-2026 Andreas Warnke |
| 300 |
|
| 301 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 302 |
you may not use this file except in compliance with the License. |
| 303 |
You may obtain a copy of the License at |
| 304 |
|
| 305 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 306 |
|
| 307 |
Unless required by applicable law or agreed to in writing, software |
| 308 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 309 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 310 |
See the License for the specific language governing permissions and |
| 311 |
limitations under the License. |
| 312 |
*/ |