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