2020-08-31 04:03:41 +08:00
# include "vna.h"
# include <QGridLayout>
# include <QVBoxLayout>
# include <QHBoxLayout>
# include <QPushButton>
# include <math.h>
# include <QToolBar>
# include <QMenu>
# include <QToolButton>
# include <QActionGroup>
# include <QSpinBox>
# include <QCheckBox>
# include <QComboBox>
# include <QSettings>
# include <algorithm>
# include <QMessageBox>
# include <QFileDialog>
# include <QFile>
# include <iostream>
# include <fstream>
# include <QDateTime>
# include "unit.h"
2020-09-20 16:13:06 +08:00
# include <queue>
2020-08-31 04:03:41 +08:00
# include "CustomWidgets/toggleswitch.h"
# include "Device/manualcontroldialog.h"
# include "Traces/tracemodel.h"
2020-11-25 01:08:00 +08:00
# include "tracewidgetvna.h"
2020-08-31 04:03:41 +08:00
# include "Traces/tracesmithchart.h"
2020-10-28 05:07:14 +08:00
# include "Traces/tracexyplot.h"
2020-08-31 04:03:41 +08:00
# include "Traces/traceimportdialog.h"
# include "CustomWidgets/tilewidget.h"
2020-09-13 20:44:45 +08:00
# include "CustomWidgets/siunitedit.h"
2020-08-31 04:03:41 +08:00
# include <QDockWidget>
# include "Traces/markerwidget.h"
# include "Tools/impedancematchdialog.h"
# include "Calibration/calibrationtracedialog.h"
# include "ui_main.h"
# include "Device/firmwareupdatedialog.h"
2020-09-12 05:07:15 +08:00
# include "preferences.h"
2020-09-13 20:44:45 +08:00
# include "Generator/signalgenwidget.h"
2020-09-12 05:07:15 +08:00
# include <QDesktopWidget>
# include <QApplication>
2020-09-13 20:44:45 +08:00
# include <QActionGroup>
2020-11-11 02:16:16 +08:00
# include <QErrorMessage>
# include "CustomWidgets/informationbox.h"
2020-11-22 07:41:42 +08:00
# include <QDebug>
2020-08-31 04:03:41 +08:00
2020-09-13 20:44:45 +08:00
VNA : : VNA ( AppWindow * window )
: Mode ( window , " Vector Network Analyzer " ) ,
2021-02-11 23:59:59 +08:00
deembedding ( traceModel ) ,
2020-09-13 20:44:45 +08:00
central ( new TileWidget ( traceModel ) )
2020-08-31 04:03:41 +08:00
{
averages = 1 ;
calValid = false ;
calMeasuring = false ;
calDialog . reset ( ) ;
2020-12-08 03:21:24 +08:00
calEdited = false ;
2020-08-31 04:03:41 +08:00
2020-09-12 05:07:15 +08:00
// Create default traces
auto tS11 = new Trace ( " S11 " , Qt : : yellow ) ;
tS11 - > fromLivedata ( Trace : : LivedataType : : Overwrite , Trace : : LiveParameter : : S11 ) ;
traceModel . addTrace ( tS11 ) ;
auto tS12 = new Trace ( " S12 " , Qt : : blue ) ;
tS12 - > fromLivedata ( Trace : : LivedataType : : Overwrite , Trace : : LiveParameter : : S12 ) ;
traceModel . addTrace ( tS12 ) ;
auto tS21 = new Trace ( " S21 " , Qt : : green ) ;
tS21 - > fromLivedata ( Trace : : LivedataType : : Overwrite , Trace : : LiveParameter : : S21 ) ;
traceModel . addTrace ( tS21 ) ;
auto tS22 = new Trace ( " S22 " , Qt : : red ) ;
tS22 - > fromLivedata ( Trace : : LivedataType : : Overwrite , Trace : : LiveParameter : : S22 ) ;
traceModel . addTrace ( tS22 ) ;
auto tracesmith1 = new TraceSmithChart ( traceModel ) ;
tracesmith1 - > enableTrace ( tS11 , true ) ;
auto tracesmith2 = new TraceSmithChart ( traceModel ) ;
tracesmith2 - > enableTrace ( tS22 , true ) ;
2020-10-28 05:08:05 +08:00
auto traceXY1 = new TraceXYPlot ( traceModel ) ;
traceXY1 - > enableTrace ( tS12 , true ) ;
auto traceXY2 = new TraceXYPlot ( traceModel ) ;
traceXY2 - > enableTrace ( tS21 , true ) ;
2020-09-12 05:07:15 +08:00
2020-09-16 05:22:08 +08:00
connect ( & traceModel , & TraceModel : : requiredExcitation , this , & VNA : : ExcitationRequired ) ;
2020-09-13 20:44:45 +08:00
central - > splitVertically ( ) ;
central - > Child1 ( ) - > splitHorizontally ( ) ;
central - > Child2 ( ) - > splitHorizontally ( ) ;
central - > Child1 ( ) - > Child1 ( ) - > setPlot ( tracesmith1 ) ;
2020-10-28 05:08:05 +08:00
central - > Child1 ( ) - > Child2 ( ) - > setPlot ( traceXY1 ) ;
central - > Child2 ( ) - > Child1 ( ) - > setPlot ( traceXY2 ) ;
2020-09-13 20:44:45 +08:00
central - > Child2 ( ) - > Child2 ( ) - > setPlot ( tracesmith2 ) ;
// Create menu entries and connections
2020-11-01 06:03:34 +08:00
auto calMenu = new QMenu ( " Calibration " , window ) ;
2020-09-13 20:44:45 +08:00
window - > menuBar ( ) - > insertMenu ( window - > getUi ( ) - > menuWindow - > menuAction ( ) , calMenu ) ;
actions . insert ( calMenu - > menuAction ( ) ) ;
2020-11-11 02:16:16 +08:00
auto calLoad = calMenu - > addAction ( " Load " ) ;
saveCal = calMenu - > addAction ( " Save " ) ;
calMenu - > addSeparator ( ) ;
saveCal - > setEnabled ( false ) ;
connect ( calLoad , & QAction : : triggered , [ = ] ( ) {
2020-11-15 03:43:36 +08:00
cal . openFromFile ( ) ;
if ( cal . getType ( ) = = Calibration : : Type : : None ) {
DisableCalibration ( ) ;
} else {
2020-11-11 02:16:16 +08:00
ApplyCalibration ( cal . getType ( ) ) ;
}
2020-12-08 03:21:24 +08:00
calEdited = false ;
2020-11-11 02:16:16 +08:00
} ) ;
connect ( saveCal , & QAction : : triggered , [ = ] ( ) {
2020-12-08 03:21:24 +08:00
if ( cal . saveToFile ( ) ) {
calEdited = false ;
}
2020-11-11 02:16:16 +08:00
} ) ;
2020-09-13 20:44:45 +08:00
auto calDisable = calMenu - > addAction ( " Disabled " ) ;
calDisable - > setCheckable ( true ) ;
calDisable - > setChecked ( true ) ;
calMenu - > addSeparator ( ) ;
2020-11-11 02:16:16 +08:00
auto calData = calMenu - > addAction ( " Calibration Measurements " ) ;
2020-09-13 20:44:45 +08:00
connect ( calData , & QAction : : triggered , [ = ] ( ) {
2020-10-30 02:27:04 +08:00
StartCalibrationDialog ( ) ;
2020-08-31 04:03:41 +08:00
} ) ;
2020-09-13 20:44:45 +08:00
auto calEditKit = calMenu - > addAction ( " Edit Calibration Kit " ) ;
connect ( calEditKit , & QAction : : triggered , [ = ] ( ) {
2020-11-15 03:43:36 +08:00
cal . getCalibrationKit ( ) . edit ( [ = ] ( ) {
if ( calValid ) {
ApplyCalibration ( cal . getType ( ) ) ;
}
} ) ;
2020-09-13 20:44:45 +08:00
} ) ;
2020-11-28 01:18:31 +08:00
calMenu - > addSeparator ( ) ;
auto calImportTerms = calMenu - > addAction ( " Import error terms as traces " ) ;
calImportTerms - > setEnabled ( false ) ;
connect ( calImportTerms , & QAction : : triggered , [ = ] ( ) {
auto import = new TraceImportDialog ( traceModel , cal . getErrorTermTraces ( ) ) ;
import - > show ( ) ;
} ) ;
auto calImportMeas = calMenu - > addAction ( " Import measurements as traces " ) ;
calImportMeas - > setEnabled ( false ) ;
connect ( calImportMeas , & QAction : : triggered , [ = ] ( ) {
auto import = new TraceImportDialog ( traceModel , cal . getMeasurementTraces ( ) ) ;
import - > show ( ) ;
} ) ;
2021-01-30 04:44:44 +08:00
// portExtension.setCalkit(&cal.getCalibrationKit());
2020-09-13 20:44:45 +08:00
// Tools menu
2020-11-01 06:03:34 +08:00
auto toolsMenu = new QMenu ( " Tools " , window ) ;
2020-09-13 20:44:45 +08:00
window - > menuBar ( ) - > insertMenu ( window - > getUi ( ) - > menuWindow - > menuAction ( ) , toolsMenu ) ;
actions . insert ( toolsMenu - > menuAction ( ) ) ;
auto impedanceMatching = toolsMenu - > addAction ( " Impedance Matching " ) ;
connect ( impedanceMatching , & QAction : : triggered , this , & VNA : : StartImpedanceMatching ) ;
2021-01-30 04:44:44 +08:00
auto confDeembed = toolsMenu - > addAction ( " De-embedding " ) ;
connect ( confDeembed , & QAction : : triggered , & deembedding , & Deembedding : : configure ) ;
2020-09-13 20:44:45 +08:00
2020-11-01 06:03:34 +08:00
defaultCalMenu = new QMenu ( " Default Calibration " , window ) ;
2020-09-14 00:01:32 +08:00
assignDefaultCal = defaultCalMenu - > addAction ( " Assign... " ) ;
removeDefaultCal = defaultCalMenu - > addAction ( " Remove " ) ;
removeDefaultCal - > setEnabled ( false ) ;
defaultCalMenu - > setEnabled ( false ) ;
actions . insert ( window - > getUi ( ) - > menuDevice - > addSeparator ( ) ) ;
window - > getUi ( ) - > menuDevice - > addMenu ( defaultCalMenu ) ;
actions . insert ( defaultCalMenu - > menuAction ( ) ) ;
connect ( assignDefaultCal , & QAction : : triggered , [ = ] ( ) {
2020-09-13 20:44:45 +08:00
if ( window - > getDevice ( ) ) {
auto key = " DefaultCalibration " + window - > getDevice ( ) - > serial ( ) ;
2020-08-31 04:03:41 +08:00
QSettings settings ;
auto filename = QFileDialog : : getOpenFileName ( nullptr , " Load calibration data " , settings . value ( key ) . toString ( ) , " Calibration files (*.cal) " , nullptr , QFileDialog : : DontUseNativeDialog ) ;
if ( ! filename . isEmpty ( ) ) {
settings . setValue ( key , filename ) ;
2020-09-14 00:01:32 +08:00
removeDefaultCal - > setEnabled ( true ) ;
2020-08-31 04:03:41 +08:00
}
}
} ) ;
2020-09-14 00:01:32 +08:00
connect ( removeDefaultCal , & QAction : : triggered , [ = ] ( ) {
2020-08-31 04:03:41 +08:00
QSettings settings ;
2020-09-13 20:44:45 +08:00
settings . remove ( " DefaultCalibration " + window - > getDevice ( ) - > serial ( ) ) ;
2020-09-14 00:01:32 +08:00
removeDefaultCal - > setEnabled ( false ) ;
2020-08-31 04:03:41 +08:00
} ) ;
// Sweep toolbar
2020-09-13 20:44:45 +08:00
auto tb_sweep = new QToolBar ( " Sweep " ) ;
2020-08-31 04:03:41 +08:00
auto eStart = new SIUnitEdit ( " Hz " , " kMG " , 6 ) ;
2020-11-23 19:43:24 +08:00
// calculate width required with expected string length
auto width = QFontMetrics ( eStart - > font ( ) ) . width ( " 3.00000GHz " ) + 15 ;
eStart - > setFixedWidth ( width ) ;
2020-08-31 04:03:41 +08:00
eStart - > setToolTip ( " Start frequency " ) ;
connect ( eStart , & SIUnitEdit : : valueChanged , this , & VNA : : SetStartFreq ) ;
connect ( this , & VNA : : startFreqChanged , eStart , & SIUnitEdit : : setValueQuiet ) ;
tb_sweep - > addWidget ( new QLabel ( " Start: " ) ) ;
tb_sweep - > addWidget ( eStart ) ;
auto eCenter = new SIUnitEdit ( " Hz " , " kMG " , 6 ) ;
2020-11-23 19:43:24 +08:00
eCenter - > setFixedWidth ( width ) ;
2020-08-31 04:03:41 +08:00
eCenter - > setToolTip ( " Center frequency " ) ;
connect ( eCenter , & SIUnitEdit : : valueChanged , this , & VNA : : SetCenterFreq ) ;
connect ( this , & VNA : : centerFreqChanged , eCenter , & SIUnitEdit : : setValueQuiet ) ;
tb_sweep - > addWidget ( new QLabel ( " Center: " ) ) ;
tb_sweep - > addWidget ( eCenter ) ;
auto eStop = new SIUnitEdit ( " Hz " , " kMG " , 6 ) ;
2020-11-23 19:43:24 +08:00
eStop - > setFixedWidth ( width ) ;
2020-08-31 04:03:41 +08:00
eStop - > setToolTip ( " Stop frequency " ) ;
connect ( eStop , & SIUnitEdit : : valueChanged , this , & VNA : : SetStopFreq ) ;
connect ( this , & VNA : : stopFreqChanged , eStop , & SIUnitEdit : : setValueQuiet ) ;
tb_sweep - > addWidget ( new QLabel ( " Stop: " ) ) ;
tb_sweep - > addWidget ( eStop ) ;
auto eSpan = new SIUnitEdit ( " Hz " , " kMG " , 6 ) ;
2020-11-23 19:43:24 +08:00
eSpan - > setFixedWidth ( width ) ;
2020-08-31 04:03:41 +08:00
eSpan - > setToolTip ( " Span " ) ;
connect ( eSpan , & SIUnitEdit : : valueChanged , this , & VNA : : SetSpan ) ;
connect ( this , & VNA : : spanChanged , eSpan , & SIUnitEdit : : setValueQuiet ) ;
tb_sweep - > addWidget ( new QLabel ( " Span: " ) ) ;
tb_sweep - > addWidget ( eSpan ) ;
2020-10-25 06:12:46 +08:00
auto bFull = new QPushButton ( QIcon : : fromTheme ( " zoom-fit-best " , QIcon ( " :/icons/zoom-fit.png " ) ) , " " ) ;
2020-08-31 04:03:41 +08:00
bFull - > setToolTip ( " Full span " ) ;
connect ( bFull , & QPushButton : : clicked , this , & VNA : : SetFullSpan ) ;
tb_sweep - > addWidget ( bFull ) ;
2020-10-25 06:12:46 +08:00
auto bZoomIn = new QPushButton ( QIcon : : fromTheme ( " zoom-in " , QIcon ( " :/icons/zoom-in.png " ) ) , " " ) ;
2020-08-31 04:03:41 +08:00
bZoomIn - > setToolTip ( " Zoom in " ) ;
connect ( bZoomIn , & QPushButton : : clicked , this , & VNA : : SpanZoomIn ) ;
tb_sweep - > addWidget ( bZoomIn ) ;
2020-10-25 06:12:46 +08:00
auto bZoomOut = new QPushButton ( QIcon : : fromTheme ( " zoom-out " , QIcon ( " :/icons/zoom-out.png " ) ) , " " ) ;
2020-08-31 04:03:41 +08:00
bZoomOut - > setToolTip ( " Zoom out " ) ;
connect ( bZoomOut , & QPushButton : : clicked , this , & VNA : : SpanZoomOut ) ;
tb_sweep - > addWidget ( bZoomOut ) ;
2020-09-13 20:44:45 +08:00
window - > addToolBar ( tb_sweep ) ;
toolbars . insert ( tb_sweep ) ;
2020-08-31 04:03:41 +08:00
// Acquisition toolbar
2020-09-13 20:44:45 +08:00
auto tb_acq = new QToolBar ( " Acquisition " ) ;
2020-08-31 04:03:41 +08:00
auto dbm = new QDoubleSpinBox ( ) ;
2020-11-23 19:43:24 +08:00
width = QFontMetrics ( dbm - > font ( ) ) . width ( " -30.00dBm " ) + 20 ;
dbm - > setFixedWidth ( width ) ;
2020-09-30 05:03:20 +08:00
dbm - > setRange ( - 100.0 , 100.0 ) ;
2020-08-31 04:03:41 +08:00
dbm - > setSingleStep ( 0.25 ) ;
dbm - > setSuffix ( " dbm " ) ;
dbm - > setToolTip ( " Stimulus level " ) ;
2020-11-13 01:56:39 +08:00
dbm - > setKeyboardTracking ( false ) ;
2020-08-31 04:03:41 +08:00
connect ( dbm , qOverload < double > ( & QDoubleSpinBox : : valueChanged ) , this , & VNA : : SetSourceLevel ) ;
connect ( this , & VNA : : sourceLevelChanged , dbm , & QDoubleSpinBox : : setValue ) ;
tb_acq - > addWidget ( new QLabel ( " Level: " ) ) ;
tb_acq - > addWidget ( dbm ) ;
auto points = new QSpinBox ( ) ;
points - > setFixedWidth ( 55 ) ;
2020-11-13 01:56:39 +08:00
points - > setRange ( 1 , 9999 ) ;
2020-08-31 04:03:41 +08:00
points - > setSingleStep ( 100 ) ;
points - > setToolTip ( " Points/sweep " ) ;
2020-11-13 01:56:39 +08:00
points - > setKeyboardTracking ( false ) ;
2020-08-31 04:03:41 +08:00
connect ( points , qOverload < int > ( & QSpinBox : : valueChanged ) , this , & VNA : : SetPoints ) ;
2020-11-07 20:22:10 +08:00
connect ( this , & VNA : : pointsChanged , [ = ] ( int p ) {
points - > blockSignals ( true ) ;
points - > setValue ( p ) ;
points - > blockSignals ( false ) ;
} ) ;
2020-08-31 04:03:41 +08:00
tb_acq - > addWidget ( new QLabel ( " Points: " ) ) ;
tb_acq - > addWidget ( points ) ;
auto eBandwidth = new SIUnitEdit ( " Hz " , " k " , 3 ) ;
eBandwidth - > setFixedWidth ( 70 ) ;
eBandwidth - > setToolTip ( " IF bandwidth " ) ;
connect ( eBandwidth , & SIUnitEdit : : valueChanged , this , & VNA : : SetIFBandwidth ) ;
connect ( this , & VNA : : IFBandwidthChanged , eBandwidth , & SIUnitEdit : : setValueQuiet ) ;
tb_acq - > addWidget ( new QLabel ( " IF BW: " ) ) ;
tb_acq - > addWidget ( eBandwidth ) ;
2020-10-23 17:39:07 +08:00
tb_acq - > addWidget ( new QLabel ( " Averaging: " ) ) ;
lAverages = new QLabel ( " 0/ " ) ;
tb_acq - > addWidget ( lAverages ) ;
auto sbAverages = new QSpinBox ;
sbAverages - > setRange ( 1 , 99 ) ;
sbAverages - > setFixedWidth ( 40 ) ;
connect ( sbAverages , qOverload < int > ( & QSpinBox : : valueChanged ) , this , & VNA : : SetAveraging ) ;
connect ( this , & VNA : : averagingChanged , sbAverages , & QSpinBox : : setValue ) ;
tb_acq - > addWidget ( sbAverages ) ;
2020-09-13 20:44:45 +08:00
window - > addToolBar ( tb_acq ) ;
toolbars . insert ( tb_acq ) ;
2020-08-31 04:03:41 +08:00
// Calibration toolbar (and populate calibration menu)
auto tb_cal = new QToolBar ( " Calibration " ) ;
2020-12-08 00:58:13 +08:00
calLabel = new QLabel ( " Calibration: " ) ;
UpdateCalWidget ( ) ;
tb_cal - > addWidget ( calLabel ) ;
2020-08-31 04:03:41 +08:00
auto cbEnableCal = new QCheckBox ;
tb_cal - > addWidget ( cbEnableCal ) ;
auto cbType = new QComboBox ( ) ;
auto calMenuGroup = new QActionGroup ( this ) ;
2020-09-13 20:44:45 +08:00
calMenuGroup - > addAction ( calDisable ) ;
2020-08-31 04:03:41 +08:00
for ( auto type : Calibration : : Types ( ) ) {
cbType - > addItem ( Calibration : : TypeToString ( type ) , ( int ) type ) ;
2020-11-01 06:03:34 +08:00
auto menuAction = new QAction ( Calibration : : TypeToString ( type ) , calMenu ) ;
2020-08-31 04:03:41 +08:00
calMenuGroup - > addAction ( menuAction ) ;
connect ( menuAction , & QAction : : triggered , [ = ] ( ) {
ApplyCalibration ( type ) ;
} ) ;
connect ( this , & VNA : : CalibrationApplied , [ = ] ( Calibration : : Type applied ) {
if ( type = = applied ) {
menuAction - > setChecked ( true ) ;
}
} ) ;
menuAction - > setCheckable ( true ) ;
2020-09-13 20:44:45 +08:00
calMenu - > insertAction ( calDisable , menuAction ) ;
2020-08-31 04:03:41 +08:00
}
auto calToolbarLambda = [ = ] ( ) {
if ( cbEnableCal - > isChecked ( ) ) {
// Get requested calibration type from combobox
ApplyCalibration ( ( Calibration : : Type ) cbType - > itemData ( cbType - > currentIndex ( ) ) . toInt ( ) ) ;
} else {
DisableCalibration ( ) ;
}
} ;
// Calibration connections
connect ( cbEnableCal , & QCheckBox : : stateChanged , calToolbarLambda ) ;
connect ( cbType , qOverload < int > ( & QComboBox : : currentIndexChanged ) , calToolbarLambda ) ;
connect ( this , & VNA : : CalibrationDisabled , [ = ] ( ) {
cbType - > blockSignals ( true ) ;
cbEnableCal - > blockSignals ( true ) ;
2020-09-13 20:44:45 +08:00
calDisable - > setChecked ( true ) ;
2020-08-31 04:03:41 +08:00
cbEnableCal - > setCheckState ( Qt : : CheckState : : Unchecked ) ;
2020-12-08 00:58:13 +08:00
// visually indicate loss of calibration
// cal. file unknown at this moment
UpdateCalWidget ( ) ;
2020-08-31 04:03:41 +08:00
cbType - > blockSignals ( false ) ;
cbEnableCal - > blockSignals ( false ) ;
2020-11-28 01:18:31 +08:00
calImportTerms - > setEnabled ( false ) ;
calImportMeas - > setEnabled ( false ) ;
2020-11-11 02:16:16 +08:00
saveCal - > setEnabled ( false ) ;
2020-08-31 04:03:41 +08:00
} ) ;
2020-09-13 20:44:45 +08:00
connect ( calDisable , & QAction : : triggered , this , & VNA : : DisableCalibration ) ;
2020-08-31 04:03:41 +08:00
connect ( this , & VNA : : CalibrationApplied , [ = ] ( Calibration : : Type applied ) {
cbType - > blockSignals ( true ) ;
cbEnableCal - > blockSignals ( true ) ;
for ( int i = 0 ; i < cbType - > count ( ) ; i + + ) {
if ( cbType - > itemData ( i ) . toInt ( ) = = ( int ) applied ) {
cbType - > setCurrentIndex ( i ) ;
break ;
}
}
cbEnableCal - > setCheckState ( Qt : : CheckState : : Checked ) ;
2020-12-08 00:58:13 +08:00
// restore default look of widget
// on hover, show name of active cal. file
UpdateCalWidget ( ) ;
2020-08-31 04:03:41 +08:00
cbType - > blockSignals ( false ) ;
cbEnableCal - > blockSignals ( false ) ;
2020-11-28 01:18:31 +08:00
calImportTerms - > setEnabled ( true ) ;
calImportMeas - > setEnabled ( true ) ;
2020-11-11 02:16:16 +08:00
saveCal - > setEnabled ( true ) ;
2020-08-31 04:03:41 +08:00
} ) ;
tb_cal - > addWidget ( cbType ) ;
2020-09-13 20:44:45 +08:00
window - > addToolBar ( tb_cal ) ;
toolbars . insert ( tb_cal ) ;
2021-01-30 04:44:44 +08:00
// auto tb_portExtension = portExtension.createToolbar();
// window->addToolBar(tb_portExtension);
// toolbars.insert(tb_portExtension);
2020-10-31 23:52:59 +08:00
2020-09-13 20:44:45 +08:00
2020-11-01 06:03:34 +08:00
markerModel = new TraceMarkerModel ( traceModel , this ) ;
2020-09-13 20:44:45 +08:00
auto tracesDock = new QDockWidget ( " Traces " ) ;
2020-11-25 01:08:00 +08:00
tracesDock - > setWidget ( new TraceWidgetVNA ( traceModel ) ) ;
2020-09-13 20:44:45 +08:00
window - > addDockWidget ( Qt : : LeftDockWidgetArea , tracesDock ) ;
docks . insert ( tracesDock ) ;
auto markerWidget = new MarkerWidget ( * markerModel ) ;
auto markerDock = new QDockWidget ( " Marker " ) ;
markerDock - > setWidget ( markerWidget ) ;
window - > addDockWidget ( Qt : : BottomDockWidgetArea , markerDock ) ;
docks . insert ( markerDock ) ;
// Set initial sweep settings
2020-10-23 03:12:33 +08:00
auto pref = Preferences : : getInstance ( ) ;
2020-09-16 05:22:08 +08:00
if ( pref . Acquisition . alwaysExciteBothPorts ) {
settings . excitePort1 = 1 ;
settings . excitePort2 = 1 ;
} else {
settings . excitePort1 = traceModel . PortExcitationRequired ( 1 ) ;
settings . excitePort2 = traceModel . PortExcitationRequired ( 2 ) ;
}
2020-09-13 20:44:45 +08:00
if ( pref . Startup . RememberSweepSettings ) {
LoadSweepSettings ( ) ;
} else {
settings . f_start = pref . Startup . DefaultSweep . start ;
settings . f_stop = pref . Startup . DefaultSweep . stop ;
ConstrainAndUpdateFrequencies ( ) ;
SetSourceLevel ( pref . Startup . DefaultSweep . excitation ) ;
SetIFBandwidth ( pref . Startup . DefaultSweep . bandwidth ) ;
2020-10-23 17:39:07 +08:00
SetAveraging ( pref . Startup . DefaultSweep . averaging ) ;
2020-09-13 20:44:45 +08:00
SetPoints ( pref . Startup . DefaultSweep . points ) ;
}
2020-09-17 21:51:20 +08:00
// Set ObjectName for toolbars and docks
for ( auto d : findChildren < QDockWidget * > ( ) ) {
d - > setObjectName ( d - > windowTitle ( ) ) ;
}
for ( auto t : findChildren < QToolBar * > ( ) ) {
t - > setObjectName ( t - > windowTitle ( ) ) ;
}
finalize ( central ) ;
2020-09-13 20:44:45 +08:00
}
2020-12-07 23:04:59 +08:00
QString VNA : : getCalStyle ( )
2020-12-07 11:18:01 +08:00
{
Calibration : : InterpolationType interpol = cal . getInterpolation ( settings ) ;
QString style = " " ;
switch ( interpol )
{
case Calibration : : InterpolationType : : Unchanged :
case Calibration : : InterpolationType : : Exact :
case Calibration : : InterpolationType : : Interpolate :
style = " " ;
break ;
case Calibration : : InterpolationType : : Extrapolate :
style = " background-color: yellow " ;
break ;
case Calibration : : InterpolationType : : NoCalibration :
style = " background-color: red " ;
break ;
}
return style ;
}
QString VNA : : getCalToolTip ( )
{
Calibration : : InterpolationType interpol = cal . getInterpolation ( settings ) ;
QString txt = " " ;
switch ( interpol )
{
case Calibration : : InterpolationType : : Unchanged :
case Calibration : : InterpolationType : : Exact :
case Calibration : : InterpolationType : : Interpolate :
case Calibration : : InterpolationType : : Extrapolate :
2020-12-07 23:04:59 +08:00
{
QString lo = Unit : : ToString ( cal . getMinFreq ( ) , " " , " kMG " , 5 ) ;
QString hi = Unit : : ToString ( cal . getMaxFreq ( ) , " " , " kMG " , 5 ) ;
if ( settings . f_start < cal . getMinFreq ( ) ) { lo = " <font color= \" red \" > " + lo + " </font> " ; }
if ( settings . f_stop > cal . getMaxFreq ( ) ) { hi = " <font color= \" red \" > " + hi + " </font> " ; }
txt =
" limits: " + lo + " - " + hi
+ " <br> "
+ " points: " + QString : : number ( cal . getNumPoints ( ) )
+ " <br> "
" file: " + cal . getCurrentCalibrationFile ( ) ;
2020-12-07 11:18:01 +08:00
break ;
2020-12-07 23:04:59 +08:00
}
2020-12-07 11:18:01 +08:00
case Calibration : : InterpolationType : : NoCalibration :
txt = " none " ;
break ;
}
return txt ;
}
2020-12-07 09:44:25 +08:00
2020-09-13 20:44:45 +08:00
void VNA : : deactivate ( )
{
StoreSweepSettings ( ) ;
Mode : : deactivate ( ) ;
}
void VNA : : initializeDevice ( )
{
2020-09-14 00:01:32 +08:00
defaultCalMenu - > setEnabled ( true ) ;
2020-09-13 20:44:45 +08:00
connect ( window - > getDevice ( ) , & Device : : DatapointReceived , this , & VNA : : NewDatapoint , Qt : : UniqueConnection ) ;
// Check if default calibration exists and attempt to load it
QSettings s ;
auto key = " DefaultCalibration " + window - > getDevice ( ) - > serial ( ) ;
if ( s . contains ( key ) ) {
auto filename = s . value ( key ) . toString ( ) ;
2020-11-12 02:13:53 +08:00
qDebug ( ) < < " Attempting to load default calibration file " < < filename ;
2020-09-13 20:44:45 +08:00
if ( QFile : : exists ( filename ) ) {
2020-11-11 02:16:16 +08:00
if ( cal . openFromFile ( filename ) ) {
ApplyCalibration ( cal . getType ( ) ) ;
2021-01-30 04:44:44 +08:00
// portExtension.setCalkit(&cal.getCalibrationKit());
2020-12-01 00:05:15 +08:00
qDebug ( ) < < " Calibration successful from " < < filename ;
} else {
qDebug ( ) < < " Calibration not successfull from: " < < filename ;
2020-11-11 02:16:16 +08:00
}
2020-12-01 00:05:15 +08:00
} else {
qDebug ( ) < < " Calibration file not found: " < < filename ;
2020-09-13 20:44:45 +08:00
}
2020-09-14 00:01:32 +08:00
removeDefaultCal - > setEnabled ( true ) ;
2020-09-13 20:44:45 +08:00
} else {
qDebug ( ) < < " No default calibration file set for this device " ;
2020-09-14 00:01:32 +08:00
removeDefaultCal - > setEnabled ( false ) ;
2020-09-13 20:44:45 +08:00
}
// Configure initial state of device
2020-09-20 16:13:06 +08:00
SettingsChanged ( ) ;
2020-08-31 04:03:41 +08:00
}
2020-09-14 00:01:32 +08:00
void VNA : : deviceDisconnected ( )
{
defaultCalMenu - > setEnabled ( false ) ;
}
2020-12-08 03:21:24 +08:00
void VNA : : shutdown ( )
{
if ( calEdited & & calValid ) {
auto save = InformationBox : : AskQuestion ( " Save calibration? " , " The calibration contains data that has not been saved yet. Do you want to save it before exiting? " , false ) ;
if ( save ) {
cal . saveToFile ( ) ;
}
}
}
2020-12-05 06:49:52 +08:00
nlohmann : : json VNA : : toJSON ( )
{
nlohmann : : json j ;
j [ " traces " ] = traceModel . toJSON ( ) ;
j [ " tiles " ] = central - > toJSON ( ) ;
2020-12-05 19:59:23 +08:00
j [ " markers " ] = markerModel - > toJSON ( ) ;
2021-01-30 04:44:44 +08:00
j [ " de-embedding " ] = deembedding . toJSON ( ) ;
2020-12-05 06:49:52 +08:00
return j ;
}
void VNA : : fromJSON ( nlohmann : : json j )
{
if ( j . contains ( " traces " ) ) {
traceModel . fromJSON ( j [ " traces " ] ) ;
}
if ( j . contains ( " tiles " ) ) {
central - > fromJSON ( j [ " tiles " ] ) ;
}
2020-12-05 19:59:23 +08:00
if ( j . contains ( " markers " ) ) {
markerModel - > fromJSON ( j [ " markers " ] ) ;
}
2021-01-30 04:44:44 +08:00
if ( j . contains ( " de-embedding " ) ) {
deembedding . fromJSON ( j [ " de-embedding " ] ) ;
}
2020-12-05 06:49:52 +08:00
}
2020-09-13 20:44:45 +08:00
using namespace std ;
void VNA : : NewDatapoint ( Protocol : : Datapoint d )
2020-08-31 04:03:41 +08:00
{
2020-10-30 02:27:04 +08:00
d = average . process ( d ) ;
2020-09-13 20:44:45 +08:00
if ( calMeasuring ) {
2020-10-30 02:27:04 +08:00
if ( average . currentSweep ( ) = = averages ) {
// this is the last averaging sweep, use values for calibration
if ( ! calWaitFirst | | d . pointNum = = 0 ) {
calWaitFirst = false ;
cal . addMeasurement ( calMeasurement , d ) ;
if ( d . pointNum = = settings . points - 1 ) {
calMeasuring = false ;
2020-11-12 02:13:53 +08:00
qDebug ( ) < < " Calibration measurement " < < cal . MeasurementToString ( calMeasurement ) < < " complete " ;
2020-10-30 02:27:04 +08:00
emit CalibrationMeasurementComplete ( calMeasurement ) ;
}
2020-08-31 04:03:41 +08:00
}
2020-09-13 20:44:45 +08:00
}
2020-10-30 02:27:04 +08:00
int percentage = ( ( ( average . currentSweep ( ) - 1 ) * 100 ) + ( d . pointNum + 1 ) * 100 / settings . points ) / averages ;
calDialog . setValue ( percentage ) ;
2020-09-13 20:44:45 +08:00
}
if ( calValid ) {
cal . correctMeasurement ( d ) ;
}
2021-01-30 04:44:44 +08:00
deembedding . Deembed ( d ) ;
2020-10-31 23:52:59 +08:00
2020-11-09 04:28:47 +08:00
traceModel . addVNAData ( d , settings ) ;
2020-09-13 20:44:45 +08:00
emit dataChanged ( ) ;
if ( d . pointNum = = settings . points - 1 ) {
2020-10-23 17:39:07 +08:00
UpdateAverageCount ( ) ;
2020-10-20 23:03:49 +08:00
markerModel - > updateMarkers ( ) ;
2020-09-13 20:44:45 +08:00
}
2020-11-24 23:28:57 +08:00
static unsigned int lastPoint = 0 ;
if ( d . pointNum > 0 & & d . pointNum ! = lastPoint + 1 ) {
qWarning ( ) < < " Got point " < < d . pointNum < < " but last received point was " < < lastPoint < < " ( " < < ( d . pointNum - lastPoint - 1 ) < < " missed points) " ;
}
lastPoint = d . pointNum ;
2020-09-13 20:44:45 +08:00
}
2020-10-23 17:39:07 +08:00
void VNA : : UpdateAverageCount ( )
2020-09-13 20:44:45 +08:00
{
2020-10-23 17:39:07 +08:00
lAverages - > setText ( QString : : number ( average . getLevel ( ) ) + " / " ) ;
2020-08-31 04:03:41 +08:00
}
2020-10-30 02:27:04 +08:00
void VNA : : SettingsChanged ( std : : function < void ( Device : : TransmissionResult ) > cb )
2020-08-31 04:03:41 +08:00
{
2020-10-23 03:12:33 +08:00
settings . suppressPeaks = Preferences : : getInstance ( ) . Acquisition . suppressPeaks ? 1 : 0 ;
2020-09-13 20:44:45 +08:00
if ( window - > getDevice ( ) ) {
2020-12-19 01:52:38 +08:00
window - > getDevice ( ) - > Configure ( settings , [ = ] ( Device : : TransmissionResult res ) {
// device received command, reset traces now
average . reset ( settings . points ) ;
traceModel . clearVNAData ( ) ;
UpdateAverageCount ( ) ;
UpdateCalWidget ( ) ;
if ( cb ) {
cb ( res ) ;
}
} ) ;
2020-09-13 20:44:45 +08:00
}
2020-09-18 01:54:03 +08:00
emit traceModel . SpanChanged ( settings . f_start , settings . f_stop ) ;
2020-08-31 04:03:41 +08:00
}
void VNA : : StartImpedanceMatching ( )
{
auto dialog = new ImpedanceMatchDialog ( * markerModel ) ;
dialog - > show ( ) ;
}
void VNA : : SetStartFreq ( double freq )
{
settings . f_start = freq ;
if ( settings . f_stop < freq ) {
settings . f_stop = freq ;
}
ConstrainAndUpdateFrequencies ( ) ;
}
void VNA : : SetStopFreq ( double freq )
{
settings . f_stop = freq ;
if ( settings . f_start > freq ) {
settings . f_start = freq ;
}
ConstrainAndUpdateFrequencies ( ) ;
}
void VNA : : SetCenterFreq ( double freq )
{
auto old_span = settings . f_stop - settings . f_start ;
2020-11-13 01:56:39 +08:00
if ( freq - old_span / 2 < = Device : : Info ( ) . limits_minFreq ) {
// would shift start frequency below minimum
2020-08-31 04:03:41 +08:00
settings . f_start = 0 ;
settings . f_stop = 2 * freq ;
2020-11-13 01:56:39 +08:00
} else if ( freq + old_span / 2 > = Device : : Info ( ) . limits_maxFreq ) {
// would shift stop frequency above maximum
settings . f_start = 2 * freq - Device : : Info ( ) . limits_maxFreq ;
settings . f_stop = Device : : Info ( ) . limits_maxFreq ;
} else {
settings . f_start = freq - old_span / 2 ;
settings . f_stop = freq + old_span / 2 ;
2020-08-31 04:03:41 +08:00
}
ConstrainAndUpdateFrequencies ( ) ;
}
void VNA : : SetSpan ( double span )
{
auto old_center = ( settings . f_start + settings . f_stop ) / 2 ;
2020-11-13 01:56:39 +08:00
if ( old_center < Device : : Info ( ) . limits_minFreq + span / 2 ) {
// would shift start frequency below minimum
settings . f_start = Device : : Info ( ) . limits_minFreq ;
settings . f_stop = Device : : Info ( ) . limits_minFreq + span ;
} else if ( old_center > Device : : Info ( ) . limits_maxFreq - span / 2 ) {
// would shift stop frequency above maximum
settings . f_start = Device : : Info ( ) . limits_maxFreq - span ;
settings . f_stop = Device : : Info ( ) . limits_maxFreq ;
2020-08-31 04:03:41 +08:00
} else {
2020-11-13 01:56:39 +08:00
settings . f_start = old_center - span / 2 ;
settings . f_stop = settings . f_start + span ;
2020-08-31 04:03:41 +08:00
}
ConstrainAndUpdateFrequencies ( ) ;
}
void VNA : : SetFullSpan ( )
{
2020-11-07 20:22:10 +08:00
settings . f_start = Device : : Info ( ) . limits_minFreq ;
settings . f_stop = Device : : Info ( ) . limits_maxFreq ;
2020-08-31 04:03:41 +08:00
ConstrainAndUpdateFrequencies ( ) ;
}
void VNA : : SpanZoomIn ( )
{
auto center = ( settings . f_start + settings . f_stop ) / 2 ;
auto old_span = settings . f_stop - settings . f_start ;
settings . f_start = center - old_span / 4 ;
settings . f_stop = center + old_span / 4 ;
ConstrainAndUpdateFrequencies ( ) ;
}
void VNA : : SpanZoomOut ( )
{
auto center = ( settings . f_start + settings . f_stop ) / 2 ;
auto old_span = settings . f_stop - settings . f_start ;
if ( center > old_span ) {
settings . f_start = center - old_span ;
} else {
settings . f_start = 0 ;
}
settings . f_stop = center + old_span ;
ConstrainAndUpdateFrequencies ( ) ;
}
void VNA : : SetSourceLevel ( double level )
{
2020-11-07 20:22:10 +08:00
if ( level > Device : : Info ( ) . limits_cdbm_max / 100.0 ) {
level = Device : : Info ( ) . limits_cdbm_max / 100.0 ;
} else if ( level < Device : : Info ( ) . limits_cdbm_min / 100.0 ) {
level = Device : : Info ( ) . limits_cdbm_min / 100.0 ;
2020-08-31 04:03:41 +08:00
}
emit sourceLevelChanged ( level ) ;
settings . cdbm_excitation = level * 100 ;
SettingsChanged ( ) ;
}
void VNA : : SetPoints ( unsigned int points )
{
2020-11-07 20:22:10 +08:00
if ( points > Device : : Info ( ) . limits_maxPoints ) {
points = Device : : Info ( ) . limits_maxPoints ;
} else if ( points < 2 ) {
2020-11-03 01:12:06 +08:00
points = 2 ;
2020-08-31 04:03:41 +08:00
}
emit pointsChanged ( points ) ;
settings . points = points ;
SettingsChanged ( ) ;
}
void VNA : : SetIFBandwidth ( double bandwidth )
{
2020-11-07 20:22:10 +08:00
if ( bandwidth > Device : : Info ( ) . limits_maxIFBW ) {
bandwidth = Device : : Info ( ) . limits_maxIFBW ;
} else if ( bandwidth < Device : : Info ( ) . limits_minIFBW ) {
bandwidth = Device : : Info ( ) . limits_minIFBW ;
2020-09-27 05:34:31 +08:00
}
2020-08-31 04:03:41 +08:00
settings . if_bandwidth = bandwidth ;
emit IFBandwidthChanged ( bandwidth ) ;
SettingsChanged ( ) ;
}
void VNA : : SetAveraging ( unsigned int averages )
{
this - > averages = averages ;
average . setAverages ( averages ) ;
emit averagingChanged ( averages ) ;
SettingsChanged ( ) ;
}
2020-09-16 05:22:08 +08:00
void VNA : : ExcitationRequired ( bool port1 , bool port2 )
{
2020-10-23 03:12:33 +08:00
if ( Preferences : : getInstance ( ) . Acquisition . alwaysExciteBothPorts ) {
2020-09-16 05:22:08 +08:00
port1 = true ;
port2 = true ;
}
// check if settings actually changed
if ( settings . excitePort1 ! = port1
| | settings . excitePort2 ! = port2 ) {
settings . excitePort1 = port1 ;
settings . excitePort2 = port2 ;
SettingsChanged ( ) ;
}
}
2020-08-31 04:03:41 +08:00
void VNA : : DisableCalibration ( bool force )
{
if ( calValid | | force ) {
calValid = false ;
emit CalibrationDisabled ( ) ;
}
}
void VNA : : ApplyCalibration ( Calibration : : Type type )
{
if ( cal . calculationPossible ( type ) ) {
try {
2020-10-03 19:01:59 +08:00
if ( cal . constructErrorTerms ( type ) ) {
calValid = true ;
emit CalibrationApplied ( type ) ;
2020-11-12 02:13:53 +08:00
} else {
DisableCalibration ( true ) ;
2020-10-03 19:01:59 +08:00
}
2020-08-31 04:03:41 +08:00
} catch ( runtime_error e ) {
2020-11-01 06:03:34 +08:00
QMessageBox : : critical ( window , " Calibration failure " , e . what ( ) ) ;
2020-08-31 04:03:41 +08:00
DisableCalibration ( true ) ;
}
} else {
// Not all required traces available
2020-11-19 05:47:38 +08:00
InformationBox : : ShowMessage ( " Missing calibration measurements " , " Not all calibration measurements for this type of calibration have been taken. The calibration can be enabled after the missing measurements have been acquired. " ) ;
2020-08-31 04:03:41 +08:00
DisableCalibration ( true ) ;
2020-10-30 02:27:04 +08:00
StartCalibrationDialog ( type ) ;
2020-08-31 04:03:41 +08:00
}
}
void VNA : : StartCalibrationMeasurement ( Calibration : : Measurement m )
{
2020-10-30 02:27:04 +08:00
auto device = window - > getDevice ( ) ;
if ( ! device ) {
return ;
}
// Stop sweep
StopSweep ( ) ;
2020-11-12 02:13:53 +08:00
qDebug ( ) < < " Taking " < < Calibration : : MeasurementToString ( m ) < < " measurement " ;
calMeasurement = m ;
2020-08-31 04:03:41 +08:00
// Delete any already captured data of this measurement
cal . clearMeasurement ( m ) ;
calWaitFirst = true ;
QString text = " Measuring \" " ;
text . append ( Calibration : : MeasurementToString ( m ) ) ;
text . append ( " \" parameters. " ) ;
calDialog . setLabelText ( text ) ;
calDialog . setCancelButtonText ( " Abort " ) ;
calDialog . setWindowTitle ( " Taking calibration measurement... " ) ;
calDialog . setValue ( 0 ) ;
calDialog . setWindowModality ( Qt : : ApplicationModal ) ;
// always show the dialog
calDialog . setMinimumDuration ( 0 ) ;
connect ( & calDialog , & QProgressDialog : : canceled , [ = ] ( ) {
// the user aborted the calibration measurement
calMeasuring = false ;
cal . clearMeasurement ( calMeasurement ) ;
} ) ;
2020-10-30 02:27:04 +08:00
// Trigger sweep to start from beginning
SettingsChanged ( [ = ] ( Device : : TransmissionResult ) {
// enable calibration measurement only in transmission callback (prevents accidental sampling of data which was still being processed)
calMeasuring = true ;
} ) ;
2020-12-08 03:21:24 +08:00
calEdited = true ;
2020-09-12 18:17:35 +08:00
}
2020-08-31 04:03:41 +08:00
void VNA : : ConstrainAndUpdateFrequencies ( )
{
2020-12-18 22:03:01 +08:00
auto pref = Preferences : : getInstance ( ) ;
double maxFreq ;
if ( pref . Acquisition . harmonicMixing ) {
maxFreq = Device : : Info ( ) . limits_maxFreqHarmonic ;
} else {
maxFreq = Device : : Info ( ) . limits_maxFreq ;
}
if ( settings . f_stop > maxFreq ) {
settings . f_stop = maxFreq ;
2020-08-31 04:03:41 +08:00
}
if ( settings . f_start > settings . f_stop ) {
settings . f_start = settings . f_stop ;
}
2020-11-07 20:22:10 +08:00
if ( settings . f_start < Device : : Info ( ) . limits_minFreq ) {
settings . f_start = Device : : Info ( ) . limits_minFreq ;
2020-09-27 05:34:31 +08:00
}
2020-08-31 04:03:41 +08:00
emit startFreqChanged ( settings . f_start ) ;
emit stopFreqChanged ( settings . f_stop ) ;
emit spanChanged ( settings . f_stop - settings . f_start ) ;
emit centerFreqChanged ( ( settings . f_stop + settings . f_start ) / 2 ) ;
SettingsChanged ( ) ;
}
2020-09-12 05:07:15 +08:00
void VNA : : LoadSweepSettings ( )
{
2020-10-23 03:12:33 +08:00
auto pref = Preferences : : getInstance ( ) ;
2020-09-12 05:07:15 +08:00
QSettings s ;
settings . f_start = s . value ( " SweepStart " , pref . Startup . DefaultSweep . start ) . toULongLong ( ) ;
settings . f_stop = s . value ( " SweepStop " , pref . Startup . DefaultSweep . stop ) . toULongLong ( ) ;
SetPoints ( s . value ( " SweepPoints " , pref . Startup . DefaultSweep . points ) . toInt ( ) ) ;
2020-11-01 06:03:34 +08:00
SetIFBandwidth ( s . value ( " SweepBandwidth " , pref . Startup . DefaultSweep . bandwidth ) . toUInt ( ) ) ;
2020-10-23 17:39:07 +08:00
SetAveraging ( s . value ( " SweepAveraging " , pref . Startup . DefaultSweep . averaging ) . toInt ( ) ) ;
2020-09-12 05:07:15 +08:00
SetSourceLevel ( s . value ( " SweepLevel " , pref . Startup . DefaultSweep . excitation ) . toDouble ( ) ) ;
2020-11-01 06:03:34 +08:00
ConstrainAndUpdateFrequencies ( ) ;
2020-09-12 05:07:15 +08:00
}
void VNA : : StoreSweepSettings ( )
{
QSettings s ;
s . setValue ( " SweepStart " , static_cast < unsigned long long > ( settings . f_start ) ) ;
s . setValue ( " SweepStop " , static_cast < unsigned long long > ( settings . f_stop ) ) ;
s . setValue ( " SweepBandwidth " , settings . if_bandwidth ) ;
s . setValue ( " SweepPoints " , settings . points ) ;
2020-10-23 17:39:07 +08:00
s . setValue ( " SweepAveraging " , averages ) ;
2020-09-12 05:07:15 +08:00
s . setValue ( " SweepLevel " , ( double ) settings . cdbm_excitation / 100.0 ) ;
}
2020-10-30 02:27:04 +08:00
void VNA : : StopSweep ( )
{
if ( window - > getDevice ( ) ) {
window - > getDevice ( ) - > SetIdle ( ) ;
}
}
void VNA : : StartCalibrationDialog ( Calibration : : Type type )
{
2020-11-20 04:17:29 +08:00
auto traceDialog = new CalibrationTraceDialog ( & cal , settings , type ) ;
2020-10-30 02:27:04 +08:00
connect ( traceDialog , & CalibrationTraceDialog : : triggerMeasurement , this , & VNA : : StartCalibrationMeasurement ) ;
connect ( traceDialog , & CalibrationTraceDialog : : applyCalibration , this , & VNA : : ApplyCalibration ) ;
connect ( this , & VNA : : CalibrationMeasurementComplete , traceDialog , & CalibrationTraceDialog : : measurementComplete ) ;
2020-11-11 02:16:16 +08:00
connect ( traceDialog , & CalibrationTraceDialog : : calibrationInvalidated , [ = ] ( ) {
DisableCalibration ( true ) ;
InformationBox : : ShowMessage ( " Calibration disabled " , " The currently active calibration is no longer supported by the available measurements and was disabled. " ) ;
} ) ;
2020-10-30 02:27:04 +08:00
traceDialog - > show ( ) ;
}
2020-12-08 00:58:13 +08:00
void VNA : : UpdateCalWidget ( )
{
calLabel - > setStyleSheet ( getCalStyle ( ) ) ;
calLabel - > setToolTip ( getCalToolTip ( ) ) ;
}