1
// -*- c-basic-offset: 4 -*-
3
/** @file CPDetectorConfig.cpp
5
* @brief implementation of CPDetectorSetting, CPDetectorConfig and CPDetectorDialog classes,
6
* which are for storing and changing settings of different CP detectors
14
/* This is free software; you can redistribute it and/or
15
* modify it under the terms of the GNU General Public
16
* License as published by the Free Software Foundation; either
17
* version 2 of the License, or (at your option) any later version.
19
* This software is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
* Lesser General Public License for more details.
24
* You should have received a copy of the GNU General Public
25
* License along with this software; if not, write to the Free Software
26
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
#include "hugin/CPDetectorConfig.h"
32
#include "base_wx/huginConfig.h"
33
#include "hugin/config_defaults.h"
34
#include <hugin/CPDetectorConfig_default.h>
35
#include "hugin/huginApp.h"
37
#if defined MAC_SELF_CONTAINED_BUNDLE
38
#include "base_wx/platform.h"
40
#include <CoreFoundation/CFBundle.h>
44
void CPDetectorConfig::Read(wxConfigBase *config)
47
int count=config->Read(wxT("/AutoPano/AutoPanoCount"),0l);
48
default_generator=config->Read(wxT("/AutoPano/Default"),0l);
51
for(int i=0;i<count;i++)
54
if(settings.GetCount()==0)
56
if(default_generator>=settings.GetCount())
60
void CPDetectorConfig::ReadIndex(wxConfigBase *config, int i)
62
wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
63
if(config->HasGroup(path))
65
CPDetectorSetting* gen=new CPDetectorSetting;
66
gen->Read(config,path);
68
if(i==default_generator)
69
default_generator=settings.Index(*gen,true);
73
void CPDetectorConfig::Write(wxConfigBase *config)
75
int count=settings.Count();
76
config->Write(wxT("/AutoPano/AutoPanoCount"),count);
77
config->Write(wxT("/AutoPano/Default"),(int)default_generator);
80
for(int i=0;i<count;i++)
81
WriteIndex(config, i);
85
void CPDetectorConfig::WriteIndex(wxConfigBase *config, int i)
87
wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
88
settings[i].Write(config,path);
91
void CPDetectorConfig::ResetToDefault()
94
int maxIndex=sizeof(default_cpdetectors)/sizeof(cpdetector_default)-1;
95
for(int i=0;i<=maxIndex;i++)
96
settings.Add(new CPDetectorSetting(i));
100
void CPDetectorConfig::FillControl(wxControlWithItems *control,bool select_default,bool show_default)
103
for(unsigned int i=0;i<settings.GetCount();i++)
105
wxString s=settings[i].GetCPDetectorDesc();
106
if(show_default && i==default_generator)
107
s=s+wxT(" (")+_("Default")+wxT(")");
111
control->SetSelection(default_generator);
114
void CPDetectorConfig::Swap(int index)
116
CPDetectorSetting* setting=settings.Detach(index);
117
settings.Insert(setting,index+1);
118
if(default_generator==index)
119
default_generator=index+1;
121
if(default_generator==index+1)
122
default_generator=index;
125
void CPDetectorConfig::SetDefaultGenerator(unsigned int new_default_generator)
127
if(new_default_generator<GetCount())
128
default_generator=new_default_generator;
133
#include <wx/arrimpl.cpp>
134
WX_DEFINE_OBJARRAY(ArraySettings);
136
CPDetectorSetting::CPDetectorSetting(int new_type)
140
int maxIndex=sizeof(default_cpdetectors)/sizeof(cpdetector_default)-1;
141
if (new_type<=maxIndex)
143
type=default_cpdetectors[new_type].type;
144
desc=default_cpdetectors[new_type].desc;
145
prog=default_cpdetectors[new_type].prog;
146
args=default_cpdetectors[new_type].args;
147
prog_matcher=default_cpdetectors[new_type].prog_matcher;
148
args_matcher=default_cpdetectors[new_type].args_matcher;
149
if(type==CPDetector_AutoPanoSiftStack || type==CPDetector_AutoPanoSiftMultiRowStack)
151
prog_stack=default_cpdetectors[new_type].prog_stack;
152
args_stack=default_cpdetectors[new_type].args_stack;
156
prog_stack=wxEmptyString;
157
args_stack=wxEmptyString;
159
option=default_cpdetectors[new_type].option;
164
type=CPDetector_AutoPanoSift;
168
prog_matcher=wxEmptyString;
169
args_matcher=wxEmptyString;
170
prog_stack=wxEmptyString;
171
args_stack=wxEmptyString;
177
void CPDetectorSetting::CheckValues()
179
if(type==CPDetector_AutoPano)
181
if(!prog_matcher.IsEmpty())
183
prog_matcher=wxEmptyString;
184
args_matcher=wxEmptyString;
189
void CPDetectorSetting::Read(wxConfigBase *config, wxString path)
191
type=(CPDetectorType)config->Read(path+wxT("/Type"),default_cpdetectors[0].type);
192
desc=config->Read(path+wxT("/Description"),default_cpdetectors[0].desc);
193
prog=config->Read(path+wxT("/Program"),default_cpdetectors[0].prog);
194
args=config->Read(path+wxT("/Arguments"),default_cpdetectors[0].args);
195
prog_matcher=config->Read(path+wxT("/ProgramMatcher"),default_cpdetectors[0].prog_matcher);
196
args_matcher=config->Read(path+wxT("/ArgumentsMatcher"),default_cpdetectors[0].args_matcher);
197
if(type==CPDetector_AutoPanoSiftStack || type==CPDetector_AutoPanoSiftMultiRowStack)
199
prog_stack=config->Read(path+wxT("/ProgramStack"),default_cpdetectors[0].prog_stack);
200
args_stack=config->Read(path+wxT("/ArgumentsStack"),default_cpdetectors[0].args_stack);
204
prog_stack=wxEmptyString;
205
args_stack=wxEmptyString;
207
option=config->Read(path+wxT("/Option"),default_cpdetectors[0].option);
211
void CPDetectorSetting::Write(wxConfigBase *config, wxString path)
213
config->Write(path+wxT("/Type"),type);
214
config->Write(path+wxT("/Description"),desc);
215
config->Write(path+wxT("/Program"),prog);
216
config->Write(path+wxT("/Arguments"),args);
217
config->Write(path+wxT("/ProgramMatcher"),prog_matcher);
218
config->Write(path+wxT("/ArgumentsMatcher"),args_matcher);
219
if(type==CPDetector_AutoPanoSiftStack || type==CPDetector_AutoPanoSiftMultiRowStack)
221
config->Write(path+wxT("/ProgramStack"),prog_stack);
222
config->Write(path+wxT("/ArgumentsStack"),args_stack);
224
config->Write(path+wxT("/Option"),option);
227
// dialog for showing settings of one autopano setting
229
BEGIN_EVENT_TABLE(CPDetectorDialog,wxDialog)
230
EVT_BUTTON(wxID_OK, CPDetectorDialog::OnOk)
231
EVT_BUTTON(XRCID("prefs_cpdetector_program_select"),CPDetectorDialog::OnSelectPath)
232
EVT_BUTTON(XRCID("prefs_cpdetector_program_descriptor_select"),CPDetectorDialog::OnSelectPathDescriptor)
233
EVT_BUTTON(XRCID("prefs_cpdetector_program_matcher_select"),CPDetectorDialog::OnSelectPathMatcher)
234
EVT_BUTTON(XRCID("prefs_cpdetector_program_stack_select"),CPDetectorDialog::OnSelectPathStack)
235
EVT_CHOICE(XRCID("prefs_cpdetector_type"),CPDetectorDialog::OnTypeChange)
236
EVT_CHOICEBOOK_PAGE_CHANGING(XRCID("choicebook_steps"),CPDetectorDialog::OnStepChanging)
239
CPDetectorDialog::CPDetectorDialog(wxWindow* parent)
241
wxXmlResource::Get()->LoadDialog(this, parent, wxT("cpdetector_dialog"));
243
wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/icon.ico"),wxBITMAP_TYPE_ICO);
245
wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/icon.png"),wxBITMAP_TYPE_PNG);
249
//restore frame position and size
250
RestoreFramePosition(this,wxT("CPDetectorDialog"));
252
m_edit_desc = XRCCTRL(*this, "prefs_cpdetector_desc", wxTextCtrl);
253
m_edit_prog = XRCCTRL(*this, "prefs_cpdetector_program", wxTextCtrl);
254
m_edit_args = XRCCTRL(*this, "prefs_cpdetector_args", wxTextCtrl);
255
m_edit_prog_descriptor = XRCCTRL(*this, "prefs_cpdetector_program_descriptor", wxTextCtrl);
256
m_edit_args_descriptor = XRCCTRL(*this, "prefs_cpdetector_args_descriptor", wxTextCtrl);
257
m_edit_prog_matcher = XRCCTRL(*this, "prefs_cpdetector_program_matcher", wxTextCtrl);
258
m_edit_args_matcher = XRCCTRL(*this, "prefs_cpdetector_args_matcher", wxTextCtrl);
259
m_edit_prog_stack = XRCCTRL(*this, "prefs_cpdetector_program_stack", wxTextCtrl);
260
m_edit_args_stack = XRCCTRL(*this, "prefs_cpdetector_args_stack", wxTextCtrl);
261
m_check_option = XRCCTRL(*this, "prefs_cpdetector_option", wxCheckBox);
262
m_cpdetector_type = XRCCTRL(*this, "prefs_cpdetector_type", wxChoice);
263
m_choice_step = XRCCTRL(*this, "choicebook_steps", wxChoicebook);
264
m_cpdetector_type->SetSelection(1);
268
CPDetectorDialog::~CPDetectorDialog()
270
StoreFramePosition(this,wxT("CPDetectorDialog"));
273
void CPDetectorDialog::OnOk(wxCommandEvent & e)
276
if(m_cpdetector_type->GetSelection()==0)
278
wxMessageBox(_("Autopano from http://autopano.kolor.com is not available for OSX"),
279
_("Using Autopano-Sift instead"),wxOK|wxICON_EXCLAMATION, this);
280
m_cpdetector_type->SetSelection(1);
284
valid=valid && (m_edit_desc->GetValue().Trim().Len()>0);
285
if(m_choice_step->GetSelection()==0)
287
//detector with one step
288
valid=valid && (m_edit_prog->GetValue().Trim().Len()>0);
289
valid=valid && (m_edit_args->GetValue().Trim().Len()>0);
293
//detector with two steps
294
valid=valid && (m_edit_prog_descriptor->GetValue().Trim().Len()>0);
295
valid=valid && (m_edit_prog_matcher->GetValue().Trim().Len()>0);
296
valid=valid && (m_edit_args_descriptor->GetValue().Trim().Len()>0);
297
valid=valid && (m_edit_args_matcher->GetValue().Trim().Len()>0);
299
int type=m_cpdetector_type->GetSelection();
300
if(type==CPDetector_AutoPanoSiftStack || type==CPDetector_AutoPanoSiftMultiRowStack)
301
if(m_edit_prog_stack->GetValue().Trim().Len()>0)
302
valid=valid && (m_edit_args_stack->GetValue().Trim().Len()>0);
304
this->EndModal(wxOK);
306
wxMessageBox(_("At least one input field is empty.\nPlease check your inputs."),
307
_("Warning"),wxOK | wxICON_ERROR,this);
310
void CPDetectorDialog::UpdateFields(CPDetectorConfig* cpdet_config,int index)
312
m_edit_desc->SetValue(cpdet_config->settings[index].GetCPDetectorDesc());
313
//program names and arguments
314
if(cpdet_config->settings[index].IsTwoStepDetector())
316
m_choice_step->SetSelection(1);
317
m_edit_prog_descriptor->SetValue(cpdet_config->settings[index].GetProg());
318
m_edit_prog_matcher->SetValue(cpdet_config->settings[index].GetProgMatcher());
319
m_edit_args_descriptor->SetValue(cpdet_config->settings[index].GetArgs());
320
m_edit_args_matcher->SetValue(cpdet_config->settings[index].GetArgsMatcher());
324
m_choice_step->SetSelection(0);
325
m_edit_prog->SetValue(cpdet_config->settings[index].GetProg());
326
m_edit_args->SetValue(cpdet_config->settings[index].GetArgs());
328
int type=cpdet_config->settings[index].GetType();
329
if(type==CPDetector_AutoPanoSiftStack || type==CPDetector_AutoPanoSiftMultiRowStack)
331
m_edit_prog_stack->SetValue(cpdet_config->settings[index].GetProgStack());
332
m_edit_args_stack->SetValue(cpdet_config->settings[index].GetArgsStack());
334
m_cpdetector_type->SetSelection(type);
335
m_check_option->SetValue(cpdet_config->settings[index].GetOption());
339
void CPDetectorDialog::UpdateSettings(CPDetectorConfig* cpdet_config,int index)
341
cpdet_config->settings[index].SetCPDetectorDesc(m_edit_desc->GetValue().Trim());
342
cpdet_config->settings[index].SetType((CPDetectorType)m_cpdetector_type->GetSelection());
343
if(m_choice_step->GetSelection()==0)
345
cpdet_config->settings[index].SetProg(m_edit_prog->GetValue().Trim());
346
cpdet_config->settings[index].SetArgs(m_edit_args->GetValue().Trim());
350
cpdet_config->settings[index].SetProg(m_edit_prog_descriptor->GetValue().Trim());
351
cpdet_config->settings[index].SetArgs(m_edit_args_descriptor->GetValue().Trim());
352
cpdet_config->settings[index].SetProgMatcher(m_edit_prog_matcher->GetValue().Trim());
353
cpdet_config->settings[index].SetArgsMatcher(m_edit_args_matcher->GetValue().Trim());
355
CPDetectorType type=cpdet_config->settings[index].GetType();
356
if(type==CPDetector_AutoPanoSiftStack || type==CPDetector_AutoPanoSiftMultiRowStack)
358
cpdet_config->settings[index].SetProgStack(m_edit_prog_stack->GetValue().Trim());
359
cpdet_config->settings[index].SetArgsStack(m_edit_args_stack->GetValue().Trim());
361
cpdet_config->settings[index].SetOption(m_check_option->IsChecked());
364
void CPDetectorDialog::OnTypeChange(wxCommandEvent &e)
369
void CPDetectorDialog::ChangeType()
371
int type=m_cpdetector_type->GetSelection();
372
if(type==CPDetector_AutoPano)
374
m_choice_step->SetSelection(0);
375
twoStepAllowed=false;
379
bool isActive=(type==CPDetector_AutoPanoSiftStack || type==CPDetector_AutoPanoSiftMultiRowStack);
380
XRCCTRL(*this,"panel_stack",wxPanel)->Enable(isActive);
383
case CPDetector_AutoPanoSiftMultiRow:
384
case CPDetector_AutoPanoSiftMultiRowStack:
385
m_check_option->SetLabel(_("Try to connect all overlapping images."));
386
m_check_option->Enable(true);
387
m_check_option->Show(true);
388
XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(false);
390
case CPDetector_AutoPanoSiftPreAlign:
391
m_check_option->SetLabel(_("Only work on image pairs without control points."));
392
m_check_option->Enable(true);
393
m_check_option->Show(true);
394
XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(false);
397
XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(true);
398
m_check_option->Enable(false);
399
m_check_option->Show(false);
402
m_check_option->GetParent()->Layout();
407
bool CPDetectorDialog::ShowFileDialog(wxString & prog)
409
wxFileName executable(prog);
410
#ifdef MAC_SELF_CONTAINED_BUNDLE
411
wxString autopanoPath = MacGetPathToUserAppSupportAutoPanoFolder();
413
wxFileDialog dlg(this,_("Select control point detector program"),
414
#ifdef MAC_SELF_CONTAINED_BUNDLE
417
executable.GetPath(),
419
executable.GetFullName(),
421
_("Executables (*.exe,*.vbs,*.cmd, *.bat)|*.exe;*.vbs;*.cmd;*.bat"),
425
wxOPEN, wxDefaultPosition);
426
if (dlg.ShowModal() == wxID_OK)
435
void CPDetectorDialog::OnSelectPath(wxCommandEvent &e)
437
wxString prog=m_edit_prog->GetValue();
438
if (ShowFileDialog(prog))
439
m_edit_prog->SetValue(prog);
442
void CPDetectorDialog::OnSelectPathDescriptor(wxCommandEvent &e)
444
wxString prog=m_edit_prog_descriptor->GetValue();
445
if (ShowFileDialog(prog))
446
m_edit_prog_descriptor->SetValue(prog);
449
void CPDetectorDialog::OnSelectPathMatcher(wxCommandEvent &e)
451
wxString prog=m_edit_prog_matcher->GetValue();
452
if (ShowFileDialog(prog))
453
m_edit_prog_matcher->SetValue(prog);
456
void CPDetectorDialog::OnSelectPathStack(wxCommandEvent &e)
458
wxString prog=m_edit_prog_stack->GetValue();
459
if (ShowFileDialog(prog))
460
m_edit_prog_stack->SetValue(prog);
463
void CPDetectorDialog::OnStepChanging(wxChoicebookEvent &e)
465
if(!twoStepAllowed && e.GetOldSelection()==0)