degate  0.1.2
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Attributes | Friends
degate::Layer Class Reference

Representation of a chip layer. More...

#include <Layer.h>

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

List of all members.

Public Types

enum  LAYER_TYPE {
  UNDEFINED = 0,
  METAL = 1,
  LOGIC = 2,
  TRANSISTOR = 3
}
 Enums to declare the type of a layer. More...
typedef std::shared_ptr
< PlacedLogicModelObject
quadtree_element_type
typedef region_iterator
< quadtree_element_type
qt_region_iterator
typedef qt_region_iterator object_iterator

Public Member Functions

 Layer (BoundingBox const &bbox, LAYER_TYPE _layer_type=Layer::UNDEFINED)
 Create a new logic model layer.
 Layer (BoundingBox const &bbox, LAYER_TYPE _layer_type, BackgroundImage_shptr img)
 Create a new logic model layer.
virtual ~Layer ()
 Destruct a layer.
unsigned int get_width () const
 Get the width of a layer.
unsigned int get_height () const
 Get the height of a layer.
BoundingBox const & get_bounding_box () const
 Get the bounding box for a layer.
const std::string get_layer_type_as_string () const
 Get layer type of this layer as human readable string, e.g.
LAYER_TYPE get_layer_type () const
 Get layer type.
void set_layer_type (LAYER_TYPE _layer_type)
 Set layer type.
bool is_empty () const
 Check if a layer has logic model objects or not.
layer_position_t get_layer_pos () const
 Get the position of the layer within the layer stack.
object_iterator objects_begin ()
 Get an iterator to iterate over all placed objects.
object_iterator objects_end ()
 Get an end iterator.
qt_region_iterator region_begin (int min_x, int max_x, int min_y, int max_y)
 Get an iterator to iterate over a region.
qt_region_iterator region_begin (BoundingBox const &bbox)
 Get an iterator to iterate over a region.
qt_region_iterator region_end ()
 Get an end marker for region iteration.
void set_image (BackgroundImage_shptr img)
 Set the background image for a layer.
BackgroundImage_shptr get_image ()
 Get the background image.
std::string get_image_filename () const
 Get the directory name for the image, that represents the background image of the layer.
bool has_background_image () const
 Check if the layer has a background image.
void unset_image ()
 Unset the background image.
ScalingManager_shptr get_scaling_manager ()
 Get the scaling manager.
void print (std::ostream &os=std::cout)
 Print the layer.
void notify_shape_change (object_id_t object_id)
 Notify the layer that a shape of a logic model object changed.
PlacedLogicModelObject_shptr get_object_at_position (int x, int y, int max_distance=0)
 Get an object at a specific position.
template<typename LogicModelObjectType >
bool exists_type_in_region (unsigned int min_x, unsigned int max_x, unsigned int min_y, unsigned int max_y)
 Check for placed objects in a region of type given by template param.
unsigned int get_distance_to_gate_boundary (unsigned int x, unsigned int y, bool query_horizontal_distance=true, unsigned int width=0, unsigned int height=0)
 Check for placed gates in a region and return the distance to the boundary.
void set_enabled (bool state=true)
 Enable a layer.
bool is_enabled () const
 Check if a layer is enabled.
std::string get_description () const
 Get layer description.
void set_description (std::string const &description)
 Set layer description.
void set_layer_pos (layer_position_t pos)
 Set layer position.
virtual void set_layer_id (layer_id_t lid)
 Set the layer ID.
virtual layer_id_t get_layer_id () const
 Get the layer ID.
virtual bool has_valid_layer_id () const
 Check if the layer has a valid layer ID.
DeepCopyable_shptr cloneShallow () const
void cloneDeepInto (DeepCopyable_shptr destination, oldnew_t *oldnew) const
 Deep-copy all members to destination.

Static Public Member Functions

static const std::string get_layer_type_as_string (LAYER_TYPE _layer_type)
 Get a layer type type as human readable string.
static LAYER_TYPE get_layer_type_from_string (std::string const &layer_type_str)
 Parse a layer type indicating string.

Protected Member Functions

void add_object (std::shared_ptr< PlacedLogicModelObject > o)
 Add an logic model object into this layer.
void remove_object (std::shared_ptr< PlacedLogicModelObject > o)
 Remove object from layer.

Private Types

typedef std::map< object_id_t,
PlacedLogicModelObject_shptr
object_collection

Private Attributes

QuadTree< quadtree_element_typequadtree
LAYER_TYPE layer_type
layer_position_t layer_pos
std::shared_ptr
< ScalingManager
< BackgroundImage > > 
scaling_manager
object_collection objects
bool enabled
std::string description
layer_id_t layer_id

Friends

class LogicModel

Detailed Description

Representation of a chip layer.

Definition at line 43 of file Layer.h.


Member Typedef Documentation

Definition at line 76 of file Layer.h.

Definition at line 63 of file Layer.h.

Definition at line 62 of file Layer.h.

Definition at line 60 of file Layer.h.


Member Enumeration Documentation

Enums to declare the type of a layer.

Enumerator:
UNDEFINED 
METAL 
LOGIC 
TRANSISTOR 

Definition at line 53 of file Layer.h.

                    {
      UNDEFINED = 0,
      METAL = 1,
      LOGIC = 2,
      TRANSISTOR = 3
    };

Constructor & Destructor Documentation

Layer::Layer ( BoundingBox const &  bbox,
Layer::LAYER_TYPE  _layer_type = Layer::UNDEFINED 
)

Create a new logic model layer.

Definition at line 54 of file Layer.cc.

                                                                  :
  quadtree(bbox, 100),
  layer_type(_layer_type),
  layer_pos(0),
  enabled(true),
  layer_id(0) {
}
Layer::Layer ( BoundingBox const &  bbox,
Layer::LAYER_TYPE  _layer_type,
BackgroundImage_shptr  img 
)

Create a new logic model layer.

Definition at line 62 of file Layer.cc.

References set_image().

                                        :
  quadtree(bbox, 100),
  layer_type(_layer_type),
  layer_pos(0),
  enabled(true),
  layer_id(0) {

  set_image(img);
}

Here is the call graph for this function:

Layer::~Layer ( ) [virtual]

Destruct a layer.

Definition at line 74 of file Layer.cc.

              {
}

Member Function Documentation

void Layer::add_object ( std::shared_ptr< PlacedLogicModelObject o) [protected]

Add an logic model object into this layer.

Exceptions:
DegateRuntimeExceptionIs thrown if the object cannot be inserted into the quadtree.
DegateLogicException

Definition at line 29 of file Layer.cc.

References debug(), degate::QuadTree< T >::insert(), objects, quadtree, RET_IS_NOT_OK, and TM.

                                                              {

  if(o->get_bounding_box() == BoundingBox(0, 0, 0, 0)) {
    boost::format fmter("Error in add_object(): Object %1% with ID %2% has an "
                        "undefined bounding box. Can't insert it into the quadtree");
    fmter % o->get_object_type_name() % o->get_object_id();
    throw DegateLogicException(fmter.str());
  }

  if(RET_IS_NOT_OK(quadtree.insert(o))) {
    debug(TM, "Failed to insert object into quadtree.");
    throw DegateRuntimeException("Failed to insert object into quadtree.");
  }
  objects[o->get_object_id()] = o;
}

Here is the call graph for this function:

void Layer::cloneDeepInto ( DeepCopyable_shptr  destination,
oldnew_t oldnew 
) const [virtual]

Deep-copy all members to destination.

Todo:
Find out whether the default assignment operator can be used to simplify implementations of this method.

Implements degate::DeepCopyableBase.

Definition at line 90 of file Layer.cc.

References degate::QuadTree< T >::get_all_elements(), objects, and quadtree.

                                                                         {
  auto clone = std::dynamic_pointer_cast<Layer>(dest);

  // quadtree
  std::vector<quadtree_element_type> quadtree_elems;
  quadtree.get_all_elements(quadtree_elems);
  std::for_each(quadtree_elems.begin(), quadtree_elems.end(), [=,oldnew,&clone](const quadtree_element_type &t) {
    clone->quadtree.insert(std::dynamic_pointer_cast<PlacedLogicModelObject>(t->cloneDeep(oldnew)));
  });

  // objects
  std::for_each(objects.begin(), objects.end(), [&](object_collection::value_type v) {
    clone->objects[v.first] = std::dynamic_pointer_cast<PlacedLogicModelObject>(v.second->cloneDeep(oldnew));
  });
}

Here is the call graph for this function:

Todo:
Check whether scaling_manager can really be reused by clones without trouble.

Implements degate::DeepCopyable.

Definition at line 80 of file Layer.cc.

References description, enabled, degate::QuadTree< T >::get_bounding_box(), layer_id, layer_pos, layer_type, quadtree, and scaling_manager.

                                             {
  auto clone = std::make_shared<Layer>(quadtree.get_bounding_box(), layer_type);
  clone->layer_pos = layer_pos;
  clone->enabled = enabled;
  clone->description = description;
  clone->layer_id = layer_id;
  clone->scaling_manager = scaling_manager;
  return clone;
}

Here is the call graph for this function:

template<typename LogicModelObjectType >
bool degate::Layer::exists_type_in_region ( unsigned int  min_x,
unsigned int  max_x,
unsigned int  min_y,
unsigned int  max_y 
) [inline]

Check for placed objects in a region of type given by template param.

Returns:
Returns true, if there is a an object of the specified type in the region. Else it returns false.

Definition at line 325 of file Layer.h.

References quadtree, degate::QuadTree< T >::region_iter_begin(), and degate::QuadTree< T >::region_iter_end().

                                                                       {
      for(Layer::qt_region_iterator iter = quadtree.region_iter_begin(min_x, max_x, min_y, max_y);
          iter != quadtree.region_iter_end(); ++iter) {
        
        if(std::dynamic_pointer_cast<LogicModelObjectType>(*iter) != NULL) {
          return true;
        }
      }
      return false;      
    }

Here is the call graph for this function:

Get the bounding box for a layer.

Definition at line 114 of file Layer.cc.

References degate::QuadTree< T >::get_bounding_box(), and quadtree.

                                                 {
  return quadtree.get_bounding_box();
}

Here is the call graph for this function:

std::string Layer::get_description ( ) const

Get layer description.

Definition at line 318 of file Layer.cc.

References description.

                                       {
  return description;
}
unsigned int Layer::get_distance_to_gate_boundary ( unsigned int  x,
unsigned int  y,
bool  query_horizontal_distance = true,
unsigned int  width = 0,
unsigned int  height = 0 
)

Check for placed gates in a region and return the distance to the boundary.

Returns:
Returns the distance from x to the right boundary or from y to the bottom boundary depending on query_horizontal_distance. If there is no gate, this method returns 0.

Definition at line 284 of file Layer.cc.

References quadtree, degate::QuadTree< T >::region_iter_begin(), and degate::QuadTree< T >::region_iter_end().

                                                                       {

  for(Layer::qt_region_iterator iter = quadtree.region_iter_begin(x, x + width, y, y + height);
      iter != quadtree.region_iter_end(); ++iter) {

    if(Gate_shptr gate = std::dynamic_pointer_cast<Gate>(*iter)) {

      if(query_horizontal_distance) {
        assert(gate->get_max_x() >= (int)x);
        return gate->get_max_x() - x;
      }
      else {
        assert(gate->get_max_y() >= (int)y);
        return gate->get_max_y() - y;
      }
    }
  }

  return 0;
}

Here is the call graph for this function:

unsigned int Layer::get_height ( ) const

Get the height of a layer.

Definition at line 110 of file Layer.cc.

References degate::QuadTree< T >::get_height(), and quadtree.

Referenced by print().

                                     {
  return quadtree.get_height();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Get the background image.

Returns:
Returns a shared pointer to the background image.
Exceptions:
DegateLogicExceptionIf you did not set the background image, then this exception is thrown.
See also:
set_image()

Definition at line 193 of file Layer.cc.

References scaling_manager.

                                       {
  if(scaling_manager != NULL) {
    ScalingManager<BackgroundImage>::image_map_element p = scaling_manager->get_image(1);
    return p.second;
  }
  else throw DegateLogicException("You have to set the background image first.");
}
std::string Layer::get_image_filename ( ) const

Get the directory name for the image, that represents the background image of the layer.

Exceptions:
DegateLogicExceptionIf you did not set the background image, then this exception is thrown.

Definition at line 201 of file Layer.cc.

References scaling_manager.

Referenced by print(), and unset_image().

                                          {

  if(scaling_manager == NULL)
    throw DegateLogicException("There is no scaling manager.");
  else {
    const ScalingManager<BackgroundImage>::image_map_element p =
      scaling_manager->get_image(1);

    if(p.second != NULL)
      return p.second->get_directory();
    else
      throw DegateLogicException("The scaling manager failed to return an image pointer.");
  }
}

Here is the caller graph for this function:

virtual layer_id_t degate::Layer::get_layer_id ( ) const [inline, virtual]

Get the layer ID.

Definition at line 396 of file Layer.h.

References layer_id.

{ return layer_id; }

Get the position of the layer within the layer stack.

Definition at line 160 of file Layer.cc.

References layer_pos.

Referenced by print().

                                            {
  return layer_pos;
}

Here is the caller graph for this function:

Get layer type.

Definition at line 147 of file Layer.cc.

References layer_type.

                                            {
  return layer_type;
}
const std::string Layer::get_layer_type_as_string ( ) const

Get layer type of this layer as human readable string, e.g.

the string "metal" for a layer of type Layer::METAL .

Definition at line 119 of file Layer.cc.

References layer_type.

Referenced by degate::get_first_layer(), print(), and degate::GateTemplate::print().

Here is the caller graph for this function:

const std::string Layer::get_layer_type_as_string ( LAYER_TYPE  _layer_type) [static]

Get a layer type type as human readable string.

Definition at line 123 of file Layer.cc.

References LOGIC, METAL, TRANSISTOR, and UNDEFINED.

                                                                      {
  switch(_layer_type) {
  case METAL:
    return std::string("metal");
  case LOGIC:
    return std::string("logic");
  case TRANSISTOR:
    return std::string("transistor");
  case UNDEFINED:
  default:
    return std::string("undefined");
  }
}
Layer::LAYER_TYPE Layer::get_layer_type_from_string ( std::string const &  layer_type_str) [static]

Parse a layer type indicating string.

Exceptions:
DegateRuntimeExceptionThis exception is thrown if the string cannot be parsed.

Definition at line 137 of file Layer.cc.

References LOGIC, METAL, TRANSISTOR, and UNDEFINED.

                                                                                 {

  if(layer_type_str == "metal") return Layer::METAL;
  else if(layer_type_str == "logic") return Layer::LOGIC;
  else if(layer_type_str == "transistor") return Layer::TRANSISTOR;
  else if(layer_type_str == "undefined") return Layer::UNDEFINED;
  else throw DegateRuntimeException("Can't parse layer type.");
}
PlacedLogicModelObject_shptr Layer::get_object_at_position ( int  x,
int  y,
int  max_distance = 0 
)

Get an object at a specific position.

If multiple objects are placed at coordinate x, y, then the first one is returned. But if there is a gate port, the port is returned.

Parameters:
xThe x-position.
yThe y-position.
max_distanceIt is possible to check for objects, which are not directly placed in a way, that x and y are within the shape of an object. Therefore the parameter max_distance specifies an allowed distance to the object.
Returns:
If there is an object at the position, a shared pointer to it is returned. If there is no object, then a NULL pointer representation is returned.

Definition at line 261 of file Layer.cc.

References debug(), quadtree, degate::QuadTree< T >::region_iter_begin(), degate::QuadTree< T >::region_iter_end(), and TM.

                                                                                         {

  debug(TM, "get_object_at_position %d, %d (max-dist: %d)", x, y, max_distance);
  PlacedLogicModelObject_shptr plo;

  for(qt_region_iterator iter = quadtree.region_iter_begin(x - max_distance,
                                                           x + max_distance,
                                                           y - max_distance,
                                                           y + max_distance);
      iter != quadtree.region_iter_end(); ++iter) {

    if((*iter)->in_shape(x, y, max_distance)) {
      plo = *iter;
    }

    /* Prefer gate ports */
    if(std::dynamic_pointer_cast<GatePort>(*iter) != NULL) {
      return *iter;
    }
  }
  return plo;
}

Here is the call graph for this function:

Get the scaling manager.

If you want to access the background image of a layer, that is the chip surface depicting image, you have to ask for the ScalingMananger. From the scaling mananger you will get the image.

Returns:
Returns a shared pointer to the scaling manager object. The pointer can be a NULL pointer. This is the case if you did not initialized it via set_image()
See also:
set_image()

Definition at line 228 of file Layer.cc.

References scaling_manager.

                                                {
  return scaling_manager;
}
unsigned int Layer::get_width ( ) const

Get the width of a layer.

Definition at line 106 of file Layer.cc.

References degate::QuadTree< T >::get_width(), and quadtree.

Referenced by print().

                                    {
  return quadtree.get_width();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Check if the layer has a background image.

Definition at line 216 of file Layer.cc.

References scaling_manager.

Referenced by print().

                                       {
  return scaling_manager != NULL;
}

Here is the caller graph for this function:

virtual bool degate::Layer::has_valid_layer_id ( ) const [inline, virtual]

Check if the layer has a valid layer ID.

Definition at line 402 of file Layer.h.

References layer_id.

{ return layer_id != 0; }
bool Layer::is_empty ( ) const

Check if a layer has logic model objects or not.

Definition at line 156 of file Layer.cc.

References degate::QuadTree< T >::is_empty(), and quadtree.

                           {
  return quadtree.is_empty();
}

Here is the call graph for this function:

bool Layer::is_enabled ( ) const

Check if a layer is enabled.

Enabled means, that the layer is visible to the user.

Definition at line 313 of file Layer.cc.

References enabled.

                             {
  return enabled;
}

Notify the layer that a shape of a logic model object changed.

This will adjust the quadtree.

Exceptions:
CollectionLookupExceptionThis exception is thrown if thetre is no object in the layer, that has this object ID.
InvalidObjectIDExceptionIs raised, if object_id has an invalid ID.

Definition at line 247 of file Layer.cc.

References degate::QuadTree< T >::notify_shape_change(), objects, and quadtree.

                                                     {

  if(!object_id)
    throw InvalidObjectIDException("Invalid object ID in Layer::notify_shape_change()");

  object_collection::iterator iter = objects.find(object_id);
  if(iter == objects.end())
    throw CollectionLookupException("Error in Layer::notify_shape_change(): "
                                    "The object is not in the layer.");

  quadtree.notify_shape_change((*iter).second);
}

Here is the call graph for this function:

Get an iterator to iterate over all placed objects.

Definition at line 164 of file Layer.cc.

References quadtree, and degate::QuadTree< T >::region_iter_begin().

                                          {
  return quadtree.region_iter_begin();
}

Here is the call graph for this function:

Get an end iterator.

Definition at line 168 of file Layer.cc.

References quadtree, and degate::QuadTree< T >::region_iter_end().

                                        {
  return quadtree.region_iter_end();
}

Here is the call graph for this function:

void Layer::print ( std::ostream &  os = std::cout)

Print the layer.

Definition at line 232 of file Layer.cc.

References get_height(), get_image_filename(), get_layer_pos(), get_layer_type_as_string(), get_width(), has_background_image(), degate::QuadTree< T >::print(), and quadtree.

                                 {

  os
    << "Layer position       : " << get_layer_pos() << std::endl
    << "Width                : " << get_width() << std::endl
    << "Height               : " << get_height() << std::endl
    << "Layer type           : " << get_layer_type_as_string() << std::endl
    << "Has background image : " << (has_background_image() ? "true" : "false") << std::endl
    << "Background image     : " << (has_background_image() ? get_image_filename() : "none" ) << std::endl
    << std::endl
    ;

  quadtree.print(os);
}

Here is the call graph for this function:

Layer::qt_region_iterator Layer::region_begin ( int  min_x,
int  max_x,
int  min_y,
int  max_y 
)

Get an iterator to iterate over a region.

Definition at line 172 of file Layer.cc.

References quadtree, and degate::QuadTree< T >::region_iter_begin().

                                                                                      {
  return quadtree.region_iter_begin(min_x, max_x, min_y, max_y);
}

Here is the call graph for this function:

Get an iterator to iterate over a region.

Definition at line 176 of file Layer.cc.

References quadtree, and degate::QuadTree< T >::region_iter_begin().

                                                                   {
  return quadtree.region_iter_begin(bbox);
}

Here is the call graph for this function:

Get an end marker for region iteration.

Definition at line 180 of file Layer.cc.

References quadtree, and degate::QuadTree< T >::region_iter_end().

                                          {
  return quadtree.region_iter_end();
}

Here is the call graph for this function:

void Layer::remove_object ( std::shared_ptr< PlacedLogicModelObject o) [protected]

Remove object from layer.

Exceptions:
DegateRuntimeExceptionIs thrown if the object cannot be removed from the quadtree.

Definition at line 45 of file Layer.cc.

References debug(), objects, quadtree, degate::QuadTree< T >::remove(), RET_IS_NOT_OK, and TM.

                                                                 {
  if(RET_IS_NOT_OK(quadtree.remove(o))) {
    debug(TM, "Failed to remove object from quadtree.");
    throw std::runtime_error("Failed to remove object from quadtree.");
  }

  objects.erase(o->get_object_id());
}

Here is the call graph for this function:

void Layer::set_description ( std::string const &  description)

Set layer description.

Definition at line 323 of file Layer.cc.

References description.

                                                        {
  this->description = description;
}
void Layer::set_enabled ( bool  state = true)

Enable a layer.

Definition at line 309 of file Layer.cc.

References enabled.

                                  {
  enabled = state;
}

Set the background image for a layer.

Calling this method will also initialize the ScalingManager, that handles multiple prescaled versions of the background image. The ScalingManager will write the prescaled images into subdirectories of the the background image.

Definition at line 184 of file Layer.cc.

References scaling_manager.

Referenced by Layer().

                                               {

  scaling_manager =
    std::shared_ptr<ScalingManager<BackgroundImage> >
    (new ScalingManager<BackgroundImage>(img, img->get_directory()));

  scaling_manager->create_scalings();
}

Here is the caller graph for this function:

virtual void degate::Layer::set_layer_id ( layer_id_t  lid) [inline, virtual]

Set the layer ID.

The layer ID is not an object ID. The only requirement is that each layer has a unique and position-independend ID.

Definition at line 390 of file Layer.h.

References layer_id.

{ layer_id = lid; }

Set layer position.

Definition at line 383 of file Layer.h.

References layer_pos.

{ layer_pos = pos; }
void Layer::set_layer_type ( LAYER_TYPE  _layer_type)

Set layer type.

Definition at line 151 of file Layer.cc.

References layer_type.

                                                 {
  layer_type = _layer_type;
}

Unset the background image.

This will destroy the image and it's scaling manager object and it will remove the data from the project dir.

Exceptions:
DegateLogicExceptionThis excpetion is thrown if there is no background image.

Definition at line 220 of file Layer.cc.

References debug(), get_image_filename(), degate::remove_directory(), scaling_manager, and TM.

                        {
  if(scaling_manager == NULL) throw DegateLogicException("There is no scaling manager.");
  std::string img_dir = get_image_filename();
  scaling_manager.reset();
  debug(TM, "remove directory: %s", img_dir.c_str());
  remove_directory(img_dir);
}

Here is the call graph for this function:


Friends And Related Function Documentation

friend class LogicModel [friend]

Definition at line 45 of file Layer.h.


Member Data Documentation

std::string degate::Layer::description [private]

Definition at line 80 of file Layer.h.

Referenced by cloneShallow(), get_description(), and set_description().

bool degate::Layer::enabled [private]

Definition at line 79 of file Layer.h.

Referenced by cloneShallow(), is_enabled(), and set_enabled().

Definition at line 82 of file Layer.h.

Referenced by cloneShallow(), get_layer_id(), has_valid_layer_id(), and set_layer_id().

Definition at line 71 of file Layer.h.

Referenced by cloneShallow(), get_layer_pos(), and set_layer_pos().

Definition at line 69 of file Layer.h.

Referenced by cloneShallow(), get_layer_type(), get_layer_type_as_string(), and set_layer_type().

Definition at line 77 of file Layer.h.

Referenced by add_object(), cloneDeepInto(), notify_shape_change(), and remove_object().


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