X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fctsim.cpp;h=7097857d6662a09674662c57b5a2ee1722cccfdb;hp=d58e7daecc5e274ddb736c92f20f16ffca023383;hb=e8462f7431582627e44906239077f1c696eefba1;hpb=c2aaf11a652d43cf38959a33fe4a1275351351d2 diff --git a/src/ctsim.cpp b/src/ctsim.cpp index d58e7da..7097857 100644 --- a/src/ctsim.cpp +++ b/src/ctsim.cpp @@ -36,6 +36,7 @@ #include "wx/image.h" #include "wx/filesys.h" #include "wx/fs_zip.h" +#include "wx/cmdline.h" #ifdef __WXMSW__ #include "wx/msw/helpchm.h" #endif @@ -67,23 +68,15 @@ #endif #endif -static const char* rcsindent = "$Id$"; - -struct option CTSimApp::ctsimOptions[] = -{ - {"help", 0, 0, O_HELP}, - {"version", 0, 0, O_VERSION}, - {"print", 0, 0, O_PRINT}, - {0, 0, 0, 0} -}; IMPLEMENT_APP(CTSimApp) CTSimApp::CTSimApp() : m_bAdvancedOptions(false), m_bSetModifyNewDocs(true), m_bVerboseLogging(false), m_bShowStartupTips(true), -m_iCurrentTip(0), m_bUseBackgroundTasks(false), -m_docManager(NULL), m_pFrame(NULL), m_pConfig(0), m_pLog(0), m_pLogDoc(0) + m_iCurrentTip(0), m_bUseBackgroundTasks(false), + m_docManager(NULL), m_pFrame(NULL), m_pConfig(0), m_pLog(0), m_pLogDoc(0), + m_bPrintCmdLineImages(false), m_bCmdLineVerboseFlag(false) { theApp = this; } @@ -96,10 +89,57 @@ m_docManager(NULL), m_pFrame(NULL), m_pConfig(0), m_pLog(0), m_pLogDoc(0) #include #endif + +void CTSimApp::OnInitCmdLine(wxCmdLineParser& parser) +{ + static const wxCmdLineEntryDesc cmdLineDesc[] = { + { wxCMD_LINE_SWITCH, wxT_2("l"), wxT_2("verbose"), wxT_2("verbose logging") }, + { wxCMD_LINE_SWITCH, wxT_2("v"), wxT_2("version"), wxT_2("print version") }, + { wxCMD_LINE_SWITCH, wxT_2("p"), wxT_2("print"), wxT_2("print images from command line"), + wxCMD_LINE_VAL_NONE, + wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_SWITCH, wxT_2("h"), wxT_2("help"), wxT_2("print this help message"), + wxCMD_LINE_VAL_NONE, + wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_OPTION_HELP }, + { wxCMD_LINE_PARAM, NULL, NULL, wxT_2("input file"), + wxCMD_LINE_VAL_STRING, + wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE }, + wxCMD_LINE_DESC_END + }; + + parser.SetDesc(cmdLineDesc); +} + +bool CTSimApp::OnCmdLineParsed(wxCmdLineParser& parser) +{ + if (wxApp::OnCmdLineParsed(parser) == false) + return false; + + if (parser.Found(_T("version"))) { +#ifdef VERSION + std::cout << "Version: " << VERSION << std::endl; +#elif defined(CTSIMVERSION) + std::cout << "Version: " << CTSIMVERSION << std::endl; +#else + std::cout << "Version: " << "Unknown" << std::endl; +#endif + return false; + } + if (parser.Found(_T("print"))) { + m_bPrintCmdLineImages = true; + } + if (parser.Found(_T("verbose"))) { + m_bCmdLineVerboseFlag = true; + } + + return true; +} + bool CTSimApp::OnInit() { - wxApp::OnInit(); + if (! wxApp::OnInit()) + return false; #ifdef HAVE_SETPRIORITY setpriority (PRIO_PROCESS, 0, 15); // set to low scheduling priority @@ -108,50 +148,6 @@ CTSimApp::OnInit() openConfig(); g_bRunningWXWindows = true; - bool bPrintFiles = false; - // process options - while (1) { -#ifdef __WXMAC__ - int c = -1; -#else - char** cargv = new char* [argc]; - for (int i = 0; i < argc; i++) { - const char* p = wxConvUTF8.cWX2MB(argv[i]); - cargv[i] = new char [strlen(p)+1]; - strcpy(cargv[i], p); - } - int c = getopt_long (argc, cargv, "", ctsimOptions, NULL); - for (int i = 0; i < argc; i++) { - delete cargv[i]; - } - delete cargv; - -#endif - if (c == -1) - break; - - switch (c) { - case O_VERSION: - std::cout << rcsindent << std::endl; -#ifdef VERSION - std::cout << "Version: " << VERSION << std::endl; -#elif defined(CTSIMVERSION) - std::cout << "Version: " << CTSIMVERSION << std::endl; -#endif - exit(0); - case O_HELP: - case '?': - usage (wxConvCurrent->cWX2MB(argv[0])); - exit (0); - case O_PRINT: - bPrintFiles = true; - break; - default: - usage (wxConvCurrent->cWX2MB(argv[0])); - exit (1); - } - } - m_docManager = new wxDocManager (wxDEFAULT_DOCMAN_FLAGS, true); m_pDocTemplImage = new wxDocTemplate (m_docManager, _T("ImageFile"), _T("*.if"), _T(""), _T("if"), _T("ImageFile"), _T("ImageView"), CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView)); @@ -197,9 +193,9 @@ CTSimApp::OnInit() m_pLogDoc = newTextDoc(); if (m_pLogDoc) { m_pLog = m_pLogDoc->getTextCtrl(); - m_pLogDoc->SetDocumentName("Log.txt"); - m_pLogDoc->SetFilename("Log.txt"); - m_pLogDoc->getView()->getFrame()->SetTitle("Log"); + m_pLogDoc->SetDocumentName(_T("Log.txt")); + m_pLogDoc->SetFilename(_T("Log.txt")); + m_pLogDoc->getView()->getFrame()->SetTitle(_T("Log")); int xSize, ySize; m_pFrame->GetClientSize(&xSize, &ySize); int yLogSize = ySize / 4; @@ -238,7 +234,7 @@ CTSimApp::OnInit() for (int i = optind + 1; i <= argc; i++) { wxString filename = argv [i - 1]; wxDocument* pNewDoc = m_docManager->CreateDocument (filename, wxDOC_SILENT); - if (bPrintFiles) { + if (m_bPrintCmdLineImages) { wxView* pNewView = pNewDoc->GetFirstView(); wxPrintout *printout = pNewView->OnCreatePrintout(); if (printout) { @@ -251,12 +247,14 @@ CTSimApp::OnInit() m_docManager->OnFileClose (nullEvent); } } - if (bPrintFiles) { +#ifdef KMR_FIXME + // Move to wx3.0 event processing + if (m_bPrintCmdLineImages) { wxCommandEvent closeEvent; closeEvent.SetInt (MAINMENU_FILE_EXIT); m_pFrame->AddPendingEvent(closeEvent); } - +#endif if (getStartupTips()) ShowTips(); @@ -351,18 +349,6 @@ CTSimApp::closeConfig() } -wxString -CTSimApp::getUntitledFilename() -{ - static int untitledNumber = 1; - - wxString filename (_T("Untitled")); - filename << untitledNumber++; - - return (filename); -} - - // Top-level window for CTSim #if CTSIM_MDI @@ -404,7 +390,12 @@ EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary) EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom) EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter) EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit) + +// Unsure how to fix, OnMRUFile procedure not found in packge +#ifdef KMR_FIXME EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile) +#endif + EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0) EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1) EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2) @@ -432,7 +423,7 @@ END_EVENT_TABLE() #if CTSIM_MDI MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type) -: wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame") +: wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, _T("MainFrame")) #else MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type) : wxDocParentFrame(manager, frame, id, title, pos, size, type, _T("MainFrame")) @@ -601,7 +592,6 @@ MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event)) m_dDefaultFilterBandwidth << _T(", inputScale=") << m_dDefaultFilterInputScale << _T(", outputScale=") << m_dDefaultFilterOutputScale; *theApp->getLog() << os << _T("\n"); - wxString filename = _T("untitled.if"); ImageFileDocument* pFilterDoc = theApp->newImageDoc(); pFilterDoc->setBadFileOpen(); if (! pFilterDoc) { @@ -908,7 +898,7 @@ public: }; BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle) - : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle,*wxConvCurrent), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE) + : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle,*wxConvCurrent), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE) { wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); @@ -977,13 +967,8 @@ MainFrame::OnImport (wxCommandEvent& WXUNUSED(event) ) return; } -#if WXWIN_COMPATIBILITY_2_4 - wxString strFilename = wxFileSelector (wxString(wxConvUTF8.cMB2WX("Import Filename")), wxString(wxConvUTF8.cMB2WX("")), - wxString(wxConvUTF8.cMB2WX("")), strExt, strWildcard, wxHIDE_READONLY | wxOPEN); -#else wxString strFilename = wxFileSelector (wxString(wxConvUTF8.cMB2WX("Import Filename")), wxString(wxConvUTF8.cMB2WX("")), - wxString(wxConvUTF8.cMB2WX("")), strExt, strWildcard, wxOPEN); -#endif + wxString(wxConvUTF8.cMB2WX("")), strExt, strWildcard, wxFD_OPEN); if (! strFilename.IsEmpty()) { if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM || m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) { @@ -1085,28 +1070,40 @@ MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) // Create new documents -ProjectionFileDocument* -CTSimApp::newProjectionDoc() -{ - ProjectionFileDocument* newDoc = dynamic_cast(m_pDocTemplProjection->CreateDocument (_T(""))); +wxDocument* +CTSimApp::newDocumentHelper (wxDocTemplate* tmpl) { + wxDocument* newDoc = tmpl->CreateDocument (_T("")); if (newDoc) { - newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName()); - newDoc->SetDocumentTemplate (m_pDocTemplProjection); + newDoc->SetDocumentTemplate (tmpl); newDoc->OnNewDocument(); + wxString fname = newDoc->GetFilename(); + fname += _T("."); + fname += tmpl->GetDefaultExtension(); + newDoc->SetDocumentName(fname); + newDoc->SetTitle(fname); + newDoc->SetFilename(fname, true); } return newDoc; } +ProjectionFileDocument* +CTSimApp::newProjectionDoc() +{ + ProjectionFileDocument* newDoc = dynamic_cast + (newDocumentHelper(m_pDocTemplProjection)); + if (newDoc) + newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName()); + return newDoc; +} + ImageFileDocument* CTSimApp::newImageDoc() { - ImageFileDocument* newDoc = dynamic_cast(m_pDocTemplImage->CreateDocument (_T(""))); - if (newDoc) { - newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName()); - newDoc->SetDocumentTemplate (m_pDocTemplImage); - newDoc->OnNewDocument(); - } + ImageFileDocument* newDoc = dynamic_cast + (newDocumentHelper(m_pDocTemplImage)); + if (newDoc) + newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName()); return newDoc; } @@ -1114,12 +1111,10 @@ CTSimApp::newImageDoc() PlotFileDocument* CTSimApp::newPlotDoc() { - PlotFileDocument* newDoc = dynamic_cast(m_pDocTemplPlot->CreateDocument (_T(""))); - if (newDoc) { - newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName()); - newDoc->SetDocumentTemplate (m_pDocTemplPlot); - newDoc->OnNewDocument(); - } + PlotFileDocument* newDoc = dynamic_cast + (newDocumentHelper(m_pDocTemplPlot)); + if (newDoc) + newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName()); return newDoc; } @@ -1128,15 +1123,10 @@ CTSimApp::newPlotDoc() TextFileDocument* CTSimApp::newTextDoc() { - wxString strFilename (getUntitledFilename()); - strFilename += wxString(".txt", *wxConvCurrent); - - TextFileDocument* newDoc = dynamic_cast(m_pDocTemplText->CreateDocument (_T(""))); - if (newDoc) { - newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName()); - newDoc->SetDocumentTemplate (m_pDocTemplText); - newDoc->OnNewDocument(); - } + TextFileDocument* newDoc = dynamic_cast + (newDocumentHelper(m_pDocTemplText)); + if (newDoc) + newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName()); return newDoc; } @@ -1145,12 +1135,10 @@ CTSimApp::newTextDoc() PhantomFileDocument* CTSimApp::newPhantomDoc() { - PhantomFileDocument* newDoc = dynamic_cast(m_pDocTemplPhantom->CreateDocument (_T(""))); - if (newDoc) { - newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName()); - newDoc->SetDocumentTemplate (m_pDocTemplPhantom); - newDoc->OnNewDocument(); - } + PhantomFileDocument* newDoc = dynamic_cast + (newDocumentHelper(m_pDocTemplPhantom)); + if (newDoc) + newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName()); return newDoc; } @@ -1160,13 +1148,12 @@ CTSimApp::newPhantomDoc() Graph3dFileDocument* CTSimApp::newGraph3dDoc() { - Graph3dFileDocument* newDoc = dynamic_cast(m_pDocTemplGraph3d->CreateDocument (_T(""))); - if (newDoc) { - newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName()); - newDoc->SetDocumentTemplate (m_pDocTemplGraph3d); - newDoc->OnNewDocument(); - } + Graph3dFileDocument* newDoc = dynamic_cast + (newDocumentHelper(m_pDocTemplGraph3d)); + if (newDoc) + newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName()); return newDoc; } + #endif