Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
darwin.h
1 /*****************************************************************************
2 ** DARWIN: A FRAMEWORK FOR MACHINE LEARNING RESEARCH AND DEVELOPMENT
3 ** Distributed under the terms of the BSD license (see the LICENSE file)
4 ** Copyright (c) 2007-2015, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: darwin.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 ** DESCRIPTION:
11 ** Darwin GUI for creating and evaluating data flow algorithms.
12 **
13 *****************************************************************************/
14 
15 #pragma once
16 
17 #include <string>
18 #include <vector>
19 #include <map>
20 
21 #include "wx/wx.h"
22 #include "wx/glcanvas.h"
23 #include "wx/utils.h"
24 
25 #include "drwnBase.h"
26 #include "drwnEngine.h"
27 #include "drwnNodes.h"
28 
29 #include "drwnStatusBar.h"
30 
31 // wxWidgets Event Constants --------------------------------------------------
32 
33 // MainCanvas messages
34 enum {
35  // node popup
36  NODE_POPUP_SET_NAME = wxID_HIGHEST + 100,
37  NODE_POPUP_PROPERTIES = wxID_HIGHEST + 110,
38  NODE_POPUP_SHOWHIDE = wxID_HIGHEST + 120,
39  NODE_POPUP_EVALUATE = wxID_HIGHEST + 200,
40  NODE_POPUP_UPDATE = wxID_HIGHEST + 210,
41  NODE_POPUP_PROPBACK = wxID_HIGHEST + 220,
42  NODE_POPUP_RESETPARAMS = wxID_HIGHEST + 230,
43  NODE_POPUP_INITPARAMS = wxID_HIGHEST + 240,
44  NODE_POPUP_INPORT_BASE = wxID_HIGHEST + 400,
45  NODE_POPUP_OUTPORT_BASE = wxID_HIGHEST + 500,
46  NODE_POPUP_DISCONNECT = wxID_HIGHEST + 600,
47  NODE_POPUP_DELETE = wxID_HIGHEST + 300,
48 
49  // network popup
50  POPUP_SET_TITLE = wxID_HIGHEST + 800,
51  POPUP_NODE_INSERT_BASE = wxID_HIGHEST + 1000
52 };
53 
54 // MainWindow messages
55 enum
56 {
57  FILE_NEW = wxID_NEW,
58  FILE_OPEN = wxID_OPEN,
59  FILE_SAVE = wxID_SAVE,
60  FILE_SAVEAS = wxID_SAVEAS,
61  FILE_CLOSE = wxID_CLOSE,
62  FILE_CLOSEALL = wxID_HIGHEST + 21,
63  FILE_EXPORT = wxID_HIGHEST + 30,
64  FILE_EXPORT_HTML = wxID_HIGHEST + 31,
65  FILE_EXPORT_CODE = wxID_HIGHEST + 32,
66  FILE_EXPORT_SCRIPT = wxID_HIGHEST + 33,
67  FILE_EXIT = wxID_EXIT,
68 
69  EDIT_UNDO = wxID_UNDO,
70  EDIT_REDO = wxID_REDO,
71  EDIT_CUT = wxID_CUT,
72  EDIT_COPY = wxID_COPY,
73  EDIT_PASTE = wxID_PASTE,
74  EDIT_DELETE = wxID_DELETE,
75  EDIT_FIND = wxID_FIND,
76  EDIT_SELECTALL = wxID_SELECTALL,
77  EDIT_DESELECTALL = wxID_HIGHEST + 131,
78 
79  NETWORK_RESET = wxID_HIGHEST + 200,
80  NETWORK_EVALUATE = wxID_HIGHEST + 210,
81  NETWORK_UPDATE = wxID_HIGHEST + 220,
82  NETWORK_BACKPROP = wxID_HIGHEST + 230,
83  NETWORK_INITPARAMS = wxID_HIGHEST + 240,
84  NETWORK_GRIDSNAP = wxID_HIGHEST + 260,
85 
86  DATABASE_CONNECT = wxID_HIGHEST + 300,
87  DATABASE_VIEW_TABLES = wxID_HIGHEST + 301,
88  DATABASE_VIEW_INSTANCES = wxID_HIGHEST + 302,
89  DATABASE_IMPORT_COLOURS = wxID_HIGHEST + 310,
90  DATABASE_RANDOMIZE_COLOURS = wxID_HIGHEST + 312,
91  DATABASE_FLUSH_CACHE = wxID_HIGHEST + 350,
92 
93  OPTIONS_DISPLAY_VERBOSE = wxID_HIGHEST + 400,
94  OPTIONS_DISPLAY_MESSAGE = wxID_HIGHEST + 401,
95  OPTIONS_DISPLAY_WARNING = wxID_HIGHEST + 402,
96  OPTIONS_BEEP = wxID_HIGHEST + 410,
97  OPTIONS_CLEAR_LOG = wxID_HIGHEST + 420,
98  OPTIONS_SAVE_LOG = wxID_HIGHEST + 421,
99  OPTIONS_TILE_WINDOWS = wxID_HIGHEST + 430,
100 
101  WINDOW_MENU_BASE = wxID_HIGHEST + 500,
102 
103  HELP_DRWN_CONTENTS = wxID_HELP_CONTENTS,
104  HELP_RELEASE_NOTES = wxID_HIGHEST + 810,
105  HELP_ABOUT = wxID_ABOUT
106 };
107 
108 // Mouse Modes ----------------------------------------------------------------
109 
110 typedef enum {
111  MM_NONE, MM_DRAGGING, MM_SELECTING, MM_SELECTING_NOERASE,
112  MM_CONNECTING_INPUT, MM_CONNECTING_OUTPUT
113 } TMouseMode;
114 
115 // MainCanvas Class -----------------------------------------------------------
116 // This is required under Linux because wxFrame doesn't get keyboard focus
117 // without a child window.
118 
119 class MainCanvas : public wxScrolledWindow
120 {
121  friend class MainWindow;
122 
123  public:
124  MainCanvas(wxWindow *parent,
125  wxWindowID id = wxID_ANY,
126  const wxPoint& pos = wxDefaultPosition,
127  const wxSize& size = wxDefaultSize,
128  long style = wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER | wxWANTS_CHARS,
129  const wxString& name = wxPanelNameStr);
130  ~MainCanvas();
131 
132  // event handling
133  void on_erase_background(wxEraseEvent &event);
134  void on_paint(wxPaintEvent &event);
135  void on_size(wxSizeEvent &event);
136  void on_key(wxKeyEvent &event);
137  void on_mouse(wxMouseEvent &event);
138  void on_popup_menu(wxCommandEvent &event);
139 
140  // setting and getting options
141  const bool& snapToGrid() const { return _bSnapToGrid; }
142  bool& snapToGrid() { Refresh(false); return _bSnapToGrid; }
143 
144  void selectNodesInRegion(int x, int y, int w, int h);
145  void selectAllNodes();
146  void deselectAllNodes();
147 
148  protected:
149  void undoableAction();
150 
151  void updateImageBuffer();
152  void updateStatusBar();
153 
154  int findNodeAtLocation(int x, int y) const;
155  void updatePortSubMenu(const drwnNode *node);
156 
157  protected:
158  // algorithm state
159  string _filename;
160  drwnGraph *_graph;
161  drwnNode *_activeNode;
162  drwnDataPort *_activePort;
163  set<drwnNode *> _selectedNodes;
164 
165  // mouse management
166  bool _bSnapToGrid;
167  TMouseMode _mouseMode;
168  wxPoint _mousePoint;
169  wxPoint _lastMousePoint;
170  wxPoint _buttonDownPoint;
171 
172  // gui elements/state
173  static int _creationCount;
174  wxMenu *_nodePopupMenu;
175  wxMenuItem *_portSubMenuItem;
176  wxMenu *_connectPopupMenu;
177  wxMenu *_newNodePopupMenu;
178 
179  DECLARE_EVENT_TABLE()
180 };
181 
182 // MainWindow Class -----------------------------------------------------------
183 
184 class DarwinApp;
185 
186 class MainWindow : public wxFrame
187 {
188  friend class MainCanvas;
189  friend class DarwinApp;
190 
191  public:
192  MainWindow(wxWindow* parent,
193  wxWindowID id,
194  const wxString& title,
195  const wxPoint& pos = wxDefaultPosition,
196  const wxSize& size = wxDefaultSize,
197  long style = wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER | wxWANTS_CHARS);
198  ~MainWindow();
199 
200  // event callbacks
201  void on_idle(wxIdleEvent& event);
202  void on_close(wxCloseEvent& event);
203  void on_file_menu(wxCommandEvent& event);
204  void on_edit_menu(wxCommandEvent& event);
205  void on_network_menu(wxCommandEvent& event);
206  void on_database_menu(wxCommandEvent& event);
207  void on_options_menu(wxCommandEvent& event);
208  void on_window_menu(wxCommandEvent& event);
209  void on_help_menu(wxCommandEvent& event);
210 
211  // status
212  void logMessage(const char *msg, const wxTextAttr style = wxTextAttr(*wxBLACK));
213  void updateProgress(const char *status, double progress);
214 
215  protected:
216  void updateGUIElements();
217  bool openGraphFile(const char *filename);
218  void clearCopyBuffer();
219 
220  protected:
221  drwnStatusBar *_statusBar;
222  wxSplitterWindow *_splitterWnd;
223  vector<MainCanvas *> _canvases;
224  MainCanvas *_activeCanvas;
225  wxTextCtrl *_sessionLog;
226  wxMenu *_windowMenu;
227 
228  set<drwnNode *> _copyBuffer;
229 
230  DECLARE_EVENT_TABLE()
231 };
232 
233 // Darwin Application ---------------------------------------------------------
234 
235 class DarwinApp : public wxApp
236 {
237  public:
238  bool OnInit();
239  int OnExit();
240 };
241 
242 // Global Variables -----------------------------------------------------------
243 
244 extern MainWindow *gMainWindow;
245 
246 
Definition: drwnStatusBar.h:60
Definition: darwin.h:235
Definition: darwin.h:119
Definition: darwin.h:186