Extract info from Dialog in calling class



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

    On 25/02/2003 at 22:29, xxxxxxxx wrote:

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

    ---------
    At the beginning of my plugin's run, a configuration dialog (GeModalDialog) is opened by my configuration class (which stores the user configuration) to get some user information.  But, how does one get the settings out of the dialog when closed to apply to the calling class's variables?
    Thanks,
    Robert



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

    On 26/02/2003 at 11:20, xxxxxxxx wrote:

    Just to add, GeDialog.GetBool(GadgetPtr&, Bool&) is a strange beast indeed.  The return value is only an indication of success in getting the value and the value to be set in the arguments is not a pointer (at least it won't compile as one).  I've been programming long enough to realize that there are only two ways to set a value from a function - return it or supply the function with a pointer to store it in.  This has neither.
    I'm still waiting :)
    Robert



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

    On 26/02/2003 at 13:09, xxxxxxxx wrote:

    First of all, you have to retrieve the value before the dialog is closed. This is best done in the Command() function. A good practise, that I use myself, is to always keep an updated BaseContainer of all values in the dialog as a member of the dialog class. Then I have a DialogToContainer() and a ContainerToDialog() function that I call in the Command() function.
    Second, welcome to the world of C++. There are three ways to pass an argument: by-copy (no suffix), by-reference (& suffix) and by-pointer (* suffix). The main difference between pointer and reference is that the former has no equivalent of a null pointer. Syntax wise reference is like passing an object in Java, copy is like passing a primitive, though of course in Java there are null references. So the call is:

        
        
        Bool val = FALSE;  
        Bool success = GetBool(id, val);
    


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

    On 26/02/2003 at 15:41, xxxxxxxx wrote:

    I've programmed C for over 10 years; BASIC, LISP, PASCAL, C/C++, Java, Python, Assembly (68K and x86).  I've never used this "&" reference (which is particular to C++), only pass pointers when references are needed to memory storage (variables, structs, classes, etc).  And once again, Java is sweet.  Couldn't you have make a Java SDK instead! ;0)  This is one of the EXACT reasons why I dumped C++ as fast as possible: it's a complex mess (because it builds a substantially new and confusing layer on top of its base - C) - not truly OOP, not truly procedural, not totally understandable (and that's an understatement for someone with my experience).
    Still, I did what you show above before I asked and it did not set "val" (e.g.) to the correct value.
    Can you show an example of how to implement the "dialog calling" class, dialog, and BaseContainer to interact with one another.  The dialog is temporary (scoped within a calling class method), but the calling class persists throughout the plugin's execution.  This is why I need to get at the settings in the dialog - they're not 'act now' settings , they're constant settings.
    Thanks,
    Robert



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

    On 26/02/2003 at 23:11, xxxxxxxx wrote:

    You shouldn't be so fast to judge C++. It's complex, but only a mess the first few years of using it. Actually, Java could benefit from references, because currently one has to use cludges like "class Integer" to pass ints by reference/pointer.
    The distinction between references and pointers is more semantic than technical (even if it's nice to know for a function that it will never receive a null pointer, and that a reference cannot change). As always there are several schools.
    My interpretation of modern C++ is to use references where possible and pointers when you have to, due to the dangers of pointers that can be NULL and change.
    In the C4D SDK there's a distinction between what I call C4D classes and SDK classes.
    The former are things like BaseObject that are only reflections of a real object in C4D space, or as Platon would have said it shadows of an idea in C4D. These are characterised by having an ::Alloc() function for instantiation. When these objects are passed they are usually passed as pointers.
    The latter are things like String, more self contained objects, some of them with value semantics (i.e. they represent a value and have no other state). These can be allocated like normal C++ classes and are mostly passed by references.
    For a Java head there's also the important concept of const correctness to learn.  In C4D, const correctness is only used with SDK objects and thus only with references. The difference between "const String& str" and just "String& str" is that the former cannot be altered. This is so because C++ forbids any calls to "str" that aren't const qualified. For example "GetLength() const" is allowed, "Delete()" isn't. This way you can reap all the performance benefits of passing by reference/pointer without having to worry about the function modifiying your object. This both protects against logical errors when programming and acts as a self documentation of the code.
    (I guess these are the kinds of thing one philosophizes upon after having to use the C++ SDK for a couple of years... :-)
    As for your question, here's a code example from MSA: (A bit unpedagogic since it uses the other form of GetBool(), but you'll see what I mean with CToD() and DToC().)

        
        
        class MSATextDialog : public GeModalDialog  
        {  
        public:  
          virtual Bool CreateLayout();  
          virtual Bool InitValues();
        
        
        
        
          void ContainerToDialog();  
          void DialogToContainer();  
            
          virtual Bool Command(LONG id, const BaseContainer& msg);
        
        
        
        
          BaseContainer bc;  
        };
        
        
        
        
        Bool MSATextDialog::CreateLayout()  
        {  
          return LoadDialogResource(MSA_TEXT_DIALOG, NULL, 0);  
        }
        
        
        
        
        Bool MSATextDialog::InitValues()  
        {  
          ContainerToDialog(); // Fill all values  
          return TRUE;  
        }
        
        
        
        
        void MSATextDialog::ContainerToDialog()  
        {    
          SetString(RESULT_NAME, bc.GetString(RESULT_NAME, "MSA Text"));  
          SetMeter(TEXT_HEIGHT, bc.GetReal(TEXT_HEIGHT, 0.0));  
          SetBool(CENTER_TEXT, bc.GetBool(CENTER_TEXT));  
        }
        
        
        
        
        void MSATextDialog::DialogToContainer()  
        {  
          GetString(RESULT_NAME, &bc, RESULT_NAME);  
          GetReal(TEXT_HEIGHT, &bc, TEXT_HEIGHT);  
          GetBool(CENTER_TEXT, &bc, CENTER_TEXT);  
        }
        
        
        
        
        Bool MSATextDialog::Command(LONG id, const BaseContainer& msg)  
        {  
          DialogToContainer(); // Get all values  
          return TRUE;  
        }
        
        
        
        
         
        
        
        
        
        Bool MSATextMenuPlugin::Execute(BaseDocument* doc)  
        {  
          BaseObject* obj = doc->GetActiveObject();  
          if (!obj)   
          {  
            MessageDialog(ERROR_SELECT_OBJECT_TEXT);  
            return FALSE;  
          }  
            
          BaseContainer bc;  
          bc.SetData(RESULT_NAME, obj->GetName() + " MSA");  
            
          // Bring up the dialog  
          MSATextDialog dialog;  
          dialog.bc = bc;  
          dialog.Open();  
            
          // Check the result  
          if (!dialog.GetResult()) return FALSE;  
          else bc = dialog.bc;  
          
          // Calling dialog.GetBool() here wouldn't work...  
            
          DoMSAText(doc, obj, bc);  
            
          return TRUE;  
        }
    


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

    On 27/02/2003 at 01:12, xxxxxxxx wrote:

    I'm not too fast in judging C++.  I learnt it some years ago and found it confusing then, even with the popular "C->C++" type of books.  I do still have Bjarne Stroustrup's book for reference and have added a couple other books lately.  Maybe it has solidified over this period, but I must say that Java was simple to learn and yielded quick results.  I wrote an entire 2D+3D application (loading images and .obj files, with a basic interface for displaying/manipulating the hidden wireframe mesh and allowing the image to show through - not an easy task in plain Java, my own 3D engine - no Java3D) in several months after only spending a couple months learning Java (my OOP was pretty rusty at the time).  That's efficiency.  I guess it's a matter of the language/tools/metaphors to which you become accustomed in programming.  Obviously, some of the intricacies of C++ and the SDK still allude me.
    const doesn't bother me.  About the same functionality (eh hem, I hope :) as in C, one would gather.  One good thing about me is that I'm a fanatical checker.  My code goes like this:
    do something
    check it
    do something
    check it
    Nulls rarely get by. ;0)  And I've implemented an entire class-based ErrorException so that the error checking is minimized, handled automatically by throws, and proper dialogs are displayed on the way out.
    Yeah, I saw that [b]other[/b] GetBool() in BaseContainer and that made me look through the examples, well, for an example! :0)
    Thanks for putting up with this "wish-it-were-Java" programmer :) and for the example.  Wait till I'm done parsing this mess (nearly finished) and start converting the data.  Expect a barrage of ignorance, uh, questions...
    Robert


Log in to reply