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 <QObject>
26 #include <QRectF>
27 #include <QString>
28 #include <QMetaType>
29 
30 #include <memory>
31 
32 #include <ArmarXCore/interface/statechart/StatechartIce.h>
33 
35 
37 {
38  class State;
39  using StatePtr = std::shared_ptr<State>;
40  using StateCPtr = std::shared_ptr<const State>;
41 
42  class Visitor;
43 
44  class StateInstance :
45  public QObject,
46  public std::enable_shared_from_this<StateInstance>,
47  public Logging
48  {
49  Q_OBJECT
50  public:
51  StateInstance(const QString& instanceName, StatePtr parentState = StatePtr());
52  QString getInstanceName() const;
53  virtual void setInstanceName(const QString& value);
54 
55  virtual StatePtr getStateClass() const
56  {
57  return StatePtr();
58  }
60  {
61  return parentState.lock();
62  }
63  /**
64  * @brief getTopLeft returns the topleft point of the stateinstance in the
65  * coordinate system of the parent state.
66  *
67  */
68  const QPointF& getTopLeft() const
69  {
70  return position;
71  }
72  const QPointF getCenter() const;
73 
74  /**
75  * @brief getBoundingSquare return the maximum bounding box of this state instance
76  * in parent coordinate system
77  * @return
78  * @see getBounds()
79  */
80  QRectF getBoundingSquare() const;
81 
82  /**
83  * @brief getBounds returns the rectangle occupied by this state instance in
84  * the parent coordinate system.
85  * @see getBoundingBox()
86  */
87  QRectF getBounds() const
88  {
89  return QRectF(position, getClassSize() * getScale());
90  }
91 
92  float getBoundingSquareSize() const
93  {
94  return boundingSquareSize;
95  }
96 
97  /**
98  * @brief getScale returns the scale of this state instance, which is the relation between
99  * boundingSquareSize and classSize. Resizing is only done with this scale at the moment.
100  *
101  */
102  float getScale() const;
103 
104  QSizeF getClassSize() const;
105 
106  virtual eStateType getType() const = 0;
107 
108  virtual void accept(Visitor& visitor) const = 0;
109 
110  static const QSizeF StateDefaultSize;
111 
112  QPointF adjustPosition(QPointF& newPos) const;
113 
114  bool isActive();
115 
116  /*!
117  * @brief input values of this state instance, only used by Viewer.
118  * */
122  const int defaultBoundingSquareSize = 100;
123  public slots:
124  // void setActive(bool status);
125  void setPosition(QPointF newPosition);
126  void setCenter(const QPointF& newStateCenter);
127  void setBoundingBox(float squareSize);
128  void updateScale();
129  // signals:
130  // void instanceResized();
131  protected:
132  QString name;
133  std::weak_ptr<State> parentState;
134 
135  QPointF position;
137  };
138  using StateInstancePtr = std::shared_ptr<StateInstance>;
139 }
140 
armarx::statechartmodel::StateInstance::adjustPosition
QPointF adjustPosition(QPointF &newPos) const
Definition: StateInstance.cpp:107
armarx::statechartmodel::StateInstance::updateScale
void updateScale()
Definition: StateInstance.cpp:208
armarx::statechartmodel::StateInstance::parentState
std::weak_ptr< State > parentState
Definition: StateInstance.h:133
armarx::statechartmodel::StateInstance
Definition: StateInstance.h:44
armarx::statechartmodel::StateInstance::getStateClass
virtual StatePtr getStateClass() const
Definition: StateInstance.h:55
armarx::statechartmodel::StateInstance::outputParameters
::armarx::StateParameterMap outputParameters
Definition: StateInstance.h:121
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:172
armarx::statechartmodel::StateInstance::setPosition
void setPosition(QPointF newPosition)
Definition: StateInstance.cpp:134
armarx::statechartmodel::StateInstance::name
QString name
Definition: StateInstance.h:132
armarx::statechartmodel::StateInstance::getCenter
const QPointF getCenter() const
Definition: StateInstance.cpp:80
armarx::statechartmodel::StateInstancePtr
std::shared_ptr< StateInstance > StateInstancePtr
Definition: StateInstance.h:138
armarx::statechartmodel::StateInstance::setBoundingBox
void setBoundingBox(float squareSize)
Definition: StateInstance.cpp:187
armarx::statechartmodel::StateInstance::position
QPointF position
Definition: StateInstance.h:135
armarx::statechartmodel::StateInstance::isActive
bool isActive()
Definition: StateInstance.cpp:249
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
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:87
armarx::statechartmodel::StateInstance::getParent
StatePtr getParent() const
Definition: StateInstance.h:59
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:87
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:68
armarx::Logging
Base Class for all Logging classes.
Definition: Logging.h:232
armarx::statechartmodel::StateInstance::inputParameters
::armarx::StateParameterMap inputParameters
input values of this state instance, only used by Viewer.
Definition: StateInstance.h:119
armarx::statechartmodel::StateInstance::StateDefaultSize
static const QSizeF StateDefaultSize
Definition: StateInstance.h:110
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:239
armarx::statechartmodel::StateInstance::localParameters
::armarx::StateParameterMap localParameters
Definition: StateInstance.h:120
armarx::statechartmodel::StatePtr
std::shared_ptr< State > StatePtr
Definition: State.h:46
armarx::statechartmodel::StateInstance::defaultBoundingSquareSize
const int defaultBoundingSquareSize
Definition: StateInstance.h:122
armarx::statechartmodel::StateInstance::setInstanceName
virtual void setInstanceName(const QString &value)
Definition: StateInstance.cpp:60
Logging.h
armarx::statechartmodel::StateInstance::getClassSize
QSizeF getClassSize() const
Definition: StateInstance.cpp:226
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:92
armarx::statechartmodel::StateInstance::boundingSquareSize
float boundingSquareSize
Definition: StateInstance.h:136
armarx::statechartmodel::StateInstance::getInstanceName
QString getInstanceName() const
Definition: StateInstance.cpp:44