1 // -*- c-basic-offset: 4 -*-
2
3 /** @file ProjectArray.cpp
4 *
5 * @brief Batch processor for Hugin
6 *
7 * @author Marko Kuder <marko.kuder@gmail.com>
8 *
9 * $Id: ProjectArray.cpp 3322 2008-08-16 5:00:07Z mkuder $
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This software is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public
22 * License along with this software. If not, see
23 * <http://www.gnu.org/licenses/>.
24 *
25 */
26
27 #ifdef _WIN32
28 #include "wx/msw/wrapwin.h"
29 #endif
30 #include "ProjectArray.h"
31 #include <wx/arrimpl.cpp>
32 #include "base_wx/huginConfig.h"
33 #include <fstream>
34
35 long Project::idGenerator=1;
36
Project(wxString pth,wxString pfx,Project::Target newTarget)37 Project::Project(wxString pth,wxString pfx, Project::Target newTarget)
38 {
39 id = Project::idGenerator;
40 Project::idGenerator++;
41 path = pth;
42 prefix = pfx;
43 wxFileName file(path);
44 if(file.FileExists())
45 {
46 file.GetTimes(NULL,&modDate,NULL);
47 }
48 isAligned = true;
49 options = ReadOptions(pth);
50 skip = false;
51 status = WAITING;
52 target = newTarget;
53 }
54
Project(wxString command)55 Project::Project(wxString command)
56 {
57 path = command;
58 id = -Project::idGenerator;
59 Project::idGenerator++;
60 skip = false;
61 isAligned = true;
62 status = WAITING;
63 target = STITCHING;
64 }
65
GetStatusText()66 wxString Project::GetStatusText()
67 {
68 switch(status)
69 {
70 case WAITING:
71 return _("Waiting");
72 case RUNNING:
73 return _("In progress");
74 case FINISHED:
75 return _("Complete");
76 case FAILED:
77 return _("Failed");
78 case MISSING:
79 return _("File missing");
80 case PAUSED:
81 return _("Paused");
82 default:
83 return _T("");
84 }
85 }
86
ReadOptions(wxString projectFile)87 HuginBase::PanoramaOptions Project::ReadOptions(wxString projectFile)
88 {
89 HuginBase::Panorama pano;
90 std::ifstream prjfile((const char*)projectFile.mb_str(HUGIN_CONV_FILENAME));
91 if (prjfile.good())
92 {
93 wxString pathToPTO;
94 wxFileName::SplitPath(projectFile, &pathToPTO, NULL, NULL);
95 pathToPTO.Append(wxT("/"));
96
97 HuginBase::PanoramaMemento newPano;
98 int ptoVersion = 0;
99 if (newPano.loadPTScript(prjfile, ptoVersion, (const char*)pathToPTO.mb_str(HUGIN_CONV_FILENAME)))
100 {
101 pano.setMemento(newPano);
102 if (ptoVersion < 2)
103 {
104 HuginBase::PanoramaOptions opts = pano.getOptions();
105 // no options stored in file, use default arguments in config
106 opts.enblendOptions = wxConfigBase::Get()->Read(wxT("/Enblend/Args"), wxT("")).mb_str(wxConvLocal);
107 opts.enfuseOptions = wxConfigBase::Get()->Read(wxT("/Enfuse/Args"), wxT("")).mb_str(wxConvLocal);
108 pano.setOptions(opts);
109 }
110 // set default prefix, if not given
111 if (prefix.IsEmpty())
112 {
113 wxFileName prefixFilename(getDefaultOutputName(projectFile, pano));
114 prefixFilename.Normalize();
115 prefix = prefixFilename.GetFullPath();
116 };
117 // if project contains at least 2 images and no control points add to assistant queue
118 // a single image project is assumed as target for reprojection/remapping
119 if (pano.getNrOfImages() > 1 && pano.getNrOfCtrlPoints() == 0)
120 {
121 isAligned = false;
122 };
123 };
124 };
125 // get options
126 return pano.getOptions();
127 }
128
ResetOptions()129 void Project::ResetOptions()
130 {
131 wxFileName file(path);
132 if(file.FileExists())
133 {
134 file.GetTimes(NULL,&modDate,NULL);
135 }
136 options = ReadOptions(path);
137 }
138
139 WX_DEFINE_OBJARRAY(ProjectArray); //define the array in ProjectArray.h
140