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