00001
00002
00027 #include "ProjectListBox.h"
00028
00029 enum
00030 {
00031 ID_CHANGE_PREFIX=wxID_HIGHEST+200,
00032 ID_RESET_PROJECT=wxID_HIGHEST+201,
00033 ID_EDIT_PROJECT=wxID_HIGHEST+202,
00034 ID_REMOVE_PROJECT=wxID_HIGHEST+203
00035 };
00036
00037 BEGIN_EVENT_TABLE(ProjectListBox, wxListCtrl)
00038 EVT_LIST_ITEM_SELECTED(wxID_ANY, ProjectListBox::OnSelect)
00039 EVT_LIST_ITEM_DESELECTED(wxID_ANY, ProjectListBox::OnDeselect)
00040 EVT_LIST_COL_END_DRAG(wxID_ANY, ProjectListBox::OnColumnWidthChange)
00041 EVT_CONTEXT_MENU(ProjectListBox::OnContextMenu)
00042 EVT_MENU(ID_CHANGE_PREFIX, ProjectListBox::OnChangePrefix)
00043 EVT_MENU(ID_RESET_PROJECT, ProjectListBox::OnResetProject)
00044 EVT_MENU(ID_EDIT_PROJECT, ProjectListBox::OnEditProject)
00045 EVT_MENU(ID_REMOVE_PROJECT, ProjectListBox::OnRemoveProject)
00046 END_EVENT_TABLE()
00047
00048 bool ProjectListBox::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
00049 {
00050 if (! wxListCtrl::Create(parent, id, pos, size, wxLC_REPORT | style) )
00051 {
00052 return false;
00053 };
00054 columns.Add(ID),
00055 columns.Add(PROJECT);
00056 columns.Add(PREFIX);
00057 columns.Add(STATUS);
00058 columns.Add(MODDATE);
00059 columns.Add(FORMAT);
00060 columns.Add(PROJECTION);
00061 columns.Add(SIZE);
00062
00063 m_selected = -1;
00064 this->InsertColumn(0,_("ID"));
00065 this->InsertColumn(1,_("Project"));
00066 this->InsertColumn(2,_("Output prefix"));
00067 this->InsertColumn(3,_("Status"));
00068 this->InsertColumn(4,_("Last modified"));
00069 this->InsertColumn(5,_("Output format"));
00070 this->InsertColumn(6,_("Projection"));
00071 this->InsertColumn(7,_("Size"));
00072
00073
00074 for( int i=0; i < GetColumnCount() ; i++ )
00075 {
00076 int width = wxConfigBase::Get()->Read(wxString::Format(wxT("/BatchList/ColumnWidth%d"), columns[i] ), -1);
00077 if(width != -1)
00078 {
00079 SetColumnWidth(i, width);
00080 }
00081 }
00082 return true;
00083 }
00084
00085
00086
00087 void ProjectListBox::AppendProject(Project* project)
00088 {
00089
00090 if(project->id < 0)
00091 {
00092 int i=columns.Index(PROJECT);
00093 if(i != wxNOT_FOUND)
00094 {
00095 if(i==0)
00096 {
00097 this->InsertItem(this->GetItemCount(),project->path);
00098 }
00099 else
00100 {
00101 this->InsertItem(this->GetItemCount(),_T(""));
00102 this->SetItem(this->GetItemCount()-1,i,project->path);
00103 }
00104 }
00105 else
00106 {
00107 this->InsertItem(this->GetItemCount(),_T(""));
00108 }
00109 }
00110 else
00111 {
00112 if(columns.GetCount()>0)
00113 {
00114 this->InsertItem(this->GetItemCount(),this->GetAttributeString(columns[0],project));
00115 for(unsigned int i=1; i<columns.GetCount(); i++)
00116 {
00117 this->SetItem(this->GetItemCount()-1,i,this->GetAttributeString(columns[i],project));
00118 }
00119 }
00120 else
00121 {
00122 this->InsertItem(this->GetItemCount(),_T(""));
00123 }
00124 }
00125 }
00126
00127 void ProjectListBox::ChangePrefix(int index, wxString newPrefix)
00128 {
00129 int colIndex=columns.Index(PREFIX);
00130 if(colIndex!=wxNOT_FOUND)
00131 {
00132 Project* project=m_batch->GetProject(index);
00133 this->SetItem(index,colIndex,this->GetAttributeString(colIndex,project));
00134 }
00135 }
00136
00137 void ProjectListBox::Deselect(int index)
00138 {
00139 SetItemState(index, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
00140 m_selected=-1;
00141 }
00142
00143 void ProjectListBox::Fill(Batch* batch)
00144 {
00145 m_batch=batch;
00146 for(int i=0; i<m_batch->GetProjectCount(); i++)
00147 {
00148 AppendProject(m_batch->GetProject(i));
00149 }
00150 }
00151
00152 int ProjectListBox::GetIndex(int id)
00153 {
00154 int index=0;
00155 while(index<this->GetItemCount())
00156 {
00157 if(GetText(index,0).Cmp(wxString::Format(_("%d"),id))==0)
00158 {
00159 return index;
00160 }
00161 index++;
00162 }
00163 return -1;
00164 }
00165
00166 int ProjectListBox::GetProjectCountByPath(wxString path)
00167 {
00168 int count = 0;
00169 for(int i=0; i<this->GetItemCount(); i++)
00170 {
00171 if(path.Cmp(GetText(i,1))==0)
00172 {
00173 count++;
00174 }
00175 }
00176 return count;
00177 }
00178
00179 int ProjectListBox::GetProjectId(int index)
00180 {
00181 long id=-1;
00182 if(!GetText(index,0).ToLong(&id))
00183 {
00184 wxMessageBox(_("Error, cannot convert id"),_("Error"));
00185 }
00186 return (int)id;
00187 }
00188
00189 int ProjectListBox::GetSelectedIndex()
00190 {
00191 return m_selected;
00192 }
00193
00194 wxString ProjectListBox::GetSelectedProject()
00195 {
00196 return GetText(m_selected,1);
00197 }
00198
00199 Project::Target ProjectListBox::GetSelectedProjectTarget()
00200 {
00201 return m_batch->GetProject(m_selected)->target;
00202 };
00203
00204 wxString ProjectListBox::GetSelectedProjectPrefix()
00205 {
00206 return GetText(m_selected,2);
00207 }
00208
00209 wxString ProjectListBox::GetText(int row, int column)
00210 {
00211 wxListItem item;
00212 item.SetId(row);
00213 item.SetColumn(column);
00214 item.SetMask(wxLIST_MASK_TEXT);
00215 this->GetItem(item);
00216 return item.GetText();
00217 }
00218
00219 void ProjectListBox::ReloadProject(int index, Project* project)
00220 {
00221 for(unsigned int i=0; i<columns.GetCount(); i++)
00222 {
00223 this->SetItem(index,i,this->GetAttributeString(columns[i],project));
00224 }
00225 }
00226
00227 void ProjectListBox::Select(int index)
00228 {
00229 if(index>=0 && index<this->GetItemCount())
00230 {
00231 SetItemState(index,wxLIST_STATE_SELECTED,wxLIST_STATE_SELECTED);
00232 m_selected=index;
00233 };
00234 }
00235
00236 void ProjectListBox::SetMissing(int index)
00237 {
00238 for(int i=0; i< this->GetColumnCount(); i++)
00239 {
00240 if(columns[i]==STATUS)
00241 {
00242 this->SetItem(index,i,_("File missing"));
00243 }
00244 if(columns[i]!=ID && columns[i]!=PROJECT && columns[i]!=PREFIX)
00245 {
00246 this->SetItem(index,i,_T(""));
00247 }
00248 }
00249 }
00250
00251 void ProjectListBox::SwapProject(int index)
00252 {
00253 wxString temp;
00254 for(int i=0; i<GetColumnCount(); i++)
00255 {
00256 temp = GetText(index,i);
00257 SetItem(index,i,GetText(index+1,i));
00258 SetItem(index+1,i,temp);
00259 }
00260 }
00261
00262 bool ProjectListBox::UpdateStatus(int index, Project* project)
00263 {
00264 bool change = false;
00265 wxString newStatus;
00266 for(int i=0; i< this->GetColumnCount(); i++)
00267 {
00268 if(columns[i]==STATUS)
00269 {
00270 newStatus = project->GetStatusText();
00271 if(newStatus.Cmp(GetText(index,i))!=0)
00272 {
00273 change = true;
00274 this->SetItem(index,i,newStatus);
00275 }
00276 }
00277 }
00278 return change;
00279 }
00280
00281
00282
00283 wxString ProjectListBox::GetAttributeString(int i, Project* project)
00284 {
00285 wxString str;
00286 switch(i)
00287 {
00288 case 0:
00289 return wxString::Format(_T("%d"),project->id);
00290 case 1:
00291 return project->path;
00292 case 2:
00293 if(project->target==Project::STITCHING)
00294 {
00295
00296 wxFileName prefix(project->prefix);
00297 wxFileName projectFile(project->path);
00298 prefix.MakeRelativeTo(projectFile.GetPath());
00299 return prefix.GetFullPath();
00300 }
00301 else
00302 {
00303 return _("Assistant");
00304 };
00305 case 7:
00306 return project->GetStatusText();
00307 case 3:
00308 if(project->status!=Project::MISSING)
00309 {
00310 return project->modDate.FormatDate()+_T(", ")+project->modDate.FormatTime();
00311 }
00312 case 4:
00313 if(project->status!=Project::MISSING)
00314 {
00315 str = GetLongerFormatName(project->options.outputImageType);
00316 str = str+wxT(" (.")+wxString::FromAscii(project->options.outputImageType.c_str())+wxT(")");
00317 return str;
00318 }
00319 case 5:
00320 if(project->status!=Project::MISSING)
00321 {
00322 pano_projection_features proj;
00323 if (panoProjectionFeaturesQuery(project->options.getProjection(), &proj))
00324 {
00325 wxString str2(proj.name, wxConvLocal);
00326 return wxGetTranslation(str2);
00327 }
00328 else
00329 {
00330 return _T("");
00331 }
00332 };
00333 case 6:
00334 if(project->status!=Project::MISSING)
00335 {
00336 str = wxString() << project->options.getWidth();
00337 str = str+_T("x");
00338 str = str << project->options.getHeight();
00339 return str;
00340 }
00341 default:
00342 return _T("");
00343 }
00344 }
00345
00346 wxString ProjectListBox::GetLongerFormatName(std::string str)
00347 {
00348 if(str=="tif")
00349 {
00350 return _T("TIFF");
00351 }
00352 else if(str=="jpg")
00353 {
00354 return _T("JPEG");
00355 }
00356 else if(str=="png")
00357 {
00358 return _T("PNG");
00359 }
00360 else if(str=="exr")
00361 {
00362 return _T("EXR");
00363 }
00364 else
00365 {
00366 return _T("");
00367 }
00368 }
00369
00370 void ProjectListBox::OnDeselect(wxListEvent& event)
00371 {
00372 m_selected = -1;
00373 }
00374
00375 void ProjectListBox::OnColumnWidthChange(wxListEvent& event)
00376 {
00377 int col = event.GetColumn();
00378 wxConfigBase::Get()->Write(wxString::Format(wxT("/BatchList/ColumnWidth%d"),columns[col]), GetColumnWidth(col));
00379 }
00380
00381 void ProjectListBox::OnSelect(wxListEvent& event)
00382 {
00383 m_selected = ((wxListEvent)event).GetIndex();
00384 }
00385
00386
00387 void ProjectListBox::OnContextMenu(wxContextMenuEvent& e)
00388 {
00389 if(m_selected!=-1)
00390 {
00391 wxPoint point = e.GetPosition();
00392
00393 if((point.x==-1) && (point.y==-1))
00394 {
00395 wxSize size = GetSize();
00396 point.x = size.x / 2;
00397 point.y = size.y / 2;
00398 }
00399 else
00400 {
00401 point = ScreenToClient(point);
00402 }
00403 wxMenu menu;
00404 menu.Append(ID_CHANGE_PREFIX, _("Change prefix"));
00405 menu.Append(ID_RESET_PROJECT, _("Reset project"));
00406 menu.Append(ID_EDIT_PROJECT, _("Edit with Hugin"));
00407 menu.Append(ID_REMOVE_PROJECT, _("Remove"));
00408 PopupMenu(&menu, point.x, point.y);
00409 };
00410 };
00411
00412 void ProjectListBox::OnChangePrefix(wxCommandEvent& e)
00413 {
00414 wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, XRCID("button_prefix"));
00415 GetParent()->GetEventHandler()->AddPendingEvent(ev);
00416 };
00417
00418 void ProjectListBox::OnResetProject(wxCommandEvent& e)
00419 {
00420 wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, XRCID("button_reset"));
00421 GetParent()->GetEventHandler()->AddPendingEvent(ev);
00422 };
00423
00424 void ProjectListBox::OnEditProject(wxCommandEvent& e)
00425 {
00426 wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, XRCID("button_edit"));
00427 GetParent()->GetEventHandler()->AddPendingEvent(ev);
00428 };
00429
00430 void ProjectListBox::OnRemoveProject(wxCommandEvent& e)
00431 {
00432 wxCommandEvent ev(wxEVT_COMMAND_TOOL_CLICKED, XRCID("tool_remove"));
00433 GetParent()->GetEventHandler()->AddPendingEvent(ev);
00434 };
00435
00436 const wxString ProjectListBox::fileFormat[] = {_T("JPEG"),
00437 _T("PNG"),
00438 _T("TIFF"),
00439 _T("TIFF_m"),
00440 _T("TIFF_mask"),
00441 _T("TIFF_multilayer"),
00442 _T("TIFF_multilayer_mask"),
00443 _T("PICT"),
00444 _T("PSD"),
00445 _T("PSD_m"),
00446 _T("PSD_mask"),
00447 _T("PAN"),
00448 _T("IVR"),
00449 _T("IVR_java"),
00450 _T("VRML"),
00451 _T("QTVR"),
00452 _T("HDR"),
00453 _T("HDR_m"),
00454 _T("EXR"),
00455 _T("EXR_m"),
00456 _T("FILEFORMAT_NULL")
00457 };
00458
00459 const wxString ProjectListBox::outputMode[] =
00460 {
00461 _T("OUTPUT_LDR"),
00462 _T("OUTPUT_HDR")
00463 };
00464
00465 const wxString ProjectListBox::HDRMergeType[] =
00466 {
00467 _T("HDRMERGE_AVERAGE"),
00468 _T("HDRMERGE_DEGHOST")
00469 };
00470
00471 const wxString ProjectListBox::blendingMechanism[] =
00472 {
00473 _T("NO_BLEND"),
00474 _T("PTBLENDER_BLEND"),
00475 _T("ENBLEND_BLEND"),
00476 _T("SMARTBLEND_BLEND"),
00477 _T("PTMASKER_BLEND")
00478 };
00479
00480 const wxString ProjectListBox::colorCorrection[] =
00481 {
00482 _T("NONE"),
00483 _T("BRIGHTNESS_COLOR"),
00484 _T("BRIGHTNESS"),
00485 _T("COLOR")
00486 };
00487
00488 IMPLEMENT_DYNAMIC_CLASS(ProjectListBox, wxListCtrl)
00489
00490 ProjectListBoxXmlHandler::ProjectListBoxXmlHandler()
00491 : wxListCtrlXmlHandler()
00492 {
00493 AddWindowStyles();
00494 }
00495
00496 wxObject* ProjectListBoxXmlHandler::DoCreateResource()
00497 {
00498 XRC_MAKE_INSTANCE(cp, ProjectListBox)
00499
00500 cp->Create(m_parentAsWindow,
00501 GetID(),
00502 GetPosition(), GetSize(),
00503 GetStyle(wxT("style")),
00504 GetName());
00505
00506 SetupWindow( cp);
00507
00508 return cp;
00509 }
00510
00511 bool ProjectListBoxXmlHandler::CanHandle(wxXmlNode* node)
00512 {
00513 return IsOfClass(node, wxT("ProjectListBox"));
00514 }
00515
00516 IMPLEMENT_DYNAMIC_CLASS(ProjectListBoxXmlHandler, wxListCtrlXmlHandler)
00517