24 #include "../model/State.h"
37 layoutingDisabled(!startEnabled)
39 qRegisterMetaType<size_t>(
"size_t");
40 timer.setInterval(100);
41 connect(&timer, SIGNAL(timeout()),
this, SLOT(
startNextLayouting()), Qt::QueuedConnection);
45 createMediator(topState);
64 createMediator(topState);
70 for (
auto med : mediators)
72 emit createWorker(med.second, med.first, med.second->getState()->getStateName());
78 for (
const auto& elem : mediators)
80 if (elem.second->getState().get() == state.get())
91 layoutingDisabled = !enable;
99 size_t count = layoutQueue.count(correctPair) + layoutQueue.count(inversePair);
104 layoutQueue.append(correctPair);
106 else if (layoutAll && layoutQueue.contains(inversePair))
110 layoutQueue.removeAll(inversePair);
111 layoutQueue.removeAll(correctPair);
112 layoutQueue.append(correctPair);
118 auto iter = mediators.find(mediatorId);
120 if (iter != mediators.end())
122 if (iter->second->getState()->getSubstates().size() > 0)
124 iter->second->startLayouting(layoutAll, 1);
131 ARMARX_ERROR_S <<
"Mediator with id " << mediatorId <<
" is scheduled but no mediator"
132 <<
" with this id could be found.";
139 if (layoutingDisabled)
147 if (!(layoutQueue.empty()))
149 auto nextMediator = layoutQueue.takeFirst();
150 size_t mediatorId = nextMediator.first;
151 bool layoutAll = nextMediator.second;
152 if (!layoutNow(mediatorId, layoutAll))
154 QMetaObject::invokeMethod(
this,
"startNextLayouting");
169 while (layoutQueue.contains(truePair))
171 layoutQueue.removeAt(layoutQueue.indexOf(truePair));
176 while (layoutQueue.contains(falsePair))
178 layoutQueue.removeAt(layoutQueue.indexOf(falsePair));
182 auto iter = mediators.find(mediatorId);
184 if (iter != mediators.end())
186 int statePos = states.indexOf(iter->second->getState());
190 states.removeAt(statePos);
194 mediators.erase(mediatorId);
198 ARMARX_INFO_S <<
"Mediator with id " << mediatorId <<
" was already deleted";
210 if (states.contains(addedState))
215 createMediator(addedState);
226 qRegisterMetaType<statechartmodel::TransitionCPtr>(
"statechartmodel::TransitionCPtr");
227 qRegisterMetaType<statechartmodel::StateInstancePtr>(
"statechartmodel::StateInstancePtr");
228 qRegisterMetaType<statechartmodel::SignalType>(
"statechartmodel::SignalType");
229 qRegisterMetaType<SupportPoints>(
"SupportPoints");
230 qRegisterMetaType<QPointPtr>(
"QPointPtr");
231 qRegisterMetaType<FloatPtr>(
"FloatPtr");
234 bool correctConnected = connect(state.get(), SIGNAL(stateDeleted()),
235 mediator.get(), SLOT(stateDeleted()), Qt::QueuedConnection);
237 if (!correctConnected)
239 ARMARX_ERROR_S <<
"Signal stateDeleted was not connected to slot stateDeleted of mediator";
245 if (!correctConnected)
247 ARMARX_ERROR_S <<
"Signal substateChanged was not connected to slot substateChanged of mediator";
253 if (!correctConnected)
255 ARMARX_ERROR_S <<
"Signal stateChanged was not connected to slot stateChanged of mediator";
261 if (!correctConnected)
263 ARMARX_ERROR_S <<
"Signal transitionChanged was not connected to slot transitionChanged of mediator";
269 if (!correctConnected)
272 <<
" was not connected to slot setTransitionSupportPoints";
276 correctConnected = connect(mediator.get(), SIGNAL(layoutingFinished()),
277 this, SLOT(startNextLayouting()), Qt::QueuedConnection);
279 if (!correctConnected)
282 <<
" was not connected to slot startNextLayouting of controller";
285 correctConnected = connect(mediator.get(), SIGNAL(deleteMe(
size_t)),
286 this, SLOT(deleteMediator(
size_t)), Qt::QueuedConnection);
288 if (!correctConnected)
291 <<
" was not connected to slot deleteMediator of controller";
294 correctConnected = connect(mediator.get(), SIGNAL(scheduleMe(
size_t,
bool)),
295 this, SLOT(scheduleMediator(
size_t,
bool)));
297 if (!correctConnected)
300 <<
" was not connected to slot scheduleMediator of controller";
306 if (!correctConnected)
309 <<
" was not connected to slot potentialStateAdded of controller";
316 if (!correctConnected)
318 ARMARX_ERROR_S <<
"Signal substateChanged of state was not connected to slot"
319 <<
" potentialStateAdded of controller";
322 mediators.insert(std::pair<size_t, MediatorPtr>(mediator -> getID(), mediator));
323 states.push_back(state);
325 emit createWorker(mediator, mediator->getID(), state->getStateName());
326 QMetaObject::invokeMethod(
this,
"scheduleMediator", Qt::QueuedConnection, Q_ARG(
size_t, mediator->getID()), Q_ARG(
bool,
true));