StateItem.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #include "StateItem.h"
25 #include "TransitionItem.h"
26 
27 #include "../StateScene.h"
28 #include "../model/State.h"
29 #include "../model/Transition.h"
30 #include "../model/stateinstance/StateInstance.h"
31 #include "../model/StateMimeData.h"
32 
34 
36 
37 #include <QGraphicsProxyWidget>
38 #include <QMenu>
39 #include <QPainter>
40 #include <QtGui>
41 #include <QStyleOptionGraphicsItem>
42 #include <QGraphicsSceneContextMenuEvent>
43 #include <QMessageBox>
44 
45 
46 #define MAXFONTSIZE 300.0f
47 
48 
49 
50 namespace armarx
51 {
53  RoundRectItem(QRectF(0, 0, state->getClassSize().width(), state->getClassSize().height()),
54  // QColor(Qt::blue).lighter(190),
55  QColor(),
56  parent),
57  MorphingItem(this),
58  state(state)
59  // QGraphicsWidget(parent)
60  {
61  // if(state && state->getStateClass())
62  setAcceptDrops(true);
63  // stateScene = dynamic_cast<StateScene*>(scene());
64  setup(parent);
65  connectSlots();
67  setStateColor();
68  setRimColor();
69  setZValue(10000);
70  updateToolTip();
71  if (state->getStateClass())
72  {
73  setEditable(state->getStateClass()->isEditable());
74  }
75  }
76 
78  {
79  // ARMARX_INFO << state->getInstanceName();
80  }
81 
82  void StateItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
83  QWidget* widget)
84  {
85  StateItem* parentState = qgraphicsitem_cast<StateItem*>(parentItem());
86  LevelOfDetail detail = getLevelOfDetailByParent(painter, parentState);
87 
88  if (detail == eHidden) // only use scale of parent so that all sub elements of parent (states, transitions) are hidden at once and not one after the other
89  {
90  return;
91  }
92 
93 
94 
95  statechartmodel::StatePtr stateClass = state->getStateClass();
96 
97  // Draw state rect
98  RoundRectItem::paint(painter, option, widget);
99 
100  // draw substate rect for debug purposes
101  // if(state->getStateClass())
102  // painter->drawRect(QRectF(state->getStateClass()->margin.topLeft(),
103  // QPointF(state->getStateClass()->getSize().width()-state->getStateClass()->margin.width(),
104  // state->getStateClass()->getSize().height()-state->getStateClass()->margin.height())));
105  /*
106  * There are three different cases which must be differentiated:
107  * 1. Class known & substates: Show both names at top
108  * 2. Class known & no substates: Show both names centered (instance label centered, class name below)
109  * 3. Class unknown & no substates: Show class name centered
110  * (Class unknown & substates: Not possible, substates are deduced from state class)
111  */
112 
113  bool showSubstates = detail != eNoSubstates && stateClass && !stateClass->getSubstates().empty();
114 
115  bool showStateClassName = stateClass && (instanceName != stateClass->getStateName() /*|| !showSubstates*/);
116 
117  const int renderFlags = static_cast<uint8_t>(Qt::TextSingleLine) |
118  static_cast<uint8_t>(Qt::AlignTop) |
119  static_cast<uint8_t>(Qt::AlignHCenter);
120 
121  QRectF textRect = bounds;
122 
123  float instanceNameWidthRelative = showSubstates ? 0.5f : 0.8f;
124 
125 
126  float instanceNameScaleFactor = textRect.width() * instanceNameWidthRelative / painter->fontMetrics().width(instanceName);
127 
128  if (showSubstates)
129  {
130  if (showStateClassName)
131  {
132  textRect.adjust(0, 10, 0, 0);
133  }
134  else
135  {
136  textRect.adjust(0, 20, 0, 0);
137  }
138  }
139  else
140  {
141  textRect.adjust(0, (bounds.height() - painter->fontMetrics().height() * instanceNameScaleFactor) / 2, 0, 0);
142 
143  }
144 
145  qreal lodT = QStyleOptionGraphicsItem::levelOfDetailFromTransform(painter->worldTransform());
146  QFont f = painter->font();
147  QRectF maxFsize(0, 0, 0, MAXFONTSIZE);
148  f.setPointSizeF(std::min<float>(f.pointSizeF() * instanceNameScaleFactor, (maxFsize).height() / lodT));
149  painter->setFont(f);
150  float textHeightScale = 0.8;
151 
152 
153  if (showSubstates && state->getStateClass() && painter->fontMetrics().height() > 0.5 * state->getStateClass()->margin.top())
154  {
155  float margin = state->getStateClass()->margin.top();
156  float height = painter->fontMetrics().height();
157  float size = f.pointSizeF();
158  textHeightScale = margin / height;
159  if (showStateClassName)
160  {
161  textHeightScale *= 0.45;
162  }
163  else
164  {
165  textHeightScale *= 0.7;
166  }
167  f.setPointSizeF(size * textHeightScale);
168  painter->setFont(f);
169  // ARMARX_INFO << "Text to high: " << textHeightScale;
170  }
171 
172  painter->setFont(f);
173  painter->drawText(textRect, renderFlags, instanceName);
174 
175  if (showStateClassName && !stateClass->getStateName().isEmpty())
176  {
177  QString classNameText = "[state: " + stateClass->getStateName() + "]";
178  float instanceNamePointSize = f.pointSizeF();
179  float classNameScaleFactor = textRect.width() * 0.8f / painter->fontMetrics().width(classNameText);
180 
181 
182 
183  textRect.adjust(0, painter->fontMetrics().height() * 1.0, 0, 0);
184 
185  lodT = QStyleOptionGraphicsItem::levelOfDetailFromTransform(painter->worldTransform());
186  QRectF maxFsize(0, 0, 0, MAXFONTSIZE);
187  float classNamePointSize = textHeightScale * std::min<float>(f.pointSizeF() * classNameScaleFactor, (maxFsize).height() / lodT);
188  classNamePointSize = std::min(classNamePointSize, instanceNamePointSize); // never bigger than instance name
189  f.setPointSizeF(classNamePointSize);
190  painter->setFont(f);
191 
192  painter->drawText(textRect, renderFlags, classNameText);
193  }
194  }
195 
197  {
199 
200  if (signalType == statechartmodel::eChanged)
201  {
202  updateToolTip();
203  setRimColor();
204  update();
205  setSize(state->getClassSize());
206  setInstanceName(state->getInstanceName());
207  // ARMARX_WARNING_S << "Resizing " << state->getInstanceName() << VAROUT(state->getClassSize());
208  update(bounds);
209 
210  }
211  }
212 
214  {
215 
216  switch (signalType)
217  {
219  {
220  // ARMARX_INFO << "substate added: " << substate->getInstanceName();
221  StateInstanceItemMap::iterator it = subStates.find(substate);
222 
223  if (it != subStates.end())
224  {
225  ARMARX_WARNING << "substate already in list";
226  return;
227  }
228 
229  StateItem* stateItem = new StateItem(substate, this);
230  subStates.insert(substate, stateItem);
231  connect(stateItem, SIGNAL(stateItemMoved(QPointF)), substate.get(), SLOT(setPosition(QPointF)));
232  connect(stateItem, SIGNAL(stateItemBoundingBoxChanged(float)), substate.get(), SLOT(setBoundingBox(float)));
233  stateItem->setInstanceName(substate->getInstanceName());
234  stateItem->setScale(substate->getScale());
235  // ARMARX_INFO_S << "topleft: " << substate->getTopLeft();
236  stateItem->setPos(substate->getTopLeft());
237  stateItem->setSize(substate->getClassSize());
238 
239 
240  stateItem->adjustSize();
241  update();
242  // ARMARX_INFO << "Added state " << stateName << " to Scene";
243  }
244  break;
245 
247  {
248  // ARMARX_INFO << "substate changed: " << substate->getInstanceName();
249  StateInstanceItemMap::iterator it = subStates.find(substate);
250 
251  if (it == subStates.end())
252  {
253  break;
254  }
255 
256  StateItem* substateItem = it.value();
257  substateItem->setPos(substate->getTopLeft());
258  substateItem->setSize(substate->getClassSize());
259  substateItem->setScale(substate->getScale());
260  substateItem->setInstanceName(substate->getInstanceName());
261  substateItem->setStateColor();
262  substateItem->setRimColor();
264 
265  }
266  break;
267 
269  {
270 
271  }
272  break;
273 
275  {
276  // ARMARX_INFO << "Removing state " << substate->getInstanceName() << " from Scene";
277  StateInstanceItemMap::iterator it = subStates.find(substate);
278 
279  if (it == subStates.end())
280  {
281  // ARMARX_INFO << "Could not find substate";
282  break;
283  }
284 
285  QPointer<StateItem> substateItem = it.value();
286  subStates.remove(substate);
287  if (substateItem)
288  {
289  substateItem->prepareGeometryChange();
290  QObject::disconnect(substateItem);
291  delete substateItem.data();
292  }
293  }
294  break;
295 
296  default:
297  // ARMARX_INFO << "Unhandled state changed";
298  break;
299  }
300 
301  }
302 
304  {
305  // ARMARX_INFO << "Transition Changed";
306  switch (signalType)
307  {
309  {
310  TransitionItem* t = new TransitionItem(transition, this);
311  transitions.insert(transition, t);
312  t->recalcPath();
313  connect(t, SIGNAL(transitionEndPlaced(statechartmodel::TransitionCPtr, QPointF)), this, SLOT(transitionMoved(statechartmodel::TransitionCPtr, QPointF)));
315  }
316  break;
317 
319  {
320  TransitionMap::iterator it = transitions.find(transition);
321 
322  if (it == transitions.end())
323  {
324  break;
325  }
326  TransitionItem* t = it.value();
327  t->updateLabel();
328  t->recalcPath();
329  }
330  break;
331 
333  {
334  TransitionMap::iterator it = transitions.find(transition);
335 
336  if (it == transitions.end())
337  {
338  break;
339  }
340  // ARMARX_DEBUG << "Removing transition " << transition->eventName;
341  TransitionItem* t = it.value();
342  QObject::disconnect(t);
343  transitions.remove(transition);
344  // t->prepareGeometryChange();
345  delete t;
346 
347  }
348  break;
350  {
351  TransitionMap::iterator it = transitions.find(transition);
352 
353  if (it == transitions.end())
354  {
355  break;
356  }
357  int highlightDuration = 10000;
358  TransitionItem* t = it.value();
359  t->highlightAnimation(highlightDuration);
360  }
361  break;
362  default:
363 
364  break;
365  }
366  }
367 
369  {
370  TransitionMap::iterator it = transitions.begin();
371 
372  for (; it != transitions.end(); it++)
373  {
374  auto t = it.key();
375 
376  if (t->sourceState == state || t->destinationState == state)
377  {
378  notifyTransitionChanged(t, signalType);
379  }
380  }
381  }
382 
383  void StateItem::forwardTransitionContextMenuRequested(statechartmodel::TransitionCPtr transition, QPoint mouseScreenPos, QPointF mouseItemPos)
384  {
385  emit transitionContextMenuRequested(transition, state->getStateClass(), mouseScreenPos, mouseItemPos);
386  }
387 
389  {
390  TransitionMap::iterator it = transitions.find(transition);
392 
393  StateInstanceItemMap::iterator itState = subStates.begin();
394 
395  for (; itState != subStates.end(); itState++)
396  {
397  StateItem* item = itState.value();
398  QPointF dropPointMapped = item->mapFromParent(dropPoint);
399 
400  if (item->contains(dropPointMapped))
401  {
402 
403  ARMARX_IMPORTANT << "dropped on " << item->getStateInstance()->getInstanceName();
404  QList<QPointF> suppPoint;
405  suppPoint.push_back(dropPoint);
406  state->getStateClass()->updateTransitionDestination(transition, item->getStateInstance(), suppPoint);
407  return;
408  }
409  }
410 
411  state->getStateClass()->detachTransitionDestination(transition, dropPoint);
412 
413  }
414 
415 
416 
418  {
419  // ui.substatesView->fitInView( substateScene->sceneRect(), Qt::KeepAspectRatio );
420  }
421 
423  {
424  if (parentItem())
425  {
426  // ARMARX_INFO << "adjusting size";
427  // state->setBoundingBox(100);
428  // bounds.setWidth(parentItem()->boundingRect().width()*0.3);
429  // bounds.setHeight(parentItem()->boundingRect().height()*0.3);
430  }
431  }
432 
433 
434 
435  void StateItem::setup(QGraphicsItem* parent)
436  {
437 
438 
439 
440 
441  }
442 
444  {
446 
447  if (state->getStateClass())
448  {
449  connect(state->getStateClass().get(), SIGNAL(stateChanged(statechartmodel::SignalType)), this, SLOT(notifyStateChanged(statechartmodel::SignalType)));
452  connect(this, SIGNAL(stateItemResized(QSizeF)), state->getStateClass().get(), SLOT(setSize(QSizeF)));
453 
454  }
455 
456  if (scene())
457  {
458  QVariant v;
459  v.setValue(scene());
460  itemChange(ItemSceneChange, v);
461  }
462 
463  }
464 
466  {
469 
470  if (!state->getStateClass())
471  {
472  return;
473  }
474 
475  const auto& ts = state->getStateClass()->getTransitions(true);
476 
477  for (int i = 0; i < ts.size(); i++)
478  {
480  }
481 
482  const auto& sl = state->getStateClass()->getSubstates();
483 
484  for (auto i = sl.begin(); i != sl.end(); i++)
485  {
487  }
488 
489 
490  }
491 
492 
493 
495  {
496  if (!state)
497  {
498  return;
499  }
500  int level = getInstanceLevel();
501  switch (state->getType())
502  {
503  case eNormalState:
504  {
505  QColor color(52, 152, 219);
506  if (level % 2 == 0)
507  {
508  color = color.lighter(130);
509  }
510  else
511  {
512  color = color.lighter(110);
513  }
514  setColor(color);
515  }
516  break;
517 
518  case eRemoteState:
519  {
520  QColor color(26, 188, 156);
521  if (level % 2 == 0)
522  {
523  color = color.lighter(130);
524  }
525  else
526  {
527  color = color.lighter(110);
528  }
529  setColor(color);
530  }
531  break;
532 
533  case eDynamicRemoteState:
534  setColor(QColor(155, 89, 182));
535  break;
536 
537  case eFinalState:
538  {
539  QColor color(241, 196, 15);
540  color = color.lighter(120);
541  setColor(color);
542  }
543 
544 
545  default:
546  break;
547 
548  }
549  }
550 
552  {
553  if ((state
554  && state->isActive()) || active)
555  {
556  setRimPen(QPen(Qt::red, 10));
557  }
558  else
559  {
560  setRimPen(QPen(Qt::black, 2));
561  }
562  update();
563  }
564 
566  {
567  QString tip;
568  if (state)
569  {
570  tip = "StateType: " + statechartmodel::State::StateTypeToString(state->getType());
571  if (state->getStateClass())
572  {
573  auto desc = state->getStateClass()->getDescription();
574  if (!desc.isEmpty())
575  {
576  tip += "\n" + desc;
577  }
578  }
579  }
580  setToolTip(tip);
581  }
582 
584  {
585  auto curScene = scene();
586  if (curScene)
587  {
588  for (auto& t : transitions)
589  {
590  // t->prepareGeometryChange();
591  curScene->removeItem(t);
592  }
593  }
594  for (auto& s : subStates)
595  {
596  s->prepareGeometryChange();
597  s->removeChildren();
598  if (curScene)
599  {
600  curScene->removeItem(s);
601  }
602  }
603  }
604 
606  {
607  int level = 0;
608  const QGraphicsItem* parent = this;
609  while (dynamic_cast<StateItem*>(parent->parentItem()))
610  {
611  parent = parent->parentItem();
612  level++;
613  }
614  return level;
615  }
616 
617  QPointF StateItem::adjustPosition(QPointF& newPos)
618  {
619  if (state)
620  {
621  return state->adjustPosition(newPos);
622  }
623  ARMARX_INFO << "state ptr is null";
624  return newPos;
625  }
626 
628  {
629  return maxShownSubstateLevel;
630  }
631 
633  {
635  for (auto& substate : subStates)
636  {
637  substate->setMaxShownSubstateLevel(value);
638  }
639  for (auto& item : childItems())
640  {
641  item->update();
642  }
643  }
644 
645  void StateItem::setActiveSubstate(const QString& substateName)
646  {
647  auto substates = getSubstateItems();
648  for (auto substate : substates)
649  {
650  bool active = (substate->getInstanceName() == substateName);
651  substate->setActiveState(active);
652  }
653  }
654 
656  {
657  auto substates = getSubstateItems();
658  for (auto substate : substates)
659  {
660  substate->setActiveState(false);
661  }
662  }
663 
665  {
666  QString path = instanceName;
667  StateItem* parent = qgraphicsitem_cast<StateItem*>(parentItem());
668  while (parent)
669  {
670  path = parent->getInstanceName() + "/" + path;
671  parent = qgraphicsitem_cast<StateItem*>(parent->parentItem());
672  }
673  return path;
674  }
675 
677  {
678  StateItem* parent = qgraphicsitem_cast<StateItem*>(parentItem());
679  return parent;
680  }
681 
682  QVector<StateItem*> StateItem::getSubstateItems() const
683  {
684  QVector<StateItem*> result;
685  for (QGraphicsItem* item : this->childItems())
686  {
687  StateItem* state = dynamic_cast<StateItem*>(item);
688  if (state)
689  {
690  result.push_back(state);
691  }
692  }
693  return result;
694  }
695 
696  QVector<TransitionItem*> StateItem::getTransitionItems() const
697  {
698  QVector<TransitionItem*> result;
699  for (QGraphicsItem* item : this->childItems())
700  {
701  TransitionItem* transition = dynamic_cast<TransitionItem*>(item);
702  if (transition)
703  {
704  result.push_back(transition);
705  }
706  }
707  return result;
708  }
709 
711  {
712  return instanceName;
713  }
714 
715  void StateItem::setInstanceName(const QString& value)
716  {
717  if (value != instanceName)
718  {
720  update();
721  }
722  }
723 
724  void StateItem::setActiveState(bool active)
725  {
726  this->active = active;
727  setRimColor();
728  }
729 
730  bool StateItem::itemResizing(const QRectF& oldSize, QRectF& proposedSize)
731  {
732  if (!state->getStateClass())
733  {
734  return false;
735  }
736 
737  return true;
738  }
739 
740 
741 
742  void StateItem::itemResized(const QRectF& oldSize, const QRectF& newSize)
743  {
744  if (oldSize != newSize)
745  {
746  emit stateItemResized(newSize.size());
747  }
748  }
749 
750  void StateItem::itemMoved(const QPointF& oldPos, const QPointF& newPos)
751  {
752  // ARMARX_INFO << VAROUT(oldPos) << " " << VAROUT(newPos);
753  if (oldPos != newPos)
754  {
755  // ARMARX_INFO << "Changed";
756  emit stateItemMoved(newPos);
757 
758  }
759  }
760 
761  void StateItem::itemBoundingBoxChanged(float oldSize, float size)
762  {
763 
764  if (oldSize != size)
765  {
766  // ARMARX_INFO << VAROUT(oldSize) << " newBB: " << size;
767  emit stateItemBoundingBoxChanged(size);
768  }
769  }
770 
771 
772  void StateItem::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
773  {
774  if (isLevelOfDetailLow(event))
775  {
776  event->ignore();
777  ARMARX_DEBUG << "Ignoring context menu event on " << state->getInstanceName();
778  return;
779  }
780  if (scene())
781  {
782  scene()->clearSelection();
783  }
784 
785  this->setSelected(true);
786  emit stateContextMenuRequested(state, event->screenPos(), event->pos());
787  event->accept();
788  }
789 
790 
791  QVariant StateItem::itemChange(GraphicsItemChange change, const QVariant& value)
792  {
793  if (change == ItemSelectedHasChanged && value.toBool() == true)
794  {
795  // ARMARX_IMPORTANT << state->getInstanceName() << " was selected with scale " << scale();
796  // setScale(scale()*1.1);
797  }
798  else if (change == ItemSelectedHasChanged && value.toBool() == false)
799  {
800  // ARMARX_IMPORTANT << state->getInstanceName() << " was UNselected";
801  // setScale(scale()*0.9);
802  }
803  else if (change == ItemScaleHasChanged)
804  {
805  emit stateItemBoundingBoxChanged(std::max(bounds.width(), bounds.height())*value.toFloat());
806  // itemBoundingBoxChanged(std::max(oldRect.width(), oldRect.height()),
807  // std::max(bounds.width(), bounds.height()));
808  // emit stateItemScaled(value.toFloat());
809  }
810  else if (change == ItemSceneChange)
811  {
812  StateScene* oldStateScene = dynamic_cast<StateScene*>(scene());
813 
814  if (oldStateScene)
815  {
816  disconnect(this, SIGNAL(stateContextMenuRequested(statechartmodel::StateInstancePtr, QPoint, QPointF)), oldStateScene, SIGNAL(stateContextMenuRequested(statechartmodel::StateInstancePtr, QPoint, QPointF)));
818  }
819 
820  StateScene* stateScene = dynamic_cast<StateScene*>(value.value<QGraphicsScene*>());
821 
822  if (stateScene)
823  {
824  // ARMARX_INFO_S << "scene OF " << state->getInstanceName() << " has changed - StateScene";
825  connect(this, SIGNAL(stateContextMenuRequested(statechartmodel::StateInstancePtr, QPoint, QPointF)),
829  }
830 
831  // else
832  // ARMARX_INFO_S << "scene OF " << state->getInstanceName() << " has changed - noScene";
833  }
834 
835  return RoundRectItem::itemChange(change, value);
836  }
837 
838  void StateItem::dragEnterEvent(QGraphicsSceneDragDropEvent* event)
839  {
840  // ARMARX_INFO << "Drag Enter event " << state->getInstanceName();
841  const AbstractStateMimeData* data = qobject_cast<const AbstractStateMimeData*>(event->mimeData());
842 
843  if (data && state && state->getStateClass() && data->getState() && state->getType() == eNormalState)
844  {
845  event->setDropAction(Qt::LinkAction);
846  }
847  else
848  {
849  event->setDropAction(Qt::IgnoreAction);
850  }
851 
852  event->accept();
853  }
854 
855  void StateItem::dragMoveEvent(QGraphicsSceneDragDropEvent* event)
856  {
857  dragEnterEvent(event);
858  }
859 
860 
861 
862  void StateItem::dropEvent(QGraphicsSceneDragDropEvent* event)
863  {
864  // ARMARX_INFO << "drop event " << state->getInstanceName();
865  if (event->proposedAction() == Qt::IgnoreAction)
866  {
867  return;
868  }
869 
870  const AbstractStateMimeData* data = qobject_cast<const AbstractStateMimeData*>(event->mimeData());
871  bool accept = true;
872  if (data && state && state->getStateClass() && data->getState()
873  && (state->getType() == eNormalState || state->getType() == eRemoteState))
874  {
875  int i = 2;
876  const QString newStateNameBase = data->getState()->getStateName();
877  QString newStateName = newStateNameBase;
878 
879  while (state->getStateClass()->getSubstates().find(newStateName) != state->getStateClass()->getSubstates().end())
880  {
881  newStateName = newStateNameBase + "_" + QString::number(i);
882  i++;
883  }
884 
885  if (hasAncestor(data->getState()) || data->getState()->hasDescendant(state->getStateClass()))
886  {
887  QMessageBox::warning(event->source(), "State drag'n'drop error", "State cycle detected - you must not insert a state which is also a parent state of the current state");
888  accept = false;
889  }
890  else if (data->getState()->getType() == eDynamicRemoteState && !data->isInSameGroup(state->getStateClass()))
891  {
892  QMessageBox::warning(event->source(), "State drag'n'drop error", "Dynamic Remote States can only be added in the same group.");
893  accept = false;
894  }
895  else if (data->isInSameGroup(state->getStateClass()))
896  {
897  if (data->getState()->getType() == eDynamicRemoteState)
898  {
899  state->getStateClass()->addDynamicRemoteSubstate(data->getState(), newStateName, event->pos());
900  }
901  else
902  {
903  state->getStateClass()->addSubstate(data->getState(), newStateName, event->pos());
904  }
905  }
906  else if (data->isPublic())
907  {
908  state->getStateClass()->addRemoteSubstate(data->getState(), data->getProxyName(), newStateName, event->pos());
909  }
910  else
911  {
912  QMessageBox::warning(event->source(), "State drag'n'drop error", "Only public states can be added as a Remote State.");
913  accept = false;
914  }
915 
916 
917  }
918  else
919  {
920  accept = false;
921  }
922 
923 
924  if (accept)
925  {
926  event->setDropAction(Qt::LinkAction);
927  event->accept();
928  }
929  else
930  {
931  event->setDropAction(Qt::IgnoreAction);
932  event->accept();
933  }
934  }
935 
937  {
938  if (!sC)
939  {
940  return false;
941  }
942 
943  StateItem* state = qgraphicsitem_cast<StateItem*>(parentItem());
944  if (!state)
945  {
946  return false;
947  }
948  if (!state->getStateInstance() || !state->getStateInstance()->getStateClass())
949  {
950  return false;
951  }
952 
953  if (state->getStateInstance()->getStateClass()->getUUID() == sC->getUUID())
954  {
955  return true;
956  }
957 
958  return state->hasAncestor(sC);
959  }
960 
962  {
963  if (!sC || !state->getStateClass())
964  {
965  return false;
966  }
967  return state->getStateClass()->hasDescendant(sC);
968 
969 
970  }
971  LevelOfDetail StateItem::getLevelOfDetail(float levelOfDetail) const
972  {
973  if (maxShownSubstateLevel >= 0) // only show X levels of substates
974  {
975  int level = getInstanceLevel();
976  if (level > maxShownSubstateLevel)
977  {
978  return eHidden;
979  }
980  else if (level >= maxShownSubstateLevel)
981  {
982  return eNoSubstates;
983  }
984  }
985  return MorphingItem::getLevelOfDetail(levelOfDetail);
986  }
987 }
armarx::AbstractStateMimeData
The AbstractStateMimeData class is used to transport state data from the treeview to the stateview an...
Definition: StateMimeData.h:36
RoundRectItem::isLevelOfDetailLow
bool isLevelOfDetailLow(QGraphicsSceneEvent *event) const
Definition: RoundRectItem.cpp:445
armarx::StateItem::viewAll
void viewAll()
Definition: StateItem.cpp:417
armarx::StateItem::dragEnterEvent
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override
Definition: StateItem.cpp:838
armarx::StateItem::StateItem
StateItem(statechartmodel::StateInstancePtr state, QGraphicsItem *parent=0)
Definition: StateItem.cpp:52
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::StateItem::getInstanceName
QString getInstanceName() const
Definition: StateItem.cpp:710
armarx::TransitionItem::updateLabel
void updateLabel()
Definition: TransitionItem.cpp:276
armarx::StateItem::state
statechartmodel::StateInstancePtr state
Definition: StateItem.h:126
armarx::MorphingItem::getLevelOfDetail
virtual LevelOfDetail getLevelOfDetail(QPainter *painter) const
Definition: MorphingItem.cpp:48
armarx::StateItem::setActiveSubstate
void setActiveSubstate(const QString &substateName)
Definition: StateItem.cpp:645
RoundRectItem::setEditable
void setEditable(bool editable)
Definition: RoundRectItem.cpp:483
armarx::StateItem::getLevelOfDetail
LevelOfDetail getLevelOfDetail(float levelOfDetail) const override
Definition: StateItem.cpp:971
armarx::StateItem::getStateInstance
statechartmodel::StateInstancePtr getStateInstance() const
Definition: StateItem.h:70
armarx::StateItem::itemBoundingBoxChanged
void itemBoundingBoxChanged(float oldSize, float size) override
Definition: StateItem.cpp:761
RoundRectItem::itemChange
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override
Definition: RoundRectItem.cpp:488
StateItem.h
armarx::statechartmodel::eUnchanged
@ eUnchanged
Definition: SignalType.h:36
armarx::StateItem::setActiveState
void setActiveState(bool active)
Definition: StateItem.cpp:724
detail
Definition: OpenCVUtil.cpp:127
armarx::statechartmodel::State::StateTypeToString
static QString StateTypeToString(eStateType type)
Definition: State.cpp:1188
armarx::StateItem::notifyTransitionsChanged
void notifyTransitionsChanged(statechartmodel::StateInstancePtr transition, statechartmodel::SignalType signalType)
Definition: StateItem.cpp:368
armarx::StateItem::getInstanceLevel
int getInstanceLevel() const
Definition: StateItem.cpp:605
RoundRectItem::setRimPen
void setRimPen(QPen newPen)
Definition: RoundRectItem.cpp:73
armarx::MorphingItem
Definition: MorphingItem.h:39
armarx::StateItem::maxShownSubstateLevel
int maxShownSubstateLevel
Definition: StateItem.h:132
armarx::StateItem::~StateItem
~StateItem() override
Definition: StateItem.cpp:77
RoundRectItem::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) override
Definition: RoundRectItem.cpp:110
armarx::StateItem::hasAncestor
bool hasAncestor(statechartmodel::StatePtr state) const
Definition: StateItem.cpp:936
armarx::StateItem::setRimColor
void setRimColor()
Definition: StateItem.cpp:551
armarx::statechartmodel::StateInstancePtr
std::shared_ptr< StateInstance > StateInstancePtr
Definition: StateInstance.h:138
armarx::StateItem::instanceName
QString instanceName
Definition: StateItem.h:129
armarx::TransitionItem::recalcPath
void recalcPath()
Definition: TransitionItem.cpp:129
armarx::StateItem::clearActiveSubstate
void clearActiveSubstate()
Definition: StateItem.cpp:655
armarx::eHidden
@ eHidden
Definition: MorphingItem.h:37
armarx::StateItem::stateScene
StateScene * stateScene
Definition: StateItem.h:125
armarx::StateItem::transitionContextMenuRequested
void transitionContextMenuRequested(statechartmodel::TransitionCPtr transition, statechartmodel::StatePtr state, QPoint mouseScreenPos, QPointF mouseItemPos)
armarx::StateItem::setMaxShownSubstateLevel
void setMaxShownSubstateLevel(int value)
Definition: StateItem.cpp:632
armarx::StateItem::getFullStatePath
QString getFullStatePath() const
Definition: StateItem.cpp:664
armarx::StateItem::getMaxShownSubstateLevel
int getMaxShownSubstateLevel() const
Definition: StateItem.cpp:627
armarx::StateItem::itemChange
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
Definition: StateItem.cpp:791
armarx::StateItem::dropEvent
void dropEvent(QGraphicsSceneDragDropEvent *event) override
Definition: StateItem.cpp:862
armarx::StateItem::setStateColor
void setStateColor()
Definition: StateItem.cpp:494
armarx::TransitionItem::highlightAnimation
void highlightAnimation(int duration=5000)
Definition: TransitionItem.cpp:262
armarx::StateItem::removeChildren
void removeChildren()
Definition: StateItem.cpp:583
armarx::StateItem::stateItemMoved
void stateItemMoved(QPointF newPosition)
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::StateItem::stateItemBoundingBoxChanged
void stateItemBoundingBoxChanged(float newSquareBoundingBoxSize)
armarx::StateItem::subStates
StateInstanceItemMap subStates
Definition: StateItem.h:128
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::StateItem::transitions
TransitionMap transitions
Definition: StateItem.h:131
armarx::StateItem::adjustPosition
QPointF adjustPosition(QPointF &newPos) override
Definition: StateItem.cpp:617
armarx::StateItem::forwardTransitionContextMenuRequested
void forwardTransitionContextMenuRequested(statechartmodel::TransitionCPtr transition, QPoint mouseScreenPos, QPointF mouseItemPos)
Definition: StateItem.cpp:383
armarx::StateItem::getTransitionItems
QVector< TransitionItem * > getTransitionItems() const
Definition: StateItem.cpp:696
RoundRectItem::setColor
void setColor(QColor newColor)
Definition: RoundRectItem.cpp:63
max
T max(T t1, T t2)
Definition: gdiam.h:48
armarx::statechartmodel::eAdded
@ eAdded
Definition: SignalType.h:35
armarx::StateItem::setup
void setup(QGraphicsItem *parent)
Definition: StateItem.cpp:435
armarx::statechartmodel::eActivated
@ eActivated
Definition: SignalType.h:38
armarx::StateItem::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Definition: StateItem.cpp:82
armarx::StateItem::notifyStateChanged
void notifyStateChanged(statechartmodel::SignalType signalType)
Definition: StateItem.cpp:196
armarx::TransitionItem
Definition: TransitionItem.h:44
armarx::MorphingItem::getLevelOfDetailByParent
virtual LevelOfDetail getLevelOfDetailByParent(QPainter *painter, MorphingItem *parent) const
Definition: MorphingItem.cpp:77
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
armarx::red
QColor red()
Definition: StyleSheets.h:76
TransitionItem.h
ExpressionException.h
armarx::StateItem::itemResizing
bool itemResizing(const QRectF &oldSize, QRectF &proposedSize) override
Definition: StateItem.cpp:730
option
#define option(type, fn)
armarx::StateItem::notifyTransitionChanged
void notifyTransitionChanged(statechartmodel::TransitionCPtr transition, statechartmodel::SignalType signalType)
Definition: StateItem.cpp:303
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
RoundRectItem
Definition: RoundRectItem.h:34
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::statechartmodel::eRemoved
@ eRemoved
Definition: SignalType.h:40
ArmarXWidgetController.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::StateItem::stateContextMenuRequested
void stateContextMenuRequested(statechartmodel::StateInstancePtr stateInstace, QPoint mouseScreenPos, QPointF mouseItemPos)
armarx::statechartmodel::SignalType
SignalType
The SignalType enum.
Definition: SignalType.h:33
armarx::StateItem::itemMoved
void itemMoved(const QPointF &oldPos, const QPointF &newPos) override
Definition: StateItem.cpp:750
RoundRectItem::bounds
QRectF bounds
Definition: RoundRectItem.h:78
armarx::StateItem::transitionMoved
void transitionMoved(statechartmodel::TransitionCPtr transition, QPointF dropPoint)
Definition: StateItem.cpp:388
armarx::statechartmodel::TransitionCPtr
std::shared_ptr< const Transition > TransitionCPtr
Definition: Transition.h:94
armarx::StateItem::dragMoveEvent
void dragMoveEvent(QGraphicsSceneDragDropEvent *event) override
Definition: StateItem.cpp:855
armarx::statechartmodel::StatePtr
std::shared_ptr< State > StatePtr
Definition: State.h:46
armarx::StateItem
Definition: StateItem.h:58
armarx::statechartmodel::eChanged
@ eChanged
Definition: SignalType.h:37
armarx::StateItem::updateToolTip
void updateToolTip()
Definition: StateItem.cpp:565
armarx::LevelOfDetail
LevelOfDetail
Definition: MorphingItem.h:33
armarx::StateItem::active
bool active
Definition: StateItem.h:133
min
T min(T t1, T t2)
Definition: gdiam.h:42
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::StateItem::hasDescendant
bool hasDescendant(statechartmodel::StatePtr state) const
Definition: StateItem.cpp:961
armarx::eNoSubstates
@ eNoSubstates
Definition: MorphingItem.h:36
MAXFONTSIZE
#define MAXFONTSIZE
Definition: StateItem.cpp:46
armarx::StateScene
Definition: StateScene.h:53
armarx::StateItem::setInstanceName
void setInstanceName(const QString &value)
Definition: StateItem.cpp:715
armarx::StateItem::adjustSize
void adjustSize()
Definition: StateItem.cpp:422
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::StateItem::connectSlots
void connectSlots()
Definition: StateItem.cpp:443
armarx::StateItem::getParentStateItem
StateItem * getParentStateItem() const
Definition: StateItem.cpp:676
armarx::StateItem::notifySubstateChanged
void notifySubstateChanged(statechartmodel::StateInstancePtr substate, statechartmodel::SignalType signalType)
Definition: StateItem.cpp:213
armarx::StateItem::contextMenuEvent
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
Definition: StateItem.cpp:772
armarx::StateItem::getSubstateItems
QVector< StateItem * > getSubstateItems() const
Definition: StateItem.cpp:682
RoundRectItem::setSize
void setSize(const QSizeF &newSize)
Definition: RoundRectItem.cpp:96
armarx::StateItem::itemResized
void itemResized(const QRectF &oldSize, const QRectF &newSize) override
Definition: StateItem.cpp:742
armarx::StateItem::initialCreation
void initialCreation()
Definition: StateItem.cpp:465
armarx::StateItem::stateItemResized
void stateItemResized(QSizeF newSize)