StatechartView.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 2014
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#include "StatechartView.h"
24
25#include <QTimer>
26
28#include <ArmarXCore/interface/statechart/RemoteStateOffererIce.h>
31
32#include <ArmarXGui/gui-plugins/StatechartViewerPlugin/ui_StatechartView.h>
33
35#include "../StateScene.h"
36#include "../model/State.h"
39#include "GraphicsViewZoom.h"
40#include "StateItem.h"
41
42namespace armarx
43{
45 bool enableLayouting,
46 QWidget* parent) :
47 QWidget(parent),
48 ui(new Ui::StatechartView),
49 // layoutController(state, enableLayouting)
50 layoutThread(state, enableLayouting)
51 {
52 // layoutController.enableLayouting(enableLayouting);
53
54 srand(IceUtil::Time::now().toMilliSeconds());
55 ui->setupUi(this);
56 stateScene = new StateScene(this);
57
58 if (!state)
59 {
60 state = CreateTestStates();
61 }
62
63 setState(state);
64
65 ui->graphicsView->setScene(stateScene);
66 zoomer = new Graphics_view_zoom(ui->graphicsView);
67 zoomer->set_modifiers(Qt::NoModifier);
68
69 if (state)
70 {
71 layoutThread.run();
72 }
73 else
74 {
75 ARMARX_WARNING_S << "no state set!";
76 }
77
78 connect(stateScene, SIGNAL(selectionChanged()), this, SLOT(onItemChange()));
79 }
80
82 {
83 delete ui;
84 }
85
88 {
89 return stateScene->getStateInstance();
90 }
91
92 QGraphicsView*
94 {
95 return ui->graphicsView;
96 }
97
100 {
101 return zoomer;
102 }
103
106 {
107 return layoutThread.getController();
108 }
109
110 void
112 {
113 stateScene->setToplevelState(state);
114
115 if (state)
116 {
117 layoutThread.setState(state);
118 // layoutController.setTopState(state);
119 }
120 }
121
122 void
124 {
125 ui->graphicsView->setTransform(QTransform());
126 }
127
128 void
130 {
131 QList<QGraphicsItem*> selection = stateScene->selectedItems();
132 foreach (QGraphicsItem* item, selection)
133 {
134 StateItem* state = dynamic_cast<StateItem*>(item);
135
136 if (state)
137 {
138 statechartmodel::StatePtr parent = state->getStateInstance()->getParent();
139
140 if (parent)
141 {
142 if (parent->removeSubstate(state->getStateInstance()->getInstanceName()))
143 {
144 ARMARX_INFO_S << "removed substate";
145 }
146 else
147 {
148 ARMARX_INFO_S << "removing failed";
149 }
150 }
151 }
152 }
153 }
154
155 void
157 {
158 ui->graphicsView->fitInView(stateScene->itemsBoundingRect(), Qt::KeepAspectRatio);
159 }
160
161 void
163 {
164 QList<QGraphicsItem*> selection = stateScene->selectedItems();
165
166 if (selection.size() > 0)
167 {
168 StateItem* state = dynamic_cast<StateItem*>(selection.first());
169
170 if (state && state->getStateInstance())
171 {
173 }
174 }
175 }
176
177 void
179 {
180 stateScene->getTopLevelStateItem()->setMaxShownSubstateLevel(show ? -1 : 1);
181 stateScene->update();
182 }
183
186 {
187
189 topState->setStateName("TopLevelState");
190
192 sub1->setStateName("sub1");
193
196 e1->name = "Success";
197 eventList.append(e1);
199 e2->name = "Failure";
200 eventList.append(e2);
202 e3->name = "Lolz";
203 eventList.append(e3);
204 sub1->setOutgoingEvents(eventList);
205
207 sub2->setStateName("sub2");
208
210 subsub1->setStateName("subsub1");
211
212
213 topState->addSubstate(sub1);
214 topState->addSubstate(sub2);
215 topState->addRemoteSubstate(sub1, "ProxyName", "remotesub1-2");
218 e21->name = "Success";
219 eventList.append(e21);
221 e22->name = "Failure";
222 eventList.append(e22);
223 subsub1->setOutgoingEvents(eventList2);
224 sub1->addSubstate(subsub1);
225
226 subsub1->addEndSubstate("EndState", "Success");
227
229 t1->eventName = "GoOn";
230 t1->sourceState = topState->getSubstates()["sub1"];
231 t1->destinationState = topState->getSubstates()["sub2"];
232 topState->addTransition(t1);
233
234 return topState;
235 }
236
237 QSize
239 {
240 return QSize(200, 200);
241 }
242} // namespace armarx
statechartmodel::StateInstancePtr getStateInstance() const
Definition StateItem.h:66
QSize sizeHint() const override
QGraphicsView * getGraphicsView() const
void showSubSubstates(bool show=true)
statechartmodel::StateInstancePtr getStateInstance() const
Graphics_view_zoom * getGraphicsViewZoomer() const
LayoutController & getLayoutController()
static statechartmodel::StatePtr CreateTestStates()
StatechartView(statechartmodel::StatePtr state=statechartmodel::StatePtr(new statechartmodel::State()), bool enableLayouting=true, QWidget *parent=0)
void setState(statechartmodel::StatePtr state)
void selectedStateChanged(statechartmodel::StateInstancePtr selectedStateInstance)
#define ARMARX_INFO_S
Definition Logging.h:202
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:213
ArmarX Headers.
std::shared_ptr< State > StatePtr
Definition State.h:48
std::shared_ptr< StateInstance > StateInstancePtr
std::shared_ptr< Event > EventPtr
Definition XmlWriter.h:46
QList< EventPtr > EventList
Definition XmlWriter.h:47
std::shared_ptr< Transition > TransitionPtr
Definition Transition.h:90
This file offers overloads of toIce() and fromIce() functions for STL container types.