|
degate 0.1.1
|
Representation of a chip layer. More...
#include <Layer.h>
Public Types | |
| enum | LAYER_TYPE { UNDEFINED = 0, METAL = 1, LOGIC = 2, TRANSISTOR = 3 } |
| Enums to declare the type of a layer. More... | |
| typedef std::tr1::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. | |
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::tr1::shared_ptr< PlacedLogicModelObject > o) |
| Add an logic model object into this layer. | |
| void | remove_object (std::tr1::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_type > | quadtree |
| LAYER_TYPE | layer_type |
| layer_position_t | layer_pos |
| std::tr1::shared_ptr < ScalingManager < BackgroundImage > > | scaling_manager |
| object_collection | objects |
| bool | enabled |
| std::string | description |
| layer_id_t | layer_id |
Friends | |
| class | LogicModel |
typedef std::map<object_id_t, PlacedLogicModelObject_shptr> degate::Layer::object_collection [private] |
| typedef std::tr1::shared_ptr<PlacedLogicModelObject> degate::Layer::quadtree_element_type |
| Layer::Layer | ( | BoundingBox const & | bbox, |
| Layer::LAYER_TYPE | _layer_type = Layer::UNDEFINED |
||
| ) |
| Layer::Layer | ( | BoundingBox const & | bbox, |
| Layer::LAYER_TYPE | _layer_type, | ||
| BackgroundImage_shptr | img | ||
| ) |
Create a new logic model layer.
Definition at line 61 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); }

| void Layer::add_object | ( | std::tr1::shared_ptr< PlacedLogicModelObject > | o | ) | [protected] |
Add an logic model object into this layer.
| DegateRuntimeException | Is thrown if the object cannot be inserted into the quadtree. |
| DegateLogicException |
Definition at line 28 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;
}

| 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.
Definition at line 319 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::tr1::dynamic_pointer_cast<LogicModelObjectType>(*iter) != NULL) {
return true;
}
}
return false;
}

| BoundingBox const & Layer::get_bounding_box | ( | ) | const |
Get the bounding box for a layer.
Definition at line 84 of file Layer.cc.
References degate::QuadTree< T >::get_bounding_box(), and quadtree.
{
return quadtree.get_bounding_box();
}

| std::string Layer::get_description | ( | ) | const |
Get layer description.
Definition at line 288 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.
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 254 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::tr1::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;
}

| unsigned int Layer::get_height | ( | ) | const |
Get the height of a layer.
Definition at line 80 of file Layer.cc.
References degate::QuadTree< T >::get_height(), and quadtree.
Referenced by print().
{
return quadtree.get_height();
}


| BackgroundImage_shptr Layer::get_image | ( | ) |
Get the background image.
| DegateLogicException | If you did not set the background image, then this exception is thrown. |
Definition at line 163 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.
| DegateLogicException | If you did not set the background image, then this exception is thrown. |
Definition at line 171 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.");
}
}

| virtual layer_id_t degate::Layer::get_layer_id | ( | ) | const [inline, virtual] |
| layer_position_t Layer::get_layer_pos | ( | ) | const |
| Layer::LAYER_TYPE Layer::get_layer_type | ( | ) | const |
Get layer type.
Definition at line 117 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 89 of file Layer.cc.
References layer_type.
Referenced by degate::get_first_layer(), print(), and degate::GateTemplate::print().
{
return get_layer_type_as_string(layer_type);
}

| 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 93 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.
| DegateRuntimeException | This exception is thrown if the string cannot be parsed. |
Definition at line 107 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.
| x | The x-position. |
| y | The y-position. |
| max_distance | It 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. |
Definition at line 231 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::tr1::dynamic_pointer_cast<GatePort>(*iter) != NULL) {
return *iter;
}
}
return plo;
}

| ScalingManager_shptr Layer::get_scaling_manager | ( | ) |
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.
Definition at line 198 of file Layer.cc.
References scaling_manager.
{
return scaling_manager;
}
| unsigned int Layer::get_width | ( | ) | const |
| bool Layer::has_background_image | ( | ) | const |
Check if the layer has a background image.
Definition at line 186 of file Layer.cc.
References scaling_manager.
Referenced by print().
{
return scaling_manager != NULL;
}

| virtual bool degate::Layer::has_valid_layer_id | ( | ) | const [inline, virtual] |
| bool Layer::is_empty | ( | ) | const |
| bool Layer::is_enabled | ( | ) | const |
| void Layer::notify_shape_change | ( | object_id_t | object_id | ) |
Notify the layer that a shape of a logic model object changed.
This will adjust the quadtree.
| CollectionLookupException | This exception is thrown if thetre is no object in the layer, that has this object ID. |
| InvalidObjectIDException | Is raised, if object_id has an invalid ID. |
Definition at line 217 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);
}

| Layer::object_iterator Layer::objects_begin | ( | ) |
Get an iterator to iterate over all placed objects.
Definition at line 134 of file Layer.cc.
References quadtree, and degate::QuadTree< T >::region_iter_begin().
{
return quadtree.region_iter_begin();
}

| Layer::object_iterator Layer::objects_end | ( | ) |
Get an end iterator.
Definition at line 138 of file Layer.cc.
References quadtree, and degate::QuadTree< T >::region_iter_end().
{
return quadtree.region_iter_end();
}

| void Layer::print | ( | std::ostream & | os = std::cout | ) |
Print the layer.
Definition at line 202 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);
}

| Layer::qt_region_iterator Layer::region_begin | ( | BoundingBox const & | bbox | ) |
Get an iterator to iterate over a region.
Definition at line 146 of file Layer.cc.
References quadtree, and degate::QuadTree< T >::region_iter_begin().
{
return quadtree.region_iter_begin(bbox);
}

| 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 142 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);
}

| Layer::qt_region_iterator Layer::region_end | ( | ) |
Get an end marker for region iteration.
Definition at line 150 of file Layer.cc.
References quadtree, and degate::QuadTree< T >::region_iter_end().
{
return quadtree.region_iter_end();
}

| void Layer::remove_object | ( | std::tr1::shared_ptr< PlacedLogicModelObject > | o | ) | [protected] |
Remove object from layer.
| DegateRuntimeException | Is thrown if the object cannot be removed from the quadtree. |
Definition at line 44 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());
}

| void Layer::set_description | ( | std::string const & | description | ) |
Set layer description.
Definition at line 293 of file Layer.cc.
References description.
{
this->description = description;
}
| void Layer::set_enabled | ( | bool | state = true | ) |
| void Layer::set_image | ( | BackgroundImage_shptr | img | ) |
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 154 of file Layer.cc.
References scaling_manager.
Referenced by Layer().
{
scaling_manager =
std::tr1::shared_ptr<ScalingManager<BackgroundImage> >
(new ScalingManager<BackgroundImage>(img, img->get_directory()));
scaling_manager->create_scalings();
}

| virtual void degate::Layer::set_layer_id | ( | layer_id_t | lid | ) | [inline, virtual] |
| void degate::Layer::set_layer_pos | ( | layer_position_t | pos | ) | [inline] |
| void Layer::set_layer_type | ( | LAYER_TYPE | _layer_type | ) |
Set layer type.
Definition at line 121 of file Layer.cc.
References layer_type.
{
layer_type = _layer_type;
}
| void Layer::unset_image | ( | ) |
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.
| DegateLogicException | This excpetion is thrown if there is no background image. |
Definition at line 190 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);
}

friend class LogicModel [friend] |
std::string degate::Layer::description [private] |
Definition at line 79 of file Layer.h.
Referenced by get_description(), and set_description().
bool degate::Layer::enabled [private] |
Definition at line 78 of file Layer.h.
Referenced by is_enabled(), and set_enabled().
layer_id_t degate::Layer::layer_id [private] |
Definition at line 81 of file Layer.h.
Referenced by get_layer_id(), has_valid_layer_id(), and set_layer_id().
layer_position_t degate::Layer::layer_pos [private] |
Definition at line 70 of file Layer.h.
Referenced by get_layer_pos(), and set_layer_pos().
LAYER_TYPE degate::Layer::layer_type [private] |
Definition at line 68 of file Layer.h.
Referenced by get_layer_type(), get_layer_type_as_string(), and set_layer_type().
object_collection degate::Layer::objects [private] |
Definition at line 76 of file Layer.h.
Referenced by add_object(), notify_shape_change(), and remove_object().
QuadTree<quadtree_element_type> degate::Layer::quadtree [private] |
Definition at line 66 of file Layer.h.
Referenced by add_object(), exists_type_in_region(), get_bounding_box(), get_distance_to_gate_boundary(), get_height(), get_object_at_position(), get_width(), is_empty(), notify_shape_change(), objects_begin(), objects_end(), print(), region_begin(), region_end(), and remove_object().
std::tr1::shared_ptr<ScalingManager<BackgroundImage> > degate::Layer::scaling_manager [private] |
Definition at line 72 of file Layer.h.
Referenced by get_image(), get_image_filename(), get_scaling_manager(), has_background_image(), set_image(), and unset_image().
1.7.4