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

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

Go to the documentation of this file.
00001 #include "constants.h"
00002 
00003 #include "transitionInitialFinal.h"
00004 #include "state.h"
00005 #include "label.h"
00006 #include "transforms.h"
00007 
00008 #include <math.h>
00009 
00010 #include <QtDebug>
00011 
00012 TransitionSELine::TransitionSELine(Editor *parent, State *state, bool start, int direction, bool dimmed):
00013   OneStateTransition(parent,state,dimmed), starting(start), direction(direction)
00014 {
00015     label = NULL;
00016     setZValue(Z_TRANSITION);
00017     setRotation();    
00018 }
00019 
00020 TransitionSELine::~TransitionSELine()
00021 {
00022     DBGLOG("called");
00023 }
00024 
00025 void TransitionSELine::adjust()
00026 {
00027     prepareGeometryChange();
00028     if (!startState)
00029     { 
00030         qWarning("TransitionSELine::adjust -> startState is not valid!");
00031         return;
00032     }
00033     startPoint = startState->pos();
00034     setPos(startPoint.x(), startPoint.y());
00035     
00036     // due to StateVar (on StateVar are not supported diagonal SELines)
00037     int offset = (direction == NORTH || direction == SOUTH) ? 
00038                     startState->getHeight() / 2 :
00039                     startState->getWidth() / 2;
00040 
00041     line = QLineF(0,-offset,0,-TR_SE_LENGTH-offset);
00042 
00043     QPainterPath path;
00044     path.moveTo(starting ? line.p2() : line.p1());
00045     path.lineTo(starting ? line.p1() : line.p2());
00046     p = path;
00047 
00048     pa.clear();
00049     QMatrix matrix;
00050 
00051     if (starting)
00052     {
00053         matrix.rotate(-90);
00054         pa = matrix.map(m_arrowPoints);
00055         pa.translate(0, -offset);
00056     }
00057     else
00058     {
00059         matrix.rotate(90);
00060         pa = matrix.map(m_arrowPoints);
00061         pa.translate(0,-TR_SE_LENGTH-offset);
00062     }
00063     
00064     setLabelPosition();
00065     createStrokes(p);
00066 }
00067 
00068 QString TransitionSELine::getTypeName() const
00069 {
00070     return starting ? "Initial" : "Final";
00071 }
00072 
00073 void TransitionSELine::setDirection(int d)
00074 {
00075     direction = d;
00076     setRotation();
00077 }
00078 
00079 int TransitionSELine::getDirection() const
00080 {
00081     return direction;
00082 }
00083 
00084 void TransitionSELine::setRotation()
00085 {
00086     resetTransform();
00087     switch (direction)
00088     {
00089         case NORTH:
00090             break;
00091         case SOUTH:
00092             rotate(180);
00093             break;
00094         case EAST:
00095             rotate(90);
00096             break;
00097         case WEST:
00098             rotate(-90);
00099             break;
00100         case NORTH_EAST:
00101             rotate(45);
00102             break;
00103         case NORTH_WEST:
00104             rotate(-45);
00105             break;
00106         case SOUTH_EAST:
00107             rotate(135);
00108             break;
00109         case SOUTH_WEST:
00110             rotate(-135);
00111             break;  
00112     }  
00113     adjust();
00114 }
00115 
00116 /*void TransitionSELine::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *){
00117   QColor lineC;
00118   Qt::PenStyle lineS;
00119 
00120   if (dimmed)
00121   {
00122     lineS = dimEdgeLineStyle;
00123     lineC = dimEdgeLineColor;
00124   }
00125   else
00126   {
00127     lineS = edgeLineStyle;
00128     lineC = edgeLineColor;
00129   }
00130   
00131   if (checked)
00132   {
00133     painter->setPen(QPen(checkedColor, m_lineWidth, lineS));
00134     painter->setBrush(checkedColor);
00135   } 
00136   else
00137   {
00138     painter->setPen(QPen(lineC, m_lineWidth, lineS));
00139     painter->setBrush(lineC);
00140   }
00141   
00142   painter->strokePath(p, painter->pen());
00143   painter->drawPolygon(pa);
00144 
00145   paintSelectionDecoration(painter);
00146 
00147 #ifdef TESTING_PAINTING
00148 #   ifdef TESTING_BOUNDING_RECT_PAINTING
00149         painter->setBrush(QBrush(QColor(50,255,0,100)));
00150         painter->fillRect(boundingRect(), painter->brush());
00151 #   endif
00152 
00153     painter->setBrush(QBrush(QColor(0,0,255,150)));
00154     painter->fillPath(shape(), painter->brush());
00155 #endif
00156 }*/
00157 
00158 QString TransitionSELine::getVCCommand() const
00159 {
00160     QString command = "\\";
00161     
00162     command += getTypeName();
00163     
00164     if (getDirection() != (starting ? DEF_TR_S_DIR : DEF_TR_E_DIR))
00165     {
00166         command += "[";
00167         command += getTypeNameSuffix().toLower();       
00168         command += "]";
00169     }
00170     command += "{" + startState->getName() + "}";
00171     
00172     command += getNextLabelsVCCommand();
00173     
00174     return command;
00175 }
00176 
00177 /*
00178 QString TransitionSELine::getEPS() const
00179 {
00180   QString s = "";
00181   
00182   QColor lineC;
00183   Qt::PenStyle lineS;
00184   
00185   int r, g, b; float rf, gf, bf;
00186   
00187   if (dimmed)
00188   {
00189     lineS = dimEdgeLineStyle;
00190     lineC = dimEdgeLineColor;
00191   }
00192   else
00193   {
00194     lineS = edgeLineStyle;
00195     lineC = edgeLineColor;
00196   }
00197   
00198   lineC.getRgb(&r,&g,&b);
00199   rf = r / 255.; gf = g / 255.; bf = b / 255.;
00200   // r g b width lx ly mx my trLine 
00201   s += trLineStyle(lineS);
00202   
00203   s += QString(" %1 %2 %3 %4 %5 %6 %7 %8 trLine\n")
00204          .arg(rf).arg(gf).arg(bf)
00205          .arg(m_lineWidth)
00206          .arg(mapToScene(line.p2()).x()).arg(scene()->height()-2 - mapToScene(line.p2()).y())
00207          .arg(mapToScene(line.p1()).x()).arg(scene()->height()-2 - mapToScene(line.p1()).y());
00208   
00209   s += Transition::getEPS();
00210     
00211   return s;
00212 }
00213 */

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