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