2024-05-11 11:58:55 -03:00
|
|
|
|
using System.Globalization;
|
2024-05-01 14:45:20 -03:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
2024-06-09 12:33:09 -03:00
|
|
|
|
using System.Windows.Threading;
|
2024-06-09 16:26:09 -03:00
|
|
|
|
using System.Diagnostics;
|
2025-02-18 14:08:55 -03:00
|
|
|
|
using CtrEditor.ObjetosSim;
|
2024-06-30 13:17:44 -03:00
|
|
|
|
using CtrEditor.FuncionesBase;
|
2025-02-18 14:08:55 -03:00
|
|
|
|
using Xceed.Wpf.Toolkit.PropertyGrid;
|
|
|
|
|
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
|
|
|
|
|
using UserControl = System.Windows.Controls.UserControl;
|
2024-05-11 11:58:55 -03:00
|
|
|
|
|
2024-05-01 14:45:20 -03:00
|
|
|
|
namespace CtrEditor
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
2024-05-04 09:06:33 -03:00
|
|
|
|
// Para el Canvas
|
2024-05-03 03:58:21 -03:00
|
|
|
|
private Point _lastMousePosition;
|
2024-05-04 09:06:33 -03:00
|
|
|
|
private bool _isDrawingCanvas = false;
|
|
|
|
|
private bool _isDraggingCanvas = false;
|
2024-05-03 03:58:21 -03:00
|
|
|
|
private Image imagenDeFondo;
|
2025-02-18 14:08:55 -03:00
|
|
|
|
internal ObjectManipulationManager _objectManager;
|
2024-05-03 03:58:21 -03:00
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
// Temporizadores y animación
|
2024-06-09 12:33:09 -03:00
|
|
|
|
private DispatcherTimer _zoomTimer;
|
2024-06-09 16:26:09 -03:00
|
|
|
|
private double _targetZoomFactor;
|
|
|
|
|
private double _initialZoomFactor;
|
|
|
|
|
private double _currentZoomStep;
|
|
|
|
|
private Point _zoomCursorPosition;
|
|
|
|
|
private const int ZoomDuration = 500; // Duración del zoom en milisegundos
|
2024-06-28 14:47:08 -03:00
|
|
|
|
private int _ZoomDuration;
|
2024-06-09 16:26:09 -03:00
|
|
|
|
private const double MinZoomScale = 0.1; // Límite mínimo de zoom
|
|
|
|
|
private Stopwatch _stopwatch;
|
2024-06-09 12:33:09 -03:00
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
private dataDebug dataDebug = new dataDebug();
|
2024-05-04 09:06:33 -03:00
|
|
|
|
|
2024-05-01 14:45:20 -03:00
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-06-09 12:33:09 -03:00
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
_objectManager = new ObjectManipulationManager(this, ImagenEnTrabajoCanvas);
|
|
|
|
|
|
|
|
|
|
// Inicializar temporizador de zoom
|
2024-06-09 16:26:09 -03:00
|
|
|
|
_zoomTimer = new DispatcherTimer();
|
|
|
|
|
_zoomTimer.Interval = TimeSpan.FromMilliseconds(1);
|
|
|
|
|
_zoomTimer.Tick += ZoomTimer_Tick;
|
|
|
|
|
_stopwatch = new Stopwatch();
|
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
// Suscribir eventos
|
2024-05-03 03:58:21 -03:00
|
|
|
|
this.Loaded += MainWindow_Loaded;
|
|
|
|
|
ImagenEnTrabajoScrollViewer.PreviewMouseWheel += ImagenEnTrabajoCanvas_MouseWheel;
|
|
|
|
|
ImagenEnTrabajoCanvas.MouseDown += Canvas_MouseDown_Panning;
|
|
|
|
|
ImagenEnTrabajoCanvas.MouseMove += Canvas_MouseMove_Panning;
|
|
|
|
|
ImagenEnTrabajoCanvas.MouseUp += Canvas_MouseUp_Panning;
|
2025-02-13 12:52:33 -03:00
|
|
|
|
this.KeyDown += MainWindow_KeyDown;
|
2025-02-17 11:16:40 -03:00
|
|
|
|
ImagenEnTrabajoCanvas.MouseEnter += Canvas_MouseEnter;
|
2025-02-18 14:08:55 -03:00
|
|
|
|
this.Closed += MainWindow_Closed;
|
|
|
|
|
|
|
|
|
|
// Importante: Agregar el evento para el menú contextual
|
|
|
|
|
ImagenEnTrabajoCanvas.MouseRightButtonDown += Canvas_MouseRightButtonDown;
|
2024-05-03 03:58:21 -03:00
|
|
|
|
}
|
2025-02-13 12:52:33 -03:00
|
|
|
|
|
2024-05-03 03:58:21 -03:00
|
|
|
|
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (DataContext is MainViewModel viewModel)
|
|
|
|
|
{
|
2024-05-18 06:49:02 -03:00
|
|
|
|
viewModel.MainWindow = this;
|
2024-06-28 14:47:08 -03:00
|
|
|
|
viewModel.ImageSelected += ViewModel_ImageSelected;
|
2025-02-18 14:08:55 -03:00
|
|
|
|
viewModel?.LoadInitialData();
|
2024-05-14 03:15:54 -03:00
|
|
|
|
viewModel.simulationManager.DebugCanvas = ImagenEnTrabajoCanvas;
|
2024-05-31 14:25:24 -03:00
|
|
|
|
viewModel.MainCanvas = ImagenEnTrabajoCanvas;
|
2024-05-03 03:58:21 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-04 06:00:52 -03:00
|
|
|
|
|
2024-05-18 06:49:02 -03:00
|
|
|
|
public void SuscribirEventos(UserControl userControl)
|
2024-05-04 06:00:52 -03:00
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
_objectManager.SuscribirEventos(userControl);
|
2024-05-18 06:49:02 -03:00
|
|
|
|
}
|
2024-05-04 09:06:33 -03:00
|
|
|
|
|
2024-05-18 06:49:02 -03:00
|
|
|
|
public void AgregarRegistrarUserControlCanvas(UserControl userControl)
|
|
|
|
|
{
|
|
|
|
|
if (userControl is IDataContainer dataContainer)
|
|
|
|
|
{
|
|
|
|
|
SuscribirEventos(userControl);
|
2025-02-13 10:00:47 -03:00
|
|
|
|
Canvas.SetZIndex(userControl, ((int)dataContainer.ZIndex_Base() + dataContainer.zIndex_fromFrames));
|
2024-05-14 03:15:54 -03:00
|
|
|
|
ImagenEnTrabajoCanvas.Children.Add(userControl);
|
2024-05-04 06:00:52 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-18 09:58:41 -03:00
|
|
|
|
public void EliminarUserControlDelCanvas(UserControl userControl)
|
|
|
|
|
{
|
|
|
|
|
if (ImagenEnTrabajoCanvas.Children.Contains(userControl))
|
2024-06-28 14:47:08 -03:00
|
|
|
|
{
|
2024-05-18 09:58:41 -03:00
|
|
|
|
ImagenEnTrabajoCanvas.Children.Remove(userControl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 03:58:21 -03:00
|
|
|
|
private void LoadImageToCanvas(string imagePath)
|
|
|
|
|
{
|
|
|
|
|
BitmapImage bitmap = new BitmapImage(new Uri(imagePath, UriKind.Absolute));
|
|
|
|
|
|
|
|
|
|
if (imagenDeFondo == null)
|
|
|
|
|
{
|
|
|
|
|
imagenDeFondo = new Image();
|
|
|
|
|
ImagenEnTrabajoCanvas.Children.Add(imagenDeFondo);
|
|
|
|
|
}
|
|
|
|
|
imagenDeFondo.Source = bitmap;
|
|
|
|
|
RenderOptions.SetBitmapScalingMode(imagenDeFondo, BitmapScalingMode.HighQuality);
|
|
|
|
|
|
|
|
|
|
// Elimina solo los ROIs, no la imagen de fondo
|
|
|
|
|
for (int i = ImagenEnTrabajoCanvas.Children.Count - 1; i >= 0; i--)
|
|
|
|
|
{
|
2024-05-04 06:00:52 -03:00
|
|
|
|
if (ImagenEnTrabajoCanvas.Children[i] is not Image)
|
2024-05-03 03:58:21 -03:00
|
|
|
|
{
|
|
|
|
|
ImagenEnTrabajoCanvas.Children.RemoveAt(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImagenEnTrabajoCanvas.Width = bitmap.Width;
|
|
|
|
|
ImagenEnTrabajoCanvas.Height = bitmap.Height;
|
|
|
|
|
|
|
|
|
|
Canvas.SetLeft(imagenDeFondo, 0);
|
|
|
|
|
Canvas.SetTop(imagenDeFondo, 0);
|
2024-05-01 14:45:20 -03:00
|
|
|
|
}
|
2024-05-02 11:06:45 -03:00
|
|
|
|
|
2024-05-03 03:58:21 -03:00
|
|
|
|
private void Canvas_MouseUp_Panning(object sender, MouseButtonEventArgs e)
|
|
|
|
|
{
|
2024-05-04 09:06:33 -03:00
|
|
|
|
if (_isDraggingCanvas)
|
2024-05-03 03:58:21 -03:00
|
|
|
|
{
|
2024-05-04 09:06:33 -03:00
|
|
|
|
_isDraggingCanvas = false;
|
2025-02-18 14:08:55 -03:00
|
|
|
|
ImagenEnTrabajoCanvas.ReleaseMouseCapture();
|
2025-02-17 11:16:40 -03:00
|
|
|
|
|
|
|
|
|
if (DataContext is MainViewModel viewModel && viewModel.SelectedItemOsList != null)
|
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
_objectManager.MakeResizeRectanglesNormal();
|
2025-02-17 11:16:40 -03:00
|
|
|
|
}
|
2025-02-18 14:08:55 -03:00
|
|
|
|
e.Handled = true;
|
2024-05-03 03:58:21 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Canvas_MouseDown_Panning(object sender, MouseButtonEventArgs e)
|
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
if (e.LeftButton == MouseButtonState.Pressed && !_isDrawingCanvas)
|
2024-05-03 03:58:21 -03:00
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
// Solo activar el panning si el clic fue directamente en el canvas
|
2025-02-17 11:16:40 -03:00
|
|
|
|
if (e.Source == ImagenEnTrabajoCanvas)
|
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
_isDraggingCanvas = true;
|
|
|
|
|
_lastMousePosition = e.GetPosition(ImagenEnTrabajoScrollViewer);
|
|
|
|
|
ImagenEnTrabajoCanvas.CaptureMouse();
|
|
|
|
|
|
2025-02-17 11:16:40 -03:00
|
|
|
|
if (DataContext is MainViewModel viewModel)
|
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
viewModel.SelectedItemOsList = null;
|
|
|
|
|
_objectManager.RemoveResizeRectangles();
|
2025-02-17 11:16:40 -03:00
|
|
|
|
}
|
2025-02-18 14:08:55 -03:00
|
|
|
|
e.Handled = true;
|
2025-02-17 11:16:40 -03:00
|
|
|
|
}
|
2024-05-03 03:58:21 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Canvas_MouseMove_Panning(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
if (_isDraggingCanvas && e.LeftButton == MouseButtonState.Pressed)
|
2024-05-03 03:58:21 -03:00
|
|
|
|
{
|
|
|
|
|
var currentPosition = e.GetPosition(ImagenEnTrabajoScrollViewer);
|
|
|
|
|
var dx = currentPosition.X - _lastMousePosition.X;
|
|
|
|
|
var dy = currentPosition.Y - _lastMousePosition.Y;
|
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
_objectManager.MakeResizeRectanglesTransparent();
|
|
|
|
|
_objectManager.RemoveHighlightRectangles();
|
2024-06-28 14:47:08 -03:00
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
var transform = (TranslateTransform)((TransformGroup)ImagenEnTrabajoCanvas.RenderTransform)
|
|
|
|
|
.Children.First(t => t is TranslateTransform);
|
2024-06-09 12:33:09 -03:00
|
|
|
|
transform.X += dx;
|
|
|
|
|
transform.Y += dy;
|
2024-05-03 03:58:21 -03:00
|
|
|
|
|
|
|
|
|
_lastMousePosition = currentPosition;
|
2025-02-18 14:08:55 -03:00
|
|
|
|
e.Handled = true;
|
2024-05-03 03:58:21 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ImagenEnTrabajoCanvas_MouseWheel(object sender, MouseWheelEventArgs e)
|
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
_objectManager.MakeResizeRectanglesTransparent();
|
|
|
|
|
_objectManager.RemoveHighlightRectangles();
|
2024-06-28 14:47:08 -03:00
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
_initialZoomFactor = ((ScaleTransform)((TransformGroup)ImagenEnTrabajoCanvas.RenderTransform)
|
|
|
|
|
.Children.First(t => t is ScaleTransform)).ScaleX;
|
2024-06-09 16:26:09 -03:00
|
|
|
|
|
|
|
|
|
double minZoomFactor = Math.Min(
|
|
|
|
|
ImagenEnTrabajoScrollViewer.ViewportWidth / ImagenEnTrabajoCanvas.ActualWidth,
|
|
|
|
|
ImagenEnTrabajoScrollViewer.ViewportHeight / ImagenEnTrabajoCanvas.ActualHeight);
|
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
_targetZoomFactor = e.Delta > 0 ?
|
|
|
|
|
_initialZoomFactor * 1.4 :
|
|
|
|
|
Math.Max(_initialZoomFactor * 0.75, minZoomFactor);
|
2024-06-09 16:26:09 -03:00
|
|
|
|
|
|
|
|
|
_zoomCursorPosition = e.GetPosition(ImagenEnTrabajoCanvas);
|
|
|
|
|
|
|
|
|
|
RenderOptions.SetBitmapScalingMode(ImagenEnTrabajoCanvas, BitmapScalingMode.LowQuality);
|
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
_ZoomDuration = !_zoomTimer.IsEnabled ? ZoomDuration : ZoomDuration / 3;
|
2024-06-09 16:26:09 -03:00
|
|
|
|
|
|
|
|
|
_stopwatch.Restart();
|
|
|
|
|
_zoomTimer.Start();
|
|
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ZoomTimer_Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
2025-02-13 10:00:47 -03:00
|
|
|
|
double elapsedMilliseconds = _stopwatch.Elapsed.TotalMilliseconds;
|
2024-06-09 16:26:09 -03:00
|
|
|
|
|
|
|
|
|
if (elapsedMilliseconds >= _ZoomDuration)
|
|
|
|
|
{
|
|
|
|
|
_zoomTimer.Stop();
|
|
|
|
|
_stopwatch.Stop();
|
|
|
|
|
|
|
|
|
|
RenderOptions.SetBitmapScalingMode(ImagenEnTrabajoCanvas, BitmapScalingMode.HighQuality);
|
|
|
|
|
|
2025-02-17 11:16:40 -03:00
|
|
|
|
if (DataContext is MainViewModel viewModel && viewModel.SelectedItemOsList != null)
|
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
_objectManager.MakeResizeRectanglesNormal();
|
2025-02-17 11:16:40 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-09 16:26:09 -03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-09 12:33:09 -03:00
|
|
|
|
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);
|
|
|
|
|
|
2024-06-09 16:26:09 -03:00
|
|
|
|
double t = elapsedMilliseconds / _ZoomDuration;
|
2025-02-18 14:08:55 -03:00
|
|
|
|
double easeOutT = t * (2 - t);
|
2024-06-09 16:26:09 -03:00
|
|
|
|
double zoomFactor = _initialZoomFactor + (_targetZoomFactor - _initialZoomFactor) * easeOutT;
|
|
|
|
|
|
|
|
|
|
zoomFactor = Math.Max(zoomFactor, MinZoomScale);
|
|
|
|
|
|
|
|
|
|
Point cursorPosition = _zoomCursorPosition;
|
2024-05-03 03:58:21 -03:00
|
|
|
|
|
2024-06-09 12:33:09 -03:00
|
|
|
|
var relativeX = cursorPosition.X * st.ScaleX + tt.X;
|
|
|
|
|
var relativeY = cursorPosition.Y * st.ScaleY + tt.Y;
|
2024-05-03 03:58:21 -03:00
|
|
|
|
|
2024-06-09 16:26:09 -03:00
|
|
|
|
st.ScaleX = zoomFactor;
|
|
|
|
|
st.ScaleY = zoomFactor;
|
2024-05-03 03:58:21 -03:00
|
|
|
|
|
2024-06-09 12:33:09 -03:00
|
|
|
|
tt.X = relativeX - cursorPosition.X * st.ScaleX;
|
|
|
|
|
tt.Y = relativeY - cursorPosition.Y * st.ScaleY;
|
2024-05-03 03:58:21 -03:00
|
|
|
|
}
|
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
private void ListaOs_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UserControlFactory.LimpiarPropiedadesosDatos(PanelEdicion);
|
|
|
|
|
|
|
|
|
|
if (e.AddedItems.Count > 0 && e.AddedItems[0] is osBase selectedObject)
|
|
|
|
|
{
|
|
|
|
|
// Siempre trabajar con selección única para las propiedades
|
|
|
|
|
CargarPropiedadesosDatos(selectedObject);
|
|
|
|
|
|
|
|
|
|
// No modificar la selección múltiple aquí, solo actualizar los rectángulos de manipulación
|
|
|
|
|
// si el objeto seleccionado no está en la selección actual
|
|
|
|
|
if (!_objectManager.SelectedObjects.Contains(selectedObject))
|
|
|
|
|
{
|
|
|
|
|
if (!((MainViewModel)DataContext).IsMultiSelectionActive)
|
|
|
|
|
{
|
|
|
|
|
_objectManager.ClearSelection();
|
|
|
|
|
_objectManager.SelectObject(selectedObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_objectManager.RemoveResizeRectangles();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainWindow_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (DataContext is MainViewModel viewModel)
|
|
|
|
|
{
|
|
|
|
|
if (e.Key == Key.Delete)
|
|
|
|
|
{
|
|
|
|
|
viewModel.EliminarObjetoSeleccionado();
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
else if (e.Key == Key.Escape)
|
|
|
|
|
{
|
|
|
|
|
// Limpiar la selección en el ListBox
|
|
|
|
|
viewModel.SelectedItemOsList = null;
|
|
|
|
|
|
|
|
|
|
// Limpiar la selección múltiple
|
|
|
|
|
_objectManager.ClearSelection();
|
|
|
|
|
_objectManager.RemoveResizeRectangles();
|
|
|
|
|
|
|
|
|
|
// Desactivar el modo de selección múltiple
|
|
|
|
|
viewModel.IsMultiSelectionActive = false;
|
|
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Canvas_MouseEnter(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.OriginalSource == ImagenEnTrabajoCanvas)
|
|
|
|
|
{
|
|
|
|
|
//_objectManager.RemoveResizeRectangles();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainWindow_Closed(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (DataContext is MainViewModel viewModel)
|
|
|
|
|
{
|
|
|
|
|
viewModel.ImageSelected -= ViewModel_ImageSelected;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CargarPropiedadesosDatos(osBase selectedObject)
|
|
|
|
|
{
|
|
|
|
|
if (DataContext is MainViewModel viewModel)
|
|
|
|
|
viewModel.CargarPropiedadesosDatos(selectedObject, PanelEdicion, Resources);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public (float X, float Y) ObtenerCentroCanvasMeters()
|
|
|
|
|
{
|
|
|
|
|
var c = ObtenerCentroCanvasPixels();
|
|
|
|
|
return (PixelToMeter.Instance.calc.PixelsToMeters(c.X),
|
|
|
|
|
PixelToMeter.Instance.calc.PixelsToMeters(c.Y));
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-28 14:47:08 -03:00
|
|
|
|
public (float X, float Y) ObtenerCentroCanvasPixels()
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
double visibleWidth = ImagenEnTrabajoScrollViewer.ViewportWidth;
|
|
|
|
|
double visibleHeight = ImagenEnTrabajoScrollViewer.ViewportHeight;
|
|
|
|
|
|
|
|
|
|
double offsetX = ImagenEnTrabajoScrollViewer.HorizontalOffset;
|
|
|
|
|
double offsetY = ImagenEnTrabajoScrollViewer.VerticalOffset;
|
|
|
|
|
|
|
|
|
|
double centerX = offsetX + (visibleWidth / 2);
|
|
|
|
|
double centerY = offsetY + (visibleHeight / 2);
|
|
|
|
|
|
|
|
|
|
double canvasCenterX = (centerX - tt.X) / st.ScaleX;
|
|
|
|
|
double canvasCenterY = (centerY - tt.Y) / st.ScaleY;
|
|
|
|
|
|
|
|
|
|
return ((float)canvasCenterX, (float)canvasCenterY);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
private void ViewModel_ImageSelected(object sender, string imagePath)
|
2024-05-04 15:35:06 -03:00
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
LoadImageToCanvas(imagePath);
|
2024-05-04 15:35:06 -03:00
|
|
|
|
}
|
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
public void DebugWindow()
|
2024-05-03 03:58:21 -03:00
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
var debugWindow = new wDebug
|
2024-05-03 03:58:21 -03:00
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
Data = dataDebug
|
|
|
|
|
};
|
|
|
|
|
debugWindow.Show();
|
2024-05-03 03:58:21 -03:00
|
|
|
|
}
|
2024-05-02 11:06:45 -03:00
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
private void Canvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
2024-06-11 14:43:12 -03:00
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
// Aceptar el evento si viene del canvas o de la imagen de fondo
|
|
|
|
|
if ((e.Source == ImagenEnTrabajoCanvas || e.Source == imagenDeFondo) && DataContext is MainViewModel viewModel)
|
2025-02-17 11:16:40 -03:00
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
e.Handled = true; // Importante: marcar el evento como manejado
|
|
|
|
|
ShowContextMenu(e.GetPosition(ImagenEnTrabajoCanvas));
|
2024-06-30 13:17:44 -03:00
|
|
|
|
}
|
2024-06-11 14:43:12 -03:00
|
|
|
|
}
|
2025-02-13 12:52:33 -03:00
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
private void ShowContextMenu(Point position)
|
2025-02-13 12:52:33 -03:00
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
var contextMenu = new ContextMenu();
|
|
|
|
|
var multiSelectMenuItem = new MenuItem
|
|
|
|
|
{
|
|
|
|
|
Header = "Modo Multi-Selección",
|
|
|
|
|
IsCheckable = true,
|
|
|
|
|
StaysOpenOnClick = false // Cerrar el menú al hacer clic
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-17 11:16:40 -03:00
|
|
|
|
if (DataContext is MainViewModel viewModel)
|
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
multiSelectMenuItem.IsChecked = viewModel.IsMultiSelectionActive;
|
|
|
|
|
multiSelectMenuItem.Click += (s, e) =>
|
2025-02-17 11:16:40 -03:00
|
|
|
|
{
|
2025-02-18 14:08:55 -03:00
|
|
|
|
viewModel.IsMultiSelectionActive = multiSelectMenuItem.IsChecked;
|
|
|
|
|
};
|
2025-02-17 11:16:40 -03:00
|
|
|
|
}
|
|
|
|
|
|
2025-02-18 14:08:55 -03:00
|
|
|
|
contextMenu.Items.Add(multiSelectMenuItem);
|
|
|
|
|
contextMenu.PlacementTarget = ImagenEnTrabajoCanvas;
|
|
|
|
|
contextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
|
|
|
|
|
contextMenu.IsOpen = true;
|
2025-02-13 12:52:33 -03:00
|
|
|
|
}
|
2024-05-01 14:45:20 -03:00
|
|
|
|
}
|
2024-05-11 11:58:55 -03:00
|
|
|
|
|
|
|
|
|
public class FloatValidationRule : ValidationRule
|
|
|
|
|
{
|
|
|
|
|
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(value?.ToString()))
|
|
|
|
|
return new ValidationResult(false, "El campo no puede estar vacío.");
|
|
|
|
|
|
|
|
|
|
if (float.TryParse(value.ToString(), NumberStyles.Float, cultureInfo, out float result))
|
2025-02-18 14:08:55 -03:00
|
|
|
|
return ValidationResult.ValidResult;
|
2024-05-11 11:58:55 -03:00
|
|
|
|
else
|
|
|
|
|
return new ValidationResult(false, "Ingrese un número válido.");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-01 14:45:20 -03:00
|
|
|
|
}
|