aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-09-26 14:35:47 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-09-26 14:35:47 +0300
commitdee664eaeaf48edfa2ad2f90d6384d727dc35432 (patch)
tree12e4d9f3896812aa1358cb3d2587910447bcd53f /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs
parentb55886b8a240f597cdac1232764da0e08528fb22 (diff)
downloadTango-dee664eaeaf48edfa2ad2f90d6384d727dc35432.tar.gz
Tango-dee664eaeaf48edfa2ad2f90d6384d727dc35432.zip
Implemented Tech board tabs and project!!!
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs154
1 files changed, 148 insertions, 6 deletions
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
/// </summary>
public RelayCommand ResetHardwareConfigurationCommand { get; set; }
+ /// <summary>
+ /// Gets or sets the update graphs duration command.
+ /// </summary>
public RelayCommand UpdateGraphsDurationCommand { get; set; }
+ /// <summary>
+ /// Gets or sets the add tab command.
+ /// </summary>
+ public RelayCommand AddTabCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the remove tab command.
+ /// </summary>
+ public RelayCommand<MachineTechTabVM> RemoveTabCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the new project command.
+ /// </summary>
+ public RelayCommand NewProjectCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the rename tab command.
+ /// </summary>
+ 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<MachineTechTabVM>();
- Tabs.Add(new MachineTechTabVM() { IsSelected = true });
+ Tabs.Add(new MachineTechTabVM() { IsSelected = true, Name = "Untitled" });
SelectedTab = Tabs.First();
_settings = SettingsManager.Default.GetOrCreate<TechnicianModuleSettings>();
@@ -298,6 +324,11 @@ namespace Tango.MachineStudio.Technician.ViewModels
_settings.GraphsDuration = GraphsDurationSeconds;
ClearAllGraphs();
});
+
+ AddTabCommand = new RelayCommand(() => AddNewTab());
+ RemoveTabCommand = new RelayCommand<MachineTechTabVM>(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
/// <summary>
/// Opens a file open dialog to select a project file.
@@ -1567,8 +1598,31 @@ namespace Tango.MachineStudio.Technician.ViewModels
/// <param name="fileName">File path.</param>
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.");
+ }
}
/// <summary>
@@ -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;
}
+ /// <summary>
+ /// Removes the specified tab.
+ /// </summary>
+ /// <param name="tab">The tab.</param>
+ 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");
+ }
+ }
+ }
+
+ /// <summary>
+ /// Adds a new tab.
+ /// </summary>
+ 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;
+ }
+ }
+
+ /// <summary>
+ /// Creates a new project.
+ /// </summary>
+ private void CreateNewProject()
+ {
+ var to_remove = Tabs.ToList();
+
+ if (AddNewTab())
+ {
+ _singleControllers.Clear();
+ _multiControllers.Clear();
+
+ foreach (var tab in to_remove)
+ {
+ Tabs.Remove(tab);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Renames the tab.
+ /// </summary>
+ /// <param name="tab">The tab.</param>
+ 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