Creado un UserControl con los objetos en TreeView para simplificar la seleccion de los objetos
This commit is contained in:
parent
621ee8be39
commit
8a5ebe6ac6
|
@ -0,0 +1,21 @@
|
||||||
|
<UserControl x:Class="CtrEditor.ObjectHierarchyView"
|
||||||
|
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:oh="clr-namespace:CtrEditor"
|
||||||
|
mc:Ignorable="d">
|
||||||
|
<Grid>
|
||||||
|
<TreeView x:Name="ObjectsTreeView" ItemsSource="{Binding RootNodes}"
|
||||||
|
SelectedItemChanged="TreeView_SelectedItemChanged">
|
||||||
|
<TreeView.ItemTemplate>
|
||||||
|
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<TextBlock Text="{Binding Name}" />
|
||||||
|
<TextBlock Text="{Binding RelationshipType}" Margin="5,0,0,0" Foreground="Gray"
|
||||||
|
FontStyle="Italic" />
|
||||||
|
</StackPanel>
|
||||||
|
</HierarchicalDataTemplate>
|
||||||
|
</TreeView.ItemTemplate>
|
||||||
|
</TreeView>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
|
@ -0,0 +1,97 @@
|
||||||
|
using CtrEditor.ObjetosSim;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows; // Add this for RoutedPropertyChangedEventArgs
|
||||||
|
|
||||||
|
namespace CtrEditor
|
||||||
|
{
|
||||||
|
public partial class ObjectHierarchyView : UserControl
|
||||||
|
{
|
||||||
|
private MainViewModel _mainViewModel;
|
||||||
|
public ObservableCollection<OsTreeNode> RootNodes { get; set; }
|
||||||
|
|
||||||
|
public ObjectHierarchyView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
RootNodes = new ObservableCollection<OsTreeNode>();
|
||||||
|
this.DataContext = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize(MainViewModel mainViewModel)
|
||||||
|
{
|
||||||
|
_mainViewModel = mainViewModel;
|
||||||
|
_mainViewModel.ObjetosSimulables.CollectionChanged += ObjetosSimulables_CollectionChanged;
|
||||||
|
UpdateTree();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ObjetosSimulables_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
UpdateTree();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateTree()
|
||||||
|
{
|
||||||
|
RootNodes.Clear();
|
||||||
|
|
||||||
|
// Agrupar por tipos
|
||||||
|
var groupsByType = _mainViewModel.ObjetosSimulables
|
||||||
|
.GroupBy(obj => obj.GetType());
|
||||||
|
|
||||||
|
foreach (var group in groupsByType)
|
||||||
|
{
|
||||||
|
// Usar GetTypeDisplayName para obtener el nombre de la clase
|
||||||
|
var typeNode = new OsTreeNode(OsTreeNode.GetTypeDisplayName(group.Key));
|
||||||
|
RootNodes.Add(typeNode);
|
||||||
|
|
||||||
|
foreach (var obj in group)
|
||||||
|
{
|
||||||
|
var objNode = new OsTreeNode(obj.Nombre, obj);
|
||||||
|
typeNode.Children.Add(objNode);
|
||||||
|
|
||||||
|
// Agregar relaciones group_Panel
|
||||||
|
if (!string.IsNullOrEmpty(obj.Group_Panel))
|
||||||
|
{
|
||||||
|
var linkedPanel = _mainViewModel.ObjetosSimulables
|
||||||
|
.FirstOrDefault(o => o.Nombre == obj.Group_Panel);
|
||||||
|
if (linkedPanel != null)
|
||||||
|
{
|
||||||
|
objNode.Children.Add(new OsTreeNode(linkedPanel.Nombre, linkedPanel, "(group_Panel)"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Agregar relaciones group_FramePanel
|
||||||
|
if (!string.IsNullOrEmpty(obj.Group_FramePanel))
|
||||||
|
{
|
||||||
|
var linkedFrame = _mainViewModel.ObjetosSimulables
|
||||||
|
.FirstOrDefault(o => o.Nombre == obj.Group_FramePanel);
|
||||||
|
if (linkedFrame != null)
|
||||||
|
{
|
||||||
|
objNode.Children.Add(new OsTreeNode(linkedFrame.Nombre, linkedFrame, "(group_FramePanel)"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Agregar objetos que hacen referencia a este objeto
|
||||||
|
var referencingObjects = _mainViewModel.ObjetosSimulables
|
||||||
|
.Where(o => o.Group_Panel == obj.Nombre || o.Group_FramePanel == obj.Nombre);
|
||||||
|
|
||||||
|
foreach (var refObj in referencingObjects)
|
||||||
|
{
|
||||||
|
var relationType = refObj.Group_Panel == obj.Nombre ? "(referenced by group_Panel)" : "(referenced by group_FramePanel)";
|
||||||
|
objNode.Children.Add(new OsTreeNode(refObj.Nombre, refObj, relationType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
||||||
|
{
|
||||||
|
if (e.NewValue is OsTreeNode node && node.AssociatedObject != null)
|
||||||
|
{
|
||||||
|
// Actualizar la selección en el MainViewModel
|
||||||
|
_mainViewModel.SelectedItemOsList = node.AssociatedObject;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CtrEditor.ObjetosSim;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace CtrEditor
|
||||||
|
{
|
||||||
|
public partial class OsTreeNode : ObservableObject
|
||||||
|
{
|
||||||
|
[ObservableProperty]
|
||||||
|
private string name;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private ObservableCollection<OsTreeNode> children;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private osBase associatedObject;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private string relationshipType;
|
||||||
|
|
||||||
|
public OsTreeNode(string name, osBase obj = null, string relationship = "")
|
||||||
|
{
|
||||||
|
this.Name = name;
|
||||||
|
this.Children = new ObservableCollection<OsTreeNode>();
|
||||||
|
this.AssociatedObject = obj;
|
||||||
|
this.RelationshipType = relationship;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetTypeDisplayName(Type type)
|
||||||
|
{
|
||||||
|
var methodInfo = type.GetMethod("NombreClase", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||||
|
return methodInfo != null ? methodInfo.Invoke(null, null)?.ToString() : type.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,16 @@
|
||||||
<Window xmlns:ctreditor="clr-namespace:CtrEditor" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
<Window xmlns:ctreditor="clr-namespace:CtrEditor"
|
||||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:Siemens="clr-namespace:LibS7Adv;assembly=LibS7Adv" xmlns:local="clr-namespace:CtrEditor"
|
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:Siemens="clr-namespace:LibS7Adv;assembly=LibS7Adv"
|
||||||
|
xmlns:local="clr-namespace:CtrEditor"
|
||||||
|
xmlns:oh="clr-namespace:CtrEditor"
|
||||||
xmlns:uc="clr-namespace:CtrEditor.ObjetosSim.UserControls"
|
xmlns:uc="clr-namespace:CtrEditor.ObjetosSim.UserControls"
|
||||||
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
|
||||||
|
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||||
xmlns:ObjetosSim="clr-namespace:CtrEditor.ObjetosSim"
|
xmlns:ObjetosSim="clr-namespace:CtrEditor.ObjetosSim"
|
||||||
xmlns:ObjetosExtraccion="clr-namespace:CtrEditor.ObjetosSim.Extraccion_Datos" x:Class="CtrEditor.MainWindow"
|
xmlns:ObjetosExtraccion="clr-namespace:CtrEditor.ObjetosSim.Extraccion_Datos"
|
||||||
|
x:Class="CtrEditor.MainWindow"
|
||||||
Height="900" Width="1600" WindowState="Maximized" ResizeMode="CanResize" Title="{Binding directorioTrabajo, Converter={StaticResource UnsavedChangesConverter}}"
|
Height="900" Width="1600" WindowState="Maximized" ResizeMode="CanResize" Title="{Binding directorioTrabajo, Converter={StaticResource UnsavedChangesConverter}}"
|
||||||
Icon="/app2.png">
|
Icon="/app2.png">
|
||||||
|
|
||||||
|
@ -91,6 +97,7 @@
|
||||||
</i:EventTrigger>
|
</i:EventTrigger>
|
||||||
</i:Interaction.Triggers>
|
</i:Interaction.Triggers>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
||||||
<Siemens:PLCControl x:Name="PLCSim" Grid.Row="2" Margin="5" DataContext="{Binding PLCViewModel}" />
|
<Siemens:PLCControl x:Name="PLCSim" Grid.Row="2" Margin="5" DataContext="{Binding PLCViewModel}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
<!-- GridSplitter -->
|
<!-- GridSplitter -->
|
||||||
|
@ -211,10 +218,14 @@
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" MinHeight="50" />
|
<RowDefinition Height="Auto" MinHeight="50" />
|
||||||
<RowDefinition Height="*" MinHeight="100" />
|
|
||||||
<!-- ListBox1 -->
|
<!-- ListBox1 -->
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="*" MinHeight="50" />
|
||||||
<!-- GridSplitter -->
|
<!-- GridSplitter -->
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<!-- Tree -->
|
||||||
|
<RowDefinition Height="*" MinHeight="100" />
|
||||||
|
<!-- GridSplitter -->
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="*" MinHeight="200" />
|
<RowDefinition Height="*" MinHeight="200" />
|
||||||
<!-- StackPanel -->
|
<!-- StackPanel -->
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
|
@ -277,13 +288,16 @@
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
||||||
<!-- GridSplitter -->
|
<!-- GridSplitter -->
|
||||||
<GridSplitter Grid.Row="3" Height="5" HorizontalAlignment="Stretch" Background="Gray"
|
<GridSplitter Grid.Row="3" Height="5" HorizontalAlignment="Stretch" Background="Gray"
|
||||||
ResizeDirection="Rows" VerticalAlignment="Center" />
|
ResizeDirection="Rows" VerticalAlignment="Center" />
|
||||||
|
<oh:ObjectHierarchyView x:Name="ObjectHierarchy" Grid.Row="4" Margin="5" />
|
||||||
|
<!-- GridSplitter -->
|
||||||
|
<GridSplitter Grid.Row="5" Height="5" HorizontalAlignment="Stretch" Background="Gray"
|
||||||
|
ResizeDirection="Rows" VerticalAlignment="Center" />
|
||||||
|
|
||||||
<!-- PanelEdicion -->
|
<!-- PanelEdicion -->
|
||||||
<xctk:PropertyGrid Grid.Row="4"
|
<xctk:PropertyGrid Grid.Row="6"
|
||||||
Margin="5"
|
Margin="5"
|
||||||
x:Name="PanelEdicion"
|
x:Name="PanelEdicion"
|
||||||
AutoGenerateProperties="False"
|
AutoGenerateProperties="False"
|
||||||
|
@ -405,7 +419,7 @@
|
||||||
</xctk:PropertyGrid.EditorDefinitions>
|
</xctk:PropertyGrid.EditorDefinitions>
|
||||||
</xctk:PropertyGrid>
|
</xctk:PropertyGrid>
|
||||||
|
|
||||||
<ToolBarTray Grid.Row="5">
|
<ToolBarTray Grid.Row="7">
|
||||||
<ToolBar>
|
<ToolBar>
|
||||||
<Button Command="{Binding TBEliminarUserControlCommand}" ToolTip="Eliminar Control">
|
<Button Command="{Binding TBEliminarUserControlCommand}" ToolTip="Eliminar Control">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
|
|
|
@ -87,6 +87,9 @@ namespace CtrEditor
|
||||||
viewModel?.LoadInitialData();
|
viewModel?.LoadInitialData();
|
||||||
viewModel.simulationManager.DebugCanvas = ImagenEnTrabajoCanvas;
|
viewModel.simulationManager.DebugCanvas = ImagenEnTrabajoCanvas;
|
||||||
viewModel.MainCanvas = ImagenEnTrabajoCanvas;
|
viewModel.MainCanvas = ImagenEnTrabajoCanvas;
|
||||||
|
|
||||||
|
// Inicializar ObjectHierarchyView
|
||||||
|
ObjectHierarchy.Initialize(viewModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,24 +318,13 @@ namespace CtrEditor
|
||||||
|
|
||||||
private void ListaOs_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
|
private void ListaOs_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
ImagenEnTrabajoCanvas.Focus(); // Asegurar que el canvas tiene el foco
|
|
||||||
UserControlFactory.LimpiarPropiedadesosDatos(PanelEdicion);
|
|
||||||
|
|
||||||
if (e.AddedItems.Count > 0 && e.AddedItems[0] is osBase selectedObject)
|
if (e.AddedItems.Count > 0 && e.AddedItems[0] is osBase selectedObject)
|
||||||
{
|
{
|
||||||
// Siempre trabajar con selección única para las propiedades
|
// Siempre trabajar con selección única para las propiedades
|
||||||
CargarPropiedadesosDatos(selectedObject);
|
CargarPropiedadesosDatos(selectedObject);
|
||||||
|
|
||||||
// No modificar la selección múltiple aquí, solo actualizar los rectángulos de manipulación
|
_objectManager.SelectObject(selectedObject);
|
||||||
// si el objeto seleccionado no está en la selección actual
|
|
||||||
if (!_objectManager.SelectedObjects.Contains(selectedObject))
|
|
||||||
{
|
|
||||||
if (!((MainViewModel)DataContext).IsMultiSelectionActive)
|
|
||||||
{
|
|
||||||
_objectManager.ClearSelection();
|
|
||||||
_objectManager.SelectObject(selectedObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -407,10 +407,14 @@ namespace CtrEditor
|
||||||
{
|
{
|
||||||
_selectedObjects.Add(obj);
|
_selectedObjects.Add(obj);
|
||||||
obj.IsSelected = true;
|
obj.IsSelected = true;
|
||||||
if (_mainWindow.DataContext is MainViewModel viewModel && viewModel.IsMultiSelectionActive)
|
|
||||||
|
// Agregar highlight visual solo si estamos en modo multi-selección
|
||||||
|
if (_mainWindow.DataContext is MainViewModel vm && vm.IsMultiSelectionActive)
|
||||||
{
|
{
|
||||||
AddSelectionHighlight(obj.VisualRepresentation);
|
AddSelectionHighlight(obj.VisualRepresentation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateSelectionVisuals();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue