001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/ 004 005 package graphlab.plugins.main.select; 006 007 import graphlab.graph.graph.EdgeModel; 008 import graphlab.graph.graph.GraphModel; 009 import graphlab.graph.graph.VertexModel; 010 import graphlab.plugins.commonplugin.undo.UndoableActionOccuredData; 011 import graphlab.plugins.main.GraphData; 012 013 import java.util.HashSet; 014 import java.util.Vector; 015 016 /** 017 * @author Azin Azadi 018 */ 019 public class MakeSelectionEmptyGraph extends MakeSelectionComplementGraph { 020 public String getName() { 021 return "Make Selection Empty"; 022 } 023 024 public String getDescription() { 025 return "Make the selected subgraph an empty graph"; 026 } 027 028 public void action(GraphData gd) { 029 if (gd.select.isSelectionEmpty()) 030 return; 031 HashSet<VertexModel> V = gd.select.getSelectedVertices(); 032 //add undo data 033 UndoableActionOccuredData uaod = new UndoableActionOccuredData(this); 034 035 fillUndoEdges(uaod.properties, gd, "old edges"); 036 037 GraphModel G = gd.getGraph(); 038 039 for (VertexModel v1 : V) { 040 for (VertexModel v2 : V) { 041 // if (v1.getId() < v2.getId()) { 042 // if (G.isEdge(v1, v2)) 043 // G.insertEdge(new EdgeModel(v1, v2)); 044 // else 045 G.removeAllEdges(v1, v2); 046 // } 047 } 048 } 049 050 Vector<EdgeModel> ed = fillUndoEdges(uaod.properties, gd, "new edges"); 051 gd.select.setSelectedEdges(ed); 052 gd.core.addUndoData(uaod); 053 } 054 }