/home/enzo/treballs/fib/pfc/nanocomp/src/layoutManager.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 
00019 // $Revision: 1.23 $
00020 
00021 #include "layoutManager.hpp"
00022 #include <wx/filename.h>
00023 
00025 
00031 LayoutManager::LayoutManager(MainController *controller, TruthTableManager *tableManager, ForbiddenPatternManager *FPManager, RuleManager *ruleManager)
00032 {
00033     this->tableManager = tableManager;
00034     this->FPManager = FPManager;
00035     this->ruleManager = ruleManager;
00036     this->controller = controller;
00037     layoutModified = false;
00038     layoutNeedNewFile = false;
00039     layoutFileName = wxEmptyString;
00040     diskManager = new LayoutDiskManager(this);
00041     configuration = NULL;
00042     assigningInput = false;
00043     assigningOutput = false;
00044     currentTable = wxEmptyString;
00045     currentInput = 0; //No input
00046     currentOutput = 0; //No output
00047 }
00048 
00049 
00051 LayoutManager::~LayoutManager()
00052 {
00053     delete diskManager;
00054 }
00055 
00056 
00058 
00062 void LayoutManager::setView(LayoutView *view)
00063 {
00064     this->view = view;
00065 }
00066 
00067 
00069 
00076 void LayoutManager::cellChanged(int x, int y)
00077 {
00078     bool result;
00079     vector<coordinate> vInputs;
00080     vector<coordinate> vOutputs;
00081     //TODO: si currentTable = wxEmptyString passar vectors buits o s'assigna un vector buit al mapa i em fuckeja
00082     if (currentTable != wxEmptyString)
00083     {
00084         vInputs = tableInputs[currentTable];
00085         vOutputs = tableOutputs[currentTable];
00086     }
00087     result = configuration->cellChanged(x, y, assigningInput, assigningOutput, vInputs, vOutputs);
00088     layoutModified = true;
00089     if (assigningInput && result)
00090     {
00091         //Check if input assigned there
00092         if (inputAssigned(x, y))
00093         {
00094             controller->setStatusMessage(wxString::Format(_("Input already assigned in %d, %d"), x, y));
00095         }
00096         else
00097         {
00098             //Check if assignation or de-assignation
00099             if (tableInputs[currentTable][currentInput].x == x && tableInputs[currentTable][currentInput].y == y)
00100             {
00101                 //Deassign
00102                 tableInputs[currentTable][currentInput].x = -1;
00103                 tableInputs[currentTable][currentInput].y = -1;
00104                 controller->setStatusMessage(wxString::Format(_("Input %d de-assigned from %d, %d"), currentInput + 1, x, y));
00105             }
00106             else
00107             {
00108                 //Assign ONLY if its non assigned 
00109                 //(else we would be assigning one input to two cells
00110                 if (tableInputs[currentTable][currentInput].x == -1)
00111                 {
00112                     tableInputs[currentTable][currentInput].x = x;
00113                     tableInputs[currentTable][currentInput].y = y;
00114                     controller->setStatusMessage(wxString::Format(_("Input %d assigned to %d, %d"), currentInput + 1, x, y));
00115                 }
00116                 else
00117                 {
00118                     controller->setStatusMessage(wxString::Format(_("Input %d already assigned"), currentInput + 1));
00119                 }
00120             }
00121         }
00122         assigningInput = false;
00123         view->onlyAssign(true);
00124     }
00125     if (assigningOutput && result)
00126     {
00127         //Check if output assigned there
00128         if (outputAssigned(x, y))
00129         {
00130             controller->setStatusMessage(wxString::Format(_("Output already assigned in %d, %d"), x, y));
00131         }
00132         else
00133         {
00134             if (tableOutputs[currentTable][currentOutput].x == x && tableOutputs[currentTable][currentOutput].y == y)
00135             {
00136                 //Deassign
00137                 tableOutputs[currentTable][currentOutput].x = -1;
00138                 tableOutputs[currentTable][currentOutput].y = -1;
00139                 controller->setStatusMessage(wxString::Format(_("Output %d de-assigned from %d, %d"), currentInput + 1, x, y));
00140             }
00141             else
00142             {
00143                 //Assign
00144                 if (tableOutputs[currentTable][currentOutput].x == -1)
00145                 {
00146                     tableOutputs[currentTable][currentOutput].x = x;
00147                     tableOutputs[currentTable][currentOutput].y = y;
00148                     controller->setStatusMessage(wxString::Format(_("Output %d assigned to %d, %d"), currentInput + 1, x, y));
00149                 }
00150                 else
00151                 {
00152                     controller->setStatusMessage(wxString::Format(_("Output %d already assigned"), currentInput + 1));
00153                 }
00154             }
00155         }
00156         assigningOutput = false;
00157         view->onlyAssign(true);
00158     }
00159     if (currentTable != wxEmptyString)
00160     {
00161         view->updateInputs(tableInputs[currentTable]);
00162         view->updateOutputs(tableOutputs[currentTable]);
00163     }
00164     updateGrids(false);
00165     view->updateCanvas();
00166     controller->elementChanged();
00167 }
00168 
00169 
00171 
00174 void LayoutManager::updateGrids(bool changed)
00175 {
00176     Grid grid;
00177     grid = configuration->getGrid();
00178     view->updateGrids(grid, changed);
00179     
00180 }
00181 
00182 
00184 
00190 void LayoutManager::updateTTList(wxArrayString tables)
00191 {
00192     //First we delete the ones removed
00193     map< wxString, vector<coordinate> >::iterator i = tableInputs.begin();
00194     while (i != tableInputs.end())
00195     {
00196         if (!findString(tables, (*i).first))
00197         //Delete this element
00198         {
00199             map< wxString, vector<coordinate> >::iterator j = i;
00200             i++;
00201             tableInputs.erase(j);
00202         }
00203         else
00204         {
00205             i++;
00206         }
00207     }
00208     
00209     map< wxString, vector<coordinate> >::iterator j = tableOutputs.begin();
00210     while (j != tableOutputs.end())
00211     {
00212         if (!findString(tables, (*j).first))
00213         //Delete this element
00214         {
00215             map< wxString, vector<coordinate> >::iterator k = j;
00216             j++;
00217             tableOutputs.erase(k);
00218         }
00219         else
00220         {
00221             j++;
00222         }
00223     }
00224     
00225     map<wxString, bool>::iterator k = tableEnabled.begin();
00226     while (k != tableEnabled.end())
00227     {
00228         if (!findString(tables, (*k).first))
00229         //Delete this element
00230         {
00231             map<wxString, bool>::iterator l = k;
00232             k++;
00233             tableEnabled.erase(l);
00234         }
00235         else
00236         {
00237             k++;
00238         }
00239     }
00240     
00241     //For the new ones we must disable them by default
00242     for (unsigned int i = 0; i < tables.size(); i++)
00243     {
00244         if (tableEnabled.find(tables[i]) == tableEnabled.end())
00245         {
00246             tableEnabled[tables[i]] = false;
00247         }
00248         if (tableInputs.find(tables[i]) == tableInputs.end())
00249         {
00250             //Assign non valid coordinates for io
00251             int inputs = tableManager->getInputs(tables[i]);
00252             tableInputs[tables[i]].resize(inputs);
00253             for (int j = 0; j < inputs; j++)
00254             {
00255                 tableInputs[tables[i]][j].x = -1;
00256                 tableInputs[tables[i]][j].y = -1;
00257             }
00258             int outputs = tableManager->getOutputs(tables[i]);
00259             tableOutputs[tables[i]].resize(outputs);
00260             for (int j = 0; j < outputs; j++)
00261             {
00262                 tableOutputs[tables[i]][j].x = -1;
00263                 tableOutputs[tables[i]][j].y = -1;
00264             }
00265         }
00266     }
00267     
00268      view->updateTTList(tableEnabled);
00269         
00270     //Update selected table if necessary
00271     if (currentTable == wxEmptyString)
00272     {
00273         if (tables.size() > 0)
00274         {
00275             currentTable = tables[tables.size() - 1];
00276             view->selectTable(tables[tables.size() - 1]);
00277         }
00278     }
00279     else
00280     {
00281         if (tableEnabled.find(currentTable) == tableEnabled.end())
00282         {
00283             //The selected table was removed
00284             if (tables.size() > 0)
00285             {
00286                 currentTable = tables[tables.size() - 1];
00287                 view->selectTable(tables[tables.size() - 1]);
00288             }
00289         }
00290     }
00291     controller->elementChanged();
00292 }
00293 
00294 
00296 
00302 void LayoutManager::updateFPList(wxArrayString FPs)
00303 {
00304     //First we delete the ones removed
00305     map<unsigned int, bool>::iterator i = FPEnabled.begin();
00306     while (i != FPEnabled.end())
00307     {
00308         if (!findString(FPs, wxString::Format(_("Pattern %d"), (*i).first)))
00309         //Delete this element
00310         {
00311             map<unsigned int, bool>::iterator j = i;
00312             i++;
00313             FPEnabled.erase(j);
00314         }
00315         else
00316         {
00317             i++;
00318         }
00319     }
00320     
00321    //For the new ones we must enable them by default
00322    unsigned long int temp;
00323     for (unsigned int i = 0; i < FPs.size(); i++)
00324     {
00325         FPs[i].Mid(8).ToULong(&temp);
00326         if (FPEnabled.find(temp) == FPEnabled.end())
00327         {
00328             FPEnabled[temp] = true;
00329         }
00330     }
00331     
00332     view->updateFPList(FPEnabled);
00333     controller->elementChanged();
00334 }
00335 
00336 
00338 
00344 void LayoutManager::updateRuleList(wxArrayString rules)
00345 {
00346     //First we delete the ones removed
00347     map<unsigned int, bool>::iterator i = ruleEnabled.begin();
00348     while (i != ruleEnabled.end())
00349     {
00350         if (!findString(rules, wxString::Format(_("Rule %d"), (*i).first)))
00351         //Delete this element
00352         {
00353             map<unsigned int, bool>::iterator j = i;
00354             i++;
00355             ruleEnabled.erase(j);
00356         }
00357         else
00358         {
00359             i++;
00360         }
00361     }
00362     
00363    //For the new ones we must enable them by default
00364    unsigned long int temp;
00365     for (unsigned int i = 0; i < rules.size(); i++)
00366     {
00367         rules[i].Mid(4).ToULong(&temp);
00368         if (ruleEnabled.find(temp) == ruleEnabled.end())
00369         {
00370             ruleEnabled[temp] = true;
00371         }
00372     }
00373     
00374     view->updateRuleList(ruleEnabled);
00375     controller->elementChanged();
00376 }
00377 
00378 
00380 
00386 void LayoutManager::newLayout(int width, int height, int inputs, int outputs)
00387 {
00388     //TODO: check for memory leak
00389     //LayoutConfig *temp = configuration;
00390     configuration = new LayoutConfig(width, height, inputs, outputs);
00391     //if (temp)
00392     //{
00393     //    delete temp;
00394     //}
00395     view->updateGrids(configuration->getGrid(), true);
00396     if (layoutFileName == wxEmptyString)
00397     {
00398         layoutNeedNewFile = true;
00399     }
00400     layoutModified = true;
00401     tablesChanged();
00402     resetIO();
00403     if (currentTable != wxEmptyString)
00404     {
00405         view->updateInputs(tableInputs[currentTable]);
00406         view->updateOutputs(tableOutputs[currentTable]);
00407     }
00408     else
00409     {
00410         vector<coordinate> empty;
00411         view->updateInputs(empty);
00412         view->updateOutputs(empty);
00413     }
00414     controller->elementChanged();
00415 }
00416 
00417 
00419 
00422 void LayoutManager::newLayout(LayoutConfig *layoutConfig)
00423 {
00424     //TODO: check pointers when opening a file
00425     //LayoutConfig *temp = configuration;
00426     configuration = layoutConfig;
00427     //if (temp)
00428     //{
00429     //    delete temp;
00430     //}
00431     view->updateGrids(configuration->getGrid(), true);
00432     if (layoutFileName == wxEmptyString)
00433     {
00434         layoutNeedNewFile = true;
00435     }
00436     //layoutModified = true;
00437     tablesChanged();
00438     resetIO();
00439     if (currentTable != wxEmptyString)
00440     {
00441         view->updateInputs(tableInputs[currentTable]);
00442         view->updateOutputs(tableOutputs[currentTable]);
00443     }
00444     else
00445     {
00446         vector<coordinate> empty;
00447         view->updateInputs(empty);
00448         view->updateOutputs(empty);
00449     }
00450     controller->elementChanged();
00451 }
00452 
00453 
00455 
00459 void LayoutManager::tablesChanged()
00460 {
00461     wxArrayString tableList = tableManager->getTableList();
00462     wxArrayString validList;
00463     if (configuration)
00464     {
00465         for (unsigned int i = 0; i < tableList.size(); i++)
00466         {
00467             if ((tableManager->getInputs(tableList[i]) <= configuration->getInputs()) && (tableManager->getOutputs(tableList[i]) <= configuration->getOutputs()))
00468             {
00469                 validList.Add(tableList[i]);
00470             }
00471         }
00472     }
00473     updateTTList(validList);
00474     updateIOList();
00475     controller->elementChanged();
00476 }
00477 
00478 
00480 
00483 LayoutConfig* LayoutManager::getLayout()
00484 {
00485     return configuration;
00486 }
00487 
00488 
00490 void LayoutManager::openFile()
00491 {
00492     //Ask for save
00493     if (layoutModified)
00494     {
00495         if (view->msgYesNo(_("Do you want to save modified space?")))
00496         {
00497             saveFile();
00498         }
00499     }
00500     
00501     wxString name =fileView.openFileChoose(view, _("Select a space file to open"), _("*.space"));
00502     
00503     if (name != wxEmptyString)
00504     {
00505         //Set te new filename if necessary
00506         layoutFileName = name;
00507         diskManager->openLayout(name);
00508     }
00509     controller->elementChanged();
00510 }
00511 
00512 
00514 
00518 bool LayoutManager::openPFile(wxString file)
00519 {
00520     layoutFileName = file;
00521     controller->elementChanged();
00522     return diskManager->openLayout(file);
00523     layoutModified = false;
00524     layoutNeedNewFile = false;
00525 }
00526 
00527 
00529 
00533 bool LayoutManager::saveFile()
00534 {
00535     if (layoutModified)
00536     {
00537         if (layoutNeedNewFile)
00538         {
00539             wxString name = fileView.saveFileChoose(view, _("Select a space file to save"), _("*.space"));
00540     
00541             if (name != wxEmptyString)
00542             {
00543                 layoutFileName = name;
00544             }
00545             else
00546             {
00547                 return false;
00548             }
00549         }
00550     
00551         //Set the extension for the filename
00552         wxFileName extension(layoutFileName);
00553         extension.SetExt(_("space"));
00554         layoutFileName = extension.GetFullPath();
00555         if (diskManager->saveLayout(configuration, layoutFileName))
00556         {
00557             layoutModified = false;
00558             layoutNeedNewFile = false;
00559         }
00560         else
00561         {
00562             view->errorMsg(_("Error saving space file!"));
00563             return false;
00564         }
00565     }
00566     return true;
00567 }
00568 
00569 
00571 bool LayoutManager::saveFileAs()
00572 {
00573     wxString name = fileView.saveFileChoose(view, _("Select a space file to save"), _("*.space"));
00574     
00575     if (name != wxEmptyString)
00576     {
00577         layoutFileName = name;
00578     }
00579     else
00580     {
00581         return false;
00582     }
00583     
00584     //Set the extension for the filename
00585     wxFileName extension(layoutFileName);
00586     extension.SetExt(_("space"));
00587     layoutFileName = extension.GetFullPath();
00588     if (diskManager->saveLayout(configuration, layoutFileName))
00589     {
00590         layoutModified = false;
00591         layoutNeedNewFile = false;
00592     }
00593     else
00594     {
00595         view->errorMsg(_("Error saving space file!"));
00596         return false;
00597     }
00598     return true;
00599 }
00600 
00601 
00603 
00607 void LayoutManager::updateIOList()
00608 {
00609     wxArrayString inputs;
00610     wxArrayString outputs;
00611     if (configuration)
00612     {
00613         if (currentTable != wxEmptyString)
00614         {     
00615             for (int i = 0; i < tableManager->getInputs(currentTable); i++)
00616             {
00617                 inputs.Add(wxString::Format(_("Input %d"), i + 1));
00618             }
00619     
00620             for (int i = 0; i < tableManager->getOutputs(currentTable); i++)
00621             {
00622                 outputs.Add(wxString::Format(_("Output %d"), i + 1));
00623             }
00624         }
00625     
00626         currentInput = 0;
00627         currentOutput = 0;
00628         view->updateInputList(inputs);
00629         view->updateOutputList(outputs);
00630         controller->elementChanged();
00631     }
00632 }
00633 
00634 
00636 
00640 void LayoutManager::rulesChanged()
00641 {
00642     wxArrayString ruleList = ruleManager->getRuleList();
00643     wxArrayString validList;
00644     for (unsigned int i = 0; i < ruleList.size(); i++)
00645     {
00646            validList.Add(ruleList[i]);
00647     }
00648     updateRuleList(validList);
00649     controller->elementChanged();
00650 }
00651 
00652 
00654 
00658 void LayoutManager::FPsChanged()
00659 {
00660     wxArrayString FPList = FPManager->getFPList();
00661     wxArrayString validList;
00662     for (unsigned int i = 0; i < FPList.size(); i++)
00663     {
00664        validList.Add(FPList[i]);
00665     }
00666     updateFPList(validList);
00667     controller->elementChanged();
00668 }
00669 
00670 
00672  void LayoutManager::assignInput()
00673  {
00674     assigningInput = true;
00675  }
00676  
00677  
00679  void LayoutManager::assignOutput()
00680  {
00681     assigningOutput = true;
00682  }
00683 
00684  
00686 
00689  void LayoutManager::escapePressed()
00690  {
00691     if (assigningInput)
00692     {
00693         assigningInput = false;
00694         view->onlyAssign(true);
00695     }
00696     else if (assigningOutput)
00697     {
00698         assigningOutput = false;
00699         view->onlyAssign(true);
00700     }
00701  }
00702 
00703  
00705 
00708  void LayoutManager::tableSelected(wxString table)
00709  {
00710     currentTable = table;
00711     updateIOList();
00712     view->updateInputs(tableInputs[currentTable]);
00713     view->updateOutputs(tableOutputs[currentTable]);
00714     view->updateCanvas();
00715  }
00716 
00717 
00719 
00727 bool LayoutManager::tableChecked(wxString table, bool checked)
00728  {
00729     if (tableEnabled.find(table) == tableEnabled.end())
00730     {
00731         return false;
00732     }
00733     for (map<wxString, bool>::iterator i = tableEnabled.begin(); i != tableEnabled.end(); i++)
00734     {
00735         (*i).second = false;
00736         view->checkTable((*i).first, false);
00737     }
00738     tableEnabled[table] = checked;
00739     view->checkTable(table, checked);
00740     controller->elementChanged();
00741     return true;
00742  }
00743  
00744  
00746 
00752  bool LayoutManager::ruleChecked(unsigned int rule, bool checked)
00753  {
00754     if (ruleEnabled.find(rule) == ruleEnabled.end())
00755     {
00756         return false;
00757     }
00758     ruleEnabled[rule] = checked;
00759     view->checkRule(wxString::Format(_("Rule %d"), rule), checked);
00760     return true;
00761  }
00762  
00763  
00765 
00771  bool LayoutManager::FPChecked(unsigned int FP, bool checked)
00772  {
00773     if (FPEnabled.find(FP) == FPEnabled.end())
00774     {
00775         return false;
00776     }
00777     FPEnabled[FP] = checked;
00778     view->checkFP(wxString::Format(_("Pattern %d"), FP), checked);
00779     return true;
00780  }
00781 
00782  
00784 
00789  bool LayoutManager::findString(wxArrayString list, wxString item)
00790  {
00791     for (unsigned int i = 0; i < list.size(); i++)
00792     {
00793         if (list[i] == item)
00794         {
00795             return true;
00796         }
00797     }
00798     return false;
00799  }
00800 
00801  
00803 
00806   void LayoutManager::inputSelected(int input)
00807  {
00808     currentInput = input;
00809  }
00810 
00811  
00813 
00816   void LayoutManager::outputSelected(int output)
00817  {
00818     currentOutput = output;
00819  }
00820 
00821  
00823 
00826  bool LayoutManager::isLayoutModified()
00827 {
00828     return layoutModified;
00829 }
00830 
00831 
00833 
00838 bool LayoutManager::inputAssigned(int x,int  y)
00839 {
00840     return findInputAssignment(tableInputs[currentTable], x, y);
00841 }
00842 
00843 
00845 
00850 bool LayoutManager::outputAssigned(int x,int  y)
00851 {
00852     return findOutputAssignment(tableOutputs[currentTable], x, y);
00853 }
00854 
00855 
00857 
00865 bool LayoutManager::findInputAssignment(vector<coordinate> list, int x, int y)
00866 {
00867     for (unsigned int i = 0; i < list.size();i++ )
00868     {
00869         if ((int)i != currentInput)
00870         {
00871             if ((list[i].x == x) && (list[i].y == y))
00872             {
00873                 return true;
00874             }
00875         }
00876     }
00877     return false;
00878 }
00879 
00880 
00882 
00890 bool LayoutManager::findOutputAssignment(vector<coordinate> list, int x, int y)
00891 {
00892     for (unsigned int i = 0; i < list.size();i++ )
00893     {
00894         if ((int)i != currentOutput)
00895         {
00896             if ((list[i].x == x) && (list[i].y == y))
00897             {
00898                 return true;
00899             }
00900         }
00901     }
00902     return false;
00903 }
00904 
00905 
00907 
00911 wxString LayoutManager::getFileName()
00912 {
00913     return layoutFileName;
00914 }
00915 
00916 
00918 
00921 map< wxString, vector<coordinate> > LayoutManager::getTableInputs()
00922 {
00923     return tableInputs;
00924 }
00925 
00926 
00928 
00931 map< wxString, vector<coordinate> > LayoutManager::getTableOutputs()
00932 {
00933     return tableOutputs;
00934 }
00935 
00936 
00938 
00941 map< wxString, bool> LayoutManager::getTableEnabled()
00942 {
00943     return tableEnabled;
00944 }
00945 
00946 
00948 
00951 map<unsigned int, bool> LayoutManager::getRuleEnabled()
00952 {
00953     return ruleEnabled;
00954 }
00955 
00956 
00958 
00961 map<unsigned int, bool> LayoutManager::getFPEnabled()
00962 {
00963     return FPEnabled;
00964 }
00965 
00966 
00968 
00972 bool LayoutManager::saveFilename(wxString file)
00973 {
00974     if (diskManager->saveLayout(configuration, file))
00975     {
00976         layoutFileName = file;
00977         return true;
00978     }
00979     else
00980     {
00981         return false;
00982     }
00983 }
00984 
00985 
00987 
00990 int LayoutManager::getTables()
00991 {
00992     return tableEnabled.size();
00993 }
00994 
00995 
00997 
01000 int LayoutManager::getRules()
01001 {
01002     return ruleEnabled.size();
01003 }
01004 
01005 
01007 
01010 int LayoutManager::getFPs()
01011 {
01012     return FPEnabled.size();
01013 }
01014 
01015 
01017 
01023 bool LayoutManager::setInput(wxString table, int input, int x, int y)
01024 {
01025     if (tableInputs.find(table) == tableInputs.end())
01026     {
01027         return false;
01028     }
01029     tableInputs[table][input].x = x;
01030     tableInputs[table][input].y = y;
01031     if (currentTable != wxEmptyString)
01032     {
01033         view->updateInputs(tableInputs[currentTable]);
01034         view->updateOutputs(tableOutputs[currentTable]);
01035     }
01036     view->updateCanvas();
01037     controller->elementChanged();
01038     return true;
01039 }
01040 
01041 
01043 
01049 bool LayoutManager::setOutput(wxString table, int output, int x, int y)
01050 {
01051     if (tableOutputs.find(table) == tableOutputs.end())
01052     {
01053         return false;
01054     }
01055     tableOutputs[table][output].x = x;
01056     tableOutputs[table][output].y = y;
01057     if (currentTable != wxEmptyString)
01058     {
01059         view->updateInputs(tableInputs[currentTable]);
01060         view->updateOutputs(tableOutputs[currentTable]);
01061     }
01062     view->updateCanvas();
01063     controller->elementChanged();
01064     return true;
01065 }
01066 
01067 
01069 void LayoutManager::clean()
01070 {
01071     //TODO: check for memory leak
01072     //LayoutConfig *temp = configuration;
01073     configuration = NULL;
01074     //if (temp)
01075     //{
01076     //    delete temp;
01077     //}
01078     view->updateGrids(Grid(), true);
01079     controller->elementChanged();
01080 }
01081 
01082 
01084 
01087 list <ForbiddenPattern> LayoutManager::getListFPEnabled()
01088 {
01089     list <ForbiddenPattern> result;
01090     for (map<unsigned int, bool>::iterator i = FPEnabled.begin(); i != FPEnabled.end(); i++)
01091     {
01092         if ((*i).second)
01093         {
01094             result.push_back(*FPManager->getFP((*i).first));
01095         }
01096     }
01097     return result;
01098 }
01099 
01100 
01102 
01105 list <Rule> LayoutManager::getListRuleEnabled()
01106 {
01107     list <Rule> result;
01108     for (map<unsigned int, bool>::iterator i = ruleEnabled.begin(); i != ruleEnabled.end(); i++)
01109     {
01110         if ((*i).second)
01111         {
01112             result.push_back(*ruleManager->getRule((*i).first));
01113         }
01114     }
01115     return result;
01116 }
01117 
01118 
01120 
01123 void LayoutManager::prepareSimulation()
01124 {
01125     controller->prepareSimulation();
01126 }
01127 
01128 
01130 void LayoutManager::startSimulation()
01131 {
01132     controller->startSimulation();
01133 }
01134 
01135 
01137 
01141 void LayoutManager::elementChanged()
01142 {
01143     view->enableCheckSimulation(true);
01144     view->enableStartSimulation(false);
01145 }
01146 
01147 
01149 
01152 TruthTable * LayoutManager::getTableSelected()
01153 {
01154     for (map<wxString, bool>::iterator i = tableEnabled.begin(); i != tableEnabled.end(); i++)
01155     {
01156         if ((*i).second)
01157         {
01158             return (tableManager->getTable((*i).first));
01159         }
01160     }
01161     
01162     //We should never reach this code
01163     //If we do... we're doomed :)
01164     return NULL;
01165 }
01166 
01167 
01169 
01173 vector<coordinate> LayoutManager::getTableInput(wxString table)
01174 {
01175     vector<coordinate> result;
01176     if (tableInputs.find(table) != tableInputs.end())
01177     {
01178         result = tableInputs[table];
01179     }
01180     return result;
01181 }
01182 
01183 
01185 
01189 vector<coordinate> LayoutManager::getTableOutput(wxString table)
01190 {
01191     vector<coordinate> result;
01192     if (tableOutputs.find(table) != tableOutputs.end())
01193     {
01194         result = tableOutputs[table];
01195     }
01196     return result;
01197 }
01198 
01199 
01201 
01206 bool LayoutManager::checkLayout()
01207 {
01208     bool result = false;
01209     wxString tableChecked;
01210     //Check there's a table selected
01211     for (map<wxString, bool>::iterator i = tableEnabled.begin(); i != tableEnabled.end(); i++)
01212     {
01213         if ((*i).second)
01214         {
01215             result = true;
01216             tableChecked = (*i).first;
01217         }
01218     }
01219     
01220     //Check the IO of the selected table
01221     if (result)
01222     {
01223         for (unsigned int i = 0; i < tableInputs[tableChecked].size(); i++)
01224         {
01225             if ((tableInputs[tableChecked][i].x == -1) || (tableInputs[tableChecked][i].y == -1))
01226             {
01227                 result = false;
01228             }
01229         }
01230         for (unsigned int i = 0; i < tableOutputs[tableChecked].size(); i++)
01231         {
01232             if ((tableOutputs[tableChecked][i].x == -1) || (tableOutputs[tableChecked][i].y == -1))
01233             {
01234                 result = false;
01235             }
01236         }
01237     }
01238     return result;
01239 }
01240 
01241 
01243 void LayoutManager::enableSimulation()
01244 {
01245     view->enableCheckSimulation(false);
01246     view->enableStartSimulation(true);
01247 }
01248 
01249 
01251 void LayoutManager::resetIO()
01252 {
01253     for (map< wxString, vector<coordinate> >::iterator i = tableInputs.begin(); i != tableInputs.end(); i++)
01254     {
01255         for (unsigned int j = 0; j < (*i).second.size(); j++)
01256         {
01257             (*i).second[j].x = -1;
01258             (*i).second[j].y = -1;
01259         }
01260     }
01261     for (map< wxString, vector<coordinate> >::iterator i = tableOutputs.begin(); i != tableOutputs.end(); i++)
01262     {
01263         for (unsigned int j = 0; j < (*i).second.size(); j++)
01264         {
01265             (*i).second[j].x = -1;
01266             (*i).second[j].y = -1;
01267         }
01268     }
01269 }

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