/* * Definition of class responsible for configuring numerical grid data-sets */ NumGridDataSettings::NumGridDataSettings() : gridData_(0) { WTemplate* template_ = new WTemplate(Wt::WString::tr("numgriddata-template"), this); bindBaseToTemplate(template_); typeSelection_ = new WComboBox(this); typeSelection_->addItem("Points"); typeSelection_->addItem("Surface"); template_->bindWidget("datatype", typeSelection_); enableMesh_ = new WCheckBox(this); template_->bindWidget("enablemesh", enableMesh_); penSize_ = new WLineEdit(this); template_->bindWidget("pensize", penSize_); penColor_ = new WComboBox(this); penColor_->addItem("black"); penColor_->addItem("red"); penColor_->addItem("green"); penColor_->addItem("blue"); penColor_->addItem("something"); template_->bindWidget("pencolor", penColor_); // make connections typeSelection_->changed().connect(std::bind([&] () { switch (typeSelection_->currentIndex()) { case 0: gridData_->setType(PointSeries3D); break; case 1: gridData_->setType(SurfaceSeries3D); break; } })); enableMesh_->changed().connect(std::bind([&] () { gridData_->setSurfaceMeshEnabled(enableMesh_->checkState() == Checked); })); penSize_->changed().connect(std::bind([&] () { WPen pen = gridData_->pen(); pen.setWidth(Wt::asNumber(penSize_->text())); gridData_->setPen(pen); })); penColor_->changed().connect(std::bind([&] () { WPen pen = gridData_->pen(); switch (penColor_->currentIndex()) { case 0: pen.setColor(black); break; case 1: pen.setColor(red); break; case 2: pen.setColor(green); break; case 3: pen.setColor(blue); break; } gridData_->setPen(pen); })); }
void PaintBrush::paintEvent(WPaintDevice *paintDevice) { WPainter painter(paintDevice); painter.setRenderHint(WPainter::Antialiasing); WPen pen; pen.setWidth(3); pen.setColor(color_); painter.setPen(pen); if (interactionCount_ == 0 && !actions_.empty()) { drawActions(painter); interactionCount_ = vertexList_.size(); } if (!undo_) { painter.drawPath(path_); } else { drawActions(painter); undo_ = false; update(PaintUpdate); } path_ = WPainterPath(path_.currentPosition()); }
void WGraphicsPolygonItem::paint(WPainter* painter) { WPainterProxy proxy(painter); painter->setPen(data()->pen); painter->setBrush(data()->brush); painter->drawPolygon(data()->polygon); //绘制多边形 if (isSelected()) //多边形被选中 { painter->setPen(CP_PEN); painter->setBrush(CP_BRUSH); //绘制控制点 for (unsigned i=0; i<_cp.size(); ++i) { painter->drawEllipse(WWorldRectF(_cp[i].x() - CP_RADIUS, _cp[i].y() - CP_RADIUS, CP_RADIUS * 2, CP_RADIUS * 2)); painter->drawEllipse(WWorldRectF(data()->polygon[i].x() - CP_RADIUS, data()->polygon[i].y() - CP_RADIUS, CP_RADIUS * 2, CP_RADIUS * 2)); } if (_dragging) //多边形被拖动,绘制拖动后的多边形 { WPen dragPen = data()->pen; WBrush dragBrush = data()->brush; dragPen.setColor(dragPen.color().lighter(2.0)); dragBrush.setColor(dragBrush.color().lighter(2.0)); painter->setPen(dragPen); painter->setBrush(dragBrush); painter->drawPolygon(draggedPolygon(data()->polygon, scene()->dragStartPos(), scene()->attachedPoint(scene()->mousePos()), _select_flag)); } } }
/* * Definition of class responsible for configuring scatterdata-sets (pt-per-pt) */ ScatterDataSettings::ScatterDataSettings() : scatterData_(0) { WTemplate* template_ = new WTemplate(Wt::WString::tr("scatterdata-template"), this); bindBaseToTemplate(template_); enableDroplines_ = new WCheckBox(this); template_->bindWidget("enabledroplines", enableDroplines_); penSize_ = new WLineEdit(this); template_->bindWidget("pensize", penSize_); penColor_ = new WComboBox(this); penColor_->addItem("black"); penColor_->addItem("red"); penColor_->addItem("green"); penColor_->addItem("blue"); penColor_->addItem("something"); template_->bindWidget("pencolor", penColor_); enableDroplines_->changed().connect(std::bind([&] () { scatterData_->setDroplinesEnabled(enableDroplines_->checkState() == Checked); })); penSize_->changed().connect(std::bind([&] () { WPen pen = scatterData_->droplinesPen(); pen.setWidth(Wt::asNumber(penSize_->text())); scatterData_->setDroplinesPen(pen); })); penColor_->changed().connect(std::bind([&] () { WPen pen = scatterData_->droplinesPen(); switch (penColor_->currentIndex()) { case 0: pen.setColor(black); break; case 1: pen.setColor(red); break; case 2: pen.setColor(green); break; case 3: pen.setColor(blue); break; } scatterData_->setDroplinesPen(pen); })); }
void PaintedSlider::paintEvent(WPaintDevice *paintDevice) { if (slider_->tickPosition()) { WPainter painter(paintDevice); int w, h; if (slider_->orientation() == Horizontal) { w = (int)width().toPixels(); h = (int)height().toPixels(); } else { w = (int)height().toPixels(); h = (int)width().toPixels(); painter.translate(0, w); painter.rotate(-90); } int tickInterval = slider_->tickInterval(); int r = range(); if (tickInterval == 0) tickInterval = r / 2; double tickStep = ((double)w - (HANDLE_WIDTH - 10)) / (r / tickInterval); if (tickStep <= 0) return; WPen pen; pen.setColor(WColor(0xd7, 0xd7, 0xd7)); pen.setCapStyle(FlatCap); pen.setWidth(1); painter.setPen(pen); int y1 = h / 4; int y2 = h / 2 - 4; int y3 = h / 2 + 4; int y4 = h - h/4; for (unsigned i = 0; ; ++i) { int x = (HANDLE_WIDTH - 10)/2 + (int) (i * tickStep); if (x > w - (HANDLE_WIDTH - 10)/2) break; if (slider_->tickPosition() & WSlider::TicksAbove) painter.drawLine(x + 0.5, y1, x + 0.5, y2); if (slider_->tickPosition() & WSlider::TicksBelow) painter.drawLine(x + 0.5, y3, x + 0.5, y4); } } }
void PaintBrush::paintEvent(WPaintDevice *paintDevice) { WPainter painter(paintDevice); painter.setRenderHint(WPainter::Antialiasing); WPen pen; pen.setWidth(3); pen.setColor(color_); pen.setCapStyle(FlatCap); pen.setJoinStyle(MiterJoin); painter.setPen(pen); painter.drawPath(path_); path_ = WPainterPath(path_.currentPosition()); }
void WSlider::paintTick(WPainter& painter, int value, int x, int y) { if (!tickPosition_.empty()) { int h = 0; if (orientation_ == Orientation::Horizontal) h = (int)painter.device()->height().toPixels(); else h = (int)painter.device()->width().toPixels(); WPen pen; pen.setColor(WColor(0xd7, 0xd7, 0xd7)); pen.setCapStyle(PenCapStyle::Flat); pen.setWidth(1); painter.setPen(pen); int y1 = h / 4; int y2 = h / 2 - 4; int y3 = h / 2 + 4; int y4 = h - h/4; switch (orientation_) { case Orientation::Horizontal: if (tickPosition_.test(WSlider::TickPosition::TicksAbove)) painter.drawLine(x + 0.5, y1, x + 0.5, y2); if (tickPosition_.test(WSlider::TickPosition::TicksBelow)) painter.drawLine(x + 0.5, y3, x + 0.5, y4); break; case Orientation::Vertical: if (tickPosition_.test(WSlider::TickPosition::TicksAbove)) painter.drawLine(y1, y + 0.5, y2, y + 0.5); if (tickPosition_.test(WSlider::TickPosition::TicksBelow)) painter.drawLine(y3, y + 0.5, y4, y + 0.5); } } }
void WAircraftGlyph::paint(WPainter* painter) { data_type& d = *data(); painter->setBrush(WBrush(Ws::NoBrush)); m_cd.aircraftMatrix = painter->worldTransform(); m_cd.labelMatrix_1 = m_cd.aircraftMatrix.inverted(); const WMatrix& mapToView = m_cd.aircraftMatrix; painter->setWorldTransform(WMatrix()); WColor symbolColor = d.m_SymbolColor; WPointF view_aircraft_pos_f = mapToView.map(d.m_pos); static const double R = 10.0; static const double RS = 15.0; //draw a bigger circle around, when aircraft is selected double x = view_aircraft_pos_f.x(); double y = view_aircraft_pos_f.y(); if (d.m_eSymbolType == SYMBOL_COMBINED/*AIRCRAFT_NOR*/) { painter->setPen(WPen(symbolColor)); if (isSelected()) { painter->drawEllipse(WRectF(x - RS, y - RS, RS * 2, RS * 2)); } //tmp painter->drawEllipse(WRectF(x - R, y - R, R * 2, R * 2)); painter->drawLine(WLineF(x - R, y, x + R, y)); painter->drawLine(WLineF(x, y - R, x, y + R)); //DrawAircraft(painter, view_aircraft_pos); } else if (d.m_eSymbolType == SYMBOL_PRIMARY)//一次雷达 { painter->setPen(WPen(symbolColor)); if (isSelected()) { painter->drawEllipse(WRectF(x - RS, y - RS, RS * 2, RS * 2)); } painter->drawLine(WLineF(x - R, y, x + R, y)); painter->drawLine(WLineF(x, y - R, x, y + R)); } else if (d.m_eSymbolType == SYMBOL_SECONDARY)//二次雷达 { painter->setPen(WPen(symbolColor)); if (isSelected()) { painter->drawEllipse(WRectF(x - RS, y - RS, RS * 2, RS * 2)); } painter->drawEllipse(WRectF(x - R, y - R, R * 2, R * 2)); } else if (d.m_eSymbolType == SYMBOL_PLAN)//计划航迹 { painter->setPen(WPen(symbolColor)); if (isSelected()) { painter->drawEllipse(WRectF(x - RS, y - RS, RS * 2, RS * 2)); } painter->drawRect(WRectF(x - R, y - R, R * 2, R * 2)); } else if (d.m_eSymbolType == SYMBOL_COAST)//进入盲区 { painter->setPen(WPen(symbolColor)); if (isSelected()) { painter->drawEllipse(WRectF(x - RS, y - RS, RS * 2, RS * 2)); } WPen pen; pen.setWidth(4); pen.setColor(WColor(255, 255, 255)); painter->setPen(pen); painter->drawLine(WWorldLineF(x - R, y, x - R / 2, y)); painter->drawLine(WWorldLineF(x + R, y, x + R / 2, y)); painter->drawLine(WWorldLineF(x, y - R, x, y - R / 2)); painter->drawLine(WWorldLineF(x, y + R, x, y + R / 2)); pen.setWidth(1); pen.setColor(symbolColor); painter->setPen(pen); } else if (d.m_eSymbolType == SYMBOL_SPI)//处于SPI告警状态 { painter->setPen(WPen(symbolColor)); if (isSelected()) { painter->drawEllipse(WRectF(x - RS, y - RS, RS * 2, RS * 2)); } painter->drawLine(WLineF(x - R, y, x + R, y)); painter->drawLine(WLineF(x, y - R, x, y + R)); WPen pen; pen.setStyle(Ws::DashLine); pen.setColor(WColor(255, 255, 255)); painter->setPen(pen); painter->drawEllipse(WRectF(x - R, y - R, R * 2, R * 2)); pen.setStyle(Ws::SolidLine); pen.setColor(symbolColor); painter->setPen(pen); } else if (d.m_eSymbolType == SYMBOL_VEHICLE)//车辆航迹(实心三角) { painter->setPen(WPen(symbolColor)); painter->setBrush(WBrush(symbolColor, Ws::SolidPattern)); WPointF Tmppoint; std::vector<WPointF> vPoints; Tmppoint.setXY(x, y - 5); vPoints.push_back(Tmppoint); Tmppoint.setXY(x - 5, y + 5); vPoints.push_back(Tmppoint); Tmppoint.setXY(x + 5, y + 5); vPoints.push_back(Tmppoint); painter->drawPolygon(WWorldPolygonF(vPoints)); painter->setBrush(WBrush(Ws::NoBrush)); if (isSelected()) { painter->drawEllipse(WRectF(x - R, y - R, R * 2, R * 2)); } } else if (d.m_eSymbolType == SYMBOL_ADSB) // ADSB暂定符号(参考Indra手册)实心菱形 { painter->setPen(WPen(symbolColor)); painter->setBrush(WBrush(symbolColor, Ws::SolidPattern)); WPointF Tmppoint; std::vector<WPointF> vPoints; Tmppoint.setXY(x, y - 5); vPoints.push_back(Tmppoint); Tmppoint.setXY(x - 5, y); vPoints.push_back(Tmppoint); Tmppoint.setXY(x, y + 5); vPoints.push_back(Tmppoint); Tmppoint.setXY(x + 5, y); vPoints.push_back(Tmppoint); painter->drawPolygon(WWorldPolygonF(vPoints)); painter->setBrush(WBrush(Ws::NoBrush)); if (isSelected()) { painter->drawEllipse(WRectF(x - R, y - R, R * 2, R * 2)); } } else if (d.m_eSymbolType == SYMBOL_PIC_AIRCRAFT || d.m_eSymbolType == SYMBOL_PIC_HELICOPTER) { painter->setPen(WPen(symbolColor)); painter->setBrush(WBrush(symbolColor, Ws::SolidPattern)); painter->setBrush(WBrush(Ws::NoBrush)); painter->setRenderHint(Ws::SmoothPixmapTransform); WPixmap pixmap(d.m_eSymbolType == SYMBOL_PIC_AIRCRAFT ? ":/plane.png" : ":/helicopter.png"); WPixmap newPixmap = pixmap.xrotated(-90 + d.m_nHeading, Ws::SmoothTransformation); painter->drawPixmap(view_aircraft_pos_f-WPointF(newPixmap.width()/2, newPixmap.height()/2), newPixmap); } WLineF line(WPointF(), d.m_boundingRect.center()); if (line.length() > m_sLineMaxLength) { line.setLength(m_sLineMaxLength); WPointF offPoint = line.p2() - d.m_boundingRect.center(); d.m_boundingRect.translate(offPoint); d.m_showRect.translate(offPoint); } WPointF view_label_pos_f = d.m_boundingRect.bottomLeft() + view_aircraft_pos_f;// aircraft pos + label offset pos WPointF offset_f = d.m_showRect.bottomLeft() - d.m_boundingRect.bottomLeft(); WRectF view_label_rect(WRectF(view_label_pos_f, WSizeF(d.m_boundingRect.width(), d.m_boundingRect.height()))); //标牌避让 if (m_sLabelAvoidance) { const WRectF& r = view_label_rect; Mosaic::Instance().Allocate(reinterpret_cast<int>(this), r.left(), r.bottom(), r.right(), r.top()); } // label show rect指标牌边框显示区域,标牌有时候需要显示边框,边框与内容区域可能不一致,如C显示 WRectF label_show_rect(WRectF(view_label_rect.bottomLeft(), WSizeF(d.m_showRect.width(), d.m_showRect.height()))); label_show_rect.translate(offset_f); //show history // 尾迹点访问外部数据,本应该加锁,由于外部默认分配了很大数据存在,且点数据一致增加到默认最大值 // 内部通过下标访问不存在问题 // 如外部数据容器变小,就必须得加锁保护 if (m_sShowHistoryPoint && d.m_vHistory != NULL && d.m_vHistory->size() > 1) { size_t n = d.m_vHistory->size() - 1; size_t count = (m_sHstNum < n) ? m_sHstNum : n; size_t pos = n - 1; for (size_t i = 0; i < count; ++i, --pos) { static const double R = 0.8; double dx = 0.00; double dy = 0.00; mapToView.map((*d.m_vHistory)[pos]->x(), (*d.m_vHistory)[pos]->y(), &dx, &dy); painter->drawEllipse(WRectF(dx - R, dy - R, R * 2, R * 2)); //尾迹点 } } //show preline if (m_sShowPreLine) { painter->drawLine(WLineF(view_aircraft_pos_f, mapToView.map(d.m_PRLPos))); //预计线 } if (d.m_bShowLabel) { //show linkline (内部包含了外一点与一矩形中心点连线只绘制外一点到矩形边框的算法) DrawLabelLine(painter, view_aircraft_pos_f, label_show_rect); WPainterProxy proxy(painter); painter->setRenderHint(Ws::Antialiasing, false); // 绘制矩形的时候去掉反锯齿,效果更好 painter->setRenderHint(Ws::TextAntialiasing, false); if (d.m_bShowBounding) { painter->setPen(d.m_penBounding); // 标牌边框颜色与航迹符号与文本是分开的 painter->drawRect(label_show_rect); } //show label painter->setFont(m_sLabelFont); m_cache_locker.lock(); // 对访问d.m_blocks进行加锁,网络线程在FormatLable的时候会重新组织m_blocks数据,数据需要同步操作 BOOST_FOREACH(const WBlockData& block, m_blocks) { painter->setPen(block.m_penText); WRectF r = block.m_boundingRect.translated(view_label_pos_f); painter->drawText(r, Ws::AlignCenter, block.m_text); }
void WGraphicsRectItem::paint(WPainter* painter) { WPainterProxy proxy(painter); painter->setRenderHint(Ws::Antialiasing, false); painter->setRenderHint(Ws::TextAntialiasing, false); painter->setWorldTransform(getRotateMatrix(), true); //设置旋转矩阵 painter->setBrush(brush()); painter->setPen(pen()); painter->drawRect(data()->rect); //绘制矩形 if (isSelected()) //矩形被选中,绘制所有的控制点 { painter->drawLine(WWorldLineF(_rotate_pt, WWorldPointF(_rotate_pt.x(), data()->rect.top()))); painter->setPen(CP_PEN); painter->setBrush(CP_BRUSH); for (unsigned i=0; i<array_size(_cp); ++i) { if (i & 1) { painter->drawRect(WWorldRectF(_cp[i].x() - CP_RADIUS, _cp[i].y() - CP_RADIUS, CP_RADIUS * 2, CP_RADIUS * 2)); } else { painter->drawEllipse(WWorldRectF(_cp[i].x() - CP_RADIUS, _cp[i].y() - CP_RADIUS, CP_RADIUS * 2, CP_RADIUS * 2)); } } painter->setBrush(ROTATE_BRUSH); painter->drawEllipse(WWorldRectF(_rotate_pt.x() - CP_RADIUS, _rotate_pt.y() - CP_RADIUS, CP_RADIUS * 2, CP_RADIUS * 2)); } if (_dragging) //矩形在拖动,绘制正在拖动的矩形 { WWorldPointF pos = scene()->attachedPoint(scene()->mousePos()); WPen dragPen = data()->pen; WBrush dragBrush = data()->brush; dragPen.setColor(dragPen.color().lighter(2.0)); dragBrush.setColor(dragBrush.color().lighter(2.0)); painter->setPen(dragPen); painter->setBrush(dragBrush); if (_select_flag != SF_ROTATE) { if (_select_flag != SF_CONTENT || isMovable()) { WWorldPointF offset = pos - scene()->dragStartPos(); const int (&f)[4] = ADJUST_TABLE[bit(_select_flag)]; painter->drawRect(data()->rect.adjusted(offset.x() * f[0], offset.y() * f[1], offset.x() * f[2], offset.y() * f[3])); } } else { painter->setWorldTransform(getRotateMatrix_1(), true); WWorldPointF c = data()->rect.center(); double ag = WWorldLineF(c, pos).angle() - 90; painter->setWorldTransform(WMatrix().translate(-c.x(), -c.y()) * WMatrix().rotate(ag + data()->angle) * WMatrix().translate(c.x(), c.y())); painter->drawRect(data()->rect); } } }