@vitrosoftware/common-ui-ts 1.1.121 → 1.1.123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css/std/controls/checkbox/checkbox.css +4 -0
- package/css/std/controls/checkbox/img/checkbox-indeterminate.svg +4 -0
- package/css/std/controls/date-picker/date-picker.css +1 -25
- package/css/std/controls/dxf-viewer/annotation.css +85 -0
- package/css/std/controls/dxf-viewer/common.css +24 -0
- package/css/std/controls/dxf-viewer/dxf-viewer-index.css +14081 -0
- package/css/std/controls/dxf-viewer/dxf-viewer.css +194 -0
- package/css/std/controls/dxf-viewer/img/cancel-dark-grey.svg +5 -0
- package/css/std/controls/dxf-viewer/img/collapse-bottom.svg +5 -0
- package/css/std/controls/dxf-viewer/img/collapse-up-blue.svg +5 -0
- package/css/std/controls/dxf-viewer/img/delete-active.svg +11 -0
- package/css/std/controls/dxf-viewer/img/delete.svg +11 -0
- package/css/std/controls/dxf-viewer/img/draw-annotation.svg +3 -0
- package/css/std/controls/dxf-viewer/img/invisible-eye.svg +4 -0
- package/css/std/controls/dxf-viewer/img/show-annotation.svg +3 -0
- package/css/std/controls/dxf-viewer/img/sidebar-layers-toggle.svg +6 -0
- package/css/std/controls/dxf-viewer/img/sidebar-notes-toggle.svg +5 -0
- package/css/std/controls/dxf-viewer/img/sidebar-resizer.svg +6 -0
- package/css/std/controls/dxf-viewer/img/sidebar-toggle.svg +7 -0
- package/css/std/controls/dxf-viewer/img/visible-eye.svg +4 -0
- package/css/std/controls/dxf-viewer/img/zoom-in.svg +6 -0
- package/css/std/controls/dxf-viewer/img/zoom-out.svg +5 -0
- package/css/std/controls/dxf-viewer/layer-list.css +104 -0
- package/css/std/controls/dxf-viewer/panel.css +34 -0
- package/css/std/controls/dxf-viewer/prop-inspector.css +102 -0
- package/css/std/controls/dxf-viewer/select.css +111 -0
- package/css/std/controls/dxf-viewer/sidebar.css +190 -0
- package/css/std/controls/dxf-viewer/thumbnail-list.css +65 -0
- package/css/std/controls/dxf-viewer/toolbar.css +117 -0
- package/css/std/controls/dxf-viewer/treeview.css +3 -0
- package/css/std/controls/dxf-viewer/treeview.panel.css +108 -0
- package/css/std/controls/error-message/error-message.css +22 -0
- package/css/std/controls/image-picker/image-picker.css +0 -26
- package/css/std/controls/input/input.css +1 -24
- package/css/std/controls/issue-tile/issue-tile-header.css +1 -0
- package/css/std/controls/login/ntlm-authentication-form.css +9 -12
- package/css/std/controls/lookup-picker/lookup-picker-value-list.css +38 -2
- package/css/std/controls/lookup-picker/lookup-picker.css +1 -25
- package/css/std/controls/table-view/treegrid-context-menu.css +44 -18
- package/css/std/controls/table-view/treegrid-message.css +4 -4
- package/css/std/controls/time-picker/time-picker.css +1 -25
- package/dist/index.css +81 -143
- package/dist/index.js +15137 -489
- package/dist/index.js.map +1 -1
- package/dist/src/controls/Checkbox/Checkbox.d.ts +1 -0
- package/dist/src/controls/DxfViewer/DxfViewer.d.ts +6 -0
- package/dist/src/controls/DxfViewer/DxfViewerContext.d.ts +31 -0
- package/dist/src/controls/DxfViewer/Layer.d.ts +9 -0
- package/dist/src/controls/DxfViewer/LayerList.d.ts +11 -0
- package/dist/src/controls/DxfViewer/Thumbnail.d.ts +7 -0
- package/dist/src/controls/DxfViewer/ThumbnailList.d.ts +6 -0
- package/dist/src/controls/DxfViewer/Viewer.d.ts +6 -0
- package/dist/src/controls/ErrorMessage/ErrorMessage.d.ts +6 -0
- package/dist/src/controls/Login/FormRef.d.ts +3 -0
- package/dist/src/controls/Login/LoginConstants.d.ts +2 -1
- package/dist/src/controls/Login/LoginFormRef.d.ts +2 -2
- package/dist/src/controls/Login/NTLMAuthenticationForm.d.ts +5 -2
- package/dist/src/controls/LookupPicker/LookupPicker.d.ts +2 -0
- package/dist/src/controls/LookupPicker/ValueList.d.ts +2 -0
- package/dist/src/controls/TableView/TableViewConstants.d.ts +11 -0
- package/dist/src/controls/TableView/TreeGridTableViewContextImpl.d.ts +1 -0
- package/dist/src/controls/TreeView/TreeView.d.ts +4 -0
- package/dist/src/controls/TreeView/TreeViewConfig.d.ts +3 -0
- package/dist/src/controls/TreeView/TreeViewConstants.d.ts +2 -1
- package/dist/src/index.d.ts +7 -1
- package/lib/dxf-viewer/BatchingKey.js +91 -0
- package/lib/dxf-viewer/DxfFetcher.js +39 -0
- package/lib/dxf-viewer/DxfScene.js +2695 -0
- package/lib/dxf-viewer/DxfViewer.js +1056 -0
- package/lib/dxf-viewer/DxfWorker.js +229 -0
- package/lib/dxf-viewer/DynamicBuffer.js +100 -0
- package/lib/dxf-viewer/HatchCalculator.js +345 -0
- package/lib/dxf-viewer/LinearDimension.js +323 -0
- package/lib/dxf-viewer/MTextFormatParser.js +211 -0
- package/lib/dxf-viewer/MaterialKey.js +37 -0
- package/lib/dxf-viewer/OrbitControls.js +1253 -0
- package/lib/dxf-viewer/Pattern.js +94 -0
- package/lib/dxf-viewer/RBTree.js +471 -0
- package/lib/dxf-viewer/TextRenderer.js +1038 -0
- package/lib/dxf-viewer/index.js +42 -0
- package/lib/dxf-viewer/math/Matrix2.js +77 -0
- package/lib/dxf-viewer/math/utils.js +59 -0
- package/lib/dxf-viewer/parser/AutoCadColorIndex.js +265 -0
- package/lib/dxf-viewer/parser/DimStyleCodes.js +33 -0
- package/lib/dxf-viewer/parser/DxfArrayScanner.js +143 -0
- package/lib/dxf-viewer/parser/DxfParser.js +980 -0
- package/lib/dxf-viewer/parser/ExtendedDataParse-My.js +91 -0
- package/lib/dxf-viewer/parser/ExtendedDataParser.js +123 -0
- package/lib/dxf-viewer/parser/ParseHelpers.js +142 -0
- package/lib/dxf-viewer/parser/entities/3dface.js +83 -0
- package/lib/dxf-viewer/parser/entities/arc.js +38 -0
- package/lib/dxf-viewer/parser/entities/attdef.js +89 -0
- package/lib/dxf-viewer/parser/entities/attrib.js +34 -0
- package/lib/dxf-viewer/parser/entities/attribute.js +109 -0
- package/lib/dxf-viewer/parser/entities/circle.js +43 -0
- package/lib/dxf-viewer/parser/entities/dimension.js +72 -0
- package/lib/dxf-viewer/parser/entities/ellipse.js +46 -0
- package/lib/dxf-viewer/parser/entities/hatch.js +343 -0
- package/lib/dxf-viewer/parser/entities/insert.js +62 -0
- package/lib/dxf-viewer/parser/entities/leader.js +84 -0
- package/lib/dxf-viewer/parser/entities/line.js +34 -0
- package/lib/dxf-viewer/parser/entities/lwpolyline.js +100 -0
- package/lib/dxf-viewer/parser/entities/mtext.js +54 -0
- package/lib/dxf-viewer/parser/entities/point.js +35 -0
- package/lib/dxf-viewer/parser/entities/polyline.js +92 -0
- package/lib/dxf-viewer/parser/entities/solid.js +40 -0
- package/lib/dxf-viewer/parser/entities/spline.js +70 -0
- package/lib/dxf-viewer/parser/entities/text.js +47 -0
- package/lib/dxf-viewer/parser/entities/vertex.js +62 -0
- package/lib/dxf-viewer/parser/entities/viewport.js +56 -0
- package/lib/dxf-viewer/parser/objects/dictionary.js +29 -0
- package/lib/dxf-viewer/parser/objects/layout.js +35 -0
- package/lib/dxf-viewer/parser/objects/xrecord.js +29 -0
- package/lib/opentype/opentype.module.js +14571 -0
- package/lib/three/CSS2DRenderer.js +235 -0
- package/lib/three/three.module.js +49912 -0
- package/lib/xeokit/xeokit-sdk-2.6.10.es.js +136629 -0
- package/lib/xeokit/xeokit-sdk-2.6.10.min.es.js +299 -0
- package/package.json +12 -10
- package/src/controls/BimViewer/js/bim-viewer-models.js +93 -0
- package/src/controls/BimViewer/js/bim-viewer.js +194 -5
- package/src/controls/DxfViewer/js/dxf-viewer.js +3541 -0
- package/src/controls/PdfViewer/js/pdf-viewer.js +1 -1
- package/css/std/controls/input/img/error-message.svg +0 -6
- package/css/std/controls/lookup-picker/img/error-message.svg +0 -6
- package/css/std/controls/time-picker/img/error-message.svg +0 -6
- package/dist/src/controls/ActionHandler/ActionInfo.d.ts +0 -12
- package/dist/src/controls/ActionHandler/ActionInfoItem.d.ts +0 -13
- package/dist/src/controls/ActionHandler/UpdatingPopover.d.ts +0 -2
- package/dist/src/controls/Dialog/DialogButton.d.ts +0 -8
- package/dist/src/controls/Dialog/DialogCloseButton.d.ts +0 -8
- package/dist/src/controls/Icon/Icon.d.ts +0 -11
- package/dist/src/controls/Search/Input.d.ts +0 -21
- package/dist/src/controls/Search/SearchConstants.d.ts +0 -4
- /package/css/std/controls/{date-picker → error-message}/img/error-message.svg +0 -0
|
@@ -0,0 +1,980 @@
|
|
|
1
|
+
import DxfArrayScanner from './DxfArrayScanner.js';
|
|
2
|
+
import AUTO_CAD_COLOR_INDEX from './AutoCadColorIndex.js';
|
|
3
|
+
|
|
4
|
+
import Face from './entities/3dface.js';
|
|
5
|
+
import Arc from './entities/arc.js';
|
|
6
|
+
import AttDef from './entities/attdef.js';
|
|
7
|
+
import Attribute from './entities/attribute.js'
|
|
8
|
+
import Circle from './entities/circle.js';
|
|
9
|
+
import Dimension from './entities/dimension.js';
|
|
10
|
+
import Ellipse from './entities/ellipse.js';
|
|
11
|
+
import Insert from './entities/insert.js';
|
|
12
|
+
import Line from './entities/line.js';
|
|
13
|
+
import LWPolyline from './entities/lwpolyline.js';
|
|
14
|
+
import MText from './entities/mtext.js';
|
|
15
|
+
import Point from './entities/point.js';
|
|
16
|
+
import Polyline from './entities/polyline.js';
|
|
17
|
+
import Solid from './entities/solid.js';
|
|
18
|
+
import Spline from './entities/spline.js';
|
|
19
|
+
import Text from './entities/text.js';
|
|
20
|
+
import Hatch from './entities/hatch.js';
|
|
21
|
+
import dimStyleCodes from './DimStyleCodes.js';
|
|
22
|
+
import Leader from './entities/leader.js';
|
|
23
|
+
import Viewport from './entities/viewport.js';
|
|
24
|
+
//import Vertex from './entities/';
|
|
25
|
+
|
|
26
|
+
import Layout from './objects/layout.js';
|
|
27
|
+
|
|
28
|
+
export { DxfParser };
|
|
29
|
+
|
|
30
|
+
let log = { debug: () => { }, warn: () => { }, error: () => { }, setLevel: () => { } }
|
|
31
|
+
|
|
32
|
+
//log.setLevel('trace');
|
|
33
|
+
//log.setLevel('debug');
|
|
34
|
+
//log.setLevel('info');
|
|
35
|
+
//log.setLevel('warn');
|
|
36
|
+
log.setLevel('error');
|
|
37
|
+
//log.setLevel('silent');
|
|
38
|
+
|
|
39
|
+
function registerDefaultEntityHandlers(dxfParser) {
|
|
40
|
+
// Supported entities here (some entity code is still being refactored into this flow)
|
|
41
|
+
dxfParser.registerEntityHandler(Face);
|
|
42
|
+
dxfParser.registerEntityHandler(Arc);
|
|
43
|
+
dxfParser.registerEntityHandler(AttDef);
|
|
44
|
+
dxfParser.registerEntityHandler(Attribute);
|
|
45
|
+
dxfParser.registerEntityHandler(Circle);
|
|
46
|
+
dxfParser.registerEntityHandler(Dimension);
|
|
47
|
+
dxfParser.registerEntityHandler(Ellipse);
|
|
48
|
+
dxfParser.registerEntityHandler(Insert);
|
|
49
|
+
dxfParser.registerEntityHandler(Line);
|
|
50
|
+
dxfParser.registerEntityHandler(LWPolyline);
|
|
51
|
+
dxfParser.registerEntityHandler(MText);
|
|
52
|
+
dxfParser.registerEntityHandler(Point);
|
|
53
|
+
dxfParser.registerEntityHandler(Polyline);
|
|
54
|
+
dxfParser.registerEntityHandler(Solid);
|
|
55
|
+
dxfParser.registerEntityHandler(Spline);
|
|
56
|
+
dxfParser.registerEntityHandler(Text);
|
|
57
|
+
dxfParser.registerEntityHandler(Hatch);
|
|
58
|
+
dxfParser.registerEntityHandler(Leader);
|
|
59
|
+
dxfParser.registerEntityHandler(Viewport);
|
|
60
|
+
//dxfParser.registerEntityHandler(require('./entities/vertex'));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function registerDefaultObjectHandlers(dxfParser) {
|
|
64
|
+
// Supported objects here
|
|
65
|
+
dxfParser.registerObjectHandler(Layout);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default function DxfParser() {
|
|
69
|
+
this._entityHandlers = {};
|
|
70
|
+
this._objectHandlers = {};
|
|
71
|
+
|
|
72
|
+
registerDefaultEntityHandlers(this);
|
|
73
|
+
registerDefaultObjectHandlers(this);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
DxfParser.prototype.parse = function(source, done) {
|
|
77
|
+
throw new Error("read() not implemented. Use readSync()");
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
DxfParser.prototype.registerEntityHandler = function(handlerType) {
|
|
81
|
+
var instance = new handlerType();
|
|
82
|
+
this._entityHandlers[handlerType.ForEntityName] = instance;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
DxfParser.prototype.registerObjectHandler = function(handlerType) {
|
|
86
|
+
var instance = new handlerType();
|
|
87
|
+
this._objectHandlers[handlerType.ForEntityName] = instance;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
DxfParser.prototype.parseSync = function(source) {
|
|
91
|
+
if(typeof(source) === 'string') {
|
|
92
|
+
return this._parse(source);
|
|
93
|
+
}else {
|
|
94
|
+
console.error('Cannot read DXF source of type `' + typeof (source));
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
DxfParser.prototype.parseStream = function(stream, done) {
|
|
100
|
+
|
|
101
|
+
var dxfString = "";
|
|
102
|
+
var self = this;
|
|
103
|
+
|
|
104
|
+
stream.on('data', onData);
|
|
105
|
+
stream.on('end', onEnd);
|
|
106
|
+
stream.on('error', onError);
|
|
107
|
+
|
|
108
|
+
function onData(chunk) {
|
|
109
|
+
dxfString += chunk;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function onEnd() {
|
|
113
|
+
try {
|
|
114
|
+
var dxf = self._parse(dxfString);
|
|
115
|
+
}catch(err) {
|
|
116
|
+
return done(err);
|
|
117
|
+
}
|
|
118
|
+
done(null, dxf);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function onError(err) {
|
|
122
|
+
done(err);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
DxfParser.prototype._parse = function(dxfString) {
|
|
127
|
+
var scanner, curr, dxf = {}, lastHandle = 0;
|
|
128
|
+
var dxfLinesArray = dxfString.split(/\r\n|\r|\n/g);
|
|
129
|
+
|
|
130
|
+
scanner = new DxfArrayScanner(dxfLinesArray);
|
|
131
|
+
if (!scanner.hasNext()) {
|
|
132
|
+
throw Error('Empty file');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var self = this;
|
|
136
|
+
|
|
137
|
+
var parseAll = function() {
|
|
138
|
+
curr = scanner.next();
|
|
139
|
+
while(!scanner.isEOF()) {
|
|
140
|
+
if(curr.code === 0 && curr.value === 'SECTION') {
|
|
141
|
+
curr = scanner.next();
|
|
142
|
+
|
|
143
|
+
// Be sure we are reading a section code
|
|
144
|
+
if (curr.code !== 2) {
|
|
145
|
+
console.error('Unexpected code %s after 0:SECTION', debugCode(curr));
|
|
146
|
+
curr = scanner.next();
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (curr.value === 'HEADER') {
|
|
151
|
+
log.debug('> HEADER');
|
|
152
|
+
dxf.header = parseHeader();
|
|
153
|
+
log.debug('<');
|
|
154
|
+
} else if (curr.value === 'BLOCKS') {
|
|
155
|
+
log.debug('> BLOCKS');
|
|
156
|
+
dxf.blocks = parseBlocks();
|
|
157
|
+
log.debug('<');
|
|
158
|
+
} else if(curr.value === 'ENTITIES') {
|
|
159
|
+
log.debug('> ENTITIES');
|
|
160
|
+
dxf.entities = parseEntities(false);
|
|
161
|
+
log.debug('<');
|
|
162
|
+
} else if(curr.value === 'OBJECTS') {
|
|
163
|
+
log.debug('> OBJECTS');
|
|
164
|
+
dxf.objects = parseObjects();
|
|
165
|
+
log.debug('<');
|
|
166
|
+
} else if(curr.value === 'TABLES') {
|
|
167
|
+
log.debug('> TABLES');
|
|
168
|
+
dxf.tables = parseTables();
|
|
169
|
+
log.debug('<');
|
|
170
|
+
} else if(curr.value === 'EOF') {
|
|
171
|
+
log.debug('EOF');
|
|
172
|
+
} else {
|
|
173
|
+
log.warn('Skipping section \'%s\'', curr.value);
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
curr = scanner.next();
|
|
177
|
+
}
|
|
178
|
+
// If is a new section
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
var groupIs = function(code, value) {
|
|
183
|
+
return curr.code === code && curr.value === value;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
*
|
|
188
|
+
* @return {object} header
|
|
189
|
+
*/
|
|
190
|
+
var parseHeader = function() {
|
|
191
|
+
// interesting variables:
|
|
192
|
+
// $ACADVER, $VIEWDIR, $VIEWSIZE, $VIEWCTR, $TDCREATE, $TDUPDATE
|
|
193
|
+
// http://www.autodesk.com/techpubs/autocad/acadr14/dxf/header_section_al_u05_c.htm
|
|
194
|
+
// Also see VPORT table entries
|
|
195
|
+
var currVarName = null, currVarValue = null;
|
|
196
|
+
var header = {};
|
|
197
|
+
// loop through header variables
|
|
198
|
+
curr = scanner.next();
|
|
199
|
+
|
|
200
|
+
while(true) {
|
|
201
|
+
if(groupIs(0, 'ENDSEC')) {
|
|
202
|
+
if(currVarName) header[currVarName] = currVarValue;
|
|
203
|
+
break;
|
|
204
|
+
} else if(curr.code === 9) {
|
|
205
|
+
if(currVarName) header[currVarName] = currVarValue;
|
|
206
|
+
currVarName = curr.value;
|
|
207
|
+
// Filter here for particular variables we are interested in
|
|
208
|
+
} else {
|
|
209
|
+
if(curr.code === 10) {
|
|
210
|
+
currVarValue = { x: curr.value };
|
|
211
|
+
} else if(curr.code === 20) {
|
|
212
|
+
currVarValue.y = curr.value;
|
|
213
|
+
} else if(curr.code === 30) {
|
|
214
|
+
currVarValue.z = curr.value;
|
|
215
|
+
} else {
|
|
216
|
+
currVarValue = curr.value;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
curr = scanner.next();
|
|
220
|
+
}
|
|
221
|
+
// console.log(util.inspect(header, { colors: true, depth: null }));
|
|
222
|
+
curr = scanner.next(); // swallow up ENDSEC
|
|
223
|
+
return header;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
*
|
|
229
|
+
*/
|
|
230
|
+
var parseBlocks = function() {
|
|
231
|
+
var blocks = {}, block;
|
|
232
|
+
|
|
233
|
+
curr = scanner.next();
|
|
234
|
+
|
|
235
|
+
while(curr.value !== 'EOF') {
|
|
236
|
+
if(groupIs(0, 'ENDSEC')) {
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if(groupIs(0, 'BLOCK')) {
|
|
241
|
+
log.debug('block {');
|
|
242
|
+
block = parseBlock();
|
|
243
|
+
log.debug('}');
|
|
244
|
+
ensureHandle(block);
|
|
245
|
+
if (!block.name) {
|
|
246
|
+
groupIs(0, 'BLOCK');
|
|
247
|
+
log.error('block with handle "' + block.handle + '" is missing a name.');
|
|
248
|
+
}
|
|
249
|
+
else
|
|
250
|
+
blocks[block.name] = block;
|
|
251
|
+
} else {
|
|
252
|
+
logUnhandledGroup(curr);
|
|
253
|
+
curr = scanner.next();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return blocks;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
var parseBlock = function() {
|
|
260
|
+
var block = {};
|
|
261
|
+
curr = scanner.next();
|
|
262
|
+
|
|
263
|
+
while(curr.value !== 'EOF') {
|
|
264
|
+
switch(curr.code) {
|
|
265
|
+
case 1:
|
|
266
|
+
block.xrefPath = curr.value;
|
|
267
|
+
curr = scanner.next();
|
|
268
|
+
break;
|
|
269
|
+
case 2:
|
|
270
|
+
block.name = curr.value;
|
|
271
|
+
curr = scanner.next();
|
|
272
|
+
break;
|
|
273
|
+
case 3:
|
|
274
|
+
block.name2 = curr.value;
|
|
275
|
+
curr = scanner.next();
|
|
276
|
+
break;
|
|
277
|
+
case 5:
|
|
278
|
+
block.handle = curr.value;
|
|
279
|
+
curr = scanner.next();
|
|
280
|
+
break;
|
|
281
|
+
case 8:
|
|
282
|
+
block.layer = curr.value;
|
|
283
|
+
curr = scanner.next();
|
|
284
|
+
break;
|
|
285
|
+
case 10:
|
|
286
|
+
block.position = parsePoint();
|
|
287
|
+
curr = scanner.next();
|
|
288
|
+
break;
|
|
289
|
+
case 67:
|
|
290
|
+
block.paperSpace = (curr.value && curr.value == 1) ? true : false;
|
|
291
|
+
curr = scanner.next();
|
|
292
|
+
break;
|
|
293
|
+
case 70:
|
|
294
|
+
if (curr.value != 0) {
|
|
295
|
+
//if(curr.value & BLOCK_ANONYMOUS_FLAG) console.log(' Anonymous block');
|
|
296
|
+
//if(curr.value & BLOCK_NON_CONSTANT_FLAG) console.log(' Non-constant attributes');
|
|
297
|
+
//if(curr.value & BLOCK_XREF_FLAG) console.log(' Is xref');
|
|
298
|
+
//if(curr.value & BLOCK_XREF_OVERLAY_FLAG) console.log(' Is xref overlay');
|
|
299
|
+
//if(curr.value & BLOCK_EXTERNALLY_DEPENDENT_FLAG) console.log(' Is externally dependent');
|
|
300
|
+
//if(curr.value & BLOCK_RESOLVED_OR_DEPENDENT_FLAG) console.log(' Is resolved xref or dependent of an xref');
|
|
301
|
+
//if(curr.value & BLOCK_REFERENCED_XREF) console.log(' This definition is a referenced xref');
|
|
302
|
+
block.type = curr.value;
|
|
303
|
+
}
|
|
304
|
+
curr = scanner.next();
|
|
305
|
+
break;
|
|
306
|
+
case 100:
|
|
307
|
+
// ignore class markers
|
|
308
|
+
curr = scanner.next();
|
|
309
|
+
break;
|
|
310
|
+
case 330:
|
|
311
|
+
block.ownerHandle = curr.value;
|
|
312
|
+
curr = scanner.next();
|
|
313
|
+
break;
|
|
314
|
+
case 0:
|
|
315
|
+
if(curr.value == 'ENDBLK')
|
|
316
|
+
break;
|
|
317
|
+
block.entities = parseEntities(true);
|
|
318
|
+
break;
|
|
319
|
+
default:
|
|
320
|
+
logUnhandledGroup(curr);
|
|
321
|
+
curr = scanner.next();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if(groupIs(0, 'ENDBLK')) {
|
|
325
|
+
curr = scanner.next();
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return block;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* parseTables
|
|
334
|
+
* @return {Object} Object representing tables
|
|
335
|
+
*/
|
|
336
|
+
var parseTables = function() {
|
|
337
|
+
var tables = {};
|
|
338
|
+
curr = scanner.next();
|
|
339
|
+
while(curr.value !== 'EOF') {
|
|
340
|
+
if(groupIs(0, 'ENDSEC'))
|
|
341
|
+
break;
|
|
342
|
+
|
|
343
|
+
if(groupIs(0, 'TABLE')) {
|
|
344
|
+
curr = scanner.next();
|
|
345
|
+
|
|
346
|
+
var tableDefinition = tableDefinitions[curr.value];
|
|
347
|
+
if(tableDefinition) {
|
|
348
|
+
log.debug(curr.value + ' Table {');
|
|
349
|
+
tables[tableDefinitions[curr.value].tableName] = parseTable();
|
|
350
|
+
log.debug('}');
|
|
351
|
+
} else {
|
|
352
|
+
log.debug('Unhandled Table ' + curr.value);
|
|
353
|
+
}
|
|
354
|
+
} else {
|
|
355
|
+
// else ignored
|
|
356
|
+
curr = scanner.next();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
curr = scanner.next();
|
|
361
|
+
return tables;
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
const END_OF_TABLE_VALUE = 'ENDTAB';
|
|
365
|
+
|
|
366
|
+
var parseTable = function() {
|
|
367
|
+
var tableDefinition = tableDefinitions[curr.value],
|
|
368
|
+
table = {},
|
|
369
|
+
expectedCount = 0,
|
|
370
|
+
actualCount;
|
|
371
|
+
|
|
372
|
+
curr = scanner.next();
|
|
373
|
+
while(!groupIs(0, END_OF_TABLE_VALUE)) {
|
|
374
|
+
|
|
375
|
+
switch(curr.code) {
|
|
376
|
+
case 5:
|
|
377
|
+
table.handle = curr.value;
|
|
378
|
+
curr = scanner.next();
|
|
379
|
+
break;
|
|
380
|
+
case 330:
|
|
381
|
+
table.ownerHandle = curr.value;
|
|
382
|
+
curr = scanner.next();
|
|
383
|
+
break;
|
|
384
|
+
case 100:
|
|
385
|
+
if(curr.value === 'AcDbSymbolTable') {
|
|
386
|
+
// ignore
|
|
387
|
+
curr = scanner.next();
|
|
388
|
+
}else{
|
|
389
|
+
logUnhandledGroup(curr);
|
|
390
|
+
curr = scanner.next();
|
|
391
|
+
}
|
|
392
|
+
break;
|
|
393
|
+
case 70:
|
|
394
|
+
expectedCount = curr.value;
|
|
395
|
+
curr = scanner.next();
|
|
396
|
+
break;
|
|
397
|
+
case 0:
|
|
398
|
+
if(curr.value === tableDefinition.dxfSymbolName) {
|
|
399
|
+
table[tableDefinition.tableRecordsProperty] = tableDefinition.parseTableRecords();
|
|
400
|
+
} else {
|
|
401
|
+
logUnhandledGroup(curr);
|
|
402
|
+
curr = scanner.next();
|
|
403
|
+
}
|
|
404
|
+
break;
|
|
405
|
+
default:
|
|
406
|
+
logUnhandledGroup(curr);
|
|
407
|
+
curr = scanner.next();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
var tableRecords = table[tableDefinition.tableRecordsProperty];
|
|
411
|
+
if(tableRecords) {
|
|
412
|
+
if(tableRecords.constructor === Array){
|
|
413
|
+
actualCount = tableRecords.length;
|
|
414
|
+
} else if(typeof(tableRecords) === 'object') {
|
|
415
|
+
actualCount = Object.keys(tableRecords).length;
|
|
416
|
+
}
|
|
417
|
+
if(expectedCount !== actualCount)
|
|
418
|
+
expectedCount !== actualCount;
|
|
419
|
+
log.warn('Parsed ' + actualCount + ' ' + tableDefinition.dxfSymbolName + '\'s but expected ' + expectedCount);
|
|
420
|
+
}
|
|
421
|
+
curr = scanner.next();
|
|
422
|
+
return table;
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
var parseViewPortRecords = function() {
|
|
426
|
+
var viewPorts = [], // Multiple table entries may have the same name indicating a multiple viewport configuration
|
|
427
|
+
viewPort = {};
|
|
428
|
+
|
|
429
|
+
log.debug('ViewPort {');
|
|
430
|
+
curr = scanner.next();
|
|
431
|
+
while(!groupIs(0, END_OF_TABLE_VALUE)) {
|
|
432
|
+
|
|
433
|
+
switch(curr.code) {
|
|
434
|
+
case 2: // layer name
|
|
435
|
+
viewPort.name = curr.value;
|
|
436
|
+
curr = scanner.next();
|
|
437
|
+
break;
|
|
438
|
+
case 10:
|
|
439
|
+
viewPort.lowerLeftCorner = parsePoint();
|
|
440
|
+
curr = scanner.next();
|
|
441
|
+
break;
|
|
442
|
+
case 11:
|
|
443
|
+
viewPort.upperRightCorner = parsePoint();
|
|
444
|
+
curr = scanner.next();
|
|
445
|
+
break;
|
|
446
|
+
case 12:
|
|
447
|
+
viewPort.center = parsePoint();
|
|
448
|
+
curr = scanner.next();
|
|
449
|
+
break;
|
|
450
|
+
case 13:
|
|
451
|
+
viewPort.snapBasePoint = parsePoint();
|
|
452
|
+
curr = scanner.next();
|
|
453
|
+
break;
|
|
454
|
+
case 14:
|
|
455
|
+
viewPort.snapSpacing = parsePoint();
|
|
456
|
+
curr = scanner.next();
|
|
457
|
+
break;
|
|
458
|
+
case 15:
|
|
459
|
+
viewPort.gridSpacing = parsePoint();
|
|
460
|
+
curr = scanner.next();
|
|
461
|
+
break;
|
|
462
|
+
case 16:
|
|
463
|
+
viewPort.viewDirectionFromTarget = parsePoint();
|
|
464
|
+
curr = scanner.next();
|
|
465
|
+
break;
|
|
466
|
+
case 17:
|
|
467
|
+
viewPort.viewTarget = parsePoint();
|
|
468
|
+
curr = scanner.next();
|
|
469
|
+
break;
|
|
470
|
+
case 42:
|
|
471
|
+
viewPort.lensLength = curr.value;
|
|
472
|
+
curr = scanner.next();
|
|
473
|
+
break;
|
|
474
|
+
case 43:
|
|
475
|
+
viewPort.frontClippingPlane = curr.value;
|
|
476
|
+
curr = scanner.next();
|
|
477
|
+
break;
|
|
478
|
+
case 44:
|
|
479
|
+
viewPort.backClippingPlane = curr.value;
|
|
480
|
+
curr = scanner.next();
|
|
481
|
+
break;
|
|
482
|
+
case 45:
|
|
483
|
+
viewPort.viewHeight = curr.value;
|
|
484
|
+
curr = scanner.next();
|
|
485
|
+
break;
|
|
486
|
+
case 50:
|
|
487
|
+
viewPort.snapRotationAngle = curr.value;
|
|
488
|
+
curr = scanner.next();
|
|
489
|
+
break;
|
|
490
|
+
case 51:
|
|
491
|
+
viewPort.viewTwistAngle = curr.value;
|
|
492
|
+
curr = scanner.next();
|
|
493
|
+
break;
|
|
494
|
+
case 79:
|
|
495
|
+
viewPort.orthographicType = curr.value;
|
|
496
|
+
curr = scanner.next();
|
|
497
|
+
break;
|
|
498
|
+
case 110:
|
|
499
|
+
viewPort.ucsOrigin = parsePoint();
|
|
500
|
+
curr = scanner.next();
|
|
501
|
+
break;
|
|
502
|
+
case 111:
|
|
503
|
+
viewPort.ucsXAxis = parsePoint();
|
|
504
|
+
curr = scanner.next();
|
|
505
|
+
break;
|
|
506
|
+
case 112:
|
|
507
|
+
viewPort.ucsYAxis = parsePoint();
|
|
508
|
+
curr = scanner.next();
|
|
509
|
+
break;
|
|
510
|
+
case 110:
|
|
511
|
+
viewPort.ucsOrigin = parsePoint();
|
|
512
|
+
curr = scanner.next();
|
|
513
|
+
break;
|
|
514
|
+
case 281:
|
|
515
|
+
viewPort.renderMode = curr.value;
|
|
516
|
+
curr = scanner.next();
|
|
517
|
+
break;
|
|
518
|
+
case 281:
|
|
519
|
+
// 0 is one distant light, 1 is two distant lights
|
|
520
|
+
viewPort.defaultLightingType = curr.value;
|
|
521
|
+
curr = scanner.next();
|
|
522
|
+
break;
|
|
523
|
+
case 292:
|
|
524
|
+
viewPort.defaultLightingOn = curr.value;
|
|
525
|
+
curr = scanner.next();
|
|
526
|
+
break;
|
|
527
|
+
case 330:
|
|
528
|
+
viewPort.ownerHandle = curr.value;
|
|
529
|
+
curr = scanner.next();
|
|
530
|
+
break;
|
|
531
|
+
case 63: // These are all ambient color. Perhaps should be a gradient when multiple are set.
|
|
532
|
+
case 421:
|
|
533
|
+
case 431:
|
|
534
|
+
viewPort.ambientColor = curr.value;
|
|
535
|
+
curr = scanner.next();
|
|
536
|
+
break;
|
|
537
|
+
case 0:
|
|
538
|
+
// New ViewPort
|
|
539
|
+
if(curr.value === 'VPORT') {
|
|
540
|
+
log.debug('}');
|
|
541
|
+
viewPorts.push(viewPort);
|
|
542
|
+
log.debug('ViewPort {');
|
|
543
|
+
viewPort = {};
|
|
544
|
+
curr = scanner.next();
|
|
545
|
+
}
|
|
546
|
+
break;
|
|
547
|
+
default:
|
|
548
|
+
logUnhandledGroup(curr);
|
|
549
|
+
curr = scanner.next();
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
// Note: do not call scanner.next() here,
|
|
554
|
+
// parseTable() needs the current group
|
|
555
|
+
log.debug('}');
|
|
556
|
+
viewPorts.push(viewPort);
|
|
557
|
+
|
|
558
|
+
return viewPorts;
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
var parseLineTypes = function() {
|
|
562
|
+
var ltypes = {},
|
|
563
|
+
ltypeName,
|
|
564
|
+
ltype = {},
|
|
565
|
+
length;
|
|
566
|
+
|
|
567
|
+
log.debug('LType {');
|
|
568
|
+
curr = scanner.next();
|
|
569
|
+
while(!groupIs(0, 'ENDTAB')) {
|
|
570
|
+
|
|
571
|
+
switch(curr.code) {
|
|
572
|
+
case 2:
|
|
573
|
+
ltype.name = curr.value;
|
|
574
|
+
ltypeName = curr.value;
|
|
575
|
+
curr = scanner.next();
|
|
576
|
+
break;
|
|
577
|
+
case 3:
|
|
578
|
+
ltype.description = curr.value;
|
|
579
|
+
curr = scanner.next();
|
|
580
|
+
break;
|
|
581
|
+
case 73: // Number of elements for this line type (dots, dashes, spaces);
|
|
582
|
+
length = curr.value;
|
|
583
|
+
if(length > 0) ltype.pattern = [];
|
|
584
|
+
curr = scanner.next();
|
|
585
|
+
break;
|
|
586
|
+
case 40: // total pattern length
|
|
587
|
+
ltype.patternLength = curr.value;
|
|
588
|
+
curr = scanner.next();
|
|
589
|
+
break;
|
|
590
|
+
case 49:
|
|
591
|
+
ltype.pattern.push(curr.value);
|
|
592
|
+
curr = scanner.next();
|
|
593
|
+
break;
|
|
594
|
+
case 0:
|
|
595
|
+
log.debug('}');
|
|
596
|
+
if(length > 0 && length !== ltype.pattern.length) log.warn('lengths do not match on LTYPE pattern');
|
|
597
|
+
ltypes[ltypeName] = ltype;
|
|
598
|
+
ltype = {};
|
|
599
|
+
log.debug('LType {');
|
|
600
|
+
curr = scanner.next();
|
|
601
|
+
break;
|
|
602
|
+
default:
|
|
603
|
+
curr = scanner.next();
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
log.debug('}');
|
|
608
|
+
ltypes[ltypeName] = ltype;
|
|
609
|
+
return ltypes;
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
var parseLayers = function() {
|
|
613
|
+
var layers = {},
|
|
614
|
+
layerName,
|
|
615
|
+
layer = {};
|
|
616
|
+
|
|
617
|
+
log.debug('Layer {');
|
|
618
|
+
curr = scanner.next();
|
|
619
|
+
while(!groupIs(0, 'ENDTAB')) {
|
|
620
|
+
|
|
621
|
+
switch(curr.code) {
|
|
622
|
+
case 2: // layer name
|
|
623
|
+
layer.name = curr.value;
|
|
624
|
+
layerName = curr.value;
|
|
625
|
+
curr = scanner.next();
|
|
626
|
+
break;
|
|
627
|
+
case 62: // color, visibility
|
|
628
|
+
layer.visible = curr.value >= 0;
|
|
629
|
+
// TODO 0 and 256 are BYBLOCK and BYLAYER respectively. Need to handle these values for layers?.
|
|
630
|
+
layer.colorIndex = Math.abs(curr.value);
|
|
631
|
+
layer.color = getAcadColor(layer.colorIndex);
|
|
632
|
+
curr = scanner.next();
|
|
633
|
+
break;
|
|
634
|
+
case 70: // frozen layer
|
|
635
|
+
layer.frozen = ((curr.value & 1) !== 0 || (curr.value & 2) !== 0);
|
|
636
|
+
curr = scanner.next();
|
|
637
|
+
break;
|
|
638
|
+
case 420: // TrueColor Color
|
|
639
|
+
layer.color = curr.value;
|
|
640
|
+
curr = scanner.next();
|
|
641
|
+
break;
|
|
642
|
+
case 0:
|
|
643
|
+
// New Layer
|
|
644
|
+
if(curr.value === 'LAYER') {
|
|
645
|
+
log.debug('}');
|
|
646
|
+
layers[layerName] = layer;
|
|
647
|
+
log.debug('Layer {');
|
|
648
|
+
layer = {};
|
|
649
|
+
layerName = undefined;
|
|
650
|
+
curr = scanner.next();
|
|
651
|
+
}
|
|
652
|
+
break;
|
|
653
|
+
default:
|
|
654
|
+
logUnhandledGroup(curr);
|
|
655
|
+
curr = scanner.next();
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
// Note: do not call scanner.next() here,
|
|
660
|
+
// parseLayerTable() needs the current group
|
|
661
|
+
log.debug('}');
|
|
662
|
+
layers[layerName] = layer;
|
|
663
|
+
|
|
664
|
+
return layers;
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
var parseDimStyles = function () {
|
|
668
|
+
var dimStyles = {},
|
|
669
|
+
styleName,
|
|
670
|
+
style = {};
|
|
671
|
+
|
|
672
|
+
log.debug('DimStyle {');
|
|
673
|
+
curr = scanner.next();
|
|
674
|
+
while (!groupIs(0, 'ENDTAB')) {
|
|
675
|
+
|
|
676
|
+
if (dimStyleCodes.has(curr.code)) {
|
|
677
|
+
style[dimStyleCodes.get(curr.code)] = curr.value
|
|
678
|
+
curr = scanner.next();
|
|
679
|
+
} else {
|
|
680
|
+
switch (curr.code) {
|
|
681
|
+
case 2: // style name
|
|
682
|
+
style.name = curr.value;
|
|
683
|
+
styleName = curr.value;
|
|
684
|
+
curr = scanner.next();
|
|
685
|
+
break;
|
|
686
|
+
case 0:
|
|
687
|
+
// New style
|
|
688
|
+
if (curr.value === 'DIMSTYLE') {
|
|
689
|
+
log.debug('}');
|
|
690
|
+
dimStyles[styleName] = style;
|
|
691
|
+
log.debug('DimStyle {');
|
|
692
|
+
style = {};
|
|
693
|
+
styleName = undefined;
|
|
694
|
+
curr = scanner.next();
|
|
695
|
+
}
|
|
696
|
+
break;
|
|
697
|
+
default:
|
|
698
|
+
logUnhandledGroup(curr);
|
|
699
|
+
curr = scanner.next();
|
|
700
|
+
break;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
// Note: do not call scanner.next() here,
|
|
705
|
+
// parseLayerTable() needs the current group
|
|
706
|
+
log.debug('}');
|
|
707
|
+
dimStyles[styleName] = style;
|
|
708
|
+
|
|
709
|
+
return dimStyles;
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
var parseStyles = function () {
|
|
713
|
+
var styles = {};
|
|
714
|
+
var style = {};
|
|
715
|
+
var styleName;
|
|
716
|
+
|
|
717
|
+
log.debug('Style {');
|
|
718
|
+
curr = scanner.next();
|
|
719
|
+
while (!groupIs(0, END_OF_TABLE_VALUE)) {
|
|
720
|
+
switch (curr.code) {
|
|
721
|
+
case 100:
|
|
722
|
+
style.subClassMarker = curr.value;
|
|
723
|
+
curr = scanner.next();
|
|
724
|
+
break;
|
|
725
|
+
case 2:
|
|
726
|
+
style.styleName = curr.value;
|
|
727
|
+
styleName = curr.value;
|
|
728
|
+
curr = scanner.next();
|
|
729
|
+
break;
|
|
730
|
+
case 70:
|
|
731
|
+
style.standardFlag = curr.value;
|
|
732
|
+
curr = scanner.next();
|
|
733
|
+
break;
|
|
734
|
+
case 40:
|
|
735
|
+
style.fixedTextHeight = curr.value;
|
|
736
|
+
curr = scanner.next();
|
|
737
|
+
break;
|
|
738
|
+
case 41:
|
|
739
|
+
style.widthFactor = curr.value;
|
|
740
|
+
curr = scanner.next();
|
|
741
|
+
break;
|
|
742
|
+
case 50:
|
|
743
|
+
style.obliqueAngle = curr.value;
|
|
744
|
+
curr = scanner.next();
|
|
745
|
+
break;
|
|
746
|
+
case 71:
|
|
747
|
+
style.textGenerationFlag = curr.value;
|
|
748
|
+
curr = scanner.next();
|
|
749
|
+
break;
|
|
750
|
+
case 42:
|
|
751
|
+
style.lastHeight = curr.value;
|
|
752
|
+
curr = scanner.next();
|
|
753
|
+
break;
|
|
754
|
+
case 3:
|
|
755
|
+
style.font = curr.value;
|
|
756
|
+
curr = scanner.next();
|
|
757
|
+
break;
|
|
758
|
+
case 4:
|
|
759
|
+
style.bigFont = curr.value;
|
|
760
|
+
curr = scanner.next();
|
|
761
|
+
break;
|
|
762
|
+
case 1071:
|
|
763
|
+
style.extendedFont = curr.value;
|
|
764
|
+
curr = scanner.next();
|
|
765
|
+
break;
|
|
766
|
+
case 0:
|
|
767
|
+
if (curr.value === 'STYLE') {
|
|
768
|
+
log.debug('}');
|
|
769
|
+
styles[styleName] = style;
|
|
770
|
+
log.debug('Style {');
|
|
771
|
+
style = {};
|
|
772
|
+
styleName = undefined;
|
|
773
|
+
curr = scanner.next();
|
|
774
|
+
}
|
|
775
|
+
break;
|
|
776
|
+
default:
|
|
777
|
+
logUnhandledGroup(curr);
|
|
778
|
+
curr = scanner.next();
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
log.debug('}');
|
|
783
|
+
styles[styleName] = style;
|
|
784
|
+
return styles;
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
var tableDefinitions = {
|
|
789
|
+
VPORT: {
|
|
790
|
+
tableRecordsProperty: 'viewPorts',
|
|
791
|
+
tableName: 'viewPort',
|
|
792
|
+
dxfSymbolName: 'VPORT',
|
|
793
|
+
parseTableRecords: parseViewPortRecords
|
|
794
|
+
},
|
|
795
|
+
LTYPE: {
|
|
796
|
+
tableRecordsProperty: 'lineTypes',
|
|
797
|
+
tableName: 'lineType',
|
|
798
|
+
dxfSymbolName: 'LTYPE',
|
|
799
|
+
parseTableRecords: parseLineTypes
|
|
800
|
+
},
|
|
801
|
+
LAYER: {
|
|
802
|
+
tableRecordsProperty: 'layers',
|
|
803
|
+
tableName: 'layer',
|
|
804
|
+
dxfSymbolName: 'LAYER',
|
|
805
|
+
parseTableRecords: parseLayers
|
|
806
|
+
},
|
|
807
|
+
DIMSTYLE: {
|
|
808
|
+
tableRecordsProperty: 'dimStyles',
|
|
809
|
+
tableName: 'dimstyle',
|
|
810
|
+
dxfSymbolName: 'DIMSTYLE',
|
|
811
|
+
parseTableRecords: parseDimStyles
|
|
812
|
+
},
|
|
813
|
+
STYLE: {
|
|
814
|
+
tableRecordsProperty: 'styles',
|
|
815
|
+
tableName: 'style',
|
|
816
|
+
dxfSymbolName: 'STYLE',
|
|
817
|
+
parseTableRecords: parseStyles,
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* Is called after the parser first reads the 0:ENTITIES group. The scanner
|
|
823
|
+
* should be on the start of the first entity already.
|
|
824
|
+
* @return {Array} the resulting entities
|
|
825
|
+
*/
|
|
826
|
+
var parseEntities = function(forBlock) {
|
|
827
|
+
var entities = [];
|
|
828
|
+
|
|
829
|
+
var endingOnValue = forBlock ? 'ENDBLK' : 'ENDSEC';
|
|
830
|
+
|
|
831
|
+
if (!forBlock) {
|
|
832
|
+
curr = scanner.next();
|
|
833
|
+
}
|
|
834
|
+
while(true) {
|
|
835
|
+
|
|
836
|
+
if(curr.code === 0) {
|
|
837
|
+
if(curr.value === endingOnValue) {
|
|
838
|
+
break;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
var entity;
|
|
842
|
+
var handler = self._entityHandlers[curr.value];
|
|
843
|
+
if(handler != null) {
|
|
844
|
+
log.debug(curr.value + ' {');
|
|
845
|
+
entity = handler.parseEntity(scanner, curr);
|
|
846
|
+
curr = scanner.lastReadGroup;
|
|
847
|
+
log.debug('}');
|
|
848
|
+
} else {
|
|
849
|
+
log.warn('Unhandled entity ' + curr.value);
|
|
850
|
+
curr = scanner.next();
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
ensureHandle(entity);
|
|
854
|
+
entities.push(entity);
|
|
855
|
+
} else {
|
|
856
|
+
// ignored lines from unsupported entity
|
|
857
|
+
curr = scanner.next();
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
if (endingOnValue == 'ENDSEC') {
|
|
861
|
+
curr = scanner.next(); // swallow up ENDSEC, but not ENDBLK
|
|
862
|
+
}
|
|
863
|
+
return entities;
|
|
864
|
+
};
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* Is called after the parser first reads the 0:ENTITIES group. The scanner
|
|
869
|
+
* should be on the start of the first entity already.
|
|
870
|
+
* @return {Array} the resulting entities
|
|
871
|
+
*/
|
|
872
|
+
var parseObjects = function() {
|
|
873
|
+
var objects = [];
|
|
874
|
+
var endingOnValue = 'ENDSEC';
|
|
875
|
+
curr = scanner.next();
|
|
876
|
+
while(true) {
|
|
877
|
+
|
|
878
|
+
if(curr.code === 0) {
|
|
879
|
+
if(curr.value === endingOnValue) {
|
|
880
|
+
break;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
var object;
|
|
884
|
+
var handler = self._objectHandlers[curr.value];
|
|
885
|
+
if(handler != null) {
|
|
886
|
+
log.debug(curr.value + ' {');
|
|
887
|
+
object = handler.parseObject(scanner, curr);
|
|
888
|
+
curr = scanner.lastReadGroup;
|
|
889
|
+
log.debug('}');
|
|
890
|
+
} else {
|
|
891
|
+
log.warn('Unhandled entity ' + curr.value);
|
|
892
|
+
curr = scanner.next();
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
895
|
+
objects.push(object);
|
|
896
|
+
} else {
|
|
897
|
+
// ignored lines from unsupported entity
|
|
898
|
+
curr = scanner.next();
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
curr = scanner.next();
|
|
902
|
+
return objects;
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* Parses a 2D or 3D point, returning it as an object with x, y, and
|
|
907
|
+
* (sometimes) z property if it is 3D. It is assumed the current group
|
|
908
|
+
* is x of the point being read in, and scanner.next() will return the
|
|
909
|
+
* y. The parser will determine if there is a z point automatically.
|
|
910
|
+
* @return {Object} The 2D or 3D point as an object with x, y[, z]
|
|
911
|
+
*/
|
|
912
|
+
var parsePoint = function() {
|
|
913
|
+
var point = {},
|
|
914
|
+
code = curr.code;
|
|
915
|
+
|
|
916
|
+
point.x = curr.value;
|
|
917
|
+
|
|
918
|
+
code += 10;
|
|
919
|
+
curr = scanner.next();
|
|
920
|
+
if(curr.code != code)
|
|
921
|
+
throw new Error('Expected code for point value to be ' + code +
|
|
922
|
+
' but got ' + curr.code + '.');
|
|
923
|
+
point.y = curr.value;
|
|
924
|
+
|
|
925
|
+
code += 10;
|
|
926
|
+
curr = scanner.next();
|
|
927
|
+
if(curr.code != code)
|
|
928
|
+
{
|
|
929
|
+
scanner.rewind();
|
|
930
|
+
return point;
|
|
931
|
+
}
|
|
932
|
+
point.z = curr.value;
|
|
933
|
+
|
|
934
|
+
return point;
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
var ensureHandle = function(entity) {
|
|
938
|
+
if (!entity) {
|
|
939
|
+
throw new TypeError('entity cannot be undefined or null');
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
if (!entity.handle) {
|
|
943
|
+
entity.handle = lastHandle++;
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
|
|
947
|
+
parseAll();
|
|
948
|
+
return dxf;
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
function logUnhandledGroup(curr) {
|
|
952
|
+
log.debug('unhandled group ' + debugCode(curr));
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
function debugCode(curr) {
|
|
957
|
+
return curr.code + ':' + curr.value;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Returns the truecolor value of the given AutoCad color index value
|
|
962
|
+
* @return {Number} truecolor value as a number
|
|
963
|
+
*/
|
|
964
|
+
function getAcadColor(index) {
|
|
965
|
+
return AUTO_CAD_COLOR_INDEX[index];
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
const BLOCK_ANONYMOUS_FLAG = 1;
|
|
969
|
+
const BLOCK_NON_CONSTANT_FLAG = 2;
|
|
970
|
+
const BLOCK_XREF_FLAG = 4;
|
|
971
|
+
const BLOCK_XREF_OVERLAY_FLAG = 8;
|
|
972
|
+
const BLOCK_EXTERNALLY_DEPENDENT_FLAG = 16;
|
|
973
|
+
const BLOCK_RESOLVED_OR_DEPENDENT_FLAG = 32;
|
|
974
|
+
const BLOCK_REFERENCED_XREF = 64;
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
/* Notes */
|
|
978
|
+
// Code 6 of an entity indicates inheritance of properties (eg. color).
|
|
979
|
+
// BYBLOCK means inherits from block
|
|
980
|
+
// BYLAYER (default) mean inherits from layer
|