osg::Node *create3DAxis() { osg::PositionAttitudeTransform *xAxis = createArrow(osg::Vec4(1, 0, 0, 1)); xAxis->setAttitude(osg::Quat(M_PI / 2.0, osg::Vec3(0, 1, 0))); osg::PositionAttitudeTransform *yAxis = createArrow(osg::Vec4(0, 1, 0, 1)); yAxis->setAttitude(osg::Quat(-M_PI / 2.0, osg::Vec3(1, 0, 0))); osg::PositionAttitudeTransform *zAxis = createArrow(osg::Vec4(0, 0, 1, 1)); osg::Node *center = createSphere(osg::Vec4(0.7, 0.7, .7, 1), 0.08); osg::Group *group = new osg::Group(); group->addChild(xAxis); group->addChild(yAxis); group->addChild(zAxis); group->addChild(center); return group; }
SoSeparator * createFrame (float longueurFleche = LONGUEUR_FLECHE , float proportionFleche = PROPORTION_FLECHE, float radiusFleche = RAYON_FLECHE) { vpDEBUG_TRACE (15, "# Entree."); SoSeparator *frame = new SoSeparator; frame-> ref (); SoRotationXYZ *rotationY_X = new SoRotationXYZ; rotationY_X->axis = SoRotationXYZ::Z; rotationY_X->angle.setValue ((float)(- M_PI / 2)); SoRotationXYZ *rotationX_Y = new SoRotationXYZ; rotationX_Y->axis = SoRotationXYZ::Z; rotationX_Y->angle.setValue ((float)(M_PI / 2)); SoRotationXYZ *rotationY_Z = new SoRotationXYZ; rotationY_Z->axis = SoRotationXYZ::X; rotationY_Z->angle.setValue ((float)(M_PI / 2)); SoMaterial *rouge = new SoMaterial; rouge->diffuseColor.setValue(1.0, 0.0, 0.0); rouge->emissiveColor.setValue(0.5, 0.0, 0.0); SoMaterial *vert = new SoMaterial; vert->diffuseColor.setValue(0.0, 1.0, 0.0); vert->emissiveColor.setValue(0.0, 0.5, 0.0); SoMaterial *bleu = new SoMaterial; bleu->diffuseColor.setValue(0.0, 0.0, 1.0); bleu->emissiveColor.setValue(0.0, 0.0, 0.5); SoSeparator *fleche = createArrow(longueurFleche, proportionFleche, radiusFleche); frame->addChild (rouge); frame->addChild (rotationY_X); frame->addChild (fleche); frame->addChild (vert); frame->addChild (rotationX_Y); frame->addChild (fleche); frame->addChild (bleu); frame->addChild (rotationY_Z); frame->addChild (fleche); frame-> unrefNoDelete (); vpDEBUG_TRACE (15, "# Sortie."); return frame; }
void dbgGraphWindow::messageDelivered(operTrDef::messageID messID, int pos, int added, int removed, QString addText, operTrDef::changes appliedChanges) { QTime time=QTime::currentTime(); operTrDef::clientID receiver=static_cast<operTr*>(sender())->getPriority(); QTextDocument document; document.setHtml(addText); addText=document.toPlainText(); if(mMessages.count(messID)==0) throw QString("message ID was not created"); int long startTime=mMessages.value(messID).time; long int actTime=mCreationTime.msecsTo(QTime::currentTime()); if(actTime>mMaxTime){ mMaxTime=actTime; } //arrow QString mess; if(!addText.isEmpty()) mess+="ins("+QString().number(pos)+", "+addText+");"; if(removed) mess+="rem("+QString().number(pos)+", "+QString().number(removed)+");"; QString applCh; if(!appliedChanges.isEmpty()){ applCh="<BR>applied changes:<BR>"; foreach(operTrDef::messageID mid, appliedChanges) applCh+=" "+QString().number(mid.mClientID)+"->"+QString().number(mid.mMessageNumber)+"<BR>"; } createArrow(mMessages.value(messID).sender*clientPrToPixelsCoef+rightShitf, startTime*pixelsPerMilisecond, receiver*clientPrToPixelsCoef+rightShitf, actTime*pixelsPerMilisecond, "ID:"+QString().number(messID.mClientID)+"->"+QString().number(messID.mMessageNumber)+"<BR>"+ "pos:"+QString().number(pos)+", rem: "+QString().number(removed)+", text: "+addText+ applCh ); //text for arrow mScene->addText(mess)->setPos(mMessages.value(messID).sender*clientPrToPixelsCoef+rightShitf+20, startTime*pixelsPerMilisecond-15); //vertical line createLine(receiver, time); }
namespace Internal { /** * Rotation origin indicator. */ class RotationOriginIndicator : public QGraphicsItem { public: RotationOriginIndicator(QGraphicsItem *parent = 0) : QGraphicsItem(parent) { setFlags(QGraphicsItem::ItemIgnoresTransformations | QGraphicsItem::ItemIgnoresParentOpacity); setZValue(10000 + 1); setOpacity(0.5); } QRectF boundingRect() const { return QRectF(-9, -9, 18, 18); } void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { static const QLine lines[] = { QLine(-8,0, 8,0), QLine(0,-8, 0,8), }; painter->setPen(QPen(Qt::DashLine)); painter->drawLines(lines, sizeof(lines) / sizeof(lines[0])); } }; enum Corner { TopLeft, TopRight, BottomLeft, BottomRight }; static QPainterPath createArrow() { const qreal arrowHeadPos = 10; const qreal arrowHeadLength = 4; const qreal arrowHeadWidth = 4; const qreal arcWidth = 2; const qreal outerArcSize = arrowHeadPos + arcWidth - arrowHeadLength; const qreal innerArcSize = arrowHeadPos - arcWidth - arrowHeadLength; QPainterPath path; path.moveTo(arrowHeadPos, 0); path.lineTo(arrowHeadPos + arrowHeadWidth, arrowHeadLength); path.lineTo(arrowHeadPos + arcWidth, arrowHeadLength); path.arcTo(QRectF(arrowHeadLength - outerArcSize, arrowHeadLength - outerArcSize, outerArcSize * 2, outerArcSize * 2), 0, -90); path.lineTo(arrowHeadLength, arrowHeadPos + arrowHeadWidth); path.lineTo(0, arrowHeadPos); path.lineTo(arrowHeadLength, arrowHeadPos - arrowHeadWidth); path.lineTo(arrowHeadLength, arrowHeadPos - arcWidth); path.arcTo(QRectF(arrowHeadLength - innerArcSize, arrowHeadLength - innerArcSize, innerArcSize * 2, innerArcSize * 2), -90, 90); path.lineTo(arrowHeadPos - arrowHeadWidth, arrowHeadLength); path.closeSubpath(); path.translate(-3, -3); return path; } /** * Corner rotation handle. */ class CornerHandle : public QGraphicsItem { public: CornerHandle(Corner corner, QGraphicsItem *parent = 0) : QGraphicsItem(parent) { setFlags(QGraphicsItem::ItemIgnoresTransformations | QGraphicsItem::ItemIgnoresParentOpacity); setOpacity(0.5); setAcceptHoverEvents(true); setZValue(10000 + 1); switch (corner) { case TopLeft: setRotation(180); break; case TopRight: setRotation(-90); break; case BottomLeft: setRotation(90); break; case BottomRight: break; } } QRectF boundingRect() const { return mArrow.boundingRect(); } void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *); protected: void hoverEnterEvent(QGraphicsSceneHoverEvent *) { setOpacity(1); } void hoverLeaveEvent(QGraphicsSceneHoverEvent *) { setOpacity(0.5); } QVariant itemChange(GraphicsItemChange change, const QVariant &value); private: static const QPainterPath mArrow; }; const QPainterPath CornerHandle::mArrow = createArrow(); void CornerHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { painter->setRenderHint(QPainter::Antialiasing); painter->setBrush(Qt::white); painter->drawPath(mArrow); } QVariant CornerHandle::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == ItemVisibleHasChanged) { if (value.toBool()) setOpacity(isUnderMouse() ? 1 : 0.5); } return QGraphicsItem::itemChange(change, value); } } // namespace Internal
MySymbol( QwtSymbol::Style style, const QBrush &brush ) { QPen pen( Qt::black, 0 ); pen.setJoinStyle( Qt::MiterJoin ); pen.setCosmetic( true ); QPainterPath path = createArrow( QSize( 16, 24 ) ); const QSizeF pathSize = path.boundingRect().size(); setSize( 0.8 * pathSize.toSize() ); setPinPoint( QPointF( 0.0, 0.0 ) ); switch( style ) { case QwtSymbol::Pixmap: { const QSize sz = size(); const double ratio = qMin( sz.width() / pathSize.width(), sz.height() / pathSize.height() ); QTransform transform; transform.scale( ratio, ratio ); path = transform.map( path ); if ( isPinPointEnabled() ) { QPointF pos = transform.map( pinPoint() ); setPinPoint( pos ); } const QRectF br = path.boundingRect(); int m = 2 + qCeil( pen.widthF() ); QPixmap pm( sz + QSize( 2 * m, 2 * m ) ); pm.fill( Qt::transparent ); QPainter painter( &pm ); painter.setRenderHint( QPainter::Antialiasing, true ); painter.setPen( pen ); painter.setBrush( brush ); painter.translate( m, m ); painter.translate( -br.left(), br.top() ); painter.drawPath( path ); setPixmap( pm ); setSize( pm.size() ); if ( isPinPointEnabled() ) setPinPoint( pinPoint() + QPointF( m, m ) ); break; } case QwtSymbol::Graphic: { QwtGraphic graphic; graphic.setRenderHint( QwtGraphic::RenderPensUnscaled ); QPainter painter( &graphic ); painter.setRenderHint( QPainter::Antialiasing, true ); painter.setPen( pen ); painter.setBrush( brush ); painter.drawPath( path ); painter.end(); setGraphic( graphic ); break; } case QwtSymbol::SvgDocument: { QBuffer buf; QSvgGenerator generator; generator.setOutputDevice( &buf ); QPainter painter( &generator ); painter.setRenderHint( QPainter::Antialiasing, true ); painter.setPen( pen ); painter.setBrush( brush ); painter.drawPath( path ); painter.end(); setSvgDocument( buf.data() ); break; } case QwtSymbol::Path: default: { setPen( pen ); setBrush( brush ); setPath( path ); } } }