modify the stlye of the original, add an input field for the original, revise the definition of the canvas bounds
This commit is contained in:
+34
-10
@@ -27,6 +27,8 @@
|
|||||||
const DEFAULT_COMPONENT_BOX_SIZE = { width: 132, height: 82 };
|
const DEFAULT_COMPONENT_BOX_SIZE = { width: 132, height: 82 };
|
||||||
// Default editable canvas dimensions in micrometers.
|
// Default editable canvas dimensions in micrometers.
|
||||||
const DEFAULT_CANVAS_SIZE = { width: 5000, height: 5000 };
|
const DEFAULT_CANVAS_SIZE = { width: 5000, height: 5000 };
|
||||||
|
// Default canvas bounds as a four-wall rectangle (xmin, xmax, ymin, ymax).
|
||||||
|
const DEFAULT_CANVAS_BOUNDS = { xmin: 0, xmax: 5000, ymin: 0, ymax: 5000 };
|
||||||
// Base visual diameter and hit area used for port and anchor handles.
|
// Base visual diameter and hit area used for port and anchor handles.
|
||||||
const PORT_NODE_SIZE = 11;
|
const PORT_NODE_SIZE = 11;
|
||||||
const FREE_WIRES_BUNDLE_GROUP = 'free_wires';
|
const FREE_WIRES_BUNDLE_GROUP = 'free_wires';
|
||||||
@@ -314,15 +316,35 @@
|
|||||||
height: positiveNumber(size && size.height) || DEFAULT_CANVAS_SIZE.height
|
height: positiveNumber(size && size.height) || DEFAULT_CANVAS_SIZE.height
|
||||||
});
|
});
|
||||||
|
|
||||||
// Keep dragged or pasted nodes inside the active canvas bounds.
|
// Resolve valid canvas bounds (four-wall rectangle) from saved project metadata.
|
||||||
const clampPositionToCanvas = (position, canvasSize, boxSize) => {
|
// Accepts either legacy {width, height} or new {xmin, xmax, ymin, ymax}.
|
||||||
const size = normalizeCanvasSize(canvasSize);
|
const normalizeCanvasBounds = (bounds) => {
|
||||||
const box = normalizeBoxSize({ box_size: [boxSize && boxSize.width, boxSize && boxSize.height] });
|
if (!bounds) return { ...DEFAULT_CANVAS_BOUNDS };
|
||||||
const maxX = Math.max(0, size.width - box.width);
|
// New-style four-wall rectangle.
|
||||||
const maxY = Math.max(0, size.height - box.height);
|
if (bounds.xmin != null || bounds.xmax != null || bounds.ymin != null || bounds.ymax != null) {
|
||||||
return {
|
return {
|
||||||
x: Math.min(maxX, Math.max(0, Number(position && position.x) || 0)),
|
xmin: Number.isFinite(Number(bounds.xmin)) ? Number(bounds.xmin) : DEFAULT_CANVAS_BOUNDS.xmin,
|
||||||
y: Math.min(maxY, Math.max(0, Number(position && position.y) || 0))
|
xmax: Number.isFinite(Number(bounds.xmax)) ? Number(bounds.xmax) : DEFAULT_CANVAS_BOUNDS.xmax,
|
||||||
|
ymin: Number.isFinite(Number(bounds.ymin)) ? Number(bounds.ymin) : DEFAULT_CANVAS_BOUNDS.ymin,
|
||||||
|
ymax: Number.isFinite(Number(bounds.ymax)) ? Number(bounds.ymax) : DEFAULT_CANVAS_BOUNDS.ymax
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Legacy width/height format: treat as rectangle from (0,0).
|
||||||
|
const w = positiveNumber(bounds.width) || DEFAULT_CANVAS_SIZE.width;
|
||||||
|
const h = positiveNumber(bounds.height) || DEFAULT_CANVAS_SIZE.height;
|
||||||
|
return { xmin: 0, xmax: w, ymin: 0, ymax: h };
|
||||||
|
};
|
||||||
|
|
||||||
|
// Keep dragged or pasted nodes inside the active canvas bounds.
|
||||||
|
// Accepts either legacy {width,height} or new {xmin,xmax,ymin,ymax} canvasSize.
|
||||||
|
const clampPositionToCanvas = (position, canvasSize, boxSize) => {
|
||||||
|
const bounds = normalizeCanvasBounds(canvasSize);
|
||||||
|
const box = normalizeBoxSize({ box_size: [boxSize && boxSize.width, boxSize && boxSize.height] });
|
||||||
|
const maxX = Math.max(bounds.xmin, bounds.xmax - box.width);
|
||||||
|
const maxY = Math.max(bounds.ymin, bounds.ymax - box.height);
|
||||||
|
return {
|
||||||
|
x: Math.min(maxX, Math.max(bounds.xmin, Number(position && position.x) || 0)),
|
||||||
|
y: Math.min(maxY, Math.max(bounds.ymin, Number(position && position.y) || 0))
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -375,8 +397,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (points.length === 0) {
|
if (points.length === 0) {
|
||||||
const size = normalizeCanvasSize(page.canvasSize || DEFAULT_CANVAS_SIZE);
|
const bounds = normalizeCanvasBounds(page.canvasSize || page.canvasBounds);
|
||||||
points.push({ x: 0, y: 0 }, { x: size.width, y: size.height });
|
points.push({ x: bounds.xmin, y: bounds.ymin }, { x: bounds.xmax, y: bounds.ymax });
|
||||||
}
|
}
|
||||||
|
|
||||||
const minX = roundBoundsValue(Math.min(...points.map(point => point.x)));
|
const minX = roundBoundsValue(Math.min(...points.map(point => point.x)));
|
||||||
@@ -1321,6 +1343,7 @@ bundles:${groupsYaml ? `\n${groupsYaml}` : ' {}'}`;
|
|||||||
FORGE_COMPONENT_TYPE,
|
FORGE_COMPONENT_TYPE,
|
||||||
DEFAULT_COMPONENT_BOX_SIZE,
|
DEFAULT_COMPONENT_BOX_SIZE,
|
||||||
DEFAULT_CANVAS_SIZE,
|
DEFAULT_CANVAS_SIZE,
|
||||||
|
DEFAULT_CANVAS_BOUNDS,
|
||||||
PORT_NODE_SIZE,
|
PORT_NODE_SIZE,
|
||||||
DEFAULT_ELEMENT_PITCH,
|
DEFAULT_ELEMENT_PITCH,
|
||||||
ELEMENT_COMPONENTS,
|
ELEMENT_COMPONENTS,
|
||||||
@@ -1351,6 +1374,7 @@ bundles:${groupsYaml ? `\n${groupsYaml}` : ' {}'}`;
|
|||||||
normalizeBoxSize,
|
normalizeBoxSize,
|
||||||
chooseCategoryComponent,
|
chooseCategoryComponent,
|
||||||
normalizeCanvasSize,
|
normalizeCanvasSize,
|
||||||
|
normalizeCanvasBounds,
|
||||||
clampPositionToCanvas,
|
clampPositionToCanvas,
|
||||||
calculateLayoutBounds,
|
calculateLayoutBounds,
|
||||||
calculateCompositeBoxSize,
|
calculateCompositeBoxSize,
|
||||||
|
|||||||
+314
-93
@@ -830,6 +830,98 @@ Organization : OptiHK Limited
|
|||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.origin-pick-panel {
|
||||||
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
bottom: 60px;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
z-index: 13;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 9px 16px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 7px;
|
||||||
|
background: rgba(6, 34, 32, 0.95);
|
||||||
|
box-shadow: 0 14px 28px var(--shadow);
|
||||||
|
backdrop-filter: blur(14px);
|
||||||
|
font: 600 0.78rem/1 'IBM Plex Mono', Consolas, Monaco, monospace;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.origin-pick-panel label {
|
||||||
|
color: var(--text-main);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.origin-pick-panel input {
|
||||||
|
width: 128px;
|
||||||
|
padding: 6px 8px;
|
||||||
|
border: 1px solid rgba(45, 212, 191, 0.3);
|
||||||
|
border-radius: 5px;
|
||||||
|
background: rgba(45, 212, 191, 0.05);
|
||||||
|
color: var(--text-main);
|
||||||
|
font: inherit;
|
||||||
|
font-size: 0.78rem;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.origin-pick-panel input:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: var(--accent-green);
|
||||||
|
box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.origin-pick-panel button {
|
||||||
|
padding: 6px 14px;
|
||||||
|
border: 1px solid var(--accent-green);
|
||||||
|
border-radius: 5px;
|
||||||
|
background: rgba(45, 212, 191, 0.1);
|
||||||
|
color: var(--accent-green);
|
||||||
|
font: inherit;
|
||||||
|
font-size: 0.72rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.origin-pick-panel .cancel-btn {
|
||||||
|
border-color: var(--border);
|
||||||
|
background: transparent;
|
||||||
|
color: var(--text-muted);
|
||||||
|
margin-left: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.origin-pick-panel button:hover {
|
||||||
|
background: rgba(45, 212, 191, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.origin-pick-panel .cancel-btn:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
body.light-mode .origin-pick-panel {
|
||||||
|
background: rgba(235, 252, 249, 0.96);
|
||||||
|
border-color: rgba(30, 48, 69, 0.16);
|
||||||
|
box-shadow: 0 14px 28px rgba(18, 32, 51, 0.12);
|
||||||
|
}
|
||||||
|
|
||||||
|
body.light-mode .origin-pick-panel input {
|
||||||
|
border-color: rgba(13, 148, 136, 0.3);
|
||||||
|
background: rgba(13, 148, 136, 0.04);
|
||||||
|
color: #132033;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.light-mode .origin-pick-panel input:focus {
|
||||||
|
border-color: #0d9488;
|
||||||
|
box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
body.light-mode .origin-pick-panel .cancel-btn:hover {
|
||||||
|
background: rgba(18, 32, 51, 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
.build-layout-btn {
|
.build-layout-btn {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
@@ -1518,33 +1610,32 @@ Organization : OptiHK Limited
|
|||||||
}
|
}
|
||||||
|
|
||||||
.origin-marker-node {
|
.origin-marker-node {
|
||||||
width: 16px;
|
|
||||||
height: 16px;
|
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.origin-marker-node::before,
|
.origin-marker-node svg {
|
||||||
.origin-marker-node::after {
|
display: block;
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
background: #ef4444;
|
|
||||||
box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
|
|
||||||
}
|
|
||||||
|
|
||||||
.origin-marker-node::before {
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 2px;
|
height: 100%;
|
||||||
transform: translate(-50%, -50%) rotate(45deg);
|
overflow: visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
.origin-marker-node::after {
|
.origin-marker-node .origin-circle {
|
||||||
width: 100%;
|
fill: none;
|
||||||
height: 2px;
|
stroke: rgba(239, 68, 68, 0.42);
|
||||||
transform: translate(-50%, -50%) rotate(-45deg);
|
stroke-width: 1;
|
||||||
|
vector-effect: non-scaling-stroke;
|
||||||
|
}
|
||||||
|
|
||||||
|
.origin-marker-node .origin-x {
|
||||||
|
stroke: rgba(239, 68, 68, 0.36);
|
||||||
|
stroke-width: 1;
|
||||||
|
vector-effect: non-scaling-stroke;
|
||||||
|
stroke-linecap: round;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ruler-point-node {
|
.ruler-point-node {
|
||||||
@@ -1643,6 +1734,7 @@ Organization : OptiHK Limited
|
|||||||
FORGE_COMPONENT_TYPE,
|
FORGE_COMPONENT_TYPE,
|
||||||
DEFAULT_COMPONENT_BOX_SIZE,
|
DEFAULT_COMPONENT_BOX_SIZE,
|
||||||
DEFAULT_CANVAS_SIZE,
|
DEFAULT_CANVAS_SIZE,
|
||||||
|
DEFAULT_CANVAS_BOUNDS,
|
||||||
PORT_NODE_SIZE,
|
PORT_NODE_SIZE,
|
||||||
DEFAULT_ELEMENT_PITCH,
|
DEFAULT_ELEMENT_PITCH,
|
||||||
ELEMENT_COMPONENTS,
|
ELEMENT_COMPONENTS,
|
||||||
@@ -1654,6 +1746,7 @@ Organization : OptiHK Limited
|
|||||||
normalizeBoxSize,
|
normalizeBoxSize,
|
||||||
chooseCategoryComponent,
|
chooseCategoryComponent,
|
||||||
normalizeCanvasSize,
|
normalizeCanvasSize,
|
||||||
|
normalizeCanvasBounds,
|
||||||
clampPositionToCanvas,
|
clampPositionToCanvas,
|
||||||
calculateLayoutBounds,
|
calculateLayoutBounds,
|
||||||
calculateCompositeBoxSize,
|
calculateCompositeBoxSize,
|
||||||
@@ -2218,14 +2311,24 @@ Organization : OptiHK Limited
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Draws the non-interactive canvas extent marker used by React Flow.
|
// Draws the non-interactive canvas extent marker used by React Flow.
|
||||||
const CanvasBoundaryNode = memo(({ data }) => (
|
const CanvasBoundaryNode = memo(({ data }) => {
|
||||||
<div className="canvas-boundary-node" title={`${data.size.width} x ${data.size.height} um`} />
|
const b = data.bounds || { xmin: 0, xmax: 5000, ymin: 0, ymax: 5000 };
|
||||||
));
|
return (<div className="canvas-boundary-node" title={`x[${b.xmin}, ${b.xmax}] y[${b.ymin}, ${b.ymax}] um`} />);
|
||||||
|
});
|
||||||
|
|
||||||
// Red "X" marker at the canvas origin (0,0). Non-selectable, always visible.
|
// Red "X" marker at the canvas origin (0,0). Non-selectable, always visible.
|
||||||
const OriginMarkerNode = memo(({ data }) => (
|
const OriginMarkerNode = memo(({ data }) => {
|
||||||
<div className="origin-marker-node" title={`Canvas origin (${(data.originX ?? 0).toFixed(1)}, ${(data.originY ?? 0).toFixed(1)})`} />
|
const title = `Canvas origin (${(data.originX ?? 0).toFixed(1)}, ${(data.originY ?? 0).toFixed(1)})`;
|
||||||
));
|
return (
|
||||||
|
<div className="origin-marker-node" title={title}>
|
||||||
|
<svg viewBox="-10 -10 20 20" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<circle className="origin-circle" cx="0" cy="0" r="6" />
|
||||||
|
<line className="origin-x" x1="-8" y1="-8" x2="8" y2="8" />
|
||||||
|
<line className="origin-x" x1="-8" y1="8" x2="8" y2="-8" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// Draws invisible connection handles for ruler measurement endpoints.
|
// Draws invisible connection handles for ruler measurement endpoints.
|
||||||
const RulerPointNode = memo(({ data }) => {
|
const RulerPointNode = memo(({ data }) => {
|
||||||
@@ -2396,7 +2499,7 @@ Organization : OptiHK Limited
|
|||||||
const startMouse = rfInstance.screenToFlowPosition({ x: e.clientX, y: e.clientY });
|
const startMouse = rfInstance.screenToFlowPosition({ x: e.clientX, y: e.clientY });
|
||||||
if (!startMouse) return;
|
if (!startMouse) return;
|
||||||
|
|
||||||
const canvasSize = data?.canvasSize || { width: 5000, height: 5000 };
|
const canvasBounds = data?.canvasBounds || data?.canvasSize || { xmin: 0, xmax: 5000, ymin: 0, ymax: 5000 };
|
||||||
const endpointIds = groupNodes
|
const endpointIds = groupNodes
|
||||||
.filter(n => !n.id.startsWith('ruler_label_'))
|
.filter(n => !n.id.startsWith('ruler_label_'))
|
||||||
.map(n => n.id);
|
.map(n => n.id);
|
||||||
@@ -2427,8 +2530,8 @@ Organization : OptiHK Limited
|
|||||||
rfInstance.setNodes(allNodes.map(node => {
|
rfInstance.setNodes(allNodes.map(node => {
|
||||||
const sn = startNodes.find(n => n.id === node.id);
|
const sn = startNodes.find(n => n.id === node.id);
|
||||||
if (!sn) return node;
|
if (!sn) return node;
|
||||||
const nx = Math.min(canvasSize.width, Math.max(0, sn.x + dx));
|
const nx = Math.min(canvasBounds.xmax, Math.max(canvasBounds.xmin, sn.x + dx));
|
||||||
const ny = Math.min(canvasSize.height, Math.max(0, sn.y + dy));
|
const ny = Math.min(canvasBounds.ymax, Math.max(canvasBounds.ymin, sn.y + dy));
|
||||||
return { ...node, position: { x: Number(nx.toFixed(3)), y: Number(ny.toFixed(3)) } };
|
return { ...node, position: { x: Number(nx.toFixed(3)), y: Number(ny.toFixed(3)) } };
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
@@ -2444,7 +2547,7 @@ Organization : OptiHK Limited
|
|||||||
|
|
||||||
el.addEventListener('mousedown', handleMouseDown);
|
el.addEventListener('mousedown', handleMouseDown);
|
||||||
return () => el.removeEventListener('mousedown', handleMouseDown);
|
return () => el.removeEventListener('mousedown', handleMouseDown);
|
||||||
}, [data?.rulerGroupId, data?.canvasSize, rfInstance]);
|
}, [data?.rulerGroupId, data?.canvasBounds, data?.canvasSize, rfInstance]);
|
||||||
|
|
||||||
const d = `M ${cx1} ${cy1} L ${cx2} ${cy2}`;
|
const d = `M ${cx1} ${cy1} L ${cx2} ${cy2}`;
|
||||||
const strokeColor = style?.stroke || '#2dd4bf';
|
const strokeColor = style?.stroke || '#2dd4bf';
|
||||||
@@ -2483,7 +2586,7 @@ Organization : OptiHK Limited
|
|||||||
const previewCanvasRef = useRef(null);
|
const previewCanvasRef = useRef(null);
|
||||||
const previewBounds = useMemo(
|
const previewBounds = useMemo(
|
||||||
() => page.layoutBounds || calculateLayoutBounds(page),
|
() => page.layoutBounds || calculateLayoutBounds(page),
|
||||||
[page.layoutBounds, page.nodes, page.canvasSize]
|
[page.layoutBounds, page.nodes, page.canvasSize, page.canvasBounds]
|
||||||
);
|
);
|
||||||
const minLayoutScale = 0.01;
|
const minLayoutScale = 0.01;
|
||||||
const maxLayoutScale = 800;
|
const maxLayoutScale = 800;
|
||||||
@@ -3029,11 +3132,11 @@ Organization : OptiHK Limited
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Renders project actions, canvas sizing controls, and the component library navigation.
|
// Renders project actions, canvas sizing controls, and the component library navigation.
|
||||||
const LeftPanel = ({ projectTreeItems, library, treeKey, expanded, onToggle, treeRef, width, onOpenComposite, onOpenProject, onSelectInstance, onRenameCanvas, onDeleteCanvas, onBuildGds, buildGdsBusy, onSaveProject, saveProjectBusy, projectExpanded, onProjectToggle, projectTreeRef, projectTreeKey, canvasSize, onCanvasSizeChange }) => {
|
const LeftPanel = ({ projectTreeItems, library, treeKey, expanded, onToggle, treeRef, width, onOpenComposite, onOpenProject, onSelectInstance, onRenameCanvas, onDeleteCanvas, onBuildGds, buildGdsBusy, onSaveProject, saveProjectBusy, projectExpanded, onProjectToggle, projectTreeRef, projectTreeKey, canvasBounds, onCanvasBoundsChange }) => {
|
||||||
const [projectPanelHeight, setProjectPanelHeight] = useState(270);
|
const [projectPanelHeight, setProjectPanelHeight] = useState(270);
|
||||||
const [resizingProjectPanel, setResizingProjectPanel] = useState(false);
|
const [resizingProjectPanel, setResizingProjectPanel] = useState(false);
|
||||||
const leftPanelRef = useRef(null);
|
const leftPanelRef = useRef(null);
|
||||||
const size = normalizeCanvasSize(canvasSize);
|
const bounds = normalizeCanvasBounds(canvasBounds);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!resizingProjectPanel) return;
|
if (!resizingProjectPanel) return;
|
||||||
@@ -3085,25 +3188,45 @@ Organization : OptiHK Limited
|
|||||||
</div>
|
</div>
|
||||||
<div className="left-block-body project-tree-scroll" style={{ flex: '1 1 0', minHeight: 0, overflowY: 'auto', overflowX: 'hidden' }} key={projectTreeKey} ref={projectTreeRef}>
|
<div className="left-block-body project-tree-scroll" style={{ flex: '1 1 0', minHeight: 0, overflowY: 'auto', overflowX: 'hidden' }} key={projectTreeKey} ref={projectTreeRef}>
|
||||||
<div className="canvas-size-panel">
|
<div className="canvas-size-panel">
|
||||||
<div className="canvas-size-title">Canvas Size</div>
|
<div className="canvas-size-title">Canvas Bounds</div>
|
||||||
<div>
|
<div>
|
||||||
<label>Width um</label>
|
<label>X min</label>
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
min="100"
|
min="0"
|
||||||
step="100"
|
step="100"
|
||||||
value={size.width}
|
value={bounds.xmin}
|
||||||
onChange={(event) => onCanvasSizeChange && onCanvasSizeChange('width', event.target.value)}
|
onChange={(event) => onCanvasBoundsChange && onCanvasBoundsChange('xmin', event.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label>Height um</label>
|
<label>X max</label>
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
min="100"
|
min="0"
|
||||||
step="100"
|
step="100"
|
||||||
value={size.height}
|
value={bounds.xmax}
|
||||||
onChange={(event) => onCanvasSizeChange && onCanvasSizeChange('height', event.target.value)}
|
onChange={(event) => onCanvasBoundsChange && onCanvasBoundsChange('xmax', event.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>Y min</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
step="100"
|
||||||
|
value={bounds.ymin}
|
||||||
|
onChange={(event) => onCanvasBoundsChange && onCanvasBoundsChange('ymin', event.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>Y max</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
step="100"
|
||||||
|
value={bounds.ymax}
|
||||||
|
onChange={(event) => onCanvasBoundsChange && onCanvasBoundsChange('ymax', event.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -4187,6 +4310,9 @@ Organization : OptiHK Limited
|
|||||||
const [mouseScreenPoint, setMouseScreenPoint] = useState(null);
|
const [mouseScreenPoint, setMouseScreenPoint] = useState(null);
|
||||||
const [canvasOrigin, setCanvasOrigin] = useState({ x: 0, y: 0 });
|
const [canvasOrigin, setCanvasOrigin] = useState({ x: 0, y: 0 });
|
||||||
const [originPickMode, setOriginPickMode] = useState(false);
|
const [originPickMode, setOriginPickMode] = useState(false);
|
||||||
|
const [originPickInputX, setOriginPickInputX] = useState('');
|
||||||
|
const [originPickInputY, setOriginPickInputY] = useState('');
|
||||||
|
const [originInputFocused, setOriginInputFocused] = useState(false);
|
||||||
const [projectTechnology, setProjectTechnology] = useState('');
|
const [projectTechnology, setProjectTechnology] = useState('');
|
||||||
const [technologyManifest, setTechnologyManifest] = useState(FALLBACK_TECHNOLOGY_MANIFEST);
|
const [technologyManifest, setTechnologyManifest] = useState(FALLBACK_TECHNOLOGY_MANIFEST);
|
||||||
const [currentLinkXsection, setCurrentLinkXsection] = useState('strip');
|
const [currentLinkXsection, setCurrentLinkXsection] = useState('strip');
|
||||||
@@ -4202,17 +4328,17 @@ Organization : OptiHK Limited
|
|||||||
const compositePageNameSet = useMemo(() => new Set(compositePageNames), [compositePageNames]);
|
const compositePageNameSet = useMemo(() => new Set(compositePageNames), [compositePageNames]);
|
||||||
const currentNodes = activePage && Array.isArray(activePage.nodes) ? activePage.nodes : [];
|
const currentNodes = activePage && Array.isArray(activePage.nodes) ? activePage.nodes : [];
|
||||||
const currentEdges = activePage && Array.isArray(activePage.edges) ? activePage.edges : [];
|
const currentEdges = activePage && Array.isArray(activePage.edges) ? activePage.edges : [];
|
||||||
const activeCanvasSize = useMemo(() => normalizeCanvasSize(activePage?.canvasSize), [activePage?.canvasSize]);
|
const activeCanvasBounds = useMemo(() => normalizeCanvasBounds(activePage?.canvasBounds || activePage?.canvasSize), [activePage?.canvasBounds, activePage?.canvasSize]);
|
||||||
// Track viewport dimensions to compute dynamic zoom limits.
|
// Track viewport dimensions to compute dynamic zoom limits.
|
||||||
const [canvasViewportSize, setCanvasViewportSize] = React.useState({ width: 1200, height: 800 });
|
const [canvasViewportSize, setCanvasViewportSize] = React.useState({ width: 1200, height: 800 });
|
||||||
// Set origin from the active page's saved value, or default to (500, H-500).
|
// Set origin from the active page's saved value, or default to (500, ymax-500).
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (activePage?.origin) {
|
if (activePage?.origin) {
|
||||||
setCanvasOrigin({ x: activePage.origin.x, y: activePage.origin.y });
|
setCanvasOrigin({ x: activePage.origin.x, y: activePage.origin.y });
|
||||||
} else if (activePage) {
|
} else if (activePage) {
|
||||||
setCanvasOrigin({ x: 500, y: activeCanvasSize.height - 500 });
|
setCanvasOrigin({ x: 500, y: activeCanvasBounds.ymax - 500 });
|
||||||
}
|
}
|
||||||
}, [activePage?.id, activePage?.origin?.x, activePage?.origin?.y, activeCanvasSize.height]);
|
}, [activePage?.id, activePage?.origin?.x, activePage?.origin?.y, activeCanvasBounds.ymax]);
|
||||||
|
|
||||||
// Observe viewport size changes to recalculate minZoom.
|
// Observe viewport size changes to recalculate minZoom.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -4275,16 +4401,15 @@ Organization : OptiHK Limited
|
|||||||
setCurrentLinkXsection(linkXsectionChoices[0] || 'strip');
|
setCurrentLinkXsection(linkXsectionChoices[0] || 'strip');
|
||||||
}
|
}
|
||||||
}, [linkXsectionChoices, currentLinkXsection]);
|
}, [linkXsectionChoices, currentLinkXsection]);
|
||||||
const canvasNodeExtent = useMemo(() => [[0, 0], [activeCanvasSize.width, activeCanvasSize.height]], [activeCanvasSize.width, activeCanvasSize.height]);
|
|
||||||
// Dynamic minZoom: viewport can show at most 120% of canvas size.
|
// Dynamic minZoom: viewport can show at most 120% of canvas size.
|
||||||
const canvasMinZoom = useMemo(() => {
|
const canvasMinZoom = useMemo(() => {
|
||||||
const cw = activeCanvasSize.width;
|
const cw = activeCanvasBounds.xmax - activeCanvasBounds.xmin;
|
||||||
const ch = activeCanvasSize.height;
|
const ch = activeCanvasBounds.ymax - activeCanvasBounds.ymin;
|
||||||
const vw = canvasViewportSize.width;
|
const vw = canvasViewportSize.width;
|
||||||
const vh = canvasViewportSize.height;
|
const vh = canvasViewportSize.height;
|
||||||
if (!cw || !ch || !vw || !vh) return 0.05;
|
if (!cw || !ch || !vw || !vh) return 0.05;
|
||||||
return Math.min(vw / cw, vh / ch) / 1.2;
|
return Math.min(vw / cw, vh / ch) / 1.2;
|
||||||
}, [activeCanvasSize.width, activeCanvasSize.height, canvasViewportSize.width, canvasViewportSize.height]);
|
}, [activeCanvasBounds.xmin, activeCanvasBounds.xmax, activeCanvasBounds.ymin, activeCanvasBounds.ymax, canvasViewportSize.width, canvasViewportSize.height]);
|
||||||
const rulerActiveEndPoint = rulerEndPoint || rulerPreviewPoint;
|
const rulerActiveEndPoint = rulerEndPoint || rulerPreviewPoint;
|
||||||
const rulerMeasurement = useMemo(
|
const rulerMeasurement = useMemo(
|
||||||
() => createRulerMeasurement(rulerStartPoint, rulerActiveEndPoint),
|
() => createRulerMeasurement(rulerStartPoint, rulerActiveEndPoint),
|
||||||
@@ -4435,16 +4560,18 @@ Organization : OptiHK Limited
|
|||||||
// Combines real nodes with boundary, ruler, and hidden route helper nodes for display.
|
// Combines real nodes with boundary, ruler, and hidden route helper nodes for display.
|
||||||
const renderNodes = useMemo(() => {
|
const renderNodes = useMemo(() => {
|
||||||
if (!activePage || activePage.type === 'layoutPreview') return currentNodes;
|
if (!activePage || activePage.type === 'layoutPreview') return currentNodes;
|
||||||
|
const bw = activeCanvasBounds.xmax - activeCanvasBounds.xmin;
|
||||||
|
const bh = activeCanvasBounds.ymax - activeCanvasBounds.ymin;
|
||||||
return [{
|
return [{
|
||||||
id: '__canvas-boundary__',
|
id: '__canvas-boundary__',
|
||||||
type: 'canvasBoundaryNode',
|
type: 'canvasBoundaryNode',
|
||||||
position: { x: 0, y: 0 },
|
position: { x: activeCanvasBounds.xmin, y: activeCanvasBounds.ymin },
|
||||||
data: { size: activeCanvasSize },
|
data: { bounds: activeCanvasBounds },
|
||||||
draggable: false,
|
draggable: false,
|
||||||
selectable: false,
|
selectable: false,
|
||||||
deletable: false,
|
deletable: false,
|
||||||
focusable: false,
|
focusable: false,
|
||||||
style: { width: activeCanvasSize.width, height: activeCanvasSize.height, zIndex: -1, pointerEvents: 'none' }
|
style: { width: bw, height: bh, zIndex: -1, pointerEvents: 'none' }
|
||||||
}, {
|
}, {
|
||||||
id: '__origin-marker__',
|
id: '__origin-marker__',
|
||||||
type: 'originMarkerNode',
|
type: 'originMarkerNode',
|
||||||
@@ -4456,7 +4583,7 @@ Organization : OptiHK Limited
|
|||||||
focusable: false,
|
focusable: false,
|
||||||
style: { zIndex: 10, pointerEvents: 'none' }
|
style: { zIndex: 10, pointerEvents: 'none' }
|
||||||
}, ...currentNodes, ...freeRouteEndpointNodes, ...rulerNodes];
|
}, ...currentNodes, ...freeRouteEndpointNodes, ...rulerNodes];
|
||||||
}, [activePage, currentNodes, activeCanvasSize, canvasOrigin, freeRouteEndpointNodes, rulerNodes]);
|
}, [activePage, currentNodes, activeCanvasBounds, canvasOrigin, freeRouteEndpointNodes, rulerNodes]);
|
||||||
// Resolves rotated anchor handle direction so connected canvas links exit the correct side.
|
// Resolves rotated anchor handle direction so connected canvas links exit the correct side.
|
||||||
const getAnchorHandleRouteDirection = useCallback((node, handleId) => {
|
const getAnchorHandleRouteDirection = useCallback((node, handleId) => {
|
||||||
if (!node || !handleId || !(node.type === 'anchorNode' || node.data?.elementType === 'anchor')) return null;
|
if (!node || !handleId || !(node.type === 'anchorNode' || node.data?.elementType === 'anchor')) return null;
|
||||||
@@ -4755,7 +4882,7 @@ Organization : OptiHK Limited
|
|||||||
const boxSize = node.type === 'rotatableNode'
|
const boxSize = node.type === 'rotatableNode'
|
||||||
? normalizeBoxSize({ box_size: node.data?.boxSize }, DEFAULT_COMPONENT_BOX_SIZE)
|
? normalizeBoxSize({ box_size: node.data?.boxSize }, DEFAULT_COMPONENT_BOX_SIZE)
|
||||||
: { width: 30, height: 30 };
|
: { width: 30, height: 30 };
|
||||||
return { ...node, position: clampPositionToCanvas(node.position, p.canvasSize || activeCanvasSize, boxSize) };
|
return { ...node, position: clampPositionToCanvas(node.position, p.canvasBounds || p.canvasSize || activeCanvasBounds, boxSize) };
|
||||||
});
|
});
|
||||||
// Sync ruler label position and text when endpoints are dragged.
|
// Sync ruler label position and text when endpoints are dragged.
|
||||||
const rulerUpdates = new Map();
|
const rulerUpdates = new Map();
|
||||||
@@ -4798,7 +4925,7 @@ Organization : OptiHK Limited
|
|||||||
}
|
}
|
||||||
return { ...p, nodes: newNodes, edges: newEdges, port: newPort };
|
return { ...p, nodes: newNodes, edges: newEdges, port: newPort };
|
||||||
}));
|
}));
|
||||||
}, [activePageId, activePage, activeCanvasSize]);
|
}, [activePageId, activePage, activeCanvasBounds]);
|
||||||
|
|
||||||
// Apply React Flow edge changes while preserving route style and selection state.
|
// Apply React Flow edge changes while preserving route style and selection state.
|
||||||
// Also cascades ruler group deletion when a ruler edge is removed.
|
// Also cascades ruler group deletion when a ruler edge is removed.
|
||||||
@@ -4860,7 +4987,7 @@ Organization : OptiHK Limited
|
|||||||
: { width: 30, height: 30 };
|
: { width: 30, height: 30 };
|
||||||
return {
|
return {
|
||||||
...n,
|
...n,
|
||||||
position: update.position != null ? clampPositionToCanvas(nextPosition, p.canvasSize || activeCanvasSize, boxSize) : nextPosition,
|
position: update.position != null ? clampPositionToCanvas(nextPosition, p.canvasSize || activeCanvasBounds, boxSize) : nextPosition,
|
||||||
data: nextData
|
data: nextData
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -4875,28 +5002,26 @@ Organization : OptiHK Limited
|
|||||||
}
|
}
|
||||||
return { ...p, nodes: newNodes, port: newPort };
|
return { ...p, nodes: newNodes, port: newPort };
|
||||||
}));
|
}));
|
||||||
}, [activePageId, activeCanvasSize]);
|
}, [activePageId, activeCanvasBounds]);
|
||||||
|
|
||||||
// Update active canvas dimensions and clamp existing node positions inside the new bounds.
|
// Update active canvas bounds (four-wall rectangle) and clamp existing node positions inside the new bounds.
|
||||||
const handleCanvasSizeChange = useCallback((axis, value) => {
|
const handleCanvasBoundsChange = useCallback((field, value) => {
|
||||||
if (!activePageId) return;
|
if (!activePageId) return;
|
||||||
const numericValue = Number(value);
|
const numericValue = Number(value);
|
||||||
if (!Number.isFinite(numericValue) || numericValue <= 0) return;
|
if (!Number.isFinite(numericValue) || numericValue < 0) return;
|
||||||
setPages(prev => prev.map(page => {
|
setPages(prev => prev.map(page => {
|
||||||
if (page.id !== activePageId) return page;
|
if (page.id !== activePageId) return page;
|
||||||
const nextCanvasSize = normalizeCanvasSize({
|
const prevBounds = normalizeCanvasBounds(page.canvasBounds || page.canvasSize);
|
||||||
...(page.canvasSize || DEFAULT_CANVAS_SIZE),
|
const nextCanvasBounds = { ...prevBounds, [field]: numericValue };
|
||||||
[axis]: numericValue
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
...page,
|
...page,
|
||||||
canvasSize: nextCanvasSize,
|
canvasBounds: nextCanvasBounds,
|
||||||
nodes: page.nodes.map(node => {
|
nodes: page.nodes.map(node => {
|
||||||
if (!node.position || node.id === 'page-port') return node;
|
if (!node.position || node.id === 'page-port') return node;
|
||||||
const boxSize = node.type === 'rotatableNode'
|
const boxSize = node.type === 'rotatableNode'
|
||||||
? normalizeBoxSize({ box_size: node.data?.boxSize }, DEFAULT_COMPONENT_BOX_SIZE)
|
? normalizeBoxSize({ box_size: node.data?.boxSize }, DEFAULT_COMPONENT_BOX_SIZE)
|
||||||
: { width: 30, height: 30 };
|
: { width: 30, height: 30 };
|
||||||
return { ...node, position: clampPositionToCanvas(node.position, nextCanvasSize, boxSize) };
|
return { ...node, position: clampPositionToCanvas(node.position, nextCanvasBounds, boxSize) };
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
@@ -5497,7 +5622,7 @@ Organization : OptiHK Limited
|
|||||||
id: newPageId,
|
id: newPageId,
|
||||||
name: newPageName,
|
name: newPageName,
|
||||||
type: isProject ? 'project' : 'composite',
|
type: isProject ? 'project' : 'composite',
|
||||||
canvasSize: normalizeCanvasSize(doc.canvas_size || doc.canvasSize),
|
canvasBounds: normalizeCanvasBounds(doc.canvas_bounds || doc.canvas_size || doc.canvasSize), canvasSize: normalizeCanvasSize(doc.canvas_size || doc.canvasSize),
|
||||||
nodes: isProject ? newNodes : [
|
nodes: isProject ? newNodes : [
|
||||||
{
|
{
|
||||||
id: 'page-port',
|
id: 'page-port',
|
||||||
@@ -5603,7 +5728,7 @@ Organization : OptiHK Limited
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
edges: [],
|
edges: [],
|
||||||
canvasSize: DEFAULT_CANVAS_SIZE,
|
canvasBounds: DEFAULT_CANVAS_BOUNDS, canvasSize: DEFAULT_CANVAS_SIZE,
|
||||||
port: { x: 600, y: 4400, a: 0 }
|
port: { x: 600, y: 4400, a: 0 }
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -5736,7 +5861,7 @@ Organization : OptiHK Limited
|
|||||||
id: `cell-${Date.now()}-${Math.random().toString(36).substr(2, 5)}`,
|
id: `cell-${Date.now()}-${Math.random().toString(36).substr(2, 5)}`,
|
||||||
name: doc.name || cellName,
|
name: doc.name || cellName,
|
||||||
type: doc.type === 'project' ? 'project' : 'composite',
|
type: doc.type === 'project' ? 'project' : 'composite',
|
||||||
canvasSize: normalizeCanvasSize(doc.canvas_size || doc.canvasSize),
|
canvasBounds: normalizeCanvasBounds(doc.canvas_bounds || doc.canvas_size || doc.canvasSize), canvasSize: normalizeCanvasSize(doc.canvas_size || doc.canvasSize),
|
||||||
nodes,
|
nodes,
|
||||||
edges,
|
edges,
|
||||||
port: pagePort || { x: 0, y: 0, a: 0 },
|
port: pagePort || { x: 0, y: 0, a: 0 },
|
||||||
@@ -5850,12 +5975,12 @@ Organization : OptiHK Limited
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
reactFlowInstance.fitBounds(
|
reactFlowInstance.fitBounds(
|
||||||
{ x: 0, y: 0, width: activeCanvasSize.width, height: activeCanvasSize.height },
|
{ x: activeCanvasBounds.xmin, y: activeCanvasBounds.ymin, width: activeCanvasBounds.xmax - activeCanvasBounds.xmin, height: activeCanvasBounds.ymax - activeCanvasBounds.ymin },
|
||||||
{ padding: 0.12, duration: 0 }
|
{ padding: 0.12, duration: 0 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [activePage?.id, activePage?.viewport, activeCanvasSize.width, activeCanvasSize.height, reactFlowInstance]);
|
}, [activePage?.id, activePage?.viewport, activeCanvasBounds.xmin, activeCanvasBounds.xmax, activeCanvasBounds.ymin, activeCanvasBounds.ymax, reactFlowInstance]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setRulerStartPoint(null);
|
setRulerStartPoint(null);
|
||||||
@@ -6014,7 +6139,7 @@ Organization : OptiHK Limited
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
edges: [],
|
edges: [],
|
||||||
canvasSize: DEFAULT_CANVAS_SIZE,
|
canvasBounds: DEFAULT_CANVAS_BOUNDS, canvasSize: DEFAULT_CANVAS_SIZE,
|
||||||
port: { x: 600, y: 4400, a: 0 }
|
port: { x: 600, y: 4400, a: 0 }
|
||||||
};
|
};
|
||||||
setActivePageId(newProjectPage.id);
|
setActivePageId(newProjectPage.id);
|
||||||
@@ -6046,7 +6171,7 @@ Organization : OptiHK Limited
|
|||||||
name: name,
|
name: name,
|
||||||
type: 'composite',
|
type: 'composite',
|
||||||
isClosed: false,
|
isClosed: false,
|
||||||
canvasSize: DEFAULT_CANVAS_SIZE,
|
canvasBounds: DEFAULT_CANVAS_BOUNDS, canvasSize: DEFAULT_CANVAS_SIZE,
|
||||||
nodes: [
|
nodes: [
|
||||||
{
|
{
|
||||||
id: 'page-port',
|
id: 'page-port',
|
||||||
@@ -6138,7 +6263,7 @@ Organization : OptiHK Limited
|
|||||||
name: cellName,
|
name: cellName,
|
||||||
type: 'composite',
|
type: 'composite',
|
||||||
isClosed: false,
|
isClosed: false,
|
||||||
canvasSize: DEFAULT_CANVAS_SIZE,
|
canvasBounds: DEFAULT_CANVAS_BOUNDS, canvasSize: DEFAULT_CANVAS_SIZE,
|
||||||
nodes: [
|
nodes: [
|
||||||
{
|
{
|
||||||
id: 'page-port',
|
id: 'page-port',
|
||||||
@@ -6285,7 +6410,7 @@ Organization : OptiHK Limited
|
|||||||
const compositeBoxSize = normalizeBoxSize({ box_size: parsedData.boxSize }, DEFAULT_COMPONENT_BOX_SIZE);
|
const compositeBoxSize = normalizeBoxSize({ box_size: parsedData.boxSize }, DEFAULT_COMPONENT_BOX_SIZE);
|
||||||
const position = clampPositionToCanvas(
|
const position = clampPositionToCanvas(
|
||||||
reactFlowInstance.screenToFlowPosition({ x: event.clientX, y: event.clientY }),
|
reactFlowInstance.screenToFlowPosition({ x: event.clientX, y: event.clientY }),
|
||||||
activePage?.canvasSize || activeCanvasSize,
|
activePage?.canvasSize || activeCanvasBounds,
|
||||||
compositeBoxSize
|
compositeBoxSize
|
||||||
);
|
);
|
||||||
const newNode = {
|
const newNode = {
|
||||||
@@ -6336,7 +6461,7 @@ Organization : OptiHK Limited
|
|||||||
const compositeBoxSize = normalizeBoxSize({ box_size: parsedData.boxSize }, DEFAULT_COMPONENT_BOX_SIZE);
|
const compositeBoxSize = normalizeBoxSize({ box_size: parsedData.boxSize }, DEFAULT_COMPONENT_BOX_SIZE);
|
||||||
const position = clampPositionToCanvas(
|
const position = clampPositionToCanvas(
|
||||||
reactFlowInstance.screenToFlowPosition({ x: event.clientX, y: event.clientY }),
|
reactFlowInstance.screenToFlowPosition({ x: event.clientX, y: event.clientY }),
|
||||||
activePage?.canvasSize || activeCanvasSize,
|
activePage?.canvasSize || activeCanvasBounds,
|
||||||
compositeBoxSize
|
compositeBoxSize
|
||||||
);
|
);
|
||||||
const newNode = {
|
const newNode = {
|
||||||
@@ -6382,7 +6507,7 @@ Organization : OptiHK Limited
|
|||||||
}
|
}
|
||||||
const position = clampPositionToCanvas(
|
const position = clampPositionToCanvas(
|
||||||
reactFlowInstance.screenToFlowPosition({ x: event.clientX, y: event.clientY }),
|
reactFlowInstance.screenToFlowPosition({ x: event.clientX, y: event.clientY }),
|
||||||
activePage?.canvasSize || activeCanvasSize,
|
activePage?.canvasSize || activeCanvasBounds,
|
||||||
parsedData.type === 'element'
|
parsedData.type === 'element'
|
||||||
? buildElementBoxSize({ elementType: parsedData.elementType === 'anchor' ? 'anchor' : 'port', portNumber: 1, pitch: DEFAULT_ELEMENT_PITCH })
|
? buildElementBoxSize({ elementType: parsedData.elementType === 'anchor' ? 'anchor' : 'port', portNumber: 1, pitch: DEFAULT_ELEMENT_PITCH })
|
||||||
: DEFAULT_COMPONENT_BOX_SIZE
|
: DEFAULT_COMPONENT_BOX_SIZE
|
||||||
@@ -6395,7 +6520,7 @@ Organization : OptiHK Limited
|
|||||||
const newNode = {
|
const newNode = {
|
||||||
id: Date.now().toString(),
|
id: Date.now().toString(),
|
||||||
type: 'rotatableNode',
|
type: 'rotatableNode',
|
||||||
position: clampPositionToCanvas(position, activePage?.canvasSize || activeCanvasSize, normalizeBoxSize(metadata)),
|
position: clampPositionToCanvas(position, activePage?.canvasSize || activeCanvasBounds, normalizeBoxSize(metadata)),
|
||||||
data: {
|
data: {
|
||||||
label: componentName,
|
label: componentName,
|
||||||
componentName,
|
componentName,
|
||||||
@@ -6442,7 +6567,7 @@ Organization : OptiHK Limited
|
|||||||
: {
|
: {
|
||||||
id: Date.now().toString(),
|
id: Date.now().toString(),
|
||||||
type: 'anchorNode',
|
type: 'anchorNode',
|
||||||
position: clampPositionToCanvas(position, activePage?.canvasSize || activeCanvasSize, buildElementBoxSize({ elementType: 'anchor', portNumber: 1, pitch: DEFAULT_ELEMENT_PITCH })),
|
position: clampPositionToCanvas(position, activePage?.canvasSize || activeCanvasBounds, buildElementBoxSize({ elementType: 'anchor', portNumber: 1, pitch: DEFAULT_ELEMENT_PITCH })),
|
||||||
data: {
|
data: {
|
||||||
label: elementName,
|
label: elementName,
|
||||||
componentName: 'Anchor',
|
componentName: 'Anchor',
|
||||||
@@ -6536,7 +6661,7 @@ Organization : OptiHK Limited
|
|||||||
cell: activePage?.name,
|
cell: activePage?.name,
|
||||||
detail: { component: parsedData.name, instance: componentDisplayName, category: parsedData.category }
|
detail: { component: parsedData.name, instance: componentDisplayName, category: parsedData.category }
|
||||||
});
|
});
|
||||||
}, [activePageId, activePage, activeCanvasSize, openPage, reactFlowInstance, generateComponentDisplayName, syncCompositePlacement, recordUserAction, currentProjectName, toBooleanFlag]);
|
}, [activePageId, activePage, activeCanvasBounds, openPage, reactFlowInstance, generateComponentDisplayName, syncCompositePlacement, recordUserAction, currentProjectName, toBooleanFlag]);
|
||||||
|
|
||||||
// Expand all library tree nodes.
|
// Expand all library tree nodes.
|
||||||
const expandAll = useCallback(() => {
|
const expandAll = useCallback(() => {
|
||||||
@@ -6609,15 +6734,15 @@ Organization : OptiHK Limited
|
|||||||
setOriginPickMode(false);
|
setOriginPickMode(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Convert a pane click or pointer event into canvas coordinates.
|
// Convert a pane click or pointer event into canvas coordinates (raw, no clamp).
|
||||||
const eventToCanvasPoint = useCallback((event) => {
|
const eventToCanvasPoint = useCallback((event) => {
|
||||||
if (!reactFlowInstance || !event) return null;
|
if (!reactFlowInstance || !event) return null;
|
||||||
const rawPoint = reactFlowInstance.screenToFlowPosition({ x: event.clientX, y: event.clientY });
|
const rawPoint = reactFlowInstance.screenToFlowPosition({ x: event.clientX, y: event.clientY });
|
||||||
return {
|
return {
|
||||||
x: Number(Math.min(activeCanvasSize.width, Math.max(0, rawPoint.x)).toFixed(3)),
|
x: Number(rawPoint.x.toFixed(3)),
|
||||||
y: Number(Math.min(activeCanvasSize.height, Math.max(0, rawPoint.y)).toFixed(3))
|
y: Number(rawPoint.y.toFixed(3))
|
||||||
};
|
};
|
||||||
}, [reactFlowInstance, activeCanvasSize.width, activeCanvasSize.height]);
|
}, [reactFlowInstance]);
|
||||||
|
|
||||||
const updateMouseCanvasPoint = useCallback((event) => {
|
const updateMouseCanvasPoint = useCallback((event) => {
|
||||||
if (!activePage || activePage.type === 'layoutPreview') return null;
|
if (!activePage || activePage.type === 'layoutPreview') return null;
|
||||||
@@ -6642,11 +6767,63 @@ Organization : OptiHK Limited
|
|||||||
setRulerStartPoint(null);
|
setRulerStartPoint(null);
|
||||||
setRulerEndPoint(null);
|
setRulerEndPoint(null);
|
||||||
setRulerPreviewPoint(null);
|
setRulerPreviewPoint(null);
|
||||||
|
} else {
|
||||||
|
setOriginPickInputX('');
|
||||||
|
setOriginPickInputY('');
|
||||||
|
setOriginInputFocused(false);
|
||||||
}
|
}
|
||||||
return next;
|
return next;
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Sync mouse position to origin pick inputs during pick mode (only when inputs are not focused).
|
||||||
|
useEffect(() => {
|
||||||
|
if (!originPickMode || originInputFocused || !mouseCanvasPoint) return;
|
||||||
|
setOriginPickInputX(mouseCanvasPoint.x.toFixed(3));
|
||||||
|
setOriginPickInputY(mouseCanvasPoint.y.toFixed(3));
|
||||||
|
}, [originPickMode, mouseCanvasPoint, originInputFocused]);
|
||||||
|
|
||||||
|
// Apply manually entered origin coordinates from the input panel.
|
||||||
|
const handleApplyOriginInput = useCallback(() => {
|
||||||
|
const x = parseFloat(originPickInputX);
|
||||||
|
const y = parseFloat(originPickInputY);
|
||||||
|
if (Number.isFinite(x) && Number.isFinite(y)) {
|
||||||
|
// Origin always snaps to 10 um grid (no canvas clamp — origin may be outside bounds).
|
||||||
|
const snapped = {
|
||||||
|
x: Math.round(x / 10) * 10,
|
||||||
|
y: Math.round(y / 10) * 10
|
||||||
|
};
|
||||||
|
setCanvasOrigin(snapped);
|
||||||
|
setPages(prev => prev.map(p => p.id === activePage.id ? { ...p, origin: snapped } : p));
|
||||||
|
setOriginPickMode(false);
|
||||||
|
setOriginPickInputX('');
|
||||||
|
setOriginPickInputY('');
|
||||||
|
setOriginInputFocused(false);
|
||||||
|
addLog(`Canvas origin: (${snapped.x.toFixed(3)}, ${snapped.y.toFixed(3)}) um (manual)`);
|
||||||
|
}
|
||||||
|
}, [originPickInputX, originPickInputY, activePage, setPages, addLog]);
|
||||||
|
|
||||||
|
// Live-preview origin as the user edits the input fields (grid-snapped).
|
||||||
|
const handleOriginInputChange = useCallback((axis, rawValue) => {
|
||||||
|
const val = parseFloat(rawValue);
|
||||||
|
if (!Number.isFinite(val)) {
|
||||||
|
if (axis === 'x') setOriginPickInputX(rawValue);
|
||||||
|
else setOriginPickInputY(rawValue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const otherAxis = axis === 'x' ? 'y' : 'x';
|
||||||
|
const otherVal = parseFloat(axis === 'x' ? originPickInputY : originPickInputX);
|
||||||
|
const xRaw = axis === 'x' ? val : (Number.isFinite(otherVal) ? otherVal : canvasOrigin.x);
|
||||||
|
const yRaw = axis === 'y' ? val : (Number.isFinite(otherVal) ? otherVal : canvasOrigin.y);
|
||||||
|
const snapped = {
|
||||||
|
x: Math.round(xRaw / 10) * 10,
|
||||||
|
y: Math.round(yRaw / 10) * 10
|
||||||
|
};
|
||||||
|
if (axis === 'x') setOriginPickInputX(rawValue);
|
||||||
|
else setOriginPickInputY(rawValue);
|
||||||
|
setCanvasOrigin(snapped);
|
||||||
|
}, [originPickInputX, originPickInputY, canvasOrigin.x, canvasOrigin.y]);
|
||||||
|
|
||||||
// Set ruler endpoints from canvas clicks. First click sets start, second click persists measurement and exits ruler mode.
|
// Set ruler endpoints from canvas clicks. First click sets start, second click persists measurement and exits ruler mode.
|
||||||
const handleRulerPaneClick = useCallback((event) => {
|
const handleRulerPaneClick = useCallback((event) => {
|
||||||
if (!rulerMode || !reactFlowInstance || !activePage || activePage.type === 'layoutPreview') return;
|
if (!rulerMode || !reactFlowInstance || !activePage || activePage.type === 'layoutPreview') return;
|
||||||
@@ -6709,7 +6886,7 @@ Organization : OptiHK Limited
|
|||||||
type: 'rulerEdge',
|
type: 'rulerEdge',
|
||||||
selectable: true,
|
selectable: true,
|
||||||
focusable: true,
|
focusable: true,
|
||||||
data: { ruler: true, rulerGroupId, canvasSize: activePage.canvasSize || activeCanvasSize },
|
data: { ruler: true, rulerGroupId, canvasBounds: activePage.canvasBounds || activePage.canvasSize || activeCanvasBounds },
|
||||||
style: {
|
style: {
|
||||||
stroke: '#2dd4bf',
|
stroke: '#2dd4bf',
|
||||||
strokeWidth: 2
|
strokeWidth: 2
|
||||||
@@ -6745,11 +6922,20 @@ Organization : OptiHK Limited
|
|||||||
if (!nextPoint) return false;
|
if (!nextPoint) return false;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
setCanvasOrigin(nextPoint);
|
// Origin always snaps to 10 um grid regardless of Snap to Grid toggle.
|
||||||
|
const snapped = {
|
||||||
|
x: Math.round(nextPoint.x / 10) * 10,
|
||||||
|
y: Math.round(nextPoint.y / 10) * 10
|
||||||
|
};
|
||||||
|
setCanvasOrigin(snapped);
|
||||||
|
setPages(prev => prev.map(p => p.id === activePage.id ? { ...p, origin: snapped } : p));
|
||||||
setOriginPickMode(false);
|
setOriginPickMode(false);
|
||||||
addLog(`Canvas origin: (${nextPoint.x.toFixed(3)}, ${nextPoint.y.toFixed(3)}) um`);
|
setOriginPickInputX('');
|
||||||
|
setOriginPickInputY('');
|
||||||
|
setOriginInputFocused(false);
|
||||||
|
addLog(`Canvas origin: (${snapped.x.toFixed(3)}, ${snapped.y.toFixed(3)}) um`);
|
||||||
return true;
|
return true;
|
||||||
}, [originPickMode, activePage, updateMouseCanvasPoint, eventToCanvasPoint, addLog]);
|
}, [originPickMode, activePage, updateMouseCanvasPoint, eventToCanvasPoint, setPages, addLog]);
|
||||||
|
|
||||||
const handleCanvasMouseMove = useCallback((event) => {
|
const handleCanvasMouseMove = useCallback((event) => {
|
||||||
updateMouseCanvasPoint(event);
|
updateMouseCanvasPoint(event);
|
||||||
@@ -7011,9 +7197,14 @@ Organization : OptiHK Limited
|
|||||||
schema_version: "2.0.0"
|
schema_version: "2.0.0"
|
||||||
kind: cell
|
kind: cell
|
||||||
coordinate_system: gds_y_up
|
coordinate_system: gds_y_up
|
||||||
|
canvas_bounds:
|
||||||
|
xmin: ${Number(page.canvasBounds?.xmin ?? 0)}
|
||||||
|
xmax: ${Number(page.canvasBounds?.xmax ?? DEFAULT_CANVAS_BOUNDS.xmax)}
|
||||||
|
ymin: ${Number(page.canvasBounds?.ymin ?? 0)}
|
||||||
|
ymax: ${Number(page.canvasBounds?.ymax ?? DEFAULT_CANVAS_BOUNDS.ymax)}
|
||||||
canvas_size:
|
canvas_size:
|
||||||
width: ${Number(page.canvasSize?.width || DEFAULT_CANVAS_SIZE.width)}
|
width: ${Number(page.canvasSize?.width || page.canvasBounds ? (page.canvasBounds.xmax - page.canvasBounds.xmin) : DEFAULT_CANVAS_SIZE.width)}
|
||||||
height: ${Number(page.canvasSize?.height || DEFAULT_CANVAS_SIZE.height)}
|
height: ${Number(page.canvasSize?.height || page.canvasBounds ? (page.canvasBounds.ymax - page.canvasBounds.ymin) : DEFAULT_CANVAS_SIZE.height)}
|
||||||
origin:
|
origin:
|
||||||
x: ${Number(canvasOrigin.x).toFixed(1)}
|
x: ${Number(canvasOrigin.x).toFixed(1)}
|
||||||
y: ${Number(canvasOrigin.y).toFixed(1)}
|
y: ${Number(canvasOrigin.y).toFixed(1)}
|
||||||
@@ -7222,8 +7413,8 @@ ${bundlesBlock}`;
|
|||||||
onProjectToggle={handleProjectToggle}
|
onProjectToggle={handleProjectToggle}
|
||||||
projectTreeRef={projectTreeContainerRef}
|
projectTreeRef={projectTreeContainerRef}
|
||||||
projectTreeKey={projectTreeKey}
|
projectTreeKey={projectTreeKey}
|
||||||
canvasSize={activeCanvasSize}
|
canvasBounds={activeCanvasBounds}
|
||||||
onCanvasSizeChange={handleCanvasSizeChange}
|
onCanvasBoundsChange={handleCanvasBoundsChange}
|
||||||
/>
|
/>
|
||||||
<ResizeHandle onMouseDown={handleResizeStart('left')} />
|
<ResizeHandle onMouseDown={handleResizeStart('left')} />
|
||||||
|
|
||||||
@@ -7359,6 +7550,37 @@ ${bundlesBlock}`;
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{originPickMode && activePage?.type !== 'layoutPreview' && (
|
||||||
|
<div className="origin-pick-panel">
|
||||||
|
<label>
|
||||||
|
X
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
value={originPickInputX}
|
||||||
|
onChange={e => handleOriginInputChange('x', e.target.value)}
|
||||||
|
onFocus={() => setOriginInputFocused(true)}
|
||||||
|
onBlur={() => setOriginInputFocused(false)}
|
||||||
|
step="0.1"
|
||||||
|
placeholder="0.000"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
Y
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
value={originPickInputY}
|
||||||
|
onChange={e => handleOriginInputChange('y', e.target.value)}
|
||||||
|
onFocus={() => setOriginInputFocused(true)}
|
||||||
|
onBlur={() => setOriginInputFocused(false)}
|
||||||
|
step="0.1"
|
||||||
|
placeholder="0.000"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<button onClick={(e) => { e.stopPropagation(); handleApplyOriginInput(); }}>Apply</button>
|
||||||
|
<button className="cancel-btn" onClick={(e) => { e.stopPropagation(); toggleOriginPickMode(); }}>Cancel</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{activePage && activePage.type !== 'layoutPreview' && (
|
{activePage && activePage.type !== 'layoutPreview' && (
|
||||||
<button
|
<button
|
||||||
onClick={handleBuildLayout}
|
onClick={handleBuildLayout}
|
||||||
@@ -7391,7 +7613,6 @@ ${bundlesBlock}`;
|
|||||||
onNodeMouseUp={clearSpaceRotateNode}
|
onNodeMouseUp={clearSpaceRotateNode}
|
||||||
nodeTypes={{ rotatableNode: RotatableNode, portNode: PortNode, anchorNode: AnchorNode, canvasBoundaryNode: CanvasBoundaryNode, originMarkerNode: OriginMarkerNode, rulerPointNode: RulerPointNode, rulerMeasurementNode: RulerMeasurementNode }}
|
nodeTypes={{ rotatableNode: RotatableNode, portNode: PortNode, anchorNode: AnchorNode, canvasBoundaryNode: CanvasBoundaryNode, originMarkerNode: OriginMarkerNode, rulerPointNode: RulerPointNode, rulerMeasurementNode: RulerMeasurementNode }}
|
||||||
edgeTypes={edgeTypes}
|
edgeTypes={edgeTypes}
|
||||||
nodeExtent={canvasNodeExtent}
|
|
||||||
snapToGrid={gridSnap}
|
snapToGrid={gridSnap}
|
||||||
snapGrid={[10, 10]}
|
snapGrid={[10, 10]}
|
||||||
nodesDraggable={true}
|
nodesDraggable={true}
|
||||||
|
|||||||
Reference in New Issue
Block a user