]> 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 #include <sstream>
33
34 #include <creaWx.h>
35 #include "creaSystem.h"
36 #include "wx/treectrl.h"
37 #include "wx/treebase.h"
38 #include "wx/tooltip.h"
39 #include "wx/wxhtml.h"
40 #include "wx/statline.h"
41 #include "CDMUtilities.h"
42
43 #include "creaDevManagerIds.h"
44 #include "wxCDMMainDescriptionPanel.h"
45 #include "wxCDMProjectDescriptionPanel.h"
46 #include "wxCDMAppliDescriptionPanel.h"
47 #include "wxCDMApplicationDescriptionPanel.h"
48 #include "wxCDMLibDescriptionPanel.h"
49 #include "wxCDMLibraryDescriptionPanel.h"
50 #include "wxCDMPackageDescriptionPanel.h"
51 #include "wxCDMBlackBoxDescriptionPanel.h"
52 #include "wxCDMCMakeListsDescriptionPanel.h"
53 #include "wxCDMFolderDescriptionPanel.h"
54 #include "wxCDMFileDescriptionPanel.h"
55 #include "wxCDMPackageManagerPanel.h"
56
57 #include "wxCDMProjectActionsPanel.h"
58 #include "wxCDMNewProjectDialog.h"
59
60
61
62 BEGIN_EVENT_TABLE(wxCDMMainFrame, wxFrame)
63 EVT_MENU(ID_MENU_NEW_PROJECT, wxCDMMainFrame::OnMenuNewProject)
64 EVT_MENU(ID_MENU_OPEN_PROJECT, wxCDMMainFrame::OnMenuOpenProject)
65 EVT_MENU(ID_MENU_CLOSE_PROJECT, wxCDMMainFrame::OnMenuCloseProject)
66 EVT_MENU(ID_MENU_EXPORT_HIERARCHY, wxCDMMainFrame::OnMenuExportHierarchy)
67 EVT_MENU(ID_MENU_EXIT, wxCDMMainFrame::OnMenuExit)
68 EVT_MENU(ID_MENU_REFRESH_PROJECT, wxCDMMainFrame::OnMenuRefreshProject)
69 EVT_MENU(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxCDMMainFrame::OnMenuBBTKGraphicalEditor)
70 EVT_MENU(ID_MENU_MINITOOLS, wxCDMMainFrame::OnMenuMiniTools)
71 EVT_MENU(ID_MENU_CODE_EDITOR, wxCDMMainFrame::OnMenuCodeEditor)
72 EVT_MENU(ID_MENU_COMMAND_LINE, wxCDMMainFrame::OnMenuCommandLine)
73 EVT_MENU(ID_MENU_TOGGLE_HELP, wxCDMMainFrame::OnMenuToggleHelp)
74 EVT_MENU(ID_MENU_HELP, wxCDMMainFrame::OnMenuHelp)
75 EVT_MENU(ID_MENU_REPORT_BUG, wxCDMMainFrame::OnMenuReportBug)
76 EVT_MENU(ID_MENU_ABOUT_CREADEVMANAGER, wxCDMMainFrame::OnMenuAboutCreaDevManager)
77 EVT_MENU(ID_MENU_ABOUT_CREATIS, wxCDMMainFrame::OnMenuAboutCreatis)
78
79 EVT_BUTTON(ID_BUTTON_NEWPROJECT, wxCDMMainFrame::OnMenuNewProject)
80 EVT_BUTTON(ID_BUTTON_OPENPROJECT, wxCDMMainFrame::OnMenuOpenProject)
81
82 EVT_TREE_SEL_CHANGED(ID_TREE_PROJECTS, wxCDMMainFrame::OnTreeSelectionChanged)
83
84 EVT_COMMAND(wxID_ANY, wxEVT_DISPLAY_CHANGED, wxCDMMainFrame::OnChangeView)
85 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCDMMainFrame::OnElementSelected)
86 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_LISTBOX_SELECTED, wxCDMMainFrame::OnElementDeselected)
87
88
89 EVT_CHECKBOX(ID_CHECKBOX_DISABLE_HELP, wxCDMMainFrame::OnDisableHelp)
90 END_EVENT_TABLE()
91
92 wxCDMMainFrame::wxCDMMainFrame(
93     wxWindow* parent,
94     wxWindowID id,
95     const wxString& caption,
96     const wxPoint& pos,
97     const wxSize& size,
98     long style
99 )
100 {
101   this->menu_File = NULL;
102   this->menu_Edit = NULL;
103   this->menu_Tools = NULL;
104   this->menu_Help = NULL;
105   this->panel_Properties = NULL;
106   this->panel_ProjectActions = NULL;
107   this->tree_Projects = NULL;
108   Create(parent, id, caption, pos, size, style);
109 }
110
111 wxCDMMainFrame::~wxCDMMainFrame()
112 {
113   auiManager.UnInit();
114 }
115
116 bool wxCDMMainFrame::Create(
117     wxWindow* parent,
118     wxWindowID id,
119     const wxString& caption,
120     const wxPoint& pos,
121     const wxSize& size,
122     long style
123 )
124 {
125   wxFrame::Create(parent, id, caption, pos, size, style);
126   this->model = new modelCDMMain();
127   this->help = true;
128   CreateMenus();
129   CreateControls();
130   return TRUE;
131 }
132
133 modelCDMMain* wxCDMMainFrame::GetModel() const
134 {
135   return this->model;
136 }
137
138 wxPanel* wxCDMMainFrame::GetPropertiesPanel() const
139 {
140   return this->panel_Properties;
141 }
142
143 bool wxCDMMainFrame::isHelp() const
144 {
145   return this->help;
146 }
147
148 void wxCDMMainFrame::RefreshProject()
149 {
150   std::string* result;
151   std::cout << "refreshing project" << std::endl;
152   this->model->RefreshProject(result);
153   std::cout << "rebuilding project tree" << std::endl;
154   this->tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
155 }
156
157 void wxCDMMainFrame::CreateMenus()
158 {
159   wxMenuBar* menuBar = new wxMenuBar;
160
161   //FileMenu
162   menu_File = new wxMenu();
163   menu_File->Append(ID_MENU_NEW_PROJECT, wxT("&New Project..."));
164   menu_File->Append(ID_MENU_OPEN_PROJECT, wxT("&Open Project..."));
165   menu_File->AppendSeparator();
166   menu_File->Append(ID_MENU_CLOSE_PROJECT, wxT("&Close Project"));
167   menu_File->AppendSeparator();
168   menu_File->Append(ID_MENU_EXPORT_HIERARCHY, wxT("&Export Project Hierarchy..."));
169   menu_File->AppendSeparator();
170   menu_File->Append(ID_MENU_EXIT, wxT("E&xit"));
171
172   menuBar->Append(menu_File, wxT("&File"));
173
174   //EditMenu
175   menu_Edit = new wxMenu();
176   menu_Edit->Append(ID_MENU_REFRESH_PROJECT, wxT("&Refresh Project"));
177
178   menuBar->Append(menu_Edit, wxT("&Edit"));
179
180   //ToolsMenu
181   menu_Tools = new wxMenu();
182   menu_Tools->Append(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxT("BBTK &Graphical Editor"));
183   menu_Tools->Append(ID_MENU_MINITOOLS, wxT("&MiniTools"));
184   menu_Tools->Append(ID_MENU_CODE_EDITOR, wxT("&Code Editor"));
185   menu_Tools->Append(ID_MENU_COMMAND_LINE, wxT("&Command Line"));
186
187   menuBar->Append(menu_Tools, wxT("&Tools"));
188
189   //HelpMenu
190   menu_Help = new wxMenu();
191   menu_Help->AppendCheckItem(ID_MENU_TOGGLE_HELP, wxT("He&lp Dialogs"));
192   menu_Help->Check(ID_MENU_TOGGLE_HELP, this->help);
193   menu_Help->Append(ID_MENU_HELP, wxT("&Help"));
194   menu_Help->Append(ID_MENU_REPORT_BUG, wxT("Report &Bug"));
195   menu_Help->Append(ID_MENU_ABOUT_CREADEVMANAGER, wxT("&About CreaDevManager"));
196   menu_Help->Append(ID_MENU_ABOUT_CREATIS, wxT("A&bout CREATIS"));
197
198   menuBar->Append(menu_Help, wxT("&Help"));
199
200   //Set Bar
201   SetMenuBar(menuBar);
202
203   wxStatusBar* statusBar = new wxStatusBar(this, ID_STATUS_BAR, wxST_SIZEGRIP);
204   statusBar->SetFieldsCount(1);
205   SetStatusBar(statusBar);
206
207 }
208
209 void wxCDMMainFrame::CreateControls()
210 {
211
212   auiManager.SetManagedWindow(this);
213
214
215   tree_Projects = new wxCDMProjectsTreeCtrl(
216       this,
217       ID_TREE_PROJECTS,
218       wxDefaultPosition,
219       wxSize(200,400),
220           wxTR_HAS_BUTTONS | wxTR_AQUA_BUTTONS
221   );
222
223   panel_Properties = new wxCDMMainDescriptionPanel(
224       this,
225       ID_WINDOW_PROPERTIES,
226       wxT("Description Panel"),
227       wxDefaultPosition,
228       wxSize(400, 600),
229       0
230   );
231
232   auiManager.AddPane(panel_Properties, wxAuiPaneInfo().BestSize(600,400).CenterPane().Name(wxT("panel_Properties")).Caption(wxT("")).CloseButton(false));
233   auiManager.AddPane(tree_Projects, wxAuiPaneInfo().Right().MinSize(300,300).BestSize(300,400).CloseButton(false).Name(wxT("tree_Projects")).Caption(wxT("Project Tree")).CloseButton(false));
234   auiManager.Update();
235   //auiManager.LoadPerspective(pers,true);
236   wxToolTip::Enable(true);
237   wxToolTip::SetDelay(0);
238 }
239
240 //Event Handlers
241 //File menu
242 void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
243 {
244   std::string* result;
245
246   wxCDMNewProjectDialog* dialog = new wxCDMNewProjectDialog(this);
247   long userResponse;
248   userResponse = dialog->ShowModal();
249
250   if(userResponse == wxID_FORWARD)
251     {
252       //create project
253       if(this->model->GetProject() != NULL)
254         {
255           if(!this->model->CloseProject(result))
256             {
257               std::cout << "error closing project: " << *result << std::endl;
258               wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR);
259               event.Skip();
260               return;
261             }
262         }
263
264
265       if(!this->model->CreateProject(
266           crea::wx2std(dialog->GetProjectName()),
267           crea::wx2std(dialog->GetProjectLocation()),
268           result,
269           crea::wx2std(dialog->GetPackageAuthor()),
270           crea::wx2std(dialog->GetPackageDescription())
271       ))
272         {
273           std::cout << "error opening project: " << *result << std::endl;
274           wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR);
275           event.Skip();
276           return;
277         }
278       
279       //show project actions panel
280       if(this->panel_ProjectActions != NULL)
281         {
282           auiManager.DetachPane(this->panel_Properties);
283           this->panel_ProjectActions->Destroy();
284           this->panel_ProjectActions = NULL;
285         }
286           
287       panel_ProjectActions = new wxCDMProjectActionsPanel(
288           this,
289           this->model->GetProject(),
290           ID_WINDOW_PROJ_ACTIONS,
291           wxT("Project Actions Panel"),
292           wxDefaultPosition,
293           wxSize(800,200),
294           0
295       );
296       
297       auiManager.AddPane(panel_ProjectActions, wxAuiPaneInfo().Bottom().MinSize(800,50).Name(wxT("panel_ProjectActions")).Caption(wxT("General Project Actions")).BestSize(800,70).CloseButton(false));
298       auiManager.Update();
299
300       //populate tree control
301       tree_Projects->BuildTree(this->model->GetModelElements(),this->model->GetProject());
302       tree_Projects->Unselect();
303           tree_Projects->SelectItem(this->model->GetProject()->GetId());
304           wxMessageBox(wxT("ProjectSelected") ,_T("New Project - Success!"),wxOK | wxICON_ERROR);
305     }
306 }
307 void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
308 {
309   std::string* result;
310
311   long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
312   wxDirDialog* FD = new wxDirDialog(this, wxT("Select the project directory"), wxT(""), style);
313   long userResponse = FD->ShowModal();
314   if(userResponse == wxID_OK)
315     {
316       std::string path = crea::wx2std (FD->GetPath());
317       FD -> Destroy();
318       FD = NULL;
319
320       std::cout << "Selection to open: " << path << std::endl;
321
322
323       //populate model
324       if(this->model->GetProject() != NULL)
325         {
326           std::cout << "Project not null, closing it" << std::endl;
327           if(!this->model->CloseProject(result))
328             {
329               std::cout << "error closing project: " << *result << std::endl;
330               wxMessageBox(crea::std2wx(result->c_str()),_T("New Project - Error!"),wxOK | wxICON_ERROR);
331               event.Skip();
332               return;
333             }
334         }
335
336       if (!this->model->OpenProject(path, result))
337         {
338           std::cout << "error opening project: " << *result << std::endl;
339           wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR);
340           event.Skip();
341           return;
342         };
343
344       std::cout << "building ui" << std::endl;
345
346       //populate tree control
347       tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
348       tree_Projects->Unselect();
349           tree_Projects->SelectItem(this->model->GetProject()->GetId(), true);
350
351
352
353       //change project's actions panel
354       if(this->panel_ProjectActions!= NULL)
355         {
356           auiManager.DetachPane(this->panel_ProjectActions);
357           this->panel_ProjectActions->Destroy();
358           this->panel_ProjectActions = NULL;
359         }
360       panel_ProjectActions = new wxCDMProjectActionsPanel(
361           this,
362           this->model->GetProject(),
363           ID_WINDOW_PROJ_ACTIONS,
364           wxT("Project Actions Panel"),
365           wxDefaultPosition,
366           wxSize(800,200),
367           0
368       );
369       panel_ProjectActions->SetMinSize(wxSize(500, 100));
370
371
372       auiManager.AddPane(panel_ProjectActions, wxAuiPaneInfo().Bottom().MinSize(800,50).Name(wxT("panel_ProjectActions")).Caption(wxT("General Project Actions")).BestSize(800,70).CloseButton(false));
373
374       auiManager.Update();
375
376     }
377
378   event.Skip();
379 }
380
381 void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event)
382 {
383   std::cout << "closing project" << std::endl;
384   std::string* result;
385   if(!this->model->CloseProject(result))
386     {
387       std::cout << "error closing project: " << *result << std::endl;
388       wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
389     }
390
391   tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
392
393   if(this->panel_Properties != NULL)
394     {
395       auiManager.DetachPane(this->panel_Properties);
396       this->panel_Properties->Destroy();
397       this->panel_Properties = NULL;
398     }
399   if(this->panel_ProjectActions != NULL)
400     {
401       auiManager.DetachPane(this->panel_ProjectActions);
402       this->panel_ProjectActions->Destroy();
403       this->panel_ProjectActions = NULL;
404     }
405
406   this->panel_Properties = new wxCDMMainDescriptionPanel(
407       this,
408       ID_WINDOW_PROPERTIES,
409       wxT("Description Panel"),
410       wxDefaultPosition,
411       wxSize(600, 400),
412       0
413   );
414
415   auiManager.AddPane(panel_Properties, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
416
417   auiManager.Update();
418   event.Skip();
419 }
420
421 void wxCDMMainFrame::OnMenuExportHierarchy(wxCommandEvent& event)
422 {
423   std::cerr << "Event OnMenuExportHierarchy not implemented" << std::endl;
424   event.Skip();
425 }
426 void wxCDMMainFrame::OnMenuExit(wxCommandEvent& event)
427 {
428   std::cout << "Closing CreaDevManager..." << std::endl;
429   std::string* result;
430   if(this->model->GetProject() != NULL && !this->model->CloseProject(result))
431     {
432       std::cout << "error closing project: " << *result << std::endl;
433     }
434
435   if(this->panel_Properties != NULL)
436     {
437       auiManager.DetachPane(this->panel_Properties);
438       this->panel_Properties->Destroy();
439       this->panel_Properties = NULL;
440     }
441   
442   if(this->tree_Projects != NULL)
443     {
444       auiManager.DetachPane(this->tree_Projects);
445       this->tree_Projects->Destroy();
446       this->tree_Projects = NULL;
447     }
448
449   if(this->panel_ProjectActions != NULL)
450     {
451       auiManager.DetachPane(this->panel_ProjectActions);
452       this->panel_ProjectActions->Destroy();
453       this->panel_ProjectActions = NULL;
454     }
455   
456   Close();
457 }
458
459 //Edit Menu
460 void wxCDMMainFrame::OnMenuRefreshProject(wxCommandEvent& event)
461 {
462   std::string* result;
463   if(!model->RefreshProject(result))
464     {
465       wxMessageBox( crea::std2wx(result->c_str()), wxT("Refresh Project - Error"), wxICON_ERROR);
466     }
467   if(this->model->GetProject() != NULL)
468     {
469       this->tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
470       this->auiManager.Update();
471
472       this->tree_Projects->Unselect();
473       this->tree_Projects->SelectItem(this->model->GetProject()->GetId(), true);
474     }
475   event.Skip();
476 }
477
478 void wxCDMMainFrame::OnMenuBBTKGraphicalEditor(wxCommandEvent& event)
479 {
480   std::cerr << "Event OnMenuBBTKGraphicalEditor not implemented" << std::endl;
481   event.Skip();
482   if(CDMUtilities::openBBEditor())
483     {
484       wxMessageBox( wxT("Can't open the BB Graphical Editor. Please check your Crea Tools installation."), wxT("Refresh Project - Error"), wxICON_ERROR);
485     }
486 }
487 void wxCDMMainFrame::OnMenuMiniTools(wxCommandEvent& event)
488 {
489   if(CDMUtilities::openCreaToolsTools())
490     {
491       wxMessageBox( wxT("Can't open the Minitools. Please check your Crea Tools installation."), wxT("Refresh Project - Error"), wxICON_ERROR);
492     }
493 }
494 void wxCDMMainFrame::OnMenuCodeEditor(wxCommandEvent& event)
495 {
496   if(CDMUtilities::openTextEditor())
497     {
498       wxMessageBox( wxT("Can't open the Text Editor. Please check the default text editor command in the Crea Development Manager settings (Edit -> Settings)."), wxT("Refresh Project - Error"), wxICON_ERROR);
499     }
500 }
501 void wxCDMMainFrame::OnMenuCommandLine(wxCommandEvent& event)
502 {
503   if(CDMUtilities::openTerminal())
504     {
505       wxMessageBox( wxT("Can't open Terminal. Please check the default terminal command in the Crea Development Manager settings (Edit -> Settings)."), wxT("Refresh Project - Error"), wxICON_ERROR);
506     }
507 }
508
509 //Help Menu
510 void wxCDMMainFrame::OnMenuHelp(wxCommandEvent& event)
511 {
512   wxLaunchDefaultBrowser(_T("http://www.creatis.insa-lyon.fr/site/en/CreatoolsDocumentation"), 0);
513 }
514 void wxCDMMainFrame::OnMenuReportBug(wxCommandEvent& event)
515 {
516   wxLaunchDefaultBrowser(_T("http://vip.creatis.insa-lyon.fr:9002/projects/crea"), 0);
517 }
518 void wxCDMMainFrame::OnMenuAboutCreaDevManager(wxCommandEvent& event)
519 {
520   wxBoxSizer *topsizer;
521   wxHtmlWindow *html;
522   wxDialog dlg(this, wxID_ANY, wxString(_("About")));
523
524   topsizer = new wxBoxSizer(wxVERTICAL);
525
526   html = new wxHtmlWindow(&dlg, wxID_ANY, wxDefaultPosition, wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
527   html -> SetBorders(0);
528
529   std::string content = ""
530       "<html>"
531       "<body bgcolor=\"#3333CC\">"
532       "<table cellspacing=3 cellpadding=4 width=\"100%\">"
533       "  <tr>"
534       "    <td bgcolor=\"#3333CC\">"
535       "    <center>"
536       "    <font size=+2 color=\"#FFFFFF\"><b>CREA Development Manager</b>"
537       "    </font>"
538       "    </center>"
539       "    </td>"
540       "  </tr>"
541       "  <tr>"
542       "    <td bgcolor=\"#FFFFFF\">"
543       "    <p><b><font size=+1>Creatis 2012 - Lyon, France</font></b></p>"
544       "    <font size=-1>"
545       "      <table cellpadding=0 cellspacing=0 width=\"100%\">"
546       "        <tr>"
547       "          <td width=\"65%\">"
548       "            <p>Created by Daniel Gonz&aacute;lez - daniel.gonzalez@creatis.insa-lyon.fr</p>"
549       "          </td>"
550       "        </tr>"
551       "      </table>"
552       "      <font size=1>"
553       "        <p>This software is governed by the CeCILL-B license under French law and abiding by the rules of distribution of free software.</p>"
554       "      </font>"
555       "    </font>"
556       "    </td>"
557       "  </tr>"
558       "</table>"
559       "</body>"
560       "</html>"
561       ;
562
563   html -> SetPage(crea::std2wx(content));
564   html -> SetSize(html -> GetInternalRepresentation() -> GetWidth(),
565       html -> GetInternalRepresentation() -> GetHeight());
566
567   topsizer -> Add(html, 1, wxALL, 10);
568
569 #if wxUSE_STATLINE
570   topsizer -> Add(new wxStaticLine(&dlg, wxID_ANY), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
571 #endif // wxUSE_STATLINE
572
573   wxButton *bu1 = new wxButton(&dlg, wxID_OK, _("OK"));
574   bu1 -> SetDefault();
575
576   topsizer -> Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15);
577
578   dlg.SetSizer(topsizer);
579   topsizer -> Fit(&dlg);
580
581   dlg.ShowModal();
582 }
583 void wxCDMMainFrame::OnMenuAboutCreatis(wxCommandEvent& event)
584 {
585   wxLaunchDefaultBrowser(_T("http://www.creatis.insa-lyon.fr/site/en"), 0);
586 }
587
588 void wxCDMMainFrame::OnTreeSelectionChanged(wxTreeEvent& event)
589 {
590
591   //get selected element
592   wxTreeItemId elementId = event.GetItem();
593   if(elementId.IsOk() && this->tree_Projects->IsSelected(elementId))
594     {
595       std::cout << "Tree Selection id: " << elementId << std::endl;
596       //get element from model
597       modelCDMIProjectTreeNode* element = this->model->GetModelElements()[elementId];
598
599           if (element == NULL)
600                   return;
601       std::cout << "Tree Selection: " << element->GetName() << std::endl;
602                 
603       //TODO get element type
604       //project
605       modelCDMProject* elementProject = dynamic_cast<modelCDMProject*>(element);
606       wxPanel* description;
607       if(elementProject != NULL)
608         {
609           //create element description
610           description = new wxCDMProjectDescriptionPanel(
611               this,
612               elementProject,
613               ID_WINDOW_PROPERTIES,
614               wxT("Description Panel"),
615               wxDefaultPosition,
616               wxSize(600, 400),
617               0
618           );
619
620         }
621       else
622         {
623           //appli
624           modelCDMAppli* elementAppli = dynamic_cast<modelCDMAppli*>(element);
625           if(elementAppli != NULL)
626             {
627               //create element description
628               description = new wxCDMAppliDescriptionPanel(
629                   this,
630                   elementAppli,
631                   ID_WINDOW_PROPERTIES,
632                   wxT("Description Panel"),
633                   wxDefaultPosition,
634                   wxSize(600, 400),
635                   0
636               );
637
638             }
639           else
640             {
641               //application
642               modelCDMApplication* elementApplication = dynamic_cast<modelCDMApplication*>(element);
643                           if(elementApplication != NULL)
644                 {
645                   //create element description
646                   description = new wxCDMApplicationDescriptionPanel(
647                       this,
648                       elementApplication,
649                       ID_WINDOW_PROPERTIES,
650                       wxT("Description Panel"),
651                       wxDefaultPosition,
652                       wxSize(600, 400),
653                       0
654                   );
655                 }
656               else
657                 {
658                   //lib
659                   modelCDMLib* elementLib = dynamic_cast<modelCDMLib*>(element);
660                   if(elementLib != NULL)
661                     {
662                       //create element description
663                       description = new wxCDMLibDescriptionPanel(
664                           this,
665                           elementLib,
666                           ID_WINDOW_PROPERTIES,
667                           wxT("Description Panel"),
668                           wxDefaultPosition,
669                           wxSize(600, 400),
670                           0
671                       );
672                     }
673                   else
674                     {
675                       //library
676                       modelCDMLibrary* elementLibrary = dynamic_cast<modelCDMLibrary*>(element);
677                       if(elementLibrary != NULL)
678                         {
679                           //create element description
680                           description = new wxCDMLibraryDescriptionPanel(
681                               this,
682                               elementLibrary,
683                               ID_WINDOW_PROPERTIES,
684                               wxT("Description Panel"),
685                               wxDefaultPosition,
686                               wxSize(600, 400),
687                               0
688                           );
689                         }
690                       else
691                         {
692                           //package
693                           modelCDMPackage* elementPackage = dynamic_cast<modelCDMPackage*>(element);
694                           if(elementPackage != NULL)
695                             {
696                               //create element description
697                               description = new wxCDMPackageDescriptionPanel(
698                                   this,
699                                   elementPackage,
700                                   ID_WINDOW_PROPERTIES,
701                                   wxT("Description Panel"),
702                                   wxDefaultPosition,
703                                   wxSize(600, 400),
704                                   0
705                               );
706                             }
707                           else
708                             {
709                               //black box
710                               modelCDMBlackBox* elementBlackBox = dynamic_cast<modelCDMBlackBox*>(element);
711                               if(elementBlackBox != NULL)
712                                 {
713                                   //create element description
714                                   description = new wxCDMBlackBoxDescriptionPanel(
715                                       this,
716                                       elementBlackBox,
717                                       ID_WINDOW_PROPERTIES,
718                                       wxT("Description Panel"),
719                                       wxDefaultPosition,
720                                       wxSize(600, 400),
721                                       0
722                                   );
723                                 }
724                               else
725                                 {
726                                   //CMakeLists
727                                   modelCDMCMakeListsFile* elementCMakeLists = dynamic_cast<modelCDMCMakeListsFile*>(element);
728                                   if(elementCMakeLists != NULL)
729                                     {
730                                       //create element description
731                                       description = new wxCDMCMakeListsDescriptionPanel(
732                                           this,
733                                           elementCMakeLists,
734                                           ID_WINDOW_PROPERTIES,
735                                           wxT("Description Panel"),
736                                           wxDefaultPosition,
737                                           wxSize(600, 400),
738                                           0
739                                       );
740                                     }
741                                   else
742                                     {
743                                       //folder
744                                       modelCDMFolder* elementFolder = dynamic_cast<modelCDMFolder*>(element);
745                                       if(elementFolder != NULL)
746                                         {
747                                           //create element description
748                                           description = new wxCDMFolderDescriptionPanel(
749                                               this,
750                                               elementFolder,
751                                               ID_WINDOW_PROPERTIES,
752                                               wxT("Description Panel"),
753                                               wxDefaultPosition,
754                                               wxSize(600, 400),
755                                               0
756                                           );
757                                         }
758                                       else
759                                         {
760                                           //file
761                                           modelCDMFile* elementFile = dynamic_cast<modelCDMFile*>(element);
762                                           if(elementFile != NULL)
763                                             {
764                                               //create element description
765                                               description = new wxCDMFileDescriptionPanel(
766                                                   this,
767                                                   elementFile,
768                                                   ID_WINDOW_PROPERTIES,
769                                                   wxT("Description Panel"),
770                                                   wxDefaultPosition,
771                                                   wxSize(600, 400),
772                                                   0
773                                               );
774                                             }
775                                           else
776                                             {
777
778                                               //main if not any
779                                               //create element description
780                                               description = new wxCDMMainDescriptionPanel(
781                                                   this,
782                                                   ID_WINDOW_PROPERTIES,
783                                                   wxT("Description Panel"),
784                                                   wxDefaultPosition,
785                                                   wxSize(600, 400),
786                                                   0
787                                               );
788                                             }
789                                         }
790                                     }
791                                 }
792                             }
793                         }
794                     }
795                 }
796             }
797         }
798
799       //delete old view
800       if(this->panel_Properties!= NULL)
801         {
802           this->panel_Properties->Hide();
803           auiManager.DetachPane(this->panel_Properties);
804           this->panel_Properties->Destroy();
805           this->panel_Properties = NULL;
806         }
807       //set new view
808       auiManager.AddPane(description, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
809       this->panel_Properties = description;
810
811       auiManager.Update();
812       event.Skip();
813     }
814
815   return;
816
817 }
818
819 void wxCDMMainFrame::OnChangeView(wxCommandEvent& event)
820 {
821   modelCDMIProjectTreeNode* myItem = NULL;
822   switch(event.GetId())
823   {
824   case 0:
825     myItem = ((modelCDMIProjectTreeNode*)event.GetClientData());
826     //select out old one to generate selection event
827     this->tree_Projects->Unselect();
828     this->tree_Projects->SelectItem(myItem->GetId(), true);
829     this->tree_Projects->Expand(myItem->GetId());
830     break;
831   case 1:
832     wxPanel* description = NULL;
833     if(event.GetString() == wxT("manage_packages"))
834       {
835         //this->tree_Projects->Expand(this->model->GetProject()->GetId());
836         //this->tree_Projects->Unselect();
837         description = new wxCDMPackageManagerPanel(
838             this,
839             this->model->GetProject(),
840             ID_WINDOW_PROPERTIES,
841             wxT("Description Panel"),
842             wxDefaultPosition,
843             wxSize(600, 400),
844             0
845         );
846       }
847     else if(event.GetString() == wxT("manage_libraries"))
848       {
849         this->tree_Projects->SelectItem(this->model->GetProject()->GetLib()->GetId(), true);
850         this->tree_Projects->Expand(this->model->GetProject()->GetLib()->GetId());
851         break;
852       }
853     else if(event.GetString() == wxT("manage_applications"))
854       {
855         this->tree_Projects->SelectItem(this->model->GetProject()->GetAppli()->GetId(), true);
856         this->tree_Projects->Expand(this->model->GetProject()->GetAppli()->GetId());
857         break;
858       }
859     else if(event.GetString() == wxT("blackbox"))
860       {
861         modelCDMBlackBox* bb = (modelCDMBlackBox*)event.GetClientData();
862         description = new wxCDMBlackBoxDescriptionPanel(
863             this,
864             bb,
865             ID_WINDOW_PROPERTIES,
866             wxT("Description Panel"),
867             wxDefaultPosition,
868             wxSize(600, 400),
869             0
870         );
871       }
872
873     //delete old view
874     if(this->panel_Properties!= NULL)
875       {
876         this->panel_Properties->Hide();
877         auiManager.DetachPane(this->panel_Properties);
878         this->panel_Properties->Destroy();
879         this->panel_Properties = NULL;
880       }
881     //set new view
882     auiManager.AddPane(description, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
883     this->panel_Properties = description;
884     auiManager.Update();
885
886     break;
887   }
888   event.Skip();
889 }
890
891 void wxCDMMainFrame::OnElementSelected(wxCommandEvent& event)
892 {
893   //std::cout << "element " << event.GetInt() << std::endl;
894   modelCDMIProjectTreeNode* item = (modelCDMIProjectTreeNode*)event.GetClientData();
895   this->tree_Projects->EnsureVisible(item->GetId());
896   this->tree_Projects->SetItemBold(item->GetId(), true);
897   this->tree_Projects->SetItemTextColour(item->GetId(), wxColour(0,0,255));
898   this->tree_Projects->SetItemBackgroundColour(item->GetId(), wxColour(230,230,255));
899   this->tree_Projects->UpdateWindowUI(wxUPDATE_UI_RECURSE);
900   auiManager.Update();
901 }
902
903 void wxCDMMainFrame::OnElementDeselected(wxCommandEvent& event)
904 {
905   modelCDMIProjectTreeNode* item = (modelCDMIProjectTreeNode*)event.GetClientData();
906   this->tree_Projects->SetItemBold(item->GetId(), false);
907   this->tree_Projects->SetItemTextColour(item->GetId(), wxColour(0,0,0));
908   this->tree_Projects->SetItemBackgroundColour(item->GetId(), wxColour(255,255,255));
909   this->tree_Projects->UpdateWindowUI(wxUPDATE_UI_RECURSE);
910   auiManager.Update();
911 }
912
913 void wxCDMMainFrame::OnMenuToggleHelp(wxCommandEvent& event)
914 {
915   this->help = !this->help;
916   this->menu_Help->Check(ID_MENU_TOGGLE_HELP, this->help);
917 }
918
919 void wxCDMMainFrame::OnDisableHelp(wxCommandEvent& event)
920 {
921   if (event.GetInt())
922     this->help = false;
923   else
924     this->help = true;
925
926   this->menu_Help->Check(ID_MENU_TOGGLE_HELP, this->help);
927 }