degate  0.1.2
LogicModelDOTExporter.h
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 #ifndef __LOGICMODELDOTEXPORTER_H__
00023 #define __LOGICMODELDOTEXPORTER_H__
00024 
00025 #include "globals.h"
00026 #include "LogicModel.h"
00027 #include "DOTExporter.h"
00028 #include "ObjectIDRewriter.h"
00029 #include "Layer.h"
00030 
00031 #include <stdexcept>
00032 
00033 namespace degate {
00034 
00035   /**
00036    * The LogicModelDOTExporter exports the logic model or a part
00037    * of the logic model as a dot graph.
00038    */
00039 
00040   class LogicModelDOTExporter : public DOTExporter {
00041 
00042   public:
00043 
00044     /**
00045      * Properties you can set in order to control the dot output.
00046      */
00047     enum PROPERTY {
00048 
00049       /** default: false */
00050       PRESERVE_GATE_POSITIONS,
00051 
00052       /** default: true */
00053       ENABLE_EDGES,
00054 
00055       /** default: true */
00056       ENABLE_VIAS,
00057 
00058       /** default: true */
00059       ENABLE_WIRES,
00060 
00061       /** default: true */
00062       ENABLE_TEMPLATE_NAMES,
00063 
00064       /**
00065        * Control whether the fill color of logic model objects is used
00066        * as fill color for shapes in the dot output.
00067        * default: false
00068       */
00069       ENABLE_COLORS
00070 
00071     };
00072 
00073   protected:
00074 
00075     void add_gate(Gate_shptr gate);
00076     void add_via(Via_shptr via);
00077     //void add_wire(Wire_shptr wire);
00078     void add_net(Net_shptr lmodel);
00079     std::string add_implicit_net(Net_shptr net);
00080 
00081     void add_connection(Net_shptr net, std::string const& src_name, std::string const& edge_name);
00082 
00083     std::string oid_to_str(std::string const& prefix, object_id_t oid);
00084 
00085 
00086   private:
00087 
00088     std::map<object_id_t /* net id */, int> implicit_net_counter;
00089 
00090     ObjectIDRewriter_shptr oid_rewriter;
00091 
00092     double scaling;
00093 
00094     typedef std::map<PROPERTY, bool> property_map;
00095     property_map properties;
00096 
00097     unsigned int fontsize, penwidth;
00098 
00099   public:
00100 
00101     LogicModelDOTExporter(ObjectIDRewriter_shptr _oid_rewriter) :
00102       oid_rewriter(_oid_rewriter), scaling(1) {
00103 
00104       properties[PRESERVE_GATE_POSITIONS] = false;
00105       properties[ENABLE_EDGES] = true;
00106       properties[ENABLE_VIAS] = true;
00107       properties[ENABLE_WIRES] = true;
00108       properties[ENABLE_TEMPLATE_NAMES] = true;
00109       properties[ENABLE_COLORS] = false;
00110 
00111       fontsize = 0;
00112       penwidth = 0;
00113     }
00114 
00115     ~LogicModelDOTExporter() {}
00116 
00117     /**
00118      * Export the logic model as DOT file.
00119      * @excpetion InvalidPathException
00120      * @excpetion InvalidPointerException
00121      * @excpetion std::runtime_error 
00122      */
00123     void export_data(std::string const& filename, LogicModel_shptr lmodel);
00124 
00125     /**
00126      * Set a property for the dot export.
00127      */
00128     void set_property(PROPERTY property, bool state) {
00129       properties[property] = state;
00130     }
00131 
00132     /**
00133      * Get the state of a property.
00134      * @see set_property()
00135      */
00136     bool get_property(PROPERTY property) const {
00137 
00138       property_map::const_iterator found = properties.find(property);
00139 
00140       /* We can assert this, because the property-map is
00141          filled up in the constructor with default settings.
00142          If we forget it we might notice it here. */
00143       assert(found != properties.end());
00144 
00145       return (*found).second;
00146     }
00147 
00148 
00149     /**
00150      * Set the font size.
00151      * @param size The new font size in points. If you set it
00152      *      to zero, the default font size is used.
00153      * @see http://www.graphviz.org/doc/info/attrs.html#d:fontsize
00154      */
00155     void set_fontsize(unsigned int size) { fontsize = size; }
00156 
00157     /**
00158      * Get the font size.
00159      * @see set_fontsize()
00160      */
00161     unsigned int get_fontsize() const { return fontsize; }
00162 
00163     /**
00164      * Set the pen width.
00165      * @param size The new pen width in points. If you set it
00166      *      to zero, the default pen width is used.
00167      * @see http://www.graphviz.org/doc/info/attrs.html#d:penwidth
00168      */
00169     void set_penwidth(unsigned int size) { penwidth = size; }
00170 
00171     /**
00172      * Get the pen width.
00173      * @see set_penwidth()
00174      */
00175     unsigned int get_penwidth() const { return penwidth; }
00176 
00177   };
00178 
00179 }
00180 
00181 #endif