87 if (drawing !=
nullptr) {
88 if (drawing->
type == drawing_type) {
91 switch (drawing->
type) {
101 if (drawing ==
nullptr) {
102 switch (drawing_type) {
105 MEM_new<bke::greasepencil::Drawing>(__func__));
109 MEM_new<bke::greasepencil::DrawingReference>(__func__));
125 index_ = int(drawing_index);
128 geometry_ = drawing_geometry.
geometry.wrap();
141 drawing_geometry.
geometry.wrap() = geometry_;
145 drawing_geometry.wrap().tag_topology_changed();
150 UndoRefID_GreasePencil grease_pencil_ref_ = {};
158 index_ = int(drawing_index);
161 grease_pencil_ref_.ptr = drawing_reference.
id_reference;
174 if (drawing_reference.
id_reference != grease_pencil_ref_.ptr) {
176 drawing_reference.
id_reference = grease_pencil_ref_.ptr;
184 foreach_ID_ref_fn(user_data,
reinterpret_cast<UndoRefID *
>(&grease_pencil_ref_));
198 std::string active_node_name_;
205 int64_t drawings_geometry_num = 0;
206 int64_t drawings_reference_num = 0;
209 switch (drawing.
type) {
211 drawings_geometry_num++;
214 drawings_reference_num++;
220 drawings_reference_.
reinitialize(drawings_reference_num);
222 int drawings_geometry_idx = 0;
223 int drawings_reference_idx = 0;
226 switch (drawing.
type) {
228 drawings_geometry_[drawings_geometry_idx++].encode(
232 drawings_reference_[drawings_reference_idx++].encode(
239 void decode_drawings(
GreasePencil &grease_pencil, StepDecodeStatus &decode_status)
const
241 const int drawing_array_num = int(drawings_geometry_.size() + drawings_reference_.size());
242 grease_pencil.resize_drawings(drawing_array_num);
244 for (
const StepDrawingGeometry &drawing : drawings_geometry_) {
245 drawing.decode(grease_pencil, decode_status);
247 for (
const StepDrawingReference &drawing : drawings_reference_) {
248 drawing.decode(grease_pencil, decode_status);
252 void encode_layers(
const GreasePencil &grease_pencil, StepEncodeStatus & )
254 layers_num_ = int(grease_pencil.layers().size());
258 active_node_name_ = grease_pencil.get_active_node()->name();
261 root_group_ = grease_pencil.root_group();
264 void decode_layers(
GreasePencil &grease_pencil, StepDecodeStatus & )
const
267 MEM_delete(&grease_pencil.root_group());
269 grease_pencil.set_active_node(
nullptr);
271 grease_pencil.
root_group_ptr = MEM_new<bke::greasepencil::LayerGroup>(__func__, root_group_);
272 BLI_assert(layers_num_ == grease_pencil.layers().size());
274 if (!active_node_name_.empty()) {
275 if (bke::greasepencil::TreeNode *active_node = grease_pencil.root_group().find_node_by_name(
278 grease_pencil.set_active_node(active_node);
291 this->obedit_ref.ptr = ob;
293 this->encode_drawings(grease_pencil, encode_status);
294 this->encode_layers(grease_pencil, encode_status);
301 this->decode_drawings(grease_pencil, decode_status);
302 this->decode_layers(grease_pencil, decode_status);
309 foreach_ID_ref_fn(user_data,
reinterpret_cast<UndoRefID *
>(&this->obedit_ref));
311 drawing_ref.foreach_id_ref(foreach_ID_ref_fn, user_data);
336 for (const int64_t i : range) {
337 Object *ob = objects[i];
338 us->objects[i].encode(ob, encode_status);
342 bmain->is_memfile_undo_flush_needed =
true;
360 &us->
objects.first().obedit_ref.ptr,
362 sizeof(
decltype(us->
objects)::value_type));
367 step_object.
decode(decode_status);
375 scene, view_layer, us->
objects.first().obedit_ref.ptr, us_p->
name, &
LOG);
396 object.foreach_id_ref(foreach_ID_ref_fn, user_data);
408 ut->
name =
"Edit GreasePencil";
Scene * CTX_data_scene(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
Low-level operations for curves.
CustomData interface, see also DNA_customdata_types.h.
Low-level operations for grease pencil.
General operations, lookup, etc. for blender objects.
bool BKE_object_is_in_editmode(const Object *ob)
@ UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE
void(*)(void *user_data, UndoRefID *id_ref) UndoTypeForEachIDRefFn
void DEG_id_tag_update(ID *id, unsigned int flags)
void DEG_relations_tag_update(Main *bmain)
struct GreasePencil GreasePencil
void ED_undo_object_set_active_or_warn(Scene *scene, ViewLayer *view_layer, Object *ob, const char *info, CLG_LogRef *log)
void ED_undo_object_editmode_restore_helper(Scene *scene, ViewLayer *view_layer, Object **object_array, uint object_array_len, uint object_array_stride)
blender::Vector< Object * > ED_undo_editmode_objects_from_view_layer(const Scene *scene, ViewLayer *view_layer)
void ED_undo_object_editmode_validate_scene_from_windows(wmWindowManager *wm, const Scene *scene_ref, Scene **scene_p, ViewLayer **view_layer_p)
Read Guarded memory(de)allocation.
void reinitialize(const int64_t new_size)
constexpr IndexRange index_range() const
void decode_valid_drawingtype_at_index_ensure(MutableSpan< GreasePencilDrawingBase * > drawings, const GreasePencilDrawingType drawing_type) const
void encode(const GreasePencilDrawing &drawing_geometry, const int64_t drawing_index, StepEncodeStatus &)
void decode(GreasePencil &grease_pencil, StepDecodeStatus &) const
void foreach_id_ref(UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
void encode(const GreasePencilDrawingReference &drawing_reference, const int64_t drawing_index, StepEncodeStatus &)
void decode(GreasePencil &grease_pencil, StepDecodeStatus &decode_status) const
void foreach_id_ref(UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
UndoRefID_Object obedit_ref
void decode(StepDecodeStatus &decode_status) const
void encode(Object *ob, StepEncodeStatus &encode_status)
void ED_undosys_type_grease_pencil(UndoType *ut)
static void foreach_ID_ref(UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
static bool step_encode(bContext *C, Main *bmain, UndoStep *us_p)
static void step_free(UndoStep *us_p)
static void step_decode(bContext *C, Main *bmain, UndoStep *us_p, const eUndoStepDir, bool)
bool grease_pencil_edit_poll(bContext *C)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
float wrap(float value, float max, float min)
struct GreasePencil * id_reference
GreasePencilDrawingBase base
GreasePencilDrawingBase base
GreasePencilLayerTreeNode * active_node
GreasePencilLayerTreeGroup * root_group_ptr
struct AttributeStorage attribute_storage
bool is_memfile_undo_flush_needed
void(* step_foreach_ID_ref)(UndoStep *us, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
void(* step_free)(UndoStep *us)
bool(* poll)(struct bContext *C)
void(* step_decode)(bContext *C, Main *bmain, UndoStep *us, eUndoStepDir dir, bool is_final)
bool(* step_encode)(bContext *C, Main *bmain, UndoStep *us)
Array< StepObject > objects
UndoRefID_Scene scene_ref
bool needs_relationships_update
void WM_event_add_notifier(const bContext *C, uint type, void *reference)