About Prefs Hook



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/09/2004 at 08:32, xxxxxxxx wrote:

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

    ---------
    Hi
    The documentation is a bit unclear what "data" in

        
        
          
        
        
        
        PrefsDlg_Base::SetValues(BaseContainer* data)
        
        
        
    

    and

        
        
          
        
        
        
        PrefsDlg_Base::CommandValues(LONG id, const Basecontainer &msg,BaseContainer* data)
        
        
        
    

    and

        
        
        
        
        PrefsDlg_Base::EnableValues(BaseContainer* data)
        
        
        
    

    actually is.
    After 2 hours of messing around, i found out that it is simply the WorldContainer.  What i do now is:

        
        
        
        
        SetValues(BaseContainer* data)
        
        
        
        
        {
        
        
        
        
             if(!data) return;
        
        
        
        
              data = data->GetContainerInstance(PLUGIN_ID);
        
        
        
        
             if(!data) return;
        
        
        
        
             ...
        
        
        
        
             ...
        
        
        
        
        }
        
        
        
    

    The Examples in the docs are very much misleading since the code in MyPrefsDialog assumes that you store data directly in the worldcontainer. While the code in MyPrefs assumes that you store data in a Container which itself is stored in the WorldContainer.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/09/2004 at 10:02, xxxxxxxx wrote:

    I do it something like this. Here is a snippet of my prefs for DPIT:

    class MyPrefsDialog : public PrefsDlg_Base //Dialog  
    {  
      
    private:  
         DpitSubPrefs *s_dpit_dlg;  
         IconArea ua;  
    public:  
           
        MyPrefsDialog(PrefsDialogHookClass* hook) : PrefsDlg_Base(IDD_DPIT_PREFS, hook)   
         {   
                
         }  
          
        virtual void SetValues(BaseContainer *data)  
        {  
          if (!data) return;  
          SetBool(IDC_BARBEGIN, data, PREFS_SLIDERAT0);  
            
         }  
         virtual Bool CreateLayout()  
         {  
              Bool res = LoadDialogResource(IDD_DPIT_PREFS,NULL,0);  
              AttachUserArea(ua,IDC_ICONAREA);  
              return res;  
         }  
          
        virtual void EnableValues(BaseContainer *data)  
        {  
        }  
          
        virtual LONG CommandValues(LONG id, const BaseContainer &msg;, BaseContainer *data)  
        {  
         switch (id)   
         {       
         case IDC_BARBEGIN: GetBool(id, data, PREFS_SLIDERAT0); break;  
                          
                    }  
          return TRUE;  
        }       
    };
    

    HTH
    Samir



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/09/2004 at 12:06, xxxxxxxx wrote:

    So.. i would say this means that you store all your data in the Worldcontainer without putting it in a "sub" Container.   At least i'm very sure this was the case for me.
    There is one thing i would like to know. If you do it like this, how do you retrieve your prefs data outside of the Prefs Dialog.
    I simply do ...
    Basecontainer *prefs = GetWorldContainerInstance()->GetContainerInstance(PLUGIN_ID);
    ... and i can do this everywhere in my code.
     
    Btw. i have a pretty cool "ScanContainer" function that prints all data in a Container to the DebugConsole using GeDebugOut.
    Anyone interested might have a look
    http://www.welter-4d.de/myc4dtools.h
    http://www.welter-4d.de/myc4dtools.cpp
    Samir you could use it to scan your "data" container to see if it's really what you expect.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/09/2004 at 12:17, xxxxxxxx wrote:

    yes, I am reading it out elsewhere in the code too by simply accessing the world container as you do. :)

    Hehe, I also have a similar Scan Container function, but I am using the BrowseContainer Class for this.

    But surely someone can use this. Thanks for sharing

    Best



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 19/09/2004 at 02:43, xxxxxxxx wrote:

    But in
        virtual void SetValues(BaseContainer *data)
        {
          if (!data) return;
          SetBool(IDC_BARBEGIN, data, PREFS_SLIDERAT0);
         
         }
    isnt "data" the WorldContainer with lot's of other stuff ??
    For me it is 8-o



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 19/09/2004 at 05:49, xxxxxxxx wrote:

    Quote: _isnt "data" the WorldContainer with lot's of other stuff ??
    >
    > * * *
    _


    yes, why? IDC_BARBEGIN is a unique ID, that way I make sure I am not running into conflicts (hopefully, if other people use unique IDs too).



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 19/09/2004 at 08:52, xxxxxxxx wrote:

    Hmm... ok.. how do you get a unique ID ?   Is it your plugin ID ?  What if you want to store more than one Boolean ? You need unique iD's for all your variables ??!!



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 19/09/2004 at 09:02, xxxxxxxx wrote:

    yeah, for each one. I get all from the plugin cafe here. There is maybe a range that is never used (for example you could just use an imaginary number that is very high, like: 94560345743267 and then just count up for all your variables. I doubt anybody else will ever have this exact same number in use in conjunction with the worldcontainer :-) You just need to go sure that you are not overwriting any of c4ds values.)



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 19/09/2004 at 13:45, xxxxxxxx wrote:

    8-]   
    well.. btw.. i found out that the "BaseContainer *data" isn't probably a pointer to the realy WorldContainer, but to a copy of the worldcontainer.  It seemed to me that reading and writing to this Container only changes things in the PrefsDialog (?!).  So I've changed my code again, and it should finally work...

        
        
        
        
        class PrefsDlg : public PrefsDlg_Base   
        {  
        public:  
         PrefsDialogHookClass *hook;  
         PrefsDlg(PrefsDialogHookClass* hook) :   
          PrefsDlg_Base(DLG_PREFS,hook),hook(hook)  
          {}  
            
         virtual void SetValues(BaseContainer* data)   
         {  
          if(!data) return;  
          data = data->GetContainerInstance(PLUG_ID);  
          if(!data) return;
        
        
        
        
          data->SetBool(FIRSTRUN,TRUE);
        
        
        
        
          SetReal(SCALE,data,SCALE,0.0001,1000.0,0.01);  
          SetBool(FORMAT,data,FORMAT);  
          ..  
          ..  
          ..  
         }
        
        
        
        
         
        
        
        
        
        // must use this command function because the other won't recognize when a button in the dialog is hit 
        
        
        
        
         virtual Bool Command(LONG id,const BaseContainer &msg)  
         {  
          BaseContainer *data = hook->GetData();  
          if(!data) return TRUE;  
          data = data->GetContainerInstance(PLUG_ID);  
          if(!data) return TRUE;
        
        
        
        
          switch(id)  
          {  
           case SCALE: GetReal(id,data,SCALE); break;  
           case FORMAT: GetBool(id,data,FORMAT); break;  
           ..  
           ..  
           ..  
          }
        
        
        
        
          Filename fn;  
          switch(id)  
          {  
           case TEMP_DIR_BTN:  
           {  
            ..   
            ..  
            data->SetFilename(TEMP_DIR,fn);  
            SetFilename(TEMP_DIR,data,TEMP_DIR);  
           }  
           break;  
           ..  
           ..  
           ..  
          }
        
        
        
        
          GetWorldContainerInstance()->SetContainer(PLUG_ID,*data);
        
        
        
        
          return TRUE;  
         }  
        };
        
        
        
    

Log in to reply