From 3ca5f28be0a266e57a3ddece80d28072a1811de7 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期四, 25 十二月 2025 16:04:04 +0800
Subject: [PATCH] 解决了点击保存路径的bug
---
src/zhangaiwu/AddDikuai.java | 568 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 548 insertions(+), 20 deletions(-)
diff --git a/src/zhangaiwu/AddDikuai.java b/src/zhangaiwu/AddDikuai.java
index 07d238c..8d6764a 100644
--- a/src/zhangaiwu/AddDikuai.java
+++ b/src/zhangaiwu/AddDikuai.java
@@ -24,6 +24,9 @@
import dikuai.Gecaoanquanjuli;
import bianjie.Bianjieyouhuatoxy;
import lujing.Lunjingguihua;
+import lujing.Qufenxingzhuang;
+import lujing.AoxinglujingNoObstacle;
+import lujing.YixinglujingNoObstacle;
import set.Setsys;
import ui.UIConfig;
import zhuye.MowerLocationData;
@@ -73,7 +76,8 @@
private JButton prevButton;
private JButton nextButton;
private JButton createButton;
- private JButton previewButton;
+ private JButton previewButton; // 姝ラ3鐨勯瑙堟寜閽紙棰勮鍓茶崏璺緞锛�
+ private JButton boundaryPreviewButton; // 姝ラ2鐨勯瑙堟寜閽紙棰勮杈圭晫锛�
private Component previewButtonSpacer;
private JLabel boundaryCountLabel;
private JTextArea boundaryXYTextArea; // 鏄剧ず杈圭晫XY鍧愭爣鐨勬枃鏈煙
@@ -260,7 +264,7 @@
));
areaNameField.setAlignmentX(Component.LEFT_ALIGNMENT);
- // 娣诲姞杈撳叆妗嗙劍鐐规晥鏋�
+ // 娣诲姞杈撳叆妗嗙劍鐐规晥鏋滃拰鏂囨湰鍙樺寲鐩戝惉
areaNameField.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
@@ -276,6 +280,16 @@
BorderFactory.createLineBorder(BORDER_COLOR, 2),
BorderFactory.createEmptyBorder(12, 15, 12, 15)
));
+ // 鏇存柊涓嬩竴姝ユ寜閽姸鎬�
+ updateStep1ButtonState();
+ }
+ });
+
+ // 娣诲姞鏂囨湰鍙樺寲鐩戝惉锛屽疄鏃舵洿鏂版寜閽姸鎬�
+ areaNameField.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyReleased(KeyEvent e) {
+ updateStep1ButtonState();
}
});
@@ -654,6 +668,7 @@
startEndDrawingBtn.setAlignmentX(Component.LEFT_ALIGNMENT);
startEndDrawingBtn.setMaximumSize(new Dimension(400, 55));
startEndDrawingBtn.setEnabled(false); // 鍒濆涓嶅彲鐢�
+ startEndDrawingBtn.setBackground(MEDIUM_GRAY); // 鍒濆鐏拌壊鑳屾櫙
startEndDrawingBtn.addActionListener(e -> toggleDrawing());
@@ -773,7 +788,7 @@
return;
}
if (selectDrawingOption(optionPanel, type, true)) {
- startEndDrawingBtn.setEnabled(true); // 閫夋嫨鍚庡惎鐢ㄦ寜閽�
+ updateStartDrawingButtonState(); // 閫夋嫨鍚庢洿鏂版寜閽姸鎬�
}
}
@@ -866,6 +881,8 @@
JOptionPane.showMessageDialog(this, "杈圭晫缁樺埗宸插畬鎴�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
showBoundaryPointSummary();
updateBoundaryXYDisplay();
+ // 鏇存柊棰勮鍜屼笅涓�姝ユ寜閽姸鎬侊紙鑳屾櫙棰滆壊鍙樼豢鑹诧紝鍙偣鍑伙級
+ updateStep2ButtonsAfterDrawing();
}
}
@@ -1331,15 +1348,34 @@
showStep(2);
return;
}
- Dikuai dikuai = getOrCreatePendingDikuai();
+ // 浠庢楠�2鐨勮竟鐣屽潗鏍囨枃鏈煙鑾峰彇杈圭晫鍧愭爣
String boundaryCoords = null;
- if (dikuai != null) {
- boundaryCoords = normalizeCoordinateValue(dikuai.getBoundaryCoordinates());
+ if (boundaryXYTextArea != null) {
+ String boundaryText = boundaryXYTextArea.getText();
+ if (boundaryText != null && !boundaryText.trim().isEmpty() && !boundaryText.startsWith("ERROR")) {
+ boundaryCoords = boundaryText.trim();
+ }
}
- if (boundaryCoords == null) {
+
+ // 濡傛灉鏂囨湰鍩熶腑娌℃湁锛屽皾璇曚粠dikuaiData鑾峰彇
+ if (boundaryCoords == null || boundaryCoords.isEmpty()) {
+ boundaryCoords = normalizeCoordinateValue(dikuaiData.get("optimizedBoundaryXY"));
+ }
+
+ // 濡傛灉杩樻槸娌℃湁锛屽皾璇曚粠Dikuai瀵硅薄鑾峰彇
+ if (boundaryCoords == null || boundaryCoords.isEmpty()) {
+ Dikuai dikuai = getOrCreatePendingDikuai();
+ if (dikuai != null) {
+ boundaryCoords = normalizeCoordinateValue(dikuai.getBoundaryCoordinates());
+ }
+ }
+
+ // 濡傛灉杩樻槸娌℃湁锛屼粠dikuaiData鑾峰彇boundaryCoordinates
+ if (boundaryCoords == null || boundaryCoords.isEmpty()) {
boundaryCoords = normalizeCoordinateValue(dikuaiData.get("boundaryCoordinates"));
}
- if (boundaryCoords == null) {
+
+ if (boundaryCoords == null || boundaryCoords.isEmpty()) {
JOptionPane.showMessageDialog(this, "鏈壘鍒版湁鏁堢殑鍦板潡杈圭晫鍧愭爣锛屾棤娉曠敓鎴愯矾寰�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
dikuaiData.remove("plannedPath");
showPathGenerationMessage("鏈壘鍒版湁鏁堢殑鍦板潡杈圭晫鍧愭爣锛屾棤娉曠敓鎴愯矾寰勩��", false);
@@ -1403,19 +1439,48 @@
}
}
+ // 鏍煎紡鍖栧壊鑽夊搴﹀拰瀹夊叏璺濈锛堝崟浣嶏細绫筹紝淇濈暀3浣嶅皬鏁帮級
String widthMetersStr = String.format(Locale.US, "%.3f", widthMeters);
String safetyDistanceMetersStr = Double.isNaN(safetyDistanceMeters) ? null : String.format(Locale.US, "%.3f", safetyDistanceMeters);
- String plannerMode = resolvePlannerMode(patternDisplay);
+
+ // 濡傛灉娌℃湁瀹夊叏璺濈锛屼娇鐢ㄩ粯璁ゅ��
+ if (safetyDistanceMetersStr == null) {
+ double defaultSafetyDistance = widthMeters / 2.0 + 0.2;
+ safetyDistanceMetersStr = String.format(Locale.US, "%.3f", defaultSafetyDistance);
+ }
try {
- // 浣跨敤涓庤矾寰勮鍒掗〉闈㈢浉鍚岀殑鏂规硶锛歀unjingguihua.generatePathFromStrings
- String plannedPath = Lunjingguihua.generatePathFromStrings(
- boundaryCoords,
- obstacleCoords != null ? obstacleCoords : "",
- widthMetersStr,
- safetyDistanceMetersStr,
- plannerMode
- );
+ // 1. 璋冪敤Qufenxingzhuang涓殑judgeGrassType鏂规硶璁$畻鍦板潡杈圭晫鐨勫舰鐘�
+ Qufenxingzhuang shapeJudger = new Qufenxingzhuang();
+ int grassType = shapeJudger.judgeGrassType(boundaryCoords);
+ // grassType: 0=鏃犳硶鍒ゆ柇, 1=鍑稿舰, 2=寮傚舰
+
+ String plannedPath = null;
+
+ // 2. 鏍规嵁璁$畻鍚庣殑缁撴灉鍐冲畾璋冪敤鍝釜鏂规硶鐢熸垚鍓茶崏璺緞
+ if (grassType == 1) {
+ // 鍑稿舰鍦板潡 -> 璋冪敤AoxinglujingNoObstacle绫讳腑鐨勬柟娉�
+ List<AoxinglujingNoObstacle.PathSegment> segments =
+ AoxinglujingNoObstacle.planPath(boundaryCoords, widthMetersStr, safetyDistanceMetersStr);
+ plannedPath = formatAoxingPathSegments(segments);
+ } else if (grassType == 2) {
+ // 寮傚舰鍦板潡 -> 璋冪敤YixinglujingNoObstacle涓殑鏂规硶
+ List<YixinglujingNoObstacle.PathSegment> segments =
+ YixinglujingNoObstacle.planPath(boundaryCoords, widthMetersStr, safetyDistanceMetersStr);
+ plannedPath = formatYixingPathSegments(segments);
+ } else {
+ // 鏃犳硶鍒ゆ柇鍦板潡绫诲瀷锛屼娇鐢ㄩ粯璁ゆ柟娉曚綔涓哄悗澶�
+ JOptionPane.showMessageDialog(this, "鏃犳硶鍒ゆ柇鍦板潡绫诲瀷锛屼娇鐢ㄩ粯璁よ矾寰勭敓鎴愭柟娉�",
+ "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ String plannerMode = resolvePlannerMode(patternDisplay);
+ plannedPath = Lunjingguihua.generatePathFromStrings(
+ boundaryCoords,
+ obstacleCoords != null ? obstacleCoords : "",
+ widthMetersStr,
+ safetyDistanceMetersStr,
+ plannerMode
+ );
+ }
if (!isMeaningfulValue(plannedPath)) {
JOptionPane.showMessageDialog(this, "鐢熸垚鍓茶崏璺緞澶辫触: 鐢熸垚缁撴灉涓虹┖", "閿欒", JOptionPane.ERROR_MESSAGE);
@@ -1450,6 +1515,96 @@
}
}
+ /**
+ * 鏍煎紡鍖� AoxinglujingNoObstacle.PathSegment 鍒楄〃涓哄潗鏍囧瓧绗︿覆
+ */
+ private String formatAoxingPathSegments(List<AoxinglujingNoObstacle.PathSegment> segments) {
+ if (segments == null || segments.isEmpty()) {
+ return "";
+ }
+ StringBuilder sb = new StringBuilder();
+ AoxinglujingNoObstacle.Point last = null;
+ for (AoxinglujingNoObstacle.PathSegment segment : segments) {
+ // 鍙坊鍔犲壊鑽夊伐浣滄锛岃烦杩囪繃娓℃
+ if (segment.isMowing) {
+ // 濡傛灉璧风偣涓庝笂涓�涓粓鐐逛笉鍚岋紝娣诲姞璧风偣
+ if (last == null || !equalsAoxingPoint(last, segment.start)) {
+ appendAoxingPoint(sb, segment.start);
+ }
+ // 娣诲姞缁堢偣
+ appendAoxingPoint(sb, segment.end);
+ last = segment.end;
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * 鏍煎紡鍖� YixinglujingNoObstacle.PathSegment 鍒楄〃涓哄潗鏍囧瓧绗︿覆
+ */
+ private String formatYixingPathSegments(List<YixinglujingNoObstacle.PathSegment> segments) {
+ if (segments == null || segments.isEmpty()) {
+ return "";
+ }
+ StringBuilder sb = new StringBuilder();
+ YixinglujingNoObstacle.Point last = null;
+ for (YixinglujingNoObstacle.PathSegment segment : segments) {
+ // 鍙坊鍔犲壊鑽夊伐浣滄锛岃烦杩囪繃娓℃
+ if (segment.isMowing) {
+ // 濡傛灉璧风偣涓庝笂涓�涓粓鐐逛笉鍚岋紝娣诲姞璧风偣
+ if (last == null || !equalsYixingPoint(last, segment.start)) {
+ appendYixingPoint(sb, segment.start);
+ }
+ // 娣诲姞缁堢偣
+ appendYixingPoint(sb, segment.end);
+ last = segment.end;
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * 姣旇緝涓や釜 AoxinglujingNoObstacle.Point 鏄惁鐩稿悓锛堜娇鐢ㄥ皬鐨勫宸級
+ */
+ private boolean equalsAoxingPoint(AoxinglujingNoObstacle.Point p1, AoxinglujingNoObstacle.Point p2) {
+ if (p1 == null || p2 == null) {
+ return p1 == p2;
+ }
+ double tolerance = 1e-6;
+ return Math.abs(p1.x - p2.x) < tolerance && Math.abs(p1.y - p2.y) < tolerance;
+ }
+
+ /**
+ * 娣诲姞 AoxinglujingNoObstacle.Point 鍒板瓧绗︿覆鏋勫缓鍣�
+ */
+ private void appendAoxingPoint(StringBuilder sb, AoxinglujingNoObstacle.Point point) {
+ if (sb.length() > 0) {
+ sb.append(";");
+ }
+ sb.append(String.format(Locale.US, "%.6f,%.6f", point.x, point.y));
+ }
+
+ /**
+ * 姣旇緝涓や釜 YixinglujingNoObstacle.Point 鏄惁鐩稿悓锛堜娇鐢ㄥ皬鐨勫宸級
+ */
+ private boolean equalsYixingPoint(YixinglujingNoObstacle.Point p1, YixinglujingNoObstacle.Point p2) {
+ if (p1 == null || p2 == null) {
+ return p1 == p2;
+ }
+ double tolerance = 1e-6;
+ return Math.abs(p1.x - p2.x) < tolerance && Math.abs(p1.y - p2.y) < tolerance;
+ }
+
+ /**
+ * 娣诲姞 YixinglujingNoObstacle.Point 鍒板瓧绗︿覆鏋勫缓鍣�
+ */
+ private void appendYixingPoint(StringBuilder sb, YixinglujingNoObstacle.Point point) {
+ if (sb.length() > 0) {
+ sb.append(";");
+ }
+ sb.append(String.format(Locale.US, "%.6f,%.6f", point.x, point.y));
+ }
+
private void previewMowingPath() {
if (!hasGeneratedPath()) {
showPathGenerationMessage("璇峰厛鐢熸垚鍓茶崏璺緞鍚庡啀棰勮銆�", false);
@@ -1515,6 +1670,11 @@
JOptionPane.showMessageDialog(this, "鏃犳硶鍚姩棰勮锛岃绋嶅悗鍐嶈瘯", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
return;
}
+
+ // 鍦ㄦ楠�3棰勮鏃讹紝涓嶆樉绀鸿竟鐣岀偣鍦嗗湀
+ if (shouye.getMapRenderer() != null) {
+ shouye.getMapRenderer().setBoundaryPointsVisible(false);
+ }
closePreviewAndDispose();
}
@@ -1575,14 +1735,23 @@
@Override
public void mouseEntered(MouseEvent e) {
if (button.isEnabled()) {
- button.setBackground(PRIMARY_DARK);
+ // 濡傛灉鎸夐挳鍙敤锛岄紶鏍囨偓鍋滄椂鏄剧ず娣辩豢鑹�
+ if (button.getBackground().equals(PRIMARY_COLOR)) {
+ button.setBackground(PRIMARY_DARK);
+ }
}
}
@Override
public void mouseExited(MouseEvent e) {
if (button.isEnabled()) {
- button.setBackground(PRIMARY_COLOR);
+ // 濡傛灉鎸夐挳鍙敤锛岄紶鏍囩寮�鏃舵仮澶嶇豢鑹�
+ if (!button.getBackground().equals(MEDIUM_GRAY)) {
+ button.setBackground(PRIMARY_COLOR);
+ }
+ } else {
+ // 濡傛灉鎸夐挳涓嶅彲鐢紝淇濇寔鐏拌壊
+ button.setBackground(MEDIUM_GRAY);
}
}
});
@@ -1643,7 +1812,15 @@
));
prevButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ boundaryPreviewButton = createPrimaryButton("棰勮", 16);
+ boundaryPreviewButton.setVisible(false);
+ boundaryPreviewButton.setEnabled(false);
+ boundaryPreviewButton.addActionListener(e -> previewBoundary());
+
nextButton = createPrimaryButton("涓嬩竴姝�", 16);
+ nextButton.setBackground(MEDIUM_GRAY); // 鍒濆鐏拌壊鑳屾櫙
+ nextButton.setEnabled(false); // 鍒濆涓嶅彲鐢�
+
createButton = createPrimaryButton("淇濆瓨", 16);
createButton.setVisible(false);
createButton.setEnabled(false);
@@ -1657,6 +1834,8 @@
buttonPanel.add(prevButton);
buttonPanel.add(Box.createHorizontalGlue());
+ buttonPanel.add(boundaryPreviewButton);
+ buttonPanel.add(Box.createHorizontalStrut(15));
buttonPanel.add(nextButton);
buttonPanel.add(previewButtonSpacer);
buttonPanel.add(previewButton);
@@ -1704,6 +1883,11 @@
dikuai.setLandArea(snapshot.areaSqMeters);
dikuai.setBaseStationCoordinates(snapshot.baseStationCoordinates);
dikuai.setUpdateTime(getCurrentTime());
+ // 璁$畻骞惰缃師濮嬭竟鐣孹Y鍧愭爣
+ String originalBoundaryXY = convertOriginalBoundaryToXY(snapshot.originalBoundary, snapshot.baseStationCoordinates);
+ if (originalBoundaryXY != null && !originalBoundaryXY.isEmpty()) {
+ dikuai.setBoundaryOriginalXY(originalBoundaryXY);
+ }
Dikuai.putDikuai(landNumber, dikuai);
}
@@ -1810,6 +1994,144 @@
}
return dikuai;
}
+
+ /**
+ * 灏嗗師濮嬭竟鐣屽潗鏍囷紙缁忕含搴︽牸寮忥級杞崲涓篨Y鍧愭爣
+ * @param originalBoundary 鍘熷杈圭晫鍧愭爣瀛楃涓诧紝鏍煎紡锛�"lat1,lon1,alt1;lat2,lon2,alt2;..."
+ * @param baseStationCoordinates 鍩哄噯绔欏潗鏍囷紝鏍煎紡锛�"lat,N/S,lon,E/W"
+ * @return XY鍧愭爣瀛楃涓诧紝鏍煎紡锛�"X0,Y0;X1,Y1;X2,Y2;..." 濡傛灉杞崲澶辫触杩斿洖null
+ */
+ private static String convertOriginalBoundaryToXY(String originalBoundary, String baseStationCoordinates) {
+ if (originalBoundary == null || originalBoundary.trim().isEmpty() || "-1".equals(originalBoundary.trim())) {
+ return null;
+ }
+ if (baseStationCoordinates == null || baseStationCoordinates.trim().isEmpty()) {
+ return null;
+ }
+
+ try {
+ // 瑙f瀽鍩哄噯绔欏潗鏍�
+ String[] baseParts = baseStationCoordinates.trim().split(",");
+ if (baseParts.length != 4) {
+ return null;
+ }
+ double baseLat = convertToDecimalDegree(baseParts[0], baseParts[1]);
+ double baseLon = convertToDecimalDegree(baseParts[2], baseParts[3]);
+
+ // 瑙f瀽鍘熷杈圭晫鍧愭爣
+ String[] points = originalBoundary.split(";");
+ StringBuilder xyStr = new StringBuilder();
+
+ for (int i = 0; i < points.length; i++) {
+ String point = points[i].trim();
+ if (point.isEmpty()) {
+ continue;
+ }
+
+ String[] coords = point.split(",");
+ if (coords.length >= 2) {
+ try {
+ double lat = Double.parseDouble(coords[0].trim());
+ double lon = Double.parseDouble(coords[1].trim());
+
+ // 杞崲涓篨Y鍧愭爣
+ double[] xy = publicway.Gpstoxuzuobiao.convertLatLonToLocal(lat, lon, baseLat, baseLon);
+ if (xy != null && xy.length >= 2) {
+ if (xyStr.length() > 0) {
+ xyStr.append(";");
+ }
+ xyStr.append(String.format(Locale.US, "%.3f,%.3f", xy[0], xy[1]));
+ }
+ } catch (NumberFormatException e) {
+ // 璺宠繃鏃犳晥鐨勫潗鏍囩偣
+ continue;
+ }
+ }
+ }
+
+ return xyStr.length() > 0 ? xyStr.toString() : null;
+ } catch (Exception e) {
+ System.err.println("杞崲鍘熷杈圭晫鍧愭爣鍒癤Y澶辫触: " + e.getMessage());
+ return null;
+ }
+ }
+
+ /**
+ * 棰勮杈圭晫
+ */
+ private void previewBoundary() {
+ if (!dikuaiData.containsKey("boundaryDrawn")) {
+ JOptionPane.showMessageDialog(this, "璇峰厛瀹屾垚杈圭晫缁樺埗鍚庡啀棰勮", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+
+ // 鑾峰彇鎴栧垱寤哄湴鍧楀璞�
+ String landNumber = getPendingLandNumber();
+ Dikuai dikuai = getOrCreatePendingDikuai();
+ if (dikuai == null) {
+ JOptionPane.showMessageDialog(this, "鏃犳硶鑾峰彇鍦板潡淇℃伅", "閿欒", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ // 纭繚鍦板潡鏁版嵁鏄渶鏂扮殑
+ String optimizedBoundaryXY = dikuaiData.get("optimizedBoundaryXY");
+ if (optimizedBoundaryXY == null || optimizedBoundaryXY.isEmpty() || optimizedBoundaryXY.startsWith("ERROR")) {
+ // 濡傛灉娌℃湁浼樺寲鍚庣殑杈圭晫锛屽皾璇曚粠boundaryCoordinates鑾峰彇
+ String boundaryCoords = dikuaiData.get("boundaryCoordinates");
+ if (boundaryCoords != null && !boundaryCoords.isEmpty() && !"-1".equals(boundaryCoords)) {
+ optimizedBoundaryXY = boundaryCoords;
+ } else {
+ // 灏濊瘯浠庡湴鍧楀璞¤幏鍙�
+ optimizedBoundaryXY = dikuai.getBoundaryCoordinates();
+ }
+ }
+
+ if (optimizedBoundaryXY == null || optimizedBoundaryXY.isEmpty() || "-1".equals(optimizedBoundaryXY)) {
+ JOptionPane.showMessageDialog(this, "鏈壘鍒版湁鏁堢殑杈圭晫鍧愭爣锛屾棤娉曢瑙�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+
+ // 纭繚鍘熷杈圭晫XY鍧愭爣宸茶绠�
+ String originalBoundaryXY = dikuai.getBoundaryOriginalXY();
+ if (originalBoundaryXY == null || originalBoundaryXY.isEmpty() || "-1".equals(originalBoundaryXY)) {
+ // 璁$畻鍘熷杈圭晫XY鍧愭爣
+ String originalBoundary = dikuaiData.get("boundaryOriginalCoordinates");
+ String baseStationCoordinates = dikuaiData.get("baseStationCoordinates");
+ if (originalBoundary != null && baseStationCoordinates != null) {
+ originalBoundaryXY = convertOriginalBoundaryToXY(originalBoundary, baseStationCoordinates);
+ if (originalBoundaryXY != null && !originalBoundaryXY.isEmpty()) {
+ dikuai.setBoundaryOriginalXY(originalBoundaryXY);
+ Dikuai.putDikuai(landNumber, dikuai);
+ }
+ }
+ }
+
+ // 淇濆瓨浼氳瘽蹇収
+ captureSessionSnapshot();
+
+ // 鍒涘缓final鍙橀噺渚沴ambda浣跨敤
+ final String finalOptimizedBoundaryXY = optimizedBoundaryXY;
+ final Dikuai finalDikuai = dikuai;
+
+ // 鍏抽棴瀵硅瘽妗�
+ setVisible(false);
+ dispose();
+
+ // 璋冪敤棣栭〉鏄剧ず棰勮锛堜笌杈圭晫绠$悊椤甸潰閫昏緫涓�鑷达級
+ SwingUtilities.invokeLater(() -> {
+ Shouye.showBoundaryPreview(finalDikuai, finalOptimizedBoundaryXY, () -> {
+ // 杩斿洖鍥炶皟锛氶噸鏂版墦寮�鏂板鍦板潡瀵硅瘽妗嗭紝骞舵樉绀烘楠�2
+ Component parent = Shouye.getInstance();
+ if (parent != null) {
+ // 纭繚浼氳瘽鐘舵�佹纭紝浠ヤ究杩斿洖鏃舵樉绀烘楠�2
+ if (activeSession != null && activeSession.drawingCompleted) {
+ resumeRequested = true;
+ }
+ showAddDikuaiDialog(parent);
+ }
+ });
+ });
+ }
private void hideBoundaryPointSummary() {
if (boundaryCountLabel != null) {
@@ -2010,6 +2332,8 @@
if (step == 1) {
updateObstacleSummary();
+ // 姝ラ1鏄剧ず鏃讹紝绔嬪嵆鏇存柊鎸夐挳鐘舵��
+ SwingUtilities.invokeLater(() -> updateStep1ButtonState());
}
// 鏇存柊鎸夐挳鐘舵��
@@ -2030,6 +2354,39 @@
if (previewButtonSpacer != null) {
previewButtonSpacer.setVisible(false);
}
+ // 姝ラ1锛氭牴鎹獙璇佺粨鏋滄洿鏂颁笅涓�姝ユ寜閽姸鎬�
+ if (step == 1) {
+ updateStep1ButtonState();
+ }
+ // 姝ラ2鏄剧ず杈圭晫棰勮鎸夐挳
+ if (step == 2) {
+ if (boundaryPreviewButton != null) {
+ boundaryPreviewButton.setVisible(true);
+ // 鏍规嵁鏄惁瀹屾垚杈圭晫缁樺埗鏉ヨ缃寜閽姸鎬佸拰鑳屾櫙棰滆壊
+ boolean boundaryDrawn = dikuaiData.containsKey("boundaryDrawn");
+ boundaryPreviewButton.setEnabled(boundaryDrawn);
+ if (boundaryDrawn) {
+ boundaryPreviewButton.setBackground(PRIMARY_COLOR); // 缁胯壊鑳屾櫙
+ } else {
+ boundaryPreviewButton.setBackground(MEDIUM_GRAY); // 鐏拌壊鑳屾櫙
+ }
+ }
+ // 鏇存柊涓嬩竴姝ユ寜閽姸鎬侊紙鏍规嵁鏄惁瀹屾垚杈圭晫缁樺埗锛�
+ boolean boundaryDrawn = dikuaiData.containsKey("boundaryDrawn");
+ nextButton.setEnabled(boundaryDrawn);
+ if (boundaryDrawn) {
+ nextButton.setBackground(PRIMARY_COLOR); // 缁胯壊鑳屾櫙
+ } else {
+ nextButton.setBackground(MEDIUM_GRAY); // 鐏拌壊鑳屾櫙
+ }
+ // 鏇存柊寮�濮嬬粯鍒舵寜閽姸鎬�
+ updateStartDrawingButtonState();
+ } else {
+ if (boundaryPreviewButton != null) {
+ boundaryPreviewButton.setVisible(false);
+ boundaryPreviewButton.setEnabled(false);
+ }
+ }
} else {
nextButton.setVisible(false);
createButton.setVisible(true);
@@ -2039,6 +2396,10 @@
if (previewButtonSpacer != null) {
previewButtonSpacer.setVisible(true);
}
+ if (boundaryPreviewButton != null) {
+ boundaryPreviewButton.setVisible(false);
+ boundaryPreviewButton.setEnabled(false);
+ }
setPathAvailability(hasGeneratedPath());
}
@@ -2049,6 +2410,85 @@
}
}
+ /**
+ * 鏇存柊姝ラ1鐨勪笅涓�姝ユ寜閽姸鎬�
+ * 鏍规嵁鍦板潡鍚嶇О鏄惁濉啓鏉ヨ缃寜閽殑鍚敤鐘舵�佸拰鑳屾櫙棰滆壊
+ */
+ private void updateStep1ButtonState() {
+ if (nextButton == null || currentStep != 1) {
+ return;
+ }
+
+ String name = areaNameField.getText().trim();
+ boolean canProceed = !name.isEmpty();
+
+ nextButton.setEnabled(canProceed);
+ if (canProceed) {
+ // 鍙偣鍑绘椂锛氱豢鑹茶儗鏅�
+ nextButton.setBackground(PRIMARY_COLOR);
+ } else {
+ // 涓嶅彲鐐瑰嚮鏃讹細鐏拌壊鑳屾櫙
+ nextButton.setBackground(MEDIUM_GRAY);
+ }
+ }
+
+ /**
+ * 鏇存柊姝ラ2鐨勫紑濮嬬粯鍒舵寜閽姸鎬�
+ * 鏍规嵁鏄惁閫夋嫨浜嗙粯鍒舵柟寮忔潵璁剧疆鎸夐挳鐨勫惎鐢ㄧ姸鎬佸拰鑳屾櫙棰滆壊
+ */
+ private void updateStartDrawingButtonState() {
+ if (startEndDrawingBtn == null || currentStep != 2) {
+ return;
+ }
+
+ boolean hasSelectedMethod = dikuaiData.containsKey("drawingMethod");
+ boolean isDrawingActive = isDrawing;
+
+ // 濡傛灉姝e湪缁樺埗锛屾寜閽姸鎬佺敱toggleDrawing鏂规硶鎺у埗
+ if (isDrawingActive) {
+ return;
+ }
+
+ // 濡傛灉宸茬粡瀹屾垚缁樺埗锛屾寜閽樉绀�"宸插畬鎴�"涓斾笉鍙敤
+ boolean boundaryDrawn = dikuaiData.containsKey("boundaryDrawn");
+ if (boundaryDrawn) {
+ startEndDrawingBtn.setEnabled(false);
+ startEndDrawingBtn.setBackground(MEDIUM_GRAY);
+ return;
+ }
+
+ startEndDrawingBtn.setEnabled(hasSelectedMethod);
+ if (hasSelectedMethod) {
+ // 宸查�夋嫨缁樺埗鏂瑰紡锛氱豢鑹茶儗鏅紝鍙偣鍑�
+ startEndDrawingBtn.setBackground(PRIMARY_COLOR);
+ } else {
+ // 鏈�夋嫨缁樺埗鏂瑰紡锛氱伆鑹茶儗鏅紝涓嶅彲鐐瑰嚮
+ startEndDrawingBtn.setBackground(MEDIUM_GRAY);
+ }
+ }
+
+ /**
+ * 鏇存柊姝ラ2鐨勯瑙堝拰涓嬩竴姝ユ寜閽姸鎬侊紙鍦ㄥ畬鎴愯竟鐣岀粯鍒跺悗璋冪敤锛�
+ * 灏嗘寜閽儗鏅鑹茶缃负缁胯壊锛岃〃绀哄彲浠ョ偣鍑绘搷浣�
+ */
+ private void updateStep2ButtonsAfterDrawing() {
+ if (currentStep != 2) {
+ return;
+ }
+
+ // 鏇存柊棰勮鎸夐挳
+ if (boundaryPreviewButton != null) {
+ boundaryPreviewButton.setEnabled(true);
+ boundaryPreviewButton.setBackground(PRIMARY_COLOR); // 缁胯壊鑳屾櫙
+ }
+
+ // 鏇存柊涓嬩竴姝ユ寜閽�
+ if (nextButton != null) {
+ nextButton.setEnabled(true);
+ nextButton.setBackground(PRIMARY_COLOR); // 缁胯壊鑳屾櫙
+ }
+ }
+
private boolean validateCurrentStep() {
switch (currentStep) {
case 1:
@@ -2244,6 +2684,25 @@
private String generateNewLandNumber() {
Map<String, Dikuai> existing = Dikuai.getAllDikuai();
+
+ // 鑾峰彇鍓茶崏鏈虹紪鍙�
+ String mowerId = Setsys.getPropertyValue("mowerId");
+
+ // 濡傛灉鏈夊壊鑽夋満缂栧彿锛屼娇鐢� 缂栧彿+涓や綅鑷鏁板瓧 鏍煎紡
+ if (mowerId != null && !mowerId.trim().isEmpty() && !"-1".equals(mowerId)) {
+ int attempt = 1;
+ while (true) {
+ // 鏍煎紡鍖栦负涓や綅鏁板瓧锛屽 01, 02, ...
+ String suffix = String.format("%02d", attempt);
+ String candidate = mowerId + suffix;
+ if (!existing.containsKey(candidate)) {
+ return candidate;
+ }
+ attempt++;
+ }
+ }
+
+ // 濡傛灉娌℃湁鍓茶崏鏈虹紪鍙凤紝鍥為��鍒伴粯璁ら�昏緫
int attempt = 1;
while (true) {
String candidate = "LAND" + attempt;
@@ -2340,6 +2799,8 @@
showStep(2);
showBoundaryPointSummary();
updateBoundaryXYDisplay();
+ // 鏇存柊棰勮鍜屼笅涓�姝ユ寜閽姸鎬侊紙鑳屾櫙棰滆壊鍙樼豢鑹诧紝鍙偣鍑伙級
+ updateStep2ButtonsAfterDrawing();
} else {
if (startEndDrawingBtn != null) {
startEndDrawingBtn.setText("寮�濮嬬粯鍒�");
@@ -2511,10 +2972,70 @@
if (dikuaiData.containsKey("mowingPattern")) {
dikuai.setMowingPattern(dikuaiData.get("mowingPattern"));
}
- if (dikuaiData.containsKey("mowingWidth")) {
+
+ // 淇濆瓨鍓茶崏瀹藉害锛堜粠鏂囨湰妗嗚幏鍙栵紝鍗曚綅锛氱背锛岃浆鎹负鍘樼背淇濆瓨锛�
+ if (mowingWidthField != null) {
+ String mowingWidthStr = mowingWidthField.getText().trim();
+ if (mowingWidthStr != null && !mowingWidthStr.isEmpty()) {
+ try {
+ double mowingWidthMeters = Double.parseDouble(mowingWidthStr);
+ // 杞崲涓哄帢绫充繚瀛�
+ double mowingWidthCm = mowingWidthMeters * 100.0;
+ dikuai.setMowingWidth(String.format(Locale.US, "%.2f", mowingWidthCm));
+ } catch (NumberFormatException e) {
+ // 濡傛灉瑙f瀽澶辫触锛屽皾璇曚娇鐢╠ikuaiData涓殑鍊�
+ if (dikuaiData.containsKey("mowingWidth")) {
+ dikuai.setMowingWidth(dikuaiData.get("mowingWidth"));
+ }
+ }
+ } else if (dikuaiData.containsKey("mowingWidth")) {
+ dikuai.setMowingWidth(dikuaiData.get("mowingWidth"));
+ }
+ } else if (dikuaiData.containsKey("mowingWidth")) {
dikuai.setMowingWidth(dikuaiData.get("mowingWidth"));
}
+
+ // 淇濆瓨鍓茶崏鏈哄壊鍒�瀹藉害锛堜粠鏂囨湰妗嗚幏鍙栵紝鍗曚綅锛氱背锛�
+ if (bladeWidthField != null) {
+ String bladeWidthStr = bladeWidthField.getText().trim();
+ if (bladeWidthStr != null && !bladeWidthStr.isEmpty()) {
+ try {
+ double bladeWidthMeters = Double.parseDouble(bladeWidthStr);
+ // 淇濆瓨涓虹背锛屼繚鐣�2浣嶅皬鏁�
+ dikuai.setMowingBladeWidth(String.format(Locale.US, "%.2f", bladeWidthMeters));
+ } catch (NumberFormatException e) {
+ // 瑙f瀽澶辫触鏃讹紝淇濆瓨鍘熷瀛楃涓�
+ dikuai.setMowingBladeWidth(bladeWidthStr);
+ }
+ }
+ }
+
+ // 淇濆瓨鍓茶崏瀹夊叏璺濈锛堜粠鏂囨湰妗嗚幏鍙栵紝鍗曚綅锛氱背锛�
+ if (safetyDistanceField != null) {
+ String safetyDistanceStr = safetyDistanceField.getText().trim();
+ if (safetyDistanceStr != null && !safetyDistanceStr.isEmpty()) {
+ try {
+ double safetyDistanceMeters = Double.parseDouble(safetyDistanceStr);
+ // 淇濆瓨涓虹背锛屼繚鐣�2浣嶅皬鏁�
+ String formattedValue = String.format(Locale.US, "%.2f", safetyDistanceMeters);
+ dikuai.setMowingSafetyDistance(formattedValue);
+ // 鍚屾椂淇濆瓨鍒癲ikuaiData涓紝浠ヤ究鍚庣画浣跨敤
+ dikuaiData.put("mowingSafetyDistance", formattedValue);
+ } catch (NumberFormatException e) {
+ // 瑙f瀽澶辫触鏃讹紝淇濆瓨鍘熷瀛楃涓�
+ dikuai.setMowingSafetyDistance(safetyDistanceStr);
+ dikuaiData.put("mowingSafetyDistance", safetyDistanceStr);
+ }
+ } else if (dikuaiData.containsKey("mowingSafetyDistance")) {
+ // 濡傛灉鏂囨湰妗嗕负绌猴紝灏濊瘯浠巇ikuaiData鑾峰彇
+ dikuai.setMowingSafetyDistance(dikuaiData.get("mowingSafetyDistance"));
+ }
+ } else if (dikuaiData.containsKey("mowingSafetyDistance")) {
+ // 濡傛灉safetyDistanceField涓簄ull锛屼粠dikuaiData鑾峰彇
+ dikuai.setMowingSafetyDistance(dikuaiData.get("mowingSafetyDistance"));
+ }
+ // 淇濆瓨鍓茶崏璺緞鍧愭爣
String plannedPath = dikuaiData.get("plannedPath");
if (isMeaningfulValue(plannedPath)) {
dikuai.setPlannedPath(plannedPath);
@@ -2569,6 +3090,13 @@
if (resumeRequested && activeSession != null) {
dialog.applySessionData(activeSession);
resumeRequested = false;
+ // 濡傛灉浼氳瘽宸茬敓鎴愯矾寰勶紝浼樺厛鏄剧ず姝ラ3
+ if (activeSession.data != null && isMeaningfulValue(activeSession.data.get("plannedPath"))) {
+ dialog.showStep(3);
+ } else if (activeSession.drawingCompleted) {
+ // 濡傛灉浼氳瘽宸插畬鎴愮粯鍒讹紝鏄剧ず姝ラ2
+ dialog.showStep(2);
+ }
}
dialog.setVisible(true);
--
Gitblit v1.10.0