This commit is contained in:
2026-06-29 08:54:12 +08:00
parent 8ba1c8c14b
commit 71b7655d91
3 changed files with 151 additions and 39 deletions
+40
View File
@@ -45,6 +45,8 @@ FRONTEND_DIR = os.path.join(BASE_DIR, '..', 'frontend')
REPO_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', '..'))
# Component/category icons are served from backend/icons for the library panel.
ICONS_DIR = os.path.join(BASE_DIR, 'icons')
# Login page time-of-day background images.
PIC_DIR = os.path.join(FRONTEND_DIR, 'pic')
# Flask serves the HTML/CSS/JS frontend and exposes JSON APIs for persistence,
@@ -448,6 +450,14 @@ def canvas_helpers():
"""Serve the shared canvas helper script used by canvas.html."""
return no_cache_response(send_from_directory(FRONTEND_DIR, 'canvas-helpers.js'))
@app.route('/pic/<filename>')
def pic(filename):
"""Serve time-of-day background images for the login page."""
safe_name = os.path.basename(filename)
return send_from_directory(PIC_DIR, safe_name)
@app.route('/logout')
def logout():
"""Clear session and return to login."""
@@ -702,6 +712,36 @@ def delete_project(project_name):
return jsonify({"message": "deleted", "project": safe_name(project_name, 'project_1')})
@app.route('/api/projects/<project_name>/rename', methods=['PUT'])
@login_required_json
def rename_project(project_name):
"""Rename a project folder."""
data = request.get_json(silent=True) or {}
new_name = (data.get('name') or '').strip()
if not new_name:
return jsonify({"error": "New project name is required"}), 400
root = project_root(project_name)
layout_root = os.path.abspath(user_layout_root())
target = os.path.abspath(root)
if not target.startswith(layout_root + os.sep):
return jsonify({"error": "Invalid project path"}), 400
if not os.path.isdir(target):
return jsonify({"error": "Project not found"}), 404
safe_new = safe_name(new_name, 'project_1')
new_root = os.path.join(user_layout_root(), safe_new)
if os.path.exists(new_root):
return jsonify({"error": "A project with that name already exists"}), 409
old_meta = read_project_meta(project_name)
os.rename(target, new_root)
write_project_meta(safe_new, {"name": safe_new, "technology": old_meta.get("technology")})
record_action('project.rename', project=safe_new, detail={"old_name": project_name})
return jsonify({"name": safe_new})
@app.route('/api/projects/<project_name>/cells/<cell_name>', methods=['PATCH', 'DELETE'])
@login_required_json
def rename_cell(project_name, cell_name):
+98 -38
View File
@@ -1,6 +1,9 @@
<!DOCTYPE html>
<!-- CANVAS v22: per-page instance counter — reserveComponentDisplayNamesFromPages only scans active page, not whole project -->
<!-- CANVAS v6: marquee-selection — drag-to-pan, Shift+drag marquee, button at bottom-left above zoom -->
<!-- CANVAS v5: inverse-label-scale — instance name only, exponent 1.3 -->
<!-- CANVAS v7: marquee button auto-stacked above Controls via flex container (no hardcoded offset) -->
<!--
Description: Main MXPIC EDA canvas UI with React Flow editing, project pages, routing, layout build controls, and inspector panels.
Inside functions: fetchIcon, RotatableNode, PortNode, AnchorNode, RightPanel, findComponentPath, loadProject, handleBasicConnection, buildElementNodesFromYaml.
@@ -1509,6 +1512,39 @@ Organization : OptiHK Limited
display: none;
}
.react-flow__controls-button.marquee-active {
background: var(--accent);
color: #05080f;
box-shadow: 0 0 10px rgba(69, 214, 200, 0.45);
}
.marquee-btn-normal {
background: #0b1320;
color: #f5f7fa;
border-color: rgba(163, 186, 212, 0.16);
}
.marquee-btn-normal:hover {
background: #101a29;
color: #f5f7fa;
}
body.light-mode .react-flow__controls-button.marquee-active {
color: #ffffff;
box-shadow: 0 0 10px rgba(8, 127, 115, 0.45);
}
body.light-mode .marquee-btn-normal {
background: #ffffff;
color: #122033;
border-color: rgba(30, 48, 69, 0.18);
}
body.light-mode .marquee-btn-normal:hover {
background: #f0f4f8;
color: #122033;
}
body.light-mode .port-name-label {
background: var(--port-label-bg);
border-color: var(--floating-label-border);
@@ -1793,6 +1829,8 @@ Organization : OptiHK Limited
};
const iconPromiseCache = {};
// Global fetch guard for component data — survives component remounts
const globalComponentFetchGuard = {};
// Loads and caches category icons so repeated library renders do not refetch the same image.
function fetchIcon(category) {
if (!iconPromiseCache[category]) {
@@ -1891,6 +1929,8 @@ Organization : OptiHK Limited
// Renders PDK and primitive component instances with transformed ports and selection styling.
const RotatableNode = memo(({ id, data, selected }) => {
const updateNodeInternals = useUpdateNodeInternals();
const zoom = useStore(state => state.transform[2]);
const inverseScale = zoom ? Math.max(1, Math.pow(1 / zoom, 1.3)) : 1;
const prevTransformRef = useRef(`${data.rotation || 0}:${data.flip ? 1 : 0}:${data.flop ? 1 : 0}`);
const updateNodeInternalsRef = useRef(updateNodeInternals);
@@ -2003,7 +2043,7 @@ Organization : OptiHK Limited
className="component-node-shell"
style={{ width: visualSize.width, minWidth: visualSize.width, maxWidth: visualSize.width, minHeight: visualSize.height }}
>
<div className="component-floating-label" title={data.componentDisplayName} style={hasTopHandles ? { bottom: 'calc(100% + 27px)' } : undefined}>
<div className="component-floating-label" title={data.componentDisplayName} style={{ ...(hasTopHandles ? { bottom: 'calc(100% + 27px)' } : {}), transform: `translateX(-50%) scale(${inverseScale})`, transformOrigin: 'center bottom' }}>
<strong>{data.componentDisplayName}</strong>
</div>
<div
@@ -2120,6 +2160,8 @@ Organization : OptiHK Limited
};
const PortNode = ({ id, data, selected }) => {
const zoom = useStore(state => state.transform[2]);
const inverseScale = zoom ? Math.max(1, Math.pow(1 / zoom, 1.3)) : 1;
const angle = data.angle ?? 0;
const canvasAngle = -Number(angle || 0);
const portDisplayName = data.portName || data.componentDisplayName || data.label || 'port';
@@ -2172,7 +2214,7 @@ Organization : OptiHK Limited
background: 'rgba(239,68,68,0.08)',
boxShadow: 'none'
}}>
<div className="component-floating-label" title={portDisplayName}>
<div className="component-floating-label" title={portDisplayName} style={{ transform: `translateX(-50%) scale(${inverseScale})`, transformOrigin: 'center bottom' }}>
<strong>{portDisplayName}</strong>
</div>
{portHandles.map((portHandle) => (
@@ -2203,6 +2245,8 @@ Organization : OptiHK Limited
// Renders anchor elements with split visual handles while keeping paired layout ports connected.
const AnchorNode = memo(({ id, data, selected }) => {
const updateNodeInternals = useUpdateNodeInternals();
const zoom = useStore(state => state.transform[2]);
const inverseScale = zoom ? Math.max(1, Math.pow(1 / zoom, 1.3)) : 1;
const anchorRotation = data.rotation || 0;
const anchorVisualRotation = -Number(anchorRotation || 0);
const anchorDisplayName = data.componentDisplayName || data.label || 'anchor';
@@ -2267,7 +2311,7 @@ Organization : OptiHK Limited
return (
<>
<div className="anchor-node-shell" style={{ width: elementSize.width, height: elementSize.height }}>
<div className="component-floating-label" title={anchorDisplayName}>
<div className="component-floating-label" title={anchorDisplayName} style={{ transform: `translateX(-50%) scale(${inverseScale})`, transformOrigin: 'center bottom' }}>
<strong>{anchorDisplayName}</strong>
</div>
<div className="anchor-visual-body" style={{
@@ -2707,7 +2751,7 @@ Organization : OptiHK Limited
setValue(page.name);
}, [page.name, page.id]);
if (!active || page.type === 'project') {
if (!active) {
return <span>{page.name}</span>;
}
@@ -3326,50 +3370,46 @@ Organization : OptiHK Limited
useEffect(() => {
const nodeId = selectedNode?.id;
if (!nodeId || isMultiNodeSelection) {
setComponentData(null);
setLoading(false);
return;
}
const compName = selectedNode?.data?.componentName;
const selectedIsComposite = selectedNode?.data?.type === 'composite' || compositeNames.includes(compName);
if (selectedNode?.data?.elementType || selectedIsComposite || isBasicComponent(compName)) {
const fetchKey = (nodeId && compName) ? `${nodeId}:${compName}` : null;
// Restore from global cache if previously fetched
if (fetchKey && globalComponentFetchGuard[fetchKey]) {
setComponentData(globalComponentFetchGuard[fetchKey]);
setLoading(false);
return;
}
// Selection cleared or not a fetchable component — clear data
if (!nodeId || isMultiNodeSelection || !compName ||
selectedNode?.data?.elementType ||
selectedNode?.data?.type === 'composite' ||
compositeNames.includes(compName) ||
isBasicComponent(compName) ||
isForgeComponent(compName)) {
setComponentData(null);
setLoading(false);
return;
}
if (!compName) {
setComponentData(null);
setLoading(false);
return;
}
if (isForgeComponent(compName)) {
setComponentData(null);
setLoading(false);
return;
}
if (componentData && componentData.name === compName && componentData.nodeId === nodeId) return;
setLoading(true);
fetch(`/api/component/${encodeURIComponent(compName)}?project=${encodeURIComponent(projectName || '')}`)
const controller = new AbortController();
fetch(`/api/component/${encodeURIComponent(compName)}?project=${encodeURIComponent(projectName || '')}`, { signal: controller.signal })
.then(r => {
if (!r.ok) throw new Error('Component metadata not found');
return r.json();
})
.then(data => {
setComponentData({ ...data, nodeId: nodeId, componentDisplayName: selectedNode.data.componentDisplayName || data.name });
onUpdateNode(nodeId, {
data: {
ports: data.ports || {},
boxSize: normalizeBoxSize(data),
foundry: data.foundry || '',
process: data.process || ''
}
});
const result = { ...data, nodeId: nodeId, componentDisplayName: selectedNode.data.componentDisplayName || data.name };
globalComponentFetchGuard[fetchKey] = result;
setComponentData(result);
setLoading(false);
})
.catch(() => setLoading(false));
}, [selectedNode?.id, selectedNode?.data?.componentName, selectedNode?.data?.componentDisplayName, isMultiNodeSelection, compositeNames, projectName, onUpdateNode]);
.catch(err => {
if (err.name !== 'AbortError') setLoading(false);
});
return () => controller.abort();
}, [selectedNode?.id, selectedNode?.data?.componentName, selectedNode?.data?.componentDisplayName, isMultiNodeSelection, projectName]);
useEffect(() => {
if (editingTransformField) return;
@@ -4143,7 +4183,7 @@ Organization : OptiHK Limited
))}
</ul>
<p style={{ color: 'var(--text-main)', fontWeight: '500', marginBottom: '4px' }}>Preview:</p>
{/* <p style={{ color: 'var(--text-main)', fontWeight: '500', marginBottom: '4px' }}>Preview:</p>
<div style={{
border: '1px solid var(--border)', width: '100%', height: 100,
display: 'flex', alignItems: 'center', justifyContent: 'center',
@@ -4161,7 +4201,7 @@ Organization : OptiHK Limited
e.currentTarget.parentElement.innerHTML = '<span style="color:var(--text-muted)">No preview</span>';
}}
/>
</div>
</div> */}
</>
) : (
<p style={{ color: 'var(--text-muted)' }}>No data available</p>
@@ -4643,6 +4683,7 @@ Organization : OptiHK Limited
const [projectCompositeMap, setProjectCompositeMap] = useState({});
const [standaloneComposites, setStandaloneComposites] = useState([]);
const [compositeTrees, setCompositeTrees] = useState({});
const [marqueeMode, setMarqueeMode] = useState(false);
useEffect(() => {
document.body.classList.toggle('light-mode', themeMode === 'light');
@@ -6717,6 +6758,11 @@ Organization : OptiHK Limited
};
}, [dragging]);
// Toggle marquee selection mode (drag to select, Shift+drag to pan).
const toggleMarqueeMode = useCallback(() => {
setMarqueeMode(prev => !prev);
}, []);
// Toggle snap-to-grid movement in the editor.
const toggleGridSnap = useCallback(() => {
setGridSnap(prev => !prev);
@@ -7626,12 +7672,26 @@ ${bundlesBlock}`;
maxZoom={4}
defaultViewport={{ x: 80, y: 80, zoom: 0.12 }}
onMoveEnd={handleCanvasViewportMoveEnd}
panOnDrag={false}
selectionOnDrag={true}
panOnDrag={!marqueeMode}
selectionOnDrag={marqueeMode}
selectionMode={FULL_SELECTION_MODE}
multiSelectionKeyCode="Shift"
selectionKeyCode="Shift"
panActivationKeyCode="Shift"
deleteKeyCode={['Backspace', 'Delete']}
>
<div style={{ position: 'absolute', bottom: 140, left: 30, zIndex: 5 }}>
<button
onClick={toggleMarqueeMode}
className={`react-flow__controls-button ${marqueeMode ? 'marquee-active' : 'marquee-btn-normal'}`}
style={{ borderBottom: 'none', borderRadius: '4px 4px 0 0' }}
title={marqueeMode ? 'Marquee Selection: drag to select, Shift+drag to pan' : 'Pan Mode: drag to pan, Shift+drag to marquee select'}
>
<svg width="20" height="18" viewBox="0 0 20 18" fill="none">
<rect x="1.5" y="0.5" width="17" height="17" rx="1.5" stroke="currentColor" strokeWidth="1.5" strokeDasharray="3.6 1.8" />
</svg>
</button>
</div>
<Controls style={{ bottom: 15, left: 15 }} />
<Background color="#334155" gap={10} size={1} />
</ReactFlow>
+12
View File
@@ -31,4 +31,16 @@ Added origin coordinates to the YML file; fixed a bug that caused component misa
Fixed a bug where the default port would reload on every page refresh.
06/27
Add inverse name scaling to keep labels readable when zooming out
Switch canvas drag mode to direct panning
Replace widget selection with button-based toggle
Fix lag caused by duplicate image requests
Add rename functionality to project tabs