[208] Wettbewerbs-Abgabe: Bilder auf Layout-Blättern, Plakat-Vorlagen A0/A1, anonyme Abgabe, Satz „WBW-Abgabe“
- Bild-Element im Layout (Layout.images, Data-URL wie ContextImage): Kern layout_image.rs (Dateikopf, Seitenverhältnis, Zuschnitt, dpi), Blatt mit Knopf, Verschieben, Skalieren, HUD; PDF bettet das Original ein (JPEG ohne Neukompression). - Rendering-Dialog: „Ins Layout einsetzen“. - Plakat-Vorlagen A0/A1 hoch/quer (Master mit Raster-Hilfslinien, Kopfzeile mit Kennwort-Feld und Plan x/n, Massstab je Viewport; Kern layout_poster.rs), wählbar in „Neues Layout“. - Project.competition: anonym + Kennwort; Plankopf, PDF-Info (Producer/Datum neutralisiert) und Dateinamen nur mit Kennwort. - Publikationssatz „WBW-Abgabe“ mit allen Plakaten.
This commit is contained in:
39 files changed
+2184
-27
No files matched your search
@@ -0,0 +1,41 @@
|
||||
// Bilder aufs Layout-Blatt setzen ([208]): aus dem Rendering-Dialog („Ins Layout einsetzen"), später auch für
|
||||
// Fotos. Reine Ops-Bildung (`placeImageOps`) getrennt vom Store-Aufruf, damit sie ohne DOM testbar ist.
|
||||
|
||||
import { patchItem, type CoreOp } from "../core";
|
||||
import type { Layout, Project } from "../model/types";
|
||||
import { addImage, createLayoutImage } from "../model/layoutImages";
|
||||
import { effectiveSheetSizeMm, findMaster, sheetLevelOf } from "../model/layoutModel";
|
||||
import { getState } from "./appStore";
|
||||
|
||||
/** Blatt, das beim Einsetzen vorgewählt ist: das Blatt der aktiven Ebene (offenes Layout), sonst das letzte. */
|
||||
export function defaultTargetLayout(project: Pick<Project, "layouts" | "drawingLevels">, activeLevelId: string): Layout | undefined {
|
||||
const layouts = project.layouts ?? [];
|
||||
const level = project.drawingLevels.find((l) => l.id === activeLevelId);
|
||||
return layouts.find((l) => l.id === level?.layoutId) ?? layouts[layouts.length - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ops, die `bytes` (PNG/JPEG) mittig und im Seitenverhältnis auf das Blatt `layoutId` setzen; `null`, wenn das Blatt
|
||||
* fehlt oder die Bytes kein PNG/JPEG sind. `id` ist die Bild-Id (Aufrufer: Zeitstempel).
|
||||
*/
|
||||
export function placeImageOps(project: Project, layoutId: string, name: string, bytes: Uint8Array, id: string, mime = "image/png"): CoreOp[] | null {
|
||||
const layout = (project.layouts ?? []).find((l) => l.id === layoutId);
|
||||
if (!layout) return null;
|
||||
const image = createLayoutImage(id, name, bytes, effectiveSheetSizeMm(findMaster(project, layout) ?? layout), mime);
|
||||
if (!image) return null;
|
||||
return patchItem(project, "layouts", layoutId, (l) => addImage(l, image));
|
||||
}
|
||||
|
||||
/** Setzt das Bild auf das Blatt (ein Undo-Schritt); `false`, wenn nichts eingesetzt werden konnte. */
|
||||
export function placeImageOnLayout(layoutId: string, name: string, bytes: Uint8Array, mime = "image/png"): boolean {
|
||||
const st = getState();
|
||||
const ops = placeImageOps(st.project, layoutId, name, bytes, `img-${Date.now()}`, mime);
|
||||
if (!ops) return false;
|
||||
st.applyChange(ops);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Blatt-Ebene eines Layouts (für „Blatt öffnen" nach dem Einsetzen). */
|
||||
export function layoutSheetLevelId(project: Project, layoutId: string): string | undefined {
|
||||
return sheetLevelOf(project, layoutId)?.id;
|
||||
}
|
||||
@@ -5,9 +5,10 @@ import { addItems, fieldOps, patchItem, patchItems, removeItems } from "../../co
|
||||
import { t } from "../../i18n";
|
||||
import { createLayout, createLayoutFolder, createMasterLayout, deleteFolder as deleteLayoutFolder, deleteMasterFolder, moveLayoutToFolder, moveFolderToFolder, createSheetLevel } from "../../model/layoutModel";
|
||||
import { folderPdfBytes } from "../../export/layoutPdf";
|
||||
import { addPublishSetOps, deletePublishSetOps, patchPublishSetOps, publishSet } from "../publishActions";
|
||||
import { addPublishSetOps, addWbwSetOps, deletePublishSetOps, patchPublishSetOps, publishSet, setCompetitionOps } from "../publishActions";
|
||||
import { openLayoutTab } from "../tabNavigation";
|
||||
import { saveBinaryFile } from "../../native/saveFile";
|
||||
import { createPosterMaster, findPosterMaster, posterTemplate } from "../../model/posterTemplates";
|
||||
import type { FlatHostOpts, HostPart } from "./types";
|
||||
|
||||
export function buildLayoutsHost(c: FlatHostOpts) {
|
||||
@@ -105,10 +106,15 @@ export function buildLayoutsHost(c: FlatHostOpts) {
|
||||
},
|
||||
onCreateLayout: (opts) => {
|
||||
const id = `lay-${Date.now()}`;
|
||||
// Plakat-Vorlage ([208]): der Master der Vorlage wird angelegt, falls das Projekt noch keinen hat.
|
||||
const tpl = opts.posterTemplate ? posterTemplate(opts.posterTemplate) : undefined;
|
||||
const posterMaster = tpl ? (findPosterMaster(project, tpl.key) ?? createPosterMaster(`mas-${tpl.key}`, tpl)) : undefined;
|
||||
const newMaster = posterMaster && !findPosterMaster(project, posterMaster.template ?? "") ? posterMaster : undefined;
|
||||
const masterId = posterMaster?.id ?? opts.masterId;
|
||||
// Bei gebundenem Master erbt das Blatt dessen Papier/Ausrichtung/Grösse.
|
||||
const master = opts.masterId
|
||||
const master = posterMaster ?? (opts.masterId
|
||||
? (project.masterLayouts ?? []).find((m) => m.id === opts.masterId)
|
||||
: undefined;
|
||||
: undefined);
|
||||
const paper = master?.paper ?? opts.paper;
|
||||
const orientation = master?.orientation ?? opts.orientation;
|
||||
const customWidthMm = master ? master.customWidthMm : opts.customWidthMm;
|
||||
@@ -116,13 +122,17 @@ export function buildLayoutsHost(c: FlatHostOpts) {
|
||||
const lay = createLayout(id, t("layouts.defaultName"), paper, orientation);
|
||||
const full = {
|
||||
...lay,
|
||||
...(opts.masterId ? { masterId: opts.masterId } : {}),
|
||||
...(masterId ? { masterId } : {}),
|
||||
...(opts.folderId ? { folderId: opts.folderId } : {}),
|
||||
...(customWidthMm !== undefined && customHeightMm !== undefined
|
||||
? { customWidthMm, customHeightMm }
|
||||
: {}),
|
||||
};
|
||||
applyChange([...addItems("layouts", [full]), ...addItems("drawingLevels", [createSheetLevel(`sheet-${id}`, full)])]);
|
||||
applyChange([
|
||||
...(newMaster ? addItems("masterLayouts", [newMaster]) : []),
|
||||
...addItems("layouts", [full]),
|
||||
...addItems("drawingLevels", [createSheetLevel(`sheet-${id}`, full)]),
|
||||
]);
|
||||
return id;
|
||||
},
|
||||
onCreateMasterLayout: (opts) => {
|
||||
@@ -163,6 +173,12 @@ export function buildLayoutsHost(c: FlatHostOpts) {
|
||||
return id;
|
||||
},
|
||||
onPatchPublishSet: (id, patch) => applyChange((p) => patchPublishSetOps(p, id, patch), `pubset-${id}`),
|
||||
onSetCompetition: (patch) => applyChange((p) => setCompetitionOps(p, patch), "competition"),
|
||||
onAddWbwSet: () => {
|
||||
const id = `pubset-${Date.now()}`;
|
||||
applyChange((p) => addWbwSetOps(p, id));
|
||||
return id;
|
||||
},
|
||||
onSetProjectNumber: (value) => applyChange((p) => fieldOps(p, "projectNumber", value.trim() ? value : undefined), "projectNumber"),
|
||||
onDeletePublishSet: (id) => applyChange((p) => deletePublishSetOps(p, id)),
|
||||
onPublishSet: (id) => {
|
||||
|
||||
@@ -14,6 +14,30 @@ export function addPublishSetOps(p: Project, id: string): CoreOp[] {
|
||||
return fieldOps(p, "publishSets", [...(p.publishSets ?? []), set]);
|
||||
}
|
||||
|
||||
/** Publikationssatz „WBW-Abgabe" ([208]): alle Plakate (Blätter mit Plakat-Master, sonst alle Blätter) als ein PDF. */
|
||||
export function addWbwSetOps(p: Project, id: string): CoreOp[] {
|
||||
const posterMasters = new Set((p.masterLayouts ?? []).filter((m) => m.posterHeader).map((m) => m.id));
|
||||
const posters = (p.layouts ?? []).filter((l) => l.masterId && posterMasters.has(l.masterId));
|
||||
const layoutIds = (posters.length > 0 ? posters : (p.layouts ?? [])).map((l) => l.id);
|
||||
const set: PublishSet = {
|
||||
id,
|
||||
name: t("publish.wbw.name"),
|
||||
layoutIds,
|
||||
format: "pdf-multi",
|
||||
namePattern: "{Projekt}_{Satz}",
|
||||
includeRevision: false,
|
||||
bumpRevision: false,
|
||||
pdfLayers: false,
|
||||
};
|
||||
return fieldOps(p, "publishSets", [...(p.publishSets ?? []), set]);
|
||||
}
|
||||
|
||||
/** Wettbewerbs-Einstellung ([208]) ändern; ohne Kennwort und nicht anonym entfällt das Feld. */
|
||||
export function setCompetitionOps(p: Project, patch: { anonymous?: boolean; keyword?: string }): CoreOp[] {
|
||||
const next = { anonymous: false, keyword: "", ...p.competition, ...patch };
|
||||
return fieldOps(p, "competition", next.anonymous || next.keyword.trim() ? next : undefined);
|
||||
}
|
||||
|
||||
export function patchPublishSetOps(p: Project, id: string, patch: Partial<Omit<PublishSet, "id">>): CoreOp[] {
|
||||
return fieldOps(p, "publishSets", (p.publishSets ?? []).map((s) => (s.id === id ? { ...s, ...patch } : s)));
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import type { CategoryDisplayResolver } from "../core";
|
||||
import type { DetailLevel } from "../model/viewTypes";
|
||||
import type { DisplayResolver } from "../viewport/Viewport3D";
|
||||
import { savePlanPdf } from "../export/exportPdf";
|
||||
import { exportProjectName } from "../export/pdfInfo";
|
||||
import { savePlanSvg } from "../export/exportSvg";
|
||||
import { savePlanDxf } from "../export/exportDxf";
|
||||
import type { ExportPdfDecision } from "../ui/ExportPdfDialog";
|
||||
@@ -110,8 +111,10 @@ export function useExportHandlers(opts: {
|
||||
paper: decision.paper,
|
||||
orientation: decision.orientation,
|
||||
title: activeLevelName,
|
||||
subtitle: getState().project.name,
|
||||
fileName: `${getState().project.name}-${activeLevelName}`,
|
||||
// Wettbewerb anonym ([208]): Kennwort statt Projektname in Schriftfeld und Dateiname.
|
||||
subtitle: exportProjectName(getState().project),
|
||||
fileName: `${exportProjectName(getState().project)}-${activeLevelName}`,
|
||||
competition: getState().project.competition,
|
||||
});
|
||||
setExportOpen(false);
|
||||
};
|
||||
@@ -137,7 +140,7 @@ export function useExportHandlers(opts: {
|
||||
scaleDenominator: decision.scaleDenominator,
|
||||
paper: decision.paper,
|
||||
orientation: decision.orientation,
|
||||
fileName: `${getState().project.name}-${activeLevelName}`,
|
||||
fileName: `${exportProjectName(getState().project)}-${activeLevelName}`,
|
||||
});
|
||||
setExportOpen(false);
|
||||
};
|
||||
@@ -194,7 +197,7 @@ export function useExportHandlers(opts: {
|
||||
dimUnit: decision.dimUnit,
|
||||
paperLayout: decision.paperLayout,
|
||||
levelId: activeLevelId,
|
||||
fileName: `${getState().project.name}-${activeLevelName}`,
|
||||
fileName: `${exportProjectName(getState().project)}-${activeLevelName}`,
|
||||
});
|
||||
} catch (err) {
|
||||
getState().notify(`${t("exportDxf.failed")}: ${err instanceof Error ? err.message : String(err)}`, "error");
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { useEffect, useMemo, useRef } from "react";
|
||||
import type { Layout, LayoutLegend, LayoutTable, LayoutTitleBlock, LayoutViewport } from "../model/types";
|
||||
import type { Layout, LayoutImage, LayoutLegend, LayoutTable, LayoutTitleBlock, LayoutViewport } from "../model/types";
|
||||
import { useStore } from "./appStore";
|
||||
import { addItems, patchItem } from "../core";
|
||||
import type { ProjectSlice } from "./projectSlice";
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
patchTable as patchTableInLayout,
|
||||
removeTable as removeTableFromLayout,
|
||||
} from "../model/layoutModel";
|
||||
import { addImage, patchImage, removeImage } from "../model/layoutImages";
|
||||
import { addLegend, patchLegend, removeLegend } from "../analysis/legend";
|
||||
import { useEventBundle } from "./useEvent";
|
||||
|
||||
@@ -95,6 +96,10 @@ export function useSheetPane(opts: {
|
||||
onPatchTable: (tableId: string, patch: Partial<Omit<LayoutTable, "id">>, coalesceKey?: string) =>
|
||||
patchOpenLayout(openId(), (l) => patchTableInLayout(l, tableId, patch), coalesceKey),
|
||||
onRemoveTable: (tableId: string) => patchOpenLayout(openId(), (l) => removeTableFromLayout(l, tableId)),
|
||||
onAddImage: (image: LayoutImage) => patchOpenLayout(openId(), (l) => addImage(l, image)),
|
||||
onPatchImage: (imageId: string, patch: Partial<Omit<LayoutImage, "id">>, coalesceKey?: string) =>
|
||||
patchOpenLayout(openId(), (l) => patchImage(l, imageId, patch), coalesceKey),
|
||||
onRemoveImage: (imageId: string) => patchOpenLayout(openId(), (l) => removeImage(l, imageId)),
|
||||
onAddViewport: (snapshotId: string, init: Partial<Omit<LayoutViewport, "id" | "snapshotId">>) =>
|
||||
patchOpenLayout(openId(), (l) =>
|
||||
addViewportToLayout(l, createViewport(`vp-${Date.now()}`, snapshotId, init)),
|
||||
|
||||
Reference in new issue
Block a user