1
// -*- c-basic-offset: 4 -*-
3
/** @file CPDetectorConfig.cpp
5
* @brief implementation of CPDetectorSetting and CPDetectorConfig classes,
6
* which are for storing and changing settings of different CP detectors
12
/* This is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public
14
* License as published by the Free Software Foundation; either
15
* version 2 of the License, or (at your option) any later version.
17
* This software is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
* Lesser General Public License for more details.
22
* You should have received a copy of the GNU General Public
23
* License along with this software; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
#include "icpfind/CPDetectorConfig.h"
30
#include <wx/fileconf.h>
32
/** description of default cp generator, for fall back procedure */
33
wxString default_cpgenerator_desc(wxT("Hugins Cpfind"));
34
/** program name of default cp generator, for fall back procedure */
36
wxString default_cpgenerator_prog(wxT("cpfind.exe"));
38
wxString default_cpgenerator_prog(wxT("cpfind"));
40
/** arguments for default cp generator, for fall back procedure */
41
wxString default_cpgenerator_args(wxT("-o %o %s"));
43
void CPDetectorConfig::Read(wxConfigBase *config,wxString loadFromFile)
46
int count=config->Read(wxT("/AutoPano/AutoPanoCount"),0l);
47
default_generator=config->Read(wxT("/AutoPano/Default"),0l);
50
for(int i=0;i<count;i++)
53
if(settings.GetCount()==0)
55
if(loadFromFile.IsEmpty())
61
ReadFromFile(loadFromFile);
64
if(default_generator>=settings.GetCount())
68
void CPDetectorConfig::ReadFromFile(wxString filename)
70
if(wxFile::Exists(filename))
72
wxFileConfig fconfig(wxT("hugin"),wxEmptyString,filename);
81
void CPDetectorConfig::ReadIndex(wxConfigBase *config, int i)
83
wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
84
if(config->HasGroup(path))
86
CPDetectorSetting* gen=new CPDetectorSetting;
87
if(gen->Read(config,path))
90
if(i==default_generator)
92
default_generator=settings.Index(*gen,true);
98
void CPDetectorConfig::Write(wxConfigBase *config)
100
int count=settings.Count();
101
config->Write(wxT("/AutoPano/AutoPanoCount"),count);
102
config->Write(wxT("/AutoPano/Default"),(int)default_generator);
105
for(int i=0;i<count;i++)
106
WriteIndex(config, i);
110
void CPDetectorConfig::WriteToFile(wxString filename)
112
wxFileConfig fconfig(wxT("hugin"),wxEmptyString,filename);
117
void CPDetectorConfig::WriteIndex(wxConfigBase *config, int i)
119
wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
120
settings[i].Write(config,path);
123
void CPDetectorConfig::ResetToDefault()
126
settings.Add(new CPDetectorSetting());
130
void CPDetectorConfig::FillControl(wxControlWithItems *control,bool select_default,bool show_default)
133
for(unsigned int i=0;i<settings.GetCount();i++)
135
wxString s=settings[i].GetCPDetectorDesc();
136
if(show_default && i==default_generator)
137
s=s+wxT(" (")+_("Default")+wxT(")");
141
control->SetSelection(default_generator);
144
void CPDetectorConfig::Swap(int index)
146
CPDetectorSetting* setting=settings.Detach(index);
147
settings.Insert(setting,index+1);
148
if(default_generator==index)
149
default_generator=index+1;
151
if(default_generator==index+1)
152
default_generator=index;
155
void CPDetectorConfig::SetDefaultGenerator(unsigned int new_default_generator)
157
if(new_default_generator<GetCount())
158
default_generator=new_default_generator;
163
#include <wx/arrimpl.cpp>
164
WX_DEFINE_OBJARRAY(ArraySettings);
166
CPDetectorSetting::CPDetectorSetting()
168
type=CPDetector_AutoPanoSift;
169
desc=default_cpgenerator_desc;
170
prog=default_cpgenerator_prog;
171
args=default_cpgenerator_args;
172
args_cleanup=wxEmptyString;
173
prog_matcher=wxEmptyString;
174
args_matcher=wxEmptyString;
175
prog_stack=wxEmptyString;
176
args_stack=wxEmptyString;
181
void CPDetectorSetting::CheckValues()
183
if(type==CPDetector_AutoPano)
185
if(!prog_matcher.IsEmpty())
187
prog_matcher=wxEmptyString;
188
args_matcher=wxEmptyString;
193
const bool CPDetectorSetting::IsCleanupPossible(CPDetectorType _type)
195
return (_type==CPDetector_AutoPanoSiftMultiRow ||
196
_type==CPDetector_AutoPanoSiftMultiRowStack ||
197
_type==CPDetector_AutoPanoSiftPreAlign);
200
const bool CPDetectorSetting::ContainsStacks(CPDetectorType _type)
202
return (_type==CPDetector_AutoPanoSiftStack || _type==CPDetector_AutoPanoSiftMultiRowStack);
205
bool CPDetectorSetting::Read(wxConfigBase *config, wxString path)
207
if(!config->Exists(path))
211
type=(CPDetectorType)config->Read(path+wxT("/Type"),CPDetector_AutoPanoSift);
212
desc=config->Read(path+wxT("/Description"),default_cpgenerator_desc);
213
prog=config->Read(path+wxT("/Program"),default_cpgenerator_prog);
214
args=config->Read(path+wxT("/Arguments"),default_cpgenerator_args);
215
if(IsCleanupPossible())
217
args_cleanup=config->Read(path+wxT("/ArgumentsCleanup"),wxEmptyString);
221
args_cleanup=wxEmptyString;
223
prog_matcher=config->Read(path+wxT("/ProgramMatcher"),wxEmptyString);
224
args_matcher=config->Read(path+wxT("/ArgumentsMatcher"),wxEmptyString);
227
prog_stack=config->Read(path+wxT("/ProgramStack"),wxEmptyString);
228
args_stack=config->Read(path+wxT("/ArgumentsStack"),wxEmptyString);
232
prog_stack=wxEmptyString;
233
args_stack=wxEmptyString;
235
config->Read(path+wxT("/Option"),&option,true);
240
void CPDetectorSetting::Write(wxConfigBase *config, wxString path)
242
config->Write(path+wxT("/Type"),int(type));
243
config->Write(path+wxT("/Description"),desc);
244
config->Write(path+wxT("/Program"),prog);
245
config->Write(path+wxT("/Arguments"),args);
246
config->Write(path+wxT("/ProgramMatcher"),prog_matcher);
247
config->Write(path+wxT("/ArgumentsMatcher"),args_matcher);
248
if(IsCleanupPossible())
250
config->Write(path+wxT("/ArgumentsCleanup"),args_cleanup);
254
config->Write(path+wxT("/ProgramStack"),prog_stack);
255
config->Write(path+wxT("/ArgumentsStack"),args_stack);
257
config->Write(path+wxT("/Option"),option);