using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Markup; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Tango.Editors; using Tango.BL.Entities; using Tango.MachineStudio.Technician.TechItems; using Tango.Core; using static Tango.MachineStudio.Technician.TechItems.ProcessParametersItem; using Tango.SharedUI.Editors; namespace Tango.MachineStudio.Technician.Editors { [ContentProperty("InnerContent")] public partial class ProcessParametersElementEditor : ElementEditor { /// /// Initializes a new instance of the class. /// public ProcessParametersElementEditor() : base() { InitializeComponent(); } /// /// Initializes a new instance of the class. /// /// The framework element. public ProcessParametersElementEditor(ProcessParametersItem processParametersItem) : this() { ProcessParametersItem = processParametersItem; DataContext = ProcessParametersItem; } /// /// Initializes a new instance of the class. /// /// The framework element. /// The bounds. public ProcessParametersElementEditor(ProcessParametersItem processParametersItem, Rect bounds) : this(processParametersItem) { Left = bounds.Left; Top = bounds.Top; Width = bounds.Width; Height = bounds.Height; } private ProcessParametersItem _processParametersItem; public ProcessParametersItem ProcessParametersItem { get { return _processParametersItem; } set { _processParametersItem = value; RaisePropertyChanged(nameof(ProcessParametersItem)); } } /// /// Clones this instance. /// /// public override IElementEditor Clone() { try { var clonedItem = ProcessParametersItem.Clone() as ProcessParametersItem; ProcessParametersElementEditor cloned = new ProcessParametersElementEditor(clonedItem); cloned.Top = Top; cloned.Left = Left; cloned.Width = Width; cloned.Height = Height; cloned.Angle = Angle; return cloned; } catch (Exception ex) { throw new InvalidOperationException("Could not clone this editor. You may have to create a custom editor and implement a custom Clone method.", ex); } } /// /// Gets the hosted element. /// [ParameterIgnore] public override Object HostedElement { get { return ProcessParametersItem; } } private void OnProcessParametersDropped(object sender, DragAndDrop.DropEventArgs e) { ParameterItem draggedItem = e.Draggable.DataContext as ParameterItem; ParameterItem droppedItem = e.Droppable.DataContext as ParameterItem; if (draggedItem != null && droppedItem != null && draggedItem.ParameterizedObject == droppedItem.ParameterizedObject) { var parameters = draggedItem.ParameterizedObject.Parameters; var draggedSettingItem = ProcessParametersItem.ParametersIndices.FirstOrDefault(x => x.Name == draggedItem.Name); var droppedSettingItem = ProcessParametersItem.ParametersIndices.FirstOrDefault(x => x.Name == droppedItem.Name); if (draggedSettingItem != null && droppedSettingItem != null) { if (draggedSettingItem.Index > droppedSettingItem.Index) { draggedSettingItem.Index = droppedSettingItem.Index - 1; } else { draggedSettingItem.Index = droppedSettingItem.Index + 1; } int index = 1; foreach (var settingItem in ProcessParametersItem.ParametersIndices.OrderBy(x => x.Index)) { settingItem.Index = index++; } } } var editor = e.Draggable.FindAncestor(); if (editor != null) { editor.ParameterizedObject = null; editor.ParameterizedObject = draggedItem.ParameterizedObject; } } private void ParameterizedEditor_GeneratingItems(object sender, SharedUI.Editors.ParameterizedEditor.GeneratingItemsEventArgs e) { List items = e.Result.ToList(); if (ProcessParametersItem.ParametersIndices.Count > 0) { items.Clear(); foreach (var item in ProcessParametersItem.ParametersIndices.OrderBy(x => x.Index)) { var p = e.Source.SingleOrDefault(x => x.Name == item.Name); if (p != null) { items.Add(p); } } } else { ProcessParametersTable p = new ProcessParametersTable(); var pp = p.CreateParametersCollection(Core.ParameterItemMode.Binding); foreach (var item in pp) { ProcessParametersItem.ParametersIndices.Add(new ParameterIndex() { Index = pp.IndexOf(item), Name = item.Name }); } } e.Result = items; } } }