degate  0.1.2
Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Attributes
degate::LogicModelDOTExporter Class Reference

The LogicModelDOTExporter exports the logic model or a part of the logic model as a dot graph. More...

#include <LogicModelDOTExporter.h>

Inheritance diagram for degate::LogicModelDOTExporter:
Inheritance graph
[legend]

List of all members.

Public Types

enum  PROPERTY {
  PRESERVE_GATE_POSITIONS,
  ENABLE_EDGES,
  ENABLE_VIAS,
  ENABLE_WIRES,
  ENABLE_TEMPLATE_NAMES,
  ENABLE_COLORS
}
 Properties you can set in order to control the dot output. More...

Public Member Functions

 LogicModelDOTExporter (ObjectIDRewriter_shptr _oid_rewriter)
 ~LogicModelDOTExporter ()
void export_data (std::string const &filename, LogicModel_shptr lmodel)
 Export the logic model as DOT file.
void set_property (PROPERTY property, bool state)
 Set a property for the dot export.
bool get_property (PROPERTY property) const
 Get the state of a property.
void set_fontsize (unsigned int size)
 Set the font size.
unsigned int get_fontsize () const
 Get the font size.
void set_penwidth (unsigned int size)
 Set the pen width.
unsigned int get_penwidth () const
 Get the pen width.

Protected Member Functions

void add_gate (Gate_shptr gate)
void add_via (Via_shptr via)
void add_net (Net_shptr lmodel)
std::string add_implicit_net (Net_shptr net)
void add_connection (Net_shptr net, std::string const &src_name, std::string const &edge_name)
std::string oid_to_str (std::string const &prefix, object_id_t oid)

Private Types

typedef std::map< PROPERTY, bool > property_map

Private Attributes

std::map< object_id_t, int > implicit_net_counter
ObjectIDRewriter_shptr oid_rewriter
double scaling
property_map properties
unsigned int fontsize
unsigned int penwidth

Detailed Description

The LogicModelDOTExporter exports the logic model or a part of the logic model as a dot graph.

Definition at line 40 of file LogicModelDOTExporter.h.


Member Typedef Documentation

typedef std::map<PROPERTY, bool> degate::LogicModelDOTExporter::property_map [private]

Definition at line 94 of file LogicModelDOTExporter.h.


Member Enumeration Documentation

Properties you can set in order to control the dot output.

Enumerator:
PRESERVE_GATE_POSITIONS 

default: false

ENABLE_EDGES 

default: true

ENABLE_VIAS 

default: true

ENABLE_WIRES 

default: true

ENABLE_TEMPLATE_NAMES 

default: true

ENABLE_COLORS 

Control whether the fill color of logic model objects is used as fill color for shapes in the dot output.

default: false

Definition at line 47 of file LogicModelDOTExporter.h.

                  {

      /** default: false */
      PRESERVE_GATE_POSITIONS,

      /** default: true */
      ENABLE_EDGES,

      /** default: true */
      ENABLE_VIAS,

      /** default: true */
      ENABLE_WIRES,

      /** default: true */
      ENABLE_TEMPLATE_NAMES,

      /**
       * Control whether the fill color of logic model objects is used
       * as fill color for shapes in the dot output.
       * default: false
      */
      ENABLE_COLORS

    };

Constructor & Destructor Documentation

Definition at line 115 of file LogicModelDOTExporter.h.

{}

Member Function Documentation

void LogicModelDOTExporter::add_connection ( Net_shptr  net,
std::string const &  src_name,
std::string const &  edge_name 
) [protected]

Definition at line 233 of file LogicModelDOTExporter.cc.

References degate::DOTAttributes::add(), degate::DOTAttributes::get_string(), and MAX_NODES.

                                                                       {

  string net_name(oid_to_str("N", net->get_object_id()));

  DOTAttributes edge_attrs;
  edge_attrs.add("taillabel", edge_name);

  if(net->size() < MAX_NODES)
    add_edge(src_name, net_name,  edge_attrs.get_string());
  else {
    string implicit_net_name = add_implicit_net(net);
    edge_attrs.add("color", "red");
    add_edge(src_name, implicit_net_name, edge_attrs.get_string());
  }

}

Here is the call graph for this function:

void LogicModelDOTExporter::add_gate ( Gate_shptr  gate) [protected]

Definition at line 167 of file LogicModelDOTExporter.cc.

References degate::DOTAttributes::add(), MASK_B, MASK_G, and MASK_R.

                                                    {

  string node_name(oid_to_str("G", gate->get_object_id()));

  std::ostringstream stm;
  stm << (gate->has_name() ? gate->get_name() : node_name);

  if(get_property(ENABLE_TEMPLATE_NAMES) && gate->has_template()) {
    const GateTemplate_shptr tmpl = gate->get_gate_template();
    stm << "\\n" << tmpl->get_name();
  }

  string gate_name(stm.str());

  DOTAttributes attrs;
  attrs.add("label", gate_name);
  attrs.add("shape", "component");

  if(get_fontsize() > 0)
    attrs.add_number<unsigned int>("fontsize", get_fontsize());

  if(get_penwidth() > 0)
    attrs.add_number<unsigned int>("penwidth", get_penwidth());

  if(properties[PRESERVE_GATE_POSITIONS]) {
    attrs.add_number<unsigned int>("height", lround(scaling*gate->get_height()));
    attrs.add_number<unsigned int>("width", lround(scaling*gate->get_width()));
  }

  /* Use the placement on the chip as hint for graphviz. Graphviz
     might benefit from this.
  */
  attrs.add_position(lround(scaling*gate->get_center_x()),
                     lround(scaling*gate->get_center_y()),
                     properties[PRESERVE_GATE_POSITIONS]);


  if(properties[ENABLE_COLORS] &&
     (MASK_R(gate->get_fill_color()) != 0 ||
      MASK_G(gate->get_fill_color()) != 0 ||
      MASK_B(gate->get_fill_color()) != 0 ))
    attrs.add("color", to_color_string(gate->get_fill_color()));

  if(properties[PRESERVE_GATE_POSITIONS])
    attrs.add("fixedsize", "true");

  add_node(node_name, attrs.get_string());



  if(properties[ENABLE_EDGES]) {
    for(Gate::port_iterator piter = gate->ports_begin();
        piter != gate->ports_end(); ++piter) {
      GatePort_shptr gate_port = *piter;

      add_connection(gate_port->get_net(), node_name,
                     gate_port->get_template_port()->get_name());


    }
  }


}

Here is the call graph for this function:

std::string LogicModelDOTExporter::add_implicit_net ( Net_shptr  net) [protected]

Definition at line 141 of file LogicModelDOTExporter.cc.

References degate::DOTAttributes::add(), and degate::DOTAttributes::get_string().

                                                               {

  object_id_t new_oid = net->get_object_id();
  string net_name(oid_to_str("N", new_oid));

  if(implicit_net_counter.find(new_oid) == implicit_net_counter.end())
    implicit_net_counter[new_oid] = 1;
  else
    implicit_net_counter[new_oid]++;


  DOTAttributes attrs;
  attrs.add("label", net_name);
  attrs.add("shape", "box");
  attrs.add("color", "red");

  std::ostringstream stm;
  stm << net_name << "_" << implicit_net_counter[new_oid];


  add_node(stm.str(), attrs.get_string());
  return stm.str();

}

Here is the call graph for this function:

void LogicModelDOTExporter::add_net ( Net_shptr  lmodel) [protected]

Definition at line 129 of file LogicModelDOTExporter.cc.

References degate::DOTAttributes::add(), and degate::DOTAttributes::get_string().

                                                 {

  string net_name(oid_to_str("N", net->get_object_id()));

  DOTAttributes attrs;
  //attrs.add("label", net_name);
  attrs.add("shape", "point");

  add_node(net_name, attrs.get_string());

}

Here is the call graph for this function:

void LogicModelDOTExporter::add_via ( Via_shptr  via) [protected]

Definition at line 253 of file LogicModelDOTExporter.cc.

References degate::DOTAttributes::add(), degate::DOTAttributes::add_number(), and degate::DOTAttributes::get_string().

                                                 {

  string via_name(oid_to_str("V", via->get_object_id()));

  DOTAttributes attrs;
  attrs.add("label", via_name);
  attrs.add("shape", "box");

  if(get_fontsize() > 0)
    attrs.add_number<unsigned int>("fontsize", get_fontsize());
  if(get_penwidth() > 0)
    attrs.add_number<unsigned int>("penwidth", get_penwidth());

  add_node(via_name, attrs.get_string());

  if(properties[ENABLE_EDGES])
    add_connection(via->get_net(), via_name, "");
}

Here is the call graph for this function:

void LogicModelDOTExporter::export_data ( std::string const &  filename,
LogicModel_shptr  lmodel 
)

Export the logic model as DOT file.

InvalidPathException InvalidPointerException std::runtime_error

Definition at line 44 of file LogicModelDOTExporter.cc.

References debug(), degate::get_basename(), MAX_NODES, and TM.

                                                                                          {

  if(lmodel == NULL) throw InvalidPointerException("Logic model pointer is NULL.");

  /* Calculate a scaling, so that we can use pixel coordinates from the logic model
     as dot coordinates.

  scaling = (
             21.0 // cm  -- the width of an A4 paper
              / 2.54 // cm/inch
             * (double)get_dots_per_inch() // dots/inch
             ) / (double)(lmodel->get_width());

  */

  debug(TM, "scaling: %f", scaling);
  string basename(get_basename(filename));
  std::ostringstream stm;
  stm << "time neato -v -Tsvg"
    //<< " -Gdpi=" << get_dots_per_inch()
      << " -o " << basename
      << ".svg " << basename << ".dot";


  add_header_line("");
  add_header_line("This is a logic model export.");
  add_header_line("");
  add_header_line("You can generate an image of this graph with:");
  add_header_line(stm.str());
  add_header_line("");

  add_graph_setting("");

  try {

    // iterate over nets
    if(properties[ENABLE_EDGES]) {
      for(LogicModel::net_collection::iterator net_iter = lmodel->nets_begin();
          net_iter != lmodel->nets_end(); ++net_iter) {
        Net_shptr net = (*net_iter).second;
        if(net->size() < MAX_NODES)
          add_net(net);
      }
    }

    // iterate over logic model objects
    for(LogicModel::object_collection::iterator iter = lmodel->objects_begin();
        iter != lmodel->objects_end(); ++iter) {

      PlacedLogicModelObject_shptr o = (*iter).second;

      if(Gate_shptr gate = std::dynamic_pointer_cast<Gate>(o)) {
        // check if the gate should be rendered
        //if(accept_gate_for_output)
        add_gate(gate);
      }

      else if(properties[ENABLE_VIAS]) {
        if(Via_shptr via = std::dynamic_pointer_cast<Via>(o))
          add_via(via);
      }

      /*
        else if(Wire_shptr wire = std::dynamic_pointer_cast<Wire>(o))
          add_wire(wires_elem, wire, layer_pos);

      */
    }

    dump_to_file(filename);

  }
  catch(const std::exception& ex) {
    std::cout << "Exception caught: " << ex.what() << std::endl;
    throw;
  }

}

Here is the call graph for this function:

unsigned int degate::LogicModelDOTExporter::get_fontsize ( ) const [inline]

Get the font size.

See also:
set_fontsize()

Definition at line 161 of file LogicModelDOTExporter.h.

References fontsize.

{ return fontsize; }
unsigned int degate::LogicModelDOTExporter::get_penwidth ( ) const [inline]

Get the pen width.

See also:
set_penwidth()

Definition at line 175 of file LogicModelDOTExporter.h.

References penwidth.

{ return penwidth; }
bool degate::LogicModelDOTExporter::get_property ( PROPERTY  property) const [inline]

Get the state of a property.

See also:
set_property()

Definition at line 136 of file LogicModelDOTExporter.h.

References properties.

                                               {

      property_map::const_iterator found = properties.find(property);

      /* We can assert this, because the property-map is
         filled up in the constructor with default settings.
         If we forget it we might notice it here. */
      assert(found != properties.end());

      return (*found).second;
    }
std::string LogicModelDOTExporter::oid_to_str ( std::string const &  prefix,
object_id_t  oid 
) [protected]

Definition at line 123 of file LogicModelDOTExporter.cc.

                                                                                    {
  std::ostringstream stm;
  stm << prefix << oid_rewriter->get_new_object_id(oid);
  return stm.str();
}
void degate::LogicModelDOTExporter::set_fontsize ( unsigned int  size) [inline]

Set the font size.

Parameters:
sizeThe new font size in points. If you set it to zero, the default font size is used.
See also:
http://www.graphviz.org/doc/info/attrs.html#d:fontsize

Definition at line 155 of file LogicModelDOTExporter.h.

References fontsize.

{ fontsize = size; }
void degate::LogicModelDOTExporter::set_penwidth ( unsigned int  size) [inline]

Set the pen width.

Parameters:
sizeThe new pen width in points. If you set it to zero, the default pen width is used.
See also:
http://www.graphviz.org/doc/info/attrs.html#d:penwidth

Definition at line 169 of file LogicModelDOTExporter.h.

References penwidth.

{ penwidth = size; }
void degate::LogicModelDOTExporter::set_property ( PROPERTY  property,
bool  state 
) [inline]

Set a property for the dot export.

Definition at line 128 of file LogicModelDOTExporter.h.

References properties.

                                                     {
      properties[property] = state;
    }

Member Data Documentation

Definition at line 97 of file LogicModelDOTExporter.h.

Referenced by get_fontsize(), LogicModelDOTExporter(), and set_fontsize().

Definition at line 88 of file LogicModelDOTExporter.h.

Definition at line 90 of file LogicModelDOTExporter.h.

Definition at line 97 of file LogicModelDOTExporter.h.

Referenced by get_penwidth(), LogicModelDOTExporter(), and set_penwidth().

Definition at line 95 of file LogicModelDOTExporter.h.

Referenced by get_property(), LogicModelDOTExporter(), and set_property().

Definition at line 92 of file LogicModelDOTExporter.h.


The documentation for this class was generated from the following files: