[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Advice on how best to structure app with V insterface



Here is one way to implement it (its not pretty but it works):
Say you need to send text from your class to a GUI text canvas in the
vCmdWindow.

In your derived vCmdWindow class define a member function such as -
    void myvCmdWindow::MakeMess(LPCSTR msg){textCanvas->DrawText(msg);}

In the your vApp class define a global (friend) function such as -
    friend void MakeMess(LPCSTR msg){((myvApp
*)theApp)->_myvCmdWin->MakeMess(msg); }
_myvCmdWin is a private member variable in your derived vApp class that
points to your derived vCmdWindow, where your GUI components are.

In your class you can have a function pointer that points to the global
MakeMess function such as -
    void (*msgFunc)(LPCSTR msg);
When you instantiate your class set myClass.msgFunc = ::MakeMess
Then call msgFunc("A message") as needed from your class.

Hope this helps.

-----Original Message-----
From: Martin Waller <polytope_@hotmail.com>
To: vgui-discuss@other.debian.org <vgui-discuss@other.debian.org>
Date: Wednesday, September 15, 1999 8:43 AM
Subject: Advice on how best to structure app with V insterface


>Hello,
>
>I'm after some advice on how best to construct my V app.
>
>I have a (vanilla) c++ class (call it base_model) that solves special types
>of differential equations used in population biology. To use it, one
derives
>a new class defining various functions which describe the specific model
you
>wish to create (pure virtual functions in the base class).
>
>This works fine as a console app in either win95 or X.
>
>I've been trying to add gui functionality to it - for other models, I've
>previously used Borland's OWL (the versions that come with BC++ 4.52 and
>5.01).
>
>But now I want them to run under Linux to, so I've switched to V.
>
>So far, I've got code to get user input (for variables, etc. used by the
>model) and can then pass this to the model and run it by just creating an
>instance of the model and running it.  Of course, not being 'V aware' the
>model won't output any progress or results to the gui (running from an
xterm
>though, it will print out stuff using
>cout << variable in the xterm from which the gui app is run).
>
>I want it to be able to comunicate it's progress and results to the gui
>though by:
>
>a) ideally, a progress graph (population vs. time) as the model runs and
>then the possibilty to view other info after the model has ran
>
>or
>
>b) (would do) updating it's progress in a dialog, and then after it's run
>have the ability to select what data to view
>
>What's the best way to do this?
>
>Without any attempt at gui stuff, this works (RunModel() runs when the
>corresponding menuitem, or button bar button is selected, tryit is the
model
>derived from base_model):
>
>derivedCmdWindow::RunModel()
>{
>
>   vNoticeDialog note(this);// Used for default actions
>
>   tryit=new model(/*various input parameters passed*/);//model *tryit is a
>private member of derivedCmdWindow
>
>   note.Notice("tryit created");
>
>   tryit->run();
>
>   note.Notice("Model ran!");
>
>   delete tryit;
>
>}
>
>I thought to add gui functionality I could do one of the following:
>
>for solution a) above:
>
>1. Derive base_model from vCmdWindow (then model from base_model)
>
>2. Derive model jointly from base_model and vCmdWindow
>
>for solution b) above
>
>3. Derive base_model from vDialog
>
>4. derive model jointly from base_model and vDialog
>
>
>Deriving from vDialog has issues, as I can't create the derived model in
>vCmdWindow's constructor (as is usual for dialogs, no?) and deriving from
>vCmdWindow and using the following code casues crashes once the model has
>stopped running:
>
>derivedCmdWindow::RunModel()
>{
>
>   vNoticeDialog note(this);// Used for default actions
>
>   tryit=new model(/*various input parameters passed*/);//tryit * is a
>private member of derivedCmdWindow
> //model derived jointly from base_model and vCmdWindow
>
>   note.Notice("tryit created");
>
>   theApp->NewAppWin(tryit,"Title!",800,600);
>
>   tryit->run();
>
>   note.Notice("Model ran!");
>
>   tryit->CloseWin();
>
>   delete tryit;
>
>}
>
>Comments, advice and suggestions strongly desired!
>
>Please help,
>
>Martin
>
>
>______________________________________________________
>Get Your Private, Free Email at http://www.hotmail.com
>
>
>--
>To UNSUBSCRIBE, email to other-vgui-discuss-request@other.debian.org
>with a subject of "unsubscribe". Trouble? Contact
listmaster@other.debian.org
>
>


Reply to: