saving/loading data in iCustomGui [SOLVED]



  • On 28/01/2015 at 08:11, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   13+ 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    _<_n_<_o_>__
    I have a lot of data which are inside a GeUserArea sub class, the data is dynamic "lots of pointers, vectors of pointers, ..."

    example:

    class myNodeUserArea : public GeUserArea
    {
    private:
    	std::vector<mNode*> nodes;
    	std::vector<mWire*> wires;  
    	....  
    }
    

    I'm not sure where to "put" these data so they can be saved/loaded easily, for example in the iCustomGui class, also I'm not sure how the TriState<> is loading and saving data

    right now I can add my custom data type from userdata, display it with my custom gui, modify the user area stuff, once I change any thing in the ui the user area becomes empty!! "as if I just created it without any modification"



  • On 28/01/2015 at 14:15, xxxxxxxx wrote:

    _<_n_<_o_>__update: inside CustomGuiDat_<_o_<_o_>_a_<_n_<_o_>__/_<_o_<__<_o_<_o_>_>
    <_<_n_<_o_>__o>

    virtual CDial_<_o_<__<_o_<_o_>_Alloc(c_<_n_<_o_>__ B_<_o_<__<_o_<_o_>_ontaine_<_n_<_o_>__p; settings);
    [/C_<_o_<_o_>_
    is called every time the layout gets changed "a nightmare!!" , 
    so how can I store my data between draws, I see 2 examples which somehow stores a si_<_n_<_o_>__ data "tristate example for Niklas & custom slider example for Scotta"
      
    not sure how and where is this TriState is holding the data "after all every Alloc create_<_o_<_o_<_o_<__<_o_<_o_>_ew class which should contain a fresh TriState, pretty confusing_<_o_<_o_>_p;:nauseated_face: "
    


  • On 29/01/2015 at 08:28, xxxxxxxx wrote:

    Hello,

    a GeUserArea and a custom GUI are exactly this – GUI elements that should display data but are not in charge of saving data.

    You can store custom data in a custom datatype. To be sure that the data is correctly written, read and copied overwrite WriteData(), ReadData() and CopyData(). You could write your data to the Hyperfile using a BaseContainer and WriteContainer() (depending on your data).

    The data is handed over to your custom GUI in SetData(). To get custom data simple read the value of the Tristate via GetValue() and then get the custom data type with GetCustomDataType(). When you change the data in your custom GUI you have to update the parent that the data was changed. This has to be done with a message:

      
    BaseContainer m(BFM_ACTION);  
    m.SetInt32(BFM_ACTION_ID, GetId());  
    m.SetData(BFM_ACTION_VALUE, GeData(MYCUSTOMDATATYPE, data));  
    SendParentMessage(m);  
    

    best wishes,
    Sebastian



  • On 29/01/2015 at 08:48, xxxxxxxx wrote:

    Hi Sebastian,

    thanks for the help, I kinda understand now how to work it out 🙂, you are great.



  • On 29/01/2015 at 17:34, xxxxxxxx wrote:

    well I tested, kinda works but there is a missing part in the chain "tristate sets data, gets data, but data is reset or not saved"

        virtual Bool SetData(const TriState<GeData>& tristate) {
    		GePrint("TriState SetData()");
    		GePrint("setdata m_ua count " + String::IntToString(m_ua.count));
    		
    		const GeData& value = tristate.GetValue();
    		if(!value.GetCustomDataType(23123123))
    			return FALSE;
    		iExampleDataType* mdata = static_cast<iExampleDataType*> (value.GetCustomDataType(23123123));
    		m_ua.count = mdata->count;
    		GePrint("setdata mdata count " + String::IntToString(mdata->count));
    		
            return TRUE;
        }
    
        virtual TriState<GeData> GetData() {
    		GePrint("TriState GetData()");
    		Int32 count = m_ua.count;
    		GePrint("getdata count " + String::IntToString(m_ua.count));
    		iExampleDataType a;
    		a.count = count;
    		return TriState<GeData>(GeData(23123123, static_cast<CustomDataType> (a)));
        }
    

    and here is the print of a simple variable "initialized to 1"

    TriState GetData()
    getdata count 2
    msg count 2 #making sure that the msg is correct
    TriState SetData()
    setdata m_ua count 2
    setdata mdata count 1 #bam!!! why it reads 1 not 2
    


  • On 30/01/2015 at 00:26, xxxxxxxx wrote:

    Hello,

    such a behavior could be caused by the absence or incorrect implementation of a function in your datatype class. For example it is also important to correctly implement the Compare() function.

    Best wishes,
    Sebastian



  • On 30/01/2015 at 03:23, xxxxxxxx wrote:

    wow Sebastian!! , you nailed it from the first shot 👏, thanks again for the help.


Log in to reply