Esempio n. 1
0
        public bool CopyTow(object obj)
        {
            if (!(obj is RectLayer))
            {
                return false;
            }
            RectLayer temp = (RectLayer)obj;
            #region
            temp.BackgroundBrush = this.BackgroundBrush;
            temp.CenterX = this.CenterX;
            temp.CenterY = this.CenterY;
            temp.ElementSelectedState = this.ElementSelectedState;
            temp.Height = this.Height;
            temp.IsLocked = this.IsLocked;
            temp.IsOutlineDisplay = this.IsOutlineDisplay;
            temp.StartAndEndIconMargin = this.StartAndEndIconMargin;
            temp.Name = this.Name;
            temp.Opacity = this.Opacity;
            temp.OutlineBrush = this.OutlineBrush;
            temp.Visible = this.Visible;
            temp.Width = this.Width;
            temp.Tag = this.Tag;
            temp.EleType = this.EleType;
            temp.BorderThickness = this.BorderThickness;
            temp.SizeVisibility = this.SizeVisibility;
            temp.CLineType = this.CLineType;
            temp.MaxGroupName = this.MaxGroupName;
            temp.MaxZorder = this.MaxZorder;
            temp.CurrentPortIndex = this.CurrentPortIndex;
            temp.CurrentSenderIndex = this.CurrentSenderIndex;
            temp.RectSize = this.RectSize;
            temp.OperateEnviron = this.OperateEnviron;
            #endregion

            temp.ElementCollection = new ObservableCollection<IElement>();
            for (int i = 0; i < this.ElementCollection.Count; i++)
            {
                if (this.ElementCollection[i] is RectElement)
                {
                    RectElement rect = new RectElement();
                    rect = (RectElement)((RectElement)this.ElementCollection[i]).Clone();
                    rect.ParentElement = temp;
                    temp.ElementCollection.Add(rect);
                }
                else if (this.ElementCollection[i] is RectLayer)
                {
                    RectLayer rectLayer = new RectLayer();
                    rectLayer = (RectLayer)((RectLayer)this.ElementCollection[i]).Clone();
                    rectLayer.ParentElement = temp;
                    temp.ElementCollection.Add(rectLayer);
                }
                else if (this.ElementCollection[i] is LineElement)
                {
                    LineElement lineElement = new LineElement();
                    ((LineElement)this.ElementCollection[i]).CopyTo(lineElement);
                    lineElement.ParentElement = temp;
                    temp.ElementCollection.Add(lineElement);
                }
            }
            for (int i = 0; i < temp.ElementCollection.Count; i++)
            {
                if (temp.ElementCollection[i] is LineElement)
                {
                    for (int j = 0; j < temp.ElementCollection.Count; j++)
                    {
                        if ((temp.ElementCollection[j] is RectElement) && (((LineElement)temp.ElementCollection[i]).FrontElement.ZOrder == temp.ElementCollection[j].ZOrder))
                        {
                            ((LineElement)temp.ElementCollection[i]).FrontElement=(RectElement)temp.ElementCollection[j];
                        }
                        if ((temp.ElementCollection[j] is RectElement) && (((LineElement)temp.ElementCollection[i]).EndElement.ZOrder == temp.ElementCollection[j].ZOrder))
                        {
                            ((LineElement)temp.ElementCollection[i]).EndElement = (RectElement)temp.ElementCollection[j];
                        }
                    }
                    ((LineElement)temp.ElementCollection[i]).FrontElement.EndLine = (LineElement)temp.ElementCollection[i];
                    ((LineElement)temp.ElementCollection[i]).EndElement.FrontLine = (LineElement)temp.ElementCollection[i];
                }
            }
            return true;
        }
 public object Clone()
 {
     LineElement newObj = new LineElement();
     bool res = this.CopyTo(newObj);
     if (!res)
     {
         return null;
     }
     else
     {
         return newObj;
     }
 }