]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMMainFrame.cpp
Feature #1711
[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 "wx/treectrl.h"
35 #include "CDMUtilities.h"
36
37 #include "creaDevManagerIds.h"
38 #include "wxCDMMainDescriptionPanel.h"
39 #include "wxCDMProjectDescriptionPanel.h"
40 #include "wxCDMProjectActionsPanel.h"
41 #include "wxCDMNewProjectDialog.h"
42
43
44 BEGIN_EVENT_TABLE(wxCDMMainFrame, wxFrame)
45 EVT_MENU(ID_MENU_NEW_PROJECT, wxCDMMainFrame::OnMenuNewProject)
46 EVT_MENU(ID_MENU_OPEN_PROJECT, wxCDMMainFrame::OnMenuOpenProject)
47 EVT_MENU(ID_MENU_OPEN_RECENT, wxCDMMainFrame::OnMenuOpenRecent)
48 EVT_MENU(ID_MENU_CLOSE_PROJECT, wxCDMMainFrame::OnMenuCloseProject)
49 EVT_MENU(ID_MENU_CLOSE_ALL_PROJECTS, wxCDMMainFrame::OnMenuCloseAllProjects)
50 EVT_MENU(ID_MENU_EXPORT_HIERARCHY, wxCDMMainFrame::OnMenuExportHierarchy)
51 EVT_MENU(ID_MENU_EXIT, wxCDMMainFrame::OnMenuExit)
52 EVT_MENU(ID_MENU_REFRESH_PROJECT, wxCDMMainFrame::OnMenuRefreshProject)
53 EVT_MENU(ID_MENU_CUT, wxCDMMainFrame::OnMenuMenuCut)
54 EVT_MENU(ID_MENU_COPY, wxCDMMainFrame::OnMenuMenuCopy)
55 EVT_MENU(ID_MENU_PASTE, wxCDMMainFrame::OnMenuMenuPaste)
56 EVT_MENU(ID_MENU_DELETE, wxCDMMainFrame::OnMenuMenuDelete)
57 EVT_MENU(ID_MENU_SELECT_ALL, wxCDMMainFrame::OnMenuSelectAll)
58 EVT_MENU(ID_MENU_SELECT_NONE, wxCDMMainFrame::OnMenuSelectNone)
59 EVT_MENU(ID_MENU_EVENT_LOG, wxCDMMainFrame::OnMenuEventLog)
60 EVT_MENU(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxCDMMainFrame::OnMenuBBTKGraphicalEditor)
61 EVT_MENU(ID_MENU_MINITOOLS, wxCDMMainFrame::OnMenuMiniTools)
62 EVT_MENU(ID_MENU_CODE_EDITOR, wxCDMMainFrame::OnMenuCodeEditor)
63 EVT_MENU(ID_MENU_COMMAND_LINE, wxCDMMainFrame::OnMenuCommandLine)
64 EVT_MENU(ID_MENU_HELP, wxCDMMainFrame::OnMenuHelp)
65 EVT_MENU(ID_MENU_REPORT_BUG, wxCDMMainFrame::OnMenuReportBug)
66 EVT_MENU(ID_MENU_ABOUT_CREADEVMANAGER, wxCDMMainFrame::OnMenuAboutCreaDevManager)
67 EVT_MENU(ID_MENU_ABOUT_CREATIS, wxCDMMainFrame::OnMenuAboutCreatis)
68 EVT_BUTTON(ID_BUTTON_NEWPROJECT, wxCDMMainFrame::OnMenuNewProject)
69 EVT_BUTTON(ID_BUTTON_OPENPROJECT, wxCDMMainFrame::OnMenuOpenProject)
70 EVT_TREE_SEL_CHANGED(ID_TREE_PROJECTS, wxCDMMainFrame::OnTreeSelectionChanged)
71 END_EVENT_TABLE()
72
73 wxCDMMainFrame::wxCDMMainFrame(
74     wxWindow* parent,
75     wxWindowID id,
76     const wxString& caption,
77     const wxPoint& pos,
78     const wxSize& size,
79     long style
80 )
81 {
82   Create(parent, id, caption, pos, size, style);
83 }
84
85 wxCDMMainFrame::~wxCDMMainFrame()
86 {
87   auiManager.UnInit();
88 }
89
90 bool wxCDMMainFrame::Create(
91     wxWindow* parent,
92     wxWindowID id,
93     const wxString& caption,
94     const wxPoint& pos,
95     const wxSize& size,
96     long style
97 )
98 {
99   wxFrame::Create(parent, id, caption, pos, size, style);
100   this->model = new modelCDMMain();
101   CreateMenus();
102   CreateControls();
103   return TRUE;
104 }
105
106 void wxCDMMainFrame::CreateMenus()
107 {
108   wxMenuBar* menuBar = new wxMenuBar;
109
110   //FileMenu
111   menu_File = new wxMenu();
112   menu_File->Append(ID_MENU_NEW_PROJECT, wxT("&New Project..."));
113   menu_File->Append(ID_MENU_OPEN_PROJECT, wxT("&Open Project..."));
114   menu_File->Append(ID_MENU_OPEN_RECENT, wxT("Open &Recent"));
115   menu_File->AppendSeparator();
116   menu_File->Append(ID_MENU_CLOSE_PROJECT, wxT("&Close Project"));
117   menu_File->Append(ID_MENU_CLOSE_ALL_PROJECTS, wxT("C&lose All Projects"));
118   menu_File->AppendSeparator();
119   menu_File->Append(ID_MENU_EXPORT_HIERARCHY, wxT("&Export Project Hierarchy..."));
120   menu_File->AppendSeparator();
121   menu_File->Append(ID_MENU_EXIT, wxT("E&xit"));
122
123   menuBar->Append(menu_File, wxT("&File"));
124
125   //EditMenu
126   menu_Edit = new wxMenu();
127   menu_Edit->Append(ID_MENU_REFRESH_PROJECT, wxT("&Refresh Project"));
128   menu_Edit->AppendSeparator();
129   menu_Edit->Append(ID_MENU_CUT, wxT("Cu&t"));
130   menu_Edit->Append(ID_MENU_COPY, wxT("&Copy"));
131   menu_Edit->Append(ID_MENU_PASTE, wxT("&Paste"));
132   menu_Edit->AppendSeparator();
133   menu_Edit->Append(ID_MENU_DELETE, wxT("&Delete"));
134   menu_Edit->Append(ID_MENU_SELECT_ALL, wxT("Select &All"));
135   menu_Edit->Append(ID_MENU_SELECT_NONE, wxT("Ca&ncel Selection"));
136
137   menuBar->Append(menu_Edit, wxT("&Edit"));
138
139   //ToolsMenu
140   menu_Tools = new wxMenu();
141   menu_Tools->Append(ID_MENU_EVENT_LOG, wxT("Event &Log"));
142   menu_Tools->Append(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxT("BBTK &Graphical Editor"));
143   menu_Tools->Append(ID_MENU_MINITOOLS, wxT("&MiniTools"));
144   menu_Tools->Append(ID_MENU_CODE_EDITOR, wxT("&Code Editor"));
145   menu_Tools->Append(ID_MENU_COMMAND_LINE, wxT("&Command Line"));
146
147   menuBar->Append(menu_Tools, wxT("&Tools"));
148
149   //HelpMenu
150   menu_Help = new wxMenu();
151   menu_Help->Append(ID_MENU_HELP, wxT("&Help"));
152   menu_Help->Append(ID_MENU_REPORT_BUG, wxT("Report &Bug"));
153   menu_Help->Append(ID_MENU_ABOUT_CREADEVMANAGER, wxT("&About CreaDevManager"));
154   menu_Help->Append(ID_MENU_ABOUT_CREATIS, wxT("A&bout CREATIS"));
155
156   menuBar->Append(menu_Help, wxT("&Help"));
157
158   //Set Bar
159   SetMenuBar(menuBar);
160
161   wxStatusBar* statusBar = new wxStatusBar(this, ID_STATUS_BAR, wxST_SIZEGRIP);
162   statusBar->SetFieldsCount(1);
163   SetStatusBar(statusBar);
164
165 }
166
167 void wxCDMMainFrame::CreateControls()
168 {
169
170   auiManager.SetManagedWindow(this);
171
172
173   tree_Projects = new wxCDMProjectsTreeCtrl(
174       this,
175       ID_TREE_PROJECTS,
176       wxDefaultPosition,
177       wxSize(300,400),
178       wxTR_HAS_BUTTONS | wxTR_AQUA_BUTTONS
179   );
180   tree_Projects->SetMinSize(wxSize(200,200));
181
182   panel_Properties = new wxCDMMainDescriptionPanel(
183       this,
184       ID_WINDOW_PROPERTIES,
185       wxT("Description Panel"),
186       wxDefaultPosition,
187       wxSize(300, 400),
188       0
189   );
190
191
192
193
194
195   auiManager.AddPane(tree_Projects, wxLEFT, wxT("Projects Tree"));
196   auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
197
198   auiManager.Update();
199   auiManager.GetPane(tree_Projects).CloseButton(false).MaximizeButton(true);
200 }
201
202 //Event Handlers
203 //File menu
204 void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
205 {
206   std::string* result;
207
208   wxCDMNewProjectDialog* dialog = new wxCDMNewProjectDialog(this);
209   long userResponse;
210   userResponse = dialog->ShowModal();
211
212   if(userResponse == wxID_FORWARD)
213     {
214       //create project
215       if(this->model->GetProject() != NULL)
216         {
217           if(!this->model->CloseProject(result))
218             {
219               std::cout << "error closing project: " << *result << std::endl;
220               wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR);
221               event.Skip();
222               return;
223             }
224         }
225
226       if(!this->model->CreateProject(
227           crea::wx2std(dialog->GetProjectName()),
228           crea::wx2std(dialog->GetProjectLocation()),
229           result,
230           crea::wx2std(dialog->GetPackageAuthor()),
231           crea::wx2std(dialog->GetPackageDescription())
232       ))
233         {
234           std::cout << "error opening project: " << *result << std::endl;
235           wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR);
236           event.Skip();
237           return;
238         }
239
240       //populate tree control
241       tree_Projects->BuildTree(this->model->GetProject());
242       tree_Projects->SelectItem(this->model->GetProject()->GetId());
243
244       //change description panel
245       if(this->panel_Properties != NULL)
246         {
247           auiManager.DetachPane(this->panel_Properties);
248           this->panel_Properties->Destroy();
249         }
250
251       this->panel_Properties = new wxCDMProjectDescriptionPanel(
252           this,
253           this->model->GetProject(),
254           ID_WINDOW_PROPERTIES,
255           wxT("Description Panel"),
256           wxDefaultPosition,
257           wxSize(300, 400),
258           0);
259       //show projectactions panel
260       if(this->panel_ProjectActions != NULL)
261         {
262           auiManager.DetachPane(this->panel_Properties);
263           this->panel_ProjectActions->Destroy();
264         }
265
266       panel_ProjectActions = new wxCDMProjectActionsPanel(
267           this,
268           ID_WINDOW_PROJ_ACTIONS,
269           wxT("Project Actions Panel"),
270           wxDefaultPosition,
271           wxSize(600,200),
272           0
273       );
274       panel_ProjectActions->SetMinSize(wxSize(500, 100));
275
276
277       auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
278       auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions"));
279
280       auiManager.Update();
281
282       wxMessageBox(_T("New Project created!"),_T("New Project - Success!"), wxOK | wxICON_INFORMATION);
283     }
284
285   event.Skip();
286 }
287 void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
288 {
289   std::string* result;
290
291   long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
292   wxDirDialog* FD = new wxDirDialog(this, wxT("Select the project directory"), wxT(""), style);
293   long userResponse = FD->ShowModal();
294   if(userResponse == wxID_OK)
295     {
296       std::string path = crea::wx2std (FD->GetPath());
297       FD -> Destroy();
298       FD = NULL;
299
300       std::cout << "Selection to open: " << path << std::endl;
301
302
303       //populate model
304       if(this->model->GetProject() != NULL)
305         {
306           std::cout << "Project not null, closing it" << std::endl;
307           if(!this->model->CloseProject(result))
308             {
309               std::cout << "error closing project: " << *result << std::endl;
310               wxMessageBox(crea::std2wx(result->c_str()),_T("New Project - Error!"),wxOK | wxICON_ERROR);
311               event.Skip();
312               return;
313             }
314         }
315
316       if (!this->model->OpenProject(path, result))
317         {
318           std::cout << "error opening project: " << *result << std::endl;
319           wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR);
320           event.Skip();
321           return;
322         };
323
324       std::cout << "building ui" << std::endl;
325
326
327       //populate tree control
328       tree_Projects->BuildTree(this->model->GetProject());
329       tree_Projects->SelectItem(this->model->GetProject()->GetId());
330
331       //change description panel
332       if(this->panel_Properties != NULL)
333         {
334           auiManager.DetachPane(this->panel_Properties);
335           this->panel_Properties->Destroy();
336         }
337
338       this->panel_Properties = new wxCDMProjectDescriptionPanel(
339           this,
340           this->model->GetProject(),
341           ID_WINDOW_PROPERTIES,
342           wxT("Description Panel"),
343           wxDefaultPosition,
344           wxSize(300, 400),
345           0
346       );
347
348       //change project's actions panel
349       if(this->panel_ProjectActions!= NULL)
350         {
351           auiManager.DetachPane(this->panel_ProjectActions);
352           this->panel_ProjectActions->Destroy();
353         }
354       panel_ProjectActions = new wxCDMProjectActionsPanel(
355           this,
356           ID_WINDOW_PROJ_ACTIONS,
357           wxT("Project Actions Panel"),
358           wxDefaultPosition,
359           wxSize(600,200),
360           0
361       );
362       panel_ProjectActions->SetMinSize(wxSize(500, 100));
363
364
365       auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
366       auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions"));
367
368       auiManager.Update();
369     }
370
371   event.Skip();
372 }
373 void wxCDMMainFrame::OnMenuOpenRecent(wxCommandEvent& event)
374 {
375   std::cerr << "Event OnMenuOpenRecent not implemented" << std::endl;
376   event.Skip();
377 }
378 void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event)
379 {
380   std::string* result;
381   if(!this->model->CloseProject(result))
382     {
383       std::cout << "error closing project: " << *result << std::endl;
384       wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
385     }
386   tree_Projects->BuildTree(this->model->GetProject());
387
388   if(this->panel_Properties != NULL)
389     {
390       auiManager.DetachPane(this->panel_Properties);
391       this->panel_Properties->Destroy();
392     }
393   if(this->panel_ProjectActions != NULL)
394     {
395       auiManager.DetachPane(this->panel_ProjectActions);
396       this->panel_ProjectActions->Destroy();
397     }
398
399   this->panel_Properties = new wxCDMMainDescriptionPanel(
400       this,
401       ID_WINDOW_PROPERTIES,
402       wxT("Description Panel"),
403       wxDefaultPosition,
404       wxSize(300, 400),
405       0
406   );
407
408   auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
409
410   auiManager.Update();
411   event.Skip();
412 }
413 void wxCDMMainFrame::OnMenuCloseAllProjects(wxCommandEvent& event)
414 {
415   std::cerr << "Event OnMenuCloseAllProjects not implemented" << std::endl;
416   event.Skip();
417 }
418 void wxCDMMainFrame::OnMenuExportHierarchy(wxCommandEvent& event)
419 {
420   std::cerr << "Event OnMenuExportHierarchy not implemented" << std::endl;
421   event.Skip();
422 }
423 void wxCDMMainFrame::OnMenuExit(wxCommandEvent& event)
424 {
425   std::cout << "Closing CreaDevManager..." << std::endl;
426   Close();
427   event.Skip();
428 }
429
430 //Edit Menu
431 void wxCDMMainFrame::OnMenuRefreshProject(wxCommandEvent& event)
432 {
433   std::string* result;
434   if(!model->RefreshProject(result))
435     {
436       wxMessageBox( crea::std2wx(result->c_str()), wxT("Refresh Project - Error"), wxICON_ERROR);
437     }
438   //TODO: Show possible problems in CMakeLists files
439   event.Skip();
440 }
441 void wxCDMMainFrame::OnMenuMenuCut(wxCommandEvent& event)
442 {
443   std::cerr << "Event OnMenuMenuCut not implemented" << std::endl;
444   event.Skip();
445 }
446 void wxCDMMainFrame::OnMenuMenuCopy(wxCommandEvent& event)
447 {
448   std::cerr << "Event OnMenuMenuCopy not implemented" << std::endl;
449   event.Skip();
450 }
451 void wxCDMMainFrame::OnMenuMenuPaste(wxCommandEvent& event)
452 {
453   std::cerr << "Event OnMenuMenuPaste not implemented" << std::endl;
454   event.Skip();
455 }
456 void wxCDMMainFrame::OnMenuMenuDelete(wxCommandEvent& event)
457 {
458   std::cerr << "Event OnMenuMenuDelete not implemented" << std::endl;
459   event.Skip();
460 }
461 void wxCDMMainFrame::OnMenuSelectAll(wxCommandEvent& event)
462 {
463   std::cerr << "Event OnMenuSelectAll not implemented" << std::endl;
464   event.Skip();
465 }
466 void wxCDMMainFrame::OnMenuSelectNone(wxCommandEvent& event)
467 {
468   std::cerr << "Event OnMenuSelectNone not implemented" << std::endl;
469   event.Skip();
470 }
471
472 //Tools Menu
473 void wxCDMMainFrame::OnMenuEventLog(wxCommandEvent& event)
474 {
475   std::cerr << "Event OnMenuEventLog not implemented" << std::endl;
476   event.Skip();
477 }
478 void wxCDMMainFrame::OnMenuBBTKGraphicalEditor(wxCommandEvent& event)
479 {
480   std::cerr << "Event OnMenuBBTKGraphicalEditor not implemented" << std::endl;
481   event.Skip();
482 }
483 void wxCDMMainFrame::OnMenuMiniTools(wxCommandEvent& event)
484 {
485   std::cerr << "Event OnMenuMiniTools not implemented" << std::endl;
486   event.Skip();
487 }
488 void wxCDMMainFrame::OnMenuCodeEditor(wxCommandEvent& event)
489 {
490   std::cerr << "Event OnMenuCodeEditor not implemented" << std::endl;
491   event.Skip();
492 }
493 void wxCDMMainFrame::OnMenuCommandLine(wxCommandEvent& event)
494 {
495   std::cerr << "Event OnMenuCommandLine not implemented" << std::endl;
496   event.Skip();
497 }
498
499 //Help Menu
500 void wxCDMMainFrame::OnMenuHelp(wxCommandEvent& event)
501 {
502   std::cerr << "Event OnMenuHelp not implemented" << std::endl;
503   event.Skip();
504 }
505 void wxCDMMainFrame::OnMenuReportBug(wxCommandEvent& event)
506 {
507   std::cerr << "Event OnMenuReportBug not implemented" << std::endl;
508   event.Skip();
509 }
510 void wxCDMMainFrame::OnMenuAboutCreaDevManager(wxCommandEvent& event)
511 {
512   std::cerr << "Event OnMenuAboutCreaDevManager not implemented" << std::endl;
513   event.Skip();
514 }
515 void wxCDMMainFrame::OnMenuAboutCreatis(wxCommandEvent& event)
516 {
517   std::cerr << "Event OnMenuAboutCreatis not implemented" << std::endl;
518   event.Skip();
519 }
520
521 void wxCDMMainFrame::OnTreeSelectionChanged(wxTreeEvent& event)
522 {
523   std::cerr << "Event OnTreeSelectionChange not implemented" << std::endl;
524   event.Skip();
525 }