Make trace viewer able to handle multiple traces

master
Timothy Pearson 13 years ago
parent b85a292ce0
commit ad5dff2bda

@ -480,7 +480,7 @@ void CommAnalyzerPart::mainEventLoop() {
if (result == "ACK") {
// Update display widget(s)
m_traceWidget->setSamples(trace);
m_traceWidget->setSamples(trace, 0);
postProcessTrace();
m_traceWidget->repaint();
}
@ -590,13 +590,13 @@ void CommAnalyzerPart::postProcessTrace() {
}
void CommAnalyzerPart::updateGraticule() {
m_traceWidget->setNumberOfSamples(m_samplesInTrace);
m_traceWidget->setNumberOfSamples(m_samplesInTrace, 0);
m_traceWidget->setNumberOfHorizontalDivisions(m_hdivs);
m_traceWidget->setNumberOfVerticalDivisions(m_vdivs);
m_leftFrequency = m_centerfreq - (m_spanfreq/2.0);
m_rightFrequency = m_centerfreq + (m_spanfreq/2.0);
m_traceWidget->setDisplayLimits(m_leftFrequency, m_rpower, m_rightFrequency, m_rpower-(m_vscale*m_hdivs));
m_traceWidget->setDisplayLimits(m_leftFrequency, m_rpower, m_rightFrequency, m_rpower-(m_vscale*m_hdivs), 0);
// Also update controls
m_base->saRefLevel->blockSignals(true);

@ -8,14 +8,38 @@
#include <tqpixmap.h>
#include <tqpainter.h>
#define VERIFY_TRACE_ARRAY_SIZE if (traceNumber >= m_traceArray.count()) resizeTraceArray(traceNumber+1);
TraceData::TraceData() {
color = TQColor(0, 255, 0);
numberOfSamples = 0;
leftEdge = 0;
rightEdge = 0;
topEdge = 0;
bottomEdge = 0;
enabled = false;
}
void TraceData::drawTrace(TQPainter* p, int graticule_width, int graticule_height) {
p->setPen(color);
if ((bottomEdge != topEdge) && (enabled)) {
// Draw the points
unsigned int n;
int x,y,x2,y2;
for (n=0; n<numberOfSamples-1; n++) {
x = abs(((n*1.0)/(numberOfSamples-1))*(graticule_width));
y = abs(((sampleArray[n]-topEdge)/(bottomEdge-topEdge))*(graticule_height));
x2 = abs(((n+1*1.0)/(numberOfSamples-1))*(graticule_width));
y2 = abs(((sampleArray[n+1]-topEdge)/(bottomEdge-topEdge))*(graticule_height));
p->drawLine(x, y, x2, y2);
}
}
}
TraceWidget::TraceWidget(TQWidget* parent, const char* name) : TQWidget(parent, name),
m_samples(0),
m_horizDivs(0),
m_vertDivs(0),
m_leftEdge(0),
m_rightEdge(0),
m_topEdge(0),
m_bottomEdge(0),
m_graticulePixmap(0) {
setBackgroundMode(NoBackground);
@ -24,12 +48,14 @@ TraceWidget::TraceWidget(TQWidget* parent, const char* name) : TQWidget(parent,
}
TraceWidget::~TraceWidget() {
//
resizeTraceArray(0);
}
void TraceWidget::setNumberOfSamples(unsigned int samples) {
m_samples = samples;
m_sampleArray.resize(m_samples);
void TraceWidget::setNumberOfSamples(unsigned int samples, uint traceNumber) {
VERIFY_TRACE_ARRAY_SIZE
m_traceArray[traceNumber]->numberOfSamples = samples;
m_traceArray[traceNumber]->sampleArray.resize(samples);
updateGraticule();
}
@ -44,20 +70,67 @@ void TraceWidget::setNumberOfVerticalDivisions(unsigned int divisions) {
updateGraticule();
}
void TraceWidget::setDisplayLimits(double x, double y, double w, double h) {
m_leftEdge = x;
m_rightEdge = w;
m_topEdge = y;
m_bottomEdge = h;
void TraceWidget::setDisplayLimits(double x, double y, double w, double h, uint traceNumber) {
VERIFY_TRACE_ARRAY_SIZE
m_traceArray[traceNumber]->leftEdge = x;
m_traceArray[traceNumber]->rightEdge = w;
m_traceArray[traceNumber]->topEdge = y;
m_traceArray[traceNumber]->bottomEdge = h;
}
TQDoubleArray& TraceWidget::samples(uint traceNumber) {
VERIFY_TRACE_ARRAY_SIZE
return m_traceArray[traceNumber]->sampleArray;
}
void TraceWidget::setSamples(TQDoubleArray& tqda, uint traceNumber) {
VERIFY_TRACE_ARRAY_SIZE
m_traceArray[traceNumber]->sampleArray = tqda;
m_traceArray[traceNumber]->numberOfSamples = tqda.size();
}
TQColor& TraceWidget::traceColor(uint traceNumber) {
VERIFY_TRACE_ARRAY_SIZE
return m_traceArray[traceNumber]->color;
}
void TraceWidget::setTraceColor(TQColor& color, uint traceNumber) {
VERIFY_TRACE_ARRAY_SIZE
m_traceArray[traceNumber]->color = color;
}
TQDoubleArray& TraceWidget::samples() {
return m_sampleArray;
bool TraceWidget::traceEnabled(uint traceNumber) {
VERIFY_TRACE_ARRAY_SIZE
return m_traceArray[traceNumber]->enabled;
}
void TraceWidget::setSamples(TQDoubleArray& tqda) {
m_sampleArray = tqda;
m_samples = tqda.size();
void TraceWidget::setTraceEnabled(bool enabled, uint traceNumber) {
VERIFY_TRACE_ARRAY_SIZE
m_traceArray[traceNumber]->enabled = enabled;
}
void TraceWidget::resizeTraceArray(uint newsize) {
uint oldcount = m_traceArray.count();
if (newsize > oldcount) {
m_traceArray.resize(newsize);
for (uint i=oldcount;i<newsize;i++) {
m_traceArray[i] = new TraceData;
}
}
else {
m_traceArray.resize(newsize);
for (uint i=newsize;i<oldcount;i++) {
delete m_traceArray[i];
}
}
}
void TraceWidget::updateGraticule() {
@ -98,21 +171,14 @@ void TraceWidget::updateGraticule() {
void TraceWidget::paintEvent(TQPaintEvent*) {
TQPainter p(this);
p.setPen(foregroundColor().light(150));
if ((m_graticulePixmap) && (m_bottomEdge != m_topEdge)) {
if (m_graticulePixmap) {
// Draw the graticule pixmap to erase the widget
p.drawPixmap(0, 0, *m_graticulePixmap);
// Draw the points
unsigned int n;
int x,y,x2,y2;
for (n=0; n<m_samples-1; n++) {
x = abs(((n*1.0)/(m_samples-1))*(m_graticulePixmap->width()));
y = abs(((m_sampleArray[n]-m_topEdge)/(m_bottomEdge-m_topEdge))*(m_graticulePixmap->height()));
x2 = abs(((n+1*1.0)/(m_samples-1))*(m_graticulePixmap->width()));
y2 = abs(((m_sampleArray[n+1]-m_topEdge)/(m_bottomEdge-m_topEdge))*(m_graticulePixmap->height()));
p.drawLine(x, y, x2, y2);
// Draw the traces
for (uint trace=0;trace<m_traceArray.count();trace++) {
m_traceArray[trace]->drawTrace(&p, m_graticulePixmap->width(), m_graticulePixmap->height());
}
}
else {

@ -7,6 +7,25 @@
class TQPixmap;
class TraceData
{
public:
TraceData();
void drawTrace(TQPainter* p, int graticule_width, int graticule_height);
public:
TQDoubleArray sampleArray;
unsigned int numberOfSamples;
TQColor color;
bool enabled;
double leftEdge;
double rightEdge;
double topEdge;
double bottomEdge;
};
typedef TQMemArray<TraceData*> TraceList;
class TraceWidget : public TQWidget
{
Q_OBJECT
@ -15,13 +34,17 @@ class TraceWidget : public TQWidget
TraceWidget(TQWidget* = 0, const char* = 0);
~TraceWidget();
void setNumberOfSamples(unsigned int samples);
void setNumberOfSamples(unsigned int samples, uint traceNumber);
void setNumberOfHorizontalDivisions(unsigned int divisions);
void setNumberOfVerticalDivisions(unsigned int divisions);
void setDisplayLimits(double x, double y, double w, double h);
void setDisplayLimits(double x, double y, double w, double h, uint traceNumber);
TQDoubleArray& samples();
void setSamples(TQDoubleArray&);
TQDoubleArray& samples(uint traceNumber);
void setSamples(TQDoubleArray&, uint traceNumber);
TQColor& traceColor(uint traceNumber);
void setTraceColor(TQColor&, uint traceNumber);
bool traceEnabled(uint traceNumber);
void setTraceEnabled(bool enabled, uint traceNumber);
protected:
virtual void paintEvent(TQPaintEvent*);
@ -31,13 +54,11 @@ class TraceWidget : public TQWidget
void updateGraticule();
private:
unsigned int m_samples;
void resizeTraceArray(uint newsize);
private:
unsigned int m_horizDivs;
unsigned int m_vertDivs;
double m_leftEdge;
double m_rightEdge;
double m_topEdge;
double m_bottomEdge;
TQDoubleArray m_sampleArray;
TraceList m_traceArray;
TQPixmap* m_graticulePixmap;
};
Loading…
Cancel
Save