/////////////////////////////////////////////////////////////////////////////// // 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. /////////////////////////////////////////////////////////////////////////////// /************************************************************************/ /* This console application reads a SVG file, and saves it to a DWG */ /* file in the current version */ /* */ /* Calling sequence: */ /* */ /* OdSvgImportEx */ /* */ /************************************************************************/ #include "OdaCommon.h" #define STL_USING_IOSTREAM #include "OdaSTL.h" #define STD(a) std:: a #include "DbDatabase.h" #include "ExSystemServices.h" #include "ExHostAppServices.h" #include "OdFileBuf.h" #include "RxModule.h" #include "RxDynamicModule.h" #include "RxVariantValue.h" #include "ColorMapping.h" #include "SvgImport.h" #include #include "diagnostics.h" #ifdef OD_HAVE_CONSOLE_H_FILE #include #endif static void myTrace(const OdChar* debugString) { (void)debugString; #if defined(_DEBUG) && defined(_WIN32) OutputDebugStringW((const wchar_t*)debugString); #endif } //---------------------------------------------------------------------------------- class MyServices : public ExSystemServices, public ExHostAppServices { protected: ODRX_USING_HEAP_OPERATORS(ExSystemServices); }; #ifndef _TOOLKIT_IN_DLL_ ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(SvgImportModule); ODRX_BEGIN_STATIC_MODULE_MAP() ODRX_DEFINE_STATIC_APPLICATION(L"TD_SvgImport", SvgImportModule) ODRX_END_STATIC_MODULE_MAP() #endif /************************************************************************/ /* Main */ /************************************************************************/ #if defined(OD_USE_WMAIN) int wmain(int argc, wchar_t* argv[]) #else int main(int argc, char* argv[]) #endif { #ifdef OD_HAVE_CCOMMAND_FUNC argc = ccommand(&argv); #endif if (argc < 3) { odPrintConsoleString(L"usage: OdSvgImportEx \n"); } else { /********************************************************************/ /* For correct Unicode translation, apply the current system locale.*/ /********************************************************************/ setlocale(LC_ALL, ""); /********************************************************************/ /* But use usual conversion for scanf()/sprintf() */ /********************************************************************/ setlocale(LC_NUMERIC, "C"); #ifndef _TOOLKIT_IN_DLL_ ODRX_INIT_STATIC_MODULE_MAP(); #endif /********************************************************************/ /* Create a custom Services instance. */ /********************************************************************/ OdStaticRxObject svcs; svcs.setRecomputeDimBlocksRequired(false); odInitialize(&svcs); odSetTraceFunc(&myTrace); /********************************************************************/ /* Display the Product and Version that created the executable */ /********************************************************************/ odPrintConsoleString(L"Developed using %ls, %ls\n", svcs.product().c_str(), svcs.versionString().c_str()); try { /****************************************************************/ /* Create importer object */ /****************************************************************/ OdSvgImportModulePtr pModule = ::odrxDynamicLinker()->loadApp(L"TD_SvgImport"); if (pModule.isNull()) { odPrintConsoleString(L"Error load TD_SvgImport\n"); } else /****************************************************************/ /* Import SVG file */ /****************************************************************/ { OdDbDatabasePtr pDb = svcs.createDatabase(); /**************************************************************/ /* Create SVG importer */ /**************************************************************/ auto im = pModule->create(); /**************************************************************/ /* Set the conversion parameters */ /**************************************************************/ im->properties()->putAt(L"Database", pDb); im->properties()->putAt(L"SvgPath", OdRxVariantValue(OdString(argv[1]))); im->properties()->putAt(L"Palette", OdRxVariantValue(OdIntPtr(::odcmAcadLightPalette()))); im->properties()->putAt(L"Tolerance", OdRxVariantValue(0.001)); im->properties()->putAt(L"BlockName", OdRxVariantValue(OdString("SVG"))); im->properties()->putAt(L"LineWeightScale", OdRxVariantValue(25.0)); //Import svg from buffer /*OdStreamBufPtr svgBuffer = odSystemServices()->createFile(L"pathToSvg.svg"); im->properties()->putAt(L"InputStream", svgBuffer.get());*/ /**************************************************************/ /* Import SVG file */ /**************************************************************/ auto res = im->import(); if (res != OdSvgImport::ImportResult::success) throw OdError(OD_T("SVG Import error")); //importer = 0; /**************************************************************/ /* Write DWG file */ /**************************************************************/ OdString out(argv[2]); OdWrFileBuf fb(out); pDb->writeFile(&fb, OdDb::kDwg, OdDb::kDHL_CURRENT); } } catch (OdError& err) { odPrintConsoleString(L"ODA SDK Error: %ls\n\n", err.description().c_str()); } catch (...) { odPrintConsoleString(L"Unknown Error.\n\n"); return 0; } odUninitialize(); } return 0; }