]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMMainFrame.cpp
new model classes
[crea.git] / lib / creaDevManagerLib / wxCDMMainFrame.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Sant�)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ 
26 */ 
27
28
29 #include "wxCDMMainFrame.h"
30
31 #include <iostream>
32
33 #include <creaWx.h>
34 #include "CDMUtilities.h"
35
36 #include "creaDevManagerIds.h"
37 #include "wxCDMMainDescriptionPanel.h"
38 #include "wxCDMProjectActionsPanel.h"
39 #include "wxCDMNewProjectDialog.h"
40
41
42 BEGIN_EVENT_TABLE(wxCDMMainFrame, wxFrame)
43   EVT_MENU(ID_MENU_NEW_PROJECT, wxCDMMainFrame::OnMenuNewProject)
44   EVT_MENU(ID_MENU_OPEN_PROJECT, wxCDMMainFrame::OnMenuOpenProject)
45   EVT_MENU(ID_MENU_OPEN_RECENT, wxCDMMainFrame::OnMenuOpenRecent)
46   EVT_MENU(ID_MENU_CLOSE_PROJECT, wxCDMMainFrame::OnMenuCloseProject)
47   EVT_MENU(ID_MENU_CLOSE_ALL_PROJECTS, wxCDMMainFrame::OnMenuCloseAllProjects)
48   EVT_MENU(ID_MENU_EXPORT_HIERARCHY, wxCDMMainFrame::OnMenuExportHierarchy)
49   EVT_MENU(ID_MENU_EXIT, wxCDMMainFrame::OnMenuExit)
50   EVT_MENU(ID_MENU_REFRESH_PROJECT, wxCDMMainFrame::OnMenuRefreshProject)
51   EVT_MENU(ID_MENU_CUT, wxCDMMainFrame::OnMenuMenuCut)
52   EVT_MENU(ID_MENU_COPY, wxCDMMainFrame::OnMenuMenuCopy)
53   EVT_MENU(ID_MENU_PASTE, wxCDMMainFrame::OnMenuMenuPaste)
54   EVT_MENU(ID_MENU_DELETE, wxCDMMainFrame::OnMenuMenuDelete)
55   EVT_MENU(ID_MENU_SELECT_ALL, wxCDMMainFrame::OnMenuSelectAll)
56   EVT_MENU(ID_MENU_SELECT_NONE, wxCDMMainFrame::OnMenuSelectNone)
57   EVT_MENU(ID_MENU_EVENT_LOG, wxCDMMainFrame::OnMenuEventLog)
58   EVT_MENU(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxCDMMainFrame::OnMenuBBTKGraphicalEditor)
59   EVT_MENU(ID_MENU_MINITOOLS, wxCDMMainFrame::OnMenuMiniTools)
60   EVT_MENU(ID_MENU_CODE_EDITOR, wxCDMMainFrame::OnMenuCodeEditor)
61   EVT_MENU(ID_MENU_COMMAND_LINE, wxCDMMainFrame::OnMenuCommandLine)
62   EVT_MENU(ID_MENU_HELP, wxCDMMainFrame::OnMenuHelp)
63   EVT_MENU(ID_MENU_REPORT_BUG, wxCDMMainFrame::OnMenuReportBug)
64   EVT_MENU(ID_MENU_ABOUT_CREADEVMANAGER, wxCDMMainFrame::OnMenuAboutCreaDevManager)
65   EVT_MENU(ID_MENU_ABOUT_CREATIS, wxCDMMainFrame::OnMenuAboutCreatis)
66   EVT_BUTTON(ID_BUTTON_NEWPROJECT, wxCDMMainFrame::OnMenuNewProject)
67   EVT_BUTTON(ID_BUTTON_OPENPROJECT, wxCDMMainFrame::OnMenuOpenProject)
68 END_EVENT_TABLE()
69
70 wxCDMMainFrame::wxCDMMainFrame(
71   wxWindow* parent,
72   wxWindowID id,
73   const wxString& caption,
74   const wxPoint& pos,
75   const wxSize& size,
76   long style
77 )
78 {
79   Create(parent, id, caption, pos, size, style);
80 }
81
82 wxCDMMainFrame::~wxCDMMainFrame()
83 {
84   auiManager.UnInit();
85 }
86
87 bool wxCDMMainFrame::Create(
88   wxWindow* parent,
89   wxWindowID id,
90   const wxString& caption,
91   const wxPoint& pos,
92   const wxSize& size,
93   long style
94 )
95 {
96   wxFrame::Create(parent, id, caption, pos, size, style);
97   this->model = new modelCDMMain();
98   CreateMenus();
99   CreateControls();
100   return TRUE;
101 }
102
103 void wxCDMMainFrame::CreateMenus()
104 {
105   wxMenuBar* menuBar = new wxMenuBar;
106
107   //FileMenu
108   menu_File = new wxMenu();
109   menu_File->Append(ID_MENU_NEW_PROJECT, wxT("&New Project..."));
110   menu_File->Append(ID_MENU_OPEN_PROJECT, wxT("&Open Project..."));
111   menu_File->Append(ID_MENU_OPEN_RECENT, wxT("Open &Recent"));
112   menu_File->AppendSeparator();
113   menu_File->Append(ID_MENU_CLOSE_PROJECT, wxT("&Close Project"));
114   menu_File->Append(ID_MENU_CLOSE_ALL_PROJECTS, wxT("C&lose All Projects"));
115   menu_File->AppendSeparator();
116   menu_File->Append(ID_MENU_EXPORT_HIERARCHY, wxT("&Export Project Hierarchy..."));
117   menu_File->AppendSeparator();
118   menu_File->Append(ID_MENU_EXIT, wxT("E&xit"));
119
120   menuBar->Append(menu_File, wxT("&File"));
121
122   //EditMenu
123   menu_Edit = new wxMenu();
124   menu_Edit->Append(ID_MENU_REFRESH_PROJECT, wxT("&Refresh Project"));
125   menu_Edit->AppendSeparator();
126   menu_Edit->Append(ID_MENU_CUT, wxT("Cu&t"));
127   menu_Edit->Append(ID_MENU_COPY, wxT("&Copy"));
128   menu_Edit->Append(ID_MENU_PASTE, wxT("&Paste"));
129   menu_Edit->AppendSeparator();
130   menu_Edit->Append(ID_MENU_DELETE, wxT("&Delete"));
131   menu_Edit->Append(ID_MENU_SELECT_ALL, wxT("Select &All"));
132   menu_Edit->Append(ID_MENU_SELECT_NONE, wxT("Ca&ncel Selection"));
133
134   menuBar->Append(menu_Edit, wxT("&Edit"));
135
136   //ToolsMenu
137   menu_Tools = new wxMenu();
138   menu_Tools->Append(ID_MENU_EVENT_LOG, wxT("Event &Log"));
139   menu_Tools->Append(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxT("BBTK &Graphical Editor"));
140   menu_Tools->Append(ID_MENU_MINITOOLS, wxT("&MiniTools"));
141   menu_Tools->Append(ID_MENU_CODE_EDITOR, wxT("&Code Editor"));
142   menu_Tools->Append(ID_MENU_COMMAND_LINE, wxT("&Command Line"));
143
144   menuBar->Append(menu_Tools, wxT("&Tools"));
145
146   //HelpMenu
147   menu_Help = new wxMenu();
148   menu_Help->Append(ID_MENU_HELP, wxT("&Help"));
149   menu_Help->Append(ID_MENU_REPORT_BUG, wxT("Report &Bug"));
150   menu_Help->Append(ID_MENU_ABOUT_CREADEVMANAGER, wxT("&About CreaDevManager"));
151   menu_Help->Append(ID_MENU_ABOUT_CREATIS, wxT("A&bout CREATIS"));
152
153   menuBar->Append(menu_Help, wxT("&Help"));
154
155   //Set Bar
156   SetMenuBar(menuBar);
157
158   wxStatusBar* statusBar = new wxStatusBar(this, ID_STATUS_BAR, wxST_SIZEGRIP);
159   statusBar->SetFieldsCount(1);
160   SetStatusBar(statusBar);
161
162 }
163
164 void wxCDMMainFrame::CreateControls()
165 {
166
167   auiManager.SetManagedWindow(this);
168
169
170   tree_Projects = new wxCDMProjectsTreeCtrl(
171     this,
172     ID_TREE_PROJECTS,
173     wxDefaultPosition,
174     wxSize(300,400),
175     wxTR_HAS_BUTTONS | wxTR_AQUA_BUTTONS
176   );
177   tree_Projects->SetMinSize(wxSize(200,200));
178
179   panel_Properties = new wxCDMMainDescriptionPanel(
180     this,
181     ID_WINDOW_PROPERTIES,
182     wxT("Description Panel"),
183     wxDefaultPosition,
184     wxSize(300, 400),
185     0
186   );
187
188
189
190   panel_ProjectActions = new wxCDMProjectActionsPanel(
191     this,
192     ID_WINDOW_PROJ_ACTIONS,
193     wxT("Project Actions Panel"),
194     wxDefaultPosition,
195     wxSize(600,200),
196     0
197   );
198   panel_ProjectActions->SetMinSize(wxSize(500, 100));
199
200   auiManager.AddPane(tree_Projects, wxLEFT, wxT("Projects Tree"));
201   auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions"));
202   auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
203
204   auiManager.Update();
205   auiManager.GetPane(tree_Projects).CloseButton(false).MaximizeButton(true);
206   auiManager.GetPane(panel_Properties).CloseButton(false);
207 }
208
209 //Event Handlers
210 //File menu
211 void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
212 {
213   wxCDMNewProjectDialog* dialog = new wxCDMNewProjectDialog(this);
214   long userResponse;
215   userResponse = dialog->ShowModal();
216
217   if(userResponse == wxID_FORWARD)
218   {
219     //TODO createProject
220     std::cerr << "should create Project here" << std::endl;
221     //tree_Projects->BuildTree(this->model->GetActiveProjects());
222   }
223
224   event.Skip();
225 }
226 void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
227 {
228   long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
229   wxDirDialog* FD = new wxDirDialog(this, wxT("Select the project directory"), wxT(""), style);
230   long userResponse;
231   userResponse = FD->ShowModal();
232   if(userResponse == wxID_OK)
233   {
234     std::cout << "selection: " << crea::wx2std (FD->GetPath()) << std::endl;
235     std::string path = CDMUtilities::fixPath(crea::wx2std (FD->GetPath()));
236     std::cout << "fixed selection: " << path << std::endl;
237     std::string* result;
238     if (!this->model->OpenProject(path, result))
239     {
240       wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR);
241       event.Skip();
242     };
243     //TODO: Create tree control
244     //((wxCreaDevManagerTreeCtrl*)tree_Projects)->BuildTree(controller->GetActiveProjects());
245
246     auiManager.Update();
247   }
248
249   event.Skip();
250 }
251 void wxCDMMainFrame::OnMenuOpenRecent(wxCommandEvent& event)
252 {
253   std::cerr << "Event OnMenuOpenRecent not implemented" << std::endl;
254   event.Skip();
255 }
256 void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event)
257 {
258   std::cerr << "Event OnMenuCloseProject not implemented" << std::endl;
259   event.Skip();
260 }
261 void wxCDMMainFrame::OnMenuCloseAllProjects(wxCommandEvent& event)
262 {
263   std::cerr << "Event OnMenuCloseAllProjects not implemented" << std::endl;
264   event.Skip();
265 }
266 void wxCDMMainFrame::OnMenuExportHierarchy(wxCommandEvent& event)
267 {
268   std::cerr << "Event OnMenuExportHierarchy not implemented" << std::endl;
269   event.Skip();
270 }
271 void wxCDMMainFrame::OnMenuExit(wxCommandEvent& event)
272 {
273   std::cout << "Closing CreaDevManager..." << std::endl;
274   Close();
275   event.Skip();
276 }
277
278 //Edit Menu
279 void wxCDMMainFrame::OnMenuRefreshProject(wxCommandEvent& event)
280 {
281   std::cerr << "Event OnMenuRefreshProject not implemented" << std::endl;
282   event.Skip();
283 }
284 void wxCDMMainFrame::OnMenuMenuCut(wxCommandEvent& event)
285 {
286   std::cerr << "Event OnMenuMenuCut not implemented" << std::endl;
287   event.Skip();
288 }
289 void wxCDMMainFrame::OnMenuMenuCopy(wxCommandEvent& event)
290 {
291   std::cerr << "Event OnMenuMenuCopy not implemented" << std::endl;
292   event.Skip();
293 }
294 void wxCDMMainFrame::OnMenuMenuPaste(wxCommandEvent& event)
295 {
296   std::cerr << "Event OnMenuMenuPaste not implemented" << std::endl;
297   event.Skip();
298 }
299 void wxCDMMainFrame::OnMenuMenuDelete(wxCommandEvent& event)
300 {
301   std::cerr << "Event OnMenuMenuDelete not implemented" << std::endl;
302   event.Skip();
303 }
304 void wxCDMMainFrame::OnMenuSelectAll(wxCommandEvent& event)
305 {
306   std::cerr << "Event OnMenuSelectAll not implemented" << std::endl;
307   event.Skip();
308 }
309 void wxCDMMainFrame::OnMenuSelectNone(wxCommandEvent& event)
310 {
311   std::cerr << "Event OnMenuSelectNone not implemented" << std::endl;
312   event.Skip();
313 }
314
315 //Tools Menu
316 void wxCDMMainFrame::OnMenuEventLog(wxCommandEvent& event)
317 {
318   std::cerr << "Event OnMenuEventLog not implemented" << std::endl;
319   event.Skip();
320 }
321 void wxCDMMainFrame::OnMenuBBTKGraphicalEditor(wxCommandEvent& event)
322 {
323   std::cerr << "Event OnMenuBBTKGraphicalEditor not implemented" << std::endl;
324   event.Skip();
325 }
326 void wxCDMMainFrame::OnMenuMiniTools(wxCommandEvent& event)
327 {
328   std::cerr << "Event OnMenuMiniTools not implemented" << std::endl;
329   event.Skip();
330 }
331 void wxCDMMainFrame::OnMenuCodeEditor(wxCommandEvent& event)
332 {
333   std::cerr << "Event OnMenuCodeEditor not implemented" << std::endl;
334   event.Skip();
335 }
336 void wxCDMMainFrame::OnMenuCommandLine(wxCommandEvent& event)
337 {
338   std::cerr << "Event OnMenuCommandLine not implemented" << std::endl;
339   event.Skip();
340 }
341
342 //Help Menu
343 void wxCDMMainFrame::OnMenuHelp(wxCommandEvent& event)
344 {
345   std::cerr << "Event OnMenuHelp not implemented" << std::endl;
346   event.Skip();
347 }
348 void wxCDMMainFrame::OnMenuReportBug(wxCommandEvent& event)
349 {
350   std::cerr << "Event OnMenuReportBug not implemented" << std::endl;
351   event.Skip();
352 }
353 void wxCDMMainFrame::OnMenuAboutCreaDevManager(wxCommandEvent& event)
354 {
355   std::cerr << "Event OnMenuAboutCreaDevManager not implemented" << std::endl;
356   event.Skip();
357 }
358 void wxCDMMainFrame::OnMenuAboutCreatis(wxCommandEvent& event)
359 {
360   std::cerr << "Event OnMenuAboutCreatis not implemented" << std::endl;
361   event.Skip();
362 }