/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef OD_TV_DATABASECLEANER_H #define OD_TV_DATABASECLEANER_H #include "TvDatabase.h" #include "TvGroup.h" #include "TvInsert.h" #define STL_USING_SET #define STL_USING_MAP #include "OdaSTL.h" typedef OdVector OdTvGsViewIdArray; typedef std::set< OdTvBlockId > OdTvBlockIdSet; typedef std::map< OdTvBlockId, bool > OdTvBlockIdMap; class OdTvDatabaseCleaner { public: static void cleanTvDatabase(OdTvDatabaseId& tvDbId); static void cleanTvDatabaseForAppend(OdTvDatabaseId& tvDbId, std::set& foreignViews, std::set& foreignModels, std::set& foreignBlocks); static bool cleanTvModel(OdTvModelId& modelId); static bool clearGeometryLevel(OdTvEntityPtr pEntity); private: static bool clearModelsLevel(OdTvGsViewPtr pView, OdTvBlockIdSet& blockArray, OdTvBlockIdMap& blockVisitedMap); static bool clearModelsLevelForAppend(OdTvGsViewPtr pView, std::set& foreignModels, OdTvBlockIdSet& blockArray, OdTvBlockIdMap& blockVisitedMap); template static bool clearEntitiesLevel(T pObj, OdTvBlockIdSet& keepAliveBlockArray, OdTvBlockIdMap& blockVisitedMap) { bool bIsEmpty = true; for (OdTvEntitiesIteratorPtr pIt = pObj->getEntitiesIterator(); !pIt->done(); pIt->step()) { OdTvEntityId entityId = pIt->getEntity(); if (entityId.getType() == OdTvEntityId::kEntity) { OdTvEntityPtr pEntity = entityId.openObject(OdTv::kForWrite); if (clearGeometryLevel(pEntity)) pObj->removeEntity(entityId); else bIsEmpty = false; } else if (entityId.getType() == OdTvEntityId::kInsert) { OdTvInsertPtr pInsert = entityId.openObjectAsInsert(OdTv::kForWrite); OdTvBlockId blockId = pInsert->getBlock(); OdTvBlockIdMap::iterator itBlock = blockVisitedMap.find(blockId); if (itBlock == blockVisitedMap.end()) { OdTvBlockPtr pBlock = blockId.openObject(OdTv::kForWrite); if (clearEntitiesLevel(pBlock, keepAliveBlockArray, blockVisitedMap)) { blockVisitedMap.insert(std::pair(blockId, true)); if (pInsert->hasSubEntities()) { //SEA VIS-3807 //This block is empty, but insert is not. So, we keep insert alive and have to keep block alive too keepAliveBlockArray.insert(pInsert->getBlock()); bIsEmpty = false; } else { pObj->removeEntity(entityId); } } else { blockVisitedMap.insert(std::pair(blockId, false)); bIsEmpty = false; } } else // already visited { if (itBlock->second) { if (pInsert->hasSubEntities()) { //SEA VIS-3807 //This block is empty, but insert is not. So, we keep insert alive and have to keep block alive too keepAliveBlockArray.insert(pInsert->getBlock()); bIsEmpty = false; } else { pObj->removeEntity(entityId); } } else bIsEmpty = false; } } else if (entityId.getType() == OdTvEntityId::kGroup) { if (clearEntitiesLevel(entityId.openObjectAsGroup(OdTv::kForWrite), keepAliveBlockArray, blockVisitedMap)) pObj->removeEntity(entityId); else bIsEmpty = false; } else bIsEmpty = false; } return bIsEmpty; } static bool modelIsFromActiveView(OdTvModelId modelId, OdTvGsViewIdArray& activesViews); }; #endif //OD_TV_DATABASECLEANER_H