ProjectArray.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00027 #include "ProjectArray.h"
00028 #include <wx/arrimpl.cpp>
00029 #include "base_wx/huginConfig.h"
00030 #include <fstream>
00031 
00032 long Project::idGenerator=1;
00033 
00034 Project::Project(wxString pth,wxString pfx, Project::Target newTarget)
00035 {
00036     id = Project::idGenerator;
00037     Project::idGenerator++;
00038     path = pth;
00039     prefix = pfx;
00040     wxFileName file(path);
00041     if(file.FileExists())
00042     {
00043         file.GetTimes(NULL,&modDate,NULL);
00044     }
00045     isAligned = true;
00046     options = ReadOptions(pth);
00047     skip = false;
00048     status = WAITING;
00049     target = newTarget;
00050 }
00051 
00052 Project::Project(wxString command)
00053 {
00054     path = command;
00055     id = -Project::idGenerator;
00056     Project::idGenerator++;
00057     skip = false;
00058     isAligned = true;
00059     status = WAITING;
00060     target = STITCHING;
00061 }
00062 
00063 wxString Project::GetStatusText()
00064 {
00065     switch(status)
00066     {
00067         case WAITING:
00068             return _("Waiting");
00069         case RUNNING:
00070             return _("In progress");
00071         case FINISHED:
00072             return _("Complete");
00073         case FAILED:
00074             return _("Failed");
00075         case MISSING:
00076             return _("File missing");
00077         case PAUSED:
00078             return _("Paused");
00079         default:
00080             return _T("");
00081     }
00082 }
00083 
00084 HuginBase::PanoramaOptions Project::ReadOptions(wxString projectFile)
00085 {
00086     std::ifstream prjfile((const char*)projectFile.mb_str(HUGIN_CONV_FILENAME));
00087     if (prjfile.bad())
00088     {
00089         wxLogError( wxString::Format(_("could not open script: %s"), projectFile.c_str()) );
00090     }
00091 
00092     wxString pathToPTO;
00093     wxFileName::SplitPath(projectFile, &pathToPTO, NULL, NULL);
00094     pathToPTO.Append(wxT("/"));
00095 
00096     HuginBase::Panorama pano;
00097     HuginBase::PanoramaMemento newPano;
00098     int ptoVersion = 0;
00099     if (newPano.loadPTScript(prjfile, ptoVersion, (const char*)pathToPTO.mb_str(HUGIN_CONV_FILENAME)))
00100     {
00101         pano.setMemento(newPano);
00102         if (ptoVersion < 2)
00103         {
00104             HuginBase::PanoramaOptions opts = pano.getOptions();
00105             // no options stored in file, use default arguments in config
00106             opts.enblendOptions = wxConfigBase::Get()->Read(wxT("/Enblend/Args"), wxT("")).mb_str(wxConvLocal);
00107             opts.enfuseOptions = wxConfigBase::Get()->Read(wxT("/Enfuse/Args"), wxT("")).mb_str(wxConvLocal);
00108             pano.setOptions(opts);
00109         }
00110         // set default prefix, if not given
00111         if(prefix.IsEmpty())
00112         {
00113             wxFileName prefixFilename(getDefaultOutputName(projectFile, pano));
00114             prefixFilename.Normalize();
00115             prefix=prefixFilename.GetFullPath();
00116         };
00117         // if project contains at least 2 images and no control points add to assistant queue
00118         // a single image project is assumed as target for reprojection/remapping
00119         if(pano.getNrOfImages()>1 && pano.getNrOfCtrlPoints()==0)
00120         {
00121             isAligned=false;
00122         };
00123     }
00124     else
00125     {
00126         wxLogError( wxString::Format(_("error while parsing panotools script: %s"), projectFile.c_str()) );
00127     }
00128     // get options and correct for correct makefile
00129     HuginBase::PanoramaOptions opts = pano.getOptions();
00130     return opts;
00131 }
00132 
00133 void Project::ResetOptions()
00134 {
00135     wxFileName file(path);
00136     if(file.FileExists())
00137     {
00138         file.GetTimes(NULL,&modDate,NULL);
00139     }
00140     options = ReadOptions(path);
00141 }
00142 
00143 WX_DEFINE_OBJARRAY(ProjectArray); //define the array in ProjectArray.h

Generated on 30 Jun 2016 for Hugintrunk by  doxygen 1.4.7