Hugin trunk 0.1
Loading...
Searching...
No Matches
ChangeImageVariableDialog.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 "panoinc.h"
29#include "hugin/huginApp.h"
30#include "base_wx/platform.h"
31#include "base_wx/wxutils.h"
32#include "panodata/ParseExp.h"
33#include <iostream>
34
36{
37 // load our children. some children might need special
38 // initialization. this will be done later.
39 wxXmlResource::Get()->LoadDialog(this, parent, "image_variables_change_dialog");
40
41 m_textInput = XRCCTRL(*this, "change_variable_text", wxTextCtrl);
42 m_presetsList = XRCCTRL(*this, "change_variable_choice", wxChoice);
43 m_textAttrInactive = wxTextAttr(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
44 m_textAttrDefault = wxTextAttr(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
45 hugin_utils::RestoreFramePosition(this, "ChangeImageVariablesDialog");
46 SetExpression(wxConfig::Get()->Read("/ChangeImageVariablesDialog/LastExpression", wxEmptyString));
47 m_pano=pano;
48 const wxFileName filename(hugin_utils::GetUserAppDataDir(), "expressions.ini");
49 // if no expressions.ini exits in users data dir copy example from global data dir
50 if (!filename.FileExists())
51 {
52 const wxFileName globalFilename(hugin_utils::GetDataDir(), "expressions.ini");
53 if (globalFilename.FileExists())
54 {
55 wxCopyFile(globalFilename.GetFullPath(), filename.GetFullPath());
56 };
57 };
58 m_presets = new wxFileConfig(wxEmptyString, wxEmptyString, filename.GetFullPath());
59 wxString name;
60 long index;
61 if (m_presets->GetFirstGroup(name, index))
62 {
63 m_presetsList->AppendString(name);
64 while (m_presets->GetNextGroup(name, index))
65 {
66 m_presetsList->AppendString(name);
67 };
68 };
69 Bind(wxEVT_BUTTON, &ImageVariablesExpressionDialog::OnLoad, this, XRCID("change_variable_load"));
70 Bind(wxEVT_BUTTON, &ImageVariablesExpressionDialog::OnSave, this, XRCID("change_variable_save"));
71 Bind(wxEVT_BUTTON, &ImageVariablesExpressionDialog::OnDelete, this, XRCID("change_variable_delete"));
72 Bind(wxEVT_BUTTON, &ImageVariablesExpressionDialog::OnTest, this, XRCID("change_variable_test"));
73 Bind(wxEVT_TEXT, &ImageVariablesExpressionDialog::OnTextChange, this, XRCID("change_variable_text"));
75};
76
82
84{
85 if (!s.IsEmpty())
86 {
87 m_textInput->SetValue(s);
88 }
89 else
90 {
91 m_textInput->Clear();
92 };
93 m_textInput->MarkDirty();
94 // update colors
95 wxCommandEvent dummy;
97};
98
100{
101 return std::string(m_textInput->GetValue().mb_str(wxConvLocal));
102}
103
105{
106 wxConfigBase* config = wxConfig::Get();
107 config->Write("/ChangeImageVariablesDialog/LastExpression", m_textInput->GetValue());
108 hugin_utils::StoreFramePosition(this, "ChangeImageVariablesDialog");
109 config->Flush();
111}
112
114{
115 if (m_presetsList->GetSelection() != wxNOT_FOUND)
116 {
117 wxString s = m_presets->Read(m_presetsList->GetString(m_presetsList->GetSelection()) + "/Expression", wxEmptyString);
118 if (!s.IsEmpty())
119 {
121 }
122 else
123 {
124 wxBell();
125 };
126 }
127 else
128 {
129 wxBell();
130 };
131}
132
134{
135 wxTextEntryDialog dlg(this, _("Input name for new preset"), _("Save preset"));
136 if (dlg.ShowModal() == wxID_OK)
137 {
138 wxString s = dlg.GetValue();
139 // replace slashes with underscore, slashes have a special meaning in wxFileConfig
140 s.Replace("/", "_", true);
141 s = s.Trim(true).Trim(false);
142 if (s.IsEmpty())
143 {
144 wxBell();
145 return;
146 }
147 bool newPreset = true;
148 if (m_presets->HasGroup(s))
149 {
150 if (hugin_utils::HuginMessageBox(wxString::Format(_("Preset with name \"%s\" already exists.\nShould this preset be overwritten?"), s), _("Hugin"),
152 {
153 return;
154 };
155 newPreset = false;
156 }
157 // now save
158 m_presets->Write(s + "/Expression", m_textInput->GetValue());
159 m_presets->Flush();
160 if (newPreset)
161 {
162 // add to selection list
163 m_presetsList->AppendString(s);
164 m_presetsList->Select(m_presetsList->GetCount() - 1);
165 };
166 Layout();
167 };
168}
169
171{
172 if (m_presetsList->GetSelection() != wxNOT_FOUND)
173 {
174 const int selection = m_presetsList->GetSelection();
175 m_presets->DeleteGroup(m_presetsList->GetString(selection));
176 m_presets->Flush();
177 m_presetsList->Delete(selection);
178 Layout();
179 Update();
180 }
181 else
182 {
183 wxBell();
184 };
185}
186
188{
190 std::ostringstream status, error;
192 wxDialog dlg;
193 if (wxXmlResource::Get()->LoadDialog(&dlg, this, "log_dialog"))
194 {
196 if (error.str().empty())
197 {
198 // no error, show status
199 XRCCTRL(dlg, "log_dialog_text", wxTextCtrl)->SetValue(wxString(status.str().c_str(), wxConvLocal));
200 dlg.SetTitle(_("Result of expression parsing"));
201 }
202 else
203 {
204 // show errors
205 XRCCTRL(dlg, "log_dialog_text", wxTextCtrl)->SetValue(wxString(error.str().c_str(), wxConvLocal));
206 dlg.SetTitle(_("Errors during expression parsing"));
207 };
208 dlg.ShowModal();
210 };
211}
212
214{
215 if (!m_textInput->IsModified())
216 {
217 return;
218 };
219 bool newLine = true;
220 size_t commentStart=-1;
221 // reset style
222 m_textInput->SetStyle(0, m_textInput->GetLastPosition(), m_textAttrDefault);
223 for (size_t i = 0; i < m_textInput->GetLastPosition(); ++i)
224 {
225 const wxString s = m_textInput->GetRange(i, i + 1);
226 if (s == " ")
227 {
228 continue;
229 };
230 if (newLine && s == "#" && commentStart == -1)
231 {
232 commentStart = i;
233 continue;
234 };
235 newLine = false;
236 if (s == "\n")
237 {
238 if (commentStart != -1)
239 {
241 };
242 newLine = true;
243 commentStart = -1;
244 continue;
245 };
246 };
247 if (commentStart != -1)
248 {
249 m_textInput->SetStyle(commentStart, m_textInput->GetLastPosition(), m_textAttrInactive);
250 };
251}
Definition of dialog to edit image variables by parsing an expression.
function to parse expressions from strings
Model for a panorama.
Definition Panorama.h:153
Panorama duplicate() const
duplicate the panorama
void OnSave(wxCommandEvent &e)
saves the current expression as preset
ImageVariablesExpressionDialog(wxWindow *parent, HuginBase::Panorama *pano)
Constructor, read from xrc ressource; restore last uses settings and position.
void OnTest(wxCommandEvent &e)
tests the current expression
void OnOk(wxCommandEvent &e)
Saves current expression when closing dialog with Ok.
void OnTextChange(wxCommandEvent &e)
text change event, used to format text
void OnLoad(wxCommandEvent &e)
loads the selected preset into control
void OnDelete(wxCommandEvent &e)
deletes the seletected preset
~ImageVariablesExpressionDialog()
destructor, saves position
implementation of huginApp Class
void PanoParseExpression(HuginBase::Panorama &pano, const std::string &expression, std::ostream &statusStream, std::ostream &errorStream)
parses the given expression and apply the changes to the Panorama
Definition ParseExp.cpp:768
int HuginMessageBox(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition wxutils.cpp:176
std::string GetDataDir()
returns the full path to the data directory
Definition utils.cpp:441
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
include file for the hugin project
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