@mlightcad/cad-simple-viewer 1.2.2 → 1.2.3

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.
Files changed (202) hide show
  1. package/dist/__vite-browser-external-l0sNRNKZ-l0sNRNKZ.js +1 -0
  2. package/dist/index.js +40205 -0
  3. package/dist/index.umd.cjs +333 -0
  4. package/dist/libredwg-parser-worker.js +15458 -0
  5. package/dist/mtext-renderer-worker.js +29930 -0
  6. package/lib/app/AcApContext.d.ts +57 -0
  7. package/lib/app/AcApContext.d.ts.map +1 -0
  8. package/lib/app/AcApContext.js +106 -0
  9. package/lib/app/AcApContext.js.map +1 -0
  10. package/lib/app/AcApDocManager.d.ts +291 -0
  11. package/lib/app/AcApDocManager.d.ts.map +1 -0
  12. package/lib/app/AcApDocManager.js +498 -0
  13. package/lib/app/AcApDocManager.js.map +1 -0
  14. package/lib/app/AcApDocument.d.ts +101 -0
  15. package/lib/app/AcApDocument.d.ts.map +1 -0
  16. package/lib/app/AcApDocument.js +237 -0
  17. package/lib/app/AcApDocument.js.map +1 -0
  18. package/lib/app/AcApFontLoader.d.ts +54 -0
  19. package/lib/app/AcApFontLoader.d.ts.map +1 -0
  20. package/lib/app/AcApFontLoader.js +151 -0
  21. package/lib/app/AcApFontLoader.js.map +1 -0
  22. package/lib/app/AcApGlobalFunc.d.ts +26 -0
  23. package/lib/app/AcApGlobalFunc.d.ts.map +1 -0
  24. package/lib/app/AcApGlobalFunc.js +66 -0
  25. package/lib/app/AcApGlobalFunc.js.map +1 -0
  26. package/lib/app/AcApSettingManager.d.ts +232 -0
  27. package/lib/app/AcApSettingManager.d.ts.map +1 -0
  28. package/lib/app/AcApSettingManager.js +283 -0
  29. package/lib/app/AcApSettingManager.js.map +1 -0
  30. package/lib/app/index.d.ts +6 -0
  31. package/lib/app/index.d.ts.map +1 -0
  32. package/lib/app/index.js +6 -0
  33. package/lib/app/index.js.map +1 -0
  34. package/lib/command/AcApConvertToSvgCmd.d.ts +32 -0
  35. package/lib/command/AcApConvertToSvgCmd.d.ts.map +1 -0
  36. package/lib/command/AcApConvertToSvgCmd.js +56 -0
  37. package/lib/command/AcApConvertToSvgCmd.js.map +1 -0
  38. package/lib/command/AcApOpenCmd.d.ts +37 -0
  39. package/lib/command/AcApOpenCmd.d.ts.map +1 -0
  40. package/lib/command/AcApOpenCmd.js +60 -0
  41. package/lib/command/AcApOpenCmd.js.map +1 -0
  42. package/lib/command/AcApPanCmd.d.ts +31 -0
  43. package/lib/command/AcApPanCmd.d.ts.map +1 -0
  44. package/lib/command/AcApPanCmd.js +55 -0
  45. package/lib/command/AcApPanCmd.js.map +1 -0
  46. package/lib/command/AcApQNewCmd.d.ts +32 -0
  47. package/lib/command/AcApQNewCmd.d.ts.map +1 -0
  48. package/lib/command/AcApQNewCmd.js +56 -0
  49. package/lib/command/AcApQNewCmd.js.map +1 -0
  50. package/lib/command/AcApRegenCmd.d.ts +21 -0
  51. package/lib/command/AcApRegenCmd.d.ts.map +1 -0
  52. package/lib/command/AcApRegenCmd.js +45 -0
  53. package/lib/command/AcApRegenCmd.js.map +1 -0
  54. package/lib/command/AcApSelectCmd.d.ts +32 -0
  55. package/lib/command/AcApSelectCmd.d.ts.map +1 -0
  56. package/lib/command/AcApSelectCmd.js +56 -0
  57. package/lib/command/AcApSelectCmd.js.map +1 -0
  58. package/lib/command/AcApSvgConvertor.d.ts +53 -0
  59. package/lib/command/AcApSvgConvertor.d.ts.map +1 -0
  60. package/lib/command/AcApSvgConvertor.js +103 -0
  61. package/lib/command/AcApSvgConvertor.js.map +1 -0
  62. package/lib/command/AcApZoomCmd.d.ts +35 -0
  63. package/lib/command/AcApZoomCmd.d.ts.map +1 -0
  64. package/lib/command/AcApZoomCmd.js +57 -0
  65. package/lib/command/AcApZoomCmd.js.map +1 -0
  66. package/lib/command/AcApZoomToBoxCmd.d.ts +68 -0
  67. package/lib/command/AcApZoomToBoxCmd.d.ts.map +1 -0
  68. package/lib/command/AcApZoomToBoxCmd.js +158 -0
  69. package/lib/command/AcApZoomToBoxCmd.js.map +1 -0
  70. package/lib/command/index.d.ts +11 -0
  71. package/lib/command/index.d.ts.map +1 -0
  72. package/lib/command/index.js +11 -0
  73. package/lib/command/index.js.map +1 -0
  74. package/lib/editor/command/AcEdCommand.d.ts +151 -0
  75. package/lib/editor/command/AcEdCommand.d.ts.map +1 -0
  76. package/lib/editor/command/AcEdCommand.js +164 -0
  77. package/lib/editor/command/AcEdCommand.js.map +1 -0
  78. package/lib/editor/command/AcEdCommandIterator.d.ts +36 -0
  79. package/lib/editor/command/AcEdCommandIterator.d.ts.map +1 -0
  80. package/lib/editor/command/AcEdCommandIterator.js +65 -0
  81. package/lib/editor/command/AcEdCommandIterator.js.map +1 -0
  82. package/lib/editor/command/AcEdCommandStack.d.ts +120 -0
  83. package/lib/editor/command/AcEdCommandStack.d.ts.map +1 -0
  84. package/lib/editor/command/AcEdCommandStack.js +235 -0
  85. package/lib/editor/command/AcEdCommandStack.js.map +1 -0
  86. package/lib/editor/command/index.d.ts +3 -0
  87. package/lib/editor/command/index.d.ts.map +1 -0
  88. package/lib/editor/command/index.js +3 -0
  89. package/lib/editor/command/index.js.map +1 -0
  90. package/lib/editor/global/AcEdConditionWaiter.d.ts +51 -0
  91. package/lib/editor/global/AcEdConditionWaiter.d.ts.map +1 -0
  92. package/lib/editor/global/AcEdConditionWaiter.js +87 -0
  93. package/lib/editor/global/AcEdConditionWaiter.js.map +1 -0
  94. package/lib/editor/global/AcEdGlobalFunc.d.ts +8 -0
  95. package/lib/editor/global/AcEdGlobalFunc.d.ts.map +1 -0
  96. package/lib/editor/global/AcEdGlobalFunc.js +14 -0
  97. package/lib/editor/global/AcEdGlobalFunc.js.map +1 -0
  98. package/lib/editor/global/AcEdMessage.d.ts +5 -0
  99. package/lib/editor/global/AcEdMessage.d.ts.map +1 -0
  100. package/lib/editor/global/AcEdMessage.js +6 -0
  101. package/lib/editor/global/AcEdMessage.js.map +1 -0
  102. package/lib/editor/global/eventBus.d.ts +103 -0
  103. package/lib/editor/global/eventBus.d.ts.map +1 -0
  104. package/lib/editor/global/eventBus.js +41 -0
  105. package/lib/editor/global/eventBus.js.map +1 -0
  106. package/lib/editor/global/index.d.ts +4 -0
  107. package/lib/editor/global/index.d.ts.map +1 -0
  108. package/lib/editor/global/index.js +4 -0
  109. package/lib/editor/global/index.js.map +1 -0
  110. package/lib/editor/index.d.ts +5 -0
  111. package/lib/editor/index.d.ts.map +1 -0
  112. package/lib/editor/index.js +5 -0
  113. package/lib/editor/index.js.map +1 -0
  114. package/lib/editor/input/AcEdBaseInput.d.ts +89 -0
  115. package/lib/editor/input/AcEdBaseInput.d.ts.map +1 -0
  116. package/lib/editor/input/AcEdBaseInput.js +166 -0
  117. package/lib/editor/input/AcEdBaseInput.js.map +1 -0
  118. package/lib/editor/input/AcEdBoxSelector.d.ts +108 -0
  119. package/lib/editor/input/AcEdBoxSelector.d.ts.map +1 -0
  120. package/lib/editor/input/AcEdBoxSelector.js +220 -0
  121. package/lib/editor/input/AcEdBoxSelector.js.map +1 -0
  122. package/lib/editor/input/AcEdCursorManager.d.ts +130 -0
  123. package/lib/editor/input/AcEdCursorManager.d.ts.map +1 -0
  124. package/lib/editor/input/AcEdCursorManager.js +155 -0
  125. package/lib/editor/input/AcEdCursorManager.js.map +1 -0
  126. package/lib/editor/input/AcEdInputPoint.d.ts +51 -0
  127. package/lib/editor/input/AcEdInputPoint.d.ts.map +1 -0
  128. package/lib/editor/input/AcEdInputPoint.js +78 -0
  129. package/lib/editor/input/AcEdInputPoint.js.map +1 -0
  130. package/lib/editor/input/AcEdJig.d.ts +180 -0
  131. package/lib/editor/input/AcEdJig.d.ts.map +1 -0
  132. package/lib/editor/input/AcEdJig.js +256 -0
  133. package/lib/editor/input/AcEdJig.js.map +1 -0
  134. package/lib/editor/input/AcEdJigLoop.d.ts +63 -0
  135. package/lib/editor/input/AcEdJigLoop.d.ts.map +1 -0
  136. package/lib/editor/input/AcEdJigLoop.js +91 -0
  137. package/lib/editor/input/AcEdJigLoop.js.map +1 -0
  138. package/lib/editor/input/AcEdSelectionSet.d.ts +146 -0
  139. package/lib/editor/input/AcEdSelectionSet.d.ts.map +1 -0
  140. package/lib/editor/input/AcEdSelectionSet.js +179 -0
  141. package/lib/editor/input/AcEdSelectionSet.js.map +1 -0
  142. package/lib/editor/input/AcEditor.d.ts +111 -0
  143. package/lib/editor/input/AcEditor.d.ts.map +1 -0
  144. package/lib/editor/input/AcEditor.js +183 -0
  145. package/lib/editor/input/AcEditor.js.map +1 -0
  146. package/lib/editor/input/index.d.ts +5 -0
  147. package/lib/editor/input/index.d.ts.map +1 -0
  148. package/lib/editor/input/index.js +5 -0
  149. package/lib/editor/input/index.js.map +1 -0
  150. package/lib/editor/view/AcEdBaseView.d.ts +457 -0
  151. package/lib/editor/view/AcEdBaseView.d.ts.map +1 -0
  152. package/lib/editor/view/AcEdBaseView.js +349 -0
  153. package/lib/editor/view/AcEdBaseView.js.map +1 -0
  154. package/lib/editor/view/AcEdLayerInfo.d.ts +21 -0
  155. package/lib/editor/view/AcEdLayerInfo.d.ts.map +1 -0
  156. package/lib/editor/view/AcEdLayerInfo.js +2 -0
  157. package/lib/editor/view/AcEdLayerInfo.js.map +1 -0
  158. package/lib/editor/view/index.d.ts +3 -0
  159. package/lib/editor/view/index.d.ts.map +1 -0
  160. package/lib/editor/view/index.js +3 -0
  161. package/lib/editor/view/index.js.map +1 -0
  162. package/lib/index.d.ts +5 -0
  163. package/lib/index.d.ts.map +1 -0
  164. package/lib/index.js +5 -0
  165. package/lib/index.js.map +1 -0
  166. package/lib/util/AcTrGeometryUtil.d.ts +92 -0
  167. package/lib/util/AcTrGeometryUtil.d.ts.map +1 -0
  168. package/lib/util/AcTrGeometryUtil.js +109 -0
  169. package/lib/util/AcTrGeometryUtil.js.map +1 -0
  170. package/lib/util/index.d.ts +2 -0
  171. package/lib/util/index.d.ts.map +1 -0
  172. package/lib/util/index.js +2 -0
  173. package/lib/util/index.js.map +1 -0
  174. package/lib/view/AcTrLayer.d.ts +132 -0
  175. package/lib/view/AcTrLayer.d.ts.map +1 -0
  176. package/lib/view/AcTrLayer.js +199 -0
  177. package/lib/view/AcTrLayer.js.map +1 -0
  178. package/lib/view/AcTrLayout.d.ts +218 -0
  179. package/lib/view/AcTrLayout.d.ts.map +1 -0
  180. package/lib/view/AcTrLayout.js +437 -0
  181. package/lib/view/AcTrLayout.js.map +1 -0
  182. package/lib/view/AcTrLayoutView.d.ts +115 -0
  183. package/lib/view/AcTrLayoutView.d.ts.map +1 -0
  184. package/lib/view/AcTrLayoutView.js +200 -0
  185. package/lib/view/AcTrLayoutView.js.map +1 -0
  186. package/lib/view/AcTrLayoutViewManager.d.ts +89 -0
  187. package/lib/view/AcTrLayoutViewManager.d.ts.map +1 -0
  188. package/lib/view/AcTrLayoutViewManager.js +118 -0
  189. package/lib/view/AcTrLayoutViewManager.js.map +1 -0
  190. package/lib/view/AcTrScene.d.ts +162 -0
  191. package/lib/view/AcTrScene.d.ts.map +1 -0
  192. package/lib/view/AcTrScene.js +370 -0
  193. package/lib/view/AcTrScene.js.map +1 -0
  194. package/lib/view/AcTrView2d.d.ts +262 -0
  195. package/lib/view/AcTrView2d.d.ts.map +1 -0
  196. package/lib/view/AcTrView2d.js +772 -0
  197. package/lib/view/AcTrView2d.js.map +1 -0
  198. package/lib/view/index.d.ts +2 -0
  199. package/lib/view/index.d.ts.map +1 -0
  200. package/lib/view/index.js +2 -0
  201. package/lib/view/index.js.map +1 -0
  202. package/package.json +3 -3
@@ -0,0 +1,772 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
28
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
29
+ return new (P || (P = Promise))(function (resolve, reject) {
30
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
31
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
32
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
33
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
34
+ });
35
+ };
36
+ var __generator = (this && this.__generator) || function (thisArg, body) {
37
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
38
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
39
+ function verb(n) { return function (v) { return step([n, v]); }; }
40
+ function step(op) {
41
+ if (f) throw new TypeError("Generator is already executing.");
42
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
43
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
44
+ if (y = 0, t) op = [op[0] & 2, t.value];
45
+ switch (op[0]) {
46
+ case 0: case 1: t = op; break;
47
+ case 4: _.label++; return { value: op[1], done: false };
48
+ case 5: _.label++; y = op[1]; op = [0]; continue;
49
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
50
+ default:
51
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
52
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
53
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
54
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
55
+ if (t[2]) _.ops.pop();
56
+ _.trys.pop(); continue;
57
+ }
58
+ op = body.call(thisArg, _);
59
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
60
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
61
+ }
62
+ };
63
+ var __read = (this && this.__read) || function (o, n) {
64
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
65
+ if (!m) return o;
66
+ var i = m.call(o), r, ar = [], e;
67
+ try {
68
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
69
+ }
70
+ catch (error) { e = { error: error }; }
71
+ finally {
72
+ try {
73
+ if (r && !r.done && (m = i["return"])) m.call(i);
74
+ }
75
+ finally { if (e) throw e.error; }
76
+ }
77
+ return ar;
78
+ };
79
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
80
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
81
+ if (ar || !(i in from)) {
82
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
83
+ ar[i] = from[i];
84
+ }
85
+ }
86
+ return to.concat(ar || Array.prototype.slice.call(from));
87
+ };
88
+ import { acdbHostApplicationServices, AcDbRasterImage, AcDbRay, AcDbViewport, AcDbXline, AcGePoint2d } from '@mlightcad/data-model';
89
+ import { AcTrEntity, AcTrGroup, AcTrRenderer, AcTrViewportView } from '@mlightcad/three-renderer';
90
+ import * as THREE from 'three';
91
+ import Stats from 'three/examples/jsm/libs/stats.module';
92
+ import { AcApSettingManager } from '../app';
93
+ import { AcEdBaseView, AcEdConditionWaiter, AcEdCorsorType, AcEdViewMode, eventBus } from '../editor';
94
+ import { AcTrGeometryUtil } from '../util';
95
+ import { AcTrLayoutView } from './AcTrLayoutView';
96
+ import { AcTrLayoutViewManager } from './AcTrLayoutViewManager';
97
+ import { AcTrScene } from './AcTrScene';
98
+ /**
99
+ * Default view option values
100
+ */
101
+ export var DEFAULT_VIEW_2D_OPTIONS = {
102
+ background: 0x000000
103
+ };
104
+ /**
105
+ * A 2D CAD viewer component that renders CAD drawings using Three.js.
106
+ *
107
+ * This class extends {@link AcEdBaseView} and provides functionality for:
108
+ * - Rendering 2D CAD drawings with Three.js WebGL renderer
109
+ * - Handling user interactions (pan, zoom, select)
110
+ * - Managing layouts, layers, and entities
111
+ * - Supporting various CAD file formats (DWG, DXF)
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const viewer = new AcTrView2d({
116
+ * canvas: document.getElementById('canvas') as HTMLCanvasElement,
117
+ * background: 0x000000,
118
+ * calculateSizeCallback: () => ({
119
+ * width: window.innerWidth,
120
+ * height: window.innerHeight
121
+ * })
122
+ * });
123
+ * ```
124
+ */
125
+ var AcTrView2d = /** @class */ (function (_super) {
126
+ __extends(AcTrView2d, _super);
127
+ /**
128
+ * Creates a new 2D CAD viewer instance.
129
+ *
130
+ * @param options - Configuration options for the viewer
131
+ * @param options.canvas - Optional HTML canvas element. If not provided, a new canvas will be created
132
+ * @param options.calculateSizeCallback - Optional callback function to calculate canvas size on window resize
133
+ * @param options.background - Optional background color as hex number (default: 0x000000)
134
+ */
135
+ function AcTrView2d(options) {
136
+ if (options === void 0) { options = DEFAULT_VIEW_2D_OPTIONS; }
137
+ var _this = this;
138
+ var mergedOptions = __assign(__assign({}, DEFAULT_VIEW_2D_OPTIONS), options);
139
+ var renderer = new THREE.WebGLRenderer({
140
+ antialias: true,
141
+ alpha: true,
142
+ canvas: options.canvas
143
+ });
144
+ if (mergedOptions.canvas == null) {
145
+ mergedOptions.canvas = renderer.domElement;
146
+ }
147
+ _this = _super.call(this, mergedOptions.canvas) || this;
148
+ if (options.calculateSizeCallback) {
149
+ _this.setCalculateSizeCallback(options.calculateSizeCallback);
150
+ }
151
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
152
+ renderer.setSize(_this.width, _this.height);
153
+ _this._renderer = new AcTrRenderer(renderer);
154
+ var fontMapping = AcApSettingManager.instance.fontMapping;
155
+ _this._renderer.setFontMapping(fontMapping);
156
+ _this._renderer.events.fontNotFound.addEventListener(function (args) {
157
+ var _a;
158
+ eventBus.emit('font-not-found', {
159
+ fontName: args.fontName,
160
+ count: (_a = args.count) !== null && _a !== void 0 ? _a : 0
161
+ });
162
+ });
163
+ _this._scene = _this.createScene();
164
+ // Initialize background color via renderer clear color
165
+ _this._renderer.setClearColor(mergedOptions.background || 0x000000);
166
+ _this._stats = _this.createStats(AcApSettingManager.instance.isShowStats);
167
+ AcApSettingManager.instance.events.modified.addEventListener(function (args) {
168
+ if (args.key == 'isShowStats') {
169
+ _this.toggleStatsVisibility(_this._stats, args.value);
170
+ }
171
+ });
172
+ _this.canvas.addEventListener('click', function () {
173
+ if (_this.mode == AcEdViewMode.SELECTION) {
174
+ _this.select();
175
+ }
176
+ });
177
+ // When using OrbitControls in THREE.js, it attaches its own event listeners to the DOM elements,
178
+ // such as the canvas or the entire document. This can interfere with other event listeners you
179
+ // add, including the keydown event.
180
+ document.addEventListener('keydown', function (e) {
181
+ if (e.code === 'Escape') {
182
+ _this.selectionSet.clear();
183
+ }
184
+ });
185
+ acdbHostApplicationServices().layoutManager.events.layoutSwitched.addEventListener(function (args) {
186
+ _this.activeLayoutBtrId = args.layout.blockTableRecordId;
187
+ });
188
+ _this._missedImages = new Map();
189
+ _this._layoutViewManager = new AcTrLayoutViewManager();
190
+ _this.initialize();
191
+ _this.onWindowResize();
192
+ _this.animate();
193
+ _this._isDirty = true;
194
+ _this._numOfEntitiesToProcess = 0;
195
+ return _this;
196
+ }
197
+ /**
198
+ * Initializes the viewer after renderer and camera are created.
199
+ *
200
+ * This method sets up the initial cursor and can be overridden by child classes
201
+ * to add custom initialization logic.
202
+ *
203
+ * @protected
204
+ */
205
+ AcTrView2d.prototype.initialize = function () {
206
+ // This method is called after camera and render are created.
207
+ // Children class can override this method to add its own logic
208
+ this.setCursor(AcEdCorsorType.Crosshair);
209
+ };
210
+ Object.defineProperty(AcTrView2d.prototype, "mode", {
211
+ /**
212
+ * Gets the current view mode (selection or pan).
213
+ *
214
+ * @returns The current view mode
215
+ * @inheritdoc
216
+ */
217
+ get: function () {
218
+ var activeLayoutView = this.activeLayoutView;
219
+ return activeLayoutView ? activeLayoutView.mode : AcEdViewMode.SELECTION;
220
+ },
221
+ /**
222
+ * Sets the view mode (selection or pan).
223
+ *
224
+ * @param value - The view mode to set
225
+ */
226
+ set: function (value) {
227
+ this.activeLayoutView.mode = value;
228
+ this.editor.getPoint();
229
+ },
230
+ enumerable: false,
231
+ configurable: true
232
+ });
233
+ Object.defineProperty(AcTrView2d.prototype, "renderer", {
234
+ /**
235
+ * Gets the Three.js renderer wrapper used for CAD rendering.
236
+ *
237
+ * @returns The renderer instance
238
+ */
239
+ get: function () {
240
+ return this._renderer;
241
+ },
242
+ enumerable: false,
243
+ configurable: true
244
+ });
245
+ Object.defineProperty(AcTrView2d.prototype, "isDirty", {
246
+ /**
247
+ * Gets whether the view needs to be re-rendered.
248
+ *
249
+ * @returns True if the view is dirty and needs re-rendering
250
+ */
251
+ get: function () {
252
+ return this._isDirty;
253
+ },
254
+ /**
255
+ * Sets whether the view needs to be re-rendered.
256
+ *
257
+ * @param value - True to mark the view as needing re-rendering
258
+ */
259
+ set: function (value) {
260
+ this._isDirty = value;
261
+ },
262
+ enumerable: false,
263
+ configurable: true
264
+ });
265
+ Object.defineProperty(AcTrView2d.prototype, "missedData", {
266
+ /**
267
+ * Gets information about missing data during rendering (fonts and images).
268
+ *
269
+ * @returns Object containing maps of missing fonts and images
270
+ */
271
+ get: function () {
272
+ return {
273
+ fonts: this._renderer.missedFonts,
274
+ images: this._missedImages
275
+ };
276
+ },
277
+ enumerable: false,
278
+ configurable: true
279
+ });
280
+ Object.defineProperty(AcTrView2d.prototype, "center", {
281
+ get: function () {
282
+ return this.activeLayoutView.center;
283
+ },
284
+ set: function (value) {
285
+ this.activeLayoutView.center = value;
286
+ },
287
+ enumerable: false,
288
+ configurable: true
289
+ });
290
+ Object.defineProperty(AcTrView2d.prototype, "backgroundColor", {
291
+ /**
292
+ * Gets the background color of the view.
293
+ *
294
+ * The color is represented as a 24-bit hexadecimal RGB number, e.g.,
295
+ * `0x000000` for black.
296
+ */
297
+ get: function () {
298
+ return this._renderer.getClearColor();
299
+ },
300
+ /**
301
+ * Sets the background color of the view.
302
+ *
303
+ * @param value - The background color as a 24-bit hexadecimal RGB number
304
+ */
305
+ set: function (value) {
306
+ this._renderer.setClearColor(value);
307
+ this._isDirty = true;
308
+ },
309
+ enumerable: false,
310
+ configurable: true
311
+ });
312
+ Object.defineProperty(AcTrView2d.prototype, "modelSpaceBtrId", {
313
+ /**
314
+ * The block table record id of the model space
315
+ */
316
+ get: function () {
317
+ return this._scene.modelSpaceBtrId;
318
+ },
319
+ set: function (value) {
320
+ this._scene.modelSpaceBtrId = value;
321
+ },
322
+ enumerable: false,
323
+ configurable: true
324
+ });
325
+ Object.defineProperty(AcTrView2d.prototype, "activeLayoutBtrId", {
326
+ /**
327
+ * The block table record id associated with the active layout
328
+ */
329
+ get: function () {
330
+ return this._scene.activeLayoutBtrId;
331
+ },
332
+ set: function (value) {
333
+ this._layoutViewManager.activeLayoutBtrId = value;
334
+ this._scene.activeLayoutBtrId = value;
335
+ this._isDirty = true;
336
+ },
337
+ enumerable: false,
338
+ configurable: true
339
+ });
340
+ Object.defineProperty(AcTrView2d.prototype, "activeLayoutView", {
341
+ /**
342
+ * The active layout view
343
+ */
344
+ get: function () {
345
+ return this._layoutViewManager.activeLayoutView;
346
+ },
347
+ enumerable: false,
348
+ configurable: true
349
+ });
350
+ Object.defineProperty(AcTrView2d.prototype, "stats", {
351
+ /**
352
+ * The statistics of the current scene
353
+ */
354
+ get: function () {
355
+ return this._scene.stats;
356
+ },
357
+ enumerable: false,
358
+ configurable: true
359
+ });
360
+ AcTrView2d.prototype.animate = function () {
361
+ var _a;
362
+ requestAnimationFrame(this.animate.bind(this));
363
+ if (this._isDirty) {
364
+ this._layoutViewManager.render(this._scene);
365
+ (_a = this._stats) === null || _a === void 0 ? void 0 : _a.update();
366
+ this._isDirty = false;
367
+ }
368
+ };
369
+ /**
370
+ * @inheritdoc
371
+ */
372
+ AcTrView2d.prototype.cwcs2Wcs = function (point) {
373
+ var activeLayoutView = this.activeLayoutView;
374
+ return activeLayoutView
375
+ ? activeLayoutView.cwcs2Wcs(point)
376
+ : new AcGePoint2d(point);
377
+ };
378
+ /**
379
+ * @inheritdoc
380
+ */
381
+ AcTrView2d.prototype.wcs2Cwcs = function (point) {
382
+ var activeLayoutView = this.activeLayoutView;
383
+ return activeLayoutView
384
+ ? activeLayoutView.wcs2Cwcs(point)
385
+ : new AcGePoint2d(point);
386
+ };
387
+ /**
388
+ * @inheritdoc
389
+ */
390
+ AcTrView2d.prototype.zoomTo = function (box, margin) {
391
+ if (margin === void 0) { margin = 1.1; }
392
+ this.activeLayoutView.zoomTo(box, margin);
393
+ this._isDirty = true;
394
+ };
395
+ /**
396
+ * Re-render points with latest point style settings
397
+ * @param displayMode Input display mode of points
398
+ */
399
+ AcTrView2d.prototype.rerenderPoints = function (displayMode) {
400
+ var activeLayout = this._scene.activeLayout;
401
+ if (activeLayout) {
402
+ activeLayout.rerenderPoints(displayMode);
403
+ this._isDirty = true;
404
+ }
405
+ };
406
+ /**
407
+ * @inheritdoc
408
+ */
409
+ AcTrView2d.prototype.zoomToFit = function (timeout) {
410
+ var _this = this;
411
+ if (timeout === void 0) { timeout = 0; }
412
+ var waiter = new AcEdConditionWaiter(function () { return _this._numOfEntitiesToProcess <= 0; }, function () {
413
+ if (_this._scene.box) {
414
+ var box = AcTrGeometryUtil.threeBox3dToGeBox2d(_this._scene.box);
415
+ _this.zoomTo(box);
416
+ _this._isDirty = true;
417
+ }
418
+ }, 300, // check every 200 ms
419
+ timeout);
420
+ waiter.start();
421
+ };
422
+ /**
423
+ * @inheritdoc
424
+ */
425
+ AcTrView2d.prototype.pick = function (point) {
426
+ if (point == null)
427
+ point = this.curPos;
428
+ var results = [];
429
+ var activeLayout = this._scene.activeLayout;
430
+ if (activeLayout) {
431
+ var activeLayoutView = this.activeLayoutView;
432
+ var box = activeLayoutView.pointToBox(point, this.selectionBoxSize);
433
+ var firstQueryResults = this._scene.search(box);
434
+ var threshold = Math.max(box.size.width / 2, box.size.height / 2);
435
+ var raycaster_1 = activeLayoutView.resetRaycaster(point, threshold);
436
+ firstQueryResults.forEach(function (item) {
437
+ var objectId = item.id;
438
+ if (activeLayout.isIntersectWith(objectId, raycaster_1)) {
439
+ results.push(objectId);
440
+ }
441
+ });
442
+ }
443
+ return results;
444
+ };
445
+ /**
446
+ * @inheritdoc
447
+ */
448
+ AcTrView2d.prototype.search = function (box) {
449
+ return this._scene.search(box);
450
+ };
451
+ /**
452
+ * @inheritdoc
453
+ */
454
+ AcTrView2d.prototype.select = function (point) {
455
+ var idsAdded = [];
456
+ var results = this.pick(point);
457
+ results.forEach(function (id) { return idsAdded.push(id); });
458
+ if (idsAdded.length > 0)
459
+ this.selectionSet.add(idsAdded);
460
+ };
461
+ /**
462
+ * @inheritdoc
463
+ */
464
+ AcTrView2d.prototype.selectByBox = function (box) {
465
+ var idsAdded = [];
466
+ var results = this._scene.search(box);
467
+ results.forEach(function (item) { return idsAdded.push(item.id); });
468
+ this.selectionSet.add(idsAdded);
469
+ };
470
+ /**
471
+ * @inheritdoc
472
+ */
473
+ AcTrView2d.prototype.addLayer = function (layer) {
474
+ this._scene.addLayer({
475
+ name: layer.name,
476
+ isFrozen: layer.isFrozen,
477
+ isOff: layer.isOff
478
+ });
479
+ this._isDirty = true;
480
+ };
481
+ /**
482
+ * @inheritdoc
483
+ */
484
+ AcTrView2d.prototype.updateLayer = function (layer) {
485
+ this._scene.updateLayer({
486
+ name: layer.name,
487
+ isFrozen: layer.isFrozen,
488
+ isOff: layer.isOff
489
+ });
490
+ this._isDirty = true;
491
+ };
492
+ /**
493
+ * @inheritdoc
494
+ */
495
+ AcTrView2d.prototype.addEntity = function (entity) {
496
+ var _this = this;
497
+ var entities = Array.isArray(entity) ? entity : [entity];
498
+ this._numOfEntitiesToProcess += entities.length;
499
+ setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
500
+ return __generator(this, function (_a) {
501
+ switch (_a.label) {
502
+ case 0: return [4 /*yield*/, this.batchConvert(entities)];
503
+ case 1:
504
+ _a.sent();
505
+ return [2 /*return*/];
506
+ }
507
+ });
508
+ }); });
509
+ };
510
+ /**
511
+ * Remove the specified entity from this view.
512
+ * @param objectId Input the object id of the entity to remove
513
+ */
514
+ AcTrView2d.prototype.removeEntity = function (objectId) {
515
+ this._scene.remove(objectId);
516
+ };
517
+ /**
518
+ * @inheritdoc
519
+ */
520
+ AcTrView2d.prototype.updateEntity = function (entity) {
521
+ var _this = this;
522
+ var entities = [];
523
+ if (Array.isArray(entity)) {
524
+ entities = entity;
525
+ }
526
+ else {
527
+ entities.push(entity);
528
+ }
529
+ for (var i = 0; i < entities.length; ++i) {
530
+ var entity_1 = entities[i];
531
+ var threeEntity = entity_1.draw(this._renderer);
532
+ if (threeEntity) {
533
+ threeEntity.objectId = entity_1.objectId;
534
+ threeEntity.ownerId = entity_1.ownerId;
535
+ threeEntity.layerName = entity_1.layer;
536
+ threeEntity.visible = entity_1.visibility;
537
+ this._scene.update(threeEntity);
538
+ }
539
+ }
540
+ this._isDirty = true;
541
+ // Not sure why texture for image entity isn't updated even if 'isDirty' flag is already set to true.
542
+ // So add one timeout event to set 'isDirty' flag to true again to make it work
543
+ setTimeout(function () {
544
+ _this._isDirty = true;
545
+ }, 100);
546
+ };
547
+ /**
548
+ * @inheritdoc
549
+ */
550
+ AcTrView2d.prototype.addLayout = function (layout) {
551
+ this._scene.addEmptyLayout(layout.blockTableRecordId);
552
+ this.createLayoutViewIfNeeded(layout.blockTableRecordId);
553
+ this._isDirty = true;
554
+ };
555
+ /**
556
+ * @inheritdoc
557
+ */
558
+ AcTrView2d.prototype.clear = function () {
559
+ this._scene.clear();
560
+ this._isDirty = true;
561
+ this._missedImages.clear();
562
+ this._renderer.clearMissedFonts();
563
+ };
564
+ /**
565
+ * @inheritdoc
566
+ */
567
+ AcTrView2d.prototype.highlight = function (ids) {
568
+ this._isDirty = this._scene.select(ids);
569
+ };
570
+ /**
571
+ * @inheritdoc
572
+ */
573
+ AcTrView2d.prototype.unhighlight = function (ids) {
574
+ this._isDirty = this._scene.unselect(ids);
575
+ };
576
+ /**
577
+ * @inheritdoc
578
+ */
579
+ AcTrView2d.prototype.onHover = function (id) {
580
+ this._isDirty = this._scene.hover([id]);
581
+ };
582
+ /**
583
+ * @inheritdoc
584
+ */
585
+ AcTrView2d.prototype.onUnhover = function (id) {
586
+ this._isDirty = this._scene.unhover([id]);
587
+ };
588
+ AcTrView2d.prototype.createScene = function () {
589
+ var _this = this;
590
+ var scene = new AcTrScene();
591
+ scene.layouts.forEach(function (layout) {
592
+ layout.setSnapObject(_this.renderer.createObject());
593
+ });
594
+ return scene;
595
+ };
596
+ AcTrView2d.prototype.createStats = function (show) {
597
+ var stats = new Stats();
598
+ document.body.appendChild(stats.dom);
599
+ // Show Stats component at the right-bottom corner of the window
600
+ var statsDom = stats.dom;
601
+ statsDom.style.position = 'fixed';
602
+ statsDom.style.inset = 'unset';
603
+ statsDom.style.bottom = '30px';
604
+ statsDom.style.right = '0px';
605
+ this.toggleStatsVisibility(stats, show);
606
+ return stats;
607
+ };
608
+ AcTrView2d.prototype.onWindowResize = function () {
609
+ _super.prototype.onWindowResize.call(this);
610
+ this._renderer.setSize(this.width, this.height);
611
+ this._layoutViewManager.resize(this.width, this.height);
612
+ this._isDirty = true;
613
+ };
614
+ /**
615
+ * Create the layout view with the specified block table record id.
616
+ * @param layoutBtrId Input the block table record id associated with the layout view.
617
+ */
618
+ AcTrView2d.prototype.createLayoutViewIfNeeded = function (layoutBtrId) {
619
+ var _this = this;
620
+ var layoutView = this._layoutViewManager.getAt(layoutBtrId);
621
+ if (layoutView == null) {
622
+ layoutView = new AcTrLayoutView(this._renderer, layoutBtrId, this.width, this.height);
623
+ layoutView.events.viewChanged.addEventListener(function () {
624
+ _this._isDirty = true;
625
+ });
626
+ this._layoutViewManager.add(layoutView);
627
+ }
628
+ return layoutView;
629
+ };
630
+ /**
631
+ * Show or hide stats component
632
+ * @param show If it is true, show stats component. Otherwise, hide stats component.
633
+ * Default value is false.
634
+ */
635
+ AcTrView2d.prototype.toggleStatsVisibility = function (stats, show) {
636
+ if (show) {
637
+ stats.dom.style.display = 'block'; // Show the stats
638
+ }
639
+ else {
640
+ stats.dom.style.display = 'none'; // Hide the stats
641
+ }
642
+ };
643
+ /**
644
+ * Converts the specified database entities to three entities
645
+ * @param entities - The database entities
646
+ * @returns The converted three entities
647
+ */
648
+ AcTrView2d.prototype.batchConvert = function (entities) {
649
+ return __awaiter(this, void 0, void 0, function () {
650
+ var _loop_1, this_1, i;
651
+ var _this = this;
652
+ return __generator(this, function (_a) {
653
+ switch (_a.label) {
654
+ case 0:
655
+ _loop_1 = function (i) {
656
+ var entity, threeEntity, isExtendBbox_1, layoutView, viewportView, fileName;
657
+ return __generator(this, function (_b) {
658
+ switch (_b.label) {
659
+ case 0:
660
+ entity = entities[i];
661
+ threeEntity = entity.draw(this_1._renderer, true);
662
+ if (!threeEntity) return [3 /*break*/, 4];
663
+ threeEntity.objectId = entity.objectId;
664
+ threeEntity.ownerId = entity.ownerId;
665
+ threeEntity.layerName = entity.layer;
666
+ threeEntity.visible = entity.visibility;
667
+ if (!(threeEntity instanceof AcTrGroup &&
668
+ !threeEntity.isOnTheSameLayer)) return [3 /*break*/, 1];
669
+ this_1.handleGroup(threeEntity);
670
+ this_1.decreaseNumOfEntitiesToProcess();
671
+ return [3 /*break*/, 3];
672
+ case 1:
673
+ isExtendBbox_1 = !(entity instanceof AcDbRay || entity instanceof AcDbXline);
674
+ return [4 /*yield*/, threeEntity
675
+ .draw()
676
+ .then(function () {
677
+ _this._scene.addEntity(threeEntity, isExtendBbox_1);
678
+ // Release memory occupied by this entity
679
+ threeEntity.dispose();
680
+ _this._isDirty = true;
681
+ })
682
+ .finally(function () {
683
+ _this.decreaseNumOfEntitiesToProcess();
684
+ })];
685
+ case 2:
686
+ _b.sent();
687
+ _b.label = 3;
688
+ case 3:
689
+ if (entity instanceof AcDbViewport) {
690
+ // In paper space layouts, there is always a system-defined "default" viewport that exists as
691
+ // the bottom-most item. This viewport doesn't show any entities and is mainly for internal
692
+ // AutoCAD purposes. The viewport id number of this system-defined "default" viewport is 1.
693
+ if (entity.number > 1) {
694
+ layoutView = this_1._layoutViewManager.getAt(entity.ownerId);
695
+ if (layoutView) {
696
+ viewportView = new AcTrViewportView(layoutView, entity.toGiViewport(), this_1._renderer);
697
+ layoutView.addViewport(viewportView);
698
+ }
699
+ }
700
+ }
701
+ else if (entity instanceof AcDbRasterImage) {
702
+ fileName = entity.imageFileName;
703
+ if (fileName)
704
+ this_1._missedImages.set(entity.objectId, fileName);
705
+ }
706
+ return [3 /*break*/, 5];
707
+ case 4:
708
+ this_1.decreaseNumOfEntitiesToProcess();
709
+ _b.label = 5;
710
+ case 5: return [2 /*return*/];
711
+ }
712
+ });
713
+ };
714
+ this_1 = this;
715
+ i = 0;
716
+ _a.label = 1;
717
+ case 1:
718
+ if (!(i < entities.length)) return [3 /*break*/, 4];
719
+ return [5 /*yield**/, _loop_1(i)];
720
+ case 2:
721
+ _a.sent();
722
+ _a.label = 3;
723
+ case 3:
724
+ ++i;
725
+ return [3 /*break*/, 1];
726
+ case 4: return [2 /*return*/];
727
+ }
728
+ });
729
+ });
730
+ };
731
+ AcTrView2d.prototype.handleGroup = function (group) {
732
+ var _this = this;
733
+ var children = group.children;
734
+ var objectsGroupByLayer = new Map();
735
+ children.forEach(function (child) {
736
+ var _a;
737
+ var layerName = child.userData.layerName;
738
+ if (!objectsGroupByLayer.has(layerName)) {
739
+ objectsGroupByLayer.set(layerName, []);
740
+ }
741
+ (_a = objectsGroupByLayer.get(layerName)) === null || _a === void 0 ? void 0 : _a.push(child);
742
+ });
743
+ var styleManager = group.styleManager;
744
+ var groupObjectId = group.objectId;
745
+ var groupLayerName = group.layerName;
746
+ var groupBox = group.box;
747
+ objectsGroupByLayer.forEach(function (objects, layerName) {
748
+ var entity = new AcTrEntity(styleManager);
749
+ entity.applyMatrix4(group.matrix);
750
+ entity.objectId = groupObjectId;
751
+ entity.ownerId = group.ownerId;
752
+ // Here one group represents one block reference. If the layer name of entities in block
753
+ // definition is '0', it should be put on layer where the group exist.
754
+ entity.layerName = layerName === '0' ? groupLayerName : layerName;
755
+ entity.box = groupBox;
756
+ entity.add.apply(entity, __spreadArray([], __read(objects), false));
757
+ _this._scene.addEntity(entity, true);
758
+ entity.dispose();
759
+ });
760
+ this._isDirty = true;
761
+ };
762
+ AcTrView2d.prototype.decreaseNumOfEntitiesToProcess = function () {
763
+ this._numOfEntitiesToProcess--;
764
+ if (this._numOfEntitiesToProcess < 0) {
765
+ this._numOfEntitiesToProcess = 0;
766
+ console.warn('Something wrong! The number of entities to process should not be less than 0.');
767
+ }
768
+ };
769
+ return AcTrView2d;
770
+ }(AcEdBaseView));
771
+ export { AcTrView2d };
772
+ //# sourceMappingURL=AcTrView2d.js.map