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 <QFileSystemWatcher>
27 
31 
35 
36 #include "StateEditorController.h"
37 #include "StateTreeController.h"
38 
39 namespace armarx
40 {
41  class StatechartEditorMainWindow;
42 
43  /**
44  \page ArmarXGui-GuiPlugins-StatechartEditorController StatechartEditor
45  \tableofcontents
46 
47  The Statechart Editor is a powerful and convenient tool to design complex behavior.
48  It is deeply integrated into ArmarX and tailored onto it.
49  It allows the user to design hierarchical, distributed statecharts inspired by Harel, 84 [1] in
50  a graphical way and generate and connect it directly with C++ code.
51  For a step-by-step tutorial refer to: \ref ArmarXCore-Tutorials-sce
52 
53  A detailed explanation of ArmarX Statecharts can be found in the publication:<br/>
54  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.
55  <a href="http://journal.frontiersin.org/article/10.3389/frobt.2016.00033/full">[DOI]</a>
56 
57  [1]: David Harel: *Statecharts: A Visual Approach to Complex Systems*, CS84-05, Department of Applied Mathematics, The Weizmann Institute of Science, 1984
58 
59  \image html StatechartEditor.png
60 
61  \see \ref Statechart
62  \see \ref ArmarXGui-GuiPlugins-StatechartViewer
63  \see \ref RobotSkillTemplates
64  \see \ref StatechartEditorController
65  \see \ref ArmarXGui-GuiPlugins-EventSender
66  \see \ref ArmarXCore-Tutorials-sce
67 
68  \section SCE-Group-Execution Statechart Execution from the Statechart Editor
69  Statecharts are always executed as part of their statechart group.
70  There are two different ways to execute a statechart group:
71  \li <b>From the Statechart Editor directly:</b> In the context menu of the statechart group it is possible
72  to execute a statechart group directly. This option is meant for quick testing of statecharts. All statechart group dependencies
73  are automatically also executed (they need to be loaded in the current session of the Statechart Editor for this).
74  Before execution a public state that should immediately be entered can be selected. Note
75  that this state must not need any input paramters.
76  \li <b>Starting a statechart group with a scenario:</b> The usual way to start a statechart group is as part of
77  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".
78  The statechart group needs to be dropped on an open scenario. It is then fully parameterized and ready to be started.
79  Note that for this option all statechart group dependencies need to be added to the scenario manually as well.
80  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.
81 
82  \section SCE-Intro Statechart Editor Intro: Making Armar wave in 4 minutes
83  In this video, the Statechart Editor used to program a simple
84  statechart that makes Armar3 wave. This demonstrates the basic features of the Statechart Editor.
85  There was nothing prepared except starting the simulation and getting the needed joint values for the arm joints.
86  \htmlonly
87  <video width="700" controls>
88  <source src="images/SCE-intro-2016-03-25_17.38.00.mp4" type="video/mp4">
89  Your browser does not support HTML5 video.
90  </video>
91  \endhtmlonly
92 
93  \section SCE-Configurations Editing the runtime configuration of a statechart group
94  Statecharts groups need like component often parameters to work with one specific robot.
95  For statechart groups this can be done with the Statechart Editor. In this video, it is shown
96  how to setup the configuration for one group. This configuration is then always applied when starting
97  the statechart group.
98  \htmlonly
99  <video width="700" controls>
100  <source src="images/SCE-configurations-2016-03-24_03.13.42.mp4" type="video/mp4">
101  Your browser does not support HTML5 video.
102  </video>
103  \endhtmlonly
104 
105  \section SCE-GroupCloning Cloning a statechart group to another package
106  \htmlonly
107  <video width="700" controls>
108  <source src="images/SCE-cloning-2016-03-24_03.50.53.mp4" type="video/mp4">
109  Your browser does not support HTML5 video.
110  </video>
111  \endhtmlonly
112 
113 
114  \section SCE-DirectMapping Direct mapping of parameters during transitions
115  \htmlonly
116  <video width="700" controls>
117  <source src="images/SCE-directvaluemapping-2016-03-30_23.44.26.mp4" type="video/mp4">
118  Your browser does not support HTML5 video.
119  </video>
120  \endhtmlonly
121 
122 
123  */
124 
125 
126  /**
127  \class StatechartEditorController
128  \brief The StatechartEditorController class is the controller of the main widget of the Statechart Editor.
129  */
131  public ArmarXComponentWidgetControllerTemplate<StatechartEditorController>
132  {
133  Q_OBJECT
134 
135  public:
137  ~StatechartEditorController() override;
138 
139  QStringList findAllStatechartGroupDefinitions(const QString& basePath);
140 
141  public slots:
142  void treeviewGroupsDoubleClicked(QModelIndex index);
143  void requestSave();
144  void onStateTabChanged(int index);
147  void searchAndOpenPaths(QStringList paths);
148 
149  void connectToView(int tabIndex);
151  void showCodeFileContent(const QString& path);
152  void showOnEnterFunction();
153  void showRunFunction();
154  void showOnBreakFunction();
155  void showOnExitFunction();
156  void openSelectedState();
157  void closeAllTabs();
158  void executeOpenedState(bool);
159 
160  public:
161  // inherited from Component
162  void onInitComponent() override;
163  void onConnectComponent() override;
164  void onDisconnectComponent() override;
165  void onExitComponent() override;
166 
167  // inherited of ArmarXWidget
168  static QString
170  {
171  return "Statecharts.StatechartEditor";
172  }
173 
174  static QIcon
176  {
177  return QIcon(":/statechart-editor/states.svg");
178  }
179 
180  static QIcon
182  {
183  return QIcon(":/statechart-editor/states.svg");
184  }
185 
186  void loadSettings(QSettings* settings) override;
187  void saveSettings(QSettings* settings) override;
188 
189  // ArmarXWidgetController interface
190  QPointer<QWidget> getWidget() override;
191  void openStatechartGroups(QStringList groups);
192  private slots:
193  void initWidget();
194 
195  private:
196  void updateExecutionButtonStatus();
197  void watchState(const std::string& objName);
198  QPointer<StatechartEditorMainWindow> editor;
199  StateEditorControllerPtr stateEditorController;
200  StateTreeControllerPtr treeController;
201  ArmarXPackageToolInterfacePtr packageTool;
202  QFileSystemWatcher* watcher;
203  StateWatcherPtr stateWatcher;
204  bool alreadyWatchingState = false;
205  VariantInfoPtr variantInfo;
206  StatechartProfilesPtr profiles;
207  QPointer<StatechartEditorConfigDialog> dialog;
208  StatechartGroupPtr executedOpenedGroup;
210  // ArmarXWidgetController interface
211  public:
212  QPointer<QDialog> getConfigDialog(QWidget* parent) override;
213 
214  struct Config
215  {
216  QStringList searchPaths;
217  QStringList groupsToLoad;
221  } config;
222 
223  // ArmarXWidgetController interface
224  bool onClose() override;
225  void configured() override;
226  void storeAutoSaveSettings();
227  };
228 
229 } // namespace armarx
armarx::StatechartEditorController::Config
Definition: StatechartEditorController.h:214
armarx::StatechartEditorController::Config::lockRemoteStates
bool lockRemoteStates
Definition: StatechartEditorController.h:218
armarx::StatechartEditorController::treeviewGroupsDoubleClicked
void treeviewGroupsDoubleClicked(QModelIndex index)
Definition: StatechartEditorController.cpp:221
armarx::StatechartEditorController::Config::groupsToLoad
QStringList groupsToLoad
Definition: StatechartEditorController.h:217
armarx::StateEditorControllerPtr
std::shared_ptr< StateEditorController > StateEditorControllerPtr
Definition: StateEditorController.h:105
armarx::StatechartEditorController::GetWidgetCategoryIcon
static QIcon GetWidgetCategoryIcon()
Definition: StatechartEditorController.h:181
armarx::ArmarXPackageToolInterfacePtr
std::shared_ptr< ArmarXPackageToolInterface > ArmarXPackageToolInterfacePtr
Definition: ArmarXPackageToolInterface.h:71
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::StatechartEditorController::showCodeFileContent
void showCodeFileContent(const QString &path)
Definition: StatechartEditorController.cpp:369
armarx::StatechartEditorController::getConfigDialog
QPointer< QDialog > getConfigDialog(QWidget *parent) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
Definition: StatechartEditorController.cpp:909
PeriodicTask.h
StateEditorController.h
armarx::StatechartProfilePtr
std::shared_ptr< class StatechartProfile > StatechartProfilePtr
Definition: StatechartContext.h:51
armarx::StatechartEditorController::showStatechartEditorSettingsDialog
void showStatechartEditorSettingsDialog()
Definition: StatechartEditorController.cpp:289
armarx::StatechartEditorController::~StatechartEditorController
~StatechartEditorController() override
Definition: StatechartEditorController.cpp:71
armarx::StatechartEditorController::openStatechartGroups
void openStatechartGroups(QStringList groups)
Definition: StatechartEditorController.cpp:312
armarx::StatechartEditorController::searchAndOpenPaths
void searchAndOpenPaths(QStringList paths)
Definition: StatechartEditorController.cpp:328
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
armarx::StatechartEditorController::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: StatechartEditorController.cpp:151
armarx::StatechartEditorController::Config::selectedProfile
StatechartProfilePtr selectedProfile
Definition: StatechartEditorController.h:220
armarx::StatechartEditorController::onClose
bool onClose() override
onClose is called before the DockWidget is closed.
Definition: StatechartEditorController.cpp:890
armarx::StatechartEditorController::Config::openAllStatesWasSelected
bool openAllStatesWasSelected
Definition: StatechartEditorController.h:219
armarx::statechartmodel::StateInstancePtr
std::shared_ptr< StateInstance > StateInstancePtr
Definition: StateInstance.h:146
armarx::StatechartEditorController::Config::searchPaths
QStringList searchPaths
Definition: StatechartEditorController.h:216
armarx::StatechartEditorController::StatechartEditorController
StatechartEditorController()
Definition: StatechartEditorController.cpp:59
armarx::StatechartEditorController::configured
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
Definition: StatechartEditorController.cpp:898
IceInternal::Handle< StateWatcher >
armarx::StatechartProfilesPtr
std::shared_ptr< StatechartProfiles > StatechartProfilesPtr
Definition: StatechartProfiles.h:36
armarx::StatechartEditorController::showNewStatechartGroupDialog
void showNewStatechartGroupDialog()
Definition: StatechartEditorController.cpp:264
ArmarXPackageToolInterface.h
ArmarXComponentWidgetController.h
armarx::StatechartEditorController::closeAllTabs
void closeAllTabs()
Definition: StatechartEditorController.cpp:465
StateTreeController.h
armarx::StatechartEditorController::connectToView
void connectToView(int tabIndex)
Definition: StatechartEditorController.cpp:340
StatechartProfiles.h
armarx::StatechartEditorController::requestSave
void requestSave()
Definition: StatechartEditorController.cpp:245
armarx::StatechartEditorController::showOnExitFunction
void showOnExitFunction()
Definition: StatechartEditorController.cpp:413
armarx::StatechartEditorController::getWidget
QPointer< QWidget > getWidget() override
getWidget returns a pointer to the a widget of this controller.
Definition: StatechartEditorController.cpp:690
armarx::StatechartEditorController
The StatechartEditorController class is the controller of the main widget of the Statechart Editor.
Definition: StatechartEditorController.h:130
armarx::StatechartEditorController::GetWidgetName
static QString GetWidgetName()
Definition: StatechartEditorController.h:169
armarx::StatechartEditorController::saveSettings
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition: StatechartEditorController.cpp:194
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:406
armarx::StatechartEditorController::showRunFunction
void showRunFunction()
Definition: StatechartEditorController.cpp:399
armarx::StatechartEditorController::executeOpenedState
void executeOpenedState(bool)
Definition: StatechartEditorController.cpp:471
armarx::StatechartEditorController::GetWidgetIcon
static QIcon GetWidgetIcon()
Definition: StatechartEditorController.h:175
IceUtil::Handle
Definition: forward_declarations.h:30
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:146
armarx::StatechartEditorController::loadSettings
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition: StatechartEditorController.cpp:160
armarx::StatechartEditorController::showOnEnterFunction
void showOnEnterFunction()
Definition: StatechartEditorController.cpp:392
armarx::StatechartEditorController::openSelectedState
void openSelectedState()
Definition: StatechartEditorController.cpp:420
armarx::StatechartEditorController::storeAutoSaveSettings
void storeAutoSaveSettings()
Definition: StatechartEditorController.cpp:77
armarx::StatechartEditorController::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: StatechartEditorController.cpp:137
armarx::StatechartEditorController::findAllStatechartGroupDefinitions
QStringList findAllStatechartGroupDefinitions(const QString &basePath)
Definition: StatechartEditorController.cpp:86
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::StatechartEditorController::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: StatechartEditorController.cpp:131
armarx::StateTreeControllerPtr
std::shared_ptr< StateTreeController > StateTreeControllerPtr
Definition: StateEditorController.h:43
armarx::StatechartEditorController::showStateCode
void showStateCode(statechartmodel::StateInstancePtr stateInstance)
Definition: StatechartEditorController.cpp:354
armarx::StatechartEditorController::onStateTabChanged
void onStateTabChanged(int index)
Definition: StatechartEditorController.cpp:251