From 9a8d2a25d55f4999b9c127beb734162fde6a7f82 Mon Sep 17 00:00:00 2001 From: Amit-Matth Date: Wed, 13 May 2026 22:03:20 +0530 Subject: [PATCH] PAINTROID-729 refactor converters --- .../command_factory/command_factory.dart | 6 +- .../graphic/line_command.dart | 18 +- .../graphic/line_command.g.dart | 5 +- .../graphic/path_command.dart | 14 +- .../graphic/path_command.g.dart | 5 +- .../graphic_factory/graphic_factory.dart | 5 +- .../commands/path_with_action_history.dart | 93 -------- .../converter/path_action_converter.dart | 45 ---- .../path_with_action_history_converter.dart | 35 --- .../versioning/serializer_version.dart | 1 + .../versioning/version_strategy.dart | 4 + .../models/path_actions/close_action.dart | 21 ++ .../models/path_actions/close_action.g.dart | 12 + .../models/path_actions/line_to_action.dart | 27 +++ .../models/path_actions/line_to_action.g.dart | 18 ++ .../models/path_actions/move_to_action.dart | 27 +++ .../models/path_actions/move_to_action.g.dart | 18 ++ lib/core/models/path_actions/path_action.dart | 24 ++ lib/core/models/path_model.dart | 207 ++++++++++++++++++ lib/core/models/path_model.g.dart | 21 ++ lib/core/tools/implementation/brush_tool.dart | 8 +- lib/core/tools/line_tool/line_tool.dart | 6 +- test/unit/command/command_factory_test.dart | 6 +- test/unit/command/draw_path_command_test.dart | 8 +- .../command/line_command_serializer_test.dart | 4 +- .../command/path_command_serializer_test.dart | 10 +- .../converter/path_action_converter_test.dart | 26 +-- ...th_with_action_history_converter_test.dart | 33 ++- .../utils/dummy_command_factory.dart | 10 +- .../utils/dummy_path_factory.dart | 15 +- .../utils/dummy_version_strategy.dart | 5 + test/unit/tools/brush_tool_test.dart | 4 +- .../unit/tools/clipboard_tool_test.mocks.dart | 6 +- test/unit/tools/cursor_tool_test.dart | 3 +- test/unit/tools/pipette_tool_test.mocks.dart | 22 +- test/unit/tools/text_tool_test.mocks.dart | 22 +- test/unit/tools/watercolor_tool_test.dart | 4 +- 37 files changed, 501 insertions(+), 297 deletions(-) delete mode 100644 lib/core/commands/path_with_action_history.dart delete mode 100644 lib/core/json_serialization/converter/path_action_converter.dart delete mode 100644 lib/core/json_serialization/converter/path_with_action_history_converter.dart create mode 100644 lib/core/models/path_actions/close_action.dart create mode 100644 lib/core/models/path_actions/close_action.g.dart create mode 100644 lib/core/models/path_actions/line_to_action.dart create mode 100644 lib/core/models/path_actions/line_to_action.g.dart create mode 100644 lib/core/models/path_actions/move_to_action.dart create mode 100644 lib/core/models/path_actions/move_to_action.g.dart create mode 100644 lib/core/models/path_actions/path_action.dart create mode 100644 lib/core/models/path_model.dart create mode 100644 lib/core/models/path_model.g.dart diff --git a/lib/core/commands/command_factory/command_factory.dart b/lib/core/commands/command_factory/command_factory.dart index 220b530e..57bb7b61 100644 --- a/lib/core/commands/command_factory/command_factory.dart +++ b/lib/core/commands/command_factory/command_factory.dart @@ -13,21 +13,21 @@ import 'package:paintroid/core/commands/command_implementation/graphic/shape/squ import 'package:paintroid/core/commands/command_implementation/graphic/shape/star_shape_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/spray_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/color_changed_command.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_model.dart'; import 'package:paintroid/core/enums/shape_style.dart'; class CommandFactory { const CommandFactory(); PathCommand createPathCommand( - PathWithActionHistory path, + PathModel path, Paint paint, { bool isCursor = false, }) => PathCommand(path, paint, isCursorPath: isCursor); LineCommand createLineCommand( - PathWithActionHistory path, + PathModel path, Paint paint, Offset startPoint, Offset endPoint, diff --git a/lib/core/commands/command_implementation/graphic/line_command.dart b/lib/core/commands/command_implementation/graphic/line_command.dart index 68c8ddb2..016421a7 100644 --- a/lib/core/commands/command_implementation/graphic/line_command.dart +++ b/lib/core/commands/command_implementation/graphic/line_command.dart @@ -5,23 +5,23 @@ import 'dart:ui'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/graphic_command.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_model.dart'; +import 'package:paintroid/core/models/path_actions/move_to_action.dart'; +import 'package:paintroid/core/models/path_actions/line_to_action.dart'; import 'package:paintroid/core/json_serialization/converter/offset_converter.dart'; import 'package:paintroid/core/json_serialization/converter/paint_converter.dart'; -import 'package:paintroid/core/json_serialization/converter/path_with_action_history_converter.dart'; import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart'; import 'package:paintroid/core/json_serialization/versioning/version_strategy.dart'; part 'line_command.g.dart'; -@JsonSerializable() +@JsonSerializable(explicitToJson: true) class LineCommand extends GraphicCommand { final String type; final int version; bool isSourcePath = false; - @PathWithActionHistoryConverter() - PathWithActionHistory path; + PathModel path; @OffsetConverter() Offset startPoint; @@ -41,7 +41,7 @@ class LineCommand extends GraphicCommand { @override void call(Canvas canvas) { - canvas.drawPath(path.path, paint); + canvas.drawPath(path.nativePath, paint); } @override @@ -51,7 +51,7 @@ class LineCommand extends GraphicCommand { isSourcePath = true; } - void updatePath(PathWithActionHistory newPath) { + void updatePath(PathModel newPath) { path = newPath; final moveAction = path.actions.first as MoveToAction; final lineAction = path.actions.last as LineToAction; @@ -63,11 +63,13 @@ class LineCommand extends GraphicCommand { Map toJson() => _$LineCommandToJson(this); factory LineCommand.fromJson(Map json) { - int version = json['version'] as int; + int? version = json['version'] as int?; switch (version) { case Version.v1: return _$LineCommandFromJson(json); + case null: + return _$LineCommandFromJson(json); case Version.v2: // For different versions of PathCommand the deserialization // has to be implemented manually. diff --git a/lib/core/commands/command_implementation/graphic/line_command.g.dart b/lib/core/commands/command_implementation/graphic/line_command.g.dart index 9e41a807..6c4135ff 100644 --- a/lib/core/commands/command_implementation/graphic/line_command.g.dart +++ b/lib/core/commands/command_implementation/graphic/line_command.g.dart @@ -7,8 +7,7 @@ part of 'line_command.dart'; // ************************************************************************** LineCommand _$LineCommandFromJson(Map json) => LineCommand( - const PathWithActionHistoryConverter() - .fromJson(json['path'] as Map), + PathModel.fromJson(json['path'] as Map), const PaintConverter().fromJson(json['paint'] as Map), const OffsetConverter() .fromJson(json['startPoint'] as Map), @@ -24,7 +23,7 @@ Map _$LineCommandToJson(LineCommand instance) => 'type': instance.type, 'version': instance.version, 'isSourcePath': instance.isSourcePath, - 'path': const PathWithActionHistoryConverter().toJson(instance.path), + 'path': instance.path.toJson(), 'startPoint': const OffsetConverter().toJson(instance.startPoint), 'endPoint': const OffsetConverter().toJson(instance.endPoint), }; diff --git a/lib/core/commands/command_implementation/graphic/path_command.dart b/lib/core/commands/command_implementation/graphic/path_command.dart index ba0a20b0..e1823f2d 100644 --- a/lib/core/commands/command_implementation/graphic/path_command.dart +++ b/lib/core/commands/command_implementation/graphic/path_command.dart @@ -5,15 +5,14 @@ import 'package:flutter/widgets.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/graphic_command.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_model.dart'; import 'package:paintroid/core/json_serialization/converter/paint_converter.dart'; -import 'package:paintroid/core/json_serialization/converter/path_with_action_history_converter.dart'; import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart'; import 'package:paintroid/core/json_serialization/versioning/version_strategy.dart'; part 'path_command.g.dart'; -@JsonSerializable() +@JsonSerializable(explicitToJson: true) class PathCommand extends GraphicCommand { final String type; final int version; @@ -28,12 +27,11 @@ class PathCommand extends GraphicCommand { }) : version = version ?? VersionStrategyManager.strategy.getPathCommandVersion(); - @PathWithActionHistoryConverter() - final PathWithActionHistory path; + final PathModel path; @override void call(Canvas canvas) { - canvas.drawPath(path.path, paint); + canvas.drawPath(path.nativePath, paint); } @override @@ -43,11 +41,13 @@ class PathCommand extends GraphicCommand { Map toJson() => _$PathCommandToJson(this); factory PathCommand.fromJson(Map json) { - int version = json['version'] as int; + int? version = json['version'] as int?; switch (version) { case Version.v1: return _$PathCommandFromJson(json); + case null: + return _$PathCommandFromJson(json); case Version.v2: // For different versions of PathCommand the deserialization // has to be implemented manually. diff --git a/lib/core/commands/command_implementation/graphic/path_command.g.dart b/lib/core/commands/command_implementation/graphic/path_command.g.dart index cb5748ad..fd7a9dfa 100644 --- a/lib/core/commands/command_implementation/graphic/path_command.g.dart +++ b/lib/core/commands/command_implementation/graphic/path_command.g.dart @@ -7,8 +7,7 @@ part of 'path_command.dart'; // ************************************************************************** PathCommand _$PathCommandFromJson(Map json) => PathCommand( - const PathWithActionHistoryConverter() - .fromJson(json['path'] as Map), + PathModel.fromJson(json['path'] as Map), const PaintConverter().fromJson(json['paint'] as Map), type: json['type'] as String? ?? SerializerType.PATH_COMMAND, version: (json['version'] as num?)?.toInt(), @@ -21,5 +20,5 @@ Map _$PathCommandToJson(PathCommand instance) => 'type': instance.type, 'version': instance.version, 'isCursorPath': instance.isCursorPath, - 'path': const PathWithActionHistoryConverter().toJson(instance.path), + 'path': instance.path.toJson(), }; diff --git a/lib/core/commands/graphic_factory/graphic_factory.dart b/lib/core/commands/graphic_factory/graphic_factory.dart index 3b88cd8c..64ce4b6d 100644 --- a/lib/core/commands/graphic_factory/graphic_factory.dart +++ b/lib/core/commands/graphic_factory/graphic_factory.dart @@ -1,7 +1,7 @@ import 'dart:ui'; import 'package:flutter/material.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_model.dart'; class GraphicFactory { const GraphicFactory(); @@ -52,8 +52,7 @@ class GraphicFactory { ..strokeJoin = StrokeJoin.round; } - PathWithActionHistory createPathWithActionHistory() => - PathWithActionHistory(); + PathModel createPathModel() => PathModel(); PictureRecorder createPictureRecorder() => PictureRecorder(); diff --git a/lib/core/commands/path_with_action_history.dart b/lib/core/commands/path_with_action_history.dart deleted file mode 100644 index e7a022dc..00000000 --- a/lib/core/commands/path_with_action_history.dart +++ /dev/null @@ -1,93 +0,0 @@ -import 'dart:ui'; - -import 'package:collection/collection.dart'; - -import 'package:paintroid/core/json_serialization/converter/path_action_converter.dart'; -import 'package:paintroid/core/json_serialization/converter/path_with_action_history_converter.dart'; - -class PathWithActionHistory { - PathWithActionHistory(); - - final path = Path(); - - @PathActionConverter() - final actions = []; - - void moveTo(double x, double y) { - actions.add(MoveToAction(x, y)); - path.moveTo(x, y); - } - - void lineTo(double x, double y) { - actions.add(LineToAction(x, y)); - path.lineTo(x, y); - } - - void close() { - actions.add(const CloseAction()); - path.close(); - } - - Map toJson() { - return const PathWithActionHistoryConverter().toJson(this); - } - - factory PathWithActionHistory.fromJson(Map json) { - return const PathWithActionHistoryConverter().fromJson(json); - } - - @override - bool operator ==(Object other) { - if (other is PathWithActionHistory) { - return const ListEquality().equals(actions, other.actions); - } - return false; - } - - @override - int get hashCode => const ListEquality().hash(actions); -} - -abstract class PathAction { - const PathAction(); -} - -class MoveToAction extends PathAction { - final double x; - final double y; - - const MoveToAction(this.x, this.y); - - @override - bool operator ==(Object other) { - if (other is MoveToAction) { - return x == other.x && y == other.y; - } - return false; - } - - @override - int get hashCode => Object.hash(x, y); -} - -class LineToAction extends PathAction { - final double x; - final double y; - - const LineToAction(this.x, this.y); - - @override - bool operator ==(Object other) { - if (other is LineToAction) { - return x == other.x && y == other.y; - } - return false; - } - - @override - int get hashCode => Object.hash(x, y); -} - -class CloseAction extends PathAction { - const CloseAction(); -} diff --git a/lib/core/json_serialization/converter/path_action_converter.dart b/lib/core/json_serialization/converter/path_action_converter.dart deleted file mode 100644 index 9586bf05..00000000 --- a/lib/core/json_serialization/converter/path_action_converter.dart +++ /dev/null @@ -1,45 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -import 'package:paintroid/core/commands/path_with_action_history.dart'; -import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart'; - -class PathActionConverter - implements JsonConverter> { - const PathActionConverter(); - - @override - PathAction fromJson(Map json) { - switch (json['type'] as String) { - case SerializerType.MOVE_TO_ACTION: - return MoveToAction(json['x'] as double, json['y'] as double); - case SerializerType.LINE_TO_ACTION: - return LineToAction(json['x'] as double, json['y'] as double); - case SerializerType.CLOSE_ACTION: - return const CloseAction(); - default: - return const CloseAction(); - } - } - - @override - Map toJson(PathAction action) { - switch (action.runtimeType) { - case == MoveToAction: - action as MoveToAction; - return { - 'type': SerializerType.MOVE_TO_ACTION, - 'x': action.x, - 'y': action.y, - }; - case == LineToAction: - action as LineToAction; - return { - 'type': SerializerType.LINE_TO_ACTION, - 'x': action.x, - 'y': action.y, - }; - default: - return {'type': SerializerType.CLOSE_ACTION}; - } - } -} diff --git a/lib/core/json_serialization/converter/path_with_action_history_converter.dart b/lib/core/json_serialization/converter/path_with_action_history_converter.dart deleted file mode 100644 index 740c1acf..00000000 --- a/lib/core/json_serialization/converter/path_with_action_history_converter.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -import 'package:paintroid/core/commands/path_with_action_history.dart'; -import 'package:paintroid/core/json_serialization/converter/path_action_converter.dart'; - -class PathWithActionHistoryConverter - implements JsonConverter> { - const PathWithActionHistoryConverter(); - - @override - PathWithActionHistory fromJson(Map json) { - var pathWithActionHistory = PathWithActionHistory(); - var actionsJson = json['actions'] as List; - for (var actionJson in actionsJson) { - var action = const PathActionConverter() - .fromJson(actionJson as Map); - - if (action is MoveToAction) { - pathWithActionHistory.moveTo(action.x, action.y); - } else if (action is LineToAction) { - pathWithActionHistory.lineTo(action.x, action.y); - } else if (action is CloseAction) { - pathWithActionHistory.close(); - } - } - return pathWithActionHistory; - } - - @override - Map toJson(PathWithActionHistory pathWithActionHistory) => { - 'actions': pathWithActionHistory.actions - .map((action) => const PathActionConverter().toJson(action)) - .toList(), - }; -} diff --git a/lib/core/json_serialization/versioning/serializer_version.dart b/lib/core/json_serialization/versioning/serializer_version.dart index 28d88e89..14d225bd 100644 --- a/lib/core/json_serialization/versioning/serializer_version.dart +++ b/lib/core/json_serialization/versioning/serializer_version.dart @@ -12,6 +12,7 @@ class SerializerVersion { static const int CLIPBOARD_COMMAND_VERSION = Version.v1; static const int DELETE_REGION_COMMAND_VERSION = Version.v1; static const int COLOR_CHANGED_COMMAND_VERSION = Version.v1; + static const int PATH_MODEL_VERSION = Version.v1; } class Version { diff --git a/lib/core/json_serialization/versioning/version_strategy.dart b/lib/core/json_serialization/versioning/version_strategy.dart index 42bf991e..534aa23c 100644 --- a/lib/core/json_serialization/versioning/version_strategy.dart +++ b/lib/core/json_serialization/versioning/version_strategy.dart @@ -24,6 +24,7 @@ abstract class IVersionStrategy { int getDeleteRegionCommandVersion(); int getColorChangedCommandVersion(); + int getPathModelVersion(); } class ProductionVersionStrategy implements IVersionStrategy { @@ -69,6 +70,9 @@ class ProductionVersionStrategy implements IVersionStrategy { @override int getColorChangedCommandVersion() => SerializerVersion.COLOR_CHANGED_COMMAND_VERSION; + + @override + int getPathModelVersion() => SerializerVersion.PATH_MODEL_VERSION; } class VersionStrategyManager { diff --git a/lib/core/models/path_actions/close_action.dart b/lib/core/models/path_actions/close_action.dart new file mode 100644 index 00000000..c56f61bc --- /dev/null +++ b/lib/core/models/path_actions/close_action.dart @@ -0,0 +1,21 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart'; +import 'package:paintroid/core/models/path_actions/path_action.dart'; + +part 'close_action.g.dart'; + +@JsonSerializable() +class CloseAction extends PathAction { + const CloseAction(); + + factory CloseAction.fromJson(Map json) => const CloseAction(); + + @override + Map toJson() => {'type': SerializerType.CLOSE_ACTION}; + + @override + bool operator ==(Object other) => other is CloseAction; + + @override + int get hashCode => runtimeType.hashCode; +} diff --git a/lib/core/models/path_actions/close_action.g.dart b/lib/core/models/path_actions/close_action.g.dart new file mode 100644 index 00000000..15fc55f3 --- /dev/null +++ b/lib/core/models/path_actions/close_action.g.dart @@ -0,0 +1,12 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'close_action.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CloseAction _$CloseActionFromJson(Map json) => CloseAction(); + +Map _$CloseActionToJson(CloseAction instance) => + {}; diff --git a/lib/core/models/path_actions/line_to_action.dart b/lib/core/models/path_actions/line_to_action.dart new file mode 100644 index 00000000..d5d2fbd8 --- /dev/null +++ b/lib/core/models/path_actions/line_to_action.dart @@ -0,0 +1,27 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart'; +import 'package:paintroid/core/models/path_actions/path_action.dart'; + +part 'line_to_action.g.dart'; + +@JsonSerializable() +class LineToAction extends PathAction { + final double x; + final double y; + + const LineToAction(this.x, this.y); + + factory LineToAction.fromJson(Map json) => + _$LineToActionFromJson(json); + + @override + Map toJson() => + _$LineToActionToJson(this)..['type'] = SerializerType.LINE_TO_ACTION; + + @override + bool operator ==(Object other) => + other is LineToAction && x == other.x && y == other.y; + + @override + int get hashCode => Object.hash(x, y); +} diff --git a/lib/core/models/path_actions/line_to_action.g.dart b/lib/core/models/path_actions/line_to_action.g.dart new file mode 100644 index 00000000..67bc8260 --- /dev/null +++ b/lib/core/models/path_actions/line_to_action.g.dart @@ -0,0 +1,18 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'line_to_action.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +LineToAction _$LineToActionFromJson(Map json) => LineToAction( + (json['x'] as num).toDouble(), + (json['y'] as num).toDouble(), + ); + +Map _$LineToActionToJson(LineToAction instance) => + { + 'x': instance.x, + 'y': instance.y, + }; diff --git a/lib/core/models/path_actions/move_to_action.dart b/lib/core/models/path_actions/move_to_action.dart new file mode 100644 index 00000000..6ea61b45 --- /dev/null +++ b/lib/core/models/path_actions/move_to_action.dart @@ -0,0 +1,27 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart'; +import 'package:paintroid/core/models/path_actions/path_action.dart'; + +part 'move_to_action.g.dart'; + +@JsonSerializable() +class MoveToAction extends PathAction { + final double x; + final double y; + + const MoveToAction(this.x, this.y); + + factory MoveToAction.fromJson(Map json) => + _$MoveToActionFromJson(json); + + @override + Map toJson() => + _$MoveToActionToJson(this)..['type'] = SerializerType.MOVE_TO_ACTION; + + @override + bool operator ==(Object other) => + other is MoveToAction && x == other.x && y == other.y; + + @override + int get hashCode => Object.hash(x, y); +} diff --git a/lib/core/models/path_actions/move_to_action.g.dart b/lib/core/models/path_actions/move_to_action.g.dart new file mode 100644 index 00000000..43d2a010 --- /dev/null +++ b/lib/core/models/path_actions/move_to_action.g.dart @@ -0,0 +1,18 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'move_to_action.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +MoveToAction _$MoveToActionFromJson(Map json) => MoveToAction( + (json['x'] as num).toDouble(), + (json['y'] as num).toDouble(), + ); + +Map _$MoveToActionToJson(MoveToAction instance) => + { + 'x': instance.x, + 'y': instance.y, + }; diff --git a/lib/core/models/path_actions/path_action.dart b/lib/core/models/path_actions/path_action.dart new file mode 100644 index 00000000..13d3db7c --- /dev/null +++ b/lib/core/models/path_actions/path_action.dart @@ -0,0 +1,24 @@ +import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart'; +import 'package:paintroid/core/models/path_actions/move_to_action.dart'; +import 'package:paintroid/core/models/path_actions/line_to_action.dart'; +import 'package:paintroid/core/models/path_actions/close_action.dart'; + +abstract class PathAction { + const PathAction(); + + factory PathAction.fromJson(Map json) { + final type = json['type'] as String; + switch (type) { + case SerializerType.MOVE_TO_ACTION: + return MoveToAction.fromJson(json); + case SerializerType.LINE_TO_ACTION: + return LineToAction.fromJson(json); + case SerializerType.CLOSE_ACTION: + return const CloseAction(); + default: + return const CloseAction(); + } + } + + Map toJson(); +} diff --git a/lib/core/models/path_model.dart b/lib/core/models/path_model.dart new file mode 100644 index 00000000..67b9c644 --- /dev/null +++ b/lib/core/models/path_model.dart @@ -0,0 +1,207 @@ +import 'dart:typed_data'; +import 'dart:ui'; +import 'package:collection/collection.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:paintroid/core/models/path_actions/path_action.dart'; +import 'package:paintroid/core/models/path_actions/move_to_action.dart'; +import 'package:paintroid/core/models/path_actions/line_to_action.dart'; +import 'package:paintroid/core/models/path_actions/close_action.dart'; +import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart'; +import 'package:paintroid/core/json_serialization/versioning/version_strategy.dart'; + +part 'path_model.g.dart'; + +@JsonSerializable(explicitToJson: true) +class PathModel { + final int version; + + PathModel({ + int? version, + }) : _path = Path(), + version = version ?? VersionStrategyManager.strategy.getPathModelVersion(); + + final Path _path; + Path get nativePath => _path; + final List actions = []; + + PathFillType get fillType => _path.fillType; + + set fillType(PathFillType value) => _path.fillType = value; + + void moveTo(double x, double y) { + actions.add(MoveToAction(x, y)); + _path.moveTo(x, y); + } + + void lineTo(double x, double y) { + actions.add(LineToAction(x, y)); + _path.lineTo(x, y); + } + + void close() { + actions.add(const CloseAction()); + _path.close(); + } + + void reset() { + actions.clear(); + _path.reset(); + } + + void relativeMoveTo(double dx, double dy) { + _path.relativeMoveTo(dx, dy); + } + + void relativeLineTo(double dx, double dy) { + _path.relativeLineTo(dx, dy); + } + + void quadraticBezierTo(double x1, double y1, double x2, double y2) { + _path.quadraticBezierTo(x1, y1, x2, y2); + } + + void relativeQuadraticBezierTo(double x1, double y1, double x2, double y2) { + _path.relativeQuadraticBezierTo(x1, y1, x2, y2); + } + + void cubicTo( + double x1, double y1, double x2, double y2, double x3, double y3) { + _path.cubicTo(x1, y1, x2, y2, x3, y3); + } + + void relativeCubicTo( + double x1, double y1, double x2, double y2, double x3, double y3) { + _path.relativeCubicTo(x1, y1, x2, y2, x3, y3); + } + + void conicTo(double x1, double y1, double x2, double y2, double w) { + _path.conicTo(x1, y1, x2, y2, w); + } + + void relativeConicTo(double x1, double y1, double x2, double y2, double w) { + _path.relativeConicTo(x1, y1, x2, y2, w); + } + + void arcTo(Rect rect, double startAngle, double sweepAngle, bool forceMoveTo) { + _path.arcTo(rect, startAngle, sweepAngle, forceMoveTo); + } + + void addRect(Rect rect) { + _path.addRect(rect); + } + + void addOval(Rect rect) { + _path.addOval(rect); + } + + void addArc(Rect rect, double startAngle, double sweepAngle) { + _path.addArc(rect, startAngle, sweepAngle); + } + + void addPolygon(List points, bool close) { + _path.addPolygon(points, close); + } + + void addRRect(RRect rrect) { + _path.addRRect(rrect); + } + + void addPath(Path path, Offset offset, {Float64List? matrix4}) { + _path.addPath(path, offset, matrix4: matrix4); + } + + void extendWithPath(Path path, Offset offset, {Float64List? matrix4}) { + _path.extendWithPath(path, offset, matrix4: matrix4); + } + + bool contains(Offset point) => _path.contains(point); + + Path shift(Offset offset) => _path.shift(offset); + + Path transform(Float64List matrix4) => _path.transform(matrix4); + + Rect getBounds() => _path.getBounds(); + + void arcToPoint(Offset arcEnd, + {Radius radius = Radius.zero, + double rotation = 0.0, + bool largeArc = false, + bool clockwise = true}) { + _path.arcToPoint(arcEnd, + radius: radius, + rotation: rotation, + largeArc: largeArc, + clockwise: clockwise); + } + + void relativeArcToPoint(Offset arcEndDelta, + {Radius radius = Radius.zero, + double rotation = 0.0, + bool largeArc = false, + bool clockwise = true}) { + _path.relativeArcToPoint(arcEndDelta, + radius: radius, + rotation: rotation, + largeArc: largeArc, + clockwise: clockwise); + } + + PathMetrics computeMetrics({bool forceClosed = false}) => + _path.computeMetrics(forceClosed: forceClosed); + + void addRSuperellipse(RSuperellipse rsuperellipse) { + _path.addRSuperellipse(rsuperellipse); + } + + static Path combine(PathOperation operation, Path path1, Path path2) => + Path.combine(operation, path1, path2); + + factory PathModel.fromJson(Map json) { + int? version = json['version'] as int?; + + switch (version) { + case Version.v1: + return _fromJsonV1(json); + case null: + return _fromJsonV1(json); + case Version.v2: + // For different versions of PathModel the deserialization + // has to be implemented manually. + // Autogenerated code can only be used for one version + default: + return _fromJsonV1(json); + } + } + + static PathModel _fromJsonV1(Map json) { + final model = PathModel(version: json['version'] as int?); + final actionsJson = json['actions'] as List; + for (var actionJson in actionsJson) { + final action = PathAction.fromJson(actionJson as Map); + if (action is MoveToAction) { + model.moveTo(action.x, action.y); + } else if (action is LineToAction) { + model.lineTo(action.x, action.y); + } else if (action is CloseAction) { + model.close(); + } + } + return model; + } + + Map toJson() => { + 'version': version, + 'actions': actions.map((e) => e.toJson()).toList(), + }; + + @override + bool operator ==(Object other) { + if (other is PathModel) { + return const ListEquality().equals(actions, other.actions); + } + return false; + } + + @override + int get hashCode => const ListEquality().hash(actions); +} diff --git a/lib/core/models/path_model.g.dart b/lib/core/models/path_model.g.dart new file mode 100644 index 00000000..29d09054 --- /dev/null +++ b/lib/core/models/path_model.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'path_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PathModel _$PathModelFromJson(Map json) => PathModel( + version: (json['version'] as num?)?.toInt(), + )..fillType = $enumDecode(_$PathFillTypeEnumMap, json['fillType']); + +Map _$PathModelToJson(PathModel instance) => { + 'version': instance.version, + 'fillType': _$PathFillTypeEnumMap[instance.fillType]!, + }; + +const _$PathFillTypeEnumMap = { + PathFillType.nonZero: 'nonZero', + PathFillType.evenOdd: 'evenOdd', +}; diff --git a/lib/core/tools/implementation/brush_tool.dart b/lib/core/tools/implementation/brush_tool.dart index 04478603..9a4287f2 100644 --- a/lib/core/tools/implementation/brush_tool.dart +++ b/lib/core/tools/implementation/brush_tool.dart @@ -3,7 +3,7 @@ import 'dart:ui'; import 'package:flutter/foundation.dart'; import 'package:paintroid/core/commands/graphic_factory/graphic_factory.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_model.dart'; import 'package:paintroid/core/tools/tool.dart'; class BrushTool extends Tool { @@ -12,7 +12,7 @@ class BrushTool extends Tool { bool isDrawing = false; @visibleForTesting - late PathWithActionHistory pathToDraw; + late PathModel pathToDraw; BrushTool({ required super.commandFactory, @@ -27,7 +27,7 @@ class BrushTool extends Tool { @override void onDown(Offset point, Paint paint) { isDrawing = true; - pathToDraw = graphicFactory.createPathWithActionHistory() + pathToDraw = graphicFactory.createPathModel() ..moveTo(point.dx, point.dy); Paint savedPaint = graphicFactory.copyPaint(paint); final command = commandFactory.createPathCommand( @@ -46,7 +46,7 @@ class BrushTool extends Tool { @override void onUp(Offset point, Paint paint) { isDrawing = false; - if (pathToDraw.path.getBounds().size == Size.zero) { + if (pathToDraw.getBounds().size == Size.zero) { pathToDraw.lineTo(point.dx, point.dy); pathToDraw.close(); } diff --git a/lib/core/tools/line_tool/line_tool.dart b/lib/core/tools/line_tool/line_tool.dart index f1c6e2f2..83d5e534 100644 --- a/lib/core/tools/line_tool/line_tool.dart +++ b/lib/core/tools/line_tool/line_tool.dart @@ -6,7 +6,7 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/line_command.dart'; import 'package:paintroid/core/commands/graphic_factory/graphic_factory.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_model.dart'; import 'package:paintroid/core/tools/line_tool/vertex.dart'; import 'package:paintroid/core/tools/line_tool/vertex_stack.dart'; import 'package:paintroid/core/tools/tool.dart'; @@ -192,8 +192,8 @@ class LineTool extends Tool with EquatableMixin { outgoingGhostPathCommand = null; } - PathWithActionHistory _createPath(Offset startPoint, Offset endPoint) { - var pathToDraw = graphicFactory.createPathWithActionHistory() + PathModel _createPath(Offset startPoint, Offset endPoint) { + var pathToDraw = graphicFactory.createPathModel() ..moveTo(startPoint.dx, startPoint.dy) ..lineTo(endPoint.dx, endPoint.dy); return pathToDraw; diff --git a/test/unit/command/command_factory_test.dart b/test/unit/command/command_factory_test.dart index 95f952dd..38966996 100644 --- a/test/unit/command/command_factory_test.dart +++ b/test/unit/command/command_factory_test.dart @@ -4,15 +4,15 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:paintroid/core/commands/command_factory/command_factory.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/path_command.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_model.dart'; void main() { - late PathWithActionHistory testPath; + late PathModel testPath; late Paint testPaint; late CommandFactory sut; setUp(() { - testPath = PathWithActionHistory(); + testPath = PathModel(); testPaint = Paint(); sut = const CommandFactory(); }); diff --git a/test/unit/command/draw_path_command_test.dart b/test/unit/command/draw_path_command_test.dart index 46570349..79472dcb 100644 --- a/test/unit/command/draw_path_command_test.dart +++ b/test/unit/command/draw_path_command_test.dart @@ -5,7 +5,7 @@ import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/path_command.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_model.dart'; import 'draw_path_command_test.mocks.dart'; @GenerateMocks([Canvas]) @@ -20,12 +20,12 @@ void main() { test( 'drawPath method is called on the Canvas with given Path and Paint objects', () { - final testPath = PathWithActionHistory(); + final testPath = PathModel(); final testPaint = Paint(); drawPath = PathCommand(testPath, testPaint); - when(mockCanvas.drawPath(testPath.path, testPaint)).thenReturn(null); + when(mockCanvas.drawPath(testPath.nativePath, testPaint)).thenReturn(null); drawPath.call(mockCanvas); - verify(mockCanvas.drawPath(testPath.path, testPaint)); + verify(mockCanvas.drawPath(testPath.nativePath, testPaint)); verifyNoMoreInteractions(mockCanvas); }, ); diff --git a/test/unit/serialization/command/line_command_serializer_test.dart b/test/unit/serialization/command/line_command_serializer_test.dart index 13483fc4..9f23e946 100644 --- a/test/unit/serialization/command/line_command_serializer_test.dart +++ b/test/unit/serialization/command/line_command_serializer_test.dart @@ -9,7 +9,7 @@ import '../utils/dummy_path_factory.dart'; void main() { group('Version 1', () { test('Test LineCommand serialization as sourcePath', () { - final originalPath = DummyPathFactory.createPathWithActionHistory(1); + final originalPath = DummyPathFactory.createPathModel(1); final originalPaint = DummyPaintFactory.createPaint(version: Version.v1); const startPoint = Offset(0, 0); const endPoint = Offset(1, 1); @@ -41,7 +41,7 @@ void main() { }); test('Test LineCommand serialization not as sourcePath', () { - final originalPath = DummyPathFactory.createPathWithActionHistory(1); + final originalPath = DummyPathFactory.createPathModel(1); final originalPaint = DummyPaintFactory.createPaint(version: Version.v1); const startPoint = Offset(0, 0); const endPoint = Offset(1, 1); diff --git a/test/unit/serialization/command/path_command_serializer_test.dart b/test/unit/serialization/command/path_command_serializer_test.dart index 2dc8ba91..9e3058e3 100644 --- a/test/unit/serialization/command/path_command_serializer_test.dart +++ b/test/unit/serialization/command/path_command_serializer_test.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/path_command.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_model.dart'; import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart'; import '../utils/dummy_command_factory.dart'; import '../utils/dummy_paint_factory.dart'; @@ -13,8 +13,8 @@ import '../utils/dummy_path_factory.dart'; void main() { group('Version 1', () { test('Test PathCommand serialization with one path', () { - PathWithActionHistory originalPath = - DummyPathFactory.createPathWithActionHistory(1); + PathModel originalPath = + DummyPathFactory.createPathModel(1); Paint originalPaint = DummyPaintFactory.createPaint(version: Version.v1); PathCommand command = DummyCommandFactory.createPathCommand( originalPath, @@ -37,8 +37,8 @@ void main() { }); test('Test PathCommand serialization with multiple paths', () { - PathWithActionHistory originalPath = - DummyPathFactory.createPathWithActionHistory(5); + PathModel originalPath = + DummyPathFactory.createPathModel(5); Paint originalPaint = DummyPaintFactory.createPaint(version: Version.v1); PathCommand command = DummyCommandFactory.createPathCommand( originalPath, diff --git a/test/unit/serialization/converter/path_action_converter_test.dart b/test/unit/serialization/converter/path_action_converter_test.dart index 67b413b3..dcd7da56 100644 --- a/test/unit/serialization/converter/path_action_converter_test.dart +++ b/test/unit/serialization/converter/path_action_converter_test.dart @@ -1,47 +1,47 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; -import 'package:paintroid/core/json_serialization/converter/path_action_converter.dart'; +import 'package:paintroid/core/models/path_actions/path_action.dart'; +import 'package:paintroid/core/models/path_actions/move_to_action.dart'; +import 'package:paintroid/core/models/path_actions/line_to_action.dart'; +import 'package:paintroid/core/models/path_actions/close_action.dart'; void main() { - const PathActionConverter converter = PathActionConverter(); - - test('Test converter for MoveToAction', () { + test('Test serialization for MoveToAction', () { double xExpected = 1.0; double yExpected = 2.0; MoveToAction moveToAction = MoveToAction(xExpected, yExpected); - var json = converter.toJson(moveToAction); + var json = moveToAction.toJson(); - PathAction deserializedMoveToAction = converter.fromJson(json); + PathAction deserializedMoveToAction = PathAction.fromJson(json); expect(deserializedMoveToAction, isA()); deserializedMoveToAction as MoveToAction; expect(moveToAction, equals(deserializedMoveToAction)); }); - test('Test converter for LineToAction', () { + test('Test serialization for LineToAction', () { double xExpected = 1.0; double yExpected = 2.0; LineToAction lineToAction = LineToAction(xExpected, yExpected); - var json = converter.toJson(lineToAction); + var json = lineToAction.toJson(); - PathAction deserializedLineToAction = converter.fromJson(json); + PathAction deserializedLineToAction = PathAction.fromJson(json); expect(deserializedLineToAction, isA()); deserializedLineToAction as LineToAction; expect(lineToAction, equals(deserializedLineToAction)); }); - test('Test converter for CloseAction', () { + test('Test serialization for CloseAction', () { CloseAction closeAction = const CloseAction(); - var json = converter.toJson(closeAction); + var json = closeAction.toJson(); - PathAction deserializedCloseAction = converter.fromJson(json); + PathAction deserializedCloseAction = PathAction.fromJson(json); expect(deserializedCloseAction, isA()); }); diff --git a/test/unit/serialization/converter/path_with_action_history_converter_test.dart b/test/unit/serialization/converter/path_with_action_history_converter_test.dart index 2e7ab69e..81e42570 100644 --- a/test/unit/serialization/converter/path_with_action_history_converter_test.dart +++ b/test/unit/serialization/converter/path_with_action_history_converter_test.dart @@ -1,42 +1,35 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; -import 'package:paintroid/core/json_serialization/converter/path_with_action_history_converter.dart'; +import 'package:paintroid/core/models/path_model.dart'; import '../utils/dummy_path_factory.dart'; void main() { - const PathWithActionHistoryConverter converter = - PathWithActionHistoryConverter(); + test('Test serialization for PathModel with one path', () { + PathModel path = DummyPathFactory.createPathModel(1); - test('Test converter for PathWithActionHistory with one path', () { - PathWithActionHistory path = - DummyPathFactory.createPathWithActionHistory(1); + var json = path.toJson(); - var json = converter.toJson(path); - - PathWithActionHistory deserializedPath = converter.fromJson(json); + PathModel deserializedPath = PathModel.fromJson(json); expect(path, equals(deserializedPath)); }); - test('Test converter for PathWithActionHistory with two paths', () { - PathWithActionHistory path = - DummyPathFactory.createPathWithActionHistory(2); + test('Test serialization for PathModel with two paths', () { + PathModel path = DummyPathFactory.createPathModel(2); - var json = converter.toJson(path); + var json = path.toJson(); - PathWithActionHistory deserializedPath = converter.fromJson(json); + PathModel deserializedPath = PathModel.fromJson(json); expect(path, equals(deserializedPath)); }); - test('Test converter for PathWithActionHistory with multiple paths', () { - PathWithActionHistory path = - DummyPathFactory.createPathWithActionHistory(10); + test('Test serialization for PathModel with multiple paths', () { + PathModel path = DummyPathFactory.createPathModel(10); - var json = converter.toJson(path); + var json = path.toJson(); - PathWithActionHistory deserializedPath = converter.fromJson(json); + PathModel deserializedPath = PathModel.fromJson(json); expect(path, equals(deserializedPath)); }); diff --git a/test/unit/serialization/utils/dummy_command_factory.dart b/test/unit/serialization/utils/dummy_command_factory.dart index 1dde6f9d..db2749de 100644 --- a/test/unit/serialization/utils/dummy_command_factory.dart +++ b/test/unit/serialization/utils/dummy_command_factory.dart @@ -8,7 +8,7 @@ import 'package:paintroid/core/commands/command_implementation/graphic/shape/ell import 'package:paintroid/core/commands/command_implementation/graphic/shape/heart_shape_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/shape/square_shape_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/shape/star_shape_command.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_model.dart'; import 'package:paintroid/core/enums/shape_style.dart'; import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart'; import 'package:paintroid/core/json_serialization/versioning/version_strategy.dart'; @@ -27,8 +27,8 @@ class DummyCommandFactory { DummyVersionStrategy(pathCommandVersion: version)); List commands = []; for (int i = 0; i < numberOfCommands; i++) { - PathWithActionHistory originalPath = - DummyPathFactory.createPathWithActionHistory(i * numberOfCommands); + PathModel originalPath = + DummyPathFactory.createPathModel(i * numberOfCommands); Paint originalPaint = DummyPaintFactory.createPaint(); PathCommand command = commandFactory.createPathCommand(originalPath, originalPaint); @@ -38,7 +38,7 @@ class DummyCommandFactory { } static PathCommand createPathCommand( - PathWithActionHistory path, + PathModel path, Paint paint, { int version = Version.v1, }) { @@ -48,7 +48,7 @@ class DummyCommandFactory { } static LineCommand createLineCommand( - PathWithActionHistory path, + PathModel path, Paint paint, Offset startPoint, Offset endPoint, { diff --git a/test/unit/serialization/utils/dummy_path_factory.dart b/test/unit/serialization/utils/dummy_path_factory.dart index 9588d0df..8772f092 100644 --- a/test/unit/serialization/utils/dummy_path_factory.dart +++ b/test/unit/serialization/utils/dummy_path_factory.dart @@ -1,14 +1,13 @@ -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_model.dart'; class DummyPathFactory { - static PathWithActionHistory createPathWithActionHistory( - int numberOfActions) { - PathWithActionHistory pathWithActionHistory = PathWithActionHistory(); + static PathModel createPathModel(int numberOfActions) { + PathModel pathModel = PathModel(); for (int i = 0; i < numberOfActions; i++) { - pathWithActionHistory.moveTo(i.toDouble(), i.toDouble() + 1); - pathWithActionHistory.lineTo(i.toDouble() + 2, i.toDouble() + 3); + pathModel.moveTo(i.toDouble(), i.toDouble() + 1); + pathModel.lineTo(i.toDouble() + 2, i.toDouble() + 3); } - pathWithActionHistory.close(); - return pathWithActionHistory; + pathModel.close(); + return pathModel; } } diff --git a/test/unit/serialization/utils/dummy_version_strategy.dart b/test/unit/serialization/utils/dummy_version_strategy.dart index 0ccc3a37..7429a9eb 100644 --- a/test/unit/serialization/utils/dummy_version_strategy.dart +++ b/test/unit/serialization/utils/dummy_version_strategy.dart @@ -14,6 +14,7 @@ class DummyVersionStrategy implements IVersionStrategy { final int deleteRegionCommandVersion; final int textCommandVersion; final int colorChangedCommandVersion; + final int pathModelVersion; DummyVersionStrategy({ this.pathCommandVersion = SerializerVersion.PATH_COMMAND_VERSION, @@ -33,6 +34,7 @@ class DummyVersionStrategy implements IVersionStrategy { this.textCommandVersion = SerializerVersion.TEXT_COMMAND_VERSION, this.colorChangedCommandVersion = SerializerVersion.COLOR_CHANGED_COMMAND_VERSION, + this.pathModelVersion = SerializerVersion.PATH_MODEL_VERSION, }); @override @@ -70,4 +72,7 @@ class DummyVersionStrategy implements IVersionStrategy { @override int getColorChangedCommandVersion() => colorChangedCommandVersion; + + @override + int getPathModelVersion() => pathModelVersion; } diff --git a/test/unit/tools/brush_tool_test.dart b/test/unit/tools/brush_tool_test.dart index ed516d63..dfe9e3a8 100644 --- a/test/unit/tools/brush_tool_test.dart +++ b/test/unit/tools/brush_tool_test.dart @@ -6,7 +6,9 @@ import 'package:paintroid/core/commands/command_factory/command_factory.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/path_command.dart'; import 'package:paintroid/core/commands/command_manager/command_manager.dart'; import 'package:paintroid/core/commands/graphic_factory/graphic_factory.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_actions/move_to_action.dart'; +import 'package:paintroid/core/models/path_actions/line_to_action.dart'; +import 'package:paintroid/core/models/path_actions/close_action.dart'; import 'package:paintroid/core/enums/tool_types.dart'; import 'package:paintroid/core/tools/implementation/brush_tool.dart'; diff --git a/test/unit/tools/clipboard_tool_test.mocks.dart b/test/unit/tools/clipboard_tool_test.mocks.dart index c7c26633..e7134661 100644 --- a/test/unit/tools/clipboard_tool_test.mocks.dart +++ b/test/unit/tools/clipboard_tool_test.mocks.dart @@ -41,10 +41,10 @@ import 'package:paintroid/core/commands/command_implementation/graphic/text_comm as _i10; import 'package:paintroid/core/commands/command_manager/command_manager.dart' as _i21; -import 'package:paintroid/core/commands/path_with_action_history.dart' as _i25; import 'package:paintroid/core/enums/bounding_box_action.dart' as _i18; import 'package:paintroid/core/enums/bounding_box_resize_action.dart' as _i19; import 'package:paintroid/core/enums/shape_style.dart' as _i26; +import 'package:paintroid/core/models/path_model.dart' as _i25; import 'package:paintroid/core/tools/bounding_box.dart' as _i17; import 'package:paintroid/core/tools/line_tool/vertex_stack.dart' as _i23; import 'package:paintroid/core/tools/tool_data.dart' as _i4; @@ -683,7 +683,7 @@ class MockCommandFactory extends _i1.Mock implements _i24.CommandFactory { @override _i5.PathCommand createPathCommand( - _i25.PathWithActionHistory? path, + _i25.PathModel? path, _i2.Paint? paint, { bool? isCursor = false, }) => @@ -711,7 +711,7 @@ class MockCommandFactory extends _i1.Mock implements _i24.CommandFactory { @override _i6.LineCommand createLineCommand( - _i25.PathWithActionHistory? path, + _i25.PathModel? path, _i2.Paint? paint, _i2.Offset? startPoint, _i2.Offset? endPoint, diff --git a/test/unit/tools/cursor_tool_test.dart b/test/unit/tools/cursor_tool_test.dart index a6199d30..13f1c20e 100644 --- a/test/unit/tools/cursor_tool_test.dart +++ b/test/unit/tools/cursor_tool_test.dart @@ -7,7 +7,8 @@ import 'package:paintroid/core/commands/command_factory/command_factory.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/path_command.dart'; import 'package:paintroid/core/commands/command_manager/command_manager.dart'; import 'package:paintroid/core/commands/graphic_factory/graphic_factory.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_actions/move_to_action.dart'; +import 'package:paintroid/core/models/path_actions/line_to_action.dart'; import 'package:paintroid/core/enums/tool_types.dart'; import 'package:paintroid/core/tools/implementation/cursor_tool.dart'; diff --git a/test/unit/tools/pipette_tool_test.mocks.dart b/test/unit/tools/pipette_tool_test.mocks.dart index c53ef426..e4c5c365 100644 --- a/test/unit/tools/pipette_tool_test.mocks.dart +++ b/test/unit/tools/pipette_tool_test.mocks.dart @@ -43,9 +43,9 @@ import 'package:paintroid/core/commands/command_manager/command_manager.dart' as _i20; import 'package:paintroid/core/commands/graphic_factory/graphic_factory.dart' as _i32; -import 'package:paintroid/core/commands/path_with_action_history.dart' as _i19; import 'package:paintroid/core/enums/shape_style.dart' as _i24; import 'package:paintroid/core/enums/tool_types.dart' as _i29; +import 'package:paintroid/core/models/path_model.dart' as _i19; import 'package:paintroid/core/providers/state/canvas_state_data.dart' as _i17; import 'package:paintroid/core/providers/state/canvas_state_provider.dart' as _i30; @@ -256,9 +256,8 @@ class _FakeColor_17 extends _i1.SmartFake implements _i16.Color { ); } -class _FakePathWithActionHistory_18 extends _i1.SmartFake - implements _i19.PathWithActionHistory { - _FakePathWithActionHistory_18( +class _FakePathModel_18 extends _i1.SmartFake implements _i19.PathModel { + _FakePathModel_18( Object parent, Invocation parentInvocation, ) : super( @@ -466,7 +465,7 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { @override _i4.PathCommand createPathCommand( - _i19.PathWithActionHistory? path, + _i19.PathModel? path, _i16.Paint? paint, { bool? isCursor = false, }) => @@ -494,7 +493,7 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { @override _i5.LineCommand createLineCommand( - _i19.PathWithActionHistory? path, + _i19.PathModel? path, _i16.Paint? paint, _i16.Offset? startPoint, _i16.Offset? endPoint, @@ -1250,20 +1249,19 @@ class MockGraphicFactory extends _i1.Mock implements _i32.GraphicFactory { ) as _i16.Paint); @override - _i19.PathWithActionHistory createPathWithActionHistory() => - (super.noSuchMethod( + _i19.PathModel createPathModel() => (super.noSuchMethod( Invocation.method( - #createPathWithActionHistory, + #createPathModel, [], ), - returnValue: _FakePathWithActionHistory_18( + returnValue: _FakePathModel_18( this, Invocation.method( - #createPathWithActionHistory, + #createPathModel, [], ), ), - ) as _i19.PathWithActionHistory); + ) as _i19.PathModel); @override _i16.PictureRecorder createPictureRecorder() => (super.noSuchMethod( diff --git a/test/unit/tools/text_tool_test.mocks.dart b/test/unit/tools/text_tool_test.mocks.dart index 7d9297a5..0ed7d780 100644 --- a/test/unit/tools/text_tool_test.mocks.dart +++ b/test/unit/tools/text_tool_test.mocks.dart @@ -42,10 +42,10 @@ import 'package:paintroid/core/commands/command_manager/command_manager.dart' as _i19; import 'package:paintroid/core/commands/graphic_factory/graphic_factory.dart' as _i27; -import 'package:paintroid/core/commands/path_with_action_history.dart' as _i18; import 'package:paintroid/core/enums/bounding_box_action.dart' as _i29; import 'package:paintroid/core/enums/bounding_box_resize_action.dart' as _i30; import 'package:paintroid/core/enums/shape_style.dart' as _i23; +import 'package:paintroid/core/models/path_model.dart' as _i18; import 'package:paintroid/core/tools/bounding_box.dart' as _i28; import 'package:paintroid/core/tools/line_tool/vertex_stack.dart' as _i21; import 'package:paintroid/core/tools/tool_data.dart' as _i3; @@ -269,9 +269,8 @@ class _FakeTextStyle_18 extends _i1.SmartFake implements _i17.TextStyle { super.toString(); } -class _FakePathWithActionHistory_19 extends _i1.SmartFake - implements _i18.PathWithActionHistory { - _FakePathWithActionHistory_19( +class _FakePathModel_19 extends _i1.SmartFake implements _i18.PathModel { + _FakePathModel_19( Object parent, Invocation parentInvocation, ) : super( @@ -479,7 +478,7 @@ class MockCommandFactory extends _i1.Mock implements _i22.CommandFactory { @override _i4.PathCommand createPathCommand( - _i18.PathWithActionHistory? path, + _i18.PathModel? path, _i16.Paint? paint, { bool? isCursor = false, }) => @@ -507,7 +506,7 @@ class MockCommandFactory extends _i1.Mock implements _i22.CommandFactory { @override _i5.LineCommand createLineCommand( - _i18.PathWithActionHistory? path, + _i18.PathModel? path, _i16.Paint? paint, _i16.Offset? startPoint, _i16.Offset? endPoint, @@ -1832,20 +1831,19 @@ class MockGraphicFactory extends _i1.Mock implements _i27.GraphicFactory { ) as _i16.Paint); @override - _i18.PathWithActionHistory createPathWithActionHistory() => - (super.noSuchMethod( + _i18.PathModel createPathModel() => (super.noSuchMethod( Invocation.method( - #createPathWithActionHistory, + #createPathModel, [], ), - returnValue: _FakePathWithActionHistory_19( + returnValue: _FakePathModel_19( this, Invocation.method( - #createPathWithActionHistory, + #createPathModel, [], ), ), - ) as _i18.PathWithActionHistory); + ) as _i18.PathModel); @override _i16.PictureRecorder createPictureRecorder() => (super.noSuchMethod( diff --git a/test/unit/tools/watercolor_tool_test.dart b/test/unit/tools/watercolor_tool_test.dart index df054d1e..a11cb67a 100644 --- a/test/unit/tools/watercolor_tool_test.dart +++ b/test/unit/tools/watercolor_tool_test.dart @@ -5,7 +5,9 @@ import 'package:paintroid/core/commands/command_factory/command_factory.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/path_command.dart'; import 'package:paintroid/core/commands/command_manager/command_manager.dart'; import 'package:paintroid/core/commands/graphic_factory/graphic_factory.dart'; -import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/models/path_actions/move_to_action.dart'; +import 'package:paintroid/core/models/path_actions/line_to_action.dart'; +import 'package:paintroid/core/models/path_actions/close_action.dart'; import 'package:paintroid/core/enums/tool_types.dart'; import 'package:paintroid/core/tools/implementation/watercolor_tool.dart';