diff --git a/src/ngscopeclient/WaveformArea.cpp b/src/ngscopeclient/WaveformArea.cpp index 5c93203e..54069b60 100644 --- a/src/ngscopeclient/WaveformArea.cpp +++ b/src/ngscopeclient/WaveformArea.cpp @@ -2718,6 +2718,14 @@ void WaveformArea::RenderYAxis(ImVec2 size, map& gridmap, float vb OnMouseWheelYAxis(wheel); } + if(ImGui::BeginPopupContextWindow()) + { + if(ImGui::MenuItem("Autofit")){ + AutofitVertical(); + } + ImGui::EndPopup(); + } + //Trigger level arrow(s) RenderTriggerLevelArrows(origin, size); @@ -2779,35 +2787,7 @@ void WaveformArea::RenderYAxis(ImVec2 size, map& 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(data); - auto udata = dynamic_cast(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(); } } } @@ -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(data); + auto udata = dynamic_cast(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); + } + } +} + diff --git a/src/ngscopeclient/WaveformArea.h b/src/ngscopeclient/WaveformArea.h index d5861585..963114d7 100644 --- a/src/ngscopeclient/WaveformArea.h +++ b/src/ngscopeclient/WaveformArea.h @@ -496,6 +496,8 @@ class WaveformArea : public SerializableObject bool IsChannelBeingDragged(); StreamDescriptor GetChannelBeingDragged(); + void AutofitVertical(); + /** @brief Gets the WaveformGroup for this area */