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 47 : 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 47 : U8_TRACE_BEGIN();
15 :
16 47 : (*this_).undo_redo_list = undo_redo_list;
17 47 : (*this_).policy_enforcer = policy_enforcer;
18 47 : (*this_).database = database;
19 47 : (*this_).db_reader = db_reader;
20 47 : (*this_).db_writer = db_writer;
21 :
22 47 : U8_TRACE_END();
23 47 : }
24 :
25 47 : void ctrl_diagram_controller_destroy( ctrl_diagram_controller_t *this_ )
26 : {
27 47 : U8_TRACE_BEGIN();
28 :
29 47 : (*this_).undo_redo_list = NULL;
30 47 : (*this_).policy_enforcer = NULL;
31 47 : (*this_).database = NULL;
32 47 : (*this_).db_reader = NULL;
33 47 : (*this_).db_writer = NULL;
34 :
35 47 : U8_TRACE_END();
36 47 : }
37 :
38 : /* ================================ DIAGRAM ================================ */
39 :
40 52 : 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 52 : U8_TRACE_BEGIN();
46 52 : assert( NULL != new_diagram );
47 : data_diagram_t to_be_created;
48 52 : u8_error_t result = U8_ERROR_NONE;
49 : u8_error_t data_result;
50 : data_row_t new_id;
51 :
52 52 : data_diagram_copy( &to_be_created, new_diagram );
53 :
54 52 : data_result = data_database_writer_create_diagram( (*this_).db_writer, &to_be_created, &new_id );
55 52 : if ( U8_ERROR_NONE == data_result )
56 : {
57 : /* store new id to diagram object */
58 50 : data_diagram_set_row( &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 50 : if ( add_to_latest_undo_set == CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND )
62 : {
63 : u8_error_t internal_err;
64 6 : internal_err = ctrl_undo_redo_list_remove_boundary_from_end( (*this_).undo_redo_list );
65 6 : 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 50 : ctrl_undo_redo_list_add_create_diagram( (*this_).undo_redo_list, &to_be_created );
73 50 : ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
74 :
75 : /* copy new id to out parameter */
76 50 : if ( NULL != out_new_id )
77 : {
78 50 : *out_new_id = new_id;
79 : }
80 : }
81 52 : result = data_result;
82 :
83 52 : data_diagram_destroy( &to_be_created );
84 :
85 52 : U8_TRACE_END_ERR( result );
86 52 : 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( &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 : 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( &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 9 : 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 : consistency_stat_t *io_stat )
252 : {
253 9 : U8_TRACE_BEGIN();
254 9 : assert( io_stat != NULL );
255 9 : u8_error_t result = U8_ERROR_NONE;
256 : data_diagram_t old_diagram;
257 :
258 9 : result |= data_database_writer_update_diagram_type( (*this_).db_writer, diagram_id, new_diagram_type, &old_diagram );
259 9 : if ( U8_ERROR_NONE == result )
260 : {
261 : /* prepare the new diagram */
262 : data_diagram_t new_diagram;
263 9 : data_diagram_copy( &new_diagram, &old_diagram );
264 9 : data_diagram_set_diagram_type( &new_diagram, new_diagram_type );
265 :
266 : /* store the change of the diagram to the undo redo list */
267 9 : ctrl_undo_redo_list_add_update_diagram( (*this_).undo_redo_list, &old_diagram, &new_diagram );
268 9 : ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
269 :
270 : /* apply policy rules */
271 9 : result |= ctrl_diagram_trigger_post_update_diagram_type( (*this_).policy_enforcer, &new_diagram, io_stat );
272 :
273 9 : data_diagram_destroy( &new_diagram );
274 9 : data_diagram_destroy( &old_diagram );
275 : }
276 :
277 9 : U8_TRACE_END_ERR( result );
278 9 : return result;
279 : }
280 :
281 0 : u8_error_t ctrl_diagram_controller_update_diagram_stereotype ( ctrl_diagram_controller_t *this_,
282 : data_row_t diagram_id,
283 : const char* new_diagram_stereotype )
284 : {
285 0 : U8_TRACE_BEGIN();
286 0 : u8_error_t result = U8_ERROR_NONE;
287 : u8_error_t data_result;
288 : data_diagram_t old_diagram;
289 :
290 0 : data_result = data_database_writer_update_diagram_stereotype( (*this_).db_writer, diagram_id, new_diagram_stereotype, &old_diagram );
291 0 : if (( U8_ERROR_NONE == data_result ) || ( U8_ERROR_STRING_BUFFER_EXCEEDED == data_result ))
292 : {
293 : /* prepare the new diagram */
294 : data_diagram_t new_diagram;
295 0 : data_diagram_copy( &new_diagram, &old_diagram );
296 0 : data_diagram_set_stereotype( &new_diagram, new_diagram_stereotype );
297 : /* store the change of the diagram to the undo redo list */
298 0 : ctrl_undo_redo_list_add_update_diagram( (*this_).undo_redo_list, &old_diagram, &new_diagram );
299 0 : ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
300 :
301 0 : data_diagram_destroy( &new_diagram );
302 0 : data_diagram_destroy( &old_diagram );
303 : }
304 0 : result = data_result;
305 :
306 0 : U8_TRACE_END_ERR( result );
307 0 : return result;
308 : }
309 :
310 2 : u8_error_t ctrl_diagram_controller_update_diagram_name ( ctrl_diagram_controller_t *this_,
311 : data_row_t diagram_id,
312 : const char* new_diagram_name )
313 : {
314 2 : U8_TRACE_BEGIN();
315 2 : u8_error_t result = U8_ERROR_NONE;
316 : u8_error_t data_result;
317 : data_diagram_t old_diagram;
318 :
319 2 : data_result = data_database_writer_update_diagram_name( (*this_).db_writer, diagram_id, new_diagram_name, &old_diagram );
320 2 : if (( U8_ERROR_NONE == data_result ) || ( U8_ERROR_STRING_BUFFER_EXCEEDED == data_result ))
321 : {
322 : /* prepare the new diagram */
323 : data_diagram_t new_diagram;
324 2 : data_diagram_copy( &new_diagram, &old_diagram );
325 2 : data_diagram_set_name( &new_diagram, new_diagram_name );
326 : /* store the change of the diagram to the undo redo list */
327 2 : ctrl_undo_redo_list_add_update_diagram( (*this_).undo_redo_list, &old_diagram, &new_diagram );
328 2 : ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
329 :
330 2 : data_diagram_destroy( &new_diagram );
331 2 : data_diagram_destroy( &old_diagram );
332 : }
333 2 : result = data_result;
334 :
335 2 : U8_TRACE_END_ERR( result );
336 2 : return result;
337 : }
338 :
339 1 : u8_error_t ctrl_diagram_controller_update_diagram_description ( ctrl_diagram_controller_t *this_,
340 : data_row_t diagram_id,
341 : const char* new_diagram_description )
342 : {
343 1 : U8_TRACE_BEGIN();
344 1 : u8_error_t result = U8_ERROR_NONE;
345 : u8_error_t data_result;
346 : data_diagram_t old_diagram;
347 :
348 1 : data_result = data_database_writer_update_diagram_description( (*this_).db_writer, diagram_id, new_diagram_description, &old_diagram );
349 1 : if (( U8_ERROR_NONE == data_result ) || ( U8_ERROR_STRING_BUFFER_EXCEEDED == data_result ))
350 : {
351 : /* prepare the new diagram */
352 : data_diagram_t new_diagram;
353 1 : data_diagram_copy( &new_diagram, &old_diagram );
354 1 : data_diagram_set_description( &new_diagram, new_diagram_description );
355 : /* store the change of the diagram to the undo redo list */
356 1 : ctrl_undo_redo_list_add_update_diagram( (*this_).undo_redo_list, &old_diagram, &new_diagram );
357 1 : ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
358 :
359 1 : data_diagram_destroy( &new_diagram );
360 1 : data_diagram_destroy( &old_diagram );
361 : }
362 1 : result = data_result;
363 :
364 1 : U8_TRACE_END_ERR( result );
365 1 : return result;
366 : }
367 :
368 1 : u8_error_t ctrl_diagram_controller_update_diagram_list_order ( ctrl_diagram_controller_t *this_,
369 : data_row_t diagram_id,
370 : int32_t new_diagram_list_order )
371 : {
372 1 : U8_TRACE_BEGIN();
373 1 : u8_error_t result = U8_ERROR_NONE;
374 : u8_error_t data_result;
375 : data_diagram_t old_diagram;
376 :
377 1 : data_result = data_database_writer_update_diagram_list_order( (*this_).db_writer, diagram_id, new_diagram_list_order, &old_diagram );
378 1 : if ( U8_ERROR_NONE == data_result )
379 : {
380 : /* prepare the new diagram */
381 : data_diagram_t new_diagram;
382 1 : data_diagram_copy( &new_diagram, &old_diagram );
383 1 : data_diagram_set_list_order( &new_diagram, new_diagram_list_order );
384 : /* store the change of the diagram to the undo redo list */
385 1 : ctrl_undo_redo_list_add_update_diagram( (*this_).undo_redo_list, &old_diagram, &new_diagram );
386 1 : ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
387 :
388 1 : data_diagram_destroy( &new_diagram );
389 1 : data_diagram_destroy( &old_diagram );
390 : }
391 1 : result = data_result;
392 :
393 1 : U8_TRACE_END_ERR( result );
394 1 : return result;
395 : }
396 :
397 : /* ================================ DIAGRAMELEMENT ================================ */
398 :
399 62 : u8_error_t ctrl_diagram_controller_create_diagramelement( ctrl_diagram_controller_t *this_,
400 : const data_diagramelement_t *new_diagramelement,
401 : ctrl_undo_redo_action_boundary_t add_to_latest_undo_set,
402 : data_row_t* out_new_id,
403 : data_id_t *out_created_lifeline )
404 : {
405 62 : U8_TRACE_BEGIN();
406 62 : assert( NULL != new_diagramelement );
407 62 : assert( NULL != out_created_lifeline );
408 : data_diagramelement_t to_be_created;
409 62 : u8_error_t result = U8_ERROR_NONE;
410 : u8_error_t data_result;
411 : data_row_t new_id;
412 :
413 62 : data_diagramelement_copy( &to_be_created, new_diagramelement );
414 :
415 62 : data_result = data_database_writer_create_diagramelement( (*this_).db_writer, &to_be_created, &new_id );
416 62 : if ( U8_ERROR_NONE == data_result )
417 : {
418 : /* store new id to data_diagramelement_t object */
419 62 : data_diagramelement_set_row( &to_be_created, new_id );
420 :
421 : /* if this action shall be stored to the latest set of actions in the undo redo list, remove the boundary: */
422 62 : if ( add_to_latest_undo_set == CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND )
423 : {
424 : u8_error_t internal_err;
425 27 : internal_err = ctrl_undo_redo_list_remove_boundary_from_end( (*this_).undo_redo_list );
426 27 : if ( U8_ERROR_NONE != internal_err )
427 : {
428 0 : U8_LOG_ERROR_HEX( "unexpected internal error", internal_err );
429 : }
430 : }
431 :
432 : /* store the new diagram to the undo redo list */
433 62 : ctrl_undo_redo_list_add_create_diagramelement( (*this_).undo_redo_list, &to_be_created );
434 62 : ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
435 :
436 : /* apply policies */
437 62 : result |= ctrl_diagram_trigger_post_create_diagramelement( (*this_).policy_enforcer,
438 : &to_be_created,
439 : out_created_lifeline
440 : );
441 :
442 : /* copy new id to out parameter */
443 62 : if ( NULL != out_new_id )
444 : {
445 62 : *out_new_id = new_id;
446 : }
447 : }
448 : else
449 : {
450 0 : result = data_result;
451 0 : *out_created_lifeline = DATA_ID_VOID;
452 : }
453 :
454 62 : data_diagramelement_destroy( &to_be_created );
455 :
456 62 : U8_TRACE_END_ERR( result );
457 62 : return result;
458 : }
459 :
460 10 : u8_error_t ctrl_diagram_controller_delete_diagramelement( ctrl_diagram_controller_t *this_,
461 : data_row_t obj_id,
462 : ctrl_undo_redo_action_boundary_t add_to_latest_undo_set,
463 : consistency_stat_t *io_stat )
464 : {
465 10 : U8_TRACE_BEGIN();
466 10 : assert( NULL != io_stat );
467 10 : u8_error_t result = U8_ERROR_NONE;
468 :
469 : /* delete diagramelement */
470 : u8_error_t current_result;
471 : data_diagramelement_t old_diagramelement;
472 10 : current_result = data_database_writer_delete_diagramelement( (*this_).db_writer,
473 : obj_id,
474 : &old_diagramelement
475 : );
476 :
477 10 : if ( U8_ERROR_NONE == current_result )
478 : {
479 : /* if this action shall be stored to the latest set of actions in the undo redo list, remove the boundary: */
480 9 : if ( add_to_latest_undo_set == CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND )
481 : {
482 : u8_error_t internal_err;
483 1 : internal_err = ctrl_undo_redo_list_remove_boundary_from_end( (*this_).undo_redo_list );
484 1 : if ( U8_ERROR_NONE != internal_err )
485 : {
486 0 : U8_LOG_ERROR_HEX( "unexpected internal error", internal_err );
487 : }
488 : }
489 :
490 : /* store the deleted classifier to the undo redo list */
491 9 : ctrl_undo_redo_list_add_delete_diagramelement( (*this_).undo_redo_list, &old_diagramelement );
492 9 : ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
493 :
494 : /* try to also delete the classifier and focused lifelines */
495 9 : result |= ctrl_diagram_trigger_post_delete_diagramelement( (*this_).policy_enforcer, &old_diagramelement, io_stat );
496 :
497 9 : data_diagramelement_destroy( &old_diagramelement );
498 : }
499 : else
500 : {
501 1 : result |= current_result;
502 : }
503 :
504 10 : U8_TRACE_END_ERR( result );
505 10 : return result;
506 : }
507 :
508 1 : u8_error_t ctrl_diagram_controller_update_diagramelement_display_flags( ctrl_diagram_controller_t *this_,
509 : data_row_t diagramelement_id,
510 : data_diagramelement_flag_t new_diagramelement_display_flags,
511 : ctrl_undo_redo_action_boundary_t add_to_latest_undo_set )
512 : {
513 1 : U8_TRACE_BEGIN();
514 1 : u8_error_t result = U8_ERROR_NONE;
515 : u8_error_t data_result;
516 : data_diagramelement_t old_diagramelement;
517 :
518 1 : data_result = data_database_writer_update_diagramelement_display_flags( (*this_).db_writer,
519 : diagramelement_id,
520 : new_diagramelement_display_flags,
521 : &old_diagramelement
522 : );
523 1 : if ( U8_ERROR_NONE == data_result )
524 : {
525 : /* prepare the new diagram */
526 : data_diagramelement_t new_diagramelement;
527 1 : data_diagramelement_copy( &new_diagramelement, &old_diagramelement );
528 1 : data_diagramelement_set_display_flags( &new_diagramelement, new_diagramelement_display_flags );
529 :
530 : /* if this action shall be stored to the latest set of actions in the undo redo list, remove the boundary: */
531 1 : if ( add_to_latest_undo_set == CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND )
532 : {
533 : u8_error_t internal_err;
534 0 : internal_err = ctrl_undo_redo_list_remove_boundary_from_end( (*this_).undo_redo_list );
535 0 : if ( U8_ERROR_NONE != internal_err )
536 : {
537 0 : U8_LOG_ERROR_HEX( "unexpected internal error", internal_err );
538 : }
539 : }
540 :
541 : /* store the change of the diagramelement to the undo redo list */
542 1 : ctrl_undo_redo_list_add_update_diagramelement( (*this_).undo_redo_list, &old_diagramelement, &new_diagramelement );
543 1 : ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
544 :
545 1 : data_diagramelement_destroy( &new_diagramelement );
546 1 : data_diagramelement_destroy( &old_diagramelement );
547 : }
548 1 : result = data_result;
549 :
550 1 : U8_TRACE_END_ERR( result );
551 1 : return result;
552 : }
553 :
554 22 : u8_error_t ctrl_diagram_controller_update_diagramelement_focused_feature_id( ctrl_diagram_controller_t *this_,
555 : data_row_t diagramelement_id,
556 : data_row_t new_diagramelement_focused_feature_id,
557 : ctrl_undo_redo_action_boundary_t add_to_latest_undo_set )
558 : {
559 22 : U8_TRACE_BEGIN();
560 22 : u8_error_t result = U8_ERROR_NONE;
561 : u8_error_t data_result;
562 : data_diagramelement_t old_diagramelement;
563 :
564 22 : data_result = data_database_writer_update_diagramelement_focused_feature_id( (*this_).db_writer,
565 : diagramelement_id,
566 : new_diagramelement_focused_feature_id,
567 : &old_diagramelement
568 : );
569 22 : if ( U8_ERROR_NONE == data_result )
570 : {
571 : /* prepare the new diagram */
572 : data_diagramelement_t new_diagramelement;
573 22 : data_diagramelement_copy( &new_diagramelement, &old_diagramelement );
574 22 : data_diagramelement_set_focused_feature_row( &new_diagramelement, new_diagramelement_focused_feature_id );
575 :
576 : /* if this action shall be stored to the latest set of actions in the undo redo list, remove the boundary: */
577 22 : if ( add_to_latest_undo_set == CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND )
578 : {
579 : u8_error_t internal_err;
580 22 : internal_err = ctrl_undo_redo_list_remove_boundary_from_end( (*this_).undo_redo_list );
581 22 : if ( U8_ERROR_NONE != internal_err )
582 : {
583 0 : U8_LOG_ERROR_HEX( "unexpected internal error", internal_err );
584 : }
585 : }
586 :
587 : /* store the change of the diagramelement to the undo redo list */
588 22 : ctrl_undo_redo_list_add_update_diagramelement( (*this_).undo_redo_list, &old_diagramelement, &new_diagramelement );
589 22 : ctrl_undo_redo_list_add_boundary( (*this_).undo_redo_list );
590 :
591 22 : data_diagramelement_destroy( &new_diagramelement );
592 22 : data_diagramelement_destroy( &old_diagramelement );
593 : }
594 22 : result = data_result;
595 :
596 22 : U8_TRACE_END_ERR( result );
597 22 : return result;
598 : }
599 :
600 :
601 : /*
602 : Copyright 2016-2026 Andreas Warnke
603 :
604 : Licensed under the Apache License, Version 2.0 (the "License");
605 : you may not use this file except in compliance with the License.
606 : You may obtain a copy of the License at
607 :
608 : http://www.apache.org/licenses/LICENSE-2.0
609 :
610 : Unless required by applicable law or agreed to in writing, software
611 : distributed under the License is distributed on an "AS IS" BASIS,
612 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
613 : See the License for the specific language governing permissions and
614 : limitations under the License.
615 : */
|