diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 5db91214..f1ccf7b9 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -963,6 +963,8 @@ namespace pv _session->reload(); + std::vector view_indexs; + // load signal setting if (mode == DSO) { @@ -1031,8 +1033,8 @@ namespace pv } if (s->signal_type() == SR_CHANNEL_LOGIC && obj.contains("view_index")) - { - _session->set_channel_view_index(s->get_index(), obj["view_index"].toInt()); + { + view_indexs.push_back(obj["view_index"].toInt()); } break; @@ -1045,6 +1047,17 @@ namespace pv _sampling_bar->update_sample_rate_list(); _trigger_widget->device_updated(); _view->header_updated(); + + if (mode == LOGIC && view_indexs.size()){ + int i = 0; + + for (auto s : _session->get_signals()){ + s->set_view_index(view_indexs[i]); + i++; + } + + _view->update_all_trace_postion(); + } // load trigger settings if (sessionObj.contains("trigger")) diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index 0ccf6960..dcb5d25e 100644 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -865,9 +865,9 @@ namespace pv } clear_signals(); - std::vector().swap(_signals); _signals = sigs; + make_channels_view_index(); spectrum_rebuild(); lissajous_disable(); @@ -962,10 +962,22 @@ namespace pv if (!sigs.empty()) { + std::vector view_indexs; + for(auto s : _signals){ + view_indexs.push_back(s->get_view_index()); + } + dsv_info("SigSession::reload(), clear signals"); clear_signals(); std::vector().swap(_signals); _signals = sigs; + make_channels_view_index(); + + if (_device_agent.get_work_mode() == LOGIC){ + for (int i=0; iset_view_index(view_indexs[i]); + } + } } spectrum_rebuild(); @@ -2322,11 +2334,12 @@ namespace pv return NULL; } - void SigSession::set_channel_view_index(int orgIndex, int viewIndex) + void SigSession::make_channels_view_index() { - auto trace = get_channel_by_index(orgIndex); - if (trace != NULL){ - trace->set_view_index(viewIndex); + int index = 0; + + for(auto t : _signals){ + t->set_view_index(index++); } } diff --git a/DSView/pv/sigsession.h b/DSView/pv/sigsession.h index e39a5e3c..329ba898 100644 --- a/DSView/pv/sigsession.h +++ b/DSView/pv/sigsession.h @@ -428,8 +428,6 @@ public: _decoder_pannel = pannel; } - void set_channel_view_index(int orgIndex, int viewIndex); - private: void set_cur_samplelimits(uint64_t samplelimits); void set_cur_snap_samplerate(uint64_t samplerate); @@ -520,6 +518,7 @@ private: } view::Trace* get_channel_by_index(int orgIndex); + void make_channels_view_index(); private: mutable std::mutex _sampling_mutex; diff --git a/DSView/pv/view/header.cpp b/DSView/pv/view/header.cpp index 054fe60b..d3716e7b 100644 --- a/DSView/pv/view/header.cpp +++ b/DSView/pv/view/header.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "view.h" #include "trace.h" @@ -239,8 +240,26 @@ void Header::mouseReleaseEvent(QMouseEvent *event) changeName(event); } } + + // Make view index by Y value; + int mode = _view.session().get_device()->get_work_mode(); + if (_moveFlag && mode == LOGIC) + { + std::vector traces; + + for (auto s : _view.session().get_signals()){ + traces.push_back(s); + } + + sort(traces.begin(), traces.end(), View::compare_trace_y); + + int index = 0; + for (auto t : traces){ + t->set_view_index(index++); + } + } + if (_moveFlag) { - //move(event); _drag_traces.clear(); _view.signals_changed(); _view.set_all_update(true); diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index 8536d2df..addc1a87 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "groupsignal.h" #include "decodetrace.h" @@ -365,24 +366,52 @@ void View::get_traces(int type, std::vector &traces) traces.push_back(math); } - stable_sort(traces.begin(), traces.end(), compare_trace_v_offsets); + sort(traces.begin(), traces.end(), compare_trace_v_offsets); } -bool View::compare_trace_v_offsets(const Trace *a, - const Trace *b) +bool View::compare_trace_v_offsets(const Trace *a, const Trace *b) { assert(a); assert(b); Trace *a1 = const_cast(a); Trace *b1 = const_cast(b); + int v1 = 0; + int v2 = 0; - if (a1->get_type() != b1->get_type()) - return a1->get_type() < b1->get_type(); - else if (a1->get_type() == SR_CHANNEL_DSO || a1->get_type() == SR_CHANNEL_ANALOG) - return a1->get_index() < b1->get_index(); - else - return a1->get_v_offset() < b1->get_v_offset(); + if (a1->get_type() != b1->get_type()){ + v1 = a1->get_type(); + v2 = b1->get_type(); + } + else if (a1->get_type() == SR_CHANNEL_DSO || a1->get_type() == SR_CHANNEL_ANALOG){ + v1 = a1->get_index(); + v2 = b1->get_index(); + } + else{ + v1 = a1->get_v_offset(); + v2 = b1->get_v_offset(); + } + return v1 < v2; +} + +bool View::compare_trace_view_index(const Trace *a, const Trace *b) +{ + assert(a); + assert(b); + + Trace *a1 = const_cast(a); + Trace *b1 = const_cast(b); + return a1->get_view_index() < b1->get_view_index(); +} + +bool View::compare_trace_y(const Trace *a, const Trace *b) +{ + assert(a); + assert(b); + + Trace *a1 = const_cast(a); + Trace *b1 = const_cast(b); + return a1->get_v_offset() < b1->get_v_offset(); } void View::show_cursors(bool show) @@ -597,11 +626,18 @@ void View::signals_changed() get_traces(ALL_VIEW, traces); for(auto t : traces) { - if (_trace_view_map[t->get_type()] == TIME_VIEW) + if (_trace_view_map[t->get_type()] == TIME_VIEW){ time_traces.push_back(t); - else if (_trace_view_map[t->get_type()] == FFT_VIEW) + } + else if (_trace_view_map[t->get_type()] == FFT_VIEW){ if (t->enabled()) fft_traces.push_back(t); + } + + if (t->get_type() == SR_CHANNEL_LOGIC) + logic_traces.push_back(t); + else if (t->get_type() == SR_CHANNEL_DECODER) + decoder_traces.push_back(t); } if (!fft_traces.empty()) { @@ -611,6 +647,7 @@ void View::signals_changed() _viewport_list.push_back(_fft_viewport); _vsplitter->refresh(); } + for(auto t : fft_traces) { t->set_view(this); t->set_viewport(_fft_viewport); @@ -624,9 +661,12 @@ void View::signals_changed() // Find the _fft_viewport in the stack std::list< QWidget *>::iterator iter = _viewport_list.begin(); - for(unsigned int i = 0; i < _viewport_list.size(); i++, iter++) + + for(unsigned int i = 0; i < _viewport_list.size(); i++, iter++){ if ((*iter) == _fft_viewport) break; + } + // Delete the element if (iter != _viewport_list.end()) _viewport_list.erase(iter); @@ -645,9 +685,11 @@ void View::signals_changed() if (_device_agent->have_instance() == false){ assert(false); - } + } + + int mode = _device_agent->get_work_mode(); - if (_device_agent->get_work_mode() == LOGIC) { + if (mode == LOGIC) { int v; bool ret; @@ -676,12 +718,29 @@ void View::signals_changed() _spanY = _signalHeight + 2 * actualMargin; int next_v_offset = actualMargin; + + //Make list by view index; + if (mode == LOGIC) + { + sort(logic_traces.begin(), logic_traces.end(), compare_trace_view_index); + time_traces.clear(); + + for(auto t : decoder_traces){ + time_traces.push_back(t); + } + + for(auto t : logic_traces){ + time_traces.push_back(t); + } + } for(auto t : time_traces) { t->set_view(this); t->set_viewport(_time_viewport); + if (t->rows_size() == 0) continue; + const double traceHeight = _signalHeight*t->rows_size(); t->set_totalHeight((int)traceHeight); t->set_v_offset(next_v_offset + 0.5 * traceHeight + actualMargin); @@ -1258,5 +1317,11 @@ int View::get_body_height() return 0; } + void View::update_view_port() + { + if (_time_viewport) + _time_viewport->update(); + } + } // namespace view } // namespace pv diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index 3b31b2d9..767b97f9 100644 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -309,6 +309,12 @@ public: void check_calibration(); + void update_view_port(); + + inline void update_all_trace_postion(){ + signals_changed(); + } + signals: void hover_point_changed(); void cursor_update(); @@ -327,15 +333,18 @@ private: void update_margins(); - static bool compare_trace_v_offsets( - const pv::view::Trace *a, - const pv::view::Trace *b); + static bool compare_trace_v_offsets( const Trace *a, const Trace *b); void clear(); void reconstruct(); bool eventFilter(QObject *object, QEvent *event); bool viewportEvent(QEvent *e); void resizeEvent(QResizeEvent *e); + +public: + static bool compare_trace_view_index(const Trace *a, const Trace *b); + + static bool compare_trace_y(const Trace *a, const Trace *b); public slots: void reload();