DatistEQ之自定义节点

作者: 了无_数据科学 | 来源:发表于2021-04-11 21:42 被阅读0次

    本文旨在说明,DatistEQ原生节点及编辑器的定义方法。
    定义节点

    using System;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Text.RegularExpressions;
    using BcDataMining.Node.Define;
    using BcDataMining.Node.PluginNode;
    
    namespace BcDataMining.Node
    {
    
        //自定义分组栏中的位置
        [NodeGroup("时间序列", "GEOIST")]
        public class NodeGeoTest:NodeBase 
        {
            public NodeGeoTest()
            {
                Name = "NodeGeoTest";
                Nodetype = NodeType.OptField;
    
                SystemToolTip = "测试";
    
                //云节点标记
                IsCloud = true;
            } 
         
            public Employee Emp { get; set; }=new Employee();
        }
    
        public enum Gender
        {
            [Display(Name = "男")]
            Man,
            [Display(Name = "女")]
            Woman 
        }
    
    
        /// <summary>
        /// Serializable特性,用于Clone
        /// </summary>
        [Serializable]
        public class Employee:IDataErrorInfo
        {
            /// <summary>
            /// 特性Display需要引用System.ComponentModel.DataAnnotations
            /// </summary> 
            [Display(Name = "姓名",GroupName = "个人信息")]
            public string Name { get; set; }
    
            [Display(Name = "性别", GroupName = "个人信息")]
            public Gender Gender { get; set; }
             
    
            [Display(Name = "工资", GroupName = "工作信息")]
            public int Salary { get; set; }
    
            [Display(Name = "电话", GroupName = "工作信息", Description = "以P字母结尾")]
            public string PhoneNum { get; set; }
    
            
            [Display(Name = "时间", GroupName = "工作信息")]
            public DateTime StartingDate { get; set; }
    
            [ReadOnly(true)]
            [Display(Name = "创建日志", GroupName = "日志")]
            public DateTime CreateTime { get; set; }=DateTime.Now;
    
            #region 用于验证 IDataErrorInfo
         
            public string this[string columnName]
            {
                get
                {
                    if (columnName == nameof(Salary))
                    {
                        return this.Salary < 100 && this.Salary > 0 ? string.Empty : "Value should be in the range of (0, 100)";
                    }
                    if (columnName == nameof(PhoneNum))
                    {
                        return this.PhoneNum != null && Regex.IsMatch(this.PhoneNum, @"^[0-9]+[\p{L}]") ? string.Empty : @"Value should math the regex: ^[0-9]+[\p{L}]";
                    }
                    if (columnName == nameof(StartingDate))
                    {
                        return this.StartingDate.Year > 1900 ? string.Empty : "Date should be after 1/1/1900";
                    }
                    return string.Empty;
                }
            }
    
            [Browsable(false)]
            public string Error { get; }
            #endregion
    
        }
    }
    
    
    

    定义节点编辑器

    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Windows.Data;
    using BcDataMining.DataExtension;
    using BcDataMining.EditorEx;
    using BcDataMining.Node;
    using BcDataMining.Node.Define;
    using Telerik.Windows.Controls.Data.PropertyGrid;
    using TelerikHelper;
    
    namespace BcDataMining.NodeEditor
    {
        /// <summary>
        /// 命名规则为:节点名+Editor,需遵循INodeEditor接口
        /// </summary>
        public partial class NodeGeoTestEditor : INodeEditor, INotifyPropertyChanged,
            INodeEditorDefaultSize//接口INodeEditorDefaultSize,用于设置节点编辑器的初始尺寸
        {
            public NodeGeoTestEditor()
            {
                InitializeComponent();
            }
            private NodeGeoTest _eNode;
    
            public NodeGeoTest ENode
            {
                get { return _eNode; }
                set
                {
                    _eNode = value;
                    PropertyChanged.Raise(() => ENode);
                }
            }
    
            public string Title { get; set; }
            public bool LoadParameters(INode aNode)
            {
                if (!(aNode is NodeGeoTest)) return false;
                ENode = aNode as NodeGeoTest;
    
                PropertyGrid1.Item = ENode.Emp.Clone();//克隆一个值,而不是在原来值上修改。
                return true;
            }
    
            public bool SaveParameters()
            {
                ENode.Emp=PropertyGrid1.Item as Employee;
                return true;
            }
    
            public void AppendEditor(List<INodeEditor> nodeEditors)
            {
                tabControl1.AppendEditors(nodeEditors);
            }
    
            public event PropertyChangedEventHandler PropertyChanged;
    
    
            /// <summary>
            /// 添加验证事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void PropertyGrid1_OnAutoGeneratingPropertyDefinition(object sender, AutoGeneratingPropertyDefinitionEventArgs e)
            {
                (e.PropertyDefinition.Binding as Binding).ValidatesOnDataErrors = true;
                (e.PropertyDefinition.Binding as Binding).NotifyOnValidationError = true;
            }
        }
    }
    
    
    
    

    对应的xaml文件。

    <UserControl x:Class="BcDataMining.NodeEditor.NodeGeoTestEditor"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:local="clr-namespace:BcDataMining.NodeEditor"
                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                 mc:Ignorable="d" 
                 d:DesignHeight="450" d:DesignWidth="800" 
                 Width="810" Height="570"> <!--Width,Height,用于设置节点编辑器的初始尺寸,类需遵循INodeEditorDefaultSize-->
        <Grid>
            <telerik:RadTabControl HorizontalAlignment="Stretch" x:Name="tabControl1" Margin="0" TabStripPlacement="Top"
                        VerticalAlignment="Stretch" Grid.RowSpan="3">
    
                <telerik:RadTabItem Header="设置" IsSelected="True">
                    <Grid Margin="0">
                        <telerik:RadPropertyGrid Grid.Row="0" x:Name="PropertyGrid1" IsGrouped="True"
                                                 AutoGeneratingPropertyDefinition="PropertyGrid1_OnAutoGeneratingPropertyDefinition" />
    
                        <!--<telerik:RadPropertyGrid Grid.Row="0" x:Name="PropertyGrid1" 
                                                 RenderMode="Flat" 
                                                 AutoGeneratePropertyDefinitions="False"  
                                                 IsGrouped="True">
                            <telerik:RadPropertyGrid.PropertyDefinitions>
                                <telerik:PropertyDefinition Binding="{Binding FirstName}" GroupName="Group Name" DisplayName="First Name" Description="姓氏"/>
                                <telerik:PropertyDefinition Binding="{Binding LastName}" GroupName="Group Name" DisplayName="Last Name" Description="名字"/>
                                <telerik:PropertyDefinition Binding="{Binding Occupation}" GroupName="Group Title" DisplayName="Title"/>
                                <telerik:PropertyDefinition Binding="{Binding Gender}" GroupName="Group Gender" DisplayName="性别"/>
                            </telerik:RadPropertyGrid.PropertyDefinitions>
                        </telerik:RadPropertyGrid>-->
                    </Grid>
                </telerik:RadTabItem>
    
            </telerik:RadTabControl>
        </Grid>
    </UserControl>  
    

    节点的图标定义。图标大小建议小于100*100像素。

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:sys="clr-namespace:System;assembly=mscorlib">
    
        <!--命名规则,Stl+节点名称。图片的生成操作需指定为 Resource-->
        <ImageBrush x:Key="StlNodeGeoTest" ImageSource="/ExGeoistEditor;component/Images/NodeGeoTest.png"
                    Stretch="Fill" TileMode="None"
                    Viewport="10,10,30,30" ViewportUnits="Absolute" />
     
    </ResourceDictionary>
    

    节点效果:


    节点效果

    相关文章

      网友评论

        本文标题:DatistEQ之自定义节点

        本文链接:https://www.haomeiwen.com/subject/qvezkltx.html