Skip to content

Commit

Permalink
WaveformArea: implemented secondary trigger level arrow. Fixes #658.
Browse files Browse the repository at this point in the history
  • Loading branch information
azonenberg committed Dec 6, 2023
1 parent 7d7558f commit 97592c3
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib
91 changes: 86 additions & 5 deletions src/ngscopeclient/WaveformArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2576,13 +2576,41 @@ void WaveformArea::RenderTriggerLevelArrows(ImVec2 start, ImVec2 /*size*/)
}
}

//TODO: second level
//Second level
auto sl = dynamic_cast<TwoLevelTrigger*>(trig);
if(sl)
LogWarning("Two-level triggers not implemented\n");
{
//Draw the arrow
//If currently dragging, show at mouse position rather than actual hardware trigger level
level = sl->GetLowerBound();
y = YAxisUnitsToYPosition(level);
if( (m_dragState == DRAG_STATE_TRIGGER_SECONDARY_LEVEL) && (trig == m_triggerDuringDrag) )
y = mouse.y;
arrowtop = y - arrowsize/2;
arrowbot = y + arrowsize/2;
draw_list->AddTriangleFilled(
ImVec2(start.x, y), ImVec2(arrowright, arrowtop), ImVec2(arrowright, arrowbot), color);

//Check mouse position
//Use slightly expanded hitbox to make it easier to capture
caparrowtop = y - caparrowsize/2;
caparrowbot = y + caparrowsize/2;
if( (mouse.x >= start.x) && (mouse.x <= caparrowright) && (mouse.y >= caparrowtop) && (mouse.y <= caparrowbot) )
{
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS);
m_mouseOverTriggerArrow = true;

if(ImGui::IsMouseClicked(ImGuiMouseButton_Left))
{
LogTrace("Start dragging secondary trigger level\n");
m_dragState = DRAG_STATE_TRIGGER_SECONDARY_LEVEL;
m_triggerDuringDrag = trig;
}
}
}

//Handle dragging
if(m_dragState == DRAG_STATE_TRIGGER_LEVEL)
if( (m_dragState == DRAG_STATE_TRIGGER_LEVEL) || (m_dragState == DRAG_STATE_TRIGGER_SECONDARY_LEVEL) )
m_triggerLevelDuringDrag = YPositionToYAxisUnits(mouse.y);
}
}
Expand Down Expand Up @@ -3354,8 +3382,61 @@ void WaveformArea::OnMouseUp()
Unit volts(Unit::UNIT_VOLTS);
LogTrace("End dragging trigger level (at %s)\n", volts.PrettyPrint(m_triggerLevelDuringDrag).c_str());

m_triggerDuringDrag->SetLevel(m_triggerLevelDuringDrag);
m_triggerDuringDrag->GetScope()->PushTrigger();
//If two-level trigger, make sure we have the levels in the right order
auto tlt = dynamic_cast<TwoLevelTrigger*>(m_triggerDuringDrag);
if(tlt)
{
//We're dragging the primary level, which should always be higher than the secondary
auto sec = tlt->GetLowerBound();
if(m_triggerLevelDuringDrag >= sec)
{
tlt->SetUpperBound(m_triggerLevelDuringDrag);
tlt->GetScope()->PushTrigger();
}

//But if we dragged past the secondary level, invert (otherwise we'll never trigger)
else
{
tlt->SetUpperBound(sec);
tlt->SetLowerBound(m_triggerLevelDuringDrag);
tlt->GetScope()->PushTrigger();
}
}

else
{
m_triggerDuringDrag->SetLevel(m_triggerLevelDuringDrag);
m_triggerDuringDrag->GetScope()->PushTrigger();
}
}
break;

case DRAG_STATE_TRIGGER_SECONDARY_LEVEL:
{
Unit volts(Unit::UNIT_VOLTS);
LogTrace("End dragging secondary trigger level (at %s)\n",
volts.PrettyPrint(m_triggerLevelDuringDrag).c_str());

//If two-level trigger, make sure we have the levels in the right order
auto tlt = dynamic_cast<TwoLevelTrigger*>(m_triggerDuringDrag);
if(tlt)
{
//We're dragging the secondary level, which should always be lower than the secondary
auto prim = tlt->GetUpperBound();
if(m_triggerLevelDuringDrag < prim)
{
tlt->SetLowerBound(m_triggerLevelDuringDrag);
tlt->GetScope()->PushTrigger();
}

//But if we dragged past the secondary level, invert (otherwise we'll never trigger)
else
{
tlt->SetUpperBound(m_triggerLevelDuringDrag);
tlt->SetLowerBound(prim);
tlt->GetScope()->PushTrigger();
}
}
}
break;

Expand Down
1 change: 1 addition & 0 deletions src/ngscopeclient/WaveformArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ class WaveformArea
DRAG_STATE_CHANNEL_LAST,
DRAG_STATE_Y_AXIS,
DRAG_STATE_TRIGGER_LEVEL,
DRAG_STATE_TRIGGER_SECONDARY_LEVEL,
DRAG_STATE_BER_LEVEL,
DRAG_STATE_BER_BOTH,
DRAG_STATE_PEAK_MARKER
Expand Down

0 comments on commit 97592c3

Please sign in to comment.