diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs | 170 |
1 files changed, 146 insertions, 24 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index b0c899f06..7bed3f441 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -6,6 +6,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Reflection; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; @@ -184,7 +185,7 @@ namespace Tango.MachineStudio.Technician.ViewModels return (value as RepeatedField<double>).ToList(); } - private List<List<double>> GetMultiGraphValues(TechMonitor monitor,object value) + private List<List<double>> GetMultiGraphValues(TechMonitor monitor, object value) { DoubleArray[] arrayOfDoubles = Enumerable.ToArray(value as IEnumerable<DoubleArray>); return arrayOfDoubles.Select(x => x.Data.ToList()).ToList(); @@ -192,39 +193,105 @@ namespace Tango.MachineStudio.Technician.ViewModels public void AddElement(Rect bounds) { - lock (_elementsLock) + if (SelectedTechItem is MonitorItem) { - if (SelectedTechItem is MonitorItem) - { - var monitorItem = new MonitorItem(Adapter.TechMonitors.Where(x => !x.MultiChannel).FirstOrDefault()); - MonitorElementEditor editor = new MonitorElementEditor(monitorItem, bounds); - Elements.Add(editor); - } - else if (SelectedTechItem is MeterItem) + var monitorItem = new MonitorItem(Adapter.TechMonitors.Where(x => !x.MultiChannel).FirstOrDefault()); + MonitorElementEditor editor = new MonitorElementEditor(monitorItem, bounds); + Elements.Add(editor); + } + else if (SelectedTechItem is MeterItem) + { + var meterItem = new MeterItem(Adapter.TechMonitors.Where(x => !x.MultiChannel).FirstOrDefault()); + MeterElementEditor editor = new MeterElementEditor(meterItem, bounds); + Elements.Add(editor); + } + else if (SelectedTechItem is SingleGraphItem) + { + var graphItem = new SingleGraphItem(Adapter.TechMonitors.Where(x => !x.MultiChannel).FirstOrDefault()); + SingleGraphElementEditor editor = new SingleGraphElementEditor(graphItem, bounds); + editor.InnerGraph.InnerGraph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(graphItem.TechMonitor.PointsPerFrame); + graphItem.Editor = editor; + + + GraphController controller = new GraphController(); + editor.InnerGraph.Controller = controller; + + _singleControllers.Add(graphItem, controller); + + Elements.Add(editor); + } + else if (SelectedTechItem is MultiGraphItem) + { + var graphItem = new MultiGraphItem(Adapter.TechMonitors.Where(x => x.MultiChannel).FirstOrDefault()); + MultiGraphElementEditor editor = new MultiGraphElementEditor(graphItem, bounds); + editor.InnerGraph.InnerGraph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(graphItem.TechMonitor.PointsPerFrame); + graphItem.Editor = editor; + + + GraphMultiController controller = new GraphMultiController(); + + for (int i = 0; i < graphItem.TechMonitor.ChannelCount; i++) { - var meterItem = new MeterItem(Adapter.TechMonitors.Where(x => !x.MultiChannel).FirstOrDefault()); - MeterElementEditor editor = new MeterElementEditor(meterItem, bounds); - Elements.Add(editor); + controller.AddSeries(new RealTimeGraphEx.DataSeries.DataYSeries() + { + UseFillAndStroke = true, + Name = graphItem.TechMonitor.Name.First() + (i + 1).ToString(), + Stroke = new SolidColorBrush(ColorHelper.GetRandomColor()), + }); } - else if (SelectedTechItem is SingleGraphItem) + + editor.InnerGraph.Controller = controller; + + _multiControllers.Add(graphItem, controller); + + Elements.Add(editor); + } + else if (SelectedTechItem is MotorItem) + { + var motorItem = new MotorItem(Adapter.TechMotors.FirstOrDefault()); + MotorElementEditor editor = new MotorElementEditor(motorItem, bounds); + Elements.Add(editor); + InitMotorItem(motorItem); + } + } + + public void OnElementsRemoved(List<IElementEditor> elements) + { + //foreach (var element in elements) + //{ + // if (element.HostedElement is SingleGraphItem) + // { + // _singleControllers.Remove(element.HostedElement as SingleGraphItem); + // (element.HostedElement as SingleGraphItem).Editor.InnerGraph.InnerGraph.Dispose(); + // } + // else if (element.HostedElement is MultiGraphItem) + // { + // _multiControllers.Remove(element.HostedElement as MultiGraphItem); + // (element.HostedElement as MultiGraphItem).Editor.InnerGraph.InnerGraph.Dispose(); + // } + //} + } + + public void OnElementsPasted(List<IElementEditor> elements) + { + foreach (var element in elements) + { + if (element is SingleGraphElementEditor) { - var graphItem = new SingleGraphItem(Adapter.TechMonitors.Where(x => !x.MultiChannel).FirstOrDefault()); - SingleGraphElementEditor editor = new SingleGraphElementEditor(graphItem, bounds); - editor.InnerGraph.InnerGraph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(graphItem.TechMonitor.PointsPerFrame); + var graphItem = element.HostedElement as SingleGraphItem; + var editor = element as SingleGraphElementEditor; graphItem.Editor = editor; - + editor.InnerGraph.InnerGraph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(graphItem.TechMonitor.PointsPerFrame); GraphController controller = new GraphController(); editor.InnerGraph.Controller = controller; _singleControllers.Add(graphItem, controller); - - Elements.Add(editor); } - else if (SelectedTechItem is MultiGraphItem) + else if (element is MultiGraphElementEditor) { - var graphItem = new MultiGraphItem(Adapter.TechMonitors.Where(x => x.MultiChannel).FirstOrDefault()); - MultiGraphElementEditor editor = new MultiGraphElementEditor(graphItem, bounds); + var graphItem = element.HostedElement as MultiGraphItem; + var editor = element as MultiGraphElementEditor; editor.InnerGraph.InnerGraph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(graphItem.TechMonitor.PointsPerFrame); graphItem.Editor = editor; @@ -244,10 +311,65 @@ namespace Tango.MachineStudio.Technician.ViewModels editor.InnerGraph.Controller = controller; _multiControllers.Add(graphItem, controller); - - Elements.Add(editor); } } } + + private void InitMotorItem(MotorItem item) + { + item.ActionExecuted += async (x, action) => + { + if (action == MotorActionType.HomingStarted) + { + item.HomingProgress = 0; + item.IsHoming = true; + item.IsHomingCompleted = false; + + await Task.Factory.StartNew(() => + { + for (int i = 0; i < 101; i++) + { + item.HomingMaximumProgress = 100; + item.HomingProgress++; + + Thread.Sleep(60); + } + + item.IsHoming = false; + item.IsHomingCompleted = true; + }); + } + else if (action == MotorActionType.ForwardPressed) + { + await MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = item.TechMotor.Code, + Direction = MotorDirection.Forward, + }); + } + else if (action == MotorActionType.ForwardReleased) + { + await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = item.TechMotor.Code, + }); + } + else if (action == MotorActionType.BackwardPressed) + { + await MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = item.TechMotor.Code, + Direction = MotorDirection.Backward, + }); + } + else if (action == MotorActionType.BackwardReleased) + { + await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = item.TechMotor.Code, + }); + } + }; + } } } |
