Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[832b36]: src / hugin1 / ptbatcher / ProjectListBox.cpp Maximize Restore History

Download this file

ProjectListBox.cpp    428 lines (382 with data), 10.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
// -*- c-basic-offset: 4 -*-
/** @file ProjectListBox.cpp
*
* @brief Batch processor for Hugin with GUI
*
* @author Marko Kuder <marko.kuder@gmail.com>
*
* $Id: ProjectListBox.cpp 3322 2008-08-16 5:00:07Z mkuder $
*
* This program 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
* 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
*
*/
#include "ProjectListBox.h"
BEGIN_EVENT_TABLE(ProjectListBox, wxListCtrl)
EVT_LIST_ITEM_SELECTED(wxID_ANY, ProjectListBox::OnSelect)
EVT_LIST_ITEM_DESELECTED(wxID_ANY, ProjectListBox::OnDeselect)
EVT_LIST_COL_END_DRAG(wxID_ANY, ProjectListBox::OnColumnWidthChange)
END_EVENT_TABLE()
bool ProjectListBox::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
{
if (! wxListCtrl::Create(parent, id, pos, size, wxLC_REPORT | style) ) {
return false;
};
columns.Add(ID),
columns.Add(PROJECT);
columns.Add(PREFIX);
columns.Add(STATUS);
columns.Add(MODDATE);
columns.Add(FORMAT);
columns.Add(PROJECTION);
columns.Add(SIZE);
m_selected = -1;
this->InsertColumn(0,_("ID"));
this->InsertColumn(1,_("Project"));
this->InsertColumn(2,_("Output prefix"));
this->InsertColumn(3,_("Status"));
this->InsertColumn(4,_("Last modified"));
this->InsertColumn(5,_("Output format"));
this->InsertColumn(6,_("Projection"));
this->InsertColumn(7,_("Size"));
//get saved width
for( int i=0; i < GetColumnCount() ; i++ )
{
int width = wxConfigBase::Get()->Read(wxString::Format(wxT("/BatchList/ColumnWidth%d"), columns[i] ), -1);
if(width != -1)
SetColumnWidth(i, width);
}
return true;
}
//public methods:
void ProjectListBox::AppendProject(Project* project)
{
/*//already included
//path
//prefix
//modified
project->options.getOutputExtension() //std string
project->options.getFormatName( //std string
project->options.getProjection() //enum projectionFormat
project->options.getWidth()
project->options.getHeight()*/
/*//other possible columns
project->options.enblendOptions //std string
project->options.enfuseOptions //std string
project->options.outputMode //enum outputMode
project->options.featherWidth
project->options.gamma
project->options.getHFOV()
project->options.getVFOV()
project->options.hdrMergeMode //enum HDRMergeType
project->options.colorCorrection
project->options.hdrmergeOptions //std string
project->options.quality
project->options.blendMode //enum blendingMechanism*/
if(project->id < 0) //if we have a command-line application
{
int i=columns.Index(PROJECT); //we find the project column
if(i != wxNOT_FOUND)
{
if(i==0)
this->InsertItem(this->GetItemCount(),project->path);
else
{
this->InsertItem(this->GetItemCount(),_T(""));
this->SetItem(this->GetItemCount()-1,i,project->path);
}
}
else //we insert an empty line
this->InsertItem(this->GetItemCount(),_T(""));
}
else
{
if(columns.GetCount()>0)
{
this->InsertItem(this->GetItemCount(),this->GetAttributeString(columns[0],project));
for(unsigned int i=1; i<columns.GetCount(); i++)
this->SetItem(this->GetItemCount()-1,i,this->GetAttributeString(columns[i],project));
}
else //we have no columns?
this->InsertItem(this->GetItemCount(),_T(""));
}
}
void ProjectListBox::ChangePrefix(int index, wxString newPrefix)
{
if(columns.Index(PREFIX)!=wxNOT_FOUND)
this->SetItem(index,columns.Index(PREFIX),newPrefix);
}
void ProjectListBox::Deselect(int index)
{
SetItemState(index, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
m_selected=-1;
}
void ProjectListBox::Fill(Batch* batch)
{
m_batch=batch;
for(int i=0; i<m_batch->GetProjectCount(); i++)
AppendProject(m_batch->GetProject(i));
}
int ProjectListBox::GetIndex(int id)
{
int index=0;
while(index<this->GetItemCount())
{
if(GetText(index,0).Cmp(wxString::Format(_("%d"),id))==0)
return index;
index++;
}
return -1;
}
int ProjectListBox::GetProjectCountByPath(wxString path)
{
int count = 0;
for(int i=0; i<this->GetItemCount(); i++)
{
//wxMessageBox( path,GetText(i,0),wxOK | wxICON_INFORMATION );
if(path.Cmp(GetText(i,1))==0)
count++;
}
return count;
}
int ProjectListBox::GetProjectId(int index)
{
long id=-1;
if(!GetText(index,0).ToLong(&id))
wxMessageBox(_("Error, cannot convert id"),_("Error"));
return (int)id;
}
int ProjectListBox::GetSelectedIndex()
{
return m_selected;
}
wxString ProjectListBox::GetSelectedProject()
{
return GetText(m_selected,1);
}
Project::Target ProjectListBox::GetSelectedProjectTarget()
{
return m_batch->GetProject(m_selected)->target;
};
wxString ProjectListBox::GetSelectedProjectPrefix()
{
return GetText(m_selected,2);
}
wxString ProjectListBox::GetText(int row, int column)
{
wxListItem item;
item.SetId(row);
item.SetColumn(column);
item.SetMask(wxLIST_MASK_TEXT);
this->GetItem(item);
return item.GetText();
}
void ProjectListBox::ReloadProject(int index, Project* project)
{
for(unsigned int i=0; i<columns.GetCount(); i++)
this->SetItem(index,i,this->GetAttributeString(columns[i],project));
}
void ProjectListBox::Select(int index)
{
if(index>=0 && index<this->GetItemCount())
{
SetItemState(index,wxLIST_STATE_SELECTED,wxLIST_STATE_SELECTED);
m_selected=index;
};
}
void ProjectListBox::SetMissing(int index)
{
for(int i=0; i< this->GetColumnCount(); i++)
{
if(columns[i]==STATUS)
this->SetItem(index,i,_("File missing"));
if(columns[i]!=ID && columns[i]!=PROJECT && columns[i]!=PREFIX)
this->SetItem(index,i,_T(""));
}
}
void ProjectListBox::SwapProject(int index)
{
wxString temp;
for(int i=0; i<GetColumnCount(); i++)
{
temp = GetText(index,i);
SetItem(index,i,GetText(index+1,i));
SetItem(index+1,i,temp);
}
}
bool ProjectListBox::UpdateStatus(int index, Project* project)
{
bool change = false;
wxString newStatus;
for(int i=0; i< this->GetColumnCount(); i++)
{
if(columns[i]==STATUS)
{
newStatus = project->GetStatusText();
if(newStatus.Cmp(GetText(index,i))!=0)
{
change = true;
this->SetItem(index,i,newStatus);
}
}
}
return change;
}
//private methods:
wxString ProjectListBox::GetAttributeString(int i, Project* project)
{
wxString str;
switch(i){
case 0:
return wxString::Format(_T("%d"),project->id);
case 1:
return project->path;
case 2:
if(project->target==Project::STITCHING)
{
return project->prefix;
}
else
{
return _("Assistant");
};
case 7:
return project->GetStatusText(); //all following cases default to an empty string if file is missing
case 3:
if(project->status!=Project::MISSING)
return project->modDate.FormatDate()+_T(", ")+project->modDate.FormatTime();
case 4:
if(project->status!=Project::MISSING)
{
//str = wxString::FromAscii(project->options.getFormatName(project->options.outputFormat).c_str());
//str = str+wxT(" (.")+wxString::FromAscii(project->options.outputImageType.c_str())+wxT(")");
str = GetLongerFormatName(project->options.outputImageType);
str = str+wxT(" (.")+wxString::FromAscii(project->options.outputImageType.c_str())+wxT(")");
return str;
}
case 5:
if(project->status!=Project::MISSING)
{
pano_projection_features proj;
if (panoProjectionFeaturesQuery(project->options.getProjection(), &proj))
{
wxString str2(proj.name, wxConvLocal);
return wxGetTranslation(str2);
}
else
return _T("");
};
case 6:
if(project->status!=Project::MISSING)
{
str = wxString() << project->options.getWidth();
str = str+_T("x");
str = str << project->options.getHeight();
return str;
}
default:
return _T("");
}
}
wxString ProjectListBox::GetLongerFormatName(std::string str)
{
if(str=="tif")
return _T("TIFF");
else if(str=="jpg")
return _T("JPEG");
else if(str=="png")
return _T("PNG");
else if(str=="exr")
return _T("EXR");
else
return _T("");
}
void ProjectListBox::OnDeselect(wxListEvent &event)
{
m_selected = -1;
}
void ProjectListBox::OnColumnWidthChange(wxListEvent &event)
{
int col = event.GetColumn();
wxConfigBase::Get()->Write(wxString::Format(wxT("/BatchList/ColumnWidth%d"),columns[col]), GetColumnWidth(col));
}
void ProjectListBox::OnSelect(wxListEvent &event)
{
m_selected = ((wxListEvent)event).GetIndex();
}
const wxString ProjectListBox::fileFormat[] = {_T("JPEG"),
_T("PNG"),
_T("TIFF"),
_T("TIFF_m"),
_T("TIFF_mask"),
_T("TIFF_multilayer"),
_T("TIFF_multilayer_mask"),
_T("PICT"),
_T("PSD"),
_T("PSD_m"),
_T("PSD_mask"),
_T("PAN"),
_T("IVR"),
_T("IVR_java"),
_T("VRML"),
_T("QTVR"),
_T("HDR"),
_T("HDR_m"),
_T("EXR"),
_T("EXR_m"),
_T("FILEFORMAT_NULL")
};
const wxString ProjectListBox::outputMode[] = {
_T("OUTPUT_LDR"),
_T("OUTPUT_HDR")
};
const wxString ProjectListBox::HDRMergeType[] = {
_T("HDRMERGE_AVERAGE"),
_T("HDRMERGE_DEGHOST")
};
const wxString ProjectListBox::blendingMechanism[] = {
_T("NO_BLEND"),
_T("PTBLENDER_BLEND"),
_T("ENBLEND_BLEND"),
_T("SMARTBLEND_BLEND"),
_T("PTMASKER_BLEND")
};
const wxString ProjectListBox::colorCorrection[] = {
_T("NONE"),
_T("BRIGHTNESS_COLOR"),
_T("BRIGHTNESS"),
_T("COLOR")
};
IMPLEMENT_DYNAMIC_CLASS(ProjectListBox, wxListCtrl)
ProjectListBoxXmlHandler::ProjectListBoxXmlHandler()
: wxListCtrlXmlHandler()
{
AddWindowStyles();
}
wxObject *ProjectListBoxXmlHandler::DoCreateResource()
{
XRC_MAKE_INSTANCE(cp, ProjectListBox)
cp->Create(m_parentAsWindow,
GetID(),
GetPosition(), GetSize(),
GetStyle(wxT("style")),
GetName());
SetupWindow( cp);
return cp;
}
bool ProjectListBoxXmlHandler::CanHandle(wxXmlNode *node)
{
return IsOfClass(node, wxT("ProjectListBox"));
}
IMPLEMENT_DYNAMIC_CLASS(ProjectListBoxXmlHandler, wxListCtrlXmlHandler)