Compare commits

...

2 Commits

Author SHA1 Message Date
Miguel c1ac20964e TransporteUnion Terminado 2024-05-31 19:25:24 +02:00
Miguel 268b66ad76 Creando GuiasUnion 2024-05-31 15:06:49 +02:00
58 changed files with 947 additions and 241 deletions

View File

@ -3,7 +3,18 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CtrEditor" xmlns:local="clr-namespace:CtrEditor"
StartupUri="MainWindow.xaml"> StartupUri="MainWindow.xaml">
<Application.Resources> <Application.Resources>
<local:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
<local:LevelToHeightMultiConverter x:Key="LevelToHeightMultiConverter"/>
<local:WidthPercentageConverter x:Key="WidthPercentageConverter"/>
<local:DistanceToMarginConverter x:Key="DistanceToMarginConverter"/>
<local:MarginConverter x:Key="MarginConverter"/>
<local:FloatToFormattedStringConverter x:Key="floatFormatter"/>
<local:DoubleToFormattedStringConverter x:Key="doubleFormatter"/>
<local:BrushToColorNameConverter x:Key="BrushToColorNameConverter"/>
<local:VerticalPositionConverter x:Key="VerticalPositionConverter"/>
<local:SumConverter x:Key="SumConverter" />
</Application.Resources> </Application.Resources>
</Application> </Application>

View File

@ -6,9 +6,15 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>True</Optimize>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="ObjetosSim\ucBasicExample.xaml.cs" />
<Compile Remove="ObjetosSim\ucTransporteCurva.xaml.cs" /> <Compile Remove="ObjetosSim\ucTransporteCurva.xaml.cs" />
<Compile Remove="Simulacion\FPhysics.cs" /> <Compile Remove="Simulacion\FPhysics.cs" />
<Compile Remove="Simulacion\GeometrySimulator.cs" /> <Compile Remove="Simulacion\GeometrySimulator.cs" />
@ -41,10 +47,13 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Remove="ObjetosSim\ucBasicExample.xaml" />
<Page Remove="ObjetosSim\ucTransporteCurva.xaml" /> <Page Remove="ObjetosSim\ucTransporteCurva.xaml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="ObjetosSim\ucBasicExample.xaml" />
<None Include="ObjetosSim\ucBasicExample.xaml.cs" />
<None Include="Simulacion\FPhysics.cs" /> <None Include="Simulacion\FPhysics.cs" />
<None Include="Simulacion\GeometrySimulator.cs" /> <None Include="Simulacion\GeometrySimulator.cs" />
</ItemGroup> </ItemGroup>
@ -52,7 +61,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Aether.Physics2D" Version="2.1.0" /> <PackageReference Include="Aether.Physics2D" Version="2.1.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="FarseerPhysics" Version="3.5.0" />
<PackageReference Include="LiveChartsCore.SkiaSharpView.WPF" Version="2.0.0-rc2" /> <PackageReference Include="LiveChartsCore.SkiaSharpView.WPF" Version="2.0.0-rc2" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" /> <PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
@ -88,4 +96,19 @@
<Resource Include="imagenes\tank.png" /> <Resource Include="imagenes\tank.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project> </Project>

View File

@ -10,7 +10,6 @@ using CtrEditor.Siemens;
using System.IO; using System.IO;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Windows; using System.Windows;
using CtrEditor.Convertidores;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
@ -34,6 +33,8 @@ namespace CtrEditor
private readonly DispatcherTimer _timerSimulacion; private readonly DispatcherTimer _timerSimulacion;
public Canvas MainCanvas;
[ObservableProperty] [ObservableProperty]
private DatosDeTrabajo datosDeTrabajo; private DatosDeTrabajo datosDeTrabajo;
@ -357,7 +358,7 @@ namespace CtrEditor
stopwatch_SimModel_last = stopwatch_Sim.Elapsed.TotalMilliseconds; stopwatch_SimModel_last = stopwatch_Sim.Elapsed.TotalMilliseconds;
// Eliminar el diseño de Debug luego de 2 segundos // Eliminar el diseño de Debug luego de 2 segundos
if (TiempoDesdeStartSimulacion > 2000) if (TiempoDesdeStartSimulacion > 12000)
simulationManager.Debug_ClearSimulationShapes(); simulationManager.Debug_ClearSimulationShapes();
else else
TiempoDesdeStartSimulacion += (float)elapsedMilliseconds; TiempoDesdeStartSimulacion += (float)elapsedMilliseconds;

View File

@ -4,7 +4,6 @@
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Siemens="clr-namespace:CtrEditor.Siemens" xmlns:Siemens="clr-namespace:CtrEditor.Siemens"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
xmlns:ObjetosSim="clr-namespace:CtrEditor.ObjetosSim" x:Class="CtrEditor.MainWindow" xmlns:ObjetosSim="clr-namespace:CtrEditor.ObjetosSim" x:Class="CtrEditor.MainWindow"
Height="900" Width="1600" WindowState="Maximized" Height="900" Width="1600" WindowState="Maximized"
ResizeMode="CanResize" Title="{Binding directorioTrabajo}" Icon="/app2.png"> ResizeMode="CanResize" Title="{Binding directorioTrabajo}" Icon="/app2.png">
@ -14,9 +13,7 @@
</Window.DataContext> </Window.DataContext>
<Window.Resources> <Window.Resources>
<convert:FloatToFormattedStringConverter x:Key="floatFormatter"/>
<convert:DoubleToFormattedStringConverter x:Key="doubleFormatter"/>
<convert:BrushToColorNameConverter x:Key="BrushToColorNameConverter"/>
<!-- Style for Start/Stop Button --> <!-- Style for Start/Stop Button -->
<Style x:Key="StartStopButtonStyle" TargetType="Button"> <Style x:Key="StartStopButtonStyle" TargetType="Button">

View File

@ -10,7 +10,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using static System.Runtime.InteropServices.JavaScript.JSType; using static System.Runtime.InteropServices.JavaScript.JSType;
using Binding = System.Windows.Data.Binding; using Binding = System.Windows.Data.Binding;
@ -65,6 +65,7 @@ namespace CtrEditor
viewModel.ImageSelected += ViewModel_ImageSelected; viewModel.ImageSelected += ViewModel_ImageSelected;
viewModel?.LoadInitialData(); // Carga la primera imagen por defecto una vez cargada la ventana principal viewModel?.LoadInitialData(); // Carga la primera imagen por defecto una vez cargada la ventana principal
viewModel.simulationManager.DebugCanvas = ImagenEnTrabajoCanvas; viewModel.simulationManager.DebugCanvas = ImagenEnTrabajoCanvas;
viewModel.MainCanvas = ImagenEnTrabajoCanvas;
} }
} }

View File

@ -2,11 +2,7 @@
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:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> >
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osBotella/> <vm:osBotella/>

View File

@ -1,7 +1,7 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
//using using Microsoft.Xna.Framework; //using using Microsoft.Xna.Framework;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;

View File

@ -1,15 +1,10 @@
<UserControl x:Class="CtrEditor.ObjetosSim.Dinamicos.ucBotellaCuello" <UserControl x:Class="CtrEditor.ObjetosSim.ucBotellaCuello"
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:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim">
xmlns:convert="clr-namespace:CtrEditor.Convertidores">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osBotella/> <vm:osBotellaCuello/>
</UserControl.DataContext> </UserControl.DataContext>
<Ellipse Height="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}" <Ellipse Height="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}"

View File

@ -1,14 +1,14 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
//using using Microsoft.Xna.Framework; //using using Microsoft.Xna.Framework;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using nkast.Aether.Physics2D.Common; using nkast.Aether.Physics2D.Common;
using System.Windows.Media; using System.Windows.Media;
namespace CtrEditor.ObjetosSim.Dinamicos namespace CtrEditor.ObjetosSim
{ {
/// <summary> /// <summary>
/// Interaction logic for ucBotellaCuelloCuello.xaml /// Interaction logic for ucBotellaCuelloCuello.xaml

View File

@ -3,14 +3,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"> xmlns:vm="clr-namespace:CtrEditor.ObjetosSim">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osFiller/> <vm:osFiller/>

View File

@ -1,4 +1,4 @@
using CtrEditor.Convertidores; 
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;

View File

@ -3,16 +3,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> mc:Ignorable="d">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
<convert:LevelToHeightMultiConverter x:Key="LevelToHeightMultiConverter"/>
<convert:WidthPercentageConverter x:Key="WidthPercentageConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osTanque Alto="1" Ancho="1" Angulo="-4" /> <vm:osTanque Alto="1" Ancho="1" Angulo="-4" />

View File

@ -1,5 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;

View File

@ -4,11 +4,10 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim" xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> mc:Ignorable="d">
<UserControl.Resources> <UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
<Storyboard x:Key="PulsingStoryboard" RepeatBehavior="Forever"> <Storyboard x:Key="PulsingStoryboard" RepeatBehavior="Forever">
<DoubleAnimation <DoubleAnimation
Storyboard.TargetName="AnimatedEllipse" Storyboard.TargetName="AnimatedEllipse"

View File

@ -1,4 +1,4 @@
using CtrEditor.Convertidores; 
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using System.Windows; using System.Windows;

View File

@ -4,12 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim">
xmlns:convert="clr-namespace:CtrEditor.Convertidores">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osGuia/> <vm:osGuia/>

View File

@ -1,7 +1,7 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;

View File

@ -4,12 +4,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:localuc="clr-namespace:CtrEditor.ObjetosSim.UserControls" xmlns:localuc="clr-namespace:CtrEditor.ObjetosSim.UserControls"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"> mc:Ignorable="d">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osTransporteCurva /> <vm:osTransporteCurva />

View File

@ -1,7 +1,7 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;

View File

@ -4,13 +4,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
mc:Ignorable="d"> mc:Ignorable="d">
<UserControl.Resources> <UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
<convert:DistanceToMarginConverter x:Key="DistanceToMarginConverter"/>
<!-- Define the VisualBrush for the conveyor belt pattern --> <!-- Define the VisualBrush for the conveyor belt pattern -->
<VisualBrush x:Key="BeltBrush" TileMode="Tile" Viewport="0,0,20,10" ViewportUnits="Absolute" Viewbox="0,0,20,10" ViewboxUnits="Absolute"> <VisualBrush x:Key="BeltBrush" TileMode="Tile" Viewport="0,0,20,10" ViewportUnits="Absolute" Viewbox="0,0,20,10" ViewboxUnits="Absolute">
<VisualBrush.Transform> <VisualBrush.Transform>

View File

@ -1,7 +1,6 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;

View File

@ -0,0 +1,86 @@
<UserControl x:Class="CtrEditor.ObjetosSim.ucTransporteGuiasUnion"
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:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:uc="clr-namespace:CtrEditor.ObjetosSim.UserControls"
mc:Ignorable="d">
<UserControl.Resources>
<!-- Define the VisualBrush for the conveyor belt pattern -->
<VisualBrush x:Key="BeltBrushA" TileMode="Tile" Viewport="0,0,20,10" ViewportUnits="Absolute" Viewbox="0,0,20,10" ViewboxUnits="Absolute">
<VisualBrush.Transform>
<TransformGroup>
<TranslateTransform/>
</TransformGroup>
</VisualBrush.Transform>
<VisualBrush.Visual>
<Canvas>
<Rectangle Fill="#FFBFBFBF" Width="10" Height="10"/>
<Rectangle Fill="LightGray" Width="10" Height="10" Canvas.Left="10"/>
</Canvas>
</VisualBrush.Visual>
</VisualBrush>
<VisualBrush x:Key="BeltBrushB" TileMode="Tile" Viewport="0,0,20,10" ViewportUnits="Absolute" Viewbox="0,0,20,10" ViewboxUnits="Absolute">
<VisualBrush.Transform>
<TransformGroup>
<TranslateTransform/>
</TransformGroup>
</VisualBrush.Transform>
<VisualBrush.Visual>
<Canvas>
<Rectangle Fill="#FFBFBFBF" Width="10" Height="10"/>
<Rectangle Fill="LightGray" Width="10" Height="10" Canvas.Left="10"/>
</Canvas>
</VisualBrush.Visual>
</VisualBrush>
</UserControl.Resources>
<UserControl.DataContext>
<vm:osTransporteGuiasUnion/>
</UserControl.DataContext>
<Grid>
<Canvas x:Name="Canvas" RenderTransformOrigin="0,0">
<Canvas.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="{Binding Angulo}"/>
<TranslateTransform/>
</TransformGroup>
</Canvas.RenderTransform>
<Rectangle x:Name="TransporteA" Width="{Binding AnchoTransporte_oculto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}}"
Fill="{StaticResource BeltBrushA}"
/>
<Rectangle x:Name="TransporteB" Width="{Binding AnchoTransporte_oculto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}}"
Fill="{StaticResource BeltBrushB}"
Canvas.Top="{Binding Alto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1.05}"
Canvas.Left="{Binding AnchoRecto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
/>
<uc:ThreeLinesControl x:Name="GuiaSuperior" AnchoRecto="{Binding AnchoRecto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
AnchoCentro="{Binding AnchoCentral, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
Altura="{Binding Alto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
AltoGuia="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
Canvas.Top="{Binding Distance, Converter={StaticResource MeterToPixelConverter},ConverterParameter=-1}"
/>
<uc:ThreeLinesControl x:Name="GuiaInferior" AnchoRecto="{Binding AnchoRecto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
AnchoCentro="{Binding AnchoCentral, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
Altura="{Binding Alto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
AltoGuia="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}">
<Canvas.Top>
<MultiBinding Converter="{StaticResource SumConverter}">
<Binding Path="Alto" Converter="{StaticResource MeterToPixelConverter}" ConverterParameter="1.0" />
<Binding Path="Distance" Converter="{StaticResource MeterToPixelConverter}" ConverterParameter="1.0" />
</MultiBinding>
</Canvas.Top>
</uc:ThreeLinesControl>
</Canvas>
</Grid>
</UserControl>

View File

@ -0,0 +1,375 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Siemens;
using CtrEditor.Simulacion;
using SkiaSharp;
namespace CtrEditor.ObjetosSim
{
/// <summary>
/// Interaction logic for ucTransporteGuiasUnion.xaml
/// </summary>
public partial class osTransporteGuiasUnion : osBase, IosBase
{
private osBase _osMotorA = null;
private osBase _osMotorB = null;
Dictionary<Rectangle, simTransporte> SimGeometriaT;
Dictionary<Rectangle, simGuia> SimGeometriaG;
Dictionary<Rectangle, Storyboard> Storyboards;
Dictionary<Rectangle, BoolReference> TransportsDirection;
Dictionary<Rectangle, FloatReference> TransportsVelocidad;
public static string NombreClase()
{
return "Transporte Guias Union";
}
private string nombre = NombreClase();
public override string Nombre
{
get => nombre;
set => SetProperty(ref nombre, value);
}
[ObservableProperty]
public string motorA;
partial void OnMotorAChanged(string value)
{
_osMotorA = ObtenerLink(MotorA, typeof(osVMmotorSim));
}
[ObservableProperty]
public float velocidadActualA;
partial void OnVelocidadActualAChanged(float value)
{
if (_visualRepresentation is ucTransporteGuiasUnion uc)
{
var transporte = uc.TransporteA;
SetSpeed(transporte);
}
}
[ObservableProperty]
bool invertirDireccionA;
partial void OnInvertirDireccionAChanged(bool value)
{
if (_visualRepresentation is ucTransporteGuiasUnion uc)
{
var transporte = uc.TransporteA;
SetSpeed(transporte);
ActualizarStoryboards(transporte);
}
}
[ObservableProperty]
public string motorB;
partial void OnMotorBChanged(string value)
{
_osMotorB = ObtenerLink(MotorB, typeof(osVMmotorSim));
}
[ObservableProperty]
public float velocidadActualB;
partial void OnVelocidadActualBChanged(float value)
{
if (_visualRepresentation is ucTransporteGuiasUnion uc)
{
var transporte = uc.TransporteB;
SetSpeed(transporte);
}
}
[ObservableProperty]
bool invertirDireccionB;
partial void OnInvertirDireccionBChanged(bool value)
{
if (_visualRepresentation is ucTransporteGuiasUnion uc)
{
var transporte = uc.TransporteB;
SetSpeed(transporte);
ActualizarStoryboards(transporte);
}
}
[ObservableProperty]
public float anchoRecto;
[ObservableProperty]
public float anchoCentral;
partial void OnAnchoRectoChanged(float value)
{
AnchoTransporte_oculto = anchoRecto + anchoCentral;
}
partial void OnAnchoCentralChanged(float value)
{
AnchoTransporte_oculto = anchoRecto + anchoCentral;
}
[ObservableProperty]
public float anchoTransporte_oculto;
[ObservableProperty]
public float alto;
partial void OnAltoChanged(float value)
{
// ActualizarGeometrias();
}
[ObservableProperty]
public float angulo;
[ObservableProperty]
public float frictionCoefficient;
[ObservableProperty]
public float velMax50hz;
[ObservableProperty]
public float tiempoRampa;
[ObservableProperty]
public bool esMarcha;
[ObservableProperty]
private float distance;
[ObservableProperty]
private float altoGuia;
void ActualizarStoryboards(Rectangle transporte)
{
if (!Storyboards.Keys.Contains(transporte)) return;
var direccion = TransportsDirection[transporte].Value;
var velocidad = TransportsVelocidad[transporte].Value;
Storyboards[transporte] = CrearAnimacionMultiStoryBoardTrasnporte(Storyboards[transporte], transporte, direccion);
ActualizarAnimacionMultiStoryBoardTransporte(Storyboards[transporte], velocidad);
}
void SetSpeed(Rectangle transporte)
{
if (!Storyboards.Keys.Contains(transporte)) return;
var invertirDireccion = TransportsDirection[transporte].Value;
var velocidad = TransportsVelocidad[transporte].Value;
if (invertirDireccion)
SimGeometriaT[transporte]?.SetSpeed(-velocidad);
else
SimGeometriaT[transporte]?.SetSpeed(velocidad);
ActualizarAnimacionMultiStoryBoardTransporte(Storyboards[transporte], velocidad);
}
private void ActualizarGeometrias()
{
if (_visualRepresentation is ucTransporteGuiasUnion uc)
{
foreach (var transporte in SimGeometriaT)
{
UpdateRectangle(transporte.Value, transporte.Key, Alto, AnchoTransporte_oculto, Angulo);
ActualizarStoryboards(transporte.Key);
SetSpeed(transporte.Key);
}
foreach (var l in SimGeometriaG)
UpdateOrCreateLine(l.Value, l.Key);
}
}
public osTransporteGuiasUnion()
{
AnchoRecto = 0.5f;
AnchoCentral = 0.5f;
Alto = 0.10f;
AltoGuia = 0.03f;
Distance = 0.02f;
SimGeometriaT = new Dictionary<Rectangle, simTransporte>();
SimGeometriaG = new Dictionary<Rectangle, simGuia>();
Storyboards = new Dictionary<Rectangle, Storyboard>();
TransportsDirection = new Dictionary<Rectangle, BoolReference>();
TransportsVelocidad = new Dictionary<Rectangle, FloatReference>();
}
public override void UpdateGeometryStart()
{
// Se llama antes de la simulacion
ActualizarGeometrias();
}
public override void SimulationStop()
{
// Se llama al detener la simulacion
if (_visualRepresentation is ucTransporteGuiasUnion uc)
{
SetSpeed(uc.TransporteB);
SetSpeed(uc.TransporteA);
}
}
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{
if (_osMotorA != null)
{
if (_osMotorA is osVMmotorSim motor)
VelocidadActualA = motor.Velocidad;
}
else if (MotorA.Length > 0)
_osMotorA = ObtenerLink(MotorA, typeof(osVMmotorSim));
if (_osMotorB != null)
{
if (_osMotorB is osVMmotorSim motor)
VelocidadActualB = motor.Velocidad;
}
else if (MotorB.Length > 0)
_osMotorB = ObtenerLink(MotorB, typeof(osVMmotorSim));
}
public override void ucLoaded()
{
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion
ActualizarLeftTop();
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion
if (_visualRepresentation is ucTransporteGuiasUnion uc)
{
foreach (var child in uc.Canvas.Children)
if (child is Rectangle rect)
if (rect.Name.StartsWith("Transporte"))
{
SimGeometriaT.Add(rect,AddRectangle(simulationManager, rect, Alto, AnchoTransporte_oculto, Angulo));
Storyboards.Add(rect,CrearAnimacionMultiStoryBoardTrasnporte(rect,false));
}
foreach (var child in uc.GuiaSuperior.Canvas.Children)
if (child is Rectangle rect)
SimGeometriaG.Add(rect, AddLine(simulationManager, rect));
foreach (var child in uc.GuiaInferior.Canvas.Children)
if (child is Rectangle rect)
SimGeometriaG.Add(rect, AddLine(simulationManager, rect));
TransportsDirection.Add(uc.TransporteA, new BoolReference(() => InvertirDireccionA, value => InvertirDireccionA = value));
TransportsDirection.Add(uc.TransporteB, new BoolReference(() => InvertirDireccionB, value => InvertirDireccionB = value));
TransportsVelocidad.Add(uc.TransporteA, new FloatReference(() => VelocidadActualA, value => VelocidadActualA = value));
TransportsVelocidad.Add(uc.TransporteB, new FloatReference(() => VelocidadActualB, value => VelocidadActualB = value));
}
OnMotorAChanged(MotorA);
}
public override void ucUnLoaded()
{
// El UserControl se esta eliminando
// eliminar el objeto de simulacion
foreach (var s in SimGeometriaT)
simulationManager.Remove(s.Value);
foreach (var s in SimGeometriaG)
simulationManager.Remove(s.Value);
}
}
public class BoolReference
{
private Func<bool> getter;
private Action<bool> setter;
public BoolReference(Func<bool> getter, Action<bool> setter)
{
this.getter = getter;
this.setter = setter;
}
public bool Value
{
get => getter();
set => setter(value);
}
}
public class FloatReference
{
private Func<float> getter;
private Action<float> setter;
public FloatReference(Func<float> getter, Action<float> setter)
{
this.getter = getter;
this.setter = setter;
}
public float Value
{
get => getter();
set => setter(value);
}
}
public partial class ucTransporteGuiasUnion : UserControl, IDataContainer
{
public osBase? Datos { get; set; }
public ucTransporteGuiasUnion()
{
InitializeComponent();
this.Loaded += OnLoaded;
this.Unloaded += OnUnloaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
Datos?.ucLoaded();
}
private void OnUnloaded(object sender, RoutedEventArgs e)
{
Datos?.ucUnLoaded();
}
public void Resize(float width, float height)
{
if (Datos is osTransporteGuiasUnion datos)
datos.AnchoRecto = 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 osTransporteGuiasUnion datos)
datos.Angulo = Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
{
return 1;
}
}
}

View File

@ -4,13 +4,10 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> mc:Ignorable="d">
<UserControl.Resources> <UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
<!-- Define the VisualBrush for the conveyor belt pattern --> <!-- Define the VisualBrush for the conveyor belt pattern -->
<VisualBrush x:Key="BeltBrush" TileMode="Tile" Viewport="0,0,20,10" ViewportUnits="Absolute" Viewbox="0,0,20,10" ViewboxUnits="Absolute"> <VisualBrush x:Key="BeltBrush" TileMode="Tile" Viewport="0,0,20,10" ViewportUnits="Absolute" Viewbox="0,0,20,10" ViewboxUnits="Absolute">
<VisualBrush.Transform> <VisualBrush.Transform>

View File

@ -3,7 +3,7 @@ using System.Windows.Controls;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
using System.Windows.Media; using System.Windows.Media;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using System.Windows.Input; using System.Windows.Input;

View File

@ -4,13 +4,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim" xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> mc:Ignorable="d">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osVMmotorSim ImageSource_oculta="/imagenes/motorNegro.png" /> <vm:osVMmotorSim ImageSource_oculta="/imagenes/motorNegro.png" />

View File

@ -1,4 +1,4 @@
using CtrEditor.Convertidores; 
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;

View File

@ -5,14 +5,9 @@
xmlns:ei="http://schemas.microsoft.com/xaml/behaviors" xmlns:ei="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"> mc:Ignorable="d">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osBoton Color="#FFADE6C0" ColorButton_oculto="#FFC72323"/> <vm:osBoton Color="#FFADE6C0" ColorButton_oculto="#FFC72323"/>
</UserControl.DataContext> </UserControl.DataContext>

View File

@ -1,5 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;

View File

@ -4,13 +4,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim.UserControls" xmlns:local="clr-namespace:CtrEditor.ObjetosSim.UserControls"
mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> mc:Ignorable="d">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osGearEncoder Dientes="9"/> <vm:osGearEncoder Dientes="9"/>

View File

@ -1,4 +1,4 @@
using CtrEditor.Convertidores; 
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;

View File

@ -4,13 +4,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim.UserControls" xmlns:local="clr-namespace:CtrEditor.ObjetosSim.UserControls"
mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> mc:Ignorable="d">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osPhotocell Color="#FFCA1C1C"/> <vm:osPhotocell Color="#FFCA1C1C"/>

View File

@ -1,4 +1,4 @@
using CtrEditor.Convertidores; 
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Windows; using System.Windows;
@ -46,7 +46,7 @@ namespace CtrEditor.ObjetosSim
EscribirBitTag(TagPhotocell_OUT, !LuzCortada); EscribirBitTag(TagPhotocell_OUT, !LuzCortada);
else else
EscribirBitTag(TagPhotocell_OUT, LuzCortada); EscribirBitTag(TagPhotocell_OUT, LuzCortada);
if (filter_Frecuency < 1) if (Filter_Frecuency < 1)
{ {
Filter_Frecuency = 1; Filter_Frecuency = 1;
Frecuency = 0; Frecuency = 0;

View File

@ -4,13 +4,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim" xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> mc:Ignorable="d">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osSensTemperatura /> <vm:osSensTemperatura />

View File

@ -1,5 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;

View File

@ -5,14 +5,9 @@
xmlns:ei="http://schemas.microsoft.com/xaml/behaviors" xmlns:ei="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"> mc:Ignorable="d">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osAnalogTag/> <vm:osAnalogTag/>
</UserControl.DataContext> </UserControl.DataContext>

View File

@ -1,4 +1,4 @@
using CtrEditor.Convertidores; 
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;

View File

@ -5,14 +5,9 @@
xmlns:ei="http://schemas.microsoft.com/xaml/behaviors" xmlns:ei="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"> mc:Ignorable="d">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osBoolTag/> <vm:osBoolTag/>
</UserControl.DataContext> </UserControl.DataContext>

View File

@ -1,4 +1,4 @@
using CtrEditor.Convertidores; 
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;

View File

@ -3,10 +3,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Background="LightGray"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores" mc:Ignorable="d">
Background="LightGray">
<UserControl.DataContext> <UserControl.DataContext>
<vm:osConsensGeneric /> <vm:osConsensGeneric />

View File

@ -1,5 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;

View File

@ -1,17 +1,14 @@
<UserControl x:Class="CtrEditor.ObjetosSim.Traces.ucTrace3" <UserControl x:Class="CtrEditor.ObjetosSim.ucTrace3"
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:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:ei="http://schemas.microsoft.com/xaml/behaviors" xmlns:ei="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:convert="clr-namespace:CtrEditor.Convertidores" Background="#FFECECEC"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim.Traces" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d" Background="#FFECECEC"> mc:Ignorable="d">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osTrace3 Descripcion_Serie_1="Serie 1" Max_Cantidad_Elementos="100"/> <vm:osTrace3 Descripcion_Serie_1="Serie 1" Max_Cantidad_Elementos="100"/>

View File

@ -1,4 +1,4 @@
using CtrEditor.Convertidores; 
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
@ -7,7 +7,7 @@ using System.Windows.Shapes;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Runtime.Intrinsics; using System.Runtime.Intrinsics;
namespace CtrEditor.ObjetosSim.Traces namespace CtrEditor.ObjetosSim
{ {
/// <summary> /// <summary>
/// Interaction logic for ucTrace3.xaml /// Interaction logic for ucTrace3.xaml

View File

@ -1,16 +1,11 @@
<UserControl x:Class="CtrEditor.ObjetosSim.Traces.ucTraceSimple" <UserControl x:Class="CtrEditor.ObjetosSim.ucTraceSimple"
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:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim.Traces"
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF" xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<vm:osTraceSimple Alto="3" Ancho="6"/> <vm:osTraceSimple Alto="3" Ancho="6"/>

View File

@ -1,4 +1,4 @@
using CtrEditor.Convertidores; 
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@ -11,7 +11,7 @@ using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.Defaults; using LiveChartsCore.Defaults;
using System.Diagnostics; using System.Diagnostics;
namespace CtrEditor.ObjetosSim.Traces namespace CtrEditor.ObjetosSim
{ {
/// <summary> /// <summary>
/// Interaction logic for ucTraceSimple.xaml /// Interaction logic for ucTraceSimple.xaml

View File

@ -2,7 +2,7 @@
using System.Windows.Controls; using System.Windows.Controls;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using System.Reflection; using System.Reflection;
using CtrEditor.Convertidores;
using System.Windows.Data; using System.Windows.Data;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;

View File

@ -0,0 +1,12 @@
<UserControl x:Class="CtrEditor.ObjetosSim.UserControls.ThreeLinesControl"
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"
mc:Ignorable="d"
Width="Auto" Height="Auto">
<Grid>
<Canvas x:Name="Canvas"/>
</Grid>
</UserControl>

View File

@ -0,0 +1,144 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace CtrEditor.ObjetosSim.UserControls
{
/// <summary>
/// Interaction logic for ThreeLinesControl.xaml
/// </summary>
public partial class ThreeLinesControl : UserControl
{
private Rectangle _liz;
private Rectangle _lc;
private Rectangle _lde;
public ThreeLinesControl()
{
InitializeComponent();
this.Loaded += ThreeLinesControl_Loaded;
}
private void ThreeLinesControl_Loaded(object sender, RoutedEventArgs e)
{
CreateOrUpdateRectangles();
}
public double AnchoRecto
{
get { return (double)GetValue(AnchoRectoProperty); }
set { SetValue(AnchoRectoProperty, value); }
}
public static readonly DependencyProperty AnchoRectoProperty =
DependencyProperty.Register("AnchoRecto", typeof(double), typeof(ThreeLinesControl), new PropertyMetadata(100.0, OnDimensionsChanged));
public double AnchoCentro
{
get { return (double)GetValue(AnchoCentroProperty); }
set { SetValue(AnchoCentroProperty, value); }
}
public static readonly DependencyProperty AnchoCentroProperty =
DependencyProperty.Register("AnchoCentro", typeof(double), typeof(ThreeLinesControl), new PropertyMetadata(100.0, OnDimensionsChanged));
public double Altura
{
get { return (double)GetValue(AlturaProperty); }
set { SetValue(AlturaProperty, value); }
}
public static readonly DependencyProperty AlturaProperty =
DependencyProperty.Register("Altura", typeof(double), typeof(ThreeLinesControl), new PropertyMetadata(100.0, OnDimensionsChanged));
public double AltoGuia
{
get { return (double)GetValue(AltoGuiaProperty); }
set { SetValue(AltoGuiaProperty, value); }
}
public static readonly DependencyProperty AltoGuiaProperty =
DependencyProperty.Register("AltoGuia", typeof(double), typeof(ThreeLinesControl), new PropertyMetadata(10.0, OnDimensionsChanged));
private static void OnDimensionsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = d as ThreeLinesControl;
control?.CreateOrUpdateRectangles();
}
private void CreateOrUpdateRectangles()
{
if (_liz == null || _lc == null || _lde == null)
{
// Crear Liz
_liz = new Rectangle
{
Width = AnchoRecto,
Height = AltoGuia,
Fill = Brushes.Blue
};
Canvas.SetLeft(_liz, 0);
Canvas.SetTop(_liz, -AltoGuia / 2);
Canvas.Children.Add(_liz);
// Crear Lc
_lc = new Rectangle
{
Width = CalculateLcWidth(),
Height = AltoGuia,
Fill = Brushes.Red,
RenderTransformOrigin = new Point(0, 0.5)
};
_lc.RenderTransform = new RotateTransform(GetRotationAngle(AnchoCentro, Altura));
Canvas.SetLeft(_lc, AnchoRecto);
Canvas.SetTop(_lc, -AltoGuia / 2);
Canvas.Children.Add(_lc);
// Crear Lde
_lde = new Rectangle
{
Width = AnchoRecto,
Height = AltoGuia,
Fill = Brushes.Green
};
Canvas.SetLeft(_lde, AnchoRecto + AnchoCentro);
Canvas.SetTop(_lde, Altura - AltoGuia / 2);
Canvas.Children.Add(_lde);
}
else
{
// Actualizar Liz
_liz.Width = AnchoRecto;
_liz.Height = AltoGuia;
Canvas.SetLeft(_liz, 0);
Canvas.SetTop(_liz, -AltoGuia / 2);
// Actualizar Lc
_lc.Width = CalculateLcWidth();
_lc.Height = AltoGuia;
_lc.RenderTransform = new RotateTransform(GetRotationAngle(AnchoCentro, Altura));
Canvas.SetLeft(_lc, AnchoRecto);
Canvas.SetTop(_lc, -AltoGuia / 2);
// Actualizar Lde
_lde.Width = AnchoRecto;
_lde.Height = AltoGuia;
Canvas.SetLeft(_lde, AnchoRecto + AnchoCentro);
Canvas.SetTop(_lde, Altura - AltoGuia / 2);
}
}
// Método auxiliar para calcular la hipotenusa
private double CalculateLcWidth()
{
return Math.Sqrt(Math.Pow(AnchoCentro, 2) + Math.Pow(Altura, 2));
}
private double GetRotationAngle(double anchoCentro, double altura)
{
return Math.Atan2(altura, anchoCentro) * 180 / Math.PI;
}
}
}

View File

@ -1,29 +1,17 @@
using Newtonsoft.Json.Linq; 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using static System.Runtime.InteropServices.JavaScript.JSType;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using System.Windows.Media; using System.Windows.Media;
using nkast.Aether.Physics2D.Common; using nkast.Aether.Physics2D.Common;
using FarseerPhysics.Dynamics;
using Siemens.Simatic.Simulation.Runtime; using Siemens.Simatic.Simulation.Runtime;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
using System.Diagnostics; using System.Diagnostics;
using HarfBuzzSharp; using System.Windows.Shapes;
using System.Windows.Controls;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
@ -246,19 +234,12 @@ namespace CtrEditor.ObjetosSim
return null; return null;
} }
protected void CrearAnimacionStoryBoardTrasnporte(System.Windows.Shapes.Rectangle transporte, bool invertirDireccion) protected Storyboard CrearAnimacionMultiStoryBoardTrasnporte(Rectangle transporte, bool invertirDireccion)
{ {
if (_visualRepresentation == null) return; if (_visualRepresentation == null) return null;
if (transporte == null) return; if (transporte == null) return null;
// Detener y eliminar el storyboard existente si hay uno Storyboard storyboard = new Storyboard();
if (_storyboard != null)
{
_storyboard.Stop();
_storyboard.Children.Clear();
}
_storyboard = new Storyboard();
var animation = new DoubleAnimation var animation = new DoubleAnimation
{ {
From = invertirDireccion ? 20 : 0, From = invertirDireccion ? 20 : 0,
@ -268,20 +249,43 @@ namespace CtrEditor.ObjetosSim
}; };
Storyboard.SetTarget(animation, transporte); Storyboard.SetTarget(animation, transporte);
Storyboard.SetTargetProperty(animation, new PropertyPath("(Rectangle.Fill).(VisualBrush.Transform).(TransformGroup.Children)[0].(TranslateTransform.X)")); Storyboard.SetTargetProperty(animation, new PropertyPath("(Rectangle.Fill).(VisualBrush.Transform).(TransformGroup.Children)[0].(TranslateTransform.X)"));
_storyboard.Children.Add(animation); storyboard.Children.Add(animation);
_storyboard.Begin(); storyboard.Begin();
_storyboard.SetSpeedRatio(0); storyboard.SetSpeedRatio(0);
return storyboard;
}
protected Storyboard CrearAnimacionMultiStoryBoardTrasnporte(Storyboard storyboard, Rectangle transporte, bool invertirDireccion)
{
// Detener y eliminar el storyboard existente si hay uno
if (storyboard != null)
{
storyboard.Stop();
storyboard.Children.Clear();
}
return CrearAnimacionMultiStoryBoardTrasnporte(transporte, invertirDireccion);
}
protected void ActualizarAnimacionMultiStoryBoardTransporte(Storyboard storyboard, float velocidadActual)
{
if (_visualRepresentation == null) return;
if (storyboard == null) return;
if (!_mainViewModel.IsSimulationRunning)
storyboard.SetSpeedRatio(0);
else
storyboard.SetSpeedRatio(Math.Abs(velocidadActual));
}
protected void CrearAnimacionStoryBoardTrasnporte(Rectangle transporte, bool invertirDireccion)
{
_storyboard = CrearAnimacionMultiStoryBoardTrasnporte(_storyboard, transporte, invertirDireccion);
} }
protected void ActualizarAnimacionStoryBoardTransporte(float velocidadActual) protected void ActualizarAnimacionStoryBoardTransporte(float velocidadActual)
{ {
if (_visualRepresentation == null) return; ActualizarAnimacionMultiStoryBoardTransporte(_storyboard, velocidadActual);
if (_storyboard == null) return;
if (!_mainViewModel.IsSimulationRunning)
_storyboard.SetSpeedRatio(0);
else
_storyboard.SetSpeedRatio(Math.Abs(velocidadActual));
} }
/// <summary> /// <summary>
@ -383,11 +387,49 @@ namespace CtrEditor.ObjetosSim
public float CanvasGetTopinMeter() public float CanvasGetTopinMeter()
{ {
if (_visualRepresentation != null) if (_visualRepresentation != null)
return PixelToMeter.Instance.calc.PixelsToMeters((float)Canvas.GetTop(_visualRepresentation)); return PixelToMeter.Instance.calc.PixelsToMeters((float)System.Windows.Controls.Canvas.GetTop(_visualRepresentation));
else return 0f; else return 0f;
} }
public (Vector2 TopLeft, Vector2 BottomRight) GetRectangleCoordinatesInMeter(System.Windows.Shapes.Rectangle rect) public float PixelsToMeters(float pixel)
{
return PixelToMeter.Instance.calc.PixelsToMeters(pixel);
}
public Vector2 PixelsToMeters(Vector2 pixel)
{
return new Vector2(PixelsToMeters(pixel.X),PixelsToMeters(pixel.Y));
}
public float MeterToPixels(float meter)
{
return PixelToMeter.Instance.calc.MetersToPixels(meter);
}
public Vector2 MeterToPixels(Vector2 meter)
{
return new Vector2(MeterToPixels(meter.X), MeterToPixels(meter.Y));
}
private static GeneralTransform GetTransformToRoot(Visual visual)
{
// Crear una transformación acumulativa inicial
GeneralTransformGroup transformGroup = new GeneralTransformGroup();
// Recorrer hacia arriba el árbol visual, acumulando las transformaciones
while (visual != null)
{
GeneralTransform transform = visual.TransformToAncestor(visual);
transformGroup.Children.Insert(0, transform);
visual = VisualTreeHelper.GetParent(visual) as Visual;
}
return transformGroup;
}
public (Vector2 TopLeft, Vector2 BottomRight) GetRectangleCoordinatesInMeter(Rectangle rect)
{ {
if (rect != null) if (rect != null)
{ {
@ -407,11 +449,22 @@ namespace CtrEditor.ObjetosSim
else return (new Vector2(0, 0), new Vector2(0, 0)); else return (new Vector2(0, 0), new Vector2(0, 0));
} }
public (Vector2 Start, Vector2 End) GetCenterLineVectors(System.Windows.Shapes.Rectangle rect) public (Vector2 Start, Vector2 End) GetCenterLineVectors(Rectangle rect)
{ {
if (rect == null) if (rect == null)
return (new Vector2(0, 0), new Vector2(0, 0)); return (new Vector2(0, 0), new Vector2(0, 0));
Vector2 start = new Vector2(0, 0);
Vector2 end = new Vector2(0, 0);
// Usar Dispatcher para asegurar la ejecución en el hilo correcto
_visualRepresentation?.Dispatcher.Invoke(() =>
{
// Asegúrate de que el control está en el árbol visual y actualizado
if (_visualRepresentation.IsLoaded && rect.IsLoaded)
{
_visualRepresentation.UpdateLayout();
var _canvasLeft = CanvasGetLeftinMeter(); var _canvasLeft = CanvasGetLeftinMeter();
var _canvasTop = CanvasGetTopinMeter(); var _canvasTop = CanvasGetTopinMeter();
@ -426,12 +479,15 @@ namespace CtrEditor.ObjetosSim
Point transformedEnd = transform.Transform(endLocal); Point transformedEnd = transform.Transform(endLocal);
// Convierte a unidades de Farseer (metros en este caso) // Convierte a unidades de Farseer (metros en este caso)
Vector2 start = new Vector2(PixelToMeter.Instance.calc.PixelsToMeters((float)transformedStart.X) + _canvasLeft, PixelToMeter.Instance.calc.PixelsToMeters((float)transformedStart.Y) + _canvasTop); start = new Vector2(PixelToMeter.Instance.calc.PixelsToMeters((float)transformedStart.X) + _canvasLeft, PixelToMeter.Instance.calc.PixelsToMeters((float)transformedStart.Y) + _canvasTop);
Vector2 end = new Vector2(PixelToMeter.Instance.calc.PixelsToMeters((float)transformedEnd.X) + _canvasLeft, PixelToMeter.Instance.calc.PixelsToMeters((float)transformedEnd.Y) + _canvasTop); end = new Vector2(PixelToMeter.Instance.calc.PixelsToMeters((float)transformedEnd.X) + _canvasLeft, PixelToMeter.Instance.calc.PixelsToMeters((float)transformedEnd.Y) + _canvasTop);
}
});
return (start, end); return (start, end);
} }
public Vector2 GetCurveCenterInMeter(float RadioExterno) public Vector2 GetCurveCenterInMeter(float RadioExterno)
{ {
var _canvasLeft = CanvasGetLeftinMeter(); var _canvasLeft = CanvasGetLeftinMeter();
@ -445,7 +501,7 @@ namespace CtrEditor.ObjetosSim
return new Vector2((float)centerX, (float)centerY); return new Vector2((float)centerX, (float)centerY);
} }
public Vector2 GetRectangleCenter(System.Windows.Shapes.Rectangle wpfRect) public Vector2 GetRectangleCenter(Rectangle wpfRect)
{ {
var coords = GetRectangleCoordinatesInMeter(wpfRect); var coords = GetRectangleCoordinatesInMeter(wpfRect);
@ -458,13 +514,13 @@ namespace CtrEditor.ObjetosSim
public void UpdateRectangle(simTransporte simRect, System.Windows.Shapes.Rectangle wpfRect, float Alto, float Ancho, float Angulo) public void UpdateRectangle(simTransporte simRect, Rectangle wpfRect, float Alto, float Ancho, float Angulo)
{ {
if (simRect != null) if (simRect != null)
simRect.Create(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo); simRect.Create(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo);
} }
public void UpdateRectangle(simBarrera simRect, System.Windows.Shapes.Rectangle wpfRect, float Alto, float Ancho, float Angulo) public void UpdateRectangle(simBarrera simRect, Rectangle wpfRect, float Alto, float Ancho, float Angulo)
{ {
if (simRect != null) if (simRect != null)
simRect.Create(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo); simRect.Create(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo);
@ -480,20 +536,21 @@ namespace CtrEditor.ObjetosSim
return simulationManager.AddCurve(RadioInterno, RadioExterno, startAngle, endAngle, GetCurveCenterInMeter(RadioExterno)); return simulationManager.AddCurve(RadioInterno, RadioExterno, startAngle, endAngle, GetCurveCenterInMeter(RadioExterno));
} }
public simTransporte AddRectangle(SimulationManagerFP simulationManager, System.Windows.Shapes.Rectangle wpfRect, float Alto, float Ancho, float Angulo) public simTransporte AddRectangle(SimulationManagerFP simulationManager, Rectangle wpfRect, float Alto, float Ancho, float Angulo)
{ {
return simulationManager.AddRectangle(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo); return simulationManager.AddRectangle(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo);
} }
public simBarrera AddBarrera(SimulationManagerFP simulationManager, System.Windows.Shapes.Rectangle wpfRect, float Alto, float Ancho, float Angulo, bool detectarCuello) public simBarrera AddBarrera(SimulationManagerFP simulationManager, Rectangle wpfRect, float Alto, float Ancho, float Angulo, bool detectarCuello)
{ {
return simulationManager.AddBarrera(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo, detectarCuello); return simulationManager.AddBarrera(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo, detectarCuello);
} }
public void UpdateOrCreateLine(simGuia simGuia, System.Windows.Shapes.Rectangle wpfRect) public void UpdateOrCreateLine(simGuia simGuia, Rectangle wpfRect)
{ {
if (simGuia != null) if (simGuia != null)
{ {
var coords = GetCenterLineVectors(wpfRect); var coords = GetCenterLineVectors(wpfRect);
// Crear o actualizar simRectangle // Crear o actualizar simRectangle
@ -501,7 +558,7 @@ namespace CtrEditor.ObjetosSim
} }
} }
public simGuia AddLine(SimulationManagerFP simulationManager, System.Windows.Shapes.Rectangle wpfRect) public simGuia AddLine(SimulationManagerFP simulationManager, Rectangle wpfRect)
{ {
var coords = GetCenterLineVectors(wpfRect); var coords = GetCenterLineVectors(wpfRect);
return simulationManager.AddLine(coords.Start, coords.End); return simulationManager.AddLine(coords.Start, coords.End);

View File

@ -5,11 +5,11 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim" xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> >
<UserControl.Resources> <UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources> </UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>

View File

@ -1,4 +1,4 @@
using CtrEditor.Convertidores; 
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;

26
Properties/Settings.Designer.cs generated Normal file
View File

@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace CtrEditor.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View File

@ -0,0 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
</SettingsFile>

View File

@ -1,23 +1,15 @@
using System; using System.Windows.Controls;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Shapes; using System.Windows.Shapes;
using CtrEditor.Convertidores;
using System.Windows; using System.Windows;
using System.Diagnostics; using System.Diagnostics;
using CtrEditor.ObjetosSim;
using System.Windows.Documents;
using nkast.Aether.Physics2D;
using nkast.Aether.Physics2D.Dynamics; using nkast.Aether.Physics2D.Dynamics;
using nkast.Aether.Physics2D.Common; using nkast.Aether.Physics2D.Common;
using nkast.Aether.Physics2D.Collision.Shapes; using nkast.Aether.Physics2D.Collision.Shapes;
using nkast.Aether.Physics2D.Dynamics.Contacts; using nkast.Aether.Physics2D.Dynamics.Contacts;
using nkast.Aether.Physics2D.Collision;
using Transform = nkast.Aether.Physics2D.Common.Transform;
using nkast.Aether.Physics2D.Dynamics.Joints; using nkast.Aether.Physics2D.Dynamics.Joints;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace CtrEditor.Simulacion namespace CtrEditor.Simulacion
{ {
@ -33,6 +25,14 @@ namespace CtrEditor.Simulacion
_world.Remove(Body); _world.Remove(Body);
} }
} }
public static float GradosARadianes(float grados)
{
return (float)(grados * (Math.PI / 180));
}
public static float RadianesAGrados(float radianes)
{
return (float)(radianes * (180 / Math.PI));
}
public void SetPosition(float x, float y) public void SetPosition(float x, float y)
{ {
Body.SetTransform(new Vector2(x, y), Body.Rotation); Body.SetTransform(new Vector2(x, y), Body.Rotation);
@ -62,8 +62,8 @@ namespace CtrEditor.Simulacion
_deferredActions = deferredActions; _deferredActions = deferredActions;
_innerRadius = innerRadius; _innerRadius = innerRadius;
_outerRadius = outerRadius; _outerRadius = outerRadius;
_startAngle = Microsoft.Xna.Framework.MathHelper.ToRadians(startAngle); _startAngle = GradosARadianes(startAngle);
_endAngle = Microsoft.Xna.Framework.MathHelper.ToRadians(endAngle); _endAngle = GradosARadianes(endAngle);
Create(position); Create(position);
} }
@ -72,8 +72,8 @@ namespace CtrEditor.Simulacion
if (_world == null) return; if (_world == null) return;
_innerRadius = innerRadius; _innerRadius = innerRadius;
_outerRadius = outerRadius; _outerRadius = outerRadius;
_startAngle = Microsoft.Xna.Framework.MathHelper.ToRadians(startAngle); _startAngle = GradosARadianes(startAngle);
_endAngle = Microsoft.Xna.Framework.MathHelper.ToRadians(endAngle); _endAngle = GradosARadianes(endAngle);
Create(position); Create(position);
} }
@ -197,8 +197,8 @@ namespace CtrEditor.Simulacion
public float Angle public float Angle
{ {
get { return Microsoft.Xna.Framework.MathHelper.ToDegrees(Body.Rotation); } get { return RadianesAGrados(Body.Rotation); }
set { Body.Rotation = Microsoft.Xna.Framework.MathHelper.ToRadians(value); } set { Body.Rotation = GradosARadianes(value); }
} }
public new void SetPosition(float x, float y) public new void SetPosition(float x, float y)
@ -229,7 +229,7 @@ namespace CtrEditor.Simulacion
Body = _world.CreateRectangle( width, height, 1f, position); Body = _world.CreateRectangle( width, height, 1f, position);
Body.FixtureList[0].IsSensor = true; Body.FixtureList[0].IsSensor = true;
Body.BodyType = BodyType.Static; Body.BodyType = BodyType.Static;
Body.Rotation = Microsoft.Xna.Framework.MathHelper.ToRadians(angle); Body.Rotation = GradosARadianes(angle);
Body.Tag = this; // Importante para la identificación durante la colisión Body.Tag = this; // Importante para la identificación durante la colisión
} }
} }
@ -257,8 +257,8 @@ namespace CtrEditor.Simulacion
public float Angle public float Angle
{ {
get { return Microsoft.Xna.Framework.MathHelper.ToDegrees(Body.Rotation); } get { return RadianesAGrados(Body.Rotation); }
set { Body.Rotation = Microsoft.Xna.Framework.MathHelper.ToRadians(value); } set { Body.Rotation = GradosARadianes(value); }
} }
public new void SetPosition(float x, float y) public new void SetPosition(float x, float y)
@ -282,7 +282,7 @@ namespace CtrEditor.Simulacion
Body = _world.CreateRectangle( width, height, 1f, position); Body = _world.CreateRectangle( width, height, 1f, position);
Body.FixtureList[0].IsSensor = true; Body.FixtureList[0].IsSensor = true;
Body.BodyType = BodyType.Static; Body.BodyType = BodyType.Static;
Body.Rotation = Microsoft.Xna.Framework.MathHelper.ToRadians(angle); Body.Rotation = GradosARadianes(angle);
Body.Tag = this; // Importante para la identificación durante la colisión Body.Tag = this; // Importante para la identificación durante la colisión
LuzCortada = 0; LuzCortada = 0;
} }

View File

@ -8,7 +8,7 @@ using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories; using FarseerPhysics.Factories;
using FarseerPhysics.Collision.Shapes; using FarseerPhysics.Collision.Shapes;
using nkast.Aether.Physics2D.Common; using nkast.Aether.Physics2D.Common;
using CtrEditor.Convertidores;
using FarseerPhysics.Common; using FarseerPhysics.Common;
using System.Windows; using System.Windows;
using System.Diagnostics; using System.Diagnostics;

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using FarseerPhysics.Collision;
using Microsoft.VisualBasic.Devices; using Microsoft.VisualBasic.Devices;
using nkast.Aether.Physics2D.Common; using nkast.Aether.Physics2D.Common;

View File

@ -146,13 +146,13 @@ namespace CtrEditor.Simulacion
float radius = circleShape.Radius; float radius = circleShape.Radius;
float halfSide = radius; // El lado del cuadrado inscrito es igual al radio float halfSide = radius; // El lado del cuadrado inscrito es igual al radio
Vector2[] squareVertices = Vector2[] squareVertices = new Vector2[]
[ {
new Vector2(-halfSide, -halfSide), new Vector2(-halfSide, -halfSide),
new Vector2(halfSide, -halfSide), new Vector2(halfSide, -halfSide),
new Vector2(halfSide, halfSide), new Vector2(halfSide, halfSide),
new Vector2(-halfSide, halfSide) new Vector2(-halfSide, halfSide)
]; };
foreach (var vertex in squareVertices) foreach (var vertex in squareVertices)
{ {
@ -164,6 +164,7 @@ namespace CtrEditor.Simulacion
return vertices; return vertices;
} }
private static Vector2 RotatePoint(Vector2 point, Vector2 origin, float rotation) private static Vector2 RotatePoint(Vector2 point, Vector2 origin, float rotation)
{ {
float cos = (float)Math.Cos(rotation); float cos = (float)Math.Cos(rotation);

View File

@ -1,15 +1,43 @@
using System; using System.Globalization;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data; using System.Windows.Data;
using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using System.Windows;
namespace CtrEditor.Convertidores namespace CtrEditor
{ {
public class SumConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length == 2 && values[0] is float value1 && values[1] is float value2)
{
return (double) (value1 + value2);
}
return DependencyProperty.UnsetValue;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class VerticalPositionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double altura && double.TryParse(parameter?.ToString(), out double factor))
{
return altura * factor;
}
return 0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class HalfWidthConverter : IValueConverter public class HalfWidthConverter : IValueConverter
{ {
@ -178,6 +206,27 @@ namespace CtrEditor.Convertidores
} }
} }
public class MarginConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length == 4 &&
values[0] is double left &&
values[1] is double top &&
values[2] is double right &&
values[3] is double bottom)
{
return new Thickness(PixelToMeter.Instance.calc.MetersToPixels((float)left), PixelToMeter.Instance.calc.MetersToPixels((float)top), PixelToMeter.Instance.calc.MetersToPixels((float)right), PixelToMeter.Instance.calc.MetersToPixels((float)bottom));
}
return new Thickness();
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException("ConvertBack is not supported.");
}
}
public class DistanceToMarginConverter : IValueConverter public class DistanceToMarginConverter : IValueConverter
{ {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)