Limit movement of markers to displayed span
This commit is contained in:
parent
a0cacdfbef
commit
93ade5afe6
@ -181,6 +181,10 @@ double TracePolar::nearestTracePoint(Trace *t, QPoint pixel, double *distance)
|
||||
auto samples = t->size();
|
||||
for(unsigned int i=0;i<samples;i++) {
|
||||
auto data = t->sample(i);
|
||||
if(data.x < minimumVisibleFrequency() || data.x > maximumVisibleFrequency()) {
|
||||
// outside of displayed range
|
||||
continue;
|
||||
}
|
||||
data = dataAddOffset(data);
|
||||
auto plotPoint = dataToPixel(data);
|
||||
if (plotPoint.isNull()) {
|
||||
@ -197,7 +201,7 @@ double TracePolar::nearestTracePoint(Trace *t, QPoint pixel, double *distance)
|
||||
}
|
||||
closestDistance = sqrt(closestDistance);
|
||||
|
||||
if(closestIndex > 0) {
|
||||
if(closestIndex > 0 && t->sample(closestIndex-1).x >= minimumVisibleFrequency()) {
|
||||
auto l1 = dataToPixel(dataAddOffset(t->sample(closestIndex-1)));
|
||||
auto l2 = dataToPixel(dataAddOffset(t->sample(closestIndex)));
|
||||
double ratio;
|
||||
@ -207,7 +211,7 @@ double TracePolar::nearestTracePoint(Trace *t, QPoint pixel, double *distance)
|
||||
closestXpos = t->sample(closestIndex-1).x + (t->sample(closestIndex).x - t->sample(closestIndex-1).x) * ratio;
|
||||
}
|
||||
}
|
||||
if(closestIndex < t->size() - 1) {
|
||||
if(closestIndex < t->size() - 1 && t->sample(closestIndex+1).x <= maximumVisibleFrequency()) {
|
||||
auto l1 = dataToPixel(dataAddOffset(t->sample(closestIndex)));
|
||||
auto l2 = dataToPixel(dataAddOffset(t->sample(closestIndex+1)));
|
||||
double ratio;
|
||||
@ -295,6 +299,28 @@ void TracePolar::updateContextMenu()
|
||||
finishContextMenu();
|
||||
}
|
||||
|
||||
double TracePolar::minimumVisibleFrequency()
|
||||
{
|
||||
if(manualFrequencyRange) {
|
||||
return fmin;
|
||||
} else if(limitToSpan) {
|
||||
return sweep_fmin;
|
||||
} else {
|
||||
return std::numeric_limits<double>::lowest();
|
||||
}
|
||||
}
|
||||
|
||||
double TracePolar::maximumVisibleFrequency()
|
||||
{
|
||||
if(manualFrequencyRange) {
|
||||
return fmax;
|
||||
} else if(limitToSpan) {
|
||||
return sweep_fmax;
|
||||
} else {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
}
|
||||
|
||||
bool TracePolar::constrainLineToCircle(QPointF &a, QPointF &b, QPointF center, double radius)
|
||||
{
|
||||
auto distance = [](const QPointF &a, const QPointF &b) {
|
||||
|
@ -49,6 +49,9 @@ protected:
|
||||
virtual void updateContextMenu() override;
|
||||
virtual bool supported(Trace *t) override {Q_UNUSED(t) return false;}
|
||||
|
||||
double minimumVisibleFrequency();
|
||||
double maximumVisibleFrequency();
|
||||
|
||||
// given two points and a circle, the two points are adjusted in such a way that the line they describe
|
||||
// is constrained within the circle. Returns true if there is a remaining line segment in the circle, false
|
||||
// if the line lies completely outside of the circle (or is tangent to the circle)
|
||||
|
@ -90,16 +90,6 @@ void TracePolarChart::draw(QPainter &p) {
|
||||
transform = p.transform();
|
||||
p.restore();
|
||||
|
||||
auto minimumVisibleFrequency = std::numeric_limits<double>::lowest();
|
||||
auto maximumVisibleFrequency = std::numeric_limits<double>::max();
|
||||
if(manualFrequencyRange) {
|
||||
minimumVisibleFrequency = fmin;
|
||||
maximumVisibleFrequency = fmax;
|
||||
} else if(limitToSpan) {
|
||||
minimumVisibleFrequency = sweep_fmin;
|
||||
maximumVisibleFrequency = sweep_fmax;
|
||||
}
|
||||
|
||||
auto drawArc = [&](PolarArc a) {
|
||||
a.constrainToCircle(QPointF(0,0), edgeReflection);
|
||||
auto topleft = dataToPixel(complex<double>(a.center.x() - a.radius, a.center.y() - a.radius));
|
||||
@ -183,7 +173,7 @@ void TracePolarChart::draw(QPainter &p) {
|
||||
for(int i=1;i<nPoints;i++) {
|
||||
auto last = trace->sample(i-1);
|
||||
auto now = trace->sample(i);
|
||||
if ((trace->getDataType() == Trace::DataType::Frequency) && (last.x < minimumVisibleFrequency || now.x > maximumVisibleFrequency)) {
|
||||
if ((trace->getDataType() == Trace::DataType::Frequency) && (last.x < minimumVisibleFrequency() || now.x > maximumVisibleFrequency())) {
|
||||
continue;
|
||||
}
|
||||
if(isnan(now.y.real())) {
|
||||
@ -192,7 +182,7 @@ void TracePolarChart::draw(QPainter &p) {
|
||||
|
||||
if(pref.Graphs.SweepIndicator.hide && !isnan(xSweep) && trace->getSource() == Trace::Source::Live && trace->isVisible() && !trace->isPaused()) {
|
||||
// check if this part of the trace is visible
|
||||
double range = maximumVisibleFrequency - minimumVisibleFrequency;
|
||||
double range = maximumVisibleFrequency() - minimumVisibleFrequency();
|
||||
double afterSweep = now.x - xSweep;
|
||||
if(afterSweep > 0 && afterSweep * 100 / range <= pref.Graphs.SweepIndicator.hidePercent) {
|
||||
// do not display this part of the trace
|
||||
@ -225,7 +215,7 @@ void TracePolarChart::draw(QPainter &p) {
|
||||
if(!m->isVisible()) {
|
||||
continue;
|
||||
}
|
||||
if (m->getPosition() < minimumVisibleFrequency || m->getPosition() > maximumVisibleFrequency) {
|
||||
if (m->getPosition() < minimumVisibleFrequency() || m->getPosition() > maximumVisibleFrequency()) {
|
||||
continue;
|
||||
}
|
||||
if(m->getPosition() < trace->minX() || m->getPosition() > trace->maxX()) {
|
||||
|
@ -239,16 +239,6 @@ void TraceSmithChart::draw(QPainter &p) {
|
||||
transform = p.transform();
|
||||
p.restore();
|
||||
|
||||
auto minimumVisibleFrequency = std::numeric_limits<double>::lowest();
|
||||
auto maximumVisibleFrequency = std::numeric_limits<double>::max();
|
||||
if(manualFrequencyRange) {
|
||||
minimumVisibleFrequency = fmin;
|
||||
maximumVisibleFrequency = fmax;
|
||||
} else if(limitToSpan) {
|
||||
minimumVisibleFrequency = sweep_fmin;
|
||||
maximumVisibleFrequency = sweep_fmax;
|
||||
}
|
||||
|
||||
auto drawArc = [&](SmithChartArc a) {
|
||||
a.constrainToCircle(QPointF(0,0), edgeReflection);
|
||||
auto topleft = dataToPixel(complex<double>(a.center.x() - a.radius, a.center.y() - a.radius));
|
||||
@ -316,7 +306,7 @@ void TraceSmithChart::draw(QPainter &p) {
|
||||
for(int i=1;i<nPoints;i++) {
|
||||
auto last = trace->sample(i-1);
|
||||
auto now = trace->sample(i);
|
||||
if ((trace->getDataType() == Trace::DataType::Frequency) && (last.x < minimumVisibleFrequency || now.x > maximumVisibleFrequency)) {
|
||||
if ((trace->getDataType() == Trace::DataType::Frequency) && (last.x < minimumVisibleFrequency() || now.x > maximumVisibleFrequency())) {
|
||||
continue;
|
||||
}
|
||||
if(isnan(now.y.real())) {
|
||||
@ -325,7 +315,7 @@ void TraceSmithChart::draw(QPainter &p) {
|
||||
|
||||
if(pref.Graphs.SweepIndicator.hide && !isnan(xSweep) && trace->getSource() == Trace::Source::Live && trace->isVisible() && !trace->isPaused()) {
|
||||
// check if this part of the trace is visible
|
||||
double range = maximumVisibleFrequency - minimumVisibleFrequency;
|
||||
double range = maximumVisibleFrequency() - minimumVisibleFrequency();
|
||||
double afterSweep = now.x - xSweep;
|
||||
if(afterSweep > 0 && afterSweep * 100 / range <= pref.Graphs.SweepIndicator.hidePercent) {
|
||||
// do not display this part of the trace
|
||||
@ -361,7 +351,7 @@ void TraceSmithChart::draw(QPainter &p) {
|
||||
// if (m->isTimeDomain()) {
|
||||
// continue;
|
||||
// }
|
||||
if (m->getPosition() < minimumVisibleFrequency || m->getPosition() > maximumVisibleFrequency) {
|
||||
if (m->getPosition() < minimumVisibleFrequency() || m->getPosition() > maximumVisibleFrequency()) {
|
||||
continue;
|
||||
}
|
||||
if(m->getPosition() < trace->minX() || m->getPosition() > trace->maxX()) {
|
||||
|
Loading…
Reference in New Issue
Block a user