Debian Codegraph @

pencil/include/layout/layout_relationship.inl

raw
1 /* File: layout_relationship.inl; Copyright and License: see below */
2
3 #include <assert.h>
4
5 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 assert ( NULL != relationship_data );
13 assert ( NULL != from_classifier );
14 assert ( NULL != to_classifier );
15
16 (*this_).visible = PENCIL_VISIBILITY_HIDE;
17 geometry_connector_init_empty( &((*this_).shape) );
18 geometry_rectangle_init_empty( &((*this_).label_box) );
19 (*this_).data = relationship_data;
20 (*this_).from_classifier = from_classifier;
21 (*this_).to_classifier = to_classifier;
22 (*this_).from_feature = from_feature;
23 (*this_).to_feature = to_feature;
24 }
25
26 static inline void layout_relationship_destroy ( layout_relationship_t *this_ )
27 {
28 geometry_connector_destroy( &((*this_).shape) );
29 geometry_rectangle_destroy( &((*this_).label_box) );
30 (*this_).data = NULL;
31 }
32
33 static inline bool layout_relationship_is_valid ( const layout_relationship_t *this_ )
34 {
35 bool result;
36 if (( (*this_).data == NULL )||( (*this_).from_classifier == NULL )||( (*this_).to_classifier == NULL ))
37 {
38 result = false; /* cannot happen on initialized objects */
39 }
40 else
41 {
42 const data_row_t from_classifier_id = data_relationship_get_from_classifier_row_id( (*this_).data );
43 const data_row_t to_classifier_id = data_relationship_get_to_classifier_row_id( (*this_).data );
44 const data_row_t from_feature_id = data_relationship_get_from_feature_row_id( (*this_).data );
45 const data_row_t to_feature_id = data_relationship_get_to_feature_row_id( (*this_).data );
46 const bool from_feature_ok = ( NULL == (*this_).from_feature )
47 ? ( from_feature_id == DATA_ROW_VOID )
48 : ( from_feature_id == layout_feature_get_feature_id( (*this_).from_feature ) );
49 const bool to_feature_ok = ( NULL == (*this_).to_feature )
50 ? ( to_feature_id == DATA_ROW_VOID )
51 : ( to_feature_id == layout_feature_get_feature_id( (*this_).to_feature ) );
52 result = data_relationship_is_valid( (*this_).data )
53 && layout_visible_classifier_is_valid( (*this_).from_classifier )
54 && layout_visible_classifier_is_valid( (*this_).to_classifier )
55 && ( from_classifier_id == layout_visible_classifier_get_classifier_id( (*this_).from_classifier ) )
56 && ( to_classifier_id == layout_visible_classifier_get_classifier_id( (*this_).to_classifier ) )
57 && from_feature_ok
58 && to_feature_ok;
59 }
60 return result;
61 }
62
63 static inline pencil_visibility_t layout_relationship_get_visibility ( const layout_relationship_t *this_ )
64 {
65 return (*this_).visible;
66 }
67
68 static inline void layout_relationship_set_visibility ( layout_relationship_t *this_, pencil_visibility_t visible )
69 {
70 (*this_).visible = visible;
71 }
72
73 static inline const geometry_connector_t *layout_relationship_get_shape_const ( const layout_relationship_t *this_ )
74 {
75 return &((*this_).shape);
76 }
77
78 static inline void layout_relationship_set_shape ( layout_relationship_t *this_, const geometry_connector_t *shape )
79 {
80 geometry_connector_replace ( &((*this_).shape), shape );
81 }
82
83 static inline geometry_point_t layout_relationship_get_middle ( const layout_relationship_t *this_ )
84 {
85 double connector_length = geometry_connector_get_length( &((*this_).shape) );
86 return geometry_connector_calculate_waypoint( &((*this_).shape), connector_length/2.0 );
87 }
88
89 static inline const geometry_rectangle_t *layout_relationship_get_label_box_const ( const layout_relationship_t *this_ )
90 {
91 return &((*this_).label_box);
92 }
93
94 static inline void layout_relationship_set_label_box ( layout_relationship_t *this_, const geometry_rectangle_t *label_box )
95 {
96 geometry_rectangle_replace( &((*this_).label_box), label_box );
97 }
98
99 static inline const data_relationship_t *layout_relationship_get_data_const ( const layout_relationship_t *this_ )
100 {
101 assert ( NULL != (*this_).data );
102 return (*this_).data;
103 }
104
105 static inline layout_visible_classifier_t *layout_relationship_get_from_classifier_ptr ( const layout_relationship_t *this_ )
106 {
107 return (*this_).from_classifier;
108 }
109
110 static inline layout_visible_classifier_t *layout_relationship_get_to_classifier_ptr ( const layout_relationship_t *this_ )
111 {
112 return (*this_).to_classifier;
113 }
114
115 static inline layout_feature_t *layout_relationship_get_from_feature_ptr ( const layout_relationship_t *this_ )
116 {
117 return (*this_).from_feature;
118 }
119
120 static inline layout_feature_t *layout_relationship_get_to_feature_ptr ( const layout_relationship_t *this_ )
121 {
122 return (*this_).to_feature;
123 }
124
125 static inline data_row_t layout_relationship_get_relationship_id ( const layout_relationship_t *this_ )
126 {
127 return data_relationship_get_row_id( (*this_).data );
128 }
129
130 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 if ( NULL != (*this_).from_feature )
135 {
136 result = layout_feature_get_symbol_box_const( (*this_).from_feature );
137 }
138 else
139 {
140 const geometry_rectangle_t *from_symbol = layout_visible_classifier_get_symbol_box_const( (*this_).from_classifier );
141 const geometry_rectangle_t *from_space = layout_visible_classifier_get_space_const( (*this_).from_classifier );
142 const geometry_rectangle_t *to_symbol = layout_visible_classifier_get_symbol_box_const( (*this_).to_classifier );
143 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 result = from_space;
147 }
148 else
149 {
150 result = from_symbol;
151 }
152 }
153
154 return result;
155 }
156
157 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 if ( NULL != (*this_).to_feature )
162 {
163 result = layout_feature_get_symbol_box_const( (*this_).to_feature );
164 }
165 else
166 {
167 const geometry_rectangle_t *to_symbol = layout_visible_classifier_get_symbol_box_const( (*this_).to_classifier );
168 const geometry_rectangle_t *to_space = layout_visible_classifier_get_space_const( (*this_).to_classifier );
169 const geometry_rectangle_t *from_symbol = layout_visible_classifier_get_symbol_box_const( (*this_).from_classifier );
170 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 result = to_space;
174 }
175 else
176 {
177 result = to_symbol;
178 }
179 }
180
181 return result;
182 }
183
184
185 /*
186 Copyright 2018-2026 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 */