From 8fea8c95fcaac2c19aff27282dd2a2c6d6349708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BE=D1=80=D0=BE=D0=B7=D0=BE=D0=B2=20=D0=90=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=B5=D0=B9?= Date: Thu, 11 Nov 2021 08:11:35 +0000 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20'flu?= =?UTF-8?q?tter/lib/pages'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flutter/lib/pages/drawing_page.dart | 276 ++++++++++++++++------------ 1 file changed, 154 insertions(+), 122 deletions(-) diff --git a/flutter/lib/pages/drawing_page.dart b/flutter/lib/pages/drawing_page.dart index d87907d..d503239 100644 --- a/flutter/lib/pages/drawing_page.dart +++ b/flutter/lib/pages/drawing_page.dart @@ -1,5 +1,5 @@ import 'package:graphs/src/graph.dart'; -import 'package:graphs/curve_painter.dart'; +import 'package:graphs/src/curve_painter.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; @@ -11,7 +11,7 @@ Graphs getGraph() { d.add(Dot.fromTwoLists("3", [1, 2], [1, 2])); //d.add(Dot.fromTwoLists("Name1", [], [])); //d.add(Dot.fromTwoLists("Name2", [], [])); - return Graphs.fromList("Имя", d, true, true); + return Graphs.fromList("Имя графа", d, true, true); } class DrawingPage extends StatefulWidget { @@ -24,31 +24,37 @@ class DrawingPage extends StatefulWidget { class _DrawingPageState extends State { double screenSize = 0; Graphs graphData = getGraph(); - List? bfsPath; + List? intListPath; List? dfsAccessTable; + //List? dijkstraTable; + String op = Operations.none; int? startDot; int? endDot; String? dropdownValue1; String? dropdownValue2; + String currOp = ""; final _textNameController = TextEditingController(); - final _textNumbController = TextEditingController(); - final _textDestController = TextEditingController(); final _textLnthController = TextEditingController(); final _textGrNmController = TextEditingController(); void clearInputData() { setState(() { - _textDestController.clear(); - _textNumbController.clear(); _textLnthController.clear(); _textNameController.clear(); dropdownValue1 = null; dropdownValue2 = null; - /*startDot = null; - bfsPath = null; + }); + } + + void clearDropDownVals() { + setState(() { + startDot = null; + intListPath = null; dfsAccessTable = null; - endDot = null;*/ + endDot = null; + currOp = ""; + op = Operations.none; }); } @@ -94,11 +100,11 @@ class _DrawingPageState extends State { // ***addSpace*** // *************inputs************* - Container createInputBox(String text, double wid, IconData? icon, + Container createInputBox(String text, double width, IconData? icon, TextEditingController? controller) { if (icon == null) { return Container( - width: wid, + width: width, height: 40, margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 5), child: TextField( @@ -118,7 +124,7 @@ class _DrawingPageState extends State { )); } return Container( - width: wid, + width: width, height: 40, margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 5), child: TextField( @@ -209,45 +215,44 @@ class _DrawingPageState extends State { //*********ButtonsFunctions********* void addDotPushed() { - setState(() { - if (_textNameController.text == "") { - showPopUp("Error", "No name in \"Dot name\" box"); - } else { + clearDropDownVals(); + if (_textNameController.text == "") { + showPopUp("Error", "No name in \"Dot name\" box"); + } else { + setState(() { String? res = graphData.addIsolated(_textNameController.text); if (res != null) { showPopUp("Error", res); } - } - clearInputData(); - }); + }); + } + clearInputData(); } void addPathPushed() { - setState(() { - if (dropdownValue1 == null) { - showPopUp("Error", "Select output dot"); - } else if (dropdownValue2 == null) { - showPopUp("Error", "select input dot"); - } else if (_textLnthController.text == "" && - graphData.getUseLengthBool()) { - showPopUp("Error", "No length in \"Input length\" box"); + clearDropDownVals(); + if (dropdownValue1 == null) { + showPopUp("Error", "Select output dot"); + } else if (dropdownValue2 == null) { + showPopUp("Error", "select input dot"); + } else if (_textLnthController.text == "" && graphData.getUseLengthBool()) { + showPopUp("Error", "No length in \"Input length\" box"); + } else { + int? from = int.parse(dropdownValue1!); + int? to = int.parse(dropdownValue2!); + int? len = int.tryParse(_textLnthController.text); + if (len == null && graphData.getUseLengthBool()) { + showPopUp("Error", + "Can't parse input.\nInts only allowed in \"Dot number\", \"Destination number\" and \"Input length\""); } else { - int? from = int.parse(dropdownValue1!); - int? to = int.parse(dropdownValue2!); - int? len = int.tryParse(_textLnthController.text); - if (len == null && graphData.getUseLengthBool()) { - showPopUp("Error", - "Can't parse input.\nInts only allowed in \"Dot number\", \"Destination number\" and \"Input length\""); - } else { - len ??= 0; - String? res = graphData.addPath(from, to, len); - if (res != null) { - showPopUp("Error", res); - } - } + len ??= 0; + setState(() { + String? res = graphData.addPath(from, to, len!); + if (res != null) showPopUp("Error", res); + }); } - clearInputData(); - }); + } + clearInputData(); } void changeOriented() { @@ -265,55 +270,64 @@ class _DrawingPageState extends State { } void delPathPushed() { - setState(() { - if (_textNumbController.text == "") { - showPopUp("Error", "No number in \"Dot number\" box"); - } else if (_textDestController.text == "") { - showPopUp("Error", "No name in \"Dot name\" box"); + clearDropDownVals(); + if (dropdownValue1 == null) { + showPopUp("Error", "No number in \"Dot number\" box"); + } else if (dropdownValue2 == null) { + showPopUp("Error", "No name in \"Dot name\" box"); + } else { + int? from = int.tryParse(dropdownValue1!); + int? to = int.tryParse(dropdownValue2!); + if (from == null || to == null) { + showPopUp("Error", + "Can't parse input.\nInts only allowed in \"Dot number\" and \"Destination number\""); } else { - int? from = int.tryParse(_textNumbController.text); - int? to = int.tryParse(_textDestController.text); - if (from == null || to == null) { - showPopUp("Error", - "Can't parse input.\nInts only allowed in \"Dot number\" and \"Destination number\""); - } else { + setState(() { String? res = graphData.delPath(from, to); if (res != null) { showPopUp("Error", res); } - } + }); } - clearInputData(); - }); + } + clearInputData(); } void delDotPushed() { - setState(() { - if (dropdownValue1 != null) { - graphData.delDot(int.parse(dropdownValue1!)); - } else { - showPopUp("Error", "Nothing in input"); - } - clearInputData(); - }); + if (dropdownValue1 != null) { + setState(() { + String? res = graphData.delDot(int.parse(dropdownValue1!)); + if (res != null) { + showPopUp("Error", res); + } + }); + } else { + showPopUp("Error", "Nothing in input"); + } + clearDropDownVals(); + clearInputData(); } void fileOpener() async { FilePickerResult? result = await FilePicker.platform.pickFiles(allowedExtensions: ["txt"]); - setState(() { - if (result != null) { - if (!result.files.single.path!.endsWith(".txt")) { - showPopUp("Error", "Can open only \".txt\" files"); - } else { + + if (result != null) { + if (!result.files.single.path!.endsWith(".txt")) { + showPopUp("Error", "Can open only \".txt\" files"); + } else { + setState(() { String? res = graphData.replaceDataFromFile(result.files.single.path!); + if (res != null) showPopUp("Error", res); - } - } else { - showPopUp("Error", "No file selected"); + }); } - }); + } else { + showPopUp("Error", "No file selected"); + } + clearDropDownVals(); + clearInputData(); } void fileSaver() async { @@ -329,50 +343,69 @@ class _DrawingPageState extends State { } graphData.printToFile(outputFile); } + clearDropDownVals(); + clearInputData(); } void bfsPushed() { - setState(() { - bfsPath = null; - dfsAccessTable = null; - startDot = null; - endDot = null; - if (dropdownValue1 == null) { - showPopUp("Error", "No number in \"Dot number\" box"); - } else if (dropdownValue2 == null) { - showPopUp("Error", "No number in \"Destination number\" box"); - } else { + clearDropDownVals(); + if (dropdownValue1 == null) { + showPopUp("Error", "No number in \"Dot number\" box"); + } else if (dropdownValue2 == null) { + showPopUp("Error", "No number in \"Destination number\" box"); + } else { + setState(() { startDot = int.parse(dropdownValue1!); endDot = int.parse(dropdownValue2!); - - bfsPath = graphData.bfsPath(startDot!, endDot!); - if (bfsPath == null) { - showPopUp("Info", "There is no path"); - } - print(bfsPath); + currOp = "OP: BFS from $startDot to $endDot"; + op = Operations.bfs; + intListPath = graphData.bfsPath(startDot!, endDot!); + }); + if (intListPath == null) { + showPopUp("Info", "There is no path"); } - }); + //print(intListPath); + } clearInputData(); } void dfsPushed() { - setState(() { - bfsPath = null; - dfsAccessTable = null; - startDot = null; - endDot = null; - if (dropdownValue1 == null) { - showPopUp("Error", "No number in \"Dot number\" box"); - } else { + clearDropDownVals(); + if (dropdownValue1 == null) { + showPopUp("Error", "No number in \"Dot number\" box"); + } else { + setState(() { startDot = int.parse(dropdownValue1!); + op = Operations.dfs; + currOp = "OP: DFS from $startDot"; dfsAccessTable = graphData.dfsIterative(startDot!); - if (dfsAccessTable == null) { - showPopUp("Err", "report this error."); - } - print(dfsAccessTable); + }); + if (dfsAccessTable == null) { + showPopUp("Err", "report this error."); } - clearInputData(); - }); + //print(dfsAccessTable); + } + + clearInputData(); + } + + void dijkstraPushed() { + clearDropDownVals(); + if (dropdownValue1 == null) { + showPopUp("Error", "No number in \"Dot number\" box"); + } else { + setState(() { + startDot = int.parse(dropdownValue1!); + currOp = "OP: DFS from $startDot"; + op = Operations.dijkstra; + intListPath = graphData.dijkstra(startDot!); + }); + if (intListPath == null) { + showPopUp("Err", "report this error."); + } + //print(intListPath); + } + clearInputData(); } //*********ButtonsFunctions********* @@ -416,7 +449,7 @@ class _DrawingPageState extends State { //createInputBox("Dot number", screenSize / 4 - 25, Icons.fiber_manual_record, _textNumbController), addSpaceW(54), dropList1(screenSize / 4 - 80), - addSpaceW(54), + addSpaceW(53), createButton("\nDel path\n", delPathPushed), addSpaceW(54), dropList2(screenSize / 4 - 80), @@ -428,10 +461,7 @@ class _DrawingPageState extends State { IconButton( onPressed: () { setState(() { - startDot = null; - endDot = null; - bfsPath = null; - dfsAccessTable = null; + clearDropDownVals(); graphData.flushData(); clearInputData(); }); @@ -443,31 +473,33 @@ class _DrawingPageState extends State { body: CustomPaint( painter: CurvePainter( graphData: graphData, - bfsPath: bfsPath, + intListPath: intListPath, dfsAccessTable: dfsAccessTable, start: startDot, - end: endDot), + end: endDot, + op: op), child: Align( alignment: Alignment.topRight, child: ButtonBar( mainAxisSize: MainAxisSize.min, children: [ + Text( + currOp, + style: const TextStyle(fontSize: 14, color: Colors.black), + ), createButton("Bfs", bfsPushed), createButton("Dfs", dfsPushed), - createButton("Clear dfs or bfs", () { - setState(() { - bfsPath = null; - dfsAccessTable = null; - startDot = null; - endDot = null; - clearInputData(); - }); + createButton("Dijkstra", dijkstraPushed), + createButton("Clear OP", () { + clearDropDownVals(); + clearInputData(); }), createButton(graphData.getUseLengthStr(), changeLength), createButton(graphData.getDoubleSidedStr(), changeOriented), createButton("Save to file", fileSaver), createButton("Load from file", fileOpener), createButton("Help", () { + /* String out = " В поле \"Graph name\" можно сменить имя графу.\n"; out += @@ -487,8 +519,8 @@ class _DrawingPageState extends State { out += " Кнопки \"Save to file\" и \"Load from file\" позволяют вывести информацию в файл и загрузить информацию из файла соответственно.\n"; out += - " Кнопка \"Help\" описывает работу с интерфейсом программы."; - showPopUp("Help:", out); + " Кнопка \"Help\" описывает работу с интерфейсом программы.";*/ + showPopUp("Help:", "На переработке"); }) ], ),