From f3d05516965aece323133928f72d85e38c2b0b71 Mon Sep 17 00:00:00 2001 From: guigues Date: Mon, 15 Dec 2008 09:04:46 +0000 Subject: [PATCH] *** empty log message *** --- kernel/src/bbtkBlackBoxOutputConnector.h | 8 +- kernel/src/bbtkInterpreter.cxx | 290 ++++++++++++--------- kernel/src/bbtkInterpreter.h | 89 +++++-- kernel/src/bbtkWxGUIScriptingInterface.cxx | 91 +++++-- kernel/src/bbtkWxGUIScriptingInterface.h | 7 +- packages/demo/bbs/appli/demoFiltering1.bbs | 58 +++-- packages/wxvtk/bbs/appli/wxvtkTour.bbs | 65 +++++ 7 files changed, 412 insertions(+), 196 deletions(-) create mode 100644 packages/wxvtk/bbs/appli/wxvtkTour.bbs diff --git a/kernel/src/bbtkBlackBoxOutputConnector.h b/kernel/src/bbtkBlackBoxOutputConnector.h index 58d1c21..80559c2 100644 --- a/kernel/src/bbtkBlackBoxOutputConnector.h +++ b/kernel/src/bbtkBlackBoxOutputConnector.h @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbtkBlackBoxOutputConnector.h,v $ Language: C++ - Date: $Date: 2008/12/10 09:33:18 $ - Version: $Revision: 1.7 $ + Date: $Date: 2008/12/15 09:04:46 $ + Version: $Revision: 1.8 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -127,11 +127,9 @@ namespace bbtk ConnectionVector mConnection; /// The status of the output IOStatus mStatus; - + /// The output changed signal BlackBox::OutputChangeSignalType mChangeSignal; - // The change time -// ChangeTime mChangeTime; }; } diff --git a/kernel/src/bbtkInterpreter.cxx b/kernel/src/bbtkInterpreter.cxx index 7356fd2..0bb7894 100644 --- a/kernel/src/bbtkInterpreter.cxx +++ b/kernel/src/bbtkInterpreter.cxx @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbtkInterpreter.cxx,v $ Language: C++ - Date: $Date: 2008/12/12 12:56:28 $ - Version: $Revision: 1.80 $ + Date: $Date: 2008/12/15 09:04:47 $ + Version: $Revision: 1.81 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -142,6 +142,14 @@ namespace bbtk info.help = "Clears the currently defined complex box (deletes all its boxes and connections)"; mCommandDict[info.keyword] = info; + info.keyword = "break"; + info.argmin = 0; + info.argmax = 0; + info.code = cBreak; + info.syntax = "break"; + info.help = "Breaks the current execution"; + mCommandDict[info.keyword] = info; + info.keyword = "newgui"; info.argmin = 2; info.argmax = 2; @@ -382,7 +390,8 @@ namespace bbtk //======================================================================= - InterpreterError::InterpreterError( const std::string& message, + //======================================================================= + InterpreterException::InterpreterException( const std::string& message, bool in_script_file, const std::string& script_file, int script_line @@ -393,7 +402,9 @@ namespace bbtk mScriptLine(script_line) { } - InterpreterError::InterpreterError( const Exception& excep, + //======================================================================= + //======================================================================= + InterpreterException::InterpreterException( const Exception& excep, bool in_script_file, const std::string& script_file, int script_line @@ -405,12 +416,19 @@ namespace bbtk { } //======================================================================= - void Interpreter::CatchInterpreterException( const InterpreterError& e ) + + + //======================================================================= + void Interpreter::CatchInterpreterException( const InterpreterException& e ) { if (mThrow) { - CloseAllFiles(); - throw InterpreterError(e); + if (e.GetErrorMessage()!="break") + { + mStatus = Interpreter_ERROR; + CloseAllFiles(); + } + throw InterpreterException(e); } else { @@ -421,6 +439,7 @@ namespace bbtk mess << "* FILE : \""<0) - { - while (!mFile.back()->eof()) { - mLine.back()++; - char buf[500]; - mFile.back()->getline(buf,500); - std::string str(buf); - int size=str.length(); - if ( str[ size-1 ]==13 ) - { - str.erase(size-1,1); - } - try - { - InterpretLine(str, insideComment); - } - CATCH_MACRO; - - }//while !eof - CloseCurrentFile(); - }//while >0 - } // try + mInsideComment = false; + InterpretCurrentStreams(); + } CATCH_MACRO; - CloseAllFiles(); - bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretFile(\""<0) + mInsideComment = false; + InterpretCurrentStreams(); + } + CATCH_MACRO; + + // CloseAllFiles(); + bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretBuffer()"<0) { while (!mFile.back()->eof()) { mLine.back()++; @@ -635,21 +644,13 @@ namespace bbtk } try { - InterpretLine(str, insideComment); + DoInterpretLine(str); } CATCH_MACRO; - }//while + } CloseCurrentFile(); } - } - CATCH_MACRO; - - CloseAllFiles(); - bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretBuffer()"< words; SplitLine(line,words); @@ -709,7 +707,7 @@ void Interpreter::InterpretLine( const std::string& line, bool &insideComment ) { bbtkDebugDecTab("Interpreter",9); bbtkMessage("Interpreter",9,"In multiline comment"<SetMessageLevel(words[1],level); } + return; } else { bbtkMessage("echo",2,line<(mFile.back()); + if (fs!=0) in_script = true; + file = mFileName.back(); + line = mLine.back(); + } + if (command.code==cBreak) + { + /* + std::cout << "BreakException(" + <Create(words[1],words[2]); break; @@ -892,8 +923,8 @@ void Interpreter::InterpretLine( const std::string& line, bool &insideComment ) case cReset : Reset(); break; - - case cClear : + + case cClear : mVirtualExecuter->Clear(); break; @@ -918,10 +949,6 @@ void Interpreter::InterpretLine( const std::string& line, bool &insideComment ) GetExecuter()->UnLoadPackage(words[1]); break; - case cQuit : - throw QuitException(); - break; - case cDebug : if (words.size()==2) Debug(words[1]); else Debug(""); @@ -952,10 +979,7 @@ void Interpreter::InterpretLine( const std::string& line, bool &insideComment ) //======================================================================= - /** - * - */ -void Interpreter::SplitLine ( const std::string& str, std::vector& tokens) + void Interpreter::SplitLine ( const std::string& str, std::vector& tokens) { bbtkDebugMessageInc("Interpreter",9,"Interpreter::SplitLine(\""<& void Interpreter::Reset() { // Cannot close all files if the reset command is read from a file ! - // CloseAllFiles(); + CloseAllFiles(); mFileNameHistory.clear(); this->mVirtualExecuter->Reset(); } @@ -1416,11 +1440,9 @@ void Interpreter::SwitchToStream( std::stringstream* stream ) return; } + //======================================================================= //======================================================================= - /** - * - */ void Interpreter::CloseCurrentFile() { bbtkDebugMessage("Interpreter",9,"Interpreter::CloseCurrentFile()" @@ -1452,9 +1474,6 @@ void Interpreter::SwitchToStream( std::stringstream* stream ) //======================================================================= //======================================================================= - /** - * - */ void Interpreter::CloseAllFiles() { bbtkDebugMessage("Interpreter",9,"Interpreter::CloseAllFiles()" @@ -1472,9 +1491,6 @@ void Interpreter::SwitchToStream( std::stringstream* stream ) //======================================================================= - /** - * - */ void Interpreter::InterpretCommand( const std::vector& words, CommandInfoType& info ) { @@ -1905,20 +1921,23 @@ void Interpreter::Help(const std::vector& words) mCommandLine = true; bool again = true; - bool insideComment = false; // for multiline comment + // bool insideComment = false; // for multiline comment + mInsideComment = false; do { try { std::string line; GetLineFromPrompt(line); - InterpretLine(line, insideComment); + DoInterpretLine(line); //, insideComment); } + /* catch (QuitException e) { bbtkMessage("Interpreter",1,"Interpreter : Quit"< #include +// Signal/slot mechanism for 'break' commands +//#include +//#include + namespace bbtk { @@ -70,20 +74,20 @@ namespace bbtk //======================================================================= - class BBTK_EXPORT InterpreterError : public Exception + class BBTK_EXPORT InterpreterException : public Exception { public: - InterpreterError( const std::string& message, + InterpreterException( const std::string& message, bool in_script_file, const std::string& script_file, int script_line ); - InterpreterError( const Exception& excep, + InterpreterException( const Exception& excep, bool in_script_file, const std::string& script_file, int script_line ); - ~InterpreterError() throw() {} + ~InterpreterException() throw() {} bool IsInScriptFile() const { return mInScriptFile; } const std::string& GetScriptFile() const { return mScriptFile; } @@ -95,6 +99,37 @@ namespace bbtk }; //======================================================================= + /* + //======================================================================= + // The "Quit" exception + class BBTK_EXPORT QuitException : public InterpreterError + { + public: + QuitException( bool in_script_file, + const std::string& script_file, + int script_line + ) + : InterpreterError("QUIT",in_script_file,script_file,script_line) + {} + ~QuitException() throw() {} + }; + //======================================================================= + const std::string BREAK("BREAK"); + //======================================================================= + // The "Break" exception + class BBTK_EXPORT BreakException : public InterpreterError + { + public: + BreakException( bool in_script_file, + std::string script_file, + int script_line + ) + : InterpreterError(BREAK,in_script_file,script_file,script_line) + { std::cout << "BUILDING BREAK"< BreakSignalType; + typedef BreakSignalType::slot_function_type BreakCallbackType; + + // Adds a callback when 'break' command issued + void AddBreakObserver( BreakCallbackType ); + */ protected: /// The enumeration of command codes == Command name typedef enum { - cClear, + cBreak, // LG 12/12/08 : Stops the current script execution (if not exec frozen) - used in tutorial + debugging + cClear, // LG 12/12/08 : Clears the current complex black box (e.g. workspace) - used in tours cNew, cDelete, cConnect, @@ -217,7 +265,7 @@ namespace bbtk /// Interprets a line - void InterpretLine( const std::string& line, bool &insideComment ); + void DoInterpretLine( const std::string& line ); //, bool &insideComment ); /// Reads a line from prompt void GetLineFromPrompt( std::string& line ); @@ -279,6 +327,7 @@ namespace bbtk void Debug(const std::string& arg); + private: /// Constructor @@ -294,7 +343,7 @@ namespace bbtk std::string includeScriptName); /// - void CatchInterpreterException( const InterpreterError& e ); + void CatchInterpreterException( const InterpreterException& e ); void CatchBbtkException( const bbtk::Exception& e ); void CatchStdException( const std::exception& e ); void CatchUnknownException(); @@ -334,25 +383,29 @@ namespace bbtk /// Are we in a command line context ? bool mCommandLine; + /// Are we inside a commented-out zone ? + bool mInsideComment; + + /// The current interpreter status + ExitStatus mStatus; + /// The history of commands std::deque< char* > mHistory; - int bufferNb; + int bufferNb; bool mThrow; - protected: - ~Interpreter(); + /// The break signal + // BreakSignalType mBreakSignal; + + protected: + ~Interpreter(); }; // EO class Interpreter - // The "Quit" exception - struct QuitException : public bbtk::Exception - { - QuitException() : bbtk::Exception("Interpreter","","Quit") {} - }; } #endif diff --git a/kernel/src/bbtkWxGUIScriptingInterface.cxx b/kernel/src/bbtkWxGUIScriptingInterface.cxx index 245e1f2..966c1f7 100644 --- a/kernel/src/bbtkWxGUIScriptingInterface.cxx +++ b/kernel/src/bbtkWxGUIScriptingInterface.cxx @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $ Language: C++ - Date: $Date: 2008/10/21 14:38:31 $ - Version: $Revision: 1.31 $ + Date: $Date: 2008/12/15 09:04:47 $ + Version: $Revision: 1.32 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -95,7 +95,8 @@ namespace bbtk mInterpreter->SetUser(this); mInterpreter->SetCommandLine(true); mInterpreter->SetThrow(true); - + // mInterpreter->AddBreakObserver + //boost::bind( &WxGUIScriptingInterface::InterpreterUserOnBreak, this )); //============== // Menu wxInitAllImageHandlers(); @@ -260,7 +261,8 @@ namespace bbtk m_mgr.Update(); // LoadPerspective(); - + mBreaked = false; + wxTipWindow* tip = new wxTipWindow(this, _T("\n Welcome to bbStudio !\n\n To run a demo or example:\n 1. click on the 'Demos' or 'Examples' link\n 2. select a demo or example\n 3. click on the '[source]' link : the source file is loaded in bbStudio\n 4. click on the 'Run' button (the arrow at the bottom right of the source file) \n"),1000); tip->CenterOnParent(); @@ -282,24 +284,54 @@ namespace bbtk mWxGUITextEditor->Open(filename); } //================================================================ - -#define CATCH_MACRO \ - catch (QuitException e) \ + /* + catch (BreakException e) \ { \ - std::cout << "* quit exception caught"< 0) { \ - std::cerr << "* Exception thrown : "< 0) { \ + std::cerr << "* Exception thrown : "<GetCurrentPage()->GetText(); try { - // std::cout << "RUN"<IsChecked()) WxGUICommandEnter("reset"); - mInterpreter->InterpretBuffer(buf); + if (!mBreaked) + { + if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset"); + mInterpreter->InterpretBuffer(buf); + } + else + { + mBreaked = false; + mInterpreter->InterpretCurrentStreams(); + } // std::cout << "EO RUN"<