configurePlanTableSeating function

VenueLayoutDocument configurePlanTableSeating(
  1. VenueLayoutDocument doc, {
  2. double? width,
  3. double? height,
  4. double? gap,
  5. double? spacing,
  6. double? edgePadding,
  7. bool constrainToCanvas = true,
})

Applies only the supplied physical settings, preserving local values for every other setting. The operation is atomic if reflow cannot fit.

Implementation

VenueLayoutDocument configurePlanTableSeating(
  VenueLayoutDocument doc, {
  double? width,
  double? height,
  double? gap,
  double? spacing,
  double? edgePadding,
  bool constrainToCanvas = true,
}) {
  {
    final defaults = TableSeating.fromRecord(doc.seatingDefaults).copyWith(
      width: width,
      height: height,
      gap: gap,
      spacing: spacing,
      edgePadding: edgePadding,
    );
    for (final entry in defaults.record.entries) {
      final value = entry.value as double;
      if (!value.isFinite ||
          value > (1000000) ||
          value < (const {'width', 'height'}.contains(entry.key) ? 1 : 0)) {
        throw ArgumentError('Invalid chair dimensions or spacing');
      }
    }
    var next = doc.copyWith(seatingDefaults: defaults.record);
    final byId = {for (final n in doc.nodes) n.id: n};
    bool locked(LayoutNode node) {
      LayoutNode? current = node;
      while (current != null) {
        if (current.locked) return true;
        current = byId[current.parentId];
      }
      return doc.nodes.any((n) => n.parentId == node.id && n.locked);
    }

    for (final table in doc.nodes.where(
      (n) => n.kind == 'table' && !isBarNode(n) && !locked(n),
    )) {
      final profile = TableSeating.fromDocument(doc, table).copyWith(
        width: width,
        height: height,
        gap: gap,
        spacing: spacing,
        edgePadding: edgePadding,
      );
      next = configureTableSeating(next, table.id, profile);
    }
    final issues = validateDocument(next);
    if (issues.isNotEmpty) throw InvalidLayoutDocument(issues, next.toJson());
    return next;
  }
}