StateTreeController.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 "model/StateTreeNode.h"
27 #include "model/StateTreeModel.h"
28 
30 #include "../StatechartViewerPlugin/model/StateMimeData.h"
31 #include "../StatechartViewerPlugin/model/stateinstance/StateInstance.h"
32 
35 
36 #include <QAbstractItemModel>
37 #include <QSortFilterProxyModel>
38 #include <QTreeView>
39 
44 
45 
46 class QProcess;
47 
48 namespace armarx
49 {
50 
51  class StatechartProfiles;
52  using StatechartProfilesPtr = std::shared_ptr<StatechartProfiles>;
53 
54 
55 
56 
57 
58  class StateTreeController;
59  using StateTreeControllerPtr = std::shared_ptr<StateTreeController>;
60 
61  class StateTreeController : public QAbstractItemModel
62  {
63  Q_OBJECT
64 
65  public:
66  StateTreeController(Ice::CommunicatorPtr ic, VariantInfoPtr variantInfo, QList<QVariant> headerInfo, QTreeView* treeView, QLineEdit* filterLineEdit, const ArmarXPackageToolInterfacePtr& packageTool, const StatechartProfilesPtr& statechartProfiles, StatechartProfilePtr currentProfile, QObject* parent = 0);
67  ~StateTreeController() override;
68 
69  QVariant data(const QModelIndex& index, int role) const override;
70  Qt::ItemFlags flags(const QModelIndex& index) const override;
71  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
72  QModelIndex index(int row, int column, const QModelIndex& parentIndex = QModelIndex()) const override;
73  QModelIndex parent(const QModelIndex& index) const override;
74  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
75  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
76  StatechartGroupPtr loadAndAddGroup(QString groupDefinitionFile);
77  StatechartGroupPtr loadGroup(QString groupDefinitionFile);
78  StatechartGroupPtr addNewGroup(const QString& groupName, const QString& groupPath, const QString& description, const QString& packageName, const QList<QString> proxies, bool generateContext, const QMap<QString, QString>& statechartGroupConfigurations);
79 
80  void loadAllStates();
81 
85  bool nodeIsState(StateTreeNodePtr node);
86  bool nodeIsFolder(StateTreeNodePtr node);
87  bool nodeIsGroup(StateTreeNodePtr node);
89  bool selectedNodeIsState();
90  bool selectedNodeIsFolder();
91  bool selectedNodeIsGroup();
93  StateTreeNodePtr tryCreateNewState(QString name);
94  StateTreeNodePtr createNewState(QString name, StateTreeNodePtr parent, bool createDynamicRemoteState = false);
96  //StateTreeNodePtr get
97  void tryDeleteState();
98  void removeState(StateTreeNodePtr stateNode);
99  void tryDeleteFolder();
100  void removeFolder(StateTreeNodePtr folderNode);
101  void tryDeleteGroup();
102 
104 
105  void saveAll();
106 
107  StateTreeNodePtr getNode(QModelIndex index) const;
108 
110 
111  signals:
112  void closeAllTabsRequested();
113 
114  public slots:
115  void onContextMenu(const QPoint& point);
116  void onNewStateDefinition();
118  void onNewFolder();
119  void onDeleteNode();
120  void onMakeStatePublic(bool enable);
121  void onFindStateUsages();
122  void onRenameState();
123  void onOpenCMakeProject();
124  void onShowFullPath();
125  void onOpenStateCPP();
126  void onOpenGroup(QString groupFile = "");
127  void onExecuteGroup();
128  void onStatechartFinished(int exitCode);
129  //void onGenerateStateBaseClass();
130  //void onGenerateRsoBaseClass();
132  void onRenameGroup();
133  void onCloneGroup();
134  void onGroupProperties();
135  void collapseAll();
136  void selectNode(StateTreeNodePtr node);
137 
138  void executeGroup(StatechartGroupPtr group, QString startState = "");
139 
141 
142  void executeGroupWithDependencies(StatechartGroupPtr group, QString startState);
143 
145  public:
146  void openStateCPP(StateTreeNodePtr node);
147 
148  private slots:
149  void processOutputReady();
150  void processErrorsReady();
151  void stateAddedOrRemoved();
152  void expandFilterResults(const QString& filterString);
153  private:
154 
155  QModelIndex getIndex(StateTreeNodePtr node);
156  QString buildStateUsageString(QList<statechartmodel::StateInstancePtr> instances);
157 
158  StateTreeNodePtr rootNode;
159  QList<QVariant> headerInfo;
160  QTreeView* treeView;
161  StateTreeModelPtr stateTreeModel;
162  InfixFilterModel* proxyModel;
163  GroupClonerPtr groupCloner;
164  GroupRenamerPtr groupRenamer;
165  StatechartGroupPtr activeGroup;
166  QMenu* contextMenuGroup;
167  QMenu* contextMenuFolder;
168  QMenu* contextMenuState;
169  QAction* actionNewStateDefinition;
170  QAction* actionNewDynamicRemoteStateDefinition;
171  QAction* actionNewFolder;
172  QAction* actionDeleteNode;
173  QAction* actionMakeStatePublic;
174  QAction* actionFindStateUsages;
175  QAction* actionRenameState;
176  QAction* actionOpenCMakeProject;
177  QAction* actionShowFullPath;
178  QAction* actionOpenStateCPP;
179  QAction* actionExecuteGroup;
180  //QAction *actionGenerateStateBaseClass;
181  //QAction *actionGenerateRsoBaseClass;
182  QAction* actionGenerateStateCPP;
183  QAction* actionCloneGroup;
184  QAction* actionRenameGroup;
185  QAction* actionGroupProperties;
187 
188  ArmarXPackageToolInterfacePtr packageTool;
189  EditorFileOpener opener;
190  QMap<QString, QProcess*> processes;
191  VariantInfoPtr variantInfo;
192  StatechartProfilesPtr profiles;
193  StatechartProfilePtr currentProfile;
194  Ice::CommunicatorPtr communicator;
195 
196  struct StateMimeData : AbstractStateMimeData
197  {
198  StateMimeData(statechartmodel::StatePtr state, StateTreeModelPtr stateTreeModel);
199  bool isInSameGroup(statechartmodel::StatePtr state) const override;
200  bool isPublic() const override;
201  private:
202  StateTreeModelPtr stateTreeModel;
203  };
204 
205  // QAbstractItemModel interface
206  bool retrieveNewStateName(QString& newStateName, StateTreeNodePtr& node, bool& createCPPFiles, bool askForCPPFiles);
207  /*!
208  * \brief Buffers the icons so that they are not loaded each time again
209  * \param path Path to icon, can be resource.
210  * \return Freshly loaded or buffered icon.
211  */
212  QIcon getIcon(const QString& path) const;
213  mutable QMap<QString, QIcon> icons;
214  public:
215  QStringList mimeTypes() const override;
216  QMimeData* mimeData(const QModelIndexList& indexes) const override;
217  };
218 }
219 
armarx::StateTreeController::getNodeByState
StateTreeNodePtr getNodeByState(statechartmodel::StatePtr state)
Definition: StateTreeController.cpp:516
armarx::AbstractStateMimeData
The AbstractStateMimeData class is used to transport state data from the treeview to the stateview an...
Definition: StateMimeData.h:36
armarx::StateTreeController::getSelectedNode
StateTreeNodePtr getSelectedNode()
Definition: StateTreeController.cpp:521
armarx::StateTreeModelPtr
std::shared_ptr< StateTreeModel > StateTreeModelPtr
Definition: StateTreeModel.h:44
armarx::StateTreeController::createNewState
StateTreeNodePtr createNewState(QString name, StateTreeNodePtr parent, bool createDynamicRemoteState=false)
Definition: StateTreeController.cpp:645
cyberglove_with_calib_22dof.ic
ic
Definition: cyberglove_with_calib_22dof.py:22
armarx::StateTreeController::onRenameState
void onRenameState()
Definition: StateTreeController.cpp:1022
armarx::StateTreeController::saveAll
void saveAll()
Definition: StateTreeController.cpp:1608
armarx::StateTreeController::onCloneGroup
void onCloneGroup()
Definition: StateTreeController.cpp:1327
GfxTL::Orientation
ScalarT Orientation(const VectorXD< 2, ScalarT > &p1, const VectorXD< 2, ScalarT > &p2, const VectorXD< 2, ScalarT > &c)
Definition: Orientation.h:9
armarx::ArmarXPackageToolInterfacePtr
std::shared_ptr< ArmarXPackageToolInterface > ArmarXPackageToolInterfacePtr
Definition: ArmarXPackageToolInterface.h:55
armarx::StateTreeController::onStatechartFinished
void onStatechartFinished(int exitCode)
Definition: StateTreeController.cpp:1247
armarx::StateTreeNodePtr
std::shared_ptr< StateTreeNode > StateTreeNodePtr
Definition: StatechartGroupDefs.h:31
armarx::StateTreeController::tryDeleteState
void tryDeleteState()
Definition: StateTreeController.cpp:590
ScenarioManager::Data_Structure::ApplicationPtr
std::shared_ptr< Application > ApplicationPtr
Definition: Application.h:119
armarx::StateTreeController::selectNodeByState
void selectNodeByState(statechartmodel::StatePtr state)
Definition: StateTreeController.cpp:713
armarx::StateTreeController::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: StateTreeController.cpp:286
armarx::StateTreeController::selectedNodeIsFolder
bool selectedNodeIsFolder()
Definition: StateTreeController.cpp:563
armarx::StateTreeController::selectedNodeIsFolderOrGroup
bool selectedNodeIsFolderOrGroup()
Definition: StateTreeController.cpp:573
armarx::StateTreeController::removeFolder
void removeFolder(StateTreeNodePtr folderNode)
Definition: StateTreeController.cpp:1571
armarx::StateTreeController::stopGroupExecutionWithDependencies
void stopGroupExecutionWithDependencies(StatechartGroupPtr group)
Definition: StateTreeController.cpp:1180
armarx::StatechartProfilePtr
std::shared_ptr< class StatechartProfile > StatechartProfilePtr
Definition: StatechartContext.h:52
armarx::StateTreeController::onRenameGroup
void onRenameGroup()
Definition: StateTreeController.cpp:1371
InfixFilterModel.h
armarx::EditorFileOpener
The EditorFileOpener class.
Definition: editorfileopener.h:40
armarx::StateTreeController::selectedNodeIsState
bool selectedNodeIsState()
Definition: StateTreeController.cpp:558
armarx::StateTreeController::removeNodeFromTree
void removeNodeFromTree(StateTreeNodePtr node)
Definition: StateTreeController.cpp:1596
armarx::StateTreeController::index
QModelIndex index(int row, int column, const QModelIndex &parentIndex=QModelIndex()) const override
Definition: StateTreeController.cpp:318
armarx::StateTreeController::collapseAll
void collapseAll()
Definition: StateTreeController.cpp:1443
armarx::StateTreeController::onMakeStatePublic
void onMakeStatePublic(bool enable)
Definition: StateTreeController.cpp:1002
armarx::StateTreeController::~StateTreeController
~StateTreeController() override
Definition: StateTreeController.cpp:189
armarx::StateTreeController::onDeleteNode
void onDeleteNode()
Definition: StateTreeController.cpp:976
armarx::StateTreeController::loadAllStates
void loadAllStates()
Definition: StateTreeController.cpp:511
armarx::StateTreeController::addNewGroup
StatechartGroupPtr addNewGroup(const QString &groupName, const QString &groupPath, const QString &description, const QString &packageName, const QList< QString > proxies, bool generateContext, const QMap< QString, QString > &statechartGroupConfigurations)
Definition: StateTreeController.cpp:490
armarx::StateTreeController
Definition: StateTreeController.h:61
armarx::GroupClonerPtr
std::shared_ptr< GroupCloner > GroupClonerPtr
Definition: GroupCloner.h:46
armarx::StateTreeController::openStateCPP
void openStateCPP(StateTreeNodePtr node)
Definition: StateTreeController.cpp:1455
IceInternal::Handle< ::Ice::Communicator >
armarx::StateTreeController::onOpenStateCPP
void onOpenStateCPP()
Definition: StateTreeController.cpp:1103
armarx::StateTreeController::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: StateTreeController.cpp:387
armarx::StatechartProfilesPtr
std::shared_ptr< StatechartProfiles > StatechartProfilesPtr
Definition: StatechartProfiles.h:35
ArmarXPackageToolInterface.h
armarx::StateTreeController::onNewStateDefinition
void onNewStateDefinition()
Definition: StateTreeController.cpp:891
armarx::StateTreeController::closeAllTabsRequested
void closeAllTabsRequested()
armarx::StateTreeController::nodeIsState
bool nodeIsState(StateTreeNodePtr node)
Definition: StateTreeController.cpp:538
armarx::StateTreeController::onNewFolder
void onNewFolder()
Definition: StateTreeController.cpp:947
armarx::StateTreeController::loadGroup
StatechartGroupPtr loadGroup(QString groupDefinitionFile)
Definition: StateTreeController.cpp:465
StatechartProfiles.h
armarx::StateTreeController::stopGroupExecution
void stopGroupExecution(StatechartGroupPtr group)
Definition: StateTreeController.cpp:1115
armarx::StateTreeController::selectedNodeIsGroup
bool selectedNodeIsGroup()
Definition: StateTreeController.cpp:568
StateTreeModel.h
editorfileopener.h
armarx::StateTreeController::tryCreateNewState
StateTreeNodePtr tryCreateNewState(QString name)
Definition: StateTreeController.cpp:578
armarx::StateTreeController::onNewDynamicRemoteStateDefinition
void onNewDynamicRemoteStateDefinition()
Definition: StateTreeController.cpp:931
armarx::StateTreeController::loadAndAddGroup
StatechartGroupPtr loadAndAddGroup(QString groupDefinitionFile)
Definition: StateTreeController.cpp:399
armarx::StateTreeController::tryDeleteGroup
void tryDeleteGroup()
Definition: StateTreeController.cpp:1577
armarx::StateTreeController::onShowFullPath
void onShowFullPath()
Definition: StateTreeController.cpp:1091
armarx::StateTreeController::removeState
void removeState(StateTreeNodePtr stateNode)
Definition: StateTreeController.cpp:1537
armarx::StateTreeController::executeGroup
void executeGroup(StatechartGroupPtr group, QString startState="")
Definition: StateTreeController.cpp:1126
armarx::StatechartGroupPtr
std::shared_ptr< StatechartGroup > StatechartGroupPtr
Definition: StatechartGroupDefs.h:34
armarx::StateTreeController::onExecuteGroup
void onExecuteGroup()
Definition: StateTreeController.cpp:1205
armarx::StateTreeController::onContextMenu
void onContextMenu(const QPoint &point)
Definition: StateTreeController.cpp:723
armarx::StateTreeController::mimeData
QMimeData * mimeData(const QModelIndexList &indexes) const override
Definition: StateTreeController.cpp:1637
armarx::StateTreeController::onGroupProperties
void onGroupProperties()
Definition: StateTreeController.cpp:1423
armarx::StateTreeController::getNode
StateTreeNodePtr getNode(QModelIndex index) const
Definition: StateTreeController.cpp:697
armarx::StateTreeController::createNewFolder
StateTreeNodePtr createNewFolder(QString name, StateTreeNodePtr parent)
Definition: StateTreeController.cpp:682
armarx::StateTreeController::onOpenCMakeProject
void onOpenCMakeProject()
Definition: StateTreeController.cpp:1077
armarx::StateTreeController::tryDeleteFolder
void tryDeleteFolder()
Definition: StateTreeController.cpp:1543
GroupRenamer.h
armarx::StateTreeController::nodeIsGroup
bool nodeIsGroup(StateTreeNodePtr node)
Definition: StateTreeController.cpp:548
GroupCloner.h
armarx::VariantInfoPtr
std::shared_ptr< VariantInfo > VariantInfoPtr
Definition: VariantInfo.h:39
armarx::StateTreeController::onGenerateStateCppFiles
void onGenerateStateCppFiles()
Definition: StateTreeController.cpp:1307
armarx::StateTreeController::parent
QModelIndex parent(const QModelIndex &index) const override
Definition: StateTreeController.cpp:348
armarx::StateTreeController::mimeTypes
QStringList mimeTypes() const override
Definition: StateTreeController.cpp:1629
armarx::StateTreeController::data
QVariant data(const QModelIndex &index, int role) const override
Definition: StateTreeController.cpp:214
armarx::statechartmodel::StatePtr
std::shared_ptr< State > StatePtr
Definition: State.h:46
armarx::InfixFilterModel
This proxy model reimplements the filterAcceptsRow function with a new behavior: All elements that fi...
Definition: InfixFilterModel.h:41
armarx::GroupRenamerPtr
std::shared_ptr< GroupRenamer > GroupRenamerPtr
Definition: GroupRenamer.h:33
armarx::StateTreeController::onFindStateUsages
void onFindStateUsages()
Definition: StateTreeController.cpp:1010
Application.h
armarx::StateTreeController::selectNode
void selectNode(StateTreeNodePtr node)
Definition: StateTreeController.cpp:1448
armarx::StateTreeController::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: StateTreeController.cpp:308
armarx::StateTreeController::onOpenGroup
void onOpenGroup(QString groupFile="")
Definition: StateTreeController.cpp:1108
StateTreeNode.h
armarx::StateTreeController::executeGroupWithDependencies
void executeGroupWithDependencies(StatechartGroupPtr group, QString startState)
Definition: StateTreeController.cpp:1170
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::StateTreeController::getClosestParentFolderOrGroupNode
StateTreeNodePtr getClosestParentFolderOrGroupNode(StateTreeNodePtr node)
Definition: StateTreeController.cpp:533
armarx::StateTreeController::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: StateTreeController.cpp:366
armarx::StateTreeControllerPtr
std::shared_ptr< StateTreeController > StateTreeControllerPtr
Definition: StateEditorController.h:46
armarx::StateTreeController::nodeIsFolderOrGroup
bool nodeIsFolderOrGroup(StateTreeNodePtr node)
Definition: StateTreeController.cpp:553
armarx::StateTreeController::nodeIsFolder
bool nodeIsFolder(StateTreeNodePtr node)
Definition: StateTreeController.cpp:543
armarx::StateTreeController::StateTreeController
StateTreeController(Ice::CommunicatorPtr ic, VariantInfoPtr variantInfo, QList< QVariant > headerInfo, QTreeView *treeView, QLineEdit *filterLineEdit, const ArmarXPackageToolInterfacePtr &packageTool, const StatechartProfilesPtr &statechartProfiles, StatechartProfilePtr currentProfile, QObject *parent=0)
Definition: StateTreeController.cpp:63