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