]> 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           if(this->panel_Properties != NULL)
266             {
267               auiManager.DetachPane(this->panel_Properties);
268               this->panel_Properties->Hide();
269             }
270           if(this->panel_ProjectActions != NULL)
271             {
272               auiManager.DetachPane(this->panel_ProjectActions);
273               this->panel_ProjectActions->Hide();    
274             }
275
276         }
277
278
279       if(!this->model->CreateProject(
280           crea::wx2std(dialog->GetProjectName()),
281           crea::wx2std(dialog->GetProjectLocation()),
282           result,
283           crea::wx2std(dialog->GetPackageAuthor()),
284           crea::wx2std(dialog->GetPackageDescription())
285       ))
286         {
287           std::cout << "error opening project: " << *result << std::endl;
288           wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR);
289           event.Skip();
290           return;
291         }
292       
293       //show project actions panel
294       if(this->panel_ProjectActions != NULL)
295         {
296           auiManager.DetachPane(this->panel_Properties);
297           this->panel_ProjectActions->Destroy();
298           this->panel_ProjectActions = NULL;
299         }
300           
301       panel_ProjectActions = new wxCDMProjectActionsPanel(
302           this,
303           this->model->GetProject(),
304           ID_WINDOW_PROJ_ACTIONS,
305           wxT("Project Actions Panel"),
306           wxDefaultPosition,
307           wxSize(800,200),
308           0
309       );
310       
311       auiManager.AddPane(panel_ProjectActions, wxAuiPaneInfo().Bottom().MinSize(800,50).Name(wxT("panel_ProjectActions")).Caption(wxT("General Project Actions")).BestSize(800,70).CloseButton(false));
312       auiManager.Update();
313
314       //populate tree control
315           tree_Projects->BuildTree(this->model->GetModelElements(),this->model->GetProject());
316       tree_Projects->Unselect();
317           this->actualTreeItem.Unset();
318           tree_Projects->SelectItem(this->model->GetProject()->GetId().GetWxId(), true);
319           //wxMessageBox(wxT("ProjectSelected") ,_T("New Project - Success!"),wxOK | wxICON_ERROR);
320     }
321 }
322 void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
323 {
324   std::string* result;
325
326   long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
327   wxDirDialog* FD = new wxDirDialog(this, wxT("Select the project directory"), wxT(""), style);
328   long userResponse = FD->ShowModal();
329   if(userResponse == wxID_OK)
330     {
331       std::string path = crea::wx2std (FD->GetPath());
332       FD -> Destroy();
333       FD = NULL;
334
335       std::cout << "Selection to open: " << path << std::endl;
336
337
338       //populate model
339       if(this->model->GetProject() != NULL)
340         {
341           std::cout << "Project not null, closing it" << std::endl;
342           if(!this->model->CloseProject(result))
343             {
344               std::cout << "error closing project: " << *result << std::endl;
345               wxMessageBox(crea::std2wx(result->c_str()),_T("New Project - Error!"),wxOK | wxICON_ERROR);
346               event.Skip();
347               return;
348             }
349           if(this->panel_Properties != NULL)
350             {
351               auiManager.DetachPane(this->panel_Properties);
352               this->panel_Properties->Hide();
353             }
354           if(this->panel_ProjectActions != NULL)
355             {
356               auiManager.DetachPane(this->panel_ProjectActions);
357               this->panel_ProjectActions->Hide();    
358             }
359         }
360
361       if (!this->model->OpenProject(path, result))
362         {
363           std::cout << "error opening project: " << *result << std::endl;
364           wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR);
365           event.Skip();
366           return;
367         };
368
369       std::cout << "building ui" << std::endl;
370
371       //populate tree control
372       tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
373       tree_Projects->Unselect();
374       this->actualTreeItem.Unset();
375           tree_Projects->SelectItem(this->model->GetProject()->GetId().GetWxId(), true);
376
377
378       //change project's actions panel
379       if(this->panel_ProjectActions!= NULL)
380         {
381           auiManager.DetachPane(this->panel_ProjectActions);
382           this->panel_ProjectActions->Destroy();
383           this->panel_ProjectActions = NULL;
384         }
385       panel_ProjectActions = new wxCDMProjectActionsPanel(
386           this,
387           this->model->GetProject(),
388           ID_WINDOW_PROJ_ACTIONS,
389           wxT("Project Actions Panel"),
390           wxDefaultPosition,
391           wxSize(800,200),
392           0
393       );
394       panel_ProjectActions->SetMinSize(wxSize(500, 100));
395
396
397       auiManager.AddPane(panel_ProjectActions, wxAuiPaneInfo().Bottom().MinSize(800,50).Name(wxT("panel_ProjectActions")).Caption(wxT("General Project Actions")).BestSize(800,70).CloseButton(false));
398
399       auiManager.Update();
400
401     }
402 }
403
404 void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event)
405 {
406   std::cout << "closing project" << std::endl;
407   std::string* result;
408   if(!this->model->CloseProject(result))
409     {
410       std::cout << "error closing project: " << *result << std::endl;
411       wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
412     }
413
414   tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
415   this->actualTreeItem.Unset();
416   if(this->panel_Properties != NULL)
417     {
418       auiManager.DetachPane(this->panel_Properties);
419           this->panel_Properties->Hide();
420     }
421   if(this->panel_ProjectActions != NULL)
422     {
423       auiManager.DetachPane(this->panel_ProjectActions);
424       this->panel_ProjectActions->Hide();    
425     }
426
427   this->panel_Properties = new wxCDMMainDescriptionPanel(
428       this,
429       ID_WINDOW_PROPERTIES,
430       wxT("Description Panel"),
431       wxDefaultPosition,
432       wxSize(600, 400),
433       0
434   );
435
436   auiManager.AddPane(panel_Properties, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
437
438   auiManager.Update();
439 }
440
441 void wxCDMMainFrame::OnMenuExportHierarchy(wxCommandEvent& event)
442 {
443   std::cerr << "Event OnMenuExportHierarchy not implemented" << std::endl;
444   event.Skip();
445 }
446 void wxCDMMainFrame::OnMenuExit(wxCommandEvent& event)
447 {
448   std::cout << "Closing CreaDevManager..." << std::endl;
449   std::string* result;
450   if(this->model->GetProject() != NULL && !this->model->CloseProject(result))
451     {
452       std::cout << "error closing project: " << *result << std::endl;
453     }
454
455   if(this->panel_Properties != NULL)
456     {
457       auiManager.DetachPane(this->panel_Properties);
458       this->panel_Properties->Destroy();
459       this->panel_Properties = NULL;
460     }
461   
462   if(this->tree_Projects != NULL)
463     {
464       auiManager.DetachPane(this->tree_Projects);
465       this->tree_Projects->Destroy();
466       this->tree_Projects = NULL;
467     }
468
469   if(this->panel_ProjectActions != NULL)
470     {
471       auiManager.DetachPane(this->panel_ProjectActions);
472       this->panel_ProjectActions->Destroy();
473       this->panel_ProjectActions = NULL;
474     }
475   
476   Close();
477 }
478
479 //Edit Menu
480 void wxCDMMainFrame::OnMenuRefreshProject(wxCommandEvent& event)
481 {
482   std::string* result;
483   if(!model->RefreshProject(result))
484     {
485       wxMessageBox( crea::std2wx(result->c_str()), wxT("Refresh Project - Error"), wxICON_ERROR);
486     }
487   if(this->model->GetProject() != NULL)
488     {
489       this->tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
490       this->auiManager.Update();
491
492       this->tree_Projects->Unselect();
493           this->actualTreeItem.Unset();
494       this->tree_Projects->SelectItem(this->model->GetProject()->GetId().GetWxId(), true);
495     }
496   event.Skip();
497 }
498
499 void wxCDMMainFrame::OnMenuBBTKGraphicalEditor(wxCommandEvent& event)
500 {
501   std::cerr << "Event OnMenuBBTKGraphicalEditor not implemented" << std::endl;
502   event.Skip();
503   if(CDMUtilities::openBBEditor())
504     {
505       wxMessageBox( wxT("Can't open the BB Graphical Editor. Please check your Crea Tools installation."), wxT("Refresh Project - Error"), wxICON_ERROR);
506     }
507 }
508 void wxCDMMainFrame::OnMenuMiniTools(wxCommandEvent& event)
509 {
510   if(CDMUtilities::openCreaToolsTools())
511     {
512       wxMessageBox( wxT("Can't open the Minitools. Please check your Crea Tools installation."), wxT("Refresh Project - Error"), wxICON_ERROR);
513     }
514 }
515 void wxCDMMainFrame::OnMenuCodeEditor(wxCommandEvent& event)
516 {
517   if(CDMUtilities::openTextEditor())
518     {
519       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);
520     }
521 }
522 void wxCDMMainFrame::OnMenuCommandLine(wxCommandEvent& event)
523 {
524   if(CDMUtilities::openTerminal())
525     {
526       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);
527     }
528 }
529
530 //Help Menu
531 void wxCDMMainFrame::OnMenuHelp(wxCommandEvent& event)
532 {
533   wxLaunchDefaultBrowser(_T("http://www.creatis.insa-lyon.fr/site/en/CreatoolsDocumentation"), 0);
534 }
535 void wxCDMMainFrame::OnMenuReportBug(wxCommandEvent& event)
536 {
537   wxLaunchDefaultBrowser(_T("http://vip.creatis.insa-lyon.fr:9002/projects/crea"), 0);
538 }
539 void wxCDMMainFrame::OnMenuAboutCreaDevManager(wxCommandEvent& event)
540 {
541   wxBoxSizer *topsizer;
542   wxHtmlWindow *html;
543   wxDialog dlg(this, wxID_ANY, wxString(_("About")));
544
545   topsizer = new wxBoxSizer(wxVERTICAL);
546
547   html = new wxHtmlWindow(&dlg, wxID_ANY, wxDefaultPosition, wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
548   html -> SetBorders(0);
549
550   std::string content = ""
551       "<html>"
552       "<body bgcolor=\"#3333CC\">"
553       "<table cellspacing=3 cellpadding=4 width=\"100%\">"
554       "  <tr>"
555       "    <td bgcolor=\"#3333CC\">"
556       "    <center>"
557       "    <font size=+2 color=\"#FFFFFF\"><b>CREA Development Manager</b>"
558       "    </font>"
559       "    </center>"
560       "    </td>"
561       "  </tr>"
562       "  <tr>"
563       "    <td bgcolor=\"#FFFFFF\">"
564       "    <p><b><font size=+1>Creatis 2012 - Lyon, France</font></b></p>"
565       "    <font size=-1>"
566       "      <table cellpadding=0 cellspacing=0 width=\"100%\">"
567       "        <tr>"
568       "          <td width=\"65%\">"
569       "            <p>Created by Daniel Gonz&aacute;lez - daniel.gonzalez@creatis.insa-lyon.fr</p>"
570       "          </td>"
571       "        </tr>"
572       "      </table>"
573       "      <font size=1>"
574       "        <p>This software is governed by the CeCILL-B license under French law and abiding by the rules of distribution of free software.</p>"
575       "      </font>"
576       "    </font>"
577       "    </td>"
578       "  </tr>"
579       "</table>"
580       "</body>"
581       "</html>"
582       ;
583
584   html -> SetPage(crea::std2wx(content));
585   html -> SetSize(html -> GetInternalRepresentation() -> GetWidth(),
586       html -> GetInternalRepresentation() -> GetHeight());
587
588   topsizer -> Add(html, 1, wxALL, 10);
589
590 #if wxUSE_STATLINE
591   topsizer -> Add(new wxStaticLine(&dlg, wxID_ANY), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
592 #endif // wxUSE_STATLINE
593
594   wxButton *bu1 = new wxButton(&dlg, wxID_OK, _("OK"));
595   bu1 -> SetDefault();
596
597   topsizer -> Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15);
598
599   dlg.SetSizer(topsizer);
600   topsizer -> Fit(&dlg);
601
602   dlg.ShowModal();
603 }
604 void wxCDMMainFrame::OnMenuAboutCreatis(wxCommandEvent& event)
605 {
606   wxLaunchDefaultBrowser(_T("http://www.creatis.insa-lyon.fr/site/en"), 0);
607 }
608
609 void wxCDMMainFrame::OnTreeSelectionChanged(wxTreeEvent& event)
610 {
611
612   //get selected element
613   wxTreeItemId elementId = event.GetItem();
614   //std::cout << "Tree Selection id: " << elementId.m_pItem << this->actualTreeItem.m_pItem << std::endl;
615   //elementId.IsOk() && this->tree_Projects->IsSelected(elementId)
616   if(elementId.IsOk() && this->actualTreeItem != elementId)
617     {
618       
619       //std::cout << "Valid tree selection id: " << elementId.m_pItem << std::endl;
620       //get element from model
621       modelCDMIProjectTreeNode* element = this->model->GetModelElements()[elementId];
622
623           if (element == NULL)
624                   return;
625       std::cout << "Tree Selection: " << element->GetName() << std::endl;
626
627           //std::stringstream ss;
628           //ss << this->actualTreeItem.m_pItem << ":" << event.GetOldItem().m_pItem << " --> " << elementId.m_pItem;
629           //wxMessageBox( wxT("Tree Selection id: " + ss.str() + " by " + element->GetName()), wxT("Refresh Project - Error"), wxICON_ERROR);   
630       this->actualTreeItem = elementId;
631
632           //get element type
633       //project
634       modelCDMProject* elementProject = dynamic_cast<modelCDMProject*>(element);
635       wxPanel* description;
636       if(elementProject != NULL)
637         {
638           //create element description
639           description = new wxCDMProjectDescriptionPanel(
640               this,
641               elementProject,
642               ID_WINDOW_PROPERTIES,
643               wxT("Description Panel"),
644               wxDefaultPosition,
645               wxSize(600, 400),
646               0
647           );
648
649         }
650       else
651         {
652           //appli
653           modelCDMAppli* elementAppli = dynamic_cast<modelCDMAppli*>(element);
654           if(elementAppli != NULL)
655             {
656               //create element description
657               description = new wxCDMAppliDescriptionPanel(
658                   this,
659                   elementAppli,
660                   ID_WINDOW_PROPERTIES,
661                   wxT("Description Panel"),
662                   wxDefaultPosition,
663                   wxSize(600, 400),
664                   0
665               );
666
667             }
668           else
669             {
670               //application
671               modelCDMApplication* elementApplication = dynamic_cast<modelCDMApplication*>(element);
672                           if(elementApplication != NULL)
673                 {
674                   //create element description
675                   description = new wxCDMApplicationDescriptionPanel(
676                       this,
677                       elementApplication,
678                       ID_WINDOW_PROPERTIES,
679                       wxT("Description Panel"),
680                       wxDefaultPosition,
681                       wxSize(600, 400),
682                       0
683                   );
684                 }
685               else
686                 {
687                   //lib
688                   modelCDMLib* elementLib = dynamic_cast<modelCDMLib*>(element);
689                   if(elementLib != NULL)
690                     {
691                       //create element description
692                       description = new wxCDMLibDescriptionPanel(
693                           this,
694                           elementLib,
695                           ID_WINDOW_PROPERTIES,
696                           wxT("Description Panel"),
697                           wxDefaultPosition,
698                           wxSize(600, 400),
699                           0
700                       );
701                     }
702                   else
703                     {
704                       //library
705                       modelCDMLibrary* elementLibrary = dynamic_cast<modelCDMLibrary*>(element);
706                       if(elementLibrary != NULL)
707                         {
708                           //create element description
709                           description = new wxCDMLibraryDescriptionPanel(
710                               this,
711                               elementLibrary,
712                               ID_WINDOW_PROPERTIES,
713                               wxT("Description Panel"),
714                               wxDefaultPosition,
715                               wxSize(600, 400),
716                               0
717                           );
718                         }
719                       else
720                         {
721                           //package
722                           modelCDMPackage* elementPackage = dynamic_cast<modelCDMPackage*>(element);
723                           if(elementPackage != NULL)
724                             {
725                               //create element description
726                               description = new wxCDMPackageDescriptionPanel(
727                                   this,
728                                   elementPackage,
729                                   ID_WINDOW_PROPERTIES,
730                                   wxT("Description Panel"),
731                                   wxDefaultPosition,
732                                   wxSize(600, 400),
733                                   0
734                               );
735                             }
736                           else
737                             {
738                               //black box
739                               modelCDMBlackBox* elementBlackBox = dynamic_cast<modelCDMBlackBox*>(element);
740                               if(elementBlackBox != NULL)
741                                 {
742                                   //create element description
743                                   description = new wxCDMBlackBoxDescriptionPanel(
744                                       this,
745                                       elementBlackBox,
746                                       ID_WINDOW_PROPERTIES,
747                                       wxT("Description Panel"),
748                                       wxDefaultPosition,
749                                       wxSize(600, 400),
750                                       0
751                                   );
752                                 }
753                               else
754                                 {
755                                   //CMakeLists
756                                   modelCDMCMakeListsFile* elementCMakeLists = dynamic_cast<modelCDMCMakeListsFile*>(element);
757                                   if(elementCMakeLists != NULL)
758                                     {
759                                       //create element description
760                                       description = new wxCDMCMakeListsDescriptionPanel(
761                                           this,
762                                           elementCMakeLists,
763                                           ID_WINDOW_PROPERTIES,
764                                           wxT("Description Panel"),
765                                           wxDefaultPosition,
766                                           wxSize(600, 400),
767                                           0
768                                       );
769                                     }
770                                   else
771                                     {
772                                       //folder
773                                       modelCDMFolder* elementFolder = dynamic_cast<modelCDMFolder*>(element);
774                                       if(elementFolder != NULL)
775                                         {
776                                           //create element description
777                                           description = new wxCDMFolderDescriptionPanel(
778                                               this,
779                                               elementFolder,
780                                               ID_WINDOW_PROPERTIES,
781                                               wxT("Description Panel"),
782                                               wxDefaultPosition,
783                                               wxSize(600, 400),
784                                               0
785                                           );
786                                         }
787                                       else
788                                         {
789                                           //file
790                                           modelCDMFile* elementFile = dynamic_cast<modelCDMFile*>(element);
791                                           if(elementFile != NULL)
792                                             {
793                                               //create element description
794                                               description = new wxCDMFileDescriptionPanel(
795                                                   this,
796                                                   elementFile,
797                                                   ID_WINDOW_PROPERTIES,
798                                                   wxT("Description Panel"),
799                                                   wxDefaultPosition,
800                                                   wxSize(600, 400),
801                                                   0
802                                               );
803                                             }
804                                           else
805                                             {
806
807                                               //main if not any
808                                               //create element description
809                                               description = new wxCDMMainDescriptionPanel(
810                                                   this,
811                                                   ID_WINDOW_PROPERTIES,
812                                                   wxT("Description Panel"),
813                                                   wxDefaultPosition,
814                                                   wxSize(600, 400),
815                                                   0
816                                               );
817                                             }
818                                         }
819                                     }
820                                 }
821                             }
822                         }
823                     }
824                 }
825             }
826         }
827
828       //delete old view
829       if(this->panel_Properties!= NULL)
830         {
831           this->panel_Properties->Hide();
832           auiManager.DetachPane(this->panel_Properties);
833           //this->panel_Properties->Destroy();
834           //this->panel_Properties = NULL;
835         }
836       //set new view
837       auiManager.AddPane(description, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
838       this->panel_Properties = description;
839
840       auiManager.Update();
841     }
842   else
843     {
844       event.Skip();
845         }
846
847   return;
848
849 }
850
851 void wxCDMMainFrame::OnChangeView(wxCommandEvent& event)
852 {
853   modelCDMIProjectTreeNode* myItem = NULL;
854   wxPanel* description = NULL;
855   switch(event.GetId())
856   {
857   case 0:
858     myItem = ((modelCDMIProjectTreeNode*)event.GetClientData());
859     //select out old one to generate selection event
860     this->tree_Projects->Unselect();
861     this->tree_Projects->SelectItem(myItem->GetId().GetWxId());
862     this->tree_Projects->Expand(myItem->GetId().GetWxId());
863     break;
864   case 1:
865     
866     if(event.GetString() == wxT("manage_packages"))
867       {
868         //this->tree_Projects->Expand(this->model->GetProject()->GetId());
869         //this->tree_Projects->Unselect();
870         this->actualTreeItem.Unset();
871                   description = new wxCDMPackageManagerPanel(
872             this,
873             this->model->GetProject(),
874             ID_WINDOW_PROPERTIES,
875             wxT("Description Panel"),
876             wxDefaultPosition,
877             wxSize(600, 400),
878             0
879         );
880       }
881     else if(event.GetString() == wxT("manage_libraries"))
882       {
883         this->tree_Projects->SelectItem(this->model->GetProject()->GetLib()->GetId().GetWxId());
884         this->tree_Projects->Expand(this->model->GetProject()->GetLib()->GetId().GetWxId());
885         break;
886       }
887     else if(event.GetString() == wxT("manage_applications"))
888       {
889         this->tree_Projects->SelectItem(this->model->GetProject()->GetAppli()->GetId().GetWxId());
890         this->tree_Projects->Expand(this->model->GetProject()->GetAppli()->GetId().GetWxId());
891         break;
892       }
893     else if(event.GetString() == wxT("blackbox"))
894       {
895         modelCDMBlackBox* bb = (modelCDMBlackBox*)event.GetClientData();
896                 this->actualTreeItem.Unset();
897         description = new wxCDMBlackBoxDescriptionPanel(
898             this,
899             bb,
900             ID_WINDOW_PROPERTIES,
901             wxT("Description Panel"),
902             wxDefaultPosition,
903             wxSize(600, 400),
904             0
905         );
906                 
907       }
908
909     //delete old view
910     if(this->panel_Properties!= NULL)
911       {
912         this->panel_Properties->Hide();
913         auiManager.DetachPane(this->panel_Properties);
914         this->panel_Properties->Destroy();
915         this->panel_Properties = NULL;
916       }
917     //set new view
918     auiManager.AddPane(description, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
919     this->panel_Properties = description;
920     auiManager.Update();
921     break;
922   default:
923           event.Skip();
924   }
925   
926 }
927
928 void wxCDMMainFrame::OnElementSelected(wxCommandEvent& event)
929 {
930   //std::cout << "element " << event.GetInt() << std::endl;
931   modelCDMIProjectTreeNode* item = (modelCDMIProjectTreeNode*)event.GetClientData();
932   this->tree_Projects->EnsureVisible(item->GetId().GetWxId());
933   this->tree_Projects->SetItemBold(item->GetId().GetWxId(), true);
934   this->tree_Projects->SetItemTextColour(item->GetId().GetWxId(), wxColour(0,0,255));
935   this->tree_Projects->SetItemBackgroundColour(item->GetId().GetWxId(), wxColour(230,230,255));
936   this->tree_Projects->UpdateWindowUI(wxUPDATE_UI_RECURSE);
937   auiManager.Update();
938 }
939
940 void wxCDMMainFrame::OnElementDeselected(wxCommandEvent& event)
941 {
942   modelCDMIProjectTreeNode* item = (modelCDMIProjectTreeNode*)event.GetClientData();
943   this->tree_Projects->SetItemBold(item->GetId().GetWxId(), false);
944   this->tree_Projects->SetItemTextColour(item->GetId().GetWxId(), wxColour(0,0,0));
945   this->tree_Projects->SetItemBackgroundColour(item->GetId().GetWxId(), wxColour(255,255,255));
946   this->tree_Projects->UpdateWindowUI(wxUPDATE_UI_RECURSE);
947   auiManager.Update();
948 }
949
950 void wxCDMMainFrame::OnMenuToggleHelp(wxCommandEvent& event)
951 {
952   this->help = !this->help;
953   this->menu_Help->Check(ID_MENU_TOGGLE_HELP, this->help);
954 }
955
956 void wxCDMMainFrame::OnDisableHelp(wxCommandEvent& event)
957 {
958   if (event.GetInt())
959     this->help = false;
960   else
961     this->help = true;
962
963   this->menu_Help->Check(ID_MENU_TOGGLE_HELP, this->help);
964 }