Skip to content

Commit 964e07a

Browse files
authored
Merge pull request #212 from pathsim/feature/url-model-loading
Feature/url model loading
2 parents a0b7c37 + 41ac2af commit 964e07a

File tree

6 files changed

+219
-188
lines changed

6 files changed

+219
-188
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,43 @@ PathView uses JSON-based file formats for saving and sharing:
428428

429429
---
430430

431+
## Sharing Models via URL
432+
433+
Models can be loaded directly from a URL using query parameters:
434+
435+
```
436+
https://view.pathsim.org/?model=<url>
437+
https://view.pathsim.org/?modelgh=<github-shorthand>
438+
```
439+
440+
### Parameters
441+
442+
| Parameter | Description | Example |
443+
|-----------|-------------|---------|
444+
| `model` | Direct URL to a `.pvm` or `.json` file | `?model=https://example.com/mymodel.pvm` |
445+
| `modelgh` | GitHub shorthand (expands to raw.githubusercontent.com) | `?modelgh=user/repo/path/to/model.pvm` |
446+
447+
### GitHub Shorthand
448+
449+
The `modelgh` parameter expands to a raw GitHub URL:
450+
451+
```
452+
modelgh=user/repo/examples/demo.pvm
453+
→ https://raw.githubusercontent.com/user/repo/main/examples/demo.pvm
454+
```
455+
456+
### Examples
457+
458+
```
459+
# Load from any URL
460+
https://view.pathsim.org/?model=https://mysite.com/models/feedback.pvm
461+
462+
# Load from GitHub repository
463+
https://view.pathsim.org/?modelgh=pathsim/pathview/static/examples/feedback-system.json
464+
```
465+
466+
---
467+
431468
## Scripts
432469

433470
| Script | Purpose |

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/extract-blocks.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
from pathsim.blocks import *
3232
from pathsim.subsystem import Subsystem, Interface
3333

34-
from pathsim_chem.tritium import *
34+
try:
35+
from pathsim_chem.tritium import *
36+
HAS_PATHSIM_CHEM = True
37+
except ImportError:
38+
HAS_PATHSIM_CHEM = False
39+
print("Warning: pathsim_chem not installed, Chemical blocks will be skipped")
3540

3641
# Block configuration - defines which blocks to extract and their categories
3742
BLOCK_CONFIG = {
@@ -441,6 +446,10 @@ def main():
441446
# Extract all blocks
442447
extracted_blocks = {}
443448
for category, block_names in BLOCK_CONFIG.items():
449+
# Skip Chemical category if pathsim_chem not available
450+
if category == "Chemical" and not HAS_PATHSIM_CHEM:
451+
print(f" Skipping {category} category (pathsim_chem not installed)")
452+
continue
444453
for block_name in block_names:
445454
print(f" Extracting {block_name}...")
446455
block_data = extract_block(block_name)
@@ -464,8 +473,11 @@ def main():
464473

465474
print(f"Extracted {len(extracted_blocks)} blocks")
466475

476+
# Filter config to only include categories that were extracted
477+
filtered_config = {k: v for k, v in BLOCK_CONFIG.items() if k != "Chemical" or HAS_PATHSIM_CHEM}
478+
467479
# Generate TypeScript
468-
ts_content = generate_typescript(extracted_blocks, BLOCK_CONFIG, UI_OVERRIDES)
480+
ts_content = generate_typescript(extracted_blocks, filtered_config, UI_OVERRIDES)
469481

470482
# Write output file
471483
output_path = (

0 commit comments

Comments
 (0)