Compare commits
2 Commits
e14c28920f
...
b6b078f8ce
Author | SHA1 | Date |
---|---|---|
|
b6b078f8ce | |
|
3fe845b02f |
|
@ -945,6 +945,33 @@ namespace CtrEditor
|
|||
plcSampleCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Reemplazar la propiedad _multiPropertyEditorWindow por un diccionario
|
||||
private Dictionary<string, Windows.MultiPropertyEditorWindow> _propertyEditorWindows = new();
|
||||
|
||||
public void ShowMultiPropertyEditor(IEnumerable<osBase> selectedObjects)
|
||||
{
|
||||
var objectsList = selectedObjects.ToList();
|
||||
// Crear una clave única basada en los IDs de los objetos seleccionados
|
||||
string key = string.Join("_", objectsList.Select(o => o.Id.Value).OrderBy(id => id));
|
||||
|
||||
// Verificar si ya existe una ventana para esta selección
|
||||
if (_propertyEditorWindows.TryGetValue(key, out var existingWindow) &&
|
||||
existingWindow.IsVisible)
|
||||
{
|
||||
existingWindow.Activate();
|
||||
return;
|
||||
}
|
||||
|
||||
// Crear nueva ventana
|
||||
var window = new Windows.MultiPropertyEditorWindow(objectsList, MainWindow);
|
||||
window.Closed += (s, e) => _propertyEditorWindows.Remove(key);
|
||||
_propertyEditorWindows[key] = window;
|
||||
|
||||
window.Show();
|
||||
HasUnsavedChanges = true;
|
||||
_objectManager.UpdateSelectionVisuals();
|
||||
}
|
||||
}
|
||||
public class SimulationData
|
||||
{
|
||||
|
|
|
@ -610,6 +610,16 @@ namespace CtrEditor
|
|||
contextMenu.Items.Add(alignSubmenu);
|
||||
}
|
||||
|
||||
// Add Edit Properties option when objects are selected
|
||||
if (_objectManager.SelectedObjects.Count > 0)
|
||||
{
|
||||
var editPropertiesItem = new MenuItem { Header = "Edit Properties" };
|
||||
editPropertiesItem.Click += (s, e) => viewModel.ShowMultiPropertyEditor(_objectManager.SelectedObjects);
|
||||
contextMenu.Items.Add(editPropertiesItem);
|
||||
|
||||
contextMenu.Items.Add(new Separator());
|
||||
}
|
||||
|
||||
contextMenu.IsOpen = true;
|
||||
contextMenu.PlacementTarget = ImagenEnTrabajoCanvas;
|
||||
contextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
|
||||
|
|
|
@ -95,6 +95,33 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
Search_templates = false;
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
[property: Category("Tag Extraction:")]
|
||||
bool tomarClip;
|
||||
|
||||
// En lugar de almacenar Mat directamente, guardaremos una representación serializable
|
||||
[ObservableProperty]
|
||||
[property: Category("Tag Extraction:")]
|
||||
byte[] capturedRegionData;
|
||||
|
||||
[ObservableProperty]
|
||||
[property: Category("Tag Extraction:")]
|
||||
[property: ReadOnly(true)]
|
||||
bool regionCapturada;
|
||||
|
||||
// Para uso interno (no serializado)
|
||||
[JsonIgnore]
|
||||
private Mat _capturedRegion;
|
||||
|
||||
// Propiedades para almacenar las dimensiones de la captura
|
||||
[ObservableProperty]
|
||||
[property: Category("Tag Extraction:")]
|
||||
int capturedWidth;
|
||||
|
||||
[ObservableProperty]
|
||||
[property: Category("Tag Extraction:")]
|
||||
int capturedHeight;
|
||||
|
||||
[ObservableProperty]
|
||||
[property: Category("Tag Extraction:")]
|
||||
bool export_ocr;
|
||||
|
@ -103,6 +130,200 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
[property: Category("Tag Extraction:")]
|
||||
string text_export_ocr;
|
||||
|
||||
|
||||
// Esta propiedad manejará la conversión entre Mat y datos serializables
|
||||
[JsonIgnore]
|
||||
public Mat CapturedRegion
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_capturedRegion == null && CapturedRegionData != null && CapturedRegionData.Length > 0)
|
||||
{
|
||||
// Recrear Mat desde los datos almacenados
|
||||
_capturedRegion = BytesToMat(CapturedRegionData, CapturedWidth, CapturedHeight);
|
||||
}
|
||||
return _capturedRegion;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
// Convertir Mat a bytes para serialización
|
||||
CapturedRegionData = MatToBytes(value);
|
||||
CapturedWidth = value.Width;
|
||||
CapturedHeight = value.Height;
|
||||
_capturedRegion = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
CapturedRegionData = null;
|
||||
CapturedWidth = 0;
|
||||
CapturedHeight = 0;
|
||||
_capturedRegion = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
partial void OnTomarClipChanged(bool oldValue, bool newValue)
|
||||
{
|
||||
if (tomarClip)
|
||||
{
|
||||
CapturarRegionActual();
|
||||
TomarClip = false; // Resetear el flag después de la captura
|
||||
}
|
||||
}
|
||||
|
||||
// Método para capturar la región actual
|
||||
private void CapturarRegionActual()
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
if (_mainViewModel?.MainCanvas.Children[0] is Image imagenDeFondo)
|
||||
{
|
||||
if (imagenDeFondo.Source is BitmapSource bitmapSource)
|
||||
{
|
||||
// Obtener los DPI de la imagen original
|
||||
float originalDpiX = (float)bitmapSource.DpiX;
|
||||
float originalDpiY = (float)bitmapSource.DpiY;
|
||||
|
||||
// Estándar DPI en el que el Canvas renderiza la imagen
|
||||
float canvasDpiX = 96;
|
||||
float canvasDpiY = 96;
|
||||
|
||||
// Calcular el ratio de escala entre el Canvas y la imagen original
|
||||
float scaleFactorX = originalDpiX / canvasDpiX;
|
||||
float scaleFactorY = originalDpiY / canvasDpiY;
|
||||
|
||||
// Ajustar las coordenadas de recorte en función del ratio de escala
|
||||
int x = (int)MeterToPixels(Left * scaleFactorX);
|
||||
int y = (int)MeterToPixels(Top * scaleFactorY);
|
||||
int width = (int)MeterToPixels(Ancho * scaleFactorX);
|
||||
int height = (int)MeterToPixels(Alto * scaleFactorY);
|
||||
|
||||
// Validar y ajustar el tamaño del recorte para que se mantenga dentro de los límites de la imagen
|
||||
if (x < 0) x = 0;
|
||||
if (y < 0) y = 0;
|
||||
if (x + width > bitmapSource.PixelWidth) width = bitmapSource.PixelWidth - x;
|
||||
if (y + height > bitmapSource.PixelHeight) height = bitmapSource.PixelHeight - y;
|
||||
|
||||
// Recortar el área deseada utilizando las coordenadas ajustadas
|
||||
CroppedBitmap croppedBitmap = new CroppedBitmap(bitmapSource, new Int32Rect(x, y, width, height));
|
||||
|
||||
// Capturar la región y almacenarla
|
||||
if (_capturedRegion != null)
|
||||
{
|
||||
_capturedRegion.Dispose(); // Liberar recursos previos
|
||||
}
|
||||
|
||||
// Usar la propiedad que maneja la serialización
|
||||
CapturedRegion = BitmapSourceToMat(croppedBitmap);
|
||||
|
||||
// Actualizar el estado
|
||||
RegionCapturada = true;
|
||||
MessageBox.Show("Región capturada correctamente.", "Información", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Métodos para convertir entre Mat y bytes
|
||||
private byte[] MatToBytes(Mat mat)
|
||||
{
|
||||
if (mat == null)
|
||||
return null;
|
||||
|
||||
// Asegurar que tenemos un formato consistente para serialización
|
||||
Mat bgr = new Mat();
|
||||
if (mat.NumberOfChannels != 3)
|
||||
{
|
||||
CvInvoke.CvtColor(mat, bgr, mat.NumberOfChannels == 1 ?
|
||||
ColorConversion.Gray2Bgr : ColorConversion.Bgra2Bgr);
|
||||
}
|
||||
else
|
||||
{
|
||||
bgr = mat.Clone();
|
||||
}
|
||||
|
||||
// Convertir a un formato que pueda ser serializado
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
// Convertir Mat a Bitmap
|
||||
Bitmap bitmap = bgr.ToBitmap();
|
||||
|
||||
// Guardar como PNG (sin pérdida de calidad)
|
||||
bitmap.Save(ms, ImageFormat.Png);
|
||||
|
||||
// Liberar recursos
|
||||
bitmap.Dispose();
|
||||
if (bgr != mat)
|
||||
bgr.Dispose();
|
||||
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private Mat BytesToMat(byte[] bytes, int width, int height)
|
||||
{
|
||||
if (bytes == null || bytes.Length == 0)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream(bytes))
|
||||
{
|
||||
// Cargar imagen desde bytes
|
||||
Bitmap bitmap = (Bitmap)System.Drawing.Image.FromStream(ms);
|
||||
|
||||
// Convertir Bitmap a Mat
|
||||
Image<Bgr, byte> img = bitmap.ToImage<Bgr, byte>();
|
||||
|
||||
// Liberar recursos
|
||||
bitmap.Dispose();
|
||||
|
||||
// Si las dimensiones no coinciden, redimensionar
|
||||
if (img.Width != width || img.Height != height)
|
||||
{
|
||||
CvInvoke.Resize(img.Mat, img.Mat, new Size(width, height));
|
||||
}
|
||||
|
||||
return img.Mat;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Error al reconstruir Mat: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Sobrescribir los métodos de cambio de tamaño para limpiar la región capturada
|
||||
public override void AnchoChanged(float newValue)
|
||||
{
|
||||
base.AnchoChanged(newValue);
|
||||
//LimpiarRegionCapturada();
|
||||
}
|
||||
|
||||
public override void AltoChanged(float newValue)
|
||||
{
|
||||
base.AnchoChanged(newValue);
|
||||
// LimpiarRegionCapturada();
|
||||
}
|
||||
|
||||
private void LimpiarRegionCapturada()
|
||||
{
|
||||
if (_capturedRegion != null)
|
||||
{
|
||||
_capturedRegion.Dispose();
|
||||
_capturedRegion = null;
|
||||
}
|
||||
|
||||
// Usar la propiedad para manejar la serialización
|
||||
CapturedRegion = null;
|
||||
RegionCapturada = false;
|
||||
}
|
||||
|
||||
|
||||
partial void OnExport_ocrChanged(bool value)
|
||||
{
|
||||
if (Export_ocr)
|
||||
|
@ -211,6 +432,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
progressDialog.Show();
|
||||
}
|
||||
|
||||
// Modificar el método BuscarCoincidenciasAsync para usar la región capturada si está disponible
|
||||
private void BuscarCoincidenciasAsync(ProgressDialog progressDialog)
|
||||
{
|
||||
// Reset the Canvas children
|
||||
|
@ -221,29 +443,55 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
{
|
||||
_mainViewModel.MainCanvas.Children.Remove(shape);
|
||||
}
|
||||
|
||||
if (_mainViewModel?.MainCanvas.Children[0] is Image imagenDeFondo)
|
||||
{
|
||||
// Asegurarse de que la imagen origen está disponible
|
||||
if (imagenDeFondo.Source is BitmapSource bitmapSource)
|
||||
{
|
||||
progressDialog.ReportProgress(10);
|
||||
|
||||
Mat templateMat;
|
||||
int width, height;
|
||||
float scaleFactorX, scaleFactorY;
|
||||
bool deleteTemplateMat = false;
|
||||
|
||||
// Usar la región capturada si existe, de lo contrario capturar la región actual
|
||||
if (CapturedRegion != null && RegionCapturada)
|
||||
{
|
||||
// Usar la región almacenada (ya deserializada)
|
||||
templateMat = CapturedRegion.Clone();
|
||||
deleteTemplateMat = true;
|
||||
width = templateMat.Width;
|
||||
height = templateMat.Height;
|
||||
|
||||
// Para mantener la relación con la imagen original
|
||||
float originalDpiX = (float)bitmapSource.DpiX;
|
||||
float originalDpiY = (float)bitmapSource.DpiY;
|
||||
float canvasDpiX = 96;
|
||||
float canvasDpiY = 96;
|
||||
scaleFactorX = originalDpiX / canvasDpiX;
|
||||
scaleFactorY = originalDpiY / canvasDpiY;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Obtener los DPI de la imagen original
|
||||
float originalDpiX = (float)bitmapSource.DpiX;
|
||||
float originalDpiY = (float)bitmapSource.DpiY;
|
||||
|
||||
// Estándar DPI en el que el Canvas renderiza la imagen
|
||||
float canvasDpiX = 96; // WPF usually renders at 96 DPI
|
||||
float canvasDpiX = 96;
|
||||
float canvasDpiY = 96;
|
||||
|
||||
// Calcular el ratio de escala entre el Canvas y la imagen original
|
||||
float scaleFactorX = originalDpiX / canvasDpiX;
|
||||
float scaleFactorY = originalDpiY / canvasDpiY;
|
||||
scaleFactorX = originalDpiX / canvasDpiX;
|
||||
scaleFactorY = originalDpiY / canvasDpiY;
|
||||
|
||||
// Ajustar las coordenadas de recorte en función del ratio de escala
|
||||
int x = (int)MeterToPixels(Left * scaleFactorX);
|
||||
int y = (int)MeterToPixels(Top * scaleFactorY);
|
||||
int width = (int)MeterToPixels(Ancho * scaleFactorX);
|
||||
int height = (int)MeterToPixels(Alto * scaleFactorY);
|
||||
width = (int)MeterToPixels(Ancho * scaleFactorX);
|
||||
height = (int)MeterToPixels(Alto * scaleFactorY);
|
||||
|
||||
// Validar y ajustar el tamaño del recorte para que se mantenga dentro de los límites de la imagen
|
||||
if (x < 0) x = 0;
|
||||
|
@ -255,7 +503,9 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
CroppedBitmap croppedBitmap = new CroppedBitmap(bitmapSource, new Int32Rect(x, y, width, height));
|
||||
|
||||
// Convertir CroppedBitmap a Mat directamente
|
||||
Mat templateMat = BitmapSourceToMat(croppedBitmap);
|
||||
templateMat = BitmapSourceToMat(croppedBitmap);
|
||||
deleteTemplateMat = true;
|
||||
}
|
||||
|
||||
int scale = 4;
|
||||
|
||||
|
@ -265,6 +515,9 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
Mat templateGrayResized = new Mat();
|
||||
CvInvoke.Resize(templateGray, templateGrayResized, new Size(templateGray.Width / scale, templateGray.Height / scale), 0, 0, Inter.Linear);
|
||||
progressDialog.ReportProgress(20);
|
||||
|
||||
// El resto del código permanece igual...
|
||||
|
||||
// Cargar la imagen principal completa en un Mat
|
||||
Mat mainImageMat = BitmapSourceToMat(bitmapSource);
|
||||
|
||||
|
@ -293,9 +546,6 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
else
|
||||
search_rectangles = new List<Rect>();
|
||||
|
||||
// Añadir el rectángulo usado por croppedBitmap a search_rectangles
|
||||
//search_rectangles.Add(new Rect(x / scaleFactorX, y / scaleFactorY, width / scaleFactorX, height / scaleFactorY));
|
||||
|
||||
// Obtener los puntos que superan el umbral
|
||||
float[] resultArray = result.GetData(false) as float[];
|
||||
if (resultArray != null)
|
||||
|
@ -342,18 +592,36 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
Coincidencias = ConteoPositivos;
|
||||
progressDialog.ReportProgress(90);
|
||||
if (ConteoPositivos > 20)
|
||||
{
|
||||
// Liberar recursos antes de salir
|
||||
if (deleteTemplateMat) templateMat.Dispose();
|
||||
templateGray.Dispose();
|
||||
templateGrayResized.Dispose();
|
||||
mainImageMat.Dispose();
|
||||
mainImageGray.Dispose();
|
||||
mainImageGrayResized.Dispose();
|
||||
result.Dispose();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
PopularTagExtraction();
|
||||
}
|
||||
|
||||
// Limpiar recursos
|
||||
if (deleteTemplateMat) templateMat.Dispose();
|
||||
templateGray.Dispose();
|
||||
templateGrayResized.Dispose();
|
||||
mainImageMat.Dispose();
|
||||
mainImageGray.Dispose();
|
||||
mainImageGrayResized.Dispose();
|
||||
result.Dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void PopularTagExtraction()
|
||||
{
|
||||
var objetosSimulablesCopy = new List<osBase>(_mainViewModel.ObjetosSimulables);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
using System.Windows;
|
||||
using System.Diagnostics;
|
||||
using nkast.Aether.Physics2D.Dynamics;
|
||||
|
@ -9,15 +8,16 @@ using nkast.Aether.Physics2D.Common;
|
|||
using nkast.Aether.Physics2D.Collision.Shapes;
|
||||
using nkast.Aether.Physics2D.Dynamics.Contacts;
|
||||
using nkast.Aether.Physics2D.Dynamics.Joints;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CtrEditor.Simulacion
|
||||
{
|
||||
public class simBase
|
||||
{
|
||||
public Body Body { get; protected set; }
|
||||
public World _world;
|
||||
|
||||
public World _world;
|
||||
public void RemoverBody()
|
||||
{
|
||||
if (Body != null && _world.BodyList.Count > 0 && _world.BodyList.Contains(Body))
|
||||
|
@ -25,6 +25,7 @@ namespace CtrEditor.Simulacion
|
|||
_world.Remove(Body);
|
||||
}
|
||||
}
|
||||
|
||||
public static float Min(float Value, float Min = 0.01f)
|
||||
{
|
||||
return Value < Min ? Min : Value;
|
||||
|
@ -34,21 +35,26 @@ namespace CtrEditor.Simulacion
|
|||
{
|
||||
return (float)(grados * (Math.PI / 180));
|
||||
}
|
||||
|
||||
public static float RadianesAGrados(float radianes)
|
||||
{
|
||||
return (float)(radianes * (180 / Math.PI));
|
||||
}
|
||||
|
||||
public void SetPosition(float x, float y)
|
||||
{
|
||||
Body.SetTransform(new Vector2(x, y), Body.Rotation);
|
||||
}
|
||||
|
||||
public void SetPosition(Vector2 centro)
|
||||
{
|
||||
try
|
||||
{
|
||||
Body.SetTransform(centro, Body.Rotation);
|
||||
}
|
||||
catch { }
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,8 +65,8 @@ namespace CtrEditor.Simulacion
|
|||
private float _startAngle;
|
||||
private float _endAngle;
|
||||
public float Speed { get; set; } // Velocidad para efectos de cinta transportadora
|
||||
private List<Action> _deferredActions;
|
||||
|
||||
private List<Action> _deferredActions;
|
||||
public simCurve(World world, List<Action> deferredActions, float innerRadius, float outerRadius, float startAngle, float endAngle, Vector2 position)
|
||||
{
|
||||
_world = world;
|
||||
|
@ -74,7 +80,8 @@ namespace CtrEditor.Simulacion
|
|||
|
||||
public void Create(float innerRadius, float outerRadius, float startAngle, float endAngle, Vector2 position)
|
||||
{
|
||||
if (_world == null) return;
|
||||
if (_world == null)
|
||||
return;
|
||||
_innerRadius = innerRadius;
|
||||
_outerRadius = outerRadius;
|
||||
_startAngle = GradosARadianes(startAngle);
|
||||
|
@ -85,16 +92,16 @@ namespace CtrEditor.Simulacion
|
|||
public void Create(Vector2 position)
|
||||
{
|
||||
RemoverBody();
|
||||
|
||||
// Crear la geometría del sensor de curva
|
||||
List<Vertices> segments = CreateCurveVertices(_innerRadius, _outerRadius, _startAngle, _endAngle);
|
||||
// Crear triangulación de la curva
|
||||
List<Vertices> triangles = CreateTriangulatedCurve(_innerRadius, _outerRadius, _startAngle, _endAngle);
|
||||
Body = _world.CreateBody();
|
||||
foreach (var segment in segments)
|
||||
foreach (var triangle in triangles)
|
||||
{
|
||||
var shape = new PolygonShape(segment, 1f);
|
||||
var shape = new PolygonShape(triangle, 1f);
|
||||
var fixture = Body.CreateFixture(shape);
|
||||
fixture.IsSensor = true;
|
||||
}
|
||||
|
||||
Body.Position = position;
|
||||
Body.BodyType = BodyType.Static;
|
||||
Body.Tag = this;
|
||||
|
@ -110,10 +117,8 @@ namespace CtrEditor.Simulacion
|
|||
List<Vertices> verticesList = new List<Vertices>();
|
||||
int segments = 32;
|
||||
float angleStep = (endAngle - startAngle) / segments;
|
||||
|
||||
Vertices innerVertices = new Vertices();
|
||||
Vertices outerVertices = new Vertices();
|
||||
|
||||
for (int i = 0; i <= segments; i++)
|
||||
{
|
||||
float angle = startAngle + i * angleStep;
|
||||
|
@ -124,7 +129,6 @@ namespace CtrEditor.Simulacion
|
|||
outerVertices.Reverse();
|
||||
innerVertices.AddRange(outerVertices);
|
||||
verticesList.Add(innerVertices);
|
||||
|
||||
return verticesList;
|
||||
}
|
||||
|
||||
|
@ -132,36 +136,27 @@ namespace CtrEditor.Simulacion
|
|||
{
|
||||
// Get bottle position relative to curve center
|
||||
Vector2 centerToBottle = bottle.Body.Position - Body.Position;
|
||||
|
||||
// Calculate angle of bottle relative to curve center (in radians)
|
||||
float bottleAngle = (float)Math.Atan2(centerToBottle.Y, centerToBottle.X);
|
||||
|
||||
// Normalize angle to be positive
|
||||
if (bottleAngle < 0)
|
||||
bottleAngle += 2 * (float)Math.PI;
|
||||
|
||||
// If bottle is outside the angle range, return 0
|
||||
if (bottleAngle < _startAngle || bottleAngle > _endAngle)
|
||||
return 0;
|
||||
|
||||
// Calculate distance from center
|
||||
float distanceToCenter = centerToBottle.Length();
|
||||
|
||||
// If bottle is outside radius range, return 0
|
||||
if (distanceToCenter < _innerRadius || distanceToCenter > _outerRadius)
|
||||
return 0;
|
||||
|
||||
// Calculate how far the bottle is from the edges
|
||||
float angleFromStart = bottleAngle - _startAngle;
|
||||
float angleToEnd = _endAngle - bottleAngle;
|
||||
|
||||
// Use the minimum distance to either edge to calculate overlap
|
||||
float minAngleDistance = Math.Min(angleFromStart, angleToEnd);
|
||||
float totalAngle = _endAngle - _startAngle;
|
||||
|
||||
// Calculate overlap percentage based on angle proximity to edges
|
||||
float overlapPercentage = Math.Min(minAngleDistance / (totalAngle * 0.1f), 1.0f);
|
||||
|
||||
return overlapPercentage;
|
||||
}
|
||||
|
||||
|
@ -169,59 +164,91 @@ namespace CtrEditor.Simulacion
|
|||
{
|
||||
Vector2 centerToBottle = bottle.Body.Position - Body.Position;
|
||||
float distanceToCenter = centerToBottle.Length();
|
||||
|
||||
if (distanceToCenter >= _innerRadius && distanceToCenter <= _outerRadius)
|
||||
{
|
||||
// Calculate overlap percentage
|
||||
float overlapPercentage = CalculateAngleOverlap(bottle);
|
||||
|
||||
// Only apply effect if there's overlap
|
||||
if (overlapPercentage > 0)
|
||||
{
|
||||
// Calculate the tangential velocity
|
||||
float speedMetersPerSecond = Speed / 60.0f;
|
||||
|
||||
// Vector tangent (perpendicular to radius)
|
||||
Vector2 tangent = new Vector2(-centerToBottle.Y, centerToBottle.X);
|
||||
tangent.Normalize();
|
||||
|
||||
// Adjust tangent direction based on speed sign
|
||||
if (speedMetersPerSecond < 0)
|
||||
tangent = -tangent;
|
||||
|
||||
// Current velocity magnitude
|
||||
float currentSpeed = bottle.Body.LinearVelocity.Length();
|
||||
|
||||
// Desired conveyor speed
|
||||
float conveyorSpeed = Math.Abs(speedMetersPerSecond);
|
||||
|
||||
// Use the larger of the two speeds as base speed
|
||||
float targetSpeed = Math.Max(currentSpeed, conveyorSpeed);
|
||||
|
||||
// Lerp between current direction and curve direction
|
||||
Vector2 currentDir = bottle.Body.LinearVelocity;
|
||||
if (currentDir.LengthSquared() > 0)
|
||||
currentDir.Normalize();
|
||||
else
|
||||
currentDir = tangent;
|
||||
|
||||
// Interpolate between current direction and curve direction
|
||||
Vector2 newDirection = currentDir * (1 - overlapPercentage) + tangent * overlapPercentage;
|
||||
newDirection.Normalize();
|
||||
|
||||
// Apply new velocity with combined speed
|
||||
bottle.Body.LinearVelocity = newDirection * targetSpeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const float SegmentationFactor = 32f / 3f;
|
||||
private const int MinSegments = 8;
|
||||
private const int MaxSegments = 64;
|
||||
private List<Vertices> CreateTriangulatedCurve(float innerRadius, float outerRadius, float startAngle, float endAngle)
|
||||
{
|
||||
List<Vertices> triangles = new List<Vertices>();
|
||||
float arcLength = (endAngle - startAngle) * ((innerRadius + outerRadius) / 2f);
|
||||
// Calcular número de segmentos basado en el tamaño del arco
|
||||
int segments = (int)(arcLength * SegmentationFactor);
|
||||
// Aplicar límites para asegurar calidad y eficiencia
|
||||
segments = Math.Max(MinSegments, Math.Min(segments, MaxSegments));
|
||||
float angleStep = (endAngle - startAngle) / segments;
|
||||
// Generar vértices para los arcos interior y exterior
|
||||
Vector2[] innerPoints = new Vector2[segments + 1];
|
||||
Vector2[] outerPoints = new Vector2[segments + 1];
|
||||
for (int i = 0; i <= segments; i++)
|
||||
{
|
||||
float angle = startAngle + i * angleStep;
|
||||
float cosAngle = (float)Math.Cos(angle);
|
||||
float sinAngle = (float)Math.Sin(angle);
|
||||
innerPoints[i] = new Vector2(innerRadius * cosAngle, innerRadius * sinAngle);
|
||||
outerPoints[i] = new Vector2(outerRadius * cosAngle, outerRadius * sinAngle);
|
||||
}
|
||||
|
||||
// Crear triángulos
|
||||
for (int i = 0; i < segments; i++)
|
||||
{
|
||||
// Primer triángulo (superior) del sector
|
||||
Vertices upperTriangle = new Vertices(3);
|
||||
upperTriangle.Add(innerPoints[i]);
|
||||
upperTriangle.Add(outerPoints[i]);
|
||||
upperTriangle.Add(outerPoints[i + 1]);
|
||||
triangles.Add(upperTriangle);
|
||||
// Segundo triángulo (inferior) del sector
|
||||
Vertices lowerTriangle = new Vertices(3);
|
||||
lowerTriangle.Add(innerPoints[i]);
|
||||
lowerTriangle.Add(outerPoints[i + 1]);
|
||||
lowerTriangle.Add(innerPoints[i + 1]);
|
||||
triangles.Add(lowerTriangle);
|
||||
}
|
||||
|
||||
return triangles;
|
||||
}
|
||||
}
|
||||
|
||||
public class simDescarte : simBase
|
||||
{
|
||||
private float _radius;
|
||||
private List<Action> _deferredActions;
|
||||
|
||||
public simDescarte(World world, List<Action> deferredActions, float diameter, Vector2 position)
|
||||
{
|
||||
_world = world;
|
||||
|
@ -242,20 +269,19 @@ namespace CtrEditor.Simulacion
|
|||
{
|
||||
RemoverBody();
|
||||
Body = _world.CreateCircle(_radius, 1f, position);
|
||||
|
||||
Body.FixtureList[0].IsSensor = true;
|
||||
Body.BodyType = BodyType.Static;
|
||||
Body.Tag = this; // Importante para la identificación durante la colisión
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class simTransporte : simBase
|
||||
{
|
||||
public float Speed { get; set; } // Velocidad para efectos de cinta transportadora
|
||||
public float Friction { get; set; } // Friccion para efectos de cinta transportadora
|
||||
public float DistanceGuide2Guide { get; set; }
|
||||
public bool isBrake { get; set; }
|
||||
|
||||
public bool TransportWithGuides = false;
|
||||
private List<Action> _deferredActions;
|
||||
public float Width { get; set; }
|
||||
|
@ -270,8 +296,15 @@ namespace CtrEditor.Simulacion
|
|||
|
||||
public float Angle
|
||||
{
|
||||
get { return RadianesAGrados(Body.Rotation); }
|
||||
set { Body.Rotation = GradosARadianes(value); }
|
||||
get
|
||||
{
|
||||
return RadianesAGrados(Body.Rotation);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Body.Rotation = GradosARadianes(value);
|
||||
}
|
||||
}
|
||||
|
||||
public new void SetPosition(float x, float y)
|
||||
|
@ -287,12 +320,12 @@ namespace CtrEditor.Simulacion
|
|||
public void SetDimensions(float width, float height)
|
||||
{
|
||||
Body.Remove(Body.FixtureList[0]);
|
||||
|
||||
var newShape = new PolygonShape(PolygonTools.CreateRectangle(width / 2, height / 2), 1f);
|
||||
Body.CreateFixture(newShape);
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public void Create(float width, float height, Vector2 position, float angle = 0)
|
||||
{
|
||||
RemoverBody();
|
||||
|
@ -315,9 +348,7 @@ namespace CtrEditor.Simulacion
|
|||
public bool DetectNeck;
|
||||
public List<simBotella> ListSimBotellaContact;
|
||||
float _height;
|
||||
|
||||
private List<Action> _deferredActions;
|
||||
|
||||
public simBarrera(World world, List<Action> deferredActions, float width, float height, Vector2 position, float angle = 0, bool detectectNeck = false)
|
||||
{
|
||||
_world = world;
|
||||
|
@ -330,8 +361,15 @@ namespace CtrEditor.Simulacion
|
|||
|
||||
public float Angle
|
||||
{
|
||||
get { return RadianesAGrados(Body.Rotation); }
|
||||
set { Body.Rotation = GradosARadianes(value); }
|
||||
get
|
||||
{
|
||||
return RadianesAGrados(Body.Rotation);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Body.Rotation = GradosARadianes(value);
|
||||
}
|
||||
}
|
||||
|
||||
public new void SetPosition(float x, float y)
|
||||
|
@ -342,7 +380,6 @@ namespace CtrEditor.Simulacion
|
|||
public void SetDimensions(float width, float height)
|
||||
{
|
||||
Body.Remove(Body.FixtureList[0]);
|
||||
|
||||
var newShape = new PolygonShape(PolygonTools.CreateRectangle(Min(width) / 2, Min(height) / 2), 1f);
|
||||
Body.CreateFixture(newShape);
|
||||
}
|
||||
|
@ -362,26 +399,22 @@ namespace CtrEditor.Simulacion
|
|||
|
||||
public void CheckIfNecksIsTouching()
|
||||
{
|
||||
if (LuzCortada == 0) return;
|
||||
|
||||
if (LuzCortada == 0)
|
||||
return;
|
||||
foreach (var botella in ListSimBotellaContact)
|
||||
{
|
||||
// Obtener el centro de la barrera
|
||||
Vector2 sensorCenter = Body.Position;
|
||||
|
||||
// Calcular el vector de la línea horizontal centrada de la barrera
|
||||
float halfHeight = _height / 2;
|
||||
float cos = (float)Math.Cos(Body.Rotation);
|
||||
float sin = (float)Math.Sin(Body.Rotation);
|
||||
|
||||
// Calcular los puntos inicial y final de la línea horizontal centrada y rotada
|
||||
Vector2 lineStart = sensorCenter + new Vector2(-halfHeight * cos, halfHeight * sin);
|
||||
Vector2 lineEnd = sensorCenter + new Vector2(halfHeight * cos, -halfHeight * sin);
|
||||
|
||||
// Proyectar el centro de la botella sobre la línea horizontal
|
||||
Vector2 fixtureCenter = botella.Body.Position;
|
||||
Vector2 closestPoint = ProjectPointOntoLine(fixtureCenter, lineStart, lineEnd);
|
||||
|
||||
// Calcular la distancia entre el punto más cercano y el centro del cuello de la botella
|
||||
float distance;
|
||||
Vector2.Distance(ref closestPoint, ref fixtureCenter, out distance);
|
||||
|
@ -392,6 +425,7 @@ namespace CtrEditor.Simulacion
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LuzCortadaNeck = false;
|
||||
}
|
||||
|
||||
|
@ -399,16 +433,11 @@ namespace CtrEditor.Simulacion
|
|||
{
|
||||
Vector2 lineDirection = lineEnd - lineStart;
|
||||
lineDirection.Normalize();
|
||||
|
||||
Vector2 pointToLineStart = point - lineStart;
|
||||
float projectionLength;
|
||||
Vector2.Dot(ref pointToLineStart, ref lineDirection, out projectionLength);
|
||||
|
||||
return lineStart + projectionLength * lineDirection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class simGuia : simBase
|
||||
|
@ -440,7 +469,6 @@ namespace CtrEditor.Simulacion
|
|||
public float Radius;
|
||||
private float _mass;
|
||||
public bool Descartar = false;
|
||||
|
||||
public int isOnTransports;
|
||||
public List<simBase> ListOnTransports;
|
||||
public bool isRestricted;
|
||||
|
@ -448,14 +476,10 @@ namespace CtrEditor.Simulacion
|
|||
public float OriginalMass;
|
||||
public simTransporte ConveyorRestrictedTo;
|
||||
public Fixture axisRestrictedBy;
|
||||
|
||||
public float OverlapPercentage;
|
||||
|
||||
public float _neckRadius;
|
||||
|
||||
PrismaticJoint _activeJoint;
|
||||
private List<Action> _deferredActions;
|
||||
|
||||
public simBotella(World world, List<Action> deferredActions, float diameter, Vector2 position, float mass, float neckRadius = 0)
|
||||
{
|
||||
_world = world;
|
||||
|
@ -464,30 +488,42 @@ namespace CtrEditor.Simulacion
|
|||
Radius = diameter / 2;
|
||||
_mass = mass;
|
||||
_activeJoint = null;
|
||||
|
||||
if (neckRadius <= 0)
|
||||
neckRadius = diameter / 4;
|
||||
|
||||
_neckRadius = neckRadius;
|
||||
|
||||
Create(position);
|
||||
}
|
||||
|
||||
public float CenterX
|
||||
{
|
||||
get { return Body.Position.X; }
|
||||
set { }
|
||||
get
|
||||
{
|
||||
return Body.Position.X;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public float CenterY
|
||||
{
|
||||
get { return Body.Position.Y; }
|
||||
set { }
|
||||
get
|
||||
{
|
||||
return Body.Position.Y;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 Center
|
||||
{
|
||||
get { return Body.Position; }
|
||||
get
|
||||
{
|
||||
return Body.Position;
|
||||
}
|
||||
}
|
||||
|
||||
public float Mass
|
||||
|
@ -498,7 +534,11 @@ namespace CtrEditor.Simulacion
|
|||
_mass = 1;
|
||||
return _mass;
|
||||
}
|
||||
set { _mass = value; }
|
||||
|
||||
set
|
||||
{
|
||||
_mass = value;
|
||||
}
|
||||
}
|
||||
|
||||
private void Create(Vector2 position)
|
||||
|
@ -506,24 +546,18 @@ namespace CtrEditor.Simulacion
|
|||
RemoverBody();
|
||||
isOnTransports = 0;
|
||||
_activeJoint = null;
|
||||
|
||||
Body = _world.CreateCircle(Radius, 1f, position);
|
||||
Body.BodyType = BodyType.Dynamic;
|
||||
|
||||
// Restablecer manejador de eventos de colisión
|
||||
Body.OnCollision += HandleCollision;
|
||||
Body.OnSeparation += HandleOnSeparation;
|
||||
|
||||
Body.Tag = this; // Importante para la identificación durante la colisión
|
||||
|
||||
// Configurar la fricción
|
||||
Body.SetFriction(0.2f);
|
||||
|
||||
// Configurar amortiguamiento
|
||||
Body.LinearDamping = 3f; // Ajustar para controlar la reducción de la velocidad lineal
|
||||
Body.AngularDamping = 1f; // Ajustar para controlar la reducción de la velocidad angular
|
||||
Body.SetRestitution(0f); // Baja restitución para menos rebote
|
||||
|
||||
Body.SleepingAllowed = false;
|
||||
Body.IsBullet = true;
|
||||
}
|
||||
|
@ -561,10 +595,8 @@ namespace CtrEditor.Simulacion
|
|||
else if (fixtureB.Body.Tag is simTransporte)
|
||||
{
|
||||
simTransporte conveyor = fixtureB.Body.Tag as simTransporte;
|
||||
|
||||
isOnTransports += 1;
|
||||
ListOnTransports.Add(conveyor);
|
||||
|
||||
// Aplicar el efecto del transportador usando el porcentaje calculado
|
||||
if (conveyor.TransportWithGuides && conveyor.isBrake)
|
||||
{
|
||||
|
@ -574,8 +606,10 @@ namespace CtrEditor.Simulacion
|
|||
isRestricted = true;
|
||||
isNoMoreRestricted = false;
|
||||
}
|
||||
|
||||
return true; // No aplicar respuestas físicas
|
||||
}
|
||||
|
||||
return true; // No aplicar respuestas físicas
|
||||
}
|
||||
|
||||
|
@ -583,16 +617,13 @@ namespace CtrEditor.Simulacion
|
|||
{
|
||||
CircleShape circleShape = Body.FixtureList[0].Shape as CircleShape;
|
||||
PolygonShape polygonShape = conveyor.Body.FixtureList[0].Shape as PolygonShape;
|
||||
|
||||
// Obtener centro y radio del círculo
|
||||
Vector2 centroCirculo = Body.Position;
|
||||
float radio = circleShape.Radius;
|
||||
|
||||
// Obtener los vértices del polígono (rectángulo)
|
||||
Vector2[] vertices = new Vector2[polygonShape.Vertices.Count];
|
||||
float cos = (float)Math.Cos(conveyor.Body.Rotation);
|
||||
float sin = (float)Math.Sin(conveyor.Body.Rotation);
|
||||
|
||||
for (int i = 0; i < polygonShape.Vertices.Count; i++)
|
||||
{
|
||||
Vector2 vertex = polygonShape.Vertices[i];
|
||||
|
@ -613,23 +644,27 @@ namespace CtrEditor.Simulacion
|
|||
ListOnTransports.Remove(transport);
|
||||
isOnTransports -= 1;
|
||||
}
|
||||
|
||||
if (isOnTransports > 0 && fixtureB.Body.Tag is simCurve)
|
||||
{
|
||||
if (fixtureB.Body.Tag is simCurve transport)
|
||||
ListOnTransports.Remove(transport);
|
||||
isOnTransports -= 1;
|
||||
}
|
||||
|
||||
if (isRestricted && fixtureB == axisRestrictedBy)
|
||||
{
|
||||
isRestricted = false;
|
||||
isNoMoreRestricted = true;
|
||||
}
|
||||
|
||||
if (fixtureB.Body.Tag is simBarrera Sensor)
|
||||
{
|
||||
Sensor.LuzCortada -= 1;
|
||||
Sensor.ListSimBotellaContact.Remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aplica la fuerza de traccion a la botellas segun los
|
||||
/// transportes sobre los que se encuentra
|
||||
|
@ -653,37 +688,32 @@ namespace CtrEditor.Simulacion
|
|||
// Calcular el porcentaje de superficie sobrepuesta
|
||||
float overlapPercentage = CalculateOverlapedArea(this, conveyor); // CalculateOverlapPercentage(conveyor);
|
||||
OverlapPercentage = overlapPercentage;
|
||||
|
||||
// Calcular la velocidad deseada del transporte
|
||||
float speedMetersPerSecond = conveyor.Speed / 60.0f;
|
||||
Vector2 desiredVelocity = new Vector2((float)Math.Cos(conveyor.Body.Rotation), (float)Math.Sin(conveyor.Body.Rotation)) * speedMetersPerSecond;
|
||||
|
||||
// Obtener la velocidad actual de la botella
|
||||
Vector2 currentVelocity = Body.LinearVelocity;
|
||||
|
||||
// Calcular la diferencia de velocidad deseada
|
||||
Vector2 velocityDifference = desiredVelocity - currentVelocity;
|
||||
|
||||
// Calcular la fuerza de fricción necesaria - 0 : ya esta en velocidad - 1 : esta detenido
|
||||
float proporcionalVelocityNeeded = 1 - CalculateProportion(currentVelocity, desiredVelocity);
|
||||
float frictionCoefficient;
|
||||
|
||||
switch (proporcionalVelocityNeeded) {
|
||||
switch (proporcionalVelocityNeeded)
|
||||
{
|
||||
case > 0.3f:
|
||||
frictionCoefficient = conveyor.Friction * overlapPercentage;
|
||||
break;
|
||||
|
||||
default:
|
||||
frictionCoefficient = proporcionalVelocityNeeded * overlapPercentage;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (isRestricted && conveyor == ConveyorRestrictedTo && overlapPercentage > 0.5f)
|
||||
{
|
||||
Body.LinearVelocity = desiredVelocity;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Aplicar la fuerza de fricción en función del porcentaje de superficie sobrepuesta
|
||||
Body.LinearVelocity += frictionCoefficient * desiredVelocity;
|
||||
//Body.ApplyForce(frictionForce * overlapPercentage);
|
||||
|
@ -705,7 +735,6 @@ namespace CtrEditor.Simulacion
|
|||
float dotProduct;
|
||||
Vector2.Dot(ref desiredVelocity, ref currentVelocity, out dotProduct);
|
||||
float magnitudeV1Squared = desiredVelocity.LengthSquared();
|
||||
|
||||
// Si la magnitud de v1 es 0, la proporción no está definida
|
||||
if (magnitudeV1Squared == 0)
|
||||
{
|
||||
|
@ -721,25 +750,19 @@ namespace CtrEditor.Simulacion
|
|||
{
|
||||
if (!isRestricted || ConveyorRestrictedTo == null)
|
||||
return;
|
||||
|
||||
// Obtener el centro del conveyor
|
||||
Vector2 conveyorCenter = ConveyorRestrictedTo.Body.Position;
|
||||
|
||||
// Calcular el vector de la línea horizontal centrada de conveyor
|
||||
float halfDistance = ConveyorRestrictedTo.DistanceGuide2Guide / 2;
|
||||
float cos = (float)Math.Cos(ConveyorRestrictedTo.Body.Rotation);
|
||||
float sin = (float)Math.Sin(ConveyorRestrictedTo.Body.Rotation);
|
||||
|
||||
Vector2 offset = new Vector2(halfDistance * cos, halfDistance * sin);
|
||||
|
||||
// Línea horizontal centrada de conveyor en el espacio del mundo
|
||||
Vector2 lineStart = conveyorCenter - offset;
|
||||
Vector2 lineEnd = conveyorCenter + offset;
|
||||
|
||||
// Proyectar el centro de fixtureA sobre la línea horizontal
|
||||
Vector2 fixtureCenter = Body.Position;
|
||||
Vector2 closestPoint = ProjectPointOntoLine(fixtureCenter, lineStart, lineEnd);
|
||||
|
||||
// Mover fixtureA al punto más cercano en la línea horizontal
|
||||
Body.Position = closestPoint;
|
||||
}
|
||||
|
@ -748,10 +771,8 @@ namespace CtrEditor.Simulacion
|
|||
{
|
||||
Vector2 lineDirection = lineEnd - lineStart;
|
||||
lineDirection.Normalize();
|
||||
|
||||
Vector2 pointToLineStart = point - lineStart;
|
||||
Vector2.Dot(ref pointToLineStart, ref lineDirection, out float projectionLength);
|
||||
|
||||
return lineStart + projectionLength * lineDirection;
|
||||
}
|
||||
|
||||
|
@ -768,20 +789,16 @@ namespace CtrEditor.Simulacion
|
|||
public List<simBase> Cuerpos;
|
||||
public List<Action> _deferredActions;
|
||||
SolverIterations Iterations;
|
||||
|
||||
private Stopwatch stopwatch;
|
||||
private double stopwatch_last;
|
||||
|
||||
public Canvas DebugCanvas { get => simulationCanvas; set => simulationCanvas = value; }
|
||||
|
||||
public SimulationManagerFP()
|
||||
{
|
||||
world = new World(new Vector2(0, 0)); // Vector2.Zero
|
||||
|
||||
SolverIterations Iterations = new SolverIterations();
|
||||
Iterations.PositionIterations = 1;
|
||||
Iterations.VelocityIterations = 1;
|
||||
|
||||
Cuerpos = new List<simBase>();
|
||||
_deferredActions = new List<Action>();
|
||||
stopwatch = new Stopwatch();
|
||||
|
@ -795,9 +812,9 @@ namespace CtrEditor.Simulacion
|
|||
if (Cuerpos.Count > 0)
|
||||
Cuerpos.Clear();
|
||||
}
|
||||
// ******************************************************************************************************************************************
|
||||
// ******************************************************************************************************************************************
|
||||
|
||||
// ******************************************************************************************************************************************
|
||||
// ******************************************************************************************************************************************
|
||||
public void Start()
|
||||
{
|
||||
stopwatch.Start();
|
||||
|
@ -809,16 +826,13 @@ namespace CtrEditor.Simulacion
|
|||
// Detener el cronómetro y obtener el tiempo transcurrido en milisegundos
|
||||
float elapsedMilliseconds = (float)(stopwatch.Elapsed.TotalMilliseconds - stopwatch_last);
|
||||
stopwatch_last = stopwatch.Elapsed.TotalMilliseconds;
|
||||
|
||||
// Pasar el tiempo transcurrido al método Step
|
||||
world.Step(elapsedMilliseconds / 1000.0f);
|
||||
|
||||
foreach (var cuerpo in Cuerpos)
|
||||
{
|
||||
if (cuerpo is simBotella botella)
|
||||
{
|
||||
botella.ApplyConveyorSpeed(elapsedMilliseconds / 1000);
|
||||
|
||||
if (botella.isRestricted)
|
||||
{
|
||||
botella.CenterFixtureOnConveyor();
|
||||
|
@ -840,6 +854,7 @@ namespace CtrEditor.Simulacion
|
|||
{
|
||||
action();
|
||||
}
|
||||
|
||||
_deferredActions.Clear();
|
||||
}
|
||||
|
||||
|
@ -933,6 +948,7 @@ namespace CtrEditor.Simulacion
|
|||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
shape.Tag = "Simulation"; // Marcar para simulación
|
||||
Canvas.SetZIndex(shape, 20);
|
||||
simulationCanvas.Children.Add(shape);
|
||||
|
@ -976,17 +992,18 @@ namespace CtrEditor.Simulacion
|
|||
|
||||
private System.Windows.Shapes.Shape DrawPolygon(Fixture fixture)
|
||||
{
|
||||
Polygon polygon = new Polygon { Stroke = Brushes.Black, StrokeThickness = 2 };
|
||||
Polygon polygon = new Polygon
|
||||
{
|
||||
Stroke = Brushes.Black,
|
||||
StrokeThickness = 2
|
||||
};
|
||||
PolygonShape polyShape = fixture.Shape as PolygonShape;
|
||||
|
||||
float cos = (float)Math.Cos(fixture.Body.Rotation);
|
||||
float sin = (float)Math.Sin(fixture.Body.Rotation);
|
||||
|
||||
foreach (Vector2 vertex in polyShape.Vertices)
|
||||
{
|
||||
float rotatedX = vertex.X * cos - vertex.Y * sin + fixture.Body.Position.X;
|
||||
float rotatedY = vertex.X * sin + vertex.Y * cos + fixture.Body.Position.Y;
|
||||
|
||||
polygon.Points.Add(new Point(p(rotatedX), p(rotatedY)));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<Window x:Class="CtrEditor.Windows.MultiPropertyEditorWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="clr-namespace:CtrEditor.Controls"
|
||||
Title="Multiple Object Editor"
|
||||
Height="600"
|
||||
Width="800"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
<DockPanel>
|
||||
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right" Margin="10">
|
||||
<Button Content="OK" Width="75" Margin="5" Click="OKButton_Click"/>
|
||||
<Button Content="Cancel" Width="75" Margin="5" Click="CancelButton_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Auto">
|
||||
<Grid x:Name="MainGrid">
|
||||
<Grid.ColumnDefinitions>
|
||||
<!-- Columns will be added dynamically -->
|
||||
</Grid.ColumnDefinitions>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</DockPanel>
|
||||
</Window>
|
|
@ -0,0 +1,98 @@
|
|||
using CtrEditor.Controls;
|
||||
using CtrEditor.ObjetosSim;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CtrEditor.Windows
|
||||
{
|
||||
public partial class MultiPropertyEditorWindow : Window
|
||||
{
|
||||
private List<osBase> _objects;
|
||||
|
||||
public MultiPropertyEditorWindow(List<osBase> objects, Window owner)
|
||||
{
|
||||
InitializeComponent();
|
||||
_objects = objects;
|
||||
this.Owner = owner;
|
||||
InitializeGrid();
|
||||
}
|
||||
|
||||
public void UpdateSelectedObjects(List<osBase> newObjects)
|
||||
{
|
||||
_objects = newObjects;
|
||||
MainGrid.Children.Clear();
|
||||
MainGrid.ColumnDefinitions.Clear();
|
||||
InitializeGrid();
|
||||
}
|
||||
|
||||
private void InitializeGrid()
|
||||
{
|
||||
// Clear existing column definitions
|
||||
MainGrid.ColumnDefinitions.Clear();
|
||||
|
||||
// Add column definitions for each object
|
||||
for (int i = 0; i < _objects.Count; i++)
|
||||
{
|
||||
MainGrid.ColumnDefinitions.Add(new ColumnDefinition
|
||||
{
|
||||
Width = new GridLength(1, GridUnitType.Star)
|
||||
});
|
||||
|
||||
// Create a container for each object's editor
|
||||
var container = new DockPanel();
|
||||
|
||||
// Add header with object name
|
||||
var header = new TextBlock
|
||||
{
|
||||
Text = _objects[i].Nombre,
|
||||
FontWeight = FontWeights.Bold,
|
||||
Margin = new Thickness(5),
|
||||
TextAlignment = TextAlignment.Center
|
||||
};
|
||||
DockPanel.SetDock(header, Dock.Top);
|
||||
container.Children.Add(header);
|
||||
|
||||
// Add property grid
|
||||
var propertyGrid = new PanelEdicionControl();
|
||||
propertyGrid.CargarPropiedades(_objects[i]);
|
||||
container.Children.Add(propertyGrid);
|
||||
|
||||
// Add separator line except for the last column
|
||||
if (i < _objects.Count - 1)
|
||||
{
|
||||
var separator = new GridSplitter
|
||||
{
|
||||
Width = 5,
|
||||
HorizontalAlignment = HorizontalAlignment.Right,
|
||||
VerticalAlignment = VerticalAlignment.Stretch,
|
||||
Background = SystemColors.ControlLightBrush
|
||||
};
|
||||
Grid.SetColumn(separator, i);
|
||||
MainGrid.Children.Add(separator);
|
||||
}
|
||||
|
||||
// Add the container to the grid
|
||||
Grid.SetColumn(container, i);
|
||||
MainGrid.Children.Add(container);
|
||||
}
|
||||
}
|
||||
|
||||
private void OKButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
// Eliminar el comportamiento anterior que cancelaba el cierre
|
||||
// y permitir que la ventana se cierre normalmente
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue