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

Debugging Plant View parts



Fixing issues with the way the Plant View is populated and its contents
are drawn.
Signed-off-by: Robert Smith's avatarRobert Smith <SmithRW@ornl.gov>
parent 7f3118a3
......@@ -9,7 +9,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime
Bundle-Vendor: Oak Ridge National Laboratory
Eclipse-ExtensibleAPI: true
Import-Package: javafx.scene.image;version="2.2.0",
Import-Package: javafx.scene;version="2.2.0",
javafx.scene.image;version="2.2.0",
org.eclipse.ice.datastructures.ICEObject,
org.eclipse.ice.reactor.plant,
org.eclipse.ice.viz.service,
......
......@@ -168,8 +168,12 @@ public class FXShapeView extends AbstractView implements IWireFramePart {
if (customMaterial == null) {
defaultMaterial = new PhongMaterial(Color.rgb(50, 50, 255));
defaultMaterial.setSpecularColor(Color.WHITE);
box.setMaterial(defaultMaterial);
} else {
// If a material is specified, set it
box.setMaterial(customMaterial);
}
box.setMaterial(defaultMaterial);
shape = box;
}
......@@ -185,8 +189,12 @@ public class FXShapeView extends AbstractView implements IWireFramePart {
if (customMaterial == null) {
defaultMaterial = new PhongMaterial(Color.rgb(0, 181, 255));
defaultMaterial.setSpecularColor(Color.WHITE);
cyl.setMaterial(defaultMaterial);
} else {
// If a material is specified, set it
cyl.setMaterial(customMaterial);
}
cyl.setMaterial(defaultMaterial);
shape = cyl;
}
......@@ -204,8 +212,12 @@ public class FXShapeView extends AbstractView implements IWireFramePart {
if (customMaterial == null) {
defaultMaterial = new PhongMaterial(Color.rgb(131, 0, 157));
defaultMaterial.setSpecularColor(Color.WHITE);
sphere.setMaterial(defaultMaterial);
} else {
// If a material is specified, set it
sphere.setMaterial(customMaterial);
}
sphere.setMaterial(defaultMaterial);
shape = sphere;
}
......@@ -230,10 +242,15 @@ public class FXShapeView extends AbstractView implements IWireFramePart {
// If a material is not specified, create a new one
if (customMaterial == null) {
defaultMaterial = new PhongMaterial(Color.CYAN);
}
shape.setMaterial(defaultMaterial);
if (defaultMaterial == null) {
defaultMaterial = new PhongMaterial(Color.CYAN);
}
shape.setMaterial(defaultMaterial);
} else {
// If a material is specified, set it
shape.setMaterial(customMaterial);
}
break;
default:
return;
......@@ -364,6 +381,7 @@ public class FXShapeView extends AbstractView implements IWireFramePart {
// If the transformation updated, update the JavaFX transformation
if (component == transformation) {
// Set the node's transformation
node.getTransforms()
.setAll(Util.convertTransformation(transformation));
......
......@@ -105,21 +105,24 @@ public class FXJunctionView extends JunctionView implements IWireFramePart {
// Get the bounds of the region encompassing all pipe ends
Extrema boxBounds = new Extrema(pipeEdges);
// Get the size of the box, which has a minimum size of 10 x 10 x 10 in
// Get the size of the box, which has a minimum size of 1 x 1 x 1 in
// case the calculated size is smaller, as might be the case if one of
// the pipes is a secondary Heat Exchanger loop pipe which cannot be
// drawn until the center of the junction's bounds is known
centerX = Math.max(boxBounds.getMaxX() - boxBounds.getMinX(), 10);
centerY = Math.max(boxBounds.getMaxY() - boxBounds.getMinY(), 10);
centerZ = Math.max(boxBounds.getMaxZ() - boxBounds.getMinZ(), 10);
centerX = Math.max(boxBounds.getMaxX() - boxBounds.getMinX(), 1);
centerY = Math.max(boxBounds.getMaxY() - boxBounds.getMinY(), 1);
centerZ = Math.max(boxBounds.getMaxZ() - boxBounds.getMinZ(), 1);
System.out.println(
"Junction center:" + centerX + " " + centerY + " " + centerZ);
// Create a box which fills the box bounds
box = new Box(centerX, centerY, centerZ);
// Move the box to the center of the bounded area
box.setTranslateX(boxBounds.getMaxX() / 2 + boxBounds.getMinX());
box.setTranslateY(boxBounds.getMaxY() / 2 + boxBounds.getMinY());
box.setTranslateZ(boxBounds.getMaxZ() / 2 + boxBounds.getMinZ());
box.setTranslateX((boxBounds.getMaxX() + boxBounds.getMinX()) / 2);
box.setTranslateX((boxBounds.getMaxY() + boxBounds.getMinY()) / 2);
box.setTranslateX((boxBounds.getMaxZ() + boxBounds.getMinZ()) / 2);
// Add the box to the scene and set its material
node.getChildren().add(box);
......
......@@ -14,6 +14,7 @@ import org.eclipse.ice.viz.service.geometry.reactor.Extrema;
import org.eclipse.ice.viz.service.geometry.reactor.PipeMesh;
import org.eclipse.ice.viz.service.geometry.reactor.PipeView;
import org.eclipse.ice.viz.service.javafx.geometry.datatypes.FXShapeView;
import org.eclipse.ice.viz.service.modeling.AbstractMesh;
import org.eclipse.ice.viz.service.modeling.IWireFramePart;
import javafx.scene.paint.Color;
......@@ -35,6 +36,7 @@ public class FXPipeView extends FXShapeView
super();
defaultMaterial = new PhongMaterial(Color.CYAN);
defaultMaterial.setSpecularColor(Color.WHITE);
}
/**
......@@ -47,7 +49,15 @@ public class FXPipeView extends FXShapeView
public FXPipeView(PipeMesh model) {
super(model);
setMaterial(new PhongMaterial(Color.CYAN));
// Pipes are cyan by default
if (!"True".equals(model.getProperty("Core Channel"))) {
setMaterial(new PhongMaterial(Color.CYAN));
}
// Core channels are red
else {
setMaterial(new PhongMaterial(Color.RED));
}
}
/*
......@@ -88,12 +98,18 @@ public class FXPipeView extends FXShapeView
private Extrema calculateExtrema(float[] points) {
// Get the transformation's parameters
double[] rotation = transformation.getRotation();
double[] rotationDegrees = transformation.getRotation();
double[] scale = transformation.getScale();
double size = transformation.getSize();
double[] skew = transformation.getSkew();
double[] translation = transformation.getTranslation();
// Convert the degrees to radians
double[] rotation = new double[3];
rotation[0] = rotationDegrees[0] * 180 / Math.PI;
rotation[1] = rotationDegrees[1] * 180 / Math.PI;
rotation[2] = rotationDegrees[2] * 180 / Math.PI;
// TODO Apply skew from the transformation
// Consider each point one at a time
for (int i = 0; i < points.length / 3; i++) {
......@@ -183,6 +199,30 @@ public class FXPipeView extends FXShapeView
return new Extrema(minX, maxX, minY, maxY, minZ, maxZ);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ice.viz.service.javafx.geometry.datatypes.FXShapeView#refresh
* (org.eclipse.ice.viz.service.modeling.AbstractMesh)
*/
@Override
public void refresh(AbstractMesh model) {
// Pipes are cyan by default
if (!"True".equals(model.getProperty("Core Channel"))) {
defaultMaterial = new PhongMaterial(Color.CYAN);
}
// Core channels are red
else {
defaultMaterial = new PhongMaterial(Color.RED);
}
super.refresh(model);
}
// /*
// * (non-Javadoc)
// *
......
......@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.ice.viz.service.javafx.geometry.plant;
import java.util.List;
import org.eclipse.ice.reactor.plant.Boundary;
import org.eclipse.ice.reactor.plant.Branch;
import org.eclipse.ice.reactor.plant.CoreChannel;
......@@ -68,6 +70,12 @@ import org.eclipse.ice.viz.service.modeling.AbstractView;
*/
public class FXPlantCompositeConverter implements IVizUpdateableListener {
/**
* The scale which translates between RELAP7 units and JavaFX units. Each
* RELAP7 unit will be treated as SCALE JavaFX units.
*/
private final int SCALE = 100;
/**
* The root of the tree of plant parts converted from the source.
*/
......@@ -121,6 +129,26 @@ public class FXPlantCompositeConverter implements IVizUpdateableListener {
for (PlantComponent plantComp : source.getPlantComponents()) {
plantComp.accept(visitor);
}
// PipeMesh mesh = new PipeMesh();
// mesh.setAxialSamples(40);
// mesh.setInnerRadius(40);
// mesh.setLength(100);
// mesh.setRadius(50);
//
// PipeController pipe = (PipeController) new FXPlantViewFactory()
// .createController(mesh);
//
// pipe.setRotation(0, 0, 2);
//
// ShapeMesh box = new ShapeMesh();
// box.setProperty("Type", "Cube");
// ShapeController boxC = new ShapeController(box, new
// FXShapeView(box));
//
// output.addEntity(boxC);
// output.addEntity(pipe);
}
private class FXPlantComponentVisitor implements IPlantComponentVisitor {
......@@ -164,6 +192,12 @@ public class FXPlantCompositeConverter implements IVizUpdateableListener {
JunctionController junction = (JunctionController) factory
.createController(mesh);
// 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"));
// Add all the input pipes to the junction
for (PlantComponent input : plantComp.getInputs()) {
......@@ -171,8 +205,7 @@ public class FXPlantCompositeConverter implements IVizUpdateableListener {
boolean found = false;
// Check the root to see if a pipe with that id already exists
for (AbstractController pipe : root
.getEntitiesByCategory("Pipes")) {
for (AbstractController pipe : pipeList) {
if (Integer.parseInt(pipe.getProperty("Id")) == input
.getId()) {
......@@ -193,11 +226,15 @@ public class FXPlantCompositeConverter implements IVizUpdateableListener {
// Convert the pipe into a modeling data structure
input.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 : root
.getEntitiesByCategory("Pipes")) {
for (AbstractController pipe : pipeList) {
if (Integer.parseInt(pipe.getProperty("Id")) == input
.getId()) {
junction.addEntityByCategory(pipe, "Input");
......@@ -215,8 +252,7 @@ public class FXPlantCompositeConverter implements IVizUpdateableListener {
boolean found = false;
// Check the root to see if a pipe with that id already exists
for (AbstractController pipe : root
.getEntitiesByCategory("Pipes")) {
for (AbstractController pipe : pipeList) {
if (Integer.parseInt(pipe.getProperty("Id")) == output
.getId()) {
......@@ -237,6 +273,11 @@ public class FXPlantCompositeConverter implements IVizUpdateableListener {
// Convert the pipe into a modeling data structure
output.accept(this);
// Refresh the list of pipes
pipeList = root.getEntitiesByCategory("Pipes");
pipeList.addAll(
root.getEntitiesByCategory("Core Channels"));
// Now that the pipe is gauranteed to be in the root, as it
// was added when visited, find the pipe with that id and
// add it
......@@ -291,9 +332,14 @@ public class FXPlantCompositeConverter implements IVizUpdateableListener {
// 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 : root
.getEntitiesByCategory("Pipes")) {
for (AbstractController pipe : pipeList) {
if (Integer.parseInt(pipe.getProperty("Id")) == primary
.getId()) {
......@@ -312,10 +358,13 @@ public class FXPlantCompositeConverter implements IVizUpdateableListener {
// Convert the pipe into a modeling data structure
primary.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 : root
.getEntitiesByCategory("Pipes")) {
for (AbstractController pipe : pipeList) {
if (Integer.parseInt(pipe.getProperty("Id")) == primary
.getId()) {
heatExchanger.setPrimaryPipe((PipeController) pipe);
......@@ -330,8 +379,7 @@ public class FXPlantCompositeConverter implements IVizUpdateableListener {
found = false;
// Check the root to see if a pipe with that id already exists
for (AbstractController pipe : root
.getEntitiesByCategory("Pipes")) {
for (AbstractController pipe : pipeList) {
if (Integer.parseInt(pipe.getProperty("Id")) == secondary
.getId()) {
......@@ -350,10 +398,13 @@ public class FXPlantCompositeConverter implements IVizUpdateableListener {
// Convert the pipe into a modeling data structure
primary.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 : root
.getEntitiesByCategory("Pipes")) {
for (AbstractController pipe : pipeList) {
if (Integer.parseInt(pipe.getProperty("Id")) == secondary
.getId()) {
heatExchanger.setSecondaryPipe((PipeController) pipe);
......@@ -371,17 +422,17 @@ public class FXPlantCompositeConverter implements IVizUpdateableListener {
public void visit(Pipe plantComp) {
// Convert the pipe and add it to the root.
addPipe(plantComp);
root.addEntityByCategory(createPipe(plantComp), "Pipes");
}
@Override
public void visit(CoreChannel plantComp) {
// Convert the pipe and add it to the root
PipeController pipe = addPipe(plantComp);
// Convert the pipe
PipeController pipe = createPipe(plantComp);
// Set the pipe as a core channel and add it to the root again, this
// time in the core channel category
// Set the pipe as a core channel and add it to the root
pipe.setProperty("Core Channel", "True");
root.addEntityByCategory(pipe, "Core Channels");
......@@ -532,22 +583,21 @@ public class FXPlantCompositeConverter implements IVizUpdateableListener {
}
/**
* Creates a JavaFX PipeController from a RELAP7 Pipe and adds it to the
* visitor's root node.
* Creates a JavaFX PipeController from a RELAP7 Pipe.
*
* @param plantComp
* The pipe to be converted.
* @return The converted pipe.
*/
public PipeController addPipe(Pipe plantComp) {
public PipeController createPipe(Pipe plantComp) {
// Create a new pipe
PipeMesh mesh = new PipeMesh();
// Set the pipe's properties
mesh.setProperty("Id", Integer.toString(plantComp.getId()));
mesh.setLength(plantComp.getLength());
mesh.setRadius(plantComp.getRadius());
mesh.setInnerRadius(plantComp.getRadius());
mesh.setLength(plantComp.getLength() * SCALE);
mesh.setRadius(plantComp.getRadius() * SCALE);
mesh.setInnerRadius(plantComp.getRadius() * SCALE);
mesh.setAxialSamples(plantComp.getNumElements());
// Create the view and controller
......@@ -558,37 +608,64 @@ public class FXPlantCompositeConverter implements IVizUpdateableListener {
// center of the pipe's input end, while orientation is a vector
// from the position which describes the pipe's axis.
double[] position = plantComp.getPosition();
// Multiply the positions to the proper scale
position[0] = position[0] * SCALE;
position[1] = position[1] * SCALE;
position[2] = position[2] * SCALE;
// System.out.println("Original Position: " + position[0] + " "
// + position[1] + " " + position[2]);
double[] orientation = plantComp.getOrientation();
// System.out.println("Orientation Vector: " + orientation[0] + " "
// + orientation[1] + " " + orientation[2]);
// Normalize the orientation vector
double[] normalized = new double[3];
double length = Math.sqrt(
Math.pow(orientation[0], 2) + Math.pow(orientation[1], 2)
+ Math.pow(orientation[2], 2));
normalized[0] = normalized[0] / length;
normalized[1] = normalized[1] / length;
normalized[2] = normalized[2] / length;
normalized[0] = orientation[0] / length;
normalized[1] = orientation[1] / length;
normalized[2] = orientation[2] / length;
// The tube is, by default, centered on the origin. Stepping one
// half its length in the direction of the orientation vector will
// place the output edge's center on the origin, so that the
// position vector now properly represents the movement from the
// origen to the pipe's position.
position[0] += plantComp.getLength() / 2 * normalized[0];
position[1] += plantComp.getLength() / 2 * normalized[1];
position[2] += plantComp.getLength() / 2 * normalized[2];
double pipeLength = plantComp.getLength() * SCALE;
position[0] += pipeLength / 2 * normalized[0];
position[1] += pipeLength / 2 * normalized[1];
position[2] += pipeLength / 2 * normalized[2];
// System.out.println("Translation: " + position[0] + " " +
// position[1]
// + " " + position[2]);
// Set the pipe's translation
pipe.setTranslation(position[0], position[1], position[2]);
// 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]), 0,
Math.atan(normalized[1] / normalized[2]));
// vector, calculated by arccos(z).
pipe.setRotation(Math.acos(normalized[2] * 180 / Math.PI), 0,
Math.atan(zRotation * 180 / Math.PI));
// Add the pipe to the root
root.addEntityByCategory(pipe, "Pipes");
// System.out.println(
// "Rotation: " + normalized[2] + " " + 0 + " " + (zRotation));
return pipe;
}
......
......@@ -11,7 +11,6 @@
package org.eclipse.ice.viz.service.javafx.geometry.plant;
import org.eclipse.ice.viz.service.datastructures.VizObject.UpdateableSubscriptionType;
import org.eclipse.ice.viz.service.geometry.reactor.PipeController;
import org.eclipse.ice.viz.service.geometry.reactor.ReactorController;
import org.eclipse.ice.viz.service.modeling.AbstractController;
import org.eclipse.ice.viz.service.modeling.AbstractMesh;
......@@ -54,28 +53,27 @@ public class FXPlantViewRootController extends AbstractController
public void addEntity(AbstractController entity) {
// If the entity is a core channel, add it to all reactors
if (entity instanceof PipeController) {
if ("True".equals(entity.getProperty("Core Channel"))) {
if ("True".equals(entity.getProperty("Core Channel"))) {
// Queue updates from adding children
updateManager.enqueue();
// Add the entity to this, then to all reactors
model.addEntityByCategory(entity, "Core Channels");
// Queue updates from adding children
updateManager.enqueue();
for (AbstractController reactor : model
.getEntitiesByCategory("Reactors")) {
reactor.addEntity(entity);
}
// Add the entity to this, then to all reactors
model.addEntityByCategory(entity, "Core Channels");
// Fire update for the added child
UpdateableSubscriptionType[] eventTypes = new UpdateableSubscriptionType[] {
UpdateableSubscriptionType.Child };
updateManager.notifyListeners(eventTypes);
for (AbstractController reactor : model
.getEntitiesByCategory("Reactors")) {
reactor.addEntity(entity);
}
// If the entity is a reactor, add all core channels to it
} else if (entity instanceof ReactorController) {
// Fire update for the added child
UpdateableSubscriptionType[] eventTypes = new UpdateableSubscriptionType[] {
UpdateableSubscriptionType.Child };
updateManager.notifyListeners(eventTypes);
}
// If the entity is a reactor, add all core channels to it
else if (entity instanceof ReactorController) {
// Queue updates from adding children
updateManager.enqueue();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment