2021-11-05 14:25:36 +03:00
|
|
|
|
import 'package:graphs/src/graph.dart';
|
2021-11-11 11:11:35 +03:00
|
|
|
|
import 'package:graphs/src/curve_painter.dart';
|
2021-11-05 14:25:36 +03:00
|
|
|
|
|
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
2021-11-05 00:35:51 +03:00
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
2021-11-05 02:50:05 +03:00
|
|
|
|
Graphs getGraph() {
|
|
|
|
|
List<Dot> d = <Dot>[];
|
2021-11-11 13:35:34 +03:00
|
|
|
|
d.add(Dot.fromTwoLists("1", [2], [3]));
|
|
|
|
|
d.add(Dot.fromTwoLists("2", [3], [1]));
|
|
|
|
|
d.add(Dot.fromTwoLists("3", [1], [2]));
|
2021-11-08 18:37:13 +03:00
|
|
|
|
//d.add(Dot.fromTwoLists("Name1", [], []));
|
|
|
|
|
//d.add(Dot.fromTwoLists("Name2", [], []));
|
2021-11-11 11:11:35 +03:00
|
|
|
|
return Graphs.fromList("Имя графа", d, true, true);
|
2021-11-05 02:50:05 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-05 00:35:51 +03:00
|
|
|
|
class DrawingPage extends StatefulWidget {
|
|
|
|
|
const DrawingPage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<StatefulWidget> createState() => _DrawingPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _DrawingPageState extends State<DrawingPage> {
|
2021-11-05 01:40:16 +03:00
|
|
|
|
double screenSize = 0;
|
2021-11-08 19:50:43 +03:00
|
|
|
|
Graphs graphData = getGraph();
|
2021-11-11 11:11:35 +03:00
|
|
|
|
List<int?>? intListPath;
|
2021-11-08 21:37:55 +03:00
|
|
|
|
List<bool>? dfsAccessTable;
|
2021-11-11 11:11:35 +03:00
|
|
|
|
//List<int?>? dijkstraTable;
|
|
|
|
|
String op = Operations.none;
|
2021-11-10 14:26:25 +03:00
|
|
|
|
int? startDot;
|
|
|
|
|
int? endDot;
|
|
|
|
|
String? dropdownValue1;
|
|
|
|
|
String? dropdownValue2;
|
2021-11-11 11:11:35 +03:00
|
|
|
|
String currOp = "";
|
2021-11-05 00:35:51 +03:00
|
|
|
|
|
2021-11-05 02:50:05 +03:00
|
|
|
|
final _textNameController = TextEditingController();
|
|
|
|
|
final _textLnthController = TextEditingController();
|
2021-11-05 17:43:27 +03:00
|
|
|
|
final _textGrNmController = TextEditingController();
|
2021-11-05 14:25:36 +03:00
|
|
|
|
|
2021-11-10 14:26:25 +03:00
|
|
|
|
void clearInputData() {
|
|
|
|
|
setState(() {
|
|
|
|
|
_textLnthController.clear();
|
|
|
|
|
_textNameController.clear();
|
|
|
|
|
dropdownValue1 = null;
|
|
|
|
|
dropdownValue2 = null;
|
2021-11-11 11:11:35 +03:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearDropDownVals() {
|
|
|
|
|
setState(() {
|
|
|
|
|
startDot = null;
|
|
|
|
|
intListPath = null;
|
2021-11-10 14:26:25 +03:00
|
|
|
|
dfsAccessTable = null;
|
2021-11-11 11:11:35 +03:00
|
|
|
|
endDot = null;
|
|
|
|
|
currOp = "";
|
|
|
|
|
op = Operations.none;
|
2021-11-10 14:26:25 +03:00
|
|
|
|
});
|
2021-11-05 02:50:05 +03:00
|
|
|
|
}
|
2021-11-05 01:40:16 +03:00
|
|
|
|
|
2021-11-10 15:05:16 +03:00
|
|
|
|
// *************buttons*************
|
|
|
|
|
ElevatedButton createButton(String txt, void Function() onPressing) {
|
2021-11-05 00:35:51 +03:00
|
|
|
|
return ElevatedButton(
|
2021-11-05 01:40:16 +03:00
|
|
|
|
onPressed: onPressing,
|
2021-11-09 03:15:36 +03:00
|
|
|
|
style: ButtonStyle(
|
|
|
|
|
backgroundColor: MaterialStateProperty.resolveWith<Color>(
|
|
|
|
|
(states) => Colors.green.shade700)),
|
2021-11-05 00:35:51 +03:00
|
|
|
|
child: Text(txt,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 15,
|
2021-11-09 03:15:36 +03:00
|
|
|
|
color: Colors.white70,
|
2021-11-05 00:35:51 +03:00
|
|
|
|
height: 1,
|
|
|
|
|
)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-10 15:05:16 +03:00
|
|
|
|
void showPopUp(String alertTitle, String err) => showDialog<String>(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (BuildContext context) => AlertDialog(
|
2021-11-11 13:35:34 +03:00
|
|
|
|
title: Text(alertTitle, style: const TextStyle(fontSize: 26)),
|
|
|
|
|
content: Text(
|
|
|
|
|
err,
|
|
|
|
|
style: const TextStyle(fontSize: 18),
|
|
|
|
|
),
|
2021-11-10 15:05:16 +03:00
|
|
|
|
actions: <Widget>[
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () => Navigator.pop(context, 'OK'),
|
|
|
|
|
child: const Text('OK'),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
// *************buttons*************
|
|
|
|
|
|
|
|
|
|
// ***addSpace***
|
|
|
|
|
SizedBox addSpaceH(double h) {
|
|
|
|
|
return SizedBox(height: h);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SizedBox addSpaceW(double w) {
|
|
|
|
|
return SizedBox(width: w);
|
|
|
|
|
}
|
|
|
|
|
// ***addSpace***
|
|
|
|
|
|
|
|
|
|
// *************inputs*************
|
2021-11-11 11:11:35 +03:00
|
|
|
|
Container createInputBox(String text, double width, IconData? icon,
|
2021-11-05 17:43:27 +03:00
|
|
|
|
TextEditingController? controller) {
|
|
|
|
|
if (icon == null) {
|
|
|
|
|
return Container(
|
2021-11-11 11:11:35 +03:00
|
|
|
|
width: width,
|
2021-11-05 17:43:27 +03:00
|
|
|
|
height: 40,
|
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 5),
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: controller,
|
|
|
|
|
textAlign: TextAlign.center,
|
2021-11-08 19:50:43 +03:00
|
|
|
|
onChanged: (name) => graphData.setName(name),
|
2021-11-05 17:43:27 +03:00
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
contentPadding:
|
|
|
|
|
const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
|
|
|
|
filled: true,
|
|
|
|
|
fillColor: Colors.white,
|
|
|
|
|
//prefixIcon: Icon(icon, color: Colors.black),
|
|
|
|
|
border: const OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(40))),
|
|
|
|
|
hintStyle: const TextStyle(color: Colors.black38),
|
|
|
|
|
hintText: text),
|
|
|
|
|
));
|
|
|
|
|
}
|
2021-11-05 01:40:16 +03:00
|
|
|
|
return Container(
|
2021-11-11 11:11:35 +03:00
|
|
|
|
width: width,
|
2021-11-05 01:40:16 +03:00
|
|
|
|
height: 40,
|
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 5),
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: controller,
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
contentPadding:
|
|
|
|
|
const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
|
|
|
|
filled: true,
|
|
|
|
|
fillColor: Colors.white,
|
|
|
|
|
prefixIcon: Icon(icon, color: Colors.black),
|
|
|
|
|
border: const OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(40))),
|
|
|
|
|
hintStyle: const TextStyle(color: Colors.black38),
|
|
|
|
|
hintText: text),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-10 15:05:16 +03:00
|
|
|
|
SizedBox dropList1(double width) {
|
|
|
|
|
var button = DropdownButton(
|
|
|
|
|
hint: const Text(
|
2021-11-11 13:35:34 +03:00
|
|
|
|
'Select dot',
|
2021-11-10 15:05:16 +03:00
|
|
|
|
style: TextStyle(color: Colors.white, fontSize: 13),
|
|
|
|
|
),
|
|
|
|
|
//icon: const Icon(Icons.fiber_manual_record, color: Colors.white),
|
|
|
|
|
alignment: AlignmentDirectional.bottomEnd,
|
|
|
|
|
value: dropdownValue1,
|
|
|
|
|
isDense: true,
|
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
|
|
|
|
dropdownColor: Colors.green.shade800,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
),
|
|
|
|
|
onChanged: (String? newValue) {
|
|
|
|
|
setState(() {
|
|
|
|
|
dropdownValue1 = newValue;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
items: graphData.getDots().map((location) {
|
|
|
|
|
return DropdownMenuItem(
|
|
|
|
|
child: Text(location.getName()),
|
|
|
|
|
value: location.num.toString(),
|
|
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
);
|
2021-11-05 00:35:51 +03:00
|
|
|
|
|
2021-11-10 15:05:16 +03:00
|
|
|
|
return SizedBox(
|
|
|
|
|
child: button,
|
|
|
|
|
width: width,
|
|
|
|
|
);
|
2021-11-05 01:40:16 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-10 15:05:16 +03:00
|
|
|
|
SizedBox dropList2(double width) {
|
|
|
|
|
var button = DropdownButton(
|
|
|
|
|
hint: const Text(
|
|
|
|
|
'Select Dot',
|
|
|
|
|
style: TextStyle(color: Colors.white, fontSize: 13),
|
|
|
|
|
),
|
|
|
|
|
alignment: AlignmentDirectional.centerEnd,
|
|
|
|
|
value: dropdownValue2,
|
|
|
|
|
isDense: true,
|
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
|
|
|
|
dropdownColor: Colors.green.shade800,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
),
|
|
|
|
|
onChanged: (String? newValue) {
|
|
|
|
|
setState(() {
|
|
|
|
|
dropdownValue2 = newValue;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
items: graphData.getDots().map((location) {
|
|
|
|
|
return DropdownMenuItem(
|
|
|
|
|
child: Text(location.getName()),
|
|
|
|
|
value: location.num.toString(),
|
|
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return SizedBox(
|
|
|
|
|
child: button,
|
|
|
|
|
width: width,
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-11-11 13:35:34 +03:00
|
|
|
|
// *************inputs*************
|
2021-11-08 19:50:43 +03:00
|
|
|
|
|
|
|
|
|
//*********ButtonsFunctions*********
|
2021-11-05 01:40:16 +03:00
|
|
|
|
void addDotPushed() {
|
2021-11-11 11:11:35 +03:00
|
|
|
|
clearDropDownVals();
|
|
|
|
|
if (_textNameController.text == "") {
|
|
|
|
|
showPopUp("Error", "No name in \"Dot name\" box");
|
|
|
|
|
} else {
|
|
|
|
|
setState(() {
|
2021-11-08 19:50:43 +03:00
|
|
|
|
String? res = graphData.addIsolated(_textNameController.text);
|
2021-11-05 17:43:27 +03:00
|
|
|
|
if (res != null) {
|
|
|
|
|
showPopUp("Error", res);
|
|
|
|
|
}
|
2021-11-11 11:11:35 +03:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
clearInputData();
|
2021-11-05 14:25:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addPathPushed() {
|
2021-11-11 11:11:35 +03:00
|
|
|
|
clearDropDownVals();
|
|
|
|
|
if (dropdownValue1 == null) {
|
2021-11-11 13:35:34 +03:00
|
|
|
|
showPopUp("Error", "No dot in first box selected");
|
2021-11-11 11:11:35 +03:00
|
|
|
|
} else if (dropdownValue2 == null) {
|
2021-11-11 13:35:34 +03:00
|
|
|
|
showPopUp("Error", "No dot in second box selected");
|
2021-11-11 11:11:35 +03:00
|
|
|
|
} 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",
|
2021-11-11 13:35:34 +03:00
|
|
|
|
"Can't parse input.\nInts only allowed in \"Input length\"");
|
2021-11-05 17:43:27 +03:00
|
|
|
|
} else {
|
2021-11-11 11:11:35 +03:00
|
|
|
|
len ??= 0;
|
|
|
|
|
setState(() {
|
|
|
|
|
String? res = graphData.addPath(from, to, len!);
|
|
|
|
|
if (res != null) showPopUp("Error", res);
|
|
|
|
|
});
|
2021-11-05 14:25:36 +03:00
|
|
|
|
}
|
2021-11-11 11:11:35 +03:00
|
|
|
|
}
|
|
|
|
|
clearInputData();
|
2021-11-05 17:43:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void changeOriented() {
|
|
|
|
|
setState(() {
|
2021-11-08 19:50:43 +03:00
|
|
|
|
String? res = graphData.flipUseOrientation();
|
2021-11-05 17:43:27 +03:00
|
|
|
|
if (res != null) showPopUp("Error", res);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void changeLength() {
|
|
|
|
|
setState(() {
|
2021-11-08 19:50:43 +03:00
|
|
|
|
String? res = graphData.flipUseLength();
|
2021-11-05 17:43:27 +03:00
|
|
|
|
if (res != null) showPopUp("Error", res);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-05 14:25:36 +03:00
|
|
|
|
void delPathPushed() {
|
2021-11-11 11:11:35 +03:00
|
|
|
|
clearDropDownVals();
|
|
|
|
|
if (dropdownValue1 == null) {
|
2021-11-11 13:35:34 +03:00
|
|
|
|
showPopUp("Error", "No dot in first box selected");
|
2021-11-11 11:11:35 +03:00
|
|
|
|
} else if (dropdownValue2 == null) {
|
2021-11-11 13:35:34 +03:00
|
|
|
|
showPopUp("Error", "No dot in second box selected");
|
2021-11-11 11:11:35 +03:00
|
|
|
|
} 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\"");
|
2021-11-05 17:43:27 +03:00
|
|
|
|
} else {
|
2021-11-11 11:11:35 +03:00
|
|
|
|
setState(() {
|
2021-11-08 19:50:43 +03:00
|
|
|
|
String? res = graphData.delPath(from, to);
|
2021-11-05 17:43:27 +03:00
|
|
|
|
if (res != null) {
|
|
|
|
|
showPopUp("Error", res);
|
|
|
|
|
}
|
2021-11-11 11:11:35 +03:00
|
|
|
|
});
|
2021-11-05 14:25:36 +03:00
|
|
|
|
}
|
2021-11-11 11:11:35 +03:00
|
|
|
|
}
|
|
|
|
|
clearInputData();
|
2021-11-05 02:50:05 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void delDotPushed() {
|
2021-11-11 11:11:35 +03:00
|
|
|
|
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();
|
2021-11-05 01:40:16 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-05 14:25:36 +03:00
|
|
|
|
void fileOpener() async {
|
2021-11-05 17:43:27 +03:00
|
|
|
|
FilePickerResult? result =
|
|
|
|
|
await FilePicker.platform.pickFiles(allowedExtensions: ["txt"]);
|
2021-11-11 11:11:35 +03:00
|
|
|
|
|
|
|
|
|
if (result != null) {
|
|
|
|
|
if (!result.files.single.path!.endsWith(".txt")) {
|
|
|
|
|
showPopUp("Error", "Can open only \".txt\" files");
|
|
|
|
|
} else {
|
|
|
|
|
setState(() {
|
2021-11-08 19:50:43 +03:00
|
|
|
|
String? res =
|
|
|
|
|
graphData.replaceDataFromFile(result.files.single.path!);
|
2021-11-11 11:11:35 +03:00
|
|
|
|
|
2021-11-05 20:57:12 +03:00
|
|
|
|
if (res != null) showPopUp("Error", res);
|
2021-11-11 11:11:35 +03:00
|
|
|
|
});
|
2021-11-05 17:43:27 +03:00
|
|
|
|
}
|
2021-11-11 11:11:35 +03:00
|
|
|
|
} else {
|
|
|
|
|
showPopUp("Error", "No file selected");
|
|
|
|
|
}
|
|
|
|
|
clearDropDownVals();
|
|
|
|
|
clearInputData();
|
2021-11-05 17:43:27 +03:00
|
|
|
|
}
|
2021-11-05 14:25:36 +03:00
|
|
|
|
|
2021-11-05 17:43:27 +03:00
|
|
|
|
void fileSaver() async {
|
|
|
|
|
String? outputFile = await FilePicker.platform.saveFile(
|
|
|
|
|
dialogTitle: 'Please select an output file:',
|
|
|
|
|
fileName: 'output-file.txt',
|
|
|
|
|
allowedExtensions: ["txt"]);
|
|
|
|
|
if (outputFile == null) {
|
|
|
|
|
showPopUp("Error", "Save cancelled");
|
|
|
|
|
} else {
|
|
|
|
|
if (!outputFile.endsWith(".txt")) {
|
|
|
|
|
outputFile += ".txt";
|
|
|
|
|
}
|
2021-11-08 19:50:43 +03:00
|
|
|
|
graphData.printToFile(outputFile);
|
2021-11-05 00:35:51 +03:00
|
|
|
|
}
|
2021-11-11 11:11:35 +03:00
|
|
|
|
clearDropDownVals();
|
|
|
|
|
clearInputData();
|
2021-11-05 00:35:51 +03:00
|
|
|
|
}
|
2021-11-05 14:25:36 +03:00
|
|
|
|
|
2021-11-08 19:50:43 +03:00
|
|
|
|
void bfsPushed() {
|
2021-11-11 11:11:35 +03:00
|
|
|
|
clearDropDownVals();
|
|
|
|
|
if (dropdownValue1 == null) {
|
2021-11-11 13:35:34 +03:00
|
|
|
|
showPopUp("Error", "No dot in first box selected");
|
2021-11-11 11:11:35 +03:00
|
|
|
|
} else if (dropdownValue2 == null) {
|
2021-11-11 13:35:34 +03:00
|
|
|
|
showPopUp("Error", "No dot in second box selected");
|
2021-11-11 11:11:35 +03:00
|
|
|
|
} else {
|
|
|
|
|
setState(() {
|
2021-11-10 14:26:25 +03:00
|
|
|
|
startDot = int.parse(dropdownValue1!);
|
|
|
|
|
endDot = int.parse(dropdownValue2!);
|
2021-11-11 11:11:35 +03:00
|
|
|
|
currOp = "OP: BFS from $startDot to $endDot";
|
|
|
|
|
op = Operations.bfs;
|
|
|
|
|
intListPath = graphData.bfsPath(startDot!, endDot!);
|
|
|
|
|
});
|
|
|
|
|
if (intListPath == null) {
|
|
|
|
|
showPopUp("Info", "There is no path");
|
2021-11-08 19:50:43 +03:00
|
|
|
|
}
|
2021-11-11 11:11:35 +03:00
|
|
|
|
//print(intListPath);
|
|
|
|
|
}
|
2021-11-10 14:26:25 +03:00
|
|
|
|
clearInputData();
|
2021-11-08 19:50:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-08 21:37:55 +03:00
|
|
|
|
void dfsPushed() {
|
2021-11-11 11:11:35 +03:00
|
|
|
|
clearDropDownVals();
|
|
|
|
|
if (dropdownValue1 == null) {
|
2021-11-11 13:35:34 +03:00
|
|
|
|
showPopUp("Error", "No dot in first box selected");
|
2021-11-11 11:11:35 +03:00
|
|
|
|
} else {
|
|
|
|
|
setState(() {
|
2021-11-10 14:26:25 +03:00
|
|
|
|
startDot = int.parse(dropdownValue1!);
|
2021-11-11 11:11:35 +03:00
|
|
|
|
op = Operations.dfs;
|
|
|
|
|
currOp = "OP: DFS from $startDot";
|
2021-11-10 14:26:25 +03:00
|
|
|
|
dfsAccessTable = graphData.dfsIterative(startDot!);
|
2021-11-11 11:11:35 +03:00
|
|
|
|
});
|
|
|
|
|
if (dfsAccessTable == null) {
|
|
|
|
|
showPopUp("Err", "report this error.");
|
2021-11-08 21:37:55 +03:00
|
|
|
|
}
|
2021-11-11 11:11:35 +03:00
|
|
|
|
//print(dfsAccessTable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearInputData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dijkstraPushed() {
|
|
|
|
|
clearDropDownVals();
|
|
|
|
|
if (dropdownValue1 == null) {
|
|
|
|
|
showPopUp("Error", "No number in \"Dot number\" box");
|
|
|
|
|
} else {
|
|
|
|
|
setState(() {
|
|
|
|
|
startDot = int.parse(dropdownValue1!);
|
2021-11-11 13:35:34 +03:00
|
|
|
|
currOp = "OP: Dijkstra from $startDot";
|
2021-11-11 11:11:35 +03:00
|
|
|
|
op = Operations.dijkstra;
|
|
|
|
|
intListPath = graphData.dijkstra(startDot!);
|
|
|
|
|
});
|
|
|
|
|
if (intListPath == null) {
|
|
|
|
|
showPopUp("Err", "report this error.");
|
|
|
|
|
}
|
|
|
|
|
//print(intListPath);
|
|
|
|
|
}
|
|
|
|
|
clearInputData();
|
2021-11-08 21:37:55 +03:00
|
|
|
|
}
|
2021-11-08 19:50:43 +03:00
|
|
|
|
//*********ButtonsFunctions*********
|
2021-11-10 14:26:25 +03:00
|
|
|
|
|
2021-11-10 15:05:16 +03:00
|
|
|
|
// build
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
screenSize = MediaQuery.of(context).size.width;
|
|
|
|
|
_textGrNmController.text = graphData.getName();
|
|
|
|
|
return MaterialApp(
|
|
|
|
|
home: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
title: const Align(
|
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
|
child: Text("Graph name:\n",
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
))),
|
|
|
|
|
toolbarHeight: 110,
|
|
|
|
|
flexibleSpace: Container(
|
|
|
|
|
color: Colors.green.shade900,
|
|
|
|
|
child: Column(children: <Widget>[
|
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
|
Row(children: [
|
|
|
|
|
addSpaceW(screenSize / 8 + 19),
|
|
|
|
|
createButton("\nAdd dot\n", addDotPushed),
|
|
|
|
|
createInputBox("Dot name", screenSize / 4 - 25, Icons.label,
|
|
|
|
|
_textNameController),
|
|
|
|
|
addSpaceW(8),
|
|
|
|
|
createButton("\nAdd path\n", addPathPushed),
|
|
|
|
|
createInputBox("Input length", screenSize / 4 - 25,
|
|
|
|
|
Icons.arrow_right_alt_outlined, _textLnthController),
|
|
|
|
|
]),
|
|
|
|
|
addSpaceH(3),
|
|
|
|
|
Row(children: [
|
|
|
|
|
addSpaceW(6),
|
|
|
|
|
createInputBox(
|
|
|
|
|
"Name", screenSize / 8 - 25, null, _textGrNmController),
|
|
|
|
|
//addSpaceW(screenSize / 8 - 4),
|
|
|
|
|
createButton("\nDel dot \n", delDotPushed),
|
|
|
|
|
//createInputBox("Dot number", screenSize / 4 - 25, Icons.fiber_manual_record, _textNumbController),
|
|
|
|
|
addSpaceW(54),
|
|
|
|
|
dropList1(screenSize / 4 - 80),
|
2021-11-11 11:11:35 +03:00
|
|
|
|
addSpaceW(53),
|
2021-11-10 15:05:16 +03:00
|
|
|
|
createButton("\nDel path\n", delPathPushed),
|
|
|
|
|
addSpaceW(54),
|
|
|
|
|
dropList2(screenSize / 4 - 80),
|
|
|
|
|
//createInputBox("Destination number", screenSize / 4 - 25, Icons.fiber_manual_record, _textDestController),
|
|
|
|
|
]),
|
|
|
|
|
]),
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
setState(() {
|
2021-11-11 11:11:35 +03:00
|
|
|
|
clearDropDownVals();
|
2021-11-10 15:05:16 +03:00
|
|
|
|
graphData.flushData();
|
|
|
|
|
clearInputData();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
icon: const Icon(Icons.delete_sweep),
|
|
|
|
|
iconSize: 60,
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
body: CustomPaint(
|
|
|
|
|
painter: CurvePainter(
|
|
|
|
|
graphData: graphData,
|
2021-11-11 11:11:35 +03:00
|
|
|
|
intListPath: intListPath,
|
2021-11-10 15:05:16 +03:00
|
|
|
|
dfsAccessTable: dfsAccessTable,
|
|
|
|
|
start: startDot,
|
2021-11-11 11:11:35 +03:00
|
|
|
|
end: endDot,
|
|
|
|
|
op: op),
|
2021-11-10 15:05:16 +03:00
|
|
|
|
child: Align(
|
|
|
|
|
alignment: Alignment.topRight,
|
|
|
|
|
child: ButtonBar(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: <Widget>[
|
2021-11-11 11:11:35 +03:00
|
|
|
|
Text(
|
|
|
|
|
currOp,
|
|
|
|
|
style: const TextStyle(fontSize: 14, color: Colors.black),
|
|
|
|
|
),
|
2021-11-10 15:05:16 +03:00
|
|
|
|
createButton("Bfs", bfsPushed),
|
|
|
|
|
createButton("Dfs", dfsPushed),
|
2021-11-11 11:11:35 +03:00
|
|
|
|
createButton("Dijkstra", dijkstraPushed),
|
2021-11-15 21:04:08 +03:00
|
|
|
|
createButton("Kruskal", () {
|
|
|
|
|
clearDropDownVals();
|
|
|
|
|
setState(() {
|
|
|
|
|
currOp = "OP: Kruscal algo";
|
|
|
|
|
graphData.kruskal();
|
|
|
|
|
});
|
|
|
|
|
clearInputData();
|
|
|
|
|
}),
|
2021-11-11 11:11:35 +03:00
|
|
|
|
createButton("Clear OP", () {
|
|
|
|
|
clearDropDownVals();
|
|
|
|
|
clearInputData();
|
2021-11-10 15:05:16 +03:00
|
|
|
|
}),
|
|
|
|
|
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 +=
|
|
|
|
|
" Для добавления точки необходимо ввести имя в \"Dot name\" и нажать на \"Add dot\".\n";
|
|
|
|
|
out +=
|
2021-11-11 13:35:34 +03:00
|
|
|
|
" Для удаления точки необходимо выбрать номер в левом выпадающем списке и нажать на \"Del dot\".\n";
|
2021-11-10 15:05:16 +03:00
|
|
|
|
out +=
|
2021-11-11 13:35:34 +03:00
|
|
|
|
" Для добавления пути необходимо выбрать: первую вершину в левом выпадающем списке, вторую вершину в правом выпадающем списке, ";
|
2021-11-10 15:05:16 +03:00
|
|
|
|
out +=
|
|
|
|
|
"и, если граф взвешенный, то ввести длину пути в \"Input length\". Затем нажать \"Add path\".\n";
|
|
|
|
|
out +=
|
2021-11-11 13:35:34 +03:00
|
|
|
|
" Для удаления пути необходимо выбрать первую вершину из левого списка и вторую вершину в правом списке. Затем нажать \"Del path\".\n\n";
|
|
|
|
|
out +=
|
|
|
|
|
" Кнопка \"Bfs\" отмечает точки в пути из вершины, выбранной слева, в вершину, выбранную справа.\n";
|
|
|
|
|
out +=
|
|
|
|
|
" Кнопка \"Dfs\" помечает точки, которые доступны из вершины, выбранной слева.";
|
|
|
|
|
out +=
|
|
|
|
|
" Кнопка \"Dijkstra\" ищет кратчайший путь из вершины, выбранной слева. во все другие.";
|
2021-11-10 15:05:16 +03:00
|
|
|
|
out +=
|
2021-11-11 13:35:34 +03:00
|
|
|
|
" Кнопка \"Clear op\" отменяет \"Bfs\", \"Dfs\" и \"Dijkstra\". Все эти отображения так же отменяются при любых действиях с графом.";
|
2021-11-10 15:05:16 +03:00
|
|
|
|
out +=
|
|
|
|
|
" Кнопки \"Взвешенный\" и \"Ориентированный\" позволяют сменить эти значения перед построением графа (т.е. для их работы граф должен быть пустым).\n";
|
|
|
|
|
out +=
|
|
|
|
|
" Кнопки \"Save to file\" и \"Load from file\" позволяют вывести информацию в файл и загрузить информацию из файла соответственно.\n";
|
|
|
|
|
out +=
|
2021-11-11 13:35:34 +03:00
|
|
|
|
" Кнопка \"Help\" описывает работу с интерфейсом программы.";
|
|
|
|
|
showPopUp("Help:", out);
|
2021-11-10 15:05:16 +03:00
|
|
|
|
})
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
2021-11-10 14:26:25 +03:00
|
|
|
|
),
|
2021-11-10 15:05:16 +03:00
|
|
|
|
));
|
2021-11-10 14:26:25 +03:00
|
|
|
|
}
|
2021-11-05 00:35:51 +03:00
|
|
|
|
}
|