dxf-parser
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -1,2 +0,2 @@ | ||
(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){ | ||
(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){ | ||
/** | ||
@@ -445,3 +445,3 @@ * AutoCad files sometimes use an indexed color value between 1 and 255 inclusive. | ||
DxfParser.prototype._parse = function(dxfString) { | ||
var scanner, curr, dxf = {}; | ||
var scanner, curr, dxf = {}, lastHandle = 0; | ||
var dxfLinesArray = dxfString.split(/\r\n|\r|\n/g); | ||
@@ -555,2 +555,3 @@ | ||
log.debug('}'); | ||
ensureHandle(block); | ||
blocks[block.handle] = block; | ||
@@ -716,3 +717,2 @@ } else { | ||
var tableRecords = table[tableDefinition.tableRecordsProperty]; | ||
console.error(typeof(tableRecords)); | ||
if(tableRecords) { | ||
@@ -985,19 +985,20 @@ if(tableRecords.constructor === Array){ | ||
} | ||
var entity; | ||
// Supported entities here | ||
if(curr.value === 'LWPOLYLINE') { | ||
log.debug('LWPOLYLINE {'); | ||
entities.push(parseLWPOLYLINE()); | ||
entity = parseLWPOLYLINE(); | ||
log.debug('}') | ||
} else if(curr.value === 'POLYLINE') { | ||
log.debug('POLYLINE {'); | ||
entities.push(parsePOLYLINE()); | ||
entity = parsePOLYLINE(); | ||
log.debug('}'); | ||
} else if(curr.value === 'LINE') { | ||
log.debug('LINE {'); | ||
entities.push(parseLINE()); | ||
entity = parseLINE(); | ||
log.debug('}'); | ||
} else if(curr.value === 'CIRCLE') { | ||
log.debug('CIRCLE {'); | ||
entities.push(parseCIRCLE()); | ||
entity = parseCIRCLE(); | ||
log.debug('}'); | ||
@@ -1007,27 +1008,27 @@ } else if(curr.value === 'ARC') { | ||
// similar properties to circle? | ||
entities.push(parseCIRCLE()); | ||
entity = parseCIRCLE(); | ||
log.debug('}') | ||
} else if(curr.value === 'TEXT') { | ||
log.debug('TEXT {'); | ||
entities.push(parseTEXT()); | ||
entity = parseTEXT(); | ||
log.debug('}') | ||
} else if(curr.value === 'DIMENSION') { | ||
log.debug('DIMENSION {'); | ||
entities.push(parseDIMENSION()); | ||
entity = parseDIMENSION(); | ||
log.debug('}') | ||
} else if(curr.value === 'SOLID') { | ||
log.debug('SOLID {'); | ||
entities.push(parseSOLID()); | ||
entity = parseSOLID(); | ||
log.debug('}') | ||
} else if(curr.value === 'POINT') { | ||
log.debug('POINT {'); | ||
entities.push(parsePOINT()); | ||
entity = parsePOINT(); | ||
log.debug('}') | ||
} else if(curr.value === 'MTEXT') { | ||
log.debug('MTEXT {'); | ||
entities.push(parseMTEXT()); | ||
entity = parseMTEXT(); | ||
log.debug('}') | ||
} else if(curr.value === 'ATTDEF') { | ||
log.debug('ATTDEF {'); | ||
entities.push(parseATTDEF()); | ||
entity = parseATTDEF(); | ||
log.debug('}') | ||
@@ -1037,4 +1038,6 @@ } else { | ||
curr = scanner.next(); | ||
continue; | ||
} | ||
ensureHandle(entity); | ||
entities.push(entity); | ||
} else { | ||
@@ -1710,2 +1713,8 @@ // ignored lines from unsupported entity | ||
}; | ||
var ensureHandle = function(entity) { | ||
if(!entity) throw new TypeError('entity cannot be undefined or null'); | ||
if(!entity.handle) entity.handle = lastHandle++; | ||
}; | ||
@@ -1712,0 +1721,0 @@ parseAll(); |
@@ -57,3 +57,3 @@ var DxfArrayScanner = require('./DxfArrayScanner.js'), | ||
DxfParser.prototype._parse = function(dxfString) { | ||
var scanner, curr, dxf = {}; | ||
var scanner, curr, dxf = {}, lastHandle = 0; | ||
var dxfLinesArray = dxfString.split(/\r\n|\r|\n/g); | ||
@@ -167,2 +167,3 @@ | ||
log.debug('}'); | ||
ensureHandle(block); | ||
blocks[block.handle] = block; | ||
@@ -328,3 +329,2 @@ } else { | ||
var tableRecords = table[tableDefinition.tableRecordsProperty]; | ||
console.error(typeof(tableRecords)); | ||
if(tableRecords) { | ||
@@ -597,19 +597,20 @@ if(tableRecords.constructor === Array){ | ||
} | ||
var entity; | ||
// Supported entities here | ||
if(curr.value === 'LWPOLYLINE') { | ||
log.debug('LWPOLYLINE {'); | ||
entities.push(parseLWPOLYLINE()); | ||
entity = parseLWPOLYLINE(); | ||
log.debug('}') | ||
} else if(curr.value === 'POLYLINE') { | ||
log.debug('POLYLINE {'); | ||
entities.push(parsePOLYLINE()); | ||
entity = parsePOLYLINE(); | ||
log.debug('}'); | ||
} else if(curr.value === 'LINE') { | ||
log.debug('LINE {'); | ||
entities.push(parseLINE()); | ||
entity = parseLINE(); | ||
log.debug('}'); | ||
} else if(curr.value === 'CIRCLE') { | ||
log.debug('CIRCLE {'); | ||
entities.push(parseCIRCLE()); | ||
entity = parseCIRCLE(); | ||
log.debug('}'); | ||
@@ -619,27 +620,27 @@ } else if(curr.value === 'ARC') { | ||
// similar properties to circle? | ||
entities.push(parseCIRCLE()); | ||
entity = parseCIRCLE(); | ||
log.debug('}') | ||
} else if(curr.value === 'TEXT') { | ||
log.debug('TEXT {'); | ||
entities.push(parseTEXT()); | ||
entity = parseTEXT(); | ||
log.debug('}') | ||
} else if(curr.value === 'DIMENSION') { | ||
log.debug('DIMENSION {'); | ||
entities.push(parseDIMENSION()); | ||
entity = parseDIMENSION(); | ||
log.debug('}') | ||
} else if(curr.value === 'SOLID') { | ||
log.debug('SOLID {'); | ||
entities.push(parseSOLID()); | ||
entity = parseSOLID(); | ||
log.debug('}') | ||
} else if(curr.value === 'POINT') { | ||
log.debug('POINT {'); | ||
entities.push(parsePOINT()); | ||
entity = parsePOINT(); | ||
log.debug('}') | ||
} else if(curr.value === 'MTEXT') { | ||
log.debug('MTEXT {'); | ||
entities.push(parseMTEXT()); | ||
entity = parseMTEXT(); | ||
log.debug('}') | ||
} else if(curr.value === 'ATTDEF') { | ||
log.debug('ATTDEF {'); | ||
entities.push(parseATTDEF()); | ||
entity = parseATTDEF(); | ||
log.debug('}') | ||
@@ -649,4 +650,6 @@ } else { | ||
curr = scanner.next(); | ||
continue; | ||
} | ||
ensureHandle(entity); | ||
entities.push(entity); | ||
} else { | ||
@@ -1322,2 +1325,8 @@ // ignored lines from unsupported entity | ||
}; | ||
var ensureHandle = function(entity) { | ||
if(!entity) throw new TypeError('entity cannot be undefined or null'); | ||
if(!entity.handle) entity.handle = lastHandle++; | ||
}; | ||
@@ -1324,0 +1333,0 @@ parseAll(); |
{ | ||
"name": "dxf-parser", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Parse dxf files into a readable, logical js object.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -45,3 +45,3 @@ | ||
* LType table | ||
* Block table (not inserts) | ||
* Block table | ||
* VPort table | ||
@@ -51,3 +51,3 @@ * Text and some MTEXT | ||
Does not yet support | ||
* Attributes | ||
* Block Inserts | ||
* 3DSolids | ||
@@ -54,0 +54,0 @@ * All types of Leaders |
187307
12
5513