Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CPDetectorConfig.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
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.
16  *
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.
21  *
22  * You should have received a copy of the GNU General Public
23  * License along with this software. If not, see
24  * <http://www.gnu.org/licenses/>.
25  *
26  */
27 
28 #ifdef _WIN32
29 #include "wx/msw/wrapwin.h"
30 // Mingw define still DIFFERENCE, which conflicts with vigra, so disable it
31 #undef DIFFERENCE
32 #endif
34 #include "hugin_config.h"
35 #include <wx/fileconf.h>
36 
38 wxString default_cpgenerator_desc(wxT("Hugin's Cpfind"));
40 #ifdef _WIN32
41 wxString default_cpgenerator_prog(wxT("cpfind.exe"));
42 #else
43 wxString default_cpgenerator_prog(wxT("cpfind"));
44 #endif
45 
46 wxString default_cpgenerator_args(wxT("-o %o %s"));
47 
48 void CPDetectorConfig::Read(wxConfigBase *config,wxString loadFromFile)
49 {
50  settings.Clear();
51  int count=config->Read(wxT("/AutoPano/AutoPanoCount"),0l);
52  default_generator=config->Read(wxT("/AutoPano/Default"),0l);
53  if(count>0)
54  {
55  for(int i=0;i<count;i++)
56  ReadIndex(config, i);
57  };
58  if(settings.GetCount()==0)
59  {
60  if(loadFromFile.IsEmpty())
61  {
63  }
64  else
65  {
66  ReadFromFile(loadFromFile);
67  };
68  };
69  if(default_generator>=settings.GetCount())
71 };
72 
73 void CPDetectorConfig::ReadFromFile(wxString filename)
74 {
75  if(wxFile::Exists(filename))
76  {
77  wxFileConfig fconfig(wxT("hugin"),wxEmptyString,filename);
78  Read(&fconfig);
79  }
80  else
81  {
83  };
84 };
85 
86 void CPDetectorConfig::ReadIndex(wxConfigBase *config, int i)
87 {
88  wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
89  if(config->HasGroup(path))
90  {
92  if(gen->Read(config,path))
93  {
94  settings.Add(gen);
95  if(i==default_generator)
96  {
97  default_generator=settings.Index(*gen,true);
98  };
99  };
100  };
101 };
102 
103 void CPDetectorConfig::Write(wxConfigBase *config)
104 {
105  int count=settings.Count();
106  config->Write(wxT("/AutoPano/AutoPanoCount"),count);
107  config->Write(wxT("/AutoPano/Default"),(int)default_generator);
108  if(count>0)
109  {
110  for(int i=0;i<count;i++)
111  WriteIndex(config, i);
112  };
113 };
114 
115 void CPDetectorConfig::WriteToFile(wxString filename)
116 {
117  wxFileConfig fconfig(wxT("hugin"),wxEmptyString,filename);
118  Write(&fconfig);
119  fconfig.Flush();
120 };
121 
122 void CPDetectorConfig::WriteIndex(wxConfigBase *config, int i)
123 {
124  wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
125  settings[i].Write(config,path);
126 };
127 
129 {
130  settings.Clear();
131  settings.Add(new CPDetectorSetting());
133 };
134 
135 void CPDetectorConfig::FillControl(wxControlWithItems *control,bool select_default,bool show_default)
136 {
137  control->Clear();
138  for(unsigned int i=0;i<settings.GetCount();i++)
139  {
140  wxString s=settings[i].GetCPDetectorDesc();
141  if(show_default && i==default_generator)
142  s=s+wxT(" (")+_("Default")+wxT(")");
143  control->Append(s);
144  };
145  if(select_default)
146  control->SetSelection(default_generator);
147 };
148 
149 void CPDetectorConfig::Swap(int index)
150 {
151  CPDetectorSetting* setting=settings.Detach(index);
152  settings.Insert(setting,index+1);
153  if(default_generator==index)
154  default_generator=index+1;
155  else
156  if(default_generator==index+1)
157  default_generator=index;
158 };
159 
160 void CPDetectorConfig::SetDefaultGenerator(unsigned int new_default_generator)
161 {
162  if(new_default_generator<GetCount())
163  default_generator=new_default_generator;
164  else
166 };
167 
168 #include <wx/arrimpl.cpp>
169 WX_DEFINE_OBJARRAY(ArraySettings);
170 
172 {
177  args_cleanup=wxEmptyString;
178  prog_matcher=wxEmptyString;
179  args_matcher=wxEmptyString;
180  prog_stack=wxEmptyString;
181  args_stack=wxEmptyString;
182  option=true;
183  CheckValues();
184 };
185 
187 {
189  {
190  if(!prog_matcher.IsEmpty())
191  {
192  prog_matcher=wxEmptyString;
193  args_matcher=wxEmptyString;
194  };
195  };
196 };
197 
199 {
200  return (_type==CPDetector_AutoPanoSiftMultiRow ||
203 };
204 
206 {
208 };
209 
210 bool CPDetectorSetting::Read(wxConfigBase *config, wxString path)
211 {
212  if(!config->Exists(path))
213  {
214  return false;
215  }
216  type=(CPDetectorType)config->Read(path+wxT("/Type"),CPDetector_AutoPanoSift);
217  desc=config->Read(path+wxT("/Description"),default_cpgenerator_desc);
218  prog=config->Read(path+wxT("/Program"),default_cpgenerator_prog);
219  args=config->Read(path+wxT("/Arguments"),default_cpgenerator_args);
220  if(IsCleanupPossible())
221  {
222  args_cleanup=config->Read(path+wxT("/ArgumentsCleanup"),wxEmptyString);
223  }
224  else
225  {
226  args_cleanup=wxEmptyString;
227  };
228  prog_matcher=config->Read(path+wxT("/ProgramMatcher"),wxEmptyString);
229  args_matcher=config->Read(path+wxT("/ArgumentsMatcher"),wxEmptyString);
230  if(ContainsStacks())
231  {
232  prog_stack=config->Read(path+wxT("/ProgramStack"),wxEmptyString);
233  args_stack=config->Read(path+wxT("/ArgumentsStack"),wxEmptyString);
234  }
235  else
236  {
237  prog_stack=wxEmptyString;
238  args_stack=wxEmptyString;
239  };
240  config->Read(path+wxT("/Option"),&option,true);
241  CheckValues();
242  return true;
243 };
244 
245 void CPDetectorSetting::Write(wxConfigBase *config, wxString path)
246 {
247  config->Write(path+wxT("/Type"),int(type));
248  config->Write(path+wxT("/Description"),desc);
249  config->Write(path+wxT("/Program"),prog);
250  config->Write(path+wxT("/Arguments"),args);
251  config->Write(path+wxT("/ProgramMatcher"),prog_matcher);
252  config->Write(path+wxT("/ArgumentsMatcher"),args_matcher);
253  if(IsCleanupPossible())
254  {
255  config->Write(path+wxT("/ArgumentsCleanup"),args_cleanup);
256  };
257  if(ContainsStacks())
258  {
259  config->Write(path+wxT("/ProgramStack"),prog_stack);
260  config->Write(path+wxT("/ArgumentsStack"),args_stack);
261  };
262  config->Write(path+wxT("/Option"),option);
263 };
264 
265 
const bool IsCleanupPossible()
void Read(wxConfigBase *config=wxConfigBase::Get(), wxString loadFromFile=wxEmptyString)
read the settings of different cp generators from config
CPDetectorSetting()
constructor
void Swap(int index)
swaps setting which index and index+1
WX_DEFINE_OBJARRAY(wxArrayTreeListColumnInfo)
CPDetectorType
unsigned int GetCount()
return counts of cp detector settings
unsigned int default_generator
void Write(wxConfigBase *config, wxString path)
writes setting for this generator to config
bool Read(wxConfigBase *config, wxString path)
read setting for this generator from config
ArraySettings settings
array which stores the different autopano settings
void FillControl(wxControlWithItems *control, bool select_default=false, bool show_default=false)
fills a wxControlWithItems with the available generators
class, which stores all settings of one cp detector
void ReadIndex(wxConfigBase *config, int i)
void WriteToFile(wxString filename)
exporth the cp detector settings to external file
wxString default_cpgenerator_args(wxT("-o %o %s"))
arguments for default cp generator, for fall back procedure
void ReadFromFile(wxString filename)
import the cp detector settings from external file
wxString default_cpgenerator_desc(wxT("Hugin's Cpfind"))
description of default cp generator, for fall back procedure
void ResetToDefault()
reset values to default
declaration of CPDetectorSetting and CPDetectorConfig classes, which are for storing and changing set...
wxString default_cpgenerator_prog(wxT("cpfind"))
program name of default cp generator, for fall back procedure
void Write(wxConfigBase *config=wxConfigBase::Get())
writes the settings of different cp generators to config
void SetDefaultGenerator(unsigned int new_default_generator)
sets new default generator, which is used by assistent
void WriteIndex(wxConfigBase *config, int i)
const bool ContainsStacks()
CPDetectorType type