Ejemplo n.º 1
0
void VectorCurve::drawVector(QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
{
if (d_style == XYAM)
{
 for (int i = from; i <= to; i++)
	{
	const double x0 = x(i);
	const double y0 = y(i);
	const double angle = vectorEnd->x(i);
	const double mag = vectorEnd->y(i);

	int xs = 0, ys = 0, xe = 0, ye = 0;
	switch(d_position)
		{
		case Tail:
			xs = xMap.transform(x0);
			ys = yMap.transform(y0);
			xe = xMap.transform(x0 + mag*cos(angle));
			ye = yMap.transform(y0 + mag*sin(angle));
		break;

		case Middle:
			{
			double dxh = 0.5*mag*cos(angle);
			double dyh = 0.5*mag*sin(angle);
			xs = xMap.transform(x0 - dxh);
			ys = yMap.transform(y0 - dyh);
			xe = xMap.transform(x0 + dxh);
			ye = yMap.transform(y0 + dyh);
			}
		break;

		case Head:
			xs = xMap.transform(x0 - mag*cos(angle));
			ys = yMap.transform(y0 - mag*sin(angle));
			xe = xMap.transform(x0);
			ye = yMap.transform(y0);
		break;
		}
	QwtPainter::drawLine(painter, xs, ys, xe, ye);
	drawArrowHead(painter, xs, ys, xe, ye);
	}
}
else
	{
	for (int i = from; i <= to; i++)
		{
		const int xs = xMap.transform(x(i));
		const int ys = yMap.transform(y(i));
		const int xe = xMap.transform(vectorEnd->x(i));
		const int ye = yMap.transform(vectorEnd->y(i));
		QwtPainter::drawLine(painter, xs, ys, xe, ye);
		drawArrowHead(painter, xs, ys, xe, ye);
		}
	}
}
Ejemplo n.º 2
0
// Draw self edge
void LineGraphEdge::drawSelf(Widget w,
			     const BoxRegion& exposed,
			     const GraphGC& gc) const
{
    assert(from() == to());

    // Get region
    BoxRegion region = from()->region(gc);
    if (from()->selected())
	region.origin() += gc.offsetIfSelected;

    LineGraphEdgeSelfInfo info(region, gc);

    XDrawArc(XtDisplay(w), XtWindow(w), gc.edgeGC, info.arc_pos[X],
	     info.arc_pos[Y], info.diameter, info.diameter,
	     info.arc_start * 64, info.arc_extend * 64);

    if (annotation() != 0)
    {
	// Draw annotation
	annotation()->draw(w, info.anno_pos, exposed, gc);
    }

    // Find arrow angle
    drawArrowHead(w, exposed, gc, info.arrow_pos, info.arrow_alpha);
}
Ejemplo n.º 3
0
void QgsLayoutItemPolyline::drawArrow( QPainter *painter, QPointF center, double angle )
{
  // translate angle from ccw from axis to cw from north
  angle = 90 - angle;
  QPen p;
  p.setColor( mArrowHeadStrokeColor );
  p.setWidthF( mArrowHeadStrokeWidth );
  painter->setPen( p );
  QBrush b;
  b.setColor( mArrowHeadFillColor );
  painter->setBrush( b );

  drawArrowHead( painter, center.x(), center.y(), angle, mArrowHeadWidth );
}
Ejemplo n.º 4
0
void LineGraphEdge::drawLine(Widget w, 
			     const BoxRegion& exposed, 
			     const GraphGC& gc) const
{
    // Get node starting points
    BoxPoint pos1     = from()->pos();
    BoxRegion region1 = from()->region(gc);
    if (from()->selected())
    {
	pos1             += gc.offsetIfSelected;
	region1.origin() += gc.offsetIfSelected;
    }

    BoxPoint pos2     = to()->pos();
    BoxRegion region2 = to()->region(gc);
    if (to()->selected())
    {
	pos2             += gc.offsetIfSelected;
	region2.origin() += gc.offsetIfSelected;
    }

    // If nodes overlap, don't draw the edge.
    if (region1 <= region2)
	return;

    // Get the line points
    BoxPoint l1, l2;
    findLine(pos1, pos2, region1, region2, l1, l2, gc);

    // If there is no edge (adjacent nodes), don't draw it.
    if (l1 == l2)
	return;

    XDrawLine(XtDisplay(w), XtWindow(w), gc.edgeGC,
	      l1[X], l1[Y], l2[X], l2[Y]);

    // Draw annotation
    BoxPoint anno_pos = annotationPosition(gc);
    if (annotation() != 0 && anno_pos.isValid())
    {
	annotation()->draw(w, anno_pos, exposed, gc);
    }

    // Get arrow angle
    double alpha = atan2(double(l1[Y] - l2[Y]), double(l1[X] - l2[X]));

    // Draw arrow head at L2
    drawArrowHead(w, exposed, gc, l2, alpha);
}
Ejemplo n.º 5
0
void Particle::draw(){
    ofFill();
    ofSetColor(100, 100, 100,100);
    drawArrowHead(vel, loc, 2);
    ofNoFill();
//    ofSetColor(118, 208, 244);
    ofBeginShape();
    for(int i =0; i<counter;i++){
        ofVertex(hist[i].x, hist[i].y);
        ofSetColor(118, 208, 244, 20);
    }
    
    if(counter > 0) ofVertex(loc.x,loc.y);
    ofEndShape(false);
}
Ejemplo n.º 6
0
    void draw() {
        float c = 100.0f/255.0f;
        glColor4f(c, c, c, 50.0f/255.0f);

        drawArrowHead(vel,loc,10);

        // draw history path
        glColor4f(0.0f, 0.0f, 0.0f, 100.0f/255.0f);
        glBegin(GL_LINE_STRIP);
        for (int i = 0; i < counter; i++) {
            glVertex2f(hist[i].x, hist[i].y);
        }

        if (!hist.empty()) glVertex2f(loc.x, loc.y);
        
        glEnd();
    }
Ejemplo n.º 7
0
void QgsResidualPlotItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
{
  if ( mGCPList.size() < 1 || !painter )
  {
    return;
  }

  double widthMM = rect().width();
  double heightMM = rect().height();

  QPen enabledPen( QColor( 255, 0, 0, 255 ), 0.3, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin );
  QPen disabledPen( QColor( 255, 0, 0, 85 ), 0.2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin );
  QBrush enabledBrush( QColor( 255, 255, 255, 255 ) );
  QBrush disabledBrush( QColor( 255, 255, 255, 127 ) );

  //draw all points and collect minimal mm/pixel ratio
  double minMMPixelRatio = DBL_MAX;
  double mmPixelRatio = 1;

  painter->setRenderHint( QPainter::Antialiasing, true );

  QgsGCPList::const_iterator gcpIt = mGCPList.constBegin();
  for ( ; gcpIt != mGCPList.constEnd(); ++gcpIt )
  {
    QgsPoint gcpCoords = ( *gcpIt )->pixelCoords();
    double gcpItemMMX = ( gcpCoords.x() - mExtent.xMinimum() ) / mExtent.width() * widthMM;
    double gcpItemMMY = ( 1 - ( gcpCoords.y() - mExtent.yMinimum() ) / mExtent.height() ) * heightMM;

    if (( *gcpIt )->isEnabled() )
    {
      painter->setPen( enabledPen );
      painter->setBrush( enabledBrush );
    }
    else
    {
      painter->setPen( disabledPen );
      painter->setBrush( disabledBrush );
    }
    painter->drawRect( QRectF( gcpItemMMX - 0.5, gcpItemMMY - 0.5, 1, 1 ) );
    drawText( painter, gcpItemMMX + 2, gcpItemMMY + 2, QString::number(( *gcpIt )->id() ), QFont() );

    mmPixelRatio = maxMMToPixelRatioForGCP( *gcpIt, gcpItemMMX, gcpItemMMY );
    if ( mmPixelRatio < minMMPixelRatio )
    {
      minMMPixelRatio = mmPixelRatio;
    }
  }

  //draw residual arrows
  gcpIt = mGCPList.constBegin();
  for ( ; gcpIt != mGCPList.constEnd(); ++gcpIt )
  {
    QgsPoint gcpCoords = ( *gcpIt )->pixelCoords();
    double gcpItemMMX = ( gcpCoords.x() - mExtent.xMinimum() ) / mExtent.width() * widthMM;
    double gcpItemMMY = ( 1 - ( gcpCoords.y() - mExtent.yMinimum() ) / mExtent.height() ) * heightMM;
    if (( *gcpIt )->isEnabled() )
    {
      painter->setPen( enabledPen );
    }
    else
    {
      painter->setPen( disabledPen );
    }

    QPointF p1( gcpItemMMX, gcpItemMMY );
    QPointF p2( gcpItemMMX + ( *gcpIt )->residual().x() * minMMPixelRatio, gcpItemMMY + ( *gcpIt )->residual().y() * minMMPixelRatio );
    painter->drawLine( p1, p2 );
    painter->setBrush( QBrush( painter->pen().color() ) );
    drawArrowHead( painter, p2.x(), p2.y(), angle( p1, p2 ), 1 );
  }

  //draw scale bar
  double initialScaleBarWidth = rect().width() / 5;
  double scaleBarWidthUnits = rect().width() / 5 / minMMPixelRatio;

  //a simple method to round to next nice number
  int nDecPlaces;
  if ( scaleBarWidthUnits < 1 )
  {
    nDecPlaces = -floor( log10( scaleBarWidthUnits ) );
    scaleBarWidthUnits *= pow( 10.0, nDecPlaces );
    scaleBarWidthUnits = ( int )( scaleBarWidthUnits + 0.5 );
    scaleBarWidthUnits /= pow( 10.0, nDecPlaces );
  }
  else
  {
    nDecPlaces = ( int )log10( scaleBarWidthUnits );
    scaleBarWidthUnits /= pow( 10.0, nDecPlaces );
    scaleBarWidthUnits = ( int )( scaleBarWidthUnits + 0.5 );
    scaleBarWidthUnits *= pow( 10.0, nDecPlaces );
  }
  initialScaleBarWidth = scaleBarWidthUnits * minMMPixelRatio;



  painter->setPen( QColor( 0, 0, 0 ) );
  painter->drawLine( QPointF( 5, rect().height() - 5 ), QPointF( 5 + initialScaleBarWidth, rect().height() - 5 ) );
  painter->drawLine( QPointF( 5, rect().height() - 5 ), QPointF( 5, rect().height() - 7 ) );
  painter->drawLine( QPointF( 5 + initialScaleBarWidth, rect().height() - 5 ), QPointF( 5 + initialScaleBarWidth, rect().height() - 7 ) );
  QFont scaleBarFont;
  scaleBarFont.setPointSize( 9 );
  if ( mConvertScaleToMapUnits )
  {
    drawText( painter, 5, rect().height() - 4 + fontAscentMillimeters( scaleBarFont ), QString( "%1 map units" ).arg( scaleBarWidthUnits ), QFont() );
  }
  else
  {
    drawText( painter, 5, rect().height() - 4 + fontAscentMillimeters( scaleBarFont ), QString( "%1 pixels" ).arg( scaleBarWidthUnits ), QFont() );
  }

  drawFrame( painter );
  if ( isSelected() )
  {
    drawSelectionBoxes( painter );
  }
}
Ejemplo n.º 8
0
void ArcGraphEdge::makeLine(Widget w,
			    const BoxRegion& exposed,
			    std::ostream& os,
			    const GraphGC& gc) const
{
    HintGraphNode   *arc_hint = 0;
    RegionGraphNode *arc_from = 0;
    RegionGraphNode *arc_to   = 0;

    bool make_arc = true;
    if (from()->isHint() && to()->isHint())
    {
	// Edge between two hints
	make_arc = false;
    }
    else if (from()->isHint() && from()->firstTo() != 0)
    {
	arc_hint = ptr_cast(HintGraphNode, from());
	arc_from = ptr_cast(RegionGraphNode, arc_hint->firstTo()->from());
	arc_to   = ptr_cast(RegionGraphNode, to());

	if (arc_hint == 0 || arc_from == 0 || arc_to == 0 
	    || arc_hint->nextTo(arc_hint->firstTo()) != 0)
	{
	    // Bad nodes or hint with multiple edges
	    make_arc = false;
	}
    }
    else if (to()->isHint() && to()->firstFrom() != 0)
    {
	arc_hint = ptr_cast(HintGraphNode, to());
	arc_to   = ptr_cast(RegionGraphNode, arc_hint->firstFrom()->to());
	arc_from = ptr_cast(RegionGraphNode, from());

	if (arc_hint == 0 || arc_from == 0 || arc_to == 0
	    || arc_hint->nextFrom(arc_hint->firstFrom()) != 0)
	{
	    // Bad nodes or hint with multiple edges
	    make_arc = false;
	}
    }
    else
    {
	// Edge between two ordinary nodes
	make_arc = false;
    }

    if (!make_arc)
    {
 	if (w != 0)
	    LineGraphEdge::drawLine(w, exposed, gc);
	else
	    LineGraphEdge::_print(os, gc);
	return;
    }

    BoxPoint pos_from     = arc_from->pos();
    BoxRegion region_from = arc_from->region(gc);
    if (arc_from->selected())
    {
	pos_from             += gc.offsetIfSelected;
	region_from.origin() += gc.offsetIfSelected;
    }

    BoxPoint pos_to     = arc_to->pos();
    BoxRegion region_to = arc_to->region(gc);
    if (arc_to->selected())
    {
	pos_to             += gc.offsetIfSelected;
	region_to.origin() += gc.offsetIfSelected;
    }

    BoxPoint pos_hint     = arc_hint->pos();
    BoxRegion region_hint = arc_hint->region(gc);
    if (arc_hint->selected())
    {
	pos_hint             += gc.offsetIfSelected;
	region_hint.origin() += gc.offsetIfSelected;
    }

    if (pos_hint <= region_from || pos_hint <= region_to)
    {
	// Hint within region
 	if (w != 0)
	    LineGraphEdge::drawLine(w, exposed, gc);
	else
	    LineGraphEdge::_print(os, gc);
	return;
    }

    BoxPoint new_pos_from, new_pos_to, dummy;
    findLine(pos_from, pos_hint, region_from, region_hint,
	     new_pos_from, dummy, gc);
    findLine(pos_hint, pos_to, region_hint, region_to,
	     dummy, new_pos_to, gc);
    pos_from = new_pos_from;
    pos_to   = new_pos_to;

    // Draw circle segment POS_FROM -> POS_HINT or POS_HINT -> POS_TO

    // Determine the arc center
    double cx, cy;
    bool ok = center(pos_from, pos_hint, pos_to, cx, cy);
    if (!ok)
    {
	// Nodes form a line
 	if (w != 0)
	    LineGraphEdge::drawLine(w, exposed, gc);
	else
	    LineGraphEdge::_print(os, gc);
	return;
    }

    // Determine radius (easy when you have the center)
    double radius = hypot(cx - pos_to[X], cy - pos_to[Y]);

    // Determine start and path of arc
    double alpha_from = -atan2(pos_from[Y] - cy, pos_from[X] - cx);
    double alpha_hint = -atan2(pos_hint[Y] - cy, pos_hint[X] - cx);
    double alpha_to   = -atan2(pos_to[Y]   - cy, pos_to[X]   - cx);

    const int base = 360 * 64;

    int angle_from = (int(alpha_from * base / (PI * 2.0)) + base) % base;
    int angle_to   = (int(alpha_to   * base / (PI * 2.0)) + base) % base;
    int angle_hint = (int(alpha_hint * base / (PI * 2.0)) + base) % base;

    int path_from_hint = (base + angle_hint - angle_from) % base;
    int path_hint_to   = (base + angle_to - angle_hint) % base;

    if (abs(path_from_hint) > base / 2)
	path_from_hint = (path_from_hint - base) % base;
    if (abs(path_hint_to) > base / 2)
	path_hint_to = (path_hint_to - base) % base;

    if (sgn(path_from_hint) * sgn(path_hint_to) == -1)
    {
	// Hint is not between FROM and TO
 	if (w != 0)
	    LineGraphEdge::drawLine(w, exposed, gc);
	else
	    LineGraphEdge::_print(os, gc);
	return;
    }

    int angle, path;
    if (to()->isHint())
    {
	angle = angle_from;
	path  = path_from_hint;
    }
    else
    {
	angle = angle_hint;
	path  = path_hint_to;
    }

    if (w != 0)
    {
	XDrawArc(XtDisplay(w), XtWindow(w), gc.edgeGC,
		 int(cx - radius), int(cy - radius),
		 unsigned(radius) * 2, unsigned(radius) * 2, angle, path);
    }
    else if (gc.printGC->isPostScript())
    {
	BoxCoordinate line_width = 1;

	int arc_start  = angle / 64;
	int arc_extend = path / 64;

	int start, end;
	if (arc_extend > 0)
	{
	    start = (720 - arc_start - arc_extend) % 360;
	    end   = (720 - arc_start) % 360;
	}
	else
	{
	    start = (720 - arc_start) % 360;
	    end   = (720 - arc_start - arc_extend) % 360;
	}

	os << start << " " << end << " " 
	   << int(radius) << " " << int(radius) << " "
	   << int(cx) << " " << int(cy) << " " << line_width << " arc*\n";
    }
    else if (gc.printGC->isFig())
    {
	// We draw the entire arc in one stroke.
	if (from()->isHint())
	{
	    BoxCoordinate line_width = 1;

	    os << ARCARROWHEAD1 << line_width << ARCARROWHEAD2;
	    if (path > 0)
		os << ARCCOUNTERCLOCKWISE;
	    else
		os << ARCCLOCKWISE;
	    os << ARCARROWHEAD3
	       << cx << " " << cy << " "
	       << pos_from[X] << " " << pos_from[Y] << " "
	       << pos_hint[X] << " " << pos_hint[Y] << " "
	       << pos_to[X]   << " " << pos_to[Y]   << " "
	       << ARCARROWHEAD4;
	}
    }

    if (from()->isHint())
    {
	// Draw arrow head at POS_TO
	double alpha = atan2(pos_to[Y] - cy, pos_to[X] - cx);

	if (w != 0)
	{
	    if (path > 0)
		alpha += PI / 2.0;
	    else
		alpha -= PI / 2.0;

	    drawArrowHead(w, exposed, gc, pos_to, alpha);
	}
	else if (gc.printGC->isPostScript())
	{
	    if (path > 0)
		alpha -= PI / 2.0;
	    else
		alpha += PI / 2.0;

	    os << gc.arrowAngle << " " << gc.arrowLength << " " 
	       << (360 + int(alpha * 360.0 / (PI * 2.0))) % 360 << " "
	       << pos_to[X] << " " << pos_to[Y] << " arrowhead*\n";
	}
    }

    if (to()->isHint() && annotation() != 0)
    {
	if (w != 0)
	{
	    annotation()->draw(w, to()->pos(), exposed, gc);
	}
	else
	{
	    annotation()->_print(os, to()->pos(), gc);
	}
    }
}