diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.cpp index 91ead3acc5..49045c2015 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.cpp @@ -15,6 +15,7 @@ // #include "AL/usdmaya/Global.h" +#include "AL/usd/transaction/TransactionManager.h" #include "AL/usdmaya/DebugCodes.h" #include "AL/usdmaya/StageCache.h" #include "AL/usdmaya/nodes/LayerManager.h" @@ -201,6 +202,7 @@ AL::event::CallbackId Global::m_postSave; AL::event::CallbackId Global::m_preRead; AL::event::CallbackId Global::m_postRead; AL::event::CallbackId Global::m_fileNew; +AL::event::CallbackId Global::m_mayaExit; AL::event::CallbackId Global::m_preExport; AL::event::CallbackId Global::m_postExport; @@ -284,6 +286,14 @@ static void onFileNew(void*) // Puzzled. UsdUtilsStageCache::Get().Clear(); StageCache::Clear(); + AL::usd::transaction::TransactionManager::CloseAll(); +} + +//---------------------------------------------------------------------------------------------------------------------- +static void onMayaExit(void*) +{ + TF_DEBUG(ALUSDMAYA_EVENTS).Msg("onMayaExit\n"); + onFileNew(nullptr); } //---------------------------------------------------------------------------------------------------------------------- @@ -441,6 +451,7 @@ void Global::onPluginLoad() auto& manager = AL::maya::event::MayaEventManager::instance(); m_fileNew = manager.registerCallback(onFileNew, "AfterNew", "usdmaya_onFileNew", 0x1000); + m_mayaExit = manager.registerCallback(onMayaExit, "MayaExiting", "usdmaya_onMayaExit", 0x1000); m_preSave = manager.registerCallback(preFileSave, "BeforeSave", "usdmaya_preFileSave", 0x1000); m_postSave = manager.registerCallback(postFileSave, "AfterSave", "usdmaya_postFileSave", 0x1000); diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.h index 595846b76f..ee02e3ac50 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.h @@ -54,6 +54,9 @@ class Global /// callback used to flush the USD caches after a file new static AL::event::CallbackId fileNew() { return m_fileNew; } + /// callback used to flush the USD caches on exit + static AL::event::CallbackId mayaExit() { return m_mayaExit; } + static void openingFile(bool val); private: @@ -64,7 +67,8 @@ class Global static AL::event::CallbackId m_postRead; ///< callback executed after opening a maya file - ///< needed to re-hook up the UsdPrims static AL::event::CallbackId - m_fileNew; ///< callback used to flush the USD caches after a file new + m_fileNew; ///< callback used to flush the USD caches after a file new + static AL::event::CallbackId m_mayaExit; ///< callback used to flush the USD caches on exit static AL::event::CallbackId m_preExport; ///< callback prior to exporting the scene (so we can store the session layer) static AL::event::CallbackId m_postExport; ///< callback after exporting diff --git a/plugin/al/usdtransaction/AL/usd/transaction/TransactionManager.cpp b/plugin/al/usdtransaction/AL/usd/transaction/TransactionManager.cpp index 90b9b56dd6..0e34f23c84 100644 --- a/plugin/al/usdtransaction/AL/usd/transaction/TransactionManager.cpp +++ b/plugin/al/usdtransaction/AL/usd/transaction/TransactionManager.cpp @@ -199,6 +199,9 @@ bool TransactionManager::Close(const UsdStageWeakPtr& stage, const SdfLayerHandl return false; } +//---------------------------------------------------------------------------------------------------------------------- +void TransactionManager::CloseAll() { GetManagers().clear(); } + //---------------------------------------------------------------------------------------------------------------------- } // namespace transaction } // namespace usd diff --git a/plugin/al/usdtransaction/AL/usd/transaction/TransactionManager.h b/plugin/al/usdtransaction/AL/usd/transaction/TransactionManager.h index 6f6628d9a4..848bfc1d73 100644 --- a/plugin/al/usdtransaction/AL/usd/transaction/TransactionManager.h +++ b/plugin/al/usdtransaction/AL/usd/transaction/TransactionManager.h @@ -116,6 +116,11 @@ class TransactionManager AL_USD_TRANSACTION_PUBLIC static bool Close(const PXR_NS::UsdStageWeakPtr& stage, const PXR_NS::SdfLayerHandle& layer); + /// \brief clears the transaction manager of all active transactions, effectively closing them + /// all. Intended to be used for File->New and on exit. + AL_USD_TRANSACTION_PUBLIC + static void CloseAll(); + private: typedef std::map StageManagerMap; static StageManagerMap& GetManagers(); diff --git a/plugin/al/usdtransaction/AL/usd/transaction/tests/testTransaction.py b/plugin/al/usdtransaction/AL/usd/transaction/tests/testTransaction.py index 9169461fba..d410a044a1 100644 --- a/plugin/al/usdtransaction/AL/usd/transaction/tests/testTransaction.py +++ b/plugin/al/usdtransaction/AL/usd/transaction/tests/testTransaction.py @@ -18,6 +18,9 @@ def setUp(self): if sys.version_info[0] >= 3: self.assertItemsEqual = self.assertCountEqual + def tearDown(self): + transaction.TransactionManager.CloseAll() + def _openNoticeHandler(self, notice, stage): self.assertEqual(stage, self._stage) self._opened += 1 diff --git a/plugin/al/usdtransaction/AL/usd/transaction/tests/testTransactionManager.py b/plugin/al/usdtransaction/AL/usd/transaction/tests/testTransactionManager.py index 8982ff6b86..fb0264bf77 100644 --- a/plugin/al/usdtransaction/AL/usd/transaction/tests/testTransactionManager.py +++ b/plugin/al/usdtransaction/AL/usd/transaction/tests/testTransactionManager.py @@ -33,6 +33,8 @@ def test_InProgress_Stage(self): self.assertFalse(TransactionManager.InProgress(stageA)) self.assertFalse(TransactionManager.InProgress(stageB)) + TransactionManager.CloseAll() + ## Test that TransactionManager reports transactions for multiple layers as expected def test_InProgress_Layer(self): stage = Usd.Stage.CreateInMemory() @@ -67,6 +69,8 @@ def test_InProgress_Layer(self): self.assertFalse(TransactionManager.InProgress(stage, layerA)) self.assertFalse(TransactionManager.InProgress(stage, layerB)) + TransactionManager.CloseAll() + if __name__ == '__main__': unittest.main() diff --git a/plugin/al/usdtransaction/AL/usd/transaction/wrapTransactionManager.cpp b/plugin/al/usdtransaction/AL/usd/transaction/wrapTransactionManager.cpp index 148569e018..af5c1c23f5 100644 --- a/plugin/al/usdtransaction/AL/usd/transaction/wrapTransactionManager.cpp +++ b/plugin/al/usdtransaction/AL/usd/transaction/wrapTransactionManager.cpp @@ -44,6 +44,8 @@ static bool CloseStageLayer(const UsdStageWeakPtr& stage, const SdfLayerHandle& return This::Close(stage, layer); } +static void CloseAllStage() { This::CloseAll(); } + void wrapTransactionManager() { { @@ -56,6 +58,9 @@ void wrapTransactionManager() .staticmethod("Open") .def("Close", CloseStageLayer, (arg("stage"), arg("layer"))) - .staticmethod("Close"); + .staticmethod("Close") + + .def("CloseAll", CloseAllStage) + .staticmethod("CloseAll"); } }