Skip to content

armgit / SOMA

Public Imported from GitHub
0

Desktop app for designing parametric 3D models in CadQuery together with the coding agent of your choice

App: Ursprung und Achsen im Viewer, Logs in den Einstellungen

Kai-Jungsthoefelb2b77419fcd3
diff --git a/app/src/renderer/icons.ts b/app/src/renderer/icons.ts
index cde1332..56a3a3a 100644
--- a/app/src/renderer/icons.ts
+++ b/app/src/renderer/icons.ts
@@ -35,7 +35,8 @@ const PATHS: Record<string, string> = {
explode: '<rect x="9" y="9" width="6" height="6" rx="1"/><path d="M4 4l3 3M20 4l-3 3M4 20l3-3M20 20l-3-3M4 8V4h4M16 4h4v4M4 16v4h4M20 16v4h-4"/>',
flip: '<path d="M7 4 3 8l4 4M3 8h14M17 12l4 4-4 4M21 16H7"/>',
camera: '<path d="M4 8h3l2-3h6l2 3h3a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z"/><circle cx="12" cy="13" r="3.5"/>',
- fit: '<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/>', home: '<path d="M3 11 12 4l9 7"/><path d="M5 10v10h14V10"/>',
+ fit: '<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/>',
+ axes: '<path d="M6 18V4M6 18h14M6 18l7.5-7.5"/><path d="m3.5 6.5 2.5-2.5 2.5 2.5M17.5 15.5l2.5 2.5-2.5 2.5"/><circle cx="6" cy="18" r="1.4" fill="currentColor"/>', home: '<path d="M3 11 12 4l9 7"/><path d="M5 10v10h14V10"/>',
x: '<path d="M18 6 6 18M6 6l12 12"/>', plus: '<path d="M12 5v14M5 12h14"/>', minus: '<path d="M5 12h14"/>', send: '<path d="M5 12h14M13 6l6 6-6 6"/>',
history: '<path d="M3 12a9 9 0 1 0 3-6.7L3 8"/><path d="M3 3v5h5M12 7v5l3 2"/>',
term: '<path d="m5 8 4 4-4 4M12 16h7"/>', panel: '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M15 4v16"/>',
diff --git a/app/src/renderer/index.html b/app/src/renderer/index.html
index 3b11f49..4f6b9b0 100644
--- a/app/src/renderer/index.html
+++ b/app/src/renderer/index.html
@@ -178,7 +178,8 @@
<div class="vbtns">
<button data-view="fit" aria-label="Fit all" title="Fit all"><i data-icon="fit"></i></button>
<button data-view="iso" aria-label="Default view" title="Default view (isometric)"><i data-icon="home"></i></button>
- <button id="btn-display" aria-haspopup="menu" aria-expanded="false" aria-label="Display" title="Display: edges, wireframe, transparent and views"><i data-icon="layers"></i></button>
+ <button id="btn-axes" aria-pressed="false" aria-label="Origin and axes" title="Origin and axes: X red, Y green, Z blue"><i data-icon="axes"></i></button>
+ <button id="btn-display" aria-haspopup="menu" aria-expanded="false" aria-label="Display" title="Display: edges, wireframe, transparent, origin and axes, and views"><i data-icon="layers"></i></button>
</div>
</div>
@@ -438,6 +439,7 @@
<button class="mi keep" role="menuitemcheckbox" data-display="edges" aria-checked="true"><span class="chk"><i data-icon="check" data-size="15" data-stroke="2.2"></i></span><span>Edges</span></button>
<button class="mi keep" role="menuitemcheckbox" data-display="wire" aria-checked="false"><span class="chk"><i data-icon="check" data-size="15" data-stroke="2.2"></i></span><span>Wireframe</span></button>
<button class="mi keep" role="menuitemcheckbox" data-display="ghost" aria-checked="false"><span class="chk"><i data-icon="check" data-size="15" data-stroke="2.2"></i></span><span>Transparent</span></button>
+ <button class="mi keep" role="menuitemcheckbox" data-display="axes" aria-checked="false"><span class="chk"><i data-icon="check" data-size="15" data-stroke="2.2"></i></span><span>Origin and axes</span></button>
<div class="msep"></div>
<div class="mh">VIEW</div>
<div class="chips views">
diff --git a/app/src/renderer/main.ts b/app/src/renderer/main.ts
index 215a175..d29bcb3 100644
--- a/app/src/renderer/main.ts
+++ b/app/src/renderer/main.ts
@@ -230,11 +230,19 @@ function applySettings(): void {
/** Darstellung beim Öffnen eines Modells (Menü „Display“). Danach gilt bis zum nächsten Modell, was der Nutzer dort umstellt. */
function applyDisplayDefaults(): void {
const v = appSettings.settings.viewer;
- const want: Record<string, boolean> = { edges: v.edges, wire: v.wireframe, ghost: v.transparent };
+ const want: Record<string, boolean> = { edges: v.edges, wire: v.wireframe, ghost: v.transparent, axes: v.axes };
document.querySelectorAll<HTMLButtonElement>('[data-display]').forEach((b) => b.setAttribute('aria-checked', String(want[b.dataset.display!])));
viewer.setEdges(v.edges);
viewer.setWireframe(v.wireframe);
viewer.setGhost(v.transparent);
+ setAxes(v.axes);
+}
+
+/** Ursprung und Achsen: eigener Knopf neben dem ViewCube und Eintrag im Menü „Display“, beide zeigen denselben Stand. */
+function setAxes(on: boolean): void {
+ $('btn-axes').setAttribute('aria-pressed', String(on));
+ document.querySelector('[data-display="axes"]')?.setAttribute('aria-checked', String(on));
+ viewer.setAxes(on);
}
async function changeSettings(patch: SettingsPatch): Promise<SettingsResult> {
@@ -358,7 +366,8 @@ function fileOpAllowed(rel: string, what: 'rename' | 'delete'): boolean {
}
async function refreshFiles(): Promise<void> {
- if (panel !== 'files') { filesDirty = true; return; }
+ // Ohne Modell (Startseite) gibt es keine Dateien: Die Anfrage scheiterte nur und stand als Fehler im Protokoll
+ if (panel !== 'files' || !project) { filesDirty = true; return; }
filesDirty = false;
try { files.render(await api.fs.list()); } catch { /* Projekt wechselt gerade */ }
}
@@ -1392,11 +1401,13 @@ $('btn-buildinfo').addEventListener('click', () => {
// Darstellung
$('btn-display').addEventListener('click', () => menus.toggle($('menu-display'), $('btn-display'), 'beside'));
+$('btn-axes').addEventListener('click', () => setAxes($('btn-axes').getAttribute('aria-pressed') !== 'true'));
document.querySelectorAll<HTMLButtonElement>('[data-display]').forEach((b) => b.addEventListener('click', () => {
const on = b.getAttribute('aria-checked') !== 'true';
b.setAttribute('aria-checked', String(on));
if (b.dataset.display === 'edges') viewer.setEdges(on);
else if (b.dataset.display === 'wire') viewer.setWireframe(on);
+ else if (b.dataset.display === 'axes') setAxes(on);
else viewer.setGhost(on);
}));
@@ -1984,6 +1995,7 @@ if (api.testMode) {
settingsPages: () => ({ viewer: viewerPage.state(), storage: storagePage.state(), about: aboutPage.state() }),
appSettings: () => appSettings,
storageRefresh: () => storagePage.refresh(),
+ axes: () => viewer.axesState(),
display: () => Object.fromEntries([...document.querySelectorAll<HTMLElement>('[data-display]')].map((b) => [b.dataset.display, b.getAttribute('aria-checked') === 'true'])),
/** Export wie über das Menü (`sel`: das ausgewählte Bauteil), liefert das Ergebnis. */
exportAs: (fmt: string, scope: 'all' | 'sel') => { exportScope = scope; return doExport(fmt, fmt.toUpperCase()); },
diff --git a/app/src/renderer/settingspages.ts b/app/src/renderer/settingspages.ts
index a57156b..ef02a83 100644
--- a/app/src/renderer/settingspages.ts
+++ b/app/src/renderer/settingspages.ts
@@ -110,8 +110,9 @@ export class ViewerPage implements SettingsPage {
group('When a model opens',
field('Edges', null, toggle('st-edges', v.edges, 'Edges', (on) => void this.change({ edges: on }))),
field('Wireframe', null, toggle('st-wire', v.wireframe, 'Wireframe', (on) => void this.change({ wireframe: on }))),
- field('Transparent', 'The display menu in the viewer changes these for the open model, until the next one opens.',
- toggle('st-ghost', v.transparent, 'Transparent', (on) => void this.change({ transparent: on })))),
+ field('Transparent', null, toggle('st-ghost', v.transparent, 'Transparent', (on) => void this.change({ transparent: on }))),
+ field('Origin and axes', 'The display menu in the viewer changes these for the open model, until the next one opens.',
+ toggle('st-axes', v.axes, 'Origin and axes', (on) => void this.change({ axes: on })))),
group('Measurements',
field('Decimal places', `In the measurement card and at the measuring line, for example ${sample} mm. Text sent to the agent always has three decimals.`, digits)),
));
@@ -130,6 +131,7 @@ const AREA: Record<Exclude<StorageEntry['id'], 'appdata'>, { title: string; icon
previews: { title: 'Preview cache', icon: 'layers', desc: () => 'Older versions from the history, prepared for viewing. Created again when needed.' },
thumbnails: { title: 'Start page pictures', icon: 'image', desc: () => 'Pictures of your models on the start page.' },
skills: { title: 'Your skills', icon: 'book', desc: () => 'Skills you created or edited under “Skills”.' },
+ logs: { title: 'Logs', icon: 'file', desc: () => 'What the app did and what went wrong, for bug reports. A few MB at most, older entries are dropped.' },
other: { title: 'Other', icon: 'file', desc: () => 'Caches of the display, the settings and the state of the app.' },
};
@@ -316,7 +318,7 @@ export class AboutPage implements SettingsPage {
el('span', { className: 'c3', textContent: x.found ? `found (${x.command})` : `not installed (${x.command})` })))
: [el('span', { className: 'c3', textContent: 'No agents were checked.' })]))));
kids.push(group('Folders', el('div', { className: 'st-kv paths' }, ...a.paths.flatMap((p) => {
- const area: StorageArea | null = p.label === 'App data' ? 'appdata' : p.label === 'Your skills' ? 'skills' : null;
+ const area: StorageArea | null = p.label === 'App data' ? 'appdata' : p.label === 'Your skills' ? 'skills' : p.label === 'Logs' ? 'logs' : null;
const open = area ? el('button', { className: 'ibtn s', title: 'Open the folder' }, icon('folder', 14, 1.8)) : null;
open?.setAttribute('aria-label', `Open the folder: ${p.label}`);
open?.addEventListener('click', () => this.deps.openFolder(area!));
diff --git a/app/src/renderer/style.css b/app/src/renderer/style.css
index 25b8b3b..f688c2b 100644
--- a/app/src/renderer/style.css
+++ b/app/src/renderer/style.css
@@ -545,6 +545,7 @@ code { font-family:var(--mono); font-size:.95em; }
.vbtns { display:flex; flex-direction:column; gap:2px; padding:3px; background:rgba(24,27,31,.95); border:1px solid var(--line2); border-radius:9px; }
.vbtns button { width:30px; height:30px; display:flex; align-items:center; justify-content:center; border-radius:6px; color:#c9ced4; }
.vbtns button:hover { background:var(--s3); }
+.vbtns button[aria-pressed="true"] { background:var(--acc-tint); color:var(--acc-tx); }
/* Karten unten links (Entwurf 2): Auswahl, Messen, Schnitt, Explosion, Animation und Analyse stapeln sich nach oben */
.cards { position:absolute; left:12px; bottom:12px; z-index:2; width:360px; display:flex; flex-direction:column-reverse; gap:8px; pointer-events:none; }
@@ -579,6 +580,8 @@ code { font-family:var(--mono); font-size:.95em; }
.mc-ent b { color:var(--acc-tx); }
.mc-ent span { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.v-overlay { position:absolute; inset:0; pointer-events:none; z-index:1; overflow:hidden; }
+/* Beschriftung der Hauptachsen (Farbe je Achse wie am ViewCube, im Code gesetzt) */
+.v-axis { position:absolute; left:0; top:0; margin:-8px 0 0 -4px; font:700 12px/1 var(--mono, monospace); text-shadow:0 0 3px #000, 0 0 2px #000; }
/* Rahmenauswahl (Alt + links ziehen): durchgezogen von links nach rechts (ganz darin), gestrichelt von rechts nach links (angeschnitten) */
.v-box { position:absolute; z-index:2; pointer-events:none; border:1px solid var(--acc); background:rgba(242,154,56,.08); }
.v-box.cross { border-style:dashed; background:rgba(242,154,56,.05); }
diff --git a/app/src/renderer/viewer.ts b/app/src/renderer/viewer.ts
index 5d6ebfc..8551608 100644
--- a/app/src/renderer/viewer.ts
+++ b/app/src/renderer/viewer.ts
@@ -125,6 +125,10 @@ const NAV_BUTTON: Record<number, NavButton> = { 0: 'left', 1: 'middle', 2: 'righ
const NAV_KEY: Record<NavButton, 'LEFT' | 'MIDDLE' | 'RIGHT'> = { left: 'LEFT', middle: 'MIDDLE', right: 'RIGHT' };
/** Keine Bewegung für eine Taste (OrbitControls kennt dafür keinen eigenen Wert, alles außer den drei Aktionen gilt als nichts). */
const NAV_NONE = -1 as THREE.MOUSE;
+/** Hauptachsen, Farben wie am ViewCube (viewcube.ts). */
+const AXES = [
+ { dir: [1, 0, 0], color: 0xe5534b, label: 'X' }, { dir: [0, 1, 0], color: 0x57ab5a, label: 'Y' }, { dir: [0, 0, 1], color: 0x539bf5, label: 'Z' },
+];
export class Viewer {
private renderer: THREE.WebGLRenderer;
@@ -152,6 +156,10 @@ export class Viewer {
private edges = true;
private wire = false;
private ghost = false;
+ /** Ursprung und Hauptachsen (Menü „Display“), Farben wie am ViewCube. Länge nach der Größe des Modells beim Laden. */
+ private axes = new THREE.Group();
+ private showAxes = false;
+ private axisItems: { el: HTMLElement; at: THREE.Vector3 }[] = [];
private selectedId: string | null = null;
/** Mehrfachauswahl (Strg/Shift-Klick, Rahmen, Baum): alle leuchten orange, `selectedId` ist das zuletzt gewählte. */
private selectedIds = new Set<string>();
@@ -235,7 +243,7 @@ export class Viewer {
this.scene.add(new THREE.HemisphereLight(0xffffff, 0x445566, 1.6));
const sun = new THREE.DirectionalLight(0xffffff, 2.2);
sun.position.set(80, -120, 200);
- this.scene.add(sun, this.highlight, this.hover, this.marks, this.caps, this.trails);
+ this.scene.add(sun, this.highlight, this.hover, this.marks, this.caps, this.trails, this.axes);
this.overlay = document.createElement('div');
this.overlay.className = 'v-overlay';
container.appendChild(this.overlay);
@@ -310,6 +318,7 @@ export class Viewer {
for (const id of [...this.selectedIds]) if (!this.parts.has(id)) this.selectedIds.delete(id);
this.applySelection();
this.updateExtent();
+ this.buildAxes();
if (!this.hasFitted && this.parts.size) { this.setView('iso'); this.hasFitted = true; }
this.fitClip();
this.syncSection();
@@ -423,6 +432,39 @@ export class Viewer {
setEdges(on: boolean): void { this.edges = on; this.applyDisplay(); this.requestRender(); }
setWireframe(on: boolean): void { this.wire = on; this.applyDisplay(); this.requestRender(); }
setGhost(on: boolean): void { this.ghost = on; this.applyDisplay(); this.requestRender(); }
+ setAxes(on: boolean): void { this.showAxes = on; this.buildAxes(); this.fitClip(); this.requestRender(); }
+
+ /**
+ * Ursprung und Achsen X, Y, Z. Immer obenauf (ohne Tiefentest): Der Ursprung liegt oft im Modell, verdeckt wäre er nutzlos.
+ * Nicht auswählbar (Auswählen trifft nur Bauteile), vom Schnitt nicht betroffen. Länge rund 30 % des Modellradius,
+ * auf 1, 2 oder 5 × 10ⁿ mm gerundet: Sie zeigen Lage und Richtung, ohne das Modell zu überdecken.
+ */
+ private buildAxes(): void {
+ this.clearGroup(this.axes);
+ for (const it of this.axisItems) it.el.remove();
+ this.axisItems = [];
+ if (!this.showAxes) return;
+ const raw = Math.max(this.radius * 0.3, 1);
+ const pow = 10 ** Math.floor(Math.log10(raw));
+ const len = [1, 2, 5, 10].map((f) => f * pow).find((v) => v >= raw * 0.75) ?? raw;
+ for (const a of AXES) {
+ const tip = a.dir.map((d) => d * len);
+ const l = this.fatLines([0, 0, 0, ...tip], a.color, 2, false);
+ l.renderOrder = 11;
+ this.axes.add(l);
+ const el = document.createElement('div');
+ el.className = 'v-axis';
+ el.textContent = a.label;
+ el.style.color = `#${a.color.toString(16).padStart(6, '0')}`;
+ this.overlay.appendChild(el);
+ this.axisItems.push({ el, at: new THREE.Vector3(...(a.dir.map((d) => d * len * 1.08) as [number, number, number])) });
+ }
+ const og = new THREE.BufferGeometry();
+ og.setAttribute('position', new THREE.Float32BufferAttribute([0, 0, 0], 3));
+ const origin = new THREE.Points(og, new THREE.PointsMaterial({ color: 0xe6e8eb, size: 7, sizeAttenuation: false, map: Viewer.dot(), transparent: true, alphaTest: 0.2, depthTest: false }));
+ origin.renderOrder = 11;
+ this.axes.add(origin);
+ }
private applyDisplay(): void {
for (const [id, p] of this.parts) {
@@ -741,7 +783,9 @@ export class Viewer {
if (this.camera === this.ortho) { this.fitOrtho(); return; }
const dist = Math.max(this.camera.position.distanceTo(this.controls.target), 1e-3);
const near = Math.max(dist / 200, 1e-3);
- const far = Math.max(this.camera.position.distanceTo(this.center) + this.radius * 2, near * 100);
+ // Die Achsen liegen am Ursprung, der kann weit neben dem Modell liegen
+ const axes = this.showAxes ? this.camera.position.length() + this.radius : 0;
+ const far = Math.max(this.camera.position.distanceTo(this.center) + this.radius * 2, axes, near * 100);
if (Math.abs(near - this.camera.near) > near * 0.02 || Math.abs(far - this.camera.far) > far * 0.02) {
this.camera.near = near;
this.camera.far = far;
@@ -755,7 +799,7 @@ export class Viewer {
*/
private fitOrtho(): void {
const target = this.controls.target;
- const need = target.distanceTo(this.center) + this.radius * 2 + 1;
+ const need = Math.max(target.distanceTo(this.center), this.showAxes ? target.length() : 0) + this.radius * 2 + 1;
const off = this.ortho.position.clone().sub(target);
if (off.lengthSq() < 1e-18) off.set(0.8, -1.2, 0.9);
if (off.length() < need) this.ortho.position.copy(target).addScaledVector(off.normalize(), need);
@@ -1191,10 +1235,10 @@ export class Viewer {
}
private placeOverlay(): void {
- if (!this.overlayItems.length && !this.tagItems.length) return;
+ if (!this.overlayItems.length && !this.tagItems.length && !this.axisItems.length) return;
const w = this.container.clientWidth, h = this.container.clientHeight;
const v = new THREE.Vector3();
- for (const it of [...this.overlayItems, ...this.tagItems]) {
+ for (const it of [...this.overlayItems, ...this.tagItems, ...this.axisItems]) {
v.copy(it.at).project(this.camera);
const off = v.z > 1 || v.x < -1.2 || v.x > 1.2 || v.y < -1.2 || v.y > 1.2;
it.el.hidden = off;
@@ -2136,6 +2180,11 @@ export class Viewer {
buttons: [b.LEFT, b.MIDDLE, b.RIGHT] };
}
+ /** Ursprung und Achsen, für Tests: an, Anzahl der Objekte (3 Linien und der Punkt), Beschriftungen im Bild, Länge der X-Achse. */
+ axesState() {
+ return { on: this.showAxes, objects: this.axes.children.length, labels: this.axisItems.filter((it) => !it.el.hidden).map((it) => it.el.textContent), len: this.axisItems[0] ? this.axisItems[0].at.x / 1.08 : 0 };
+ }
+
/** Stand des Schnitts, für Tests: Ebene, Bauteile mit Deckel, Segmente und Ausdehnung der Kontur, geschnittene Materialien. */
sectionState() {
this.prepareSection();
diff --git a/app/src/shared/settings.ts b/app/src/shared/settings.ts
index a1fa0ff..8cdac77 100644
--- a/app/src/shared/settings.ts
+++ b/app/src/shared/settings.ts
@@ -19,6 +19,8 @@ export interface ViewerPrefs {
edges: boolean;
wireframe: boolean;
transparent: boolean;
+ /** Ursprung und Hauptachsen X, Y, Z. */
+ axes: boolean;
/** Nachkommastellen der Messwerte in der Oberfläche. Der Text für den Agenten hat immer drei. */
decimals: number;
}
@@ -33,7 +35,7 @@ export interface SettingsResult extends SettingsState { ok: boolean; error?: str
export const DECIMALS = { min: 0, max: 4 };
export const DEFAULT_SETTINGS: AppSettings = {
- viewer: { navigation: 'soma', invertZoom: false, projection: 'perspective', edges: true, wireframe: false, transparent: false, decimals: 2 },
+ viewer: { navigation: 'soma', invertZoom: false, projection: 'perspective', edges: true, wireframe: false, transparent: false, axes: false, decimals: 2 },
start: { tutorialCard: true, updateCheck: true },
};
@@ -89,7 +91,7 @@ const isProjection = (v: unknown): v is Projection => v === 'perspective' || v =
const isDecimals = (v: unknown): v is number => typeof v === 'number' && Number.isInteger(v) && v >= DECIMALS.min && v <= DECIMALS.max;
const isBool = (v: unknown): v is boolean => typeof v === 'boolean';
const VIEWER_CHECKS: { [K in keyof ViewerPrefs]: (v: unknown) => boolean } = {
- navigation: isNav, invertZoom: isBool, projection: isProjection, edges: isBool, wireframe: isBool, transparent: isBool, decimals: isDecimals,
+ navigation: isNav, invertZoom: isBool, projection: isProjection, edges: isBool, wireframe: isBool, transparent: isBool, axes: isBool, decimals: isDecimals,
};
const START_CHECKS: { [K in keyof StartPrefs]: (v: unknown) => boolean } = { tutorialCard: isBool, updateCheck: isBool };
/** Bereiche der Einstellungen mit der Prüfung je Wert. */