> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ploterr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ManagedPlanEditor

> ManagedPlanEditor is the 2D plan editor.

It shows one saved plan view and lets the user edit walls and openings. Each edit goes through a `BuildingSession`, so undo and redo work.

## Import

```typescript theme={null}
import { ManagedPlanEditor } from '@opengeometry/floorkit';
```

## Example

```typescript theme={null}
import { ManagedPlanEditor, type ProjectFile, type BuildingSession } from '@opengeometry/floorkit';

export async function mountPlan(
  project: ProjectFile,
  viewId: string,
  container: HTMLElement,
  session: BuildingSession,
): Promise<ManagedPlanEditor> {
  const plan = new ManagedPlanEditor(project, viewId, { session });
  plan.onError = (error) => console.error('Plan edit rejected', error);
  try {
    await plan.mount(container);
    return plan;
  } catch (error) {
    plan.dispose();
    throw error;
  }
}
```

## Notes

* The view must be a saved plan in the project.
* Give the same session to each plan editor and to the 3D editor. Then all of them show the same building.
* `save()` returns the project text with the current building.
* Set `onError` to show an edit that Floorkit rejected.
* If you give a session, you own it. Dispose the editors first, then the session. If you give none, the editor makes one and disposes it.

## Constructor

```typescript theme={null}
constructor(project: ProjectFile, viewId: string, options?: ManagedPlanEditorOptions);
```

<ParamField path="options.session" type="BuildingSession">
  Share one saved building session across several plans and a 3D view.
</ParamField>

<ParamField path="options.build" type="Pick<BuildOptions, &#x22;assetSources&#x22; | &#x22;massColors&#x22; | &#x22;stampMembership&#x22;>" />

<ParamField path="options.hostedOpeningDetachTolerance" type="number">
  Metres from every wall beyond which a dragged door or window leaves its wall; default 0.35.
</ParamField>

<ParamField path="options.history" type="ManagedEditHistory">
  Undo and redo through another history, such as a project manager; default is the session.
</ParamField>

<ParamField path="options.checkCommand" type="((command: BuildingEditCommand) => void)">
  Refuse a command before a gesture of this plan saves it; throw to refuse. A project manager passes
  its storey-in-use rule, as it does to a bound 3D editor.
</ParamField>

<ParamField path="options.storeyInUse" type="((storeyId: string) => boolean)">
  Whether a saved view names the storey; Delete of a part of a mass keeps such a storey.
</ParamField>

## Properties

<ResponseField name="session" type="BuildingSession">
  Read-only.
</ResponseField>

<ResponseField name="viewId" type="string">
  Read-only.
</ResponseField>

<ResponseField name="onError" type="(error: unknown) => void" />

<ResponseField name="lastError" type="unknown" />

<ResponseField name="renderer" type="ModelScreenRenderer | undefined">
  Read-only. The renderer of the plan. Assign `renderer.onDrag` for live figures during a grip drag
  (the same rules as `GUIEditor.onDrag`), and `renderer.onChange` for each saved edit.
</ResponseField>

## Methods

### mount

```typescript theme={null}
mount(container: HTMLElement): Promise<ModelScreenRenderer>;
```

Mount the editable plan once; callers may mount session.root in their 3D scene.

### startWallDrawing

```typescript theme={null}
startWallDrawing(wall: WallDrawingTemplate): void;
```

Collect a saved wall axis on this plan.

### startOutlineDrawing

```typescript theme={null}
startOutlineDrawing(options?: OutlineDrawingOptions): Promise<PointXZ[] | undefined>;
```

Let the user draw a closed outline on this plan and resolve with it, in site XZ metres (the plan's model coordinates), without saving anything; `undefined` when the user presses Escape or the draft ends otherwise (another gesture, a change of the model, `dispose`).

### startMassDrawing

```typescript theme={null}
startMassDrawing(options: MassDrawingOptions): Promise<string | undefined>;
```

Let the user draw the outline of a new building with one mass, then save it as one step (`add-building` from `massBuildingCommand`; `renderer.onChange` gets a `create`) and resolve with the id of the new mass.

### projectSnapshot

```typescript theme={null}
projectSnapshot(): ProjectFile;
```

### save

```typescript theme={null}
save(): string;
```

### setProject

```typescript theme={null}
setProject(project: ProjectFile): void;
```

Replace the saved views, sheets and markers of this plan; a mounted plan draws again.

### undo

```typescript theme={null}
undo(): number | null;
```

Undo one step of `history`, or of the session; renderer.onChange gets a changed building.

### redo

```typescript theme={null}
redo(): number | null;
```

Redo one step of `history`, or of the session; renderer.onChange gets a changed building.

### dispose

```typescript theme={null}
dispose(): void;
```

## Types

### ManagedPlanEditorOptions

```typescript theme={null}
interface ManagedPlanEditorOptions {
  session?: BuildingSession;
  build?: Pick<BuildOptions, 'assetSources' | 'stampMembership' | 'massColors'>;
  hostedOpeningDetachTolerance?: number;
  history?: ManagedEditHistory;
  checkCommand?(command: BuildingEditCommand): void;
  storeyInUse?(storeyId: string): boolean;
}
```

### WallDrawingTemplate

The package does not export this type by name.

```typescript theme={null}
type WallDrawingTemplate = Omit<WallCreateCommand['wall'], 'points' | 'closed'>;
```

### OutlineDrawingOptions

How `ManagedPlanEditor.startOutlineDrawing` collects the outline.

```typescript theme={null}
interface OutlineDrawingOptions {
  mode?: 'free' | 'rectangle';
}
```

<ResponseField name="mode" type="'free' | 'rectangle'">
  `free` (the default): each click adds a corner; a click on the first corner, Enter or a double
  click closes the outline once it has three corners. `rectangle`: two clicks at opposite corners.
</ResponseField>

### MassDrawingOptions

The new building of `ManagedPlanEditor.startMassDrawing`, and how its outline is drawn.

```typescript theme={null}
interface MassDrawingOptions extends MassBuildingOptions, OutlineDrawingOptions {}
```

### ManagedEditHistory

The package does not export this type by name.

```typescript theme={null}
interface ManagedEditHistory {
  undo(): number | null;
  redo(): number | null;
}
```

## Related

* [`BuildingSession`](/floorkit/api/editor/building-session)
* [`BuildingEditCommand`](/floorkit/api/editor/building-session#buildingeditcommand)
* [`BuildOptions`](/floorkit/api/architecture/build-from-building-model#buildoptions)
* [`MassBuildingOptions`](/floorkit/api/architecture/massing-helpers#massbuildingoptions)
* [`PointXZ`](/floorkit/api/primitives/polygon-maths#pointxz)
* [`ProjectFile`](/floorkit/api/exports/project-file#projectfile)
* [`WallCreateCommand`](/floorkit/api/editor/building-session#wallcreatecommand)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.