diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2017-12-13 18:50:24 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2017-12-13 18:50:24 +0200 |
| commit | 471daec51d0fc9437f8551d5d48c9fa2fb031871 (patch) | |
| tree | 1ecd78d48d761c18936b311d4e3d8eb8ebfb3cd1 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI | |
| parent | 2a51f05523c1397b77eca5e5188520919205638c (diff) | |
| download | Tango-471daec51d0fc9437f8551d5d48c9fa2fb031871.tar.gz Tango-471daec51d0fc9437f8551d5d48c9fa2fb031871.zip | |
Machine Studio, Dynamic Module Loading...
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs | 81 | ||||
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml | 138 |
2 files changed, 179 insertions, 40 deletions
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 00571007c..5fb4b436d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -1,8 +1,13 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.MachineStudio.Common; using Tango.MachineStudio.UI.SupervisingController; using Tango.SharedUI; @@ -10,11 +15,87 @@ namespace Tango.MachineStudio.UI.ViewModels { public class MainViewVM : ViewModel<IMainView> { + public ObservableCollection<IStudioModule> Modules { get; set; } + + private IStudioModule _currentModule; + + public IStudioModule CurrentModule + { + get { return _currentModule; } + set { _currentModule = value; RaisePropertyChangedAuto(); } + } + + private bool _isMenuOpened; + + public bool IsMenuOpened + { + get { return _isMenuOpened; } + set { _isMenuOpened = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand<IStudioModule> StartModuleCommand { get; set; } + + public RelayCommand HomeCommand { get; set; } + public String Text { get; set; } public MainViewVM(IMainView view) : base(view) { + Modules = new ObservableCollection<IStudioModule>(); + + LoadModules(); + Text = "Hi ROy"; + + StartModuleCommand = new RelayCommand<IStudioModule>(StartModule); + + HomeCommand = new RelayCommand(Home); + } + + private void LoadModules() + { + string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + + foreach (var file in Directory.GetFiles(assemblyFolder, "*.dll").Where(x => x.Contains("MachineStudio"))) + { + try + { + Assembly moduleAssembly = null; + String pdbFile = Path.ChangeExtension(file, ".pdb"); + var data = File.ReadAllBytes(file); + + if (File.Exists(pdbFile)) + { + var pdbData = File.ReadAllBytes(pdbFile); + moduleAssembly = Assembly.Load(data, pdbData); + } + else + { + moduleAssembly = Assembly.Load(data); + } + + if (moduleAssembly != null) + { + foreach (var moduleType in moduleAssembly.GetTypes().Where(x => !x.IsInterface && typeof(IStudioModule).IsAssignableFrom(x))) + { + var module = Activator.CreateInstance(moduleType) as IStudioModule; + Modules.Add(module); + } + } + } + catch { } + } + } + + private void Home() + { + StartModule(null); + } + + private void StartModule(IStudioModule module) + { + IsMenuOpened = false; + CurrentModule = module; } protected override void OnViewAttached() diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml index f8424b26d..ad366ce9a 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml @@ -15,12 +15,18 @@ <materialDesign:DrawerHost IsLeftDrawerOpen="{Binding ElementName=MenuToggleButton, Path=IsChecked}"> <materialDesign:DrawerHost.LeftDrawerContent> <DockPanel MinWidth="212"> - <ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}" - DockPanel.Dock="Top" + <Grid DockPanel.Dock="Top"> + <ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}" HorizontalAlignment="Right" Margin="16" IsChecked="{Binding ElementName=MenuToggleButton, Path=IsChecked, Mode=TwoWay}" /> + + <StackPanel Margin="5 0 0 0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center"> + <materialDesign:PackIcon VerticalAlignment="Center" Kind="Account" Foreground="{StaticResource AccentColorBrush}" Width="32" Height="32"></materialDesign:PackIcon> + <TextBlock Margin="10 0 0 0" VerticalAlignment="Center">User Name</TextBlock> + </StackPanel> + </Grid> <ListBox x:Name="DemoItemsListBox" Margin="0 16 0 16" SelectedIndex="0"> - <ListBoxItem>Item 1</ListBoxItem> + <Button Command="{Binding HomeCommand}" Style="{DynamicResource MaterialDesignFlatButton}">Home</Button> <ListBoxItem>Item 2</ListBoxItem> <ListBoxItem>Item 3</ListBoxItem> <ListBoxItem>Item 4</ListBoxItem> @@ -32,11 +38,11 @@ <materialDesign:ColorZone Padding="16" materialDesign:ShadowAssist.ShadowDepth="Depth2" Mode="PrimaryMid" DockPanel.Dock="Top"> <DockPanel> - <ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}" IsChecked="False" + <ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}" IsChecked="{Binding IsMenuOpened}" x:Name="MenuToggleButton"/> <materialDesign:PopupBox DockPanel.Dock="Right" PlacementMode="BottomAndAlignRightEdges" StaysOpen="False"> <StackPanel> - <Button Content="Hello World"/> + <Button Content="Home"/> <Button Content="Nice Popup"/> <Button Content="Can't Touch This" IsEnabled="False" /> <Separator/> @@ -52,44 +58,96 @@ <Grid> <Grid> - <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition Height="1*"/> + </Grid.RowDefinitions> + + <Grid Grid.Row="1"> + <Grid.RowDefinitions> + <RowDefinition Height="150"/> + <RowDefinition Height="*"/> + </Grid.RowDefinitions> <Grid> - <Grid.RowDefinitions> - <RowDefinition Height="Auto"/> - <RowDefinition Height="1*"/> - </Grid.RowDefinitions> + <StackPanel Margin="30 20" HorizontalAlignment="Left"> + <TextBlock Style="{StaticResource MaterialDesignDisplay1TextBlock}">Welcome to Machine Studio</TextBlock> + <TextBlock HorizontalAlignment="Right" Margin="0 5 -130 0" FontStyle="Italic" Style="{StaticResource MaterialDesignSubheadingTextBlock}" Foreground="{StaticResource AccentColorBrush}">Select Your Studio Module...</TextBlock> + </StackPanel> + </Grid> + <ItemsControl ItemsSource="{Binding Modules}" Grid.Row="2" Margin="10"> + <ItemsControl.ItemsPanel> + <ItemsPanelTemplate> + <WrapPanel IsItemsHost="True"></WrapPanel> + </ItemsPanelTemplate> + </ItemsControl.ItemsPanel> + + <ItemsControl.ItemTemplate> + <DataTemplate> + <materialDesign:Card Width="300" Margin="10" Height="400"> + <Grid > + <Grid.RowDefinitions> + <RowDefinition Height="180" /> + <RowDefinition Height="*" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + <Image Source="{Binding Image,Mode=OneWay}" Stretch="Fill" RenderOptions.BitmapScalingMode="Fant" /> + <Button Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.StartModuleCommand}" CommandParameter="{Binding}" Grid.Row="0" Margin="0,0,20,-35" HorizontalAlignment="Right" Width="70" Height="70" VerticalAlignment="Bottom" Style="{StaticResource MaterialDesignFloatingActionMiniButton}" ToolTip="Start This Module"> + <materialDesign:PackIcon Kind="Play" Width="30" Height="30" /> + </Button> + <StackPanel Grid.Row="1" Margin="8,24,8,0"> + <TextBlock FontWeight="Bold" FontSize="20" Text="{Binding Name,Mode=OneWay}"></TextBlock> + <TextBlock VerticalAlignment="Center" Margin="0 5 0 0" FontSize="14" TextWrapping="Wrap" Text="{Binding Description,Mode=OneWay}"></TextBlock> + </StackPanel> + <StackPanel Grid.Row="2" Margin="8" HorizontalAlignment="Right" Orientation="Horizontal"> + <materialDesign:PopupBox Padding="2,0,2,0" Style="{StaticResource MaterialDesignToolPopupBox}"> + <StackPanel> + <Button Content="More" /> + <Button Content="Options" /> + </StackPanel> + </materialDesign:PopupBox> + </StackPanel> + </Grid> + </materialDesign:Card> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + </Grid> - <Grid Grid.Row="1"> - <db:MainDBView></db:MainDBView> - </Grid> + <Grid Grid.Row="1" RenderTransformOrigin="0.5,0.5"> + <Grid.Style> + <Style TargetType="Grid"> + <Setter Property="RenderTransform"> + <Setter.Value> + <ScaleTransform ScaleX="0" ScaleY="0"></ScaleTransform> + </Setter.Value> + </Setter> + <Setter Property="Opacity" Value="0"></Setter> - <!--<dragablz:TabablzControl BorderThickness="0" FontSize="14" ItemContainerStyle="{DynamicResource TabItemStyle}"> - <dragablz:TabablzControl.Resources> - <Style x:Key="TabItemStyle" TargetType="{x:Type dragablz:DragablzItem}" BasedOn="{StaticResource MaterialDesignDragableTabItemStyle}"> - <Setter Property="Height" Value="60" /> - <Setter Property="Padding" Value="24,0,24,0" /> - </Style> - </dragablz:TabablzControl.Resources> - <dragablz:TabablzControl.InterTabController> - <dragablz:InterTabController /> - </dragablz:TabablzControl.InterTabController> - <TabItem Header="ORGANIZATIONS"> - <local:OrganizationsView></local:OrganizationsView> - </TabItem> - <TabItem Header="MACHINES"> - <local:MachinesView></local:MachinesView> - </TabItem> - <TabItem Header="ADDRESSES"> - <local:AddressesView></local:AddressesView> - </TabItem> - <TabItem Header="DISPENSERS"> - <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">Looks Quite Nice</TextBlock> - </TabItem> - <TabItem Header="MEDIA LIST"> - <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">Looks Quite Nice</TextBlock> - </TabItem> - </dragablz:TabablzControl>--> - </Grid> + <Style.Triggers> + <DataTrigger Binding="{Binding CurrentModule}" Value="{x:Null}"> + <DataTrigger.EnterActions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="0" Duration="00:00:0.2"></DoubleAnimation> + <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" To="0" Duration="00:00:0.2"></DoubleAnimation> + <DoubleAnimation Storyboard.TargetProperty="Opacity" To="0" Duration="00:00:0.2"></DoubleAnimation> + </Storyboard> + </BeginStoryboard> + </DataTrigger.EnterActions> + <DataTrigger.ExitActions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="1" Duration="00:00:0.2"></DoubleAnimation> + <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" To="1" Duration="00:00:0.2"></DoubleAnimation> + <DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="00:00:0.2"></DoubleAnimation> + </Storyboard> + </BeginStoryboard> + </DataTrigger.ExitActions> + </DataTrigger> + </Style.Triggers> + </Style> + </Grid.Style> + <ContentPresenter Content="{Binding CurrentModule.MainView}"></ContentPresenter> </Grid> </Grid> </Grid> |
