degate  0.1.2
Public Member Functions | Private Member Functions | Private Attributes
degate::ExternalMatching Class Reference

Run an external program, that analyzes images. More...

#include <ExternalMatching.h>

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

List of all members.

Public Member Functions

 ExternalMatching ()
virtual void init (BoundingBox const &bounding_box, Project_shptr project)
 
Exceptions:
InvalidPointerException
DegateRuntimeException

virtual void run ()
void set_command (std::string const &cmd)
std::string get_command () const
int get_exit_code () const

Private Member Functions

std::list
< PlacedLogicModelObject_shptr
parse_file (std::string const &filename) const
PlacedLogicModelObject_shptr parse_line (std::string const &line) const
 Parse a line, that describes an object.

Private Attributes

Layer_shptr layer
LogicModel_shptr lmodel
BackgroundImage_shptr img
BoundingBox bounding_box
std::string cmd
int exit_code

Detailed Description

Run an external program, that analyzes images.

The program extracts wires and vias and writes the results into a file. The file is parsed bu this class and the object are added into the logic model.

Here is a brief decription of the result file:

Comment lines are starting with a hash mark ('#')

Wire:

Format: "wire" x1 y1 x2 y2 diameter Example: wire 10 23 100 23 5

Via:

Format: "via" x y diameter direction Example: via 42 23 5 up

The direction is either "up" or "down"

Strings are case sensitive.

Definition at line 56 of file ExternalMatching.h.


Constructor & Destructor Documentation

Definition at line 32 of file ExternalMatching.cc.

{}

Member Function Documentation

std::string ExternalMatching::get_command ( ) const

Definition at line 61 of file ExternalMatching.cc.

References cmd.

                                              {
  return cmd;
}

Definition at line 106 of file ExternalMatching.cc.

References exit_code.

                                          {
  return WEXITSTATUS(exit_code);
}
void ExternalMatching::init ( BoundingBox const &  bounding_box,
Project_shptr  project 
) [virtual]

Exceptions:
InvalidPointerException
DegateRuntimeException

Implements degate::Matching.

Definition at line 35 of file ExternalMatching.cc.

References bounding_box, img, layer, and lmodel.

                                                                                  {

  this->bounding_box = bounding_box;

  if(project == NULL)
    throw InvalidPointerException("Invalid pointer for parameter project.");

  lmodel = project->get_logic_model();
  assert(lmodel != NULL); // always has a logic model

  layer = lmodel->get_current_layer();
  if(layer == NULL) throw DegateRuntimeException("No current layer in project.");


  ScalingManager_shptr sm = layer->get_scaling_manager();
  assert(sm != NULL);

  img = sm->get_image(1).second;
  assert(img != NULL);
}
std::list< PlacedLogicModelObject_shptr > ExternalMatching::parse_file ( std::string const &  filename) const [private]

Definition at line 111 of file ExternalMatching.cc.

References parse_line().

Referenced by run().

                                                                                                  {

  std::list<PlacedLogicModelObject_shptr> list;
  std::string line;
  std::ifstream file(filename.c_str());

  if(file.is_open()) {

    while(!file.eof()) {

      getline(file, line);

      PlacedLogicModelObject_shptr plo = parse_line(line);
      if(plo != NULL) list.push_back(plo);
    }
    file.close();
  }
  return list;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PlacedLogicModelObject_shptr ExternalMatching::parse_line ( std::string const &  line) const [private]

Parse a line, that describes an object.

Exceptions:
DegateRuntimeExcpetionThis expetion is thrown if a line cannot be parsed.
Returns:
Returns a shared pointer to an object, that can be added to the logic model. It returns a NULL pointer equivalent, if the line does not represent a command.

Definition at line 131 of file ExternalMatching.cc.

References degate::Via::DIRECTION_DOWN, degate::Via::DIRECTION_UP, and degate::tokenize().

Referenced by parse_file().

                                                                                     {

  std::vector<std::string> tokens = tokenize(line);

  PlacedLogicModelObject_shptr plo;

  if(tokens.size() == 0) return plo;
  else if(tokens[0].at(0) == '#') return plo;
  else if(tokens[0] == "wire" and tokens.size() >= 6) {

    int
      x1 = boost::lexical_cast<int>(tokens[1]),
      y1 = boost::lexical_cast<int>(tokens[2]),
      x2 = boost::lexical_cast<int>(tokens[3]),
      y2 = boost::lexical_cast<int>(tokens[4]),
      diameter = boost::lexical_cast<unsigned int>(tokens[5]);

    return Wire_shptr(new Wire(x1, y1, x2, y2, diameter));
  }
  else if(tokens[0] == "via" and tokens.size() >= 6) {

    int
      x = boost::lexical_cast<int>(tokens[1]),
      y = boost::lexical_cast<int>(tokens[2]),
      diameter = boost::lexical_cast<unsigned int>(tokens[3]);

    Via::DIRECTION dir = tokens[4] == "up" ?
      Via::DIRECTION_UP : Via::DIRECTION_DOWN;

    return Via_shptr(new Via(x, y, diameter, dir));
  }

  else {
    std::string err("Can't parse line: ");
    throw DegateRuntimeException(err + line);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ExternalMatching::run ( ) [virtual]

Implements degate::Matching.

Definition at line 65 of file ExternalMatching.cc.

References bounding_box, cmd, degate::create_temp_directory(), debug(), exit_code, degate::BoundingBox::get_height(), degate::BoundingBox::get_min_x(), degate::BoundingBox::get_min_y(), degate::BoundingBox::get_width(), img, degate::is_directory(), layer, lmodel, parse_file(), degate::remove_directory(), degate::save_part_of_image(), and TM.

                           {

  // create a temp dir
  std::string dir = create_temp_directory();
  assert(is_directory(dir));

  std::string image_file = dir;
  image_file.append("/image.tiff");

  std::string results_file = dir;
  results_file.append("/results.dat");

  save_part_of_image(image_file, img, bounding_box);

  boost::format f("%1% --image %2% --results %3% "
                  "--start-x %4% --start-y %5% --width %6% --height %7%");
  f % cmd
    % image_file
    % results_file
    % bounding_box.get_min_x()
    % bounding_box.get_min_y()
    % bounding_box.get_width()
    % bounding_box.get_height();


  debug(TM, "start external command: %s", f.str().c_str());
  exit_code = system(f.str().c_str());
  if(exit_code == -1) {
    debug(TM, "system() failed");
  }
  else {
    BOOST_FOREACH(PlacedLogicModelObject_shptr plo,
                  parse_file(results_file)) {
      lmodel->add_object(layer, plo);
    }
  }

  // cleanup
  remove_directory(dir);
}

Here is the call graph for this function:

void ExternalMatching::set_command ( std::string const &  cmd)

Definition at line 57 of file ExternalMatching.cc.

References cmd.

                                                       {
  this->cmd = cmd;
}

Member Data Documentation

Definition at line 63 of file ExternalMatching.h.

Referenced by init(), and run().

std::string degate::ExternalMatching::cmd [private]

Definition at line 65 of file ExternalMatching.h.

Referenced by get_command(), run(), and set_command().

Definition at line 66 of file ExternalMatching.h.

Referenced by get_exit_code(), and run().

Definition at line 62 of file ExternalMatching.h.

Referenced by init(), and run().

Definition at line 60 of file ExternalMatching.h.

Referenced by init(), and run().

Definition at line 61 of file ExternalMatching.h.

Referenced by init(), and run().


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