diff --git a/flutter/lib/src/graph.dart b/flutter/lib/src/graph.dart index ef05c6c..256e85c 100644 --- a/flutter/lib/src/graph.dart +++ b/flutter/lib/src/graph.dart @@ -174,6 +174,8 @@ class Graphs { _fixAfterDel(inn); return null; } + + void flushData() => _dots = []; //*********Delete********* //******Helper******* @@ -242,6 +244,49 @@ class Graphs { } //******Helper******* + //*****Setters******* + void setName(String name) => _name = name; + String? replaceDataFromFile(String path) { + Separators sep = Separators(); + File file = File(path); + List lines = file.readAsLinesSync(); + _name = lines.removeAt(0); + _oriented = lines.removeAt(0) == sep.isOriented.trim(); + _useLength = lines.removeAt(0) == sep.hasLength.trim(); + _dots = []; + for (var l in lines) { + l = l.trimRight(); + if (l != sep.end) { + var spl = l.split(sep.space); + List dot = []; + List len = []; + String name = spl.removeAt(0); + name = name.substring(0, name.length - 1); + for (var splitted in spl) { + if (splitted != "") { + var dt = splitted.split(sep.dotToLength); + if (dt.length == 2) { + dot.add(int.parse(dt[0])); + if (_useLength) { + len.add(int.parse(dt[1])); + } else { + len.add(0); + } + } else if (dt.length == 1) { + dot.add(int.parse(splitted)); + len.add(0); + } + } + } + _dots.add(Dot.fromTwoLists(name, dot, len)); + } + } + _syncNum(); + _syncNameTable(); + if (!_oriented) _fullFix(); + } + //*****Setters******* + //*****Getters******* bool getDoubleSided() => _oriented; bool getUseLength() => _useLength; @@ -401,12 +446,6 @@ class Graphs { _syncNameTable(); } - //***********Cleaning*********** - void flushData() { - _dots = []; - } - //***********Cleaning*********** - //************Алгоритмы************ bool bfsHasPath(int startDot, int goalDot) { // обход в ширину