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