StatechartEditorMainWindow.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 
24 
25 #include <QFileDialog>
26 #include <QLabel>
27 #include <QMessageBox>
28 #include <QToolBar>
29 
34 
35 #include "../../StatechartViewerPlugin/view/StateItem.h"
36 #include "../../StatechartViewerPlugin/view/StatechartView.h"
37 #include "CppHighlighter.h"
38 #include "dialogs/StateDialog.h"
39 
40 namespace armarx
41 {
42 
44  QMainWindow(parent), ui(new Ui::StatechartEditorMainWindow)
45  {
46  ui->setupUi(this);
47  setupStatechartGroupsToolbar();
48  addAction(ui->actionSave_State);
49  addAction(ui->actionDelete_State);
50  }
51 
53  {
54  delete ui;
55  }
56 
59  {
60  return ui->stateTabWidget;
61  }
62 
63  void
64  StatechartEditorMainWindow::setTipDialog(QPointer<TipDialog> tipDialog)
65  {
66  this->tipDialog = tipDialog;
67  }
68 
69  void
71  {
72  if (ui->stateTabWidget->currentStateview())
73  {
74  ui->stateTabWidget->currentStateview()->setOriginalZoom();
75  }
76  }
77 
78  void
80  {
81  if (QMessageBox::question(this,
82  "Delete state?",
83  "Do you really want to delete the selected states?",
86  {
87  if (ui->stateTabWidget->currentStateview())
88  {
89  ui->stateTabWidget->currentStateview()->deleteSelectedStates();
90  }
91  }
92  }
93 
94  void
96  {
97  StatechartView* view = ui->stateTabWidget->currentStateview();
98 
99  if (view && view->getScene())
100  {
101  ui->graphicsOverview->setScene(view->getScene());
102  ui->graphicsOverview->fitInView(view->getScene()->itemsBoundingRect(),
103  Qt::KeepAspectRatio);
104  ui->graphicsOverview->setZoomer(view->getGraphicsViewZoomer());
105  }
106  else
107  {
108  ui->graphicsOverview->setZoomer(NULL);
109  }
110  }
111 
112  void
114  {
115  if (!instance)
116  {
117  if (ui->stateTabWidget->currentStateview() &&
118  ui->stateTabWidget->currentStateview()->getScene() &&
119  ui->stateTabWidget->currentStateview()->getScene()->selectedItems().size() > 0)
120  {
121  StateItem* item = dynamic_cast<StateItem*>(
122  *ui->stateTabWidget->currentStateview()->getScene()->selectedItems().begin());
123  if (item)
124  {
125  instance = item->getStateInstance();
126  }
127  }
128  }
129 
130  StatechartView* view = ui->stateTabWidget->currentStateview();
131  if (instance && view)
132  {
134  view->getLayoutController().getStateId(instance->getStateClass()), true);
135  }
136  }
137 
138  /*void StatechartEditorMainWindow::setStatechartGroupModel(StatechartGroupTreeModel* model)
139  {
140  ui->treeViewGroups->setModel(model);
141  }*/
142 
143  void
145  {
146  if (ui->stateTabWidget->currentStateview() &&
147  ui->stateTabWidget->currentStateview()->getScene() &&
148  ui->stateTabWidget->currentStateview()->getScene()->selectedItems().size() > 0)
149  {
150  StateItem* item = dynamic_cast<StateItem*>(
151  *ui->stateTabWidget->currentStateview()->getScene()->selectedItems().begin());
152 
153  if (item && item->getStateInstance() && item->getStateInstance()->getStateClass())
154  {
155  ARMARX_INFO_S << "Adding new endstate";
156  statechartmodel::StatePtr state = item->getStateInstance()->getStateClass();
157  int i = 2;
158  const QString newStateNameBase = "MyEndState";
159  QString newStateName = newStateNameBase;
160 
161  while (!state->addEndSubstate(newStateName, newStateName))
162  {
163  newStateName = newStateNameBase + "_" + QString::number(i);
164  i++;
165  }
166  }
167  else
168  {
169  ARMARX_INFO_S << "Cannot add endstate";
170  }
171  }
172  }
173 
174  void
176  {
177  if (ui->stateTabWidget->currentStateview())
178  {
179  ui->stateTabWidget->currentStateview()->viewAll();
180  }
181  }
182 
183  void
184  StatechartEditorMainWindow::setupStatechartGroupsToolbar()
185  {
186  stGroupToolBar = new QToolBar(this);
187  stGroupToolBar->setIconSize(QSize(16, 16));
188  ui->gridLayout_3->addWidget(stGroupToolBar, 0, 0);
189  stGroupToolBar->addAction(ui->actionNew_Statechart_Group);
190  stGroupToolBar->addAction(ui->actionOpenStatechartGroup);
191  stGroupToolBar->addSeparator();
192  stGroupToolBar->addAction(ui->actionNew_State_Definition);
193  stGroupToolBar->addAction(ui->actionDelete_State_Definition);
194  // stGroupToolBar->addAction(ui->actionRefresh_Statechart_Groups);
195 
196  connect(
197  ui->actionZoom_Original, SIGNAL(triggered()), this, SLOT(originalZoomCurrentState()));
198  connect(ui->actionDelete_State, SIGNAL(triggered()), this, SLOT(deleteSelectedStates()));
199  connect(ui->actionView_All, SIGNAL(triggered()), this, SLOT(zoomToViewAll()));
200  connect(ui->actionInsert_Endstate, SIGNAL(triggered()), this, SLOT(addEndState()));
201  connect(ui->actionLayout_state, SIGNAL(triggered()), this, SLOT(layoutState()));
202 
203  connect(ui->stateTabWidget,
204  SIGNAL(currentChanged(int)),
205  this,
206  SLOT(connectOverviewToTab(int)),
207  Qt::UniqueConnection);
208  highlighter = new CppHighlighter(ui->textEditCppCode->document());
209  }
210 
211 
212 } // namespace armarx
213 
214 void
215 armarx::StatechartEditorMainWindow::on_actionSave_as_Image_file_triggered()
216 {
217  if (ui->stateTabWidget->currentStateview())
218  {
219  QFileDialog d(0, "Save statechart to file", "", "Images (*.png *.jpg *.jpeg)");
220  d.setDefaultSuffix("png");
221  d.setFileMode(QFileDialog::QFileDialog::AnyFile);
222  d.setAcceptMode(QFileDialog::AcceptSave);
223  d.layout()->addWidget(new QLabel("Image width in pixel"));
224  QLineEdit* localQLineEdit = new QLineEdit("4000");
225  localQLineEdit->setValidator(new QIntValidator(1, 20000));
226  d.layout()->addWidget(localQLineEdit);
227  if (d.exec() == QDialog::Accepted)
228  {
229  ui->stateTabWidget->currentStateview()->getScene()->saveSceneToSVG(
230  d.selectedFiles().first(), localQLineEdit->text().toInt());
231  }
232  }
233 }
armarx::StatechartView::getScene
StateScene * getScene() const
Definition: StatechartView.h:60
armarx::StatechartEditorMainWindow::originalZoomCurrentState
void originalZoomCurrentState()
Definition: StatechartEditorMainWindow.cpp:70
CppHighlighter.h
armarx::StatechartEditorMainWindow::connectOverviewToTab
void connectOverviewToTab(int tabIndex)
Definition: StatechartEditorMainWindow.cpp:95
armarx::StateItem::getStateInstance
statechartmodel::StateInstancePtr getStateInstance() const
Definition: StateItem.h:66
StateDialog.h
StatechartEditorMainWindow.h
armarx::statechartmodel::StateInstancePtr
std::shared_ptr< StateInstance > StateInstancePtr
Definition: StateInstance.h:146
armarx::StatechartView
Definition: StatechartView.h:45
armarx::StatechartEditorMainWindow::~StatechartEditorMainWindow
~StatechartEditorMainWindow() override
Definition: StatechartEditorMainWindow.cpp:52
LayoutController.h
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
armarx::StatechartView::getLayoutController
LayoutController & getLayoutController()
Definition: StatechartView.cpp:105
armarx::StatechartView::getGraphicsViewZoomer
Graphics_view_zoom * getGraphicsViewZoomer() const
Definition: StatechartView.cpp:99
armarx::StatechartEditorMainWindow::getStateTabWidget
StateTabWidget * getStateTabWidget() const
Definition: StatechartEditorMainWindow.cpp:58
armarx::LayoutController::getStateId
size_t getStateId(armarx::statechartmodel::StatePtr state) const
Definition: LayoutController.cpp:79
TransitionItem.h
armarx::StateTabWidget
Definition: StateTabWidget.h:35
armarx::StatechartEditorMainWindow
Definition: StatechartEditorMainWindow.h:48
No
Introduction Thank you for taking interest in our work and downloading this software This library implements the algorithm described in the paper R R R Klein Efficient RANSAC for Point Cloud Shape in Computer Graphics No
Definition: ReadMe.txt:21
armarx::LayoutController::layoutNow
bool layoutNow(size_t mediatorId, bool layoutAll)
Definition: LayoutController.cpp:122
armarx::StatechartEditorMainWindow::deleteSelectedStates
void deleteSelectedStates()
Definition: StatechartEditorMainWindow.cpp:79
armarx::CppHighlighter
Definition: CppHighlighter.h:30
StateTabWidget.h
armarx::StatechartEditorMainWindow::zoomToViewAll
void zoomToViewAll()
Definition: StatechartEditorMainWindow.cpp:175
GfxTL::Yes
OnOff< true > Yes
Definition: OnOff.h:14
armarx::statechartmodel::StatePtr
std::shared_ptr< State > StatePtr
Definition: State.h:48
armarx::StateItem
Definition: StateItem.h:58
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:202
TransitionDialog.h
armarx::StatechartEditorMainWindow::StatechartEditorMainWindow
StatechartEditorMainWindow(QWidget *parent=0)
Definition: StatechartEditorMainWindow.cpp:43
armarx::StatechartEditorMainWindow::layoutState
void layoutState(statechartmodel::StateInstancePtr instance=statechartmodel::StateInstancePtr())
Definition: StatechartEditorMainWindow.cpp:113
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::StatechartEditorMainWindow::setTipDialog
void setTipDialog(QPointer< TipDialog > tipDialog)
Definition: StatechartEditorMainWindow.cpp:64
armarx::StatechartEditorMainWindow::addEndState
void addEndState()
Definition: StatechartEditorMainWindow.cpp:144