| 165 | } |
| 166 | |
| 167 | lay::CellView |
| 168 | DisplayState::cellview (unsigned int index, lay::LayoutHandle *layout_h) const |
| 169 | { |
| 170 | // try to restore the cell path |
| 171 | lay::CellView::unspecific_cell_path_type cell_path; |
| 172 | |
| 173 | std::list<CellPath>::const_iterator cvi = m_paths.begin (); |
| 174 | for (unsigned int i = 0; i < index && cvi != m_paths.end (); ++i) { |
| 175 | ++cvi; |
| 176 | } |
| 177 | |
| 178 | // create the cellview to return |
| 179 | lay::CellView cv; |
| 180 | cv.set (layout_h); |
| 181 | |
| 182 | if (cvi != m_paths.end ()) { |
| 183 | |
| 184 | // check, if we can reconstruct the path from the names |
| 185 | bool valid_path = false; |
| 186 | |
| 187 | for (std::vector<std::string>::const_iterator cn = cvi->begin_path (); cn != cvi->end_path (); ++cn) { |
| 188 | std::pair<bool, db::cell_index_type> pci = layout_h->layout ().cell_by_name (cn->c_str ()); |
| 189 | if (pci.first) { |
| 190 | cell_path.push_back (pci.second); |
| 191 | valid_path = true; |
| 192 | } else { |
| 193 | tl::warn << tl::to_string (tr ("Cellname cannot be reconstructed: ")) << *cn; |
| 194 | valid_path = false; |
| 195 | break; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // if available, take the path that was reconstructed |
| 200 | if (valid_path) { |
| 201 | |
| 202 | cv.set_unspecific_path (cell_path); |
| 203 | |
| 204 | tl_assert (! cell_path.empty ()); |
| 205 | const db::Cell *pc = &layout_h->layout ().cell (cell_path.back ()); |
| 206 | |
| 207 | std::vector<db::InstElement> context_path; |
| 208 | |
| 209 | // try further to extract the context path component |
| 210 | valid_path = false; |
| 211 | for (std::vector<SpecificInst>::const_iterator ci = cvi->begin_context_path (); ci != cvi->end_context_path (); ++ci) { |
| 212 | std::pair<bool, db::InstElement> ie = ci->to_inst_element (layout_h->layout (), *pc); |
| 213 | if (ie.first) { |
| 214 | context_path.push_back (ie.second); |
| 215 | pc = &layout_h->layout ().cell (ie.second.inst_ptr.cell_index ()); |
| 216 | valid_path = true; |
| 217 | } else { |
| 218 | tl::warn << tl::to_string (tr ("Specific instance cannot be reconstructed: instantiated cell is ")) << ci->cell_name |
| 219 | << tl::to_string (tr (", parent cell is ")) << layout_h->layout ().cell_name (pc->cell_index ()); |
| 220 | valid_path = false; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | // if possible, establish the context path now |