back to polygonf
git-svn-id: svn://db.shs.com.ru/libs@7 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -206,11 +206,13 @@ void KX_Pult::setControlsEnable(bool enable) {
|
|||||||
|
|
||||||
|
|
||||||
void KX_Pult::setX(const KX_X_Data & data) {
|
void KX_Pult::setX(const KX_X_Data & data) {
|
||||||
|
ui->graphic->lock();
|
||||||
for (int i = 0; i < KX_X_PACKET_NUM; ++i) {
|
for (int i = 0; i < KX_X_PACKET_NUM; ++i) {
|
||||||
if (!isNormalDouble(data.x_data[i])) continue;
|
if (!isNormalDouble(data.x_data[i])) continue;
|
||||||
ui->graphic->addPoint(data.x_data[i], i, false);
|
ui->graphic->addPoint(data.x_data[i], i, false);
|
||||||
values[i]->setText(QString("(%1): %2").arg(data.x_num[i]).arg(data.x_data[i]));
|
values[i]->setText(QString("(%1): %2").arg(data.x_num[i]).arg(data.x_data[i]));
|
||||||
}
|
}
|
||||||
|
ui->graphic->unlock();
|
||||||
if (!isPause) {
|
if (!isPause) {
|
||||||
need_update = true;
|
need_update = true;
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-11
@@ -155,6 +155,7 @@ void Graphic::timerEvent(QTimerEvent * ) {
|
|||||||
|
|
||||||
void Graphic::canvasPaintEvent(QPaintEvent * ) {
|
void Graphic::canvasPaintEvent(QPaintEvent * ) {
|
||||||
if (is_lines_update) return;
|
if (is_lines_update) return;
|
||||||
|
QMutexLocker ml(&mutex_);
|
||||||
static int pwid = 0, phei = 0;
|
static int pwid = 0, phei = 0;
|
||||||
int wid = canvas->width(), hei = canvas->height();
|
int wid = canvas->width(), hei = canvas->height();
|
||||||
lastw = wid;
|
lastw = wid;
|
||||||
@@ -446,6 +447,7 @@ void Graphic::setPaused(bool yes) {
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < graphics.size(); ++i) {
|
for (int i = 0; i < graphics.size(); ++i) {
|
||||||
graphics[i].polyline_pause = graphics[i].polyline;
|
graphics[i].polyline_pause = graphics[i].polyline;
|
||||||
|
graphics[i].polyline_pause.detach();
|
||||||
graphics[i].max_x_pause = graphics[i].max_x;
|
graphics[i].max_x_pause = graphics[i].max_x;
|
||||||
}
|
}
|
||||||
timer_pause = startTimer(40);
|
timer_pause = startTimer(40);
|
||||||
@@ -456,7 +458,7 @@ void Graphic::setHistorySize(double val) {
|
|||||||
history = val;
|
history = val;
|
||||||
double x;
|
double x;
|
||||||
for (int i = 0; i < graphics.size(); ++i) {
|
for (int i = 0; i < graphics.size(); ++i) {
|
||||||
QList<QPointF> & pol(graphics[i].polyline);
|
QPolygonF & pol(graphics[i].polyline);
|
||||||
if (pol.isEmpty()) continue;
|
if (pol.isEmpty()) continue;
|
||||||
x = pol.back().x() - history;
|
x = pol.back().x() - history;
|
||||||
for (int j = pol.size() - 2; j >= 0 ; --j)
|
for (int j = pol.size() - 2; j >= 0 ; --j)
|
||||||
@@ -538,7 +540,7 @@ void Graphic::addPoint(const QPointF & p, int graphic, bool update_) {
|
|||||||
void Graphic::setGraphicData(const QVector<QPointF> & g, int graphic, bool update_) {
|
void Graphic::setGraphicData(const QVector<QPointF> & g, int graphic, bool update_) {
|
||||||
if (graphic >= graphics.size() || graphic < 0) return;
|
if (graphic >= graphics.size() || graphic < 0) return;
|
||||||
graphics[graphic].polyline.clear();
|
graphics[graphic].polyline.clear();
|
||||||
graphics[graphic].polyline = g.toList();
|
graphics[graphic].polyline = g;
|
||||||
if (graphics.at(graphic).polyline.size() == 0) {
|
if (graphics.at(graphic).polyline.size() == 0) {
|
||||||
graphics[graphic].max_x = 0.;
|
graphics[graphic].max_x = 0.;
|
||||||
tick(graphic, false, update_);
|
tick(graphic, false, update_);
|
||||||
@@ -662,7 +664,7 @@ void Graphic::setHistogramData(const QVector<float> & g, int graphic) {
|
|||||||
//if (ci >= ic) ci = ic - 1;
|
//if (ci >= ic) ci = ic - 1;
|
||||||
hist[ci]++;
|
hist[ci]++;
|
||||||
}
|
}
|
||||||
QList<QPointF> & cpol(graphics[graphic].polyline);
|
QPolygonF & cpol(graphics[graphic].polyline);
|
||||||
if (hist.size() == 1 || range == 0.) {
|
if (hist.size() == 1 || range == 0.) {
|
||||||
cpol << QPointF(min - 0.5, 0.) << QPointF(min - 0.25, 0.);
|
cpol << QPointF(min - 0.5, 0.) << QPointF(min - 0.25, 0.);
|
||||||
cpol << QPointF(min - 0.25, hist[0]) << QPointF(min + 0.25, hist[0]);
|
cpol << QPointF(min - 0.25, hist[0]) << QPointF(min + 0.25, hist[0]);
|
||||||
@@ -684,7 +686,7 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou
|
|||||||
bool isRangeX = (start_x != end_x), isRangeY = (start_y != end_y);
|
bool isRangeX = (start_x != end_x), isRangeY = (start_y != end_y);
|
||||||
bool isEmpty = true, anyVisible = false, isTimeLimit = (visible_time > 0.) && !(isRangeX || isRangeY);
|
bool isEmpty = true, anyVisible = false, isTimeLimit = (visible_time > 0.) && !(isRangeX || isRangeY);
|
||||||
foreach (const GraphicType & t, graphics) {
|
foreach (const GraphicType & t, graphics) {
|
||||||
const QList<QPointF> & pol(pause_ ? t.polyline_pause : t.polyline);
|
const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline);
|
||||||
if (!pol.isEmpty()) {
|
if (!pol.isEmpty()) {
|
||||||
isEmpty = false;
|
isEmpty = false;
|
||||||
break;
|
break;
|
||||||
@@ -704,7 +706,7 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou
|
|||||||
vx -= visible_time;
|
vx -= visible_time;
|
||||||
foreach (const GraphicType & t, graphics) {
|
foreach (const GraphicType & t, graphics) {
|
||||||
if (!t.visible) continue;
|
if (!t.visible) continue;
|
||||||
const QList<QPointF> & pol(pause_ ? t.polyline_pause : t.polyline);
|
const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline);
|
||||||
for (int i = 0; i < pol.size(); i++) {
|
for (int i = 0; i < pol.size(); i++) {
|
||||||
cx = pol[i].x();
|
cx = pol[i].x();
|
||||||
cy = pol[i].y();
|
cy = pol[i].y();
|
||||||
@@ -869,10 +871,10 @@ void Graphic::drawGraphics() {
|
|||||||
QTransform mat = painter->transform();
|
QTransform mat = painter->transform();
|
||||||
painter->resetTransform();
|
painter->resetTransform();
|
||||||
painter->setWorldMatrixEnabled(false);
|
painter->setWorldMatrixEnabled(false);
|
||||||
QList<QPointF> cpol;
|
QPolygonF cpol;
|
||||||
for (int i = 0; i < graphics.size(); ++i) {
|
for (int i = 0; i < graphics.size(); ++i) {
|
||||||
GraphicType & t(graphics[i]);
|
GraphicType & t(graphics[i]);
|
||||||
QList<QPointF> & rpol(pause_ ? t.polyline_pause : t.polyline);
|
QPolygonF & rpol(pause_ ? t.polyline_pause : t.polyline);
|
||||||
if (t.visible && !rpol.isEmpty()) {
|
if (t.visible && !rpol.isEmpty()) {
|
||||||
pw = t.pen.widthF();
|
pw = t.pen.widthF();
|
||||||
if (t.lines) {
|
if (t.lines) {
|
||||||
@@ -883,16 +885,16 @@ void Graphic::drawGraphics() {
|
|||||||
painter->setBrush(t.fill_color);
|
painter->setBrush(t.fill_color);
|
||||||
//cpol.push_front(QPointF(cpol.front().x(), 0.));
|
//cpol.push_front(QPointF(cpol.front().x(), 0.));
|
||||||
//cpol.push_back(QPointF(cpol.back().x(), 0.));
|
//cpol.push_back(QPointF(cpol.back().x(), 0.));
|
||||||
painter->drawPolygon(mat.map(QPolygonF(cpol.toVector())));
|
painter->drawPolygon(mat.map(cpol));
|
||||||
} else
|
} else
|
||||||
painter->drawPolyline(mat.map(QPolygonF(rpol.toVector())));
|
painter->drawPolyline(mat.map(rpol));
|
||||||
}
|
}
|
||||||
if (t.points) {
|
if (t.points) {
|
||||||
if (qRound(t.pointWidth) == t.pointWidth) t.pen.setWidth(qRound(t.pointWidth));
|
if (qRound(t.pointWidth) == t.pointWidth) t.pen.setWidth(qRound(t.pointWidth));
|
||||||
else t.pen.setWidthF(t.pointWidth);
|
else t.pen.setWidthF(t.pointWidth);
|
||||||
t.pen.setCosmetic(true);
|
t.pen.setCosmetic(true);
|
||||||
painter->setPen(t.pen);
|
painter->setPen(t.pen);
|
||||||
painter->drawPoints(mat.map(QPolygonF(rpol.toVector())));
|
painter->drawPoints(mat.map(rpol));
|
||||||
if (qRound(pw) == pw) t.pen.setWidth(qRound(pw));
|
if (qRound(pw) == pw) t.pen.setWidth(qRound(pw));
|
||||||
else t.pen.setWidthF(pw);
|
else t.pen.setWidthF(pw);
|
||||||
}
|
}
|
||||||
@@ -1093,7 +1095,7 @@ void Graphic::on_buttonAutofit_clicked() {
|
|||||||
isFit = true;
|
isFit = true;
|
||||||
bool isEmpty = true;
|
bool isEmpty = true;
|
||||||
foreach (const GraphicType & t, graphics) {
|
foreach (const GraphicType & t, graphics) {
|
||||||
const QList<QPointF> & pol(pause_ ? t.polyline_pause : t.polyline);
|
const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline);
|
||||||
if (!pol.isEmpty()) {
|
if (!pol.isEmpty()) {
|
||||||
isEmpty = false;
|
isEmpty = false;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -198,6 +198,8 @@ public:
|
|||||||
QWidget * viewport() const {return canvas;}
|
QWidget * viewport() const {return canvas;}
|
||||||
QByteArray save();
|
QByteArray save();
|
||||||
void load(QByteArray ba);
|
void load(QByteArray ba);
|
||||||
|
void lock() {mutex_.lock();}
|
||||||
|
void unlock() {mutex_.unlock();}
|
||||||
|
|
||||||
void reset() {mutex.lock(); clear(); mutex.unlock();}
|
void reset() {mutex.lock(); clear(); mutex.unlock();}
|
||||||
|
|
||||||
@@ -336,7 +338,7 @@ protected:
|
|||||||
QString pointCoords(QPointF point) {return "(" + QString::number(point.x(), 'f', 3) + " ; " + QString::number(point.y(), 'f', 3) + ")";}
|
QString pointCoords(QPointF point) {return "(" + QString::number(point.x(), 'f', 3) + " ; " + QString::number(point.y(), 'f', 3) + ")";}
|
||||||
|
|
||||||
Ui::Graphic * ui;
|
Ui::Graphic * ui;
|
||||||
QMutex mutex;
|
QMutex mutex, mutex_;
|
||||||
QWidget * canvas;
|
QWidget * canvas;
|
||||||
QImage * buffer;
|
QImage * buffer;
|
||||||
QPainter * painter;
|
QPainter * painter;
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ struct GraphicType {
|
|||||||
}
|
}
|
||||||
//~GraphicType() {delete pb;}
|
//~GraphicType() {delete pb;}
|
||||||
QString name;
|
QString name;
|
||||||
QList<QPointF> polyline;
|
QPolygonF polyline;
|
||||||
QList<QPointF> polyline_pause;
|
QPolygonF polyline_pause;
|
||||||
QPen pen;
|
QPen pen;
|
||||||
QColor fill_color;
|
QColor fill_color;
|
||||||
bool lines;
|
bool lines;
|
||||||
|
|||||||
Reference in New Issue
Block a user