degate 0.1.1
Project.cc
Go to the documentation of this file.
00001 /*
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 "Project.h"
00024 
00025 #include <string>
00026 #include <iostream>
00027 #include <ctime>
00028 #include <cstdlib>
00029 
00030 using namespace std;
00031 using namespace degate;
00032 
00033 Project::Project(length_t width, length_t height) :
00034   bounding_box(width, height),
00035   logic_model(new LogicModel(width, height)),
00036   port_color_manager(new PortColorManager()) {
00037   init_default_values();
00038 }
00039 
00040 
00041 Project::Project(length_t width, length_t height, std::string const& _directory, unsigned int layers) :
00042   bounding_box(width, height),
00043   directory(_directory),
00044   logic_model(new LogicModel(width, height, layers)),
00045   port_color_manager(new PortColorManager()) {
00046   init_default_values();
00047 }
00048 
00049 Project::~Project() {
00050 }
00051 
00052 void Project::set_project_directory(std::string const& _directory) {
00053   directory = _directory;
00054 }
00055 
00056 std::string const& Project::get_project_directory() {
00057   return directory;
00058 }
00059 
00060 BoundingBox const& Project::get_bounding_box() const {
00061   return bounding_box;
00062 }
00063 
00064 unsigned int Project::get_width() const {
00065   return bounding_box.get_width();
00066 }
00067 
00068 unsigned int Project::get_height() const {
00069   return bounding_box.get_height();
00070 }
00071 
00072 LogicModel_shptr Project::get_logic_model() {
00073   return logic_model;
00074 }
00075 
00076 
00077 void Project::set_logic_model(LogicModel_shptr _logic_model) {
00078   logic_model = _logic_model;
00079 }
00080 
00081 
00082 void Project::set_name(std::string _name) {
00083   name = _name;
00084 }
00085 
00086 std::string const& Project::get_name() const {
00087   return name;
00088 }
00089 
00090 void Project::set_description(std::string _description) {
00091   description = _description;
00092 }
00093 
00094 std::string const& Project::get_description() const {
00095   return description;
00096 }
00097 
00098 void Project::set_degate_version(std::string version_str) {
00099   degate_version = version_str;
00100 }
00101 
00102 std::string const& Project::get_degate_version() {
00103   return degate_version;
00104 }
00105 
00106 void Project::set_lambda(length_t l) {
00107   lambda = l;
00108 }
00109 
00110 length_t Project::get_lambda() const {
00111   return lambda;
00112 }
00113 
00114 void Project::set_default_pin_diameter(diameter_t pin_diameter) {
00115   default_pin_diameter = pin_diameter;
00116 }
00117 
00118 diameter_t Project::get_default_pin_diameter() const {
00119   return default_pin_diameter;
00120 }
00121 
00122 void Project::set_default_wire_diameter(diameter_t wire_diameter) {
00123   default_wire_diameter = wire_diameter;
00124 }
00125 
00126 diameter_t Project::get_default_wire_diameter() const {
00127   return default_wire_diameter;
00128 }
00129 
00130 void Project::set_default_port_diameter(diameter_t port_diameter) {
00131   default_port_diameter = port_diameter;
00132 }
00133 
00134 diameter_t Project::get_default_port_diameter() const {
00135   return default_port_diameter;
00136 }
00137 
00138 
00139 void Project::set_changed(bool state) {
00140   changed = state;
00141   if(state == false)
00142     reset_last_saved_counter();
00143 }
00144 
00145 bool Project::is_changed() const {
00146   return changed;
00147 }
00148 
00149 time_t Project::get_time_since_last_save() const {
00150   return time(NULL) - last_persistent_version;
00151 }
00152 
00153 void Project::reset_last_saved_counter() {
00154   last_persistent_version = time(NULL);
00155 }
00156 
00157 RegularGrid_shptr Project::get_regular_horizontal_grid() {
00158   return regular_horizontal_grid;
00159 }
00160 
00161 RegularGrid_shptr Project::get_regular_vertical_grid() {
00162   return regular_vertical_grid;
00163 }
00164 
00165 IrregularGrid_shptr Project::get_irregular_horizontal_grid() {
00166   return irregular_horizontal_grid;
00167 }
00168 
00169 IrregularGrid_shptr Project::get_irregular_vertical_grid() {
00170   return irregular_vertical_grid;
00171 }
00172 
00173 PortColorManager_shptr Project::get_port_color_manager() {
00174   return port_color_manager;
00175 }
00176 
00177 void Project::print(std::ostream & os) {
00178   os
00179     << endl
00180     << "================================[ "
00181     << (name.empty() ? "Unnamed project" : name)
00182     << " ]=================================" << endl
00183     << "+ Project description: " << description << endl
00184     << "+ Degate version: " << degate_version << endl
00185     << "+ Directory: " << directory << endl
00186     << "+" << endl
00187     << "+ Changed: " << (changed ? "true" : "false") << endl
00188     << "+" << endl
00189     << "+ Default wire diameter: " << default_wire_diameter << endl
00190     << "+ Default pin diameter: " << default_pin_diameter << endl
00191     << "+ Default port diameter: " << default_port_diameter << endl
00192     << "+ Min distance between electrically isolated objects in pixel (lambda value): " << lambda << endl
00193     << endl;
00194 
00195 }
00196 
00197 void Project::print_all(std::ostream & os) {
00198   print(os);
00199   if(logic_model == NULL) {
00200     os << "+ The project has no logic model." << endl
00201        << endl;
00202   }
00203   else
00204     logic_model->print(os);
00205 }
00206 
00207 void Project::init_default_values() {
00208   default_pin_diameter = 5;
00209   default_wire_diameter = 5;
00210   default_port_diameter = 5;
00211   lambda = 5;
00212   last_transaction_id = 0;
00213 
00214   pixel_per_um = 0;
00215   font_size = 12;
00216 
00217   // A B G R
00218   default_colors[DEFAULT_COLOR_WIRE] = 0xff00a3fb;
00219   default_colors[DEFAULT_COLOR_VIA_UP] = 0xffff8900;
00220   default_colors[DEFAULT_COLOR_VIA_DOWN] = 0xff0023ff;
00221   default_colors[DEFAULT_COLOR_GRID] = 0xffff1200;
00222   default_colors[DEFAULT_COLOR_ANNOTATION] = 0xa0303030;
00223   default_colors[DEFAULT_COLOR_ANNOTATION_FRAME] = 0xa032d932;
00224   default_colors[DEFAULT_COLOR_GATE] = 0xa0303030;
00225   default_colors[DEFAULT_COLOR_GATE_FRAME] = 0xa032b0d9;
00226   default_colors[DEFAULT_COLOR_GATE_PORT] = 0xff0000ff;
00227   default_colors[DEFAULT_COLOR_TEXT] = 0xffffffff;
00228   default_colors[DEFAULT_COLOR_EMARKER] = 0xffa0a0ff;
00229 
00230   set_changed(false);
00231 
00232   reset_last_saved_counter();
00233 
00234   regular_horizontal_grid = RegularGrid_shptr(new RegularGrid(Grid::HORIZONTAL));
00235   regular_vertical_grid = RegularGrid_shptr(new RegularGrid(Grid::VERTICAL));
00236   irregular_horizontal_grid = IrregularGrid_shptr(new IrregularGrid(Grid::HORIZONTAL));
00237   irregular_vertical_grid = IrregularGrid_shptr(new IrregularGrid(Grid::VERTICAL));
00238 
00239   // Generate a server URL
00240 
00241   srand(time(NULL));
00242   std::string channel_ident;
00243   while(channel_ident.size() <= 20)
00244     channel_ident += (char)('a'+(int) (26.0*rand()/(RAND_MAX+1.0)));
00245 
00246 
00247   boost::format f(Configuration::get_instance().get_servers_uri_pattern());
00248   f % channel_ident;
00249   server_url = f.str();
00250 }
00251 
00252 
00253 void Project::set_server_url(std::string const& server_url) {
00254   this->server_url = server_url;
00255 }
00256 
00257 std::string Project::get_server_url() const {
00258   return server_url;
00259 }
00260 
00261 transaction_id_t Project::get_last_pulled_tid() const {
00262   return last_transaction_id;
00263 }
00264 
00265 void Project::set_last_pulled_tid(transaction_id_t tid) {
00266   last_transaction_id = tid;
00267 }
00268 
00269 
00270 void Project::set_default_color(ENTITY_COLOR e, color_t c) {
00271   default_colors[e] = c;
00272 }
00273 
00274 color_t Project::get_default_color(ENTITY_COLOR e) const {
00275   default_colors_t::const_iterator i = default_colors.find(e);
00276   if(i == default_colors.end()) return 0;
00277   else return i->second;
00278 }
00279 
00280 const default_colors_t Project::get_default_colors() const {
00281   return default_colors;
00282 }
00283 
00284 double Project::get_pixel_per_um() const {
00285   return pixel_per_um;
00286 }
00287 
00288 void Project::set_pixel_per_um(double pix_per_um) {
00289   pixel_per_um = pix_per_um;
00290 }
00291 
00292 
00293 int Project::get_template_dimension() const {
00294   return template_dimension;
00295 }
00296 
00297 void Project::set_template_dimension(int template_dimension) {
00298   this->template_dimension = template_dimension;
00299 }
00300 
00301 void Project::set_font_size(unsigned int font_size) {
00302   this->font_size = font_size;
00303 }
00304 
00305 unsigned int Project::get_font_size() const {
00306   return font_size;
00307 }
00308 
00309 
00310 RCBase::container_type & Project::get_rcv_blacklist() {
00311   return rcv_blacklist;
00312 }
00313