]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMMainFrame.cpp
open project fixed for model creation. Model not created yet
[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       std::string* result;
220       if(!this->model->CreateProject(
221           crea::wx2std(dialog->GetProjectName()),
222           crea::wx2std(dialog->GetProjectLocation()),
223           result,
224           crea::wx2std(dialog->GetPackageAuthor()),
225           crea::wx2std(dialog->GetPackageDescription())
226           ))
227         {
228           wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR);
229         }
230       wxMessageBox(_T("New Project created!"),_T("New Project - Success!"), wxOK | wxICON_INFORMATION);
231
232       //TODO: populate model
233       //TODO: populate tree control
234
235       //tree_Projects->BuildTree(this->model->GetActiveProjects());
236       auiManager.Update();
237     }
238
239   event.Skip();
240 }
241 void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
242 {
243   long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
244   wxDirDialog* FD = new wxDirDialog(this, wxT("Select the project directory"), wxT(""), style);
245   long userResponse;
246   userResponse = FD->ShowModal();
247   if(userResponse == wxID_OK)
248     {
249       std::cout << "Selection to open: " << crea::wx2std (FD->GetPath()) << std::endl;
250       std::string path = crea::wx2std (FD->GetPath());
251
252       std::string* result;
253       if (!this->model->OpenProject(path, result))
254         {
255           wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR);
256           event.Skip();
257         };
258
259       //TODO: populate model
260       //TODO: populate tree control
261
262       //((wxCreaDevManagerTreeCtrl*)tree_Projects)->BuildTree(controller->GetActiveProjects());
263       auiManager.Update();
264     }
265
266   event.Skip();
267 }
268 void wxCDMMainFrame::OnMenuOpenRecent(wxCommandEvent& event)
269 {
270   std::cerr << "Event OnMenuOpenRecent not implemented" << std::endl;
271   event.Skip();
272 }
273 void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event)
274 {
275   std::cerr << "Event OnMenuCloseProject not implemented" << std::endl;
276   event.Skip();
277 }
278 void wxCDMMainFrame::OnMenuCloseAllProjects(wxCommandEvent& event)
279 {
280   std::cerr << "Event OnMenuCloseAllProjects not implemented" << std::endl;
281   event.Skip();
282 }
283 void wxCDMMainFrame::OnMenuExportHierarchy(wxCommandEvent& event)
284 {
285   std::cerr << "Event OnMenuExportHierarchy not implemented" << std::endl;
286   event.Skip();
287 }
288 void wxCDMMainFrame::OnMenuExit(wxCommandEvent& event)
289 {
290   std::cout << "Closing CreaDevManager..." << std::endl;
291   Close();
292   event.Skip();
293 }
294
295 //Edit Menu
296 void wxCDMMainFrame::OnMenuRefreshProject(wxCommandEvent& event)
297 {
298   std::cerr << "Event OnMenuRefreshProject not implemented" << std::endl;
299   event.Skip();
300 }
301 void wxCDMMainFrame::OnMenuMenuCut(wxCommandEvent& event)
302 {
303   std::cerr << "Event OnMenuMenuCut not implemented" << std::endl;
304   event.Skip();
305 }
306 void wxCDMMainFrame::OnMenuMenuCopy(wxCommandEvent& event)
307 {
308   std::cerr << "Event OnMenuMenuCopy not implemented" << std::endl;
309   event.Skip();
310 }
311 void wxCDMMainFrame::OnMenuMenuPaste(wxCommandEvent& event)
312 {
313   std::cerr << "Event OnMenuMenuPaste not implemented" << std::endl;
314   event.Skip();
315 }
316 void wxCDMMainFrame::OnMenuMenuDelete(wxCommandEvent& event)
317 {
318   std::cerr << "Event OnMenuMenuDelete not implemented" << std::endl;
319   event.Skip();
320 }
321 void wxCDMMainFrame::OnMenuSelectAll(wxCommandEvent& event)
322 {
323   std::cerr << "Event OnMenuSelectAll not implemented" << std::endl;
324   event.Skip();
325 }
326 void wxCDMMainFrame::OnMenuSelectNone(wxCommandEvent& event)
327 {
328   std::cerr << "Event OnMenuSelectNone not implemented" << std::endl;
329   event.Skip();
330 }
331
332 //Tools Menu
333 void wxCDMMainFrame::OnMenuEventLog(wxCommandEvent& event)
334 {
335   std::cerr << "Event OnMenuEventLog not implemented" << std::endl;
336   event.Skip();
337 }
338 void wxCDMMainFrame::OnMenuBBTKGraphicalEditor(wxCommandEvent& event)
339 {
340   std::cerr << "Event OnMenuBBTKGraphicalEditor not implemented" << std::endl;
341   event.Skip();
342 }
343 void wxCDMMainFrame::OnMenuMiniTools(wxCommandEvent& event)
344 {
345   std::cerr << "Event OnMenuMiniTools not implemented" << std::endl;
346   event.Skip();
347 }
348 void wxCDMMainFrame::OnMenuCodeEditor(wxCommandEvent& event)
349 {
350   std::cerr << "Event OnMenuCodeEditor not implemented" << std::endl;
351   event.Skip();
352 }
353 void wxCDMMainFrame::OnMenuCommandLine(wxCommandEvent& event)
354 {
355   std::cerr << "Event OnMenuCommandLine not implemented" << std::endl;
356   event.Skip();
357 }
358
359 //Help Menu
360 void wxCDMMainFrame::OnMenuHelp(wxCommandEvent& event)
361 {
362   std::cerr << "Event OnMenuHelp not implemented" << std::endl;
363   event.Skip();
364 }
365 void wxCDMMainFrame::OnMenuReportBug(wxCommandEvent& event)
366 {
367   std::cerr << "Event OnMenuReportBug not implemented" << std::endl;
368   event.Skip();
369 }
370 void wxCDMMainFrame::OnMenuAboutCreaDevManager(wxCommandEvent& event)
371 {
372   std::cerr << "Event OnMenuAboutCreaDevManager not implemented" << std::endl;
373   event.Skip();
374 }
375 void wxCDMMainFrame::OnMenuAboutCreatis(wxCommandEvent& event)
376 {
377   std::cerr << "Event OnMenuAboutCreatis not implemented" << std::endl;
378   event.Skip();
379 }