herberekenAlles method

Future<void> herberekenAlles()

Implementation

Future<void> herberekenAlles() async {
  if (_boom == null) return;
  final updated = List<LeidingNode>.from(_boom!.nodes);

  // Topologische volgorde (BFS vanuit wortels).
  final wachtrij = updated.where((n) => n.parentId == null).toList();
  while (wachtrij.isNotEmpty) {
    final node = wachtrij.removeAt(0);
    final idx = updated.indexWhere((n) => n.id == node.id);

    final zUp = _upstreamMohmFromList(node.id, updated);
    final invoer = updated[idx].invoer.copyWith(
      bronimpedantieActief: true,
      zUpstreamHandmatigMohm: zUp,
      aardingsstelsel: _boom!.aardingsstelsel,
    );
    final resultaten = KabelOntwerper(invoer).bereken();

    updated[idx] = updated[idx].copyWith(
      invoer: updated[idx].invoer, // ongewijzigde gebruikersinvoer
      resultaten: resultaten,
    );

    wachtrij.addAll(updated.where((n) => n.parentId == node.id));
  }

  _boom = _boom!.copyWith(nodes: updated);
  notifyListeners();
  await _slaOp();
}