degate  0.1.2
Grid.h
Go to the documentation of this file.
00001 /* -*-c++-*-
00002 
00003  This file is part of the IC reverse engineering tool degate.
00004 
00005  Copyright 2008, 2009, 2010 by Martin Schobert
00006 
00007  Degate is free software: you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation, either version 3 of the License, or
00010  any later version.
00011 
00012  Degate is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with degate. If not, see <http://www.gnu.org/licenses/>.
00019 
00020 */
00021 
00022 #ifndef __GRID_H__
00023 #define __GRID_H__
00024 
00025 #include <list>
00026 #include <memory>
00027 
00028 namespace degate {
00029 
00030   /**
00031    * Base class for grid types.
00032    */
00033 
00034   class Grid {
00035 
00036   public:
00037 
00038     /**
00039      * Enum to declare the type of a grid.
00040      */
00041 
00042     enum ORIENTATION {
00043       UNDEFINED = 0,
00044       HORIZONTAL = 1,
00045       VERTICAL = 2
00046     };
00047 
00048   private:
00049 
00050     ORIENTATION orientation;
00051     bool enabled;
00052 
00053   public:
00054     typedef std::list<int> grid_set;
00055     typedef grid_set::const_iterator grid_iter;
00056 
00057     /**
00058      * Create a new grid.
00059      * @param _orientation This parameter defines the orientation. E.g. a horizontal
00060      *   grid that defines horizontal spacings. This means that lines are vertical.
00061      * @param _enabled You can enable/disable grids. With this parameter you can
00062      *   control whether the grid is enabled od disabled.
00063      */
00064 
00065     Grid(ORIENTATION _orientation, bool _enabled = false) :
00066       orientation(_orientation),
00067       enabled(_enabled) {}
00068 
00069     /**
00070      * The destructor.
00071      */
00072 
00073     virtual ~Grid() {}
00074 
00075     /**
00076      * Get an iterator to iterate over grid offsets.
00077      */
00078 
00079     virtual grid_iter begin() const = 0;
00080 
00081     /**
00082      * Get an end marker for ther iteration.
00083      */
00084 
00085     virtual grid_iter end() const = 0;
00086 
00087     /**
00088      * Clear the grid.
00089      */
00090 
00091     virtual void clear() = 0;
00092 
00093     /**
00094      * Set the state, whether a grid is enabled or not.
00095      */
00096 
00097     virtual void set_enabled(bool state = true) { enabled = state; }
00098 
00099     /**
00100      * Check the state, whether a grid is enabled or not.
00101      */
00102 
00103     virtual bool is_enabled() const { return enabled; }
00104 
00105     /**
00106      * Get the nearest offset, that is on grid.
00107      */
00108 
00109     virtual int snap_to_grid(int pos) const = 0;
00110 
00111     /**
00112      * Get the grid orientation.
00113      */
00114 
00115     virtual ORIENTATION get_orientation() const { return orientation; }
00116 
00117     /**
00118      * Check grid orientation: this is if the spacing is horizontal (vertical lines).
00119      */
00120 
00121     virtual bool is_horizontal() const { return orientation == HORIZONTAL; }
00122 
00123     /**
00124      * Check grid orientation: this is if the spacing is vertical (horizontal lines.)
00125      */
00126 
00127     virtual bool is_vertical() const { return orientation == VERTICAL; }
00128 
00129   };
00130 
00131   typedef std::shared_ptr<Grid> Grid_shptr;
00132 }
00133 
00134 #endif