ActiveStateFollower.cpp
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 2016
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22#include "ActiveStateFollower.h"
23
25
26namespace armarx
27{
28
30 QVariantAnimation(parent), statechartView(statechartView)
31 {
32 duration = 1000;
33 connect(&activeStateCheckerTimer, SIGNAL(timeout()), this, SLOT(checkActiveState()));
34 activeStateCheckerTimer.setInterval(1000);
35 // activeStateCheckerTimer.start();
36 }
37
38 void
40 {
41 if (on)
42 {
44 }
45 else
46 {
48 }
49 }
50
51 void
56
57 void
62
63 void
65 {
66 if (!statechartView)
67 {
68 return;
69 }
70 auto state = statechartView->getStateInstance();
71 if (!state || !state->getStateClass())
72 {
73 return;
74 }
75 statechartmodel::StateInstancePtr activeState = state->getStateClass()->getActiveSubstate();
76 while (activeState)
77 {
78 if (!activeState->getStateClass() || !activeState->getStateClass()->getActiveSubstate())
79 {
80 break;
81 }
82 activeState = activeState->getStateClass()->getActiveSubstate();
83 }
84
85 if (!activeState || activeState == currentActiveState)
86 {
87 return;
88 }
89 auto items = statechartView->getScene()->items();
90 QPointer<StateItem> stateItem;
91 for (QGraphicsItem* item : items)
92 {
93 stateItem = dynamic_cast<StateItem*>(item);
94 if (stateItem && activeState == stateItem->getStateInstance())
95 {
96 break;
97 }
98 }
99 if (currentActiveStateItem == stateItem)
100 {
101 return;
102 }
103 stop();
104 currentActiveStateItem = stateItem;
105 currentTargetPos = stateItem->mapToScene(stateItem->scenePos());
106 startPos = statechartView->getGraphicsView()
107 ->mapToScene(statechartView->getGraphicsView()->viewport()->rect())
108 .boundingRect()
109 .center();
110 if (statechartView->getGraphicsView()
111 ->viewport()
112 ->rect()
113 .adjusted(50, 50, -50, -50)
114 .contains(statechartView->getGraphicsView()->mapFromScene(currentTargetPos)))
115 {
116 ARMARX_DEBUG_S << "already visible: " << currentTargetPos;
117 return;
118 }
119 ARMARX_INFO_S << "travel distance: " << (startPos - currentTargetPos).manhattanLength();
120 // if ((startPos - currentTargetPos).manhattanLength() < 1) // dont do marginal motions
121 // {
122 // return;
123 // }
124 startTime = IceUtil::Time::now();
125 setStartValue(startPos);
126 setEndValue(currentTargetPos);
127 setEasingCurve(QEasingCurve::InOutQuad);
128 setDuration(duration);
129 start();
130 }
131
137
138 void
143
144} // namespace armarx
145
146void
150
151void
153{
154 ARMARX_INFO_S << "Manually triggered centering on state";
157}
158
159void
161{
162 // ARMARX_INFO_S << "cur ani value : " << value.toPointF();
163 statechartView->getGraphicsView()->centerOn(value.toPointF());
164 // statechartView->getGraphicsView()->ensureVisible(QRectF(value.toPointF(), QSizeF(1, 1)));
165}
QPointer< StateItem > currentActiveStateItem
QPointer< StatechartView > statechartView
StatechartView * getStatechartView() const
ActiveStateFollower(StatechartView *statechartView, QWidget *parent=NULL)
statechartmodel::StateInstancePtr currentActiveState
void setStatechartView(StatechartView *value)
void updateCurrentValue(const QVariant &value) override
#define ARMARX_DEBUG_S
The logging level for output that is only interesting while debugging.
Definition Logging.h:205
#define ARMARX_INFO_S
Definition Logging.h:202
std::shared_ptr< StateInstance > StateInstancePtr
This file offers overloads of toIce() and fromIce() functions for STL container types.