From 858a2b114f78c87883510e3627874c7632f81177 Mon Sep 17 00:00:00 2001 From: Roy Date: Sun, 18 Feb 2018 09:23:15 +0200 Subject: Developer redesign.. --- .../Views/JobView.xaml.cs | 140 +++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs new file mode 100644 index 000000000..a030cf885 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Windows.Threading; +using Tango.DragAndDrop; +using Tango.Integration.Observables; +using Tango.MachineStudio.Developer.Converters; +using Tango.MachineStudio.Developer.ViewModels; + +namespace Tango.MachineStudio.Developer.Views +{ + /// + /// Interaction logic for JobView.xaml + /// + public partial class JobView : UserControl + { + private MainViewVM _vm; + private DispatcherTimer _jobBrushTimer; + + public DraggingSurface DraggingSurface + { + get { return (DraggingSurface)GetValue(DraggingSurfaceProperty); } + set { SetValue(DraggingSurfaceProperty, value); } + } + public static readonly DependencyProperty DraggingSurfaceProperty = + DependencyProperty.Register("DraggingSurface", typeof(DraggingSurface), typeof(JobView), new PropertyMetadata(null)); + + public JobView() + { + InitializeComponent(); + + DraggingSurface = draggingSurface; + + this.Loaded += (x, y) => + { + _vm = DataContext as MainViewVM; + }; + + _jobBrushTimer = new DispatcherTimer(); + _jobBrushTimer.Interval = TimeSpan.FromSeconds(1); + _jobBrushTimer.Tick += _jobBrushTimer_Tick; + _jobBrushTimer.Start(); + } + + private void _jobBrushTimer_Tick(object sender, EventArgs e) + { + if (_vm != null && _vm.SelectedJob != null) + { + List segments = new List(); + foreach (var s in _vm.SelectedJob.Segments) + { + segments.Add(s); + + if (_vm.SelectedJob.EnableInterSegment && _vm.SelectedJob.Segments.IndexOf(s) != _vm.SelectedJob.Segments.Count - 1) + { + segments.Add(new Segment() + { + Length = _vm.SelectedJob.InterSegmentLength, + BrushStops = new System.Collections.ObjectModel.ObservableCollection() + { + new BrushStop() + { + Color = Colors.White, + } + }, + }); + } + } + + jobBrushList.ItemsSource = segments; + } + } + + private void OnDropAvailableGraph(object sender, DropEventArgs e) + { + if (e.Draggable.DataContext is TechMonitor) + { + _vm.OnDropAvailableGraph(e.Draggable.DataContext as TechMonitor); + } + } + + private void Offset_Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) + { + UpdateGradientBrushDisplay(); + } + + private void UpdateGradientBrushDisplay() + { + if (_vm.SelectedSegment != null) + { + SegmentToGradientStopsConverter converter = new SegmentToGradientStopsConverter(); + GradientStopCollection stops = converter.Convert(_vm.SelectedSegment, null, null, null) as GradientStopCollection; + gradientBrush.GradientStops = stops; + } + else + { + gradientBrush.GradientStops = new GradientStopCollection(); + } + } + + private void OnBrushStopBorderDrop(object sender, DropEventArgs e) + { + if (e.Draggable.DataContext is BrushStop) + { + _vm.OnDropBrushStop(e.Draggable.DataContext as BrushStop, e.Droppable.DataContext as BrushStop); + } + } + + private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + UpdateGradientBrushDisplay(); + } + + private void OnJobStartClick(object sender, RoutedEventArgs e) + { + + } + + private void HiveColorPickerControl_SelectedColorChanged(object sender, Color e) + { + UpdateGradientBrushDisplay(); + } + + private void Popup_MouseDown(object sender, MouseButtonEventArgs e) + { + e.Handled = true; + } + } +} -- cgit v1.3.1 From 8feeef663f8984c609cb3aa530d09ffcffda5709 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 19 Feb 2018 17:17:25 +0200 Subject: Working on new developer module... --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 8388608 -> 8388608 bytes .../Converters/BrushStopToOffsetLimitConverter.cs | 4 +- .../Converters/BrushStopToOffsetValueConverter.cs | 4 +- .../Converters/SegmentToBrushConverter.cs | 2 +- .../Converters/SegmentToBrushConverterMulti.cs | 2 +- .../Converters/SegmentToGradientStopsConverter.cs | 2 +- .../SegmentToGradientStopsConverterMulti.cs | 2 +- .../ViewModels/MainViewVM.cs | 488 +++++++++++++++------ .../Views/JobView.xaml | 87 +--- .../Views/JobView.xaml.cs | 13 +- .../Views/MachineJobSelectionView.xaml | 5 +- .../Views/MainView.xaml.cs | 8 +- .../Views/MachineView.xaml | 6 +- .../Resources/MaterialDesign.xaml | 87 +++- .../Tango.MachineStudio.Common.csproj | 4 + .../ObservableCollectionExtensions.cs | 13 + .../Observables/IObservableEntity.cs | 8 +- .../Observables/ObservableEntity.cs | 34 +- .../Observables/Partials/Configuration.cs | 16 +- .../Observables/Partials/Machine.cs | 2 +- .../Observables/Partials/MachineVersion.cs | 2 +- .../Tango.Integration/Printing/BrushStop.cs | 28 +- .../Tango.Integration/Printing/Job.cs | 8 +- .../Tango.Integration/Printing/Segment.cs | 6 +- 25 files changed, 551 insertions(+), 280 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 0e6d30aef..89b9bb6e2 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index cb15dbe51..064ee4ca7 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetLimitConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetLimitConverter.cs index 62d678888..96c44a5a0 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetLimitConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetLimitConverter.cs @@ -22,11 +22,11 @@ namespace Tango.MachineStudio.Developer.Converters if (stop != null && segment != null) { - if (segment.BrushStops.IndexOf(stop) == segment.BrushStops.Count - 1) + if (stop.IsLast) { return 100d; } - else if (segment.BrushStops.IndexOf(stop) == 0) + else if (stop.IsFirst) { return 0d; } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetValueConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetValueConverter.cs index d8ac744a9..d78ef0c8e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetValueConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetValueConverter.cs @@ -20,11 +20,11 @@ namespace Tango.MachineStudio.Developer.Converters if (stop != null && segment != null) { - if (segment.BrushStops.IndexOf(stop) == segment.BrushStops.Count - 1) + if (stop.IsLast) { return 100d; } - else if (segment.BrushStops.IndexOf(stop) == 0) + else if (stop.IsFirst) { return 0d; } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverter.cs index 8aef260ff..1ac498070 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverter.cs @@ -21,7 +21,7 @@ namespace Tango.MachineStudio.Developer.Converters GradientStopCollection stops = new GradientStopCollection(); - foreach (var stop in segment.BrushStops) + foreach (var stop in segment.BrushStops.OrderBy(x => x.StopIndex)) { stops.Add(new GradientStop(stop.Color, stop.OffsetPercent / 100d)); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverterMulti.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverterMulti.cs index 0248fd730..41c1dd4df 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverterMulti.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverterMulti.cs @@ -23,7 +23,7 @@ namespace Tango.MachineStudio.Developer.Converters { GradientStopCollection stops = new GradientStopCollection(); - foreach (var stop in segment.BrushStops) + foreach (var stop in segment.BrushStops.OrderBy(x => x.StopIndex)) { stops.Add(new GradientStop(stop.Color, stop.OffsetPercent / 100d)); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverter.cs index 37908c940..f28a0b594 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverter.cs @@ -20,7 +20,7 @@ namespace Tango.MachineStudio.Developer.Converters GradientStopCollection stops = new GradientStopCollection(); - foreach (var stop in segment.BrushStops) + foreach (var stop in segment.BrushStops.OrderBy(x => x.StopIndex)) { stops.Add(new GradientStop(stop.Color, stop.OffsetPercent / 100d)); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverterMulti.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverterMulti.cs index 68ff95a9c..c50fbb06c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverterMulti.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverterMulti.cs @@ -22,7 +22,7 @@ namespace Tango.MachineStudio.Developer.Converters { GradientStopCollection stops = new GradientStopCollection(); - foreach (var stop in segment.BrushStops) + foreach (var stop in segment.BrushStops.OrderBy(x => x.StopIndex)) { stops.Add(new GradientStop(stop.Color, stop.OffsetPercent / 100d)); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 5c5531063..c8a6aa89f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -36,6 +36,8 @@ using Tango.MachineStudio.Developer.Navigation; using System.Data.Entity; using Tango.MachineStudio.Common.Authentication; using DeepEqual.Syntax; +using System.ComponentModel; +using System.Windows.Data; namespace Tango.MachineStudio.Developer.ViewModels { @@ -45,6 +47,8 @@ namespace Tango.MachineStudio.Developer.ViewModels /// public class MainViewVM : ViewModel, IShutdownRequestBlocker { + private static object _syncLock = new object(); + private INotificationProvider _notification; private TimeSpan _runningJobEstimatedDuration; private Dictionary _controllers; @@ -52,9 +56,9 @@ namespace Tango.MachineStudio.Developer.ViewModels private JobHandler _jobHandler; private DeveloperNavigationManager _navigation; private ObservablesContext _dbJobContext; - private Job _jobFromList; private bool _blockInvalidateCommands; private IAuthenticationProvider _authentication; + private ObservablesContext _machineDBContext; #region Properties @@ -103,7 +107,7 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _selectedMachine = value; - OnMachineChanged(); + OnSelectedMachineChanged(); RaisePropertyChangedAuto(); InvalidateRelayCommands(); @@ -136,6 +140,21 @@ namespace Tango.MachineStudio.Developer.ViewModels { _rmlProcessParametersTablesGroup = value; RaisePropertyChangedAuto(); OnProcessParametersTableGroupChanged(); } } + public void OnDropSegment(Segment dragged, Segment dropped) + { + dragged.SegmentIndex = dropped.SegmentIndex; + dropped.SegmentIndex++; + + int index = 1; + + foreach (var segment in ActiveJob.Segments.OrderBy(x => x.SegmentIndex)) + { + segment.SegmentIndex = index++; + } + + SegmentsCollectionView.Refresh(); + } + private ObservableCollection _groupsHistory; /// /// Gets or sets the RML process parameters groups history. @@ -166,20 +185,31 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _selectedProcessParametersTable = value; RaisePropertyChangedAuto(); OnSelectedParametersTableChanged(); } } - private Job _selectedJob; + private Job _activeJob; /// /// Gets or sets the selected machine job. /// - public Job SelectedJob + public Job ActiveJob { - get { return _selectedJob; } + get { return _activeJob; } set { - _selectedJob = value; + _activeJob = value; RaisePropertyChangedAuto(); + OnActiveJobChanged(); } } + private Job _selectedMachineJob; + /// + /// Gets or sets the selected machine job. + /// + public Job SelectedMachineJob + { + get { return _selectedMachineJob; } + set { _selectedMachineJob = value; RaisePropertyChangedAuto(); } + } + private ObservableCollection _selectedJobs; /// /// Gets or sets the selected jobs. @@ -396,6 +426,52 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _runningJobSegments = value; RaisePropertyChangedAuto(); } } + private ICollectionView _jobsCollectionView; + /// + /// Gets or sets the jobs collection view. + /// + public ICollectionView JobsCollectionView + { + get { return _jobsCollectionView; } + set + { + _jobsCollectionView = value; + BindingOperations.EnableCollectionSynchronization(_jobsCollectionView, _syncLock); + + RaisePropertyChangedAuto(); + } + } + + private ICollectionView _segmentsCollectionView; + /// + /// Gets or sets the segments collection view. + /// + public ICollectionView SegmentsCollectionView + { + get { return _segmentsCollectionView; } + set + { + _segmentsCollectionView = value; + BindingOperations.EnableCollectionSynchronization(_segmentsCollectionView, _syncLock); + RaisePropertyChangedAuto(); + } + } + + private ICollectionView _brushStopsCollectionView; + /// + /// Gets or sets the brush stops collection view. + /// + public ICollectionView BrushStopsCollectionView + { + get { return _brushStopsCollectionView; } + set + { + _brushStopsCollectionView = value; + BindingOperations.EnableCollectionSynchronization(_brushStopsCollectionView, _syncLock); + RaisePropertyChangedAuto(); + } + } + #endregion #region Commands @@ -500,6 +576,16 @@ namespace Tango.MachineStudio.Developer.ViewModels /// public RelayCommand DuplicateJobCommand { get; set; } + /// + /// Gets or sets the duplicate segment command. + /// + public RelayCommand DuplicateSegmentCommand { get; set; } + + /// + /// Gets or sets the duplicate brush stop command. + /// + public RelayCommand DuplicateBrushStopCommand { get; set; } + #endregion #region Constructors @@ -527,6 +613,8 @@ namespace Tango.MachineStudio.Developer.ViewModels [PreferredConstructor] public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IMainView view, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation, IAuthenticationProvider authentication) : this(view) { + _machineDBContext = ObservablesContext.CreateDefault(); + SelectedJobs = new ObservableCollection(); _authentication = authentication; @@ -543,20 +631,22 @@ namespace Tango.MachineStudio.Developer.ViewModels ToggleSideBarCommand = new RelayCommand(() => IsSideBarOpened = !IsSideBarOpened); SaveProcessParametersCommand = new RelayCommand(SaveProcessParameters, () => SelectedRML != null && SelectedRML.ProcessParametersTablesGroups.Count > 0); SaveLiquidFactorsCommand = new RelayCommand(SaveLiquidFactors, () => SelectedRML != null); - AddSegmentCommand = new RelayCommand(AddSegment, () => SelectedJob != null); - RemoveSegmentCommand = new RelayCommand(RemoveSegment, () => SelectedSegment != null); + AddSegmentCommand = new RelayCommand(AddSegment, () => ActiveJob != null); + RemoveSegmentCommand = new RelayCommand(RemoveSelectedSegments, () => SelectedSegment != null); AddJobCommand = new RelayCommand(AddJob, () => SelectedMachine != null); - RemoveJobCommand = new RelayCommand(RemoveJob, () => SelectedJob != null); + RemoveJobCommand = new RelayCommand(RemoveSelectedJobs, () => SelectedMachineJob != null); AddBrushStopCommand = new RelayCommand(AddBrushStop, () => SelectedSegment != null); - RemoveBrushStopCommand = new RelayCommand(RemoveBrushStop, () => SelectedBrushStop != null); + RemoveBrushStopCommand = new RelayCommand(RemoveSelectedBrushStops, () => SelectedBrushStop != null); SaveJobCommand = new RelayCommand(SaveJob, () => SelectedMachine != null); DiscardJobCommand = new RelayCommand(DiscardJob, () => SelectedMachine != null); - StartJobCommand = new RelayCommand(StartJob, () => SelectedJob != null && !IsJobRunning); + StartJobCommand = new RelayCommand(StartJob, () => ActiveJob != null && !IsJobRunning); StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning); CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar); ExitFullScreenCommand = new RelayCommand(ExitFullScreen); - LoadJobCommand = new RelayCommand(LoadJob, () => SelectedJob != null); - DuplicateJobCommand = new RelayCommand(DuplicateJob, () => SelectedJob != null); + LoadJobCommand = new RelayCommand(LoadJob, () => SelectedMachineJob != null); + DuplicateJobCommand = new RelayCommand(DuplicateSelectedJobs, () => SelectedMachineJob != null); + DuplicateSegmentCommand = new RelayCommand(DuplicateSelectedSegments, () => SelectedSegment != null); + DuplicateBrushStopCommand = new RelayCommand(DuplicateSelectedBrushStops, () => SelectedBrushStop != null); ToggleCameraCommand = new RelayCommand(ToggleCamera); @@ -595,7 +685,7 @@ namespace Tango.MachineStudio.Developer.ViewModels private void SelectedMachine_Saved(object sender, EventArgs e) { InvalidateLiquidFactorsAndProcessTables(); - SelectedMachine.Reload(); + SelectedMachine.Reload(_machineDBContext); } /// @@ -603,7 +693,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// The source of the event. /// The instance containing the event data. - private void SelectedJob_LengthChanged(object sender, EventArgs e) + private void ActiveJob_LengthChanged(object sender, EventArgs e) { UpdateEstimatedDuration(); } @@ -639,6 +729,8 @@ namespace Tango.MachineStudio.Developer.ViewModels } SetSegmentBrushStopsLiquidVolumes(SelectedSegment); + + UpdateEstimatedDuration(); } /// @@ -663,6 +755,9 @@ namespace Tango.MachineStudio.Developer.ViewModels { SetSegmentBrushStopsLiquidVolumes(SelectedSegment); SelectedBrushStop = SelectedSegment.BrushStops.FirstOrDefault(); + + BrushStopsCollectionView = CollectionViewSource.GetDefaultView(SelectedSegment.BrushStops); + BrushStopsCollectionView.SortDescriptions.Add(new SortDescription(nameof(BrushStop.StopIndex), ListSortDirection.Ascending)); } } @@ -680,38 +775,45 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// Called when the machine has been changed /// - protected virtual void OnMachineChanged() + protected virtual void OnSelectedMachineChanged() { - InvalidateLiquidFactorsAndProcessTables(); + if (SelectedMachine != null) + { + ReloadMachine(); + JobsCollectionView = CollectionViewSource.GetDefaultView(SelectedMachine.Jobs); + JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); + InvalidateLiquidFactorsAndProcessTables(); + } + } + + private void ReloadMachine() + { + _machineDBContext.Dispose(); + _machineDBContext = ObservablesContext.CreateDefault(); + _machineDBContext.Configuration.LazyLoadingEnabled = true; + _selectedMachine = _machineDBContext.Machines.SingleOrDefault(x => x.Guid == _selectedMachine.Guid); + RaisePropertyChanged(nameof(SelectedMachine)); + + JobsCollectionView = CollectionViewSource.GetDefaultView(SelectedMachine.Jobs); + JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); } #endregion #region Private Methods - private async void DuplicateJob() + private void OnActiveJobChanged() { - if (SelectedJobs.Count > 0) + if (ActiveJob != null) { - using (_notification.PushTaskItem("Cloning selected jobs...")) - { - int index = SelectedMachine.Jobs.Max(x => x.JobIndex); - - foreach (var job in SelectedJobs) - { - var cloned = job.Clone(); - cloned.JobIndex = ++index; - SelectedMachine.Jobs.Add(cloned); - } - - await SelectedMachine.SaveAsync(); - } + SegmentsCollectionView = CollectionViewSource.GetDefaultView(ActiveJob.Segments); + SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Segment.SegmentIndex), ListSortDirection.Ascending)); } } - private async void LoadJob() + private void LoadJob() { - if (SelectedJob != null) + if (SelectedMachineJob != null) { SelectedSegments = new ObservableCollection(); SelectedBrushStops = new ObservableCollection(); @@ -726,33 +828,34 @@ namespace Tango.MachineStudio.Developer.ViewModels { //await Task.Factory.StartNew(() => //{ - _blockInvalidateCommands = false; + _blockInvalidateCommands = false; + + _dbJobContext = ObservablesContext.CreateDefault(); + _dbJobContext.Configuration.LazyLoadingEnabled = true; - _dbJobContext = ObservablesContext.CreateDefault(); - _dbJobContext.Configuration.LazyLoadingEnabled = true; + ColorSpaces = _dbJobContext.ColorSpaces.ToObservableCollection(); + Rmls = _dbJobContext.Rmls.ToObservableCollection(); - ColorSpaces = _dbJobContext.ColorSpaces.ToObservableCollection(); - Rmls = _dbJobContext.Rmls.ToObservableCollection(); + _activeJob = _dbJobContext.Jobs.SingleOrDefault(x => x.Guid == SelectedMachineJob.Guid); - _jobFromList = SelectedJob; - _selectedJob = _dbJobContext.Jobs.SingleOrDefault(x => x.Guid == SelectedJob.Guid); - _selectedRML = SelectedJob.Rml; + _selectedRML = ActiveJob.Rml; - _selectedSegment = SelectedJob.Segments.FirstOrDefault(); + _selectedSegment = ActiveJob.Segments.FirstOrDefault(); - SelectedJob.LengthChanged -= SelectedJob_LengthChanged; - SelectedJob.LengthChanged += SelectedJob_LengthChanged; + ActiveJob.LengthChanged -= ActiveJob_LengthChanged; + ActiveJob.LengthChanged += ActiveJob_LengthChanged; - SelectedJob = _selectedJob; - SelectedRML = _selectedRML; - SelectedSegment = _selectedSegment; + ActiveJob = _activeJob; - UpdateEstimatedDuration(); + SelectedRML = _selectedRML; + SelectedSegment = _selectedSegment; - _blockInvalidateCommands = false; - InvalidateRelayCommands(); + UpdateEstimatedDuration(); - InvokeUI(() => _navigation.NavigateTo(DeveloperNavigationView.JobView)); + _blockInvalidateCommands = false; + InvalidateRelayCommands(); + + InvokeUI(() => _navigation.NavigateTo(DeveloperNavigationView.JobView)); //}); } } @@ -760,45 +863,27 @@ namespace Tango.MachineStudio.Developer.ViewModels private async void SaveJob() { - if (SelectedJob != null) + if (ActiveJob != null) { using (_notification.PushTaskItem("Saving job to database...")) { - SelectedJob.LastUpdated = DateTime.UtcNow; - SelectedJob.Rml = SelectedRML; - await SelectedJob.SaveAsync(_dbJobContext); - _jobFromList = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == SelectedJob.Guid); - await _jobFromList.Reload(); - - foreach (var segment in _jobFromList.Segments) - { - await segment.Reload(); + ActiveJob.LastUpdated = DateTime.UtcNow; + ActiveJob.Rml = SelectedRML; - foreach (var stop in segment.BrushStops) - { - await stop.Reload(); - } - } + await ActiveJob.SaveAsync(_dbJobContext); + ReloadMachine(); + SelectedMachineJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == ActiveJob.Guid); } } } private void DiscardJob() { - //bool jobModified = !SelectedJob.WithDeepEqual(_jobFromList) - // .IgnoreSourceProperty(x => x.Machine) - // .IgnoreSourceProperty(x => x.JobRuns) - // .IgnoreSourceProperty(x => x.Parameters) - // .IgnoreSourceProperty(x => x.Rml) - // .IgnoreSourceProperty(x => x.User) - // .IgnoreSourceProperty(x => x.Segments) - // .Compare(); - - bool jobModified = !SelectedJob.CompareUsingJson(_jobFromList); + bool jobModified = !ActiveJob.CompareUsingJson(SelectedMachineJob); if (jobModified) { - if (_notification.ShowQuestion("This will discard the current job changes. Are you sue?")) + if (_notification.ShowQuestion("This will discard the current job changes. Are you sure?")) { _dbJobContext.Dispose(); _navigation.NavigateTo(DeveloperNavigationView.MachineJobSelectionView); @@ -914,14 +999,14 @@ namespace Tango.MachineStudio.Developer.ViewModels IsJobCompleted = false; IsJobRunning = true; ShowJobStatus = true; - RunningJob = SelectedJob; + RunningJob = ActiveJob; _runningJobEstimatedDuration = EstimatedDuration; RunningJobSegments = CreateRunningJobEffectiveSegments(RunningJob); _navigation.NavigateTo(DeveloperNavigationView.RunningJobView); - _jobHandler = MachineOperator.Print(SelectedJob, SelectedProcessParametersTable); + _jobHandler = MachineOperator.Print(ActiveJob, SelectedProcessParametersTable); _jobHandler.StatusReceived += (x, status) => { @@ -973,9 +1058,9 @@ namespace Tango.MachineStudio.Developer.ViewModels private void UpdateEstimatedDuration() { - if (SelectedJob != null && SelectedProcessParametersTable != null && SelectedProcessParametersTable.DyeingSpeed > 0) + if (ActiveJob != null && SelectedProcessParametersTable != null && SelectedProcessParametersTable.DyeingSpeed > 0) { - EstimatedDuration = TimeSpan.FromSeconds(SelectedJob.Length / (SelectedProcessParametersTable.DyeingSpeed / 100d)); + EstimatedDuration = TimeSpan.FromSeconds(ActiveJob.Length / (SelectedProcessParametersTable.DyeingSpeed / 100d)); } } @@ -1090,14 +1175,93 @@ namespace Tango.MachineStudio.Developer.ViewModels } } + private List CreateRunningJobEffectiveSegments(Job job) + { + List segments = new List(); + foreach (var s in job.Segments) + { + s.Completed = false; + s.Started = false; + segments.Add(s); + + if (job.EnableInterSegment && job.Segments.IndexOf(s) != job.Segments.Count - 1) + { + segments.Add(new Segment() + { + Length = job.InterSegmentLength, + BrushStops = new System.Collections.ObjectModel.ObservableCollection() + { + new BrushStop() + { + Color = Colors.White, + } + }, + Started = false, + Completed = false + }); + } + } + + return segments; + } + + #endregion + + #region Add / Remove / Duplicate Jobs, Segments & Brush Stops + + private void ArrangeSegmentsIndices() + { + int index = 1; + + foreach (var segment in ActiveJob.Segments.OrderBy(x => x.SegmentIndex)) + { + segment.SegmentIndex = index++; + } + + SegmentsCollectionView.Refresh(); + } + + private void ArrangeBrushStopsIndices() + { + int index = 0; + + foreach (var stop in SelectedSegment.BrushStops.OrderBy(x => x.StopIndex)) + { + stop.SetStopIndex(index++); + } + + if (SelectedSegment.BrushStops.Count > 1) + { + SelectedSegment.BrushStops.OrderBy(x => x.StopIndex).First().OffsetPercent = 0; + SelectedSegment.BrushStops.OrderBy(x => x.StopIndex).Last().OffsetPercent = 100; + } + + foreach (var stop in SelectedSegment.BrushStops.OrderBy(x => x.StopIndex)) + { + stop.RaiseStopIndex(); + stop.RaiseOffsetChanged(); + } + + BrushStopsCollectionView.Refresh(); + } + /// - /// Removes the selected segment. + /// Removes the selected segments. /// - private void RemoveSegment() + private void RemoveSelectedSegments() { - if (SelectedJob != null && SelectedSegment != null) + if (ActiveJob != null && SelectedSegment != null) { - SelectedJob.Segments.Remove(SelectedSegment); + if (_notification.ShowQuestion("Are you sure you want to delete the selected segments?")) + { + SelectedSegments.ToList().ForEach(x => + { + ActiveJob.Segments.Remove(x); + x.DefferedDelete(_dbJobContext); + }); + + ArrangeSegmentsIndices(); + } } } @@ -1106,31 +1270,46 @@ namespace Tango.MachineStudio.Developer.ViewModels /// private void AddSegment() { - if (SelectedJob != null) + if (ActiveJob != null) { Segment seg = new Segment(); seg.Name = "Untitled Segment"; - seg.Length = 1; - SelectedJob.Segments.Add(seg); + seg.Length = 10; + + if (ActiveJob.Segments.Count > 0) + { + seg.SegmentIndex = ActiveJob.Segments.Max(x => x.SegmentIndex) + 1; + } + else + { + seg.SegmentIndex = 1; + } + ActiveJob.Segments.Add(seg); SelectedSegment = seg; AddBrushStop(); + ArrangeSegmentsIndices(); } } /// - /// Removes the selected job. + /// Removes the selected jobs. /// - private async void RemoveJob() + private async void RemoveSelectedJobs() { - if (SelectedMachine != null && SelectedJob != null) + if (SelectedMachine != null && SelectedMachineJob != null) { if (_notification.ShowQuestion("Are you sure you want to delete the selected jobs?")) { SelectedJobs.ToList().ForEach(x => { - x.DefferedDelete(); + SelectedMachine.Jobs.Remove(x); + x.DefferedDelete(_machineDBContext); }); - await SelectedMachine.SaveAsync(); + + using (_notification.PushTaskItem("Removing selected jobs...")) + { + await SelectedMachine.SaveAsync(_machineDBContext); + } } } } @@ -1138,7 +1317,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// Adds a new job to the selected machine. /// - private void AddJob() + private async void AddJob() { if (SelectedMachine != null) { @@ -1151,9 +1330,14 @@ namespace Tango.MachineStudio.Developer.ViewModels newJob.CreationDate = DateTime.UtcNow; newJob.User = _authentication.CurrentUser; newJob.Rml = Adapter.Rmls.FirstOrDefault(); + newJob.WindingMethod = Adapter.WindingMethods.FirstOrDefault(); + newJob.Machine = SelectedMachine; - SelectedJob = newJob; + SelectedMachine.Jobs.Add(newJob); + await SelectedMachine.SaveAsync(_machineDBContext); + SelectedMachineJob = newJob; LoadJob(); + AddSegment(); } } } @@ -1161,18 +1345,20 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// Removes the selected brush stop. /// - private void RemoveBrushStop() + private void RemoveSelectedBrushStops() { if (SelectedBrushStop != null && SelectedSegment != null) { - SelectedSegment.BrushStops.Remove(SelectedBrushStop); - - if (SelectedSegment.BrushStops.Count > 1) + if (_notification.ShowQuestion("Are you sure you want to delete the selected colors?")) { - SelectedSegment.BrushStops.Last().OffsetPercent = 100; - } + SelectedBrushStops.ToList().ForEach(x => + { + SelectedSegment.BrushStops.Remove(x); + x.DefferedDelete(_dbJobContext); + }); - SelectedSegment.BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged()); + ArrangeBrushStopsIndices(); + } } } @@ -1184,44 +1370,78 @@ namespace Tango.MachineStudio.Developer.ViewModels if (SelectedSegment != null) { var stop = new BrushStop(); + + if (SelectedSegment.BrushStops.Count > 0) + { + stop.StopIndex = SelectedSegment.BrushStops.Max(x => x.StopIndex) + 1; + } + else + { + stop.StopIndex = 0; + } + stop.OffsetPercent = 100; stop.Segment = SelectedSegment; - stop.ColorSpace = Adapter.ColorSpaces.FirstOrDefault(); + stop.ColorSpace = _dbJobContext.ColorSpaces.FirstOrDefault(); stop.Color = Colors.Black; stop.SetLiquidVolumes(SelectedMachine.Configuration, SelectedRML, SelectedProcessParametersTable); SelectedSegment.BrushStops.Add(stop); SelectedSegment.BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged()); + ArrangeBrushStopsIndices(); } } - private List CreateRunningJobEffectiveSegments(Job job) + /// + /// Duplicates the selected brush stops. + /// + private void DuplicateSelectedBrushStops() { - List segments = new List(); - foreach (var s in job.Segments) + foreach (var stop in SelectedBrushStops.OrderBy(x => x.StopIndex)) { - s.Completed = false; - s.Started = false; - segments.Add(s); + var cloned = stop.Clone(); + cloned.StopIndex = SelectedSegment.BrushStops.Max(x => x.StopIndex) + 1; + SelectedSegment.BrushStops.Add(cloned); + } - if (job.EnableInterSegment && job.Segments.IndexOf(s) != job.Segments.Count - 1) + ArrangeBrushStopsIndices(); + } + + /// + /// Duplicates the selected segments. + /// + private void DuplicateSelectedSegments() + { + foreach (var segment in SelectedSegments.OrderBy(x => x.SegmentIndex)) + { + var cloned = segment.Clone(); + cloned.SegmentIndex = ActiveJob.Segments.Max(x => x.SegmentIndex) + 1; + ActiveJob.Segments.Add(cloned); + } + + ArrangeSegmentsIndices(); + } + + /// + /// Duplicates the selected jobs. + /// + private async void DuplicateSelectedJobs() + { + if (SelectedMachineJob != null) + { + using (_notification.PushTaskItem("Cloning selected jobs...")) { - segments.Add(new Segment() + int index = SelectedMachine.Jobs.Max(x => x.JobIndex); + + foreach (var job in SelectedJobs) { - Length = job.InterSegmentLength, - BrushStops = new System.Collections.ObjectModel.ObservableCollection() - { - new BrushStop() - { - Color = Colors.White, - } - }, - Started = false, - Completed = false - }); + var cloned = job.Clone(); + cloned.JobIndex = ++index; + SelectedMachine.Jobs.Add(cloned); + } + + await SelectedMachine.SaveAsync(_machineDBContext); } } - - return segments; } #endregion @@ -1311,17 +1531,9 @@ namespace Tango.MachineStudio.Developer.ViewModels /// The dropped stop. public void OnDropBrushStop(BrushStop draggedStop, BrushStop droppedStop) { - SelectedSegment.BrushStops.Swap(draggedStop, droppedStop); - - int tmpIndex = draggedStop.StopIndex; - draggedStop.StopIndex = droppedStop.StopIndex; - droppedStop.StopIndex = tmpIndex; - - if (SelectedSegment.BrushStops.Count > 1) - { - SelectedSegment.BrushStops.First().OffsetPercent = 0; - SelectedSegment.BrushStops.Last().OffsetPercent = 100; - } + draggedStop.SetStopIndex(droppedStop.StopIndex); + droppedStop.SetStopIndex(droppedStop.StopIndex + 1); + ArrangeBrushStopsIndices(); } /// @@ -1354,7 +1566,7 @@ namespace Tango.MachineStudio.Developer.ViewModels } SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid = SelectedMachine != null ? SelectedMachine.Guid : null; - SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid = SelectedJob != null ? SelectedJob.Guid : null; + SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid = ActiveJob != null ? ActiveJob.Guid : null; return Task.FromResult(true); } @@ -1374,7 +1586,7 @@ namespace Tango.MachineStudio.Developer.ViewModels if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid != null && SelectedMachine != null) { - SelectedJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid); + ActiveJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid); } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml index 35a30e91e..cf7af21d9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml @@ -75,39 +75,6 @@ Transparent - - - - - - + # @@ -333,13 +287,12 @@ - - + + - @@ -378,11 +331,11 @@ - + - + @@ -394,7 +347,7 @@ Name - + @@ -404,7 +357,7 @@ Winding Method - + @@ -415,8 +368,8 @@ Inter Segment - - + + @@ -428,7 +381,7 @@ Lubrication - + @@ -441,7 +394,7 @@ - + @@ -619,7 +572,7 @@ - + - + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 7e0ef2eb5..cd4fc1aeb 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -185,6 +185,10 @@ {38197109-8610-4d3f-92b9-16d48df94d7c} Tango.DAL.Remote + + {b112d89a-a106-41ae-a0c1-4abc84c477f5} + Tango.DragAndDrop + {de2f2b86-025b-4f26-83a4-38bd48224ed5} Tango.Editors diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObservableCollectionExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObservableCollectionExtensions.cs index d7161953f..948be3c4a 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObservableCollectionExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObservableCollectionExtensions.cs @@ -41,5 +41,18 @@ public static class ObservableCollectionExtensions collection[index1] = collection[index2]; collection[index2] = tmp; } + + /// + /// Removes the dragged element and inserts it after the dropped element position. + /// + /// + /// The collection. + /// The dragged element. + /// The dropped element. + public static void DragAndDrop(this ObservableCollection collection, T dragged, T dropped) + { + collection.Remove(dragged); + collection.Insert(collection.IndexOf(dropped), dragged); + } } diff --git a/Software/Visual_Studio/Tango.Integration/Observables/IObservableEntity.cs b/Software/Visual_Studio/Tango.Integration/Observables/IObservableEntity.cs index eb16d150d..15fb521ba 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/IObservableEntity.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/IObservableEntity.cs @@ -54,12 +54,12 @@ namespace Tango.Integration.Observables /// /// Attaches this observable to the proper DbSet. /// - void Attach(); + void Attach(ObservablesContext context = null); /// /// Detaches this observable from the proper DbSet. /// - void Detach(); + void Detach(ObservablesContext context = null); /// /// Saves the changes on this entity to database asynchronously. @@ -76,12 +76,12 @@ namespace Tango.Integration.Observables /// /// Deletes this entity from the database. /// - void Delete(); + void Delete(ObservablesContext context = null); /// /// Deletes this entity without saving changes to data base. /// - void DefferedDelete(); + void DefferedDelete(ObservablesContext context = null); /// /// Deletes this entity from the database. diff --git a/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs b/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs index d5b218453..f92d9dfa0 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs @@ -44,6 +44,7 @@ namespace Tango.Integration.Observables /// Gets or sets the entity identifier. /// [Column("ID")] + [JsonIgnore] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public Int32 ID { @@ -57,6 +58,7 @@ namespace Tango.Integration.Observables /// [Key] [Column("GUID")] + [JsonIgnore] public String Guid { get { return _guid; } @@ -121,17 +123,17 @@ namespace Tango.Integration.Observables /// /// Attaches this entity to the proper DbSet. /// - public virtual void Attach() + public virtual void Attach(ObservablesContext context = null) { - GetDbSet().Add(this as T); + GetDbSet(context).Add(this as T); } /// /// Detaches this observable from the proper DbSet. /// - public virtual void Detach() + public virtual void Detach(ObservablesContext context = null) { - GetDbSet().Remove(this as T); + GetDbSet(context).Remove(this as T); } /// @@ -150,15 +152,15 @@ namespace Tango.Integration.Observables /// Reloads this observable entity. /// /// - public Task Reload() + public Task Reload(ObservablesContext context) { - return ObservablesEntitiesAdapter.Instance.Context.Entry(this).ReloadAsync(); + return context.Entry(this).ReloadAsync(); } /// /// Deletes this entity from the database /// - public virtual void Delete() + public virtual void Delete(ObservablesContext context = null) { var delProp = this.GetType().GetProperty("Deleted"); @@ -169,7 +171,7 @@ namespace Tango.Integration.Observables } else { - GetDbSet().Remove(this as T); + GetDbSet(context).Remove(this as T); Save(); } } @@ -177,9 +179,9 @@ namespace Tango.Integration.Observables /// /// Deletes this entity without saving changes to data base. /// - public virtual void DefferedDelete() + public virtual void DefferedDelete(ObservablesContext context = null) { - GetDbSet().Remove(this as T); + GetDbSet(context).Remove(this as T); } /// @@ -193,17 +195,15 @@ namespace Tango.Integration.Observables }); } - /// - /// Gets the observable database set. - /// - /// - public DbSet GetDbSet() + public DbSet GetDbSet(ObservablesContext context) { + context = context != null ? context : ObservablesEntitiesAdapter.Instance.Context; + String tabelName = this.GetType().Name.PluralizeMVC(); var p = typeof(ObservablesContext).GetProperty(tabelName); if (p != null) { - var set1 = p.GetValue(ObservablesEntitiesAdapter.Instance.Context) as DbSet; + var set1 = p.GetValue(context) as DbSet; return set1; } else @@ -212,7 +212,7 @@ namespace Tango.Integration.Observables p = typeof(ObservablesContext).GetProperty(tabelName); if (p != null) { - var set2 = p.GetValue(ObservablesEntitiesAdapter.Instance.Context) as DbSet; + var set2 = p.GetValue(context) as DbSet; return set2; } } diff --git a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Configuration.cs b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Configuration.cs index c60102671..3622169c9 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Configuration.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Configuration.cs @@ -8,21 +8,21 @@ namespace Tango.Integration.Observables { public partial class Configuration { - public override void DefferedDelete() + public override void DefferedDelete(ObservablesContext context = null) { - IdsPacks.ToList().ForEach(x => x.DefferedDelete()); + IdsPacks.ToList().ForEach(x => x.DefferedDelete(context)); var machine_configurations = ObservablesEntitiesAdapter.Instance.MachinesConfigurations.Where(x => x.Configuration == this); - MachinesConfigurations.ToList().ForEach(x => x.DefferedDelete()); - base.DefferedDelete(); + MachinesConfigurations.ToList().ForEach(x => x.DefferedDelete(context)); + base.DefferedDelete(context); IdsPacks.Clear(); } - public override void Delete() + public override void Delete(ObservablesContext context = null) { - IdsPacks.ToList().ForEach(x => x.DefferedDelete()); + IdsPacks.ToList().ForEach(x => x.DefferedDelete(context)); var machine_configurations = ObservablesEntitiesAdapter.Instance.MachinesConfigurations.Where(x => x.Configuration == this); - MachinesConfigurations.ToList().ForEach(x => x.DefferedDelete()); - base.Delete(); + MachinesConfigurations.ToList().ForEach(x => x.DefferedDelete(context)); + base.Delete(context); IdsPacks.Clear(); } } diff --git a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Machine.cs b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Machine.cs index 850003e60..bb26acc39 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Machine.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Machine.cs @@ -12,7 +12,7 @@ namespace Tango.Integration.Observables /// /// Deletes this entity from the database /// - public override void Delete() + public override void Delete(ObservablesContext context = null) { foreach (var machine_config in MachinesConfigurations) { diff --git a/Software/Visual_Studio/Tango.Integration/Observables/Partials/MachineVersion.cs b/Software/Visual_Studio/Tango.Integration/Observables/Partials/MachineVersion.cs index c7d1f8321..18799b7ed 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/Partials/MachineVersion.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/Partials/MachineVersion.cs @@ -8,7 +8,7 @@ namespace Tango.Integration.Observables { public partial class MachineVersion { - public override void Delete() + public override void Delete(ObservablesContext context = null) { this.DefaultConfiguration.Delete(); base.Delete(); diff --git a/Software/Visual_Studio/Tango.Integration/Printing/BrushStop.cs b/Software/Visual_Studio/Tango.Integration/Printing/BrushStop.cs index ebc77e615..ae8aa0e37 100644 --- a/Software/Visual_Studio/Tango.Integration/Printing/BrushStop.cs +++ b/Software/Visual_Studio/Tango.Integration/Printing/BrushStop.cs @@ -37,7 +37,6 @@ namespace Tango.Integration.Observables set { _liquidVolumes = value; RaisePropertyChangedAuto(); } } - private Color _color; /// /// Gets or sets the brush stop color. /// @@ -45,13 +44,12 @@ namespace Tango.Integration.Observables [JsonIgnore] public Color Color { - get { return _color; } + get { return Color.FromRgb((byte)_red, (byte)_green,(byte)_blue); } set { - _color = value; - _red = _color.R; - _green = _color.G; - _blue = _color.B; + _red = value.R; + _green = value.G; + _blue = value.B; RaisePropertyChanged(nameof(Color)); } } @@ -62,7 +60,7 @@ namespace Tango.Integration.Observables [NotMapped] public int Index { - get { return Segment.BrushStops.IndexOf(this); } + get { return StopIndex; } } /// @@ -72,7 +70,7 @@ namespace Tango.Integration.Observables [JsonIgnore] public bool IsFirst { - get { return Segment.BrushStops.IndexOf(this) == 0; } + get { return StopIndex == 0; } } /// @@ -82,7 +80,7 @@ namespace Tango.Integration.Observables [JsonIgnore] public bool IsLast { - get { return Segment.BrushStops.IndexOf(this) == Segment.BrushStops.Count - 1; } + get { return StopIndex == Segment.BrushStops.Count - 1; } } /// @@ -146,6 +144,16 @@ namespace Tango.Integration.Observables } } + public void SetStopIndex(int index) + { + _stopindex = index; + } + + public void RaiseStopIndex() + { + StopIndex = _stopindex; + } + #endregion #region Override Methods @@ -229,8 +237,6 @@ namespace Tango.Integration.Observables _l = lab.L; _a = lab.A; _b = lab.B; - - _color = Color.FromRgb((byte)_red, (byte)_green, (byte)_blue); } #endregion diff --git a/Software/Visual_Studio/Tango.Integration/Printing/Job.cs b/Software/Visual_Studio/Tango.Integration/Printing/Job.cs index 1cc4865f2..49c5fbdae 100644 --- a/Software/Visual_Studio/Tango.Integration/Printing/Job.cs +++ b/Software/Visual_Studio/Tango.Integration/Printing/Job.cs @@ -124,7 +124,7 @@ namespace Tango.Integration.Observables { for (int i = 0; i < Segments.Count; i++) { - Segments[i].SegmentIndex = i; + Segments[i].SegmentIndex = i + 1; for (int j = 0; j < Segments[i].BrushStops.Count; j++) { @@ -146,11 +146,11 @@ namespace Tango.Integration.Observables return cloned; } - public override void DefferedDelete() + public override void DefferedDelete(ObservablesContext context = null) { - Segments.ToList().ForEach(x => x.DefferedDelete()); + Segments.ToList().ForEach(x => x.DefferedDelete(context)); Segments.Clear(); - base.DefferedDelete(); + base.DefferedDelete(context); } #endregion diff --git a/Software/Visual_Studio/Tango.Integration/Printing/Segment.cs b/Software/Visual_Studio/Tango.Integration/Printing/Segment.cs index 6213240ed..d3e50ec37 100644 --- a/Software/Visual_Studio/Tango.Integration/Printing/Segment.cs +++ b/Software/Visual_Studio/Tango.Integration/Printing/Segment.cs @@ -68,11 +68,11 @@ namespace Tango.Integration.Observables return cloned; } - public override void DefferedDelete() + public override void DefferedDelete(ObservablesContext context = null) { - BrushStops.ToList().ForEach(x => x.DefferedDelete()); + BrushStops.ToList().ForEach(x => x.DefferedDelete(context)); BrushStops.Clear(); - base.DefferedDelete(); + base.DefferedDelete(context); } } } -- cgit v1.3.1 From a794a5d088b425d7b41f87d7c3a43b904249e11e Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 19 Feb 2018 17:52:10 +0200 Subject: Working on developer module... --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 8388608 -> 8388608 bytes .../Tango.MachineStudio.Developer.csproj | 7 - .../ViewModelLocator.cs | 2 +- .../ViewModels/MainViewVM.cs | 251 +-- .../Views/JobView.xaml | 2 +- .../Views/JobView.xaml.cs | 8 - .../Views/MachineJobSelectionView.xaml | 4 +- .../Views/MainView.xaml | 2246 -------------------- .../Views/MainView.xaml.cs | 162 -- .../Observables/IObservableEntity.cs | 18 +- .../Observables/ObservableEntity.cs | 30 +- .../Observables/Partials/Machine.cs | 4 +- .../Observables/Partials/Segment.cs | 4 +- .../Tango.Integration/Printing/Job.cs | 4 +- 15 files changed, 68 insertions(+), 2674 deletions(-) delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 89b9bb6e2..24b24abfc 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 064ee4ca7..54bf7ba0d 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index eae234a8b..f986219e2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -136,9 +136,6 @@ MachineJobSelectionView.xaml - - MainView.xaml - GlobalVersionInfo.cs @@ -165,10 +162,6 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - Designer MSBuild:Compile diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs index 415643e3f..b397f1912 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs @@ -20,7 +20,7 @@ namespace Tango.MachineStudio.Developer { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); - SimpleIoc.Default.Register(() => MainView.Self); + //SimpleIoc.Default.Register(() => MainView.Self); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index c8a6aa89f..199183c12 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -45,14 +45,12 @@ namespace Tango.MachineStudio.Developer.ViewModels /// Represents the developer module main view, view model. /// /// - public class MainViewVM : ViewModel, IShutdownRequestBlocker + public class MainViewVM : ViewModel, IShutdownRequestBlocker { private static object _syncLock = new object(); private INotificationProvider _notification; private TimeSpan _runningJobEstimatedDuration; - private Dictionary _controllers; - private int _fullScreenGraphIndex; private JobHandler _jobHandler; private DeveloperNavigationManager _navigation; private ObservablesContext _dbJobContext; @@ -62,6 +60,16 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Properties + private ObservableCollection _machines; + /// + /// Gets or sets the machines. + /// + public ObservableCollection Machines + { + get { return _machines; } + set { _machines = value; RaisePropertyChangedAuto(); } + } + private ObservableCollection _colorSpaces; /// /// Gets or sets the color spaces. @@ -82,6 +90,15 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _rmls = value; RaisePropertyChangedAuto(); } } + private ObservableCollection _windingMethods; + + public ObservableCollection WindingMethods + { + get { return _windingMethods; } + set { _windingMethods = value; RaisePropertyChangedAuto(); } + } + + /// /// Gets or sets the application manager. /// @@ -92,11 +109,6 @@ namespace Tango.MachineStudio.Developer.ViewModels /// public IVideoCaptureProvider VideoCaptureProvider { get; set; } - /// - /// Gets or sets observable entites database the adapter. - /// - public ObservablesEntitiesAdapter Adapter { get; set; } - protected Machine _selectedMachine; /// /// Gets or sets the selected machine. @@ -286,26 +298,6 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _isSideBarOpened = value; RaisePropertyChangedAuto(); } } - private ObservableCollection _availableGraphs; - /// - /// Gets or sets the available sensors. - /// - public ObservableCollection AvailableGraphs - { - get { return _availableGraphs; } - set { _availableGraphs = value; RaisePropertyChangedAuto(); } - } - - private ObservableCollection _graphs; - /// - /// Gets or sets the collection of displayed graph controls. - /// - public ObservableCollection Graphs - { - get { return _graphs; } - set { _graphs = value; RaisePropertyChangedAuto(); } - } - private TimeSpan _estimatedDuration; /// /// Gets or sets the estimated duration for the selected job. @@ -556,16 +548,6 @@ namespace Tango.MachineStudio.Developer.ViewModels /// public RelayCommand CloseJobCompletionStatusCommand { get; set; } - /// - /// Gets or sets the toggle camera command. - /// - public RelayCommand ToggleCameraCommand { get; set; } - - /// - /// Gets or sets the exit full screen command. - /// - public RelayCommand ExitFullScreenCommand { get; set; } - /// /// Gets or sets the load job command. /// @@ -593,16 +575,9 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// Initializes a new instance of the class. /// - public MainViewVM(IMainView view) : base(view, true) + public MainViewVM() : base() { - if (!this.DesignMode) - { - Adapter = ObservablesEntitiesAdapter.Instance; - AvailableGraphs = Adapter.TechMonitors.ToObservableCollection(); - } - Graphs = new ObservableCollection(); - _controllers = new Dictionary(); } /// @@ -611,8 +586,13 @@ namespace Tango.MachineStudio.Developer.ViewModels /// The application manager. /// The notification provider. [PreferredConstructor] - public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IMainView view, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation, IAuthenticationProvider authentication) : this(view) + public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation, IAuthenticationProvider authentication) : this() { + using (var db = ObservablesContext.CreateDefault()) + { + Machines = db.Machines.ToObservableCollection(); + } + _machineDBContext = ObservablesContext.CreateDefault(); SelectedJobs = new ObservableCollection(); @@ -623,7 +603,6 @@ namespace Tango.MachineStudio.Developer.ViewModels _navigation = navigation; ApplicationManager = applicationManager; VideoCaptureProvider = videoCaptureProvider; - diagnosticsFrameProvider.FrameReceived += DiagnosticsFrameProvider_FrameReceived; //Initialize Commands... EditMachineCommand = new RelayCommand(EditMachine, () => SelectedMachine != null); @@ -642,14 +621,11 @@ namespace Tango.MachineStudio.Developer.ViewModels StartJobCommand = new RelayCommand(StartJob, () => ActiveJob != null && !IsJobRunning); StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning); CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar); - ExitFullScreenCommand = new RelayCommand(ExitFullScreen); LoadJobCommand = new RelayCommand(LoadJob, () => SelectedMachineJob != null); DuplicateJobCommand = new RelayCommand(DuplicateSelectedJobs, () => SelectedMachineJob != null); DuplicateSegmentCommand = new RelayCommand(DuplicateSelectedSegments, () => SelectedSegment != null); DuplicateBrushStopCommand = new RelayCommand(DuplicateSelectedBrushStops, () => SelectedBrushStop != null); - ToggleCameraCommand = new RelayCommand(ToggleCamera); - ApplicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged; } @@ -657,16 +633,6 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Event Handlers - /// - /// Handles the diagnostics provider frame received event. - /// - /// The sender. - /// The response. - private void DiagnosticsFrameProvider_FrameReceived(object sender, PushDiagnosticsResponse response) - { - PopulateDiagnosticsData(response); - } - /// /// Handles the application manager connected machine changes event. /// @@ -835,6 +801,7 @@ namespace Tango.MachineStudio.Developer.ViewModels ColorSpaces = _dbJobContext.ColorSpaces.ToObservableCollection(); Rmls = _dbJobContext.Rmls.ToObservableCollection(); + WindingMethods = _dbJobContext.WindingMethods.ToObservableCollection(); _activeJob = _dbJobContext.Jobs.SingleOrDefault(x => x.Guid == SelectedMachineJob.Guid); @@ -896,59 +863,6 @@ namespace Tango.MachineStudio.Developer.ViewModels } } - private void ClearGraphs() - { - _controllers.ToList().ForEach(x => x.Value.Clear()); - } - - private void PopulateDiagnosticsData(PushDiagnosticsResponse data) - { - foreach (var prop in data.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) - { - GraphControllerBase controller = null; - - if (_controllers.TryGetValue(prop.Name, out controller)) - { - if (controller is GraphController) - { - double[] arr = Enumerable.ToArray(prop.GetValue(data) as IEnumerable); - (controller as GraphController).PushData(arr); - } - else - { - DoubleArray[] arrayOfDoubles = Enumerable.ToArray(prop.GetValue(data) as IEnumerable); - (controller as GraphMultiController).PushData(arrayOfDoubles.Select(x => x.Data.ToList()).ToList()); - } - } - } - } - - private void ExitFullScreen() - { - if (FullScreenGraph != null) - { - FullScreenGraph.EnableToolBar = true; - Graphs.Insert(_fullScreenGraphIndex, FullScreenGraph); - FullScreenGraph = null; - } - } - - private void StartFullScreenGraph(IRealTimeGraph graph) - { - graph.EnableToolBar = false; - _fullScreenGraphIndex = Graphs.IndexOf(graph); - Graphs.Remove(graph); - FullScreenGraph = graph; - } - - private void ToggleCamera(CaptureDevice captureDevice) - { - if (captureDevice.Device != null) - { - captureDevice.IsStarted = !captureDevice.IsStarted; - } - } - private void CloseJobCompletionStatusBar() { _navigation.NavigateTo(DeveloperNavigationView.JobView); @@ -1138,15 +1052,9 @@ namespace Tango.MachineStudio.Developer.ViewModels g.Active = false; } - //String machineGuid = SelectedMachine.Guid; - //String rmlGuid = SelectedRML.Guid; - SelectedRML.ProcessParametersTablesGroups.Add(group); await SelectedRML.SaveAsync(); - //SelectedMachine = Adapter.Machines.SingleOrDefault(x => x.Guid == machineGuid); - //SelectedRML = Adapter.Rmls.SingleOrDefault(x => x.Guid == rmlGuid); - InvalidateLiquidFactorsAndProcessTables(); } } @@ -1329,8 +1237,8 @@ namespace Tango.MachineStudio.Developer.ViewModels newJob.Name = jobName; newJob.CreationDate = DateTime.UtcNow; newJob.User = _authentication.CurrentUser; - newJob.Rml = Adapter.Rmls.FirstOrDefault(); - newJob.WindingMethod = Adapter.WindingMethods.FirstOrDefault(); + newJob.Rml = _machineDBContext.Rmls.FirstOrDefault(); + newJob.WindingMethod = _machineDBContext.WindingMethods.FirstOrDefault(); newJob.Machine = SelectedMachine; SelectedMachine.Jobs.Add(newJob); @@ -1462,68 +1370,6 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Public Methods - /// - /// Add sensor graph from available sensors to displayed graphs. - /// - /// The sensor. - public void OnDropAvailableGraph(TechMonitor sensor) - { - if (Graphs.Count < 8) - { - IRealTimeGraph graphControl = null; - GraphControllerBase controller = null; - - if (!sensor.MultiChannel) - { - graphControl = new RealTimeGraphControl(); - controller = new GraphController(); - graphControl.Controller = controller; - } - else - { - graphControl = new RealTimeGraphMultiControl(); - controller = new GraphMultiController(); - - for (int i = 0; i < sensor.ChannelCount; i++) - { - var randomColor = new SolidColorBrush(Core.Helpers.ColorHelper.GetRandomColor()); - - (controller as GraphMultiController).AddSeries(new DataYSeries() - { - Name = sensor.Description.First().ToString() + (i + 1), - UseFillAndStroke = true, - Stroke = randomColor - }); - } - - graphControl.Controller = controller; - } - - graphControl.Tag = sensor; - graphControl.SensorName = sensor.Description; - graphControl.SensorUnits = sensor.Units; - graphControl.InnerGraph.Minimum = sensor.Min; - graphControl.InnerGraph.Maximum = sensor.Max; - graphControl.InnerGraph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(sensor.PointsPerFrame); - graphControl.GraphRemoveButtonPressed += (sender, _) => - { - RemoveGraph(sender as IRealTimeGraph); - }; - graphControl.GraphFullScreenButtonPressed += (sender, _) => - { - StartFullScreenGraph(sender as IRealTimeGraph); - }; - Graphs.Add(graphControl); - AvailableGraphs.Remove(sensor); - - _controllers.Add(sensor.Name, controller); - } - else - { - _notification.ShowInfo("The maximum number of real-time graphs is eight. Please remove a graph to add another."); - } - } - /// /// Switch the brush stop position in the segment. /// @@ -1536,19 +1382,6 @@ namespace Tango.MachineStudio.Developer.ViewModels ArrangeBrushStopsIndices(); } - /// - /// Removes the graph. - /// - /// The graph. - public void RemoveGraph(IRealTimeGraph graph) - { - var sensor = graph.Tag as TechMonitor; - _controllers.Remove(sensor.Name); - graph.InnerGraph.Dispose(); - Graphs.Remove(graph); - AvailableGraphs.Insert(0, sensor); - } - #endregion #region IShutdownRequestBlocker @@ -1575,20 +1408,20 @@ namespace Tango.MachineStudio.Developer.ViewModels #region IMainView - protected override void OnViewAttached() - { - base.OnViewAttached(); + //protected override void OnViewAttached() + //{ + // base.OnViewAttached(); - if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid != null) - { - SelectedMachine = Adapter.Machines.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid); - } + // //if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid != null) + // //{ + // // SelectedMachine = Adapter.Machines.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid); + // //} - if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid != null && SelectedMachine != null) - { - ActiveJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid); - } - } + // //if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid != null && SelectedMachine != null) + // //{ + // // ActiveJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid); + // //} + //} #endregion } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml index cf7af21d9..69f0fed5c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml @@ -357,7 +357,7 @@ Winding Method - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs index 41886357b..27ea3cae8 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs @@ -82,14 +82,6 @@ namespace Tango.MachineStudio.Developer.Views } } - private void OnDropAvailableGraph(object sender, DropEventArgs e) - { - if (e.Draggable.DataContext is TechMonitor) - { - _vm.OnDropAvailableGraph(e.Draggable.DataContext as TechMonitor); - } - } - private void Offset_Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { UpdateGradientBrushDisplay(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml index 8881e4f57..c07ddb95b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml @@ -31,7 +31,7 @@ TARGET MACHINE - + @@ -84,7 +84,7 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Job Completed Successfully - - - - - - - - - - - - - - - - - - - - - - - Job Failed To Complete - - - - - - - - - - - - - - - - - - - - - - - - - Job Aborted By User - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HISTORY - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SELECT MACHINE & MEDIA - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - MACHINE JOBS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Name - - - - - - - - - - Winding Method - - - - - - - - - - Inter Segment - - - - - - - - - - - - - Lubrication - - - - - - - - - - - - Description - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SEGMENTS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Name - - - - - - - - - Length - - - - - - - - - - - - - - - - - - - - - - - - - - - SEGMENT BRUSH - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Color Space - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ESTIMATED DURATION: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - USB CAMERAS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AVAILABLE GRAPHS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DRAG & DROP GRAPHS - - - - - - - - - - - - - - - - - - - - Display Graphs - - - - - - - - - - - - - - - - - Job Status - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - LIQUID FACTORS ( Max Nanolitter/CM ) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SELECT MACHINE & MEDIA - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press - 'Escape' - to exit full screen mode - - - - - - - - - - - diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs deleted file mode 100644 index 2bd36e449..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs +++ /dev/null @@ -1,162 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using Tango.Integration.Observables; -using Tango.DragAndDrop; -using Tango.MachineStudio.Developer.Converters; -using Tango.MachineStudio.Developer.ViewModels; -using System.Windows.Threading; -using Tango.SharedUI; - -namespace Tango.MachineStudio.Developer.Views -{ - /// - /// Interaction logic for MainView.xaml - /// - public partial class MainView : UserControl, IMainView - { - public static MainView Self { get; set; } - - private MainViewVM _vm; - private DispatcherTimer _jobBrushTimer; - - public DraggingSurface DraggingSurface - { - get { return (DraggingSurface)GetValue(DraggingSurfaceProperty); } - set { SetValue(DraggingSurfaceProperty, value); } - } - public static readonly DependencyProperty DraggingSurfaceProperty = - DependencyProperty.Register("DraggingSurface", typeof(DraggingSurface), typeof(MainView), new PropertyMetadata(null)); - - public event EventHandler ViewAttached; - - public MainView() - { - Self = this; - - InitializeComponent(); - - DraggingSurface = draggingSurface; - this.Loaded += (x, y) => - { - _vm = DataContext as MainViewVM; - ViewAttached?.Invoke(this, this); - }; - - chkGraphs.Checked += (x, y) => - { - graphRowDefinition.Height = new GridLength(440, GridUnitType.Pixel); - //listCameras.Width = 240; - //dockCameras.Width = 270; - //dockCameras.Height = 600; - }; - chkGraphs.Unchecked += (x, y) => - { - graphRowDefinition.Height = new GridLength(80, GridUnitType.Pixel); - //listCameras.Width = double.NaN; - //dockCameras.Width = 330; - //dockCameras.Height = 850; - }; - - _jobBrushTimer = new DispatcherTimer(); - _jobBrushTimer.Interval = TimeSpan.FromSeconds(1); - _jobBrushTimer.Tick += _jobBrushTimer_Tick; - _jobBrushTimer.Start(); - } - - private void _jobBrushTimer_Tick(object sender, EventArgs e) - { - if (_vm != null && _vm.ActiveJob != null) - { - List segments = new List(); - foreach (var s in _vm.ActiveJob.Segments) - { - segments.Add(s); - - if (_vm.ActiveJob.EnableInterSegment && _vm.ActiveJob.Segments.IndexOf(s) != _vm.ActiveJob.Segments.Count - 1) - { - segments.Add(new Segment() - { - Length = _vm.ActiveJob.InterSegmentLength, - BrushStops = new System.Collections.ObjectModel.ObservableCollection() - { - new BrushStop() - { - Color = Colors.White, - } - }, - }); - } - } - - jobBrushList.ItemsSource = segments; - } - } - - private void OnDropAvailableGraph(object sender, DropEventArgs e) - { - if (e.Draggable.DataContext is TechMonitor) - { - _vm.OnDropAvailableGraph(e.Draggable.DataContext as TechMonitor); - } - } - - private void Offset_Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) - { - UpdateGradientBrushDisplay(); - } - - private void UpdateGradientBrushDisplay() - { - if (_vm.SelectedSegment != null) - { - SegmentToGradientStopsConverter converter = new SegmentToGradientStopsConverter(); - GradientStopCollection stops = converter.Convert(_vm.SelectedSegment, null, null, null) as GradientStopCollection; - gradientBrush.GradientStops = stops; - } - else - { - gradientBrush.GradientStops = new GradientStopCollection(); - } - } - - private void OnBrushStopBorderDrop(object sender, DropEventArgs e) - { - if (e.Draggable.DataContext is BrushStop) - { - _vm.OnDropBrushStop(e.Draggable.DataContext as BrushStop, e.Droppable.DataContext as BrushStop); - } - } - - private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - UpdateGradientBrushDisplay(); - } - - private void OnJobStartClick(object sender, RoutedEventArgs e) - { - - } - - private void HiveColorPickerControl_SelectedColorChanged(object sender, Color e) - { - UpdateGradientBrushDisplay(); - } - - private void Popup_MouseDown(object sender, MouseButtonEventArgs e) - { - e.Handled = true; - } - } -} diff --git a/Software/Visual_Studio/Tango.Integration/Observables/IObservableEntity.cs b/Software/Visual_Studio/Tango.Integration/Observables/IObservableEntity.cs index 15fb521ba..cd046ac2b 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/IObservableEntity.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/IObservableEntity.cs @@ -43,13 +43,7 @@ namespace Tango.Integration.Observables /// /// Saves the changes on this entity to database. /// - void Save(); - - /// - /// Saves the changes on this entity to database using the specified context. - /// - /// The context. - void Save(DbContext context); + void Save(ObservablesContext context = null); /// /// Attaches this observable to the proper DbSet. @@ -65,13 +59,7 @@ namespace Tango.Integration.Observables /// Saves the changes on this entity to database asynchronously. /// /// - Task SaveAsync(); - - /// - /// Saves the changes on this entity to database asynchronously. - /// - /// - Task SaveAsync(DbContext context); + Task SaveAsync(ObservablesContext context = null); /// /// Deletes this entity from the database. @@ -86,6 +74,6 @@ namespace Tango.Integration.Observables /// /// Deletes this entity from the database. /// - Task DeleteAsync(); + Task DeleteAsync(ObservablesContext context = null); } } diff --git a/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs b/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs index f92d9dfa0..e18193586 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs @@ -114,9 +114,16 @@ namespace Tango.Integration.Observables /// /// Saves the changes on this entity to database. /// - public virtual void Save() + public virtual void Save(ObservablesContext context = null) { - ObservablesEntitiesAdapter.Instance.SaveChanges(); + if (context == null) + { + ObservablesEntitiesAdapter.Instance.SaveChanges(); + } + else + { + context.SaveChanges(); + } OnSaved(); } @@ -140,11 +147,11 @@ namespace Tango.Integration.Observables /// Saves the changes on this entity to database asynchronously. /// /// - public Task SaveAsync() + public Task SaveAsync(ObservablesContext context = null) { return Task.Factory.StartNew(() => { - Save(); + Save(context); }); } @@ -187,11 +194,11 @@ namespace Tango.Integration.Observables /// /// Deletes this entity from the database /// - public Task DeleteAsync() + public Task DeleteAsync(ObservablesContext context = null) { return Task.Factory.StartNew(() => { - Delete(); + Delete(context); }); } @@ -254,17 +261,6 @@ namespace Tango.Integration.Observables return (this as T).CloneEntity() as T; } - public void Save(DbContext context) - { - context.SaveChanges(); - OnSaved(); - } - - public Task SaveAsync(DbContext context) - { - return Task.Factory.StartNew(() => Save(context)); - } - public bool CompareUsingJson(T entity) { String me = JsonConvert.SerializeObject(this); diff --git a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Machine.cs b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Machine.cs index bb26acc39..1669230d6 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Machine.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Machine.cs @@ -23,7 +23,7 @@ namespace Tango.Integration.Observables base.Delete(); } - public override void Save() + public override void Save(ObservablesContext context = null) { foreach (var job in Jobs) { @@ -48,7 +48,7 @@ namespace Tango.Integration.Observables } } - base.Save(); + base.Save(context); } } } diff --git a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Segment.cs b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Segment.cs index c83c34870..71a15b90c 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Segment.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Segment.cs @@ -10,14 +10,14 @@ namespace Tango.Integration.Observables { public partial class Segment { - public override void Save() + public override void Save(ObservablesContext context = null) { for (int i = 0; i < BrushStops.Count; i++) { BrushStops[i].StopIndex = i; } - base.Save(); + base.Save(context); } } } diff --git a/Software/Visual_Studio/Tango.Integration/Printing/Job.cs b/Software/Visual_Studio/Tango.Integration/Printing/Job.cs index 49c5fbdae..29155be53 100644 --- a/Software/Visual_Studio/Tango.Integration/Printing/Job.cs +++ b/Software/Visual_Studio/Tango.Integration/Printing/Job.cs @@ -120,7 +120,7 @@ namespace Tango.Integration.Observables /// /// Saves the changes on this entity to database. /// - public override void Save() + public override void Save(ObservablesContext context = null) { for (int i = 0; i < Segments.Count; i++) { @@ -132,7 +132,7 @@ namespace Tango.Integration.Observables } } - base.Save(); + base.Save(context); } public override Job Clone() -- cgit v1.3.1