aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs165
1 files changed, 114 insertions, 51 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs
index d00cf14fd..0ffc65fc0 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs
@@ -237,13 +237,7 @@ namespace Tango.PPC.Jobs.ViewModels
/// Gets or sets the add solid segment command.
/// </summary>
public RelayCommand<Int32> AddNewSegmentCommand { get; set; }
-
- /// <summary>
- /// Gets or sets the undo last color command.
- /// </summary>
- public RelayCommand<SegmentModel> UndoLastColorCommand { get; set; }
-
-
+
/// <summary>
/// Gets or sets the remove segment command.
/// </summary>
@@ -268,18 +262,12 @@ namespace Tango.PPC.Jobs.ViewModels
/// Gets or sets the replace brush stop command.
/// </summary>
public RelayCommand<BrushStop> ReplaceBrushStopCommand { get; set; }
-
- /// <summary>
- /// Gets or sets the twine catalog field tap command.
- /// </summary>
- //public RelayCommand<BrushStop> OpenCatalogCommand { get; set; }
-
+
/// <summary>
/// Gets or sets the dye command.
/// </summary>
public RelayCommand DyeCommand { get; set; }
-
-
+
/// <summary>
/// Gets or sets the export embroidery command.
/// </summary>
@@ -291,26 +279,22 @@ namespace Tango.PPC.Jobs.ViewModels
public RelayCommand JobModeSwitchCommand { get; set; }
+ public RelayCommand<SegmentsGroupModel> UngroupSegmentsCommand { get; set; }
+ public RelayCommand<SegmentsGroupModel> DeleteSegmentsGroupCommand { get; set; }
+
#endregion
#region collapsed mode commands
public RelayCommand InsertWhiteGapCommand { get; set; }
-
public RelayCommand ReverseCommand { get; set; }
-
public RelayCommand DeleteSegmentCommand { get; set; }
-
public RelayCommand RepeateSegmentCommand { get; set; }
-
public RelayCommand PasteCommand { get; set; }
-
public RelayCommand CopyCommand { get; set; }
-
public RelayCommand UndoCommand { get; set; }
-
public RelayCommand RedoCommand { get; set; }
-
+
#endregion
#region Constructors
@@ -351,7 +335,6 @@ namespace Tango.PPC.Jobs.ViewModels
//Initialize Commands
AddNewSegmentCommand = new RelayCommand<Int32>(AddNewSegment);
- UndoLastColorCommand = new RelayCommand<SegmentModel>(UndoLastColor);
RemoveSegmentCommand = new RelayCommand<SegmentModel>(RemoveSegment);
DuplicateSegmentCommand = new RelayCommand<SegmentModel>(DuplicateSegment);
@@ -368,7 +351,9 @@ namespace Tango.PPC.Jobs.ViewModels
InsertWhiteGapCommand = new RelayCommand(InsertWhiteGap);
ReverseCommand = new RelayCommand(Reverse);
DeleteSegmentCommand = new RelayCommand(DeleteSegments);
+ DeleteSegmentsGroupCommand = new RelayCommand<SegmentsGroupModel>(DeleteSegmentsGroup);
RepeateSegmentCommand = new RelayCommand(RepeateSegments);
+ UngroupSegmentsCommand = new RelayCommand<SegmentsGroupModel>(UngroupSegments);
PasteCommand = new RelayCommand(Paste);
CopyCommand = new RelayCommand(Copy);
UndoCommand = new RelayCommand(Undo);//(x) => { return UndoRedoManager.Instance.IsEnableUndoOperation(); }
@@ -479,16 +464,16 @@ namespace Tango.PPC.Jobs.ViewModels
LogManager.Log($"Job editing state = '{Job.JobEditingState}'.");
- if (Job.JobEditingState == BL.Enumerations.EditingStates.SampleDye && Job.JobSampleDyeStatus == BL.Enumerations.SampleDyeStatuses.PendingApproval)
- {
- LogManager.Log("Directing view to display sample dye region.");
- View.DisplaySampleDye();
- }
- else if (Job.JobEditingState == BL.Enumerations.EditingStates.FineTuning && Job.JobFineTuningStatus == BL.Enumerations.FineTuningStatuses.PendingApproval)
- {
- LogManager.Log("Directing view to display fine tuning region.");
- View.DisplayFineTuning();
- }
+ //if (Job.JobEditingState == BL.Enumerations.EditingStates.SampleDye && Job.JobSampleDyeStatus == BL.Enumerations.SampleDyeStatuses.PendingApproval)
+ //{
+ // LogManager.Log("Directing view to display sample dye region.");
+ // View.DisplaySampleDye();
+ //}
+ //else if (Job.JobEditingState == BL.Enumerations.EditingStates.FineTuning && Job.JobFineTuningStatus == BL.Enumerations.FineTuningStatuses.PendingApproval)
+ //{
+ // LogManager.Log("Directing view to display fine tuning region.");
+ // View.DisplayFineTuning();
+ //}
IsFullMode = true;
DyeCommand.RaiseCanExecuteChanged();
@@ -522,7 +507,7 @@ namespace Tango.PPC.Jobs.ViewModels
User = Job.User,
Machine = Job.Machine
};
-
+ Dictionary<string, SegmentsGroupModel> guidToGroup = new Dictionary<string, SegmentsGroupModel>();
foreach (var segm in Job.Segments)
{
if (Job.Version == 1 && segm.BrushStops.Count > 1)
@@ -565,6 +550,22 @@ namespace Tango.PPC.Jobs.ViewModels
IsInterSegment = segm.IsInterSegment,
Job = jobModel,
};
+ if(segm.SegmentsGroupGuid != null)
+ {
+ SegmentsGroupModel segmentsGroupModel;
+ if(guidToGroup.TryGetValue(segm.SegmentsGroupGuid, out segmentsGroupModel))
+ {
+ segmentsGroupModel.Segments.Add(segmentModel);
+ segmentModel.SegmentsGroupModel = segmentsGroupModel;
+ }
+ else
+ {
+ segmentsGroupModel = new SegmentsGroupModel() { GroupID = segm.SegmentsGroup.GroupIndex, Repeats = segm.SegmentsGroup.Repeats };
+ guidToGroup[segm.SegmentsGroupGuid] = segmentsGroupModel;
+ segmentsGroupModel.Segments.Add(segmentModel);
+ segmentModel.SegmentsGroupModel = segmentsGroupModel;
+ }
+ }
foreach (var brushStop in segm.BrushStops)
{
BrushStopModel brushStopModel = new BrushStopModel(brushStop, segmentModel, Job.Version);
@@ -575,14 +576,16 @@ namespace Tango.PPC.Jobs.ViewModels
jobModel.Segments.Add(segmentModel);
}
}
+
jobModel.InterSegmentLength = Job.EnableInterSegment ? Job.InterSegmentLength : 0;
jobModel.Segments.Last().IsLast = true;
+ jobModel.LoadGroupingSegments();
JobModel = jobModel;
- SegmentsCollectionView = CollectionViewSource.GetDefaultView(JobModel.Segments);
+ //create grouping
+ SegmentsCollectionView = CollectionViewSource.GetDefaultView(JobModel.GroupingSegments);
SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(SegmentModel.SegmentIndex), ListSortDirection.Ascending));
UndoRedoManager.Instance.ClearAll();
-
}
private void Job_NameChanged(object sender, string e)
@@ -701,12 +704,10 @@ namespace Tango.PPC.Jobs.ViewModels
{
var maxLength = Job.SpoolType.Length;
var maxRep = (maxLength == 0 ? 999 : (maxLength / JobModel.Length));
-
-
- var vm = await NotificationProvider.ShowDialog<RepeatJobViewVM>(new RepeatJobViewVM()
+
+ var vm = await NotificationProvider.ShowDialog<RepeatJobViewVM>(new RepeatJobViewVM("Repeat All", JobModel.NumberOfUnits)
{
- MaxRepeations = (int)maxRep,
- Repeats = JobModel.NumberOfUnits
+ MaxRepeations = (int)maxRep
});
if (vm.DialogResult)
@@ -805,13 +806,21 @@ namespace Tango.PPC.Jobs.ViewModels
NotificationProvider.ShowError("An error occurred while trying to add a new segment.");
}
}
-
- /// <summary>
- /// Undoes the last color.
- /// </summary>
- private void UndoLastColor(SegmentModel segment)
+
+ private async void RepeatSegmentsGroup( SegmentsGroupModel group)
{
+ var maxLength = 999;
+ var maxRep = (maxLength == 0 ? 999 : (maxLength / JobModel.Length));
+
+ var vm = await NotificationProvider.ShowDialog<RepeatJobViewVM>(new RepeatJobViewVM($"Edit \"Group {group.GroupID}\" Repeat", group.Repeats)
+ {
+ MaxRepeations = (int)maxRep
+ });
+ if (vm.DialogResult)
+ {
+ JobModel.NumberOfUnits = vm.Repeats;
+ }
}
/// <summary>
@@ -843,7 +852,32 @@ namespace Tango.PPC.Jobs.ViewModels
}
}
+ private async void DeleteSegmentsGroup(SegmentsGroupModel segmentsGroup)
+ {
+ if (JobModel.GroupingSegments.Count > 1)
+ {
+ try
+ {
+ if (await NotificationProvider.ShowQuestion("Are you sure you want to remove the selected group of segments?"))
+ {
+
+ UndoRedoManager.Instance.InsertAndExecuteCommand(new DeleteSegmentsGroupCommand(JobModel, segmentsGroup));
+ ArrangeSegmentsIndixes();
+ DyeCommand.RaiseCanExecuteChanged();
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Could not remove group of segments.");
+ await NotificationProvider.ShowError("An error occurred while trying to delete group of segments.");
+ }
+ }
+ else
+ {
+ await NotificationProvider.ShowInfo("A job must contain at least one color segment.");
+ }
+ }
/// <summary>
/// Duplicates the segment.
/// </summary>
@@ -1186,7 +1220,14 @@ namespace Tango.PPC.Jobs.ViewModels
private void RepeateSegments()
{
+ if ( (JobModel.Segments.ToList().Where(x => x.IsSelected).Count()) < 2)
+ return;
+ UndoRedoManager.Instance.InsertAndExecuteCommand(new RepeatCommand(JobModel));
+ }
+ private void UngroupSegments(SegmentsGroupModel segmentsGroup)
+ {
+ UndoRedoManager.Instance.InsertAndExecuteCommand(new UnGroupSegmentsCommand(JobModel, segmentsGroup));
}
private void Paste()
@@ -1240,12 +1281,17 @@ namespace Tango.PPC.Jobs.ViewModels
{
_db.BrushStops.Remove(x);
});
-
+ if(segment.SegmentsGroupGuid != null)
+ {
+ _db.SegmentsGroups.Remove(segment.SegmentsGroup);
+ }
_db.Segments.Remove(segment);
}
-
+
Job.Segments.Clear();
-
+
+ Dictionary<int, SegmentsGroup> groupIDToSegmentsGroupGuid = new Dictionary<int, SegmentsGroup>();
+
foreach (var segment in JobModel.Segments.OrderBy(x => x.SegmentIndex).ToList())
{
var dbSegment = new Segment();
@@ -1255,7 +1301,24 @@ namespace Tango.PPC.Jobs.ViewModels
dbSegment.Job = Job;
dbSegment.SegmentIndex = segment.SegmentIndex;
dbSegment.Length = segment.Length;
-
+ if(segment.IsGroupSegment)
+ {
+ SegmentsGroup dbSegmentsGroup;
+ if (false == groupIDToSegmentsGroupGuid.TryGetValue(segment.SegmentsGroupModel.GroupID, out dbSegmentsGroup))
+ {
+ dbSegmentsGroup = new SegmentsGroup();
+ dbSegmentsGroup.Guid = System.Guid.NewGuid().ToString();
+ dbSegmentsGroup.Repeats = segment.SegmentsGroupModel.Repeats;
+ dbSegmentsGroup.GroupIndex = segment.SegmentsGroupModel.GroupID;
+ _db.SegmentsGroups.Add(dbSegmentsGroup);
+ dbSegment.SegmentsGroup = dbSegmentsGroup;
+ groupIDToSegmentsGroupGuid[segment.SegmentsGroupModel.GroupID] = dbSegmentsGroup;
+ }
+ else
+ {
+ dbSegment.SegmentsGroup = dbSegmentsGroup;
+ }
+ }
_db.Segments.Add(dbSegment);
foreach (var stop in segment.BrushStops.OrderBy(x => x.StopIndex).ToList())