Skip to content

Commit bc4745e

Browse files
author
Tom Verbeure
committed
Add context popup on vertical axis menu to autofit.
1 parent 53152c7 commit bc4745e

2 files changed

Lines changed: 45 additions & 29 deletions

File tree

src/ngscopeclient/WaveformArea.cpp

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,14 @@ void WaveformArea::RenderYAxis(ImVec2 size, map<float, float>& gridmap, float vb
27182718
OnMouseWheelYAxis(wheel);
27192719
}
27202720

2721+
if(ImGui::BeginPopupContextWindow())
2722+
{
2723+
if(ImGui::MenuItem("Autofit")){
2724+
AutofitVertical();
2725+
}
2726+
ImGui::EndPopup();
2727+
}
2728+
27212729
//Trigger level arrow(s)
27222730
RenderTriggerLevelArrows(origin, size);
27232731

@@ -2779,35 +2787,7 @@ void WaveformArea::RenderYAxis(ImVec2 size, map<float, float>& gridmap, float vb
27792787

27802788
if(ImGui::IsMouseClicked(ImGuiMouseButton_Middle))
27812789
{
2782-
//Find the min and max of all currently displayed analog channels
2783-
//TODO: do we want to not allow autoscale on instrument inputs?
2784-
float vmax = FLT_MIN;
2785-
float vmin = FLT_MAX;
2786-
bool found = false;
2787-
for(auto& c : m_displayedChannels)
2788-
{
2789-
auto data = c->GetStream().GetData();
2790-
data->PrepareForCpuAccess();
2791-
auto sdata = dynamic_cast<SparseAnalogWaveform*>(data);
2792-
auto udata = dynamic_cast<UniformAnalogWaveform*>(data);
2793-
if(!sdata && !udata)
2794-
continue;
2795-
2796-
found = true;
2797-
vmax = max(vmax, Filter::GetMaxVoltage(sdata, udata));
2798-
vmin = min(vmin, Filter::GetMinVoltage(sdata, udata));
2799-
}
2800-
2801-
if(found)
2802-
{
2803-
auto off = (vmax + vmin) / 2;
2804-
auto range = (vmax - vmin) * 1.05;
2805-
for(auto& c : m_displayedChannels)
2806-
{
2807-
c->GetStream().SetOffset(-off);
2808-
c->GetStream().SetVoltageRange(range);
2809-
}
2810-
}
2790+
AutofitVertical();
28112791
}
28122792
}
28132793
}
@@ -4420,3 +4400,37 @@ bool WaveformArea::IsStreamBeingDisplayed(StreamDescriptor target)
44204400
}
44214401
return false;
44224402
}
4403+
4404+
void WaveformArea::AutofitVertical()
4405+
{
4406+
//Find the min and max of all currently displayed analog channels
4407+
//TODO: do we want to not allow autoscale on instrument inputs?
4408+
float vmax = FLT_MIN;
4409+
float vmin = FLT_MAX;
4410+
bool found = false;
4411+
for(auto& c : m_displayedChannels)
4412+
{
4413+
auto data = c->GetStream().GetData();
4414+
data->PrepareForCpuAccess();
4415+
auto sdata = dynamic_cast<SparseAnalogWaveform*>(data);
4416+
auto udata = dynamic_cast<UniformAnalogWaveform*>(data);
4417+
if(!sdata && !udata)
4418+
continue;
4419+
4420+
found = true;
4421+
vmax = max(vmax, Filter::GetMaxVoltage(sdata, udata));
4422+
vmin = min(vmin, Filter::GetMinVoltage(sdata, udata));
4423+
}
4424+
4425+
if(found)
4426+
{
4427+
auto off = (vmax + vmin) / 2;
4428+
auto range = (vmax - vmin) * 1.05;
4429+
for(auto& c : m_displayedChannels)
4430+
{
4431+
c->GetStream().SetOffset(-off);
4432+
c->GetStream().SetVoltageRange(range);
4433+
}
4434+
}
4435+
}
4436+

src/ngscopeclient/WaveformArea.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ class WaveformArea : public SerializableObject
496496
bool IsChannelBeingDragged();
497497
StreamDescriptor GetChannelBeingDragged();
498498

499+
void AutofitVertical();
500+
499501
/**
500502
@brief Gets the WaveformGroup for this area
501503
*/

0 commit comments

Comments
 (0)