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