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