THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/05/2008 at 07:39, xxxxxxxx wrote:
That helps a little...
Based on what you are showing above, take a look at this:
(btw, use square brackets for CODE keyword)
if( jointOrigin == NULL )
{
//allocate new top level object
BaseObject *origin = BaseObject::Alloc(Onull);
// note that the following line is:
// a) accessing a NULL 'jointOrigin' pointer (generally a BAD idea)
// b) essentially trying to tell the document to make a backup copy of
// an object (well, a NULL pointer, in this case) that is not yet attached
// to it (it doesn't know about it yet)
// c) not necessary to start with
doc->AddUndo(UNDO_CHANGE, jointOrigin);
// as per your code, it now gets set to point to the newly allocated object
jointOrigin = origin;
// ...and then added to the scene/doc
doc->InsertObject (origin, NULL, NULL);
doc->AddUndo(UNDO_NEW, origin);
// do changes to your tag...
doc->AddUndo (UNDO_CHANGE_SMALL, tag);
data->SetBool (DESC_NO_ORIGIN, FALSE);
}
// etc...
...let's back up a bit and talk about what AddUndo() is actually doing internally. A user activated 'Undo' operation should: "restore the document to the state it was in, prior to the last user-initiated action". I don't have access to the code, but my understanding is that what AddUndo() is doing is essentially causing backup copies of objects to be created, so that if/when the user does an Undo, it reverts to the backup copy.
With that in mind, let's assume that your plugin is a Tag Plugin (which it seems to be) and that the user activates some menu option that adds your tag to some mesh in the Object Manager ( and/or a Null object to the scene ). From the user's perspective, his "last user-initiated action" was to activate the menu that adds your tag to some mesh. In which case, the "doc->AddUndo(UNDO_NEW, tag)" ( and/or doc->AddUndo(UNDO_NEW, origin) ) should be the only AddUndo() you need ( unless you make other changes to the mesh object, in which case you'd be doing AddUndo() to on the mesh object itself ).
But your code seems to indicate that the tag (or the Null object that your plugin adds to the scene) might or might not already exist when it's called so the more correct code would be:
if( jointOrigin == NULL )
{
//allocate new top level object
jointOrigin = BaseObject::Alloc(Onull);
// add to the scene/doc
doc->InsertObject (jointOrigin, NULL, NULL);
doc->AddUndo(UNDO_NEW, jointOrigin); // tell doc about new object
// going to modify tag, so AddUndo() on the pre-existing tag is appropriate here
doc->AddUndo (UNDO_CHANGE_SMALL, tag);
data->SetBool (DESC_NO_ORIGIN, FALSE);
}
// etc...
...note that if 'jointOrigin' didn't exist yet, there's no need to do any AddUndo() for changes to that variable... just allocate it, add it to the doc, then do the UNDO_NEW to tell the doc about it being added. Once it exists in the document, if code below there modifies it, then additional AddUndo()'s can/should be added (again, a lot of if/when AddUndo() is needed would depend on knowing more details about what your code is doing and how it's structured).
I hope the above makes some sense ;).