Exemple #1
0
        /// <summary>
        /// This method is calling when you press any mouse button within the workspace
        /// </summary>
        /// <param name="e"></param>
        public void MouseDown(MouseEventArgs e)
        {
            GraphElement element;

            //Looking for an item in the given position
            if ((this.tempLayer.Elements.Count != 0) && (this.tempLayer.Elements[0].IntersectsWith(e.Location)))
            {
                element = this.tempLayer.Elements[0];
            }
            else
            {
                element = GraphDiagram.GetElement(this.diagramLayer, e.Location);
            }
            //Position is saved for future operations
            this.downInitialPoint = e.Location;
            //If an item exists, the mouse button is checked for a change of operation
            if (element != null)
            {
                //If the button pressed is the left...
                if (e.Button == MouseButtons.Left)
                {
                    //If the press is on an arrow
                    if ((element is GraphArrow) && (this.tempLayer.Elements.Count == 1))
                    {
                        ArrowModifier modifier = ((GraphArrow)this.tempLayer.Elements[0]).GetModifier(e.Location);
                        if (modifier == null)
                        {
                            this.ClearOperationContext();
                            throw new OperationException(Operation.Nop, "Change to Select Operation");
                        }
                        else if (modifier is ConnectorModifier)
                        {
                            throw new OperationException(Operation.Nop, "Change to Reconnect Operation");
                        }
                        //If the press is on the element, it is passed to the selection operation
                        else
                        {
                            throw new OperationException(Operation.Nop, "Change to ModifyArrow Operation");
                        }
                    }
                    //If the pulsation is over a connector is passed to the arrow insert operation
                    else
                    if (element.IntersectsWithConnector(e.Location))
                    {
                        throw new OperationException(Operation.Nop, "Change to InsertArrow Operation");
                    }
                    //If the press is on the element, it is passed to the selection operation
                    else
                    {
                        this.ClearOperationContext();
                        throw new OperationException(Operation.Nop, "Change to Select Operation");
                    }
                }
                //If the button pressed is the left one, it is passed to the selection operation
                else if (e.Button == MouseButtons.Right)
                {
                    this.ClearOperationContext();
                    throw new OperationException(Operation.Nop, "Change to Select Operation");
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// This method is called when the mouse moves into the workspace
        /// </summary>
        /// <param name="e"></param>
        public void MouseMove(MouseEventArgs e)
        {
            if (this.tempLayer.Elements.Count != 0)
            {
                if (this.tempLayer.Elements[0].IntersectsWith(e.Location))
                {
                    if (this.tempLayer.Elements[0] is GraphArrow)
                    {
                        ArrowModifier modifier = ((GraphArrow)this.tempLayer.Elements[0]).GetModifier(e.Location);
                        if (modifier is ConnectorModifier)
                        {
                            if ((Cursor.Current != Cursors.Hand) && (this.CursorChanged != null))
                            {
                                this.CursorChanged(this, new CursorEventArgs(Cursors.Hand));
                            }
                        }
                        else if (modifier is HorizontalModifier)
                        {
                            if ((Cursor.Current != Cursors.HSplit) && (this.CursorChanged != null))
                            {
                                this.CursorChanged(this, new CursorEventArgs(Cursors.HSplit));
                            }
                        }
                        else if (modifier is VerticalModifier)
                        {
                            if ((Cursor.Current != Cursors.VSplit) && (this.CursorChanged != null))
                            {
                                this.CursorChanged(this, new CursorEventArgs(Cursors.VSplit));
                            }
                        }
                        else
                        {
                            if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null))
                            {
                                this.CursorChanged(this, new CursorEventArgs(Cursors.Default));
                            }
                        }
                    }
                    else
                    if (this.tempLayer.Elements[0].IntersectsWithConnector(e.Location))
                    {
                        if ((Cursor.Current != Cursors.Hand) && (this.CursorChanged != null))
                        {
                            this.CursorChanged(this, new CursorEventArgs(Cursors.Hand));
                        }
                    }
                    else
                    if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null))
                    {
                        this.CursorChanged(this, new CursorEventArgs(Cursors.Default));
                    }
                    return;
                }
            }
            //Looking for an item in the given position
            GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location);

            //If no items are found the operation is cancelled
            if (element == null)
            {
                //If there is any element in the temporal layer, it removes
                if (this.tempLayer.Elements.Count != 0)
                {
                    this.ClearOperationContext();
                    //The temporary layer is updated
                    this.tempLayer.UpdateSurface();
                    //The cursor is updated a default
                    if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null))
                    {
                        this.CursorChanged(this, new CursorEventArgs(Cursors.Default));
                    }
                }
                //If the left button is pressed, the zone selection operation starts
                if (e.Button == MouseButtons.Left)
                {
                    throw new OperationException(Operation.Nop, "Change to SelectZone Operation");
                }
            }
            else
            {
                if (this.tempLayer.Elements.Count == 0)
                {
                    this.tempLayer.Visible = true;
                }
                else
                {
                    //The temporary layer is cleaned
                    if (this.tempLayer.Elements[0] is GraphArrow)
                    {
                        //The arrow modifiers are disabled
                        ((GraphArrow)this.tempLayer.Elements[0]).DisableModifiers();
                    }
                    else
                    {
                        //Disables connectors
                        ((GraphElement)this.tempLayer.Elements[0]).DisableConnectors();
                    }
                    //Removes the element from the temporary layer
                    this.tempLayer.RemoveElement((GraphElement)this.tempLayer.Elements[0]);
                }
                if (element is GraphArrow)
                {
                    ((GraphArrow)element).EnableModifiers();
                    //Added to the temporary layer
                    this.tempLayer.AddElement(element);
                    this.tempLayer.UpdateSurface();
                    //Updates to the corresponding cursor
                    if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null))
                    {
                        this.CursorChanged(this, new CursorEventArgs(Cursors.Default));
                    }
                }
                else
                {
                    //The following connectors are enabled
                    if (element.EnableNextConnectors())
                    {
                        //Added to the temporary layer
                        this.tempLayer.AddElement(element);
                        this.tempLayer.UpdateSurface();
                        //Updates to the corresponding cursor
                        if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null))
                        {
                            this.CursorChanged(this, new CursorEventArgs(Cursors.Default));
                        }
                    }
                    else
                    {
                        this.tempLayer.ClearAndHide();
                        this.tempLayer.UpdateSurface();
                    }
                }
            }
        }