Example #1
0
 /// <summary>
 /// Select the given <see cref="Shape"/> and deselects all other <see cref="Shape"/>s.
 /// </summary>
 /// <param name="shape">The <see cref="Shape"/> to be selected.</param>
 private void SingleSelect(Shape shape)
 {
     DeselectAll();
     Canvas.RemoveShape(shape);
     Canvas.AddShape(shape);
     shape.IsSelected = true;
 }
Example #2
0
        /// <summary>
        /// Performs the mouse down event.
        /// If mouse is pressed on any <see cref="Shape"/> on <see cref="Canvas"/>, then set this
        /// <seealso cref="object"/> selected, otherwise, deselect all <see cref="Shape"/>s and
        /// forms a <see cref="SelectedArea"/>.
        /// </summary>
        /// <remarks>Also updates the position of <see cref="_currentMousePoint"/>.</remarks>
        /// <param name="sender">The <seealso cref="object"/> which triggers the event.</param>
        /// <param name="e">The <seealso cref="EventArgs"/> containing information of mouse.</param>
        /// <seealso cref="Mode.OnMouseDown"/>
        public override void OnMouseDown(object sender, MouseEventArgs e)
        {
            _mousePressedPoint = new Point(e.X, e.Y);
            _currentMousePoint = new Point(e.X, e.Y);
            Shape = GetPressedShape(_currentMousePoint);

            if (Shape != null)
            {
                if (!Shape.IsSelected)
                {
                    SingleSelect(Shape);
                }
            }
            else
            {
                //Mouse pressed on blank field: deselect all shapes
                DeselectAll();
                //Not a single shape selected: prepare to form a selection area.
                Shape = new SelectedArea(e.X, e.Y);
                Canvas.AddShape(Shape);
                _hasSelectArea = true;
            }

            base.OnMouseDown(sender, e);
        }
Example #3
0
        /// <summary>
        /// Performs the mouse wheel event.
        /// Adds the newly created <see cref="Shape"/> onto <see cref="Canvas"/>
        /// for painting.
        /// </summary>
        /// <param name="sender">The <seealso cref="object"/> which triggers the event.</param>
        /// <param name="e">The <seealso cref="EventArgs"/> containing information of mouse.</param>
        /// <seealso cref="Mode.OnMouseDown"/>
        public override void OnMouseDown(object sender, MouseEventArgs e)
        {
            Shape.SetLocation(e.X, e.Y);
            Canvas.AddShape(Shape);

            base.OnMouseDown(sender, e);
        }
Example #4
0
        /// <summary>
        /// Performs the mouse down event.
        /// If mouse is clicking on a <see cref="BasicObject"/>, adds the newly created
        /// <see cref="Line"/> onto <see cref="Canvas"/>, also adds a <see cref="Combination"/>
        /// to source <see cref="BasicObject"/>. If mouse is not pressing on a <see cref="BasicObject"/>,
        /// dispose the created <see cref="Line"/> object and do nothing.
        /// </summary>
        /// <param name="sender">The <seealso cref="object"/> which triggers the event.</param>
        /// <param name="e">The <seealso cref="EventArgs"/> containing information of mouse.</param>
        /// <seealso cref="Mode.OnMouseDown"/>
        public override void OnMouseDown(object sender, MouseEventArgs e)
        {
            bool  created    = false;
            Point mousePoint = new Point(e.X, e.Y);

            for (int i = Canvas.GetShapeCount() - 1; i >= 0; i--)
            {
                Shape currentShape = Canvas.GetShape(i);
                SourcePort = currentShape.GetNearestPort(mousePoint);
                if (currentShape.IsCovers(mousePoint) && SourcePort != null)
                {
                    Shape.SetPort(0, SourcePort); // Set source port to pressed object
                    SourcePort.Visible = true;    // Set port to visible
                    TargetPort         = new Port(e.X, e.Y);
                    Shape.SetPort(1, TargetPort); // Set destination port to the current position of mouse
                    Canvas.AddShape(Shape);       // Add line to canvas
                    created     = true;
                    SourceShape = currentShape;
                    break;
                }
            }

            if (!created)
            {
                Shape = null;
            }

            base.OnMouseDown(sender, e);
        }
Example #5
0
        public CanvasTest()
        {
            List <Line> lines = new List <Line>()
            {
                new Line(new Point(0, 0), new Point(6, 6)),
                new Line(new Point(0, 6), new Point(6, 0))
            };

            canvas = new Canvas();
            foreach (var line in lines)
            {
                canvas.AddShape(line);
            }
        }
Example #6
0
        /// <summary>
        /// Selects all <see cref="Shape"/>s which are within the area covered by
        /// the <see cref="SelectedArea"/>.
        /// </summary>
        /// <param name="selectedArea">The selection area.</param>
        private void MultipleSelect(Shape selectedArea)
        {
            Point p1 = new Point(selectedArea.X, selectedArea.Y);
            Point p2 = new Point(selectedArea.X + selectedArea.Width, selectedArea.X + selectedArea.Height);

            foreach (Shape shape in Canvas.Shapes)
            {
                if (shape.IsWithin(p1, p2))
                {
                    Canvas.RemoveShape(shape);
                    Canvas.AddShape(shape);
                    shape.IsSelected = true;
                }
            }
        }
Example #7
0
        /// <summary>
        /// Ungroup the given <see cref="Shape"/>s and extract the sub-<see cref="Shape"/>s
        /// onto <see cref="Canvas"/> if the <see cref="Shape"/> is a <see cref="CompositionObject"/>.
        /// </summary>
        /// <param name="shapes">The <see cref="Shape"/>s to be ungrouped.</param>
        private void UngroupShapes(Shape[] shapes)
        {
            foreach (Shape shape in shapes)
            {
                if (shape.Count > 1) // Then it is a composittion object.
                {
                    Canvas.RemoveShape(shape);

                    while (shape.Count > 0)
                    {
                        Shape tempShape = shape.RemoveFirst();
                        tempShape.IsSelected = false;
                        Canvas.AddShape(tempShape);
                    }
                }
            }
        }
        /// <summary>
        /// Triggers and performs the to-do action.
        /// Groups all selected <see cref="Shape"/>s into a newly created
        /// <see cref="CompositionObject"/>.
        /// </summary>
        /// <seealso cref="UMLAction.Trigger()"/>
        public override void Trigger()
        {
            Shape[] selectedShapes = Canvas.SelectedShapes;

            if (selectedShapes.Length < 2)
            {
                MessageBox.Show("Please select 2 or more object for grouping", "Warning", MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                return;
            }

            CompositionObject compositionObject = GroupShapes(selectedShapes);

            Canvas.AddShape(compositionObject);
            compositionObject.IsSelected = true;
            Canvas.Invalidate();

            base.Trigger();
        }
Example #9
0
        /// <summary>
        /// Ungroup the given <see cref="Shape"/>s and extract the sub-<see cref="Shape"/>s
        /// onto <see cref="Canvas"/> if the <see cref="Shape"/> is a <see cref="CompositionObject"/>.
        /// </summary>
        /// <param name="shapes">The <see cref="Shape"/>s to be ungrouped.</param>
        private void UngroupShapes(Shape[] shapes)
        {
            foreach (Shape shape in shapes)
            {
                if (shape.Count > 1) // Then it is a composittion object.
                {
                    Canvas.RemoveShape(shape);

                    while (shape.Count > 0)
                    {
                        Shape tempShape = shape.RemoveFirst();
                        tempShape.IsSelected = false;
                        //09 / 14 修正在ungroup時object的port消失情形
                        tempShape.InitializePorts(tempShape.X, tempShape.Y);

                        Canvas.AddShape(tempShape);
                    }
                }
            }
        }