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 
43  class StateInstance :
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
55  getStateClass() const
56  {
57  return StatePtr();
58  }
59 
60  StatePtr
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  * */
129  const int defaultBoundingSquareSize = 100;
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 
armarx::statechartmodel::StateInstance::adjustPosition
QPointF adjustPosition(QPointF &newPos) const
Definition: StateInstance.cpp:114
armarx::statechartmodel::StateInstance::updateScale
void updateScale()
Definition: StateInstance.cpp:219
armarx::statechartmodel::StateInstance::parentState
std::weak_ptr< State > parentState
Definition: StateInstance.h:140
armarx::statechartmodel::StateInstance
Definition: StateInstance.h:43
armarx::statechartmodel::StateInstance::getStateClass
virtual StatePtr getStateClass() const
Definition: StateInstance.h:55
armarx::statechartmodel::StateInstance::outputParameters
::armarx::StateParameterMap outputParameters
Definition: StateInstance.h:128
armarx::statechartmodel::StateInstance::StateInstance
StateInstance(const QString &instanceName, StatePtr parentState=StatePtr())
Definition: StateInstance.cpp:33
armarx::statechartmodel::StateInstance::setCenter
void setCenter(const QPointF &newStateCenter)
Definition: StateInstance.cpp:179
armarx::statechartmodel::StateInstance::setPosition
void setPosition(QPointF newPosition)
Definition: StateInstance.cpp:139
armarx::statechartmodel::StateInstance::name
QString name
Definition: StateInstance.h:139
armarx::statechartmodel::StateInstance::getCenter
const QPointF getCenter() const
Definition: StateInstance.cpp:86
armarx::statechartmodel::StateInstancePtr
std::shared_ptr< StateInstance > StateInstancePtr
Definition: StateInstance.h:146
armarx::statechartmodel::StateInstance::setBoundingBox
void setBoundingBox(float squareSize)
Definition: StateInstance.cpp:197
armarx::statechartmodel::StateInstance::position
QPointF position
Definition: StateInstance.h:142
armarx::statechartmodel::StateInstance::isActive
bool isActive()
Definition: StateInstance.cpp:259
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::statechartmodel::StateInstance::getType
virtual eStateType getType() const =0
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::statechartmodel
Definition: XmlWriter.h:36
KITProsthesis::ProsthesisState::State
State
Definition: KITProstheticHandInterface.ice:32
armarx::statechartmodel::StateInstance::getBoundingSquare
QRectF getBoundingSquare() const
getBoundingSquare return the maximum bounding box of this state instance in parent coordinate system
Definition: StateInstance.cpp:95
armarx::statechartmodel::StateInstance::getParent
StatePtr getParent() const
Definition: StateInstance.h:61
armarx::statechartmodel::Visitor
Definition: Visitor.h:39
armarx::statechartmodel::StateInstance::getBounds
QRectF getBounds() const
getBounds returns the rectangle occupied by this state instance in the parent coordinate system.
Definition: StateInstance.h:93
armarx::statechartmodel::StateInstance::getTopLeft
const QPointF & getTopLeft() const
getTopLeft returns the topleft point of the stateinstance in the coordinate system of the parent stat...
Definition: StateInstance.h:72
armarx::Logging
Base Class for all Logging classes.
Definition: Logging.h:239
armarx::statechartmodel::StateInstance::inputParameters
::armarx::StateParameterMap inputParameters
input values of this state instance, only used by Viewer.
Definition: StateInstance.h:126
armarx::statechartmodel::StateInstance::StateDefaultSize
static const QSizeF StateDefaultSize
Definition: StateInstance.h:117
armarx::statechartmodel::StateInstance::getScale
float getScale() const
getScale returns the scale of this state instance, which is the relation between boundingSquareSize a...
Definition: StateInstance.cpp:251
armarx::statechartmodel::StateInstance::localParameters
::armarx::StateParameterMap localParameters
Definition: StateInstance.h:127
armarx::statechartmodel::StatePtr
std::shared_ptr< State > StatePtr
Definition: State.h:48
armarx::statechartmodel::StateInstance::defaultBoundingSquareSize
const int defaultBoundingSquareSize
Definition: StateInstance.h:129
armarx::statechartmodel::StateInstance::setInstanceName
virtual void setInstanceName(const QString &value)
Definition: StateInstance.cpp:65
Logging.h
armarx::statechartmodel::StateInstance::getClassSize
QSizeF getClassSize() const
Definition: StateInstance.cpp:238
armarx::statechartmodel::StateCPtr
std::shared_ptr< const State > StateCPtr
Definition: XmlWriter.h:45
armarx::statechartmodel::StateInstance::accept
virtual void accept(Visitor &visitor) const =0
armarx::statechartmodel::StateInstance::getBoundingSquareSize
float getBoundingSquareSize() const
Definition: StateInstance.h:99
armarx::statechartmodel::StateInstance::boundingSquareSize
float boundingSquareSize
Definition: StateInstance.h:143
armarx::statechartmodel::StateInstance::getInstanceName
QString getInstanceName() const
Definition: StateInstance.cpp:48