From: Pablo d'A. <da...@us...> - 2007-02-12 00:03:18
|
Update of /cvsroot/hugin/hugin/src/hugin In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv1063/src/hugin Modified Files: ImageCache.cpp MainFrame.cpp PreferencesDialog.cpp wxPanoCommand.cpp Log Message: added "apply template" function Index: wxPanoCommand.cpp =================================================================== RCS file: /cvsroot/hugin/hugin/src/hugin/wxPanoCommand.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- wxPanoCommand.cpp 2 Feb 2007 22:03:23 -0000 1.5 +++ wxPanoCommand.cpp 12 Feb 2007 00:03:13 -0000 1.6 @@ -324,6 +324,109 @@ } +void wxApplyTemplateCmd::execute() +{ + PanoCommand::execute(); + + wxConfigBase* config = wxConfigBase::Get(); + + if (pano.getNrOfImages() == 0) { + // TODO: prompt for images! + + // add a dummy lens + Lens dummyLens; + pano.addLens(dummyLens); + + wxString wildcard (_("All Image files|*.jpg;*.JPG;*.tif;*.TIF;*.tiff;*.TIFF;*.png;*.PNG;*.bmp;*.BMP;*.gif;*.GIF;*.pnm;*.PNM;*.sun;*.viff;*.hdr|JPEG files (*.jpg)|*.jpg;*.JPG;*.jpeg;*.jpg|All files (*)|*")); + + wxString path = config->Read(wxT("actualPath"), wxT("")); + wxFileDialog dlg(MainFrame::Get(), _("Add images"), + path, wxT(""), + wildcard, wxOPEN|wxMULTIPLE , wxDefaultPosition); + + // remember the image extension + wxString img_ext; + if (config->HasEntry(wxT("lastImageType"))){ + img_ext = config->Read(wxT("lastImageType")).c_str(); + } + if (img_ext == wxT("all images")) + dlg.SetFilterIndex(0); + else if (img_ext == wxT("jpg")) + dlg.SetFilterIndex(1); + else if (img_ext == wxT("all files")) + dlg.SetFilterIndex(2); + DEBUG_INFO ( "Image extention: " << img_ext.mb_str() ); + + // call the file dialog + if (dlg.ShowModal() == wxID_OK) { + // get the selections + wxArrayString Pathnames; + wxArrayString Filenames; + dlg.GetPaths(Pathnames); + dlg.GetFilenames(Filenames); + + // e safe the current path to config + config->Write(wxT("actualPath"), dlg.GetDirectory()); // remember for later + DEBUG_INFO ( wxString::Format(wxT("img_ext: %d"), dlg.GetFilterIndex()).mb_str() ); + // save the image extension + switch ( dlg.GetFilterIndex() ) { + case 0: config->Write(wxT("lastImageType"), wxT("all images")); break; + case 1: config->Write(wxT("lastImageType"), wxT("jpg")); break; + case 2: config->Write(wxT("lastImageType"), wxT("all files")); break; + } + + // add images. + for (unsigned int i=0; i< Pathnames.GetCount(); i++) { + std::string filename = (const char *)Pathnames[i].mb_str(); + vigra::ImageImportInfo inf(filename.c_str()); + PanoImage img(filename, inf.width(), inf.height(), 0); + VariableMap vars; + fillVariableMap(vars); + int imgNr = pano.addImage(img, vars); + } + + } + } + + int nOldImg = pano.getNrOfImages(); + PanoramaMemento newPanoMem; + + if (newPanoMem.loadPTScript(in, "")) { + Panorama newPano; + newPano.setMemento(newPanoMem); + + unsigned int nNewImg = newPano.getNrOfImages(); + if (nOldImg != nNewImg) { + wxString errMsg = wxString::Format(_("Error, template expects %d images,\ncurrent project contains %d images\n"), nNewImg, nOldImg); + wxMessageBox(errMsg, _("Could not apply template"), wxICON_ERROR); + pano.changeFinished(); + return; + } + + // check image sizes, and correct parameters if required. + for (unsigned int i = 0; i < nNewImg; i++) { + + // check if image size is correct + SrcPanoImage oldSrcImg = pano.getSrcImage(i); + SrcPanoImage newSrcImg = newPano.getSrcImage(i); + + // just keep the file name + DEBUG_DEBUG("apply template fn:" << newSrcImg.getFilename() << " real fn: " << oldSrcImg.getFilename()); + newSrcImg.setFilename(oldSrcImg.getFilename()); + if (oldSrcImg.getSize() != newSrcImg.getSize()) { + // adjust size properly. + newSrcImg.resize(oldSrcImg.getSize()); + } + newPano.setSrcImage(i, newSrcImg); + } + newPanoMem = newPano.getMemento(); + pano.setMemento(newPanoMem); + } else { + wxMessageBox(_("Error loading project file"), _("Could not apply template"), wxICON_ERROR); + } + pano.changeFinished(); +} + } // namespace Index: PreferencesDialog.cpp =================================================================== RCS file: /cvsroot/hugin/hugin/src/hugin/PreferencesDialog.cpp,v retrieving revision 1.66 retrieving revision 1.67 diff -u -d -r1.66 -r1.67 --- PreferencesDialog.cpp 25 Jan 2007 22:47:43 -0000 1.66 +++ PreferencesDialog.cpp 12 Feb 2007 00:03:13 -0000 1.67 @@ -179,6 +179,8 @@ this->SetBackgroundColour(XRCCTRL(*this, "prefs_ft_RotationStartAngle", wxSpinCtrl)->GetBackgroundColour()); #endif + GetSizer()->Layout(); + RestoreFramePosition(this, wxT("PreferencesDialog")); } Index: ImageCache.cpp =================================================================== RCS file: /cvsroot/hugin/hugin/src/hugin/ImageCache.cpp,v retrieving revision 1.53 retrieving revision 1.54 diff -u -d -r1.53 -r1.54 --- ImageCache.cpp 25 Jan 2007 22:47:43 -0000 1.53 +++ ImageCache.cpp 12 Feb 2007 00:03:13 -0000 1.54 @@ -776,8 +776,8 @@ } DEBUG_DEBUG("creating small image " << name ); Entry * entry = getImage(filename); - wxImage * image = entry->image; - if (image->Ok()) { + if (entry && entry->image->Ok()) { + wxImage * image = entry->image; wxImage small_image; const int w = 512; double ratio = (double)image->GetWidth() / image->GetHeight(); Index: MainFrame.cpp =================================================================== RCS file: /cvsroot/hugin/hugin/src/hugin/MainFrame.cpp,v retrieving revision 1.194 retrieving revision 1.195 diff -u -d -r1.194 -r1.195 --- MainFrame.cpp 11 Feb 2007 22:55:09 -0000 1.194 +++ MainFrame.cpp 12 Feb 2007 00:03:13 -0000 1.195 @@ -1103,7 +1103,24 @@ void MainFrame::OnApplyTemplate(wxCommandEvent & e) { - wxMessageBox(wxT("Templates not implemented yet")); + // get the global config object + wxConfigBase* config = wxConfigBase::Get(); + + wxFileDialog dlg(this, + _("Choose template project"), + config->Read(wxT("/templatePath"),wxT("")), wxT(""), + _("Project files (*.pto,*.ptp,*.pts,*.oto)|*.pto;*.ptp;*.pts;*.oto;|All files (*)|*"), + wxOPEN, wxDefaultPosition); + if (dlg.ShowModal() == wxID_OK) { + wxString filename = dlg.GetPath(); + wxConfig::Get()->Write(wxT("/templatePath"), dlg.GetDirectory()); // remember for later + + std::ifstream file((const char *)filename.mb_str()); + + GlobalCmdHist::getInstance().addCommand( + new wxApplyTemplateCmd(pano, file)); + + } } @@ -1391,3 +1408,8 @@ MainFrame * MainFrame::m_this = 0; + +void applyTemplate() +{ + // ask for template +} |