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