| 456 | } |
| 457 | |
| 458 | void |
| 459 | LayoutViewFunctions::cm_cell_replace () |
| 460 | { |
| 461 | int cv_index = view ()->active_cellview_index (); |
| 462 | std::vector<lay::LayoutViewBase::cell_path_type> paths; |
| 463 | view ()->selected_cells_paths (cv_index, paths); |
| 464 | |
| 465 | if (cv_index >= 0 && paths.size () > 0) { |
| 466 | |
| 467 | if (paths.size () > 1) { |
| 468 | throw tl::Exception (tl::to_string (tr ("Replace cell cannot be used when multiple cells are selected"))); |
| 469 | } |
| 470 | |
| 471 | db::Layout &layout = view ()->cellview (cv_index)->layout (); |
| 472 | |
| 473 | bool needs_to_ask = false; |
| 474 | for (std::vector<lay::LayoutViewBase::cell_path_type>::const_iterator p = paths.begin (); p != paths.end () && ! needs_to_ask; ++p) { |
| 475 | if (layout.is_valid_cell_index (p->back ()) && ! layout.cell (p->back ()).is_leaf ()) { |
| 476 | needs_to_ask = true; |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | |
| 481 | lay::ReplaceCellOptionsDialog mode_dialog (parent_widget ()); |
| 482 | |
| 483 | db::cell_index_type with_cell = paths.front ().back (); |
| 484 | int mode = needs_to_ask ? m_del_cell_mode : 0; |
| 485 | |
| 486 | if (mode_dialog.exec_dialog (view ()->cellview (cv_index), mode, with_cell)) { |
| 487 | |
| 488 | if (needs_to_ask) { |
| 489 | m_del_cell_mode = mode; |
| 490 | } |
| 491 | |
| 492 | if (with_cell != paths.front ().back ()) { |
| 493 | |
| 494 | // remember the current path |
| 495 | lay::LayoutViewBase::cell_path_type cell_path (view ()->cellview (cv_index).combined_unspecific_path ()); |
| 496 | |
| 497 | view ()->clear_selection (); |
| 498 | |
| 499 | view ()->transaction (tl::to_string (tr ("Replace cells"))); |
| 500 | |
| 501 | // replace instances of the target cell with the new cell |
| 502 | |
| 503 | db::cell_index_type target_cell_index = paths.front ().back (); |
| 504 | layout.replace_instances_of (target_cell_index, with_cell); |
| 505 | |
| 506 | std::set<db::cell_index_type> cells_to_delete; |
| 507 | for (std::vector<lay::LayoutViewBase::cell_path_type>::const_iterator p = paths.begin (); p != paths.end (); ++p) { |
| 508 | if (! p->empty () && layout.is_valid_cell_index (p->back ())) { |
| 509 | cells_to_delete.insert (p->back ()); |
| 510 | if (mode == 2) { |
| 511 | layout.cell (p->back ()).collect_called_cells (cells_to_delete); |
| 512 | } |
| 513 | } |
| 514 | } |
| 515 |
nothing calls this directly
no test coverage detected