| 1 |
/* File: layout_visible_classifier.inl; Copyright and License: see below */ |
| 2 |
|
| 3 |
#include <assert.h> |
| 4 |
|
| 5 |
static inline void layout_visible_classifier_init ( layout_visible_classifier_t *this_, const data_visible_classifier_t *visible_classifier_data ) |
| 6 |
{ |
| 7 |
assert ( NULL != visible_classifier_data ); |
| 8 |
|
| 9 |
geometry_rectangle_init_empty( &((*this_).symbol_box) ); |
| 10 |
geometry_rectangle_init_empty( &((*this_).space) ); |
| 11 |
geometry_rectangle_init_empty( &((*this_).label_box) ); |
| 12 |
geometry_rectangle_init_empty( &((*this_).icon_box) ); |
| 13 |
geometry_rectangle_init_empty( &((*this_).envelope_box_cache) ); |
| 14 |
(*this_).label_h_anchor = GEOMETRY_H_ALIGN_CENTER; /* most labels are centered */ |
| 15 |
(*this_).label_v_anchor = GEOMETRY_V_ALIGN_TOP; /* most labels are fixed to the top */ |
| 16 |
(*this_).data = visible_classifier_data; |
| 17 |
} |
| 18 |
|
| 19 |
static inline void layout_visible_classifier_copy( layout_visible_classifier_t *this_, const layout_visible_classifier_t *original ) |
| 20 |
{ |
| 21 |
assert ( NULL != original ); |
| 22 |
assert ( NULL != (*original).data ); |
| 23 |
|
| 24 |
geometry_rectangle_copy( &((*this_).symbol_box), &((*original).symbol_box) ); |
| 25 |
geometry_rectangle_copy( &((*this_).space), &((*original).space) ); |
| 26 |
geometry_rectangle_copy( &((*this_).label_box), &((*original).label_box) ); |
| 27 |
geometry_rectangle_copy( &((*this_).icon_box), &((*original).icon_box) ); |
| 28 |
geometry_rectangle_copy( &((*this_).envelope_box_cache), &((*original).envelope_box_cache) ); |
| 29 |
(*this_).label_h_anchor = (*original).label_h_anchor; |
| 30 |
(*this_).label_v_anchor = (*original).label_v_anchor; |
| 31 |
(*this_).data = (*original).data; |
| 32 |
} |
| 33 |
|
| 34 |
static inline void layout_visible_classifier_move( layout_visible_classifier_t *this_, layout_visible_classifier_t *that ) |
| 35 |
{ |
| 36 |
assert ( NULL != that ); |
| 37 |
assert ( NULL != (*that).data ); |
| 38 |
|
| 39 |
geometry_rectangle_move( &((*this_).symbol_box), &((*that).symbol_box) ); |
| 40 |
geometry_rectangle_move( &((*this_).space), &((*that).space) ); |
| 41 |
geometry_rectangle_move( &((*this_).label_box), &((*that).label_box) ); |
| 42 |
geometry_rectangle_move( &((*this_).icon_box), &((*that).icon_box) ); |
| 43 |
geometry_rectangle_move( &((*this_).envelope_box_cache), &((*that).envelope_box_cache) ); |
| 44 |
(*this_).label_h_anchor = (*that).label_h_anchor; |
| 45 |
(*this_).label_v_anchor = (*that).label_v_anchor; |
| 46 |
(*this_).data = (*that).data; |
| 47 |
|
| 48 |
(*that).data = NULL; |
| 49 |
} |
| 50 |
|
| 51 |
static inline void layout_visible_classifier_replace( layout_visible_classifier_t *this_, const layout_visible_classifier_t *original ) |
| 52 |
{ |
| 53 |
assert ( NULL != original ); |
| 54 |
assert ( NULL != (*original).data ); |
| 55 |
|
| 56 |
geometry_rectangle_replace( &((*this_).symbol_box), &((*original).symbol_box) ); |
| 57 |
geometry_rectangle_replace( &((*this_).space), &((*original).space) ); |
| 58 |
geometry_rectangle_replace( &((*this_).label_box), &((*original).label_box) ); |
| 59 |
geometry_rectangle_replace( &((*this_).icon_box), &((*original).icon_box) ); |
| 60 |
geometry_rectangle_replace( &((*this_).envelope_box_cache), &((*original).envelope_box_cache) ); |
| 61 |
(*this_).label_h_anchor = (*original).label_h_anchor; |
| 62 |
(*this_).label_v_anchor = (*original).label_v_anchor; |
| 63 |
(*this_).data = (*original).data; |
| 64 |
} |
| 65 |
|
| 66 |
static inline void layout_visible_classifier_replacemove( layout_visible_classifier_t *this_, layout_visible_classifier_t *that ) |
| 67 |
{ |
| 68 |
assert ( NULL != that ); |
| 69 |
assert ( NULL != (*that).data ); |
| 70 |
|
| 71 |
geometry_rectangle_replacemove( &((*this_).symbol_box), &((*that).symbol_box) ); |
| 72 |
geometry_rectangle_replacemove( &((*this_).space), &((*that).space) ); |
| 73 |
geometry_rectangle_replacemove( &((*this_).label_box), &((*that).label_box) ); |
| 74 |
geometry_rectangle_replacemove( &((*this_).icon_box), &((*that).icon_box) ); |
| 75 |
geometry_rectangle_replacemove( &((*this_).envelope_box_cache), &((*that).envelope_box_cache) ); |
| 76 |
(*this_).label_h_anchor = (*that).label_h_anchor; |
| 77 |
(*this_).label_v_anchor = (*that).label_v_anchor; |
| 78 |
(*this_).data = (*that).data; |
| 79 |
|
| 80 |
(*that).data = NULL; |
| 81 |
} |
| 82 |
|
| 83 |
static inline void layout_visible_classifier_destroy ( layout_visible_classifier_t *this_ ) |
| 84 |
{ |
| 85 |
geometry_rectangle_destroy( &((*this_).symbol_box) ); |
| 86 |
geometry_rectangle_destroy( &((*this_).space) ); |
| 87 |
geometry_rectangle_destroy( &((*this_).label_box) ); |
| 88 |
geometry_rectangle_destroy( &((*this_).icon_box) ); |
| 89 |
geometry_rectangle_destroy( &((*this_).envelope_box_cache) ); |
| 90 |
(*this_).data = NULL; |
| 91 |
} |
| 92 |
|
| 93 |
static inline bool layout_visible_classifier_is_valid ( const layout_visible_classifier_t *this_ ) |
| 94 |
{ |
| 95 |
bool result; |
| 96 |
if ( (*this_).data == NULL ) |
| 97 |
{ |
| 98 |
result = false; /* cannot happen on initialized objects */ |
| 99 |
} |
| 100 |
else |
| 101 |
{ |
| 102 |
result = data_visible_classifier_is_valid( (*this_).data ); |
| 103 |
} |
| 104 |
return result; |
| 105 |
} |
| 106 |
|
| 107 |
static inline const geometry_rectangle_t *layout_visible_classifier_get_symbol_box_const ( const layout_visible_classifier_t *this_ ) |
| 108 |
{ |
| 109 |
return &((*this_).symbol_box); |
| 110 |
} |
| 111 |
|
| 112 |
static inline void layout_visible_classifier_set_symbol_box ( layout_visible_classifier_t *this_, const geometry_rectangle_t *symbol_box ) |
| 113 |
{ |
| 114 |
geometry_rectangle_replace( &((*this_).symbol_box), symbol_box ); |
| 115 |
|
| 116 |
/* update the cached value of envelope_box */ |
| 117 |
layout_visible_classifier_private_update_envelope_box( this_ ); |
| 118 |
} |
| 119 |
|
| 120 |
static inline const geometry_rectangle_t *layout_visible_classifier_get_space_const ( const layout_visible_classifier_t *this_ ) |
| 121 |
{ |
| 122 |
return &((*this_).space); |
| 123 |
} |
| 124 |
|
| 125 |
static inline void layout_visible_classifier_set_space ( layout_visible_classifier_t *this_, const geometry_rectangle_t *space ) |
| 126 |
{ |
| 127 |
geometry_rectangle_replace( &((*this_).space), space ); |
| 128 |
|
| 129 |
/* update the cached value of envelope_box */ |
| 130 |
layout_visible_classifier_private_update_envelope_box( this_ ); |
| 131 |
} |
| 132 |
|
| 133 |
static inline const geometry_rectangle_t *layout_visible_classifier_get_label_box_const ( const layout_visible_classifier_t *this_ ) |
| 134 |
{ |
| 135 |
return &((*this_).label_box); |
| 136 |
} |
| 137 |
|
| 138 |
static inline void layout_visible_classifier_set_label_box ( layout_visible_classifier_t *this_, const geometry_rectangle_t *label_box ) |
| 139 |
{ |
| 140 |
geometry_rectangle_replace( &((*this_).label_box), label_box ); |
| 141 |
|
| 142 |
/* update the cached value of envelope_box */ |
| 143 |
layout_visible_classifier_private_update_envelope_box( this_ ); |
| 144 |
} |
| 145 |
|
| 146 |
static inline void layout_visible_classifier_set_label_anchor ( layout_visible_classifier_t *this_, |
| 147 |
geometry_h_align_t label_h_anchor, |
| 148 |
geometry_v_align_t label_v_anchor ) |
| 149 |
{ |
| 150 |
(*this_).label_h_anchor = label_h_anchor; |
| 151 |
(*this_).label_v_anchor = label_v_anchor; |
| 152 |
} |
| 153 |
|
| 154 |
static inline const geometry_rectangle_t *layout_visible_classifier_get_icon_box_const ( const layout_visible_classifier_t *this_ ) |
| 155 |
{ |
| 156 |
return &((*this_).icon_box); |
| 157 |
} |
| 158 |
|
| 159 |
static inline void layout_visible_classifier_set_icon_box ( layout_visible_classifier_t *this_, const geometry_rectangle_t *icon_box ) |
| 160 |
{ |
| 161 |
geometry_rectangle_replace( &((*this_).icon_box), icon_box ); |
| 162 |
|
| 163 |
/* update the cached value of envelope_box */ |
| 164 |
layout_visible_classifier_private_update_envelope_box( this_ ); |
| 165 |
} |
| 166 |
|
| 167 |
static inline geometry_rectangle_t layout_visible_classifier_get_envelope_box ( const layout_visible_classifier_t *this_ ) |
| 168 |
{ |
| 169 |
return (*this_).envelope_box_cache; |
| 170 |
} |
| 171 |
|
| 172 |
static inline const geometry_rectangle_t *layout_visible_classifier_get_envelope_box_const ( const layout_visible_classifier_t *this_ ) |
| 173 |
{ |
| 174 |
/* return the cached value */ |
| 175 |
return &((*this_).envelope_box_cache); |
| 176 |
} |
| 177 |
|
| 178 |
static inline void layout_visible_classifier_shift ( layout_visible_classifier_t *this_, const geometry_offset_t *offset ) |
| 179 |
{ |
| 180 |
assert( offset != NULL ); |
| 181 |
const double delta_x = geometry_offset_get_dx( offset ); |
| 182 |
const double delta_y = geometry_offset_get_dy( offset ); |
| 183 |
|
| 184 |
geometry_rectangle_shift( &((*this_).symbol_box), delta_x, delta_y ); |
| 185 |
geometry_rectangle_shift( &((*this_).space), delta_x, delta_y ); |
| 186 |
geometry_rectangle_shift( &((*this_).label_box), delta_x, delta_y ); |
| 187 |
geometry_rectangle_shift( &((*this_).icon_box), delta_x, delta_y ); |
| 188 |
|
| 189 |
/* update the cached value of envelope_box */ |
| 190 |
geometry_rectangle_shift( &((*this_).envelope_box_cache), delta_x, delta_y ); |
| 191 |
} |
| 192 |
|
| 193 |
static inline const data_visible_classifier_t *layout_visible_classifier_get_data_const ( const layout_visible_classifier_t *this_ ) |
| 194 |
{ |
| 195 |
return (*this_).data; |
| 196 |
} |
| 197 |
|
| 198 |
static inline const data_classifier_t *layout_visible_classifier_get_classifier_const ( const layout_visible_classifier_t *this_ ) |
| 199 |
{ |
| 200 |
return data_visible_classifier_get_classifier_const ( (*this_).data ); |
| 201 |
} |
| 202 |
|
| 203 |
static inline const data_diagramelement_t *layout_visible_classifier_get_diagramelement_const ( const layout_visible_classifier_t *this_ ) |
| 204 |
{ |
| 205 |
return data_visible_classifier_get_diagramelement_const ( (*this_).data ); |
| 206 |
} |
| 207 |
|
| 208 |
static inline data_row_t layout_visible_classifier_get_classifier_id ( const layout_visible_classifier_t *this_ ) |
| 209 |
{ |
| 210 |
return data_classifier_get_row_id( data_visible_classifier_get_classifier_const ( (*this_).data ) ); |
| 211 |
} |
| 212 |
|
| 213 |
static inline data_row_t layout_visible_classifier_get_diagramelement_id ( const layout_visible_classifier_t *this_ ) |
| 214 |
{ |
| 215 |
return data_diagramelement_get_row_id( data_visible_classifier_get_diagramelement_const ( (*this_).data ) ); |
| 216 |
} |
| 217 |
|
| 218 |
static inline bool layout_visible_classifier_is_equal_diagramelement_id ( const layout_visible_classifier_t *this_, |
| 219 |
const layout_visible_classifier_t *that ) |
| 220 |
{ |
| 221 |
const data_row_t this_diagele_id = layout_visible_classifier_get_diagramelement_id( this_ ); |
| 222 |
const data_row_t that_diagele_id = layout_visible_classifier_get_diagramelement_id( that ); |
| 223 |
return ( this_diagele_id == that_diagele_id ); |
| 224 |
} |
| 225 |
|
| 226 |
static inline void layout_visible_classifier_private_update_envelope_box ( layout_visible_classifier_t *this_ ) |
| 227 |
{ |
| 228 |
geometry_rectangle_t intermediate; |
| 229 |
geometry_rectangle_init_by_bounds( &intermediate, &((*this_).symbol_box), &((*this_).label_box) ); |
| 230 |
/* Note: the icon_box is always contained within the symbol_box */ |
| 231 |
geometry_rectangle_init_by_bounds( &((*this_).envelope_box_cache), &intermediate, &((*this_).space) ); |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
/* |
| 236 |
Copyright 2018-2026 Andreas Warnke |
| 237 |
|
| 238 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 239 |
you may not use this file except in compliance with the License. |
| 240 |
You may obtain a copy of the License at |
| 241 |
|
| 242 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 243 |
|
| 244 |
Unless required by applicable law or agreed to in writing, software |
| 245 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 246 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 247 |
See the License for the specific language governing permissions and |
| 248 |
limitations under the License. |
| 249 |
*/ |