Search in sources :

Example 1 with ModelPath

use of easik.model.path.ModelPath in project fql by CategoricalData.

the class Sketch method multPathWarning.

/**
 * Method that checks if there are paths with the same domain and codomain
 * and then sees if they mismatch. We only care about when one of the paths
 * is all cascade and the other path contains an edge which is not cascade.
 * In this case we will warn the user.
 *
 * @return String warning
 * @author Federico Mora
 */
private String multPathWarning() {
    boolean cascade = false;
    boolean other = false;
    String warning = "";
    // want to look at paths from every node to every other node
    for (EntityNode s : _nodes.values()) {
        for (EntityNode t : _nodes.values()) {
            if (s != t) {
                cascade = false;
                other = false;
                // System.out.println("Finding paths from " + s.getName() +
                // " to " + t.getName());
                ArrayList<SketchEdge> startEdges = new ArrayList<>();
                ArrayList<SketchEdge> endEdges = new ArrayList<>();
                for (SketchEdge edge : _edges.values()) {
                    if (edge.getSourceEntity() == s) {
                        startEdges.add(edge);
                    }
                    if (edge.getTargetEntity() == t) {
                        endEdges.add(edge);
                    }
                }
                // care
                if (startEdges.size() < 2 || endEdges.size() < 2) {
                    // + t.getName());
                    continue;
                }
                ArrayList<ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> paths = new ArrayList<>();
                ArrayList<LinkedList<SketchEdge>> temp = buildpath(s, t);
                for (LinkedList<SketchEdge> q : temp) {
                    if (q.peekLast().getTargetEntity() != t) {
                        q.clear();
                    } else {
                        paths.add(new ModelPath<>(q));
                    }
                }
                if (paths.size() > 1) {
                    for (ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> p : paths) {
                        if (p.isCompositeCascade()) {
                            cascade = true;
                        } else {
                            other = true;
                        }
                    }
                    if (cascade && other) {
                        warning += this.getName() + " contains multiple paths from " + s.getName() + " to " + t.getName() + "\n";
                        for (ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> p : paths) {
                            if (p.isCompositeCascade()) {
                                warning += "        " + p.toString() + " is Aggregate Cascade\n";
                            } else {
                                warning += "        " + p.toString() + " is Aggregate Other\n";
                            }
                        }
                    }
                }
            }
        }
    }
    return warning;
}
Also used : ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) EntityNode(easik.sketch.vertex.EntityNode) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) SketchFrame(easik.ui.SketchFrame) SketchEdge(easik.sketch.edge.SketchEdge) ModelPath(easik.model.path.ModelPath)

Example 2 with ModelPath

use of easik.model.path.ModelPath in project fql by CategoricalData.

the class MySQLExporter method createConstraint.

/**
 * @param constraint
 * @param id
 *
 * @return
 */
@Override
public List<String> createConstraint(final LimitConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> constraint, final String id) {
    final List<String> sql = new LinkedList<>();
    StringBuilder proc = new StringBuilder(500);
    final List<String> declarations = new LinkedList<>();
    final List<String> values = new LinkedList<>();
    final List<String> args = new LinkedList<>();
    final List<String> params = new LinkedList<>();
    // getting the paths involved in this limit constraint
    ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> coneAB = constraint.getCone().AB;
    ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> coneBC = constraint.getCone().BC;
    ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> coneAC = constraint.getCone().AC;
    // TODO this should be in the LimitConstraint
    List<SketchEdge> tmpEdges = coneAB.getEdges();
    tmpEdges.addAll(coneBC.getEdges());
    ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> coneABC = new ModelPath<>(tmpEdges);
    ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> limitConeAB = constraint.getLimitCone1().AB;
    ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> limitCone1BC = constraint.getLimitCone1().BC;
    ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> limitCone2BC = constraint.getLimitCone2().BC;
    tmpEdges = limitConeAB.getEdges();
    tmpEdges.addAll(limitCone1BC.getEdges());
    ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> limitCone1ABC = new ModelPath<>(tmpEdges);
    tmpEdges = limitConeAB.getEdges();
    tmpEdges.addAll(limitCone2BC.getEdges());
    ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> limitCone2ABC = new ModelPath<>(tmpEdges);
    ArrayList<ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> paths = new ArrayList<>();
    paths.add(coneABC);
    paths.add(coneAC);
    paths.add(limitCone1ABC);
    paths.add(coneAB);
    paths.add(limitCone2ABC);
    // would add coneAC, but it's already been added
    int targetNum = 0;
    for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : paths) {
        ++targetNum;
        final LinkedList<SketchEdge> tmpPath = new LinkedList<>(path.getEdges());
        tmpPath.removeFirst();
        final String fk = "_path" + targetNum + "fk";
        args.add(fk + ' ' + pkType());
        params.add("NEW." + quoteId(tableFK(path.getFirstEdge())));
        declarations.add("_cdTarget" + targetNum);
        if (tmpPath.size() == 0) {
            values.add("    SELECT " + fk + " INTO _cdTarget" + targetNum + ';' + lineSep);
        } else {
            values.add("    SELECT " + qualifiedFK(path.getLastEdge()) + " INTO _cdTarget" + targetNum + " FROM " + joinPath(tmpPath, false) + " WHERE " + qualifiedPK(tmpPath.getFirst().getSourceEntity()) + " = " + fk + ';' + lineSep);
        }
    }
    proc.append("CREATE PROCEDURE ").append(quoteId("limitConstraint" + id)).append('(').append(EasikTools.join(", ", args)).append(") BEGIN").append(lineSep).append("    DECLARE ").append(EasikTools.join(", ", declarations)).append(' ').append(pkType()).append(';').append(lineSep).append(EasikTools.join("", values)).append("    IF").append(lineSep);
    // cone commutativity check
    proc.append("        NOT (_cdTarget1 <=> _cdTarget2) OR");
    proc.append(lineSep);
    // limitCone1 commutativity check
    proc.append("        NOT (_cdTarget3 <=> _cdTarget4) OR");
    proc.append(lineSep);
    // limitCone2 commutativity check
    proc.append("        NOT (_cdTarget5 <=> _cdTarget2)");
    proc.append(lineSep);
    proc.append("    THEN CALL constraint_failure('Limit constraint failure.');").append(lineSep).append("    END IF;").append(lineSep).append("END");
    addFail = true;
    sql.addAll(delimit("$$", proc));
    // cast because we will only do this in sketches
    addTrigger(constraint.getCone().getA(), "BEFORE INSERT", "CALL " + quoteId("limitConstraint" + id) + '(' + EasikTools.join(", ", params) + ')');
    return sql;
}
Also used : ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LimitConstraint(easik.model.constraint.LimitConstraint) EqualizerConstraint(easik.model.constraint.EqualizerConstraint) ProductConstraint(easik.model.constraint.ProductConstraint) SumConstraint(easik.model.constraint.SumConstraint) PullbackConstraint(easik.model.constraint.PullbackConstraint) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) EntityNode(easik.sketch.vertex.EntityNode) SketchFrame(easik.ui.SketchFrame) SketchEdge(easik.sketch.edge.SketchEdge) ModelPath(easik.model.path.ModelPath) Sketch(easik.sketch.Sketch)

Example 3 with ModelPath

use of easik.model.path.ModelPath in project fql by CategoricalData.

the class XSDExporter method createConstraint.

/**
 * Add an annotation explaining the equalizer and effect the isA.
 * <p/>
 * Today, this has two parts. First the annotation. For example in the
 * standard equalizer constraint in constraints.easik gives this annotation:
 *
 * <pre>
 * &lt;xs:annotation>
 *  &lt;xs:documentation>
 *     Equalizer(f3); B(f4) ;C(f5) ;Codomain =
 *     Equalizer(f1); D(f2) ;Codomain
 *   &lt;/xs:documentation>
 * &lt;/xs:annotation>
 * </pre>
 * <p/>
 * In addition, the equalizer entity has an "isA" relationship to another
 * entity at the start of the diagram, so this is reflected in the typing.
 * First, an element of equalizer type is added to the target of the "isA"
 * relationship. Second, since there is no need for a separate element in
 * the schema for the equalizer entity, its element is removed from the
 * sketch entity.
 *
 * @param eq
 *            the equalizer diagram constraint.
 * @todo Why not do this with standard isA relationships as well?
 * @todo The equalizer element should be added in some way so there is a
 *       "minoccurs" of zero.
 * @todo The equalizer does not really need a "key" element, but what if
 *       other constraints refer to it.
 */
private void createConstraint(final EqualizerConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> eq) {
    final List<ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> paths = eq.getEqualizerPaths();
    final EntityNode equalizer = eq.getEqualizerEntity();
    final XSDType domType = equalizer.getXsdType();
    final String keyrefName = Easik.getInstance().getSettings().getProperty("xml_keyref_name");
    final List<String> values = new ArrayList<>(paths.size());
    for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : paths) {
        final LinkedList<SketchEdge> tmpPath = new LinkedList<>(path.getEdges());
        tmpPath.removeFirst();
        if (tmpPath.size() == 0) {
            values.add(equalizer.getName() + '(' + path.getFirstEdge().getForeignKeyName(keyrefName) + ')');
        } else {
            values.add(equalizer.getName() + '(' + path.getFirstEdge().getForeignKeyName(keyrefName) + ')' + xmlJoinPath(tmpPath, true));
        }
    }
    final EntityNode isaNode = paths.get(0).getDomain();
    final XSDComplexType isaNodeType = (XSDComplexType) isaNode.getXsdType();
    final XSDElement element = equalizer.getXsdElement();
    element.setParent(isaNode.getXsdElement());
    isaNodeType.addAtom(element);
    equalizer.setXsdElement(null);
    domType.addAnnotation(new XSDAnnotation(EasikTools.join(" = " + lineSep, values)));
}
Also used : ArrayList(java.util.ArrayList) XSDElement(easik.xml.xsd.nodes.elements.XSDElement) LinkedList(java.util.LinkedList) EntityNode(easik.sketch.vertex.EntityNode) XSDType(easik.xml.xsd.nodes.types.XSDType) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) SketchFrame(easik.ui.SketchFrame) SketchEdge(easik.sketch.edge.SketchEdge) ModelPath(easik.model.path.ModelPath) Sketch(easik.sketch.Sketch) XSDAnnotation(easik.xml.xsd.nodes.XSDAnnotation) XSDComplexType(easik.xml.xsd.nodes.types.XSDComplexType)

Example 4 with ModelPath

use of easik.model.path.ModelPath in project fql by CategoricalData.

the class XSDExporter method createConstraint.

/**
 * Add an annotation explaining the commutativity of the diagram.
 * <p/>
 * Today, this is simply done by creating an annotation. For example in the
 * standard cd in constraints.easik gives this annotation:
 *
 * <pre>
 * &lt;xs:annotation>
 *  &lt;xs:documentation>
 *     Domain(f1); A(f2) ;Codomain =
 *     Domain(f3); B(f4) ;Codomain
 *   &lt;/xs:documentation>
 * &lt;/xs:annotation>
 * </pre>
 *
 * @param cd
 *            the commutative diagram constraint.
 */
private void createConstraint(final CommutativeDiagram<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> cd) {
    final List<ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> paths = cd.getPaths();
    final EntityNode dom = paths.get(0).getDomain();
    final XSDType domType = dom.getXsdType();
    final String keyrefName = Easik.getInstance().getSettings().getProperty("xml_keyref_name");
    final List<String> values = new ArrayList<>(paths.size());
    for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : paths) {
        final LinkedList<SketchEdge> tmpPath = new LinkedList<>(path.getEdges());
        tmpPath.removeFirst();
        if (tmpPath.size() == 0) {
            values.add(dom.getName() + '(' + path.getFirstEdge().getForeignKeyName(keyrefName) + ')');
        } else {
            values.add(dom.getName() + '(' + path.getFirstEdge().getForeignKeyName(keyrefName) + ')' + xmlJoinPath(tmpPath, true));
        }
    }
    domType.addAnnotation(new XSDAnnotation(EasikTools.join(" = " + lineSep, values)));
}
Also used : ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) EntityNode(easik.sketch.vertex.EntityNode) XSDType(easik.xml.xsd.nodes.types.XSDType) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) SketchFrame(easik.ui.SketchFrame) SketchEdge(easik.sketch.edge.SketchEdge) ModelPath(easik.model.path.ModelPath) Sketch(easik.sketch.Sketch) XSDAnnotation(easik.xml.xsd.nodes.XSDAnnotation)

Example 5 with ModelPath

use of easik.model.path.ModelPath in project fql by CategoricalData.

the class ModelInfoTreeUI method setPopMenuItems.

/**
 * Sets which of the menu items will be visible
 *
 * @return true if the popup should be displayed, false otherwise
 */
public boolean setPopMenuItems() {
    // If there is nothing seleceted then just do nothing
    if (_theFrame.getInfoTreeUI().getInfoTree().isSelectionEmpty()) {
        return false;
    } else // sketch
    if (_theFrame.getMode() == F.Mode.MANIPULATE) {
        return false;
    }
    // Get currently selected object
    DefaultMutableTreeNode curSelected = (DefaultMutableTreeNode) _theFrame.getInfoTreeUI().getInfoTree().getSelectionPath().getLastPathComponent();
    // Hide all elements
    for (Component c : _popupMenu.getComponents()) {
        c.setVisible(false);
    }
    // Check what is currently selected
    if (curSelected instanceof ModelVertex) {
        _addAttributeItem.setVisible(true);
        _addUniqueKeyItem.setVisible(true);
        _renameEntityItem.setVisible(true);
        _deleteEntityItem.setVisible(true);
    } else if (curSelected instanceof EntityAttribute) {
        if (_theFrame.getMModel() instanceof Sketch) {
            _editAttributeItem.setVisible(true);
            _deleteAttributeItem.setVisible(true);
        }
    } else if (curSelected instanceof UniqueKey) {
        if (_theFrame.getMModel() instanceof Sketch) {
            _editUniqueKeyItem.setVisible(true);
            _deleteUniqueKeyItem.setVisible(true);
        }
    } else if (curSelected instanceof ModelConstraint) {
        if (_theFrame.getMModel() instanceof Sketch) {
            if ((curSelected instanceof SumConstraint) || (curSelected instanceof ProductConstraint) || (curSelected instanceof CommutativeDiagram)) {
                _addPathItem.setVisible(true);
            }
            _deleteConstraintItem.setVisible(true);
        }
    } else if (curSelected instanceof ModelPath) {
        Object myConst = curSelected.getParent();
        if ((myConst instanceof SumConstraint) || (myConst instanceof ProductConstraint) || (myConst instanceof CommutativeDiagram)) {
            _deletePathItem.setVisible(true);
        }
    } else if (curSelected == _tree_entities) {
        _addEntityItem.setVisible(true);
    } else if (curSelected == _tree_constraints) {
        _addCommutativeItem.setVisible(true);
        _addProductItem.setVisible(true);
        _addPullbackItem.setVisible(true);
        _addSumItem.setVisible(true);
    // _addLimItem.setVisible(true);
    } else if (curSelected == _tree_constraints_commutative) {
        _addCommutativeItem.setVisible(true);
    } else if (curSelected == _tree_constraints_product) {
        _addProductItem.setVisible(true);
    } else if (curSelected == _tree_constraints_pullback) {
        _addPullbackItem.setVisible(true);
    } else if (curSelected == _tree_constraints_equalizer) {
        _addEqualizerItem.setVisible(true);
    } else if (curSelected == _tree_constraints_sum) {
        _addSumItem.setVisible(true);
    } else if (curSelected == _tree_constraints_limit) {
    // _addLimItem.setVisible(true);
    } else {
        return false;
    }
    return true;
}
Also used : ProductConstraint(easik.model.constraint.ProductConstraint) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) EntityAttribute(easik.model.attribute.EntityAttribute) ModelConstraint(easik.model.constraint.ModelConstraint) UniqueKey(easik.model.keys.UniqueKey) ModelPath(easik.model.path.ModelPath) ModelVertex(easik.model.vertex.ModelVertex) Sketch(easik.sketch.Sketch) Component(java.awt.Component) SumConstraint(easik.model.constraint.SumConstraint) CommutativeDiagram(easik.model.constraint.CommutativeDiagram)

Aggregations

ModelPath (easik.model.path.ModelPath)14 ArrayList (java.util.ArrayList)10 Sketch (easik.sketch.Sketch)9 SketchEdge (easik.sketch.edge.SketchEdge)9 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)9 SketchFrame (easik.ui.SketchFrame)9 LinkedList (java.util.LinkedList)9 ModelConstraint (easik.model.constraint.ModelConstraint)8 ProductConstraint (easik.model.constraint.ProductConstraint)8 SumConstraint (easik.model.constraint.SumConstraint)8 EntityNode (easik.sketch.vertex.EntityNode)8 EqualizerConstraint (easik.model.constraint.EqualizerConstraint)6 LimitConstraint (easik.model.constraint.LimitConstraint)6 PullbackConstraint (easik.model.constraint.PullbackConstraint)6 XSDAnnotation (easik.xml.xsd.nodes.XSDAnnotation)4 XSDType (easik.xml.xsd.nodes.types.XSDType)4 Point (java.awt.Point)3 CommutativeDiagram (easik.model.constraint.CommutativeDiagram)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 EntityAttribute (easik.model.attribute.EntityAttribute)1