diff --git a/ObjetosSim/Estaticos/ucTransporteCurvaGuias.xaml b/ObjetosSim/Estaticos/ucTransporteCurvaGuias.xaml index a312b35..cf46df0 100644 --- a/ObjetosSim/Estaticos/ucTransporteCurvaGuias.xaml +++ b/ObjetosSim/Estaticos/ucTransporteCurvaGuias.xaml @@ -15,6 +15,10 @@ + StartAngle="{Binding Angulo}" EndAngle="{Binding AnguloFinal}" + ShowGuides="{Binding MostrarGuias}" + GuideDistance="{Binding DistanciaGuias, Converter={StaticResource MeterToPixelConverter}}" + GuideThickness="{Binding GrosorGuias, Converter={StaticResource MeterToPixelConverter}}" + GuideStroke="{Binding ColorGuiasBrush}" /> diff --git a/ObjetosSim/Estaticos/ucTransporteCurvaGuias.xaml.cs b/ObjetosSim/Estaticos/ucTransporteCurvaGuias.xaml.cs index 26ea6e5..989d780 100644 --- a/ObjetosSim/Estaticos/ucTransporteCurvaGuias.xaml.cs +++ b/ObjetosSim/Estaticos/ucTransporteCurvaGuias.xaml.cs @@ -7,6 +7,7 @@ using CtrEditor.Simulacion; using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; using CtrEditor.FuncionesBase; using System.Text.Json.Serialization; +using System.Windows.Media; namespace CtrEditor.ObjetosSim { @@ -124,6 +125,46 @@ namespace CtrEditor.ObjetosSim ActualizarGeometrias(); } + [ObservableProperty] + [property: Description("Mostrar guías visuales")] + [property: Category("Guías")] + private bool mostrarGuias; + + // Propiedad interna Brush para el binding + private Brush _colorGuiasBrush = new SolidColorBrush(Colors.DarkBlue); + + [JsonIgnore] + public Brush ColorGuiasBrush + { + get => _colorGuiasBrush; + set + { + if (_colorGuiasBrush != value) + { + _colorGuiasBrush = value; + OnPropertyChanged(nameof(ColorGuiasBrush)); + + // Extraer el color del brush y actualizar la propiedad Color + if (value is SolidColorBrush solidBrush) + { + colorGuias = solidBrush.Color; + OnPropertyChanged(nameof(ColorGuias)); + } + } + } + } + + [ObservableProperty] + [property: Description("Color de las guías")] + [property: Category("Guías")] + private Color colorGuias = Colors.DarkBlue; + + partial void OnColorGuiasChanged(Color value) + { + // Sincronizar con la propiedad Brush + ColorGuiasBrush = new SolidColorBrush(value); + } + [ObservableProperty] [property: Description("Bit to enable Link to Motor")] [property: Category("PLC link:")] @@ -347,6 +388,7 @@ namespace CtrEditor.ObjetosSim NumeroSegmentosGuias = 12; // Valor por defecto GrosorGuias = 0.03f; DistanciaGuias = 0.05f; + MostrarGuias = true; // Mostrar guías por defecto } public override void UpdateGeometryStart() diff --git a/ObjetosSim/UserControls/CircularSegment.xaml b/ObjetosSim/UserControls/CircularSegment.xaml index 1656504..dbe6441 100644 --- a/ObjetosSim/UserControls/CircularSegment.xaml +++ b/ObjetosSim/UserControls/CircularSegment.xaml @@ -5,7 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CtrEditor.ObjetosSim.UserControls" mc:Ignorable="d" Name="circularSegmentControl"> - + diff --git a/ObjetosSim/UserControls/CircularSegment.xaml.cs b/ObjetosSim/UserControls/CircularSegment.xaml.cs index 16c1960..b885616 100644 --- a/ObjetosSim/UserControls/CircularSegment.xaml.cs +++ b/ObjetosSim/UserControls/CircularSegment.xaml.cs @@ -1,6 +1,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; +using System.Windows.Shapes; namespace CtrEditor.ObjetosSim.UserControls { @@ -54,9 +55,53 @@ namespace CtrEditor.ObjetosSim.UserControls public static readonly DependencyProperty EndAngleProperty = DependencyProperty.Register("EndAngle", typeof(double), typeof(CircularSegment), new PropertyMetadata(90.0, OnPropertyChanged)); + // Nuevas propiedades para las guías + public bool ShowGuides + { + get { return (bool)GetValue(ShowGuidesProperty); } + set { SetValue(ShowGuidesProperty, value); } + } + + public static readonly DependencyProperty ShowGuidesProperty = + DependencyProperty.Register("ShowGuides", typeof(bool), typeof(CircularSegment), new PropertyMetadata(false, OnPropertyChanged)); + + public double GuideDistance + { + get { return (double)GetValue(GuideDistanceProperty); } + set { SetValue(GuideDistanceProperty, value); } + } + + public static readonly DependencyProperty GuideDistanceProperty = + DependencyProperty.Register("GuideDistance", typeof(double), typeof(CircularSegment), new PropertyMetadata(5.0, OnPropertyChanged)); + + public double GuideThickness + { + get { return (double)GetValue(GuideThicknessProperty); } + set { SetValue(GuideThicknessProperty, value); } + } + + public static readonly DependencyProperty GuideThicknessProperty = + DependencyProperty.Register("GuideThickness", typeof(double), typeof(CircularSegment), new PropertyMetadata(2.0, OnPropertyChanged)); + + public static readonly DependencyProperty GuideStrokeProperty = + DependencyProperty.Register("GuideStroke", typeof(Brush), typeof(CircularSegment), new PropertyMetadata(new SolidColorBrush(Colors.DarkBlue), OnGuidePropertyChanged)); + + public Brush GuideStroke + { + get { return (Brush)GetValue(GuideStrokeProperty); } + set { SetValue(GuideStrokeProperty, value); } + } + public CircularSegment() { InitializeComponent(); + this.Loaded += CircularSegment_Loaded; + } + + private void CircularSegment_Loaded(object sender, RoutedEventArgs e) + { + System.Diagnostics.Debug.WriteLine("CircularSegment_Loaded called"); + DrawSegment(); } // Propiedad pública para acceder al Path desde código externo @@ -67,11 +112,38 @@ namespace CtrEditor.ObjetosSim.UserControls (d as CircularSegment)?.DrawSegment(); } + private static void OnGuidePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + (d as CircularSegment)?.DrawSegment(); + } + private void DrawSegment() { + System.Diagnostics.Debug.WriteLine($"DrawSegment called - ShowGuides: {ShowGuides}"); + if (OuterRadius <= 0 || InnerRadius <= 0 || StartAngle == EndAngle) return; + // Limpiar canvas existente - mantener solo el path principal + for (int i = mainCanvas.Children.Count - 1; i >= 0; i--) + { + if (mainCanvas.Children[i] != path) + { + mainCanvas.Children.RemoveAt(i); + } + } + + DrawMainSegment(); + + if (ShowGuides) + { + System.Diagnostics.Debug.WriteLine("About to call DrawGuides()"); + DrawGuides(); + } + } + + private void DrawMainSegment() + { PathGeometry geometry = new PathGeometry(); PathFigure figure = new PathFigure(); @@ -103,5 +175,76 @@ namespace CtrEditor.ObjetosSim.UserControls geometry.Figures.Add(figure); path.Data = geometry; } + + private void DrawGuides() + { + Point center = new Point(OuterRadius, OuterRadius); + + // Calcular radios de las guías + double outerGuideRadius = OuterRadius + GuideDistance; + double innerGuideRadius = InnerRadius - GuideDistance; + + System.Diagnostics.Debug.WriteLine($"DrawGuides - Creating guides with radii: Outer={outerGuideRadius}, Inner={innerGuideRadius}"); + + // Asegurar que el radio interior no sea negativo + if (innerGuideRadius < 1.0) + innerGuideRadius = 1.0; + + // Crear guía exterior + CreateGuideArc(center, outerGuideRadius, "OuterGuide"); + + // Crear guía interior solo si el radio es válido + if (innerGuideRadius > 1.0) + { + CreateGuideArc(center, innerGuideRadius, "InnerGuide"); + } + } + + private void CreateGuideArc(Point center, double radius, string name) + { + var guidePath = new System.Windows.Shapes.Path + { + Name = name, + Stroke = GuideStroke, + StrokeThickness = GuideThickness, + Fill = null + }; + + // Crear geometría del arco + double radiansStart = StartAngle * Math.PI / 180.0; + double radiansEnd = EndAngle * Math.PI / 180.0; + + Point startPoint = new Point( + center.X + radius * Math.Cos(radiansStart), + center.Y + radius * Math.Sin(radiansStart) + ); + + Point endPoint = new Point( + center.X + radius * Math.Cos(radiansEnd), + center.Y + radius * Math.Sin(radiansEnd) + ); + + // Crear el arco usando ArcSegment + var pathGeometry = new PathGeometry(); + var pathFigure = new PathFigure + { + StartPoint = startPoint + }; + + var arcSegment = new ArcSegment + { + Point = endPoint, + Size = new Size(radius, radius), + SweepDirection = SweepDirection.Clockwise, + IsLargeArc = Math.Abs(EndAngle - StartAngle) > 180 + }; + + pathFigure.Segments.Add(arcSegment); + pathGeometry.Figures.Add(pathFigure); + guidePath.Data = pathGeometry; + + System.Diagnostics.Debug.WriteLine($"Adding guide {name} to canvas"); + mainCanvas.Children.Add(guidePath); + } } }