]> 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           ID_WINDOW_PROJ_ACTIONS,
306           wxT("Project Actions Panel"),
307           wxDefaultPosition,
308           wxSize(800,200),
309           0
310       );
311       panel_ProjectActions->SetMinSize(wxSize(500, 100));
312
313
314       auiManager.AddPane(panel_Properties, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
315       auiManager.AddPane(panel_ProjectActions, wxAuiPaneInfo().Bottom().MinSize(800,50).Name(wxT("panel_ProjectActions")).Caption(wxT("General Project Actions")).BestSize(800,70).CloseButton(false));
316
317       auiManager.Update();
318
319       wxMessageBox(_T("New Project created!"),_T("New Project - Success!"), wxOK | wxICON_INFORMATION);
320     }
321
322   event.Skip();
323 }
324 void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
325 {
326   std::string* result;
327
328   long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
329   wxDirDialog* FD = new wxDirDialog(this, wxT("Select the project directory"), wxT(""), style);
330   long userResponse = FD->ShowModal();
331   if(userResponse == wxID_OK)
332     {
333       std::string path = crea::wx2std (FD->GetPath());
334       FD -> Destroy();
335       FD = NULL;
336
337       std::cout << "Selection to open: " << path << std::endl;
338
339
340       //populate model
341       if(this->model->GetProject() != NULL)
342         {
343           std::cout << "Project not null, closing it" << std::endl;
344           if(!this->model->CloseProject(result))
345             {
346               std::cout << "error closing project: " << *result << std::endl;
347               wxMessageBox(crea::std2wx(result->c_str()),_T("New Project - Error!"),wxOK | wxICON_ERROR);
348               event.Skip();
349               return;
350             }
351         }
352
353       if (!this->model->OpenProject(path, result))
354         {
355           std::cout << "error opening project: " << *result << std::endl;
356           wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR);
357           event.Skip();
358           return;
359         };
360
361       std::cout << "building ui" << std::endl;
362
363
364       //populate tree control
365       tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
366       tree_Projects->SelectItem(this->model->GetProject()->GetId());
367
368       //change description panel
369       if(this->panel_Properties != NULL)
370         {
371           auiManager.DetachPane(this->panel_Properties);
372           this->panel_Properties->Destroy();
373           this->panel_Properties = NULL;
374         }
375
376       this->panel_Properties = new wxCDMProjectDescriptionPanel(
377           this,
378           this->model->GetProject(),
379           ID_WINDOW_PROPERTIES,
380           wxT("Description Panel"),
381           wxDefaultPosition,
382           wxSize(600, 400),
383           0
384       );
385
386       //change project's actions panel
387       if(this->panel_ProjectActions!= NULL)
388         {
389           auiManager.DetachPane(this->panel_ProjectActions);
390           this->panel_ProjectActions->Destroy();
391           this->panel_ProjectActions = NULL;
392         }
393       panel_ProjectActions = new wxCDMProjectActionsPanel(
394           this,
395           ID_WINDOW_PROJ_ACTIONS,
396           wxT("Project Actions Panel"),
397           wxDefaultPosition,
398           wxSize(800,200),
399           0
400       );
401       panel_ProjectActions->SetMinSize(wxSize(500, 100));
402
403
404       auiManager.AddPane(panel_Properties, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
405       auiManager.AddPane(panel_ProjectActions, wxAuiPaneInfo().Bottom().MinSize(800,50).Name(wxT("panel_ProjectActions")).Caption(wxT("General Project Actions")).BestSize(800,70).CloseButton(false));
406
407       auiManager.Update();
408     }
409
410   event.Skip();
411 }
412 void wxCDMMainFrame::OnMenuOpenRecent(wxCommandEvent& event)
413 {
414   std::cerr << "Event OnMenuOpenRecent not implemented" << std::endl;
415   event.Skip();
416 }
417 void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event)
418 {
419   std::cout << "closing project" << std::endl;
420   std::string* result;
421   if(!this->model->CloseProject(result))
422     {
423       std::cout << "error closing project: " << *result << std::endl;
424       wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
425     }
426
427   tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
428
429   if(this->panel_Properties != NULL)
430     {
431       auiManager.DetachPane(this->panel_Properties);
432       this->panel_Properties->Destroy();
433       this->panel_Properties = NULL;
434     }
435   if(this->panel_ProjectActions != NULL)
436     {
437       auiManager.DetachPane(this->panel_ProjectActions);
438       this->panel_ProjectActions->Destroy();
439       this->panel_ProjectActions = NULL;
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   event.Skip();
455 }
456 void wxCDMMainFrame::OnMenuCloseAllProjects(wxCommandEvent& event)
457 {
458   std::cerr << "Event OnMenuCloseAllProjects closing only one project" << std::endl;
459   std::string* result;
460   if(!this->model->CloseProject(result))
461     {
462       std::cout << "error closing project: " << *result << std::endl;
463       wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
464     }
465   tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
466
467   if(this->panel_Properties != NULL)
468     {
469       auiManager.DetachPane(this->panel_Properties);
470       this->panel_Properties->Destroy();
471       this->panel_Properties = NULL;
472     }
473   if(this->panel_ProjectActions != NULL)
474     {
475       auiManager.DetachPane(this->panel_ProjectActions);
476       this->panel_ProjectActions->Destroy();
477       this->panel_ProjectActions = NULL;
478     }
479
480   this->panel_Properties = new wxCDMMainDescriptionPanel(
481       this,
482       ID_WINDOW_PROPERTIES,
483       wxT("Description Panel"),
484       wxDefaultPosition,
485       wxSize(600, 400),
486       0
487   );
488
489   auiManager.AddPane(panel_Properties, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400));
490
491   auiManager.Update();
492   event.Skip();
493 }
494 void wxCDMMainFrame::OnMenuExportHierarchy(wxCommandEvent& event)
495 {
496   std::cerr << "Event OnMenuExportHierarchy not implemented" << std::endl;
497   event.Skip();
498 }
499 void wxCDMMainFrame::OnMenuExit(wxCommandEvent& event)
500 {
501   std::cout << "Closing CreaDevManager..." << std::endl;
502   std::string* result;
503   if(this->model->GetProject() != NULL && !this->model->CloseProject(result))
504     {
505       std::cout << "error closing project: " << *result << std::endl;
506       wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
507     }
508   tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
509
510   if(this->panel_Properties != NULL)
511     {
512       auiManager.DetachPane(this->panel_Properties);
513       this->panel_Properties->Destroy();
514       this->panel_Properties = NULL;
515     }
516
517   if(this->panel_ProjectActions != NULL)
518     {
519       auiManager.DetachPane(this->panel_ProjectActions);
520       this->panel_ProjectActions->Destroy();
521       this->panel_ProjectActions = NULL;
522     }
523
524   Close();
525   event.Skip();
526 }
527
528 //Edit Menu
529 void wxCDMMainFrame::OnMenuRefreshProject(wxCommandEvent& event)
530 {
531   std::string* result;
532   if(!model->RefreshProject(result))
533     {
534       wxMessageBox( crea::std2wx(result->c_str()), wxT("Refresh Project - Error"), wxICON_ERROR);
535     }
536   this->tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
537
538   this->auiManager.Update();
539
540   this->tree_Projects->SelectItem(this->model->GetProject()->GetId(), false);
541   this->tree_Projects->SelectItem(this->model->GetProject()->GetId(), true);
542
543   //TODO: Show possible problems in CMakeLists files
544   event.Skip();
545 }
546 void wxCDMMainFrame::OnMenuMenuCut(wxCommandEvent& event)
547 {
548   std::cerr << "Event OnMenuMenuCut not implemented" << std::endl;
549   event.Skip();
550 }
551 void wxCDMMainFrame::OnMenuMenuCopy(wxCommandEvent& event)
552 {
553   std::cerr << "Event OnMenuMenuCopy not implemented" << std::endl;
554   event.Skip();
555 }
556 void wxCDMMainFrame::OnMenuMenuPaste(wxCommandEvent& event)
557 {
558   std::cerr << "Event OnMenuMenuPaste not implemented" << std::endl;
559   event.Skip();
560 }
561 void wxCDMMainFrame::OnMenuMenuDelete(wxCommandEvent& event)
562 {
563   std::cerr << "Event OnMenuMenuDelete not implemented" << std::endl;
564   event.Skip();
565 }
566 void wxCDMMainFrame::OnMenuSelectAll(wxCommandEvent& event)
567 {
568   std::cerr << "Event OnMenuSelectAll not implemented" << std::endl;
569   event.Skip();
570 }
571 void wxCDMMainFrame::OnMenuSelectNone(wxCommandEvent& event)
572 {
573   std::cerr << "Event OnMenuSelectNone not implemented" << std::endl;
574   event.Skip();
575 }
576
577 //Tools Menu
578 void wxCDMMainFrame::OnMenuEventLog(wxCommandEvent& event)
579 {
580   std::cerr << "Event OnMenuEventLog not implemented" << std::endl;
581   event.Skip();
582 }
583 void wxCDMMainFrame::OnMenuBBTKGraphicalEditor(wxCommandEvent& event)
584 {
585   std::cerr << "Event OnMenuBBTKGraphicalEditor not implemented" << std::endl;
586   event.Skip();
587   if(CDMUtilities::openBBEditor())
588     {
589       wxMessageBox( wxT("Can't open the BB Graphical Editor. Please check your Crea Tools installation."), wxT("Refresh Project - Error"), wxICON_ERROR);
590     }
591 }
592 void wxCDMMainFrame::OnMenuMiniTools(wxCommandEvent& event)
593 {
594   if(CDMUtilities::openCreaToolsTools())
595     {
596       wxMessageBox( wxT("Can't open the Minitools. Please check your Crea Tools installation."), wxT("Refresh Project - Error"), wxICON_ERROR);
597     }
598 }
599 void wxCDMMainFrame::OnMenuCodeEditor(wxCommandEvent& event)
600 {
601   if(CDMUtilities::openTextEditor())
602     {
603       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);
604     }
605 }
606 void wxCDMMainFrame::OnMenuCommandLine(wxCommandEvent& event)
607 {
608   if(CDMUtilities::openTerminal())
609     {
610       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);
611     }
612 }
613
614 //Help Menu
615 void wxCDMMainFrame::OnMenuHelp(wxCommandEvent& event)
616 {
617   std::cerr << "Event OnMenuHelp not implemented" << std::endl;
618   event.Skip();
619 }
620 void wxCDMMainFrame::OnMenuReportBug(wxCommandEvent& event)
621 {
622   std::cerr << "Event OnMenuReportBug not implemented" << std::endl;
623   event.Skip();
624 }
625 void wxCDMMainFrame::OnMenuAboutCreaDevManager(wxCommandEvent& event)
626 {
627   std::cerr << "Event OnMenuAboutCreaDevManager not implemented" << std::endl;
628   event.Skip();
629 }
630 void wxCDMMainFrame::OnMenuAboutCreatis(wxCommandEvent& event)
631 {
632   std::cerr << "Event OnMenuAboutCreatis not implemented" << std::endl;
633   event.Skip();
634 }
635
636 void wxCDMMainFrame::OnTreeSelectionChanged(wxTreeEvent& event)
637 {
638   //get selected element
639   wxTreeItemId elementId = event.GetItem();
640
641   //get element from model
642   modelCDMIProjectTreeNode* element = this->model->GetModelElements()[elementId];
643   std::cout << "Tree Selection: " << element->GetName() << std::endl;
644
645   //TODO get element type
646   //project
647   modelCDMProject* elementProject = dynamic_cast<modelCDMProject*>(element);
648   wxPanel* description;
649   if(elementProject != NULL)
650     {
651       //create element description
652       description = new wxCDMProjectDescriptionPanel(
653           this,
654           elementProject,
655           ID_WINDOW_PROPERTIES,
656           wxT("Description Panel"),
657           wxDefaultPosition,
658           wxSize(600, 400),
659           0
660       );
661
662     }
663   else
664     {
665       //appli
666       modelCDMAppli* elementAppli = dynamic_cast<modelCDMAppli*>(element);
667       if(elementAppli != NULL)
668         {
669           //create element description
670           description = new wxCDMAppliDescriptionPanel(
671               this,
672               elementAppli,
673               ID_WINDOW_PROPERTIES,
674               wxT("Description Panel"),
675               wxDefaultPosition,
676               wxSize(600, 400),
677               0
678           );
679         }
680       else
681         {
682           //application
683           modelCDMApplication* elementApplication = dynamic_cast<modelCDMApplication*>(element);
684           if(elementApplication != NULL)
685             {
686               //create element description
687               description = new wxCDMApplicationDescriptionPanel(
688                   this,
689                   elementApplication,
690                   ID_WINDOW_PROPERTIES,
691                   wxT("Description Panel"),
692                   wxDefaultPosition,
693                   wxSize(600, 400),
694                   0
695               );
696             }
697           else
698             {
699               //lib
700               modelCDMLib* elementLib = dynamic_cast<modelCDMLib*>(element);
701               if(elementLib != NULL)
702                 {
703                   //create element description
704                   description = new wxCDMLibDescriptionPanel(
705                       this,
706                       elementLib,
707                       ID_WINDOW_PROPERTIES,
708                       wxT("Description Panel"),
709                       wxDefaultPosition,
710                       wxSize(600, 400),
711                       0
712                   );
713                 }
714               else
715                 {
716                   //library
717                   modelCDMLibrary* elementLibrary = dynamic_cast<modelCDMLibrary*>(element);
718                   if(elementLibrary != NULL)
719                     {
720                       //create element description
721                       description = new wxCDMLibraryDescriptionPanel(
722                           this,
723                           elementLibrary,
724                           ID_WINDOW_PROPERTIES,
725                           wxT("Description Panel"),
726                           wxDefaultPosition,
727                           wxSize(600, 400),
728                           0
729                       );
730                     }
731                   else
732                     {
733                       //package
734                       modelCDMPackage* elementPackage = dynamic_cast<modelCDMPackage*>(element);
735                       if(elementPackage != NULL)
736                         {
737                           //create element description
738                           description = new wxCDMPackageDescriptionPanel(
739                               this,
740                               elementPackage,
741                               ID_WINDOW_PROPERTIES,
742                               wxT("Description Panel"),
743                               wxDefaultPosition,
744                               wxSize(600, 400),
745                               0
746                           );
747                         }
748                       else
749                         {
750                           //black box
751                           modelCDMBlackBox* elementBlackBox = dynamic_cast<modelCDMBlackBox*>(element);
752                           if(elementBlackBox != NULL)
753                             {
754                               //create element description
755                               description = new wxCDMBlackBoxDescriptionPanel(
756                                   this,
757                                   elementBlackBox,
758                                   ID_WINDOW_PROPERTIES,
759                                   wxT("Description Panel"),
760                                   wxDefaultPosition,
761                                   wxSize(600, 400),
762                                   0
763                               );
764                             }
765                           else
766                             {
767                               //CMakeLists
768                               modelCDMCMakeListsFile* elementCMakeLists = dynamic_cast<modelCDMCMakeListsFile*>(element);
769                               if(elementCMakeLists != NULL)
770                                 {
771                                   //create element description
772                                   description = new wxCDMCMakeListsDescriptionPanel(
773                                       this,
774                                       elementCMakeLists,
775                                       ID_WINDOW_PROPERTIES,
776                                       wxT("Description Panel"),
777                                       wxDefaultPosition,
778                                       wxSize(600, 400),
779                                       0
780                                   );
781                                 }
782                               else
783                                 {
784                                   //folder
785                                   modelCDMFolder* elementFolder = dynamic_cast<modelCDMFolder*>(element);
786                                   if(elementFolder != NULL)
787                                     {
788                                       //create element description
789                                       description = new wxCDMFolderDescriptionPanel(
790                                           this,
791                                           elementFolder,
792                                           ID_WINDOW_PROPERTIES,
793                                           wxT("Description Panel"),
794                                           wxDefaultPosition,
795                                           wxSize(600, 400),
796                                           0
797                                       );
798                                     }
799                                   else
800                                     {
801                                       //file
802                                       modelCDMFile* elementFile = dynamic_cast<modelCDMFile*>(element);
803                                       if(elementFile != NULL)
804                                         {
805                                           //create element description
806                                           description = new wxCDMFileDescriptionPanel(
807                                               this,
808                                               elementFile,
809                                               ID_WINDOW_PROPERTIES,
810                                               wxT("Description Panel"),
811                                               wxDefaultPosition,
812                                               wxSize(600, 400),
813                                               0
814                                           );
815                                         }
816                                       else
817                                         {
818
819                                           //main if not any
820                                           //create element description
821                                           description = new wxCDMMainDescriptionPanel(
822                                               this,
823                                               ID_WINDOW_PROPERTIES,
824                                               wxT("Description Panel"),
825                                               wxDefaultPosition,
826                                               wxSize(600, 400),
827                                               0
828                                           );
829                                         }
830                                     }
831                                 }
832                             }
833                         }
834                     }
835                 }
836             }
837         }
838     }
839
840   if(this->panel_Properties!= NULL)
841     this->panel_Properties->Hide();
842
843   auiManager.AddPane(description, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
844   auiManager.Update();
845
846   //delete old view
847   if(this->panel_Properties!= NULL)
848     {
849       auiManager.DetachPane(this->panel_Properties);
850       this->panel_Properties->Destroy();
851       this->panel_Properties = NULL;
852     }
853   //set new view
854
855   this->panel_Properties = description;
856   //auiManager.AddPane(panel_Properties, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("Properties")).BestSize(600,400).CloseButton(false));
857   auiManager.Update();
858   event.Skip();
859   return;
860
861 }
862
863 void wxCDMMainFrame::OnCreationComplete(wxCommandEvent& event)
864 {
865   switch(event.GetId() != 0)
866   {
867   case 0:
868     //select out old one to generate selection event
869     this->tree_Projects->SelectItem(event.GetInt(), true);
870     this->tree_Projects->Expand(event.GetInt());
871     break;
872   case 1:
873     wxPanel* description = NULL;
874     if(event.GetString() == wxT("manage_packages"))
875       {
876         this->tree_Projects->SelectItem(this->model->GetProject()->GetId(), false);
877         this->tree_Projects->Expand(this->model->GetProject()->GetId());
878         description = new wxCDMPackageManagerPanel(
879             this,
880             this->model->GetProject(),
881             ID_WINDOW_PROPERTIES,
882             wxT("Description Panel"),
883             wxDefaultPosition,
884             wxSize(600, 400),
885             0
886         );
887       }
888     else if(event.GetString() == wxT("manage_libraries"))
889       {
890         this->tree_Projects->SelectItem(this->model->GetProject()->GetLib()->GetId(), true);
891         this->tree_Projects->Expand(this->model->GetProject()->GetLib()->GetId());
892         break;
893       }
894     else if(event.GetString() == wxT("manage_applications"))
895       {
896         this->tree_Projects->SelectItem(this->model->GetProject()->GetAppli()->GetId(), true);
897         this->tree_Projects->Expand(this->model->GetProject()->GetAppli()->GetId());
898         break;
899       }
900
901     if(this->panel_Properties!= NULL)
902       this->panel_Properties->Hide();
903
904     auiManager.AddPane(description, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("")).BestSize(600,400).CloseButton(false));
905     auiManager.Update();
906
907     //delete old view
908     if(this->panel_Properties!= NULL)
909       {
910         auiManager.DetachPane(this->panel_Properties);
911         this->panel_Properties->Destroy();
912         this->panel_Properties = NULL;
913       }
914     //set new view
915
916     this->panel_Properties = description;
917     auiManager.Update();
918     break;
919   }
920   event.Skip();
921 }
922
923 void wxCDMMainFrame::OnElementSelected(wxCommandEvent& event)
924 {
925   //std::cout << "element " << event.GetInt() << std::endl;
926   this->tree_Projects->SetItemBold(event.GetInt(), true);
927   this->tree_Projects->SetItemTextColour(event.GetInt(), wxColour(0,0,255));
928   this->tree_Projects->UpdateWindowUI(wxUPDATE_UI_RECURSE);
929   auiManager.Update();
930 }
931
932 void wxCDMMainFrame::OnElementDeselected(wxCommandEvent& event)
933 {
934   this->tree_Projects->SetItemBold(event.GetInt(), false);
935   this->tree_Projects->SetItemTextColour(event.GetInt(), wxColour(0,0,0));
936   this->tree_Projects->UpdateWindowUI(wxUPDATE_UI_RECURSE);
937   auiManager.Update();
938 }