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