]> 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   this->tree_Projects->Unselect();
156   this->actualTreeItem.Unset();
157 }
158
159 void wxCDMMainFrame::CreateMenus()
160 {
161   wxMenuBar* menuBar = new wxMenuBar;
162
163   //FileMenu
164   menu_File = new wxMenu();
165   menu_File->Append(ID_MENU_NEW_PROJECT, wxT("&New Project..."));
166   menu_File->Append(ID_MENU_OPEN_PROJECT, wxT("&Open Project..."));
167   menu_File->AppendSeparator();
168   menu_File->Append(ID_MENU_CLOSE_PROJECT, wxT("&Close Project"));
169   menu_File->AppendSeparator();
170   menu_File->Append(ID_MENU_EXPORT_HIERARCHY, wxT("&Export Project Hierarchy..."));
171   menu_File->AppendSeparator();
172   menu_File->Append(ID_MENU_EXIT, wxT("E&xit"));
173
174   menuBar->Append(menu_File, wxT("&File"));
175
176   //EditMenu
177   menu_Edit = new wxMenu();
178   menu_Edit->Append(ID_MENU_REFRESH_PROJECT, wxT("&Refresh Project"));
179
180   menuBar->Append(menu_Edit, wxT("&Edit"));
181
182   //ToolsMenu
183   menu_Tools = new wxMenu();
184   menu_Tools->Append(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxT("BBTK &Graphical Editor"));
185   menu_Tools->Append(ID_MENU_MINITOOLS, wxT("&MiniTools"));
186   menu_Tools->Append(ID_MENU_CODE_EDITOR, wxT("&Code Editor"));
187   menu_Tools->Append(ID_MENU_COMMAND_LINE, wxT("&Command Line"));
188
189   menuBar->Append(menu_Tools, wxT("&Tools"));
190
191   //HelpMenu
192   menu_Help = new wxMenu();
193   menu_Help->AppendCheckItem(ID_MENU_TOGGLE_HELP, wxT("He&lp Dialogs"));
194   menu_Help->Check(ID_MENU_TOGGLE_HELP, this->help);
195   menu_Help->Append(ID_MENU_HELP, wxT("&Help"));
196   menu_Help->Append(ID_MENU_REPORT_BUG, wxT("Report &Bug"));
197   menu_Help->Append(ID_MENU_ABOUT_CREADEVMANAGER, wxT("&About CreaDevManager"));
198   menu_Help->Append(ID_MENU_ABOUT_CREATIS, wxT("A&bout CREATIS"));
199
200   menuBar->Append(menu_Help, wxT("&Help"));
201
202   //Set Bar
203   SetMenuBar(menuBar);
204
205   wxStatusBar* statusBar = new wxStatusBar(this, ID_STATUS_BAR, wxST_SIZEGRIP);
206   statusBar->SetFieldsCount(1);
207   SetStatusBar(statusBar);
208
209 }
210
211 void wxCDMMainFrame::CreateControls()
212 {
213
214   auiManager.SetManagedWindow(this);
215
216
217   tree_Projects = new wxCDMProjectsTreeCtrl(
218       this,
219       ID_TREE_PROJECTS,
220       wxDefaultPosition,
221       wxSize(200,400),
222           wxTR_HAS_BUTTONS | wxTR_AQUA_BUTTONS
223   );
224   this->actualTreeItem.Unset();
225
226   panel_Properties = new wxCDMMainDescriptionPanel(
227       this,
228       ID_WINDOW_PROPERTIES,
229       wxT("Description Panel"),
230       wxDefaultPosition,
231       wxSize(400, 600),
232       0
233   );
234
235   auiManager.AddPane(panel_Properties, wxAuiPaneInfo().BestSize(600,400).CenterPane().Name(wxT("panel_Properties")).Caption(wxT("")).CloseButton(false));
236   auiManager.AddPane(tree_Projects, wxAuiPaneInfo().Right().MinSize(300,300).BestSize(300,400).CloseButton(false).Name(wxT("tree_Projects")).Caption(wxT("Project Tree")).CloseButton(false));
237   auiManager.Update();
238   //auiManager.LoadPerspective(pers,true);
239   wxToolTip::Enable(true);
240   wxToolTip::SetDelay(0);
241 }
242
243 //Event Handlers
244 //File menu
245 void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
246 {
247   std::string* result;
248
249   wxCDMNewProjectDialog* dialog = new wxCDMNewProjectDialog(this);
250   long userResponse;
251   userResponse = dialog->ShowModal();
252
253   if(userResponse == wxID_FORWARD)
254     {
255       //create project
256       if(this->model->GetProject() != NULL)
257         {
258           if(!this->model->CloseProject(result))
259             {
260               std::cout << "error closing project: " << *result << std::endl;
261               wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR);
262               event.Skip();
263               return;
264             }
265         }
266
267
268       if(!this->model->CreateProject(
269           crea::wx2std(dialog->GetProjectName()),
270           crea::wx2std(dialog->GetProjectLocation()),
271           result,
272           crea::wx2std(dialog->GetPackageAuthor()),
273           crea::wx2std(dialog->GetPackageDescription())
274       ))
275         {
276           std::cout << "error opening project: " << *result << std::endl;
277           wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR);
278           event.Skip();
279           return;
280         }
281       
282       //show project actions panel
283       if(this->panel_ProjectActions != NULL)
284         {
285           auiManager.DetachPane(this->panel_Properties);
286           this->panel_ProjectActions->Destroy();
287           this->panel_ProjectActions = NULL;
288         }
289           
290       panel_ProjectActions = new wxCDMProjectActionsPanel(
291           this,
292           this->model->GetProject(),
293           ID_WINDOW_PROJ_ACTIONS,
294           wxT("Project Actions Panel"),
295           wxDefaultPosition,
296           wxSize(800,200),
297           0
298       );
299       
300       auiManager.AddPane(panel_ProjectActions, wxAuiPaneInfo().Bottom().MinSize(800,50).Name(wxT("panel_ProjectActions")).Caption(wxT("General Project Actions")).BestSize(800,70).CloseButton(false));
301       auiManager.Update();
302
303       //populate tree control
304       tree_Projects->Unselect();
305           this->actualTreeItem.Unset();
306           tree_Projects->BuildTree(this->model->GetModelElements(),this->model->GetProject());
307           tree_Projects->SelectItem(this->model->GetProject()->GetId().GetWxId());
308           //wxMessageBox(wxT("ProjectSelected") ,_T("New Project - Success!"),wxOK | wxICON_ERROR);
309     }
310 }
311 void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
312 {
313   std::string* result;
314
315   long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
316   wxDirDialog* FD = new wxDirDialog(this, wxT("Select the project directory"), wxT(""), style);
317   long userResponse = FD->ShowModal();
318   if(userResponse == wxID_OK)
319     {
320       std::string path = crea::wx2std (FD->GetPath());
321       FD -> Destroy();
322       FD = NULL;
323
324       std::cout << "Selection to open: " << path << std::endl;
325
326
327       //populate model
328       if(this->model->GetProject() != NULL)
329         {
330           std::cout << "Project not null, closing it" << std::endl;
331           if(!this->model->CloseProject(result))
332             {
333               std::cout << "error closing project: " << *result << std::endl;
334               wxMessageBox(crea::std2wx(result->c_str()),_T("New Project - Error!"),wxOK | wxICON_ERROR);
335               event.Skip();
336               return;
337             }
338         }
339
340       if (!this->model->OpenProject(path, result))
341         {
342           std::cout << "error opening project: " << *result << std::endl;
343           wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR);
344           event.Skip();
345           return;
346         };
347
348       std::cout << "building ui" << std::endl;
349
350       //populate tree control
351           tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
352           tree_Projects->Unselect();
353           this->actualTreeItem.Unset();
354           tree_Projects->SelectItem(this->model->GetProject()->GetId().GetWxId(), true);
355
356
357       //change project's actions panel
358       if(this->panel_ProjectActions!= NULL)
359         {
360           auiManager.DetachPane(this->panel_ProjectActions);
361           this->panel_ProjectActions->Destroy();
362           this->panel_ProjectActions = NULL;
363         }
364       panel_ProjectActions = new wxCDMProjectActionsPanel(
365           this,
366           this->model->GetProject(),
367           ID_WINDOW_PROJ_ACTIONS,
368           wxT("Project Actions Panel"),
369           wxDefaultPosition,
370           wxSize(800,200),
371           0
372       );
373       panel_ProjectActions->SetMinSize(wxSize(500, 100));
374
375
376       auiManager.AddPane(panel_ProjectActions, wxAuiPaneInfo().Bottom().MinSize(800,50).Name(wxT("panel_ProjectActions")).Caption(wxT("General Project Actions")).BestSize(800,70).CloseButton(false));
377
378       auiManager.Update();
379
380     }
381 }
382
383 void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event)
384 {
385   std::cout << "closing project" << std::endl;
386   std::string* result;
387   if(!this->model->CloseProject(result))
388     {
389       std::cout << "error closing project: " << *result << std::endl;
390       wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
391     }
392
393   tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
394   this->actualTreeItem.Unset();
395   if(this->panel_Properties != NULL)
396     {
397       auiManager.DetachPane(this->panel_Properties);
398           this->panel_Properties->Hide();
399     }
400   if(this->panel_ProjectActions != NULL)
401     {
402       auiManager.DetachPane(this->panel_ProjectActions);
403       this->panel_ProjectActions->Hide();    
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 }
419
420 void wxCDMMainFrame::OnMenuExportHierarchy(wxCommandEvent& event)
421 {
422   std::cerr << "Event OnMenuExportHierarchy not implemented" << std::endl;
423   event.Skip();
424 }
425 void wxCDMMainFrame::OnMenuExit(wxCommandEvent& event)
426 {
427   std::cout << "Closing CreaDevManager..." << std::endl;
428   std::string* result;
429   if(this->model->GetProject() != NULL && !this->model->CloseProject(result))
430     {
431       std::cout << "error closing project: " << *result << std::endl;
432     }
433
434   if(this->panel_Properties != NULL)
435     {
436       auiManager.DetachPane(this->panel_Properties);
437       this->panel_Properties->Destroy();
438       this->panel_Properties = NULL;
439     }
440   
441   if(this->tree_Projects != NULL)
442     {
443       auiManager.DetachPane(this->tree_Projects);
444       this->tree_Projects->Destroy();
445       this->tree_Projects = NULL;
446     }
447
448   if(this->panel_ProjectActions != NULL)
449     {
450       auiManager.DetachPane(this->panel_ProjectActions);
451       this->panel_ProjectActions->Destroy();
452       this->panel_ProjectActions = NULL;
453     }
454   
455   Close();
456 }
457
458 //Edit Menu
459 void wxCDMMainFrame::OnMenuRefreshProject(wxCommandEvent& event)
460 {
461   std::string* result;
462   if(!model->RefreshProject(result))
463     {
464       wxMessageBox( crea::std2wx(result->c_str()), wxT("Refresh Project - Error"), wxICON_ERROR);
465     }
466   if(this->model->GetProject() != NULL)
467     {
468       this->tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
469       this->auiManager.Update();
470
471       this->tree_Projects->Unselect();
472           this->actualTreeItem.Unset();
473       this->tree_Projects->SelectItem(this->model->GetProject()->GetId().GetWxId(), 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   //std::cout << "Tree Selection id: " << elementId.m_pItem << this->actualTreeItem.m_pItem << std::endl;
594   //elementId.IsOk() && this->tree_Projects->IsSelected(elementId)
595   if(elementId.IsOk() && this->actualTreeItem != elementId)
596     {
597       
598       //std::cout << "Valid tree selection id: " << elementId.m_pItem << std::endl;
599       //get element from model
600       modelCDMIProjectTreeNode* element = this->model->GetModelElements()[elementId];
601
602           if (element == NULL)
603                   return;
604       std::cout << "Tree Selection: " << element->GetName() << std::endl;
605
606           //std::stringstream ss;
607           //ss << this->actualTreeItem.m_pItem << ":" << event.GetOldItem().m_pItem << " --> " << elementId.m_pItem;
608           //wxMessageBox( wxT("Tree Selection id: " + ss.str() + " by " + element->GetName()), wxT("Refresh Project - Error"), wxICON_ERROR);   
609       this->actualTreeItem = elementId;
610
611           //get element type
612       //project
613       modelCDMProject* elementProject = dynamic_cast<modelCDMProject*>(element);
614       wxPanel* description;
615       if(elementProject != NULL)
616         {
617           //create element description
618           description = new wxCDMProjectDescriptionPanel(
619               this,
620               elementProject,
621               ID_WINDOW_PROPERTIES,
622               wxT("Description Panel"),
623               wxDefaultPosition,
624               wxSize(600, 400),
625               0
626           );
627
628         }
629       else
630         {
631           //appli
632           modelCDMAppli* elementAppli = dynamic_cast<modelCDMAppli*>(element);
633           if(elementAppli != NULL)
634             {
635               //create element description
636               description = new wxCDMAppliDescriptionPanel(
637                   this,
638                   elementAppli,
639                   ID_WINDOW_PROPERTIES,
640                   wxT("Description Panel"),
641                   wxDefaultPosition,
642                   wxSize(600, 400),
643                   0
644               );
645
646             }
647           else
648             {
649               //application
650               modelCDMApplication* elementApplication = dynamic_cast<modelCDMApplication*>(element);
651                           if(elementApplication != NULL)
652                 {
653                   //create element description
654                   description = new wxCDMApplicationDescriptionPanel(
655                       this,
656                       elementApplication,
657                       ID_WINDOW_PROPERTIES,
658                       wxT("Description Panel"),
659                       wxDefaultPosition,
660                       wxSize(600, 400),
661                       0
662                   );
663                 }
664               else
665                 {
666                   //lib
667                   modelCDMLib* elementLib = dynamic_cast<modelCDMLib*>(element);
668                   if(elementLib != NULL)
669                     {
670                       //create element description
671                       description = new wxCDMLibDescriptionPanel(
672                           this,
673                           elementLib,
674                           ID_WINDOW_PROPERTIES,
675                           wxT("Description Panel"),
676                           wxDefaultPosition,
677                           wxSize(600, 400),
678                           0
679                       );
680                     }
681                   else
682                     {
683                       //library
684                       modelCDMLibrary* elementLibrary = dynamic_cast<modelCDMLibrary*>(element);
685                       if(elementLibrary != NULL)
686                         {
687                           //create element description
688                           description = new wxCDMLibraryDescriptionPanel(
689                               this,
690                               elementLibrary,
691                               ID_WINDOW_PROPERTIES,
692                               wxT("Description Panel"),
693                               wxDefaultPosition,
694                               wxSize(600, 400),
695                               0
696                           );
697                         }
698                       else
699                         {
700                           //package
701                           modelCDMPackage* elementPackage = dynamic_cast<modelCDMPackage*>(element);
702                           if(elementPackage != NULL)
703                             {
704                               //create element description
705                               description = new wxCDMPackageDescriptionPanel(
706                                   this,
707                                   elementPackage,
708                                   ID_WINDOW_PROPERTIES,
709                                   wxT("Description Panel"),
710                                   wxDefaultPosition,
711                                   wxSize(600, 400),
712                                   0
713                               );
714                             }
715                           else
716                             {
717                               //black box
718                               modelCDMBlackBox* elementBlackBox = dynamic_cast<modelCDMBlackBox*>(element);
719                               if(elementBlackBox != NULL)
720                                 {
721                                   //create element description
722                                   description = new wxCDMBlackBoxDescriptionPanel(
723                                       this,
724                                       elementBlackBox,
725                                       ID_WINDOW_PROPERTIES,
726                                       wxT("Description Panel"),
727                                       wxDefaultPosition,
728                                       wxSize(600, 400),
729                                       0
730                                   );
731                                 }
732                               else
733                                 {
734                                   //CMakeLists
735                                   modelCDMCMakeListsFile* elementCMakeLists = dynamic_cast<modelCDMCMakeListsFile*>(element);
736                                   if(elementCMakeLists != NULL)
737                                     {
738                                       //create element description
739                                       description = new wxCDMCMakeListsDescriptionPanel(
740                                           this,
741                                           elementCMakeLists,
742                                           ID_WINDOW_PROPERTIES,
743                                           wxT("Description Panel"),
744                                           wxDefaultPosition,
745                                           wxSize(600, 400),
746                                           0
747                                       );
748                                     }
749                                   else
750                                     {
751                                       //folder
752                                       modelCDMFolder* elementFolder = dynamic_cast<modelCDMFolder*>(element);
753                                       if(elementFolder != NULL)
754                                         {
755                                           //create element description
756                                           description = new wxCDMFolderDescriptionPanel(
757                                               this,
758                                               elementFolder,
759                                               ID_WINDOW_PROPERTIES,
760                                               wxT("Description Panel"),
761                                               wxDefaultPosition,
762                                               wxSize(600, 400),
763                                               0
764                                           );
765                                         }
766                                       else
767                                         {
768                                           //file
769                                           modelCDMFile* elementFile = dynamic_cast<modelCDMFile*>(element);
770                                           if(elementFile != NULL)
771                                             {
772                                               //create element description
773                                               description = new wxCDMFileDescriptionPanel(
774                                                   this,
775                                                   elementFile,
776                                                   ID_WINDOW_PROPERTIES,
777                                                   wxT("Description Panel"),
778                                                   wxDefaultPosition,
779                                                   wxSize(600, 400),
780                                                   0
781                                               );
782                                             }
783                                           else
784                                             {
785
786                                               //main if not any
787                                               //create element description
788                                               description = new wxCDMMainDescriptionPanel(
789                                                   this,
790                                                   ID_WINDOW_PROPERTIES,
791                                                   wxT("Description Panel"),
792                                                   wxDefaultPosition,
793                                                   wxSize(600, 400),
794                                                   0
795                                               );
796                                             }
797                                         }
798                                     }
799                                 }
800                             }
801                         }
802                     }
803                 }
804             }
805         }
806
807       //delete old view
808       if(this->panel_Properties!= NULL)
809         {
810           this->panel_Properties->Hide();
811           auiManager.DetachPane(this->panel_Properties);
812           //this->panel_Properties->Destroy();
813           //this->panel_Properties = NULL;
814         }
815       //set new view
816       auiManager.AddPane(description, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
817       this->panel_Properties = description;
818
819       auiManager.Update();
820     }
821   else
822     {
823       event.Skip();
824         }
825
826   return;
827
828 }
829
830 void wxCDMMainFrame::OnChangeView(wxCommandEvent& event)
831 {
832   modelCDMIProjectTreeNode* myItem = NULL;
833   wxPanel* description = NULL;
834   switch(event.GetId())
835   {
836   case 0:
837     myItem = ((modelCDMIProjectTreeNode*)event.GetClientData());
838     //select out old one to generate selection event
839     this->tree_Projects->Unselect();
840     this->tree_Projects->SelectItem(myItem->GetId().GetWxId());
841     this->tree_Projects->Expand(myItem->GetId().GetWxId());
842     break;
843   case 1:
844     
845     if(event.GetString() == wxT("manage_packages"))
846       {
847         //this->tree_Projects->Expand(this->model->GetProject()->GetId());
848         //this->tree_Projects->Unselect();
849         this->actualTreeItem.Unset();
850                   description = new wxCDMPackageManagerPanel(
851             this,
852             this->model->GetProject(),
853             ID_WINDOW_PROPERTIES,
854             wxT("Description Panel"),
855             wxDefaultPosition,
856             wxSize(600, 400),
857             0
858         );
859       }
860     else if(event.GetString() == wxT("manage_libraries"))
861       {
862         this->tree_Projects->SelectItem(this->model->GetProject()->GetLib()->GetId().GetWxId());
863         this->tree_Projects->Expand(this->model->GetProject()->GetLib()->GetId().GetWxId());
864         break;
865       }
866     else if(event.GetString() == wxT("manage_applications"))
867       {
868         this->tree_Projects->SelectItem(this->model->GetProject()->GetAppli()->GetId().GetWxId());
869         this->tree_Projects->Expand(this->model->GetProject()->GetAppli()->GetId().GetWxId());
870         break;
871       }
872     else if(event.GetString() == wxT("blackbox"))
873       {
874         modelCDMBlackBox* bb = (modelCDMBlackBox*)event.GetClientData();
875                 this->actualTreeItem.Unset();
876         description = new wxCDMBlackBoxDescriptionPanel(
877             this,
878             bb,
879             ID_WINDOW_PROPERTIES,
880             wxT("Description Panel"),
881             wxDefaultPosition,
882             wxSize(600, 400),
883             0
884         );
885                 
886       }
887
888     //delete old view
889     if(this->panel_Properties!= NULL)
890       {
891         this->panel_Properties->Hide();
892         auiManager.DetachPane(this->panel_Properties);
893         this->panel_Properties->Destroy();
894         this->panel_Properties = NULL;
895       }
896     //set new view
897     auiManager.AddPane(description, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
898     this->panel_Properties = description;
899     auiManager.Update();
900     break;
901   default:
902           event.Skip();
903   }
904   
905 }
906
907 void wxCDMMainFrame::OnElementSelected(wxCommandEvent& event)
908 {
909   //std::cout << "element " << event.GetInt() << std::endl;
910   modelCDMIProjectTreeNode* item = (modelCDMIProjectTreeNode*)event.GetClientData();
911   this->tree_Projects->EnsureVisible(item->GetId().GetWxId());
912   this->tree_Projects->SetItemBold(item->GetId().GetWxId(), true);
913   this->tree_Projects->SetItemTextColour(item->GetId().GetWxId(), wxColour(0,0,255));
914   this->tree_Projects->SetItemBackgroundColour(item->GetId().GetWxId(), wxColour(230,230,255));
915   this->tree_Projects->UpdateWindowUI(wxUPDATE_UI_RECURSE);
916   auiManager.Update();
917 }
918
919 void wxCDMMainFrame::OnElementDeselected(wxCommandEvent& event)
920 {
921   modelCDMIProjectTreeNode* item = (modelCDMIProjectTreeNode*)event.GetClientData();
922   this->tree_Projects->SetItemBold(item->GetId().GetWxId(), false);
923   this->tree_Projects->SetItemTextColour(item->GetId().GetWxId(), wxColour(0,0,0));
924   this->tree_Projects->SetItemBackgroundColour(item->GetId().GetWxId(), wxColour(255,255,255));
925   this->tree_Projects->UpdateWindowUI(wxUPDATE_UI_RECURSE);
926   auiManager.Update();
927 }
928
929 void wxCDMMainFrame::OnMenuToggleHelp(wxCommandEvent& event)
930 {
931   this->help = !this->help;
932   this->menu_Help->Check(ID_MENU_TOGGLE_HELP, this->help);
933 }
934
935 void wxCDMMainFrame::OnDisableHelp(wxCommandEvent& event)
936 {
937   if (event.GetInt())
938     this->help = false;
939   else
940     this->help = true;
941
942   this->menu_Help->Check(ID_MENU_TOGGLE_HELP, this->help);
943 }