예제 #1
0
파일: Form1.cs 프로젝트: donRipat/OOPlab6
        private void separateGroupToolStripMenuItem_Click
            (object sender, EventArgs e)
        {
            if (s == null)
            {
                return;
            }
            DoublyLinkedList ungr = s.Ungroup();

            if (ungr == null)
            {
                return;
            }
            shapes.Search(s);
            shapes.Delete_current();
            ungr.Set_current_first();
            for (bool cond = !ungr.Is_empty(); cond;
                 cond = ungr.Step_forward())
            {
                shapes.Push_back(ungr.Current.Shape);
            }
            s = shapes.Head.Shape;
            Draw_all_shapes();
            shapeIndex = 0;
        }
예제 #2
0
 public bool Contains(AShape aShape)
 {
     lock (shapes)
     {
         return(shapes.Contains(aShape));
     }
 }
예제 #3
0
파일: Geom.cs 프로젝트: Chandler0591/wMaper
 /// <summary>
 /// 移除对象
 /// </summary>
 public sealed override void Remove()
 {
     if (!MatchUtils.IsEmpty(this.Target) && this.Target.Enable && this.Enable && !MatchUtils.IsEmpty(this.handle))
     {
         if (this.Obscure(this.Target.Listen.ZoomEvent, this.Redraw))
         {
             if (!this.Obscure(this.Target.Listen.SwapEvent, this.Redraw))
             {
                 this.Observe(this.Target.Listen.ZoomEvent, this.Redraw);
             }
             else
             {
                 if (!this.Target.Symbol.Draw.Remove(this.Index))
                 {
                     this.Observe(this.Target.Listen.ZoomEvent, this.Redraw);
                     this.Observe(this.Target.Listen.SwapEvent, this.Redraw);
                 }
                 else
                 {
                     // 擦除图形
                     this.handle.Earse();
                     {
                         this.Facade = null;
                         this.handle = null;
                         this.Target = null;
                     }
                 }
             }
         }
     }
 }
예제 #4
0
파일: Geom.cs 프로젝트: Chandler0591/wMaper
 public Geom()
     : base()
 {
     this.arise  = null;
     this.matte  = false;
     this.amend  = false;
     this.handle = null;
 }
예제 #5
0
        private void OnColorChanged(AShape shape)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            ShapeCollection shapeCollection = EnsureEntities(shape.Color);

            shapeCollection.Add(shape);
        }
예제 #6
0
 public void OnPropertyChanged(AShape shape)
 {
     if (shape.Color != Color)
     {
         Remove(shape);
         ColorChanged?.Invoke(shape);
     }
     else
     {
         IsModified = true;
     }
 }
예제 #7
0
 public MagicGraphic(IGraphic panel)
 {
     if (!MatchUtils.IsEmpty(panel))
     {
         this.count = 0;
         this.cache = null;
         this.panel = panel;
         // 事件绑定
         {
             this.InitializeEventListener(this.panel as FrameworkElement);
         }
     }
 }
예제 #8
0
        public bool Remove(AShape shape)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            IsModified = true;

            lock (shapes)
            {
                return(shapes.Remove(shape));
            }
        }
예제 #9
0
        public void UpdateStickyShapes(AShape s)
        {
            DoublyLinkedList t = new DoublyLinkedList();

            Set_current_first();
            for (bool cond = !Is_empty(); cond; cond = Step_forward())
            {
                if (CurShape != s && s.CloseTo(CurShape))
                {
                    t.Push_back(CurShape);
                }
            }
            s.ChangeObservers(t);
        }
예제 #10
0
파일: Form1.cs 프로젝트: donRipat/OOPlab6
 private void makeGroupToolStripMenuItem_Click(object sender,
                                               EventArgs e)
 {
     if (shapeIndex == 4)
     {
         shapeIndex = 0;
         shapes.Push_back(gr);
         s = gr;
         Draw_all_shapes();
         gr = new CGroup();
     }
     else
     {
         shapeIndex = 4;
     }
 }
예제 #11
0
        public void Add(AShape shape)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            IsModified = true;

            shape.ChangeHandler = this;

            lock (shapes)
            {
                shapes.Add(shape);
            }
        }
예제 #12
0
        public static void PlayWithShapes()
        {
            Rectangle r1 = new Rectangle();
            AShape    a1 = new Square();
            var       a2 = new Square();
            IShape    i1 = new Triangle();
            Object    o  = 10;
            int       i  = (int)o;
            int       i2 = (int)((Object)a2);

            var arr1 = new AShape[] { r1, a1, a2 };

            PrintShapes(arr1);
            PrintShapes(r1);
            PrintShapes(a1, a2, arr1);

            System.Console.WriteLine(r1.Sides);
        }
예제 #13
0
        /// <summary>
        /// 清空舞台
        /// </summary>
        public void ClearStage()
        {
            // 几何对象
            AShape shape = null;
            // 图形对象
            DrawingVisual brush = null;

            for (int i = this.panel.AmountVisual() - 1; i > -1; i--)
            {
                if (!MatchUtils.IsEmpty(brush = this.panel.ObtainVisual(i) as DrawingVisual) && !MatchUtils.IsEmpty(shape = brush.GetValue(MagicGraphic.Nexus) as AShape))
                {
                    shape.Earse();
                    {
                        shape = null;
                        brush = null;
                    }
                }
            }
        }
예제 #14
0
 //  Search given shape and set current to it if found
 public bool Search(AShape s)
 {
     if (s != null)
     {
         DoublyNode t = current;
         Set_current_first();
         for (bool cond = !Is_empty(); cond;
              cond = Step_forward())
         {
             if (Current.Shape == s)
             {
                 return(true);
             }
         }
         current = t;
     }
     Notify();
     return(false);
 }
예제 #15
0
파일: Form1.cs 프로젝트: donRipat/OOPlab6
 private void loadShapesToolStripMenuItem_Click(object sender,
                                                EventArgs e)
 {
     try
     {
         using (StreamReader sr = new StreamReader(shapesPath,
                                                   false))
             shapes.LoadShapes(sr);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     if (shapes.Is_empty())
     {
         return;
     }
     s = shapes.Tail.Shape;
     Draw_all_shapes();
     shapeIndex = 0;
 }
예제 #16
0
파일: Tree.cs 프로젝트: donRipat/OOPlab6
        protected void ProcessNode(TreeNode tn, AShape a)
        {
            if (a != null)
            {
                tn.Text = a.ToString().Substring(8);
            }
            CGroup gr = a as CGroup;

            if (gr != null)
            {
                DoublyLinkedList L = gr.Shapes;
                int i = 0;
                L.Set_current_first();
                for (bool cond = !L.Is_empty(); cond;
                     cond = L.Step_forward())
                {
                    tn.Nodes.Add(new TreeNode());
                    ProcessNode(tn.Nodes[i++], L.Current.Shape);
                }
            }
        }
예제 #17
0
        public override AShape CreateShape(string code)
        {
            AShape ans = null;

            if (code == "C")
            {
                ans = new CCircle();
            }
            if (code == "S")
            {
                ans = new CSegment();
            }
            if (code == "P")
            {
                ans = new Polygon();
            }
            if (code == "G")
            {
                ans = new CGroup();
            }
            return(ans);
        }
예제 #18
0
        //  Add new shape to the front of the list
        public bool Push_front(AShape shape)
        {
            if (shape == null)
            {
                return(false);
            }
            DoublyNode fresh = new DoublyNode(shape);

            if (count > 0)
            {
                head.prev  = fresh;
                fresh.next = head;
                head       = fresh;
            }
            else
            {
                tail = fresh;
                head = fresh;
            }
            current = head;
            ++count;
            Notify();
            return(true);
        }
예제 #19
0
        //  Add new shape to the back of the list
        public bool Push_back(AShape shape)
        {
            if (shape == null)
            {
                return(false);
            }
            DoublyNode fresh = new DoublyNode(shape);

            if (count > 0)
            {
                fresh.prev = tail;
                tail.next  = fresh;
                tail       = fresh;
            }
            else
            {
                tail = fresh;
                head = fresh;
            }
            current = tail;
            ++count;
            Notify();
            return(true);
        }
예제 #20
0
 public DoublyNode(AShape shape)
 {
     this.shape = shape;
     prev       = null;
     next       = null;
 }
예제 #21
0
파일: Form1.cs 프로젝트: donRipat/OOPlab6
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     if (s == null)
     {
         return;
     }
     if (e.KeyCode == Keys.Add ||
         e.KeyCode == Keys.Subtract)
     {
         int sz;
         if (e.KeyCode == Keys.Add)
         {
             sz = res;
         }
         else
         {
             sz = -res;
         }
         s.Resize(sz);
         if (s.sticky)
         {
             shapes.UpdateStickyShapes(s);
         }
     }
     else if (e.KeyCode >= Keys.NumPad1 &&
              e.KeyCode <= Keys.NumPad9)
     {
         s.Move(e.KeyCode - Keys.NumPad0, mov);
         if (s.sticky)
         {
             shapes.UpdateStickyShapes(s);
         }
     }
     else if (e.KeyCode == Keys.C)
     {
         s.Chng_clr(-1);
         s.Draw(g, w);
     }
     else if (e.KeyCode == Keys.Delete || e.KeyCode == Keys.D)
     {
         if (shapes.Count == 0)
         {
             return;
         }
         shapes.Search(s);
         shapes.Delete_current();
         if (shapes.Tail != null)
         {
             s = shapes.Tail.Shape;
         }
         else
         {
             s = null;
         }
     }
     else if (e.KeyCode == Keys.S)
     {
         s.Switch();
     }
     if (e.KeyCode != Keys.C || e.KeyCode != Keys.S)
     {
         Draw_all_shapes();
     }
     UpdateTB();
     e.Handled = true;
 }
예제 #22
0
        /// <summary>
        /// 鼠标移动事件处理函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnMouseMoveEventListener(object sender, MouseEventArgs e)
        {
            AShape shape = null;

            try
            {
                HitTestResult target = VisualTreeHelper.HitTest(this.canvas, e.GetPosition(this.canvas));
                if (!MatchUtils.IsEmpty(target) && !MatchUtils.IsEmpty(target.VisualHit))
                {
                    shape = (target.VisualHit as DrawingVisual).GetValue(MagicGraphic.Nexus) as AShape;
                }
            }
            catch
            {
                shape = null;
            }
            finally
            {
                if (!MatchUtils.IsEmpty(shape))
                {
                    this.canvas.Cursor  = shape.Mouse;
                    this.canvas.ToolTip = shape.Title;
                    try
                    {
                        shape.OnMouseMove(e);
                    }
                    finally
                    {
                        if (!shape.Equals(cache))
                        {
                            try
                            {
                                if (!MatchUtils.IsEmpty(cache))
                                {
                                    cache.OnMouseLeave(e);
                                }
                            }
                            finally
                            {
                                (cache = shape).OnMouseEnter(e);
                            }
                        }
                    }
                }
                else
                {
                    this.canvas.Cursor  = null;
                    this.canvas.ToolTip = null;
                    try
                    {
                        if (!MatchUtils.IsEmpty(cache))
                        {
                            cache.OnMouseLeave(e);
                        }
                    }
                    finally
                    {
                        cache = null;
                    }
                }
            }
        }
예제 #23
0
파일: Form1.cs 프로젝트: donRipat/OOPlab6
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            treeClicked = false;

            if (shapeIndex == 0)
            {
                PointF p = new PointF(e.X, e.Y);
                shapes.Set_current_first();
                for (bool cond = !shapes.Is_empty(); cond;
                     cond = shapes.Step_forward())
                {
                    if (shapes.Current.Shape.Contains(p))
                    {
                        if (s != null)
                        {
                            s.Draw(g, w);
                        }
                        s = shapes.Current.Shape;
                        s.Draw(g, w, 4);
                        UpdateTB();
                        return;
                    }
                }
            }

            if (shapeIndex == 1)
            {
                if (s != null)
                {
                    s.Draw(g, w);
                }
                s = new CCircle(e.X, e.Y, 100);
                s.Draw(g, w, 4);
                shapes.Push_back(s);
            }

            if (shapeIndex == 2)
            {
                if (a == default(PointF))
                {
                    a = new PointF(e.X, e.Y);
                }
                else
                {
                    b = new PointF(e.X, e.Y);
                }
                if (b != default(PointF))
                {
                    if (s != null)
                    {
                        s.Draw(g, w);
                    }
                    s = new CSegment(a, b);
                    a = default(PointF);
                    b = default(PointF);
                    s.Draw(g, w, 4);
                    shapes.Push_back(s);
                }
            }

            if (shapeIndex == 3)
            {
                PointF cur = new PointF(e.X, e.Y);
                curver = new CCircle(cur, 5);
                curver.Draw(g, w);
                if (first == null)
                {
                    first = new CCircle(cur, 5);
                    first.Chng_clr(3);
                    first.Draw(g, w);
                }
                if (first.Contains(cur) && cur != first.Center)
                {
                    if (s != null)
                    {
                        s.Draw(g, w);
                    }
                    cur   = default(PointF);
                    first = null;
                    s     = new Polygon(v);
                    Draw_all_shapes();
                    s.Draw(g, w, 4);
                    shapes.Push_back(s);
                    v.Clear();
                }
                else
                {
                    v.Add(cur);
                }
            }

            if (shapeIndex == 4)
            {
                PointF p = new PointF(e.X, e.Y);
                shapes.Set_current_first();
                for (bool cond = !shapes.Is_empty(); cond;)
                {
                    if (shapes.Current.Shape.Contains(p))
                    {
                        gr.Add(shapes.Current.Shape);
                        shapes.Current.Shape.Draw(g, w, 3);
                        if (shapes.Current.Shape != shapes.Head.Shape)
                        {
                            shapes.Delete_current();
                            cond = shapes.Step_forward();
                        }
                        else
                        {
                            shapes.Delete_current();
                            cond = !shapes.Is_empty();
                        }
                    }
                    else
                    {
                        cond = shapes.Step_forward();
                    }
                }
            }
            UpdateTB();
        }