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
195 bool GetValueAtX( double aX, double* aY ) const;
196
197 bool HasCursor( int aCursorId ) { return m_cursors[ aCursorId ] != nullptr; }
198
199 void SetCursor( int aCursorId, CURSOR* aCursor ) { m_cursors[ aCursorId ] = aCursor; }
200 CURSOR* GetCursor( int aCursorId ) { return m_cursors[ aCursorId ]; }
201 std::map<int, CURSOR*>& GetCursors() { return m_cursors; }
202
203 SIM_TRACE_TYPE GetType() const { return m_type; }
204
205 void SetTraceColour( const wxColour& aColour ) { m_traceColour = aColour; }
206 wxColour GetTraceColour() const { return m_traceColour; }
207
208 void SetIsMultiRun( bool aIsMultiRun ) { m_isMultiRun = aIsMultiRun; }
209 bool IsMultiRun() const { return m_isMultiRun; }
210
211 void SetMultiRunLabels( const std::vector<wxString>& aLabels ) { m_multiRunLabels = aLabels; }
212 const std::vector<wxString>& GetMultiRunLabels() const { return m_multiRunLabels; }
213
215 SIM_VIEW* GetView() const { return m_view; }
216 void SetView( SIM_VIEW* aView ) { m_view = aView; }
217
222 void SetYScaleView( SIM_VIEW* aView ) { m_yScaleView = ( aView == m_view ) ? nullptr : aView; }
223
226 bool IsYScaleDefault() const { return m_yScaleView == nullptr; }
227
230 {
231 if( m_yScaleView == aView )
232 m_yScaleView = nullptr;
233 }
234
235protected:
236 std::map<int, CURSOR*> m_cursors; // No ownership; the mpWindow owns the CURSORs
240 std::vector<wxString> m_multiRunLabels;
241 SIM_VIEW* m_view; // No ownership; the SIM_PLOT_TAB owns the SIM_VIEWs
242 SIM_VIEW* m_yScaleView; // No ownership; nullptr means "same as m_view"
243};
244
245
247class SMITH_GRID : public mpLayer
248{
249public:
251
252 void Plot( wxDC& aDC, mpWindow& aWindow ) override;
253
254 bool HasBBox() const override { return false; }
255
257 void SetReferenceImpedance( double aZ0 ) { m_z0 = aZ0; }
258
259 void SetMixedReferences( bool aMixed ) { m_mixedReferences = aMixed; }
260
262 static bool GetChartView( mpWindow& aWindow, double aZoom, const wxRealPoint& aPan, SMITH_VIEW& aView );
263
264private:
265 double m_z0 = 0.0;
266 bool m_mixedReferences = false;
267};
268
269
271class SMITH_TRACE : public TRACE
272{
273public:
274 SMITH_TRACE( const wxString& aName, SIM_TRACE_TYPE aType ) :
275 TRACE( aName, aType )
276 {
277 }
278
279 void Plot( wxDC& aDC, mpWindow& aWindow ) override;
280
281 // drawn directly, keep the locus out of the axis auto-fit
282 bool HasBBox() const override { return false; }
283
284 void SetFrequencies( const std::vector<double>& aFreqs ) { m_frequencies = aFreqs; }
285 const std::vector<double>& GetFrequencies() const { return m_frequencies; }
286
288 void SetReferenceImpedance( double aZ0 ) { m_z0 = aZ0; }
289 double GetReferenceImpedance() const { return m_z0; }
290
291private:
292 std::vector<double> m_frequencies;
293 double m_z0 = 0.0;
294};
295
296
299class SMITH_CURSOR : public CURSOR
300{
301public:
302 SMITH_CURSOR( SMITH_TRACE* aTrace, SIM_PLOT_TAB* aPlotTab ) :
303 CURSOR( aTrace, aPlotTab ),
304 m_index( -1 ),
305 m_gamma( 0.0, 0.0 ),
306 m_requestFreq( 0.0 ),
307 m_pendingFreq( false ),
308 m_dragging( false )
309 {
310 }
311
312 void Plot( wxDC& aDC, mpWindow& aWindow ) override;
313
314 bool Inside( const wxPoint& aPoint ) const override;
315
316 void Move( wxPoint aDelta ) override;
317
318 void UpdateReference() override;
319
320 void SetCoordX( double aValue ) override;
321
322 void UpdateForNewData() override;
323
324 const wxRealPoint& GetGamma() const { return m_gamma; }
325
326private:
327 void snapToIndex( int aIndex );
328 void snapToFrequency( double aFreq );
329
330private:
332 wxRealPoint m_gamma;
334 bool m_pendingFreq; // a saved frequency waiting for the sim data to load
335 bool m_dragging; // the pending update comes from a drag, not a data refresh
336};
337
338
341{
342 wxString vectorName;
343 wxString displayName;
345};
346
347
350{
351 int id;
352 wxString vectorName;
354 int subType; // the SP subtype bit the cursor lived on before Smith mode
355 double frequency;
356};
357
358
365{
366public:
367 TRACK_CURSOR( SIM_PLOT_TAB* aPlotTab, SIM_VIEW* aView ) :
368 mpInfoLayer( wxRect( 0, 0, 1, 1 ), wxTRANSPARENT_BRUSH ),
369 m_plotTab( aPlotTab ),
370 m_view( aView ),
371 m_plotX( 0.0 )
372 {
373 m_visible = false;
374 }
375
376 void Plot( wxDC& aDC, mpWindow& aWindow ) override;
377
378 // Never draggable/clickable; it just tracks the mouse.
379 bool Inside( const wxPoint& aPoint ) const override { return false; }
380 void Move( wxPoint aDelta ) override {}
381 void UpdateReference() override {}
382
385 void SetPlotX( double aPlotX )
386 {
387 m_plotX = aPlotX;
388 SetVisible( true );
389 }
390
391 void SetHidden() { SetVisible( false ); }
392
393 double GetPlotX() const { return m_plotX; }
394
395private:
398 double m_plotX;
399};
400
401
408class SIM_VIEW : public mpWindow
409{
410public:
411 SIM_VIEW( SIM_PLOT_TAB* aPlotTab, wxWindow* aParent );
412
414 void OnXViewChanged() override;
415
417 void SetXRange( double aPos, double aDesiredMax, double aDesiredMin )
418 {
419 SetXView( aPos, aDesiredMax, aDesiredMin );
420 }
421
422 SIM_PLOT_TAB* GetPlotTab() const { return m_plotTab; }
423
424 wxString GetLabelX() const { return m_axis_x ? m_axis_x->GetName() : wxString( wxS( "" ) ); }
425
426 wxString GetLabelY1() const { return m_axis_y1 ? m_axis_y1->GetName() : wxString( wxS( "" ) ); }
427
428 wxString GetLabelY2() const { return m_axis_y2 ? m_axis_y2->GetName() : wxString( wxS( "" ) ); }
429
430 wxString GetLabelY3() const { return m_axis_y3 ? m_axis_y3->GetName() : wxString( wxS( "" ) ); }
431
432 bool GetY1Scale( double* aMin, double* aMax ) const
433 {
434 if( m_axis_y1 )
435 return m_axis_y1->GetAxisMinMax( aMin, aMax );
436
437 return false;
438 }
439
440 bool GetY2Scale( double* aMin, double* aMax ) const
441 {
442 if( m_axis_y2 )
443 return m_axis_y2->GetAxisMinMax( aMin, aMax );
444
445 return false;
446 }
447
448 bool GetY3Scale( double* aMin, double* aMax ) const
449 {
450 if( m_axis_y3 )
451 return m_axis_y3->GetAxisMinMax( aMin, aMax );
452
453 return false;
454 }
455
456 void SetY1Scale( bool aLock, double aMin, double aMax );
457 void SetY2Scale( bool aLock, double aMin, double aMax );
458 void SetY3Scale( bool aLock, double aMin, double aMax );
459
460 wxString GetUnitsX() const;
461 wxString GetUnitsY1() const;
462 wxString GetUnitsY2() const;
463 wxString GetUnitsY3() const;
464
466 wxString GetUnitsForTrace( TRACE* aTrace ) const;
467
469 int GetAxisSlot( TRACE* aTrace ) const;
470
472 mpScaleY* GetAxisBySlot( int aSlot ) const;
473
474 void ShowGrid( bool aEnable )
475 {
476 if( m_axis_x )
477 m_axis_x->SetTicks( !aEnable );
478
479 if( m_axis_y1 )
480 m_axis_y1->SetTicks( !aEnable );
481
482 if( m_axis_y2 )
483 m_axis_y2->SetTicks( !aEnable );
484
485 if( m_axis_y3 )
486 m_axis_y3->SetTicks( !aEnable );
487
488 UpdateAll();
489 }
490
491 bool IsGridShown() const
492 {
493 if( !m_axis_x || !m_axis_y1 )
494 return false;
495
496 return !m_axis_x->GetTicks();
497 }
498
499 void ShowLegend( bool aEnable )
500 {
501 m_legend->SetVisible( aEnable );
502 UpdateAll();
503 }
504
505 bool IsLegendShown() const { return m_legend->IsVisible(); }
506
507 wxPoint GetLegendPosition() const { return m_legend->GetPosition(); }
508
509 void SetLegendPosition( const wxPoint& aPosition )
510 {
511 m_legend->Move( aPosition );
512 m_legend->UpdateReference();
513 m_lastLegendPosition = aPosition;
514 }
515
517 void ResetScales( bool aIncludeX );
518
520 void updateAxes( int aNewTraceType = SIM_TRACE_TYPE::SPT_UNKNOWN );
521
523
525
526 // ---- Smith chart --------------------------------------------------------------------
527
530 void SetSmithChart( bool aEnable );
531
532 bool IsSmithChart() const { return m_smithChart; }
533
536
539
540 double GetSmithZoom() const { return m_smithZoom; }
541 const wxRealPoint& GetSmithPan() const { return m_smithPan; }
542
544 {
545 m_smithZoom = 1.0;
546 m_smithPan = wxRealPoint( 0.0, 0.0 );
547 }
548
549 void SetSmithView( double aZoom, double aPanX, double aPanY )
550 {
551 m_smithZoom = std::isfinite( aZoom ) ? std::clamp( aZoom, 1.0, 50.0 ) : 1.0;
552 m_smithPan.x = std::isfinite( aPanX ) ? std::clamp( aPanX, -100.0, 100.0 ) : 0.0;
553 m_smithPan.y = std::isfinite( aPanY ) ? std::clamp( aPanY, -100.0, 100.0 ) : 0.0;
554 }
555
556 void SmithZoomAt( const wxPoint& aPos, double aFactor );
557 void SmithPanBy( const wxPoint& aDelta );
558
559 // ---- Track cursor -------------------------------------------------------------------
560
563 bool SetTrackCursorPlotX( double aPlotX );
564
566 bool HideTrackCursor();
567
570 void RaiseOverlays();
571
572public:
574
580
581private:
583 void prepareDCAxes( int aNewTraceType );
584
585 void onSmithMouseWheel( wxMouseEvent& aEvent );
586 void onSmithMagnify( wxMouseEvent& aEvent );
587 void onSmithMiddleDown( wxMouseEvent& aEvent );
588 void onSmithLeftDown( wxMouseEvent& aEvent );
589 void onSmithMotion( wxMouseEvent& aEvent );
590 void onSmithLeftUp( wxMouseEvent& aEvent );
591 void onSmithDClick( wxMouseEvent& aEvent );
592 void onSmithRightDown( wxMouseEvent& aEvent );
593 void onSmithRightUp( wxMouseEvent& aEvent );
594 void onSmithMenuCommand( wxCommandEvent& aEvent );
595
596 bool getSmithView( SMITH_VIEW& aView ) const;
597
598 void onPlotMouseMove( wxMouseEvent& aEvent );
599 void onPlotMouseLeave( wxMouseEvent& aEvent );
600
601private:
603
605
607
610 wxRealPoint m_smithPan;
615};
616
617
618class SIM_PLOT_TAB : public SIM_TAB
619{
620public:
621 SIM_PLOT_TAB( const wxString& aSimCommand, wxWindow* parent );
622
623 virtual ~SIM_PLOT_TAB();
624
625 void ApplyPreferences( const SIM_PREFERENCES& aPrefs ) override;
626
627 // ---- View management ----------------------------------------------------------------
628
629 const std::vector<SIM_VIEW*>& GetViews() const { return m_views; }
630
631 SIM_VIEW* GetView( int aIndex ) const
632 {
633 return ( aIndex >= 0 && aIndex < (int) m_views.size() ) ? m_views[aIndex] : nullptr;
634 }
635
636 int GetViewIndex( SIM_VIEW* aView ) const;
637
638 int GetViewCount() const { return (int) m_views.size(); }
639
641 SIM_VIEW* GetDefaultView() const { return m_views.empty() ? nullptr : m_views[0]; }
642
644 SIM_VIEW* AddView();
645
648 bool RemoveView( SIM_VIEW* aView );
649
651 void SyncXView( SIM_VIEW* aSource );
652
653 // ---- Tab-wide accessors (identical across views; delegate to the default view) -------
654
655 wxString GetLabelX() const;
656 wxString GetUnitsX() const;
657
659 wxString GetUnitsForTrace( TRACE* aTrace ) const;
660
661 // ---- Settings shared/fanned out across all views --------------------------------------
662
663 void ShowGrid( bool aEnable );
664 bool IsGridShown() const;
665
666 void ShowLegend( bool aEnable );
667 bool IsLegendShown() const;
668 wxPoint GetLegendPosition() const;
669 void SetLegendPosition( const wxPoint& aPosition );
670
671 // ---- Default-view convenience (used by the Analysis Properties dialog) ----------------
672
673 wxString GetLabelY1() const;
674 wxString GetLabelY2() const;
675 wxString GetLabelY3() const;
676 wxString GetUnitsY1() const;
677 wxString GetUnitsY2() const;
678 wxString GetUnitsY3() const;
679
680 bool GetY1Scale( double* aMin, double* aMax ) const;
681 bool GetY2Scale( double* aMin, double* aMax ) const;
682 bool GetY3Scale( double* aMin, double* aMax ) const;
683 void SetY1Scale( bool aLock, double aMin, double aMax );
684 void SetY2Scale( bool aLock, double aMin, double aMax );
685 void SetY3Scale( bool aLock, double aMin, double aMax );
686
688
692 void SetDottedSecondary( bool aEnable )
693 {
694 m_dotted_cp = aEnable;
695
696 for( const auto& [name, trace] : m_traces )
697 UpdateTraceStyle( trace );
698
699 for( SIM_VIEW* view : m_views )
700 view->UpdateAll();
701 }
702
703 bool GetDottedSecondary() const { return m_dotted_cp; }
704
706 void SetSmithMode( bool aEnable );
707 bool IsSmithMode() const { return m_smithMode; }
708
711
713 double GetSmithZoom() const;
714 wxRealPoint GetSmithPan() const;
715
716 void ResetSmithView();
717
719 void SetSmithView( double aZoom, double aPanX, double aPanY );
720
721 void SmithZoomAt( const wxPoint& aPos, double aFactor );
722 void SmithPanBy( const wxPoint& aDelta );
723
725 std::vector<SMITH_STASHED_TRACE>& SmithStashedTraces() { return m_smithStashedTraces; }
726 std::vector<SMITH_STASHED_CURSOR>& SmithStashedCursors() { return m_smithStashedCursors; }
727
730 void EnableTrackCursor( bool aEnable );
732
734 void SetTrackCursorX( double aPlotX );
735
736 void HideTrackCursor();
737
739 void EnableCursor( TRACE* aTrace, int aCursorId, const wxString& aSignalName );
740 void DisableCursor( TRACE* aTrace, int aCursorId );
741
743 void ResetScales( bool aIncludeX );
744
746 void UpdateTraceStyle( TRACE* trace );
747
749 void UpdatePlotColors();
750
751 wxColour GetPlotColor( SIM_PLOT_COLORS::COLOR_SET aColorId ) { return m_colors.GetPlotColor( aColorId ); }
752
753 void OnLanguageChanged() override;
754
756 mpWindow* GetPlotWin() const;
757
761 TRACE* GetOrAddTrace( const wxString& aVectorName, int aType, SIM_VIEW* aView );
762
763 void SetTraceData( TRACE* aTrace, std::vector<double>& aX, std::vector<double>& aY, int aSweepCount,
764 size_t aSweepSize, bool aIsMultiRun = false, const std::vector<wxString>& aMultiRunLabels = {} );
765
766 bool DeleteTrace( const wxString& aVectorName, int aTraceType );
767 void DeleteTrace( TRACE* aTrace );
768
769 const std::map<wxString, TRACE*>& GetTraces() const { return m_traces; }
770
771 TRACE* GetTrace( const wxString& aVecName, int aType ) const
772 {
773 auto trace = m_traces.find( getTraceId( aVecName, aType ) );
774
775 return trace == m_traces.end() ? nullptr : trace->second;
776 }
777
778 std::vector<std::pair<wxString, wxString>>& Measurements() { return m_measurements; }
779
780public:
782
783private:
785 {
786 static_assert( static_cast<unsigned>( mpWindow::MouseWheelAction::COUNT )
787 == static_cast<unsigned>( SIM_MOUSE_WHEEL_ACTION::COUNT ),
788 "mpWindow::MouseWheelAction enum must match SIM_MOUSE_WHEEL_ACTION" );
789
792 m.verticalUnmodified = static_cast<A>( s.vertical_unmodified );
793 m.verticalWithCtrl = static_cast<A>( s.vertical_with_ctrl );
794 m.verticalWithShift = static_cast<A>( s.vertical_with_shift );
795 m.verticalWithAlt = static_cast<A>( s.vertical_with_alt );
796 m.horizontal = static_cast<A>( s.horizontal );
797
798 return m;
799 }
800
801 wxString getTraceId( const wxString& aVectorName, int aType ) const
802 {
803 return wxString::Format( wxS( "%s%d" ), aVectorName, aType & SPT_Y_AXIS_MASK );
804 }
805
807 bool getYScale( int aSlot, double* aMin, double* aMax ) const;
808
809private:
811 std::map<wxString, wxColour> m_sessionTraceColors;
812
813 wxBoxSizer* m_viewsSizer; // Holds all the stacked SIM_VIEWs
814
815 // Stacked plot views (owned via wx parent-child, except when explicitly removed)
816 std::vector<SIM_VIEW*> m_views;
817
818 // Cached so newly-added views can be initialized with the current preferences
820
821 // Traces to be plotted; each knows which view (if any) it's currently plotted on
822 std::map<wxString, TRACE*> m_traces;
823
825
826 // Re-entrancy guard for SyncXView()
828
830
831 // Smith-chart mode is a property of the whole tab; each SIM_VIEW carries its own grid
832 // layer and pan/zoom state.
834
835 std::vector<SMITH_STASHED_TRACE> m_smithStashedTraces;
836 std::vector<SMITH_STASHED_CURSOR> m_smithStashedCursors;
837
838 // Measurements (and their format strings)
839 std::vector<std::pair<wxString, wxString>> m_measurements;
840};
841
842wxDECLARE_EVENT( EVT_SIM_CURSOR_UPDATE, wxCommandEvent );
843
846wxDECLARE_EVENT( EVT_SIM_VIEWS_CHANGED, wxCommandEvent );
847
848#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.
void EnableTrackCursor(bool aEnable)
Turn on/off the crosshair that follows the mouse and reads out every trace's value.
SIM_VIEW * GetView(int aIndex) const
bool getYScale(int aSlot, double *aMin, double *aMax) 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 SetTrackCursorX(double aPlotX)
Show the track cursor of every view at a shared plot-space X.
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.
bool m_trackCursorEnabled
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
Shared implementation of GetY1Scale/GetY2Scale/GetY3Scale for axis slot 1/2/3.
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
bool IsTrackCursorEnabled() const
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 onPlotMouseLeave(wxMouseEvent &aEvent)
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 onPlotMouseMove(wxMouseEvent &aEvent)
bool HideTrackCursor()
void onSmithMagnify(wxMouseEvent &aEvent)
void SetY1Scale(bool aLock, double aMin, double aMax)
const wxRealPoint & GetSmithPan() const
void SetY3Scale(bool aLock, double aMin, double aMax)
TRACK_CURSOR * m_trackCursor
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 RaiseOverlays()
Move the floating overlays (legend, track cursor) to the end of the layer stack so they draw on top o...
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 SetTrackCursorPlotX(double aPlotX)
Position this view's track cursor at a shared plot-space X.
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.
bool GetValueAtX(double aX, double *aY) const
Linearly interpolate this trace's value at a given X (in the trace's own data space).
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)
A crosshair that follows the mouse pointer (rather than being manually positioned) and shows every tr...
bool Inside(const wxPoint &aPoint) const override
Checks whether a point is inside the info box rectangle.
double GetPlotX() const
SIM_PLOT_TAB * m_plotTab
void SetPlotX(double aPlotX)
The X position is kept in plot space (not pixels), because the stacked views share an X range but not...
TRACK_CURSOR(SIM_PLOT_TAB *aPlotTab, SIM_VIEW *aView)
void UpdateReference() override
Updates the rectangle reference point.
void Move(wxPoint aDelta) override
Moves the layer rectangle of given pixel deltas.
SIM_VIEW * m_view
void Plot(wxDC &aDC, mpWindow &aWindow) override
Plot method.
mpFXYVector(const wxString &name=wxEmptyString, int flags=mpALIGN_NE)
std::vector< double > m_ys
Definition mathplot.h:1523
std::vector< double > m_xs
The internal copy of the set of data to draw.
Definition mathplot.h:1523
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
bool m_visible
Toggles layer visibility.
Definition mathplot.h:348
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
void SetVisible(bool show)
Sets layer visibility.
Definition mathplot.h:328
wxString m_displayName
Definition mathplot.h:344
Plot layer implementing a y-scale ruler.
Definition mathplot.h:889
Canvas for plotting mpLayer implementations.
Definition mathplot.h:970
MouseWheelAction
Enumerates the possible mouse wheel actions that can be performed on the plot.
Definition mathplot.h:976
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:991
MouseWheelAction horizontal
Definition mathplot.h:1001
MouseWheelAction verticalWithShift
Definition mathplot.h:999
MouseWheelAction verticalWithCtrl
Definition mathplot.h:998
MouseWheelAction verticalWithAlt
Definition mathplot.h:1000
MouseWheelAction verticalUnmodified
Definition mathplot.h:997