# Referencia: Formato XML do Arquivo .process

## Visao Geral

Arquivos `.process` sao XML com namespace XMI, gerados pelo editor BPMN do Fluig Studio/Eclipse.
Contem duas secoes principais:

1. **pi:Diagram** — Layout visual (posicoes, cores, estilos dos elementos)
2. **bpmn2:*** — Modelo BPMN semantico (atividades, flows, gateways)

## Namespaces

```xml
xmlns:xmi="http://www.omg.org/XMI"
xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL-XMI"
xmlns:pi="http://eclipse.org/graphiti/mm/pictograms"
xmlns:al="http://eclipse.org/graphiti/mm/algorithms"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
```

## Secao bpmn2 — Elementos BPMN

### BpmnProcess (metadados do processo)

```xml
<bpmn2:BpmnProcess
    id="FIN_SLIP_001"
    name="Solicitacao de SLIP"
    cardIndex="517899"
    version="24"
    formSource="server"
    author="admin"
    serverId="Producao"
    category=""
    expedient="Default"
    complementsLevel="1"
/>
```

| Atributo | Descricao |
|---|---|
| `id` | Codigo do processo (usado em hAPI.startProcess) |
| `name` | Nome exibido |
| `cardIndex` | ID do formulario vinculado |
| `version` | Versao atual do processo |
| `formSource` | "server" = formulario server-side, "local" = incorporado |

### BpmnStartEvent

```xml
<bpmn2:BpmnStartEvent
    id="startevent1"
    name="Inicio"
    outgoing="flow3"
    type="10"
    selecionaColaboradores="1"
    signalId="0"
/>
```

| type | Significado |
|---|---|
| 10 | None (inicio normal) |
| 20 | Timer |
| 30 | Message |

### BpmnTask (atividade humana)

```xml
<bpmn2:BpmnTask
    id="task5"
    name="Aprovacao do Gestor"
    incoming="flow6"
    outgoing="flow8"
    type="80"
    selecionaColaboradores="1"
    authNotify="true"
    loopType="0"
    executionAttempts="0"
    frequency="0"
    expediente=""
/>
```

**Regra do activityId:** sufixo numerico do `id` → `task5` = activityId **5**

### BpmnEndEvent

```xml
<bpmn2:BpmnEndEvent
    id="endevent14"
    name="Cancelado"
    incoming="flow15"
    type="60"
    signalId="0"
/>
```

| type | Significado |
|---|---|
| 60 | None (fim normal) |
| 70 | Terminate |

### SequenceFlow (conexoes)

```xml
<bpmn2:SequenceFlow
    id="flow6"
    name=""
    sourceRef="startevent4"
    targetRef="task5"
    permiteRetorno="true"
    atividadeFluxo=""
    atividadeRetorno=""
/>
```

| Atributo | Descricao |
|---|---|
| `sourceRef` | Elemento de origem |
| `targetRef` | Elemento de destino |
| `permiteRetorno` | Se "true", fluxo bidirecional |
| `name` | Label exibido na seta |

### BpmnSwimLane (raias)

```xml
<bpmn2:BpmnSwimLane id="swimlane2" name="Solicitante" cores="9F9F9F"/>
<bpmn2:BpmnSwimLane id="swimlane3" name="Aprovador" cores="C0C0C0"/>
```

### BpmnPool (container)

```xml
<bpmn2:BpmnPool id="pool1" name="Nome do Processo" cores="FFFFFF"/>
```

## Secao pi:Diagram — Layout Visual

### Estrutura de Children

Cada elemento BPMN tem um `<children>` correspondente com:
- `<link businessObjects="taskN"/>` — vincula ao elemento BPMN
- `<graphicsAlgorithm x="190" y="188" width="105" height="56"/>` — posicao
- `<children><graphicsAlgorithm value="Nome da Atividade"/></children>` — label visual

### Mapeamento Swimlane ↔ Atividade

A associacao e feita por sobreposicao de coordenadas Y:
- Swimlane: `y=0, height=136` → faixa vertical 0-136px
- Atividade com `y=62` → esta dentro da swimlane

## Exemplo Minimo Completo

```xml
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmlns:xmi="http://www.omg.org/XMI"
          xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL-XMI"
          xmi:version="2.0">

  <bpmn2:BpmnPool id="pool1" name="Aprovacao Simples"/>
  <bpmn2:BpmnSwimLane id="lane2" name="Solicitante"/>
  <bpmn2:BpmnSwimLane id="lane3" name="Aprovador"/>

  <bpmn2:BpmnStartEvent id="startevent1" name="Inicio" outgoing="flow2" type="10"/>
  <bpmn2:BpmnTask id="task3" name="Solicitar" incoming="flow2" outgoing="flow4" type="80"/>
  <bpmn2:BpmnTask id="task5" name="Aprovar" incoming="flow4" outgoing="flow6" type="80"/>
  <bpmn2:BpmnEndEvent id="endevent7" name="Fim" incoming="flow6" type="60"/>

  <bpmn2:SequenceFlow id="flow2" sourceRef="startevent1" targetRef="task3"/>
  <bpmn2:SequenceFlow id="flow4" sourceRef="task3" targetRef="task5"/>
  <bpmn2:SequenceFlow id="flow6" sourceRef="task5" targetRef="endevent7"/>

  <bpmn2:BpmnProcess id="AprovacaoSimples" name="Aprovacao Simples"
                      cardIndex="1234" version="1" formSource="server"/>
</xmi:XMI>
```

**activityIds extraidos:** start=1, task3=3, task5=5, end=7
**WKNumState no displayFields:** `if (numState == 3)` e `if (numState == 5)`
