예제 #1
0
        public override void WriteShape(ShapeBase Shape, IO.TextWriter Writer)
        {
            var Dic = new Dictionary<PointF, Int32>();
            var Sz = 0;

            ShapeWalker.Instance.TypedWalk<LinesShape>(Shape, S => { Sz++; });
            Writer.WriteLine(Sz);
            ShapeWalker.Instance.TypedWalk<LinesShape>(Shape, S => { Writer.WriteLine(S.Lines.Count); });

            Sz = 0;
            ShapeWalker.Instance.TypedWalk<LinesShape>(Shape,
                S =>
                {
                    foreach (var L in S.Lines)
                    {
                        if (!Dic.ContainsKey(L.P1))
                        {
                            Dic.Add(L.P1, Sz++);
                        }
                        if (!Dic.ContainsKey(L.P2))
                        {
                            Dic.Add(L.P2, Sz++);
                        }
                    }
                });

            Writer.WriteLine(Sz);
            foreach (var KV in Dic.OrderBy(KV => KV.Value))
            {
                Writer.Write(KV.Key.X);
                Writer.Write(" ");
                Writer.Write(KV.Key.Y);
                Writer.WriteLine();
            }

            ShapeWalker.Instance.TypedWalk<LinesShape>(Shape,
                S =>
                {
                    Writer.WriteLine();
                    foreach (var l in S.Lines)
                    {
                        Writer.Write(Dic[l.P1]);
                        Writer.Write(" ");
                        Writer.Write(Dic[l.P2]);
                        Writer.WriteLine();
                    }
                });
        }
        public override void WriteShape(ShapeBase Shape, IO.TextWriter Writer)
        {
            ShapeWalker.Instance.TypedWalk<LinesShape>(Shape,
                S =>
                {
                    foreach (var l in S.Lines)
                    {
                        Writer.WriteLine(" zone");

                        Writer.Write(l.P1.X);
                        Writer.Write(" ");
                        Writer.Write(l.P1.Y);
                        Writer.WriteLine();

                        Writer.Write(l.P2.X);
                        Writer.Write(" ");
                        Writer.Write(l.P2.Y);
                        Writer.WriteLine();
                    }
                });
        }
예제 #3
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (!DoEvents)
            {
                return;
            }

            var T = this._SelectedShape;
            if (this.treeView1.SelectedNode == null)
            {
                this._SelectedShape = null;
            }
            else
            {
                this._SelectedShape = (ShapeBase)this.treeView1.SelectedNode.Tag;
            }

            this.OnSelectedShapeChanged(T);
        }
예제 #4
0
 private void RemoveNode(ShapeBase Shape)
 {
     ShapeWalker.Instance.Walk(Shape,
         S =>
         {
             this.NodesDic.Remove(S);
             var Coll = S as ShapeCollection;
             if (Coll != null)
             {
                 this.CollsDic.Remove(Coll.Shapes);
             }
         });
     ShapeWalker.Instance.RemoveHandler(Shape, this.CollectionChangedEventHandler, this.PropertyChangedEventHandler);
 }
예제 #5
0
 private TreeNode GetNode(ShapeBase Shape)
 {
     if (Shape == null)
         return null;
     return this.NodesDic[Shape];
 }
예제 #6
0
        private TreeNode CreateNode(ShapeBase Shape)
        {
            #region ...
            //if (this.NodesDic.TryGetValue(Shape, out Node))
            //{
            //    return false;
            //}

            //Node = ShapeWalker.Instance.NonNullWalk<TreeNode>(Shape,
            //    (S, P) =>
            //    {
            //        var Bl = true;

            //        TreeNode N;
            //        if (!this.NodesDic.TryGetValue(Shape, out N))
            //        {
            //            N = new TreeNode(Shape.Name);
            //            Bl = false;
            //        }

            //        if (P != null)
            //        {
            //            P.Nodes.Add(N);
            //        }

            //        if (Bl)
            //        {
            //            return N;
            //        }

            //        //Console.WriteLine(Shape.Name);

            //        this.NodesDic.Add(Shape, N);
            //        var Coll = Shape as ShapeCollection;
            //        if (Coll != null)
            //        {
            //            this.CollsDic.Add(Coll.Shapes, Coll);
            //        }

            //        return N;
            //    });
            #endregion

            var R = ShapeWalker.Instance.Walk<TreeNode>(Shape,
                (S, P) =>
                {
                    TreeNode N = new TreeNode(S.Name) { Tag = S, Checked = this.CheckBoxGetter.Invoke(S) };

                    var PS = S as PenShape;
                    if (PS != null)
                    {
                        N.ForeColor = PS.Color;
                    }
                    //Console.Write("'{0}:{1}'", S.GetType().Name, S.Name);

                    if (P != null)
                    {
                        P.Nodes.Add(N);
                    }

                    //Console.WriteLine(Shape.Name);

                    this.NodesDic.Add(S, N);
                    var Coll = S as ShapeCollection;
                    if (Coll != null)
                    {
                        this.CollsDic.Add(Coll.Shapes, Coll);
                    }

                    return N;
                });
            ShapeWalker.Instance.AddHandler(Shape, this.CollectionChangedEventHandler, this.PropertyChangedEventHandler);

            return R;
        }
예제 #7
0
        protected virtual void OnSelectedShapeChanged(ShapeBase PreviousShape)
        {
            if (PreviousShape != null)
            {
                PreviousShape.IsSelected = false;
            }

            if (this._SelectedShape != null)
            {
                this._SelectedShape.IsSelected = true;
            }

            if (this.SelectedShapeChanged != null)
            {
                this.SelectedShapeChanged.Invoke(this, EventArgs.Empty);
            }
        }
예제 #8
0
 public void ShapeCheckBoxStateChanged(ShapeBase Shape)
 {
     var TN = this.GetNode(Shape);
     if (TN == null)
     {
         return;
     }
     TN.Checked = this.CheckBoxGetter.Invoke(Shape);
 }
예제 #9
0
        private ShapeBase RemoveNode(ShapeBase Shape)
        {
            var Parent = Shape.Parent as ShapeCollection;
            //Console.WriteLine(Shape.Parent);
            if (Parent == null)
                return Shape;

            if (Shape is IndicatorShape)
            {
                var IP = Parent as ShapeWithIndicator;
                if (IP != null && IP.Shapes.Count == 2)
                {
                    var PParent = IP.Parent as ShapeCollection;
                    if (PParent != null)
                    {
                        var I = PParent.Shapes.IndexOf(IP);
                        var J = IP.Shapes.IndexOf(Shape);

                        Shape = IP.Shapes[1 - J];
                        PParent.Shapes[I] = Shape;
                        return Shape;
                    }
                }
            }

            var II = Parent.Shapes.IndexOf(Shape);
            Parent.Shapes.RemoveAt(II);
            if (Parent.Shapes.Count == 0)
                return this.RemoveNode(Parent);

            if (II < Parent.Shapes.Count)
                return Parent.Shapes[II];
            return Parent.Shapes[II - 1];
        }
예제 #10
0
        private ShapeBase AddIndicators(ShapeBase ShapeBase)
        {
            if (ShapeBase is ShapeWithIndicator)
            {
                return ShapeBase;
            }

            var Collection = ShapeBase as ShapeCollection;
            if (Collection != null)
            {
                for (int i = 0; i < Collection.Shapes.Count; i++)
                {
                    this.AddIndicators(Collection.Shapes[i]);
                }
                return Collection;
            }

            var Shape = ShapeBase as Shape;
            if (Shape == null || Shape is IndicatorShape)
                return ShapeBase;

            var Parent = Shape.Parent as ShapeCollection;
            if (Parent == null || Parent is ShapeWithIndicator)
            {
                return ShapeBase;
            }

            var I = Parent.Shapes.IndexOf(Shape);
            var SI = new ShapeWithIndicator(Shape);
            Parent.Shapes[I] = SI;

            return SI;
        }
예제 #11
0
 public abstract void WriteShape(ShapeBase Shape, IO.TextWriter Writer);
예제 #12
0
        internal void SetParent(ShapeBase Shape)
        {
            this._Parent = Shape;

            Debug.Assert(new StackTrace().GetFrame(1).GetMethod().DeclaringType == typeof(ShapeCollection));
        }
예제 #13
0
 protected ShapeBase(SerializationInfo Info, StreamingContext Context)
 {
     Utils.Deserializing();
     this._Name = Info.GetString("Name");
     this._Parent = (ShapeBase)Info.GetValueWithType("Parent");
 }