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