ProjectListBox.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
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     //get saved width
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 //public methods:
00086 
00087 void ProjectListBox::AppendProject(Project* project)
00088 {
00089     //if we have a command-line application
00090     if(project->id < 0) 
00091     {
00092         int i=columns.Index(PROJECT);   //we find the project column
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    //we insert an empty line
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    //we have no columns?
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 //private methods:
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("%ld"),project->id);
00290         case 1:
00291             return project->path;
00292         case 2:
00293             if(project->target==Project::STITCHING)
00294             {
00295                 //make prefix relative to project path
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         //all following cases default to an empty string if file is missing
00308         case 3:
00309             if(project->status!=Project::MISSING)
00310             {
00311                 if (project->modDate.IsValid())
00312                 {
00313                     return project->modDate.Format();
00314                 };
00315             };
00316             return wxEmptyString;
00317         case 4:
00318             if(project->status!=Project::MISSING)
00319             {
00320                 str = GetLongerFormatName(project->options.outputImageType);
00321                 str = str+wxT(" (.")+wxString::FromAscii(project->options.outputImageType.c_str())+wxT(")");
00322                 return str;
00323             };
00324             return wxEmptyString;
00325         case 5:
00326             if(project->status!=Project::MISSING)
00327             {
00328                 pano_projection_features proj;
00329                 if (panoProjectionFeaturesQuery(project->options.getProjection(), &proj))
00330                 {
00331                     wxString str2(proj.name, wxConvLocal);
00332                     return wxGetTranslation(str2);
00333                 }
00334                 else
00335                 {
00336                     return _T("");
00337                 }
00338             };
00339             return wxEmptyString;
00340         case 6:
00341             if(project->status!=Project::MISSING)
00342             {
00343                 str = wxString() << project->options.getWidth();
00344                 str = str+_T("x");
00345                 str = str << project->options.getHeight();
00346                 return str;
00347             }
00348             return wxEmptyString;
00349         default:
00350             return _T("");
00351     }
00352 }
00353 
00354 wxString ProjectListBox::GetLongerFormatName(std::string str)
00355 {
00356     if(str=="tif")
00357     {
00358         return _T("TIFF");
00359     }
00360     else if(str=="jpg")
00361     {
00362         return _T("JPEG");
00363     }
00364     else if(str=="png")
00365     {
00366         return _T("PNG");
00367     }
00368     else if(str=="exr")
00369     {
00370         return _T("EXR");
00371     }
00372     else
00373     {
00374         return _T("");
00375     }
00376 }
00377 
00378 void ProjectListBox::OnDeselect(wxListEvent& event)
00379 {
00380     m_selected = -1;
00381 }
00382 
00383 void ProjectListBox::OnColumnWidthChange(wxListEvent& event)
00384 {
00385     int col = event.GetColumn();
00386     wxConfigBase::Get()->Write(wxString::Format(wxT("/BatchList/ColumnWidth%d"),columns[col]), GetColumnWidth(col));
00387 }
00388 
00389 void ProjectListBox::OnSelect(wxListEvent& event)
00390 {
00391     m_selected = ((wxListEvent)event).GetIndex();
00392 }
00393 
00394 // functions for context menu
00395 void ProjectListBox::OnContextMenu(wxContextMenuEvent& e)
00396 {
00397     if(m_selected!=-1)
00398     {
00399         wxPoint point = e.GetPosition();
00400         // if from keyboard
00401         if((point.x==-1) && (point.y==-1))
00402         {
00403             wxSize size = GetSize();
00404             point.x = size.x / 2;
00405             point.y = size.y / 2;
00406         }
00407         else
00408         {
00409             point = ScreenToClient(point);
00410         }
00411         wxMenu menu;
00412         menu.Append(ID_CHANGE_PREFIX, _("Change prefix"));
00413         menu.Append(ID_RESET_PROJECT, _("Reset project"));
00414         menu.Append(ID_EDIT_PROJECT, _("Edit with Hugin"));
00415         menu.Append(ID_REMOVE_PROJECT, _("Remove"));
00416         PopupMenu(&menu, point.x, point.y);
00417     };
00418 };
00419 
00420 void ProjectListBox::OnChangePrefix(wxCommandEvent& e)
00421 {
00422     wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, XRCID("button_prefix"));
00423     GetParent()->GetEventHandler()->AddPendingEvent(ev);
00424 };
00425 
00426 void ProjectListBox::OnResetProject(wxCommandEvent& e)
00427 {
00428     wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, XRCID("button_reset"));
00429     GetParent()->GetEventHandler()->AddPendingEvent(ev);
00430 };
00431 
00432 void ProjectListBox::OnEditProject(wxCommandEvent& e)
00433 {
00434     wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, XRCID("button_edit"));
00435     GetParent()->GetEventHandler()->AddPendingEvent(ev);
00436 };
00437 
00438 void ProjectListBox::OnRemoveProject(wxCommandEvent& e)
00439 {
00440     wxCommandEvent ev(wxEVT_COMMAND_TOOL_CLICKED, XRCID("tool_remove"));
00441     GetParent()->GetEventHandler()->AddPendingEvent(ev);
00442 };
00443 
00444 const wxString ProjectListBox::fileFormat[] = {_T("JPEG"),
00445         _T("JPEG_m"),
00446         _T("PNG"),
00447         _T("PNG_m"),
00448         _T("TIFF"),
00449         _T("TIFF_m"),
00450         _T("TIFF_mask"),
00451         _T("TIFF_multilayer"),
00452         _T("TIFF_multilayer_mask"),
00453         _T("PICT"),
00454         _T("PSD"),
00455         _T("PSD_m"),
00456         _T("PSD_mask"),
00457         _T("PAN"),
00458         _T("IVR"),
00459         _T("IVR_java"),
00460         _T("VRML"),
00461         _T("QTVR"),
00462         _T("HDR"),
00463         _T("HDR_m"),
00464         _T("EXR"),
00465         _T("EXR_m"),
00466         _T("FILEFORMAT_NULL")
00467                                               };
00468 
00469 const wxString ProjectListBox::outputMode[] =
00470 {
00471     _T("OUTPUT_LDR"),
00472     _T("OUTPUT_HDR")
00473 };
00474 
00475 const wxString ProjectListBox::HDRMergeType[] =
00476 {
00477     _T("HDRMERGE_AVERAGE"),
00478     _T("HDRMERGE_DEGHOST")
00479 };
00480 
00481 const wxString ProjectListBox::blendingMechanism[] =
00482 {
00483     _T("NO_BLEND"),
00484     _T("PTBLENDER_BLEND"),
00485     _T("ENBLEND_BLEND"),
00486     _T("SMARTBLEND_BLEND"),
00487     _T("PTMASKER_BLEND")
00488 };
00489 
00490 const wxString ProjectListBox::colorCorrection[] =
00491 {
00492     _T("NONE"),
00493     _T("BRIGHTNESS_COLOR"),
00494     _T("BRIGHTNESS"),
00495     _T("COLOR")
00496 };
00497 
00498 IMPLEMENT_DYNAMIC_CLASS(ProjectListBox, wxListCtrl)
00499 
00500 ProjectListBoxXmlHandler::ProjectListBoxXmlHandler()
00501     : wxListCtrlXmlHandler()
00502 {
00503     AddWindowStyles();
00504 }
00505 
00506 wxObject* ProjectListBoxXmlHandler::DoCreateResource()
00507 {
00508     XRC_MAKE_INSTANCE(cp, ProjectListBox)
00509 
00510     cp->Create(m_parentAsWindow,
00511                GetID(),
00512                GetPosition(), GetSize(),
00513                GetStyle(wxT("style")),
00514                GetName());
00515 
00516     SetupWindow( cp);
00517 
00518     return cp;
00519 }
00520 
00521 bool ProjectListBoxXmlHandler::CanHandle(wxXmlNode* node)
00522 {
00523     return IsOfClass(node, wxT("ProjectListBox"));
00524 }
00525 
00526 IMPLEMENT_DYNAMIC_CLASS(ProjectListBoxXmlHandler, wxListCtrlXmlHandler)
00527 

Generated on 27 Aug 2015 for Hugintrunk by  doxygen 1.4.7