kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
rodzic
8108c3e601
commit
a4b47f118d
|
@ -55,6 +55,14 @@ class Chart(QtWidgets.QWidget):
|
|||
def setMarkers(self, markers):
|
||||
self.markers = markers
|
||||
|
||||
@staticmethod
|
||||
def shortenFrequency(frequency):
|
||||
if frequency < 50000:
|
||||
return frequency
|
||||
if frequency < 5000000:
|
||||
return str(round(frequency / 1000)) + "k"
|
||||
return str(round(frequency / 1000000, 1)) + "M"
|
||||
|
||||
|
||||
class PhaseChart(Chart):
|
||||
def __init__(self, name=""):
|
||||
|
@ -123,14 +131,14 @@ class PhaseChart(Chart):
|
|||
qp.drawText(3, 35, str(-min))
|
||||
qp.drawText(3, self.chartHeight+20, str(-max))
|
||||
# At least 100 px between ticks
|
||||
qp.drawText(self.leftMargin-20, 20 + self.chartHeight + 15, PhaseChart.shortenFrequency(fstart))
|
||||
qp.drawText(self.leftMargin-20, 20 + self.chartHeight + 15, Chart.shortenFrequency(fstart))
|
||||
ticks = math.floor(self.chartWidth/100) # Number of ticks does not include the origin
|
||||
for i in range(ticks):
|
||||
x = self.leftMargin + round((i+1)*self.chartWidth/ticks)
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.drawLine(x, 20, x, 20+self.chartHeight+5)
|
||||
qp.setPen(QtCore.Qt.black)
|
||||
qp.drawText(x-20, 20+self.chartHeight+15, PhaseChart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
|
||||
qp.drawText(x-20, 20+self.chartHeight+15, Chart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
|
||||
|
||||
if self.mouselocation != 0:
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor(224,224,224)))
|
||||
|
@ -172,14 +180,6 @@ class PhaseChart(Chart):
|
|||
qp.drawLine(int(x) - 3, int(y) - 3, int(x) + 3, int(y) - 3)
|
||||
#qp.drawPoint(int(x), int(y))
|
||||
|
||||
@staticmethod
|
||||
def shortenFrequency(frequency):
|
||||
if frequency < 50000:
|
||||
return frequency
|
||||
if frequency < 5000000:
|
||||
return str(round(frequency / 1000)) + "k"
|
||||
return str(round(frequency / 1000000, 1)) + "M"
|
||||
|
||||
def mousePressEvent(self, a0: QtGui.QMouseEvent) -> None:
|
||||
self.mouseMoveEvent(a0)
|
||||
|
||||
|
@ -200,3 +200,155 @@ class PhaseChart(Chart):
|
|||
else:
|
||||
self.mouselocation = 0
|
||||
return
|
||||
|
||||
|
||||
class VSWRChart(Chart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__()
|
||||
self.leftMargin = 30
|
||||
self.chartWidth = 360
|
||||
self.chartHeight = 360
|
||||
self.name = name
|
||||
self.fstart = 0
|
||||
self.fstop = 0
|
||||
self.mouselocation = 0
|
||||
|
||||
self.setMinimumSize(self.chartWidth + 20 + self.leftMargin, self.chartHeight + 40)
|
||||
self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding))
|
||||
pal = QtGui.QPalette()
|
||||
pal.setColor(QtGui.QPalette.Background, QtGui.QColor("white"))
|
||||
self.setPalette(pal)
|
||||
self.setAutoFillBackground(True)
|
||||
|
||||
self.marker1Color = QtGui.QColor(255, 0, 20)
|
||||
self.marker2Color = QtGui.QColor(20, 0, 255)
|
||||
|
||||
def resizeEvent(self, a0: QtGui.QResizeEvent) -> None:
|
||||
self.chartWidth = a0.size().width()-20-self.leftMargin
|
||||
self.chartHeight = a0.size().height()-40
|
||||
self.update()
|
||||
|
||||
def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
|
||||
qp = QtGui.QPainter(self)
|
||||
#qp.begin(self) # Apparently not needed?
|
||||
self.drawChart(qp)
|
||||
self.drawValues(qp)
|
||||
qp.end()
|
||||
|
||||
def drawChart(self, qp: QtGui.QPainter):
|
||||
qp.drawText(3, 15, self.name)
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.drawLine(self.leftMargin, 20, self.leftMargin, 20+self.chartHeight+5)
|
||||
qp.drawLine(self.leftMargin-5, 20+self.chartHeight, self.leftMargin+self.chartWidth, 20 + self.chartHeight)
|
||||
|
||||
def drawValues(self, qp: QtGui.QPainter):
|
||||
from NanoVNASaver.NanoVNASaver import NanoVNASaver
|
||||
if len(self.data) == 0 and len(self.reference) == 0:
|
||||
return
|
||||
pen = QtGui.QPen(self.sweepColor)
|
||||
pen.setWidth(2)
|
||||
highlighter = QtGui.QPen(QtGui.QColor(20, 0, 255))
|
||||
highlighter.setWidth(1)
|
||||
if len(self.data) > 0:
|
||||
fstart = self.data[0].freq
|
||||
fstop = self.data[len(self.data)-1].freq
|
||||
else:
|
||||
fstart = self.reference[0].freq
|
||||
fstop = self.reference[len(self.reference) - 1].freq
|
||||
self.fstart = fstart
|
||||
self.fstop = fstop
|
||||
fspan = fstop-fstart
|
||||
# Find scaling
|
||||
minVSWR = 1
|
||||
maxVSWR = 3
|
||||
for d in self.data:
|
||||
_, _, vswr = NanoVNASaver.vswr(d)
|
||||
if vswr > maxVSWR:
|
||||
maxVSWR = vswr
|
||||
maxVSWR = min(25, math.ceil(maxVSWR))
|
||||
span = maxVSWR-minVSWR
|
||||
ticksize = 1
|
||||
if span > 10 and span % 5 == 0:
|
||||
ticksize = 5
|
||||
elif span > 10 and span % 2 == 0:
|
||||
ticksize = 2
|
||||
elif span > 8 and span % 3 == 0:
|
||||
ticksize = 3
|
||||
|
||||
for i in range(minVSWR, maxVSWR, ticksize):
|
||||
y = 30 + round((maxVSWR-i)/span*(self.chartHeight-10))
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.drawLine(self.leftMargin-5, y, self.leftMargin+self.chartWidth, y)
|
||||
qp.drawLine(self.leftMargin - 5, 30, self.leftMargin + self.chartWidth, 30)
|
||||
qp.setPen(QtCore.Qt.black)
|
||||
qp.drawText(3, 35, str(maxVSWR))
|
||||
qp.drawText(3, self.chartHeight+20, str(minVSWR))
|
||||
# At least 100 px between ticks
|
||||
qp.drawText(self.leftMargin-20, 20 + self.chartHeight + 15, Chart.shortenFrequency(fstart))
|
||||
ticks = math.floor(self.chartWidth/100) # Number of ticks does not include the origin
|
||||
for i in range(ticks):
|
||||
x = self.leftMargin + round((i+1)*self.chartWidth/ticks)
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.drawLine(x, 20, x, 20+self.chartHeight+5)
|
||||
qp.setPen(QtCore.Qt.black)
|
||||
qp.drawText(x-20, 20+self.chartHeight+15, Chart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
|
||||
|
||||
if self.mouselocation != 0:
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor(224,224,224)))
|
||||
x = self.leftMargin + 1 + round(self.chartWidth * (self.mouselocation - fstart) / fspan)
|
||||
qp.drawLine(x, 20, x, 20 + self.chartHeight +5)
|
||||
|
||||
qp.setPen(pen)
|
||||
for i in range(len(self.data)):
|
||||
_, _, vswr = NanoVNASaver.vswr(self.data[i])
|
||||
x = self.leftMargin + 1 + round(self.chartWidth/len(self.data) * i)
|
||||
y = 30 + round((maxVSWR-vswr)/span*(self.chartHeight-10))
|
||||
if y < 30:
|
||||
continue
|
||||
qp.drawPoint(int(x), int(y))
|
||||
pen.setColor(self.referenceColor)
|
||||
qp.setPen(pen)
|
||||
for i in range(len(self.reference)):
|
||||
if self.reference[i].freq < fstart or self.reference[i].freq > fstop:
|
||||
continue
|
||||
_, _, vswr = NanoVNASaver.vswr(self.data[i])
|
||||
x = self.leftMargin + 1 + round(self.chartWidth*(self.reference[i].freq - fstart)/fspan)
|
||||
y = 30 + round((maxVSWR - vswr) / span * (self.chartHeight - 10))
|
||||
if y < 30:
|
||||
continue
|
||||
qp.drawPoint(int(x), int(y))
|
||||
# Now draw the markers
|
||||
for m in self.markers:
|
||||
if m.location != -1:
|
||||
highlighter.setColor(m.color)
|
||||
qp.setPen(highlighter)
|
||||
_, _, vswr = NanoVNASaver.vswr(self.data[m.location])
|
||||
x = self.leftMargin + 1 + round(self.chartWidth/len(self.data) * m.location)
|
||||
y = 30 + round((maxVSWR-vswr) / span * (self.chartHeight - 10))
|
||||
if y < 30:
|
||||
continue
|
||||
qp.drawLine(int(x), int(y) + 3, int(x) - 3, int(y) - 3)
|
||||
qp.drawLine(int(x), int(y) + 3, int(x) + 3, int(y) - 3)
|
||||
qp.drawLine(int(x) - 3, int(y) - 3, int(x) + 3, int(y) - 3)
|
||||
#qp.drawPoint(int(x), int(y))
|
||||
|
||||
def mousePressEvent(self, a0: QtGui.QMouseEvent) -> None:
|
||||
self.mouseMoveEvent(a0)
|
||||
|
||||
def mouseMoveEvent(self, a0: QtGui.QMouseEvent) -> None:
|
||||
x = a0.x()
|
||||
absx = x - self.leftMargin
|
||||
if absx < 0 or absx > self.chartWidth:
|
||||
self.mouselocation = 0
|
||||
a0.ignore()
|
||||
return
|
||||
a0.accept()
|
||||
if self.fstop - self.fstart > 0:
|
||||
span = self.fstop - self.fstart
|
||||
step = span/self.chartWidth
|
||||
f = absx * step
|
||||
# self.mouselocation = f
|
||||
self.markers[0].setFrequency(str(round(f)))
|
||||
else:
|
||||
self.mouselocation = 0
|
||||
return
|
|
@ -24,7 +24,7 @@ import serial
|
|||
from PyQt5 import QtWidgets, QtCore, QtGui
|
||||
from serial.tools import list_ports
|
||||
|
||||
from .Chart import Chart, PhaseChart
|
||||
from .Chart import Chart, PhaseChart, VSWRChart
|
||||
from .Calibration import CalibrationWindow, Calibration
|
||||
from .Marker import Marker
|
||||
from .SmithChart import SmithChart
|
||||
|
@ -89,16 +89,20 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
self.s21LogMag = LogMagChart("S21 Gain")
|
||||
self.s11Phase = PhaseChart("S11 Phase")
|
||||
self.s21Phase = PhaseChart("S21 Phase")
|
||||
self.s11VSWR = VSWRChart("S11 VSWR")
|
||||
self.s21VSWR = VSWRChart("S21 VSWR")
|
||||
|
||||
self.s11charts: List[Chart] = []
|
||||
self.s11charts.append(self.s11SmithChart)
|
||||
self.s11charts.append(self.s11LogMag)
|
||||
self.s11charts.append(self.s11Phase)
|
||||
self.s11charts.append(self.s11VSWR)
|
||||
|
||||
self.s21charts: List[Chart] = []
|
||||
self.s21charts.append(self.s21SmithChart)
|
||||
self.s21charts.append(self.s21LogMag)
|
||||
self.s21charts.append(self.s21Phase)
|
||||
self.s21charts.append(self.s21VSWR)
|
||||
|
||||
self.charts = self.s11charts + self.s21charts
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue