DWG: implement import.

Before this commit, the file filter suggested that DWG was readable,
but it wasn't.

Also, report any failures while reading DWG and DXF files.
pull/4/head
whitequark 2016-05-07 05:17:23 +00:00
parent 7da5cfbaae
commit d05e9a938b
3 changed files with 23 additions and 2 deletions

View File

@ -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());
}
}
}

View File

@ -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;
}

View File

@ -952,6 +952,7 @@ public:
};
void ImportDxf(const std::string &file);
void ImportDwg(const std::string &file);
extern SolveSpaceUI SS;
extern Sketch SK;