00001 #include "constants.h"
00002
00003 #include "transitionManager.h"
00004 #include "editor.h"
00005 #include "state.h"
00006 #include "transition.h"
00007 #include "oneStateTransition.h"
00008 #include "twoStatesTransition.h"
00009 #include "transitionDialogs.h"
00010 #include "transitionLoop.h"
00011 #include "transitionInitialFinal.h"
00012 #include "transitionLine.h"
00013 #include "transitionArc.h"
00014 #include "transitionVArc.h"
00015 #include "transitionVCurve.h"
00016
00017 bool TransitionManager::instantiated = false;
00018 TransitionManager* TransitionManager::manager = NULL;
00019
00020 TransitionManager::TransitionManager()
00021 {
00022 oneStateTransitionTypeList <<
00023 "Loop" << "CLoop" << "LoopVar" << "Initial" << "Final";
00024 int i = 0;
00025 typeNameToOneStateInstanceMap[oneStateTransitionTypeList[i++]] =
00026 &TransitionManager::createTransitionLoop;
00027 typeNameToOneStateInstanceMap[oneStateTransitionTypeList[i++]] =
00028 &TransitionManager::createTransitionCLoop;
00029 typeNameToOneStateInstanceMap[oneStateTransitionTypeList[i++]] =
00030 &TransitionManager::createTransitionLoopVar;
00031 typeNameToOneStateInstanceMap[oneStateTransitionTypeList[i++]] =
00032 &TransitionManager::createTransitionInitial;
00033 typeNameToOneStateInstanceMap[oneStateTransitionTypeList[i++]] =
00034 &TransitionManager::createTransitionFinal;
00035 i = 0;
00036 typeNameToOneStatePropsMap[oneStateTransitionTypeList[i++]] =
00037 OneStateTransitionProperties(true, true, DEF_LOOP_LAB_POS);
00038 typeNameToOneStatePropsMap[oneStateTransitionTypeList[i++]] =
00039 OneStateTransitionProperties(true, true, DEF_LOOP_LAB_POS);
00040 typeNameToOneStatePropsMap[oneStateTransitionTypeList[i++]] =
00041 OneStateTransitionProperties(true,true, DEF_LOOP_LAB_POS);
00042 typeNameToOneStatePropsMap[oneStateTransitionTypeList[i++]] =
00043 OneStateTransitionProperties(false, false);
00044 typeNameToOneStatePropsMap[oneStateTransitionTypeList[i++]] =
00045 OneStateTransitionProperties(false, false);
00046
00047
00048 twoStatesTransitionTypeList
00049 << "Edge" << "Arc" << "LArc" << "VArc" << "VCurve";
00050 i = 0;
00051 typeNameToTwoStatesInstanceMap[twoStatesTransitionTypeList[i++]] =
00052 &TransitionManager::createTransitionLine;
00053 typeNameToTwoStatesInstanceMap[twoStatesTransitionTypeList[i++]] =
00054 &TransitionManager::createTransitionArc;
00055 typeNameToTwoStatesInstanceMap[twoStatesTransitionTypeList[i++]] =
00056 &TransitionManager::createTransitionLArc;
00057 typeNameToTwoStatesInstanceMap[twoStatesTransitionTypeList[i++]] =
00058 &TransitionManager::createTransitionVArc;
00059 typeNameToTwoStatesInstanceMap[twoStatesTransitionTypeList[i++]] =
00060 &TransitionManager::createTransitionVCurve;
00061 i = 0;
00062 typeNameToTwoStatesPropsMap[twoStatesTransitionTypeList[i++]] =
00063 TwoStatesTransitionProperties(true, true, false, false, false,
00064 DEF_EDGE_LAB_POS);
00065 typeNameToTwoStatesPropsMap[twoStatesTransitionTypeList[i++]] =
00066 TwoStatesTransitionProperties(true, true, false, false, false,
00067 DEF_ARC_LAB_POS);
00068 typeNameToTwoStatesPropsMap[twoStatesTransitionTypeList[i++]] =
00069 TwoStatesTransitionProperties(true, true, false, false, false,
00070 DEF_ARC_LAB_POS);
00071 typeNameToTwoStatesPropsMap[twoStatesTransitionTypeList[i++]] =
00072 TwoStatesTransitionProperties(true, true, true, true, false,
00073 DEF_ARC_LAB_POS, DEF_ARC_ANGLE, DEF_ARC_CURV);
00074 typeNameToTwoStatesPropsMap[twoStatesTransitionTypeList[i++]] =
00075 TwoStatesTransitionProperties(true, true, true, true, true,
00076 DEF_ARC_LAB_POS, DEF_VCURV_ANGLE, DEF_VCURV_CURV, DEF_VCURV_ANGLE_B);
00077 }
00078
00079 TransitionManager* TransitionManager::getInstance()
00080 {
00081 if(!instantiated)
00082 {
00083 manager = new TransitionManager();
00084 instantiated = true;
00085 return manager;
00086 }
00087 else
00088 {
00089 return manager;
00090 }
00091 }
00092
00093 const QList<QString>& TransitionManager::getOneStateTransitionTypeNameList() const
00094 {
00095 return oneStateTransitionTypeList;
00096 }
00097
00098 const QList<QString>& TransitionManager::getTwoStatesTransitionTypeNameList() const
00099 {
00100 return twoStatesTransitionTypeList;
00101 }
00102
00103 int TransitionManager::getTypeNameId(const QString &typeName) const
00104 {
00105 Q_ASSERT(oneStateTransitionTypeList.contains(typeName)
00106 || twoStatesTransitionTypeList.contains(typeName));
00107
00108 if (oneStateTransitionTypeList.contains(typeName))
00109 return oneStateTransitionTypeList.indexOf(typeName);
00110 else
00111 return twoStatesTransitionTypeList.indexOf(typeName);
00112 }
00113
00114 const OneStateTransitionProperties& TransitionManager::
00115 getOneStateTransitionProperties(int typeId) const
00116 {
00117 Q_ASSERT(oneStateTransitionTypeList.size() > typeId &&
00118 typeId >= 0);
00119 TypeNameToOneStatePropsMap::const_iterator constIt =
00120 typeNameToOneStatePropsMap.find(oneStateTransitionTypeList[typeId]);
00121 Q_ASSERT(constIt != typeNameToOneStatePropsMap.end());
00122 return *constIt;
00123 }
00124
00125 const TwoStatesTransitionProperties& TransitionManager::
00126 getTwoStatesTransitionProperties(int typeId) const
00127 {
00128 Q_ASSERT(twoStatesTransitionTypeList.size() > typeId &&
00129 typeId >= 0);
00130 TypeNameToTwoStatesPropsMap::const_iterator constIt =
00131 typeNameToTwoStatesPropsMap.find(twoStatesTransitionTypeList[typeId]);
00132 Q_ASSERT(constIt != typeNameToTwoStatesPropsMap.end());
00133 return *constIt;
00134 }
00135
00136 OneStateTransition* TransitionManager::createOneStateTransition
00137 (Editor *editor, State *state, const TransitionLoopSEDialog& td)
00138 {
00139 Q_ASSERT(oneStateTransitionTypeList.size() > td.getType() &&
00140 td.getType() >= 0);
00141 return createOneStateTransition(oneStateTransitionTypeList[td.getType()],
00142 editor, state, td.getLabel(), td.getDirection(), td.isDimmed());
00143 }
00144
00145 OneStateTransition* TransitionManager::createOneStateTransition
00146 (const QString& typeName, Editor *editor, State *state,
00147 const QString& label, int direction, bool dimmed)
00148 {
00149 Q_ASSERT(typeNameToOneStateInstanceMap.contains(typeName));
00150 return (this->*(typeNameToOneStateInstanceMap[typeName]))
00151 (editor, state, label, direction, dimmed);
00152 }
00153
00154 TwoStatesTransition* TransitionManager::createTwoStatesTransition
00155 (Editor *editor, State *s1, State *s2, const TransitionDialog& td)
00156 {
00157 Q_ASSERT(twoStatesTransitionTypeList.size() > td.getType() &&
00158 td.getType() >= 0);
00159 return createTwoStatesTransition(twoStatesTransitionTypeList[td.getType()],
00160 editor, s1, s2, td.getLabel(), td.isLeftOriented(), td.isDimmed());
00161 }
00162
00163 TwoStatesTransition* TransitionManager::createTwoStatesTransition
00164 (const QString& typeName, Editor *editor, State* s1, State* s2,
00165 const QString& label, bool leftOriented, bool dimmed)
00166 {
00167 Q_ASSERT(typeNameToTwoStatesInstanceMap.contains(typeName));
00168 return (this->*(typeNameToTwoStatesInstanceMap[typeName]))
00169 (editor, s1, s2, label, leftOriented, dimmed);
00170 }
00171
00172
00173
00174
00175
00176 OneStateTransition* TransitionManager::createTransitionInitial
00177 (Editor *editor, State *state, const QString &, int direction, bool dimmed)
00178 {
00179 return new TransitionSELine(editor, state, true, direction, dimmed);
00180 }
00181
00182 OneStateTransition* TransitionManager::createTransitionFinal
00183 (Editor *editor, State *state, const QString &, int direction, bool dimmed)
00184 {
00185 return new TransitionSELine(editor, state, false, direction, dimmed);
00186 }
00187
00188 OneStateTransition* TransitionManager::createTransitionLoop
00189 (Editor *editor, State *state, const QString &label, int direction, bool dimmed)
00190 {
00191 return new TransitionLoop(editor, state, label, TransitionLoop::eLoop, dimmed, direction);
00192 }
00193
00194 OneStateTransition* TransitionManager::createTransitionCLoop
00195 (Editor *editor, State *state, const QString &label, int direction, bool dimmed)
00196 {
00197 return new TransitionLoop(editor, state, label, TransitionLoop::eCLoop, dimmed, direction);
00198 }
00199
00200 OneStateTransition* TransitionManager::createTransitionLoopVar
00201 (Editor *editor, State *state, const QString &label, int direction, bool dimmed)
00202 {
00203 return new TransitionLoop(editor, state, label, TransitionLoop::eLoopVar, dimmed, direction);
00204 }
00205
00206
00207
00208 TwoStatesTransition* TransitionManager::createTransitionLine
00209 (Editor *editor, State *s1, State *s2, const QString &label, bool leftOriented, bool dimmed)
00210 {
00211 return new TransitionLine(editor, s1, s2, label, leftOriented, dimmed);
00212 }
00213
00214 TwoStatesTransition* TransitionManager::createTransitionArc
00215 (Editor *editor, State *s1, State *s2, const QString &label, bool leftOriented, bool dimmed)
00216 {
00217 return new TransitionArc(editor, s1, s2, label, leftOriented, dimmed, false);
00218 }
00219
00220 TwoStatesTransition* TransitionManager::createTransitionLArc
00221 (Editor *editor, State *s1, State *s2, const QString &label, bool leftOriented, bool dimmed)
00222 {
00223 return new TransitionArc(editor, s1, s2, label, leftOriented, dimmed, true);
00224 }
00225
00226 TwoStatesTransition* TransitionManager::createTransitionVArc
00227 (Editor *editor, State *s1, State *s2, const QString &label, bool leftOriented, bool dimmed)
00228 {
00229 return new TransitionVArc(editor, s1, s2, label, leftOriented, dimmed);
00230 }
00231
00232 TwoStatesTransition* TransitionManager::createTransitionVCurve
00233 (Editor *editor, State *s1, State *s2, const QString &label, bool leftOriented, bool dimmed)
00234 {
00235 return new TransitionVCurve(editor, s1, s2, label, leftOriented, dimmed);
00236 }