source: git/src/cavernlog.h @ 83eaae1

log-select
Last change on this file since 83eaae1 was ac20829b, checked in by Olly Betts <olly@…>, 14 months ago

Reimplement aven's cavern log window

The old version turned the log into HTML and displayed it using
wxHtmlWindow, but that adds a lot of overhead and is especially
inefficient if there are many diagnostics - cavern could finish
almost instantly yet aven could take many seconds to process
the output.

The new version renders directly from the log data. It should
have most of the features from before - the only missing feature
I'm currently aware of is that you can't now select and copy text
from the log window, which wxHtmlWindow provided for free. If
people miss this feature, we could add it to the new implementation.

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[b0c416c]1/* cavernlog.h
[6bec10c]2 * Run cavern inside an Aven window
3 *
[ac20829b]4 * Copyright (C) 2005-2024 Olly Betts
[6bec10c]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"
[15ba0b5]25#include <wx/process.h>
[6bec10c]26
[0e81a88]27#include <string>
[ac20829b]28#include <vector>
[0e81a88]29
[fb5887c]30class MainFrm;
31
[ac20829b]32class CavernLogWindow : public wxScrolledWindow {
[fb5887c]33    wxString filename;
34
35    MainFrm * mainfrm;
36
[76bc864f]37    wxProcess * cavern_out = nullptr;
[ac20829b]38    size_t ptr = 0;
39    bool expecting_caret_line = false;
[76bc864f]40    int info_count = 0;
41    int link_count = 0;
[8991d7f]42
[76bc864f]43    bool init_done = false;
[d7b53e3]44
45    wxString survey;
46
[ac20829b]47    wxTimer timer;
48
[0e81a88]49    std::string log_txt;
50
[ac20829b]51    enum { LOG_NONE, LOG_ERROR, LOG_WARNING, LOG_INFO };
[fc626ae]52
[ac20829b]53    class LineInfo {
54      public:
55        unsigned start_offset = 0;
56        unsigned len = 0;
57        unsigned link_len = 0;
58        unsigned link_pixel_width = 0;
59        unsigned colour = LOG_NONE;
60        unsigned colour_start = 0;
61        unsigned colour_len = 0;
[fc626ae]62
[ac20829b]63        LineInfo() { }
64
65        explicit LineInfo(unsigned start_offset_)
66            : start_offset(start_offset_) { }
67    };
68
69    std::vector<LineInfo> line_info;
70
71    wxButton* save_button = nullptr;
72    wxButton* reprocess_button = nullptr;
73    wxButton* ok_button = nullptr;
[fc626ae]74
[6bec10c]75  public:
[d7b53e3]76    CavernLogWindow(MainFrm * mainfrm_, const wxString & survey_, wxWindow * parent);
[6bec10c]77
[8991d7f]78    ~CavernLogWindow();
79
80    /** Start to process survey data in file. */
81    void process(const wxString &file);
[6bec10c]82
[ac20829b]83    void OnMouseMove(wxMouseEvent& e);
84
85    void OnLinkClicked(wxMouseEvent& e);
[fb5887c]86
[81e1aa4]87    void OnReprocess(wxCommandEvent &);
[fb5887c]88
[0e81a88]89    void OnSave(wxCommandEvent &);
90
[fb5887c]91    void OnOK(wxCommandEvent &);
92
[ac20829b]93    void ProcessCavernOutput();
[fc626ae]94
[ac20829b]95    void OnCavernOutput(wxCommandEvent&) {
96        ProcessCavernOutput();
97        Update();
98        timer.StartOnce();
99    }
100
101    void CheckForOutput(bool immediate = false);
102
103    void OnIdle(wxIdleEvent&) { CheckForOutput(); }
104
105    void OnTimer(wxTimerEvent&) { CheckForOutput(); }
106
107    int OnPaintButton(wxButton* b, int x);
108
109    void OnPaint(wxPaintEvent&);
[8991d7f]110
[15ba0b5]111    void OnEndProcess(wxProcessEvent & e);
112
[fb5887c]113    DECLARE_EVENT_TABLE()
[6bec10c]114};
115
[549eb37]116wxString escape_for_shell(wxString s, bool protect_dash = false);
117wxString get_command_path(const wxChar * command_name);
118
[6bec10c]119#endif
Note: See TracBrowser for help on using the repository browser.