Vehicle System: Full SysML v2 Demo¶
A complete worked example showing every major SysML v2 element type and
every diagram path provided by sphinx-need-sysml — both the
PlantUML directives (needsysml-bdd, needsysml-ibd,
needsysml-req) and the inline-SVG variants powered by
sphinx-need-svg (needsysml-bdd-svg and raw needsvg
templates).
Setup¶
Enable the extensions in docs/conf.py:
extensions = [
"sphinx_needs",
"sphinxcontrib.plantuml",
"sphinx_need_sysml",
"sphinx_need_svg", # optional, enables SVG diagrams
]
plantuml_output_format = "svg" # required for clickable PlantUML links
Structural Model¶
The vehicle decomposes into a powertrain (engine + transmission) and a chassis with four wheels.
PartDefs (definitions)¶
Top-level vehicle system. |
Powertrain subsystem: engine plus transmission. |
Internal combustion engine. |
Multi-speed gearbox. |
Vehicle chassis carrying the wheels. |
Wheel and tyre assembly. |
Parts (usages)¶
The vehicle’s powertrain instance. |
The engine instance. |
The transmission instance. |
The chassis instance. |
Ports and Connections¶
Ports specify how parts interface; connections wire compatible ports together.
Fuel inlet port type. |
Rotational power output port type. |
Rotational power input port type (conjugate of POD-002). |
Connector type carrying rotational power. |
Wires engine |
|
Package Organization¶
Packages organize the model into nested groupings, with cross-package dependencies labelled by kind.
Package Definitions¶
Top-level package for the whole vehicle system. |
Dependencies¶
Package Diagram (PlantUML)¶
.. needsysml-pkg:: PKG-001
:align: center
Package Diagram (SVG)¶
.. needsysml-pkg-svg:: PKG-001
:align: center
Use Cases¶
Use cases capture stakeholder-system interactions inside a system
boundary. Actor.interacts_with wires actors to use cases;
UseCase.extends / .includes / .generalizes wire use cases
to each other.
Actors¶
Use Cases¶
Use Case Diagram (PlantUML)¶
.. needsysml-uc::
:align: center
Use Case Diagram (SVG)¶
.. needsysml-uc-svg::
:align: center
Sequence¶
A sequence diagram captures the cross-component interaction during
key-on ignition: Driver → ECU → Starter. The two combined
fragments illustrate an alt (sync vs. accessory mode) and a loop
(warm-up).
Action Definition¶
Key-on ignition interaction across Driver, ECU, and Starter. |
Lifelines¶
Messages¶
Sequence Diagram (PlantUML)¶
.. needsysml-sd:: AD-010
:align: center
Sequence Diagram (SVG)¶
.. needsysml-sd-svg:: AD-010
:align: center
Activity Diagram¶
needsysml-act walks the ActionDef’s owned actions, groups them
into swimlanes by :partition:, and connects them via the
controlflow (and optional objectflow) edges.
Action Definitions¶
Cold-start sequence for the engine. |
Control Flows¶
Activity Diagram (PlantUML)¶
.. needsysml-act:: AD-001
:show-partitions: true
:align: center
Activity Diagram (SVG)¶
.. needsysml-act-svg:: AD-001
:align: center
State Machine Diagram¶
needsysml-stm walks the StateDef’s usages and renders them with
their transitions. Pseudostates (initial / final / history / choice /
junction) appear with their UML notation.
State Definitions¶
Lifecycle states of the engine. |
Transitions¶
State Machine Diagram (PlantUML)¶
.. needsysml-stm:: SD-001
:align: center
State Machine Diagram (SVG)¶
.. needsysml-stm-svg:: SD-001
:align: center
Block Definition Diagram¶
needsysml-bdd renders a class-diagram BDD with composition arrows
via PlantUML.
Block Definition Diagram (PlantUML)¶
.. needsysml-bdd:: PD-001
:depth: 2
:scale: 80%
:align: center
Block Definition Diagram (SVG)¶
.. needsysml-bdd-svg:: PD-001
:align: center
Custom SVG with needsvg¶
For full control, drop into a raw needsvg directive and use the
Jinja helpers (needs, filter, flow, ref) directly.
.. needsvg::
:align: center
{% set root_id = "PD-002" %}
{% set root = needs.get(root_id) %}
{% set children = filter("type == 'partdef' and owned_by == '" + root_id + "'") %}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 240">
<g transform="translate(240, 20)">{{ flow(root_id) }}</g>
{% for child in children %}
{% set cx = 150 * loop.index %}
<line x1="300" y1="60" x2="{{ cx }}" y2="180"
stroke="#336699" stroke-width="1.5"/>
<g transform="translate({{ cx - 60 }}, 180)">{{ flow(child.id) }}</g>
{% endfor %}
</svg>
Internal Block Diagram¶
needsysml-ibd renders an IBD showing parts and their ports inside a
boundary rectangle.
Internal Block Diagram (PlantUML)¶
.. needsysml-ibd:: PD-002
:show-ports: true
:align: center
Internal Block Diagram (SVG)¶
.. needsysml-ibd-svg:: PD-002
:align: center
Requirements¶
Requirements link to the structural elements they govern via
satisfies, refines, and allocates.
Requirement Definitions¶
Abstract base for vehicle safety requirements. |
The vehicle shall stop within 50 m from 100 km/h. |
The engine shall produce at least 150 kW at 5000 rpm. |
The vehicle shall achieve 6 L / 100 km combined cycle. |
The vehicle shall accelerate 0 to 100 km/h in under 8 s. |
Requirements Diagram (PlantUML)¶
.. needsysml-req:: type == 'requirement'
:show-satisfy: true
:show-refine: true
:show-allocate: true
:align: center
Requirements Diagram (SVG)¶
A simple SVG list of requirements with their satisfy links, built using
needsvg:
.. needsvg::
:align: center
{% set reqs = filter("type == 'requirement'") | list %}
<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 640 {{ 40 + (reqs | length) * 60 }}">
{% for r in reqs %}
<g transform="translate(20, {{ 20 + loop.index0 * 60 }})">
<a href="{{ ref(r.id) }}">
<rect width="120" height="40" rx="4" fill="#ddeeff" stroke="#336699"/>
<text x="60" y="16" text-anchor="middle" font-size="10" fill="#666">{{ r.id }}</text>
<text x="60" y="30" text-anchor="middle" font-size="11">{{ r.title }}</text>
</a>
</g>
{% if r.satisfies %}
<text x="160" y="{{ 45 + loop.index0 * 60 }}"
font-family="sans-serif" font-size="11" fill="#444">
satisfies → {{ r.satisfies }}
</text>
{% endif %}
{% endfor %}
</svg>
Query Tables¶
Once the model is in place, sphinx-needs queries work across every
SysML element:
.. needtable::
:filter: type == 'requirement' and satisfies != ""
:columns: id, title, satisfies, refines, status
ID |
Title |
Satisfies |
Refines |
Status |
|---|---|---|---|---|
Braking Distance |
PD-001 |
RD-001 |
||
Engine Power |
PD-003 |
|||
Fuel Efficiency |
PD-001 |
|||
Acceleration |
PD-001 |
RD-001 |
.. needtable::
:filter: type == 'part'
:columns: id, title, definition, owned_by
ID |
Title |
Definition |
Owned By |
|---|---|---|---|
powertrain |
PD-002 |
PD-001 |
|
engine |
PD-003 |
PD-002 |
|
transmission |
PD-004 |
PD-002 |
|
chassis |
PD-005 |
PD-001 |
|
front_left_wheel |
PD-006 |
PD-005 |
|
front_right_wheel |
PD-006 |
PD-005 |
|
rear_left_wheel |
PD-006 |
PD-005 |
|
rear_right_wheel |
PD-006 |
PD-005 |
Allocation Matrix¶
The needsysml-alloc directive renders a traceability table showing
which requirements allocate to which parts. Rows are needs with
non-empty allocates; columns are the unique part IDs referenced.
P-002 |
|
|---|---|
A-001 |
|
A-002 |
|
A-003 |
|
A-004 |
|
A-005 |
|
A-006 |
|
A-007 |
|
ACTOR-001 |
|
ACTOR-002 |
|
AD-001 |
|
AD-010 |
|
C-001 |
|
C-002 |
|
CD-001 |
|
CTRLFLOW-001 |
|
CTRLFLOW-002 |
|
CTRLFLOW-003 |
|
CTRLFLOW-004 |
|
CTRLFLOW-005 |
|
CTRLFLOW-006 |
|
CTRLFLOW-007 |
|
DEP-001 |
|
DEP-002 |
|
LIFELINE-001 |
|
LIFELINE-002 |
|
LIFELINE-003 |
|
MSG-001 |
|
MSG-002 |
|
MSG-003 |
|
MSG-004 |
|
P-001 |
|
P-002 |
|
P-003 |
|
P-004 |
|
P-005 |
|
P-006 |
|
P-007 |
|
P-008 |
|
PD-001 |
|
PD-002 |
|
PD-003 |
|
PD-004 |
|
PD-005 |
|
PD-006 |
|
PKG-001 |
|
PKG-002 |
|
PKG-003 |
|
PKG-004 |
|
PO-001 |
|
PO-002 |
|
PO-003 |
|
PO-004 |
|
PO-005 |
|
POD-001 |
|
POD-002 |
|
POD-003 |
|
R-001 |
|
R-002 |
|
R-003 |
✓ |
R-004 |
|
RD-001 |
|
SD-001 |
|
SU-001 |
|
SU-002 |
|
SU-003 |
|
SU-004 |
|
TRANS-001 |
|
TRANS-002 |
|
TRANS-003 |
|
TRANS-004 |
|
TRANS-005 |
|
USECASE-001 |
|
USECASE-002 |
|
USECASE-003 |
|
USECASE-004 |
You can also filter explicitly:
.. needsysml-alloc::
:rows: type == 'requirement'
:columns: type == 'part'
Parametric Diagram¶
Parametric diagrams show constraint blocks with their parameters and binding connectors to value properties. PlantUML uses a class-diagram approximation.
Constraint Parameters¶
Value Properties¶
Binding Connectors¶
Parametric Diagram (PlantUML)¶