/////////////////////////////////////////////////////////////////////////////// // 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 "NwGiWorldDraw.h" #include "DynamicLinker.h" #include "NwGiContext.h" #include "DbBaseDatabase.h" #include "RxRasterServices.h" #include "Gi/GiRasterImage.h" #include "ColorMapping.h" OdNwGiWorldDraw::OdNwGiWorldDraw() : m_OutPath() , m_Width(512) , m_Height(512) { } OdNwGiWorldDraw::~OdNwGiWorldDraw() { } void OdNwGiWorldDraw::setOutput(const OdString& path) { m_OutPath = path; } void OdNwGiWorldDraw::setWidth(OdUInt32 width) { m_Width = width; } void OdNwGiWorldDraw::setHeight(OdUInt32 height) { m_Height = height; } static bool isDarkPalette(ODCOLORREF bgColor) { return (ODGETRED(bgColor) < 140) && (ODGETGREEN(bgColor) < 140) && (ODGETBLUE(bgColor) < 140); } OdResult OdNwGiWorldDraw::drawByDb(OdNwDatabase* pDb, const OdString& moduleName) const { // - initialize device OdGsModulePtr pGsModule = ::odrxDynamicLinker()->loadModule(moduleName); OdGsDevicePtr pBitmapDevice; if (pGsModule.get()) { pBitmapDevice = pGsModule->createBitmapDevice(); } if (!pBitmapDevice.get()) { throw OdError(eDeviceNotFound); } // - setup render params OdGiContextForNwDatabasePtr pNvContext = OdGiContextForNwDatabase::createObject(); pNvContext->setDatabase(pDb); pNvContext->enableGsModel(true); OdDbBaseDatabasePEPtr pDbPE = OdNwDatabase::desc()->getX(OdDbBaseDatabasePE::desc()); pBitmapDevice = pDbPE->setupActiveLayoutViews(pBitmapDevice, pNvContext); ODCOLORREF bgColor = ODRGB(0, 0, 0); pBitmapDevice->setLogicalPalette((isDarkPalette(bgColor)) ? (::odcmAcadDarkPalette()) : (::odcmAcadLightPalette()), 256); pBitmapDevice->setBackgroundColor(bgColor); // - setup output dims OdGsDCRect screenRect(OdGsDCPoint(0, m_Height), OdGsDCPoint(m_Width, 0)); pBitmapDevice->onSize(screenRect); // - render image (internal) pBitmapDevice->update(); // - save image // - NOTICE that type of raster file is deducted from example input (e.g. if output file is D:\picture.bmp image will be saved as .bmp) OdGiRasterImagePtr ptrImage = pBitmapDevice->properties()->getAt(OD_T("RasterImage")); OdRxRasterServicesPtr pRasSvcs = ::odrxDynamicLinker()->loadApp(RX_RASTER_SERVICES_APPNAME); if (pRasSvcs.get()) { OdString img(m_OutPath); pRasSvcs->saveRasterImage(ptrImage, img); } return eOk; }