From ed6936545d20cc490145d2936cee4387be2afd53 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期一, 22 十二月 2025 19:04:34 +0800
Subject: [PATCH] 优化了导航预览模式
---
src/zhuye/MapRenderer.java | 605 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 588 insertions(+), 17 deletions(-)
diff --git a/src/zhuye/MapRenderer.java b/src/zhuye/MapRenderer.java
index b83f3c8..1eb0bd2 100644
--- a/src/zhuye/MapRenderer.java
+++ b/src/zhuye/MapRenderer.java
@@ -31,6 +31,7 @@
import zhangaiwu.Obstacledge;
import zhangaiwu.yulanzhangaiwu;
import yaokong.Control03;
+import bianjie.shudongdraw;
/**
* 鍦板浘娓叉煋鍣� - 璐熻矗鍧愭爣绯荤粯鍒躲�佽鍥惧彉鎹㈢瓑鍔熻兘
@@ -74,6 +75,7 @@
private String boundaryName;
private boolean boundaryPointsVisible;
private boolean obstaclePointsVisible;
+ private boolean boundaryLengthVisible = false; // 鏄惁鏄剧ず杈圭晫璺濈锛岄粯璁ゅ叧闂�
private double boundaryPointSizeScale = 1.0d;
private boolean previewSizingEnabled;
private String currentBoundaryLandNumber;
@@ -84,6 +86,7 @@
private CircleCaptureOverlay circleCaptureOverlay;
private final List<double[]> circleSampleMarkers = new ArrayList<>();
private final List<Point2D.Double> realtimeMowingTrack = new ArrayList<>();
+ private final List<Point2D.Double> navigationPreviewTrack = new ArrayList<>(); // 瀵艰埅棰勮杞ㄨ抗
private final Deque<tuowei.TrailSample> idleMowerTrail = new ArrayDeque<>();
private final List<Point2D.Double> handheldBoundaryPreview = new ArrayList<>();
private double boundaryPreviewMarkerScale = 1.0d;
@@ -97,11 +100,19 @@
private double mowingCompletionRatio;
private long lastTrackPersistTimeMillis;
private boolean trackDirty;
+ private boolean measurementModeActive = false; // 娴嬮噺妯″紡鏄惁婵�娲�
private boolean handheldBoundaryPreviewActive;
private boolean pendingTrackBreak = true;
+ private bianjie.shudongdraw manualBoundaryDrawer = new bianjie.shudongdraw(); // 鎵嬪姩缁樺埗杈圭晫缁樺埗鍣�
private boolean idleTrailSuppressed;
private Path2D.Double realtimeBoundaryPathCache;
private String realtimeBoundaryPathLand;
+ private WangfanDraw returnPathDrawer; // 寰�杩旇矾寰勭粯鍒剁鐞嗗櫒
+ private List<Point2D.Double> currentReturnPath; // 褰撳墠鍦板潡鐨勫線杩旇矾寰勶紙鐢ㄤ簬鏄剧ず锛�
+ private List<Point2D.Double> previewReturnPath; // 棰勮鐨勫線杩旇矾寰�
+ private List<Point2D.Double> previewOriginalBoundary; // 棰勮鐨勫師濮嬭竟鐣岋紙绱壊锛�
+ private List<Point2D.Double> previewOptimizedBoundary; // 棰勮鐨勪紭鍖栧悗杈圭晫
+ private boolean boundaryPreviewActive; // 鏄惁澶勪簬杈圭晫棰勮妯″紡
private static final double TRACK_SAMPLE_MIN_DISTANCE_METERS = 0.2d;
private static final double TRACK_DUPLICATE_TOLERANCE_METERS = 1e-3d;
@@ -204,6 +215,14 @@
lastDragPoint = null;
dragInProgress = false;
}
+
+ public void mouseExited(MouseEvent e) {
+ // 榧犳爣绂诲紑闈㈡澘鏃讹紝娓呴櫎榧犳爣浣嶇疆鏄剧ず
+ if (manualBoundaryDrawer.isManualBoundaryDrawingMode()) {
+ manualBoundaryDrawer.clearMousePosition();
+ visualizationPanel.repaint();
+ }
+ }
public void mouseClicked(MouseEvent e) {
if (dragInProgress) {
@@ -213,6 +232,18 @@
if (!SwingUtilities.isLeftMouseButton(e) || e.getClickCount() != 1) {
return;
}
+ // 浼樺厛澶勭悊鎵嬪姩缁樺埗杈圭晫妯″紡鐐瑰嚮
+ if (manualBoundaryDrawer.isManualBoundaryDrawingMode()) {
+ Point2D.Double worldPoint = screenToWorld(e.getPoint());
+ if (manualBoundaryDrawer.handleClick(worldPoint)) {
+ visualizationPanel.repaint();
+ return;
+ }
+ }
+ // 浼樺厛澶勭悊娴嬮噺妯″紡鐐瑰嚮
+ if (measurementModeActive && handleMeasurementClick(e.getPoint())) {
+ return;
+ }
if (handleMowerClick(e.getPoint())) {
return;
}
@@ -241,6 +272,17 @@
visualizationPanel.repaint();
}
}
+
+ public void mouseMoved(MouseEvent e) {
+ // 鍦ㄦ墜鍔ㄧ粯鍒惰竟鐣屾ā寮忔椂锛屾洿鏂伴紶鏍囦綅缃�
+ if (manualBoundaryDrawer.isManualBoundaryDrawingMode()) {
+ Point2D.Double worldPoint = screenToWorld(e.getPoint());
+ manualBoundaryDrawer.updateMousePosition(worldPoint);
+ visualizationPanel.repaint();
+ } else {
+ manualBoundaryDrawer.clearMousePosition();
+ }
+ }
});
}
@@ -358,6 +400,11 @@
if (hasBoundary) {
drawCurrentBoundary(g2d);
}
+
+ // 缁樺埗杈圭晫棰勮锛堝師濮嬭竟鐣�-绱壊锛屼紭鍖栧悗杈圭晫锛�
+ if (boundaryPreviewActive) {
+ drawBoundaryPreview(g2d);
+ }
yulanzhangaiwu.renderPreview(g2d, scale);
@@ -371,6 +418,12 @@
adddikuaiyulan.drawPreview(g2d, handheldBoundaryPreview, scale, handheldBoundaryPreviewActive, boundaryPreviewMarkerScale);
+ // 缁樺埗鎵嬪姩缁樺埗鐨勮竟鐣�
+ manualBoundaryDrawer.drawBoundary(g2d, scale);
+
+ // 缁樺埗榧犳爣瀹炴椂浣嶇疆锛堟墜鍔ㄧ粯鍒惰竟鐣屾ā寮忔椂锛�
+ manualBoundaryDrawer.drawMousePosition(g2d, scale);
+
// 缁樺埗瀵艰埅璺緞锛堜腑灞傦級
if (hasPlannedPath) {
drawCurrentPlannedPath(g2d);
@@ -381,7 +434,8 @@
Obstacledraw.drawObstacles(g2d, currentObstacles, scale, selectedObstacleName);
}
- if (boundaryPointsVisible && hasBoundary) {
+ // 鏄剧ず杈圭晫鐐癸紙濡傛灉杈圭晫鐐瑰彲瑙侊紝鎴栬�呰竟鐣岃窛绂诲彲瑙侊級
+ if ((boundaryPointsVisible || boundaryLengthVisible) && hasBoundary) {
// 棰勮妯″紡涓嬫樉绀哄簭鍙�
if (previewSizingEnabled) {
drawBoundaryPointsWithNumbers(g2d, currentBoundary, scale);
@@ -397,7 +451,7 @@
);
}
}
-
+
// 缁樺埗闅滅鐗╁潗鏍囩偣锛堝甫搴忓彿锛�
if (obstaclePointsVisible && hasObstacles) {
drawObstaclePointsWithNumbers(g2d, currentObstacles, scale);
@@ -410,12 +464,47 @@
if (!realtimeMowingTrack.isEmpty()) {
drawRealtimeMowingCoverage(g2d);
}
+
+ // 缁樺埗瀵艰埅棰勮宸插壊鍖哄煙
+ if (!navigationPreviewTrack.isEmpty()) {
+ drawNavigationPreviewCoverage(g2d);
+ }
+
+ // 鍏堢敾寰�杩旇矾寰勶紙绾�+鐐癸級锛屼繚璇佸壊鑽夋満鍥炬爣鍦ㄥ叾涓婃柟
+ if (returnPathDrawer != null && returnPathDrawer.isActive()) {
+ returnPathDrawer.draw(g2d, scale);
+ } else if (previewReturnPath != null && !previewReturnPath.isEmpty()) {
+ // 缁樺埗棰勮鐨勫線杩旇矾寰勶紙閾佺嚎璺浘椋庢牸锛�
+ WangfanDraw.drawRailwayPath(g2d, previewReturnPath, scale);
+ } else if (currentReturnPath != null && !currentReturnPath.isEmpty()) {
+ // 缁樺埗淇濆瓨鐨勫線杩旇矾寰勶紙閾佺嚎璺浘椋庢牸锛�
+ WangfanDraw.drawRailwayPath(g2d, currentReturnPath, scale);
+ }
drawMower(g2d);
+ // 缁樺埗瀵艰埅棰勮閫熷害锛堝鏋滄鍦ㄥ鑸瑙堬級
+ if (navigationPreviewSpeed > 0 && mower != null && mower.hasValidPosition()) {
+ drawNavigationPreviewSpeed(g2d, scale);
+ }
+
+ // 缁樺埗娴嬮噺妯″紡锛堝鏋滄縺娲伙級
+ if (measurementModeActive) {
+ drawMeasurementMode(g2d, scale);
+ }
+
+ // 淇濆瓨褰撳墠鍙樻崲锛堝寘鍚鍥惧彉鎹級鐢ㄤ簬鍧愭爣杞崲
+ AffineTransform currentTransformForLength = g2d.getTransform();
+
// 鎭㈠鍘熷鍙樻崲
g2d.setTransform(originalTransform);
+ // 缁樺埗杈圭晫闀垮害锛堝鏋滃惎鐢級- 鍦ㄦ仮澶嶅師濮嬪彉鎹㈠悗缁樺埗
+ if (boundaryLengthVisible && hasBoundary) {
+ bianjie.BoundaryLengthDrawer.drawBoundaryLengths(g2d, currentBoundary, scale,
+ visualizationPanel.getWidth(), visualizationPanel.getHeight(), translateX, translateY);
+ }
+
// 缁樺埗瑙嗗浘淇℃伅
drawViewInfo(g2d);
}
@@ -437,6 +526,60 @@
private void drawMower(Graphics2D g2d) {
mower.draw(g2d, scale);
}
+
+ /**
+ * 缁樺埗瀵艰埅棰勮閫熷害锛堝湪鍓茶崏鏈哄浘鏍囦笂鏂癸級
+ */
+ private void drawNavigationPreviewSpeed(Graphics2D g2d, double scale) {
+ if (mower == null || !mower.hasValidPosition()) {
+ return;
+ }
+
+ Point2D.Double mowerPos = mower.getPosition();
+ if (mowerPos == null) {
+ return;
+ }
+
+ // 灏嗛�熷害浠庣背/绉掕浆鎹负KM/h
+ double speedKmh = navigationPreviewSpeed * 3.6;
+ String speedText = String.format("%.1f km/h", speedKmh);
+
+ // 淇濆瓨鍘熷鍙樻崲
+ AffineTransform originalTransform = g2d.getTransform();
+
+ // 灏嗕笘鐣屽潗鏍囪浆鎹负灞忓箷鍧愭爣
+ Point2D.Double screenPos = worldToScreen(mowerPos);
+
+ // 鎭㈠鍘熷鍙樻崲浠ョ粯鍒舵枃瀛楋紙鍥哄畾澶у皬锛屼笉闅忕缉鏀惧彉鍖栵級
+ g2d.setTransform(new AffineTransform());
+
+ // 璁剧疆瀛椾綋锛堜笌缂╂斁鏂囧瓧澶у皬涓�鑷达紝11鍙峰瓧浣擄級
+ Font labelFont = new Font("寰蒋闆呴粦", Font.PLAIN, 11);
+ g2d.setFont(labelFont);
+ FontMetrics metrics = g2d.getFontMetrics(labelFont);
+
+ // 璁$畻鏂囧瓧浣嶇疆锛堝湪鍓茶崏鏈哄浘鏍囦笂鏂癸級
+ int textWidth = metrics.stringWidth(speedText);
+ int textHeight = metrics.getHeight();
+ int textX = (int)Math.round(screenPos.x - textWidth / 2.0);
+ // 鍦ㄥ壊鑽夋満鍥炬爣涓婃柟锛岀暀鍑轰竴瀹氶棿璺�
+ // 鍥炬爣鍦ㄤ笘鐣屽潗鏍囩郴涓殑澶у皬绾︿负 48 * 0.8 / scale 绫�
+ // 杞崲涓哄睆骞曞儚绱狅細鍥炬爣楂樺害锛堝儚绱狅級= (48 * 0.8 / scale) * scale = 48 * 0.8 = 38.4 鍍忕礌
+ double iconSizePixels = 48.0 * 0.8; // 鍥炬爣鍦ㄥ睆骞曚笂鐨勫ぇ灏忥紙鍍忕礌锛�
+ int spacing = 8; // 闂磋窛锛堝儚绱狅級
+ int textY = (int)Math.round(screenPos.y - iconSizePixels / 2.0 - spacing - textHeight);
+
+ // 缁樺埗鏂囧瓧鑳屾櫙锛堝崐閫忔槑鐧借壊锛屽寮哄彲璇绘�э級
+ g2d.setColor(new Color(255, 255, 255, 200));
+ g2d.fillRoundRect(textX - 4, textY - metrics.getAscent() - 2, textWidth + 8, textHeight + 4, 4, 4);
+
+ // 缁樺埗鏂囧瓧
+ g2d.setColor(new Color(46, 139, 87)); // 浣跨敤涓婚缁胯壊
+ g2d.drawString(speedText, textX, textY);
+
+ // 鎭㈠鍙樻崲
+ g2d.setTransform(originalTransform);
+ }
private void drawRealtimeMowingCoverage(Graphics2D g2d) {
if (realtimeMowingTrack == null || realtimeMowingTrack.size() < 2) {
@@ -447,6 +590,91 @@
double effectiveWidth = getEffectiveMowerWidthMeters();
gecaolunjing.draw(g2d, realtimeMowingTrack, effectiveWidth, boundaryPath);
}
+
+ /**
+ * 缁樺埗瀵艰埅棰勮宸插壊鍖哄煙
+ */
+ private void drawNavigationPreviewCoverage(Graphics2D g2d) {
+ if (navigationPreviewTrack == null || navigationPreviewTrack.size() < 2) {
+ return;
+ }
+
+ Path2D.Double boundaryPath = currentBoundaryPath;
+ // 鑾峰彇瀵艰埅棰勮鐨勫壊鑽夊搴︼紙浠巇aohangyulan鑾峰彇锛�
+ double previewWidth = getNavigationPreviewWidth();
+ if (previewWidth <= 0) {
+ previewWidth = 0.5; // 榛樿50鍘樼背
+ }
+ gecaolunjing.draw(g2d, navigationPreviewTrack, previewWidth, boundaryPath);
+ }
+
+ /**
+ * 璁剧疆瀵艰埅棰勮杞ㄨ抗
+ */
+ public void setNavigationPreviewTrack(List<Point2D.Double> track) {
+ if (track == null) {
+ navigationPreviewTrack.clear();
+ } else {
+ navigationPreviewTrack.clear();
+ navigationPreviewTrack.addAll(track);
+ }
+ if (visualizationPanel != null) {
+ visualizationPanel.repaint();
+ }
+ }
+
+ /**
+ * 娣诲姞瀵艰埅棰勮杞ㄨ抗鐐�
+ */
+ public void addNavigationPreviewTrackPoint(Point2D.Double point) {
+ if (point != null && Double.isFinite(point.x) && Double.isFinite(point.y)) {
+ navigationPreviewTrack.add(new Point2D.Double(point.x, point.y));
+ if (visualizationPanel != null) {
+ visualizationPanel.repaint();
+ }
+ }
+ }
+
+ /**
+ * 娓呴櫎瀵艰埅棰勮杞ㄨ抗
+ */
+ public void clearNavigationPreviewTrack() {
+ navigationPreviewTrack.clear();
+ if (visualizationPanel != null) {
+ visualizationPanel.repaint();
+ }
+ }
+
+ private double navigationPreviewWidth = 0.5; // 瀵艰埅棰勮鐨勫壊鑽夊搴︼紙绫筹級
+ private double navigationPreviewSpeed = 0.0; // 瀵艰埅棰勮鐨勫壊鑽夋満閫熷害锛堢背/绉掞級
+
+ /**
+ * 璁剧疆瀵艰埅棰勮鐨勫壊鑽夊搴�
+ */
+ public void setNavigationPreviewWidth(double widthMeters) {
+ navigationPreviewWidth = widthMeters > 0 ? widthMeters : 0.5;
+ }
+
+ /**
+ * 鑾峰彇瀵艰埅棰勮鐨勫壊鑽夊搴�
+ */
+ private double getNavigationPreviewWidth() {
+ return navigationPreviewWidth;
+ }
+
+ /**
+ * 璁剧疆瀵艰埅棰勮鐨勫壊鑽夋満閫熷害锛堢背/绉掞級
+ */
+ public void setNavigationPreviewSpeed(double speedMetersPerSecond) {
+ navigationPreviewSpeed = speedMetersPerSecond >= 0 ? speedMetersPerSecond : 0.0;
+ }
+
+ /**
+ * 鑾峰彇瀵艰埅棰勮鐨勫壊鑽夋満閫熷害锛堢背/绉掞級
+ */
+ private double getNavigationPreviewSpeed() {
+ return navigationPreviewSpeed;
+ }
private Path2D.Double getRealtimeBoundaryPath() {
if (realtimeTrackLandNumber == null) {
@@ -756,6 +984,14 @@
mowerEffectiveWidthMeters = defaultMowerWidthMeters;
}
+ // 鍔犺浇寰�杩旇矾寰�
+ String returnPathStr = dikuai != null ? dikuai.getReturnPathCoordinates() : null;
+ if (returnPathStr != null && !returnPathStr.isEmpty() && !"-1".equals(returnPathStr)) {
+ currentReturnPath = lujingdraw.parsePlannedPath(returnPathStr);
+ } else {
+ currentReturnPath = null;
+ }
+
loadRealtimeTrack(landNumber, dikuai != null ? dikuai.getMowingTrack() : null);
visualizationPanel.repaint();
}
@@ -1037,6 +1273,172 @@
double worldY = (screenPoint.y - visualizationPanel.getHeight() / 2.0) / scale - translateY;
return new Point2D.Double(worldX, worldY);
}
+
+ /**
+ * 澶勭悊娴嬮噺妯″紡鐐瑰嚮
+ */
+ private boolean handleMeasurementClick(Point screenPoint) {
+ if (!measurementModeActive) {
+ return false;
+ }
+ Point2D.Double worldPoint = screenToWorld(screenPoint);
+ celiangmoshi.addPoint(worldPoint);
+ visualizationPanel.repaint();
+ return true;
+ }
+
+ /**
+ * 璁剧疆鎵嬪姩缁樺埗杈圭晫妯″紡
+ */
+ public void setManualBoundaryDrawingMode(boolean active) {
+ manualBoundaryDrawer.setManualBoundaryDrawingMode(active);
+ if (visualizationPanel != null) {
+ visualizationPanel.repaint();
+ }
+ }
+
+ /**
+ * 鑾峰彇鎵嬪姩缁樺埗鐨勮竟鐣岀偣鍒楄〃
+ */
+ public List<Point2D.Double> getManualBoundaryPoints() {
+ return manualBoundaryDrawer.getManualBoundaryPoints();
+ }
+
+ /**
+ * 娓呯┖鎵嬪姩缁樺埗鐨勮竟鐣岀偣
+ */
+ public void clearManualBoundaryPoints() {
+ manualBoundaryDrawer.clearManualBoundaryPoints();
+ if (visualizationPanel != null) {
+ visualizationPanel.repaint();
+ }
+ }
+
+ /**
+ * 璁剧疆娴嬮噺妯″紡
+ */
+ public void setMeasurementMode(boolean active) {
+ measurementModeActive = active;
+ if (!active) {
+ celiangmoshi.clear();
+ }
+ if (visualizationPanel != null) {
+ visualizationPanel.repaint();
+ }
+ }
+
+ /**
+ * 瑙﹀彂鍦板浘閲嶇粯
+ */
+ public void repaint() {
+ if (visualizationPanel != null) {
+ visualizationPanel.repaint();
+ }
+ }
+
+ /**
+ * 缁樺埗娴嬮噺妯″紡
+ */
+ private void drawMeasurementMode(Graphics2D g2d, double scale) {
+ List<Point2D.Double> points = celiangmoshi.getPoints();
+ if (points.isEmpty()) {
+ return;
+ }
+
+ // 淇濆瓨鍘熷鍙樻崲
+ AffineTransform originalTransform = g2d.getTransform();
+
+ // 璁剧疆娴嬮噺妯″紡棰滆壊
+ Color lineColor = new Color(255, 0, 0, 200); // 绾㈣壊鍗婇�忔槑
+ Color pointColor = new Color(255, 0, 0, 255); // 绾㈣壊
+ Color textColor = new Color(33, 37, 41, 220); // 娣辩伆鑹叉枃瀛�
+
+ // 璁剧疆绾垮鍜岀偣鐨勫ぇ灏忥紙纭繚鐐瑰拰绾胯繛鎺ワ級
+ float lineWidth = (float)(2.0 / scale);
+ // 鐐圭殑澶у皬锛堝湪涓栫晫鍧愭爣绯讳腑锛岀背锛夛紝纭繚鐐硅冻澶熷ぇ浠ヨ鐩栫嚎鐨勭鐐�
+ double pointSizeInWorld = 0.15d; // 鐐圭殑澶у皬锛堢背锛�
+ double halfSize = pointSizeInWorld / 2.0;
+
+ // 鍏堢粯鍒舵墍鏈夋祴閲忕偣锛堜綔涓哄熀纭�灞傦級
+ g2d.setColor(pointColor);
+ for (Point2D.Double point : points) {
+ // 鐐圭殑涓績鍦� point.x, point.y
+ Ellipse2D.Double pointShape = new Ellipse2D.Double(
+ point.x - halfSize,
+ point.y - halfSize,
+ pointSizeInWorld,
+ pointSizeInWorld
+ );
+ g2d.fill(pointShape);
+ }
+
+ // 鐒跺悗缁樺埗杩炵嚎锛岀‘淇濈嚎浠庣偣鐨勪腑蹇冨紑濮嬪拰缁撴潫锛岀偣鍜岀嚎杩炴帴鍦ㄤ竴璧�
+ g2d.setColor(lineColor);
+ g2d.setStroke(new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+
+ // 缁樺埗杩炵嚎鍜岃窛绂绘枃瀛楋紙鏄剧ず涓や釜鐩搁偦鐐硅繛绾跨殑闀垮害锛�
+ for (int i = 0; i < points.size() - 1; i++) {
+ Point2D.Double p1 = points.get(i);
+ Point2D.Double p2 = points.get(i + 1);
+
+ // 缁樺埗杩炵嚎锛堜粠绗竴涓偣鐨勪腑蹇冨埌绗簩涓偣鐨勪腑蹇冿級
+ // 浣跨敤 Path2D 纭繚绮剧‘缁樺埗锛屼繚鎸佹诞鐐圭簿搴�
+ Path2D.Double linePath = new Path2D.Double();
+ linePath.moveTo(p1.x, p1.y);
+ linePath.lineTo(p2.x, p2.y);
+ g2d.draw(linePath);
+
+ // 璁$畻璺濈锛堜袱涓浉閭荤偣杩炵嚎鐨勯暱搴︼級
+ double distance = celiangmoshi.calculateDistance(p1, p2);
+ String distanceText = celiangmoshi.formatDistance(distance);
+
+ // 璁$畻涓偣浣嶇疆锛堢敤浜庢樉绀烘枃瀛楋級
+ double midX = (p1.x + p2.x) / 2.0;
+ double midY = (p1.y + p2.y) / 2.0;
+
+ // 灏嗕笘鐣屽潗鏍囪浆鎹负灞忓箷鍧愭爣锛堢敤浜庢枃瀛楁樉绀猴級
+ Point2D.Double worldMid = new Point2D.Double(midX, midY);
+ Point2D.Double screenMid = worldToScreen(worldMid);
+
+ // 鎭㈠鍘熷鍙樻崲浠ョ粯鍒舵枃瀛楋紙鍥哄畾澶у皬锛屼笉闅忕缉鏀惧彉鍖栵級
+ g2d.setTransform(new AffineTransform());
+
+ // 璁剧疆瀛椾綋锛堜笌缂╂斁鏂囧瓧澶у皬涓�鑷达紝11鍙峰瓧浣擄級
+ Font labelFont = new Font("寰蒋闆呴粦", Font.PLAIN, 11);
+ g2d.setFont(labelFont);
+ FontMetrics metrics = g2d.getFontMetrics(labelFont);
+
+ // 璁$畻鏂囧瓧浣嶇疆锛堝眳涓樉绀猴級
+ int textWidth = metrics.stringWidth(distanceText);
+ int textHeight = metrics.getHeight();
+ int textX = (int)Math.round(screenMid.x - textWidth / 2.0);
+ int textY = (int)Math.round(screenMid.y - textHeight / 2.0) + metrics.getAscent();
+
+ // 缁樺埗鏂囧瓧鑳屾櫙锛堝彲閫夛紝鐢ㄤ簬鎻愰珮鍙鎬э級
+ g2d.setColor(new Color(255, 255, 255, 200));
+ g2d.fillRoundRect(textX - 2, textY - metrics.getAscent() - 2, textWidth + 4, textHeight + 4, 4, 4);
+
+ // 缁樺埗鏂囧瓧
+ g2d.setColor(textColor);
+ g2d.drawString(distanceText, textX, textY);
+
+ // 鎭㈠鍙樻崲
+ g2d.setTransform(originalTransform);
+ }
+
+ // 鏈�鍚庡啀娆$粯鍒舵祴閲忕偣锛堝湪杩炵嚎涔嬩笂锛岀‘淇濈偣瑕嗙洊鍦ㄧ嚎鐨勭鐐逛笂锛岀偣鍜岀嚎杩炴帴鍦ㄤ竴璧凤級
+ g2d.setColor(pointColor);
+ for (Point2D.Double point : points) {
+ // 鐐圭殑涓績鍦� point.x, point.y锛屾濂芥槸绾跨殑绔偣浣嶇疆
+ Ellipse2D.Double pointShape = new Ellipse2D.Double(
+ point.x - halfSize,
+ point.y - halfSize,
+ pointSizeInWorld,
+ pointSizeInWorld
+ );
+ g2d.fill(pointShape);
+ }
+ }
private void drawCurrentBoundary(Graphics2D g2d) {
bianjiedrwa.drawBoundary(g2d, currentBoundary, scale, GRASS_FILL_COLOR, GRASS_BORDER_COLOR);
@@ -1051,33 +1453,53 @@
if (markers == null || markers.isEmpty()) {
return;
}
+
+ // 淇濆瓨鍘熷鍙樻崲
+ AffineTransform originalTransform = g2d.getTransform();
+
Shape markerShape;
double half = CIRCLE_SAMPLE_SIZE / 2.0;
g2d.setColor(CIRCLE_SAMPLE_COLOR);
g2d.setStroke(new BasicStroke((float) (1.2f / scale), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
- Font originalFont = g2d.getFont();
- float baseSize = (float) Math.max(12f / scale, 9f);
- float reducedSize = Math.max(baseSize / 3f, 3f);
- Font labelFont = originalFont.deriveFont(reducedSize);
+
+ // 璁剧疆瀛椾綋锛堜笌缂╂斁鏂囧瓧澶у皬涓�鑷达紝11鍙峰瓧浣擄紝涓嶉殢缂╂斁鍙樺寲锛�
+ Font labelFont = new Font("寰蒋闆呴粦", Font.PLAIN, 11);
g2d.setFont(labelFont);
- FontMetrics metrics = g2d.getFontMetrics();
+ FontMetrics metrics = g2d.getFontMetrics(labelFont);
+
for (double[] pt : markers) {
if (pt == null || pt.length < 2 || !Double.isFinite(pt[0]) || !Double.isFinite(pt[1])) {
continue;
}
double x = pt[0];
double y = pt[1];
+
+ // 缁樺埗鐐癸紙鍦ㄤ笘鐣屽潗鏍囩郴涓紝闅忕缉鏀惧彉鍖栵級
markerShape = new Ellipse2D.Double(x - half, y - half, CIRCLE_SAMPLE_SIZE, CIRCLE_SAMPLE_SIZE);
g2d.fill(markerShape);
+
+ // 灏嗕笘鐣屽潗鏍囪浆鎹负灞忓箷鍧愭爣浠ョ粯鍒舵枃瀛楋紙涓嶉殢缂╂斁鍙樺寲锛�
+ Point2D.Double worldPoint = new Point2D.Double(x, y);
+ Point2D.Double screenPoint = new Point2D.Double();
+ originalTransform.transform(worldPoint, screenPoint);
+
+ // 鎭㈠鍘熷鍙樻崲浠ヤ娇鐢ㄥ睆骞曞潗鏍囩粯鍒舵枃瀛�
+ g2d.setTransform(new AffineTransform());
+
String label = String.format(Locale.US, "%.2f,%.2f", x, y);
int textWidth = metrics.stringWidth(label);
- float textX = (float) (x - textWidth / 2.0);
- float textY = (float) (y - half - 0.2d) - metrics.getDescent();
+ int textHeight = metrics.getHeight();
+
+ // 鍦ㄥ睆骞曞潗鏍囩郴涓粯鍒舵枃瀛楋紙涓嶉殢缂╂斁鍙樺寲锛�
+ int textX = (int)(screenPoint.x - textWidth / 2.0);
+ int textY = (int)(screenPoint.y - half - 0.2d) - metrics.getDescent();
g2d.setColor(new Color(33, 37, 41, 220));
g2d.drawString(label, textX, textY);
+
+ // 鎭㈠鍘熷鍙樻崲
+ g2d.setTransform(originalTransform);
g2d.setColor(CIRCLE_SAMPLE_COLOR);
}
- g2d.setFont(originalFont);
}
private void drawCircleCaptureOverlay(Graphics2D g2d, CircleCaptureOverlay overlay, double scale) {
@@ -1690,14 +2112,11 @@
return;
}
- // 璁剧疆鐐圭殑澶у皬锛堥殢缂╂斁鍙樺寲锛�
+ // 璁剧疆鐐圭殑澶у皬锛堣竟鐣岀嚎瀹藉害鐨�2鍊嶏級
+ // 杈圭晫绾垮搴︼細3 / Math.max(0.5, scale)
double scaleFactor = Math.max(0.5, scale);
- double clampedScale = boundaryPointSizeScale * (previewSizingEnabled ? PREVIEW_BOUNDARY_MARKER_SCALE : 1.0d);
- if (!Double.isFinite(clampedScale) || clampedScale <= 0.0d) {
- clampedScale = 1.0d;
- }
- double minimumDiameter = clampedScale < 1.0 ? 0.5 : 1.0;
- double markerDiameter = Math.max(minimumDiameter, (10.0 / scaleFactor) * 0.2 * clampedScale);
+ double boundaryLineWidth = 3.0 / scaleFactor; // 杈圭晫绾垮搴�
+ double markerDiameter = boundaryLineWidth * 2.0; // 杈圭晫鐐圭洿寰� = 杈圭晫绾垮搴︾殑2鍊�
double markerRadius = markerDiameter / 2.0;
// 璁剧疆瀛椾綋锛堜笌闅滅鐗╁簭鍙蜂竴鑷达紝涓嶉殢缂╂斁鍙樺寲锛�
@@ -2370,6 +2789,23 @@
this.obstaclePointsVisible = visible;
visualizationPanel.repaint();
}
+
+ /**
+ * 璁剧疆鏄惁鏄剧ず杈圭晫璺濈
+ */
+ public void setBoundaryLengthVisible(boolean visible) {
+ boundaryLengthVisible = visible;
+ if (visualizationPanel != null) {
+ visualizationPanel.repaint();
+ }
+ }
+
+ /**
+ * 鑾峰彇鏄惁鏄剧ず杈圭晫璺濈
+ */
+ public boolean isBoundaryLengthVisible() {
+ return boundaryLengthVisible;
+ }
public void setBoundaryPointSizeScale(double sizeScale) {
double normalized = (Double.isFinite(sizeScale) && sizeScale > 0.0d) ? sizeScale : 1.0d;
@@ -2587,5 +3023,140 @@
public Gecaoji getMower() {
return mower;
}
+
+ /**
+ * 璁剧疆寰�杩旇矾寰勭粯鍒剁鐞嗗櫒
+ */
+ public void setReturnPathDrawer(WangfanDraw drawer) {
+ this.returnPathDrawer = drawer;
+ }
+
+ /**
+ * 璁剧疆棰勮鐨勫線杩旇矾寰�
+ */
+ public void setPreviewReturnPath(List<Point2D.Double> path) {
+ this.previewReturnPath = path;
+ if (visualizationPanel != null) {
+ visualizationPanel.repaint();
+ }
+ }
+
+ /**
+ * 寮�濮嬪線杩旇矾寰勭粯鍒�
+ */
+ public void startReturnPathDrawing() {
+ if (returnPathDrawer != null) {
+ // 绂佺敤鎷栧熬鏁堟灉锛堝湪寰�杩旇矾寰勭粯鍒舵ā寮忎笅涓嶆樉绀哄疄鏃惰建杩规嫋灏撅級
+ idleTrailSuppressed = true;
+ clearIdleMowerTrail();
+ // 娓呯┖涔嬪墠鐨勮矾寰勭偣锛堥�氳繃 WangfanDraw 绠$悊锛�
+ repaint();
+ }
+ }
+
+ /**
+ * 鍋滄寰�杩旇矾寰勭粯鍒�
+ */
+ public void stopReturnPathDrawing() {
+ // 鎭㈠鎷栧熬鏁堟灉
+ idleTrailSuppressed = false;
+ repaint();
+ }
+
+ /**
+ * 璁剧疆鎷栧熬鎶戝埗鐘舵��
+ * @param suppressed true琛ㄧず鎶戝埗鎷栧熬缁樺埗锛宖alse琛ㄧず鍏佽鎷栧熬缁樺埗
+ */
+ public void setIdleTrailSuppressed(boolean suppressed) {
+ idleTrailSuppressed = suppressed;
+ if (suppressed && !idleMowerTrail.isEmpty()) {
+ clearIdleMowerTrail();
+ }
+ if (visualizationPanel != null) {
+ visualizationPanel.repaint();
+ }
+ }
+
+ /**
+ * 娣诲姞寰�杩旇矾寰勭偣锛堝凡搴熷純锛岃矾寰勭偣鐢� WangfanDraw 鐩存帴绠$悊锛�
+ */
+ @Deprecated
+ public void addReturnPathPoint(double x, double y) {
+ // 璺緞鐐圭敱 WangfanDraw 鐩存帴绠$悊锛岃繖閲屽彧闇�瑕侀噸缁�
+ repaint();
+ }
+
+ /**
+ * 鑾峰彇寰�杩旇矾寰勭偣鍒楄〃鐨勫揩鐓�
+ */
+ public List<Point2D.Double> getReturnPathPointsSnapshot() {
+ if (returnPathDrawer != null) {
+ return returnPathDrawer.getPointsSnapshot();
+ }
+ return new ArrayList<>();
+ }
+
+ /**
+ * 璁剧疆杈圭晫棰勮鏁版嵁锛堝師濮嬭竟鐣屽拰浼樺寲鍚庤竟鐣岋級
+ */
+ public void setBoundaryPreview(String originalBoundaryXY, String optimizedBoundary) {
+ if (originalBoundaryXY != null && !originalBoundaryXY.trim().isEmpty() && !"-1".equals(originalBoundaryXY.trim())) {
+ previewOriginalBoundary = parseBoundary(originalBoundaryXY.trim());
+ } else {
+ previewOriginalBoundary = null;
+ }
+
+ if (optimizedBoundary != null && !optimizedBoundary.trim().isEmpty() && !"-1".equals(optimizedBoundary.trim())) {
+ previewOptimizedBoundary = parseBoundary(optimizedBoundary.trim());
+ } else {
+ previewOptimizedBoundary = null;
+ }
+
+ boundaryPreviewActive = (previewOriginalBoundary != null && previewOriginalBoundary.size() >= 2) ||
+ (previewOptimizedBoundary != null && previewOptimizedBoundary.size() >= 2);
+
+ if (boundaryPreviewActive) {
+ // 璁$畻棰勮杈圭晫鐨勮竟鐣屾骞惰皟鏁磋鍥�
+ List<Point2D.Double> allPoints = new ArrayList<>();
+ if (previewOriginalBoundary != null) allPoints.addAll(previewOriginalBoundary);
+ if (previewOptimizedBoundary != null) allPoints.addAll(previewOptimizedBoundary);
+ if (!allPoints.isEmpty()) {
+ Rectangle2D.Double bounds = computeBounds(allPoints);
+ SwingUtilities.invokeLater(() -> {
+ fitBoundsToView(bounds);
+ visualizationPanel.repaint();
+ });
+ }
+ } else {
+ visualizationPanel.repaint();
+ }
+ }
+
+ /**
+ * 娓呴櫎杈圭晫棰勮
+ */
+ public void clearBoundaryPreview() {
+ previewOriginalBoundary = null;
+ previewOptimizedBoundary = null;
+ boundaryPreviewActive = false;
+ visualizationPanel.repaint();
+ }
+
+ /**
+ * 缁樺埗杈圭晫棰勮锛堝師濮嬭竟鐣�-绱壊锛屼紭鍖栧悗杈圭晫-缁胯壊锛�
+ */
+ private void drawBoundaryPreview(Graphics2D g2d) {
+ // 缁樺埗鍘熷杈圭晫锛堢传鑹诧級
+ if (previewOriginalBoundary != null && previewOriginalBoundary.size() >= 2) {
+ Color purpleFill = new Color(128, 0, 128, 80); // 绱壊鍗婇�忔槑濉厖
+ Color purpleBorder = new Color(128, 0, 128, 255); // 绱壊杈规
+ bianjiedrwa.drawBoundary(g2d, previewOriginalBoundary, scale, purpleFill, purpleBorder);
+ }
+
+ // 缁樺埗浼樺寲鍚庤竟鐣岋紙缁胯壊锛屼笌姝e父杈圭晫棰滆壊涓�鑷达級
+ if (previewOptimizedBoundary != null && previewOptimizedBoundary.size() >= 2) {
+ bianjiedrwa.drawBoundary(g2d, previewOptimizedBoundary, scale, GRASS_FILL_COLOR, GRASS_BORDER_COLOR);
+ }
+ }
}
\ No newline at end of file
--
Gitblit v1.10.0