From 6bd3da435ed43a541739de9d2856b11a84a35615 Mon Sep 17 00:00:00 2001 From: andyfox-rushc Date: Thu, 5 Dec 2024 12:57:08 -0800 Subject: [PATCH] Added undo for net name swap Signed-off-by: andyfox-rushc --- src/odb/include/odb/db.h | 2 +- src/odb/src/db/dbJournal.cpp | 26 ++++++++++++++++++++++++++ src/odb/src/db/dbNet.cpp | 16 +++++++++++++++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/odb/include/odb/db.h b/src/odb/include/odb/db.h index 36156b4c060..46abf1aa0a2 100644 --- a/src/odb/include/odb/db.h +++ b/src/odb/include/odb/db.h @@ -2116,7 +2116,7 @@ class dbNet : public dbObject /// /// Swaps the current db net name with the source db net - void swapNetNames(dbNet* source); + void swapNetNames(dbNet* source, bool journal = true); /// /// RC netowork disconnect diff --git a/src/odb/src/db/dbJournal.cpp b/src/odb/src/db/dbJournal.cpp index 8cda1730758..7f5def580bb 100644 --- a/src/odb/src/db/dbJournal.cpp +++ b/src/odb/src/db/dbJournal.cpp @@ -1754,6 +1754,32 @@ void dbJournal::undo_swapObject() auto obj_type = popObjectType(); switch (obj_type) { + case dbNameObj: { + // name swapping undo + auto sub_obj_type = popObjectType(); + switch (sub_obj_type) { + // net name swap + case dbNetObj: { + // assume source and destination + uint source_net_id; + uint dest_net_id; + _log.pop(source_net_id); + _log.pop(dest_net_id); + // note because we are undoing the source is the prior dest + //(we are move dest name back to source name). + dbNet* source_net = dbNet::getNet(_block, dest_net_id); + dbNet* dest_net = dbNet::getNet(_block, source_net_id); + // don't allow undo to be undone, turn off journaling doing swap + source_net->swapNetNames(dest_net, false); + } + default: { + _logger->critical(utl::ODB, + 444, + "No undo_swapObject Name support for type {}", + dbObject::getTypeName(sub_obj_type)); + } + } + } case dbInstObj: { uint inst_id; _log.pop(inst_id); diff --git a/src/odb/src/db/dbNet.cpp b/src/odb/src/db/dbNet.cpp index 6542a00b634..4b32adf6ad7 100644 --- a/src/odb/src/db/dbNet.cpp +++ b/src/odb/src/db/dbNet.cpp @@ -727,7 +727,7 @@ bool dbNet::rename(const char* name) return true; } -void dbNet::swapNetNames(dbNet* source) +void dbNet::swapNetNames(dbNet* source, bool ok_to_journal) { _dbNet* dest_net = (_dbNet*) this; _dbNet* source_net = (_dbNet*) source; @@ -736,6 +736,20 @@ void dbNet::swapNetNames(dbNet* source) char* dest_name_ptr = dest_net->_name; char* source_name_ptr = source_net->_name; + // allow undo.. + if (block->_journal && ok_to_journal) { + block->_journal->beginAction(dbJournal::SWAP_OBJECT); + // a name + block->_journal->pushParam(dbNameObj); + // the type of name swap + block->_journal->pushParam(dbNetObj); + // stash the source and dest in that order, + // let undo reorder + block->_journal->pushParam(source_net->getId()); + block->_journal->pushParam(dest_net->getId()); + block->_journal->endAction(); + } + block->_net_hash.remove(dest_net); block->_net_hash.remove(source_net);