| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup edundo | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-04-02 15:02:08 +02:00
										 |  |  |  * Wrapper between 'ED_undo.h' and 'BKE_undo_system.h' API's. | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_sys_types.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  | #include "BLI_ghash.h"
 | 
					
						
							| 
									
										
										
										
											2020-11-12 10:41:33 +01:00
										 |  |  | #include "BLI_listbase.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 10:41:33 +01:00
										 |  |  | #include "DNA_ID.h"
 | 
					
						
							| 
									
										
										
										
											2020-12-15 10:47:58 +11:00
										 |  |  | #include "DNA_collection_types.h"
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:30:42 +02:00
										 |  |  | #include "DNA_node_types.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | #include "DNA_object_enums.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  | #include "DNA_object_types.h"
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:30:42 +02:00
										 |  |  | #include "DNA_scene_types.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_blender_undo.h"
 | 
					
						
							|  |  |  | #include "BKE_context.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  | #include "BKE_lib_id.h"
 | 
					
						
							|  |  |  | #include "BKE_lib_query.h"
 | 
					
						
							| 
									
										
										
										
											2019-11-07 16:52:03 +11:00
										 |  |  | #include "BKE_main.h"
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:30:42 +02:00
										 |  |  | #include "BKE_node.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  | #include "BKE_scene.h"
 | 
					
						
							|  |  |  | #include "BKE_undo_system.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "../depsgraph/DEG_depsgraph.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ED_object.h"
 | 
					
						
							| 
									
										
										
										
											2018-04-02 15:02:08 +02:00
										 |  |  | #include "ED_undo.h"
 | 
					
						
							| 
									
										
										
										
											2019-01-15 21:33:01 +11:00
										 |  |  | #include "ED_util.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "../blenloader/BLO_undofile.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-02 15:02:08 +02:00
										 |  |  | #include "undo_intern.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 10:41:33 +01:00
										 |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Implements ED Undo System
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct MemFileUndoStep { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   UndoStep step; | 
					
						
							|  |  |  |   MemFileUndoData *data; | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | } MemFileUndoStep; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-19 00:48:00 +11:00
										 |  |  | static bool memfile_undosys_poll(bContext *C) | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* other poll functions must run first, this is a catch-all. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if ((U.uiflag & USER_GLOBALUNDO) == 0) { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Allow a single memfile undo step (the first). */ | 
					
						
							|  |  |  |   UndoStack *ustack = ED_undo_stack_get(); | 
					
						
							|  |  |  |   if ((ustack->step_active != NULL) && (ED_undo_is_memfile_compatible(C) == false)) { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return true; | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static bool memfile_undosys_step_encode(struct bContext *UNUSED(C), | 
					
						
							|  |  |  |                                         struct Main *bmain, | 
					
						
							|  |  |  |                                         UndoStep *us_p) | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   MemFileUndoStep *us = (MemFileUndoStep *)us_p; | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* Important we only use 'main' from the context (see: BKE_undosys_stack_init_from_main). */ | 
					
						
							|  |  |  |   UndoStack *ustack = ED_undo_stack_get(); | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-07 16:52:03 +11:00
										 |  |  |   if (bmain->is_memfile_undo_flush_needed) { | 
					
						
							|  |  |  |     ED_editors_flush_edits_ex(bmain, false, true); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* can be NULL, use when set. */ | 
					
						
							|  |  |  |   MemFileUndoStep *us_prev = (MemFileUndoStep *)BKE_undosys_step_find_by_type( | 
					
						
							|  |  |  |       ustack, BKE_UNDOSYS_TYPE_MEMFILE); | 
					
						
							|  |  |  |   us->data = BKE_memfile_undo_encode(bmain, us_prev ? us_prev->data : NULL); | 
					
						
							|  |  |  |   us->step.data_size = us->data->undo_size; | 
					
						
							| 
									
										
										
										
											2018-04-01 19:28:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  |   /* Store the fact that we should not re-use old data with that undo step, and reset the Main
 | 
					
						
							|  |  |  |    * flag. */ | 
					
						
							|  |  |  |   us->step.use_old_bmain_data = !bmain->use_memfile_full_barrier; | 
					
						
							|  |  |  |   bmain->use_memfile_full_barrier = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return true; | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  | static int memfile_undosys_step_id_reused_cb(LibraryIDLinkCallbackData *cb_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ID *id_self = cb_data->id_self; | 
					
						
							|  |  |  |   ID **id_pointer = cb_data->id_pointer; | 
					
						
							|  |  |  |   BLI_assert((id_self->tag & LIB_TAG_UNDO_OLD_ID_REUSED) != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ID *id = *id_pointer; | 
					
						
							|  |  |  |   if (id != NULL && id->lib == NULL && (id->tag & LIB_TAG_UNDO_OLD_ID_REUSED) == 0) { | 
					
						
							|  |  |  |     bool do_stop_iter = true; | 
					
						
							|  |  |  |     if (GS(id_self->name) == ID_OB) { | 
					
						
							|  |  |  |       Object *ob_self = (Object *)id_self; | 
					
						
							|  |  |  |       if (ob_self->type == OB_ARMATURE) { | 
					
						
							|  |  |  |         if (ob_self->data == id) { | 
					
						
							|  |  |  |           BLI_assert(GS(id->name) == ID_AR); | 
					
						
							|  |  |  |           if (ob_self->pose != NULL) { | 
					
						
							|  |  |  |             /* We have a changed/re-read armature used by an unchanged armature object: our beloved
 | 
					
						
							|  |  |  |              * Bone pointers from the object's pose need their usual special treatment. */ | 
					
						
							|  |  |  |             ob_self->pose->flag |= POSE_RECALC; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |           /* Cannot stop iteration until we checked ob_self->data pointer... */ | 
					
						
							|  |  |  |           do_stop_iter = false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return do_stop_iter ? IDWALK_RET_STOP_ITER : IDWALK_RET_NOP; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return IDWALK_RET_NOP; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void memfile_undosys_step_decode(struct bContext *C, | 
					
						
							|  |  |  |                                         struct Main *bmain, | 
					
						
							|  |  |  |                                         UndoStep *us_p, | 
					
						
							| 
									
										
										
										
											2021-02-04 22:03:39 +01:00
										 |  |  |                                         const eUndoStepDir undo_direction, | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  |                                         bool UNUSED(is_final)) | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-04 22:03:39 +01:00
										 |  |  |   BLI_assert(undo_direction != STEP_INVALID); | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   bool use_old_bmain_data = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-17 15:11:16 +02:00
										 |  |  |   if (USER_EXPERIMENTAL_TEST(&U, use_undo_legacy)) { | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  |     use_old_bmain_data = false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-02-04 22:03:39 +01:00
										 |  |  |   else if (undo_direction == STEP_REDO) { | 
					
						
							|  |  |  |     /* The only time we should have to force a complete redo is when current step is tagged as a
 | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  |      * redo barrier. | 
					
						
							|  |  |  |      * If previous step was not a memfile one should not matter here, current data in old bmain | 
					
						
							| 
									
										
										
										
											2020-03-19 12:05:34 +11:00
										 |  |  |      * should still always be valid for unchanged data-blocks. */ | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  |     if (us_p->use_old_bmain_data == false) { | 
					
						
							|  |  |  |       use_old_bmain_data = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-02-04 22:03:39 +01:00
										 |  |  |   else if (undo_direction == STEP_UNDO) { | 
					
						
							|  |  |  |     /* Here we do not care whether current step is an undo barrier, since we are coming from
 | 
					
						
							| 
									
										
										
										
											2020-03-19 12:05:34 +11:00
										 |  |  |      * 'the future' we can still re-use old data. However, if *next* undo step | 
					
						
							| 
									
										
										
										
											2020-03-18 22:28:54 +11:00
										 |  |  |      * (i.e. the one immediately in the future, the one we are coming from) | 
					
						
							|  |  |  |      * is a barrier, then we have to force a complete undo. | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  |      * Note that non-memfile undo steps **should** not be an issue anymore, since we handle | 
					
						
							|  |  |  |      * fine-grained update flags now. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     UndoStep *us_next = us_p->next; | 
					
						
							|  |  |  |     if (us_next != NULL) { | 
					
						
							|  |  |  |       if (us_next->use_old_bmain_data == false) { | 
					
						
							|  |  |  |         use_old_bmain_data = false; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Extract depsgraphs from current bmain (which may be freed during undo step reading),
 | 
					
						
							|  |  |  |    * and store them for re-use. */ | 
					
						
							|  |  |  |   GHash *depsgraphs = NULL; | 
					
						
							|  |  |  |   if (use_old_bmain_data) { | 
					
						
							|  |  |  |     depsgraphs = BKE_scene_undo_depsgraphs_extract(bmain); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ED_editors_exit(bmain, false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   MemFileUndoStep *us = (MemFileUndoStep *)us_p; | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  |   BKE_memfile_undo_decode(us->data, undo_direction, use_old_bmain_data, C); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for (UndoStep *us_iter = us_p->next; us_iter; us_iter = us_iter->next) { | 
					
						
							|  |  |  |     if (BKE_UNDOSYS_TYPE_IS_MEMFILE_SKIP(us_iter->type)) { | 
					
						
							|  |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     us_iter->is_applied = false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   for (UndoStep *us_iter = us_p; us_iter; us_iter = us_iter->prev) { | 
					
						
							|  |  |  |     if (BKE_UNDOSYS_TYPE_IS_MEMFILE_SKIP(us_iter->type)) { | 
					
						
							|  |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     us_iter->is_applied = true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* bmain has been freed. */ | 
					
						
							|  |  |  |   bmain = CTX_data_main(C); | 
					
						
							|  |  |  |   ED_editors_init_for_undo(bmain); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  |   if (use_old_bmain_data) { | 
					
						
							|  |  |  |     /* Restore previous depsgraphs into current bmain. */ | 
					
						
							|  |  |  |     BKE_scene_undo_depsgraphs_restore(bmain, depsgraphs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* We need to inform depsgraph about re-used old IDs that would be using newly read
 | 
					
						
							|  |  |  |      * data-blocks, at least COW evaluated copies need to be updated... */ | 
					
						
							|  |  |  |     ID *id = NULL; | 
					
						
							|  |  |  |     FOREACH_MAIN_ID_BEGIN (bmain, id) { | 
					
						
							|  |  |  |       if (id->tag & LIB_TAG_UNDO_OLD_ID_REUSED) { | 
					
						
							|  |  |  |         BKE_library_foreach_ID_link( | 
					
						
							| 
									
										
										
										
											2020-05-25 15:26:58 +02:00
										 |  |  |             bmain, id, memfile_undosys_step_id_reused_cb, NULL, IDWALK_READONLY); | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-04-04 19:30:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-08 10:33:56 +10:00
										 |  |  |       /* Tag depsgraph to update data-block for changes that happened between the
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:30:42 +02:00
										 |  |  |        * current and the target state, see direct_link_id_restore_recalc(). */ | 
					
						
							|  |  |  |       if (id->recalc) { | 
					
						
							|  |  |  |         DEG_id_tag_update_ex(bmain, id, id->recalc); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     FOREACH_MAIN_ID_END; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:30:42 +02:00
										 |  |  |     FOREACH_MAIN_ID_BEGIN (bmain, id) { | 
					
						
							|  |  |  |       /* Clear temporary tag. */ | 
					
						
							|  |  |  |       id->tag &= ~LIB_TAG_UNDO_OLD_ID_REUSED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /* We only start accumulating from this point, any tags set up to here
 | 
					
						
							|  |  |  |        * are already part of the current undo state. This is done in a second | 
					
						
							|  |  |  |        * loop because DEG_id_tag_update may set tags on other datablocks. */ | 
					
						
							| 
									
										
										
										
											2020-04-13 17:38:34 +02:00
										 |  |  |       id->recalc_after_undo_push = 0; | 
					
						
							| 
									
										
										
										
											2020-04-04 19:30:42 +02:00
										 |  |  |       bNodeTree *nodetree = ntreeFromID(id); | 
					
						
							|  |  |  |       if (nodetree != NULL) { | 
					
						
							| 
									
										
										
										
											2020-04-13 17:38:34 +02:00
										 |  |  |         nodetree->id.recalc_after_undo_push = 0; | 
					
						
							| 
									
										
										
										
											2020-04-04 19:30:42 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |       if (GS(id->name) == ID_SCE) { | 
					
						
							|  |  |  |         Scene *scene = (Scene *)id; | 
					
						
							|  |  |  |         if (scene->master_collection != NULL) { | 
					
						
							| 
									
										
										
										
											2020-04-13 17:38:34 +02:00
										 |  |  |           scene->master_collection->id.recalc_after_undo_push = 0; | 
					
						
							| 
									
										
										
										
											2020-04-04 19:30:42 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     FOREACH_MAIN_ID_END; | 
					
						
							| 
									
										
										
										
											2020-03-17 12:29:36 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, CTX_data_scene(C)); | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void memfile_undosys_step_free(UndoStep *us_p) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-22 00:18:34 +10:00
										 |  |  |   /* To avoid unnecessary slow down, free backwards
 | 
					
						
							|  |  |  |    * (so we don't need to merge when clearing all). */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   MemFileUndoStep *us = (MemFileUndoStep *)us_p; | 
					
						
							|  |  |  |   if (us_p->next != NULL) { | 
					
						
							|  |  |  |     UndoStep *us_next_p = BKE_undosys_step_same_type_next(us_p); | 
					
						
							|  |  |  |     if (us_next_p != NULL) { | 
					
						
							|  |  |  |       MemFileUndoStep *us_next = (MemFileUndoStep *)us_next_p; | 
					
						
							|  |  |  |       BLO_memfile_merge(&us->data->memfile, &us_next->data->memfile); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   BKE_memfile_undo_free(us->data); | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Export for ED_undo_sys. */ | 
					
						
							|  |  |  | void ED_memfile_undosys_type(UndoType *ut) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ut->name = "Global Undo"; | 
					
						
							|  |  |  |   ut->poll = memfile_undosys_poll; | 
					
						
							|  |  |  |   ut->step_encode = memfile_undosys_step_encode; | 
					
						
							|  |  |  |   ut->step_decode = memfile_undosys_step_decode; | 
					
						
							|  |  |  |   ut->step_free = memfile_undosys_step_free; | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 18:06:11 +01:00
										 |  |  |   ut->flags = 0; | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ut->step_size = sizeof(MemFileUndoStep); | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Utilities
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2019-04-22 00:18:34 +10:00
										 |  |  |  * Ideally we wouldn't need to export global undo internals, | 
					
						
							|  |  |  |  * there are some cases where it's needed though. | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | static struct MemFile *ed_undosys_step_get_memfile(UndoStep *us_p) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   MemFileUndoStep *us = (MemFileUndoStep *)us_p; | 
					
						
							|  |  |  |   return &us->data->memfile; | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct MemFile *ED_undosys_stack_memfile_get_active(UndoStack *ustack) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   UndoStep *us = BKE_undosys_stack_active_with_type(ustack, BKE_UNDOSYS_TYPE_MEMFILE); | 
					
						
							|  |  |  |   if (us) { | 
					
						
							|  |  |  |     return ed_undosys_step_get_memfile(us); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 10:41:33 +01:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-11-16 16:48:41 +11:00
										 |  |  |  * If the last undo step is a memfile one, find the first #MemFileChunk matching given ID | 
					
						
							|  |  |  |  * (using its session UUID), and tag it as "changed in the future". | 
					
						
							| 
									
										
										
										
											2020-11-12 10:41:33 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-02-09 10:42:00 +11:00
										 |  |  |  * Since non-memfile undoes cannot automatically set this flag in the previous step as done with | 
					
						
							| 
									
										
										
										
											2020-11-12 10:41:33 +01:00
										 |  |  |  * memfile ones, this has to be called manually by relevant undo code. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2020-11-16 16:48:41 +11:00
										 |  |  |  * \note Only current known case for this is undoing a switch from Object to Sculpt mode (see | 
					
						
							| 
									
										
										
										
											2020-11-12 10:41:33 +01:00
										 |  |  |  * T82388). | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2020-11-16 16:48:41 +11:00
										 |  |  |  * \note Calling this ID by ID is not optimal, as it will loop over all #MemFile.chunks until it | 
					
						
							|  |  |  |  * finds the expected one. If this becomes an issue we'll have to add a mapping from session UUID | 
					
						
							|  |  |  |  * to first #MemFileChunk in #MemFile itself | 
					
						
							|  |  |  |  * (currently we only do that in #MemFileWriteData when writing a new step). | 
					
						
							| 
									
										
										
										
											2020-11-12 10:41:33 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | void ED_undosys_stack_memfile_id_changed_tag(UndoStack *ustack, ID *id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   UndoStep *us = ustack->step_active; | 
					
						
							|  |  |  |   if (id == NULL || us == NULL || us->type != BKE_UNDOSYS_TYPE_MEMFILE) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   MemFile *memfile = &((MemFileUndoStep *)us)->data->memfile; | 
					
						
							|  |  |  |   LISTBASE_FOREACH (MemFileChunk *, mem_chunk, &memfile->chunks) { | 
					
						
							|  |  |  |     if (mem_chunk->id_session_uuid == id->session_uuid) { | 
					
						
							|  |  |  |       mem_chunk->is_identical_future = false; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-19 14:17:59 +01:00
										 |  |  | /** \} */ |