List of usage examples for org.apache.poi.xdgf.usermodel.shape.exceptions StopVisiting StopVisiting
StopVisiting
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 va 2 s . com*/ 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(); }