Skip to content

Commit

Permalink
feat: add edit path button in auto editor
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley31 committed Oct 10, 2023
1 parent a9e8b76 commit 678d5e0
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/pages/auto_editor_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:pathplanner/auto/pathplanner_auto.dart';
import 'package:pathplanner/pages/project/project_page.dart';
import 'package:pathplanner/path/pathplanner_path.dart';
import 'package:pathplanner/services/pplib_telemetry.dart';
import 'package:pathplanner/widgets/conditional_widget.dart';
Expand All @@ -18,6 +19,7 @@ class AutoEditorPage extends StatefulWidget {
final List<String> allPathNames;
final FieldImage fieldImage;
final ValueChanged<String> onRenamed;
final OpenPathCallback? onPathOpened;
final ChangeStack undoStack;
final bool shortcuts;
final PPLibTelemetry? telemetry;
Expand All @@ -32,6 +34,7 @@ class AutoEditorPage extends StatefulWidget {
required this.fieldImage,
required this.onRenamed,
required this.undoStack,
this.onPathOpened,
this.shortcuts = true,
this.telemetry,
this.hotReload = false,
Expand Down Expand Up @@ -67,6 +70,7 @@ class _AutoEditorPageState extends State<AutoEditorPage> {
widget.telemetry?.hotReloadAuto(widget.auto);
}
},
onPathOpened: widget.onPathOpened,
);

return Scaffold(
Expand Down
28 changes: 28 additions & 0 deletions lib/pages/project/project_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import 'package:pathplanner/widgets/renamable_title.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:undo/undo.dart';

typedef OpenPathCallback = void Function(BuildContext context, String name);

class ProjectPage extends StatefulWidget {
final SharedPreferences prefs;
final FieldImage fieldImage;
Expand Down Expand Up @@ -687,6 +689,31 @@ class _ProjectPageState extends State<ProjectPage> {
});
}

void _openPathByName(BuildContext context, String name) async {
int index = _paths.indexWhere((path) => path.name == name);

Check warning on line 693 in lib/pages/project/project_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/project/project_page.dart#L692-L693

Added lines #L692 - L693 were not covered by tests

if (index == -1) {
throw Exception("No path found with name '$name'");

Check warning on line 696 in lib/pages/project/project_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/project/project_page.dart#L695-L696

Added lines #L695 - L696 were not covered by tests
}

await Navigator.push(

Check warning on line 699 in lib/pages/project/project_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/project/project_page.dart#L699

Added line #L699 was not covered by tests
context,
MaterialPageRoute(
builder: (context) => PathEditorPage(
prefs: widget.prefs,
path: _paths[index],
fieldImage: widget.fieldImage,
undoStack: widget.undoStack,
onRenamed: (value) => _renamePath(index, value, context),
shortcuts: widget.shortcuts,
telemetry: widget.telemetry,
hotReload: widget.hotReload,
simulatePath: widget.simulatePath,

Check warning on line 711 in lib/pages/project/project_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/project/project_page.dart#L701-L711

Added lines #L701 - L711 were not covered by tests
),
),
);
}

void _renamePath(int pathIdx, String newName, BuildContext context) {
List<String> pathNames = [];
for (PathPlannerPath path in _paths) {
Expand Down Expand Up @@ -1117,6 +1144,7 @@ class _ProjectPageState extends State<ProjectPage> {
allPathNames: _paths.map((e) => e.name).toList(),
fieldImage: widget.fieldImage,
onRenamed: (value) => _renameAuto(i, value, context),
onPathOpened: _openPathByName,
shortcuts: widget.shortcuts,
telemetry: widget.telemetry,
hotReload: widget.hotReload,
Expand Down
4 changes: 4 additions & 0 deletions lib/widgets/editor/split_auto_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:multi_split_view/multi_split_view.dart';
import 'package:pathplanner/auto/pathplanner_auto.dart';
import 'package:pathplanner/pages/project/project_page.dart';
import 'package:pathplanner/services/simulator/trajectory_generator.dart';
import 'package:pathplanner/util/pose2d.dart';
import 'package:pathplanner/path/pathplanner_path.dart';
Expand All @@ -20,6 +21,7 @@ class SplitAutoEditor extends StatefulWidget {
final List<PathPlannerPath> autoPaths;
final List<String> allPathNames;
final VoidCallback? onAutoChanged;
final OpenPathCallback? onPathOpened;
final FieldImage fieldImage;
final ChangeStack undoStack;

Expand All @@ -30,6 +32,7 @@ class SplitAutoEditor extends StatefulWidget {
required this.allPathNames,
required this.fieldImage,
required this.undoStack,
this.onPathOpened,
this.onAutoChanged,
super.key,
});
Expand Down Expand Up @@ -270,6 +273,7 @@ class _SplitAutoEditorState extends State<SplitAutoEditor>
widget.onAutoChanged?.call();
_simulateAuto();
},
onPathOpened: widget.onPathOpened,
onSideSwapped: () => setState(() {
_treeOnRight = !_treeOnRight;
widget.prefs.setBool(PrefsKeys.treeOnRight, _treeOnRight);
Expand Down
4 changes: 4 additions & 0 deletions lib/widgets/editor/tree_widgets/auto_tree.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:pathplanner/auto/pathplanner_auto.dart';
import 'package:pathplanner/pages/project/project_page.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/commands/command_group_widget.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/editor_settings_tree.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/starting_pose_tree.dart';
Expand All @@ -11,6 +12,7 @@ class AutoTree extends StatefulWidget {
final ValueChanged<String?>? onPathHovered;
final VoidCallback? onSideSwapped;
final VoidCallback? onAutoChanged;
final OpenPathCallback? onPathOpened;
final ChangeStack undoStack;
final num? autoRuntime;

Expand All @@ -21,6 +23,7 @@ class AutoTree extends StatefulWidget {
this.onPathHovered,
this.onSideSwapped,
this.onAutoChanged,
this.onPathOpened,
required this.undoStack,
this.autoRuntime,
});
Expand Down Expand Up @@ -72,6 +75,7 @@ class _AutoTreeState extends State<AutoTree> {
command: widget.auto.sequence,
allPathNames: widget.allPathNames,
onPathCommandHovered: widget.onPathHovered,
onPathOpened: widget.onPathOpened,
removable: false,
onUpdated: widget.onAutoChanged,
undoStack: widget.undoStack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:pathplanner/commands/command_groups.dart';
import 'package:pathplanner/commands/named_command.dart';
import 'package:pathplanner/commands/path_command.dart';
import 'package:pathplanner/commands/wait_command.dart';
import 'package:pathplanner/pages/path_editor_page.dart';
import 'package:pathplanner/pages/project/project_page.dart';
import 'package:pathplanner/widgets/conditional_widget.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/commands/add_command_button.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/commands/named_command_widget.dart';
Expand All @@ -20,6 +22,7 @@ class CommandGroupWidget extends StatelessWidget {
final bool removable;
final List<String>? allPathNames;
final ValueChanged<String?>? onPathCommandHovered;
final OpenPathCallback? onPathOpened;
final ChangeStack undoStack;

const CommandGroupWidget({
Expand All @@ -32,6 +35,7 @@ class CommandGroupWidget extends StatelessWidget {
this.removable = true,
this.allPathNames,
this.onPathCommandHovered,
this.onPathOpened,
required this.undoStack,
});

Expand Down Expand Up @@ -166,6 +170,7 @@ class CommandGroupWidget extends StatelessWidget {
allPathNames: allPathNames ?? [],
onUpdated: onUpdated,
onRemoved: () => _removeCommand(index),
onOpened: onPathOpened,
undoStack: undoStack,
),
),
Expand Down
22 changes: 19 additions & 3 deletions lib/widgets/editor/tree_widgets/commands/path_command_widget.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import 'package:flutter/material.dart';
import 'package:pathplanner/commands/path_command.dart';
import 'package:pathplanner/pages/project/project_page.dart';
import 'package:undo/undo.dart';

class PathCommandWidget extends StatefulWidget {
final PathCommand command;
final List<String> allPathNames;
final VoidCallback? onUpdated;
final VoidCallback? onRemoved;
final OpenPathCallback? onOpened;
final ChangeStack undoStack;

const PathCommandWidget({
Expand All @@ -15,6 +17,7 @@ class PathCommandWidget extends StatefulWidget {
required this.allPathNames,
this.onUpdated,
this.onRemoved,
this.onOpened,
required this.undoStack,
});

Expand Down Expand Up @@ -81,15 +84,28 @@ class _PathCommandWidgetState extends State<PathCommandWidget> {
}),
),
const SizedBox(width: 8),
Visibility(
visible: widget.command.pathName == null,
child: const Tooltip(
widget.command.pathName == null
? const Tooltip(
message: 'Missing path name',
child: Icon(
Icons.warning_amber_rounded,
color: Colors.yellow,
size: 32,
),
)
: Tooltip(
message: 'Edit Path',
waitDuration: const Duration(milliseconds: 500),
child: IconButton(
onPressed: () {
if (widget.onOpened != null){
widget.onOpened!(context, widget.command.pathName!);

Check warning on line 102 in lib/widgets/editor/tree_widgets/commands/path_command_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/editor/tree_widgets/commands/path_command_widget.dart#L100-L102

Added lines #L100 - L102 were not covered by tests
}
},
visualDensity: const VisualDensity(
horizontal: VisualDensity.minimumDensity,
vertical: VisualDensity.minimumDensity),
icon: Icon(Icons.open_in_new, color: colorScheme.primary),
),
),
Tooltip(
Expand Down

0 comments on commit 678d5e0

Please sign in to comment.