connect new gui to vr engine
This commit is contained in:
@@ -10,5 +10,7 @@ namespace ClientApp.Models
|
|||||||
public bool ConnectedToServer { get; set; }
|
public bool ConnectedToServer { get; set; }
|
||||||
public bool ConnectedToVREngine { get; set; }
|
public bool ConnectedToVREngine { get; set; }
|
||||||
public bool DoctorConnected { get; set; }
|
public bool DoctorConnected { get; set; }
|
||||||
|
|
||||||
|
public bool CanConnectToVR { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,18 @@ using ProftaakRH;
|
|||||||
|
|
||||||
namespace ClientApp.Utils
|
namespace ClientApp.Utils
|
||||||
{
|
{
|
||||||
|
public delegate void EngineCallback();
|
||||||
public class Client : IDataReceiver
|
public class Client : IDataReceiver
|
||||||
{
|
{
|
||||||
|
public EngineCallback engineConnectFailed;
|
||||||
|
public EngineCallback engineConnectSuccess;
|
||||||
private TcpClient client;
|
private TcpClient client;
|
||||||
private NetworkStream stream;
|
private NetworkStream stream;
|
||||||
private byte[] buffer = new byte[1024];
|
private byte[] buffer = new byte[1024];
|
||||||
private bool connected;
|
private bool connected;
|
||||||
private byte[] totalBuffer = new byte[1024];
|
private byte[] totalBuffer = new byte[1024];
|
||||||
private int totalBufferReceived = 0;
|
private int totalBufferReceived = 0;
|
||||||
private EngineConnection engineConnection;
|
public EngineConnection engineConnection;
|
||||||
private bool sessionRunning = false;
|
private bool sessionRunning = false;
|
||||||
private IHandler handler = null;
|
private IHandler handler = null;
|
||||||
private LoginViewModel LoginViewModel;
|
private LoginViewModel LoginViewModel;
|
||||||
@@ -40,7 +43,7 @@ namespace ClientApp.Utils
|
|||||||
private void initEngine()
|
private void initEngine()
|
||||||
{
|
{
|
||||||
engineConnection = EngineConnection.INSTANCE;
|
engineConnection = EngineConnection.INSTANCE;
|
||||||
engineConnection.OnNoTunnelId = retryEngineConnection;
|
engineConnection.OnNoTunnelId = RetryEngineConnection;
|
||||||
engineConnection.OnSuccessFullConnection = engineConnected;
|
engineConnection.OnSuccessFullConnection = engineConnected;
|
||||||
if (!engineConnection.Connected) engineConnection.Connect();
|
if (!engineConnection.Connected) engineConnection.Connect();
|
||||||
}
|
}
|
||||||
@@ -48,24 +51,16 @@ namespace ClientApp.Utils
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// retries to connect to the VR engine if no tunnel id was found
|
/// retries to connect to the VR engine if no tunnel id was found
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void retryEngineConnection()
|
public void RetryEngineConnection()
|
||||||
{
|
{
|
||||||
Console.WriteLine("-- Could not connect to the VR engine. Please make sure you are running the simulation!");
|
engineConnectFailed?.Invoke();
|
||||||
Console.WriteLine("-- Press ENTER to retry connecting to the VR engine.");
|
|
||||||
Console.WriteLine("-- Press 'q' and then ENTER to not connect to the VR engine");
|
|
||||||
string input = Console.ReadLine();
|
|
||||||
if (input == string.Empty) engineConnection.CreateConnection();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("Skipping connecting to VR engine...");
|
|
||||||
engineConnection.Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void engineConnected()
|
private void engineConnected()
|
||||||
{
|
{
|
||||||
Console.WriteLine("successfully connected to VR engine");
|
Console.WriteLine("successfully connected to VR engine");
|
||||||
|
engineConnectSuccess?.Invoke();
|
||||||
engineConnection.initScene();
|
engineConnection.initScene();
|
||||||
if (engineConnection.Connected && sessionRunning && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
|
if (engineConnection.Connected && sessionRunning && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
|
||||||
}
|
}
|
||||||
@@ -126,6 +121,7 @@ namespace ClientApp.Utils
|
|||||||
this.LoginViewModel.setLoginStatus(true);
|
this.LoginViewModel.setLoginStatus(true);
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
initEngine();
|
initEngine();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace ClientApp.ViewModels
|
|||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
public ICommand LoginCommand { get; set; }
|
public ICommand LoginCommand { get; set; }
|
||||||
public bool LoginStatus { get; set; }
|
public bool LoginStatus { get; set; }
|
||||||
|
|
||||||
private MainWindowViewModel mainWindowViewModel;
|
private MainWindowViewModel mainWindowViewModel;
|
||||||
public LoginViewModel(MainWindowViewModel mainWindowViewModel)
|
public LoginViewModel(MainWindowViewModel mainWindowViewModel)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,10 +11,14 @@ namespace ClientApp.ViewModels
|
|||||||
public ICommand RetryVREngineCommand { get; set; }
|
public ICommand RetryVREngineCommand { get; set; }
|
||||||
public MainWindowViewModel MainWindowViewModel { get; set; }
|
public MainWindowViewModel MainWindowViewModel { get; set; }
|
||||||
|
|
||||||
|
private Client client;
|
||||||
|
|
||||||
public MainViewModel(MainWindowViewModel mainWindowViewModel)
|
public MainViewModel(MainWindowViewModel mainWindowViewModel)
|
||||||
{
|
{
|
||||||
this.MainWindowViewModel = mainWindowViewModel;
|
this.MainWindowViewModel = mainWindowViewModel;
|
||||||
|
client = this.MainWindowViewModel.client;
|
||||||
|
client.engineConnectFailed = retryEngineConnection;
|
||||||
|
client.engineConnectSuccess = succesEngineConnection;
|
||||||
this.RetryServerCommand = new RelayCommand(() =>
|
this.RetryServerCommand = new RelayCommand(() =>
|
||||||
{
|
{
|
||||||
//try connect server
|
//try connect server
|
||||||
@@ -23,8 +27,28 @@ namespace ClientApp.ViewModels
|
|||||||
this.RetryVREngineCommand = new RelayCommand(() =>
|
this.RetryVREngineCommand = new RelayCommand(() =>
|
||||||
{
|
{
|
||||||
//try connect vr-engine
|
//try connect vr-engine
|
||||||
|
|
||||||
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = true;
|
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = true;
|
||||||
|
this.MainWindowViewModel.InfoModel.CanConnectToVR = false;
|
||||||
|
client.engineConnection.CreateConnection();
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void retryEngineConnection()
|
||||||
|
{
|
||||||
|
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = false;
|
||||||
|
this.MainWindowViewModel.InfoModel.CanConnectToVR = true;
|
||||||
|
client.engineConnection.CreateConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void succesEngineConnection()
|
||||||
|
{
|
||||||
|
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = true;
|
||||||
|
this.MainWindowViewModel.InfoModel.CanConnectToVR = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
</Button.Content>
|
</Button.Content>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button Grid.Column="1" Grid.Row="1" Command="{Binding RetryVREngineCommand}" Width="50" Height="20">
|
<Button Grid.Column="1" Grid.Row="1" Command="{Binding RetryVREngineCommand}" Width="50" Height="20" IsEnabled="{Binding MainWindowViewModel.InfoModel.CanConnectToVR}">
|
||||||
<Button.Content>
|
<Button.Content>
|
||||||
<TextBlock TextWrapping="Wrap" Text="retry"/>
|
<TextBlock TextWrapping="Wrap" Text="retry"/>
|
||||||
</Button.Content>
|
</Button.Content>
|
||||||
|
|||||||
Reference in New Issue
Block a user