Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProjectListBox.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
27 #ifdef _WIN32
28 #include "wx/msw/wrapwin.h"
29 #endif
30 #include "ProjectListBox.h"
31 
32 enum
33 {
34  ID_CHANGE_PREFIX=wxID_HIGHEST+200,
35  ID_RESET_PROJECT=wxID_HIGHEST+201,
36  ID_EDIT_PROJECT=wxID_HIGHEST+202,
37  ID_REMOVE_PROJECT=wxID_HIGHEST+203,
38  ID_CHANGE_USER_DEFINED=wxID_HIGHEST+204
39 };
40 
41 BEGIN_EVENT_TABLE(ProjectListBox, wxListCtrl)
42  EVT_LIST_COL_END_DRAG(wxID_ANY, ProjectListBox::OnColumnWidthChange)
43  EVT_CONTEXT_MENU(ProjectListBox::OnContextMenu)
44  EVT_MENU(ID_CHANGE_PREFIX, ProjectListBox::OnChangePrefix)
45  EVT_MENU(ID_RESET_PROJECT, ProjectListBox::OnResetProject)
46  EVT_MENU(ID_EDIT_PROJECT, ProjectListBox::OnEditProject)
47  EVT_MENU(ID_REMOVE_PROJECT, ProjectListBox::OnRemoveProject)
48  EVT_MENU(ID_CHANGE_USER_DEFINED, ProjectListBox::OnChangeUserDefined)
49  EVT_CHAR(ProjectListBox::OnChar)
51 
52 bool ProjectListBox::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
53 {
54  if (! wxListCtrl::Create(parent, id, pos, size, wxLC_REPORT | style) )
55  {
56  return false;
57  };
58  columns.Add(ID);
59  columns.Add(PROJECT);
60  columns.Add(PREFIX);
61  columns.Add(STATUS);
62  columns.Add(MODDATE);
63  columns.Add(FORMAT);
64  columns.Add(PROJECTION);
65  columns.Add(SIZE);
66  columns.Add(USERDEFINEDSEQUENCE);
67 
68  this->InsertColumn(0,_("ID"));
69  this->InsertColumn(1,_("Project"));
70  this->InsertColumn(2,_("Output prefix"));
71  this->InsertColumn(3,_("Status"));
72  this->InsertColumn(4,_("Last modified"));
73  this->InsertColumn(5,_("Output format"));
74  this->InsertColumn(6,_("Projection"));
75  this->InsertColumn(7,_("Size"));
76  this->InsertColumn(8, _("User defined sequence"));
77 
78  //get saved width
79  for( int i=0; i < GetColumnCount() ; i++ )
80  {
81  int width = wxConfigBase::Get()->Read(wxString::Format(wxT("/BatchList/ColumnWidth%d"), columns[i] ), -1);
82  if(width != -1)
83  {
84  SetColumnWidth(i, width);
85  }
86  }
87  return true;
88 }
89 
90 //public methods:
91 
93 {
94  //if we have a command-line application
95  if(project->id < 0)
96  {
97  int i=columns.Index(PROJECT); //we find the project column
98  if(i != wxNOT_FOUND)
99  {
100  if(i==0)
101  {
102  this->InsertItem(this->GetItemCount(),project->path);
103  }
104  else
105  {
106  this->InsertItem(this->GetItemCount(),_T(""));
107  this->SetItem(this->GetItemCount()-1,i,project->path);
108  }
109  }
110  else //we insert an empty line
111  {
112  this->InsertItem(this->GetItemCount(),_T(""));
113  }
114  }
115  else
116  {
117  if(columns.GetCount()>0)
118  {
119  this->InsertItem(this->GetItemCount(),this->GetAttributeString(columns[0],project));
120  for(unsigned int i=1; i<columns.GetCount(); i++)
121  {
122  this->SetItem(this->GetItemCount()-1,i,this->GetAttributeString(columns[i],project));
123  }
124  }
125  else //we have no columns?
126  {
127  this->InsertItem(this->GetItemCount(),_T(""));
128  }
129  }
130 }
131 
132 void ProjectListBox::ChangePrefix(int index, wxString newPrefix)
133 {
134  int colIndex=columns.Index(PREFIX);
135  if(colIndex!=wxNOT_FOUND)
136  {
137  Project* project=m_batch->GetProject(index);
138  this->SetItem(index,colIndex,this->GetAttributeString(colIndex,project));
139  }
140 }
141 
142 void ProjectListBox::ChangeUserDefined(int index, wxString newUserDefined)
143 {
144  int colIndex = columns.Index(USERDEFINEDSEQUENCE);
145  if (colIndex != wxNOT_FOUND)
146  {
147  Project* project = m_batch->GetProject(index);
148  this->SetItem(index, colIndex, this->GetAttributeString(colIndex, project));
149  }
150 }
151 
153 {
154  SetItemState(index, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
155 }
156 
158 {
159  m_batch=batch;
160  for(int i=0; i<m_batch->GetProjectCount(); i++)
161  {
163  }
164 }
165 
167 {
168  int index=0;
169  while(index<this->GetItemCount())
170  {
171  if(GetText(index,0).Cmp(wxString::Format(_("%d"),id))==0)
172  {
173  return index;
174  }
175  index++;
176  }
177  return -1;
178 }
179 
181 {
182  int count = 0;
183  for(int i=0; i<this->GetItemCount(); i++)
184  {
185  if(path.Cmp(GetText(i,1))==0)
186  {
187  count++;
188  }
189  }
190  return count;
191 }
192 
194 {
195  long id=-1;
196  if(!GetText(index,0).ToLong(&id))
197  {
198  wxMessageBox(_("Error, cannot convert id"),_("Error"));
199  }
200  return (int)id;
201 }
202 
204 {
205  HuginBase::UIntSet selected;
206  for (int i = 0; i<GetItemCount(); i++)
207  {
208  if (GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED)
209  {
210  selected.insert(i);
211  };
212  };
213  return selected;
214 }
215 
216 wxString ProjectListBox::GetText(int row, int column)
217 {
218  wxListItem item;
219  item.SetId(row);
220  item.SetColumn(column);
221  item.SetMask(wxLIST_MASK_TEXT);
222  this->GetItem(item);
223  return item.GetText();
224 }
225 
226 void ProjectListBox::ReloadProject(int index, Project* project)
227 {
228  for(unsigned int i=0; i<columns.GetCount(); i++)
229  {
230  this->SetItem(index,i,this->GetAttributeString(columns[i],project));
231  }
232 }
233 
234 void ProjectListBox::Select(int index)
235 {
236  if(index>=0 && index<this->GetItemCount())
237  {
238  SetItemState(index,wxLIST_STATE_SELECTED,wxLIST_STATE_SELECTED);
239  };
240 }
241 
243 {
244  for(int i=0; i< this->GetColumnCount(); i++)
245  {
246  if(columns[i]==STATUS)
247  {
248  this->SetItem(index,i,_("File missing"));
249  }
250  if(columns[i]!=ID && columns[i]!=PROJECT && columns[i]!=PREFIX && columns[i]!=USERDEFINEDSEQUENCE)
251  {
252  this->SetItem(index,i,_T(""));
253  }
254  }
255 }
256 
258 {
259  wxString temp;
260  for(int i=0; i<GetColumnCount(); i++)
261  {
262  temp = GetText(index,i);
263  SetItem(index,i,GetText(index+1,i));
264  SetItem(index+1,i,temp);
265  }
266 }
267 
268 bool ProjectListBox::UpdateStatus(int index, Project* project)
269 {
270  bool change = false;
271  wxString newStatus;
272  for(int i=0; i< this->GetColumnCount(); i++)
273  {
274  if(columns[i]==STATUS)
275  {
276  newStatus = project->GetStatusText();
277  if(newStatus.Cmp(GetText(index,i))!=0)
278  {
279  change = true;
280  this->SetItem(index,i,newStatus);
281  }
282  }
283  }
284  return change;
285 }
286 
287 //private methods:
288 
290 {
291  wxString str;
292  switch(i)
293  {
294  case 0:
295  return wxString::Format(_T("%ld"),project->id);
296  case 1:
297  return project->path;
298  case 2:
299  if(project->target==Project::STITCHING)
300  {
301  //make prefix relative to project path
302  wxFileName prefix(project->prefix);
303  wxFileName projectFile(project->path);
304  prefix.MakeRelativeTo(projectFile.GetPath());
305  return prefix.GetFullPath();
306  }
307  else
308  {
309  return _("Assistant");
310  };
311  case 7:
312  return project->GetStatusText();
313  //all following cases default to an empty string if file is missing
314  case 3:
315  if(project->status!=Project::MISSING)
316  {
317  if (project->modDate.IsValid())
318  {
319  return project->modDate.Format();
320  };
321  };
322  return wxEmptyString;
323  case 4:
324  if(project->status!=Project::MISSING)
325  {
327  str = str+wxT(" (.")+wxString::FromAscii(project->options.outputImageType.c_str())+wxT(")");
328  return str;
329  };
330  return wxEmptyString;
331  case 5:
332  if(project->status!=Project::MISSING)
333  {
334  pano_projection_features proj;
335  if (panoProjectionFeaturesQuery(project->options.getProjection(), &proj))
336  {
337  wxString str2(proj.name, wxConvLocal);
338  return wxGetTranslation(str2);
339  }
340  else
341  {
342  return _T("");
343  }
344  };
345  return wxEmptyString;
346  case 6:
347  if(project->status!=Project::MISSING)
348  {
349  str = wxString() << project->options.getWidth();
350  str = str+_T("x");
351  str = str << project->options.getHeight();
352  return str;
353  }
354  return wxEmptyString;
355  case 8:
356  if (!project->userDefindSequence.IsEmpty())
357  {
358  return project->userDefindSequence;
359  };
360  return wxEmptyString;
361  default:
362  return _T("");
363  }
364 }
365 
366 wxString ProjectListBox::GetLongerFormatName(std::string str)
367 {
368  if(str=="tif")
369  {
370  return _T("TIFF");
371  }
372  else if(str=="jpg")
373  {
374  return _T("JPEG");
375  }
376  else if(str=="png")
377  {
378  return _T("PNG");
379  }
380  else if(str=="exr")
381  {
382  return _T("EXR");
383  }
384  else
385  {
386  return _T("");
387  }
388 }
389 
390 void ProjectListBox::OnColumnWidthChange(wxListEvent& event)
391 {
392  int col = event.GetColumn();
393  wxConfigBase::Get()->Write(wxString::Format(wxT("/BatchList/ColumnWidth%d"),columns[col]), GetColumnWidth(col));
394 }
395 
396 // functions for context menu
397 void ProjectListBox::OnContextMenu(wxContextMenuEvent& e)
398 {
399  const HuginBase::UIntSet selected(GetSelectedProjects());
400  wxPoint point = e.GetPosition();
401  // if from keyboard
402  if ((point.x == -1) && (point.y == -1))
403  {
404  wxSize size = GetSize();
405  point.x = size.x / 2;
406  point.y = size.y / 2;
407  }
408  else
409  {
410  point = ScreenToClient(point);
411  };
412  if (selected.size() == 1)
413  {
414  wxMenu menu;
415  menu.Append(ID_CHANGE_PREFIX, _("Change prefix"));
416  menu.Append(ID_CHANGE_USER_DEFINED, _("Change user defined sequence"));
417  menu.Append(ID_RESET_PROJECT, _("Reset project"));
418  menu.Append(ID_EDIT_PROJECT, _("Edit with Hugin"));
419  menu.Append(ID_REMOVE_PROJECT, _("Remove"));
420  PopupMenu(&menu, point.x, point.y);
421  }
422  else
423  {
424  if (selected.size() > 1)
425  {
426  wxMenu menu;
427  // check that all selected project have the same target
428  const Project::Target target = m_batch->GetProject(*(selected.begin()))->target;
429  bool isSameTarget = true;
430  for (const auto& i : selected)
431  {
432  if (m_batch->GetProject(i)->target != target)
433  {
434  isSameTarget = false;
435  break;
436  };
437  };
438  if (isSameTarget)
439  {
440  menu.Append(ID_CHANGE_USER_DEFINED, _("Change user defined sequence"));
441  };
442  menu.Append(ID_RESET_PROJECT, _("Reset project"));
443  menu.Append(ID_REMOVE_PROJECT, _("Remove"));
444  PopupMenu(&menu, point.x, point.y);
445  };
446  };
447 };
448 
449 void ProjectListBox::OnChar(wxKeyEvent& e)
450 {
451  switch (e.GetKeyCode())
452  {
453  case WXK_DELETE:
454  case WXK_NUMPAD_DELETE:
455  {
456  wxCommandEvent ev(wxEVT_TOOL, XRCID("tool_remove"));
457  GetParent()->GetEventHandler()->AddPendingEvent(ev);
458  };
459  break;
460  case WXK_INSERT:
461  case WXK_NUMPAD_INSERT:
462  {
463  wxCommandEvent ev(wxEVT_MENU, XRCID("menu_add"));
464  GetParent()->GetEventHandler()->AddPendingEvent(ev);
465  };
466  break;
467  case WXK_ESCAPE:
468  {
469  wxCommandEvent ev(wxEVT_TOOL, XRCID("tool_cancel"));
470  GetParent()->GetEventHandler()->AddPendingEvent(ev);
471  };
472  break;
473  default:
474  e.Skip();
475  };
476 }
477 void ProjectListBox::OnChangePrefix(wxCommandEvent& e)
478 {
479  wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, XRCID("button_prefix"));
480  GetParent()->GetEventHandler()->AddPendingEvent(ev);
481 };
482 
483 void ProjectListBox::OnResetProject(wxCommandEvent& e)
484 {
485  wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, XRCID("button_reset"));
486  GetParent()->GetEventHandler()->AddPendingEvent(ev);
487 };
488 
489 void ProjectListBox::OnEditProject(wxCommandEvent& e)
490 {
491  wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, XRCID("button_edit"));
492  GetParent()->GetEventHandler()->AddPendingEvent(ev);
493 };
494 
495 void ProjectListBox::OnRemoveProject(wxCommandEvent& e)
496 {
497  wxCommandEvent ev(wxEVT_COMMAND_TOOL_CLICKED, XRCID("tool_remove"));
498  GetParent()->GetEventHandler()->AddPendingEvent(ev);
499 };
500 
501 void ProjectListBox::OnChangeUserDefined(wxCommandEvent& e)
502 {
503  wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, XRCID("button_user_defined"));
504  GetParent()->GetEventHandler()->AddPendingEvent(ev);
505 }
506 
507 const wxString ProjectListBox::fileFormat[] = {_T("JPEG"),
508  _T("JPEG_m"),
509  _T("PNG"),
510  _T("PNG_m"),
511  _T("TIFF"),
512  _T("TIFF_m"),
513  _T("TIFF_mask"),
514  _T("TIFF_multilayer"),
515  _T("TIFF_multilayer_mask"),
516  _T("PICT"),
517  _T("PSD"),
518  _T("PSD_m"),
519  _T("PSD_mask"),
520  _T("PAN"),
521  _T("IVR"),
522  _T("IVR_java"),
523  _T("VRML"),
524  _T("QTVR"),
525  _T("HDR"),
526  _T("HDR_m"),
527  _T("EXR"),
528  _T("EXR_m"),
529  _T("FILEFORMAT_NULL")
530  };
531 
532 const wxString ProjectListBox::outputMode[] =
533 {
534  _T("OUTPUT_LDR"),
535  _T("OUTPUT_HDR")
536 };
537 
538 const wxString ProjectListBox::HDRMergeType[] =
539 {
540  _T("HDRMERGE_AVERAGE"),
541  _T("HDRMERGE_DEGHOST")
542 };
543 
544 const wxString ProjectListBox::blendingMechanism[] =
545 {
546  _T("NO_BLEND"),
547  _T("PTBLENDER_BLEND"),
548  _T("ENBLEND_BLEND"),
549  _T("SMARTBLEND_BLEND"),
550  _T("PTMASKER_BLEND")
551 };
552 
554 
556  : wxListCtrlXmlHandler()
557 {
558  AddWindowStyles();
559 }
560 
562 {
563  XRC_MAKE_INSTANCE(cp, ProjectListBox)
564 
565  cp->Create(m_parentAsWindow,
566  GetID(),
567  GetPosition(), GetSize(),
568  GetStyle(wxT("style")),
569  GetName());
570 
571  SetupWindow( cp);
572 
573  return cp;
574 }
575 
577 {
578  return IsOfClass(node, wxT("ProjectListBox"));
579 }
580 
582 
void OnResetProject(wxCommandEvent &e)
PanoramaOptions::ProjectionFormat getProjection() const
int GetProjectCount()
Returns number of projects in batch list.
Definition: Batch.cpp:316
wxString userDefindSequence
Definition: ProjectArray.h:73
static const wxString outputMode[]
void OnChangeUserDefined(wxCommandEvent &e)
void SetMissing(int index)
wxDateTime modDate
Definition: ProjectArray.h:75
Status status
Definition: ProjectArray.h:65
int GetProjectCountByPath(wxString path)
unsigned int getHeight() const
get panorama height
void Deselect(int index)
static const wxString HDRMergeType[]
void AppendProject(Project *project)
virtual wxObject * DoCreateResource()
END_EVENT_TABLE()
wxString GetText(int row, int column)
void OnEditProject(wxCommandEvent &e)
HuginBase::PanoramaOptions options
Definition: ProjectArray.h:77
void ChangePrefix(int index, wxString newPrefix)
void ChangeUserDefined(int index, wxString newUserDefined)
std::set< unsigned int > UIntSet
Definition: PanoramaData.h:51
int GetIndex(int id)
void Select(int index)
virtual bool CanHandle(wxXmlNode *node)
void OnContextMenu(wxContextMenuEvent &e)
Target target
Definition: ProjectArray.h:67
IMPLEMENT_DYNAMIC_CLASS(wxTreeListHeaderWindow, wxWindow)
bool UpdateStatus(int index, Project *project)
Batch processor for Hugin with GUI.
void OnRemoveProject(wxCommandEvent &e)
Project * GetProject(int index)
Returns project at index.
Definition: Batch.cpp:311
Definition: Batch.h:48
void OnChangePrefix(wxCommandEvent &e)
wxString path
Definition: ProjectArray.h:69
wxString GetLongerFormatName(std::string str)
static const wxString blendingMechanism[]
unsigned int getWidth() const
HuginBase::UIntSet GetSelectedProjects()
wxString GetAttributeString(int i, Project *project)
static const wxString fileFormat[]
wxString GetStatusText()
void ReloadProject(int index, Project *project)
void OnChar(wxKeyEvent &e)
void Fill(Batch *batch)
IntArray columns
void OnColumnWidthChange(wxListEvent &event)
wxString prefix
Definition: ProjectArray.h:71
int GetProjectId(int index)
long id
Definition: ProjectArray.h:63
void SwapProject(int index)