Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ChangeUserDefinedDialog.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
11 /* This 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  * Lesser 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 
28 #include <wx/dir.h>
29 #include <wx/stdpaths.h>
30 #include <wx/wfstream.h>
31 #include "base_wx/Executor.h"
32 #if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
33 #include "base_wx/platform.h"
34 #endif
35 
36 BEGIN_EVENT_TABLE(ChangeUserDefinedSequenceDialog,wxDialog)
37  EVT_RADIOBUTTON(XRCID("radio_default_sequence"), ChangeUserDefinedSequenceDialog::UpdateStatus)
38  EVT_RADIOBUTTON(XRCID("radio_user_defined"), ChangeUserDefinedSequenceDialog::UpdateStatus)
39  EVT_RADIOBUTTON(XRCID("radio_external_sequence"), ChangeUserDefinedSequenceDialog::UpdateStatus)
40  EVT_CHOICE(XRCID("choice_user_defined"), ChangeUserDefinedSequenceDialog::OnChangeUserDefinedChoice)
41  EVT_BUTTON(XRCID("button_external_file"), ChangeUserDefinedSequenceDialog::OnChooseFilename)
42  EVT_BUTTON(wxID_OK, ChangeUserDefinedSequenceDialog::OnOk)
44 
45 
46 ChangeUserDefinedSequenceDialog::ChangeUserDefinedSequenceDialog(wxWindow* parent, wxString xrcPrefix, wxString userDefinedSequence, bool assistantUserDefined)
47 {
48  // load our children. some children might need special
49  // initialization. this will be done later.
50  wxXmlResource::Get()->LoadDialog(this, parent, "change_user_defined_dialog");
51 
52 #ifdef __WXMSW__
53  wxIconBundle myIcons(xrcPrefix+ "data/ptbatcher.ico",wxBITMAP_TYPE_ICO);
54  SetIcons(myIcons);
55 #else
56  wxIcon myIcon(xrcPrefix + "data/ptbatcher.png",wxBITMAP_TYPE_PNG);
57  SetIcon(myIcon);
58 #endif
59 
60  m_radio_default = XRCCTRL(*this, "radio_default_sequence", wxRadioButton);
61  m_radio_user_sequence = XRCCTRL(*this, "radio_user_defined", wxRadioButton);
62  m_choice_user_define=XRCCTRL(*this, "choice_user_defined", wxChoice);
63  m_label_user_define = XRCCTRL(*this, "label_user_defined", wxStaticText);
64  m_label_user_define_filename = XRCCTRL(*this, "label_user_defined_filename", wxStaticText);
65  m_radio_external = XRCCTRL(*this, "radio_external_sequence", wxRadioButton);
66  m_text_external_file = XRCCTRL(*this, "text_external_file", wxTextCtrl);
67  m_text_external_file->AutoCompleteFileNames();
68  m_button_external_file = XRCCTRL(*this, "button_external_file", wxButton);
69 
70  m_isAssistantUserDefined = assistantUserDefined;
71  if (m_isAssistantUserDefined)
72  {
73  FillAssistantUserDefined();
74  }
75  else
76  {
77  FillStitcherUserDefined();
78  };
79  if (userDefinedSequence.IsEmpty())
80  {
81  m_radio_default->SetValue(true);
82  }
83  else
84  {
85  int index = m_userFileNames.Index(userDefinedSequence);
86  if (index == wxNOT_FOUND)
87  {
88  // user defined sequence not found in list
89  // so use external entry
90  m_radio_external->SetValue(true);
91  m_text_external_file->SetValue(userDefinedSequence);
92  }
93  else
94  {
95  // item found in list
96  m_radio_user_sequence->SetValue(true);
97  m_choice_user_define->Select(index);
98  };
99  };
100  wxCommandEvent dummy;
101  UpdateStatus(dummy);
102 
103  //set parameters
104  wxConfigBase* config = wxConfigBase::Get();
105  // restore position and size
106  int dx,dy;
107  wxDisplaySize(&dx,&dy);
108  //size
109  int w = config->Read("/UserDefinedSequenceDialog/width", -1l);
110  int h = config->Read("/UserDefinedSequenceDialog/height", -1l);
111  if (w > 0 && w <= dx)
112  {
113  this->SetClientSize(w,h);
114  }
115  else
116  {
117  this->Fit();
118  }
119  //position
120  int x = config->Read("/UserDefinedSequenceDialog/positionX", -1l);
121  int y = config->Read("/UserDefinedSequenceDialog/positionY", -1l);
122  if ( y >= 0 && x >= 0 && x < dx && y < dy)
123  {
124  this->Move(x, y);
125  }
126  else
127  {
128  this->Move(0, 44);
129  }
130 }
131 
133 {
134  wxConfigBase* config=wxConfigBase::Get();
135  wxSize sz = this->GetClientSize();
136  config->Write("/UserDefinedSequenceDialog/width", sz.GetWidth());
137  config->Write("/UserDefinedSequenceDialog/height", sz.GetHeight());
138  wxPoint ps = this->GetPosition();
139  config->Write("/UserDefinedSequenceDialog/positionX", ps.x);
140  config->Write("/UserDefinedSequenceDialog/positionY", ps.y);
141 }
142 
144 {
145  m_choice_user_define->Enable(m_radio_user_sequence->GetValue());
146  m_label_user_define->Enable(m_radio_user_sequence->GetValue());
148  m_text_external_file->Enable(m_radio_external->GetValue());
149  m_button_external_file->Enable(m_radio_external->GetValue());
150 }
151 
153 {
154  // update help text
155  const long id = e.GetSelection();
156  if (id >= 0 && id < m_userHelpTexts.size())
157  {
159  m_label_user_define->SetLabel(m_userHelpTexts[id]);
160  };
161 }
162 
164 {
165  wxFileDialog userOutputDlg(this, (m_isAssistantUserDefined ? _("Select user defined assistant") : _("Select user defined output")),
166  m_text_external_file->GetValue(), wxEmptyString, (m_isAssistantUserDefined ? _("User defined assistant|*.assistant") : _("User defined output|*.executor")),
167  wxFD_OPEN | wxFD_FILE_MUST_EXIST, wxDefaultPosition);
168  if (userOutputDlg.ShowModal() == wxID_OK)
169  {
170  m_text_external_file->SetValue(userOutputDlg.GetPath());
171  };
172 }
173 
175 {
176  if (m_radio_external->GetValue())
177  {
178  // check that a valid file was given
179  wxString filename = m_text_external_file->GetValue();
180  if (filename.IsEmpty())
181  {
182  wxMessageBox(_("Please provide a filename to the user defined sequence."),
183 #ifdef __WXMSW__
184  "PTBatcherGUI",
185 #else
186  wxEmptyString,
187 #endif
188  wxOK | wxOK_DEFAULT | wxICON_WARNING);
189  return;
190  };
191  if (!wxFileName::FileExists(filename))
192  {
193  wxMessageBox(wxString::Format(_("The file \"%s\" does not exists.\nPlease provide an existing file to the user defined sequence."), filename.c_str()),
194 #ifdef __WXMSW__
195  "PTBatcherGUI",
196 #else
197  wxEmptyString,
198 #endif
199  wxOK | wxOK_DEFAULT | wxICON_WARNING);
200  return;
201  };
202  }
203  EndModal(wxID_OK);
204 }
205 
207 {
208  if (m_radio_default->GetValue())
209  {
210  return wxEmptyString;
211  };
212  if (m_radio_user_sequence->GetValue())
213  {
214  if (m_choice_user_define->GetCount() > 0 && m_choice_user_define->GetSelection() != wxNOT_FOUND)
215  {
216  return m_userFileNames[m_choice_user_define->GetSelection()];
217  }
218  else
219  {
220  return wxEmptyString;
221  };
222  };
223  return m_text_external_file->GetValue();
224 }
225 
227 wxString GetDataPath()
228 {
229 #if defined __WXMSW__
230  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
231  exePath.RemoveLastDir();
232  const wxString huginRoot = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
233  return huginRoot + "share\\hugin\\data\\";
234 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
235  // initialize paths
236  {
237  wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
238  if (thePath.IsEmpty())
239  {
240  wxMessageBox(_("xrc directory not found in bundle"), _("Fatal Error"));
241  return wxEmptyString;
242  }
243  return thePath + "/";
244  }
245 #elif defined UNIX_SELF_CONTAINED_BUNDLE
246  // initialize paths
247  {
248  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
249  m_utilsBinDir = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
250  exePath.RemoveLastDir();
251  const wxString huginRoot = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
252  return huginRoot + "share/hugin/data/";
253  }
254 #else
255  // add the locale directory specified during configure
256  return INSTALL_DATA_DIR;
257 #endif
258 }
259 
261 {
262  wxArrayString files;
263  // search all .assistant files, do not follow links
264  wxDir::GetAllFiles(GetDataPath() + "assistant", &files, "*.assistant", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
265  wxDir::GetAllFiles(hugin_utils::GetUserAppDataDir(), &files, "*.assistant", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
266  FillUserDefinedChoice(files);
267 }
268 
270 {
271  wxArrayString files;
272  // search all .executor files, do not follow links
273  wxDir::GetAllFiles(GetDataPath() + "output", &files, "*.executor", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
274  wxDir::GetAllFiles(hugin_utils::GetUserAppDataDir(), &files, "*.executor", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
275  FillUserDefinedChoice(files);
276 }
277 
279 {
280  if (!files.IsEmpty())
281  {
282  for (auto file : files)
283  {
284  // read all files
285  wxFileInputStream inputStream(file);
286  if (inputStream.IsOk())
287  {
288  // read descriptions from file
289  wxFileConfig executorFile(inputStream);
290  wxString desc = HuginQueue::GetSettingStringTranslated(&executorFile, "/General/Description", wxEmptyString);
291  if (desc.IsEmpty())
292  {
293  desc = file;
294  };
295  wxString help = HuginQueue::GetSettingStringTranslated(&executorFile, "/General/Help", wxEmptyString);
296  if (help.IsEmpty())
297  {
298  help = wxString::Format(_("User defined sequence: %s"), file);
299  };
300  // add to wxChoice and remember help text
301  m_choice_user_define->AppendString(desc);
302  m_userFileNames.Add(file);
303  m_userHelpTexts.Add(help);
304  };
305  };
306  if (m_choice_user_define->GetCount() > 0)
307  {
308  m_choice_user_define->Select(0);
309  wxCommandEvent dummy;
310  dummy.SetInt(0);
312  };
313  };
314 }
implementation of huginApp Class
bool FileExists(const std::string &filename)
checks if file exists
Definition: utils.cpp:362
wxString GetDataPath()
return path to data directory, it depends on operating system
END_EVENT_TABLE()
void OnChangeUserDefinedChoice(wxCommandEvent &e)
wxString GetNewSequence()
returns the newly selected sequence
~ChangeUserDefinedSequenceDialog()
destructor, saves size and position
basic classes and function for queuing commands in wxWidgets
void FillUserDefinedChoice(const wxArrayString &files)
IMPEX double h[25][1024]
Definition: emor.cpp:169
Dialog for changing the user defined sequence.
const wxString GetSettingStringTranslated(wxConfigBase *setting, const wxString &name, const wxString defaultValue)
read a translated string from settings and remove all whitespaces
Definition: Executor.cpp:288
std::string GetUserAppDataDir()
returns the directory for user specific Hugin settings, e.g.
Definition: utils.cpp:497