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

« back to all changes in this revision

Viewing changes to src/hugin1/hugin/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, CPDetectorConfig and CPDetectorDialog classes, 
6
 
 *         which are for storing and changing settings of different CP detectors
7
 
 *
8
 
 *  @author Thomas Modes
9
 
 *
10
 
 *  $Id$
11
 
 *
12
 
 */
13
 
 
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.
18
 
 *
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.
23
 
 *
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
27
 
 *
28
 
 */
29
 
 
30
 
#include "hugin/CPDetectorConfig.h"
31
 
#include <config.h>
32
 
#include "base_wx/huginConfig.h"
33
 
#include "hugin/config_defaults.h"
34
 
#include <hugin/CPDetectorConfig_default.h>
35
 
#include "hugin/huginApp.h"
36
 
 
37
 
#if defined MAC_SELF_CONTAINED_BUNDLE 
38
 
  #include "base_wx/platform.h"
39
 
  #include <wx/dir.h>
40
 
  #include <CoreFoundation/CFBundle.h>
41
 
#endif
42
 
 
43
 
 
44
 
void CPDetectorConfig::Read(wxConfigBase *config)
45
 
{
46
 
    settings.Clear();
47
 
    int count=config->Read(wxT("/AutoPano/AutoPanoCount"),0l);
48
 
    default_generator=config->Read(wxT("/AutoPano/Default"),0l);
49
 
    if(count>0)
50
 
    {
51
 
        for(int i=0;i<count;i++)
52
 
            ReadIndex(config, i);
53
 
    };
54
 
    if(settings.GetCount()==0)
55
 
        ResetToDefault();
56
 
    if(default_generator>=settings.GetCount())
57
 
        default_generator=0;
58
 
};
59
 
 
60
 
void CPDetectorConfig::ReadIndex(wxConfigBase *config, int i)
61
 
{
62
 
    wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
63
 
    if(config->HasGroup(path))
64
 
    {
65
 
        CPDetectorSetting* gen=new CPDetectorSetting;
66
 
        gen->Read(config,path);
67
 
        settings.Add(gen);
68
 
        if(i==default_generator)
69
 
            default_generator=settings.Index(*gen,true);
70
 
    };
71
 
};
72
 
 
73
 
void CPDetectorConfig::Write(wxConfigBase *config)
74
 
{
75
 
    int count=settings.Count();
76
 
    config->Write(wxT("/AutoPano/AutoPanoCount"),count);
77
 
    config->Write(wxT("/AutoPano/Default"),(int)default_generator);
78
 
    if(count>0)
79
 
    {
80
 
        for(int i=0;i<count;i++)
81
 
            WriteIndex(config, i);
82
 
    };
83
 
};
84
 
 
85
 
void CPDetectorConfig::WriteIndex(wxConfigBase *config, int i)
86
 
{
87
 
    wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i);
88
 
    settings[i].Write(config,path);
89
 
};
90
 
 
91
 
void CPDetectorConfig::ResetToDefault()
92
 
{
93
 
    settings.Clear();
94
 
    int maxIndex=sizeof(default_cpdetectors)/sizeof(cpdetector_default)-1;
95
 
    for(int i=0;i<=maxIndex;i++)
96
 
        settings.Add(new CPDetectorSetting(i));
97
 
    default_generator=0;
98
 
};
99
 
 
100
 
void CPDetectorConfig::FillControl(wxControlWithItems *control,bool select_default,bool show_default)
101
 
{
102
 
    control->Clear();
103
 
    for(unsigned int i=0;i<settings.GetCount();i++)
104
 
    {
105
 
        wxString s=settings[i].GetCPDetectorDesc();
106
 
        if(show_default && i==default_generator)
107
 
            s=s+wxT(" (")+_("Default")+wxT(")");
108
 
        control->Append(s);
109
 
    };
110
 
    if(select_default)
111
 
        control->SetSelection(default_generator);
112
 
};
113
 
 
114
 
void CPDetectorConfig::Swap(int index)
115
 
{
116
 
    CPDetectorSetting* setting=settings.Detach(index);
117
 
    settings.Insert(setting,index+1);
118
 
    if(default_generator==index)
119
 
        default_generator=index+1;
120
 
    else 
121
 
        if(default_generator==index+1)
122
 
            default_generator=index;
123
 
};
124
 
 
125
 
void CPDetectorConfig::SetDefaultGenerator(unsigned int new_default_generator)
126
 
{
127
 
    if(new_default_generator<GetCount())
128
 
        default_generator=new_default_generator;
129
 
    else
130
 
        default_generator=0;
131
 
};
132
 
 
133
 
#include <wx/arrimpl.cpp> 
134
 
WX_DEFINE_OBJARRAY(ArraySettings);
135
 
 
136
 
CPDetectorSetting::CPDetectorSetting(int new_type)
137
 
{
138
 
    if(new_type>=0)
139
 
    {
140
 
        int maxIndex=sizeof(default_cpdetectors)/sizeof(cpdetector_default)-1;
141
 
        if (new_type<=maxIndex)
142
 
        {
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)
150
 
            {
151
 
                prog_stack=default_cpdetectors[new_type].prog_stack;
152
 
                args_stack=default_cpdetectors[new_type].args_stack;
153
 
            }
154
 
            else
155
 
            {
156
 
                prog_stack=wxEmptyString;
157
 
                args_stack=wxEmptyString;
158
 
            };
159
 
            option=default_cpdetectors[new_type].option;
160
 
        };
161
 
    }
162
 
    else
163
 
    {
164
 
        type=CPDetector_AutoPanoSift;
165
 
        desc=wxEmptyString;
166
 
        prog=wxEmptyString;
167
 
        args=wxEmptyString;
168
 
        prog_matcher=wxEmptyString;
169
 
        args_matcher=wxEmptyString;
170
 
        prog_stack=wxEmptyString;
171
 
        args_stack=wxEmptyString;
172
 
        option=true;
173
 
    };
174
 
    CheckValues();
175
 
};
176
 
 
177
 
void CPDetectorSetting::CheckValues()
178
 
{
179
 
    if(type==CPDetector_AutoPano)
180
 
    {
181
 
        if(!prog_matcher.IsEmpty())
182
 
        {
183
 
            prog_matcher=wxEmptyString;
184
 
            args_matcher=wxEmptyString;
185
 
        };
186
 
    };
187
 
};
188
 
 
189
 
void CPDetectorSetting::Read(wxConfigBase *config, wxString path)
190
 
{
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)
198
 
    {
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);
201
 
    }
202
 
    else
203
 
    {
204
 
        prog_stack=wxEmptyString;
205
 
        args_stack=wxEmptyString;
206
 
    };
207
 
    option=config->Read(path+wxT("/Option"),default_cpdetectors[0].option);
208
 
    CheckValues();
209
 
};
210
 
 
211
 
void CPDetectorSetting::Write(wxConfigBase *config, wxString path)
212
 
{
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)
220
 
    {
221
 
        config->Write(path+wxT("/ProgramStack"),prog_stack);
222
 
        config->Write(path+wxT("/ArgumentsStack"),args_stack);
223
 
    };
224
 
    config->Write(path+wxT("/Option"),option);
225
 
};
226
 
 
227
 
// dialog for showing settings of one autopano setting
228
 
 
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)
237
 
END_EVENT_TABLE()
238
 
 
239
 
CPDetectorDialog::CPDetectorDialog(wxWindow* parent)
240
 
{
241
 
    wxXmlResource::Get()->LoadDialog(this, parent, wxT("cpdetector_dialog"));
242
 
#ifdef __WXMSW__
243
 
    wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/icon.ico"),wxBITMAP_TYPE_ICO);
244
 
#else
245
 
    wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/icon.png"),wxBITMAP_TYPE_PNG);
246
 
#endif
247
 
    SetIcon(myIcon);
248
 
 
249
 
    //restore frame position and size
250
 
    RestoreFramePosition(this,wxT("CPDetectorDialog"));
251
 
 
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);
265
 
    ChangeType();
266
 
};
267
 
 
268
 
CPDetectorDialog::~CPDetectorDialog()
269
 
{
270
 
    StoreFramePosition(this,wxT("CPDetectorDialog"));
271
 
};
272
 
 
273
 
void CPDetectorDialog::OnOk(wxCommandEvent & e)
274
 
{
275
 
#ifdef __WXMAC__
276
 
    if(m_cpdetector_type->GetSelection()==0)
277
 
    {
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);
281
 
    };
282
 
#endif
283
 
    bool valid=true;
284
 
    valid=valid && (m_edit_desc->GetValue().Trim().Len()>0);
285
 
    if(m_choice_step->GetSelection()==0)
286
 
    {
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);
290
 
    }
291
 
    else
292
 
    {
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);
298
 
    };
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);
303
 
    if(valid)        
304
 
        this->EndModal(wxOK);
305
 
    else
306
 
        wxMessageBox(_("At least one input field is empty.\nPlease check your inputs."),
307
 
            _("Warning"),wxOK | wxICON_ERROR,this);
308
 
};
309
 
 
310
 
void CPDetectorDialog::UpdateFields(CPDetectorConfig* cpdet_config,int index)
311
 
{
312
 
    m_edit_desc->SetValue(cpdet_config->settings[index].GetCPDetectorDesc());
313
 
    //program names and arguments
314
 
    if(cpdet_config->settings[index].IsTwoStepDetector())
315
 
    {
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());
321
 
    }
322
 
    else
323
 
    {
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());
327
 
    };
328
 
    int type=cpdet_config->settings[index].GetType();
329
 
    if(type==CPDetector_AutoPanoSiftStack || type==CPDetector_AutoPanoSiftMultiRowStack)
330
 
    {
331
 
        m_edit_prog_stack->SetValue(cpdet_config->settings[index].GetProgStack());
332
 
        m_edit_args_stack->SetValue(cpdet_config->settings[index].GetArgsStack());
333
 
    };
334
 
    m_cpdetector_type->SetSelection(type);
335
 
    m_check_option->SetValue(cpdet_config->settings[index].GetOption());
336
 
    ChangeType();
337
 
};
338
 
 
339
 
void CPDetectorDialog::UpdateSettings(CPDetectorConfig* cpdet_config,int index)
340
 
{
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)
344
 
    {
345
 
        cpdet_config->settings[index].SetProg(m_edit_prog->GetValue().Trim());
346
 
        cpdet_config->settings[index].SetArgs(m_edit_args->GetValue().Trim());
347
 
    }
348
 
    else
349
 
    {
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());
354
 
    };
355
 
    CPDetectorType type=cpdet_config->settings[index].GetType();
356
 
    if(type==CPDetector_AutoPanoSiftStack || type==CPDetector_AutoPanoSiftMultiRowStack)
357
 
    {
358
 
        cpdet_config->settings[index].SetProgStack(m_edit_prog_stack->GetValue().Trim());
359
 
        cpdet_config->settings[index].SetArgsStack(m_edit_args_stack->GetValue().Trim());
360
 
    };
361
 
    cpdet_config->settings[index].SetOption(m_check_option->IsChecked());
362
 
};
363
 
 
364
 
void CPDetectorDialog::OnTypeChange(wxCommandEvent &e)
365
 
{
366
 
    ChangeType();
367
 
};
368
 
 
369
 
void CPDetectorDialog::ChangeType()
370
 
{
371
 
    int type=m_cpdetector_type->GetSelection();
372
 
    if(type==CPDetector_AutoPano)
373
 
    {
374
 
        m_choice_step->SetSelection(0);
375
 
        twoStepAllowed=false;
376
 
    }
377
 
    else
378
 
        twoStepAllowed=true;
379
 
    bool isActive=(type==CPDetector_AutoPanoSiftStack || type==CPDetector_AutoPanoSiftMultiRowStack);
380
 
    XRCCTRL(*this,"panel_stack",wxPanel)->Enable(isActive);
381
 
    switch(type)
382
 
    {
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);
389
 
            break;
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);
395
 
            break;
396
 
        default:
397
 
            XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(true);
398
 
            m_check_option->Enable(false);
399
 
            m_check_option->Show(false);
400
 
            break;
401
 
    };
402
 
    m_check_option->GetParent()->Layout();
403
 
    Layout();
404
 
};
405
 
 
406
 
 
407
 
bool CPDetectorDialog::ShowFileDialog(wxString & prog)
408
 
{
409
 
    wxFileName executable(prog);
410
 
#ifdef MAC_SELF_CONTAINED_BUNDLE
411
 
    wxString autopanoPath = MacGetPathToUserAppSupportAutoPanoFolder();
412
 
#endif
413
 
    wxFileDialog dlg(this,_("Select control point detector program"), 
414
 
#ifdef MAC_SELF_CONTAINED_BUNDLE
415
 
            autopanoPath,
416
 
#else
417
 
            executable.GetPath(),
418
 
#endif
419
 
            executable.GetFullName(),
420
 
#ifdef __WXMSW__
421
 
            _("Executables (*.exe,*.vbs,*.cmd, *.bat)|*.exe;*.vbs;*.cmd;*.bat"),
422
 
#else
423
 
            wxT(""),
424
 
#endif
425
 
            wxOPEN, wxDefaultPosition);
426
 
    if (dlg.ShowModal() == wxID_OK)
427
 
    {
428
 
        prog=dlg.GetPath();
429
 
        return true;
430
 
    }
431
 
    else
432
 
        return false;
433
 
};
434
 
 
435
 
void CPDetectorDialog::OnSelectPath(wxCommandEvent &e)
436
 
{
437
 
    wxString prog=m_edit_prog->GetValue();
438
 
    if (ShowFileDialog(prog))
439
 
        m_edit_prog->SetValue(prog);
440
 
};
441
 
 
442
 
void CPDetectorDialog::OnSelectPathDescriptor(wxCommandEvent &e)
443
 
{
444
 
    wxString prog=m_edit_prog_descriptor->GetValue();
445
 
    if (ShowFileDialog(prog))
446
 
        m_edit_prog_descriptor->SetValue(prog);
447
 
};
448
 
 
449
 
void CPDetectorDialog::OnSelectPathMatcher(wxCommandEvent &e)
450
 
{
451
 
    wxString prog=m_edit_prog_matcher->GetValue();
452
 
    if (ShowFileDialog(prog))
453
 
        m_edit_prog_matcher->SetValue(prog);
454
 
};
455
 
 
456
 
void CPDetectorDialog::OnSelectPathStack(wxCommandEvent &e)
457
 
{
458
 
    wxString prog=m_edit_prog_stack->GetValue();
459
 
    if (ShowFileDialog(prog))
460
 
        m_edit_prog_stack->SetValue(prog);
461
 
};
462
 
 
463
 
void CPDetectorDialog::OnStepChanging(wxChoicebookEvent &e)
464
 
{
465
 
    if(!twoStepAllowed && e.GetOldSelection()==0)
466
 
    {
467
 
        wxBell();
468
 
        e.Veto();
469
 
    };
470
 
};