Search in sources :

Example 1 with KosarajuSCC

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();
}
Also used : KosarajuSCC(easik.model.util.graph.KosarajuSCC) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) EntityNode(easik.sketch.vertex.EntityNode) SketchFrame(easik.ui.SketchFrame) AbstractUndoableEdit(javax.swing.undo.AbstractUndoableEdit) SketchEdge(easik.sketch.edge.SketchEdge) UniqueIndexable(easik.model.keys.UniqueIndexable)

Example 2 with KosarajuSCC

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;
}
Also used : AbstractUndoableEdit(javax.swing.undo.AbstractUndoableEdit) GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) SketchEdge(easik.sketch.edge.SketchEdge) KosarajuSCC(easik.model.util.graph.KosarajuSCC)

Aggregations

KosarajuSCC (easik.model.util.graph.KosarajuSCC)2 SketchEdge (easik.sketch.edge.SketchEdge)2 AbstractUndoableEdit (javax.swing.undo.AbstractUndoableEdit)2 UniqueIndexable (easik.model.keys.UniqueIndexable)1 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)1 EntityNode (easik.sketch.vertex.EntityNode)1 SketchFrame (easik.ui.SketchFrame)1 GraphLayoutCache (org.jgraph.graph.GraphLayoutCache)1