@mlightcad/cad-simple-viewer 1.4.12 → 1.4.13

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 (160) hide show
  1. package/dist/index.js +15901 -10590
  2. package/dist/index.umd.cjs +55 -48
  3. package/dist/libredwg-parser-worker.js +4724 -4762
  4. package/lib/app/AcApDocManager.d.ts +60 -4
  5. package/lib/app/AcApDocManager.d.ts.map +1 -1
  6. package/lib/app/AcApDocManager.js +160 -33
  7. package/lib/app/AcApDocManager.js.map +1 -1
  8. package/lib/command/AcApArcCmd.d.ts.map +1 -1
  9. package/lib/command/AcApArcCmd.js +1 -1
  10. package/lib/command/AcApArcCmd.js.map +1 -1
  11. package/lib/command/AcApCircleCmd.d.ts +59 -0
  12. package/lib/command/AcApCircleCmd.d.ts.map +1 -1
  13. package/lib/command/AcApCircleCmd.js +489 -18
  14. package/lib/command/AcApCircleCmd.js.map +1 -1
  15. package/lib/command/AcApConvertToPngCmd.d.ts +35 -0
  16. package/lib/command/AcApConvertToPngCmd.d.ts.map +1 -0
  17. package/lib/command/{AcApZoomToBoxCmd.js → AcApConvertToPngCmd.js} +50 -26
  18. package/lib/command/AcApConvertToPngCmd.js.map +1 -0
  19. package/lib/command/AcApEllipseCmd.d.ts +87 -0
  20. package/lib/command/AcApEllipseCmd.d.ts.map +1 -0
  21. package/lib/command/AcApEllipseCmd.js +583 -0
  22. package/lib/command/AcApEllipseCmd.js.map +1 -0
  23. package/lib/command/AcApHatchCmd.d.ts +210 -0
  24. package/lib/command/AcApHatchCmd.d.ts.map +1 -0
  25. package/lib/command/AcApHatchCmd.js +808 -0
  26. package/lib/command/AcApHatchCmd.js.map +1 -0
  27. package/lib/command/AcApLayerCmd.d.ts +217 -0
  28. package/lib/command/AcApLayerCmd.d.ts.map +1 -0
  29. package/lib/command/AcApLayerCmd.js +768 -0
  30. package/lib/command/AcApLayerCmd.js.map +1 -0
  31. package/lib/command/AcApLineCmd.d.ts +36 -1
  32. package/lib/command/AcApLineCmd.d.ts.map +1 -1
  33. package/lib/command/AcApLineCmd.js +157 -20
  34. package/lib/command/AcApLineCmd.js.map +1 -1
  35. package/lib/command/AcApMeasureAreaCmd.d.ts.map +1 -1
  36. package/lib/command/AcApMeasureAreaCmd.js +3 -0
  37. package/lib/command/AcApMeasureAreaCmd.js.map +1 -1
  38. package/lib/command/AcApMoveCmd.d.ts +16 -0
  39. package/lib/command/AcApMoveCmd.d.ts.map +1 -0
  40. package/lib/command/AcApMoveCmd.js +278 -0
  41. package/lib/command/AcApMoveCmd.js.map +1 -0
  42. package/lib/command/AcApPngConvertor.d.ts +95 -0
  43. package/lib/command/AcApPngConvertor.d.ts.map +1 -0
  44. package/lib/command/AcApPngConvertor.js +205 -0
  45. package/lib/command/AcApPngConvertor.js.map +1 -0
  46. package/lib/command/AcApPolygonCmd.d.ts +69 -0
  47. package/lib/command/AcApPolygonCmd.d.ts.map +1 -0
  48. package/lib/command/AcApPolygonCmd.js +422 -0
  49. package/lib/command/AcApPolygonCmd.js.map +1 -0
  50. package/lib/command/AcApRectCmd.d.ts +149 -4
  51. package/lib/command/AcApRectCmd.d.ts.map +1 -1
  52. package/lib/command/AcApRectCmd.js +716 -34
  53. package/lib/command/AcApRectCmd.js.map +1 -1
  54. package/lib/command/AcApRevCircleCmd.d.ts +8 -0
  55. package/lib/command/AcApRevCircleCmd.d.ts.map +1 -1
  56. package/lib/command/AcApRevCircleCmd.js +30 -6
  57. package/lib/command/AcApRevCircleCmd.js.map +1 -1
  58. package/lib/command/AcApRevRectCmd.d.ts +8 -0
  59. package/lib/command/AcApRevRectCmd.d.ts.map +1 -1
  60. package/lib/command/AcApRevRectCmd.js +78 -6
  61. package/lib/command/AcApRevRectCmd.js.map +1 -1
  62. package/lib/command/AcApSplineCmd.d.ts +66 -1
  63. package/lib/command/AcApSplineCmd.d.ts.map +1 -1
  64. package/lib/command/AcApSplineCmd.js +466 -59
  65. package/lib/command/AcApSplineCmd.js.map +1 -1
  66. package/lib/command/AcApZoomCmd.d.ts +91 -20
  67. package/lib/command/AcApZoomCmd.d.ts.map +1 -1
  68. package/lib/command/AcApZoomCmd.js +288 -23
  69. package/lib/command/AcApZoomCmd.js.map +1 -1
  70. package/lib/command/index.d.ts +7 -1
  71. package/lib/command/index.d.ts.map +1 -1
  72. package/lib/command/index.js +7 -1
  73. package/lib/command/index.js.map +1 -1
  74. package/lib/editor/command/AcEdCommandStack.d.ts +54 -1
  75. package/lib/editor/command/AcEdCommandStack.d.ts.map +1 -1
  76. package/lib/editor/command/AcEdCommandStack.js +207 -25
  77. package/lib/editor/command/AcEdCommandStack.js.map +1 -1
  78. package/lib/editor/input/AcEdSelectionFilter.d.ts +79 -0
  79. package/lib/editor/input/AcEdSelectionFilter.d.ts.map +1 -0
  80. package/lib/editor/input/AcEdSelectionFilter.js +231 -0
  81. package/lib/editor/input/AcEdSelectionFilter.js.map +1 -0
  82. package/lib/editor/input/AcEditor.d.ts +20 -2
  83. package/lib/editor/input/AcEditor.d.ts.map +1 -1
  84. package/lib/editor/input/AcEditor.js +66 -0
  85. package/lib/editor/input/AcEditor.js.map +1 -1
  86. package/lib/editor/input/index.d.ts +1 -0
  87. package/lib/editor/input/index.d.ts.map +1 -1
  88. package/lib/editor/input/index.js +1 -0
  89. package/lib/editor/input/index.js.map +1 -1
  90. package/lib/editor/input/prompt/AcEdKeywordCollection.d.ts +47 -0
  91. package/lib/editor/input/prompt/AcEdKeywordCollection.d.ts.map +1 -1
  92. package/lib/editor/input/prompt/AcEdKeywordCollection.js +19 -0
  93. package/lib/editor/input/prompt/AcEdKeywordCollection.js.map +1 -1
  94. package/lib/editor/input/prompt/AcEdPromptAngleOptions.d.ts +7 -0
  95. package/lib/editor/input/prompt/AcEdPromptAngleOptions.d.ts.map +1 -1
  96. package/lib/editor/input/prompt/AcEdPromptAngleOptions.js +17 -0
  97. package/lib/editor/input/prompt/AcEdPromptAngleOptions.js.map +1 -1
  98. package/lib/editor/input/prompt/AcEdPromptEntityOptions.d.ts +17 -0
  99. package/lib/editor/input/prompt/AcEdPromptEntityOptions.d.ts.map +1 -1
  100. package/lib/editor/input/prompt/AcEdPromptEntityOptions.js +30 -3
  101. package/lib/editor/input/prompt/AcEdPromptEntityOptions.js.map +1 -1
  102. package/lib/editor/input/prompt/AcEdPromptOptions.d.ts +6 -1
  103. package/lib/editor/input/prompt/AcEdPromptOptions.d.ts.map +1 -1
  104. package/lib/editor/input/prompt/AcEdPromptOptions.js +7 -0
  105. package/lib/editor/input/prompt/AcEdPromptOptions.js.map +1 -1
  106. package/lib/editor/input/session/AcEdKeywordSession.d.ts +65 -0
  107. package/lib/editor/input/session/AcEdKeywordSession.d.ts.map +1 -1
  108. package/lib/editor/input/session/AcEdKeywordSession.js +71 -0
  109. package/lib/editor/input/session/AcEdKeywordSession.js.map +1 -1
  110. package/lib/editor/input/ui/AcEdCommandLine.d.ts +23 -0
  111. package/lib/editor/input/ui/AcEdCommandLine.d.ts.map +1 -1
  112. package/lib/editor/input/ui/AcEdCommandLine.js +42 -6
  113. package/lib/editor/input/ui/AcEdCommandLine.js.map +1 -1
  114. package/lib/editor/input/ui/AcEdFloatingInput.d.ts +1 -0
  115. package/lib/editor/input/ui/AcEdFloatingInput.d.ts.map +1 -1
  116. package/lib/editor/input/ui/AcEdFloatingInput.js +8 -2
  117. package/lib/editor/input/ui/AcEdFloatingInput.js.map +1 -1
  118. package/lib/editor/input/ui/AcEdFloatingInputBoxes.d.ts +23 -1
  119. package/lib/editor/input/ui/AcEdFloatingInputBoxes.d.ts.map +1 -1
  120. package/lib/editor/input/ui/AcEdFloatingInputBoxes.js +32 -9
  121. package/lib/editor/input/ui/AcEdFloatingInputBoxes.js.map +1 -1
  122. package/lib/editor/input/ui/AcEdFloatingInputTypes.d.ts +28 -0
  123. package/lib/editor/input/ui/AcEdFloatingInputTypes.d.ts.map +1 -1
  124. package/lib/editor/input/ui/AcEdInputManager.d.ts +356 -16
  125. package/lib/editor/input/ui/AcEdInputManager.d.ts.map +1 -1
  126. package/lib/editor/input/ui/AcEdInputManager.js +964 -529
  127. package/lib/editor/input/ui/AcEdInputManager.js.map +1 -1
  128. package/lib/editor/input/ui/AcEdRubberBand.d.ts +15 -1
  129. package/lib/editor/input/ui/AcEdRubberBand.d.ts.map +1 -1
  130. package/lib/editor/input/ui/AcEdRubberBand.js +42 -10
  131. package/lib/editor/input/ui/AcEdRubberBand.js.map +1 -1
  132. package/lib/i18n/en/command.d.ts +21 -3
  133. package/lib/i18n/en/command.d.ts.map +1 -1
  134. package/lib/i18n/en/command.js +21 -3
  135. package/lib/i18n/en/command.js.map +1 -1
  136. package/lib/i18n/en/jig.d.ts +443 -0
  137. package/lib/i18n/en/jig.d.ts.map +1 -1
  138. package/lib/i18n/en/jig.js +452 -9
  139. package/lib/i18n/en/jig.js.map +1 -1
  140. package/lib/i18n/zh/command.d.ts +21 -3
  141. package/lib/i18n/zh/command.d.ts.map +1 -1
  142. package/lib/i18n/zh/command.js +21 -3
  143. package/lib/i18n/zh/command.js.map +1 -1
  144. package/lib/i18n/zh/jig.d.ts +443 -0
  145. package/lib/i18n/zh/jig.d.ts.map +1 -1
  146. package/lib/i18n/zh/jig.js +452 -9
  147. package/lib/i18n/zh/jig.js.map +1 -1
  148. package/lib/plugin/AcApPluginManager.d.ts.map +1 -1
  149. package/lib/plugin/AcApPluginManager.js.map +1 -1
  150. package/lib/view/AcTrLayer.d.ts.map +1 -1
  151. package/lib/view/AcTrLayer.js +5 -3
  152. package/lib/view/AcTrLayer.js.map +1 -1
  153. package/lib/view/AcTrView2d.d.ts +0 -1
  154. package/lib/view/AcTrView2d.d.ts.map +1 -1
  155. package/lib/view/AcTrView2d.js +17 -4
  156. package/lib/view/AcTrView2d.js.map +1 -1
  157. package/package.json +11 -9
  158. package/lib/command/AcApZoomToBoxCmd.d.ts +0 -29
  159. package/lib/command/AcApZoomToBoxCmd.d.ts.map +0 -1
  160. package/lib/command/AcApZoomToBoxCmd.js.map +0 -1
@@ -0,0 +1,278 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ 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);
27
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
+ 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;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ import { AcGeMatrix3d, AcGePoint3d } from '@mlightcad/data-model';
53
+ import { AcApAnnotation, AcApDocManager } from '../app';
54
+ import { AcEdCommand } from '../command';
55
+ import { AcEdOpenMode, AcEdPreviewJig, AcEdPromptPointOptions, AcEdPromptSelectionOptions, AcEdPromptStateMachine, AcEdPromptStatus } from '../editor';
56
+ import { AcApI18n } from '../i18n';
57
+ /**
58
+ * MOVE preview jig.
59
+ *
60
+ * It clones source entities once in memory and updates those clones by
61
+ * incremental translations during mouse move, so the database entities are
62
+ * untouched until command commit.
63
+ */
64
+ var AcApMovePreviewJig = /** @class */ (function (_super) {
65
+ __extends(AcApMovePreviewJig, _super);
66
+ function AcApMovePreviewJig(view, sourceEntities, basePoint) {
67
+ var _this = _super.call(this, view) || this;
68
+ _this._view = view;
69
+ _this._basePoint = new AcGePoint3d(basePoint);
70
+ _this._lastDisplacement = new AcGePoint3d(0, 0, 0);
71
+ _this._previewEntities = sourceEntities
72
+ .map(function (entity) { return _this.cloneEntity(entity); })
73
+ .filter(function (entity) { return !!entity; });
74
+ return _this;
75
+ }
76
+ Object.defineProperty(AcApMovePreviewJig.prototype, "entity", {
77
+ get: function () {
78
+ var _a;
79
+ return (_a = this._previewEntities[0]) !== null && _a !== void 0 ? _a : null;
80
+ },
81
+ enumerable: false,
82
+ configurable: true
83
+ });
84
+ AcApMovePreviewJig.prototype.update = function (point) {
85
+ if (this._previewEntities.length === 0)
86
+ return;
87
+ var displacement = new AcGePoint3d(point.x - this._basePoint.x, point.y - this._basePoint.y, point.z - this._basePoint.z);
88
+ var delta = new AcGePoint3d(displacement.x - this._lastDisplacement.x, displacement.y - this._lastDisplacement.y, displacement.z - this._lastDisplacement.z);
89
+ var hasDelta = delta.x !== 0 || delta.y !== 0 || delta.z !== 0;
90
+ if (!hasDelta)
91
+ return;
92
+ var matrix = new AcGeMatrix3d().makeTranslation(delta.x, delta.y, delta.z);
93
+ this._previewEntities.forEach(function (entity) { return entity.transformBy(matrix); });
94
+ this._lastDisplacement = displacement;
95
+ };
96
+ AcApMovePreviewJig.prototype.render = function () {
97
+ if (this._previewEntities.length === 0)
98
+ return;
99
+ this._view.addTransientEntity(this._previewEntities);
100
+ };
101
+ AcApMovePreviewJig.prototype.end = function () {
102
+ var _this = this;
103
+ this._previewEntities.forEach(function (entity) {
104
+ return _this._view.removeTransientEntity(entity.objectId);
105
+ });
106
+ };
107
+ AcApMovePreviewJig.prototype.cloneEntity = function (entity) {
108
+ return entity.clone();
109
+ };
110
+ return AcApMovePreviewJig;
111
+ }(AcEdPreviewJig));
112
+ /**
113
+ * Command to move selected entities by a displacement vector.
114
+ *
115
+ * Behavior (AutoCAD-like):
116
+ * 1) Select entities (or reuse preselection),
117
+ * 2) Specify base point or choose `Displacement`,
118
+ * 3) Specify second point (or displacement point),
119
+ * 4) Apply translation to all selected entities.
120
+ */
121
+ var AcApMoveCmd = /** @class */ (function (_super) {
122
+ __extends(AcApMoveCmd, _super);
123
+ function AcApMoveCmd() {
124
+ var _this = _super.call(this) || this;
125
+ _this.mode = AcEdOpenMode.Review;
126
+ return _this;
127
+ }
128
+ AcApMoveCmd.prototype.execute = function (context) {
129
+ return __awaiter(this, void 0, void 0, function () {
130
+ var selectionSet, annotation, blockTable, selectionIds, _a, ids, sourceEntities, basePoint, displacement, createDisplacementKeyword, BasePointState, SecondPointState, DisplacementState, machine, matrix;
131
+ var _b, _c;
132
+ return __generator(this, function (_d) {
133
+ switch (_d.label) {
134
+ case 0:
135
+ selectionSet = context.view.selectionSet;
136
+ annotation = new AcApAnnotation(context.doc.database);
137
+ blockTable = context.doc.database.tables.blockTable;
138
+ if (!(selectionSet.count > 0)) return [3 /*break*/, 1];
139
+ _a = selectionSet.ids;
140
+ return [3 /*break*/, 3];
141
+ case 1: return [4 /*yield*/, AcApDocManager.instance.editor.getSelection(new AcEdPromptSelectionOptions(AcApI18n.sysCmdPrompt('move')))];
142
+ case 2:
143
+ _a = ((_c = (_b = (_d.sent()).value) === null || _b === void 0 ? void 0 : _b.ids) !== null && _c !== void 0 ? _c : []);
144
+ _d.label = 3;
145
+ case 3:
146
+ selectionIds = _a;
147
+ if (selectionIds.length === 0)
148
+ return [2 /*return*/];
149
+ ids = context.doc.openMode == AcEdOpenMode.Review
150
+ ? annotation.filterAnnotationEntities(selectionIds)
151
+ : selectionIds;
152
+ if (ids.length === 0) {
153
+ selectionSet.clear();
154
+ return [2 /*return*/];
155
+ }
156
+ sourceEntities = ids
157
+ .map(function (id) { return blockTable.getEntityById(id); })
158
+ .filter(function (entity) { return !!entity; });
159
+ if (sourceEntities.length === 0) {
160
+ selectionSet.clear();
161
+ return [2 /*return*/];
162
+ }
163
+ createDisplacementKeyword = function (prompt) {
164
+ prompt.keywords.add(AcApI18n.t('jig.move.keywords.displacement.display'), AcApI18n.t('jig.move.keywords.displacement.global'), AcApI18n.t('jig.move.keywords.displacement.local'));
165
+ };
166
+ BasePointState = /** @class */ (function () {
167
+ function BasePointState(machine) {
168
+ this.machine = machine;
169
+ }
170
+ BasePointState.prototype.buildPrompt = function () {
171
+ var prompt = new AcEdPromptPointOptions(AcApI18n.t('jig.move.basePointOrDisplacement'));
172
+ createDisplacementKeyword(prompt);
173
+ return prompt;
174
+ };
175
+ BasePointState.prototype.handleResult = function (result) {
176
+ return __awaiter(this, void 0, void 0, function () {
177
+ return __generator(this, function (_a) {
178
+ if (result.status === AcEdPromptStatus.OK) {
179
+ basePoint = new AcGePoint3d(result.value);
180
+ this.machine.setState(new SecondPointState(this.machine));
181
+ return [2 /*return*/, 'continue'];
182
+ }
183
+ if (result.status === AcEdPromptStatus.Keyword &&
184
+ result.stringResult === 'Displacement') {
185
+ this.machine.setState(new DisplacementState());
186
+ return [2 /*return*/, 'continue'];
187
+ }
188
+ return [2 /*return*/, 'finish'];
189
+ });
190
+ });
191
+ };
192
+ return BasePointState;
193
+ }());
194
+ SecondPointState = /** @class */ (function () {
195
+ function SecondPointState(machine) {
196
+ this.machine = machine;
197
+ }
198
+ SecondPointState.prototype.buildPrompt = function () {
199
+ var prompt = new AcEdPromptPointOptions(AcApI18n.t('jig.move.secondPointOrDisplacement'));
200
+ createDisplacementKeyword(prompt);
201
+ if (basePoint) {
202
+ prompt.useBasePoint = true;
203
+ prompt.useDashedLine = true;
204
+ prompt.basePoint = basePoint;
205
+ prompt.jig = new AcApMovePreviewJig(context.view, sourceEntities, basePoint);
206
+ }
207
+ return prompt;
208
+ };
209
+ SecondPointState.prototype.handleResult = function (result) {
210
+ return __awaiter(this, void 0, void 0, function () {
211
+ var secondPoint;
212
+ return __generator(this, function (_a) {
213
+ if (result.status === AcEdPromptStatus.OK && basePoint) {
214
+ secondPoint = new AcGePoint3d(result.value);
215
+ displacement = new AcGePoint3d(secondPoint.x - basePoint.x, secondPoint.y - basePoint.y, secondPoint.z - basePoint.z);
216
+ return [2 /*return*/, 'finish'];
217
+ }
218
+ if (result.status === AcEdPromptStatus.Keyword &&
219
+ result.stringResult === 'Displacement') {
220
+ this.machine.setState(new DisplacementState());
221
+ return [2 /*return*/, 'continue'];
222
+ }
223
+ return [2 /*return*/, 'finish'];
224
+ });
225
+ });
226
+ };
227
+ return SecondPointState;
228
+ }());
229
+ DisplacementState = /** @class */ (function () {
230
+ function DisplacementState() {
231
+ }
232
+ DisplacementState.prototype.buildPrompt = function () {
233
+ var prompt = new AcEdPromptPointOptions(AcApI18n.t('jig.move.displacement'));
234
+ prompt.useBasePoint = true;
235
+ prompt.useDashedLine = true;
236
+ prompt.basePoint = new AcGePoint3d(0, 0, 0);
237
+ prompt.jig = new AcApMovePreviewJig(context.view, sourceEntities, prompt.basePoint);
238
+ return prompt;
239
+ };
240
+ DisplacementState.prototype.handleResult = function (result) {
241
+ return __awaiter(this, void 0, void 0, function () {
242
+ return __generator(this, function (_a) {
243
+ if (result.status === AcEdPromptStatus.OK) {
244
+ displacement = new AcGePoint3d(result.value);
245
+ }
246
+ return [2 /*return*/, 'finish'];
247
+ });
248
+ });
249
+ };
250
+ return DisplacementState;
251
+ }());
252
+ machine = new AcEdPromptStateMachine();
253
+ machine.setState(new BasePointState(machine));
254
+ return [4 /*yield*/, machine.run(function (prompt) { return AcApDocManager.instance.editor.getPoint(prompt); })];
255
+ case 4:
256
+ _d.sent();
257
+ if (!displacement) {
258
+ selectionSet.clear();
259
+ return [2 /*return*/];
260
+ }
261
+ matrix = new AcGeMatrix3d().makeTranslation(displacement.x, displacement.y, displacement.z);
262
+ ids.forEach(function (id) {
263
+ var entity = blockTable.getEntityById(id);
264
+ if (!entity)
265
+ return;
266
+ entity.transformBy(matrix);
267
+ entity.triggerModifiedEvent();
268
+ });
269
+ selectionSet.clear();
270
+ return [2 /*return*/];
271
+ }
272
+ });
273
+ });
274
+ };
275
+ return AcApMoveCmd;
276
+ }(AcEdCommand));
277
+ export { AcApMoveCmd };
278
+ //# sourceMappingURL=AcApMoveCmd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcApMoveCmd.js","sourceRoot":"","sources":["../../src/command/AcApMoveCmd.ts"],"names":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CAAA;wBAC7C,qBAAM,OAAO,CAAC,GAAG,CAAC,UAAA,MAAM,IAAI,OAAA,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAA/C,CAA+C,CAAC,EAAA;;wBAA5E,SAA4E,CAAA;wBAE5E,IAAI,CAAC,YAAY,EAAE,CAAC;4BAClB,YAAY,CAAC,KAAK,EAAE,CAAA;4BACpB,sBAAM;wBACR,CAAC;wBAEK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC,eAAe,CAC/C,YAAY,CAAC,CAAC,EACd,YAAY,CAAC,CAAC,EACd,YAAY,CAAC,CAAC,CACf,CAAA;wBACD,GAAG,CAAC,OAAO,CAAC,UAAA,EAAE;4BACZ,IAAM,MAAM,GAAG,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC,CAAA;4BAC3C,IAAI,CAAC,MAAM;gCAAE,OAAM;4BACnB,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;4BAC1B,MAAM,CAAC,oBAAoB,EAAE,CAAA;wBAC/B,CAAC,CAAC,CAAA;wBACF,YAAY,CAAC,KAAK,EAAE,CAAA;;;;;KACrB;IACH,kBAAC;AAAD,CAAC,AAvLD,CAAiC,WAAW,GAuL3C"}
@@ -0,0 +1,95 @@
1
+ import { AcGeBox2d } from '@mlightcad/data-model';
2
+ /**
3
+ * Utility class for converting CAD drawings to PNG format.
4
+ *
5
+ * This class provides functionality to export the current CAD drawing
6
+ * to PNG format and download it as a file. It renders the current view
7
+ * using WebGLRenderTarget for optimal performance without requiring
8
+ * preserveDrawingBuffer to be enabled on the renderer.
9
+ *
10
+ * The conversion process:
11
+ * 1. Gets the current view and its associated renderer, scene, and camera
12
+ * 2. Creates an offscreen render target for pixel capture
13
+ * 3. Renders the scene to the render target
14
+ * 4. Reads the pixel data and flips it vertically (WebGL renders upside down)
15
+ * 5. Creates a canvas, draws the pixel data, and exports as PNG
16
+ * 6. Triggers a download of the PNG file
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const converter = new AcApPngConvertor();
21
+ *
22
+ * // Convert and download current drawing as PNG
23
+ * converter.convert();
24
+ * ```
25
+ */
26
+ export declare class AcApPngConvertor {
27
+ /**
28
+ * Converts the current CAD drawing to PNG format and initiates download.
29
+ *
30
+ * This method:
31
+ * - Retrieves the current view, renderer, scene, and camera
32
+ * - Creates a WebGLRenderTarget for offscreen rendering
33
+ * - Renders the scene to the render target
34
+ * - Reads pixel data and flips it vertically to correct WebGL's upside-down rendering
35
+ * - Creates a canvas with the pixel data
36
+ * - Exports as PNG and downloads with timestamp-based filename
37
+ *
38
+ * @param bounds - Optional world coordinate bounding box to export.
39
+ * If provided, the camera will zoom to fit this region.
40
+ * If not provided, exports the current view.
41
+ * @param long_side - Optional maximum dimension (width or height) in pixels for the output PNG.
42
+ * The other dimension is calculated based on the aspect ratio of bounds.
43
+ * If not provided, uses the current view dimensions.
44
+ * @example
45
+ * ```typescript
46
+ * const converter = new AcApPngConvertor();
47
+ * converter.convert(); // Downloads the drawing as PNG
48
+ * ```
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // Export a specific region
53
+ * const bounds = new AcGeBox2d(new AcGePoint2d(0, 0), new AcGePoint2d(100, 100));
54
+ * const converter = new AcApPngConvertor();
55
+ * converter.convert(bounds); // Downloads the specified region as PNG
56
+ * ```
57
+ */
58
+ convert(bounds?: AcGeBox2d, long_side?: number): void;
59
+ /**
60
+ * Flips pixel data vertically to correct WebGL's upside-down rendering.
61
+ *
62
+ * WebGL renders images upside down (origin at bottom-left), so the pixel
63
+ * data needs to be flipped to display correctly in standard image viewers.
64
+ *
65
+ * @param pixels - The raw pixel data from WebGL render target
66
+ * @param width - Width of the image in pixels
67
+ * @param height - Height of the image in pixels
68
+ * @returns The vertically flipped pixel data
69
+ * @private
70
+ */
71
+ private flipPixelsVertically;
72
+ /**
73
+ * Creates a canvas element from pixel data.
74
+ *
75
+ * @param pixels - The vertically flipped pixel data
76
+ * @param width - Width of the image in pixels
77
+ * @param height - Height of the image in pixels
78
+ * @returns A canvas element containing the image
79
+ * @private
80
+ */
81
+ private createCanvasFromPixels;
82
+ /**
83
+ * Creates a downloadable PNG file and triggers the download.
84
+ *
85
+ * This method:
86
+ * - Exports the canvas to a PNG data URL
87
+ * - Generates a timestamped filename
88
+ * - Creates and triggers a download link
89
+ *
90
+ * @param canvas - The canvas element containing the image
91
+ * @private
92
+ */
93
+ private createFileAndDownloadIt;
94
+ }
95
+ //# sourceMappingURL=AcApPngConvertor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcApPngConvertor.d.ts","sourceRoot":"","sources":["../../src/command/AcApPngConvertor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAgB,MAAM,uBAAuB,CAAA;AAM/D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM;IAgH9C;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,oBAAoB;IAgB5B;;;;;;;;OAQG;IACH,OAAO,CAAC,sBAAsB;IAe9B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,uBAAuB;CAchC"}
@@ -0,0 +1,205 @@
1
+ import { AcGeVector2d } from '@mlightcad/data-model';
2
+ import * as THREE from 'three';
3
+ import { AcApDocManager } from '../app';
4
+ /**
5
+ * Utility class for converting CAD drawings to PNG format.
6
+ *
7
+ * This class provides functionality to export the current CAD drawing
8
+ * to PNG format and download it as a file. It renders the current view
9
+ * using WebGLRenderTarget for optimal performance without requiring
10
+ * preserveDrawingBuffer to be enabled on the renderer.
11
+ *
12
+ * The conversion process:
13
+ * 1. Gets the current view and its associated renderer, scene, and camera
14
+ * 2. Creates an offscreen render target for pixel capture
15
+ * 3. Renders the scene to the render target
16
+ * 4. Reads the pixel data and flips it vertically (WebGL renders upside down)
17
+ * 5. Creates a canvas, draws the pixel data, and exports as PNG
18
+ * 6. Triggers a download of the PNG file
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const converter = new AcApPngConvertor();
23
+ *
24
+ * // Convert and download current drawing as PNG
25
+ * converter.convert();
26
+ * ```
27
+ */
28
+ var AcApPngConvertor = /** @class */ (function () {
29
+ function AcApPngConvertor() {
30
+ }
31
+ /**
32
+ * Converts the current CAD drawing to PNG format and initiates download.
33
+ *
34
+ * This method:
35
+ * - Retrieves the current view, renderer, scene, and camera
36
+ * - Creates a WebGLRenderTarget for offscreen rendering
37
+ * - Renders the scene to the render target
38
+ * - Reads pixel data and flips it vertically to correct WebGL's upside-down rendering
39
+ * - Creates a canvas with the pixel data
40
+ * - Exports as PNG and downloads with timestamp-based filename
41
+ *
42
+ * @param bounds - Optional world coordinate bounding box to export.
43
+ * If provided, the camera will zoom to fit this region.
44
+ * If not provided, exports the current view.
45
+ * @param long_side - Optional maximum dimension (width or height) in pixels for the output PNG.
46
+ * The other dimension is calculated based on the aspect ratio of bounds.
47
+ * If not provided, uses the current view dimensions.
48
+ * @example
49
+ * ```typescript
50
+ * const converter = new AcApPngConvertor();
51
+ * converter.convert(); // Downloads the drawing as PNG
52
+ * ```
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // Export a specific region
57
+ * const bounds = new AcGeBox2d(new AcGePoint2d(0, 0), new AcGePoint2d(100, 100));
58
+ * const converter = new AcApPngConvertor();
59
+ * converter.convert(bounds); // Downloads the specified region as PNG
60
+ * ```
61
+ */
62
+ AcApPngConvertor.prototype.convert = function (bounds, long_side) {
63
+ var view = AcApDocManager.instance.curView;
64
+ var renderer = view.renderer.internalRenderer;
65
+ var scene = view.internalScene;
66
+ var camera = view.internalCamera;
67
+ if (!scene || !camera) {
68
+ console.error('[PNGOUT] Scene or camera not available');
69
+ return;
70
+ }
71
+ var outputWidth = view.width;
72
+ var outputHeight = view.height;
73
+ if (long_side && bounds) {
74
+ var size = new AcGeVector2d();
75
+ bounds.getSize(size);
76
+ var boundsWidth = size.x;
77
+ var boundsHeight = size.y;
78
+ var boundsAspect = boundsWidth / boundsHeight;
79
+ if (boundsAspect > 1) {
80
+ outputWidth = long_side;
81
+ outputHeight = Math.round(long_side / boundsAspect);
82
+ }
83
+ else {
84
+ outputHeight = long_side;
85
+ outputWidth = Math.round(long_side * boundsAspect);
86
+ }
87
+ }
88
+ // Save original camera state for restoration later
89
+ var originalZoom = camera.zoom;
90
+ var originalPosition = camera.position.clone();
91
+ // If bounds provided, calculate zoom and position to fit the specified region
92
+ if (bounds) {
93
+ var size = new AcGeVector2d();
94
+ bounds.getSize(size);
95
+ var center = new AcGeVector2d();
96
+ bounds.getCenter(center);
97
+ var boundsWidth = size.x;
98
+ var boundsHeight = size.y;
99
+ var widthRatio = view.width / boundsWidth;
100
+ var heightRatio = view.height / boundsHeight;
101
+ var scale = Math.min(widthRatio, heightRatio);
102
+ // Set camera position to center of bounds and adjust zoom
103
+ camera.position.set(center.x, center.y, camera.position.z);
104
+ camera.zoom = scale;
105
+ camera.updateProjectionMatrix();
106
+ }
107
+ // Create a render target for offscreen rendering
108
+ var renderTarget = new THREE.WebGLRenderTarget(outputWidth, outputHeight, {
109
+ minFilter: THREE.LinearFilter,
110
+ magFilter: THREE.LinearFilter,
111
+ format: THREE.RGBAFormat,
112
+ type: THREE.UnsignedByteType
113
+ });
114
+ // Store the original render target
115
+ var originalRenderTarget = renderer.getRenderTarget();
116
+ // Render to the offscreen target
117
+ renderer.setRenderTarget(renderTarget);
118
+ renderer.render(scene, camera);
119
+ // Read pixels from the render target
120
+ var pixels = new Uint8Array(outputWidth * outputHeight * 4);
121
+ renderer.readRenderTargetPixels(renderTarget, 0, 0, outputWidth, outputHeight, pixels);
122
+ // Restore the original render target
123
+ renderer.setRenderTarget(originalRenderTarget);
124
+ // Clean up the render target
125
+ renderTarget.dispose();
126
+ // Restore original camera state
127
+ camera.zoom = originalZoom;
128
+ camera.position.copy(originalPosition);
129
+ camera.updateProjectionMatrix();
130
+ // Flip the image vertically (WebGL renders upside down)
131
+ var flippedPixels = this.flipPixelsVertically(pixels, outputWidth, outputHeight);
132
+ // Create canvas and draw the pixels
133
+ var canvas = this.createCanvasFromPixels(flippedPixels, outputWidth, outputHeight);
134
+ // Export to PNG and download
135
+ this.createFileAndDownloadIt(canvas);
136
+ };
137
+ /**
138
+ * Flips pixel data vertically to correct WebGL's upside-down rendering.
139
+ *
140
+ * WebGL renders images upside down (origin at bottom-left), so the pixel
141
+ * data needs to be flipped to display correctly in standard image viewers.
142
+ *
143
+ * @param pixels - The raw pixel data from WebGL render target
144
+ * @param width - Width of the image in pixels
145
+ * @param height - Height of the image in pixels
146
+ * @returns The vertically flipped pixel data
147
+ * @private
148
+ */
149
+ AcApPngConvertor.prototype.flipPixelsVertically = function (pixels, width, height) {
150
+ var flippedPixels = new Uint8Array(width * height * 4);
151
+ for (var y = 0; y < height; y++) {
152
+ var srcRow = (height - 1 - y) * width * 4;
153
+ var dstRow = y * width * 4;
154
+ for (var x = 0; x < width * 4; x++) {
155
+ flippedPixels[dstRow + x] = pixels[srcRow + x];
156
+ }
157
+ }
158
+ return flippedPixels;
159
+ };
160
+ /**
161
+ * Creates a canvas element from pixel data.
162
+ *
163
+ * @param pixels - The vertically flipped pixel data
164
+ * @param width - Width of the image in pixels
165
+ * @param height - Height of the image in pixels
166
+ * @returns A canvas element containing the image
167
+ * @private
168
+ */
169
+ AcApPngConvertor.prototype.createCanvasFromPixels = function (pixels, width, height) {
170
+ var canvas = document.createElement('canvas');
171
+ canvas.width = width;
172
+ canvas.height = height;
173
+ var ctx = canvas.getContext('2d');
174
+ var imageData = ctx.createImageData(width, height);
175
+ imageData.data.set(pixels);
176
+ ctx.putImageData(imageData, 0, 0);
177
+ return canvas;
178
+ };
179
+ /**
180
+ * Creates a downloadable PNG file and triggers the download.
181
+ *
182
+ * This method:
183
+ * - Exports the canvas to a PNG data URL
184
+ * - Generates a timestamped filename
185
+ * - Creates and triggers a download link
186
+ *
187
+ * @param canvas - The canvas element containing the image
188
+ * @private
189
+ */
190
+ AcApPngConvertor.prototype.createFileAndDownloadIt = function (canvas) {
191
+ // Export canvas to PNG data URL
192
+ var dataURL = canvas.toDataURL('image/png');
193
+ // Create a download link and trigger the download
194
+ var downloadLink = document.createElement('a');
195
+ downloadLink.href = dataURL;
196
+ downloadLink.download = "cad-export-".concat(Date.now(), ".png");
197
+ // Trigger the download
198
+ document.body.appendChild(downloadLink);
199
+ downloadLink.click();
200
+ document.body.removeChild(downloadLink);
201
+ };
202
+ return AcApPngConvertor;
203
+ }());
204
+ export { AcApPngConvertor };
205
+ //# sourceMappingURL=AcApPngConvertor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcApPngConvertor.js","sourceRoot":"","sources":["../../src/command/AcApPngConvertor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAGvC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH;IAAA;IA6NA,CAAC;IA5NC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,kCAAO,GAAP,UAAQ,MAAkB,EAAE,SAAkB;QAC5C,IAAM,IAAI,GAAG,cAAc,CAAC,QAAQ,CAAC,OAAqB,CAAA;QAC1D,IAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAA;QAC/C,IAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAA;QAChC,IAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAA;QAElC,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;YACtB,OAAO,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAA;YACvD,OAAM;QACR,CAAC;QAED,IAAI,WAAW,GAAG,IAAI,CAAC,KAAK,C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