ngscopeclient 0.1-dev+51fbda87c
WaveformGroup.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ngscopeclient *
4* *
5* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
35#ifndef WaveformGroup_h
36#define WaveformGroup_h
37
38#include "WaveformArea.h"
39
44{
45public:
46 WaveformGroup(MainWindow* parent, const std::string& title);
47 virtual ~WaveformGroup();
48
49 void Clear();
50
51 bool Render();
52 void ToneMapAllWaveforms(vk::raii::CommandBuffer& cmdbuf);
53 void ReferenceWaveformTextures();
54
55 void RenderWaveformTextures(
56 vk::raii::CommandBuffer& cmdbuf,
57 std::vector<std::shared_ptr<DisplayedChannel> >& channels,
58 bool clearPersistence);
59
60 const std::string GetID()
61 { return m_title + "###" + m_id; }
62
63 const std::string GetRawID()
64 { return m_id; }
65
66 const std::string& GetTitle()
67 { return m_title; }
68
69 void AddArea(std::shared_ptr<WaveformArea>& area);
70
71 void OnZoomInHorizontal(int64_t target, float step);
72 void OnZoomOutHorizontal(int64_t target, float step);
73 void OnPanHorizontal(float step);
75 int64_t timestamp,
76 int64_t duration = 0,
77 StreamDescriptor target = StreamDescriptor(nullptr, 0));
78
80
85 { return m_xAxisUnit; }
86
90 int64_t XPositionToXAxisUnits(float pix)
91 { return m_xAxisOffset + PixelsToXAxisUnits(pix - m_xpos); }
92
96 int64_t PixelsToXAxisUnits(float pix)
97 { return pix / m_pixelsPerXUnit; }
98
102 float XAxisUnitsToPixels(int64_t t)
103 { return t * m_pixelsPerXUnit; }
104
108 float XAxisUnitsToXPosition(int64_t t)
109 { return XAxisUnitsToPixels(t - m_xAxisOffset) + m_xpos; }
110
111 float GetPixelsPerXUnit()
112 { return m_pixelsPerXUnit; }
113
114 int64_t GetXAxisOffset()
115 { return m_xAxisOffset; }
116
117 void ClearPersistence();
118
119 float GetYAxisWidth()
120 { return 6 * ImGui::GetFontSize() * ImGui::GetWindowDpiScale(); }
121
122 float GetSpacing()
123 { return ImGui::GetFrameHeightWithSpacing() - ImGui::GetFrameHeight(); }
124
126 std::vector< std::shared_ptr<WaveformArea> > GetWaveformAreas()
127 {
128 std::lock_guard<std::mutex> lock(m_areaMutex);
129 return m_areas;
130 }
131
132 //Serialization
133 bool LoadConfiguration(const YAML::Node& node);
134 YAML::Node SerializeConfiguration(IDTable& table);
135
136 bool IsDraggingTrigger()
137 { return m_dragState == DRAG_STATE_TRIGGER; }
138
139protected:
140 void RenderTimeline(float width, float height);
141 void RenderTriggerPositionArrows(ImVec2 pos, float height);
142 void RenderXAxisCursors(ImVec2 pos, ImVec2 size);
143 void RenderMarkers(ImVec2 pos, ImVec2 size);
144 void DoCursorReadouts();
145
146 void TitleHoverHelp();
147
148 float GetInBandPower(WaveformBase* wfm, Unit yunit, int64_t t1, int64_t t2);
149
151
152 enum DragState
153 {
154 DRAG_STATE_NONE,
155 DRAG_STATE_TIMELINE,
156 DRAG_STATE_X_CURSOR0,
157 DRAG_STATE_X_CURSOR1,
158 DRAG_STATE_MARKER,
159 DRAG_STATE_TRIGGER
160 };
161
162 void DoCursor(int iCursor, DragState state);
163
164 int64_t GetRoundingDivisor(int64_t width_xunits);
165 void OnMouseWheel(float delta);
166
169
171 float m_xpos;
172
174 float m_width;
175
178
181
183 std::string m_title;
184
186 std::string m_id;
187
190
192 std::vector< std::shared_ptr<WaveformArea> > m_areas;
193
194 //Mutex for controlling access to m_areas
195 std::mutex m_areaMutex;
196
198 DragState m_dragState;
199
202
205
207 std::vector<size_t> m_areasToClose;
208
211
213 std::atomic<bool> m_clearPersistence;
214
217
220
222 std::shared_ptr<Oscilloscope> m_scopeTriggerDuringDrag;
223
226
227public:
228
231 {
232 X_CURSOR_NONE,
233 X_CURSOR_SINGLE,
234 X_CURSOR_DUAL
235 } m_xAxisCursorMode;
236
239};
240
241#endif
242
Declaration of WaveformArea.
Bidirectional table mapping integer IDs in scopesession files to object pointers.
Definition: IDTable.h:49
Top level application window.
Definition: MainWindow.h:115
Data for a marker.
Definition: Marker.h:84
A single channel on an oscilloscope.
Definition: OscilloscopeChannel.h:49
Descriptor for a single stream coming off a channel.
Definition: StreamDescriptor.h:46
A unit of measurement, plus conversion to pretty-printed output.
Definition: Unit.h:57
Base class for all Waveform specializations.
Definition: Waveform.h:59
A WaveformGroup is a container for one or more WaveformArea's.
Definition: WaveformGroup.h:44
void NavigateToTimestamp(int64_t timestamp, int64_t duration=0, StreamDescriptor target=StreamDescriptor(nullptr, 0))
Scrolls the group so the specified timestamp is visible.
Definition: WaveformGroup.cpp:1325
void RenderMarkers(ImVec2 pos, ImVec2 size)
Render our markers (and the hovered-packet indicator if any)
Definition: WaveformGroup.cpp:485
CursorMode_t
Type of X axis cursor we're displaying.
Definition: WaveformGroup.h:231
float m_pixelsPerXUnit
Display scale factor.
Definition: WaveformGroup.h:177
double m_tLastMouseMove
Time of last mouse movement.
Definition: WaveformGroup.h:204
DragState m_dragState
Description of item being dragged, if any.
Definition: WaveformGroup.h:198
void ClearPersistenceOfChannel(OscilloscopeChannel *chan)
Clear saved persistence waveforms of any WaveformArea's within this group containing a stream of one ...
Definition: WaveformGroup.cpp:1266
void DoCursorReadouts()
Run the popup window with cursor values.
Definition: WaveformGroup.cpp:256
int64_t m_xAxisOffset
X axis position of the left edge of our view.
Definition: WaveformGroup.h:180
float XAxisUnitsToPixels(int64_t t)
Converts a distance measurement in X axis units to pixels.
Definition: WaveformGroup.h:102
std::vector< size_t > m_areasToClose
List of waveform areas to close next frame.
Definition: WaveformGroup.h:207
bool m_mouseOverTriggerArrow
True if mouse is over a trigger arrow.
Definition: WaveformGroup.h:216
std::string m_title
Display title of the group.
Definition: WaveformGroup.h:183
void RenderXAxisCursors(ImVec2 pos, ImVec2 size)
Render our cursors.
Definition: WaveformGroup.cpp:651
std::shared_ptr< Oscilloscope > m_scopeTriggerDuringDrag
The scope whose trigger being dragged when in DRAG_STATE_TRIGGER.
Definition: WaveformGroup.h:222
float m_width
Width of the window (used for autoscaling)
Definition: WaveformGroup.h:174
float GetInBandPower(WaveformBase *wfm, Unit yunit, int64_t t1, int64_t t2)
Calculates the in-band power between two frequencies.
Definition: WaveformGroup.cpp:439
void ToneMapAllWaveforms(vk::raii::CommandBuffer &cmdbuf)
Run the tone-mapping shader on all of our waveforms.
Definition: WaveformGroup.cpp:113
int64_t PixelsToXAxisUnits(float pix)
Converts a distance measurement in pixels to X axis units.
Definition: WaveformGroup.h:96
bool m_mouseOverMarker
True if mouse is over a marker.
Definition: WaveformGroup.h:219
bool m_displayingEye
True if we're displaying an eye pattern (fixed x axis scale)
Definition: WaveformGroup.h:225
std::vector< std::shared_ptr< WaveformArea > > GetWaveformAreas()
Gets an atomic snapshot of the waveform areas in this group.
Definition: WaveformGroup.h:126
float m_timelineHeight
Height of the timeline.
Definition: WaveformGroup.h:210
void ClearPersistence()
Clear saved persistence waveforms.
Definition: WaveformGroup.cpp:1255
std::vector< std::shared_ptr< WaveformArea > > m_areas
The set of waveform areas within this group.
Definition: WaveformGroup.h:192
int64_t GetRoundingDivisor(int64_t width_xunits)
Decide on reasonable rounding intervals for X axis scale ticks.
Definition: WaveformGroup.cpp:1213
std::atomic< bool > m_clearPersistence
True if clearing persistence.
Definition: WaveformGroup.h:213
void OnMouseWheel(float delta)
Handles a mouse wheel scroll step.
Definition: WaveformGroup.cpp:1187
void RenderTriggerPositionArrows(ImVec2 pos, float height)
Draws an arrow for each scope's trigger position.
Definition: WaveformGroup.cpp:1064
int64_t XPositionToXAxisUnits(float pix)
Converts a position in pixels (relative to left side of plot) to X axis units (relative to time zero)
Definition: WaveformGroup.h:90
Unit m_xAxisUnit
X axis unit.
Definition: WaveformGroup.h:189
float XAxisUnitsToXPosition(int64_t t)
Converts a position in X axis units to pixels (in window coordinates)
Definition: WaveformGroup.h:108
Unit GetXAxisUnit()
Gets the X axis unit for this group.
Definition: WaveformGroup.h:84
std::string m_id
Internal ImGui ID of the group.
Definition: WaveformGroup.h:186
int64_t m_xAxisCursorPositions[2]
Position (in X axis units) of each cursor.
Definition: WaveformGroup.h:238
MainWindow * m_parent
Top level window we're attached to.
Definition: WaveformGroup.h:168
float m_xpos
X position of our child windows.
Definition: WaveformGroup.h:171
bool IsMouseOverButtonInWaveformArea()
Returns true if the mouse is over a channel button or similar UI element in a WaveformArea.
Definition: WaveformGroup.cpp:637
Marker * m_dragMarker
Marker being dragged, if any.
Definition: WaveformGroup.h:201
void OnZoomInHorizontal(int64_t target, float step)
Zoom in, keeping timestamp "target" at the same pixel position.
Definition: WaveformGroup.cpp:1279