discontinuedPackage jet_cad_floor_plan has been discontinued and replaced by jet_cad_2d_plan.

accept method

  1. @override
void accept(
  1. Vector2 point,
  2. ToolContext ctx
)

Implementation

@override
void accept(Vector2 point, ToolContext ctx) {
  final doc = ctx.document;
  _preview = const [];
  _onHost = false;
  final host = _hostAt(doc, _raw);
  if (host == null || !_ready(doc, host)) return;
  try {
    commit(ctx, () {
      // The new opening's handle, allocated first (after the permission
      // check, Ruling 05-3): the placement is decided among the host's
      // openings in ascending handle order (D8's "a wall keeps a piece"),
      // and this one takes its place there.
      final h = doc.handleSeed.next();
      final placed = _place(host, _raw, point, h);
      return CompoundCommand([
        AddNodeCommand(GroupNode(
            handle: h,
            parent: doc.rootHandle,
            transform: Transform2.identity(),
            children: const [])),
        SetComponentCommand<OpeningParams>(h, placed.params),
        // Spec 12b D2: a new object takes the current layer.
        SetComponentCommand<ObjectLayer>(h, ObjectLayer(drawingLayer(doc))),
      ], label: 'Add $name');
    }, needs: const {
      Capability.structure,
      Capability.components,
      Capability.geometry,
    });
  } on ArgumentError {
    // A malformed host from a file: nothing is placed.
  } on StateError {
    // Likewise.
  } on DanglingReferenceError {
    // The host stopped being an object: nothing is placed.
  }
}