diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-01 16:40:13 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-01 16:40:13 +0200 |
| commit | eb2c264422b98458979bc96504ce8830a527d48c (patch) | |
| tree | 2c2e0bcb908867759e7bea31dad0e21bd82f9cff /Software/Visual_Studio/MachineStudio/Modules | |
| parent | a89c18abf7175f76f8673c12dac35d1658209d4e (diff) | |
| download | Tango-eb2c264422b98458979bc96504ce8830a527d48c.tar.gz Tango-eb2c264422b98458979bc96504ce8830a527d48c.zip | |
Added Tango.Video project.
Implemented USB video device capture for developer module.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules')
4 files changed, 126 insertions, 35 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index 9696f47ca..622e4f51c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -167,6 +167,10 @@ <Project>{8491d07b-c1f6-4b62-a412-41b9fd2d6538}</Project> <Name>Tango.SharedUI</Name> </ProjectReference> + <ProjectReference Include="..\..\..\Tango.Video\Tango.Video.csproj"> + <Project>{9652f972-2bd1-4283-99cb-fc6240434c17}</Project> + <Name>Tango.Video</Name> + </ProjectReference> <ProjectReference Include="..\..\Tango.MachineStudio.Common\Tango.MachineStudio.Common.csproj"> <Project>{cb0b0aa2-bb24-4bca-a720-45e397684e12}</Project> <Name>Tango.MachineStudio.Common</Name> 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 a9e71de5a..7086cfb4d 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 @@ -18,6 +18,7 @@ using System.Runtime.CompilerServices; using System.Windows.Threading; using Tango.Settings; using Tango.MachineStudio.Developer.Views; +using Tango.Video.DirectCapture; namespace Tango.MachineStudio.Developer.ViewModels { @@ -286,6 +287,10 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _isJobCanceled = value; RaisePropertyChangedAuto(); } } + /// <summary> + /// Gets or sets the capture devices. + /// </summary> + public ObservableCollection<CaptureDevice> CaptureDevices { get; set; } #endregion #region Commands @@ -365,6 +370,11 @@ namespace Tango.MachineStudio.Developer.ViewModels /// </summary> public RelayCommand CloseJobCompletionStatusCommand { get; set; } + /// <summary> + /// Gets or sets the toggle camera command. + /// </summary> + public RelayCommand<CaptureDevice> ToggleCameraCommand { get; set; } + #endregion #region Constructors @@ -412,6 +422,23 @@ namespace Tango.MachineStudio.Developer.ViewModels StartJobCommand = new RelayCommand(StartJob, () => SelectedJob != null && !IsJobRunning); StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning); CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar); + + CaptureDevices = new ObservableCollection<CaptureDevice>(); + var availableDevices = CaptureDevice.GetAvailableCaptureDevices(); + + for (int i = 0; i < 3; i++) + { + if (i > availableDevices.Count - 1) + { + CaptureDevices.Add(new CaptureDevice() { Device = null }); + } + else + { + CaptureDevices.Add(new CaptureDevice() { Device = availableDevices[i] }); + } + } + + ToggleCameraCommand = new RelayCommand<CaptureDevice>(ToggleCamera); } #endregion @@ -526,6 +553,14 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Private Methods + private void ToggleCamera(CaptureDevice captureDevice) + { + if (captureDevice.Device != null) + { + captureDevice.IsStarted = !captureDevice.IsStarted; + } + } + private void CloseJobCompletionStatusBar() { IsJobCompleted = false; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml index b2d553ff2..cf5d1e19e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml @@ -16,6 +16,7 @@ xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:observables="clr-namespace:Tango.Integration.Observables;assembly=Tango.Integration" xmlns:editors="clr-namespace:Tango.SharedUI.Editors;assembly=Tango.SharedUI" + xmlns:video="clr-namespace:Tango.Video.DirectCapture;assembly=Tango.Video" xmlns:shapes="clr-namespace:Tango.SharedUI.Shapes;assembly=Tango.SharedUI" xmlns:local="clr-namespace:Tango.MachineStudio.Developer.Views" mc:Ignorable="d" @@ -1502,46 +1503,87 @@ </Grid.Style> <Grid Margin="5 0 0 0"> - <DockPanel Height="850" VerticalAlignment="Top"> + <DockPanel x:Name="dockCameras" VerticalAlignment="Top" Height="850" Width="330" HorizontalAlignment="Right"> <StackPanel Orientation="Horizontal" DockPanel.Dock="Top"> <Image Source="../Images/camera.png" Width="42"></Image> <TextBlock VerticalAlignment="Center" Margin="10 0 0 0" Foreground="DimGray" FontSize="16" FontWeight="SemiBold">USB CAMERAS</TextBlock> </StackPanel> - <UniformGrid Rows="3"> - <Border RenderOptions.BitmapScalingMode="Fant"> - <Border.Background> - <ImageBrush ImageSource="../Images/video-frame.png" Stretch="Fill"></ImageBrush> - </Border.Background> - <Grid> - <Label Margin="22 23 0 0" Style="{StaticResource graphLabel}"> - <TextBlock FontFamily="digital-7" VerticalAlignment="Center" FontSize="10" Margin="0 0 30 0">CAMERA 1</TextBlock> - </Label> - </Grid> - </Border> - <Border RenderOptions.BitmapScalingMode="Fant"> - <Border.Background> - <ImageBrush ImageSource="../Images/video-frame.png" Stretch="Fill"></ImageBrush> - </Border.Background> + <ItemsControl ItemsSource="{Binding CaptureDevices}"> + <ItemsControl.ItemsPanel> + <ItemsPanelTemplate> + <UniformGrid Rows="3" /> + </ItemsPanelTemplate> + </ItemsControl.ItemsPanel> - <Grid> - <Label Margin="22 23 0 0" Style="{StaticResource graphLabel}"> - <TextBlock FontFamily="digital-7" VerticalAlignment="Center" FontSize="10" Margin="0 0 30 0">CAMERA 2</TextBlock> - </Label> - </Grid> - </Border> - <Border RenderOptions.BitmapScalingMode="Fant"> - <Border.Background> - <ImageBrush ImageSource="../Images/video-frame.png" Stretch="Fill"></ImageBrush> - </Border.Background> + <ItemsControl.ItemTemplate> + <DataTemplate DataType="{x:Type video:CaptureDevice}"> + <Border RenderOptions.BitmapScalingMode="Fant"> + <Border.Background> + <ImageBrush ImageSource="../Images/video-frame.png" Stretch="Fill"></ImageBrush> + </Border.Background> - <Grid> - <Label Margin="22 23 0 0" Style="{StaticResource graphLabel}"> - <TextBlock FontFamily="digital-7" VerticalAlignment="Center" FontSize="10" Margin="0 0 30 0">CAMERA 3</TextBlock> - </Label> - </Grid> - </Border> - </UniformGrid> + <Grid> + <Border Margin="22 24 23 42"> + <Grid> + <Image Source="{Binding VideoSource,Mode=OneWay,IsAsync=True}" Stretch="Fill"></Image> + + <Grid Background="#83000000" Cursor="Hand"> + <Grid.Style> + <Style TargetType="Grid"> + <Setter Property="Opacity" Value="0"></Setter> + <Style.Triggers> + <EventTrigger RoutedEvent="MouseEnter"> + <EventTrigger.Actions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="00:00:0.2"></DoubleAnimation> + </Storyboard> + </BeginStoryboard> + </EventTrigger.Actions> + </EventTrigger> + <EventTrigger RoutedEvent="MouseLeave"> + <EventTrigger.Actions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimation Storyboard.TargetProperty="Opacity" To="0" Duration="00:00:0.2"></DoubleAnimation> + </Storyboard> + </BeginStoryboard> + </EventTrigger.Actions> + </EventTrigger> + </Style.Triggers> + </Style> + </Grid.Style> + + <Button Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.ToggleCameraCommand}" CommandParameter="{Binding}" Style="{StaticResource MaterialDesignFloatingActionMiniButton}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="60" Height="60" Padding="0"> + <materialDesign:PackIcon Width="40" Height="40"> + <materialDesign:PackIcon.Style> + <Style TargetType="materialDesign:PackIcon"> + <Setter Property="Kind" Value="Play"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding IsStarted}" Value="True"> + <Setter Property="Kind" Value="Stop"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding IsStarted}" Value="False"> + <Setter Property="Kind" Value="Play"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </materialDesign:PackIcon.Style> + </materialDesign:PackIcon> + </Button> + </Grid> + </Grid> + </Border> + + <Label Margin="22 23 0 0" Style="{StaticResource graphLabel}"> + <TextBlock VerticalAlignment="Center" FontSize="10" Margin="0 0 30 0" Text="{Binding Device.Name,FallbackValue='No Camera',TargetNullValue='No Camera'}"></TextBlock> + </Label> + </Grid> + </Border> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> </DockPanel> </Grid> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs index cdf2248a6..16427c42b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs @@ -54,8 +54,18 @@ namespace Tango.MachineStudio.Developer.Views ViewAttached?.Invoke(this, this); }; - chkGraphs.Checked += (x, y) => { graphRowDefinition.Height = new GridLength(440, GridUnitType.Pixel); }; - chkGraphs.Unchecked += (x, y) => { graphRowDefinition.Height = new GridLength(80, GridUnitType.Pixel); }; + chkGraphs.Checked += (x, y) => + { + graphRowDefinition.Height = new GridLength(440, GridUnitType.Pixel); + //dockCameras.Width = 270; + //dockCameras.Height = 600; + }; + chkGraphs.Unchecked += (x, y) => + { + graphRowDefinition.Height = new GridLength(80, GridUnitType.Pixel); + //dockCameras.Width = 330; + //dockCameras.Height = 850; + }; _jobBrushTimer = new DispatcherTimer(); _jobBrushTimer.Interval = TimeSpan.FromSeconds(1); |
