MIRA
Workbench.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_WORKBENCH_H_
48 #define _MIRA_WORKBENCH_H_
49 
50 #include <set>
51 
52 #include <QSignalMapper>
53 #include <QMainWindow>
54 
56 
57 #include <factory/Factory.h>
58 #include <utils/Buffer.h>
59 
60 #include <rcp/WorkbenchPart.h>
61 #include <rcp/ViewPart.h>
62 #include <rcp/EditorPart.h>
63 
64 namespace mira {
65 
67 
68 class PerspectiveTabWidget;
69 
70 class MIRA_GUI_RCP_EXPORT Workbench : public QMainWindow, public IWorkbenchPartSite
71 {
72  Q_OBJECT
73 public:
74 
75  Workbench(bool setupUi = true);
76  virtual ~Workbench();
77 
78 public:
79 
80  void reflect(XMLSerializer& r);
81  void reflect(XMLDeserializer& r);
82 
83 public:
84 
85  void setupUi();
86 
87 public:
88 
89  QWidget* createPart(ClassProxy partClass);
90  QWidget* restorePart(ClassProxy partClass, const XMLDom& xml);
91 
92 public:
93 
94  virtual void saveWorkspace(const std::string& file);
95  virtual void loadWorkspace(const std::string& file);
96 
98  void cleanupWorkspace();
99 
100 public:
101 
103  {
104  public:
106  Perspective(const std::string& name) : mName(name) {}
107 
108  const std::string getName() const { return mName; }
109  void setName(const std::string& name) { mName = name; }
110 
111  public:
112 
113  template <typename Reflector>
114  void reflect(Reflector& r)
115  {
116  r.member("Name", mName, "");
117  r.member("State", mState, "");
118  }
119 
120  private:
121  friend class Workbench;
122 
123  std::string mName;
124  XMLDom mState; // the state of all views, editors, etc. as XMLDom document
125  };
126  typedef boost::shared_ptr<Perspective> PerspectivePtr;
127 
128 private:
129 
130  void setupNewViewPart(ViewPart* viewPart);
131  void setupNewEditorPart(EditorPart* editorPart);
132 
133  void clearWorkspaceParts(); // removes all components of a perspective
134  void storeCurrentPerspective();
135  void storeCurrentPerspective(Perspective* perspective);
136  bool restorePerspective(Perspective* perspective);
137 
138 public:
139 
140  bool isDockAreaMinimized(Qt::DockWidgetArea area);
141  void minimizeDockArea(Qt::DockWidgetArea area);
142  void restoreDockArea(Qt::DockWidgetArea area);
143 
144 protected:
145 
146  std::list<ViewPart*> mViewParts;
147  std::list<EditorPart*> mEditorParts;
148 
149  std::map<std::string, ViewPart*> mCreatedViews;
150 
151  std::list<PerspectivePtr> mPerspectives;
153 
155  QDockWidget* dock;
156  QWidget* widget;
157  QBoxLayout* layout;
158  bool minimized;
159  };
160 
161  std::map<Qt::DockWidgetArea, MinimizedDockArea> mMinimizedDockAreas;
162  QSignalMapper* mDockRestoreMapper;
163 
164  // state of dockwidget before minimizing, in order to restore its state
166  QSize size;
167  bool visible;
168  };
169  std::map<QDockWidget*, MinimizedDockWidgetState> mMinimizedDockWidgetStates;
170 
171  void createMinimizedDockArea(Qt::DockWidgetArea area);
172 
173 public: // GUI parts
174 
175  QMenu* createPopupMenu();
176 
177 public slots:
178 
179  Perspective* addPerspective(std::string name);
180  void removePerspective(Perspective* perspective);
181  void activatePerspective(Perspective* perspective);
182 
183 private slots:
184 
185  bool onChangedPerspective(Perspective* perspective);
186  void onMovedPerspective(int from, int to);
187  void onViewDestroyed(ViewPart* view);
188  void onViewActivated(ViewPart* view);
189  void onViewMinimizedRequested(ViewPart* view);
190  void onViewDockLocationChanged(Qt::DockWidgetArea area);
191  void onViewRestore(QWidget* view);
192 
193 protected slots:
194  virtual void onEditorCreated(EditorPart* editor);
195  virtual void onEditorDestroyed(EditorPart* editor);
196 
197  virtual void onWindowTitleChanged(EditorPartWindow* editor);
198  virtual void onEditorWindowActivated(EditorPartWindow* window);
199 
200 private: // GUI parts
201 
202  PerspectiveTabWidget* mPerspectiveTabWidget;
203 
204 public: // implementation of IWorkbenchPartSite
205 
206  virtual void addPartListener(IPartListener* listener);
207  virtual void removePartListener(IPartListener* listener);
208  virtual IWorkbenchPart* getActiveEditor();
209  virtual std::list<IWorkbenchPart*> getEditors(bool backToFront = false);
210 
211 private:
212 
213  std::set<IPartListener*> mPartListeners;
214  IWorkbenchPart* mActiveEditorPart;
215 
216 public:
217 
218  void savePartMemory();
219  void loadPartMemory();
220 
221 protected slots:
222 
223  void storePartMemory(ViewPart* part);
224  void storePartMemory(EditorPart* part);
225 
226 protected:
227 
228  typedef boost::shared_ptr<XMLDom> XMLDomPtr;
229  std::map<std::string, XMLDomPtr> mPartMemory;
230 
231 protected:
232  MIRA_DEFINE_EXCEPTION(XInvalidWorkspace, Exception)
233 };
234 
236 
237 }
238 
239 #endif
boost::shared_ptr< XMLDom > XMLDomPtr
Definition: Workbench.h:228
A STL conform wrapper for libxml2 to read XML files as DOM.
Definition: XMLDom.h:73
#define MIRA_DEFINE_EXCEPTION(Ex, Base)
Macro for easily defining a new compatible exception class.
Definition: Exception.h:165
The class proxy assures that the pointer to the class object is always valid.
Definition: Class.h:400
PropertyHint file(const std::string &filters=std::string(), bool save=false)
Tells the property editor that the path is for a file, and that it should show a "File Open"/"File Sa...
Definition: Path.h:247
std::list< EditorPart * > mEditorParts
Definition: Workbench.h:147
Definition: XMLSerializer.h:121
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
An editor is typically used to edit or browse data or objects.
Definition: EditorPart.h:69
Definition: Workbench.h:102
bool minimized
Definition: Workbench.h:158
boost::shared_ptr< Perspective > PerspectivePtr
Definition: Workbench.h:126
Perspective * mCurrentPerspective
Definition: Workbench.h:152
void setName(const std::string &name)
Definition: Workbench.h:109
const std::string getName() const
Definition: Workbench.h:108
Perspective(const std::string &name)
Definition: Workbench.h:106
std::map< std::string, ViewPart * > mCreatedViews
Definition: Workbench.h:149
Definition: Workbench.h:154
Declaration of the ViewPart.
std::list< ViewPart * > mViewParts
Definition: Workbench.h:146
$Header file containing base classes to enable class creation using a class factory$ ...
Perspective()
Definition: Workbench.h:105
Definition: EditorPartWindow.h:63
Definition: PartListener.h:56
Definition: Workbench.h:70
QDockWidget * dock
Definition: Workbench.h:155
void reflect(Reflector &r)
Definition: Workbench.h:114
void reflect(Reflector &r, LogRecord &record)
Non-intrusive reflector for LogRecord.
Definition: LoggingCore.h:136
bool visible
Definition: Workbench.h:167
A view is typically used to display information or properties.
Definition: ViewPart.h:69
Base class for exceptions.
Definition: Exception.h:194
QBoxLayout * layout
Definition: Workbench.h:157
QSize size
Definition: Workbench.h:166
Definition: WorkbenchPart.h:89
std::map< QDockWidget *, MinimizedDockWidgetState > mMinimizedDockWidgetStates
Definition: Workbench.h:169
The primary interface between a workbench part and the workbench.
Definition: WorkbenchPart.h:68
Definition: PerspectiveTabWidget.h:89
std::list< PerspectivePtr > mPerspectives
Definition: Workbench.h:151
XMLSerializer and XMLDeserializer.
QWidget * widget
Definition: Workbench.h:156
#define MIRA_GUI_RCP_EXPORT
Definition: GuiRCPExports.h:61
QSignalMapper * mDockRestoreMapper
Definition: Workbench.h:162
Generic buffer class that can be used as a replacement for std::vector.
std::map< Qt::DockWidgetArea, MinimizedDockArea > mMinimizedDockAreas
Definition: Workbench.h:161
std::map< std::string, XMLDomPtr > mPartMemory
Definition: Workbench.h:229
Declaration of the EditorPart class.
Declaration of WorkbenchPart and related interfaces.
Deserializer for serializing objects from XML format.
Definition: XMLSerializer.h:313