view.h 8.53 KB
Newer Older
DreamSourceLab's avatar
DreamSourceLab committed
1
/*
DreamSourceLab's avatar
DreamSourceLab committed
2 3
 * This file is part of the DSView project.
 * DSView is based on PulseView.
DreamSourceLab's avatar
DreamSourceLab committed
4 5
 *
 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
6
 * Copyright (C) 2013 DreamSourceLab <support@dreamsourcelab.com>
DreamSourceLab's avatar
DreamSourceLab committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */


DreamSourceLab's avatar
DreamSourceLab committed
24 25
#ifndef DSVIEW_PV_VIEW_VIEW_H
#define DSVIEW_PV_VIEW_VIEW_H
DreamSourceLab's avatar
DreamSourceLab committed
26 27

#include <stdint.h>
DreamSourceLab's avatar
DreamSourceLab committed
28 29 30 31 32 33
#include <set>
#include <vector>

#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

DreamSourceLab's avatar
DreamSourceLab committed
34
#include <QScrollArea>
DreamSourceLab's avatar
DreamSourceLab committed
35
#include <QSizeF>
36
#include <QDateTime>
DreamSourceLab's avatar
DreamSourceLab committed
37
#include <QSplitter>
DreamSourceLab's avatar
DreamSourceLab committed
38

DreamSourceLab's avatar
DreamSourceLab committed
39
#include "../../extdef.h"
DreamSourceLab's avatar
DreamSourceLab committed
40
#include "../toolbars/samplingbar.h"
DreamSourceLab's avatar
DreamSourceLab committed
41
#include "../data/signaldata.h"
DreamSourceLab's avatar
DreamSourceLab committed
42
#include "../view/viewport.h"
DreamSourceLab's avatar
DreamSourceLab committed
43
#include "cursor.h"
Andy Dneg's avatar
Andy Dneg committed
44
#include "xcursor.h"
DreamSourceLab's avatar
DreamSourceLab committed
45
#include "signal.h"
Andy Dneg's avatar
Andy Dneg committed
46
#include "viewstatus.h"
DreamSourceLab's avatar
DreamSourceLab committed
47 48 49

namespace pv {

DreamSourceLab's avatar
DreamSourceLab committed
50 51 52 53
namespace toolbars {
    class SamplingBar;
}

Andy Dneg's avatar
Andy Dneg committed
54 55 56 57 58
namespace dialogs {
    class Calibration;
    class Lissajous;
}

DreamSourceLab's avatar
DreamSourceLab committed
59 60 61 62 63
class SigSession;

namespace view {

class Header;
DreamSourceLab's avatar
DreamSourceLab committed
64
class DevMode;
DreamSourceLab's avatar
DreamSourceLab committed
65
class Ruler;
DreamSourceLab's avatar
DreamSourceLab committed
66
class Trace;
DreamSourceLab's avatar
DreamSourceLab committed
67
class Viewport;
Andy Dneg's avatar
Andy Dneg committed
68
class LissajousFigure;
DreamSourceLab's avatar
DreamSourceLab committed
69

DreamSourceLab's avatar
DreamSourceLab committed
70
class View : public QScrollArea {
DreamSourceLab's avatar
DreamSourceLab committed
71 72 73 74 75 76 77
	Q_OBJECT

private:
	static const int LabelMarginWidth;
	static const int RulerHeight;

	static const int MaxScrollValue;
78
    static const int MaxHeightUnit;
DreamSourceLab's avatar
DreamSourceLab committed
79 80 81 82 83 84 85 86 87 88

public:
    //static const int SignalHeight;
	static const int SignalMargin;
	static const int SignalSnapGridSize;

	static const QColor CursorAreaColour;

	static const QSizeF LabelPadding;

89
    static const int WellSamplesPerPixel = 2048;
90 91
    static constexpr double MaxViewRate = 1.0;
    static const int MaxPixelsPerSample = 100;
DreamSourceLab's avatar
DreamSourceLab committed
92

93
    static const int StatusHeight = 20;
Andy Dneg's avatar
Andy Dneg committed
94 95 96 97 98 99 100 101 102 103
    static const int DsoStatusHeight = 55;

    static const int ForeAlpha = 200;
    static const int BackAlpha = 100;
    static const QColor Red;
    static const QColor Orange;
    static const QColor Blue;
    static const QColor Green;
    static const QColor Purple;
    static const QColor LightBlue;
DreamSourceLab's avatar
DreamSourceLab committed
104
    static const QColor LightRed;
105

DreamSourceLab's avatar
DreamSourceLab committed
106
public:
DreamSourceLab's avatar
DreamSourceLab committed
107
    explicit View(SigSession &session, pv::toolbars::SamplingBar *sampling_bar, QWidget *parent = 0);
DreamSourceLab's avatar
DreamSourceLab committed
108 109 110 111 112 113 114 115 116

	SigSession& session();

	/**
	 * Returns the view time scale in seconds per pixel.
	 */
	double scale() const;

	/**
117
     * Returns the pixels offset of the left edge of the view
DreamSourceLab's avatar
DreamSourceLab committed
118
	 */
119
    int64_t offset() const;
DreamSourceLab's avatar
DreamSourceLab committed
120 121
	int v_offset() const;

122 123 124 125 126 127
    /**
     * trigger position fix
     */
    double trig_hoff() const;
    void set_trig_hoff(double hoff);

128 129 130
    int64_t get_min_offset();
    int64_t get_max_offset();

131
    void capture_init();
132

DreamSourceLab's avatar
DreamSourceLab committed
133
	void zoom(double steps);
134
    bool zoom(double steps, int offset);
DreamSourceLab's avatar
DreamSourceLab committed
135 136 137 138 139 140

	/**
	 * Sets the scale and offset.
	 * @param scale The new view scale in seconds per pixel.
	 * @param offset The view time offset in seconds.
	 */
141
    void set_scale_offset(double scale, int64_t offset);
DreamSourceLab's avatar
DreamSourceLab committed
142 143
    void set_preScale_preOffset();

DreamSourceLab's avatar
DreamSourceLab committed
144
    std::vector< boost::shared_ptr<Trace> > get_traces(int type);
DreamSourceLab's avatar
DreamSourceLab committed
145

DreamSourceLab's avatar
DreamSourceLab committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
	/**
	 * Returns true if cursors are displayed. false otherwise.
	 */
	bool cursors_shown() const;
    bool trig_cursor_shown() const;
    bool search_cursor_shown() const;

    int get_spanY();

    int get_signalHeight();

    int headerWidth();

    Ruler* get_ruler();

	/**
	 * Shows or hides the cursors.
	 */
	void show_cursors(bool show = true);

166
    const QPoint& hover_point() const;
DreamSourceLab's avatar
DreamSourceLab committed
167 168 169 170 171 172 173 174 175 176 177

	void normalize_layout();

    void show_trig_cursor(bool show = true);

    void show_search_cursor(bool show = true);

    /*
     * cursorList
     */
    std::list<Cursor*>& get_cursorList();
178
    void add_cursor(QColor color, uint64_t index);
DreamSourceLab's avatar
DreamSourceLab committed
179 180 181 182 183
    void del_cursor(Cursor* cursor);
    void set_cursor_middle(int index);

    Cursor* get_trig_cursor();
    Cursor* get_search_cursor();
184
    bool get_search_hit();
DreamSourceLab's avatar
DreamSourceLab committed
185

186
    void set_search_pos(uint64_t search_pos, bool hit);
DreamSourceLab's avatar
DreamSourceLab committed
187 188 189

    uint64_t get_search_pos();

Andy Dneg's avatar
Andy Dneg committed
190 191 192 193 194 195 196 197 198
    /*
     * horizental cursors
     */
    bool xcursors_shown();
    void show_xcursors(bool show);
    std::list<XCursor*>& get_xcursorList();
    void add_xcursor(QColor color, double value0, double value1);
    void del_xcursor(XCursor* xcursor);

DreamSourceLab's avatar
DreamSourceLab committed
199 200 201 202 203 204
    /*
     *
     */
    double get_minscale() const;
    double get_maxscale() const;

DreamSourceLab's avatar
DreamSourceLab committed
205 206
    void set_update(Viewport *viewport, bool need_update);
    void set_all_update(bool need_update);
DreamSourceLab's avatar
DreamSourceLab committed
207

DreamSourceLab's avatar
DreamSourceLab committed
208
    uint64_t get_cursor_samples(int index);
DreamSourceLab's avatar
DreamSourceLab committed
209 210
    QString get_cm_time(int index);
    QString get_cm_delta(int index1, int index2);
211
    QString get_index_delta(uint64_t start, uint64_t end);
DreamSourceLab's avatar
DreamSourceLab committed
212 213 214

    void on_state_changed(bool stop);

215
    QRect get_view_rect();
DreamSourceLab's avatar
DreamSourceLab committed
216
    int get_view_width();
217
    int get_view_height();
DreamSourceLab's avatar
DreamSourceLab committed
218

219
    double get_hori_res();
DreamSourceLab's avatar
DreamSourceLab committed
220

DreamSourceLab's avatar
DreamSourceLab committed
221 222 223 224
    QString get_measure(QString option);

    void viewport_update();

225 226
    void set_capture_status();

227 228
    bool get_dso_trig_moved() const;

Andy Dneg's avatar
Andy Dneg committed
229 230 231 232 233 234 235 236
    ViewStatus* get_viewstatus();

    /*
     * back paint status
     */
    bool back_ready() const;
    void set_back(bool ready);

237 238 239 240 241 242
    /*
     * untils
     */
    double index2pixel(uint64_t index, bool has_hoff = true);
    uint64_t pixel2index(double pixel);

DreamSourceLab's avatar
DreamSourceLab committed
243 244 245 246
signals:
	void hover_point_changed();

    void cursor_update();
Andy Dneg's avatar
Andy Dneg committed
247
    void xcursor_update();
DreamSourceLab's avatar
DreamSourceLab committed
248

249
    void cursor_moving();
DreamSourceLab's avatar
DreamSourceLab committed
250 251
    void cursor_moved();

DreamSourceLab's avatar
DreamSourceLab committed
252 253
    void measure_updated();

254 255
    void prgRate(int progress);

Andy Dneg's avatar
Andy Dneg committed
256
    void device_changed(bool close);
257

258 259
    void resize();

260 261
    void auto_trig(int index);

DreamSourceLab's avatar
DreamSourceLab committed
262
private:
263
    void get_scroll_layout(int64_t &length, int64_t &offset) const;
DreamSourceLab's avatar
DreamSourceLab committed
264 265 266 267 268
	
	void update_scroll();

    void update_margins();

DreamSourceLab's avatar
DreamSourceLab committed
269 270 271 272
    static bool compare_trace_v_offsets(
        const boost::shared_ptr<pv::view::Trace> &a,
        const boost::shared_ptr<pv::view::Trace> &b);

Andy Dneg's avatar
Andy Dneg committed
273 274 275
    void clear();
    void reconstruct();

DreamSourceLab's avatar
DreamSourceLab committed
276 277 278 279 280 281 282 283
private:
	bool eventFilter(QObject *object, QEvent *event);

	bool viewportEvent(QEvent *e);

	void resizeEvent(QResizeEvent *e);

public slots:
284
    void reload();
DreamSourceLab's avatar
v0.3  
DreamSourceLab committed
285
    void set_measure_en(int enable);
DreamSourceLab's avatar
DreamSourceLab committed
286 287
    void signals_changed();
    void data_updated();
288
    void update_scale_offset();
289
    void show_region(uint64_t start, uint64_t end, bool keep);
290
    // -- calibration
291
    void hide_calibration();
292
    void status_clear();
293
    void repeat_unshow();
Andy Dneg's avatar
Andy Dneg committed
294

295 296
    // -- repeat
    void repeat_show();
297 298 299
    // --
    void timebase_changed();
    // --
Andy Dneg's avatar
Andy Dneg committed
300 301
    void vDial_updated();
    // --
302
    void update_hori_res();
DreamSourceLab's avatar
DreamSourceLab committed
303

Andy Dneg's avatar
Andy Dneg committed
304 305 306 307
    // --
    void set_trig_time();
    bool trig_time_setted();

DreamSourceLab's avatar
DreamSourceLab committed
308 309 310 311 312 313 314
private slots:

	void h_scroll_value_changed(int value);
	void v_scroll_value_changed(int value);

	void marker_time_changed();

DreamSourceLab's avatar
DreamSourceLab committed
315
    void on_traces_moved();
DreamSourceLab's avatar
DreamSourceLab committed
316 317 318

    void header_updated();

319 320
    void receive_trigger(quint64 trig_pos);
    void set_trig_pos(int percent);
DreamSourceLab's avatar
DreamSourceLab committed
321

322 323 324 325
    void receive_end();

    void frame_began();

326 327
    // calibration for oscilloscope
    void show_calibration();
Andy Dneg's avatar
Andy Dneg committed
328 329
    // lissajous figure
    void show_lissajous(bool show);
DreamSourceLab's avatar
DreamSourceLab committed
330 331 332 333
    void on_measure_updated();

    void splitterMoved(int pos, int index);

Andy Dneg's avatar
Andy Dneg committed
334
    void dev_changed(bool close);
335

DreamSourceLab's avatar
DreamSourceLab committed
336 337 338
private:

	SigSession &_session;
DreamSourceLab's avatar
DreamSourceLab committed
339
    pv::toolbars::SamplingBar *_sampling_bar;
DreamSourceLab's avatar
DreamSourceLab committed
340

DreamSourceLab's avatar
DreamSourceLab committed
341
    QWidget *_viewcenter;
Andy Dneg's avatar
Andy Dneg committed
342
    ViewStatus *_viewbottom;
DreamSourceLab's avatar
DreamSourceLab committed
343 344 345
    QSplitter *_vsplitter;
    Viewport * _time_viewport;
    Viewport * _fft_viewport;
Andy Dneg's avatar
Andy Dneg committed
346
    LissajousFigure *_lissajous;
DreamSourceLab's avatar
DreamSourceLab committed
347
    Viewport *_active_viewport;
Andy Dneg's avatar
Andy Dneg committed
348
    std::list<QWidget *> _viewport_list;
DreamSourceLab's avatar
DreamSourceLab committed
349
    std::map<int, int> _trace_view_map;
DreamSourceLab's avatar
DreamSourceLab committed
350 351
	Ruler *_ruler;
	Header *_header;
DreamSourceLab's avatar
DreamSourceLab committed
352
    DevMode *_devmode;
DreamSourceLab's avatar
DreamSourceLab committed
353 354 355

	/// The view time scale in seconds per pixel.
	double _scale;
356 357 358
    double _preScale;
    double _maxscale;
    double _minscale;
DreamSourceLab's avatar
DreamSourceLab committed
359

360 361 362 363 364 365
    /// The pixels offset of the left edge of the view
    int64_t _offset;
    int64_t _preOffset;
    int _spanY;
    int _signalHeight;
    bool _updating_scroll;
DreamSourceLab's avatar
DreamSourceLab committed
366

367 368 369
    // trigger position fix
    double _trig_hoff;

DreamSourceLab's avatar
DreamSourceLab committed
370
	bool _show_cursors;
371 372 373 374 375 376 377 378
    std::list<Cursor*> _cursorList;
    Cursor *_trig_cursor;
    bool _show_trig_cursor;
    Cursor *_search_cursor;
    bool _show_search_cursor;
    uint64_t _search_pos;
    bool _search_hit;

Andy Dneg's avatar
Andy Dneg committed
379 380 381
    bool _show_xcursors;
    std::list<XCursor*> _xcursorList;

382 383
    QPoint _hover_point;
    dialogs::Calibration *_cali;
Andy Dneg's avatar
Andy Dneg committed
384

385
    bool _dso_auto;
Andy Dneg's avatar
Andy Dneg committed
386 387 388
    bool _show_lissajous;
    bool _back_ready;
    bool _trig_time_setted;
DreamSourceLab's avatar
DreamSourceLab committed
389 390 391 392 393
};

} // namespace view
} // namespace pv

DreamSourceLab's avatar
DreamSourceLab committed
394
#endif // DSVIEW_PV_VIEW_VIEW_H