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