StateItem.h
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 #pragma once
25 
26 #include "RoundRectItem.h"
27 #include "MorphingItem.h"
28 #include "../model/SignalType.h"
29 
31 
32 #include <QGraphicsWidget>
33 #include <QPointer>
34 
35 #include <memory>
36 
37 namespace armarx
38 {
39  class StateScene;
40 }
41 
43 {
44  class State;
45  using StatePtr = std::shared_ptr<State>;
46  class Transition;
47  using TransitionPtr = std::shared_ptr<Transition>;
48  using TransitionCPtr = std::shared_ptr<const Transition>;
49  class StateInstance;
50  using StateInstancePtr = std::shared_ptr<StateInstance>;
51 }
52 
53 namespace armarx
54 {
55  class StateItem;
56  class TransitionItem;
57 
58  class StateItem :
59  public RoundRectItem,
60  public MorphingItem
61  {
62  Q_OBJECT
63  public:
64 
65 
66 
67  explicit StateItem(statechartmodel::StateInstancePtr state, QGraphicsItem* parent = 0);
68  ~StateItem() override;
69 
71  {
72  return state;
73  }
74 
75 
76 
77  QString getInstanceName() const;
78 
81  int getMaxShownSubstateLevel() const;
83 
84  void clearActiveSubstate();
86 
87  QString getFullStatePath() const;
88  QVector<StateItem*> getSubstateItems() const;
89  QVector<TransitionItem*> getTransitionItems() const;
90  signals:
91  void stateItemResized(QSizeF newSize);
92  void stateItemMoved(QPointF newPosition);
93  void stateItemBoundingBoxChanged(float newSquareBoundingBoxSize);
94  void stateContextMenuRequested(statechartmodel::StateInstancePtr stateInstace, QPoint mouseScreenPos, QPointF mouseItemPos);
95  void transitionContextMenuRequested(statechartmodel::TransitionCPtr transition, statechartmodel::StatePtr state, QPoint mouseScreenPos, QPointF mouseItemPos);
96  public slots:
101 
102  void forwardTransitionContextMenuRequested(statechartmodel::TransitionCPtr transition, QPoint mouseScreenPos, QPointF mouseItemPos);
103  void transitionMoved(statechartmodel::TransitionCPtr transition, QPointF dropPoint);
104  void viewAll();
105  void adjustSize();
106  void setInstanceName(const QString& value);
107  void setActiveState(bool active);
108  void setActiveSubstate(const QString& substateName);
109 
110 
111  protected:
112  void setup(QGraphicsItem* parent);
113  void connectSlots();
114  void initialCreation();
115  void setStateColor();
116  void setRimColor();
117  void updateToolTip();
118  void removeChildren();
119  int getInstanceLevel() const;
120  QPointF adjustPosition(QPointF& newPos) override;
121 
122  // Ui_StateWidget ui;
123  // QGraphicsProxyWidget* prx;
124  QWidget* subWidget;
127  using StateInstanceItemMap = QMap<statechartmodel::StateInstancePtr, QPointer<StateItem>>;
129  QString instanceName;
130  using TransitionMap = QMap<statechartmodel::TransitionCPtr, QPointer<TransitionItem>>;
133  bool active = false;
134 
135 
136  // RoundRectItem interface
137  protected:
138  bool itemResizing(const QRectF& oldSize, QRectF& proposedSize) override;
139  void itemResized(const QRectF& oldSize, const QRectF& newSize) override;
140  void itemMoved(const QPointF& oldPos, const QPointF& newPos) override;
141  void itemBoundingBoxChanged(float oldSize, float size) override;
142 
143  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
144 
145  // QGraphicsItem interface
146  protected:
147  void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
148 
149  // QGraphicsItem interface
150  protected:
151  QVariant itemChange(GraphicsItemChange change, const QVariant& value) override;
152 
153  // QGraphicsItem interface
154  protected:
155  void dragEnterEvent(QGraphicsSceneDragDropEvent* event) override;
156  void dragMoveEvent(QGraphicsSceneDragDropEvent* event) override;
157  void dropEvent(QGraphicsSceneDragDropEvent* event) override;
158 
159  // MorphingItem interface
160  public:
161  LevelOfDetail getLevelOfDetail(float levelOfDetail) const override;
162  };
163 
164 }
165 
166 
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::StateItem::getInstanceName
QString getInstanceName() const
Definition: StateItem.cpp:710
armarx::StateItem::state
statechartmodel::StateInstancePtr state
Definition: StateItem.h:126
armarx::StateItem::setActiveSubstate
void setActiveSubstate(const QString &substateName)
Definition: StateItem.cpp:645
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
armarx::statechartmodel::TransitionPtr
std::shared_ptr< Transition > TransitionPtr
Definition: Transition.h:93
armarx::StateItem::subWidget
QWidget * subWidget
Definition: StateItem.h:124
armarx::StateItem::setActiveState
void setActiveState(bool active)
Definition: StateItem.cpp:724
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
armarx::MorphingItem
Definition: MorphingItem.h:39
armarx::StateItem::maxShownSubstateLevel
int maxShownSubstateLevel
Definition: StateItem.h:132
armarx::StateItem::~StateItem
~StateItem() override
Definition: StateItem.cpp:77
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::StateItem::clearActiveSubstate
void clearActiveSubstate()
Definition: StateItem.cpp:655
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::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::TransitionMap
QMap< statechartmodel::TransitionCPtr, QPointer< TransitionItem > > TransitionMap
Definition: StateItem.h:130
MorphingItem.h
armarx::StateItem::subStates
StateInstanceItemMap subStates
Definition: StateItem.h:128
armarx::statechartmodel
Definition: XmlWriter.h:36
KITProsthesis::ProsthesisState::State
State
Definition: KITProstheticHandInterface.ice:32
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
armarx::StateItem::setup
void setup(QGraphicsItem *parent)
Definition: StateItem.cpp:435
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::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
RoundRectItem
Definition: RoundRectItem.h:34
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
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::StateItem::updateToolTip
void updateToolTip()
Definition: StateItem.cpp:565
armarx::LevelOfDetail
LevelOfDetail
Definition: MorphingItem.h:33
armarx::StateItem::active
bool active
Definition: StateItem.h:133
Logging.h
RoundRectItem.h
armarx::StateItem::hasDescendant
bool hasDescendant(statechartmodel::StatePtr state) const
Definition: StateItem.cpp:961
armarx::StateScene
Definition: StateScene.h:53
armarx::StateItem::setInstanceName
void setInstanceName(const QString &value)
Definition: StateItem.cpp:715
armarx::StateItem::StateInstanceItemMap
QMap< statechartmodel::StateInstancePtr, QPointer< StateItem > > StateInstanceItemMap
Definition: StateItem.h:127
armarx::StateItem::adjustSize
void adjustSize()
Definition: StateItem.cpp:422
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
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)