List of usage examples for org.apache.poi.xdgf.usermodel.shape ShapeVisitor ShapeVisitor
public ShapeVisitor()
From source file:com.bbn.poi.xdgf.parsers.VisioPageParser.java
License:Apache License
protected void collectShapes() { pageContents.visitShapes(new ShapeVisitor() { @Override// w w w .j a v a2 s.c om 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 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//w w w . j a v a 2 s.c o m 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(); }