home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-16 | 8.8 KB | 313 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CGraphWindow.cp ©1995-97 Timo Eloranta All rights reserved.
- // ===========================================================================
-
- #include "CGraphWindow.h"
- #include "CGraphGAApp.h"
- #include "GraphGA_PaneIDs.h"
- #include <LString.h>
-
-
- // ---------------------------------------------------------------------------
- // • CGraphWindow
- //
- // Called by: URegistrar::CreateObject
- // ---------------------------------------------------------------------------
-
- CGraphWindow::CGraphWindow(
- LStream *inStream)
- : LWindow(inStream)
- {
- }
-
- // ---------------------------------------------------------------------------
- // • FinishCreateSelf
- //
- // Called by: LView::FinishCreate
- // ---------------------------------------------------------------------------
- // Finish Creating a Pane
- //
- // This function gets called after creating a Pane from a data stream.
- // Override to perform finishing touches that depend on the entire
- // Pane hierarchy being constructed.
-
- void
- CGraphWindow::FinishCreateSelf()
- {
- mApp = (CGraphGAApp *) mSuperCommander;
-
- mGraphPane = (CGraphPane *) FindPaneByID( pane_GraphDrawing );
-
- mGraphPane -> SetApp( mApp );
-
- // Make the graph pane latent so that
- // when the window becomes active
- // the graph pane is the target.
-
- SetLatentSub( mGraphPane );
-
- // Set light grey as backcolor.
- // Actually only backgrounds of the caption fields will get
- // the light grey color, but hey, I like it that way... :)
-
- const RGBColor greyRGB = { 0xEEEE, 0xEEEE, 0xEEEE };
- SetForeAndBackColors( nil, &greyRGB );
-
- mPopSizeCapt = (LCaption*) FindPaneByID( capt_PopSize );
- mCurGenerCapt = (LCaption*) FindPaneByID( capt_CurGeneration );
- mRunningCapt = (LCaption*) FindPaneByID( capt_RunningTime );
- mLeastCapt = (LCaption*) FindPaneByID( capt_LeastCrossings );
- mAverageCapt = (LCaption*) FindPaneByID( capt_AvgCrossings );
- mIterCapt = (LCaption*) FindPaneByID( capt_IterState );
- mFitnessCapt = (LCaption*) FindPaneByID( capt_BestEverFitness );
- mBestGenCapt = (LCaption*) FindPaneByID( capt_BestEverGeneration );
- mNoGenCapt = (LCaption*) FindPaneByID( capt_NoChangeGenerations );
- mNoTimeCapt = (LCaption*) FindPaneByID( capt_NoChangeTime );
- }
-
- // ---------------------------------------------------------------------------
- // • ResetSuperCommanderToApp
- //
- // Called by: CGraphGAApp::RemoveDoc
- // ---------------------------------------------------------------------------
-
- void
- CGraphWindow::ResetSuperCommanderToApp( )
- {
- SetSuperCommander( mApp );
- }
-
- // ---------------------------------------------------------------------------
- // • UpdateGraphInfo
- //
- // Called by: CGraphGAApp::InitForNoGraph
- // CGraphGAApp::ObeyCommand
- // CGraphGADoc::PrepareToIterate
- // ---------------------------------------------------------------------------
-
- void
- CGraphWindow::UpdateGraphInfo( CPopulation *inPop )
- {
- LCaption *theCaption;
- LStr255 theString;
-
- // Name
- theCaption = (LCaption*) FindPaneByID( capt_Name );
-
- if ( inPop ) {
- GetDescriptor( theString );
- theCaption -> SetDescriptor( theString );
- } else
- theCaption -> SetDescriptor( "\pn/a" );
-
- // Nodes
- theCaption = (LCaption*) FindPaneByID( capt_Nodes );
- if ( inPop ) {
- theCaption -> SetValue( (Int32) inPop -> GetNodeCount() );
- theCaption -> Refresh();
- } else
- theCaption -> SetDescriptor( "\pn/a" );
-
- // Edges
- theCaption = (LCaption*) FindPaneByID( capt_Edges );
- if ( inPop ) {
- theCaption -> SetValue( (Int32) inPop -> GetEdgeCount() );
- theCaption -> Refresh();
- } else
- theCaption -> SetDescriptor( "\pn/a" );
-
- // Grid size - for example "20 x 20"
- theCaption = (LCaption*) FindPaneByID( capt_GridSize );
- LStr255 theNbrString( (Int32) mApp -> GetGridSize() );
-
- theString.Assign( theNbrString );
- theString.Append( "\p x " );
- theString.Append( theNbrString );
-
- theCaption -> SetDescriptor( theString );
- }
-
- // ---------------------------------------------------------------------------
- // • UpdatePopInfo
- //
- // Called by: CGraphGAApp::InitForNoGraph
- // CGraphGAApp::ObeyCommand
- // CGraphGADoc::SpendTime
- // ---------------------------------------------------------------------------
-
- void
- CGraphWindow::UpdatePopInfo( Boolean inPopSizeToo, CPopulation *inPop )
- {
- LStr255 theString;
- Int32 theTimeInTicks, theMinutes, theSeconds;
- static Int32 theOldSeconds1 = 0;
-
- // Pop size
- // Doesn't change during iteration, so we usually don't update it
- if ( inPopSizeToo ) {
- mPopSizeCapt -> SetValue( (Int32) mApp -> mGeneral.sizePop );
- mPopSizeCapt -> Refresh();
- }
-
- // Current generation
- if ( inPop ) {
- mCurGenerCapt -> SetValue( inPop -> GetCurGeneration() );
- mCurGenerCapt -> Refresh();
- } else
- mCurGenerCapt -> SetDescriptor( "\pn/a" );
-
- // Total running time (1 minute == 3600 ticks...)
- if ( inPop ) {
- theTimeInTicks = inPop -> GetRunningTime();
- theMinutes = theTimeInTicks / 3600;
- theSeconds = (theTimeInTicks % 3600) / 60;
-
- if ( (theSeconds != theOldSeconds1) || (theSeconds == 0) ) {
- theString.Assign( theMinutes );
- if ( theSeconds > 9 )
- theString.Append( "\p:" );
- else theString.Append( "\p:0" );
-
- LStr255 theNbrString( theSeconds );
- theString.Append( theNbrString );
- mRunningCapt -> SetDescriptor( theString );
-
- theOldSeconds1 = theSeconds;
- }
- } else
- mRunningCapt -> SetDescriptor( "\pn/a" );
-
- // Least crossings
- if ( inPop ) {
- mLeastCapt -> SetValue( inPop -> GetLeastCrossings() );
- mLeastCapt -> Refresh();
- } else
- mLeastCapt -> SetDescriptor( "\pn/a" );
-
- // Average crossings
- if ( inPop ) {
- mAverageCapt -> SetValue( inPop -> GetAvgCrossings() );
- mAverageCapt -> Refresh();
- } else
- mAverageCapt -> SetDescriptor( "\pn/a" );
- }
-
- // ---------------------------------------------------------------------------
- // • UpdateIterStateInfo
- //
- // Called by: CGraphGAApp::InitForNoGraph
- // CGraphGADoc::SetIterState
- // ---------------------------------------------------------------------------
-
- void
- CGraphWindow::UpdateIterStateInfo( EIterState inIterState )
- {
- LStr255 theString;
-
- // Iteration state
-
- switch ( inIterState ) {
-
- case iter_NoGraph:
- theString.Assign( STRx_IterStates, str_NoGraph );
- break;
- case iter_ReadyToGo:
- theString.Assign( STRx_IterStates, str_ReadyToStart );
- break;
- case iter_Running:
- theString.Assign( STRx_IterStates, str_Running );
- break;
- case iter_Paused:
- theString.Assign( STRx_IterStates, str_Paused );
- break;
- case iter_Finished:
- theString.Assign( STRx_IterStates, str_Finished );
- break;
- case iter_Walking:
- theString.Assign( STRx_IterStates, str_Walking );
- break;
- }
-
- mIterCapt -> SetDescriptor( theString );
- }
-
- // ---------------------------------------------------------------------------
- // • UpdateBestInfo
- //
- // Called by: CGraphGAApp::InitForNoGraph
- // CGraphGADoc::PrepareToIterate
- // CGraphGADoc::SpendTime
- // ---------------------------------------------------------------------------
-
- void
- CGraphWindow::UpdateBestInfo( Boolean inBestHasChanged, CPopulation *inPop )
- {
- LStr255 theString, theNbrString;
- Int32 theNoChangeTicks, theMinutes, theSeconds;
- static Int32 theOldSeconds2 = 0;
- CFitness theFitness;
-
- if ( inBestHasChanged ) {
-
- // Fitness
- if ( inPop ) {
- inPop -> GetBestEverFitness( theFitness );
- theString.Assign( (Int32) theFitness.GetCrossings() );
- theString.Append( "\p/" );
- theNbrString.Assign( theFitness.Get2ndValue() );
- theString.Append( theNbrString );
- mFitnessCapt -> SetDescriptor( theString );
- } else
- mFitnessCapt -> SetDescriptor( "\pn/a" );
-
- // Generation
- if ( inPop ) {
- mBestGenCapt -> SetValue( inPop -> GetBestGeneration() );
- mBestGenCapt -> Refresh();
- } else
- mBestGenCapt -> SetDescriptor( "\pn/a" );
- }
-
- // Generations without improvement
- if ( inPop ) {
- mNoGenCapt -> SetValue( inPop -> GetNoChangeGener() );
- mNoGenCapt -> Refresh();
- } else
- mNoGenCapt -> SetDescriptor( "\pn/a" );
-
- // Time without improvement (1 minute == 3600 ticks...)
- if ( inPop ) {
- theNoChangeTicks = inPop -> GetNoChangeTime();
- theMinutes = theNoChangeTicks / 3600;
- theSeconds = (theNoChangeTicks % 3600) / 60;
-
- if ( (theSeconds != theOldSeconds2) || (theSeconds == 0) ) {
- theString.Assign( theMinutes );
- if ( theSeconds > 9 )
- theString.Append( "\p:" );
- else theString.Append( "\p:0" );
-
- theNbrString.Assign( theSeconds );
- theString.Append( theNbrString );
- mNoTimeCapt -> SetDescriptor( theString );
-
- theOldSeconds2 = theSeconds;
- }
- } else
- mNoTimeCapt -> SetDescriptor( "\pn/a" );
- }
-
- // ---------------------------------------------------------------------------
- // • DoSetZoom (OVERRIDE)
- // ---------------------------------------------------------------------------
- // Zoom window to either the Standard or User state
-
- void
- CGraphWindow::DoSetZoom(
- Boolean inZoomToStdState)
- {
- LWindow::DoSetZoom( inZoomToStdState);
-
- LCommander::SetUpdateCommandStatus( true );
- }
-