feat: add branch overviews scoped outdoor plans and complete room moves
This commit is contained in:
1 parent
382d6e04f2
commit
16eddacebf
35 files changed
+2598
-2116
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { editorFloors, editorScopeChoices, editorScopeFromKey, editorScopeKey, moveSelectedFloor, reconcileEditorContext, scopeForFloor, selectEditorScope, type EditorScope } from "./editor/editor-context.ts";
|
||||
import "./editor/hierarchy-manager.ts";
|
||||
import { floorSelection, floorTopologyPath, normalizeTopology, topologyFloors } from "../topology.ts";
|
||||
import { floorSelection, floorTopologyPath, isOutdoorFloor, normalizeTopology, topologyFloors, topologyItems } from "../topology.ts";
|
||||
// 2D editor: floors, rooms (rectangles and free shapes), snapping, undo, background template.
|
||||
|
||||
import { html, LitElement, nothing, svg, type PropertyValues, type TemplateResult } from "lit";
|
||||
@@ -78,6 +78,7 @@ import "./editor/wall-view.ts";
|
||||
import "./editor/ble-locate.ts";
|
||||
import { LibraryState, renderLibrary, renderPreview, type LibraryActions } from "./editor/forms/library.ts";
|
||||
import { arcFreeWall, arcRoomEdge, insertCorner } from "./editor/ops/rooms.ts";
|
||||
import { moveRoomToFloor, roomMovePosition } from "./editor/ops/room-move.ts";
|
||||
import type { ArcActions, ArcEdit } from "./editor/forms/arc.ts";
|
||||
import { dragStep, facingAngle, gridPositionAfter, hasLeftStart, headingAngle, outlineWithCornerAt, shifted, steppedDelta, straightEnd } from "./editor/ops/drags.ts";
|
||||
import { snapOutdoorMove, snapToPlan, type SnapOptions } from "./editor/ops/snapping.ts";
|
||||
@@ -86,7 +87,7 @@ import { devicesLayer, furnitureLayer, notesLayer } from "./editor/canvas/items.
|
||||
import { dimensionsLayer } from "./editor/canvas/plan.ts";
|
||||
import { renderNoteForm } from "./editor/forms/note.ts";
|
||||
import { openingsLayer } from "./editor/canvas/openings.ts";
|
||||
import { cutMarksLayer, floorBelowLayer, freeWallsLayer, gridLayer, meterLayer, outdoorHandlesLayer, outdoorLayer, roomHandlesLayer, roomsLayer, wallsLayer } from "./editor/canvas/plan.ts";
|
||||
import { cutMarksLayer, floorBelowLayer, freeWallsLayer, gridLayer, meterLayer, outdoorHandlesLayer, outdoorLayer, roomHandlesLayer, roomsLayer, scopeOverviewLayer, wallsLayer } from "./editor/canvas/plan.ts";
|
||||
import { renderEdgeHeights, type EdgeActions } from "./editor/forms/edges.ts";
|
||||
import { clearWallSlope, cutEdge, joinAtCut, moveCut, setPartHeight, setWallHeight, setWallSlope, setWallThickness } from "./editor/ops/edges.ts";
|
||||
import { renderDeviceForm, type DeviceActions } from "./editor/forms/device.ts";
|
||||
@@ -209,6 +210,7 @@ export class NfEditor extends LitElement {
|
||||
_floorId: { state: true },
|
||||
_editorScope: { state: true },
|
||||
_floorMove: { state: true },
|
||||
_roomMove: { state: true },
|
||||
_energyNote: { state: true },
|
||||
_ctx: { state: true },
|
||||
_fixedHint: { state: true },
|
||||
@@ -267,6 +269,7 @@ export class NfEditor extends LitElement {
|
||||
private declare _floorId: string | null;
|
||||
private declare _editorScope: EditorScope | null;
|
||||
private declare _floorMove: {floorId:string;targetId:string} | null;
|
||||
private declare _roomMove: {sourceId:string;roomId:string;buildingId:string;targetId:string;x:number;z:number;error:string} | null;
|
||||
/** What the import from the energy dashboard did (shown under its button). */
|
||||
private declare _energyNote: string | null;
|
||||
/** Open context menu (right-click, long press) at a plan point, for one item. */
|
||||
@@ -333,7 +336,7 @@ export class NfEditor extends LitElement {
|
||||
this.narrow = false;
|
||||
this.roomLabels = true;
|
||||
this._floorId = null;
|
||||
this._editorScope=null;this._floorMove=null;
|
||||
this._editorScope=null;this._floorMove=null;this._roomMove=null;
|
||||
this._arcEdit = null;
|
||||
this._routeDraft = null;
|
||||
this.roof.sectionId = null;
|
||||
@@ -794,6 +797,7 @@ export class NfEditor extends LitElement {
|
||||
if (!this.floor?.rooms.some((r) => r.id === this.sel.room)) this.sel.room = null;
|
||||
}
|
||||
if(changed.has("_doc"))this.syncEditorContext();
|
||||
if(changed.has("_size")&&(this._editorScope?.kind==="branch"||this._editorScope?.kind==="location"))this.fit();
|
||||
}
|
||||
|
||||
protected firstUpdated(): void {
|
||||
@@ -1062,6 +1066,7 @@ export class NfEditor extends LitElement {
|
||||
<nf-view3d
|
||||
.hass=${this.hass ? withSymconWeather(withCoverControls(this.hass, this._doc3d.floors), this._doc3d.settings) : undefined}
|
||||
.building=${this._doc3d}
|
||||
.topologySelection=${this._editorScope}
|
||||
.floorId=${this.houseTool ? null : this._floorId}
|
||||
.roomId=${null}
|
||||
.wallMode=${this.houseTool ? "auto" : this._wall3d}
|
||||
@@ -1158,6 +1163,8 @@ export class NfEditor extends LitElement {
|
||||
const valid=editorScopeFromKey(this._doc,editorScopeKey(scope));if(!valid)return;
|
||||
const next=selectEditorScope(this._doc,valid);
|
||||
this._editorScope=next.scope;this._floorId=next.floorId;
|
||||
if(scope.kind==="branch"||scope.kind==="location")this._tool="select";
|
||||
this.reframe3d=true;
|
||||
this.clearPlanSelection();this.fit();
|
||||
}
|
||||
|
||||
@@ -1167,7 +1174,7 @@ export class NfEditor extends LitElement {
|
||||
}
|
||||
|
||||
private async openFloorMove():Promise<void> {
|
||||
if(!this.isAdmin||!this.floor||this.floor.outdoor_location_id||!this._doc.topology)return;
|
||||
if(!this.isAdmin||!this.floor||isOutdoorFloor(this.floor)||!this._doc.topology)return;
|
||||
this._floorMove={floorId:this.floor.id,targetId:""};await this.updateComplete;
|
||||
const dialog=this.renderRoot.querySelector<HTMLDialogElement>(".nf-floor-move-dialog");
|
||||
if(dialog&&!dialog.open)dialog.showModal();
|
||||
@@ -1181,20 +1188,62 @@ export class NfEditor extends LitElement {
|
||||
this.renderRoot.querySelector<HTMLDialogElement>(".nf-floor-move-dialog")?.close();
|
||||
}
|
||||
|
||||
private async openRoomMove():Promise<void> {
|
||||
if(!this.isAdmin||!this.floor||!this.room)return;
|
||||
this._roomMove={sourceId:this.floor.id,roomId:this.room.id,buildingId:"",targetId:"",x:0,z:0,error:""};
|
||||
await this.updateComplete;
|
||||
this.renderRoot.querySelector<HTMLDialogElement>(".nf-room-move-dialog")?.showModal();
|
||||
}
|
||||
|
||||
private applyRoomMove():void {
|
||||
const move=this._roomMove;
|
||||
if(!this.isAdmin||!move||move.sourceId!==this.floor?.id||move.roomId!==this.room?.id)return;
|
||||
const next=structuredClone(this._doc),target=next.floors.find((f)=>f.id===move.targetId);
|
||||
if(!target||target.building_id!==move.buildingId)return;
|
||||
const error=moveRoomToFloor(next,move.sourceId,move.roomId,move.targetId,[move.x,move.z]);
|
||||
if(error){this._roomMove={...move,error};return;}
|
||||
this.setDoc(next);this.adoptFloor(move.targetId);this.selectItem("room",move.roomId);this.fit();
|
||||
this.renderRoot.querySelector<HTMLDialogElement>(".nf-room-move-dialog")?.close();
|
||||
}
|
||||
|
||||
private renderRoomMoveDialog():TemplateResult {
|
||||
const move=this._roomMove,source=this._doc.floors.find((f)=>f.id===move?.sourceId),room=source?.rooms.find((r)=>r.id===move?.roomId);
|
||||
const buildings=editorScopeChoices(this._doc).filter(([key])=>key.startsWith("building:"));
|
||||
const floors=this._doc.floors.filter((f)=>!isOutdoorFloor(f)&&f.building_id===move?.buildingId&&f.id!==move?.sourceId);
|
||||
return html`<dialog class="nf-room-move-dialog" aria-label="Raum verschieben" @close=${(e:Event)=>{if(!(e.target as HTMLDialogElement).open)this._roomMove=null;}} @keydown=${(e:KeyboardEvent)=>e.stopPropagation()}>
|
||||
<header><h2>Raum verschieben</h2><button class="nf-btn" aria-label="Schließen" @click=${()=>this.renderRoot.querySelector<HTMLDialogElement>(".nf-room-move-dialog")?.close()}>×</button></header>
|
||||
${move&&source&&room?html`<p>${floorTopologyPath(this._doc,source)} / ${room.name}</p>
|
||||
<div class="nf-form">
|
||||
<label class="nf-field nf-wide">Zielgebäude<select class="nf-room-move-building" @change=${(e:Event)=>this._roomMove={...move,buildingId:(e.target as HTMLSelectElement).value,targetId:"",error:""}}>
|
||||
<option value="" .selected=${!move.buildingId}>Gebäude auswählen</option>${buildings.map(([key,name])=>html`<option value=${key.slice(9)} .selected=${move.buildingId===key.slice(9)}>${name}</option>`)}
|
||||
</select></label>
|
||||
<label class="nf-field nf-wide">Zieletage<select class="nf-room-move-floor" ?disabled=${!move.buildingId} @change=${(e:Event)=>{const targetId=(e.target as HTMLSelectElement).value,f=floors.find((f)=>f.id===targetId),[x,z]=f?roomMovePosition(f):[0,0];this._roomMove={...move,targetId,x,z,error:""};}}>
|
||||
<option value="" .selected=${!move.targetId}>${move.buildingId&&!floors.length?"Keine andere Etage in diesem Gebäude":"Etage auswählen"}</option>${floors.map((f)=>html`<option value=${f.id} .selected=${move.targetId===f.id}>${f.name}</option>`)}
|
||||
</select></label>
|
||||
${(["x","z"] as const).map((axis)=>html`<label class="nf-field">${axis.toUpperCase()} (m)<input class="nf-room-move-${axis}" type="number" step="0.05" .value=${String(move[axis])} ?disabled=${!move.targetId} @change=${(e:Event)=>this._roomMove={...move,[axis]:(e.target as HTMLInputElement).valueAsNumber,error:""}} /></label>`)}
|
||||
${hint("Der Raum wird zusammen mit seinen Türen, Fenstern, Möbeln, platzierten Geräten und Notizen verschoben. Datenpunktverknüpfungen bleiben erhalten. X und Z bestimmen die linke obere Ecke auf der Zieletage; vorgeschlagen wird ein freier Platz neben den vorhandenen Räumen.","nf-wide")}
|
||||
${move.error?html`<p class="nf-room-move-error nf-wide" role="alert">${move.error}</p>`:nothing}
|
||||
</div>
|
||||
<button class="nf-btn nf-primary nf-room-move-apply" ?disabled=${!this.isAdmin||!floors.some((f)=>f.id===move.targetId)||![move.x,move.z].every(Number.isFinite)||this.floor?.id!==move.sourceId||this.room?.id!==move.roomId} @click=${()=>this.applyRoomMove()}>Raum „${room.name}“ verschieben</button>`:nothing}
|
||||
</dialog>`;
|
||||
}
|
||||
|
||||
private renderEditorNavigation():TemplateResult|typeof nothing {
|
||||
if(!this._doc.topology)return isSymcon(this.hass)?html`<div class="nf-editor-context"><button class="nf-btn nf-hierarchy-open" @click=${()=>this.openHierarchy()}>Hierarchie</button></div>`:nothing;
|
||||
const scope=this._editorScope,choices=editorScopeChoices(this._doc),floors=editorFloors(this._doc,scope);
|
||||
const label=choices.find(([key])=>key===editorScopeKey(scope))?.[1]??"Gebäude auswählen";
|
||||
const overview=scope?.kind==="branch"||scope?.kind==="location";
|
||||
const label=choices.find(([key])=>key===editorScopeKey(scope))?.[1]??"Ansicht auswählen";
|
||||
return html`<div class="nf-editor-context">
|
||||
<div class="nf-editor-building-row"><label>Gebäude<select class="nf-editor-building-select" aria-label="Gebäude" title=${label} @change=${(e:Event)=>{const s=editorScopeFromKey(this._doc,(e.target as HTMLSelectElement).value);if(s)this.selectBuilding(s);}}>
|
||||
${!scope?html`<option value="">Gebäude auswählen</option>`:nothing}
|
||||
${choices.map(([key,name])=>html`<option value=${key} .selected=${key===editorScopeKey(scope)}>${name}</option>`)}
|
||||
<div class="nf-editor-building-row"><label>Ansicht<select class="nf-editor-building-select" aria-label="Ort, Niederlassung oder Gebäude" title=${label} @change=${(e:Event)=>{const s=editorScopeFromKey(this._doc,(e.target as HTMLSelectElement).value);if(s)this.selectBuilding(s);}}>
|
||||
${!scope?html`<option value="">Ansicht auswählen</option>`:nothing}
|
||||
${choices.map(([key,name])=>html`<option value=${key} .selected=${key===editorScopeKey(scope)}>${key.startsWith("branch:")?"Niederlassung · ":key.startsWith("location:")?"Ort · ":""}${name}</option>`)}
|
||||
</select></label><button class="nf-btn nf-hierarchy-open" @click=${()=>this.openHierarchy()}>Hierarchie</button></div>
|
||||
<nav class="nf-editor-floor-nav" aria-label="Etagen des gewählten Gebäudes">
|
||||
<span class="nf-muted">${scope?.kind==="outside"?"Außenplan":"Etagen"}</span>
|
||||
${[...floors].reverse().map((f)=>html`<button class="nf-chip" data-editor-floor=${f.id} aria-pressed=${f.id===this._floorId} @click=${()=>{this.adoptFloor(f.id);this.fit();}}>${f.name}</button>`)}
|
||||
<nav class="nf-editor-floor-nav" aria-label="Untergeordnete Pläne">
|
||||
<span class="nf-muted">${overview?"Auswahl":scope?.kind==="outside"?"Außenplan":"Etagen"}</span>
|
||||
${overview?topologyItems(this._doc,scope).map((n)=>html`<button class="nf-chip" data-editor-scope=${n.key} @click=${()=>this.selectBuilding(n.selection as EditorScope)}>${n.name}</button>`):[...floors].reverse().map((f)=>html`<button class="nf-chip" data-editor-floor=${f.id} aria-pressed=${f.id===this._floorId} @click=${()=>{this.adoptFloor(f.id);this.fit();}}>${f.name}</button>`)}
|
||||
${scope?.kind==="building"?topologyItems(this._doc,scope).filter((n)=>n.selection.kind==="outside").map((n)=>html`<button class="nf-chip" data-editor-scope=${n.key} @click=${()=>this.selectBuilding(n.selection as EditorScope)}>🌳 Außen</button>`):nothing}
|
||||
${scope?.kind==="building"?html`<button class="nf-btn nf-editor-add-floor" ?disabled=${!this.isAdmin} @click=${()=>this.addFloor(null)}>+ Etage</button>`:nothing}
|
||||
${this.floor&&!this.floor.outdoor_location_id?html`<button class="nf-link nf-editor-move-floor" ?disabled=${!this.isAdmin} @click=${()=>void this.openFloorMove()}>Ausgewählte Etage verschieben…</button>`:nothing}
|
||||
${this.floor&&!isOutdoorFloor(this.floor)?html`<button class="nf-link nf-editor-move-floor" ?disabled=${!this.isAdmin} @click=${()=>void this.openFloorMove()}>Ausgewählte Etage verschieben…</button>`:nothing}
|
||||
</nav>
|
||||
</div>`;
|
||||
}
|
||||
@@ -1208,7 +1257,7 @@ export class NfEditor extends LitElement {
|
||||
@hierarchy-change=${(e:CustomEvent<{building:Building}>)=>{e.stopPropagation();if(this.isAdmin)this.setDoc(e.detail.building);}}
|
||||
@hierarchy-open=${(e:CustomEvent<EditorScope>)=>{e.stopPropagation();this.selectBuilding(e.detail);this.renderRoot.querySelector<HTMLDialogElement>(".nf-hierarchy-dialog")?.close();}}></nf-hierarchy-manager>
|
||||
</dialog>
|
||||
<dialog class="nf-floor-move-dialog" aria-label="Ausgewählte Etage verschieben" @close=${()=>this._floorMove=null} @keydown=${(e:KeyboardEvent)=>e.stopPropagation()}>
|
||||
<dialog class="nf-floor-move-dialog" aria-label="Ausgewählte Etage verschieben" @close=${(e:Event)=>{if(!(e.target as HTMLDialogElement).open)this._floorMove=null;}} @keydown=${(e:KeyboardEvent)=>e.stopPropagation()}>
|
||||
<header><h2>Ausgewählte Etage verschieben</h2><button class="nf-btn" aria-label="Schließen" @click=${()=>this.renderRoot.querySelector<HTMLDialogElement>(".nf-floor-move-dialog")?.close()}>×</button></header>
|
||||
${move&&source?html`<p class="nf-floor-move-source">${floorTopologyPath(this._doc,source)}</p>
|
||||
<label class="nf-field">Zielgebäude<select class="nf-floor-move-target" @change=${(e:Event)=>this._floorMove={...move,targetId:(e.target as HTMLSelectElement).value}}>
|
||||
@@ -1308,7 +1357,8 @@ export class NfEditor extends LitElement {
|
||||
}
|
||||
|
||||
private fit(): void {
|
||||
const pts = this.floor?.rooms.flatMap((r) => r.points) ?? [];
|
||||
const floors=this.floor?[this.floor]:this._doc.topology?editorFloors(this._doc,this._editorScope):[];
|
||||
const pts = floors.flatMap((f)=>[...f.rooms.flatMap((r)=>r.points),...f.outdoor.flatMap((a)=>a.points),...f.furniture.map((p):Vec2=>[p.x,p.z]),...f.placements.map((p):Vec2=>[p.x,p.z])]);
|
||||
const b = pts.length ? bounds(pts) : { x0: 0, z0: 0, x1: 10, z1: 8 };
|
||||
const margin = 1.5;
|
||||
const w = b.x1 - b.x0 + 2 * margin;
|
||||
@@ -1348,6 +1398,8 @@ export class NfEditor extends LitElement {
|
||||
// ------------------------------------------------------------------ pointer input
|
||||
|
||||
private onPointerDown(e: PointerEvent): void {
|
||||
const overview=(e.target as Element)?.closest("[data-overview-floor]")?.getAttribute("data-overview-floor");
|
||||
if(overview){this.adoptFloor(overview);this.fit();return;}
|
||||
// a form is waiting for one place on the plan: this tap is it
|
||||
if (this._pick) {
|
||||
const [sx, sy] = this.localPoint(e);
|
||||
@@ -2256,6 +2308,8 @@ export class NfEditor extends LitElement {
|
||||
|
||||
private readonly onKey = (e: KeyboardEvent) => {
|
||||
const path = e.composedPath();
|
||||
const overview=path.find((el)=>el instanceof Element&&el.hasAttribute("data-overview-floor")) as Element|undefined;
|
||||
if(overview&&(e.key==="Enter"||e.key===" ")){e.preventDefault();this.adoptFloor(overview.getAttribute("data-overview-floor"));this.fit();return;}
|
||||
if (path.some((el) => el instanceof HTMLInputElement || el instanceof HTMLSelectElement || el instanceof HTMLTextAreaElement)) return;
|
||||
if (!this.isConnected || !this.offsetParent) return;
|
||||
if (e.key === "Escape" && this._pick) {
|
||||
@@ -2352,7 +2406,7 @@ export class NfEditor extends LitElement {
|
||||
${outdoorHandlesLayer(ctx, this.outdoorArea, this._tool)}
|
||||
${room && this._tool === "select" ? cutMarksLayer(ctx, room) : nothing}
|
||||
${headroomLayer(ctx, floor)}`
|
||||
: nothing}
|
||||
: this._doc.topology?scopeOverviewLayer(ctx,editorFloors(this._doc,this._editorScope)):nothing}
|
||||
${this._tool === "roof" ? svg`${roofSectionsLayer(ctx, this.roof)}${roofWindowsLayer(ctx, this.roof)}${chimneysLayer(ctx, this.roof)}` : this._tool === "energy" ? svg`${roofSectionsLayer(ctx, this.roof)}${solarLayer(ctx, this.roof)}${energyRoutesLayer(ctx, this.floor, this._doc.energy.routes ?? [], this._routeDraft)}${energyMarkersLayer(ctx, this.floor, this.sel.furniture)}` : nothing}
|
||||
${draftLayer(ctx, sketch, this._tool, this._draft, this._cursor)} ${guidesLayer(ctx, this._guides, this._size)}`;
|
||||
}
|
||||
@@ -2497,6 +2551,7 @@ export class NfEditor extends LitElement {
|
||||
removeCorner: (index) => this.deleteVertex(index),
|
||||
duplicate: () => this.duplicateRoom(),
|
||||
remove: () => this.deleteRoom(),
|
||||
move: () => {if(this.room?.id===room.id)void this.openRoomMove();},
|
||||
rememberView: () => this.rememberRoomView(),
|
||||
applyPackage: (pkg) => this.applyPackage(room, pkg),
|
||||
openSpots: () => {
|
||||
@@ -3260,6 +3315,7 @@ export class NfEditor extends LitElement {
|
||||
const walls = floor ? generateWalls(floor.rooms, { exterior: this._doc.settings.wall_exterior, interior: this._doc.settings.wall_interior }, floor.walls ?? []) : null;
|
||||
return html`
|
||||
${this.renderHierarchyDialogs()}
|
||||
${this.renderRoomMoveDialog()}
|
||||
${renderPreview(this.host, this.lib.preview)}
|
||||
${this._wallView
|
||||
? html`<nf-wall-view .host=${this.host} .doc=${this._doc} .roomId=${this._wallView.roomId} .edge=${this._wallView.edge} @close=${() => (this._wallView = null)}></nf-wall-view>`
|
||||
|
||||
Reference in new issue
Block a user