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