/////////////////////////////////////////////////////////////////////////////// // 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. /////////////////////////////////////////////////////////////////////////////// #include "OdaCommon.h" #include "ExMeshConvertToSolid.h" #include "StaticRxObject.h" #include "DbUserIO.h" #include "DbCommandContext.h" #include "Db3dSolid.h" #include "DbBlockTableRecord.h" class SurfaceFilter : public OdStaticRxObject { public: SurfaceFilter() {} int addDrawables(OdGsView*) { return 0; } void removeDrawables(OdGsView*) { } bool check(const OdDbObjectId&) { return true; } bool append(const OdDbObjectId& entId, const OdDbSelectionMethod*) { return check(entId); } bool remove(const OdDbObjectId& entId, const OdDbSelectionMethod*) { return check(entId); } }; const OdString MeshToSolidCommand::globalName() const { return OD_T("MeshToSolid"); } const OdString MeshToSolidCommand::groupName() const { return OD_T("MODELER GEOMETRY"); } void MeshToSolidCommand::execute(OdEdCommandContext* pCmdCtx) { OdDbCommandContextPtr pDbCmdCtx(pCmdCtx); OdDbDatabasePtr pDb = pDbCmdCtx->database(); OdSmartPtr pIO = pDbCmdCtx->userIO(); if (pIO.isNull()) return; try { SurfaceFilter filter; OdDbSelectionSetPtr pSet = pIO->select(OD_T("Select Mesh for solid creation:"), OdEd::kSelAllowSubentsAlways, 0, OdString::kEmpty, &filter); bool bSmoothed = pIO->getInt(OD_T("Smoothing mode(0 - unsmoothed, 1 - smoothed)"), OdEd::kSelSingleEntity, 0, OdString::kEmpty) != 0; bool bOptimize = pIO->getInt(OD_T("Optimization mode(0 - not optimize, 1 - optimize)"), OdEd::kSelSingleEntity, 0, OdString::kEmpty) != 0; if (pSet->numEntities() == 0) { pIO->putString(OD_T("Nothing selected.")); return; } OdDbSelectionSetIteratorPtr pIt = pSet->newIterator(); unsigned int solidsCount = 0; while (!pIt->done()) { OdDbObjectPtr pObj = pIt->objectId().safeOpenObject(OdDb::kForWrite); OdDbEntityPtr pSubDMesh = OdDbEntity::cast(pObj); if (pSubDMesh.isNull() || !pSubDMesh->isKindOf(OdDbSubDMesh::desc())) { pIO->putString(OD_T("Unsupported entity.")); return; } OdDb3dSolidPtr pNewSolid; OdResult res = static_cast(pSubDMesh.get())->convertToSolid(bSmoothed, bOptimize, pNewSolid); if (res != eOk) { OdString tmp; tmp.format(OD_T("Error : %s"), OdError(res).description().c_str()); pIO->putString(tmp); return; } solidsCount++; OdDbObjectId ownerId = pSubDMesh->ownerId(); if (ownerId && ownerId.database()) { OdDbBlockTableRecordPtr pBlock = ownerId.openObject(OdDb::kForWrite); pBlock->appendOdDbEntity(pNewSolid); pSubDMesh->erase(); OdString tmp; tmp.format(OD_T("%d Solid created"), solidsCount); pIO->putString(tmp); } pIt->next(); } } catch (...) { pIO->putString(OD_T("Create Solid Failed!")); } }