bbStudio.cxx

Go to the documentation of this file.
00001 #ifdef _USE_WXWIDGETS_
00002 
00003 //==========================================================================
00004 // WITH WX
00005 //==========================================================================
00006 #include "bbtkWxGUIScriptingInterface.h"
00007 
00008 #include <wx/cmdline.h> 
00009 #include <vector>
00010 
00011 
00012 static const wxCmdLineEntryDesc cmdLineDesc[] =
00013 {
00014   { wxCMD_LINE_PARAM,  NULL, NULL, _T("file1 [file2 [...]]"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, 
00015   { wxCMD_LINE_SWITCH, _T("h"), _T("help"),   _T("Prints this help") },
00016   { wxCMD_LINE_SWITCH, _T("d"), _T("debug"),   _T("Message all 9") },
00017   { wxCMD_LINE_NONE }
00018 };
00019 
00020 
00021 
00022 class wxBBIApp : public wxApp
00023 {
00024 public:
00025   bool OnInit( );
00026   int  OnExit() { return true; }
00027   void OnInitCmdLine(wxCmdLineParser& parser);
00028   bool OnCmdLineParsed(wxCmdLineParser& parser);
00029 
00030   bool usage;
00031   std::vector<std::string> input_file;
00032 };
00033 
00034 IMPLEMENT_APP(wxBBIApp);
00035 
00036 void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
00037 {
00038   //    std::cout << "OnInitCmdLine"<<std::endl;
00039   parser.SetDesc(cmdLineDesc);
00040 }
00041 
00042 bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
00043 {
00044   int argc = parser.GetParamCount();
00045   for (int i=0; i<argc; ++i) 
00046     {
00047       std::string s = bbtk::wx2std(parser.GetParam(i));
00048       input_file.push_back(s);
00049     }
00050 
00051   bool help = ( parser.Found(_T("h")) );
00052   usage = (help && (input_file.size()==0));
00053   if (usage) {
00054     std::cout << "bbStudio (The Black Box Development Studio) - bbtk "
00055               << bbtk::GetVersion() << " - (c) Creatis 2007-2008"
00056               << std::endl;
00057     parser.Usage();
00058   }
00059   else 
00060   {
00061         if ( parser.Found(_T("d")) )
00062         {
00063                 bbtk::MessageManager::SetMessageLevel("all",9);
00064         }
00065   }
00066 
00067 
00068   return true;
00069 }
00070 
00071 
00072 
00073 // ----------------------------------------------------------------------------
00074 // The `main program' equivalent, creating the windows and returning the
00075 // main frame
00076 bool wxBBIApp::OnInit( )
00077 {
00078   //    std::cout << "OnInit"<<std::endl;
00079   wxApp::OnInit();
00080 #ifdef __WXGTK__
00081   //See http://www.wxwindows.org/faqgtk.htm#locale
00082   setlocale(LC_NUMERIC, "C");
00083 #endif
00084   if (usage) return false;
00085   
00086   bbtk::WxGUIScriptingInterface *I = 
00087     new bbtk::WxGUIScriptingInterface(0);
00088   SetTopWindow(I);  
00089   I->Show(true);
00090 
00091   std::vector<std::string>::const_iterator i;
00092   i=input_file.begin(); 
00093   if (i!=input_file.end()) I->Open(*i);
00094 
00095   return true;
00096 }
00097 
00098 
00099 #if defined(_WIN32) 
00100 
00101 //  How to have a Console and wxWidgets
00102 //  http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
00103 //   In Visual C++ 6 (7 should be similar), to create an application that is both a console application 
00104 //  (cout's to the console are visible) and has a wxWidgets GUI, 
00105 //  you need to use the linker option "/subsystem:console" and the following code:
00106 int main(int argc, char* argv[])
00107 {
00108         return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
00109 }
00110 
00111 #endif // defined(_WIN32) 
00112 
00113 
00114 #else
00115 //==========================================================================
00116 // WITHOUT WX
00117 //==========================================================================
00118 #include <iostream>
00119 int main(int argc, char* argv[])
00120 {  
00121   std::cout << "bbStudio was not compiled with wxWidgets : ciao !" <<std::endl;
00122   return 0;
00123 }
00124 
00125 // EOF
00126 #endif //#ifdef _USE_WXWIDGETS_
00127 
00128 
00129 

Generated on Thu May 31 14:12:02 2012 for BBTK by  doxygen 1.5.7.1