From 0a3391041194e3d5d068f9c37ee9ba4d71c78d63 Mon Sep 17 00:00:00 2001 From: Kasper Gammeltoft Date: Tue, 23 Jun 2015 17:04:14 -0400 Subject: [PATCH 1/4] Added fields for deltaq0, deltaq1byq, and wave length for input. Implemented reading of those fields when the model is processing. Signed-off-by: Kasper Gammeltoft --- .../META-INF/MANIFEST.MF | 5 +- .../ice/reflectivity/ReflectivityModel.java | 161 ++++++++++++++++-- 2 files changed, 147 insertions(+), 19 deletions(-) diff --git a/src/org.eclipse.ice.reflectivity/META-INF/MANIFEST.MF b/src/org.eclipse.ice.reflectivity/META-INF/MANIFEST.MF index 893c947f6..33276d882 100644 --- a/src/org.eclipse.ice.reflectivity/META-INF/MANIFEST.MF +++ b/src/org.eclipse.ice.reflectivity/META-INF/MANIFEST.MF @@ -8,9 +8,12 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Import-Package: org.apache.commons.math;version="2.1.0", org.apache.commons.math.complex;version="2.1.0", org.apache.commons.math.special;version="2.1.0", + org.eclipse.ice.io.csv, + org.eclipse.ice.io.serializable, org.eclipse.ice.item, org.eclipse.ice.item.model, - org.eclipse.ice.materials + org.eclipse.ice.materials, + org.eclipse.ui.forms.widgets Require-Bundle: org.eclipse.ice.datastructures;bundle-version="2.0.0", org.eclipse.core.resources;bundle-version="3.8.101", org.eclipse.core.runtime;bundle-version="3.9.100" diff --git a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java index 39bc19234..7be6a4f14 100644 --- a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java +++ b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java @@ -8,7 +8,7 @@ * Contributors: * Initial API and implementation and/or initial documentation - Jay Jay Billings, * Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson, - * Claire Saunders, Matthew Wang, Anna Wojtowicz + * Claire Saunders, Matthew Wang, Anna Wojtowicz, Kasper Gammeltoft *******************************************************************************/ package org.eclipse.ice.reflectivity; @@ -25,10 +25,12 @@ import org.eclipse.ice.datastructures.ICEObject.ListComponent; import org.eclipse.ice.datastructures.form.AllowedValueType; import org.eclipse.ice.datastructures.form.DataComponent; import org.eclipse.ice.datastructures.form.Entry; +import org.eclipse.ice.datastructures.form.Form; import org.eclipse.ice.datastructures.form.FormStatus; import org.eclipse.ice.datastructures.form.Material; import org.eclipse.ice.datastructures.form.ResourceComponent; import org.eclipse.ice.datastructures.resource.VizResource; +import org.eclipse.ice.io.csv.CSVReader; import org.eclipse.ice.item.model.Model; import org.eclipse.ice.materials.IMaterialsDatabase; import org.eclipse.ice.materials.MaterialWritableTableFormat; @@ -38,7 +40,7 @@ import org.eclipse.ice.materials.MaterialWritableTableFormat; * layered on top of each other. It... * - * @author Jay Jay Billings, Alex McCaskey + * @author Jay Jay Billings, Alex McCaskey, Kasper Gammeltoft */ @XmlRootElement(name = "ReflectivityModel") public class ReflectivityModel extends Model { @@ -48,6 +50,41 @@ public class ReflectivityModel extends Model { */ private final String processActionName = "Calculate Reflectivity"; + /** + * The name for the wave vector entry. + */ + private static final String WaveEntryName = "Wave Vector (Q) file"; + + /** + * The roughness entry name. + */ + private static final String RoughnessEntryName = "Roughness"; + + /** + * The delta q0 entry name. + */ + private static final String deltaQ0EntryName = "deltaQ0"; + + /** + * The delta q1 by q entry name. + */ + private static final String deltaQ1ByQEntryName = "deltaQ1ByQ"; + + /** + * The wave length entry name. + */ + private static final String WaveLengthEntryName = "Wave Length"; + + /** + * The output file for reflectivity data. + */ + private IFile reflectivityFile; + + /** + * the output file for the scattering density profile data + */ + private IFile scatteringFile; + /** * Identification number for the component that contains the parameters. */ @@ -91,14 +128,9 @@ public class ReflectivityModel extends Model { if (actionName.equals(processActionName)) { - // Convert the material table to slabs - - // Get the roughness parameter, dQ, dQ/Q and the wavelength - - // Get and load the wave vector and related information - + // Get the material list from the form. ListComponent matList = (ListComponent) form - .getComponent(2); + .getComponent(matListId); ArrayList slabs = new ArrayList(); // Create the slabs from the materials @@ -115,12 +147,58 @@ public class ReflectivityModel extends Model { slabs.add(slab); } + // Get the roughness from the form. + int numRough = Integer.parseInt(((DataComponent) form + .getComponent(paramsCompId)).retrieveEntry( + RoughnessEntryName).getValue()); + + // Get the deltaQ0 from the form. + double deltaQ0 = Double.parseDouble(((DataComponent) form + .getComponent(paramsCompId)) + .retrieveEntry(deltaQ0EntryName).getValue()); + + // Get the deltaQ0 from the form. + double deltaQ1ByQ = Double.parseDouble(((DataComponent) form + .getComponent(paramsCompId)).retrieveEntry( + deltaQ1ByQEntryName).getValue()); + + // Get the wave length from the form. + double wavelength = Double.parseDouble(((DataComponent) form + .getComponent(paramsCompId)).retrieveEntry( + WaveLengthEntryName).getValue()); + + // Get the wave vector from the file picker in the paramters + // component. + double[] waveVector; + String fileName = ((DataComponent) form.getComponent(paramsCompId)) + .retrieveEntry(WaveEntryName).getValue(); + + // Get the file that should have been pulled into the local project. + IFile waveInput = project.getFile(fileName); + + // Get the reader and read in the values. + Form form = new CSVReader().read(waveInput); + ListComponent waveData = (ListComponent) form + .getComponent(1); + + // Pull the data from the form into an array. + waveVector = new double[waveData.size()]; + for (int i = 0; i < waveData.size(); i++) { + String[] dataLine = waveData.get(i); + double dataEntry = Double.parseDouble(dataLine[0]); + waveVector[i] = dataEntry; + } + // Calculate the reflectivity ReflectivityCalculator calculator = new ReflectivityCalculator(); - // calculator.getReflectivityProfile(slabs, numRough, deltaQ0, - // deltaQ1ByQ, wavelength, waveVector, getRQ4); + ReflectivityProfile profile = calculator.getReflectivityProfile( + slabs.toArray(new Slab[slabs.size()]), numRough, deltaQ0, + deltaQ1ByQ, wavelength, waveVector, true); - // Write the files + // Write the files. + double[] reflectivity = profile.reflectivity; + double[] scatDensity = profile.scatteringDensity; + double[] depth = profile.depth; retVal = FormStatus.InfoError; } else { @@ -142,8 +220,8 @@ public class ReflectivityModel extends Model { String line1 = "#features,t, p_x, p_y\n"; String line2 = "#units,t,p_x,p_y\n"; String line3 = "1.0,1.0,1.0\n"; - String line4 = "2.0,4.0,8.0\n"; - String line5 = "3.0,9.0,27.0\n"; + String line4 = "2.0,4.0,4.0\n"; + String line5 = "3.0,9.0,9.0\n"; String allLines = line1 + line2 + line3 + line4 + line5; // Create an empty stream for the output files @@ -172,7 +250,7 @@ public class ReflectivityModel extends Model { } }; fileEntry.setId(1); - fileEntry.setName("Wave Vector (Q) file"); + fileEntry.setName(WaveEntryName); fileEntry.setDescription("Wave vector information for this problem."); paramComponent.addEntry(fileEntry); @@ -189,11 +267,58 @@ public class ReflectivityModel extends Model { } }; numLayersEntry.setId(2); - numLayersEntry.setName("Roughness"); + numLayersEntry.setName(RoughnessEntryName); numLayersEntry.setDescription("Number of layers of " + "roughness per material layer."); paramComponent.addEntry(numLayersEntry); + // Add an entry for the deltaQ0 + Entry deltaQ0Entry = new Entry() { + @Override + protected void setup() { + allowedValueType = AllowedValueType.Continuous; + allowedValues.add(".00001"); + allowedValues.add("5.0"); + return; + } + }; + deltaQ0Entry.setId(3); + deltaQ0Entry.setName(deltaQ0EntryName); + deltaQ0Entry + .setDescription("The incident angle of the neutron stream."); + paramComponent.addEntry(deltaQ0Entry); + + // Add an entry for the deltaQ1ByQ + Entry deltaQ1Entry = new Entry() { + @Override + protected void setup() { + allowedValueType = AllowedValueType.Continuous; + allowedValues.add(".00001"); + allowedValues.add("5.0"); + return; + } + }; + deltaQ1Entry.setId(4); + deltaQ1Entry.setName(deltaQ1ByQEntryName); + deltaQ1Entry + .setDescription("The angle of refraction on the neutron stream."); + paramComponent.addEntry(deltaQ1Entry); + + // Add an entry for the wavelength + Entry waveEntry = new Entry() { + @Override + protected void setup() { + allowedValueType = AllowedValueType.Continuous; + allowedValues.add(".000001"); + allowedValues.add("1000"); + return; + } + }; + waveEntry.setId(5); + waveEntry.setName(WaveLengthEntryName); + waveEntry.setDescription("The wavelength of the neutron stream."); + paramComponent.addEntry(waveEntry); + // Configure a list of property names for the materials ArrayList names = new ArrayList(); names.add("Material ID"); @@ -224,9 +349,9 @@ public class ReflectivityModel extends Model { // FIXME! ID is always 1 at this point! String basename = "reflectivityModel_" + getId() + "_"; // Create the output file for the reflectivity data - IFile reflectivityFile = project.getFile(basename + "rfd.csv"); + reflectivityFile = project.getFile(basename + "rfd.csv"); // Create the output file for the scattering density data - IFile scatteringFile = project.getFile(basename + "scdens.csv"); + scatteringFile = project.getFile(basename + "scdens.csv"); try { // Reflectivity first if (reflectivityFile.exists()) { -- GitLab From 2f110058b3099e30aeb4abba7841a95c7c1dd245 Mon Sep 17 00:00:00 2001 From: Kasper Gammeltoft Date: Wed, 24 Jun 2015 16:11:42 -0400 Subject: [PATCH 2/4] Made reflectivity model finally write its data to the files. Confirmed that the model works, however it is plagued still by bugs. Working on those next. Signed-off-by: Kasper Gammeltoft --- .../ice/reflectivity/ReflectivityModel.java | 116 +++++++++++++----- .../test/ReflectivityModelBuilderTester.java | 2 +- .../test/ReflectivityModelTester.java | 6 +- 3 files changed, 90 insertions(+), 34 deletions(-) diff --git a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java index 7be6a4f14..26d2e3ebe 100644 --- a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java +++ b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java @@ -12,8 +12,10 @@ *******************************************************************************/ package org.eclipse.ice.reflectivity; +import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import javax.xml.bind.annotation.XmlRootElement; @@ -29,6 +31,7 @@ import org.eclipse.ice.datastructures.form.Form; import org.eclipse.ice.datastructures.form.FormStatus; import org.eclipse.ice.datastructures.form.Material; import org.eclipse.ice.datastructures.form.ResourceComponent; +import org.eclipse.ice.datastructures.resource.ICEResource; import org.eclipse.ice.datastructures.resource.VizResource; import org.eclipse.ice.io.csv.CSVReader; import org.eclipse.ice.item.model.Model; @@ -75,16 +78,6 @@ public class ReflectivityModel extends Model { */ private static final String WaveLengthEntryName = "Wave Length"; - /** - * The output file for reflectivity data. - */ - private IFile reflectivityFile; - - /** - * the output file for the scattering density profile data - */ - private IFile scatteringFile; - /** * Identification number for the component that contains the parameters. */ @@ -96,6 +89,12 @@ public class ReflectivityModel extends Model { */ public static final int matListId = 2; + /** + * Identification number for the resource component that contains the output + * files. + */ + public static final int resourceCompId = 3; + /** * The constructor. */ @@ -123,8 +122,9 @@ public class ReflectivityModel extends Model { @Override public FormStatus process(String actionName) { - // Local Declarations - FormStatus retVal; + // Local Declarations. Return this value to display the process status + // on the form. + FormStatus retVal = null; if (actionName.equals(processActionName)) { @@ -177,8 +177,8 @@ public class ReflectivityModel extends Model { IFile waveInput = project.getFile(fileName); // Get the reader and read in the values. - Form form = new CSVReader().read(waveInput); - ListComponent waveData = (ListComponent) form + Form waveForm = new CSVReader().read(waveInput); + ListComponent waveData = (ListComponent) waveForm .getComponent(1); // Pull the data from the form into an array. @@ -189,22 +189,73 @@ public class ReflectivityModel extends Model { waveVector[i] = dataEntry; } - // Calculate the reflectivity + // Calculate the reflectivity - FIXME! Add RQ4 parameter ReflectivityCalculator calculator = new ReflectivityCalculator(); ReflectivityProfile profile = calculator.getReflectivityProfile( slabs.toArray(new Slab[slabs.size()]), numRough, deltaQ0, - deltaQ1ByQ, wavelength, waveVector, true); + deltaQ1ByQ, wavelength, waveVector, false); - // Write the files. + // Get the data from the profile double[] reflectivity = profile.reflectivity; double[] scatDensity = profile.scatteringDensity; double[] depth = profile.depth; - retVal = FormStatus.InfoError; + // Create the csv data for the reflectivity file + String reflectData = "#features, p_x, p_y\n#units,p_x,p_y\n"; + for (int i = 0; i < reflectivity.length; i++) { + reflectData += Double.toString(reflectivity[i]) + "," + + Double.toString(waveVector[i]) + "\n"; + } + + // Create the stream + ByteArrayInputStream reflectStream = new ByteArrayInputStream( + reflectData.getBytes()); + + // Create the data for the scattering density profile + String scatData = "#features, p_x, p_y\n#units,p_x,p_y\n"; + for (int i = 0; i < depth.length; i++) { + scatData += Double.toString(scatDensity[i]) + "," + + Double.toString(depth[i]) + "\n"; + } + + ResourceComponent resComp = (ResourceComponent) form + .getComponent(resourceCompId); + + // Create the stream + ByteArrayInputStream scatStream = new ByteArrayInputStream( + scatData.getBytes()); + + // Write the data to the files. + try { + // First the reflectivity file + VizResource reflectSource = (VizResource)resComp.get(0); + IFile reflectivityFile = project.getFile(reflectSource.getContents().getName()); + reflectivityFile.setContents(new BufferedInputStream( + reflectStream), true, false, null); + + // Then the scattering density file + VizResource scatSource = (VizResource)resComp.get(1); + IFile scatteringFile = project.getFile(scatSource.getContents().getName()); + scatteringFile.setContents(new BufferedInputStream(scatStream), + true, false, null); + + // Catch exceptions, should return an error. + } catch (CoreException | NullPointerException e) { + e.printStackTrace(); + retVal = FormStatus.InfoError; + } + + // Return processed if the value has not already beens set. + if (retVal == null) { + retVal = FormStatus.Processed; + } + + // Some other process action. } else { retVal = super.process(actionName); } + // Finally return retVal. return retVal; } @@ -217,11 +268,11 @@ public class ReflectivityModel extends Model { protected void setupForm() { // FIXME! Simple data entered now for testing - String line1 = "#features,t, p_x, p_y\n"; - String line2 = "#units,t,p_x,p_y\n"; - String line3 = "1.0,1.0,1.0\n"; - String line4 = "2.0,4.0,4.0\n"; - String line5 = "3.0,9.0,9.0\n"; + String line1 = "#features, p_x, p_y\n"; + String line2 = "#units,p_x,p_y\n"; + String line3 = "1.0,1.0\n"; + String line4 = "2.0,4.0\n"; + String line5 = "3.0,9.0\n"; String allLines = line1 + line2 + line3 + line4 + line5; // Create an empty stream for the output files @@ -345,13 +396,20 @@ public class ReflectivityModel extends Model { // Make sure to put it in the form! form.addComponent(matList); + // Create a component to hold the output + ResourceComponent resources = new ResourceComponent(); + resources.setName("Results"); + resources.setDescription("Results and Output"); + resources.setId(resourceCompId); + form.addComponent(resources); + if (project != null) { // FIXME! ID is always 1 at this point! String basename = "reflectivityModel_" + getId() + "_"; // Create the output file for the reflectivity data - reflectivityFile = project.getFile(basename + "rfd.csv"); + IFile reflectivityFile = project.getFile(basename + "rfd.csv"); // Create the output file for the scattering density data - scatteringFile = project.getFile(basename + "scdens.csv"); + IFile scatteringFile = project.getFile(basename + "scdens.csv"); try { // Reflectivity first if (reflectivityFile.exists()) { @@ -380,15 +438,9 @@ public class ReflectivityModel extends Model { scatDensitySource.setId(2); scatDensitySource.setDescription("Data from Stattering " + "Density calculation"); - - // Create a component to hold the output - ResourceComponent resources = new ResourceComponent(); - resources.setName("Results"); - resources.setDescription("Results and Output"); - resources.setId(2); + resources.addResource(reflectivitySource); resources.addResource(scatDensitySource); - form.addComponent(resources); } catch (CoreException | IOException e) { // Complain System.err.println("ReflectivityModel Error: " diff --git a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelBuilderTester.java b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelBuilderTester.java index f3fa8e7a7..8dc6103f3 100644 --- a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelBuilderTester.java +++ b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelBuilderTester.java @@ -62,7 +62,7 @@ public class ReflectivityModelBuilderTester implements IMaterialsDatabase { // Make sure we have a form and some components assertNotNull(model.getForm()); - assertEquals(2, model.getForm().getComponents().size()); + assertEquals(3, model.getForm().getComponents().size()); // Get the table component list = (ListComponent) model.getForm().getComponent(ReflectivityModel.matListId); diff --git a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelTester.java b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelTester.java index 7794cf6ab..57e6638e0 100644 --- a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelTester.java +++ b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelTester.java @@ -54,7 +54,7 @@ public class ReflectivityModelTester implements IMaterialsDatabase { // Make sure we have a form and some components assertNotNull(model.getForm()); - assertEquals(2, model.getForm().getComponents().size()); + assertEquals(3, model.getForm().getComponents().size()); // Get the table component list = (ListComponent) model.getForm().getComponent(ReflectivityModel.matListId); @@ -67,6 +67,10 @@ public class ReflectivityModelTester implements IMaterialsDatabase { // setupFormWithServices() worked. assertNotNull(list.getElementSource()); assertEquals(list.getElementSource(),this); + + // Make sure the other components in the form are not null. + assertNotNull(model.getForm().getComponent(ReflectivityModel.paramsCompId)); + assertNotNull(model.getForm().getComponent(ReflectivityModel.resourceCompId)); return; } -- GitLab From 88551943f89a56d7d4720a76640139340d014dc6 Mon Sep 17 00:00:00 2001 From: Kasper Gammeltoft Date: Wed, 24 Jun 2015 16:11:42 -0400 Subject: [PATCH 3/4] Made reflectivity model finally write its data to the files. Confirmed that the model works, however it is plagued still by bugs. Working on those next. Signed-off-by: Kasper Gammeltoft --- .../ice/reflectivity/ReflectivityModel.java | 116 +++++++++++++----- .../test/ReflectivityModelBuilderTester.java | 2 +- .../test/ReflectivityModelTester.java | 6 +- 3 files changed, 90 insertions(+), 34 deletions(-) diff --git a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java index 7be6a4f14..26d2e3ebe 100644 --- a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java +++ b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java @@ -12,8 +12,10 @@ *******************************************************************************/ package org.eclipse.ice.reflectivity; +import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import javax.xml.bind.annotation.XmlRootElement; @@ -29,6 +31,7 @@ import org.eclipse.ice.datastructures.form.Form; import org.eclipse.ice.datastructures.form.FormStatus; import org.eclipse.ice.datastructures.form.Material; import org.eclipse.ice.datastructures.form.ResourceComponent; +import org.eclipse.ice.datastructures.resource.ICEResource; import org.eclipse.ice.datastructures.resource.VizResource; import org.eclipse.ice.io.csv.CSVReader; import org.eclipse.ice.item.model.Model; @@ -75,16 +78,6 @@ public class ReflectivityModel extends Model { */ private static final String WaveLengthEntryName = "Wave Length"; - /** - * The output file for reflectivity data. - */ - private IFile reflectivityFile; - - /** - * the output file for the scattering density profile data - */ - private IFile scatteringFile; - /** * Identification number for the component that contains the parameters. */ @@ -96,6 +89,12 @@ public class ReflectivityModel extends Model { */ public static final int matListId = 2; + /** + * Identification number for the resource component that contains the output + * files. + */ + public static final int resourceCompId = 3; + /** * The constructor. */ @@ -123,8 +122,9 @@ public class ReflectivityModel extends Model { @Override public FormStatus process(String actionName) { - // Local Declarations - FormStatus retVal; + // Local Declarations. Return this value to display the process status + // on the form. + FormStatus retVal = null; if (actionName.equals(processActionName)) { @@ -177,8 +177,8 @@ public class ReflectivityModel extends Model { IFile waveInput = project.getFile(fileName); // Get the reader and read in the values. - Form form = new CSVReader().read(waveInput); - ListComponent waveData = (ListComponent) form + Form waveForm = new CSVReader().read(waveInput); + ListComponent waveData = (ListComponent) waveForm .getComponent(1); // Pull the data from the form into an array. @@ -189,22 +189,73 @@ public class ReflectivityModel extends Model { waveVector[i] = dataEntry; } - // Calculate the reflectivity + // Calculate the reflectivity - FIXME! Add RQ4 parameter ReflectivityCalculator calculator = new ReflectivityCalculator(); ReflectivityProfile profile = calculator.getReflectivityProfile( slabs.toArray(new Slab[slabs.size()]), numRough, deltaQ0, - deltaQ1ByQ, wavelength, waveVector, true); + deltaQ1ByQ, wavelength, waveVector, false); - // Write the files. + // Get the data from the profile double[] reflectivity = profile.reflectivity; double[] scatDensity = profile.scatteringDensity; double[] depth = profile.depth; - retVal = FormStatus.InfoError; + // Create the csv data for the reflectivity file + String reflectData = "#features, p_x, p_y\n#units,p_x,p_y\n"; + for (int i = 0; i < reflectivity.length; i++) { + reflectData += Double.toString(reflectivity[i]) + "," + + Double.toString(waveVector[i]) + "\n"; + } + + // Create the stream + ByteArrayInputStream reflectStream = new ByteArrayInputStream( + reflectData.getBytes()); + + // Create the data for the scattering density profile + String scatData = "#features, p_x, p_y\n#units,p_x,p_y\n"; + for (int i = 0; i < depth.length; i++) { + scatData += Double.toString(scatDensity[i]) + "," + + Double.toString(depth[i]) + "\n"; + } + + ResourceComponent resComp = (ResourceComponent) form + .getComponent(resourceCompId); + + // Create the stream + ByteArrayInputStream scatStream = new ByteArrayInputStream( + scatData.getBytes()); + + // Write the data to the files. + try { + // First the reflectivity file + VizResource reflectSource = (VizResource)resComp.get(0); + IFile reflectivityFile = project.getFile(reflectSource.getContents().getName()); + reflectivityFile.setContents(new BufferedInputStream( + reflectStream), true, false, null); + + // Then the scattering density file + VizResource scatSource = (VizResource)resComp.get(1); + IFile scatteringFile = project.getFile(scatSource.getContents().getName()); + scatteringFile.setContents(new BufferedInputStream(scatStream), + true, false, null); + + // Catch exceptions, should return an error. + } catch (CoreException | NullPointerException e) { + e.printStackTrace(); + retVal = FormStatus.InfoError; + } + + // Return processed if the value has not already beens set. + if (retVal == null) { + retVal = FormStatus.Processed; + } + + // Some other process action. } else { retVal = super.process(actionName); } + // Finally return retVal. return retVal; } @@ -217,11 +268,11 @@ public class ReflectivityModel extends Model { protected void setupForm() { // FIXME! Simple data entered now for testing - String line1 = "#features,t, p_x, p_y\n"; - String line2 = "#units,t,p_x,p_y\n"; - String line3 = "1.0,1.0,1.0\n"; - String line4 = "2.0,4.0,4.0\n"; - String line5 = "3.0,9.0,9.0\n"; + String line1 = "#features, p_x, p_y\n"; + String line2 = "#units,p_x,p_y\n"; + String line3 = "1.0,1.0\n"; + String line4 = "2.0,4.0\n"; + String line5 = "3.0,9.0\n"; String allLines = line1 + line2 + line3 + line4 + line5; // Create an empty stream for the output files @@ -345,13 +396,20 @@ public class ReflectivityModel extends Model { // Make sure to put it in the form! form.addComponent(matList); + // Create a component to hold the output + ResourceComponent resources = new ResourceComponent(); + resources.setName("Results"); + resources.setDescription("Results and Output"); + resources.setId(resourceCompId); + form.addComponent(resources); + if (project != null) { // FIXME! ID is always 1 at this point! String basename = "reflectivityModel_" + getId() + "_"; // Create the output file for the reflectivity data - reflectivityFile = project.getFile(basename + "rfd.csv"); + IFile reflectivityFile = project.getFile(basename + "rfd.csv"); // Create the output file for the scattering density data - scatteringFile = project.getFile(basename + "scdens.csv"); + IFile scatteringFile = project.getFile(basename + "scdens.csv"); try { // Reflectivity first if (reflectivityFile.exists()) { @@ -380,15 +438,9 @@ public class ReflectivityModel extends Model { scatDensitySource.setId(2); scatDensitySource.setDescription("Data from Stattering " + "Density calculation"); - - // Create a component to hold the output - ResourceComponent resources = new ResourceComponent(); - resources.setName("Results"); - resources.setDescription("Results and Output"); - resources.setId(2); + resources.addResource(reflectivitySource); resources.addResource(scatDensitySource); - form.addComponent(resources); } catch (CoreException | IOException e) { // Complain System.err.println("ReflectivityModel Error: " diff --git a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelBuilderTester.java b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelBuilderTester.java index f3fa8e7a7..8dc6103f3 100644 --- a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelBuilderTester.java +++ b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelBuilderTester.java @@ -62,7 +62,7 @@ public class ReflectivityModelBuilderTester implements IMaterialsDatabase { // Make sure we have a form and some components assertNotNull(model.getForm()); - assertEquals(2, model.getForm().getComponents().size()); + assertEquals(3, model.getForm().getComponents().size()); // Get the table component list = (ListComponent) model.getForm().getComponent(ReflectivityModel.matListId); diff --git a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelTester.java b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelTester.java index 7794cf6ab..57e6638e0 100644 --- a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelTester.java +++ b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelTester.java @@ -54,7 +54,7 @@ public class ReflectivityModelTester implements IMaterialsDatabase { // Make sure we have a form and some components assertNotNull(model.getForm()); - assertEquals(2, model.getForm().getComponents().size()); + assertEquals(3, model.getForm().getComponents().size()); // Get the table component list = (ListComponent) model.getForm().getComponent(ReflectivityModel.matListId); @@ -67,6 +67,10 @@ public class ReflectivityModelTester implements IMaterialsDatabase { // setupFormWithServices() worked. assertNotNull(list.getElementSource()); assertEquals(list.getElementSource(),this); + + // Make sure the other components in the form are not null. + assertNotNull(model.getForm().getComponent(ReflectivityModel.paramsCompId)); + assertNotNull(model.getForm().getComponent(ReflectivityModel.resourceCompId)); return; } -- GitLab From 53380c2151a4f1c9fe75e0c4af1e09d75b8f63f8 Mon Sep 17 00:00:00 2001 From: Kasper Gammeltoft Date: Thu, 25 Jun 2015 09:40:57 -0400 Subject: [PATCH 4/4] Merged changes from master yesterday. Signed-off-by: Kasper Gammeltoft --- .../form/BasicEntryContentProvider.java | 19 +- .../form/IEntryContentProvider.java | 2 +- .../datastructures/form/MatrixComponent.java | 3 +- .../form/ResourceComponent.java | 10 + .../datastructures/form/TableComponent.java | 2 +- .../ice/item/jobLauncher/JobLauncher.java | 41 ++- .../ice/item/jobLauncher/SuiteLauncher.java | 5 +- .../src/org/eclipse/ice/item/model/Model.java | 12 + .../eclipse/ice/kdd/kddmath/KDDMatrix.java | 39 +-- .../materials/ui/AddMaterialWizardPage.java | 2 +- .../MaterialsDatabaseMasterDetailsBlock.java | 2 - .../ice/reflectivity/ReflectivityModel.java | 237 +++--------------- .../ice/viz/PlotEntryContentProvider.java | 2 +- .../META-INF/MANIFEST.MF | 39 ++- .../build.properties | 2 - .../test/ReflectivityModelBuilderTester.java | 2 +- .../test/ReflectivityModelTester.java | 6 +- 17 files changed, 148 insertions(+), 277 deletions(-) diff --git a/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/BasicEntryContentProvider.java b/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/BasicEntryContentProvider.java index ff4d71f18..eb63fbdfb 100644 --- a/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/BasicEntryContentProvider.java +++ b/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/BasicEntryContentProvider.java @@ -206,32 +206,33 @@ public class BasicEntryContentProvider extends ICEObject implements * @see IEntryContentProvider#equals(IEntryContentProvider otherProvider) */ @Override - public boolean equals(IEntryContentProvider otherProvider) { + public boolean equals(Object otherProvider) { // Local Declarations boolean retVal = false; // Check the provider, null and base type check first. - if (otherProvider != null) { + if (otherProvider != null && otherProvider instanceof IEntryContentProvider) { + IEntryContentProvider provider = (IEntryContentProvider) otherProvider; // See if they are the same reference on the heap if (this == otherProvider) { retVal = true; } else { // Check each member value - retVal = super.equals((ICEObject) otherProvider) - && (this.defaultValue.equals(otherProvider + retVal = super.equals((ICEObject) provider) + && (this.defaultValue.equals(provider .getDefaultValue())) - && (this.allowedValues.equals(otherProvider + && (this.allowedValues.equals(provider .getAllowedValues())) - && (this.parent.equals(otherProvider.getParent())) - && (this.allowedValueType.equals(otherProvider + && (this.parent.equals(provider.getParent())) + && (this.allowedValueType.equals(provider .getAllowedValueType())); // Check the tag if it is already set if (this.tag != null) { retVal = retVal - && (this.tag.equals(otherProvider.getTag())); + && (this.tag.equals(provider.getTag())); } else { - if (otherProvider.getTag() != null) { + if (provider.getTag() != null) { return false; } } diff --git a/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/IEntryContentProvider.java b/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/IEntryContentProvider.java index e33e2d561..41f134d4d 100644 --- a/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/IEntryContentProvider.java +++ b/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/IEntryContentProvider.java @@ -111,7 +111,7 @@ public interface IEntryContentProvider { *

* @return True if equivalent, false otherwise. */ - public boolean equals(IEntryContentProvider otherProvider); + public boolean equals(Object otherProvider); /** *

diff --git a/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/MatrixComponent.java b/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/MatrixComponent.java index 69cb2a3eb..c8091dc1a 100644 --- a/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/MatrixComponent.java +++ b/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/MatrixComponent.java @@ -370,7 +370,8 @@ public class MatrixComponent extends ICEObject implements Component { * True if the TableComponents are equal, false if not *

*/ - public boolean equals(MatrixComponent otherMatrixComponent) { + public boolean equals(Object otherMatrixComponent) { + boolean retVal = true; // Check if they are the same reference in memory if (this == otherMatrixComponent) { diff --git a/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/ResourceComponent.java b/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/ResourceComponent.java index 56c88642f..df4ff957b 100644 --- a/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/ResourceComponent.java +++ b/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/ResourceComponent.java @@ -103,6 +103,16 @@ public class ResourceComponent extends ListComponent { return outputComponent; } + /* + * (non-Javadoc) + * @see org.eclipse.ice.datastructures.ICEObject.ListComponent#hashCode() + */ + @Override + public int hashCode() { + return super.hashCode(); + + } + /** * This operation is used to check equality between the ResourceComponent * and another ResourceComponent. It returns true if the Components are diff --git a/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/TableComponent.java b/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/TableComponent.java index 2b2133396..92447f234 100644 --- a/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/TableComponent.java +++ b/src/org.eclipse.ice.datastructures/src/org/eclipse/ice/datastructures/form/TableComponent.java @@ -484,7 +484,7 @@ public class TableComponent extends ICEObject implements Component { * True if the TableComponents are equal, false if not *

*/ - public boolean equals(TableComponent otherTableComponent) { + public boolean equals(Object otherTableComponent) { boolean retVal = true; // Check if they are the same reference in memory if (this == otherTableComponent) { diff --git a/src/org.eclipse.ice.item/src/org/eclipse/ice/item/jobLauncher/JobLauncher.java b/src/org.eclipse.ice.item/src/org/eclipse/ice/item/jobLauncher/JobLauncher.java index ca6255467..b7a7e3165 100644 --- a/src/org.eclipse.ice.item/src/org/eclipse/ice/item/jobLauncher/JobLauncher.java +++ b/src/org.eclipse.ice.item/src/org/eclipse/ice/item/jobLauncher/JobLauncher.java @@ -1357,7 +1357,7 @@ public class JobLauncher extends Item { * True if the launchers are equal, false if not *

*/ - public boolean equals(JobLauncher otherLauncher) { + public boolean equals(Object otherLauncher) { boolean retVal; // Check if they are the same reference in memory @@ -1373,48 +1373,47 @@ public class JobLauncher extends Item { } // Check data - retVal = (this.allowedActions.equals(otherLauncher.allowedActions)) - && (this.form.equals(otherLauncher.form)) - && (this.itemType == otherLauncher.itemType) - && (this.status.equals(otherLauncher.status)) - && (this.mpiEnabled == otherLauncher.mpiEnabled) - && (this.openMPEnabled == otherLauncher.openMPEnabled) - && (this.tbbEnabled == otherLauncher.tbbEnabled) - && (this.hostsTable.equals(otherLauncher.hostsTable)) - && (this.hosts.equals(otherLauncher.hosts)); + JobLauncher launcher = (JobLauncher) otherLauncher; + retVal = (this.allowedActions.equals(launcher.allowedActions)) + && (this.form.equals(launcher.form)) + && (this.itemType == launcher.itemType) + && (this.status.equals(launcher.status)) + && (this.mpiEnabled == launcher.mpiEnabled) + && (this.openMPEnabled == launcher.openMPEnabled) + && (this.tbbEnabled == launcher.tbbEnabled) + && (this.hostsTable.equals(launcher.hostsTable)) + && (this.hosts.equals(launcher.hosts)); // Check the remote download directory if it has been configure if (remoteDownloadDir != null) { retVal &= (this.remoteDownloadDir - .equals(otherLauncher.remoteDownloadDir)); + .equals(launcher.remoteDownloadDir)); } // Check project - if (this.project != null && otherLauncher.project != null - && (!(this.project.equals(otherLauncher.project)))) { + if (this.project != null && launcher.project != null + && (!(this.project.equals(launcher.project)))) { return false; - } // Check project - set to null - - if (this.project == null && otherLauncher.project != null - || this.project != null && otherLauncher.project == null) { + if (this.project == null && launcher.project != null + || this.project != null && launcher.project == null) { return false; } // Check executable command name if (this.executableCommandName != null - && otherLauncher.executableCommandName != null + && launcher.executableCommandName != null && !(this.executableCommandName - .equals(otherLauncher.executableCommandName))) { + .equals(launcher.executableCommandName))) { return false; } // Check dictionary - if (this.actionDataMap != null && otherLauncher.actionDataMap != null - && (!(this.actionDataMap.equals(otherLauncher.actionDataMap)))) { + if (this.actionDataMap != null && launcher.actionDataMap != null + && (!(this.actionDataMap.equals(launcher.actionDataMap)))) { return false; } diff --git a/src/org.eclipse.ice.item/src/org/eclipse/ice/item/jobLauncher/SuiteLauncher.java b/src/org.eclipse.ice.item/src/org/eclipse/ice/item/jobLauncher/SuiteLauncher.java index 33be5128e..821bf5275 100644 --- a/src/org.eclipse.ice.item/src/org/eclipse/ice/item/jobLauncher/SuiteLauncher.java +++ b/src/org.eclipse.ice.item/src/org/eclipse/ice/item/jobLauncher/SuiteLauncher.java @@ -359,12 +359,13 @@ public class SuiteLauncher extends JobLauncher { * The launcher to compare against. * @return True if equal, false otherwise. */ - public boolean equals(SuiteLauncher otherLauncher) { + public boolean equals(Object otherLauncher) { // Aside from checking the executables, there's nothing to do but let // Joblauncher check its info and the Form. boolean retVal = super.equals(otherLauncher) - && executablesList.equals(otherLauncher.executablesList); + && executablesList + .equals(((SuiteLauncher) otherLauncher).executablesList); return retVal; } diff --git a/src/org.eclipse.ice.item/src/org/eclipse/ice/item/model/Model.java b/src/org.eclipse.ice.item/src/org/eclipse/ice/item/model/Model.java index 6bc0cc2fa..09ea2bca4 100644 --- a/src/org.eclipse.ice.item/src/org/eclipse/ice/item/model/Model.java +++ b/src/org.eclipse.ice.item/src/org/eclipse/ice/item/model/Model.java @@ -64,5 +64,17 @@ public class Model extends Item { protected IMaterialsDatabase getMaterialsDatabase() { return materialsDatabase; } + + /* + * (non-Javadoc) + * @see org.eclipse.ice.item.Item#copy(org.eclipse.ice.item.Item) + */ + @Override + public void copy(Item item){ + super.copy(item); + System.out.println("copys"); + setupFormWithServices(); + + } } \ No newline at end of file diff --git a/src/org.eclipse.ice.kdd/src/org/eclipse/ice/kdd/kddmath/KDDMatrix.java b/src/org.eclipse.ice.kdd/src/org/eclipse/ice/kdd/kddmath/KDDMatrix.java index e2e4bc9c3..40ffcf27d 100644 --- a/src/org.eclipse.ice.kdd/src/org/eclipse/ice/kdd/kddmath/KDDMatrix.java +++ b/src/org.eclipse.ice.kdd/src/org/eclipse/ice/kdd/kddmath/KDDMatrix.java @@ -620,27 +620,34 @@ public class KDDMatrix implements IAbstractMatrix { *

* * @param matrix - * @return + * @return true if the matrices are equal to each other, false otherwise. */ - public boolean equals(KDDMatrix matrix) { - // First make sure the incoming matrix is the right - // size - if (matrix.numberOfColumns() != nCols || matrix.numberOfRows() != nRows) { - return false; - } - // Then make sure all the elements are the same - for (int i = 0; i < nRows; i++) { - for (int j = 0; j < nCols; j++) { - if (!matrix.getElement(i, j).equals(getElement(i, j))) { - return false; + public boolean equals(Object matrix) { + + boolean retVal = true; + + if (matrix != null && matrix instanceof KDDMatrix && matrix != this) { + KDDMatrix otherMatrix = (KDDMatrix) matrix; + // First make sure the incoming matrix is the right + // size + if (otherMatrix.numberOfColumns() != nCols + || otherMatrix.numberOfRows() != nRows) { + retVal = false; + } + // Then make sure all the elements are the same + for (int i = 0; i < nRows; i++) { + for (int j = 0; j < nCols; j++) { + if (!otherMatrix.getElement(i, j).equals(getElement(i, j))) { + retVal = false; + } } } } // If we make it here, they are equal - return true; + return retVal; } - + /** *

* This operation returns the hashcode value of the KDDMatrix. @@ -652,7 +659,7 @@ public class KDDMatrix implements IAbstractMatrix { */ @Override public int hashCode() { - + // Local Declarations int hash = 8; @@ -661,7 +668,7 @@ public class KDDMatrix implements IAbstractMatrix { hash = 31 * hash + this.nRows; hash = 31 * hash + this.elements.hashCode(); hash = 31 * hash + this.dataProvider.hashCode(); - + // Done, return return hash; } diff --git a/src/org.eclipse.ice.materials.ui/src/org/eclipse/ice/materials/ui/AddMaterialWizardPage.java b/src/org.eclipse.ice.materials.ui/src/org/eclipse/ice/materials/ui/AddMaterialWizardPage.java index a516693e3..9b38155bb 100644 --- a/src/org.eclipse.ice.materials.ui/src/org/eclipse/ice/materials/ui/AddMaterialWizardPage.java +++ b/src/org.eclipse.ice.materials.ui/src/org/eclipse/ice/materials/ui/AddMaterialWizardPage.java @@ -23,6 +23,7 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionEvent; @@ -30,7 +31,6 @@ import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; diff --git a/src/org.eclipse.ice.materials.ui/src/org/eclipse/ice/materials/ui/MaterialsDatabaseMasterDetailsBlock.java b/src/org.eclipse.ice.materials.ui/src/org/eclipse/ice/materials/ui/MaterialsDatabaseMasterDetailsBlock.java index d6305cafd..fb3918614 100644 --- a/src/org.eclipse.ice.materials.ui/src/org/eclipse/ice/materials/ui/MaterialsDatabaseMasterDetailsBlock.java +++ b/src/org.eclipse.ice.materials.ui/src/org/eclipse/ice/materials/ui/MaterialsDatabaseMasterDetailsBlock.java @@ -16,8 +16,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; - -import org.eclipse.ice.datastructures.ICEObject.ListComponent; import org.eclipse.ice.datastructures.form.Material; import org.eclipse.ice.datastructures.form.MaterialStack; import org.eclipse.ice.materials.IMaterialsDatabase; diff --git a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java index 26d2e3ebe..39bc19234 100644 --- a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java +++ b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityModel.java @@ -8,14 +8,12 @@ * Contributors: * Initial API and implementation and/or initial documentation - Jay Jay Billings, * Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson, - * Claire Saunders, Matthew Wang, Anna Wojtowicz, Kasper Gammeltoft + * Claire Saunders, Matthew Wang, Anna Wojtowicz *******************************************************************************/ package org.eclipse.ice.reflectivity; -import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import javax.xml.bind.annotation.XmlRootElement; @@ -27,13 +25,10 @@ import org.eclipse.ice.datastructures.ICEObject.ListComponent; import org.eclipse.ice.datastructures.form.AllowedValueType; import org.eclipse.ice.datastructures.form.DataComponent; import org.eclipse.ice.datastructures.form.Entry; -import org.eclipse.ice.datastructures.form.Form; import org.eclipse.ice.datastructures.form.FormStatus; import org.eclipse.ice.datastructures.form.Material; import org.eclipse.ice.datastructures.form.ResourceComponent; -import org.eclipse.ice.datastructures.resource.ICEResource; import org.eclipse.ice.datastructures.resource.VizResource; -import org.eclipse.ice.io.csv.CSVReader; import org.eclipse.ice.item.model.Model; import org.eclipse.ice.materials.IMaterialsDatabase; import org.eclipse.ice.materials.MaterialWritableTableFormat; @@ -43,7 +38,7 @@ import org.eclipse.ice.materials.MaterialWritableTableFormat; * layered on top of each other. It... * - * @author Jay Jay Billings, Alex McCaskey, Kasper Gammeltoft + * @author Jay Jay Billings, Alex McCaskey */ @XmlRootElement(name = "ReflectivityModel") public class ReflectivityModel extends Model { @@ -53,31 +48,6 @@ public class ReflectivityModel extends Model { */ private final String processActionName = "Calculate Reflectivity"; - /** - * The name for the wave vector entry. - */ - private static final String WaveEntryName = "Wave Vector (Q) file"; - - /** - * The roughness entry name. - */ - private static final String RoughnessEntryName = "Roughness"; - - /** - * The delta q0 entry name. - */ - private static final String deltaQ0EntryName = "deltaQ0"; - - /** - * The delta q1 by q entry name. - */ - private static final String deltaQ1ByQEntryName = "deltaQ1ByQ"; - - /** - * The wave length entry name. - */ - private static final String WaveLengthEntryName = "Wave Length"; - /** * Identification number for the component that contains the parameters. */ @@ -89,12 +59,6 @@ public class ReflectivityModel extends Model { */ public static final int matListId = 2; - /** - * Identification number for the resource component that contains the output - * files. - */ - public static final int resourceCompId = 3; - /** * The constructor. */ @@ -122,15 +86,19 @@ public class ReflectivityModel extends Model { @Override public FormStatus process(String actionName) { - // Local Declarations. Return this value to display the process status - // on the form. - FormStatus retVal = null; + // Local Declarations + FormStatus retVal; if (actionName.equals(processActionName)) { - // Get the material list from the form. + // Convert the material table to slabs + + // Get the roughness parameter, dQ, dQ/Q and the wavelength + + // Get and load the wave vector and related information + ListComponent matList = (ListComponent) form - .getComponent(matListId); + .getComponent(2); ArrayList slabs = new ArrayList(); // Create the slabs from the materials @@ -147,115 +115,18 @@ public class ReflectivityModel extends Model { slabs.add(slab); } - // Get the roughness from the form. - int numRough = Integer.parseInt(((DataComponent) form - .getComponent(paramsCompId)).retrieveEntry( - RoughnessEntryName).getValue()); - - // Get the deltaQ0 from the form. - double deltaQ0 = Double.parseDouble(((DataComponent) form - .getComponent(paramsCompId)) - .retrieveEntry(deltaQ0EntryName).getValue()); - - // Get the deltaQ0 from the form. - double deltaQ1ByQ = Double.parseDouble(((DataComponent) form - .getComponent(paramsCompId)).retrieveEntry( - deltaQ1ByQEntryName).getValue()); - - // Get the wave length from the form. - double wavelength = Double.parseDouble(((DataComponent) form - .getComponent(paramsCompId)).retrieveEntry( - WaveLengthEntryName).getValue()); - - // Get the wave vector from the file picker in the paramters - // component. - double[] waveVector; - String fileName = ((DataComponent) form.getComponent(paramsCompId)) - .retrieveEntry(WaveEntryName).getValue(); - - // Get the file that should have been pulled into the local project. - IFile waveInput = project.getFile(fileName); - - // Get the reader and read in the values. - Form waveForm = new CSVReader().read(waveInput); - ListComponent waveData = (ListComponent) waveForm - .getComponent(1); - - // Pull the data from the form into an array. - waveVector = new double[waveData.size()]; - for (int i = 0; i < waveData.size(); i++) { - String[] dataLine = waveData.get(i); - double dataEntry = Double.parseDouble(dataLine[0]); - waveVector[i] = dataEntry; - } - - // Calculate the reflectivity - FIXME! Add RQ4 parameter + // Calculate the reflectivity ReflectivityCalculator calculator = new ReflectivityCalculator(); - ReflectivityProfile profile = calculator.getReflectivityProfile( - slabs.toArray(new Slab[slabs.size()]), numRough, deltaQ0, - deltaQ1ByQ, wavelength, waveVector, false); - - // Get the data from the profile - double[] reflectivity = profile.reflectivity; - double[] scatDensity = profile.scatteringDensity; - double[] depth = profile.depth; - - // Create the csv data for the reflectivity file - String reflectData = "#features, p_x, p_y\n#units,p_x,p_y\n"; - for (int i = 0; i < reflectivity.length; i++) { - reflectData += Double.toString(reflectivity[i]) + "," - + Double.toString(waveVector[i]) + "\n"; - } - - // Create the stream - ByteArrayInputStream reflectStream = new ByteArrayInputStream( - reflectData.getBytes()); - - // Create the data for the scattering density profile - String scatData = "#features, p_x, p_y\n#units,p_x,p_y\n"; - for (int i = 0; i < depth.length; i++) { - scatData += Double.toString(scatDensity[i]) + "," - + Double.toString(depth[i]) + "\n"; - } + // calculator.getReflectivityProfile(slabs, numRough, deltaQ0, + // deltaQ1ByQ, wavelength, waveVector, getRQ4); - ResourceComponent resComp = (ResourceComponent) form - .getComponent(resourceCompId); + // Write the files - // Create the stream - ByteArrayInputStream scatStream = new ByteArrayInputStream( - scatData.getBytes()); - - // Write the data to the files. - try { - // First the reflectivity file - VizResource reflectSource = (VizResource)resComp.get(0); - IFile reflectivityFile = project.getFile(reflectSource.getContents().getName()); - reflectivityFile.setContents(new BufferedInputStream( - reflectStream), true, false, null); - - // Then the scattering density file - VizResource scatSource = (VizResource)resComp.get(1); - IFile scatteringFile = project.getFile(scatSource.getContents().getName()); - scatteringFile.setContents(new BufferedInputStream(scatStream), - true, false, null); - - // Catch exceptions, should return an error. - } catch (CoreException | NullPointerException e) { - e.printStackTrace(); - retVal = FormStatus.InfoError; - } - - // Return processed if the value has not already beens set. - if (retVal == null) { - retVal = FormStatus.Processed; - } - - // Some other process action. + retVal = FormStatus.InfoError; } else { retVal = super.process(actionName); } - // Finally return retVal. return retVal; } @@ -268,11 +139,11 @@ public class ReflectivityModel extends Model { protected void setupForm() { // FIXME! Simple data entered now for testing - String line1 = "#features, p_x, p_y\n"; - String line2 = "#units,p_x,p_y\n"; - String line3 = "1.0,1.0\n"; - String line4 = "2.0,4.0\n"; - String line5 = "3.0,9.0\n"; + String line1 = "#features,t, p_x, p_y\n"; + String line2 = "#units,t,p_x,p_y\n"; + String line3 = "1.0,1.0,1.0\n"; + String line4 = "2.0,4.0,8.0\n"; + String line5 = "3.0,9.0,27.0\n"; String allLines = line1 + line2 + line3 + line4 + line5; // Create an empty stream for the output files @@ -301,7 +172,7 @@ public class ReflectivityModel extends Model { } }; fileEntry.setId(1); - fileEntry.setName(WaveEntryName); + fileEntry.setName("Wave Vector (Q) file"); fileEntry.setDescription("Wave vector information for this problem."); paramComponent.addEntry(fileEntry); @@ -318,58 +189,11 @@ public class ReflectivityModel extends Model { } }; numLayersEntry.setId(2); - numLayersEntry.setName(RoughnessEntryName); + numLayersEntry.setName("Roughness"); numLayersEntry.setDescription("Number of layers of " + "roughness per material layer."); paramComponent.addEntry(numLayersEntry); - // Add an entry for the deltaQ0 - Entry deltaQ0Entry = new Entry() { - @Override - protected void setup() { - allowedValueType = AllowedValueType.Continuous; - allowedValues.add(".00001"); - allowedValues.add("5.0"); - return; - } - }; - deltaQ0Entry.setId(3); - deltaQ0Entry.setName(deltaQ0EntryName); - deltaQ0Entry - .setDescription("The incident angle of the neutron stream."); - paramComponent.addEntry(deltaQ0Entry); - - // Add an entry for the deltaQ1ByQ - Entry deltaQ1Entry = new Entry() { - @Override - protected void setup() { - allowedValueType = AllowedValueType.Continuous; - allowedValues.add(".00001"); - allowedValues.add("5.0"); - return; - } - }; - deltaQ1Entry.setId(4); - deltaQ1Entry.setName(deltaQ1ByQEntryName); - deltaQ1Entry - .setDescription("The angle of refraction on the neutron stream."); - paramComponent.addEntry(deltaQ1Entry); - - // Add an entry for the wavelength - Entry waveEntry = new Entry() { - @Override - protected void setup() { - allowedValueType = AllowedValueType.Continuous; - allowedValues.add(".000001"); - allowedValues.add("1000"); - return; - } - }; - waveEntry.setId(5); - waveEntry.setName(WaveLengthEntryName); - waveEntry.setDescription("The wavelength of the neutron stream."); - paramComponent.addEntry(waveEntry); - // Configure a list of property names for the materials ArrayList names = new ArrayList(); names.add("Material ID"); @@ -396,13 +220,6 @@ public class ReflectivityModel extends Model { // Make sure to put it in the form! form.addComponent(matList); - // Create a component to hold the output - ResourceComponent resources = new ResourceComponent(); - resources.setName("Results"); - resources.setDescription("Results and Output"); - resources.setId(resourceCompId); - form.addComponent(resources); - if (project != null) { // FIXME! ID is always 1 at this point! String basename = "reflectivityModel_" + getId() + "_"; @@ -438,9 +255,15 @@ public class ReflectivityModel extends Model { scatDensitySource.setId(2); scatDensitySource.setDescription("Data from Stattering " + "Density calculation"); - + + // Create a component to hold the output + ResourceComponent resources = new ResourceComponent(); + resources.setName("Results"); + resources.setDescription("Results and Output"); + resources.setId(2); resources.addResource(reflectivitySource); resources.addResource(scatDensitySource); + form.addComponent(resources); } catch (CoreException | IOException e) { // Complain System.err.println("ReflectivityModel Error: " diff --git a/src/org.eclipse.ice.viz/src/org/eclipse/ice/viz/PlotEntryContentProvider.java b/src/org.eclipse.ice.viz/src/org/eclipse/ice/viz/PlotEntryContentProvider.java index be4cef4b7..e993bbb87 100644 --- a/src/org.eclipse.ice.viz/src/org/eclipse/ice/viz/PlotEntryContentProvider.java +++ b/src/org.eclipse.ice.viz/src/org/eclipse/ice/viz/PlotEntryContentProvider.java @@ -106,7 +106,7 @@ public class PlotEntryContentProvider implements IEntryContentProvider { * The IEntryContentProvider to check if this is equal to. */ @Override - public boolean equals(IEntryContentProvider otherProvider) { + public boolean equals(Object otherProvider) { boolean equal = false; if (otherProvider != null diff --git a/tests/org.eclipse.ice.client.widgets.test/META-INF/MANIFEST.MF b/tests/org.eclipse.ice.client.widgets.test/META-INF/MANIFEST.MF index 30d1e5ce8..1fa6452b4 100644 --- a/tests/org.eclipse.ice.client.widgets.test/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.ice.client.widgets.test/META-INF/MANIFEST.MF @@ -3,13 +3,38 @@ Bundle-ManifestVersion: 2 Bundle-Name: ICEEclipseWidgetsTest Bundle-SymbolicName: org.eclipse.ice.client.widgets.test Bundle-Version: 2.0.0 -Fragment-Host: org.eclipse.ice.client.widgets;bundle-version="2.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.7 -Import-Package: org.eclipse.ice.client.widgets.test.utils, +Import-Package: ca.odell.glazedlists, + ca.odell.glazedlists.gui, + org.apache.log4j;version="1.2.15", + org.eclipse.ice.client.common, + org.eclipse.ice.client.widgets, + org.eclipse.ice.client.widgets.geometry, + org.eclipse.ice.client.widgets.test.utils, + org.eclipse.ice.datastructures.ICEObject, + org.eclipse.ice.datastructures.form, + org.eclipse.ice.datastructures.form.emf, + org.eclipse.ice.datastructures.form.geometry, + org.eclipse.ice.datastructures.resource, + org.eclipse.ice.iclient.uiwidgets, + org.eclipse.ice.materials, + org.eclipse.ice.materials.ui, org.eclipse.ice.viz.service, - org.eclipse.ui, - org.junit -Require-Bundle: org.eclipse.swtbot.eclipse.core;bundle-version="2.2.1", - org.eclipse.swtbot.go;bundle-version="2.2.1", + org.eclipse.jface, + org.eclipse.jface.action, + org.eclipse.swt, + org.eclipse.swt.events, + org.eclipse.swt.graphics, + org.eclipse.swt.layout, + org.eclipse.swt.widgets, + org.eclipse.swtbot.eclipse.finder, + org.eclipse.swtbot.eclipse.finder.widgets, org.eclipse.swtbot.swt.finder, - org.eclipse.ice.materials + org.eclipse.swtbot.swt.finder.widgets, + org.eclipse.ui, + org.eclipse.ui.forms, + org.eclipse.ui.forms.editor, + org.eclipse.ui.forms.widgets +Require-Bundle: org.junit;bundle-version="4.11.0", + org.hamcrest.library;bundle-version="1.3.0", + org.eclipse.ice.client.compatibility;bundle-version="2.0.0" diff --git a/tests/org.eclipse.ice.client.widgets.test/build.properties b/tests/org.eclipse.ice.client.widgets.test/build.properties index c0e10d4d6..34d2e4d2d 100644 --- a/tests/org.eclipse.ice.client.widgets.test/build.properties +++ b/tests/org.eclipse.ice.client.widgets.test/build.properties @@ -2,5 +2,3 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ . -additional.bundles = org.junit,\ - org.hamcrest.core diff --git a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelBuilderTester.java b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelBuilderTester.java index 8dc6103f3..f3fa8e7a7 100644 --- a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelBuilderTester.java +++ b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelBuilderTester.java @@ -62,7 +62,7 @@ public class ReflectivityModelBuilderTester implements IMaterialsDatabase { // Make sure we have a form and some components assertNotNull(model.getForm()); - assertEquals(3, model.getForm().getComponents().size()); + assertEquals(2, model.getForm().getComponents().size()); // Get the table component list = (ListComponent) model.getForm().getComponent(ReflectivityModel.matListId); diff --git a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelTester.java b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelTester.java index 57e6638e0..7794cf6ab 100644 --- a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelTester.java +++ b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityModelTester.java @@ -54,7 +54,7 @@ public class ReflectivityModelTester implements IMaterialsDatabase { // Make sure we have a form and some components assertNotNull(model.getForm()); - assertEquals(3, model.getForm().getComponents().size()); + assertEquals(2, model.getForm().getComponents().size()); // Get the table component list = (ListComponent) model.getForm().getComponent(ReflectivityModel.matListId); @@ -67,10 +67,6 @@ public class ReflectivityModelTester implements IMaterialsDatabase { // setupFormWithServices() worked. assertNotNull(list.getElementSource()); assertEquals(list.getElementSource(),this); - - // Make sure the other components in the form are not null. - assertNotNull(model.getForm().getComponent(ReflectivityModel.paramsCompId)); - assertNotNull(model.getForm().getComponent(ReflectivityModel.resourceCompId)); return; } -- GitLab