]> Creatis software - bbtk.git/commitdiff
*** empty log message ***
authorguigues <guigues>
Fri, 25 Jul 2008 11:07:34 +0000 (11:07 +0000)
committerguigues <guigues>
Fri, 25 Jul 2008 11:07:34 +0000 (11:07 +0000)
kernel/appli/bbi/bbi.cxx
kernel/cmake/BBTKPreventInSourceBuild.cmake
kernel/src/bbtkWx.cxx

index 378c1f63eda4cfbefb1c229355b0b0dc7a3c7fbb..a1984f5e38c532779ee274c60da67e68c1d90697 100644 (file)
@@ -12,7 +12,8 @@
 #include <vector>
 #include <map>
 
-
+//==========================================================================
+// Command line options definition
 static const wxCmdLineEntryDesc cmdLineDesc[] =
 {
   { wxCMD_LINE_SWITCH, _T("h"), _T("help"),   _T("print this help or help on the application defined in input bbs file if any") },
@@ -26,23 +27,16 @@ static const wxCmdLineEntryDesc cmdLineDesc[] =
   { wxCMD_LINE_PARAM,  NULL, NULL, _T("file [file [...]]"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
   { wxCMD_LINE_NONE }
 };
+//==========================================================================
 
-
-
-class wxBBIApp : public wxApp
+//==========================================================================
+// Processes the command line parsing result
+struct ProcessCmdLine
 {
-public:
-  bool OnInit( );
-  int  OnExit() { 
-    //    std::cout << "wxBBIApp::OnExit()"<<std::endl;
-    // bbtk::Object::PrintObjectListInfo();
-    return true; }
-  void OnInitCmdLine(wxCmdLineParser& parser);
-  bool OnCmdLineParsed(wxCmdLineParser& parser);
-  void Run(bbtk::Interpreter*);
+  ProcessCmdLine() {}
+  void Process(wxCmdLineParser& parser);
 
-  bbtk::Interpreter* I;
-  int argc;
+  //  int argc;
   std::vector<std::string> argv;
   bool console;
   bool debug;
@@ -51,40 +45,36 @@ public:
   bool graphical_dialog;
   bool text_dialog;
   bool no_console;
-
+  bool proceed;
   std::map<std::string,std::string> param_map;
   std::vector<std::string> input_file;
   
 };
+//==========================================================================
 
-IMPLEMENT_APP(wxBBIApp);
-
-void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
-{
-  //    std::cout << "OnInitCmdLine"<<std::endl;
-  parser.SetDesc(cmdLineDesc);
-}
-
-bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
+//==========================================================================
+void ProcessCmdLine::Process(wxCmdLineParser& parser)
 {
-
+  proceed = true;
   if (parser.Found(_T("D"))) 
     {
       bbtk::StaticInitTime::PrintObjectListInfo = true;
     }
   
-  debug = ( parser.Found(_T("d")) );
-
+  debug = ( parser.Found(_T("d")) );  
   quiet = ( parser.Found(_T("q")) );
   help = ( parser.Found(_T("h")) );
   graphical_dialog = ( parser.Found(_T("g")) );
   text_dialog = ( parser.Found(_T("t")) );
   no_console = ( parser.Found(_T("N")) );
+  
+  if (quiet) bbtk::MessageManager::SetMessageLevel("max",0);
+  if (debug) bbtk::MessageManager::SetMessageLevel("all",9);
 
   // parse the arguments and consider those which contain a "=" 
   // as set input commands, other as files
-  int argc = parser.GetParamCount();
-  for (int i=0; i<argc; ++i) 
+  int pargc = parser.GetParamCount();
+  for (int i=0; i<pargc; ++i) 
     {
       std::string s = bbtk::wx2std(parser.GetParam(i));
       std::string::size_type pos = s.find_first_of("=");
@@ -93,11 +83,9 @@ bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
          std::string left = s.substr(0,pos);
          std::string right = s.substr(pos+1,s.size());
          param_map[left]=right;
-         //      std::cout << "'"<<left << "' = '"<<right<<"'"<<std::endl;
        }
       else 
        {
-         //      std::cout << "input file = ["<<s<<"]"<<std::endl;
          input_file.push_back(s);
        }
     }
@@ -108,24 +96,57 @@ bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
              << bbtk::GetVersion() << " - (c) Creatis 2007-2008"
              << std::endl;
     parser.Usage();
+    proceed = false;
   }
 
   console = ( parser.Found(_T("c")) || 
              ((input_file.size() == 0) && 
               (!no_console) &&
               (!usage) ) );
+  
+}
+//==========================================================================
 
 
+//==========================================================================
+class wxBBIApp : public wxApp
+{
+public:
+  bool OnInit( );
+  int  OnExit() { 
+    //    std::cout << "wxBBIApp::OnExit()"<<std::endl;
+    // bbtk::Object::PrintObjectListInfo();
+    return true; }
+  void OnInitCmdLine(wxCmdLineParser& parser);
+  bool OnCmdLineParsed(wxCmdLineParser& parser);
+
+  ProcessCmdLine cmd;
+};
+//==========================================================================
+
+
+//==========================================================================
+void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
+{
+  parser.SetDesc(cmdLineDesc);
+}
+//==========================================================================
 
+//==========================================================================
+bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
+{
+  cmd.Process(parser);
+  // if (!cmd.proceed) return false;
   return true;
 }
+//==========================================================================
 
 
 
 
 
 
-// ----------------------------------------------------------------------------
+//==========================================================================
 // The `main program' equivalent, creating the windows and returning the
 // main frame
 bool wxBBIApp::OnInit( )
@@ -138,32 +159,34 @@ bool wxBBIApp::OnInit( )
 #endif
   
 
-  if (quiet) bbtk::MessageManager::SetMessageLevel("max",0);
-  if (debug) bbtk::MessageManager::SetMessageLevel("all",9);
+  if (cmd.quiet) bbtk::MessageManager::SetMessageLevel("max",0);
+  if (cmd.debug) bbtk::MessageManager::SetMessageLevel("all",9);
   
 
   bbtk::WxGUIConsole *I = new bbtk::WxGUIConsole(0,_T("bbi"),wxSize(800,600));
   SetTopWindow(I);  
-  if (console) I->Show(true);
+  if (cmd.console) I->Show(true);
 
 
-  I->SetInputs(param_map);
+  I->SetInputs(cmd.param_map);
 
-  bool help_on_script = help && (input_file.size() > 0);
-  if (help_on_script) I->SetNoExecMode(true);
-
-  if (graphical_dialog) I->SetDialogMode(bbtk::VirtualExec::GraphicalDialog);
-  if (text_dialog) I->SetDialogMode(bbtk::VirtualExec::TextDialog);
+  bool help_on_script = cmd.help && (cmd.input_file.size() > 0);
+  if (help_on_script) 
+    I->SetNoExecMode(true);
+  if (cmd.graphical_dialog) 
+    I->SetDialogMode(bbtk::VirtualExec::GraphicalDialog);
+  if (cmd.text_dialog) 
+    I->SetDialogMode(bbtk::VirtualExec::TextDialog);
 
   std::vector<std::string>::const_iterator i;
   bool error = false;
 
-  for (i=input_file.begin(); i!=input_file.end(); ++i) 
+  for (i=cmd.input_file.begin(); i!=cmd.input_file.end(); ++i) 
     {
       error = ! I->InterpretFile(*i);
       if (error) break;
     }
-  bool show_on_error = error && ! no_console;
+  bool show_on_error = error && ! cmd.no_console;
   if (show_on_error) I->Show();
 
   I->SetNoExecMode(false);
@@ -179,7 +202,7 @@ bool wxBBIApp::OnInit( )
   std::cout << "con="<<console<<std::endl;
   std::cout << "iws="<<bbtk::Wx::IsSomeWindowShown()<<std::endl;
   */
-  if (!(show_on_error || console || bbtk::Wx::IsSomeWindowShown() ))
+  if (!(show_on_error || cmd.console || bbtk::Wx::IsSomeWindowShown() ))
     {
       I->Close();
       //      std::cout << "I->Close"<<std::endl;
@@ -191,10 +214,14 @@ bool wxBBIApp::OnInit( )
   return true;
 
 }
+//==========================================================================
 
 
 #if defined(_WIN32) 
-
+//==========================================================================
+// WINDOWS
+//==========================================================================
+IMPLEMENT_APP(wxBBIApp);
 //  How to have a Console and wxWidgets
 //  http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
 //   In Visual C++ 6 (7 should be similar), to create an application that is both a console application 
@@ -202,10 +229,97 @@ bool wxBBIApp::OnInit( )
 //  you need to use the linker option "/subsystem:console" and the following code:
 int main(int argc, char* argv[])
 {
-       return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
+  return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
+}
+
+#else 
+//==========================================================================
+// OTHER ( Linux... )
+//==========================================================================
+
+IMPLEMENT_APP_NO_MAIN(wxBBIApp);
+
+
+int main(int argc, char* argv[])
+{
+  wxMessageOutput::Set( new wxMessageOutputBest );
+
+  wxCmdLineParser parser(cmdLineDesc,argc,argv);
+  int val = parser.Parse(false);
+  if (val>0) 
+    {  
+      parser.Usage();
+      return 0;
+    }
+  ProcessCmdLine cmdline;
+  cmdline.Process(parser);
+
+  if (!cmdline.proceed) return 0;
+
+  if (cmdline.no_console) 
+    {
+      //      std::cout << "main NC"<<std::endl;
+      // Interpreter 
+      bbtk::Interpreter::Pointer I = bbtk::Interpreter::New();
+      I->SetInputs(cmdline.param_map);
+      bool help_on_script = cmdline.help && (cmdline.input_file.size() > 0);
+      if (help_on_script) I->SetNoExecMode(true);
+      if (cmdline.text_dialog) I->SetDialogMode(bbtk::VirtualExec::TextDialog);
+      std::vector<std::string>::const_iterator i;
+      bool error = false;
+      for (i=cmdline.input_file.begin(); 
+          i!=cmdline.input_file.end(); ++i) 
+       {
+         error = ! I->InterpretFile(*i);
+         if (error) break;
+       }
+      if (help_on_script) 
+       {
+         I->SetNoExecMode(false);
+         std::string package; 
+         I->GetExecuter()->GetFactory()->HelpBlackBox("workspace",
+                                                      package,
+                                                      false);
+       }
+      if (cmdline.input_file.size()==0)
+       I->CommandLineInterpreter();
+
+      //
+    }
+  else 
+    {
+      //      std::cout << "main C"<<std::endl;
+      wxEntry(argc, argv);
+      /*
+      // Create wxApp
+      wxBBIApp* app = new wxBBIApp();
+      app->SetCmdLine(cmdline);
+      if (wxApp::GetInstance()!=0)
+       {
+         std::cout << "WXAPP!!!"<<std::endl;
+       }
+      //  wxApp::SetInstance(app);
+      // Start wx
+      wxInitialize();
+      std::cout << "Loop"<<std::endl;
+      app->MainLoop();
+      //bbtk::Wx::LoopUntilAllWindowsClose();
+      */
+    }
+
+  std::cout << "EO main"<<std::endl;
+
 }
 
+
 #endif // defined(_WIN32) 
+//==========================================================================
+
+
+
+
+
+
 
 
 #else
@@ -218,23 +332,30 @@ int main(int argc, char* argv[])
 int main(int argc, char* argv[])
 {  
 
-  if (argc>2) return 0;
+  if (argc>2) 
+    {
+      std::cout << "usage : "<<argv[0]<<" [filename]"<<std::endl;
+      return 0;
+    }
 
   std::cout << "BBI (Black Box Interpreter) - bbtk "
-           << bbtk::GetVersion()<< " - (c) Creatis 2007"
-           <<std::endl;
+            << bbtk::GetVersion()<< " - (c) Creatis 2007"
+            << std::endl;
 
-  bbtk::Interpreter I;
+  bbtk::Interpreter::Pointer I = bbtk::Interpreter::New();
   if (argc==1) 
     {
-      I.CommandLineInterpreter();
+      I->CommandLineInterpreter();
     }
   else 
+
     {
       std::string f(argv[1]);
-      I.InterpretFile(f);
+      I->InterpretFile(f);
     }
-    
+  
+  bbtk::Wx::LoopUntilAllWindowsClose(); 
+     
   return 0;
 
 }
index de12a492d72a5112866f5d3e82a4ecba663a6268..8126ce8985a8c3f1c4f5f8361ed9a467965df05e 100644 (file)
@@ -1,6 +1,9 @@
-#-----------------------------------------------------------------------------
-# Building in the source tree is forbidden ! 
-IF(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR})
-  MESSAGE(FATAL_ERROR "Building in the source tree is not allowed !! Quit; remove the file 'CMakeCache.txt' and the folder 'CMakeFiles' and build outside the sources")
-ENDIF(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR})
-#-----------------------------------------------------------------------------
+IF(NOT ALLOW_IN_SOURCE_BUILD)
+  #---------------------------------------------------------------------------
+  # Building in the source tree is forbidden ! 
+  # (except if ALLOW_IN_SOURCE_BUILD is set, e.g. for packaging with rpmbuild)
+  IF(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR})
+    MESSAGE(FATAL_ERROR "Building in the source tree is not allowed !! Quit; remove the file 'CMakeCache.txt' and the folder 'CMakeFiles' and build outside the sources")
+  ENDIF(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR})
+  #---------------------------------------------------------------------------
+ENDIF(NOT ALLOW_IN_SOURCE_BUILD)
index ec1327fb8c1b4f3da3f178413e24eb953fc5e8c2..46712c4869ad4bcc1bc15da6845677437b2df7ef 100644 (file)
@@ -59,6 +59,8 @@ namespace bbtk
        bbtkDebugMessage("wx",1,"  --> Creating bbtk wxApp"<<std::endl);
        mgWxApp = new WxApp;
        wxApp::SetInstance(mgWxApp);
+       //int argc = 0;
+       //wxEntry(argc,0);
        wxInitialize();
       } 
   }