Skip to content
Open
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
15 changes: 15 additions & 0 deletions lib/auto/pathplanner_auto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';

import 'package:file/file.dart';
import 'package:path/path.dart';
import 'package:pathplanner/commands/conditional_command_group.dart';
import 'package:pathplanner/commands/named_command.dart';
import 'package:pathplanner/commands/command.dart';
import 'package:pathplanner/commands/command_groups.dart';
Expand Down Expand Up @@ -165,6 +166,12 @@ class PathPlannerAuto {
continue;
}
}
if (cmd is ConditionalCommandGroup) {
if (cmd.namedConditional.name != null) {
ProjectPage.conditions.add(cmd.namedConditional.name!);
continue;
}
}

if (cmd is CommandGroup) {
_addNamedCommandsToEvents(cmd.commands);
Expand Down Expand Up @@ -219,6 +226,14 @@ class PathPlannerAuto {
names.add(cmd.pathName!);
} else if (cmd is CommandGroup) {
names.addAll(_getPathNamesInCommands(cmd.commands));
} else if (cmd is ConditionalCommandGroup) {
if (cmd.namedConditional.defaultValue) {
names.addAll(
_getPathNamesInCommands((cmd.onTrue as CommandGroup).commands));
} else {
names.addAll(
_getPathNamesInCommands((cmd.onFalse as CommandGroup).commands));
}
}
}
return names;
Expand Down
6 changes: 6 additions & 0 deletions lib/commands/command.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:flutter/foundation.dart';
import 'package:pathplanner/commands/command_groups.dart';
import 'package:pathplanner/commands/conditional_command_group.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/commands/wait_until_command.dart';

abstract class Command {
final String type;
Expand All @@ -29,12 +31,14 @@ abstract class Command {

return switch (type) {
'wait' => WaitCommand.fromDataJson(data),
'wait_until' => WaitUntilCommand.fromDataJson(data),
'named' => NamedCommand.fromDataJson(data),
'path' => PathCommand.fromDataJson(data),
'sequential' => SequentialCommandGroup.fromDataJson(data),
'parallel' => ParallelCommandGroup.fromDataJson(data),
'race' => RaceCommandGroup.fromDataJson(data),
'deadline' => DeadlineCommandGroup.fromDataJson(data),
'conditional' => ConditionalCommandGroup.fromDataJson(data),
_ => null,
};
}
Expand All @@ -43,11 +47,13 @@ abstract class Command {
return switch (type) {
'named' => NamedCommand(),
'wait' => WaitCommand(),
'wait_until' => WaitUntilCommand(),
'path' => PathCommand(),
'sequential' => SequentialCommandGroup(commands: commands ?? []),
'parallel' => ParallelCommandGroup(commands: commands ?? []),
'race' => RaceCommandGroup(commands: commands ?? []),
'deadline' => DeadlineCommandGroup(commands: commands ?? []),
'conditional' => ConditionalCommandGroup(),
_ => null,
};
}
Expand Down
62 changes: 62 additions & 0 deletions lib/commands/conditional_command_group.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import 'package:pathplanner/commands/command.dart';
import 'package:pathplanner/commands/command_groups.dart';

class NamedConditional {
String? name;
bool defaultValue = true;
}

class ConditionalCommandGroup extends Command {
Command? onTrue;
Command? onFalse;
NamedConditional namedConditional;

ConditionalCommandGroup(
{this.onTrue, this.onFalse, String? namedConditional, bool? defaultValue})
: namedConditional = NamedConditional(),
super(type: 'conditional') {
onTrue = SequentialCommandGroup(commands: []);
onFalse = SequentialCommandGroup(commands: []);
this.namedConditional.name = namedConditional;
this.namedConditional.defaultValue = defaultValue ?? true;
}

ConditionalCommandGroup.fromDataJson(Map<String, dynamic> json)
: namedConditional = NamedConditional(),
super(type: 'conditional') {
onTrue = Command.fromJson(json['onTrue']);
onFalse = Command.fromJson(json['onFalse']);
namedConditional.name = json['namedConditional'];
namedConditional.defaultValue = json['default'];
}

@override
Map<String, dynamic> dataToJson() {
return {
'onTrue': onTrue?.toJson(),
'onFalse': onFalse?.toJson(),
'namedConditional': namedConditional.name,
'default': namedConditional.defaultValue,
};
}

@override
Command clone() {
return ConditionalCommandGroup(
onTrue: onTrue?.clone(),
onFalse: onFalse?.clone(),
namedConditional: namedConditional.name,
defaultValue: namedConditional.defaultValue);
}

@override
bool operator ==(Object other) =>
other is ConditionalCommandGroup &&
other.runtimeType == runtimeType &&
other.namedConditional == namedConditional &&
other.onFalse == onFalse &&
other.onTrue == onTrue;

@override
int get hashCode => Object.hash(type, onTrue, onFalse, namedConditional);
}
37 changes: 37 additions & 0 deletions lib/commands/wait_until_command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:pathplanner/commands/command.dart';
import 'package:pathplanner/commands/conditional_command_group.dart';

class WaitUntilCommand extends Command {
NamedConditional conditional;

WaitUntilCommand({String? name})
: conditional = NamedConditional(),
super(type: 'wait_until') {
conditional.name = name;
conditional.defaultValue = true;
}

WaitUntilCommand.fromDataJson(Map<String, dynamic> json)
: this(name: json['namedConditional']);

@override
Map<String, dynamic> dataToJson() {
return {
'namedConditional': conditional.name,
};
}

@override
Command clone() {
return WaitUntilCommand(name: conditional.name);
}

@override
bool operator ==(Object other) =>
other is WaitUntilCommand &&
other.runtimeType == runtimeType &&
other.conditional == conditional;

@override
int get hashCode => Object.hash(type, conditional);
}
1 change: 1 addition & 0 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
// Clear event names
if (projectDir != _projectDir?.path) {
ProjectPage.events.clear();
ProjectPage.conditions.clear();
}

setState(() {
Expand Down
1 change: 1 addition & 0 deletions lib/pages/project/project_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import 'package:watcher/watcher.dart';

class ProjectPage extends StatefulWidget {
static Set<String> events = {};
static Set<String> conditions = {};

final SharedPreferences prefs;
final FieldImage fieldImage;
Expand Down
8 changes: 8 additions & 0 deletions lib/path/pathplanner_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart';
import 'package:path/path.dart';
import 'package:pathplanner/commands/command.dart';
import 'package:pathplanner/commands/command_groups.dart';
import 'package:pathplanner/commands/conditional_command_group.dart';
import 'package:pathplanner/commands/named_command.dart';
import 'package:pathplanner/pages/project/project_page.dart';
import 'package:pathplanner/path/constraints_zone.dart';
Expand Down Expand Up @@ -326,6 +327,13 @@ class PathPlannerPath {
}
}

if (command is ConditionalCommandGroup) {
if (command.namedConditional.name != null) {
ProjectPage.conditions.add(command.namedConditional.name!);
return;
}
}

if (command is CommandGroup) {
for (Command cmd in command.commands) {
_addNamedCommandsToEvents(cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class AddCommandButton extends StatelessWidget {
value: 'wait',
child: Text('Wait Command'),
),
if (allowWaitCommand)
const PopupMenuItem(
value: 'wait_until',
child: Text('Wait Until Command'),
),
const PopupMenuItem(
value: 'sequential',
child: Text('Sequential Command Group'),
Expand All @@ -63,6 +68,10 @@ class AddCommandButton extends StatelessWidget {
value: 'race',
child: Text('Parallel Race Group'),
),
const PopupMenuItem(
value: 'conditional',
child: Text('Conditional Command Group'),
),
];
}
}
25 changes: 25 additions & 0 deletions lib/widgets/editor/tree_widgets/commands/command_group_widget.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import 'package:flutter/material.dart';
import 'package:pathplanner/commands/command.dart';
import 'package:pathplanner/commands/command_groups.dart';
import 'package:pathplanner/commands/conditional_command_group.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/commands/wait_until_command.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/conditional_group_widget.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/commands/duplicate_command_button.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/commands/named_command_widget.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/commands/path_command_widget.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/commands/wait_command_widget.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/commands/wait_until_widget.dart';
import 'package:undo/undo.dart';

class CommandGroupWidget extends StatelessWidget {
Expand Down Expand Up @@ -293,6 +297,27 @@ class CommandGroupWidget extends StatelessWidget {
},
onDuplicateCommand: () => _duplicateCommand(cmdIndex),
);
} else if (command.commands[cmdIndex] is ConditionalCommandGroup) {
return ConditionalCommandGroupWidget(
command: command.commands[cmdIndex] as ConditionalCommandGroup,
undoStack: undoStack,
allPathNames: allPathNames,
onDuplicateCommand: () => _duplicateCommand(cmdIndex),
onEditPathPressed: onEditPathPressed,
onPathCommandHovered: onPathCommandHovered,
onRemoved: () => _removeCommand(cmdIndex),
onUpdated: onUpdated,
showEditPathButton: showEditPathButton,
subCommandElevation: subCommandElevation,
);
} else if (command.commands[cmdIndex] is WaitUntilCommand) {
return WaitUntilCommandWidget(
command: command.commands[cmdIndex] as WaitUntilCommand,
onUpdated: onUpdated,
onRemoved: () => _removeCommand(cmdIndex),
undoStack: undoStack,
onDuplicateCommand: () => _duplicateCommand(cmdIndex),
);
}

return Container();
Expand Down
Loading