Exemplo n.º 1
0
void WLEMDDrawable3D::osgAddSurface( const WLPositions& positions, const std::vector< WVector3i >& faces )
{
    // draw head surface
    if( m_surfaceChanged )
    {
        m_rootGroup->removeChild( m_surfaceGeode );

        const WLPositions::IndexT nbPositions = positions.size();
        const WLPositions::PositionsT tmp = positions.data() * m_zoomFactor;
        std::vector< WPosition > scaledPos;
        scaledPos.reserve( nbPositions );
        for( WLPositions::IndexT i = 0; i < nbPositions; ++i )
        {
            scaledPos.push_back( WPosition( tmp.col( i ).x(), tmp.col( i ).y(), tmp.col( i ).z() ) );
        }
        WTriangleMesh::SPtr tri;
        if( faces.size() > 0 )
        {
            osg::ref_ptr< osg::Vec3Array > vertices = wge::osgVec3Array( scaledPos );
            std::vector< size_t > triangles;
            triangles.resize( faces.size() * 3 );

            for( size_t i = 0; i < faces.size(); ++i )
            {
                triangles.push_back( faces.at( i ).x() );
                triangles.push_back( faces.at( i ).y() );
                triangles.push_back( faces.at( i ).z() );
            }

            tri = WTriangleMesh::SPtr( new WTriangleMesh( vertices, triangles ) );
            m_surfaceGeometry = wge::convertToOsgGeometry( tri, WColor( 1.0, 1.0, 1.0, 1.0 ), true );
        }
        else
        {
            try
            {
                tri = wge::triangulate( scaledPos, -0.005 );
            }
            catch( const WException& e )
            {
                wlog::error( CLASS ) << "wge::triangulate() " << e.what();
                return;
            }
            m_surfaceGeometry = wge::convertToOsgGeometry( tri, WColor( 1.0, 1.0, 1.0, 1.0 ), true );
        }
        osg::ref_ptr< osg::Vec4Array > colors = new osg::Vec4Array;
        colors->push_back( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ) );
        m_surfaceGeometry->setColorArray( colors );
        m_surfaceGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
        m_surfaceGeometry->setStateSet( m_state );
        osg::ref_ptr< osg::FloatArray > texCoords = new osg::FloatArray;
        texCoords->assign( nbPositions, 0.5f );
        m_surfaceGeometry->setTexCoordArray( 0, texCoords );
        m_surfaceGeometry->setDataVariance( osg::Object::DYNAMIC );

        m_surfaceGeode = new osg::Geode;
        m_surfaceGeode->addDrawable( m_surfaceGeometry );
        m_rootGroup->addChild( m_surfaceGeode );
    }
}
Exemplo n.º 2
0
WColor WStandardPalette::fontColor(int index) const
{
  WColor c = color(index);
  if (c.red() + c.green() + c.blue() > 3*128) {
    return WColor(StandardColor::Black);
  } else
    return WColor(StandardColor::White);
}
Exemplo n.º 3
0
void WBrush::assignFromJSON(const Json::Value &value)
{
  try {
#ifndef WT_TARGET_JAVA
    const Json::Object &o = value;
    const Json::Value &color = o.get("color");
    const Json::Array &col = color;
#else
    const Json::Object &o = static_cast<const Json::Object &>(value);
    const Json::Value &color = o.get("color");
    const Json::Array &col = static_cast<const Json::Array &>(color);
#endif
    if (col.size() == 4 &&
	!col[0].toNumber().isNull() &&
	!col[1].toNumber().isNull() &&
	!col[2].toNumber().isNull() &&
	!col[3].toNumber().isNull()) {
      color_ = WColor(col[0].toNumber().orIfNull(0),
		      col[1].toNumber().orIfNull(0),
		      col[2].toNumber().orIfNull(0),
		      col[3].toNumber().orIfNull(255));
    } else {
      LOG_ERROR("Couldn't convert JSON to WBrush");
    }
  } catch (std::exception& e) {
    LOG_ERROR("Couldn't convert JSON to WBrush: " + std::string(e.what()));
  }
}
void WArcCreator::mousePressEvent(WGraphicsSceneMouseEvent* event)
{
	if (event->button() == Ws::RightButton)
	{
		if (_item)
		{
			scene()->currentLayer()->removeItem(_item, true);
			scene()->currentLayer()->removeItem(_helperItem, true);
		}
		emit finished(0);
		clear();
	}
	else if (event->button() == Ws::LeftButton)
	{
		WWorldPointF pos = event->scenePos();
		if (_step == 0)
		{
			WWorldRectF rect(pos.x()-20, pos.y(), 20, 20);
			_item = scene()->currentLayer()->addArc(rect, 30, 150, WCreatorSettings::instance().pen(), true);
			_helperItem = scene()->currentLayer()->addRect(rect, 0.0, WPen(Ws::DashLine, WColor(0, 0, 255), 1.0), WBrush(), true);
			emit geometry(cell_format(*_item));
			emit tip("move mouse and release left button to select rectangle's bottom right point or press right button to cancel");
			++_step;	
		}
	}
}
/**
\brief      mouseMoveEvent
\Access    virtual public
\param  WGraphicsSceneMouseEvent * event
\retval     void
\remark
*/
void WFrameCreator::mouseMoveEvent( WGraphicsSceneMouseEvent* event )
{
    if (event->buttons() & Ws::RightButton)
    {
        if (_step == 0)
        {
            WWorldPointF pos = event->scenePos();
            scene()->attachPoint(pos, &pos);
            WWorldRectF rect(pos.x(), pos.y(), 0, 0);
            WPen pen(Ws::SolidLine, WColor(255,255,0), 0);
            WBrush brush(Ws::NoBrush);
            _item = m_layer->addRect(rect, 0.0, pen, brush, true);
            emit filterOtherViews((WGraphicsItem*)_item);
            ++_step;
        }

        else if (_step == 1)
        {
            WWorldRectF rect = _item->rect();
            WWorldPointF pos = event->scenePos();
            scene()->attachPoint(pos, &pos);
            WWorldPointF offset = pos - rect.bottomRight();
            _item->setRect(rect.adjusted(0, offset.y(), offset.x(), 0), true);
        }
    }
}
Exemplo n.º 6
0
WColor WStandardColorMap::toColor(double value) const
{
  if (colors_.size() == 0)
    return WColor();
  
  // value outside of the colormap
  if (value < colors_[0].value()) {
    return colors_[0].color();
  } else if (value >= colors_[colors_.size()-1].value()) {
    return colors_[colors_.size()-1].color();
  }

  // value inside of the colormap
  unsigned i = 0;
  for (; i < colors_.size(); i++) {
    if (value < colors_[i].value())
      break;
  }

  if (continuous_) {
    Pair mapVal1 = colors_[i-1];
    Pair mapVal2 = colors_[i];
    
    double factor = (value - mapVal1.value())/(mapVal2.value() - mapVal1.value());
    return interpolate(mapVal1.color(), mapVal2.color(), factor);
  } else {
    return colors_[i-1].color();
  }
}
Exemplo n.º 7
0
WStandardColorMap::WStandardColorMap(double min, double max, bool continuous)
  : WAbstractColorMap(min,max),
    continuous_(continuous)
{
  double interval;
  if (continuous_) {
    interval = (max_ - min_)/4;
  } else {
    interval = (max_ - min_)/5;
  }
  colors_.push_back(Pair(min_, WColor(255,255,178)));
  colors_.push_back(Pair(min_+1*interval, WColor(254,204,92)));
  colors_.push_back(Pair(min_+2*interval, WColor(253,141,60)));
  colors_.push_back(Pair(min_+3*interval, WColor(240,59,32)));
  colors_.push_back(Pair(min_+4*interval, WColor(189,0,38)));
}
Exemplo n.º 8
0
WApplication *createApplication(const WEnvironment& env)
{
  WApplication *app = new WApplication(env);
  app->setTitle(L"Hangman");
  new HangmanGame(app->root());  

  /*
   * The application style sheet (only for the highscore widget)
   */
  WCssDecorationStyle cellStyle;
  WBorder cellBorder;
  cellBorder.setStyle(WBorder::Solid);
  cellBorder.setWidth(WBorder::Explicit, WLength(1));
  cellBorder.setColor(WColor(Wt::lightGray));
  cellStyle.setBorder(cellBorder);

  app->styleSheet().addRule(".highscores * TD", cellStyle);

  cellStyle.font().setVariant(WFont::SmallCaps);

  app->styleSheet().addRule(".highscoresheader", cellStyle);

  cellStyle.font().setVariant(WFont::NormalVariant);
  cellStyle.font().setStyle(WFont::Italic);
  cellStyle.font().setWeight(WFont::Bold);

  app->styleSheet().addRule(".highscoresself", cellStyle);

  return app;
}
Exemplo n.º 9
0
ShapeColor ShapesWidget::createRandomColor() 
{
  static const unsigned amountOfColors = 4;
  
  switch (randomInt(amountOfColors)) {
  case 0:
    return ShapeColor(WColor(StandardColor::Red), WString::tr("captcha.red"));
  case 1:
    return ShapeColor(WColor(StandardColor::Green), WString::tr("captcha.green"));
  case 2:
    return ShapeColor(WColor(StandardColor::Blue), WString::tr("captcha.blue"));
  case 3:
    return ShapeColor(WColor(StandardColor::Yellow), WString::tr("captcha.yellow"));
  default:
    return ShapeColor(WColor(StandardColor::Black), WString("Invalid color"));
  }
}
void WTelemeterCreator::mouseMoveEvent(WGraphicsSceneMouseEvent* event)
{

	// 	if (event->buttons() & Ws::RightButton)
// 	{
// 		if (_item)
// 		{
// 			scene()->currentLayer()->removeItem(_item, true);
// 		}
// 		emit finished(0);
// 		clear();
// 	}

	if (event->buttons() & Ws::MidButton)
	{
		if (_step == 0)
		{
			WPointF pos = event->widget()->mapToScene(_savePoint);// 使用上一次保存的点
			scene()->attachPoint(pos, &pos);

			_item = new WTelemeterGlyph;
			WTelemeterItemData& d = *_item->data();
			d.m_penLine.setColor(WColor(255, 0, 0));
			d.m_penLine.setStyle(Ws::DashLine);
			d.m_penText.setColor(WColor(0, 255, 255));
			d.m_line.setLine(pos.x(), pos.y(), pos.x() + 1.0, pos.y() - 1.0);

			WGraphicsLayer* l = scene()->addLayer(GLYPH_TELEMETER);
			l->setEditable(true);
			l->addItem(_item, true);
			emit start(_item);

			emit stepOver(_item, _step, pos);
			++_step;
		}
		else if (_step == 1)
		{
			WRectF r = _item->boundingRect();
			WPointF pos = event->scenePos();

			scene()->attachPoint(pos, &pos);
			_item->data()->m_line.setP2(pos);
			scene()->update(_item->boundingRect() | r);
		}
	}
}
Exemplo n.º 11
0
WColor WStandardColorMap::interpolate(const WColor& color1,
				      const WColor& color2,
				      double factor) const
{
  return WColor((int)((1-factor)*color1.red() + factor*color2.red()),
		(int)((1-factor)*color1.green() + factor*color2.green()),
		(int)((1-factor)*color1.blue() + factor*color2.blue()));
}
Exemplo n.º 12
0
WColor WDataSeries::labelColor() const
{
  if (customFlags_.test(CustomFlag::LabelColor))
    return labelColor_;
  else
    if (chart_)
      return chart_->palette()->fontColor(chart_->seriesIndexOf(*this));
    else
      return WColor(StandardColor::Black);
}
Exemplo n.º 13
0
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);
    }
  }
}
Exemplo n.º 14
0
void ShapesWidget::paintEvent(WPaintDevice *paintDevice)
{
  WPainter painter(paintDevice);

  painter.setShadow(WShadow(10, 10, WColor(0, 0, 0, 50), 10));
  painter.setRenderHint(WPainter::Antialiasing);

  painter.translate(width().value()/2, height().value()/2);
  painter.rotate(angle_);
  painter.scale(size_, size_);
  painter.translate(-width().value()/2 + 50, -height().value()/2 + 150);

  drawEmwebLogo(painter);
}
Exemplo n.º 15
0
void StyleExample::updateStyle()
{
  if ((r_->validate() == WValidator::Valid)
      && (g_->validate() == WValidator::Valid)
      && (b_->validate() == WValidator::Valid)
      && (radius_->validate() == WValidator::Valid)) {
    w_->setBackgroundColor(WColor(boost::lexical_cast<int>(r_->text()),
				  boost::lexical_cast<int>(g_->text()),
				  boost::lexical_cast<int>(b_->text())));
    w_->setCornerRadius(boost::lexical_cast<int>(radius_->text()));
    error_->setText(L"");
  } else {
    error_->setText(L"All values must be numbers between 0 and 255...");
  }
}
Exemplo n.º 16
0
PaintBrush::PaintBrush(int width, int height, WContainerWidget *parent)
    : WPaintedWidget(parent)
{
    setSelectable(false);
    interactionCount_ = 0;
    undo_ = false;

//     setPositionScheme(Absolute);
    resize(WLength(width), WLength(height));

    decorationStyle().setCursor("icons/pencil.cur", CrossCursor);

    mouseWentDown().connect(this, &PaintBrush::mouseDown);

    color_ = WColor(black);

    // setPreferredMethod(InlineSvgVml);
}
Exemplo n.º 17
0
PaintBrush::PaintBrush(int width, int height, WContainerWidget *parent)
  : WPaintedWidget(parent)
{
  setSelectable(false);

  resize(WLength(width), WLength(height));

  decorationStyle().setCursor("icons/pencil.cur", CrossCursor);

  mouseDragged().connect(this, &PaintBrush::mouseDrag);
  mouseWentDown().connect(this, &PaintBrush::mouseDown);
  touchStarted().connect(this, &PaintBrush::touchStart);
  touchMoved().connect(this, &PaintBrush::touchMove);
  touchMoved().preventDefaultAction();
  
  color_ = WColor(black);

  // setPreferredMethod(InlineSvgVml);
}
Exemplo n.º 18
0
CCheckBoxTreeView::CCheckBoxTreeView(WContainerWidget *parent)
:WTable(parent),
testCount_(0)
{
    bDevice =true;
    bCheck = true;
    bMain  = false;
    strFirstNode ="";
    m_szSelMonitorID = "";
    strUser ="******";

    pTreeSelNode = NULL;
    m_pOldSelNode = NULL;
    //  this->setStyleClass("t2");
    treeroot = NULL;
    pRightTbl = NULL;



    m_menutable = new WTable((WTableCell*)this->elementAt(0,0));
    m_menutable->decorationStyle().setBackgroundColor(WColor(235 ,244 ,255));
    m_menutable->setStyleClass("widthauto");

    m_menutable->setCellPadding(0);
    m_menutable->setCellSpaceing(0);

    //makeTreeFile("无依靠", "-2", Tree_MONITOR, NULL, false,	
    //    false, "../Images/monitor.gif", "../Images/monitor.gif");

    Scrolltable = new WScrollArea(this->elementAt(0,0));

    //table->resize(WLength(100,WLength::Percentage), 350);
    //table->setStyleClass("t6");
    Scrolltable->setWidget(m_menutable);

    pMonitorBtn = new WPushButton("",this->elementAt(0,0));
    pMonitorBtn->hide();
    WObject::connect(pMonitorBtn,SIGNAL(clicked()),this,SLOT(ListMonitorInDevice()));
	//WObject::connect(pMonitorBtn,SIGNAL(clicked()), "alert('hhhh');SetViewPanelHeight();SetItemPanelHeight();" ,this, SLOT(ListMonitorInDevice()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC);	

}
Exemplo n.º 19
0
std::unique_ptr<WApplication> createApplication(const WEnvironment& env)
{
  std::unique_ptr<WApplication> app
      = cpp14::make_unique<WApplication>(env);
  app->messageResourceBundle().use(WApplication::appRoot() + "form-example");
  app->setTitle("Form example");

  app->root()->addWidget(cpp14::make_unique<FormExample>());

  WCssDecorationStyle langStyle;
  langStyle.font().setSize(FontSize::Smaller);
  langStyle.setCursor(Cursor::PointingHand);
  langStyle.setForegroundColor(WColor("blue"));
  langStyle.setTextDecoration(TextDecoration::Underline);
  app->styleSheet().addRule(".lang", langStyle);

  langStyle.setCursor(Cursor::Arrow);
  langStyle.font().setWeight(FontWeight::Bold);
  app->styleSheet().addRule(".langcurrent", langStyle);

  return app;
}
Exemplo n.º 20
0
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);
    }
  }
}
WAzimuthRectItemData::WAzimuthRectItemData() : m_pen(WColor(255, 255, 0))
{
}
Exemplo n.º 22
0
WBrush::WBrush(Ws::BrushStyle style) : _style(style), _color(WColor(0, 0, 0))
{
}
Exemplo n.º 23
0
WBrush::WBrush() : _style(Ws::NoBrush), _color(WColor(0, 0, 0))
{
}
WFrozenFrameItemData::WFrozenFrameItemData() : 
	m_brushBegin(WColor(255, 255, 255)), m_brushEnd(WColor(255, 0, 0))
{
}
Exemplo n.º 25
0
CategoryExample::CategoryExample(WContainerWidget *parent)
  : WContainerWidget(parent)
{
  setContentAlignment(AlignCenter);
  chart_ = new WCartesian3DChart(this);
  chart_->setType(CategoryChart);

  Wt::WCssDecorationStyle style;
  style.setBorder(Wt::WBorder(Wt::WBorder::Solid, Wt::WBorder::Medium, Wt::black));
  chart_->setDecorationStyle(style);

  chart_->resize(600, 600);
  
  // **** Dataset
  WStandardItemModel *isotopeModel_ = readCsvFile(WApplication::appRoot() + "isotope_decay.csv");
  // add some color-roles
  for (int i=1; i<isotopeModel_->rowCount(); i++) {
    for (int j=1; j<isotopeModel_->columnCount(); j++) {
      double value = Wt::asNumber(isotopeModel_->data(i, j));
      if (value < 3)
  	isotopeModel_->setData(i, j, WColor(blue), MarkerBrushColorRole);
    }
  }
  WGridData *isotopes = new WGridData(isotopeModel_);
  isotopes->setType(BarSeries3D);
  
  // **** Dataset
  planeModel_ = readCsvFile(WApplication::appRoot() + "hor_plane.csv");
  WGridData *horPlane = new WGridData(planeModel_);
  horPlane->setType(BarSeries3D);

  // **** Dataset
  randomModel_ = readCsvFile(WApplication::appRoot() + "hor_plane.csv");
  for (int i=1; i<randomModel_->rowCount(); i++) {
    for (int j=1; j<randomModel_->columnCount(); j++) {
      randomModel_->setData(i, j,Wt::asNumber(randomModel_->data(i, j)) + (rand() % 100)/100.0);
    }
  }
  WGridData *randomPlane = new WGridData(randomModel_);
  randomPlane->setType(BarSeries3D);

  // **** Dataset
  yPlaneModel_ = new PlaneData(20, 20, 0, 1, 0, 1, true, 100, 100);
  WEquidistantGridData *yPlaneFunc = new WEquidistantGridData(yPlaneModel_,
							       0, 1, 0, 1);
  yPlaneFunc->setType(BarSeries3D);

  // **** Dataset
  xPlaneModel_ = new PlaneData(20, 20, 0, 1, 0, 1, false, 100, 100);
  WEquidistantGridData *xPlaneFunc = new WEquidistantGridData(xPlaneModel_,
							       0, 1, 0, 1);
  xPlaneFunc->setType(BarSeries3D);

  // **** Dataset
  xPlaneModelColor_ = new PlaneData(20, 20, 0, 1, 0, 1, false, 5, 100);
  WEquidistantGridData *xPlaneFuncColor = new WEquidistantGridData(xPlaneModelColor_,
							       0, 1, 0, 1);
  xPlaneFuncColor->setType(BarSeries3D);
  

  
  // Data configuration widget
  DataConfig *dataconfig = new DataConfig(chart_);
  dataconfig->addDataToCollection("Isotope data (10x10) with ColorRoles", isotopes);
  dataconfig->addDataToCollection("Horizontal Plane (10x10)", horPlane);  
  dataconfig->addDataToCollection("Random Data (10x10)", randomPlane);  
  // dataconfig->addDataToCollection("tilted plane y (20x20)", yPlaneFunc);
  // dataconfig->addDataToCollection("tilted plane x (20x20)", xPlaneFunc);
  // dataconfig->addDataToCollection("tilted plane x (20x20) with ColorRoles", xPlaneFuncColor);
  
  

  WTabWidget *configuration_ = new WTabWidget(this);
  configuration_->addTab(new ChartSettings(chart_), "General Chart Settings", Wt::WTabWidget::PreLoading);
  configuration_->addTab(dataconfig, "Data selection and configuration", Wt::WTabWidget::PreLoading);
}
Exemplo n.º 26
0
    GoogleMapExample()
        : WContainerWidget()
    {
        auto layout = setLayout(cpp14::make_unique<WHBoxLayout>());

	setHeight(400);

	auto map = cpp14::make_unique<WGoogleMap>(GoogleMapsVersion::v3);
	map_ = map.get();
	layout->addWidget(std::move(map), 1);

	map_->setMapTypeControl(MapTypeControl::Default);
	map_->enableScrollWheelZoom();

	auto controls =
	    cpp14::make_unique<WTemplate>(tr("graphics-GoogleMap-controls"));
	auto controls_ = controls.get();
	layout->addWidget(std::move(controls));

	auto zoomIn = cpp14::make_unique<WPushButton>("+");
	auto zoomIn_ = controls_->bindWidget("zoom-in", std::move(zoomIn));
	zoomIn_->addStyleClass("zoom");

	zoomIn_->clicked().connect([=] {
	    map_->zoomIn();
	});

	auto zoomOut = cpp14::make_unique<WPushButton>("-");
	auto zoomOut_ = controls_->bindWidget("zoom-out", std::move(zoomOut));
	zoomOut_->addStyleClass("zoom");

        zoomOut_->clicked().connect([=] {
            map_->zoomOut();
	});

	std::string cityNames[] = { "Brussels", "Lisbon", "Paris" };
	WGoogleMap::Coordinate cityCoords[] = {
	    WGoogleMap::Coordinate(50.85034,4.35171),
	    WGoogleMap::Coordinate(38.703731,-9.135475),
	    WGoogleMap::Coordinate(48.877474, 2.312579)
	};
	    
	for (unsigned i = 0; i < 3; ++i) {
	    auto city = cpp14::make_unique<WPushButton>(cityNames[i]);
	    auto city_ = controls_->bindWidget(cityNames[i], std::move(city));

	    WGoogleMap::Coordinate coord = cityCoords[i];
	    city_->clicked().connect([=] {
		map_->panTo(coord);
	    });
	}

	auto reset = cpp14::make_unique<WPushButton>("Reset");
	auto reset_ = controls_->bindWidget("emweb", std::move(reset));

        reset_->clicked().connect([=] {
            this->panToEmWeb();
        });

	auto savePosition =
	    cpp14::make_unique<WPushButton>("Save current position");
	auto savePosition_ = controls_->bindWidget("save-position", std::move(savePosition));

        savePosition_->clicked().connect([=] {
            this->savePosition();
        });

	auto returnToPosition = cpp14::make_unique<WPushButton>("Return to saved position");
	returnToPosition_ = controls_->bindWidget("return-to-saved-position", std::move(returnToPosition));
	returnToPosition_->setEnabled(false);

	returnToPosition_->clicked().connect([=] {
            map_->returnToSavedPosition();
        });

	mapTypeModel_ = std::make_shared<WStringListModel>();
	addMapTypeControl("No control", MapTypeControl::None);
	addMapTypeControl("Default", MapTypeControl::Default);
	addMapTypeControl("Menu", MapTypeControl::Menu);
	if (map_->apiVersion() == GoogleMapsVersion::v2)
	    addMapTypeControl("Hierarchical",
			      MapTypeControl::Hierarchical);
	if (map_->apiVersion() == GoogleMapsVersion::v3)
	    addMapTypeControl("Horizontal bar",
			      MapTypeControl::HorizontalBar);

	auto menuControls = cpp14::make_unique<WComboBox>();
	auto menuControls_ = controls_->bindWidget("control-menu-combo", std::move(menuControls));
	menuControls_->setModel(mapTypeModel_);
	menuControls_->setCurrentIndex(1);

        menuControls_->activated().connect([=] (int mapType) {
            this->setMapTypeControl(mapType);
        });

	auto draggingCB = cpp14::make_unique<WCheckBox>("Enable dragging");
	auto draggingCB_ = controls_->bindWidget("dragging-cb", std::move(draggingCB));
	draggingCB_->setChecked(true);
	map_->enableDragging();

        draggingCB_->checked().connect([=] {
            map_->enableDragging();
        });

        draggingCB_->unChecked().connect([=] {
            map_->disableDragging();
        });

        auto enableDoubleClickZoomCB =
            cpp14::make_unique<WCheckBox>("Enable double click zoom");
        auto enableDoubleClickZoomCB_ =
            controls_->bindWidget("double-click-zoom-cb", std::move(enableDoubleClickZoomCB));
        enableDoubleClickZoomCB_->setChecked(false);
	map_->disableDoubleClickZoom();

        enableDoubleClickZoomCB_->checked().connect([=] {
            map_->enableDoubleClickZoom();
	});

        enableDoubleClickZoomCB_->unChecked().connect([=] {
            map_->disableDoubleClickZoom();
        });

        auto enableScrollWheelZoomCB =
            cpp14::make_unique<WCheckBox>("Enable scroll wheel zoom");
        auto enableScrollWheelZoomCB_ =
            controls_->bindWidget("scroll-wheel-zoom-cb", std::move(enableScrollWheelZoomCB));
        enableScrollWheelZoomCB_->setChecked(true);
	map_->enableScrollWheelZoom();

        enableScrollWheelZoomCB_->checked().connect([=] {
            map_->enableScrollWheelZoom();
        });

        enableScrollWheelZoomCB_->unChecked().connect([=] {
            map_->disableScrollWheelZoom();
        });

        std::vector<WGoogleMap::Coordinate> road = roadDescription();

        map_->addPolyline(road, WColor(0, 191, 255));

	//Koen's favourite bar!
	map_->addMarker(WGoogleMap::Coordinate(50.885069,4.71958));

	map_->setCenter(road[road.size()-1]);

	map_->openInfoWindow(road[0],
           "<img src=\"http://www.emweb.be/css/emweb_small.jpg\" />"
           "<p><strong>Emweb office</strong></p>");

        map_->clicked().connect([=] (WGoogleMap::Coordinate c) {
            this->googleMapClicked(c);
        });

	map_->doubleClicked().connect([=] (WGoogleMap::Coordinate c) {
            this->googleMapDoubleClicked(c);
        });
    }
WAzimuthCircleItemData::WAzimuthCircleItemData() : m_pen(WColor(255, 255, 0))
{
}
WColor transform(const QColor& color)
{
	return WColor(color.red(), color.green(), color.blue(), color.alpha());
}
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);
		}
Exemplo n.º 30
0
WColor WRasterImage::getPixel(int x, int y) 
{
  impl_->canvas_->flush();
  SkColor c = impl_->bitmap_->getColor(x, y);
  return WColor(SkColorGetR(c), SkColorGetG(c), SkColorGetB(c), SkColorGetA(c));
}