2
* stringKeyFrameDialog.cpp - String value keyframe selection dialog
3
* Copyright (C) 2013, D Haley
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
// -*- C++ -*- generated by wxGlade 0.6.5 on Sat Sep 22 21:13:08 2012
20
#include "stringKeyFrameDialog.h"
22
#include "common/translation.h"
29
// begin wxGlade: ::extracode
41
StringKeyFrameDialog::StringKeyFrameDialog(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
42
wxDialog(parent, id, title, pos, size, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
44
// begin wxGlade: StringKeyFrameDialog::StringKeyFrameDialog
45
labelStartFrame = new wxStaticText(this, wxID_ANY, wxTRANS("Start Frame: "));
46
textStartFrame = new wxTextCtrl(this, ID_TEXT_START_FRAME, wxEmptyString);
47
radioFromFile = new wxRadioButton(this, ID_RADIO_FROM_FILE, wxTRANS("From File"));
48
textFilename = new wxTextCtrl(this, ID_TEXT_FROM_FILE, wxEmptyString);
49
btnChooseFile = new wxButton(this, wxID_OPEN, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
50
radioFromTable = new wxRadioButton(this, ID_RADIO_FROM_TABLE, wxTRANS("From Table"));
51
gridStrings = new wxGrid(this, ID_GRID_STRINGS);
52
btnStringAdd = new wxButton(this, wxID_ADD, wxEmptyString);
53
btnRemove = new wxButton(this, wxID_REMOVE, wxEmptyString);
54
btnCancel = new wxButton(this, wxID_CANCEL, wxEmptyString);
55
btnOK = new wxButton(this, wxID_OK, wxEmptyString);
63
startFrameOK=filenameOK=false;
65
stream_cast(s,startFrame);
66
textStartFrame->SetValue(wxStr(s));
68
radioFromFile->SetValue(true);
70
dataSourceFromFile=radioFromFile->GetValue();
74
BEGIN_EVENT_TABLE(StringKeyFrameDialog, wxDialog)
75
// begin wxGlade: StringKeyFrameDialog::event_table
76
EVT_TEXT(ID_TEXT_START_FRAME, StringKeyFrameDialog::OnTextStart)
77
EVT_RADIOBUTTON(ID_RADIO_FROM_FILE, StringKeyFrameDialog::OnFileRadio)
78
EVT_TEXT(ID_TEXT_FROM_FILE, StringKeyFrameDialog::OnTextFilename)
79
EVT_BUTTON(wxID_OPEN, StringKeyFrameDialog::OnBtnChooseFile)
80
EVT_RADIOBUTTON(ID_RADIO_FROM_TABLE, StringKeyFrameDialog::OnTableRadio)
81
EVT_GRID_CMD_CELL_CHANGE(ID_GRID_STRINGS, StringKeyFrameDialog::OnGridCellChange)
82
EVT_GRID_CMD_EDITOR_SHOWN(ID_GRID_STRINGS, StringKeyFrameDialog::OnGridEditorShown)
83
EVT_BUTTON(wxID_ADD, StringKeyFrameDialog::OnBtnAdd)
84
EVT_BUTTON(wxID_REMOVE, StringKeyFrameDialog::OnBtnRemove)
88
size_t StringKeyFrameDialog::getStartFrame() const
94
void StringKeyFrameDialog::buildGrid()
96
gridStrings->BeginBatch();
98
if(gridStrings->GetNumberCols())
99
gridStrings->DeleteCols(0,gridStrings->GetNumberCols());
100
if(gridStrings->GetNumberRows())
101
gridStrings->DeleteRows(0,gridStrings->GetNumberRows());
103
gridStrings->AppendCols(2);
104
gridStrings->SetColLabelValue(0,wxTRANS("Frame"));
105
gridStrings->SetColLabelValue(1,wxTRANS("Value"));
107
gridStrings->AppendRows(valueStrings.size());
109
wxGridCellAttr *readOnlyColAttr=new wxGridCellAttr;
110
readOnlyColAttr->SetReadOnly(true);
111
gridStrings->SetColAttr(0,readOnlyColAttr);
113
for(size_t ui=0;ui<valueStrings.size();ui++)
116
stream_cast(pos,ui+startFrame);
118
//set the frame-value pair
119
gridStrings->SetCellValue(ui,0,wxStr(pos));
120
gridStrings->SetCellValue(ui,1,wxStr(valueStrings[ui]));
122
gridStrings->EndBatch();
125
bool StringKeyFrameDialog::getStrings(vector<string> &res) const
127
if(dataSourceFromFile)
129
vector<vector<string> > dataVec;
130
if(loadTextStringData(dataFilename.c_str(), dataVec,"\t"))
133
res.reserve(dataVec.size());
134
for(size_t ui=0;ui<dataVec.size();ui++)
136
if(dataVec[ui].size())
137
res.push_back(dataVec[ui][0]);
149
void StringKeyFrameDialog::OnTextStart(wxCommandEvent &event)
151
startFrameOK=validateTextAsStream(textStartFrame,startFrame);
156
void StringKeyFrameDialog::OnFileRadio(wxCommandEvent &event)
158
dataSourceFromFile=radioFromFile->GetValue();
159
if(dataSourceFromFile)
161
//Disable grid & enable text box
162
gridStrings->Enable(false);
163
textFilename->Enable(true);
164
btnChooseFile->Enable(true);
168
//Enable grid & disable text box
169
gridStrings->Enable(true);
170
textFilename->Enable(false);
171
btnChooseFile->Enable(false);
175
void StringKeyFrameDialog::OnTableRadio(wxCommandEvent &event)
177
dataSourceFromFile=!radioFromTable->GetValue();
178
if(dataSourceFromFile)
180
//Disable grid & enable text box
181
gridStrings->Enable(false);
182
textFilename->Enable(true);
183
btnChooseFile->Enable(true);
187
//Enable grid & disable text box
188
gridStrings->Enable(true);
189
textFilename->Enable(false);
190
btnChooseFile->Enable(false);
193
void StringKeyFrameDialog::OnTextFilename(wxCommandEvent &event)
195
if(!wxFileExists(textFilename->GetValue()))
197
textFilename->SetBackgroundColour(*wxCYAN);
199
dataFilename.clear();
203
textFilename->SetBackgroundColour(wxNullColour);
205
dataFilename=stlStr(textFilename->GetValue());
211
void StringKeyFrameDialog::updateOKButton()
216
if(dataSourceFromFile)
219
isOK&=(bool)(valueStrings.size());
224
void StringKeyFrameDialog::OnGridCellChange(wxGridEvent &event)
227
s=stlStr(gridStrings->GetCellValue(event.GetRow(),event.GetCol()));
228
valueStrings[event.GetRow()] = s;
231
void StringKeyFrameDialog::OnGridEditorShown(wxGridEvent &event)
234
wxLogDebug(wxT("Event handler (StringKeyFrameDialog::OnGridEditorShown) not implemented yet")); //notify the user that he hasn't implemented the event handler yet
237
void StringKeyFrameDialog::OnBtnChooseFile(wxCommandEvent &event)
239
//Pop up a directory dialog, to choose the base path for the new folder
240
wxFileDialog *wxD = new wxFileDialog(this,wxTRANS("Select text file..."), wxT(""),
241
wxT(""),wxTRANS("Text files (*.txt)|*.txt;|All Files (*)|*"),wxFD_OPEN|wxFD_FILE_MUST_EXIST);
244
res = wxD->ShowModal();
246
while(res != wxID_CANCEL)
248
//If dir exists, exit
249
if(wxFileExists(wxD->GetPath()))
252
res=wxD->ShowModal();
255
//User aborted directory choice.
262
textFilename->SetValue(wxD->GetPath());
267
void StringKeyFrameDialog::OnBtnAdd(wxCommandEvent &event)
269
wxMouseState wxm = wxGetMouseState();
271
valueStrings.resize(valueStrings.size() + 5,"");
272
else if (wxm.CmdDown())
273
valueStrings.resize(valueStrings.size() + 10,"");
275
valueStrings.push_back("");
280
void StringKeyFrameDialog::OnBtnRemove(wxCommandEvent &event)
282
if(!gridStrings->GetNumberRows())
284
// Whole selected rows.
285
const wxArrayInt& rows(gridStrings->GetSelectedRows());
286
for (size_t i = rows.size(); i--; )
288
valueStrings.erase(valueStrings.begin() + rows[i],
289
valueStrings.begin()+rows[i]+1);
296
//Obtain the IDs of the selected rows, or partially selected rows
297
wxGridCellCoordsArray selectedRows = gridStrings->GetSelectedCells();
299
wxGridCellCoordsArray arrayTL(gridStrings->GetSelectionBlockTopLeft());
300
wxGridCellCoordsArray arrayBR(gridStrings->GetSelectionBlockBottomRight());
302
//This is an undocumented class AFAIK. :(
303
if(arrayTL.Count() && arrayBR.Count())
305
//Grab the coordinates f the selection block,
306
// top left (TL) and bottom right (BR)
307
wxGridCellCoords coordTL = arrayTL.Item(0);
308
wxGridCellCoords coordBR = arrayBR.Item(0);
310
size_t rows = coordBR.GetRow() - coordTL.GetRow()+1;
312
ASSERT(coordTL.GetRow()+rows-1<valueStrings.size());
313
//work out which rows we want to delete
314
valueStrings.erase(valueStrings.begin() + coordTL.GetRow(),
315
valueStrings.begin()+coordTL.GetRow() + rows);
320
rowToKill=gridStrings->GetGridCursorRow();
321
ASSERT(rowToKill<valueStrings.size());
322
valueStrings.erase(valueStrings.begin()+rowToKill,
323
valueStrings.begin()+rowToKill+1);
329
//update user interface
336
// wxGlade: add StringKeyFrameDialog event handlers
339
void StringKeyFrameDialog::set_properties()
341
// begin wxGlade: StringKeyFrameDialog::set_properties
342
SetTitle(wxTRANS("String Keyframes"));
343
SetSize(wxSize(542, 412));
344
SetToolTip(wxTRANS("Frame at which to start string sequence"));
345
textStartFrame->SetToolTip(wxTRANS("Frame offset for data start"));
346
textFilename->SetToolTip(wxTRANS("File to use as string data source, one value per row"));
347
btnChooseFile->SetToolTip(wxTRANS("Select file to use as data source"));
348
radioFromTable->SetToolTip(wxTRANS("Use table below for data source"));
349
gridStrings->CreateGrid(0, 2);
350
gridStrings->SetColLabelValue(0, wxTRANS("Frame"));
351
gridStrings->SetColSize(0, 1);
352
gridStrings->SetColLabelValue(1, wxTRANS("Value"));
353
gridStrings->SetColSize(1, 3);
354
btnStringAdd->SetToolTip(wxTRANS("Add new data rows to table, hold shift/cmd to insert multiple rows"));
355
btnRemove->SetToolTip(wxTRANS("Remove selected strings from table"));
356
btnCancel->SetToolTip(wxTRANS("Abort value selection and return to previous window"));
357
btnOK->SetToolTip(wxTRANS("Accept data values"));
362
void StringKeyFrameDialog::do_layout()
364
// begin wxGlade: StringKeyFrameDialog::do_layout
365
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
366
wxBoxSizer* footerSizer = new wxBoxSizer(wxHORIZONTAL);
367
wxBoxSizer* gridAreaSizer = new wxBoxSizer(wxHORIZONTAL);
368
wxBoxSizer* gridButtonSizer = new wxBoxSizer(wxVERTICAL);
369
wxBoxSizer* fromFileSizer = new wxBoxSizer(wxHORIZONTAL);
370
wxBoxSizer* startFrameSizer = new wxBoxSizer(wxHORIZONTAL);
371
startFrameSizer->Add(labelStartFrame, 0, wxALIGN_CENTER_VERTICAL, 0);
372
startFrameSizer->Add(textStartFrame, 1, wxLEFT|wxALIGN_CENTER_VERTICAL, 6);
373
startFrameSizer->Add(20, 20, 1, 0, 0);
374
mainSizer->Add(startFrameSizer, 0, wxALL|wxEXPAND, 6);
375
fromFileSizer->Add(radioFromFile, 0, wxALIGN_CENTER_VERTICAL, 0);
376
fromFileSizer->Add(textFilename, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 6);
377
fromFileSizer->Add(btnChooseFile, 0, wxLEFT|wxRIGHT, 6);
378
mainSizer->Add(fromFileSizer, 0, wxALL|wxEXPAND, 6);
379
mainSizer->Add(radioFromTable, 0, wxLEFT, 6);
380
gridAreaSizer->Add(gridStrings, 1, wxALL|wxEXPAND, 5);
381
gridButtonSizer->Add(btnStringAdd, 0, wxBOTTOM, 5);
382
gridButtonSizer->Add(btnRemove, 0, 0, 0);
383
gridAreaSizer->Add(gridButtonSizer, 0, wxRIGHT|wxEXPAND, 5);
384
mainSizer->Add(gridAreaSizer, 1, wxEXPAND, 0);
385
footerSizer->Add(20, 20, 1, 0, 0);
386
footerSizer->Add(btnCancel, 0, wxALL, 5);
387
footerSizer->Add(btnOK, 0, wxALL, 5);
388
mainSizer->Add(footerSizer, 0, wxEXPAND, 0);