LCOV - code coverage report
Current view: top level - ctrl/source - ctrl_diagram_controller.c (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.61.0_covts Lines: 202 247 81.8 %
Date: 2024-10-26 21:44:38 Functions: 14 16 87.5 %

          Line data    Source code
       1             : /* File: ctrl_diagram_controller.c; Copyright and License: see below */
       2             : 
       3             : #include "ctrl_diagram_controller.h"
       4             : #include "u8/u8_trace.h"
       5             : #include "u8/u8_log.h"
       6             : 
       7          42 : void ctrl_diagram_controller_init ( ctrl_diagram_controller_t *this_,
       8             :                                     ctrl_undo_redo_list_t *undo_redo_list,
       9             :                                     ctrl_diagram_trigger_t *policy_enforcer,
      10             :                                     data_database_t *database,
      11             :                                     data_database_reader_t *db_reader,
      12             :                                     data_database_writer_t *db_writer )
      13             : {
      14          42 :     U8_TRACE_BEGIN();
      15             : 
      16          42 :     (*this_).undo_redo_list = undo_redo_list;
      17          42 :     (*this_).policy_enforcer = policy_enforcer;
      18          42 :     (*this_).database = database;
      19          42 :     (*this_).db_reader = db_reader;
      20          42 :     (*this_).db_writer = db_writer;
      21             : 
      22          42 :     U8_TRACE_END();
      23          42 : }
      24             : 
      25          42 : void ctrl_diagram_controller_destroy ( ctrl_diagram_controller_t *this_ )
      26             : {
      27          42 :     U8_TRACE_BEGIN();
      28             : 
      29          42 :     (*this_).undo_redo_list = NULL;
      30          42 :     (*this_).policy_enforcer = NULL;
      31          42 :     (*this_).database = NULL;
      32          42 :     (*this_).db_reader = NULL;
      33          42 :     (*this_).db_writer = NULL;
      34             : 
      35          42 :     U8_TRACE_END();
      36          42 : }
      37             : 
      38             : /* ================================ DIAGRAM ================================ */
      39             : 
      40          29 : u8_error_t ctrl_diagram_controller_create_diagram ( ctrl_diagram_controller_t *this_,
      41             :                                                     const data_diagram_t *new_diagram,
      42             :                                                     ctrl_undo_redo_action_boundary_t add_to_latest_undo_set,
      43             :                                                     data_row_id_t* out_new_id )
      44             : {
      45          29 :     U8_TRACE_BEGIN();
      46          29 :     assert( NULL != new_diagram );
      47             :     data_diagram_t to_be_created;
      48          29 :     u8_error_t result = U8_ERROR_NONE;
      49             :     u8_error_t data_result;
      50             :     data_row_id_t new_id;
      51             : 
      52          29 :     data_diagram_copy( &to_be_created, new_diagram );
      53             : 
      54          29 :     data_result = data_database_writer_create_diagram( (*this_).db_writer, &to_be_created, &new_id );
      55          29 :     if ( U8_ERROR_NONE == data_result )
      56             :     {
      57             :         /* store new id to diagram object */
      58          28 :         data_diagram_set_row_id( &to_be_created, new_id );
      59             : 
      60             :         /* if this action shall be stored to the latest set of actions in the undo redo list, remove the boundary: */
      61          28 :         if ( add_to_latest_undo_set == CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND )
      62             :         {
      63             :             u8_error_t internal_err;
      64           1 :             internal_err = ctrl_undo_redo_list_remove_boundary_from_end( (*this_).undo_redo_list );
      65           1 :             if ( U8_ERROR_NONE != internal_err )
      66             :             {
      67           0 :                 U8_LOG_ERROR_HEX( "unexpected internal error", internal_err );
      68             :             }
      69             :         }
      70             : 
      71             :         /* store the new diagram to the undo redo list */
      72          28 :         ctrl_undo_redo_list_add_create_diagram( (*this_).undo_redo_list, &to_be_created );
      73          28 :         ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
      74             : 
      75             :         /* copy new id to out parameter */
      76          28 :         if ( NULL != out_new_id )
      77             :         {
      78          28 :             *out_new_id = new_id;
      79             :         }
      80             :     }
      81          29 :     result = (u8_error_t) data_result;
      82             : 
      83          29 :     data_diagram_destroy( &to_be_created );
      84             : 
      85          29 :     U8_TRACE_END_ERR( result );
      86          29 :     return result;
      87             : }
      88             : 
      89         134 : u8_error_t ctrl_diagram_controller_private_create_child_diagram ( ctrl_diagram_controller_t *this_,
      90             :                                                                   data_row_id_t parent_diagram_id,
      91             :                                                                   data_diagram_type_t diagram_type,
      92             :                                                                   const char* diagram_name,
      93             :                                                                   data_row_id_t* out_new_id )
      94             : {
      95         134 :     U8_TRACE_BEGIN();
      96             :     data_diagram_t to_be_created;
      97         134 :     u8_error_t result = U8_ERROR_NONE;
      98             :     u8_error_t data_result;
      99             :     data_row_id_t new_id;
     100             : 
     101         134 :     data_diagram_init_new( &to_be_created, parent_diagram_id, diagram_type, "", diagram_name, "", 0, DATA_DIAGRAM_FLAG_NONE );
     102             : 
     103         134 :     data_result = data_database_writer_create_diagram( (*this_).db_writer, &to_be_created, &new_id );
     104         134 :     if ( U8_ERROR_NONE == data_result )
     105             :     {
     106             :         /* store new id to diagram object */
     107         134 :         data_diagram_set_row_id( &to_be_created, new_id );
     108             : 
     109             :         /* store the new diagram to the undo redo list */
     110         134 :         ctrl_undo_redo_list_add_create_diagram( (*this_).undo_redo_list, &to_be_created );
     111         134 :         ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
     112             : 
     113             :         /* copy new id to out parameter */
     114         134 :         if ( NULL != out_new_id )
     115             :         {
     116         134 :             *out_new_id = new_id;
     117             :         }
     118             :     }
     119         134 :     result = (u8_error_t) data_result;
     120             : 
     121         134 :     data_diagram_destroy( &to_be_created );
     122             : 
     123         134 :     U8_TRACE_END_ERR( result );
     124         134 :     return result;
     125             : }
     126             : 
     127           5 : u8_error_t ctrl_diagram_controller_create_root_diagram_if_not_exists ( ctrl_diagram_controller_t *this_,
     128             :                                                                        data_diagram_type_t diagram_type,
     129             :                                                                        const char* diagram_name,
     130             :                                                                        data_row_id_t* out_new_id )
     131             : {
     132           5 :     U8_TRACE_BEGIN();
     133           5 :     u8_error_t result = U8_ERROR_NONE;
     134             :     u8_error_t data_result;
     135             :     data_diagram_t root_diag_buf[1];
     136             : 
     137             :     /* load all without parent */
     138             :     uint32_t count;
     139           5 :     data_result = data_database_reader_get_diagrams_by_parent_id( (*this_).db_reader,
     140             :                                                                   DATA_ROW_ID_VOID,
     141             :                                                                   1,
     142             :                                                                   &(root_diag_buf),
     143             :                                                                   &count
     144             :                                                                 );
     145           5 :     if ( U8_ERROR_NONE != data_result )
     146             :     {
     147           0 :         result = (u8_error_t) data_result;
     148             :     }
     149             :     else
     150             :     {
     151           5 :         if ( 0 == count )
     152             :         {
     153             :             /* no root diagram exists */
     154           5 :             result = ctrl_diagram_controller_private_create_child_diagram( this_, DATA_ROW_ID_VOID, diagram_type, diagram_name, out_new_id );
     155             :         }
     156             :         else
     157             :         {
     158           0 :             if ( NULL != out_new_id )
     159             :             {
     160           0 :                 *out_new_id = DATA_ROW_ID_VOID;
     161             :             }
     162             :         }
     163             :     }
     164             : 
     165           5 :     U8_TRACE_END_ERR( result );
     166           5 :     return result;
     167             : }
     168             : 
     169           3 : u8_error_t ctrl_diagram_controller_delete_diagram ( ctrl_diagram_controller_t *this_,
     170             :                                                     data_row_id_t obj_id,
     171             :                                                     ctrl_undo_redo_action_boundary_t add_to_latest_undo_set )
     172             : {
     173           3 :     U8_TRACE_BEGIN();
     174           3 :     u8_error_t result = U8_ERROR_NONE;
     175             : 
     176             :     /* delete diagram */
     177             :     /* data_database_writer_delete_diagram checks that this diagram is not a parent */
     178             :     /* and is not referenced by diagramelements */
     179             :     /* fails otherwise: U8_ERROR_OBJECT_STILL_REFERENCED */
     180             :     data_diagram_t old_diagram;
     181             :     u8_error_t current_result3;
     182           3 :     current_result3 = data_database_writer_delete_diagram ( (*this_).db_writer, obj_id, &old_diagram );
     183             : 
     184           3 :     if ( U8_ERROR_NONE == current_result3 )
     185             :     {
     186             :         /* if this action shall be stored to the latest set of actions in the undo redo list, remove the boundary: */
     187           2 :         if ( add_to_latest_undo_set == CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND )
     188             :         {
     189             :             u8_error_t internal_err;
     190           2 :             internal_err = ctrl_undo_redo_list_remove_boundary_from_end( (*this_).undo_redo_list );
     191           2 :             if ( U8_ERROR_NONE != internal_err )
     192             :             {
     193           0 :                 U8_LOG_ERROR_HEX( "unexpected internal error", internal_err );
     194             :             }
     195             :         }
     196             : 
     197             :         /* store the deleted diagram to the undo redo list */
     198           2 :         ctrl_undo_redo_list_add_delete_diagram( (*this_).undo_redo_list, &old_diagram );
     199           2 :         ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
     200             : 
     201           2 :         data_diagram_destroy( &old_diagram );
     202             :     }
     203             : 
     204           3 :     result |= (u8_error_t) current_result3;
     205             : 
     206           3 :     U8_TRACE_END_ERR( result );
     207           3 :     return result;
     208             : }
     209             : 
     210           0 : u8_error_t ctrl_diagram_controller_update_diagram_parent_id ( ctrl_diagram_controller_t *this_,
     211             :                                                               data_row_id_t diagram_id,
     212             :                                                               data_row_id_t new_diagram_parent_id,
     213             :                                                               ctrl_undo_redo_action_boundary_t add_to_latest_undo_set )
     214             : {
     215           0 :     U8_TRACE_BEGIN();
     216           0 :     u8_error_t result = U8_ERROR_NONE;
     217             :     u8_error_t data_result;
     218             :     data_diagram_t old_diagram;
     219             : 
     220           0 :     data_result = data_database_writer_update_diagram_parent_id( (*this_).db_writer, diagram_id, new_diagram_parent_id, &old_diagram );
     221           0 :     if ( U8_ERROR_NONE == data_result )
     222             :     {
     223             :         /* prepare the new diagram */
     224             :         data_diagram_t new_diagram;
     225           0 :         data_diagram_copy( &new_diagram, &old_diagram );
     226           0 :         data_diagram_set_parent_row_id( &new_diagram, new_diagram_parent_id );
     227             : 
     228             :         /* if this action shall be stored to the latest set of actions in the undo redo list, remove the boundary: */
     229           0 :         if ( add_to_latest_undo_set == CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND )
     230             :         {
     231             :             u8_error_t internal_err;
     232           0 :             internal_err = ctrl_undo_redo_list_remove_boundary_from_end( (*this_).undo_redo_list );
     233           0 :             if ( U8_ERROR_NONE != internal_err )
     234             :             {
     235           0 :                 U8_LOG_ERROR_HEX( "unexpected internal error", internal_err );
     236             :             }
     237             :         }
     238             : 
     239             :         /* store the change of the diagram to the undo redo list */
     240           0 :         ctrl_undo_redo_list_add_update_diagram( (*this_).undo_redo_list, &old_diagram, &new_diagram );
     241           0 :         ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
     242             : 
     243           0 :         data_diagram_destroy( &new_diagram );
     244           0 :         data_diagram_destroy( &old_diagram );
     245             :     }
     246           0 :     result = (u8_error_t) data_result;
     247             : 
     248           0 :     U8_TRACE_END_ERR( result );
     249           0 :     return result;
     250             : }
     251             : 
     252           5 : u8_error_t ctrl_diagram_controller_update_diagram_type ( ctrl_diagram_controller_t *this_,
     253             :                                                          data_row_id_t diagram_id,
     254             :                                                          data_diagram_type_t new_diagram_type,
     255             :                                                          data_stat_t *io_stat )
     256             : {
     257           5 :     U8_TRACE_BEGIN();
     258           5 :     assert( io_stat != NULL );
     259           5 :     u8_error_t result = U8_ERROR_NONE;
     260             :     data_diagram_t old_diagram;
     261             : 
     262           5 :     result |= data_database_writer_update_diagram_type( (*this_).db_writer, diagram_id, new_diagram_type, &old_diagram );
     263           5 :     if ( U8_ERROR_NONE == result )
     264             :     {
     265             :         /* prepare the new diagram */
     266             :         data_diagram_t new_diagram;
     267           5 :         data_diagram_copy( &new_diagram, &old_diagram );
     268           5 :         data_diagram_set_diagram_type( &new_diagram, new_diagram_type );
     269             : 
     270             :         /* store the change of the diagram to the undo redo list */
     271           5 :         ctrl_undo_redo_list_add_update_diagram( (*this_).undo_redo_list, &old_diagram, &new_diagram );
     272           5 :         ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
     273             : 
     274             :         /* apply policy rules */
     275           5 :         result |= ctrl_diagram_trigger_post_update_diagram_type( (*this_).policy_enforcer, &new_diagram );
     276             : 
     277           5 :         data_diagram_destroy( &new_diagram );
     278           5 :         data_diagram_destroy( &old_diagram );
     279             : 
     280             :         /* report statistics */
     281             :         /* changing diagram types may create or delete lifelines and messages, */
     282             :         /* therefore ask the undo_redo_list for statistics */
     283             :         ctrl_undo_redo_iterator_t iter;
     284           5 :         ctrl_undo_redo_iterator_init_empty( &iter );
     285           5 :         result |= ctrl_undo_redo_list_get_undo_iterator( (*this_).undo_redo_list, &iter );
     286           5 :         ctrl_undo_redo_iterator_collect_statistics( &iter, false /* NOT categorize as undo */, io_stat );
     287           5 :         ctrl_undo_redo_iterator_destroy( &iter );
     288             :     }
     289             :     else
     290             :     {
     291           0 :         data_stat_inc_count ( io_stat, DATA_STAT_TABLE_DIAGRAM, DATA_STAT_SERIES_ERROR );
     292             :     }
     293             : 
     294           5 :     U8_TRACE_END_ERR( result );
     295           5 :     return result;
     296             : }
     297             : 
     298           0 : u8_error_t ctrl_diagram_controller_update_diagram_stereotype ( ctrl_diagram_controller_t *this_,
     299             :                                                                data_row_id_t diagram_id,
     300             :                                                                const char* new_diagram_stereotype )
     301             : {
     302           0 :     U8_TRACE_BEGIN();
     303           0 :     u8_error_t result = U8_ERROR_NONE;
     304             :     u8_error_t data_result;
     305             :     data_diagram_t old_diagram;
     306             : 
     307           0 :     data_result = data_database_writer_update_diagram_stereotype( (*this_).db_writer, diagram_id, new_diagram_stereotype, &old_diagram );
     308           0 :     if  (( U8_ERROR_NONE == data_result ) || ( U8_ERROR_STRING_BUFFER_EXCEEDED == data_result ))
     309             :     {
     310             :         /* prepare the new diagram */
     311             :         data_diagram_t new_diagram;
     312           0 :         data_diagram_copy( &new_diagram, &old_diagram );
     313           0 :         data_diagram_set_stereotype( &new_diagram, new_diagram_stereotype );
     314             :         /* store the change of the diagram to the undo redo list */
     315           0 :         ctrl_undo_redo_list_add_update_diagram( (*this_).undo_redo_list, &old_diagram, &new_diagram );
     316           0 :         ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
     317             : 
     318           0 :         data_diagram_destroy( &new_diagram );
     319           0 :         data_diagram_destroy( &old_diagram );
     320             :     }
     321           0 :     result = (u8_error_t) data_result;
     322             : 
     323           0 :     U8_TRACE_END_ERR( result );
     324           0 :     return result;
     325             : }
     326             : 
     327           2 : u8_error_t ctrl_diagram_controller_update_diagram_name ( ctrl_diagram_controller_t *this_,
     328             :                                                          data_row_id_t diagram_id,
     329             :                                                          const char* new_diagram_name )
     330             : {
     331           2 :     U8_TRACE_BEGIN();
     332           2 :     u8_error_t result = U8_ERROR_NONE;
     333             :     u8_error_t data_result;
     334             :     data_diagram_t old_diagram;
     335             : 
     336           2 :     data_result = data_database_writer_update_diagram_name( (*this_).db_writer, diagram_id, new_diagram_name, &old_diagram );
     337           2 :     if  (( U8_ERROR_NONE == data_result ) || ( U8_ERROR_STRING_BUFFER_EXCEEDED == data_result ))
     338             :     {
     339             :         /* prepare the new diagram */
     340             :         data_diagram_t new_diagram;
     341           2 :         data_diagram_copy( &new_diagram, &old_diagram );
     342           2 :         data_diagram_set_name( &new_diagram, new_diagram_name );
     343             :         /* store the change of the diagram to the undo redo list */
     344           2 :         ctrl_undo_redo_list_add_update_diagram( (*this_).undo_redo_list, &old_diagram, &new_diagram );
     345           2 :         ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
     346             : 
     347           2 :         data_diagram_destroy( &new_diagram );
     348           2 :         data_diagram_destroy( &old_diagram );
     349             :     }
     350           2 :     result = (u8_error_t) data_result;
     351             : 
     352           2 :     U8_TRACE_END_ERR( result );
     353           2 :     return result;
     354             : }
     355             : 
     356           1 : u8_error_t ctrl_diagram_controller_update_diagram_description ( ctrl_diagram_controller_t *this_,
     357             :                                                                 data_row_id_t diagram_id,
     358             :                                                                 const char* new_diagram_description )
     359             : {
     360           1 :     U8_TRACE_BEGIN();
     361           1 :     u8_error_t result = U8_ERROR_NONE;
     362             :     u8_error_t data_result;
     363             :     data_diagram_t old_diagram;
     364             : 
     365           1 :     data_result = data_database_writer_update_diagram_description( (*this_).db_writer, diagram_id, new_diagram_description, &old_diagram );
     366           1 :     if  (( U8_ERROR_NONE == data_result ) || ( U8_ERROR_STRING_BUFFER_EXCEEDED == data_result ))
     367             :     {
     368             :         /* prepare the new diagram */
     369             :         data_diagram_t new_diagram;
     370           1 :         data_diagram_copy( &new_diagram, &old_diagram );
     371           1 :         data_diagram_set_description( &new_diagram, new_diagram_description );
     372             :         /* store the change of the diagram to the undo redo list */
     373           1 :         ctrl_undo_redo_list_add_update_diagram( (*this_).undo_redo_list, &old_diagram, &new_diagram );
     374           1 :         ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
     375             : 
     376           1 :         data_diagram_destroy( &new_diagram );
     377           1 :         data_diagram_destroy( &old_diagram );
     378             :     }
     379           1 :     result = (u8_error_t) data_result;
     380             : 
     381           1 :     U8_TRACE_END_ERR( result );
     382           1 :     return result;
     383             : }
     384             : 
     385           1 : u8_error_t ctrl_diagram_controller_update_diagram_list_order ( ctrl_diagram_controller_t *this_,
     386             :                                                                data_row_id_t diagram_id,
     387             :                                                                int32_t new_diagram_list_order )
     388             : {
     389           1 :     U8_TRACE_BEGIN();
     390           1 :     u8_error_t result = U8_ERROR_NONE;
     391             :     u8_error_t data_result;
     392             :     data_diagram_t old_diagram;
     393             : 
     394           1 :     data_result = data_database_writer_update_diagram_list_order( (*this_).db_writer, diagram_id, new_diagram_list_order, &old_diagram );
     395           1 :     if ( U8_ERROR_NONE == data_result )
     396             :     {
     397             :         /* prepare the new diagram */
     398             :         data_diagram_t new_diagram;
     399           1 :         data_diagram_copy( &new_diagram, &old_diagram );
     400           1 :         data_diagram_set_list_order( &new_diagram, new_diagram_list_order );
     401             :         /* store the change of the diagram to the undo redo list */
     402           1 :         ctrl_undo_redo_list_add_update_diagram( (*this_).undo_redo_list, &old_diagram, &new_diagram );
     403           1 :         ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
     404             : 
     405           1 :         data_diagram_destroy( &new_diagram );
     406           1 :         data_diagram_destroy( &old_diagram );
     407             :     }
     408           1 :     result = (u8_error_t) data_result;
     409             : 
     410           1 :     U8_TRACE_END_ERR( result );
     411           1 :     return result;
     412             : }
     413             : 
     414             : /* ================================ DIAGRAMELEMENT ================================ */
     415             : 
     416          33 : u8_error_t ctrl_diagram_controller_create_diagramelement( ctrl_diagram_controller_t *this_,
     417             :                                                           const data_diagramelement_t *new_diagramelement,
     418             :                                                           ctrl_undo_redo_action_boundary_t add_to_latest_undo_set,
     419             :                                                           data_row_id_t* out_new_id )
     420             : {
     421          33 :     U8_TRACE_BEGIN();
     422          33 :     assert( NULL != new_diagramelement );
     423             :     data_diagramelement_t to_be_created;
     424          33 :     u8_error_t result = U8_ERROR_NONE;
     425             :     u8_error_t data_result;
     426             :     data_row_id_t new_id;
     427             : 
     428          33 :     data_diagramelement_copy( &to_be_created, new_diagramelement );
     429             : 
     430          33 :     data_result = data_database_writer_create_diagramelement( (*this_).db_writer, &to_be_created, &new_id );
     431          33 :     if ( U8_ERROR_NONE == data_result )
     432             :     {
     433             :         /* store new id to data_diagramelement_t object */
     434          33 :         data_diagramelement_set_row_id( &to_be_created, new_id );
     435             : 
     436             :         /* if this action shall be stored to the latest set of actions in the undo redo list, remove the boundary: */
     437          33 :         if ( add_to_latest_undo_set == CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND )
     438             :         {
     439             :             u8_error_t internal_err;
     440          25 :             internal_err = ctrl_undo_redo_list_remove_boundary_from_end( (*this_).undo_redo_list );
     441          25 :             if ( U8_ERROR_NONE != internal_err )
     442             :             {
     443           0 :                 U8_LOG_ERROR_HEX( "unexpected internal error", internal_err );
     444             :             }
     445             :         }
     446             : 
     447             :         /* store the new diagram to the undo redo list */
     448          33 :         ctrl_undo_redo_list_add_create_diagramelement( (*this_).undo_redo_list, &to_be_created );
     449          33 :         ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
     450             : 
     451             :         /* apply policies */
     452          33 :         result |= ctrl_diagram_trigger_post_create_diagramelement( (*this_).policy_enforcer, &to_be_created );
     453             : 
     454             :         /* copy new id to out parameter */
     455          33 :         if ( NULL != out_new_id )
     456             :         {
     457          33 :             *out_new_id = new_id;
     458             :         }
     459             :     }
     460             :     else
     461             :     {
     462           0 :         result = (u8_error_t) data_result;
     463             :     }
     464             : 
     465          33 :     data_diagramelement_destroy( &to_be_created );
     466             : 
     467          33 :     U8_TRACE_END_ERR( result );
     468          33 :     return result;
     469             : }
     470             : 
     471           6 : u8_error_t ctrl_diagram_controller_delete_diagramelement( ctrl_diagram_controller_t *this_,
     472             :                                                           data_row_id_t obj_id,
     473             :                                                           ctrl_undo_redo_action_boundary_t add_to_latest_undo_set )
     474             : {
     475           6 :     U8_TRACE_BEGIN();
     476           6 :     u8_error_t result = U8_ERROR_NONE;
     477             : 
     478             :     /* delete diagramelement */
     479             :     u8_error_t current_result;
     480             :     data_diagramelement_t old_diagramelement;
     481           6 :     current_result = data_database_writer_delete_diagramelement( (*this_).db_writer,
     482             :                                                                  obj_id,
     483             :                                                                  &old_diagramelement
     484             :                                                                );
     485             : 
     486           6 :     if ( U8_ERROR_NONE == current_result )
     487             :     {
     488             :         /* if this action shall be stored to the latest set of actions in the undo redo list, remove the boundary: */
     489           5 :         if ( add_to_latest_undo_set == CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND )
     490             :         {
     491             :             u8_error_t internal_err;
     492           1 :             internal_err = ctrl_undo_redo_list_remove_boundary_from_end( (*this_).undo_redo_list );
     493           1 :             if ( U8_ERROR_NONE != internal_err )
     494             :             {
     495           0 :                 U8_LOG_ERROR_HEX( "unexpected internal error", internal_err );
     496             :             }
     497             :         }
     498             : 
     499             :         /* store the deleted classifier to the undo redo list */
     500           5 :         ctrl_undo_redo_list_add_delete_diagramelement( (*this_).undo_redo_list, &old_diagramelement );
     501           5 :         ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
     502             : 
     503             :         /* try to also delete the classifier and focused lifelines */
     504           5 :         result |= ctrl_diagram_trigger_post_delete_diagramelement( (*this_).policy_enforcer, &old_diagramelement );
     505             : 
     506           5 :         data_diagramelement_destroy( &old_diagramelement );
     507             :     }
     508             :     else
     509             :     {
     510           1 :         result |= (u8_error_t) current_result;
     511             :     }
     512             : 
     513           6 :     U8_TRACE_END_ERR( result );
     514           6 :     return result;
     515             : }
     516             : 
     517           1 : u8_error_t ctrl_diagram_controller_update_diagramelement_display_flags( ctrl_diagram_controller_t *this_,
     518             :                                                                         data_row_id_t diagramelement_id,
     519             :                                                                         data_diagramelement_flag_t new_diagramelement_display_flags,
     520             :                                                                         ctrl_undo_redo_action_boundary_t add_to_latest_undo_set )
     521             : {
     522           1 :     U8_TRACE_BEGIN();
     523           1 :     u8_error_t result = U8_ERROR_NONE;
     524             :     u8_error_t data_result;
     525             :     data_diagramelement_t old_diagramelement;
     526             : 
     527           1 :     data_result = data_database_writer_update_diagramelement_display_flags( (*this_).db_writer,
     528             :                                                                             diagramelement_id,
     529             :                                                                             new_diagramelement_display_flags,
     530             :                                                                             &old_diagramelement
     531             :                                                                           );
     532           1 :     if ( U8_ERROR_NONE == data_result )
     533             :     {
     534             :         /* prepare the new diagram */
     535             :         data_diagramelement_t new_diagramelement;
     536           1 :         data_diagramelement_copy( &new_diagramelement, &old_diagramelement );
     537           1 :         data_diagramelement_set_display_flags( &new_diagramelement, new_diagramelement_display_flags );
     538             : 
     539             :         /* if this action shall be stored to the latest set of actions in the undo redo list, remove the boundary: */
     540           1 :         if ( add_to_latest_undo_set == CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND )
     541             :         {
     542             :             u8_error_t internal_err;
     543           0 :             internal_err = ctrl_undo_redo_list_remove_boundary_from_end( (*this_).undo_redo_list );
     544           0 :             if ( U8_ERROR_NONE != internal_err )
     545             :             {
     546           0 :                 U8_LOG_ERROR_HEX( "unexpected internal error", internal_err );
     547             :             }
     548             :         }
     549             : 
     550             :         /* store the change of the diagramelement to the undo redo list */
     551           1 :         ctrl_undo_redo_list_add_update_diagramelement( (*this_).undo_redo_list, &old_diagramelement, &new_diagramelement );
     552           1 :         ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
     553             : 
     554           1 :         data_diagramelement_destroy( &new_diagramelement );
     555           1 :         data_diagramelement_destroy( &old_diagramelement );
     556             :     }
     557           1 :     result = (u8_error_t) data_result;
     558             : 
     559           1 :     U8_TRACE_END_ERR( result );
     560           1 :     return result;
     561             : }
     562             : 
     563          21 : u8_error_t ctrl_diagram_controller_update_diagramelement_focused_feature_id( ctrl_diagram_controller_t *this_,
     564             :                                                                              data_row_id_t diagramelement_id,
     565             :                                                                              data_row_id_t new_diagramelement_focused_feature_id,
     566             :                                                                              ctrl_undo_redo_action_boundary_t add_to_latest_undo_set )
     567             : {
     568          21 :     U8_TRACE_BEGIN();
     569          21 :     u8_error_t result = U8_ERROR_NONE;
     570             :     u8_error_t data_result;
     571             :     data_diagramelement_t old_diagramelement;
     572             : 
     573          21 :     data_result = data_database_writer_update_diagramelement_focused_feature_id( (*this_).db_writer,
     574             :                                                                                  diagramelement_id,
     575             :                                                                                  new_diagramelement_focused_feature_id,
     576             :                                                                                  &old_diagramelement
     577             :                                                                                );
     578          21 :     if ( U8_ERROR_NONE == data_result )
     579             :     {
     580             :         /* prepare the new diagram */
     581             :         data_diagramelement_t new_diagramelement;
     582          21 :         data_diagramelement_copy( &new_diagramelement, &old_diagramelement );
     583          21 :         data_diagramelement_set_focused_feature_row_id( &new_diagramelement, new_diagramelement_focused_feature_id );
     584             : 
     585             :         /* if this action shall be stored to the latest set of actions in the undo redo list, remove the boundary: */
     586          21 :         if ( add_to_latest_undo_set == CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND )
     587             :         {
     588             :             u8_error_t internal_err;
     589          21 :             internal_err = ctrl_undo_redo_list_remove_boundary_from_end( (*this_).undo_redo_list );
     590          21 :             if ( U8_ERROR_NONE != internal_err )
     591             :             {
     592           0 :                 U8_LOG_ERROR_HEX( "unexpected internal error", internal_err );
     593             :             }
     594             :         }
     595             : 
     596             :         /* store the change of the diagramelement to the undo redo list */
     597          21 :         ctrl_undo_redo_list_add_update_diagramelement( (*this_).undo_redo_list, &old_diagramelement, &new_diagramelement );
     598          21 :         ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
     599             : 
     600          21 :         data_diagramelement_destroy( &new_diagramelement );
     601          21 :         data_diagramelement_destroy( &old_diagramelement );
     602             :     }
     603          21 :     result = (u8_error_t) data_result;
     604             : 
     605          21 :     U8_TRACE_END_ERR( result );
     606          21 :     return result;
     607             : }
     608             : 
     609             : 
     610             : /*
     611             : Copyright 2016-2024 Andreas Warnke
     612             : 
     613             : Licensed under the Apache License, Version 2.0 (the "License");
     614             : you may not use this file except in compliance with the License.
     615             : You may obtain a copy of the License at
     616             : 
     617             :     http://www.apache.org/licenses/LICENSE-2.0
     618             : 
     619             : Unless required by applicable law or agreed to in writing, software
     620             : distributed under the License is distributed on an "AS IS" BASIS,
     621             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     622             : See the License for the specific language governing permissions and
     623             : limitations under the License.
     624             : */

Generated by: LCOV version 1.16