~ubuntu-branches/ubuntu/trusty/hugin/trusty-proposed

« back to all changes in this revision

Viewing changes to src/hugin1/icpfind/CPDetectorConfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2011-01-06 14:28:24 UTC
  • mfrom: (1.1.9 upstream) (0.1.21 experimental)
  • Revision ID: james.westby@ubuntu.com-20110106142824-zn9lxylg5z44dynn
* Drop Cyril Brulebois from Uploaders. Thank you very much for your work.
* Bump package version. (rc3 was re-released as 2010.4.0).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- c-basic-offset: 4 -*-
 
2
 
 
3
/** @file CPDetectorConfig.cpp
 
4
 *
 
5
 *  @brief implementation of CPDetectorSetting and CPDetectorConfig classes, 
 
6
 *         which are for storing and changing settings of different CP detectors
 
7
 *
 
8
 *  @author Thomas Modes
 
9
 *
 
10
 */
 
11
 
 
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, write to the Free Software
 
24
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
25
 *
 
26
 */
 
27
 
 
28
#include "icpfind/CPDetectorConfig.h"
 
29
#include <config.h>
 
30
#include <wx/fileconf.h>
 
31
 
 
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 */
 
35
#ifdef __WINDOWS__
 
36
wxString default_cpgenerator_prog(wxT("cpfind.exe"));
 
37
#else
 
38
wxString default_cpgenerator_prog(wxT("cpfind"));
 
39
#endif
 
40
/** arguments for default cp generator, for fall back procedure */
 
41
wxString default_cpgenerator_args(wxT("-o %o %s"));
 
42
 
 
43
void CPDetectorConfig::Read(wxConfigBase *config,wxString loadFromFile)
 
44
{
 
45
    settings.Clear();
 
46
    int count=config->Read(wxT("/AutoPano/AutoPanoCount"),0l);
 
47
    default_generator=config->Read(wxT("/AutoPano/Default"),0l);
 
48
    if(count>0)
 
49
    {
 
50
        for(int i=0;i<count;i++)
 
51
            ReadIndex(config, i);
 
52
    };
 
53
    if(settings.GetCount()==0)
 
54
    {
 
55
        if(loadFromFile.IsEmpty())
 
56
        {
 
57
            ResetToDefault();
 
58
        }
 
59
        else
 
60
        {
 
61
            ReadFromFile(loadFromFile);
 
62
        };
 
63
    };
 
64
    if(default_generator>=settings.GetCount())
 
65
        default_generator=0;
 
66
};
 
67
 
 
68
void CPDetectorConfig::ReadFromFile(wxString filename)
 
69
{
 
70
    if(wxFile::Exists(filename))
 
71
    {
 
72
        wxFileConfig fconfig(wxT("hugin"),wxEmptyString,filename);
 
73
        Read(&fconfig);
 
74
    }
 
75
    else
 
76
    {
 
77
        ResetToDefault();
 
78
    };
 
79
};
 
80
 
 
81
void CPDetectorConfig::ReadIndex(wxConfigBase *config, int i)
 
82
{
 
83
    wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
 
84
    if(config->HasGroup(path))
 
85
    {
 
86
        CPDetectorSetting* gen=new CPDetectorSetting;
 
87
        if(gen->Read(config,path))
 
88
        {
 
89
            settings.Add(gen);
 
90
            if(i==default_generator)
 
91
            {
 
92
                default_generator=settings.Index(*gen,true);
 
93
            };
 
94
        };
 
95
    };
 
96
};
 
97
 
 
98
void CPDetectorConfig::Write(wxConfigBase *config)
 
99
{
 
100
    int count=settings.Count();
 
101
    config->Write(wxT("/AutoPano/AutoPanoCount"),count);
 
102
    config->Write(wxT("/AutoPano/Default"),(int)default_generator);
 
103
    if(count>0)
 
104
    {
 
105
        for(int i=0;i<count;i++)
 
106
            WriteIndex(config, i);
 
107
    };
 
108
};
 
109
 
 
110
void CPDetectorConfig::WriteToFile(wxString filename)
 
111
{
 
112
    wxFileConfig fconfig(wxT("hugin"),wxEmptyString,filename);
 
113
    Write(&fconfig);
 
114
    fconfig.Flush();
 
115
};
 
116
 
 
117
void CPDetectorConfig::WriteIndex(wxConfigBase *config, int i)
 
118
{
 
119
    wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
 
120
    settings[i].Write(config,path);
 
121
};
 
122
 
 
123
void CPDetectorConfig::ResetToDefault()
 
124
{
 
125
    settings.Clear();
 
126
    settings.Add(new CPDetectorSetting());
 
127
    default_generator=0;
 
128
};
 
129
 
 
130
void CPDetectorConfig::FillControl(wxControlWithItems *control,bool select_default,bool show_default)
 
131
{
 
132
    control->Clear();
 
133
    for(unsigned int i=0;i<settings.GetCount();i++)
 
134
    {
 
135
        wxString s=settings[i].GetCPDetectorDesc();
 
136
        if(show_default && i==default_generator)
 
137
            s=s+wxT(" (")+_("Default")+wxT(")");
 
138
        control->Append(s);
 
139
    };
 
140
    if(select_default)
 
141
        control->SetSelection(default_generator);
 
142
};
 
143
 
 
144
void CPDetectorConfig::Swap(int index)
 
145
{
 
146
    CPDetectorSetting* setting=settings.Detach(index);
 
147
    settings.Insert(setting,index+1);
 
148
    if(default_generator==index)
 
149
        default_generator=index+1;
 
150
    else 
 
151
        if(default_generator==index+1)
 
152
            default_generator=index;
 
153
};
 
154
 
 
155
void CPDetectorConfig::SetDefaultGenerator(unsigned int new_default_generator)
 
156
{
 
157
    if(new_default_generator<GetCount())
 
158
        default_generator=new_default_generator;
 
159
    else
 
160
        default_generator=0;
 
161
};
 
162
 
 
163
#include <wx/arrimpl.cpp> 
 
164
WX_DEFINE_OBJARRAY(ArraySettings);
 
165
 
 
166
CPDetectorSetting::CPDetectorSetting()
 
167
{
 
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;
 
177
    option=true;
 
178
    CheckValues();
 
179
};
 
180
 
 
181
void CPDetectorSetting::CheckValues()
 
182
{
 
183
    if(type==CPDetector_AutoPano)
 
184
    {
 
185
        if(!prog_matcher.IsEmpty())
 
186
        {
 
187
            prog_matcher=wxEmptyString;
 
188
            args_matcher=wxEmptyString;
 
189
        };
 
190
    };
 
191
};
 
192
 
 
193
const bool CPDetectorSetting::IsCleanupPossible(CPDetectorType _type)
 
194
{
 
195
    return (_type==CPDetector_AutoPanoSiftMultiRow || 
 
196
            _type==CPDetector_AutoPanoSiftMultiRowStack ||
 
197
            _type==CPDetector_AutoPanoSiftPreAlign);
 
198
};
 
199
 
 
200
const bool CPDetectorSetting::ContainsStacks(CPDetectorType _type)
 
201
{
 
202
    return (_type==CPDetector_AutoPanoSiftStack || _type==CPDetector_AutoPanoSiftMultiRowStack);
 
203
};
 
204
 
 
205
bool CPDetectorSetting::Read(wxConfigBase *config, wxString path)
 
206
{
 
207
    if(!config->Exists(path))
 
208
    {
 
209
        return false;
 
210
    }
 
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())
 
216
    {
 
217
        args_cleanup=config->Read(path+wxT("/ArgumentsCleanup"),wxEmptyString);
 
218
    }
 
219
    else
 
220
    {
 
221
        args_cleanup=wxEmptyString;
 
222
    };
 
223
    prog_matcher=config->Read(path+wxT("/ProgramMatcher"),wxEmptyString);
 
224
    args_matcher=config->Read(path+wxT("/ArgumentsMatcher"),wxEmptyString);
 
225
    if(ContainsStacks())
 
226
    {
 
227
        prog_stack=config->Read(path+wxT("/ProgramStack"),wxEmptyString);
 
228
        args_stack=config->Read(path+wxT("/ArgumentsStack"),wxEmptyString);
 
229
    }
 
230
    else
 
231
    {
 
232
        prog_stack=wxEmptyString;
 
233
        args_stack=wxEmptyString;
 
234
    };
 
235
    config->Read(path+wxT("/Option"),&option,true);
 
236
    CheckValues();
 
237
    return true;
 
238
};
 
239
 
 
240
void CPDetectorSetting::Write(wxConfigBase *config, wxString path)
 
241
{
 
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())
 
249
    {
 
250
        config->Write(path+wxT("/ArgumentsCleanup"),args_cleanup);
 
251
    };
 
252
    if(ContainsStacks())
 
253
    {
 
254
        config->Write(path+wxT("/ProgramStack"),prog_stack);
 
255
        config->Write(path+wxT("/ArgumentsStack"),args_stack);
 
256
    };
 
257
    config->Write(path+wxT("/Option"),option);
 
258
};
 
259
 
 
260