]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMPackageConfigurationDialog.cpp
e88415b928f664d02a94bb51519c8e978198f005
[crea.git] / lib / creaDevManagerLib / wxCDMPackageConfigurationDialog.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 /*
30  * wxCDMPackageConfigurationDialog.cpp
31  *
32  *  Created on: 6/4/2013
33  *      Author: Daniel Felipe Gonzalez Obando
34  */
35
36 #include "wxCDMPackageConfigurationDialog.h"
37
38 #include "creaDevManagerIds.h"
39
40 BEGIN_EVENT_TABLE(wxCDMPackageConfigurationDialog, wxDialog)
41 EVT_BUTTON(wxID_OK, wxCDMPackageConfigurationDialog::OnFinish)
42 EVT_CHECKBOX(ID_CHECK_INCLUDE_3RDLIBRARY, wxCDMPackageConfigurationDialog::On3rdLibraryIncludeChange)
43 EVT_CHECKBOX(ID_CHECK_INCLUDE_LIBRARY, wxCDMPackageConfigurationDialog::OnCustomLibraryIncludeChange)
44 END_EVENT_TABLE()
45
46 wxCDMPackageConfigurationDialog::wxCDMPackageConfigurationDialog(
47     wxWindow* parent,
48     modelCDMPackage* package,
49     wxWindowID id,
50     const wxString& caption,
51     const wxPoint& position,
52     const wxSize& size,
53     long style
54 )
55 {
56   this->package = package;
57   wxCDMPackageConfigurationDialog::Create(parent, id, caption, position, size, style);
58 }
59
60 wxCDMPackageConfigurationDialog::~wxCDMPackageConfigurationDialog()
61 {
62 }
63
64 bool wxCDMPackageConfigurationDialog::Create(
65     wxWindow* parent,
66     wxWindowID id,
67     const wxString& caption,
68     const wxPoint& position,
69     const wxSize& size,
70     long int style
71 )
72 {
73   wxDialog::Create(parent, id, caption, position, size, style);
74
75   this->CreateControls();
76
77   return TRUE;
78 }
79
80 void wxCDMPackageConfigurationDialog::CreateControls()
81 {
82
83   wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL);
84
85
86   wxStaticText* title = new wxStaticText(this, wxID_ANY, wxT("Please select the libraries that are used in this package."), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);//new wxRichTextCtrl(this,wxID_ANY, wxString("Create a new project"), wxDefaultPosition, wxDefaultSize, wxRE_READONLY);
87   v_sizer1->Add(title, 0, wxEXPAND | wxALIGN_LEFT | wxALL, 5);
88
89   wxScrolledWindow* includesPanel = new wxScrolledWindow(this);
90   includesPanel->FitInside();
91   includesPanel->SetScrollRate(5,5);
92
93   wxBoxSizer* includesPanelSizer = new wxBoxSizer(wxVERTICAL);
94
95     //Third Party Libraries
96     wxStaticText* Title1 = new wxStaticText(includesPanel, wxID_ANY, wxT("Third Party Libraries:"));
97     wxFont font = Title1->GetFont();
98     font.SetWeight(wxFONTWEIGHT_BOLD);
99     Title1->SetFont(font);
100     includesPanelSizer->Add(Title1, 0, wxEXPAND);
101
102     //inclusion data
103     std::map<std::string, bool> inclusions = this->package->Get3rdPartyLibraries();
104     //includesGrid Sizer
105     wxFlexGridSizer* includesGridSizer = new wxFlexGridSizer(inclusions.size()+1, 2, 0, 5);
106
107     wxStaticText* ChBTitle = new wxStaticText(
108         includesPanel,
109         wxID_ANY,
110         wxT("Included"),
111         wxDefaultPosition,
112         wxDefaultSize,
113         wxALIGN_CENTER
114       );
115     wxStaticText* LNmTitle = new wxStaticText(
116         includesPanel,
117         wxID_ANY,
118         wxT("Library Name"),
119         wxDefaultPosition,
120         wxDefaultSize,
121         wxALIGN_LEFT
122       );
123
124     includesGridSizer->Add(ChBTitle, 1, wxEXPAND);
125     includesGridSizer->Add(LNmTitle, 1, wxEXPAND);
126
127     for (std::map<std::string, bool>::iterator it = inclusions.begin(); it != inclusions.end(); ++it) {
128       wxCheckBox* ChBIncl = new wxCheckBox(
129           includesPanel, ID_CHECK_INCLUDE_3RDLIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT
130         );
131       ChBIncl->SetToolTip(crea::std2wx(
132           "When this box is checked the " + it->first + " library\n"
133           "is included in the project configuration for\n"
134           "this package including the following instruction\n"
135           "in the package's folder CMakeLists.txt file:\n"
136           "SET(${BBTK_PACKAGE_NAME}_USE_" + it->first+ "  ON)\n"
137           ));
138       ChBIncl->SetName(crea::std2wx(it->first));
139       ChBIncl->SetValue(it->second);
140       includesGridSizer->Add(ChBIncl, 1, wxEXPAND);
141
142       wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first));
143       includesGridSizer->Add(LNmIncl, 1, wxEXPAND);
144     }
145
146     includesGridSizer->AddGrowableCol(1,1);
147
148     includesPanelSizer->Add(includesGridSizer, 1, wxEXPAND | wxLEFT, 5);
149
150     //Custom Libraries
151     wxStaticText* Title2 = new wxStaticText(includesPanel, wxID_ANY, wxT("Custom Libraries:"));
152     font = Title2->GetFont();
153     font.SetWeight(wxFONTWEIGHT_BOLD);
154     Title2->SetFont(font);
155     includesPanelSizer->Add(Title2, 0, wxEXPAND);
156
157     //inclusion data
158     std::map<std::string, bool> inclusionsLibs = this->package->GetCustomLibraries();
159     //includesGrid Sizer
160     wxFlexGridSizer* includesLibGridSizer = new wxFlexGridSizer(inclusionsLibs.size()+1, 2, 0, 5);
161
162     wxStaticText* ChBTitle1 = new wxStaticText(
163         includesPanel,
164         wxID_ANY,
165         wxT("Included"),
166         wxDefaultPosition,
167         wxDefaultSize,
168         wxALIGN_CENTER
169       );
170     wxStaticText* LNmTitle1 = new wxStaticText(
171         includesPanel,
172         wxID_ANY,
173         wxT("Library Name"),
174         wxDefaultPosition,
175         wxDefaultSize,
176         wxALIGN_LEFT
177       );
178
179     includesLibGridSizer->Add(ChBTitle1, 1, wxEXPAND);
180     includesLibGridSizer->Add(LNmTitle1, 1, wxEXPAND);
181
182     for (std::map<std::string, bool>::iterator it = inclusionsLibs.begin(); it != inclusionsLibs.end(); ++it) {
183       wxCheckBox* ChBIncl = new wxCheckBox(
184           includesPanel, ID_CHECK_INCLUDE_LIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT
185         );
186       ChBIncl->SetToolTip(crea::std2wx(
187           "When this box is checked the " + it->first + " custom\n"
188           "library is included in the project configuration for\n"
189           "this packages including the following code in the\n"
190           "package's folder CMakeLists.txt file:\n"
191           "SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS\n"
192           "  ../lib/"+ it->first + "\n"
193           ")\n"
194           "SET(${BBTK_PACKAGE_NAME}_LIBS\n"
195           "  " + it->first+ "\n"
196           ")"));
197       ChBIncl->SetName(crea::std2wx(it->first));
198       ChBIncl->SetValue(it->second);
199       includesLibGridSizer->Add(ChBIncl, 1, wxEXPAND);
200
201       wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first));
202       includesLibGridSizer->Add(LNmIncl, 1, wxEXPAND);
203     }
204
205     includesLibGridSizer->AddGrowableCol(1,1);
206
207     includesPanelSizer->Add(includesLibGridSizer, 0, wxEXPAND | wxLEFT, 5);
208
209     includesPanel->SetSizer(includesPanelSizer);
210
211     v_sizer1->Add(includesPanel, 1, wxEXPAND | wxALL, 10);
212
213   v_sizer1->Add(new wxButton(this, wxID_OK, wxT("Close")), 0, wxALIGN_CENTER | wxRIGHT | wxBOTTOM, 30);
214
215   SetSizer(v_sizer1);
216 }
217
218 void wxCDMPackageConfigurationDialog::OnFinish(wxCommandEvent& event)
219 {
220   this->EndModal(wxID_OK);
221 }
222
223 void wxCDMPackageConfigurationDialog::On3rdLibraryIncludeChange(
224     wxCommandEvent& event)
225 {
226   if(this->package->Set3rdPartyLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue()))
227     ((wxCheckBox*)event.GetEventObject())->SetValue(((wxCheckBox*)event.GetEventObject())->GetValue());
228   else
229     ((wxCheckBox*)event.GetEventObject())->SetValue(!((wxCheckBox*)event.GetEventObject())->GetValue());
230 }
231
232 void wxCDMPackageConfigurationDialog::OnCustomLibraryIncludeChange(
233     wxCommandEvent& event)
234 {
235   if(this->package->SetCustomLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue()))
236       ((wxCheckBox*)event.GetEventObject())->SetValue(((wxCheckBox*)event.GetEventObject())->GetValue());
237     else
238       ((wxCheckBox*)event.GetEventObject())->SetValue(!((wxCheckBox*)event.GetEventObject())->GetValue());
239 }