Agregada la posibilidad de invertir la imagen ucCustomImage

This commit is contained in:
Miguel 2025-03-26 15:18:58 +01:00
parent 304bdb06d4
commit 211c518be6
8 changed files with 113 additions and 10 deletions

View File

@ -0,0 +1,30 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace CtrEditor.FuncionesBase
{
public class BooleanToDoubleConverter : IValueConverter
{
public double TrueValue { get; set; } = -1;
public double FalseValue { get; set; } = 1;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return boolValue ? TrueValue : FalseValue;
}
return FalseValue;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double doubleValue)
{
return Math.Abs(doubleValue - TrueValue) < double.Epsilon;
}
return false;
}
}
}

View File

@ -1,14 +1,22 @@
<UserControl x:Class="CtrEditor.ObjetosSim.ucCustomImage" <UserControl x:Class="CtrEditor.ObjetosSim.ucCustomImage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:funcionesbase="clr-namespace:CtrEditor.FuncionesBase">
<UserControl.DataContext> <UserControl.DataContext>
<vm:osCustomImage /> <vm:osCustomImage />
</UserControl.DataContext> </UserControl.DataContext>
<UserControl.Resources>
<funcionesbase:BooleanToDoubleConverter x:Key="FlipConverter" TrueValue="-1" FalseValue="1"/>
</UserControl.Resources>
<Grid RenderTransformOrigin="0.5,0.5"> <Grid RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform> <Grid.RenderTransform>
<TransformGroup> <TransformGroup>
<ScaleTransform
ScaleX="{Binding Horizontal_Flip, Converter={StaticResource FlipConverter}}"
ScaleY="{Binding Vertical_Flip, Converter={StaticResource FlipConverter}}"/>
<RotateTransform Angle="{Binding Angulo}"/> <RotateTransform Angle="{Binding Angulo}"/>
</TransformGroup> </TransformGroup>
</Grid.RenderTransform> </Grid.RenderTransform>

View File

@ -33,6 +33,16 @@ namespace CtrEditor.ObjetosSim
[property: Category("Image:")] [property: Category("Image:")]
private string imagePath; private string imagePath;
[ObservableProperty]
[property: Description("Flip the image horizontally")]
[property: Category("Image:")]
private bool horizontal_Flip;
[ObservableProperty]
[property: Description("Flip the image vertically")]
[property: Category("Image:")]
private bool vertical_Flip;
[JsonIgnore] [JsonIgnore]
[ObservableProperty] [ObservableProperty]
@ -51,6 +61,16 @@ namespace CtrEditor.ObjetosSim
} }
} }
partial void OnHorizontal_FlipChanged(bool value)
{
// Property changed handler will trigger UI update through binding
}
partial void OnVertical_FlipChanged(bool value)
{
// Property changed handler will trigger UI update through binding
}
public osCustomImage() public osCustomImage()
{ {
Ancho = 0.30f; Ancho = 0.30f;

View File

@ -68,6 +68,13 @@ namespace CtrEditor.ObjetosSim
[property: Category("Encoders:")] [property: Category("Encoders:")]
public float k_encoder_X; public float k_encoder_X;
[ObservableProperty]
[property: ReadOnly(true)]
[property: Description("Actual Position X")]
[property: Category("Encoders:")]
public float encoder_X_Position;
[ObservableProperty] [ObservableProperty]
[property: Description("X in meter offset Left. Position when the encoder is 0")] [property: Description("X in meter offset Left. Position when the encoder is 0")]
[property: Category("Encoders:")] [property: Category("Encoders:")]
@ -85,6 +92,12 @@ namespace CtrEditor.ObjetosSim
[property: Category("Encoders:")] [property: Category("Encoders:")]
public float k_encoder_Y; public float k_encoder_Y;
[ObservableProperty]
[property: ReadOnly(true)]
[property: Description("Actual Position Y")]
[property: Category("Encoders:")]
public float encoder_Y_Position;
[ObservableProperty] [ObservableProperty]
[property: Description("Y in meter offset Top. Position when the encoder is 0")] [property: Description("Y in meter offset Top. Position when the encoder is 0")]
[property: Category("Encoders:")] [property: Category("Encoders:")]
@ -186,11 +199,16 @@ namespace CtrEditor.ObjetosSim
{ {
// Update X position if encoder is available // Update X position if encoder is available
if (EncoderX != null && K_encoder_X != 0) if (EncoderX != null && K_encoder_X != 0)
Left = (EncoderX.Valor_Actual / k_encoder_X) + offset_encoder_X; {
Encoder_Y_Position = EncoderY.Valor_Actual;
Left = (Encoder_X_Position / k_encoder_X) + offset_encoder_X;
}
// Update Y position if encoder is available // Update Y position if encoder is available
if (EncoderY != null && K_encoder_Y != 0) if (EncoderY != null && K_encoder_Y != 0)
Top = (EncoderY.Valor_Actual / k_encoder_Y) + offset_encoder_Y; {
Encoder_Y_Position = EncoderY.Valor_Actual;
Top = (Encoder_Y_Position / k_encoder_Y) + offset_encoder_Y;
}
} }
public override void TopChanging(float oldValue, float newValue) public override void TopChanging(float oldValue, float newValue)

View File

@ -13,7 +13,7 @@ using System.Text.Json.Serialization;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
/// <summary> /// <summary>
/// Interaction logic for ucTransporteTTop.xaml /// Interaction logic for ucTransporteTTopDualInverter.xaml
/// </summary> /// </summary>
/// ///
@ -53,7 +53,7 @@ namespace CtrEditor.ObjetosSim
partial void OnInvertirDireccionChanged(bool value) partial void OnInvertirDireccionChanged(bool value)
{ {
SetSpeed(); SetSpeed();
if (_visualRepresentation is ucTransporteTTop uc) if (_visualRepresentation is ucTransporteTTopDualInverter uc)
{ {
CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion); CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion);
ActualizarAnimacionStoryBoardTransporte(VelocidadActual); ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
@ -156,7 +156,7 @@ namespace CtrEditor.ObjetosSim
private void ActualizarGeometrias() private void ActualizarGeometrias()
{ {
if (_visualRepresentation is ucTransporteTTop uc) if (_visualRepresentation is ucTransporteTTopDualInverter uc)
{ {
UpdateRectangle(SimGeometria, uc.Transporte, Alto, Ancho, Angulo); UpdateRectangle(SimGeometria, uc.Transporte, Alto, Ancho, Angulo);
SetSpeed(); SetSpeed();
@ -206,6 +206,8 @@ namespace CtrEditor.ObjetosSim
else else
VelocidadActual = 0; VelocidadActual = 0;
} }
else
VelocidadActual = 0;
} }
public override void ucLoaded() public override void ucLoaded()
@ -216,7 +218,7 @@ namespace CtrEditor.ObjetosSim
OnId_Motor_AChanged(Id_Motor_A); // Link Id_Motor = Motor OnId_Motor_AChanged(Id_Motor_A); // Link Id_Motor = Motor
OnId_Motor_BChanged(Id_Motor_B); // Link Id_Motor = Motor OnId_Motor_BChanged(Id_Motor_B); // Link Id_Motor = Motor
if (_visualRepresentation is ucTransporteTTop uc) if (_visualRepresentation is ucTransporteTTopDualInverter uc)
{ {
SimGeometria = AddRectangle(simulationManager, uc.Transporte, Alto, Ancho, Angulo); SimGeometria = AddRectangle(simulationManager, uc.Transporte, Alto, Ancho, Angulo);
CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion); CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion);

View File

@ -213,7 +213,7 @@ namespace CtrEditor.ObjetosSim
// Update local state from ControlWord // Update local state from ControlWord
OUT_Run = control.run; OUT_Run = control.run;
OUT_Stop = control.stop; OUT_Stop = !control.stop;
OUT_Reversal = control.reversal; OUT_Reversal = control.reversal;
OUT_OUT_VFD_REQ_Speed_Hz = control.reqSpeedHz; OUT_OUT_VFD_REQ_Speed_Hz = control.reqSpeedHz;

View File

@ -56,6 +56,12 @@ namespace CtrEditor.ObjetosSim
[property: Category("PLC link:")] [property: Category("PLC link:")]
string tag_Valor; string tag_Valor;
[ObservableProperty]
[property: Description("Tag para leer el valor del encoder. Este tag tiene prioridad sobre el Motor. Si se usa solo se lee el tag para actualizar la posicion.")]
[property: Category("PLC link:")]
string tag_ReadValor;
partial void OnId_MotorChanged(string value) partial void OnId_MotorChanged(string value)
{ {
if (Motor != null) if (Motor != null)
@ -85,7 +91,16 @@ namespace CtrEditor.ObjetosSim
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds) public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
{ {
if (Motor != null && Motor is osVMmotorSim motor) if (Tag_ReadValor != null && Tag_ReadValor.Length > 0)
{
// Bypass motor and read directly from tag
var value = LeerDINTTag(tag_ReadValor);
if (value != null)
{
Valor_Actual = (int)value;
return;
}
} else if (Motor != null && Motor is osVMmotorSim motor)
{ {
VelocidadActual = motor.Velocidad; VelocidadActual = motor.Velocidad;

View File

@ -782,6 +782,16 @@ namespace CtrEditor.ObjetosSim
} }
} }
public int? LeerDINTTag(string Tag)
{
if (_plc == null) return null;
if (!string.IsNullOrEmpty(Tag))
{
return _plc.LeerTagDInt(Tag);
}
return null;
}
public void EscribirWordTagScaled(string Tag, float Value, float IN_scale_Min, float IN_scale_Max, float OUT_scale_Min, float OUT_scale_Max) public void EscribirWordTagScaled(string Tag, float Value, float IN_scale_Min, float IN_scale_Max, float OUT_scale_Min, float OUT_scale_Max)
{ {
if (_plc == null) return; if (_plc == null) return;