Catch other object's delete/undo
-
Hello,
I have a generator that contains an InExclude list where I can add polygons, and I create my own mesh over those polygons. When a polygon from my list is deleted from the scene, it is not deleted from the list, and my mesh becomes outdated, it has some faces that should not exist anymote. Anyone would expect my mesh to be updated right away, so I need to manually check if there's any null object in the list, remove it, delete some data that was generated for that polygon, and recompute my mesh. I'm doing this in Execute() and is working good.
The problem is when the user hits Undo after that. The original polygon is back, but the operation I did on my generator (delete the polygon from the list and updated data) is not.
When I'm updating my list, BaseDocument:: GetUndoPtr() returns nothing (and would not be of great help).
Adding a new Undo step triggers a debug breakpoint (CRITICAL: Stop), and the step is not created.I need some understanding how can I not lose any data when that original polygon is deleted.
Is there a better way to catch the delete?
Is there a way to catch that polygon Undo and add my generator to it? The polygons are added as dependencies but no messages are sent to my generator.
Should I add a new undo step? Where?Thanks,
Roger -
Hi @rsodre just some clarification:
"I can add polygons". Do you mean PolygonObject or PolygonSelection?
Thanks in advance.
Cheers,
Maxime. -
Hi @m_adam
I add PolygonObjects to the InExclude list.
-
Hi @rsodre do you have some minimal code to reproduce?
"I need some understanding of how can I not lose any data when that original polygon is deleted." This part is really not clear since you said that you manually delete if the original polygonObj is deleted, if you don't want to lose your data, then copy them into a local variable?
You can be informed of an undo with MSG_DOCUMENTINFO and listen to MSG_DOCUMENTINFO_TYPE_UNDO.
An idea you could also AddEventNotification to redirect undo, but use it as the last way to do since it can really screw-up things and without a clear example it's pretty hard for me to guide you.
Cheers,
Maxime. -
@m_adam ,
AddEventNotification
was exactly what I needed. I created a notification toNOTIFY_EVENT_UNDO
, and then add my object to it. Now if I delete anything from my object after a polygon is deleted, it will be restored with Undo.Thanks!
case MSG_NOTIFY_EVENT: { CHECK_BREAK( data != nullptr ); const auto eventData = static_cast<NotifyEventData*>( data ); if( eventData->eventid == NOTIFY_EVENT_UNDO ) { NotifyEventMsg* notifyMessage = static_cast<NotifyEventMsg*>( eventData->event_data ); CHECK_BREAK( notifyMessage != nullptr ); if( notifyMessage->msg_id == Int32( UNDOTYPE_DELETE ) ) { eventData->doc->AddUndo( UNDOTYPE_CHANGE, Get() ); } } break; }