/////////////////////////////////////////////////////////////////////////////// // 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 "RxObject.h" #include "Br/BrBrep.h" #include "MemoryStream.h" #include "StepDgnCmds.h" #include "Ed/EdUserIO.h" #include "Ed/EdCommandStack.h" #include "DgCommandContext.h" #include "DgHostAppServices.h" #include "DgModelerGeometry.h" #include "DgBRepEntityPE.h" #include "BrepBuilderFillerModule.h" #include "BaseMaterialAndColorHelper.h" #include "StepCore.h" #include "ExStepHostAppServices.h" #include "StepManifoldSolidBrep.h" using namespace OdStep; OdStaticRxObject svcs; OdString g_workDir; void setModuleWorkDir(const OdString& moduleName) { g_workDir = moduleName; int pos = g_workDir.reverseFind('\\'); if (pos < 0) { pos = g_workDir.reverseFind('/'); } if (pos > 0) { g_workDir = g_workDir.mid(0, pos + 1); } } namespace { class OdStep2DgnMaterialAndColorHelper : public OdBaseMaterialAndColorHelper { protected: virtual OdResult convertColor(const OdCmEntityColor& sourceDbColor, OdCmEntityColor& destinationDbColor) override { destinationDbColor = sourceDbColor; return eOk; } }; } void _StepBrep2Dgn_func(OdEdCommandContext* pCmdCtx) { OdDgCommandContextPtr pDbCmdCtx(pCmdCtx); OdDgUserIO* pIO = pDbCmdCtx->dbUserIO(); OdString fileName = pIO->getString(OD_T("Enter STEP file name :")); if (fileName.isEmpty()) { pIO->putString(OD_T("Empty filename entered")); return; } OdDbHandle brepId = pIO->getInt(OD_T("Enter manifold_solid_brep id: "), 0, 0); if ((OdUInt64)brepId <= 0) { pIO->putString(OD_T("Incorrect object id")); return; } odStepInitialize(false, true); { //Sets the StepSolidModeler to generate brep as MdBody OdStep::OdStepGeometricRepresentationItemMD::setDataAsMdBody(true); svcs.setFilesDir(g_workDir + OD_T("Schemas/")); OdStepFilePtr pFile = svcs.readFile(fileName); if (pFile.isNull()) { pIO->putString(OD_T("Failed to read STEP file")); return; } OdDAI::ModelPtr pModel = pFile->getModel(sdaiRW); if (pModel.isNull()) { pIO->putString(OD_T("Failed to get STEP model")); return; } OdDAIObjectId brepObjId = pModel->getEntityInstance(brepId); if (brepObjId.isNull()) { pIO->putString(OD_T("Failed to read manifold_solid_brep id from file")); return; } OdStep::OdStepManifoldSolidBrepPtr pSolidBrep = pFile->getCompound(brepObjId); if (pSolidBrep.isNull()) { pIO->putString(OD_T("Failed to read entered id as manifold_solid_brep")); return; } //Load Dgn Brep modeler OdRxModulePtr pModule = ::odrxDynamicLinker()->loadModule("TG_ModelerGeometry"); if (pModule.isNull()) { pIO->putString(OD_T("Failed to get DGN geometry modeler")); return; } OdBrBrep brep; pSolidBrep->brep(brep); OdDgDatabase* pDb = pDbCmdCtx->database(); OdBrepBuilder brepBuilder; pDb->appServices()->brepBuilder(brepBuilder, kSolid, false); brepBuilder.enableValidator(false/*true*/); OdBrepBuilderFiller filler; filler.params().setupFor(OdBrepBuilderFillerParams::kBrepStep, pFile, OdBrepBuilderFillerParams::kBrepPS/*OdBrepBuilderFillerParams::kBrepAcisDgn*/, pDb); //Init materials and colors support OdStep2DgnMaterialAndColorHelper materialAndColorHelper; filler.initFrom(brepBuilder, brep, &materialAndColorHelper); OdDgModelerGeometryPtr pDgnModelerData = brepBuilder.finish(); OdStreamBufPtr pMemStream = OdMemoryStream::createNew(); pDgnModelerData->out(pMemStream,/* OdDgModelerGeometry::kParasolidMask |*/ OdDgModelerGeometry::kPS_12_6 | OdDgModelerGeometry::kXB_Bare); pMemStream->seek(0, OdDb::kSeekFromStart); //Create new Dgn object with generated brep OdDgCellHeader3dPtr pCellHeader = OdDgCellHeader3d::createObject(); pCellHeader->setLevelEntryId(0x40); OdDgModelPtr pDgnModel = pDb->getActiveModelId().openObject(OdDg::kForWrite); pDgnModel->setName("BrBrep"); pDgnModel->setWorkingUnit(OdDgModel::kWuWorldUnit); pDgnModel->addElement(pCellHeader); // fill entity with data OdDgBRepEntityPEPtr(pCellHeader)->fillSmartSolid(*pCellHeader, *pMemStream.get(), false, 0.0, false); } odStepUninitialize(); }