Esempio n. 1
0
 /// <summary>
 /// Creates a new connection from the active item to the given item
 /// </summary>
 /// <param name="itemName">name of the given item</param>
 /// <param name="direction">direction where the given item should be placed</param>
 public void CreateConnection(string itemName, ConnectionDirections.Direction direction)
 {
     Item itemOne = m_Items.ActiveItem;
     Item itemTwo = m_Items.GetItem(itemName);
     ConnectionDirections.Direction oppositDirection = ConnectionDirections.GetOppositeDirection(direction);
     ItemConnection newConnection = new ItemConnection(itemOne, itemTwo);
     m_ItemConnections.AddConnection(newConnection);
     itemOne.AddConnection(direction, newConnection);
     itemTwo.AddConnection(oppositDirection, newConnection);
 }
Esempio n. 2
0
        /// <summary>
        /// Returns the start point for a connection to an other object
        /// </summary>
        /// <param name="top"></param>
        /// <param name="left"></param>
        /// <returns></returns>
        private int[] GetItemConnectionPoints(ConnectionDirections.Direction direction,int top, int left)
        {
            int[] position = new int[4];

            switch (direction)
            {
                case ConnectionDirections.Direction.North:
                    position[0] = top;
                    position[1] = left + ITEM_WIDTH / 2;
                    position[2] = position[0] - CONNECTION_LENGTH;
                    position[3] = position[1];
                    break;
                case ConnectionDirections.Direction.South:
                    position[0] = top + ITEM_HEIGTH;
                    position[1] = left + ITEM_WIDTH / 2;
                    position[2] = position[0] + CONNECTION_LENGTH;
                    position[3] = position[1];
                    break;
                case ConnectionDirections.Direction.East:
                    position[0] = top + ITEM_HEIGTH / 2;
                    position[1] = left + ITEM_WIDTH;
                    position[2] = position[0];
                    position[3] = position[1] + CONNECTION_LENGTH;
                    break;
                case ConnectionDirections.Direction.West:
                    position[0] = top + ITEM_HEIGTH / 2;
                    position[1] = left;
                    position[2] = position[0];
                    position[3] = position[1] - CONNECTION_LENGTH;
                    break;
                case ConnectionDirections.Direction.NorthWest:
                    position[0] = top + ITEM_HEIGTH / 6;
                    position[1] = left + ITEM_WIDTH / 6;
                    position[2] = position[0] - GetDiagonalConnectorY();
                    position[3] = position[1] - GetDiagonalConnectorX();
                    break;
                case ConnectionDirections.Direction.NorthEast:
                    position[0] = top + ITEM_HEIGTH / 6;
                    position[1] = left + 5 * ITEM_WIDTH / 6;
                    position[2] = position[0] - GetDiagonalConnectorY();
                    position[3] = position[1] + GetDiagonalConnectorX();
                    break;
                case ConnectionDirections.Direction.SouthEast:
                    position[0] = top + 5 * ITEM_HEIGTH / 6;
                    position[1] = left + 5 * ITEM_WIDTH / 6;
                    position[2] = position[0] + GetDiagonalConnectorY();
                    position[3] = position[1] + GetDiagonalConnectorX();
                    break;
                case ConnectionDirections.Direction.SouthWest:
                    position[0] = top + 5 * ITEM_HEIGTH / 6;
                    position[1] = left + ITEM_WIDTH / 6;
                    position[2] = position[0] + GetDiagonalConnectorY();
                    position[3] = position[1] - GetDiagonalConnectorX();
                    break;
                default:
                    position[0] = top;
                    position[1] = left;
                    break;
            }

            return position;
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the item position based of a connection point
        /// </summary>
        /// <param name="direction">connection point direction</param>
        /// <param name="top">top</param>
        /// <param name="left">left</param>
        /// <returns>position</returns>
        private int[] GetElementPosition(ConnectionDirections.Direction direction, int top, int left)
        {
            int[] position = new int[2];

            switch (direction)
            {
                case ConnectionDirections.Direction.North:
                    position[0] = top;
                    position[1] = left - ITEM_WIDTH / 2;
                    break;
                case ConnectionDirections.Direction.South:
                    position[0] = top - ITEM_HEIGTH;
                    position[1] = left - ITEM_WIDTH / 2;
                    break;
                case ConnectionDirections.Direction.East:
                    position[0] = top - ITEM_HEIGTH / 2;
                    position[1] = left - ITEM_WIDTH;
                    break;
                case ConnectionDirections.Direction.West:
                    position[0] = top - ITEM_HEIGTH / 2;
                    position[1] = left;
                    break;
                case ConnectionDirections.Direction.NorthEast:
                    position[0] = top - ITEM_HEIGTH / 6;
                    position[1] = left - 5 * ITEM_WIDTH / 6;
                    break;
                case ConnectionDirections.Direction.NorthWest:
                    position[0] = top - ITEM_HEIGTH / 6;
                    position[1] = left - ITEM_WIDTH / 6;
                    break;
                case ConnectionDirections.Direction.SouthEast:
                    position[0] = top - 5*ITEM_HEIGTH / 6;
                    position[1] = left - 5 * ITEM_WIDTH / 6;
                    break;
                case ConnectionDirections.Direction.SouthWest:
                    position[0] = top - 5 * ITEM_HEIGTH / 6;
                    position[1] = left - ITEM_WIDTH / 6;
                    break;
                default:
                    position[0] = top;
                    position[1] = left;
                    break;
            }

            return position;
        }
Esempio n. 4
0
        /// <summary>
        /// Displays the substructure of an element.
        /// </summary>
        /// <param name="element">mindmap item</param>
        /// <param name="top">current position top</param>
        /// <param name="left">current position left</param>
        private void DisplaySubStructure(Item element, int top, int left, ConnectionDirections.Direction excludingDirection)
        {
            int[] connectionPoints;
            int[] newElementPosition;
            ConnectionDirections.Direction oppositeDirection;
            Item nextElement;

            foreach (KeyValuePair<ConnectionDirections.Direction,ItemConnection> connection in element.Connections)
            {
                if (connection.Key != excludingDirection)
                {
                    connectionPoints = GetItemConnectionPoints(connection.Key, top, left);
                    oppositeDirection = ConnectionDirections.GetOppositeDirection(connection.Key);
                    newElementPosition = GetElementPosition(oppositeDirection,connectionPoints[2], connectionPoints[3]);
                    DisplayConnection(connectionPoints[0], connectionPoints[1], connectionPoints[2], connectionPoints[3]);
                    nextElement = connection.Value.GetOtherItem(element.Name);
                    DisplayItemElement(nextElement, newElementPosition[0], newElementPosition[1]);
                    DisplaySubStructure(nextElement, newElementPosition[0], newElementPosition[1], oppositeDirection);
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Releases the given connection from the item
 /// </summary>
 /// <param name="connection"></param>
 public void ReleaseConnectionFromItem(ConnectionDirections.Direction direction)
 {
     m_Connections.Remove(direction);
 }
Esempio n. 6
0
 /// <summary>
 /// Register the connection at the item
 /// </summary>
 /// <param name="direction">direction of the connection</param>
 /// <param name="connection">connection</param>
 public void AddConnection(ConnectionDirections.Direction direction, ItemConnection connection)
 {
     m_Connections.Add(direction, connection);
 }