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

Generated on 10 Dec 2017 for Hugintrunk by  doxygen 1.4.7