]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMPackageConfigurationDialog.cpp
Feature #1711 CreaDevManager application implementation
[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("When this box is checked the " + it->first + " library is included in the project configuration for this library."));
132       ChBIncl->SetName(crea::std2wx(it->first));
133       ChBIncl->SetValue(it->second);
134       includesGridSizer->Add(ChBIncl, 1, wxEXPAND);
135
136       wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first));
137       includesGridSizer->Add(LNmIncl, 1, wxEXPAND);
138     }
139
140     includesGridSizer->AddGrowableCol(1,1);
141
142     includesPanelSizer->Add(includesGridSizer, 1, wxEXPAND | wxLEFT, 5);
143
144     //Custom Libraries
145     wxStaticText* Title2 = new wxStaticText(includesPanel, wxID_ANY, wxT("Custom Libraries:"));
146     font = Title2->GetFont();
147     font.SetWeight(wxFONTWEIGHT_BOLD);
148     Title2->SetFont(font);
149     includesPanelSizer->Add(Title2, 0, wxEXPAND);
150
151     //inclusion data
152     std::map<std::string, bool> inclusionsLibs = this->package->GetCustomLibraries();
153     //includesGrid Sizer
154     wxFlexGridSizer* includesLibGridSizer = new wxFlexGridSizer(inclusionsLibs.size()+1, 2, 0, 5);
155
156     wxStaticText* ChBTitle1 = new wxStaticText(
157         includesPanel,
158         wxID_ANY,
159         wxT("Included"),
160         wxDefaultPosition,
161         wxDefaultSize,
162         wxALIGN_CENTER
163       );
164     wxStaticText* LNmTitle1 = new wxStaticText(
165         includesPanel,
166         wxID_ANY,
167         wxT("Library Name"),
168         wxDefaultPosition,
169         wxDefaultSize,
170         wxALIGN_LEFT
171       );
172
173     includesLibGridSizer->Add(ChBTitle1, 1, wxEXPAND);
174     includesLibGridSizer->Add(LNmTitle1, 1, wxEXPAND);
175
176     for (std::map<std::string, bool>::iterator it = inclusionsLibs.begin(); it != inclusionsLibs.end(); ++it) {
177       wxCheckBox* ChBIncl = new wxCheckBox(
178           includesPanel, ID_CHECK_INCLUDE_LIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT
179         );
180       ChBIncl->SetToolTip(crea::std2wx("When this box is checked the " + it->first + " custom library is included in the project configuration for this library."));
181       ChBIncl->SetName(crea::std2wx(it->first));
182       ChBIncl->SetValue(it->second);
183       includesLibGridSizer->Add(ChBIncl, 1, wxEXPAND);
184
185       wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first));
186       includesLibGridSizer->Add(LNmIncl, 1, wxEXPAND);
187     }
188
189     includesLibGridSizer->AddGrowableCol(1,1);
190
191     includesPanelSizer->Add(includesLibGridSizer, 0, wxEXPAND | wxLEFT, 5);
192
193     includesPanel->SetSizer(includesPanelSizer);
194
195     v_sizer1->Add(includesPanel, 1, wxEXPAND | wxALL, 10);
196
197   v_sizer1->Add(new wxButton(this, wxID_OK, wxT("Close")), 0, wxALIGN_CENTER | wxRIGHT | wxBOTTOM, 30);
198
199   SetSizer(v_sizer1);
200 }
201
202 void wxCDMPackageConfigurationDialog::OnFinish(wxCommandEvent& event)
203 {
204   this->EndModal(wxID_OK);
205 }
206
207 void wxCDMPackageConfigurationDialog::On3rdLibraryIncludeChange(
208     wxCommandEvent& event)
209 {
210   if(this->package->Set3rdPartyLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue()))
211     ((wxCheckBox*)event.GetEventObject())->SetValue(((wxCheckBox*)event.GetEventObject())->GetValue());
212   else
213     ((wxCheckBox*)event.GetEventObject())->SetValue(!((wxCheckBox*)event.GetEventObject())->GetValue());
214 }
215
216 void wxCDMPackageConfigurationDialog::OnCustomLibraryIncludeChange(
217     wxCommandEvent& event)
218 {
219   this->package->SetCustomLibrary(
220     crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()),
221     ((wxCheckBox*)event.GetEventObject())->GetValue()
222   );
223 }