openswx 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openswx/__init__.py +41 -0
- openswx/__main__.py +160 -0
- openswx/advanced.py +708 -0
- openswx/analysis_more.py +296 -0
- openswx/api.py +221 -0
- openswx/applog.py +77 -0
- openswx/assembly.py +1172 -0
- openswx/cache.py +168 -0
- openswx/cam.py +754 -0
- openswx/cfd.py +455 -0
- openswx/cli.py +124 -0
- openswx/commands_app.py +235 -0
- openswx/commands_asm.py +42 -0
- openswx/commands_assembly.py +476 -0
- openswx/commands_blocks.py +198 -0
- openswx/commands_document.py +758 -0
- openswx/commands_drawing.py +927 -0
- openswx/commands_features.py +875 -0
- openswx/commands_mfg.py +586 -0
- openswx/commands_more.py +1585 -0
- openswx/commands_review.py +655 -0
- openswx/commands_settings.py +44 -0
- openswx/commands_simreport.py +178 -0
- openswx/commands_simulation.py +414 -0
- openswx/commands_sketch.py +476 -0
- openswx/commands_std.py +123 -0
- openswx/commands_tol.py +127 -0
- openswx/desktop.py +243 -0
- openswx/document.py +957 -0
- openswx/drawing.py +535 -0
- openswx/drawing_export.py +274 -0
- openswx/drawing_more.py +314 -0
- openswx/drawing_sheets.py +1398 -0
- openswx/dxf_io.py +187 -0
- openswx/ecosystem.py +389 -0
- openswx/electrical.py +255 -0
- openswx/equations.py +162 -0
- openswx/evaluate.py +214 -0
- openswx/fcstd.py +103 -0
- openswx/fea.py +809 -0
- openswx/fea_more.py +272 -0
- openswx/fea_tet.py +909 -0
- openswx/features.py +2975 -0
- openswx/fileassoc.py +117 -0
- openswx/geom.py +222 -0
- openswx/hardware.py +174 -0
- openswx/inspection.py +291 -0
- openswx/isolated.py +103 -0
- openswx/jobs.py +101 -0
- openswx/materials.py +172 -0
- openswx/mcp_bridge.py +122 -0
- openswx/mcp_server.py +214 -0
- openswx/migrate.py +52 -0
- openswx/naming.py +272 -0
- openswx/parasolid.py +1264 -0
- openswx/parasolid_write.py +467 -0
- openswx/piping.py +230 -0
- openswx/plastics.py +318 -0
- openswx/plugins.py +54 -0
- openswx/recovery.py +205 -0
- openswx/render.py +165 -0
- openswx/security.py +177 -0
- openswx/session.py +1277 -0
- openswx/settings.py +95 -0
- openswx/sketch.py +1497 -0
- openswx/sldprt.py +510 -0
- openswx/snapshots.py +81 -0
- openswx/sw_drawing.py +261 -0
- openswx/sw_rebuild.py +2168 -0
- openswx/sw_sketch.py +436 -0
- openswx/sw_tree.py +147 -0
- openswx/tolerance.py +169 -0
- openswx/updates.py +52 -0
- openswx/web/app.js +2818 -0
- openswx/web/drawing.js +621 -0
- openswx/web/icons.js +214 -0
- openswx/web/index.html +91 -0
- openswx/web/mfg.js +231 -0
- openswx/web/more.js +1072 -0
- openswx/web/propman.js +990 -0
- openswx/web/sketcher.js +794 -0
- openswx/web/style.css +353 -0
- openswx/web/vendor/three-Pass.js +95 -0
- openswx/web/vendor/three-gpu-pathtracer.LICENSE +21 -0
- openswx/web/vendor/three-gpu-pathtracer.module.js +9361 -0
- openswx/web/vendor/three-mesh-bvh.LICENSE +21 -0
- openswx/web/vendor/three-mesh-bvh.module.js +8373 -0
- openswx/web/vendor/three.LICENSE +21 -0
- openswx/web/vendor/three.module.min.js +6 -0
- openswx/web/viewport.js +802 -0
- openswx/web_server.py +179 -0
- openswx-0.2.0.dist-info/METADATA +331 -0
- openswx-0.2.0.dist-info/RECORD +98 -0
- openswx-0.2.0.dist-info/WHEEL +5 -0
- openswx-0.2.0.dist-info/entry_points.txt +2 -0
- openswx-0.2.0.dist-info/licenses/LICENSE +202 -0
- openswx-0.2.0.dist-info/licenses/NOTICE +38 -0
- openswx-0.2.0.dist-info/top_level.txt +1 -0
openswx/__init__.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""openswx: open-source parametric CAD with a SOLIDWORKS-style workflow and a built-in MCP server."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.2.0"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _defer_sklearn() -> None:
|
|
7
|
+
"""build123d imports scikit-learn (DBSCAN, for STL primitive detection, which openswx never uses) when it
|
|
8
|
+
loads: 1-2 s of every start. Until something actually uses it, stand-in modules take its place; the first
|
|
9
|
+
use of one swaps the real package in."""
|
|
10
|
+
import sys
|
|
11
|
+
import types
|
|
12
|
+
if "sklearn" in sys.modules:
|
|
13
|
+
return
|
|
14
|
+
|
|
15
|
+
def real():
|
|
16
|
+
for name in ("sklearn.cluster", "sklearn"):
|
|
17
|
+
if getattr(sys.modules.get(name), "_openswx_stub", False):
|
|
18
|
+
del sys.modules[name]
|
|
19
|
+
import sklearn.cluster
|
|
20
|
+
return sklearn.cluster
|
|
21
|
+
|
|
22
|
+
class _Stub(types.ModuleType):
|
|
23
|
+
_openswx_stub = True
|
|
24
|
+
|
|
25
|
+
def __getattr__(self, attr):
|
|
26
|
+
if attr.startswith("__"): # the import machinery probes these (__path__, __spec__ ...)
|
|
27
|
+
raise AttributeError(attr)
|
|
28
|
+
mod = real()
|
|
29
|
+
return getattr(mod if self.__name__ == "sklearn.cluster" else sys.modules["sklearn"], attr)
|
|
30
|
+
|
|
31
|
+
def DBSCAN(*args, **kwargs): # noqa: N802 - the class it stands in for
|
|
32
|
+
return real().DBSCAN(*args, **kwargs)
|
|
33
|
+
|
|
34
|
+
pkg, cluster = _Stub("sklearn"), _Stub("sklearn.cluster")
|
|
35
|
+
pkg.__path__ = []
|
|
36
|
+
pkg.cluster = cluster
|
|
37
|
+
cluster.DBSCAN = DBSCAN
|
|
38
|
+
sys.modules["sklearn"], sys.modules["sklearn.cluster"] = pkg, cluster
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
_defer_sklearn()
|
openswx/__main__.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""openswx command line.
|
|
2
|
+
|
|
3
|
+
openswx [FILE] desktop application (native window; default)
|
|
4
|
+
python -m openswx serve [--port 8765] web UI + REST + MCP (streamable HTTP at /mcp)
|
|
5
|
+
python -m openswx mcp [--port 8765] [--no-ui] MCP over stdio for agents, plus the live web UI
|
|
6
|
+
python -m openswx sldinfo FILE.SLDPRT [--extract DIR]
|
|
7
|
+
python -m openswx token the token agents send to MCP over HTTP (Authorization: Bearer)
|
|
8
|
+
openswx-cli register-file-types [--exe EXE] .oswprt/.oswasm open in openswx; Open with for CAD files
|
|
9
|
+
openswx-cli unregister-file-types remove those file associations again
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import sys
|
|
17
|
+
import threading
|
|
18
|
+
import webbrowser
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def main(argv: list[str] | None = None) -> int:
|
|
23
|
+
ap = argparse.ArgumentParser(prog="openswx")
|
|
24
|
+
sub = ap.add_subparsers(dest="cmd")
|
|
25
|
+
d = sub.add_parser("desktop", help="run openswx as a desktop application (default)")
|
|
26
|
+
d.add_argument("file", nargs="?", help="document to open")
|
|
27
|
+
d.add_argument("--port", type=int, default=8765)
|
|
28
|
+
s = sub.add_parser("serve", help="run the web UI (and MCP over HTTP at /mcp)")
|
|
29
|
+
s.add_argument("--host", default="127.0.0.1")
|
|
30
|
+
s.add_argument("--port", type=int, default=8765)
|
|
31
|
+
s.add_argument("--open", action="store_true", help="open the browser")
|
|
32
|
+
s.add_argument("--file", help="part to open on start (.oswprt/.step)")
|
|
33
|
+
s.add_argument("--no-token", action="store_true", help="do not ask for the token (this computer only)")
|
|
34
|
+
s.add_argument("--share", action="store_true", help="also print a view-only link: whoever opens it sees the model live but cannot change it")
|
|
35
|
+
s.add_argument("--workspace", help="folder agents (MCP) may read and write files in; elsewhere is refused")
|
|
36
|
+
s.add_argument("--toolsets", help="MCP tools listed at first: core (default), all, or e.g. core,assembly,drawing")
|
|
37
|
+
s.add_argument("--allow-remote", action="store_true", help="allow --host to be an address other computers can reach")
|
|
38
|
+
sub.add_parser("token", help="print the token for the web UI link and for agents (MCP over HTTP)")
|
|
39
|
+
m = sub.add_parser("mcp", help="run the MCP server over stdio")
|
|
40
|
+
m.add_argument("--host", default="127.0.0.1")
|
|
41
|
+
m.add_argument("--port", type=int, default=8765)
|
|
42
|
+
m.add_argument("--no-ui", action="store_true", help="do not start the web UI alongside")
|
|
43
|
+
m.add_argument("--standalone", action="store_true",
|
|
44
|
+
help="always serve MCP from this process (by default it relays to an openswx already running on --port)")
|
|
45
|
+
m.add_argument("--workspace", help="folder agents (MCP) may read and write files in; elsewhere is refused")
|
|
46
|
+
m.add_argument("--toolsets", help="MCP tools listed at first: core (default), all, or e.g. core,assembly,drawing")
|
|
47
|
+
i = sub.add_parser("sldinfo", help="inspect a SOLIDWORKS file container")
|
|
48
|
+
i.add_argument("file")
|
|
49
|
+
i.add_argument("--extract", help="directory to extract streams and Parasolid data into")
|
|
50
|
+
r = sub.add_parser("register-file-types", help="open .oswprt/.oswasm in openswx and add it to Open with (this user)")
|
|
51
|
+
r.add_argument("--exe", help="program to register (default: openswx.exe next to this program)")
|
|
52
|
+
sub.add_parser("unregister-file-types", help="remove the file associations register-file-types added")
|
|
53
|
+
from . import cli # (headless one-shot tools: convert, render, massprops, check, drawing, script, diff)
|
|
54
|
+
cli.add_parsers(sub)
|
|
55
|
+
argv = [x for x in (sys.argv[1:] if argv is None else argv) if not x.startswith("-psn_")] # (macOS Finder launch)
|
|
56
|
+
if not argv or (argv[0] not in ("desktop", "serve", "mcp", "token", "sldinfo", "register-file-types", "unregister-file-types", "-h", "--help", *cli.COMMANDS)):
|
|
57
|
+
argv = ["desktop", *argv] # double-clicking openswx.exe (or opening a file with it) starts the app
|
|
58
|
+
a = ap.parse_args(argv)
|
|
59
|
+
if getattr(a, "workspace", None):
|
|
60
|
+
os.environ["OPENSWX_WORKSPACE"] = str(Path(a.workspace).resolve())
|
|
61
|
+
if getattr(a, "toolsets", None):
|
|
62
|
+
os.environ["OPENSWX_TOOLSETS"] = a.toolsets
|
|
63
|
+
|
|
64
|
+
if a.cmd in cli.COMMANDS:
|
|
65
|
+
return cli.run(a)
|
|
66
|
+
|
|
67
|
+
if a.cmd == "desktop":
|
|
68
|
+
from .desktop import run as run_desktop
|
|
69
|
+
return run_desktop(a.port, a.file)
|
|
70
|
+
|
|
71
|
+
if a.cmd == "serve":
|
|
72
|
+
from . import security
|
|
73
|
+
remote = not security.is_loopback(a.host)
|
|
74
|
+
if remote and not a.allow_remote:
|
|
75
|
+
print(f"openswx: --host {a.host} lets other computers reach openswx; add --allow-remote if that is intended",
|
|
76
|
+
file=sys.stderr)
|
|
77
|
+
return 2
|
|
78
|
+
if remote and a.no_token:
|
|
79
|
+
print("openswx: --no-token is only for this computer (not with --allow-remote)", file=sys.stderr)
|
|
80
|
+
return 2
|
|
81
|
+
token = None if a.no_token else security.user_token()
|
|
82
|
+
from . import session as S
|
|
83
|
+
from .web_server import run
|
|
84
|
+
if a.file:
|
|
85
|
+
S.open_part(a.file)
|
|
86
|
+
url = f"http://{a.host}:{a.port}/"
|
|
87
|
+
link = url + (f"?token={token}" if token else "")
|
|
88
|
+
if a.open:
|
|
89
|
+
threading.Timer(1.0, lambda: webbrowser.open(link)).start()
|
|
90
|
+
print(f"openswx UI: {link}\nMCP (streamable HTTP): {url}mcp"
|
|
91
|
+
+ (" header Authorization: Bearer <token> (the token: `openswx token`)" if token else ""), file=sys.stderr)
|
|
92
|
+
view = security.view_token() if a.share and token else None
|
|
93
|
+
if a.share and not token:
|
|
94
|
+
print("openswx: --share needs the token (not with --no-token)", file=sys.stderr)
|
|
95
|
+
return 2
|
|
96
|
+
if view:
|
|
97
|
+
print(f"view-only link: {url}?view={view}" + ("" if remote else " (this computer only; for others add --host and --allow-remote)"),
|
|
98
|
+
file=sys.stderr)
|
|
99
|
+
run(a.host, a.port, token=token, view_token=view)
|
|
100
|
+
return 0
|
|
101
|
+
|
|
102
|
+
if a.cmd == "token":
|
|
103
|
+
from . import security
|
|
104
|
+
print(security.user_token())
|
|
105
|
+
return 0
|
|
106
|
+
|
|
107
|
+
if a.cmd == "mcp":
|
|
108
|
+
from . import mcp_bridge
|
|
109
|
+
running = None if a.standalone or a.workspace or a.toolsets else mcp_bridge.find_running(a.port)
|
|
110
|
+
if running: # an openswx window is open: the agent works in it (its edits show there, live)
|
|
111
|
+
from . import security
|
|
112
|
+
print(f"openswx: relaying MCP to the running openswx at {running}", file=sys.stderr)
|
|
113
|
+
mcp_bridge.run(running + "/mcp", security.user_token())
|
|
114
|
+
return 0
|
|
115
|
+
from .mcp_server import build_mcp
|
|
116
|
+
if not a.no_ui:
|
|
117
|
+
from . import security
|
|
118
|
+
if not security.is_loopback(a.host):
|
|
119
|
+
print("openswx: the live UI of `mcp` is for this computer only (use `serve --allow-remote`)", file=sys.stderr)
|
|
120
|
+
return 2
|
|
121
|
+
token = security.user_token()
|
|
122
|
+
|
|
123
|
+
def ui():
|
|
124
|
+
try:
|
|
125
|
+
from .web_server import run
|
|
126
|
+
run(a.host, a.port, mount_mcp=False, log_level="error", token=token)
|
|
127
|
+
except (OSError, SystemExit) as exc: # port busy: agents still work headless
|
|
128
|
+
print(f"openswx: web UI not started ({exc})", file=sys.stderr)
|
|
129
|
+
threading.Thread(target=ui, daemon=True).start()
|
|
130
|
+
print(f"openswx: live UI at http://{a.host}:{a.port}/?token={token}", file=sys.stderr)
|
|
131
|
+
build_mcp().run("stdio")
|
|
132
|
+
return 0
|
|
133
|
+
|
|
134
|
+
if a.cmd == "sldinfo":
|
|
135
|
+
from .sldprt import extract, read_info
|
|
136
|
+
info = read_info(a.file)
|
|
137
|
+
if a.extract:
|
|
138
|
+
info["extracted"] = extract(a.file, a.extract)
|
|
139
|
+
print(json.dumps(info, indent=1))
|
|
140
|
+
return 0
|
|
141
|
+
if a.cmd in ("register-file-types", "unregister-file-types"):
|
|
142
|
+
from . import fileassoc
|
|
143
|
+
if a.cmd == "unregister-file-types":
|
|
144
|
+
print(json.dumps({"removed": fileassoc.unregister()}, indent=1))
|
|
145
|
+
return 0
|
|
146
|
+
exe = a.exe
|
|
147
|
+
if not exe and getattr(sys, "frozen", False): # the windowed app beside openswx-cli.exe (or its launcher)
|
|
148
|
+
launcher = os.environ.get("OPENSWX_LAUNCHER_DIR")
|
|
149
|
+
gui = Path(launcher) / "openswx.exe" if launcher else Path(sys.executable).with_name("openswx.exe")
|
|
150
|
+
exe = str(gui if gui.exists() else Path(sys.executable))
|
|
151
|
+
if not exe:
|
|
152
|
+
print("pass --exe (the program files should open with) when running from source", file=sys.stderr)
|
|
153
|
+
return 2
|
|
154
|
+
print(json.dumps({"registered": fileassoc.register(exe)}, indent=1))
|
|
155
|
+
return 0
|
|
156
|
+
return 1
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
if __name__ == "__main__":
|
|
160
|
+
raise SystemExit(main())
|