Commit 86eac012 authored by Robert Smith's avatar Robert Smith
Browse files

Continued MeshComponentTester update again



Further work on ironing out functionality for objects for the
MeshComponentTester.
Signed-off-by: Robert Smith's avatarRobert Smith <SmithRW@ornl.gov>
parent 2e1182f9
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.ice.viz.service.modeling; package org.eclipse.ice.viz.service.modeling;
import org.eclipse.ice.viz.service.datastructures.VizObject.IManagedVizUpdateable;
import org.eclipse.ice.viz.service.datastructures.VizObject.UpdateableSubscriptionType;
/** /**
* A controller for an Edge part. * A controller for an Edge part.
* *
...@@ -57,6 +60,16 @@ public class Edge extends AbstractController { ...@@ -57,6 +60,16 @@ public class Edge extends AbstractController {
return ((EdgeComponent) model).getLength(); return ((EdgeComponent) model).getLength();
} }
@Override
public void update(IManagedVizUpdateable component,
UpdateableSubscriptionType[] type) {
// Recalculate the edge's length
((EdgeComponent) model).calculateLength();
super.update(component, type);
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
......
...@@ -70,27 +70,11 @@ public class EdgeComponent extends AbstractMeshComponent { ...@@ -70,27 +70,11 @@ public class EdgeComponent extends AbstractMeshComponent {
@Override @Override
public void addEntity(AbstractController newEntity) { public void addEntity(AbstractController newEntity) {
// When a vertex is added, take action to ensure the edge maintains its // When a vertex is added, place it into the Vertices category by
// proper state // default
if (newEntity instanceof Vertex) { if (newEntity instanceof Vertex) {
// The number of vertices addEntityByCategory(newEntity, "Vertices");
List<AbstractController> vertices = entities.get("Vertices");
int verticesNum = (vertices != null ? vertices.size() : 0);
// If the object is a vertex and the edge already has both vertices,
// fail silently.
if (verticesNum >= 2) {
return;
}
// Add the entity
super.addEntityByCategory(newEntity, "Vertices");
// If this was the second vertex, calculate the edge's new length.
if (verticesNum == 1) {
length = calculateLength();
}
// For other entities, add them normally // For other entities, add them normally
} else { } else {
...@@ -140,12 +124,16 @@ public class EdgeComponent extends AbstractMeshComponent { ...@@ -140,12 +124,16 @@ public class EdgeComponent extends AbstractMeshComponent {
} }
/** /**
* Calculates the length of the edge. This method does nothing by default, * Calculates the length of the edge, saving the value in this object as
* well as returning it to the caller. This method does nothing by default,
* and is intended to be overwritten by subclasses. * and is intended to be overwritten by subclasses.
* *
* @return The edge's current length * @return The edge's current length
*/ */
protected double calculateLength() { public double calculateLength() {
length = 0;
return 0; return 0;
} }
......
...@@ -49,8 +49,10 @@ public class LinearEdgeComponent extends EdgeComponent { ...@@ -49,8 +49,10 @@ public class LinearEdgeComponent extends EdgeComponent {
.getLocation(); .getLocation();
double[] endPoint = ((Vertex) entities.get("Vertices").get(1)) double[] endPoint = ((Vertex) entities.get("Vertices").get(1))
.getLocation(); .getLocation();
return Math.sqrt(Math.pow(startPoint[0] + endPoint[0], 2) length = Math.sqrt(Math.pow(startPoint[0] + endPoint[0], 2)
+ Math.pow(startPoint[1] + endPoint[1], 2) + Math.pow(startPoint[1] + endPoint[1], 2)
+ Math.pow(startPoint[2] + endPoint[2], 2)); + Math.pow(startPoint[2] + endPoint[2], 2));
return length;
} }
} }
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