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