diff --git a/CtrEditor.csproj b/CtrEditor.csproj
index 36e5d46..eab6b69 100644
--- a/CtrEditor.csproj
+++ b/CtrEditor.csproj
@@ -15,6 +15,11 @@
+
+
+
+
+
@@ -48,6 +53,11 @@
+
+
+
+
+
diff --git a/Icons/connect.png b/Icons/connect.png
new file mode 100644
index 0000000..4a0bf70
Binary files /dev/null and b/Icons/connect.png differ
diff --git a/Icons/disconnect.png b/Icons/disconnect.png
new file mode 100644
index 0000000..2b6be8a
Binary files /dev/null and b/Icons/disconnect.png differ
diff --git a/Icons/save.png b/Icons/save.png
new file mode 100644
index 0000000..18320c7
Binary files /dev/null and b/Icons/save.png differ
diff --git a/Icons/start.png b/Icons/start.png
new file mode 100644
index 0000000..c43be3f
Binary files /dev/null and b/Icons/start.png differ
diff --git a/Icons/stop.png b/Icons/stop.png
new file mode 100644
index 0000000..eb7d756
Binary files /dev/null and b/Icons/stop.png differ
diff --git a/MainViewModel.cs b/MainViewModel.cs
index ddaeae2..9be5ac6 100644
--- a/MainViewModel.cs
+++ b/MainViewModel.cs
@@ -38,8 +38,10 @@ namespace CtrEditor
public ObservableCollection listaImagenes { get; private set; } // Publicación de las claves del diccionario
public ObservableCollection ListaOsBase { get; } = new ObservableCollection();
private ObservableCollection _objetosSimulables = new ObservableCollection();
- public PLCViewModel _plcViewModelData;
+ public PLCViewModel plcViewModelData;
public Stopwatch stopwatch;
+ private bool isSimulationRunning;
+ private bool isConnected;
public SimulationManagerFP simulationManager = new SimulationManagerFP();
@@ -49,6 +51,11 @@ namespace CtrEditor
public ICommand StopSimulationCommand { get; }
public ICommand ItemDoubleClickCommand { get; private set; }
+ public ICommand TBStartSimulationCommand { get; }
+ public ICommand TBStopSimulationCommand { get; }
+ public ICommand TBSaveCommand { get; }
+ public ICommand TBConnectPLCCommand { get; }
+ public ICommand TBDisconnectPLCCommand { get; }
// Evento que se dispara cuando se selecciona una nueva imagen
public event EventHandler ImageSelected;
@@ -61,8 +68,8 @@ namespace CtrEditor
datosDeTrabajo = new DatosDeTrabajo();
// Inicializa el PLCViewModel
- _plcViewModelData = new PLCViewModel();
- _plcViewModelData.RefreshEvent += OnRefreshEvent;
+ plcViewModelData = new PLCViewModel();
+ plcViewModelData.RefreshEvent += OnRefreshEvent;
InitializeTipoSimulableList();
@@ -75,6 +82,12 @@ namespace CtrEditor
StartSimulationCommand = new RelayCommand(StartSimulation);
StopSimulationCommand = new RelayCommand(StopSimulation);
+ TBStartSimulationCommand = new RelayCommand(StartSimulation, () => !IsSimulationRunning);
+ TBStopSimulationCommand = new RelayCommand(StopSimulation, () => IsSimulationRunning);
+ TBSaveCommand = new RelayCommand(Save);
+ TBConnectPLCCommand = new RelayCommand(ConnectPLC, () => !IsConnected);
+ TBDisconnectPLCCommand = new RelayCommand(DisconnectPLC, () => IsConnected);
+
stopwatch = new Stopwatch();
}
@@ -128,6 +141,27 @@ namespace CtrEditor
}
}
+ public bool IsSimulationRunning
+ {
+ get => isSimulationRunning;
+ set
+ {
+ isSimulationRunning = value;
+ OnPropertyChanged(nameof(IsSimulationRunning));
+ CommandManager.InvalidateRequerySuggested(); // Notificar que el estado de los comandos ha cambiado
+ }
+ }
+
+ public bool IsConnected
+ {
+ get => isConnected;
+ set
+ {
+ isConnected = value;
+ OnPropertyChanged(nameof(IsConnected));
+ CommandManager.InvalidateRequerySuggested();
+ }
+ }
private void StartSimulation()
{
@@ -138,12 +172,14 @@ namespace CtrEditor
_timerSimulacion.Start();
simulationManager.stopwatch.Start();
+ IsSimulationRunning = true;
}
private void StopSimulation()
{
_timerSimulacion.Stop();
simulationManager.stopwatch.Stop();
+ IsSimulationRunning = false;
}
private void OnTickSimulacion(object sender, EventArgs e)
@@ -159,10 +195,23 @@ namespace CtrEditor
}
+ private void ConnectPLC()
+ {
+ plcViewModelData.Connect();
+ }
+
+ private void DisconnectPLC()
+ {
+ plcViewModelData.Disconnect();
+ IsConnected = false;
+ }
+
private void OnRefreshEvent(object sender, EventArgs e)
{
- if (_plcViewModelData.IsConnected)
+ if (plcViewModelData.IsConnected)
{
+ if (!isConnected)
+ IsConnected = true;
// Detener el cronómetro y obtener el tiempo transcurrido en milisegundos
stopwatch.Stop();
float elapsedMilliseconds = (float)stopwatch.Elapsed.TotalMilliseconds;
@@ -171,7 +220,7 @@ namespace CtrEditor
stopwatch.Restart();
foreach (var objetoSimulable in ObjetosSimulables)
- objetoSimulable.UpdatePLC(_plcViewModelData.PLCInterface, (int) elapsedMilliseconds);
+ objetoSimulable.UpdatePLC(plcViewModelData.PLCInterface, (int) elapsedMilliseconds);
} else
stopwatch.Stop();
@@ -206,10 +255,10 @@ namespace CtrEditor
public PLCViewModel PLCViewModel
{
- get { return _plcViewModelData; }
+ get { return plcViewModelData; }
set
{
- _plcViewModelData = value;
+ plcViewModelData = value;
OnPropertyChanged(nameof(PLCViewModel));
}
}
@@ -350,7 +399,7 @@ namespace CtrEditor
PixelToMeter.Instance.calc = simulationData.UnitConverter;
// Re-register to the events
- _plcViewModelData.RefreshEvent += OnRefreshEvent;
+ plcViewModelData.RefreshEvent += OnRefreshEvent;
// Recorrer la colección de objetos simulables
foreach (var objetoSimulable in ObjetosSimulables)
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 7cdae76..d7a6a26 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -9,15 +9,35 @@
Height="900" Width="1600"
ResizeMode="CanResize" Title="{Binding directorioTrabajo}">
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+