• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

C:/CVUT/diplomka/Automata_editor/sources/transitionVCurve.cpp

Go to the documentation of this file.
00001 #include "constants.h"
00002 
00003 #include "transitionVCurve.h"
00004 #include "state.h"
00005 #include "label.h"
00006 #include "transforms.h"
00007 
00008 #include <math.h>
00009 
00010 #include <QtDebug>
00011 
00012 TransitionVCurve::TransitionVCurve(Editor *parent, State *ss, State *es,
00013                                    const QString &labelText, bool left, bool dimmed)
00014 : TwoStatesTransition(parent, ss, es, left, dimmed),
00015   arcangle(DEF_VCURV_ANGLE),
00016   arcangleB(left ? DEF_VCURV_ANGLE_B : DEF_VCURVR_ANGLE_B),
00017   ncurv(DEF_VCURV_CURV)
00018 {
00019   setZValue(Z_TRANSITION);
00020   label = new LabelX(this, labelText, leftOriented, m_labelFontSize,
00021         dimmed ? QColor(dimEdgeLabelColor) : QColor(edgeLabelColor));
00022   label->setZValue(Z_TR_LABEL);
00023   label->setPosParam(DEF_ARC_LAB_POS);
00024   adjust();
00025   setLabelPosition();
00026 }
00027 
00028 TransitionVCurve::~TransitionVCurve()
00029 {
00030     DBGLOG("called");
00031 }
00032 
00033 void TransitionVCurve::adjust()
00034 {
00035     prepareGeometryChange();
00036     if (!startState || !endState) return;
00037 
00038     QPolygonF anglePol, statePol, iPol;
00039     anglePol << startState->pos() << startState->pos() + QPointF(cos(M_PI/180*arcangle), -sin(M_PI/180*arcangle))*startState->getWidth();
00040     statePol << mapFromItem(startState, startState->getMyPolygon());
00041     iPol = (findIntersectedPoints(anglePol, statePol, eFIND_FIRST));
00042     if (iPol.empty())
00043     {
00044         qWarning("TransitionVCurve::adjust -> startPoint is set to startState->pos()!");
00045         startPoint = startState->pos();
00046     }
00047     else
00048     {
00049         startPoint = iPol[0];
00050     }
00051 
00052     anglePol.clear();
00053     statePol.clear();
00054     anglePol << endState->pos() << endState->pos() + QPointF(cos(M_PI/180*arcangleB), -sin(M_PI/180*arcangleB))*endState->getWidth();
00055     statePol << mapFromItem(endState, endState->getMyPolygon());
00056     iPol = (findIntersectedPoints(anglePol, statePol, eFIND_FIRST));
00057     if (iPol.empty())
00058     {
00059         qWarning("TransitionVCurve::adjust -> endPoint is set to endState->pos()!");
00060         endPoint  = endState->pos();
00061     }
00062     else
00063     {
00064         endPoint = iPol[0];
00065     }
00066 
00067     if (startPoint == endPoint)
00068     {
00069         setLabelPosition();
00070         return;
00071     }
00072   
00073     QPainterPath path;
00074   
00075     QLineF s_v(startPoint, endPoint);
00076     float len = s_v.length()/2;
00077 
00078     float angleA, angleB; // left or right orientation
00079     angleA = arcangle;
00080     angleB = arcangleB;
00081   
00082     float x,y;  // compute vector from start point
00083     x = cos(M_PI/180*(angleA));
00084     y = sin(M_PI/180*(angleA)); // compute new unitVector
00085     QPointF point = QPointF(x,-y); 
00086     point += startPoint; // place to startPoint
00087   
00088     QLineF a_v(startPoint,point); // vector from startPoint
00089   
00090     // now compute vector from end point
00091     x = cos(M_PI/180*(angleB));
00092     y = sin(M_PI/180*(angleB)); // compute new unitVector
00093     point = QPointF(x,-y); 
00094     point += endPoint; // place to endPoint
00095       
00096     QLineF b_v(s_v.p2(),point); // vector from endPoint
00097 
00098     // set length by ncurv
00099     float current_ncurv = len * ncurv; // experiment
00100     a_v.setLength(current_ncurv);
00101     b_v.setLength(current_ncurv);
00102 
00103     a_point = a_v.p2(); b_point = b_v.p2();
00104     path.moveTo(startPoint);
00105     path.cubicTo(a_point, b_point, endPoint);
00106 
00107     p = path;
00108   
00109     QList<QPolygonF> pathList = p.toSubpathPolygons();
00110     if (pathList.size() > 1)
00111         RELLOG("not only one sub-path polygon!");
00112     
00113     iPol = pathList[0]; // endPoint is on state's polygon, so it may be no intersected
00114     iPol << endState->pos();
00115     
00116     pa = getArrowPolygon(p);
00117     
00118     setLabelPosition();
00119     createStrokes(p);
00120 }
00121 
00122 void TransitionVCurve::setLabelPosition()
00123 {
00124     if (label)
00125     { 
00126         Transition::setLabelPosition(label, label->posParam(), leftOriented, label->getWidth(), label->getHeight());
00127     } // if
00128     Transition::setLabelPosition();
00129 }
00130 
00131 QString TransitionVCurve::getTypeName() const
00132 {
00133     return "VCurve";
00134 }
00135 
00136 /*void TransitionVCurve::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
00137 {
00138     if (startPoint == endPoint)     
00139         return;    
00140 
00141     QColor lineC;
00142     Qt::PenStyle lineS;
00143   
00144     if (dimmed)
00145     {
00146         lineS = dimEdgeLineStyle;
00147         lineC = dimEdgeLineColor;
00148     } 
00149     else
00150     {
00151         lineS = edgeLineStyle;
00152         lineC = edgeLineColor;
00153     }
00154   
00155     if (checked)    
00156         painter->setPen(QPen(checkedColor, m_lineWidth, lineS));    
00157     else
00158         painter->setPen(QPen(lineC, m_lineWidth, lineS));
00159 
00160     painter->setBrush(Qt::NoBrush);
00161     painter->strokePath(p, painter->pen());
00162  
00163 
00164     // arrow
00165     if (checked)
00166         painter->setBrush(checkedColor);
00167     else
00168         painter->setBrush(lineC);
00169 
00170     painter->drawPolygon(pa); // computed in adjust
00171 
00172     paintSelectionDecoration(painter);
00173 
00174 #ifdef TESTING_PAINTING
00175 #   ifdef TESTING_BOUNDING_RECT_PAINTING
00176         painter->setBrush(QBrush(QColor(50,255,0,100)));
00177         painter->fillRect(boundingRect(), painter->brush());
00178 #   endif
00179 
00180     painter->setBrush(QBrush(QColor(0,0,255,150)));
00181     painter->fillPath(shape(), painter->brush());      
00182 #endif
00183 }*/
00184 
00185 QString TransitionVCurve::getVCCommand() const
00186 {
00187     QString command = "\\";
00188 
00189     command += getTypeName();
00190     command += getTypeNameSuffix();
00191       
00192     float def_vcurv_angle_b = (getTypeNameSuffix() == "L") ? DEF_VCURV_ANGLE_B : DEF_VCURVR_ANGLE_B;
00193     
00194     Q_ASSERT(label != NULL);
00195     if (label->posParam() != DEF_ARC_LAB_POS) 
00196         command += QString("[%1]").arg(label->posParam());
00197       
00198     command += "{";        
00199     if (getArcAngle() != (int)DEF_VCURV_ANGLE)
00200         command += QString("angleA=%1").arg(getArcAngle());
00201     if (getArcAngleB() != def_vcurv_angle_b)
00202     {
00203         if (getArcAngle() != (int)DEF_VCURV_ANGLE)
00204             command += ",";
00205         command += QString("angleB=%1").arg(getArcAngleB());
00206     }
00207     if (getNCurv() != (float)DEF_VCURV_CURV)
00208     {
00209         if (getArcAngle() != (int)DEF_VCURV_ANGLE ||
00210             getArcAngleB() != def_vcurv_angle_b)
00211             command += ",";
00212         command += QString("ncurv=%1").arg(getNCurv());
00213     }
00214     command += "}";
00215     
00216     command += "{" + startState->getName() + "}";
00217     command += "{" + endState->getName() + "}";
00218 
00219     command += "{" + label->text() + "}";
00220 
00221     command += getNextLabelsVCCommand();
00222 
00223     return command;
00224 }
00225 
00226 QString TransitionVCurve::getGraphMLParams() const
00227 {
00228     QString params = "";
00229     
00230     if (arcangle != DEF_VCURV_ANGLE)
00231     {
00232         params += QString("      <data key=\"d131\">%1</data>\n")
00233                     .arg(getArcAngle());
00234     }
00235     if (arcangleB != DEF_VCURV_ANGLE_B)
00236     {
00237         params += QString("      <data key=\"d132\">%1</data>\n")
00238                     .arg(getArcAngle());
00239     }
00240     if (ncurv != DEF_VCURV_CURV)
00241     {
00242         params += QString("      <data key=\"d133\">%1</data>\n")
00243                     .arg(getNCurv());
00244     }
00245 
00246     return params;
00247 }
00248 
00249 /*
00250 // export
00251 QString TransitionVCurve::getEPS() const
00252 {
00253     QString s = "";
00254   
00255     QColor lineC;
00256     Qt::PenStyle lineS;
00257   
00258     int r, g, b; float rf, gf, bf;
00259   
00260     if (dimmed)
00261     {
00262         lineS = dimEdgeLineStyle;
00263         lineC = dimEdgeLineColor;
00264     }
00265     else
00266     {
00267         lineS = edgeLineStyle;
00268         lineC = edgeLineColor;
00269     }
00270   
00271     lineC.getRgb(&r,&g,&b);
00272     rf = r / 255.; gf = g / 255.; bf = b / 255.;
00273     // % r g b width x0 y0 x1 y1 x2 y2 x y trVCurve
00274     s += trLineStyle(lineS);
00275     s += QString(" %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 trVCurve\n")
00276          .arg(rf).arg(gf).arg(bf)
00277          .arg(m_lineWidth)
00278          .arg(a_point.x()).arg(scene()->height()-2 - a_point.y())
00279          .arg(b_point.x()).arg(scene()->height()-2 - b_point.y())
00280          .arg(endPoint.x()).arg(scene()->height()-2 - endPoint.y())
00281          .arg(startPoint.x()).arg(scene()->height()-2 - startPoint.y());
00282   
00283     s += Transition::getEPS();   // nakonec se vykresli label
00284   
00285     return s;
00286 }
00287 */

Generated on Tue Jan 4 2011 03:03:24 for Autoamata editor by  doxygen 1.7.0