​

# DRAKON Editor 1.5 .drn file format

## Contents

- General notes
- Tables
  - info table
  - diagrams table
  - state table
  - diagram_info table
  - items table
  - tree_nodes table
- Items
  - Rectangular items
  - horizontal item
  - vertical item
  - arrow item
  - if item
  - commentout item
  - branch item
  - address item

## General notes

DRAKON Editor relies on SQLite to work with files. A .drn file is an SQLite 3.6 database.

DRAKON files are guaranteed to be backward and forward compatible within the major version. For example, DRAKON Editor 1.4 can use files created with DRAKON Editor 1.5 and vice-versa.

No conversion is needed when a new version of DRAKON Editor comes out.

There are free tools that can be used to read and edit SQLite database files, for example SQLite Database Browser.

The SQL script that creates the database is located in scripts/schema.sql. This script does not create the info table (which serves like a file signature).

## info table

General information related to the whole file. A record in this table is a property consisting of a key-value pair.

Field | Data type | Description
key | text, unique | The name of the property.
value | text | The value of the property.

Typical content of the info table:

key field | value field | Comment
type | drakon | This is a DRAKON Editor diagram file.
version | 5 | The minor version number: 1.5
start_version | 1 | The major version number: 1.5
language | c++ | The diagrams in this file can be used to generate C++ code.

## diagrams table

The list of diagrams.

The diagram coordinate space:

- X-axis is directed to the right.
- Y-axis is direct down.

Field | Data type | Description
diagram_id | integer, unique | The primary key.
name | text, unique | The name of the diagram.
origin | text | The position of the left top corner of the diagram viewport in the diagram coordinate space. Used for scrolling. The origin is stored as a tcl list with two elements. The first element is X, the second element is Y.
description | text | An optional text description of the diagram.
zoom | double | The visible scale of the diagram in percents. 100 means a one-to-one mapping between the screen space and the diagram space. 200 means the coordinate (10, 20) in the diagram transforms to (20, 40) on the screen.

## state table

Miscellaneous global information.

This table always contains only one row with the field "row" equal to 1.

Field | Data type | Description
row | integer, unique | Must be equal 1.
current_dia | integer | The currently visible diagram. A reference to the diagrams table.
description | text | An optional text description of the whole file.

## diagram_info table

Each diagram owns a list of properties in the form of key-value pairs.

Export parameters are stored as diagram properties.

Field | Data type | Description
diagram_id | integer | References the diagram that owns the property.
name | text | The name of the property.
value | text | The value of the property.

diagram_info table has a composite primary key: diagram_id, name.

## items table

Each diagram owns a list of items. An item is an object on the diagram, like an icon or a connector.

Field | Data type | Description
item_id | integer, unique | The primary key of the item.
diagram_id | integer | References the diagram that owns the item.
type | text | The type of the item. For example, action or beginend.
text | text | The text on the icon. Lines and arrows do not have text. Not all items can have text.
selected | integer | 1 if the item is selectd, 0 otherwise.
x | integer | The meaning depends on the item type. Usually, it is the X coordinate of the geometric center of the item.
y | integer | The meaning depends on the item type. Usually, it is the Y coordinate of the geometric center of the item.
w | integer | The meaning depends on the item type. Usually, it is a half of the width of the item.
h | integer | The meaning depends on the item type. Usually, it is a half of the height of the item.
a | integer | The meaning depends on the item type.
b | integer | The meaning depends on the item type.

## tree_nodes table

Each node in the main tree view control of DRAKON Editor is stored as a record in the tree_nodes table.

There are two kinds of nodes: folder nodes and diagram nodes.

There is a one-to-one link between diagram nodes and diagrams.

Field | Data type | Description
node_id | integer, unique | The primary key of the node.
parent | integer | References the node_id of the parent of this node.
type | text | The type of the node. Can be either folder or item.
name | text | For folder nodes, this field contains the text of the tree node. For diagram nodes, the text of the node is taken from diagram name.
diagram_id | integer | For diagram nodes, references the related diagram.

## Rectangular items

Items of these types have a similar form based on rectangle:

- action
- beginend
- case
- commentin
- insertion
- loopend
- loopstart
- select

Field | Data type | Description
x | integer | The X coordinate of the geometric center of the item.
y | integer | The Y coordinate of the geometric center of the item.
w | integer | A half of the width of the item.
h | integer | A half of the height of the item.
a | integer | Ignored.
b | integer | Ignored.

## horizontal item

The horizontal line.

Field | Data type | Description
x | integer | The X coordinate of the left end.
y | integer | The Y coordinate of the left end.
w | integer | The distance between the left and right ends.
h | integer | Ignored.
a | integer | Ignored.
b | integer | Ignored.

## vertical item

The vertical line.

Field | Data type | Description
x | integer | The X coordinate of the top end.
y | integer | The Y coordinate of the top end.
w | integer | Ignored.
h | integer | The distance between the top and bottom ends.
a | integer | Ignored.
b | integer | Ignored.

## arrow item

The arrow with two angles.

Field | Data type | Description
x | integer | The X coordinate of the top end of the vertical segment.
y | integer | The Y coordinate of the top end of the vertical segment.
w | integer | The length of the upper horizontal segment.
h | integer | The height of the vertical segment.
a | integer | The length of the lower horizontal segment.
b | integer | 0 if the arrow points to the left, 1 if to the right.

## if item

The if icon.

Field | Data type | Description
x | integer | The X coordinate of the geometric center of the item.
y | integer | The Y coordinate of the geometric center of the item.
w | integer | A half of the width of the item.
h | integer | A half of the height of the item.
a | integer | The length of the horizontal line at the right side.
b | integer | 0 means the right exit is YES. 1 means the right exit is NO.

## commentout item

A standalone comment icon.

Field | Data type | Description
x | integer | The X coordinate of the geometric center of the item.
y | integer | The Y coordinate of the geometric center of the item.
w | integer | A half of the width of the item.
h | integer | A half of the height of the item.
a | integer | The length of the horizontal line at the side.
b | integer | 0 if the horizontal line goes out of the left side, 1 if out of the right side.

## branch item

The header of a branch.

Field | Data type | Description
x | integer | The X coordinate of the geometric center of the item.
y | integer | The Y coordinate of the geometric center of the item.
w | integer | A half of the width of the item.
h | integer | A half of the height of the item.
a | integer | Ignored
b | integer | 1 if the icon has a cycle mark, 0 if the icon does not have a cycle mark.

## address item

The footer of a branch.

Field | Data type | Description
x | integer | The X coordinate of the geometric center of the item.
y | integer | The Y coordinate of the geometric center of the item.
w | integer | A half of the width of the item.
h | integer | A half of the height of the item.
a | integer | Ignored
b | integer | 1 if the icon has a cycle mark, 0 if the icon does not have a cycle mark.