Apply unit preference to property display
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -62,8 +62,11 @@
|
||||
- **底部停靠面板**:`shell/bottom-dock.tsx` + Windows 菜单入口。
|
||||
- Selection view 显示当前选择对象;Report view 保留最近 50 条状态;
|
||||
- 实测打开/切换正常,0 pageError;截图 `bottom-dock.png`。
|
||||
- 说明:原生 `BaseApp/Preferences` 参数同步与单位制驱动显示待 P3;
|
||||
快捷键仍仅 localStorage;Python 控制台尚未接入。
|
||||
- **单位制已驱动属性显示**:`shell/units.ts`;Preferences 修改后广播
|
||||
`freecad-preferences-changed`,属性面板 Bounds 标签与数值、Volume 按 mm/m/in/cm
|
||||
换算显示。实测 mm → m 切换生效,0 pageError。
|
||||
- 输入框仍以 mm 写入内核,显示层换算;原生 `BaseApp/Preferences` 同步待 P3。
|
||||
- 说明:快捷键仍仅 localStorage;Python 控制台尚未接入。
|
||||
- 非 Part 菜单命令改为打开 **React TaskFrame 模态**(`web/src/shell/task-frame.tsx`),
|
||||
iframe 复用 `/workbench.html?module=<id>&command=<id>` 的现有任务面板;
|
||||
BIM_TogglePanels 实测弹出 "Bottom panels" 任务并可点按钮,0 pageError;
|
||||
|
||||
@@ -86,7 +86,8 @@ import { ParityWorkbenchMenu } from "./shell/workbench-menu.js";
|
||||
import { TaskFrame } from "./shell/task-frame.js";
|
||||
import { ParityWorkbenchToolbars } from "./shell/workbench-toolbars.js";
|
||||
import { UtilityMenus } from "./shell/utility-menus.js";
|
||||
import { PreferencesDialog } from "./shell/preferences-dialog.js";
|
||||
import { PreferencesDialog, loadWebPreferences } from "./shell/preferences-dialog.js";
|
||||
import { formatLength, formatVolume, unitInfo } from "./shell/units.js";
|
||||
import { ShortcutEditor, ShortcutManager } from "./shell/shortcut-manager.js";
|
||||
import { BottomDock } from "./shell/bottom-dock.js";
|
||||
import { DocumentTree, type DocumentTreeNode } from "./document-tree.js";
|
||||
@@ -320,8 +321,15 @@ function App() {
|
||||
const [workbenches, setWorkbenches] = useState<Record<string, "Part" | "Sketcher" | "PartDesign" | "Spreadsheet" | "Surface" | "Assembly" | "Draft" | "Architecture" | "TechDraw" | "CAM">>(() => initialWorkbench ? { [initialDocumentId]: initialWorkbench } : {});
|
||||
const workbench = workbenches[active] ?? "Part";
|
||||
useEffect(() => { if (status) setReportLog(previous => previous[0] === status ? previous : [status, ...previous].slice(0, 50)); }, [status]);
|
||||
useEffect(() => {
|
||||
const refresh = () => setUnitSystem(loadWebPreferences().unitSystem);
|
||||
window.addEventListener("freecad-preferences-changed", refresh);
|
||||
window.addEventListener("storage", refresh);
|
||||
return () => { window.removeEventListener("freecad-preferences-changed", refresh); window.removeEventListener("storage", refresh); };
|
||||
}, []);
|
||||
const [parityTask, setParityTask] = useState<{ module: string; command: string } | null>(null);
|
||||
const [preferencesOpen, setPreferencesOpen] = useState(false);
|
||||
const [unitSystem, setUnitSystem] = useState(() => loadWebPreferences().unitSystem);
|
||||
const [shortcutsOpen, setShortcutsOpen] = useState(false);
|
||||
const [selectedSheets, setSelectedSheets] = useState<Record<string, string>>({});
|
||||
const [csvPanel, setCsvPanel] = useState<{ id: string; mode: "import" | "export"; selected?: string; done(result: Record<string, unknown>): void } | null>(null);
|
||||
@@ -3125,11 +3133,11 @@ function App() {
|
||||
<div className="primitive-actions"><button type="button" data-create-primitive onClick={() => void createOrEditPrimitive(false)}><ToolIcon nodes={Plus} />创建{primitives[primitive].label}</button>
|
||||
<button type="button" data-update-primitive disabled={selectedObject?.type !== `Part::${primitive}`} onClick={() => void createOrEditPrimitive(true)}><ToolIcon nodes={RefreshCw} />重算</button></div>
|
||||
</fieldset>}
|
||||
{typeof selectedObject?.properties.volume === "number" ? <div className="stat"><strong>Volume</strong><small data-native-volume>{selectedObject.properties.volume.toFixed(6)}</small></div> : null}
|
||||
{typeof selectedObject?.properties.volume === "number" ? <div className="stat"><strong>Volume</strong><small data-native-volume>{formatVolume(selectedObject.properties.volume, unitSystem)}</small></div> : null}
|
||||
{Array.isArray(selectedObject?.properties.bounds) && selectedObject.properties.bounds.length === 6 &&
|
||||
<div className="stat"><strong>Bounds (mm)</strong><small data-native-bounds={JSON.stringify(selectedObject.properties.bounds)}>
|
||||
<div className="stat"><strong>Bounds ({unitInfo(unitSystem).symbol})</strong><small data-native-bounds={JSON.stringify(selectedObject.properties.bounds)}>
|
||||
{selectedObject.properties.bounds.map((value, index) => <span key={index} style={{ display: "block" }}>
|
||||
{["Min X", "Min Y", "Min Z", "Max X", "Max Y", "Max Z"][index]}: {Number(value).toFixed(6)}
|
||||
{["Min X", "Min Y", "Min Z", "Max X", "Max Y", "Max Z"][index]}: {formatLength(Number(value), unitSystem, 4)}
|
||||
</span>)}
|
||||
</small></div>}
|
||||
<div className="stat"><strong>{active || "none"}</strong><small>{objects.length} objects</small></div>
|
||||
|
||||
@@ -36,6 +36,7 @@ export function PreferencesDialog({ onClose }: { onClose: () => void }) {
|
||||
useEffect(() => {
|
||||
localStorage.setItem(KEY, JSON.stringify(preferences));
|
||||
if (hydrated.current) void saveSettings("web-preferences.json", preferences);
|
||||
window.dispatchEvent(new Event("freecad-preferences-changed"));
|
||||
}, [preferences]);
|
||||
const update = <K extends keyof WebPreferences>(key: K, value: WebPreferences[K]) =>
|
||||
setPreferences(previous => ({ ...previous, [key]: value }));
|
||||
|
||||
19
web/src/shell/units.ts
Normal file
19
web/src/shell/units.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export type UnitInfo = { symbol: string; lengthFactor: number; volumeFactor: number };
|
||||
|
||||
export function unitInfo(unitSystem: string): UnitInfo {
|
||||
if (unitSystem.startsWith("MKS")) return { symbol: "m", lengthFactor: 0.001, volumeFactor: 1e-9 };
|
||||
if (unitSystem.startsWith("Imperial")) return { symbol: "in", lengthFactor: 1 / 25.4, volumeFactor: 1 / (25.4 ** 3) };
|
||||
if (unitSystem.startsWith("Building US")) return { symbol: "in", lengthFactor: 1 / 25.4, volumeFactor: 1 / (25.4 ** 3) };
|
||||
if (unitSystem.startsWith("Building cm")) return { symbol: "cm", lengthFactor: 0.1, volumeFactor: 0.001 };
|
||||
return { symbol: "mm", lengthFactor: 1, volumeFactor: 1 };
|
||||
}
|
||||
|
||||
export function formatLength(valueMm: number, unitSystem: string, digits = 3) {
|
||||
const info = unitInfo(unitSystem);
|
||||
return `${(valueMm * info.lengthFactor).toFixed(digits)} ${info.symbol}`;
|
||||
}
|
||||
|
||||
export function formatVolume(valueMm3: number, unitSystem: string, digits = 4) {
|
||||
const info = unitInfo(unitSystem);
|
||||
return `${(valueMm3 * info.volumeFactor).toFixed(digits)} ${info.symbol}³`;
|
||||
}
|
||||
Reference in New Issue
Block a user