| 1 |
/* File: pencil_diagram_maker.h; Copyright and License: see below */ |
| 2 |
|
| 3 |
#ifndef PENCIL_DIAGRAM_MAKER_H |
| 4 |
#define PENCIL_DIAGRAM_MAKER_H |
| 5 |
|
| 6 |
/* public file for the doxygen documentation: */ |
| 7 |
/*! |
| 8 |
* \file |
| 9 |
* \brief Layouts and paints a diagram with all its contents into a cairo drawing context |
| 10 |
*/ |
| 11 |
|
| 12 |
#include "pencil_layouter.h" |
| 13 |
#include "pencil_marker.h" |
| 14 |
#include "pencil_diagram_painter.h" |
| 15 |
#include "pencil_classifier_painter.h" |
| 16 |
#include "pencil_relationship_painter.h" |
| 17 |
#include "pencil_size.h" |
| 18 |
#include "pencil_error.h" |
| 19 |
#include "layout/layout_order.h" |
| 20 |
#include "layout/layout_visible_set.h" |
| 21 |
#include "geometry/geometry_rectangle.h" |
| 22 |
#include "geometry/geometry_non_linear_scale.h" |
| 23 |
#include "geometry/geometry_grid.h" |
| 24 |
#include "set/data_full_id.h" |
| 25 |
#include "set/data_profile_part.h" |
| 26 |
#include "set/data_small_set.h" |
| 27 |
#include "set/data_stat.h" |
| 28 |
#include "set/data_visible_set.h" |
| 29 |
#include "entity/data_diagram.h" |
| 30 |
#include "entity/data_id.h" |
| 31 |
#include <cairo.h> |
| 32 |
#include <stdint.h> |
| 33 |
|
| 34 |
/*! |
| 35 |
* \brief attributes of the diagram painter |
| 36 |
*/ |
| 37 |
struct pencil_diagram_maker_struct { |
| 38 |
const data_visible_set_t *input_data; /*!< pointer to an external elements-data cache */ |
| 39 |
const data_profile_part_t *profile; /*!< pointer to an external stereotype-data cache */ |
| 40 |
|
| 41 |
pencil_layouter_t layouter; /* own instance of a layouter */ |
| 42 |
|
| 43 |
pencil_diagram_painter_t diagram_painter; /*!< own instance of a diagram_painter */ |
| 44 |
pencil_classifier_painter_t classifier_painter; /*!< own instance of a classifier painter */ |
| 45 |
pencil_relationship_painter_t relationship_painter; /*!< own instance of a relationship_painter */ |
| 46 |
pencil_feature_painter_t feature_painter; /*!< own instance of a feature_painter */ |
| 47 |
|
| 48 |
universal_array_index_sorter_t temp_order; /*!< temporary own instance of a sort order to process layouter.layout_data */ |
| 49 |
}; |
| 50 |
|
| 51 |
typedef struct pencil_diagram_maker_struct pencil_diagram_maker_t; |
| 52 |
|
| 53 |
/*! |
| 54 |
* \brief initializes the painter |
| 55 |
* |
| 56 |
* \param this_ pointer to own object attributes |
| 57 |
* \param input_data pointer to the (cached) data to be drawn |
| 58 |
* \param profile pointer to the profile-part that provides the stereotypes of the elements to be drawn |
| 59 |
*/ |
| 60 |
static inline void pencil_diagram_maker_init ( pencil_diagram_maker_t *this_, |
| 61 |
const data_visible_set_t *input_data, |
| 62 |
const data_profile_part_t *profile |
| 63 |
); |
| 64 |
|
| 65 |
/*! |
| 66 |
* \brief re-initializes the painter |
| 67 |
* |
| 68 |
* \param this_ pointer to own object attributes |
| 69 |
* \param input_data pointer to the (cached) data to be drawn |
| 70 |
* \param profile pointer to the profile-part that provided the stereotypes of the elements to be drawn |
| 71 |
*/ |
| 72 |
static inline void pencil_diagram_maker_reinit ( pencil_diagram_maker_t *this_, |
| 73 |
const data_visible_set_t *input_data, |
| 74 |
const data_profile_part_t *profile |
| 75 |
); |
| 76 |
|
| 77 |
/*! |
| 78 |
* \brief destroys the painter |
| 79 |
* |
| 80 |
* \param this_ pointer to own object attributes |
| 81 |
*/ |
| 82 |
static inline void pencil_diagram_maker_destroy ( pencil_diagram_maker_t *this_ ); |
| 83 |
|
| 84 |
/*! |
| 85 |
* \brief defines coordinates |
| 86 |
* |
| 87 |
* Resets internal caches, any changes in input_data are ok, the profile needs to be updated accordingly. |
| 88 |
* |
| 89 |
* \param this_ pointer to own object attributes |
| 90 |
* \param diagram_bounds the diagram_bounds rectangle where to draw the diagram |
| 91 |
* \param cr a cairo drawing context, used to determine the font metrics in the given drawing context |
| 92 |
*/ |
| 93 |
static inline void pencil_diagram_maker_define_grid ( pencil_diagram_maker_t *this_, |
| 94 |
geometry_rectangle_t diagram_bounds, |
| 95 |
cairo_t *cr |
| 96 |
); |
| 97 |
|
| 98 |
/*! |
| 99 |
* \brief returns the geometry_grid_t |
| 100 |
* |
| 101 |
* \param this_ pointer to own object attributes |
| 102 |
*/ |
| 103 |
static inline const geometry_grid_t *pencil_diagram_maker_get_grid_const ( const pencil_diagram_maker_t *this_ ); |
| 104 |
|
| 105 |
/*! |
| 106 |
* \brief layouts the chosen diagram contents into the diagram_bounds area |
| 107 |
* |
| 108 |
* No reset of internal caches, no structural changes in input_data are allowed; |
| 109 |
* only updates of attributes like order values. |
| 110 |
* |
| 111 |
* \param this_ pointer to own object attributes |
| 112 |
* \param io_layout_stat pointer to already initialized statistics object where layouting statistics are added |
| 113 |
* or NULL if no statistics of interest |
| 114 |
* \param cr a cairo drawing context, used to determine the font metrics in the given drawing context |
| 115 |
*/ |
| 116 |
static inline void pencil_diagram_maker_layout_elements ( pencil_diagram_maker_t *this_, |
| 117 |
data_stat_t *io_layout_stat, |
| 118 |
cairo_t *cr |
| 119 |
); |
| 120 |
|
| 121 |
/*! |
| 122 |
* \brief returns the layout_visible_set_t object |
| 123 |
* |
| 124 |
* \param this_ pointer to own object attributes |
| 125 |
*/ |
| 126 |
static inline const layout_visible_set_t *pencil_diagram_maker_get_layout_data_const ( const pencil_diagram_maker_t *this_ ); |
| 127 |
|
| 128 |
/*! |
| 129 |
* \brief draws the chosen diagram contents into the diagram_bounds area of the cairo drawing context |
| 130 |
* |
| 131 |
* This function may be called only after a call to pencil_diagram_maker_layout_elements() |
| 132 |
* |
| 133 |
* \param this_ pointer to own object attributes |
| 134 |
* \param mark_focused id of the object that is to be marked as "focused" |
| 135 |
* \param mark_highlighted id of the object that is to be marked as "highlighted" |
| 136 |
* \param mark_selected set of objects that are to be marked as "selected" |
| 137 |
* \param cr a cairo drawing context |
| 138 |
*/ |
| 139 |
void pencil_diagram_maker_draw ( pencil_diagram_maker_t *this_, |
| 140 |
data_id_t mark_focused, |
| 141 |
data_id_t mark_highlighted, |
| 142 |
const data_small_set_t *mark_selected, |
| 143 |
cairo_t *cr |
| 144 |
); |
| 145 |
|
| 146 |
/*! |
| 147 |
* \brief draws the classifiers and contained features into the diagram_bounds area of the cairo drawing context |
| 148 |
* |
| 149 |
* \param this_ pointer to own object attributes |
| 150 |
* \param mark_focused id of the object that is to be marked as "focused" |
| 151 |
* \param mark_highlighted id of the object that is to be marked as "highlighted" |
| 152 |
* \param mark_selected set of objects that are to be marked as "selected" |
| 153 |
* \param layout structure to layout fonts |
| 154 |
* \param cr a cairo drawing context |
| 155 |
*/ |
| 156 |
void pencil_diagram_maker_private_draw_classifiers ( pencil_diagram_maker_t *this_, |
| 157 |
data_id_t mark_focused, |
| 158 |
data_id_t mark_highlighted, |
| 159 |
const data_small_set_t *mark_selected, |
| 160 |
PangoLayout *layout, |
| 161 |
cairo_t *cr |
| 162 |
); |
| 163 |
|
| 164 |
/*! |
| 165 |
* \brief draws the features of classifiers into the diagram_bounds area of the cairo drawing context |
| 166 |
* |
| 167 |
* \param this_ pointer to own object attributes |
| 168 |
* \param mark_focused id of the object that is to be marked as "focused" |
| 169 |
* \param mark_highlighted id of the object that is to be marked as "highlighted" |
| 170 |
* \param mark_selected set of objects that are to be marked as "selected" |
| 171 |
* \param layout structure to layout fonts |
| 172 |
* \param cr a cairo drawing context |
| 173 |
*/ |
| 174 |
void pencil_diagram_maker_private_draw_features ( pencil_diagram_maker_t *this_, |
| 175 |
data_id_t mark_focused, |
| 176 |
data_id_t mark_highlighted, |
| 177 |
const data_small_set_t *mark_selected, |
| 178 |
PangoLayout *layout, |
| 179 |
cairo_t *cr |
| 180 |
); |
| 181 |
|
| 182 |
/*! |
| 183 |
* \brief draws the relationships into the diagram_bounds area of the cairo drawing context |
| 184 |
* |
| 185 |
* \param this_ pointer to own object attributes |
| 186 |
* \param mark_focused id of the object that is to be marked as "focused" |
| 187 |
* \param mark_highlighted id of the object that is to be marked as "highlighted" |
| 188 |
* \param mark_selected set of objects that are to be marked as "selected" |
| 189 |
* \param layout structure to layout fonts |
| 190 |
* \param cr a cairo drawing context |
| 191 |
*/ |
| 192 |
void pencil_diagram_maker_private_draw_relationships ( pencil_diagram_maker_t *this_, |
| 193 |
data_id_t mark_focused, |
| 194 |
data_id_t mark_highlighted, |
| 195 |
const data_small_set_t *mark_selected, |
| 196 |
PangoLayout *layout, |
| 197 |
cairo_t *cr |
| 198 |
); |
| 199 |
|
| 200 |
/*! |
| 201 |
* \brief gets the layout order at a given position |
| 202 |
* |
| 203 |
* \param this_ pointer to own object attributes |
| 204 |
* \param obj_id object for which to determine the layout order |
| 205 |
* \param x x-position |
| 206 |
* \param y y-position |
| 207 |
* \param snap_to_grid_distance number of pixels by which a close-to-grid position is snapped to the grid |
| 208 |
* \param out_layout_order order at given position |
| 209 |
* \return PENCIL_ERROR_OUT_OF_BOUNDS if the given position x, y is not in the diagram, |
| 210 |
* PENCIL_ERROR_UNKNOWN_OBJECT if the object is not in the diagram |
| 211 |
*/ |
| 212 |
pencil_error_t pencil_diagram_maker_get_order_at_pos ( const pencil_diagram_maker_t *this_, |
| 213 |
data_id_t obj_id, |
| 214 |
double x, |
| 215 |
double y, |
| 216 |
double snap_to_grid_distance, |
| 217 |
layout_order_t* out_layout_order |
| 218 |
); |
| 219 |
|
| 220 |
/*! |
| 221 |
* \brief gets the layout order at a given position for a feature |
| 222 |
* |
| 223 |
* Avoid using this function, prefer to use pencil_diagram_maker_get_order_at_pos() |
| 224 |
* unless the feature is new/fake and does not yet have an ID. |
| 225 |
* |
| 226 |
* \param this_ pointer to own object attributes |
| 227 |
* \param feature_ptr feature for which to determine the layout order; not NULL |
| 228 |
* \param x x-position |
| 229 |
* \param y y-position |
| 230 |
* \param out_layout_order order at given position |
| 231 |
* \return PENCIL_ERROR_OUT_OF_BOUNDS if the given position x, y is not in the diagram, |
| 232 |
* PENCIL_ERROR_UNKNOWN_OBJECT if the parent classifier is not in the diagram |
| 233 |
*/ |
| 234 |
pencil_error_t pencil_diagram_maker_get_feature_order_at_pos ( const pencil_diagram_maker_t *this_, |
| 235 |
const data_feature_t *feature_ptr, |
| 236 |
double x, |
| 237 |
double y, |
| 238 |
layout_order_t* out_layout_order |
| 239 |
); |
| 240 |
|
| 241 |
#include "pencil_diagram_maker.inl" |
| 242 |
|
| 243 |
#endif /* PENCIL_DIAGRAM_MAKER_H */ |
| 244 |
|
| 245 |
|
| 246 |
/* |
| 247 |
Copyright 2016-2026 Andreas Warnke |
| 248 |
|
| 249 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 250 |
you may not use this file except in compliance with the License. |
| 251 |
You may obtain a copy of the License at |
| 252 |
|
| 253 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 254 |
|
| 255 |
Unless required by applicable law or agreed to in writing, software |
| 256 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 257 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 258 |
See the License for the specific language governing permissions and |
| 259 |
limitations under the License. |
| 260 |
*/ |