KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sim_plot_tab.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016-2023 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 * @author Maciej Suminski <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 3
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef __SIM_PLOT_PANEL_H
25#define __SIM_PLOT_PANEL_H
26
27#include "sim_types.h"
28#include <map>
29#include <vector>
30#include <limits>
31#include <widgets/mathplot.h>
32#include <math/util.h>
33#include <wx/colour.h>
34#include <wx/sizer.h>
35#include "sim_tab.h"
36#include "smith_math.h"
37#include "sim_plot_colors.h"
38
39class SIMULATOR_FRAME;
40class SIM_PLOT_TAB;
41class SIM_VIEW;
42class TRACE;
43
65
66
68class CURSOR : public mpInfoLayer
69{
70public:
71 CURSOR( TRACE* aTrace, SIM_PLOT_TAB* aPlotTab ) :
72 mpInfoLayer( wxRect( 0, 0, DRAG_MARGIN, DRAG_MARGIN ), wxTRANSPARENT_BRUSH ),
73 m_trace( aTrace ),
74 m_updateRequired( true ),
75 m_updateRef( false ),
76 m_coords( 0.0, 0.0 ),
77 m_window( nullptr ),
78 m_sweepIndex( 0 ),
79 m_snapToNearest( false ),
80 m_snapTargetY( 0.0 )
81 {
82 }
83
84 void Plot( wxDC& aDC, mpWindow& aWindow ) override;
85
86 void SetX( int aX )
87 {
88 m_reference.x = 0;
89 m_updateRef = true;
90 Move( wxPoint( aX, 0 ) );
91 }
92
93 void Update()
94 {
95 m_updateRequired = true;
96 }
97
98 virtual void UpdateForNewData() { SetCoordX( m_coords.x ); }
99
100 bool Inside( const wxPoint& aPoint ) const override;
101
102 void Move( wxPoint aDelta ) override;
103
104 void UpdateReference() override;
105
106 bool OnDoubleClick( const wxPoint& aPoint, mpWindow& aWindow ) override;
107
108 const wxRealPoint& GetCoords() const
109 {
110 return m_coords;
111 }
112
113 virtual void SetCoordX( double aValue );
114
115private:
116 void doSetCoordX( double aValue );
117
118protected:
119 wxString getID();
120
121protected:
125 wxRealPoint m_coords;
130
131 static constexpr int DRAG_MARGIN = 10;
132};
133
134
135class TRACE : public mpFXYVector
136{
137public:
138 TRACE( const wxString& aName, SIM_TRACE_TYPE aType ) :
139 mpFXYVector( aName ),
140 m_type( aType ),
141 m_isMultiRun( false ),
142 m_view( nullptr ),
143 m_yScaleView( nullptr )
144 {
145 SetContinuity( true );
146 ShowName( false );
147 SetName( aName );
148 }
149
150 void SetName( const wxString& aName ) override
151 {
152 for( auto& [ idx, cursor ] : m_cursors )
153 {
154 if( cursor )
155 cursor->SetName( aName );
156 }
157
158 mpFXYVector::SetName( aName );
159
160 if( m_type & SPT_AC_GAIN )
161 m_displayName = aName + _( " (gain)" );
162 else if( m_type & SPT_AC_PHASE )
163 m_displayName = aName + _( " (phase)" );
164 else
165 m_displayName = aName;
166 }
167
174 void SetData( const std::vector<double>& aX, const std::vector<double>& aY ) override
175 {
176 for( auto& [ idx, cursor ] : m_cursors )
177 {
178 if( cursor )
179 cursor->Update();
180 }
181
182 mpFXYVector::SetData( aX, aY );
183 }
184
185 const std::vector<double>& GetDataX() const { return m_xs; }
186 const std::vector<double>& GetDataY() const { return m_ys; }
187
188 bool HasCursor( int aCursorId ) { return m_cursors[ aCursorId ] != nullptr; }
189
190 void SetCursor( int aCursorId, CURSOR* aCursor ) { m_cursors[ aCursorId ] = aCursor; }
191 CURSOR* GetCursor( int aCursorId ) { return m_cursors[ aCursorId ]; }
192 std::map<int, CURSOR*>& GetCursors() { return m_cursors; }
193
194 SIM_TRACE_TYPE GetType() const { return m_type; }
195
196 void SetTraceColour( const wxColour& aColour ) { m_traceColour = aColour; }
197 wxColour GetTraceColour() const { return m_traceColour; }
198
199 void SetIsMultiRun( bool aIsMultiRun ) { m_isMultiRun = aIsMultiRun; }
200 bool IsMultiRun() const { return m_isMultiRun; }
201
202 void SetMultiRunLabels( const std::vector<wxString>& aLabels ) { m_multiRunLabels = aLabels; }
203 const std::vector<wxString>& GetMultiRunLabels() const { return m_multiRunLabels; }
204
206 SIM_VIEW* GetView() const { return m_view; }
207 void SetView( SIM_VIEW* aView ) { m_view = aView; }
208
213 void SetYScaleView( SIM_VIEW* aView ) { m_yScaleView = ( aView == m_view ) ? nullptr : aView; }
214
217 bool IsYScaleDefault() const { return m_yScaleView == nullptr; }
218
221 {
222 if( m_yScaleView == aView )
223 m_yScaleView = nullptr;
224 }
225
226protected:
227 std::map<int, CURSOR*> m_cursors; // No ownership; the mpWindow owns the CURSORs
231 std::vector<wxString> m_multiRunLabels;
232 SIM_VIEW* m_view; // No ownership; the SIM_PLOT_TAB owns the SIM_VIEWs
233 SIM_VIEW* m_yScaleView; // No ownership; nullptr means "same as m_view"
234};
235
236
238class SMITH_GRID : public mpLayer
239{
240public:
242
243 void Plot( wxDC& aDC, mpWindow& aWindow ) override;
244
245 bool HasBBox() const override { return false; }
246
248 void SetReferenceImpedance( double aZ0 ) { m_z0 = aZ0; }
249
250 void SetMixedReferences( bool aMixed ) { m_mixedReferences = aMixed; }
251
253 static bool GetChartView( mpWindow& aWindow, double aZoom, const wxRealPoint& aPan, SMITH_VIEW& aView );
254
255private:
256 double m_z0 = 0.0;
257 bool m_mixedReferences = false;
258};
259
260
262class SMITH_TRACE : public TRACE
263{
264public:
265 SMITH_TRACE( const wxString& aName, SIM_TRACE_TYPE aType ) :
266 TRACE( aName, aType )
267 {
268 }
269
270 void Plot( wxDC& aDC, mpWindow& aWindow ) override;
271
272 // drawn directly, keep the locus out of the axis auto-fit
273 bool HasBBox() const override { return false; }
274
275 void SetFrequencies( const std::vector<double>& aFreqs ) { m_frequencies = aFreqs; }
276 const std::vector<double>& GetFrequencies() const { return m_frequencies; }
277
279 void SetReferenceImpedance( double aZ0 ) { m_z0 = aZ0; }
280 double GetReferenceImpedance() const { return m_z0; }
281
282private:
283 std::vector<double> m_frequencies;
284 double m_z0 = 0.0;
285};
286
287
290class SMITH_CURSOR : public CURSOR
291{
292public:
293 SMITH_CURSOR( SMITH_TRACE* aTrace, SIM_PLOT_TAB* aPlotTab ) :
294 CURSOR( aTrace, aPlotTab ),
295 m_index( -1 ),
296 m_gamma( 0.0, 0.0 ),
297 m_requestFreq( 0.0 ),
298 m_pendingFreq( false ),
299 m_dragging( false )
300 {
301 }
302
303 void Plot( wxDC& aDC, mpWindow& aWindow ) override;
304
305 bool Inside( const wxPoint& aPoint ) const override;
306
307 void Move( wxPoint aDelta ) override;
308
309 void UpdateReference() override;
310
311 void SetCoordX( double aValue ) override;
312
313 void UpdateForNewData() override;
314
315 const wxRealPoint& GetGamma() const { return m_gamma; }
316
317private:
318 void snapToIndex( int aIndex );
319 void snapToFrequency( double aFreq );
320
321private:
323 wxRealPoint m_gamma;
325 bool m_pendingFreq; // a saved frequency waiting for the sim data to load
326 bool m_dragging; // the pending update comes from a drag, not a data refresh
327};
328
329
332{
333 wxString vectorName;
334 wxString displayName;
336};
337
338
341{
342 int id;
343 wxString vectorName;
345 int subType; // the SP subtype bit the cursor lived on before Smith mode
346 double frequency;
347};
348
349
356class SIM_VIEW : public mpWindow
357{
358public:
359 SIM_VIEW( SIM_PLOT_TAB* aPlotTab, wxWindow* aParent );
360
362 void OnXViewChanged() override;
363
365 void SetXRange( double aPos, double aDesiredMax, double aDesiredMin )
366 {
367 SetXView( aPos, aDesiredMax, aDesiredMin );
368 }
369
370 SIM_PLOT_TAB* GetPlotTab() const { return m_plotTab; }
371
372 wxString GetLabelX() const { return m_axis_x ? m_axis_x->GetName() : wxString( wxS( "" ) ); }
373
374 wxString GetLabelY1() const { return m_axis_y1 ? m_axis_y1->GetName() : wxString( wxS( "" ) ); }
375
376 wxString GetLabelY2() const { return m_axis_y2 ? m_axis_y2->GetName() : wxString( wxS( "" ) ); }
377
378 wxString GetLabelY3() const { return m_axis_y3 ? m_axis_y3->GetName() : wxString( wxS( "" ) ); }
379
380 bool GetY1Scale( double* aMin, double* aMax ) const
381 {
382 if( m_axis_y1 )
383 return m_axis_y1->GetAxisMinMax( aMin, aMax );
384
385 return false;
386 }
387
388 bool GetY2Scale( double* aMin, double* aMax ) const
389 {
390 if( m_axis_y2 )
391 return m_axis_y2->GetAxisMinMax( aMin, aMax );
392
393 return false;
394 }
395
396 bool GetY3Scale( double* aMin, double* aMax ) const
397 {
398 if( m_axis_y3 )
399 return m_axis_y3->GetAxisMinMax( aMin, aMax );
400
401 return false;
402 }
403
404 void SetY1Scale( bool aLock, double aMin, double aMax );
405 void SetY2Scale( bool aLock, double aMin, double aMax );
406 void SetY3Scale( bool aLock, double aMin, double aMax );
407
408 wxString GetUnitsX() const;
409 wxString GetUnitsY1() const;
410 wxString GetUnitsY2() const;
411 wxString GetUnitsY3() const;
412
414 wxString GetUnitsForTrace( TRACE* aTrace ) const;
415
417 int GetAxisSlot( TRACE* aTrace ) const;
418
420 mpScaleY* GetAxisBySlot( int aSlot ) const;
421
422 void ShowGrid( bool aEnable )
423 {
424 if( m_axis_x )
425 m_axis_x->SetTicks( !aEnable );
426
427 if( m_axis_y1 )
428 m_axis_y1->SetTicks( !aEnable );
429
430 if( m_axis_y2 )
431 m_axis_y2->SetTicks( !aEnable );
432
433 if( m_axis_y3 )
434 m_axis_y3->SetTicks( !aEnable );
435
436 UpdateAll();
437 }
438
439 bool IsGridShown() const
440 {
441 if( !m_axis_x || !m_axis_y1 )
442 return false;
443
444 return !m_axis_x->GetTicks();
445 }
446
447 void ShowLegend( bool aEnable )
448 {
449 m_legend->SetVisible( aEnable );
450 UpdateAll();
451 }
452
453 bool IsLegendShown() const { return m_legend->IsVisible(); }
454
455 wxPoint GetLegendPosition() const { return m_legend->GetPosition(); }
456
457 void SetLegendPosition( const wxPoint& aPosition )
458 {
459 m_legend->Move( aPosition );
460 m_legend->UpdateReference();
461 m_lastLegendPosition = aPosition;
462 }
463
465 void ResetScales( bool aIncludeX );
466
468 void updateAxes( int aNewTraceType = SIM_TRACE_TYPE::SPT_UNKNOWN );
469
471
473
474 // ---- Smith chart --------------------------------------------------------------------
475
478 void SetSmithChart( bool aEnable );
479
480 bool IsSmithChart() const { return m_smithChart; }
481
484
487
488 double GetSmithZoom() const { return m_smithZoom; }
489 const wxRealPoint& GetSmithPan() const { return m_smithPan; }
490
492 {
493 m_smithZoom = 1.0;
494 m_smithPan = wxRealPoint( 0.0, 0.0 );
495 }
496
497 void SetSmithView( double aZoom, double aPanX, double aPanY )
498 {
499 m_smithZoom = std::isfinite( aZoom ) ? std::clamp( aZoom, 1.0, 50.0 ) : 1.0;
500 m_smithPan.x = std::isfinite( aPanX ) ? std::clamp( aPanX, -100.0, 100.0 ) : 0.0;
501 m_smithPan.y = std::isfinite( aPanY ) ? std::clamp( aPanY, -100.0, 100.0 ) : 0.0;
502 }
503
504 void SmithZoomAt( const wxPoint& aPos, double aFactor );
505 void SmithPanBy( const wxPoint& aDelta );
506
507public:
509
515
516private:
518 void prepareDCAxes( int aNewTraceType );
519
520 void onSmithMouseWheel( wxMouseEvent& aEvent );
521 void onSmithMagnify( wxMouseEvent& aEvent );
522 void onSmithMiddleDown( wxMouseEvent& aEvent );
523 void onSmithLeftDown( wxMouseEvent& aEvent );
524 void onSmithMotion( wxMouseEvent& aEvent );
525 void onSmithLeftUp( wxMouseEvent& aEvent );
526 void onSmithDClick( wxMouseEvent& aEvent );
527 void onSmithRightDown( wxMouseEvent& aEvent );
528 void onSmithRightUp( wxMouseEvent& aEvent );
529 void onSmithMenuCommand( wxCommandEvent& aEvent );
530
531 bool getSmithView( SMITH_VIEW& aView ) const;
532
533private:
535
537
540 wxRealPoint m_smithPan;
545};
546
547
548class SIM_PLOT_TAB : public SIM_TAB
549{
550public:
551 SIM_PLOT_TAB( const wxString& aSimCommand, wxWindow* parent );
552
553 virtual ~SIM_PLOT_TAB();
554
555 void ApplyPreferences( const SIM_PREFERENCES& aPrefs ) override;
556
557 // ---- View management ----------------------------------------------------------------
558
559 const std::vector<SIM_VIEW*>& GetViews() const { return m_views; }
560
561 SIM_VIEW* GetView( int aIndex ) const
562 {
563 return ( aIndex >= 0 && aIndex < (int) m_views.size() ) ? m_views[aIndex] : nullptr;
564 }
565
566 int GetViewIndex( SIM_VIEW* aView ) const;
567
568 int GetViewCount() const { return (int) m_views.size(); }
569
571 SIM_VIEW* GetDefaultView() const { return m_views.empty() ? nullptr : m_views[0]; }
572
574 SIM_VIEW* AddView();
575
578 bool RemoveView( SIM_VIEW* aView );
579
581 void SyncXView( SIM_VIEW* aSource );
582
583 // ---- Tab-wide accessors (identical across views; delegate to the default view) -------
584
585 wxString GetLabelX() const;
586 wxString GetUnitsX() const;
587
589 wxString GetUnitsForTrace( TRACE* aTrace ) const;
590
591 // ---- Settings shared/fanned out across all views --------------------------------------
592
593 void ShowGrid( bool aEnable );
594 bool IsGridShown() const;
595
596 void ShowLegend( bool aEnable );
597 bool IsLegendShown() const;
598 wxPoint GetLegendPosition() const;
599 void SetLegendPosition( const wxPoint& aPosition );
600
601 // ---- Default-view convenience (used by the Analysis Properties dialog) ----------------
602
603 wxString GetLabelY1() const;
604 wxString GetLabelY2() const;
605 wxString GetLabelY3() const;
606 wxString GetUnitsY1() const;
607 wxString GetUnitsY2() const;
608 wxString GetUnitsY3() const;
609
610 bool GetY1Scale( double* aMin, double* aMax ) const;
611 bool GetY2Scale( double* aMin, double* aMax ) const;
612 bool GetY3Scale( double* aMin, double* aMax ) const;
613 void SetY1Scale( bool aLock, double aMin, double aMax );
614 void SetY2Scale( bool aLock, double aMin, double aMax );
615 void SetY3Scale( bool aLock, double aMin, double aMax );
616
618
622 void SetDottedSecondary( bool aEnable )
623 {
624 m_dotted_cp = aEnable;
625
626 for( const auto& [name, trace] : m_traces )
627 UpdateTraceStyle( trace );
628
629 for( SIM_VIEW* view : m_views )
630 view->UpdateAll();
631 }
632
633 bool GetDottedSecondary() const { return m_dotted_cp; }
634
636 void SetSmithMode( bool aEnable );
637 bool IsSmithMode() const { return m_smithMode; }
638
641
643 double GetSmithZoom() const;
644 wxRealPoint GetSmithPan() const;
645
646 void ResetSmithView();
647
649 void SetSmithView( double aZoom, double aPanX, double aPanY );
650
651 void SmithZoomAt( const wxPoint& aPos, double aFactor );
652 void SmithPanBy( const wxPoint& aDelta );
653
655 std::vector<SMITH_STASHED_TRACE>& SmithStashedTraces() { return m_smithStashedTraces; }
656 std::vector<SMITH_STASHED_CURSOR>& SmithStashedCursors() { return m_smithStashedCursors; }
657
659 void EnableCursor( TRACE* aTrace, int aCursorId, const wxString& aSignalName );
660 void DisableCursor( TRACE* aTrace, int aCursorId );
661
663 void ResetScales( bool aIncludeX );
664
666 void UpdateTraceStyle( TRACE* trace );
667
669 void UpdatePlotColors();
670
671 wxColour GetPlotColor( SIM_PLOT_COLORS::COLOR_SET aColorId ) { return m_colors.GetPlotColor( aColorId ); }
672
673 void OnLanguageChanged() override;
674
676 mpWindow* GetPlotWin() const;
677
681 TRACE* GetOrAddTrace( const wxString& aVectorName, int aType, SIM_VIEW* aView );
682
683 void SetTraceData( TRACE* aTrace, std::vector<double>& aX, std::vector<double>& aY, int aSweepCount,
684 size_t aSweepSize, bool aIsMultiRun = false, const std::vector<wxString>& aMultiRunLabels = {} );
685
686 bool DeleteTrace( const wxString& aVectorName, int aTraceType );
687 void DeleteTrace( TRACE* aTrace );
688
689 const std::map<wxString, TRACE*>& GetTraces() const { return m_traces; }
690
691 TRACE* GetTrace( const wxString& aVecName, int aType ) const
692 {
693 auto trace = m_traces.find( getTraceId( aVecName, aType ) );
694
695 return trace == m_traces.end() ? nullptr : trace->second;
696 }
697
698 std::vector<std::pair<wxString, wxString>>& Measurements() { return m_measurements; }
699
700public:
702
703private:
705 {
706 static_assert( static_cast<unsigned>( mpWindow::MouseWheelAction::COUNT )
707 == static_cast<unsigned>( SIM_MOUSE_WHEEL_ACTION::COUNT ),
708 "mpWindow::MouseWheelAction enum must match SIM_MOUSE_WHEEL_ACTION" );
709
712 m.verticalUnmodified = static_cast<A>( s.vertical_unmodified );
713 m.verticalWithCtrl = static_cast<A>( s.vertical_with_ctrl );
714 m.verticalWithShift = static_cast<A>( s.vertical_with_shift );
715 m.verticalWithAlt = static_cast<A>( s.vertical_with_alt );
716 m.horizontal = static_cast<A>( s.horizontal );
717
718 return m;
719 }
720
721 wxString getTraceId( const wxString& aVectorName, int aType ) const
722 {
723 return wxString::Format( wxS( "%s%d" ), aVectorName, aType & SPT_Y_AXIS_MASK );
724 }
725
726private:
728 std::map<wxString, wxColour> m_sessionTraceColors;
729
730 wxBoxSizer* m_viewsSizer; // Holds all the stacked SIM_VIEWs
731
732 // Stacked plot views (owned via wx parent-child, except when explicitly removed)
733 std::vector<SIM_VIEW*> m_views;
734
735 // Cached so newly-added views can be initialized with the current preferences
737
738 // Traces to be plotted; each knows which view (if any) it's currently plotted on
739 std::map<wxString, TRACE*> m_traces;
740
742
743 // Re-entrancy guard for SyncXView()
745
746 // Smith-chart mode is a property of the whole tab; each SIM_VIEW carries its own grid
747 // layer and pan/zoom state.
749
750 std::vector<SMITH_STASHED_TRACE> m_smithStashedTraces;
751 std::vector<SMITH_STASHED_CURSOR> m_smithStashedCursors;
752
753 // Measurements (and their format strings)
754 std::vector<std::pair<wxString, wxString>> m_measurements;
755};
756
757wxDECLARE_EVENT( EVT_SIM_CURSOR_UPDATE, wxCommandEvent );
758
761wxDECLARE_EVENT( EVT_SIM_VIEWS_CHANGED, wxCommandEvent );
762
763#endif
const char * name
The SIMULATOR_FRAME holds the main user-interface for running simulations.
CURSOR(TRACE *aTrace, SIM_PLOT_TAB *aPlotTab)
mpWindow * m_window
const wxRealPoint & GetCoords() const
void Move(wxPoint aDelta) override
Moves the layer rectangle of given pixel deltas.
void SetX(int aX)
wxString getID()
wxRealPoint m_coords
bool m_updateRef
static constexpr int DRAG_MARGIN
bool Inside(const wxPoint &aPoint) const override
Checks whether a point is inside the info box rectangle.
void doSetCoordX(double aValue)
int m_sweepIndex
virtual void UpdateForNewData()
bool OnDoubleClick(const wxPoint &aPoint, mpWindow &aWindow) override
virtual void SetCoordX(double aValue)
void UpdateReference() override
Updates the rectangle reference point.
bool m_updateRequired
double m_snapTargetY
TRACE * m_trace
void Plot(wxDC &aDC, mpWindow &aWindow) override
Plot method.
bool m_snapToNearest
void Update()
The SIMULATOR_FRAME holds the main user-interface for running simulations.
bool DeleteTrace(const wxString &aVectorName, int aTraceType)
int GetViewCount() const
double GetSmithZoom() const
The saved/restored pan and zoom track the default view.
void UpdateSmithReferenceImpedance()
Refresh the grid z0 from the shown Smith traces, on every view.
wxString GetLabelY1() const
mpWindow * GetPlotWin() const
Getter for the default view's math plot window (back-compat for zoom undo/redo, export).
void SetSmithView(double aZoom, double aPanX, double aPanY)
Restore a saved view, values are validated and clamped.
SIM_VIEW * GetView(int aIndex) const
void ShowGrid(bool aEnable)
void SetTraceData(TRACE *aTrace, std::vector< double > &aX, std::vector< double > &aY, int aSweepCount, size_t aSweepSize, bool aIsMultiRun=false, const std::vector< wxString > &aMultiRunLabels={})
void SyncXView(SIM_VIEW *aSource)
Mirror aSource's current X range onto every other view of this tab.
const std::vector< SIM_VIEW * > & GetViews() const
wxString GetUnitsY2() const
void SetY2Scale(bool aLock, double aMin, double aMax)
void SmithZoomAt(const wxPoint &aPos, double aFactor)
TRACE * GetTrace(const wxString &aVecName, int aType) const
std::vector< SMITH_STASHED_CURSOR > m_smithStashedCursors
void SetSmithMode(bool aEnable)
Smith mode is tab-wide: every view of the tab shows a Smith chart while it is on.
virtual ~SIM_PLOT_TAB()
wxString GetLabelX() const
bool IsGridShown() const
wxRealPoint GetSmithPan() const
const std::map< wxString, TRACE * > & GetTraces() const
wxString GetLabelY3() const
void SetY1Scale(bool aLock, double aMin, double aMax)
bool GetDottedSecondary() const
wxPoint GetLegendPosition() const
std::vector< std::pair< wxString, wxString > > m_measurements
void SetY3Scale(bool aLock, double aMin, double aMax)
std::map< wxString, TRACE * > m_traces
bool IsLegendShown() const
SIM_VIEW * GetDefaultView() const
The view new traces default to, and legacy (single-view) settings apply to.
SIM_VIEW * AddView()
Add a new (empty) view, stacked below the existing ones.
std::vector< SMITH_STASHED_TRACE > m_smithStashedTraces
std::vector< std::pair< wxString, wxString > > & Measurements()
wxString GetUnitsForTrace(TRACE *aTrace) const
Get the display units (e.g. "V", "A", "dB") for a given trace's own view.
SIM_PLOT_COLORS m_colors
void UpdateTraceStyle(TRACE *trace)
Update trace line style.
void SetLegendPosition(const wxPoint &aPosition)
TRACE * GetOrAddTrace(const wxString &aVectorName, int aType, SIM_VIEW *aView)
Get (or create, on aView) the TRACE for a signal.
void ResetScales(bool aIncludeX)
Reset scale ranges to fit the current traces, on every view.
void UpdatePlotColors()
Update plot colors.
std::vector< SMITH_STASHED_TRACE > & SmithStashedTraces()
Traces and cursors set aside while in Smith mode, restored when leaving it.
void ShowLegend(bool aEnable)
bool GetY3Scale(double *aMin, double *aMax) const
SIM_PLOT_TAB(const wxString &aSimCommand, wxWindow *parent)
wxString GetLabelY2() const
void EnableCursor(TRACE *aTrace, int aCursorId, const wxString &aSignalName)
Turn on/off the cursor for a particular trace.
int GetViewIndex(SIM_VIEW *aView) const
bool IsSmithMode() const
wxString GetUnitsX() const
void OnLanguageChanged() override
void EnsureThirdYAxisExists()
wxString getTraceId(const wxString &aVectorName, int aType) const
std::vector< SMITH_STASHED_CURSOR > & SmithStashedCursors()
void SetDottedSecondary(bool aEnable)
Draw secondary signal traces (current or phase) with dotted lines.
void ApplyPreferences(const SIM_PREFERENCES &aPrefs) override
wxBoxSizer * m_viewsSizer
mpWindow::MouseWheelActionSet m_mouseWheelActions
bool RemoveView(SIM_VIEW *aView)
Remove a view.
void SmithPanBy(const wxPoint &aDelta)
std::vector< SIM_VIEW * > m_views
wxPoint m_LastLegendPosition
wxColour GetPlotColor(SIM_PLOT_COLORS::COLOR_SET aColorId)
wxString GetUnitsY1() const
std::map< wxString, wxColour > m_sessionTraceColors
static mpWindow::MouseWheelActionSet convertMouseWheelActions(const SIM_MOUSE_WHEEL_ACTION_SET &s)
void DisableCursor(TRACE *aTrace, int aCursorId)
bool GetY2Scale(double *aMin, double *aMax) const
bool GetY1Scale(double *aMin, double *aMax) const
wxString GetUnitsY3() const
SIM_TAB()
Definition sim_tab.cpp:29
A single stacked plot area within a SIM_PLOT_TAB.
wxString GetLabelY2() const
void OnXViewChanged() override
Mirrors this view's X range onto every other view of the same tab.
void updateAxes(int aNewTraceType=SIM_TRACE_TYPE::SPT_UNKNOWN)
Create/Ensure axes are available for plotting.
void SetSmithView(double aZoom, double aPanX, double aPanY)
void SmithZoomAt(const wxPoint &aPos, double aFactor)
bool GetY3Scale(double *aMin, double *aMax) const
void onSmithMenuCommand(wxCommandEvent &aEvent)
mpScaleY * m_axis_y3
wxString GetUnitsForTrace(TRACE *aTrace) const
Get the display units (e.g. "V", "A", "dB") for a given trace plotted on this view.
bool m_smithPanning
bool IsSmithChart() const
void UpdateSmithGridColor()
Re-read the Smith grid pen from the tab's color theme.
void SetY2Scale(bool aLock, double aMin, double aMax)
void EnsureThirdYAxisExists()
wxPoint m_smithMenuPos
void SmithPanBy(const wxPoint &aDelta)
mpInfoLegend * m_legend
void ResetSmithView()
void onSmithDClick(wxMouseEvent &aEvent)
wxString GetLabelX() const
bool m_smithLeftSkipped
void ShowGrid(bool aEnable)
wxPoint m_lastLegendPosition
wxString GetLabelY3() const
wxString GetUnitsY3() const
wxPoint GetLegendPosition() const
void onSmithMagnify(wxMouseEvent &aEvent)
void SetY1Scale(bool aLock, double aMin, double aMax)
const wxRealPoint & GetSmithPan() const
void SetY3Scale(bool aLock, double aMin, double aMax)
void onSmithMiddleDown(wxMouseEvent &aEvent)
void onSmithRightDown(wxMouseEvent &aEvent)
SIM_VIEW(SIM_PLOT_TAB *aPlotTab, wxWindow *aParent)
void SetLegendPosition(const wxPoint &aPosition)
bool IsLegendShown() const
mpScaleY * GetAxisBySlot(int aSlot) const
Get the Y-axis scale object for a given slot (1, 2 or 3), or nullptr if not created yet.
double GetSmithZoom() const
bool getSmithView(SMITH_VIEW &aView) const
bool GetY2Scale(double *aMin, double *aMax) const
SIM_PLOT_TAB * GetPlotTab() const
bool GetY1Scale(double *aMin, double *aMax) const
void onSmithLeftUp(wxMouseEvent &aEvent)
void SetXRange(double aPos, double aDesiredMax, double aDesiredMin)
Directly set this view's X range (used to mirror another view's zoom/pan onto this one).
wxString GetLabelY1() const
void UpdateSmithReferenceImpedance()
Refresh the grid z0 from the Smith traces shown on this view.
mpScaleY * m_axis_y2
SMITH_GRID * m_smithGrid
void onSmithLeftDown(wxMouseEvent &aEvent)
void ResetScales(bool aIncludeX)
Reset the Y (and, if requested, X) scale ranges to fit this view's own traces.
mpScaleXBase * m_axis_x
int GetAxisSlot(TRACE *aTrace) const
Get the Y-axis slot (1, 2 or 3) a trace of this type is plotted on.
SIM_PLOT_TAB * m_plotTab
mpScaleY * m_axis_y1
void ShowLegend(bool aEnable)
wxString GetUnitsX() const
void onSmithRightUp(wxMouseEvent &aEvent)
void SetSmithChart(bool aEnable)
Show/hide this view's Smith chart overlay.
bool m_smithChart
void UpdateAxisVisibility()
void onSmithMotion(wxMouseEvent &aEvent)
wxString GetUnitsY2() const
wxPoint m_smithPanLast
wxString GetUnitsY1() const
void onSmithMouseWheel(wxMouseEvent &aEvent)
double m_smithZoom
bool IsGridShown() const
wxRealPoint m_smithPan
void prepareDCAxes(int aNewTraceType)
Construct the plot axes for DC simulation plot.
void UpdateReference() override
Updates the rectangle reference point.
void Plot(wxDC &aDC, mpWindow &aWindow) override
Plot method.
bool Inside(const wxPoint &aPoint) const override
Checks whether a point is inside the info box rectangle.
void SetCoordX(double aValue) override
double m_requestFreq
void snapToIndex(int aIndex)
void snapToFrequency(double aFreq)
const wxRealPoint & GetGamma() const
void UpdateForNewData() override
wxRealPoint m_gamma
SMITH_CURSOR(SMITH_TRACE *aTrace, SIM_PLOT_TAB *aPlotTab)
void Move(wxPoint aDelta) override
Moves the layer rectangle of given pixel deltas.
Overlay layer drawing the Smith chart grid (constant resistance and reactance circles)
static bool GetChartView(mpWindow &aWindow, double aZoom, const wxRealPoint &aPan, SMITH_VIEW &aView)
Chart placement including pan/zoom.
void Plot(wxDC &aDC, mpWindow &aWindow) override
Plot given view of layer to the given device context.
void SetMixedReferences(bool aMixed)
void SetReferenceImpedance(double aZ0)
Zero when no single reference applies, which labels the grid normalized.
bool HasBBox() const override
Check whether this layer has a bounding box.
bool m_mixedReferences
Reflection coefficient locus, Re in X and Im in Y, drawn on the Smith chart.
void Plot(wxDC &aDC, mpWindow &aWindow) override
Layer plot handler.
bool HasBBox() const override
Check whether this layer has a bounding box.
void SetReferenceImpedance(double aZ0)
Zero until the response port resolves one, which leaves only normalized values readable.
SMITH_TRACE(const wxString &aName, SIM_TRACE_TYPE aType)
const std::vector< double > & GetFrequencies() const
void SetFrequencies(const std::vector< double > &aFreqs)
std::vector< double > m_frequencies
double GetReferenceImpedance() const
SIM_VIEW * m_yScaleView
std::vector< wxString > m_multiRunLabels
bool IsYScaleDefault() const
True if this trace's Y-axis scale hasn't been explicitly linked to another view (i....
void SetIsMultiRun(bool aIsMultiRun)
void SetTraceColour(const wxColour &aColour)
void SetName(const wxString &aName) override
Set layer name.
wxColour m_traceColour
void SetMultiRunLabels(const std::vector< wxString > &aLabels)
std::map< int, CURSOR * > & GetCursors()
SIM_TRACE_TYPE m_type
SIM_VIEW * GetView() const
The SIM_VIEW this trace is currently plotted on (nullptr if not plotted anywhere).
void SetView(SIM_VIEW *aView)
SIM_TRACE_TYPE GetType() const
SIM_VIEW * m_view
std::map< int, CURSOR * > m_cursors
bool HasCursor(int aCursorId)
bool m_isMultiRun
TRACE(const wxString &aName, SIM_TRACE_TYPE aType)
void SetData(const std::vector< double > &aX, const std::vector< double > &aY) override
Assigns new data set for the trace.
const std::vector< wxString > & GetMultiRunLabels() const
void SetCursor(int aCursorId, CURSOR *aCursor)
SIM_VIEW * GetYScaleView() const
The view whose Y-axis scale this trace's axis should match (defaults to its own view).
bool IsMultiRun() const
void ClearYScaleViewIf(SIM_VIEW *aView)
Clears an explicit Y-scale link if it pointed at a view that no longer exists.
const std::vector< double > & GetDataY() const
wxColour GetTraceColour() const
const std::vector< double > & GetDataX() const
CURSOR * GetCursor(int aCursorId)
void SetYScaleView(SIM_VIEW *aView)
mpFXYVector(const wxString &name=wxEmptyString, int flags=mpALIGN_NE)
std::vector< double > m_ys
Definition mathplot.h:1525
std::vector< double > m_xs
The internal copy of the set of data to draw.
Definition mathplot.h:1525
virtual void SetData(const std::vector< double > &xs, const std::vector< double > &ys)
Changes the internal data: the set of points to draw.
wxPoint m_reference
Definition mathplot.h:417
mpInfoLayer()
Default constructor.
Definition mathplot.cpp:105
Implements the legend to be added to the plot This layer allows you to add a legend to describe the p...
Definition mathplot.h:430
void SetContinuity(bool continuity)
Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points...
Definition mathplot.h:292
void ShowName(bool show)
Shows or hides the text label with the name of the layer (default is visible).
Definition mathplot.h:301
virtual void SetName(const wxString &name)
Set layer name.
Definition mathplot.h:306
mpLayerType m_type
Define layer type, which is assigned by constructor.
Definition mathplot.h:347
wxString m_displayName
Definition mathplot.h:344
Plot layer implementing a y-scale ruler.
Definition mathplot.h:886
Canvas for plotting mpLayer implementations.
Definition mathplot.h:967
MouseWheelAction
Enumerates the possible mouse wheel actions that can be performed on the plot.
Definition mathplot.h:973
void UpdateAll()
Refresh display.
virtual bool SetXView(double pos, double desiredMax, double desiredMin)
Applies new X view coordinates depending on the settings.
#define _(s)
@ mpLAYER_AXIS
Definition mathplot.h:147
Class is responsible for providing colors for traces on simulation plot.
wxDECLARE_EVENT(EVT_SIM_CURSOR_UPDATE, wxCommandEvent)
SIM_TRACE_TYPE
Possible trace types.
Definition sim_types.h:49
@ SPT_AC_PHASE
Definition sim_types.h:53
@ SPT_UNKNOWN
Definition sim_types.h:68
@ SPT_AC_GAIN
Definition sim_types.h:54
@ SPT_Y_AXIS_MASK
Definition sim_types.h:59
Contains the set of modified mouse wheel actions that can be performed on a simulator plot.
SIM_MOUSE_WHEEL_ACTION vertical_unmodified
SIM_MOUSE_WHEEL_ACTION vertical_with_alt
SIM_MOUSE_WHEEL_ACTION horizontal
SIM_MOUSE_WHEEL_ACTION vertical_with_ctrl
SIM_MOUSE_WHEEL_ACTION vertical_with_shift
Contains preferences pertaining to the simulator.
Cursor recorded when entering Smith mode, so leaving restores it to its original trace.
Trace hidden while the tab is in Smith mode, kept so leaving the mode restores it.
Smith chart placement plus pan/zoom, maps a gamma point to a screen pixel and back.
Definition smith_math.h:32
Contains the set of modified mouse wheel actions that can be performed on the plot.
Definition mathplot.h:988
MouseWheelAction horizontal
Definition mathplot.h:998
MouseWheelAction verticalWithShift
Definition mathplot.h:996
MouseWheelAction verticalWithCtrl
Definition mathplot.h:995
MouseWheelAction verticalWithAlt
Definition mathplot.h:997
MouseWheelAction verticalUnmodified
Definition mathplot.h:994