VPTissue Reference Manual
EditorActions.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "EditorActions.h"
21 #include "PTreePanels.h"
22 #include "SelectByIDWidget.h"
23 #include "TissueEditor.h"
24 #include "TissueGraphicsView.h"
25 #include "UndoStack.h"
26 
27 #include "../../cpp_simshell/common/InstallDirs.h"
29 #include "gui/EnabledActions.h"
30 #include "gui/PTreeContainer.h"
31 #include "gui/PTreeEditorWindow.h"
32 
33 #include <cassert>
34 #include <QAction>
35 #include <QDockWidget>
36 #include <QIcon>
37 #include <QMenuBar>
38 #include <QToolBar>
39 #include <string>
40 
41 namespace SimPT_Editor {
42 
44  TissueGraphicsView* view, PTreePanels* panels, UndoStack* undoStack)
45  : QMenuBar(parent), m_parent(parent), m_view(view),
46  m_panels(panels), m_undo_stack(undoStack)
47 {
48  assert(parent != nullptr && "The parent isn't initialized.");
49  assert(view != nullptr && "The view isn't initialized.");
50  assert(panels != nullptr && "The panels isn't initialized.");
51  assert(undoStack != nullptr && "The undo stack isn't initialized.");
52 
53  Initialize();
54 }
55 
57 
59 {
60  m_node_mode->setChecked(m_view->GetMode() == Mode::NODE);
61  m_edge_mode->setChecked(m_view->GetMode() == Mode::EDGE);
62  m_cell_mode->setChecked(m_view->GetMode() == Mode::CELL);
63 }
64 
65 void EditorActions::Initialize()
66 {
67  //Creation of menus
68  m_menu_project = new QMenu("&Project", this);
69  m_menu_edit = new QMenu("&Edit", this);
70  m_menu_view = new QMenu("&View", this);
71 
72  //Creation of actions for project menu
73 
74  //Action for creating a new tissue
75  m_new_tissue = new QAction("&New", m_menu_project);
76  m_new_tissue->setShortcut(QKeySequence("Ctrl+N"));
77  m_new_tissue->setStatusTip("Creates a new tissue");
78  connect(m_new_tissue, SIGNAL(triggered()), m_parent, SLOT(NewLeaf()));
79 
80  //Action for opening an existing tissue
81  m_open_tissue = new QAction("&Open", m_menu_project);
82  m_open_tissue->setShortcut(QKeySequence("Ctrl+O"));
83  m_open_tissue->setStatusTip("Opens an existing project");
84  connect(m_open_tissue, SIGNAL(triggered()), m_parent, SLOT(OpenLeaf()));
85 
86  //Action for saving the current tissue
87  m_save_tissue = new QAction("&Save", m_menu_project);
88  m_save_tissue->setShortcut(QKeySequence("Ctrl+S"));
89  m_save_tissue->setStatusTip("Saves the current project");
90  m_save_tissue->setEnabled(false);
91  connect(m_save_tissue, SIGNAL(triggered()), m_parent, SLOT(SaveLeaf()));
92 
93  //Action for closing the current tissue
94  m_close_tissue = new QAction("&Close", m_menu_project);
95  m_close_tissue->setStatusTip("Closes the current project");
96  m_close_tissue->setEnabled(false);
97  connect(m_close_tissue, SIGNAL(triggered()), m_parent, SLOT(CloseLeaf()));
98 
99  //Action for closing the program
100  m_quit = new QAction("&Quit", m_menu_project);
101  m_quit->setShortcut(QKeySequence("Ctrl+Q"));
102  m_quit->setStatusTip("Quits the program");
103  connect(m_quit, SIGNAL(triggered()), m_parent, SLOT(close()));
104 
105  //Creation of actions for the edit menu
106 
107  //Submenu for choosing the editing mode.
108  QMenu* menuMode = new QMenu("&Mode", m_menu_edit);
109 
110  //Action for switching to Node mode
111  m_node_mode = new QAction("&Node", menuMode);
112  m_node_mode->setShortcut(QKeySequence("Ctrl+1"));
113  m_node_mode->setStatusTip("Set editing mode to 'Node'");
114  m_node_mode->setEnabled(false);
115  m_node_mode->setCheckable(true);
116  connect(m_node_mode, SIGNAL(triggered()), m_parent, SLOT(SetNodeMode()));
117  menuMode->addAction(m_node_mode);
118 
119  //Action for switching to Edge mode
120  m_edge_mode = new QAction("&Edge", menuMode);
121  m_edge_mode->setShortcut(QKeySequence("Ctrl+2"));
122  m_edge_mode->setStatusTip("Set editing mode to 'Edge'");
123  m_edge_mode->setEnabled(false);
124  m_edge_mode->setCheckable(true);
125  connect(m_edge_mode, SIGNAL(triggered()), m_parent, SLOT(SetEdgeMode()));
126  menuMode->addAction(m_edge_mode);
127 
128  //Action for switching to Cell mode
129  m_cell_mode = new QAction("&Cell", menuMode);
130  m_cell_mode->setShortcut(QKeySequence("Ctrl+3"));
131  m_cell_mode->setStatusTip("Set editing mode to 'Cell'");
132  m_cell_mode->setEnabled(false);
133  m_cell_mode->setCheckable(true);
134  connect(m_cell_mode, SIGNAL(triggered()), m_parent, SLOT(SetCellMode()));
135  menuMode->addAction(m_cell_mode);
136 
137  //Submenu for generating actions.
138  /*QMenu* menuGenerate = new QMenu("&Generate", m_menu_edit);
139 
140  //Generate regular pattern action
141  m_generate_regular_pattern = new QAction("&Regular", menuGenerate);
142  m_generate_regular_pattern->setShortcut(QKeySequence("Ctrl+Shift+R"));
143  m_generate_regular_pattern->setStatusTip("Generate a regular cell pattern in the selected cell");
144  connect(m_generate_regular_pattern, SIGNAL(triggered()), m_parent, SLOT(GenerateRegularPattern()));
145  m_generate_regular_pattern->setEnabled(false);
146  menuGenerate->addAction(m_generate_regular_pattern);
147 
148  //Generate Voronoi pattern action
149  m_generate_voronoi_pattern = new QAction("&Voronoi Tesselation", menuGenerate);
150  m_generate_voronoi_pattern->setShortcut(QKeySequence("Ctrl+Shift+V"));
151  m_generate_voronoi_pattern->setStatusTip("Generate a Voronoi cell pattern in the selected cell");
152  connect(m_generate_voronoi_pattern, SIGNAL(triggered()), m_parent, SLOT(GenerateVoronoiPattern()));
153  m_generate_voronoi_pattern->setEnabled(false);
154  menuGenerate->addAction(m_generate_voronoi_pattern);
155  */
156 
157  //Delete item action
158  m_delete_item = new QAction("&Delete", m_menu_edit);
159  m_delete_item->setShortcut(QKeySequence("Ctrl+D"));
160  m_delete_item->setStatusTip("Delete the selected item");
161  connect(m_delete_item, SIGNAL(triggered()), m_view, SLOT(DeleteItem()));
162  m_delete_item->setEnabled(false);
163 
164  //Split edge action
165  m_split_edge = new QAction("&Split edge", m_menu_edit);
166  m_split_edge->setShortcut(QKeySequence("Ctrl+B"));
167  m_split_edge->setStatusTip("Split the selected edge");
168  connect(m_split_edge, SIGNAL(triggered()), m_view, SLOT(SplitEdge()));
169  m_split_edge->setEnabled(false);
170 
171  //Split cell action
172  m_split_cell = new QAction("&Split cell", m_menu_edit);
173  m_split_cell->setShortcut(QKeySequence("Ctrl+B"));
174  m_split_cell->setStatusTip("Split the selected cell");
175  connect(m_split_cell, SIGNAL(triggered()), m_view, SLOT(SplitCell()));
176  m_split_cell->setEnabled(false);
177 
178  //Create cell action
179  m_create_cell = new QAction("&Create cell", m_menu_edit);
180  m_create_cell->setShortcut(QKeySequence("Ctrl+A"));
181  m_create_cell->setStatusTip("Create a cell with the selected endpoints");
182  m_create_cell->setEnabled(false);
183  connect(m_create_cell, SIGNAL(triggered()), m_view, SLOT(CreateCell()));
184 
185  //Copy attributes action
186  m_copy_attributes = new QAction("&Copy attributes", m_menu_edit);
187  m_copy_attributes->setShortcut(QKeySequence("Ctrl+C"));
188  m_copy_attributes->setStatusTip("Copy attributes to the selected items from ...");
189  m_copy_attributes->setEnabled(false);
190  connect(m_copy_attributes, SIGNAL(triggered()), m_view, SLOT(CopyAttributes()));
191 
192  //Undo action
193  m_undo = new QAction("&Undo", m_menu_edit);
194  m_undo->setShortcut(QKeySequence("Ctrl+z"));
195  m_undo->setStatusTip("Undo the last action");
196  m_undo->setEnabled(false);
197  connect(m_undo, SIGNAL(triggered()), m_parent, SLOT(Undo()));
198 
199  //Redo action
200  m_redo = new QAction("&Redo", m_menu_edit);
201  m_redo->setShortcut(QKeySequence("Ctrl+Shift+z"));
202  m_redo->setStatusTip("Redo the last action");
203  m_redo->setEnabled(false);
204  connect(m_redo, SIGNAL(triggered()), m_parent, SLOT(Redo()));
205 
206  //Creation of actions for the view menu
207 
208  //Show attribute panel
209  m_show_attribute_panel = m_panels->AttributePanel()->GetDock()->toggleViewAction();
210  m_panels->AttributePanel()->GetDock()->toggleViewAction()->setText("Attribute panel");
211  m_show_attribute_panel->setStatusTip("Show the attribute panel");
212  m_show_attribute_panel->setEnabled(false);
213 
214  //Show geometric panel
215  m_show_geometric_panel = m_panels->GeometricPanel()->GetDock()->toggleViewAction();
216  m_panels->GeometricPanel()->GetDock()->toggleViewAction()->setText("Geometric panel");
217  m_show_geometric_panel->setStatusTip("Show the geometric panel");
218  m_show_geometric_panel->setEnabled(false);
219 
220  //Show parameters panel
221  m_show_parameters_panel = m_panels->ParametersPanel()->GetDock()->toggleViewAction();
222  m_panels->ParametersPanel()->GetDock()->toggleViewAction()->setText("Parameters panel");
223  m_show_parameters_panel->setStatusTip("Show the parameters panel");
224  m_show_parameters_panel->setEnabled(false);
225 
226  //Transparent cells
227  m_transparent_cells = new QAction("&Transparent cells", m_menu_view);
228  m_transparent_cells->setStatusTip("Set background of cells transparent");
229  m_transparent_cells->setCheckable(true);
230  m_transparent_cells->setEnabled(false);
231  connect(m_transparent_cells, SIGNAL(toggled(bool)), m_view, SLOT(SetTransparentCells(bool)));
232 
233  //Set background
234  m_set_background = new QAction("&Set background...", m_menu_view);
235  m_set_background->setStatusTip("Set background image");
236  m_set_background->setEnabled(false);
237  connect(m_set_background, SIGNAL(triggered()), m_view, SLOT(SetBackground()));
238 
239  //Set display mode
240  m_set_display_mode = new QAction("&Set color scheme ...", m_menu_view);
241  m_set_display_mode->setStatusTip("Set the color scheme for cells in display mode");
242  m_set_display_mode->setEnabled(false);
243  connect(m_set_display_mode, SIGNAL(triggered()), m_view, SLOT(SetDisplayModePreferences()));
244 
245 
246  //Cancel action
247  m_cancel = new QAction("&Cancel", m_parent);
248  m_cancel->setStatusTip("Cancel the current action");
249  m_cancel->setEnabled(false);
250  connect(m_cancel, SIGNAL(triggered()), m_view, SLOT(CancelAction()));
251 
252  // Setting up menus
253 
254  // Project menu
255  m_menu_project->addAction(m_new_tissue);
256  m_menu_project->addAction(m_open_tissue);
257  m_menu_project->addAction(m_save_tissue);
258  m_menu_project->addAction(m_close_tissue);
259  m_menu_project->addAction(m_quit);
260  addMenu(m_menu_project);
261 
262  // Edit menu
263  m_menu_edit->addMenu(menuMode);
264  //m_menu_edit->addMenu(menuGenerate);
265  m_menu_edit->addAction(m_delete_item);
266  m_menu_edit->addAction(m_split_edge);
267  m_menu_edit->addAction(m_split_cell);
268  m_menu_edit->addAction(m_create_cell);
269  m_menu_edit->addAction(m_copy_attributes);
270  m_menu_edit->addAction(m_undo);
271  m_menu_edit->addAction(m_redo);
272  addMenu(m_menu_edit);
273 
274  // View menu
275  m_menu_view->addAction(m_show_attribute_panel);
276  m_menu_view->addAction(m_show_geometric_panel);
277  m_menu_view->addAction(m_show_parameters_panel);
278  m_menu_view->addAction(m_transparent_cells);
279  m_menu_view->addAction(m_set_background);
280  m_menu_view->addAction(m_set_display_mode);
281  addMenu(m_menu_view);
282 
283  // Toolbar
284  QToolBar* toolBar = new QToolBar("Toolbar");
285 
286  QIcon nodeIcon(QString::fromStdString(InstallDirs::GetDataDir() + "/icons/editor/node.png"));
287  QIcon edgeIcon(QString::fromStdString(InstallDirs::GetDataDir() + "/icons/editor/edge.png"));
288  QIcon cellIcon(QString::fromStdString(InstallDirs::GetDataDir() + "/icons/editor/cell.png"));
289  QIcon cancelIcon(QString::fromStdString(InstallDirs::GetDataDir() + "/icons/Tango/22x22/actions/process-stop.png"));
290 
291  toolBar->addAction(m_node_mode);
292  toolBar->addAction(m_edge_mode);
293  toolBar->addAction(m_cell_mode);
294  toolBar->addAction(m_cancel);
295 
296  m_node_mode->setIcon(nodeIcon);
297  m_edge_mode->setIcon(edgeIcon);
298  m_cell_mode->setIcon(cellIcon);
299  m_cancel->setIcon(cancelIcon);
300 
301  QWidget* spacer = new QWidget();
302  spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
303  toolBar->addWidget(spacer);
304  toolBar->addWidget(m_view->GetSelectByIDWidget());
305 
306  m_parent->addToolBar(toolBar);
307 }
308 
309 void EditorActions::ItemsSelected(unsigned int count)
310 {
311  assert((m_view->GetMode() == Mode::NODE
312  || m_view->GetMode() == Mode::EDGE || m_view->GetMode() == Mode::CELL)
313  && "This mode isn't allowed.");
314 
315  m_delete_item->setEnabled(count == 1 && m_view->SelectedIsDeletable());
316  m_split_edge->setEnabled(count == 1 && m_view->GetMode() == Mode::EDGE);
317  m_split_cell->setEnabled(count == 2
318  && m_view->GetMode() == Mode::NODE && m_view->SelectedIsSplitable());
319  m_create_cell->setEnabled(count == 2
320  && m_view->GetMode() == Mode::NODE && m_view->SelectedIsAtBoundary());
321  m_copy_attributes->setEnabled(count > 0
322  && (m_view->GetMode() == Mode::CELL
323  || m_view->GetMode() == Mode::EDGE || m_view->GetMode() == Mode::NODE));
324 }
325 
327 {
328  m_new_tissue->setEnabled(true);
329  m_open_tissue->setEnabled(true);
330  m_save_tissue->setEnabled(true);
331  m_close_tissue->setEnabled(true);
332 
333  m_node_mode->setEnabled(true);
334  m_edge_mode->setEnabled(true);
335  m_cell_mode->setEnabled(true);
336  m_undo->setEnabled(false);
337  m_redo->setEnabled(false);
338 
339  m_show_attribute_panel->setEnabled(true);
340  m_show_geometric_panel->setEnabled(true);
341  m_show_parameters_panel->setEnabled(true);
342  m_transparent_cells->setEnabled(true);
343  m_set_background->setEnabled(true);
344  m_set_display_mode->setEnabled(true);
345 }
346 
348 {
349  m_save_tissue->setEnabled(false);
350  m_close_tissue->setEnabled(false);
351 
352  m_node_mode->setEnabled(false);
353  m_edge_mode->setEnabled(false);
354  m_cell_mode->setEnabled(false);
355 
356  m_delete_item->setEnabled(false);
357  m_split_edge->setEnabled(false);
358  m_split_cell->setEnabled(false);
359  m_create_cell->setEnabled(false);
360  m_copy_attributes->setEnabled(false);
361 
362  m_undo->setEnabled(false);
363  m_redo->setEnabled(false);
364 
365  m_cancel->setEnabled(false);
366 
367  m_show_attribute_panel->setEnabled(false);
368  m_show_geometric_panel->setEnabled(false);
369  m_show_parameters_panel->setEnabled(false);
370  m_transparent_cells->setEnabled(false);
371  m_set_background->setEnabled(false);
372  m_set_display_mode->setEnabled(false);
373 }
374 
376 {
377  FixToggle();
378 
379  bool modesEnabled = (m_view->GetMode() == Mode::DISPLAY
380  || m_view->GetMode() == Mode::NODE || m_view->GetMode() == Mode::EDGE
381  || m_view->GetMode() == Mode::CELL || m_view->GetMode() == Mode::NONE);
382 
383  m_node_mode->setEnabled(modesEnabled);
384  m_edge_mode->setEnabled(modesEnabled);
385  m_cell_mode->setEnabled(modesEnabled);
386 
387  m_delete_item->setEnabled(false);
388  m_split_edge->setEnabled(false);
389  m_split_cell->setEnabled(false);
390  m_create_cell->setEnabled(false);
391  m_copy_attributes->setEnabled(false);
392 
393 
394  m_undo->setEnabled(m_view->GetMode() != Mode::CELL_CREATE
395  && m_view->GetMode() != Mode::CELL_SLICE && m_undo_stack->CanUndo());
396  m_redo->setEnabled(m_view->GetMode() != Mode::CELL_CREATE
397  && m_view->GetMode() != Mode::CELL_SLICE && m_undo_stack->CanRedo());
398 
399  m_cancel->setEnabled(m_view->GetMode() == Mode::CELL_COPY
400  || m_view->GetMode() == Mode::CELL_CREATE || m_view->GetMode() == Mode::CELL_SLICE
401  || m_view->GetMode() == Mode::EDGE_COPY || m_view->GetMode() == Mode::NODE_COPY);
402 }
403 
405 {
406  m_undo->setEnabled(m_undo_stack->CanUndo());
407  m_redo->setEnabled(m_undo_stack->CanRedo());
408 }
409 
410 void EditorActions::Show(bool visible)
411 {
412  m_menu_project->menuAction()->setVisible(visible);
413  m_menu_edit->menuAction()->setVisible(visible);
414  m_menu_view->menuAction()->setVisible(visible);
415 }
416 
417 } // namespace
static std::string GetDataDir()
Utility method: get name of the directory for data files.
see the online Qt documentation
Namespace for SimPT tissue editor package.
Definition: Cell.h:32
bool SelectedIsAtBoundary() const
Checks whether the selected (editable) items are at the boundary of the cell complex.
The graphical view on the tissue.
EnabledActions interface.
Interface for PTreePanels.
Interface for the TissueEditor.
Gui::PTreeContainer * ParametersPanel() const
Get the parameters panel.
void FixToggle()
Fix the toggles of the modes.
Interface for EditorActions.
void ModeChanged()
The mode has been changed.
EditorActions(TissueEditor *parent, TissueGraphicsView *view, PTreePanels *panels, UndoStack *undoStack)
Constructor.
Main GUI class for cell editor.
Definition: TissueEditor.h:42
void Show(bool visible)
Show or hide the menubar.
bool SelectedIsDeletable() const
Checks whether the selected (editable) items are deletable.
bool SelectedIsSplitable() const
Checks whether two selected nodes can split a single cell.
see the online Qt documentation
Interface for SelectByIDWidget.
Undo Stack for actions performed on a tissue.
Definition: UndoStack.h:31
Manages the attribute and geometric ptree panel for a given tissue.
Definition: PTreePanels.h:35
void ItemsSelected(unsigned int count)
Number of items that were selected.
QDockWidget * GetDock() const
Get the associated dock widget, containing the ptree editor.
Interface for UndoStack.
Interface for PTreeEditorWindow.
Interface for GraphicsView of tissue.
bool CanUndo() const
True if the current action can be undone.
Definition: UndoStack.cpp:48
virtual ~EditorActions()
Destructor.
void LeafOpened()
A tissue has been opened.
see the online Qt documentation
Interface for Compressor.
void LeafClosed()
The tissue has been closed.
SelectByIDWidget * GetSelectByIDWidget() const
Returns the widget for selecting items by ID.
void Modified()
The tissue has been modified.
Gui::PTreeContainer * AttributePanel() const
Get the attribute panel.
bool CanRedo() const
True if the current action can be redone.
Definition: UndoStack.cpp:53
Mode GetMode() const
Returns the current mode.
Gui::PTreeContainer * GeometricPanel() const
Get the geometric panel.
Interface for PTreeContainer.