]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMProjectActionsPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMProjectActionsPanel.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 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------ 
24  */
25
26
27 /*
28  * wxCDMProjectActionsPanel.cpp
29  *
30  *  Created on: 25/10/2012
31  *      Author: Daniel Felipe Gonzalez Obando
32  */
33
34 #include "wxCDMProjectActionsPanel.h"
35
36 #include <wx/progdlg.h>
37
38 #include "creaDevManagerIds.h"
39
40 #include <map>
41 #include "wxCDMProjectStructureReportDialog.h"
42
43 BEGIN_EVENT_TABLE(wxCDMProjectActionsPanel, wxPanel)
44 EVT_BUTTON(ID_BUTTON_CHECK_PROJECT, wxCDMProjectActionsPanel::OnBtnCheckProjectStructure)
45 EVT_BUTTON(ID_BUTTON_BUILD_PROJECT, wxCDMProjectActionsPanel::OnBtnBuildProject)
46 EVT_BUTTON(ID_BUTTON_CONFIGURE_BUILD, wxCDMProjectActionsPanel::OnBtnConfigureBuild)
47 EVT_BUTTON(ID_BUTTON_CONNECT_PROJECT, wxCDMProjectActionsPanel::OnBtnConnectProject)
48 END_EVENT_TABLE()
49
50 wxCDMProjectActionsPanel::wxCDMProjectActionsPanel(
51     wxWindow* parent,
52     modelCDMProject* project,
53     wxWindowID id,
54     const wxString& caption,
55     const wxPoint& pos,
56     const wxSize& size,
57     long style
58 )
59 {
60   wxCDMProjectActionsPanel::Create(parent,id,caption,pos,size,style);
61   this->project = project;
62 }
63
64 wxCDMProjectActionsPanel::~wxCDMProjectActionsPanel()
65 {
66 }
67
68 bool wxCDMProjectActionsPanel::Create(
69     wxWindow* parent,
70     wxWindowID id,
71     const wxString& caption,
72     const wxPoint& pos,
73     const wxSize& size,
74     long style
75 )
76 {
77   wxPanel::Create(parent,id,pos,size,style);
78   wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
79   this->SetSizer(sizer);
80
81   CreateControls();
82
83   return TRUE;
84 }
85
86 void wxCDMProjectActionsPanel::CreateControls()
87 {
88   wxButton* checkStructbt = new wxButton(this, ID_BUTTON_CHECK_PROJECT, _T("1. Check Project Structure"));
89   checkStructbt->SetToolTip(wxT("This step checks the project structure and tells what is going to be compiled."));
90   wxButton* configurebt = new wxButton(this, ID_BUTTON_CONFIGURE_BUILD, _T("2. Configure Project (CMake)"));
91   configurebt->SetToolTip(wxT("This is the second step in order to execute the project. Make sure you have selected the desired Build location."));
92   wxButton* compilebt = new wxButton(this, ID_BUTTON_BUILD_PROJECT, _T("3. Compile Project"));
93   compilebt->SetToolTip(wxT("This step should be done after configuring the project. This will create the executables."));
94   wxButton* plugbt = new wxButton(this, ID_BUTTON_CONNECT_PROJECT, _T("4. Plug Packages (BBTK)"));
95   plugbt->SetToolTip(wxT("This step should be done after compiling the project. This will allow to use the boxes in this project to be available in the bbEditor."));
96   this->GetSizer()->Add(checkStructbt, 0, wxALL, 5);
97   this->GetSizer()->Add(configurebt, 0, wxALL, 5);
98   this->GetSizer()->Add(compilebt, 0, wxALL, 5);
99   this->GetSizer()->Add(plugbt, 0, wxALL, 5);
100 }
101
102 //check project structure
103 void wxCDMProjectActionsPanel::OnBtnCheckProjectStructure(wxCommandEvent& event)
104 {
105   std::map<std::string, bool> prjStruct;
106   this->project->CheckStructure(prjStruct);
107   std::cout << prjStruct.size() << std::endl;
108   wxCDMProjectStructureReportDialog* structure = new wxCDMProjectStructureReportDialog(this->GetParent(), prjStruct, wxID_ANY);
109   structure->Show(true);
110 }
111
112 //configure project
113 void wxCDMProjectActionsPanel::OnBtnConfigureBuild(wxCommandEvent& event)
114 {
115   std::string* result;
116   if(!this->project->ConfigureBuild(result))
117     {
118       wxMessageBox(crea::std2wx(result->c_str()), wxT("Project Configuration - Error!"));
119       return;
120     }
121   wxMessageBox(crea::std2wx("The configuration was executed successfully."), wxT("Project Configuration"));
122 }
123
124 //compile project
125 void wxCDMProjectActionsPanel::OnBtnBuildProject(wxCommandEvent& event)
126 {
127 #ifdef _WIN32
128         std::string* result;
129         if(!this->project->Build(result, ""))
130         {
131           wxMessageBox(crea::std2wx(result->c_str()), wxT("Project Compilation - Error!"));
132           return;
133         }
134 #else
135   //get author from user
136   wxTextEntryDialog* buildDlg = new wxTextEntryDialog(
137       this,
138       wxT("Enter the compilation instruction:"),
139       wxT("Project Compilation- creaDevManager"),
140       crea::std2wx(this->project->GetBuildInstruction()),
141       wxTE_MULTILINE | wxOK | wxCANCEL
142   );
143
144   if (buildDlg->ShowModal() == wxID_OK)
145     {
146       std::string buildDlgStr = crea::wx2std(buildDlg->GetValue());
147       //check name
148       if (buildDlgStr != "")
149         {
150           std::string* result;
151           //wxProgressDialog* loadBar = new wxProgressDialog(wxT("Compiling"), wxT("Please wait while the compilation is executing..."), 100, this);
152           //loadBar->Pulse();
153           if(!this->project->Build(result, buildDlgStr))
154             {
155               //loadBar->Destroy();
156               wxMessageBox(crea::std2wx(result->c_str()), wxT("Project Compilation - Error!"));
157               return;
158             }
159           //loadBar->Destroy();
160           //wxMessageBox(crea::std2wx("The compilation was executed successfully. Please check the \"building.log\" file located in the build folder to check the compilation result."), wxT("Project Compilation"));
161         }
162     }
163 #endif
164 }
165 //plug packages
166 void wxCDMProjectActionsPanel::OnBtnConnectProject(wxCommandEvent& event)
167 {
168   std::string* result;
169   wxString file = wxDirSelector(
170     wxT("Please select the folder containing the bbtkPackage file you want to use. Usually it is where you built your project."),
171     crea::std2wx(this->project->GetBuildPath())
172   );
173   std::cout << crea::wx2std(file) << std::endl;
174   std::cout.flush();
175
176   if(crea::wx2std(file) == "" || !this->project->Connect(result, crea::wx2std(file)))
177     {
178       if (crea::wx2std(file) == "")
179         result = new std::string("Folder not specified.");
180       wxMessageBox(crea::std2wx(result->c_str()), wxT("Plug BBTK Packages - Error!"), wxICON_ERROR);
181       return;
182     }
183 #ifdef _WIN32
184   wxMessageBox(crea::std2wx("The connection was executed successfully. Please check the console to see the compilation result."), wxT("Plug Package"));
185 #else
186   wxMessageBox(crea::std2wx("The connection was executed successfully. Please check the \"plugging.log\" file located in the build folder to see the compilation result."), wxT("Plug Package"));
187 #endif
188   
189 }