degate  0.1.2
GatePort.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 __GATEPORT_H__
00024 #define __GATEPORT_H__
00025 
00026 #include "globals.h"
00027 
00028 #include "ConnectedLogicModelObject.h"
00029 #include "Rectangle.h"
00030 #include "Gate.h"
00031 #include "GateTemplatePort.h"
00032 #include <set>
00033 
00034 #include <memory>
00035 
00036 namespace degate {
00037 
00038   /**
00039    * This class represents a port of a gate.
00040    * @todo Dispatch get_fill/frame_color() calls to
00041    *   GateTemplatePort::get_xxx_color(). Make sure, that colors
00042    *   are updated when changes are made in the PortColorManager.
00043    */
00044   class GatePort : public Circle, public ConnectedLogicModelObject {
00045 
00046   private:
00047 
00048     std::shared_ptr<Gate> gate;
00049     std::shared_ptr<GateTemplatePort> gate_template_port;
00050     object_id_t template_port_id;
00051 
00052   public:
00053 
00054 
00055     explicit GatePort() {};
00056     
00057     /**
00058      * Create a gate port and set a "reference" to the the template port.
00059      *
00060      * @param _gate A shared pointer to the gate, the port is created for.
00061      * @param _gate_template_port A shared pointer to a template port.
00062      * @param _diameter The diameter of the port.
00063      */
00064     GatePort(std::shared_ptr<Gate> _gate,
00065              std::shared_ptr<GateTemplatePort> _gate_template_port,
00066              unsigned int _diameter = 5);
00067 
00068     /**
00069      * Create a gate port.
00070      *
00071      * @param _gate A shared pointer to the gate, the port is created for.
00072      * @param diameter The diameter of the port.
00073      */
00074     GatePort(std::shared_ptr<Gate> _gate, unsigned int _diameter = 5);
00075 
00076 
00077     /**
00078      * The destructor.
00079      */
00080 
00081     virtual ~GatePort() {}
00082 
00083     //@{
00084     DeepCopyable_shptr cloneShallow() const;
00085     void cloneDeepInto(DeepCopyable_shptr destination, oldnew_t *oldnew) const;
00086     //@}
00087 
00088     /**
00089      * Set the ID of the template port.
00090      */
00091 
00092     virtual void set_template_port_type_id(object_id_t _template_port_id);
00093 
00094     /**
00095      * Get the ID of the template port.
00096      */
00097 
00098     virtual object_id_t get_template_port_type_id() const;
00099 
00100     /**
00101      * Get the template port.
00102      */
00103 
00104     virtual GateTemplatePort_shptr get_template_port();
00105 
00106     /**
00107      * Get the template port.
00108      */
00109 
00110     virtual const GateTemplatePort_shptr get_template_port() const;
00111 
00112     /**
00113      * Set the template port.
00114      */
00115 
00116     virtual void set_template_port(std::shared_ptr<GateTemplatePort>
00117                                    _gate_template_port);
00118 
00119 
00120     /**
00121      * Check if there is a template port defined.
00122      */
00123 
00124     virtual bool has_template_port() const;
00125 
00126     /**
00127      * Check if a gate port already belongs to a gate.
00128      * Normally a gate port belongs to a gate.
00129      */
00130 
00131     virtual bool is_assigned_to_a_gate() const;
00132 
00133 
00134     /**
00135      * Get the gate, this gate port belongs to.
00136      * @return Returns a shared pointer to a gate. A pointer value
00137      *   of NULL indicates, that the gate port is not assigned to a gate.
00138      * @see has_gate()
00139      */
00140 
00141     std::shared_ptr<Gate> get_gate();
00142 
00143 
00144     /**
00145      * Get a human readable string that describes the whole
00146      * logic model object. The string should be unique in order
00147      * to let the user identify the concrete object. But that
00148      * is not a must.
00149      */
00150 
00151     virtual const std::string get_descriptive_identifier() const;
00152 
00153     /**
00154      * Get a human readable string that names the object type.
00155      * Here it is "Gate port".
00156      */
00157 
00158     virtual const std::string get_object_type_name() const;
00159 
00160 
00161     /**
00162      * Print gate port.
00163      */
00164 
00165     void print(std::ostream & os = std::cout, int n_tabs = 0) const;
00166 
00167 
00168 
00169     /**
00170      * Set the absolute position of a port.
00171      */
00172 
00173     void set_x(int x);
00174 
00175     /**
00176      * Set the absolute position of a port.
00177      */
00178 
00179     void set_y(int y);
00180 
00181 
00182     void shift_x(int delta_x);
00183     void shift_y(int delta_y);
00184     void set_diameter(unsigned int diameter);
00185 
00186 
00187 
00188     virtual bool in_bounding_box(BoundingBox const& bbox) const {
00189       return Circle::in_bounding_box(bbox);
00190     }
00191 
00192     virtual BoundingBox const& get_bounding_box() const {
00193       return Circle::get_bounding_box();
00194     }
00195 
00196     virtual bool in_shape(int x, int y, int max_distance = 0) const {
00197       return Circle::in_shape(x, y, max_distance);
00198     }
00199 
00200   };
00201 
00202 }
00203 
00204 #endif