Tulip  4.10.0
Better Visualization Through Research
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
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/PluginContext.h>
24 #include <tulip/Plugin.h>
25 
26 #include <QString>
27 #include <QVariantMap>
28 #include <QSet>
29 
30 class QMainWindow;
31 class QTcpSocket;
32 
33 namespace tlp {
34 
35 class PluginProgress;
36 class TulipProject;
37 
38 static const std::string PERSPECTIVE_CATEGORY = "Perspective";
39 
40 /**
41  * @ingroup Plugins
42  * @brief A context data structure for tlp::Perspective instances.
43  *
44  * @see tlp::Perspective
45  */
46 class TLP_QT_SCOPE PerspectiveContext : public tlp::PluginContext {
47 public:
48  PerspectiveContext(): mainWindow(0), project(0), tulipPort(0) {}
49  QMainWindow *mainWindow;
50  TulipProject *project;
51  QString externalFile;
52  QVariantMap parameters;
53  quint64 tulipPort;
54  unsigned int id;
55 };
56 
57 /**
58  * @ingroup Plugins
59  * @brief A Perspective is a Tulip plugin that completely re-defines the user interface.
60  *
61  * A Perspective aims at using the multiple features available in Tulip to create a complete, coherent workflow dedicated to a particular use-case.
62  * 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.
63  *
64  * A Perspective always acts in its own process and communicate with the Tulip agent via TCP sockets.
65  * 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.
66  *
67  * 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.
68  * 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 developer.
69  */
70 class TLP_QT_SCOPE Perspective : public QObject, public tlp::Plugin {
71  Q_OBJECT
72 
73  static tlp::Perspective* _instance;
74  QSet<QString> _reservedProperties;
75  QTcpSocket* _agentSocket;
76  unsigned int _perspectiveId;
77  bool _maximised;
78  void sendAgentMessage(const QString&);
79  void notifyProjectLocation(const QString& path);
80 
81 
82 protected:
83  /**
84  * @brief The project associated to this perspective. This project can be empty or contain data depending on how the Perspective was launched:
85  * To launch a perspective, the tulip_perspective executable is called with the following arguments:
86  * @code
87  * tulip_perspective [--perspective=Name] [file_path]
88  * @endcode
89  * @list
90  * @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.
91  * @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.
92  * @endlist
93  */
95 
96  /**
97  * @brief The main window on which the perspective should build the GUI.
98  *
99  * 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.
100  */
101  QMainWindow *_mainWindow;
102 
103  /**
104  * 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.
105  * @note Remember that perspectives should always store their data into TulipProject in order to keep a consistent workflow.
106  */
107  QString _externalFile;
108 
109  /**
110  * @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.
111  */
112  QVariantMap _parameters;
113  bool checkSocketConnected();
114 
115 public:
116  enum ProgressOption {
117  NoProgressOption = 0x0,
118  IsPreviewable = 0x1,
119  IsCancellable = 0x2,
120  IsStoppable = 0x4
121  };
122  Q_DECLARE_FLAGS(ProgressOptions,ProgressOption)
123 
124  virtual std::string category() const {
125  return PERSPECTIVE_CATEGORY;
126  }
127  std::string icon() const {
128  return ":/tulip/gui/icons/32/plugin_controller.png";
129  }
130 
131  /**
132  * @brief Called at the beginning of the tulip_perspective to set the Perspective singleton.
133  * @see instance()
134  */
135  static void setInstance(tlp::Perspective*);
136 
137  /**
138  * Since a Perspective has its own process to work in, there can be only one perspective instance by process.
139  * 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.
140  * This architecture was added for developers who want to create an application containing several plugins grouped into Perspective.
141  * @return The perspective singleton
142  */
143  static tlp::Perspective* instance();
144 
145  /**
146  * @return A typed instance of the perspective singleton.
147  */
148  template<typename T>
149  static T* typedInstance() {
150  return dynamic_cast<T*>(instance());
151  }
152 
153  /**
154  * @brief Constructs a perspective object
155  * @warning There should not be any logic implemented into the Perspective's constructor. See the start method instead.
156  */
158  virtual ~Perspective();
159 
160  /**
161  * @brief Build the main window GUI and starts the workflow.
162  * When this method is called, it means that the Perspective is reponsible of the application workflow until the application is closed by the user.
163  * @param progress A progress handler
164  */
165  virtual void start(tlp::PluginProgress* progress)=0;
166 
167  /**
168  * @brief Creates a progress handler and returns it.
169  * This method allows lower-level widgets to create top-level progress bars directly from the Perspective.
170  * @return
171  */
172  virtual PluginProgress *progress(ProgressOptions options = ProgressOptions(IsPreviewable | IsStoppable | IsCancellable));
173 
174  /**
175  * @return The Perspective's main window.
176  */
177  QMainWindow* mainWindow() const;
178 
179  /**
180  * @brief Checks if the name corresponds to a reserved properties.
181  * 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.
182  * @return true if the perspective is registered.
183  */
184  bool isReservedPropertyName(QString name);
185 
186  /**
187  * @brief Sets a new property name as registered
188  */
189  void registerReservedProperty(QString);
190 
191  /**
192  * @brief Tells the perspective that the graph visualizations should be redrawn.
193  * @param center if true, visualization should also be centered (eg. the layout has been changed)
194  */
195  virtual void redrawPanels(bool center=false)=0;
196 
197  /**
198  * @brief Tells the perspective that the visualizations for a given graph should be centered.
199  * @note By default, this method does nothing.
200  */
201  virtual void centerPanelsForGraph(tlp::Graph*);
202 
203 public slots:
204  /**
205  * @brief Called when the user wants to close the application.
206  * @return Returning false prevents the window from being closed but the Perspective will have to implement its own way of closing the application.
207  */
208  virtual bool terminated() {
209  return true;
210  }
211 
212 protected slots:
213  /**
214  * @brief Send a message to the Tulip agent to make him display the Plugins Center page.
215  */
216  void showPluginsCenter();
217 
218  /**
219  * @brief Call this slot to swith to full screen or windowed mode
220  * @param f is true, switch to full screen mode. If false, switch to windowed mode
221  */
222  void showFullScreen(bool f);
223 
224  /**
225  * @brief Send a message to the Tulip agent to make him display the Projects page.
226  */
227  void showProjectsPage();
228 
229  /**
230  * @brief Send a message to the Tulip agent to make him display the "About us" page.
231  */
232  void showAboutPage();
233 
234  /**
235  * @brief Send a message to the Tulip agent to make him display a message in the system notification area.
236  * @param s The message to display.
237  */
238  void showTrayMessage(const QString& s);
239 
240  /**
241  * @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.
242  * @param title The message's title.
243  * @param s The message to display.
244  */
245  void showErrorMessage(const QString& title, const QString& s);
246 
247  /**
248  * @brief Send a message to the Tulip agent to make him open a new Tulip Project.
249  * @param path the absolute path of the project file.
250  */
251  virtual void openProjectFile(const QString& path);
252 
253  /**
254  * @brief Send a message to the Tulip agent to make him open a new Perspective without a project.
255  * @param name The name of the PErspective to create.
256  */
257  void createPerspective(const QString& name);
258 };
259 Q_DECLARE_OPERATORS_FOR_FLAGS(Perspective::ProgressOptions)
260 
261 }
262 
263 #endif //_PERSPECTIVE_H
QVariantMap _parameters
Contains extra parameters that have not been parsed by the overleying system. Those are considered to...
Definition: Perspective.h:112
QMainWindow * _mainWindow
The main window on which the perspective should build the GUI.
Definition: Perspective.h:101
std::string icon() const
The icon (preferably a thumbnail) of the plugin.
Definition: Perspective.h:127
QString _externalFile
Definition: Perspective.h:107
The TulipProject object handles the content of a Tulip project.
Definition: TulipProject.h:71
TulipProject * _project
The project associated to this perspective. This project can be empty or contain data depending on ho...
Definition: Perspective.h:94
virtual bool terminated()
Called when the user wants to close the application.
Definition: Perspective.h:208
Contains runtime parameters for a plugin.
Definition: PluginContext.h:39
static T * typedInstance()
Definition: Perspective.h:149
A context data structure for tlp::Perspective instances.
Definition: Perspective.h:46
Top-level interface for plug-ins.
Definition: Plugin.h:79
PluginProcess subclasses are meant to notify about the progress state of some process (typically a pl...
A Perspective is a Tulip plugin that completely re-defines the user interface.
Definition: Perspective.h:70