GetSelection() public method

public GetSelection ( ) : DiagramSelection,
return DiagramSelection,
 public override void OnDrag(DiagramContext context , Vector2 position)
 {
     Debug.Log(" OnDrag!!! ");
     Vector2 delta = context.GetDragDelta();
     foreach(DiagramElement element in context.GetSelection().GetElements()){
         if(element is DiagramNode){
             DiagramNode node = (DiagramNode)element;
             node.rect.x += delta.x;
             node.rect.y += delta.y;
         }
     }
 }
    public override void OnDrag(DiagramContext context, Vector2 position)
    {
        int pos = nodeHandle.GetPosition ();
        Vector2 delta = context.GetDragDelta ();
        foreach (DiagramElement element in context.GetSelection().GetElements()) {
            if (element is DiagramNode) {
                DiagramNode node = (DiagramNode)element;
                Debug.Log( " resize delta !!! " + delta);
                Debug.Log( " resize !!! " + node.rect);
                switch (pos) {
                case NodeHandle.POS_TOP_LEFT:
                    {
                        Resize (ref node.rect,delta.x, delta.y, -delta.x, -delta.y);
                        break;
                    }
                case NodeHandle.POS_TOP:{
                        Resize (ref node.rect,0, delta.y, 0, -delta.y);
                        break;
                    }
                case NodeHandle.POS_TOP_RIGHT:{
                        Resize (ref node.rect, 0, delta.y , delta.x, -delta.y);
                        break;
                    }
                case NodeHandle.POS_LEFT:{
                        Resize (ref node.rect,delta.x, 0, -delta.x, 0);
                        break;
                    }
                case NodeHandle.POS_RIGHT:{
                    Resize (ref node.rect,0, 0, delta.x, 0);
                        break;
                    }
                case NodeHandle.POS_BOTTOM_LEFT:{
                    Resize (ref node.rect,delta.x, 0, -delta.x, delta.y);
                        break;
                    }
                case NodeHandle.POS_BOTTOM:{
                    Resize (ref node.rect,0, 0, 0, delta.y);
                        break;
                    }
                case NodeHandle.POS_BOTTOM_RIGHT:{
                    Resize (ref node.rect,0, 0, delta.x, delta.y);
                        break;
                    }

                }
            }
        }
    }
    public override void DrawNode(DiagramNode node ,DiagramContext context)
    {
        bool selected = context.GetSelection().GetElements().Contains(node);
        GUI.Box (node.rect, "");

        if(selected){

            GUIStyle style = new GUIStyle (GUIStyle.none);
            style.normal.background = Config.TEX_ADD;

            TEMP =  DiagramUtil.TranslateRect(addAttributeToolRect , node.rect.x , node.rect.y );
            if (GUI.Button (TEMP, "", style)) {
                context.GetCommand().AddAttribute(node);
            }

        }

        TEMP =  DiagramUtil.TranslateRect(iconRect , node.rect.x , node.rect.y );

        if (node.iconPath != null) {
            node.texIcon = Config.loadTexture (node.iconPath);
        }
        if (node.texIcon == null) {
            node.texIcon = Config.TEX_NO_IMAGE;
        }

        node.iconStyle.normal.background = node.texIcon;
        if (GUI.Button (TEMP, "", node.iconStyle)) {
            string path = EditorUtility.OpenFilePanel ("Select Icon", "Assets", "");
            if (path != null) {
                if (Application.dataPath.Length < path.Length) {
                    path = path.Substring (Application.dataPath.Length);
                    char[] chTrims = {'/', '\\'};
                    path = path.TrimStart (chTrims);
                    node.iconPath = path;
                }
            }
        }

        TEMP = DiagramUtil.TranslateRect( new  Rect (iconRect.x + iconRect.width + 10, iconRect.y + 8, node.rect.width - (iconRect.x + iconRect.width + 8) - 20, 16) , node.rect.x , node.rect.y);
        if (selected) {
            node.name = GUI.TextField (TEMP, node.name);
        } else {
            GUI.Label (TEMP, node.name);
        }

        for (int index = 0; index < node.attributes.Count; index++) {
            Attribute attr = (Attribute)node.attributes[index];
            float nwidth = 50;
            float twidth = 90;
            float y = 60 + 18 * index;

            Rect irect =new Rect (12, y, 16, 16);
            Rect nrect = new Rect (irect.x + irect.width + 4, y, nwidth, 16);
            Rect crect = new Rect (nrect.x + nwidth, y, 8, 16);
            Rect trect = new Rect (crect.x + crect.width - 10, y, twidth, 16);

            Texture2D texIcon = null;
            string attrIconPath = attr.iconPath;
            if (attrIconPath != null) {
                texIcon = Config.loadTexture (attrIconPath);
            }
            if (texIcon == null) {
                texIcon = Config.TEX_NO_IMAGE_16;
            }
            GUIStyle attrIconStyle = new GUIStyle (GUIStyle.none);
            attrIconStyle.normal.background = texIcon;

            TEMP = DiagramUtil.TranslateRect( irect,node.rect.x , node.rect.y);
            if (GUI.Button (TEMP, "", attrIconStyle)) {
                string path = EditorUtility.OpenFilePanel ("Select Icon", "Assets", "");
                if (path != null) {
                    if (Application.dataPath.Length < path.Length) {
                        path = path.Substring (Application.dataPath.Length);
                        char[] chTrims = {'/', '\\'};
                        path = path.TrimStart (chTrims);
                        attr.iconPath = path;
                    }
                }
            }

            if (selected) {
                TEMP = DiagramUtil.TranslateRect( nrect,node.rect.x , node.rect.y);
                attr.name = GUI.TextField (TEMP, attr.name);
                TEMP = DiagramUtil.TranslateRect( crect,node.rect.x , node.rect.y);
                GUI.Label (TEMP, ":");
                TEMP = DiagramUtil.TranslateRect( trect,node.rect.x , node.rect.y);
                attr.type = DrawTypeField (TEMP, attr.type);
            } else {
                TEMP = DiagramUtil.TranslateRect( nrect,node.rect.x , node.rect.y);
                GUI.Label (TEMP, attr.name);
                TEMP = DiagramUtil.TranslateRect( crect,node.rect.x , node.rect.y);
                GUI.Label (TEMP, ":");
                TEMP = DiagramUtil.TranslateRect( trect,node.rect.x , node.rect.y);
                DrawTypeField (TEMP, attr.type);
                //GUI.Label (trect, attr.type);
            }

            if (selected) {

                GUIStyle style = new GUIStyle (GUIStyle.none);
                style.normal.background = Config.TEX_TOOL_REMOVE_MINI;
                TEMP = DiagramUtil.TranslateRect(new Rect (trect.x + trect.width - 4, y, 13, 16),node.rect.x , node.rect.y);
                if (GUI.Button (TEMP, "", style)) {
                    node.attributes.Remove (attr);
                }
            }

        }
    }
 public override bool HitTest(DiagramNode node , DiagramContext context , Vector2 position)
 {
     bool selected = context.GetSelection().GetElements().Contains(node);
     if(selected){
     TEMP =  DiagramUtil.TranslateRect(addAttributeToolRect , node.rect.x , node.rect.y );
         if(TEMP.Contains(position)){
             return true;
         }
     }
     return false;
 }
    public override bool OnGUI(DiagramContext context)
    {
        Event e = Event.current;
        switch (e.type) {

        case EventType.KeyDown:
            {
                log ("key down");
                break;
            }
        case EventType.KeyUp:
            {

                log ("key up typecode= " + e.keyCode);
            if(e.keyCode == KeyCode.Delete || e.keyCode == KeyCode.Backspace){
                foreach(DiagramElement element in  context.GetSelection().GetElements()){
                    if(element is DiagramNode){
                        context.GetCommand().DeleteNode((DiagramNode)element);
                    }
                }
            }
            context.editor.Repaint ();

                break;
            }
        case EventType.ContextClick:
            {
                log ("ContextClick");
                        //Draw Context menu
            log ("ContextClick");

            GenericMenu menu = new GenericMenu();
            //menu.AddItem( new GUIContent("item1") , true , this.Action ,"item1");
                break;
            }
        case EventType.DragExited:
            {
                log ("DragExited");
                break;
            }
        case EventType.DragPerform:
            {
                log ("DragPerform");
                break;
            }
        case EventType.DragUpdated:
            {
                log ("DragUpdated");
                break;
            }
        case EventType.ExecuteCommand:
            {
                log ("ExecuteCommand");
                break;
            }
        case EventType.Ignore:
            {
                log ("Ignore");
                break;
            }
        case EventType.Layout:
            {
                log ("Layout");
                break;
            }
        case EventType.MouseDown:
            {
                log ("MouseDown " + Event.current.mousePosition);
                context.DragStart (Event.current.mousePosition);
                Select (context, Event.current.mousePosition);
                context.editor.Repaint ();
                break;
            }
        case EventType.MouseDrag:
            {
                context.Drag (Event.current.mousePosition);
                log ("MouseDrag");
                if (dragTracker != null) {
                    dragTracker.OnDrag (context, Event.current.mousePosition);
                    context.editor.Repaint ();
                }
                break;
            }
        case EventType.MouseUp:
            {
                context.DragEnd (Event.current.mousePosition);
                if (dragTracker != null) {
                    dragTracker.OnDrop (context, Event.current.mousePosition);
                    context.editor.Repaint ();
                }
                dragTracker = null;
                log ("MouseUp");
                break;
            }
        case EventType.Repaint:
            {
                log ("Repaint");

                return true;
            }
        case EventType.ScrollWheel:
            {
                log ("ScrollWheel");
                break;
            }
        case EventType.Used:
            {
                log ("Used");
                break;
            }
        case EventType.ValidateCommand:
            {
                log ("ValidateCommand");
                break;
            }
        case EventType.MouseMove:
            {
                log ("MouseMove");
                //Repaint ();
                break;
            }
        }
        return true;

        //currentDiagramRoot.OnGUI();
    }
    public virtual void Select(DiagramContext context, Vector2 position)
    {
        DiagramRoot root = context.editor.GetRoot ();

        DiagramElement hit = null;

        //Handle Hit Test
        foreach (DiagramElement element in context.GetSelection().GetElements()) {
            DiagramHandle[] handles = element.GetHandles ();
            if (handles != null) {
                foreach (DiagramHandle handle in handles) {
                    hit = handle.HitTest (context, position);
                    if (hit != null) {
                        Debug.Log (" handle hit !!");
                        break;
                    }
                }
            }
        }

        if (hit == null) {
            //Node Hit Test
            foreach (DiagramNode node in root.nodes) {
                hit = node.HitTest (context, position);
                if (hit != null) {
                    break;
                }
            }
        }

        //Edge Hit Test
        if (hit == null) {
            foreach (DiagramNode node in root.nodes) {
                foreach (DiagramEdge edge in node.edges) {
                    hit = edge.HitTest (context, position);
                    if (hit != null) {
                        break;
                    }
                }
            }
        }

        //Diagram Hit Test (canvas)
        if (hit == null) {
            hit = root.HitTest (context, position);
        }

        if (hit is DiagramRoot) {
            //No Select
            context.GetSelection ().Clear ();
            dragTracker = null;
            return;
        }

        dragTracker = hit.GetDragTracker ();

        // Modifirers check
        EventModifiers mod = Event.current.modifiers;
        bool selectAdd = mod.Equals (EventModifiers.Shift);

        if (hit is DiagramHandle) {

        } else {
            if (selectAdd) {
                if (context.GetSelection ().GetElements ().Contains (hit)) {
                } else {
                    context.GetSelection ().AddElement (hit);
                }
            } else {
                if (context.GetSelection ().GetElements ().Contains (hit)) {
                } else {
                    context.GetSelection ().SetElement (hit);
                }
            }

        }
    }