From 6700283f9103a45bc087838ebf3eeeeb9022dd98 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 19 十二月 2025 12:11:45 +0800
Subject: [PATCH] 新增了割草机长宽和割草安全距离属性
---
src/set/Sets.java | 281 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 281 insertions(+), 0 deletions(-)
diff --git a/src/set/Sets.java b/src/set/Sets.java
index 9a4d8c2..5b2bafa 100644
--- a/src/set/Sets.java
+++ b/src/set/Sets.java
@@ -1,6 +1,8 @@
package set;
import baseStation.BaseStation;
+import gecaoji.Device;
+import gecaoji.MowerSafetyDistanceCalculator;
import zhuye.MapRenderer;
import zhuye.Shouye;
@@ -32,6 +34,8 @@
// 璁剧疆椤圭粍浠�
private JLabel mowerIdLabel;
+ private JLabel mowerSizeLabel;
+ private JLabel mowingSafetyDistanceLabel;
private JLabel baseStationIdLabel;
private JLabel handheldMarkerLabel;
private JLabel simCardNumberLabel;
@@ -43,6 +47,8 @@
private JLabel measurementModeEnabledLabel;
private JButton mowerIdEditBtn;
+ private JButton mowerSizeEditBtn;
+ private JButton mowingSafetyDistanceEditBtn;
private JButton baseStationIdEditBtn;
private JButton handheldEditBtn;
private JButton checkUpdateBtn;
@@ -123,6 +129,18 @@
mowerIdLabel = (JLabel) mowerIdPanel.getClientProperty("valueLabel");
mowerIdEditBtn = (JButton) mowerIdPanel.getClientProperty("editButton");
+ // 鍓茶崏鏈洪暱瀹�
+ JPanel mowerSizePanel = createSettingItemPanel("鍓茶崏鏈洪暱瀹�",
+ formatMowerSize(), true);
+ mowerSizeLabel = (JLabel) mowerSizePanel.getClientProperty("valueLabel");
+ mowerSizeEditBtn = (JButton) mowerSizePanel.getClientProperty("editButton");
+
+ // 鍓茶崏瀹夊叏璺濈
+ JPanel mowingSafetyDistancePanel = createSettingItemPanel("鍓茶崏瀹夊叏璺濈",
+ formatMowingSafetyDistance(), true);
+ mowingSafetyDistanceLabel = (JLabel) mowingSafetyDistancePanel.getClientProperty("valueLabel");
+ mowingSafetyDistanceEditBtn = (JButton) mowingSafetyDistancePanel.getClientProperty("editButton");
+
JPanel baseStationIdPanel = createSettingItemPanel("宸垎鍩哄噯绔欑紪鍙�",
resolveBaseStationId(), true);
baseStationIdLabel = (JLabel) baseStationIdPanel.getClientProperty("valueLabel");
@@ -167,6 +185,8 @@
// 娣诲姞璁剧疆椤癸紝浣跨敤鍒嗗壊绾垮垎闅�
addSettingItem(panel, mowerIdPanel, true);
+ addSettingItem(panel, mowerSizePanel, true);
+ addSettingItem(panel, mowingSafetyDistancePanel, true);
addSettingItem(panel, baseStationIdPanel, true);
addSettingItem(panel, handheldPanel, true);
addSettingItem(panel, simCardPanel, true);
@@ -205,6 +225,67 @@
return seconds + "绉�";
}
+ /**
+ * 灏嗗瓧绗︿覆鍊艰浆鎹负绫筹紙鍏煎鏃ф暟鎹紝濡傛灉鍊煎ぇ浜�100璁や负鏄帢绫筹紝闇�瑕侀櫎浠�100锛�
+ */
+ private double convertToMeters(String value) {
+ if (value == null || value.trim().isEmpty() || "-1".equals(value.trim())) {
+ return -1;
+ }
+ try {
+ double val = Double.parseDouble(value.trim());
+ // 濡傛灉鍊煎ぇ浜�100锛岃涓烘槸鍘樼背锛岄渶瑕佽浆鎹负绫�
+ if (val > 100) {
+ return val / 100.0;
+ }
+ return val;
+ } catch (NumberFormatException e) {
+ return -1;
+ }
+ }
+
+ /**
+ * 鏍煎紡鍖栨暟鍊间负绫筹紝淇濈暀2浣嶅皬鏁�
+ */
+ private String formatMeters(double value) {
+ if (value < 0) {
+ return "鏈缃�";
+ }
+ return String.format("%.2f", value) + "m";
+ }
+
+ private String formatMowerSize() {
+ Device device = Device.getActiveDevice();
+ if (device == null) {
+ return "鏈缃�";
+ }
+ String width = device.getMowerWidth();
+ String length = device.getMowerLength();
+ double widthMeters = convertToMeters(width);
+ double lengthMeters = convertToMeters(length);
+
+ if (widthMeters < 0 && lengthMeters < 0) {
+ return "鏈缃�";
+ }
+
+ String widthStr = widthMeters >= 0 ? formatMeters(widthMeters) : "鏈缃�";
+ String lengthStr = lengthMeters >= 0 ? formatMeters(lengthMeters) : "鏈缃�";
+ return lengthStr + " 脳 " + widthStr;
+ }
+
+ private String formatMowingSafetyDistance() {
+ Device device = Device.getActiveDevice();
+ if (device == null) {
+ return "鏈缃�";
+ }
+ String distance = device.getMowingSafetyDistance();
+ double distanceMeters = convertToMeters(distance);
+ if (distanceMeters < 0) {
+ return "鏈缃�";
+ }
+ return formatMeters(distanceMeters);
+ }
+
private JPanel createSettingItemPanel(String title, String value, boolean editable) {
JPanel panel = new JPanel(new GridBagLayout());
@@ -620,6 +701,11 @@
// 浠嶴etsys绫诲姞杞芥暟鎹�
setData.initializeFromProperties();
baseStation.load();
+ // 浠巇evice.properties鍔犺浇璁惧鏁版嵁
+ Device device = Device.getActiveDevice();
+ if (device != null) {
+ device.initFromProperties();
+ }
updateDisplay();
// 鍔犺浇骞跺簲鐢ㄤ笂娆′繚瀛樼殑瑙嗗浘涓績鍧愭爣
loadViewCenterFromProperties();
@@ -671,6 +757,16 @@
mowerIdLabel.setText(setData.getMowerId() != null ? setData.getMowerId() : "鏈缃�");
}
+ // 鏇存柊鍓茶崏鏈洪暱瀹芥樉绀�
+ if (mowerSizeLabel != null) {
+ mowerSizeLabel.setText(formatMowerSize());
+ }
+
+ // 鏇存柊鍓茶崏瀹夊叏璺濈鏄剧ず
+ if (mowingSafetyDistanceLabel != null) {
+ mowingSafetyDistanceLabel.setText(formatMowingSafetyDistance());
+ }
+
if (baseStationIdLabel != null) {
baseStationIdLabel.setText(resolveBaseStationId());
}
@@ -768,6 +864,16 @@
mowerIdEditBtn.addActionListener(e -> editMowerId());
}
+ // 鍓茶崏鏈洪暱瀹界紪杈戞寜閽簨浠�
+ if (mowerSizeEditBtn != null) {
+ mowerSizeEditBtn.addActionListener(e -> editMowerSize());
+ }
+
+ // 鍓茶崏瀹夊叏璺濈缂栬緫鎸夐挳浜嬩欢
+ if (mowingSafetyDistanceEditBtn != null) {
+ mowingSafetyDistanceEditBtn.addActionListener(e -> editMowingSafetyDistance());
+ }
+
if (baseStationIdEditBtn != null) {
baseStationIdEditBtn.addActionListener(e -> editBaseStationId());
}
@@ -816,6 +922,181 @@
}
}
+ private void editMowerSize() {
+ Device device = Device.getActiveDevice();
+ if (device == null) {
+ JOptionPane.showMessageDialog(this, "璁惧鏈垵濮嬪寲", "閿欒", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ // 鑾峰彇褰撳墠鍊煎苟杞崲涓虹背锛堝吋瀹规棫鏁版嵁锛�
+ double currentLengthMeters = convertToMeters(device.getMowerLength());
+ double currentWidthMeters = convertToMeters(device.getMowerWidth());
+
+ String currentLengthStr = currentLengthMeters >= 0 ? String.format("%.2f", currentLengthMeters) : "";
+ String currentWidthStr = currentWidthMeters >= 0 ? String.format("%.2f", currentWidthMeters) : "";
+
+ // 鍒涘缓杈撳叆瀵硅瘽妗�
+ JPanel inputPanel = new JPanel(new GridLayout(2, 2, 5, 5));
+ inputPanel.add(new JLabel("闀垮害(m):"));
+ JTextField lengthField = new JTextField(currentLengthStr);
+ inputPanel.add(lengthField);
+ inputPanel.add(new JLabel("瀹藉害(m):"));
+ JTextField widthField = new JTextField(currentWidthStr);
+ inputPanel.add(widthField);
+
+ int result = JOptionPane.showConfirmDialog(this,
+ inputPanel,
+ "淇敼鍓茶崏鏈洪暱瀹�",
+ JOptionPane.OK_CANCEL_OPTION,
+ JOptionPane.QUESTION_MESSAGE);
+
+ if (result == JOptionPane.OK_OPTION) {
+ String newLength = lengthField.getText().trim();
+ String newWidth = widthField.getText().trim();
+
+ // 楠岃瘉杈撳叆
+ if (newLength.isEmpty() && newWidth.isEmpty()) {
+ JOptionPane.showMessageDialog(this, "闀垮害鍜屽搴︿笉鑳藉悓鏃朵负绌�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+
+ double lengthValue = -1;
+ double widthValue = -1;
+
+ if (!newLength.isEmpty()) {
+ try {
+ lengthValue = Double.parseDouble(newLength);
+ if (lengthValue < 0) {
+ JOptionPane.showMessageDialog(this, "闀垮害蹇呴』澶т簬绛変簬0", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+ } catch (NumberFormatException e) {
+ JOptionPane.showMessageDialog(this, "闀垮害蹇呴』鏄湁鏁堢殑鏁板瓧", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+ }
+
+ if (!newWidth.isEmpty()) {
+ try {
+ widthValue = Double.parseDouble(newWidth);
+ if (widthValue < 0) {
+ JOptionPane.showMessageDialog(this, "瀹藉害蹇呴』澶т簬绛変簬0", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+ } catch (NumberFormatException e) {
+ JOptionPane.showMessageDialog(this, "瀹藉害蹇呴』鏄湁鏁堢殑鏁板瓧", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+ }
+
+ // 鏇存柊璁惧灞炴�э紙淇濆瓨涓虹背锛屼繚鐣�2浣嶅皬鏁帮級
+ if (lengthValue >= 0) {
+ String lengthStr = String.format("%.2f", lengthValue);
+ device.setMowerLength(lengthStr);
+ device.updateField("mowerLength", lengthStr);
+ } else {
+ device.setMowerLength("-1");
+ device.updateField("mowerLength", "-1");
+ }
+
+ if (widthValue >= 0) {
+ String widthStr = String.format("%.2f", widthValue);
+ device.setMowerWidth(widthStr);
+ device.updateField("mowerWidth", widthStr);
+ } else {
+ device.setMowerWidth("-1");
+ device.updateField("mowerWidth", "-1");
+ }
+
+ // 濡傛灉闀垮害鍜屽搴﹂兘鏈夋晥锛岃嚜鍔ㄨ绠楀畨鍏ㄨ窛绂�
+ if (lengthValue > 0 && widthValue > 0) {
+ try {
+ double safetyDistance = MowerSafetyDistanceCalculator.calculateSafetyDistance(lengthValue, widthValue);
+ String safetyDistanceStr = String.format("%.2f", safetyDistance);
+ device.setMowingSafetyDistance(safetyDistanceStr);
+ device.updateField("mowingSafetyDistance", safetyDistanceStr);
+
+ // 鏇存柊瀹夊叏璺濈鏄剧ず
+ if (mowingSafetyDistanceLabel != null) {
+ mowingSafetyDistanceLabel.setText(formatMowingSafetyDistance());
+ }
+ } catch (IllegalArgumentException e) {
+ // 濡傛灉璁$畻澶辫触锛屼笉鏇存柊瀹夊叏璺濈
+ System.err.println("璁$畻瀹夊叏璺濈澶辫触: " + e.getMessage());
+ }
+ }
+
+ // 淇濆瓨鍒癲evice.properties
+ device.saveToProperties();
+
+ // 鏇存柊鏄剧ず
+ if (mowerSizeLabel != null) {
+ mowerSizeLabel.setText(formatMowerSize());
+ }
+ JOptionPane.showMessageDialog(this, "鍓茶崏鏈洪暱瀹芥洿鏂版垚鍔�" +
+ (lengthValue > 0 && widthValue > 0 ? "锛屽畨鍏ㄨ窛绂诲凡鑷姩璁$畻" : ""),
+ "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+ }
+ }
+
+ private void editMowingSafetyDistance() {
+ Device device = Device.getActiveDevice();
+ if (device == null) {
+ JOptionPane.showMessageDialog(this, "璁惧鏈垵濮嬪寲", "閿欒", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ // 鑾峰彇褰撳墠鍊煎苟杞崲涓虹背锛堝吋瀹规棫鏁版嵁锛�
+ double currentDistanceMeters = convertToMeters(device.getMowingSafetyDistance());
+ String currentValueStr = currentDistanceMeters >= 0 ? String.format("%.2f", currentDistanceMeters) : "";
+
+ String newValue = (String) JOptionPane.showInputDialog(this,
+ "璇疯緭鍏ュ壊鑽夊畨鍏ㄨ窛绂�(鍗曚綅:m):",
+ "淇敼鍓茶崏瀹夊叏璺濈",
+ JOptionPane.QUESTION_MESSAGE,
+ null,
+ null,
+ currentValueStr);
+
+ if (newValue == null) {
+ return; // 鐢ㄦ埛鍙栨秷
+ }
+
+ newValue = newValue.trim();
+ if (newValue.isEmpty()) {
+ JOptionPane.showMessageDialog(this, "鍓茶崏瀹夊叏璺濈涓嶈兘涓虹┖", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+
+ // 楠岃瘉杈撳叆
+ double distanceValue;
+ try {
+ distanceValue = Double.parseDouble(newValue);
+ if (distanceValue < 0) {
+ JOptionPane.showMessageDialog(this, "鍓茶崏瀹夊叏璺濈蹇呴』澶т簬绛変簬0", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+ } catch (NumberFormatException e) {
+ JOptionPane.showMessageDialog(this, "鍓茶崏瀹夊叏璺濈蹇呴』鏄湁鏁堢殑鏁板瓧", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+
+ // 鏇存柊璁惧灞炴�э紙淇濆瓨涓虹背锛屼繚鐣�2浣嶅皬鏁帮級
+ String distanceStr = String.format("%.2f", distanceValue);
+ device.setMowingSafetyDistance(distanceStr);
+ device.updateField("mowingSafetyDistance", distanceStr);
+
+ // 淇濆瓨鍒癲evice.properties
+ device.saveToProperties();
+
+ // 鏇存柊鏄剧ず
+ if (mowingSafetyDistanceLabel != null) {
+ mowingSafetyDistanceLabel.setText(formatMowingSafetyDistance());
+ }
+ JOptionPane.showMessageDialog(this, "鍓茶崏瀹夊叏璺濈鏇存柊鎴愬姛", "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+ }
+
private void editHandheldMarkerId() {
String currentValue = setData.getHandheldMarkerId() != null ? setData.getHandheldMarkerId() : "";
String newValue = (String) JOptionPane.showInputDialog(this,
--
Gitblit v1.10.0