Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 43 additions & 29 deletions src/ngscopeclient/WaveformArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,14 @@ void WaveformArea::RenderYAxis(ImVec2 size, map<float, float>& gridmap, float vb
OnMouseWheelYAxis(wheel);
}

if(ImGui::BeginPopupContextWindow())
{
if(ImGui::MenuItem("Autofit")){
AutofitVertical();
}
ImGui::EndPopup();
}

//Trigger level arrow(s)
RenderTriggerLevelArrows(origin, size);

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

if(ImGui::IsMouseClicked(ImGuiMouseButton_Middle))
{
//Find the min and max of all currently displayed analog channels
//TODO: do we want to not allow autoscale on instrument inputs?
float vmax = FLT_MIN;
float vmin = FLT_MAX;
bool found = false;
for(auto& c : m_displayedChannels)
{
auto data = c->GetStream().GetData();
data->PrepareForCpuAccess();
auto sdata = dynamic_cast<SparseAnalogWaveform*>(data);
auto udata = dynamic_cast<UniformAnalogWaveform*>(data);
if(!sdata && !udata)
continue;

found = true;
vmax = max(vmax, Filter::GetMaxVoltage(sdata, udata));
vmin = min(vmin, Filter::GetMinVoltage(sdata, udata));
}

if(found)
{
auto off = (vmax + vmin) / 2;
auto range = (vmax - vmin) * 1.05;
for(auto& c : m_displayedChannels)
{
c->GetStream().SetOffset(-off);
c->GetStream().SetVoltageRange(range);
}
}
AutofitVertical();
}
}
}
Expand Down Expand Up @@ -4420,3 +4400,37 @@ bool WaveformArea::IsStreamBeingDisplayed(StreamDescriptor target)
}
return false;
}

void WaveformArea::AutofitVertical()
{
//Find the min and max of all currently displayed analog channels
//TODO: do we want to not allow autoscale on instrument inputs?
float vmax = FLT_MIN;
float vmin = FLT_MAX;
bool found = false;
for(auto& c : m_displayedChannels)
{
auto data = c->GetStream().GetData();
data->PrepareForCpuAccess();
auto sdata = dynamic_cast<SparseAnalogWaveform*>(data);
auto udata = dynamic_cast<UniformAnalogWaveform*>(data);
if(!sdata && !udata)
continue;

found = true;
vmax = max(vmax, Filter::GetMaxVoltage(sdata, udata));
vmin = min(vmin, Filter::GetMinVoltage(sdata, udata));
}

if(found)
{
auto off = (vmax + vmin) / 2;
auto range = (vmax - vmin) * 1.05;
for(auto& c : m_displayedChannels)
{
c->GetStream().SetOffset(-off);
c->GetStream().SetVoltageRange(range);
}
}
}

2 changes: 2 additions & 0 deletions src/ngscopeclient/WaveformArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ class WaveformArea : public SerializableObject
bool IsChannelBeingDragged();
StreamDescriptor GetChannelBeingDragged();

void AutofitVertical();

/**
@brief Gets the WaveformGroup for this area
*/
Expand Down
Loading