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