use of org.concord.energy3d.model.Sensor in project energy3d by concord-consortium.
the class Scene method removeAllSensors.
public void removeAllSensors() {
final ArrayList<HousePart> sensors = new ArrayList<HousePart>();
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart != null) {
final Foundation foundation = selectedPart instanceof Foundation ? (Foundation) selectedPart : selectedPart.getTopContainer();
for (final HousePart part : parts) {
if (part instanceof Sensor && part.getTopContainer() == foundation) {
sensors.add(part);
}
}
} else {
for (final HousePart part : parts) {
if (part instanceof Sensor) {
sensors.add(part);
}
}
}
if (sensors.isEmpty()) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "There is no sensor to remove.", "No Sensor", JOptionPane.INFORMATION_MESSAGE);
return;
}
if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), "Do you really want to remove all " + sensors.size() + " sensors" + (selectedPart != null ? " on the selected foundation" : "") + "?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) != JOptionPane.YES_OPTION) {
return;
}
final RemoveMultiplePartsCommand c = new RemoveMultiplePartsCommand(sensors);
for (final HousePart part : sensors) {
remove(part, false);
}
redrawAll();
SceneManager.getInstance().getUndoManager().addEdit(c);
edited = true;
}
use of org.concord.energy3d.model.Sensor in project energy3d by concord-consortium.
the class SceneManager method newPart.
private HousePart newPart() {
final HousePart drawn;
setGridsVisible(false);
if (operation == Operation.DRAW_WALL) {
drawn = new Wall();
drawn.setColor(Scene.getInstance().getWallColor());
} else if (operation == Operation.DRAW_DOOR) {
drawn = new Door();
drawn.setColor(Scene.getInstance().getDoorColor());
} else if (operation == Operation.DRAW_WINDOW) {
drawn = new Window();
} else if (operation == Operation.DRAW_ROOF_PYRAMID) {
drawn = new PyramidRoof();
drawn.setColor(Scene.getInstance().getRoofColor());
} else if (operation == Operation.DRAW_ROOF_HIP) {
drawn = new HipRoof();
drawn.setColor(Scene.getInstance().getRoofColor());
} else if (operation == Operation.DRAW_ROOF_SHED) {
drawn = new ShedRoof();
drawn.setColor(Scene.getInstance().getRoofColor());
} else if (operation == Operation.DRAW_ROOF_GAMBREL) {
drawn = new GambrelRoof();
drawn.setColor(Scene.getInstance().getRoofColor());
} else if (operation == Operation.DRAW_ROOF_CUSTOM) {
drawn = new CustomRoof();
drawn.setColor(Scene.getInstance().getRoofColor());
} else if (operation == Operation.DRAW_FLOOR) {
drawn = new Floor();
drawn.setColor(Scene.getInstance().getFloorColor());
} else if (operation == Operation.DRAW_SOLAR_PANEL) {
drawn = new SolarPanel();
} else if (operation == Operation.DRAW_RACK) {
drawn = new Rack();
} else if (operation == Operation.DRAW_MIRROR) {
drawn = new Mirror();
} else if (operation == Operation.DRAW_PARABOLIC_TROUGH) {
drawn = new ParabolicTrough();
} else if (operation == Operation.DRAW_PARABOLIC_DISH) {
drawn = new ParabolicDish();
} else if (operation == Operation.DRAW_FRESNEL_REFLECTOR) {
drawn = new FresnelReflector();
} else if (operation == Operation.DRAW_SENSOR) {
drawn = new Sensor();
} else if (operation == Operation.DRAW_FOUNDATION) {
drawn = new Foundation();
setGridsVisible(Scene.getInstance().isSnapToGrids());
drawn.setColor(Scene.getInstance().getFoundationColor());
} else if (operation == Operation.DRAW_DOGWOOD) {
drawn = new Tree(Tree.DOGWOOD);
setGridsVisible(true);
} else if (operation == Operation.DRAW_ELM) {
drawn = new Tree(Tree.ELM);
setGridsVisible(true);
} else if (operation == Operation.DRAW_OAK) {
drawn = new Tree(Tree.OAK);
setGridsVisible(true);
} else if (operation == Operation.DRAW_LINDEN) {
drawn = new Tree(Tree.LINDEN);
setGridsVisible(true);
} else if (operation == Operation.DRAW_COTTONWOOD) {
drawn = new Tree(Tree.COTTONWOOD);
setGridsVisible(true);
} else if (operation == Operation.DRAW_MAPLE) {
drawn = new Tree(Tree.MAPLE);
setGridsVisible(true);
} else if (operation == Operation.DRAW_PINE) {
drawn = new Tree(Tree.PINE);
setGridsVisible(true);
} else if (operation == Operation.DRAW_JANE) {
drawn = new Human(Human.JANE);
setGridsVisible(true);
} else if (operation == Operation.DRAW_JENI) {
drawn = new Human(Human.JENI);
setGridsVisible(true);
} else if (operation == Operation.DRAW_JILL) {
drawn = new Human(Human.JILL);
setGridsVisible(true);
} else if (operation == Operation.DRAW_JACK) {
drawn = new Human(Human.JACK);
setGridsVisible(true);
} else if (operation == Operation.DRAW_JOHN) {
drawn = new Human(Human.JOHN);
setGridsVisible(true);
} else if (operation == Operation.DRAW_JOSE) {
drawn = new Human(Human.JOSE);
setGridsVisible(true);
} else {
return null;
}
Scene.getInstance().add(drawn, false);
addPartCommand = new AddPartCommand(drawn);
return drawn;
}
use of org.concord.energy3d.model.Sensor in project energy3d by concord-consortium.
the class DailySensorData method toJson.
@Override
public String toJson() {
String s = "{\"Hours\": " + getNumberOfDataPoints() + ", \"Data\": [";
final List<HousePart> parts = Scene.getInstance().getParts();
for (final HousePart p : parts) {
if (p instanceof Sensor) {
final Sensor sensor = (Sensor) p;
final long id = sensor.getId();
List<Double> lightData = graph.getData("Light: #" + id);
s += "{\"ID\": " + id;
s += ", \"Light\": [";
for (Double x : lightData) {
s += Graph.FIVE_DECIMALS.format(x) + ",";
}
s = s.substring(0, s.length() - 1);
s += "]\n";
List<Double> heatData = graph.getData("Heat Flux: #" + id);
s += ", \"HeatFlux\": [";
for (Double x : heatData) {
s += Graph.FIVE_DECIMALS.format(x) + ",";
}
s = s.substring(0, s.length() - 1);
s += "]";
s += "},";
}
}
s = s.substring(0, s.length() - 1);
s += "]}";
return s;
}
use of org.concord.energy3d.model.Sensor in project energy3d by concord-consortium.
the class DailySensorData method updateGraph.
@Override
public void updateGraph() {
final int n = (int) Math.round(60.0 / Scene.getInstance().getTimeStep());
final List<HousePart> parts = Scene.getInstance().getParts();
for (final HousePart p : parts) {
if (p instanceof Sensor) {
final Sensor sensor = (Sensor) p;
String lid = "Light: #" + sensor.getId();
String hid = "Heat Flux: #" + sensor.getId();
graph.hideData(lid, sensor.isLightOff());
graph.hideData(hid, sensor.isHeatFluxOff());
final double area = sensor.getArea();
for (int i = 0; i < 24; i++) {
SolarRadiation.getInstance().computeEnergyAtHour(i);
final double solar = sensor.getSolarPotentialNow();
graph.addData(lid, solar / area);
final double[] loss = sensor.getHeatLoss();
int t0 = n * i;
double sum = 0;
for (int k = t0; k < t0 + n; k++) sum += loss[k];
graph.addData(hid, -sum / area);
}
}
}
graph.repaint();
}
use of org.concord.energy3d.model.Sensor in project energy3d by concord-consortium.
the class DataViewer method viewRawData.
static void viewRawData(final java.awt.Window parent, final Graph graph, final boolean selectAll) {
String[] header = null;
if (graph instanceof BuildingEnergyDailyGraph) {
header = new String[] { "Hour", "Windows", "Solar Panels", "Heater", "AC", "Net" };
} else if (graph instanceof BuildingEnergyAnnualGraph) {
header = new String[] { "Month", "Windows", "Solar Panels", "Heater", "AC", "Net" };
} else if (graph instanceof PartEnergyDailyGraph) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectAll || selectedPart instanceof SolarPanel || selectedPart instanceof Rack || selectedPart instanceof Mirror || selectedPart instanceof Foundation) {
header = new String[] { "Hour", "Solar" };
} else if (selectedPart instanceof Wall || selectedPart instanceof Roof || selectedPart instanceof Door) {
header = new String[] { "Hour", "Heat Gain" };
} else if (selectedPart instanceof Window) {
header = new String[] { "Hour", "Solar", "Heat Gain" };
}
if (graph.instrumentType == Graph.SENSOR) {
final List<HousePart> parts = Scene.getInstance().getParts();
final List<String> sensorList = new ArrayList<String>();
for (final HousePart p : parts) {
if (p instanceof Sensor) {
final Sensor sensor = (Sensor) p;
sensorList.add("Light: #" + sensor.getId());
sensorList.add("Heat Flux: #" + sensor.getId());
}
}
if (!sensorList.isEmpty()) {
header = new String[1 + sensorList.size()];
header[0] = "Hour";
for (int i = 1; i < header.length; i++) {
header[i] = sensorList.get(i - 1);
}
}
}
} else if (graph instanceof PartEnergyAnnualGraph) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectAll || selectedPart instanceof SolarPanel || selectedPart instanceof Rack || selectedPart instanceof Mirror || selectedPart instanceof Foundation) {
header = new String[] { "Month", "Solar" };
} else if (selectedPart instanceof Wall || selectedPart instanceof Roof || selectedPart instanceof Door) {
header = new String[] { "Month", "Heat Gain" };
} else if (selectedPart instanceof Window) {
header = new String[] { "Month", "Solar", "Heat Gain" };
}
if (graph.instrumentType == Graph.SENSOR) {
final List<HousePart> parts = Scene.getInstance().getParts();
final List<String> sensorList = new ArrayList<String>();
for (final HousePart p : parts) {
if (p instanceof Sensor) {
final Sensor sensor = (Sensor) p;
sensorList.add("Light: #" + sensor.getId());
sensorList.add("Heat Flux: #" + sensor.getId());
}
}
if (!sensorList.isEmpty()) {
header = new String[1 + sensorList.size()];
header[0] = "Month";
for (int i = 1; i < header.length; i++) {
header[i] = sensorList.get(i - 1);
}
}
}
} else if (graph instanceof BuildingEnergyAngularGraph) {
header = new String[] { "Degree", "Windows", "Solar Panels", "Heater", "AC", "Net" };
} else if (graph instanceof PartEnergyAngularGraph) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof SolarPanel || selectedPart instanceof Rack || selectedPart instanceof Mirror || selectedPart instanceof Foundation) {
header = new String[] { "Degree", "Solar" };
} else if (selectedPart instanceof Wall || selectedPart instanceof Roof || selectedPart instanceof Door) {
header = new String[] { "Degree", "Heat Gain" };
} else if (selectedPart instanceof Window) {
header = new String[] { "Degree", "Solar", "Heat Gain" };
}
}
if (header == null) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Problem in finding data.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
final int m = header.length;
final int n = graph.getLength();
final Object[][] column = new Object[n][m + 1];
for (int i = 0; i < n; i++) {
column[i][0] = header[0].equals("Hour") ? i : (i + 1);
}
for (int j = 1; j < m; j++) {
final List<Double> list = graph.getData(header[j]);
for (int i = 0; i < n; i++) {
column[i][j] = list.get(i);
}
}
showDataWindow("Data", column, header, parent);
}
Aggregations