From: <hug...@li...> - 2010-10-11 18:13:09
|
branch: details: http://hugin.hg.sourceforge.net/hgweb/hugin/hugin/hgrepo/h/hu/hugin/hugin/rev/edb56af6bd6a changeset: 4458:edb56af6bd6a user: tmodes date: Mon Oct 11 20:11:53 2010 +0200 description: Load default cp detector settings from external file * Allows also importing/exporting of cp detector settings to file diffstat: src/hugin1/hugin/CPDetectorDialog.cpp | 1 - src/hugin1/hugin/MainFrame.h | 3 +- src/hugin1/hugin/PreferencesDialog.cpp | 46 +++++++++- src/hugin1/hugin/PreferencesDialog.h | 6 + src/hugin1/hugin/xrc/pref_dialog.xrc | 41 +++++++- src/hugin1/icpfind/CMakeLists.txt | 12 ++- src/hugin1/icpfind/CPDetectorConfig.cpp | 123 ++++++++++++------------- src/hugin1/icpfind/CPDetectorConfig.h | 14 +- src/hugin1/icpfind/CPDetectorConfig_default.h | 104 --------------------- src/hugin1/icpfind/default.mac | 40 ++++++++ src/hugin1/icpfind/default.unix | 52 ++++++++++ src/hugin1/icpfind/default.win | 51 ++++++++++ 12 files changed, 309 insertions(+), 184 deletions(-) diffs (truncated from 708 to 500 lines): diff -r 7ef4c5b742a7 -r edb56af6bd6a src/hugin1/hugin/CPDetectorDialog.cpp --- a/src/hugin1/hugin/CPDetectorDialog.cpp Mon Oct 11 19:39:56 2010 +0200 +++ b/src/hugin1/hugin/CPDetectorDialog.cpp Mon Oct 11 20:11:53 2010 +0200 @@ -29,7 +29,6 @@ #include <config.h> #include "base_wx/huginConfig.h" #include "hugin/config_defaults.h" -#include "icpfind/CPDetectorConfig_default.h" #include "hugin/huginApp.h" #if defined MAC_SELF_CONTAINED_BUNDLE diff -r 7ef4c5b742a7 -r edb56af6bd6a src/hugin1/hugin/MainFrame.h --- a/src/hugin1/hugin/MainFrame.h Mon Oct 11 19:39:56 2010 +0200 +++ b/src/hugin1/hugin/MainFrame.h Mon Oct 11 20:11:53 2010 +0200 @@ -145,6 +145,8 @@ void OnToggleGLPreviewFrame(wxCommandEvent & e); void OnAddImages(wxCommandEvent & e); void OnSaveProject(wxCommandEvent & e); + /** call help browser with given file */ + void DisplayHelp(wxString section); void ShowCtrlPointEditor(unsigned int img1, unsigned int img2); @@ -204,7 +206,6 @@ void OnSize(wxSizeEvent &e); void enableTools(bool option); - void DisplayHelp(wxString section); void OnShowDonate(wxCommandEvent &e); void OnShowPanel(wxCommandEvent &e); diff -r 7ef4c5b742a7 -r edb56af6bd6a src/hugin1/hugin/PreferencesDialog.cpp --- a/src/hugin1/hugin/PreferencesDialog.cpp Mon Oct 11 19:39:56 2010 +0200 +++ b/src/hugin1/hugin/PreferencesDialog.cpp Mon Oct 11 20:11:53 2010 +0200 @@ -76,6 +76,9 @@ EVT_BUTTON(XRCID("pref_cpdetector_movedown"), PreferencesDialog::OnCPDetectorMoveDown) EVT_BUTTON(XRCID("pref_cpdetector_default"), PreferencesDialog::OnCPDetectorDefault) EVT_LISTBOX_DCLICK(XRCID("pref_cpdetector_list"), PreferencesDialog::OnCPDetectorListDblClick) + EVT_BUTTON(XRCID("pref_cpdetector_load"), PreferencesDialog::OnCPDetectorLoad) + EVT_BUTTON(XRCID("pref_cpdetector_save"), PreferencesDialog::OnCPDetectorSave) + EVT_BUTTON(XRCID("pref_cpdetector_help"), PreferencesDialog::OnCPDetectorHelp) // EVT_CLOSE(RunOptimizerFrame::OnClose) END_EVENT_TABLE() @@ -643,7 +646,15 @@ if (noteb->GetSelection() == 3) { ///// /// AUTOPANO - cpdetector_config_edit.ResetToDefault(); + wxString default_cpg_file=huginApp::Get()->GetDataPath()+wxT("default.setting"); + if(wxFileName::FileExists(default_cpg_file)) + { + cpdetector_config_edit.ReadFromFile(default_cpg_file); + } + else + { + cpdetector_config_edit.ResetToDefault(); + }; cpdetector_config_edit.Write(cfg); } if (noteb->GetSelection() == 4) { @@ -872,3 +883,36 @@ { OnCPDetectorEdit(e); }; + +void PreferencesDialog::OnCPDetectorLoad(wxCommandEvent &e) +{ + wxFileDialog dlg(this,_("Load control point detector settings"), + wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")), wxEmptyString, + _("Control point detector settings (*.setting)|*.setting"),wxFD_OPEN | wxFD_FILE_MUST_EXIST); + if (dlg.ShowModal() == wxID_OK) + { + wxConfig::Get()->Write(wxT("/actualPath"), dlg.GetDirectory()); // remember for later + wxString fn = dlg.GetPath(); + cpdetector_config_edit.ReadFromFile(fn); + cpdetector_config_edit.Write(); + UpdateDisplayData(4); + }; +}; + +void PreferencesDialog::OnCPDetectorSave(wxCommandEvent &e) +{ + wxFileDialog dlg(this,_("Save control point detector settings"), + wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")), wxEmptyString, + _("Control point detector settings (*.setting)|*.setting"),wxFD_SAVE | wxFD_OVERWRITE_PROMPT); + if (dlg.ShowModal() == wxID_OK) + { + wxConfig::Get()->Write(wxT("/actualPath"), dlg.GetDirectory()); // remember for later + wxString fn = dlg.GetPath(); + cpdetector_config_edit.WriteToFile(fn); + }; +}; + +void PreferencesDialog::OnCPDetectorHelp(wxCommandEvent &e) +{ + MainFrame::Get()->DisplayHelp(wxT("/Control_Point_Detector_Parameters.html")); +}; \ No newline at end of file diff -r 7ef4c5b742a7 -r edb56af6bd6a src/hugin1/hugin/PreferencesDialog.h --- a/src/hugin1/hugin/PreferencesDialog.h Mon Oct 11 19:39:56 2010 +0200 +++ b/src/hugin1/hugin/PreferencesDialog.h Mon Oct 11 20:11:53 2010 +0200 @@ -79,6 +79,12 @@ void OnCPDetectorMoveDown(wxCommandEvent & e); void OnCPDetectorDefault(wxCommandEvent & e); void OnCPDetectorListDblClick(wxCommandEvent & e); + /** event handler for loading cp detector settings */ + void OnCPDetectorLoad(wxCommandEvent & e); + /** event handler for saving cp detector settings */ + void OnCPDetectorSave(wxCommandEvent & e); + /** event handler for showing help for cp detector settings */ + void OnCPDetectorHelp(wxCommandEvent & e); void EnableRotationCtrls(bool enable); bool GetPanoVersion(); diff -r 7ef4c5b742a7 -r edb56af6bd6a src/hugin1/hugin/xrc/pref_dialog.xrc --- a/src/hugin1/hugin/xrc/pref_dialog.xrc Mon Oct 11 19:39:56 2010 +0200 +++ b/src/hugin1/hugin/xrc/pref_dialog.xrc Mon Oct 11 20:11:53 2010 +0200 @@ -676,42 +676,71 @@ <label>New...</label> </object> <flag>wxALL|wxEXPAND</flag> - <border>5</border> + <border>3</border> </object> <object class="sizeritem"> <object class="wxButton" name="pref_cpdetector_edit"> <label>Edit...</label> </object> <flag>wxALL|wxEXPAND</flag> - <border>5</border> + <border>3</border> </object> <object class="sizeritem"> <object class="wxButton" name="pref_cpdetector_del"> <label>Delete</label> </object> <flag>wxALL|wxEXPAND</flag> - <border>5</border> + <border>3</border> </object> <object class="sizeritem"> <object class="wxButton" name="pref_cpdetector_moveup"> <label>Move up</label> </object> <flag>wxALL|wxEXPAND</flag> - <border>5</border> + <border>3</border> </object> <object class="sizeritem"> <object class="wxButton" name="pref_cpdetector_movedown"> <label>Move down</label> </object> <flag>wxALL|wxEXPAND</flag> - <border>5</border> + <border>3</border> </object> <object class="sizeritem"> <object class="wxButton" name="pref_cpdetector_default"> <label>Set default</label> </object> <flag>wxALL|wxEXPAND</flag> - <border>5</border> + <border>3</border> + </object> + <object class="sizeritem"> + <object class="wxStaticLine"/> + <flag>wxEXPAND</flag> + </object> + <object class="sizeritem"> + <object class="wxButton" name="pref_cpdetector_load"> + <label>Import</label> + </object> + <flag>wxALL|wxEXPAND</flag> + <border>3</border> + </object> + <object class="sizeritem"> + <object class="wxButton" name="pref_cpdetector_save"> + <label>Export</label> + </object> + <flag>wxALL|wxEXPAND</flag> + <border>3</border> + </object> + <object class="sizeritem"> + <object class="wxStaticLine"/> + <flag>wxEXPAND</flag> + </object> + <object class="sizeritem"> + <object class="wxButton" name="pref_cpdetector_help"> + <label>Help</label> + </object> + <flag>wxALL|wxEXPAND</flag> + <border>3</border> </object> </object> <flag>wxALL</flag> diff -r 7ef4c5b742a7 -r edb56af6bd6a src/hugin1/icpfind/CMakeLists.txt --- a/src/hugin1/icpfind/CMakeLists.txt Mon Oct 11 19:39:56 2010 +0200 +++ b/src/hugin1/icpfind/CMakeLists.txt Mon Oct 11 20:11:53 2010 +0200 @@ -1,5 +1,5 @@ SET(ICPFIND_LIB_SRC AutoCtrlPointCreator.cpp CPDetectorConfig.cpp) -SET(ICPFIND_LIB_HEADER AutoCtrlPointCreator.h CPDetectorConfig.h CPDetectorConfig_default.h) +SET(ICPFIND_LIB_HEADER AutoCtrlPointCreator.h CPDetectorConfig.h) IF (${HUGIN_SHARED_LIBS}) ADD_LIBRARY(icpfindlib SHARED ${ICPFIND_LIB_SRC} ${ICPFIND_LIB_HEADER}) @@ -21,4 +21,12 @@ TARGET_LINK_LIBRARIES(icpfind icpfindlib ${wxWidgets_LIBRARIES} ${common_libs}) INSTALL(TARGETS icpfind DESTINATION ${BINDIR}) - +IF(WIN32) + INSTALL(FILES default.win DESTINATION ${INSTALL_DATA_DIR} RENAME default.setting) +ELSE() + IF(APPLE) + INSTALL(FILES default.mac DESTINATION ${INSTALL_DATA_DIR} RENAME default.setting) + ELSE() + INSTALL(FILES default.unix DESTINATION ${INSTALL_DATA_DIR} RENAME default.setting) + ENDIF() +ENDIF() diff -r 7ef4c5b742a7 -r edb56af6bd6a src/hugin1/icpfind/CPDetectorConfig.cpp --- a/src/hugin1/icpfind/CPDetectorConfig.cpp Mon Oct 11 19:39:56 2010 +0200 +++ b/src/hugin1/icpfind/CPDetectorConfig.cpp Mon Oct 11 20:11:53 2010 +0200 @@ -27,7 +27,18 @@ #include "icpfind/CPDetectorConfig.h" #include <config.h> -#include "icpfind/CPDetectorConfig_default.h" +#include <wx/fileconf.h> + +/** description of default cp generator, for fall back procedure */ +wxString default_cpgenerator_desc(wxT("Hugins Cpfind")); +/** program name of default cp generator, for fall back procedure */ +#ifdef __WINDOWS__ +wxString default_cpgenerator_prog(wxT("cpfind.exe")); +#else +wxString default_cpgenerator_prog(wxT("cpfind")); +#endif +/** arguments for default cp generator, for fall back procedure */ +wxString default_cpgenerator_args(wxT("-o %o %s")); void CPDetectorConfig::Read(wxConfigBase *config) { @@ -45,16 +56,26 @@ default_generator=0; }; +void CPDetectorConfig::ReadFromFile(wxString filename) +{ + wxFileConfig fconfig(wxT("hugin"),wxEmptyString,filename); + Read(&fconfig); +}; + void CPDetectorConfig::ReadIndex(wxConfigBase *config, int i) { wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i); if(config->HasGroup(path)) { CPDetectorSetting* gen=new CPDetectorSetting; - gen->Read(config,path); - settings.Add(gen); - if(i==default_generator) - default_generator=settings.Index(*gen,true); + if(gen->Read(config,path)) + { + settings.Add(gen); + if(i==default_generator) + { + default_generator=settings.Index(*gen,true); + }; + }; }; }; @@ -70,6 +91,12 @@ }; }; +void CPDetectorConfig::WriteToFile(wxString filename) +{ + wxFileConfig fconfig(wxT("hugin"),wxEmptyString,filename); + Write(&fconfig); +}; + void CPDetectorConfig::WriteIndex(wxConfigBase *config, int i) { wxString path=wxString::Format(wxT("/AutoPano/AutoPano_%d"),i); @@ -79,9 +106,7 @@ void CPDetectorConfig::ResetToDefault() { settings.Clear(); - int maxIndex=sizeof(default_cpdetectors)/sizeof(cpdetector_default)-1; - for(int i=0;i<=maxIndex;i++) - settings.Add(new CPDetectorSetting(i)); + settings.Add(new CPDetectorSetting()); default_generator=0; }; @@ -121,53 +146,18 @@ #include <wx/arrimpl.cpp> WX_DEFINE_OBJARRAY(ArraySettings); -CPDetectorSetting::CPDetectorSetting(int new_type) +CPDetectorSetting::CPDetectorSetting() { - if(new_type>=0) - { - int maxIndex=sizeof(default_cpdetectors)/sizeof(cpdetector_default)-1; - if (new_type<=maxIndex) - { - type=default_cpdetectors[new_type].type; - desc=default_cpdetectors[new_type].desc; - prog=default_cpdetectors[new_type].prog; - args=default_cpdetectors[new_type].args; - if(IsCleanupPossible()) - { - args_cleanup=default_cpdetectors[new_type].args_cleanup; - } - else - { - args_cleanup=wxEmptyString; - }; - prog_matcher=default_cpdetectors[new_type].prog_matcher; - args_matcher=default_cpdetectors[new_type].args_matcher; - if(ContainsStacks()) - { - prog_stack=default_cpdetectors[new_type].prog_stack; - args_stack=default_cpdetectors[new_type].args_stack; - } - else - { - prog_stack=wxEmptyString; - args_stack=wxEmptyString; - }; - option=default_cpdetectors[new_type].option; - }; - } - else - { - type=CPDetector_AutoPanoSift; - desc=wxEmptyString; - prog=wxEmptyString; - args=wxEmptyString; - args_cleanup=wxEmptyString; - prog_matcher=wxEmptyString; - args_matcher=wxEmptyString; - prog_stack=wxEmptyString; - args_stack=wxEmptyString; - option=true; - }; + type=CPDetector_AutoPanoSift; + desc=default_cpgenerator_desc; + prog=default_cpgenerator_prog; + args=default_cpgenerator_args; + args_cleanup=wxEmptyString; + prog_matcher=wxEmptyString; + args_matcher=wxEmptyString; + prog_stack=wxEmptyString; + args_stack=wxEmptyString; + option=true; CheckValues(); }; @@ -195,12 +185,16 @@ return (_type==CPDetector_AutoPanoSiftStack || _type==CPDetector_AutoPanoSiftMultiRowStack); }; -void CPDetectorSetting::Read(wxConfigBase *config, wxString path) +bool CPDetectorSetting::Read(wxConfigBase *config, wxString path) { - type=(CPDetectorType)config->Read(path+wxT("/Type"),default_cpdetectors[0].type); - desc=config->Read(path+wxT("/Description"),default_cpdetectors[0].desc); - prog=config->Read(path+wxT("/Program"),default_cpdetectors[0].prog); - args=config->Read(path+wxT("/Arguments"),default_cpdetectors[0].args); + if(!config->Exists(path)) + { + return false; + } + type=(CPDetectorType)config->Read(path+wxT("/Type"),CPDetector_AutoPanoSift); + desc=config->Read(path+wxT("/Description"),default_cpgenerator_desc); + prog=config->Read(path+wxT("/Program"),default_cpgenerator_prog); + args=config->Read(path+wxT("/Arguments"),default_cpgenerator_args); if(IsCleanupPossible()) { args_cleanup=config->Read(path+wxT("/ArgumentsCleanup"),wxEmptyString); @@ -209,20 +203,21 @@ { args_cleanup=wxEmptyString; }; - prog_matcher=config->Read(path+wxT("/ProgramMatcher"),default_cpdetectors[0].prog_matcher); - args_matcher=config->Read(path+wxT("/ArgumentsMatcher"),default_cpdetectors[0].args_matcher); + prog_matcher=config->Read(path+wxT("/ProgramMatcher"),wxEmptyString); + args_matcher=config->Read(path+wxT("/ArgumentsMatcher"),wxEmptyString); if(ContainsStacks()) { - prog_stack=config->Read(path+wxT("/ProgramStack"),default_cpdetectors[0].prog_stack); - args_stack=config->Read(path+wxT("/ArgumentsStack"),default_cpdetectors[0].args_stack); + prog_stack=config->Read(path+wxT("/ProgramStack"),wxEmptyString); + args_stack=config->Read(path+wxT("/ArgumentsStack"),wxEmptyString); } else { prog_stack=wxEmptyString; args_stack=wxEmptyString; }; - config->Read(path+wxT("/Option"),&option,default_cpdetectors[0].option); + config->Read(path+wxT("/Option"),&option,true); CheckValues(); + return true; }; void CPDetectorSetting::Write(wxConfigBase *config, wxString path) diff -r 7ef4c5b742a7 -r edb56af6bd6a src/hugin1/icpfind/CPDetectorConfig.h --- a/src/hugin1/icpfind/CPDetectorConfig.h Mon Oct 11 19:39:56 2010 +0200 +++ b/src/hugin1/icpfind/CPDetectorConfig.h Mon Oct 11 20:11:53 2010 +0200 @@ -47,13 +47,13 @@ class ICPIMPEX CPDetectorSetting { public: - /** constructor - * @param new_type: -1: no settings, otherwise index of default_cpdetectors array */ - CPDetectorSetting(int new_type = -1); + /** constructor */ + CPDetectorSetting(); /** destructor */ virtual ~CPDetectorSetting() {}; - /** read setting for this generator from config */ - void Read(wxConfigBase* config, wxString path); + /** read setting for this generator from config + * @return true on success */ + bool Read(wxConfigBase* config, wxString path); /** writes setting for this generator to config */ void Write(wxConfigBase* config, wxString path); /** return description of this setting */ @@ -136,6 +136,10 @@ void Read(wxConfigBase* config=wxConfigBase::Get()); /** writes the settings of different cp generators to config */ void Write(wxConfigBase* config=wxConfigBase::Get()); + /** import the cp detector settings from external file */ + void ReadFromFile(wxString filename); + /** exporth the cp detector settings to external file */ + void WriteToFile(wxString filename); /** reset values to default */ void ResetToDefault(); /** fills a wxControlWithItems with the available generators diff -r 7ef4c5b742a7 -r edb56af6bd6a src/hugin1/icpfind/CPDetectorConfig_default.h --- a/src/hugin1/icpfind/CPDetectorConfig_default.h Mon Oct 11 19:39:56 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,104 +0,0 @@ -// -*- c-basic-offset: 4 -*- - -/** @file CPDetectorConfig_default.h - * - * @brief default settings for different control point detectors - * - * @author Thomas Modes - * - * $Id$ - * - */ - -/* This is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef _CPDETECTORCONFIG_DEFAULT_H -#define _CPDETECTORCONFIG_DEFAULT_H - -#include "panoinc_WX.h" - -/** struct to save the default setting of one CP detector */ -struct cpdetector_default -{ - /** cp detector type */ - CPDetectorType type; - /** name, which is shown in GUI */ - wxString desc; - /** program name for detector or descriptor*/ - wxString prog; - /** arguments of the detector or descriptor*/ - wxString args; - /** arguments for the cleanup step */ - wxString args_cleanup; - /** program name for matcher */ - wxString prog_matcher; - /** arguments of matcher */ - wxString args_matcher; - /** program name of cp detector for stacks */ |