discontinuedPackage jet_cad_floor_plan has been discontinued and replaced by jet_cad_2d_plan.

placeSymbol function

CompoundCommand placeSymbol(
  1. DraftDocument doc,
  2. SymbolEntry entry, {
  3. required Vector2 at,
  4. int quarterTurns = 0,
  5. bool mirrored = false,
  6. Transform2? transform,
  7. InstanceStyle style = const InstanceStyle(),
  8. bool numbered = true,
})

The command that places entry in doc at at. Labelled Place <name>; it does not execute.

Every handle is allocated from doc.handleSeed here, once (spec F-8), so a redo reuses them. A definition already in doc with the entry's key and version is reused when it is leaf-equal to the entry (isLeafEqual, spec 09c D10), the first such in ascending handle; otherwise the definition is copied with fresh handles for it and for every leaf, the leaves in the library's ascending order so draw order is stable, under the first free name of key@version, key@version#2, #3, ...

A servable entry becomes a numbered table (spec 14a T13): when numbered, its label, with the plan's next number, is added after the instance and stamped upright for the placement. The palette's thumbnails pass numbered: false (F-15). The number is fixed here, with the handles, so a redo replays the same one.

Implementation

CompoundCommand placeSymbol(
  DraftDocument doc,
  SymbolEntry entry, {
  required Vector2 at,
  int quarterTurns = 0,
  bool mirrored = false,
  Transform2? transform,
  InstanceStyle style = const InstanceStyle(),
  bool numbered = true,
}) {
  final made = definitionForEntry(doc, entry);
  final commands = <DraftCommand>[...made.commands];
  final definition = made.definition;

  final instance = doc.handleSeed.next();
  final placement = transform ??
      placementTransform(
        at: at,
        basePoint: entry.definition.basePoint,
        quarterTurns: quarterTurns,
        mirrored: mirrored,
      );
  commands.add(AddNodeCommand(InstanceNode(
    handle: instance,
    parent: doc.rootHandle,
    definition: definition,
    // Spec 12b D7: the instance takes the current layer; the definition's
    // leaves stay on layer 0 (the library's rule) and follow it.
    layer: drawingLayer(doc),
    transform: placement,
    color: style.color,
    lineweight: style.lineweight,
    transparency: style.transparency,
    linetype: style.linetype,
    linetypeScale: style.linetypeScale,
  )));

  if (numbered && entry.seats != null) {
    final first = entry.leaves.isEmpty ? null : entry.leaves.first;
    commands.add(AddEntityCommand(
      record: tableLabelRecord(
        handle: doc.handleSeed.next(),
        instance: instance,
        number: nextTableNumber(TableSurvey.of(doc).numbers),
      ),
      payload: tableLabelPayload(
        anchor: entry.definition.basePoint,
        height: first == null
            ? kTableLabelMaxHeight
            : tableLabelHeight(first.record.kind, first.payload),
        placement: placement,
      ),
    ));
  }

  return CompoundCommand(commands, label: 'Place ${entry.name}');
}