Agregando el uc Motor
This commit is contained in:
parent
222cabf630
commit
81450e56aa
|
@ -0,0 +1,130 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using System.Windows;
|
||||
|
||||
namespace CtrEditor.Convertidores
|
||||
{
|
||||
public class PixelToMeter
|
||||
{
|
||||
// Instancia privada estática, parte del patrón Singleton
|
||||
private static PixelToMeter? _instance;
|
||||
public UnitConverter calc = new UnitConverter(0.01f);
|
||||
|
||||
// Propiedad pública estática para acceder a la instancia
|
||||
public static PixelToMeter Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new PixelToMeter();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MeterToPixelConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
float meters = (float)value;
|
||||
float factor = 1;
|
||||
if (parameter != null)
|
||||
if (parameter.ToString() == "0.5") factor = 0.5f;
|
||||
else if (parameter.ToString() == "-0.5") factor = -0.5f;
|
||||
|
||||
return PixelToMeter.Instance.calc.MetersToPixels(meters) * factor;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
float pixels = (float)value;
|
||||
float factor = 1;
|
||||
if (parameter != null)
|
||||
if (parameter.ToString() == "0.5") factor = 0.5f;
|
||||
else if (parameter.ToString() == "-0.5") factor = -0.5f;
|
||||
|
||||
return PixelToMeter.Instance.calc.PixelsToMeters(pixels) * factor;
|
||||
}
|
||||
}
|
||||
|
||||
public class DistanceToMarginConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is double distance)
|
||||
{
|
||||
return new Thickness(0, 0, 0, PixelToMeter.Instance.calc.MetersToPixels((float)distance)); // Ajustar Bottom a 'distance'
|
||||
}
|
||||
return new Thickness();
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException("ConvertBack is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
public class FloatToFormattedStringConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is float floatValue)
|
||||
{
|
||||
return floatValue.ToString("0.00", culture); // Formatear a dos decimales
|
||||
}
|
||||
return value; // Devolver el valor original si no es un float
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string stringValue && float.TryParse(stringValue, NumberStyles.Float, culture, out float result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return value; // Devolver el valor original si no se puede convertir
|
||||
}
|
||||
}
|
||||
|
||||
public class UnitConverter
|
||||
{
|
||||
// La escala representa cuántos metros hay en un píxel
|
||||
public float Scale { get; private set; }
|
||||
|
||||
|
||||
public UnitConverter(float scale)
|
||||
{
|
||||
if (scale <= 0)
|
||||
throw new ArgumentException("Scale must be greater than zero.");
|
||||
|
||||
Scale = scale;
|
||||
}
|
||||
|
||||
// Convierte una distancia en metros a píxeles
|
||||
public float MetersToPixels(float meters)
|
||||
{
|
||||
return meters / Scale;
|
||||
}
|
||||
|
||||
// Convierte una distancia en píxeles a metros
|
||||
public float PixelsToMeters(float pixels)
|
||||
{
|
||||
return pixels * Scale;
|
||||
}
|
||||
|
||||
// Configurar o ajustar la escala
|
||||
public void SetScale(float newScale)
|
||||
{
|
||||
if (newScale <= 0)
|
||||
throw new ArgumentException("Scale must be greater than zero.");
|
||||
|
||||
Scale = newScale;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,6 +8,10 @@
|
|||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="motor2.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
|
@ -18,7 +22,12 @@
|
|||
<ItemGroup>
|
||||
<Reference Include="Siemens.Simatic.Simulation.Runtime.Api.x64">
|
||||
<HintPath>C:\Program Files (x86)\Common Files\Siemens\PLCSIMADV\API\6.0\Siemens.Simatic.Simulation.Runtime.Api.x64.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Resource Include="motor2.png" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -23,6 +23,7 @@ using Newtonsoft.Json;
|
|||
using System.Windows.Data;
|
||||
using System.Windows;
|
||||
using static System.Resources.ResXFileRef;
|
||||
using CtrEditor.Convertidores;
|
||||
|
||||
namespace CtrEditor
|
||||
{
|
||||
|
|
|
@ -4,9 +4,14 @@
|
|||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:Siemens="clr-namespace:CtrEditor.Siemens" x:Class="CtrEditor.MainWindow"
|
||||
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
|
||||
Height="900" Width="1600"
|
||||
ResizeMode="CanResize" Title="{Binding directorioTrabajo}">
|
||||
|
||||
<Window.Resources>
|
||||
<convert:FloatToFormattedStringConverter x:Key="floatFormatter"/>
|
||||
</Window.Resources>
|
||||
|
||||
<Window.DataContext>
|
||||
<ctreditor:MainViewModel/>
|
||||
</Window.DataContext>
|
||||
|
@ -69,19 +74,39 @@
|
|||
<!-- Tercera Columna -->
|
||||
<Grid Grid.Column="2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="1*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
<RowDefinition Height="*" />
|
||||
<!-- Altura ajustable para el ListBox -->
|
||||
<RowDefinition Height="Auto" />
|
||||
<!-- Espacio para el GridSplitter -->
|
||||
<RowDefinition Height="*" />
|
||||
<!-- Altura ajustable para el PanelEdicion -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- ListBox -->
|
||||
<ListBox x:Name="ListaOs"
|
||||
Grid.Row="0"
|
||||
Margin="5"
|
||||
ItemsSource="{Binding ObjetosSimulables}" DisplayMemberPath="Nombre"
|
||||
SelectedItem="{Binding SelectedItemOsList, Mode=TwoWay}"
|
||||
SelectionChanged="ListaOs_SelectionChanged"/>
|
||||
<StackPanel x:Name="PanelEdicion" Grid.Row="1" Margin="5">
|
||||
<!-- Aquí puedes agregar los controles para editar propiedades -->
|
||||
</StackPanel>
|
||||
Grid.Row="0"
|
||||
Margin="5"
|
||||
ItemsSource="{Binding ObjetosSimulables}"
|
||||
DisplayMemberPath="Nombre"
|
||||
SelectedItem="{Binding SelectedItemOsList, Mode=TwoWay}"
|
||||
SelectionChanged="ListaOs_SelectionChanged"/>
|
||||
|
||||
<!-- GridSplitter -->
|
||||
<GridSplitter Grid.Row="1"
|
||||
Height="5"
|
||||
HorizontalAlignment="Stretch"
|
||||
Background="Gray"
|
||||
ResizeDirection="Rows"
|
||||
VerticalAlignment="Center"/>
|
||||
|
||||
<!-- PanelEdicion -->
|
||||
<ScrollViewer Grid.Row="2" Margin="5" VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel x:Name="PanelEdicion">
|
||||
<!-- Aquí puedes agregar los controles para editar propiedades -->
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
@ -10,6 +11,7 @@ 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;
|
||||
using Binding = System.Windows.Data.Binding;
|
||||
|
@ -18,6 +20,7 @@ using MouseEventArgs = System.Windows.Input.MouseEventArgs;
|
|||
using TextBox = System.Windows.Controls.TextBox;
|
||||
using UserControl = System.Windows.Controls.UserControl;
|
||||
|
||||
|
||||
namespace CtrEditor
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -405,30 +408,46 @@ namespace CtrEditor
|
|||
|
||||
private void CargarPropiedadesosDatos(osBase selectedObject)
|
||||
{
|
||||
PanelEdicion.Children.Clear(); // Limpiar el panel existente
|
||||
|
||||
// Reflexión para obtener todas las propiedades del objeto seleccionado
|
||||
PanelEdicion.Children.Clear();
|
||||
var properties = selectedObject.GetType().GetProperties();
|
||||
|
||||
foreach (var property in properties)
|
||||
{
|
||||
// Crear un Label y un TextBox para cada propiedad
|
||||
var label = new Label { Content = property.Name };
|
||||
var textBox = new TextBox { Width = 200, Margin = new Thickness(2) };
|
||||
textBox.SetBinding(TextBox.TextProperty, new Binding(property.Name)
|
||||
if (property.PropertyType == typeof(float) || property.PropertyType == typeof(string))
|
||||
{
|
||||
Source = selectedObject,
|
||||
Mode = BindingMode.TwoWay,
|
||||
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
|
||||
});
|
||||
var label = new Label { Content = property.Name };
|
||||
var textBox = new TextBox { Width = 200, Margin = new Thickness(0) };
|
||||
|
||||
// Agregar controles al StackPanel
|
||||
PanelEdicion.Children.Add(label);
|
||||
PanelEdicion.Children.Add(textBox);
|
||||
var binding = new Binding(property.Name)
|
||||
{
|
||||
Source = selectedObject,
|
||||
Mode = BindingMode.TwoWay,
|
||||
UpdateSourceTrigger = UpdateSourceTrigger.LostFocus, // Actualizar solo al perder el foco
|
||||
Converter = (FloatToFormattedStringConverter)Resources["floatFormatter"] // Usar el convertidor
|
||||
};
|
||||
|
||||
// Aplicar el convertidor solo a propiedades float
|
||||
if (property.PropertyType == typeof(float))
|
||||
{
|
||||
textBox.SetBinding(TextBox.TextProperty, binding);
|
||||
}
|
||||
else
|
||||
{
|
||||
textBox.SetBinding(TextBox.TextProperty, new Binding(property.Name)
|
||||
{
|
||||
Source = selectedObject,
|
||||
Mode = BindingMode.TwoWay,
|
||||
UpdateSourceTrigger = UpdateSourceTrigger.LostFocus
|
||||
});
|
||||
}
|
||||
|
||||
PanelEdicion.Children.Add(label);
|
||||
PanelEdicion.Children.Add(textBox);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void MainWindow_Closed(object sender, EventArgs e)
|
||||
{
|
||||
if (DataContext is MainViewModel viewModel)
|
||||
|
@ -438,4 +457,21 @@ namespace CtrEditor
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public class FloatValidationRule : ValidationRule
|
||||
{
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
||||
{
|
||||
// Comprobamos si el valor es nulo o está vacío
|
||||
if (string.IsNullOrEmpty(value?.ToString()))
|
||||
return new ValidationResult(false, "El campo no puede estar vacío.");
|
||||
|
||||
// Intentamos convertir el valor a un tipo float
|
||||
if (float.TryParse(value.ToString(), NumberStyles.Float, cultureInfo, out float result))
|
||||
return ValidationResult.ValidResult; // La validación es exitosa
|
||||
else
|
||||
return new ValidationResult(false, "Ingrese un número válido.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,10 @@ namespace CtrEditor.ObjetosSim
|
|||
return new ucGuia();
|
||||
if (tipoObjeto == typeof(osTransporteGuias))
|
||||
return new ucTransporteGuias();
|
||||
if (tipoObjeto == typeof(osTransporteCurva))
|
||||
return new ucTransporteCurva();
|
||||
if (tipoObjeto == typeof(osVMmotorSim ))
|
||||
return new ucVMmotorSim();
|
||||
|
||||
// Puedes añadir más condiciones para otros tipos
|
||||
|
||||
|
@ -36,6 +40,11 @@ namespace CtrEditor.ObjetosSim
|
|||
return new osGuia();
|
||||
if (tipoObjeto == typeof(osTransporteGuias))
|
||||
return new osTransporteGuias();
|
||||
if (tipoObjeto == typeof(osTransporteCurva))
|
||||
return new osTransporteCurva();
|
||||
if (tipoObjeto == typeof(osVMmotorSim))
|
||||
return new osVMmotorSim();
|
||||
|
||||
|
||||
// Puedes añadir más condiciones para otros tipos
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<UserControl x:Class="CtrEditor.ObjetosSim.UserControls.CircularSegment"
|
||||
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.UserControls"
|
||||
mc:Ignorable="d" Name="circularSegmentControl">
|
||||
<Canvas>
|
||||
<Path Name="path" Stroke="Black" Fill="LightBlue" StrokeThickness="1">
|
||||
<Path.RenderTransform>
|
||||
<RotateTransform Angle="{Binding Angle, ElementName=circularSegmentControl}"/>
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
</Canvas>
|
||||
</UserControl>
|
|
@ -0,0 +1,115 @@
|
|||
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.UserControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CircularSegment.xaml
|
||||
/// </summary>
|
||||
public partial class CircularSegment : UserControl
|
||||
{
|
||||
public double Angle
|
||||
{
|
||||
get { return (double)GetValue(AngleProperty); }
|
||||
set { SetValue(AngleProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty AngleProperty =
|
||||
DependencyProperty.Register("Angle", typeof(double), typeof(CircularSegment), new PropertyMetadata(0.0));
|
||||
|
||||
public double OuterRadius
|
||||
{
|
||||
get { return (double)GetValue(OuterRadiusProperty); }
|
||||
set { SetValue(OuterRadiusProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty OuterRadiusProperty =
|
||||
DependencyProperty.Register("OuterRadius", typeof(double), typeof(CircularSegment), new PropertyMetadata(100.0, OnPropertyChanged));
|
||||
|
||||
public double InnerRadius
|
||||
{
|
||||
get { return (double)GetValue(InnerRadiusProperty); }
|
||||
set { SetValue(InnerRadiusProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty InnerRadiusProperty =
|
||||
DependencyProperty.Register("InnerRadius", typeof(double), typeof(CircularSegment), new PropertyMetadata(80.0, OnPropertyChanged));
|
||||
|
||||
public double StartAngle
|
||||
{
|
||||
get { return (double)GetValue(StartAngleProperty); }
|
||||
set { SetValue(StartAngleProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty StartAngleProperty =
|
||||
DependencyProperty.Register("StartAngle", typeof(double), typeof(CircularSegment), new PropertyMetadata(0.0, OnPropertyChanged));
|
||||
|
||||
public double EndAngle
|
||||
{
|
||||
get { return (double)GetValue(EndAngleProperty); }
|
||||
set { SetValue(EndAngleProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty EndAngleProperty =
|
||||
DependencyProperty.Register("EndAngle", typeof(double), typeof(CircularSegment), new PropertyMetadata(90.0, OnPropertyChanged));
|
||||
|
||||
public CircularSegment()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
(d as CircularSegment)?.DrawSegment();
|
||||
}
|
||||
|
||||
private void DrawSegment()
|
||||
{
|
||||
if (OuterRadius <= 0 || InnerRadius <= 0 || StartAngle == EndAngle)
|
||||
return;
|
||||
|
||||
PathGeometry geometry = new PathGeometry();
|
||||
PathFigure figure = new PathFigure();
|
||||
|
||||
// Calcula el centro del Canvas (suponemos que el Canvas es lo suficientemente grande)
|
||||
Point center = new Point(OuterRadius, OuterRadius);
|
||||
|
||||
// Calcular los puntos de inicio y fin del arco externo
|
||||
Point startPoint = new Point(center.X + Math.Cos(StartAngle * Math.PI / 180) * OuterRadius,
|
||||
center.Y + Math.Sin(StartAngle * Math.PI / 180) * OuterRadius);
|
||||
Point endPoint = new Point(center.X + Math.Cos(EndAngle * Math.PI / 180) * OuterRadius,
|
||||
center.Y + Math.Sin(EndAngle * Math.PI / 180) * OuterRadius);
|
||||
|
||||
// Crear arco externo
|
||||
bool largeArc = Math.Abs(EndAngle - StartAngle) > 180.0;
|
||||
figure.StartPoint = startPoint;
|
||||
figure.Segments.Add(new ArcSegment(endPoint, new Size(OuterRadius, OuterRadius), 0, largeArc, SweepDirection.Clockwise, true));
|
||||
|
||||
// Crear línea hacia el arco interno
|
||||
figure.Segments.Add(new LineSegment(new Point(center.X + Math.Cos(EndAngle * Math.PI / 180) * InnerRadius,
|
||||
center.Y + Math.Sin(EndAngle * Math.PI / 180) * InnerRadius), true));
|
||||
|
||||
// Crear arco interno
|
||||
startPoint = new Point(center.X + Math.Cos(StartAngle * Math.PI / 180) * InnerRadius,
|
||||
center.Y + Math.Sin(StartAngle * Math.PI / 180) * InnerRadius);
|
||||
figure.Segments.Add(new ArcSegment(startPoint, new Size(InnerRadius, InnerRadius), 0, largeArc, SweepDirection.Counterclockwise, true));
|
||||
|
||||
// Cerrar la figura
|
||||
figure.IsClosed = true;
|
||||
geometry.Figures.Add(figure);
|
||||
path.Data = geometry;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ using System.Windows;
|
|||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using CtrEditor.Convertidores;
|
||||
|
||||
namespace CtrEditor.ObjetosSim
|
||||
{
|
||||
|
@ -90,103 +91,7 @@ namespace CtrEditor.ObjetosSim
|
|||
}
|
||||
}
|
||||
|
||||
public class PixelToMeter
|
||||
{
|
||||
// Instancia privada estática, parte del patrón Singleton
|
||||
private static PixelToMeter? _instance;
|
||||
public UnitConverter calc = new UnitConverter(0.01f);
|
||||
|
||||
// Propiedad pública estática para acceder a la instancia
|
||||
public static PixelToMeter Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new PixelToMeter();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MeterToPixelConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
float meters = (float)value;
|
||||
float factor = 1;
|
||||
if (parameter != null)
|
||||
if (parameter.ToString() == "0.5") factor = 0.5f;
|
||||
else if (parameter.ToString() == "-0.5") factor = -0.5f;
|
||||
|
||||
return PixelToMeter.Instance.calc.MetersToPixels(meters) * factor;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
float pixels = (float)value;
|
||||
float factor = 1;
|
||||
if (parameter != null)
|
||||
if (parameter.ToString() == "0.5") factor = 0.5f;
|
||||
else if (parameter.ToString() == "-0.5") factor = -0.5f;
|
||||
|
||||
return PixelToMeter.Instance.calc.PixelsToMeters(pixels) * factor;
|
||||
}
|
||||
}
|
||||
|
||||
public class DistanceToMarginConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is double distance)
|
||||
{
|
||||
return new Thickness(0, 0, 0, PixelToMeter.Instance.calc.MetersToPixels((float)distance)); // Ajustar Bottom a 'distance'
|
||||
}
|
||||
return new Thickness();
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException("ConvertBack is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
public class UnitConverter
|
||||
{
|
||||
// La escala representa cuántos metros hay en un píxel
|
||||
public float Scale { get; private set; }
|
||||
|
||||
|
||||
public UnitConverter(float scale)
|
||||
{
|
||||
if (scale <= 0)
|
||||
throw new ArgumentException("Scale must be greater than zero.");
|
||||
|
||||
Scale = scale;
|
||||
}
|
||||
|
||||
// Convierte una distancia en metros a píxeles
|
||||
public float MetersToPixels(float meters)
|
||||
{
|
||||
return meters / Scale;
|
||||
}
|
||||
|
||||
// Convierte una distancia en píxeles a metros
|
||||
public float PixelsToMeters(float pixels)
|
||||
{
|
||||
return pixels * Scale;
|
||||
}
|
||||
|
||||
// Configurar o ajustar la escala
|
||||
public void SetScale(float newScale)
|
||||
{
|
||||
if (newScale <= 0)
|
||||
throw new ArgumentException("Scale must be greater than zero.");
|
||||
|
||||
Scale = newScale;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<UserControl x:Class="CtrEditor.ObjetosSim.ucBotella"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:CtrEditor.ObjetosSim">
|
||||
xmlns:convert="clr-namespace:CtrEditor.Convertidores">
|
||||
<UserControl.Resources>
|
||||
<local:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
|
||||
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
|
||||
</UserControl.Resources>
|
||||
<Ellipse Height="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}"
|
||||
Stroke="red" Fill="Gray"
|
||||
|
|
|
@ -13,6 +13,7 @@ using System.Windows.Media.Imaging;
|
|||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Numerics;
|
||||
using CtrEditor.Convertidores;
|
||||
|
||||
namespace CtrEditor.ObjetosSim
|
||||
{
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
xmlns:local="clr-namespace:CtrEditor.ObjetosSim">
|
||||
xmlns:convert="clr-namespace:CtrEditor.Convertidores">
|
||||
|
||||
<UserControl.Resources>
|
||||
<local:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
|
||||
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Canvas>
|
||||
|
|
|
@ -12,6 +12,7 @@ using System.Windows.Media;
|
|||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using CtrEditor.Convertidores;
|
||||
|
||||
namespace CtrEditor.ObjetosSim
|
||||
{
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<UserControl x:Class="CtrEditor.ObjetosSim.ucTransporteCurva"
|
||||
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:localuc="clr-namespace:CtrEditor.ObjetosSim.UserControls"
|
||||
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
|
||||
</UserControl.Resources>
|
||||
<Canvas>
|
||||
<localuc:CircularSegment Angle="{Binding Angulo}" OuterRadius="{Binding RadioExterno, Converter={StaticResource MeterToPixelConverter}}" InnerRadius="{Binding RadioInterno, Converter={StaticResource MeterToPixelConverter}}"
|
||||
StartAngle="0" EndAngle="90" />
|
||||
</Canvas>
|
||||
</UserControl>
|
|
@ -0,0 +1,168 @@
|
|||
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;
|
||||
using CtrEditor.Convertidores;
|
||||
|
||||
namespace CtrEditor.ObjetosSim
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ucTransporteCurva.xaml
|
||||
/// </summary>
|
||||
public class osTransporteCurva : osBase
|
||||
{
|
||||
private string _nombre = "Transporte Curva";
|
||||
|
||||
private float frictionCoefficient;
|
||||
private float velMax50hz; // en metros por minuto
|
||||
private float tiempoRampa;
|
||||
private bool esMarcha;
|
||||
|
||||
private Rectangle Geometria = new Rectangle();
|
||||
|
||||
public override float Left
|
||||
{
|
||||
get => Geometria.Left;
|
||||
set
|
||||
{
|
||||
Geometria.Left = value;
|
||||
CanvasSetLeftinMeter(value);
|
||||
OnPropertyChanged(nameof(Left));
|
||||
}
|
||||
}
|
||||
public override float Top
|
||||
{
|
||||
get => Geometria.Top;
|
||||
set
|
||||
{
|
||||
Geometria.Top = value;
|
||||
CanvasSetTopinMeter(value);
|
||||
OnPropertyChanged(nameof(Top));
|
||||
}
|
||||
}
|
||||
|
||||
public float RadioExterno
|
||||
{
|
||||
get => Geometria.Length;
|
||||
set
|
||||
{
|
||||
Geometria.Length = value;
|
||||
OnPropertyChanged(nameof(RadioExterno));
|
||||
}
|
||||
}
|
||||
public float RadioInterno
|
||||
{
|
||||
get => Geometria.Width;
|
||||
set
|
||||
{
|
||||
Geometria.Width = value;
|
||||
OnPropertyChanged(nameof(RadioInterno));
|
||||
}
|
||||
}
|
||||
|
||||
public float Angulo
|
||||
{
|
||||
get => Geometria.Angle;
|
||||
set
|
||||
{
|
||||
Geometria.Angle = value;
|
||||
OnPropertyChanged(nameof(Angulo));
|
||||
}
|
||||
}
|
||||
public float VelocidadActual
|
||||
{
|
||||
get => Geometria.Speed;
|
||||
set
|
||||
{
|
||||
Geometria.Speed = value;
|
||||
OnPropertyChanged(nameof(VelocidadActual));
|
||||
}
|
||||
}
|
||||
|
||||
public override string Nombre
|
||||
{
|
||||
get => _nombre;
|
||||
set
|
||||
{
|
||||
if (_nombre != value)
|
||||
{
|
||||
_nombre = value;
|
||||
OnPropertyChanged(nameof(Nombre));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float FrictionCoefficient { get => frictionCoefficient; set => frictionCoefficient = value; }
|
||||
public float VelMax50hz { get => velMax50hz; set => velMax50hz = value; }
|
||||
public float TiempoRampa { get => tiempoRampa; set => tiempoRampa = value; }
|
||||
public bool EsMarcha { get => esMarcha; set => esMarcha = value; }
|
||||
|
||||
public osTransporteCurva()
|
||||
{
|
||||
RadioExterno = 2;
|
||||
RadioInterno = 1;
|
||||
}
|
||||
|
||||
public override void ConnectSimManager(SimulationManager simulationManager)
|
||||
{
|
||||
simulationManager.rectangles.Add(Geometria);
|
||||
}
|
||||
public override void UpdateGeometry()
|
||||
{
|
||||
// Se llama antes de la simulacion
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateControl()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class ucTransporteCurva : UserControl, IDataContainer
|
||||
{
|
||||
public osBase? Datos { get; set; }
|
||||
|
||||
public ucTransporteCurva()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public void Resize(float width, float height)
|
||||
{
|
||||
if (Datos is osTransporteCurva datos)
|
||||
datos.RadioExterno = 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 osTransporteCurva datos)
|
||||
datos.Angulo = Angle;
|
||||
}
|
||||
public void Highlight(bool State) { }
|
||||
public int ZIndex()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -3,12 +3,12 @@
|
|||
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"
|
||||
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<UserControl.Resources>
|
||||
<local:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
|
||||
<local:DistanceToMarginConverter x:Key="DistanceToMarginConverter"/>
|
||||
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
|
||||
<convert:DistanceToMarginConverter x:Key="DistanceToMarginConverter"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
|
|
|
@ -12,6 +12,7 @@ using System.Windows.Media;
|
|||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using CtrEditor.Convertidores;
|
||||
|
||||
namespace CtrEditor.ObjetosSim
|
||||
{
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
xmlns:local="clr-namespace:CtrEditor.ObjetosSim">
|
||||
xmlns:convert="clr-namespace:CtrEditor.Convertidores">
|
||||
|
||||
<UserControl.Resources>
|
||||
<local:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
|
||||
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Canvas>
|
||||
|
|
|
@ -15,6 +15,7 @@ using System.Windows.Shapes;
|
|||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using System.Numerics;
|
||||
using System.Windows.Markup;
|
||||
using CtrEditor.Convertidores;
|
||||
|
||||
namespace CtrEditor.ObjetosSim
|
||||
{
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<UserControl x:Class="CtrEditor.ObjetosSim.ucVMmotorSim"
|
||||
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>
|
||||
<Image Source="/motor2.png"
|
||||
Width="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}}"
|
||||
Height="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}}"
|
||||
Stretch="Uniform"/>
|
||||
</Grid>
|
||||
|
||||
</UserControl>
|
|
@ -0,0 +1,132 @@
|
|||
using CtrEditor.Convertidores;
|
||||
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 ucVMmotorSim.xaml
|
||||
/// </summary>
|
||||
public class osVMmotorSim : osBase
|
||||
{
|
||||
|
||||
|
||||
// Otros datos y métodos relevantes para la simulación
|
||||
|
||||
private string _nombre = "VetroMeccanica Motor";
|
||||
private float _tamano;
|
||||
private float _left;
|
||||
private float _top;
|
||||
private float _numeroMotor;
|
||||
|
||||
public float Tamano
|
||||
{
|
||||
get => _tamano;
|
||||
set
|
||||
{
|
||||
_tamano = value;
|
||||
OnPropertyChanged(nameof(Tamano));
|
||||
}
|
||||
}
|
||||
|
||||
public float PLC_NumeroMotor
|
||||
{
|
||||
get => _numeroMotor;
|
||||
set
|
||||
{
|
||||
_numeroMotor = value;
|
||||
OnPropertyChanged(nameof(PLC_NumeroMotor));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 override string Nombre
|
||||
{
|
||||
get => _nombre;
|
||||
set
|
||||
{
|
||||
if (_nombre != value)
|
||||
{
|
||||
_nombre = value;
|
||||
OnPropertyChanged(nameof(Nombre));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public osVMmotorSim()
|
||||
{
|
||||
Tamano = 0.30f;
|
||||
}
|
||||
|
||||
public override void ConnectSimManager(SimulationManager simulationManager)
|
||||
{
|
||||
}
|
||||
public override void UpdateGeometry()
|
||||
{
|
||||
// Se llama antes de la simulacion
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateControl()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ucVMmotorSim : UserControl, IDataContainer
|
||||
{
|
||||
public osBase? Datos { get; set; }
|
||||
|
||||
public ucVMmotorSim()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public void Resize(float width, float height) { }
|
||||
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) { }
|
||||
public void Highlight(bool State) { }
|
||||
public int ZIndex()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Loading…
Reference in New Issue