diff --git a/CtrEditor.csproj b/CtrEditor.csproj
index 6f4af59..01e6ff4 100644
--- a/CtrEditor.csproj
+++ b/CtrEditor.csproj
@@ -44,6 +44,10 @@
+
+
+
+
@@ -85,6 +89,10 @@
+
+
+
+
C:\Program Files (x86)\Common Files\Siemens\PLCSIMADV\API\6.0\Siemens.Simatic.Simulation.Runtime.Api.x64.dll
@@ -111,6 +119,8 @@
+
+
diff --git a/CtrEditor.sln b/CtrEditor.sln
index 26884fd..dceba64 100644
--- a/CtrEditor.sln
+++ b/CtrEditor.sln
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34723.18
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CtrEditor", "CtrEditor.csproj", "{A4DC96D9-6C55-42ED-8E29-DCBC8D7AB831}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CtrEditor", "CtrEditor.csproj", "{A4DC96D9-6C55-42ED-8E29-DCBC8D7AB831}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibS7Adv", "..\Libraries\LibS7Adv\LibS7Adv.csproj", "{86A7FED2-AEB1-4766-819F-C6256FA7DD38}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +17,10 @@ Global
{A4DC96D9-6C55-42ED-8E29-DCBC8D7AB831}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4DC96D9-6C55-42ED-8E29-DCBC8D7AB831}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4DC96D9-6C55-42ED-8E29-DCBC8D7AB831}.Release|Any CPU.Build.0 = Release|Any CPU
+ {86A7FED2-AEB1-4766-819F-C6256FA7DD38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {86A7FED2-AEB1-4766-819F-C6256FA7DD38}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {86A7FED2-AEB1-4766-819F-C6256FA7DD38}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {86A7FED2-AEB1-4766-819F-C6256FA7DD38}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/FuncionesBase/MutableRect.cs b/FuncionesBase/MutableRect.cs
new file mode 100644
index 0000000..536e71e
--- /dev/null
+++ b/FuncionesBase/MutableRect.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace CtrEditor.FuncionesBase
+{
+ public struct MutableRect
+ {
+ public float Left { get; set; }
+ public float Top { get; set; }
+ public float Right { get; set; }
+ public float Bottom { get; set; }
+
+ public MutableRect(float left, float top, float right, float bottom)
+ {
+ Left = left;
+ Top = top;
+ Right = right;
+ Bottom = bottom;
+ }
+
+ public MutableRect(Rect r)
+ {
+ Left = (float) r.Left;
+ Top = (float)r.Top;
+ Right = (float)r.Right;
+ Bottom = (float)r.Bottom;
+ }
+
+
+ public float Width => Right - Left;
+ public float Height => Bottom - Top;
+ }
+
+}
diff --git a/Icons/rotationRx.cur b/Icons/rotationRx.cur
new file mode 100644
index 0000000..1c26cbd
Binary files /dev/null and b/Icons/rotationRx.cur differ
diff --git a/Icons/rotationSx.cur b/Icons/rotationSx.cur
new file mode 100644
index 0000000..f4a0b6b
Binary files /dev/null and b/Icons/rotationSx.cur differ
diff --git a/MainViewModel.cs b/MainViewModel.cs
index 64e5fcb..bbd1e03 100644
--- a/MainViewModel.cs
+++ b/MainViewModel.cs
@@ -5,7 +5,7 @@ using Ookii.Dialogs.Wpf;
using System.Collections.ObjectModel;
using System.Windows.Threading;
using CtrEditor.ObjetosSim;
-using CtrEditor.Siemens;
+using LibS7Adv;
using System.IO;
using Newtonsoft.Json;
using System.Windows;
@@ -18,6 +18,7 @@ using CtrEditor.ObjetosSim.Extraccion_Datos;
using ClosedXML.Excel;
using CtrEditor.PopUps;
using System.Windows.Data;
+using CommunityToolkit.Mvvm.Input;
namespace CtrEditor
@@ -36,9 +37,15 @@ namespace CtrEditor
public SimulationManagerFP simulationManager = new SimulationManagerFP();
private readonly DispatcherTimer _timerSimulacion;
+ private readonly DispatcherTimer _timerPLCUpdate;
public Canvas MainCanvas;
+ public bool IsConnected
+ {
+ get => PLCViewModel.IsConnected;
+ }
+
[ObservableProperty]
private DatosDeTrabajo datosDeTrabajo;
@@ -101,14 +108,6 @@ namespace CtrEditor
CommandManager.InvalidateRequerySuggested(); // Notificar que el estado de los comandos ha cambiado
}
- [ObservableProperty]
- private bool isConnected;
-
- partial void OnIsConnectedChanged(bool value)
- {
- CommandManager.InvalidateRequerySuggested();
- }
-
public string directorioTrabajo
{
get => EstadoPersistente.Instance.directorio;
@@ -133,6 +132,12 @@ namespace CtrEditor
}
}
+ [RelayCommand]
+ public void DebugWindow()
+ {
+ MainWindow.DebugWindow();
+ }
+
[ObservableProperty]
private PLCViewModel pLCViewModel;
@@ -202,7 +207,10 @@ namespace CtrEditor
// Inicializa el PLCViewModel
PLCViewModel = new PLCViewModel();
- PLCViewModel.RefreshEvent += OnRefreshEvent;
+
+ _timerPLCUpdate = new DispatcherTimer();
+ _timerPLCUpdate.Interval = TimeSpan.FromMilliseconds(100); // ajusta el intervalo según sea necesario
+ _timerPLCUpdate.Tick += OnRefreshEvent;
InitializeTipoSimulableList();
@@ -218,8 +226,8 @@ namespace CtrEditor
TBStartSimulationCommand = new RelayCommand(StartSimulation, () => !IsSimulationRunning);
TBStopSimulationCommand = new RelayCommand(StopSimulation, () => IsSimulationRunning);
TBSaveCommand = new RelayCommand(Save);
- TBConnectPLCCommand = new RelayCommand(ConnectPLC, () => !IsConnected);
- TBDisconnectPLCCommand = new RelayCommand(DisconnectPLC, () => IsConnected);
+ TBConnectPLCCommand = new RelayCommand(ConnectPLC, () => !PLCViewModel.IsConnected);
+ TBDisconnectPLCCommand = new RelayCommand(DisconnectPLC, () => PLCViewModel.IsConnected);
TBEliminarUserControlCommand = new RelayCommand(EliminarUserControl, () => habilitarEliminarUserControl);
TBDuplicarUserControlCommand = new RelayCommand(DuplicarUserControl, () => habilitarEliminarUserControl);
@@ -707,13 +715,16 @@ namespace CtrEditor
private void ConnectPLC()
{
+ _timerPLCUpdate.Start();
PLCViewModel.Connect();
+ foreach (var objetoSimulable in ObjetosSimulables)
+ objetoSimulable.SetPLC(PLCViewModel);
}
private void DisconnectPLC()
{
PLCViewModel.Disconnect();
- IsConnected = false;
+ _timerPLCUpdate.Stop();
foreach (var objetoSimulable in ObjetosSimulables)
objetoSimulable.SetPLC(null);
@@ -723,12 +734,6 @@ namespace CtrEditor
{
if (PLCViewModel.IsConnected)
{
- if (!isConnected)
- {
- IsConnected = true;
- foreach (var objetoSimulable in ObjetosSimulables)
- objetoSimulable.SetPLC(PLCViewModel.PLCInterface);
- }
// Detener el cronómetro y obtener el tiempo transcurrido en milisegundos
var elapsedMilliseconds = stopwatch_Sim.Elapsed.TotalMilliseconds - stopwatch_SimPLC_last;
stopwatch_SimPLC_last = stopwatch_Sim.Elapsed.TotalMilliseconds;
@@ -736,7 +741,7 @@ namespace CtrEditor
// Reiniciar el cronómetro para la próxima medición
foreach (var objetoSimulable in ObjetosSimulables)
- objetoSimulable.UpdatePLC(PLCViewModel.PLCInterface, (int)elapsedMilliseconds);
+ objetoSimulable.UpdatePLC(PLCViewModel, (int)elapsedMilliseconds);
}
}
@@ -867,9 +872,6 @@ namespace CtrEditor
PixelToMeter.Instance.calc = simulationData.UnitConverter;
- // Re-register to the events
- PLCViewModel.RefreshEvent += OnRefreshEvent;
-
}
}
@@ -887,7 +889,11 @@ namespace CtrEditor
}
// Recorrer la colección de objetos simulables
foreach (var objetoSimulable in ObjetosSimulables)
- if (objetoSimulable != null) CrearUserControlDesdeObjetoSimulable(objetoSimulable);
+ if (objetoSimulable != null)
+ {
+ objetoSimulable.CheckData();
+ CrearUserControlDesdeObjetoSimulable(objetoSimulable);
+ }
}
}
catch { /* Consider logging the error or handling it appropriately */ }
diff --git a/MainWindow.xaml b/MainWindow.xaml
index f969b9b..eb4008a 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -1,6 +1,6 @@
+
@@ -51,7 +52,7 @@
-
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index f161ade..d120cf1 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -11,7 +11,9 @@ using System.Windows.Threading;
using System.Diagnostics;
using CtrEditor.ObjetosSim.UserControls;
using DocumentFormat.OpenXml.Spreadsheet;
-
+using System.Windows.Shapes;
+using System.Numerics;
+using CommunityToolkit.Mvvm.Input;
namespace CtrEditor
{
@@ -27,13 +29,15 @@ namespace CtrEditor
private bool _isDraggingCanvas = false;
private Image imagenDeFondo;
+ private List resizeRectangles = new List();
+
private DispatcherTimer _zoomTimer;
private double _targetZoomFactor;
private double _initialZoomFactor;
private double _currentZoomStep;
private Point _zoomCursorPosition;
private const int ZoomDuration = 500; // Duración del zoom en milisegundos
- private int _ZoomDuration;
+ private int _ZoomDuration;
private const double MinZoomScale = 0.1; // Límite mínimo de zoom
private Stopwatch _stopwatch;
@@ -67,34 +71,13 @@ namespace CtrEditor
if (DataContext is MainViewModel viewModel)
{
viewModel.MainWindow = this;
- viewModel.ImageSelected += ViewModel_ImageSelected;
+ viewModel.ImageSelected += ViewModel_ImageSelected;
viewModel?.LoadInitialData(); // Carga la primera imagen por defecto una vez cargada la ventana principal
viewModel.simulationManager.DebugCanvas = ImagenEnTrabajoCanvas;
viewModel.MainCanvas = ImagenEnTrabajoCanvas;
}
}
- public (float X, float Y) ObtenerCentroCanvasPixels()
- {
- var scaleTransform = ImagenEnTrabajoCanvas.LayoutTransform as ScaleTransform;
- float scaleX = (float)(scaleTransform?.ScaleX ?? 1.0);
- float scaleY = (float)(scaleTransform?.ScaleY ?? 1.0);
-
- // Obtiene el área visible del ScrollViewer
- float visibleWidth = (float)ImagenEnTrabajoScrollViewer.ViewportWidth;
- float visibleHeight = (float)ImagenEnTrabajoScrollViewer.ViewportHeight;
-
- // Obtiene la posición actual del desplazamiento ajustada por el zoom
- float offsetX = (float)ImagenEnTrabajoScrollViewer.HorizontalOffset / scaleX;
- float offsetY = (float)ImagenEnTrabajoScrollViewer.VerticalOffset / scaleY;
-
- // Calcula el centro visible ajustado
- float centerX = offsetX + (visibleWidth / scaleX) / 2;
- float centerY = offsetY + (visibleHeight / scaleY) / 2;
-
- return (centerX, centerY);
- }
-
public (float X, float Y) ObtenerCentroCanvasMeters()
{
var c = ObtenerCentroCanvasPixels();
@@ -127,7 +110,7 @@ namespace CtrEditor
public void EliminarUserControlDelCanvas(UserControl userControl)
{
if (ImagenEnTrabajoCanvas.Children.Contains(userControl))
- {
+ {
ImagenEnTrabajoCanvas.Children.Remove(userControl);
}
}
@@ -136,81 +119,286 @@ namespace CtrEditor
{
if (!_isDrawingCanvas)
{
- var userControl = sender as UserControl;
- _currentDraggingControl = userControl;
- userControl.CaptureMouse(); // Importante para recibir eventos de movimiento incluso fuera del control
- _isMovingUserControl = true;
-
- if (sender is UserControl control && control.DataContext is osBase datos)
+ if (resizeRectangles != null && resizeRectangles.Contains(sender))
{
- var viewModel = DataContext as MainViewModel;
- if (viewModel != null)
- {
- viewModel.SelectedItemOsList = datos; // Esto desencadenará ListaOs_SelectionChanged
- }
- }
-
- // ROTACION
- if (Keyboard.IsKeyDown(Key.LeftShift))
- {
- // Inicializar la rotación
- _isRotatingUserControl = true;
- RotateTransform rotateTransform = userControl.RenderTransform as RotateTransform;
- if (rotateTransform == null)
- {
- rotateTransform = new RotateTransform();
- userControl.RenderTransform = rotateTransform;
- }
- _initialAngleUserControl = rotateTransform.Angle;
-
- // Establecer el punto inicial de referencia para el cálculo de rotación
- _startPointUserControl = new Point(rotateTransform.CenterX, rotateTransform.CenterY);
-
- // Ajusta el punto inicial al espacio del Canvas
- _startPointUserControl = userControl.TranslatePoint(_startPointUserControl, ImagenEnTrabajoCanvas);
-
- // Crear y configurar el TextBlock si no existe
- if (_angleDisplayTextBlock == null)
- {
- _angleDisplayTextBlock = new TextBlock
- {
- Foreground = Brushes.Black,
- Background = Brushes.White,
- Opacity = 0.8,
- Padding = new Thickness(5)
- };
- ImagenEnTrabajoCanvas.Children.Add(_angleDisplayTextBlock);
- }
-
- PositionAngleDisplay(userControl);
- _angleDisplayTextBlock.Visibility = Visibility.Visible;
- Canvas.SetZIndex(_angleDisplayTextBlock, 15);
- }
- // TAMANO
- else if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
- {
- // Inicializar el cambio de tamaño
_isResizingUserControl = true;
+ lastMousePosition = e.GetPosition(ImagenEnTrabajoCanvas);
+ ((Rectangle)sender).CaptureMouse();
+ _isMovingUserControl = true;
+ lastAngle = 0;
}
- // MOVIMIENTO
else
{
- // Inicializar el movimiento/panning
- _isDraggingUserControl = true;
- _startPointUserControl = e.GetPosition(ImagenEnTrabajoCanvas);
+ var userControl = sender as UserControl;
+ userControl.CaptureMouse(); // Importante para recibir eventos de movimiento incluso fuera del control
+ _currentDraggingControl = userControl;
+ _isMovingUserControl = true;
+ RemoveResizeRectangles();
+
+ if (sender is UserControl control && control.DataContext is osBase datos)
+ {
+ var viewModel = DataContext as MainViewModel;
+ if (viewModel != null)
+ {
+ viewModel.SelectedItemOsList = datos; // Esto desencadenará ListaOs_SelectionChanged
+ }
+ }
+
+ // ROTACION
+ if (Keyboard.IsKeyDown(Key.LeftShift))
+ {
+ // Inicializar la rotación
+ _isRotatingUserControl = true;
+ RotateTransform rotateTransform = userControl.RenderTransform as RotateTransform;
+ if (rotateTransform == null)
+ {
+ rotateTransform = new RotateTransform();
+ userControl.RenderTransform = rotateTransform;
+ }
+ _initialAngleUserControl = rotateTransform.Angle;
+
+ // Establecer el punto inicial de referencia para el cálculo de rotación
+ _startPointUserControl = new Point(rotateTransform.CenterX, rotateTransform.CenterY);
+
+ // Ajusta el punto inicial al espacio del Canvas
+ _startPointUserControl = userControl.TranslatePoint(_startPointUserControl, ImagenEnTrabajoCanvas);
+
+ // Crear y configurar el TextBlock si no existe
+ if (_angleDisplayTextBlock == null)
+ {
+ _angleDisplayTextBlock = new TextBlock
+ {
+ Foreground = Brushes.Black,
+ Background = Brushes.White,
+ Opacity = 0.8,
+ Padding = new Thickness(5)
+ };
+ ImagenEnTrabajoCanvas.Children.Add(_angleDisplayTextBlock);
+ }
+
+ PositionAngleDisplay(userControl);
+ _angleDisplayTextBlock.Visibility = Visibility.Visible;
+ Canvas.SetZIndex(_angleDisplayTextBlock, 15);
+ }
+ // TAMANO
+ else if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
+ {
+ // Inicializar el cambio de tamaño
+ _isResizingUserControl = true;
+ _startPointUserControl = e.GetPosition(ImagenEnTrabajoCanvas);
+ }
+ // MOVIMIENTO
+ else
+ {
+ // Inicializar el movimiento/panning
+ _isDraggingUserControl = true;
+ _startPointUserControl = e.GetPosition(ImagenEnTrabajoCanvas);
+ }
}
}
}
+ dataDebug dataDebug = new dataDebug();
+
+ public void DebugWindow()
+ {
+ // Crear una instancia de wDebug
+ var debugWindow = new wDebug
+ {
+ Data = dataDebug // Asignar la instancia de Test a la propiedad Data
+ };
+
+ // Mostrar la ventana de depuración
+ debugWindow.Show();
+ }
+
+ private Point transformedBoundingBoxCenter = new Point();
+ private float lastAngle;
+ private System.Threading.Timer timerRemoveResizeRectangles = null;
+
+ public void ResetTimerRemoveResizeRectangles()
+ {
+ if (timerRemoveResizeRectangles == null)
+ timerRemoveResizeRectangles = new System.Threading.Timer(TimerCallbackRemoveResizeRectangles, null, Timeout.Infinite, Timeout.Infinite);
+
+ timerRemoveResizeRectangles.Change(2000, Timeout.Infinite);
+ }
+
+ private async void TimerCallbackRemoveResizeRectangles(object state)
+ {
+ Application.Current.Dispatcher.Invoke(() =>
+ {
+ // Realiza tus cambios en la interfaz de usuario aquí
+ MakeResizeRectanglesTransparent();
+ });
+ }
+
+ public void PauseTimerRemoveResizeRectangles()
+ {
+ if (timerRemoveResizeRectangles != null)
+ {
+ timerRemoveResizeRectangles.Change(Timeout.Infinite, Timeout.Infinite);
+ }
+ }
+
+ private void AddResizeRectangles(UserControl userControl)
+ {
+ double rectSize = 10;
+ RemoveResizeRectangles();
+
+ // Obtener el BoundingBox aproximado del UserControl
+ Rect boundingBox = VisualTreeHelper.GetDescendantBounds(userControl);
+
+ // Transformar el BoundingBox a las coordenadas del Canvas
+ GeneralTransform transform = userControl.TransformToAncestor(ImagenEnTrabajoCanvas);
+ Rect transformedBoundingBox = transform.TransformBounds(boundingBox);
+
+ FuncionesBase.MutableRect rectBox = new FuncionesBase.MutableRect(transformedBoundingBox);
+ rectBox.Left -= (float)rectSize;
+ rectBox.Right += (float)rectSize;
+ rectBox.Top -= (float)rectSize;
+ rectBox.Bottom += (float)rectSize;
+
+ transformedBoundingBoxCenter.X = transformedBoundingBox.Left + transformedBoundingBox.Width / 2;
+ transformedBoundingBoxCenter.Y = transformedBoundingBox.Top + transformedBoundingBox.Height / 2;
+
+ // Cargar el cursor personalizado para rotación
+ Cursor rotationCursorRx = new Cursor(Application.GetResourceStream(new Uri("pack://application:,,,/CtrEditor;component/Icons/rotationRx.cur")).Stream);
+ Cursor rotationCursorSx = new Cursor(Application.GetResourceStream(new Uri("pack://application:,,,/CtrEditor;component/Icons/rotationSx.cur")).Stream);
+
+ // Calcular las posiciones de los rectángulos de redimensionamiento
+ var positions = new List>()
+ {
+ new Tuple(new Point(rectBox.Left, rectBox.Top), "TopLeft"),
+ new Tuple(new Point(rectBox.Right, rectBox.Top), "TopRight"),
+ new Tuple(new Point(rectBox.Left, rectBox.Bottom), "BottomLeft"),
+ new Tuple(new Point(rectBox.Right, rectBox.Bottom), "BottomRight"),
+ new Tuple(new Point(rectBox.Left + rectBox.Width / 2, rectBox.Top), "TopCenter"),
+ new Tuple(new Point(rectBox.Left + rectBox.Width / 2, rectBox.Bottom), "BottomCenter"),
+ new Tuple(new Point(rectBox.Left, rectBox.Top + rectBox.Height / 2), "CenterLeft"),
+ new Tuple(new Point(rectBox.Right, rectBox.Top + rectBox.Height / 2), "CenterRight")
+ };
+
+ foreach (var position in positions)
+ {
+ Rectangle rect = new Rectangle
+ {
+ Width = rectSize,
+ Height = rectSize,
+ Fill = Brushes.Transparent,
+ Stroke = Brushes.Black,
+ StrokeThickness = 1,
+ Tag = position.Item2 // Asignar la etiqueta
+ };
+
+ // Establecer el cursor adecuado
+ switch (position.Item2)
+ {
+ case "TopLeft":
+ rect.Cursor = Cursors.Arrow;
+ break;
+ case "TopRight":
+ rect.Cursor = rotationCursorRx; // Cursor de rotación
+ break;
+ case "BottomLeft":
+ rect.Cursor = rotationCursorSx; // Cursor de rotación
+ break;
+ case "BottomRight":
+ rect.Cursor = Cursors.SizeNWSE; // Cursor de dimensionar altura y anchura
+ break;
+ case "TopCenter":
+ rect.Cursor = Cursors.Arrow;
+ break;
+ case "BottomCenter":
+ rect.Cursor = Cursors.SizeNS; // Cursor de dimensionar altura
+ break;
+ case "CenterLeft":
+ rect.Cursor = rotationCursorRx; // Cursor de rotación
+ break;
+ case "CenterRight":
+ rect.Cursor = Cursors.SizeWE; // Cursor de dimensionar anchura
+ break;
+ }
+
+ Canvas.SetLeft(rect, position.Item1.X - rectSize / 2);
+ Canvas.SetTop(rect, position.Item1.Y - rectSize / 2);
+
+ rect.MouseLeftButtonDown += UserControl_MouseLeftButtonDown;
+ rect.MouseMove += UserControl_MouseMove;
+ rect.MouseLeftButtonUp += UserControl_MouseLeftButtonUp;
+ rect.MouseLeave += ResizeRectangle_MouseLeave;
+
+ resizeRectangles.Add(rect);
+ ImagenEnTrabajoCanvas.Children.Add(rect);
+
+ ResetTimerRemoveResizeRectangles();
+ }
+ }
+
+
+
+
+ private void ResizeRectangle_MouseLeave(object sender, MouseEventArgs e)
+ {
+ var rect = sender as Rectangle;
+ rect.Fill = Brushes.Transparent; // Volver al color original
+ ResetTimerRemoveResizeRectangles();
+ }
+
+ private void MakeResizeRectanglesTransparent()
+ {
+ if (resizeRectangles == null || resizeRectangles.Count == 0)
+ return;
+
+ foreach (var rect in resizeRectangles)
+ {
+ rect.Opacity = 0; // Hacer transparente
+ }
+ }
+
+ private void MakeResizeRectanglesNormal()
+ {
+ if (resizeRectangles == null || resizeRectangles.Count == 0)
+ return;
+
+ foreach (var rect in resizeRectangles)
+ {
+ rect.Opacity = 1;
+ }
+ }
+
+
+ private void RemoveResizeRectangles()
+ {
+ if (resizeRectangles == null || resizeRectangles.Count == 0)
+ return;
+
+ foreach (var rect in resizeRectangles)
+ {
+ ImagenEnTrabajoCanvas.Children.Remove(rect);
+ }
+ resizeRectangles.Clear();
+ }
+
+ private Point lastMousePosition;
+
private void UserControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
- if (_isMovingUserControl)
+ if (_isResizingUserControl && resizeRectangles != null && resizeRectangles.Contains(sender))
+ {
+ _isResizingUserControl = false;
+ _isMovingUserControl = false;
+ ((Rectangle)sender).ReleaseMouseCapture();
+ AddResizeRectangles(_currentDraggingControl);
+ }
+ else if (_isMovingUserControl)
{
var userControl = sender as UserControl;
-
+
userControl.ReleaseMouseCapture();
- _currentDraggingControl = null;
- _isResizingUserControl = _isRotatingUserControl = _isDraggingUserControl = false ;
+ // _currentDraggingControl = null;
+ AddResizeRectangles(_currentDraggingControl);
+ _isResizingUserControl = _isRotatingUserControl = _isDraggingUserControl = false;
_isMovingUserControl = false;
// Ocultar el TextBlock de ángulo
if (_angleDisplayTextBlock != null)
@@ -220,8 +408,19 @@ namespace CtrEditor
}
}
+ Rectangle _currentDraggingRectangle;
+
private void UserControl_MouseMove(object sender, MouseEventArgs e)
{
+ if (!_isMovingUserControl && resizeRectangles != null && resizeRectangles.Contains(sender))
+ {
+ var rect = sender as Rectangle;
+ rect.Fill = Brushes.Black; // Pintar de negro el rectángulo bajo el ratón
+ _currentDraggingRectangle = rect; // Asignar el rectángulo actual que se está arrastrando
+ _startPointUserControl = new Point(Canvas.GetLeft(rect), Canvas.GetTop(rect));
+ MakeResizeRectanglesNormal();
+ PauseTimerRemoveResizeRectangles();
+ }
if (_isMovingUserControl && _currentDraggingControl != null)
{
var currentPosition = e.GetPosition(ImagenEnTrabajoCanvas);
@@ -235,7 +434,7 @@ namespace CtrEditor
var newY = Canvas.GetTop(_currentDraggingControl) + dy;
if (_currentDraggingControl is IDataContainer dataContainer)
- dataContainer.Move((float)newX,(float) newY);
+ dataContainer.Move((float)newX, (float)newY);
_startPointUserControl = currentPosition; // Actualiza el punto inicial para el siguiente movimiento
}
@@ -249,7 +448,6 @@ namespace CtrEditor
// Código para cambiar el tamaño del control
ResizeControl(_currentDraggingControl, currentPosition);
}
-
}
}
@@ -279,37 +477,104 @@ namespace CtrEditor
private void ResizeControl(UserControl control, Point currentPosition)
{
- // Calcular la diferencia en la posición X desde el punto de inicio
- double widthChange = currentPosition.X - _startPointUserControl.X;
-
- // Calcular la diferencia en la posición Y desde el punto de inicio
- double heightChange = currentPosition.Y - _startPointUserControl.Y;
-
- // Actualizar el ancho del control
- double newWidth = Math.Max(control.ActualWidth + widthChange, control.MinWidth);
-
- // Actualizar la altura del control
- double newHeight = Math.Max(control.ActualHeight + heightChange, control.MinHeight);
-
- // Asegurar que el nuevo tamaño no sea menor que los mínimos
- control.Width = newWidth;
- control.Height = newHeight;
+ bool ActivateRotation = false, ActivateSizeWidth = false, ActivateSizeHeight = false, ActivateMove = false;
if (control is IDataContainer dataContainer)
{
- dataContainer.Resize((float)newWidth, (float)newHeight);
- }
+ MakeResizeRectanglesTransparent();
- // Actualizar el punto de inicio para el próximo evento de movimiento
- _startPointUserControl = currentPosition;
+ // Obtener el rectángulo desde el que se inició la redimensión
+ var resizeRect = _currentDraggingRectangle as Rectangle;
+ if (resizeRect == null) return;
+
+ string resizeDirection = resizeRect.Tag as string;
+ if (resizeDirection == null) return;
+
+ switch (resizeDirection)
+ {
+ case "TopLeft":
+ break;
+ case "TopRight":
+ ActivateRotation = true;
+ break;
+ case "BottomLeft":
+ ActivateRotation = true;
+ break;
+ case "BottomRight":
+ ActivateSizeHeight = true;
+ ActivateSizeWidth = true;
+ break;
+ case "TopCenter":
+ break;
+ case "BottomCenter":
+ ActivateSizeHeight = true;
+ break;
+ case "CenterLeft":
+ ActivateRotation = true;
+ break;
+ case "CenterRight":
+ ActivateSizeWidth = true;
+ break;
+ }
+ if (ActivateMove)
+ {
+ // Código para mover el control
+ var dx = currentPosition.X - _startPointUserControl.X;
+ var dy = currentPosition.Y - _startPointUserControl.Y;
+
+ var newX = Canvas.GetLeft(_currentDraggingControl) + dx;
+ var newY = Canvas.GetTop(_currentDraggingControl) + dy;
+
+ dataContainer.Move((float)newX, (float)newY);
+ }
+ if (ActivateRotation)
+ {
+ double deltaX = currentPosition.X - transformedBoundingBoxCenter.X;
+ double deltaY = currentPosition.Y - transformedBoundingBoxCenter.Y;
+ double angle = Math.Atan2(deltaY, deltaX) * (180 / Math.PI);
+ if (lastAngle == 0 && angle != 0) lastAngle = (float)angle;
+
+ dataContainer.Rotate((float)angle - lastAngle);
+ lastAngle = (float)angle;
+
+
+ dataDebug.TransformedBoundingBoxCenter = transformedBoundingBoxCenter;
+ dataDebug.LastAngle = lastAngle;
+ dataDebug.CurrentPosition = currentPosition;
+ dataDebug.Angle = (float)angle;
+ }
+ if (ActivateSizeWidth || ActivateSizeHeight)
+ {
+ // Calcular la diferencia en la posición X desde el punto de inicio
+ double widthChange = currentPosition.X - _startPointUserControl.X;
+
+ // Calcular la diferencia en la posición Y desde el punto de inicio
+ double heightChange = currentPosition.Y - _startPointUserControl.Y;
+
+ if (!ActivateSizeHeight) heightChange = 0;
+ if (!ActivateSizeWidth) widthChange = 0;
+
+ dataContainer.Resize((float)widthChange, (float)heightChange);
+ }
+ _startPointUserControl = currentPosition; // Actualiza el punto inicial para el siguiente movimiento
+ }
}
private void UserControl_MouseEnter(object sender, MouseEventArgs e)
{
+ if (_currentDraggingControl != null)
+ {
+ RemoveResizeRectangles();
+ }
+
if (sender is UserControl userControl)
if (userControl is IDataContainer dataContainer)
+ {
dataContainer.Highlight(true);
+ _currentDraggingControl = sender as UserControl;
+ AddResizeRectangles(_currentDraggingControl);
+ }
}
private void UserControl_MouseLeave(object sender, MouseEventArgs e)
@@ -385,6 +650,8 @@ namespace CtrEditor
var dx = currentPosition.X - _lastMousePosition.X;
var dy = currentPosition.Y - _lastMousePosition.Y;
+ MakeResizeRectanglesTransparent();
+
// Obtener la transformación actual del Canvas
var transform = (TranslateTransform)((TransformGroup)ImagenEnTrabajoCanvas.RenderTransform).Children.First(t => t is TranslateTransform);
transform.X += dx;
@@ -396,6 +663,8 @@ namespace CtrEditor
private void ImagenEnTrabajoCanvas_MouseWheel(object sender, MouseWheelEventArgs e)
{
+ MakeResizeRectanglesTransparent();
+
_initialZoomFactor = ((ScaleTransform)((TransformGroup)ImagenEnTrabajoCanvas.RenderTransform).Children.First(t => t is ScaleTransform)).ScaleX;
// Calcula el factor de escala mínimo para que toda la imagen sea visible
@@ -462,6 +731,33 @@ namespace CtrEditor
tt.Y = relativeY - cursorPosition.Y * st.ScaleY;
}
+ public (float X, float Y) ObtenerCentroCanvasPixels()
+ {
+ // Obtener las transformaciones actuales del Canvas
+ var tg = (TransformGroup)ImagenEnTrabajoCanvas.RenderTransform;
+ var st = (ScaleTransform)tg.Children.First(t => t is ScaleTransform);
+ var tt = (TranslateTransform)tg.Children.First(t => t is TranslateTransform);
+
+ // Obtener el tamaño del ScrollViewer visible
+ double visibleWidth = ImagenEnTrabajoScrollViewer.ViewportWidth;
+ double visibleHeight = ImagenEnTrabajoScrollViewer.ViewportHeight;
+
+ // Obtener el desplazamiento del ScrollViewer
+ double offsetX = ImagenEnTrabajoScrollViewer.HorizontalOffset;
+ double offsetY = ImagenEnTrabajoScrollViewer.VerticalOffset;
+
+ // Calcular las coordenadas del centro visible del ScrollViewer
+ double centerX = offsetX + (visibleWidth / 2);
+ double centerY = offsetY + (visibleHeight / 2);
+
+ // Ajustar las coordenadas del centro para tener en cuenta las transformaciones del Canvas
+ double canvasCenterX = (centerX - tt.X) / st.ScaleX;
+ double canvasCenterY = (centerY - tt.Y) / st.ScaleY;
+
+ return ((float)canvasCenterX, (float)canvasCenterY);
+ }
+
+
private void CargarPropiedadesosDatos(osBase selectedObject)
{
if (DataContext is MainViewModel viewModel)
diff --git a/ObjetosSim/Decorativos/ucTextPlate.xaml.cs b/ObjetosSim/Decorativos/ucTextPlate.xaml.cs
index c166453..efef247 100644
--- a/ObjetosSim/Decorativos/ucTextPlate.xaml.cs
+++ b/ObjetosSim/Decorativos/ucTextPlate.xaml.cs
@@ -95,8 +95,8 @@ namespace CtrEditor.ObjetosSim
{
if (Datos is osTextPlate datos)
{
- datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
- datos.Alto = PixelToMeter.Instance.calc.PixelsToMeters(height);
+ datos.Ancho += PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.Alto += PixelToMeter.Instance.calc.PixelsToMeters(height);
}
}
public void Move(float LeftPixels, float TopPixels)
@@ -111,7 +111,7 @@ namespace CtrEditor.ObjetosSim
{
if (Datos != null)
if (Datos is osTextPlate datos)
- datos.Angulo = Angle;
+ datos.Angulo += Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
diff --git a/ObjetosSim/Dinamicos/ucBotella.xaml.cs b/ObjetosSim/Dinamicos/ucBotella.xaml.cs
index 6e75f65..cf76bfc 100644
--- a/ObjetosSim/Dinamicos/ucBotella.xaml.cs
+++ b/ObjetosSim/Dinamicos/ucBotella.xaml.cs
@@ -2,7 +2,7 @@
using System.Windows.Controls;
//using using Microsoft.Xna.Framework;
-using CtrEditor.Siemens;
+using LibS7Adv;
using CtrEditor.Simulacion;
using CommunityToolkit.Mvvm.ComponentModel;
using nkast.Aether.Physics2D.Common;
diff --git a/ObjetosSim/Dinamicos/ucBotellaCuello.xaml.cs b/ObjetosSim/Dinamicos/ucBotellaCuello.xaml.cs
index ecec48b..7023ef3 100644
--- a/ObjetosSim/Dinamicos/ucBotellaCuello.xaml.cs
+++ b/ObjetosSim/Dinamicos/ucBotellaCuello.xaml.cs
@@ -2,7 +2,7 @@
using System.Windows.Controls;
//using using Microsoft.Xna.Framework;
-using CtrEditor.Siemens;
+using LibS7Adv;
using CtrEditor.Simulacion;
using CommunityToolkit.Mvvm.ComponentModel;
using nkast.Aether.Physics2D.Common;
diff --git a/ObjetosSim/Emuladores/ucBottGenerator.xaml.cs b/ObjetosSim/Emuladores/ucBottGenerator.xaml.cs
index cfa1687..afb5e40 100644
--- a/ObjetosSim/Emuladores/ucBottGenerator.xaml.cs
+++ b/ObjetosSim/Emuladores/ucBottGenerator.xaml.cs
@@ -1,4 +1,4 @@
-using CtrEditor.Siemens;
+using LibS7Adv;
using System.Windows;
using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
@@ -87,7 +87,7 @@ namespace CtrEditor.ObjetosSim
Filtro_consenso_s = 1;
}
- public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
+ public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
{
if (Consenso_NC)
Consenso = !LeerBitTag(Tag_consenso);
@@ -180,8 +180,8 @@ namespace CtrEditor.ObjetosSim
{
if (Datos is osBottGenerator datos)
{
- datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
- datos.Alto = PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.Ancho += PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.Alto += PixelToMeter.Instance.calc.PixelsToMeters(width);
}
}
public void Move(float LeftPixels, float TopPixels)
@@ -196,7 +196,7 @@ namespace CtrEditor.ObjetosSim
{
if (Datos != null)
if (Datos is osBottGenerator datos)
- datos.Angulo = Angle;
+ datos.Angulo += Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
diff --git a/ObjetosSim/Emuladores/ucFiller.xaml b/ObjetosSim/Emuladores/ucFiller.xaml
index 710fbbb..8d1af4d 100644
--- a/ObjetosSim/Emuladores/ucFiller.xaml
+++ b/ObjetosSim/Emuladores/ucFiller.xaml
@@ -15,7 +15,7 @@
+ Stretch="Fill">
diff --git a/ObjetosSim/Emuladores/ucFiller.xaml.cs b/ObjetosSim/Emuladores/ucFiller.xaml.cs
index dfea75d..4d001d3 100644
--- a/ObjetosSim/Emuladores/ucFiller.xaml.cs
+++ b/ObjetosSim/Emuladores/ucFiller.xaml.cs
@@ -1,5 +1,5 @@
-using CtrEditor.Siemens;
+using LibS7Adv;
using System.Windows;
using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
@@ -88,7 +88,7 @@ namespace CtrEditor.ObjetosSim
Filtro_consenso_s = 1;
}
- public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
+ public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
{
if (Consenso_NC)
Consenso = !LeerBitTag(Tag_consenso);
@@ -181,8 +181,8 @@ namespace CtrEditor.ObjetosSim
{
if (Datos is osFiller datos)
{
- datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
- datos.Alto = PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.Ancho += PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.Alto += PixelToMeter.Instance.calc.PixelsToMeters(height);
}
}
public void Move(float LeftPixels, float TopPixels)
@@ -197,7 +197,7 @@ namespace CtrEditor.ObjetosSim
{
if (Datos != null)
if (Datos is osFiller datos)
- datos.Angulo = Angle;
+ datos.Angulo += Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
diff --git a/ObjetosSim/Emuladores/ucTanque.xaml.cs b/ObjetosSim/Emuladores/ucTanque.xaml.cs
index 62358d0..84a8856 100644
--- a/ObjetosSim/Emuladores/ucTanque.xaml.cs
+++ b/ObjetosSim/Emuladores/ucTanque.xaml.cs
@@ -1,6 +1,6 @@
using CommunityToolkit.Mvvm.ComponentModel;
-using CtrEditor.Siemens;
+using LibS7Adv;
using System.Windows;
using System.Windows.Controls;
@@ -61,7 +61,7 @@ namespace CtrEditor.ObjetosSim
Min_OUT_Scaled = 0;
}
- public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
+ public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
{
EscribirWordTagScaled(TagNivel_Word, Level, 0, 100, Min_OUT_Scaled, Max_OUT_Scaled);
Ingreso_Abierto = LeerBitTag(TagIngresoAbierto_Bool);
@@ -114,8 +114,8 @@ namespace CtrEditor.ObjetosSim
{
if (Datos is osTanque datos)
{
- datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
- datos.Alto = PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.Ancho += PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.Alto += PixelToMeter.Instance.calc.PixelsToMeters(width);
}
}
public void Move(float LeftPixels, float TopPixels)
@@ -130,7 +130,7 @@ namespace CtrEditor.ObjetosSim
{
if (Datos != null)
if (Datos is osTanque datos)
- datos.Angulo = Angle;
+ datos.Angulo += Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
diff --git a/ObjetosSim/Estaticos/ucDescarte.xaml.cs b/ObjetosSim/Estaticos/ucDescarte.xaml.cs
index 0f05ecf..7d394fd 100644
--- a/ObjetosSim/Estaticos/ucDescarte.xaml.cs
+++ b/ObjetosSim/Estaticos/ucDescarte.xaml.cs
@@ -1,5 +1,5 @@
-using CtrEditor.Siemens;
+using LibS7Adv;
using CtrEditor.Simulacion;
using System.Windows;
using System.Windows.Controls;
@@ -82,7 +82,7 @@ namespace CtrEditor.ObjetosSim
public override void UpdateGeometryStep()
{
}
- public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
+ public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
{
}
@@ -133,7 +133,7 @@ namespace CtrEditor.ObjetosSim
{
if (Datos is osDescarte datos)
{
- datos.Diametro = PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.Diametro += PixelToMeter.Instance.calc.PixelsToMeters(width+ height);
}
}
public void Move(float LeftPixels, float TopPixels)
diff --git a/ObjetosSim/Estaticos/ucGuia.xaml.cs b/ObjetosSim/Estaticos/ucGuia.xaml.cs
index 2e6766e..7bfd9cc 100644
--- a/ObjetosSim/Estaticos/ucGuia.xaml.cs
+++ b/ObjetosSim/Estaticos/ucGuia.xaml.cs
@@ -2,7 +2,7 @@
using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
-using CtrEditor.Siemens;
+using LibS7Adv;
using CtrEditor.Simulacion;
namespace CtrEditor.ObjetosSim
@@ -57,7 +57,7 @@ namespace CtrEditor.ObjetosSim
public override void UpdateGeometryStep()
{
}
- public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { }
+ public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds) { }
public override void ucLoaded()
{
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
@@ -98,7 +98,7 @@ namespace CtrEditor.ObjetosSim
public void Resize(float width, float height)
{
if (Datos is osGuia datos)
- datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.Ancho += PixelToMeter.Instance.calc.PixelsToMeters(width);
}
public void Move(float LeftPixels, float TopPixels)
{
@@ -112,7 +112,7 @@ namespace CtrEditor.ObjetosSim
{
if (Datos != null)
if (Datos is osGuia datos)
- datos.Angulo = Angle;
+ datos.Angulo += Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
diff --git a/ObjetosSim/Estaticos/ucTransporteCurva.xaml.cs b/ObjetosSim/Estaticos/ucTransporteCurva.xaml.cs
index 08b5ba3..bbcd400 100644
--- a/ObjetosSim/Estaticos/ucTransporteCurva.xaml.cs
+++ b/ObjetosSim/Estaticos/ucTransporteCurva.xaml.cs
@@ -2,7 +2,7 @@
using System.Windows;
using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
-using CtrEditor.Siemens;
+using LibS7Adv;
using CtrEditor.Simulacion;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
@@ -131,7 +131,7 @@ namespace CtrEditor.ObjetosSim
}
- public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
+ public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
{
if (Motor != null)
{
@@ -186,8 +186,8 @@ namespace CtrEditor.ObjetosSim
{
if (RadioExterno > RadioInterno && RadioExterno > 0 && RadioInterno >= 0)
{
- datos.RadioExterno = PixelToMeter.Instance.calc.PixelsToMeters(RadioExterno);
- datos.RadioInterno = PixelToMeter.Instance.calc.PixelsToMeters(RadioInterno);
+ datos.RadioExterno += PixelToMeter.Instance.calc.PixelsToMeters(RadioExterno);
+ datos.RadioInterno += PixelToMeter.Instance.calc.PixelsToMeters(RadioInterno);
}
}
}
@@ -203,7 +203,7 @@ namespace CtrEditor.ObjetosSim
{
if (Datos != null)
if (Datos is osTransporteCurva datos)
- datos.Angulo = Angle;
+ datos.Angulo += Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
diff --git a/ObjetosSim/Estaticos/ucTransporteGuias.xaml.cs b/ObjetosSim/Estaticos/ucTransporteGuias.xaml.cs
index f91db8b..37ec7d6 100644
--- a/ObjetosSim/Estaticos/ucTransporteGuias.xaml.cs
+++ b/ObjetosSim/Estaticos/ucTransporteGuias.xaml.cs
@@ -3,7 +3,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using CommunityToolkit.Mvvm.ComponentModel;
-using CtrEditor.Siemens;
+using LibS7Adv;
using CtrEditor.Simulacion;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
@@ -160,7 +160,7 @@ namespace CtrEditor.ObjetosSim
// Se llama al detener la simulacion
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
}
- public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
+ public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
{
if (Motor != null)
if (Motor is osVMmotorSim id_motor)
@@ -220,7 +220,7 @@ namespace CtrEditor.ObjetosSim
public void Resize(float width, float height)
{
if (Datos is osTransporteGuias datos)
- datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.Ancho += PixelToMeter.Instance.calc.PixelsToMeters(width);
}
public void Move(float LeftPixels, float TopPixels)
{
@@ -234,7 +234,7 @@ namespace CtrEditor.ObjetosSim
{
if (Datos != null)
if (Datos is osTransporteGuias datos)
- datos.Angulo = Angle;
+ datos.Angulo += Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
diff --git a/ObjetosSim/Estaticos/ucTransporteGuiasUnion.xaml.cs b/ObjetosSim/Estaticos/ucTransporteGuiasUnion.xaml.cs
index 9b1a4b8..f625bc3 100644
--- a/ObjetosSim/Estaticos/ucTransporteGuiasUnion.xaml.cs
+++ b/ObjetosSim/Estaticos/ucTransporteGuiasUnion.xaml.cs
@@ -5,7 +5,7 @@ using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunityToolkit.Mvvm.ComponentModel;
-using CtrEditor.Siemens;
+using LibS7Adv;
using CtrEditor.Simulacion;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
@@ -263,7 +263,7 @@ namespace CtrEditor.ObjetosSim
}
}
- public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
+ public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
{
if (_osMotorA != null)
{
@@ -387,7 +387,7 @@ namespace CtrEditor.ObjetosSim
public void Resize(float width, float height)
{
if (Datos is osTransporteGuiasUnion datos)
- datos.AnchoRecto = PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.AnchoRecto += PixelToMeter.Instance.calc.PixelsToMeters(width);
}
public void Move(float LeftPixels, float TopPixels)
{
@@ -401,7 +401,7 @@ namespace CtrEditor.ObjetosSim
{
if (Datos != null)
if (Datos is osTransporteGuiasUnion datos)
- datos.Angulo = Angle;
+ datos.Angulo += Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
diff --git a/ObjetosSim/Estaticos/ucTransporteTTop.xaml.cs b/ObjetosSim/Estaticos/ucTransporteTTop.xaml.cs
index ba081ab..e8d78c0 100644
--- a/ObjetosSim/Estaticos/ucTransporteTTop.xaml.cs
+++ b/ObjetosSim/Estaticos/ucTransporteTTop.xaml.cs
@@ -1,7 +1,7 @@
using System.Windows;
using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
-using CtrEditor.Siemens;
+using LibS7Adv;
using CtrEditor.Simulacion;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using System.ComponentModel;
@@ -141,7 +141,7 @@ namespace CtrEditor.ObjetosSim
ActualizarGeometrias();
}
- public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
+ public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
{
if (Motor != null)
if (Motor is osVMmotorSim motor)
@@ -191,7 +191,7 @@ namespace CtrEditor.ObjetosSim
public void Resize(float width, float height)
{
if (Datos is osTransporteTTop datos)
- datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.Ancho += PixelToMeter.Instance.calc.PixelsToMeters(width);
}
public void Move(float LeftPixels, float TopPixels)
{
@@ -205,7 +205,7 @@ namespace CtrEditor.ObjetosSim
{
if (Datos != null)
if (Datos is osTransporteTTop datos)
- datos.Angulo = Angle;
+ datos.Angulo += Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
diff --git a/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs b/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs
index 46e6b83..6db886f 100644
--- a/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs
+++ b/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs
@@ -1,5 +1,5 @@
-using CtrEditor.Siemens;
+using LibS7Adv;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
@@ -17,7 +17,7 @@ namespace CtrEditor.ObjetosSim
{
// Otros datos y métodos relevantes para la simulación
-
+
private VMSimMotor motState = new VMSimMotor();
public static string NombreClase()
@@ -46,6 +46,8 @@ namespace CtrEditor.ObjetosSim
[ObservableProperty]
public float max_Speed_for_Ramp;
+ [ObservableProperty]
+ bool vFD_Trip_NC;
[ObservableProperty]
public float tiempoRampa;
@@ -58,9 +60,22 @@ namespace CtrEditor.ObjetosSim
}
[ObservableProperty]
- public bool encendido;
+ bool encendido;
[ObservableProperty]
- public int pLC_NumeroMotor;
+ int pLC_NumeroMotor;
+
+ partial void OnPLC_NumeroMotorChanged(int value)
+ {
+ if (PLC_DB_Motor==0)
+ {
+ PLC_DB_Motor = PLC_NumeroMotor - 30 + 300;
+ }
+ }
+
+ [ObservableProperty]
+ int pLC_DB_Motor;
+
+
[ObservableProperty]
public float ratio;
@@ -83,16 +98,16 @@ namespace CtrEditor.ObjetosSim
Max_Speed_for_Ramp = 100;
TiempoRampa = 3;
ImageSource_oculta = ImageFromPath("/imagenes/motor2.png");
- }
+ }
public override void UpdateGeometryStart()
{
// Se llama antes de la simulacion
}
- public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) {
-
- motState.UpdatePLC(plc,PLC_NumeroMotor,Encendido, elapsedMilliseconds);
+ public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
+ {
+ motState.UpdatePLC(plc, this, elapsedMilliseconds);
Velocidad = (ProporcionalSpeed / 100) * (motState.STATUS_VFD_ACT_Speed_Hz / 10);
}
@@ -131,7 +146,14 @@ namespace CtrEditor.ObjetosSim
{
Datos?.ucUnLoaded();
}
- public void Resize(float width, float height) { }
+ public void Resize(float width, float height)
+ {
+ if (Datos != null)
+ if (Datos is osVMmotorSim datos)
+ {
+ datos.Tamano += PixelToMeter.Instance.calc.PixelsToMeters( width + height);
+ }
+ }
public void Move(float LeftPixels, float TopPixels)
{
if (Datos != null)
@@ -140,10 +162,11 @@ namespace CtrEditor.ObjetosSim
Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels);
}
}
- public void Rotate(float Angle) {
+ public void Rotate(float Angle)
+ {
if (Datos != null)
if (Datos is osVMmotorSim datos)
- datos.Angulo = Angle;
+ datos.Angulo += Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
@@ -165,23 +188,21 @@ namespace CtrEditor.ObjetosSim
public bool OUT_Reversal;
public float OUT_OUT_VFD_REQ_Speed_Hz;
- public void UpdatePLC(PLCModel plc, int NumeroMotor, bool Encendido, int elapsedMilliseconds)
+ public void UpdatePLC(PLCViewModel plc, osVMmotorSim Data, int elapsedMilliseconds)
{
- var index = 0;
- switch (NumeroMotor)
- {
- case < 100:
- index = (int)NumeroMotor - 30 + 300;
- break;
- }
+ var DB_Motor = Data.PLC_DB_Motor;
- OUT_Run = plc.LeerTagBool($"\"DB MotorSimulate\".Motors[{index}].OUT.Run");
- OUT_Reversal = plc.LeerTagBool($"\"DB MotorSimulate\".Motors[{index}].OUT.\"Reversal Direction\"");
- OUT_OUT_VFD_REQ_Speed_Hz = (float)plc.LeerTagInt16($"\"DB MotorSimulate\".Motors[{index}].OUT.OUT_VFD_REQ_Speed_Hz");
+ if (DB_Motor == 0)
+ return;
+
+
+ OUT_Run = plc.LeerTagBool($"\"DB MotorSimulate\".Motors[{DB_Motor}].OUT.Run");
+ OUT_Reversal = plc.LeerTagBool($"\"DB MotorSimulate\".Motors[{DB_Motor}].OUT.\"Reversal Direction\"");
+ OUT_OUT_VFD_REQ_Speed_Hz = (float)plc.LeerTagInt16($"\"DB MotorSimulate\".Motors[{DB_Motor}].OUT.OUT_VFD_REQ_Speed_Hz");
- if (Encendido)
+ if (Data.Encendido)
{
_STATUS_VFD_Ready = true;
Motor_Running = true;
@@ -198,13 +219,16 @@ namespace CtrEditor.ObjetosSim
STATUS_VFD_Coasting = false;
}
- plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{index}].STATUS_VFD_Ready", _STATUS_VFD_Ready);
- plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{index}].Motor_Running", Motor_Running);
- plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{index}].STATUS_VFD_Trip", STATUS_VFD_Trip);
- plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{index}].STATUS_VFD_Warning", STATUS_VFD_Warning);
- plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{index}].STATUS_VFD_Coasting", STATUS_VFD_Coasting);
+ if (Data.VFD_Trip_NC)
+ STATUS_VFD_Trip = !STATUS_VFD_Trip;
- plc.EscribirTagInt16($"\"DB MotorSimulate\".Motors[{index}].STATUS_VFD_ACT_Speed_Hz", (int)STATUS_VFD_ACT_Speed_Hz);
+ plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{DB_Motor}].STATUS_VFD_Ready", _STATUS_VFD_Ready);
+ plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{DB_Motor}].Motor_Running", Motor_Running);
+ plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{DB_Motor}].STATUS_VFD_Trip", STATUS_VFD_Trip);
+ plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{DB_Motor}].STATUS_VFD_Warning", STATUS_VFD_Warning);
+ plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{DB_Motor}].STATUS_VFD_Coasting", STATUS_VFD_Coasting);
+
+ plc.EscribirTagInt16($"\"DB MotorSimulate\".Motors[{DB_Motor}].STATUS_VFD_ACT_Speed_Hz", (int)STATUS_VFD_ACT_Speed_Hz);
}
diff --git a/ObjetosSim/Extraccion Datos/ucBuscarCoincidencias.xaml.cs b/ObjetosSim/Extraccion Datos/ucBuscarCoincidencias.xaml.cs
index e6fce86..555d1a8 100644
--- a/ObjetosSim/Extraccion Datos/ucBuscarCoincidencias.xaml.cs
+++ b/ObjetosSim/Extraccion Datos/ucBuscarCoincidencias.xaml.cs
@@ -435,8 +435,8 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
{
if (Datos is osBuscarCoincidencias datos)
{
- datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
- datos.Alto = PixelToMeter.Instance.calc.PixelsToMeters(height);
+ datos.Ancho += PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.Alto += PixelToMeter.Instance.calc.PixelsToMeters(height);
}
}
public void Move(float LeftPixels, float TopPixels)
@@ -451,7 +451,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
{
if (Datos != null)
if (Datos is osBuscarCoincidencias datos)
- datos.Angulo = Angle;
+ datos.Angulo += Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
diff --git a/ObjetosSim/Extraccion Datos/ucExtraccionTag.xaml.cs b/ObjetosSim/Extraccion Datos/ucExtraccionTag.xaml.cs
index 70e832b..5dbb6fc 100644
--- a/ObjetosSim/Extraccion Datos/ucExtraccionTag.xaml.cs
+++ b/ObjetosSim/Extraccion Datos/ucExtraccionTag.xaml.cs
@@ -208,8 +208,8 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
{
if (Datos is osExtraccionTag datos)
{
- datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
- datos.Alto = PixelToMeter.Instance.calc.PixelsToMeters(height);
+ datos.Ancho += PixelToMeter.Instance.calc.PixelsToMeters(width);
+ datos.Alto += PixelToMeter.Instance.calc.PixelsToMeters(height);
}
}
public void Move(float LeftPixels, float TopPixels)
@@ -224,7 +224,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
{
if (Datos != null)
if (Datos is osExtraccionTag datos)
- datos.Angulo = Angle;
+ datos.Angulo += Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
diff --git a/ObjetosSim/SensoresComandos/ucBoton.xaml b/ObjetosSim/SensoresComandos/ucBoton.xaml
index 36a88e7..ece7860 100644
--- a/ObjetosSim/SensoresComandos/ucBoton.xaml
+++ b/ObjetosSim/SensoresComandos/ucBoton.xaml
@@ -9,7 +9,7 @@
mc:Ignorable="d">
-
+