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