2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
29 #include "wxCDMMainFrame.h"
34 #include "wx/treectrl.h"
35 #include "CDMUtilities.h"
37 #include "creaDevManagerIds.h"
38 #include "wxCDMMainDescriptionPanel.h"
39 #include "wxCDMProjectDescriptionPanel.h"
40 #include "wxCDMProjectActionsPanel.h"
41 #include "wxCDMNewProjectDialog.h"
44 BEGIN_EVENT_TABLE(wxCDMMainFrame, wxFrame)
45 EVT_MENU(ID_MENU_NEW_PROJECT, wxCDMMainFrame::OnMenuNewProject)
46 EVT_MENU(ID_MENU_OPEN_PROJECT, wxCDMMainFrame::OnMenuOpenProject)
47 EVT_MENU(ID_MENU_OPEN_RECENT, wxCDMMainFrame::OnMenuOpenRecent)
48 EVT_MENU(ID_MENU_CLOSE_PROJECT, wxCDMMainFrame::OnMenuCloseProject)
49 EVT_MENU(ID_MENU_CLOSE_ALL_PROJECTS, wxCDMMainFrame::OnMenuCloseAllProjects)
50 EVT_MENU(ID_MENU_EXPORT_HIERARCHY, wxCDMMainFrame::OnMenuExportHierarchy)
51 EVT_MENU(ID_MENU_EXIT, wxCDMMainFrame::OnMenuExit)
52 EVT_MENU(ID_MENU_REFRESH_PROJECT, wxCDMMainFrame::OnMenuRefreshProject)
53 EVT_MENU(ID_MENU_CUT, wxCDMMainFrame::OnMenuMenuCut)
54 EVT_MENU(ID_MENU_COPY, wxCDMMainFrame::OnMenuMenuCopy)
55 EVT_MENU(ID_MENU_PASTE, wxCDMMainFrame::OnMenuMenuPaste)
56 EVT_MENU(ID_MENU_DELETE, wxCDMMainFrame::OnMenuMenuDelete)
57 EVT_MENU(ID_MENU_SELECT_ALL, wxCDMMainFrame::OnMenuSelectAll)
58 EVT_MENU(ID_MENU_SELECT_NONE, wxCDMMainFrame::OnMenuSelectNone)
59 EVT_MENU(ID_MENU_EVENT_LOG, wxCDMMainFrame::OnMenuEventLog)
60 EVT_MENU(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxCDMMainFrame::OnMenuBBTKGraphicalEditor)
61 EVT_MENU(ID_MENU_MINITOOLS, wxCDMMainFrame::OnMenuMiniTools)
62 EVT_MENU(ID_MENU_CODE_EDITOR, wxCDMMainFrame::OnMenuCodeEditor)
63 EVT_MENU(ID_MENU_COMMAND_LINE, wxCDMMainFrame::OnMenuCommandLine)
64 EVT_MENU(ID_MENU_HELP, wxCDMMainFrame::OnMenuHelp)
65 EVT_MENU(ID_MENU_REPORT_BUG, wxCDMMainFrame::OnMenuReportBug)
66 EVT_MENU(ID_MENU_ABOUT_CREADEVMANAGER, wxCDMMainFrame::OnMenuAboutCreaDevManager)
67 EVT_MENU(ID_MENU_ABOUT_CREATIS, wxCDMMainFrame::OnMenuAboutCreatis)
68 EVT_BUTTON(ID_BUTTON_NEWPROJECT, wxCDMMainFrame::OnMenuNewProject)
69 EVT_BUTTON(ID_BUTTON_OPENPROJECT, wxCDMMainFrame::OnMenuOpenProject)
70 EVT_TREE_SEL_CHANGED(ID_TREE_PROJECTS, wxCDMMainFrame::OnTreeSelectionChanged)
73 wxCDMMainFrame::wxCDMMainFrame(
76 const wxString& caption,
82 Create(parent, id, caption, pos, size, style);
85 wxCDMMainFrame::~wxCDMMainFrame()
90 bool wxCDMMainFrame::Create(
93 const wxString& caption,
99 wxFrame::Create(parent, id, caption, pos, size, style);
100 this->model = new modelCDMMain();
106 void wxCDMMainFrame::CreateMenus()
108 wxMenuBar* menuBar = new wxMenuBar;
111 menu_File = new wxMenu();
112 menu_File->Append(ID_MENU_NEW_PROJECT, wxT("&New Project..."));
113 menu_File->Append(ID_MENU_OPEN_PROJECT, wxT("&Open Project..."));
114 menu_File->Append(ID_MENU_OPEN_RECENT, wxT("Open &Recent"));
115 menu_File->AppendSeparator();
116 menu_File->Append(ID_MENU_CLOSE_PROJECT, wxT("&Close Project"));
117 menu_File->Append(ID_MENU_CLOSE_ALL_PROJECTS, wxT("C&lose All Projects"));
118 menu_File->AppendSeparator();
119 menu_File->Append(ID_MENU_EXPORT_HIERARCHY, wxT("&Export Project Hierarchy..."));
120 menu_File->AppendSeparator();
121 menu_File->Append(ID_MENU_EXIT, wxT("E&xit"));
123 menuBar->Append(menu_File, wxT("&File"));
126 menu_Edit = new wxMenu();
127 menu_Edit->Append(ID_MENU_REFRESH_PROJECT, wxT("&Refresh Project"));
128 menu_Edit->AppendSeparator();
129 menu_Edit->Append(ID_MENU_CUT, wxT("Cu&t"));
130 menu_Edit->Append(ID_MENU_COPY, wxT("&Copy"));
131 menu_Edit->Append(ID_MENU_PASTE, wxT("&Paste"));
132 menu_Edit->AppendSeparator();
133 menu_Edit->Append(ID_MENU_DELETE, wxT("&Delete"));
134 menu_Edit->Append(ID_MENU_SELECT_ALL, wxT("Select &All"));
135 menu_Edit->Append(ID_MENU_SELECT_NONE, wxT("Ca&ncel Selection"));
137 menuBar->Append(menu_Edit, wxT("&Edit"));
140 menu_Tools = new wxMenu();
141 menu_Tools->Append(ID_MENU_EVENT_LOG, wxT("Event &Log"));
142 menu_Tools->Append(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxT("BBTK &Graphical Editor"));
143 menu_Tools->Append(ID_MENU_MINITOOLS, wxT("&MiniTools"));
144 menu_Tools->Append(ID_MENU_CODE_EDITOR, wxT("&Code Editor"));
145 menu_Tools->Append(ID_MENU_COMMAND_LINE, wxT("&Command Line"));
147 menuBar->Append(menu_Tools, wxT("&Tools"));
150 menu_Help = new wxMenu();
151 menu_Help->Append(ID_MENU_HELP, wxT("&Help"));
152 menu_Help->Append(ID_MENU_REPORT_BUG, wxT("Report &Bug"));
153 menu_Help->Append(ID_MENU_ABOUT_CREADEVMANAGER, wxT("&About CreaDevManager"));
154 menu_Help->Append(ID_MENU_ABOUT_CREATIS, wxT("A&bout CREATIS"));
156 menuBar->Append(menu_Help, wxT("&Help"));
161 wxStatusBar* statusBar = new wxStatusBar(this, ID_STATUS_BAR, wxST_SIZEGRIP);
162 statusBar->SetFieldsCount(1);
163 SetStatusBar(statusBar);
167 void wxCDMMainFrame::CreateControls()
170 auiManager.SetManagedWindow(this);
173 tree_Projects = new wxCDMProjectsTreeCtrl(
178 wxTR_HAS_BUTTONS | wxTR_AQUA_BUTTONS
180 tree_Projects->SetMinSize(wxSize(200,200));
182 panel_Properties = new wxCDMMainDescriptionPanel(
184 ID_WINDOW_PROPERTIES,
185 wxT("Description Panel"),
195 auiManager.AddPane(tree_Projects, wxLEFT, wxT("Projects Tree"));
196 auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
199 auiManager.GetPane(tree_Projects).CloseButton(false).MaximizeButton(true);
204 void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
208 wxCDMNewProjectDialog* dialog = new wxCDMNewProjectDialog(this);
210 userResponse = dialog->ShowModal();
212 if(userResponse == wxID_FORWARD)
215 if(this->model->GetProject() != NULL)
217 if(!this->model->CloseProject(result))
219 std::cout << "error closing project: " << *result << std::endl;
220 wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR);
226 if(!this->model->CreateProject(
227 crea::wx2std(dialog->GetProjectName()),
228 crea::wx2std(dialog->GetProjectLocation()),
230 crea::wx2std(dialog->GetPackageAuthor()),
231 crea::wx2std(dialog->GetPackageDescription())
234 std::cout << "error opening project: " << *result << std::endl;
235 wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR);
240 //populate tree control
241 tree_Projects->BuildTree(this->model->GetModelElements(),this->model->GetProject());
242 tree_Projects->SelectItem(this->model->GetProject()->GetId());
244 //change description panel
245 if(this->panel_Properties != NULL)
247 auiManager.DetachPane(this->panel_Properties);
248 this->panel_Properties->Destroy();
251 this->panel_Properties = new wxCDMProjectDescriptionPanel(
253 this->model->GetProject(),
254 ID_WINDOW_PROPERTIES,
255 wxT("Description Panel"),
259 //show projectactions panel
260 if(this->panel_ProjectActions != NULL)
262 auiManager.DetachPane(this->panel_Properties);
263 this->panel_ProjectActions->Destroy();
266 panel_ProjectActions = new wxCDMProjectActionsPanel(
268 ID_WINDOW_PROJ_ACTIONS,
269 wxT("Project Actions Panel"),
274 panel_ProjectActions->SetMinSize(wxSize(500, 100));
277 auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
278 auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions"));
282 wxMessageBox(_T("New Project created!"),_T("New Project - Success!"), wxOK | wxICON_INFORMATION);
287 void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
291 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
292 wxDirDialog* FD = new wxDirDialog(this, wxT("Select the project directory"), wxT(""), style);
293 long userResponse = FD->ShowModal();
294 if(userResponse == wxID_OK)
296 std::string path = crea::wx2std (FD->GetPath());
300 std::cout << "Selection to open: " << path << std::endl;
304 if(this->model->GetProject() != NULL)
306 std::cout << "Project not null, closing it" << std::endl;
307 if(!this->model->CloseProject(result))
309 std::cout << "error closing project: " << *result << std::endl;
310 wxMessageBox(crea::std2wx(result->c_str()),_T("New Project - Error!"),wxOK | wxICON_ERROR);
316 if (!this->model->OpenProject(path, result))
318 std::cout << "error opening project: " << *result << std::endl;
319 wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR);
324 std::cout << "building ui" << std::endl;
327 //populate tree control
328 tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
329 tree_Projects->SelectItem(this->model->GetProject()->GetId());
331 //change description panel
332 if(this->panel_Properties != NULL)
334 auiManager.DetachPane(this->panel_Properties);
335 this->panel_Properties->Destroy();
338 this->panel_Properties = new wxCDMProjectDescriptionPanel(
340 this->model->GetProject(),
341 ID_WINDOW_PROPERTIES,
342 wxT("Description Panel"),
348 //change project's actions panel
349 if(this->panel_ProjectActions!= NULL)
351 auiManager.DetachPane(this->panel_ProjectActions);
352 this->panel_ProjectActions->Destroy();
354 panel_ProjectActions = new wxCDMProjectActionsPanel(
356 ID_WINDOW_PROJ_ACTIONS,
357 wxT("Project Actions Panel"),
362 panel_ProjectActions->SetMinSize(wxSize(500, 100));
365 auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
366 auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions"));
373 void wxCDMMainFrame::OnMenuOpenRecent(wxCommandEvent& event)
375 std::cerr << "Event OnMenuOpenRecent not implemented" << std::endl;
378 void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event)
381 if(!this->model->CloseProject(result))
383 std::cout << "error closing project: " << *result << std::endl;
384 wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
386 tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
388 if(this->panel_Properties != NULL)
390 auiManager.DetachPane(this->panel_Properties);
391 this->panel_Properties->Destroy();
393 if(this->panel_ProjectActions != NULL)
395 auiManager.DetachPane(this->panel_ProjectActions);
396 this->panel_ProjectActions->Destroy();
399 this->panel_Properties = new wxCDMMainDescriptionPanel(
401 ID_WINDOW_PROPERTIES,
402 wxT("Description Panel"),
408 auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
413 void wxCDMMainFrame::OnMenuCloseAllProjects(wxCommandEvent& event)
415 std::cerr << "Event OnMenuCloseAllProjects closing only one project" << std::endl;
417 if(!this->model->CloseProject(result))
419 std::cout << "error closing project: " << *result << std::endl;
420 wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
422 tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
424 if(this->panel_Properties != NULL)
426 auiManager.DetachPane(this->panel_Properties);
427 this->panel_Properties->Destroy();
429 if(this->panel_ProjectActions != NULL)
431 auiManager.DetachPane(this->panel_ProjectActions);
432 this->panel_ProjectActions->Destroy();
435 this->panel_Properties = new wxCDMMainDescriptionPanel(
437 ID_WINDOW_PROPERTIES,
438 wxT("Description Panel"),
444 auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
449 void wxCDMMainFrame::OnMenuExportHierarchy(wxCommandEvent& event)
451 std::cerr << "Event OnMenuExportHierarchy not implemented" << std::endl;
454 void wxCDMMainFrame::OnMenuExit(wxCommandEvent& event)
456 std::cout << "Closing CreaDevManager..." << std::endl;
458 if(!this->model->CloseProject(result))
460 std::cout << "error closing project: " << *result << std::endl;
461 wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
463 tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
465 if(this->panel_Properties != NULL)
467 auiManager.DetachPane(this->panel_Properties);
468 this->panel_Properties->Destroy();
470 if(this->panel_ProjectActions != NULL)
472 auiManager.DetachPane(this->panel_ProjectActions);
473 this->panel_ProjectActions->Destroy();
476 this->panel_Properties = new wxCDMMainDescriptionPanel(
478 ID_WINDOW_PROPERTIES,
479 wxT("Description Panel"),
489 void wxCDMMainFrame::OnMenuRefreshProject(wxCommandEvent& event)
492 if(!model->RefreshProject(result))
494 wxMessageBox( crea::std2wx(result->c_str()), wxT("Refresh Project - Error"), wxICON_ERROR);
496 //TODO: Show possible problems in CMakeLists files
499 void wxCDMMainFrame::OnMenuMenuCut(wxCommandEvent& event)
501 std::cerr << "Event OnMenuMenuCut not implemented" << std::endl;
504 void wxCDMMainFrame::OnMenuMenuCopy(wxCommandEvent& event)
506 std::cerr << "Event OnMenuMenuCopy not implemented" << std::endl;
509 void wxCDMMainFrame::OnMenuMenuPaste(wxCommandEvent& event)
511 std::cerr << "Event OnMenuMenuPaste not implemented" << std::endl;
514 void wxCDMMainFrame::OnMenuMenuDelete(wxCommandEvent& event)
516 std::cerr << "Event OnMenuMenuDelete not implemented" << std::endl;
519 void wxCDMMainFrame::OnMenuSelectAll(wxCommandEvent& event)
521 std::cerr << "Event OnMenuSelectAll not implemented" << std::endl;
524 void wxCDMMainFrame::OnMenuSelectNone(wxCommandEvent& event)
526 std::cerr << "Event OnMenuSelectNone not implemented" << std::endl;
531 void wxCDMMainFrame::OnMenuEventLog(wxCommandEvent& event)
533 std::cerr << "Event OnMenuEventLog not implemented" << std::endl;
536 void wxCDMMainFrame::OnMenuBBTKGraphicalEditor(wxCommandEvent& event)
538 std::cerr << "Event OnMenuBBTKGraphicalEditor not implemented" << std::endl;
541 void wxCDMMainFrame::OnMenuMiniTools(wxCommandEvent& event)
543 std::cerr << "Event OnMenuMiniTools not implemented" << std::endl;
546 void wxCDMMainFrame::OnMenuCodeEditor(wxCommandEvent& event)
548 std::cerr << "Event OnMenuCodeEditor not implemented" << std::endl;
551 void wxCDMMainFrame::OnMenuCommandLine(wxCommandEvent& event)
553 std::cerr << "Event OnMenuCommandLine not implemented" << std::endl;
558 void wxCDMMainFrame::OnMenuHelp(wxCommandEvent& event)
560 std::cerr << "Event OnMenuHelp not implemented" << std::endl;
563 void wxCDMMainFrame::OnMenuReportBug(wxCommandEvent& event)
565 std::cerr << "Event OnMenuReportBug not implemented" << std::endl;
568 void wxCDMMainFrame::OnMenuAboutCreaDevManager(wxCommandEvent& event)
570 std::cerr << "Event OnMenuAboutCreaDevManager not implemented" << std::endl;
573 void wxCDMMainFrame::OnMenuAboutCreatis(wxCommandEvent& event)
575 std::cerr << "Event OnMenuAboutCreatis not implemented" << std::endl;
579 void wxCDMMainFrame::OnTreeSelectionChanged(wxTreeEvent& event)
581 std::cout << "New Tree Selection" << std::endl;
582 //get selected element
583 wxTreeItemId elementId = event.GetItem();
585 //get element from model
586 modelCDMIProjectTreeNode* element = this->model->GetModelElements()[elementId];
587 std::cout << "Tree Selection: " << element->GetName() << std::endl;
589 //TODO get element type
590 //TODO create element description
591 //TODO delete old view