DataDirector API
DDD_Viewer.h
Go to the documentation of this file.
1 /*! \file DDD_Viewer.h
2 
3  \par Copyright Information
4 
5  Copyright (c) 2012 The DiSTI Corporation.<br>
6  11301 Corporate Blvd; Suite 100<br>
7  Orlando, Florida 32817<br>
8  USA<br>
9  <br>
10  All rights reserved.<br>
11 
12  This Software contains proprietary trade secrets of DiSTI and may not be
13 reproduced, in whole or part, in any form, or by any means of electronic,
14 mechanical, or otherwise, without the written permission of DiSTI. Said
15 permission may be derived through the purchase of applicable DiSTI product
16 licenses which detail the distribution rights of this content and any
17 Derivative Works based on this or other copyrighted DiSTI Software.
18 
19  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
20 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
21 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
22 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
23 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
24 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
25 
26  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
27 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
28 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
29 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
30 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
31 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBLITY
32 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
33 EXCEED FIVE DOLLARS (US$5.00).
34 
35  The aforementioned terms and restrictions are governed by the laws of the
36 State of Florida and the United States of America.
37 
38 */
39 
40 #ifndef DDD_VIEWER_H_
41 #define DDD_VIEWER_H_
42 
43 #include "DDD_DataDirector.h"
44 #include "DDD_EventPublisher.h"
45 #include <sstream>
46 
47 
48 class Fl_RSO_Window;
49 
50 namespace disti
51 {
52 
53 class ComponentBase;
54 
55 /** \brief Interface for GUI that utilizes the DataDirectorViewer (ie- DataDirector Editor) */
57 {
58 public:
59  /* This function is used to let the front end define how to ask
60  * the user if they want to save their changes if at all
61  * \return True if the user wants to save changes False otherwise
62  */
63  virtual bool AskUserToSaveChanges() = 0;
64 
65  /* This function is used to let the front end define how to ask
66  * the user if they want to delete an object
67  * \param message Question string presented to the user (ie- "Are you sure you want to do this?")
68  * \return True if the user wants to continue and False otherwise
69  */
70  virtual bool ConfirmDialog(const char *message) = 0;
71 
72  /* This is to let the front dn know that the document has been
73  * modified
74  */
75  virtual void SetDocumentModified() = 0;
76 
77  /* This function is used to direct the front end to clear its UI
78  * and reset itself at a starting point
79  */
80  virtual void ClearUI() = 0;
81 
82  /* This function is used to add a component to the the main window
83  *
84  */
85  virtual void AddComponentToWindow(disti::ComponentBase * comp) = 0;
86 };
87 
88 /** \brief Viewer class. Contains a RSO Window and DataDirector instance. */
89 class DDD_EXPORT DataDirectorViewer : public XMLConfigTarget, public DDD_EventPublisher
90 {
91 public:
92 
93  /** Window Settings data */
94  typedef struct
95  {
97  {
98  CONSTANT, /**< Redraw at a constant frame rate */
99  CONTINUOUS /**< Redraw continuously (no waiting between each frame) */
100  };
101 
102  std::string title; /**< Window title */
103  unsigned int width; /**< Window width */
104  unsigned int height; /**< Window height */
105  int initialPosX; /**< Window initial position X */
106  int initialPosY; /**< Window initial position Y */
107  DrawRateType drawRateType; /**< Window draw rate type */
108  unsigned int drawRate; /**< Window draw rate (in Hz); only used when drawRateType is set to CONSTANT */
109  } Window_Settings;
110 
112  {
113  std::stringstream ourlayout;
114  std::string ourlayoutName;
115  int MwX;
116  int MwY;
117  int MwW;
118  int MwH;
119  };
120 
122 
123  /** Constructor */
125 
126  /* set the front end interface
127  * \param fe Front end instance to use
128  */
129  void SetFrontEnd(IDataDirectorViewerFrontend* fe) { frontEnd = fe; }
130 
131 
132  // Menu
133  /* Start with fresh new file
134  * \return True if the operation was sucesful and False otherwise
135  */
136  virtual bool FileNew();
137 
138  /* Close the current file
139  * \return True if the operation was succesful and False otherwise
140  */
141  virtual bool FileClose();
142 
143  /* Close the viewer
144  * \return True if the operation was succesful and False otherwise
145  */
146  virtual void FileExit();
147 
148  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
149 
150  /* XMLConfigTarget override */
151  virtual DDD_AssetBase* AddAsset(const std::string &instanceName, const std::string &className, const std::string &libName, const DDD_AttributeList& params );
152 
153  /* XMLConfigTarget override */
154  virtual void AddConnection(DDD_Connection *connection);
155 
156  /* XMLConfigTarget override */
157  WindowAttributes GetXMLWindowAttributes( unsigned int currentWindow );
158 
159  /* Notifications from GUI elements to sync with DataDirector core
160  * \param connection Pointer to the connection that we want to remove
161  */
162  void RemoveConnectionFromDirector(DDD_Connection *connection);
163 
164  /* Helper function to find a pointer to a particular asset by using its name
165  * \param assetInstance Name of the asset we are looking for
166  */
167  virtual DDD_AssetBase* FindAsset(const std::string &assetInstance);
168 
169  /* Used to obtain the list of assets within the current viewer
170  * \return DDD_AssetList reference
171  */
172  virtual DDD_AssetList& GetAssetList();
173 
174  /* Used to obtain the list of connections within the current viewer
175  * \return DDD_ConnectionList reference
176  */
177  virtual DDD_ConnectionList& GetConnectionList();
178 
179  /* Used to create an instance of an asset within this viewer
180  * \param instance Instance name for the new asset
181  * \param className Name of the class we want to instantiate
182  * \param params List of attributes used to intialize the new asset instance
183  * \return Pointer to the new DDD_AssetBase instance
184  */
185  DDD_AssetBase* CreateAsset(const std::string& instance, const std::string& className, const DDD_AttributeList& params);
186 
187  /* Specialized AddAsset method to handle the RSO template browser callback
188  * \param instanceName Name for the new asset
189  * \param params List of attributes used to initialize the new asset instance
190  */
191  void AddRSOAsset(const std::string& instanceName, const DDD_AttributeList& params);
192 
193  /* Used to create and instance of a connection within this viewer
194  *
195  */
196  DDD_Connection * NewConnection();
197 
198  /* Starts an asset within the viewer
199  * \param asset Asset to be started.
200  */
201  void StartAsset(DDD_AssetBase *asset = NULL);
202 
203  /* Stops an asset within the viewer
204  * \param asset Asset to be stopped.
205  */
206  void StopAsset(DDD_AssetBase *asset = NULL);
207 
208  /* Frees up the resources taken by the asset by the given name and
209  * publishes a corresponding event
210  * \param assetName Name of the asset that is to be deleted
211  */
212  bool RemoveAsset(const std::string& assetName);
213 
214  /* Changes the name of the asset with the given name
215  * \param assetNameOld Current name of the asset that is to be renamed
216  * \param assetNameNew New name for the asset that is to be renamed
217  * \return True if succesful and False otherwise
218  */
219  bool ChangeAssetInstanceName(const std::string& assetNameOld, const std::string& assetNameNew);
220 
221  /* Moves the specified connection to an earlier point on the list
222  * The connection order is used when eveluating data flowing through each connection.
223  * As well as used to display in the proper order vie a GUI.
224  * \param connection Pointer to the DDD_Connection instance that is to be moved
225  */
226  bool MoveConnectionUp(DDD_Connection* connection);
227 
228  /* Moves the specified connection to a later point on the list
229  * \param connection Pointer to the DDD_Connection instance that is to be moved
230  */
231  bool MoveConnectionDown(DDD_Connection* connection);
232 
233  /* Moves the specified asset to an earlier point on the list
234  * \param asset Pointer to the DDD_AssetBase instance that is to be moved
235  */
236  bool MoveAssetUp(DDD_AssetBase* asset);
237 
238  /* Moves the specified asset to a later point on the list
239  * \param asset Pointer to the DDD_Assetbase instance that is to be moved
240  */
241  bool MoveAssetDown(DDD_AssetBase* asset);
242 
243  /* If there are no assets or connections, it returns true
244  * \return True if there are no assets or connections False otherwise
245  */
246  bool EmptyConfiguration();
247 
248  /* what version of DataDirector DLL are we linked against?
249  * \return C-string containing the current version
250  */
251  static const char* Version();
252 
253  /* DDD_EventPublisher override. Notifies subscribers that an asset is being deleted.
254  * \param asset pointer to asset to be deleted
255  */
256  virtual void Dispatch_AssetDeleted(DDD_AssetBase *asset);
257 
258  /* DDD_EventPublisher override. Notifies subscribers that an asset has been shifted
259  * \param connection pointer to asset to be shifted
260  * \param direction shift direction (enum is defined in DDD_AssetShifted_Subscriber)
261  * \note Depending on the DataDirector's ability to perform the shift
262  (specifically, the asset's index within the Core's internal list),
263  this may or may not notify subscribers.
264  */
265  virtual void Dispatch_AssetShifted(DDD_AssetBase *asset, DDD_AssetShifted_Subscriber::AssetShiftDirection direction);
266 
267  /* DDD_EventPublisher override. Notifies subscribers that a connection is being deleted.
268  * \param connection pointer to connection to be deleted
269  */
270  virtual void Dispatch_ConnectionDeleted(DDD_Connection *connection);
271 
272  /* DDD_EventPublisher override. Notifies subscribers that a connection has been shifted
273  * \param connection pointer to connection to be shifted
274  * \param direction shift direction (enum is defined in DDD_ConnectionShifted_Subscriber)
275  * \note Depending on the DataDirector's ability to perform the shift
276  (specifically, the connection's index within the Core's internal list),
277  this may or may not notify subscribers.
278  */
279  virtual void Dispatch_ConnectionShifted(DDD_Connection *connection, DDD_ConnectionShifted_Subscriber::ConnectionShiftDirection direction);
280 
281  /* Load from an XML File
282  * \param filename Location of the file that needs to be loaded
283  * \param errosString Refference to an std::string to use in case of an error
284  * \return True if succesful False otherwise
285  */
286  virtual bool LoadXML(const std::string &filename, std::string& errorString);
287 
288  /* Start up the viewer
289  *
290  */
291  virtual void Startup();
292 
293  /* Stop the viewer
294  *
295  */
296  virtual void Shutdown();
297 
298  ///////////////////////////////////////////////////////////////////////////////
299 
300  /* Asset Creator Callback (for non-plugin assets)
301  * \param data Pointer to the viewer instance
302  * \param instance Name for the new asset instance
303  * \param className Name of the class that needs to be instantiated
304  * \param params List of attributes to use when creating the asset instance
305  * \param director Pointer to the data director instance
306  * \return A pointer to the new DDD_AssetBase instance
307  */
308  static DDD_AssetBase* CreateAssetCb(void *data,const std::string& instance, const std::string& className, const DDD_AttributeList& params,DDD_DataDirector *director);
309  /* Returns the current window list
310  * \return the current window list
311  */
312  RSOWindowList GetWindowList() { return _windowList; };
313 
314  /* Static callback for updating the viewer
315  * \param data Void pointer to this that gets casted to call local callback UpdateViewer().
316  */
317  static void UpdateViewerCb(void *data);
318 
319  /* Local callback for updating the viewer.
320  */
321  void UpdateViewer();
322 
323 protected:
324  /* Updates the Producer window title bar
325  *
326  */
327  virtual void UpdateProducerWindowTitle();
328 
329  /* closes current document, reverts DataDirector to blank configuration
330  *
331  */
332  void CloseDocument();
333 
334  /* Save to an XML file
335  * \param filename Name of the file to save to
336  */
337  bool SaveXML(const std::string &filename);
338 
339  /* Refreshes the DataDirector core and damages the viewer window so that it gets redrawn.
340  */
341  void RefreshDirector();
342 
343  /* Sets the frame rate for given RSO Window
344  * \param fps Desired frames per second.
345  * \param windowIndex Index of RSO Window (only required if there are multiple RSO windows).
346  */
347  void SetFrameRate(int fps, unsigned int windowIndex=0);
348 
349 protected:
350  DDD_DataDirector *_director; /**< DataDirector instance */
351 
352  bool _documentOpen; /**< Is there a document (configuration) currently loaded? */
353  bool _documentModified; /**< Is the current document modified since last save?*/
354  std::string _openFileName; /**< Filename of current file (if it hasn't been created or none opened, it will be empty) */
355  std::string _windowLabel; /**< String that gets displayed on top window */
356  bool _editorRunning; /**< Flag for keeping the Startup/Shutdown methods from getting abused */
357  RSOWindowList _windowList; /**< Contains a list of all known windows */
358 
359  /** GUI instance for this viewer, if applicable.
360  * \warning This may be NULL on some configurations. Be sure to check this before using it.
361  */
363 
364  Fl_RSO_Window *_rsoWindow; /**< RSO Window instance */
365 };
366 
367 
368 #define FPS_TO_MICROSECONDS(x) (1000000.0/(x)) /**< Simple macro to convert from Hz to microsec */
369 
370 
371 } // end namespace disti
372 #endif
373 
std::string title
Definition: DDD_Viewer.h:102
DrawRateType
Definition: DDD_Viewer.h:96
std::string _windowLabel
Definition: DDD_Viewer.h:355
A virtual interface class for all DataDirector assets.
Definition: DDD_AssetBase.h:115
bool _documentModified
Definition: DDD_Viewer.h:353
unsigned int width
Definition: DDD_Viewer.h:103
unsigned int drawRate
Definition: DDD_Viewer.h:108
DDD_DataDirector * _director
Definition: DDD_Viewer.h:350
int initialPosX
Definition: DDD_Viewer.h:105
The DDD_AttributeList class. Maintains a list of Data Director attributes.
Definition: DDD_AttributeList.h:52
The DDD_AssetList class. Maintains a list of Data Director assets.
Definition: DDD_AssetList.h:51
Interface for GUI that utilizes the DataDirectorViewer (ie- DataDirector Editor)
Definition: DDD_Viewer.h:56
std::string _openFileName
Definition: DDD_Viewer.h:354
AssetShiftDirection
Definition: DDD_EventSubscriber.h:142
DDD_DataDirector. Main interface to DataDirector core that encapsulates all Assets, Connections and core logic.
Definition: DDD_DataDirector.h:78
Fl_RSO_Window. FLTK/OpenGL window that displays RSO Assets.
Definition: Fl_RSO_Window.H:76
unsigned int height
Definition: DDD_Viewer.h:104
ConnectionShiftDirection
Definition: DDD_EventSubscriber.h:231
IDataDirectorViewerFrontend * frontEnd
Definition: DDD_Viewer.h:362
RSOWindowList _windowList
Definition: DDD_Viewer.h:357
Fl_RSO_Window * _rsoWindow
Definition: DDD_Viewer.h:364
Viewer class. Contains a RSO Window and DataDirector instance.
Definition: DDD_Viewer.h:89
int initialPosY
Definition: DDD_Viewer.h:106
The DDD_Connection class. Base class for connections between assets.
Definition: DDD_Connection.h:54
DrawRateType drawRateType
Definition: DDD_Viewer.h:107
The DDD_EventPublisher class. Central class for publishing events. Contains all logic for registering...
Definition: DDD_EventPublisher.h:56
Definition: DDD_XMLConfigMgr.h:63
bool _editorRunning
Definition: DDD_Viewer.h:356
bool _documentOpen
Definition: DDD_Viewer.h:352
The DDD_EventPublisher class.
Abstract base class for any object that uses DDD_XMLConfigMgr.
Definition: DDD_XMLConfigMgr.h:74
Definition: AttributeChangedEmitter.h:46