BlinkenArea - GitList
Repositories
Blog
Wiki
dxfngc
Code
Commits
Branches
Tags
Search
Tree:
be85cfc
Branches
Tags
master
dxfngc
src
traverse.cpp
initial version, DXFs can be read, some G-code can be produced
Stefan Schuermans
commited
be85cfc
at 2013-01-20 20:53:53
traverse.cpp
Blame
History
Raw
/* 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/entities/Entity.h> #include <dime/State.h> #include <string> #include "drawing.h" #include "layer.h" #include "path.h" #include "traverse.h" /** * @brief process an entity during DXF traversal * @param[in] state current state of libdime * @param[in] entity pointer to entity * @param[in] vp_ctx context pointer, must point to traverse_ctx structure * @return if to continue enumeration */ bool traverse_entity(const class dimeState * const state, dimeEntity *entity, void *vp_ctx) { struct traverse_ctx *p_ctx = (struct traverse_ctx *)vp_ctx; // get layer std::string strLayerName = entity->getLayerName(); Layer &layer = p_ctx->mpDrawing->mLayers[strLayerName]; // get transformation matrix dimeMatrix matrix; state->getMatrix(matrix); // get geometry data dimeArray<dimeVec3f> vertices; dimeArray<int> indices; dimeVec3f extrusionDir; dxfdouble thickness; entity->extractGeometry(vertices, indices, extrusionDir, thickness); // transform geometry data for (int v = 0; v < vertices.count(); ++v) matrix.multMatrixVec(vertices[v]); // no indices -> entire vertices array forms a path if (indices.count() == 0) { Path &path = layer.addPath(); for (int v = 0; v < vertices.count(); ++v) path.addPoint(vertices[v].x, vertices[v].y); } // indices available: paths given by indices else { Path *path = &layer.addPath(); for (int i = 0; i < indices.count(); ++i) { int v = indices[i]; // valid index: add to path if (v >= 0 || v < vertices.count()) path->addPoint(vertices[v].x, vertices[v].y); // invalid index: start new path else path = &layer.addPath(); } } return true; // continue enumeration }