]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMProjectActionsPanel.cpp
#3136 creaFeature New Normal - branch vtk7itk4wx3
[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   CreateControls();
81   // this part makes the scrollbars show up
82   this->FitInside(); // ask the sizer about the needed size
83   this->SetScrollRate(5, 5);
84   return TRUE;
85 }
86
87 void wxCDMProjectActionsPanel::CreateControls()
88 {
89   wxButton* checkStructbt = new wxButton(this, ID_BUTTON_CHECK_PROJECT, _T("1. Check Project Structure"));
90   checkStructbt->SetToolTip(wxT("This step checks the project structure and tells what is going to be compiled."));
91   wxButton* configurebt = new wxButton(this, ID_BUTTON_CONFIGURE_BUILD, _T("2. Configure Project (CMake)"));
92   configurebt->SetToolTip(wxT("This is the second step in order to execute the project. Make sure you have selected the desired Build location."));
93   wxButton* compilebt = new wxButton(this, ID_BUTTON_BUILD_PROJECT, _T("3. Compile Project"));
94   compilebt->SetToolTip(wxT("This step should be done after configuring the project. This will create the executables."));
95   wxButton* plugbt = new wxButton(this, ID_BUTTON_CONNECT_PROJECT, _T("4. Plug Packages (BBTK)"));
96   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."));
97   this->GetSizer()->Add(checkStructbt, 0, wxALL, 5);
98   this->GetSizer()->Add(configurebt, 0, wxALL, 5);
99   this->GetSizer()->Add(compilebt, 0, wxALL, 5);
100   this->GetSizer()->Add(plugbt, 0, wxALL, 5);
101 }
102
103 //check project structure
104 void wxCDMProjectActionsPanel::OnBtnCheckProjectStructure(wxCommandEvent& event)
105 {
106   std::map<std::string, bool> prjStruct;
107   this->project->CheckStructure(prjStruct);
108   std::cout << prjStruct.size() << std::endl;
109   wxCDMProjectStructureReportDialog* structure = new wxCDMProjectStructureReportDialog(this->GetParent(), prjStruct, wxID_ANY);
110   structure->Show(true);
111 }
112
113 //configure project
114 void wxCDMProjectActionsPanel::OnBtnConfigureBuild(wxCommandEvent& event)
115 {
116   std::string* result;
117   if(!this->project->ConfigureBuild(result))
118     {
119       wxMessageBox(crea::std2wx(result->c_str()), wxT("Project Configuration - Error!"));
120       return;
121     }
122   wxMessageBox(crea::std2wx("The configuration was executed successfully."), wxT("Project Configuration"));
123 }
124
125 //compile project
126 void wxCDMProjectActionsPanel::OnBtnBuildProject(wxCommandEvent& event)
127 {
128 #ifdef _WIN32
129   std::string* result;
130   if(!this->project->Build(result, ""))
131     {
132       wxMessageBox(crea::std2wx(result->c_str()), wxT("Project Compilation - Error!"));
133       return;
134     }
135 #else
136
137   std::string* result;
138   int isDir = wxMessageBox(crea::std2wx("Is this the path of the project compilation?:\n"+this->project->GetBuildPath()), wxT("Project Compilation - CreaDevManager"), wxYES_NO|wxCANCEL);
139   if(isDir != wxCANCEL)
140     {
141       wxString file = crea::std2wx(this->project->GetBuildPath());
142       if(isDir == wxNO)
143         {
144           file = wxDirSelector(
145               wxT("Please select the folder where your project is to be built."),
146               crea::std2wx(this->project->GetBuildPath())
147           );
148         }
149
150       if(!file.IsEmpty())
151         {
152           this->project->SetBuildPath(crea::wx2std(file), result);
153
154           wxTextEntryDialog* buildDlg = new wxTextEntryDialog(
155                 this,
156                 wxT("Check the compilation instruction:"),
157                 wxT("Project Compilation - CreaDevManager"),
158                 crea::std2wx(this->project->GetBuildInstruction()),
159                 wxTE_MULTILINE | wxOK | wxCANCEL
160             );
161
162           if (buildDlg->ShowModal() == wxID_OK)
163             {
164               std::string buildDlgStr = crea::wx2std(buildDlg->GetValue());
165               //check line
166               if (buildDlgStr != "")
167                 {
168                   std::string* result;
169                   if(!this->project->Build(result, buildDlgStr))
170                     {
171                       wxMessageBox(crea::std2wx(result->c_str()), wxT("Project Compilation - Error!"));
172                       return;
173                     }
174                 }
175             }
176         }
177     }
178 #endif
179 }
180 //plug packages
181 void wxCDMProjectActionsPanel::OnBtnConnectProject(wxCommandEvent& event)
182 {
183   std::string* result;
184   int isDir = wxMessageBox(crea::std2wx("Is this the path of the project compilation to plug?:\n"+this->project->GetBuildPath()), wxT("Plug BBTK Packages"), wxYES_NO|wxCANCEL);
185   if(isDir != wxCANCEL)
186     {
187       wxString file = crea::std2wx(this->project->GetBuildPath());
188       if(isDir == wxNO)
189         {
190           file = wxDirSelector(
191               wxT("Please select the folder containing the bbtkPackage file you want to use. Usually it is where you built your project."),
192               crea::std2wx(this->project->GetBuildPath())
193           );
194         }
195
196       if(!file.IsEmpty())
197         {
198           if(!this->project->Connect(result, crea::wx2std(file)))
199             {
200               wxMessageBox(crea::std2wx(result->c_str()), wxT("Plug BBTK Packages - Error!"), wxICON_ERROR);
201               return;
202             }
203           else
204             {
205               wxMessageBox(crea::std2wx("The connection was executed successfully. Please check the console to see the compilation result.\n Also, don't forget to restart the BBTK Graphical Editor (if already opened) to see the plugged packages."), wxT("Plug Package"));
206             }
207
208         }
209
210     }
211 }