/home/enzo/treballs/fib/pfc/nanocomp/src/forbiddenPatternView.cpp

Go to the documentation of this file.
00001 /*
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   This program is distributed in the hope that it will be useful,       *
00009  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00010  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00011  *   GNU General Public License for more details.                          *
00012  *                                                                         *
00013  *   You should have received a copy of the GNU General Public License     *
00014  *   along with this program; if not, write to the                         *
00015  *   Free Software Foundation, Inc.,                                       *
00016  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00017                                                                           */
00018 // $Revision: 1.20 $
00019 
00020 #include "forbiddenPatternView.hpp"
00021 #include <wx/statline.h>
00022 #include "resources/cross.xpm"
00023 #include "resources/fileopen.xpm"
00024 #include "resources/filesave.xpm"
00025 #include "resources/filesaveas.xpm"
00026 #include "resources/new.xpm"
00027 
00029 enum
00030 {
00031     ID_BUTTON_NEW = 0,
00032     ID_BUTTON_OPEN,
00033     ID_BUTTON_SAVE,
00034     ID_BUTTON_SAVEAS,
00035     ID_BUTTON_REMOVE,
00036     ID_BUTTON_CHECK,
00037     ID_LISTFP,
00038     ID_CANVAS
00039 };
00040 
00041 
00042 BEGIN_EVENT_TABLE(ForbiddenPatternView, wxPanel)
00043     EVT_LAYOUT_CANVAS  (ID_CANVAS,  ForbiddenPatternView::OnClick)
00044     EVT_BUTTON  (ID_BUTTON_NEW, ForbiddenPatternView::OnNew)
00045     EVT_LISTBOX (ID_LISTFP, ForbiddenPatternView::OnSelection)
00046     EVT_BUTTON  (ID_BUTTON_REMOVE, ForbiddenPatternView::OnRemove)
00047     EVT_BUTTON  (ID_BUTTON_SAVE, ForbiddenPatternView::OnSave)
00048     EVT_BUTTON  (ID_BUTTON_SAVEAS, ForbiddenPatternView::OnSaveAs)
00049     EVT_BUTTON  (ID_BUTTON_OPEN, ForbiddenPatternView::OnOpen)
00050         EVT_BUTTON  (ID_BUTTON_CHECK, ForbiddenPatternView::OnCheck)
00051 END_EVENT_TABLE()
00052 
00053 
00055 
00060 ForbiddenPatternView::ForbiddenPatternView(wxWindow* parent, wxWindowID id, ForbiddenPatternManager *controller)
00061     :wxPanel(parent, id)
00062 {
00063     this->controller = controller;
00064     initControls();
00065     initSizers();
00066     controller->setView(this);
00067 }
00068 
00069 
00071 ForbiddenPatternView::~ForbiddenPatternView()
00072 {
00073 }
00074 
00075 
00077 
00080 void ForbiddenPatternView::initControls()
00081 {
00082     //Buttons
00083     wxBitmap newBitmap(wxBITMAP(new));
00084     wxBitmap saveBitmap(wxBITMAP(filesave));
00085     wxBitmap saveAsBitmap(wxBITMAP(filesaveas));
00086     wxBitmap removeBitmap(wxBITMAP(cross));
00087     wxBitmap openBitmap(wxBITMAP(fileopen));
00088     buttonNew = new wxBitmapButton(this, ID_BUTTON_NEW, newBitmap);
00089     buttonNew->SetToolTip(_("Add a new forbidden pattern"));
00090     buttonOpen = new wxBitmapButton(this, ID_BUTTON_OPEN, openBitmap);
00091     buttonOpen->SetToolTip(_("Open a forbidden pattern file"));
00092     buttonSave = new wxBitmapButton(this, ID_BUTTON_SAVE, saveBitmap);
00093     buttonSave->SetToolTip(_("Save selected forbidden pattern to a file"));
00094     buttonSaveAs = new wxBitmapButton(this, ID_BUTTON_SAVEAS, saveAsBitmap);
00095     buttonSaveAs->SetToolTip(_("Save selected forbidden pattern to a new file"));
00096     buttonRemove = new wxBitmapButton(this, ID_BUTTON_REMOVE, removeBitmap);
00097     buttonRemove->SetToolTip(_("Delete selected forbidden pattern"));
00098     buttonSave->Enable(false);
00099     buttonSaveAs->Enable(false);
00100     buttonRemove->Enable(false);
00101     buttonCheck = new wxButton(this, ID_BUTTON_CHECK, _("Check patterns"));
00102     
00103     //Other controls
00104     listFP = new wxListBox(this, ID_LISTFP);
00105     canvas = new LayoutCanvas(this, ID_CANVAS, Grid());
00106 }
00107 
00109 
00112 void ForbiddenPatternView::initSizers()
00113 {
00114     //Main Sizer
00115     wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
00116     //mainSizer->Add(labelTitle, 0, wxEXPAND | wxALL, 2);
00117     
00118         //List and layout sizer
00119         wxBoxSizer *listLayoutSizer = new wxBoxSizer(wxHORIZONTAL);
00120             
00121             //List sizer
00122             wxStaticBoxSizer *listVerticalSizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Pattern list"));
00123             wxBoxSizer *listSizer = new wxBoxSizer(wxHORIZONTAL);
00124             listSizer->Add(listFP, 1, wxEXPAND | wxALL, 1);
00125             
00126                 //Buttons sizer
00127                 wxBoxSizer *buttonSizer = new wxBoxSizer(wxVERTICAL);
00128                 buttonSizer->Add(buttonNew, 0, wxEXPAND | wxALL);
00129                 buttonSizer->Add(buttonOpen, 0, wxEXPAND | wxALL);
00130                 buttonSizer->Add(buttonRemove, 0, wxEXPAND | wxALL);
00131                 buttonSizer->Add(buttonSave, 0, wxEXPAND | wxALL);
00132                 buttonSizer->Add(buttonSaveAs, 0, wxEXPAND | wxALL);
00133                 
00134             listSizer->Add(buttonSizer, 0, wxEXPAND | wxALL, 1);
00135             
00136             listVerticalSizer->Add(listSizer, 1, wxEXPAND | wxALL, 1);
00137             
00138             //Check button sizer
00139             wxBoxSizer *checkButtonSizer = new wxBoxSizer(wxVERTICAL);
00140             checkButtonSizer->Add(buttonCheck, 0, wxSHAPED | wxALIGN_CENTER, 1);
00141             
00142             listVerticalSizer->Add(checkButtonSizer, 0, wxSHAPED | wxALIGN_CENTER, 1);
00143             
00144         listLayoutSizer->Add(listVerticalSizer, 2, wxEXPAND | wxALL, 1);
00145         
00146             //Layouts sizer
00147             wxStaticBoxSizer *layoutSizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Layout"));
00148             layoutSizer->Add(canvas, 1, wxEXPAND | wxALL | wxALIGN_CENTER, 1);
00149             
00150         //listLayoutSizer->AddStretchSpacer();
00151         listLayoutSizer->Add(layoutSizer, 3, wxEXPAND | wxALL, 1);
00152         
00153     mainSizer->Add(listLayoutSizer, 3, wxEXPAND | wxALL, 1);
00154 
00155     SetSizer(mainSizer);
00156 }
00157 
00158 
00160 
00164 void ForbiddenPatternView::OnClick(LayoutCanvasEvent &event)
00165 {
00166     controller->cellChanged(event.getX(), event.getY());
00167 }
00168 
00169 
00171 
00175 void ForbiddenPatternView::OnNew(wxCommandEvent &event)
00176 {
00177     //The user is asked for the width and height of the new pattern
00178     //and then the controller is called to do the actual work.
00179     int width;
00180     int height;
00181     wxNumberEntryDialog widthDialog(this,
00182                         wxEmptyString,
00183                         _("Insert the layout width"),
00184                         _("New Forbidden Pattern"),
00185                         1, 1, 100);
00186     if (widthDialog.ShowModal() == wxID_OK)
00187     {
00188         width = (int)(widthDialog.GetValue());
00189     
00190         wxNumberEntryDialog heightDialog(this,
00191                         wxEmptyString,
00192                         _("Insert the layout height"),
00193                         _("New ForbiddenPattern"),
00194                         1, 1, 100);
00195         if (heightDialog.ShowModal() == wxID_OK)
00196         {
00197             height = (int)(heightDialog.GetValue());
00198             controller->newFP(width, height);
00199         }
00200     }
00201     
00202 }
00203 
00204 
00206 
00210 void ForbiddenPatternView::OnSelection(wxCommandEvent &event)
00211 {
00212     //New FP selected, we must let the controller know
00213     //to update us with new info
00214     if (event.IsSelection())
00215     {
00216         wxString selection = event.GetString();
00217         unsigned long int temp;
00218         selection.Mid(7).ToULong(&temp);
00219         unsigned int FPId = temp;
00220         controller->FPSelected(FPId);
00221         buttonRemove->Enable(true);
00222         buttonSave->Enable(true);
00223         buttonSaveAs->Enable(true);
00224     }
00225 }
00226 
00227 
00229 
00233 void ForbiddenPatternView::OnRemove(wxCommandEvent &event)
00234 {
00235     controller->removeFP();
00236 }
00237 
00238 
00240 
00245 void ForbiddenPatternView::updateGrids(Grid grid, bool changed)
00246 {
00247     canvas->setGrid(grid, changed);
00248 }
00249 
00250 
00252 
00256 void ForbiddenPatternView::updateList(wxArrayString strings)
00257 {
00258     listFP->Set(strings);
00259     //Enable/Disable modify buttons if the list is (not) empty
00260     buttonRemove->Enable(strings.size() > 0);
00261     buttonSave->Enable(strings.size() > 0);
00262     buttonSaveAs->Enable(strings.size() > 0);
00263 }
00264 
00265 
00267 
00271 void ForbiddenPatternView::selectFP(unsigned int FP)
00272 {
00273     int item = listFP->FindString(wxString::Format(_("Pattern %d"), FP));
00274     if (item != wxNOT_FOUND)
00275     {
00276         listFP->SetSelection(item);
00277         buttonRemove->Enable(true);
00278         buttonSave->Enable(true);
00279         buttonSaveAs->Enable(true);
00280     }
00281 }
00282 
00283 
00285 
00289 void ForbiddenPatternView::OnSave(wxCommandEvent& event)
00290 {
00291     controller->saveFile();
00292 }
00293 
00294 
00296 
00300 void ForbiddenPatternView::OnSaveAs(wxCommandEvent& event)
00301 {
00302     controller->saveFileAs();
00303 }
00304 
00305 
00307 
00311 void ForbiddenPatternView::OnOpen(wxCommandEvent& event)
00312 {
00313     controller->openFile();
00314 }
00315 
00316 
00318 
00323 bool ForbiddenPatternView::msgYesNo(wxString message)
00324 {
00325     wxMessageDialog dialog(this,
00326             message,
00327             _("Question"), 
00328             wxYES | wxNO); 
00329     return (dialog.ShowModal() == wxID_YES);
00330 }
00331 
00332 
00334 
00337 void ForbiddenPatternView::errorMsg(wxString message)
00338 {
00339     wxMessageDialog dialog(this,
00340             message,
00341             _("Error"), 
00342             wxOK | wxICON_ERROR); 
00343     dialog.ShowModal();
00344 }
00345 
00346 
00348 
00352 void ForbiddenPatternView::OnCheck(wxCommandEvent& event)
00353 {
00354     controller->checkPatterns();
00355 }
00356 
00357 
00359 
00364 void ForbiddenPatternView::setListMessage(int id, wxString message)
00365 {
00366     //TODO bug: id could not be the index if some patterns have
00367     //been deleted. We have to find the index.
00368     //Do it on the rule view too.
00369     listFP->SetString(id - 1, listFP->GetString(id - 1) + message);
00370 }
00371 
00372 
00374 
00378 void ForbiddenPatternView::resetListItem(int id)
00379 {
00380     //TODO bug: same as above
00381     listFP->SetString(id - 1, wxString::Format(_("Pattern %d"), id + 1));
00382 }

Generated on Fri Sep 1 23:55:13 2006 for NanoComp by  doxygen 1.4.6