32 #include "../model/State.h"
37 QObject(), idCounter(0), 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);
65 createMediator(topState);
72 for (
auto med : mediators)
74 emit createWorker(med.second, med.first, med.second->getState()->getStateName());
81 for (
const auto& elem : mediators)
83 if (elem.second->getState().get() == state.get())
95 layoutingDisabled = !enable;
104 size_t count = layoutQueue.count(correctPair) + layoutQueue.count(inversePair);
109 layoutQueue.append(correctPair);
111 else if (layoutAll && layoutQueue.contains(inversePair))
115 layoutQueue.removeAll(inversePair);
116 layoutQueue.removeAll(correctPair);
117 layoutQueue.append(correctPair);
124 auto iter = mediators.find(mediatorId);
126 if (iter != mediators.end())
128 if (iter->second->getState()->getSubstates().size() > 0)
130 iter->second->startLayouting(layoutAll, 1);
137 ARMARX_ERROR_S <<
"Mediator with id " << mediatorId <<
" is scheduled but no mediator"
138 <<
" with this id could be found.";
146 if (layoutingDisabled)
154 if (!(layoutQueue.empty()))
156 auto nextMediator = layoutQueue.takeFirst();
157 size_t mediatorId = nextMediator.first;
158 bool layoutAll = nextMediator.second;
159 if (!layoutNow(mediatorId, layoutAll))
161 QMetaObject::invokeMethod(
this,
"startNextLayouting");
176 while (layoutQueue.contains(truePair))
178 layoutQueue.removeAt(layoutQueue.indexOf(truePair));
183 while (layoutQueue.contains(falsePair))
185 layoutQueue.removeAt(layoutQueue.indexOf(falsePair));
189 auto iter = mediators.find(mediatorId);
191 if (iter != mediators.end())
193 int statePos = states.indexOf(iter->second->getState());
197 states.removeAt(statePos);
201 mediators.erase(mediatorId);
205 ARMARX_INFO_S <<
"Mediator with id " << mediatorId <<
" was already deleted";
219 if (states.contains(addedState))
224 createMediator(addedState);
236 qRegisterMetaType<statechartmodel::TransitionCPtr>(
"statechartmodel::TransitionCPtr");
237 qRegisterMetaType<statechartmodel::StateInstancePtr>(
"statechartmodel::StateInstancePtr");
238 qRegisterMetaType<statechartmodel::SignalType>(
"statechartmodel::SignalType");
239 qRegisterMetaType<SupportPoints>(
"SupportPoints");
240 qRegisterMetaType<QPointPtr>(
"QPointPtr");
241 qRegisterMetaType<FloatPtr>(
"FloatPtr");
244 bool correctConnected = connect(state.get(),
245 SIGNAL(stateDeleted()),
247 SLOT(stateDeleted()),
248 Qt::QueuedConnection);
250 if (!correctConnected)
252 ARMARX_ERROR_S <<
"Signal stateDeleted was not connected to slot stateDeleted of mediator";
255 correctConnected = connect(
260 Qt::QueuedConnection);
262 if (!correctConnected)
265 <<
"Signal substateChanged was not connected to slot substateChanged of mediator";
268 correctConnected = connect(state.get(),
272 Qt::QueuedConnection);
274 if (!correctConnected)
276 ARMARX_ERROR_S <<
"Signal stateChanged was not connected to slot stateChanged of mediator";
279 correctConnected = connect(
284 Qt::QueuedConnection);
286 if (!correctConnected)
289 <<
"Signal transitionChanged was not connected to slot transitionChanged of mediator";
293 connect(mediator.get(),
294 SIGNAL(supportPointsChanged(
297 SLOT(setTransitionSupportPoints(
299 Qt::QueuedConnection);
301 if (!correctConnected)
304 <<
" was not connected to slot setTransitionSupportPoints";
308 correctConnected = connect(mediator.get(),
309 SIGNAL(layoutingFinished()),
311 SLOT(startNextLayouting()),
312 Qt::QueuedConnection);
314 if (!correctConnected)
317 <<
" was not connected to slot startNextLayouting of controller";
320 correctConnected = connect(mediator.get(),
321 SIGNAL(deleteMe(
size_t)),
323 SLOT(deleteMediator(
size_t)),
324 Qt::QueuedConnection);
326 if (!correctConnected)
329 <<
" was not connected to slot deleteMediator of controller";
332 correctConnected = connect(mediator.get(),
333 SIGNAL(scheduleMe(
size_t,
bool)),
335 SLOT(scheduleMediator(
size_t,
bool)));
337 if (!correctConnected)
340 <<
" was not connected to slot scheduleMediator of controller";
343 correctConnected = connect(
348 Qt::QueuedConnection);
350 if (!correctConnected)
353 <<
" was not connected to slot potentialStateAdded of controller";
357 correctConnected = connect(
362 Qt::QueuedConnection);
364 if (!correctConnected)
366 ARMARX_ERROR_S <<
"Signal substateChanged of state was not connected to slot"
367 <<
" potentialStateAdded of controller";
370 mediators.insert(std::pair<size_t, MediatorPtr>(mediator->getID(), mediator));
371 states.push_back(state);
373 emit createWorker(mediator, mediator->getID(), state->getStateName());
374 QMetaObject::invokeMethod(
this,
376 Qt::QueuedConnection,
377 Q_ARG(
size_t, mediator->getID()),