use of easik.model.util.graph.KosarajuSCC in project fql by CategoricalData.
the class Sketch method removeEdge.
/**
* Removes an edge, also cascades to remove all constraints using it.
*
* @param toRemove
* The edge about to be removed
*/
public void removeEdge(final SketchEdge toRemove) {
model.beginUpdate();
// Check for constraints that need these edges
for (final ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> c : _constraints.values()) {
if (c.hasEdge(toRemove)) {
removeConstraint(c);
}
}
if (toRemove instanceof UniqueIndexable) {
final EntityNode source = toRemove.getSourceEntity();
boolean needCleanup = false;
for (final UniqueKey<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> q : source.getUniqueKeys()) {
if (q.removeElement((UniqueIndexable) toRemove)) {
needCleanup = true;
}
}
if (needCleanup) {
source.cleanup();
}
// FIXME: undo: unique key cleanup stuff
}
_edges.remove(toRemove.getName());
toRemove.getSourceEntity().removeDepend(toRemove.getTargetEntity());
model.postEdit(new AbstractUndoableEdit() {
/**
*/
private static final long serialVersionUID = 711022413236293938L;
@Override
public void undo() {
super.undo();
_edges.put(toRemove.getName(), toRemove);
toRemove.getSourceEntity().addDepend(toRemove.getTargetEntity());
}
@Override
public void redo() {
super.redo();
_edges.remove(toRemove.getName());
toRemove.getSourceEntity().removeDepend(toRemove.getTargetEntity());
}
});
getGraphLayoutCache().remove(new Object[] { toRemove });
model.endUpdate();
KosarajuSCC s = new KosarajuSCC(this);
strongConnected = s.getSCC();
}
use of easik.model.util.graph.KosarajuSCC in project fql by CategoricalData.
the class Sketch method addEdge.
/**
* Adds a collection (set, list, etc.) of edges to the sketch.
*
* @param inEdges
* Collection of SketchEdges to add
*/
public String addEdge(final Collection<SketchEdge> inEdges) {
// Push loading state
_stateManager.pushState(new LoadingState<>(this));
final GraphLayoutCache glc = getGraphLayoutCache();
model.beginUpdate();
for (final SketchEdge edge : inEdges) {
if (_edges.containsKey(edge.getName())) {
edge.setName(edge.getName());
}
// Add our entity to the graph
glc.insert(edge);
_edges.put(edge.getName(), edge);
edge.getSourceEntity().addDepend(edge.getTargetEntity());
}
String warning = "";
String prevCycle = strongConnected;
KosarajuSCC s = new KosarajuSCC(this);
strongConnected = s.getSCC();
// about this cycle previously
if (setHasCycle(!strongConnected.isEmpty()) && !prevCycle.equals(strongConnected)) {
warning += this.getName() + " contains a strongly connected component" + "\n " + strongConnected + "\n";
}
// if there is a mismatched path pair in the sketch
String temp = pPaths;
pPaths = this.multPathWarning();
if (!pPaths.isEmpty() && !temp.equals(pPaths)) {
warning += pPaths;
}
if (!warning.isEmpty() && useWarnings()) {
JOptionPane.showMessageDialog(this, warning, "Warning", JOptionPane.ERROR_MESSAGE);
} else if (!useWarnings()) {
return warning;
}
model.postEdit(new AbstractUndoableEdit() {
/**
*/
private static final long serialVersionUID = -6523342649950083978L;
@Override
public void undo() {
super.undo();
for (final SketchEdge edge : inEdges) {
_edges.remove(edge.getName());
}
}
@Override
public void redo() {
super.redo();
for (final SketchEdge edge : inEdges) {
_edges.put(edge.getName(), edge);
edge.getSourceEntity().addDepend(edge.getTargetEntity());
}
}
});
model.endUpdate();
// Pop state
_stateManager.popState();
refresh();
_theOverview.refresh();
return null;
}
Aggregations