24#include <wx/tokenzr.h>
39#include <wx/dcclient.h>
47 fmt.Printf(
"%%.0%df", nDigits );
57static void getSISuffix(
double x,
const wxString& unit,
int& power, wxString& suffix )
59 const int n_powers = 11;
87 for(
int i = 0; i < n_powers - 1; i++ )
89 double r_cur = pow( 10, powers[i].exponent );
91 if( fabs( x ) >= r_cur && fabs( x ) < r_cur * 1000.0 )
93 power = powers[i].exponent;
95 if( powers[i].suffix )
96 suffix = wxString( powers[i].suffix ) + unit;
108 if( std::isnan( x ) )
111 auto countSignificantDigits =
114 while( k && ( k % 10LL ) == 0LL )
128 int64_t k = (int)( ( x - floor( x ) ) * pow( 10.0, (
double) maxDigits ) );
129 int n = countSignificantDigits( k );
132 n = std::min( n, countSignificantDigits( k + 1 ) );
138template <
typename T_PARENT>
143 T_PARENT(
name, flags, false ),
152 double maxVis = T_PARENT::AbsVisibleMaxValue();
157 int constexpr MAX_DIGITS = 3;
158 int constexpr MAX_DISAMBIGUATION_DIGITS = 6;
159 bool duplicateLabels =
false;
163 double sf = pow( 10.0, power );
170 for(
size_t ii = 0; ii < T_PARENT::m_tickLabels.size(); ++ii )
177 if( ii > 0 && l.
label == T_PARENT::m_tickLabels[ii-1].label )
178 duplicateLabels =
true;
181 while( duplicateLabels && ++digits <= MAX_DISAMBIGUATION_DIGITS );
206 LIN_SCALE::ExtendDataRange( minV, maxV );
236template <
typename T_PARENT>
241 T_PARENT(
name, flags, false ),
252 int constexpr MAX_DIGITS = 3;
257 double sf = pow( 10.0, power );
275 int radius = std::min( plotW, plotH ) / 2 - 15;
280 aView.
center = wxPoint( mL + plotW / 2, mT + plotH / 2 );
284 aView.
plotRect = wxRect( mL, mT, plotW, plotH );
295 wxRealPoint pan = view ? view->
GetSmithPan() : wxRealPoint( 0.0, 0.0 );
311 const wxRect& plotRect = view.
plotRect;
312 int mL = plotRect.x, mT = plotRect.y, plotW = plotRect.width, plotH = plotRect.height;
314 aDC.SetClippingRegion( plotRect );
318 [&](
double aR ) ->
int
324 auto drawClippedCircle =
325 [&](
double aCx,
double aCy,
double aR )
327 constexpr double LIMIT = 1.0002;
329 std::vector<wxPoint> run;
330 int segments = segmentsFor( aR );
332 for(
int ii = 0; ii <= segments; ii++ )
334 double angle = 2.0 *
M_PI * ii / segments;
335 double re = aCx + aR * cos( angle );
336 double im = aCy + aR * sin( angle );
338 if( re * re + im * im <= LIMIT )
340 run.push_back( view.
ToScreen( re, im ) );
345 aDC.DrawLines( (
int) run.size(), run.data() );
352 aDC.DrawLines( (
int) run.size(), run.data() );
356 [](
double aValue ) -> wxString
358 return wxString::Format( wxS(
"%g" ), aValue );
362 double labelScale =
m_z0 > 0.0 ?
m_z0 : 1.0;
364 static const std::vector<double> baseVals = { 0.2, 0.5, 1.0, 2.0, 5.0 };
365 std::vector<double> gridVals = baseVals;
367 constexpr double FINEST_SCALE = 2.0 / ( 1.0 + 20.0 );
369 wxRealPoint lowGamma = view.
ToGamma( wxPoint( mL, mT + plotH ) );
370 wxRealPoint highGamma = view.
ToGamma( wxPoint( mL + plotW, mT ) );
375 return std::hypot( std::max( { lowGamma.x - aRe, aRe - highGamma.x, 0.0 } ),
376 std::max( { lowGamma.y, -highGamma.y, 0.0 } ) );
379 bool zoomedIn = ( plotW / 2.0 ) / view.
radius < 1.0;
380 bool converged = zoomedIn && std::min( poleDistance( 1.0 ), poleDistance( -1.0 ) ) < FINEST_SCALE;
382 if( view.
zoom >= 2.0 && !converged )
383 gridVals.insert( gridVals.end(), { 0.1, 0.3, 0.4, 0.7, 1.5, 3.0, 10.0 } );
385 if( view.
zoom >= 5.0 && !converged )
386 gridVals.insert( gridVals.end(), { 0.05, 0.15, 0.6, 0.8, 1.2, 1.7, 2.5, 4.0, 7.0, 20.0 } );
388 wxPen gridPen =
m_pen;
389 gridPen.SetStyle( wxPENSTYLE_DOT );
391 aDC.SetBrush( *wxTRANSPARENT_BRUSH );
393 aDC.SetTextForeground(
m_pen.GetColour() );
394 aDC.SetPen( gridPen );
397 for(
double r : gridVals )
398 drawClippedCircle( r / ( 1.0 + r ), 0.0, 1.0 / ( 1.0 + r ) );
401 for(
double x : gridVals )
403 drawClippedCircle( 1.0, 1.0 / x, 1.0 / x );
404 drawClippedCircle( 1.0, -1.0 / x, 1.0 / x );
413 constexpr double LABEL_LIMIT = 1.0002;
416 [&](
double aRe,
double aIm, wxPoint& aOut ) ->
bool
418 if( aRe * aRe + aIm * aIm > LABEL_LIMIT )
421 wxPoint p = view.
ToScreen( aRe, aIm );
423 if( !plotRect.Contains( p ) )
432 [&](
double aCx,
double aCy,
double aR, wxPoint& aOut ) ->
bool
434 int bestMargin = std::numeric_limits<int>::max();
436 int segments = segmentsFor( aR );
438 for(
int ii = 0; ii <= segments; ii++ )
440 double angle = 2.0 *
M_PI * ii / segments;
441 double re = aCx + aR * cos( angle );
442 double im = aCy + aR * sin( angle );
444 if( re * re + im * im > LABEL_LIMIT )
447 wxPoint p = view.
ToScreen( re, im );
449 if( !plotRect.Contains( p ) )
452 int margin = std::min( { p.x - mL, mL + plotW - p.x, p.y - mT, mT + plotH - p.y } );
454 if( margin < bestMargin )
466 [&](
const wxPoint& aPos,
const wxSize& aExt ) -> wxPoint
468 return wxPoint( std::clamp( aPos.x, mL + 1, mL + plotW - aExt.x - 1 ),
469 std::clamp( aPos.y, mT + 1, mT + plotH - aExt.y - 1 ) );
472 std::vector<wxRect> placed;
475 [&](
const wxString& aLabel,
const wxPoint& aPos,
const wxSize& aExt )
477 wxPoint pos = clampToPlot( aPos, aExt );
478 wxRect box( pos, aExt );
482 for(
const wxRect& seen : placed )
484 if( seen.Intersects( box ) )
488 placed.push_back( box );
489 aDC.DrawText( aLabel, pos );
493 [&](
const wxString& aLabel,
const wxPoint& aAt )
495 wxSize ext = aDC.GetTextExtent( aLabel );
497 drawLabel( aLabel, wxPoint( aAt.x - ext.x / 2, aAt.y + 3 ), ext );
501 auto drawRimLabel = [&](
const wxString& aLabel,
const wxPoint& aAt,
double aRe,
double aIm )
503 wxSize ext = aDC.GetTextExtent( aLabel );
508 pos.x -=
KiROUND( ext.x * ( 1.0 - aRe ) / 2.0 );
509 pos.y -=
KiROUND( ext.y * ( 1.0 + aIm ) / 2.0 );
511 drawLabel( aLabel, pos, ext );
517 if( anchorPos( -1.0, 0.0, at ) )
518 drawRimLabel( wxS(
"0" ), at, -1.0, 0.0 );
519 else if( edgePos( 0.0, 0.0, 1.0, at ) )
520 drawEdgeLabel( wxS(
"0" ), at );
522 for(
double r : gridVals )
524 if( anchorPos( ( r - 1.0 ) / ( r + 1.0 ), 0.0, at ) || edgePos( r / ( 1.0 + r ), 0.0, 1.0 / ( 1.0 + r ), at ) )
526 drawEdgeLabel( formatValue( r * labelScale ), at );
530 for(
double x : gridVals )
532 double d = x * x + 1.0;
533 double re = ( x * x - 1.0 ) / d;
534 double im = 2.0 * x / d;
535 wxString posLabel = wxS(
"j" ) + formatValue( x * labelScale );
536 wxString negLabel = wxS(
"-j" ) + formatValue( x * labelScale );
538 if( anchorPos( re, im, at ) )
539 drawRimLabel( posLabel, at, re, im );
540 else if( edgePos( 1.0, 1.0 / x, 1.0 / x, at ) )
541 drawEdgeLabel( posLabel, at );
543 if( anchorPos( re, -im, at ) )
544 drawRimLabel( negLabel, at, re, -im );
545 else if( edgePos( 1.0, -1.0 / x, 1.0 / x, at ) )
546 drawEdgeLabel( negLabel, at );
553 note = wxString::Format( wxS(
"Z0 = %s Ω" ), formatValue(
m_z0 ) );
555 note =
_(
"Normalized Z/Z0 (ports differ)" );
557 note =
_(
"Normalized Z/Z0" );
559 wxSize ext = aDC.GetTextExtent( note );
561 aDC.DrawText( note, mL + 4, mT + plotH - ext.y - 4 );
563 aDC.DestroyClippingRegion();
577 const std::vector<double>& xs =
GetDataX();
578 const std::vector<double>& ys =
GetDataY();
579 size_t count = std::min( xs.size(), ys.size() );
585 aDC.SetClippingRegion( view.
plotRect );
589 if(
GetSweepCount() <= 1 || chunk == std::numeric_limits<size_t>::max() || chunk == 0 )
592 std::vector<wxPoint> pts;
599 aDC.DrawLines( (
int) pts.size(), pts.data() );
601 else if( pts.size() == 1 )
603 aDC.SetBrush( wxBrush(
m_pen.GetColour() ) );
604 aDC.DrawCircle( pts[0], 2 );
610 for(
size_t start = 0; start < count; start += chunk )
612 size_t end = std::min( count, start + chunk );
614 for(
size_t ii = start; ii <
end; ii++ )
617 if( !std::isfinite( xs[ii] ) || !std::isfinite( ys[ii] ) )
623 pts.emplace_back( view.
ToScreen( xs[ii], ys[ii] ) );
629 aDC.DestroyClippingRegion();
635 const std::vector<double>& re =
m_trace->GetDataX();
636 const std::vector<double>& im =
m_trace->GetDataY();
637 const std::vector<double>& freqs =
static_cast<SMITH_TRACE*
>(
m_trace )->GetFrequencies();
639 size_t count = std::min( re.size(), im.size() );
644 m_index = std::clamp( aIndex, 0, (
int) count - 1 );
656 const std::vector<double>& freqs =
static_cast<SMITH_TRACE*
>(
m_trace )->GetFrequencies();
657 const std::vector<double>& re =
m_trace->GetDataX();
658 const std::vector<double>& im =
m_trace->GetDataY();
663 size_t end = freqs.size();
664 size_t chunk =
m_trace->GetSweepSize();
666 if(
m_trace->GetSweepCount() > 1
668 && chunk != std::numeric_limits<size_t>::max()
670 && (
size_t)
m_index < freqs.size() )
672 begin = ( (size_t)
m_index / chunk ) * chunk;
673 end = std::min( freqs.size(), begin + chunk );
677 double bestDist = std::numeric_limits<double>::max();
679 for(
size_t ii = begin; ii <
end; ii++ )
681 if( !std::isfinite( freqs[ii] ) )
684 if( ii < re.size() && ii < im.size() && ( !std::isfinite( re[ii] ) || !std::isfinite( im[ii] ) ) )
687 double dist = std::fabs( freqs[ii] - aFreq );
689 if( dist < bestDist )
774 const std::vector<double>& re =
m_trace->GetDataX();
775 const std::vector<double>& im =
m_trace->GetDataY();
776 size_t count = std::min( re.size(), im.size() );
795 double bestDist = std::numeric_limits<double>::max();
797 for(
size_t ii = 0; ii < count; ii++ )
799 if( !std::isfinite( re[ii] ) || !std::isfinite( im[ii] ) )
802 wxPoint p = view.
ToScreen( re[ii], im[ii] );
803 double dx = (double) p.x -
m_dim.x;
804 double dy = (double) p.y -
m_dim.y;
805 double dist = dx * dx + dy * dy;
807 if( dist < bestDist )
832 wxQueueEvent( aWindow.GetParent(),
new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) );
847 m_dim.SetX( marker.x );
848 m_dim.SetY( marker.y );
857 wxColour fg = aWindow.GetForegroundColour();
860 pen.SetColour( cursorColor.
ToColour() );
861 pen.SetStyle( wxPENSTYLE_SOLID );
863 aDC.SetBrush( *wxTRANSPARENT_BRUSH );
865 aDC.DrawCircle( marker, 4 );
866 aDC.DrawLine( marker.x - 8, marker.y, marker.x - 4, marker.y );
867 aDC.DrawLine( marker.x + 4, marker.y, marker.x + 8, marker.y );
868 aDC.DrawLine( marker.x, marker.y - 8, marker.x, marker.y - 4 );
869 aDC.DrawLine( marker.x, marker.y + 4, marker.x, marker.y + 8 );
876 auto formatSI = [](
double aValue,
const wxString& aUnit ) -> wxString
878 if( std::isnan( aValue ) )
886 double sf = pow( 10.0, power );
888 return formatFloat( aValue / sf, 3 ) + wxS(
" " ) + suffix;
891 std::vector<wxString> lines;
893 lines.push_back(
getID() + wxS(
": f = " ) + formatSI( freq, wxS(
"Hz" ) ) );
896 bool absolute = z0 > 0.0;
900 lines.push_back( wxS(
"Z = inf" ) );
904 lines.push_back( wxString::Format( wxS(
"Z = %s %s j%s" ),
905 formatSI( zr, wxS(
"Ω" ) ),
906 zi < 0 ? wxS(
"-" ) : wxS(
"+" ),
907 formatSI( std::fabs( zi ), wxS(
"Ω" ) ) ) );
910 if( std::isfinite( freq ) && freq > 0.0 && zi != 0.0 )
920 lines.push_back( wxString::Format( wxS(
"z = %s %s j%s" ),
922 zi < 0 ? wxS(
"-" ) : wxS(
"+" ),
929 if( std::isfinite( rl ) )
930 lines.push_back( wxString::Format( wxS(
"RL = %s dB" ),
formatFloat( rl, 1 ) ) );
932 lines.push_back( wxS(
"RL = inf" ) );
934 if( std::isfinite( vswr ) )
935 lines.push_back( wxString::Format( wxS(
"VSWR = %s" ),
formatFloat( vswr, 2 ) ) );
937 lines.push_back( wxS(
"VSWR = inf" ) );
943 int lineH = aDC.GetTextExtent( wxS(
"M" ) ).y;
945 for(
const wxString& line : lines )
946 boxW = std::max( boxW, aDC.GetTextExtent( line ).x );
949 boxH = (int) lines.size() * lineH + 6;
951 wxPoint boxPos( marker.x + ( marker.x < aWindow.
GetScrX() / 2 ? 12 : -12 - boxW ),
952 marker.y + ( marker.y < aWindow.
GetScrY() / 2 ? 12 : -12 - boxH ) );
954 boxPos.x = std::clamp( boxPos.x, 0, std::max( 0, aWindow.
GetScrX() - boxW ) );
955 boxPos.y = std::clamp( boxPos.y, 0, std::max( 0, aWindow.
GetScrY() - boxH ) );
957 wxBrush labelBrush( aWindow.GetBackgroundColour() );
959 aDC.SetBrush( labelBrush );
960 aDC.DrawRectangle( wxRect( boxPos, wxSize( boxW, boxH ) ) );
961 aDC.SetTextForeground( cursorColor.
ToColour() );
963 for(
size_t ii = 0; ii < lines.size(); ii++ )
964 aDC.DrawText( lines[ii], boxPos.x + 4, boxPos.y + 3 + (
int) ii * lineH );
992 &&
m_trace->GetSweepCount() > 1
993 &&
m_trace->GetSweepSize() != std::numeric_limits<size_t>::max() )
997 double plotY =
m_window->p2y( newY );
1014 int sweepCount =
m_trace->GetSweepCount();
1015 size_t sweepSize =
m_trace->GetSweepSize();
1017 if( sweepCount <= 1 )
1020 if( sweepSize == std::numeric_limits<size_t>::max() || sweepSize == 0 )
1041 const std::vector<double>& dataX =
m_trace->GetDataX();
1042 const std::vector<double>& dataY =
m_trace->GetDataY();
1044 if( dataX.size() <= 1 )
1051 size_t startIdx = 0;
1052 size_t endIdx = dataX.size();
1053 int sweepCount =
m_trace->GetSweepCount();
1054 size_t sweepSize =
m_trace->GetSweepSize();
1056 if( snapToNearest &&
m_trace->IsMultiRun()
1058 && sweepSize != std::numeric_limits<size_t>::max()
1060 && std::isfinite( snapTargetY ) )
1062 double bestDistance = std::numeric_limits<double>::infinity();
1066 for(
int sweepIdx = 0; sweepIdx < sweepCount; ++sweepIdx )
1068 size_t candidateStart =
static_cast<size_t>( sweepIdx ) * sweepSize;
1069 size_t candidateEnd = std::min( dataX.size(), candidateStart + sweepSize );
1071 if( candidateStart >= candidateEnd )
1074 auto candidateBegin = dataX.begin() + candidateStart;
1075 auto candidateEndIt = dataX.begin() + candidateEnd;
1076 auto candidateMaxIt = std::upper_bound( candidateBegin, candidateEndIt,
m_coords.x );
1077 int candidateMaxIdx = candidateMaxIt - dataX.begin();
1078 int candidateMinIdx = candidateMaxIdx - 1;
1080 if( candidateMinIdx < (
int) candidateStart
1081 || candidateMaxIdx >= (
int) candidateEnd
1082 || candidateMaxIdx >= (
int) dataX.size() )
1087 double leftX = dataX[candidateMinIdx];
1088 double rightX = dataX[candidateMaxIdx];
1090 if( leftX == rightX )
1093 double leftY = dataY[candidateMinIdx];
1094 double rightY = dataY[candidateMaxIdx];
1095 double value = leftY + ( rightY - leftY ) / ( rightX - leftX ) * (
m_coords.x - leftX );
1096 double distance = std::fabs( value - snapTargetY );
1101 bestSweep = sweepIdx;
1112 && sweepSize != std::numeric_limits<size_t>::max()
1115 size_t available =
static_cast<size_t>( sweepCount ) * sweepSize;
1117 if( available <= dataX.size() )
1122 startIdx =
static_cast<size_t>(
m_sweepIndex ) * sweepSize;
1123 endIdx = std::min( dataX.size(), startIdx + sweepSize );
1135 if( startIdx >= endIdx )
1141 auto beginIt = dataX.begin() + startIdx;
1142 auto endIt = dataX.begin() + endIdx;
1145 auto maxXIt = std::upper_bound( beginIt, endIt,
m_coords.x );
1146 int maxIdx = maxXIt - dataX.begin();
1147 int minIdx = maxIdx - 1;
1150 if( minIdx < (
int) startIdx || maxIdx >= (
int) endIdx || maxIdx >= (
int) dataX.size() )
1159 const double leftX = dataX[minIdx];
1160 const double rightX = dataX[maxIdx];
1161 const double leftY = dataY[minIdx];
1162 const double rightY = dataY[maxIdx];
1165 m_coords.y = leftY + ( rightY - leftY ) / ( rightX - leftX ) * (
m_coords.x - leftX );
1174 return wxString::Format(
_(
"%d" ),
id );
1177 return wxEmptyString;
1183 size_t count = std::min(
m_xs.size(),
m_ys.size() );
1188 size_t startIdx = 0;
1189 size_t endIdx = count;
1197 startIdx = std::min(
static_cast<size_t>(
GetSweepCount() - 1 ) * sweepSize,
1198 ( count - 1 ) / sweepSize * sweepSize );
1199 endIdx = std::min( count, startIdx + sweepSize );
1202 if( endIdx - startIdx < 2 )
1205 auto beginIt =
m_xs.begin() + startIdx;
1206 auto endIt =
m_xs.begin() + endIdx;
1209 auto maxXIt =
m_xs[endIdx - 1] <
m_xs[startIdx] ? std::upper_bound( beginIt, endIt, aX, std::greater<double>() )
1210 : std::upper_bound( beginIt, endIt, aX );
1212 if( maxXIt == beginIt || maxXIt == endIt )
1215 size_t maxIdx = maxXIt -
m_xs.begin();
1216 size_t minIdx = maxIdx - 1;
1218 const double leftX =
m_xs[minIdx];
1219 const double rightX =
m_xs[maxIdx];
1220 const double leftY =
m_ys[minIdx];
1221 const double rightY =
m_ys[maxIdx];
1223 if( leftX == rightX )
1226 *aY = leftY + ( rightY - leftY ) / ( rightX - leftX ) * ( aX - leftX );
1229 return std::isfinite( *aY );
1247 wxQueueEvent( aWindow.GetParent(),
new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) );
1265 const bool hasY = std::isfinite(
m_coords.y );
1277 wxColour fg = aWindow.GetForegroundColour();
1281 if( cursorColor.
Distance( textColor ) < 0.66 )
1284 pen.SetColour( cursorColor.
ToColour() );
1285 pen.SetStyle(
m_continuous ? wxPENSTYLE_SOLID : wxPENSTYLE_LONG_DASH );
1288 if( hasY && topPx < cursorPos.y && cursorPos.y < bottomPx )
1289 aDC.DrawLine( leftPx, cursorPos.y, rightPx, cursorPos.y );
1291 if( leftPx < cursorPos.x && cursorPos.x < rightPx )
1293 aDC.DrawLine( cursorPos.x, topPx, cursorPos.x, bottomPx );
1295 wxString
id =
getID();
1296 wxSize size = aDC.GetTextExtent( wxS(
"M" ) );
1297 wxRect textRect( wxPoint( cursorPos.x + 1 - size.x / 2, topPx - 4 - size.y ), size );
1308 size.y = ( size.y / 2 ) * 2;
1309 poly[0] = { cursorPos.x - 1 - size.y / 2, topPx - size.y };
1310 poly[1] = { cursorPos.x + 1 + size.y / 2, topPx - size.y };
1311 poly[2] = { cursorPos.x, topPx };
1313 brush.SetStyle( wxBRUSHSTYLE_SOLID );
1314 brush.SetColour(
m_trace->GetTraceColour() );
1315 aDC.SetBrush( brush );
1316 aDC.DrawPolygon( 3, poly );
1318 aDC.SetTextForeground( textColor.
ToColour() );
1319 aDC.DrawLabel(
id, textRect, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL );
1322 &&
m_trace->GetSweepSize() != std::numeric_limits<size_t>::max() )
1325 const std::vector<wxString>& labels =
m_trace->GetMultiRunLabels();
1333 runLabel = wxString::Format(
_(
"Run %d" ),
m_sweepIndex + 1 );
1336 wxSize runSize = aDC.GetTextExtent( runLabel );
1337 int runX = textRect.GetRight() + 6;
1338 wxRect runRect( wxPoint( runX, textRect.y ), runSize );
1340 runRect.Inflate( 3, 1 );
1342 wxBrush labelBrush( aWindow.GetBackgroundColour() );
1343 wxPen labelPen( cursorColor.
ToColour() );
1345 aDC.SetPen( labelPen );
1346 aDC.SetBrush( labelBrush );
1347 aDC.DrawRectangle( runRect );
1348 aDC.SetTextForeground( cursorColor.
ToColour() );
1349 aDC.DrawLabel( runLabel, runRect, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL );
1361 bool nearX = std::isfinite(
m_coords.x )
1363 bool nearY = std::isfinite(
m_coords.y )
1366 return nearX || nearY;
1391 if(
m_view->IsSmithChart() )
1402 if( mouseX < leftPx || mouseX > rightPx )
1405 wxColour fg = aWindow.GetForegroundColour();
1406 wxPen linePen( fg, 1, wxPENSTYLE_DOT );
1408 aDC.SetPen( linePen );
1409 aDC.DrawLine( mouseX, topPx, mouseX, bottomPx );
1412 std::vector<TRACE*> traces;
1416 if( trace && trace->GetView() ==
m_view )
1417 traces.push_back( trace );
1420 if( traces.empty() )
1428 double dataX = traces.front()->s2x(
m_plotX );
1430 wxColour bg = aWindow.GetBackgroundColour();
1434 double luminance = 0.299 * bg.Red() + 0.587 * bg.Green() + 0.114 * bg.Blue();
1435 bool plotIsDark = luminance < 128;
1436 wxColour boxBg = plotIsDark ? wxColour( 0, 0, 0, 220 ) : wxColour( 255, 255, 255, 220 );
1437 wxColour boxDefaultText = plotIsDark ? *wxWHITE : *wxBLACK;
1446 std::vector<ROW>
rows;
1451 for(
TRACE* trace : traces )
1453 double traceX = trace->s2x(
m_plotX );
1456 if( !trace->GetValueAtX( traceX, &y ) )
1459 wxColour traceColour = trace->GetTraceColour();
1462 int markerY = aWindow.
y2p( trace->y2s( y ) );
1464 if( markerY >= topPx && markerY <= bottomPx )
1466 wxBrush markerBrush( traceColour );
1467 wxPen markerPen( bg, 1 );
1469 aDC.SetBrush( markerBrush );
1470 aDC.SetPen( markerPen );
1471 aDC.DrawCircle( mouseX, markerY, 4 );
1479 if(
rows.size() <= 1 )
1486 for(
const ROW& row :
rows )
1488 wxSize labelSize = aDC.GetTextExtent( row.label );
1489 wxSize valueSize = aDC.GetTextExtent( row.value );
1491 labelWidth = std::max( labelWidth, labelSize.x );
1492 valueWidth = std::max( valueWidth, valueSize.x );
1493 rowHeight = std::max( { rowHeight, labelSize.y, valueSize.y } );
1496 const int columnGap = 8;
1497 int lineHeight = rowHeight + 2;
1498 int boxWidth = labelWidth + columnGap + valueWidth + 10;
1499 int boxHeight = lineHeight * (int)
rows.size() + 6;
1501 int boxX = mouseX + 12;
1503 if( boxX + boxWidth > rightPx )
1504 boxX = std::max( leftPx, mouseX - 12 - boxWidth );
1506 int boxY = topPx + 4;
1508 wxBrush brush( boxBg );
1511 aDC.SetBrush( brush );
1512 aDC.SetPen( boxPen );
1513 aDC.DrawRectangle( boxX, boxY, boxWidth, boxHeight );
1515 int textY = boxY + 3;
1516 int valueRight = boxX + boxWidth - 5;
1518 for(
const ROW& row :
rows )
1520 aDC.SetTextForeground( row.colour );
1521 aDC.DrawText( row.label, boxX + 5, textY );
1522 aDC.DrawText( row.value, valueRight - aDC.GetTextExtent( row.value ).x, textY );
1523 textY += lineHeight;
1631 m_axis_y1->SetAxisMinMax( aLock, aMin, aMax );
1638 m_axis_y2->SetAxisMinMax( aLock, aMin, aMax );
1645 m_axis_y3->SetAxisMinMax( aLock, aMin, aMax );
1659 return wxEmptyString;
1670 return wxEmptyString;
1681 return wxEmptyString;
1692 return wxEmptyString;
1820 m_axis_y1->SetName(
_(
"Noise (V/√Hz)" ) );
1823 m_axis_y2->SetName(
_(
"Noise (A/√Hz)" ) );
1912 wxClientDC
dc(
this );
1916 dc.GetTextExtent( wxT(
"0" ), &tx, &ty );
1922 int marginBottom = 2 * ty + 10;
1934 wxString sim_cmd =
m_plotTab->GetSimCommand().Lower();
1937 if( sim_cmd.StartsWith(
".dc", &rem ) )
1945 ch = rem.GetChar( 0 );
1964 m_axis_x->SetName(
_(
"Voltage (swept)" ) );
1975 m_axis_x->SetName(
_(
"Current (swept)" ) );
1986 m_axis_x->SetName(
_(
"Resistance (swept)" ) );
1997 m_axis_x->SetName(
_(
"Temperature (swept)" ) );
2015 m_axis_y1->SetName(
_(
"Voltage (measured)" ) );
2051 bool hasY1Traces =
false;
2052 bool hasY2Traces =
false;
2053 bool hasY3Traces =
false;
2059 if( !trace || trace->GetView() !=
this )
2078 bool visibilityChanged =
false;
2083 visibilityChanged =
true;
2089 visibilityChanged =
true;
2095 visibilityChanged =
true;
2101 visibilityChanged =
true;
2104 if( visibilityChanged )
2117 wxStringTokenizer tokenizer(
m_plotTab->GetSimCommand(),
" \t\r\n", wxTOKEN_STRTOK );
2118 wxString cmd = tokenizer.GetNextToken().Lower();
2120 wxASSERT( cmd == wxS(
".tran" ) );
2126 if( tokenizer.HasMoreTokens() )
2129 if( tokenizer.HasMoreTokens() )
2132 if( tokenizer.HasMoreTokens() )
2150 if( trace->GetView() ==
this )
2151 trace->UpdateScales();
2198 bool unresolved =
false;
2204 if( !smithTrace || smithTrace->
GetView() !=
this )
2209 if( traceZ0 <= 0.0 )
2211 else if( z0 == 0.0 )
2213 else if( traceZ0 != z0 )
2218 m_smithGrid->SetReferenceImpedance( mixed || unresolved ? 0.0 : z0 );
2243 double newZoom = std::clamp(
m_smithZoom * aFactor, 1.0, 50.0 );
2245 if( newZoom <= 1.0 )
2283 if( aEvent.GetWheelAxis() != wxMOUSE_WHEEL_VERTICAL || aEvent.GetWheelRotation() == 0 )
2287 SmithZoomAt( aEvent.GetPosition(), aEvent.GetWheelRotation() > 0 ? 1.2 : 1.0 / 1.2 );
2299 double factor = aEvent.GetMagnification() + 1.0;
2320 wxPoint pos = aEvent.GetPosition();
2346 wxPoint pos = aEvent.GetPosition();
2356 if( aEvent.MiddleIsDown() )
2384 wxPoint pos = aEvent.GetPosition();
2421 PopupMenu( menu, aEvent.GetPosition() );
2433 switch( aEvent.GetId() )
2456 default: aEvent.Skip();
2462 SIM_TAB( aSimCommand, parent ),
2470 wxBoxSizer* outerSizer =
new wxBoxSizer( wxVERTICAL );
2475 wxBoxSizer* viewButtonsSizer =
new wxBoxSizer( wxHORIZONTAL );
2479 addViewButton->SetToolTip(
_(
"Add a new signal view" ) );
2483 removeViewButton->SetToolTip(
_(
"Remove the last signal view" ) );
2485 viewButtonsSizer->Add( addViewButton, 0, wxLEFT, 5 );
2486 viewButtonsSizer->Add( removeViewButton, 0, wxLEFT, 30 );
2488 addViewButton->Bind( wxEVT_BUTTON,
2489 [
this]( wxCommandEvent& aEvent )
2494 removeViewButton->Bind( wxEVT_BUTTON,
2495 [
this]( wxCommandEvent& aEvent )
2497 const std::vector<SIM_VIEW*>& views =
GetViews();
2499 if( !views.empty() )
2503 outerSizer->Add( viewButtonsSizer, 0, wxEXPAND | wxTOP | wxBOTTOM, 3 );
2505 SetSizer( outerSizer );
2553 if( firstView->GetY1Scale( &min, &max ) )
2556 if( firstView->GetY2Scale( &min, &max ) )
2559 if( firstView->GetY3Scale( &min, &max ) )
2566 view->
ShowLegend( firstView->IsLegendShown() );
2580 wxQueueEvent(
this,
new wxCommandEvent( EVT_SIM_VIEWS_CHANGED ) );
2600 std::vector<TRACE*> plottedHere;
2604 trace->ClearYScaleViewIf( aView );
2606 if( trace->GetView() == aView )
2607 plottedHere.push_back( trace );
2611 for(
TRACE* trace : plottedHere )
2627 wxQueueEvent(
this,
new wxCommandEvent( EVT_SIM_VIEWS_CHANGED ) );
2635 for(
size_t i = 0; i <
m_views.size(); ++i )
2653 double pos = aSource->
GetPosX();
2659 if( view == aSource )
2662 view->SetScaleX( scaleX );
2663 view->SetXRange( pos, desiredMax, desiredMin );
2674 return view ? view->
GetLabelX() : wxString( wxS(
"" ) );
2681 return view ? view->
GetUnitsX() : wxString( wxS(
"" ) );
2695 view->ShowGrid( aEnable );
2709 view->ShowLegend( aEnable );
2730 view->SetLegendPosition( aPosition );
2739 return view ? view->
GetLabelY1() : wxString( wxS(
"" ) );
2746 return view ? view->
GetLabelY2() : wxString( wxS(
"" ) );
2753 return view ? view->
GetLabelY3() : wxString( wxS(
"" ) );
2760 return view ? view->
GetUnitsY1() : wxString( wxS(
"" ) );
2767 return view ? view->
GetUnitsY2() : wxString( wxS(
"" ) );
2774 return view ? view->
GetUnitsY3() : wxString( wxS(
"" ) );
2789 if( axis->GetAxisMinMax( aMin, aMax ) )
2796 bool haveRange =
false;
2797 double min = 0.0, max = 0.0;
2801 mpScaleY* axis = view->GetAxisBySlot( aSlot );
2806 double viewMin, viewMax;
2817 min = std::min( min, viewMin );
2818 max = std::max( max, viewMax );
2853 view->SetY1Scale( aLock, aMin, aMax );
2860 view->SetY2Scale( aLock, aMin, aMax );
2867 view->SetY3Scale( aLock, aMin, aMax );
2874 view->EnsureThirdYAxisExists();
2886 view->UpdateSmithGridColor();
2906 if( view->SetTrackCursorPlotX( aPlotX ) )
2916 if( view->HideTrackCursor() )
2934 view->SetSmithChart( aEnable );
2941 view->UpdateSmithReferenceImpedance();
2955 return view ? view->
GetSmithPan() : wxRealPoint( 0.0, 0.0 );
2963 view->ResetSmithView();
2972 view->SetSmithView( aZoom, aPanX, aPanY );
2979 view->SmithZoomAt( aPos, aFactor );
2986 view->SmithPanBy( aDelta );
3003 wxPenStyle penStyle;
3006 penStyle = wxPENSTYLE_SOLID;
3008 penStyle =
m_dotted_cp ? wxPENSTYLE_DOT : wxPENSTYLE_SOLID;
3010 penStyle =
m_dotted_cp ? wxPENSTYLE_DOT : wxPENSTYLE_SOLID;
3012 penStyle = wxPENSTYLE_SOLID;
3023 if( !trace && aView )
3029 bool hasVoltageTraces =
false;
3031 for(
const auto& [
id, candidate] :
m_traces )
3033 if( candidate->GetView() == aView && ( candidate->GetType() &
SPT_VOLTAGE ) )
3035 hasVoltageTraces =
true;
3040 if( !hasVoltageTraces )
3073 size_t aSweepSize,
bool aIsMultiRun,
const std::vector<wxString>& aMultiRunLabels )
3085 if( aX.size() > 0 && aX[0] == 0 )
3087 aX.erase( aX.begin() );
3088 aY.erase( aY.begin() );
3096 for(
double& pt : aY )
3097 pt = pt * 180.0 /
M_PI;
3101 for(
double& pt : aY )
3116 trace->
SetScale(
nullptr,
nullptr );
3135 cursor->UpdateForNewData();
3146 if( trace == aTrace )
3158 view->DelLayer(
cursor,
true );
3161 view->DelLayer( aTrace,
true,
true );
3162 view->UpdateAxisVisibility();
3163 view->UpdateSmithReferenceImpedance();
3199 if( !freqs.empty() )
3200 cursor->SetCoordX( freqs[freqs.size() * ( aCursorId == 1 ? 2 : 3 ) / 5] );
3212 cursor->SetName( aSignalName );
3219 wxQueueEvent(
this,
new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) );
3227 aTrace->
SetCursor( aCursorId,
nullptr );
3230 view->DelLayer(
cursor,
true );
3233 wxQueueEvent(
this,
new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) );
3241 view->ResetScales( aIncludeX );
3246 std::map<std::pair<SIM_VIEW*, int>, std::vector<TRACE*>> groups;
3250 if(
SIM_VIEW* view = trace->GetView() )
3251 groups[{ trace->GetYScaleView(), view->GetAxisSlot( trace ) }].push_back( trace );
3254 for(
const auto& [key, traces] : groups )
3256 std::vector<SIM_VIEW*> actualViews;
3258 for(
TRACE* trace : traces )
3262 if( std::find( actualViews.begin(), actualViews.end(), view ) == actualViews.end() )
3263 actualViews.push_back( view );
3266 if( actualViews.size() <= 1 )
3269 bool haveRange =
false;
3273 for(
TRACE* trace : traces )
3275 double lo = trace->GetMinY();
3276 double hi = trace->GetMaxY();
3278 if( !std::isfinite( lo ) || !std::isfinite( hi ) )
3289 minV = std::min( minV, lo );
3290 maxV = std::max( maxV, hi );
3297 for(
SIM_VIEW* view : actualViews )
3299 if(
mpScaleY* axis = view->GetAxisBySlot( key.second ) )
3300 axis->SetDataRange( minV, maxV );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
The SIMULATOR_FRAME holds the main user-interface for running simulations.
void Move(wxPoint aDelta) override
Moves the layer rectangle of given pixel deltas.
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)
bool OnDoubleClick(const wxPoint &aPoint, mpWindow &aWindow) override
virtual void SetCoordX(double aValue)
void UpdateReference() override
Updates the rectangle reference point.
void Plot(wxDC &aDC, mpWindow &aWindow) override
Plot method.
A color representation with 4 components: red, green, blue, alpha.
COLOR4D & Invert()
Makes the color inverted, alpha remains the same.
wxColour ToColour() const
double Distance(const COLOR4D &other) const
Returns the distance (in RGB space) between two colors.
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
void formatLabels() override
wxString GetUnits() const
LIN_SCALE(const wxString &name, const wxString &unit, int flags)
wxString m_base_axis_label
wxString GetUnits() const
LOG_SCALE(const wxString &name, const wxString &unit, int flags)
void formatLabels() override
bool DeleteTrace(const wxString &aVectorName, int aTraceType)
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.
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
void SetSmithMode(bool aEnable)
Smith mode is tab-wide: every view of the tab shows a Smith chart while it is on.
wxString GetLabelX() const
wxRealPoint GetSmithPan() const
wxString GetLabelY3() const
void SetY1Scale(bool aLock, double aMin, double aMax)
wxPoint GetLegendPosition() const
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.
wxString GetUnitsForTrace(TRACE *aTrace) const
Get the display units (e.g. "V", "A", "dB") for a given trace's own view.
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.
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
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.
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
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_TYPE GetSimType() const
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 SmithZoomAt(const wxPoint &aPos, double aFactor)
void onSmithMenuCommand(wxCommandEvent &aEvent)
wxString GetUnitsForTrace(TRACE *aTrace) const
Get the display units (e.g. "V", "A", "dB") for a given trace plotted on this view.
void UpdateSmithGridColor()
Re-read the Smith grid pen from the tab's color theme.
void SetY2Scale(bool aLock, double aMin, double aMax)
void EnsureThirdYAxisExists()
void SmithPanBy(const wxPoint &aDelta)
void onSmithDClick(wxMouseEvent &aEvent)
wxString GetLabelX() const
wxPoint m_lastLegendPosition
wxString GetLabelY3() const
wxString GetUnitsY3() const
wxPoint GetLegendPosition() const
void onPlotMouseMove(wxMouseEvent &aEvent)
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)
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
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)
wxString GetLabelY1() const
void UpdateSmithReferenceImpedance()
Refresh the grid z0 from the Smith traces shown on this view.
void onSmithLeftDown(wxMouseEvent &aEvent)
void ResetScales(bool aIncludeX)
Reset the Y (and, if requested, X) scale ranges to fit this view's own traces.
int GetAxisSlot(TRACE *aTrace) const
Get the Y-axis slot (1, 2 or 3) a trace of this type is plotted on.
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.
void UpdateAxisVisibility()
void onSmithMotion(wxMouseEvent &aEvent)
wxString GetUnitsY2() const
wxString GetUnitsY1() const
void onSmithMouseWheel(wxMouseEvent &aEvent)
void prepareDCAxes(int aNewTraceType)
Construct the plot axes for DC simulation plot.
Cursor that snaps along a Smith chart locus, keyed by frequency.
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
void snapToIndex(int aIndex)
void snapToFrequency(double aFreq)
void UpdateForNewData() override
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.
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.
const std::vector< double > & GetFrequencies() const
double GetReferenceImpedance() const
Helper class to handle Spice way of expressing values (e.g. 10.5 Meg)
wxString ToString() const
Return string value as when converting double to string (e.g.
void ResetDataRange() override
True once ExtendDataRange()/SetDataRange() has established a real data range.
void ExtendDataRange(double minV, double maxV) override
void SetStartAndEnd(double aStartTime, double aEndTime)
TIME_SCALE(const wxString &name, const wxString &unit, int flags)
void SetIsMultiRun(bool aIsMultiRun)
void SetTraceColour(const wxColour &aColour)
void SetMultiRunLabels(const std::vector< wxString > &aLabels)
std::map< int, CURSOR * > & GetCursors()
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
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).
void SetCursor(int aCursorId, CURSOR *aCursor)
const std::vector< double > & GetDataY() const
wxColour GetTraceColour() const
const std::vector< double > & GetDataX() const
CURSOR * GetCursor(int aCursorId)
A crosshair that follows the mouse pointer (rather than being manually positioned) and shows every tr...
void Plot(wxDC &aDC, mpWindow &aWindow) override
Plot method.
void SetSweepSize(size_t aSweepSize)
std::vector< double > m_ys
std::vector< double > m_xs
The internal copy of the set of data to draw.
size_t GetSweepSize() const
void SetSweepCount(int aSweepCount)
int GetSweepCount() const override
virtual void SetScale(mpScaleBase *scaleX, mpScaleBase *scaleY)
wxPoint GetPosition() const
Returns the position of the upper left corner of the box (in pixels)
virtual void UpdateReference()
Updates the rectangle reference point.
virtual void Move(wxPoint delta)
Moves the layer rectangle of given pixel deltas.
Implements the legend to be added to the plot This layer allows you to add a legend to describe the p...
const wxString & GetName() const
Get layer name.
bool m_continuous
Specify if the layer will be plotted as a continuous line or a set of points.
bool m_visible
Toggles layer visibility.
const wxPen & GetPen() const
Get pen set for this layer.
void SetVisible(bool show)
Sets layer visibility.
const wxFont & GetPlotFont() const
Get the font to draw this layer with, which is the default one when none was set.
void SetPen(const wxPen &pen)
Set layer pen.
void GetDataRange(double &minV, double &maxV) const
Plot layer implementing a y-scale ruler.
void SetMasterScale(mpScaleY *masterScale)
Canvas for plotting mpLayer implementations.
int GetMarginLeft() const
void SetMargins(int top, int right, int bottom, int left)
Set window margins, creating a blank area where some kinds of layers cannot draw.
int GetScrX() const
Get current view's X dimension in device context units.
int GetScrY() const
Get current view's Y dimension in device context units.
void SetMouseWheelActions(const MouseWheelActionSet &s)
Set the pan/zoom actions corresponding to mousewheel/trackpad events.
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
void LimitView(bool aEnable)
Enable limiting of zooming & panning to the area used by the plots.
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
mpInfoLayer * IsInsideInfoLayer(wxPoint &point)
Check if a given point is inside the area of a mpInfoLayer and eventually returns its pointer.
bool DelLayer(mpLayer *layer, bool alsoDeleteObject=false, bool refreshDisplay=true)
Remove a plot layer from the canvas.
void UpdateAll()
Refresh display.
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
double GetDesiredXmax() const
Returns the right-border layer coordinate that the user wants the mpWindow to show (it may be not exa...
wxMenu * GetPopupMenu()
Get reference to context menu of the plot canvas.
double GetDesiredXmin() const
Returns the left-border layer coordinate that the user wants the mpWindow to show (it may be not exac...
int GetMarginRight() const
int GetMarginBottom() const
void EnableDoubleBuffer(bool enabled)
Enable/disable the double-buffering of the window, eliminating the flicker (default=disabled).
double GetScaleX() const
Get current view's X scale.
bool AddLayer(mpLayer *layer, bool refreshDisplay=true)
Add a plot layer to the canvas.
double GetPosX() const
Get current view's X position.
static bool empty(const wxTextEntryBase *aCtrl)
#define mpALIGN_BORDER_RIGHT
Aligns Y axis to right border.
#define mpALIGN_RIGHT
Aligns label to the right.
#define mpALIGN_LEFT
Aligns label to the left.
#define mpALIGN_BOTTOM
Aligns label to the bottom.
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
double SeriesCapacitance(double aReactance, double aFreq)
double SeriesInductance(double aReactance, double aFreq)
Series equivalent element of a reactance at one frequency, henries for aReactance > 0,...
double VSWR(double aGammaMag)
wxRealPoint ZoomAboutPoint(const SMITH_VIEW &aView, const wxPoint &aPos, double aNewZoom)
Pan that keeps the gamma point under aPos fixed when the view zooms to aNewZoom.
bool GammaToImpedance(double aRe, double aIm, double aZ0, double &aResistance, double &aReactance)
Impedance of a reflection coefficient, z = z0 ( 1 + gamma ) / ( 1 - gamma ), false at the gamma = 1 s...
double ReturnLoss(double aGammaMag)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > overlay
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
Class is responsible for providing colors for traces on simulation plot.
wxDEFINE_EVENT(EVT_SIM_CURSOR_UPDATE, wxCommandEvent)
static void getSISuffix(double x, const wxString &unit, int &power, wxString &suffix)
static int countDecimalDigits(double x, int maxDigits)
static bool smithView(mpWindow &aWindow, SMITH_VIEW &aView)
static wxString formatFloat(double x, int nDigits)
SIM_TRACE_TYPE
Possible trace types.
double MagnitudeToDb(double aMagnitude)
Convert a linear magnitude to decibels.
static SIM_MOUSE_WHEEL_ACTION_SET GetMouseDefaults()
Contains preferences pertaining to the simulator.
SIM_MOUSE_WHEEL_ACTION_SET mouse_wheel_actions
Smith chart placement plus pan/zoom, maps a gamma point to a screen pixel and back.
wxRealPoint ToGamma(const wxPoint &aPt) const
wxPoint ToScreen(double aRe, double aIm) const
DATABASE_CONNECTION dc(odbcBackend(cs))
std::vector< DATABASE_CONNECTION::ROW > rows