FL: "Add dot" base work
Send value to painter GR: "return string of error"
This commit is contained in:
parent
6bb06f2521
commit
bbba3a65e8
|
@ -3,17 +3,18 @@ import 'package:flutter/material.dart';
|
|||
import 'dart:math';
|
||||
|
||||
class CurvePainter extends CustomPainter {
|
||||
CurvePainter(Graphs gr) {
|
||||
_gr = gr;
|
||||
}
|
||||
CurvePainter({
|
||||
Key? key,
|
||||
required this.gr,
|
||||
});
|
||||
|
||||
Graphs _gr = Graphs();
|
||||
double rad = 7;
|
||||
double width = 4;
|
||||
Color col = Colors.black;
|
||||
double aboveHeight = 5;
|
||||
Graphs gr;
|
||||
final double rad = 7;
|
||||
final double width = 4;
|
||||
final Color col = Colors.black;
|
||||
final double aboveHeight = 5;
|
||||
double circleRad = 100;
|
||||
TextStyle textStyle = const TextStyle(
|
||||
final TextStyle textStyle = const TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 21,
|
||||
);
|
||||
|
@ -91,13 +92,14 @@ class CurvePainter extends CustomPainter {
|
|||
//drawLine(canvas, Offset(0, size.height / 2),
|
||||
//Offset(size.width, size.height / 2));
|
||||
|
||||
_gr = getGraph();
|
||||
var off = getDotPos(_gr.getDotAmount(), size);
|
||||
//gr = getGraph();
|
||||
var off = getDotPos(gr.getDotAmount(), size);
|
||||
for (int i = 0; i < off.length; i++) {
|
||||
drawDot(canvas, off[i + 1]!);
|
||||
drawAboveText(canvas, off[i + 1]!, _gr.getDots()[i].getName());
|
||||
drawAboveText(
|
||||
canvas, off[i + 1]!, "${gr.getDots()[i].getName()}:[${i + 1}]");
|
||||
}
|
||||
drawConnections(canvas, _gr.getDots(), off);
|
||||
drawConnections(canvas, gr.getDots(), off);
|
||||
|
||||
paint.color = Colors.blue;
|
||||
paint.style = PaintingStyle.stroke;
|
||||
|
@ -109,7 +111,7 @@ class CurvePainter extends CustomPainter {
|
|||
|
||||
@override
|
||||
bool shouldRepaint(CustomPainter oldDelegate) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*void _drawTextAt(String txt, Offset position, Canvas canvas) {
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:graphs/curve_painter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:graphs/src/graph.dart';
|
||||
|
||||
Graphs getGraph() {
|
||||
List<Dot> d = <Dot>[];
|
||||
d.add(Dot.fromTwoLists("1", [2, 3], [1, 1]));
|
||||
d.add(Dot.fromTwoLists("2", [1, 3], [1, 1]));
|
||||
d.add(Dot.fromTwoLists("3", [1, 2], [1, 1]));
|
||||
d.add(Dot.fromTwoLists("Name1", [], []));
|
||||
d.add(Dot.fromTwoLists("Name2", [], []));
|
||||
return Graphs.fromList("1", d, false, false);
|
||||
}
|
||||
|
||||
class DrawingPage extends StatefulWidget {
|
||||
const DrawingPage({Key? key}) : super(key: key);
|
||||
|
||||
|
@ -15,11 +24,18 @@ class DrawingPage extends StatefulWidget {
|
|||
|
||||
class _DrawingPageState extends State<DrawingPage> {
|
||||
double screenSize = 0;
|
||||
Graphs data = Graphs("Data");
|
||||
Graphs data = getGraph();
|
||||
|
||||
final _textDot1Controller = TextEditingController();
|
||||
final _textDot2Controller = TextEditingController();
|
||||
final _textLenController = TextEditingController();
|
||||
final _textNameController = TextEditingController();
|
||||
final _textInptController = TextEditingController();
|
||||
final _textDistController = TextEditingController();
|
||||
final _textLnthController = TextEditingController();
|
||||
void clearTextControllers() {
|
||||
_textDistController.clear();
|
||||
_textInptController.clear();
|
||||
_textLnthController.clear();
|
||||
_textNameController.clear();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -35,35 +51,44 @@ class _DrawingPageState extends State<DrawingPage> {
|
|||
child: Column(children: <Widget>[
|
||||
const SizedBox(height: 5),
|
||||
Row(children: [
|
||||
addSpaceW(screenSize / 4 - 20),
|
||||
createInputBox("Input dot1 number", screenSize / 4 - 5,
|
||||
Icons.fiber_manual_record, _textDot1Controller),
|
||||
//addSpaceW(4),
|
||||
createInputBox("Input dot2 number", screenSize / 4 - 5,
|
||||
Icons.fiber_manual_record, _textDot2Controller),
|
||||
addSpaceW(screenSize / 8 - 20),
|
||||
createButton("\nAdd dot\n", addDotPushed),
|
||||
createInputBox("Dot name", screenSize / 4 - 25, Icons.label,
|
||||
_textNameController),
|
||||
addSpaceW(20),
|
||||
createButton("\nDel dot \n", delDotPushed),
|
||||
createInputBox("Dot number", screenSize / 4 - 25,
|
||||
Icons.fiber_manual_record, _textInptController),
|
||||
]),
|
||||
addSpaceH(3),
|
||||
createInputBox("Input path length", screenSize / 3 + 30,
|
||||
Icons.arrow_right_alt_outlined, _textLenController),
|
||||
Row(children: [
|
||||
addSpaceW(screenSize / 4 - 20),
|
||||
createInputBox("Destination number", screenSize / 4 - 5,
|
||||
Icons.fiber_manual_record, _textDistController),
|
||||
//addSpaceW(4),
|
||||
createInputBox("Input length", screenSize / 4 - 5,
|
||||
Icons.arrow_right_alt_outlined, _textLnthController),
|
||||
]),
|
||||
//createInputBox("Input path length", screenSize / 3 + 30, Icons.arrow_right_alt_outlined, _textLenController),
|
||||
]),
|
||||
),
|
||||
actions: [
|
||||
Column(
|
||||
/*Column(
|
||||
children: [
|
||||
addSpaceH(10),
|
||||
createButton("\nAdd dot\n", addDotPushed),
|
||||
addSpaceH(3),
|
||||
createButton("\nDel dot \n", addLenPushed),
|
||||
],
|
||||
),
|
||||
),*/
|
||||
IconButton(
|
||||
onPressed: () => closeApp(),
|
||||
icon: const Icon(Icons.close),
|
||||
iconSize: 50,
|
||||
onPressed: () => flushData(),
|
||||
icon: const Icon(Icons.delete_sweep),
|
||||
iconSize: 60,
|
||||
),
|
||||
]),
|
||||
body: CustomPaint(
|
||||
painter: CurvePainter(Graphs()),
|
||||
painter: CurvePainter(gr: data),
|
||||
child: const Center(),
|
||||
),
|
||||
));
|
||||
|
@ -116,17 +141,37 @@ class _DrawingPageState extends State<DrawingPage> {
|
|||
}
|
||||
|
||||
void addDotPushed() {
|
||||
showPopUp("Test", "Test message");
|
||||
print(_textDot1Controller.text);
|
||||
_textDot1Controller.clear();
|
||||
//showPopUp("Test", "Test message");
|
||||
//var inp = int.tryParse(_textNameController.text);
|
||||
if (_textNameController.text == "") {
|
||||
showPopUp("Error", "No name in \"Dot name\" box");
|
||||
} else {
|
||||
String? res = data.addIsolated(_textNameController.text);
|
||||
if (res != null) {
|
||||
showPopUp("Error", res);
|
||||
}
|
||||
}
|
||||
//print(_textNameController.text);
|
||||
clearTextControllers();
|
||||
}
|
||||
|
||||
void delDotPushed() {
|
||||
if (_textNameController.text == "") {
|
||||
showPopUp("Error", "No name in \"Dot name\" box");
|
||||
} else {
|
||||
String? res = data.addIsolated(_textNameController.text);
|
||||
if (res != null) {
|
||||
showPopUp("Error", res);
|
||||
}
|
||||
}
|
||||
clearTextControllers();
|
||||
}
|
||||
|
||||
void addLenPushed() {
|
||||
//data.delDot()
|
||||
print(
|
||||
"${_textDot1Controller.text} -> ${_textDot2Controller.text} = ${_textLenController.text}");
|
||||
_textDot1Controller.clear();
|
||||
_textDot2Controller.clear();
|
||||
_textLenController.clear();
|
||||
"${_textInptController.text} -> ${_textDistController.text} = ${_textLnthController.text}");
|
||||
clearTextControllers();
|
||||
}
|
||||
|
||||
void showPopUp(String alertTitle, String err) => showDialog<String>(
|
||||
|
@ -143,10 +188,11 @@ class _DrawingPageState extends State<DrawingPage> {
|
|||
),
|
||||
);
|
||||
|
||||
void closeApp() {
|
||||
if (Platform.isWindows) {
|
||||
void flushData() {
|
||||
/*if (Platform.isWindows) {
|
||||
exit(0);
|
||||
}
|
||||
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
|
||||
SystemChannels.platform.invokeMethod('SystemNavigator.pop');*/
|
||||
data.flushData();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,11 +97,9 @@ class Graphs {
|
|||
bool _oriented = false; //Ориентированность
|
||||
|
||||
//*********************Add************************
|
||||
bool addDot(Dot a) {
|
||||
String? addDot(Dot a) {
|
||||
if (getNumByName(a.getName()) != null) {
|
||||
print(
|
||||
"Dot name ${a.getName()} already in use. Change name or use addPath");
|
||||
return false;
|
||||
return ("Dot name \"${a.getName()}\" already in use. Change name or use addPath");
|
||||
}
|
||||
_amount++;
|
||||
a.num = _amount;
|
||||
|
@ -109,7 +107,7 @@ class Graphs {
|
|||
_syncNameTable();
|
||||
checkDots(false);
|
||||
if (!_oriented) _fullFix();
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
|
||||
bool addDotFromToLists(String name, List<int> num0, List<int> length,
|
||||
|
@ -129,21 +127,21 @@ class Graphs {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool addIsolated(String name) {
|
||||
var o = addDot(Dot.fromTwoLists(name, [], []));
|
||||
String? addIsolated(String name) {
|
||||
var res = addDot(Dot.fromTwoLists(name, [], []));
|
||||
_syncNameTable();
|
||||
return o;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool addPath(int from, int to, [int len = 0]) {
|
||||
String? addPath(int from, int to, [int len = 0]) {
|
||||
if (from <= 0 || from > _amount || to <= 0 && to > _amount) {
|
||||
return false;
|
||||
return "Index out of range. Have dots 1..$_amount";
|
||||
}
|
||||
_dots[from - 1].addPath(to, len);
|
||||
if (!_oriented) {
|
||||
_dots[to - 1].addPath(from, len);
|
||||
}
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
//*********************Add************************
|
||||
|
||||
|
@ -400,6 +398,12 @@ class Graphs {
|
|||
_syncNameTable();
|
||||
}
|
||||
|
||||
//***********Cleaning***********
|
||||
void flushData() {
|
||||
_dots = <Dot>[];
|
||||
}
|
||||
//***********Cleaning***********
|
||||
|
||||
//************Алгоритмы************
|
||||
bool bfsHasPath(int startDot, int goalDot) {
|
||||
// обход в ширину
|
||||
|
|
Loading…
Reference in New Issue