NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
terminal.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2018 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19
20#ifndef TERMINAL_HPP
21#define TERMINAL_HPP
22
23#ifdef __GNUG__
24#pragma interface
25#endif
26
27#include <map>
28#include "../NumeReWindow.h"
29#include "../../common/Options.h"
30#include "gterm.hpp"
31#include "../../kernel/kernel.hpp"
32
33#define wxEVT_COMMAND_TERM_RESIZE wxEVT_USER_FIRST + 1000
34#define wxEVT_COMMAND_TERM_NEXT wxEVT_USER_FIRST + 1001
35
36#define EVT_TERM_RESIZE(id, fn) { wxEVT_COMMAND_TERM_RESIZE, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) &fn, (wxObject *)NULL },
37
38class TerminalCallTip;
39
40
45class NumeReTerminal : public wxWindow, public GenericTerminal, public wxThreadHelper
46{
47 // Easier to use the NumeReKernel as a friend
48 // to create the communication
49 friend class NumeReKernel;
50 friend class DebugViewer;
51
52 private:
53 int
70
74
76
77 unsigned char
79
80 bool
83
87
88 wxColour
90
91 wxPen
93
94 wxFont
99
100 wxDC
102
103 wxMemoryDC
105
106 wxBitmap
108
109 wxTimer
111
113
115
116 public:
118 {
120 COLOR = 0,
122 FONT = 2
123 };
124
126 {
127 if (frame && !m_wxParent)
128 m_wxParent = frame;
129 }
131 {
132 return m_charHeight;
133 }
134
135 private:
136 void pipe_command(const std::string& sCommand);
139
140 bool filterKeyCodes(int keyCode, bool ctrlDown);
141 void scrollToInput();
142 void MarkSelection(bool bRectangular = false);
143 void DoDrawCursor(int fg_color, int bg_color, int flags,
144 int x, int y, unsigned char c);
145
146 // Private event handler functions
147 void OnChar(wxKeyEvent& event);
148 void OnKeyDown(wxKeyEvent& event);
149 void OnPaint(wxPaintEvent& event);
150 void OnLeftDown(wxMouseEvent& event);
151 void OnLoseMouseCapture(wxMouseCaptureLostEvent& event);
152 void OnLeftUp(wxMouseEvent& event);
153 void OnMouseMove(wxMouseEvent& event);
154 void OnEnter(wxMouseEvent& event);
155 void OnTimer(wxTimerEvent& event);
156 void OnActivate(wxActivateEvent& event);
157 void OnSize(wxSizeEvent& event);
158 void OnGainFocus(wxFocusEvent& event);
159 void OnLoseFocus(wxFocusEvent& event);
160
161 void Busy();
162 void Ready();
163
164 protected:
165 virtual wxThread::ExitCode Entry();
167 wxCriticalSection m_kernelCS;
174 std::string m_sCommandLine;
175 std::string m_sAnswer;
176
177 public:
178 // Constructor and destructor
179 NumeReTerminal(wxWindow* parent, wxWindowID id,
180 Options* _option,
181 const wxString& sPath,
182 const wxPoint& pos = wxDefaultPosition,
183 int width = 80, int height = 24,
184 const wxString& name = "wxTerm");
185 virtual ~NumeReTerminal();
186
187 // Kernel communication functions
188 void pass_command(const std::string& command, bool isEvent);
189 NumeRe::Table getTable(const std::string& sTableName);
190 NumeRe::Container<std::string> getStringTable(const std::string& sStringTableName);
193 {
194 return _kernel;
195 }
196 void setKernelSettings(const Settings&);
197 void EndKernelTask();
198 void CancelCalculation();
199 void StartKernelTask();
200 void OnThreadUpdate(wxThreadEvent& event);
201 void OnClose(wxCloseEvent& event);
202 std::vector<std::string> getPathSettings();
203 const std::vector<Package>& getInstalledPackages();
204 std::map<std::string, std::string> getMenuMap();
205 void updatePackage(const std::string& package);
206 void passEditedTable(NumeRe::Table _table);
208 {
209 wxCriticalSectionLocker lock(m_kernelCS);
211 }
212 void addBreakpoint(const std::string& _sFilename, size_t nLine);
213 void removeBreakpoint(const std::string& _sFilename, size_t nLine);
214 void clearBreakpoints(const std::string& _sFilename);
215
217 {
218 wxCriticalSectionLocker lock(m_kernelCS);
220 }
222 {
223 wxCriticalSectionLocker lock(m_kernelCS);
225 }
227 {
228 wxCriticalSectionLocker lock(m_kernelCS);
230 }
232 {
233 wxCriticalSectionLocker lock(m_kernelCS);
235 }
236 std::string getDocumentation(const std::string& sCommand);
237 std::vector<std::string> getDocIndex();
238 std::map<std::string, std::string> getPluginLanguageStrings();
239 std::map<std::string, std::string> getFunctionLanguageStrings();
241 {
243 }
245
246 // Styling functions
247 bool SetFont(const wxFont& font);
248 void GetDefColors(wxColor colors[16], NumeReTerminal::BOLDSTYLE boldStyle = NumeReTerminal::DEFAULT);
250 {
251 return m_curBlinkRate;
252 }
253 void SetCursorBlinkRate(int rate);
254
255 // Copy-pasting
256 void copyText();
257 void pasteText();
258 void cutText();
259
260 // Text printing functions
261 virtual void DrawText(int fg_color, int bg_color, int flags, int x, int y, const std::string& sText) override;
262 virtual void DrawCursor(int fg_color, int bg_color, int flags, int x, int y, unsigned char c) override;
263
264 virtual void Calltip(int x, int y, NumeRe::CallTip& _cTip) override;
265 virtual void CalltipCancel() override;
266
267 virtual void ClearChars(int bg_color, int x, int y, int w, int h) override;
268 virtual void ProcessInput(int len, const std::string& sData) override;
269 virtual void ProcessOutput(int len, const std::string& sData) override;
270
271 // Terminal control functions
272 void ScrollTerminal(int numLines, bool scrollUp = true);
273 void ClearSelection();
274 bool HasSelection();
275 wxString GetSelection();
277 {
278 return GetThread() && GetThread()->IsRunning();
279 }
280 void UpdateSize();
281 void UpdateColors();
282 virtual void ModeChange(int state) override;
283 virtual void Bell() override;
284 virtual void ResizeTerminal(int width, int height) override;
285 virtual void UpdateRemoteSize(int width, int height);
286 void clearTerminal();
287
289 {
290 return m_charsInLine;
291 }
293 {
294 return m_linesDisplayed;
295 }
296
298};
299
300#endif /* TERMINAL_HPP */
An implementation of a generic terminal, which has to be specialized in the child classes.
Definition: gterm.hpp:42
This data container is a copy- efficient table to interchange data between Kernel and GUI.
Definition: table.hpp:87
This class provides the interface to the core of NumeRe. It provides all functionalities,...
Definition: kernel.hpp:97
@ DEBUGGER_LEAVE
Definition: kernel.hpp:134
@ DEBUGGER_STEPOVER
Definition: kernel.hpp:133
@ DEBUGGER_CONTINUE
Definition: kernel.hpp:131
The terminal class for the GUI. It's a specialisation of the GenericTerminal.
Definition: terminal.hpp:46
std::vector< std::string > getDocIndex()
Gets the contents of the documentation index as a vector.
Definition: terminal.cpp:324
TerminalCallTip * m_callTip
Definition: terminal.hpp:75
NumeReKernel & getKernel()
Definition: terminal.hpp:192
int GetTermHeight()
Definition: terminal.hpp:292
NumeReVariables getVariableList()
This will return the variable list from the kernel to be shown in the variable viewer.
Definition: terminal.cpp:369
void ClearSelection()
Definition: terminal.cpp:1382
void OnPaint(wxPaintEvent &event)
Definition: terminal.cpp:1233
NumeReKernel::KernelStatus m_KernelStatus
Definition: terminal.hpp:168
void OnThreadUpdate(wxThreadEvent &event)
This function is the thread update event handler member function. Here are all returned messages from...
Definition: terminal.cpp:573
wxFont m_boldUnderlinedFont
Definition: terminal.hpp:98
bool IsWorking()
Definition: terminal.hpp:276
virtual void UpdateRemoteSize(int width, int height)
Fallback for the virtual definition.
Definition: terminal.cpp:2278
std::map< std::string, std::string > getPluginLanguageStrings()
This will return the language strings for the plugins used by the language class for filling the symb...
Definition: terminal.cpp:339
bool m_bTableEditAvailable
Definition: terminal.hpp:170
bool m_inUpdateSize
Definition: terminal.hpp:84
void passEditedTable(NumeRe::Table _table)
Passes a table (as a container) to the kernel.
Definition: terminal.cpp:245
NumeReTerminal(wxWindow *parent, wxWindowID id, Options *_option, const wxString &sPath, const wxPoint &pos=wxDefaultPosition, int width=80, int height=24, const wxString &name="wxTerm")
Terminal constructor.
Definition: terminal.cpp:85
Options * m_options
Definition: terminal.hpp:114
void OnSize(wxSizeEvent &event)
Definition: terminal.cpp:2264
void cutText()
Implements copy to clip board and deleting the selection.
Definition: terminal.cpp:1553
void DoDrawCursor(int fg_color, int bg_color, int flags, int x, int y, unsigned char c)
Definition: terminal.cpp:1662
void pipe_command(const std::string &sCommand)
Pass the entered command line to the kernel.
Definition: terminal.cpp:901
void EndKernelTask()
This function forces the thread to terminate so that the application may be shut down.
Definition: terminal.cpp:535
wxMemoryDC m_memDC
Definition: terminal.hpp:104
NumeRe::Table getTable(const std::string &sTableName)
This function will return the named table from the kernel to be shown in a GUI window.
Definition: terminal.cpp:964
wxTimer m_timer
Definition: terminal.hpp:110
virtual void Bell() override
Definition: terminal.cpp:1935
virtual void Calltip(int x, int y, NumeRe::CallTip &_cTip) override
Function reimplementation to display a tooltip requested by the GenericTerminal.
Definition: terminal.cpp:1839
NumeReKernel _kernel
Definition: terminal.hpp:166
void OnGainFocus(wxFocusEvent &event)
Definition: terminal.cpp:2184
virtual void DrawCursor(int fg_color, int bg_color, int flags, int x, int y, unsigned char c) override
Definition: terminal.cpp:1749
int getTextHeight()
Definition: terminal.hpp:130
bool m_selecting
Definition: terminal.hpp:81
void StartKernelTask()
This member function will start the managed, second thread, in which the kernel will operate.
Definition: terminal.cpp:415
wxDC * m_curDC
Definition: terminal.hpp:101
void OnLoseMouseCapture(wxMouseCaptureLostEvent &event)
This member function handles the "MouseCaptureLostEvent" and releases the mouse.
Definition: terminal.cpp:1280
void clearTerminal()
This member function clears the terminal.
Definition: terminal.cpp:2290
virtual ~NumeReTerminal()
Terminal destructor.
Definition: terminal.cpp:168
void UpdateLibrary()
Definition: terminal.hpp:240
virtual void ModeChange(int state) override
Definition: terminal.cpp:1915
bool HasSelection()
Definition: terminal.cpp:1477
wxString GetSelection()
Definition: terminal.cpp:1492
wxColour * m_colors
Definition: terminal.hpp:89
void OnLeftDown(wxMouseEvent &event)
Definition: terminal.cpp:1260
const std::vector< Package > & getInstalledPackages()
Returns the installed plugins as a STL vector.
Definition: terminal.cpp:200
void copyText()
Implements copy to clip board.
Definition: terminal.cpp:1506
virtual void ProcessOutput(int len, const std::string &sData) override
Processes text received from the kernel.
Definition: terminal.cpp:2146
void continueDebug()
Definition: terminal.hpp:216
void stepDebug()
Definition: terminal.hpp:221
void Busy()
Inform the GUI that the kernel is currently busy.
Definition: terminal.cpp:2215
bool filterKeyCodes(int keyCode, bool ctrlDown)
This private member function filters special key codes and handles them.
Definition: terminal.cpp:1070
virtual void CalltipCancel() override
Function reimplementation to close the previously opened calltip.
Definition: terminal.cpp:1865
void OnClose(wxCloseEvent &event)
This function forces the thread to terminate immediately. Should only occur in situations,...
Definition: terminal.cpp:554
void pasteText()
Implements paste from clip board.
Definition: terminal.cpp:1528
void OnLoseFocus(wxFocusEvent &event)
Definition: terminal.cpp:2201
void stepOverDebug()
Definition: terminal.hpp:226
void leaveDebug()
Definition: terminal.hpp:231
std::string m_sCommandLine
Definition: terminal.hpp:174
void MarkSelection(bool bRectangular=false)
Definition: terminal.cpp:1403
virtual void ClearChars(int bg_color, int x, int y, int w, int h) override
Definition: terminal.cpp:1887
void OnKeyDown(wxKeyEvent &event)
Definition: terminal.cpp:1187
void cancelTableEdit()
Definition: terminal.hpp:207
void ScrollTerminal(int numLines, bool scrollUp=true)
Definition: terminal.cpp:2247
void pass_command(const std::string &command, bool isEvent)
Pass the external command to the kernel without printing it to the console.
Definition: terminal.cpp:925
void updatePackage(const std::string &package)
Updates an installed package with new information after the user created a package with the package c...
Definition: terminal.cpp:230
bool m_bTableEditCanceled
Definition: terminal.hpp:171
virtual void DrawText(int fg_color, int bg_color, int flags, int x, int y, const std::string &sText) override
Definition: terminal.cpp:1578
Settings getKernelSettings()
This will return a copy of the internal settings object of the kernel.
Definition: terminal.cpp:383
void CancelCalculation()
Inform the kernel to stop the current calculation. Used to handle the ESC key press.
Definition: terminal.cpp:994
NumeReWindow * m_wxParent
Definition: terminal.hpp:112
bool m_updateProcedureLibrary
Definition: terminal.hpp:86
wxFont m_underlinedFont
Definition: terminal.hpp:96
wxFont m_normalFont
Definition: terminal.hpp:95
int m_scrollBarWidth
Definition: terminal.hpp:71
int m_curBlinkRate
Definition: terminal.hpp:69
bool m_bCommandAvailable
Definition: terminal.hpp:169
void UpdateColors()
This member function sets the new colors to the internal pen definitions.
Definition: terminal.cpp:2021
virtual void ResizeTerminal(int width, int height) override
Definition: terminal.cpp:2052
void clearBreakpoints(const std::string &_sFilename)
This member function removes all breakpoints from the passed file.
Definition: terminal.cpp:295
void GetDefColors(wxColor colors[16], NumeReTerminal::BOLDSTYLE boldStyle=NumeReTerminal::DEFAULT)
Definition: terminal.cpp:791
wxCriticalSection m_kernelCS
Definition: terminal.hpp:167
void UpdateSize()
Definition: terminal.cpp:1953
void scrollToInput()
This private member function scrolls the terminal all the way down.
Definition: terminal.cpp:1164
std::map< std::string, std::string > getMenuMap()
Returns the menu map of the installed plugins as a STL map.
Definition: terminal.cpp:214
NumeRe::Container< std::string > getStringTable(const std::string &sStringTableName)
This member function will return the named table containing strings.
Definition: terminal.cpp:979
void removeBreakpoint(const std::string &_sFilename, size_t nLine)
This member function removes a breakpoint from the passed file at the indicated line number.
Definition: terminal.cpp:280
int GetTermWidth()
Definition: terminal.hpp:288
void OnTimer(wxTimerEvent &event)
Definition: terminal.cpp:1786
void OnEnter(wxMouseEvent &event)
This member function handles the "Mouse Enter" event.
Definition: terminal.cpp:1361
int GetCursorBlinkRate()
Definition: terminal.hpp:249
std::string getDocumentation(const std::string &sCommand)
Gets the desired documentation article as a HTML string.
Definition: terminal.cpp:310
wxPen * m_colorPens
Definition: terminal.hpp:92
void OnChar(wxKeyEvent &event)
Definition: terminal.cpp:1012
void SetParent(NumeReWindow *frame)
Definition: terminal.hpp:125
virtual void ProcessInput(int len, const std::string &sData) override
Processes text received from the keybord or clipboard.
Definition: terminal.cpp:2118
wxBitmap * m_bitmap
Definition: terminal.hpp:107
wxFont m_boldFont
Definition: terminal.hpp:97
std::string m_sAnswer
Definition: terminal.hpp:175
void setKernelSettings(const Settings &)
This will pass the new kernel settings to the kernel.
Definition: terminal.cpp:399
void SetCursorBlinkRate(int rate)
Definition: terminal.cpp:866
std::map< std::string, std::string > getFunctionLanguageStrings()
This will return the language strings for the custom defined functions used by the language class for...
Definition: terminal.cpp:354
wxColour m_color_defs[16]
Definition: terminal.hpp:89
std::vector< std::string > getPathSettings()
Returns the standard paths as a STL vector.
Definition: terminal.cpp:185
void OnActivate(wxActivateEvent &event)
Definition: terminal.cpp:2168
int m_linesDisplayed
Definition: terminal.hpp:73
void Ready()
Inform the GUI that the kernel is ready for calculation.
Definition: terminal.cpp:2229
unsigned char m_curChar
Definition: terminal.hpp:78
bool SetFont(const wxFont &font)
Definition: terminal.cpp:746
void OnMouseMove(wxMouseEvent &event)
Definition: terminal.cpp:1325
wxPen m_colorPen_defs[16]
Definition: terminal.hpp:92
BOLDSTYLE m_boldStyle
Definition: terminal.hpp:138
void OnLeftUp(wxMouseEvent &event)
Definition: terminal.cpp:1302
virtual wxThread::ExitCode Entry()
This is the main thread function and will be called repeatedly from the wxWidgets library.
Definition: terminal.cpp:438
void addBreakpoint(const std::string &_sFilename, size_t nLine)
This member function adds a breakpoint to the passed file at the indicated line number.
Definition: terminal.cpp:263
This class is the actual NumeRe main frame. The application's logic is implemented here.
Definition: NumeReWindow.h:177
This class implements an interface of the internal Settings object adapted to be usable from the GUI.
Definition: Options.h:178
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663
This class represents the calltip in the terminal. The associated window will only be shown and hidde...
char name[32]
Definition: resampler.cpp:371
This structure contains the data for a single calltip, which might be shown in the editor or the term...
This structure combines a vector of declared variables including their values and respective sizes wi...
Definition: kernel.hpp:80