StateInstance.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::
17* @author Mirko Waechter ( mirko.waechter at kit dot edu)
18* @date 2014
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#pragma once
24
25#include <memory>
26
27#include <QMetaType>
28#include <QObject>
29#include <QRectF>
30#include <QString>
31
33#include <ArmarXCore/interface/statechart/StatechartIce.h>
34
36{
37 class State;
38 using StatePtr = std::shared_ptr<State>;
39 using StateCPtr = std::shared_ptr<const State>;
40
41 class Visitor;
42
44 public QObject,
45 public std::enable_shared_from_this<StateInstance>,
46 public Logging
47 {
48 Q_OBJECT
49 public:
50 StateInstance(const QString& instanceName, StatePtr parentState = StatePtr());
51 QString getInstanceName() const;
52 virtual void setInstanceName(const QString& value);
53
54 virtual StatePtr
56 {
57 return StatePtr();
58 }
59
61 getParent() const
62 {
63 return parentState.lock();
64 }
65
66 /**
67 * @brief getTopLeft returns the topleft point of the stateinstance in the
68 * coordinate system of the parent state.
69 *
70 */
71 const QPointF&
72 getTopLeft() const
73 {
74 return position;
75 }
76
77 const QPointF getCenter() const;
78
79 /**
80 * @brief getBoundingSquare return the maximum bounding box of this state instance
81 * in parent coordinate system
82 * @return
83 * @see getBounds()
84 */
85 QRectF getBoundingSquare() const;
86
87 /**
88 * @brief getBounds returns the rectangle occupied by this state instance in
89 * the parent coordinate system.
90 * @see getBoundingBox()
91 */
92 QRectF
93 getBounds() const
94 {
95 return QRectF(position, getClassSize() * getScale());
96 }
97
98 float
100 {
101 return boundingSquareSize;
102 }
103
104 /**
105 * @brief getScale returns the scale of this state instance, which is the relation between
106 * boundingSquareSize and classSize. Resizing is only done with this scale at the moment.
107 *
108 */
109 float getScale() const;
110
111 QSizeF getClassSize() const;
112
113 virtual eStateType getType() const = 0;
114
115 virtual void accept(Visitor& visitor) const = 0;
116
117 static const QSizeF StateDefaultSize;
118
119 QPointF adjustPosition(QPointF& newPos) const;
120
121 bool isActive();
122
123 /*!
124 * @brief input values of this state instance, only used by Viewer.
125 * */
126 ::armarx::StateParameterMap inputParameters;
127 ::armarx::StateParameterMap localParameters;
128 ::armarx::StateParameterMap outputParameters;
130 public slots:
131 // void setActive(bool status);
132 void setPosition(QPointF newPosition);
133 void setCenter(const QPointF& newStateCenter);
134 void setBoundingBox(float squareSize);
135 void updateScale();
136 // signals:
137 // void instanceResized();
138 protected:
139 QString name;
140 std::weak_ptr<State> parentState;
141
142 QPointF position;
144 };
145
146 using StateInstancePtr = std::shared_ptr<StateInstance>;
147} // namespace armarx::statechartmodel
148
StateInstance(const QString &instanceName, StatePtr parentState=StatePtr())
::armarx::StateParameterMap inputParameters
input values of this state instance, only used by Viewer.
QRectF getBounds() const
getBounds returns the rectangle occupied by this state instance in the parent coordinate system.
virtual eStateType getType() const =0
const QPointF & getTopLeft() const
getTopLeft returns the topleft point of the stateinstance in the coordinate system of the parent stat...
virtual void accept(Visitor &visitor) const =0
QPointF adjustPosition(QPointF &newPos) const
QRectF getBoundingSquare() const
getBoundingSquare return the maximum bounding box of this state instance in parent coordinate system
virtual void setInstanceName(const QString &value)
float getScale() const
getScale returns the scale of this state instance, which is the relation between boundingSquareSize a...
void setPosition(QPointF newPosition)
virtual StatePtr getStateClass() const
::armarx::StateParameterMap localParameters
::armarx::StateParameterMap outputParameters
void setCenter(const QPointF &newStateCenter)
std::shared_ptr< State > StatePtr
Definition State.h:48
std::shared_ptr< StateInstance > StateInstancePtr
std::shared_ptr< const State > StateCPtr
Definition XmlWriter.h:45