]> 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   panel_ProjectActions = new wxCDMProjectActionsPanel(
194       this,
195       ID_WINDOW_PROJ_ACTIONS,
196       wxT("Project Actions Panel"),
197       wxDefaultPosition,
198       wxSize(600,200),
199       0
200   );
201   panel_ProjectActions->SetMinSize(wxSize(500, 100));
202
203   auiManager.AddPane(tree_Projects, wxLEFT, wxT("Projects Tree"));
204   auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions"));
205   auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
206
207   auiManager.Update();
208   auiManager.GetPane(tree_Projects).CloseButton(false).MaximizeButton(true);
209 }
210
211 //Event Handlers
212 //File menu
213 void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
214 {
215   wxCDMNewProjectDialog* dialog = new wxCDMNewProjectDialog(this);
216   long userResponse;
217   userResponse = dialog->ShowModal();
218
219   if(userResponse == wxID_FORWARD)
220     {
221       //create project
222       std::string* result;
223       if(!this->model->CreateProject(
224           crea::wx2std(dialog->GetProjectName()),
225           crea::wx2std(dialog->GetProjectLocation()),
226           result,
227           crea::wx2std(dialog->GetPackageAuthor()),
228           crea::wx2std(dialog->GetPackageDescription())
229       ))
230         {
231           wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR);
232           event.Skip();
233           return;
234         }
235
236       //populate tree control
237       tree_Projects->BuildTree(this->model->GetProject());
238       tree_Projects->SelectItem(this->model->GetProject()->GetId());
239
240       //change description panel
241       auiManager.DetachPane(this->panel_Properties);
242       this->panel_Properties->Destroy();
243       this->panel_Properties = new wxCDMProjectDescriptionPanel(
244           this,
245           this->model->GetProject(),
246           ID_WINDOW_PROPERTIES,
247           wxT("Description Panel"),
248           wxDefaultPosition,
249           wxSize(300, 400),
250           0);
251       auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
252
253       //TODO: change project's actions panel
254       auiManager.Update();
255
256       wxMessageBox(_T("New Project created!"),_T("New Project - Success!"), wxOK | wxICON_INFORMATION);
257     }
258
259   event.Skip();
260 }
261 void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
262 {
263   long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
264   wxDirDialog* FD = new wxDirDialog(this, wxT("Select the project directory"), wxT(""), style);
265   long userResponse = FD->ShowModal();
266   if(userResponse == wxID_OK)
267     {
268       std::string path = crea::wx2std (FD->GetPath());
269       FD -> Destroy();
270       FD = NULL;
271
272       std::cout << "Selection to open: " << path << std::endl;
273
274
275       //populate model
276       std::string* result;
277       if (!this->model->OpenProject(path, result))
278         {
279           wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR);
280         };
281
282       //populate tree control
283       tree_Projects->BuildTree(this->model->GetProject());
284       tree_Projects->SelectItem(this->model->GetProject()->GetId());
285
286       //change description panel
287       auiManager.DetachPane(this->panel_Properties);
288       this->panel_Properties->Destroy();
289       this->panel_Properties = new wxCDMProjectDescriptionPanel(
290           this,
291           this->model->GetProject(),
292           ID_WINDOW_PROPERTIES,
293           wxT("Description Panel"),
294           wxDefaultPosition,
295           wxSize(300, 400),
296           0);
297
298       auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
299
300       //TODO: change project's actions panel
301       auiManager.Update();
302     }
303
304   event.Skip();
305 }
306 void wxCDMMainFrame::OnMenuOpenRecent(wxCommandEvent& event)
307 {
308   std::cerr << "Event OnMenuOpenRecent not implemented" << std::endl;
309   event.Skip();
310 }
311 void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event)
312 {
313   std::string* result;
314   if(!this->model->CloseProject(result))
315     {
316       wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
317     }
318   tree_Projects->BuildTree(this->model->GetProject());
319   auiManager.Update();
320   event.Skip();
321 }
322 void wxCDMMainFrame::OnMenuCloseAllProjects(wxCommandEvent& event)
323 {
324   std::cerr << "Event OnMenuCloseAllProjects not implemented" << std::endl;
325   event.Skip();
326 }
327 void wxCDMMainFrame::OnMenuExportHierarchy(wxCommandEvent& event)
328 {
329   std::cerr << "Event OnMenuExportHierarchy not implemented" << std::endl;
330   event.Skip();
331 }
332 void wxCDMMainFrame::OnMenuExit(wxCommandEvent& event)
333 {
334   std::cout << "Closing CreaDevManager..." << std::endl;
335   Close();
336   event.Skip();
337 }
338
339 //Edit Menu
340 void wxCDMMainFrame::OnMenuRefreshProject(wxCommandEvent& event)
341 {
342   std::string* result;
343   if(!model->RefreshProject(result))
344     {
345       wxMessageBox( crea::std2wx(result->c_str()), wxT("Refresh Project - Error"), wxICON_ERROR);
346     }
347   //TODO: Show possible problems in CMakeLists files
348   event.Skip();
349 }
350 void wxCDMMainFrame::OnMenuMenuCut(wxCommandEvent& event)
351 {
352   std::cerr << "Event OnMenuMenuCut not implemented" << std::endl;
353   event.Skip();
354 }
355 void wxCDMMainFrame::OnMenuMenuCopy(wxCommandEvent& event)
356 {
357   std::cerr << "Event OnMenuMenuCopy not implemented" << std::endl;
358   event.Skip();
359 }
360 void wxCDMMainFrame::OnMenuMenuPaste(wxCommandEvent& event)
361 {
362   std::cerr << "Event OnMenuMenuPaste not implemented" << std::endl;
363   event.Skip();
364 }
365 void wxCDMMainFrame::OnMenuMenuDelete(wxCommandEvent& event)
366 {
367   std::cerr << "Event OnMenuMenuDelete not implemented" << std::endl;
368   event.Skip();
369 }
370 void wxCDMMainFrame::OnMenuSelectAll(wxCommandEvent& event)
371 {
372   std::cerr << "Event OnMenuSelectAll not implemented" << std::endl;
373   event.Skip();
374 }
375 void wxCDMMainFrame::OnMenuSelectNone(wxCommandEvent& event)
376 {
377   std::cerr << "Event OnMenuSelectNone not implemented" << std::endl;
378   event.Skip();
379 }
380
381 //Tools Menu
382 void wxCDMMainFrame::OnMenuEventLog(wxCommandEvent& event)
383 {
384   std::cerr << "Event OnMenuEventLog not implemented" << std::endl;
385   event.Skip();
386 }
387 void wxCDMMainFrame::OnMenuBBTKGraphicalEditor(wxCommandEvent& event)
388 {
389   std::cerr << "Event OnMenuBBTKGraphicalEditor not implemented" << std::endl;
390   event.Skip();
391 }
392 void wxCDMMainFrame::OnMenuMiniTools(wxCommandEvent& event)
393 {
394   std::cerr << "Event OnMenuMiniTools not implemented" << std::endl;
395   event.Skip();
396 }
397 void wxCDMMainFrame::OnMenuCodeEditor(wxCommandEvent& event)
398 {
399   std::cerr << "Event OnMenuCodeEditor not implemented" << std::endl;
400   event.Skip();
401 }
402 void wxCDMMainFrame::OnMenuCommandLine(wxCommandEvent& event)
403 {
404   std::cerr << "Event OnMenuCommandLine not implemented" << std::endl;
405   event.Skip();
406 }
407
408 //Help Menu
409 void wxCDMMainFrame::OnMenuHelp(wxCommandEvent& event)
410 {
411   std::cerr << "Event OnMenuHelp not implemented" << std::endl;
412   event.Skip();
413 }
414 void wxCDMMainFrame::OnMenuReportBug(wxCommandEvent& event)
415 {
416   std::cerr << "Event OnMenuReportBug not implemented" << std::endl;
417   event.Skip();
418 }
419 void wxCDMMainFrame::OnMenuAboutCreaDevManager(wxCommandEvent& event)
420 {
421   std::cerr << "Event OnMenuAboutCreaDevManager not implemented" << std::endl;
422   event.Skip();
423 }
424 void wxCDMMainFrame::OnMenuAboutCreatis(wxCommandEvent& event)
425 {
426   std::cerr << "Event OnMenuAboutCreatis not implemented" << std::endl;
427   event.Skip();
428 }
429
430 void wxCDMMainFrame::OnTreeSelectionChanged(wxTreeEvent& event)
431 {
432   std::cerr << "Event OnTreeSelectionChange not implemented" << std::endl;
433   event.Skip();
434 }