/home/enzo/treballs/fib/pfc/nanocomp/src/layoutConfig.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.16 $
00020 
00021 #include "layoutConfig.hpp"
00022 
00023 
00025 
00031 LayoutConfig::LayoutConfig(int width, int height, int inputs, int outputs)
00032     :grid(width, height)
00033 {
00034     this->width = width;
00035     this->height = height;
00036     this->inputs = inputs;
00037     this->outputs = outputs;
00038     assignedInputs = 0;
00039     assignedOutputs = 0;
00040 }
00041 
00042 
00044 LayoutConfig::~LayoutConfig()
00045 {
00046 }
00047 
00048 
00050 
00064 bool LayoutConfig::cellChanged(int x, int y, bool assigningInput, bool assigningOutput, vector<coordinate> listInputs, vector<coordinate> listOutputs)
00065 {
00066     if (assigningInput)
00067     {
00068         //Only do something if the selected cell is an input
00069         if (grid(x, y) == nINPUT)
00070         {
00071             return true;
00072         }
00073         else
00074         {
00075             return false;
00076         }
00077     }
00078     else if (assigningOutput)
00079     {
00080         //Only do something if the selected cell is an output
00081         if (grid(x, y) == nOUTPUT)
00082         {
00083             return true;
00084         }
00085         else
00086         {
00087             return false;
00088         }
00089     }
00090     else //Status change mode
00091     {
00092         switch (grid(x, y))
00093         {
00094             case nNOSPACE:
00095             {
00096                 grid(x, y) = nENABLED;
00097                 return true;
00098             }
00099             case nDONTCARE:
00100             {
00101                 grid(x, y) = nNOSPACE;
00102                 return true;
00103             }
00104             case nENABLED:
00105             {
00106                 grid(x, y) = nDISABLED;
00107                 return true;
00108             }
00109             case nDISABLED:
00110             {
00111                 //Input only if there are inputs left to be set
00112                 //if not we skip the nINPUT status
00113                  if (assignedInputs < inputs)
00114                 {
00115                     grid(x, y) = nINPUT;
00116                     assignedInputs++;
00117                     return true;
00118                 }
00119                 else
00120                 {
00121                     //Output only if there are outputs left to be set
00122                     //if not we skip the nOUTPUT status
00123                     if (assignedOutputs < outputs)
00124                     {
00125                         grid(x, y) = nOUTPUT;
00126                         assignedOutputs++;
00127                         return true;
00128                     }
00129                     else
00130                     {
00131                         //Output to no cell
00132                         grid(x, y) = nDONTCARE;
00133                         return true;
00134                     }
00135                 }
00136             }
00137             case nINPUT:
00138             {
00139                 if (!findCoordinate(listInputs, x, y))
00140                 {
00141                     if (assignedOutputs < outputs)
00142                     {
00143                         grid(x, y) = nOUTPUT;
00144                         assignedInputs--;
00145                         assignedOutputs++;
00146                         return true;
00147                     }
00148                     else
00149                     {
00150                         //Output to don't care
00151                         grid(x, y) = nDONTCARE;
00152                         assignedInputs--;
00153                         return true;
00154                     }
00155                 }
00156                 else
00157                 {
00158                     return false;
00159                 }
00160             }
00161             case nOUTPUT:
00162             {
00163                 if (!findCoordinate(listOutputs, x, y))
00164                 {
00165                     grid(x, y) = nDONTCARE;
00166                     assignedOutputs--;
00167                     return true;
00168                 }
00169                 else
00170                 {
00171                     return false;
00172                 }
00173             }
00174             default:
00175             {
00176                 return false;
00177             }
00178         }
00179     }
00180 }
00181 
00182 
00184 
00187 Grid LayoutConfig::getGrid()
00188 {
00189     return grid;    
00190 }
00191 
00192 
00194 
00197 int LayoutConfig::getWidth()
00198 {
00199     return width;
00200 }
00201 
00202 
00204 
00207 int LayoutConfig::getHeight()
00208 {
00209     return height;
00210 }
00211 
00212 
00214 
00221 bool LayoutConfig::cellChanged(int x, int y, int status)
00222 {
00223     if (status == nINPUT)
00224     {
00225         assignedInputs++;
00226     }
00227     if (status == nOUTPUT)
00228     {
00229         assignedOutputs++;
00230     }
00231     
00232     grid(x, y) = status;
00233     return true;
00234 }
00235 
00236 
00238 
00241 int LayoutConfig::getInputs()
00242 {
00243     return inputs;
00244 }
00245 
00246 
00248 
00251 int LayoutConfig::getOutputs()
00252 {
00253     return outputs;
00254 }
00255 
00256 
00258 
00265 bool LayoutConfig::findCoordinate(vector<coordinate> list, int x, int y)
00266 {
00267     for (unsigned int i = 0; i < list.size(); i++)
00268     {
00269         if (list[i].x == x && list[i].y == y)
00270         {
00271             return true;
00272         }
00273     }
00274     return false;
00275 }
00276 
00277 
00279 
00282 matrix LayoutConfig::getMatrix()
00283 {
00284     return grid.getCells();
00285 }

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