Example usage for org.apache.poi.xdgf.usermodel XDGFShape getID

List of usage examples for org.apache.poi.xdgf.usermodel XDGFShape getID

Introduction

In this page you can find the example usage for org.apache.poi.xdgf.usermodel XDGFShape getID.

Prototype

public long getID() 

Source Link

Usage

From source file:com.bbn.poi.xdgf.parsers.ShapeData.java

License:Apache License

public ShapeData(XDGFShape shape, AffineTransform globalTransform) {

    Path2D shapeBounds;// w  w w . j a  v a2  s  . c o m
    Path2D path = shape.getPath();

    // some 1d shapes don't have a path associated with them, 
    // if they have subshapes... 
    if (shape.isShape1D() && path != null) {
        path1D = path;
        path1D.transform(globalTransform);
        path1D = GeomUtils.roundPath(path1D);
        hasGeometry = true;

        calculate1dEndpoints();
        shapeBounds = path1D; // use path as bounds
    } else {
        // calculate bounding boxes + other geometry information we'll need later
        shapeBounds = shape.getBoundsAsPath();

        shapeBounds.transform(globalTransform);
        shapeBounds = GeomUtils.roundPath(shapeBounds);

        path2D = shapeBounds;
        hasGeometry = (path != null);
    }

    this.bounds = shapeBounds.getBounds2D();

    this.shape = shape;
    this.shapeId = shape.getID();
    this.rtreeBounds = SpatialTools.convertRect(this.bounds);
    this.area = this.rtreeBounds.area();

    this.isInteresting = isInteresting(shape);

    this.lineColor = shape.getLineColor();
    this.linePattern = shape.getLinePattern();

    hasText = shape.hasText() && !shape.getTextAsString().isEmpty();
    isTextbox = hasText && !shape.hasMaster() && !shape.hasMasterShape();

    if (hasText)
        textCenter = globalTransform.transform(shape.getText().getTextCenter(), null);
}

From source file:com.bbn.poi.xdgf.parsers.VisioPageParser.java

License:Apache License

protected void collectShapes() {

    pageContents.visitShapes(new ShapeVisitor() {

        @Override//from w w w. j  a v a 2  s  . c o m
        public org.apache.poi.xdgf.usermodel.shape.ShapeVisitorAcceptor getAcceptor() {
            return new ShapeDataAcceptor();
        };

        @Override
        public void visit(XDGFShape shape, AffineTransform globalTransform, int level) {

            ShapeData shapeData = new ShapeData(shape, globalTransform);

            if (shapeData.hasText && reassignTextNodeToParent(shape, shapeData)) {
                return;
            }

            String id = pageId + ": " + shape.getID();
            Vertex vertex = graph.addVertex(id);

            shapeData.vertex = vertex;

            // useful properties for later... 
            vertex.setProperty("label", shape.getTextAsString());
            vertex.setProperty("shapeId", shape.getID());

            vertex.setProperty("group", "");
            vertex.setProperty("groupId", "");
            vertex.setProperty("inSecondaryGroup", false);
            vertex.setProperty("is1d", shape.isShape1D());
            vertex.setProperty("name", shape.getName());
            vertex.setProperty("pageName", pageName);
            vertex.setProperty("symbolName", shape.getSymbolName());
            vertex.setProperty("type", shape.getShapeType());

            // this isn't actually accurate
            //vertex.setProperty("visible", shape.isVisible());

            // local coordinates
            vertex.setProperty("x", shapeData.getCenterX());
            vertex.setProperty("y", shapeData.getCenterY());

            helper.onCreate(shapeData, shape);

            shapesMap.put(shape.getID(), shapeData);
            shapes.add(shapeData);
        }
    });
}

From source file:com.bbn.poi.xdgf.parsers.VisioPageParser.java

License:Apache License

protected boolean reassignTextNodeToParent(XDGFShape shape, ShapeData shapeData) {

    // keep looking at parents to see if they're a good match
    ShapeData parentMatch = null;// ww w.j a v a 2  s . c  o m
    XDGFShape current = shape;
    ArrayList<ShapeData> duplicates = new ArrayList<>();

    double x = shapeData.bounds.getMinX();
    double width = shapeData.bounds.getWidth();

    while (current.hasParent()) {

        XDGFShape parent = current.getParentShape();
        ShapeData parentData = getShape(parent.getID());

        if (parentData != null) {

            double parentWidth = parentData.bounds.getWidth();
            double px = parentData.bounds.getMinX();

            if (Math.abs(width - parentWidth) > 0.0001 || Math.abs(px - x) > 0.0001)
                break;

            // found a potential match
            if (!parentData.hasText) {

                // discard duplicate useless shapes
                if (parentMatch != null)
                    duplicates.add(parentMatch);

                parentMatch = parentData;
            }
        }

        current = parent;
    }

    // if there's a parent match, reassign the text
    if (parentMatch != null) {
        XDGFText text = shape.getText();

        parentMatch.vertex.setProperty("label", shape.getTextAsString());
        parentMatch.vertex.setProperty("textRef", shape.getID());
        parentMatch.vertex.setProperty("textRefWhy", "reassignToParent");
        parentMatch.hasText = true;
        parentMatch.isInteresting = true;
        parentMatch.textCenter = text.getTextCenter();

        helper.onReassignToParent(parentMatch, shape);

        for (ShapeData dup : duplicates) {
            removeShape(dup);
        }

        return true;
    }

    return false;
}

From source file:com.bbn.poi.xdgf.parsers.VisioPageParser.java

License:Apache License

protected void collectConnections() {

    if (!helper.useRealConnections())
        return;/*from  ww  w. ja  v  a  2  s .  c o m*/

    for (XDGFConnection conn : pageContents.getConnections()) {
        // if we get the connection point, then it has to be in real coordinates

        Double x = null, y = null;
        XDGFShape from = conn.getFromShape();
        XDGFShape to = conn.getToShape();

        ShapeData fromShapeData = findShapeOrParent(from.getID());

        switch (conn.getFromPart()) {
        case XDGFConnection.visBegin:
            x = fromShapeData.path1Dstart.getX();
            y = fromShapeData.path1Dstart.getY();
            break;
        case XDGFConnection.visEnd:
            x = fromShapeData.path1Dend.getX();
            y = fromShapeData.path1Dend.getY();
            break;
        default:
            break;
        }

        createEdge(from, to, "real", x, y);
    }
}

From source file:com.bbn.poi.xdgf.parsers.VisioPageParser.java

License:Apache License

protected void removeBoringShapes() {

    // remove the boring shapes -- we only kept them so far because one of the 
    // reasons a shape could be interesting is if there was a connection to it

    // if there isn't, get rid of it so we don't have extra stuff in the output

    for (final ShapeData shapeData : shapes) {

        if (shapeData.removed)
            continue;

        if (!shapeData.isInteresting && shapeData.vertex.getProperty("type").equals("Group")) {

            final List<ShapeData> children = new ArrayList<>();

            // if not interesting -- but, all of the children are either groups or shapes..
            // .. remove the kids?
            try {
                shapeData.shape.visitShapes(new ShapeVisitor() {

                    @Override/*from w  w  w.  ja v a 2  s.c  om*/
                    public void visit(XDGFShape shape, AffineTransform globalTransform, int level) {

                        if (shape.getID() == shapeData.shapeId)
                            return;

                        ShapeData child = getShape(shape.getID());
                        if (child != null) {
                            if (child.hasText || !child.shape.getSymbolName().isEmpty())
                                throw new StopVisiting();

                            children.add(child);
                        }
                    }
                }, 0);
            } catch (StopVisiting e) {
                children.clear();
            }

            // if deemed interesting, remove kids and mark self as interesting
            if (!children.isEmpty()) {
                shapeData.isInteresting = true;
                for (ShapeData child : children) {

                    // if child has connections, move them over to the new interesting shape
                    for (Edge edge : child.vertex.getEdges(Direction.BOTH)) {
                        ShapeData other = getShapeFromEdge(edge, Direction.IN);
                        if (other == child)
                            other = getShapeFromEdge(edge, Direction.OUT);

                        Double x = edge.getProperty("x");
                        Double y = edge.getProperty("y");

                        createEdge(shapeData, other, "real-moved", x, y);
                        edge.remove();
                    }

                    removeShape(child);
                }
            }
        }

        // if it's interesting -- or if it has a connection, then keep it
        if (shapeData.isInteresting || shapeData.vertex.getEdges(Direction.BOTH).iterator().hasNext()) {

            // add to the tree
            // - RTree only deals with bounding rectangles, so we need
            //   to get the bounding rectangle in local coordinates, put
            //   into a polygon (to allow accounting for rotation), and
            //   then get the minimum bounding rectangle.

            // TODO: is it worth setting up a custom geometry?
            // -> problem with a custom geometry is that calculating the
            //    distance between objects would be annoying
            rtree = rtree.add(shapeData, shapeData.rtreeBounds);

        } else {
            removeShape(shapeData);
        }
    }

    cleanShapes();
}

From source file:com.bbn.poi.xdgf.parsers.VisioPageParser.java

License:Apache License

protected void createEdge(XDGFShape shape1, XDGFShape shape2, String edgeType, Double x, Double y) {

    ShapeData sd1 = findShapeOrParent(shape1.getID());
    ShapeData sd2 = findShapeOrParent(shape2.getID());

    if (sd1 == null)
        throw new POIXMLException("Cannot find from node " + shape1.getID());

    if (sd2 == null)
        throw new POIXMLException("Cannot find to node " + shape2.getID());

    // TODO: how to deal with from/to being null? Might happen.
    createEdge(sd1, sd2, edgeType, x, y);
}

From source file:com.bbn.poi.xdgf.parsers.VisioPageParser.java

License:Apache License

protected ShapeData findShapeOrParent(long id) {

    ShapeData sd = getShape(id);//from  w ww  .  j  a  v a 2s  .c  o  m
    if (sd != null)
        return sd;

    // find a parent that is in the graph already
    XDGFShape shape = pageContents.getShapeById(id);

    while (sd == null) {
        shape = shape.getParentShape();
        if (shape == null)
            break;

        sd = getShape(shape.getID());
    }

    return sd;
}

From source file:com.bbn.poi.xdgf.parsers.VisioPageParser.java

License:Apache License

protected ShapeData findTopmostParentWithGeom(ShapeData shapeData) {

    ShapeData shapeWithGeom = (shapeData.hasGeometry ? shapeData : null);

    XDGFShape shape = pageContents.getShapeById(shapeData.shapeId);

    while (true) {
        shape = shape.getParentShape();/* ww w  .j a v  a2  s .c  o  m*/
        if (shape == null)
            break;

        shapeData = getShape(shape.getID());
        if (shapeData != null && shapeData.hasGeometry)
            shapeWithGeom = shapeData;
    }

    return shapeWithGeom;
}