dxf-parser
Advanced tools
Comparing version 0.4.8 to 0.5.0
@@ -1006,2 +1006,6 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.DxfParser = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
log.debug('}'); | ||
} else if (curr.value === '3DFACE') { | ||
log.debug('3DFACE {'); | ||
entity = parse3DFACE(); | ||
log.debug('}'); | ||
} else if(curr.value === 'CIRCLE') { | ||
@@ -1048,2 +1052,6 @@ log.debug('CIRCLE {'); | ||
log.debug('}'); | ||
} else if(curr.value == 'SPLINE') { | ||
log.debug('INSERT {'); | ||
entity = parseSPLINE(); | ||
log.debug('}'); | ||
} else { | ||
@@ -1264,5 +1272,7 @@ log.warn('Unhandled entity ' + curr.value); | ||
default: | ||
//todo: mark unhandled somehow? | ||
curr = scanner.next(); | ||
continue; | ||
// if we do not hit known code return vertices. Code might belong to entity | ||
if (vertexIsStarted) { | ||
vertices.push(vertex); | ||
} | ||
return vertices; | ||
} | ||
@@ -1451,3 +1461,83 @@ curr = scanner.next(); | ||
}; | ||
var parse3dFaceVertices = function(entity) { | ||
var vertices = [], | ||
i; | ||
var vertexIsStarted = false; | ||
var vertexIsFinished = false; | ||
var verticesPer3dFace = 4; // there can be up to four vertices per face, although 3 is most used for TIN | ||
for (i = 0; i <= verticesPer3dFace; i++) { | ||
var vertex = {}; | ||
while (curr !== 'EOF') { | ||
if (curr.code === 0 || vertexIsFinished) break; | ||
switch (curr.code) { | ||
case 10: // X0 | ||
case 11: // X1 | ||
case 12: // X2 | ||
case 13: // X3 | ||
if (vertexIsStarted) { | ||
vertexIsFinished = true; | ||
continue; | ||
} | ||
vertex.x = curr.value; | ||
vertexIsStarted = true; | ||
break; | ||
case 20: // Y | ||
case 21: | ||
case 22: | ||
case 23: | ||
vertex.y = curr.value; | ||
break; | ||
case 30: // Z | ||
case 31: | ||
case 32: | ||
case 33: | ||
vertex.z = curr.value; | ||
break; | ||
default: | ||
// it is possible to have entity codes after the vertices. | ||
// So if code is not accounted for return to entity parser where it might be accounted for | ||
return vertices; | ||
continue; | ||
} | ||
curr = scanner.next(); | ||
} | ||
// See https://groups.google.com/forum/#!topic/comp.cad.autocad/9gn8s5O_w6E | ||
vertices.push(vertex); | ||
vertexIsStarted = false; | ||
vertexIsFinished = false; | ||
} | ||
return vertices; | ||
}; | ||
/** | ||
* Called when the parser reads the beginning of a new entity, | ||
* 0:parse3DFACE. Scanner.next() will return the first attribute of the | ||
* entity. | ||
* @return {Object} the entity parsed | ||
*/ | ||
var parse3DFACE = function() { | ||
var entity = { type: curr.value, vertices: [] }; | ||
curr = scanner.next(); | ||
while (curr !== 'EOF') { | ||
if (curr.code === 0) break; | ||
switch (curr.code) { | ||
case 70: // 1 = Closed shape, 128 = plinegen?, 0 = default | ||
entity.shape = ((curr.value & 1) === 1); | ||
entity.hasContinuousLinetypePattern = ((curr.value & 128) === 128); | ||
curr = scanner.next(); | ||
break; | ||
case 10: // X coordinate of point | ||
entity.vertices = parse3dFaceVertices(); | ||
break; | ||
default: | ||
checkCommonEntityProperties(entity); | ||
break; | ||
} | ||
} | ||
return entity; | ||
}; | ||
/** | ||
@@ -1491,2 +1581,14 @@ * Called when the parser reads the beginning of a new entity, | ||
break; | ||
case 210: | ||
entity.extrusionDirectionX = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
case 220: | ||
entity.extrusionDirectionY = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
case 230: | ||
entity.extrusionDirectionZ = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
default: | ||
@@ -1814,2 +1916,71 @@ checkCommonEntityProperties(entity); | ||
var parseSPLINE = function() { | ||
var entity; | ||
entity = { type: curr.value }; | ||
curr = scanner.next(); | ||
while(curr !== 'EOF') | ||
{ | ||
if(curr.code === 0) break; | ||
switch(curr.code) { | ||
case 10: | ||
if (!entity.controlPoints) entity.controlPoints = []; | ||
entity.controlPoints.push(parsePoint()); | ||
break; | ||
case 11: | ||
if (!entity.fitPoints) entity.fitPoints = []; | ||
entity.fitPoints.push(parsePoint()); | ||
break; | ||
case 12: | ||
entity.startTangent = parsePoint(); | ||
break; | ||
case 13: | ||
entity.endTangent = parsePoint(); | ||
break; | ||
case 40: | ||
if (!entity.knotValues) entity.knotValues = []; | ||
entity.knotValues.push(curr.value); | ||
curr = scanner.next(); | ||
break; | ||
case 70: | ||
if ((curr.value & 1) != 0) entity.closed = true; | ||
if ((curr.value & 2) != 0) entity.periodic = true; | ||
if ((curr.value & 4) != 0) entity.rational = true; | ||
if ((curr.value & 8) != 0) entity.planar = true; | ||
if ((curr.value & 16) != 0) | ||
{ | ||
entity.planar = true; | ||
entity.linear = true; | ||
} | ||
curr = scanner.next(); | ||
break; | ||
case 71: | ||
entity.degreeOfSplineCurve = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
case 72: | ||
entity.numberOfKnots = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
case 73: | ||
entity.numberOfControlPoints = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
case 74: | ||
entity.numberOfFitPoints = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
case 210: | ||
entity.normalVector = parsePoint(); | ||
break; | ||
default: | ||
checkCommonEntityProperties(entity); | ||
break; | ||
} | ||
} | ||
return entity; | ||
}; | ||
var parseELLIPSE = function() { | ||
@@ -1816,0 +1987,0 @@ var entity; |
@@ -618,2 +618,6 @@ var DxfArrayScanner = require('./DxfArrayScanner.js'), | ||
log.debug('}'); | ||
} else if (curr.value === '3DFACE') { | ||
log.debug('3DFACE {'); | ||
entity = parse3DFACE(); | ||
log.debug('}'); | ||
} else if(curr.value === 'CIRCLE') { | ||
@@ -660,2 +664,6 @@ log.debug('CIRCLE {'); | ||
log.debug('}'); | ||
} else if(curr.value == 'SPLINE') { | ||
log.debug('INSERT {'); | ||
entity = parseSPLINE(); | ||
log.debug('}'); | ||
} else { | ||
@@ -876,5 +884,7 @@ log.warn('Unhandled entity ' + curr.value); | ||
default: | ||
//todo: mark unhandled somehow? | ||
curr = scanner.next(); | ||
continue; | ||
// if we do not hit known code return vertices. Code might belong to entity | ||
if (vertexIsStarted) { | ||
vertices.push(vertex); | ||
} | ||
return vertices; | ||
} | ||
@@ -1063,3 +1073,83 @@ curr = scanner.next(); | ||
}; | ||
var parse3dFaceVertices = function(entity) { | ||
var vertices = [], | ||
i; | ||
var vertexIsStarted = false; | ||
var vertexIsFinished = false; | ||
var verticesPer3dFace = 4; // there can be up to four vertices per face, although 3 is most used for TIN | ||
for (i = 0; i <= verticesPer3dFace; i++) { | ||
var vertex = {}; | ||
while (curr !== 'EOF') { | ||
if (curr.code === 0 || vertexIsFinished) break; | ||
switch (curr.code) { | ||
case 10: // X0 | ||
case 11: // X1 | ||
case 12: // X2 | ||
case 13: // X3 | ||
if (vertexIsStarted) { | ||
vertexIsFinished = true; | ||
continue; | ||
} | ||
vertex.x = curr.value; | ||
vertexIsStarted = true; | ||
break; | ||
case 20: // Y | ||
case 21: | ||
case 22: | ||
case 23: | ||
vertex.y = curr.value; | ||
break; | ||
case 30: // Z | ||
case 31: | ||
case 32: | ||
case 33: | ||
vertex.z = curr.value; | ||
break; | ||
default: | ||
// it is possible to have entity codes after the vertices. | ||
// So if code is not accounted for return to entity parser where it might be accounted for | ||
return vertices; | ||
continue; | ||
} | ||
curr = scanner.next(); | ||
} | ||
// See https://groups.google.com/forum/#!topic/comp.cad.autocad/9gn8s5O_w6E | ||
vertices.push(vertex); | ||
vertexIsStarted = false; | ||
vertexIsFinished = false; | ||
} | ||
return vertices; | ||
}; | ||
/** | ||
* Called when the parser reads the beginning of a new entity, | ||
* 0:parse3DFACE. Scanner.next() will return the first attribute of the | ||
* entity. | ||
* @return {Object} the entity parsed | ||
*/ | ||
var parse3DFACE = function() { | ||
var entity = { type: curr.value, vertices: [] }; | ||
curr = scanner.next(); | ||
while (curr !== 'EOF') { | ||
if (curr.code === 0) break; | ||
switch (curr.code) { | ||
case 70: // 1 = Closed shape, 128 = plinegen?, 0 = default | ||
entity.shape = ((curr.value & 1) === 1); | ||
entity.hasContinuousLinetypePattern = ((curr.value & 128) === 128); | ||
curr = scanner.next(); | ||
break; | ||
case 10: // X coordinate of point | ||
entity.vertices = parse3dFaceVertices(); | ||
break; | ||
default: | ||
checkCommonEntityProperties(entity); | ||
break; | ||
} | ||
} | ||
return entity; | ||
}; | ||
/** | ||
@@ -1103,2 +1193,14 @@ * Called when the parser reads the beginning of a new entity, | ||
break; | ||
case 210: | ||
entity.extrusionDirectionX = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
case 220: | ||
entity.extrusionDirectionY = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
case 230: | ||
entity.extrusionDirectionZ = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
default: | ||
@@ -1426,2 +1528,71 @@ checkCommonEntityProperties(entity); | ||
var parseSPLINE = function() { | ||
var entity; | ||
entity = { type: curr.value }; | ||
curr = scanner.next(); | ||
while(curr !== 'EOF') | ||
{ | ||
if(curr.code === 0) break; | ||
switch(curr.code) { | ||
case 10: | ||
if (!entity.controlPoints) entity.controlPoints = []; | ||
entity.controlPoints.push(parsePoint()); | ||
break; | ||
case 11: | ||
if (!entity.fitPoints) entity.fitPoints = []; | ||
entity.fitPoints.push(parsePoint()); | ||
break; | ||
case 12: | ||
entity.startTangent = parsePoint(); | ||
break; | ||
case 13: | ||
entity.endTangent = parsePoint(); | ||
break; | ||
case 40: | ||
if (!entity.knotValues) entity.knotValues = []; | ||
entity.knotValues.push(curr.value); | ||
curr = scanner.next(); | ||
break; | ||
case 70: | ||
if ((curr.value & 1) != 0) entity.closed = true; | ||
if ((curr.value & 2) != 0) entity.periodic = true; | ||
if ((curr.value & 4) != 0) entity.rational = true; | ||
if ((curr.value & 8) != 0) entity.planar = true; | ||
if ((curr.value & 16) != 0) | ||
{ | ||
entity.planar = true; | ||
entity.linear = true; | ||
} | ||
curr = scanner.next(); | ||
break; | ||
case 71: | ||
entity.degreeOfSplineCurve = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
case 72: | ||
entity.numberOfKnots = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
case 73: | ||
entity.numberOfControlPoints = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
case 74: | ||
entity.numberOfFitPoints = curr.value; | ||
curr = scanner.next(); | ||
break; | ||
case 210: | ||
entity.normalVector = parsePoint(); | ||
break; | ||
default: | ||
checkCommonEntityProperties(entity); | ||
break; | ||
} | ||
} | ||
return entity; | ||
}; | ||
var parseELLIPSE = function() { | ||
@@ -1428,0 +1599,0 @@ var entity; |
{ | ||
"name": "dxf-parser", | ||
"version": "0.4.8", | ||
"version": "0.5.0", | ||
"description": "Parse dxf files into a readable, logical js object.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
210619
6232