Hugin trunk 0.1
Loading...
Searching...
No Matches
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#include "base_wx/wxutils.h"
33#if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
34#include "base_wx/platform.h"
35#endif
36
38{
39 // load our children. some children might need special
40 // initialization. this will be done later.
41 wxXmlResource::Get()->LoadDialog(this, parent, "change_user_defined_dialog");
42
43 m_radio_default = XRCCTRL(*this, "radio_default_sequence", wxRadioButton);
45 m_radio_user_sequence = XRCCTRL(*this, "radio_user_defined", wxRadioButton);
47 m_choice_user_define=XRCCTRL(*this, "choice_user_defined", wxChoice);
49 m_label_user_define = XRCCTRL(*this, "label_user_defined", wxStaticText);
50 m_label_user_define_filename = XRCCTRL(*this, "label_user_defined_filename", wxStaticText);
51 m_radio_external = XRCCTRL(*this, "radio_external_sequence", wxRadioButton);
53 m_text_external_file = XRCCTRL(*this, "text_external_file", wxTextCtrl);
54 m_text_external_file->AutoCompleteFileNames();
55 m_button_external_file = XRCCTRL(*this, "button_external_file", wxButton);
57
60 {
62 }
63 else
64 {
66 };
67 if (userDefinedSequence.IsEmpty())
68 {
69 m_radio_default->SetValue(true);
70 }
71 else
72 {
73 int index = m_userFileNames.Index(userDefinedSequence);
74 if (index == wxNOT_FOUND)
75 {
76 // user defined sequence not found in list
77 // so use external entry
78 m_radio_external->SetValue(true);
80 }
81 else
82 {
83 // item found in list
84 m_radio_user_sequence->SetValue(true);
85 m_choice_user_define->Select(index);
86 };
87 };
88 wxCommandEvent dummy;
90
91 //set parameters
92 hugin_utils::RestoreFramePosition(this, "UserDefinedSequenceDialog", true);
94}
95
100
102{
103 m_choice_user_define->Enable(m_radio_user_sequence->GetValue());
104 m_label_user_define->Enable(m_radio_user_sequence->GetValue());
106 m_text_external_file->Enable(m_radio_external->GetValue());
107 m_button_external_file->Enable(m_radio_external->GetValue());
108}
109
111{
112 // update help text
113 const long id = e.GetSelection();
114 if (id >= 0 && id < m_userHelpTexts.size())
115 {
118 };
119}
120
122{
123 wxFileDialog userOutputDlg(this, (m_isAssistantUserDefined ? _("Select user defined assistant") : _("Select user defined output")),
124 m_text_external_file->GetValue(), wxEmptyString, (m_isAssistantUserDefined ? _("User defined assistant|*.assistant") : _("User defined output|*.executor")),
126 if (userOutputDlg.ShowModal() == wxID_OK)
127 {
128 m_text_external_file->SetValue(userOutputDlg.GetPath());
129 };
130}
131
133{
134 if (m_radio_external->GetValue())
135 {
136 // check that a valid file was given
137 wxString filename = m_text_external_file->GetValue();
138 if (filename.IsEmpty())
139 {
140 hugin_utils::HuginMessageBox(_("Please provide a filename to the user defined sequence."), _("PTBatcherGUI"), wxOK | wxOK_DEFAULT | wxICON_WARNING, this);
141 return;
142 };
143 if (!wxFileName::FileExists(filename))
144 {
145 hugin_utils::HuginMessageBox(wxString::Format(_("The file \"%s\" does not exists.\nPlease provide an existing file to the user defined sequence."), filename),
146 _("PTBatcherGUI"), wxOK | wxOK_DEFAULT | wxICON_WARNING, this);
147 return;
148 };
149 }
151}
152
154{
155 if (m_radio_default->GetValue())
156 {
157 return wxEmptyString;
158 };
159 if (m_radio_user_sequence->GetValue())
160 {
161 if (m_choice_user_define->GetCount() > 0 && m_choice_user_define->GetSelection() != wxNOT_FOUND)
162 {
163 return m_userFileNames[m_choice_user_define->GetSelection()];
164 }
165 else
166 {
167 return wxEmptyString;
168 };
169 };
170 return m_text_external_file->GetValue();
171}
172
175{
176#if defined __WXMSW__
177 wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
178 exePath.RemoveLastDir();
180 return huginRoot + "share\\hugin\\data\\";
181#elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
182 // initialize paths
183 {
185 if (thePath.IsEmpty())
186 {
187 hugin_utils::HuginMessageBox(_("xrc directory not found in bundle"), _("PTBatcherGUI"), wxOK|wxICON_ERROR, wxGetActiveWindow());
188 return wxEmptyString;
189 }
190 return thePath + "/";
191 }
192#elif defined UNIX_SELF_CONTAINED_BUNDLE
193 // initialize paths
194 {
195 wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
196 exePath.RemoveLastDir();
198 return huginRoot + "share/hugin/data/";
199 }
200#else
201 // add the locale directory specified during configure
202 return INSTALL_DATA_DIR;
203#endif
204}
205
207{
208 wxArrayString files;
209 // search all .assistant files, do not follow links
210 wxDir::GetAllFiles(GetDataPath() + "assistant", &files, "*.assistant", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
211 wxDir::GetAllFiles(hugin_utils::GetUserAppDataDir(), &files, "*.assistant", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
213}
214
216{
217 wxArrayString files;
218 // search all .executor files, do not follow links
219 wxDir::GetAllFiles(GetDataPath() + "output", &files, "*.executor", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
220 wxDir::GetAllFiles(hugin_utils::GetUserAppDataDir(), &files, "*.executor", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
222}
223
225{
226 if (!files.IsEmpty())
227 {
228 for (auto file : files)
229 {
230 // read all files
232 if (inputStream.IsOk())
233 {
234 // read descriptions from file
237 if (desc.IsEmpty())
238 {
239 desc = file;
240 };
242 if (help.IsEmpty())
243 {
244 help = wxString::Format(_("User defined sequence: %s"), file);
245 };
246 // add to wxChoice and remember help text
247 m_choice_user_define->AppendString(desc);
248 m_userFileNames.Add(file);
250 };
251 };
252 if (m_choice_user_define->GetCount() > 0)
253 {
254 m_choice_user_define->Select(0);
255 wxCommandEvent dummy;
256 dummy.SetInt(0);
258 };
259 };
260}
wxString GetDataPath()
return path to data directory, it depends on operating system
basic classes and function for queuing commands in wxWidgets
~ChangeUserDefinedSequenceDialog()
destructor, saves size and position
ChangeUserDefinedSequenceDialog(wxWindow *parent, wxString xrcPrefix, wxString userDefinedSequence, bool assistantUserDefined)
Constructor, read from xrc ressource; restore last uses size and position.
wxString GetNewSequence()
returns the newly selected sequence
void OnChangeUserDefinedChoice(wxCommandEvent &e)
void FillUserDefinedChoice(const wxArrayString &files)
implementation of huginApp Class
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
int HuginMessageBox(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition wxutils.cpp:176
std::string GetUserAppDataDir()
returns the directory for user specific Hugin settings, e.g.
Definition utils.cpp:497
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename, const bool ignoreMaximize)
Definition wxutils.cpp:106
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename, const bool ignoreMaximize)
Definition wxutils.cpp:67
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41