degate  0.1.2
HlObjectSet.cc
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 #include "HlObjectSet.h"
00023 #include <algorithm>
00024 #include <memory>
00025 
00026 using namespace std;
00027 using namespace degate;
00028 
00029 
00030 void HlObjectSet::clear() {
00031   highlight(PlacedLogicModelObject::HLIGHTSTATE_NOT);
00032 
00033   
00034   for(adjacent_objects_t::iterator iter = adjacent_objects.begin();
00035       iter != adjacent_objects.end(); ++iter) {
00036     unhighlight_adjacent_objects(iter->second);
00037   }
00038 
00039   adjacent_objects.clear();
00040   ObjectSet::clear();
00041 }
00042 
00043 void HlObjectSet::highlight(PlacedLogicModelObject::HIGHLIGHTING_STATE state) {
00044   for(iterator it = begin(); it != end(); ++it)
00045     (*it)->set_highlighted(state);
00046 }
00047 
00048 
00049 void HlObjectSet::add(std::shared_ptr<PlacedLogicModelObject> object) {
00050   ObjectSet::add(object);
00051   object->set_highlighted(PlacedLogicModelObject::HLIGHTSTATE_DIRECT);
00052 }
00053 
00054 void HlObjectSet::add(std::shared_ptr<PlacedLogicModelObject> object,
00055                       LogicModel_shptr lmodel) {
00056   add(object);
00057 
00058   if(ConnectedLogicModelObject_shptr o =
00059      std::dynamic_pointer_cast<ConnectedLogicModelObject>(object) ) {
00060     // highlight adjacent objects
00061     highlight_adjacent_objects(o, lmodel);
00062   }
00063 }
00064 
00065 
00066 void HlObjectSet::highlight_adjacent_objects(ConnectedLogicModelObject_shptr o,
00067                                              LogicModel_shptr lmodel) {
00068   Net_shptr net = o->get_net();
00069   if(net == NULL) return;
00070 
00071   // iterate over net
00072   BOOST_FOREACH(object_id_t oid, *net) {
00073     PlacedLogicModelObject_shptr plo = lmodel->get_object(oid);
00074     ConnectedLogicModelObject_shptr clo =
00075       std::dynamic_pointer_cast<ConnectedLogicModelObject>(plo);
00076     assert(clo != NULL);
00077     // remember connnected objects in list
00078     if(o != clo) {
00079 
00080       clo->set_highlighted(PlacedLogicModelObject::HLIGHTSTATE_ADJACENT);
00081 
00082       adjacent_objects[o].push_back(clo);
00083     }
00084   }
00085 }
00086 
00087 void HlObjectSet::unhighlight_adjacent_objects(adjacent_objects_t::mapped_type & list) {
00088   // iterate over list
00089   BOOST_FOREACH(ConnectedLogicModelObject_shptr clo, list) {
00090 
00091     adjacent_objects_t::iterator iter = adjacent_objects.find(clo);
00092     if(iter == adjacent_objects.end())
00093       clo->set_highlighted(PlacedLogicModelObject::HLIGHTSTATE_NOT);
00094 
00095   }
00096   list.clear();
00097 }
00098 
00099 void HlObjectSet::remove(std::shared_ptr<PlacedLogicModelObject> object) {
00100   ObjectSet::remove(object);
00101 
00102   if(ConnectedLogicModelObject_shptr o =
00103      std::dynamic_pointer_cast<ConnectedLogicModelObject>(object) ) {
00104   
00105     adjacent_objects_t::iterator iter = adjacent_objects.find(o);
00106     if(iter != adjacent_objects.end()) {
00107       unhighlight_adjacent_objects((*iter).second);
00108     }
00109     adjacent_objects.erase(iter);
00110   }
00111 
00112   object->set_highlighted(PlacedLogicModelObject::HLIGHTSTATE_NOT);
00113 }