degate 0.1.1
Annotation.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 __ANNOTATION_H__
00023 #define __ANNOTATION_H__
00024 
00025 #include "globals.h"
00026 #include "LogicModelObjectBase.h"
00027 #include "Layer.h"
00028 #include "PlacedLogicModelObject.h"
00029 
00030 #include "Rectangle.h"
00031 
00032 #include <set>
00033 #include <boost/lexical_cast.hpp>
00034 #include <boost/filesystem.hpp>
00035 
00036 namespace degate {
00037 
00038   /**
00039    * An annotation is a descriptive meta object that can be
00040    * placed on a logic model's layer to mark a region of interest.
00041    *
00042    * The semantics of an annotation is user defined. The libdegate
00043    * does not establish a relationship from an annotaion to another
00044    * logic model object or to an background image region.
00045    *
00046    * Each annotation should have a class ID. This might be used
00047    * to classify the kind of annotation. For example you can place
00048    * an annotation 'above' a distored part of the background image to
00049    * remember yourself, that this image part should be rephotographed.
00050    * An image recognition algorithm may auto-annotate, that it is unsure
00051    * e.g. if there is a via or not due to fuzzy thresholds.
00052    *
00053    * You can set a name and a description for the annotation as well.
00054    *
00055    * This class is designed to be derived for concrete annotations.
00056    *
00057    * @see set_name()
00058    * @see set_description()
00059    */
00060 
00061   class Annotation : public Rectangle, public PlacedLogicModelObject {
00062 
00063   public:
00064 
00065     typedef unsigned int class_id_t;
00066 
00067     /**
00068      * Enums to declare the type of annotation.
00069      */
00070 
00071     enum ANNOTATION_TYPE {
00072       UNDEFINED = 0,
00073       SUBPROJECT = 1
00074     };
00075 
00076     typedef std::map<std::string, /* param name */
00077                      std::string  /* param value */ > parameter_set_type;
00078 
00079   private:
00080 
00081     class_id_t class_id;
00082     parameter_set_type parameters;
00083 
00084   protected:
00085 
00086 
00087     /**
00088      * Set a parameter.
00089      */
00090 
00091     void set_parameter(std::string const& parameter_name,
00092                        std::string const& parameter_value) {
00093       parameters[parameter_name] = parameter_value;
00094     }
00095 
00096   public:
00097 
00098     /**
00099      * Create a new annotation.
00100      */
00101 
00102     Annotation(int _min_x, int _max_x, int _min_y, int _max_y,
00103                class_id_t _class_id = UNDEFINED);
00104 
00105     /**
00106      * Create a new annotation.
00107      */
00108 
00109     Annotation(BoundingBox const& bbox,
00110                class_id_t _class_id = UNDEFINED);
00111 
00112 
00113     /**
00114      * The destructor for an annotaion.
00115      */
00116 
00117     virtual ~Annotation();
00118 
00119     /**
00120      * Get the class ID for an annotation.
00121      */
00122 
00123     virtual class_id_t get_class_id() const;
00124 
00125     /**
00126      * Set the class ID for an annotation.
00127      */
00128 
00129     virtual void set_class_id(class_id_t _class_id);
00130 
00131     /**
00132      * Get a human readable string that describes the whole
00133      * logic model object. The string should be unique in order
00134      * to let the user identify the concrete object. But that
00135      * is not a must.
00136      */
00137 
00138     virtual const std::string get_descriptive_identifier() const;
00139 
00140     /**
00141      * Get a human readable string that names the object type.
00142      * Here it is "Annotation".
00143      */
00144 
00145     virtual const std::string get_object_type_name() const;
00146 
00147     /**
00148      * Print annotation.
00149      */
00150     void print(std::ostream & os = std::cout, int n_tabs = 0) const;
00151 
00152 
00153 
00154     void shift_x(int delta_x) {
00155       Rectangle::shift_x(delta_x);
00156       notify_shape_change();
00157     }
00158 
00159     void shift_y(int delta_y) {
00160       Rectangle::shift_y(delta_y);
00161       notify_shape_change();
00162     }
00163 
00164     virtual bool in_bounding_box(BoundingBox const& bbox) const {
00165       return in_bounding_box(bbox);
00166     }
00167 
00168     virtual BoundingBox const& get_bounding_box() const {
00169       return Rectangle::get_bounding_box();
00170     }
00171 
00172     virtual bool in_shape(int x, int y, int max_distance = 0) const {
00173       return Rectangle::in_shape(x, y, max_distance);
00174     }
00175 
00176 
00177     /**
00178      * Get a parameter value.
00179      *
00180      * @exception boost::bad_lexical_cast This exception is thrown if the parameter value
00181      *   cannot be converted to the desired type.
00182      * @exception CollectionLookupException This exception is thrown if the parameter is
00183      *   not stored in the lookup table.
00184      */
00185 
00186     template<typename NewType>
00187     NewType get_parameter(std::string parameter_name) const {
00188 
00189       parameter_set_type::const_iterator iter = parameters.find(parameter_name);
00190       if(iter == parameters.end()) {
00191         boost::format f("Failed to lookup parameter %1%.");
00192         f % parameter_name;
00193         throw CollectionLookupException(f.str());
00194       }
00195 
00196       if(typeid(NewType) == typeid(std::string) ||
00197          typeid(NewType) == typeid(boost::filesystem::path)) {
00198 
00199         return NewType(iter->second);
00200       }
00201 
00202       try {
00203         return boost::lexical_cast<NewType>(iter->second);
00204       }
00205       catch(boost::bad_lexical_cast &) {
00206         debug(TM, "Failed to convert value string '%s'.", iter->second.c_str());
00207         throw;
00208       }
00209     }
00210 
00211     /**
00212      * Get an iterator to iterate over parameters.
00213      */
00214     parameter_set_type::const_iterator parameters_begin() const;
00215 
00216     /**
00217      * Get an end marker for the parameter iteration.
00218      */
00219     parameter_set_type::const_iterator parameters_end() const;
00220   };
00221 
00222 }
00223 #endif