Line data Source code
1 : /* File: layout_relationship.inl; Copyright and License: see below */
2 :
3 : #include <assert.h>
4 :
5 856 : static inline void layout_relationship_init ( layout_relationship_t *this_,
6 : const data_relationship_t *relationship_data,
7 : layout_visible_classifier_t *from_classifier,
8 : layout_visible_classifier_t *to_classifier,
9 : layout_feature_t *from_feature,
10 : layout_feature_t *to_feature )
11 : {
12 856 : assert ( NULL != relationship_data );
13 856 : assert ( NULL != from_classifier );
14 856 : assert ( NULL != to_classifier );
15 :
16 856 : (*this_).visible = PENCIL_VISIBILITY_HIDE;
17 856 : geometry_connector_init_empty( &((*this_).shape) );
18 856 : geometry_rectangle_init_empty( &((*this_).label_box) );
19 856 : (*this_).data = relationship_data;
20 856 : (*this_).from_classifier = from_classifier;
21 856 : (*this_).to_classifier = to_classifier;
22 856 : (*this_).from_feature = from_feature;
23 856 : (*this_).to_feature = to_feature;
24 856 : }
25 :
26 856 : static inline void layout_relationship_destroy ( layout_relationship_t *this_ )
27 : {
28 856 : geometry_connector_destroy( &((*this_).shape) );
29 856 : geometry_rectangle_destroy( &((*this_).label_box) );
30 856 : (*this_).data = NULL;
31 856 : }
32 :
33 1712 : static inline bool layout_relationship_is_valid ( const layout_relationship_t *this_ )
34 : {
35 : bool result;
36 1712 : if (( (*this_).data == NULL )||( (*this_).from_classifier == NULL )||( (*this_).to_classifier == NULL ))
37 : {
38 0 : result = false; /* cannot happen on initialized objects */
39 : }
40 : else
41 : {
42 1712 : const data_row_t from_classifier_id = data_relationship_get_from_classifier_row_id( (*this_).data );
43 1712 : const data_row_t to_classifier_id = data_relationship_get_to_classifier_row_id( (*this_).data );
44 1712 : const data_row_t from_feature_id = data_relationship_get_from_feature_row_id( (*this_).data );
45 1712 : const data_row_t to_feature_id = data_relationship_get_to_feature_row_id( (*this_).data );
46 3424 : const bool from_feature_ok = ( NULL == (*this_).from_feature )
47 : ? ( from_feature_id == DATA_ROW_VOID )
48 1712 : : ( from_feature_id == layout_feature_get_feature_id( (*this_).from_feature ) );
49 3424 : const bool to_feature_ok = ( NULL == (*this_).to_feature )
50 : ? ( to_feature_id == DATA_ROW_VOID )
51 1712 : : ( to_feature_id == layout_feature_get_feature_id( (*this_).to_feature ) );
52 3424 : result = data_relationship_is_valid( (*this_).data )
53 1712 : && layout_visible_classifier_is_valid( (*this_).from_classifier )
54 1712 : && layout_visible_classifier_is_valid( (*this_).to_classifier )
55 1712 : && ( from_classifier_id == layout_visible_classifier_get_classifier_id( (*this_).from_classifier ) )
56 1712 : && ( to_classifier_id == layout_visible_classifier_get_classifier_id( (*this_).to_classifier ) )
57 1712 : && from_feature_ok
58 3424 : && to_feature_ok;
59 : }
60 1712 : return result;
61 : }
62 :
63 0 : static inline pencil_visibility_t layout_relationship_get_visibility ( const layout_relationship_t *this_ )
64 : {
65 0 : return (*this_).visible;
66 : }
67 :
68 0 : static inline void layout_relationship_set_visibility ( layout_relationship_t *this_, pencil_visibility_t visible )
69 : {
70 0 : (*this_).visible = visible;
71 0 : }
72 :
73 0 : static inline const geometry_connector_t *layout_relationship_get_shape_const ( const layout_relationship_t *this_ )
74 : {
75 0 : return &((*this_).shape);
76 : }
77 :
78 0 : static inline void layout_relationship_set_shape ( layout_relationship_t *this_, const geometry_connector_t *shape )
79 : {
80 0 : geometry_connector_replace ( &((*this_).shape), shape );
81 0 : }
82 :
83 0 : static inline geometry_point_t layout_relationship_get_middle ( const layout_relationship_t *this_ )
84 : {
85 0 : double connector_length = geometry_connector_get_length( &((*this_).shape) );
86 0 : return geometry_connector_calculate_waypoint( &((*this_).shape), connector_length/2.0 );
87 : }
88 :
89 0 : static inline const geometry_rectangle_t *layout_relationship_get_label_box_const ( const layout_relationship_t *this_ )
90 : {
91 0 : return &((*this_).label_box);
92 : }
93 :
94 0 : static inline void layout_relationship_set_label_box ( layout_relationship_t *this_, const geometry_rectangle_t *label_box )
95 : {
96 0 : geometry_rectangle_replace( &((*this_).label_box), label_box );
97 0 : }
98 :
99 0 : static inline const data_relationship_t *layout_relationship_get_data_const ( const layout_relationship_t *this_ )
100 : {
101 0 : assert ( NULL != (*this_).data );
102 0 : return (*this_).data;
103 : }
104 :
105 0 : static inline layout_visible_classifier_t *layout_relationship_get_from_classifier_ptr ( const layout_relationship_t *this_ )
106 : {
107 0 : return (*this_).from_classifier;
108 : }
109 :
110 0 : static inline layout_visible_classifier_t *layout_relationship_get_to_classifier_ptr ( const layout_relationship_t *this_ )
111 : {
112 0 : return (*this_).to_classifier;
113 : }
114 :
115 0 : static inline layout_feature_t *layout_relationship_get_from_feature_ptr ( const layout_relationship_t *this_ )
116 : {
117 0 : return (*this_).from_feature;
118 : }
119 :
120 0 : static inline layout_feature_t *layout_relationship_get_to_feature_ptr ( const layout_relationship_t *this_ )
121 : {
122 0 : return (*this_).to_feature;
123 : }
124 :
125 0 : static inline data_row_t layout_relationship_get_relationship_id ( const layout_relationship_t *this_ )
126 : {
127 0 : return data_relationship_get_row_id( (*this_).data );
128 : }
129 :
130 0 : static inline const geometry_rectangle_t *layout_relationship_get_from_box_const ( const layout_relationship_t *this_ )
131 : {
132 : const geometry_rectangle_t *result;
133 :
134 0 : if ( NULL != (*this_).from_feature )
135 : {
136 0 : result = layout_feature_get_symbol_box_const( (*this_).from_feature );
137 : }
138 : else
139 : {
140 0 : const geometry_rectangle_t *from_symbol = layout_visible_classifier_get_symbol_box_const( (*this_).from_classifier );
141 0 : const geometry_rectangle_t *from_space = layout_visible_classifier_get_space_const( (*this_).from_classifier );
142 0 : const geometry_rectangle_t *to_symbol = layout_visible_classifier_get_symbol_box_const( (*this_).to_classifier );
143 0 : if( geometry_rectangle_is_containing( from_space, to_symbol ) )
144 : {
145 : /* special case: if from classifier contains to classifier, take the space box as source */
146 0 : result = from_space;
147 : }
148 : else
149 : {
150 0 : result = from_symbol;
151 : }
152 : }
153 :
154 0 : return result;
155 : }
156 :
157 0 : static inline const geometry_rectangle_t *layout_relationship_get_to_box_const ( const layout_relationship_t *this_ )
158 : {
159 : const geometry_rectangle_t *result;
160 :
161 0 : if ( NULL != (*this_).to_feature )
162 : {
163 0 : result = layout_feature_get_symbol_box_const( (*this_).to_feature );
164 : }
165 : else
166 : {
167 0 : const geometry_rectangle_t *to_symbol = layout_visible_classifier_get_symbol_box_const( (*this_).to_classifier );
168 0 : const geometry_rectangle_t *to_space = layout_visible_classifier_get_space_const( (*this_).to_classifier );
169 0 : const geometry_rectangle_t *from_symbol = layout_visible_classifier_get_symbol_box_const( (*this_).from_classifier );
170 0 : if( geometry_rectangle_is_containing( to_space, from_symbol ) )
171 : {
172 : /* special case: if to classifier contains from classifier, take the space box as destination */
173 0 : result = to_space;
174 : }
175 : else
176 : {
177 0 : result = to_symbol;
178 : }
179 : }
180 :
181 0 : return result;
182 : }
183 :
184 :
185 : /*
186 : Copyright 2018-2025 Andreas Warnke
187 :
188 : Licensed under the Apache License, Version 2.0 (the "License");
189 : you may not use this file except in compliance with the License.
190 : You may obtain a copy of the License at
191 :
192 : http://www.apache.org/licenses/LICENSE-2.0
193 :
194 : Unless required by applicable law or agreed to in writing, software
195 : distributed under the License is distributed on an "AS IS" BASIS,
196 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
197 : See the License for the specific language governing permissions and
198 : limitations under the License.
199 : */
|