Record Cloning

Involved development of the OpenMW construction set.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Record Cloning

Post by sirherrbatka »

Hi,

I would like to try implementing the following feature. Is there anything important I should know before starting?

I also wanted to ask if I should use our creator widget for the inputing new id.
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Record Cloning

Post by Zini »

Yeah, the creator widget is the right way. I guess you know that you must not change tables directly and go through commands instead. Other than that, there is no issue I can think of right now.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Record Cloning

Post by sirherrbatka »

yeah, I kinda see. I guess i need clone there that would accept baserecord, new id and type of that record, right?
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Record Cloning

Post by Zini »

Actually, not that simple. The type would only be relevant for tables with multiple record types (i.e. referencebles). Also note that for some tables IDs are auto-generated. And for referenceables the refnum must be dealth with, but this isn't implemented yet, so I guess you can skip it for now. When cloning, the cloned record should always be flagged as ModifiedOnly. Oh, and you can't clone deleted records.

Quite a few things I missed in my previous posting. Oops.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Record Cloning

Post by sirherrbatka »

Oh man, i still miss the complete idea of how commands works.

I can see that tabblebottombox holds creator widget that most likely is child of genericcreator. Genericreator uses <CSMWorld::CreateCommand> to actually create a new record. However, I have no idea how createcommand actually appends new record :/
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Record Cloning

Post by Zini »

Have a look at CreateCommand::Redo.

Seems we are getting into more problems here. CreateCommand is actually not a good choice for this task, because we need to copy an entire record. It would be better to add a a clone function to the IdTable and then write a new command that uses this function in redo (and deletes the row in undo). Having a new base class in-between Command and CreateCommand would also be useful.

That however causes some problems with the GenericCreator hierarchy, which assumes a CreateCommand. Well, you need to modify GenericCreator anyway. Maybe a bool flag at construction that distinguishes between create and clone? The configureCreateCommand function can be changed to use the new in-between Command class mentioned above (you want the CreateCommand::addValue function in that new class, pure virtual).
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Record Cloning

Post by sirherrbatka »

yeah makes sense. Hopefully this task is not superurgent :roll:
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Record Cloning

Post by sirherrbatka »

Wow, OpenCS is quite confusing.

It seems that we don't have interface to easily insert existing record. Although collectionbase has interface to appendRecord (accepts const reference to RecordBase) it's implementation in RefIdCollection is quite surprising:

Code: Select all

void CSMWorld::RefIdCollection::appendRecord (const RecordBase& record,
    UniversalId::Type type)
{
    std::string id = findAdaptor (type).getId (record);

    int index = mData.getAppendIndex (type);

    mData.appendRecord (type, id);

    mData.getRecord (mData.globalToLocalIndex (index)).assign (record);
}
That being said I must admit that I have a quite hard time understanding design of the OpenCS. It looks like responsobility for creating new records is in the DataContainers, therefore to implement cloning feature i will have to augment those containers to be able clone recordsbase and create interface everywhere to access those new methods from command. I'm under impression that this task is a lot more ambitious and complicated task than I initially thought.

… or maybe I just lost topic somewhere?
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Record Cloning

Post by Zini »

What is the problem with appendRecord? Does exactly what it is supposed to do.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Record Cloning

Post by sirherrbatka »

Pardon my ignorance, but I think that this method will acquire id from record (if it is already in the table):

Code: Select all

std::string id = findAdaptor (type).getId (record);
And ask to create a new record of the said type and id with:
mData.appendRecord (type, id);
I don't quite understand why it does that, and how it is even possible since id are supposed to be unique.

I was expecting it to simply insert passed record into proper collection instead.

If you could summaraize what excatly this function is doing, i'm sure it would explain quite a lot to me.
Post Reply