Compare commits

..

No commits in common. "6155f8475ebefcdfcbef7d05365606e6130ade22" and "2e8c3b7d8314ce3c34dbda44e8f0b4118bbd60bb" have entirely different histories.

28 changed files with 115 additions and 125 deletions

View File

@ -11,8 +11,6 @@
<ItemGroup>
<Compile Remove="ObjetosSim\ucBasicExample.xaml.cs" />
<Compile Remove="ObjetosSim\ucTransporteCurva.xaml.cs" />
<Compile Remove="ObjetosSim\UserControls\ucBasicExample.xaml.cs" />
<Compile Remove="ObjetosSim\UserControls\ucTransporteCurva.xaml.cs" />
<Compile Remove="Simulacion\GeometrySimulator.cs" />
</ItemGroup>
@ -32,15 +30,13 @@
<ItemGroup>
<Page Remove="ObjetosSim\ucBasicExample.xaml" />
<Page Remove="ObjetosSim\ucTransporteCurva.xaml" />
<Page Remove="ObjetosSim\UserControls\ucBasicExample.xaml" />
<Page Remove="ObjetosSim\UserControls\ucTransporteCurva.xaml" />
</ItemGroup>
<ItemGroup>
<None Include="ObjetosSim\UserControls\ucBasicExample.xaml" />
<None Include="ObjetosSim\UserControls\ucBasicExample.xaml.cs" />
<None Include="ObjetosSim\UserControls\ucTransporteCurva.xaml" />
<None Include="ObjetosSim\UserControls\ucTransporteCurva.xaml.cs" />
<None Include="ObjetosSim\ucBasicExample.xaml" />
<None Include="ObjetosSim\ucBasicExample.xaml.cs" />
<None Include="ObjetosSim\ucTransporteCurva.xaml" />
<None Include="ObjetosSim\ucTransporteCurva.xaml.cs" />
<None Include="Simulacion\GeometrySimulator.cs" />
</ItemGroup>

View File

@ -10,6 +10,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CtrEditor.ObjetosSim;
using CtrEditor.Convertidores;
using CtrEditor.Siemens;
using static System.Runtime.InteropServices.JavaScript.JSType;
@ -21,7 +22,6 @@ using UserControl = System.Windows.Controls.UserControl;
using CheckBox = System.Windows.Controls.CheckBox;
using Orientation = System.Windows.Controls.Orientation;
using ListBox = System.Windows.Controls.ListBox;
using CtrEditor.ObjetosSim;
namespace CtrEditor

View File

@ -27,7 +27,7 @@ namespace CtrEditor.ObjetosSim
public interface IosBase
{
string Nombre { get; }
string Nombre { get; }
void UpdateControl(int elapsedMilliseconds);
}
@ -44,7 +44,7 @@ namespace CtrEditor.ObjetosSim
}
public abstract class osBase : INotifyPropertyChanged, IosBase
{
{
public abstract float Left { get; set; }
public abstract float Top { get; set; }
@ -83,9 +83,9 @@ namespace CtrEditor.ObjetosSim
{
foreach (var objetoSimulable in _mainViewModel.ObjetosSimulables)
{
if (tipoOsBase.IsInstanceOfType(objetoSimulable) && objetoSimulable.Nombre == NameLink)
if (tipoOsBase.IsInstanceOfType(objetoSimulable) && ((osBase)objetoSimulable).Nombre == NameLink)
{
return objetoSimulable;
return (osBase)objetoSimulable;
}
}
}
@ -102,8 +102,8 @@ namespace CtrEditor.ObjetosSim
{
if (!string.IsNullOrEmpty(Tag))
{
if (Tag == "1") return true;
else if (Tag == "0") return false;
if (Tag=="1") return true;
else if (Tag=="0") return false;
if (plc != null)
return plc.LeerTagBool(Tag);
}
@ -123,7 +123,7 @@ namespace CtrEditor.ObjetosSim
if (!string.IsNullOrEmpty(Tag))
{
SDataValue plcData = new SDataValue();
plcData.UInt16 = (ushort)((Value - IN_scale_Min) / (IN_scale_Max - IN_scale_Min) * (OUT_scale_Max - OUT_scale_Min) + OUT_scale_Min);
plcData.UInt16 = (ushort)(((Value - IN_scale_Min) / (IN_scale_Max - IN_scale_Min) * (OUT_scale_Max - OUT_scale_Min)) + OUT_scale_Min);
plc.EscribirTag(Tag, plcData);
}
}
@ -138,7 +138,7 @@ namespace CtrEditor.ObjetosSim
{
SDataValue plcData = plc.LeerTag(Tag);
float Value = plcData.UInt16; // WORD
return (Value - OUT_scale_Min) / (OUT_scale_Max - OUT_scale_Min) * (IN_scale_Max - IN_scale_Min) + IN_scale_Min;
return (((Value - OUT_scale_Min) / (OUT_scale_Max - OUT_scale_Min) * (IN_scale_Max - IN_scale_Min)) + IN_scale_Min);
}
}
return 0;
@ -147,7 +147,7 @@ namespace CtrEditor.ObjetosSim
public void CanvasSetLeftinMeter(float left)
{
if (_visualRepresentation != null)
Canvas.SetLeft(_visualRepresentation, PixelToMeter.Instance.calc.MetersToPixels(left));
Canvas.SetLeft(_visualRepresentation, PixelToMeter.Instance.calc.MetersToPixels(left));
}
public float CanvasGetLeftinMeter()
{
@ -243,7 +243,7 @@ namespace CtrEditor.ObjetosSim
var coords = GetCenterLineVectors(wpfRect);
// Crear o actualizar simRectangle
simGuia.Create(coords.Start, coords.End); // asumiendo que el ángulo inicial es 0
simGuia.Create( coords.Start,coords.End); // asumiendo que el ángulo inicial es 0
}
}

View File

@ -24,7 +24,7 @@ namespace CtrEditor.ObjetosSim
/// Interaction logic for ucBotella.xaml
/// </summary>
///
public class osBotella : osBase
{
private float _diametro;

View File

@ -15,8 +15,7 @@ using System.Windows.Shapes;
using CtrEditor.Convertidores;
using CtrEditor.Siemens;
namespace CtrEditor.ObjetosSim.UserControls
namespace CtrEditor.ObjetosSim
{
/// <summary>
/// Interaction logic for ucTransporteCurva.xaml

View File

@ -213,9 +213,9 @@ namespace CtrEditor.ObjetosSim
// crear el objeto de simulacion
ActualizarLeftTop();
//simulationManager.rectangles.Add(TransporteCentral);
//simulationManager.lines.Add(Guia_Superior);
//simulationManager.lines.Add(Guia_Inferior);
simulationManager.rectangles.Add(TransporteCentral);
simulationManager.lines.Add(Guia_Superior);
simulationManager.lines.Add(Guia_Inferior);
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion

View File

@ -11,7 +11,7 @@ namespace CtrEditor.ObjetosSim
/// Interaction logic for ucTransporteTTop.xaml
/// </summary>
///
public class osTransporteTTop : osBase
{
private string _nombre = "Transporte TTOP";

View File

@ -18,28 +18,12 @@ using static System.Runtime.InteropServices.JavaScript.JSType;
namespace CtrEditor.Simulacion
{
public class simBase
{
public Body Body { get; protected set; }
public World _world;
public void RemoverBody()
{
if (Body != null)
{
_world.RemoveBody(Body);
}
}
public void SetPosition(float x, float y)
{
Body.SetTransform(new Vector2(x, y), Body.Rotation);
}
}
public class simDescarte : simBase
public class simDescarte
{
public Body Body { get; private set; }
private float _radius;
public World _world;
public simDescarte(World world, float diameter, Vector2 position)
{
@ -48,12 +32,23 @@ namespace CtrEditor.Simulacion
Create(position);
}
public void SetPosition(float x, float y)
{
Body.SetTransform(new Vector2(x, y), Body.Rotation);
}
public void SetDiameter(float diameter)
{
_radius = diameter / 2;
Create(Body.Position); // Recrear el círculo con el nuevo tamaño
}
public void RemoverBody()
{
if (Body != null)
{
_world.RemoveBody(Body);
}
}
public void Create(Vector2 position)
{
RemoverBody();
@ -65,10 +60,11 @@ namespace CtrEditor.Simulacion
}
}
public class simTransporte : simBase
public class simTransporte
{
public Body Body { get; private set; }
public float Speed { get; set; } // Velocidad para efectos de cinta transportadora
public World _world;
public simTransporte(World world, float width, float height, Vector2 position, float angle = 0)
{
@ -82,7 +78,7 @@ namespace CtrEditor.Simulacion
set { Body.Rotation = MathHelper.ToRadians(value); }
}
public new void SetPosition(float x, float y)
public void SetPosition(float x, float y)
{
Body.Position = new Vector2(x, y);
}
@ -99,6 +95,13 @@ namespace CtrEditor.Simulacion
var newShape = new PolygonShape(PolygonTools.CreateRectangle(width / 2, height / 2), 1f);
Body.CreateFixture(newShape);
}
public void RemoverBody()
{
if (Body != null)
{
_world.RemoveBody(Body);
}
}
public void Create(float width, float height, Vector2 position, float angle = 0)
{
RemoverBody();
@ -110,55 +113,23 @@ namespace CtrEditor.Simulacion
}
}
public class simBarrera : simBase
public class simGuia
{
public bool LuzCortada = false;
public Body Body { get; private set; }
public World _world;
public simBarrera(World world, float width, float height, Vector2 position, float angle = 0)
{
_world = world;
Create(width, height, position, angle);
}
public float Angle
{
get { return MathHelper.ToDegrees(Body.Rotation); }
set { Body.Rotation = MathHelper.ToRadians(value); }
}
public new void SetPosition(float x, float y)
{
Body.Position = new Vector2(x, y);
}
public void SetDimensions(float width, float height)
{
Body.DestroyFixture(Body.FixtureList[0]);
var newShape = new PolygonShape(PolygonTools.CreateRectangle(width / 2, height / 2), 1f);
Body.CreateFixture(newShape);
}
public void Create(float width, float height, Vector2 position, float angle = 0)
{
RemoverBody();
Body = BodyFactory.CreateRectangle(_world, width, height, 1f, position);
Body.FixtureList[0].IsSensor = true;
Body.BodyType = BodyType.Static;
Body.Rotation = MathHelper.ToRadians(angle);
Body.UserData = this; // Importante para la identificación durante la colisión
LuzCortada = false;
}
}
public class simGuia : simBase
{
public simGuia(World world, Vector2 start, Vector2 end)
{
_world = world;
Create(start, end);
}
public void RemoverBody()
{
if (Body != null)
{
_world.RemoveBody(Body);
}
}
public void Create(Vector2 start, Vector2 end)
{
RemoverBody();
@ -173,8 +144,10 @@ namespace CtrEditor.Simulacion
}
}
public class simBotella : simBase
public class simBotella
{
public Body Body { get; private set; }
public World _world;
private float _radius;
private float _mass;
public bool Descartar = false;
@ -214,7 +187,13 @@ namespace CtrEditor.Simulacion
}
set { _mass = value; }
}
public void RemoverBody()
{
if (Body != null)
{
_world.RemoveBody(Body);
}
}
private void Create(Vector2 position)
{
RemoverBody();
@ -223,7 +202,7 @@ namespace CtrEditor.Simulacion
// Restablecer manejador de eventos de colisión
Body.OnCollision += HandleCollision;
Body.OnSeparation += HandleOnSeparation;
//Body.OnSeparation += HandleOnSeparation;
Body.UserData = this; // Importante para la identificación durante la colisión
@ -234,7 +213,12 @@ namespace CtrEditor.Simulacion
Body.LinearDamping = 0f; // Ajustar para controlar la reducción de la velocidad lineal
Body.AngularDamping = 0f; // Ajustar para controlar la reducción de la velocidad angular
Body.Restitution = 0.2f; // Baja restitución para menos rebote
// Body.IsBullet = true;
Body.IsBullet = true;
}
public void SetPosition(float x, float y)
{
Body.SetTransform(new Vector2(x, y), Body.Rotation);
}
public void SetDiameter(float diameter)
@ -250,12 +234,7 @@ namespace CtrEditor.Simulacion
private bool HandleCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
{
if (fixtureB.Body.UserData is simBarrera Sensor)
{
Sensor.LuzCortada = true;
return true;
}
else if (fixtureB.Body.UserData is simDescarte)
if (fixtureB.Body.UserData is simDescarte)
{
Descartar = true;
return true;
@ -295,8 +274,7 @@ namespace CtrEditor.Simulacion
private void HandleOnSeparation(Fixture fixtureA, Fixture fixtureB)
{
if (fixtureB.Body.UserData is simBarrera Sensor)
Sensor.LuzCortada = false;
// Aquí puedes restablecer cualquier estado si es necesario al separarse de un simRectangle
}
private void ApplyConveyorEffect(simTransporte conveyor, Fixture circleFixture, float porcentajeCompartido)
@ -311,8 +289,10 @@ namespace CtrEditor.Simulacion
{
private World world;
private Canvas simulationCanvas;
public List<simBase> Cuerpos;
public List<simBotella> circles;
public List<simTransporte> rectangles;
public List<simGuia> lines;
public List<simDescarte> descartes;
public Stopwatch stopwatch;
public Canvas DebugCanvas { get => simulationCanvas; set => simulationCanvas = value; }
@ -320,16 +300,19 @@ namespace CtrEditor.Simulacion
public SimulationManagerFP()
{
world = new World(new Vector2(0, 0)); // Vector2.Zero
Cuerpos = new List<simBase>();
circles = new List<simBotella>();
rectangles = new List<simTransporte>();
lines = new List<simGuia>();
descartes = new List<simDescarte>();
stopwatch = new Stopwatch();
}
public void Clear()
{
if (world.BodyList.Count > 0)
world.Clear();
if (Cuerpos.Count > 0)
Cuerpos.Clear();
circles.Clear();
rectangles.Clear();
lines.Clear();
world.Clear();
}
public void Step()
@ -345,44 +328,56 @@ namespace CtrEditor.Simulacion
world.Step(elapsedMilliseconds / 1000.0f);
}
public void Remove(simBase Objeto)
public void Remove(object Objeto)
{
Objeto.RemoverBody();
Cuerpos.Remove(Objeto);
switch (Objeto)
{
case simBotella obj:
obj.RemoverBody();
circles.Remove(obj);
break;
case simTransporte obj:
obj.RemoverBody();
rectangles.Remove(obj);
break;
case simGuia obj:
obj.RemoverBody();
lines.Remove(obj);
break;
case simDescarte obj:
obj.RemoverBody();
descartes.Remove(obj);
break;
default:
throw new InvalidOperationException("Tipo no soportado");
}
}
public simBotella AddCircle(float diameter, Vector2 position, float mass)
{
simBotella circle = new simBotella(world, diameter, position, mass);
Cuerpos.Add(circle);
circles.Add(circle);
return circle;
}
public simTransporte AddRectangle(float width, float height, Vector2 position, float angle)
{
simTransporte rectangle = new simTransporte(world, width, height, position, angle);
Cuerpos.Add(rectangle);
return rectangle;
}
public simTransporte AddBarrera(float width, float height, Vector2 position, float angle)
{
simTransporte rectangle = new simTransporte(world, width, height, position, angle);
Cuerpos.Add(rectangle);
rectangles.Add(rectangle);
return rectangle;
}
public simGuia AddLine(Vector2 start, Vector2 end)
{
simGuia line = new simGuia(world, start, end);
Cuerpos.Add(line);
lines.Add(line);
return line;
}
public simDescarte AddDescarte(float diameter, Vector2 position)
{
simDescarte descarte = new simDescarte(world, diameter, position);
Cuerpos.Add(descarte);
descartes.Add(descarte);
return descarte;
}