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

Added tests and fixed bugs



Added tests and fixed miscellaneous bugs for the javafx packages.
Signed-off-by: Robert Smith's avatarRobert Smith <SmithRW@ornl.gov>
parent b0c1cd35
......@@ -385,95 +385,6 @@ public class FXPlantCompositeConverter
applyTransformation(heatExchanger, plantComp.getPosition(),
plantComp.getOrientation(), plantComp.getLength());
// // Get the primary pipe
// Pipe primary = plantComp.getPrimaryPipe();
//
// // Whether or not a match was found
// boolean found = false;
//
// // Create a list of all pipes in the plant by combining the pipes
// // with the core channels
// List<AbstractController> pipeList = root
// .getEntitiesByCategory("Pipes");
// pipeList.addAll(root.getEntitiesByCategory("Core Channels"));
//
// // Check the root to see if a pipe with that id already exists
// for (AbstractController pipe : pipeList) {
// if (Integer.parseInt(pipe.getProperty("Id")) == primary
// .getId()) {
//
// // If found, set the pipe as the exchanger's primary
// heatExchanger.setPrimaryPipe((PipeController) pipe);
//
// // Match found, stop the search
// found = true;
// break;
// }
// }
//
// // If a match was not found, create a new pipe
// if (!found) {
//
// // Convert the pipe into a modeling data structure
// // primary.accept(this);
// source.getPlantComponent(primary.getId()).accept(this);
//
// // Refresh the list of pipes
// pipeList = root.getEntitiesByCategory("Pipes");
// pipeList.addAll(root.getEntitiesByCategory("Core Channels"));
//
// // Now that the pipe is guaranteed to be in the root, as it was
// // added when visited, find the pipe with that id and add it
// for (AbstractController pipe : pipeList) {
// if (Integer.parseInt(pipe.getProperty("Id")) == primary
// .getId()) {
// heatExchanger.setPrimaryPipe((PipeController) pipe);
// break;
// }
// }
// }
//
// // Get the secondary pipe
// Pipe secondary = plantComp.getSecondaryPipe();
//
// found = false;
//
// // Check the root to see if a pipe with that id already exists
// for (AbstractController pipe : pipeList) {
// if (Integer.parseInt(pipe.getProperty("Id")) == secondary
// .getId()) {
//
// // If found, set the pipe as the exchanger's primary
// heatExchanger.setSecondaryPipe((PipeController) pipe);
//
// // Match found, stop the search
// found = true;
// break;
// }
// }
//
// // If a match was not found, create a new pipe
// if (!found) {
//
// // Convert the pipe into a modeling data structure
// // primary.accept(this);
// source.getPlantComponent(secondary.getId()).accept(this);
//
// // Refresh the list of pipes
// pipeList = root.getEntitiesByCategory("Pipes");
// pipeList.addAll(root.getEntitiesByCategory("Core Channels"));
//
// // Now that the pipe is guaranteed to be in the root, as it was
// // added when visited, find the pipe with that id and add it
// for (AbstractController pipe : pipeList) {
// if (Integer.parseInt(pipe.getProperty("Id")) == secondary
// .getId()) {
// heatExchanger.setSecondaryPipe((PipeController) pipe);
// break;
// }
// }
// }
// Add the heat exchanger to the root
root.addEntityByCategory(heatExchanger, "Heat Exchangers");
......@@ -834,25 +745,6 @@ public class FXPlantCompositeConverter
applyTransformation(pipe, plantComp.getPosition(),
plantComp.getOrientation(), plantComp.getLength());
//
// // Calculate the amount of z rotation in the formula, applying
// none
// // if the normalized vector has a 0 X component. This is done to
// // avoid division by 0.
// double zRotation;
// if (normalized[0] != 0) {
// zRotation = normalized[1] / normalized[0] + 90;
// } else {
// zRotation = 90d;
// }
//
// // The normalized orientation vector can be represented by an
// // XY-plane angle calculated by arctan(y/x) and an angle from the
// z
// // vector, calculated by arccos(z).
// pipe.setRotation(Math.acos(normalized[2] * 180 / Math.PI), 0,
// Math.atan(zRotation * 180 / Math.PI));
return pipe;
}
......
......@@ -61,17 +61,20 @@ public class ExtremaTester {
// 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);
// Create an extrema from an empty list and check that it creates a
// region with 0 for all its values
Extrema empty = new Extrema(new ArrayList<Extrema>());
assertTrue(empty.getMinX() == 0d);
assertTrue(empty.getMaxX() == 0d);
assertTrue(empty.getMinY() == 0d);
assertTrue(empty.getMaxY() == 0d);
assertTrue(empty.getMinZ() == 0d);
assertTrue(empty.getMaxZ() == 0d);
}
}
\ No newline at end of file
......@@ -91,7 +91,8 @@ public class Extrema {
/**
* A constructor which creates an extrema from a list of the extrema of
* other sub-regions. The new extrema will be the extrema of the smallest
* region possible which contains all given sub-regions.
* region possible which contains all given sub-regions. If subRegions is
* null, the extrema will have 0 for all minimum and maximum values.
*
* @param subRegions
* The list of regions which this extrema will contain.
......@@ -101,6 +102,16 @@ public class Extrema {
// Allocate the logger
logger = LoggerFactory.getLogger(getClass());
// If the list is empty, set everything to 0
if (subRegions.isEmpty()) {
minX = 0;
maxX = 0;
minY = 0;
maxY = 0;
minZ = 0;
maxZ = 0;
}
for (Extrema region : subRegions) {
// For subsequent regions, compare each value
......
......@@ -10,8 +10,10 @@
*******************************************************************************/
package org.eclipse.ice.viz.service.geometry.reactor;
import java.util.ArrayList;
import java.util.List;
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;
......@@ -107,6 +109,58 @@ public class HeatExchangerMesh extends AbstractMesh {
addEntityByCategory(pipe, "Secondary Pipe");
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ice.viz.service.modeling.AbstractMesh#addEntityByCategory(org
* .eclipse.ice.viz.service.modeling.AbstractController, java.lang.String)
*/
@Override
public void addEntityByCategory(AbstractController newEntity,
String category) {
// Don't listen to junctions, to avoid circular listening
if ("Secondary Input".equals(category)
|| "Secondary Output".equals(category)) {
// Get the entities for the given category
List<AbstractController> catList = entities.get(category);
// If the list is null, make an empty one
if (catList == null) {
catList = new ArrayList<AbstractController>();
}
// Prevent a part from being added multiple times
else if (catList.contains(newEntity)) {
return;
}
// If the entity is already present in this category, don't add a
// second
// entry for it
else
for (AbstractController entity : catList) {
if (entity == newEntity) {
return;
}
}
// Add the entity to the list and put it in the map
catList.add(newEntity);
entities.put(category, catList);
SubscriptionType[] eventTypes = { SubscriptionType.CHILD };
updateManager.notifyListeners(eventTypes);
}
// Otherwise, add the entity normally
else {
super.addEntityByCategory(newEntity, category);
}
}
/*
* (non-Javadoc)
*
......
/*******************************************************************************
* 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.javafx.geometry.plant.test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.eclipse.ice.viz.service.geometry.reactor.HeatExchangerMesh;
import org.eclipse.ice.viz.service.javafx.geometry.plant.FXHeatExchangerController;
import org.eclipse.ice.viz.service.javafx.geometry.plant.FXHeatExchangerView;
import org.eclipse.ice.viz.service.modeling.AbstractMesh;
import org.junit.Test;
/**
* A class for testing the functionality of the FXHeatExchangerController
*
* @author Robert Smith
*
*/
public class FXHeatExchangerControllerTester {
/**
* Check that the exchanger will ignore Wireframe type messages except when
* they are sent by the controller's view.
*/
@Test
public void checkUpdate() {
// Create an exchanger
HeatExchangerMesh mesh = new HeatExchangerMesh();
TestHeatExchangerView view = new TestHeatExchangerView(mesh);
FXHeatExchangerController exchanger = new FXHeatExchangerController(
mesh, view);
// Reset the view's refreshed state
view.wasRefreshed();
// Set the view to wireframe mode
view.setWireFrameMode(true);
// This should have signaled the controller to perform a refresh
assertTrue(view.wasRefreshed());
// Create a second exchanger
HeatExchangerMesh mesh2 = new HeatExchangerMesh();
TestHeatExchangerView view2 = new TestHeatExchangerView(mesh2);
FXHeatExchangerController exchanger2 = new FXHeatExchangerController(
mesh2, view2);
// Add it as a child to the current one
exchanger.addEntity(exchanger2);
// Reset the view's state
view.wasRefreshed();
// Set the child's view to wireframe mode
view2.setWireFrameMode(true);
// Since the wireframe message was not received from the controller's
// view, it should not cause the controller to refresh the view.
assertFalse(view.wasRefreshed());
}
private class TestHeatExchangerView extends FXHeatExchangerView {
/**
* Whether the view has been refreshed since the last time it was
* checked.
*/
boolean refreshed = false;
/**
* The default constructor.
*
* @param model
* The internal model to be dispalyed.
*/
public TestHeatExchangerView(AbstractMesh model) {
super(model);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ice.viz.service.javafx.geometry.plant.FXHeatExchangerView
* #refresh(org.eclipse.ice.viz.service.modeling.AbstractMesh)
*/
@Override
public void refresh(AbstractMesh model) {
super.refresh(model);
refreshed = true;
}
/**
* Determines if the view has been refreshed since the last time it was
* checked and returns it to its initial, un-refreshed state.
*
* @return True if the view has been refreshed since the last time
* wasRefreshed() was invoked. False otherwise.
*/
public boolean wasRefreshed() {
boolean temp = refreshed;
refreshed = false;
return temp;
}
}
}
/*******************************************************************************
* 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.javafx.geometry.plant.test;
import static org.junit.Assert.assertEquals;
import org.eclipse.ice.viz.service.geometry.reactor.HeatExchangerMesh;
import org.eclipse.ice.viz.service.geometry.reactor.JunctionController;
import org.eclipse.ice.viz.service.geometry.reactor.JunctionMesh;
import org.eclipse.ice.viz.service.geometry.reactor.PipeMesh;
import org.eclipse.ice.viz.service.javafx.geometry.plant.FXHeatExchangerController;
import org.eclipse.ice.viz.service.javafx.geometry.plant.FXHeatExchangerView;
import org.eclipse.ice.viz.service.javafx.geometry.plant.FXJunctionView;
import org.eclipse.ice.viz.service.javafx.geometry.plant.FXPipeController;
import org.eclipse.ice.viz.service.javafx.geometry.plant.FXPipeView;
import org.junit.Test;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.shape.Box;
import javafx.scene.shape.MeshView;
/**
* A class to test the functionality of the FXHeatExchangerView
*
* @author Robert Smith
*
*/
public class FXHeatExchangerViewTester {
/**
* Check that the view produces the correct JavaFX output.
*/
@Test
public void checkView() {
// Create a pipe for the HeatExchanger to contain
PipeMesh pipeMesh = new PipeMesh();
pipeMesh.setLength(100);
pipeMesh.setInnerRadius(25);
pipeMesh.setRadius(25);
pipeMesh.setAxialSamples(3);
FXPipeView pipeView = new FXPipeView(pipeMesh);
FXPipeController pipe = new FXPipeController(pipeMesh, pipeView);
// Create a heat exchanger
HeatExchangerMesh mesh = new HeatExchangerMesh();
FXHeatExchangerView view = new FXHeatExchangerView(mesh);
FXHeatExchangerController exchanger = new FXHeatExchangerController(
mesh, view);
exchanger.setPrimaryPipe(pipe);
// Create a second pipe and two junctions to connect it to the exchanger
PipeMesh pipeMesh2 = new PipeMesh();
pipeMesh2.setLength(100);
pipeMesh2.setInnerRadius(25);
pipeMesh2.setRadius(25);
pipeMesh2.setAxialSamples(3);
FXPipeView pipeView2 = new FXPipeView(pipeMesh2);
FXPipeController pipe2 = new FXPipeController(pipeMesh2, pipeView2);
pipe2.setTranslation(50, 0, 0);
JunctionMesh junctionMesh = new JunctionMesh();
FXJunctionView junctionView = new FXJunctionView(junctionMesh);
JunctionController junction = new JunctionController(junctionMesh,
junctionView);
junction.addEntityByCategory(exchanger, "Input");
exchanger.addEntityByCategory(junction, "Secondary Output");
junction.addEntityByCategory(pipe2, "Output");
pipe2.addEntityByCategory(junction, "Input");
JunctionMesh junctionMesh2 = new JunctionMesh();
FXJunctionView junctionView2 = new FXJunctionView(junctionMesh2);
JunctionController junction2 = new JunctionController(junctionMesh2,
junctionView2);
junction.addEntityByCategory(exchanger, "Output");
exchanger.addEntityByCategory(junction2, "Secondary Input");
junction2.addEntityByCategory(pipe2, "Input");
pipe2.addEntityByCategory(junction2, "Output");
// Check that the view has all four parts: a central pipe, a box around
// it, and two pipes leading to junctions.
Group node = (Group) exchanger.getRepresentation();
assertEquals(4, node.getChildren().size());
// The number of children of each type found
int numPipes = 0;
int numWalls = 0;
int numPrimaryPipes = 0;
// Count each child from the node
for (Node child : node.getChildren()) {
// MeshViews contain custom pipe meshes
if (child instanceof MeshView) {
numPipes++;
}
// A box is used to draw the seperating wall
else if (child instanceof Box) {
numWalls++;
}
// The child primary pipe will package its own rendering in a group
else if (child instanceof Group) {
numPrimaryPipes++;
}
}
// Check that there are three pipes and a wall
assertEquals(2, numPipes);
assertEquals(1, numWalls);
assertEquals(1, numPrimaryPipes);
}
}
/*******************************************************************************
* 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.javafx.geometry.plant.test;
import static org.junit.Assert.assertTrue;
import org.eclipse.ice.viz.service.geometry.reactor.JunctionMesh;
import org.eclipse.ice.viz.service.geometry.reactor.PipeMesh;
import org.eclipse.ice.viz.service.javafx.geometry.plant.FXJunctionView;
import org.eclipse.ice.viz.service.javafx.geometry.plant.FXPipeController;
import org.eclipse.ice.viz.service.javafx.geometry.plant.FXPipeView;
import org.junit.Test;
/**
* A class to test the functionality of FXJunctionView
*
* @author Robert Smith
*
*/
public class FXJunctionViewTester {
/**
* Check that the junction is drawn in the right position to cover the ends
* of its pipes.
*/
@Test
public void checkPosition() {
// Create a view on a junction with no connecting pipes
JunctionMesh mesh = new JunctionMesh();
FXJunctionView view = new FXJunctionView(mesh);
// Check that the junction is centered at the origin by default
assertTrue(view.getCenter()[0] == 0d);
assertTrue(view.getCenter()[1] == 0d);
assertTrue(view.getCenter()[2] == 0d);
// Create a pipe
PipeMesh pipeMesh = new PipeMesh();
pipeMesh.setLength(100);
pipeMesh.setInnerRadius(25);
pipeMesh.setRadius(25);
pipeMesh.setAxialSamples(3);
FXPipeView pipeView = new FXPipeView(pipeMesh);
FXPipeController pipe = new FXPipeController(pipeMesh, pipeView);
// Add the pipe as input
mesh.addEntityByCategory(pipe, "Input");
System.out.println(view.getCenter());
}
}