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

« back to all changes in this revision

Viewing changes to src/hugin1/ptbatcher/Batch.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:
31
31
 EVT_END_PROCESS(-1, Batch::OnProcessTerminate)
32
32
END_EVENT_TABLE()
33
33
 
 
34
#if _WINDOWS && defined Hugin_shared
 
35
DEFINE_LOCAL_EVENT_TYPE(EVT_BATCH_FAILED)
 
36
#else
 
37
DEFINE_EVENT_TYPE(EVT_BATCH_FAILED)
 
38
#endif
 
39
 
34
40
Batch::Batch(wxFrame* parent, wxString path, bool bgui) : wxFrame(parent,wxID_ANY,_T("Batch")){
35
41
        //default flag settings
36
42
        parallel = false;
49
55
    //SetAppName(wxT("hugin"));
50
56
 
51
57
    // setup the environment for the different operating systems
 
58
    wxConfigBase* config=wxConfigBase::Get();
52
59
#if defined __WXMSW__
53
60
    wxString huginExeDir = getExePath(path);
54
61
        
55
62
        wxString huginRoot;
56
63
    wxFileName::SplitPath(huginExeDir, &huginRoot, NULL, NULL);
57
64
        
58
 
        progs = getPTProgramsConfig(huginExeDir, wxConfigBase::Get());
 
65
        progs = getPTProgramsConfig(huginExeDir, config);
 
66
    progsAss = getAssistantProgramsConfig(huginExeDir, config);
59
67
#else
60
68
    // add the locale directory specified during configure
61
 
    progs = getPTProgramsConfig(wxT(""), wxConfigBase::Get());
 
69
    progs = getPTProgramsConfig(wxT(""), config);
 
70
    progsAss = getAssistantProgramsConfig(wxT(""), config);
62
71
#endif
63
72
 
64
73
}
69
78
        m_projList.Add(newApp);
70
79
}
71
80
 
72
 
void Batch::AddProjectToBatch(wxString projectFile, wxString outputFile)
 
81
void Batch::AddProjectToBatch(wxString projectFile, wxString outputFile,Project::Target target)
73
82
{
74
83
        wxFileName projectName(projectFile);
75
84
        wxFileName outName(outputFile);
76
85
        projectName.Normalize();
77
86
        outName.Normalize();
78
87
        
79
 
        if(outputFile.Cmp(_T(""))!=0)
 
88
    if(outputFile.Cmp(_T(""))!=0 || target==Project::DETECTING)
80
89
        {
81
 
                Project *proj = new Project(projectName.GetFullPath(),outName.GetFullPath());
 
90
                Project *proj = new Project(projectName.GetFullPath(),outName.GetFullPath(),target);
82
91
                m_projList.Add(proj);
83
92
                /*if(gui)
84
93
                        ((wxFrame*)GetParent())->SetStatusText(_T("Added project ")+projectFile+_T(" with output ")+outputFile);
129
138
                while((projectName = textStream.ReadLine()).Cmp(wxT(""))!=0)
130
139
                {
131
140
                        //we add project to internal list
132
 
                        AddProjectToBatch(projectName,textStream.ReadLine());
 
141
            wxString line=textStream.ReadLine();
 
142
            if(line.IsEmpty())
 
143
            {
 
144
                AddProjectToBatch(projectName,wxT(""),Project::DETECTING);
 
145
            }
 
146
            else
 
147
            {
 
148
                            AddProjectToBatch(projectName,line);
 
149
            };
133
150
                        textStream.ReadLine().ToLong(&m_projList.Last().id);
134
151
                        long status;
135
152
                        textStream.ReadLine().ToLong(&status);
224
241
        {
225
242
                if(gui)
226
243
                {
227
 
                        wxMessageDialog message(this, _("Cannot clear batch in progress.\nDo you want to cancel it?"), _("In progress"), wxYES | wxCANCEL | wxICON_INFORMATION);
 
244
                        wxMessageDialog message(this, _("Cannot clear batch in progress.\nDo you want to cancel it?"), 
 
245
#ifdef _WINDOWS
 
246
                _("PTBatcherGUI"),
 
247
#else
 
248
                wxT(""),
 
249
#endif
 
250
                wxYES | wxCANCEL | wxICON_INFORMATION);
228
251
                        if(message.ShowModal()==wxID_YES)
229
252
                        {
230
253
                                CancelBatch();
456
479
                        m_paused = false;
457
480
                i = GetIndex(event.GetId());
458
481
                if (event.GetExitCode() != 0 || event.GetTimestamp()==-1) //timestamp is used as a fake exit code because it cannot be set manually
459
 
                        m_projList.Item(i).status=Project::FAILED;
 
482
        {
 
483
            m_projList.Item(i).status=Project::FAILED;
 
484
            struct FailedProject failedProject;
 
485
            failedProject.project=m_projList.Item(i).path;
 
486
            failedProject.logfile=wxEmptyString;
 
487
            //get filename for automatic saving of log file
 
488
            wxFileName logFile(m_projList.Item(i).path);
 
489
            logFile.MakeAbsolute();
 
490
            logFile.SetExt(wxT("log"));
 
491
            wxString name=logFile.GetName();
 
492
            unsigned int i=1;
 
493
            while(logFile.FileExists() && i<1000)
 
494
            {
 
495
                logFile.SetName(wxString::Format(wxT("%s_%d"),name.c_str(),i));
 
496
                i++;
 
497
            };
 
498
            if(i<1000)
 
499
            {
 
500
                //now save log file
 
501
                if(((RunStitchFrame*)(event.GetEventObject()))->SaveLog(logFile.GetFullPath()))
 
502
                    failedProject.logfile=logFile.GetFullPath();
 
503
            };
 
504
            //remember failed project
 
505
            m_failedProjects.push_back(failedProject);
 
506
        }
460
507
                else            
461
508
                        m_projList.Item(i).status=Project::FINISHED;
462
509
                if(!m_cancelled && !m_paused)
476
523
                                else
477
524
                                {
478
525
                                        if(gui)
479
 
                                                //SetStatusText(_T("Project \""+m_projList.Item(i).path)+_T("\" finished. Batch completed with errors."));
 
526
                    {
480
527
                                                SetStatusText(_("Batch completed with errors."));
 
528
                        if(!shutdown)
 
529
                        {
 
530
                            //notify parent, that at least one project failed
 
531
                            wxCommandEvent e(EVT_BATCH_FAILED,wxID_ANY);
 
532
                            GetParent()->GetEventHandler()->AddPendingEvent(e);
 
533
                        };
 
534
                    }
481
535
                                        else
482
536
                                                //cout << "Project \"" << m_projList.Item(i).path.char_str() << "\" finished. Batch completed with errors." << endl;
483
537
                                                cout << "Batch completed with errors." << endl;
572
626
                         _("Specify project source project file"),
573
627
                         defaultdir, wxT(""),
574
628
                         _("Project files (*.pto,*.ptp,*.pts,*.oto)|*.pto;*.ptp;*.pts;*.oto;|All files (*)|*"),
575
 
                         wxOPEN, wxDefaultPosition);
 
629
                         wxFD_OPEN, wxDefaultPosition);
576
630
 
577
631
        dlg.SetDirectory(wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")));
578
632
        if (dlg.ShowModal() == wxID_OK) {
582
636
                        wxFileDialog dlg2(0,_("Specify output prefix"),
583
637
                     wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")),
584
638
                     wxT(""), wxT(""),
585
 
                     wxSAVE, wxDefaultPosition);
 
639
                     wxFD_SAVE, wxDefaultPosition);
586
640
                        dlg2.SetDirectory(wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")));
587
641
                        if (dlg2.ShowModal() == wxID_OK) {
588
642
                                //wxConfig::Get()->Write(wxT("/actualPath"), dlg2.GetDirectory());  // remember for later
640
694
        
641
695
}
642
696
 
643
 
 
644
 
 
 
697
bool Batch::OnDetect(wxString scriptFile, int id)
 
698
{    
 
699
        if(!gui)
 
700
                cout << "Running assistant with input file " << (const char *)scriptFile.mb_str(wxConvLocal) << "..." << endl;
 
701
 
 
702
        RunStitchFrame *stitchFrame = new RunStitchFrame(this, wxT("Hugin Assistant"), wxDefaultPosition, wxSize(640,600));
 
703
        stitchFrame->SetProjectId(id);
 
704
        if(verbose && gui)
 
705
        {
 
706
                stitchFrame->Show( true );
 
707
                wxTheApp->SetTopWindow( stitchFrame );
 
708
        }
 
709
        
 
710
    wxFileName basename(scriptFile);
 
711
    stitchFrame->SetTitle(wxString::Format(_("%s - Assistant"), basename.GetName().c_str()));
 
712
 
 
713
    bool n = stitchFrame->DetectProject(scriptFile, progsAss);
 
714
        if(n)
 
715
                m_stitchFrames.Add(stitchFrame);
 
716
        else
 
717
                stitchFrame->Close();
 
718
    return n;
 
719
        
 
720
}
645
721
 
646
722
void Batch::PauseBatch()
647
723
{
716
792
                cout << "Batch is empty." << endl;
717
793
        else if(!m_running)
718
794
        {
 
795
        m_failedProjects.clear();
719
796
                if(gui)
720
797
                        ((wxFrame*)GetParent())->SetStatusText(_("Running batch..."));
721
798
                else
800
877
                                m_projList.Item(i).status=Project::RUNNING;
801
878
                                //SetStatusText(_T("Stitching project \"")+m_projList.Item(i).path+_T("\""));
802
879
                                m_running = true;
803
 
                                value = OnStitch(m_projList.Item(i).path, m_projList.Item(i).prefix, m_projList.Item(i).id);
 
880
                if(m_projList.Item(i).target==Project::STITCHING)
 
881
                {
 
882
                                    value = OnStitch(m_projList.Item(i).path, m_projList.Item(i).prefix, m_projList.Item(i).id);
 
883
                }
 
884
                else
 
885
                {
 
886
                    value = OnDetect(m_projList.Item(i).path,m_projList.Item(i).id);
 
887
                };
804
888
                                if(!value)
805
889
                                        m_projList.Item(i).status=Project::FAILED;
806
890
                                else
816
900
                                        m_projList.Item(i).status=Project::RUNNING;
817
901
                                        //SetStatusText(_T("Stitching..."));
818
902
                                        m_running = true;
819
 
                                        value = OnStitch(m_projList.Item(i).path, m_projList.Item(i).prefix, m_projList.Item(i).id);
 
903
                    if(m_projList.Item(i).target==Project::STITCHING)
 
904
                    {
 
905
                                    value = OnStitch(m_projList.Item(i).path, m_projList.Item(i).prefix, m_projList.Item(i).id);
 
906
                    }
 
907
                    else
 
908
                    {
 
909
                        value = OnDetect(m_projList.Item(i).path,m_projList.Item(i).id);
 
910
                    };
820
911
                                        if(!value)
821
912
                                                m_projList.Item(i).status=Project::FAILED;
822
913
                                        else
844
935
        for(unsigned int i = 0; i< m_projList.GetCount(); i++)
845
936
        {
846
937
                textStream.WriteString(m_projList.Item(i).path+_T("\n"));
847
 
                textStream.WriteString(m_projList.Item(i).prefix+_T("\n"));
 
938
        if(m_projList.Item(i).target==Project::STITCHING)
 
939
        {
 
940
                    textStream.WriteString(m_projList.Item(i).prefix+_T("\n"));
 
941
        }
 
942
        else
 
943
        {
 
944
            textStream.WriteString(_T("\n"));
 
945
        };
848
946
                line = _T("");
849
947
                line << m_projList.Item(i).id;
850
948
                textStream.WriteString(line+_T("\n"));
907
1005
                m_stitchFrames.Item(i)->Show(isVisible);
908
1006
        };
909
1007
};
 
1008
 
 
1009
wxString Batch::GetFailedProjectName(unsigned int i)
 
1010
{
 
1011
    if(i>=0 && i<m_failedProjects.size())
 
1012
        return m_failedProjects[i].project;
 
1013
    else
 
1014
        return wxEmptyString;
 
1015
};
 
1016
 
 
1017
wxString Batch::GetFailedProjectLog(unsigned int i)
 
1018
{
 
1019
    if(i>=0 && i<m_failedProjects.size())
 
1020
        return m_failedProjects[i].logfile;
 
1021
    else
 
1022
        return wxEmptyString;
 
1023
};