From fc399c5aab38ad24ea5d57552701411b4d805181 Mon Sep 17 00:00:00 2001 From: guigues Date: Fri, 21 Mar 2008 14:59:39 +0000 Subject: [PATCH] *** empty log message *** --- kernel/src/bbtkException.h | 14 +- kernel/src/bbtkInterpreter.cxx | 235 +++++++++++++-------- kernel/src/bbtkInterpreter.h | 36 +++- kernel/src/bbtkWxGUIHtmlBrowser.cxx | 32 ++- kernel/src/bbtkWxGUIHtmlBrowser.h | 17 +- kernel/src/bbtkWxGUIScriptingInterface.cxx | 170 +++++++-------- kernel/src/bbtkWxGUIScriptingInterface.h | 23 +- kernel/src/bbtkWxGUITextEditor.cxx | 61 ++---- kernel/src/bbtkWxGUITextEditor.h | 74 ++++++- 9 files changed, 402 insertions(+), 260 deletions(-) diff --git a/kernel/src/bbtkException.h b/kernel/src/bbtkException.h index 9c5c6ae..96e04a7 100644 --- a/kernel/src/bbtkException.h +++ b/kernel/src/bbtkException.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkException.h,v $ Language: C++ - Date: $Date: 2008/01/22 15:02:00 $ - Version: $Revision: 1.1 $ + Date: $Date: 2008/03/21 14:59:39 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -46,10 +46,10 @@ namespace bbtk { public: Exception(const std::string& object, - const std::string& file, + const std::string& source_file, const std::string& message) throw() : mObject(object), - mFile(file), + mSourceFile(source_file), mMessage(message) {} ~Exception() throw() {} @@ -59,15 +59,15 @@ namespace bbtk int lev = bbtk::MessageManager::GetMessageLevel("Error"); if (lev > 0) { std::cerr << "* OBJECT : " <(mFile.back()); + if (fs!=0) in_script = true; + file = mFileName.back(); + line = mLine.back(); + } + throw InterpreterError(e,in_script,file,line); + } + else + { + std::stringstream mess; + mess << "* ERROR : "<(mFile.back()); + if (fs!=0) in_script = true; + file = mFileName.back(); + line = mLine.back(); + } + throw InterpreterError(e.what(),in_script,file,line); + } + else + { + std::stringstream mess; + mess << "* ERROR : "<(mFile.back()); + if (fs!=0) in_script = true; + file = mFileName.back(); + line = mLine.back(); + } + throw InterpreterError("Unknown exception caught", + in_script,file,line); + } + else + { + std::stringstream mess; + mess << "* UNDEFINED ERROR (not a bbtk nor a std exception)" + << std::endl; + if (mFileName.size()) { + mess << "* FILE : \""<LoadPage( e.GetLinkInfo().GetHref() ); + { + std::cout << "BrOnLink"<GetValue()); + file += std2wx(ConfigurationFile::GetInstance().Get_file_separator()); + file += e.GetLinkInfo().GetHref(); + go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) ); + } + if (go) + { + mwxHtmlWindow->LoadPage( e.GetLinkInfo().GetHref() ); UpdateURL(); - mwxHtmlWindow->LoadPage( mwxURL->GetValue() ); - } + } + // mwxHtmlWindow->LoadPage( mwxURL->GetValue() ); + } //======================================================================== diff --git a/kernel/src/bbtkWxGUIHtmlBrowser.h b/kernel/src/bbtkWxGUIHtmlBrowser.h index 885dad0..bf8b99c 100644 --- a/kernel/src/bbtkWxGUIHtmlBrowser.h +++ b/kernel/src/bbtkWxGUIHtmlBrowser.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkWxGUIHtmlBrowser.h,v $ Language: C++ - Date: $Date: 2008/03/20 09:51:29 $ - Version: $Revision: 1.1 $ + Date: $Date: 2008/03/21 14:59:39 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -65,15 +65,18 @@ namespace bbtk }; - /* + /// Abstract class which defines the callbacks invoked by WxGUIHtmlBrowser class WxGUIHtmlBrowserUser { public : WxGUIHtmlBrowserUser() {} ~WxGUIHtmlBrowserUser() {} + + virtual bool WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target) + { return true; } }; - */ + // class WxGUIConsole; @@ -82,8 +85,8 @@ namespace bbtk class WxGUIHtmlBrowser : public wxPanel { public: - WxGUIHtmlBrowser ( wxWindow *parent, wxSize size ); - // WxGUIHtmlBrowserUser* = 0 ); + WxGUIHtmlBrowser ( wxWindow *parent, wxSize size, + WxGUIHtmlBrowserUser* = 0 ); bool GoTo(std::string&); void GoHome(); @@ -111,7 +114,7 @@ namespace bbtk wxButton* mwxReloadButton; // wxButton* mwxRunButton; - // WxGUIHtmlBrowserUser* mUser; + WxGUIHtmlBrowserUser* mUser; // any class wishing to process wxWidgets events must use this macro DECLARE_EVENT_TABLE() diff --git a/kernel/src/bbtkWxGUIScriptingInterface.cxx b/kernel/src/bbtkWxGUIScriptingInterface.cxx index 9952d89..8654ed2 100644 --- a/kernel/src/bbtkWxGUIScriptingInterface.cxx +++ b/kernel/src/bbtkWxGUIScriptingInterface.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $ Language: C++ - Date: $Date: 2008/03/21 11:46:41 $ - Version: $Revision: 1.1 $ + Date: $Date: 2008/03/21 14:59:39 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -95,101 +95,61 @@ namespace bbtk CreateStatusBar(); SetStatusText( _T("Welcome to bbi !") ); - - /* - m_mgr.AddPane(CreateSizeReportCtrl(), wxAuiPaneInfo(). - Name(wxT("test4")).Caption(wxT("Pane Caption")). - Left()); - */ - - //============== - // Notebook - - // wxFlexGridSizer *sizer = new wxFlexGridSizer(1); - -//EED wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); -// mwxNotebook = new wxNotebook(this,-1,wxDefaultPosition, wxDefaultSize, 0); -/* - mwxNotebook = new wxAuiNotebook(this, - -1, - wxPoint(0, 0), - wxSize(500,500), - wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER); - - mwxPageCommand = new wxPanel(mwxNotebook,-1); - mwxPageHelp = new wxPanel(mwxNotebook,-1); - - - wxBoxSizer *cmdsizer = new wxBoxSizer(wxVERTICAL); - - mwxPageCommand->SetAutoLayout(true); - mwxPageCommand->SetSizer(cmdsizer); - cmdsizer->Fit(mwxPageCommand); - cmdsizer->SetSizeHints(mwxPageCommand); - - wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL); - - mwxPageHelp->SetAutoLayout(true); - mwxPageHelp->SetSizer(helpsizer); - helpsizer->Fit(mwxPageHelp); - helpsizer->SetSizeHints(mwxPageHelp); -*/ - mWxGUITextEditor = new WxGUITextEditor(this); + // + mWxGUITextEditor = new WxGUITextEditor(this,this); mWxGUITextEditor->SetFileNameFilter("*.bbs"); - mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this, //mwxPageHelp, - //EED wxSize(1200,0)); - wxSize(200,0)); - - // mWxGUIHtmlBrowser->SetSize(wxSize(800,1000)); - // helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5 ); - // helpsizer->Add ( new wxButton(mwxPageHelp,-1,"perro"), 0, wxEXPAND ); - - wxBitmap bmp_run(cc_run_xpm); - mwxButtonRun = new wxBitmapButton( this, ID_Button_Run,bmp_run);//_T("Run") ); - // helpsizer->Add( mwxButtonRun, 0, wxALL, 5 ); + mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this); + /* + wxBitmap bmp_run(cc_run_xpm); + mwxButtonRun = new wxBitmapButton( this, ID_Button_Run,bmp_run);//_T("Run") ); + */ - //============== - // Command page mWxGUIOutputMessages = new WxGUIOutputMessages(this); mWxGUICommand = new WxGUICommand(this,this); - // mWxGUICommand->SetFocus(); - - // cmdsizer->Add (mWxGUIOutputMessages, 1, wxALL | wxGROW, 5); - // cmdsizer->Add (mWxGUICommand, 0, wxALL | wxGROW, 5); + mWxGUICommand->SetFocus(); - // Creates and sets the parent window of all bbtk windows wxWindow* top = new wxPanel(this,-1);//,_T("top")); top->Hide(); Wx::SetTopWindow(top); - // Layout -//EED SetSizer(sizer); -/* - mwxNotebook->AddPage( mwxPageCommand, _T("Command")); - mwxNotebook->AddPage( mwxPageHelp, _T("Help")); -*/ - + // m_mgr.AddPane(mWxGUITextEditor, wxAuiPaneInfo().Name(wxT("editor_content")) - .Top()); + .Caption(wxT("Files")) + .MinimizeButton(true) + .MaximizeButton(true) + .Center() + ); + m_mgr.AddPane(mWxGUIHtmlBrowser, + wxAuiPaneInfo().Name(wxT("browser_content")) + .Caption(wxT("Help")) + .MinimizeButton(true) + .MaximizeButton(true) + .Right() + ); m_mgr.AddPane(mWxGUIOutputMessages, wxAuiPaneInfo().Name(wxT("messages_content")) .Caption(wxT("Messages")) - .Center()); - m_mgr.AddPane(mWxGUIHtmlBrowser, - wxAuiPaneInfo().Name(wxT("browser_content")) - .Right()); + .MinimizeButton(true) + .MaximizeButton(true) + .Bottom() + ); m_mgr.AddPane(mWxGUICommand, wxAuiPaneInfo().Name(wxT("command_content")) - .Bottom()); - m_mgr.AddPane(mwxButtonRun, - wxAuiPaneInfo().Name(wxT("button_run_content"))); + .Caption(wxT("Command")) + .MinimizeButton(true) + .MaximizeButton(true) + .Bottom() + .Position(1) +); + // m_mgr.AddPane(mwxButtonRun, + // wxAuiPaneInfo().Name(wxT("button_run_content"))); //.PaneBorder(false)); @@ -224,7 +184,7 @@ namespace bbtk mWxGUIOutputMessages->Print(s,wxRED); if ( mInterpreter->InterpretLine( command ) == - Interpreter::QUIT ) + Interpreter::Interpreter_QUIT ) { Close(true); } @@ -236,7 +196,7 @@ namespace bbtk bool WxGUIScriptingInterface::InterpretFile( const std::string& filename) { if ( mInterpreter->InterpretFile(filename) == - Interpreter::ERROR ) + Interpreter::Interpreter_ERROR ) { return false; } @@ -245,13 +205,36 @@ namespace bbtk //================================================================ //================================================================ - void WxGUIScriptingInterface::OnButtonRun(wxCommandEvent& WXUNUSED(event)) + void WxGUIScriptingInterface::WxGUITextEditorRun() { - wxString per = m_mgr.SavePerspective(); - std::cout << per<< std::endl; + // wxString per = m_mgr.SavePerspective(); + // std::cout << per<< std::endl; + + // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage(); + std::stringstream* buf = new std::stringstream; + (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText(); -// wxString temp = mWxGUIHtmlBrowser->GetCurrentPage(); - std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();//wx2std(temp); + mInterpreter->SetThrow(true); + try + { + mInterpreter->InterpretBuffer(buf); + } + catch (InterpreterError e) + { + std::cerr << "* IERROR : "< 0) { + std::cerr << "* Exception thrown : "<GetCurrentPage(); + std::string filename = mWxGUITextEditor->GetCurrentPage();//wx2std(temp); size_t s = filename.length(); Interpreter* I = new Interpreter; @@ -272,6 +255,7 @@ namespace bbtk } delete I; + */ } //================================================================ @@ -390,7 +374,7 @@ printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 06 \n"); if (mWxGUIHtmlBrowser->GoTo(s)) { //EED mwxNotebook->ChangeSelection(1); - mwxNotebook->SetSelection(1); +// mwxNotebook->SetSelection(1); } else { @@ -399,7 +383,23 @@ printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 06 \n"); } //================================================================ - + //================================================================ + bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target) + { + std::cout << "OnLink"<3) && (target[s-1]=='s') + && (target[s-2]=='b') + && (target[s-3]=='b') + && (target[s-4]=='.')) + { + mWxGUITextEditor->Open(target); + return false; + } + return true; + } + //================================================================ + //================================================================ BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame) EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit) @@ -409,7 +409,7 @@ printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 06 \n"); EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox) EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph) EVT_MENU(ID_Menu_CreateIndex, WxGUIScriptingInterface::OnMenuCreateIndex) - EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun ) + // EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun ) END_EVENT_TABLE() //================================================================ diff --git a/kernel/src/bbtkWxGUIScriptingInterface.h b/kernel/src/bbtkWxGUIScriptingInterface.h index 251961f..2f3327c 100644 --- a/kernel/src/bbtkWxGUIScriptingInterface.h +++ b/kernel/src/bbtkWxGUIScriptingInterface.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkWxGUIScriptingInterface.h,v $ Language: C++ - Date: $Date: 2008/03/21 11:46:41 $ - Version: $Revision: 1.1 $ + Date: $Date: 2008/03/21 14:59:39 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -54,8 +54,10 @@ namespace bbtk /// A scripting interface window class BBTK_EXPORT WxGUIScriptingInterface : public wxFrame, - public InterpreterUser, - public WxGUICommandUser + public InterpreterUser, + public WxGUICommandUser, + public WxGUITextEditorUser, + public WxGUIHtmlBrowserUser { public: WxGUIScriptingInterface( wxWindow *parent, wxString title, wxSize size); @@ -96,7 +98,7 @@ namespace bbtk void OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event)); - void OnButtonRun(wxCommandEvent& WXUNUSED(event)); + // void OnButtonRun(wxCommandEvent& WXUNUSED(event)); // Interpreter callbacks bool InterpreterUserHasOwnHtmlPageViewer() { return true; } @@ -105,21 +107,26 @@ namespace bbtk // WxGUICommand callbacks void WxGUICommandEnter(const std::string&); + // WxGUITextEditor callbacks + void WxGUITextEditorRun(); + + // WxGUIHtmlBrowser callbacks + bool WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target); private: wxAuiManager m_mgr; Interpreter* mInterpreter; //EED wxNotebook* mwxNotebook; - wxAuiNotebook* mwxNotebook; - wxPanel *mwxPageCommand, *mwxPageHelp; +// wxAuiNotebook* mwxNotebook; +// wxPanel *mwxPageCommand, *mwxPageHelp; WxGUICommand* mWxGUICommand; WxGUIOutputMessages* mWxGUIOutputMessages; WxGUIHtmlBrowser* mWxGUIHtmlBrowser; WxGUITextEditor* mWxGUITextEditor; - wxButton* mwxButtonRun; + // wxButton* mwxButtonRun; public: diff --git a/kernel/src/bbtkWxGUITextEditor.cxx b/kernel/src/bbtkWxGUITextEditor.cxx index 7de7106..e2f7fe4 100644 --- a/kernel/src/bbtkWxGUITextEditor.cxx +++ b/kernel/src/bbtkWxGUITextEditor.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkWxGUITextEditor.cxx,v $ Language: C++ - Date: $Date: 2008/03/21 11:46:41 $ - Version: $Revision: 1.1 $ + Date: $Date: 2008/03/21 14:59:39 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -96,42 +96,6 @@ namespace bbtk //================================================================ - //================================================================ - class WxGUITextEditorPage : public wxPanel - { - public: - WxGUITextEditorPage(wxWindow* parent, WxGUITextEditor* editor); - ~WxGUITextEditorPage(); - - void SetPageName(const std::string& name) { mName = name; } - const std::string& GetPageName() const { return mName; } - - bool AskFilename() const { return mAskFilename; } - - WxTextCtrlGettingKeyEvents* GetTextCtrl() { return mwxInputText; } - - void Load(const std::string& filename); - void Save(const std::string& filter); - - bool IsModified() { return mwxInputText->IsModified(); } - - private: - WxGUITextEditor* mEditor; - WxTextCtrlGettingKeyEvents* mwxInputText; - wxTextAttr* mwxInputTextAttr; - std::string mName; - bool mAskFilename; - - /* - enum - { - ID_InputText - }; - */ - //DECLARE_EVENT_TABLE(); - - } ; - //================================================================ //================================================================ /* BEGIN_EVENT_TABLE(WxGUITextEditorPage, wxPanel) @@ -185,6 +149,13 @@ namespace bbtk } //================================================================ + bool WxGUITextEditorPage::IsModified() + { return mwxInputText->IsModified(); } + + std::string WxGUITextEditorPage::GetText() + { + return wx2std(GetTextCtrl()->GetValue()); + } //================================================================ void WxGUITextEditorPage::Load(const std::string& filename) @@ -228,8 +199,10 @@ namespace bbtk //================================================================ //================================================================ - WxGUITextEditor::WxGUITextEditor( wxWindow *parent ) + WxGUITextEditor::WxGUITextEditor( wxWindow *parent, + WxGUITextEditorUser* user ) : wxPanel(parent, -1), + mUser(user), mFileNameFilter("*.*") { std::cout << "WxGUITextEditor::WxGUITextEditor"<Add( mwxButtonSave ); - /* wxBitmap bmp_run(cc_run_xpm); mwxButtonRun = new wxBitmapButton( btnsCtrlPanel,ID_ButtonRun,bmp_run);//_T("Run") ); btnsSizer->Add( mwxButtonRun ); + /* wxBitmap bmp_quit(cc_exit_xpm); mwxButtonQuit = new wxBitmapButton( btnsCtrlPanel,ID_ButtonQuit,bmp_quit);//_T("Quit") ); btnsSizer->Add( mwxButtonQuit ); @@ -435,14 +408,16 @@ namespace bbtk if (AskSave()) GetParent()->Close(); } //================================================================ - + */ //================================================================ void WxGUITextEditor::OnButtonRun(wxCommandEvent& event) { - Run(); + if (mUser!=0) mUser->WxGUITextEditorRun(); FocusOnCurrentPage(); } + + /* void WxGUITextEditor::Run() { std::cout << "-------------- RUN ---------------"<IsModified(); } + + std::string GetText(); + + private: + WxGUITextEditor* mEditor; + WxTextCtrlGettingKeyEvents* mwxInputText; + wxTextAttr* mwxInputTextAttr; + std::string mName; + bool mAskFilename; + + /* + enum + { + ID_InputText + }; + */ + //DECLARE_EVENT_TABLE(); + + } ; + //================================================================ + + + + /// A text editor panel class BBTK_EXPORT WxGUITextEditor : public wxPanel { public: - WxGUITextEditor( wxWindow *parent ); + WxGUITextEditor( wxWindow *parent, WxGUITextEditorUser* user = 0 ); ~WxGUITextEditor(); void OnKeyDown(wxKeyEvent& event); @@ -64,7 +116,7 @@ namespace bbtk void OnButtonNew(wxCommandEvent& event); void OnButtonOpen(wxCommandEvent& event); void OnButtonSave(wxCommandEvent& event); - // void OnButtonRun(wxCommandEvent& event); + void OnButtonRun(wxCommandEvent& event); // void OnButtonQuit(wxCommandEvent& event); void OnPageClose(wxAuiNotebookEvent& evt); @@ -72,7 +124,7 @@ namespace bbtk void Open(); void Open(const std::string& filename); void Save(); - // void Run(); + // void Run(); // void Quit(); void HighlightSyntax(); @@ -86,6 +138,8 @@ namespace bbtk { mFileNameFilter = filter; } private: + WxGUITextEditorUser* mUser; + wxAuiManager m_mgr; wxAuiNotebook* mwxNotebook; @@ -95,7 +149,7 @@ namespace bbtk wxButton * mwxButtonNew; wxButton * mwxButtonOpen; wxButton * mwxButtonSave; - // wxButton * mwxButtonRun; + wxButton * mwxButtonRun; // wxButton * mwxButtonQuit; wxStaticText* mwxPosition; @@ -107,8 +161,8 @@ namespace bbtk { ID_ButtonNew, ID_ButtonOpen, - ID_ButtonSave - // ID_ButtonRun, + ID_ButtonSave, + ID_ButtonRun // ID_ButtonQuit }; -- 2.45.1