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