Line data Source code
1 : /* File: ctrl_classifier_trigger.inl; Copyright and License: see below */
2 :
3 : #include <assert.h>
4 : #include "u8/u8_log.h"
5 :
6 47 : static inline void ctrl_classifier_trigger_init ( ctrl_classifier_trigger_t *this_,
7 : consistency_feature_t *feature,
8 : consistency_lifeline_t *lifeline,
9 : consistency_relationship_t *relationship )
10 : {
11 47 : assert( feature != NULL );
12 47 : assert( lifeline != NULL );
13 47 : assert( relationship != NULL );
14 47 : (*this_).feature = feature;
15 47 : (*this_).lifeline = lifeline;
16 47 : (*this_).relationship = relationship;
17 47 : }
18 :
19 47 : static inline void ctrl_classifier_trigger_destroy ( ctrl_classifier_trigger_t *this_ )
20 : {
21 47 : (*this_).feature = NULL;
22 47 : (*this_).lifeline = NULL;
23 47 : (*this_).relationship = NULL;
24 47 : }
25 :
26 15 : static inline u8_error_t ctrl_classifier_trigger_post_delete_feature( ctrl_classifier_trigger_t *this_,
27 : const data_feature_t *deleted_feature )
28 : {
29 15 : assert( NULL != deleted_feature );
30 15 : u8_error_t result_err = U8_ERROR_NONE;
31 :
32 15 : const data_feature_type_t f_type = data_feature_get_main_type( deleted_feature );
33 15 : if ( f_type == DATA_FEATURE_TYPE_LIFELINE )
34 : {
35 : /* if a lifeline was deleted, check if to unlink the lifeline from the diagramelement */
36 9 : result_err |= consistency_lifeline_unlink_lifeline( (*this_).lifeline, deleted_feature );
37 : }
38 :
39 15 : return result_err;
40 : }
41 :
42 39 : static inline u8_error_t ctrl_classifier_trigger_post_create_feature( ctrl_classifier_trigger_t *this_,
43 : const data_feature_t *create_feature )
44 : {
45 39 : assert( NULL != create_feature );
46 39 : u8_error_t result_err = U8_ERROR_NONE;
47 :
48 39 : const data_feature_type_t f_type = data_feature_get_main_type( create_feature );
49 39 : if ( f_type != DATA_FEATURE_TYPE_LIFELINE )
50 : {
51 : /* if a non-lifeline was created, check if it is visible */
52 21 : const data_row_t classifier_id = data_feature_get_classifier_row( create_feature );
53 21 : consistency_stat_t stat = CONSISTENCY_STAT_ZERO;
54 21 : result_err |= consistency_feature_delete_invisibles_of_classifier( (*this_).feature, classifier_id, &stat );
55 21 : if ( consistency_stat_get_features( &stat ) != 0 )
56 : {
57 0 : U8_LOG_WARNING("A feature was created. It was invisible. It is deleted again.");
58 0 : assert( consistency_stat_get_total_count( &stat ) == -1 ); /* otherwise the model was already inconsistent before... */
59 0 : result_err |= U8_ERROR_DIAGRAM_HIDES_FEATURES;
60 : }
61 : }
62 :
63 39 : return result_err;
64 : }
65 :
66 19 : static inline u8_error_t ctrl_classifier_trigger_post_create_relationship( ctrl_classifier_trigger_t *this_,
67 : const data_relationship_t *create_relationship )
68 : {
69 19 : assert( NULL != create_relationship );
70 19 : u8_error_t result_err = U8_ERROR_NONE;
71 :
72 : /* delete immediately if not visible */
73 : int32_t deleted_relationships;
74 19 : const data_row_t classifier_id = data_relationship_get_from_classifier_row( create_relationship );
75 19 : result_err |= consistency_relationship_delete_invisibles_at_classifier( (*this_).relationship,
76 : classifier_id,
77 : &deleted_relationships
78 : );
79 19 : if ( deleted_relationships != 0 )
80 : {
81 0 : U8_LOG_WARNING("A relationship was created. It was invisible. It is deleted again.");
82 0 : assert( deleted_relationships == 1 ); /* otherwise the model was already inconsistent before... */
83 0 : result_err |= U8_ERROR_DIAGRAM_HIDES_RELATIONSHIPS;
84 : }
85 :
86 19 : return result_err;
87 : }
88 :
89 :
90 : /*
91 : Copyright 2018-2026 Andreas Warnke
92 :
93 : Licensed under the Apache License, Version 2.0 (the "License");
94 : you may not use this file except in compliance with the License.
95 : You may obtain a copy of the License at
96 :
97 : http://www.apache.org/licenses/LICENSE-2.0
98 :
99 : Unless required by applicable law or agreed to in writing, software
100 : distributed under the License is distributed on an "AS IS" BASIS,
101 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
102 : See the License for the specific language governing permissions and
103 : limitations under the License.
104 : */
|