Write/Read BaseLinks



  • On 04/08/2013 at 02:23, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R14/R15 
    Platform:      
    Language(s) :     C++  ;

    ---------
    I'm trying to write a BaseLink to a HyperFile

    struct ProxyItem {
            Matrix mg;
            Vector size;
            AutoAlloc<BaseLink> link;

    ProxyItem() { }

    ProxyItem(const ProxyItem& item) {
                mg = item.mg;
                size = item.size;
                link->SetLink(item.link->ForceGetLink());
            }

    Bool Write(HyperFile* hf) {
                if (!hf->WriteMatrix(mg)) return FALSE;
                if (!hf->WriteVector(size)) return FALSE;
                if (!link->Write(hf)) return FALSE;
                return TRUE;
            }

    Bool Read(HyperFile* hf, LONG level) {
                if (!hf->ReadMatrix(&mg)) return FALSE;
                if (!hf->ReadVector(&size)) return FALSE;
                if (!link->Read(hf)) return FALSE;
                return TRUE;
            }

    BaseObject* GetLink(BaseDocument* doc) const {
                return (BaseObject* ) link.GetLink(doc, Obase);
            }

    void SetLink(BaseObject* op) {
                link.SetLink(op);
            }

    };

    But the resulting link always looses its connection (so I always get NULL). I now use a
    BaseContainer as a workaround which works fine. I'd rather use the BaseLink directly, though!

    struct ProxyItem {
            Matrix mg;
            Vector size;
            BaseContainer linkbc;

    ProxyItem() { }

    ProxyItem(const ProxyItem& item) {
                mg = item.mg;
                size = item.size;
                linkbc = item.linkbc;
            }

    Bool Write(HyperFile* hf) {
                if (!hf->WriteMatrix(mg)) return FALSE;
                if (!hf->WriteVector(size)) return FALSE;
                if (!hf->WriteContainer(linkbc)) return FALSE;
                return TRUE;
            }

    Bool Read(HyperFile* hf, LONG level) {
                if (!hf->ReadMatrix(&mg)) return FALSE;
                if (!hf->ReadVector(&size)) return FALSE;
                if (!hf->ReadContainer(&linkbc, TRUE)) return FALSE;
                return TRUE;
            }

    BaseObject* GetLink(BaseDocument* doc) const {
                return (BaseObject* ) linkbc.GetLink(1000, doc, Obase);
            }

    void SetLink(BaseObject* op) {
                linkbc.SetLink(1000, op);
            }

    };

    Any ideas?

    Thanks



  • On 06/08/2013 at 07:31, xxxxxxxx wrote:

    Howdy,

    It may be losing the pointer to the link due to not implementing a "CopyTo()" function. If you look at the NodeData class you'll see that it implements Read(), Write() and CopyTo() functions. The CopyTo() function is necessary to make sure you don't lose the data in member variables, when copies are made.

    Remember that when something is added to the Undo stack, it actually replaces the old one with a new copy and puts the old one on the Undo stack. BaseContainers are automatically handled internally for this, but you have to handle member variables yourself.

    I'm not exactly sure how you'd implement a CopyTo() function in your own custom structure, though. You may need to create a MessageData, or SceneHookData plugin specifically to handle your structure's CopyTo() function call.

    Adios,
    Cactus Dan


Log in to reply