diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-07-03 12:03:55 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-07-03 12:03:55 +0300 |
| commit | c9d3c1a7408f6f7a4814c1a8f5cf58a2d13e1694 (patch) | |
| tree | 3b92b537099625fd2d29a4e08378194c3c62f3c4 /Software/Visual_Studio | |
| parent | 5ab2e8a2edf1ce487976da347a5e03d18ff307b1 (diff) | |
| download | Tango-c9d3c1a7408f6f7a4814c1a8f5cf58a2d13e1694.tar.gz Tango-c9d3c1a7408f6f7a4814c1a8f5cf58a2d13e1694.zip | |
Machine Studio.
Implemented upload hardware configuration from connected machine view.
Implemented process parameters dragging through developer module settings :/
Diffstat (limited to 'Software/Visual_Studio')
16 files changed, 433 insertions, 112 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModuleSettings.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModuleSettings.cs index 73d979662..5e0e6d838 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModuleSettings.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModuleSettings.cs @@ -3,14 +3,28 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL.Entities; using Tango.Settings; namespace Tango.MachineStudio.Developer { public class DeveloperModuleSettings : SettingsBase { + public class ParameterIndex + { + public String Name { get; set; } + public int Index { get; set; } + } + public String LastSelectedMachineGuid { get; set; } public String LastSelectedJobGuid { get; set; } + + public List<ParameterIndex> ProcessParametersIndices { get; set; } + + public DeveloperModuleSettings() + { + ProcessParametersIndices = new List<ParameterIndex>(); + } } } 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 258750800..585a0cb6b 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 @@ -1252,102 +1252,104 @@ </Border.Style> <Grid> <StackPanel> - <DockPanel> - <TextBox materialDesign:HintAssist.Hint="Table Name" DockPanel.Dock="Top" Text="{Binding Name}"></TextBox> - <WrapPanel Orientation="Vertical" Margin="0 5 0 0"> - <WrapPanel.Resources> - <Style TargetType="TextBlock"> - <Setter Property="FontSize" Value="10"></Setter> - <Setter Property="Foreground" Value="#7A7A7A"></Setter> - <Setter Property="Margin" Value="0 5 0 5"></Setter> - <Setter Property="MinWidth" Value="80"></Setter> - </Style> + <DockPanel> + <TextBox materialDesign:HintAssist.Hint="Table Name" DockPanel.Dock="Top" Text="{Binding Name}"></TextBox> + <WrapPanel Orientation="Vertical" Margin="0 5 0 0"> + <WrapPanel.Resources> + <Style TargetType="TextBlock"> + <Setter Property="FontSize" Value="10"></Setter> + <Setter Property="Foreground" Value="#7A7A7A"></Setter> + <Setter Property="Margin" Value="0 5 0 5"></Setter> + <Setter Property="MinWidth" Value="80"></Setter> + </Style> - <Style TargetType="mahapps:NumericUpDown"> - <Setter Property="FontFamily" Value="{StaticResource digital-7}"></Setter> - </Style> + <Style TargetType="mahapps:NumericUpDown"> + <Setter Property="FontFamily" Value="{StaticResource digital-7}"></Setter> + </Style> - <Style TargetType="ContentControl"> - <!--<Setter Property="FontFamily" Value="digital-7"></Setter>--> - <Setter Property="Template"> - <Setter.Value> - <ControlTemplate TargetType="ContentControl"> - <Grid Width="97" FlowDirection="LeftToRight"> - <Border> - <Border.Style> - <Style TargetType="Border"> - <Setter Property="BorderBrush" Value="Gainsboro"></Setter> - <Setter Property="BorderThickness" Value="1"></Setter> - <Setter Property="Padding" Value="2"></Setter> - <Setter Property="Margin" Value="4"></Setter> - <Setter Property="CornerRadius" Value="3"></Setter> - </Style> - </Border.Style> - <ContentPresenter Content="{TemplateBinding Content}"></ContentPresenter> - </Border> + <Style TargetType="ContentControl"> + <!--<Setter Property="FontFamily" Value="digital-7"></Setter>--> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="ContentControl"> + <Grid Width="97"> + <Border> + <Border.Style> + <Style TargetType="Border"> + <Setter Property="BorderBrush" Value="Gainsboro"></Setter> + <Setter Property="BorderThickness" Value="1"></Setter> + <Setter Property="Padding" Value="2"></Setter> + <Setter Property="Margin" Value="4"></Setter> + <Setter Property="CornerRadius" Value="3"></Setter> + </Style> + </Border.Style> + <ContentPresenter Content="{TemplateBinding Content}"></ContentPresenter> + </Border> - <materialDesign:PackIcon HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0 0 0 0" Width="12" Height="12" Kind="Settings"></materialDesign:PackIcon> - </Grid> - </ControlTemplate> - </Setter.Value> - </Setter> - </Style> + <materialDesign:PackIcon HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0 0 0 0" Width="12" Height="12" Kind="Settings"></materialDesign:PackIcon> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> - </WrapPanel.Resources> - <editors:ParameterizedEditor ParameterizedObject="{Binding}"> - <editors:ParameterizedEditor.ItemsPanel> - <ItemsPanelTemplate> - <WrapPanel IsItemsHost="True" Orientation="Horizontal" FlowDirection="RightToLeft" /> - </ItemsPanelTemplate> - </editors:ParameterizedEditor.ItemsPanel> - <editors:ParameterizedEditor.DoubleTemplate> - <DataTemplate> - <ContentControl> - <StackPanel> - <TextBlock Margin="0 5 0 5" TextAlignment="Right" Text="{Binding Name}" FontSize="10"></TextBlock> - <mahapps:NumericUpDown FontSize="16" Minimum="0" Margin="0 0 5 0" HideUpDownButtons="True" HorizontalContentAlignment="Center" Maximum="10000" StringFormat="0.0" InterceptArrowKeys="True" Background="Transparent" BorderThickness="0" InterceptMouseWheel="True" HasDecimals="True" Value="{Binding Value,Mode=TwoWay}"></mahapps:NumericUpDown> - </StackPanel> - </ContentControl> - </DataTemplate> - </editors:ParameterizedEditor.DoubleTemplate> - </editors:ParameterizedEditor> - </WrapPanel> - </DockPanel> + </WrapPanel.Resources> + <editors:ParameterizedEditor ParameterizedObject="{Binding}" GeneratingItems="ParameterizedEditor_GeneratingItems"> + <editors:ParameterizedEditor.ItemsPanel> + <ItemsPanelTemplate> + <WrapPanel IsItemsHost="True" Orientation="Horizontal" /> + </ItemsPanelTemplate> + </editors:ParameterizedEditor.ItemsPanel> + <editors:ParameterizedEditor.DoubleTemplate> + <DataTemplate> + <Grid Background="Transparent" Style="{StaticResource draggableDroppableGrid}" dragAndDrop:DragAndDropService.Drop="OnProcessParameterDropped" dragAndDrop:DragAndDropService.DraggingSurface="{Binding RelativeSource={RelativeSource AncestorType=editors:ParameterizedEditor},Path=DraggingSurface}"> + <ContentControl> + <StackPanel> + <TextBlock IsHitTestVisible="False" Margin="0 5 0 5" Text="{Binding Name}" FontSize="10"></TextBlock> + <mahapps:NumericUpDown FontSize="16" Minimum="0" Margin="0 0 5 0" HideUpDownButtons="True" HorizontalContentAlignment="Center" Maximum="10000" StringFormat="0.0" InterceptArrowKeys="True" Background="Transparent" BorderThickness="0" InterceptMouseWheel="True" HasDecimals="True" Value="{Binding Value,Mode=TwoWay}"></mahapps:NumericUpDown> + </StackPanel> + </ContentControl> + </Grid> + </DataTemplate> + </editors:ParameterizedEditor.DoubleTemplate> + </editors:ParameterizedEditor> + </WrapPanel> + </DockPanel> - <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="5" Visibility="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected,Converter={StaticResource BooleanToVisibilityConverter}}"> - <TextBlock Text="Active" FontWeight="Bold" FontStyle="Italic" FontSize="13" VerticalAlignment="Center"></TextBlock> - <materialDesign:PackIcon Foreground="#90E990" Kind="CheckboxBlankCircle" VerticalAlignment="Center" Margin="5 0 0 0"> - <materialDesign:PackIcon.Style> - <Style TargetType="materialDesign:PackIcon"> - <Setter Property="Opacity" Value="0"></Setter> - <Style.Triggers> - <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected,FallbackValue=False}" Value="True"> - <DataTrigger.EnterActions> - <BeginStoryboard> - <Storyboard> - <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Duration="00:00:01" RepeatBehavior="Forever"> - <DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="1" /> - <DiscreteDoubleKeyFrame KeyTime="00:00:0.5" Value="0" /> - </DoubleAnimationUsingKeyFrames> - </Storyboard> - </BeginStoryboard> - </DataTrigger.EnterActions> - <DataTrigger.ExitActions> - <BeginStoryboard> - <Storyboard> - <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Duration="00:00:01"> - <DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="0" /> - </DoubleAnimationUsingKeyFrames> - </Storyboard> - </BeginStoryboard> - </DataTrigger.ExitActions> - </DataTrigger> - </Style.Triggers> - </Style> - </materialDesign:PackIcon.Style> - </materialDesign:PackIcon> - </StackPanel> + <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="5" Visibility="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected,Converter={StaticResource BooleanToVisibilityConverter}}"> + <TextBlock Text="Active" FontWeight="Bold" FontStyle="Italic" FontSize="13" VerticalAlignment="Center"></TextBlock> + <materialDesign:PackIcon Foreground="#90E990" Kind="CheckboxBlankCircle" VerticalAlignment="Center" Margin="5 0 0 0"> + <materialDesign:PackIcon.Style> + <Style TargetType="materialDesign:PackIcon"> + <Setter Property="Opacity" Value="0"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected,FallbackValue=False}" Value="True"> + <DataTrigger.EnterActions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Duration="00:00:01" RepeatBehavior="Forever"> + <DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="1" /> + <DiscreteDoubleKeyFrame KeyTime="00:00:0.5" Value="0" /> + </DoubleAnimationUsingKeyFrames> + </Storyboard> + </BeginStoryboard> + </DataTrigger.EnterActions> + <DataTrigger.ExitActions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Duration="00:00:01"> + <DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="0" /> + </DoubleAnimationUsingKeyFrames> + </Storyboard> + </BeginStoryboard> + </DataTrigger.ExitActions> + </DataTrigger> + </Style.Triggers> + </Style> + </materialDesign:PackIcon.Style> + </materialDesign:PackIcon> + </StackPanel> </StackPanel> </Grid> </Border> 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 044046450..b48e91f31 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 @@ -19,6 +19,10 @@ using Tango.BL.Entities; using Tango.MachineStudio.Developer.Converters; using Tango.MachineStudio.Developer.ViewModels; using Tango.BL; +using Tango.Settings; +using Tango.Core; +using Tango.SharedUI.Editors; +using static Tango.MachineStudio.Developer.DeveloperModuleSettings; namespace Tango.MachineStudio.Developer.Views { @@ -153,5 +157,90 @@ namespace Tango.MachineStudio.Developer.Views { e.Handled = true; } + + private void ParameterizedEditor_GeneratingItems(object sender, SharedUI.Editors.ParameterizedEditor.GeneratingItemsEventArgs e) + { + var settings = SettingsManager.Default.GetOrCreate<DeveloperModuleSettings>(); + + List<ParameterItem> items = e.Result.ToList(); + + if (settings.ProcessParametersIndices.Count > 0) + { + items.Clear(); + + foreach (var item in settings.ProcessParametersIndices.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) + { + settings.ProcessParametersIndices.Add(new ParameterIndex() + { + Index = pp.IndexOf(item), + Name = item.Name + }); + } + + settings.Save(); + } + + e.Result = items; + } + + private void OnProcessParameterDropped(object sender, 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 settings = SettingsManager.Default.GetOrCreate<DeveloperModuleSettings>(); + + var parameters = draggedItem.ParameterizedObject.Parameters; + + var draggedSettingItem = settings.ProcessParametersIndices.FirstOrDefault(x => x.Name == draggedItem.Name); + var droppedSettingItem = settings.ProcessParametersIndices.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 settings.ProcessParametersIndices.OrderBy(x => x.Index)) + { + settingItem.Index = index++; + } + } + + settings.Save(); + } + + var editor = e.Draggable.FindAncestor<ParameterizedEditor>(); + + if (editor != null) + { + editor.ParameterizedObject = null; + editor.ParameterizedObject = draggedItem.ParameterizedObject; + } + } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs index 10b05bc64..777c488d7 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs @@ -24,6 +24,7 @@ namespace Tango.MachineStudio.UI.Console private INotificationProvider _notificatrion; private TextBox _txtLog; private String _currentFile; + private ScriptEngine _engine; /// <summary> @@ -160,22 +161,24 @@ namespace Tango.MachineStudio.UI.Console private void Stop() { - + if (_engine != null) + { + _engine.Stop(); + } } private async void Run() { - ScriptEngine engine = new ScriptEngine(new ConsoleOnExecuteParameters(new ConsoleManager(WriteLine))); - engine.Stop(); - engine.ReferencedAssemblies.Add(this.GetType()); - engine.ReferencedAssemblies.Add(typeof(INotificationProvider)); + _engine = new ScriptEngine(new ConsoleOnExecuteParameters(new ConsoleManager(WriteLine))); + _engine.ReferencedAssemblies.Add(this.GetType()); + _engine.ReferencedAssemblies.Add(typeof(INotificationProvider)); foreach (var module in _moduleLoader.AllModules) { - engine.ReferencedAssemblies.Add(module.GetType()); + _engine.ReferencedAssemblies.Add(module.GetType()); } - await engine.Run(Code, null); + await _engine.Run(Code, null); } private void WriteLine(String text) diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs index 9f84cfb53..76e138e0e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs @@ -13,6 +13,13 @@ namespace Tango.MachineStudio.UI.ViewModels { public class ConnectedMachineViewVM : DialogViewVM { + public enum ConnectedMachineVMResult + { + Cancel, + Disconnect, + UploadHardwareConfig, + } + private IStudioApplicationManager _applicationManager; public IStudioApplicationManager ApplicationManager { @@ -20,16 +27,28 @@ namespace Tango.MachineStudio.UI.ViewModels set { _applicationManager = value; RaisePropertyChangedAuto(); } } + public ConnectedMachineVMResult Result { get; set; } + public RelayCommand DisconnectCommand { get; set; } + public RelayCommand UploadHardwareConfigurationCommand { get; set; } + public ConnectedMachineViewVM(IStudioApplicationManager application) { ApplicationManager = application; DisconnectCommand = new RelayCommand(Disconnect); + UploadHardwareConfigurationCommand = new RelayCommand(UploadHardwareConfiguration); + } + + private void UploadHardwareConfiguration() + { + Result = ConnectedMachineVMResult.UploadHardwareConfig; + Accept(); } private void Disconnect() { + Result = ConnectedMachineVMResult.Disconnect; Accept(); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index aa0eedefb..45ae68cc5 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -502,9 +502,32 @@ namespace Tango.MachineStudio.UI.ViewModels } else { - _notificationProvider.ShowModalDialog<ConnectedMachineViewVM>((x) => + _notificationProvider.ShowModalDialog<ConnectedMachineViewVM>(async (x) => { - DisconnectFromMachine(); + if (x.Result == ConnectedMachineViewVM.ConnectedMachineVMResult.Disconnect) + { + DisconnectFromMachine(); + } + else if (x.Result == ConnectedMachineViewVM.ConnectedMachineVMResult.UploadHardwareConfig) + { + if (NotificationProvider.ShowQuestion("This will reset the machine hardware configuration to the database configuration. Are you sure?")) + { + using (NotificationProvider.PushTaskItem("Uploading hardware configuration...")) + { + try + { + var configuration = ApplicationManager.ConnectedMachine.Machine.Configuration; + await ApplicationManager.ConnectedMachine.UploadHardwareConfiguration(configuration.HardwareVersion, configuration); + NotificationProvider.ShowInfo("Hardware configuration uploaded successfully."); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error upload hardware configuration."); + NotificationProvider.ShowError("Error upload hardware configuration." + Environment.NewLine + ex.Message); + } + } + } + } }); } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml index 45f1c9b26..a4f253de3 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml @@ -40,7 +40,7 @@ </DataTemplate> </ContentControl.Resources> </ContentControl> - + <TextBlock Text="Machine Connection" VerticalAlignment="Center" Margin="10 0 0 0" FontSize="20"></TextBlock> </StackPanel> </Grid> @@ -116,7 +116,15 @@ </Grid> <Grid Grid.Row="1"> - <Button HorizontalAlignment="Right" Width="140" Command="{Binding DisconnectCommand}">DISCONNECT</Button> + <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Height="40" VerticalAlignment="Bottom"> + <Button Height="Auto" Command="{Binding UploadHardwareConfigurationCommand}" ToolTip="Upload the current hardware configuration stored for this machine"> + <StackPanel Orientation="Horizontal"> + <TextBlock VerticalAlignment="Center">UPLOAD HW CONFIG</TextBlock> + <materialDesign:PackIcon Margin="10 0 0 0" Width="16" Height="16" VerticalAlignment="Center" Kind="ArrowRightBold"/> + </StackPanel> + </Button> + <Button Height="Auto" Width="140" Command="{Binding DisconnectCommand}" Margin="10 0 0 0">DISCONNECT</Button> + </StackPanel> </Grid> </Grid> </Grid> diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs index 2193127cf..5a5efd6ad 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs @@ -9,6 +9,8 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Markup; +using System.Windows.Media; +using System.Windows.Media.Imaging; using Tango.Core.EventArguments; public static class FrameworkElementExtensions @@ -343,6 +345,7 @@ public static class FrameworkElementExtensions #endregion + #region Visual Tree /// <summary> /// A recursive search for a child of type T in memory and not on logical/visual tree. /// </summary> @@ -443,4 +446,50 @@ public static class FrameworkElementExtensions return null; } + #endregion + + #region Bitmaps + + /// <summary> + /// Creates a bitmap source from the framework element. + /// </summary> + /// <param name="element">The element.</param> + /// <returns></returns> + public static RenderTargetBitmap TakeSnapshot(this FrameworkElement element) + { + + int nWidth = (int)Math.Ceiling(element.ActualWidth); + int nHeight = (int)Math.Ceiling(element.ActualHeight); + + RenderTargetBitmap oTargetBitmap = new RenderTargetBitmap( + nWidth, + nHeight, + 96, + 96, + PixelFormats.Pbgra32 + ); + + DrawingVisual oDrawingVisual = new DrawingVisual(); + + using (DrawingContext oDrawingContext = oDrawingVisual.RenderOpen()) + { + VisualBrush oVisualBrush = new VisualBrush(element) { Stretch = Stretch.Fill }; + + oDrawingContext.DrawRectangle( + oVisualBrush, + null, + new Rect( + new Point(), + new Size(nWidth, nHeight) + ) + ); + + oDrawingContext.Close(); + oTargetBitmap.Render(oDrawingVisual); + } + + return oTargetBitmap; + } + + #endregion } diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs index 0114b50b4..3b1c5f271 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs @@ -80,6 +80,7 @@ public static class IParameterizedExtensions item.Name = propertyInfo.Name.ToTitle(); item.Index = index; item.Type = propertyInfo.PropertyType; + item.ParameterizedObject = instance; if (attribute != null) { diff --git a/Software/Visual_Studio/Tango.Core/ParameterItem.cs b/Software/Visual_Studio/Tango.Core/ParameterItem.cs index a1fd21826..01a9bf72c 100644 --- a/Software/Visual_Studio/Tango.Core/ParameterItem.cs +++ b/Software/Visual_Studio/Tango.Core/ParameterItem.cs @@ -18,6 +18,19 @@ namespace Tango.Core /// </summary> public event EventHandler<ParameterItem> ParameterValueChanged; + + /// <summary> + /// Gets or sets the parameterized object. + /// </summary> + public IParameterized ParameterizedObject + { + get { return (IParameterized)GetValue(ParameterizedObjectProperty); } + set { SetValue(ParameterizedObjectProperty, value); } + } + public static readonly DependencyProperty ParameterizedObjectProperty = + DependencyProperty.Register("ParameterizedObject", typeof(IParameterized), typeof(ParameterItem), new PropertyMetadata(null)); + + /// <summary> /// Gets or sets the parameter index. /// </summary> diff --git a/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropContainer.cs b/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropContainer.cs new file mode 100644 index 000000000..043613308 --- /dev/null +++ b/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropContainer.cs @@ -0,0 +1,44 @@ +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.Markup; + +namespace Tango.DragAndDrop +{ + [ContentProperty(nameof(InnerContent))] + public class DragAndDropContainer : ContentControl + { + public DragAndDropContainer() + { + Grid g = new Grid(); + Content = g; + + ContentControl control = new ContentControl(); + control.Bind(ContentControl.ContentProperty, this, InnerContentProperty, System.Windows.Data.BindingMode.OneWay); + g.Children.Add(control); + + DraggingSurface = new DraggingSurface(); + g.Children.Add(DraggingSurface); + } + + public DraggingSurface DraggingSurface + { + get { return (DraggingSurface)GetValue(DraggingSurfaceProperty); } + private set { SetValue(DraggingSurfaceProperty, value); } + } + public static readonly DependencyProperty DraggingSurfaceProperty = + DependencyProperty.Register("DraggingSurface", typeof(DraggingSurface), typeof(DragAndDropContainer), new PropertyMetadata(null)); + + public Object InnerContent + { + get { return (Object)GetValue(InnerContentProperty); } + set { SetValue(InnerContentProperty, value); } + } + public static readonly DependencyProperty InnerContentProperty = + DependencyProperty.Register("InnerContent", typeof(Object), typeof(DragAndDropContainer), new PropertyMetadata(null)); + } +} diff --git a/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs b/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs index 445cc3924..26a89911e 100644 --- a/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs +++ b/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs @@ -12,7 +12,7 @@ using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Threading; using Tango.Core.EventArguments; -using Tango.SharedUI.Helpers; + namespace Tango.DragAndDrop { @@ -621,7 +621,7 @@ namespace Tango.DragAndDrop { if (_currentDragedElement != null) { - BitmapSource source = UIHelper.TakeSnapshot(_currentDragedElement); + BitmapSource source = _currentDragedElement.TakeSnapshot(); _dragBorder = new Border(); var surface = GetDraggingSurface(_currentDragedElement); diff --git a/Software/Visual_Studio/Tango.DragAndDrop/Tango.DragAndDrop.csproj b/Software/Visual_Studio/Tango.DragAndDrop/Tango.DragAndDrop.csproj index 8d267b703..1cebe0037 100644 --- a/Software/Visual_Studio/Tango.DragAndDrop/Tango.DragAndDrop.csproj +++ b/Software/Visual_Studio/Tango.DragAndDrop/Tango.DragAndDrop.csproj @@ -67,6 +67,7 @@ <Compile Include="..\Versioning\Core.cs"> <Link>Core.cs</Link> </Compile> + <Compile Include="DragAndDropContainer.cs" /> <Compile Include="DragAndDropService.cs" /> <Compile Include="DraggingSurface.cs" /> <Compile Include="DragThumb.cs" /> @@ -103,10 +104,6 @@ <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> <Name>Tango.Core</Name> </ProjectReference> - <ProjectReference Include="..\Tango.SharedUI\Tango.SharedUI.csproj"> - <Project>{8491d07b-c1f6-4b62-a412-41b9fd2d6538}</Project> - <Name>Tango.SharedUI</Name> - </ProjectReference> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. diff --git a/Software/Visual_Studio/Tango.SharedUI/Editors/ParameterizedEditor.xaml b/Software/Visual_Studio/Tango.SharedUI/Editors/ParameterizedEditor.xaml index 2f150fa2f..f9ffa762e 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Editors/ParameterizedEditor.xaml +++ b/Software/Visual_Studio/Tango.SharedUI/Editors/ParameterizedEditor.xaml @@ -4,6 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Tango.SharedUI.Editors" + xmlns:dragAndDrop="clr-namespace:Tango.DragAndDrop;assembly=Tango.DragAndDrop" xmlns:converters="clr-namespace:Tango.SharedUI.Converters" xmlns:sys="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" @@ -22,7 +23,7 @@ </UserControl.Resources> <Grid> - <ItemsControl x:Name="itemsControl" ItemsPanel="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=ItemsPanel}" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=ParameterizedObject.Parameters}" HorizontalContentAlignment="Stretch"> + <ItemsControl x:Name="itemsControl" ItemsPanel="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=ItemsPanel}" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=Parameters}" HorizontalContentAlignment="Stretch"> <ItemsControl.ItemTemplate> <DataTemplate> <ContentControl Content="{Binding}"> @@ -89,5 +90,7 @@ </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> + + <dragAndDrop:DraggingSurface x:Name="draggingSurface" ClipToBounds="True" /> </Grid> </UserControl> diff --git a/Software/Visual_Studio/Tango.SharedUI/Editors/ParameterizedEditor.xaml.cs b/Software/Visual_Studio/Tango.SharedUI/Editors/ParameterizedEditor.xaml.cs index 64bb1e9bd..30f1974d7 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Editors/ParameterizedEditor.xaml.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Editors/ParameterizedEditor.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -14,6 +15,7 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Tango.Core; +using Tango.DragAndDrop; using Tango.SharedUI; namespace Tango.SharedUI.Editors @@ -23,16 +25,49 @@ namespace Tango.SharedUI.Editors /// </summary> public partial class ParameterizedEditor : UserControl { + public class GeneratingItemsEventArgs : EventArgs + { + public IEnumerable<ParameterItem> Source { get; set; } + public IEnumerable<ParameterItem> Result { get; set; } + } + + public event EventHandler<GeneratingItemsEventArgs> GeneratingItems; + /// <summary> /// Initializes a new instance of the <see cref="ParameterizedEditor"/> class. /// </summary> public ParameterizedEditor() { InitializeComponent(); + + DraggingSurface = draggingSurface; } /// <summary> + /// Gets or sets the parameters. + /// </summary> + public List<ParameterItem> Parameters + { + get { return (List<ParameterItem>)GetValue(ParametersProperty); } + set { SetValue(ParametersProperty, value); } + } + public static readonly DependencyProperty ParametersProperty = + DependencyProperty.Register("Parameters", typeof(List<ParameterItem>), typeof(ParameterizedEditor), new PropertyMetadata(null)); + + /// <summary> + /// Gets or sets the dragging surface. + /// </summary> + public DraggingSurface DraggingSurface + { + get { return (DraggingSurface)GetValue(DraggingSurfaceProperty); } + set { SetValue(DraggingSurfaceProperty, value); } + } + public static readonly DependencyProperty DraggingSurfaceProperty = + DependencyProperty.Register("DraggingSurface", typeof(DraggingSurface), typeof(ParameterizedEditor), new PropertyMetadata(null)); + + + /// <summary> /// Gets or sets the items panel. /// </summary> public ItemsPanelTemplate ItemsPanel @@ -43,8 +78,6 @@ namespace Tango.SharedUI.Editors public static readonly DependencyProperty ItemsPanelProperty = DependencyProperty.Register("ItemsPanel", typeof(ItemsPanelTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null)); - - /// <summary> /// Gets or sets the parameterized object. /// </summary> @@ -54,7 +87,7 @@ namespace Tango.SharedUI.Editors set { SetValue(ParameterizedObjectProperty, value); } } public static readonly DependencyProperty ParameterizedObjectProperty = - DependencyProperty.Register("ParameterizedObject", typeof(IParameterized), typeof(ParameterizedEditor), new PropertyMetadata(null)); + DependencyProperty.Register("ParameterizedObject", typeof(IParameterized), typeof(ParameterizedEditor), new PropertyMetadata(null,(d,e) => (d as ParameterizedEditor).OnParameterizedObjectChanged())); /// <summary> /// Gets or sets a single item padding. @@ -200,7 +233,26 @@ namespace Tango.SharedUI.Editors } public static readonly DependencyProperty StringTemplateProperty = DependencyProperty.Register("StringTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null)); - + + #endregion + + private void OnParameterizedObjectChanged() + { + if (ParameterizedObject != null) + { + GeneratingItemsEventArgs e = new GeneratingItemsEventArgs(); + e.Source = ParameterizedObject.Parameters; + e.Result = ParameterizedObject.Parameters; + + GeneratingItems?.Invoke(this, e); + + Parameters = e.Result.ToList(); + } + else + { + Parameters = null; + } + } } } diff --git a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj index ad5dc531b..2f418ff4a 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj +++ b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj @@ -206,6 +206,10 @@ <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> <Name>Tango.Core</Name> </ProjectReference> + <ProjectReference Include="..\Tango.DragAndDrop\Tango.DragAndDrop.csproj"> + <Project>{b112d89a-a106-41ae-a0c1-4abc84c477f5}</Project> + <Name>Tango.DragAndDrop</Name> + </ProjectReference> <ProjectReference Include="..\Tango.Scripting\Tango.Scripting.csproj"> <Project>{401989E7-AE1E-4002-B0EE-9A9F63740B97}</Project> <Name>Tango.Scripting</Name> |
