Tulip  4.1.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
Perspective.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef _PERSPECTIVE_H
21 #define _PERSPECTIVE_H
22 
23 #include <tulip/PluginLister.h>
24 #include <tulip/TulipProject.h>
25 #include <tulip/PluginContext.h>
26 #include <tulip/Plugin.h>
27 #include <QtCore/QObject>
28 #include <QtCore/QVariant>
29 
30 class QMainWindow;
31 class QTcpSocket;
32 
33 namespace tlp {
34 
35 class PluginProgress;
36 
37 static const std::string PERSPECTIVE_CATEGORY = QObject::trUtf8("Perspective").toStdString();
38 
39 /**
40  * @ingroup Plugins
41  * @brief A context data structure for tlp::Perspective instances.
42  *
43  * @see tlp::Perspective
44  */
45 class TLP_QT_SCOPE PerspectiveContext : public tlp::PluginContext {
46 public:
47  PerspectiveContext(): mainWindow(0), project(0), tulipPort(0) {}
48  QMainWindow *mainWindow;
49  TulipProject *project;
50  QString externalFile;
51  QVariantMap parameters;
52  quint64 tulipPort;
53  unsigned int id;
54 };
55 
56 /**
57  * @ingroup Plugins
58  * @brief A Perspective is a Tulip plugin that completely re-defines the user interface.
59  *
60  * A Perspective aims at using the multiple features available in Tulip to create a complete, coherent workflow dedicated to a particular use-case.
61  * Perspectives are chosen by the user when first running the Tulip agent. The main perspective is called "Tulip". This perspective unveils all the Tulip features and aims at being a protyping and researching platform.
62  *
63  * A Perspective always acts in its own process and communicate with the Tulip agent via TCP sockets.
64  * Thus, it is the Perspective's responsibility to offer the possibility to display graphs, run plugins, etc. A lot of helper classes can be found into the tulip-gui API like pre-made widgets, Qt models, etc.
65  *
66  * Perspective's data is stored into a TulipProject. A TulipProject is an archive capable of containing heterogeneous data (like multiple graphs, textures, extra files, etc). When a TulipProject gets saved by a perspective, it is linked to it in its meta-informations.
67  * Creating a Perspective primarily into implementing the start() method that builds the GUI. This method will be called by the overleying system when a new perspective is launched. The rest of the logic implementation is left to the developper.
68  */
69 class TLP_QT_SCOPE Perspective : public QObject, public tlp::Plugin {
70  Q_OBJECT
71 
72  static tlp::Perspective* _instance;
73  QSet<QString> _reservedProperties;
74  QTcpSocket* _agentSocket;
75  unsigned int _perspectiveId;
76 
77  void sendAgentMessage(const QString&);
78  void notifyProjectLocation(const QString& path);
79 
80 protected:
81  /**
82  * @brief The project associated to this perspective. This project can be empty or contain data depending on how the Perspective was launched:
83  * To launch a perspective, the tulip_perspective executable is called with the following arguments:
84  * @code
85  * tulip_perspective [--perspective=Name] [file_path]
86  * @endcode
87  * @list
88  * @li The --perspective argument forces Tulip to start the "Name" perspective. Even if the project states otherwise. If this argument is not specified, Tulip will look in the project's meta-data to dertermine the perspective to launch.
89  * @li file_path is the absolute path of the project archive to associate with the perspective. If file_path is not given, the --perspective argument must be declared in order for Tulip to know what perspective to launch. In this case, _project will point to an empty (but valid!) project.
90  * @endlist
91  */
93 
94  /**
95  * @brief The main window on which the perspective should build the GUI.
96  *
97  * It is note the Perspective's reponsibility to destroy the main window when the application gets closed. Generally speaking, destorying the _mainWindow pointer could lead to undefined behavior.
98  */
99  QMainWindow *_mainWindow;
100 
101  /**
102  * If the user provided a file to the tulip_perspective but this file is not recognized as a valid TulipProject, the full path of the file will be stored into the _externalFile member.
103  * @note Remember that perspectives should always store their data into TulipProject in order to keep a consistent workflow.
104  */
105  QString _externalFile;
106 
107  /**
108  * @brief Contains extra parameters that have not been parsed by the overleying system. Those are considered to be Perspective-specific and are forwarded into this variable.
109  */
110  QVariantMap _parameters;
111 
112 public:
113  enum ProgressOption {
114  NoProgressOption = 0x0,
115  IsPreviewable = 0x1,
116  IsCancellable = 0x2,
117  IsStoppable = 0x4
118  };
119  Q_DECLARE_FLAGS(ProgressOptions,ProgressOption)
120 
121  virtual std::string category() const {
122  return PERSPECTIVE_CATEGORY;
123  }
124  std::string icon() const {
125  return ":/tulip/gui/icons/32/plugin_controller.png";
126  }
127 
128  /**
129  * @brief Called at the beginning of the tulip_perspective to set the Perspective singleton.
130  * @see instance()
131  */
132  static void setInstance(tlp::Perspective*);
133 
134  /**
135  * Since a Perspective has its own process to work in, there can be only one perspective instance by process.
136  * In order to ease the development process, Perspective are available as a singleton in order for child widgets and plugins to be able to access to the features of a Perspective.
137  * This architecture was added for developers who want to create an application containing several plugins grouped into Perspective.
138  * @return The perspective singleton
139  */
140  static tlp::Perspective* instance();
141 
142  /**
143  * @return A typed instance of the perspective singleton.
144  */
145  template<typename T>
146  static T* typedInstance() {
147  return dynamic_cast<T*>(instance());
148  }
149 
150  /**
151  * @brief Constructs a perspective object
152  * @warning There should not be any logic implemented into the Perspective's constructor. See the start method instead.
153  */
155  virtual ~Perspective();
156 
157  /**
158  * @brief Build the main window GUI and starts the workflow.
159  * When this method is called, it means that the Perspective is reponsible of the application workflow until the application is closed by the user.
160  * @param progress A progress handler
161  */
162  virtual void start(tlp::PluginProgress* progress)=0;
163 
164  /**
165  * @brief Creates a progress handler and returns it.
166  * This method allows lower-level widgets to create top-level progress bars directly from the Perspective.
167  * @return
168  */
169  virtual PluginProgress *progress(ProgressOptions options = ProgressOptions(IsPreviewable | IsStoppable | IsCancellable));
170 
171  /**
172  * @return The Perspective's main window.
173  */
174  QMainWindow* mainWindow() const;
175 
176  /**
177  * @brief Checks if the name corresponds to a reserved properties.
178  * Perspectives are allowed to reserve graph properties. A reserved graph properties is a core property that cannot be deleted by the user and cannot be renamed.
179  * @return true if the perspective is registered.
180  */
181  bool isReservedPropertyName(QString name);
182 
183  /**
184  * @brief Sets a new property name as registered
185  */
186  void registerReservedProperty(QString);
187 
188  /**
189  * @brief Tells the perspective that the graph visualizations should be redrawn.
190  * @param center if true, visualization should also be centered (eg. the layout has been changed)
191  */
192  virtual void redrawPanels(bool center=false)=0;
193 
194  /**
195  * @brief Tells the perspective that the visualizations for a given graph should be centered.
196  * @note By default, this method does nothing.
197  */
198  virtual void centerPanelsForGraph(tlp::Graph*);
199 
200 public slots:
201  /**
202  * @brief Called when the user wants to close the application.
203  * @return Returning false prevents the window from being closed but the Perspective will have to implement its own way of closing the application.
204  */
205  virtual bool terminated() {
206  return true;
207  }
208 
209 protected slots:
210  /**
211  * @brief Send a message to the Tulip agent to make him display the Plugins Center page.
212  */
213  void showPluginsCenter();
214 
215  /**
216  * @brief Send a message to the Tulip agent to make him display the Projects page.
217  */
218  void showProjectsPage();
219 
220  /**
221  * @brief Send a message to the Tulip agent to make him display the "About us" page.
222  */
223  void showAboutPage();
224 
225  /**
226  * @brief Send a message to the Tulip agent to make him display a message in the system notification area.
227  * @param s The message to display.
228  */
229  void showTrayMessage(const QString& s);
230 
231  /**
232  * @brief Send a message to the Tulip agent to make him display an error message that will be shown in the system notification as well as on the welcome page.
233  * @param title The message's title.
234  * @param s The message to display.
235  */
236  void showErrorMessage(const QString& title, const QString& s);
237 
238  /**
239  * @brief Send a message to the Tulip agent to make him open a new Tulip Project.
240  * @param path the absolute path of the project file.
241  */
242  virtual void openProjectFile(const QString& path);
243 
244  /**
245  * @brief Send a message to the Tulip agent to make him open a new Perspective without a project.
246  * @param name The name of the PErspective to create.
247  */
248  void createPerspective(const QString& name);
249 };
250 Q_DECLARE_OPERATORS_FOR_FLAGS(Perspective::ProgressOptions)
251 
252 }
253 
254 #endif //_PERSPECTIVE_H