diff --git a/src/importdxf.cpp b/src/importdxf.cpp index 99059b90..dd582aa4 100644 --- a/src/importdxf.cpp +++ b/src/importdxf.cpp @@ -1,5 +1,6 @@ #include "solvespace.h" #include "libdxfrw.h" +#include "libdwgr.h" #ifdef WIN32 // Conflicts with DRW::TEXT. @@ -882,11 +883,26 @@ void ImportDxf(const std::string &filename) { dxfRW dxf(filename.c_str()); DxfReadInterface interface; interface.clearBlockTransform(); - dxf.read(&interface, false); + if(!dxf.read(&interface, false)) { + Error("Corrupted DXF file!"); + } if(interface.unknownEntities > 0) { Message(ssprintf("%u DXF entities of unknown type were ignored.", interface.unknownEntities).c_str()); } } +void ImportDwg(const std::string &filename) { + dwgR dwg(filename.c_str()); + DxfReadInterface interface; + interface.clearBlockTransform(); + if(!dwg.read(&interface, false)) { + Error("Corrupted DWG file!"); + } + if(interface.unknownEntities > 0) { + Message(ssprintf("%u DWG entities of unknown type were ignored.", + interface.unknownEntities).c_str()); + } +} + } diff --git a/src/solvespace.cpp b/src/solvespace.cpp index 12acc283..0c6e7615 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -547,7 +547,11 @@ void SolveSpaceUI::MenuFile(int id) { ImportableFileFilter)) break; CnfFreezeString(Extension(importFile), "ImportFormat"); - ImportDxf(importFile); + if(Extension(importFile) == "dxf") { + ImportDxf(importFile); + } else if(Extension(importFile) == "dwg") { + ImportDwg(importFile); + } else oops(); break; } diff --git a/src/solvespace.h b/src/solvespace.h index 46c597f3..9c5fcc8b 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -952,6 +952,7 @@ public: }; void ImportDxf(const std::string &file); +void ImportDwg(const std::string &file); extern SolveSpaceUI SS; extern Sketch SK;