pile_nav_new/lib/pages/pile/pileGenerateCard/pileGenerate.dart
2024-09-04 18:10:55 +08:00

339 lines
13 KiB
Dart

import 'dart:math';
import 'package:cpnav/service/pile_cm.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:scence_map/controllers/controller.dart';
import 'package:scence_map/controllers/plumController.dart';
import '../../../service/pile/device_type.dart';
import '../../../service/pile/input.dart';
import '../../../service/pile/public_widget.dart';
import 'pileGenerController.dart';
final ScenceMapController mapController = Get.find<ScenceMapController>();
final PlumDataController controller = Get.find<PlumDataController>();
class PileGenerate extends StatefulWidget {
const PileGenerate({super.key});
@override
_PileGenerateState createState() => _PileGenerateState();
}
class _PileGenerateState extends State<PileGenerate> {
@override
Widget build(BuildContext context) {
double titleTextWidth = 90;
double inputLength = 120;
FocusNode xFocus = FocusNode();
FocusNode yFocus = FocusNode();
FocusNode directionFocus = FocusNode();
FocusNode pileSpaceFocus = FocusNode();
FocusNode pileWidthFocus = FocusNode();
DeviceType deviceType = getDeviceType(context);
double fontSize = 16;
if (deviceType == DeviceType.mobile) {
fontSize = 16;
} else {
fontSize = 20;
}
double centerPointX = controller.centerXY.value.dx;
double centerPointY = controller.centerXY.value.dy;
final size = MediaQuery.of(context).size;
return OrientationBuilder(builder: ((context, orientation) {
return Scaffold(
appBar: AppBar(
title: const Text("桩点生成"),
toolbarHeight: 30,
leading: IconButton(
icon: Icon(Icons.close),
onPressed: () {
setState(() {
pilecontroller.isPileCardVisible.value = false;
pilecontroller.isRealViewCardVisible.value = false;
});
},
),
),
body: SizedBox(
height: size.height,
child: Stack(
children: [
SingleChildScrollView(
child: AlignWrapWidget(
children: [
Row(
children: [
const Text('地图显示:'),
Obx(() => Switch(
value: controller.isMap.value,
onChanged: ((value) {
controller.isMap.value = !controller.isMap.value;
}))),
],
),
AlignWrapWidget(
children: [
ElevatedButton(
child: const Text("夯锤坐标"),
onPressed: () => {controller.isDirect.value = false},
),
const SizedBox(
width: 10,
),
ElevatedButton(
child: const Text("桩点坐标"),
onPressed: () => {
controller.isGenerate.value = true,
controller.checkValue.value = "checkPile",
controller.isDirect.value = false,
pilecontroller.isPileCardVisible.value = false,
}),
const SizedBox(
width: 10,
),
ElevatedButton(
child: const Text("方向设置"),
onPressed: () => {
controller.isGenerate.value = true,
controller.checkValue.value = "checkDirection",
controller.isDirect.value = true,
controller.centerXY.value =
Offset(centerPointX, centerPointY),
pilecontroller.isPileCardVisible.value = false,
}),
],
),
Row(children: [
FixedWidthTextWidget(width: titleTextWidth, text: "X:"),
inputText(
inputLength: inputLength,
value: centerPointX.toString(),
fontsize: fontSize,
focusNode: yFocus,
onChanged: (value) => value.isNotEmpty
? centerPointY = double.parse(value)
: '')
]),
Row(children: [
FixedWidthTextWidget(width: titleTextWidth, text: "Y:"),
inputText(
inputLength: inputLength,
value: centerPointY.toString(),
fontsize: fontSize,
focusNode: xFocus,
onChanged: (value) => value.isNotEmpty
? centerPointX = double.parse(value)
: '')
]),
Row(children: [
FixedWidthTextWidget(width: titleTextWidth, text: "方向(°):"),
inputText(
inputLength: inputLength,
value: controller.direction.toString(),
fontsize: fontSize,
focusNode: directionFocus,
keyboardType: 0,
onChanged: (value) {
if (value.isNotEmpty) {
controller.direction.value = double.parse(value);
// bug 值修改后 绘制没有变化
controller.angle.value =
controller.direction.value * pi / 180;
}
})
]),
Row(children: [
FixedWidthTextWidget(
width: titleTextWidth + 10, text: "夯点间距(m):"),
inputText(
inputLength: inputLength - 10,
fontsize: fontSize,
value: controller.space.toString(),
focusNode: pileSpaceFocus,
onChanged: (value) => {
value.isNotEmpty
? controller.space.value = double.parse(value)
: '',
})
]),
Row(children: [
FixedWidthTextWidget(
width: titleTextWidth + 10, text: "宽度(m):"),
inputText(
inputLength: inputLength - 10,
fontsize: fontSize,
value: controller.pileWidth.toString(),
focusNode: pileWidthFocus,
onChanged: (value) => {
value.isNotEmpty
? controller.pileWidth.value =
double.parse(value)
: '',
})
]),
Row(children: [
const Icon(
Icons.tips_and_updates_outlined,
color: Colors.red,
),
Text(
controller.isPileId.value
? '选中桩点:${controller.checkName.value}'
: ' 未选中桩点',
style: TextStyle(
color: !controller.isPileId.value
? Colors.red
: Colors.black),
)
]),
],
)),
Positioned(
bottom: 10,
child: Row(
children: [
TextButton(
child: const Text('取消'),
onPressed: () {
controller.isGenerate.value = false;
controller.isDirect.value = false;
controller.isSave.value = false;
// 执行取消的逻辑
},
),
TextButton(
child: const Text('确定'),
onPressed: () {
// 执行确定的逻辑
var dx = (controller.canvasSize.width) / 2;
var dy = (controller.canvasSize.height) / 2;
var rotation = mapController.rotation.value;
for (int i = 0; i < controller.plumList.length; i++) {
Offset item = controller.plumList[i];
var dx1 = ((item.dx - dx) * cos(rotation) +
(item.dy - dy) * sin(rotation));
var dy1 = -(item.dx - dx) * sin(rotation) +
(item.dy - dy) * cos(rotation);
Offset xy = mapController.ScreenCenter2xy(dx1, dy1);
PilePoint pilePoint = PilePoint(
x: (xy.dx * 1000).roundToDouble() / 1000,
y: (xy.dy * 1000).roundToDouble() / 1000,
times: 0,
id: i + 1,
radius: 0.3);
mapController.pilePoints.add(pilePoint);
}
controller.isGenerate.value = false;
controller.isDirect.value = false;
controller.isSave.value = true;
controller.centerXY.value =
Offset(centerPointX, centerPointY);
},
),
],
))
],
),
),
);
}));
}
}
final PileGenerController pilecontroller = Get.put(PileGenerController());
//卡片
class PileGenerateCard extends StatelessWidget {
const PileGenerateCard();
@override
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
MediaQueryData mediaQueryData =
MediaQueryData.fromView(WidgetsBinding.instance.window); //获取当前屏幕信息
final orientation = mediaQueryData.orientation; //获得设备方向
double rectWidth = size.width;
final deviceType = getDeviceType(context);
if (orientation == Orientation.landscape) {
rectWidth = size.width / 2;
if (deviceType == DeviceType.mobile) {
rectWidth = size.height - 130;
}
} else {
rectWidth = size.height / 2;
if (deviceType == DeviceType.mobile) {
rectWidth = size.width - 5;
}
}
return Obx(() => Visibility(
visible: pilecontroller.isPileCardVisible.value,
child: Positioned(
right: 0,
top: 0,
width: rectWidth - 30,
height: rectWidth + 45,
child: Stack(children: [
Container(
decoration: const BoxDecoration(color: Colors.transparent),
child: Stack(children: [
Card(
color: Colors.transparent,
elevation: 5.0,
child: PileGenerate(),
),
]))
]))));
}
}
//卡片
class PileGenerateCard1 extends StatelessWidget {
const PileGenerateCard1();
@override
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
MediaQueryData mediaQueryData =
MediaQueryData.fromView(WidgetsBinding.instance.window); //获取当前屏幕信息
final orientation = mediaQueryData.orientation; //获得设备方向
double rectWidth = size.width;
final deviceType = getDeviceType(context);
if (orientation == Orientation.landscape) {
rectWidth = size.width / 2;
if (deviceType == DeviceType.mobile) {
rectWidth = size.height - 130;
}
} else {
rectWidth = size.height / 2;
if (deviceType == DeviceType.mobile) {
rectWidth = size.width - 5;
}
}
return Obx(() => Visibility(
visible: pilecontroller.isRealViewCardVisible.value,
child: Positioned(
right: 0,
top: 0,
width: rectWidth - 30,
height: rectWidth + 45,
child: Stack(children: [
Container(
decoration: const BoxDecoration(color: Colors.transparent),
child: Stack(children: [
Card(
color: Colors.transparent,
elevation: 5.0,
child: PileGenerate(),
),
]))
]))));
}
}