| 1 | /* cavernlog.h |
|---|
| 2 | * Run cavern inside an Aven window |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2005-2024 Olly Betts |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #ifndef SURVEX_CAVERNLOG_H |
|---|
| 22 | #define SURVEX_CAVERNLOG_H |
|---|
| 23 | |
|---|
| 24 | #include "wx.h" |
|---|
| 25 | #include <wx/process.h> |
|---|
| 26 | |
|---|
| 27 | #include <string> |
|---|
| 28 | #include <vector> |
|---|
| 29 | |
|---|
| 30 | class MainFrm; |
|---|
| 31 | |
|---|
| 32 | class CavernLogWindow : public wxScrolledWindow { |
|---|
| 33 | wxString filename; |
|---|
| 34 | |
|---|
| 35 | MainFrm * mainfrm; |
|---|
| 36 | |
|---|
| 37 | wxProcess * cavern_out = nullptr; |
|---|
| 38 | size_t ptr = 0; |
|---|
| 39 | bool expecting_caret_line = false; |
|---|
| 40 | int info_count = 0; |
|---|
| 41 | int link_count = 0; |
|---|
| 42 | |
|---|
| 43 | bool init_done = false; |
|---|
| 44 | |
|---|
| 45 | bool dark_mode = false; |
|---|
| 46 | |
|---|
| 47 | wxString survey; |
|---|
| 48 | |
|---|
| 49 | wxTimer timer; |
|---|
| 50 | |
|---|
| 51 | std::string log_txt; |
|---|
| 52 | |
|---|
| 53 | enum { LOG_NONE, LOG_ERROR, LOG_WARNING, LOG_INFO }; |
|---|
| 54 | |
|---|
| 55 | class LineInfo { |
|---|
| 56 | public: |
|---|
| 57 | unsigned start_offset = 0; |
|---|
| 58 | unsigned len = 0; |
|---|
| 59 | unsigned link_len = 0; |
|---|
| 60 | unsigned link_pixel_width = 0; |
|---|
| 61 | unsigned colour = LOG_NONE; |
|---|
| 62 | unsigned colour_start = 0; |
|---|
| 63 | unsigned colour_len = 0; |
|---|
| 64 | |
|---|
| 65 | LineInfo() { } |
|---|
| 66 | |
|---|
| 67 | explicit LineInfo(unsigned start_offset_) |
|---|
| 68 | : start_offset(start_offset_) { } |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | std::vector<LineInfo> line_info; |
|---|
| 72 | |
|---|
| 73 | wxButton* save_button = nullptr; |
|---|
| 74 | wxButton* reprocess_button = nullptr; |
|---|
| 75 | wxButton* ok_button = nullptr; |
|---|
| 76 | |
|---|
| 77 | public: |
|---|
| 78 | CavernLogWindow(MainFrm * mainfrm_, const wxString & survey_, wxWindow * parent); |
|---|
| 79 | |
|---|
| 80 | ~CavernLogWindow(); |
|---|
| 81 | |
|---|
| 82 | /** Start to process survey data in file. */ |
|---|
| 83 | void process(const wxString &file); |
|---|
| 84 | |
|---|
| 85 | void OnMouseMove(wxMouseEvent& e); |
|---|
| 86 | |
|---|
| 87 | void OnLinkClicked(wxMouseEvent& e); |
|---|
| 88 | |
|---|
| 89 | void OnReprocess(wxCommandEvent &); |
|---|
| 90 | |
|---|
| 91 | void OnSave(wxCommandEvent &); |
|---|
| 92 | |
|---|
| 93 | void OnOK(wxCommandEvent &); |
|---|
| 94 | |
|---|
| 95 | void ProcessCavernOutput(); |
|---|
| 96 | |
|---|
| 97 | void OnCavernOutput(wxCommandEvent&) { |
|---|
| 98 | ProcessCavernOutput(); |
|---|
| 99 | Update(); |
|---|
| 100 | timer.StartOnce(); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | void CheckForOutput(bool immediate = false); |
|---|
| 104 | |
|---|
| 105 | void OnIdle(wxIdleEvent&) { CheckForOutput(); } |
|---|
| 106 | |
|---|
| 107 | void OnTimer(wxTimerEvent&) { CheckForOutput(); } |
|---|
| 108 | |
|---|
| 109 | int OnPaintButton(wxButton* b, int x); |
|---|
| 110 | |
|---|
| 111 | void OnPaint(wxPaintEvent&); |
|---|
| 112 | |
|---|
| 113 | void OnEndProcess(wxProcessEvent & e); |
|---|
| 114 | |
|---|
| 115 | DECLARE_EVENT_TABLE() |
|---|
| 116 | }; |
|---|
| 117 | |
|---|
| 118 | wxString escape_for_shell(wxString s, bool protect_dash = false); |
|---|
| 119 | wxString get_command_path(const wxChar * command_name); |
|---|
| 120 | |
|---|
| 121 | #endif |
|---|