Commit cd779ad6 authored by Robert Smith's avatar Robert Smith
Browse files

Rolling back to previous state



Rolling the branch back to a previous commit while copying changes from
later ones, to correct a build error.
Signed-off-by: Robert Smith's avatarRobert Smith <SmithRW@ornl.gov>
parent 44fdce3d
/*******************************************************************************
* Copyright (c) 2016 UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Robert Smith
*******************************************************************************/
package org.eclipse.ice.viz.service.geometry.reactor.test;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import org.eclipse.ice.viz.service.geometry.reactor.Extrema;
import org.junit.Test;
/**
* A class to test the functionality of Extrema.
*
* @author Robert Smith
*
*/
public class ExtremaTester {
/**
* Check that an Extrema is constructed correctly.
*/
@Test
public void checkConstruction() {
// Create some extrema and check the initial values.
Extrema first = new Extrema(-1d, 0d, 0.5d, 0.5d, 0d, 1d);
assertTrue(first.getMinX() == -1d);
assertTrue(first.getMinY() == -0.5d);
assertTrue(first.getMaxY() == 0.5d);
assertTrue(first.getMaxZ() == 1d);
Extrema second = new Extrema(0d, 1d, -1d, 0d, 0.5d, 0.5d);
assertTrue(second.getMinY() == -1d);
assertTrue(second.getMinZ() == -0.5d);
assertTrue(second.getMaxZ() == 0.5d);
assertTrue(second.getMaxX() == 1d);
Extrema third = new Extrema(0.5d, 0.5d, 0d, 1d, -1d, 0d);
assertTrue(third.getMinZ() == -1d);
assertTrue(third.getMinX() == -0.5d);
assertTrue(third.getMaxX() == 0.5d);
assertTrue(third.getMaxY() == 1d);
// Create an extrema by combining the regions above
ArrayList<Extrema> extrema = new ArrayList<Extrema>();
extrema.add(first);
extrema.add(second);
extrema.add(third);
Extrema all = new Extrema(extrema);
// Check that the new Extrema covers all the sub-regions it was made
// from
assertTrue(all.getMinX() == -1d);
assertTrue(all.getMaxX() == 1d);
// Check that the new Extrema covers all the sub-regions it was made
// from
assertTrue(all.getMinY() == -1d);
assertTrue(all.getMaxY() == 1d);
// Check that the new Extrema covers all the sub-regions it was made
// from
assertTrue(all.getMinZ() == -1d);
assertTrue(all.getMaxZ() == 1d);
}
}
\ No newline at end of file
/*******************************************************************************
* Copyright (c) 2015 UT-Battelle, LLC.
* Copyright (c) 2015-2016 UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -12,6 +12,9 @@ package org.eclipse.ice.viz.service.geometry.reactor;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A class defining the extrema of some shape or region in three dimensional
* space. It includes the minimum and maximum x, y, and z coordinates found
......@@ -22,6 +25,11 @@ import java.util.List;
*/
public class Extrema {
/**
* The extrema's error logger.
*/
private final Logger logger;
/**
* The region's maximum x coordinate.
*/
......@@ -70,6 +78,14 @@ public class Extrema {
this.maxY = maxY;
this.minZ = minZ;
this.maxZ = maxZ;
// Allocate the logger
logger = LoggerFactory.getLogger(getClass());
if (minX > maxX || minY > maxY || minZ > maxZ) {
logger.error(
"Illegal Extrama bounds: Minimum values may not exceed maximum values");
}
}
/**
......@@ -82,6 +98,9 @@ public class Extrema {
*/
public Extrema(List<Extrema> subRegions) {
// Allocate the logger
logger = LoggerFactory.getLogger(getClass());
for (Extrema region : subRegions) {
// For subsequent regions, compare each value
......@@ -250,4 +269,4 @@ public class Extrema {
maxZ = coordinate;
}
}
}
\ No newline at end of file
......@@ -170,13 +170,26 @@ public class AbstractViewTester {
* Check the AbstractView's equality testing.
*/
@Test
public void checkEquality(){
public void checkEquality() {
// Create objects for testing
AbstractView object = new AbstractView();
AbstractView equalObject = new AbstractView();
AbstractView unequalObject = new AbstractView();
// Give one view a different transformation
Transformation transformation = new Transformation();
unequalObject.
transformation.setSize(2);
unequalObject.setTransformation(transformation);
// An object should equal itself
assertTrue(object.equals(object));
// Check that a comparison of two equal objects returns true
assertTrue(object.equals(equalObject));
assertTrue(equalObject.equals(object));
// Check that a comparison of two unequal objects returns false
assertFalse(object.equals(unequalObject));
}
}
}
\ No newline at end of file
/*******************************************************************************
* Copyright (c) 2015 UT-Battelle, LLC.
* Copyright (c) 2015-2016 UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -10,8 +10,7 @@
*******************************************************************************/
package org.eclipse.ice.viz.service.modeling.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
......@@ -26,7 +25,7 @@ import org.eclipse.ice.viz.service.modeling.VertexMesh;
import org.junit.Test;
/**
* A class that tests the functionality of the EdgeAndVertexFaceComponent.
* A class that tests the functionality of the EdgeAndVertexFaceMesh.
*
* @author Robert Smith
*
......@@ -34,10 +33,10 @@ import org.junit.Test;
public class EdgeAndVertexFaceMeshtester {
/**
* Tests that the face adds all child entities to the correct categories.
* Tests that the face adds and removes all child entities in the correct categories.
*/
@Test
public void checkAddEntities() {
public void checkEntities() {
// Create the face
List<AbstractController> entities = new ArrayList<AbstractController>();
......@@ -53,7 +52,7 @@ public class EdgeAndVertexFaceMeshtester {
new AbstractView());
EdgeController edge = new EdgeController(
new LinearEdgeMesh(vertex1, vertex2), new AbstractView());
face.addEntity(edge);
face.addEntityByCategory(edge, "Edges");
// The Edges category should have one object, the edge
assertTrue(face.getEntitiesByCategory("Edges").contains(edge));
......@@ -71,11 +70,40 @@ public class EdgeAndVertexFaceMeshtester {
edge2.setProperty("Id", "2");
edge2.getEntitiesByCategory("Vertices").get(0).setProperty("Id", "2");
edge2.getEntitiesByCategory("Vertices").get(1).setProperty("Id", "3");
face.addEntity(edge2);
face.addEntityByCategory(edge2, "Edges");
// Check that there are now two edges and four vertices in the map.
assertEquals(2, face.getEntitiesByCategory("Edges").size());
assertEquals(4, face.getEntitiesByCategory("Vertices").size());
//Add a second edge, sharing a vertex with the first, to the face
VertexController vertex3 = new VertexController(new VertexMesh(2, 2, 2),
new AbstractView());
EdgeController edge3 = new EdgeController(new LinearEdgeMesh(vertex2, vertex3), new AbstractView());
face.addEntityByCategory(edge3, "Edges");
//The face should have three edges
assertEquals(3, face.getEntitiesByCategory("Edges").size());
//The face should have five vertices, as one of the vertices from the new edge was already present
assertEquals(5, face.getEntitiesByCategory("Vertices").size());
//Try to remove a vertex. This should fail.
face.removeEntity(vertex1);
assertTrue(face.getEntitiesByCategory("Vertices").contains(vertex1));
//Remove an edge. The non-shared vertex should be taken off with it, but the other should remain
face.removeEntity(edge);
assertFalse(face.getEntitiesByCategory("Edges").contains(edge));
assertFalse(face.getEntitiesByCategory("Vertices").contains(vertex1));
assertTrue(face.getEntitiesByCategory("Vertices").contains(vertex2));
//Remove vertex2's other edge. This should remove both vertex2 and 3
face.removeEntity(edge3);
assertFalse(face.getEntitiesByCategory("Edges").contains(edge3));
assertFalse(face.getEntitiesByCategory("Vertices").contains(vertex2));
assertFalse(face.getEntitiesByCategory("Vertices").contains(vertex3));
}
}
}
\ No newline at end of file
/*******************************************************************************
* Copyright (c) 2015 UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Robert Smith
*******************************************************************************/
package org.eclipse.ice.viz.service.modeling.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.eclipse.ice.viz.service.modeling.AbstractController;
import org.eclipse.ice.viz.service.modeling.AbstractView;
import org.eclipse.ice.viz.service.modeling.EdgeController;
import org.eclipse.ice.viz.service.modeling.EdgeMesh;
import org.eclipse.ice.viz.service.modeling.LinearEdgeMesh;
import org.eclipse.ice.viz.service.modeling.VertexController;
import org.eclipse.ice.viz.service.modeling.VertexMesh;
import org.junit.Test;
/**
* A class for testing EdgeController's functionality
*
* @author Robert Smith
*
*/
public class EdgeControllerTester {
/**
* Checks that the edge correctly manages its vertices
*/
@Test
public void checkVertices() {
// Create the edge
EdgeMesh edgeMesh = new LinearEdgeMesh();
EdgeController edge = new EdgeController(edgeMesh, new AbstractView());
// The edge should initially have length 0
assertEquals(0, Double.compare(edge.getLength(), 0d));
// Try adding a non-vertex. It should be put in the Default category
edge.addEntity(new AbstractController());
assertEquals(1, edge.getEntitiesByCategory("Default").size());
// Create some vertices
VertexController vertex1 = new VertexController(new VertexMesh(0, 0, 0),
new AbstractView());
VertexController vertex2 = new VertexController(new VertexMesh(1, 1, 1),
new AbstractView());
VertexController vertex3 = new VertexController(new VertexMesh(2, 2, 2),
new AbstractView());
// Add all three vertices to the edge.
edge.addEntity(vertex1);
edge.addEntity(vertex2);
edge.addEntity(vertex3);
// Check the Vertices category to ensure that the edge accepted the
// first two vertices and ignored the third
List<AbstractController> vertices = edge
.getEntitiesByCategory("Vertices");
assertTrue(vertices.contains(vertex1));
assertTrue(vertices.contains(vertex2));
assertFalse(vertices.contains(vertex3));
assertEquals(2, vertices.size());
// Replace the second vertex with the third
edge.removeEntity(vertex2);
edge.addEntity(vertex3);
// Check the Vertices category to ensure that the last vertex was
// replaced
vertices = edge.getEntitiesByCategory("Vertices");
assertTrue(vertices.contains(vertex1));
assertFalse(vertices.contains(vertex2));
assertTrue(vertices.contains(vertex3));
}
}
\ No newline at end of file
/*******************************************************************************
* Copyright (c) 2015 UT-Battelle, LLC.
* Copyright (c) 2015-2016 UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -11,10 +11,14 @@
package org.eclipse.ice.viz.service.modeling.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.ice.viz.service.datastructures.VizObject.IManagedUpdateable;
import org.eclipse.ice.viz.service.datastructures.VizObject.SubscriptionType;
import org.eclipse.ice.viz.service.modeling.AbstractController;
import org.eclipse.ice.viz.service.modeling.AbstractMesh;
import org.eclipse.ice.viz.service.modeling.AbstractView;
......@@ -22,6 +26,7 @@ import org.eclipse.ice.viz.service.modeling.EdgeController;
import org.eclipse.ice.viz.service.modeling.EdgeMesh;
import org.eclipse.ice.viz.service.modeling.VertexController;
import org.eclipse.ice.viz.service.modeling.VertexMesh;
import org.junit.Test;
/**
* A class which tests the functionality of Vertex
......@@ -34,6 +39,7 @@ public class VertexControllerTester {
/**
* Tests the Vertex's ability to correctly manage its edges
*/
@Test
public void checkEdges() {
// Create a vertex
......@@ -42,14 +48,17 @@ public class VertexControllerTester {
VertexController vertex = new VertexController(vertexModel, view);
// Add an entity and check that it did not go into the edges category
vertex.addEntity(new AbstractController(new AbstractMesh(),
new AbstractView()));
vertex.addEntity(
new AbstractController(new AbstractMesh(), new AbstractView()));
assertEquals(0, vertex.getEntitiesByCategory("Edges").size());
// Create some edges
EdgeController edge1 = new EdgeController(new EdgeMesh(), new AbstractView());
EdgeController edge2 = new EdgeController(new EdgeMesh(), new AbstractView());
EdgeController edge3 = new EdgeController(new EdgeMesh(), new AbstractView());
EdgeController edge1 = new EdgeController(new EdgeMesh(),
new AbstractView());
EdgeController edge2 = new EdgeController(new EdgeMesh(),
new AbstractView());
EdgeController edge3 = new EdgeController(new EdgeMesh(),
new AbstractView());
// Add two edges to the vertex and a thrid explicitly under a different
// category
......@@ -65,4 +74,105 @@ public class VertexControllerTester {
// The last edge should have been put in the specified custom category
assertTrue(vertex.getEntitiesByCategory("test").contains(edge3));
}
}
/**
* Test that the Vertex properly updates
*/
@Test
public void checkUpdates() {
// Create the vertex
VertexMesh vertexMesh = new VertexMesh(0, 0, 0);
TestVertexController vertex = new TestVertexController(vertexMesh,
new AbstractView());
// Create a test object to receive updates
TestMesh otherMesh = new TestMesh(new ArrayList<AbstractController>());
TestController other = new TestController(otherMesh,
new AbstractView());
// Create a second vertex for the edge
VertexMesh otherVertexMesh = new VertexMesh(1, 1, 1);
VertexController otherVertex = new VertexController(otherVertexMesh,
new AbstractView());
// Create an edge
EdgeMesh edgeMesh = new EdgeMesh(vertex, otherVertex);
EdgeController edge = new EdgeController(edgeMesh, new AbstractView());
// Add the test object and edge to the vertex.
vertex.addEntityByCategory(other, "Test");
vertex.addEntityByCategory(edge, "Edges");
// Clear the vertex's updated state
vertex.wasUpdated();
// The vertex should receive updates from child entities by default
other.setProperty("Send", "Update");
assertTrue(vertex.wasUpdated());
// The vertex should not receive updates from objects in the Edges
// category.
edge.setProperty("Send", "Update");
assertFalse(vertex.wasUpdated());
}
/**
* An extension of VertexController that tracks whether it has been updated.
*
* @author Robert Smith
*
*/
private class TestVertexController extends VertexController {
/**
* Whether or not this object has received an update since the last time
* it was checked for an update.
*/
boolean updated;
/**
* The defualt constructor.
*
* @param model
* The internal representation of the part.
* @param view
* The graphical representation of the part.
*/
public TestVertexController(VertexMesh model, AbstractView view) {
super(model, view);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ice.viz.service.modeling.AbstractController#update(org.
* eclipse.ice.viz.service.datastructures.VizObject.IManagedUpdateable,
* org.eclipse.ice.viz.service.datastructures.VizObject.SubscriptionType
* [])
*/
@Override
public void update(IManagedUpdateable component,
SubscriptionType[] type) {
// The object has received an updated
updated = true;
super.update(component, type);
}
/**
* Checks whether this object has received an update since the last time
* it was checked for an update.
*
* @return True if an update was received since the last time this
* method was invoked. False otherwise.
*/
public boolean wasUpdated() {
boolean temp = updated;
updated = false;
return temp;
}
}
}
\ No newline at end of file
......@@ -44,23 +44,23 @@ public class EdgeAndVertexFaceMesh extends FaceMesh {
*
*/
@Override
public void addEntity(AbstractController newEntity) {
public void addEntityByCategory(AbstractController newEntity,
String category) {
// If the new entity is an edge, add it and its vertices under the
// appropriate categories.
if (newEntity instanceof EdgeController) {
if ("Edges".equals(category)) {
// Queue updates for all the new children
updateManager.enqueue();
// Add the edge under the Edges category
EdgeController edge = (EdgeController) newEntity;
addEntityByCategory(edge, "Edges");
super.addEntityByCategory(newEntity, "Edges");
// Add each of the edge's vertices under the "Vertices" category
for (AbstractController vertex : edge
for (AbstractController vertex : newEntity
.getEntitiesByCategory("Vertices")) {
addEntityByCategory(vertex, "Vertices");
super.addEntityByCategory(vertex, "Vertices");
}
// Send notifications for all children
......@@ -68,7 +68,59 @@ public class EdgeAndVertexFaceMesh extends FaceMesh {
}
// Otherwise, add the entity normally
super.addEntity(newEntity);
super.addEntityByCategory(newEntity, category);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.viz.service.modeling.AbstractMesh#removeEntity(org.
* eclipse.ice.viz.service.modeling.AbstractController)
*/
@Override
public void removeEntity(AbstractController entity) {
// Ignore requests to remove a vertex, to keep the Vertex category
// consistent with the Edges category
if (!getEntitiesByCategory("Vertices").contains(entity)) {
//Queue messages from all the removals
updateManager.enqueue();
// If the entity is an edge, also remove its vertices
if (getEntitiesByCategory("Edges").contains(entity)) {