source: git/src/cavernlog.h

faster-cavernlog
Last change on this file was a79ab17, checked in by Olly Betts <olly@…>, 15 hours ago

WIP

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[b0c416c]1/* cavernlog.h
[6bec10c]2 * Run cavern inside an Aven window
3 *
[76bc864f]4 * Copyright (C) 2005-2022 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>
[4d1c855]28#include <vector>
[0e81a88]29
[15ba0b5]30// We probably want to use a thread if we can - that way we can use a blocking
31// read from cavern rather than busy-waiting via idle events.
[fc626ae]32#ifdef wxUSE_THREADS
[0415bac]33# define CAVERNLOG_USE_THREADS
34#endif
35
36#ifdef CAVERNLOG_USE_THREADS
[fc626ae]37class CavernThread;
38#endif
[fb5887c]39class MainFrm;
40
[4d1c855]41class CavernLogWindow : public wxScrolledWindow {
[0415bac]42#ifdef CAVERNLOG_USE_THREADS
[fc626ae]43    friend class CavernThread;
44#endif
45
[fb5887c]46    wxString filename;
47
48    MainFrm * mainfrm;
49
[76bc864f]50    wxProcess * cavern_out = nullptr;
[4d1c855]51    size_t ptr = 0;
52    bool expecting_caret_line = false;
[76bc864f]53    int info_count = 0;
54    int link_count = 0;
[8991d7f]55    unsigned char buf[1024];
56    unsigned char * end;
57
[76bc864f]58    bool init_done = false;
[d7b53e3]59
60    wxString survey;
61
[0e81a88]62    std::string log_txt;
63
[0415bac]64#ifdef CAVERNLOG_USE_THREADS
[fc626ae]65    void stop_thread();
66
[76bc864f]67    CavernThread * thread = nullptr;
[fc626ae]68
69    wxCriticalSection thread_lock;
70#endif
71
[4d1c855]72    enum { LOG_NONE, LOG_ERROR, LOG_WARNING, LOG_INFO };
73
74    class LineInfo {
75      public:
76        unsigned start_offset = 0;
77        unsigned len = 0;
78        unsigned link_len = 0;
[a79ab17]79        unsigned link_pixel_width = 0;
[4d1c855]80        unsigned colour = LOG_NONE;
81        unsigned colour_start = 0;
82        unsigned colour_len = 0;
83
84        LineInfo() { }
85
86        explicit LineInfo(unsigned start_offset_)
87            : start_offset(start_offset_) { }
88    };
89
90    std::vector<LineInfo> line_info;
91
[6bec10c]92  public:
[d7b53e3]93    CavernLogWindow(MainFrm * mainfrm_, const wxString & survey_, wxWindow * parent);
[6bec10c]94
[8991d7f]95    ~CavernLogWindow();
96
97    /** Start to process survey data in file. */
98    void process(const wxString &file);
[6bec10c]99
[a79ab17]100    void OnMouseMove(wxMouseEvent& e);
101
102    void OnLinkClicked(wxMouseEvent& e);
[fb5887c]103
[81e1aa4]104    void OnReprocess(wxCommandEvent &);
[fb5887c]105
[0e81a88]106    void OnSave(wxCommandEvent &);
107
[fb5887c]108    void OnOK(wxCommandEvent &);
109
[fc626ae]110    void OnCavernOutput(wxCommandEvent & e);
111
[15ba0b5]112#ifdef CAVERNLOG_USE_THREADS
[fc626ae]113    void OnClose(wxCloseEvent &);
114#else
[8991d7f]115    void OnIdle(wxIdleEvent &);
[fc626ae]116#endif
[8991d7f]117
[4d1c855]118    void OnPaint(wxPaintEvent &);
119
[15ba0b5]120    void OnEndProcess(wxProcessEvent & e);
121
[fb5887c]122    DECLARE_EVENT_TABLE()
[6bec10c]123};
124
[549eb37]125wxString escape_for_shell(wxString s, bool protect_dash = false);
126wxString get_command_path(const wxChar * command_name);
127
[6bec10c]128#endif
Note: See TracBrowser for help on using the repository browser.