@mlightcad/cad-simple-viewer 1.5.0 → 1.5.1
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/dist/index.js +11070 -34695
- package/dist/index.umd.cjs +39 -52
- package/dist/libredwg-parser-worker.js +3955 -7422
- package/dist/mtext-renderer-worker.js +978 -789
- package/dist/viewer-runtime.iife.js +3879 -0
- package/lib/app/AcApAnnotation.js +4 -4
- package/lib/app/AcApAnnotation.js.map +1 -1
- package/lib/app/AcApDocManager.d.ts +45 -1
- package/lib/app/AcApDocManager.d.ts.map +1 -1
- package/lib/app/AcApDocManager.js +127 -10
- package/lib/app/AcApDocManager.js.map +1 -1
- package/lib/command/AcApZoomCmd.js +3 -3
- package/lib/command/AcApZoomCmd.js.map +1 -1
- package/lib/command/convert/AcApExportHtmlCmd.d.ts +22 -0
- package/lib/command/convert/AcApExportHtmlCmd.d.ts.map +1 -0
- package/lib/command/convert/AcApExportHtmlCmd.js +93 -0
- package/lib/command/convert/AcApExportHtmlCmd.js.map +1 -0
- package/lib/command/convert/AcApHtmlConvertor.d.ts +61 -0
- package/lib/command/convert/AcApHtmlConvertor.d.ts.map +1 -0
- package/lib/command/convert/AcApHtmlConvertor.js +223 -0
- package/lib/command/convert/AcApHtmlConvertor.js.map +1 -0
- package/lib/command/convert/AcApHtmlSnapshotBuilder.d.ts +65 -0
- package/lib/command/convert/AcApHtmlSnapshotBuilder.d.ts.map +1 -0
- package/lib/command/convert/AcApHtmlSnapshotBuilder.js +301 -0
- package/lib/command/convert/AcApHtmlSnapshotBuilder.js.map +1 -0
- package/lib/command/convert/index.d.ts +3 -0
- package/lib/command/convert/index.d.ts.map +1 -1
- package/lib/command/convert/index.js +3 -0
- package/lib/command/convert/index.js.map +1 -1
- package/lib/command/draw/AcApArcCmd.d.ts.map +1 -1
- package/lib/command/draw/AcApArcCmd.js +46 -20
- package/lib/command/draw/AcApArcCmd.js.map +1 -1
- package/lib/command/draw/AcApCircleCmd.d.ts.map +1 -1
- package/lib/command/draw/AcApCircleCmd.js +5 -6
- package/lib/command/draw/AcApCircleCmd.js.map +1 -1
- package/lib/command/draw/AcApEllipseCmd.d.ts.map +1 -1
- package/lib/command/draw/AcApEllipseCmd.js +4 -6
- package/lib/command/draw/AcApEllipseCmd.js.map +1 -1
- package/lib/command/draw/AcApMLineCmd.d.ts.map +1 -1
- package/lib/command/draw/AcApMLineCmd.js +4 -7
- package/lib/command/draw/AcApMLineCmd.js.map +1 -1
- package/lib/command/draw/AcApMTextCmd.d.ts.map +1 -1
- package/lib/command/draw/AcApMTextCmd.js +3 -1
- package/lib/command/draw/AcApMTextCmd.js.map +1 -1
- package/lib/command/draw/AcApPolygonCmd.d.ts.map +1 -1
- package/lib/command/draw/AcApPolygonCmd.js +4 -5
- package/lib/command/draw/AcApPolygonCmd.js.map +1 -1
- package/lib/command/draw/AcApPolylineCmd.d.ts +49 -0
- package/lib/command/draw/AcApPolylineCmd.d.ts.map +1 -1
- package/lib/command/draw/AcApPolylineCmd.js +200 -18
- package/lib/command/draw/AcApPolylineCmd.js.map +1 -1
- package/lib/command/draw/AcApRayCmd.d.ts.map +1 -1
- package/lib/command/draw/AcApRayCmd.js +2 -3
- package/lib/command/draw/AcApRayCmd.js.map +1 -1
- package/lib/command/draw/AcApRectCmd.d.ts.map +1 -1
- package/lib/command/draw/AcApRectCmd.js +9 -10
- package/lib/command/draw/AcApRectCmd.js.map +1 -1
- package/lib/command/draw/AcApSplineCmd.d.ts.map +1 -1
- package/lib/command/draw/AcApSplineCmd.js +3 -6
- package/lib/command/draw/AcApSplineCmd.js.map +1 -1
- package/lib/command/draw/AcApXLineCmd.d.ts.map +1 -1
- package/lib/command/draw/AcApXLineCmd.js +2 -3
- package/lib/command/draw/AcApXLineCmd.js.map +1 -1
- package/lib/command/measure/AcApClearMeasurementsCmd.d.ts +11 -0
- package/lib/command/measure/AcApClearMeasurementsCmd.d.ts.map +1 -1
- package/lib/command/measure/AcApClearMeasurementsCmd.js +15 -4
- package/lib/command/measure/AcApClearMeasurementsCmd.js.map +1 -1
- package/lib/command/measure/AcApMeasureAngleCmd.d.ts.map +1 -1
- package/lib/command/measure/AcApMeasureAngleCmd.js +15 -6
- package/lib/command/measure/AcApMeasureAngleCmd.js.map +1 -1
- package/lib/command/measure/AcApMeasureArcCmd.d.ts.map +1 -1
- package/lib/command/measure/AcApMeasureArcCmd.js +11 -4
- package/lib/command/measure/AcApMeasureArcCmd.js.map +1 -1
- package/lib/command/measure/AcApMeasureAreaCmd.d.ts.map +1 -1
- package/lib/command/measure/AcApMeasureAreaCmd.js +11 -4
- package/lib/command/measure/AcApMeasureAreaCmd.js.map +1 -1
- package/lib/command/measure/AcApMeasureDistanceCmd.d.ts +3 -2
- package/lib/command/measure/AcApMeasureDistanceCmd.d.ts.map +1 -1
- package/lib/command/measure/AcApMeasureDistanceCmd.js +14 -6
- package/lib/command/measure/AcApMeasureDistanceCmd.js.map +1 -1
- package/lib/command/modify/AcApOffsetCmd.d.ts +30 -0
- package/lib/command/modify/AcApOffsetCmd.d.ts.map +1 -0
- package/lib/command/modify/AcApOffsetCmd.js +424 -0
- package/lib/command/modify/AcApOffsetCmd.js.map +1 -0
- package/lib/command/modify/AcApRotateCmd.d.ts.map +1 -1
- package/lib/command/modify/AcApRotateCmd.js +3 -4
- package/lib/command/modify/AcApRotateCmd.js.map +1 -1
- package/lib/command/modify/index.d.ts +1 -0
- package/lib/command/modify/index.d.ts.map +1 -1
- package/lib/command/modify/index.js +1 -0
- package/lib/command/modify/index.js.map +1 -1
- package/lib/command/review/AcApRevCircleCmd.d.ts.map +1 -1
- package/lib/command/review/AcApRevCircleCmd.js +4 -1
- package/lib/command/review/AcApRevCircleCmd.js.map +1 -1
- package/lib/editor/input/AcEdSelectionFilter.js +7 -6
- package/lib/editor/input/AcEdSelectionFilter.js.map +1 -1
- package/lib/editor/input/prompt/AcEdPromptDistanceOptions.d.ts.map +1 -1
- package/lib/editor/input/prompt/AcEdPromptDistanceOptions.js +1 -1
- package/lib/editor/input/prompt/AcEdPromptDistanceOptions.js.map +1 -1
- package/lib/editor/input/ui/AcEdFloatingInput.d.ts +9 -0
- package/lib/editor/input/ui/AcEdFloatingInput.d.ts.map +1 -1
- package/lib/editor/input/ui/AcEdFloatingInput.js +21 -3
- package/lib/editor/input/ui/AcEdFloatingInput.js.map +1 -1
- package/lib/editor/input/ui/AcEdInputManager.d.ts +25 -6
- package/lib/editor/input/ui/AcEdInputManager.d.ts.map +1 -1
- package/lib/editor/input/ui/AcEdInputManager.js +119 -39
- package/lib/editor/input/ui/AcEdInputManager.js.map +1 -1
- package/lib/editor/input/ui/AcEdMTextEditor.d.ts +67 -2
- package/lib/editor/input/ui/AcEdMTextEditor.d.ts.map +1 -1
- package/lib/editor/input/ui/AcEdMTextEditor.js +210 -19
- package/lib/editor/input/ui/AcEdMTextEditor.js.map +1 -1
- package/lib/editor/input/ui/AcEdRubberBand.d.ts.map +1 -1
- package/lib/editor/input/ui/AcEdRubberBand.js +16 -8
- package/lib/editor/input/ui/AcEdRubberBand.js.map +1 -1
- package/lib/i18n/en/command.d.ts +64 -10
- package/lib/i18n/en/command.d.ts.map +1 -1
- package/lib/i18n/en/command.js +67 -13
- package/lib/i18n/en/command.js.map +1 -1
- package/lib/i18n/en/jig.d.ts +8 -0
- package/lib/i18n/en/jig.d.ts.map +1 -1
- package/lib/i18n/en/jig.js +8 -0
- package/lib/i18n/en/jig.js.map +1 -1
- package/lib/i18n/zh/command.d.ts +64 -10
- package/lib/i18n/zh/command.d.ts.map +1 -1
- package/lib/i18n/zh/command.js +67 -13
- package/lib/i18n/zh/command.js.map +1 -1
- package/lib/i18n/zh/jig.d.ts +8 -0
- package/lib/i18n/zh/jig.d.ts.map +1 -1
- package/lib/i18n/zh/jig.js +8 -0
- package/lib/i18n/zh/jig.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/util/AcApFontUtil.d.ts +69 -0
- package/lib/util/AcApFontUtil.d.ts.map +1 -0
- package/lib/util/AcApFontUtil.js +161 -0
- package/lib/util/AcApFontUtil.js.map +1 -0
- package/lib/util/index.d.ts +2 -0
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +2 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/yieldToMain.d.ts +5 -0
- package/lib/util/yieldToMain.d.ts.map +1 -0
- package/lib/util/yieldToMain.js +11 -0
- package/lib/util/yieldToMain.js.map +1 -0
- package/lib/view/AcTrLayoutView.d.ts +12 -0
- package/lib/view/AcTrLayoutView.d.ts.map +1 -1
- package/lib/view/AcTrLayoutView.js +18 -0
- package/lib/view/AcTrLayoutView.js.map +1 -1
- package/lib/view/AcTrScene.d.ts +38 -6
- package/lib/view/AcTrScene.d.ts.map +1 -1
- package/lib/view/AcTrScene.js +57 -30
- package/lib/view/AcTrScene.js.map +1 -1
- package/lib/view/AcTrView2d.d.ts +166 -0
- package/lib/view/AcTrView2d.d.ts.map +1 -1
- package/lib/view/AcTrView2d.js +586 -53
- package/lib/view/AcTrView2d.js.map +1 -1
- package/package.json +14 -8
package/lib/view/AcTrView2d.js
CHANGED
|
@@ -71,14 +71,14 @@ var __values = (this && this.__values) || function(o) {
|
|
|
71
71
|
};
|
|
72
72
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
73
73
|
};
|
|
74
|
-
import { acdbHostApplicationServices, AcDbRasterImage, AcDbRay, AcDbSysVarManager, AcDbViewport, AcDbXline, AcGeBox2d, AcGePoint2d, log } from '@mlightcad/data-model';
|
|
74
|
+
import { acdbHostApplicationServices, AcDbMText, AcDbRasterImage, AcDbRay, AcDbSysVarManager, AcDbViewport, AcDbXline, AcGeBox2d, AcGePoint2d, log } from '@mlightcad/data-model';
|
|
75
75
|
import { AcDbSystemVariables } from '@mlightcad/data-model';
|
|
76
76
|
import { AcTrEntity, AcTrGroup, AcTrRenderer, AcTrViewportView, getMaterialMetadata, hasByLayerBinding, setMaterialMetadata } from '@mlightcad/three-renderer';
|
|
77
77
|
import * as THREE from 'three';
|
|
78
78
|
import Stats from 'three/examples/jsm/libs/stats.module';
|
|
79
79
|
import { CSS2DRenderer } from 'three/examples/jsm/renderers/CSS2DRenderer.js';
|
|
80
80
|
import { AcApDocManager, AcApSettingManager } from '../app';
|
|
81
|
-
import { AcEdBaseView, AcEdConditionWaiter, AcEdCorsorType, AcEdViewMode, applyUiThemeFromBackground, eventBus, resolvePointerSelectionAction } from '../editor';
|
|
81
|
+
import { AcEdBaseView, AcEdConditionWaiter, AcEdCorsorType, AcEdMTextEditor, AcEdOpenMode, AcEdViewMode, applyUiThemeFromBackground, eventBus, resolvePointerSelectionAction } from '../editor';
|
|
82
82
|
import { AcTrGeometryUtil } from '../util';
|
|
83
83
|
import { AcTrLayoutView } from './AcTrLayoutView';
|
|
84
84
|
import { AcTrLayoutViewManager } from './AcTrLayoutViewManager';
|
|
@@ -145,6 +145,37 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
145
145
|
* A value of `null` indicates that no animation frame is currently scheduled.
|
|
146
146
|
*/
|
|
147
147
|
_this._rafId = null;
|
|
148
|
+
/**
|
|
149
|
+
* Block table record ids of layouts whose entities are currently being
|
|
150
|
+
* batch-converted into the scene. Used by
|
|
151
|
+
* {@link AcTrView2d.loadLayoutEntitiesIfNeeded} to guard against
|
|
152
|
+
* re-entrant calls before the `setTimeout` callback flips
|
|
153
|
+
* `AcTrLayout.isLoaded` to `true`, which would otherwise duplicate
|
|
154
|
+
* entities when the same layout tab is clicked twice in quick succession.
|
|
155
|
+
*/
|
|
156
|
+
_this._loadingLayouts = new Set();
|
|
157
|
+
/**
|
|
158
|
+
* Block table record ids of layouts that have already received an
|
|
159
|
+
* initial zoom-to-fit. Used by the `layoutSwitched` handler to apply
|
|
160
|
+
* the auto-zoom **only on the first user visit** to each layout, and
|
|
161
|
+
* to preserve the camera state on subsequent visits (matches AutoCAD's
|
|
162
|
+
* per-tab view persistence).
|
|
163
|
+
*
|
|
164
|
+
* Cannot be inferred from `_layoutViewManager.has(btrId)` because
|
|
165
|
+
* `addLayout` pre-creates an `AcTrLayoutView` for every layout in the
|
|
166
|
+
* DWG at document load time — by the time the user clicks a layout
|
|
167
|
+
* tab the view already exists, so "first existence of view" is
|
|
168
|
+
* always false. This set tracks the orthogonal question "has the user
|
|
169
|
+
* actually focused on this layout before?".
|
|
170
|
+
*
|
|
171
|
+
* Marked from two entry points:
|
|
172
|
+
* - `onAfterOpenDocument` (via `markLayoutAsInitialized`): the
|
|
173
|
+
* document's startup layout is initialized externally, so we don't
|
|
174
|
+
* auto-zoom again when the user clicks back to it.
|
|
175
|
+
* - `layoutSwitched` handler: after the first user-driven switch
|
|
176
|
+
* completes its initial zoom-to-fit.
|
|
177
|
+
*/
|
|
178
|
+
_this._initializedLayouts = new Set();
|
|
148
179
|
_this.animate = function () {
|
|
149
180
|
var _a;
|
|
150
181
|
_this._rafId = requestAnimationFrame(_this.animate);
|
|
@@ -228,7 +259,9 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
228
259
|
var selectionStartCanvas = null;
|
|
229
260
|
var selectionPreviewEl = null;
|
|
230
261
|
var canHandleSelectionGesture = function () {
|
|
231
|
-
return _this.mode === AcEdViewMode.SELECTION &&
|
|
262
|
+
return (_this.mode === AcEdViewMode.SELECTION &&
|
|
263
|
+
!_this.editor.isActive &&
|
|
264
|
+
!AcEdMTextEditor.getActiveInputBox());
|
|
232
265
|
};
|
|
233
266
|
var clearSelectionPreview = function () {
|
|
234
267
|
selectionPreviewEl === null || selectionPreviewEl === void 0 ? void 0 : selectionPreviewEl.remove();
|
|
@@ -302,6 +335,16 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
302
335
|
selectionStartWcs = null;
|
|
303
336
|
selectionStartCanvas = null;
|
|
304
337
|
});
|
|
338
|
+
_this.canvas.addEventListener('dblclick', function (e) {
|
|
339
|
+
if (e.button !== 0)
|
|
340
|
+
return;
|
|
341
|
+
if (!canHandleSelectionGesture())
|
|
342
|
+
return;
|
|
343
|
+
if (AcApDocManager.instance.curDocument.openMode !== AcEdOpenMode.Write) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
void _this.openPickedMTextEditor(e);
|
|
347
|
+
});
|
|
305
348
|
// When using OrbitControls in THREE.js, it attaches its own event listeners to the DOM elements,
|
|
306
349
|
// such as the canvas or the entire document. This can interfere with other event listeners you
|
|
307
350
|
// add, including the keydown event.
|
|
@@ -333,10 +376,50 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
333
376
|
}
|
|
334
377
|
});
|
|
335
378
|
acdbHostApplicationServices().layoutManager.events.layoutSwitched.addEventListener(function (args) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
379
|
+
var btrId = args.layout.blockTableRecordId;
|
|
380
|
+
// "First visit" is tracked separately from view existence because
|
|
381
|
+
// `addLayout` pre-creates an `AcTrLayoutView` for every layout in
|
|
382
|
+
// the DWG at load time — `_layoutViewManager.has(btrId)` is
|
|
383
|
+
// therefore `true` even for layouts the user has never focused
|
|
384
|
+
// on, and "first visit" computed from it would always be false.
|
|
385
|
+
// We use a dedicated set instead, marked here on first switch and
|
|
386
|
+
// also from `markLayoutAsInitialized` when the document opens
|
|
387
|
+
// straight into a layout (AcApDocManager has already framed it).
|
|
388
|
+
// Each AcTrLayoutView owns its own camera, so on subsequent
|
|
389
|
+
// visits the previous camera state is naturally restored and we
|
|
390
|
+
// must NOT zoom-to-fit again — that would be jarring and
|
|
391
|
+
// diverges from how AutoCAD preserves per-tab view state.
|
|
392
|
+
var isFirstVisit = !_this._initializedLayouts.has(btrId);
|
|
393
|
+
_this._initializedLayouts.add(btrId);
|
|
394
|
+
// Clear measurement overlays before swapping layouts.
|
|
395
|
+
// Measurements are screen/coordinate-anchored — their dimension
|
|
396
|
+
// text, hatch indicators, and HTML overlays were laid out in
|
|
397
|
+
// the previous layout's WCS (paper coords, ~unit scale) and
|
|
398
|
+
// would render at nonsense positions in a different layout
|
|
399
|
+
// (model WCS is typically O(10^5) larger, paper layouts use
|
|
400
|
+
// their own sheet coords). Selection state is intentionally
|
|
401
|
+
// **not** cleared here: it is entity-id-based and the same
|
|
402
|
+
// entity stays selected wherever it is rendered (the model
|
|
403
|
+
// entity drilled through a paper viewport remains visually
|
|
404
|
+
// selected when the user returns to model space, matching
|
|
405
|
+
// AutoCAD desktop's behaviour).
|
|
406
|
+
//
|
|
407
|
+
// Dynamic import avoids a circular dependency: the cleanup
|
|
408
|
+
// module already imports `AcTrView2d` for its
|
|
409
|
+
// `htmlTransientManager` cast, so a static import here would
|
|
410
|
+
// create a cycle. The cost (one extra microtask) is
|
|
411
|
+
// negligible for a layout switch.
|
|
412
|
+
void import('../command/measure/AcApClearMeasurementsCmd').then(function (_a) {
|
|
413
|
+
var clearAllMeasurements = _a.clearAllMeasurements;
|
|
414
|
+
return clearAllMeasurements(_this);
|
|
415
|
+
});
|
|
416
|
+
_this.activeLayoutBtrId = btrId;
|
|
417
|
+
_this.createLayoutViewIfNeeded(btrId);
|
|
418
|
+
_this.loadLayoutEntitiesIfNeeded(btrId);
|
|
339
419
|
_this._isDirty = true;
|
|
420
|
+
if (isFirstVisit) {
|
|
421
|
+
_this.applyInitialZoom(btrId, args.layout);
|
|
422
|
+
}
|
|
340
423
|
});
|
|
341
424
|
_this._css2dRenderer = new CSS2DRenderer();
|
|
342
425
|
_this._css2dRenderer.setSize(_this.width, _this.height);
|
|
@@ -526,6 +609,16 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
526
609
|
enumerable: false,
|
|
527
610
|
configurable: true
|
|
528
611
|
});
|
|
612
|
+
Object.defineProperty(AcTrView2d.prototype, "cadScene", {
|
|
613
|
+
/**
|
|
614
|
+
* CAD scene graph used for rendering and HTML export.
|
|
615
|
+
*/
|
|
616
|
+
get: function () {
|
|
617
|
+
return this._scene;
|
|
618
|
+
},
|
|
619
|
+
enumerable: false,
|
|
620
|
+
configurable: true
|
|
621
|
+
});
|
|
529
622
|
Object.defineProperty(AcTrView2d.prototype, "internalScene", {
|
|
530
623
|
/**
|
|
531
624
|
* The internal THREE scene used by this view.
|
|
@@ -653,30 +746,248 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
653
746
|
this.activeLayoutView.flyTo(point, scale);
|
|
654
747
|
this._isDirty = true;
|
|
655
748
|
};
|
|
749
|
+
AcTrView2d.prototype.openPickedMTextEditor = function (e) {
|
|
750
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
751
|
+
var point, worldPoint, picked, entity;
|
|
752
|
+
return __generator(this, function (_a) {
|
|
753
|
+
switch (_a.label) {
|
|
754
|
+
case 0:
|
|
755
|
+
point = this.viewportToCanvas({
|
|
756
|
+
x: e.clientX,
|
|
757
|
+
y: e.clientY
|
|
758
|
+
});
|
|
759
|
+
worldPoint = this.screenToWorld(point);
|
|
760
|
+
picked = this.pick(worldPoint, undefined, true);
|
|
761
|
+
if (!picked.length)
|
|
762
|
+
return [2 /*return*/];
|
|
763
|
+
entity = AcApDocManager.instance.curDocument.database.tables.blockTable.getEntityById(picked[0].id);
|
|
764
|
+
if (!(entity instanceof AcDbMText))
|
|
765
|
+
return [2 /*return*/];
|
|
766
|
+
e.preventDefault();
|
|
767
|
+
return [4 /*yield*/, this.editMTextEntity(entity)];
|
|
768
|
+
case 1:
|
|
769
|
+
_a.sent();
|
|
770
|
+
return [2 /*return*/];
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
});
|
|
774
|
+
};
|
|
775
|
+
AcTrView2d.prototype.editMTextEntity = function (mtext) {
|
|
776
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
777
|
+
var editor, applied, result;
|
|
778
|
+
return __generator(this, function (_a) {
|
|
779
|
+
switch (_a.label) {
|
|
780
|
+
case 0:
|
|
781
|
+
if (mtext.lineSpacingFactor !== AcEdMTextEditor.defaultLineSpacingFactor) {
|
|
782
|
+
mtext.lineSpacingFactor = AcEdMTextEditor.defaultLineSpacingFactor;
|
|
783
|
+
mtext.triggerModifiedEvent();
|
|
784
|
+
}
|
|
785
|
+
// Hide the in-scene MTEXT while the inline editor renders its own copy; otherwise
|
|
786
|
+
// both draw at once (double text) when the user double-clicks to edit.
|
|
787
|
+
// this.removeEntity(mtext)
|
|
788
|
+
this._isDirty = true;
|
|
789
|
+
editor = new AcEdMTextEditor();
|
|
790
|
+
applied = false;
|
|
791
|
+
_a.label = 1;
|
|
792
|
+
case 1:
|
|
793
|
+
_a.trys.push([1, , 3, 4]);
|
|
794
|
+
return [4 /*yield*/, editor.open({
|
|
795
|
+
view: this,
|
|
796
|
+
location: mtext.location,
|
|
797
|
+
width: this.resolveMTextEditorWidth(mtext),
|
|
798
|
+
textHeight: this.resolveMTextEditorTextHeight(mtext),
|
|
799
|
+
initialText: mtext.contents,
|
|
800
|
+
initialAttachmentPoint: mtext.attachmentPoint,
|
|
801
|
+
toolbarFontFamilies: this.getMTextToolbarFontFamilies()
|
|
802
|
+
})];
|
|
803
|
+
case 2:
|
|
804
|
+
result = _a.sent();
|
|
805
|
+
if (!result)
|
|
806
|
+
return [2 /*return*/];
|
|
807
|
+
mtext.location = result.location;
|
|
808
|
+
mtext.contents = result.contents;
|
|
809
|
+
mtext.width = result.width;
|
|
810
|
+
mtext.height = result.height;
|
|
811
|
+
mtext.lineSpacingFactor = result.lineSpacingFactor;
|
|
812
|
+
mtext.attachmentPoint = result.attachmentPoint;
|
|
813
|
+
mtext.triggerModifiedEvent();
|
|
814
|
+
applied = true;
|
|
815
|
+
return [3 /*break*/, 4];
|
|
816
|
+
case 3:
|
|
817
|
+
if (!applied) {
|
|
818
|
+
this.updateEntity(mtext);
|
|
819
|
+
this._isDirty = true;
|
|
820
|
+
}
|
|
821
|
+
return [7 /*endfinally*/];
|
|
822
|
+
case 4: return [2 /*return*/];
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
});
|
|
826
|
+
};
|
|
827
|
+
AcTrView2d.prototype.resolveMTextEditorWidth = function (mtext) {
|
|
828
|
+
var width = Number(mtext.width);
|
|
829
|
+
if (Number.isFinite(width) && width > 0)
|
|
830
|
+
return width;
|
|
831
|
+
return 1e-4;
|
|
832
|
+
};
|
|
833
|
+
AcTrView2d.prototype.resolveMTextEditorTextHeight = function (mtext) {
|
|
834
|
+
var textHeight = Number(mtext.height);
|
|
835
|
+
if (Number.isFinite(textHeight) && textHeight > 0)
|
|
836
|
+
return textHeight;
|
|
837
|
+
return this.pixelsToWorldY(24);
|
|
838
|
+
};
|
|
839
|
+
AcTrView2d.prototype.pixelsToWorldY = function (pixels) {
|
|
840
|
+
var p0 = this.screenToWorld({ x: 0, y: 0 });
|
|
841
|
+
var p1 = this.screenToWorld({ x: 0, y: pixels });
|
|
842
|
+
return Math.max(Math.abs(p1.y - p0.y), 1e-4);
|
|
843
|
+
};
|
|
844
|
+
AcTrView2d.prototype.getMTextToolbarFontFamilies = function () {
|
|
845
|
+
return Array.from(new Set(AcApDocManager.instance.avaiableFonts
|
|
846
|
+
.flatMap(function (fontInfo) { return fontInfo.name; })
|
|
847
|
+
.map(function (fontName) { return fontName.trim(); })
|
|
848
|
+
.filter(function (fontName) { return fontName.length > 0; })));
|
|
849
|
+
};
|
|
656
850
|
/**
|
|
657
851
|
* @inheritdoc
|
|
852
|
+
*
|
|
853
|
+
* In **paper space** layouts the selection pipeline supports
|
|
854
|
+
* "drill-through": clicks inside a viewport rectangle resolve against
|
|
855
|
+
* the model-space entities that are visually rendered through that
|
|
856
|
+
* viewport, rather than picking the viewport's border. Clicks **near**
|
|
857
|
+
* the border still pick the `AcDbViewport` entity itself so the user
|
|
858
|
+
* can grip, move, lock or delete the viewport.
|
|
859
|
+
*
|
|
860
|
+
* This mirrors AutoCAD **web** behaviour (single-click selection of
|
|
861
|
+
* model content through the viewport). The desktop ARX behaviour
|
|
862
|
+
* (explicit MSPACE/PSPACE modes, CVPORT system variable, double-click
|
|
863
|
+
* to enter mspace) is a separate, larger feature — tracked in
|
|
864
|
+
* `.claude/plans/next_14_viewports_full.md` PR-γ Option A. We
|
|
865
|
+
* intentionally do **not** implement it here.
|
|
866
|
+
*
|
|
867
|
+
* The border vs interior decision uses a tolerance derived from
|
|
868
|
+
* `selectionBoxSize` (the same pixel-sized hit radius used elsewhere
|
|
869
|
+
* in pick) converted to paper-space WCS via `pointToBox`. This keeps
|
|
870
|
+
* the gesture consistent with how other entity edges behave — you
|
|
871
|
+
* don't have to land pixel-perfect on the viewport line to grab it.
|
|
658
872
|
*/
|
|
659
873
|
AcTrView2d.prototype.pick = function (point, hitRadius, pickOneOnly) {
|
|
874
|
+
var e_1, _a;
|
|
660
875
|
if (point == null)
|
|
661
876
|
point = this.curPos;
|
|
662
877
|
var results = [];
|
|
663
878
|
var activeLayout = this._scene.activeLayout;
|
|
664
|
-
if (activeLayout)
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
879
|
+
if (!activeLayout)
|
|
880
|
+
return results;
|
|
881
|
+
var activeLayoutView = this.activeLayoutView;
|
|
882
|
+
var effectiveHitRadius = hitRadius !== null && hitRadius !== void 0 ? hitRadius : this.selectionBoxSize;
|
|
883
|
+
var paperBox = activeLayoutView.pointToBox(point, effectiveHitRadius);
|
|
884
|
+
var threshold = Math.max(paperBox.size.width / 2, paperBox.size.height / 2);
|
|
885
|
+
// Identify drill-through viewports (paper space only): viewports whose
|
|
886
|
+
// paper rectangle contains the click AND whose border is NOT within
|
|
887
|
+
// tolerance of the click. The border tolerance is the average of the
|
|
888
|
+
// hit-box width/height — a robust, scale-aware proxy for "user is
|
|
889
|
+
// trying to grab the frame, not click inside".
|
|
890
|
+
var isPaperSpace = activeLayoutView.layoutBtrId !== this._scene.modelSpaceBtrId;
|
|
891
|
+
var borderTolerance = (paperBox.size.width + paperBox.size.height) / 2;
|
|
892
|
+
var drillThroughViewports = [];
|
|
893
|
+
var drillThroughViewportIds = new Set();
|
|
894
|
+
if (isPaperSpace) {
|
|
895
|
+
try {
|
|
896
|
+
for (var _b = __values(activeLayoutView.viewportViews), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
897
|
+
var vpView = _c.value;
|
|
898
|
+
if (vpView.containsPaperPoint(point) &&
|
|
899
|
+
!vpView.isNearPaperBorder(point, borderTolerance)) {
|
|
900
|
+
drillThroughViewports.push(vpView);
|
|
901
|
+
drillThroughViewportIds.add(vpView.viewport.id);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
906
|
+
finally {
|
|
907
|
+
try {
|
|
908
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
909
|
+
}
|
|
910
|
+
finally { if (e_1) throw e_1.error; }
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
// 1) Resolve hits in the active layout. Skip the `AcDbViewport`
|
|
914
|
+
// entity for any viewport we're drilling through — otherwise the
|
|
915
|
+
// rectangle's bounding box always wins (it covers the whole click
|
|
916
|
+
// region) and selection feels "stuck on the frame".
|
|
917
|
+
var firstQueryResults = this._scene.search(paperBox);
|
|
918
|
+
var raycaster = activeLayoutView.resetRaycaster(point, threshold);
|
|
919
|
+
firstQueryResults.forEach(function (item) {
|
|
920
|
+
if (drillThroughViewportIds.has(item.id))
|
|
921
|
+
return;
|
|
922
|
+
if (activeLayout.isIntersectWith(item.id, raycaster)) {
|
|
923
|
+
results.push(item);
|
|
924
|
+
}
|
|
925
|
+
});
|
|
926
|
+
// 2) For each drill-through viewport, resolve hits against the
|
|
927
|
+
// model-space layout using the viewport's own camera/raycaster.
|
|
928
|
+
if (drillThroughViewports.length > 0) {
|
|
929
|
+
this.pickThroughViewports(point, paperBox, drillThroughViewports, results);
|
|
930
|
+
}
|
|
931
|
+
var sortedResults = sortPickResults(results, point);
|
|
932
|
+
return pickOneOnly ? sortedResults.slice(0, 1) : sortedResults;
|
|
933
|
+
};
|
|
934
|
+
/**
|
|
935
|
+
* Resolves hits against the model-space layout for each viewport the
|
|
936
|
+
* click drills through. Appends the matches into `results` (caller
|
|
937
|
+
* sorts/dedups). Kept private and separate from `pick` so the main
|
|
938
|
+
* pick path stays a single straight read.
|
|
939
|
+
*
|
|
940
|
+
* Each viewport gets its own raycaster shot (using the viewport view's
|
|
941
|
+
* own camera, which is zoomed to `viewport.viewBox` in model WCS), so
|
|
942
|
+
* a click that lands in overlapping viewports correctly resolves
|
|
943
|
+
* against each viewport's particular model framing.
|
|
944
|
+
*
|
|
945
|
+
* `pickThroughViewports` does NOT consult the active (paper) layout's
|
|
946
|
+
* spatial index — that work is already done by the caller. It only
|
|
947
|
+
* adds model-space results that would otherwise be invisible to the
|
|
948
|
+
* paper-space pick.
|
|
949
|
+
*/
|
|
950
|
+
AcTrView2d.prototype.pickThroughViewports = function (paperPoint, paperBox, viewports, results) {
|
|
951
|
+
var e_2, _a;
|
|
952
|
+
var modelLayout = this._scene.modelSpaceLayout;
|
|
953
|
+
if (!modelLayout)
|
|
954
|
+
return;
|
|
955
|
+
// Half-extent of the paper-space hit box (== "radius" in paper WCS).
|
|
956
|
+
// Multiplied per viewport by its paper→model scale, this becomes a
|
|
957
|
+
// model-WCS radius that the per-viewport raycaster threshold and the
|
|
958
|
+
// spatial-index probe both use. This keeps the hit area visually
|
|
959
|
+
// consistent across viewports at different zoom levels.
|
|
960
|
+
var paperHalfRadius = (paperBox.size.width + paperBox.size.height) / 4;
|
|
961
|
+
var _loop_1 = function (vpView) {
|
|
962
|
+
var modelPt = vpView.paperPointToModel(paperPoint);
|
|
963
|
+
var modelRadius = paperHalfRadius * vpView.paperToModelScale;
|
|
964
|
+
if (modelRadius <= 0)
|
|
965
|
+
return "continue";
|
|
966
|
+
var modelBox = new AcGeBox2d().setFromPoints([
|
|
967
|
+
new AcGePoint2d(modelPt.x - modelRadius, modelPt.y - modelRadius),
|
|
968
|
+
new AcGePoint2d(modelPt.x + modelRadius, modelPt.y + modelRadius)
|
|
969
|
+
]);
|
|
970
|
+
var vpRaycaster = vpView.resetRaycaster(modelPt, modelRadius);
|
|
971
|
+
var modelHits = modelLayout.search(modelBox);
|
|
972
|
+
modelHits.forEach(function (item) {
|
|
973
|
+
if (modelLayout.isIntersectWith(item.id, vpRaycaster)) {
|
|
673
974
|
results.push(item);
|
|
674
975
|
}
|
|
675
976
|
});
|
|
676
|
-
|
|
677
|
-
|
|
977
|
+
};
|
|
978
|
+
try {
|
|
979
|
+
for (var viewports_1 = __values(viewports), viewports_1_1 = viewports_1.next(); !viewports_1_1.done; viewports_1_1 = viewports_1.next()) {
|
|
980
|
+
var vpView = viewports_1_1.value;
|
|
981
|
+
_loop_1(vpView);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
985
|
+
finally {
|
|
986
|
+
try {
|
|
987
|
+
if (viewports_1_1 && !viewports_1_1.done && (_a = viewports_1.return)) _a.call(viewports_1);
|
|
988
|
+
}
|
|
989
|
+
finally { if (e_2) throw e_2.error; }
|
|
678
990
|
}
|
|
679
|
-
return results;
|
|
680
991
|
};
|
|
681
992
|
/**
|
|
682
993
|
* @inheritdoc
|
|
@@ -851,6 +1162,91 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
851
1162
|
this.createLayoutViewIfNeeded(layout.blockTableRecordId);
|
|
852
1163
|
this._isDirty = true;
|
|
853
1164
|
};
|
|
1165
|
+
/**
|
|
1166
|
+
* Marks a layout as already framed by an external caller (typically
|
|
1167
|
+
* `AcApDocManager.onAfterOpenDocument`, which zooms the startup
|
|
1168
|
+
* layout right after parsing). Subsequent `layoutSwitched` events
|
|
1169
|
+
* for this btrId will skip their initial zoom-to-fit so the user's
|
|
1170
|
+
* camera state on the startup layout is preserved when they click
|
|
1171
|
+
* back to that tab.
|
|
1172
|
+
*
|
|
1173
|
+
* This is the public counterpart of the `_initializedLayouts` set —
|
|
1174
|
+
* exposed so the application layer can stay in sync with the view's
|
|
1175
|
+
* notion of "which layouts have been framed already" without
|
|
1176
|
+
* needing access to private state.
|
|
1177
|
+
*/
|
|
1178
|
+
AcTrView2d.prototype.markLayoutAsInitialized = function (layoutBtrId) {
|
|
1179
|
+
this._initializedLayouts.add(layoutBtrId);
|
|
1180
|
+
};
|
|
1181
|
+
/**
|
|
1182
|
+
* Applies the initial zoom-to-fit for a layout the user just switched
|
|
1183
|
+
* into for the first time. Picks the best available "what should the
|
|
1184
|
+
* camera frame?" signal in this order:
|
|
1185
|
+
*
|
|
1186
|
+
* 1. **`AcDbLayout.limits`** (LIMMIN/LIMMAX) — only when it actually
|
|
1187
|
+
* contains the layout's viewports. Many real DWGs ship with garbage
|
|
1188
|
+
* limits (e.g. `(0,0)-(12,9)` from a legacy template setup) that
|
|
1189
|
+
* don't reflect the actual paper sheet. We reject those by
|
|
1190
|
+
* checking containment against `viewportsBoundingBox`.
|
|
1191
|
+
*
|
|
1192
|
+
* 2. **`AcTrLayoutView.viewportsBoundingBox`** — bounding box of all
|
|
1193
|
+
* real user viewports in the layout. In production sheets viewports
|
|
1194
|
+
* typically span 70-90% of the paper, so this is a great proxy for
|
|
1195
|
+
* the printable area and (crucially) ignores outliers like title
|
|
1196
|
+
* blocks authored in a different unit/scale.
|
|
1197
|
+
*
|
|
1198
|
+
* 3. **`AcDbLayout.extents`** — the layout's own EXTMIN/EXTMAX, if
|
|
1199
|
+
* populated. Many parsers leave this empty (we've seen `(0,0)-(0,0)`),
|
|
1200
|
+
* so it sits below the viewport-based heuristic.
|
|
1201
|
+
*
|
|
1202
|
+
* 4. **`zoomToFitDrawing`** (entity extents from spatial index) —
|
|
1203
|
+
* last-resort fallback for layouts with no viewports and no
|
|
1204
|
+
* sensible limits/extents (e.g. a freshly created empty paper).
|
|
1205
|
+
* Vulnerable to scale-mismatch outliers, but better than no zoom.
|
|
1206
|
+
*
|
|
1207
|
+
* **Critically, this runs through `AcEdConditionWaiter`**: at the
|
|
1208
|
+
* moment `layoutSwitched` fires, the layout's entities (including its
|
|
1209
|
+
* `AcDbViewport`s) have not yet been batch-converted into the scene
|
|
1210
|
+
* — `loadLayoutEntitiesIfNeeded` chunked-converts via `setTimeout`.
|
|
1211
|
+
* Without the waiter, `viewportsBoundingBox` returns undefined and
|
|
1212
|
+
* the strategy degrades into (1) zooming to garbage `limits`, or
|
|
1213
|
+
* (4) zooming to an empty scene box. The waiter polls
|
|
1214
|
+
* `_numOfEntitiesToProcess` and only fires the heuristic once the
|
|
1215
|
+
* conversion is done.
|
|
1216
|
+
*/
|
|
1217
|
+
AcTrView2d.prototype.applyInitialZoom = function (btrId, layout) {
|
|
1218
|
+
var _this = this;
|
|
1219
|
+
var waiter = new AcEdConditionWaiter(function () { return _this._numOfEntitiesToProcess <= 0; }, function () {
|
|
1220
|
+
var limits = layout.limits;
|
|
1221
|
+
var layoutView = _this._layoutViewManager.getAt(btrId);
|
|
1222
|
+
var vpsBox = layoutView === null || layoutView === void 0 ? void 0 : layoutView.viewportsBoundingBox;
|
|
1223
|
+
var limitsContainsViewports = (function () {
|
|
1224
|
+
if (!limits || limits.isEmpty())
|
|
1225
|
+
return false;
|
|
1226
|
+
if (!vpsBox)
|
|
1227
|
+
return true;
|
|
1228
|
+
return (limits.min.x <= vpsBox.min.x &&
|
|
1229
|
+
limits.min.y <= vpsBox.min.y &&
|
|
1230
|
+
limits.max.x >= vpsBox.max.x &&
|
|
1231
|
+
limits.max.y >= vpsBox.max.y);
|
|
1232
|
+
})();
|
|
1233
|
+
if (limits && !limits.isEmpty() && limitsContainsViewports) {
|
|
1234
|
+
_this.zoomTo(limits);
|
|
1235
|
+
}
|
|
1236
|
+
else if (vpsBox) {
|
|
1237
|
+
_this.zoomTo(vpsBox);
|
|
1238
|
+
}
|
|
1239
|
+
else if (layout.extents && !layout.extents.isEmpty()) {
|
|
1240
|
+
var extents = layout.extents;
|
|
1241
|
+
_this.zoomTo(new AcGeBox2d({ x: extents.min.x, y: extents.min.y }, { x: extents.max.x, y: extents.max.y }));
|
|
1242
|
+
}
|
|
1243
|
+
else if (_this._scene.box) {
|
|
1244
|
+
_this.zoomTo(AcTrGeometryUtil.threeBox3dToGeBox2d(_this._scene.box));
|
|
1245
|
+
}
|
|
1246
|
+
_this._isDirty = true;
|
|
1247
|
+
}, 300, 0);
|
|
1248
|
+
waiter.start();
|
|
1249
|
+
};
|
|
854
1250
|
/**
|
|
855
1251
|
* @inheritdoc
|
|
856
1252
|
*/
|
|
@@ -938,10 +1334,26 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
938
1334
|
/**
|
|
939
1335
|
* Load entities from the specified layout if they haven't been loaded yet.
|
|
940
1336
|
* This ensures that when switching to a layout, all its entities are available for rendering.
|
|
1337
|
+
*
|
|
1338
|
+
* Two non-obvious invariants are enforced here:
|
|
1339
|
+
*
|
|
1340
|
+
* 1. The layout is looked up by `layoutBtrId` (the argument), not by
|
|
1341
|
+
* `this._scene.activeLayout`. The active layout reference happens to
|
|
1342
|
+
* match in the current `layoutSwitched` handler call site, but relying
|
|
1343
|
+
* on it would silently miss layouts that are pre-loaded ahead of
|
|
1344
|
+
* becoming active (e.g. background prefetch).
|
|
1345
|
+
* 2. The `_loadingLayouts` guard prevents re-entrance while the
|
|
1346
|
+
* `setTimeout` chunked-convert callback is still in flight. Without it,
|
|
1347
|
+
* clicking the same layout tab twice in quick succession (or
|
|
1348
|
+
* `layoutSwitched` firing twice during the async window) would iterate
|
|
1349
|
+
* the block table record again and duplicate every entity in the
|
|
1350
|
+
* layout — visible as ghosted overdraw and double the spatial-index
|
|
1351
|
+
* weight.
|
|
1352
|
+
*
|
|
941
1353
|
* @param layoutBtrId Input the block table record id of the layout
|
|
942
1354
|
*/
|
|
943
1355
|
AcTrView2d.prototype.loadLayoutEntitiesIfNeeded = function (layoutBtrId) {
|
|
944
|
-
var
|
|
1356
|
+
var e_3, _a;
|
|
945
1357
|
var _this = this;
|
|
946
1358
|
try {
|
|
947
1359
|
var db = AcApDocManager.instance.curDocument.database;
|
|
@@ -949,10 +1361,60 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
949
1361
|
if (!blockTableRecord) {
|
|
950
1362
|
return;
|
|
951
1363
|
}
|
|
952
|
-
var
|
|
953
|
-
if (
|
|
1364
|
+
var existingLayout = this._scene.layouts.get(layoutBtrId);
|
|
1365
|
+
if (existingLayout && existingLayout.isLoaded) {
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1368
|
+
if (this._loadingLayouts.has(layoutBtrId)) {
|
|
954
1369
|
return;
|
|
955
1370
|
}
|
|
1371
|
+
// Ensure `AcTrViewportView`s exist for every real `AcDbViewport`
|
|
1372
|
+
// in this layout when the layout's entities were already streamed
|
|
1373
|
+
// in by the document parser. There is a race in the parser-driven
|
|
1374
|
+
// load path: `addLayout(layout)` creates the `AcTrLayoutView`,
|
|
1375
|
+
// but the parser may dispatch the AcDbViewport entities before
|
|
1376
|
+
// that happens. When that races, `batchConvert`'s viewport
|
|
1377
|
+
// handler does `_layoutViewManager.getAt(entity.ownerId)`, gets
|
|
1378
|
+
// `undefined`, and **silently skips creating the
|
|
1379
|
+
// AcTrViewportView**. The reload path below used to mask this by
|
|
1380
|
+
// re-running batchConvert after the layoutView existed, but the
|
|
1381
|
+
// entityCount-skip optimization that follows removes that
|
|
1382
|
+
// side-effect, so we do the viewport-view-only pass explicitly
|
|
1383
|
+
// here. Skipped when the layout is empty — in that case the
|
|
1384
|
+
// batchConvert path below will create the viewport views directly
|
|
1385
|
+
// as it processes each entity.
|
|
1386
|
+
var layoutView = this._layoutViewManager.getAt(layoutBtrId);
|
|
1387
|
+
if (existingLayout &&
|
|
1388
|
+
existingLayout.entityCount > 0 &&
|
|
1389
|
+
layoutView &&
|
|
1390
|
+
layoutView.viewportCount === 0) {
|
|
1391
|
+
this.ensureViewportViews(blockTableRecord, layoutView);
|
|
1392
|
+
}
|
|
1393
|
+
// Model space (and any other layout pre-populated by the document
|
|
1394
|
+
// parser at open time) lands here without `isLoaded` ever having
|
|
1395
|
+
// been flipped — the initial entity stream goes through
|
|
1396
|
+
// `addEntity()` directly, bypassing this method. Without this
|
|
1397
|
+
// guard, switching back to model space from a paper layout would
|
|
1398
|
+
// re-iterate the full block table record and re-batch-convert
|
|
1399
|
+
// every entity (5759+ on real DWGs), freezing the UI for several
|
|
1400
|
+
// seconds AND duplicating entities (every entity ends up in the
|
|
1401
|
+
// layout twice, doubling the spatial-index weight and render
|
|
1402
|
+
// cost).
|
|
1403
|
+
//
|
|
1404
|
+
// If the layout already has entities, the parser has finished
|
|
1405
|
+
// loading them — flip the flag and bail. The reload path below
|
|
1406
|
+
// is only for layouts whose entities were never streamed in
|
|
1407
|
+
// (typically non-active paper-space layouts loaded on first user
|
|
1408
|
+
// visit).
|
|
1409
|
+
if (existingLayout && existingLayout.entityCount > 0) {
|
|
1410
|
+
existingLayout.isLoaded = true;
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
// Ensure layout exists in scene. `addEmptyLayout` is idempotent, but
|
|
1414
|
+
// guarding the call avoids an unnecessary Map probe + log noise.
|
|
1415
|
+
if (!existingLayout) {
|
|
1416
|
+
this._scene.addEmptyLayout(layoutBtrId);
|
|
1417
|
+
}
|
|
956
1418
|
// Collect all entities from this layout
|
|
957
1419
|
var entities_1 = [];
|
|
958
1420
|
var iterator = blockTableRecord.newIterator();
|
|
@@ -962,34 +1424,46 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
962
1424
|
entities_1.push(entity);
|
|
963
1425
|
}
|
|
964
1426
|
}
|
|
965
|
-
catch (
|
|
1427
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
966
1428
|
finally {
|
|
967
1429
|
try {
|
|
968
1430
|
if (iterator_1_1 && !iterator_1_1.done && (_a = iterator_1.return)) _a.call(iterator_1);
|
|
969
1431
|
}
|
|
970
|
-
finally { if (
|
|
1432
|
+
finally { if (e_3) throw e_3.error; }
|
|
971
1433
|
}
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
switch (_a.label) {
|
|
981
|
-
case 0: return [4 /*yield*/, this.batchConvert(entities_1)];
|
|
982
|
-
case 1:
|
|
983
|
-
_a.sent();
|
|
984
|
-
layout = this._scene.layouts.get(layoutBtrId);
|
|
985
|
-
if (layout) {
|
|
986
|
-
layout.isLoaded = true;
|
|
987
|
-
}
|
|
988
|
-
return [2 /*return*/];
|
|
989
|
-
}
|
|
990
|
-
});
|
|
991
|
-
}); });
|
|
1434
|
+
if (entities_1.length === 0) {
|
|
1435
|
+
// Empty layout (e.g. a freshly-created paper space tab). Mark as
|
|
1436
|
+
// loaded immediately so subsequent visits short-circuit.
|
|
1437
|
+
var layout = this._scene.layouts.get(layoutBtrId);
|
|
1438
|
+
if (layout) {
|
|
1439
|
+
layout.isLoaded = true;
|
|
1440
|
+
}
|
|
1441
|
+
return;
|
|
992
1442
|
}
|
|
1443
|
+
// Load entities asynchronously
|
|
1444
|
+
this._loadingLayouts.add(layoutBtrId);
|
|
1445
|
+
this._numOfEntitiesToProcess += entities_1.length;
|
|
1446
|
+
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1447
|
+
var layout;
|
|
1448
|
+
return __generator(this, function (_a) {
|
|
1449
|
+
switch (_a.label) {
|
|
1450
|
+
case 0:
|
|
1451
|
+
_a.trys.push([0, , 2, 3]);
|
|
1452
|
+
return [4 /*yield*/, this.batchConvert(entities_1)];
|
|
1453
|
+
case 1:
|
|
1454
|
+
_a.sent();
|
|
1455
|
+
layout = this._scene.layouts.get(layoutBtrId);
|
|
1456
|
+
if (layout) {
|
|
1457
|
+
layout.isLoaded = true;
|
|
1458
|
+
}
|
|
1459
|
+
return [3 /*break*/, 3];
|
|
1460
|
+
case 2:
|
|
1461
|
+
this._loadingLayouts.delete(layoutBtrId);
|
|
1462
|
+
return [7 /*endfinally*/];
|
|
1463
|
+
case 3: return [2 /*return*/];
|
|
1464
|
+
}
|
|
1465
|
+
});
|
|
1466
|
+
}); });
|
|
993
1467
|
}
|
|
994
1468
|
catch (error) {
|
|
995
1469
|
log.error('[AcTrView2d] Error loading layout entities:', error);
|
|
@@ -1011,6 +1485,48 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
1011
1485
|
AcTrView2d.prototype.drawEntity = function (entity, delay) {
|
|
1012
1486
|
return entity.worldDraw(this._renderer, delay);
|
|
1013
1487
|
};
|
|
1488
|
+
/**
|
|
1489
|
+
* Walks the given block table record once and creates one
|
|
1490
|
+
* `AcTrViewportView` for every real `AcDbViewport` entity it finds
|
|
1491
|
+
* (skipping the default paper-space viewport that is filtered
|
|
1492
|
+
* everywhere else by `AcTrViewportView.isDefaultPaperSpaceViewport`).
|
|
1493
|
+
*
|
|
1494
|
+
* This is the recovery pass for paper-space layouts whose viewport
|
|
1495
|
+
* entities reached `batchConvert` before the `AcTrLayoutView` was
|
|
1496
|
+
* created — those entities were drawn and added to the scene, but
|
|
1497
|
+
* the viewport-view creation step silently no-oped (lookup returned
|
|
1498
|
+
* undefined). Without this recovery, `viewportsBoundingBox` stays
|
|
1499
|
+
* `undefined` on first user visit, the initial-zoom strategy
|
|
1500
|
+
* degrades to the bogus `limits` branch, and the layout renders as
|
|
1501
|
+
* a "grain in the corner" with empty viewport scissors. See the
|
|
1502
|
+
* call site in `loadLayoutEntitiesIfNeeded` for the full context.
|
|
1503
|
+
*
|
|
1504
|
+
* Cheap operation: only AcDbViewport entities are inspected; for a
|
|
1505
|
+
* typical sheet that's a handful of entities even on 5000-entity
|
|
1506
|
+
* paper layouts.
|
|
1507
|
+
*/
|
|
1508
|
+
AcTrView2d.prototype.ensureViewportViews = function (blockTableRecord, layoutView) {
|
|
1509
|
+
var e_4, _a;
|
|
1510
|
+
var iterator = blockTableRecord.newIterator();
|
|
1511
|
+
try {
|
|
1512
|
+
for (var iterator_2 = __values(iterator), iterator_2_1 = iterator_2.next(); !iterator_2_1.done; iterator_2_1 = iterator_2.next()) {
|
|
1513
|
+
var entity = iterator_2_1.value;
|
|
1514
|
+
if (!(entity instanceof AcDbViewport))
|
|
1515
|
+
continue;
|
|
1516
|
+
if (AcTrViewportView.isDefaultPaperSpaceViewport(entity))
|
|
1517
|
+
continue;
|
|
1518
|
+
var viewportView = new AcTrViewportView(layoutView, entity.toGiViewport(), this._renderer);
|
|
1519
|
+
layoutView.addViewport(viewportView);
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1523
|
+
finally {
|
|
1524
|
+
try {
|
|
1525
|
+
if (iterator_2_1 && !iterator_2_1.done && (_a = iterator_2.return)) _a.call(iterator_2);
|
|
1526
|
+
}
|
|
1527
|
+
finally { if (e_4) throw e_4.error; }
|
|
1528
|
+
}
|
|
1529
|
+
};
|
|
1014
1530
|
/**
|
|
1015
1531
|
* Converts the specified database entities to three entities
|
|
1016
1532
|
* @param entities - The database entities
|
|
@@ -1030,6 +1546,21 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
1030
1546
|
_a.label = 2;
|
|
1031
1547
|
case 2:
|
|
1032
1548
|
_a.trys.push([2, 6, 7, 8]);
|
|
1549
|
+
// Skip the default paper-space viewport (`*Paper_Space`) entirely:
|
|
1550
|
+
// it is an AutoCAD-internal viewport that exists in every paper
|
|
1551
|
+
// layout and must not be drawn (would render a giant rectangle in
|
|
1552
|
+
// the paper coordinate system), nor added to the spatial index
|
|
1553
|
+
// (would stretch the layout's bounding box and break
|
|
1554
|
+
// zoomToFitDrawing), nor turned into an AcTrViewportView (would
|
|
1555
|
+
// setScissor over most of the canvas and squeeze the real user
|
|
1556
|
+
// viewports into a corner). See
|
|
1557
|
+
// `AcTrViewportView.isDefaultPaperSpaceViewport` for the criterion
|
|
1558
|
+
// and the rationale (legacy `number === 1` is unreliable across
|
|
1559
|
+
// parsers).
|
|
1560
|
+
if (entity instanceof AcDbViewport &&
|
|
1561
|
+
AcTrViewportView.isDefaultPaperSpaceViewport(entity)) {
|
|
1562
|
+
return [3 /*break*/, 8];
|
|
1563
|
+
}
|
|
1033
1564
|
threeEntity = this.drawEntity(entity, true);
|
|
1034
1565
|
if (!threeEntity)
|
|
1035
1566
|
return [3 /*break*/, 8];
|
|
@@ -1059,10 +1590,12 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
1059
1590
|
_a.label = 5;
|
|
1060
1591
|
case 5:
|
|
1061
1592
|
if (entity instanceof AcDbViewport) {
|
|
1062
|
-
//
|
|
1063
|
-
//
|
|
1064
|
-
//
|
|
1065
|
-
|
|
1593
|
+
// Default paper-space viewport was already filtered out at the
|
|
1594
|
+
// top of the loop, so anything that reaches here is a real
|
|
1595
|
+
// user-created viewport. The redundant check below is kept as
|
|
1596
|
+
// a defensive guard in case a future refactor reorders the
|
|
1597
|
+
// early-skip — it costs ~nothing and prevents a regression.
|
|
1598
|
+
if (!AcTrViewportView.isDefaultPaperSpaceViewport(entity)) {
|
|
1066
1599
|
layoutView = this._layoutViewManager.getAt(entity.ownerId);
|
|
1067
1600
|
if (layoutView) {
|
|
1068
1601
|
viewportView = new AcTrViewportView(layoutView, entity.toGiViewport(), this._renderer);
|
|
@@ -1092,7 +1625,7 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
1092
1625
|
});
|
|
1093
1626
|
};
|
|
1094
1627
|
AcTrView2d.prototype.handleGroup = function (group) {
|
|
1095
|
-
var
|
|
1628
|
+
var e_5, _a;
|
|
1096
1629
|
var _this = this;
|
|
1097
1630
|
var children = group.children;
|
|
1098
1631
|
var objectsGroupByLayer = new Map();
|
|
@@ -1120,12 +1653,12 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
1120
1653
|
child.parent = null;
|
|
1121
1654
|
}
|
|
1122
1655
|
}
|
|
1123
|
-
catch (
|
|
1656
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1124
1657
|
finally {
|
|
1125
1658
|
try {
|
|
1126
1659
|
if (children_1_1 && !children_1_1.done && (_a = children_1.return)) _a.call(children_1);
|
|
1127
1660
|
}
|
|
1128
|
-
finally { if (
|
|
1661
|
+
finally { if (e_5) throw e_5.error; }
|
|
1129
1662
|
}
|
|
1130
1663
|
var styleManager = group.styleManager;
|
|
1131
1664
|
var groupObjectId = group.objectId;
|
|
@@ -1180,7 +1713,7 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
1180
1713
|
* @param effectiveLayerName - Final layer name used by rendering and style updates.
|
|
1181
1714
|
*/
|
|
1182
1715
|
AcTrView2d.prototype.remapInheritedLayerObjects = function (objects, sourceLayerName, effectiveLayerName) {
|
|
1183
|
-
var
|
|
1716
|
+
var e_6, _a;
|
|
1184
1717
|
var _this = this;
|
|
1185
1718
|
if (sourceLayerName === effectiveLayerName)
|
|
1186
1719
|
return;
|
|
@@ -1209,12 +1742,12 @@ var AcTrView2d = /** @class */ (function (_super) {
|
|
|
1209
1742
|
});
|
|
1210
1743
|
}
|
|
1211
1744
|
}
|
|
1212
|
-
catch (
|
|
1745
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1213
1746
|
finally {
|
|
1214
1747
|
try {
|
|
1215
1748
|
if (objects_1_1 && !objects_1_1.done && (_a = objects_1.return)) _a.call(objects_1);
|
|
1216
1749
|
}
|
|
1217
|
-
finally { if (
|
|
1750
|
+
finally { if (e_6) throw e_6.error; }
|
|
1218
1751
|
}
|
|
1219
1752
|
};
|
|
1220
1753
|
/**
|