ScanGraph2.xaml.cs 8.45 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
using FLY.ControlLibrary;
using FLY.Thick.BulkDataModule;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ThickTcpUiInWindow.UIModule;

namespace FLY.Thick.BlowingScan.UI.Client.UIModule
{
    /// <summary>
    /// ScanGraph2.xaml 的交互逻辑
    /// </summary>
    public partial class ScanGraph2 : UserControl
    {
25
        TDGage gage;
潘栩锋's avatar
潘栩锋 committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
        ScanGraphItemParam graphparam;
        public ScanGraph2()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        public void Init(int id)
        {
            //查找参数
            graphparam = ScanGraphParams.Current.Items.Find(p => p.ID == id);
            if (graphparam == null)
            {
42
                graphparam = new ScanGraphItemParam() { UiModule="scangraph2", ID = id };
潘栩锋's avatar
潘栩锋 committed
43 44 45 46 47
                ScanGraphParams.Current.Items.Add(graphparam);
                ScanGraphParams.Current.Save();
            }

            //获取设备
48
            gage = Application.Current.Properties["ThickGage"] as TDGage;
潘栩锋's avatar
潘栩锋 committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164


            GraphScan2 graph = graphscan;
            Misc.BindingOperations.SetBinding(graphparam, "ChartType", () =>
            {
                if (graphparam.ChartType == "Line")
                    graph.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                else
                    graph.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
            });

            graph.DataContext = graphparam;
            graph.SetBinding(GraphScan.TitleProperty, new Binding("Title"));
            graph.SetBinding(Grid.ColumnProperty, new Binding("Column"));
            graph.SetBinding(Grid.RowProperty, new Binding("Row"));
            graph.SetBinding(Grid.ColumnSpanProperty, new Binding("ColumnSpan"));
            graph.SetBinding(Grid.RowSpanProperty, new Binding("RowSpan"));
            graph.SetBinding(GraphScan.IsAutoTargetProperty, new Binding("IsAutoTarget"));
            graph.SetBinding(GraphScan.IsPercentProperty, new Binding("IsPercent"));
            graph.SetBinding(GraphScan.YRangePercentProperty, new Binding("YRangePercent"));

            graph.SetBinding(GraphScan.IsReversedProperty, new Binding("IsReversed") { Source = ScanGraphParams.Current });
            graph.SetBinding(GraphScan.LeftRightIsVisableProperty, new Binding("LRIsVisable") { Source = ScanGraphParams.Current });
            graph.SetBinding(GraphScan.LeftRightIsReversedProperty, new Binding("LRIsReversed") { Source = ScanGraphParams.Current });



            //报警线
            {
                graph.HasCtrlLine = false;
            }

            {
                graph.SetBinding(GraphScan.FirstBoltNoProperty, new Binding("FirstBoltNo") { Source = gage.mDynAreaService.mDynArea });

                //graph.SetValue(GraphScan.FirstIndexProperty, 0);
                //graph.SetBinding(GraphScan.LastIndexProperty, new Binding("NBolts") { Source = gage.mDynArea });

                Binding b0 = new Binding("FirstBoltNo") { Source = gage.mDynAreaService.mDynArea };
                Binding b1 = new Binding("DataBoltNoBegin") { Source = gage.mDynAreaService.mDynArea };
                Binding b2 = new Binding("DataBoltNoEnd") { Source = gage.mDynAreaService.mDynArea };
                Binding b3 = new Binding("ScanBoltNoBegin") { Source = gage.mDynAreaService.mDynArea };
                Binding b4 = new Binding("ScanBoltNoEnd") { Source = gage.mDynAreaService.mDynArea };

                {
                    MultiBinding mb = new MultiBinding() { Mode = BindingMode.OneWay, Converter = new ThickTcpUiInWindow.Converter.BoltNo2BoltIndexConverter() };
                    mb.Bindings.Add(b0);
                    mb.Bindings.Add(b1);
                    graph.SetBinding(GraphScan.DataFirstProperty, mb);
                }

                {
                    MultiBinding mb = new MultiBinding() { Mode = BindingMode.OneWay, Converter = new ThickTcpUiInWindow.Converter.BoltNo2BoltIndexConverter() };
                    mb.Bindings.Add(b0);
                    mb.Bindings.Add(b2);
                    graph.SetBinding(GraphScan.DataLastProperty, mb);
                }

                {
                    MultiBinding mb = new MultiBinding() { Mode = BindingMode.OneWay, Converter = new ThickTcpUiInWindow.Converter.BoltNo2BoltIndexConverter() };
                    mb.Bindings.Add(b0);
                    mb.Bindings.Add(b3);
                    graph.SetBinding(GraphScan.FirstIndexProperty, mb);
                }

                {
                    MultiBinding mb = new MultiBinding() { Mode = BindingMode.OneWay, Converter = new ThickTcpUiInWindow.Converter.BoltNo2BoltIndexConverter() };
                    mb.Bindings.Add(b0);
                    mb.Bindings.Add(b4);
                    graph.SetBinding(GraphScan.LastIndexProperty, mb);
                }
            }

            graph.SetBinding(GraphScan.TargetProperty, new Binding("Target") { Source = gage.mDynAreaService.mDynArea });
            graph.SetBinding(GraphScan.AlarmProperty, new Binding("Alarm") { Source = gage.mDynAreaService.mDynArea });


            //bulkdata 数据绑定!!!
            BulkDataServiceClientAdv.BulkDataGraphFrame bulkdata_client = new BulkDataServiceClientAdv.BulkDataGraphFrame();
            //graphparam 绑定到 bulkdataclient
            Misc.BindingOperations.SetBinding(graphparam, "BM", bulkdata_client, "BM");
            Misc.BindingOperations.SetBinding(graphparam, "Mix", bulkdata_client, "Mix");

            graph.SetBinding(GraphScan.Title2Property, new Binding("Info") { Source = bulkdata_client });
            graph.SetBinding(GraphScan.IsValidProperty, new Binding("Type")
            {
                Source = bulkdata_client,
                Converter = new ThickTcpUiInWindow.Converter.Equals2BoolConverter(),
                ConverterParameter = FR_DATA_TYPE.VALID
            });

            graph.DataSource = bulkdata_client.Frame;


            BulkDataServiceClientAdv.BulkDataGraphFrame bulkdata_client2 = new BulkDataServiceClientAdv.BulkDataGraphFrame();
            //graphparam 绑定到 bulkdataclient
            bulkdata_client2.BM = 0;
            bulkdata_client2.Mix = 1;
            graph.DataSource2 = bulkdata_client2.Frame;
            
            graph.ShowSettingDialogEvent += new EventHandler(delegate (object sender, EventArgs e)
            {
                ScanGraphConfig window = new ScanGraphConfig();
                window.Init((sender as GraphScan).DataContext as ScanGraphItemParam);
                window.Owner = FLY.ControlLibrary.COMMON.GetWindow(graph);
                window.ShowDialog();
            });
            
            gage.mBulkDataClient.Add(bulkdata_client);
            gage.mBulkDataClient.Add(bulkdata_client2);
        }
    }


    public class UIModule_ScanGraph2 : FLY.UI.Module.IUIModule
    {
165
        
潘栩锋's avatar
潘栩锋 committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
        /// <summary>
        /// 控件标题
        /// 它的值取决于culture
        /// </summary>
        public string Title
        {
            get
            {
                return Application.Current.FindResource("strScanGraph2") as string;
            }
        }

        /// <summary>
        /// 控件
        /// 创建时,需要给它唯一ID,让加载自己的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FrameworkElement GetComponent(int id)
        {
            ScanGraph2 graph = new ScanGraph2();
            graph.Init(id);
            return graph;
        }

        /// <summary>
        /// 控件缩略图,用于编辑界面时,大致看看
        /// 创建时,需要给它唯一ID,让加载自己的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FrameworkElement GetThumbnail(int id)
        {
            return new System.Windows.Controls.Grid();
        }


        /// <summary>
        /// 给出全部控件ID, 控件自行删除没有的参数
        /// </summary>
        /// <param name="IDs"></param>
        public void MatchParam(int[] IDs)
        {
209
            ScanGraphParams.Current.MatchParam("scangraph2",IDs);
潘栩锋's avatar
潘栩锋 committed
210 211 212
        }
    }
}