degate 0.1.1
GatePort.cc
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 #include "globals.h"
00023 #include "LogicModelObjectBase.h"
00024 #include "Net.h"
00025 #include "Layer.h"
00026 #include "LogicModel.h"
00027 
00028 #include "GatePort.h"
00029 #include "Gate.h"
00030 #include "GateTemplatePort.h"
00031 #include "Circle.h"
00032 
00033 #include <boost/format.hpp>
00034 #include <tr1/memory>
00035 
00036 using namespace degate;
00037 
00038 GatePort::GatePort(std::tr1::shared_ptr<Gate> _gate,
00039                    std::tr1::shared_ptr<GateTemplatePort> _gate_template_port,
00040                    unsigned int _diameter) :
00041   Circle(_gate->get_min_x() +
00042          _gate->get_relative_x_position_within_gate(_gate_template_port->get_x()),
00043          _gate->get_min_y() +
00044          _gate->get_relative_y_position_within_gate(_gate_template_port->get_y()),
00045          _diameter),
00046   gate(_gate),
00047   gate_template_port(_gate_template_port),
00048   template_port_id(_gate_template_port->get_object_id()) {
00049 
00050 }
00051 
00052 
00053 GatePort::GatePort(std::tr1::shared_ptr<Gate> _gate, unsigned int _diameter) :
00054   Circle(0, 0, _diameter),
00055   gate(_gate),
00056   template_port_id(0) {
00057   //set_x(gate->get_min_x());
00058   //set_y(gate->get_min_y());
00059 }
00060 
00061 
00062 void GatePort::set_template_port_type_id(object_id_t _template_port_id) {
00063   template_port_id = _template_port_id;
00064 }
00065 
00066 
00067 object_id_t GatePort::get_template_port_type_id() const {
00068   return template_port_id;
00069 }
00070 
00071 GateTemplatePort_shptr GatePort::get_template_port() {
00072   return gate_template_port;
00073 }
00074 
00075 const GateTemplatePort_shptr GatePort::get_template_port() const {
00076   return gate_template_port;
00077 }
00078 
00079 void GatePort::set_template_port(std::tr1::shared_ptr<GateTemplatePort>
00080                                  _gate_template_port) {
00081   gate_template_port = _gate_template_port;
00082   /* If the gate port is added to a gate afterwards, this caluclation will
00083    be ignored. But if the port already belongs to a gate and a a template is
00084    set afterwards, this calculation is used.
00085   */
00086   assert(gate != NULL);
00087   set_x(gate->get_min_x() +
00088         gate->get_relative_x_position_within_gate(gate_template_port->get_x()));
00089   set_y(gate->get_min_y() +
00090         gate->get_relative_y_position_within_gate(gate_template_port->get_y()));
00091 }
00092 
00093 
00094 bool GatePort::has_template_port() const {
00095   return gate_template_port != NULL;
00096 }
00097 
00098 bool GatePort::is_assigned_to_a_gate() const {
00099   return gate != NULL;
00100 }
00101 
00102 
00103 std::tr1::shared_ptr<Gate> GatePort::get_gate() {
00104   return gate;
00105 }
00106 
00107 const std::string GatePort::get_descriptive_identifier() const {
00108 
00109   if(has_template_port() && is_assigned_to_a_gate() &&
00110      gate->has_template()) {
00111 
00112     if(gate->has_name()) {
00113       boost::format fmter("%1%: %2% (%3%)");
00114       fmter
00115         % gate->get_name()
00116         % gate_template_port->get_name()
00117         % gate->get_gate_template()->get_name();
00118       return fmter.str();
00119     }
00120     else {
00121       boost::format fmter("%1% (%2%, gate=%3%)");
00122       fmter
00123         % gate_template_port->get_name()
00124         % gate->get_gate_template()->get_name()
00125         % gate->get_object_id();
00126       return fmter.str();
00127     }
00128   }
00129   else {
00130     boost::format fmter("Gate port %1%");
00131     fmter % get_object_id();
00132     return fmter.str();
00133   }
00134 
00135 }
00136 
00137 
00138 const std::string GatePort::get_object_type_name() const {
00139   return std::string("Gate port");
00140 }
00141 
00142 
00143 void GatePort::print(std::ostream & os, int n_tabs) const {
00144 
00145   const GateTemplatePort_shptr tmpl_port = get_template_port();
00146 
00147   os
00148     << gen_tabs(n_tabs) << "Gate port name    : " << get_name() << std::endl
00149     << gen_tabs(n_tabs) << "Object ID         : " << get_object_id() << std::endl
00150     << gen_tabs(n_tabs) << "Template Port ID  : " <<
00151     (has_template_port() ? tmpl_port->get_object_id() : 0)  << std::endl
00152     << gen_tabs(n_tabs) << "Diameter          : " << get_diameter() << std::endl
00153     << gen_tabs(n_tabs) << "Port position     : " << get_x() << " / " << get_y() << std::endl
00154     << gen_tabs(n_tabs) << "Bounding box      : " << get_bounding_box().to_string() << std::endl
00155 
00156     << std::endl;
00157     ;
00158 
00159 }
00160 
00161 
00162 void GatePort::set_x(int x) {
00163   Circle::set_x(x);
00164   notify_shape_change();
00165 }
00166 
00167 
00168 void GatePort::set_y(int y) {
00169   Circle::set_y(y);
00170   notify_shape_change();
00171 }
00172 
00173 void GatePort::shift_x(int delta_x) {
00174   Circle::shift_x(delta_x);
00175   notify_shape_change();
00176 }
00177 
00178 void GatePort::shift_y(int delta_y) {
00179   Circle::shift_y(delta_y);
00180   notify_shape_change();
00181 }
00182 
00183 void GatePort::set_diameter(unsigned int diameter) {
00184   Circle::set_diameter(diameter);
00185   notify_shape_change();
00186 }