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