@reekon-tools/boldr-cad 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -9
- package/dist/app/edit.d.ts +12 -1
- package/dist/app/edit.js +96 -11
- package/dist/app/edit.js.map +1 -1
- package/dist/app/state.d.ts +31 -4
- package/dist/app/state.js +31 -2
- package/dist/app/state.js.map +1 -1
- package/dist/data/memory.d.ts +5 -0
- package/dist/data/memory.js +2 -2
- package/dist/data/memory.js.map +1 -1
- package/dist/data/provider.d.ts +19 -7
- package/dist/data/sync.d.ts +7 -2
- package/dist/data/sync.js +115 -64
- package/dist/data/sync.js.map +1 -1
- package/dist/editor/actions.d.ts +1 -2
- package/dist/editor/actions.js +391 -113
- package/dist/editor/actions.js.map +1 -1
- package/dist/editor/confirm.d.ts +23 -0
- package/dist/editor/confirm.js +35 -0
- package/dist/editor/confirm.js.map +1 -0
- package/dist/editor/elevation.d.ts +191 -90
- package/dist/editor/elevation.js +812 -616
- package/dist/editor/elevation.js.map +1 -1
- package/dist/editor/face.d.ts +73 -0
- package/dist/editor/face.js +269 -0
- package/dist/editor/face.js.map +1 -0
- package/dist/editor/files.d.ts +6 -0
- package/dist/editor/files.js +50 -4
- package/dist/editor/files.js.map +1 -1
- package/dist/editor/gestures.d.ts +18 -3
- package/dist/editor/gestures.js +145 -30
- package/dist/editor/gestures.js.map +1 -1
- package/dist/editor/keypad.d.ts +19 -4
- package/dist/editor/keypad.js +39 -9
- package/dist/editor/keypad.js.map +1 -1
- package/dist/editor/keys.js +36 -4
- package/dist/editor/keys.js.map +1 -1
- package/dist/editor/laser.d.ts +20 -4
- package/dist/editor/laser.js +104 -21
- package/dist/editor/laser.js.map +1 -1
- package/dist/editor/linkActions.d.ts +49 -0
- package/dist/editor/linkActions.js +210 -0
- package/dist/editor/linkActions.js.map +1 -0
- package/dist/editor/linkFollow.d.ts +2 -0
- package/dist/editor/linkFollow.js +53 -0
- package/dist/editor/linkFollow.js.map +1 -0
- package/dist/editor/linkWrite.d.ts +13 -0
- package/dist/editor/linkWrite.js +84 -0
- package/dist/editor/linkWrite.js.map +1 -0
- package/dist/editor/links.d.ts +84 -0
- package/dist/editor/links.js +130 -0
- package/dist/editor/links.js.map +1 -0
- package/dist/editor/markup.d.ts +29 -3
- package/dist/editor/markup.js +95 -10
- package/dist/editor/markup.js.map +1 -1
- package/dist/editor/mode.d.ts +40 -2
- package/dist/editor/mode.js +71 -4
- package/dist/editor/mode.js.map +1 -1
- package/dist/editor/ports.d.ts +36 -6
- package/dist/editor/ports.js +10 -1
- package/dist/editor/ports.js.map +1 -1
- package/dist/editor/project.d.ts +38 -6
- package/dist/editor/project.js +167 -27
- package/dist/editor/project.js.map +1 -1
- package/dist/editor/selection.d.ts +10 -0
- package/dist/editor/selection.js +62 -8
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/status.js +3 -0
- package/dist/editor/status.js.map +1 -1
- package/dist/editor/tooltips.d.ts +5 -0
- package/dist/editor/tooltips.js +48 -0
- package/dist/editor/tooltips.js.map +1 -0
- package/dist/editor/view3d.d.ts +17 -0
- package/dist/editor/view3d.js +135 -0
- package/dist/editor/view3d.js.map +1 -0
- package/dist/editor/view3dState.d.ts +39 -0
- package/dist/editor/view3dState.js +44 -0
- package/dist/editor/view3dState.js.map +1 -0
- package/dist/export/dxf.js +1 -1
- package/dist/export/dxf.js.map +1 -1
- package/dist/export/pdf.js +17 -12
- package/dist/export/pdf.js.map +1 -1
- package/dist/export/plan.d.ts +23 -6
- package/dist/export/plan.js +127 -44
- package/dist/export/plan.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/model/constraints.js +15 -4
- package/dist/model/constraints.js.map +1 -1
- package/dist/model/demo.js +3 -3
- package/dist/model/demo.js.map +1 -1
- package/dist/model/elevation.d.ts +6 -9
- package/dist/model/elevation.js +5 -13
- package/dist/model/elevation.js.map +1 -1
- package/dist/model/faces.d.ts +58 -0
- package/dist/model/faces.js +197 -0
- package/dist/model/faces.js.map +1 -0
- package/dist/model/facesolve.d.ts +72 -0
- package/dist/model/facesolve.js +369 -0
- package/dist/model/facesolve.js.map +1 -0
- package/dist/model/history.d.ts +3 -2
- package/dist/model/history.js +17 -11
- package/dist/model/history.js.map +1 -1
- package/dist/model/images.d.ts +18 -0
- package/dist/model/images.js +26 -0
- package/dist/model/images.js.map +1 -0
- package/dist/model/links.d.ts +46 -0
- package/dist/model/links.js +73 -0
- package/dist/model/links.js.map +1 -0
- package/dist/model/markup.d.ts +46 -0
- package/dist/model/markup.js +71 -0
- package/dist/model/markup.js.map +1 -0
- package/dist/model/measurement.d.ts +11 -0
- package/dist/model/measurement.js +24 -0
- package/dist/model/measurement.js.map +1 -0
- package/dist/model/openings.d.ts +4 -0
- package/dist/model/openings.js +4 -0
- package/dist/model/openings.js.map +1 -1
- package/dist/model/planGeom.d.ts +72 -2
- package/dist/model/planGeom.js +184 -10
- package/dist/model/planGeom.js.map +1 -1
- package/dist/model/project.js +3 -2
- package/dist/model/project.js.map +1 -1
- package/dist/model/projectfile.js +2 -1
- package/dist/model/projectfile.js.map +1 -1
- package/dist/model/rooms.js +2 -2
- package/dist/model/rooms.js.map +1 -1
- package/dist/model/settings.d.ts +6 -0
- package/dist/model/settings.js +2 -2
- package/dist/model/settings.js.map +1 -1
- package/dist/model/sketch.d.ts +14 -0
- package/dist/model/sketch.js +143 -24
- package/dist/model/sketch.js.map +1 -1
- package/dist/model/smooth.d.ts +6 -0
- package/dist/model/smooth.js +52 -0
- package/dist/model/smooth.js.map +1 -0
- package/dist/model/store.d.ts +12 -0
- package/dist/model/store.js +35 -3
- package/dist/model/store.js.map +1 -1
- package/dist/model/types.d.ts +173 -8
- package/dist/model/wallfaces.d.ts +32 -0
- package/dist/model/wallfaces.js +133 -20
- package/dist/model/wallfaces.js.map +1 -1
- package/dist/model/wallshape.d.ts +15 -0
- package/dist/model/wallshape.js +89 -0
- package/dist/model/wallshape.js.map +1 -0
- package/dist/react/BottomBar.d.ts +9 -5
- package/dist/react/BottomBar.js +213 -24
- package/dist/react/BottomBar.js.map +1 -1
- package/dist/react/Buttons.d.ts +13 -2
- package/dist/react/Buttons.js +37 -5
- package/dist/react/Buttons.js.map +1 -1
- package/dist/react/CadEditor.d.ts +46 -3
- package/dist/react/CadEditor.js +77 -20
- package/dist/react/CadEditor.js.map +1 -1
- package/dist/react/ConfirmSheet.d.ts +4 -0
- package/dist/react/ConfirmSheet.js +31 -0
- package/dist/react/ConfirmSheet.js.map +1 -0
- package/dist/react/ConflictSheet.d.ts +2 -1
- package/dist/react/ConflictSheet.js +16 -8
- package/dist/react/ConflictSheet.js.map +1 -1
- package/dist/react/Drawer.d.ts +8 -2
- package/dist/react/Drawer.js +167 -38
- package/dist/react/Drawer.js.map +1 -1
- package/dist/react/Duck.d.ts +13 -0
- package/dist/react/Duck.js +45 -0
- package/dist/react/Duck.js.map +1 -0
- package/dist/react/Empty3D.d.ts +2 -0
- package/dist/react/Empty3D.js +39 -0
- package/dist/react/Empty3D.js.map +1 -0
- package/dist/react/FitScroll.d.ts +6 -0
- package/dist/react/FitScroll.js +14 -0
- package/dist/react/FitScroll.js.map +1 -0
- package/dist/react/Icon.native.d.ts +6 -0
- package/dist/react/Icon.native.js +4 -0
- package/dist/react/Icon.native.js.map +1 -1
- package/dist/react/Icon.web.d.ts +6 -0
- package/dist/react/Icon.web.js +4 -0
- package/dist/react/Icon.web.js.map +1 -1
- package/dist/react/KeypadSheet.d.ts +9 -2
- package/dist/react/KeypadSheet.js +174 -42
- package/dist/react/KeypadSheet.js.map +1 -1
- package/dist/react/LaserTray.js +8 -5
- package/dist/react/LaserTray.js.map +1 -1
- package/dist/react/MarkupPanel.d.ts +8 -0
- package/dist/react/MarkupPanel.js +67 -0
- package/dist/react/MarkupPanel.js.map +1 -0
- package/dist/react/PageThumb.native.d.ts +7 -2
- package/dist/react/PageThumb.native.js +19 -7
- package/dist/react/PageThumb.native.js.map +1 -1
- package/dist/react/PageThumb.web.d.ts +3 -2
- package/dist/react/PageThumb.web.js +4 -4
- package/dist/react/PageThumb.web.js.map +1 -1
- package/dist/react/PlanCanvas.native.d.ts +1 -1
- package/dist/react/PlanCanvas.native.js +134 -36
- package/dist/react/PlanCanvas.native.js.map +1 -1
- package/dist/react/PlanCanvas.web.js +16 -5
- package/dist/react/PlanCanvas.web.js.map +1 -1
- package/dist/react/Popovers.d.ts +12 -6
- package/dist/react/Popovers.js +53 -26
- package/dist/react/Popovers.js.map +1 -1
- package/dist/react/Rail.d.ts +24 -0
- package/dist/react/Rail.js +324 -34
- package/dist/react/Rail.js.map +1 -1
- package/dist/react/ShapeMenu.d.ts +7 -0
- package/dist/react/ShapeMenu.js +58 -0
- package/dist/react/ShapeMenu.js.map +1 -0
- package/dist/react/Sheet.d.ts +14 -4
- package/dist/react/Sheet.js +54 -9
- package/dist/react/Sheet.js.map +1 -1
- package/dist/react/Slider.d.ts +18 -0
- package/dist/react/Slider.js +27 -0
- package/dist/react/Slider.js.map +1 -0
- package/dist/react/Toast.js +14 -6
- package/dist/react/Toast.js.map +1 -1
- package/dist/react/ToolTip.d.ts +7 -0
- package/dist/react/ToolTip.js +43 -0
- package/dist/react/ToolTip.js.map +1 -0
- package/dist/react/TopBar.d.ts +6 -3
- package/dist/react/TopBar.js +48 -17
- package/dist/react/TopBar.js.map +1 -1
- package/dist/react/Tween.d.ts +7 -0
- package/dist/react/Tween.js +26 -0
- package/dist/react/Tween.js.map +1 -0
- package/dist/react/Tween.native.d.ts +6 -0
- package/dist/react/Tween.native.js +43 -0
- package/dist/react/Tween.native.js.map +1 -0
- package/dist/react/View3D.native.d.ts +4 -0
- package/dist/react/View3D.native.js +103 -0
- package/dist/react/View3D.native.js.map +1 -0
- package/dist/react/View3D.web.d.ts +4 -0
- package/dist/react/View3D.web.js +151 -0
- package/dist/react/View3D.web.js.map +1 -0
- package/dist/react/View3DHost.d.ts +143 -0
- package/dist/react/View3DHost.js +377 -0
- package/dist/react/View3DHost.js.map +1 -0
- package/dist/react/corners.d.ts +7 -0
- package/dist/react/corners.js +51 -0
- package/dist/react/corners.js.map +1 -0
- package/dist/react/easing.d.ts +15 -0
- package/dist/react/easing.js +10 -0
- package/dist/react/easing.js.map +1 -0
- package/dist/react/host.d.ts +7 -2
- package/dist/react/host.js +8 -3
- package/dist/react/host.js.map +1 -1
- package/dist/react/hostKeypad.d.ts +56 -0
- package/dist/react/hostKeypad.js +5 -0
- package/dist/react/hostKeypad.js.map +1 -0
- package/dist/react/motion.d.ts +77 -0
- package/dist/react/motion.js +173 -0
- package/dist/react/motion.js.map +1 -0
- package/dist/react/ports.js +90 -8
- package/dist/react/ports.js.map +1 -1
- package/dist/react/saving.d.ts +15 -0
- package/dist/react/saving.js +76 -0
- package/dist/react/saving.js.map +1 -0
- package/dist/react/store.d.ts +38 -1
- package/dist/react/store.js +31 -1
- package/dist/react/store.js.map +1 -1
- package/dist/react/theme.d.ts +10 -0
- package/dist/react/theme.js +8 -0
- package/dist/react/theme.js.map +1 -1
- package/dist/react/topRow.d.ts +22 -0
- package/dist/react/topRow.js +61 -0
- package/dist/react/topRow.js.map +1 -0
- package/dist/react/touch.d.ts +6 -0
- package/dist/react/touch.js +9 -0
- package/dist/react/touch.js.map +1 -0
- package/dist/render/ctx.d.ts +8 -0
- package/dist/render/draw.d.ts +33 -1
- package/dist/render/draw.js +593 -215
- package/dist/render/draw.js.map +1 -1
- package/dist/render/elevation.d.ts +65 -43
- package/dist/render/elevation.js +414 -140
- package/dist/render/elevation.js.map +1 -1
- package/dist/render/figmaIcons.d.ts +12 -0
- package/dist/render/figmaIcons.js +21 -0
- package/dist/render/figmaIcons.js.map +1 -0
- package/dist/render/hit.d.ts +22 -2
- package/dist/render/hit.js +168 -25
- package/dist/render/hit.js.map +1 -1
- package/dist/render/icons.js +69 -10
- package/dist/render/icons.js.map +1 -1
- package/dist/render/linkTile.d.ts +15 -0
- package/dist/render/linkTile.js +369 -0
- package/dist/render/linkTile.js.map +1 -0
- package/dist/render/markup.d.ts +11 -0
- package/dist/render/markup.js +112 -0
- package/dist/render/markup.js.map +1 -0
- package/dist/render/navigate.d.ts +88 -0
- package/dist/render/navigate.js +100 -0
- package/dist/render/navigate.js.map +1 -0
- package/dist/render/snap.d.ts +20 -1
- package/dist/render/snap.js +118 -25
- package/dist/render/snap.js.map +1 -1
- package/dist/render/squircle.d.ts +8 -0
- package/dist/render/squircle.js +71 -0
- package/dist/render/squircle.js.map +1 -0
- package/dist/render/view.d.ts +115 -2
- package/dist/render/view.js +244 -19
- package/dist/render/view.js.map +1 -1
- package/dist/skia/SkiaDrawCtx.d.ts +30 -2
- package/dist/skia/SkiaDrawCtx.js +198 -43
- package/dist/skia/SkiaDrawCtx.js.map +1 -1
- package/dist/skia/host.d.ts +18 -2
- package/dist/skia/host.js +46 -1
- package/dist/skia/host.js.map +1 -1
- package/dist/solver/equations.js +37 -2
- package/dist/solver/equations.js.map +1 -1
- package/dist/solver/gauss-newton.d.ts +17 -0
- package/dist/solver/gauss-newton.js +144 -36
- package/dist/solver/gauss-newton.js.map +1 -1
- package/dist/solver/linalg.d.ts +45 -2
- package/dist/solver/linalg.js +164 -10
- package/dist/solver/linalg.js.map +1 -1
- package/dist/solver/types.d.ts +5 -0
- package/dist/tools/annotate.d.ts +57 -1
- package/dist/tools/annotate.js +64 -43
- package/dist/tools/annotate.js.map +1 -1
- package/dist/tools/chamfer.d.ts +12 -0
- package/dist/tools/chamfer.js +114 -0
- package/dist/tools/chamfer.js.map +1 -0
- package/dist/tools/corner.d.ts +38 -0
- package/dist/tools/corner.js +99 -0
- package/dist/tools/corner.js.map +1 -0
- package/dist/tools/dim.d.ts +86 -9
- package/dist/tools/dim.js +581 -96
- package/dist/tools/dim.js.map +1 -1
- package/dist/tools/elevation.js +1 -1
- package/dist/tools/elevation.js.map +1 -1
- package/dist/tools/fillet.d.ts +9 -0
- package/dist/tools/fillet.js +86 -0
- package/dist/tools/fillet.js.map +1 -0
- package/dist/tools/freehand.d.ts +3 -2
- package/dist/tools/freehand.js +19 -12
- package/dist/tools/freehand.js.map +1 -1
- package/dist/tools/index.js +14 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/line.d.ts +8 -3
- package/dist/tools/line.js +66 -30
- package/dist/tools/line.js.map +1 -1
- package/dist/tools/modify.d.ts +13 -0
- package/dist/tools/modify.js +105 -25
- package/dist/tools/modify.js.map +1 -1
- package/dist/tools/openings.js +22 -15
- package/dist/tools/openings.js.map +1 -1
- package/dist/tools/registry.d.ts +8 -0
- package/dist/tools/registry.js +42 -2
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/select.d.ts +77 -3
- package/dist/tools/select.js +560 -74
- package/dist/tools/select.js.map +1 -1
- package/dist/tools/shapes.d.ts +14 -0
- package/dist/tools/shapes.js +154 -75
- package/dist/tools/shapes.js.map +1 -1
- package/dist/units/format.d.ts +10 -2
- package/dist/units/format.js +18 -3
- package/dist/units/format.js.map +1 -1
- package/dist/view3d/build.d.ts +35 -0
- package/dist/view3d/build.js +630 -0
- package/dist/view3d/build.js.map +1 -0
- package/dist/view3d/camera.d.ts +60 -0
- package/dist/view3d/camera.js +84 -0
- package/dist/view3d/camera.js.map +1 -0
- package/dist/view3d/fatLines.d.ts +11 -0
- package/dist/view3d/fatLines.js +83 -0
- package/dist/view3d/fatLines.js.map +1 -0
- package/dist/view3d/lines.d.ts +17 -0
- package/dist/view3d/lines.js +271 -0
- package/dist/view3d/lines.js.map +1 -0
- package/dist/view3d/mesh.d.ts +51 -0
- package/dist/view3d/mesh.js +101 -0
- package/dist/view3d/mesh.js.map +1 -0
- package/dist/view3d/poly.d.ts +16 -0
- package/dist/view3d/poly.js +109 -0
- package/dist/view3d/poly.js.map +1 -0
- package/dist/view3d/viewer.d.ts +86 -0
- package/dist/view3d/viewer.js +350 -0
- package/dist/view3d/viewer.js.map +1 -0
- package/package.json +15 -2
- package/src/app/edit.ts +83 -12
- package/src/app/main.ts +11 -5
- package/src/app/state.ts +38 -5
- package/src/data/memory.ts +2 -2
- package/src/data/provider.ts +15 -7
- package/src/data/sync.ts +87 -50
- package/src/editor/actions.ts +292 -83
- package/src/editor/confirm.ts +58 -0
- package/src/editor/elevation.ts +698 -478
- package/src/editor/face.ts +227 -0
- package/src/editor/files.ts +40 -4
- package/src/editor/gestures.ts +147 -31
- package/src/editor/keypad.ts +43 -11
- package/src/editor/keys.ts +25 -5
- package/src/editor/laser.ts +98 -20
- package/src/editor/linkActions.ts +194 -0
- package/src/editor/linkFollow.ts +43 -0
- package/src/editor/linkWrite.ts +77 -0
- package/src/editor/links.ts +181 -0
- package/src/editor/markup.ts +92 -8
- package/src/editor/mode.ts +83 -7
- package/src/editor/ports.ts +37 -6
- package/src/editor/project.ts +155 -26
- package/src/editor/selection.ts +54 -8
- package/src/editor/status.ts +2 -0
- package/src/editor/tooltips.ts +47 -0
- package/src/editor/view3d.ts +119 -0
- package/src/editor/view3dState.ts +61 -0
- package/src/export/dxf.ts +1 -1
- package/src/export/pdf.ts +15 -7
- package/src/export/plan.ts +119 -35
- package/src/index.ts +5 -0
- package/src/input/keyboard.ts +2 -4
- package/src/model/constraints.ts +13 -4
- package/src/model/demo.ts +3 -3
- package/src/model/elevation.ts +6 -16
- package/src/model/faces.ts +153 -0
- package/src/model/facesolve.ts +322 -0
- package/src/model/history.ts +19 -11
- package/src/model/images.ts +35 -0
- package/src/model/links.ts +77 -0
- package/src/model/markup.ts +80 -0
- package/src/model/measurement.ts +26 -0
- package/src/model/openings.ts +6 -0
- package/src/model/planGeom.ts +174 -8
- package/src/model/project.ts +3 -2
- package/src/model/projectfile.ts +2 -1
- package/src/model/rooms.ts +1 -1
- package/src/model/settings.ts +8 -2
- package/src/model/sketch.ts +101 -14
- package/src/model/smooth.ts +51 -0
- package/src/model/store.ts +35 -4
- package/src/model/types.ts +170 -8
- package/src/model/wallfaces.ts +126 -17
- package/src/model/wallshape.ts +97 -0
- package/src/react/BottomBar.tsx +263 -46
- package/src/react/Buttons.tsx +50 -9
- package/src/react/CadEditor.tsx +133 -30
- package/src/react/ConfirmSheet.tsx +38 -0
- package/src/react/ConflictSheet.tsx +19 -12
- package/src/react/Drawer.tsx +213 -110
- package/src/react/Duck.tsx +50 -0
- package/src/react/Empty3D.tsx +32 -0
- package/src/react/FitScroll.tsx +19 -0
- package/src/react/Icon.native.tsx +5 -0
- package/src/react/Icon.web.tsx +5 -0
- package/src/react/KeypadSheet.tsx +253 -60
- package/src/react/LaserTray.tsx +12 -8
- package/src/react/MarkupPanel.tsx +150 -0
- package/src/react/PageThumb.native.tsx +18 -7
- package/src/react/PageThumb.web.tsx +4 -4
- package/src/react/PlanCanvas.native.tsx +151 -34
- package/src/react/PlanCanvas.web.tsx +15 -5
- package/src/react/Popovers.tsx +116 -51
- package/src/react/Rail.tsx +360 -27
- package/src/react/ShapeMenu.tsx +66 -0
- package/src/react/Sheet.tsx +56 -11
- package/src/react/Slider.tsx +48 -0
- package/src/react/Toast.tsx +16 -9
- package/src/react/ToolTip.tsx +49 -0
- package/src/react/TopBar.tsx +97 -39
- package/src/react/Tween.native.tsx +36 -0
- package/src/react/Tween.tsx +24 -0
- package/src/react/View3D.native.tsx +131 -0
- package/src/react/View3D.web.tsx +131 -0
- package/src/react/View3DHost.ts +367 -0
- package/src/react/corners.ts +52 -0
- package/src/react/easing.ts +14 -0
- package/src/react/host.ts +8 -3
- package/src/react/hostKeypad.ts +66 -0
- package/src/react/motion.tsx +239 -0
- package/src/react/ports.ts +78 -9
- package/src/react/saving.ts +80 -0
- package/src/react/store.ts +35 -3
- package/src/react/theme.ts +8 -0
- package/src/react/topRow.ts +71 -0
- package/src/react/touch.ts +10 -0
- package/src/render/ctx.ts +8 -0
- package/src/render/draw.ts +437 -175
- package/src/render/elevation.ts +349 -143
- package/src/render/figmaIcons.ts +22 -0
- package/src/render/hit.ts +140 -21
- package/src/render/icons.ts +69 -10
- package/src/render/linkTile.ts +297 -0
- package/src/render/markup.ts +91 -0
- package/src/render/navigate.ts +114 -0
- package/src/render/snap.ts +105 -22
- package/src/render/squircle.ts +73 -0
- package/src/render/view.ts +255 -19
- package/src/skia/SkiaDrawCtx.ts +163 -41
- package/src/skia/host.ts +46 -1
- package/src/solver/equations.ts +37 -2
- package/src/solver/gauss-newton.ts +125 -28
- package/src/solver/linalg.ts +141 -5
- package/src/solver/types.ts +5 -0
- package/src/styles.css +91 -42
- package/src/tools/annotate.ts +58 -29
- package/src/tools/chamfer.ts +103 -0
- package/src/tools/corner.ts +99 -0
- package/src/tools/dim.ts +524 -92
- package/src/tools/elevation.ts +1 -1
- package/src/tools/fillet.ts +82 -0
- package/src/tools/freehand.ts +20 -16
- package/src/tools/index.ts +17 -4
- package/src/tools/line.ts +59 -23
- package/src/tools/modify.ts +86 -24
- package/src/tools/openings.ts +8 -13
- package/src/tools/registry.ts +27 -2
- package/src/tools/select.ts +424 -75
- package/src/tools/shapes.ts +119 -58
- package/src/ui/ctx.ts +2 -1
- package/src/ui/domPorts.ts +23 -4
- package/src/ui/drawer.ts +6 -26
- package/src/ui/elevation.ts +10 -101
- package/src/ui/keypad.ts +8 -14
- package/src/ui/laser.ts +2 -2
- package/src/ui/menu.ts +63 -17
- package/src/ui/noteinput.ts +3 -3
- package/src/ui/opacity.ts +108 -0
- package/src/ui/palette.ts +67 -12
- package/src/ui/rail.ts +21 -7
- package/src/ui/topbar.ts +4 -14
- package/src/units/format.ts +18 -3
- package/src/view3d/build.ts +607 -0
- package/src/view3d/camera.ts +113 -0
- package/src/view3d/fatLines.ts +83 -0
- package/src/view3d/lines.ts +258 -0
- package/src/view3d/mesh.ts +111 -0
- package/src/view3d/poly.ts +104 -0
- package/src/view3d/viewer.ts +348 -0
- package/dist/react/ElevCanvas.native.d.ts +0 -3
- package/dist/react/ElevCanvas.native.js +0 -58
- package/dist/react/ElevCanvas.native.js.map +0 -1
- package/dist/react/ElevCanvas.web.d.ts +0 -4
- package/dist/react/ElevCanvas.web.js +0 -44
- package/dist/react/ElevCanvas.web.js.map +0 -1
- package/dist/react/ElevationSheet.d.ts +0 -2
- package/dist/react/ElevationSheet.js +0 -38
- package/dist/react/ElevationSheet.js.map +0 -1
- package/dist/render/elevationView.d.ts +0 -3
- package/dist/render/elevationView.js +0 -100
- package/dist/render/elevationView.js.map +0 -1
- package/src/react/ElevCanvas.native.tsx +0 -68
- package/src/react/ElevCanvas.web.tsx +0 -42
- package/src/react/ElevationSheet.tsx +0 -88
- package/src/render/elevationView.ts +0 -73
package/src/editor/elevation.ts
CHANGED
|
@@ -1,591 +1,811 @@
|
|
|
1
|
-
import { afterEdit,
|
|
2
|
-
import { ed } from '../app/state';
|
|
3
|
-
import {
|
|
1
|
+
import { afterEdit, analyze, resolveOpeningsNow, undo } from '../app/edit';
|
|
2
|
+
import { ed, type Hit } from '../app/state';
|
|
3
|
+
import { DOOR_H, elevFrame, elevOpenings, openingHeights, roomSideOf, toU, wallHeight, WINDOW_H, type ElevFrame } from '../model/elevation';
|
|
4
|
+
import { faceEdit, faceKey, faceKeyParts } from '../model/faces';
|
|
5
|
+
import { wallFace } from '../model/wallfaces';
|
|
6
|
+
import { faceOverflow, forgetSynced, openFace, placedMarks, planOverflow, pushedOut, setPlacedMarks, syncFace, syncFaces, type Overflow } from '../model/facesolve';
|
|
4
7
|
import { clamp } from '../model/geom';
|
|
5
8
|
import { pushHistory } from '../model/history';
|
|
6
9
|
import { uid } from '../model/ids';
|
|
7
|
-
import { applySlide, openingSpan, pickBetween, sameRef, slideGroup, type SlideGroup } from '../model/openings';
|
|
8
|
-
import {
|
|
10
|
+
import { applySlide, edgeS, openingSpan, pickBetween, resolveOpenings, sameRef, slideGroup, STANDARD_OPENING_W, type SlideGroup } from '../model/openings';
|
|
11
|
+
import { sessionState } from '../model/session';
|
|
9
12
|
import { settings } from '../model/settings';
|
|
10
|
-
import { deleteSel, lineLen } from '../model/sketch';
|
|
11
|
-
import { SK } from '../model/store';
|
|
12
|
-
import type { OpeningDim, OpeningRef } from '../model/types';
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
13
|
+
import { deleteSel, gc, lineLen, restorePos, snapshotPos, type PosSnapshot } from '../model/sketch';
|
|
14
|
+
import { planSK, SK } from '../model/store';
|
|
15
|
+
import type { Opening, OpeningDim, OpeningRef, Sketch, WallFace } from '../model/types';
|
|
16
|
+
import type { DrawCtx } from '../render/ctx';
|
|
17
|
+
import { cabBox, previewChip, type ElevAct } from '../render/elevation';
|
|
18
|
+
import { TH } from '../render/theme';
|
|
19
|
+
import { fitView, mainT, requestDraw, requestOverlayDraw, S, setWallBox, type Xform } from '../render/view';
|
|
15
20
|
import { editElevationPosition, editOpeningHeight, editSill, editWallHeight } from '../tools/elevation';
|
|
16
21
|
import { editOpeningDim } from '../tools/openings';
|
|
22
|
+
import { cancelTool, type PEv, type Tool } from '../tools/registry';
|
|
17
23
|
import { fmtLen } from '../units';
|
|
18
|
-
import
|
|
19
|
-
import type {
|
|
20
|
-
import { openKeypad,
|
|
24
|
+
import { addCabinet, addHeightLine, CAB, cabinetSpot, deleteCabinets, dimensionFace, editCabinet, editCabinetDepth, snapObjectMove } from './face';
|
|
25
|
+
import type { RailItem } from './mode';
|
|
26
|
+
import { openKeypad, refreshModes, renderElevation, toast, updateCtx, updateHint, updateRail, updateTopBar } from './ports';
|
|
21
27
|
|
|
22
28
|
/*
|
|
23
|
-
The wall
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
the
|
|
29
|
+
The wall view: one straight wall seen straight on, edited with the plan's own tools. Opening a wall makes the
|
|
30
|
+
editor work on that wall face's sketch (model/faces.ts: SK() is the face) — its grid, lines, circles and arcs,
|
|
31
|
+
constraints, dimensions, selection and dragging are the plan's — with the plan's corners, floor, ceiling, doors and
|
|
32
|
+
windows as fixed anchors to snap and constrain to. On top of that, the wall view's own: doors and windows placed
|
|
33
|
+
and dragged on the wall (they're the plan's), cabinets, height lines, and the dimension chips doors, windows and
|
|
34
|
+
cabinets get (render/elevation.ts), each tapped to select and changed with the yellow +.
|
|
28
35
|
*/
|
|
29
36
|
|
|
30
|
-
/** The open wall
|
|
37
|
+
/** The open wall: which wall, from which side, and its frame (from the live plan). */
|
|
31
38
|
export const elev = sessionState(() => ({
|
|
32
39
|
lid: null as string | null,
|
|
33
40
|
flip: false,
|
|
34
|
-
view: null as ElevView | null,
|
|
35
41
|
frame: null as ElevFrame | null,
|
|
36
|
-
W: 0, H: 0,
|
|
37
|
-
hits: [] as ElevHit[],
|
|
38
|
-
/** the selected dimension (ringed in yellow; the bar's + opens its keypad) */
|
|
39
|
-
active: null as string | null,
|
|
40
|
-
/** the opening being dragged (outlined in yellow) */
|
|
41
|
-
dragOp: null as string | null,
|
|
42
|
-
/** selected openings, wall corners and drawn lines (tap; Shift/⌘-tap adds) — the bar's + dimensions them */
|
|
43
|
-
objs: [] as Obj[],
|
|
44
|
-
/** the active tool (the toolbar on the left) */
|
|
45
|
-
tool: 'select' as ElevTool,
|
|
46
|
-
/** line / guide tool: the first point, [u, z], once placed */
|
|
47
|
-
lineStart: null as [number, number] | null,
|
|
48
|
-
/** where the pointer is (snapped), for previews while a drawing tool is active */
|
|
49
|
-
cursor: null as Snapped | null,
|
|
50
42
|
}));
|
|
51
43
|
|
|
52
|
-
/** Something selectable in the elevation: a door/window, a corner of the wall face, or a line drawn on it. */
|
|
53
|
-
export type Obj = { k: 'op'; id: string } | { k: 'corner'; end: 'a' | 'b' } | { k: 'line'; id: string };
|
|
54
|
-
const objKey = (o: Obj) => (o.k === 'corner' ? 'corner:' + o.end : o.k + ':' + o.id);
|
|
55
|
-
|
|
56
|
-
/** Wall view tools: a simplified version of the plan's toolbar. */
|
|
57
|
-
export type ElevTool = 'select' | 'door' | 'window' | 'line' | 'guide';
|
|
58
|
-
/** A point under the pointer, snapped: kind says what it snapped to (drawn as a purple marker). */
|
|
59
|
-
export interface Snapped { p: [number, number]; kind: 'pt' | 'edge' | 'hv' | null }
|
|
60
|
-
|
|
61
44
|
/** Size of a new door/window placed in the wall view (as the plan's tool), inches. */
|
|
62
|
-
export const NEW_W =
|
|
45
|
+
export const NEW_W = STANDARD_OPENING_W;
|
|
63
46
|
|
|
64
47
|
export const elevOpen = (): boolean => elev.lid != null;
|
|
65
48
|
|
|
66
|
-
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
49
|
+
/** The open wall, for the wall view to fit: along it from corner to corner, and from the floor to its height. */
|
|
50
|
+
const wallBox = () => (elev.frame ? { x0: elev.frame.face[0], y0: 0, x1: elev.frame.face[1], y1: elev.frame.H } : null);
|
|
51
|
+
|
|
52
|
+
/** Open the wall view of a straight wall, seen from the room side. */
|
|
53
|
+
/** Open a wall's view: from the side a room is on — or `side`, the face to the left (+1) or right (−1) of its A → B. */
|
|
54
|
+
export function openElevation(lid: string, side?: 1 | -1): void {
|
|
55
|
+
if (!elevFrame(planSK(), lid)) { toast('Elevations work on straight walls. Turn the line into a wall first.', { warn: true }); return; }
|
|
56
|
+
cancelTool();
|
|
57
|
+
elev.lid = lid; elev.flip = side != null && side !== (roomSideOf(planSK(), lid) || 1);
|
|
58
|
+
enterFace();
|
|
74
59
|
}
|
|
75
60
|
|
|
76
|
-
/**
|
|
61
|
+
/** Start editing the open wall's face (from the side `elev.flip` says). */
|
|
62
|
+
function enterFace(): void {
|
|
63
|
+
const f = elevFrame(planSK(), elev.lid!, elev.flip)!;
|
|
64
|
+
elev.frame = f;
|
|
65
|
+
// (handed over here, not as this module loads: the view module is still loading then)
|
|
66
|
+
setWallBox(wallBox);
|
|
67
|
+
faceEdit.key = faceKey(f.lid, f.side);
|
|
68
|
+
openFace(planSK(), f.lid, f.side as 1 | -1);
|
|
69
|
+
ed.mode = 'draft'; ed.tool = 'select'; ed.sel = []; ed.hover = null; ed.snapState = null; ed.preview = null; ed.boxSel = null;
|
|
70
|
+
analyze();
|
|
71
|
+
fitView();
|
|
72
|
+
refreshModes(); updateRail(); updateCtx(); updateHint(); updateTopBar(); renderElevation(); requestDraw();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Stop editing the face (a face with nothing on it isn't kept). */
|
|
76
|
+
function leaveFace(): void {
|
|
77
|
+
cancelTool();
|
|
78
|
+
faceEdit.key = null;
|
|
79
|
+
gc(planSK());
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Open the wall a cabinet is on, from its side, with the cabinet selected (a tap on its footprint in the plan). */
|
|
83
|
+
export function openCabinet(key: string, cabId: string): void {
|
|
84
|
+
const { lid, side } = faceKeyParts(key);
|
|
85
|
+
openElevation(lid);
|
|
86
|
+
if (!elevOpen()) return;
|
|
87
|
+
if (elev.frame && elev.frame.side !== side) flipElevation();
|
|
88
|
+
if ((SK() as WallFace).cabs?.[cabId]) { ed.sel = [{ type: 'cab', id: cabId }]; updateCtx(); updateHint(); requestDraw(); }
|
|
89
|
+
toast('This cabinet’s wall — Back returns to the plan.');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Back to the plan, with the wall selected. */
|
|
77
93
|
export function closeElevation(): void {
|
|
78
94
|
if (!elevOpen()) return;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
95
|
+
const lid = elev.lid!;
|
|
96
|
+
leaveFace();
|
|
97
|
+
elev.lid = null; elev.frame = null;
|
|
98
|
+
ed.tool = 'select'; ed.hover = null; ed.preview = null;
|
|
99
|
+
ed.sel = planSK().lines[lid] ? [{ type: 'line', id: lid }] : [];
|
|
100
|
+
analyze();
|
|
101
|
+
refreshModes(); updateRail(); updateCtx(); updateHint(); updateTopBar(); renderElevation(); requestDraw();
|
|
82
102
|
}
|
|
103
|
+
|
|
104
|
+
/** Look at the wall from its other side (each side has its own drawing). */
|
|
83
105
|
export function flipElevation(): void {
|
|
84
106
|
if (!elevOpen()) return;
|
|
85
|
-
|
|
86
|
-
|
|
107
|
+
leaveFace();
|
|
108
|
+
elev.flip = !elev.flip;
|
|
109
|
+
enterFace();
|
|
87
110
|
}
|
|
111
|
+
|
|
88
112
|
/** Fit the wall to the view again. */
|
|
89
|
-
export function fitElevation(): void {
|
|
90
|
-
|
|
113
|
+
export function fitElevation(): void { fitView(); }
|
|
114
|
+
|
|
115
|
+
/** The open wall's frame, from the live plan. Closes the view if the wall is gone (or isn't a straight wall now). */
|
|
91
116
|
export function elevSyncFrame(): ElevFrame | null {
|
|
92
117
|
if (!elevOpen()) return null;
|
|
93
|
-
const f = elevFrame(
|
|
118
|
+
const f = elevFrame(planSK(), elev.lid!, elev.flip);
|
|
94
119
|
if (!f) { closeElevation(); return null; }
|
|
95
120
|
elev.frame = f;
|
|
121
|
+
// a room appeared or went on one side: the side "inside" is the other face now
|
|
122
|
+
const key = faceKey(f.lid, f.side);
|
|
123
|
+
if (faceEdit.key !== key) { faceEdit.key = key; openFace(planSK(), f.lid, f.side as 1 | -1); ed.sel = []; analyze(); }
|
|
96
124
|
return f;
|
|
97
125
|
}
|
|
98
126
|
|
|
99
|
-
/**
|
|
100
|
-
* After drawing: keep the tappable chips, drop a selected dimension that no longer shows and selected things that
|
|
101
|
-
* are gone. Returns the selected dimension's chip, if any.
|
|
102
|
-
*/
|
|
103
|
-
export function elevAfterRender(hits: ElevHit[]): ElevHit | undefined {
|
|
104
|
-
elev.hits = hits;
|
|
105
|
-
let on = elev.active ? hits.find(h => JSON.stringify(h.act) === elev.active) : undefined;
|
|
106
|
-
if (elev.active && !on) { elev.active = null; on = undefined; }
|
|
107
|
-
const sk = SK(), lines = elev.frame ? elevLines(sk, elev.frame) : [];
|
|
108
|
-
elev.objs = elev.objs.filter(o => o.k === 'corner' || (o.k === 'op' ? !!sk.openings[o.id] : lines.some(l => l.id === o.id)));
|
|
109
|
-
return on;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** Whether the trash has something to do: free or remove the selected dimension, or delete selected things. */
|
|
113
|
-
export const elevTrashEnabled = (on?: ElevHit): boolean =>
|
|
114
|
-
on ? !!storedDim(on.act) || !!lockedSill(on.act) : elev.objs.some(o => o.k !== 'corner');
|
|
115
|
-
|
|
116
127
|
/** The view's title: the wall's length, and which side it's seen from. */
|
|
117
128
|
export function elevTitle(): { title: string; sub: string } {
|
|
118
|
-
const sk =
|
|
129
|
+
const sk = planSK(), f = elev.frame!, hasRoom = roomSideOf(sk, elev.lid!) !== 0;
|
|
119
130
|
return {
|
|
120
131
|
title: 'Wall ' + fmtLen(lineLen(sk, sk.lines[elev.lid!])),
|
|
121
132
|
sub: hasRoom ? (f.inside ? 'Seen from inside' : 'Seen from outside') : 'Side ' + (elev.flip ? 2 : 1) + ' of 2',
|
|
122
133
|
};
|
|
123
134
|
}
|
|
124
135
|
|
|
125
|
-
|
|
126
|
-
[...elev.hits].reverse().find(h => x >= h.x && x <= h.x + h.w && y >= h.y && y <= h.y + h.h);
|
|
136
|
+
// ---- keeping what's drawn inside the wall ----
|
|
127
137
|
|
|
128
|
-
|
|
138
|
+
/** The open wall face's edges: across from corner to corner, up from the floor to the ceiling. Null outside the wall view. */
|
|
139
|
+
export function wallBounds(): { x0: number; x1: number; y0: number; y1: number } | null {
|
|
140
|
+
const f = elevOpen() ? elev.frame : null;
|
|
141
|
+
return f ? { x0: f.face[0], x1: f.face[1], y0: 0, y1: f.H } : null;
|
|
142
|
+
}
|
|
129
143
|
|
|
130
|
-
/**
|
|
131
|
-
function
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
if (locked && o.sillLocked) return 'This window is locked along the wall and in height. Select a blue dimension and press Delete to free it.';
|
|
135
|
-
if (o.sillLocked) return 'This window’s height above the floor is locked — it only slides along the wall. Delete the blue sill dimension to free it.';
|
|
136
|
-
return locked ? 'This window is locked along the wall by a dimension — drag it to raise or lower it.' : 'Drag the ' + n + ' to move it along the wall or up and down.';
|
|
144
|
+
/** A point brought inside the wall (as it is, outside the wall view). */
|
|
145
|
+
export function intoWall(x: number, y: number): [number, number] {
|
|
146
|
+
const b = wallBounds();
|
|
147
|
+
return b ? [Math.min(Math.max(x, b.x0), b.x1), Math.min(Math.max(y, b.y0), b.y1)] : [x, y];
|
|
137
148
|
}
|
|
138
149
|
|
|
139
150
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
151
|
+
* How far what's drawn on the face reaches past the wall, inches (0: it's all inside): each point, and each circle's
|
|
152
|
+
* and arc's reach. Edits that make this grow are refused, so nothing is pushed out (a wall made shorter in the plan can
|
|
153
|
+
* leave something outside: it can still be edited, just not pushed further out).
|
|
143
154
|
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const sk = SK(), o = sk.openings[op];
|
|
148
|
-
if (!o) return null;
|
|
149
|
-
const group = slideGroup(sk, op);
|
|
150
|
-
return { op, group, sill: openingHeights(o).sill, lockedH: !group, started: false, cx, cy };
|
|
155
|
+
export function wallOverflow(sk = SK()): Overflow {
|
|
156
|
+
const b = wallBounds();
|
|
157
|
+
return b ? faceOverflow(sk, b) : {};
|
|
151
158
|
}
|
|
152
|
-
function moveDrag(d: Drag, du: number, dz: number): void {
|
|
153
|
-
const sk = SK(), o = sk.openings[d.op], f = elev.frame, g = o && openingSpan(sk, o), l = o && sk.lines[o.line];
|
|
154
|
-
if (!o || !f || !g || !l) return;
|
|
155
|
-
if (!d.started) {
|
|
156
|
-
const stuck = d.lockedH && (o.type === 'door' || !!o.sillLocked);
|
|
157
|
-
if (stuck) { toast(dragHint(d.op)); elev.dragOp = null; return; }
|
|
158
|
-
if (d.lockedH || o.sillLocked) toast(dragHint(d.op));
|
|
159
|
-
d.started = true;
|
|
160
|
-
pushHistory();
|
|
161
|
-
elev.dragOp = d.op;
|
|
162
|
-
elev.active = null;
|
|
163
|
-
if (!elev.objs.some(x => x.k === 'op' && x.id === d.op)) elev.objs = [{ k: 'op', id: d.op }];
|
|
164
|
-
}
|
|
165
|
-
if (d.group) applySlide(sk, d.group, f.mirror ? -du : du);
|
|
166
|
-
if (o.type === 'window' && !o.sillLocked) {
|
|
167
|
-
const { sill, head } = openingHeights(o), q = 1 / settings.denom;
|
|
168
|
-
o.sill = clamp(Math.round((d.sill + dz) / q) * q, 0, Math.max(0, wallHeight(l) - (head - sill)));
|
|
169
|
-
}
|
|
170
|
-
resolveOpeningsNow();
|
|
171
|
-
requestDraw();
|
|
172
|
-
renderElevation();
|
|
173
|
-
}
|
|
174
|
-
// ---- drawing tools ----
|
|
175
|
-
|
|
176
|
-
/** The wall view's toolbar: [tool, label, shortcut, icon]. */
|
|
177
|
-
export const ELEV_RAIL: ([ElevTool, string, string, string] | '|')[] = [
|
|
178
|
-
['select', 'Select', 'V', 'select'], ['door', 'Door', 'B', 'door'], ['window', 'Window', 'N', 'window'],
|
|
179
|
-
['line', 'Line', 'L', 'line'], ['guide', 'Guide line', 'X', 'constr'], '|',
|
|
180
|
-
];
|
|
181
159
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
160
|
+
/**
|
|
161
|
+
* How far things run past their walls, once an edit has been followed through: in the wall view, what's drawn on it;
|
|
162
|
+
* in the plan, the doors and windows (re-placed from their dimensions) and what's drawn on each wall face (brought up
|
|
163
|
+
* to date with the plan). Edits that make this grow are refused — a wall can't be made shorter than what's on it.
|
|
164
|
+
*/
|
|
165
|
+
export function overflow(sk = SK()): Overflow {
|
|
166
|
+
if (elevOpen()) return wallOverflow(sk);
|
|
167
|
+
if (sk !== planSK()) return {};
|
|
168
|
+
resolveOpenings(sk);
|
|
169
|
+
syncFaces(sk, true);
|
|
170
|
+
return planOverflow(sk);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Everything following an edit through can change (see overflow), to put back if the edit is refused. */
|
|
174
|
+
export interface FitState {
|
|
175
|
+
pos: PosSnapshot;
|
|
176
|
+
/** each door and window as it was (its place, sill, width, dimensions: whatever the edit may have changed) */
|
|
177
|
+
ops?: Record<string, string>;
|
|
178
|
+
/** each wall face's positions and where its corners were (what a sync moves; the rest it rebuilds from the plan) */
|
|
179
|
+
faces?: Record<string, { pos: PosSnapshot; wall?: WallFace['wall'] }>;
|
|
180
|
+
marks?: string;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function fitState(sk = SK()): FitState {
|
|
184
|
+
if (elevOpen() || sk !== planSK()) return { pos: snapshotPos(sk) };
|
|
185
|
+
return planFitState(sk);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Everything following a change to the plan through can change (see planFit), whichever view is open. */
|
|
189
|
+
export function planFitState(sk = planSK()): FitState {
|
|
190
|
+
const pos = snapshotPos(sk);
|
|
191
|
+
const ops: FitState['ops'] = {}, faces: FitState['faces'] = {};
|
|
192
|
+
Object.assign(ops, snapOpenings(sk));
|
|
193
|
+
// (copied by hand: React Native has no structuredClone)
|
|
194
|
+
for (const [key, face] of Object.entries(sk.faces ?? {})) faces[key] = { pos: snapshotPos(face), wall: face.wall && { u: [...face.wall.u], ends: [[...face.wall.ends[0]], [...face.wall.ends[1]]] } };
|
|
195
|
+
return { pos, ops, faces, marks: placedMarks() };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Each door and window as it is — its place, sill, width, dimensions: whatever an edit to it may change. */
|
|
199
|
+
function snapOpenings(sk: Sketch): Record<string, string> {
|
|
200
|
+
const out: Record<string, string> = {};
|
|
201
|
+
for (const [id, o] of Object.entries(sk.openings)) out[id] = JSON.stringify(o);
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
/** Put them back as they were — in place: what holds on to a door or window (a drag, a keypad) keeps the same one. */
|
|
205
|
+
function putOpenings(sk: Sketch, snap: Record<string, string>): void {
|
|
206
|
+
for (const [id, v] of Object.entries(snap)) {
|
|
207
|
+
const o = sk.openings[id] as unknown as Record<string, unknown> | undefined;
|
|
208
|
+
if (!o) continue;
|
|
209
|
+
const was = JSON.parse(v) as Record<string, unknown>;
|
|
210
|
+
for (const k of Object.keys(o)) if (!(k in was)) delete o[k];
|
|
211
|
+
Object.assign(o, was);
|
|
212
|
+
}
|
|
203
213
|
}
|
|
204
214
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
215
|
+
export function restoreFit(sk: Sketch, s: FitState): void {
|
|
216
|
+
restorePos(sk, s.pos);
|
|
217
|
+
if (!s.ops) return;
|
|
218
|
+
putOpenings(sk, s.ops);
|
|
219
|
+
for (const [key, v] of Object.entries(s.faces ?? {})) {
|
|
220
|
+
const face = sk.faces?.[key];
|
|
221
|
+
if (!face) continue;
|
|
222
|
+
restorePos(face, v.pos);
|
|
223
|
+
if (v.wall) face.wall = v.wall; else delete face.wall;
|
|
224
|
+
}
|
|
225
|
+
setPlacedMarks(s.marks!);
|
|
226
|
+
forgetSynced();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Limit a move of points (from where they started) so they all stay inside the wall, circles centred on them whole. */
|
|
230
|
+
export function keepInWall(sk: Sketch, ids: string[], start: { x: number; y: number }[], dx: number, dy: number): [number, number] {
|
|
231
|
+
const b = wallBounds();
|
|
232
|
+
if (!b || !ids.length) return [dx, dy];
|
|
233
|
+
let lo = -Infinity, hi = Infinity, dlo = -Infinity, dhi = Infinity;
|
|
234
|
+
ids.forEach((id, i) => {
|
|
235
|
+
const r = Math.max(0, ...Object.values(sk.circles).filter(c => c.c === id).map(c => c.r)), p = start[i];
|
|
236
|
+
lo = Math.max(lo, b.x0 - (p.x - r)); hi = Math.min(hi, b.x1 - (p.x + r));
|
|
237
|
+
dlo = Math.max(dlo, b.y0 - (p.y - r)); dhi = Math.min(dhi, b.y1 - (p.y + r));
|
|
238
|
+
});
|
|
239
|
+
return [lo <= hi ? Math.min(Math.max(dx, lo), hi) : 0, dlo <= dhi ? Math.min(Math.max(dy, dlo), dhi) : 0];
|
|
211
240
|
}
|
|
212
241
|
|
|
213
|
-
|
|
242
|
+
export const PAST_WALL = 'That would run past the edge of the wall.';
|
|
243
|
+
/** A door or window moved or resized in a way that would shove what's tied to it (a cabinet) off its wall. */
|
|
244
|
+
export const PUSHES_OFF = 'That would push what’s tied to it past the edge of the wall.';
|
|
214
245
|
|
|
215
246
|
/**
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
247
|
+
* How far things run past their walls in the plan — doors and windows past their walls' ends, what's on each wall
|
|
248
|
+
* face past its corners, floor and ceiling — once a change to the plan has been followed through (the doors and
|
|
249
|
+
* windows re-placed from their dimensions, the faces brought up to date). Whichever view is open: a door or window
|
|
250
|
+
* changed from the wall view (its width, its distance from a corner) is the plan's.
|
|
219
251
|
*/
|
|
220
|
-
function
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const pts: [number, number][] = [[f.face[0], 0], [f.face[0], f.H], [f.face[1], 0], [f.face[1], f.H]];
|
|
225
|
-
for (const o of ops) pts.push([o.u0, o.sill], [o.u0, o.head], [o.u1, o.sill], [o.u1, o.head]);
|
|
226
|
-
for (const [a, b] of lines) pts.push(a, b, [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2]);
|
|
227
|
-
let best: [number, number] | null = null, bd = R;
|
|
228
|
-
for (const p of pts) { const d = Math.hypot(p[0] - u, p[1] - z); if (d < bd) { bd = d; best = p; } }
|
|
229
|
-
if (best) return { p: [best[0], best[1]], kind: 'pt' };
|
|
230
|
-
const us = [f.face[0], f.face[1], ...ops.flatMap(o => [o.u0, o.u1]), ...lines.flatMap(([a, b]) => [a[0], b[0]])];
|
|
231
|
-
const zs = [0, f.H, ...ops.flatMap(o => [o.sill, o.head]), ...lines.flatMap(([a, b]) => [a[1], b[1]])];
|
|
232
|
-
const near = (v: number, list: number[]) => list.reduce<number | null>((m, x) => (Math.abs(x - v) < R && (m == null || Math.abs(x - v) < Math.abs(m - v)) ? x : m), null);
|
|
233
|
-
const q = 1 / settings.denom, su = near(u, us), sz = near(z, zs);
|
|
234
|
-
let pu = su ?? Math.round(u / q) * q, pz = sz ?? Math.round(z / q) * q, kind: Snapped['kind'] = su != null || sz != null ? 'edge' : null;
|
|
235
|
-
if (from) {
|
|
236
|
-
const du = Math.abs(pu - from[0]), dz = Math.abs(pz - from[1]), tan = Math.tan((6 * Math.PI) / 180);
|
|
237
|
-
if (sz == null && dz < du * tan) { pz = from[1]; kind = 'hv'; }
|
|
238
|
-
else if (su == null && du < dz * tan) { pu = from[0]; kind = 'hv'; }
|
|
239
|
-
}
|
|
240
|
-
return { p: [pu, pz], kind };
|
|
252
|
+
export function planFit(sk = planSK()): Overflow {
|
|
253
|
+
resolveOpenings(sk);
|
|
254
|
+
syncFaces(sk, true);
|
|
255
|
+
return planOverflow(sk);
|
|
241
256
|
}
|
|
242
257
|
|
|
243
|
-
/**
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const id = uid('o');
|
|
257
|
-
// a door swings toward the side you're looking from
|
|
258
|
-
sk.openings[id] = { line: f.lid, at: spot.at, w: NEW_W, type, flip: f.side !== 1, ...(type === 'window' ? { sill: spot.sill } : {}) };
|
|
259
|
-
elev.objs = [{ k: 'op', id }];
|
|
260
|
-
afterEdit();
|
|
258
|
+
/**
|
|
259
|
+
* Make a change to the plan's doors and windows — a width, a distance entered — only if it pushes nothing on a wall
|
|
260
|
+
* past its edges (a cabinet tied to a window would otherwise be shoved off the wall). Taken back, and said, if it
|
|
261
|
+
* would. Returns whether it was made.
|
|
262
|
+
*/
|
|
263
|
+
export function withinWalls(change: () => void): boolean {
|
|
264
|
+
const sk = planSK(), was = planFit(sk), held = planFitState(sk);
|
|
265
|
+
change();
|
|
266
|
+
if (!pushedOut(was, planFit(sk))) return true;
|
|
267
|
+
restoreFit(sk, held);
|
|
268
|
+
planFit(sk);
|
|
269
|
+
toast(PUSHES_OFF, { warn: true });
|
|
270
|
+
return false;
|
|
261
271
|
}
|
|
262
272
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
let best: string | null = null, bd = 9;
|
|
279
|
-
for (const ln of elevLines(sk, f)) {
|
|
280
|
-
const [a, b] = elevLineUZ(f, ln), p = S(T, a[0], a[1]), q = S(T, b[0], b[1]);
|
|
281
|
-
const dx = q[0] - p[0], dy = q[1] - p[1], L2 = dx * dx + dy * dy || 1, t = clamp(((x - p[0]) * dx + (y - p[1]) * dy) / L2, 0, 1);
|
|
282
|
-
const d = Math.hypot(x - (p[0] + dx * t), y - (p[1] + dy * t));
|
|
283
|
-
if (d < bd) { bd = d; best = ln.id; }
|
|
273
|
+
/**
|
|
274
|
+
* Slide a chain of doors and windows along their wall in the plan to `delta` from where it started, no further than
|
|
275
|
+
* what's drawn on the wall's faces can follow without being pushed off them (`base`: what ran past its wall when the
|
|
276
|
+
* slide began; `from`: the last slide that pushed nothing further out). The faces follow as it goes. Returns the
|
|
277
|
+
* slide made.
|
|
278
|
+
*/
|
|
279
|
+
export function slideWithinWalls(sk: Sketch, group: SlideGroup, delta: number, from: number, base: Overflow): number {
|
|
280
|
+
const held = planFitState(sk);
|
|
281
|
+
const tryAt = (v: number) => { applySlide(sk, group, v); return !pushedOut(base, planFit(sk)); };
|
|
282
|
+
if (tryAt(delta)) return delta;
|
|
283
|
+
let lo = 0, hi = 1;
|
|
284
|
+
for (let i = 0; i < 8; i++) {
|
|
285
|
+
const m = (lo + hi) / 2;
|
|
286
|
+
restoreFit(sk, held);
|
|
287
|
+
if (tryAt(from + (delta - from) * m)) lo = m; else hi = m;
|
|
284
288
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
if (h && h.act.k !== 'body' && h.act.k !== 'corner') return h.act;
|
|
292
|
-
const l = lineAt(x, y);
|
|
293
|
-
if (l) return { k: 'eline', id: l };
|
|
294
|
-
return h ? h.act : null;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/** Set a drawn line's length (its first end stays put). */
|
|
298
|
-
function editLineLength(id: string): void {
|
|
299
|
-
const sk = SK(), f = elev.frame, ln = f && elevLines(sk, f).find(l => l.id === id);
|
|
300
|
-
if (!ln) return;
|
|
301
|
-
const cur = Math.hypot(ln.b[0] - ln.a[0], ln.b[1] - ln.a[1]);
|
|
302
|
-
openKeypad({
|
|
303
|
-
title: ln.guide ? 'Guide line length' : 'Line length', initial: fmtLen(cur), selectAll: true, laser: true,
|
|
304
|
-
onDone: v => {
|
|
305
|
-
if (v <= 0) return;
|
|
306
|
-
pushHistory();
|
|
307
|
-
const k = v / (cur || 1);
|
|
308
|
-
ln.b = [ln.a[0] + (ln.b[0] - ln.a[0]) * k, ln.a[1] + (ln.b[1] - ln.a[1]) * k];
|
|
309
|
-
afterEdit();
|
|
310
|
-
},
|
|
311
|
-
});
|
|
289
|
+
// none of the way: back exactly as it was (solved again from there, the faces can land a hair apart — past the wall)
|
|
290
|
+
restoreFit(sk, held);
|
|
291
|
+
if (lo === 0) return from;
|
|
292
|
+
const to = from + (delta - from) * lo;
|
|
293
|
+
tryAt(to);
|
|
294
|
+
return to;
|
|
312
295
|
}
|
|
296
|
+
/** In the plan: a wall made shorter than what's on it. */
|
|
297
|
+
export const TOO_SHORT = 'The wall can’t be shorter than what’s on it. Move or remove things on it first.';
|
|
298
|
+
/** The right message for an edit refused by overflow(). */
|
|
299
|
+
export const pastWallMsg = (): string => (elevOpen() ? PAST_WALL : TOO_SHORT);
|
|
300
|
+
|
|
301
|
+
// ---- the dimension chips ----
|
|
313
302
|
|
|
314
303
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
304
|
+
* What can be tapped in the wall view, in canvas pixels, for tests: the doors' and windows' bodies, cabinets, the
|
|
305
|
+
* wall's corners (its end edges), and the dimension chips as last drawn (with their look).
|
|
317
306
|
*/
|
|
318
|
-
function
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
elev.objs = [];
|
|
328
|
-
selectDim(a);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/** Select an elevation dimension (null clears): yellow border and the bar with its name and the yellow +. */
|
|
332
|
-
function selectDim(a: ElevAct | null): void {
|
|
333
|
-
elev.active = a ? JSON.stringify(a) : null;
|
|
334
|
-
renderElevation();
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/** What the + does for the selected objects, with the bar's name for it (null: nothing to dimension). */
|
|
338
|
-
function objPlan(): { name: string; run: () => void } | null {
|
|
339
|
-
const sk = SK(), f = elev.frame, objs = elev.objs;
|
|
340
|
-
if (!f || !objs.length) return null;
|
|
341
|
-
const ops = elevOpenings(sk, f), seen = (id: string) => ops.find(o => o.id === id);
|
|
342
|
-
const label = (id: string) => (sk.openings[id].type === 'door' ? 'Door' : 'Window');
|
|
343
|
-
const opsSel = objs.filter((o): o is { k: 'op'; id: string } => o.k === 'op').map(o => seen(o.id)).filter((o): o is ElevOpening => !!o);
|
|
344
|
-
const corners = objs.filter((o): o is { k: 'corner'; end: 'a' | 'b' } => o.k === 'corner');
|
|
345
|
-
const lines = objs.filter((o): o is { k: 'line'; id: string } => o.k === 'line');
|
|
346
|
-
if (objs.length === 1 && lines.length === 1) {
|
|
347
|
-
const ln = elevLines(sk, f).find(l => l.id === lines[0].id);
|
|
348
|
-
if (!ln) return null;
|
|
349
|
-
return { name: (ln.guide ? 'Guide line ' : 'Line ') + fmtLen(Math.hypot(ln.b[0] - ln.a[0], ln.b[1] - ln.a[1])), run: () => editLineLength(ln.id) };
|
|
307
|
+
export function elevHits(): { x: number; y: number; w: number; h: number; act: ElevAct | { k: 'body'; op: string } | { k: 'cab'; id: string } | { k: 'corner'; end: 'a' | 'b' }; look?: string }[] {
|
|
308
|
+
const f = elev.frame;
|
|
309
|
+
if (!elevOpen() || !f) return [];
|
|
310
|
+
const T = mainT(), out: ReturnType<typeof elevHits> = [];
|
|
311
|
+
for (const o of elevOpenings(planSK(), f)) {
|
|
312
|
+
const [x0, y0] = S(T, o.u0, o.head), [x1, y1] = S(T, o.u1, o.sill);
|
|
313
|
+
out.push({ x: x0, y: y0, w: x1 - x0, h: y1 - y0, act: { k: 'body', op: o.id } });
|
|
350
314
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
return { name: label(l.id) + ' + ' + label(r.id).toLowerCase(), run: () => editElevationPosition(t.op, t.edge, t.ref, 'Space between') };
|
|
315
|
+
for (const id of Object.keys((SK() as WallFace).cabs ?? {})) {
|
|
316
|
+
const b = cabBox(SK() as WallFace, id);
|
|
317
|
+
if (!b) continue;
|
|
318
|
+
const [x0, y0] = S(T, b.u0, b.z1), [x1, y1] = S(T, b.u1, b.z0);
|
|
319
|
+
out.push({ x: x0, y: y0, w: x1 - x0, h: y1 - y0, act: { k: 'cab', id } });
|
|
357
320
|
}
|
|
358
|
-
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
return { name: label(o.id) + ' + corner', run: () => editElevationPosition(o.id, leftCorner ? o.e0 : o.e1, ref, 'Distance from the corner') };
|
|
321
|
+
for (const [u, end] of [[f.face[0], f.leftEnd], [f.face[1], f.leftEnd === 'a' ? 'b' : 'a']] as const) {
|
|
322
|
+
const [x, yTop] = S(T, u, f.H), [, yBot] = S(T, u, 0);
|
|
323
|
+
out.push({ x: x - 10, y: yTop, w: 20, h: yBot - yTop, act: { k: 'corner', end } });
|
|
362
324
|
}
|
|
363
|
-
|
|
364
|
-
return
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (
|
|
374
|
-
if (
|
|
375
|
-
if (
|
|
376
|
-
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
const id = (elev.objs[0] as { id: string }).id;
|
|
380
|
-
actions.push({ icon: 'v', label: 'Height', run: () => editOpeningHeight(id) });
|
|
381
|
-
if (one.type === 'window') actions.push({ icon: 'h', label: 'Sill', run: () => editSill(id) });
|
|
382
|
-
}
|
|
383
|
-
return { label: plan!.name, plus: true, actions };
|
|
325
|
+
for (const h of ed.hitChips) if (h.kind === 'elev') out.push({ x: h.x, y: h.y, w: h.w, h: h.h, act: JSON.parse(h.id) as ElevAct, look: h.part });
|
|
326
|
+
return out;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export const elevAct = (id: string): ElevAct => JSON.parse(id) as ElevAct;
|
|
330
|
+
|
|
331
|
+
/** A chip's name, as the bar shows it. */
|
|
332
|
+
export function elevChipName(a: ElevAct): string {
|
|
333
|
+
if (a.k === 'gap') return a.title;
|
|
334
|
+
if (a.k === 'len') return 'Wall length · set in the floor plan';
|
|
335
|
+
if (a.k === 'wallH') return 'Wall height';
|
|
336
|
+
if (a.k === 'pos') return a.title;
|
|
337
|
+
if (a.k === 'fdim') return 'Dimension';
|
|
338
|
+
if (a.k === 'depth') return 'Cabinet depth · out from the wall';
|
|
339
|
+
const o = planSK().openings[a.op], n = o ? (o.type === 'door' ? 'Door' : 'Window') : '';
|
|
340
|
+
return a.k === 'w' ? n + ' width' : a.k === 'sill' ? n + ' sill height' : n + ' height';
|
|
384
341
|
}
|
|
385
342
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
343
|
+
/** The yellow + on a selected chip: its keypad. */
|
|
344
|
+
export function editElevChip(a: ElevAct): void {
|
|
345
|
+
if (a.k === 'w') editOpeningDim(a.op, 'w');
|
|
346
|
+
else if (a.k === 'sill') editSill(a.op);
|
|
347
|
+
else if (a.k === 'h') editOpeningHeight(a.op);
|
|
348
|
+
else if (a.k === 'wallH') editWallHeight(elev.lid!);
|
|
349
|
+
else if (a.k === 'pos') editElevationPosition(a.op, a.edge, a.ref, a.title);
|
|
350
|
+
else if (a.k === 'gap') dimensionFace(a.kind, a.a, a.b, a.title);
|
|
351
|
+
else if (a.k === 'depth') editCabinetDepth(a.cab);
|
|
352
|
+
else if (a.k === 'len') goToPlan();
|
|
353
|
+
}
|
|
391
354
|
|
|
392
|
-
/** The window whose locked sill height a
|
|
393
|
-
function lockedSill(a: ElevAct
|
|
394
|
-
if (
|
|
395
|
-
const o =
|
|
355
|
+
/** The window whose locked sill height a chip shows, if any. */
|
|
356
|
+
function lockedSill(a: ElevAct) {
|
|
357
|
+
if (a.k !== 'sill') return null;
|
|
358
|
+
const o = planSK().openings[a.op];
|
|
396
359
|
return o && o.sillLocked ? o : null;
|
|
397
360
|
}
|
|
398
361
|
|
|
399
|
-
/** The stored door/window dimension a
|
|
400
|
-
function storedDim(a: ElevAct
|
|
401
|
-
if (
|
|
402
|
-
const o =
|
|
362
|
+
/** The stored door/window dimension a position chip shows, if any. */
|
|
363
|
+
function storedDim(a: ElevAct): { op: string; d: OpeningDim } | null {
|
|
364
|
+
if (a.k !== 'pos') return null;
|
|
365
|
+
const o = planSK().openings[a.op], d = o && (o.dims || []).find(x => x.edge === a.edge && sameRef(x.ref, a.ref));
|
|
403
366
|
return d ? { op: a.op, d } : null;
|
|
404
367
|
}
|
|
405
368
|
|
|
406
|
-
/**
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
*/
|
|
410
|
-
export function
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
369
|
+
/** Whether the trash does something for a selected chip: frees a locked one, or removes a reference. */
|
|
370
|
+
export const elevChipDeletable = (a: ElevAct): boolean => !!storedDim(a) || !!lockedSill(a);
|
|
371
|
+
|
|
372
|
+
/** The trash on a selected chip: a locked door/window dimension is freed (it stays as a reference), a reference is removed, a locked sill is freed. */
|
|
373
|
+
export function deleteElevChip(a: ElevAct): void {
|
|
374
|
+
// a cabinet's entered depth: back to the standard one (grey), as an entered size is wiped
|
|
375
|
+
if (a.k === 'depth') {
|
|
376
|
+
const cb = (SK() as WallFace).cabs?.[a.cab];
|
|
377
|
+
if (!cb) return;
|
|
378
|
+
if (!cb.depthSet) { toast('That’s the standard depth. Tap + to enter one.', { warn: true }); return; }
|
|
415
379
|
pushHistory();
|
|
416
|
-
|
|
417
|
-
const key = elev.frame && elevKey(elev.frame.lid, elev.frame.side);
|
|
418
|
-
if (key && sk.elev?.[key]) sk.elev[key] = sk.elev[key].filter(l => !doomedLines.includes(l.id));
|
|
419
|
-
elev.objs = elev.objs.filter(o => o.k === 'corner');
|
|
420
|
-
ed.sel = ed.sel.filter(x => !(x.type === 'opening' && doomed.includes(x.id)));
|
|
380
|
+
cb.depth = CAB.d; cb.depthSet = false;
|
|
421
381
|
afterEdit();
|
|
422
|
-
|
|
423
|
-
toast(what + ' deleted', { action: { label: 'Undo', fn: () => undo() } });
|
|
382
|
+
toast('Depth cleared — back to the standard ' + fmtLen(CAB.d) + '.', { action: { label: 'Undo', fn: () => undo() } });
|
|
424
383
|
return;
|
|
425
384
|
}
|
|
426
|
-
const a = elev.active ? (JSON.parse(elev.active) as ElevAct) : null, s = storedDim(a);
|
|
427
385
|
const ls = lockedSill(a);
|
|
428
|
-
if (ls) {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
toast('Sill height freed — drag the window to raise or lower it.');
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
if (!s) { if (a) toast('Only locked dimensions and door/window position dimensions can be deleted here.'); return; }
|
|
436
|
-
const o = SK().openings[s.op], name = o.type === 'door' ? 'door' : 'window';
|
|
386
|
+
if (ls) { pushHistory(); ls.sillLocked = false; afterEdit(); toast('Sill height freed — drag the window to raise or lower it.'); return; }
|
|
387
|
+
const s = storedDim(a);
|
|
388
|
+
if (!s) { toast('Only locked dimensions and door/window position dimensions can be deleted here.', { warn: true }); return; }
|
|
389
|
+
const o = planSK().openings[s.op], name = o.type === 'door' ? 'door' : 'window';
|
|
437
390
|
pushHistory();
|
|
438
391
|
if (s.d.driving) { s.d.driving = false; afterEdit(); toast('Now a reference — it no longer sets the ' + name + '’s position.'); }
|
|
439
|
-
else { o.dims = (o.dims || []).filter(x => x !== s.d); afterEdit(); toast('Dimension removed'); }
|
|
392
|
+
else { o.dims = (o.dims || []).filter(x => x !== s.d); ed.sel = []; afterEdit(); toast('Dimension removed'); }
|
|
440
393
|
}
|
|
441
394
|
|
|
442
395
|
/** Back to the floor plan with this wall selected, ready for its + (where its length is set). */
|
|
443
396
|
function goToPlan(): void {
|
|
444
|
-
const lid = elev.lid;
|
|
445
397
|
closeElevation();
|
|
446
|
-
if (!lid) return;
|
|
447
|
-
ed.sel = [{ type: 'line', id: lid }];
|
|
448
|
-
updateCtx(); requestDraw();
|
|
449
398
|
toast('Tap + to change the wall’s length.');
|
|
450
399
|
}
|
|
451
400
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
401
|
+
// ---- doors and windows on the wall ----
|
|
402
|
+
|
|
403
|
+
/** Where a new door/window would go for a pointer at (u, z): centre s along the wall, and the window's sill. */
|
|
404
|
+
export function openingAt(type: 'door' | 'window', u: number, z: number, tol = 0): { at: number; sill: number } | null {
|
|
405
|
+
const f = elev.frame!, w = NEW_W;
|
|
406
|
+
if (f.L < w + 2) return null;
|
|
407
|
+
// snapped (Object snapping) as a door or window dragged on the wall is: its sides to the corners and the other
|
|
408
|
+
// doors', windows' and cabinets' sides; a window's sill and head to the floor, the ceiling, cabinet tops and other
|
|
409
|
+
// windows' (a door sits on the floor)
|
|
410
|
+
const raw = type === 'door' ? 0 : z - WINDOW_H / 2, h = type === 'door' ? DOOR_H : WINDOW_H;
|
|
411
|
+
const [du, dz] = tol > 0 ? snapObjectMove({}, { u0: u - w / 2, u1: u + w / 2, z0: raw, z1: raw + h }, 0, 0, tol) : [0, 0];
|
|
412
|
+
const at = clamp(toU(f, u + du), w / 2, f.L - w / 2);
|
|
413
|
+
const q = 1 / settings.denom, sill = type === 'door' ? 0 : clamp(Math.round((raw + dz) / q) * q, 0, Math.max(0, f.H - WINDOW_H));
|
|
414
|
+
return { at, sill };
|
|
462
415
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
416
|
+
|
|
417
|
+
function placeOpening(type: 'door' | 'window', u: number, z: number, tol = 0): void {
|
|
418
|
+
const sk = planSK(), f = elev.frame!, spot = openingAt(type, u, z, tol);
|
|
419
|
+
if (!spot) { toast('That wall is too short for a ' + fmtLen(NEW_W) + ' ' + type + '.', { warn: true }); return; }
|
|
420
|
+
pushHistory();
|
|
421
|
+
const id = uid('o');
|
|
422
|
+
// a door swings toward the side you're looking from
|
|
423
|
+
sk.openings[id] = { line: f.lid, at: spot.at, w: NEW_W, wSet: false, type, flip: f.side !== 1, ...(type === 'window' ? { sill: spot.sill } : {}) };
|
|
424
|
+
// (placed, not selected: tap it to size it)
|
|
425
|
+
ed.sel = [];
|
|
426
|
+
afterEdit();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const nameOf = (op: string) => (planSK().openings[op].type === 'door' ? 'door' : 'window');
|
|
430
|
+
|
|
431
|
+
/** What dragging an opening will do, given its locks. */
|
|
432
|
+
function dragHint(op: string): string {
|
|
433
|
+
const sk = planSK(), o = sk.openings[op], locked = !slideGroup(sk, op), n = nameOf(op);
|
|
434
|
+
if (o.type === 'door') return locked ? 'This door is locked by a dimension. Change the dimension, or make it a reference, to move it.' : 'Drag the door to slide it along the floor.';
|
|
435
|
+
if (locked && o.sillLocked) return 'This window is locked along the wall and in height. Select a blue dimension and press Delete to free it.';
|
|
436
|
+
if (o.sillLocked) return 'This window’s height above the floor is locked — it only slides along the wall. Delete the blue sill dimension to free it.';
|
|
437
|
+
return locked ? 'This window is locked along the wall by a dimension — drag it to raise or lower it.' : 'Drag the ' + n + ' to move it along the wall or up and down.';
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Dragging a door or window on the wall: along it — or, if it's locked to other openings, the whole free chain it's
|
|
442
|
+
* part of (a dimension between openings fixes their spacing, not where they sit) — unless the chain is locked to the
|
|
443
|
+
* wall itself. Windows also move up and down; doors stay on the floor. The sill snaps to the display precision.
|
|
444
|
+
*/
|
|
445
|
+
export interface OpeningDrag {
|
|
446
|
+
op: string; group: SlideGroup | null; sill: number; lockedH: boolean; started: boolean; box: { u0: number; u1: number; z0: number; z1: number } | null;
|
|
447
|
+
/** what on the wall was past it when the drag began, and the last move that pushed nothing further out */
|
|
448
|
+
base?: Overflow; last?: { du: number; dz: number };
|
|
449
|
+
}
|
|
450
|
+
export function startOpeningDrag(op: string): OpeningDrag | null {
|
|
451
|
+
const sk = planSK(), o = sk.openings[op];
|
|
452
|
+
if (!o) return null;
|
|
453
|
+
const group = slideGroup(sk, op), e = elev.frame ? elevOpenings(sk, elev.frame).find(x => x.id === op) : null;
|
|
454
|
+
return { op, group, sill: openingHeights(o).sill, lockedH: !group, started: false, box: e ? { u0: e.u0, u1: e.u1, z0: e.sill, z1: e.head } : null };
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Move a drag to (du, dz) inches from where it started, snapping to corners and the other objects (within `tol`
|
|
458
|
+
* inches). Returns false if it can't move at all (a locked door).
|
|
459
|
+
*/
|
|
460
|
+
export function moveOpeningDrag(d: OpeningDrag, du: number, dz: number, tol = 0): boolean {
|
|
461
|
+
if (d.box && tol > 0) [du, dz] = snapObjectMove({ op: d.op }, d.box, du, dz, tol);
|
|
462
|
+
const sk = planSK(), o = sk.openings[d.op], f = elev.frame, g = o && openingSpan(sk, o), l = o && sk.lines[o.line];
|
|
463
|
+
if (!o || !f || !g || !l) return false;
|
|
464
|
+
if (!d.started) {
|
|
465
|
+
if (d.lockedH && (o.type === 'door' || !!o.sillLocked)) { toast(dragHint(d.op), { warn: true }); return false; }
|
|
466
|
+
if (d.lockedH || o.sillLocked) toast(dragHint(d.op), { warn: true });
|
|
467
|
+
d.started = true;
|
|
515
468
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
469
|
+
const face = faceEdit.key ? SK() : null;
|
|
470
|
+
/** The opening at (u, z) from where it started, and what's drawn on the face following it (cabinets tied to it). */
|
|
471
|
+
const place = (u: number, z: number) => {
|
|
472
|
+
// (a slide is measured from where the chain started)
|
|
473
|
+
if (d.group) applySlide(sk, d.group, f.mirror ? -u : u);
|
|
474
|
+
if (o.type === 'window' && !o.sillLocked) {
|
|
475
|
+
// kept between the floor and the ceiling — but one already past them (pushed there before) isn't yanked back
|
|
476
|
+
// at the first touch: that dragged whatever's tied to it along, through the floor
|
|
477
|
+
const { sill, head } = openingHeights(o), q = 1 / settings.denom;
|
|
478
|
+
o.sill = clamp(Math.round((d.sill + z) / q) * q, Math.min(0, d.sill), Math.max(0, wallHeight(l) - (head - sill), d.sill));
|
|
479
|
+
}
|
|
480
|
+
resolveOpeningsNow();
|
|
481
|
+
// what's drawn on the face follows the opening's corners as it moves
|
|
482
|
+
if (faceEdit.key) syncFace(sk, faceEdit.key);
|
|
483
|
+
};
|
|
484
|
+
if (!face) { place(du, dz); requestDraw(); return true; }
|
|
485
|
+
// what's tied to it (a cabinet a set distance below a window) can't be pushed off the wall — past its floor,
|
|
486
|
+
// ceiling or ends: the opening goes as far as that allows and stops there, as a cabinet dragged to the edge does
|
|
487
|
+
d.base ??= wallOverflow(face);
|
|
488
|
+
const from = d.last ?? { du: 0, dz: 0 }, held = holdFace(sk, face);
|
|
489
|
+
const at = (t: number) => ({ du: from.du + (du - from.du) * t, dz: from.dz + (dz - from.dz) * t });
|
|
490
|
+
const fits = () => !pushedOut(d.base!, wallOverflow(face));
|
|
491
|
+
place(du, dz);
|
|
492
|
+
let to = { du, dz };
|
|
493
|
+
if (!fits()) {
|
|
494
|
+
let lo = 0, hi = 1;
|
|
495
|
+
for (let i = 0; i < 8; i++) {
|
|
496
|
+
const m = (lo + hi) / 2;
|
|
497
|
+
putBack(sk, face, held); place(at(m).du, at(m).dz);
|
|
498
|
+
if (fits()) lo = m; else hi = m;
|
|
499
|
+
}
|
|
500
|
+
putBack(sk, face, held);
|
|
501
|
+
// (none of the way: left exactly as it was — solved again, it can land a hair apart)
|
|
502
|
+
to = at(lo);
|
|
503
|
+
if (lo > 0) place(to.du, to.dz);
|
|
525
504
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
505
|
+
d.last = to;
|
|
506
|
+
requestDraw();
|
|
507
|
+
return true;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** The doors' and windows' places in the plan and what's drawn on the face, to put back if a move is taken back. */
|
|
511
|
+
function holdFace(sk: Sketch, face: Sketch) {
|
|
512
|
+
return { ops: snapOpenings(sk), pos: snapshotPos(face), marks: placedMarks() };
|
|
513
|
+
}
|
|
514
|
+
function putBack(sk: Sketch, face: Sketch, h: ReturnType<typeof holdFace>): void {
|
|
515
|
+
putOpenings(sk, h.ops);
|
|
516
|
+
restorePos(face, h.pos);
|
|
517
|
+
setPlacedMarks(h.marks);
|
|
518
|
+
forgetSynced();
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Where a door or window sliding along its wall in the plan can snap its edges: the wall's ends, its corners on both
|
|
523
|
+
* sides, and the edges of the other doors and windows on it — not those sliding with it (locked to it in a chain).
|
|
524
|
+
* Empty when Object snapping is off.
|
|
525
|
+
*/
|
|
526
|
+
/**
|
|
527
|
+
* Where a door or window placed on wall `lid` in the plan snaps its edges (Object snapping): the wall's ends, its
|
|
528
|
+
* corners on both sides, and the edges of the doors and windows already on it — as one slid along it does.
|
|
529
|
+
*/
|
|
530
|
+
export function placeTargets(sk: Sketch, lid: string): number[] {
|
|
531
|
+
const l = sk.lines[lid];
|
|
532
|
+
if (!l || !settings.layers.objSnap) return [];
|
|
533
|
+
const A = sk.points[l.a], B = sk.points[l.b], out = [0, Math.hypot(B.x - A.x, B.y - A.y)];
|
|
534
|
+
for (const side of [1, -1] as const) { const wf = wallFace(sk, lid, side); if (wf) out.push(wf.s0, wf.s1); }
|
|
535
|
+
for (const x of Object.values(sk.openings)) {
|
|
536
|
+
if (x.line !== lid) continue;
|
|
537
|
+
const g = openingSpan(sk, x);
|
|
538
|
+
if (g) out.push(edgeS(x, g.w, 's0'), edgeS(x, g.w, 's1'));
|
|
530
539
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
540
|
+
return out;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export function slideTargets(sk: Sketch, op: string, group: SlideGroup): number[] {
|
|
544
|
+
const o = sk.openings[op], l = o && sk.lines[o.line];
|
|
545
|
+
if (!o || !l || !settings.layers.objSnap) return [];
|
|
546
|
+
// which move with it: slide the chain a little and see
|
|
547
|
+
const before = Object.fromEntries(Object.entries(sk.openings).map(([id, x]) => [id, x.at]));
|
|
548
|
+
applySlide(sk, group, group.hi > 0.25 ? 0.25 : group.lo < -0.25 ? -0.25 : (group.hi || group.lo)); resolveOpeningsNow();
|
|
549
|
+
const moving = new Set(Object.keys(sk.openings).filter(id => Math.abs(sk.openings[id].at - before[id]) > 1e-9));
|
|
550
|
+
applySlide(sk, group, 0); resolveOpeningsNow();
|
|
551
|
+
const A = sk.points[l.a], B = sk.points[l.b], out = [0, Math.hypot(B.x - A.x, B.y - A.y)];
|
|
552
|
+
for (const side of [1, -1] as const) { const wf = wallFace(sk, o.line, side); if (wf) out.push(wf.s0, wf.s1); }
|
|
553
|
+
for (const [id, x] of Object.entries(sk.openings)) {
|
|
554
|
+
if (x.line !== o.line || moving.has(id) || id === op) continue;
|
|
555
|
+
const g = openingSpan(sk, x);
|
|
556
|
+
if (g) out.push(edgeS(x, g.w, 's0'), edgeS(x, g.w, 's1'));
|
|
547
557
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
558
|
+
return out;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/** A slide `delta` of a door or window (centre `at0`, width `w`, when the drag began) pulled so an edge meets the nearest target within `tol`. */
|
|
562
|
+
export function snapSlide(at0: number, w: number, delta: number, targets: number[], tol: number): number {
|
|
563
|
+
let best: number | null = null;
|
|
564
|
+
for (const e of [at0 + delta - w / 2, at0 + delta + w / 2]) for (const t of targets) if (Math.abs(t - e) < tol && (best == null || Math.abs(t - e) < Math.abs(best))) best = t - e;
|
|
565
|
+
return delta + (best ?? 0);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// ---- the wall tools ----
|
|
569
|
+
|
|
570
|
+
/** A ghost of what a placing tool would put at the pointer. */
|
|
571
|
+
function ghost(c: DrawCtx, T: Xform, u0: number, z0: number, w: number, h: number, label?: string): void {
|
|
572
|
+
const [x0, y0] = S(T, u0, z0 + h), [x1, y1] = S(T, u0 + w, z0);
|
|
573
|
+
c.save();
|
|
574
|
+
c.fillStyle = 'rgba(0,102,255,.08)'; c.fillRect(x0, y0, x1 - x0, y1 - y0);
|
|
575
|
+
c.strokeStyle = TH.blue; c.lineWidth = 1.5; c.setLineDash([6, 4]); c.strokeRect(x0, y0, x1 - x0, y1 - y0);
|
|
576
|
+
c.restore();
|
|
577
|
+
if (label) previewChip(c, label, (x0 + x1) / 2, y0 - 16);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/** On the wall (with a little slack), or not. */
|
|
581
|
+
const onWall = (u: number, z: number): boolean => { const f = elev.frame; return !!f && z >= -2 && z <= f.H + 2 && u >= f.face[0] - 2 && u <= f.face[1] + 2; };
|
|
582
|
+
|
|
583
|
+
interface PlacingState { down?: PEv; far?: boolean }
|
|
584
|
+
|
|
585
|
+
/** A tool that does something where the wall is tapped: a ghost follows the pointer, a tap acts (a drag doesn't). */
|
|
586
|
+
/**
|
|
587
|
+
* A tool that places something where the wall is tapped, a ghost of it following the pointer first. `tol`: how near
|
|
588
|
+
* (inches) it snaps to what's on the wall — a finger's reach or a mouse's, as a drag snaps (Object snapping).
|
|
589
|
+
*/
|
|
590
|
+
function placingTool(o: { preview: (c: DrawCtx, T: Xform, u: number, z: number, tol: number) => void; place: (u: number, z: number, tol: number) => void; hint: string }): Tool {
|
|
591
|
+
const tolOf = (ev: PEv) => (ev.touch ? 16 : 10) / mainT().s;
|
|
592
|
+
return {
|
|
593
|
+
st: {} as PlacingState,
|
|
594
|
+
reset() { this.st = {}; ed.preview = null; },
|
|
595
|
+
hover(ev: PEv) {
|
|
596
|
+
const tol = tolOf(ev);
|
|
597
|
+
ed.preview = onWall(ev.wx, ev.wy) ? (c, T) => o.preview(c, T, ev.wx, ev.wy, tol) : null;
|
|
598
|
+
requestOverlayDraw();
|
|
599
|
+
},
|
|
600
|
+
down(ev: PEv) { this.st = { down: ev, far: false }; this.hover!(ev); },
|
|
601
|
+
move(ev: PEv) {
|
|
602
|
+
const st = this.st as PlacingState;
|
|
603
|
+
if (st.down && Math.hypot(ev.sx - st.down.sx, ev.sy - st.down.sy) > (ev.touch ? 12 : 6)) st.far = true;
|
|
604
|
+
this.hover!(ev);
|
|
605
|
+
},
|
|
606
|
+
up(ev: PEv) {
|
|
607
|
+
const st = this.st as PlacingState;
|
|
608
|
+
this.st = {};
|
|
609
|
+
if (ev.touch) ed.preview = null;
|
|
610
|
+
requestOverlayDraw();
|
|
611
|
+
if (!st.down || st.far) return;
|
|
612
|
+
if (!onWall(ev.wx, ev.wy)) { toast('Tap on the wall to place it.', { warn: true }); return; }
|
|
613
|
+
o.place(ev.wx, ev.wy, tolOf(ev));
|
|
614
|
+
},
|
|
615
|
+
hint: () => o.hint,
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
const openingTool = (type: 'door' | 'window'): Tool => placingTool({
|
|
620
|
+
preview(c, T, u, z, tol) {
|
|
621
|
+
const spot = openingAt(type, u, z, tol), f = elev.frame;
|
|
622
|
+
if (!spot || !f) return;
|
|
623
|
+
const a = toU(f, spot.at - NEW_W / 2), b = toU(f, spot.at + NEW_W / 2);
|
|
624
|
+
ghost(c, T, Math.min(a, b), spot.sill, NEW_W, type === 'door' ? DOOR_H : WINDOW_H);
|
|
625
|
+
},
|
|
626
|
+
place: (u, z, tol) => placeOpening(type, u, z, tol),
|
|
627
|
+
hint: type === 'door' ? 'Tap the wall to place a 3\'-0" door. It sits on the floor where you tap.' : 'Tap the wall to place a 3\'-0" window, centered where you tap.',
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
export const wallDoorTool = openingTool('door');
|
|
631
|
+
export const wallWindowTool = openingTool('window');
|
|
632
|
+
|
|
633
|
+
export const cabinetTool = placingTool({
|
|
634
|
+
preview(c, T, u, z) { const spot = cabinetSpot(u, z); if (spot) ghost(c, T, spot.u0, spot.z0, CAB.w, CAB.h, fmtLen(CAB.w) + ' × ' + fmtLen(CAB.h)); },
|
|
635
|
+
place: (u, z) => { addCabinet(u, z); },
|
|
636
|
+
hint: 'Tap the wall to place a cabinet (24" wide, 34½" high, 24" deep) — anywhere, like a window. Tap it, then one of its dimensions, to set it.',
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
export const heightTool = placingTool({
|
|
640
|
+
preview(c, T, _u, z) {
|
|
641
|
+
const f = elev.frame;
|
|
642
|
+
if (!f) return;
|
|
643
|
+
const q = 1 / settings.denom, h = clamp(Math.round(z / q) * q, 0, f.H), [x0, y] = S(T, f.face[0], h), [x1] = S(T, f.face[1], h);
|
|
644
|
+
c.save(); c.strokeStyle = TH.blue; c.lineWidth = 1.5; c.setLineDash([6, 4]); c.beginPath(); c.moveTo(x0, y); c.lineTo(x1, y); c.stroke(); c.restore();
|
|
645
|
+
previewChip(c, fmtLen(h), x1 - 40, y - 16);
|
|
646
|
+
},
|
|
647
|
+
place: (_u, z) => {
|
|
648
|
+
const q = 1 / settings.denom, start = clamp(Math.round(z / q) * q, 0, elev.frame!.H);
|
|
649
|
+
openKeypad({ title: 'Height line', sub: 'Floor to the line — it runs across the whole wall', initial: fmtLen(start), selectAll: true, laser: true, onDone: v => { addHeightLine(v); } });
|
|
650
|
+
},
|
|
651
|
+
hint: 'Tap the wall at a height, then enter it: a level line across the wall (a counter, a rail).',
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
/** The wall view's toolbar: the plan's drawing tools, then what goes on a wall. (The height line tool is kept off it for now.) */
|
|
655
|
+
export const WALL_RAIL: RailItem[] = [
|
|
656
|
+
['select', 'Select', 'V'], ['line', 'Line', 'L'], ['freehand', 'Draw to shape', 'S'], ['rect', 'Rectangle', 'R'], ['circle', 'Circle', 'C'], ['arc', 'Arc', 'A'], '|',
|
|
657
|
+
['dim', 'Dimension', 'D'], ['wdoor', 'Door', 'B'], ['wwindow', 'Window', 'N'], ['cabinet', 'Cabinet', 'K'], '|', ['constr', 'Construction lines', 'X', 'toggle'], '|',
|
|
658
|
+
['undo', 'Undo', '⌘Z', 'act'], ['redo', 'Redo', '⇧⌘Z', 'act'],
|
|
659
|
+
];
|
|
660
|
+
/** Tool letters in the wall view. */
|
|
661
|
+
export const WALL_KEYS: Record<string, string> = { v: 'select', l: 'line', s: 'freehand', r: 'rect', c: 'circle', a: 'arc', d: 'dim', t: 'trim', o: 'offset', b: 'wdoor', n: 'wwindow', k: 'cabinet' };
|
|
662
|
+
/** The icon for a wall tool whose id isn't an icon's name. */
|
|
663
|
+
export const WALL_ICON: Record<string, string> = { wdoor: 'door', wwindow: 'window', height: 'hline' };
|
|
664
|
+
|
|
665
|
+
// ---- what's under the pointer, beyond the face's own geometry ----
|
|
666
|
+
|
|
667
|
+
/** A cabinet (on it, or within `slack` inches of its outline) or a door/window body under a world point on the face (cabinets first). */
|
|
668
|
+
export function wallBodyAt(wx: number, wy: number, slack = 0): Hit | null {
|
|
669
|
+
const face = SK() as WallFace, f = elev.frame;
|
|
670
|
+
if (!f) return null;
|
|
671
|
+
// (inside it: right on its edge picks the edge, as a window's)
|
|
672
|
+
for (const id of Object.keys(face.cabs ?? {}).reverse()) {
|
|
673
|
+
const b = cabBox(face, id);
|
|
674
|
+
if (b && wx > b.u0 && wx < b.u1 && wy > b.z0 && wy < b.z1) return { type: 'cab', id };
|
|
554
675
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
if (tapped) tap(pickAt(down!.x, down!.y), !!e.shift || !!e.mod || e.kind !== 'mouse');
|
|
558
|
-
down = null;
|
|
676
|
+
for (const o of elevOpenings(planSK(), f)) if (wx > o.u0 && wx < o.u1 && wy > o.sill && wy < o.head) return { type: 'opening', id: o.id };
|
|
677
|
+
return null;
|
|
559
678
|
}
|
|
560
679
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
680
|
+
// ---- the bar, the yellow + and the trash for wall things ----
|
|
681
|
+
|
|
682
|
+
export interface WallBarItem { ic: string; label: string; act: string }
|
|
683
|
+
|
|
684
|
+
/** Two doors/windows, or one and a wall end: the + sets the distance between them (the plan's door/window dimension). */
|
|
685
|
+
function wallPair(): { op: string; other: { op: string } | { end: 'a' | 'b' } } | null {
|
|
686
|
+
if (ed.sel.length !== 2) return null;
|
|
687
|
+
const ops = ed.sel.filter(x => x.type === 'opening').map(x => x.id);
|
|
688
|
+
const ends = ed.sel.filter(x => x.type === 'line' && (x.id === '@ea' || x.id === '@eb')).map(x => x.id.slice(2) as 'a' | 'b');
|
|
689
|
+
if (ops.length === 2) return { op: ops[0], other: { op: ops[1] } };
|
|
690
|
+
if (ops.length === 1 && ends.length === 1) return { op: ops[0], other: { end: ends[0] } };
|
|
691
|
+
return null;
|
|
565
692
|
}
|
|
566
693
|
|
|
567
|
-
/**
|
|
568
|
-
export function
|
|
569
|
-
if (
|
|
694
|
+
/** The bar for what's selected on the wall that the plan doesn't know (a door or window, a cabinet, a chip). Null: the plan's bar. */
|
|
695
|
+
export function wallBar(): { label?: string; items: WallBarItem[]; plus: boolean } | null {
|
|
696
|
+
if (!elevOpen()) return null;
|
|
697
|
+
const pair = wallPair();
|
|
698
|
+
if (pair) {
|
|
699
|
+
const name = (id: string) => (planSK().openings[id]?.type === 'door' ? 'Door' : 'Window');
|
|
700
|
+
const label = name(pair.op) + ' + ' + ('op' in pair.other ? name(pair.other.op).toLowerCase() : 'corner');
|
|
701
|
+
return { label, items: [{ ic: 'dim', label: 'Distance', act: 'wallDist' }], plus: true };
|
|
702
|
+
}
|
|
703
|
+
if (ed.sel.length !== 1) return null;
|
|
704
|
+
const s = ed.sel[0], sk = planSK();
|
|
705
|
+
if (s.type === 'elev') {
|
|
706
|
+
const a = elevAct(s.id);
|
|
707
|
+
return { label: elevChipName(a), items: a.k === 'len' ? [{ ic: 'back', label: 'Go to plan', act: 'wallGoPlan' }] : [], plus: a.k !== 'len' };
|
|
708
|
+
}
|
|
709
|
+
// a door, window or cabinet picked as a whole: its sizes to set, by name (no + — it isn't one dimension)
|
|
710
|
+
if (s.type === 'opening') {
|
|
711
|
+
const o = sk.openings[s.id];
|
|
712
|
+
if (!o) return null;
|
|
713
|
+
return { label: openingLabel(o), items: OPENING_SIZES, plus: false };
|
|
714
|
+
}
|
|
715
|
+
if (s.type === 'cab') {
|
|
716
|
+
const face = SK() as WallFace, b = cabBox(face, s.id), cb = face.cabs[s.id];
|
|
717
|
+
return {
|
|
718
|
+
label: 'Cabinet' + (b ? ' ' + fmtLen(b.u1 - b.u0) + ' L × ' + fmtLen(b.z1 - b.z0) + ' H × ' + fmtLen(cb.depth) + ' D' : ''),
|
|
719
|
+
items: [{ ic: 'v', label: 'Height', act: 'cabH' }, { ic: 'h', label: 'Length', act: 'cabW' }, { ic: 'thick', label: 'Depth', act: 'cabD' }], plus: false,
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
const face = SK() as WallFace;
|
|
723
|
+
if (s.type === 'line' && face.lines[s.id]?.anchor) return { label: anchorName(s.id), items: [], plus: false };
|
|
724
|
+
if (s.type === 'line' && face.lines[s.id]?.cab) return { label: 'Cabinet edge', items: [], plus: false };
|
|
725
|
+
if (s.type === 'point' && face.points[s.id]?.anchor) return { label: 'Corner · set by the plan', items: [], plus: false };
|
|
726
|
+
return null;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/** What one of the plan's edges on the face is. */
|
|
730
|
+
function anchorName(id: string): string {
|
|
731
|
+
if (id === '@floor') return 'Floor';
|
|
732
|
+
if (id === '@ceil') return 'Ceiling';
|
|
733
|
+
if (id === '@ea' || id === '@eb') return 'Wall corner';
|
|
734
|
+
const op = planSK().openings[id.split(':')[1]];
|
|
735
|
+
return (op?.type === 'door' ? 'Door' : 'Window') + ' edge';
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/** A door's or window's sizes to set, in the bar (the wall view's and the plan's): its height and its length. */
|
|
739
|
+
export const OPENING_SIZES: WallBarItem[] = [{ ic: 'v', label: 'Height', act: 'opHeight' }, { ic: 'h', label: 'Length', act: 'opLength' }];
|
|
740
|
+
|
|
741
|
+
/** What the bar calls a door or window: its kind and sizes, length by height ("Door 3'-0" L × 6'-8" H"). */
|
|
742
|
+
export function openingLabel(o: Opening): string {
|
|
743
|
+
const { sill, head } = openingHeights(o);
|
|
744
|
+
return (o.type === 'door' ? 'Door ' : 'Window ') + fmtLen(o.w) + ' L × ' + fmtLen(head - sill) + ' H';
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/** Run a bar action for the wall view's things (a door's or window's sizes work in the plan too). Returns false if it isn't one. */
|
|
748
|
+
export function wallAction(act: string): boolean {
|
|
749
|
+
const s = ed.sel[0];
|
|
750
|
+
switch (act) {
|
|
751
|
+
case 'opHeight': editOpeningHeight(s.id); return true;
|
|
752
|
+
case 'opLength': editOpeningDim(s.id, 'w'); return true;
|
|
753
|
+
case 'cabW': editCabinet(s.id, 'w'); return true;
|
|
754
|
+
case 'opSill': editSill(s.id); return true;
|
|
755
|
+
case 'cabH': editCabinet(s.id, 'h'); return true;
|
|
756
|
+
case 'cabD': editCabinetDepth(s.id); return true;
|
|
757
|
+
case 'cabZ': editCabinet(s.id, 'z'); return true;
|
|
758
|
+
case 'wallGoPlan': goToPlan(); return true;
|
|
759
|
+
case 'wallDist': wallPlus(); return true;
|
|
760
|
+
}
|
|
761
|
+
return false;
|
|
570
762
|
}
|
|
571
763
|
|
|
572
|
-
/** The
|
|
573
|
-
export function
|
|
574
|
-
if (!
|
|
575
|
-
|
|
764
|
+
/** The yellow + for wall things. Returns false if the plan's + should handle the selection. */
|
|
765
|
+
export function wallPlus(): boolean {
|
|
766
|
+
if (!elevOpen()) return false;
|
|
767
|
+
const pair = wallPair(), f = elev.frame!;
|
|
768
|
+
if (pair) {
|
|
769
|
+
const ops = elevOpenings(planSK(), f), a = ops.find(o => o.id === pair.op);
|
|
770
|
+
if (!a) return true;
|
|
771
|
+
if ('op' in pair.other) {
|
|
772
|
+
const otherId = pair.other.op, b = ops.find(o => o.id === otherId);
|
|
773
|
+
if (!b) return true;
|
|
774
|
+
const [l, r] = a.u0 <= b.u0 ? [a, b] : [b, a], t = pickBetween(planSK(), l.id, l.e1, r.id, r.e0);
|
|
775
|
+
editElevationPosition(t.op, t.edge, t.ref, 'Space between');
|
|
776
|
+
} else {
|
|
777
|
+
const end = pair.other.end, ref: OpeningRef = { face: end, line: f.lid, side: f.side as 1 | -1 };
|
|
778
|
+
editElevationPosition(a.id, end === f.leftEnd ? a.e0 : a.e1, ref, 'Distance from the corner');
|
|
779
|
+
}
|
|
780
|
+
return true;
|
|
781
|
+
}
|
|
782
|
+
if (ed.sel.length !== 1) return false;
|
|
783
|
+
const s = ed.sel[0];
|
|
784
|
+
if (s.type === 'elev') { editElevChip(elevAct(s.id)); return true; }
|
|
785
|
+
if (s.type === 'opening') { editOpeningDim(s.id, 'w'); return true; }
|
|
786
|
+
if (s.type === 'cab') { editCabinet(s.id, 'w'); return true; }
|
|
787
|
+
return false;
|
|
576
788
|
}
|
|
577
789
|
|
|
578
790
|
/**
|
|
579
|
-
*
|
|
580
|
-
*
|
|
791
|
+
* Delete in the wall view: a selected chip's dimension is freed or removed; doors and windows go from the plan,
|
|
792
|
+
* cabinets from the face, the rest as in the plan. The plan's anchors stay. Returns false outside the wall view.
|
|
581
793
|
*/
|
|
582
|
-
export function
|
|
583
|
-
|
|
584
|
-
if (
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
if (!
|
|
589
|
-
|
|
590
|
-
|
|
794
|
+
export function wallDelete(): boolean {
|
|
795
|
+
if (!elevOpen()) return false;
|
|
796
|
+
if (ed.sel.length === 1 && ed.sel[0].type === 'elev') { deleteElevChip(elevAct(ed.sel[0].id)); return true; }
|
|
797
|
+
const face = SK() as WallFace;
|
|
798
|
+
const anchor = (x: { type: string; id: string }) => (x.type === 'line' && !!face.lines[x.id]?.anchor) || (x.type === 'point' && !!face.points[x.id]?.anchor);
|
|
799
|
+
const items = ed.sel.filter(x => !anchor(x) && x.type !== 'elev');
|
|
800
|
+
if (!items.length) { toast('The wall’s edges and corners come from the plan — they can’t be deleted here.', { warn: true }); return true; }
|
|
801
|
+
const one = items.length === 1 ? items[0] : null, op = one?.type === 'opening' ? planSK().openings[one.id] : null;
|
|
802
|
+
const what = one?.type === 'cab' ? 'Cabinet deleted' : op ? (op.type === 'door' ? 'Door' : 'Window') + ' deleted' : 'Deleted';
|
|
803
|
+
pushHistory();
|
|
804
|
+
deleteSel(planSK(), items.filter(x => x.type === 'opening'));
|
|
805
|
+
deleteCabinets(items.filter(x => x.type === 'cab').map(x => x.id));
|
|
806
|
+
deleteSel(face, items.filter(x => x.type !== 'opening' && x.type !== 'cab'));
|
|
807
|
+
ed.sel = [];
|
|
808
|
+
afterEdit();
|
|
809
|
+
toast(what, { action: { label: 'Undo', fn: () => undo() } });
|
|
810
|
+
return true;
|
|
591
811
|
}
|