]> 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 "wxCDMProjectActionsPanel.h"
40 #include "wxCDMNewProjectDialog.h"
41
42
43 BEGIN_EVENT_TABLE(wxCDMMainFrame, wxFrame)
44 EVT_MENU(ID_MENU_NEW_PROJECT, wxCDMMainFrame::OnMenuNewProject)
45 EVT_MENU(ID_MENU_OPEN_PROJECT, wxCDMMainFrame::OnMenuOpenProject)
46 EVT_MENU(ID_MENU_OPEN_RECENT, wxCDMMainFrame::OnMenuOpenRecent)
47 EVT_MENU(ID_MENU_CLOSE_PROJECT, wxCDMMainFrame::OnMenuCloseProject)
48 EVT_MENU(ID_MENU_CLOSE_ALL_PROJECTS, wxCDMMainFrame::OnMenuCloseAllProjects)
49 EVT_MENU(ID_MENU_EXPORT_HIERARCHY, wxCDMMainFrame::OnMenuExportHierarchy)
50 EVT_MENU(ID_MENU_EXIT, wxCDMMainFrame::OnMenuExit)
51 EVT_MENU(ID_MENU_REFRESH_PROJECT, wxCDMMainFrame::OnMenuRefreshProject)
52 EVT_MENU(ID_MENU_CUT, wxCDMMainFrame::OnMenuMenuCut)
53 EVT_MENU(ID_MENU_COPY, wxCDMMainFrame::OnMenuMenuCopy)
54 EVT_MENU(ID_MENU_PASTE, wxCDMMainFrame::OnMenuMenuPaste)
55 EVT_MENU(ID_MENU_DELETE, wxCDMMainFrame::OnMenuMenuDelete)
56 EVT_MENU(ID_MENU_SELECT_ALL, wxCDMMainFrame::OnMenuSelectAll)
57 EVT_MENU(ID_MENU_SELECT_NONE, wxCDMMainFrame::OnMenuSelectNone)
58 EVT_MENU(ID_MENU_EVENT_LOG, wxCDMMainFrame::OnMenuEventLog)
59 EVT_MENU(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxCDMMainFrame::OnMenuBBTKGraphicalEditor)
60 EVT_MENU(ID_MENU_MINITOOLS, wxCDMMainFrame::OnMenuMiniTools)
61 EVT_MENU(ID_MENU_CODE_EDITOR, wxCDMMainFrame::OnMenuCodeEditor)
62 EVT_MENU(ID_MENU_COMMAND_LINE, wxCDMMainFrame::OnMenuCommandLine)
63 EVT_MENU(ID_MENU_HELP, wxCDMMainFrame::OnMenuHelp)
64 EVT_MENU(ID_MENU_REPORT_BUG, wxCDMMainFrame::OnMenuReportBug)
65 EVT_MENU(ID_MENU_ABOUT_CREADEVMANAGER, wxCDMMainFrame::OnMenuAboutCreaDevManager)
66 EVT_MENU(ID_MENU_ABOUT_CREATIS, wxCDMMainFrame::OnMenuAboutCreatis)
67 EVT_BUTTON(ID_BUTTON_NEWPROJECT, wxCDMMainFrame::OnMenuNewProject)
68 EVT_BUTTON(ID_BUTTON_OPENPROJECT, wxCDMMainFrame::OnMenuOpenProject)
69 EVT_TREE_SEL_CHANGED(ID_TREE_PROJECTS, wxCDMMainFrame::OnTreeSelectionChanged)
70 END_EVENT_TABLE()
71
72 wxCDMMainFrame::wxCDMMainFrame(
73     wxWindow* parent,
74     wxWindowID id,
75     const wxString& caption,
76     const wxPoint& pos,
77     const wxSize& size,
78     long style
79 )
80 {
81   Create(parent, id, caption, pos, size, style);
82 }
83
84 wxCDMMainFrame::~wxCDMMainFrame()
85 {
86   auiManager.UnInit();
87 }
88
89 bool wxCDMMainFrame::Create(
90     wxWindow* parent,
91     wxWindowID id,
92     const wxString& caption,
93     const wxPoint& pos,
94     const wxSize& size,
95     long style
96 )
97 {
98   wxFrame::Create(parent, id, caption, pos, size, style);
99   this->model = new modelCDMMain();
100   CreateMenus();
101   CreateControls();
102   return TRUE;
103 }
104
105 void wxCDMMainFrame::CreateMenus()
106 {
107   wxMenuBar* menuBar = new wxMenuBar;
108
109   //FileMenu
110   menu_File = new wxMenu();
111   menu_File->Append(ID_MENU_NEW_PROJECT, wxT("&New Project..."));
112   menu_File->Append(ID_MENU_OPEN_PROJECT, wxT("&Open Project..."));
113   menu_File->Append(ID_MENU_OPEN_RECENT, wxT("Open &Recent"));
114   menu_File->AppendSeparator();
115   menu_File->Append(ID_MENU_CLOSE_PROJECT, wxT("&Close Project"));
116   menu_File->Append(ID_MENU_CLOSE_ALL_PROJECTS, wxT("C&lose All Projects"));
117   menu_File->AppendSeparator();
118   menu_File->Append(ID_MENU_EXPORT_HIERARCHY, wxT("&Export Project Hierarchy..."));
119   menu_File->AppendSeparator();
120   menu_File->Append(ID_MENU_EXIT, wxT("E&xit"));
121
122   menuBar->Append(menu_File, wxT("&File"));
123
124   //EditMenu
125   menu_Edit = new wxMenu();
126   menu_Edit->Append(ID_MENU_REFRESH_PROJECT, wxT("&Refresh Project"));
127   menu_Edit->AppendSeparator();
128   menu_Edit->Append(ID_MENU_CUT, wxT("Cu&t"));
129   menu_Edit->Append(ID_MENU_COPY, wxT("&Copy"));
130   menu_Edit->Append(ID_MENU_PASTE, wxT("&Paste"));
131   menu_Edit->AppendSeparator();
132   menu_Edit->Append(ID_MENU_DELETE, wxT("&Delete"));
133   menu_Edit->Append(ID_MENU_SELECT_ALL, wxT("Select &All"));
134   menu_Edit->Append(ID_MENU_SELECT_NONE, wxT("Ca&ncel Selection"));
135
136   menuBar->Append(menu_Edit, wxT("&Edit"));
137
138   //ToolsMenu
139   menu_Tools = new wxMenu();
140   menu_Tools->Append(ID_MENU_EVENT_LOG, wxT("Event &Log"));
141   menu_Tools->Append(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxT("BBTK &Graphical Editor"));
142   menu_Tools->Append(ID_MENU_MINITOOLS, wxT("&MiniTools"));
143   menu_Tools->Append(ID_MENU_CODE_EDITOR, wxT("&Code Editor"));
144   menu_Tools->Append(ID_MENU_COMMAND_LINE, wxT("&Command Line"));
145
146   menuBar->Append(menu_Tools, wxT("&Tools"));
147
148   //HelpMenu
149   menu_Help = new wxMenu();
150   menu_Help->Append(ID_MENU_HELP, wxT("&Help"));
151   menu_Help->Append(ID_MENU_REPORT_BUG, wxT("Report &Bug"));
152   menu_Help->Append(ID_MENU_ABOUT_CREADEVMANAGER, wxT("&About CreaDevManager"));
153   menu_Help->Append(ID_MENU_ABOUT_CREATIS, wxT("A&bout CREATIS"));
154
155   menuBar->Append(menu_Help, wxT("&Help"));
156
157   //Set Bar
158   SetMenuBar(menuBar);
159
160   wxStatusBar* statusBar = new wxStatusBar(this, ID_STATUS_BAR, wxST_SIZEGRIP);
161   statusBar->SetFieldsCount(1);
162   SetStatusBar(statusBar);
163
164 }
165
166 void wxCDMMainFrame::CreateControls()
167 {
168
169   auiManager.SetManagedWindow(this);
170
171
172   tree_Projects = new wxCDMProjectsTreeCtrl(
173       this,
174       ID_TREE_PROJECTS,
175       wxDefaultPosition,
176       wxSize(300,400),
177       wxTR_HAS_BUTTONS | wxTR_AQUA_BUTTONS
178   );
179   tree_Projects->SetMinSize(wxSize(200,200));
180
181   panel_Properties = new wxCDMMainDescriptionPanel(
182       this,
183       ID_WINDOW_PROPERTIES,
184       wxT("Description Panel"),
185       wxDefaultPosition,
186       wxSize(300, 400),
187       0
188   );
189
190
191
192   panel_ProjectActions = new wxCDMProjectActionsPanel(
193       this,
194       ID_WINDOW_PROJ_ACTIONS,
195       wxT("Project Actions Panel"),
196       wxDefaultPosition,
197       wxSize(600,200),
198       0
199   );
200   panel_ProjectActions->SetMinSize(wxSize(500, 100));
201
202   auiManager.AddPane(tree_Projects, wxLEFT, wxT("Projects Tree"));
203   auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions"));
204   auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
205
206   auiManager.Update();
207   auiManager.GetPane(tree_Projects).CloseButton(false).MaximizeButton(true);
208   auiManager.GetPane(panel_Properties).CloseButton(false);
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       //TODO: change description panel
240       //TODO: change project's actions panel
241       auiManager.Update();
242
243       wxMessageBox(_T("New Project created!"),_T("New Project - Success!"), wxOK | wxICON_INFORMATION);
244     }
245
246   event.Skip();
247 }
248 void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
249 {
250   long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
251   wxDirDialog* FD = new wxDirDialog(this, wxT("Select the project directory"), wxT(""), style);
252   long userResponse = FD->ShowModal();
253   if(userResponse == wxID_OK)
254     {
255       std::string path = crea::wx2std (FD->GetPath());
256       FD -> Destroy();
257       FD = NULL;
258
259       std::cout << "Selection to open: " << path << std::endl;
260
261
262       //populate model
263       std::string* result;
264       if (!this->model->OpenProject(path, result))
265         {
266           wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR);
267         };
268
269       //populate tree control
270       tree_Projects->BuildTree(this->model->GetProject());
271       tree_Projects->SelectItem(this->model->GetProject()->GetId());
272       auiManager.Update();
273     }
274
275   event.Skip();
276 }
277 void wxCDMMainFrame::OnMenuOpenRecent(wxCommandEvent& event)
278 {
279   std::cerr << "Event OnMenuOpenRecent not implemented" << std::endl;
280   event.Skip();
281 }
282 void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event)
283 {
284   std::string* result;
285   if(!this->model->CloseProject(result))
286     {
287       wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
288     }
289   event.Skip();
290 }
291 void wxCDMMainFrame::OnMenuCloseAllProjects(wxCommandEvent& event)
292 {
293   std::cerr << "Event OnMenuCloseAllProjects not implemented" << std::endl;
294   event.Skip();
295 }
296 void wxCDMMainFrame::OnMenuExportHierarchy(wxCommandEvent& event)
297 {
298   std::cerr << "Event OnMenuExportHierarchy not implemented" << std::endl;
299   event.Skip();
300 }
301 void wxCDMMainFrame::OnMenuExit(wxCommandEvent& event)
302 {
303   std::cout << "Closing CreaDevManager..." << std::endl;
304   Close();
305   event.Skip();
306 }
307
308 //Edit Menu
309 void wxCDMMainFrame::OnMenuRefreshProject(wxCommandEvent& event)
310 {
311   std::string* result;
312   if(!model->RefreshProject(result))
313     {
314       wxMessageBox( crea::std2wx(result->c_str()), wxT("Refresh Project - Error"), wxICON_ERROR);
315     }
316   //TODO: Show possible problems in CMakeLists files
317   event.Skip();
318 }
319 void wxCDMMainFrame::OnMenuMenuCut(wxCommandEvent& event)
320 {
321   std::cerr << "Event OnMenuMenuCut not implemented" << std::endl;
322   event.Skip();
323 }
324 void wxCDMMainFrame::OnMenuMenuCopy(wxCommandEvent& event)
325 {
326   std::cerr << "Event OnMenuMenuCopy not implemented" << std::endl;
327   event.Skip();
328 }
329 void wxCDMMainFrame::OnMenuMenuPaste(wxCommandEvent& event)
330 {
331   std::cerr << "Event OnMenuMenuPaste not implemented" << std::endl;
332   event.Skip();
333 }
334 void wxCDMMainFrame::OnMenuMenuDelete(wxCommandEvent& event)
335 {
336   std::cerr << "Event OnMenuMenuDelete not implemented" << std::endl;
337   event.Skip();
338 }
339 void wxCDMMainFrame::OnMenuSelectAll(wxCommandEvent& event)
340 {
341   std::cerr << "Event OnMenuSelectAll not implemented" << std::endl;
342   event.Skip();
343 }
344 void wxCDMMainFrame::OnMenuSelectNone(wxCommandEvent& event)
345 {
346   std::cerr << "Event OnMenuSelectNone not implemented" << std::endl;
347   event.Skip();
348 }
349
350 //Tools Menu
351 void wxCDMMainFrame::OnMenuEventLog(wxCommandEvent& event)
352 {
353   std::cerr << "Event OnMenuEventLog not implemented" << std::endl;
354   event.Skip();
355 }
356 void wxCDMMainFrame::OnMenuBBTKGraphicalEditor(wxCommandEvent& event)
357 {
358   std::cerr << "Event OnMenuBBTKGraphicalEditor not implemented" << std::endl;
359   event.Skip();
360 }
361 void wxCDMMainFrame::OnMenuMiniTools(wxCommandEvent& event)
362 {
363   std::cerr << "Event OnMenuMiniTools not implemented" << std::endl;
364   event.Skip();
365 }
366 void wxCDMMainFrame::OnMenuCodeEditor(wxCommandEvent& event)
367 {
368   std::cerr << "Event OnMenuCodeEditor not implemented" << std::endl;
369   event.Skip();
370 }
371 void wxCDMMainFrame::OnMenuCommandLine(wxCommandEvent& event)
372 {
373   std::cerr << "Event OnMenuCommandLine not implemented" << std::endl;
374   event.Skip();
375 }
376
377 //Help Menu
378 void wxCDMMainFrame::OnMenuHelp(wxCommandEvent& event)
379 {
380   std::cerr << "Event OnMenuHelp not implemented" << std::endl;
381   event.Skip();
382 }
383 void wxCDMMainFrame::OnMenuReportBug(wxCommandEvent& event)
384 {
385   std::cerr << "Event OnMenuReportBug not implemented" << std::endl;
386   event.Skip();
387 }
388 void wxCDMMainFrame::OnMenuAboutCreaDevManager(wxCommandEvent& event)
389 {
390   std::cerr << "Event OnMenuAboutCreaDevManager not implemented" << std::endl;
391   event.Skip();
392 }
393 void wxCDMMainFrame::OnMenuAboutCreatis(wxCommandEvent& event)
394 {
395   std::cerr << "Event OnMenuAboutCreatis not implemented" << std::endl;
396   event.Skip();
397 }
398
399 void wxCDMMainFrame::OnTreeSelectionChanged(wxTreeEvent& event)
400 {
401   std::cerr << "Event OnTreeSelectionChange not implemented" << std::endl;
402   event.Skip();
403 }