From dee664eaeaf48edfa2ad2f90d6384d727dc35432 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 26 Sep 2018 14:35:47 +0300 Subject: Implemented Tech board tabs and project!!! --- .../Build/Shortcuts/Machine Emulator.lnk | Bin 1471 -> 1455 bytes .../Build/Shortcuts/Proto Compiler GUI.lnk | Bin 1464 -> 1448 bytes .../Project/MachineTechViewProject.cs | 7 + .../Tango.MachineStudio.Technician.csproj | 9 +- .../ViewModels/MachineTechViewVM.cs | 154 ++++++++++++++++++++- .../Views/MachineTechTabView.xaml | 13 -- .../Views/MachineTechTabView.xaml.cs | 28 ---- .../Views/MachineTechView.xaml | 107 ++++++++++---- .../Controls/RealTimeGraphControl.xaml | 8 +- .../Controls/RealTimeGraphMultiControl.xaml | 8 +- .../Resources/MaterialDesign.xaml | 2 +- .../Notifications/TextInputBoxWindow.xaml.cs | 12 +- 12 files changed, 252 insertions(+), 96 deletions(-) delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml.cs (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk index 72aadc5cf..bcc3c888a 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk b/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk index edc2f528f..8472e8003 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk and b/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Project/MachineTechViewProject.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Project/MachineTechViewProject.cs index 0837fde53..2e7ba6cf7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Project/MachineTechViewProject.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Project/MachineTechViewProject.cs @@ -10,10 +10,17 @@ namespace Tango.MachineStudio.Technician.Project { public class MachineTechViewProject { + +#warning This is legacy and should be removed + public List Items { get; set; } + public List Tabs { get; set; } + public int SelectedTabIndex { get; set; } + public MachineTechViewProject() { + Items = new List(); Tabs = new List(); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj index 4df317c6a..38868a649 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj @@ -264,9 +264,6 @@ - - MachineTechTabView.xaml - MachineTechView.xaml @@ -442,10 +439,6 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - MSBuild:Compile Designer @@ -667,7 +660,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index 85a431594..738e871c9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -33,6 +33,7 @@ using Tango.MachineStudio.Common; using Tango.Core.Commands; using Tango.MachineStudio.Technician.Helpers; using Tango.MachineStudio.Technician.Models; +using Tango.Logging; namespace Tango.MachineStudio.Technician.ViewModels { @@ -88,7 +89,10 @@ namespace Tango.MachineStudio.Technician.ViewModels tab.IsSelected = false; } - _selectedTab.IsSelected = true; + if (_selectedTab != null) + { + _selectedTab.IsSelected = true; + } } } @@ -231,8 +235,30 @@ namespace Tango.MachineStudio.Technician.ViewModels /// public RelayCommand ResetHardwareConfigurationCommand { get; set; } + /// + /// Gets or sets the update graphs duration command. + /// public RelayCommand UpdateGraphsDurationCommand { get; set; } + /// + /// Gets or sets the add tab command. + /// + public RelayCommand AddTabCommand { get; set; } + + /// + /// Gets or sets the remove tab command. + /// + public RelayCommand RemoveTabCommand { get; set; } + + /// + /// Gets or sets the new project command. + /// + public RelayCommand NewProjectCommand { get; set; } + + /// + /// Gets or sets the rename tab command. + /// + public RelayCommand RenameTabCommand { get; set; } #endregion #region Constructors @@ -245,7 +271,7 @@ namespace Tango.MachineStudio.Technician.ViewModels public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider diagnosticsFrameProvider, IEventLogger eventLogger) { Tabs = new ObservableCollection(); - Tabs.Add(new MachineTechTabVM() { IsSelected = true }); + Tabs.Add(new MachineTechTabVM() { IsSelected = true, Name = "Untitled" }); SelectedTab = Tabs.First(); _settings = SettingsManager.Default.GetOrCreate(); @@ -298,6 +324,11 @@ namespace Tango.MachineStudio.Technician.ViewModels _settings.GraphsDuration = GraphsDurationSeconds; ClearAllGraphs(); }); + + AddTabCommand = new RelayCommand(() => AddNewTab()); + RemoveTabCommand = new RelayCommand(RemoveTab); + NewProjectCommand = new RelayCommand(CreateNewProject); + RenameTabCommand = new RelayCommand(RenameTab); } #endregion @@ -1544,7 +1575,7 @@ namespace Tango.MachineStudio.Technician.ViewModels #endregion - #region Public Methods + #region Project Management /// /// Opens a file open dialog to select a project file. @@ -1567,8 +1598,31 @@ namespace Tango.MachineStudio.Technician.ViewModels /// File path. public void OpenProjectFile(String fileName) { - LoadProject(MachineTechViewProject.Load(fileName)); - _lastTechProjectFile = fileName; + try + { + MachineTechViewProject project = null; + + project = MachineTechViewProject.Load(fileName); + + if (project.Tabs.Count == 0) + { + LogManager.Log($"Error loading project file {fileName}. Trying to load using legacy project loader.", LogCategory.Warning); + + MachineTechViewProjectTab tab = new MachineTechViewProjectTab(); + tab.Name = "Untitled"; + tab.Items.AddRange(project.Items); + project.Items.Clear(); + project.Tabs.Add(tab); + } + + LoadProject(project); + _lastTechProjectFile = fileName; + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error loading project file {fileName}."); + _notification.ShowError("An error occurred while trying to load the tech board project file."); + } } /// @@ -1587,9 +1641,10 @@ namespace Tango.MachineStudio.Technician.ViewModels { MachineTechTabVM t = new MachineTechTabVM(); t.Name = tab.Name; - t.IsSelected = true; Tabs.Add(t); + SelectedTab = t; + foreach (var item in tab.Items) { if (item is MotorGroupItem) @@ -1600,6 +1655,8 @@ namespace Tango.MachineStudio.Technician.ViewModels AddTechItem(item); } } + + SelectedTab = Tabs.ElementAt(project.SelectedTabIndex); } } @@ -1654,6 +1711,7 @@ namespace Tango.MachineStudio.Technician.ViewModels private MachineTechViewProject GenerateProjectFile() { MachineTechViewProject project = new MachineTechViewProject(); + project.SelectedTabIndex = Tabs.IndexOf(SelectedTab); foreach (var tab in Tabs) { @@ -1678,6 +1736,90 @@ namespace Tango.MachineStudio.Technician.ViewModels return project; } + /// + /// Removes the specified tab. + /// + /// The tab. + private void RemoveTab(MachineTechTabVM tab) + { + if (_notification.ShowQuestion("Are you sure you want to delete the selected tab?")) + { + Tabs.Remove(tab); + SelectedTab = Tabs.LastOrDefault(); + + if (SelectedTab == null) + { + AddNewTab("Untitled"); + } + } + } + + /// + /// Adds a new tab. + /// + private bool AddNewTab(String name = null) + { + if (Tabs.Count > 7) + { + _notification.ShowError("Cannot exceed the maximum number of 8 tabs. You can remove a tab, or create a new project."); + return false; + } + + if (name == null) + { + name = _notification.ShowTextInput("Enter tab name", "Tab Name", "Untitled"); + } + + if (!String.IsNullOrWhiteSpace(name)) + { + MachineTechTabVM t = new MachineTechTabVM(); + t.Name = name; + Tabs.Add(t); + SelectedTab = t; + return true; + } + else + { + return false; + } + } + + /// + /// Creates a new project. + /// + private void CreateNewProject() + { + var to_remove = Tabs.ToList(); + + if (AddNewTab()) + { + _singleControllers.Clear(); + _multiControllers.Clear(); + + foreach (var tab in to_remove) + { + Tabs.Remove(tab); + } + } + } + + /// + /// Renames the tab. + /// + /// The tab. + private void RenameTab() + { + if (SelectedTab != null) + { + var name = _notification.ShowTextInput("Enter tab name", "Tab Name", SelectedTab.Name); + + if (!String.IsNullOrWhiteSpace(name)) + { + SelectedTab.Name = name; + } + } + } + #endregion #region IStudioModuleVM diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml deleted file mode 100644 index fc14343a2..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml.cs deleted file mode 100644 index 38b1ae045..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -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.Technician.Views -{ - /// - /// Interaction logic for MachineTechTabView.xaml - /// - public partial class MachineTechTabView : UserControl - { - public MachineTechTabView() - { - InitializeComponent(); - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml index 99ecf72f2..dec4cee44 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml @@ -134,6 +134,12 @@ + + + + + + @@ -152,58 +158,58 @@ - + - + - + - + - + - + - + - + - + - + @@ -355,28 +361,73 @@ - + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml index 74ce549bf..bf2e41afa 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml @@ -56,13 +56,13 @@ - + - + @@ -72,8 +72,8 @@ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphMultiControl.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphMultiControl.xaml index c5ecf60d5..4976739e4 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphMultiControl.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphMultiControl.xaml @@ -56,13 +56,13 @@ - + - + @@ -72,8 +72,8 @@ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml index eea369dfe..acddeec6e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml @@ -251,7 +251,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/TextInputBoxWindow.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/TextInputBoxWindow.xaml.cs index d774c14eb..bc11dfd18 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/TextInputBoxWindow.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/TextInputBoxWindow.xaml.cs @@ -26,6 +26,14 @@ namespace Tango.MachineStudio.UI.Notifications { InitializeComponent(); this.Loaded += TextInputBoxWindow_Loaded; + + ContentRendered += TextInputBoxWindow_ContentRendered; + } + + private void TextInputBoxWindow_ContentRendered(object sender, EventArgs e) + { + txtText.Focus(); + txtText.SelectAll(); } private void TextInputBoxWindow_Loaded(object sender, RoutedEventArgs e) @@ -34,12 +42,8 @@ namespace Tango.MachineStudio.UI.Notifications ani.To = 1; ani.Duration = TimeSpan.FromSeconds(0.5); this.BeginAnimation(Window.OpacityProperty, ani); - - txtText.Focus(); } - - public String Hint { get { return (String)GetValue(HintProperty); } -- cgit v1.3.1