Skip to content

Commit 93380d8

Browse files
committed
some progress with wave reload, incomplete
1 parent 97b3539 commit 93380d8

File tree

7 files changed

+46
-22
lines changed

7 files changed

+46
-22
lines changed

src/panel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class Panel : public TextReceiver {
4646
virtual bool Modal() const { return false; }
4747
// Returns the current error message and clears it.
4848
std::string Error() const;
49+
virtual void PrepareForWaveDataReload() {}
50+
virtual void HandleReloadedWaves() {}
4951

5052
protected:
5153
virtual int NumLines() const = 0;

src/ui.cc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ void UI::UpdateTooltips() {
6363
tooltips_.clear();
6464
// Add the tooltips that are always present.
6565
tooltips_.push_back({"C-q", "quit"});
66-
if (layout_.has_waves) {
66+
if (layout_.has_waves && (panels_[focused_panel_idx_] == waves_panel_.get() ||
67+
panels_[focused_panel_idx_] == wave_tree_panel_.get() ||
68+
panels_[focused_panel_idx_] == wave_signals_panel_.get())) {
6769
tooltips_.push_back(
6870
{.hotkeys = "C-p",
6971
.description =
@@ -250,14 +252,18 @@ void UI::EventLoop() {
250252
break;
251253
break;
252254
case 0x10: // ctrl-P
253-
layout_.show_wave_picker = !layout_.show_wave_picker;
254-
// If one of those panels was selected, move focus to the wave panel.
255-
if (focused_panel == wave_tree_panel_.get() || wave_signals_panel_.get()) {
256-
focused_panel->SetFocus(false);
257-
waves_panel_->SetFocus(true);
258-
focused_panel_idx_ = panels_.size() - 1;
255+
if (layout_.has_waves && (panels_[focused_panel_idx_] == waves_panel_.get() ||
256+
panels_[focused_panel_idx_] == wave_tree_panel_.get() ||
257+
panels_[focused_panel_idx_] == wave_signals_panel_.get())) {
258+
layout_.show_wave_picker = !layout_.show_wave_picker;
259+
// If one of those panels was selected, move focus to the wave panel.
260+
if (focused_panel == wave_tree_panel_.get() || wave_signals_panel_.get()) {
261+
focused_panel->SetFocus(false);
262+
waves_panel_->SetFocus(true);
263+
focused_panel_idx_ = panels_.size() - 1;
264+
}
265+
LayoutPanels();
259266
}
260-
LayoutPanels();
261267
break;
262268
case 0x9: // tab
263269
case 0x161: { // shift-tab

src/wavedata_tree_panel.cc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace sv {
66

7-
WaveDataTreePanel::WaveDataTreePanel() {
7+
void WaveDataTreePanel::BuildInitialTree() {
88
if (Workspace::Get().Waves() == nullptr) return;
99
for (const auto &scope : Workspace::Get().Waves()->Roots()) {
1010
roots_.push_back(std::make_unique<WaveDataTreeItem>(scope));
@@ -15,31 +15,36 @@ WaveDataTreePanel::WaveDataTreePanel() {
1515
if (data_.ListSize() == 2) {
1616
data_.ToggleExpand(1);
1717
}
18+
line_idx_ = 0;
19+
}
20+
21+
WaveDataTreePanel::WaveDataTreePanel() { BuildInitialTree(); }
22+
23+
void WaveDataTreePanel::HandleReloadedWaves() {
24+
BuildInitialTree();
25+
scope_for_signals_ = dynamic_cast<WaveDataTreeItem *>(data_[line_idx_])->SignalScope();
1826
}
1927

2028
void WaveDataTreePanel::UIChar(int ch) {
2129
int initial_line = line_idx_;
2230
switch (ch) {
2331
case 'S':
2432
Workspace::Get().SetMatchedSignalScope(
25-
dynamic_cast<const WaveDataTreeItem *>(data_[line_idx_])
26-
->SignalScope());
33+
dynamic_cast<const WaveDataTreeItem *>(data_[line_idx_])->SignalScope());
2734
break;
2835
default: TreePanel::UIChar(ch);
2936
}
3037
// If the selection moved, update the signals panel
3138
if (line_idx_ != initial_line) {
32-
scope_for_signals_ =
33-
dynamic_cast<WaveDataTreeItem *>(data_[line_idx_])->SignalScope();
39+
scope_for_signals_ = dynamic_cast<WaveDataTreeItem *>(data_[line_idx_])->SignalScope();
3440
}
3541
}
3642

3743
std::vector<Tooltip> WaveDataTreePanel::Tooltips() const {
3844
return std::vector<Tooltip>{{"S", "set scope for source"}};
3945
}
4046

41-
std::optional<const WaveData::SignalScope *>
42-
WaveDataTreePanel::ScopeForSignals() {
47+
std::optional<const WaveData::SignalScope *> WaveDataTreePanel::ScopeForSignals() {
4348
if (scope_for_signals_ == nullptr) return std::nullopt;
4449
auto ptr = scope_for_signals_;
4550
scope_for_signals_ = nullptr;

src/wavedata_tree_panel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ class WaveDataTreePanel : public TreePanel {
1616
std::vector<Tooltip> Tooltips() const final;
1717
bool Searchable() const final { return true; }
1818
std::optional<const WaveData::SignalScope *> ScopeForSignals();
19+
void HandleReloadedWaves() final;
1920

2021
private:
22+
void BuildInitialTree();
2123
const WaveData::SignalScope *scope_for_signals_ = nullptr;
2224
std::vector<std::unique_ptr<WaveDataTreeItem>> roots_;
2325
};

src/waves_panel.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,19 +1220,19 @@ bool WavesPanel::Search(bool search_down) {
12201220
}
12211221
}
12221222

1223-
void WavesPanel::ReloadWaves() {
1223+
void WavesPanel::PrepareForWaveDataReload() {
12241224
// After the wave file is reloaded, the signal pointers are no longer valid.
12251225
// Save the signal hierarchical paths so they can be re-discovered.
1226-
absl::flat_hash_map<int, std::string> signal_paths;
12271226
for (int i = 0; i < items_.size(); ++i) {
12281227
if (items_[i].signal != nullptr) {
1229-
signal_paths[i] = WaveData::SignalToPath(items_[i].signal);
1228+
reload_waves_[i] = WaveData::SignalToPath(items_[i].signal);
12301229
}
12311230
}
1232-
// Do the actual reload...
1233-
Workspace::Get().Waves()->Reload();
1231+
}
1232+
1233+
void WavesPanel::HandleReloadedWaves() {
12341234
// Redo all the pointers.
1235-
for (auto &[idx, path] : signal_paths) {
1235+
for (auto &[idx, path] : reload_waves_) {
12361236
auto &item = items_[idx];
12371237
if (auto signal = wave_data_->PathToSignal(path)) {
12381238
item.signal = *signal;

src/waves_panel.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "absl/container/flat_hash_map.h"
34
#include "panel.h"
45
#include "radix.h"
56
#include "text_input.h"
@@ -26,6 +27,8 @@ class WavesPanel : public Panel {
2627
bool Searchable() const final { return true; }
2728
bool Search(bool search_down) final;
2829
std::optional<const WaveData::Signal *> SignalForSource();
30+
void PrepareForWaveDataReload() final;
31+
void HandleReloadedWaves() final;
2932

3033
private:
3134
struct ListItem {
@@ -58,7 +61,6 @@ class WavesPanel : public Panel {
5861
void AddGroup();
5962
void UpdateValues();
6063
void UpdateWaves();
61-
void ReloadWaves();
6264
void UpdateValue(ListItem *item);
6365
void UpdateWave(ListItem *item);
6466
void SnapToValue();
@@ -104,6 +106,10 @@ class WavesPanel : public Panel {
104106
int name_value_size_ = 30;
105107
// Convenience to avoid repeated workspace Get() calls.
106108
const WaveData *wave_data_;
109+
110+
// When waves are reloaded, the current wave paths are stored here as strings, so they can be
111+
// re-looked up afterwards.
112+
absl::flat_hash_map<int, std::string> reload_waves_;
107113
};
108114

109115
} // namespace sv

src/workspace.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ bool Workspace::ParseDesign(int argc, char *argv[]) {
8484
void Workspace::TryMatchDesignWithWaves() {
8585
// Don't do anything unless there are both waves and design.
8686
if (wave_data_ == nullptr || design_root_ == nullptr) return;
87+
// Reset initial to unmatched, to avoid stale pointers after wave-reload.
88+
matched_design_scope_ = nullptr;
89+
matched_signal_scope_ = nullptr;
8790
// Look for a scope with stuff in it, go 3 levels in.
8891
std::vector<const WaveData::SignalScope *> signal_scopes;
8992
for (const WaveData::SignalScope &root_scope : wave_data_->Roots()) {

0 commit comments

Comments
 (0)