/* drawing (DXF) to G-code (NGC) converter
* Copyright 2013 Stefan Schuermans <stefan@schuermans.info>
* Copyleft: CC-BY-SA http://creativecommons.org/licenses/by-sa/3.0/
*/
#include <dime/Input.h>
#include <dime/Model.h>
#include <iostream>
#include <map>
#include <string>
#include "drawing.h"
#include "layer.h"
#include "traverse.h"
/**
* @brief clear all contents of drawing
*/
void Drawing::clear()
{
mLayers.clear();
}
/**
* @brief add a DXF file to this drawing
* @param[in] strFileName name of the DXF file to read
* @return if the DXF file could be read
*/
bool Drawing::addDxf(const std::string &strFileName)
{
// read DXF file
dimeInput in;
if (!in.setFile(strFileName.c_str())) {
std::cerr << "error opening file \"" << strFileName
<< "\" for reading" << std::endl;
return false;
}
dimeModel model;
if (!model.read(&in)) {
std::cerr << "DXF read error in line " << in.getFilePosition()
<< " of file \"" << strFileName << "\""
<< std::endl;
return false;
}
// enumerate all entities and add them to drawing
struct traverse_ctx ctx;
ctx.mpDrawing = this;
model.traverseEntities(traverse_entity, &ctx);
return true;