Compare commits
No commits in common. "f3e5992433a57892217aca46c911500b4247abfb" and "494f960628396ddbec9a47de4e226ac502174b1a" have entirely different histories.
f3e5992433
...
494f960628
|
@ -15,11 +15,6 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Icons\connect.png" />
|
||||
<None Remove="Icons\disconnect.png" />
|
||||
<None Remove="Icons\save.png" />
|
||||
<None Remove="Icons\start.png" />
|
||||
<None Remove="Icons\stop.png" />
|
||||
<None Remove="motor2.png" />
|
||||
<None Remove="tank.png" />
|
||||
</ItemGroup>
|
||||
|
@ -53,11 +48,6 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Resource Include="Icons\connect.png" />
|
||||
<Resource Include="Icons\disconnect.png" />
|
||||
<Resource Include="Icons\save.png" />
|
||||
<Resource Include="Icons\start.png" />
|
||||
<Resource Include="Icons\stop.png" />
|
||||
<Resource Include="motor2.png" />
|
||||
<Resource Include="tank.png" />
|
||||
</ItemGroup>
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 8.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 9.1 KiB |
BIN
Icons/save.png
BIN
Icons/save.png
Binary file not shown.
Before Width: | Height: | Size: 12 KiB |
BIN
Icons/start.png
BIN
Icons/start.png
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
BIN
Icons/stop.png
BIN
Icons/stop.png
Binary file not shown.
Before Width: | Height: | Size: 14 KiB |
|
@ -38,10 +38,8 @@ namespace CtrEditor
|
|||
public ObservableCollection<string> listaImagenes { get; private set; } // Publicación de las claves del diccionario
|
||||
public ObservableCollection<TipoSimulable> ListaOsBase { get; } = new ObservableCollection<TipoSimulable>();
|
||||
private ObservableCollection<osBase> _objetosSimulables = new ObservableCollection<osBase>();
|
||||
public PLCViewModel plcViewModelData;
|
||||
public PLCViewModel _plcViewModelData;
|
||||
public Stopwatch stopwatch;
|
||||
private bool isSimulationRunning;
|
||||
private bool isConnected;
|
||||
|
||||
public SimulationManagerFP simulationManager = new SimulationManagerFP();
|
||||
|
||||
|
@ -51,11 +49,6 @@ namespace CtrEditor
|
|||
public ICommand StopSimulationCommand { get; }
|
||||
public ICommand ItemDoubleClickCommand { get; private set; }
|
||||
|
||||
public ICommand TBStartSimulationCommand { get; }
|
||||
public ICommand TBStopSimulationCommand { get; }
|
||||
public ICommand TBSaveCommand { get; }
|
||||
public ICommand TBConnectPLCCommand { get; }
|
||||
public ICommand TBDisconnectPLCCommand { get; }
|
||||
|
||||
// Evento que se dispara cuando se selecciona una nueva imagen
|
||||
public event EventHandler<string> ImageSelected;
|
||||
|
@ -68,8 +61,8 @@ namespace CtrEditor
|
|||
datosDeTrabajo = new DatosDeTrabajo();
|
||||
|
||||
// Inicializa el PLCViewModel
|
||||
plcViewModelData = new PLCViewModel();
|
||||
plcViewModelData.RefreshEvent += OnRefreshEvent;
|
||||
_plcViewModelData = new PLCViewModel();
|
||||
_plcViewModelData.RefreshEvent += OnRefreshEvent;
|
||||
|
||||
InitializeTipoSimulableList();
|
||||
|
||||
|
@ -82,12 +75,6 @@ namespace CtrEditor
|
|||
StartSimulationCommand = new RelayCommand(StartSimulation);
|
||||
StopSimulationCommand = new RelayCommand(StopSimulation);
|
||||
|
||||
TBStartSimulationCommand = new RelayCommand(StartSimulation, () => !IsSimulationRunning);
|
||||
TBStopSimulationCommand = new RelayCommand(StopSimulation, () => IsSimulationRunning);
|
||||
TBSaveCommand = new RelayCommand(Save);
|
||||
TBConnectPLCCommand = new RelayCommand(ConnectPLC, () => !IsConnected);
|
||||
TBDisconnectPLCCommand = new RelayCommand(DisconnectPLC, () => IsConnected);
|
||||
|
||||
stopwatch = new Stopwatch();
|
||||
}
|
||||
|
||||
|
@ -141,27 +128,6 @@ namespace CtrEditor
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsSimulationRunning
|
||||
{
|
||||
get => isSimulationRunning;
|
||||
set
|
||||
{
|
||||
isSimulationRunning = value;
|
||||
OnPropertyChanged(nameof(IsSimulationRunning));
|
||||
CommandManager.InvalidateRequerySuggested(); // Notificar que el estado de los comandos ha cambiado
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsConnected
|
||||
{
|
||||
get => isConnected;
|
||||
set
|
||||
{
|
||||
isConnected = value;
|
||||
OnPropertyChanged(nameof(IsConnected));
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
}
|
||||
|
||||
private void StartSimulation()
|
||||
{
|
||||
|
@ -172,14 +138,12 @@ namespace CtrEditor
|
|||
|
||||
_timerSimulacion.Start();
|
||||
simulationManager.stopwatch.Start();
|
||||
IsSimulationRunning = true;
|
||||
}
|
||||
|
||||
private void StopSimulation()
|
||||
{
|
||||
_timerSimulacion.Stop();
|
||||
simulationManager.stopwatch.Stop();
|
||||
IsSimulationRunning = false;
|
||||
}
|
||||
|
||||
private void OnTickSimulacion(object sender, EventArgs e)
|
||||
|
@ -195,23 +159,10 @@ namespace CtrEditor
|
|||
|
||||
}
|
||||
|
||||
private void ConnectPLC()
|
||||
{
|
||||
plcViewModelData.Connect();
|
||||
}
|
||||
|
||||
private void DisconnectPLC()
|
||||
{
|
||||
plcViewModelData.Disconnect();
|
||||
IsConnected = false;
|
||||
}
|
||||
|
||||
private void OnRefreshEvent(object sender, EventArgs e)
|
||||
{
|
||||
if (plcViewModelData.IsConnected)
|
||||
if (_plcViewModelData.IsConnected)
|
||||
{
|
||||
if (!isConnected)
|
||||
IsConnected = true;
|
||||
// Detener el cronómetro y obtener el tiempo transcurrido en milisegundos
|
||||
stopwatch.Stop();
|
||||
float elapsedMilliseconds = (float)stopwatch.Elapsed.TotalMilliseconds;
|
||||
|
@ -220,7 +171,7 @@ namespace CtrEditor
|
|||
stopwatch.Restart();
|
||||
|
||||
foreach (var objetoSimulable in ObjetosSimulables)
|
||||
objetoSimulable.UpdatePLC(plcViewModelData.PLCInterface, (int) elapsedMilliseconds);
|
||||
objetoSimulable.UpdatePLC(_plcViewModelData.PLCInterface, (int) elapsedMilliseconds);
|
||||
} else
|
||||
stopwatch.Stop();
|
||||
|
||||
|
@ -255,10 +206,10 @@ namespace CtrEditor
|
|||
|
||||
public PLCViewModel PLCViewModel
|
||||
{
|
||||
get { return plcViewModelData; }
|
||||
get { return _plcViewModelData; }
|
||||
set
|
||||
{
|
||||
plcViewModelData = value;
|
||||
_plcViewModelData = value;
|
||||
OnPropertyChanged(nameof(PLCViewModel));
|
||||
}
|
||||
}
|
||||
|
@ -399,7 +350,7 @@ namespace CtrEditor
|
|||
PixelToMeter.Instance.calc = simulationData.UnitConverter;
|
||||
|
||||
// Re-register to the events
|
||||
plcViewModelData.RefreshEvent += OnRefreshEvent;
|
||||
_plcViewModelData.RefreshEvent += OnRefreshEvent;
|
||||
|
||||
// Recorrer la colección de objetos simulables
|
||||
foreach (var objetoSimulable in ObjetosSimulables)
|
||||
|
|
|
@ -9,35 +9,15 @@
|
|||
Height="900" Width="1600"
|
||||
ResizeMode="CanResize" Title="{Binding directorioTrabajo}">
|
||||
|
||||
<Window.DataContext>
|
||||
<ctreditor:MainViewModel/>
|
||||
</Window.DataContext>
|
||||
|
||||
<Window.Resources>
|
||||
<convert:FloatToFormattedStringConverter x:Key="floatFormatter"/>
|
||||
<convert:BrushToColorNameConverter x:Key="BrushToColorNameConverter"/>
|
||||
|
||||
<!-- Style for Start/Stop Button -->
|
||||
<Style x:Key="StartStopButtonStyle" TargetType="Button">
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsSimulationRunning}" Value="True">
|
||||
<Setter Property="Background" Value="LightGreen"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<!-- Style for Connect/Disconnect Button -->
|
||||
<Style x:Key="ConnectDisconnectButtonStyle" TargetType="Button">
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Background" Value="LightGreen"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
|
||||
<Window.DataContext>
|
||||
<ctreditor:MainViewModel/>
|
||||
</Window.DataContext>
|
||||
|
||||
<Grid>
|
||||
<!-- Menú Principal sobre toda la ventana -->
|
||||
<Menu VerticalAlignment="Top" HorizontalAlignment="Stretch">
|
||||
|
@ -80,47 +60,7 @@
|
|||
|
||||
<!-- Segunda Columna -->
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ToolBarTray Grid.Row="0">
|
||||
<ToolBar>
|
||||
<Button Command="{Binding TBStartSimulationCommand}" ToolTip="Iniciar Simulación" Style="{StaticResource StartStopButtonStyle}">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/start.png" Width="16" Height="16"/>
|
||||
<TextBlock Text="Iniciar"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBStopSimulationCommand}" ToolTip="Detener Simulación">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/stop.png" Width="16" Height="16"/>
|
||||
<TextBlock Text="Detener"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBSaveCommand}" ToolTip="Guardar">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/save.png" Width="16" Height="16"/>
|
||||
<TextBlock Text="Guardar"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBConnectPLCCommand}" ToolTip="Conectar PLC" Style="{StaticResource ConnectDisconnectButtonStyle}">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/connect.png" Width="16" Height="16"/>
|
||||
<TextBlock Text="Conectar"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBDisconnectPLCCommand}" ToolTip="Desconectar PLC">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/disconnect.png" Width="16" Height="16"/>
|
||||
<TextBlock Text="Desconectar"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</ToolBar>
|
||||
</ToolBarTray>
|
||||
|
||||
<ScrollViewer Grid.Row="1" x:Name="ImagenEnTrabajoScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" PanningMode="Both">
|
||||
<ScrollViewer x:Name="ImagenEnTrabajoScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" PanningMode="Both">
|
||||
<Canvas x:Name="ImagenEnTrabajoCanvas" Margin="20">
|
||||
<!-- El Margin puede ser ajustado según el espacio adicional que quieras proporcionar -->
|
||||
<Canvas.LayoutTransform>
|
||||
|
|
|
@ -29,9 +29,6 @@ namespace CtrEditor.ObjetosSim
|
|||
return new ucBoton();
|
||||
if (tipoObjeto == typeof(osTanque))
|
||||
return new ucTanque();
|
||||
if (tipoObjeto == typeof(osSensTemperatura))
|
||||
return new ucSensTemperatura();
|
||||
|
||||
|
||||
// Puedes añadir más condiciones para otros tipos
|
||||
|
||||
|
@ -56,8 +53,6 @@ namespace CtrEditor.ObjetosSim
|
|||
return new osBoton();
|
||||
if (tipoObjeto == typeof(osTanque))
|
||||
return new osTanque();
|
||||
if (tipoObjeto == typeof(osSensTemperatura))
|
||||
return new osSensTemperatura();
|
||||
|
||||
|
||||
// Puedes añadir más condiciones para otros tipos
|
||||
|
|
|
@ -70,22 +70,6 @@ namespace CtrEditor.ObjetosSim
|
|||
public SimulationManagerFP simulationManager;
|
||||
|
||||
|
||||
protected osBase ObtenerLink(string NameLink, Type tipoOsBase)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(NameLink) && _mainViewModel != null)
|
||||
{
|
||||
foreach (var objetoSimulable in _mainViewModel.ObjetosSimulables)
|
||||
{
|
||||
if (tipoOsBase.IsInstanceOfType(objetoSimulable) && ((osBase)objetoSimulable).Nombre == NameLink)
|
||||
{
|
||||
return (osBase)objetoSimulable;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void CanvasSetLeftinMeter(float left)
|
||||
{
|
||||
if (_visualRepresentation != null)
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
<UserControl x:Class="CtrEditor.ObjetosSim.ucSensTemperatura"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
|
||||
mc:Ignorable="d"
|
||||
xmlns:convert="clr-namespace:CtrEditor.Convertidores">
|
||||
|
||||
<UserControl.Resources>
|
||||
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Border x:Name="BackgroundRectangle"
|
||||
BorderBrush="Black"
|
||||
BorderThickness="2"
|
||||
Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=1.5}"
|
||||
VerticalAlignment="Top"
|
||||
Background="Gray"
|
||||
HorizontalAlignment="Center"
|
||||
Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}">
|
||||
<Grid>
|
||||
<Slider
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}}"
|
||||
Orientation="Vertical"
|
||||
Value="{Binding Value}"
|
||||
Maximum="100"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
|
@ -1,222 +0,0 @@
|
|||
using CtrEditor.Convertidores;
|
||||
using CtrEditor.Siemens;
|
||||
using Siemens.Simatic.Simulation.Runtime;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace CtrEditor.ObjetosSim
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ucSensTemperatura.xaml
|
||||
/// </summary>
|
||||
public class osSensTemperatura : osBase
|
||||
{
|
||||
// Otros datos y métodos relevantes para la simulación
|
||||
|
||||
private string _nombre = "Temperatura";
|
||||
private float _ancho;
|
||||
private float _alto;
|
||||
private float _left;
|
||||
private float _top;
|
||||
private float _angulo;
|
||||
private string _tag;
|
||||
private float _value;
|
||||
private float _max_OUT_Scaled;
|
||||
private float _min_OUT_Scaled;
|
||||
|
||||
public string Tag
|
||||
{
|
||||
get => _tag;
|
||||
set
|
||||
{
|
||||
if (_tag != value)
|
||||
{
|
||||
_tag = value;
|
||||
OnPropertyChanged(nameof(Tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float Min_OUT_Scaled
|
||||
{
|
||||
get => _min_OUT_Scaled;
|
||||
set
|
||||
{
|
||||
_min_OUT_Scaled = value;
|
||||
OnPropertyChanged(nameof(Min_OUT_Scaled));
|
||||
}
|
||||
}
|
||||
public float Max_OUT_Scaled
|
||||
{
|
||||
get => _max_OUT_Scaled;
|
||||
set
|
||||
{
|
||||
_max_OUT_Scaled = value;
|
||||
OnPropertyChanged(nameof(Max_OUT_Scaled));
|
||||
}
|
||||
}
|
||||
|
||||
public float Value
|
||||
{
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
_value = value;
|
||||
OnPropertyChanged(nameof(Value));
|
||||
}
|
||||
}
|
||||
public override float Left
|
||||
{
|
||||
get => _left;
|
||||
set
|
||||
{
|
||||
_left = value;
|
||||
CanvasSetLeftinMeter(value);
|
||||
OnPropertyChanged(nameof(Left));
|
||||
}
|
||||
}
|
||||
public override float Top
|
||||
{
|
||||
get => _top;
|
||||
set
|
||||
{
|
||||
_top = value;
|
||||
CanvasSetTopinMeter(value);
|
||||
OnPropertyChanged(nameof(Top));
|
||||
}
|
||||
}
|
||||
|
||||
public float Ancho
|
||||
{
|
||||
get => _ancho;
|
||||
set
|
||||
{
|
||||
_ancho = value;
|
||||
OnPropertyChanged(nameof(Ancho));
|
||||
}
|
||||
}
|
||||
public float Alto
|
||||
{
|
||||
get => _alto;
|
||||
set
|
||||
{
|
||||
_alto = value;
|
||||
OnPropertyChanged(nameof(Alto));
|
||||
}
|
||||
}
|
||||
|
||||
public float Angulo
|
||||
{
|
||||
get => _angulo;
|
||||
set
|
||||
{
|
||||
_angulo = value;
|
||||
OnPropertyChanged(nameof(Angulo));
|
||||
}
|
||||
}
|
||||
|
||||
public override string Nombre
|
||||
{
|
||||
get => _nombre;
|
||||
set
|
||||
{
|
||||
if (_nombre != value)
|
||||
{
|
||||
_nombre = value;
|
||||
OnPropertyChanged(nameof(Nombre));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public osSensTemperatura()
|
||||
{
|
||||
Ancho = 0.4f;
|
||||
Alto = 1f;
|
||||
Max_OUT_Scaled = 27648;
|
||||
Min_OUT_Scaled = 0;
|
||||
}
|
||||
|
||||
public override void UpdateGeometryStart()
|
||||
{
|
||||
// Se llama antes de la simulacion
|
||||
|
||||
}
|
||||
public override void UpdateGeometryStep()
|
||||
{
|
||||
}
|
||||
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
|
||||
{
|
||||
if (Tag.Length > 0)
|
||||
{
|
||||
SDataValue s = new SDataValue();
|
||||
s.UInt16 = (ushort)((Value / 100.0 * Max_OUT_Scaled) + Min_OUT_Scaled);
|
||||
plc.EscribirTag(Tag, s);
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateControl()
|
||||
{
|
||||
|
||||
}
|
||||
public override void ucLoaded()
|
||||
{
|
||||
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
||||
// crear el objeto de simulacion
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class ucSensTemperatura : UserControl, IDataContainer
|
||||
{
|
||||
public osBase? Datos { get; set; }
|
||||
|
||||
public ucSensTemperatura()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Loaded += OnLoaded;
|
||||
}
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Datos?.ucLoaded();
|
||||
}
|
||||
public void Resize(float width, float height)
|
||||
{
|
||||
if (Datos is osSensTemperatura datos)
|
||||
{
|
||||
datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
|
||||
datos.Alto = PixelToMeter.Instance.calc.PixelsToMeters(width);
|
||||
}
|
||||
}
|
||||
public void Move(float LeftPixels, float TopPixels)
|
||||
{
|
||||
if (Datos != null)
|
||||
{
|
||||
Datos.Left = PixelToMeter.Instance.calc.PixelsToMeters(LeftPixels);
|
||||
Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels);
|
||||
}
|
||||
}
|
||||
public void Rotate(float Angle)
|
||||
{
|
||||
if (Datos != null)
|
||||
if (Datos is osSensTemperatura datos)
|
||||
datos.Angulo = Angle;
|
||||
}
|
||||
public void Highlight(bool State) { }
|
||||
public int ZIndex()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,15 +18,7 @@
|
|||
Source="/tank.png"
|
||||
Width="{Binding Alto, Converter={StaticResource MeterToPixelConverter}}"
|
||||
Height="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}"
|
||||
Stretch="Uniform">
|
||||
</Image>
|
||||
<Slider
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}}"
|
||||
Orientation="Vertical"
|
||||
Value="{Binding Level}"
|
||||
Maximum="100"/>
|
||||
Stretch="Uniform"/>
|
||||
|
||||
<Rectangle x:Name="WaterLevel"
|
||||
Fill="Blue"
|
||||
|
@ -42,7 +34,6 @@
|
|||
</MultiBinding>
|
||||
</Rectangle.Height>
|
||||
</Rectangle>
|
||||
|
||||
<Label Content="{Binding Level}" HorizontalAlignment="Center" Margin="10,10,0,0" VerticalAlignment="Top"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using CtrEditor.Convertidores;
|
||||
using CtrEditor.Siemens;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OpenCvSharp.Flann;
|
||||
using Siemens.Simatic.Simulation.Runtime;
|
||||
using System;
|
||||
|
@ -35,8 +34,7 @@ namespace CtrEditor.ObjetosSim
|
|||
private float _angulo;
|
||||
private float _level;
|
||||
private string _tag;
|
||||
private float _max_OUT_Scaled;
|
||||
private float _min_OUT_Scaled;
|
||||
|
||||
|
||||
public string Tag
|
||||
{
|
||||
|
@ -50,27 +48,6 @@ namespace CtrEditor.ObjetosSim
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float Min_OUT_Scaled
|
||||
{
|
||||
get => _min_OUT_Scaled;
|
||||
set
|
||||
{
|
||||
_min_OUT_Scaled = value;
|
||||
OnPropertyChanged(nameof(Min_OUT_Scaled));
|
||||
}
|
||||
}
|
||||
|
||||
public float Max_OUT_Scaled
|
||||
{
|
||||
get => _max_OUT_Scaled;
|
||||
set
|
||||
{
|
||||
_max_OUT_Scaled = value;
|
||||
OnPropertyChanged(nameof(Max_OUT_Scaled));
|
||||
}
|
||||
}
|
||||
|
||||
public float Level
|
||||
{
|
||||
get => _level;
|
||||
|
@ -148,8 +125,6 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
Ancho = 0.30f;
|
||||
Alto = 0.30f;
|
||||
Max_OUT_Scaled = 27648;
|
||||
Min_OUT_Scaled = 0;
|
||||
}
|
||||
|
||||
public override void UpdateGeometryStart()
|
||||
|
@ -165,7 +140,7 @@ namespace CtrEditor.ObjetosSim
|
|||
if (Tag.Length > 0)
|
||||
{
|
||||
SDataValue s = new SDataValue();
|
||||
s.UInt16 = (ushort)((Level / 100.0 * Max_OUT_Scaled) + Min_OUT_Scaled);
|
||||
s.UInt16 = (ushort)(Level / 100.0 * 26600);
|
||||
plc.EscribirTag(Tag, s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,11 +202,18 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
if (_osMotor is osVMmotorSim motor)
|
||||
VelocidadActual = motor.Velocidad;
|
||||
} else
|
||||
{
|
||||
if (Motor.Length > 0)
|
||||
if (_mainViewModel != null)
|
||||
foreach (var objetoSimulable in _mainViewModel.ObjetosSimulables)
|
||||
if (objetoSimulable.Nombre == _motor)
|
||||
{
|
||||
_osMotor = objetoSimulable;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
_osMotor = ObtenerLink(_motor, typeof(osVMmotorSim));
|
||||
}
|
||||
|
||||
public override void ucLoaded()
|
||||
{
|
||||
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
||||
|
|
|
@ -153,7 +153,16 @@ namespace CtrEditor.ObjetosSim
|
|||
VelocidadActual = motor.Velocidad;
|
||||
}
|
||||
else
|
||||
_osMotor = ObtenerLink(_motor, typeof(osVMmotorSim));
|
||||
{
|
||||
if (Motor.Length > 0)
|
||||
if (_mainViewModel != null)
|
||||
foreach (var objetoSimulable in _mainViewModel.ObjetosSimulables)
|
||||
if (objetoSimulable.Nombre == _motor)
|
||||
{
|
||||
_osMotor = objetoSimulable;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateControl()
|
||||
|
|
|
@ -103,8 +103,6 @@ namespace CtrEditor.Siemens
|
|||
}
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Implementa la conexión utilizando PLCModel
|
||||
PLCInterface.Instance = SimulationRuntimeManager.CreateInterface(Name);
|
||||
|
@ -118,11 +116,6 @@ namespace CtrEditor.Siemens
|
|||
ConnectionStatus = "connected";
|
||||
IsConnected = true;
|
||||
}
|
||||
} catch (Exception ex)
|
||||
{
|
||||
LastError = ex.Message;
|
||||
ConnectionStatus = "offline";
|
||||
}
|
||||
}
|
||||
|
||||
private void Instance_OnSoftwareConfigurationChanged(IInstance instance, SOnSoftwareConfigChangedParameter event_param)
|
||||
|
|
|
@ -12,7 +12,6 @@ using CtrEditor.Convertidores;
|
|||
using FarseerPhysics.Common;
|
||||
using System.Windows;
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Documents;
|
||||
|
||||
namespace CtrEditor.Simulacion
|
||||
{
|
||||
|
@ -183,32 +182,7 @@ namespace CtrEditor.Simulacion
|
|||
if (fixtureB.Body.UserData is simRectangle)
|
||||
{
|
||||
simRectangle conveyor = fixtureB.Body.UserData as simRectangle;
|
||||
CircleShape circleShape = fixtureA.Shape as CircleShape;
|
||||
PolygonShape polygonShape = fixtureB.Shape as PolygonShape;
|
||||
|
||||
// Obtener centro y radio del círculo
|
||||
Vector2 centroCirculo = fixtureA.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(fixtureB.Body.Rotation);
|
||||
float sin = (float)Math.Sin(fixtureB.Body.Rotation);
|
||||
|
||||
for (int i = 0; i < polygonShape.Vertices.Count; i++)
|
||||
{
|
||||
Vector2 vertex = polygonShape.Vertices[i];
|
||||
float rotatedX = vertex.X * cos - vertex.Y * sin + fixtureB.Body.Position.X;
|
||||
float rotatedY = vertex.X * sin + vertex.Y * cos + fixtureB.Body.Position.Y;
|
||||
vertices[i] = new Vector2(rotatedX, rotatedY);
|
||||
}
|
||||
|
||||
// Calcular el porcentaje de la superficie compartida
|
||||
float porcentajeCompartido = InterseccionCirculoRectangulo.CalcularSuperficieCompartida(vertices, centroCirculo, radio);
|
||||
|
||||
// Aplicar el efecto del transportador usando el porcentaje calculado
|
||||
ApplyConveyorEffect(conveyor, fixtureA, porcentajeCompartido);
|
||||
|
||||
ApplyConveyorEffect(conveyor, fixtureA);
|
||||
return true; // No aplicar respuestas físicas
|
||||
}
|
||||
return true; // No aplicar respuestas físicas
|
||||
|
@ -219,11 +193,11 @@ namespace CtrEditor.Simulacion
|
|||
// Aquí puedes restablecer cualquier estado si es necesario al separarse de un simRectangle
|
||||
}
|
||||
|
||||
private void ApplyConveyorEffect(simRectangle conveyor, Fixture circleFixture, float porcentajeCompartido)
|
||||
private void ApplyConveyorEffect(simRectangle conveyor, Fixture circleFixture)
|
||||
{
|
||||
float speedMetersPerSecond = conveyor.Speed / 60.0f;
|
||||
Vector2 desiredVelocity = new Vector2((float)Math.Cos(conveyor.Body.Rotation), (float)Math.Sin(conveyor.Body.Rotation)) * speedMetersPerSecond;
|
||||
circleFixture.Body.LinearVelocity += desiredVelocity * porcentajeCompartido;
|
||||
circleFixture.Body.LinearVelocity = desiredVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FarseerPhysics.Collision;
|
||||
using Microsoft.VisualBasic.Devices;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace CtrEditor.Simulacion
|
||||
{
|
||||
internal class InterseccionCirculoRectangulo
|
||||
{
|
||||
// Definición de la función CalcularSuperficieCompartida
|
||||
public static float CalcularSuperficieCompartida(Vector2[] vertices, Vector2 center, float r)
|
||||
{
|
||||
float totalCircleArea = (float)Math.PI * r * r;
|
||||
|
||||
// Distancia a líneas ajustado
|
||||
float[] distances = new float[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
distances[i] = DistanceFromLine(center, vertices[i], vertices[(i + 1) % 4]);
|
||||
}
|
||||
|
||||
float minDistance = float.MaxValue;
|
||||
foreach (var dist in distances)
|
||||
{
|
||||
if (Math.Abs(dist) < Math.Abs(minDistance))
|
||||
minDistance = dist;
|
||||
}
|
||||
float d = Math.Abs(minDistance);
|
||||
|
||||
float sharedArea = 0;
|
||||
if (Array.TrueForAll(distances, dist => Math.Abs(dist) > r))
|
||||
{
|
||||
sharedArea = totalCircleArea;
|
||||
}
|
||||
else if (d < r)
|
||||
{
|
||||
float cosTheta = Math.Min(1, d / r);
|
||||
float sinTheta = (float)Math.Sqrt(Math.Max(0, r * r - d * d));
|
||||
if (minDistance < 0) // El centro está dentro del rectángulo
|
||||
{
|
||||
float areaOutside = r * r * (float)Math.Acos(cosTheta) - d * sinTheta;
|
||||
sharedArea = totalCircleArea - areaOutside;
|
||||
}
|
||||
else // El centro está fuera del rectángulo
|
||||
{
|
||||
sharedArea = r * r * (float)Math.Acos(cosTheta) - d * sinTheta;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sharedArea = 0;
|
||||
}
|
||||
|
||||
return sharedArea / totalCircleArea;
|
||||
}
|
||||
|
||||
public static float DistanceFromLine(Vector2 point, Vector2 start, Vector2 end)
|
||||
{
|
||||
float A = end.Y - start.Y;
|
||||
float B = start.X - end.X;
|
||||
float C = end.X * start.Y - start.X * end.Y;
|
||||
float distance = (A * point.X + B * point.Y + C) / (float)Math.Sqrt(A * A + B * B);
|
||||
return distance;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue