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;
00079 angleA = arcangle;
00080 angleB = arcangleB;
00081
00082 float x,y;
00083 x = cos(M_PI/180*(angleA));
00084 y = sin(M_PI/180*(angleA));
00085 QPointF point = QPointF(x,-y);
00086 point += startPoint;
00087
00088 QLineF a_v(startPoint,point);
00089
00090
00091 x = cos(M_PI/180*(angleB));
00092 y = sin(M_PI/180*(angleB));
00093 point = QPointF(x,-y);
00094 point += endPoint;
00095
00096 QLineF b_v(s_v.p2(),point);
00097
00098
00099 float current_ncurv = len * ncurv;
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];
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 }
00128 Transition::setLabelPosition();
00129 }
00130
00131 QString TransitionVCurve::getTypeName() const
00132 {
00133 return "VCurve";
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
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
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287