From f4a2ce6f608049dc11f00908ee8a829060882de3 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期四, 25 十二月 2025 16:38:32 +0800
Subject: [PATCH] 优化了部分内容
---
src/dikuai/daohangyulan.java | 80 ++++++++++++++++++++++++++++++++++++++-
1 files changed, 77 insertions(+), 3 deletions(-)
diff --git a/src/dikuai/daohangyulan.java b/src/dikuai/daohangyulan.java
index ec51972..8d3bfaf 100644
--- a/src/dikuai/daohangyulan.java
+++ b/src/dikuai/daohangyulan.java
@@ -9,6 +9,7 @@
import java.util.ArrayList;
import zhuye.Shouye;
import zhuye.MapRenderer;
+import gecaoji.Device;
import gecaoji.Gecaoji;
import gecaoji.lujingdraw;
import publicway.buttonset;
@@ -82,12 +83,85 @@
return;
}
- // 瑙f瀽璺緞鍧愭爣
- pathPoints = lujingdraw.parsePlannedPath(plannedPath);
- if (pathPoints == null || pathPoints.size() < 2) {
+ // 1. 瑙f瀽璺緞鍧愭爣锛堝師濮嬭矾寰勶級
+ List<Point2D.Double> rawPathPoints = lujingdraw.parsePlannedPath(plannedPath);
+ if (rawPathPoints == null || rawPathPoints.size() < 2) {
JOptionPane.showMessageDialog(null, "璺緞鍧愭爣瑙f瀽澶辫触锛屾棤娉曡繘琛屽鑸瑙�", "閿欒", JOptionPane.ERROR_MESSAGE);
return;
}
+
+ // 2. 灏濊瘯閲嶆柊鐢熸垚瀹屾暣璺緞娈碉紙鍖呭惈鍥磋竟鍜屼綔涓氳矾寰勶級
+ // 杩欐牱鍙互纭繚瀵艰埅棰勮鏃讹紝鍓茶崏鏈哄厛娌跨潃鍐呯缉杈圭晫璧颁竴鍦堬紝鍐嶈蛋鍓茶崏璺緞
+ List<lujing.Lunjingguihua.PathSegment> segments = null;
+ String boundaryCoords = dikuai.getBoundaryCoordinates();
+ String mowingWidth = dikuai.getMowingBladeWidth(); // 娉ㄦ剰锛氳繖閲屽簲璇ョ敤鍓茶崏瀹藉害锛岃�屼笉鏄壊鍒�瀹藉害锛岄�氬父鏄竴鏍风殑
+ // 濡傛灉娌℃湁鍓茶崏瀹藉害锛屽皾璇曚粠Device鑾峰彇
+ if (mowingWidth == null || mowingWidth.trim().isEmpty() || "-1".equals(mowingWidth.trim())) {
+ Device device = Device.getActiveDevice();
+ if (device != null) {
+ mowingWidth = device.getMowingWidth();
+ }
+ }
+ // 濡傛灉杩樻槸娌℃湁锛屼娇鐢ㄩ粯璁ゅ��
+ if (mowingWidth == null || mowingWidth.trim().isEmpty() || "-1".equals(mowingWidth.trim())) {
+ mowingWidth = "0.34";
+ }
+
+ String safetyDistance = dikuai.getMowingSafetyDistance();
+ String obstaclesCoords = dikuai.getObstacleCoordinates();
+ String mowingPattern = dikuai.getMowingPattern();
+
+ if (boundaryCoords != null && !boundaryCoords.trim().isEmpty() && !"-1".equals(boundaryCoords.trim())) {
+ try {
+ // 瑙f瀽鍓茶崏妯″紡
+ String mode = "parallel"; // 榛樿骞宠妯″紡
+ if (mowingPattern != null && !mowingPattern.trim().isEmpty()) {
+ String pattern = mowingPattern.trim().toLowerCase();
+ if ("1".equals(pattern) || "spiral".equals(pattern) || "铻烘棆寮�".equals(pattern) || "铻烘棆".equals(pattern)) {
+ mode = "spiral";
+ } else if ("parallel".equals(pattern) || "骞宠绾�".equals(pattern) || "骞宠".equals(pattern)) {
+ mode = "parallel";
+ }
+ }
+
+ // 璋冪敤璺緞瑙勫垝鐢熸垚瀹屾暣璺緞娈�
+ segments = lujing.Lunjingguihua.generatePathSegments(
+ boundaryCoords,
+ obstaclesCoords != null ? obstaclesCoords : "",
+ mowingWidth,
+ safetyDistance,
+ mode
+ );
+ } catch (Exception e) {
+ // 濡傛灉閲嶆柊鐢熸垚澶辫触锛宻egments 涓� null
+ System.err.println("瀵艰埅棰勮閲嶆柊鐢熸垚璺緞澶辫触: " + e.getMessage());
+ }
+ }
+
+ // 3. 鏋勫缓鏈�缁堝鑸矾寰勭偣鍒楄〃
+ pathPoints = new ArrayList<>();
+ if (segments != null && !segments.isEmpty()) {
+ // 濡傛灉鎴愬姛鐢熸垚浜嗚矾寰勬锛屼娇鐢ㄨ矾寰勬鏋勫缓鐐瑰垪琛�
+ // 杩欐牱鍖呭惈浜嗗洿杈硅矾寰勫拰浣滀笟璺緞锛屼互鍙婂畠浠箣闂寸殑杩炴帴
+ lujing.Lunjingguihua.PathSegment firstSeg = segments.get(0);
+ pathPoints.add(new Point2D.Double(firstSeg.start.x, firstSeg.start.y));
+
+ for (lujing.Lunjingguihua.PathSegment seg : segments) {
+ // 娣诲姞缁堢偣锛堣捣鐐瑰凡缁忓湪涓婁竴娆″惊鐜垨鍒濆鍖栨椂娣诲姞浜嗭級
+ // 娉ㄦ剰锛氳繖閲屽亣璁捐矾寰勬鏄繛缁殑锛屾垨鑰呮垜浠彧鍏冲績绔偣
+ // 濡傛灉娈典箣闂翠笉杩炵画锛堟湁绌鸿蛋锛夛紝generatePathSegments 搴旇宸茬粡鐢熸垚浜嗚繛鎺ユ锛坕sMowing=false锛�
+ pathPoints.add(new Point2D.Double(seg.end.x, seg.end.y));
+ }
+ } else {
+ // 濡傛灉鐢熸垚澶辫触锛屽洖閫�鍒颁娇鐢ㄥ師濮嬭В鏋愮殑璺緞鐐�
+ // 杩欓�氬父鍙寘鍚綔涓氳矾寰勶紝鍙兘娌℃湁鍥磋竟
+ pathPoints = rawPathPoints;
+ }
+
+ if (pathPoints == null || pathPoints.size() < 2) {
+ JOptionPane.showMessageDialog(null, "鏃犳硶鏋勫缓鏈夋晥鐨勫鑸矾寰�", "閿欒", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
this.currentDikuai = dikuai;
this.currentPathIndex = 0;
--
Gitblit v1.10.0