view src/main.cpp @ 25:b3b3b8e97b54 v2.2dev

Added tag v2.2 for changeset 5c99c6fa50df
author pyon@macmini
date Thu, 03 Nov 2011 15:47:25 +0900
parents c540dc3eabe5
children 405e08552527
line wrap: on
line source

// Filename   : main.cpp
// Last Change: 26-Oct-2011.
//

#include "common.h"
#include "main.h"
#include "myframe.h"
//#include "testframe.cpp"

IMPLEMENT_APP(MyApp)

IMPLEMENT_CLASS( MyApp, wxApp )

MyApp::MyApp()
{
}
MyApp::~MyApp()
{
}

bool MyApp::OnInit()
{
    if ( !wxApp::OnInit() ) return false;

    wxImage::AddHandler( new wxJPEGHandler );
    wxImage::AddHandler( new wxPNGHandler );

    ConfInit();
    InitLog();

    wxString progname = wxT("A Mover");
    wxString verstr = wxString::Format( wxT(" - v%d.%d ( build %d )"), VER, REV, BLD );
    wxString title = progname + verstr;

    MyFrame *mainframe = new MyFrame( NULL, ID_MAIN, title );
    mainframe->SetSize( rect );
    mainframe->SetMinSize( wxSize( 1200, 400 ) );
    mainframe->Show(true);
    /*
    TestFrame *tf = new TestFrame( NULL, ID_TEST, wxT("A Test") );
    tf->Show(true);
    */

    return true;
}

int MyApp::OnExit()
{
    config->SetPath( wxT("/Geometry") );
    config->Write( wxT("x"), rect.x );
    config->Write( wxT("y"), rect.y );
    config->Write( wxT("w"), rect.width );
    config->Write( wxT("h"), rect.height );

    config->SetPath( wxT("/WorkDir") );
    config->Write( wxT("workdir"), workdir );

    config->SetPath( wxT("/Param") );
    config->Write( wxT("lmin"), lmin );
    config->Write( wxT("lmax"), lmax );
    config->Write( wxT("zmin"), zmin );
    config->Write( wxT("zmax"), zmax );

    delete config;

    return 0;
}

void MyApp::ConfInit()
{
    conf_file = wxGetCwd() + wxFILE_SEP_PATH + MYAPPNAME + wxT(".conf");
    config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE );

    config->SetPath( wxT("/Geometry") );
    config->Read( wxT("x"), &rect.x );
    config->Read( wxT("y"), &rect.y );
    config->Read( wxT("w"), &rect.width );
    config->Read( wxT("h"), &rect.height );

    config->SetPath( wxT("/WorkDir") );
    config->Read( wxT("workdir"), &workdir );

    config->SetPath( wxT("/Param") );
    config->Read( wxT("lmin"), &lmin );
    config->Read( wxT("lmax"), &lmax );
    config->Read( wxT("zmin"), &zmin );
    config->Read( wxT("zmax"), &zmax );
}

void MyApp::InitLog()
{
    wxDateTime now = wxDateTime::Now();
    wxTextFile logfile;
    logfile.Open(wxT("log"));
    logfile.Clear();
    logfile.AddLine( now.Format(wxT("%Y-%m-%d %H:%M:%S ")) + wxT("[Application start...]") );
    logfile.Write();
    logfile.Close();
}
void MyApp::WriteLog( wxString msg )
{
    wxDateTime now = wxDateTime::Now();
    wxTextFile logfile;
    logfile.Open(wxT("log"));
    logfile.AddLine( now.Format(wxT("%Y-%m-%d %H:%M:%S ")) + msg );
    logfile.Write();
    logfile.Close();
}