Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .copilot-tracking/changes/20260219-sketch-style-editing-changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!-- markdownlint-disable-file -->
# Release Changes: Phase 4.0 Sketch-Style Curve Editing

**Related Plan**: .github/planning/phase-4-plan.md (Section 0)
**Implementation Date**: 2026-02-19

## Summary

Implements sketch-style curve editing on the chart, allowing users to click and drag to draw torque values directly onto a curve series. The mouse position is snapped to the nearest speed data point (X axis) and rounded to a configurable torque increment (Y axis, default 0.2).

## Changes

### Added

- src/MotorEditor.Avalonia/ViewModels/ChartViewModel.cs - Added `SketchEditSeriesName`, `IsSketchEditActive`, `TorqueSnapIncrement` properties and `SetSketchEditSeries`, `ClearSketchEditSeries`, `ApplySketchPoint`, `FindNearestSpeedIndex`, `SnapTorque` methods for sketch-edit mode
- src/MotorEditor.Avalonia/Views/ChartView.axaml.cs - Added `_isSketchDragging` state, `TryApplySketchAtPixel` helper, and sketch-edit handling in pointer event handlers
- tests/CurveEditor.Tests/ViewModels/ChartViewModelTests.cs - Added 26 unit tests covering sketch-edit activation/deactivation, torque snapping, nearest speed index, and ApplySketchPoint behavior

### Modified

- src/MotorEditor.Avalonia/Models/UserPreferences.cs - Added `TorqueSnapIncrement` property (default 0.2) with clone support
- src/MotorEditor.Avalonia/Views/ChartView.axaml - Added sketch-edit mode indicator overlay showing active series name
- src/MotorEditor.Avalonia/Views/ChartView.axaml.cs - Extended pointer pressed/moved/released/capture-lost handlers to support sketch-edit drag interactions
- src/MotorEditor.Avalonia/Views/CurveDataPanel.axaml - Added per-series ✏ sketch-edit toggle button in the column header
- src/MotorEditor.Avalonia/Views/CurveDataPanel.axaml.cs - Added `OnSketchEditToggleClick` and `RefreshSketchEditToggles` handlers for sketch-edit toggle

### Removed

(none)

## Release Summary

**Total Files Affected**: 6

### Files Created (0)

(none)

### Files Modified (6)

- src/MotorEditor.Avalonia/Models/UserPreferences.cs - Added TorqueSnapIncrement preference
- src/MotorEditor.Avalonia/ViewModels/ChartViewModel.cs - Added sketch-edit state management and point application logic
- src/MotorEditor.Avalonia/Views/ChartView.axaml - Added sketch-edit mode indicator overlay
- src/MotorEditor.Avalonia/Views/ChartView.axaml.cs - Added sketch-edit mouse interaction handling
- src/MotorEditor.Avalonia/Views/CurveDataPanel.axaml - Added per-series sketch-edit toggle button in column header
- src/MotorEditor.Avalonia/Views/CurveDataPanel.axaml.cs - Added sketch-edit toggle click handler and sibling refresh logic
- tests/CurveEditor.Tests/ViewModels/ChartViewModelTests.cs - Added 26 unit tests for sketch-edit functionality

### Files Removed (0)

(none)

### Dependencies & Infrastructure

- **New Dependencies**: None
- **Updated Dependencies**: None
- **Infrastructure Changes**: None
- **Configuration Updates**: None

### Deployment Notes

No special deployment considerations. The sketch-edit feature is purely additive and does not change existing behavior.
12 changes: 6 additions & 6 deletions .github/planning/phase-4-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
### 0. Sketch-Style Curve Editing
- **Goal**: Enable simple, straightforward editing of a specified torque curve by clicking and dragging the mouse in the graph area.
- **Steps**:
- [ ] Enable "Sketch edit" mode for a curve series. Only one curve series can be in sketch edit mode at a time.
- [ ] Implement a manner to track mouse position over the chart area in near-real time, in terms of x (speed), and y (torque).
- [ ] The speed component of the mouse position shall be rounded to the nearest speed data point in the chart field.
- [ ] The torque component of the mouse position shall be rounded to the nearest 0.2; this value shall be set-able in preferences.
- [ ] When the mouse is clicked while in the graph area, the curve with an active sketch-edit mode, will record the position of the mouse in the curve data, at the position of the x (speed) value in the dataset. E.g. if the mouse is nearest to 5% speed, and is nearest to 10.2 Nm and the user clicks, the curve series data should update such that at 5% speed that curve torque value is equal to 10.2 Nm.
- [ ] The user shall be able to click and drag the mouse over the graph, with the positions of the active sketch-edit curve being written to the curve data series as the mouse moves. Hence, the user could "sketch" over an image motor curve, cleaning up slight data errors very easily.
- [X] Enable "Sketch edit" mode for a curve series. Only one curve series can be in sketch edit mode at a time.
- [X] Implement a manner to track mouse position over the chart area in near-real time, in terms of x (speed), and y (torque).
- [X] The speed component of the mouse position shall be rounded to the nearest speed data point in the chart field.
- [X] The torque component of the mouse position shall be rounded to the nearest 0.2; this value shall be set-able in preferences.
- [X] When the mouse is clicked while in the graph area, the curve with an active sketch-edit mode, will record the position of the mouse in the curve data, at the position of the x (speed) value in the dataset. E.g. if the mouse is nearest to 5% speed, and is nearest to 10.2 Nm and the user clicks, the curve series data should update such that at 5% speed that curve torque value is equal to 10.2 Nm.
- [X] The user shall be able to click and drag the mouse over the graph, with the positions of the active sketch-edit curve being written to the curve data series as the mouse moves. Hence, the user could "sketch" over an image motor curve, cleaning up slight data errors very easily.

### 1. EQ-Style Curve Editing
- **Goal**: Enable rich, EQ-style editing of torque curves directly on the chart while keeping the data grid and underlying models in sync.
Expand Down
18 changes: 17 additions & 1 deletion src/MotorEditor.Avalonia/Models/UserPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ public sealed class UserPreferences
/// </summary>
public bool ShowVoltageMaxSpeedLine { get; set; } = true;

/// <summary>
/// Torque snap increment used during sketch editing. The torque value
/// recorded when the user sketches on the chart is rounded to the
/// nearest multiple of this value. Defaults to 0.2.
/// </summary>
public decimal TorqueSnapIncrement { get; set; } = 0.2m;

/// <summary>
/// Drag sketch band width as a percent of nearest point spacing.
/// Lower values require the pointer to stay closer to each point while
/// click-hold-drag sketching. Defaults to 5%.
/// </summary>
public decimal SketchDragBandPercent { get; set; } = 5m;

/// <summary>
/// Creates a copy of the current preferences.
/// </summary>
Expand All @@ -54,7 +68,9 @@ public UserPreferences Clone()
Theme = Theme,
CurveColors = new List<string>(CurveColors),
ShowMotorRatedSpeedLine = ShowMotorRatedSpeedLine,
ShowVoltageMaxSpeedLine = ShowVoltageMaxSpeedLine
ShowVoltageMaxSpeedLine = ShowVoltageMaxSpeedLine,
TorqueSnapIncrement = TorqueSnapIncrement,
SketchDragBandPercent = SketchDragBandPercent
};
}
}
Loading