コード例 #1
0
 public GL.Connection Connect(GL.Shape s1, GL.Shape s2, string linePath, GL.ConnectionEnd lineEnd)
 {
     GL.Connection con = GraphControl.AddConnection(s1.Connectors[0], s2.Connectors[0]);
     con.LinePath = linePath;
     con.LineEnd  = lineEnd;
     return(con);
 }
コード例 #2
0
        //        public BezierPainter()
        //        {
        //            
        //            mHandles = new BezierHandleCollection(this);
        //            mHandles.Add(new BezierHandle(10,10));
        //            mHandles.Add( new BezierHandle(50,50));
        //            mHandles.Add( new BezierHandle(100,100));
        //            mHandles.Add(new BezierHandle(150,150));
        //            Init();
        //        }
        //        public BezierPainter(BezierHandleCollection mHandles)
        //        {
        //        
        //            if(mHandles.Count>1)
        //            {
        //                this.mHandles = mHandles;
        //                for(int k =0; k<mHandles.Count; k++)
        //                {mHandles[k].Curve = this;}
        //            }
        //            else
        //                throw new Exception("A curve requires at least two handles");
        //
        //            Init();
        //        }
        //        public BezierPainter(PointF[] points)
        //        {
        //            if(points.Length>1)
        //            {
        //                mHandles = new BezierHandleCollection();
        //                BezierHandle hd;
        //                for(int k=0; k<points.Length; k++)
        //                {
        //                    if(k==0 || k==points.Length-1) //start and final handle should be single-type
        //                        hd = new BezierHandle(points[k],HandleTypes.Single);
        //                    else
        //                        hd = new BezierHandle(points[k],HandleTypes.Symmetric);
        //
        //                    hd.Curve = this;
        //                    mHandles.Add(hd);
        //                }
        //            }
        //            else
        //                throw new Exception("A curve requires at least two handles");
        //
        //            Init();
        //        }
        public BezierPainter(Connection connection)
            : base(connection)
        {
            mPoints = mConnection.GetConnectionPoints();
            if(mPoints.Length>1)
            {
                mHandles = new BezierHandleCollection();
                BezierHandle hd;

                for(int k=1; k<mPoints.Length-1; k++)
                {
                    if(k==1 || k==mPoints.Length-2) //start and final handle should be single-type
                        hd = new BezierHandle(mPoints[k],HandleTypes.Single);
                    else
                        hd = new BezierHandle(mPoints[k],HandleTypes.Symmetric);

                    hd.Curve = this;
                    mHandles.Add(hd);
                }
            }
            else
                throw new Exception("A curve requires at least two handles");

            Init();
        }
コード例 #3
0
 public ConnectionEventArgs(Connection connection, bool manual)
 {
     this.connection=connection;
         this.to=connection.To;
         this.from=connection.From;
         this.manual = manual;
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the ConnectionEventArgs class.
 /// </summary>			
 public ConnectionEventArgs(Connection connection)
 {
     this.connection=connection;
         this.to=connection.To;
         this.from=connection.From;
 }
コード例 #5
0
 /// <summary>
 /// Creates a connection painter based on the given connection
 /// </summary>
 /// <param name="connection"></param>
 public ConnectionPainter(Connection connection)
 {
     mConnection = connection;
     pen = connection.pen;
     mPoints = connection.GetConnectionPoints();
 }
コード例 #6
0
        /// <summary>
        /// There is only one way to specify a connection: by specifying the two connectors
        /// Unless you have a single connector per shape which allows you to use the shape GUID
        /// Going via node label is possible as well if you filter out doubles on (automatic) creation.
        /// </summary>
        /// <param name="From"></param>
        /// <param name="To"></param>
        public Connection AddEdge(Connector From, Connector To)
        {
            if (From !=null && To != null)
            {
                Connection con =new Connection(this);
                con.From=From;
                con.To=To;
                From.Connections.Add(con);
                To.Connections.Add(con);
                con.LineEnd=this.DefaultLineEnd;
                con.Site = this;
                Update();
                Invalidate();
                if(OnNewConnection != null)
                {
                    OnNewConnection(this,new ConnectionEventArgs(con,false));
                }
                return con;

            }
            return null;
        }
コード例 #7
0
        /// <summary>
        /// Handles the mouse up event
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            // Get current mouse point adjusted by the current scroll position and zoom factor
            PointF p = new PointF(e.X - this.AutoScrollPosition.X, e.Y - this.AutoScrollPosition.Y);
            p = UnzoomPoint(Point.Round(p));

            //pass the event to the entity
            HitHover(p);
            if ((Hover != null) && (typeof(Entity).IsInstanceOfType(Hover)))
            {
                (Hover as Entity).RaiseMouseUp(e);
            }
            //paint the selector if there is one
            if (selector != null) selector.Paint(this);

            #region Left mouse button
            if (e.Button == MouseButtons.Left)
            {
                //are we dragging a new connection?
                if (connection != null)
                {
                    HitHover(p);

                    connection.Invalidate();
                    //if the cursor is over a connector then attach new connection
                    if ((Hover != null) && (typeof(Connector).IsInstanceOfType(Hover)))
                        if (!Hover.Equals(connection.From))
                        {//check if the connector can have an extra connection
                            if(((Connector) Hover).AllowMultipleConnections || ((Connector) Hover).Connections.Count==0)
                            {

                                    connection.Insert(connection.From,(Connector) Hover);
                                    connection.LinePath = this.connectionPath; //set the default path/shape style
                                    connection.LineEnd = this.connectionEnd; //the default end
                                if(OnNewConnection != null)
                                {
                                    if(!OnNewConnection(this,new ConnectionEventArgs(connection,true)))
                                    {
                                        connection.Delete(); //if the (external) handler tells it's not OK we delete the connection again
                                    }
                                }

                            }
                        }

                    connection = null;
                    Capture = false;
                }
                //are we dragging a marquee to select shapes?
                if (selector != null)
                {
                    RectangleF r = selector.Rectangle;

                    //CHANGED BY FERDA - the scrolling is not taken into acount
                    r.Offset(-AutoScrollPosition.X, -AutoScrollPosition.Y);
                    //END OF CHANGE

                    r = this.UnzoomRectangle(r);
                    //if ((Hover == null) || (Hover.IsSelected == false))
                    if (ModifierKeys != Keys.Shift) Deselect();

                    if ((r.Width != 0) || (r.Height != 0))
                    {
                        foreach (Shape o in extract.Shapes)
                        {
                            if (o.Hit(r))
                            {
                                o.IsSelected=true;
                            }

                            foreach (Connector c in o.Connectors)
                                foreach (Connection n in c.Connections)
                                {
                                    if (n.Hit(r))
                                    {
                                        n.IsSelected=true;
                                        c.Invalidate();
                                    }
                                }
                        }
                    }
                    selector = null;
                    Capture = false;
                }
                //are we draggging or resizing shapes?
                if (mDoTrack)
                {
                    foreach (Shape o in extract.Shapes)
                        if (o.ShapeTracker != null)
                        {
                            o.ShapeTracker.End();
                            o.Invalidate();
                            o.Rectangle=o.ShapeTracker.Rectangle;
                        }
                    mDoTrack = false;
                    Capture = false;
                    HitHover(p);
                }
                OnFerdaMouseUp(this, e);
            }
            #endregion

            Update();
            SetCursor(p);
        }
コード例 #8
0
        /// <summary>
        /// Handles the mouse down event
        /// </summary>
        /// <param name="e">Events arguments</param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            //make sure the canvas has the focus
            this.Focus();
            // Get a point adjusted by the current scroll position and zoom factor
            PointF p = new PointF(e.X - this.AutoScrollPosition.X, e.Y - this.AutoScrollPosition.Y);
            p = UnzoomPoint(Point.Round(p));

            //pass the event to the hit entity
            HitHover(p);

            #region Ctrl+Shift left
            if((e.Button==MouseButtons.Left) && (e.Clicks==1) && (CtrlShift))
            {
                this.Zoom +=0.1F;
                CtrlShift = false;
                return;
            }
            #endregion
            #region Ctrl+Shift right
            if((e.Button==MouseButtons.Right) && (e.Clicks==1) && (CtrlShift))
            {
                this.Zoom -=0.1F;
                CtrlShift = false;
                this.ContextMenu = null;
                return;
            }
            #endregion
            #region Double click left
            //shows the properties of the underlying object
            if ((e.Button == MouseButtons.Left) && (e.Clicks == 2))
            {
                //do we hit something under the cursor?
                HitHover(p);

                if ((Hover != null) && (typeof(Entity).IsInstanceOfType(Hover)))
                {
                    this.RaiseShowProps(((Entity) Hover).Properties);
                    Update();
                    return;
                }
            }
            #endregion
            #region SINGLE click left

            if ((e.Button == MouseButtons.Left) && (e.Clicks == 1))
            {

                // Alt+Click allows fast creation of elements
                if ((shapeObject == null) && (ModifierKeys == Keys.Alt))
                {
                    shapeObject = this.GetShapeInstance(lastAddedShapeKey);

                }
                if (shapeObject != null)
                {
                    shapeObject.Invalidate();
                    RectangleF r = shapeObject.Rectangle;
                    shapeObject.Rectangle = new RectangleF(p.X, p.Y, r.Width, r.Height);
                    shapeObject.Invalidate();
                    if(OnShapeAdded!=null) OnShapeAdded(this,shapeObject); //raise the event
                    extract.Insert(shapeObject);
                    shapeObject = null;
                    return;
                }
                //reset the selector marquee
                selector = null;
                //see if something under the cursor
                HitHover(p);

                if (Hover != null)//the click resulted in an object; shape or connection
                {
                    if (typeof(Connector).IsInstanceOfType(Hover))
                    {
                        if(!((Connector) Hover).AllowMultipleConnections && ((Connector) Hover).Connections.Count>0) return;
                        if(!mAllowAddConnection) return;
                        connection = new Connection(this);
                        connection.Site=this;
                        connection.From = (Connector) Hover;
                        connection.ToPoint = p; //we use the mouse as To as long as we haven't a real connector, which will occur in the OnMouseUp
                        Hover.Invalidate();
                        Capture = true;
                        Update();
                        return;
                    }

                    // select object or add to the list of selected objects
                    if (!Hover.IsSelected)
                    {
                        if (ModifierKeys != Keys.Shift) Deselect(); //s is empty only if shift is pushed
                        //shift-click adds only ONE item while a normal click can change a set of shapes to
                        //another state.
                        Hover.IsSelected=true;
                        Update();
                    }
                    //fix the node if the layout is manipulating the position
                    if (typeof(Shape).IsInstanceOfType(Hover))
                    {
                        foreach(Shape sho in extract.Shapes) sho.Fixed=false;
                        ((Shape) Hover).Fixed=true;
                    }

                    // search tracking handle
                    Point h = new Point(0, 0);
                    if (extract.Shapes.Contains(Hover))
                    {
                        Shape o = (Shape) Hover;
                        h = o.ShapeTracker.Hit(p);
                    }

                    foreach (Shape j in extract.Shapes)
                    {
                        if (j.ShapeTracker != null) //will only be one tracker per hit
                        {
                            j.ShapeTracker.Start(p, h);
                            foreach(Connector c in j.Connectors)
                            {
                                foreach(Connection cn in c.Connections)
                                    if( cn.Tracker != null )
                                        cn.Tracker.Start(p,Point.Empty);
                            }

                        }

                    }

                    // Search tracker handle of connection and start tracking
                    if( typeof(Connection).IsInstanceOfType(Hover) )
                    {
                        connection = Hover as Connection;
                        h = connection.Tracker.Hit(p);
                        connection.Tracker.Start(p,h);
                    }

                    mDoTrack = true;
                    Capture = true;

                    if ((Hover != null) && (typeof(Entity).IsInstanceOfType(Hover)))
                    {
                        (Hover as Entity).RaiseMouseDown(e);
                    }

                    SetCursor(p);
                    return;
                }

                //TADY JE MOZNA DALSI PROBLEM
                p=new PointF(e.X,e.Y);
                selector = new Selector(p, this);

            }
            #endregion

            #region SINGLE click right
            if (e.Button == MouseButtons.Right)
            {
                if (Hover != null)
                {
                    if (!Hover.IsSelected)
                    {
                        //Select s = new Select();
                        Deselect();
                        //s.Add(Hover, true);
                        //extract.History.Do(s);
                        Hover.IsSelected=true;
                        Update();
                    }
                }

                if(this.mEnableContextMenu )
                {
                    if(OnContextMenu !=null) OnContextMenu(this, e);
                    //This region must be dropped out. It is a little against the
                    //concept of object programming to let the successor of this class
                    //create some context menu and then erase it with this context menu
                    /*
                    this.ContextMenu=new ContextMenu();

                    ResetToBaseMenu();

                    if(typeof(Shape).IsInstanceOfType(Hover))
                    {
                        //MenuItem[] tmp = new MenuItem[mContextMenu.MenuItems.Count];
                        //mContextMenu.MenuItems.CopyTo(tmp,0);

                        MenuItem[] additionals = (Hover as Shape).ShapeMenu();
                        if(additionals != null)
                        {
                            this.ContextMenu.MenuItems.Add("-");
                            this.ContextMenu.MenuItems.AddRange(additionals);
                        }

                    }
                    else if(typeof(Connection).IsInstanceOfType(Hover))
                    {
                        if((Hover as Connection).LinePath== "Rectangular") return;
                        this.insertionPoint = p;
                        this.ContextMenu.MenuItems.Add("-");
                        MenuItem[] subconnection = new MenuItem[2]{
                                new MenuItem("Add point",new EventHandler(AddConnectionPoint)),
                                new MenuItem("Delete point",new EventHandler(RemoveConnectionPoint))
                                                                  };
                        this.ContextMenu.MenuItems.Add(new MenuItem("Connection",subconnection));
                    }
                    */
                }

            }
            #endregion
        }
コード例 #9
0
 /// <summary>
 /// Deletes a connection - especially for Ferda usage
 /// </summary>
 /// <param name="con">connection to be deleted</param>
 protected void DeleteConnection(Connection con)
 {
     con.Delete();
 }
コード例 #10
0
 public DefaultPainter(Connection connection)
     : base(connection)
 {
 }
コード例 #11
0
 public BezierTracker(Connection connection)
     : base(connection.GetConnectionPoints())
 {
     mCurve = connection.mPainter as BezierPainter;
     mHandles = mCurve.Handles;
 }
コード例 #12
0
 public void Remove(Connection connection)
 {
     this.InnerList.Remove(connection);
 }
コード例 #13
0
 public int Add(Connection connection)
 {
     return this.InnerList.Add(connection);
 }
コード例 #14
0
 public RectangularPainter(Connection connection)
     : base(connection)
 {
 }