Intento con LinearAxisMotor
This commit is contained in:
parent
3e53a51e8b
commit
fd215bc677
|
@ -61,6 +61,25 @@ namespace CtrEditor.ObjetosSim
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Estructura para almacenar las dimensiones de los objetos de simulación
|
||||||
|
/// </summary>
|
||||||
|
public struct SimObjectDimensions
|
||||||
|
{
|
||||||
|
public float Width { get; set; }
|
||||||
|
public float Height { get; set; }
|
||||||
|
public float Radius { get; set; }
|
||||||
|
public int ObjectType { get; set; } // Tipo de objeto: 1=Transport, 2=Barrier, 3=Guide, etc.
|
||||||
|
|
||||||
|
public bool Equals(SimObjectDimensions other)
|
||||||
|
{
|
||||||
|
return Math.Abs(Width - other.Width) < 0.001f &&
|
||||||
|
Math.Abs(Height - other.Height) < 0.001f &&
|
||||||
|
Math.Abs(Radius - other.Radius) < 0.001f &&
|
||||||
|
ObjectType == other.ObjectType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public abstract partial class osBase : ObservableObject
|
public abstract partial class osBase : ObservableObject
|
||||||
{
|
{
|
||||||
public virtual string Nombre { get; set; } = "osBase";
|
public virtual string Nombre { get; set; } = "osBase";
|
||||||
|
@ -70,6 +89,10 @@ namespace CtrEditor.ObjetosSim
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
private System.Threading.Timer timer = null;
|
private System.Threading.Timer timer = null;
|
||||||
|
|
||||||
|
// ✅ SISTEMA DE DIMENSIONES: Para evitar recreación innecesaria de objetos físicos
|
||||||
|
[JsonIgnore]
|
||||||
|
private static Dictionary<simBase, SimObjectDimensions> _lastKnownDimensions = new Dictionary<simBase, SimObjectDimensions>();
|
||||||
|
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
[property: JsonIgnore]
|
[property: JsonIgnore]
|
||||||
|
@ -1531,8 +1554,24 @@ namespace CtrEditor.ObjetosSim
|
||||||
if (simRect != null)
|
if (simRect != null)
|
||||||
{
|
{
|
||||||
var topLeft2D = GetRectangleTopLeft(wpfRect);
|
var topLeft2D = GetRectangleTopLeft(wpfRect);
|
||||||
// simRect.Create maneja internamente la conversión a 3D con pivot correcto
|
|
||||||
|
// ✅ SISTEMA INTELIGENTE: Solo recrear si las dimensiones han cambiado
|
||||||
|
bool dimensionsChanged = HasTransportDimensionsChanged(simRect, Ancho, Alto);
|
||||||
|
|
||||||
|
if (dimensionsChanged)
|
||||||
|
{
|
||||||
|
// Las dimensiones cambiaron, recrear el objeto físico
|
||||||
simRect.Create(Ancho, Alto, topLeft2D, Angulo);
|
simRect.Create(Ancho, Alto, topLeft2D, Angulo);
|
||||||
|
simRect.SetDimensions(Ancho, Alto); // Actualizar dimensiones internas
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// ✅ CORREGIDO: Usar UpdateFromWpfParameters para manejar correctamente Top-Left + Ángulo
|
||||||
|
simRect.UpdateFromWpfParameters(topLeft2D, Angulo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualizar propiedades cacheadas
|
||||||
|
simRect.UpdateCachedProperties();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1541,8 +1580,21 @@ namespace CtrEditor.ObjetosSim
|
||||||
if (simRect != null)
|
if (simRect != null)
|
||||||
{
|
{
|
||||||
var topLeft2D = GetRectangleTopLeft(wpfRect);
|
var topLeft2D = GetRectangleTopLeft(wpfRect);
|
||||||
// simRect.Create maneja internamente la conversión a 3D con pivot correcto
|
|
||||||
|
// ✅ SISTEMA INTELIGENTE: Solo recrear si las dimensiones han cambiado
|
||||||
|
bool dimensionsChanged = HasBarrierDimensionsChanged(simRect, Ancho, Alto);
|
||||||
|
|
||||||
|
if (dimensionsChanged)
|
||||||
|
{
|
||||||
|
// Las dimensiones cambiaron, recrear el objeto físico
|
||||||
simRect.Create(Ancho, Alto, topLeft2D, Angulo);
|
simRect.Create(Ancho, Alto, topLeft2D, Angulo);
|
||||||
|
simRect.SetDimensions(Ancho, Alto); // Actualizar dimensiones internas
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// ✅ CORREGIDO: Usar UpdateFromWpfParameters para manejar correctamente Top-Left + Ángulo
|
||||||
|
simRect.UpdateFromWpfParameters(topLeft2D, Angulo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1585,9 +1637,23 @@ namespace CtrEditor.ObjetosSim
|
||||||
// Actualizar las propiedades desde el objeto osGuia
|
// Actualizar las propiedades desde el objeto osGuia
|
||||||
if (this is osGuia guiaObj)
|
if (this is osGuia guiaObj)
|
||||||
{
|
{
|
||||||
simGuia.UpdateProperties(guiaObj.Ancho, guiaObj.AltoGuia, guiaObj.Angulo);
|
// ✅ SISTEMA INTELIGENTE: Solo recrear si las dimensiones han cambiado
|
||||||
// Crear usando Top-Left + dimensiones + ángulo
|
bool dimensionsChanged = HasGuideDimensionsChanged(simGuia, guiaObj.Ancho, guiaObj.AltoGuia);
|
||||||
|
|
||||||
|
if (dimensionsChanged)
|
||||||
|
{
|
||||||
|
// Las dimensiones cambiaron, recrear el objeto físico
|
||||||
simGuia.Create(guiaObj.Ancho, guiaObj.AltoGuia, topLeft2D, guiaObj.Angulo);
|
simGuia.Create(guiaObj.Ancho, guiaObj.AltoGuia, topLeft2D, guiaObj.Angulo);
|
||||||
|
simGuia.SetDimensions(guiaObj.Ancho, guiaObj.AltoGuia); // Actualizar dimensiones internas
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Solo actualizar posición y rotación
|
||||||
|
simGuia.SetPosition(topLeft2D, guiaObj.Angulo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualizar propiedades internas
|
||||||
|
simGuia.UpdateProperties(guiaObj.Ancho, guiaObj.AltoGuia, guiaObj.Angulo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1676,6 +1742,128 @@ namespace CtrEditor.ObjetosSim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ✅ MÉTODOS PARA GESTIÓN INTELIGENTE DE DIMENSIONES
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifica si las dimensiones de un transporte han cambiado
|
||||||
|
/// </summary>
|
||||||
|
private bool HasTransportDimensionsChanged(simTransporte transport, float newWidth, float newHeight)
|
||||||
|
{
|
||||||
|
if (transport == null) return true;
|
||||||
|
|
||||||
|
var newDimensions = new SimObjectDimensions
|
||||||
|
{
|
||||||
|
Width = newWidth,
|
||||||
|
Height = newHeight,
|
||||||
|
ObjectType = 1 // Transport
|
||||||
|
};
|
||||||
|
|
||||||
|
if (_lastKnownDimensions.TryGetValue(transport, out var lastDimensions))
|
||||||
|
{
|
||||||
|
bool changed = !newDimensions.Equals(lastDimensions);
|
||||||
|
if (changed)
|
||||||
|
{
|
||||||
|
_lastKnownDimensions[transport] = newDimensions;
|
||||||
|
System.Diagnostics.Debug.WriteLine($"[Dimensions] Transport dimensions CHANGED: {newWidth}x{newHeight}");
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Primera vez - consideramos como cambio
|
||||||
|
_lastKnownDimensions[transport] = newDimensions;
|
||||||
|
System.Diagnostics.Debug.WriteLine($"[Dimensions] Transport first time: {newWidth}x{newHeight}");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifica si las dimensiones de una barrera han cambiado
|
||||||
|
/// </summary>
|
||||||
|
private bool HasBarrierDimensionsChanged(simBarrera barrier, float newWidth, float newHeight)
|
||||||
|
{
|
||||||
|
if (barrier == null) return true;
|
||||||
|
|
||||||
|
var newDimensions = new SimObjectDimensions
|
||||||
|
{
|
||||||
|
Width = newWidth,
|
||||||
|
Height = newHeight,
|
||||||
|
ObjectType = 2 // Barrier
|
||||||
|
};
|
||||||
|
|
||||||
|
if (_lastKnownDimensions.TryGetValue(barrier, out var lastDimensions))
|
||||||
|
{
|
||||||
|
bool changed = !newDimensions.Equals(lastDimensions);
|
||||||
|
if (changed)
|
||||||
|
{
|
||||||
|
_lastKnownDimensions[barrier] = newDimensions;
|
||||||
|
System.Diagnostics.Debug.WriteLine($"[Dimensions] Barrier dimensions CHANGED: {newWidth}x{newHeight}");
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Primera vez - consideramos como cambio
|
||||||
|
_lastKnownDimensions[barrier] = newDimensions;
|
||||||
|
System.Diagnostics.Debug.WriteLine($"[Dimensions] Barrier first time: {newWidth}x{newHeight}");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifica si las dimensiones de una guía han cambiado
|
||||||
|
/// </summary>
|
||||||
|
private bool HasGuideDimensionsChanged(simGuia guide, float newWidth, float newHeight)
|
||||||
|
{
|
||||||
|
if (guide == null) return true;
|
||||||
|
|
||||||
|
var newDimensions = new SimObjectDimensions
|
||||||
|
{
|
||||||
|
Width = newWidth,
|
||||||
|
Height = newHeight,
|
||||||
|
ObjectType = 3 // Guide
|
||||||
|
};
|
||||||
|
|
||||||
|
if (_lastKnownDimensions.TryGetValue(guide, out var lastDimensions))
|
||||||
|
{
|
||||||
|
bool changed = !newDimensions.Equals(lastDimensions);
|
||||||
|
if (changed)
|
||||||
|
{
|
||||||
|
_lastKnownDimensions[guide] = newDimensions;
|
||||||
|
System.Diagnostics.Debug.WriteLine($"[Dimensions] Guide dimensions CHANGED: {newWidth}x{newHeight}");
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Primera vez - consideramos como cambio
|
||||||
|
_lastKnownDimensions[guide] = newDimensions;
|
||||||
|
System.Diagnostics.Debug.WriteLine($"[Dimensions] Guide first time: {newWidth}x{newHeight}");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Limpia las dimensiones almacenadas para un objeto específico
|
||||||
|
/// </summary>
|
||||||
|
public static void ClearStoredDimensions(simBase simObj)
|
||||||
|
{
|
||||||
|
if (simObj != null && _lastKnownDimensions.ContainsKey(simObj))
|
||||||
|
{
|
||||||
|
_lastKnownDimensions.Remove(simObj);
|
||||||
|
System.Diagnostics.Debug.WriteLine($"[Dimensions] Cleared stored dimensions for {simObj.GetType().Name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Limpia todas las dimensiones almacenadas (útil al cerrar simulación)
|
||||||
|
/// </summary>
|
||||||
|
public static void ClearAllStoredDimensions()
|
||||||
|
{
|
||||||
|
_lastKnownDimensions.Clear();
|
||||||
|
System.Diagnostics.Debug.WriteLine($"[Dimensions] Cleared ALL stored dimensions");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public class UniqueId
|
public class UniqueId
|
||||||
{
|
{
|
||||||
|
|
1918
Simulacion/BEPU.cs
1918
Simulacion/BEPU.cs
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue