home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-03-25 | 7.0 KB | 231 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CParamsDialog.cp ©1996-97 Timo Eloranta
- // ===========================================================================
- // This class handles the dialog where the user can view and modify the
- // parameters of a new neural net. CParamsDialog is derived from LGADialogBox
- // - a PowerPlant window class with default (OK) and Cancel buttons.
-
- #include "CParamsDialog.h"
-
- #include <PP_Messages.h> // cmd_About
- #include <UDesktop.h>
- #include <UAttachments.h>
-
- #include "NS_Utils.h" // SignedIntField keyfilter
-
- // ---------------------------------------------------------------------------
- // • CParamsDialog
- //
- // Called by: CParamsDialog::CreateParamsDialogStream
- // ---------------------------------------------------------------------------
- // Constructor. Call the base class with the LStream object reference.
-
- CParamsDialog::CParamsDialog(
- LStream *inStream )
- : LGADialogBox( inStream )
- {
- }
-
- // ---------------------------------------------------------------------------
- // • CreateParamsDialogStream [static]
- //
- // Called by: CNeuroSimApp::ObeyCommand (indirect call)
- // ---------------------------------------------------------------------------
- // Return a new ParamsDialog object initialized using data from a Stream.
-
- CParamsDialog *
- CParamsDialog::CreateParamsDialogStream(
- LStream *inStream)
- {
- return ( new CParamsDialog( inStream ) );
- }
-
- // ---------------------------------------------------------------------------
- // • InitDialog
- //
- // Called by: CNeuroSimApp::ObeyCommand
- // ---------------------------------------------------------------------------
- // Initialize all the controls inside the dialog.
-
- void
- CParamsDialog::InitDialog()
- {
- mSizeCapt = (LCaption *) this -> FindPaneByID( capt_Size );
-
- mMinEdit = (LGAEditField *) this -> FindPaneByID( edit_Qty_Min );
- mMaxEdit = (LGAEditField *) this -> FindPaneByID( edit_Qty_Max );
- mAvg_X_Edit = (LGAEditField *) this -> FindPaneByID( edit_Avg_x );
- mDev_X_Edit = (LGAEditField *) this -> FindPaneByID( edit_Dev_x );
- mAvg_Y_Edit = (LGAEditField *) this -> FindPaneByID( edit_Avg_y );
- mDev_Y_Edit = (LGAEditField *) this -> FindPaneByID( edit_Dev_y );
-
- mFactoryButton = (LGAPushButton *) this -> FindPaneByID( but_Factory );
-
- if ( mFactoryButton)
- mFactoryButton -> AddListener( this );
-
- mSizeSlider = (CAGASlider *) this -> FindPaneByID( slid_Size );
-
- if ( mSizeSlider )
- mSizeSlider -> AddListener( this );
-
- mMinEdit -> Enable();
- mMinEdit -> Activate();
- mMinEdit -> SelectAll();
-
- // The average values can be negative and since PowerPlant
- // doesn't have a built-in keyfilter for allowing only
- // numbers and the '-' character, we set our custom keyfilter
- // here "manually". The filter is defined in NS_Utils.h.
-
- mAvg_X_Edit -> SetKeyFilter( SignedIntField );
- mAvg_Y_Edit -> SetKeyFilter( SignedIntField );
- }
-
- // ---------------------------------------------------------------------------
- // • SetValues
- //
- // Called by: CNeuroSimApp::ObeyCommand
- // CParamsDialog::SetDefaultValues
- // ---------------------------------------------------------------------------
- // Set the controls of the dialog to the values given in "inParams".
-
- void
- CParamsDialog::SetValues( SGenParams &inParams )
- {
- SetSizeValue( inParams.size );
- mSizeSlider -> SetValue( inParams.size );
-
- mMinEdit -> SetValue( inParams.qtyMin );
- mMaxEdit -> SetValue( inParams.qtyMax );
- mAvg_X_Edit -> SetValue( inParams.xLengthAvg );
- mDev_X_Edit -> SetValue( inParams.xLengthDev );
- mAvg_Y_Edit -> SetValue( inParams.yLengthAvg );
- mDev_Y_Edit -> SetValue( inParams.yLengthDev );
- }
-
- // ---------------------------------------------------------------------------
- // • SetSizeValue
- //
- // Called by: CParamsDialog::SetValues
- // CParamsDialog::ListenToMessage
- // ---------------------------------------------------------------------------
- // Transform the given (numeric) net size N to a string of type "N x N"
- // and set this string to the caption field beside the slider.
-
- void
- CParamsDialog::SetSizeValue( Int16 inValue )
- {
- LStr255 theNbrString( (Int32) inValue );
- LStr255 theString( theNbrString );
-
- theString.Append( "\p x " );
- theString.Append( theNbrString );
-
- mSizeCapt -> SetDescriptor( theString );
- }
-
- // ---------------------------------------------------------------------------
- // • GetValues
- //
- // Called by: CNeuroSimApp::ObeyCommand
- // ---------------------------------------------------------------------------
- // Read the new values of the controls. Do also some validity checking.
-
- void
- CParamsDialog::GetValues( SGenParams &outParams )
- {
- outParams.size = mSizeSlider -> GetValue();
-
- outParams.xLengthAvg = mAvg_X_Edit -> GetValue();
- outParams.xLengthDev = mDev_X_Edit -> GetValue();
- outParams.yLengthAvg = mAvg_Y_Edit -> GetValue();
- outParams.yLengthDev = mDev_Y_Edit -> GetValue();
-
- outParams.qtyMin = mMinEdit -> GetValue();
- outParams.qtyMax = mMaxEdit -> GetValue();
-
- // Minimum can not be bigger than maximum...
- // If it is, set the maximum to be equal to minimum
- // and show an alert box to the silly user!
-
- if ( outParams.qtyMax < outParams.qtyMin ) {
- outParams.qtyMax = outParams.qtyMin;
- LStr255 theParam0( (Int32) outParams.qtyMin );
-
- UDesktop::Deactivate();
- ::ParamText( theParam0, "\p", "\p", "\p");
- ::StopAlert( ALRT_MinMax, nil );
- UDesktop::Activate();
- }
- }
-
- // ---------------------------------------------------------------------------
- // • ListenToMessage
- //
- // Called by: LBroadcaster::BroadcastMessage
- // ---------------------------------------------------------------------------
- // Respond to messages from Broadcasters
-
- void
- CParamsDialog::ListenToMessage(
- MessageT inMessage,
- void *ioParam )
- {
- switch ( inMessage ) {
-
- case slid_Size:
- if ( mSizeCapt ) {
- SetSizeValue( *(Int32 *) ioParam );
- mSizeCapt -> Draw( NULL );
- }
- break;
-
- case msg_FactorySettings:
- SetDefaultValues();
- break;
-
- default:
- LGADialogBox::ListenToMessage( inMessage, ioParam );
- break;
- }
- }
-
- // ---------------------------------------------------------------------------
- // • SetDefaultValues
- //
- // Called by: CParamsDialog::ListenToMessage
- // ---------------------------------------------------------------------------
- // This function is used when the user pushes the "Factory Settings" button.
-
- void
- CParamsDialog::SetDefaultValues()
- {
- SGenParams theDefaults = { DEFAULT_LENGTH_X_AVG, DEFAULT_LENGTH_Y_AVG,
- DEFAULT_LENGTH_X_DEV, DEFAULT_LENGTH_Y_DEV,
- DEFAULT_NET_SIZE,
- DEFAULT_QTY_MIN, DEFAULT_QTY_MAX };
- SetValues( theDefaults );
- }
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- //
- // Called by: LCommander::ProcessCommandStatus
- // ---------------------------------------------------------------------------
- // Disable all menu commands except cmd_About
-
- void
- CParamsDialog::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean& /* outUsesMark */,
- Char16& /* outMark */,
- Str255 /* outName */)
- {
- outEnabled = false;
- if (inCommand == cmd_About) {
- outEnabled = true;
- }
- }
-