@mlightcad/cad-simple-viewer 1.0.0
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/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/index.js +2422 -0
- package/dist/index.umd.cjs +9 -0
- package/lib/app/AcApContext.d.ts +15 -0
- package/lib/app/AcApContext.d.ts.map +1 -0
- package/lib/app/AcApContext.js +56 -0
- package/lib/app/AcApContext.js.map +1 -0
- package/lib/app/AcApDocCreator.d.ts +17 -0
- package/lib/app/AcApDocCreator.d.ts.map +1 -0
- package/lib/app/AcApDocCreator.js +140 -0
- package/lib/app/AcApDocCreator.js.map +1 -0
- package/lib/app/AcApDocManager.d.ts +60 -0
- package/lib/app/AcApDocManager.d.ts.map +1 -0
- package/lib/app/AcApDocManager.js +275 -0
- package/lib/app/AcApDocManager.js.map +1 -0
- package/lib/app/AcApDocument.d.ts +27 -0
- package/lib/app/AcApDocument.d.ts.map +1 -0
- package/lib/app/AcApDocument.js +165 -0
- package/lib/app/AcApDocument.js.map +1 -0
- package/lib/app/AcApFontLoader.d.ts +20 -0
- package/lib/app/AcApFontLoader.d.ts.map +1 -0
- package/lib/app/AcApFontLoader.js +135 -0
- package/lib/app/AcApFontLoader.js.map +1 -0
- package/lib/app/AcApSettingManager.d.ts +44 -0
- package/lib/app/AcApSettingManager.d.ts.map +1 -0
- package/lib/app/AcApSettingManager.js +122 -0
- package/lib/app/AcApSettingManager.js.map +1 -0
- package/lib/app/index.d.ts +5 -0
- package/lib/app/index.d.ts.map +1 -0
- package/lib/app/index.js +5 -0
- package/lib/app/index.js.map +1 -0
- package/lib/command/AcApConvertToSvgCmd.d.ts +6 -0
- package/lib/command/AcApConvertToSvgCmd.d.ts.map +1 -0
- package/lib/command/AcApConvertToSvgCmd.js +30 -0
- package/lib/command/AcApConvertToSvgCmd.js.map +1 -0
- package/lib/command/AcApOpenCmd.d.ts +6 -0
- package/lib/command/AcApOpenCmd.d.ts.map +1 -0
- package/lib/command/AcApOpenCmd.js +29 -0
- package/lib/command/AcApOpenCmd.js.map +1 -0
- package/lib/command/AcApPanCmd.d.ts +6 -0
- package/lib/command/AcApPanCmd.d.ts.map +1 -0
- package/lib/command/AcApPanCmd.js +30 -0
- package/lib/command/AcApPanCmd.js.map +1 -0
- package/lib/command/AcApQNewCmd.d.ts +6 -0
- package/lib/command/AcApQNewCmd.d.ts.map +1 -0
- package/lib/command/AcApQNewCmd.js +30 -0
- package/lib/command/AcApQNewCmd.js.map +1 -0
- package/lib/command/AcApSelectCmd.d.ts +6 -0
- package/lib/command/AcApSelectCmd.d.ts.map +1 -0
- package/lib/command/AcApSelectCmd.js +30 -0
- package/lib/command/AcApSelectCmd.js.map +1 -0
- package/lib/command/AcApSvgConvertor.d.ts +5 -0
- package/lib/command/AcApSvgConvertor.d.ts.map +1 -0
- package/lib/command/AcApSvgConvertor.js +55 -0
- package/lib/command/AcApSvgConvertor.js.map +1 -0
- package/lib/command/AcApZoomCmd.d.ts +6 -0
- package/lib/command/AcApZoomCmd.d.ts.map +1 -0
- package/lib/command/AcApZoomCmd.js +28 -0
- package/lib/command/AcApZoomCmd.js.map +1 -0
- package/lib/command/AcApZoomToBoxCmd.d.ts +11 -0
- package/lib/command/AcApZoomToBoxCmd.d.ts.map +1 -0
- package/lib/command/AcApZoomToBoxCmd.js +101 -0
- package/lib/command/AcApZoomToBoxCmd.js.map +1 -0
- package/lib/command/index.d.ts +10 -0
- package/lib/command/index.d.ts.map +1 -0
- package/lib/command/index.js +10 -0
- package/lib/command/index.js.map +1 -0
- package/lib/editor/command/AcEdCommand.d.ts +42 -0
- package/lib/editor/command/AcEdCommand.d.ts.map +1 -0
- package/lib/editor/command/AcEdCommand.js +60 -0
- package/lib/editor/command/AcEdCommand.js.map +1 -0
- package/lib/editor/command/AcEdCommandIterator.d.ts +36 -0
- package/lib/editor/command/AcEdCommandIterator.d.ts.map +1 -0
- package/lib/editor/command/AcEdCommandIterator.js +65 -0
- package/lib/editor/command/AcEdCommandIterator.js.map +1 -0
- package/lib/editor/command/AcEdCommandStack.d.ts +66 -0
- package/lib/editor/command/AcEdCommandStack.d.ts.map +1 -0
- package/lib/editor/command/AcEdCommandStack.js +192 -0
- package/lib/editor/command/AcEdCommandStack.js.map +1 -0
- package/lib/editor/command/index.d.ts +3 -0
- package/lib/editor/command/index.d.ts.map +1 -0
- package/lib/editor/command/index.js +3 -0
- package/lib/editor/command/index.js.map +1 -0
- package/lib/editor/global/AcEdGlobalFunc.d.ts +8 -0
- package/lib/editor/global/AcEdGlobalFunc.d.ts.map +1 -0
- package/lib/editor/global/AcEdGlobalFunc.js +14 -0
- package/lib/editor/global/AcEdGlobalFunc.js.map +1 -0
- package/lib/editor/global/AcEdMessage.d.ts +5 -0
- package/lib/editor/global/AcEdMessage.d.ts.map +1 -0
- package/lib/editor/global/AcEdMessage.js +6 -0
- package/lib/editor/global/AcEdMessage.js.map +1 -0
- package/lib/editor/global/eventBus.d.ts +34 -0
- package/lib/editor/global/eventBus.d.ts.map +1 -0
- package/lib/editor/global/eventBus.js +3 -0
- package/lib/editor/global/eventBus.js.map +1 -0
- package/lib/editor/global/index.d.ts +3 -0
- package/lib/editor/global/index.d.ts.map +1 -0
- package/lib/editor/global/index.js +3 -0
- package/lib/editor/global/index.js.map +1 -0
- package/lib/editor/index.d.ts +5 -0
- package/lib/editor/index.d.ts.map +1 -0
- package/lib/editor/index.js +5 -0
- package/lib/editor/index.js.map +1 -0
- package/lib/editor/input/AcEdBaseInput.d.ts +25 -0
- package/lib/editor/input/AcEdBaseInput.d.ts.map +1 -0
- package/lib/editor/input/AcEdBaseInput.js +105 -0
- package/lib/editor/input/AcEdBaseInput.js.map +1 -0
- package/lib/editor/input/AcEdBoxSelector.d.ts +27 -0
- package/lib/editor/input/AcEdBoxSelector.d.ts.map +1 -0
- package/lib/editor/input/AcEdBoxSelector.js +140 -0
- package/lib/editor/input/AcEdBoxSelector.js.map +1 -0
- package/lib/editor/input/AcEdCursorManager.d.ts +43 -0
- package/lib/editor/input/AcEdCursorManager.d.ts.map +1 -0
- package/lib/editor/input/AcEdCursorManager.js +71 -0
- package/lib/editor/input/AcEdCursorManager.js.map +1 -0
- package/lib/editor/input/AcEdInputPoint.d.ts +14 -0
- package/lib/editor/input/AcEdInputPoint.d.ts.map +1 -0
- package/lib/editor/input/AcEdInputPoint.js +41 -0
- package/lib/editor/input/AcEdInputPoint.js.map +1 -0
- package/lib/editor/input/AcEdJig.d.ts +14 -0
- package/lib/editor/input/AcEdJig.d.ts.map +1 -0
- package/lib/editor/input/AcEdJig.js +92 -0
- package/lib/editor/input/AcEdJig.js.map +1 -0
- package/lib/editor/input/AcEdJigLoop.d.ts +14 -0
- package/lib/editor/input/AcEdJigLoop.d.ts.map +1 -0
- package/lib/editor/input/AcEdJigLoop.js +43 -0
- package/lib/editor/input/AcEdJigLoop.js.map +1 -0
- package/lib/editor/input/AcEdSelectionSet.d.ts +26 -0
- package/lib/editor/input/AcEdSelectionSet.d.ts.map +1 -0
- package/lib/editor/input/AcEdSelectionSet.js +63 -0
- package/lib/editor/input/AcEdSelectionSet.js.map +1 -0
- package/lib/editor/input/AcEditor.d.ts +27 -0
- package/lib/editor/input/AcEditor.d.ts.map +1 -0
- package/lib/editor/input/AcEditor.js +103 -0
- package/lib/editor/input/AcEditor.js.map +1 -0
- package/lib/editor/input/index.d.ts +5 -0
- package/lib/editor/input/index.d.ts.map +1 -0
- package/lib/editor/input/index.js +5 -0
- package/lib/editor/input/index.js.map +1 -0
- package/lib/editor/view/AcEdBaseView.d.ts +261 -0
- package/lib/editor/view/AcEdBaseView.d.ts.map +1 -0
- package/lib/editor/view/AcEdBaseView.js +260 -0
- package/lib/editor/view/AcEdBaseView.js.map +1 -0
- package/lib/editor/view/index.d.ts +2 -0
- package/lib/editor/view/index.d.ts.map +1 -0
- package/lib/editor/view/index.js +2 -0
- package/lib/editor/view/index.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -0
- package/lib/util/AcTrGeometryUtil.d.ts +18 -0
- package/lib/util/AcTrGeometryUtil.d.ts.map +1 -0
- package/lib/util/AcTrGeometryUtil.js +33 -0
- package/lib/util/AcTrGeometryUtil.js.map +1 -0
- package/lib/util/index.d.ts +2 -0
- package/lib/util/index.d.ts.map +1 -0
- package/lib/util/index.js +2 -0
- package/lib/util/index.js.map +1 -0
- package/lib/view/AcTrLayer.d.ts +97 -0
- package/lib/view/AcTrLayer.d.ts.map +1 -0
- package/lib/view/AcTrLayer.js +170 -0
- package/lib/view/AcTrLayer.js.map +1 -0
- package/lib/view/AcTrLayout.d.ts +114 -0
- package/lib/view/AcTrLayout.d.ts.map +1 -0
- package/lib/view/AcTrLayout.js +344 -0
- package/lib/view/AcTrLayout.js.map +1 -0
- package/lib/view/AcTrLayoutView.d.ts +57 -0
- package/lib/view/AcTrLayoutView.d.ts.map +1 -0
- package/lib/view/AcTrLayoutView.js +151 -0
- package/lib/view/AcTrLayoutView.js.map +1 -0
- package/lib/view/AcTrLayoutViewManager.d.ts +43 -0
- package/lib/view/AcTrLayoutViewManager.d.ts.map +1 -0
- package/lib/view/AcTrLayoutViewManager.js +74 -0
- package/lib/view/AcTrLayoutViewManager.js.map +1 -0
- package/lib/view/AcTrScene.d.ts +115 -0
- package/lib/view/AcTrScene.d.ts.map +1 -0
- package/lib/view/AcTrScene.js +319 -0
- package/lib/view/AcTrScene.js.map +1 -0
- package/lib/view/AcTrView2d.d.ts +160 -0
- package/lib/view/AcTrView2d.d.ts.map +1 -0
- package/lib/view/AcTrView2d.js +473 -0
- package/lib/view/AcTrView2d.js.map +1 -0
- package/lib/view/index.d.ts +2 -0
- package/lib/view/index.d.ts.map +1 -0
- package/lib/view/index.js +2 -0
- package/lib/view/index.js.map +1 -0
- package/package.json +55 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2422 @@
|
|
|
1
|
+
import { AcCmEventManager as m, AcGePoint2d as u, AcGeBox2d as N, AcCmColor as k, AcGeBox3d as $, AcDbDatabase as J, AcDbFileType as G, acdbHostApplicationServices as W, AcDbViewport as K, AcDbRasterImage as Z, AcDbRay as Q, AcDbXline as tt, AcDbHatch as j, AcGePolyline2d as et, AcDbLine as st, AcDbTextStyleTableRecord as it, AcDbMText as nt, AcGiMTextAttachmentPoint as ot, AcGePoint3d as rt, AcGeLoop2d as at, AcGeCircArc2d as ct, AcGeMathUtil as T, AcGeLine2d as ht, AcDbArc as lt, AcGeLine3d as M } from "@mlightcad/data-model";
|
|
2
|
+
import { AcSvgRenderer as dt } from "@mlightcad/svg-renderer";
|
|
3
|
+
import { find as ut, findIndex as mt, defaults as _t } from "lodash-es";
|
|
4
|
+
import { AcTrBaseView as wt, AcTrBatchedGroup as pt, AcTrRenderer as ft, AcTrViewportView as yt } from "@mlightcad/three-renderer";
|
|
5
|
+
import * as f from "three";
|
|
6
|
+
import vt from "three/examples/jsm/libs/stats.module";
|
|
7
|
+
import { AxesGizmo as gt, ObjectPosition as xt } from "@mlightcad/three-viewcube";
|
|
8
|
+
class bt {
|
|
9
|
+
/**
|
|
10
|
+
* Construct one context to bind one drawing database with its viewer
|
|
11
|
+
* @param view Input the view used to show the specified drawing
|
|
12
|
+
* @param doc Input the document associated with the drawing database
|
|
13
|
+
*/
|
|
14
|
+
constructor(t, e) {
|
|
15
|
+
this._view = t, this._doc = e, e.database.events.entityAppended.addEventListener((s) => {
|
|
16
|
+
this.view.addEntity(s.entity);
|
|
17
|
+
}), e.database.events.entityModified.addEventListener((s) => {
|
|
18
|
+
this.view.updateEntity(s.entity);
|
|
19
|
+
}), e.database.events.layerModified.addEventListener((s) => {
|
|
20
|
+
this._view.setLayerVisibility(s.layer.name, !s.layer.isOff);
|
|
21
|
+
}), e.database.events.headerSysVarChanged.addEventListener((s) => {
|
|
22
|
+
s.name == "pdmode" && this._view.rerenderPoints(s.database.pdmode);
|
|
23
|
+
}), t.selectionSet.events.selectionAdded.addEventListener((s) => {
|
|
24
|
+
t.highlight(s.ids);
|
|
25
|
+
}), t.selectionSet.events.selectionRemoved.addEventListener((s) => {
|
|
26
|
+
t.unhighlight(s.ids);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
get view() {
|
|
30
|
+
return this._view;
|
|
31
|
+
}
|
|
32
|
+
get doc() {
|
|
33
|
+
return this._doc;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
class x {
|
|
37
|
+
constructor() {
|
|
38
|
+
this.events = {
|
|
39
|
+
commandWillStart: new m(),
|
|
40
|
+
commandEnded: new m()
|
|
41
|
+
}, this._globalName = "", this._localName = "";
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The global or untranslated name associated with the command.
|
|
45
|
+
*/
|
|
46
|
+
get globalName() {
|
|
47
|
+
return this._globalName;
|
|
48
|
+
}
|
|
49
|
+
set globalName(t) {
|
|
50
|
+
this._globalName = t;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The local or translated name associated with the command.
|
|
54
|
+
*/
|
|
55
|
+
get localName() {
|
|
56
|
+
return this._localName;
|
|
57
|
+
}
|
|
58
|
+
set localName(t) {
|
|
59
|
+
this._localName = t;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Trigger this command. The children class should not override this method to keep event notification
|
|
63
|
+
* work correctly.
|
|
64
|
+
* @param context Input current context to execute this command.
|
|
65
|
+
*/
|
|
66
|
+
tirgger(t) {
|
|
67
|
+
this.events.commandWillStart.dispatch({ command: this }), this.execute(t), this.events.commandEnded.dispatch({ command: this });
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Execute this command. The children class should override this method to add business logic of this command.
|
|
71
|
+
* @param _context Input current context to execute this command.
|
|
72
|
+
*/
|
|
73
|
+
execute(t) {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
class St {
|
|
77
|
+
constructor(t) {
|
|
78
|
+
this._index = 0, this._commands = [], t.forEach((e) => {
|
|
79
|
+
const s = e.groupName;
|
|
80
|
+
e.commandsByGlobalName.forEach((n) => {
|
|
81
|
+
this._commands.push({
|
|
82
|
+
command: n,
|
|
83
|
+
commandGroup: s
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
[Symbol.iterator]() {
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Return command object the iterator currently points to. If the iterator is at the beginning, then the
|
|
93
|
+
* first object is returned. If the iterator has already gone past the last entry, then null is returned.
|
|
94
|
+
*/
|
|
95
|
+
get command() {
|
|
96
|
+
return this._index < this._commands.length ? this._commands[this._index].command : null;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Return the name of the command object the iterator currently points to. If the iterator is at the
|
|
100
|
+
* beginning, then the first object is returned. If the iterator has already gone past the last entry,
|
|
101
|
+
* then null is returned.
|
|
102
|
+
*/
|
|
103
|
+
get commandGroup() {
|
|
104
|
+
return this._index < this._commands.length ? this._commands[this._index].commandGroup : null;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Increment the iterator to the next entry.
|
|
108
|
+
* @returns Return the next entry
|
|
109
|
+
*/
|
|
110
|
+
next() {
|
|
111
|
+
for (; this._index < this._commands.length; ) {
|
|
112
|
+
const t = this._commands[this._index];
|
|
113
|
+
return this._index += 1, { value: t, done: !1 };
|
|
114
|
+
}
|
|
115
|
+
return { value: null, done: !0 };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const p = class p {
|
|
119
|
+
constructor() {
|
|
120
|
+
this._commandsByGroup = [], this._systemCommandGroup = {
|
|
121
|
+
groupName: p.SYSTEMT_COMMAND_GROUP_NAME,
|
|
122
|
+
commandsByGlobalName: /* @__PURE__ */ new Map(),
|
|
123
|
+
commandsByLocalName: /* @__PURE__ */ new Map()
|
|
124
|
+
}, this._defaultCommandGroup = {
|
|
125
|
+
groupName: p.DEFAUT_COMMAND_GROUP_NAME,
|
|
126
|
+
commandsByGlobalName: /* @__PURE__ */ new Map(),
|
|
127
|
+
commandsByLocalName: /* @__PURE__ */ new Map()
|
|
128
|
+
}, this._commandsByGroup.push(this._systemCommandGroup), this._commandsByGroup.push(this._defaultCommandGroup);
|
|
129
|
+
}
|
|
130
|
+
static get instance() {
|
|
131
|
+
return p._instance || (p._instance = new p()), p._instance;
|
|
132
|
+
}
|
|
133
|
+
addCommand(t, e, s, n) {
|
|
134
|
+
if (!e)
|
|
135
|
+
throw new Error(
|
|
136
|
+
"[AcEdCommandStack] The global name of the command is required!"
|
|
137
|
+
);
|
|
138
|
+
s || (s = e);
|
|
139
|
+
let o = this._defaultCommandGroup;
|
|
140
|
+
if (t) {
|
|
141
|
+
const r = this._commandsByGroup.find(
|
|
142
|
+
(a) => a.groupName == t
|
|
143
|
+
);
|
|
144
|
+
r ? o = r : o = {
|
|
145
|
+
groupName: t,
|
|
146
|
+
commandsByGlobalName: /* @__PURE__ */ new Map(),
|
|
147
|
+
commandsByLocalName: /* @__PURE__ */ new Map()
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (o.commandsByGlobalName.has(e))
|
|
151
|
+
throw new Error(
|
|
152
|
+
`[AcEdCommandStack] The command with global name '${e}' already exists!`
|
|
153
|
+
);
|
|
154
|
+
if (o.commandsByLocalName.has(s))
|
|
155
|
+
throw new Error(
|
|
156
|
+
`[AcEdCommandStack] The command with local name '${s}' already exists!`
|
|
157
|
+
);
|
|
158
|
+
o.commandsByGlobalName.set(e, n), o.commandsByLocalName.set(s, n), n.globalName = e, n.localName = s;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Return an iterator that can be used to traverse all of command objects in this command stack
|
|
162
|
+
* (that is, the iterator iterates through all commands in all groups).
|
|
163
|
+
* @returns Return an iterator that can be used to traverse all of command objects in this command
|
|
164
|
+
* stack.
|
|
165
|
+
*/
|
|
166
|
+
iterator() {
|
|
167
|
+
return new St(this._commandsByGroup);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Search through all of the global and untranslated names in all of the command groups in the command
|
|
171
|
+
* stack starting at the top of the stack trying to find a match with cmdName. If a match is found, the
|
|
172
|
+
* matched AcEdCommand object is returned. Otherwise undefined is returned to indicate that the command
|
|
173
|
+
* could not be found. If more than one command of the same name is present in the command stack (that
|
|
174
|
+
* is, in separate command groups), then the first one found is used.
|
|
175
|
+
* @param cmdName Input the command name to search for
|
|
176
|
+
* @returns Return the matched AcEdCommand object if a match is found. Otherwise, return undefined.
|
|
177
|
+
*/
|
|
178
|
+
lookupGlobalCmd(t) {
|
|
179
|
+
let e;
|
|
180
|
+
for (const s of this._commandsByGroup)
|
|
181
|
+
if (e = s.commandsByGlobalName.get(t), e) break;
|
|
182
|
+
return e;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Search through all of the local and translated names in all of the command groups in the command stack
|
|
186
|
+
* starting at the top of the stack trying to find a match with cmdName. If a match is found, the matched
|
|
187
|
+
* AcEdCommand object is returned. Otherwise undefined is returned to indicate that the command could not
|
|
188
|
+
* be found. If more than one command of the same name is present in the command stack (that is, in
|
|
189
|
+
* separate command groups), then the first one found is used.
|
|
190
|
+
* @param cmdName Input the command name to search for
|
|
191
|
+
* @returns Return the matched AcEdCommand object if a match is found. Otherwise, return undefined.
|
|
192
|
+
*/
|
|
193
|
+
lookupLocalCmd(t) {
|
|
194
|
+
let e;
|
|
195
|
+
for (const s of this._commandsByGroup)
|
|
196
|
+
if (e = s.commandsByLocalName.get(t), e) break;
|
|
197
|
+
return e;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Remove the command with the global and untranslated name `cmdGlobalName` from the `cmdGroupName`
|
|
201
|
+
* command group. Return true if successful. Return false if no command with the global and untranslated
|
|
202
|
+
* name `cmdGlobalName` is found in the `cmdGroupName` command group.
|
|
203
|
+
* @param cmdGroupName Input the name of the command group containing the command to be removed
|
|
204
|
+
* @param cmdGlobalName Input the command name which is to be removed from cmdGroupName
|
|
205
|
+
* @returns Return true if successful. Return false if no command with the global and untranslated
|
|
206
|
+
* name `cmdGlobalName` is found in the `cmdGroupName` command group.
|
|
207
|
+
*/
|
|
208
|
+
removeCmd(t, e) {
|
|
209
|
+
for (const s of this._commandsByGroup)
|
|
210
|
+
if (s.groupName == t)
|
|
211
|
+
return s.commandsByGlobalName.delete(e);
|
|
212
|
+
return !1;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Remove the command group with the name `GroupName` from the command stack and delete the command group
|
|
216
|
+
* dictionary object and all the AcEdCommand objects stored within it.
|
|
217
|
+
* @param groupName Input the name of the command group to be removed from the command stack.
|
|
218
|
+
* @returns Return true if successful. Return false if no command group is found with the name `GroupName`.
|
|
219
|
+
*/
|
|
220
|
+
removeGroup(t) {
|
|
221
|
+
let e = -1;
|
|
222
|
+
return this._commandsByGroup.some((s, n) => (e = n, s.groupName == t)), e >= 0 ? (this._commandsByGroup.splice(e, 1), !0) : !1;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
p.SYSTEMT_COMMAND_GROUP_NAME = "ACAD", p.DEFAUT_COMMAND_GROUP_NAME = "USER";
|
|
226
|
+
let _ = p;
|
|
227
|
+
function Bt(i) {
|
|
228
|
+
return { all: i = i || /* @__PURE__ */ new Map(), on: function(t, e) {
|
|
229
|
+
var s = i.get(t);
|
|
230
|
+
s ? s.push(e) : i.set(t, [e]);
|
|
231
|
+
}, off: function(t, e) {
|
|
232
|
+
var s = i.get(t);
|
|
233
|
+
s && (e ? s.splice(s.indexOf(e) >>> 0, 1) : i.set(t, []));
|
|
234
|
+
}, emit: function(t, e) {
|
|
235
|
+
var s = i.get(t);
|
|
236
|
+
s && s.slice().map(function(n) {
|
|
237
|
+
n(e);
|
|
238
|
+
}), (s = i.get("*")) && s.slice().map(function(n) {
|
|
239
|
+
n(t, e);
|
|
240
|
+
});
|
|
241
|
+
} };
|
|
242
|
+
}
|
|
243
|
+
const v = Bt();
|
|
244
|
+
function ve(i) {
|
|
245
|
+
v.emit("message", {
|
|
246
|
+
message: i,
|
|
247
|
+
type: "warning"
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
var C = /* @__PURE__ */ ((i) => (i[i.NoSpecialCursor = -1] = "NoSpecialCursor", i[i.Crosshair = 0] = "Crosshair", i[i.RectCursor = 1] = "RectCursor", i[i.RubberBand = 2] = "RubberBand", i[i.NotRotated = 3] = "NotRotated", i[i.TargetBox = 4] = "TargetBox", i[i.RotatedCrosshair = 5] = "RotatedCrosshair", i[i.CrosshairNoRotate = 6] = "CrosshairNoRotate", i[i.Invisible = 7] = "Invisible", i[i.EntitySelect = 8] = "EntitySelect", i[i.Parallelogram = 9] = "Parallelogram", i[i.EntitySelectNoPersp = 10] = "EntitySelectNoPersp", i[i.PkfirstOrGrips = 11] = "PkfirstOrGrips", i[i.CrosshairDashed = 12] = "CrosshairDashed", i[i.Grab = 13] = "Grab", i))(C || {});
|
|
251
|
+
class Mt {
|
|
252
|
+
constructor() {
|
|
253
|
+
this._cursorMap = /* @__PURE__ */ new Map(), this._cursorMap.set(
|
|
254
|
+
0,
|
|
255
|
+
this.createRectCrossIcon(10, 10)
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
setCursor(t, e) {
|
|
259
|
+
if (t <= -1)
|
|
260
|
+
e.style.cursor = "default";
|
|
261
|
+
else if (t == 13)
|
|
262
|
+
e.style.cursor = "grab";
|
|
263
|
+
else {
|
|
264
|
+
const s = this._cursorMap.get(t);
|
|
265
|
+
s && (e.style.cursor = s);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Encode SVG string to one cursor defined using url() in CSS
|
|
270
|
+
* @param svgString Input svg string
|
|
271
|
+
* @param xOffset Input x offset for cursor hotspot
|
|
272
|
+
* @param yOffset Input y offset for cursor hotspot
|
|
273
|
+
* @returns
|
|
274
|
+
*/
|
|
275
|
+
encodeSvg(t, e = 0, s = 0) {
|
|
276
|
+
return `url('data:image/svg+xml;base64,${btoa(t)}') ${e} ${s}, auto`;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Create one svg icon with one rectangle plus two cross lines
|
|
280
|
+
* @param rectSize Input the width and height of rectangle
|
|
281
|
+
* @param crossLineLength Input the length of one cross line
|
|
282
|
+
* @param lineColor Input line color
|
|
283
|
+
* @returns Return svg string of the icon
|
|
284
|
+
*/
|
|
285
|
+
createRectCrossIcon(t, e, s = "white") {
|
|
286
|
+
const n = t / 2, o = t + 2 * e, r = `
|
|
287
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${o}" viewBox="0 0 ${o} ${o}">
|
|
288
|
+
<rect x="${e}" y="${e}" width="${t}" height="${t}" fill="none" stroke="${s}" />
|
|
289
|
+
<line x1="${n + e}" y1="0" x2="${n + e}" y2="${e}" stroke="${s}" />
|
|
290
|
+
<line x1="${t + e}" y1="${n + e}" x2="${t + 2 * e}" y2="${n + e}" stroke="${s}" />
|
|
291
|
+
<line x1="${n + e}" y1="${t + e}" x2="${n + e}" y2="${t + 2 * e}" stroke="${s}" />
|
|
292
|
+
<line x1="0" y1="${n + e}" x2="${e}" y2="${n + e}" stroke="${s}" />
|
|
293
|
+
</svg>
|
|
294
|
+
`;
|
|
295
|
+
return this.encodeSvg(r, n + e, n + e);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
class V {
|
|
299
|
+
constructor(t) {
|
|
300
|
+
this.active = !1, this.isResolvedOrRejected = !1, this.onKeyDown = (e) => {
|
|
301
|
+
e.code === "Escape" && this.reject("Canceled by user!");
|
|
302
|
+
}, this.view = t;
|
|
303
|
+
}
|
|
304
|
+
get isActive() {
|
|
305
|
+
return this.active;
|
|
306
|
+
}
|
|
307
|
+
activate() {
|
|
308
|
+
this.isActive && console.warn("Something wrong here!"), this.active = !0, this.view.canvas.addEventListener("keydown", this.onKeyDown);
|
|
309
|
+
}
|
|
310
|
+
deactivate() {
|
|
311
|
+
this.active = !1, this.view.canvas.removeEventListener("keydown", this.onKeyDown);
|
|
312
|
+
}
|
|
313
|
+
resolve(t) {
|
|
314
|
+
this.deactivate(), this._resolve && !this.isResolvedOrRejected && (this._resolve(t), this.isResolvedOrRejected = !0);
|
|
315
|
+
}
|
|
316
|
+
reject(t) {
|
|
317
|
+
this.deactivate(), this._reject && !this.isResolvedOrRejected && (this._reject(t), this.isResolvedOrRejected = !0);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Start inputting
|
|
321
|
+
*/
|
|
322
|
+
async start() {
|
|
323
|
+
return this.isResolvedOrRejected = !1, new Promise((t, e) => {
|
|
324
|
+
this._resolve = t, this._reject = e, this.activate();
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
class Et extends V {
|
|
329
|
+
constructor(t) {
|
|
330
|
+
super(t), this.events = {
|
|
331
|
+
update: new m()
|
|
332
|
+
}, this.onMouseMove = (e) => {
|
|
333
|
+
this.curPos.set(e.clientX, e.clientY), this.events.update.dispatch();
|
|
334
|
+
}, this.curPos = new u();
|
|
335
|
+
}
|
|
336
|
+
activate() {
|
|
337
|
+
super.activate(), this.view.canvas.addEventListener("mousemove", this.onMouseMove);
|
|
338
|
+
}
|
|
339
|
+
deactivate() {
|
|
340
|
+
super.deactivate(), this.view.canvas.removeEventListener("mousemove", this.onMouseMove);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
class Lt {
|
|
344
|
+
constructor(t) {
|
|
345
|
+
this.onUpdate = () => {
|
|
346
|
+
this.update();
|
|
347
|
+
}, this._view = t, this._jigLoop = new Et(t), this._jigLoop.events.update.addEventListener(this.onUpdate);
|
|
348
|
+
}
|
|
349
|
+
get view() {
|
|
350
|
+
return this._view;
|
|
351
|
+
}
|
|
352
|
+
resolve(t) {
|
|
353
|
+
this._jigLoop.events.update.removeEventListener(this.onUpdate), this._jigLoop.resolve(t);
|
|
354
|
+
}
|
|
355
|
+
reject(t) {
|
|
356
|
+
this._jigLoop.events.update.removeEventListener(this.onUpdate), this._jigLoop.reject(t);
|
|
357
|
+
}
|
|
358
|
+
async drag() {
|
|
359
|
+
const t = this._jigLoop.start(), e = this.sampler();
|
|
360
|
+
await Promise.allSettled([t, e]);
|
|
361
|
+
}
|
|
362
|
+
async sampler() {
|
|
363
|
+
}
|
|
364
|
+
update() {
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const Dt = 16777215, It = "1px";
|
|
368
|
+
class Ct extends V {
|
|
369
|
+
constructor(t) {
|
|
370
|
+
super(t), this.mouseDown = !1, this.mouseMove = !1, this.mouseDownPositionX = -1, this.mouseDownPositionY = -1, this.mousedown = (e) => {
|
|
371
|
+
if (e.button === 0) {
|
|
372
|
+
this.mouseDown = !0;
|
|
373
|
+
const s = new u(e.x, e.y);
|
|
374
|
+
this.mouseDownPositionX = s.x, this.mouseDownPositionY = s.y;
|
|
375
|
+
}
|
|
376
|
+
}, this.mousemove = (e) => {
|
|
377
|
+
if (!this.mouseDown)
|
|
378
|
+
return;
|
|
379
|
+
const s = new u(e.x, e.y);
|
|
380
|
+
if (this.mouseDownPositionX >= 0 && this.mouseDownPositionY >= 0 && (Math.abs(s.x - this.mouseDownPositionX) >= 5 || Math.abs(s.y - this.mouseDownPositionY) >= 5)) {
|
|
381
|
+
this.mouseMove = !0;
|
|
382
|
+
const o = new u(
|
|
383
|
+
Math.min(this.mouseDownPositionX, s.x),
|
|
384
|
+
Math.min(this.mouseDownPositionY, s.y)
|
|
385
|
+
), r = new u(
|
|
386
|
+
Math.max(this.mouseDownPositionX, s.x),
|
|
387
|
+
Math.max(this.mouseDownPositionY, s.y)
|
|
388
|
+
);
|
|
389
|
+
this.drawRect(o, r);
|
|
390
|
+
}
|
|
391
|
+
}, this.mouseup = (e) => {
|
|
392
|
+
if (this.mouseDown && this.mouseMove) {
|
|
393
|
+
const s = new u(e.x, e.y), n = new u(
|
|
394
|
+
Math.min(this.mouseDownPositionX, s.x),
|
|
395
|
+
Math.min(this.mouseDownPositionY, s.y)
|
|
396
|
+
), o = new u(
|
|
397
|
+
Math.max(this.mouseDownPositionX, s.x),
|
|
398
|
+
Math.max(this.mouseDownPositionY, s.y)
|
|
399
|
+
), r = new N(n, o);
|
|
400
|
+
this.resolve(this.toWcs(r));
|
|
401
|
+
}
|
|
402
|
+
this.mouseDown = !1, this.mouseMove = !1, this.mouseDownPositionX = -1, this.mouseDownPositionY = -1;
|
|
403
|
+
}, this.container = t.canvas, this.color = Dt;
|
|
404
|
+
}
|
|
405
|
+
activate() {
|
|
406
|
+
super.activate(), this.active = !0, this.container.addEventListener("pointerdown", this.mousedown), this.container.addEventListener("pointermove", this.mousemove), this.container.addEventListener("pointerup", this.mouseup);
|
|
407
|
+
}
|
|
408
|
+
deactivate() {
|
|
409
|
+
super.deactivate(), this.container.removeEventListener("pointerdown", this.mousedown), this.container.removeEventListener("pointermove", this.mousemove), this.container.removeEventListener("pointerup", this.mouseup), this.setRectDomVisible(!1);
|
|
410
|
+
}
|
|
411
|
+
reject(t) {
|
|
412
|
+
var e;
|
|
413
|
+
super.reject(t), (e = this.boxDom) == null || e.remove(), this.boxDom = void 0;
|
|
414
|
+
}
|
|
415
|
+
drawRect(t, e) {
|
|
416
|
+
if (!this.boxDom) {
|
|
417
|
+
const o = new k();
|
|
418
|
+
o.color = this.color, this.boxDom = document.createElement("div"), this.boxDom.style.cssText = `position: absolute;border: ${It} solid ${o.cssColor};`, document.body.appendChild(this.boxDom);
|
|
419
|
+
}
|
|
420
|
+
this.setRectDomVisible(!0), t.x <= 0 && (t.x = 0), t.y <= 0 && (t.y = 0), e.x >= this.container.clientWidth - 2 && (e.x = this.container.clientWidth - 2), e.y >= this.container.clientHeight - 2 && (e.y = this.container.clientHeight - 2), this.boxDom.style.left = `${t.x}px`, this.boxDom.style.top = `${t.y}px`;
|
|
421
|
+
const s = Math.abs(e.x - t.x), n = Math.abs(e.y - t.y);
|
|
422
|
+
this.boxDom.style.width = `${s}px`, this.boxDom.style.height = `${n}px`;
|
|
423
|
+
}
|
|
424
|
+
setRectDomVisible(t) {
|
|
425
|
+
this.boxDom && (this.boxDom.style.display = t ? "inline-block" : "none");
|
|
426
|
+
}
|
|
427
|
+
toWcs(t) {
|
|
428
|
+
const e = new N(), s = new u(t.min.x, t.min.y), n = new u(t.max.x, t.max.y);
|
|
429
|
+
return e.expandByPoint(this.view.cwcs2Wcs(s)), e.expandByPoint(this.view.cwcs2Wcs(n)), e;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
class Tt extends V {
|
|
433
|
+
constructor(t) {
|
|
434
|
+
super(t), this.onClick = (e) => {
|
|
435
|
+
this.resolve(this.view.cwcs2Wcs({ x: e.clientX, y: e.clientY }));
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
activate() {
|
|
439
|
+
super.activate(), this.view.canvas.addEventListener("click", this.onClick);
|
|
440
|
+
}
|
|
441
|
+
deactivate() {
|
|
442
|
+
super.deactivate(), this.view.canvas.removeEventListener("click", this.onClick);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
class At {
|
|
446
|
+
constructor(t) {
|
|
447
|
+
this._view = t, this._cursorManager = new Mt();
|
|
448
|
+
}
|
|
449
|
+
get currentCursor() {
|
|
450
|
+
return this._currentCursor;
|
|
451
|
+
}
|
|
452
|
+
restoreCursor() {
|
|
453
|
+
this._previousCursor != null && this.setCursor(this._previousCursor);
|
|
454
|
+
}
|
|
455
|
+
setCursor(t) {
|
|
456
|
+
this._cursorManager.setCursor(t, this._view.canvas), this._previousCursor = this._currentCursor, this._currentCursor = t;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Get user input for a point.
|
|
460
|
+
*/
|
|
461
|
+
async getPoint() {
|
|
462
|
+
return await new Tt(this._view).start();
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Get the selection set obtained.
|
|
466
|
+
*/
|
|
467
|
+
async getSelection() {
|
|
468
|
+
return await new Ct(this._view).start();
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
class Ot {
|
|
472
|
+
constructor(t = []) {
|
|
473
|
+
this.events = {
|
|
474
|
+
selectionAdded: new m(),
|
|
475
|
+
selectionRemoved: new m()
|
|
476
|
+
}, this._ids = new Set(t);
|
|
477
|
+
}
|
|
478
|
+
get ids() {
|
|
479
|
+
return Array.from(this._ids);
|
|
480
|
+
}
|
|
481
|
+
get count() {
|
|
482
|
+
return this._ids.size;
|
|
483
|
+
}
|
|
484
|
+
add(t) {
|
|
485
|
+
Array.isArray(t) ? (t.forEach((e) => this._ids.add(e)), this.events.selectionAdded.dispatch({ ids: t })) : (this._ids.add(t), this.events.selectionAdded.dispatch({ ids: [t] }));
|
|
486
|
+
}
|
|
487
|
+
delete(t) {
|
|
488
|
+
Array.isArray(t) ? (t.forEach((e) => this._ids.delete(e)), this.events.selectionRemoved.dispatch({ ids: t })) : (this._ids.delete(t), this.events.selectionRemoved.dispatch({ ids: [t] }));
|
|
489
|
+
}
|
|
490
|
+
has(t) {
|
|
491
|
+
return this._ids.has(t);
|
|
492
|
+
}
|
|
493
|
+
clear() {
|
|
494
|
+
if (this._ids.size > 0) {
|
|
495
|
+
const t = Array.from(this._ids);
|
|
496
|
+
this._ids.clear(), this.events.selectionRemoved.dispatch({ ids: t });
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
var y = /* @__PURE__ */ ((i) => (i[i.SELECTION = 0] = "SELECTION", i[i.PAN = 1] = "PAN", i))(y || {});
|
|
501
|
+
class Nt {
|
|
502
|
+
constructor(t) {
|
|
503
|
+
this.events = {
|
|
504
|
+
mouseMove: new m(),
|
|
505
|
+
viewResize: new m(),
|
|
506
|
+
hover: new m(),
|
|
507
|
+
unhover: new m()
|
|
508
|
+
}, this._canvas = t;
|
|
509
|
+
const e = t.getBoundingClientRect();
|
|
510
|
+
this._bbox = new $(), this._width = e.width, this._height = e.height, this._curPos = new u(), this._curScreenPos = new u(), this._selectionSet = new Ot(), this._editor = new At(this), this._canvas.addEventListener("mousemove", (s) => this.onMouseMove(s)), this._canvas.addEventListener("mousedown", (s) => {
|
|
511
|
+
s.button === 1 && this._editor.setCursor(C.Grab);
|
|
512
|
+
}), this._canvas.addEventListener("mouseup", (s) => {
|
|
513
|
+
s.button === 1 && this._editor.restoreCursor();
|
|
514
|
+
}), window.addEventListener("resize", this.onWindowResize.bind(this)), this._selectionBoxSize = 4, this._hoverTimer = null, this._pauseTimer = null, this._hoveredObjectId = null;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* The input manager
|
|
518
|
+
*/
|
|
519
|
+
get editor() {
|
|
520
|
+
return this._editor;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* The size of selection box in pixel unit
|
|
524
|
+
*/
|
|
525
|
+
get selectionBoxSize() {
|
|
526
|
+
return this._selectionBoxSize;
|
|
527
|
+
}
|
|
528
|
+
set selectionBoxSize(t) {
|
|
529
|
+
this._selectionBoxSize = t;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Set cursor type of this view
|
|
533
|
+
* @param cursorType Input cursor type
|
|
534
|
+
*/
|
|
535
|
+
setCursor(t) {
|
|
536
|
+
this._editor.setCursor(t);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Set callback function used to calculate size of canvas when window resized
|
|
540
|
+
* @param value Input callback function
|
|
541
|
+
*/
|
|
542
|
+
setCalculateSizeCallback(t) {
|
|
543
|
+
this._calculateSizeCallback = t;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Width of canvas (not width of window) in pixel
|
|
547
|
+
*/
|
|
548
|
+
get width() {
|
|
549
|
+
return this._width;
|
|
550
|
+
}
|
|
551
|
+
set width(t) {
|
|
552
|
+
this._width = t;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Height of canvas (not height of window) in pixel
|
|
556
|
+
*/
|
|
557
|
+
get height() {
|
|
558
|
+
return this._height;
|
|
559
|
+
}
|
|
560
|
+
set height(t) {
|
|
561
|
+
this._height = t;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* The bounding box to include all entities in this viewer
|
|
565
|
+
*/
|
|
566
|
+
get bbox() {
|
|
567
|
+
return this._bbox;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* The canvas HTML element used by this view
|
|
571
|
+
*/
|
|
572
|
+
get canvas() {
|
|
573
|
+
return this._canvas;
|
|
574
|
+
}
|
|
575
|
+
get aspect() {
|
|
576
|
+
return this._width / this._height;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Postion of current mouse in world coordinate system
|
|
580
|
+
*/
|
|
581
|
+
get curPos() {
|
|
582
|
+
return this._curPos;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Postion of current mouse in screen coordinate system
|
|
586
|
+
*/
|
|
587
|
+
get curScreenPos() {
|
|
588
|
+
return this._curScreenPos;
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* The selection set in current view.
|
|
592
|
+
*/
|
|
593
|
+
get selectionSet() {
|
|
594
|
+
return this._selectionSet;
|
|
595
|
+
}
|
|
596
|
+
onWindowResize() {
|
|
597
|
+
if (this._calculateSizeCallback) {
|
|
598
|
+
const { width: t, height: e } = this._calculateSizeCallback();
|
|
599
|
+
this._width = t, this._height = e;
|
|
600
|
+
} else
|
|
601
|
+
this._width = this._canvas.clientWidth, this._height = this._canvas.clientHeight;
|
|
602
|
+
this.events.viewResize.dispatch({
|
|
603
|
+
width: this._width,
|
|
604
|
+
height: this._height
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Mouse move event handler.
|
|
609
|
+
* @param event Input mouse event argument
|
|
610
|
+
*/
|
|
611
|
+
onMouseMove(t) {
|
|
612
|
+
this._curScreenPos = new u(t.clientX, t.clientY);
|
|
613
|
+
const e = this.cwcs2Wcs(this._curScreenPos);
|
|
614
|
+
this._curPos.copy(e), this.events.mouseMove.dispatch({ x: e.x, y: e.y }), this.mode == 0 && this.startHoverTimer(e.x, e.y);
|
|
615
|
+
}
|
|
616
|
+
setHoveredObjectId(t) {
|
|
617
|
+
this._hoveredObjectId && (this.events.unhover.dispatch({
|
|
618
|
+
id: this._hoveredObjectId,
|
|
619
|
+
x: this.curScreenPos.x,
|
|
620
|
+
y: this.curScreenPos.y
|
|
621
|
+
}), this.onUnhover(this._hoveredObjectId)), this._hoveredObjectId = t, t && (this.startPauseTimer(t), this.onHover(t));
|
|
622
|
+
}
|
|
623
|
+
hoverAt(t, e) {
|
|
624
|
+
const s = this.pick({ x: t, y: e });
|
|
625
|
+
s.length > 0 ? this.setHoveredObjectId(s[0]) : (this.setHoveredObjectId(null), this.clearPauseTimer());
|
|
626
|
+
}
|
|
627
|
+
clearHoverTimer() {
|
|
628
|
+
this._hoverTimer && clearTimeout(this._hoverTimer);
|
|
629
|
+
}
|
|
630
|
+
clearPauseTimer() {
|
|
631
|
+
this._pauseTimer && clearTimeout(this._pauseTimer);
|
|
632
|
+
}
|
|
633
|
+
startHoverTimer(t, e) {
|
|
634
|
+
this.clearHoverTimer(), this._hoverTimer = setTimeout(() => {
|
|
635
|
+
this.hoverAt(t, e);
|
|
636
|
+
}, 50);
|
|
637
|
+
}
|
|
638
|
+
startPauseTimer(t) {
|
|
639
|
+
this._pauseTimer = setTimeout(() => {
|
|
640
|
+
this.events.hover.dispatch({
|
|
641
|
+
id: t,
|
|
642
|
+
x: this.curScreenPos.x,
|
|
643
|
+
y: this.curScreenPos.y
|
|
644
|
+
});
|
|
645
|
+
}, 500);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
class Pt {
|
|
649
|
+
constructor() {
|
|
650
|
+
this._fileName = "", this._docTitle = "", this._isReadOnly = !0, this._database = new J(), this.docTitle = "Untitled";
|
|
651
|
+
}
|
|
652
|
+
async openUri(t, e) {
|
|
653
|
+
this._uri = t, this._isReadOnly = e && e.readOnly || !1, this._fileName = this.getFileNameFromUri(t);
|
|
654
|
+
let s = !0;
|
|
655
|
+
try {
|
|
656
|
+
await this._database.openUri(t, e), this.docTitle = this._fileName;
|
|
657
|
+
} catch {
|
|
658
|
+
s = !1, v.emit("failed-to-open-file", { fileName: t });
|
|
659
|
+
}
|
|
660
|
+
return s;
|
|
661
|
+
}
|
|
662
|
+
async openDocument(t, e, s) {
|
|
663
|
+
var o;
|
|
664
|
+
let n = !0;
|
|
665
|
+
this._fileName = t;
|
|
666
|
+
try {
|
|
667
|
+
const r = (o = t.split(".").pop()) == null ? void 0 : o.toLocaleLowerCase();
|
|
668
|
+
await this._database.read(
|
|
669
|
+
e,
|
|
670
|
+
s,
|
|
671
|
+
r == "dwg" ? G.DWG : G.DXF
|
|
672
|
+
), this.docTitle = this._fileName;
|
|
673
|
+
} catch (r) {
|
|
674
|
+
n = !1, v.emit("failed-to-open-file", { fileName: t }), console.error(r);
|
|
675
|
+
}
|
|
676
|
+
return n;
|
|
677
|
+
}
|
|
678
|
+
get uri() {
|
|
679
|
+
return this._uri;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* The database object being used by this document instance.
|
|
683
|
+
*/
|
|
684
|
+
get database() {
|
|
685
|
+
return this._database;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* The window title of the document
|
|
689
|
+
*/
|
|
690
|
+
get docTitle() {
|
|
691
|
+
return this._docTitle;
|
|
692
|
+
}
|
|
693
|
+
set docTitle(t) {
|
|
694
|
+
this._docTitle = t, typeof document < "u" && (document.title = t);
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Return true if the document is read only; otherwise, returns false.
|
|
698
|
+
*/
|
|
699
|
+
get isReadOnly() {
|
|
700
|
+
return this._isReadOnly;
|
|
701
|
+
}
|
|
702
|
+
getFileNameFromUri(t) {
|
|
703
|
+
try {
|
|
704
|
+
const s = new URL(t).pathname.split("/");
|
|
705
|
+
return s[s.length - 1] || "";
|
|
706
|
+
} catch (e) {
|
|
707
|
+
return console.error("Invalid URI:", e), "";
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
class Rt {
|
|
712
|
+
convert() {
|
|
713
|
+
const t = w.instance.curDocument.database.tables.blockTable.modelSpace.newIterator(), e = new dt();
|
|
714
|
+
for (const s of t)
|
|
715
|
+
s.draw(e);
|
|
716
|
+
this.createFileAndDownloadIt(e.export());
|
|
717
|
+
}
|
|
718
|
+
createFileAndDownloadIt(t) {
|
|
719
|
+
const e = new Blob([t], {
|
|
720
|
+
type: "image/svg+xml;charset=utf-8"
|
|
721
|
+
}), s = URL.createObjectURL(e), n = document.createElement("a");
|
|
722
|
+
n.href = s, n.download = "example.svg", document.body.appendChild(n), n.click();
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
class zt extends x {
|
|
726
|
+
execute(t) {
|
|
727
|
+
new Rt().convert();
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
class Vt extends x {
|
|
731
|
+
execute(t) {
|
|
732
|
+
v.emit("open-file", {});
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
class Gt extends x {
|
|
736
|
+
execute(t) {
|
|
737
|
+
w.instance.openUrl("https://cdn.jsdelivr.net/gh/mlight-lee/cad-data/templates/" + "acadiso.dxf");
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
class jt extends x {
|
|
741
|
+
execute(t) {
|
|
742
|
+
t.view.mode = y.SELECTION, t.view.setCursor(C.Crosshair);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
class Yt extends x {
|
|
746
|
+
execute(t) {
|
|
747
|
+
t.view.zoomToFit();
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
class Xt extends Lt {
|
|
751
|
+
constructor(t) {
|
|
752
|
+
super(t);
|
|
753
|
+
}
|
|
754
|
+
async sampler() {
|
|
755
|
+
await w.instance.editor.getSelection().then((t) => this.view.zoomTo(t, 1));
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
class Ft extends x {
|
|
759
|
+
async execute(t) {
|
|
760
|
+
await new Xt(t.view).drag();
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
class Ut extends x {
|
|
764
|
+
execute(t) {
|
|
765
|
+
t.view.mode = y.PAN, t.view.setCursor(C.Grab);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
const kt = (i) => new $(i.min, i.max), $t = (i) => new f.Box3(
|
|
769
|
+
i.min,
|
|
770
|
+
i.max
|
|
771
|
+
), Wt = (i) => new N(i.min, i.max), Ht = (i) => new f.Box2(
|
|
772
|
+
i.min,
|
|
773
|
+
i.max
|
|
774
|
+
), qt = (i) => new N(i.min, i.max), Jt = (i) => {
|
|
775
|
+
const t = new f.Box3();
|
|
776
|
+
return t.min.set(i.min.x, i.min.y, 0), t.max.set(i.max.x, i.max.y, 0), t;
|
|
777
|
+
}, Kt = {
|
|
778
|
+
threeBo2dToGeBox2d: Wt,
|
|
779
|
+
goBox2dToThreeBox2d: Ht,
|
|
780
|
+
threeBox3dToGeBox3d: kt,
|
|
781
|
+
goBox3dToThreeBox3d: $t,
|
|
782
|
+
threeBox3dToGeBox2d: qt,
|
|
783
|
+
goBox2dToThreeBox3d: Jt
|
|
784
|
+
};
|
|
785
|
+
class Zt extends wt {
|
|
786
|
+
/**
|
|
787
|
+
* Construct one instance of this class
|
|
788
|
+
* @param layoutBtrId Input the id of the block table record associated the layout
|
|
789
|
+
* @param renderer Input renderer
|
|
790
|
+
* @param width Input width of this view
|
|
791
|
+
* @param height Input height of this view
|
|
792
|
+
*/
|
|
793
|
+
constructor(t, e, s, n) {
|
|
794
|
+
super(t, s, n), this._layoutBtrId = e, this._mode = y.SELECTION, this._axesGizmo = this.createAxesGizmo(), this._viewportViews = /* @__PURE__ */ new Map();
|
|
795
|
+
}
|
|
796
|
+
get layoutBtrId() {
|
|
797
|
+
return this._layoutBtrId;
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* The view mode of the current layout view
|
|
801
|
+
*/
|
|
802
|
+
get mode() {
|
|
803
|
+
return this._mode;
|
|
804
|
+
}
|
|
805
|
+
set mode(t) {
|
|
806
|
+
t == y.SELECTION ? this._cameraControls.mouseButtons = {
|
|
807
|
+
MIDDLE: f.MOUSE.PAN
|
|
808
|
+
} : t == y.PAN && (this._cameraControls.mouseButtons = {
|
|
809
|
+
LEFT: f.MOUSE.PAN
|
|
810
|
+
}), this._cameraControls.update(), this._mode = t;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* The number of viewports in this layout view
|
|
814
|
+
*/
|
|
815
|
+
get viewportCount() {
|
|
816
|
+
return this._viewportViews.size;
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Add one viewport view instance to this layout view
|
|
820
|
+
* @param viewportView Input one viewport instance
|
|
821
|
+
*/
|
|
822
|
+
addViewport(t) {
|
|
823
|
+
this._viewportViews.set(t.viewport.id, t);
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Remove the specified viewport view by its id from this layout view
|
|
827
|
+
* @param id Input the id of one viewport instance
|
|
828
|
+
*/
|
|
829
|
+
removeViewport(t) {
|
|
830
|
+
this._viewportViews.delete(t);
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Resize this layout view
|
|
834
|
+
* @param width Input new width of the layout view
|
|
835
|
+
* @param height Input new height of the layout view
|
|
836
|
+
*/
|
|
837
|
+
resize(t, e) {
|
|
838
|
+
this._height = e, this._width = t, this.updateCameraFrustum(), this._viewportViews.forEach((s) => {
|
|
839
|
+
s.update();
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
render(t) {
|
|
843
|
+
var s;
|
|
844
|
+
this._renderer.clear(), this._renderer.render(t.internalScene, this._camera);
|
|
845
|
+
const e = t.modelSpaceLayout;
|
|
846
|
+
e && this.drawViewports(e.internalObject), (s = this._axesGizmo) == null || s.update();
|
|
847
|
+
}
|
|
848
|
+
createAxesGizmo() {
|
|
849
|
+
return new gt(
|
|
850
|
+
this._camera.internalCamera,
|
|
851
|
+
this._renderer.internalRenderer,
|
|
852
|
+
{
|
|
853
|
+
hasZAxis: !1,
|
|
854
|
+
pos: xt.LEFT_BOTTOM
|
|
855
|
+
}
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Draw viewports
|
|
860
|
+
* @param scene Input the scene to draw
|
|
861
|
+
*/
|
|
862
|
+
drawViewports(t) {
|
|
863
|
+
if (this._viewportViews.size > 0) {
|
|
864
|
+
const e = this._renderer.autoClear;
|
|
865
|
+
this._renderer.autoClear = !1;
|
|
866
|
+
const s = new f.Vector4();
|
|
867
|
+
this._renderer.getViewport(s), this._renderer.clearDepth();
|
|
868
|
+
const n = t.visible;
|
|
869
|
+
t.visible = !0, this._viewportViews.forEach((o) => {
|
|
870
|
+
o.render(t);
|
|
871
|
+
}), t.visible = n, this._renderer.setViewport(
|
|
872
|
+
s.x,
|
|
873
|
+
s.y,
|
|
874
|
+
s.z,
|
|
875
|
+
s.w
|
|
876
|
+
), this._renderer.autoClear = e;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
class Qt {
|
|
881
|
+
constructor() {
|
|
882
|
+
this._activeLayoutBtrId = "", this._layoutViews = /* @__PURE__ */ new Map();
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* The block table record id associated with the active layout
|
|
886
|
+
*/
|
|
887
|
+
get activeLayoutBtrId() {
|
|
888
|
+
return this._activeLayoutBtrId;
|
|
889
|
+
}
|
|
890
|
+
set activeLayoutBtrId(t) {
|
|
891
|
+
this._activeLayoutBtrId = t, this._layoutViews.forEach((e) => {
|
|
892
|
+
e.enabled = e.layoutBtrId == t;
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* The active layout view.
|
|
897
|
+
*/
|
|
898
|
+
get activeLayoutView() {
|
|
899
|
+
return this._layoutViews.get(this._activeLayoutBtrId);
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Return true if the layout view manager contains one layout view associated with the sepcified block
|
|
903
|
+
* table record id. Otherwise it returns false.
|
|
904
|
+
* @param name Input the block table record id associated with the layout view
|
|
905
|
+
* @returns Return true if the layout view manager contains one layout view associated with the sepcified
|
|
906
|
+
* block table record id. Otherwise it returns false.
|
|
907
|
+
*/
|
|
908
|
+
has(t) {
|
|
909
|
+
return this._layoutViews.has(t);
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* Get the layout view by the block table record id associated with the layout
|
|
913
|
+
* @param layoutBtrId Input the id of the block table record associated the layout
|
|
914
|
+
* @returns Return the layout view by the block table record id associated with the layout
|
|
915
|
+
*/
|
|
916
|
+
getAt(t) {
|
|
917
|
+
return this._layoutViews.get(t);
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Resize all of layout views managed by layout view manager
|
|
921
|
+
* @param width Input new width of the layout view
|
|
922
|
+
* @param height Input new height of the layout view
|
|
923
|
+
*/
|
|
924
|
+
resize(t, e) {
|
|
925
|
+
this._layoutViews.forEach((s) => {
|
|
926
|
+
s.resize(t, e);
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
add(t) {
|
|
930
|
+
this._layoutViews.set(t.layoutBtrId, t);
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Render the specified scene in the current layout view
|
|
934
|
+
* @param scene Input the scene to render
|
|
935
|
+
*/
|
|
936
|
+
render(t) {
|
|
937
|
+
var e;
|
|
938
|
+
(e = this.activeLayoutView) == null || e.render(t);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
function H(i, t, e = 0, s = i.length - 1, n = te) {
|
|
942
|
+
for (; s > e; ) {
|
|
943
|
+
if (s - e > 600) {
|
|
944
|
+
const c = s - e + 1, l = t - e + 1, h = Math.log(c), d = 0.5 * Math.exp(2 * h / 3), g = 0.5 * Math.sqrt(h * d * (c - d) / c) * (l - c / 2 < 0 ? -1 : 1), P = Math.max(e, Math.floor(t - l * d / c + g)), q = Math.min(s, Math.floor(t + (c - l) * d / c + g));
|
|
945
|
+
H(i, t, P, q, n);
|
|
946
|
+
}
|
|
947
|
+
const o = i[t];
|
|
948
|
+
let r = e, a = s;
|
|
949
|
+
for (E(i, e, t), n(i[s], o) > 0 && E(i, e, s); r < a; ) {
|
|
950
|
+
for (E(i, r, a), r++, a--; n(i[r], o) < 0; ) r++;
|
|
951
|
+
for (; n(i[a], o) > 0; ) a--;
|
|
952
|
+
}
|
|
953
|
+
n(i[e], o) === 0 ? E(i, e, a) : (a++, E(i, a, s)), a <= t && (e = a + 1), t <= a && (s = a - 1);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
function E(i, t, e) {
|
|
957
|
+
const s = i[t];
|
|
958
|
+
i[t] = i[e], i[e] = s;
|
|
959
|
+
}
|
|
960
|
+
function te(i, t) {
|
|
961
|
+
return i < t ? -1 : i > t ? 1 : 0;
|
|
962
|
+
}
|
|
963
|
+
class ee {
|
|
964
|
+
constructor(t = 9) {
|
|
965
|
+
this._maxEntries = Math.max(4, t), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
|
|
966
|
+
}
|
|
967
|
+
all() {
|
|
968
|
+
return this._all(this.data, []);
|
|
969
|
+
}
|
|
970
|
+
search(t) {
|
|
971
|
+
let e = this.data;
|
|
972
|
+
const s = [];
|
|
973
|
+
if (!O(t, e)) return s;
|
|
974
|
+
const n = this.toBBox, o = [];
|
|
975
|
+
for (; e; ) {
|
|
976
|
+
for (let r = 0; r < e.children.length; r++) {
|
|
977
|
+
const a = e.children[r], c = e.leaf ? n(a) : a;
|
|
978
|
+
O(t, c) && (e.leaf ? s.push(a) : z(t, c) ? this._all(a, s) : o.push(a));
|
|
979
|
+
}
|
|
980
|
+
e = o.pop();
|
|
981
|
+
}
|
|
982
|
+
return s;
|
|
983
|
+
}
|
|
984
|
+
collides(t) {
|
|
985
|
+
let e = this.data;
|
|
986
|
+
if (!O(t, e)) return !1;
|
|
987
|
+
const s = [];
|
|
988
|
+
for (; e; ) {
|
|
989
|
+
for (let n = 0; n < e.children.length; n++) {
|
|
990
|
+
const o = e.children[n], r = e.leaf ? this.toBBox(o) : o;
|
|
991
|
+
if (O(t, r)) {
|
|
992
|
+
if (e.leaf || z(t, r)) return !0;
|
|
993
|
+
s.push(o);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
e = s.pop();
|
|
997
|
+
}
|
|
998
|
+
return !1;
|
|
999
|
+
}
|
|
1000
|
+
load(t) {
|
|
1001
|
+
if (!(t && t.length)) return this;
|
|
1002
|
+
if (t.length < this._minEntries) {
|
|
1003
|
+
for (let s = 0; s < t.length; s++)
|
|
1004
|
+
this.insert(t[s]);
|
|
1005
|
+
return this;
|
|
1006
|
+
}
|
|
1007
|
+
let e = this._build(t.slice(), 0, t.length - 1, 0);
|
|
1008
|
+
if (!this.data.children.length)
|
|
1009
|
+
this.data = e;
|
|
1010
|
+
else if (this.data.height === e.height)
|
|
1011
|
+
this._splitRoot(this.data, e);
|
|
1012
|
+
else {
|
|
1013
|
+
if (this.data.height < e.height) {
|
|
1014
|
+
const s = this.data;
|
|
1015
|
+
this.data = e, e = s;
|
|
1016
|
+
}
|
|
1017
|
+
this._insert(e, this.data.height - e.height - 1, !0);
|
|
1018
|
+
}
|
|
1019
|
+
return this;
|
|
1020
|
+
}
|
|
1021
|
+
insert(t) {
|
|
1022
|
+
return t && this._insert(t, this.data.height - 1), this;
|
|
1023
|
+
}
|
|
1024
|
+
clear() {
|
|
1025
|
+
return this.data = S([]), this;
|
|
1026
|
+
}
|
|
1027
|
+
remove(t, e) {
|
|
1028
|
+
if (!t) return this;
|
|
1029
|
+
let s = this.data;
|
|
1030
|
+
const n = this.toBBox(t), o = [], r = [];
|
|
1031
|
+
let a, c, l;
|
|
1032
|
+
for (; s || o.length; ) {
|
|
1033
|
+
if (s || (s = o.pop(), c = o[o.length - 1], a = r.pop(), l = !0), s.leaf) {
|
|
1034
|
+
const h = se(t, s.children, e);
|
|
1035
|
+
if (h !== -1)
|
|
1036
|
+
return s.children.splice(h, 1), o.push(s), this._condense(o), this;
|
|
1037
|
+
}
|
|
1038
|
+
!l && !s.leaf && z(s, n) ? (o.push(s), r.push(a), a = 0, c = s, s = s.children[0]) : c ? (a++, s = c.children[a], l = !1) : s = null;
|
|
1039
|
+
}
|
|
1040
|
+
return this;
|
|
1041
|
+
}
|
|
1042
|
+
toBBox(t) {
|
|
1043
|
+
return t;
|
|
1044
|
+
}
|
|
1045
|
+
compareMinX(t, e) {
|
|
1046
|
+
return t.minX - e.minX;
|
|
1047
|
+
}
|
|
1048
|
+
compareMinY(t, e) {
|
|
1049
|
+
return t.minY - e.minY;
|
|
1050
|
+
}
|
|
1051
|
+
toJSON() {
|
|
1052
|
+
return this.data;
|
|
1053
|
+
}
|
|
1054
|
+
fromJSON(t) {
|
|
1055
|
+
return this.data = t, this;
|
|
1056
|
+
}
|
|
1057
|
+
_all(t, e) {
|
|
1058
|
+
const s = [];
|
|
1059
|
+
for (; t; )
|
|
1060
|
+
t.leaf ? e.push(...t.children) : s.push(...t.children), t = s.pop();
|
|
1061
|
+
return e;
|
|
1062
|
+
}
|
|
1063
|
+
_build(t, e, s, n) {
|
|
1064
|
+
const o = s - e + 1;
|
|
1065
|
+
let r = this._maxEntries, a;
|
|
1066
|
+
if (o <= r)
|
|
1067
|
+
return a = S(t.slice(e, s + 1)), b(a, this.toBBox), a;
|
|
1068
|
+
n || (n = Math.ceil(Math.log(o) / Math.log(r)), r = Math.ceil(o / Math.pow(r, n - 1))), a = S([]), a.leaf = !1, a.height = n;
|
|
1069
|
+
const c = Math.ceil(o / r), l = c * Math.ceil(Math.sqrt(r));
|
|
1070
|
+
Y(t, e, s, l, this.compareMinX);
|
|
1071
|
+
for (let h = e; h <= s; h += l) {
|
|
1072
|
+
const d = Math.min(h + l - 1, s);
|
|
1073
|
+
Y(t, h, d, c, this.compareMinY);
|
|
1074
|
+
for (let g = h; g <= d; g += c) {
|
|
1075
|
+
const P = Math.min(g + c - 1, d);
|
|
1076
|
+
a.children.push(this._build(t, g, P, n - 1));
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
return b(a, this.toBBox), a;
|
|
1080
|
+
}
|
|
1081
|
+
_chooseSubtree(t, e, s, n) {
|
|
1082
|
+
for (; n.push(e), !(e.leaf || n.length - 1 === s); ) {
|
|
1083
|
+
let o = 1 / 0, r = 1 / 0, a;
|
|
1084
|
+
for (let c = 0; c < e.children.length; c++) {
|
|
1085
|
+
const l = e.children[c], h = R(l), d = oe(t, l) - h;
|
|
1086
|
+
d < r ? (r = d, o = h < o ? h : o, a = l) : d === r && h < o && (o = h, a = l);
|
|
1087
|
+
}
|
|
1088
|
+
e = a || e.children[0];
|
|
1089
|
+
}
|
|
1090
|
+
return e;
|
|
1091
|
+
}
|
|
1092
|
+
_insert(t, e, s) {
|
|
1093
|
+
const n = s ? t : this.toBBox(t), o = [], r = this._chooseSubtree(n, this.data, e, o);
|
|
1094
|
+
for (r.children.push(t), D(r, n); e >= 0 && o[e].children.length > this._maxEntries; )
|
|
1095
|
+
this._split(o, e), e--;
|
|
1096
|
+
this._adjustParentBBoxes(n, o, e);
|
|
1097
|
+
}
|
|
1098
|
+
// split overflowed node into two
|
|
1099
|
+
_split(t, e) {
|
|
1100
|
+
const s = t[e], n = s.children.length, o = this._minEntries;
|
|
1101
|
+
this._chooseSplitAxis(s, o, n);
|
|
1102
|
+
const r = this._chooseSplitIndex(s, o, n), a = S(s.children.splice(r, s.children.length - r));
|
|
1103
|
+
a.height = s.height, a.leaf = s.leaf, b(s, this.toBBox), b(a, this.toBBox), e ? t[e - 1].children.push(a) : this._splitRoot(s, a);
|
|
1104
|
+
}
|
|
1105
|
+
_splitRoot(t, e) {
|
|
1106
|
+
this.data = S([t, e]), this.data.height = t.height + 1, this.data.leaf = !1, b(this.data, this.toBBox);
|
|
1107
|
+
}
|
|
1108
|
+
_chooseSplitIndex(t, e, s) {
|
|
1109
|
+
let n, o = 1 / 0, r = 1 / 0;
|
|
1110
|
+
for (let a = e; a <= s - e; a++) {
|
|
1111
|
+
const c = L(t, 0, a, this.toBBox), l = L(t, a, s, this.toBBox), h = re(c, l), d = R(c) + R(l);
|
|
1112
|
+
h < o ? (o = h, n = a, r = d < r ? d : r) : h === o && d < r && (r = d, n = a);
|
|
1113
|
+
}
|
|
1114
|
+
return n || s - e;
|
|
1115
|
+
}
|
|
1116
|
+
// sorts node children by the best axis for split
|
|
1117
|
+
_chooseSplitAxis(t, e, s) {
|
|
1118
|
+
const n = t.leaf ? this.compareMinX : ie, o = t.leaf ? this.compareMinY : ne, r = this._allDistMargin(t, e, s, n), a = this._allDistMargin(t, e, s, o);
|
|
1119
|
+
r < a && t.children.sort(n);
|
|
1120
|
+
}
|
|
1121
|
+
// total margin of all possible split distributions where each node is at least m full
|
|
1122
|
+
_allDistMargin(t, e, s, n) {
|
|
1123
|
+
t.children.sort(n);
|
|
1124
|
+
const o = this.toBBox, r = L(t, 0, e, o), a = L(t, s - e, s, o);
|
|
1125
|
+
let c = A(r) + A(a);
|
|
1126
|
+
for (let l = e; l < s - e; l++) {
|
|
1127
|
+
const h = t.children[l];
|
|
1128
|
+
D(r, t.leaf ? o(h) : h), c += A(r);
|
|
1129
|
+
}
|
|
1130
|
+
for (let l = s - e - 1; l >= e; l--) {
|
|
1131
|
+
const h = t.children[l];
|
|
1132
|
+
D(a, t.leaf ? o(h) : h), c += A(a);
|
|
1133
|
+
}
|
|
1134
|
+
return c;
|
|
1135
|
+
}
|
|
1136
|
+
_adjustParentBBoxes(t, e, s) {
|
|
1137
|
+
for (let n = s; n >= 0; n--)
|
|
1138
|
+
D(e[n], t);
|
|
1139
|
+
}
|
|
1140
|
+
_condense(t) {
|
|
1141
|
+
for (let e = t.length - 1, s; e >= 0; e--)
|
|
1142
|
+
t[e].children.length === 0 ? e > 0 ? (s = t[e - 1].children, s.splice(s.indexOf(t[e]), 1)) : this.clear() : b(t[e], this.toBBox);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
function se(i, t, e) {
|
|
1146
|
+
if (!e) return t.indexOf(i);
|
|
1147
|
+
for (let s = 0; s < t.length; s++)
|
|
1148
|
+
if (e(i, t[s])) return s;
|
|
1149
|
+
return -1;
|
|
1150
|
+
}
|
|
1151
|
+
function b(i, t) {
|
|
1152
|
+
L(i, 0, i.children.length, t, i);
|
|
1153
|
+
}
|
|
1154
|
+
function L(i, t, e, s, n) {
|
|
1155
|
+
n || (n = S(null)), n.minX = 1 / 0, n.minY = 1 / 0, n.maxX = -1 / 0, n.maxY = -1 / 0;
|
|
1156
|
+
for (let o = t; o < e; o++) {
|
|
1157
|
+
const r = i.children[o];
|
|
1158
|
+
D(n, i.leaf ? s(r) : r);
|
|
1159
|
+
}
|
|
1160
|
+
return n;
|
|
1161
|
+
}
|
|
1162
|
+
function D(i, t) {
|
|
1163
|
+
return i.minX = Math.min(i.minX, t.minX), i.minY = Math.min(i.minY, t.minY), i.maxX = Math.max(i.maxX, t.maxX), i.maxY = Math.max(i.maxY, t.maxY), i;
|
|
1164
|
+
}
|
|
1165
|
+
function ie(i, t) {
|
|
1166
|
+
return i.minX - t.minX;
|
|
1167
|
+
}
|
|
1168
|
+
function ne(i, t) {
|
|
1169
|
+
return i.minY - t.minY;
|
|
1170
|
+
}
|
|
1171
|
+
function R(i) {
|
|
1172
|
+
return (i.maxX - i.minX) * (i.maxY - i.minY);
|
|
1173
|
+
}
|
|
1174
|
+
function A(i) {
|
|
1175
|
+
return i.maxX - i.minX + (i.maxY - i.minY);
|
|
1176
|
+
}
|
|
1177
|
+
function oe(i, t) {
|
|
1178
|
+
return (Math.max(t.maxX, i.maxX) - Math.min(t.minX, i.minX)) * (Math.max(t.maxY, i.maxY) - Math.min(t.minY, i.minY));
|
|
1179
|
+
}
|
|
1180
|
+
function re(i, t) {
|
|
1181
|
+
const e = Math.max(i.minX, t.minX), s = Math.max(i.minY, t.minY), n = Math.min(i.maxX, t.maxX), o = Math.min(i.maxY, t.maxY);
|
|
1182
|
+
return Math.max(0, n - e) * Math.max(0, o - s);
|
|
1183
|
+
}
|
|
1184
|
+
function z(i, t) {
|
|
1185
|
+
return i.minX <= t.minX && i.minY <= t.minY && t.maxX <= i.maxX && t.maxY <= i.maxY;
|
|
1186
|
+
}
|
|
1187
|
+
function O(i, t) {
|
|
1188
|
+
return t.minX <= i.maxX && t.minY <= i.maxY && t.maxX >= i.minX && t.maxY >= i.minY;
|
|
1189
|
+
}
|
|
1190
|
+
function S(i) {
|
|
1191
|
+
return {
|
|
1192
|
+
children: i,
|
|
1193
|
+
height: 1,
|
|
1194
|
+
leaf: !0,
|
|
1195
|
+
minX: 1 / 0,
|
|
1196
|
+
minY: 1 / 0,
|
|
1197
|
+
maxX: -1 / 0,
|
|
1198
|
+
maxY: -1 / 0
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
function Y(i, t, e, s, n) {
|
|
1202
|
+
const o = [t, e];
|
|
1203
|
+
for (; o.length; ) {
|
|
1204
|
+
if (e = o.pop(), t = o.pop(), e - t <= s) continue;
|
|
1205
|
+
const r = t + Math.ceil((e - t) / s / 2) * s;
|
|
1206
|
+
H(i, r, t, e, n), o.push(t, r, r, e);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
class ae {
|
|
1210
|
+
/**
|
|
1211
|
+
* Construct one instance of this class
|
|
1212
|
+
* @param name Input layer name
|
|
1213
|
+
*/
|
|
1214
|
+
constructor(t) {
|
|
1215
|
+
this._group = new pt(), this._name = t;
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Layer name
|
|
1219
|
+
*/
|
|
1220
|
+
get name() {
|
|
1221
|
+
return this._name;
|
|
1222
|
+
}
|
|
1223
|
+
set name(t) {
|
|
1224
|
+
this._name = t;
|
|
1225
|
+
}
|
|
1226
|
+
get visible() {
|
|
1227
|
+
return this._group.visible;
|
|
1228
|
+
}
|
|
1229
|
+
set visible(t) {
|
|
1230
|
+
this._group.visible = t;
|
|
1231
|
+
}
|
|
1232
|
+
get internalObject() {
|
|
1233
|
+
return this._group;
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* The statistics of this layer
|
|
1237
|
+
*/
|
|
1238
|
+
get stats() {
|
|
1239
|
+
const t = this._group.stats;
|
|
1240
|
+
return {
|
|
1241
|
+
name: this._name,
|
|
1242
|
+
...t
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* The number of entities stored in this layer
|
|
1247
|
+
*/
|
|
1248
|
+
get entityCount() {
|
|
1249
|
+
return this._group.entityCount;
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Re-render points with latest point style settings
|
|
1253
|
+
* @param displayMode Input display mode of points
|
|
1254
|
+
*/
|
|
1255
|
+
rerenderPoints(t) {
|
|
1256
|
+
this._group.rerenderPoints(t);
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Return true if this layer contains the entity with the specified object id. Otherwise, return false.
|
|
1260
|
+
* @param objectId Input the object id of one entity
|
|
1261
|
+
* @returns Return true if this layer contains the entity with the specified object id. Otherwise,
|
|
1262
|
+
* return false.
|
|
1263
|
+
*/
|
|
1264
|
+
hasEntity(t) {
|
|
1265
|
+
return this._group.hasEntity(t);
|
|
1266
|
+
}
|
|
1267
|
+
/**
|
|
1268
|
+
* Add one AutoCAD entity into this layer.
|
|
1269
|
+
* @param entity Input AutoCAD entity to be added into this layer.
|
|
1270
|
+
*/
|
|
1271
|
+
addEntity(t) {
|
|
1272
|
+
this._group.addEntity(t);
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Return true if the object with the specified object id is intersected with the ray by using raycast.
|
|
1276
|
+
* @param objectId Input object id of object to check for intersection with the ray.
|
|
1277
|
+
* @param raycaster Input raycaster to check intersection
|
|
1278
|
+
*/
|
|
1279
|
+
isIntersectWith(t, e) {
|
|
1280
|
+
return this._group.isIntersectWith(t, e);
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Remove the specified entity from this layer.
|
|
1284
|
+
* @param objectId Input the object id of the entity to remove
|
|
1285
|
+
* @returns Return true if remove the specified entity successfully. Otherwise, return false.
|
|
1286
|
+
*/
|
|
1287
|
+
remove(t) {
|
|
1288
|
+
throw new Error("Not implemented yet!");
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Update the specified entity in this layer.
|
|
1292
|
+
* @param entity Input the entity to update
|
|
1293
|
+
* @returns Return true if update the specified entity successfully. Otherwise, return false.
|
|
1294
|
+
*/
|
|
1295
|
+
update(t) {
|
|
1296
|
+
return this._group.add(t), !0;
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Hover the specified entities
|
|
1300
|
+
*/
|
|
1301
|
+
hover(t) {
|
|
1302
|
+
t.forEach((e) => {
|
|
1303
|
+
this._group.hover(e);
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
/**
|
|
1307
|
+
* Unhover the specified entities
|
|
1308
|
+
*/
|
|
1309
|
+
unhover(t) {
|
|
1310
|
+
t.forEach((e) => {
|
|
1311
|
+
this._group.unhover(e);
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Select the specified entities
|
|
1316
|
+
*/
|
|
1317
|
+
select(t) {
|
|
1318
|
+
t.forEach((e) => {
|
|
1319
|
+
this._group.select(e);
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1323
|
+
* Unselect the specified entities
|
|
1324
|
+
*/
|
|
1325
|
+
unselect(t) {
|
|
1326
|
+
t.forEach((e) => {
|
|
1327
|
+
this._group.unselect(e);
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
class ce {
|
|
1332
|
+
constructor() {
|
|
1333
|
+
this._group = new f.Group(), this._indexTree = new ee(), this._box = new f.Box3(), this._layers = /* @__PURE__ */ new Map();
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* The internal THREE.js object to use by scene. This is internally used only. Try to avoid using it.
|
|
1337
|
+
* @internal
|
|
1338
|
+
*/
|
|
1339
|
+
get internalObject() {
|
|
1340
|
+
return this._group;
|
|
1341
|
+
}
|
|
1342
|
+
get layers() {
|
|
1343
|
+
return this._layers;
|
|
1344
|
+
}
|
|
1345
|
+
get box() {
|
|
1346
|
+
return this._box;
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* The visibility of this layout
|
|
1350
|
+
*/
|
|
1351
|
+
get visible() {
|
|
1352
|
+
return this._group.visible;
|
|
1353
|
+
}
|
|
1354
|
+
set visible(t) {
|
|
1355
|
+
this._group.visible = t;
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* The number of entities stored in this layer
|
|
1359
|
+
*/
|
|
1360
|
+
get entityCount() {
|
|
1361
|
+
let t = 0;
|
|
1362
|
+
return this._layers.forEach((e) => t += e.entityCount), t;
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* The statistics of this layout
|
|
1366
|
+
*/
|
|
1367
|
+
get stats() {
|
|
1368
|
+
const t = [];
|
|
1369
|
+
let e = 0, s = 0, n = 0, o = 0, r = 0;
|
|
1370
|
+
return this._layers.forEach((a) => {
|
|
1371
|
+
const c = a.stats;
|
|
1372
|
+
t.push(c), n += c.line.indexed.geometrySize + c.line.nonIndexed.geometrySize, o += c.mesh.indexed.geometrySize + c.mesh.nonIndexed.geometrySize, r += c.point.indexed.geometrySize + c.point.nonIndexed.geometrySize, e += c.summary.totalGeometrySize, s += c.summary.totalMappingSize;
|
|
1373
|
+
}), {
|
|
1374
|
+
layers: t,
|
|
1375
|
+
summary: {
|
|
1376
|
+
entityCount: this.entityCount,
|
|
1377
|
+
totalSize: {
|
|
1378
|
+
line: n,
|
|
1379
|
+
mesh: o,
|
|
1380
|
+
point: r,
|
|
1381
|
+
geometry: e,
|
|
1382
|
+
mapping: s
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1387
|
+
clear() {
|
|
1388
|
+
return this._layers.forEach((t) => {
|
|
1389
|
+
this._group.remove(t.internalObject);
|
|
1390
|
+
}), this._layers.clear(), this._box.makeEmpty(), this._indexTree.clear(), this;
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Re-render points with latest point style settings
|
|
1394
|
+
* @param displayMode Input display mode of points
|
|
1395
|
+
*/
|
|
1396
|
+
rerenderPoints(t) {
|
|
1397
|
+
this._layers.forEach((e) => {
|
|
1398
|
+
e.rerenderPoints(t);
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Return true if the object with the specified object id is intersected with the ray by using raycast.
|
|
1403
|
+
* @param objectId Input object id of object to check for intersection with the ray.
|
|
1404
|
+
* @param raycaster Input raycaster to check intersection
|
|
1405
|
+
*/
|
|
1406
|
+
isIntersectWith(t, e) {
|
|
1407
|
+
const s = this.getLayerByObjectId(t);
|
|
1408
|
+
return s && s.isIntersectWith(t, e);
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Add one AutoCAD entity into this layout. If layer group referenced by the entity doesn't exist, create one
|
|
1412
|
+
* layer group and add this entity this group.
|
|
1413
|
+
* @param entity Input AutoCAD entity to be added into this layout.
|
|
1414
|
+
* @param extendBbox Input the flag whether to extend the bounding box of the scene by union the bounding box
|
|
1415
|
+
* of the specified entity.
|
|
1416
|
+
*/
|
|
1417
|
+
addEntity(t, e = !0) {
|
|
1418
|
+
if (!t.objectId)
|
|
1419
|
+
throw new Error("[AcTrEntity] Object id is required to add one entity!");
|
|
1420
|
+
if (!t.layerName)
|
|
1421
|
+
throw new Error("[AcTrEntity] Layer name is required to add one entity!");
|
|
1422
|
+
const s = this.getLayer(t.layerName, !0);
|
|
1423
|
+
if (s) {
|
|
1424
|
+
s.addEntity(t);
|
|
1425
|
+
const n = t.box;
|
|
1426
|
+
e && this._box.union(n), this._indexTree.insert({
|
|
1427
|
+
minX: n.min.x,
|
|
1428
|
+
minY: n.min.y,
|
|
1429
|
+
maxX: n.max.x,
|
|
1430
|
+
maxY: n.max.y,
|
|
1431
|
+
id: t.objectId
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
return this;
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* Remove the specified entity from this layout.
|
|
1438
|
+
* @param objectId Input the object id of the entity to remove
|
|
1439
|
+
* @returns Return true if remove the specified entity successfully. Otherwise, return false.
|
|
1440
|
+
*/
|
|
1441
|
+
remove(t) {
|
|
1442
|
+
for (const [e, s] of this._layers)
|
|
1443
|
+
if (s.remove(t)) return !0;
|
|
1444
|
+
return !1;
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Update the specified entity in this layout.
|
|
1448
|
+
* @param objectId Input the entity to update
|
|
1449
|
+
* @returns Return true if update the specified entity successfully. Otherwise, return false.
|
|
1450
|
+
*/
|
|
1451
|
+
update(t) {
|
|
1452
|
+
for (const [e, s] of this._layers)
|
|
1453
|
+
if (s.update(t)) return !0;
|
|
1454
|
+
return !1;
|
|
1455
|
+
}
|
|
1456
|
+
/**
|
|
1457
|
+
* Hover the specified entities
|
|
1458
|
+
*/
|
|
1459
|
+
hover(t) {
|
|
1460
|
+
t.forEach((e) => {
|
|
1461
|
+
const s = this.getLayerByObjectId(e);
|
|
1462
|
+
s && s.hover([e]);
|
|
1463
|
+
});
|
|
1464
|
+
}
|
|
1465
|
+
/**
|
|
1466
|
+
* Unhover the specified entities
|
|
1467
|
+
*/
|
|
1468
|
+
unhover(t) {
|
|
1469
|
+
t.forEach((e) => {
|
|
1470
|
+
const s = this.getLayerByObjectId(e);
|
|
1471
|
+
s && s.unhover([e]);
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
/**
|
|
1475
|
+
* Select the specified entities
|
|
1476
|
+
*/
|
|
1477
|
+
select(t) {
|
|
1478
|
+
t.forEach((e) => {
|
|
1479
|
+
const s = this.getLayerByObjectId(e);
|
|
1480
|
+
s && s.select([e]);
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
/**
|
|
1484
|
+
* Unselect the specified entities
|
|
1485
|
+
*/
|
|
1486
|
+
unselect(t) {
|
|
1487
|
+
t.forEach((e) => {
|
|
1488
|
+
const s = this.getLayerByObjectId(e);
|
|
1489
|
+
s && s.unselect([e]);
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
setSnapObject(t) {
|
|
1493
|
+
this._snapPointsObject && this._group.remove(this._snapPointsObject), this._snapPointsObject = t, this._group.add(t);
|
|
1494
|
+
}
|
|
1495
|
+
/**
|
|
1496
|
+
* Search entities intersected or contained in the specified bounding box.
|
|
1497
|
+
* @param box Input the query bounding box
|
|
1498
|
+
* @returns Return query results
|
|
1499
|
+
*/
|
|
1500
|
+
search(t) {
|
|
1501
|
+
return this._indexTree.search({
|
|
1502
|
+
minX: t.min.x,
|
|
1503
|
+
minY: t.min.y,
|
|
1504
|
+
maxX: t.max.x,
|
|
1505
|
+
maxY: t.max.y
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
getLayerByObjectId(t) {
|
|
1509
|
+
for (const [e, s] of this._layers)
|
|
1510
|
+
if (s.hasEntity(t)) return s;
|
|
1511
|
+
}
|
|
1512
|
+
/**
|
|
1513
|
+
* Get layer group by name. If the layer doesn't exist, create one layer group into this layout.
|
|
1514
|
+
* @param name Input layer name
|
|
1515
|
+
* @param createIfNotExist Input one flag to indicate whether to create layer group if it doesn't exist in
|
|
1516
|
+
* this layout.
|
|
1517
|
+
* @returns Return matched layer
|
|
1518
|
+
*/
|
|
1519
|
+
getLayer(t, e = !0) {
|
|
1520
|
+
let s = this._layers.get(t);
|
|
1521
|
+
return s === void 0 && e && (s = new ae(t), this._layers.set(t, s), this._group.add(s.internalObject)), s;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
class he {
|
|
1525
|
+
constructor() {
|
|
1526
|
+
this._scene = new f.Scene(), this._layouts = /* @__PURE__ */ new Map(), this._activeLayoutBtrId = "", this._modelSpaceBtrId = "";
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1529
|
+
* The layouts in this scene
|
|
1530
|
+
*/
|
|
1531
|
+
get layouts() {
|
|
1532
|
+
return this._layouts;
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* The bounding box of the visibile objects in this secene
|
|
1536
|
+
*/
|
|
1537
|
+
get box() {
|
|
1538
|
+
var t;
|
|
1539
|
+
return (t = this.activeLayout) == null ? void 0 : t.box;
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
* The scene object of THREE.js. This is internally used only. Try to avoid using it.
|
|
1543
|
+
*/
|
|
1544
|
+
get internalScene() {
|
|
1545
|
+
return this._scene;
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* The block table record id of the model space
|
|
1549
|
+
*/
|
|
1550
|
+
get modelSpaceBtrId() {
|
|
1551
|
+
return this._modelSpaceBtrId;
|
|
1552
|
+
}
|
|
1553
|
+
set modelSpaceBtrId(t) {
|
|
1554
|
+
if (this._modelSpaceBtrId = t, !this._layouts.has(t))
|
|
1555
|
+
throw new Error(
|
|
1556
|
+
`[AcTrScene] No layout assiciated with the specified block table record id '${t}'!`
|
|
1557
|
+
);
|
|
1558
|
+
}
|
|
1559
|
+
/**
|
|
1560
|
+
* The block table record id associated with the current active layout
|
|
1561
|
+
*/
|
|
1562
|
+
get activeLayoutBtrId() {
|
|
1563
|
+
return this._activeLayoutBtrId;
|
|
1564
|
+
}
|
|
1565
|
+
set activeLayoutBtrId(t) {
|
|
1566
|
+
this._activeLayoutBtrId = t, this._layouts.forEach((e, s) => {
|
|
1567
|
+
e.visible = t == s;
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* Get active layout
|
|
1572
|
+
*/
|
|
1573
|
+
get activeLayout() {
|
|
1574
|
+
if (this._activeLayoutBtrId && this._layouts.has(this._activeLayoutBtrId))
|
|
1575
|
+
return this._layouts.get(this._activeLayoutBtrId);
|
|
1576
|
+
}
|
|
1577
|
+
/**
|
|
1578
|
+
* Get the layout of the model space
|
|
1579
|
+
*/
|
|
1580
|
+
get modelSpaceLayout() {
|
|
1581
|
+
if (this._modelSpaceBtrId && this._layouts.has(this._modelSpaceBtrId))
|
|
1582
|
+
return this._layouts.get(this._modelSpaceBtrId);
|
|
1583
|
+
}
|
|
1584
|
+
/**
|
|
1585
|
+
* The statistics of this scene
|
|
1586
|
+
*/
|
|
1587
|
+
get stats() {
|
|
1588
|
+
const t = [];
|
|
1589
|
+
return this._layouts.forEach((e) => t.push(e.stats)), {
|
|
1590
|
+
layouts: t
|
|
1591
|
+
};
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* Add one empty layout with the specified block table record id as the its key
|
|
1595
|
+
* @param ownerId Input the block table record id associated with this layout
|
|
1596
|
+
* @returns Return the newly created empty layout
|
|
1597
|
+
*/
|
|
1598
|
+
addEmptyLayout(t) {
|
|
1599
|
+
const e = new ce();
|
|
1600
|
+
return this._layouts.set(t, e), this._scene.add(e.internalObject), e.visible = t == this._activeLayoutBtrId, e;
|
|
1601
|
+
}
|
|
1602
|
+
/**
|
|
1603
|
+
* Clear scene
|
|
1604
|
+
* @returns Return this scene
|
|
1605
|
+
*/
|
|
1606
|
+
clear() {
|
|
1607
|
+
return this._layouts.forEach((t) => {
|
|
1608
|
+
this._scene.remove(t.internalObject), t.clear();
|
|
1609
|
+
}), this._layouts.clear(), this._scene.clear(), this;
|
|
1610
|
+
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Set layer's visibility
|
|
1613
|
+
* @param layerName Input layer name
|
|
1614
|
+
* @param visible Input visibility of the layer
|
|
1615
|
+
*/
|
|
1616
|
+
setLayerVisibility(t, e) {
|
|
1617
|
+
var n;
|
|
1618
|
+
let s = !1;
|
|
1619
|
+
return (n = this.activeLayout) == null || n.layers.forEach((o) => {
|
|
1620
|
+
o.name === t && (o.visible = e, s = !0);
|
|
1621
|
+
}), s;
|
|
1622
|
+
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Hover the specified entities
|
|
1625
|
+
*/
|
|
1626
|
+
hover(t) {
|
|
1627
|
+
return this.activeLayout ? (this.activeLayout.hover(t), !0) : !1;
|
|
1628
|
+
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Unhover the specified entities
|
|
1631
|
+
*/
|
|
1632
|
+
unhover(t) {
|
|
1633
|
+
return this.activeLayout ? (this.activeLayout.unhover(t), !0) : !1;
|
|
1634
|
+
}
|
|
1635
|
+
/**
|
|
1636
|
+
* Select the specified entities
|
|
1637
|
+
*/
|
|
1638
|
+
select(t) {
|
|
1639
|
+
return this.activeLayout ? (this.activeLayout.select(t), !0) : !1;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Unselect the specified entities
|
|
1643
|
+
*/
|
|
1644
|
+
unselect(t) {
|
|
1645
|
+
return this.activeLayout ? (this.activeLayout.unselect(t), !0) : !1;
|
|
1646
|
+
}
|
|
1647
|
+
/**
|
|
1648
|
+
* Search entities intersected or contained in the specified bounding box.
|
|
1649
|
+
* @param box Input the query bounding box
|
|
1650
|
+
* @returns Return query results
|
|
1651
|
+
*/
|
|
1652
|
+
search(t) {
|
|
1653
|
+
const e = this.activeLayout;
|
|
1654
|
+
return e ? e == null ? void 0 : e.search(t) : [];
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* Add one AutoCAD entity into this scene. If the layout associated with this entity doesn't exist,
|
|
1658
|
+
* then create one layout, add this layout into this scene, and add the entity into the layout.
|
|
1659
|
+
* @param entity Input AutoCAD entity to be added into scene.
|
|
1660
|
+
* @param extendBbox Input the flag whether to extend the bounding box of this scene by union the bounding box
|
|
1661
|
+
* of the specified entity.
|
|
1662
|
+
* @returns Return this scene
|
|
1663
|
+
*/
|
|
1664
|
+
addEntity(t, e = !0) {
|
|
1665
|
+
const s = t.ownerId;
|
|
1666
|
+
if (s) {
|
|
1667
|
+
let n = this._layouts.get(s);
|
|
1668
|
+
n || (n = this.addEmptyLayout(s)), n.addEntity(t, e);
|
|
1669
|
+
} else
|
|
1670
|
+
console.warn("[AcTrSecene] The owner id of one entity cannot be empty!");
|
|
1671
|
+
return this;
|
|
1672
|
+
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Remove the specified entity from this scene.
|
|
1675
|
+
* @param objectId Input the object id of the entity to remove
|
|
1676
|
+
* @returns Return true if remove the specified entity successfully. Otherwise, return false.
|
|
1677
|
+
*/
|
|
1678
|
+
remove(t) {
|
|
1679
|
+
for (const [e, s] of this._layouts)
|
|
1680
|
+
if (s.remove(t)) return !0;
|
|
1681
|
+
return !1;
|
|
1682
|
+
}
|
|
1683
|
+
/**
|
|
1684
|
+
* Update the specified entity in this scene.
|
|
1685
|
+
* @param objectId Input the entity to update
|
|
1686
|
+
* @returns Return true if update the specified entity successfully. Otherwise, return false.
|
|
1687
|
+
*/
|
|
1688
|
+
update(t) {
|
|
1689
|
+
for (const [e, s] of this._layouts)
|
|
1690
|
+
if (s.update(t)) return !0;
|
|
1691
|
+
return !1;
|
|
1692
|
+
}
|
|
1693
|
+
setSnapObject(t) {
|
|
1694
|
+
return this._layouts.forEach((e) => {
|
|
1695
|
+
e.setSnapObject(t);
|
|
1696
|
+
}), this;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
const X = {
|
|
1700
|
+
background: 0
|
|
1701
|
+
};
|
|
1702
|
+
class le extends Nt {
|
|
1703
|
+
constructor(t = X) {
|
|
1704
|
+
const e = {
|
|
1705
|
+
...X,
|
|
1706
|
+
...t
|
|
1707
|
+
}, s = new f.WebGLRenderer({
|
|
1708
|
+
antialias: !0,
|
|
1709
|
+
alpha: !0,
|
|
1710
|
+
canvas: t.canvas
|
|
1711
|
+
});
|
|
1712
|
+
e.canvas == null && (e.canvas = s.domElement), super(e.canvas), t.calculateSizeCallback && this.setCalculateSizeCallback(t.calculateSizeCallback), s.setPixelRatio(Math.min(window.devicePixelRatio, 2)), s.setSize(this.width, this.height), s.setClearColor(e.background || 0), this._renderer = new ft(s);
|
|
1713
|
+
const n = I.instance.fontMapping;
|
|
1714
|
+
this._renderer.setFontMapping(n), this._renderer.events.fontNotFound.addEventListener((o) => {
|
|
1715
|
+
v.emit("font-not-found", {
|
|
1716
|
+
fontName: o.fontName,
|
|
1717
|
+
count: o.count ?? 0
|
|
1718
|
+
});
|
|
1719
|
+
}), this._scene = this.createScene(), this._stats = this.createStats(I.instance.isShowStats), I.instance.events.modified.addEventListener((o) => {
|
|
1720
|
+
o.key == "isShowStats" && this.toggleStatsVisibility(this._stats, o.value);
|
|
1721
|
+
}), this.canvas.addEventListener("click", () => {
|
|
1722
|
+
this.mode == y.SELECTION && this.select();
|
|
1723
|
+
}), document.addEventListener("keydown", (o) => {
|
|
1724
|
+
o.code === "Escape" && this.selectionSet.clear();
|
|
1725
|
+
}), W().layoutManager.events.layoutSwitched.addEventListener(
|
|
1726
|
+
(o) => {
|
|
1727
|
+
this.activeLayoutBtrId = o.newLayout.blockTableRecordId;
|
|
1728
|
+
}
|
|
1729
|
+
), this._missedImages = /* @__PURE__ */ new Map(), this._layoutViewManager = new Qt(), this.initialize(), this.onWindowResize(), this.animate(), this._isDirty = !0;
|
|
1730
|
+
}
|
|
1731
|
+
initialize() {
|
|
1732
|
+
this.setCursor(C.Crosshair);
|
|
1733
|
+
}
|
|
1734
|
+
/**
|
|
1735
|
+
* @inheritdoc
|
|
1736
|
+
*/
|
|
1737
|
+
get mode() {
|
|
1738
|
+
const t = this.activeLayoutView;
|
|
1739
|
+
return t ? t.mode : y.SELECTION;
|
|
1740
|
+
}
|
|
1741
|
+
set mode(t) {
|
|
1742
|
+
this.activeLayoutView.mode = t, this.editor.getPoint();
|
|
1743
|
+
}
|
|
1744
|
+
get renderer() {
|
|
1745
|
+
return this._renderer;
|
|
1746
|
+
}
|
|
1747
|
+
get isDirty() {
|
|
1748
|
+
return this._isDirty;
|
|
1749
|
+
}
|
|
1750
|
+
set isDirty(t) {
|
|
1751
|
+
this._isDirty = t;
|
|
1752
|
+
}
|
|
1753
|
+
get missedData() {
|
|
1754
|
+
return {
|
|
1755
|
+
fonts: this._renderer.missedFonts,
|
|
1756
|
+
images: this._missedImages
|
|
1757
|
+
};
|
|
1758
|
+
}
|
|
1759
|
+
get center() {
|
|
1760
|
+
return this.activeLayoutView.center;
|
|
1761
|
+
}
|
|
1762
|
+
set center(t) {
|
|
1763
|
+
this.activeLayoutView.center = t;
|
|
1764
|
+
}
|
|
1765
|
+
/**
|
|
1766
|
+
* The block table record id of the model space
|
|
1767
|
+
*/
|
|
1768
|
+
get modelSpaceBtrId() {
|
|
1769
|
+
return this._scene.modelSpaceBtrId;
|
|
1770
|
+
}
|
|
1771
|
+
set modelSpaceBtrId(t) {
|
|
1772
|
+
this._scene.modelSpaceBtrId = t;
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* The block table record id associated with the active layout
|
|
1776
|
+
*/
|
|
1777
|
+
get activeLayoutBtrId() {
|
|
1778
|
+
return this._scene.activeLayoutBtrId;
|
|
1779
|
+
}
|
|
1780
|
+
set activeLayoutBtrId(t) {
|
|
1781
|
+
this._layoutViewManager.activeLayoutBtrId = t, this._scene.activeLayoutBtrId = t, this._isDirty = !0;
|
|
1782
|
+
}
|
|
1783
|
+
/**
|
|
1784
|
+
* The active layout view
|
|
1785
|
+
*/
|
|
1786
|
+
get activeLayoutView() {
|
|
1787
|
+
return this._layoutViewManager.activeLayoutView;
|
|
1788
|
+
}
|
|
1789
|
+
/**
|
|
1790
|
+
* The statistics of the current scene
|
|
1791
|
+
*/
|
|
1792
|
+
get stats() {
|
|
1793
|
+
return this._scene.stats;
|
|
1794
|
+
}
|
|
1795
|
+
animate() {
|
|
1796
|
+
var t;
|
|
1797
|
+
requestAnimationFrame(this.animate.bind(this)), this._isDirty && (this._layoutViewManager.render(this._scene), (t = this._stats) == null || t.update(), this._isDirty = !1);
|
|
1798
|
+
}
|
|
1799
|
+
/**
|
|
1800
|
+
* @inheritdoc
|
|
1801
|
+
*/
|
|
1802
|
+
cwcs2Wcs(t) {
|
|
1803
|
+
const e = this.activeLayoutView;
|
|
1804
|
+
return e ? e.cwcs2Wcs(t) : new u(t);
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* @inheritdoc
|
|
1808
|
+
*/
|
|
1809
|
+
wcs2Cwcs(t) {
|
|
1810
|
+
const e = this.activeLayoutView;
|
|
1811
|
+
return e ? e.wcs2Cwcs(t) : new u(t);
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* @inheritdoc
|
|
1815
|
+
*/
|
|
1816
|
+
zoomTo(t, e = 1.1) {
|
|
1817
|
+
this.activeLayoutView.zoomTo(t, e), this._isDirty = !0;
|
|
1818
|
+
}
|
|
1819
|
+
/**
|
|
1820
|
+
* Re-render points with latest point style settings
|
|
1821
|
+
* @param displayMode Input display mode of points
|
|
1822
|
+
*/
|
|
1823
|
+
rerenderPoints(t) {
|
|
1824
|
+
const e = this._scene.activeLayout;
|
|
1825
|
+
e && (e.rerenderPoints(t), this._isDirty = !0);
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* @inheritdoc
|
|
1829
|
+
*/
|
|
1830
|
+
zoomToFit() {
|
|
1831
|
+
if (this._scene.box) {
|
|
1832
|
+
const t = Kt.threeBox3dToGeBox2d(this._scene.box);
|
|
1833
|
+
this.zoomTo(t), this._isDirty = !0;
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* @inheritdoc
|
|
1838
|
+
*/
|
|
1839
|
+
pick(t) {
|
|
1840
|
+
t == null && (t = this.curPos);
|
|
1841
|
+
const e = [], s = this._scene.activeLayout;
|
|
1842
|
+
if (s) {
|
|
1843
|
+
const n = this.activeLayoutView, o = n.pointToBox(t, this.selectionBoxSize), r = this._scene.search(o), a = Math.max(o.size.width / 2, o.size.height / 2), c = n.resetRaycaster(t, a);
|
|
1844
|
+
r.forEach((l) => {
|
|
1845
|
+
const h = l.id;
|
|
1846
|
+
s.isIntersectWith(h, c) && e.push(h);
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
return e;
|
|
1850
|
+
}
|
|
1851
|
+
/**
|
|
1852
|
+
* @inheritdoc
|
|
1853
|
+
*/
|
|
1854
|
+
search(t) {
|
|
1855
|
+
return this._scene.search(t);
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* @inheritdoc
|
|
1859
|
+
*/
|
|
1860
|
+
select(t) {
|
|
1861
|
+
const e = [];
|
|
1862
|
+
this.pick(t).forEach((n) => e.push(n)), e.length > 0 && this.selectionSet.add(e);
|
|
1863
|
+
}
|
|
1864
|
+
/**
|
|
1865
|
+
* @inheritdoc
|
|
1866
|
+
*/
|
|
1867
|
+
selectByBox(t) {
|
|
1868
|
+
const e = [];
|
|
1869
|
+
this._scene.search(t).forEach((n) => e.push(n.id)), this.selectionSet.add(e);
|
|
1870
|
+
}
|
|
1871
|
+
/**
|
|
1872
|
+
* @inheritdoc
|
|
1873
|
+
*/
|
|
1874
|
+
addEntity(t) {
|
|
1875
|
+
const e = this.createLayoutViewIfNeeded(t.ownerId);
|
|
1876
|
+
let s = t.draw(
|
|
1877
|
+
this._renderer
|
|
1878
|
+
);
|
|
1879
|
+
if (s) {
|
|
1880
|
+
s.objectId = t.objectId, s.ownerId = t.ownerId, s.layerName = t.layer, s.visible = t.visibility;
|
|
1881
|
+
const n = !(t instanceof Q || t instanceof tt);
|
|
1882
|
+
this._scene.addEntity(s, n), this._isDirty = !0, s.dispose(), s = null;
|
|
1883
|
+
}
|
|
1884
|
+
if (t instanceof K) {
|
|
1885
|
+
if (t.number > 1) {
|
|
1886
|
+
const n = new yt(
|
|
1887
|
+
e,
|
|
1888
|
+
t.toGiViewport(),
|
|
1889
|
+
this._renderer
|
|
1890
|
+
);
|
|
1891
|
+
e.addViewport(n);
|
|
1892
|
+
}
|
|
1893
|
+
} else if (t instanceof Z) {
|
|
1894
|
+
const n = t.imageFileName;
|
|
1895
|
+
n && this._missedImages.set(t.objectId, n);
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
/**
|
|
1899
|
+
* Remove the specified entity from this view.
|
|
1900
|
+
* @param objectId Input the object id of the entity to remove
|
|
1901
|
+
*/
|
|
1902
|
+
removeEntity(t) {
|
|
1903
|
+
this._scene.remove(t);
|
|
1904
|
+
}
|
|
1905
|
+
/**
|
|
1906
|
+
* @inheritdoc
|
|
1907
|
+
*/
|
|
1908
|
+
updateEntity(t) {
|
|
1909
|
+
const e = t.draw(this._renderer);
|
|
1910
|
+
return e && (e.objectId = t.objectId, e.ownerId = t.ownerId, e.layerName = t.layer, e.visible = t.visibility, this._scene.update(e), this._isDirty = !0, setTimeout(() => {
|
|
1911
|
+
this._isDirty = !0;
|
|
1912
|
+
}, 100)), e;
|
|
1913
|
+
}
|
|
1914
|
+
/**
|
|
1915
|
+
* @inheritdoc
|
|
1916
|
+
*/
|
|
1917
|
+
clear() {
|
|
1918
|
+
this._scene.clear(), this._isDirty = !0, this._missedImages.clear(), this._renderer.clearMissedFonts();
|
|
1919
|
+
}
|
|
1920
|
+
/**
|
|
1921
|
+
* @inheritdoc
|
|
1922
|
+
*/
|
|
1923
|
+
highlight(t) {
|
|
1924
|
+
this._isDirty = this._scene.select(t);
|
|
1925
|
+
}
|
|
1926
|
+
/**
|
|
1927
|
+
* @inheritdoc
|
|
1928
|
+
*/
|
|
1929
|
+
unhighlight(t) {
|
|
1930
|
+
this._isDirty = this._scene.unselect(t);
|
|
1931
|
+
}
|
|
1932
|
+
/**
|
|
1933
|
+
* @inheritdoc
|
|
1934
|
+
*/
|
|
1935
|
+
setLayerVisibility(t, e) {
|
|
1936
|
+
this._isDirty = this._scene.setLayerVisibility(t, e);
|
|
1937
|
+
}
|
|
1938
|
+
/**
|
|
1939
|
+
* @inheritdoc
|
|
1940
|
+
*/
|
|
1941
|
+
onHover(t) {
|
|
1942
|
+
this._isDirty = this._scene.hover([t]);
|
|
1943
|
+
}
|
|
1944
|
+
/**
|
|
1945
|
+
* @inheritdoc
|
|
1946
|
+
*/
|
|
1947
|
+
onUnhover(t) {
|
|
1948
|
+
this._isDirty = this._scene.unhover([t]);
|
|
1949
|
+
}
|
|
1950
|
+
createScene() {
|
|
1951
|
+
const t = new he();
|
|
1952
|
+
return t.layouts.forEach((e) => {
|
|
1953
|
+
e.setSnapObject(this.renderer.createObject());
|
|
1954
|
+
}), t;
|
|
1955
|
+
}
|
|
1956
|
+
createStats(t) {
|
|
1957
|
+
const e = new vt();
|
|
1958
|
+
document.body.appendChild(e.dom);
|
|
1959
|
+
const s = e.dom;
|
|
1960
|
+
return s.style.position = "fixed", s.style.inset = "unset", s.style.bottom = "30px", s.style.right = "0px", this.toggleStatsVisibility(e, t), e;
|
|
1961
|
+
}
|
|
1962
|
+
onWindowResize() {
|
|
1963
|
+
super.onWindowResize(), this._renderer.setSize(this.width, this.height), this._layoutViewManager.resize(this.width, this.height), this._isDirty = !0;
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Create the layout view with the specified block table record id.
|
|
1967
|
+
* @param layoutBtrId Input the block table record id associated with the layout view.
|
|
1968
|
+
*/
|
|
1969
|
+
createLayoutViewIfNeeded(t) {
|
|
1970
|
+
let e = this._layoutViewManager.getAt(t);
|
|
1971
|
+
return e == null && (e = new Zt(
|
|
1972
|
+
this._renderer,
|
|
1973
|
+
t,
|
|
1974
|
+
this.width,
|
|
1975
|
+
this.height
|
|
1976
|
+
), e.events.viewChanged.addEventListener(() => {
|
|
1977
|
+
this._isDirty = !0;
|
|
1978
|
+
}), this._layoutViewManager.add(e)), e;
|
|
1979
|
+
}
|
|
1980
|
+
/**
|
|
1981
|
+
* Show or hide stats component
|
|
1982
|
+
* @param show If it is true, show stats component. Otherwise, hide stats component.
|
|
1983
|
+
* Default value is false.
|
|
1984
|
+
*/
|
|
1985
|
+
toggleStatsVisibility(t, e) {
|
|
1986
|
+
e ? t.dom.style.display = "block" : t.dom.style.display = "none";
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
const F = "simsun";
|
|
1990
|
+
class B {
|
|
1991
|
+
static get instance() {
|
|
1992
|
+
return B._instance || (B._instance = new B()), B._instance;
|
|
1993
|
+
}
|
|
1994
|
+
createExampleDoc1(t) {
|
|
1995
|
+
for (let n = 0; n < 2; ++n)
|
|
1996
|
+
for (let o = 0; o < 2; ++o) {
|
|
1997
|
+
const r = new j(), a = new et();
|
|
1998
|
+
a.addVertexAt(0, { x: o * 100, y: n * 100, bulge: 1 }), a.addVertexAt(1, { x: o * 100 + 100, y: n * 100, bulge: 1 }), a.closed = !0, r.add(a), t.tables.blockTable.modelSpace.appendEntity(r);
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
createExampleDoc2(t) {
|
|
2002
|
+
const e = t.tables.blockTable.modelSpace;
|
|
2003
|
+
e.appendEntity(this.createArc()), this.createLines().forEach((n) => {
|
|
2004
|
+
t.tables.blockTable.modelSpace.appendEntity(
|
|
2005
|
+
new st(n.startPoint, n.endPoint)
|
|
2006
|
+
);
|
|
2007
|
+
}), e.appendEntity(this.createHatch()), t.tables.textStyleTable.add(this.createTextStyle()), e.appendEntity(this.createMText());
|
|
2008
|
+
}
|
|
2009
|
+
createTextStyle() {
|
|
2010
|
+
const t = {
|
|
2011
|
+
bigFont: "",
|
|
2012
|
+
color: 16777215,
|
|
2013
|
+
extendedFont: F,
|
|
2014
|
+
fixedTextHeight: 0,
|
|
2015
|
+
font: F,
|
|
2016
|
+
lastHeight: 0.2,
|
|
2017
|
+
name: "Standard",
|
|
2018
|
+
obliqueAngle: 0,
|
|
2019
|
+
standardFlag: 0,
|
|
2020
|
+
textGenerationFlag: 0,
|
|
2021
|
+
widthFactor: 0.667
|
|
2022
|
+
};
|
|
2023
|
+
return new it(t);
|
|
2024
|
+
}
|
|
2025
|
+
createMText() {
|
|
2026
|
+
const t = new nt();
|
|
2027
|
+
return t.attachmentPoint = ot.MiddleLeft, t.color = new k().setColorName("red"), t.layer = "0", t.location = new rt(9850, 86773, 0), t.contents = "{\\W0.667;\\T1.1;智慧8081}", t.height = 200, t.width = 1e3, t.styleName = "Standard", t;
|
|
2028
|
+
}
|
|
2029
|
+
createHatch() {
|
|
2030
|
+
const t = this.createLines(), e = new j(), s = new at();
|
|
2031
|
+
return s.add(
|
|
2032
|
+
new ct(
|
|
2033
|
+
{ x: 20241.23355899991, y: 174118.6312674369 },
|
|
2034
|
+
89258.30757455899,
|
|
2035
|
+
T.degToRad(262.2471115358437),
|
|
2036
|
+
T.degToRad(264.444541053754),
|
|
2037
|
+
!1
|
|
2038
|
+
)
|
|
2039
|
+
), t.forEach((n) => {
|
|
2040
|
+
s.add(new ht(n.startPoint, n.endPoint));
|
|
2041
|
+
}), e.add(s), e;
|
|
2042
|
+
}
|
|
2043
|
+
createArc() {
|
|
2044
|
+
return new lt(
|
|
2045
|
+
{ x: 20241.23355899991, y: 174118.6312674369, z: 0 },
|
|
2046
|
+
89258.30757455899,
|
|
2047
|
+
T.degToRad(262.2471115358437),
|
|
2048
|
+
T.degToRad(264.444541053754)
|
|
2049
|
+
);
|
|
2050
|
+
}
|
|
2051
|
+
createLines() {
|
|
2052
|
+
const t = [];
|
|
2053
|
+
return t.push(
|
|
2054
|
+
new M(
|
|
2055
|
+
{
|
|
2056
|
+
x: 11600.20888122753,
|
|
2057
|
+
y: 85279.57362051727,
|
|
2058
|
+
z: 0
|
|
2059
|
+
},
|
|
2060
|
+
{
|
|
2061
|
+
x: 11600.20890652924,
|
|
2062
|
+
y: 86546.03982284805,
|
|
2063
|
+
z: 0
|
|
2064
|
+
}
|
|
2065
|
+
)
|
|
2066
|
+
), t.push(
|
|
2067
|
+
new M(
|
|
2068
|
+
{
|
|
2069
|
+
x: 11600.20890652924,
|
|
2070
|
+
y: 86546.03982284805,
|
|
2071
|
+
z: 0
|
|
2072
|
+
},
|
|
2073
|
+
{
|
|
2074
|
+
x: 10850.20885583921,
|
|
2075
|
+
y: 86546.03980174381,
|
|
2076
|
+
z: 0
|
|
2077
|
+
}
|
|
2078
|
+
)
|
|
2079
|
+
), t.push(
|
|
2080
|
+
new M(
|
|
2081
|
+
{
|
|
2082
|
+
x: 10850.2088602169,
|
|
2083
|
+
y: 86546.03967292747,
|
|
2084
|
+
z: 0
|
|
2085
|
+
},
|
|
2086
|
+
{
|
|
2087
|
+
x: 9050.208860216895,
|
|
2088
|
+
y: 86546.039672927,
|
|
2089
|
+
z: 0
|
|
2090
|
+
}
|
|
2091
|
+
)
|
|
2092
|
+
), t.push(
|
|
2093
|
+
new M(
|
|
2094
|
+
{
|
|
2095
|
+
x: 9050.208855839213,
|
|
2096
|
+
y: 86546.0397510943,
|
|
2097
|
+
z: 0
|
|
2098
|
+
},
|
|
2099
|
+
{
|
|
2100
|
+
x: 8200.209067034302,
|
|
2101
|
+
y: 86546.039727177,
|
|
2102
|
+
z: 0
|
|
2103
|
+
}
|
|
2104
|
+
)
|
|
2105
|
+
), t.push(
|
|
2106
|
+
new M(
|
|
2107
|
+
{
|
|
2108
|
+
x: 8200.209067034302,
|
|
2109
|
+
y: 86546.039727177,
|
|
2110
|
+
z: 0
|
|
2111
|
+
},
|
|
2112
|
+
{
|
|
2113
|
+
x: 8200.209067033837,
|
|
2114
|
+
y: 85676.22514764359,
|
|
2115
|
+
z: 0
|
|
2116
|
+
}
|
|
2117
|
+
)
|
|
2118
|
+
), t;
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
class de {
|
|
2122
|
+
constructor(t) {
|
|
2123
|
+
this._cadRenderer = t, this._avaiableFonts = [];
|
|
2124
|
+
}
|
|
2125
|
+
/**
|
|
2126
|
+
* Avaiable fonts to load.
|
|
2127
|
+
*/
|
|
2128
|
+
get avaiableFonts() {
|
|
2129
|
+
return this._avaiableFonts;
|
|
2130
|
+
}
|
|
2131
|
+
/**
|
|
2132
|
+
* @inheritdoc
|
|
2133
|
+
*/
|
|
2134
|
+
async getAvaiableFonts() {
|
|
2135
|
+
if (this._avaiableFonts.length == 0) {
|
|
2136
|
+
const t = "https://cdn.jsdelivr.net/gh/mlight-lee/cad-data/fonts/", e = t + "fonts.json";
|
|
2137
|
+
try {
|
|
2138
|
+
const s = await fetch(e);
|
|
2139
|
+
this._avaiableFonts = await s.json();
|
|
2140
|
+
} catch {
|
|
2141
|
+
v.emit("failed-to-get-avaiable-fonts", {
|
|
2142
|
+
url: e
|
|
2143
|
+
});
|
|
2144
|
+
}
|
|
2145
|
+
this._avaiableFonts.forEach((s) => {
|
|
2146
|
+
s.url = t + s.file;
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
return this._avaiableFonts;
|
|
2150
|
+
}
|
|
2151
|
+
/**
|
|
2152
|
+
* @inheritdoc
|
|
2153
|
+
*/
|
|
2154
|
+
async load(t) {
|
|
2155
|
+
await this.getAvaiableFonts();
|
|
2156
|
+
const e = [];
|
|
2157
|
+
t.forEach((n) => {
|
|
2158
|
+
const o = n.toLowerCase(), r = ut(this._avaiableFonts, (a) => mt(a.name, (c) => c.toLowerCase() == o) >= 0);
|
|
2159
|
+
r && e.push(r.url);
|
|
2160
|
+
}), (await this._cadRenderer.loadFonts(e)).forEach((n) => {
|
|
2161
|
+
n.status || v.emit("font-not-loaded", {
|
|
2162
|
+
fontName: n.fontName,
|
|
2163
|
+
url: n.url
|
|
2164
|
+
});
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
class w {
|
|
2169
|
+
constructor(t) {
|
|
2170
|
+
this.events = {
|
|
2171
|
+
documentCreated: new m(),
|
|
2172
|
+
documentActivated: new m()
|
|
2173
|
+
};
|
|
2174
|
+
const e = new Pt();
|
|
2175
|
+
e.database.events.openProgress.addEventListener((o) => {
|
|
2176
|
+
v.emit("open-file-progress", {
|
|
2177
|
+
percentage: o.percentage,
|
|
2178
|
+
stage: o.stage,
|
|
2179
|
+
stageStatus: o.stageStatus
|
|
2180
|
+
});
|
|
2181
|
+
});
|
|
2182
|
+
const s = () => ({
|
|
2183
|
+
width: window.innerWidth,
|
|
2184
|
+
height: window.innerHeight - 30
|
|
2185
|
+
}), n = new le({ canvas: t, calculateSizeCallback: s });
|
|
2186
|
+
this._context = new bt(n, e), this._fontLoader = new de(n.renderer), W().workingDatabase = e.database, this.registerCommands(), this.createExampleDoc();
|
|
2187
|
+
}
|
|
2188
|
+
static createInstance(t) {
|
|
2189
|
+
return w._instance == null && (w._instance = new w(t)), this._instance;
|
|
2190
|
+
}
|
|
2191
|
+
static get instance() {
|
|
2192
|
+
return w._instance || (w._instance = new w()), w._instance;
|
|
2193
|
+
}
|
|
2194
|
+
/**
|
|
2195
|
+
* Current context
|
|
2196
|
+
*/
|
|
2197
|
+
get context() {
|
|
2198
|
+
return this._context;
|
|
2199
|
+
}
|
|
2200
|
+
/**
|
|
2201
|
+
* Current open drawing
|
|
2202
|
+
*/
|
|
2203
|
+
get curDocument() {
|
|
2204
|
+
return this._context.doc;
|
|
2205
|
+
}
|
|
2206
|
+
/**
|
|
2207
|
+
* For now, it is same as property `curDocument`.
|
|
2208
|
+
*/
|
|
2209
|
+
get mdiActiveDocument() {
|
|
2210
|
+
return this._context.doc;
|
|
2211
|
+
}
|
|
2212
|
+
/**
|
|
2213
|
+
* Current view used to show current drawing
|
|
2214
|
+
*/
|
|
2215
|
+
get curView() {
|
|
2216
|
+
return this._context.view;
|
|
2217
|
+
}
|
|
2218
|
+
get editor() {
|
|
2219
|
+
return this._context.view.editor;
|
|
2220
|
+
}
|
|
2221
|
+
/**
|
|
2222
|
+
* Avaiable fonts to load. It means those fonts are avaiable to load. However, it
|
|
2223
|
+
* doesn't mean those fonts are already loaded and avaiable to use.
|
|
2224
|
+
*/
|
|
2225
|
+
get avaiableFonts() {
|
|
2226
|
+
return this._fontLoader.avaiableFonts;
|
|
2227
|
+
}
|
|
2228
|
+
/**
|
|
2229
|
+
* Load the specified fonts
|
|
2230
|
+
* @param fonts Input one list of font names
|
|
2231
|
+
*/
|
|
2232
|
+
async loadFonts(t) {
|
|
2233
|
+
await this._fontLoader.load(t);
|
|
2234
|
+
}
|
|
2235
|
+
/**
|
|
2236
|
+
* Load default fonts
|
|
2237
|
+
*/
|
|
2238
|
+
async loadDefaultFonts() {
|
|
2239
|
+
const t = ["simkai"];
|
|
2240
|
+
await this._fontLoader.load(t);
|
|
2241
|
+
}
|
|
2242
|
+
createExampleDoc() {
|
|
2243
|
+
setTimeout(async () => {
|
|
2244
|
+
await this.loadDefaultFonts(), B.instance.createExampleDoc2(this.curDocument.database), this.setLayoutInfo(), this.curView.zoomToFit();
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
async openUrl(t, e) {
|
|
2248
|
+
this.onBeforeOpenDocument(), e = this.setOptions(e);
|
|
2249
|
+
const s = await this.context.doc.openUri(t, e);
|
|
2250
|
+
this.onAfterOpenDocument(s);
|
|
2251
|
+
}
|
|
2252
|
+
async openDocument(t, e, s) {
|
|
2253
|
+
this.onBeforeOpenDocument(), s = this.setOptions(s);
|
|
2254
|
+
const n = await this.context.doc.openDocument(
|
|
2255
|
+
t,
|
|
2256
|
+
e,
|
|
2257
|
+
s
|
|
2258
|
+
);
|
|
2259
|
+
this.onAfterOpenDocument(n);
|
|
2260
|
+
}
|
|
2261
|
+
registerCommands() {
|
|
2262
|
+
const t = _.instance;
|
|
2263
|
+
t.addCommand(
|
|
2264
|
+
_.SYSTEMT_COMMAND_GROUP_NAME,
|
|
2265
|
+
"pan",
|
|
2266
|
+
"pan",
|
|
2267
|
+
new Ut()
|
|
2268
|
+
), t.addCommand(
|
|
2269
|
+
_.SYSTEMT_COMMAND_GROUP_NAME,
|
|
2270
|
+
"select",
|
|
2271
|
+
"select",
|
|
2272
|
+
new jt()
|
|
2273
|
+
), t.addCommand(
|
|
2274
|
+
_.SYSTEMT_COMMAND_GROUP_NAME,
|
|
2275
|
+
"zoom",
|
|
2276
|
+
"zoom",
|
|
2277
|
+
new Yt()
|
|
2278
|
+
), t.addCommand(
|
|
2279
|
+
_.SYSTEMT_COMMAND_GROUP_NAME,
|
|
2280
|
+
"zoomw",
|
|
2281
|
+
"zoomw",
|
|
2282
|
+
new Ft()
|
|
2283
|
+
), t.addCommand(
|
|
2284
|
+
_.SYSTEMT_COMMAND_GROUP_NAME,
|
|
2285
|
+
"csvg",
|
|
2286
|
+
"csvg",
|
|
2287
|
+
new zt()
|
|
2288
|
+
), t.addCommand(
|
|
2289
|
+
_.SYSTEMT_COMMAND_GROUP_NAME,
|
|
2290
|
+
"qnew",
|
|
2291
|
+
"qnew",
|
|
2292
|
+
new Gt()
|
|
2293
|
+
), t.addCommand(
|
|
2294
|
+
_.SYSTEMT_COMMAND_GROUP_NAME,
|
|
2295
|
+
"open",
|
|
2296
|
+
"open",
|
|
2297
|
+
new Vt()
|
|
2298
|
+
);
|
|
2299
|
+
}
|
|
2300
|
+
sendStringToExecute(t) {
|
|
2301
|
+
const s = _.instance.lookupGlobalCmd(t);
|
|
2302
|
+
s == null || s.execute(this.context);
|
|
2303
|
+
}
|
|
2304
|
+
onBeforeOpenDocument() {
|
|
2305
|
+
this.curView.clear();
|
|
2306
|
+
}
|
|
2307
|
+
onAfterOpenDocument(t) {
|
|
2308
|
+
t && (this.events.documentActivated.dispatch({
|
|
2309
|
+
doc: this.context.doc
|
|
2310
|
+
}), this.setLayoutInfo(), this.curView.zoomToFit());
|
|
2311
|
+
}
|
|
2312
|
+
setOptions(t) {
|
|
2313
|
+
return t == null ? t = { fontLoader: this._fontLoader } : t.fontLoader == null && (t.fontLoader = this._fontLoader), t;
|
|
2314
|
+
}
|
|
2315
|
+
setLayoutInfo() {
|
|
2316
|
+
const t = this.curView;
|
|
2317
|
+
t.activeLayoutBtrId = this.curDocument.database.currentSpaceId, t.modelSpaceBtrId = this.curDocument.database.currentSpaceId;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
const ue = {
|
|
2321
|
+
isDebug: !1,
|
|
2322
|
+
isShowCommandLine: !0,
|
|
2323
|
+
isShowCoordinate: !0,
|
|
2324
|
+
isShowToolbar: !0,
|
|
2325
|
+
isShowStats: !1,
|
|
2326
|
+
fontMapping: {}
|
|
2327
|
+
}, U = "settings";
|
|
2328
|
+
class I {
|
|
2329
|
+
constructor() {
|
|
2330
|
+
this.events = {
|
|
2331
|
+
modified: new m()
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
static get instance() {
|
|
2335
|
+
return this._instance || (this._instance = new I()), this._instance;
|
|
2336
|
+
}
|
|
2337
|
+
set(t, e) {
|
|
2338
|
+
const s = this.settings;
|
|
2339
|
+
s[t] = e, localStorage.setItem(U, JSON.stringify(s)), this.events.modified.dispatch({
|
|
2340
|
+
key: t,
|
|
2341
|
+
value: e
|
|
2342
|
+
});
|
|
2343
|
+
}
|
|
2344
|
+
get(t) {
|
|
2345
|
+
return this.settings[t];
|
|
2346
|
+
}
|
|
2347
|
+
toggle(t) {
|
|
2348
|
+
const e = this.get(t);
|
|
2349
|
+
this.set(t, !e);
|
|
2350
|
+
}
|
|
2351
|
+
get isDebug() {
|
|
2352
|
+
return this.get("isDebug");
|
|
2353
|
+
}
|
|
2354
|
+
set isDebug(t) {
|
|
2355
|
+
this.set("isDebug", t);
|
|
2356
|
+
}
|
|
2357
|
+
get isShowCommandLine() {
|
|
2358
|
+
return this.get("isShowCommandLine");
|
|
2359
|
+
}
|
|
2360
|
+
set isShowCommandLine(t) {
|
|
2361
|
+
this.set("isShowCommandLine", t);
|
|
2362
|
+
}
|
|
2363
|
+
get isShowCoordinate() {
|
|
2364
|
+
return this.get("isShowCoordinate");
|
|
2365
|
+
}
|
|
2366
|
+
set isShowCoordinate(t) {
|
|
2367
|
+
this.set("isShowCoordinate", t);
|
|
2368
|
+
}
|
|
2369
|
+
get isShowToolbar() {
|
|
2370
|
+
return this.get("isShowToolbar");
|
|
2371
|
+
}
|
|
2372
|
+
set isShowToolbar(t) {
|
|
2373
|
+
this.set("isShowToolbar", t);
|
|
2374
|
+
}
|
|
2375
|
+
get isShowStats() {
|
|
2376
|
+
return this.get("isShowStats");
|
|
2377
|
+
}
|
|
2378
|
+
set isShowStats(t) {
|
|
2379
|
+
this.set("isShowStats", t);
|
|
2380
|
+
}
|
|
2381
|
+
get fontMapping() {
|
|
2382
|
+
return this.get("fontMapping");
|
|
2383
|
+
}
|
|
2384
|
+
set fontMapping(t) {
|
|
2385
|
+
this.set("fontMapping", t);
|
|
2386
|
+
}
|
|
2387
|
+
setFontMapping(t, e) {
|
|
2388
|
+
const s = this.get("fontMapping");
|
|
2389
|
+
s[t] = e, this.set("fontMapping", s);
|
|
2390
|
+
}
|
|
2391
|
+
get settings() {
|
|
2392
|
+
const t = localStorage.getItem(U), e = t == null ? {} : JSON.parse(t);
|
|
2393
|
+
return _t(e, ue);
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
export {
|
|
2397
|
+
bt as AcApContext,
|
|
2398
|
+
zt as AcApConvertToSvgCmd,
|
|
2399
|
+
w as AcApDocManager,
|
|
2400
|
+
Pt as AcApDocument,
|
|
2401
|
+
Vt as AcApOpenCmd,
|
|
2402
|
+
Ut as AcApPanCmd,
|
|
2403
|
+
Gt as AcApQNewCmd,
|
|
2404
|
+
jt as AcApSelectCmd,
|
|
2405
|
+
I as AcApSettingManager,
|
|
2406
|
+
Yt as AcApZoomCmd,
|
|
2407
|
+
Ft as AcApZoomToBoxCmd,
|
|
2408
|
+
Xt as AcApZoomToBoxJig,
|
|
2409
|
+
Nt as AcEdBaseView,
|
|
2410
|
+
x as AcEdCommand,
|
|
2411
|
+
_ as AcEdCommandStack,
|
|
2412
|
+
C as AcEdCorsorType,
|
|
2413
|
+
Mt as AcEdCursorManager,
|
|
2414
|
+
Lt as AcEdJig,
|
|
2415
|
+
Ot as AcEdSelectionSet,
|
|
2416
|
+
y as AcEdViewMode,
|
|
2417
|
+
At as AcEditor,
|
|
2418
|
+
le as AcTrView2d,
|
|
2419
|
+
X as DEFAULT_VIEW_2D_OPTIONS,
|
|
2420
|
+
ve as acedAlert,
|
|
2421
|
+
v as eventBus
|
|
2422
|
+
};
|