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) {
  if (points.isEmpty) {
    points.add(point);
    return;
  }
  final c1 = points.first;
  if (isDegenerateRectangle(c1, point)) return;
  commit(ctx, () {
    final doc = ctx.document;
    final h = doc.handleSeed.next();
    final minX = c1.x < point.x ? c1.x : point.x;
    final minY = c1.y < point.y ? c1.y : point.y;
    return CompoundCommand([
      AddNodeCommand(GroupNode(
          handle: h,
          parent: doc.rootHandle,
          transform: Transform2.translation(minX, minY),
          children: const [])),
      SetComponentCommand<BoxParams>(
          h, BoxParams((point.x - c1.x).abs(), (point.y - c1.y).abs())),
      // Spec 12b D2: a new object takes the current layer.
      SetComponentCommand<ObjectLayer>(h, ObjectLayer(drawingLayer(doc))),
    ], label: 'Add box');
  }, needs: const {
    Capability.structure,
    Capability.components,
    Capability.geometry,
  });
  clearShape();
}