Search in sources :

Example 1 with BoundingBox

use of org.opennms.features.topology.api.BoundingBox in project opennms by OpenNMS.

the class MapViewPortTest method testGetBounds.

@Test
public void testGetBounds() {
    DefaultMapViewManager viewManager = new DefaultMapViewManager();
    viewManager.setMapBounds(new BoundingBox(0, 0, 8000, 4000));
    viewManager.setViewPort(400, 300);
    BoundingBox boundingBox = viewManager.getCurrentBoundingBox();
    assertNotNull(boundingBox);
    assertEquals(4000.0, boundingBox.getCenter().getX(), 0.001);
    assertEquals(2000.0, boundingBox.getCenter().getY(), 0.001);
    assertEquals(8000, boundingBox.getWidth());
    assertEquals(6000, boundingBox.getHeight());
    assertEquals(0, boundingBox.getX());
    assertEquals(-1000, boundingBox.getY());
    assertEquals(0.0, viewManager.getScale(), 0.0);
    viewManager.setScale(1.0);
    boundingBox = viewManager.getCurrentBoundingBox();
    assertEquals(4000, boundingBox.getCenter().getX(), m_delta);
    assertEquals(2000, boundingBox.getCenter().getY(), m_delta);
    assertEquals(200, boundingBox.getWidth());
    assertEquals(150, boundingBox.getHeight());
    assertEquals(3900, boundingBox.getX());
    assertEquals(1925, boundingBox.getY());
    viewManager.setBoundingBox(new BoundingBox(0, 0, 1265, 600));
    assertEquals(0.5, viewManager.getScale(), 0.0001);
}
Also used : BoundingBox(org.opennms.features.topology.api.BoundingBox) Test(org.junit.Test)

Example 2 with BoundingBox

use of org.opennms.features.topology.api.BoundingBox in project opennms by OpenNMS.

the class GridLayoutAlgorithmTest method calculateGrid.

void calculateGrid(int N, int width, int height, int expectedWidth, int expectedHeight) {
    BoundingBox grid = GridLayoutAlgorithm.calculateGrid(N, width, height);
    System.out.printf("Generated a grid of width: %d and height: %d for N: %d, w: %d and h: %d\n", grid.getWidth(), grid.getHeight(), N, width, height);
    assertEquals(expectedWidth, grid.getWidth());
    assertEquals(expectedHeight, grid.getHeight());
}
Also used : BoundingBox(org.opennms.features.topology.api.BoundingBox)

Example 3 with BoundingBox

use of org.opennms.features.topology.api.BoundingBox in project opennms by OpenNMS.

the class GridLayoutAlgorithm method updateLayout.

/**
     * Updates the current layout by extracting the containers graph and then perform a (x,y) transformation
     * of all vertices.
     *
     * @param graph The container of the current graph. Contains all relevant information to perform the transformation
     *                       of the {@link Graph} by changing its {@link Layout}
     */
@Override
public void updateLayout(Graph graph) {
    final Layout graphLayout = graph.getLayout();
    // Sort the vertices
    final List<Vertex> sortedVertices = graph.getDisplayVertices().stream().sorted(new Comparator<Vertex>() {

        @Override
        public int compare(Vertex v1, Vertex v2) {
            return ComparisonChain.start().compare(getIndex(v1), getIndex(v2)).compare(v1.getLabel(), v2.getLabel()).compare(v1.getId(), v2.getId()).result();
        }
    }).collect(Collectors.toList());
    // Find the smallest rectangle (grid) that will fit all the vertices
    // while attempting to preserve the aspect ration of the view port
    final int numberOfVertices = sortedVertices.size();
    final BoundingBox layoutBounds = graphLayout.computeBoundingBox(new ArrayList<>(sortedVertices));
    final BoundingBox grid = calculateGrid(numberOfVertices, layoutBounds.getWidth(), layoutBounds.getHeight());
    // Layout the (sorted) vertices in the grid
    int k = 0;
    for (int y = 0; y < grid.getHeight(); y++) {
        for (int x = 0; x < grid.getWidth(); x++) {
            if (k >= numberOfVertices) {
                break;
            }
            graphLayout.setLocation(sortedVertices.get(k++), new Point(x * ELBOW_ROOM * 2, y * ELBOW_ROOM * 2));
        }
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) Layout(org.opennms.features.topology.api.Layout) BoundingBox(org.opennms.features.topology.api.BoundingBox) Point(org.opennms.features.topology.api.Point) Point(org.opennms.features.topology.api.Point) Comparator(java.util.Comparator)

Example 4 with BoundingBox

use of org.opennms.features.topology.api.BoundingBox in project opennms by OpenNMS.

the class DefaultMapViewManager method getCurrentBoundingBox.

@Override
public BoundingBox getCurrentBoundingBox() {
    if (m_viewPortWidth < 0 || m_mapBounds == null) {
    //return m_mapBounds;
    //throw new IllegalStateException("View port and maps bounds must be set");
    }
    BoundingBox mPrime = m_mapBounds.computeWithAspectRatio(getViewPortAspectRatio());
    int width = (int) Math.round(Math.pow((double) mPrime.getWidth(), 1.0 - m_scale) * Math.pow((double) m_viewPortWidth / 2.0, m_scale));
    int height = (int) Math.round(Math.pow((double) mPrime.getHeight(), 1.0 - m_scale) * Math.pow((double) m_viewPortHeight / 2.0, m_scale));
    return new BoundingBox(m_center, width, height);
}
Also used : BoundingBox(org.opennms.features.topology.api.BoundingBox) Point(org.opennms.features.topology.api.Point)

Example 5 with BoundingBox

use of org.opennms.features.topology.api.BoundingBox in project opennms by OpenNMS.

the class DefaultMapViewManager method setMapBounds.

@Override
public void setMapBounds(BoundingBox boundingBox) {
    // notifications, because the m_mapBounds equals the bounding box with aspect ratio
    if (boundingBox.getWidth() < m_viewPortWidth && boundingBox.getHeight() < m_viewPortHeight) {
        boundingBox = boundingBox.computeWithAspectRatio(getViewPortAspectRatio());
    }
    if (!m_mapBounds.equals(boundingBox)) {
        if (boundingBox.getHeight() < m_viewPortHeight / 2) {
            //Don't allow the height to be less than half the viewport height
            m_mapBounds = new BoundingBox(boundingBox.getCenter(), boundingBox.getWidth(), m_viewPortHeight / 2);
        } else {
            m_mapBounds = boundingBox;
        }
        m_center = m_mapBounds.getCenter();
        fireUpdate();
    }
}
Also used : BoundingBox(org.opennms.features.topology.api.BoundingBox)

Aggregations

BoundingBox (org.opennms.features.topology.api.BoundingBox)12 Point (org.opennms.features.topology.api.Point)7 Test (org.junit.Test)4 VertexRef (org.opennms.features.topology.api.topo.VertexRef)3 HashMap (java.util.HashMap)2 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Graph (org.opennms.features.topology.api.Graph)1 GraphVisitor (org.opennms.features.topology.api.GraphVisitor)1 Layout (org.opennms.features.topology.api.Layout)1 MapViewManager (org.opennms.features.topology.api.MapViewManager)1 SelectionManager (org.opennms.features.topology.api.SelectionManager)1 Criteria (org.opennms.features.topology.api.topo.Criteria)1 SearchCriteria (org.opennms.features.topology.api.topo.SearchCriteria)1 SearchResult (org.opennms.features.topology.api.topo.SearchResult)1 Vertex (org.opennms.features.topology.api.topo.Vertex)1 CircleLayoutAlgorithm (org.opennms.features.topology.app.internal.jung.CircleLayoutAlgorithm)1 AlarmHopCriteria (org.opennms.features.topology.app.internal.support.AlarmHopCriteria)1 CategoryHopCriteria (org.opennms.features.topology.app.internal.support.CategoryHopCriteria)1