stepss-cg-studio 5.3.0__tar.gz

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.
Files changed (50) hide show
  1. stepss_cg_studio-5.3.0/LICENSE +203 -0
  2. stepss_cg_studio-5.3.0/PKG-INFO +248 -0
  3. stepss_cg_studio-5.3.0/README.md +217 -0
  4. stepss_cg_studio-5.3.0/pyproject.toml +68 -0
  5. stepss_cg_studio-5.3.0/setup.cfg +4 -0
  6. stepss_cg_studio-5.3.0/src/cg_studio/__init__.py +6 -0
  7. stepss_cg_studio-5.3.0/src/cg_studio/__main__.py +5 -0
  8. stepss_cg_studio-5.3.0/src/cg_studio/_bundled.py +13 -0
  9. stepss_cg_studio-5.3.0/src/cg_studio/app.py +341 -0
  10. stepss_cg_studio-5.3.0/src/cg_studio/bin/LICENSE-CODEGEN +70 -0
  11. stepss_cg_studio-5.3.0/src/cg_studio/bin/lin/BUILDINFO.txt +11 -0
  12. stepss_cg_studio-5.3.0/src/cg_studio/bin/lin/CODEGEN +0 -0
  13. stepss_cg_studio-5.3.0/src/cg_studio/bin/mac/BUILDINFO.txt +11 -0
  14. stepss_cg_studio-5.3.0/src/cg_studio/bin/mac/CODEGEN +0 -0
  15. stepss_cg_studio-5.3.0/src/cg_studio/bin/win/BUILDINFO.txt +11 -0
  16. stepss_cg_studio-5.3.0/src/cg_studio/bin/win/CODEGEN.exe +0 -0
  17. stepss_cg_studio-5.3.0/src/cg_studio/cli.py +50 -0
  18. stepss_cg_studio-5.3.0/src/cg_studio/config.py +135 -0
  19. stepss_cg_studio-5.3.0/src/cg_studio/dsl_emitter.py +114 -0
  20. stepss_cg_studio-5.3.0/src/cg_studio/dsl_parser.py +295 -0
  21. stepss_cg_studio-5.3.0/src/cg_studio/frontend/blocks.json +1121 -0
  22. stepss_cg_studio-5.3.0/src/cg_studio/frontend/css/style.css +607 -0
  23. stepss_cg_studio-5.3.0/src/cg_studio/frontend/favicon.svg +4 -0
  24. stepss_cg_studio-5.3.0/src/cg_studio/frontend/index.html +162 -0
  25. stepss_cg_studio-5.3.0/src/cg_studio/frontend/js/api.js +36 -0
  26. stepss_cg_studio-5.3.0/src/cg_studio/frontend/js/canvas.js +662 -0
  27. stepss_cg_studio-5.3.0/src/cg_studio/frontend/js/check_model.js +296 -0
  28. stepss_cg_studio-5.3.0/src/cg_studio/frontend/js/dsl_preview.js +38 -0
  29. stepss_cg_studio-5.3.0/src/cg_studio/frontend/js/forms.js +172 -0
  30. stepss_cg_studio-5.3.0/src/cg_studio/frontend/js/main.js +370 -0
  31. stepss_cg_studio-5.3.0/src/cg_studio/frontend/js/palette.js +134 -0
  32. stepss_cg_studio-5.3.0/src/cg_studio/frontend/js/project_adapter.js +344 -0
  33. stepss_cg_studio-5.3.0/src/cg_studio/frontend/js/resizers.js +84 -0
  34. stepss_cg_studio-5.3.0/src/cg_studio/frontend/js/sidebar.js +62 -0
  35. stepss_cg_studio-5.3.0/src/cg_studio/frontend/js/store.js +93 -0
  36. stepss_cg_studio-5.3.0/src/cg_studio/frontend/js/validate.js +98 -0
  37. stepss_cg_studio-5.3.0/src/stepss_cg_studio.egg-info/PKG-INFO +248 -0
  38. stepss_cg_studio-5.3.0/src/stepss_cg_studio.egg-info/SOURCES.txt +48 -0
  39. stepss_cg_studio-5.3.0/src/stepss_cg_studio.egg-info/dependency_links.txt +1 -0
  40. stepss_cg_studio-5.3.0/src/stepss_cg_studio.egg-info/entry_points.txt +2 -0
  41. stepss_cg_studio-5.3.0/src/stepss_cg_studio.egg-info/requires.txt +9 -0
  42. stepss_cg_studio-5.3.0/src/stepss_cg_studio.egg-info/top_level.txt +1 -0
  43. stepss_cg_studio-5.3.0/tests/test_api.py +464 -0
  44. stepss_cg_studio-5.3.0/tests/test_check_model.py +208 -0
  45. stepss_cg_studio-5.3.0/tests/test_cli.py +45 -0
  46. stepss_cg_studio-5.3.0/tests/test_config.py +169 -0
  47. stepss_cg_studio-5.3.0/tests/test_e2e.py +870 -0
  48. stepss_cg_studio-5.3.0/tests/test_parser.py +432 -0
  49. stepss_cg_studio-5.3.0/tests/test_project_adapter.py +414 -0
  50. stepss_cg_studio-5.3.0/tests/test_validate.py +137 -0
@@ -0,0 +1,203 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (which shall not include Communication that is conspicuously
39
+ marked or otherwise designated in writing by the copyright owner
40
+ as "Not a Work").
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution".
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright 2026 Petros Aristidou
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
@@ -0,0 +1,248 @@
1
+ Metadata-Version: 2.4
2
+ Name: stepss-cg-studio
3
+ Version: 5.3.0
4
+ Summary: Visual block diagram editor for STEPSS CODEGEN power system models
5
+ Author-email: Petros Aristidou <apetros@pm.me>
6
+ License: Apache-2.0 AND LicenseRef-STEPSS-Academic-Public-License
7
+ Project-URL: Homepage, https://stepss.sps-lab.org/
8
+ Project-URL: Documentation, https://stepss.sps-lab.org/developer/cg-studio/
9
+ Project-URL: Repository, https://github.com/SPS-L/stepss-cg-studio
10
+ Project-URL: Issues, https://github.com/SPS-L/stepss-cg-studio/issues
11
+ Keywords: CODEGEN,Power Systems,STEPSS,RAMSES,Block Diagram
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Scientific/Engineering
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: fastapi>=0.110.0
23
+ Requires-Dist: uvicorn>=0.29.0
24
+ Requires-Dist: aiofiles>=23.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=7.0; extra == "dev"
27
+ Requires-Dist: httpx>=0.27.0; extra == "dev"
28
+ Requires-Dist: playwright>=1.40; extra == "dev"
29
+ Requires-Dist: pytest-playwright>=0.4.0; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ [![PyPI version](https://img.shields.io/pypi/v/stepss-cg-studio)](https://pypi.org/project/stepss-cg-studio/)
33
+ [![CI](https://img.shields.io/github/actions/workflow/status/SPS-L/stepss-cg-studio/ci.yml?branch=main&label=tests)](https://github.com/SPS-L/stepss-cg-studio/actions)
34
+ [![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org/)
35
+ [![License](https://img.shields.io/badge/license-Apache%202.0%20%2B%20bundled%20CODEGEN-green.svg)](#license)
36
+ [![Docs](https://img.shields.io/github/actions/workflow/status/SPS-L/stepss-docs/deploy.yml?branch=main&label=docs)](https://stepss.sps-lab.org/developer/cg-studio/)
37
+
38
+ # CODEGEN Studio
39
+
40
+ CODEGEN Studio is a browser-based, drag-and-drop visual editor for building [STEPSS CODEGEN](https://stepss.sps-lab.org/developer/user-models/) User-Defined Models, part of the [STEPSS](https://stepss.sps-lab.org/) power system simulation platform. It lets you create device models by wiring blocks on a canvas instead of manually writing DSL files.
41
+
42
+ STEPSS has been developed by [Dr. Petros Aristidou](https://sps-lab.org/) (Cyprus University of Technology) and Dr. Thierry Van Cutsem (Emeritus, University of Liège).
43
+
44
+ ## Overview
45
+
46
+ CODEGEN Studio replaces the manual editing of CODEGEN DSL `.txt` files with a graphical workflow. You drag blocks from a categorised palette, connect input/output ports to define signal flow, fill in metadata tables, and export ready-to-compile DSL files, or run the bundled CODEGEN directly from the editor to generate Fortran `.f90` source.
47
+
48
+ The tool supports all four CODEGEN model types:
49
+
50
+ | Type | Purpose | Mandatory Outputs |
51
+ |------|---------|-------------------|
52
+ | **EXC** | Excitation controller | `vf` |
53
+ | **TOR** | Torque controller | `tm` |
54
+ | **INJ** | Current injector | `ix`, `iy` |
55
+ | **TWOP** | Two-port device | `ix1`, `iy1`, `ix2`, `iy2` |
56
+
57
+ ## Features
58
+
59
+ - **Drag-and-drop block diagram editor**: assemble models visually on a canvas with 54 built-in blocks
60
+ - **Live DSL preview**: syntax-highlighted code updates in real time as you edit
61
+ - **Lossless round-trip**: import existing `.txt` DSL files with automatic canvas layout, edit, and re-export
62
+ - **One-click Fortran generation**: the CODEGEN executables ship in the wheel, so this works on a fresh install
63
+ - **Project save/load**: JSON project files preserve full editor state including block positions
64
+ - **Mandatory output validation**: warns when required outputs for the model type are missing
65
+ - **Undo/redo**: 60-step history with keyboard shortcuts
66
+ - **Extensible block catalogue**: add new blocks via a single JSON entry, no code changes required
67
+ - **No build step**: vanilla JavaScript frontend served by a Python backend
68
+
69
+ ## Installation
70
+
71
+ ### Requirements
72
+
73
+ - Python ≥ 3.10
74
+ - A modern browser (Chrome, Firefox, or Edge)
75
+
76
+ ### Install from PyPI
77
+
78
+ ```bash
79
+ pip install stepss-cg-studio
80
+ ```
81
+
82
+ The CODEGEN executables are bundled in the wheel, for Linux x86-64, Windows x86-64 and macOS Apple Silicon. **Run Codegen works on a fresh install**: there is nothing to obtain, install or configure, and no setting to point anywhere.
83
+
84
+ macOS is the one platform that needs anything else:
85
+
86
+ ```bash
87
+ brew install gcc
88
+ ```
89
+
90
+ Apple does not support fully static executables, so that CODEGEN build links against `libgfortran`. The Linux and Windows builds are statically linked and need nothing at all.
91
+
92
+ The bundled CODEGEN is named in Settings (gear icon), and in the two leading components of this package's own version: `stepss-cg-studio` 5.3.0 and 5.3.1 both run CODEGEN 5.3. See [Versioning](#versioning).
93
+
94
+ ### Install from source (for development)
95
+
96
+ ```bash
97
+ git clone https://github.com/SPS-L/stepss-cg-studio.git
98
+ cd stepss-cg-studio
99
+ pip install -e ".[dev]"
100
+ ```
101
+
102
+ ## Quick Start
103
+
104
+ ```bash
105
+ cg-studio
106
+ ```
107
+
108
+ This starts the local server and opens your browser to the editor at `http://localhost:8765`. That's it.
109
+
110
+ You can also run it as a Python module:
111
+
112
+ ```bash
113
+ python -m cg_studio
114
+ ```
115
+
116
+ ### CLI options
117
+
118
+ ```bash
119
+ cg-studio --port 9000 # use a different port
120
+ cg-studio --host 0.0.0.0 # allow network access
121
+ cg-studio --no-browser # start server without opening browser
122
+ ```
123
+
124
+ ### Building a model
125
+
126
+ 1. **Select model type and name**: choose EXC, TOR, INJ, or TWOP from the toolbar dropdown
127
+ 2. **Add blocks**: drag blocks from the left-hand palette onto the canvas
128
+ 3. **Connect blocks**: wire output ports to input ports to define signal flow
129
+ 4. **Edit block properties**: select a block to configure output names and arguments in the inspector
130
+ 5. **Populate metadata**: fill in Data, Parameters, States, and Observables in the tabs below the canvas
131
+ 6. **Export**: click "Export DSL" for the `.txt` file, or "Run Codegen" to generate Fortran directly
132
+
133
+ ### Keyboard shortcuts
134
+
135
+ | Shortcut | Action |
136
+ |----------|--------|
137
+ | Ctrl/Cmd + S | Save project |
138
+ | Ctrl/Cmd + Z | Undo |
139
+ | Ctrl/Cmd + Shift + Z (or Ctrl/Cmd + Y) | Redo |
140
+ | Delete / Backspace | Delete selected block |
141
+ | Escape | Close modal |
142
+
143
+ ## Project Structure
144
+
145
+ ```
146
+ stepss-cg-studio/
147
+ ├── pyproject.toml # Package config, dependencies, entry point
148
+ ├── src/cg_studio/
149
+ │ ├── __init__.py # Package version (<bundled CODEGEN X.Y>.<counter>)
150
+ │ ├── _bundled.py # Which CODEGEN release bin/ holds
151
+ │ ├── __main__.py # python -m cg_studio support
152
+ │ ├── cli.py # CLI entry point (cg-studio command)
153
+ │ ├── config.py # Platform-aware config & codegen resolution
154
+ │ ├── app.py # FastAPI server & API endpoints
155
+ │ ├── dsl_parser.py # DSL .txt → ModelProject dict
156
+ │ ├── dsl_emitter.py # ModelProject dict → DSL .txt
157
+ │ ├── bin/ # Bundled CODEGEN: lin/, win/, mac/ + LICENSE-CODEGEN
158
+ │ └── frontend/ # Static web assets (no build step)
159
+ │ ├── index.html
160
+ │ ├── css/style.css
161
+ │ ├── js/ # Vanilla JS modules
162
+ │ └── blocks.json # Block catalogue (54 blocks, extend here)
163
+ ├── tests/ # Pytest test suite (~150 tests)
164
+ ├── tools/ # Release automation: update_codegen.sh, bump_version.sh
165
+ ├── examples/ # Example DSL models (.txt) and projects (.json)
166
+ ├── docs/ # Design documents
167
+ ├── run.bat # Windows dev launcher
168
+ └── run.sh # Linux/macOS dev launcher
169
+ ```
170
+
171
+ ## Adding New Blocks
172
+
173
+ Edit `src/cg_studio/frontend/blocks.json`: add a single JSON entry with the block name, ports, argument schema, DSL line templates, and category. No JavaScript or Python changes required.
174
+
175
+ ## Running Tests
176
+
177
+ ```bash
178
+ # Install with dev dependencies
179
+ pip install -e ".[dev]"
180
+
181
+ # Run all tests
182
+ pytest tests/ -v
183
+
184
+ # Run specific test file
185
+ pytest tests/test_parser.py -v
186
+
187
+ # Run a single test
188
+ pytest tests/test_parser.py::test_function_name -v
189
+ ```
190
+
191
+ CI runs pytest on Python 3.10–3.12 via GitHub Actions.
192
+
193
+ ## Settings
194
+
195
+ Access via the gear icon in the toolbar:
196
+
197
+ - **Bundled CODEGEN**: which CODEGEN release this install runs. Read-only, and not a setting: the package version is derived from it, so running a different CODEGEN means installing a different `stepss-cg-studio`.
198
+ - **Server host**: change to `0.0.0.0` for network access (default: `127.0.0.1`)
199
+ - **Server port**: HTTP port (default: `8765`)
200
+
201
+ Settings are stored in a platform-specific config directory:
202
+ - **Windows:** `%LOCALAPPDATA%\cg-studio\config.json`
203
+ - **Linux/macOS:** `~/.config/cg-studio/config.json`
204
+
205
+ Also editable via the REST API at `http://localhost:8765/docs`.
206
+
207
+ ## Documentation
208
+
209
+ Full documentation is available at [https://stepss.sps-lab.org/developer/cg-studio/](https://stepss.sps-lab.org/developer/cg-studio/).
210
+
211
+ - [User-Defined Models](https://stepss.sps-lab.org/developer/user-models/): DSL format specification
212
+ - [CODEGEN Blocks Library](https://stepss.sps-lab.org/developer/codegen-library/): complete block reference
213
+ - [CODEGEN Model Examples](https://stepss.sps-lab.org/developer/codegen-examples/): annotated example files
214
+
215
+ ## Versioning
216
+
217
+ The version is `<bundled CODEGEN X.Y>.<counter>`, so the leading pair always names the generator in the wheel:
218
+
219
+ | Event | Version |
220
+ |---|---|
221
+ | CODEGEN v5.3 published | `5.3.0` |
222
+ | a change on the Python side | `5.3.1` |
223
+ | another change on the Python side | `5.3.2` |
224
+ | CODEGEN v5.4 published | `5.4.0` |
225
+
226
+ Publishing a CODEGEN release is what starts a sequence: `stepss-Codegen` tells this repository, `.github/workflows/sync-codegen-release.yml` refreshes the executables, proves the rebuilt wheel generates Fortran on all three platforms, and only then releases and publishes to PyPI. Nothing here is bumped by hand.
227
+
228
+ ## License
229
+
230
+ This package is **mixed-licence**, and the badge above says so on purpose.
231
+
232
+ - The Python and JavaScript in this repository are **Apache License 2.0**. See [LICENSE](LICENSE). Copyright © Petros Aristidou.
233
+ - The **CODEGEN executables bundled in the wheel are not**. CODEGEN is the property of **Dr. Thierry Van Cutsem** and is distributed as a compiled executable under an **Academic Public License**: free of charge for non-commercial use (teaching, and research at universities and non-profit institutions); commercial use requires a separate licence from the authors. Its source is in none of the public STEPSS repositories. The licence text ships beside the executables as `cg_studio/bin/LICENSE-CODEGEN`.
234
+
235
+ [STEPSS licensing](https://stepss.sps-lab.org/getting-started/license/) is the single owner of these facts; everything above is a summary of that page.
236
+
237
+ ## Authors
238
+
239
+ Developed and maintained by the [Sustainable Power Systems Laboratory (SPS-L)](https://sps-lab.org/) at the Cyprus University of Technology, under the direction of Dr. Petros Aristidou.
240
+
241
+ - [Dr. Petros Aristidou](https://sps-lab.org/): Cyprus University of Technology
242
+ - Dr. Thierry Van Cutsem: Emeritus, University of Liège
243
+
244
+ ## Support
245
+
246
+ - Documentation: [https://stepss.sps-lab.org/developer/cg-studio/](https://stepss.sps-lab.org/developer/cg-studio/)
247
+ - Issues: [https://github.com/SPS-L/stepss-cg-studio/issues](https://github.com/SPS-L/stepss-cg-studio/issues)
248
+ - Project page: [https://sps-lab.org/](https://sps-lab.org/)
@@ -0,0 +1,217 @@
1
+ [![PyPI version](https://img.shields.io/pypi/v/stepss-cg-studio)](https://pypi.org/project/stepss-cg-studio/)
2
+ [![CI](https://img.shields.io/github/actions/workflow/status/SPS-L/stepss-cg-studio/ci.yml?branch=main&label=tests)](https://github.com/SPS-L/stepss-cg-studio/actions)
3
+ [![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org/)
4
+ [![License](https://img.shields.io/badge/license-Apache%202.0%20%2B%20bundled%20CODEGEN-green.svg)](#license)
5
+ [![Docs](https://img.shields.io/github/actions/workflow/status/SPS-L/stepss-docs/deploy.yml?branch=main&label=docs)](https://stepss.sps-lab.org/developer/cg-studio/)
6
+
7
+ # CODEGEN Studio
8
+
9
+ CODEGEN Studio is a browser-based, drag-and-drop visual editor for building [STEPSS CODEGEN](https://stepss.sps-lab.org/developer/user-models/) User-Defined Models, part of the [STEPSS](https://stepss.sps-lab.org/) power system simulation platform. It lets you create device models by wiring blocks on a canvas instead of manually writing DSL files.
10
+
11
+ STEPSS has been developed by [Dr. Petros Aristidou](https://sps-lab.org/) (Cyprus University of Technology) and Dr. Thierry Van Cutsem (Emeritus, University of Liège).
12
+
13
+ ## Overview
14
+
15
+ CODEGEN Studio replaces the manual editing of CODEGEN DSL `.txt` files with a graphical workflow. You drag blocks from a categorised palette, connect input/output ports to define signal flow, fill in metadata tables, and export ready-to-compile DSL files, or run the bundled CODEGEN directly from the editor to generate Fortran `.f90` source.
16
+
17
+ The tool supports all four CODEGEN model types:
18
+
19
+ | Type | Purpose | Mandatory Outputs |
20
+ |------|---------|-------------------|
21
+ | **EXC** | Excitation controller | `vf` |
22
+ | **TOR** | Torque controller | `tm` |
23
+ | **INJ** | Current injector | `ix`, `iy` |
24
+ | **TWOP** | Two-port device | `ix1`, `iy1`, `ix2`, `iy2` |
25
+
26
+ ## Features
27
+
28
+ - **Drag-and-drop block diagram editor**: assemble models visually on a canvas with 54 built-in blocks
29
+ - **Live DSL preview**: syntax-highlighted code updates in real time as you edit
30
+ - **Lossless round-trip**: import existing `.txt` DSL files with automatic canvas layout, edit, and re-export
31
+ - **One-click Fortran generation**: the CODEGEN executables ship in the wheel, so this works on a fresh install
32
+ - **Project save/load**: JSON project files preserve full editor state including block positions
33
+ - **Mandatory output validation**: warns when required outputs for the model type are missing
34
+ - **Undo/redo**: 60-step history with keyboard shortcuts
35
+ - **Extensible block catalogue**: add new blocks via a single JSON entry, no code changes required
36
+ - **No build step**: vanilla JavaScript frontend served by a Python backend
37
+
38
+ ## Installation
39
+
40
+ ### Requirements
41
+
42
+ - Python ≥ 3.10
43
+ - A modern browser (Chrome, Firefox, or Edge)
44
+
45
+ ### Install from PyPI
46
+
47
+ ```bash
48
+ pip install stepss-cg-studio
49
+ ```
50
+
51
+ The CODEGEN executables are bundled in the wheel, for Linux x86-64, Windows x86-64 and macOS Apple Silicon. **Run Codegen works on a fresh install**: there is nothing to obtain, install or configure, and no setting to point anywhere.
52
+
53
+ macOS is the one platform that needs anything else:
54
+
55
+ ```bash
56
+ brew install gcc
57
+ ```
58
+
59
+ Apple does not support fully static executables, so that CODEGEN build links against `libgfortran`. The Linux and Windows builds are statically linked and need nothing at all.
60
+
61
+ The bundled CODEGEN is named in Settings (gear icon), and in the two leading components of this package's own version: `stepss-cg-studio` 5.3.0 and 5.3.1 both run CODEGEN 5.3. See [Versioning](#versioning).
62
+
63
+ ### Install from source (for development)
64
+
65
+ ```bash
66
+ git clone https://github.com/SPS-L/stepss-cg-studio.git
67
+ cd stepss-cg-studio
68
+ pip install -e ".[dev]"
69
+ ```
70
+
71
+ ## Quick Start
72
+
73
+ ```bash
74
+ cg-studio
75
+ ```
76
+
77
+ This starts the local server and opens your browser to the editor at `http://localhost:8765`. That's it.
78
+
79
+ You can also run it as a Python module:
80
+
81
+ ```bash
82
+ python -m cg_studio
83
+ ```
84
+
85
+ ### CLI options
86
+
87
+ ```bash
88
+ cg-studio --port 9000 # use a different port
89
+ cg-studio --host 0.0.0.0 # allow network access
90
+ cg-studio --no-browser # start server without opening browser
91
+ ```
92
+
93
+ ### Building a model
94
+
95
+ 1. **Select model type and name**: choose EXC, TOR, INJ, or TWOP from the toolbar dropdown
96
+ 2. **Add blocks**: drag blocks from the left-hand palette onto the canvas
97
+ 3. **Connect blocks**: wire output ports to input ports to define signal flow
98
+ 4. **Edit block properties**: select a block to configure output names and arguments in the inspector
99
+ 5. **Populate metadata**: fill in Data, Parameters, States, and Observables in the tabs below the canvas
100
+ 6. **Export**: click "Export DSL" for the `.txt` file, or "Run Codegen" to generate Fortran directly
101
+
102
+ ### Keyboard shortcuts
103
+
104
+ | Shortcut | Action |
105
+ |----------|--------|
106
+ | Ctrl/Cmd + S | Save project |
107
+ | Ctrl/Cmd + Z | Undo |
108
+ | Ctrl/Cmd + Shift + Z (or Ctrl/Cmd + Y) | Redo |
109
+ | Delete / Backspace | Delete selected block |
110
+ | Escape | Close modal |
111
+
112
+ ## Project Structure
113
+
114
+ ```
115
+ stepss-cg-studio/
116
+ ├── pyproject.toml # Package config, dependencies, entry point
117
+ ├── src/cg_studio/
118
+ │ ├── __init__.py # Package version (<bundled CODEGEN X.Y>.<counter>)
119
+ │ ├── _bundled.py # Which CODEGEN release bin/ holds
120
+ │ ├── __main__.py # python -m cg_studio support
121
+ │ ├── cli.py # CLI entry point (cg-studio command)
122
+ │ ├── config.py # Platform-aware config & codegen resolution
123
+ │ ├── app.py # FastAPI server & API endpoints
124
+ │ ├── dsl_parser.py # DSL .txt → ModelProject dict
125
+ │ ├── dsl_emitter.py # ModelProject dict → DSL .txt
126
+ │ ├── bin/ # Bundled CODEGEN: lin/, win/, mac/ + LICENSE-CODEGEN
127
+ │ └── frontend/ # Static web assets (no build step)
128
+ │ ├── index.html
129
+ │ ├── css/style.css
130
+ │ ├── js/ # Vanilla JS modules
131
+ │ └── blocks.json # Block catalogue (54 blocks, extend here)
132
+ ├── tests/ # Pytest test suite (~150 tests)
133
+ ├── tools/ # Release automation: update_codegen.sh, bump_version.sh
134
+ ├── examples/ # Example DSL models (.txt) and projects (.json)
135
+ ├── docs/ # Design documents
136
+ ├── run.bat # Windows dev launcher
137
+ └── run.sh # Linux/macOS dev launcher
138
+ ```
139
+
140
+ ## Adding New Blocks
141
+
142
+ Edit `src/cg_studio/frontend/blocks.json`: add a single JSON entry with the block name, ports, argument schema, DSL line templates, and category. No JavaScript or Python changes required.
143
+
144
+ ## Running Tests
145
+
146
+ ```bash
147
+ # Install with dev dependencies
148
+ pip install -e ".[dev]"
149
+
150
+ # Run all tests
151
+ pytest tests/ -v
152
+
153
+ # Run specific test file
154
+ pytest tests/test_parser.py -v
155
+
156
+ # Run a single test
157
+ pytest tests/test_parser.py::test_function_name -v
158
+ ```
159
+
160
+ CI runs pytest on Python 3.10–3.12 via GitHub Actions.
161
+
162
+ ## Settings
163
+
164
+ Access via the gear icon in the toolbar:
165
+
166
+ - **Bundled CODEGEN**: which CODEGEN release this install runs. Read-only, and not a setting: the package version is derived from it, so running a different CODEGEN means installing a different `stepss-cg-studio`.
167
+ - **Server host**: change to `0.0.0.0` for network access (default: `127.0.0.1`)
168
+ - **Server port**: HTTP port (default: `8765`)
169
+
170
+ Settings are stored in a platform-specific config directory:
171
+ - **Windows:** `%LOCALAPPDATA%\cg-studio\config.json`
172
+ - **Linux/macOS:** `~/.config/cg-studio/config.json`
173
+
174
+ Also editable via the REST API at `http://localhost:8765/docs`.
175
+
176
+ ## Documentation
177
+
178
+ Full documentation is available at [https://stepss.sps-lab.org/developer/cg-studio/](https://stepss.sps-lab.org/developer/cg-studio/).
179
+
180
+ - [User-Defined Models](https://stepss.sps-lab.org/developer/user-models/): DSL format specification
181
+ - [CODEGEN Blocks Library](https://stepss.sps-lab.org/developer/codegen-library/): complete block reference
182
+ - [CODEGEN Model Examples](https://stepss.sps-lab.org/developer/codegen-examples/): annotated example files
183
+
184
+ ## Versioning
185
+
186
+ The version is `<bundled CODEGEN X.Y>.<counter>`, so the leading pair always names the generator in the wheel:
187
+
188
+ | Event | Version |
189
+ |---|---|
190
+ | CODEGEN v5.3 published | `5.3.0` |
191
+ | a change on the Python side | `5.3.1` |
192
+ | another change on the Python side | `5.3.2` |
193
+ | CODEGEN v5.4 published | `5.4.0` |
194
+
195
+ Publishing a CODEGEN release is what starts a sequence: `stepss-Codegen` tells this repository, `.github/workflows/sync-codegen-release.yml` refreshes the executables, proves the rebuilt wheel generates Fortran on all three platforms, and only then releases and publishes to PyPI. Nothing here is bumped by hand.
196
+
197
+ ## License
198
+
199
+ This package is **mixed-licence**, and the badge above says so on purpose.
200
+
201
+ - The Python and JavaScript in this repository are **Apache License 2.0**. See [LICENSE](LICENSE). Copyright © Petros Aristidou.
202
+ - The **CODEGEN executables bundled in the wheel are not**. CODEGEN is the property of **Dr. Thierry Van Cutsem** and is distributed as a compiled executable under an **Academic Public License**: free of charge for non-commercial use (teaching, and research at universities and non-profit institutions); commercial use requires a separate licence from the authors. Its source is in none of the public STEPSS repositories. The licence text ships beside the executables as `cg_studio/bin/LICENSE-CODEGEN`.
203
+
204
+ [STEPSS licensing](https://stepss.sps-lab.org/getting-started/license/) is the single owner of these facts; everything above is a summary of that page.
205
+
206
+ ## Authors
207
+
208
+ Developed and maintained by the [Sustainable Power Systems Laboratory (SPS-L)](https://sps-lab.org/) at the Cyprus University of Technology, under the direction of Dr. Petros Aristidou.
209
+
210
+ - [Dr. Petros Aristidou](https://sps-lab.org/): Cyprus University of Technology
211
+ - Dr. Thierry Van Cutsem: Emeritus, University of Liège
212
+
213
+ ## Support
214
+
215
+ - Documentation: [https://stepss.sps-lab.org/developer/cg-studio/](https://stepss.sps-lab.org/developer/cg-studio/)
216
+ - Issues: [https://github.com/SPS-L/stepss-cg-studio/issues](https://github.com/SPS-L/stepss-cg-studio/issues)
217
+ - Project page: [https://sps-lab.org/](https://sps-lab.org/)