Ejemplo n.º 1
0
 /// <summary>
 /// 生成线路
 /// </summary>
 /// <param name="MapIN"></param>
 public void AddLine(Canvas MapIN, bool type)
 {
     if (GetCircuitType.Equals(CircuitType.Line))                                                 //绘制直线
     {
         Path path = painting.DrawingLine(Pairsarray[0].SetPoint, Pairsarray[1].SetPoint, MapIN); //绘制直线
         MapInstrument.wirePointArrays.Add(new WirePointArray()
         {
             circuitType = CircuitType.Line, GetPath = path, GetPoint = Pairsarray[0], GetWirePoint = Pairsarray[1]
         });
         if (type)
         {
             MainwirePoint.Add(new WirePointArray()
             {
                 circuitType = CircuitType.Line, GetPath = path, GetPoint = Pairsarray[0], GetWirePoint = Pairsarray[1]
             });
         }
     }
     else if (GetCircuitType.Equals(CircuitType.Semicircle))
     {
         Path path = painting.DrawingSemicircle(Pairsarray[0].SetPoint, Pairsarray[1].SetPoint, MapIN);//绘制半圆
         MapInstrument.wirePointArrays.Add(new WirePointArray()
         {
             circuitType = CircuitType.Semicircle, GetPath = path, GetPoint = Pairsarray[0], GetWirePoint = Pairsarray[1]
         });
         if (type)
         {
             MainwirePoint.Add(new WirePointArray()
             {
                 circuitType = CircuitType.Semicircle, GetPath = path, GetPoint = Pairsarray[0], GetWirePoint = Pairsarray[1]
             });
         }
     }
     else if (GetCircuitType.Equals(CircuitType.Broken))//折线
     {
         List <Path> Pathr = painting.DrawingBroken(Pairsarray[0].SetPoint, Pairsarray[1].SetPoint, MapIN);
         MapInstrument.wirePointArrays.Add(new WirePointArray()
         {
             circuitType = CircuitType.Broken, Paths = Pathr, GetPoint = Pairsarray[0], GetWirePoint = Pairsarray[1]
         });
         if (type)
         {
             MainwirePoint.Add(new WirePointArray()
             {
                 circuitType = CircuitType.Broken, Paths = Pathr, GetPoint = Pairsarray[0], GetWirePoint = Pairsarray[1]
             });
         }
     }
 }
Ejemplo n.º 2
0
        public void AddCircuit(int tmp, Point point)
        {
            #region 判断位置是否存在
            bool TagExistx = false; //判断位置是否存在
            foreach (WirePoint item in Pairsarray)
            {
                if (tmp.Equals(item.TagID))//如果TagID相同则存在
                {
                    TagExistx = true;
                }
            }
            #endregion

            #region 所有Tag改为原色
            foreach (int item in valuePairs.Keys)
            {
                valuePairs[item].Background = Brushes.Black;
            }
            #endregion

            if (!TagExistx) //位置不存在则添加,防止重复添加
            {
                Pairsarray.Add(new WirePoint {
                    TagID = tmp, SetPoint = point
                });
            }

            #region 线路绘制点改为红色
            foreach (int item in valuePairs.Keys)
            {
                foreach (WirePoint itms in Pairsarray)
                {
                    if (itms.TagID.Equals(item))
                    {
                        valuePairs[item].Background = new SolidColorBrush(Colors.Red);
                    }
                }
            }
            #endregion

            if (Pairsarray.Count.Equals(2))//起始位置存在则开始绘制
            {
                if (!GetCircuitType.Equals(CircuitType.Clear) && !GetCircuitType.Equals(CircuitType.Align) && !GetCircuitType.Equals(CircuitType.vertical))
                {
                    #region 判断线路是否存在
                    bool   lineExistx = false;                                               //判断线路是否存在
                    double tr         = Pairsarray[0].SetPoint.X - Pairsarray[1].SetPoint.X; //大于0下方上方小于0上方
                    foreach (WirePointArray item in wirePointArrays)
                    {
                        if (GetCircuitType.Equals(CircuitType.Semicircle))
                        {
                            //如果(线路起始位置和结束位置一一对应)则视为线路存在
                            if (((item.GetPoint.SetPoint.Equals(Pairsarray[0].SetPoint) && item.GetWirePoint.SetPoint.Equals(Pairsarray[1].SetPoint)) || (item.GetPoint.SetPoint.Equals(Pairsarray[1].SetPoint) && item.GetWirePoint.SetPoint.Equals(Pairsarray[0].SetPoint))) && item.circuitType.Equals(GetCircuitType) && item.Direction.Equals(tr > 0 ? 1 : 0))
                            {
                                lineExistx = true;
                            }
                        }
                        else if (GetCircuitType.Equals(CircuitType.Broken))
                        {
                            double diff = Pairsarray[0].SetPoint.Y - Pairsarray[1].SetPoint.Y;
                            //如果(线路起始位置和结束位置一一对应)则视为线路存在
                            if (((item.GetPoint.SetPoint.Equals(Pairsarray[0].SetPoint) && item.GetWirePoint.SetPoint.Equals(Pairsarray[1].SetPoint)) || (item.GetPoint.SetPoint.Equals(Pairsarray[1].SetPoint) && item.GetWirePoint.SetPoint.Equals(Pairsarray[0].SetPoint))) && item.circuitType.Equals(GetCircuitType) && item.Direction.Equals(diff < 0 ? 0 : 1))
                            {
                                lineExistx = true;
                            }
                        }
                        else
                        {
                            //如果(线路起始位置和结束位置一一对应)或(线路起始位置和结束位置相同,结束位置和起始位置相同)则视为线路存在
                            if (((item.GetPoint.SetPoint.Equals(Pairsarray[0].SetPoint) && item.GetWirePoint.SetPoint.Equals(Pairsarray[1].SetPoint)) || (item.GetPoint.SetPoint.Equals(Pairsarray[1].SetPoint) && item.GetWirePoint.SetPoint.Equals(Pairsarray[0].SetPoint))) && item.circuitType.Equals(GetCircuitType))
                            {
                                lineExistx = true;
                            }
                        }
                    }
                    #endregion

                    if (!lineExistx)//线路不存在则绘制线路
                    {
                        AddLine();
                    }
                    Pairsarray.Clear();//移除暂存起始结束点
                }
                else if (GetCircuitType.Equals(CircuitType.Clear))
                {
                    ClearCircuit(Pairsarray[0].TagID, Pairsarray[1].TagID);//清除路线
                }
                else if (GetCircuitType.Equals(CircuitType.Align))
                {
                    if (!Pairsarray[1].SetPoint.X.Equals(Pairsarray[0].SetPoint.X))
                    {
                        DeleteLine();
                        valuePairs[Pairsarray[1].TagID].Margin = new Thickness(valuePairs[Pairsarray[1].TagID].Margin.Left, valuePairs[Pairsarray[0].TagID].Margin.Top, 0, 0);
                        MouseMove(new Point()
                        {
                            X = valuePairs[Pairsarray[1].TagID].Margin.Left + 19, Y = valuePairs[Pairsarray[1].TagID].Margin.Top + 11.5
                        }, Pairsarray[1].TagID);
                        Pairsarray.Clear();
                    }
                }
                else if (GetCircuitType.Equals(CircuitType.vertical))
                {
                    if (!Pairsarray[1].SetPoint.Y.Equals(Pairsarray[0].SetPoint.Y))
                    {
                        DeleteLine();
                        valuePairs[Pairsarray[1].TagID].Margin = new Thickness(valuePairs[Pairsarray[0].TagID].Margin.Left, valuePairs[Pairsarray[1].TagID].Margin.Top, 0, 0);
                        MouseMove(new Point()
                        {
                            X = valuePairs[Pairsarray[1].TagID].Margin.Left + 19, Y = valuePairs[Pairsarray[1].TagID].Margin.Top + 11.5
                        }, Pairsarray[1].TagID);
                        Pairsarray.Clear();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void AddCircuit(int tmp, Point point)
        {
            #region 判断位置是否存在
            bool TagExistx = false; //判断位置是否存在
            foreach (WirePoint item in Pairsarray)
            {
                if (tmp.Equals(item.TagID))//如果TagID相同则存在
                {
                    TagExistx = true;
                }
            }
            #endregion

            #region 所有Tag改为原色
            foreach (int item in valuePairs.Keys)
            {
                valuePairs[item].Background = new SolidColorBrush(Color.FromRgb(80, 150, 255));
            }
            #endregion

            if (!TagExistx) //位置不存在则添加,防止重复添加
            {
                Pairsarray.Add(new WirePoint {
                    TagID = tmp, SetPoint = point
                });
            }

            #region 线路绘制点改为红色
            foreach (int item in valuePairs.Keys)
            {
                foreach (WirePoint itms in Pairsarray)
                {
                    if (itms.TagID.Equals(item))
                    {
                        valuePairs[item].Background = new SolidColorBrush(Colors.Red);
                    }
                }
            }
            #endregion

            if (Pairsarray.Count.Equals(2))//起始位置存在则开始绘制
            {
                if (!GetCircuitType.Equals(CircuitType.Clear))
                {
                    #region 判断线路是否存在
                    bool   lineExistx = false;                                               //判断线路是否存在
                    double tr         = Pairsarray[0].SetPoint.X - Pairsarray[1].SetPoint.X; //大于0下方上方小于0上方
                    foreach (WirePointArray item in wirePointArrays)
                    {
                        if (GetCircuitType.Equals(CircuitType.Semicircle))
                        {
                            //如果(线路起始位置和结束位置一一对应)则视为线路存在
                            if (((item.GetPoint.SetPoint.Equals(Pairsarray[0].SetPoint) && item.GetWirePoint.SetPoint.Equals(Pairsarray[1].SetPoint)) || (item.GetPoint.SetPoint.Equals(Pairsarray[1].SetPoint) && item.GetWirePoint.SetPoint.Equals(Pairsarray[0].SetPoint))) && item.circuitType.Equals(GetCircuitType) && item.Direction.Equals(tr > 0 ? 1 : 0))
                            {
                                lineExistx = true;
                            }
                        }
                        else if (GetCircuitType.Equals(CircuitType.Broken))
                        {
                            double diff = Pairsarray[0].SetPoint.Y - Pairsarray[1].SetPoint.Y;
                            //如果(线路起始位置和结束位置一一对应)则视为线路存在
                            if (((item.GetPoint.SetPoint.Equals(Pairsarray[0].SetPoint) && item.GetWirePoint.SetPoint.Equals(Pairsarray[1].SetPoint)) || (item.GetPoint.SetPoint.Equals(Pairsarray[1].SetPoint) && item.GetWirePoint.SetPoint.Equals(Pairsarray[0].SetPoint))) && item.circuitType.Equals(GetCircuitType) && item.Direction.Equals(diff < 0 ? 0 : 1))
                            {
                                lineExistx = true;
                            }
                        }
                        else
                        {
                            //如果(线路起始位置和结束位置一一对应)或(线路起始位置和结束位置相同,结束位置和起始位置相同)则视为线路存在
                            if (((item.GetPoint.SetPoint.Equals(Pairsarray[0].SetPoint) && item.GetWirePoint.SetPoint.Equals(Pairsarray[1].SetPoint)) || (item.GetPoint.SetPoint.Equals(Pairsarray[1].SetPoint) && item.GetWirePoint.SetPoint.Equals(Pairsarray[0].SetPoint))) && item.circuitType.Equals(GetCircuitType))
                            {
                                lineExistx = true;
                            }
                        }
                    }
                    #endregion

                    if (!lineExistx)//线路不存在则绘制线路
                    {
                        AddLine();
                        foreach (WirePoint item in Pairsarray)//重新添加Tag
                        {
                            GetCanvas.Children.Add(valuePairs[item.TagID]);
                        }
                    }
                    Pairsarray.Clear();//移除暂存起始结束点
                }
                else
                {
                    ClearCircuit();//清除路线
                }
            }
        }