diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner')
7 files changed, 298 insertions, 8 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/AutoComplete/MachineVersionsProvider.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/AutoComplete/MachineVersionsProvider.cs new file mode 100644 index 000000000..51ca629a4 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/AutoComplete/MachineVersionsProvider.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.AutoComplete.Editors; +using Tango.DAL.Observables; + +namespace Tango.MachineStudio.MachineDesigner.AutoComplete +{ + /// <summary> + /// Represents an auto-complete <see cref="MachineVersion">Machine Versions</see> provider. + /// </summary> + /// <seealso cref="Tango.AutoComplete.Editors.ISuggestionProvider" /> + public class MachineVersionsProvider : ISuggestionProvider + { + public String Text { get; set; } + + public IEnumerable GetSuggestions(string filter) + { + Text = filter; + return ObservablesEntitiesAdapter.Instance.MachineVersions.Where(x => x.Version.ToString().StartsWith(filter, StringComparison.CurrentCultureIgnoreCase) || x.Name.StartsWith(filter, StringComparison.CurrentCultureIgnoreCase)).ToList(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj index 46ec20fdc..ac1616401 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj @@ -78,8 +78,13 @@ </ItemGroup> <ItemGroup> <Compile Include="AutoComplete\MachinesProvider.cs" /> + <Compile Include="AutoComplete\MachineVersionsProvider.cs" /> <Compile Include="ViewModelLocator.cs" /> + <Compile Include="ViewModels\MachineVersionDialogVM.cs" /> <Compile Include="ViewModels\MainViewVM.cs" /> + <Compile Include="Views\MachineVersionDialog.xaml.cs"> + <DependentUpon>MachineVersionDialog.xaml</DependentUpon> + </Compile> <Compile Include="Views\MainView.xaml.cs"> <DependentUpon>MainView.xaml</DependentUpon> </Compile> @@ -87,6 +92,10 @@ <Link>GlobalVersionInfo.cs</Link> </Compile> <Compile Include="MachineDesignerModule.cs" /> + <Page Include="Views\MachineVersionDialog.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="Views\MainView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineVersionDialogVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineVersionDialogVM.cs new file mode 100644 index 000000000..6854472f1 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineVersionDialogVM.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.DAL.Observables; +using Tango.MachineStudio.Common.Notifications; +using Tango.MachineStudio.MachineDesigner.AutoComplete; + +namespace Tango.MachineStudio.MachineDesigner.ViewModels +{ + public class MachineVersionDialogVM : DialogViewVM + { + public MachineVersionsProvider VersionsProvider { get; set; } + + public double Version { get; set; } + + private String _versionName; + + public String VersionName + { + get { return _versionName; } + set { _versionName = value; RaisePropertyChangedAuto(); } + } + + private MachineVersion _selectedVersion; + + public MachineVersion SelectedVersion + { + get { return _selectedVersion; } + set + { + _selectedVersion = value; + RaisePropertyChangedAuto(); + VersionName = value != null ? value.Name : null; + Version = value != null ? value.Version : 0; + } + } + + public RelayCommand AcceptCommand { get; set; } + + public RelayCommand CancelCommand { get; set; } + + public MachineVersionDialogVM() + { + VersionsProvider = new MachineVersionsProvider(); + AcceptCommand = new RelayCommand(() => + { + if (SelectedVersion == null) + { + Version = double.Parse(VersionsProvider.Text); + } + + Accept(); + + }); + CancelCommand = new RelayCommand(Cancel); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index 96b66c204..24f2f6d43 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -123,6 +123,16 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// </summary> public RelayCommand RemoveIdsCommand { get; set; } + /// <summary> + /// Gets or sets the set version configuration command. + /// </summary> + public RelayCommand SetVersionConfigurationCommand { get; set; } + + /// <summary> + /// Gets or sets the set as default command. + /// </summary> + public RelayCommand SetAsDefaultCommand { get; set; } + #endregion #region Constructors @@ -143,6 +153,8 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels SaveCommand = new RelayCommand(Save, (x) => !_isSaving); AddIdsCommand = new RelayCommand(AddIds, (x) => !_isSaving && Configuration.IdsPacks.Count < 8); RemoveIdsCommand = new RelayCommand(RemoveIds, (x) => !_isSaving && SelectedIds != null); + SetVersionConfigurationCommand = new RelayCommand(SetVersionConfiguration,(x) => !_isSaving); + SetAsDefaultCommand = new RelayCommand(SetAsDefaultConfiguration,(x) => !_isSaving); } #endregion @@ -563,6 +575,61 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels History.Insert(0, machine.Configuration); } + /// <summary> + /// Sets the current configuration to the selected machine version default configuration. + /// </summary> + private void SetVersionConfiguration() + { + if (Machine.MachineVersions != null) + { + Configuration = Machine.MachineVersions.Configuration.CloneConfiguration(); + } + else + { + _notification.ShowError("No machine version selected."); + } + } + + /// <summary> + /// Sets the current configuration as a default machine version configuration. + /// </summary> + private void SetAsDefaultConfiguration() + { + _notification.ShowModalDialog<MachineVersionDialogVM>(async (vm) => + { + try + { + using (_notification.PushTaskItem("Saving Default Configuration...")) + { + if (vm.SelectedVersion != null) + { + vm.SelectedVersion.Configuration = Configuration.CloneConfiguration(); + vm.SelectedVersion.DefaultConfigurationGuid = vm.SelectedVersion.Configuration.Guid; + await vm.SelectedVersion.SaveAsync(); + } + else + { + MachineVersion newVersion = new MachineVersion(); + newVersion.Version = vm.Version; + newVersion.Name = vm.VersionName; + + newVersion.Configuration = Configuration.CloneConfiguration(); + newVersion.DefaultConfigurationGuid = newVersion.Configuration.Guid; + await newVersion.SaveAsync(); + } + } + } + catch (Exception ex) + { + _notification.ShowError(ex.Message); + } + + }, () => + { + + }); + } + #endregion } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineVersionDialog.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineVersionDialog.xaml new file mode 100644 index 000000000..60aebef7f --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineVersionDialog.xaml @@ -0,0 +1,80 @@ +<UserControl x:Class="Tango.MachineStudio.MachineDesigner.Views.MachineVersionDialog" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:autoComplete="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:providers="clr-namespace:Tango.MachineStudio.MachineDesigner.AutoComplete" + xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" + xmlns:local="clr-namespace:Tango.MachineStudio.MachineDesigner.Views" + mc:Ignorable="d" Width="530" Height="239" Background="White"> + + <UserControl.Resources> + <providers:MachineVersionsProvider x:Key="VersionsProvider"></providers:MachineVersionsProvider> + </UserControl.Resources> + + <Grid> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="50"/> + <RowDefinition Height="1*"/> + </Grid.RowDefinitions> + + <Grid> + <StackPanel Orientation="Horizontal" Margin="10"> + <materialDesign:PackIcon Width="24" Height="24" Kind="Verified" VerticalAlignment="Center"></materialDesign:PackIcon> + <TextBlock Text="Default Version Configuration" VerticalAlignment="Center" Margin="10 0 0 0" FontSize="16"></TextBlock> + </StackPanel> + </Grid> + + <Grid Grid.Row="1" Margin="10"> + <Grid.RowDefinitions> + <RowDefinition Height="1*"/> + <RowDefinition Height="Auto"/> + </Grid.RowDefinitions> + + <Grid> + <StackPanel HorizontalAlignment="Left" Margin="10"> + <TextBlock>Version</TextBlock> + <autoComplete:AutoCompleteTextBox Margin="0 5 0 0" Width="200" materialDesign:HintAssist.Hint="Selected version" DisplayMember="Version" Provider="{Binding VersionsProvider}" SelectedItem="{Binding SelectedVersion,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"> + <autoComplete:AutoCompleteTextBox.ItemTemplate> + <DataTemplate> + <TextBlock><Run Text="{Binding Name}"></Run><Run>,</Run><Run Text="{Binding Version}"></Run></TextBlock> + </DataTemplate> + </autoComplete:AutoCompleteTextBox.ItemTemplate> + <autoComplete:AutoCompleteTextBox.LoadingContent> + <TextBlock Text="Loading..." Margin="5" FontSize="14" /> + </autoComplete:AutoCompleteTextBox.LoadingContent> + </autoComplete:AutoCompleteTextBox> + <TextBlock Margin="0 10 0 0">Name</TextBlock> + <TextBox materialDesign:HintAssist.Hint="Version name" Text="{Binding VersionName}"> + <TextBox.Style> + <Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}"> + <Setter Property="IsEnabled" Value="False"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding SelectedVersion}" Value="{x:Null}"> + <Setter Property="IsEnabled" Value="True"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </TextBox.Style> + </TextBox> + </StackPanel> + </Grid> + + <Grid Grid.Row="1"> + <StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right" DockPanel.Dock="Bottom"> + <Button Command="{Binding AcceptCommand}" Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Margin="0 8 8 0"> + ACCEPT + </Button> + <Button Command="{Binding CancelCommand}" Style="{StaticResource MaterialDesignFlatButton}" IsCancel="False" Margin="0 8 8 0"> + CANCEL + </Button> + </StackPanel> + </Grid> + </Grid> + </Grid> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineVersionDialog.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineVersionDialog.xaml.cs new file mode 100644 index 000000000..3d59d7cda --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineVersionDialog.xaml.cs @@ -0,0 +1,28 @@ +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; + +namespace Tango.MachineStudio.MachineDesigner.Views +{ + /// <summary> + /// Interaction logic for MachineVersionDialog.xaml + /// </summary> + public partial class MachineVersionDialog : UserControl + { + public MachineVersionDialog() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MainView.xaml index 8f955beea..605b66a05 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MainView.xaml @@ -431,7 +431,7 @@ <Grid Grid.Column="1"> <Grid.RowDefinitions> <RowDefinition/> - <RowDefinition Height="70"/> + <RowDefinition Height="60"/> </Grid.RowDefinitions> <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"> <Grid> @@ -447,7 +447,14 @@ <TextBox Text="{Binding Machine.Name,UpdateSourceTrigger=PropertyChanged}"></TextBox> <TextBlock Margin="0 15 0 0" FontSize="10" Foreground="Gray">Machine Version</TextBlock> - <ComboBox ItemsSource="{Binding Adapter.MachineVersions}" SelectedItem="{Binding Machine.MachineVersions}" DisplayMemberPath="Name"></ComboBox> + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="1*"></ColumnDefinition> + <ColumnDefinition Width="80"></ColumnDefinition> + </Grid.ColumnDefinitions> + <ComboBox ItemsSource="{Binding Adapter.MachineVersions}" SelectedItem="{Binding Machine.MachineVersions}" DisplayMemberPath="Name"></ComboBox> + <Button Grid.Column="1" Command="{Binding SetVersionConfigurationCommand}" Height="25" Margin="10 2 2 2" ToolTip="Sets the current configuration to the selected machine version default configuration">SET</Button> + </Grid> <TextBlock Margin="0 15 0 0" FontSize="10" Foreground="Gray">Organization</TextBlock> <ComboBox ItemsSource="{Binding Adapter.Organizations}" SelectedItem="{Binding Machine.Organization}" DisplayMemberPath="Name"></ComboBox> @@ -806,12 +813,24 @@ </ScrollViewer> <Grid Grid.Row="1" Margin="10"> - <Button Height="50" Command="{Binding SaveCommand}" Margin="0 0 15 0"> - <StackPanel Orientation="Horizontal"> - <materialDesign:PackIcon Width="24" Height="24" VerticalAlignment="Center" Kind="ContentSaveSettings"></materialDesign:PackIcon> - <TextBlock FontSize="18" Margin="10 0 0 0" VerticalAlignment="Center">SAVE</TextBlock> - </StackPanel> - </Button> + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="61*"/> + <ColumnDefinition Width="84*"/> + </Grid.ColumnDefinitions> + <Button Height="Auto" Command="{Binding SaveCommand}" Margin="0 0 5 0"> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon Width="20" Height="20" VerticalAlignment="Center" Kind="ContentSaveSettings"></materialDesign:PackIcon> + <TextBlock FontSize="14" Margin="10 0 0 0" VerticalAlignment="Center">SAVE</TextBlock> + </StackPanel> + </Button> + <Button ToolTip="Set this configuration as a default machine configuration" Height="Auto" Background="#FF5C5C" BorderBrush="#FF5C5C" Command="{Binding SetAsDefaultCommand}" Margin="0 0 15 0" Grid.Column="1"> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon Width="20" Height="20" VerticalAlignment="Center" Kind="Verified"></materialDesign:PackIcon> + <TextBlock FontSize="14" Margin="10 0 0 0" VerticalAlignment="Center">SET DEFAULT</TextBlock> + </StackPanel> + </Button> + </Grid> </Grid> </Grid> </Grid> |
