degate  0.1.2
Via.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 "Via.h"
00024 #include <XmlRpc.h>
00025 #include <boost/format.hpp>
00026 
00027 using namespace degate;
00028 
00029 Via::Via(int _x, int _y, diameter_t _diameter, Via::DIRECTION _direction) :
00030   Circle(_x, _y, _diameter),
00031   direction(_direction) {
00032 }
00033 
00034 Via::~Via() {}
00035 
00036 DeepCopyable_shptr Via::cloneShallow() const {
00037   auto clone = std::make_shared<Via>();
00038   clone->direction = direction;
00039   return clone;
00040 }
00041 
00042 void Via::cloneDeepInto(DeepCopyable_shptr dest, oldnew_t *oldnew) const {
00043   Circle::cloneDeepInto(dest, oldnew);
00044   ConnectedLogicModelObject::cloneDeepInto(dest, oldnew);
00045   RemoteObject::cloneDeepInto(dest, oldnew);
00046 }
00047 
00048 Via::DIRECTION Via::get_direction() const {
00049   return direction;
00050 }
00051 
00052 void Via::set_direction(Via::DIRECTION dir) {
00053   direction = dir;
00054 }
00055 
00056 const std::string Via::get_direction_as_string() const {
00057   switch(direction) {
00058   case DIRECTION_UP: return std::string("up");
00059   case DIRECTION_DOWN: return std::string("down");
00060   case DIRECTION_UNDEFINED:
00061   default: return std::string("undefined");
00062   }
00063 }
00064 
00065 Via::DIRECTION Via::get_via_direction_from_string(std::string const& via_direction_str) {
00066 
00067   if(via_direction_str == "up") return Via::DIRECTION_UP;
00068   else if(via_direction_str == "down") return Via::DIRECTION_DOWN;
00069   else if(via_direction_str == "undefined") return Via::DIRECTION_UNDEFINED;
00070   else throw DegateRuntimeException("Can't parse via direction type.");
00071 }
00072 
00073 const std::string Via::get_descriptive_identifier() const {
00074   if(has_name()) {
00075     boost::format fmter("via %1% (%2%)");
00076     fmter % get_name() % get_object_id();
00077     return fmter.str();
00078   }
00079   else {
00080     boost::format fmter("via (%1%)");
00081     fmter % get_object_id();
00082     return fmter.str();
00083   }
00084 }
00085 
00086 const std::string Via::get_object_type_name() const {
00087   return std::string("Via");
00088 }
00089 
00090 
00091 void Via::print(std::ostream & os, int n_tabs) const {
00092 
00093   os
00094     << gen_tabs(n_tabs) << "Via name          : " << get_name() << std::endl
00095     << gen_tabs(n_tabs) << "Object ID         : " << get_object_id() << std::endl
00096     << gen_tabs(n_tabs) << "Via position      : " << get_x() << " / " << get_y() << std::endl
00097     << gen_tabs(n_tabs) << "Bounding box      : " << Circle::get_bounding_box().to_string() << std::endl
00098     << std::endl;
00099     ;
00100 
00101 }
00102 
00103 //bool Via::in_shape(int x, int y) const {
00104 //  return Circle::in_shape(x,y);
00105 //}
00106 
00107 void Via::shift_x(int delta_x) {
00108   Circle::shift_x(delta_x);
00109   notify_shape_change();
00110 }
00111 
00112 void Via::shift_y(int delta_y) {
00113   Circle::shift_y(delta_y);
00114   notify_shape_change();
00115 }
00116 
00117 void Via::set_x(int x) {
00118   Circle::set_x(x);
00119   notify_shape_change();
00120 }
00121 
00122 void Via::set_y(int y) {
00123   Circle::set_y(y);
00124   notify_shape_change();
00125 }
00126 
00127 void Via::set_diameter(unsigned int diameter) {
00128   Circle::set_diameter(diameter);
00129   notify_shape_change();
00130 }
00131 
00132 
00133 object_id_t Via::push_object_to_server(std::string const& server_url) {
00134 
00135   try {
00136 
00137     xmlrpc_c::paramList params;
00138     params.add(xmlrpc_c::value_string("add"));
00139     params.add(xmlrpc_c::value_string("via"));
00140 
00141     Layer_shptr layer = get_layer();
00142     assert(layer != NULL);
00143     params.add(xmlrpc_c::value_int(layer->get_layer_id()));
00144 
00145     params.add(xmlrpc_c::value_int(get_x()));
00146     params.add(xmlrpc_c::value_int(get_y()));
00147     params.add(xmlrpc_c::value_int(get_diameter()));
00148     params.add(xmlrpc_c::value_string(get_direction_as_string()));
00149 
00150     int const transaction_id =
00151       xmlrpc_c::value_int(remote_method_call(server_url, "degate.push", params));
00152 
00153     set_remote_object_id(transaction_id);
00154 
00155     std::cout << "Pushed via to server. remote id is: " << transaction_id << std::endl;
00156     return transaction_id;
00157   }
00158   catch(std::exception const& e) {
00159     std::cerr << "Client threw error: " << e.what() << std::endl;
00160     throw XMLRPCException(e.what());
00161   }
00162   catch(...) {
00163     std::cerr << "Client threw unexpected error." << std::endl;
00164     throw XMLRPCException("Client threw unexpected error.");
00165   }
00166 
00167 }