degate 0.1.1
Gate.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 __GATE_H__
00023 #define __GATE_H__
00024 
00025 #include <tr1/memory>
00026 
00027 #include <degate.h>
00028 #include <Layer.h>
00029 
00030 #include "GatePort.h"
00031 #include "PlacedLogicModelObject.h"
00032 #include "Rectangle.h"
00033 #include "GateTemplate.h"
00034 #include "GateTemplatePort.h"
00035 #include <set>
00036 
00037 namespace degate {
00038 
00039   /**
00040    * The class Gate defines and implements a physically placed gate.
00041    * @todo The template type id makes only sense, if ports have the
00042    *  same thing with remplate ports. Maybe removing this is an option, because there are
00043    *  easier ways to relaod the gate library.
00044    */
00045 
00046   class Gate : public Rectangle, public PlacedLogicModelObject {
00047 
00048   public:
00049 
00050     enum ORIENTATION {
00051       ORIENTATION_UNDEFINED = 0,
00052       ORIENTATION_NORMAL = 1,
00053       ORIENTATION_FLIPPED_UP_DOWN = 2,
00054       ORIENTATION_FLIPPED_LEFT_RIGHT = 3,
00055       ORIENTATION_FLIPPED_BOTH = 4
00056     };
00057 
00058     typedef std::set< GatePort_shptr >::iterator port_iterator;
00059     typedef std::set< GatePort_shptr >::const_iterator port_const_iterator;
00060 
00061   private:
00062 
00063     GateTemplate_shptr gate_template;
00064 
00065     std::set<GatePort_shptr> gate_ports;
00066 
00067     ORIENTATION orientation;
00068 
00069     object_id_t template_type_id;
00070 
00071   public:
00072 
00073 
00074     /**
00075      * Create a gate.
00076      */
00077     Gate(int _min_x, int _max_x, int _min_y, int _max_y,
00078          ORIENTATION _orientation = ORIENTATION_UNDEFINED);
00079 
00080     /**
00081      * Create a gate.
00082      */
00083 
00084     Gate(BoundingBox const& bounding_box,
00085          ORIENTATION _orientation = ORIENTATION_UNDEFINED);
00086 
00087 
00088     /**
00089      * Destroy a gate.
00090      */
00091 
00092     virtual ~Gate();
00093 
00094     /**
00095      * Add a gate port.
00096      *
00097      * If you add a gate port to a gate you have to make some changes to the logic model.
00098      * Please call method LogicModel::update_ports()
00099      * @exception InvalidObjectIDException This exception is
00100      *   thrown, if the port has no valid object ID.
00101      * @exception DegateLogicException Is thrown if \p gate_port has
00102      *   no valid GateTemplatePort or if the gate has no valid
00103      *   orientation.
00104      * @see LogicModel::update_ports()
00105      */
00106 
00107     virtual void add_port(GatePort_shptr gate_port);
00108 
00109     /**
00110      * Remove a gate port.
00111      * @se add_port()
00112      * @see LogicModel::update_ports()
00113      */
00114 
00115     virtual void remove_port(GatePort_shptr gate_port);
00116 
00117     /**
00118      * Get a gate port by a template port.
00119      */
00120 
00121     virtual GatePort_shptr get_port_by_template_port(GateTemplatePort_shptr template_port);
00122 
00123 
00124     /**
00125      * Set the ID of the corresponding template.
00126      *
00127      * This is useful, if there is a cell type defined for this
00128      * gate, but the cell library is not available, e.g. if
00129      * the gate library is unloaded in order to load another
00130      * version of the gate library. In this case we can't work
00131      * with (shared) pointers and need way to remember the cell
00132      * type.
00133      *
00134      * If you use method set_gate_template() you don't need to call
00135      * this method.
00136      *
00137      * @param template_type_id The ID of the template (cell type). A
00138      *      value of zero indicates, that there is no template for this
00139      *      gate.
00140      * @see set_gate_template()
00141      */
00142 
00143     virtual void set_template_type_id(object_id_t template_type_id);
00144 
00145     /**
00146      * Get the ID of the corresponding template.
00147      * @see set_template_type_id()
00148      */
00149 
00150     virtual object_id_t get_template_type_id() const;
00151 
00152 
00153     /**
00154      * A gate usually has a gate template. The gate template specifies common
00155      * properties. Use that function to set the gate template.
00156      * If the template has other dimensions than the gate, the gate shape is
00157      * adjusted, so that the gate's dimension complies with the template's one.
00158      * The attributes min_x and min_y are preserved in that case.
00159      *
00160      * This method updates the template type ID as well.
00161      * @see set_template_type_id()
00162      */
00163 
00164     virtual void set_gate_template(std::tr1::shared_ptr<GateTemplate> gate_template);
00165 
00166     /**
00167      * Get the gate template.
00168      * @see set_gate_template()
00169      */
00170 
00171     virtual std::tr1::shared_ptr<GateTemplate> get_gate_template() const;
00172 
00173     /**
00174      * Check if the gate has a template type set.
00175      * @return Returns true, if there is a template for this gate.
00176      *    A template is present, if the gate has a shared pointer to
00177      *    the template. That is that there is a object you can work with.
00178      *    Just having a template ID is not sufficient. If there is no
00179      *    shared pointer to the template, false is returned.
00180      */
00181 
00182     virtual bool has_template() const;
00183 
00184 
00185     /**
00186      * Remove template from gate. This will destroy all gate ports, too.
00187      */
00188 
00189     virtual void remove_template();
00190 
00191     /**
00192      * Check if a gate object has a port, that references a given template port.
00193      * This method bases on shared pointers not on simple port IDs.
00194      */
00195 
00196     virtual bool has_template_port(GateTemplatePort_shptr template_port) const;
00197 
00198     /**
00199      * If a physically placed gate has a template. This template
00200      * defines the appearance of the gate in terms of an image.
00201      * Because the physically placed gate can have another orientation than
00202      * the template image, you need to set the image orientation in
00203      * relation to the master image.
00204      */
00205 
00206     virtual void set_orientation(ORIENTATION _orientation);
00207 
00208     /**
00209      * Get the orientation relative to the master image.
00210      */
00211 
00212     virtual ORIENTATION get_orientation() const;
00213 
00214 
00215     /**
00216      * Check if the gate has a valid orientation.
00217      */
00218 
00219     bool has_orientation() const;
00220 
00221      /**
00222      * Get the orientation as a human readable string.
00223      */
00224 
00225     virtual std::string get_orienation_type_as_string() const;
00226 
00227 
00228     /**
00229      * Get an iterator to iterated over ports.
00230      */
00231 
00232     virtual port_iterator ports_begin();
00233 
00234     /**
00235      * Get an iterator to iterated over ports.
00236      */
00237 
00238     virtual port_const_iterator ports_begin() const;
00239 
00240     /**
00241      * Get an end iterator.
00242      * @see ports_begin()
00243      */
00244 
00245     virtual port_iterator ports_end();
00246 
00247     /**
00248      * Get an end iterator.
00249      * @see ports_begin()
00250      */
00251 
00252     virtual port_const_iterator ports_end() const;
00253 
00254     /**
00255      * Get the x-coordinate relative to min_x depending on the gate's orientation.
00256      * @param rel_x The x-coordinate realtive to min_x.
00257      * @exception DegateRuntimeException This exception is thrown if the object has an
00258      *   undefined gate orientation.
00259      * @see has_orientation()
00260      */
00261 
00262     virtual unsigned int get_relative_x_position_within_gate(int rel_x) const;
00263 
00264     /**
00265      * Get the y-coordinate relative to min_y depending on the gate's orientation.
00266      * @param rel_y The y-coordinate realtive to min_y.
00267      * @exception DegateRuntimeException This exception is thrown if the object has an
00268      *   undefined gate orientation.
00269      * @see has_orientation()
00270      */
00271 
00272     virtual unsigned int get_relative_y_position_within_gate(int rel_y) const;
00273 
00274     /**
00275      * Get a human readable string that describes the whole
00276      * logic model object. The string should be unique in order
00277      * to let the user identify the concrete object. But that
00278      * is not a must.
00279      */
00280 
00281     virtual const std::string get_descriptive_identifier() const;
00282 
00283     /**
00284      * Get a human readable string that names the object type.
00285      * Here it is "Gate".
00286      */
00287 
00288     virtual const std::string get_object_type_name() const;
00289 
00290     /**
00291      * Print gate.
00292      */
00293 
00294     void print(std::ostream & os = std::cout, int n_tabs = 0) const;
00295 
00296 
00297 
00298     bool in_shape(int x, int y, int max_distance = 0) const {
00299       return Rectangle::in_shape(x, y, max_distance);
00300     }
00301 
00302     void shift_x(int delta_x) {
00303       Rectangle::shift_x(delta_x);
00304     }
00305 
00306     void shift_y(int delta_y) {
00307       Rectangle::shift_y(delta_y);
00308     }
00309 
00310 
00311     virtual bool in_bounding_box(BoundingBox const& bbox) const {
00312       return Rectangle::in_bounding_box(bbox);
00313     }
00314 
00315     virtual BoundingBox const& get_bounding_box() const {
00316       return Rectangle::get_bounding_box();
00317     }
00318 
00319 
00320   };
00321 
00322 
00323   typedef std::tr1::shared_ptr<Gate> Gate_shptr;
00324 
00325 }
00326 
00327 #endif