00001
00002
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "icpfind/CPDetectorConfig.h"
00029 #include <config.h>
00030 #include <wx/fileconf.h>
00031
00033 wxString default_cpgenerator_desc(wxT("Hugin's Cpfind"));
00035 #ifdef __WINDOWS__
00036 wxString default_cpgenerator_prog(wxT("cpfind.exe"));
00037 #else
00038 wxString default_cpgenerator_prog(wxT("cpfind"));
00039 #endif
00040
00041 wxString default_cpgenerator_args(wxT("-o %o %s"));
00042
00043 void CPDetectorConfig::Read(wxConfigBase *config,wxString loadFromFile)
00044 {
00045 settings.Clear();
00046 int count=config->Read(wxT("/AutoPano/AutoPanoCount"),0l);
00047 default_generator=config->Read(wxT("/AutoPano/Default"),0l);
00048 if(count>0)
00049 {
00050 for(int i=0;i<count;i++)
00051 ReadIndex(config, i);
00052 };
00053 if(settings.GetCount()==0)
00054 {
00055 if(loadFromFile.IsEmpty())
00056 {
00057 ResetToDefault();
00058 }
00059 else
00060 {
00061 ReadFromFile(loadFromFile);
00062 };
00063 };
00064 if(default_generator>=settings.GetCount())
00065 default_generator=0;
00066 };
00067
00068 void CPDetectorConfig::ReadFromFile(wxString filename)
00069 {
00070 if(wxFile::Exists(filename))
00071 {
00072 wxFileConfig fconfig(wxT("hugin"),wxEmptyString,filename);
00073 Read(&fconfig);
00074 }
00075 else
00076 {
00077 ResetToDefault();
00078 };
00079 };
00080
00081 void CPDetectorConfig::ReadIndex(wxConfigBase *config, int i)
00082 {
00083 wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
00084 if(config->HasGroup(path))
00085 {
00086 CPDetectorSetting* gen=new CPDetectorSetting;
00087 if(gen->Read(config,path))
00088 {
00089 settings.Add(gen);
00090 if(i==default_generator)
00091 {
00092 default_generator=settings.Index(*gen,true);
00093 };
00094 };
00095 };
00096 };
00097
00098 void CPDetectorConfig::Write(wxConfigBase *config)
00099 {
00100 int count=settings.Count();
00101 config->Write(wxT("/AutoPano/AutoPanoCount"),count);
00102 config->Write(wxT("/AutoPano/Default"),(int)default_generator);
00103 if(count>0)
00104 {
00105 for(int i=0;i<count;i++)
00106 WriteIndex(config, i);
00107 };
00108 };
00109
00110 void CPDetectorConfig::WriteToFile(wxString filename)
00111 {
00112 wxFileConfig fconfig(wxT("hugin"),wxEmptyString,filename);
00113 Write(&fconfig);
00114 fconfig.Flush();
00115 };
00116
00117 void CPDetectorConfig::WriteIndex(wxConfigBase *config, int i)
00118 {
00119 wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
00120 settings[i].Write(config,path);
00121 };
00122
00123 void CPDetectorConfig::ResetToDefault()
00124 {
00125 settings.Clear();
00126 settings.Add(new CPDetectorSetting());
00127 default_generator=0;
00128 };
00129
00130 void CPDetectorConfig::FillControl(wxControlWithItems *control,bool select_default,bool show_default)
00131 {
00132 control->Clear();
00133 for(unsigned int i=0;i<settings.GetCount();i++)
00134 {
00135 wxString s=settings[i].GetCPDetectorDesc();
00136 if(show_default && i==default_generator)
00137 s=s+wxT(" (")+_("Default")+wxT(")");
00138 control->Append(s);
00139 };
00140 if(select_default)
00141 control->SetSelection(default_generator);
00142 };
00143
00144 void CPDetectorConfig::Swap(int index)
00145 {
00146 CPDetectorSetting* setting=settings.Detach(index);
00147 settings.Insert(setting,index+1);
00148 if(default_generator==index)
00149 default_generator=index+1;
00150 else
00151 if(default_generator==index+1)
00152 default_generator=index;
00153 };
00154
00155 void CPDetectorConfig::SetDefaultGenerator(unsigned int new_default_generator)
00156 {
00157 if(new_default_generator<GetCount())
00158 default_generator=new_default_generator;
00159 else
00160 default_generator=0;
00161 };
00162
00163 #include <wx/arrimpl.cpp>
00164 WX_DEFINE_OBJARRAY(ArraySettings);
00165
00166 CPDetectorSetting::CPDetectorSetting()
00167 {
00168 type=CPDetector_AutoPanoSift;
00169 desc=default_cpgenerator_desc;
00170 prog=default_cpgenerator_prog;
00171 args=default_cpgenerator_args;
00172 args_cleanup=wxEmptyString;
00173 prog_matcher=wxEmptyString;
00174 args_matcher=wxEmptyString;
00175 prog_stack=wxEmptyString;
00176 args_stack=wxEmptyString;
00177 option=true;
00178 CheckValues();
00179 };
00180
00181 void CPDetectorSetting::CheckValues()
00182 {
00183 if(type==CPDetector_AutoPano)
00184 {
00185 if(!prog_matcher.IsEmpty())
00186 {
00187 prog_matcher=wxEmptyString;
00188 args_matcher=wxEmptyString;
00189 };
00190 };
00191 };
00192
00193 const bool CPDetectorSetting::IsCleanupPossible(CPDetectorType _type)
00194 {
00195 return (_type==CPDetector_AutoPanoSiftMultiRow ||
00196 _type==CPDetector_AutoPanoSiftMultiRowStack ||
00197 _type==CPDetector_AutoPanoSiftPreAlign);
00198 };
00199
00200 const bool CPDetectorSetting::ContainsStacks(CPDetectorType _type)
00201 {
00202 return (_type==CPDetector_AutoPanoSiftStack || _type==CPDetector_AutoPanoSiftMultiRowStack);
00203 };
00204
00205 bool CPDetectorSetting::Read(wxConfigBase *config, wxString path)
00206 {
00207 if(!config->Exists(path))
00208 {
00209 return false;
00210 }
00211 type=(CPDetectorType)config->Read(path+wxT("/Type"),CPDetector_AutoPanoSift);
00212 desc=config->Read(path+wxT("/Description"),default_cpgenerator_desc);
00213 prog=config->Read(path+wxT("/Program"),default_cpgenerator_prog);
00214 args=config->Read(path+wxT("/Arguments"),default_cpgenerator_args);
00215 if(IsCleanupPossible())
00216 {
00217 args_cleanup=config->Read(path+wxT("/ArgumentsCleanup"),wxEmptyString);
00218 }
00219 else
00220 {
00221 args_cleanup=wxEmptyString;
00222 };
00223 prog_matcher=config->Read(path+wxT("/ProgramMatcher"),wxEmptyString);
00224 args_matcher=config->Read(path+wxT("/ArgumentsMatcher"),wxEmptyString);
00225 if(ContainsStacks())
00226 {
00227 prog_stack=config->Read(path+wxT("/ProgramStack"),wxEmptyString);
00228 args_stack=config->Read(path+wxT("/ArgumentsStack"),wxEmptyString);
00229 }
00230 else
00231 {
00232 prog_stack=wxEmptyString;
00233 args_stack=wxEmptyString;
00234 };
00235 config->Read(path+wxT("/Option"),&option,true);
00236 CheckValues();
00237 return true;
00238 };
00239
00240 void CPDetectorSetting::Write(wxConfigBase *config, wxString path)
00241 {
00242 config->Write(path+wxT("/Type"),int(type));
00243 config->Write(path+wxT("/Description"),desc);
00244 config->Write(path+wxT("/Program"),prog);
00245 config->Write(path+wxT("/Arguments"),args);
00246 config->Write(path+wxT("/ProgramMatcher"),prog_matcher);
00247 config->Write(path+wxT("/ArgumentsMatcher"),args_matcher);
00248 if(IsCleanupPossible())
00249 {
00250 config->Write(path+wxT("/ArgumentsCleanup"),args_cleanup);
00251 };
00252 if(ContainsStacks())
00253 {
00254 config->Write(path+wxT("/ProgramStack"),prog_stack);
00255 config->Write(path+wxT("/ArgumentsStack"),args_stack);
00256 };
00257 config->Write(path+wxT("/Option"),option);
00258 };
00259
00260