What is this?

This program lets you view, edit and simulate petri nets. It's also possible to model other kinds of graphs, like state machines and dependency graphs, which are bascially subsets of petri nets. It uses pnrs, a safe rust wrapper for pns, to load, edit and simulate the petri nets.

In case the program runs slow, try to compile using the --release option for Cargo.

Example

Here an example of how the editor looks like:

example

Usage

Standard Options

Saving and loading

Multiple files are generated when saving and loaded when loading: * Petri net simulation .pns: - contains the logical contents of the petri net - the exact format is described here * Petri net keys .pnk: - a list of names for all the transitions - if it's missing when loading, the names will be generated automatically * Petri net keys for places .pnkp: - a list of names for all the places - if it's missing when loading, the names will be empty * Petri net layout .pnl: - describes the layout of the petri net - if it's missing when loading, the layout will be generated automatically

Saving and loading while a simulation is active works different and is described later.

Editing

General controls

While editing, the keys Shift, Ctrl and Alt basically have the following meaning: * Shift: Edit multiple objects * Ctrl: Create objects * Alt: Remove objects

Both mouse buttons are mainly used for these tasks: * Left: Edit nodes * Right: Edit connections

Specific controls

When pressing Ctrl + Left, a new transition node is created. When pressing Ctrl + Right, a new place node is created.

When clicking a node, it will be selected. Selected nodes can be moved around. When clicking at some other node or at empty space, the selected nodes will be deselected.

When Shift is pressed while clicking a node, it will be selected additionally. When a new node is created while holding Shift, the previously selected nodes won't be deselected.

When clicking Alt + Left above a node, it will be removed from the currently selected bides.

When clicking a node with Ctrl + Left, it will be duplicated. Both nodes will use the same input and output connections.

When clicking a node with Right and releasing it above another node, both nodes will be connected. If multiple nodes are selected, all will be connected to the last node. If both nodes are of the same type, a new node of the other type will be inserted between them. When also holding Ctrl, releasing in empty space will create a new node of the other type there, when releasing on the same node, a bidirectional connecton to a new node will be created.

Alt + Right will remove connections between two nodes. If both nodes are of the same type, all connections to all nodes between them will be removed.

Copying and Pasting

When copying something from a net, all selected nodes and connections between them are affected. The copy can be pasted anywhere, in the same program, even after loading a different net, in another program or even in text editors.

The copy will store the position relative to the mouse, so moving the mouse before pasting will change the position.

Pasting will always create new nodes for everything and never connect to existing nodes.

It's even possible to edit the pasted data as text and copy this text into the editor.

The format is similar to the binary format, but it's a text format and also contains information about the layout and transition names.

Searching

Ctrl + F enters search mode. In search mode, you can enter a name and one of the matching nodes is focused.

Tab will let you look at different nodes with matching names. First it will focus all matching transitions, then all matching places. It's also possible to switch between places and transitions faster by pressing Ctrl + Tab.

Pressing Return will finish the search and select the focused node. Holding Ctrl while finishing will select all matching nodes. Holding Shift will in both cases select them additionally.

Simulation

Pressing Tab will switch to simulation mode. In simulation mode editing is slightly restricted.

Press Tab again to go back to edit mode.

When in simulation mode, to play and pause the simulation, press Ctrl + P.

When the simulation is active, pressing Tab does not go back to edit mode. Instead it just selects the next simulation state.

Also Ctrl + L and Ctrl + S loads and saves the currently active state as /path/to/file.pni instead of the net itself. Loading will add a new state.

Adding a new state is possible using Ctrl + A in simulation mode.

When the simulation is started, click left on some transition to fire it, if possible. Click right to unfire transitions again. Unfireing is possible in any order, that does not create invalid state.

Pausing simulations using Ctrl + P again won't delete the current state. The editing restrictions allow modifications of the net without having invalid states afterwards. This means, all possible order of actions will still be possible after the editing.

Switching back to edit mode will destroy all states, so be sure to safe them, in case you don't want to make unsafe edits to the net.

Searching also works in this mode.

View Modes

There are three modes: * default mode * state mode * actions mode

Default mode is the most powerful mode, since it gives access to the full petri net. The other modes are restricted, but they have specific features.

Both restricted modes hide one of the node types, so it's easier to overview it. When creating a connected place or transition, the end node will always be of the same type and the hidden node type will be inserted implicitly.

State mode only gives access to the state of the petri net, represented by the places. It's bascially a state machine then. It's mostly useful for switching between alternative states or stories with multiple alternatives. A common example are visual novels.

Actions mode only gives access to the actions of the petri net, represented by transitions. It's basically a dependency graph then. It's mostly useful, when things are never alternative, and calling actions only allows new actions, never remove old ones. A common example are metroidvania games.