Files
Pier_v1/src/core/copy-targets.ts
T

60 lines
2.3 KiB
TypeScript

import { COPY_ITEMS, type CopyItem } from './copy';
import { overrideKeys, type PierValues } from './changes';
import type { MemberId } from './shape-options';
/** One pier as a target of 속성 복사. */
export interface CopyCandidate {
name: string;
type: string;
/** A pier without a generated model cannot be regenerated, so it is listed but not selectable. */
hasModel: boolean;
}
export interface TargetCandidate {
name: string;
type: string;
selectable: boolean;
}
/** The piers offered as targets: every other pier. The type is shown so a different type is visible. */
export function copyCandidates(piers: CopyCandidate[], sourceName: string): TargetCandidate[] {
return piers
.filter((p) => p.name !== sourceName)
.map((p) => ({ name: p.name, type: p.type, selectable: p.hasModel }));
}
/** The targets that get the change: ticked by the user, selectable, and visible under the current filter. */
export function selectedTargets(piers: CopyCandidate[], sourceName: string, ticked: Set<string>): string[] {
return copyCandidates(piers, sourceName)
.filter((c) => c.selectable && ticked.has(c.name))
.map((c) => c.name);
}
/** 부재 → 복사 항목. A member with no copy items (기둥, 받침) copies nothing yet. */
export const MEMBER_COPY_ITEMS: Record<MemberId, CopyItem[]> = {
bearing: [],
coping: ['coping-width', 'coping-length', 'coping-h1', 'coping-h2', 'level-width'],
column: [],
footing: ['pile-length', 'pile-rows'],
ground: ['ground-position'],
};
/** Whether the 속성 복사 panel is shown for the 부재: only when it has copy items. */
export function hasCopyItems(member: MemberId): boolean {
return copyItemsFor(member).length > 0;
}
/** The copy items for the selected 부재. */
export function copyItemsFor(member: MemberId): CopyItem[] {
return MEMBER_COPY_ITEMS[member];
}
/**
* The copy items whose values the 기준 pier has changed from the imported default (되돌리기가 보이는 항목).
* They are ticked by default; the user can change the ticks afterwards.
*/
export function copyItemsWithOverrides(source: PierValues): CopyItem[] {
const changed = new Set<string>(overrideKeys(source));
return (Object.keys(COPY_ITEMS) as CopyItem[]).filter((item) => COPY_ITEMS[item].keys.some((k) => changed.has(k)));
}