Example #1
0
        private void UpdateUI(BayViewModel model)
        {
            //更新拖链小车位置
            if (model.MinCartPoint != null && model.MinCartPoint.X != 0 && model.MinCartPoint.Y != 0)
            {
                minCart.SetValue(Canvas.LeftProperty, model.MinCartPoint.X);
                minCart.SetValue(Canvas.TopProperty, model.MinCartPoint.Y);
            }
            //更新箱区
            if (!CompareBoxs(lastBoxs, model.Boxs))
            {
                UpdateBoxAreaUI(model.Boxs);
            }

            //更新移动箱的位置
            if (model.MovingBoxPoint != null && model.MovingBoxPoint.X != 0 && model.MovingBoxPoint.Y != 0)
            {
                //设置拖链小车的吊具长度
                if (model.MinCartHeight > 0)
                {
                    minCart.Height = model.MinCartHeight;
                }

                movingBox.SetValue(Canvas.LeftProperty, model.MovingBoxPoint.X);
                movingBox.SetValue(Canvas.TopProperty, model.MovingBoxPoint.Y);
                movingBox.BoxStatus = 1;
            }
            else
            {
                movingBox.BoxStatus = 2;
            }

            //更新集卡
            leftCart.ContainerBoxHeight = movingBox.Height;
            leftCart.ContainerBoxWidth  = movingBox.Width;

            rightCart.ContainerBoxHeight = movingBox.Height;
            rightCart.ContainerBoxWidth  = movingBox.Width;

            if (model.HaveLeftCart)
            {
                leftCart.Visibility = Visibility.Visible;
            }
            else
            {
                leftCart.Visibility = Visibility.Collapsed;
            }

            if (model.HaveRightCart)
            {
                rightCart.Visibility = Visibility.Visible;
            }
            else
            {
                rightCart.Visibility = Visibility.Collapsed;
            }
        }
Example #2
0
        public BayViewCanvas()
        {
            InitializeComponent();
            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            var model = new BayViewModel();

            model.HaveLeftCart = true;
            model.Boxs         = GetInitBoxData();
            UpdateUI(model);
            //this.MouseMove += BayViewCanvas_MouseMove;
        }
Example #3
0
        /// <summary>
        /// 箱到箱
        /// </summary>
        public void Test3()
        {
            minCart.Height = 45;

            var list  = new List <BayViewModel>();
            var model = new BayViewModel();

            model.HaveLeftCart = true;
            model.Boxs         = lastBoxs;
            list.Add(model);
            BayViewModel tmp = new BayViewModel();

            try
            {
                StreamReader sr   = new StreamReader("Data/4,1To1,4point.txt");
                string       str  = string.Empty;
                bool         flag = false; //初始化吊具长度变量
                while (!sr.EndOfStream)
                {
                    str = sr.ReadLine();
                    if (str != null)
                    {
                        var split = str.Split(',');
                        if (split != null && split.Length == 2)
                        {
                            tmp = model.Clone() as BayViewModel;
                            tmp.MovingBoxPoint = new Point(double.Parse(split[0]), double.Parse(split[1]));
                            if (flag)
                            {
                                tmp.MinCartHeight = tmp.MovingBoxPoint.Y + 5;
                            }
                            else
                            {
                                tmp.MinCartHeight = minCart.Height + 5;
                            }
                            //计算小车与移动箱的居中坐标
                            var minCartX = tmp.MovingBoxPoint.X - (minCart.Width - movingBox.Width) / 2;
                            tmp.MinCartPoint = new Point(minCartX, (double)minCart.GetValue(Canvas.TopProperty));
                            tmp.Boxs[4, 1]   = 2;
                            list.Add(tmp);

                            while (!flag)
                            {
                                tmp = tmp.Clone() as BayViewModel;
                                tmp.MinCartHeight += 5;
                                list.Add(tmp);
                                if (tmp.MinCartHeight > tmp.MovingBoxPoint.Y)
                                {
                                    tmp.MinCartHeight += 5;
                                    break;
                                }
                            }
                            flag = true;
                        }
                    }
                }
            }
            catch (Exception)
            {
            }


            Task.Factory.StartNew(() =>
            {
                foreach (var item in list)
                {
                    Thread.Sleep(1 * 100);
                    this.Dispatcher.Invoke(new Action(() => { UpdateUI(item); }), null);
                }
            });
        }