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... --- .../ViewModels/MainViewVM.cs | 251 ++++----------------- 1 file changed, 42 insertions(+), 209 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels') 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 } -- cgit v1.3.1