Tulip  4.8.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
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  bool checkSocketConnected();
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 
114 public:
115  enum ProgressOption {
116  NoProgressOption = 0x0,
117  IsPreviewable = 0x1,
118  IsCancellable = 0x2,
119  IsStoppable = 0x4
120  };
121  Q_DECLARE_FLAGS(ProgressOptions,ProgressOption)
122 
123  virtual std::string category() const {
124  return PERSPECTIVE_CATEGORY;
125  }
126  std::string icon() const {
127  return ":/tulip/gui/icons/32/plugin_controller.png";
128  }
129 
130  /**
131  * @brief Called at the beginning of the tulip_perspective to set the Perspective singleton.
132  * @see instance()
133  */
134  static void setInstance(tlp::Perspective*);
135 
136  /**
137  * Since a Perspective has its own process to work in, there can be only one perspective instance by process.
138  * 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.
139  * This architecture was added for developers who want to create an application containing several plugins grouped into Perspective.
140  * @return The perspective singleton
141  */
142  static tlp::Perspective* instance();
143 
144  /**
145  * @return A typed instance of the perspective singleton.
146  */
147  template<typename T>
148  static T* typedInstance() {
149  return dynamic_cast<T*>(instance());
150  }
151 
152  /**
153  * @brief Constructs a perspective object
154  * @warning There should not be any logic implemented into the Perspective's constructor. See the start method instead.
155  */
157  virtual ~Perspective();
158 
159  /**
160  * @brief Build the main window GUI and starts the workflow.
161  * When this method is called, it means that the Perspective is reponsible of the application workflow until the application is closed by the user.
162  * @param progress A progress handler
163  */
164  virtual void start(tlp::PluginProgress* progress)=0;
165 
166  /**
167  * @brief Creates a progress handler and returns it.
168  * This method allows lower-level widgets to create top-level progress bars directly from the Perspective.
169  * @return
170  */
171  virtual PluginProgress *progress(ProgressOptions options = ProgressOptions(IsPreviewable | IsStoppable | IsCancellable));
172 
173  /**
174  * @return The Perspective's main window.
175  */
176  QMainWindow* mainWindow() const;
177 
178  /**
179  * @brief Checks if the name corresponds to a reserved properties.
180  * 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.
181  * @return true if the perspective is registered.
182  */
183  bool isReservedPropertyName(QString name);
184 
185  /**
186  * @brief Sets a new property name as registered
187  */
188  void registerReservedProperty(QString);
189 
190  /**
191  * @brief Tells the perspective that the graph visualizations should be redrawn.
192  * @param center if true, visualization should also be centered (eg. the layout has been changed)
193  */
194  virtual void redrawPanels(bool center=false)=0;
195 
196  /**
197  * @brief Tells the perspective that the visualizations for a given graph should be centered.
198  * @note By default, this method does nothing.
199  */
200  virtual void centerPanelsForGraph(tlp::Graph*);
201 
202 public slots:
203  /**
204  * @brief Called when the user wants to close the application.
205  * @return Returning false prevents the window from being closed but the Perspective will have to implement its own way of closing the application.
206  */
207  virtual bool terminated() {
208  return true;
209  }
210 
211 protected slots:
212  /**
213  * @brief Send a message to the Tulip agent to make him display the Plugins Center page.
214  */
215  void showPluginsCenter();
216 
217  /**
218  * @brief Call this slot to swith to full screen or windowed mode
219  * @param f is true, switch to full screen mode. If false, switch to windowed mode
220  */
221  void showFullScreen(bool f);
222 
223  /**
224  * @brief Send a message to the Tulip agent to make him display the Projects page.
225  */
226  void showProjectsPage();
227 
228  /**
229  * @brief Send a message to the Tulip agent to make him display the "About us" page.
230  */
231  void showAboutPage();
232 
233  /**
234  * @brief Send a message to the Tulip agent to make him display a message in the system notification area.
235  * @param s The message to display.
236  */
237  void showTrayMessage(const QString& s);
238 
239  /**
240  * @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.
241  * @param title The message's title.
242  * @param s The message to display.
243  */
244  void showErrorMessage(const QString& title, const QString& s);
245 
246  /**
247  * @brief Send a message to the Tulip agent to make him open a new Tulip Project.
248  * @param path the absolute path of the project file.
249  */
250  virtual void openProjectFile(const QString& path);
251 
252  /**
253  * @brief Send a message to the Tulip agent to make him open a new Perspective without a project.
254  * @param name The name of the PErspective to create.
255  */
256  void createPerspective(const QString& name);
257 };
258 Q_DECLARE_OPERATORS_FOR_FLAGS(Perspective::ProgressOptions)
259 
260 }
261 
262 #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:126
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:207
Contains runtime parameters for a plugin.
Definition: PluginContext.h:39
static T * typedInstance()
Definition: Perspective.h:148
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