feat(wasm): kicad_editor — merge the pcbnew+eeschema kifaces into ONE bundle (Part 2)
All four editors (PCB / Footprint / Schematic / Symbol) are now runtime --frame
choices of a single kicad_editor.wasm (178 MB at -O1 vs 147+82 separate; shared
wx/common/boost linked once). One editor per page load, as before; frames pcb /
fpedit / sch / symedit.
- wasm/editor/: the merged executable target (single_top + both kiface library sets,
whole-archive pcbcommon) + the safety-net focus-walk Kiface() dispatch TU. Gated by
KICAD_WASM_MERGED_EDITOR (kicad submodule bump carries the fork side: per-engine
Kiface/getter binding + ODR renames + dual-kiface launcher).
- wasm/bindings/: per-editor collab entries renamed pcbCollab*/schCollab* (JS names
unchanged); duplicate kicadOpenFile/kicadCollabOnSave + shared-name registrations
guarded behind KICAD_MERGED_EMBIND; new kicad_editor_embind.cpp registers each
shared JS name once, dispatching on the live frame.
- Build: kicad_editor app (build wrapper, target case arms, 3-object embind compile
with the ABI-critical flags, STUB_APP=pcbnew); docker/build.sh "all" =
kicad_editor calculator pl_editor gerbview (pcbnew/eeschema stay as explicit debug
apps); scripts/kicad/audit-merged-symbols.sh = repeatable ODR-collision audit (run
on kicad bumps).
- Frontend: Bundle type (bundle ≠ tool); TOOL_BUNDLE maps all four editors to
kicad_editor; explicit --frame tokens for pcbnew (pcb) and eeschema (sch); publish
list = the 4 real bundles.
- Tests/CI: five harnesses load kicad_editor.js with explicit frame tokens;
PCBNEW_FAMILY_SPECS renamed BIG_MODULE_SPECS + the 8 eeschema-family specs (they
now boot the merged module — SpiderMonkey x86 CI OOM routing); frame-runtime spec
covers all four frames from the one bundle.
Validated so far: frame-runtime 4/4 (each frame boots with the right title, no
aborts, no duplicate embind registration); 24-spec merged-module regression green;
3D raytracer renders. Known pre-existing failure: 3d-viewer title-bar drag deadlock,
fixed on main by 7630c7e (2N+8 pthread pre-warm) — picked up by the follow-up rebase.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
c6716e6b60
commit
bbeef6d20e
23 changed files with 691 additions and 149 deletions
|
|
@ -54,6 +54,13 @@ using json = nlohmann::json;
|
|||
// frame is the app's top window and is a KIWAY_PLAYER. Returns the result of
|
||||
// OpenProjectFiles, or false if no frame is available — letting the JS caller
|
||||
// fall back to driving File→Open.
|
||||
//
|
||||
// KICAD_MERGED_EMBIND (kicad_editor, editor-unification Part 2): pcbnew_embind.cpp
|
||||
// defines the identical function and registers the same JS names — in the merged image
|
||||
// the frame-agnostic duplicates (this + kicadCollabOnSave) and the shared-name
|
||||
// registrations live once in kicad_editor_embind.cpp, which dispatches the per-editor
|
||||
// entries (renamed schCollab*/pcbCollab* below; JS-facing names are unchanged).
|
||||
#ifndef KICAD_MERGED_EMBIND
|
||||
bool kicadOpenFile( std::string path )
|
||||
{
|
||||
KIWAY_PLAYER* frame =
|
||||
|
|
@ -68,6 +75,7 @@ bool kicadOpenFile( std::string path )
|
|||
return frame->OpenProjectFiles(
|
||||
std::vector<wxString>( 1, wxString::FromUTF8( path.c_str() ) ) );
|
||||
}
|
||||
#endif // !KICAD_MERGED_EMBIND
|
||||
|
||||
// ───────────────────────────── Yjs collaborative bridge ─────────────────────────────
|
||||
//
|
||||
|
|
@ -863,7 +871,7 @@ void collabTestMove( SCH_EDIT_FRAME* aFrame, SCH_ITEM* aItem, SCH_SCREEN* aScree
|
|||
// wxEvtHandler::CallAfter queues onto the app's pending-event list, which the wasm main
|
||||
// loop drains every frame via ProcessPendingEvents() (src/wasm/evtloop.cpp) — i.e. the
|
||||
// exact context real UI edits run in. So defer the whole mutation there.
|
||||
void kicadCollabApply( std::string aJson )
|
||||
void schCollabApply( std::string aJson )
|
||||
{
|
||||
json delta = json::parse( aJson, nullptr, /*allow_exceptions*/ false );
|
||||
|
||||
|
|
@ -896,7 +904,7 @@ void kicadCollabApply( std::string aJson )
|
|||
|
||||
// JS pull of the full current model as an all-"added" delta (seed/baseline). Also
|
||||
// registers the change listener on first call.
|
||||
std::string kicadCollabSnapshot()
|
||||
std::string schCollabSnapshot()
|
||||
{
|
||||
ensureBridge();
|
||||
json added = snapshotItems( schFrame() );
|
||||
|
|
@ -912,7 +920,7 @@ std::string kicadCollabSnapshot()
|
|||
|
||||
// JS → C++, v2 items wire. Same CallAfter + COROUTINE context as kicadCollabApply
|
||||
// (LoadContent + SCH_COMMIT must run where native edits run).
|
||||
void kicadCollabApplyItems( std::string aJson )
|
||||
void schCollabApplyItems( std::string aJson )
|
||||
{
|
||||
json wire = json::parse( aJson, nullptr, /*allow_exceptions*/ false );
|
||||
|
||||
|
|
@ -938,7 +946,7 @@ void kicadCollabApplyItems( std::string aJson )
|
|||
// JS pull of the ACTIVE screen's model as an all-"added" v2 items wire: one clipboard-
|
||||
// style blob per item on the current sheet (one collab room == one .kicad_sch screen).
|
||||
// Registers the listener + rebaselines exactly like kicadCollabSnapshot.
|
||||
std::string kicadCollabSnapshotItems()
|
||||
std::string schCollabSnapshotItems()
|
||||
{
|
||||
SCH_EDIT_FRAME* fr = schFrame();
|
||||
|
||||
|
|
@ -965,7 +973,7 @@ std::string kicadCollabSnapshotItems()
|
|||
// Test/PoC helper: move the first schematic item by (dx,dy) IU via a real SCH_COMMIT,
|
||||
// firing the listener — a deterministic local edit for the two-tab demo / e2e.
|
||||
// Returns the moved item's uuid.
|
||||
std::string kicadCollabTestMoveFirst( int aDx, int aDy )
|
||||
std::string schCollabTestMoveFirst( int aDx, int aDy )
|
||||
{
|
||||
SCH_EDIT_FRAME* fr = schFrame();
|
||||
|
||||
|
|
@ -993,7 +1001,7 @@ std::string kicadCollabTestMoveFirst( int aDx, int aDy )
|
|||
|
||||
|
||||
// Test helper: read an item's position by uuid as "x,y" (internal units).
|
||||
std::string kicadCollabGetPos( std::string aId )
|
||||
std::string schCollabGetPos( std::string aId )
|
||||
{
|
||||
SCH_EDIT_FRAME* fr = schFrame();
|
||||
|
||||
|
|
@ -1022,6 +1030,9 @@ std::string kicadCollabGetPos( std::string aId )
|
|||
// kicad fork's save chokepoint (SCH_EDIT_FRAME::saveSchematicFile) after a
|
||||
// successful write to MEMFS, so the web app can route the saved bytes onward
|
||||
// (API upload, local-disk write-back, download). No-op without a JS listener.
|
||||
// KICAD_MERGED_EMBIND: identical definition in pcbnew_embind.cpp; the merged image
|
||||
// gets the one in kicad_editor_embind.cpp (both fork save chokepoints call it).
|
||||
#ifndef KICAD_MERGED_EMBIND
|
||||
extern "C" void kicadCollabOnSave( const char* aPath )
|
||||
{
|
||||
EM_ASM( {
|
||||
|
|
@ -1029,6 +1040,14 @@ extern "C" void kicadCollabOnSave( const char* aPath )
|
|||
window.kicadCollab.onSave( UTF8ToString( $0 ) );
|
||||
}, aPath );
|
||||
}
|
||||
#endif // !KICAD_MERGED_EMBIND
|
||||
|
||||
// Merged-image dispatch probe (kicad_editor_embind.cpp): is the active top window the
|
||||
// schematic editor? Counterpart of pcbnew_embind.cpp's pcbEditorActive().
|
||||
bool schEditorActive()
|
||||
{
|
||||
return schFrame() != nullptr;
|
||||
}
|
||||
|
||||
|
||||
void kicadSaveSchematic( std::string path )
|
||||
|
|
@ -1064,17 +1083,22 @@ void kicadSaveSchematic( std::string path )
|
|||
|
||||
|
||||
EMSCRIPTEN_BINDINGS(eeschema) {
|
||||
// Programmatic file open (preferred over UI automation from the web app).
|
||||
function("kicadOpenFile", &kicadOpenFile);
|
||||
// Programmatic save of the in-memory schematic (round-trip tests, README §A).
|
||||
function("kicadSaveSchematic", &kicadSaveSchematic);
|
||||
|
||||
#ifndef KICAD_MERGED_EMBIND
|
||||
// JS names ALSO registered by pcbnew_embind.cpp — in the merged image these are
|
||||
// registered once by kicad_editor_embind.cpp, dispatching on the active frame.
|
||||
// Programmatic file open (preferred over UI automation from the web app).
|
||||
function("kicadOpenFile", &kicadOpenFile);
|
||||
// Yjs collaborative bridge entry points (same contract as pl_editor).
|
||||
function("kicadCollabApply", &kicadCollabApply);
|
||||
function("kicadCollabSnapshot", &kicadCollabSnapshot);
|
||||
function("kicadCollabApply", &schCollabApply);
|
||||
function("kicadCollabSnapshot", &schCollabSnapshot);
|
||||
// v2 items bridge: per-item s-expr payloads (ysync 0008).
|
||||
function("kicadCollabApplyItems", &kicadCollabApplyItems);
|
||||
function("kicadCollabSnapshotItems", &kicadCollabSnapshotItems);
|
||||
function("kicadCollabTestMoveFirst", &kicadCollabTestMoveFirst);
|
||||
function("kicadCollabGetPos", &kicadCollabGetPos);
|
||||
function("kicadCollabApplyItems", &schCollabApplyItems);
|
||||
function("kicadCollabSnapshotItems", &schCollabSnapshotItems);
|
||||
function("kicadCollabTestMoveFirst", &schCollabTestMoveFirst);
|
||||
function("kicadCollabGetPos", &schCollabGetPos);
|
||||
#endif // !KICAD_MERGED_EMBIND
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
136
wasm/bindings/kicad_editor_embind.cpp
Normal file
136
wasm/bindings/kicad_editor_embind.cpp
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* Embind dispatcher for the merged kicad_editor WASM image (editor-unification Part 2).
|
||||
*
|
||||
* The pcbnew and eeschema binding TUs each implement the collab bridge for their own
|
||||
* frame and, standalone, register the SAME JS-facing names. In the merged image both
|
||||
* TUs are compiled with -DKICAD_MERGED_EMBIND, which
|
||||
* - compiles out their duplicate frame-agnostic definitions (kicadOpenFile,
|
||||
* extern "C" kicadCollabOnSave) — the single definitions live HERE, and
|
||||
* - compiles out their shared-name EMSCRIPTEN_BINDINGS registrations — registered
|
||||
* once HERE, dispatching to the renamed per-editor entries (pcbCollab… and
|
||||
* schCollab…) on whichever editor frame is live. Per-editor unique names
|
||||
* (kicadSaveBoard, kicadSaveSchematic, kicadCollabTestItemBlob, Board_…) keep
|
||||
* flowing from the per-editor blocks unchanged.
|
||||
*
|
||||
* With the one-frame-per-page-load model exactly one of pcbEditorActive() /
|
||||
* schEditorActive() is true — the same dynamic_cast probe every per-editor entry
|
||||
* already starts with. JS-facing names and signatures are IDENTICAL to the standalone
|
||||
* bundles, so the web app and tests need no per-bundle API differences.
|
||||
*
|
||||
* Deliberately header-light: no pcbnew/eeschema headers (avoids mixing both include
|
||||
* roots in one TU); only the generic KIWAY_PLAYER surface + the extern declarations.
|
||||
*/
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#include <emscripten/bind.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <wx/app.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/window.h>
|
||||
#include <kiway.h>
|
||||
#include <kiway_player.h>
|
||||
|
||||
using namespace emscripten;
|
||||
|
||||
// Per-editor entry points and frame probes — defined (with external linkage) in
|
||||
// pcbnew_embind.cpp / eeschema_embind.cpp.
|
||||
bool pcbEditorActive();
|
||||
void pcbCollabApply( std::string aJson );
|
||||
void pcbCollabApplyItems( std::string aJson );
|
||||
std::string pcbCollabSnapshot();
|
||||
std::string pcbCollabSnapshotItems();
|
||||
std::string pcbCollabTestMoveFirst( int aDx, int aDy );
|
||||
std::string pcbCollabGetPos( std::string aId );
|
||||
|
||||
bool schEditorActive();
|
||||
void schCollabApply( std::string aJson );
|
||||
void schCollabApplyItems( std::string aJson );
|
||||
std::string schCollabSnapshot();
|
||||
std::string schCollabSnapshotItems();
|
||||
std::string schCollabTestMoveFirst( int aDx, int aDy );
|
||||
std::string schCollabGetPos( std::string aId );
|
||||
|
||||
|
||||
// Programmatically open a project file in the running editor frame, without UI
|
||||
// automation. Frame-agnostic (any KIWAY_PLAYER); byte-identical to the definition the
|
||||
// standalone bundles compile from their own binding TU.
|
||||
static bool kicadOpenFile( std::string path )
|
||||
{
|
||||
KIWAY_PLAYER* frame =
|
||||
wxTheApp ? static_cast<KIWAY_PLAYER*>( wxTheApp->GetTopWindow() ) : nullptr;
|
||||
|
||||
if( !frame )
|
||||
return false;
|
||||
|
||||
if( wxWindow* blocking = frame->Kiway().GetBlockingDialog() )
|
||||
blocking->Close( true );
|
||||
|
||||
return frame->OpenProjectFiles(
|
||||
std::vector<wxString>( 1, wxString::FromUTF8( path.c_str() ) ) );
|
||||
}
|
||||
|
||||
|
||||
// C++ → JS save notification. Called from BOTH fork save chokepoints
|
||||
// (PCB_EDIT_FRAME::SavePcbFile and SCH_EDIT_FRAME::saveSchematicFile) — one shared
|
||||
// definition serves the merged image. No-op without a JS listener.
|
||||
extern "C" void kicadCollabOnSave( const char* aPath )
|
||||
{
|
||||
EM_ASM( {
|
||||
if( window.kicadCollab && window.kicadCollab.onSave )
|
||||
window.kicadCollab.onSave( UTF8ToString( $0 ) );
|
||||
}, aPath );
|
||||
}
|
||||
|
||||
|
||||
// Dispatch shims: route each shared JS name to the live editor's implementation.
|
||||
// The sch path is the fallback arm so a JS call with NO frame up behaves like the
|
||||
// standalone bundles (the per-editor impls no-op / return empty on a null frame).
|
||||
static void collabApply( std::string aJson )
|
||||
{
|
||||
pcbEditorActive() ? pcbCollabApply( aJson ) : schCollabApply( aJson );
|
||||
}
|
||||
|
||||
static void collabApplyItems( std::string aJson )
|
||||
{
|
||||
pcbEditorActive() ? pcbCollabApplyItems( aJson ) : schCollabApplyItems( aJson );
|
||||
}
|
||||
|
||||
static std::string collabSnapshot()
|
||||
{
|
||||
return pcbEditorActive() ? pcbCollabSnapshot() : schCollabSnapshot();
|
||||
}
|
||||
|
||||
static std::string collabSnapshotItems()
|
||||
{
|
||||
return pcbEditorActive() ? pcbCollabSnapshotItems() : schCollabSnapshotItems();
|
||||
}
|
||||
|
||||
static std::string collabTestMoveFirst( int aDx, int aDy )
|
||||
{
|
||||
return pcbEditorActive() ? pcbCollabTestMoveFirst( aDx, aDy )
|
||||
: schCollabTestMoveFirst( aDx, aDy );
|
||||
}
|
||||
|
||||
static std::string collabGetPos( std::string aId )
|
||||
{
|
||||
return pcbEditorActive() ? pcbCollabGetPos( aId ) : schCollabGetPos( aId );
|
||||
}
|
||||
|
||||
|
||||
EMSCRIPTEN_BINDINGS(kicad_editor) {
|
||||
// Programmatic file open (preferred over UI automation from the web app).
|
||||
function("kicadOpenFile", &kicadOpenFile);
|
||||
|
||||
// Yjs collaborative bridge entry points — same JS contract as the standalone
|
||||
// bundles, dispatched on the active editor frame.
|
||||
function("kicadCollabApply", &collabApply);
|
||||
function("kicadCollabSnapshot", &collabSnapshot);
|
||||
function("kicadCollabApplyItems", &collabApplyItems);
|
||||
function("kicadCollabSnapshotItems", &collabSnapshotItems);
|
||||
function("kicadCollabTestMoveFirst", &collabTestMoveFirst);
|
||||
function("kicadCollabGetPos", &collabGetPos);
|
||||
}
|
||||
|
||||
#endif // __EMSCRIPTEN__
|
||||
|
|
@ -55,6 +55,13 @@ using json = nlohmann::json;
|
|||
// the editor frame is the app's top window and is a KIWAY_PLAYER. Returns the
|
||||
// result of OpenProjectFiles, or false if no frame is available — letting the
|
||||
// JS caller fall back to driving File→Open.
|
||||
//
|
||||
// KICAD_MERGED_EMBIND (kicad_editor, editor-unification Part 2): eeschema_embind.cpp
|
||||
// defines the identical function and registers the same JS names — in the merged image
|
||||
// the frame-agnostic duplicates (this + kicadCollabOnSave) and the shared-name
|
||||
// registrations live once in kicad_editor_embind.cpp, which dispatches the per-editor
|
||||
// entries (renamed pcbCollab*/schCollab* below; JS-facing names are unchanged).
|
||||
#ifndef KICAD_MERGED_EMBIND
|
||||
bool kicadOpenFile( std::string path )
|
||||
{
|
||||
KIWAY_PLAYER* frame =
|
||||
|
|
@ -69,6 +76,7 @@ bool kicadOpenFile( std::string path )
|
|||
return frame->OpenProjectFiles(
|
||||
std::vector<wxString>( 1, wxString::FromUTF8( path.c_str() ) ) );
|
||||
}
|
||||
#endif // !KICAD_MERGED_EMBIND
|
||||
|
||||
// ───────────────────────────── Yjs collaborative bridge ─────────────────────────────
|
||||
//
|
||||
|
|
@ -912,7 +920,7 @@ void collabTestMove( PCB_EDIT_FRAME* aFrame, BOARD_ITEM* aItem, int aDx, int aDy
|
|||
// fiber stack: BOARD_COMMIT::Push's CHT_ADD of a freshly-built item dispatches GAL virtuals
|
||||
// (view->Add → ViewGetLayers) through asyncify-instrumented invoke_*; off the fiber stack those
|
||||
// mis-dispatch and trap inside KiCad core, on it they dispatch correctly (eeschema 0007).
|
||||
void kicadCollabApply( std::string aJson )
|
||||
void pcbCollabApply( std::string aJson )
|
||||
{
|
||||
json delta = json::parse( aJson, nullptr, /*allow_exceptions*/ false );
|
||||
|
||||
|
|
@ -937,7 +945,7 @@ void kicadCollabApply( std::string aJson )
|
|||
|
||||
// JS → C++, v2 items wire. Same CallAfter + COROUTINE context as kicadCollabApply
|
||||
// (the blob parse + commit must run where native edits run — see above).
|
||||
void kicadCollabApplyItems( std::string aJson )
|
||||
void pcbCollabApplyItems( std::string aJson )
|
||||
{
|
||||
json wire = json::parse( aJson, nullptr, /*allow_exceptions*/ false );
|
||||
|
||||
|
|
@ -962,7 +970,7 @@ void kicadCollabApplyItems( std::string aJson )
|
|||
|
||||
// JS pull of the full current model as an all-"added" delta (seed/baseline). Also registers the
|
||||
// change listener on first call.
|
||||
std::string kicadCollabSnapshot()
|
||||
std::string pcbCollabSnapshot()
|
||||
{
|
||||
BOARD* board = ensureBridge();
|
||||
|
||||
|
|
@ -985,7 +993,7 @@ std::string kicadCollabSnapshot()
|
|||
// JS pull of the full current model as an all-"added" v2 items wire: one blob per ROOT
|
||||
// item (a footprint's blob embeds its children — the TS side flattens). Registers the
|
||||
// listener + rebaselines exactly like kicadCollabSnapshot.
|
||||
std::string kicadCollabSnapshotItems()
|
||||
std::string pcbCollabSnapshotItems()
|
||||
{
|
||||
BOARD* board = ensureBridge();
|
||||
|
||||
|
|
@ -1020,6 +1028,9 @@ std::string kicadCollabSnapshotItems()
|
|||
// kicad fork's save chokepoint (PCB_EDIT_FRAME::SavePcbFile) after a successful
|
||||
// write to MEMFS, so the web app can route the saved bytes onward (API upload,
|
||||
// local-disk write-back, download). No-op without a JS listener.
|
||||
// KICAD_MERGED_EMBIND: identical definition in eeschema_embind.cpp; the merged image
|
||||
// gets the one in kicad_editor_embind.cpp (both fork save chokepoints call it).
|
||||
#ifndef KICAD_MERGED_EMBIND
|
||||
extern "C" void kicadCollabOnSave( const char* aPath )
|
||||
{
|
||||
EM_ASM( {
|
||||
|
|
@ -1027,6 +1038,15 @@ extern "C" void kicadCollabOnSave( const char* aPath )
|
|||
window.kicadCollab.onSave( UTF8ToString( $0 ) );
|
||||
}, aPath );
|
||||
}
|
||||
#endif // !KICAD_MERGED_EMBIND
|
||||
|
||||
// Merged-image dispatch probe (kicad_editor_embind.cpp): is the active top window the
|
||||
// PCB editor? Each shared JS entry routes to the pcb*/sch* implementation whose frame
|
||||
// is live — exactly the null-check its body starts with anyway.
|
||||
bool pcbEditorActive()
|
||||
{
|
||||
return pcbFrame() != nullptr;
|
||||
}
|
||||
|
||||
|
||||
void kicadSaveBoard( std::string path )
|
||||
|
|
@ -1057,7 +1077,7 @@ void kicadSaveBoard( std::string path )
|
|||
// Test/PoC helper: move the first top-level board item by (dx,dy) IU via a real BOARD_COMMIT,
|
||||
// firing the listener — a deterministic local edit for the two-tab demo / e2e. Returns the
|
||||
// moved item's uuid.
|
||||
std::string kicadCollabTestMoveFirst( int aDx, int aDy )
|
||||
std::string pcbCollabTestMoveFirst( int aDx, int aDy )
|
||||
{
|
||||
PCB_EDIT_FRAME* fr = pcbFrame();
|
||||
|
||||
|
|
@ -1090,7 +1110,7 @@ std::string kicadCollabTestMoveFirst( int aDx, int aDy )
|
|||
|
||||
|
||||
// Test helper: read an item's position by uuid as "x,y" (internal units).
|
||||
std::string kicadCollabGetPos( std::string aId )
|
||||
std::string pcbCollabGetPos( std::string aId )
|
||||
{
|
||||
PCB_EDIT_FRAME* fr = pcbFrame();
|
||||
|
||||
|
|
@ -1194,19 +1214,24 @@ EMSCRIPTEN_BINDINGS(pcbnew) {
|
|||
function("Pad_GetNumber", &Pad_GetNumber, allow_raw_pointers());
|
||||
function("Pad_GetPinFunction", &Pad_GetPinFunction, allow_raw_pointers());
|
||||
|
||||
// Programmatic file open (preferred over UI automation from the web app).
|
||||
function("kicadOpenFile", &kicadOpenFile);
|
||||
// Programmatic save of the in-memory board (round-trip tests, README §A).
|
||||
function("kicadSaveBoard", &kicadSaveBoard);
|
||||
|
||||
// Yjs collaborative bridge entry points (same contract as pl_editor / eeschema).
|
||||
function("kicadCollabApply", &kicadCollabApply);
|
||||
function("kicadCollabSnapshot", &kicadCollabSnapshot);
|
||||
// v2 items bridge: per-item s-expr payloads (ysync 0008).
|
||||
function("kicadCollabApplyItems", &kicadCollabApplyItems);
|
||||
function("kicadCollabSnapshotItems", &kicadCollabSnapshotItems);
|
||||
function("kicadCollabTestMoveFirst", &kicadCollabTestMoveFirst);
|
||||
function("kicadCollabGetPos", &kicadCollabGetPos);
|
||||
// pcbnew-only test helper (no eeschema counterpart — name is not shared).
|
||||
function("kicadCollabTestItemBlob", &kicadCollabTestItemBlob);
|
||||
|
||||
#ifndef KICAD_MERGED_EMBIND
|
||||
// JS names ALSO registered by eeschema_embind.cpp — in the merged image these are
|
||||
// registered once by kicad_editor_embind.cpp, dispatching on the active frame.
|
||||
// Programmatic file open (preferred over UI automation from the web app).
|
||||
function("kicadOpenFile", &kicadOpenFile);
|
||||
// Yjs collaborative bridge entry points (same contract as pl_editor / eeschema).
|
||||
function("kicadCollabApply", &pcbCollabApply);
|
||||
function("kicadCollabSnapshot", &pcbCollabSnapshot);
|
||||
// v2 items bridge: per-item s-expr payloads (ysync 0008).
|
||||
function("kicadCollabApplyItems", &pcbCollabApplyItems);
|
||||
function("kicadCollabSnapshotItems", &pcbCollabSnapshotItems);
|
||||
function("kicadCollabTestMoveFirst", &pcbCollabTestMoveFirst);
|
||||
function("kicadCollabGetPos", &pcbCollabGetPos);
|
||||
#endif // !KICAD_MERGED_EMBIND
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
57
wasm/editor/CMakeLists.txt
Normal file
57
wasm/editor/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# Merged pcbnew+eeschema WASM editor (editor-unification Part 2).
|
||||
#
|
||||
# ONE executable links BOTH kifaces; the editor frame (PCB / Footprint / Schematic /
|
||||
# Symbol) is chosen at runtime by single_top.cpp's --frame flag. Added from the kicad
|
||||
# fork's top-level CMakeLists.txt via add_subdirectory( ${KICAD_WASM_LAYER}/editor )
|
||||
# when EMSCRIPTEN AND KICAD_WASM_MERGED_EDITOR — after eeschema/ and pcbnew/, so both
|
||||
# kifaces' CACHE INTERNAL library lists exist here.
|
||||
#
|
||||
# Collision handling (see KICAD_WASM_PCB_SIDE_RENAMES in the fork's top-level
|
||||
# CMakeLists.txt and docs/features/editor-unification/): the PCB-side targets compile
|
||||
# with per-engine symbol renames; each kiface gets its own KIFACE_GETTER name; the
|
||||
# plain Kiface() the shared common/ code falls back to is defined here
|
||||
# (merged_kiface_dispatch.cpp).
|
||||
#
|
||||
# The standalone pcbnew/eeschema targets still exist in this (option-ON) tree but are
|
||||
# not intended to be built here: their kiface objects carry the merged renames, and
|
||||
# their single_top TUs still bind the un-renamed KIFACE_GETTER — build them from their
|
||||
# own (option-OFF) per-app trees as before.
|
||||
|
||||
include_directories( BEFORE ${INC_BEFORE} )
|
||||
include_directories(
|
||||
${CMAKE_SOURCE_DIR}/common
|
||||
${CMAKE_SOURCE_DIR}/common/dialogs
|
||||
${INC_AFTER}
|
||||
)
|
||||
|
||||
add_executable( kicad_editor
|
||||
${CMAKE_SOURCE_DIR}/common/single_top.cpp
|
||||
merged_kiface_dispatch.cpp
|
||||
)
|
||||
|
||||
# TOP_FRAME is only the DEFAULT frame (no --frame given). No PGM_DATA_FILE_EXT: the
|
||||
# runtime extension map in single_top.cpp covers all four frames. No BUILD_KIWAY_DLL:
|
||||
# static kiface linking (matches the per-app WASM executables). KICAD_MERGED_KIFACES
|
||||
# selects single_top.cpp's dual-getter registration branch.
|
||||
set_source_files_properties( ${CMAKE_SOURCE_DIR}/common/single_top.cpp PROPERTIES
|
||||
COMPILE_DEFINITIONS "TOP_FRAME=FRAME_PCB_EDITOR;KICAD_MERGED_KIFACES"
|
||||
)
|
||||
|
||||
# Both kifaces' full library sets (exported CACHE INTERNAL by pcbnew/ and eeschema/).
|
||||
# The overlap (common, kicommon, gal, ...) is deduped; generator-expression entries
|
||||
# (native-only pads_common/pcm) are inert strings that evaluate to nothing here.
|
||||
set( KICAD_EDITOR_LIBS ${PCBNEW_KIFACE_LIBRARIES} ${EESCHEMA_KIFACE_LIBRARIES} )
|
||||
list( REMOVE_DUPLICATES KICAD_EDITOR_LIBS )
|
||||
|
||||
target_link_libraries( kicad_editor PRIVATE ${KICAD_EDITOR_LIBS} )
|
||||
|
||||
# Same link shape as the standalone pcbnew WASM executable: allow-multiple-definition
|
||||
# for the wx/KiCad dupes, and --whole-archive pcbcommon so RTTI-only-referenced
|
||||
# vtables/typeinfo are pulled in.
|
||||
target_link_options( kicad_editor PRIVATE
|
||||
"LINKER:--allow-multiple-definition"
|
||||
"LINKER:--whole-archive"
|
||||
"$<TARGET_FILE:pcbcommon>"
|
||||
"LINKER:--no-whole-archive"
|
||||
$<$<BOOL:${KICAD_MAKE_LINK_MAPS}>:-Wl,--cref,-Map=kicad_editor.map>
|
||||
)
|
||||
68
wasm/editor/merged_kiface_dispatch.cpp
Normal file
68
wasm/editor/merged_kiface_dispatch.cpp
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Merged-editor safety-net Kiface() (editor-unification Part 2).
|
||||
*
|
||||
* In the merged kicad_editor image the pcbnew and eeschema kifaces are compiled with
|
||||
* -DKiface=PcbKiface / -DKiface=SchKiface, so every module-owned call site binds
|
||||
* statically to its own engine. The handful of shared common/ call sites are patched
|
||||
* to resolve their owning frame's kiface exactly (eda_base_frame.cpp,
|
||||
* dialog_color_picker.cpp, design_block_tree_model_adapter.cpp) and only FALL BACK to
|
||||
* the plain Kiface() — which, in this image, is THIS definition. It also keeps any
|
||||
* future upstream common/ caller linking.
|
||||
*
|
||||
* Resolution is best-effort by design: focused window → top window → KIWAY top frame,
|
||||
* walking parents to an EDA_BASE_FRAME whose FRAME_T names its face. With the one-
|
||||
* frame-per-page-load model there is exactly one editor frame, so the walk is exact
|
||||
* in practice; FACE_PCB is the last-resort default.
|
||||
*/
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
|
||||
#include <wx/app.h>
|
||||
#include <wx/window.h>
|
||||
|
||||
#include <kiway.h>
|
||||
#include <kiface_base.h>
|
||||
#include <eda_base_frame.h>
|
||||
|
||||
// single_top.cpp's process-global KIWAY (declared in kiway.h).
|
||||
static KIFACE_BASE* frameKiface( wxWindow* aWindow )
|
||||
{
|
||||
for( wxWindow* w = aWindow; w; w = w->GetParent() )
|
||||
{
|
||||
if( EDA_BASE_FRAME* frame = dynamic_cast<EDA_BASE_FRAME*>( w ) )
|
||||
{
|
||||
KIWAY::FACE_T face = KIWAY::KifaceType( frame->GetFrameType() );
|
||||
|
||||
if( face != KIWAY::FACE_T( -1 ) )
|
||||
{
|
||||
if( KIFACE* kiface = Kiway.KiFACE( face ) )
|
||||
return static_cast<KIFACE_BASE*>( kiface );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
KIFACE_BASE& Kiface()
|
||||
{
|
||||
if( KIFACE_BASE* kiface = frameKiface( wxWindow::FindFocus() ) )
|
||||
return *kiface;
|
||||
|
||||
if( wxTheApp )
|
||||
{
|
||||
if( KIFACE_BASE* kiface = frameKiface( wxTheApp->GetTopWindow() ) )
|
||||
return *kiface;
|
||||
}
|
||||
|
||||
if( KIFACE_BASE* kiface = frameKiface( Kiway.GetTop() ) )
|
||||
return *kiface;
|
||||
|
||||
// Last resort — no frame up yet. FACE_PCB is the merged image's default TOP_FRAME
|
||||
// face; both faces are registered in OnPgmInit, so this cannot be reached before
|
||||
// registration in any path that previously had a working Kiface().
|
||||
return *static_cast<KIFACE_BASE*>( Kiway.KiFACE( KIWAY::FACE_PCB ) );
|
||||
}
|
||||
|
||||
#endif // __EMSCRIPTEN__
|
||||
Loading…
Reference in a new issue