degate  0.1.2
RegularGrid.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 __REGULARGRID_H__
00023 #define __REGULARGRID_H__
00024 
00025 #include "Grid.h"
00026 #include "globals.h"
00027 
00028 #include <algorithm>
00029 #include <memory>
00030 
00031 namespace degate {
00032 
00033   /**
00034    * Represents a grid with equidistant spacing between grid lines.
00035    */
00036   class RegularGrid : public Grid {
00037   private:
00038     double distance;
00039     int min, max;
00040     grid_set grid_offsets;
00041 
00042     void precalc_steps();
00043   public:
00044     RegularGrid(Grid::ORIENTATION orientation) : Grid(orientation) {
00045       min = 0;
00046       max = 0;
00047       distance = 0;
00048     }
00049 
00050     virtual ~RegularGrid() {}
00051 
00052     virtual grid_iter begin() const { return grid_offsets.begin(); }
00053     virtual grid_iter end() const { return grid_offsets.end(); }
00054     virtual void clear() {
00055       distance = 0;
00056       min = max = 0;
00057       grid_offsets.clear();
00058     }
00059 
00060     virtual int get_min() const { return min; }
00061     virtual int get_max() const { return max; }
00062     virtual void set_range(int min, int max) {
00063       this->min = std::min(min, max);
00064       this->max = std::max(min, max);
00065       precalc_steps();
00066     }
00067 
00068     virtual void set_distance(double distance) {
00069       assert(distance >= 0);
00070       this->distance = abs(static_cast<long>(distance));
00071       precalc_steps();
00072     }
00073     virtual double get_distance() const { return distance; }
00074     virtual int snap_to_grid(int pos) const;
00075 
00076   };
00077 
00078   typedef std::shared_ptr<RegularGrid> RegularGrid_shptr;
00079 }
00080 
00081 #endif