#editor #edit #view #model #graphs #safe #wrapper #powerful

app pn-editor

A powerful program to view, edit and simulate petri nets

13 releases

✓ Uses Rust 2018 edition

0.4.3 Oct 12, 2019
0.4.2 Oct 6, 2019
0.3.10 Oct 5, 2019
0.3.4 Sep 30, 2019

#33 in Text editors

Download history 67/week @ 2019-09-25 141/week @ 2019-10-02 55/week @ 2019-10-09 66/week @ 2019-10-16 91/week @ 2019-10-23 60/week @ 2019-10-30

77 downloads per month


2.5K SLoC

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.


Here an example of how the editor looks like:



Standard Options

  • Del: Remove selected
  • Ctrl + O: Load petri net from file
  • Ctrl + S: Save petri net to file
  • Ctrl + F: Search for node by name
  • Ctrl + N: Reset and use empty petri net
  • Ctrl + P: Play simulation (also switches to simulation mode)
  • Ctrl + C: Copy selected
  • Ctrl + V: Paste selected
  • Ctrl + X: Cut selected
  • Ctrl + 1: Set view mode to default; see and edit everything
  • Ctrl + 2: Set view mode to state; see and edit only places
  • Ctrl + 3: Set view mode to actions; see and edit only transitions

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.


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.


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.


Pressing Ctrl + P will switch to simulation mode. In simulation mode editing is slightly restricted, but it's possible to simulate the net.

Clicking Alt + Left on a transition will fire it if possible, Alt + Right will unfire it again.

Unfireing is even possible in a different order.

It's always ensured, the state of the petri net is valid in edit mode, so unfireing is not possible for every fired transition. Also editing is restricted to be only possible, if no potential state could have taken a route, that's not possible after the edit anymore.

Pressing Ctrl + P again reverts to edit mode.

Ctrl + A will add a new empty state to the simulation.

Tab will switch between different states.

Saving and loading just works as before, but is applied to the states instead of the net. In order to save the net, you have to go back to edit mode. When loading, a new state will be created and added.

Except of the restriction, most features work in this mode, also searching. Duplication and copying will not necessarily copy the current token counts. The exact token counts are calculated dynamically based on the calls of the transitions, so this wouldn't make sense.

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.


~133K SLoC