Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion docs/tools.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tools Reference

EasyEDA Pro MCP exposes **74 tools** across 8 categories. All inspection, tracing, navigation, and export tools are read-only (`readOnlyHint: true`).
EasyEDA Pro MCP exposes **76 tools** across 9 categories. All inspection, tracing, navigation, and export tools are read-only (`readOnlyHint: true`).

## Tool Catalog

Expand All @@ -18,6 +18,8 @@ EasyEDA Pro MCP exposes **74 tools** across 8 categories. All inspection, tracin
- [`easyeda_run_drc`](#easyeda_run_drc) · [`easyeda_get_pcb_layers`](#easyeda_get_pcb_layers) · [`easyeda_get_routing_status`](#easyeda_get_routing_status) · [`easyeda_list_pcb_components`](#easyeda_list_pcb_components) · [`easyeda_get_pcb_pads`](#easyeda_get_pcb_pads) · [`easyeda_prepare_pcb_component`](#easyeda_prepare_pcb_component) · [`easyeda_get_board_outline`](#easyeda_get_board_outline) · [`easyeda_prepare_board_outline`](#easyeda_prepare_board_outline) · [`easyeda_prepare_pcb_routing`](#easyeda_prepare_pcb_routing) · [`easyeda_prepare_pcb_layout`](#easyeda_prepare_pcb_layout) · [`easyeda_get_pcb_tracks`](#easyeda_get_pcb_tracks) · [`easyeda_get_pcb_vias`](#easyeda_get_pcb_vias) · [`easyeda_prepare_pcb_track_via`](#easyeda_prepare_pcb_track_via) · [`easyeda_highlight_net`](#easyeda_highlight_net) · [`easyeda_get_copper_zones`](#easyeda_get_copper_zones) · [`easyeda_get_keepouts`](#easyeda_get_keepouts) · [`easyeda_prepare_copper_keepout`](#easyeda_prepare_copper_keepout) · [`easyeda_get_pcb_airwires`](#easyeda_get_pcb_airwires) · [`easyeda_get_pcb_placement_report`](#easyeda_get_pcb_placement_report) · [`easyeda_get_pcb_net_report`](#easyeda_get_pcb_net_report) · [`easyeda_get_pcb_net_classes`](#easyeda_get_pcb_net_classes) · [`easyeda_get_pcb_differential_pairs`](#easyeda_get_pcb_differential_pairs) · [`easyeda_get_pcb_length_groups`](#easyeda_get_pcb_length_groups) · [`easyeda_prepare_pcb_net_constraint`](#easyeda_prepare_pcb_net_constraint) · [`easyeda_get_pcb_3d_inspection`](#easyeda_get_pcb_3d_inspection) · [`easyeda_get_pcb_3d_view`](#easyeda_get_pcb_3d_view) · [`easyeda_prepare_pcb_external_import`](#easyeda_prepare_pcb_external_import) · [`easyeda_get_drc_rules`](#easyeda_get_drc_rules) · [`easyeda_prepare_drc_edit`](#easyeda_prepare_drc_edit) · [`easyeda_get_drc_edit_result`](#easyeda_get_drc_edit_result)
- **[Libraries, Navigation & Exports](#navigation-exports)** (15 tools)
- [`easyeda_export_cpl`](#easyeda_export_cpl) · [`easyeda_export_bom`](#easyeda_export_bom) · [`easyeda_export_netlist`](#easyeda_export_netlist) · [`easyeda_export_gerber`](#easyeda_export_gerber) · [`easyeda_export_pdf`](#easyeda_export_pdf) · [`easyeda_export_image`](#easyeda_export_image) · [`easyeda_export_3d_model`](#easyeda_export_3d_model) · [`easyeda_export_project_archive`](#easyeda_export_project_archive) · [`easyeda_export_dxf`](#easyeda_export_dxf) · [`easyeda_navigate_component`](#easyeda_navigate_component) · [`easyeda_navigate_region`](#easyeda_navigate_region) · [`easyeda_zoom_board`](#easyeda_zoom_board) · [`easyeda_get_device_details`](#easyeda_get_device_details) · [`easyeda_compare_devices`](#easyeda_compare_devices) · [`easyeda_verify_pin_pad_mapping`](#easyeda_verify_pin_pad_mapping)
- **[SPICE Simulation Feasibility](#spice-simulation-feasibility)** (2 tools)
- [`easyeda_evaluate_spice_support`](#easyeda_evaluate_spice_support) · [`easyeda_generate_spice_netlist`](#easyeda_generate_spice_netlist)
- **[Confirmation-Gated Actions](#confirmation-gated-actions)** (1 tool)
- [`easyeda_confirmed_action`](#easyeda_confirmed_action)

Expand Down Expand Up @@ -1290,6 +1292,40 @@ Validates 1-to-1 correspondence between schematic symbol pins and PCB footprint

---

## SPICE Simulation Feasibility

### `easyeda_evaluate_spice_support`

**Scope:** Schematic Analysis RPC (`readOnlyHint: true`, default timeout: `30000` ms)

Performs a feasibility study of analog circuit SPICE simulation on the active schematic. Inspects placed components, verifies Node 0 / Ground datum connectivity, checks for power/stimulus sources, audits SPICE model availability, calculates a simulation readiness score (`0`–`100%`), and documents platform constraints and limitations.

**Parameters:**
- **`groundNet`** (`string`, _optional_, default: `"GND"`): Net name expected as ground datum (mapped to SPICE node 0).
- **`target`** (`object`, _optional_): Expected document target specification.
- **`timeoutMs`** (`number`, _optional_, default: `30000`): RPC timeout in ms.

---

### `easyeda_generate_spice_netlist`

**Scope:** Netlist Export RPC (`readOnlyHint: true`, default timeout: `30000` ms)

Generates a syntactically valid SPICE circuit netlist (`.cir` / `.sp`) from the active schematic with ground-to-0 normalization, primitive RLC elements, built-in semiconductor models, and configurable simulation directives (`.op`, `.tran`, `.ac`, `.dc`) for execution in external engines (ngspice, LTspice, Xyce).

**Parameters:**
- **`analysisType`** (`"op" | "tran" | "ac" | "dc"`, _optional_, default: `"op"`): Simulation analysis type directive.
- **`analysisParams`** (`string`, _optional_): Directive parameters (e.g., `"1u 10m"` for `.tran`, or `"10 1 1Meg"` for `.ac`).
- **`groundNet`** (`string`, _optional_, default: `"GND"`): Net name to map to SPICE datum node 0.
- **`includeSubcircuits`** (`boolean`, _optional_, default: `true`): Whether to include X subcircuit cards for ICs.
- **`includeDefaultModels`** (`boolean`, _optional_, default: `true`): Include built-in generic diode and BJT `.model` definitions.
- **`fileName`** (`string`, _optional_): Optional output file name without extension.
- **`destinationPath`** (`string`, _optional_): Optional destination directory or output file path.
- **`target`** (`object`, _optional_): Expected document target specification.
- **`timeoutMs`** (`number`, _optional_, default: `30000`): RPC timeout in ms.

---

## Confirmation-Gated Actions

### `easyeda_confirmed_action`
Expand Down
4 changes: 4 additions & 0 deletions extension/src/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ export function detectMethodCapabilities(api: () => EasyEdaApi): Record<string,
),
"sch_Drc.check": Boolean(eda.sch_Drc?.check),
"sch_Netlist.getNetlist": Boolean(eda.sch_Netlist?.getNetlist),
"sch_Sim.check": Boolean((eda as any).sch_Sim?.check || (eda as any).sim_Document?.run),
"sch_Netlist.getSpiceNetlist": Boolean(
(eda as any).sch_Netlist?.getSpiceNetlist || (eda as any).sch_Netlist?.getNetlist
),

// Libraries & System
"lib_Device.search": Boolean(eda.lib_Device?.search || eda.lib_Search?.search),
Expand Down
3 changes: 3 additions & 0 deletions extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { prepareSchematicComponentMutation } from "./mutation/schematicComponent
import { compareSchematicPcb, prepareSchematicPcbSyncMutation } from "./mutation/schematicPcbSyncMutations.js";
import { prepareSchematicBusMutation, prepareSchematicPortMutation } from "./mutation/schematicPortBusMutations.js";
import { prepareSchematicWireMutation } from "./mutation/schematicWireMutations.js";
import { evaluateSpiceFeasibility, generateSpiceNetlist } from "./reporting/spiceFeasibilityReport.js";
import type { EasyEdaApi, RpcHandler } from "./types.js";

const getApi = (): EasyEdaApi => (typeof eda !== "undefined" ? eda : (globalThis as any).eda);
Expand Down Expand Up @@ -61,6 +62,8 @@ const handlers: Record<string, RpcHandler> = {
prepareSchematicBus: (params) => prepareSchematicBusMutation(getApi, params),
prepareSchematicPcbSync: (params) => prepareSchematicPcbSyncMutation(getApi, params),
compareSchematicPcb: (params) => compareSchematicPcb(getApi, params),
evaluateSpiceFeasibility: (params) => evaluateSpiceFeasibility(getApi, params),
generateSpiceNetlist: (params) => generateSpiceNetlist(getApi, exportHandlers.saveApiFile as any, params),
...contextHandlers,
...documentHandlers,
...schematicHandlers,
Expand Down
157 changes: 157 additions & 0 deletions extension/src/reporting/spiceFeasibilityReport.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import { describe, expect, it, vi } from "vitest";
import { classifyComponentForSpice, evaluateSpiceFeasibility, generateSpiceNetlist } from "./spiceFeasibilityReport.js";

describe("spiceFeasibilityReport", () => {
describe("classifyComponentForSpice", () => {
it("classifies passive resistors, capacitors and inductors as intrinsic primitives", () => {
const res = classifyComponentForSpice({ designator: "R1", value: "10k" }, [{ net: "VCC" }, { net: "NET1" }]);
expect(res.spiceCategory).toBe("primitive_r");
expect(res.hasModel).toBe(true);
expect(res.modelSource).toBe("intrinsic");
expect(res.parameters.value).toBe("10k");

const cap = classifyComponentForSpice({ designator: "C2", value: "100n" }, [{ net: "NET1" }, { net: "GND" }]);
expect(cap.spiceCategory).toBe("primitive_c");
expect(cap.hasModel).toBe(true);

const ind = classifyComponentForSpice({ designator: "L1", value: "22u" }, [{ net: "VIN" }, { net: "SW" }]);
expect(ind.spiceCategory).toBe("primitive_l");
expect(ind.hasModel).toBe(true);
});

it("classifies diodes, transistors and voltage sources", () => {
const diode = classifyComponentForSpice({ designator: "D1", value: "1N4148" }, [{ net: "IN" }, { net: "OUT" }]);
expect(diode.spiceCategory).toBe("primitive_diode");
expect(diode.hasModel).toBe(true);

const bjt = classifyComponentForSpice({ designator: "Q1", value: "2N2222" }, [
{ net: "C" },
{ net: "B" },
{ net: "E" }
]);
expect(bjt.spiceCategory).toBe("primitive_transistor");
expect(bjt.hasModel).toBe(true);

const vsrc = classifyComponentForSpice({ designator: "V1", value: "5V" }, [{ net: "VCC" }, { net: "GND" }]);
expect(vsrc.spiceCategory).toBe("source_voltage");
expect(vsrc.hasModel).toBe(true);
expect(vsrc.parameters.dc).toBe("5V");
});

it("flags ICs without models as needs_model and connectors as non_electrical", () => {
const ic = classifyComponentForSpice({ designator: "U1", title: "STM32F103" }, []);
expect(ic.spiceCategory).toBe("subcircuit");
expect(ic.hasModel).toBe(false);
expect(ic.modelSource).toBe("missing");
expect(ic.warnings.length).toBeGreaterThan(0);

const conn = classifyComponentForSpice({ designator: "J1", title: "Header_1x4" }, []);
expect(conn.spiceCategory).toBe("non_electrical");
expect(conn.hasModel).toBe(false);
expect(conn.modelSource).toBe("none");
});
});

describe("evaluateSpiceFeasibility", () => {
it("reports simulation_ready for a complete circuit with passives, source and GND", async () => {
const api = () => ({
dmt_SelectControl: {
getCurrentDocumentInfo: () => ({ title: "RC_Filter.Schematic", documentType: 1 })
},
sch_PrimitiveComponent: {
getAll: vi.fn(async () => [
{ primitiveId: "p1", designator: "V1", value: "5V" },
{ primitiveId: "p2", designator: "R1", value: "1k" },
{ primitiveId: "p3", designator: "C1", value: "100n" }
]),
getAllPinsByPrimitiveId: vi.fn(async (id: string) => {
if (id === "p1") return [{ net: "VIN" }, { net: "GND" }];
if (id === "p2") return [{ net: "VIN" }, { net: "VOUT" }];
return [{ net: "VOUT" }, { net: "GND" }];
})
},
sch_Net: {
getAllNetsName: vi.fn(async () => ["VIN", "VOUT", "GND"])
}
});

const report = await evaluateSpiceFeasibility(api as any);
expect(report.feasibilityScorePercent).toBe(100);
expect(report.isSimulatable).toBe(true);
expect(report.verdict).toBe("simulation_ready");
expect(report.groundReference.detected).toBe(true);
expect(report.groundReference.netName).toBe("GND");
expect(report.stimulusSources.hasStimulus).toBe(true);
expect(report.stimulusSources.count).toBe(1);
expect(report.platformLimitations.length).toBeGreaterThan(0);
});

it("penalizes score and warns when ground reference is missing", async () => {
const api = () => ({
dmt_SelectControl: {
getCurrentDocumentInfo: () => ({ title: "NoGround.Schematic", documentType: 1 })
},
sch_PrimitiveComponent: {
getAll: vi.fn(async () => [
{ primitiveId: "p1", designator: "V1", value: "5V" },
{ primitiveId: "p2", designator: "R1", value: "1k" }
]),
getAllPinsByPrimitiveId: vi.fn(async (id: string) => {
if (id === "p1") return [{ net: "NET1" }, { net: "NET2" }];
return [{ net: "NET1" }, { net: "NET2" }];
})
},
sch_Net: {
getAllNetsName: vi.fn(async () => ["NET1", "NET2"])
}
});

const report = await evaluateSpiceFeasibility(api as any);
expect(report.groundReference.detected).toBe(false);
expect(report.feasibilityScorePercent).toBeLessThan(80);
expect(report.recommendations.some((r) => r.includes("CRITICAL: Add a ground reference"))).toBe(true);
});
});

describe("generateSpiceNetlist", () => {
it("generates valid SPICE netlist syntax with .tran analysis and ground mapped to node 0", async () => {
const api = () => ({
dmt_SelectControl: {
getCurrentDocumentInfo: () => ({ title: "VoltageDivider.Schematic" })
},
sch_PrimitiveComponent: {
getAll: vi.fn(async () => [
{ primitiveId: "c1", designator: "V1", value: "12V" },
{ primitiveId: "c2", designator: "R1", value: "10k" },
{ primitiveId: "c3", designator: "R2", value: "2.2k" },
{ primitiveId: "c4", designator: "D1", value: "1N4148" }
]),
getAllPinsByPrimitiveId: vi.fn(async (id: string) => {
if (id === "c1") return [{ net: "VCC" }, { net: "GND" }];
if (id === "c2") return [{ net: "VCC" }, { net: "MID" }];
if (id === "c3") return [{ net: "MID" }, { net: "GND" }];
return [{ net: "MID" }, { net: "GND" }];
})
}
});

const res = await generateSpiceNetlist(api as any, undefined, {
analysisType: "tran",
analysisParams: "10u 5ms",
groundNet: "GND"
});

expect(res.analysisType).toBe("tran");
expect(res.directive).toBe(".tran 10u 5ms");
expect(res.elementsCount).toBe(4);
expect(res.nodes).toContain("0");
expect(res.netlist).toContain("V1 VCC 0 DC 12V");
expect(res.netlist).toContain("R1 VCC MID 10k");
expect(res.netlist).toContain("R2 MID 0 2.2k");
expect(res.netlist).toContain("D1 MID 0 D_1N4148");
expect(res.netlist).toContain(".model D_GENERIC");
expect(res.netlist).toContain(".end");
expect(res.validation).toMatchObject({ valid: true });
});
});
});
Loading
Loading