]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMMainFrame.cpp
e1df059b21ffe9f5d7fdab9dc163072d1ebb6f57
[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->BuildTree(this->model->GetModelElements(), this->model->GetProject());
350           tree_Projects->Unselect();
351           this->actualTreeItem.Unset();
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   //std::cout << "Tree Selection id: " << elementId.m_pItem << this->actualTreeItem.m_pItem << std::endl;
591   //elementId.IsOk() && this->tree_Projects->IsSelected(elementId)
592   if(elementId.IsOk() && this->actualTreeItem != elementId)
593     {
594       
595       //std::cout << "Valid tree selection id: " << elementId.m_pItem << std::endl;
596       //get element from model
597       modelCDMIProjectTreeNode* element = this->model->GetModelElements()[elementId];
598
599           if (element == NULL)
600                   return;
601       std::cout << "Tree Selection: " << element->GetName() << std::endl;
602
603           //std::stringstream ss;
604           //ss << this->actualTreeItem.m_pItem << ":" << event.GetOldItem().m_pItem << " --> " << elementId.m_pItem;
605           //wxMessageBox( wxT("Tree Selection id: " + ss.str() + " by " + element->GetName()), wxT("Refresh Project - Error"), wxICON_ERROR);   
606       this->actualTreeItem = elementId;
607
608           //get element type
609       //project
610       modelCDMProject* elementProject = dynamic_cast<modelCDMProject*>(element);
611       wxPanel* description;
612       if(elementProject != NULL)
613         {
614           //create element description
615           description = new wxCDMProjectDescriptionPanel(
616               this,
617               elementProject,
618               ID_WINDOW_PROPERTIES,
619               wxT("Description Panel"),
620               wxDefaultPosition,
621               wxSize(600, 400),
622               0
623           );
624
625         }
626       else
627         {
628           //appli
629           modelCDMAppli* elementAppli = dynamic_cast<modelCDMAppli*>(element);
630           if(elementAppli != NULL)
631             {
632               //create element description
633               description = new wxCDMAppliDescriptionPanel(
634                   this,
635                   elementAppli,
636                   ID_WINDOW_PROPERTIES,
637                   wxT("Description Panel"),
638                   wxDefaultPosition,
639                   wxSize(600, 400),
640                   0
641               );
642
643             }
644           else
645             {
646               //application
647               modelCDMApplication* elementApplication = dynamic_cast<modelCDMApplication*>(element);
648                           if(elementApplication != NULL)
649                 {
650                   //create element description
651                   description = new wxCDMApplicationDescriptionPanel(
652                       this,
653                       elementApplication,
654                       ID_WINDOW_PROPERTIES,
655                       wxT("Description Panel"),
656                       wxDefaultPosition,
657                       wxSize(600, 400),
658                       0
659                   );
660                 }
661               else
662                 {
663                   //lib
664                   modelCDMLib* elementLib = dynamic_cast<modelCDMLib*>(element);
665                   if(elementLib != NULL)
666                     {
667                       //create element description
668                       description = new wxCDMLibDescriptionPanel(
669                           this,
670                           elementLib,
671                           ID_WINDOW_PROPERTIES,
672                           wxT("Description Panel"),
673                           wxDefaultPosition,
674                           wxSize(600, 400),
675                           0
676                       );
677                     }
678                   else
679                     {
680                       //library
681                       modelCDMLibrary* elementLibrary = dynamic_cast<modelCDMLibrary*>(element);
682                       if(elementLibrary != NULL)
683                         {
684                           //create element description
685                           description = new wxCDMLibraryDescriptionPanel(
686                               this,
687                               elementLibrary,
688                               ID_WINDOW_PROPERTIES,
689                               wxT("Description Panel"),
690                               wxDefaultPosition,
691                               wxSize(600, 400),
692                               0
693                           );
694                         }
695                       else
696                         {
697                           //package
698                           modelCDMPackage* elementPackage = dynamic_cast<modelCDMPackage*>(element);
699                           if(elementPackage != NULL)
700                             {
701                               //create element description
702                               description = new wxCDMPackageDescriptionPanel(
703                                   this,
704                                   elementPackage,
705                                   ID_WINDOW_PROPERTIES,
706                                   wxT("Description Panel"),
707                                   wxDefaultPosition,
708                                   wxSize(600, 400),
709                                   0
710                               );
711                             }
712                           else
713                             {
714                               //black box
715                               modelCDMBlackBox* elementBlackBox = dynamic_cast<modelCDMBlackBox*>(element);
716                               if(elementBlackBox != NULL)
717                                 {
718                                   //create element description
719                                   description = new wxCDMBlackBoxDescriptionPanel(
720                                       this,
721                                       elementBlackBox,
722                                       ID_WINDOW_PROPERTIES,
723                                       wxT("Description Panel"),
724                                       wxDefaultPosition,
725                                       wxSize(600, 400),
726                                       0
727                                   );
728                                 }
729                               else
730                                 {
731                                   //CMakeLists
732                                   modelCDMCMakeListsFile* elementCMakeLists = dynamic_cast<modelCDMCMakeListsFile*>(element);
733                                   if(elementCMakeLists != NULL)
734                                     {
735                                       //create element description
736                                       description = new wxCDMCMakeListsDescriptionPanel(
737                                           this,
738                                           elementCMakeLists,
739                                           ID_WINDOW_PROPERTIES,
740                                           wxT("Description Panel"),
741                                           wxDefaultPosition,
742                                           wxSize(600, 400),
743                                           0
744                                       );
745                                     }
746                                   else
747                                     {
748                                       //folder
749                                       modelCDMFolder* elementFolder = dynamic_cast<modelCDMFolder*>(element);
750                                       if(elementFolder != NULL)
751                                         {
752                                           //create element description
753                                           description = new wxCDMFolderDescriptionPanel(
754                                               this,
755                                               elementFolder,
756                                               ID_WINDOW_PROPERTIES,
757                                               wxT("Description Panel"),
758                                               wxDefaultPosition,
759                                               wxSize(600, 400),
760                                               0
761                                           );
762                                         }
763                                       else
764                                         {
765                                           //file
766                                           modelCDMFile* elementFile = dynamic_cast<modelCDMFile*>(element);
767                                           if(elementFile != NULL)
768                                             {
769                                               //create element description
770                                               description = new wxCDMFileDescriptionPanel(
771                                                   this,
772                                                   elementFile,
773                                                   ID_WINDOW_PROPERTIES,
774                                                   wxT("Description Panel"),
775                                                   wxDefaultPosition,
776                                                   wxSize(600, 400),
777                                                   0
778                                               );
779                                             }
780                                           else
781                                             {
782
783                                               //main if not any
784                                               //create element description
785                                               description = new wxCDMMainDescriptionPanel(
786                                                   this,
787                                                   ID_WINDOW_PROPERTIES,
788                                                   wxT("Description Panel"),
789                                                   wxDefaultPosition,
790                                                   wxSize(600, 400),
791                                                   0
792                                               );
793                                             }
794                                         }
795                                     }
796                                 }
797                             }
798                         }
799                     }
800                 }
801             }
802         }
803
804       //delete old view
805       if(this->panel_Properties!= NULL)
806         {
807           this->panel_Properties->Hide();
808           auiManager.DetachPane(this->panel_Properties);
809           //this->panel_Properties->Destroy();
810           //this->panel_Properties = NULL;
811         }
812       //set new view
813       auiManager.AddPane(description, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
814       this->panel_Properties = description;
815
816       auiManager.Update();
817     }
818   else
819     {
820       event.Skip();
821         }
822
823   return;
824
825 }
826
827 void wxCDMMainFrame::OnChangeView(wxCommandEvent& event)
828 {
829   modelCDMIProjectTreeNode* myItem = NULL;
830   wxPanel* description = NULL;
831   switch(event.GetId())
832   {
833   case 0:
834     myItem = ((modelCDMIProjectTreeNode*)event.GetClientData());
835     //select out old one to generate selection event
836     this->tree_Projects->Unselect();
837     this->tree_Projects->SelectItem(myItem->GetId().GetWxId());
838     this->tree_Projects->Expand(myItem->GetId().GetWxId());
839     break;
840   case 1:
841     
842     if(event.GetString() == wxT("manage_packages"))
843       {
844         //this->tree_Projects->Expand(this->model->GetProject()->GetId());
845         //this->tree_Projects->Unselect();
846         this->actualTreeItem.Unset();
847                   description = new wxCDMPackageManagerPanel(
848             this,
849             this->model->GetProject(),
850             ID_WINDOW_PROPERTIES,
851             wxT("Description Panel"),
852             wxDefaultPosition,
853             wxSize(600, 400),
854             0
855         );
856       }
857     else if(event.GetString() == wxT("manage_libraries"))
858       {
859         this->tree_Projects->SelectItem(this->model->GetProject()->GetLib()->GetId().GetWxId());
860         this->tree_Projects->Expand(this->model->GetProject()->GetLib()->GetId().GetWxId());
861         break;
862       }
863     else if(event.GetString() == wxT("manage_applications"))
864       {
865         this->tree_Projects->SelectItem(this->model->GetProject()->GetAppli()->GetId().GetWxId());
866         this->tree_Projects->Expand(this->model->GetProject()->GetAppli()->GetId().GetWxId());
867         break;
868       }
869     else if(event.GetString() == wxT("blackbox"))
870       {
871         modelCDMBlackBox* bb = (modelCDMBlackBox*)event.GetClientData();
872                 this->actualTreeItem.Unset();
873         description = new wxCDMBlackBoxDescriptionPanel(
874             this,
875             bb,
876             ID_WINDOW_PROPERTIES,
877             wxT("Description Panel"),
878             wxDefaultPosition,
879             wxSize(600, 400),
880             0
881         );
882                 
883       }
884
885     //delete old view
886     if(this->panel_Properties!= NULL)
887       {
888         this->panel_Properties->Hide();
889         auiManager.DetachPane(this->panel_Properties);
890         this->panel_Properties->Destroy();
891         this->panel_Properties = NULL;
892       }
893     //set new view
894     auiManager.AddPane(description, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
895     this->panel_Properties = description;
896     auiManager.Update();
897     break;
898   default:
899           event.Skip();
900   }
901   
902 }
903
904 void wxCDMMainFrame::OnElementSelected(wxCommandEvent& event)
905 {
906   //std::cout << "element " << event.GetInt() << std::endl;
907   modelCDMIProjectTreeNode* item = (modelCDMIProjectTreeNode*)event.GetClientData();
908   this->tree_Projects->EnsureVisible(item->GetId().GetWxId());
909   this->tree_Projects->SetItemBold(item->GetId().GetWxId(), true);
910   this->tree_Projects->SetItemTextColour(item->GetId().GetWxId(), wxColour(0,0,255));
911   this->tree_Projects->SetItemBackgroundColour(item->GetId().GetWxId(), wxColour(230,230,255));
912   this->tree_Projects->UpdateWindowUI(wxUPDATE_UI_RECURSE);
913   auiManager.Update();
914 }
915
916 void wxCDMMainFrame::OnElementDeselected(wxCommandEvent& event)
917 {
918   modelCDMIProjectTreeNode* item = (modelCDMIProjectTreeNode*)event.GetClientData();
919   this->tree_Projects->SetItemBold(item->GetId().GetWxId(), false);
920   this->tree_Projects->SetItemTextColour(item->GetId().GetWxId(), wxColour(0,0,0));
921   this->tree_Projects->SetItemBackgroundColour(item->GetId().GetWxId(), wxColour(255,255,255));
922   this->tree_Projects->UpdateWindowUI(wxUPDATE_UI_RECURSE);
923   auiManager.Update();
924 }
925
926 void wxCDMMainFrame::OnMenuToggleHelp(wxCommandEvent& event)
927 {
928   this->help = !this->help;
929   this->menu_Help->Check(ID_MENU_TOGGLE_HELP, this->help);
930 }
931
932 void wxCDMMainFrame::OnDisableHelp(wxCommandEvent& event)
933 {
934   if (event.GetInt())
935     this->help = false;
936   else
937     this->help = true;
938
939   this->menu_Help->Check(ID_MENU_TOGGLE_HELP, this->help);
940 }