[1fcd25]: src / hugin1 / hugin / CPDetectorConfig.cpp Maximize Restore History

Download this file

CPDetectorConfig.cpp    298 lines (268 with data), 9.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
// -*- c-basic-offset: 4 -*-
/** @file CPDetectorConfig.cpp
*
* @brief implementation of CPDetectorSetting, CPDetectorConfig and CPDetectorDialog classes,
* which are for storing and changing settings of different CP detectors
*
* @author Thomas Modes
*
* $Id$
*
*/
/* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "hugin/CPDetectorConfig.h"
#include <config.h>
#include "base_wx/huginConfig.h"
#include "hugin/config_defaults.h"
#include <hugin/CPDetectorConfig_default.h>
#include "hugin/huginApp.h"
#if defined MAC_SELF_CONTAINED_BUNDLE
#include "base_wx/platform.h"
#include <wx/dir.h>
#include <CoreFoundation/CFBundle.h>
#endif
void CPDetectorConfig::Read(wxConfigBase *config)
{
settings.Clear();
int count=config->Read(wxT("/AutoPano/AutoPanoCount"),0l);
default_generator=config->Read(wxT("/AutoPano/Default"),0l);
if(count>0)
{
for(int i=0;i<count;i++)
ReadIndex(config, i);
};
if(settings.GetCount()==0)
ResetToDefault();
if(default_generator>=settings.GetCount())
default_generator=0;
};
void CPDetectorConfig::ReadIndex(wxConfigBase *config, int i)
{
wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
if(config->HasGroup(path))
{
CPDetectorSetting* gen=new CPDetectorSetting;
gen->Read(config,path);
settings.Add(gen);
if(i==default_generator)
default_generator=settings.Index(*gen,true);
};
};
void CPDetectorConfig::Write(wxConfigBase *config)
{
int count=settings.Count();
config->Write(wxT("/AutoPano/AutoPanoCount"),count);
config->Write(wxT("/AutoPano/Default"),(int)default_generator);
if(count>0)
{
for(int i=0;i<count;i++)
WriteIndex(config, i);
};
};
void CPDetectorConfig::WriteIndex(wxConfigBase *config, int i)
{
wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
settings[i].Write(config,path);
};
void CPDetectorConfig::ResetToDefault()
{
settings.Clear();
int maxIndex=sizeof(default_cpdetectors)/sizeof(cpdetector_default)-1;
for(int i=0;i<=maxIndex;i++)
settings.Add(new CPDetectorSetting(i));
default_generator=0;
};
void CPDetectorConfig::FillControl(wxControlWithItems *control,bool select_default,bool show_default)
{
control->Clear();
for(unsigned int i=0;i<settings.GetCount();i++)
{
wxString s=settings[i].GetCPDetectorDesc();
if(show_default && i==default_generator)
s=s+wxT(" (")+_("Default")+wxT(")");
control->Append(s);
};
if(select_default)
control->SetSelection(default_generator);
};
void CPDetectorConfig::Swap(int index)
{
CPDetectorSetting* setting=settings.Detach(index);
settings.Insert(setting,index+1);
if(default_generator==index)
default_generator=index+1;
else
if(default_generator==index+1)
default_generator=index;
};
void CPDetectorConfig::SetDefaultGenerator(unsigned int new_default_generator)
{
if(new_default_generator<GetCount())
default_generator=new_default_generator;
else
default_generator=0;
};
#include <wx/arrimpl.cpp>
WX_DEFINE_OBJARRAY(ArraySettings);
CPDetectorSetting::CPDetectorSetting(int new_type)
{
custom=true;
if(new_type>=0)
{
int maxIndex=sizeof(default_cpdetectors)/sizeof(cpdetector_default)-1;
if (new_type<=maxIndex)
{
type=default_cpdetectors[new_type].type;
desc=default_cpdetectors[new_type].desc;
prog=default_cpdetectors[new_type].prog;
args=default_cpdetectors[new_type].args;
#ifdef MAC_SELF_CONTAINED_BUNDLE
custom=default_cpdetectors[new_type].custom;
#else
custom=true;
#endif
};
};
};
void CPDetectorSetting::Read(wxConfigBase *config, wxString path)
{
type=config->Read(path+wxT("/Type"),default_cpdetectors[0].type);
desc=config->Read(path+wxT("/Description"),default_cpdetectors[0].desc);
prog=config->Read(path+wxT("/Program"),default_cpdetectors[0].prog);
args=config->Read(path+wxT("/Arguments"),default_cpdetectors[0].args);
#if defined MAC_SELF_CONTAINED_BUNDLE
custom=config->Read(path+wxT("/AutopanoExeCustom"),(bool*)default_cpdetectors[0].custom);
#else
custom=true;
#endif
};
void CPDetectorSetting::Write(wxConfigBase *config, wxString path)
{
config->Write(path+wxT("/Type"),type);
config->Write(path+wxT("/Description"),desc);
config->Write(path+wxT("/Program"),prog);
config->Write(path+wxT("/Arguments"),args);
#if defined MAC_SELF_CONTAINED_BUNDLE
config->Write(path+wxT("/AutopanoExeCustom"),custom);
#endif
};
// dialog for showing settings of one autopano setting
BEGIN_EVENT_TABLE(CPDetectorDialog,wxDialog)
EVT_BUTTON(wxID_OK, CPDetectorDialog::OnOk)
EVT_BUTTON(XRCID("prefs_cpdetector_program_select"),CPDetectorDialog::OnSelectPath)
EVT_CHECKBOX(XRCID("prefs_cpdetector_custom"),CPDetectorDialog::OnCustomCPDetector)
END_EVENT_TABLE()
CPDetectorDialog::CPDetectorDialog(wxWindow* parent)
{
wxXmlResource::Get()->LoadDialog(this, parent, wxT("cpdetector_dialog"));
#ifdef __WXMSW__
wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/icon.ico"),wxBITMAP_TYPE_ICO);
#else
wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/icon.png"),wxBITMAP_TYPE_PNG);
#endif
SetIcon(myIcon);
//restore frame position and size
RestoreFramePosition(this,wxT("CPDetectorDialog"));
m_edit_desc = XRCCTRL(*this, "prefs_cpdetector_desc", wxTextCtrl);
m_edit_prog = XRCCTRL(*this, "prefs_cpdetector_program", wxTextCtrl);
m_edit_args = XRCCTRL(*this, "prefs_cpdetector_args", wxTextCtrl);
m_cpdetector_type = XRCCTRL(*this, "prefs_cpdetector_type", wxChoice);
m_cpdetector_type->SetSelection(1);
m_custom_cpdetector = XRCCTRL(*this, "prefs_cpdetector_custom", wxCheckBox);
#ifdef MAC_SELF_CONTAINED_BUNDLE
m_custom_cpdetector->SetValue(FALSE);
#else
m_custom_cpdetector->SetValue(TRUE);
#endif
EnableControls(m_custom_cpdetector->GetValue());
#ifndef MAC_SELF_CONTAINED_BUNDLE
m_custom_cpdetector->Hide();
#endif
};
CPDetectorDialog::~CPDetectorDialog()
{
StoreFramePosition(this,wxT("CPDetectorDialog"));
};
void CPDetectorDialog::OnCustomCPDetector(wxCommandEvent &e)
{
EnableControls(e.IsChecked());
};
void CPDetectorDialog::EnableControls(bool state)
{
m_edit_prog->Enable(state);
XRCCTRL(*this, "prefs_cpdetector_program_select", wxButton)->Enable(state);
};
void CPDetectorDialog::OnOk(wxCommandEvent & e)
{
#ifdef __WXMAC__
if(m_cpdetector_type->GetSelection()==0)
{
wxMessageBox(_("Autopano from http://autopano.kolor.com is not available for OSX"),
_("Using Autopano-Sift instead"),wxOK|wxICON_EXCLAMATION, this);
m_cpdetector_type->SetSelection(1);
};
#endif
bool valid=true;
valid=valid && (m_edit_desc->GetValue().Trim().Len()>0);
if (m_custom_cpdetector->IsChecked())
valid=valid && (m_edit_prog->GetValue().Trim().Len()>0);
valid=valid && (m_edit_args->GetValue().Trim().Len()>0);
if(valid)
this->EndModal(wxOK);
else
wxMessageBox(_("At least one input field is empty.\nPlease check your inputs."),
_("Warning"),wxOK | wxICON_ERROR,this);
};
void CPDetectorDialog::UpdateFields(CPDetectorConfig* cpdet_config,int index)
{
m_edit_desc->SetValue(cpdet_config->settings[index].GetCPDetectorDesc());
m_edit_prog->SetValue(cpdet_config->settings[index].GetProg());
m_edit_args->SetValue(cpdet_config->settings[index].GetArgs());
m_cpdetector_type->SetSelection(cpdet_config->settings[index].GetType());
m_custom_cpdetector->SetValue(cpdet_config->settings[index].GetCPDetectorExeCustom());
EnableControls(m_custom_cpdetector->GetValue());
};
void CPDetectorDialog::UpdateSettings(CPDetectorConfig* cpdet_config,int index)
{
cpdet_config->settings[index].SetCPDetectorDesc(m_edit_desc->GetValue().Trim());
cpdet_config->settings[index].SetProg(m_edit_prog->GetValue().Trim());
cpdet_config->settings[index].SetArgs(m_edit_args->GetValue().Trim());
cpdet_config->settings[index].SetType(m_cpdetector_type->GetSelection());
cpdet_config->settings[index].SetCPDetectorExeCustom(m_custom_cpdetector->GetValue());
};
void CPDetectorDialog::OnSelectPath(wxCommandEvent &e)
{
wxFileName executable(m_edit_prog->GetValue());
#ifdef MAC_SELF_CONTAINED_BUNDLE
wxString autopanoPath = MacGetPathToUserAppSupportAutoPanoFolder();
#endif
wxFileDialog dlg(this,_("Select Autopano program"),
#ifdef MAC_SELF_CONTAINED_BUNDLE
autopanoPath,
#else
executable.GetPath(),
#endif
executable.GetFullName(),
#ifdef __WXMSW__
_("Executables (*.exe,*.vbs,*.cmd, *.bat)|*.exe;*.vbs;*.cmd;*.bat"),
#else
wxT(""),
#endif
wxOPEN, wxDefaultPosition);
if (dlg.ShowModal() == wxID_OK)
m_edit_prog->SetValue(dlg.GetPath());
};