95 lines
3.1 KiB
C#
95 lines
3.1 KiB
C#
using Prism.Ioc;
|
|
using System;
|
|
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using XP.Common.Logging.Interfaces;
|
|
using XplorePlane.Services;
|
|
using XplorePlane.ViewModels.Cnc;
|
|
|
|
namespace XplorePlane.Views.Cnc
|
|
{
|
|
/// <summary>
|
|
/// CNC editor main page view.
|
|
/// </summary>
|
|
public partial class CncPageView : UserControl
|
|
{
|
|
private CncInspectionModulePipelineViewModel _inspectionModulePipelineViewModel;
|
|
|
|
public CncPageView()
|
|
{
|
|
InitializeComponent();
|
|
Loaded += OnLoaded;
|
|
}
|
|
|
|
private void OnLoaded(object sender, RoutedEventArgs e)
|
|
{
|
|
CncEditorViewModel editorViewModel = DataContext as CncEditorViewModel;
|
|
if (editorViewModel == null)
|
|
{
|
|
try
|
|
{
|
|
editorViewModel = ContainerLocator.Current?.Resolve<CncEditorViewModel>();
|
|
DataContext = editorViewModel;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// keep existing DataContext if resolution fails
|
|
}
|
|
}
|
|
|
|
if (editorViewModel == null || _inspectionModulePipelineViewModel != null)
|
|
return;
|
|
|
|
try
|
|
{
|
|
var imageProcessingService = ContainerLocator.Current.Resolve<IImageProcessingService>();
|
|
var persistenceService = ContainerLocator.Current.Resolve<IPipelinePersistenceService>();
|
|
var logger = ContainerLocator.Current.Resolve<ILoggerService>();
|
|
|
|
_inspectionModulePipelineViewModel = new CncInspectionModulePipelineViewModel(
|
|
editorViewModel,
|
|
imageProcessingService,
|
|
persistenceService,
|
|
logger);
|
|
|
|
InspectionModulePipelineEditor.DataContext = _inspectionModulePipelineViewModel;
|
|
InspectionModulePipelineEmptyState.DataContext = _inspectionModulePipelineViewModel;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// keep page usable even if pipeline editor host setup fails
|
|
}
|
|
}
|
|
|
|
private void CncTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
|
{
|
|
if (DataContext is CncEditorViewModel viewModel)
|
|
{
|
|
viewModel.SelectedNode = e.NewValue as CncNodeViewModel;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class NullToVisibilityConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
var invert = string.Equals(parameter as string, "Invert", StringComparison.OrdinalIgnoreCase);
|
|
var isVisible = value != null;
|
|
if (invert)
|
|
{
|
|
isVisible = !isVisible;
|
|
}
|
|
|
|
return isVisible ? Visibility.Visible : Visibility.Collapsed;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
}
|