StatechartEditorController.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include "StateEditorController.h"
27 #include "StateTreeController.h"
28 
30 
32 
33 #include <QFileSystemWatcher>
34 
36 
38 
40 
42 
43 namespace armarx
44 {
45  class StatechartEditorMainWindow;
46 
47  /**
48  \page ArmarXGui-GuiPlugins-StatechartEditorController StatechartEditor
49  \tableofcontents
50 
51  The Statechart Editor is a powerful and convenient tool to design complex behavior.
52  It is deeply integrated into ArmarX and tailored onto it.
53  It allows the user to design hierarchical, distributed statecharts inspired by Harel, 84 [1] in
54  a graphical way and generate and connect it directly with C++ code.
55  For a step-by-step tutorial refer to: \ref ArmarXCore-Tutorials-sce
56 
57  A detailed explanation of ArmarX Statecharts can be found in the publication:<br/>
58  M. Wächter, S. Ottenhaus, M. Kröhnert, N. Vahrenkamp and T. Asfour (2016), *The ArmarX Statechart Concept: Graphical Programming of Robot Behaviour*, Front. Robot. AI 3:33.
59  <a href="http://journal.frontiersin.org/article/10.3389/frobt.2016.00033/full">[DOI]</a>
60 
61  [1]: David Harel: *Statecharts: A Visual Approach to Complex Systems*, CS84-05, Department of Applied Mathematics, The Weizmann Institute of Science, 1984
62 
63  \image html StatechartEditor.png
64 
65  \see \ref Statechart
66  \see \ref ArmarXGui-GuiPlugins-StatechartViewer
67  \see \ref RobotSkillTemplates
68  \see \ref StatechartEditorController
69  \see \ref ArmarXGui-GuiPlugins-EventSender
70  \see \ref ArmarXCore-Tutorials-sce
71 
72  \section SCE-Group-Execution Statechart Execution from the Statechart Editor
73  Statecharts are always executed as part of their statechart group.
74  There are two different ways to execute a statechart group:
75  \li <b>From the Statechart Editor directly:</b> In the context menu of the statechart group it is possible
76  to execute a statechart group directly. This option is meant for quick testing of statecharts. All statechart group dependencies
77  are automatically also executed (they need to be loaded in the current session of the Statechart Editor for this).
78  Before execution a public state that should immediately be entered can be selected. Note
79  that this state must not need any input paramters.
80  \li <b>Starting a statechart group with a scenario:</b> The usual way to start a statechart group is as part of
81  a scenario. For this option, it is possible to drag'n'drop a statechart group from the Statechart Editor to the \ref ArmarXGui-GuiPlugins-ScenarioManagerGuiPlugin "/ScenarioManager.conf".
82  The statechart group needs to be dropped on an open scenario. It is then fully parameterized and ready to be started.
83  Note that for this option all statechart group dependencies need to be added to the scenario manually as well.
84  In the properties of the statechart group it is possible to define a set of state that should be entered automatically. These states will run in parallel.
85 
86  \section SCE-Intro Statechart Editor Intro: Making Armar wave in 4 minutes
87  In this video, the Statechart Editor used to program a simple
88  statechart that makes Armar3 wave. This demonstrates the basic features of the Statechart Editor.
89  There was nothing prepared except starting the simulation and getting the needed joint values for the arm joints.
90  \htmlonly
91  <video width="700" controls>
92  <source src="images/SCE-intro-2016-03-25_17.38.00.mp4" type="video/mp4">
93  Your browser does not support HTML5 video.
94  </video>
95  \endhtmlonly
96 
97  \section SCE-Configurations Editing the runtime configuration of a statechart group
98  Statecharts groups need like component often parameters to work with one specific robot.
99  For statechart groups this can be done with the Statechart Editor. In this video, it is shown
100  how to setup the configuration for one group. This configuration is then always applied when starting
101  the statechart group.
102  \htmlonly
103  <video width="700" controls>
104  <source src="images/SCE-configurations-2016-03-24_03.13.42.mp4" type="video/mp4">
105  Your browser does not support HTML5 video.
106  </video>
107  \endhtmlonly
108 
109  \section SCE-GroupCloning Cloning a statechart group to another package
110  \htmlonly
111  <video width="700" controls>
112  <source src="images/SCE-cloning-2016-03-24_03.50.53.mp4" type="video/mp4">
113  Your browser does not support HTML5 video.
114  </video>
115  \endhtmlonly
116 
117 
118  \section SCE-DirectMapping Direct mapping of parameters during transitions
119  \htmlonly
120  <video width="700" controls>
121  <source src="images/SCE-directvaluemapping-2016-03-30_23.44.26.mp4" type="video/mp4">
122  Your browser does not support HTML5 video.
123  </video>
124  \endhtmlonly
125 
126 
127  */
128 
129 
130  /**
131  \class StatechartEditorController
132  \brief The StatechartEditorController class is the controller of the main widget of the Statechart Editor.
133  */
135  public ArmarXComponentWidgetControllerTemplate<StatechartEditorController>
136  {
137  Q_OBJECT
138 
139  public:
141  ~StatechartEditorController() override;
142 
143  QStringList findAllStatechartGroupDefinitions(const QString& basePath);
144 
145  public slots:
146  void treeviewGroupsDoubleClicked(QModelIndex index);
147  void requestSave();
148  void onStateTabChanged(int index);
151  void searchAndOpenPaths(QStringList paths);
152 
153  void connectToView(int tabIndex);
155  void showCodeFileContent(const QString& path);
156  void showOnEnterFunction();
157  void showRunFunction();
158  void showOnBreakFunction();
159  void showOnExitFunction();
160  void openSelectedState();
161  void closeAllTabs();
162  void executeOpenedState(bool);
163  public:
164  // inherited from Component
165  void onInitComponent() override;
166  void onConnectComponent() override;
167  void onDisconnectComponent() override;
168  void onExitComponent() override;
169 
170  // inherited of ArmarXWidget
171  static QString GetWidgetName()
172  {
173  return "Statecharts.StatechartEditor";
174  }
175  static QIcon GetWidgetIcon()
176  {
177  return QIcon(":/statechart-editor/states.svg");
178  }
179  static QIcon GetWidgetCategoryIcon()
180  {
181  return QIcon(":/statechart-editor/states.svg");
182  }
183  void loadSettings(QSettings* settings) override;
184  void saveSettings(QSettings* settings) override;
185 
186  // ArmarXWidgetController interface
187  QPointer<QWidget> getWidget() override;
188  void openStatechartGroups(QStringList groups);
189  private slots:
190  void initWidget();
191  private:
192  void updateExecutionButtonStatus();
193  void watchState(const std::string& objName);
194  QPointer<StatechartEditorMainWindow> editor;
195  StateEditorControllerPtr stateEditorController;
196  StateTreeControllerPtr treeController;
197  ArmarXPackageToolInterfacePtr packageTool;
198  QFileSystemWatcher* watcher;
199  StateWatcherPtr stateWatcher;
200  bool alreadyWatchingState = false;
201  VariantInfoPtr variantInfo;
202  StatechartProfilesPtr profiles;
203  QPointer<StatechartEditorConfigDialog> dialog;
204  StatechartGroupPtr executedOpenedGroup;
206  // ArmarXWidgetController interface
207  public:
208  QPointer<QDialog> getConfigDialog(QWidget* parent) override;
209  struct Config
210  {
211  QStringList searchPaths;
212  QStringList groupsToLoad;
216  } config;
217 
218 
219 
220  // ArmarXWidgetController interface
221  bool onClose() override;
222  void configured() override;
223  void storeAutoSaveSettings();
224 
225  };
226 
227 }
228 
armarx::StatechartEditorController::Config
Definition: StatechartEditorController.h:209
armarx::StatechartEditorController::Config::lockRemoteStates
bool lockRemoteStates
Definition: StatechartEditorController.h:213
armarx::StatechartEditorController::treeviewGroupsDoubleClicked
void treeviewGroupsDoubleClicked(QModelIndex index)
Definition: StatechartEditorController.cpp:219
armarx::StatechartEditorController::Config::groupsToLoad
QStringList groupsToLoad
Definition: StatechartEditorController.h:212
armarx::StateEditorControllerPtr
std::shared_ptr< StateEditorController > StateEditorControllerPtr
Definition: StateEditorController.h:93
armarx::StatechartEditorController::GetWidgetCategoryIcon
static QIcon GetWidgetCategoryIcon()
Definition: StatechartEditorController.h:179
armarx::ArmarXPackageToolInterfacePtr
std::shared_ptr< ArmarXPackageToolInterface > ArmarXPackageToolInterfacePtr
Definition: ArmarXPackageToolInterface.h:55
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::StatechartEditorController::showCodeFileContent
void showCodeFileContent(const QString &path)
Definition: StatechartEditorController.cpp:367
armarx::StatechartEditorController::getConfigDialog
QPointer< QDialog > getConfigDialog(QWidget *parent) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
Definition: StatechartEditorController.cpp:907
PeriodicTask.h
StateEditorController.h
armarx::StatechartProfilePtr
std::shared_ptr< class StatechartProfile > StatechartProfilePtr
Definition: StatechartContext.h:52
armarx::StatechartEditorController::showStatechartEditorSettingsDialog
void showStatechartEditorSettingsDialog()
Definition: StatechartEditorController.cpp:287
armarx::StatechartEditorController::~StatechartEditorController
~StatechartEditorController() override
Definition: StatechartEditorController.cpp:69
armarx::StatechartEditorController::openStatechartGroups
void openStatechartGroups(QStringList groups)
Definition: StatechartEditorController.cpp:310
armarx::StatechartEditorController::searchAndOpenPaths
void searchAndOpenPaths(QStringList paths)
Definition: StatechartEditorController.cpp:326
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
armarx::StatechartEditorController::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: StatechartEditorController.cpp:149
armarx::StatechartEditorController::Config::selectedProfile
StatechartProfilePtr selectedProfile
Definition: StatechartEditorController.h:215
armarx::StatechartEditorController::onClose
bool onClose() override
onClose is called before the DockWidget is closed.
Definition: StatechartEditorController.cpp:888
armarx::StatechartEditorController::Config::openAllStatesWasSelected
bool openAllStatesWasSelected
Definition: StatechartEditorController.h:214
armarx::statechartmodel::StateInstancePtr
std::shared_ptr< StateInstance > StateInstancePtr
Definition: StateInstance.h:138
armarx::StatechartEditorController::Config::searchPaths
QStringList searchPaths
Definition: StatechartEditorController.h:211
armarx::StatechartEditorController::StatechartEditorController
StatechartEditorController()
Definition: StatechartEditorController.cpp:57
armarx::StatechartEditorController::configured
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
Definition: StatechartEditorController.cpp:896
IceInternal::Handle< StateWatcher >
armarx::StatechartProfilesPtr
std::shared_ptr< StatechartProfiles > StatechartProfilesPtr
Definition: StatechartProfiles.h:35
armarx::StatechartEditorController::showNewStatechartGroupDialog
void showNewStatechartGroupDialog()
Definition: StatechartEditorController.cpp:262
ArmarXPackageToolInterface.h
ArmarXComponentWidgetController.h
armarx::StatechartEditorController::closeAllTabs
void closeAllTabs()
Definition: StatechartEditorController.cpp:463
StateTreeController.h
armarx::StatechartEditorController::connectToView
void connectToView(int tabIndex)
Definition: StatechartEditorController.cpp:338
StatechartProfiles.h
armarx::StatechartEditorController::requestSave
void requestSave()
Definition: StatechartEditorController.cpp:243
armarx::StatechartEditorController::showOnExitFunction
void showOnExitFunction()
Definition: StatechartEditorController.cpp:411
armarx::StatechartEditorController::getWidget
QPointer< QWidget > getWidget() override
getWidget returns a pointer to the a widget of this controller.
Definition: StatechartEditorController.cpp:688
armarx::StatechartEditorController
The StatechartEditorController class is the controller of the main widget of the Statechart Editor.
Definition: StatechartEditorController.h:134
armarx::StatechartEditorController::GetWidgetName
static QString GetWidgetName()
Definition: StatechartEditorController.h:171
armarx::StatechartEditorController::saveSettings
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition: StatechartEditorController.cpp:192
armarx::StatechartGroupPtr
std::shared_ptr< StatechartGroup > StatechartGroupPtr
Definition: StatechartGroupDefs.h:34
StatechartEditorConfigDialog.h
armarx::StatechartEditorController::config
struct armarx::StatechartEditorController::Config config
armarx::StatechartEditorController::showOnBreakFunction
void showOnBreakFunction()
Definition: StatechartEditorController.cpp:404
armarx::StatechartEditorController::showRunFunction
void showRunFunction()
Definition: StatechartEditorController.cpp:397
armarx::StatechartEditorController::executeOpenedState
void executeOpenedState(bool)
Definition: StatechartEditorController.cpp:469
armarx::StatechartEditorController::GetWidgetIcon
static QIcon GetWidgetIcon()
Definition: StatechartEditorController.h:175
IceUtil::Handle
Definition: forward_declarations.h:29
StateWatcher.h
armarx::VariantInfoPtr
std::shared_ptr< VariantInfo > VariantInfoPtr
Definition: VariantInfo.h:39
armarx::StatechartEditorController::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: StatechartEditorController.cpp:144
armarx::StatechartEditorController::loadSettings
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition: StatechartEditorController.cpp:158
armarx::StatechartEditorController::showOnEnterFunction
void showOnEnterFunction()
Definition: StatechartEditorController.cpp:390
armarx::StatechartEditorController::openSelectedState
void openSelectedState()
Definition: StatechartEditorController.cpp:418
armarx::StatechartEditorController::storeAutoSaveSettings
void storeAutoSaveSettings()
Definition: StatechartEditorController.cpp:75
armarx::StatechartEditorController::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: StatechartEditorController.cpp:135
armarx::StatechartEditorController::findAllStatechartGroupDefinitions
QStringList findAllStatechartGroupDefinitions(const QString &basePath)
Definition: StatechartEditorController.cpp:84
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::StatechartEditorController::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: StatechartEditorController.cpp:129
armarx::StateTreeControllerPtr
std::shared_ptr< StateTreeController > StateTreeControllerPtr
Definition: StateEditorController.h:46
armarx::StatechartEditorController::showStateCode
void showStateCode(statechartmodel::StateInstancePtr stateInstance)
Definition: StatechartEditorController.cpp:352
armarx::StatechartEditorController::onStateTabChanged
void onStateTabChanged(int index)
Definition: StatechartEditorController.cpp:249