15 Commits

Author SHA1 Message Date
= 47ea2b5446 Merge branch 'jingwen_main' into qinyue_main 2026-06-22 10:08:24 +08:00
= 049293b3d8 Canvas break problem fixed with version problem 2026-06-22 10:08:05 +08:00
xsxx03-art 944bc26fb9 upadate 2026-06-16 20:31:34 +08:00
= a230f13cd7 icons updatted 2026-06-11 23:06:52 +08:00
PotatoMaxwell 69da8c4fbb Merge pull request 'port/anchor size adjustment' (#10) from jingwen_main into qinyue_main
Reviewed-on: #10
2026-06-11 13:45:08 +00:00
xsxx03-art 5db13a7d69 port/anchor size adjustment 2026-06-11 20:45:26 +08:00
= d577edf348 Fix project reopen persistence 2026-06-10 19:10:59 +08:00
root 7195dea7cd SVG preview fitting size problem solved 2026-06-09 20:58:37 +08:00
PotatoMaxwell fa0ebe899c Merge pull request 'rotation bug fixed' (#9) from jingwen_main into qinyue_main
Reviewed-on: #9
2026-06-09 12:17:23 +00:00
xsxx03-art 2846899097 rotation bug fixed 2026-06-08 18:54:42 +08:00
root 7953c8b624 Bundle group added to .yml generation and canvas 2026-06-08 16:34:39 +08:00
root 75dd78aa33 database removed outside 2026-06-08 14:48:14 +08:00
PotatoMaxwell bf8e72f5b6 Merge pull request 'update canvas.html' (#8) from jingwen_main into qinyue_main
Reviewed-on: #8
2026-06-08 05:20:38 +00:00
xsxx03-art 2ddd30e7bb update canvas.html 2026-06-05 20:32:16 +08:00
= 1b7357e419 redundent files deleted 2026-06-04 20:01:32 +08:00
100 changed files with 1905 additions and 3059 deletions
+8
View File
@@ -1,3 +1,11 @@
*/__pycache__/
__pycache__/
*.pyc
# Runtime data belongs outside this repository.
/database/
/backend/*.db
*.db-journal
*.db-shm
*.db-wal
/mxpic_EDA_database/
-218
View File
@@ -1,218 +0,0 @@
# GDS and SVG Generation Logic Path
This document traces the current code path for generating saved layout YAML,
layout preview SVG, and downloadable project GDS when the user clicks
`Build Layout` or `Build GDS`.
Line numbers refer to the files as currently checked in.
## Build-Time Router Gate
`python backend/server.py` -> `app.run` starts without importing
`mxpic_router`, `mxpic_forge`, Nazca, or gdstk. Login, dashboard, canvas
editing, YAML generation, PDK browsing, and project save without preview do not
require the external build stack.
Build actions validate the external stack on demand:
- `Build GDS` -> `backend/gds_builder.py` -> `require_router_stack()`.
- `Build Layout` SVG preview -> `backend/routed_layout_preview.py` ->
`require_router_stack(require_gdstk=True)`.
Important functions:
- `ensure_router_path` (`backend/router_dependency.py` line 23) adds the sibling
`../mxpic_router` checkout to `sys.path` when present.
- `require_router_stack` (`backend/router_dependency.py` line 31) imports
`mxpic_router`, `nazca`, and the route backend used by `mxpic_router`.
The preferred route backend is `mxpic_forge.Route`; if it is absent,
`mxpic_router` falls back to Nazca `interconnects.Interconnect`.
`gdstk` is checked only when SVG preview generation requests it.
## Generated Files
- Saved cell YAML: `database/<username>/layout/<project>/<cell>.yml`
- Path helpers: `user_layout_root`, `project_root`, `cell_file_path`
(`backend/server.py` lines 124-137).
- Saved layout preview SVG: `database/<username>/layout/<project>/<cell>.svg`
- Path helper: `cell_svg_path` (`backend/server.py` lines 140-142).
- Optional route sidecar: `database/<username>/layout/<project>/<cell>.routes.yml`
- Path helper and writer: `cell_routes_path`, `write_route_points_sidecar`
(`backend/server.py` lines 145-175).
- Downloadable GDS export: `database/_exports/<uuid>/<project>.gds`
- Created by `create_export_path` (`backend/pdk_access.py` lines 53-59).
## Build Layout: Click Button -> YAML -> Router GDS -> SVG
Compact path:
`Click Build Layout` -> `handleBuildLayout` (`frontend/canvas.html` line 6209) :
`buildYamlForPage` (`frontend/canvas.html` line 6141) generates layout YAML ->
POST `/api/save-layout` (`frontend/canvas.html` line 6219) -> `save_layout`
(`backend/server.py` line 715) writes `<cell>.yml` -> `create_routed_layout_svg`
(`backend/server.py` line 734) -> `mxpic_router.build_project_gds` generates
temporary Nazca GDS -> `gdstk.read_gds` + `write_svg` writes `<cell>.svg` ->
backend returns `svg_url` -> `openLayoutPreview` (`frontend/canvas.html` line
6183) opens the SVG preview tab.
Detailed path:
1. The button is rendered only for non-preview pages:
- `<button onClick={handleBuildLayout}>` (`frontend/canvas.html` lines
6491-6498).
2. `handleBuildLayout` creates YAML for the active page:
- `handleBuildLayout` starts at `frontend/canvas.html` line 6209.
- It validates route crossings and calls `buildYamlForPage(activePage)` at
line 6215.
- `buildYamlForPage` starts at line 6141 and writes:
- `schema_version`, `kind`, `coordinate_system: gds_y_up`,
`canvas_size`, `project`, `name`, `type`, `version`.
- `pins` via `buildCanvasPinsYaml`.
- `instances` via `buildInstancesYaml`.
- `elements` via `buildElementsYaml`.
- `bundles` via `buildBundlesYaml`.
3. Frontend sends the YAML to Flask:
- `fetch('/api/save-layout', ...)` at `frontend/canvas.html` line 6219.
- Body includes `project`, `cell`, and `content` at lines 6222-6226.
4. Flask saves YAML and route sidecar:
- Route: `/api/save-layout` (`backend/server.py` line 713).
- Function: `save_layout` (`backend/server.py` line 715).
- `save_path = cell_file_path(project, cell)` (`backend/server.py` line 724).
- Writes the YAML content to disk (`backend/server.py` lines 727-728).
- Extracts route points into `<cell>.routes.yml` through
`write_route_points_sidecar` (`backend/server.py` line 729).
5. Flask always uses the router-backed SVG preview:
- Preview output path is computed with `cell_svg_path`
(`backend/server.py` line 733).
- `create_routed_layout_svg(...)` is called unconditionally for preview
generation (`backend/server.py` lines 734-742).
- There is no production branch based on `bundles.*.links`; no-link and
linked layouts both use the same router path.
6. Routed preview helper converts router GDS into SVG:
- `create_routed_layout_svg` starts at `backend/routed_layout_preview.py`
line 14.
- It loads the YAML string, gets the target cell name, and imports
`mxpic_router.build_project_gds` (`backend/routed_layout_preview.py` lines
25-32).
- It builds a temporary GDS with `target_cell_name=cell_name`
(`backend/routed_layout_preview.py` lines 37-46).
- It reads that temporary GDS with `gdstk.read_gds`
(`backend/routed_layout_preview.py` line 47).
- It writes the saved preview SVG with `top_cells[0].write_svg(output_path)`
(`backend/routed_layout_preview.py` line 51).
Inside sibling router checkout:
- `mxpic_router.build_project_gds` starts at
`../mxpic_router/mxpic_router/builder.py` line 12.
- `_load_project_specs` reads all saved `.yml` / `.yaml` files from the project
directory (`../mxpic_router/mxpic_router/builder.py` line 46).
- `load_cell_spec` reads YAML with `yaml.safe_load`
(`../mxpic_router/mxpic_router/eda_loader.py` line 80).
- `parse_cell_dict` converts YAML into `CellSpec`, including `pins`,
`elements`, `instances`, and `bundles`
(`../mxpic_router/mxpic_router/eda_loader.py` lines 85-157).
- `_build_cell` creates `with nd.Cell(name=spec.name) as top`
(`../mxpic_router/mxpic_router/builder.py` line 70).
- `_build_cell` places basic, local, or PDK GDS instances and registers pins
(`../mxpic_router/mxpic_router/builder.py` lines 73-108).
- `_route_link` draws routed geometry for each bundle link when links exist
(`../mxpic_router/mxpic_router/builder.py` line 269).
- `nd.export_gds(topcells=[built_cells[top.name]], filename=output_path)`
writes the temporary routed GDS (`../mxpic_router/mxpic_router/builder.py`
line 37).
## Build GDS: Click Button -> Saved YAML -> Router GDS
Compact path:
`Click Build GDS` -> Project Tree button calls `onBuildGds`
(`frontend/canvas.html` line 2738) -> `handleBuildGds`
(`frontend/canvas.html` line 6287) -> POST `/api/build-gds`
(`frontend/canvas.html` line 6294) -> `build_gds`
(`backend/server.py` line 775) -> `build_project_gds`
(`backend/gds_builder.py` line 26) : read saved `.yml` files for project
validation -> `_build_with_mxpic_router` (`backend/gds_builder.py` line 47) ->
`mxpic_router` creates `nd.Cell` objects and exports `.gds` -> backend returns
`download_url` -> frontend clicks a temporary download link.
Detailed path:
1. The `Build GDS` button is in the project tree header:
- `<button className="build-gds-btn" onClick={onBuildGds}>`
(`frontend/canvas.html` lines 2738-2739).
- `onBuildGds={handleBuildGds}` is passed into `LeftPanel`
(`frontend/canvas.html` line 6354).
2. `handleBuildGds` calls the backend:
- Function starts at `frontend/canvas.html` line 6287.
- It validates route crossings for all non-preview pages
(`frontend/canvas.html` lines 6289-6290).
- It POSTs only `{ project: currentProjectName }` to `/api/build-gds`
(`frontend/canvas.html` lines 6294-6298).
Important behavior:
- `Build GDS` does not serialize the current in-memory canvas first.
- It reads YAML files that already exist on disk.
- Those YAML files are produced by `Build Layout` or by the separate `Save`
button, where `handleSaveProjectLayouts` saves every non-preview page with
`preview: false` (`frontend/canvas.html` lines 6253-6284).
3. Flask creates a temporary export path and calls the GDS builder:
- Route: `/api/build-gds` (`backend/server.py` line 773).
- Function: `build_gds` (`backend/server.py` line 775).
- Old exports are cleaned (`backend/server.py` line 781).
- The project directory is resolved and validated
(`backend/server.py` lines 782-784).
- `create_export_path` creates `database/_exports/<uuid>/<project>.gds`
(`backend/server.py` line 785, `backend/pdk_access.py` lines 53-59).
- `build_project_gds(...)` is called (`backend/server.py` lines 786-792).
4. `backend/gds_builder.py` delegates to `mxpic_router`:
- `build_project_gds` starts at `backend/gds_builder.py` line 26.
- `_load_project_cells(project_dir)` reads every saved `.yml` / `.yaml`
file for validation (`backend/gds_builder.py` line 73).
- `_build_with_mxpic_router` starts at `backend/gds_builder.py` line 47.
- `_build_with_mxpic_router` calls `ensure_router_path` and imports
`mxpic_router.build_project_gds` (`backend/gds_builder.py` lines 54-55).
- There is no production fallback to local gdstk or local Nazca builders.
5. `mxpic_router` builds the final GDS:
- `mxpic_router.build_project_gds` starts at
`../mxpic_router/mxpic_router/builder.py` line 12.
- `_build_cell` creates one `nd.Cell` per `CellSpec`
(`../mxpic_router/mxpic_router/builder.py` line 70).
- `_resolve_pdk_asset` finds component YAML/GDS in the active PDK root
(`../mxpic_router/mxpic_router/builder.py` line 509).
- `_route_link` draws routed geometry when saved bundle links exist
(`../mxpic_router/mxpic_router/builder.py` line 269).
- `nd.export_gds(...)` writes the output GDS
(`../mxpic_router/mxpic_router/builder.py` line 37).
## PDK Asset Resolution
The active PDK root still comes from the EDA backend request/session state:
- `current_pdk_root` uses `pdk_root_for_session`
(`backend/server.py` lines 196-198).
- `pdk_root_for_session` chooses the root based on the logged-in user group
(`backend/pdk_access.py` lines 43-50).
- Preview and GDS generation pass that PDK root into `mxpic_router`.
- `mxpic_router._resolve_pdk_asset` resolves component YAML/GDS under that root
(`../mxpic_router/mxpic_router/builder.py` line 509).
## Download Completion
After GDS build:
`build_gds` returns `download_url` (`backend/server.py` line 803) ->
`handleBuildGds` creates a temporary `<a>` and clicks it
(`frontend/canvas.html` lines 6309-6316) -> `/api/exports/<export_id>/<filename>`
serves the GDS (`backend/server.py` lines 812-829) -> the temporary export
folder is deleted when the response closes (`backend/server.py` line 829).
-84
View File
@@ -1,84 +0,0 @@
<!--
Description: Project documentation for setup, deployment, and operational guidance.
Inside functions: N/A - documentation content.
Developer : Qin Yue @ 2026
Organization : OptiHK Limited
-->
# mxPIC EDA Intranet Deployment
## Build-Time Router Stack
The Flask server can launch for login, dashboard, canvas editing, YAML
generation, and PDK browsing without importing `mxpic_router` or `mxpic_forge`.
Build actions require `mxpic_router` and Nazca. When `mxpic_forge.Route` is not
available, routing falls back to Nazca `interconnects.Interconnect`; SVG preview
generation also requires `gdstk`.
## Start on the office LAN
1. On the host computer, open PowerShell in this repository.
2. Set a persistent secret key:
```powershell
$env:MXPIC_SECRET_KEY = "replace-with-a-long-random-secret"
```
3. Start the server:
```powershell
.\run_intranet_server.ps1
```
The app listens on `0.0.0.0:3000`, so other users can open:
```text
http://<host-computer-ip>:3000
```
Find the host IP with:
```powershell
ipconfig
```
Use the IPv4 address on the company LAN adapter.
## Windows firewall
If coworkers cannot connect, allow inbound TCP port `3000` on the host computer.
## Accounts
Default local accounts:
```text
admin / 123456
engineer / 123456
```
Change these passwords from the dashboard profile panel before regular use.
Each user stores projects under:
```text
database/<username>/layout
```
## Useful environment variables
```text
MXPIC_HOST=0.0.0.0
MXPIC_PORT=3000
MXPIC_DEBUG=0
MXPIC_SECRET_KEY=<long random string>
MXPIC_COOKIE_SECURE=0
MXPIC_PDK_PUBLIC_ROOT=<path-to-public-foundries>
MXPIC_PDK_ATLAS_ROOT=<path-to-atlas-foundries>
```
Set `MXPIC_COOKIE_SECURE=1` only when serving through HTTPS.
PDK component metadata, GDS assets, and `technology.yml` manifests are all read
from these role-scoped roots. If the variables are not set, the backend defaults
to `../opt_pdk_public/foundries` for normal users/developers and
`../opt_pdk_atlas/foundries` for managers.
-581
View File
@@ -1,581 +0,0 @@
# PDK, Technology, and Xsection Loading Logic Path
This document explains how the current code loads:
- PDK component information: component folders, component YAML, images, and GDS assets.
- Technology information: selected foundry/technology for each project.
- Xsection information: routing cross-section defaults and Nazca layer bindings from `technology.yml`.
Line numbers refer to the current codebase at the time this document was written.
## Mental Model
There are three related but separate data paths.
1. Component PDK assets
- Source: role-controlled PDK trees:
- `opt_pdk_public/foundries`
- `opt_pdk_atlas/foundries`
- Controlled by user group through `pdk_root_for_session`
(`backend/pdk_access.py` line 43).
- Used for library browsing, component metadata, component images, and final
component GDS resolution.
2. Technology registry and manifests
- Source: the same role-controlled PDK trees as component assets.
- Path: `<active_role_pdk_root>/<foundry>/<technology>/technology.yml`.
- Used to list available technologies, save the project technology choice,
load route defaults, and register Nazca layers/xsections.
3. Saved project layout YAML
- Source: `database/<username>/layout/<project>/<cell>.yml`.
- Contains placed component paths and `bundles.*.links[*].xsection`.
- Consumed by `mxpic_router` when building SVG preview GDS or downloadable GDS.
Important distinction:
- The active role PDK root is now the single source of truth.
- Normal/developer users read from `opt_pdk_public/foundries`.
- Manager users read from `opt_pdk_atlas/foundries`.
- The selected project technology scopes the library browser and selects which
`technology.yml` is loaded from that same role root.
## Active Roots
Backend startup defines the important paths:
- `REPO_ROOT` (`backend/server.py` line 36) points two levels above
`backend/`.
- There is no separate technology-manifest copy inside `mxpic_EDA`.
Role-based PDK root:
`Flask session user_group` -> `current_pdk_root`
(`backend/server.py` line 196) -> `pdk_root_for_session`
(`backend/pdk_access.py` line 43) -> `pdk_root_for_group`
(`backend/pdk_access.py` line 27) : choose:
- manager -> `MXPIC_PDK_ATLAS_ROOT` or `../opt_pdk_atlas/foundries`.
- developers/user -> `MXPIC_PDK_PUBLIC_ROOT` or `../opt_pdk_public/foundries`.
## Technology Selection Path
Compact path:
`Dashboard opens` -> `loadTechnologies` (`frontend/dashboard.html` line 1238)
-> GET `/api/technologies` -> `list_technologies`
(`backend/server.py` line 441) : scan `current_pdk_root()` ->
return `{ foundry, technology, id, label }` -> dashboard fills the technology
select.
Detailed path:
1. The dashboard calls `/api/technologies`:
- `loadTechnologies` starts at `frontend/dashboard.html` line 1238.
- It stores `data.technologies` and creates `<option>` values using
`tech.id`, for example `Silterra/EMO1_2ML_CU_Al_RDL`.
2. The backend scans the technology registry:
- Route: `/api/technologies` (`backend/server.py` line 439).
- Function: `list_technologies` (`backend/server.py` line 441).
- It scans `current_pdk_root()`.
- A technology directory is exposed only when it contains `technology.yml`.
- For each valid directory pair it returns:
- `foundry`
- `technology`
- `id: foundry/technology`
- `label: foundry / technology`
3. Creating a project stores the selected technology:
- Dashboard create click posts to `/api/projects`
(`frontend/dashboard.html` line 1303).
- Body contains `{ name, technology }`.
- Backend route: `/api/projects` (`backend/server.py` line 603).
- Function: `create_project` (`backend/server.py` line 605).
- It writes `.project.json` with:
- `name`
- `technology`
- Metadata helper path: `project_meta_path`
(`backend/server.py` line 228).
- Metadata writer: `write_project_meta`
(`backend/server.py` line 242).
Saved metadata location:
`database/<username>/layout/<project>/.project.json`
Example:
```json
{
"name": "mxpic_project_1",
"technology": "Silterra/EMO1_2ML_CU_Al_RDL"
}
```
## Technology Manifest Loading Path
Compact path:
`Canvas opens project` -> `loadProject` (`frontend/canvas.html` line 5030)
-> GET `/api/projects/<project>` -> `get_project`
(`backend/server.py` line 632) : returns saved `technology` -> frontend
`loadTechnologyManifest` (`frontend/canvas.html` line 4056) -> GET
`/api/technologies/<foundry>/<technology>/manifest` -> `read_technology_manifest`
(`backend/technology_manifest.py` line 27) -> return full `technology.yml`
manifest.
Detailed path:
1. Canvas loads project metadata:
- `loadProject` fetches `/api/projects/<project>`
(`frontend/canvas.html` line 5033).
- Backend `get_project` returns:
- project name
- saved cells
- `technology: read_project_meta(project_name).get("technology")`
(`backend/server.py` line 653).
2. Canvas loads the selected technology manifest:
- `loadTechnologyManifest` starts at `frontend/canvas.html` line 4056.
- It expects technology IDs in `foundry/technology` format.
- It fetches:
`/api/technologies/<foundry>/<technology>/manifest`.
- If missing or invalid, it logs an error and uses
`FALLBACK_TECHNOLOGY_MANIFEST`.
3. Backend validates and returns the manifest:
- Route:
`/api/technologies/<foundry>/<technology>/manifest`
(`backend/server.py` line 465).
- Function: `get_technology_manifest`
(`backend/server.py` line 467).
- It calls `read_technology_manifest`
(`backend/technology_manifest.py` line 27).
- The expected path is built by `technology_manifest_path`
(`backend/technology_manifest.py` line 16):
```text
<active_role_pdk_root>/<foundry>/<technology>/technology.yml
```
4. Backend manifest validation:
- `technology.yml` must exist.
- `manifest.xsections` must be a dictionary.
- `manifest.defaults` must be a dictionary.
- Otherwise the API returns 404 with a `TechnologyManifestError`.
## Current `technology.yml` Structure
Active example:
`opt_pdk_public/foundries/Silterra/EMO1_2ML_CU_Al_RDL/technology.yml`
For manager sessions, the equivalent file is read from
`opt_pdk_atlas/foundries`.
Important sections:
- `schema_version` (`technology.yml` line 7).
- `foundry` (`technology.yml` line 8).
- `technology` (`technology.yml` line 9).
- `layers` (`technology.yml` line 18).
- `routing_types` (`technology.yml` line 41).
- `defaults` (`technology.yml` line 44).
- `xsections` (`technology.yml` line 50).
Current xsections:
- `strip` (`technology.yml` line 51).
- `rib_low` (`technology.yml` line 58).
- `metal_1` (`technology.yml` line 67).
- `metal_2` (`technology.yml` line 74).
Meaning of the main fields:
- `layers`: maps technology layer names to GDS layer/datatype pairs.
- `routing_types`: choices shown by the route editor.
- `defaults`: default route `xsection`, `family`, `width`, `radius`, and
`routing_type`.
- `xsections`: per-cross-section defaults and layer bindings.
- `constants` and `source_class`: currently kept as manifest metadata. The
active frontend and router code do not consume them directly.
## Frontend Xsection Usage
Compact path:
`technology.yml xsections` -> backend manifest API -> `technologyManifest`
state (`frontend/canvas.html` line 3756) -> route editor dropdown and route
defaults -> saved YAML `bundles.output_bus.links[*].xsection`.
Detailed path:
1. Fallback manifest:
- `FALLBACK_TECHNOLOGY_MANIFEST` is defined in
`frontend/canvas-helpers.js` line 105.
- It includes fallback `strip`, `rib_low`, `metal_1`, and `metal_2`
xsections.
2. Canvas state:
- `projectTechnology` state is declared at `frontend/canvas.html` line 3755.
- `technologyManifest` state is declared at `frontend/canvas.html` line 3756.
3. Route defaults:
- `getXsectionInfo` (`frontend/canvas-helpers.js` line 132) looks up
`manifest.xsections[xsection]`.
- `createRouteSettings` (`frontend/canvas-helpers.js` line 138) merges:
- manifest defaults
- selected xsection defaults
- user overrides saved on the edge
- Resulting route state always has:
- `xsection`
- `family`
- `width`
- `radius`
- `routing_type`
4. Changing xsection in the route editor:
- Right panel builds available xsections from
`Object.keys(technologyManifest.xsections)`
(`frontend/canvas.html` line 2999).
- The xsection select calls `updateRouteXsection`
(`frontend/canvas.html` line 3037).
- `updateRouteXsection` refreshes family, default width, and default radius
(`frontend/canvas-helpers.js` line 167).
5. Link toolbar choices:
- `linkXsectionChoices` is built from `technologyManifest.xsections`
(`frontend/canvas.html` line 3775).
- It prefers the order `strip`, `rib_low`, `metal_1`, `metal_2`, then any
extra xsections.
## Component PDK Library Loading Path
Compact path:
`Canvas needs library` -> `fetchLibrary` (`frontend/canvas.html` line 4576)
-> GET `/api/library?project=<project>` -> `pdk_root_for_request_project`
(`backend/server.py` line 222) -> `scoped_pdk_root_for_project`
(`backend/server.py` line 201) -> `findComps`
(`backend/server.py` line 262) -> frontend library tree.
Detailed path:
1. Frontend requests the library:
- `fetchLibrary` calls `/api/library?project=<currentProjectName>`
(`frontend/canvas.html` line 4576).
2. Backend chooses the PDK root for this request:
- Route: `/api/library` (`backend/server.py` line 854).
- Function: `getLib` uses `pdk_root_for_request_project`.
- `pdk_root_for_request_project` starts at `backend/server.py` line 222.
- If a project is supplied, it calls `scoped_pdk_root_for_project`.
- Otherwise it uses `current_pdk_root`.
3. Project scoping:
- `scoped_pdk_root_for_project` starts at `backend/server.py` line 201.
- It reads the project `.project.json` technology field.
- It splits the value into `foundry/technology`.
- It scopes the role root to:
```text
<active_role_pdk_root>/<foundry>/<technology>
```
- It only returns that scoped path if it exists and stays under the active
role root.
- If not valid, it falls back to the active role root.
4. Component scanning:
- `findComps` starts at `backend/server.py` line 262.
- It walks the chosen PDK directory.
- Any folder containing a `.yml` file is treated as one component leaf.
- It stores component metadata:
- folder path
- first component YAML filename
- category
- relative component path
- `addCompsToTree` (`backend/server.py` line 290) converts this flat map
into the nested library tree returned to the canvas.
Important detail:
`getLib` scans the project-scoped directory but calls:
```python
findComps(comps_root, current_pdk_root())
```
This means the visible library is limited to the selected project technology,
but each component `__path__` is stored relative to the base role PDK root, not
relative to the scoped technology directory.
For example, if the active role PDK root is:
```text
opt_pdk_public/foundries
```
and the project technology is:
```text
Silterra/EMO1_2ML_CU_Al_RDL
```
a component path saved into layout YAML can include:
```text
Silterra/EMO1_2ML_CU_Al_RDL/<category>/<component>/<component>
```
This is important because build and preview pass the base role PDK root into
`mxpic_router`, and the saved component path can still resolve under that base
root.
## Component Metadata and Image Loading
Component YAML path:
`Canvas load/drop component` -> `loadComponentMetadata`
(`frontend/canvas.html` line 4082) -> GET
`/api/component/<component_name>?project=<project>` -> `readCompYaml`
(`backend/server.py` line 345) -> return component YAML.
Details:
- Route: `/api/component/<component_name>` (`backend/server.py` line 869).
- The backend uses the same project-scoped PDK root logic as `/api/library`.
- `readCompYaml` walks the selected PDK root and matches the component folder
basename.
- If the PDK root is under `opt_pdk_public` or `opt_pdk_atlas`, legacy
component metadata with `ports` is normalized to `pins`.
Component image path:
`Canvas thumbnail` -> `/api/component/<component_name>/image?project=<project>`
-> `find_component_dir` (`backend/server.py` line 367) -> first
`.png`, `.jpg`, `.jpeg`, or `.svg` in the component folder.
Route:
- `/api/component/<component_name>/image` (`backend/server.py` line 878).
## Saved YAML: How PDK Paths and Xsections Are Written
Compact path:
`Build Layout` or `Save` -> `buildYamlForPage`
(`frontend/canvas.html` line 6141) -> `findComponentPath`
(`frontend/canvas.html` line 3659) -> `buildInstancesYaml`
(`frontend/canvas-helpers.js` line 665) -> saved `instances.*.component`.
Component path details:
- `findComponentPath` searches the loaded library tree.
- If a component node has `__path__`, that path is used.
- `buildInstanceYaml` (`frontend/canvas-helpers.js` line 643) writes:
```yaml
instances:
<instance_name>:
component: <component path from library>
```
- Forge and basic components are special:
- Forge components save the forge component type.
- Basic components save names such as `waveguide`, `90 bend`, or `taper`.
- Normal PDK components save the PDK library path.
Xsection path details:
`Canvas edges` -> `buildBundlesYaml` (`frontend/canvas-helpers.js` line 988)
-> `createRouteSettings` (`frontend/canvas-helpers.js` line 138) -> saved
bundle links:
```yaml
bundles:
output_bus:
routing_type: euler_bend
links:
- from: <instance>:<pin>
to: <instance>:<pin>
xsection: strip
family: optical
width: 0.45
radius: 10
routing_type: euler_bend
```
The saved `xsection` field is the bridge from frontend route editing into
`mxpic_router` and Nazca.
## Build-Time Technology and PDK Loading
Both SVG preview and final GDS now use the router-backed path.
### SVG Preview
Compact path:
`POST /api/save-layout` -> `save_layout` (`backend/server.py` line 715)
-> `create_routed_layout_svg` (`backend/routed_layout_preview.py` line 14)
-> `mxpic_router.build_project_gds` -> temporary GDS -> `gdstk.write_svg`.
Arguments passed from `save_layout`:
- `pdk_root=current_pdk_root()` (`backend/server.py` line 737).
- `technology_manifest_path=technology_manifest_path_for_project(project)`
(`backend/server.py` line 739).
- `prefer_full_gds=prefer_full_gds_for_session(session)`
(`backend/server.py` line 740).
The preview helper:
- Imports `mxpic_router.build_project_gds`
(`backend/routed_layout_preview.py` line 32).
- Builds a temporary GDS with the same PDK root and technology manifest path
(`backend/routed_layout_preview.py` lines 39-45).
- Reads that GDS with `gdstk`.
- Writes the SVG preview (`backend/routed_layout_preview.py` line 51).
### Final GDS
Compact path:
`POST /api/build-gds` -> `build_gds` (`backend/server.py` line 775)
-> `backend.gds_builder.build_project_gds` (`backend/gds_builder.py` line 26)
-> `_build_with_mxpic_router` (`backend/gds_builder.py` line 47)
-> `mxpic_router.build_project_gds`.
Arguments passed from `build_gds`:
- `current_pdk_root()` (`backend/server.py` line 789).
- `technology_manifest_path=technology_manifest_path_for_project(project)`
(`backend/server.py` line 790).
- `prefer_full_gds=prefer_full_gds_for_session(session)`
(`backend/server.py` line 791).
`technology_manifest_path_for_project`:
- Starts at `backend/server.py` line 183.
- Reads the project technology from `.project.json`.
- Builds:
```text
<active_role_pdk_root>/<foundry>/<technology>/technology.yml
```
- Returns the path only if it exists and stays under `current_pdk_root()`.
## Inside `mxpic_router`
Compact path:
`mxpic_router.build_project_gds` (`../mxpic_router/mxpic_router/builder.py`
line 12) -> `load_technology_manifest`
(`../mxpic_router/mxpic_router/technology.py` line 6) ->
`apply_technology_manifest` (`../mxpic_router/mxpic_router/technology.py`
line 13) -> Nazca `nd.add_layer`, `nd.add_xsection`,
`nd.add_layer2xsection`.
Detailed path:
1. Build starts:
- `build_project_gds` starts at
`../mxpic_router/mxpic_router/builder.py` line 12.
- It imports Nazca as `nd`.
- It loads the manifest from `technology_manifest_path`
(`../mxpic_router/mxpic_router/builder.py` line 23).
- It applies the manifest to Nazca
(`../mxpic_router/mxpic_router/builder.py` line 24).
2. Technology manifest to Nazca:
- `load_technology_manifest` returns `{}` if the path is missing
(`../mxpic_router/mxpic_router/technology.py` line 6).
- `apply_technology_manifest` does nothing for an empty manifest.
- For each `manifest.layers` entry it calls:
```python
nd.add_layer(name=name, layer=(layer, datatype), overwrite=True)
```
- For each `manifest.xsections` entry it calls:
```python
nd.add_xsection(name=xsection)
nd.add_layer2xsection(...)
```
- Supported layer binding keys are:
- `growx`
- `growy`
- `leftedge`
- `rightedge`
3. Project YAML parsing:
- `_load_project_specs` reads saved `.yml` / `.yaml` files
(`../mxpic_router/mxpic_router/builder.py` line 46).
- `load_cell_spec` reads YAML
(`../mxpic_router/mxpic_router/eda_loader.py` line 80).
- `parse_cell_dict` converts dictionaries into `CellSpec`
(`../mxpic_router/mxpic_router/eda_loader.py` line 85).
4. Link xsections:
- `LinkSpec.xsection` defaults to `strip`
(`../mxpic_router/mxpic_router/eda_loader.py` line 51).
- `BundleSpec.xsection` defaults to `strip`
(`../mxpic_router/mxpic_router/eda_loader.py` line 66).
- Bundle-level `xsection` is read at
`../mxpic_router/mxpic_router/eda_loader.py` line 137.
- Link-level `xsection` overrides bundle-level xsection at
`../mxpic_router/mxpic_router/eda_loader.py` line 142.
- If `family` is missing, `_family_from_xsection` maps metal-like xsections
to `electrical`, otherwise `optical`
(`../mxpic_router/mxpic_router/eda_loader.py` line 171).
5. PDK asset resolution:
- `_resolve_pdk_asset` starts at
`../mxpic_router/mxpic_router/builder.py` line 509.
- It first tries the saved component path directly under `pdk_root`.
- If no direct directory exists, it scans the whole PDK root by component
folder basename.
- It reads the component YAML if present.
- It chooses GDS through `_find_gds`
(`../mxpic_router/mxpic_router/builder.py` line 533).
- Normal users prefer `<component>_BB.gds`; manager sessions can prefer
`<component>.gds`.
6. Route generation:
- `_route_link` starts at
`../mxpic_router/mxpic_router/builder.py` line 269.
- It creates the route object with:
```python
Route(radius=link.radius or 10, width=link.width, xs=link.xsection, PCB=...)
```
- Optical and electrical routes both use `link.xsection`; metal routes also
enable PCB-style routing for `metal_1` and `metal_2`.
- Nazca can generate geometry on the correct layers because
`apply_technology_manifest` already registered the xsection layer bindings.
## Current Fallbacks and Observations
- If a project has no saved technology, the frontend uses
`FALLBACK_TECHNOLOGY_MANIFEST`.
- If `/api/technologies/<foundry>/<technology>/manifest` fails, the frontend
also uses `FALLBACK_TECHNOLOGY_MANIFEST`.
- If build-time `technology_manifest_path_for_project` cannot find
`technology.yml`, `mxpic_router` receives no manifest path and Nazca
registration is skipped.
- The library browser is project-scoped by selected technology, but preview and
GDS build pass the base role PDK root to `mxpic_router`.
- This works because normal saved component paths include
`foundry/technology/...` relative to the base role PDK root.
- Manually edited YAML with only a component folder name can still resolve, but
the router will scan the whole active PDK root and use the first matching
folder basename.
- The legacy local GDS/SVG preview builder and local PDK GDS registry have been
removed from `mxpic_EDA`; active build and preview actions call the
router-backed API wrappers instead.
+22
View File
@@ -23,3 +23,25 @@ PDK component assets and `technology.yml` manifests are loaded from the same
role-scoped PDK roots. Normal users and developers use
`MXPIC_PDK_PUBLIC_ROOT` or `../opt_pdk_public/foundries`; managers use
`MXPIC_PDK_ATLAS_ROOT` or `../opt_pdk_atlas/foundries`.
## Runtime Database Root
Runtime data is not stored inside this repository. Move the existing `database`
folder beside `mxpic_EDA` and rename it:
```text
mxpic_EDA_database
```
Default runtime data path:
```text
../mxpic_EDA_database
```
The app fails fast if this folder is missing so debugging cannot silently create
or modify tracked database files. For nonstandard deployments, set:
```text
MXPIC_DATABASE_ROOT=<path-to-mxpic_EDA_database>
```
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -3
View File
@@ -10,9 +10,7 @@ import os
from werkzeug.security import generate_password_hash
from datetime import datetime
# Store application data in the shared database folder so all backend modules
# use the same SQLite file regardless of their import path.
DB_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "database", "mxpic_data.db"))
from storage_paths import DB_FILE
def connect_db():
"""Open a SQLite connection with row-style access for application data queries."""
+21 -22
View File
@@ -4,12 +4,11 @@
# Developer : Qin Yue @ 2026
# Organization : OptiHK Limited
# -----------------------------------------------------------------------------
import os
import tempfile
from dataclasses import dataclass, field
from typing import Dict, List
import yaml
from typing import List
from layout_files import load_layout_cell_files, write_layout_cells_to_directory
from router_dependency import require_router_stack
@@ -31,16 +30,25 @@ def build_project_gds(
prefer_full_gds: bool = False,
) -> BuildResult:
"""Build a hierarchical project GDS from saved cell YAML files with mxpic_router."""
cells = _load_project_cells(project_dir)
cells, warnings = _load_project_cells(project_dir)
if not cells:
raise ValueError("No saved cell YAML files found for this project")
return _build_with_mxpic_router(
project_dir,
output_path,
pdk_public_root,
technology_manifest_path,
prefer_full_gds,
with tempfile.TemporaryDirectory(prefix="mxpic_gds_project_") as staged_project_dir:
write_layout_cells_to_directory(cells, staged_project_dir)
result = _build_with_mxpic_router(
staged_project_dir,
output_path,
pdk_public_root,
technology_manifest_path,
prefer_full_gds,
)
return BuildResult(
output_path=result.output_path,
engine=result.engine,
cells_built=result.cells_built,
warnings=warnings + result.warnings,
)
@@ -70,15 +78,6 @@ def _build_with_mxpic_router(
)
def _load_project_cells(project_dir: str) -> Dict[str, dict]:
def _load_project_cells(project_dir: str):
"""Load saved cell YAML documents from a project directory."""
cells = {}
for filename in sorted(os.listdir(project_dir)):
if not filename.lower().endswith((".yml", ".yaml")):
continue
path = os.path.join(project_dir, filename)
with open(path, "r", encoding="utf-8") as file:
data = yaml.safe_load(file) or {}
cell_name = str(data.get("name") or os.path.splitext(filename)[0])
cells[cell_name] = data
return cells
return load_layout_cell_files(project_dir)
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

+126
View File
@@ -0,0 +1,126 @@
# -----------------------------------------------------------------------------
# Description: Layout YAML file filtering, parsing, and staging helpers.
# Inside functions: is_layout_cell_filename, parse_layout_cell_content, read_layout_cell_file, load_layout_cell_files, layout_cell_filename, write_layout_cells_to_directory
# Developer : Qin Yue @ 2026
# Organization : OptiHK Limited
# -----------------------------------------------------------------------------
import os
import re
import yaml
LAYOUT_YAML_EXTENSIONS = (".yml", ".yaml")
ROUTE_SIDECAR_SUFFIXES = (".routes.yml", ".routes.yaml")
class LayoutFileError(ValueError):
"""Raised when a saved layout YAML file cannot be used as a cell."""
def is_layout_cell_filename(filename):
"""Return True for user layout cell YAML files, excluding sidecars/manifests."""
lower = (filename or "").lower()
if lower == "technology.yml":
return False
if lower.endswith(ROUTE_SIDECAR_SUFFIXES):
return False
return lower.endswith(LAYOUT_YAML_EXTENSIONS)
def is_layout_cell_document(data):
"""Return True when parsed YAML looks like an mxPIC saved cell/project."""
if not isinstance(data, dict):
return False
kind = data.get("kind")
if kind and str(kind).strip().lower() != "cell":
return False
layout_keys = {
"schema_version",
"canvas_size",
"canvasSize",
"instances",
"elements",
"pins",
"ports",
"bundles",
}
return any(key in data for key in layout_keys)
def parse_layout_cell_content(content, source="layout YAML"):
"""Parse and validate saved layout YAML content."""
try:
data = yaml.safe_load(content or "") or {}
except yaml.YAMLError as exc:
raise LayoutFileError(f"{source} is not valid YAML: {exc}") from exc
if not is_layout_cell_document(data):
raise LayoutFileError(f"{source} is not a saved mxPIC layout cell")
return data
def read_layout_cell_file(path):
"""Read a saved layout cell file and return parsed data plus raw content."""
try:
with open(path, "r", encoding="utf-8") as file:
content = file.read()
except OSError as exc:
raise LayoutFileError(f"{os.path.basename(path)} could not be read: {exc}") from exc
return parse_layout_cell_content(content, os.path.basename(path)), content
def load_layout_cell_files(project_dir):
"""Load valid layout cell files from a project directory and collect warnings."""
cells = []
warnings = []
if not os.path.isdir(project_dir):
return cells, warnings
for filename in sorted(os.listdir(project_dir)):
if not is_layout_cell_filename(filename):
continue
path = os.path.join(project_dir, filename)
if not os.path.isfile(path):
continue
try:
data, content = read_layout_cell_file(path)
except LayoutFileError as exc:
warnings.append(f"Skipped {filename}: {exc}")
continue
cells.append({
"filename": filename,
"name": str(data.get("name") or os.path.splitext(filename)[0]),
"data": data,
"content": content,
})
return cells, warnings
def layout_cell_filename(cell_name, fallback="canvas_1.yml"):
"""Build a safe filename for staging a parsed layout cell."""
name = re.sub(r"[^A-Za-z0-9_.-]+", "_", str(cell_name or "")).strip("._")
if not name:
return fallback
return f"{name}.yml"
def write_layout_cells_to_directory(cells, output_dir):
"""Write valid layout cell contents into a clean staging directory."""
os.makedirs(output_dir, exist_ok=True)
used_names = set()
for index, cell in enumerate(cells, start=1):
filename = layout_cell_filename(cell.get("name"), cell.get("filename") or f"cell_{index}.yml")
base, ext = os.path.splitext(filename)
unique_filename = filename
counter = 1
while unique_filename.lower() in used_names:
counter += 1
unique_filename = f"{base}_{counter}{ext}"
used_names.add(unique_filename.lower())
with open(os.path.join(output_dir, unique_filename), "w", encoding="utf-8") as file:
file.write(cell["content"])
Binary file not shown.
+13 -1
View File
@@ -9,6 +9,7 @@ import tempfile
import yaml
from layout_files import load_layout_cell_files, write_layout_cells_to_directory
from router_dependency import require_router_stack
@@ -32,9 +33,20 @@ def create_routed_layout_svg(
# Build into a temporary GDS first, then convert the generated top cell into
# the SVG preview consumed by the canvas.
with tempfile.TemporaryDirectory(prefix="mxpic_routed_preview_") as temp_dir:
staged_project_dir = os.path.join(temp_dir, "project")
saved_cells, _warnings = load_layout_cell_files(project_dir)
staged_cells = [cell for cell in saved_cells if cell["name"] != cell_name]
staged_cells.append({
"filename": f"{cell_name}.yml",
"name": cell_name,
"data": layout,
"content": yaml_content,
})
write_layout_cells_to_directory(staged_cells, staged_project_dir)
temp_gds = os.path.join(temp_dir, f"{cell_name}.gds")
build_project_gds(
project_dir=project_dir,
project_dir=staged_project_dir,
output_path=temp_gds,
pdk_root=pdk_root,
technology_manifest_path=technology_manifest_path,
+49 -33
View File
@@ -18,6 +18,13 @@ from werkzeug.security import check_password_hash
import database
from flask import Response
from gds_builder import build_project_gds
from layout_files import (
LayoutFileError,
is_layout_cell_filename,
load_layout_cell_files,
parse_layout_cell_content,
read_layout_cell_file,
)
from pdk_access import (
cleanup_expired_exports,
create_export_path,
@@ -26,6 +33,7 @@ from pdk_access import (
)
from router_dependency import RouterStackUnavailable
from routed_layout_preview import create_routed_layout_svg
from storage_paths import DATABASE_ROOT, EXPORT_ROOT
from technology_manifest import TechnologyManifestError, read_technology_manifest
# --- Path Configurations ---
@@ -38,11 +46,6 @@ 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')
# Saved project YAML, generated previews, and temporary exports live under the
# database folder so each user can have isolated project storage.
DATABASE_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', 'database'))
EXPORT_ROOT = os.path.abspath(os.path.join(DATABASE_ROOT, '_exports'))
# Flask serves the HTML/CSS/JS frontend and exposes JSON APIs for persistence,
# PDK lookup, preview generation, and GDS export.
@@ -149,13 +152,17 @@ def cell_routes_path(project_name, cell_name):
def write_route_points_sidecar(yaml_content, output_path):
"""Extract route points from layout YAML and save them beside the cell."""
layout = yaml.safe_load(yaml_content) or {}
layout = yaml_content if isinstance(yaml_content, dict) else parse_layout_cell_content(yaml_content)
routes = {}
# The sidecar preserves manually edited route control points separately from
# the main YAML file for tooling that wants route-only metadata.
for bundle_name, bundle in (layout.get("bundles") or {}).items():
if not isinstance(bundle, dict):
continue
saved_links = []
for link in bundle.get("links") or []:
if not isinstance(link, dict):
continue
points = link.get("points") or []
if not points:
continue
@@ -586,27 +593,29 @@ def user_logs():
@app.route('/api/projects', methods=['GET'])
@login_required_json
def list_projects():
"""List projects stored under database/<username>/layout."""
"""List projects stored under the external runtime database root."""
root = user_layout_root()
os.makedirs(root, exist_ok=True)
projects = []
# Each project is a folder and each YAML file inside that folder is treated
# as one saved cell/canvas.
# Each project is a folder and each valid layout YAML file inside that
# folder is treated as one saved cell/canvas. Route sidecars and malformed
# files are ignored so reopen stays resilient to stale runtime artifacts.
for name in sorted(os.listdir(root)):
path = os.path.join(root, name)
if not os.path.isdir(path):
continue
cells = []
for filename in sorted(os.listdir(path)):
if not filename.lower().endswith(('.yml', '.yaml')):
if not is_layout_cell_filename(filename):
continue
cell_name = os.path.splitext(filename)[0]
yml_path = os.path.join(path, filename)
cells.append({
"name": cell_name,
"has_layout": os.path.exists(yml_path)
})
try:
read_layout_cell_file(yml_path)
except LayoutFileError:
continue
cells.append({"name": cell_name, "has_layout": True})
meta = read_project_meta(name)
projects.append({
"name": name,
@@ -652,31 +661,27 @@ def get_project(project_name):
if not os.path.isdir(root):
return jsonify({"error": "Project not found"}), 404
cells = []
for filename in sorted(os.listdir(root)):
if not filename.lower().endswith(('.yml', '.yaml')):
continue
cell_name = os.path.splitext(filename)[0]
yml_path = os.path.join(root, filename)
if not os.path.exists(yml_path):
continue
with open(yml_path, 'r', encoding='utf-8') as f:
cells.append({
"name": cell_name,
"content": f.read()
})
loaded_cells, warnings = load_layout_cell_files(root)
cells = [
{
"name": os.path.splitext(cell["filename"])[0],
"content": cell["content"]
}
for cell in loaded_cells
]
return jsonify({
"name": safe_name(project_name, 'project_1'),
"cells": cells,
"technology": read_project_meta(project_name).get("technology")
"technology": read_project_meta(project_name).get("technology"),
"warnings": warnings
})
@app.route('/api/projects/<project_name>', methods=['DELETE'])
@login_required_json
def delete_project(project_name):
"""Delete a user's project folder under database/<username>/layout."""
"""Delete a user's project folder under the external runtime database root."""
root = project_root(project_name)
layout_root = os.path.abspath(user_layout_root())
target = os.path.abspath(root)
@@ -732,18 +737,19 @@ def rename_cell(project_name, cell_name):
def save_layout():
"""Persist a canvas layout YAML document and refresh its preview assets."""
try:
data = request.get_json()
data = request.get_json(silent=True) or {}
project = safe_name(data.get('project'), 'project_1')
cell = safe_name(data.get('cell'), 'canvas_1')
content = data.get('content', '')
create_preview = bool(data.get('preview', True))
layout_doc = parse_layout_cell_content(content, f"{project}/{cell}.yml")
save_path = cell_file_path(project, cell)
os.makedirs(os.path.dirname(save_path), exist_ok=True)
with open(save_path, 'w', encoding='utf-8') as f:
f.write(content)
write_route_points_sidecar(content, cell_routes_path(project, cell))
write_route_points_sidecar(layout_doc, cell_routes_path(project, cell))
svg_path = None
svg_version = None
@@ -786,6 +792,8 @@ def save_layout():
"preview_error": preview_error
}), 200
except LayoutFileError as e:
return jsonify({"error": str(e)}), 400
except Exception as e:
return jsonify({"error": str(e)}), 500
@@ -905,10 +913,18 @@ def getLib():
@app.route('/api/component/<component_name>')
@login_required_json
def getComp(component_name):
"""Return component YAML data."""
data = readCompYaml(component_name, pdk_root_for_request_project())
"""Return component YAML data with injected category."""
comps_root = pdk_root_for_request_project()
data = readCompYaml(component_name, comps_root)
if data is None:
return jsonify({"error": "Component not found"}), 404
# Derive the category (parent folder name) for icon resolution on the canvas.
if isinstance(data, dict) and '__category__' not in data:
search_root = comps_root or current_pdk_root()
for root, dirs, files in os.walk(search_root):
if os.path.basename(root) == component_name:
data['__category__'] = os.path.basename(os.path.dirname(root))
break
return jsonify(data)
@app.route('/api/component/<component_name>/image')
+49
View File
@@ -0,0 +1,49 @@
# -----------------------------------------------------------------------------
# Description: Runtime storage path resolution for SQLite data, saved layouts, and temporary exports.
# Inside functions: resolve_database_root
# Developer : Qin Yue @ 2026
# Organization : OptiHK Limited
# -----------------------------------------------------------------------------
import os
BACKEND_DIR = os.path.dirname(os.path.abspath(__file__))
REPO_ROOT = os.path.abspath(os.path.join(BACKEND_DIR, ".."))
DEFAULT_DATABASE_ROOT = os.path.abspath(os.path.join(REPO_ROOT, "..", "mxpic_EDA_database"))
def _is_inside_repo(path: str) -> bool:
"""Return True when a candidate runtime data folder lives inside this repo."""
repo_root = os.path.normcase(REPO_ROOT)
candidate = os.path.normcase(os.path.abspath(path))
try:
return os.path.commonpath([repo_root, candidate]) == repo_root
except ValueError:
return False
def resolve_database_root() -> str:
"""Resolve and validate the external runtime database root."""
configured_root = os.environ.get("MXPIC_DATABASE_ROOT", "").strip()
database_root = os.path.abspath(configured_root or DEFAULT_DATABASE_ROOT)
if _is_inside_repo(database_root):
raise RuntimeError(
"Runtime database root must live outside the mxpic_EDA repository. "
f"Resolved path: {database_root}. Move the database beside the repo as "
"mxpic_EDA_database or set MXPIC_DATABASE_ROOT to an external path."
)
if not os.path.isdir(database_root):
raise RuntimeError(
"Runtime database root is missing. Move the existing database folder "
f"beside mxpic_EDA and rename it to mxpic_EDA_database, or set "
f"MXPIC_DATABASE_ROOT to the moved folder. Expected path: {database_root}"
)
return database_root
DATABASE_ROOT = resolve_database_root()
DB_FILE = os.path.join(DATABASE_ROOT, "mxpic_data.db")
EXPORT_ROOT = os.path.join(DATABASE_ROOT, "_exports")
@@ -1,4 +0,0 @@
{
"name": "mxpic_project_1",
"technology": "Silterra/EMO1_2ML_CU_Al_RDL"
}
File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 319 KiB

@@ -1,211 +0,0 @@
# =============================================
# mxPIC Cell/Project Definition File
# =============================================
schema_version: "2.0.0"
kind: cell
coordinate_system: gds_y_up
canvas_size:
width: 500
height: 600
project: mxpic_project_1
name: canvas_1
type: composite
version: "1.0.0"
# 1. External Ports (How this cell connects to the outside world)
pins:
- name: port_io1
layer: WG_CORE
element: port
pin: io1
x: 40.0
y: -90.0
angle: 180.0
width: 0.5
- name: port_1_io1
layer: WG_CORE
element: port_1
pin: io1
x: 410.0
y: -35.0
angle: 0.0
width: 0.5
- name: port_1_io2
layer: WG_CORE
element: port_1
pin: io2
x: 410.0
y: -25.0
angle: 0.0
width: 0.5
- name: port_2_io1
layer: WG_CORE
element: port_2
pin: io1
x: 390.0
y: -215.0
angle: 0.0
width: 0.5
- name: port_2_io2
layer: WG_CORE
element: port_2
pin: io2
x: 390.0
y: -205.0
angle: 0.0
width: 0.5
# 2. Instances (The sub-components dropped onto this canvas)
instances:
MMI_1:
component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/multimode_interferometers/1x2MMI_1310nm_TE_Silterra_202603_ZKY_v2
x: 130.0
y: -90.0
rotation: 0.0
flip: 0
flop: 0
mirror: false
settings:
length:
MMI_2:
component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/multimode_interferometers/1x2MMI_1310nm_TE_Silterra_202603_ZKY_v2
x: 280.0
y: -30.0
rotation: 0.0
flip: 0
flop: 0
mirror: false
settings:
length:
MMI_3:
component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/multimode_interferometers/1x2MMI_1310nm_TE_Silterra_202603_ZKY_v2
x: 320.1
y: -144.7
rotation: 0.0
flip: 0
flop: 0
mirror: false
settings:
length:
elements:
port:
type: port
x: 40.0
y: -90.0
angle: 180.0
pin_number: 1
pitch: 10
layer: WG_CORE
width: 0.5
description: ""
pins:
- name: port_io1
role: io1
port:
type: port
x: 40.0
y: -90.0
angle: 0.0
pin_number: 1
pitch: 10
layer: WG_CORE
width: 0.5
description: ""
pins:
- name: port_io1
role: io1
port_1:
type: port
x: 410.0
y: -30.0
angle: 180.0
pin_number: 2
pitch: 10
layer: WG_CORE
width: 0.5
description: ""
pins:
- name: port_1_io1
role: io1
- name: port_1_io2
role: io2
port_2:
type: port
x: 390.0
y: -210.0
angle: 180.0
pin_number: 2
pitch: 10
layer: WG_CORE
width: 0.5
description: ""
pins:
- name: port_2_io1
role: io1
- name: port_2_io2
role: io2
# 3. Bundles (Grouped links for multi-bus/parallel routing)
bundles:
output_bus:
routing_type: euler_bend
links:
- from: MMI_1:a1
to: port:port_io1
xsection: strip
family: optical
width: 0.45
radius: 10
routing_type: euler_bend
- from: MMI_2:a1
to: MMI_1:b1
xsection: strip
family: optical
width: 0.45
radius: 10
routing_type: euler_bend
- from: MMI_3:a1
to: MMI_1:b2
xsection: strip
family: optical
width: 0.45
radius: 10
routing_type: euler_bend
- from: MMI_2:b1
to: port_1:port_1_io1
xsection: strip
family: optical
width: 0.45
radius: 10
routing_type: euler_bend
- from: MMI_2:b1
to: port_1:port_1_io2
xsection: strip
family: optical
width: 0.45
radius: 10
routing_type: euler_bend
- from: MMI_2:b2
to: port_1:port_1_io1
xsection: strip
family: optical
width: 0.45
radius: 10
routing_type: euler_bend
- from: MMI_3:b1
to: port_2:port_2_io2
xsection: strip
family: optical
width: 0.45
radius: 10
routing_type: euler_bend
- from: MMI_3:b2
to: port_2:port_2_io1
xsection: strip
family: optical
width: 0.45
radius: 10
routing_type: euler_bend
File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 165 KiB

@@ -1,58 +0,0 @@
# =============================================
# mxPIC Cell/Project Definition File
# =============================================
schema_version: "2.0.0"
kind: cell
coordinate_system: gds_y_up
canvas_size:
width: 5000
height: 5000
project: mxpic_project_1
name: mxpic_project_1
type: project
version: "1.0.0"
# 1. External Ports (How this cell connects to the outside world)
pins:
- name: port_io1
layer: WG_CORE
element: port
pin: io1
x: 50.0
y: -150.0
angle: 180.0
width: 0.5
# 2. Instances (The sub-components dropped onto this canvas)
instances:
MZM_1:
component: Silterra/EMO1_2ML_CU_Al_RDL/composites/Mach_Zender_modulators/MZI_SiN400_Si220_PIN_mod_1310_L1300_QY_202603
x: 222.2
y: -473.8
rotation: 0.0
flip: 0
flop: 0
mirror: false
settings:
length:
elements:
port:
type: port
x: 50.0
y: -150.0
angle: 0.0
pin_number: 1
pitch: 10
layer: WG_CORE
width: 0.5
description: ""
pins:
- name: port_io1
role: io1
# 3. Bundles (Grouped links for multi-bus/parallel routing)
bundles:
output_bus:
routing_type: euler_bend
links:
@@ -1,4 +0,0 @@
{
"name": "mxpic_project_1",
"technology": "Silterra/EMO1_2ML_CU_Al_RDL"
}
File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 14 KiB

@@ -1,100 +0,0 @@
# =============================================
# mxPIC Cell/Project Definition File
# =============================================
schema_version: "2.0.0"
kind: cell
coordinate_system: gds_y_up
canvas_size:
width: 5000
height: 5000
project: mxpic_project_1
name: canvas_1
type: composite
version: "1.0.0"
# 1. External Ports (How this cell connects to the outside world)
pins:
- name: port_io1
layer: WG_CORE
element: port
pin: io1
x: 50.0
y: -150.0
angle: 180.0
width: 0.5
# 2. Instances (The sub-components dropped onto this canvas)
instances:
waveguide_1:
component: waveguide
x: 686.5
y: -1027.9
rotation: 0.0
flip: 0
flop: 0
mirror: false
settings:
length: 100
width: 0.5
xsection: "strip"
circle_1:
component: circle
x: 877.2
y: -1093.7
rotation: 0.0
flip: 0
flop: 0
mirror: false
settings:
radius: 10
width: 0.5
xsection: "strip"
waveguide_2:
component: waveguide
x: 858.0
y: -1029.6
rotation: 0.0
flip: 0
flop: 0
mirror: false
settings:
length: 100
width: 0.5
xsection: "strip"
elements:
port:
type: port
x: 50.0
y: -150.0
angle: 0.0
pin_number: 1
pitch: 10
layer: WG_CORE
width: 0.5
description: ""
pins:
- name: port_io1
role: io1
# 3. Bundles (Grouped links for multi-bus/parallel routing)
bundles:
output_bus:
routing_type: euler_bend
links:
- from: waveguide_1:b1
to: waveguide_2:a1
xsection: strip
family: optical
width: 0.5
radius: 10
routing_type: euler_bend
- from: waveguide_2:b1
to: circle_1:a1
xsection: strip
family: optical
width: 0.5
radius: 10
routing_type: euler_bend
@@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="6516.95" height="2377.45" viewBox="14124.775 14328.775 6516.95 2377.45">
<defs>
<style type="text/css">
.l1111d0 {stroke: #B3446C; fill: #B3446C; fill-opacity: 0.5;}
</style>
</defs>
<rect x="14124.775" y="14328.775" width="6516.95" height="2377.45" fill="#222222" stroke="none"/>
<g id="canvas_2" transform="scale(1 -1)">
<polygon id="00000215A6721690" class="l1111d0" points="20243,-14702.5 14421,-14702.5 14421,-14697.5 20243,-14697.5"/>
<polygon id="00000215A67222D0" class="l1111d0" points="20340.5,-14800 20345.5,-14800 20345.5,-14798.61 20345.42,-14795.84 20345.27,-14793.06 20345.05,-14790.3 20344.75,-14787.54 20344.37,-14784.79 20343.92,-14782.05 20343.4,-14779.32 20342.8,-14776.61 20342.13,-14773.92 20341.39,-14771.24 20340.57,-14768.59 20339.69,-14765.96 20338.73,-14763.35 20337.7,-14760.77 20336.61,-14758.22 20335.44,-14755.7 20334.21,-14753.22 20332.91,-14750.76 20331.54,-14748.35 20330.11,-14745.97 20328.61,-14743.63 20327.06,-14741.33 20325.44,-14739.08 20323.76,-14736.87 20322.02,-14734.7 20320.22,-14732.59 20318.37,-14730.52 20316.46,-14728.51 20314.49,-14726.54 20312.48,-14724.63 20310.41,-14722.78 20308.3,-14720.98 20306.13,-14719.24 20303.92,-14717.56 20301.67,-14715.94 20299.37,-14714.39 20297.03,-14712.89 20294.65,-14711.46 20292.24,-14710.09 20289.78,-14708.79 20287.3,-14707.56 20284.78,-14706.39 20282.23,-14705.3 20279.65,-14704.27 20277.04,-14703.31 20274.41,-14702.43 20271.76,-14701.61 20269.08,-14700.87 20266.39,-14700.2 20263.68,-14699.6 20260.95,-14699.08 20258.21,-14698.63 20255.46,-14698.25 20252.7,-14697.95 20249.94,-14697.73 20247.16,-14697.58 20244.39,-14697.5 20243,-14697.5 20243,-14702.5 20244.37,-14702.5 20247.1,-14702.58 20249.83,-14702.73 20252.56,-14702.96 20255.28,-14703.27 20257.98,-14703.65 20260.68,-14704.11 20263.36,-14704.64 20266.03,-14705.25 20268.68,-14705.94 20271.3,-14706.69 20273.91,-14707.52 20276.49,-14708.43 20279.05,-14709.4 20281.57,-14710.45 20284.07,-14711.57 20286.53,-14712.75 20288.96,-14714.01 20291.36,-14715.33 20293.71,-14716.72 20296.03,-14718.17 20298.3,-14719.69 20300.53,-14721.28 20302.72,-14722.92 20304.86,-14724.63 20306.95,-14726.39 20308.99,-14728.21 20310.97,-14730.09 20312.91,-14732.03 20314.79,-14734.01 20316.61,-14736.05 20318.37,-14738.14 20320.08,-14740.28 20321.72,-14742.47 20323.31,-14744.7 20324.83,-14746.97 20326.28,-14749.29 20327.67,-14751.64 20328.99,-14754.04 20330.25,-14756.47 20331.43,-14758.93 20332.55,-14761.43 20333.6,-14763.95 20334.57,-14766.51 20335.48,-14769.09 20336.31,-14771.7 20337.06,-14774.32 20337.75,-14776.97 20338.36,-14779.64 20338.89,-14782.32 20339.35,-14785.02 20339.73,-14787.72 20340.04,-14790.44 20340.27,-14793.17 20340.42,-14795.9 20340.5,-14798.63"/>
<polygon id="00000215A67218C0" class="l1111d0" points="20340.5,-15990 20340.5,-14800 20345.5,-14800 20345.5,-15990"/>
<polygon id="00000215A6722030" class="l1111d0" points="20243,-16087.5 20243,-16092.5 20244.39,-16092.5 20247.16,-16092.42 20249.94,-16092.27 20252.7,-16092.05 20255.46,-16091.75 20258.21,-16091.37 20260.95,-16090.92 20263.68,-16090.4 20266.39,-16089.8 20269.08,-16089.13 20271.76,-16088.39 20274.41,-16087.57 20277.04,-16086.69 20279.65,-16085.73 20282.23,-16084.7 20284.78,-16083.61 20287.3,-16082.44 20289.78,-16081.21 20292.24,-16079.91 20294.65,-16078.54 20297.03,-16077.11 20299.37,-16075.61 20301.67,-16074.06 20303.92,-16072.44 20306.13,-16070.76 20308.3,-16069.02 20310.41,-16067.22 20312.48,-16065.37 20314.49,-16063.46 20316.46,-16061.49 20318.37,-16059.48 20320.22,-16057.41 20322.02,-16055.3 20323.76,-16053.13 20325.44,-16050.92 20327.06,-16048.67 20328.61,-16046.37 20330.11,-16044.03 20331.54,-16041.65 20332.91,-16039.24 20334.21,-16036.78 20335.44,-16034.3 20336.61,-16031.78 20337.7,-16029.23 20338.73,-16026.65 20339.69,-16024.04 20340.57,-16021.41 20341.39,-16018.76 20342.13,-16016.08 20342.8,-16013.39 20343.4,-16010.68 20343.92,-16007.95 20344.37,-16005.21 20344.75,-16002.46 20345.05,-15999.7 20345.27,-15996.94 20345.42,-15994.16 20345.5,-15991.39 20345.5,-15990 20340.5,-15990 20340.5,-15991.37 20340.42,-15994.1 20340.27,-15996.83 20340.04,-15999.56 20339.73,-16002.28 20339.35,-16004.98 20338.89,-16007.68 20338.36,-16010.36 20337.75,-16013.03 20337.06,-16015.68 20336.31,-16018.3 20335.48,-16020.91 20334.57,-16023.49 20333.6,-16026.05 20332.55,-16028.57 20331.43,-16031.07 20330.25,-16033.53 20328.99,-16035.96 20327.67,-16038.36 20326.28,-16040.71 20324.83,-16043.03 20323.31,-16045.3 20321.72,-16047.53 20320.08,-16049.72 20318.37,-16051.86 20316.61,-16053.95 20314.79,-16055.99 20312.91,-16057.97 20310.97,-16059.91 20308.99,-16061.79 20306.95,-16063.61 20304.86,-16065.37 20302.72,-16067.08 20300.53,-16068.72 20298.3,-16070.31 20296.03,-16071.83 20293.71,-16073.28 20291.36,-16074.67 20288.96,-16075.99 20286.53,-16077.25 20284.07,-16078.43 20281.57,-16079.55 20279.05,-16080.6 20276.49,-16081.57 20273.91,-16082.48 20271.3,-16083.31 20268.68,-16084.06 20266.03,-16084.75 20263.36,-16085.36 20260.68,-16085.89 20257.98,-16086.35 20255.28,-16086.73 20252.56,-16087.04 20249.83,-16087.27 20247.1,-16087.42 20244.37,-16087.5"/>
<polygon id="00000215A6721A80" class="l1111d0" points="16810,-14775 14421,-14775 14421,-14625 16810,-14625"/>
<polygon id="00000215A6720F90" class="l1111d0" points="16835,-14800 16985,-14800 16985,-14798.17 16984.92,-14794.5 16984.77,-14790.84 16984.54,-14787.18 16984.23,-14783.53 16983.85,-14779.89 16983.39,-14776.25 16982.85,-14772.62 16982.24,-14769.01 16981.55,-14765.41 16980.79,-14761.82 16979.95,-14758.26 16979.04,-14754.71 16978.06,-14751.17 16977,-14747.67 16975.87,-14744.18 16974.66,-14740.72 16973.38,-14737.28 16972.03,-14733.88 16970.61,-14730.5 16969.12,-14727.15 16967.56,-14723.83 16965.93,-14720.55 16964.23,-14717.3 16962.47,-14714.09 16960.64,-14710.91 16958.74,-14707.78 16956.77,-14704.68 16954.74,-14701.63 16952.65,-14698.62 16950.5,-14695.66 16948.28,-14692.74 16946.01,-14689.86 16943.67,-14687.04 16941.27,-14684.27 16938.82,-14681.54 16936.31,-14678.87 16933.75,-14676.25 16931.13,-14673.69 16928.46,-14671.18 16925.73,-14668.73 16922.96,-14666.33 16920.14,-14663.99 16917.26,-14661.72 16914.34,-14659.5 16911.38,-14657.35 16908.37,-14655.26 16905.32,-14653.23 16902.22,-14651.26 16899.09,-14649.36 16895.91,-14647.53 16892.7,-14645.77 16889.45,-14644.07 16886.17,-14642.44 16882.85,-14640.88 16879.5,-14639.39 16876.12,-14637.97 16872.72,-14636.62 16869.28,-14635.34 16865.82,-14634.13 16862.33,-14633 16858.83,-14631.94 16855.29,-14630.96 16851.74,-14630.05 16848.18,-14629.21 16844.59,-14628.45 16840.99,-14627.76 16837.38,-14627.15 16833.75,-14626.61 16830.11,-14626.15 16826.47,-14625.77 16822.82,-14625.46 16819.16,-14625.23 16815.5,-14625.08 16811.83,-14625 16810,-14625 16810,-14775 16810.68,-14775 16812.03,-14775.08 16813.38,-14775.22 16814.71,-14775.44 16816.03,-14775.73 16817.34,-14776.1 16818.62,-14776.53 16819.88,-14777.03 16821.11,-14777.6 16822.31,-14778.23 16823.47,-14778.93 16824.59,-14779.69 16825.67,-14780.51 16826.7,-14781.39 16827.68,-14782.32 16828.61,-14783.3 16829.49,-14784.33 16830.31,-14785.41 16831.07,-14786.53 16831.77,-14787.69 16832.4,-14788.89 16832.97,-14790.12 16833.47,-14791.38 16833.9,-14792.66 16834.27,-14793.97 16834.56,-14795.29 16834.78,-14796.62 16834.92,-14797.97 16835,-14799.32"/>
<polygon id="00000215A6721930" class="l1111d0" points="16835,-16235 16835,-14800 16985,-14800 16985,-16235"/>
<polygon id="00000215A67214D0" class="l1111d0" points="16810,-16260 16810,-16410 16811.83,-16410 16815.5,-16409.92 16819.16,-16409.77 16822.82,-16409.54 16826.47,-16409.23 16830.11,-16408.85 16833.75,-16408.39 16837.38,-16407.85 16840.99,-16407.24 16844.59,-16406.55 16848.18,-16405.79 16851.74,-16404.95 16855.29,-16404.04 16858.83,-16403.06 16862.33,-16402 16865.82,-16400.87 16869.28,-16399.66 16872.72,-16398.38 16876.12,-16397.03 16879.5,-16395.61 16882.85,-16394.12 16886.17,-16392.56 16889.45,-16390.93 16892.7,-16389.23 16895.91,-16387.47 16899.09,-16385.64 16902.22,-16383.74 16905.32,-16381.77 16908.37,-16379.74 16911.38,-16377.65 16914.34,-16375.5 16917.26,-16373.28 16920.14,-16371.01 16922.96,-16368.67 16925.73,-16366.27 16928.46,-16363.82 16931.13,-16361.31 16933.75,-16358.75 16936.31,-16356.13 16938.82,-16353.46 16941.27,-16350.73 16943.67,-16347.96 16946.01,-16345.14 16948.28,-16342.26 16950.5,-16339.34 16952.65,-16336.38 16954.74,-16333.37 16956.77,-16330.32 16958.74,-16327.22 16960.64,-16324.09 16962.47,-16320.91 16964.23,-16317.7 16965.93,-16314.45 16967.56,-16311.17 16969.12,-16307.85 16970.61,-16304.5 16972.03,-16301.12 16973.38,-16297.72 16974.66,-16294.28 16975.87,-16290.82 16977,-16287.33 16978.06,-16283.83 16979.04,-16280.29 16979.95,-16276.74 16980.79,-16273.18 16981.55,-16269.59 16982.24,-16265.99 16982.85,-16262.38 16983.39,-16258.75 16983.85,-16255.11 16984.23,-16251.47 16984.54,-16247.82 16984.77,-16244.16 16984.92,-16240.5 16985,-16236.83 16985,-16235 16835,-16235 16835,-16235.68 16834.92,-16237.03 16834.78,-16238.38 16834.56,-16239.71 16834.27,-16241.03 16833.9,-16242.34 16833.47,-16243.62 16832.97,-16244.88 16832.4,-16246.11 16831.77,-16247.31 16831.07,-16248.47 16830.31,-16249.59 16829.49,-16250.67 16828.61,-16251.7 16827.68,-16252.68 16826.7,-16253.61 16825.67,-16254.49 16824.59,-16255.31 16823.47,-16256.07 16822.31,-16256.77 16821.11,-16257.4 16819.88,-16257.97 16818.62,-16258.47 16817.34,-16258.9 16816.03,-16259.27 16814.71,-16259.56 16813.38,-16259.78 16812.03,-16259.92 16810.68,-16260"/>
<polygon id="00000215A67220A0" class="l1111d0" points="15610,-14775 14421,-14775 14421,-14625 15610,-14625"/>
<polygon id="00000215A6722650" class="l1111d0" points="15635,-14800 15785,-14800 15785,-14798.17 15784.92,-14794.5 15784.77,-14790.84 15784.54,-14787.18 15784.23,-14783.53 15783.85,-14779.89 15783.39,-14776.25 15782.85,-14772.62 15782.24,-14769.01 15781.55,-14765.41 15780.79,-14761.82 15779.95,-14758.26 15779.04,-14754.71 15778.06,-14751.17 15777,-14747.67 15775.87,-14744.18 15774.66,-14740.72 15773.38,-14737.28 15772.03,-14733.88 15770.61,-14730.5 15769.12,-14727.15 15767.56,-14723.83 15765.93,-14720.55 15764.23,-14717.3 15762.47,-14714.09 15760.64,-14710.91 15758.74,-14707.78 15756.77,-14704.68 15754.74,-14701.63 15752.65,-14698.62 15750.5,-14695.66 15748.28,-14692.74 15746.01,-14689.86 15743.67,-14687.04 15741.27,-14684.27 15738.82,-14681.54 15736.31,-14678.87 15733.75,-14676.25 15731.13,-14673.69 15728.46,-14671.18 15725.73,-14668.73 15722.96,-14666.33 15720.14,-14663.99 15717.26,-14661.72 15714.34,-14659.5 15711.38,-14657.35 15708.37,-14655.26 15705.32,-14653.23 15702.22,-14651.26 15699.09,-14649.36 15695.91,-14647.53 15692.7,-14645.77 15689.45,-14644.07 15686.17,-14642.44 15682.85,-14640.88 15679.5,-14639.39 15676.12,-14637.97 15672.72,-14636.62 15669.28,-14635.34 15665.82,-14634.13 15662.33,-14633 15658.83,-14631.94 15655.29,-14630.96 15651.74,-14630.05 15648.18,-14629.21 15644.59,-14628.45 15640.99,-14627.76 15637.38,-14627.15 15633.75,-14626.61 15630.11,-14626.15 15626.47,-14625.77 15622.82,-14625.46 15619.16,-14625.23 15615.5,-14625.08 15611.83,-14625 15610,-14625 15610,-14775 15610.68,-14775 15612.03,-14775.08 15613.38,-14775.22 15614.71,-14775.44 15616.03,-14775.73 15617.34,-14776.1 15618.62,-14776.53 15619.88,-14777.03 15621.11,-14777.6 15622.31,-14778.23 15623.47,-14778.93 15624.59,-14779.69 15625.67,-14780.51 15626.7,-14781.39 15627.68,-14782.32 15628.61,-14783.3 15629.49,-14784.33 15630.31,-14785.41 15631.07,-14786.53 15631.77,-14787.69 15632.4,-14788.89 15632.97,-14790.12 15633.47,-14791.38 15633.9,-14792.66 15634.27,-14793.97 15634.56,-14795.29 15634.78,-14796.62 15634.92,-14797.97 15635,-14799.32"/>
<polygon id="00000215A67226C0" class="l1111d0" points="15635,-16235 15635,-14800 15785,-14800 15785,-16235"/>
<polygon id="00000215A6721FC0" class="l1111d0" points="15810,-16260 15810,-16410 15808.17,-16410 15804.5,-16409.92 15800.84,-16409.77 15797.18,-16409.54 15793.53,-16409.23 15789.89,-16408.85 15786.25,-16408.39 15782.62,-16407.85 15779.01,-16407.24 15775.41,-16406.55 15771.82,-16405.79 15768.26,-16404.95 15764.71,-16404.04 15761.17,-16403.06 15757.67,-16402 15754.18,-16400.87 15750.72,-16399.66 15747.28,-16398.38 15743.88,-16397.03 15740.5,-16395.61 15737.15,-16394.12 15733.83,-16392.56 15730.55,-16390.93 15727.3,-16389.23 15724.09,-16387.47 15720.91,-16385.64 15717.78,-16383.74 15714.68,-16381.77 15711.63,-16379.74 15708.62,-16377.65 15705.66,-16375.5 15702.74,-16373.28 15699.86,-16371.01 15697.04,-16368.67 15694.27,-16366.27 15691.54,-16363.82 15688.87,-16361.31 15686.25,-16358.75 15683.69,-16356.13 15681.18,-16353.46 15678.73,-16350.73 15676.33,-16347.96 15673.99,-16345.14 15671.72,-16342.26 15669.5,-16339.34 15667.35,-16336.38 15665.26,-16333.37 15663.23,-16330.32 15661.26,-16327.22 15659.36,-16324.09 15657.53,-16320.91 15655.77,-16317.7 15654.07,-16314.45 15652.44,-16311.17 15650.88,-16307.85 15649.39,-16304.5 15647.97,-16301.12 15646.62,-16297.72 15645.34,-16294.28 15644.13,-16290.82 15643,-16287.33 15641.94,-16283.83 15640.96,-16280.29 15640.05,-16276.74 15639.21,-16273.18 15638.45,-16269.59 15637.76,-16265.99 15637.15,-16262.38 15636.61,-16258.75 15636.15,-16255.11 15635.77,-16251.47 15635.46,-16247.82 15635.23,-16244.16 15635.08,-16240.5 15635,-16236.83 15635,-16235 15785,-16235 15785,-16235.68 15785.08,-16237.03 15785.22,-16238.38 15785.44,-16239.71 15785.73,-16241.03 15786.1,-16242.34 15786.53,-16243.62 15787.03,-16244.88 15787.6,-16246.11 15788.23,-16247.31 15788.93,-16248.47 15789.69,-16249.59 15790.51,-16250.67 15791.39,-16251.7 15792.32,-16252.68 15793.3,-16253.61 15794.33,-16254.49 15795.41,-16255.31 15796.53,-16256.07 15797.69,-16256.77 15798.89,-16257.4 15800.12,-16257.97 15801.38,-16258.47 15802.66,-16258.9 15803.97,-16259.27 15805.29,-16259.56 15806.62,-16259.78 15807.97,-16259.92 15809.32,-16260"/>
<polygon id="00000215A6722110" class="l1111d0" points="15810,-16260 16810,-16260 16810,-16410 15810,-16410"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 14 KiB

@@ -1,136 +0,0 @@
# =============================================
# mxPIC Cell/Project Definition File
# =============================================
schema_version: "2.0.0"
kind: cell
coordinate_system: gds_y_up
canvas_size:
width: 5000
height: 5000
project: mxpic_project_1
name: canvas_2
type: composite
version: "1.0.0"
# 1. External Ports (How this cell connects to the outside world)
pins:
- name: port_io1
layer: WG_CORE
element: port
pin: io1
x: 50.0
y: -150.0
angle: 0.0
width: 0.5
- name: port_2_io1
layer: WG_CORE
element: port_2
pin: io1
x: 1442.1
y: -1470.0
angle: 180.0
width: 10
- name: port_3_io1
layer: WG_CORE
element: port_3
pin: io1
x: 2024.3
y: -1609.0
angle: 180.0
width: 0.5
# 2. Instances (The sub-components dropped onto this canvas)
instances:
waveguide_3:
component: waveguide
x: 1581.0
y: -1633.5
rotation: 0.0
flip: 0
flop: 0
mirror: false
settings:
length: 100
width: 15
xsection: "strip"
elements:
port:
type: port
x: 50.0
y: -150.0
angle: 0.0
pin_number: 1
pitch: 10
layer: WG_CORE
width: 0.5
description: ""
pins:
- name: port_io1
role: io1
port:
type: port
x: 50.0
y: -150.0
angle: 180.0
pin_number: 1
pitch: 10
layer: WG_CORE
width: 0.5
description: ""
pins:
- name: port_io1
role: io1
port_2:
type: port
x: 1442.1
y: -1470.0
angle: 0.0
pin_number: 1
pitch: 10
layer: WG_CORE
width: 10
description: ""
pins:
- name: port_2_io1
role: io1
port_3:
type: port
x: 2024.3
y: -1609.0
angle: 0.0
pin_number: 1
pitch: 10
layer: WG_CORE
width: 0.5
description: ""
pins:
- name: port_3_io1
role: io1
# 3. Bundles (Grouped links for multi-bus/parallel routing)
bundles:
output_bus:
routing_type: euler_bend
links:
- from: waveguide_3:a1
to: port_2:port_2_io1
xsection: strip
family: optical
width: 15
radius: 10
routing_type: euler_bend
- from: waveguide_3:b1
to: port_2:port_2_io1
xsection: strip
family: optical
width: 15
radius: 10
routing_type: euler_bend
- from: port_3:port_3_io1
to: port_2:port_2_io1
xsection: strip
family: optical
width: 0.5
radius: 10
routing_type: euler_bend
File diff suppressed because one or more lines are too long
@@ -1,169 +0,0 @@
# =============================================
# mxPIC Cell/Project Definition File
# =============================================
schema_version: "2.0.0"
kind: cell
coordinate_system: gds_y_up
canvas_size:
width: 5000
height: 5000
project: mxpic_project_1
name: mxpic_project_1
type: project
version: "1.0.0"
# 1. External Ports (How this cell connects to the outside world)
<<<<<<< HEAD
ports: []
# 2. Instances (The sub-components dropped onto this canvas)
instances:
MMI_1:
component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/multimode_interferometers/1x2MMI_1310nm_TE_Silterra_202603_ZKY_v2
x: 1511.5
y: -2531.5
=======
pins:
- name: port_1_io1
layer: WG_CORE
element: port_1
pin: io1
x: 1699.6
y: -1844.2
angle: 180.0
width: 0.5
# 2. Instances (The sub-components dropped onto this canvas)
instances:
circle_1:
component: circle
x: 1877.6
y: -1816.7
rotation: 90.0
flip: 0
flop: 0
mirror: false
settings:
radius: 10
width: 0.5
xsection: "strip"
BD_1:
component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/bendings/SiN_EUB_1310_H400_w2500_L45_QY_202604
x: 1926.2
y: -1813.9
rotation: 90.0
flip: 0
flop: 0
mirror: false
settings:
length:
DC_1:
component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/directional_couplers/DC_SiN400_99_1_1310_jyh_quantex_202603
x: 1766.5
y: -1945.3
rotation: 0.0
flip: 0
flop: 0
mirror: false
settings:
length:
MZM_1:
component: Silterra/EMO1_2ML_CU_Al_RDL/composites/Mach_Zender_modulators/MZI_SiN400_Si220_PIN_mod_1310_L1300_QY_202603
x: 1341.6
y: -2103.8
rotation: 0.0
flip: 0
flop: 0
mirror: false
settings:
length:
phase_shifter_1:
component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/phase_shifters/HT_150R_SiPPP_L500_100OHM_DUMMY_QY_202604
x: 2695.0
y: -2275.0
rotation: 90.0
flip: 0
flop: 0
mirror: false
settings:
length:
MMI_1:
component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/multimode_interferometers/1x2MMI_1310nm_TE_Silterra_202603_ZKY_v2
x: 2849.0
y: -1988.6
>>>>>>> jingwen_main
rotation: 0.0
flip: 0
flop: 0
mirror: false
settings:
length:
<<<<<<< HEAD
MMI_2:
component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/multimode_interferometers/1x2MMI_1310nm_TE_Silterra_202603_ZKY_v2
x: 1716.4
y: -2293.8
=======
DC_2:
component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/directional_couplers/DC_SiN400_99_1_1310_jyh_quantex_202603
x: 2656.9
y: -1992.8
>>>>>>> jingwen_main
rotation: 0.0
flip: 0
flop: 0
mirror: false
settings:
length:
<<<<<<< HEAD
elements: {}
=======
PD_1:
component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/photodetectors/PD_1310_Monitor_Si220_Ge500_NPN_XHN_202604
x: 3151.7
y: -2032.1
rotation: 0.0
flip: 0
flop: 0
mirror: false
settings:
length:
elements:
port_1:
type: port
x: 1699.6
y: -1844.2
angle: 0.0
pin_number: 1
pitch: 10
layer: WG_CORE
width: 0.5
description: ""
pins:
- name: port_1_io1
role: io1
>>>>>>> jingwen_main
# 3. Bundles (Grouped links for multi-bus/parallel routing)
bundles:
output_bus:
routing_type: euler_bend
links:
<<<<<<< HEAD
- from: MMI_2:a1
to: MMI_1:b2
xsection: strip
family: optical
width: 0.45
radius: 10
routing_type: euler_bend
=======
>>>>>>> jingwen_main
Binary file not shown.
+108
View File
@@ -0,0 +1,108 @@
# Project Findings
## Repository Inventory
- Static/frontend files are under `frontend/`: `login.html`, `dashboard.html`, `canvas.html`, and `canvas-helpers.js`.
- Backend files are under `backend/`: `server.py`, `database.py`, `pdk_access.py`, `technology_manifest.py`, `gds_builder.py`, routing helpers, icons, and `directories.yaml`.
- Persistent data appears under `database/`, including `mxpic_data.db`, saved layout YAML/SVG files, and generated `_exports/*.gds`.
- Tests are JavaScript static/unit-style tests under `tests/`.
- Project docs exist under `docs/`, including intranet deployment, GDS/SVG generation, and PDK technology loading notes.
- A checked saved layout example at `database/engineer/layout/mxpic_project_1/mxpic_project_1.yml` contains unresolved merge-conflict markers, so at least some local saved data may be invalid until cleaned.
- Conflict-marker search also found real markers in `database/engineer/layout/mxpic_project_1/mxpic_project_1.svg`, `tests/layout-ui-wiring.test.js`, and `tests/layout-backend-static.test.js`.
- `backend/directories.yaml` is a legacy/declarative directory category file with PDK-style categories; the active docs/source show library scanning is now driven by the role-scoped PDK filesystem.
## Saved Layout YAML Shape
- Saved layout YAML uses schema version `2.0.0`, `kind: cell`, `coordinate_system: gds_y_up`, `canvas_size`, `project`, `name`, `type`, and `version`.
- Modern YAML uses `pins`, `instances`, `elements`, and `bundles`.
- `instances` can reference basic components like `circle`, generated/forge components, other project cells, or PDK paths such as `Silterra/<technology>/primitives/...`.
- `bundles.output_bus.links` stores routed connections with source/target pins and route settings.
- Both checked `.project.json` metadata files (`admin` and `engineer`) select technology `Silterra/EMO1_2ML_CU_Al_RDL`.
## README / Deployment
- The project is `mxpic_EDA`, an EDA layout tool for OptiHK.
- Runtime requirement explicitly listed in README is Flask.
- The application can launch login, dashboard, canvas editing, YAML generation, and PDK browsing without build-time router dependencies.
- Build/export actions require `mxpic_router` and Nazca; if `mxpic_forge.Route` is unavailable, routing falls back to Nazca interconnects.
- SVG preview generation for routed/build output requires `gdstk`.
- Intranet server is started with `run_intranet_server.ps1` and listens on `0.0.0.0:3000` by default.
- LAN users browse to `http://<host-computer-ip>:3000`; firewall must allow inbound TCP `3000`.
- Default local accounts are `admin / 123456` and `engineer / 123456`.
- User project files are stored under `database/<username>/layout`.
- Important env vars include `MXPIC_SECRET_KEY`, `MXPIC_HOST`, `MXPIC_PORT`, `MXPIC_DEBUG`, `MXPIC_COOKIE_SECURE`, `MXPIC_PDK_PUBLIC_ROOT`, and `MXPIC_PDK_ATLAS_ROOT`.
- Public/developer PDK roots default to `../opt_pdk_public/foundries`; manager/atlas roots default to `../opt_pdk_atlas/foundries`.
- `run_intranet_server.ps1` sets default `MXPIC_SECRET_KEY` if absent, sets `MXPIC_HOST=0.0.0.0`, `MXPIC_PORT=3000`, `MXPIC_DEBUG=0`, then runs `python backend\server.py`.
- `backend/server.py` initializes the local SQLite database when the server process starts.
- Flask runs threaded on the configured host and port.
## GDS / SVG Generation
- `Build Layout` serializes the active canvas page into layout YAML, posts it to `/api/save-layout`, writes `database/<username>/layout/<project>/<cell>.yml`, writes optional route sidecar data, then calls router-backed SVG preview generation.
- Routed SVG preview uses `backend/routed_layout_preview.py`, which delegates to `mxpic_router.build_project_gds`, reads the temporary GDS with `gdstk`, and writes `<cell>.svg`.
- `Build GDS` posts to `/api/build-gds` with only the project name. It does not automatically serialize unsaved in-memory canvas state first.
- Final GDS export reads existing saved project YAML files, calls `backend/gds_builder.py`, delegates to `mxpic_router`, writes `database/_exports/<uuid>/<project>.gds`, returns a download URL, then cleans up the export folder after response close.
- Saved layout files are under `database/<username>/layout/<project>/`.
- External build dependencies are lazy: normal web usage can work without router stack, while preview/build actions require `mxpic_router`, Nazca, and sometimes `gdstk`.
## PDK / Technology / Xsections
- PDK components, technology manifests, and GDS assets all come from role-scoped PDK roots.
- Dashboard loads available technologies from `/api/technologies`, scanning `<active_role_pdk_root>/<foundry>/<technology>/technology.yml`.
- Project creation stores selected technology in `database/<username>/layout/<project>/.project.json`.
- Canvas loads project metadata from `/api/projects/<project>`, then loads `/api/technologies/<foundry>/<technology>/manifest`.
- `technology.yml` supplies layer mappings, routing type options, defaults, and xsection definitions such as `strip`, `rib_low`, `metal_1`, and `metal_2`.
- Canvas route editing uses the active technology manifest to populate xsection choices and route defaults.
- Saved YAML stores component paths and per-link route data such as `xsection`, `family`, `width`, `radius`, and `routing_type`.
- Build-time router applies `technology.yml` to Nazca layers/xsections before resolving PDK assets and routing links.
## Backend Route Surface
- `backend/server.py` serves `/`, `/dashboard`, `/canvas`, `/canvas-helpers.js`, and `/logout`.
- Login endpoint is `POST /login`.
- Health check endpoint is `/api/health`.
- Account/profile endpoints include `/api/profile`, `/api/profile/password`, and `/api/logs`.
- Project endpoints include listing/creating `/api/projects`, reading/deleting `/api/projects/<project_name>`, cell rename/delete under `/api/projects/<project_name>/cells/<cell_name>`, and `/api/save-layout`.
- Build/export endpoints include `/api/build-gds`, `/api/exports/<export_id>/<filename>`, and `/api/projects/<project_name>/gds/<filename>`.
- PDK/technology endpoints include `/api/technologies`, `/api/technologies/<foundry>/<technology>/manifest`, `/api/library`, `/api/component/<component_name>`, `/api/component/<component_name>/image`, and `/api/icon/<category>`.
- Project listing treats each `.yml`/`.yaml` inside a project folder as one saved cell/canvas.
- Project creation sanitizes the requested name, adds a numeric suffix if needed, creates an initial project folder, writes `.project.json`, and logs `project.create`.
- `/api/save-layout` accepts `project`, `cell`, `content`, and optional `preview` flag.
- `/api/library` rebuilds the component tree on each request so project technology and user role are reflected immediately.
## Frontend Page Flow
- `frontend/login.html` renders a login form that submits `POST /login` and then moves authenticated users into the dashboard.
- `frontend/dashboard.html` loads recent logs from `/api/logs`, profile data from `/api/profile`, projects from `/api/projects`, and technology choices from `/api/technologies`.
- Opening a project navigates to `/canvas?project=<name>`.
- Creating a project posts `{ name, technology }` to `/api/projects`.
- Dashboard also supports deleting projects, updating occupation, and changing password through backend APIs.
- `frontend/canvas.html` loads project metadata/cells from `/api/projects/<project>`, then loads the selected technology manifest.
- Canvas loads the component library with `/api/library?project=<project>`, component metadata from `/api/component/<component_name>?project=<project>`, and component images from `/api/component/<component_name>/image?project=<project>`.
- Canvas save/build controls call `/api/save-layout` and `/api/build-gds`.
- Dashboard `openProject(name)` navigates directly to `/canvas?project=<name>`.
- Canvas `loadTechnologyManifest` falls back to `FALLBACK_TECHNOLOGY_MANIFEST` when the saved technology is missing/invalid.
- Canvas `fetchLibrary` is project-scoped, so the visible library follows the selected project technology.
- Canvas source comments define the control split:
- `handleBuildLayout`: save active page, generate preview assets, show preview tab.
- `handleSaveProjectLayouts`: save YAML for every editable page without opening previews.
- `handleBuildGds`: build project GDS through the backend and trigger download.
## Database
- `backend/database.py` uses SQLite at `database/mxpic_data.db`.
- Tables: `users` and `user_logs`.
- User records include password hash, creation date, credits, occupation, and `user_group`.
- Database migrations add missing columns to older local SQLite files.
- Default account roles are `admin -> manager`, `engineer -> developers`, and ordinary users default to `user`.
- Audit logs record user action, project/cell context, detail, IP address, and UTC timestamp.
## PDK Access and Build Helpers
- `backend/pdk_access.py` defines supported user groups: `manager`, `developers`, and `user`.
- Managers resolve to `MXPIC_PDK_ATLAS_ROOT` or `opt_pdk_atlas/foundries`; developers/users resolve to `MXPIC_PDK_PUBLIC_ROOT` or `opt_pdk_public/foundries`.
- Only managers prefer full component GDS assets; other roles use public/black-box style assets.
- Temporary GDS exports are created in UUID folders and old export folders are cleaned up after an age threshold.
- `backend/gds_builder.py` validates that saved cell YAML files exist, then delegates all final GDS work to `mxpic_router.build_project_gds`.
- Local GDS building is not implemented as a fallback in this repository.
## Tests
- Tests are JavaScript assertion scripts in `tests/`.
- The test suite heavily checks static frontend/backend integration contracts, such as route existence, API strings, layout/GDS wiring, technology manifest loading, and PDK access behavior.
- `tests/canvas-helpers.test.js` directly imports `frontend/canvas-helpers.js` and checks handle placement, YAML serialization, route defaults, element ports, route YAML, and route crossing helpers.
- Several tests intentionally assert that legacy local preview/registry modules are absent and that the router-backed preview/GDS path is present.
- Current checked test files include unresolved conflict markers in at least two files, so `node` test execution may fail before assertions run unless those files are cleaned.
## Open Questions
- None remaining for the requested project usage/workflow summary.
+50
View File
@@ -0,0 +1,50 @@
# Project Understanding Progress
## Session Log
- Started project read-through on 2026-06-08.
- Loaded requested `planning-with-files` skill and project-analysis guidance.
- Collected initial file inventory with `rg --files`.
- Created `develop_plan` planning notes.
- Read `README.md` and `docs/INTRANET_DEPLOYMENT.md`.
- Read `docs/GDS_SVG_GENERATION_LOGIC.md` and `docs/PDK_TECHNOLOGY_XSECTION_LOADING.md`.
- Listed `backend/server.py` route/function signatures.
- Read `backend/database.py`.
- Read `backend/pdk_access.py` and `backend/gds_builder.py`.
- Read `run_intranet_server.ps1` and backend startup/config references.
- Inspected login/dashboard and canvas frontend API wiring.
- Read dashboard and canvas handler context around project open, technology load, library load, save, preview, and GDS build.
- Read backend handler context and test structure.
- Read a saved engineer project YAML example and `backend/directories.yaml`.
- Searched for conflict markers and read admin/engineer `.project.json` metadata files.
- Wrote `develop_plan/project_understanding.md`.
## Commands / Checks
- `rg --files` succeeded with escalated approval after sandbox spawn failure.
- `Get-Content -Raw README.md` succeeded.
- `Get-Content -Raw docs\INTRANET_DEPLOYMENT.md` succeeded.
- `Get-Content -Raw docs\GDS_SVG_GENERATION_LOGIC.md` succeeded.
- `Get-Content -Raw docs\PDK_TECHNOLOGY_XSECTION_LOADING.md` succeeded.
- `rg "@app\\.route|def " backend\server.py` succeeded.
- `Get-Content -Raw backend\database.py` succeeded.
- `Get-Content -Raw backend\pdk_access.py` succeeded.
- `Get-Content -Raw backend\gds_builder.py` succeeded.
- `Get-Content -Raw run_intranet_server.ps1` succeeded.
- `rg -n "app.run|MXPIC_HOST|MXPIC_PORT|MXPIC_DEBUG|SECRET_KEY|init_db|database" backend\server.py` succeeded.
- `rg -n "fetch\\(|window\\.location|..." frontend\login.html frontend\dashboard.html` succeeded.
- `rg -n "fetch\\(|handleBuildLayout|handleBuildGds|..." frontend\canvas.html frontend\canvas-helpers.js` succeeded.
- `rg -n -C 4 "function openProject|..." frontend\dashboard.html` succeeded.
- `rg -n -C 5 "const loadProject|..." frontend\canvas.html` succeeded.
- `rg -n -C 8 "def login|def list_projects|..." backend\server.py` succeeded.
- `rg -n "node:test|assert|..." tests` succeeded.
- `Get-Content -Raw database\engineer\layout\mxpic_project_1\mxpic_project_1.yml` succeeded.
- `Get-Content -Raw backend\directories.yaml` succeeded.
- `rg -n "<<<<<<<|=======|>>>>>>>"` succeeded.
- `rg --files -g .project.json -g !database\_exports` succeeded.
- `Get-Content -Raw database\admin\layout\mxpic_project_1\.project.json` succeeded.
- `Get-Content -Raw database\engineer\layout\mxpic_project_1\.project.json` succeeded.
## Files Created / Modified
- Created `develop_plan/task_plan.md`.
- Created `develop_plan/findings.md`.
- Created `develop_plan/progress.md`.
- Created `develop_plan/project_understanding.md`.
+333
View File
@@ -0,0 +1,333 @@
# mxpic_EDA Project Understanding
## Purpose
`mxpic_EDA` is a local/intranet EDA web application for creating photonic integrated circuit layout projects. It combines:
- A Flask backend for authentication, project APIs, PDK browsing, layout persistence, preview generation, and GDS export.
- Static frontend pages for login, dashboard, and canvas editing.
- SQLite account/audit storage plus filesystem-based project layout storage.
- External build-time tooling (`mxpic_router`, Nazca, and sometimes `gdstk`) for routed SVG preview and final GDS generation.
The project is designed so normal login, dashboard, canvas editing, YAML generation, and PDK browsing can run without importing the router stack. Build actions load those heavier dependencies only when needed.
## Main Entry Points
### Start the App
The intended intranet startup path is:
```powershell
.\run_intranet_server.ps1
```
That script sets:
- `MXPIC_HOST=0.0.0.0`
- `MXPIC_PORT=3000`
- `MXPIC_DEBUG=0`
- a fallback `MXPIC_SECRET_KEY` if none is set
Then it runs:
```powershell
python backend\server.py
```
The server listens on:
```text
http://<host-computer-ip>:3000
```
Default local accounts are:
```text
admin / 123456
engineer / 123456
```
`admin` is a manager account. `engineer` is a developer account.
## Repository Structure
```text
backend/
server.py Flask app, routes, project/layout APIs
database.py SQLite initialization, users, profiles, audit logs
pdk_access.py Role-aware PDK root selection and export helpers
gds_builder.py Final GDS wrapper around mxpic_router
routed_layout_preview.py SVG preview generation via temporary routed GDS
router_dependency.py Lazy build-time dependency validation
technology_manifest.py technology.yml loading/validation
icons/ Category icons served by backend
frontend/
login.html Login page
dashboard.html Project/account dashboard
canvas.html Main layout editor
canvas-helpers.js Canvas/YAML/route helper functions and tests target
database/
mxpic_data.db SQLite app database
<username>/layout/... Saved project metadata, YAML cells, SVG previews
_exports/<uuid>/... Temporary generated GDS downloads
docs/
INTRANET_DEPLOYMENT.md
GDS_SVG_GENERATION_LOGIC.md
PDK_TECHNOLOGY_XSECTION_LOADING.md
tests/
JavaScript assertion tests for static wiring and canvas helpers
```
## User Workflow
1. User opens `/`.
2. If not logged in, Flask serves `frontend/login.html`.
3. Login form posts credentials to `POST /login`.
4. On success, the session stores user id, username, and user group.
5. User lands on `/dashboard`.
6. Dashboard loads:
- `/api/profile`
- `/api/logs`
- `/api/projects`
- `/api/technologies`
7. User creates or opens a project.
8. Creating a project posts `{ name, technology }` to `POST /api/projects`.
9. Opening a project navigates to `/canvas?project=<project>`.
10. Canvas loads project data from `/api/projects/<project>`.
11. Canvas loads the selected `technology.yml` manifest from `/api/technologies/<foundry>/<technology>/manifest`.
12. Canvas loads the project-scoped PDK library from `/api/library?project=<project>`.
13. User places components, elements, pins, and routes.
14. Save or Build Layout writes YAML to disk through `/api/save-layout`.
15. Build Layout also generates and opens an SVG preview.
16. Build GDS calls `/api/build-gds` and downloads the generated GDS.
## Project and Data Model
Each user's projects live under:
```text
database/<username>/layout/<project>/
```
Project metadata is stored in:
```text
database/<username>/layout/<project>/.project.json
```
Example:
```json
{
"name": "mxpic_project_1",
"technology": "Silterra/EMO1_2ML_CU_Al_RDL"
}
```
Saved cells are YAML files:
```text
database/<username>/layout/<project>/<cell>.yml
```
Generated previews are SVG files:
```text
database/<username>/layout/<project>/<cell>.svg
```
Modern saved layout YAML contains:
- `schema_version`
- `kind`
- `coordinate_system`
- `canvas_size`
- `project`
- `name`
- `type`
- `version`
- `pins`
- `instances`
- `elements`
- `bundles`
`instances` reference basic components, forge/generated components, other project cells, or PDK component paths. `bundles` store routed links and route settings such as `xsection`, `family`, `width`, `radius`, and `routing_type`.
## PDK and Technology Workflow
The active PDK root is chosen by user role:
- `manager`: `MXPIC_PDK_ATLAS_ROOT` or `opt_pdk_atlas/foundries`
- `developers` and `user`: `MXPIC_PDK_PUBLIC_ROOT` or `opt_pdk_public/foundries`
The dashboard lists available technologies by scanning:
```text
<active_role_pdk_root>/<foundry>/<technology>/technology.yml
```
The selected technology is saved in `.project.json`.
Canvas then uses that selected technology to:
- Load route defaults and xsections from `technology.yml`.
- Scope the component library browser to the chosen foundry/technology.
- Save component paths that can later resolve under the base role PDK root.
At build time, the router receives the active PDK root and the selected project's technology manifest path. The router applies technology layers/xsections to Nazca before resolving PDK assets and routing links.
## Build Layout vs Save vs Build GDS
### Save
The canvas "Save" path calls `handleSaveProjectLayouts`. It writes YAML for every editable project/cell page to `/api/save-layout` with preview disabled. It is for persistence, not preview.
### Build Layout
The canvas "Build Layout" path:
1. Validates route crossings.
2. Serializes the active page to YAML.
3. Posts to `/api/save-layout`.
4. Backend writes `<cell>.yml`.
5. Backend writes route sidecar data when available.
6. Backend calls `routed_layout_preview.py`.
7. `routed_layout_preview.py` calls `mxpic_router.build_project_gds`.
8. The temporary routed GDS is converted to `<cell>.svg` with `gdstk`.
9. Frontend opens the SVG preview tab.
### Build GDS
The canvas "Build GDS" path:
1. Validates route crossings across editable pages.
2. Posts `{ project }` to `/api/build-gds`.
3. Backend reads saved YAML files already on disk.
4. Backend creates `database/_exports/<uuid>/<project>.gds`.
5. `backend/gds_builder.py` delegates to `mxpic_router.build_project_gds`.
6. Backend returns `download_url`.
7. Frontend triggers a browser download.
8. Backend removes the temporary export folder after serving the file.
Important: Build GDS does not serialize unsaved in-memory canvas state first. Users should Save or Build Layout before Build GDS if they want latest canvas edits included.
## Backend API Map
Primary pages:
- `GET /`
- `POST /login`
- `GET /dashboard`
- `GET /canvas`
- `GET /canvas-helpers.js`
- `GET /logout`
Account and activity:
- `GET /api/health`
- `GET/PATCH /api/profile`
- `POST /api/profile/password`
- `GET/POST /api/logs`
Projects and cells:
- `GET /api/projects`
- `POST /api/projects`
- `GET /api/projects/<project_name>`
- `DELETE /api/projects/<project_name>`
- `PATCH/DELETE /api/projects/<project_name>/cells/<cell_name>`
- `POST /api/save-layout`
- `GET /api/projects/<project_name>/cells/<cell_name>/layout.svg`
Build/export:
- `POST /api/build-gds`
- `GET /api/exports/<export_id>/<filename>`
- `GET /api/projects/<project_name>/gds/<filename>`
PDK/technology/library:
- `GET /api/technologies`
- `GET /api/technologies/<foundry>/<technology>/manifest`
- `GET /api/library`
- `GET /api/component/<component_name>`
- `GET /api/component/<component_name>/image`
- `GET /api/icon/<category>`
## Persistence and Accounts
SQLite database:
```text
database/mxpic_data.db
```
Tables observed:
- `users`
- `user_logs`
The backend initializes the database on startup. It also performs lightweight migrations for profile, credit, occupation, and group fields.
User groups affect PDK access:
- `manager` can use atlas/private PDK roots and prefers full GDS assets.
- `developers` and `user` use the public PDK roots.
Audit logs record user actions with project/cell context, details, IP address, and UTC timestamp.
## Tests
Tests are JavaScript assertion scripts under `tests/`.
The suite mostly checks integration contracts by reading source files, including:
- API route strings and handler wiring.
- Build Layout and Build GDS frontend/backend wiring.
- Removal of legacy local preview/PDK registry modules.
- Router-backed GDS and SVG preview paths.
- Technology manifest and PDK access behavior.
- Canvas helper behavior such as pin/handle placement, YAML serialization, route defaults, route YAML, element ports, and route crossing checks.
Likely command:
```powershell
node --test tests
```
## Current Repository State Notes
This checkout contains unresolved merge-conflict markers in some tracked files:
- `database/engineer/layout/mxpic_project_1/mxpic_project_1.yml`
- `database/engineer/layout/mxpic_project_1/mxpic_project_1.svg`
- `tests/layout-ui-wiring.test.js`
- `tests/layout-backend-static.test.js`
That means some checked sample data may not parse as YAML/SVG, and the test suite may fail before reaching assertions until those files are cleaned.
The checked admin and engineer project metadata both select:
```text
Silterra/EMO1_2ML_CU_Al_RDL
```
## Mental Model
Think of this app as:
```text
Flask session/account layer
-> role-scoped PDK/technology selection
-> dashboard project metadata
-> canvas layout editing
-> YAML saved on disk
-> mxpic_router/Nazca build path
-> SVG preview or downloadable GDS
```
The repository itself owns the web UI, persistence, API contracts, and orchestration. The actual routed photonic layout build is intentionally delegated to the external `mxpic_router` stack.
+19
View File
@@ -0,0 +1,19 @@
# Project Understanding Plan
## Goal
Read the `mxpic_EDA` project and document its usage and workflow in Markdown files under `develop_plan`.
## Phases
| Phase | Status | Notes |
|---|---|---|
| Initialize planning files | complete | Created `develop_plan` planning notes. |
| Inventory repository structure | complete | File list collected with `rg --files`. |
| Read README and operational docs | complete | README, intranet, GDS/SVG, and PDK technology docs read. |
| Read backend entry points and data layer | complete | Route surface, database, PDK access, and GDS builder inspected. |
| Read frontend entry points | complete | Login/dashboard/canvas API wiring and handler context inspected. |
| Summarize project usage/workflow | complete | Wrote `develop_plan/project_understanding.md`. |
## Errors Encountered
| Error | Attempt | Resolution |
|---|---|---|
| `windows sandbox: spawn setup refresh` | Tried normal PowerShell/read commands in sandbox | Re-ran required commands with escalated approval. |
+5 -5
View File
@@ -31,15 +31,15 @@ Important functions:
## Generated Files
- Saved cell YAML: `database/<username>/layout/<project>/<cell>.yml`
- Saved cell YAML: `mxpic_EDA_database/<username>/layout/<project>/<cell>.yml`
- Path helpers: `user_layout_root`, `project_root`, `cell_file_path`
(`backend/server.py` lines 124-137).
- Saved layout preview SVG: `database/<username>/layout/<project>/<cell>.svg`
- Saved layout preview SVG: `mxpic_EDA_database/<username>/layout/<project>/<cell>.svg`
- Path helper: `cell_svg_path` (`backend/server.py` lines 140-142).
- Optional route sidecar: `database/<username>/layout/<project>/<cell>.routes.yml`
- Optional route sidecar: `mxpic_EDA_database/<username>/layout/<project>/<cell>.routes.yml`
- Path helper and writer: `cell_routes_path`, `write_route_points_sidecar`
(`backend/server.py` lines 145-175).
- Downloadable GDS export: `database/_exports/<uuid>/<project>.gds`
- Downloadable GDS export: `mxpic_EDA_database/_exports/<uuid>/<project>.gds`
- Created by `create_export_path` (`backend/pdk_access.py` lines 53-59).
## Build Layout: Click Button -> YAML -> Router GDS -> SVG
@@ -170,7 +170,7 @@ Important behavior:
- Old exports are cleaned (`backend/server.py` line 781).
- The project directory is resolved and validated
(`backend/server.py` lines 782-784).
- `create_export_path` creates `database/_exports/<uuid>/<project>.gds`
- `create_export_path` creates `mxpic_EDA_database/_exports/<uuid>/<project>.gds`
(`backend/server.py` line 785, `backend/pdk_access.py` lines 53-59).
- `build_project_gds(...)` is called (`backend/server.py` lines 786-792).
+15 -1
View File
@@ -61,9 +61,22 @@ Change these passwords from the dashboard profile panel before regular use.
Each user stores projects under:
```text
database/<username>/layout
mxpic_EDA_database/<username>/layout
```
Before starting the server, move the existing `database` folder beside the repo
and rename it to `mxpic_EDA_database`:
```text
<parent-folder>/
mxpic_EDA/
mxpic_EDA_database/
```
The backend fails fast if the runtime database folder is missing or still inside
the repository. Use `MXPIC_DATABASE_ROOT` only when the database must live in a
different external location.
## Useful environment variables
```text
@@ -72,6 +85,7 @@ MXPIC_PORT=3000
MXPIC_DEBUG=0
MXPIC_SECRET_KEY=<long random string>
MXPIC_COOKIE_SECURE=0
MXPIC_DATABASE_ROOT=<path-to-mxpic_EDA_database>
MXPIC_PDK_PUBLIC_ROOT=<path-to-public-foundries>
MXPIC_PDK_ATLAS_ROOT=<path-to-atlas-foundries>
```
+2 -2
View File
@@ -28,7 +28,7 @@ There are three related but separate data paths.
load route defaults, and register Nazca layers/xsections.
3. Saved project layout YAML
- Source: `database/<username>/layout/<project>/<cell>.yml`.
- Source: `mxpic_EDA_database/<username>/layout/<project>/<cell>.yml`.
- Contains placed component paths and `bundles.*.links[*].xsection`.
- Consumed by `mxpic_router` when building SVG preview GDS or downloadable GDS.
@@ -102,7 +102,7 @@ Detailed path:
Saved metadata location:
`database/<username>/layout/<project>/.project.json`
`mxpic_EDA_database/<username>/layout/<project>/.project.json`
Example:
+137 -54
View File
@@ -12,6 +12,13 @@
}
root.MxpicCanvasHelpers = helpers;
})(typeof window !== 'undefined' ? window : globalThis, function () {
// Global origin for YAML coordinate export/import so YAML values always match
// the RightPanel display coordinate system.
let __exportOriginX = null;
let __exportOriginY = null;
var setExportOrigin = (x, y) => { __exportOriginX = x; __exportOriginY = y; };
var getExportOrigin = () => ({ x: __exportOriginX, y: __exportOriginY });
// Label used by the canvas to represent generated mxpic_forge components.
const FORGE_COMPONENT_LABEL = 'generate with mxpic_forge';
// Serialized component type used when saving mxpic_forge-generated components.
@@ -22,6 +29,7 @@
const DEFAULT_CANVAS_SIZE = { width: 5000, height: 5000 };
// Base visual diameter and hit area used for port and anchor handles.
const PORT_NODE_SIZE = 30;
const FREE_WIRES_BUNDLE_GROUP = 'free_wires';
const PORT_LABEL_MIN_CHARS = 5;
const PORT_LABEL_CHAR_WIDTH = 7;
const PORT_LABEL_HORIZONTAL_PADDING = 12;
@@ -137,6 +145,26 @@
return (technology.xsections && technology.xsections[xsection]) || technology.xsections.strip || {};
};
const cleanBundleGroupName = (value) => String(value ?? '')
.trim()
.replace(/\s+/g, '_')
.replace(/[^A-Za-z0-9_.-]/g, '_')
.replace(/_+/g, '_')
.replace(/^[._-]+|[._-]+$/g, '');
const normalizeBundleGroupName = (value, fallback = FREE_WIRES_BUNDLE_GROUP) => {
const cleaned = cleanBundleGroupName(value);
if (cleaned) return cleaned;
const fallbackText = fallback === null || fallback === undefined ? '' : String(fallback);
return cleanBundleGroupName(fallbackText) || (fallbackText === '' ? '' : FREE_WIRES_BUNDLE_GROUP);
};
const freeWireBundleGroupName = (xsection, defaultXsection) => {
const defaultName = normalizeBundleGroupName(defaultXsection || FALLBACK_TECHNOLOGY_MANIFEST.defaults.xsection || 'strip', 'strip');
const currentName = normalizeBundleGroupName(xsection || defaultXsection || defaultName, defaultName);
return currentName === defaultName ? FREE_WIRES_BUNDLE_GROUP : `${FREE_WIRES_BUNDLE_GROUP}_${currentName}`;
};
// Normalize route settings so every edge has xsection, family, width, radius, and bend type.
const createRouteSettings = (manifest, overrides) => {
const technology = getTechnologyManifest(manifest);
@@ -150,6 +178,7 @@
width: Number((overrides && overrides.width) ?? xsectionInfo.default_width ?? defaults.width ?? 0.45),
radius: Number((overrides && overrides.radius) ?? xsectionInfo.default_radius ?? defaults.radius ?? 10),
routing_type: (overrides && overrides.routing_type) || defaults.routing_type || 'euler_bend',
bundle_group: (overrides && (overrides.bundle_group ?? overrides.bundleGroup)) || '',
widthEdited: Boolean(overrides && overrides.widthEdited)
};
};
@@ -629,10 +658,20 @@
return JSON.stringify(String(value));
};
// Convert canvas Y coordinates into layout Y coordinates.
const canvasToLayoutY = (value) => -Number(value || 0);
// Convert layout Y coordinates back into canvas Y coordinates.
const layoutToCanvasY = (value) => -Number(value || 0);
// Convert canvas coordinates into layout/display coordinates.
// When origin is set, uses the RightPanel formula: displayY = originY - rfY
// Falls back to simple negation for backward compatibility.
const canvasToLayoutY = (value) => { const v = Number(value || 0); return __exportOriginY != null ? __exportOriginY - v : -v; };
const canvasToLayoutX = (value) => { const v = Number(value || 0); return __exportOriginX != null ? v - __exportOriginX : v; };
// Convert layout/display coordinates back into canvas coordinates.
// Uses self-inverse formula for Y: rfY = originY - displayY (same as above).
// Import: layout/display coords → canvas coords. Optional originY/originX allow
// per-file overrides (e.g. from a YAML canvas_origin field). When omitted the
// module-level origin is used; null origin falls back to simple negation / pass-through.
const layoutToCanvasY = (value, originY) => { const v = Number(value || 0); const oy = originY !== undefined ? originY : __exportOriginY; return oy != null ? oy - v : -v; };
const layoutToCanvasX = (value, originX) => { const v = Number(value || 0); const ox = originX !== undefined ? originX : __exportOriginX; return ox != null ? v + ox : v; };
// Serialize nested component settings into YAML blocks.
const buildSettingsYaml = (settings, indent) => {
@@ -655,8 +694,8 @@
: '\n settings:\n length:';
return ` ${instanceName}:
component: ${componentValue}
x: ${Number(position.x || 0).toFixed(1)}
component: "${componentValue}"
x: ${canvasToLayoutX(position.x).toFixed(1)}
y: ${canvasToLayoutY(position.y).toFixed(1)}
rotation: ${Number(rotation || 0).toFixed(1)}
flip: ${flip ? 1 : 0}
@@ -768,14 +807,11 @@
const portNumber = normalizePortNumber(data && data.portNumber);
const pitch = normalizePitch(data && data.pitch);
const handleClearance = Math.max(pitch, 14);
const portDisplayName = String((data && (data.portName || data.componentDisplayName || data.label)) || 'port');
const portWidth = Math.max(
PORT_NODE_SIZE,
PORT_LABEL_HORIZONTAL_PADDING + Math.max(PORT_LABEL_MIN_CHARS, portDisplayName.length) * PORT_LABEL_CHAR_WIDTH
);
return {
width: data && data.elementType === 'anchor' ? ANCHOR_NODE_WIDTH : portWidth,
height: Math.max(PORT_NODE_SIZE, PORT_NODE_SIZE + Math.max(0, portNumber - 1) * handleClearance)
width: data && data.elementType === 'anchor' ? ANCHOR_NODE_WIDTH : PORT_NODE_SIZE,
height: data && data.elementType === 'anchor'
? Math.max(PORT_NODE_SIZE / 2, PORT_NODE_SIZE / 2 + Math.max(0, portNumber - 1) * handleClearance)
: Math.max(PORT_NODE_SIZE, PORT_NODE_SIZE + Math.max(0, portNumber - 1) * handleClearance)
};
};
@@ -809,7 +845,8 @@
}
const entries = [];
Array.from({ length: portNumber }, (_, index) => {
const y = elementPortOffset(index, portNumber, pitch);
const defaultSingleAnchor = portNumber === 1;
const y = defaultSingleAnchor ? -PORT_NODE_SIZE / 2 : elementPortOffset(index, portNumber, pitch);
entries.push([`a${index + 1}`, { x: 0, y, a: 180, width }]);
entries.push([`b${index + 1}`, { x: 0, y, a: 0, width }]);
});
@@ -888,7 +925,7 @@
// Convert standalone port nodes into page-level layout pins.
const buildPageComponentPins = (port, nodes) => {
const portNodes = (nodes || []).filter(isPortElementNode);
const portNodes = (nodes || []).filter(n => n.id === 'page-port');
if (portNodes.length > 0) {
return portNodes.reduce((pins, node) => {
const data = node.data || {};
@@ -942,7 +979,7 @@
${data.layer ? `layer: ${data.layer}` : 'layer: WG_CORE'}
element: ${info.element}
pin: ${info.pin}
x: ${Number(info.x || 0).toFixed(1)}
x: ${canvasToLayoutX(info.x).toFixed(1)}
y: ${canvasToLayoutY(info.y).toFixed(1)}
angle: ${Number(info.a || 0).toFixed(1)}
width: ${Number(info.width || 0.5)}${description}`;
@@ -957,7 +994,7 @@
// Serialize built-in port and anchor nodes into layout element metadata.
const buildElementsYaml = (nodes) => {
const elementNodes = (nodes || []).filter(isElementNode);
const elementNodes = (nodes || []).filter(n => isElementNode(n) && n.id !== 'page-port');
if (elementNodes.length === 0) return 'elements: {}';
const lines = elementNodes.map(node => {
const data = node.data || {};
@@ -970,7 +1007,7 @@
.join('\n');
return ` ${name}:
type: ${data.elementType}
x: ${Number((node.position && node.position.x) || 0).toFixed(1)}
x: ${canvasToLayoutX((node.position && node.position.x) || 0).toFixed(1)}
y: ${canvasToLayoutY((node.position && node.position.y) || 0).toFixed(1)}
angle: ${Number(angle || 0).toFixed(1)}
pin_number: ${portNumber}
@@ -1004,54 +1041,76 @@ ${pinLines}`;
const nodeMap = {};
nodes.forEach(n => { nodeMap[n.id] = n; });
let linksYaml = '';
if (edges.length > 0) {
const linkLines = edges.map(edge => {
const sourceNode = nodeMap[edge.source];
const targetNode = nodeMap[edge.target];
const sourceName = sourceNode ? (sourceNode.data.componentDisplayName || sourceNode.id) : edge.source;
const targetName = targetNode ? (targetNode.data.componentDisplayName || targetNode.id) : edge.target;
const fromPort = sourceNode && sourceNode.data && sourceNode.data.elementType
? getElementPinName(sourceNode, edge.sourceHandle)
: edge.sourceHandle || 'unknown';
const toPort = targetNode && targetNode.data && targetNode.data.elementType
? getElementPinName(targetNode, edge.targetHandle)
: edge.targetHandle || 'unknown';
const route = createRouteSettings(manifest, edge.data && edge.data.route);
const routeWidth = getRouteEndpointWidth(sourceNode, edge.sourceHandle)
?? getRouteEndpointWidth(targetNode, edge.targetHandle)
?? route.width;
const storedPoints = Array.isArray(edge.data && edge.data.points) ? edge.data.points : [];
const points = storedPoints.length >= 2 ? getEdgeRoutePoints(edge, nodeMap) : [];
const pointsYaml = points.length > 0
? `\n points:\n${points.map(point => ` - x: ${Number(point.x || 0).toFixed(1)}\n y: ${canvasToLayoutY(point.y).toFixed(1)}`).join('\n')}`
: '';
const isFreeRoute = Boolean(edge.data && edge.data.freeRoute) || (!sourceNode && !targetNode && points.length >= 2);
if (isFreeRoute) {
return ` - id: ${toYamlScalar(edge.id)}
const groups = new Map();
let primaryFreeWireXsection = '';
const freeWireGroupForRoute = (route) => {
const xsectionName = normalizeBundleGroupName(route.xsection, 'strip');
if (!primaryFreeWireXsection) {
primaryFreeWireXsection = xsectionName;
return FREE_WIRES_BUNDLE_GROUP;
}
return xsectionName === primaryFreeWireXsection
? FREE_WIRES_BUNDLE_GROUP
: `${FREE_WIRES_BUNDLE_GROUP}_${xsectionName}`;
};
edges.forEach(edge => {
const sourceNode = nodeMap[edge.source];
const targetNode = nodeMap[edge.target];
const sourceName = sourceNode ? (sourceNode.data.componentDisplayName || sourceNode.id) : edge.source;
const targetName = targetNode ? (targetNode.data.componentDisplayName || targetNode.id) : edge.target;
const fromPort = sourceNode && sourceNode.data && sourceNode.data.elementType
? getElementPinName(sourceNode, edge.sourceHandle)
: edge.sourceHandle || 'unknown';
const toPort = targetNode && targetNode.data && targetNode.data.elementType
? getElementPinName(targetNode, edge.targetHandle)
: edge.targetHandle || 'unknown';
const route = createRouteSettings(manifest, edge.data && edge.data.route);
const routeWidth = getRouteEndpointWidth(sourceNode, edge.sourceHandle)
?? getRouteEndpointWidth(targetNode, edge.targetHandle)
?? route.width;
const storedPoints = Array.isArray(edge.data && edge.data.points) ? edge.data.points : [];
const points = storedPoints.length >= 2 ? getEdgeRoutePoints(edge, nodeMap) : [];
const pointsYaml = points.length > 0
? `\n points:\n${points.map(point => ` - x: ${canvasToLayoutX(point.x).toFixed(1)}\n y: ${canvasToLayoutY(point.y).toFixed(1)}`).join('\n')}`
: '';
const isFreeRoute = Boolean(edge.data && edge.data.freeRoute) || (!sourceNode && !targetNode && points.length >= 2);
const linkYaml = isFreeRoute
? ` - id: ${toYamlScalar(edge.id)}
xsection: ${route.xsection}
family: ${route.family}
width: ${Number(routeWidth)}
radius: ${Number(route.radius)}
routing_type: ${route.routing_type}${pointsYaml}`;
}
return ` - from: ${sourceName}:${fromPort}
routing_type: ${route.routing_type}${pointsYaml}`
: ` - from: ${sourceName}:${fromPort}
to: ${targetName}:${toPort}
xsection: ${route.xsection}
family: ${route.family}
width: ${Number(routeWidth)}
radius: ${Number(route.radius)}
routing_type: ${route.routing_type}${pointsYaml}`;
});
linksYaml = linkLines.join('\n');
}
const routeGroupName = normalizeBundleGroupName(route.bundle_group, '');
const groupName = routeGroupName || freeWireGroupForRoute(route);
if (!groups.has(groupName)) {
groups.set(groupName, {
xsection: route.xsection,
family: route.family,
routing_type: route.routing_type,
links: []
});
}
groups.get(groupName).links.push(linkYaml);
});
const groupsYaml = Array.from(groups.entries()).map(([groupName, group]) => ` ${groupName}:
xsection: ${group.xsection}
family: ${group.family}
routing_type: ${group.routing_type}
links:
${group.links.join('\n')}`).join('\n');
return `# 3. Bundles (Grouped links for multi-bus/parallel routing)
bundles:
output_bus:
routing_type: euler_bend
links:
${linksYaml}`;
bundles:${groupsYaml ? `\n${groupsYaml}` : ' {}'}`;
};
// Return the center point of a node when a more precise port point is unavailable.
@@ -1237,6 +1296,22 @@ ${linksYaml}`;
return null;
};
const getRotatableNodeHandleDirection = (node, handleId) => {
if (!node || !handleId) return null;
if (node.type !== 'rotatableNode' && !(!node.data?.elementType && node.data?.componentName)) return null;
const ports = node.data && node.data.ports;
if (!ports || !ports[handleId]) return null;
const boxSize = normalizeBoxSize({ box_size: node.data && node.data.boxSize }, DEFAULT_COMPONENT_BOX_SIZE);
const handles = buildPortHandles(ports, {
rotation: Number((node.data && node.data.rotation) || 0),
flip: Boolean(node.data && node.data.flip),
flop: Boolean(node.data && node.data.flop),
boxSize
});
const found = handles.find(handle => handle.name === handleId);
return found ? found.position : null;
};
// Backward-compatible alias for same-type route crossing validation.
const findSameFamilyRouteCrossing = findSameTypeRouteCrossing;
@@ -1252,13 +1327,20 @@ ${linksYaml}`;
BASIC_COMPONENTS,
DEFAULT_FORGE_ARGUMENTS,
FALLBACK_TECHNOLOGY_MANIFEST,
FREE_WIRES_BUNDLE_GROUP,
setExportOrigin,
getExportOrigin,
canvasToLayoutY,
canvasToLayoutX,
layoutToCanvasY,
layoutToCanvasX,
createForgeArguments,
createRouteSettings,
updateRouteField,
updateRouteXsection,
routeStyleForSettings,
normalizeBundleGroupName,
freeWireBundleGroupName,
findSameTypeRouteCrossing,
findSameFamilyRouteCrossing,
isForgeComponent,
@@ -1276,6 +1358,7 @@ ${linksYaml}`;
createComponentSymbolMetrics,
transformPortInfo,
getNodePortCanvasPoint,
getRotatableNodeHandleDirection,
buildPortHandles,
buildElementPorts,
buildElementPinEntries,
+675 -241
View File
File diff suppressed because it is too large Load Diff
+17
View File
@@ -63,3 +63,20 @@ assert(
!canvasHtml.includes("activePage.nodes.filter(n => n.selected && n.id !== 'page-port')"),
'copy/delete should not exclude port nodes'
);
assert(
canvasHtml.includes('Bundle Group') &&
canvasHtml.includes('bundleGroupOptions') &&
canvasHtml.includes('compatibleBundleGroupOptions'),
'route editor should expose a Bundle Group dropdown filtered by compatible xsection'
);
assert(
canvasHtml.includes('newBundleGroupName') &&
canvasHtml.includes('normalizeBundleGroupName') &&
canvasHtml.includes('onAddBundleGroup'),
'route editor should provide an add flow that sanitizes new bundle group names'
);
assert(
canvasHtml.includes('routeStyleForSettings({ xsection: option.xsection') ||
canvasHtml.includes('routeStyleForSettings({ xsection: group.xsection'),
'bundle group dropdown options should use route xsection colors'
);
+88
View File
@@ -588,9 +588,13 @@ assert.deepStrictEqual(routeDefaults, {
width: 0.45,
radius: 10,
routing_type: 'euler_bend',
bundle_group: '',
widthEdited: false
});
const groupedRouteDefaults = helpers.createRouteSettings(technologyManifest, { bundle_group: 'group_A' });
assert.strictEqual(groupedRouteDefaults.bundle_group, 'group_A');
const metalRoute = helpers.updateRouteXsection(routeDefaults, 'metal_1', technologyManifest);
assert.strictEqual(metalRoute.family, 'electrical');
assert.strictEqual(metalRoute.width, 5);
@@ -692,6 +696,90 @@ assert(freeRouteYaml.includes('points:'));
assert(freeRouteYaml.includes('x: 80.0'));
assert(freeRouteYaml.includes('y: -120.0'));
const groupedBundlesYaml = helpers.buildBundlesYaml({
nodes: [
{ id: 'a', data: { componentDisplayName: 'inst_a' } },
{ id: 'b', data: { componentDisplayName: 'inst_b' } },
{ id: 'c', data: { componentDisplayName: 'inst_c' } },
{ id: 'd', data: { componentDisplayName: 'inst_d' } }
],
edges: [
{
id: 'edge-group-a',
source: 'a',
target: 'b',
sourceHandle: 'out',
targetHandle: 'in',
data: {
route: {
xsection: 'strip',
family: 'optical',
width: 0.45,
radius: 10,
routing_type: 'euler_bend',
bundle_group: 'optical_bus'
}
}
},
{
id: 'edge-group-b',
source: 'c',
target: 'd',
sourceHandle: 'out',
targetHandle: 'in',
data: {
route: {
xsection: 'metal_1',
family: 'electrical',
width: 5,
radius: 20,
routing_type: 'standard_bend',
bundle_group: 'electrical_bus'
}
}
}
]
}, technologyManifest);
assert(groupedBundlesYaml.includes(' optical_bus:\n xsection: strip\n family: optical\n routing_type: euler_bend\n links:'));
assert(groupedBundlesYaml.includes(' electrical_bus:\n xsection: metal_1\n family: electrical\n routing_type: standard_bend\n links:'));
assert(groupedBundlesYaml.includes('from: inst_a:out'));
assert(groupedBundlesYaml.includes('from: inst_c:out'));
assert(!groupedBundlesYaml.includes('bundle_group:'), 'bundle_group should choose the YAML key, not be written inside links');
const splitFreeWireBundlesYaml = helpers.buildBundlesYaml({
nodes: [
{ id: 'a', data: { componentDisplayName: 'inst_a' } },
{ id: 'b', data: { componentDisplayName: 'inst_b' } },
{ id: 'c', data: { componentDisplayName: 'inst_c' } },
{ id: 'd', data: { componentDisplayName: 'inst_d' } }
],
edges: [
{
id: 'edge-free-strip',
source: 'a',
target: 'b',
sourceHandle: 'out',
targetHandle: 'in',
data: {
route: { xsection: 'strip', family: 'optical', width: 0.45, radius: 10, routing_type: 'euler_bend' }
}
},
{
id: 'edge-free-metal',
source: 'c',
target: 'd',
sourceHandle: 'out',
targetHandle: 'in',
data: {
route: { xsection: 'metal_1', family: 'electrical', width: 5, radius: 20, routing_type: 'standard_bend' }
}
}
]
}, technologyManifest);
assert(splitFreeWireBundlesYaml.includes(' free_wires:\n xsection: strip\n family: optical\n routing_type: euler_bend\n links:'));
assert(splitFreeWireBundlesYaml.includes(' free_wires_metal_1:\n xsection: metal_1\n family: electrical\n routing_type: standard_bend\n links:'));
assert(!splitFreeWireBundlesYaml.includes('bundle_group:'), 'free-wire bundle names should not be duplicated into link metadata');
const edgeA = {
id: 'edge-a-b',
source: 'a',
+64
View File
@@ -0,0 +1,64 @@
/*
* Description: Static regression tests for keeping mxPIC EDA runtime data outside the repository.
* Inside functions: N/A - assertion-based test/module script.
* Developer : Qin Yue @ 2026
* Organization : OptiHK Limited
*/
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const root = path.resolve(__dirname, '..');
const backend = path.join(root, 'backend');
const storagePathsPath = path.join(backend, 'storage_paths.py');
const storagePathsPy = fs.existsSync(storagePathsPath)
? fs.readFileSync(storagePathsPath, 'utf8')
: '';
const databasePy = fs.readFileSync(path.join(backend, 'database.py'), 'utf8');
const serverPy = fs.readFileSync(path.join(backend, 'server.py'), 'utf8');
const gitignore = fs.readFileSync(path.join(root, '.gitignore'), 'utf8');
assert(
fs.existsSync(storagePathsPath),
'backend/storage_paths.py should be the single source of truth for runtime storage paths'
);
assert(
storagePathsPy.includes('MXPIC_DATABASE_ROOT'),
'storage path layer should support MXPIC_DATABASE_ROOT override'
);
assert(
storagePathsPy.includes('mxpic_EDA_database'),
'default runtime database folder should be sibling mxpic_EDA_database'
);
assert(
storagePathsPy.includes('DB_FILE') && storagePathsPy.includes('EXPORT_ROOT'),
'storage path layer should export DB_FILE and EXPORT_ROOT'
);
assert(
storagePathsPy.includes('raise RuntimeError'),
'storage path layer should fail fast when the external database root is invalid'
);
assert(
!serverPy.includes("DATABASE_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', 'database'))"),
'server.py should not hardcode in-repo database/ as DATABASE_ROOT'
);
assert(
serverPy.includes('from storage_paths import DATABASE_ROOT, EXPORT_ROOT'),
'server.py should import runtime storage roots from storage_paths'
);
assert(
!databasePy.includes('"..", "database", "mxpic_data.db"') &&
!databasePy.includes("'..', 'database', 'mxpic_data.db'"),
'database.py should not hardcode database/mxpic_data.db inside the repository'
);
assert(
databasePy.includes('from storage_paths import DB_FILE'),
'database.py should import DB_FILE from storage_paths'
);
assert(
gitignore.includes('/database/') &&
gitignore.includes('/backend/*.db') &&
gitignore.includes('*.db-wal') &&
gitignore.includes('/mxpic_EDA_database/'),
'.gitignore should ignore old and accidental in-repo runtime database artifacts'
);
-3
View File
@@ -61,7 +61,6 @@ assert(
'save-layout response should include an svg_url for the new layout tab'
);
assert(
<<<<<<< HEAD
serverPy.includes('svg_ready') &&
serverPy.includes('svg_version') &&
serverPy.includes('file_version(svg_path)') &&
@@ -74,8 +73,6 @@ assert(
'save-layout should publish generated SVG previews atomically instead of serving partially written files'
);
assert(
=======
>>>>>>> jingwen_main
serverPy.includes('RouterStackUnavailable') &&
serverPy.includes('except RouterStackUnavailable as e') &&
serverPy.includes('"preview_status": preview_status') &&
+13 -13
View File
@@ -33,16 +33,6 @@ assert(
'Build Layout should use the backend svg_url response'
);
assert(
<<<<<<< HEAD
canvasHtml.includes('result.svg_ready && result.svg_url') &&
canvasHtml.includes('buildLayoutRequestRef') &&
canvasHtml.includes('buildLayoutBusyRef') &&
canvasHtml.includes("cache: 'no-store'"),
'Build Layout should wait for a ready, versioned SVG response and prevent stale duplicate preview updates'
);
assert(
=======
>>>>>>> jingwen_main
canvasHtml.includes('result.preview_error') &&
canvasHtml.includes('Preview skipped: '),
'Build Layout should log when the backend saves YAML but skips SVG preview because the router stack is unavailable'
@@ -60,8 +50,18 @@ assert(
'layout SVG preview should expose an editable scale value'
);
assert(
canvasHtml.includes('objectFit: \'contain\''),
'100% layout preview scale should fit the full SVG within the screen'
canvasHtml.includes('objectFit: \'contain\'') &&
canvasHtml.includes('previewCanvasRef') &&
canvasHtml.includes('ResizeObserver') &&
canvasHtml.includes('svgSize') &&
canvasHtml.includes('naturalWidth') &&
canvasHtml.includes('naturalHeight') &&
canvasHtml.includes('const fitScalePercent = clampLayoutScale(Math.floor') &&
canvasHtml.includes('layoutScale ?? fitScalePercent') &&
canvasHtml.includes('const stageWidth = baseWidth * normalizedScale / 100') &&
!canvasHtml.includes('useState(100)') &&
!canvasHtml.includes('baseWidth * fitScale * normalizedScale / 100'),
'layout preview should default to the actual fitted SVG scale percent instead of redefining 100% as fit'
);
assert(
canvasHtml.includes('className="build-gds-btn"'),
@@ -354,7 +354,7 @@ assert(
canvasHtml.includes('layoutBounds') &&
canvasHtml.includes('stageWidth') &&
canvasHtml.includes('stageHeight'),
'layout preview should mouse-wheel zoom and size 100% from calculated box_size layout bounds'
'layout preview should mouse-wheel zoom from the actual calculated SVG scale'
);
assert(
canvasHtml.includes('reactFlowInstance.fitBounds') &&
+12
View File
@@ -47,3 +47,15 @@ assert(
canvasHtml.includes('Array.from(new Set([FORGE_COMPONENT_LABEL, ...sameCategoryComponents'),
'loaded PDK selector choices should include forge and same-category library components'
);
assert(
canvasHtml.includes('Object.entries(doc.bundles || {})'),
'project and YAML loading should iterate all saved bundle groups, not only output_bus'
);
assert(
!canvasHtml.includes('doc.bundles?.output_bus?.links'),
'project and YAML loading should not hardcode bundles.output_bus.links'
);
assert(
canvasHtml.includes('bundle_group: bundleName'),
'loaded route metadata should remember the YAML bundle key as route.bundle_group'
);
+54
View File
@@ -0,0 +1,54 @@
/*
* Description: Static regression tests for resilient project save/reopen behavior.
* Inside functions: N/A - assertion-based test/module script.
* Developer : Qin Yue @ 2026
* Organization : OptiHK Limited
*/
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const root = path.resolve(__dirname, '..');
const backend = path.join(root, 'backend');
const layoutFilesPath = path.join(backend, 'layout_files.py');
const layoutFilesPy = fs.readFileSync(layoutFilesPath, 'utf8');
const serverPy = fs.readFileSync(path.join(backend, 'server.py'), 'utf8');
const gdsBuilderPy = fs.readFileSync(path.join(backend, 'gds_builder.py'), 'utf8');
const routedPreviewPy = fs.readFileSync(path.join(backend, 'routed_layout_preview.py'), 'utf8');
const canvasHtml = fs.readFileSync(path.join(root, 'frontend', 'canvas.html'), 'utf8');
assert(
fs.existsSync(layoutFilesPath),
'backend/layout_files.py should centralize saved layout YAML filtering and parsing'
);
assert(
layoutFilesPy.includes('ROUTE_SIDECAR_SUFFIXES') &&
layoutFilesPy.includes('def is_layout_cell_filename') &&
layoutFilesPy.includes('def parse_layout_cell_content') &&
layoutFilesPy.includes('def load_layout_cell_files'),
'layout file helpers should exclude route sidecars and validate saved layout cells'
);
assert(
serverPy.includes('is_layout_cell_filename') &&
serverPy.includes('load_layout_cell_files(root)') &&
serverPy.includes('parse_layout_cell_content(content') &&
serverPy.includes('except LayoutFileError as e'),
'project list/load/save endpoints should filter invalid YAML and reject malformed saves'
);
assert(
gdsBuilderPy.includes('TemporaryDirectory(prefix="mxpic_gds_project_"') &&
gdsBuilderPy.includes('write_layout_cells_to_directory(cells, staged_project_dir)'),
'Build GDS should call mxpic_router with a clean staged project directory'
);
assert(
routedPreviewPy.includes('staged_project_dir') &&
routedPreviewPy.includes('write_layout_cells_to_directory(staged_cells, staged_project_dir)') &&
routedPreviewPy.includes('project_dir=staged_project_dir'),
'Build Layout preview should stage valid cells before calling mxpic_router'
);
assert(
canvasHtml.includes('(data.warnings || []).forEach(warning => addLog(warning))') &&
canvasHtml.includes('const parsedCellPages = [];') &&
canvasHtml.includes('Skipped saved cell'),
'canvas project loading should report skipped files and keep loading remaining valid cells'
);
+24 -1
View File
@@ -8,4 +8,27 @@
4.Fixed the abnormal port shift after rotation.
5.Fixed the abnormal position of individual ports.
5.Fixed the abnormal position of individual ports.
06/15
Enhanced the contrast between the inside and outside of the canvas border.
Capped the maximum amount by which the canvas can be scaled down (set a minimum canvas size limit).
Labels/tags, once closed, will no longer be reloaded after a page refresh.
Modified the "select origin" functionality and set the default origin to the canvas position (500, 500).
Fixed a bug where the instance name counter was shared across different canvases within the same project.
06/16
Fixed a bug where component icons would not load when importing a YML file.
Added origin coordinates to the YML file; fixed a bug that caused component misalignment when opening a YML file with a different origin.
Fixed a bug where the default port would reload on every page refresh.