[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view View.java, 1.295, 1.296 Display.java,
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2010-11-26 14:20:36
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv26258/src/net/sourceforge/bprocessor/gl/view Modified Files: View.java Display.java Log Message: Index: Display.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/Display.java,v retrieving revision 1.106 retrieving revision 1.107 diff -C2 -d -r1.106 -r1.107 *** Display.java 22 Apr 2010 08:13:39 -0000 1.106 --- Display.java 26 Nov 2010 14:20:27 -0000 1.107 *************** *** 45,48 **** --- 45,50 ---- import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; + import net.sourceforge.bprocessor.model.sense.brunata.TargetManager; + import net.sourceforge.bprocessor.model.sense.core.Target; /** *************** *** 90,96 **** --- 92,108 ---- private static float[] middleblue = new float[] {0.11f, 0.72f, 0.67f, 0.0f}; private static float[] red = new float[]{0.8f, 0.1f, 0.1f}; + private static float[] yellow = new float[]{0.8f, 0.8f, 0.1f}; private static float[] green = new float[]{0.1f, 0.8f, 0.1f}; private static float[] blue = new float[]{0.1f, 0.1f, 0.8f}; private static float[] misty = new float[] {255f / 280, 228f / 280, 225f / 280}; + + + + private static final int ALARM_NONE = 0; + private static final int ALARM_TEMPERATURE = 1; + private static final int ALARM_HUMIDITY = 2; + private static final int ALARM_SKIMMEL = 3; + + private static byte[] highlight = new byte[128]; *************** *** 448,451 **** --- 460,471 ---- } } + private static void paintEdges(Collection<Edge> edges, float[] color, float size, double alpha) { + apply(color, (float) alpha); + gl.glLineWidth(size); + for (Edge current : edges) { + draw(current); + } + } + private static void paintStippled(Collection<Edge> edges, float[] color, float size) { if (!edges.isEmpty()) { *************** *** 919,922 **** --- 939,990 ---- } + private static int alarmOf(Instance instance) { + if (instance.getParameters() != null) { + Object id = instance.getParameters().get("moteid"); + if (id instanceof String) { + Target target = TargetManager.instance().getTarget((String) id); + if (target.humidityAlarm) { + return ALARM_HUMIDITY; + } else if (target.temperatureAlarm) { + return ALARM_TEMPERATURE; + } else if (target.skimmelAlarm) { + return ALARM_SKIMMEL; + } + } + } + return ALARM_NONE; + } + + private static void checkAlarm(Item space) { + int alarm = ALARM_NONE; + + Space s = (Space) space; + for (Item current : s.getElements()) { + if (current instanceof Instance) { + int itsAlarm = alarmOf((Instance) current); + if (itsAlarm != ALARM_NONE) { + alarm = itsAlarm; + } + } else { + checkAlarm(current); + } + } + + if (alarm != ALARM_NONE) { + Collection<Edge> edges = space.hiliteEdges(); + float[] color = null; + if (alarm == ALARM_HUMIDITY) { + color = blue; + } else if (alarm == ALARM_TEMPERATURE) { + color = red; + } else { + color = yellow; + } + disable(GL.GL_DEPTH_TEST); + paintEdges(edges, color, 6.0f, 0.4); + enable(GL.GL_DEPTH_TEST); + } + } + private static void draw(Item space, boolean inside) { if (space.isInstance()) { *************** *** 961,964 **** --- 1029,1051 ---- private static void drawInstance(Instance space, boolean inside) { + + // + // int alarm = alarmOf(space); + // + // if (alarm != ALARM_NONE) { + // Collection<Edge> edges = space.hiliteEdges(); + // float[] color = null; + // if (alarm == ALARM_HUMIDITY) { + // color = blue; + // } else if (alarm == ALARM_TEMPERATURE) { + // color = red; + // } else { + // color = yellow; + // } + // paintEdges(edges, color, 4.0f, 0.5); + // } + // + + if (Project.useDisplayLists()) { if (selecting()) { *************** *** 1433,1445 **** if (!selecting()) { disableClipplanes(); - geometrics.addAll(Selection.primary()); if (target != null) { geometrics.add(target); } enableClipplanes(); } draw(world, world == active); if (!selecting()) { --- 1520,1533 ---- if (!selecting()) { disableClipplanes(); geometrics.addAll(Selection.primary()); if (target != null) { geometrics.add(target); } + //hiliteSpaces(geometrics); enableClipplanes(); } draw(world, world == active); + checkAlarm(world); if (!selecting()) { Index: View.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View.java,v retrieving revision 1.295 retrieving revision 1.296 diff -C2 -d -r1.295 -r1.296 *** View.java 20 May 2010 10:58:51 -0000 1.295 --- View.java 26 Nov 2010 14:20:27 -0000 1.296 *************** *** 8,11 **** --- 8,12 ---- import net.sourceforge.bprocessor.gl.Editor; + import net.sourceforge.bprocessor.gl.tool.FourTool; import net.sourceforge.bprocessor.gl.tool.SelectTool; import net.sourceforge.bprocessor.gl.tool.SpaceSelectTool; *************** *** 33,37 **** --- 34,48 ---- import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.Surface; + import net.sourceforge.bprocessor.model.sense.brunata.TargetManager; + import net.sourceforge.bprocessor.model.sense.core.Measurement; + import net.sourceforge.bprocessor.model.sense.core.MoldEntry; + import net.sourceforge.bprocessor.model.sense.core.Target; + import net.sourceforge.bprocessor.model.sense.monitor.MonitorManager; + import net.sourceforge.bprocessor.model.sense.monitor.TargetMonitor; + import java.text.DateFormat; + import java.text.DecimalFormat; + import java.text.NumberFormat; + import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; *************** *** 757,766 **** } } else if (candidate instanceof Item) { ! if (editor.getTool() instanceof SpaceSelectTool) { drawSpeechBubble((Item) candidate, hitdetection); } } } //drawObscureBox(); --- 768,782 ---- } } else if (candidate instanceof Item) { ! if (editor.getTool() instanceof SpaceSelectTool || editor.getTool() instanceof FourTool) { drawSpeechBubble((Item) candidate, hitdetection); } + } } + if (editor.getTool() instanceof FourTool) { + drawMoldTable(); + } + //drawObscureBox(); *************** *** 1046,1049 **** --- 1062,1070 ---- gl.glPopMatrix(); } + + private int measureString(String string) { + return glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, string); + } + /** *************** *** 1205,1212 **** } private void drawSpeechBubble(Item space, boolean clickable) { Transformation transformation = transformation(); ! double width = 240; ! double height = 180; double delta = 10; --- 1226,1296 ---- } + private void drawMoldTable() { + double gw = 100; + double gh = 100; + double gx = View.width - gw - 10; + double gy = View.height - gh - 10; + double c0 = 75; + double c1 = 100; + double cscale = gh / (c1 - c0); + + gl.glColor3d(0.3, 0.3, 0.3); + gl.glLineWidth(1f); + gl.glBegin(GL.GL_LINES); + gl.glVertex2d(gx, gy); + gl.glVertex2d(gx + gw, gy); + gl.glVertex2d(gx, gy); + gl.glVertex2d(gx, gy + gh); + gl.glEnd(); + + { + + double range = c1 - c0; + double step = range / 5; + double m0 = c0; + + + + for (int i = 0; i < 5; i++) { + String m0s = String.valueOf(m0); + double mx = (m0 - c0) * cscale; + double xx = measureString(m0s); + drawString(gx - xx - 4, gy + mx, 0, m0s); + gl.glBegin(GL.GL_LINES); + gl.glVertex2d(gx - 2, gy + mx); + gl.glVertex2d(gx + 2, gy + mx); + gl.glEnd(); + m0 = m0 + step; + } + } + + { + drawString(gx + gw - 20, gy - 14, 0, "50"); + } + + { + gl.glColor3d(0.9, 0.1, 0.1); + gl.glLineWidth(2.5f); + gl.glBegin(GL.GL_LINE_STRIP); + + double dx = 0; + + for (MoldEntry current : Project.moldtable.entries) { + double value = current.humidity; + double dy = (value - c0) * cscale; + gl.glVertex2d(gx + dx, gy + dy); + dx = dx + 4; + } + + gl.glEnd(); + } + } + private void drawSpeechBubble(Item space, boolean clickable) { Transformation transformation = transformation(); ! double width = 400; ! double height = 200; ! double margin = 20; ! double offset = 20; double delta = 10; *************** *** 1218,1225 **** Vertex d = c.add(new Vertex(width, 0, 0)); Vertex e = a.add(new Vertex(width, 0, 0)); - front.setZ(1); gl.glColor4d(0.94f, 0.97f, 1, 0.9); - gl.glBegin(GL.GL_POLYGON); gl.glVertex3d(a.getX(), a.getY(), a.getZ()); --- 1302,1307 ---- *************** *** 1227,1231 **** gl.glVertex3d(b.getX(), b.getY(), b.getZ()); gl.glEnd(); - gl.glBegin(GL.GL_POLYGON); gl.glVertex3d(a.getX(), a.getY(), a.getZ()); --- 1309,1312 ---- *************** *** 1234,1238 **** gl.glVertex3d(e.getX(), e.getY(), e.getZ()); gl.glEnd(); - gl.glColor3d(0.1, 0.1, 0.1); gl.glLineWidth(0.5f); --- 1315,1318 ---- *************** *** 1251,1255 **** --- 1331,1568 ---- gl.glVertex3d(a.getX(), a.getY(), a.getZ()); gl.glEnd(); + + if (space instanceof Instance) { + Instance instance = (Instance) space; + if (instance.getParameters() != null) { + String id = (String) instance.getParameters().get("moteid"); + Target target = TargetManager.instance().getTarget(id); + if (target != null) { + + System.out.println("-- graph --"); + + TargetMonitor monitor = MonitorManager.instance().get(target); + + List<Measurement> temperatures = monitor.getTemperatures(); + List<Measurement> humidities = monitor.getHumidities(); + + + if (temperatures.size() > 0) { + long t0 = Long.MAX_VALUE; + long t1 = Long.MIN_VALUE; + + for (Measurement current : temperatures) { + if (current.getTime() < t0) { + t0 = current.getTime(); + } + if (current.getTime() > t1) { + t1 = current.getTime(); + } + } + + for (Measurement current : humidities) { + if (current.getTime() < t0) { + t0 = current.getTime(); + } + if (current.getTime() > t1) { + t1 = current.getTime(); + } + } + + long ellapsed = t1 - t0; + + long twohours = 2 * 60 * 60 * 1000; + long minutes = 4 * 60 * 1000; + + if (ellapsed < twohours) { + if (ellapsed > minutes) { + t0 = t1 - minutes; + } + t0 = (t0 / 1000) * 1000; + t1 = t0 + minutes; + ellapsed = minutes; + } + + double gx = a.getX() + margin + offset; + double gy = a.getY() + margin; + + double gw = width - offset - 2 * margin; + double gh = height - 2 * margin; + + double tscale = gw / (double) ellapsed; + + { + gl.glColor3d(0.3, 0.3, 0.3); + gl.glLineWidth(1f); + gl.glBegin(GL.GL_LINES); + gl.glVertex2d(gx, gy); + gl.glVertex2d(gx + gw, gy); + gl.glVertex2d(gx, gy); + gl.glVertex2d(gx, gy + gh); + gl.glEnd(); + } + + + if (ellapsed > 4 * 24 * 60 * 60 * 1000) { + DateFormat format = new SimpleDateFormat("dd/MM"); + { + long oneweek = 7 * 24 * 60 * 60 * 1000; + long m0 = ((t0 / oneweek) + 1) * oneweek; + + gl.glColor3d(0.3, 0.3, 0.3); + gl.glLineWidth(1f); + gl.glLineStipple(1, (short) 0x0F0F); + gl.glEnable(GL.GL_LINE_STIPPLE); + + for (int i = 0; i < 4; i++) { + String m0s = format.format(new Date(m0)); + double mx = gx + (m0 - t0) * tscale; + gl.glBegin(GL.GL_LINES); + gl.glVertex2d(mx, gy); + gl.glVertex2d(mx, gy + gh); + gl.glEnd(); + String[] s = m0s.split("/"); + double xx = measureString(s[0]); + drawString(mx - xx - 2, gy - 12, 0, m0s); + m0 = m0 + oneweek; + } + gl.glDisable(GL.GL_LINE_STIPPLE); + } + + } else { + DateFormat format = new SimpleDateFormat("HH:mm"); + { + long oneminute = 60 * 1000; + long m0 = ((t0 / oneminute) + 1) * oneminute; + + gl.glColor3d(0.3, 0.3, 0.3); + gl.glLineWidth(1f); + gl.glLineStipple(1, (short) 0x0F0F); + gl.glEnable(GL.GL_LINE_STIPPLE); + + for (int i = 0; i < 4; i++) { + String m0s = format.format(new Date(m0)); + double mx = gx + (m0 - t0) * tscale; + gl.glBegin(GL.GL_LINES); + gl.glVertex2d(mx, gy); + gl.glVertex2d(mx, gy + gh); + gl.glEnd(); + String[] s = m0s.split(":"); + double xx = measureString(s[0]); + drawString(mx - xx - 2, gy - 12, 0, m0s); + m0 = m0 + oneminute; + } + gl.glDisable(GL.GL_LINE_STIPPLE); + } + } + + + + double c0 = 15.0; + double c1 = 40.0; + double cscale = gh / (c1 - c0); + double h0 = 0; + double h1 = 100; + double hscale = gh / (h1 - h0); + + + System.out.println("cscale: " + cscale); + + { + double range = c1 - c0; + double step = range / 5; + double m0 = c0; + + gl.glColor3d(0.3, 0.3, 0.3); + gl.glLineWidth(1f); + NumberFormat f = new DecimalFormat("00.00"); + + for (int i = 0; i < 5; i++) { + String m0s = f.format(m0); + double mx = (m0 - c0) * cscale; + double xx = measureString(m0s); + drawString(gx - xx - 4, gy + mx, 0, m0s); + if (i > 0) { + drawString(gx + 4, gy + mx, 0, String.valueOf(i * 20)); + } + gl.glBegin(GL.GL_LINES); + gl.glVertex2d(gx - 2, gy + mx); + gl.glVertex2d(gx + 2, gy + mx); + gl.glEnd(); + + + m0 = m0 + step; + } + + gl.glColor3d(0.9, 0.1, 0.1); + drawString(gx - 20, gy + gh, 0, "¼C"); + + if (Project.enableAlarms) { + if (Project.historic) { + double value = target.average; + double dy = (value - c0) * cscale; + gl.glBegin(GL.GL_LINES); + gl.glVertex2d(gx, gy + dy); + gl.glVertex2d(gx + gw, gy + dy); + gl.glEnd(); + } + } + + gl.glColor3d(0.1, 0.1, 0.9); + drawString(gx + 5, gy + gh, 0, "RH%"); + + if (Project.enableAlarms) { + if (Project.historic) { + double value = target.limit; + double dy = (value - h0) * hscale; + gl.glBegin(GL.GL_LINES); + gl.glVertex2d(gx, gy + dy); + gl.glVertex2d(gx + gw, gy + dy); + gl.glEnd(); + } + } + } + + + { + gl.glColor3d(0.9, 0.1, 0.1); + gl.glLineWidth(2.5f); + gl.glBegin(GL.GL_LINE_STRIP); + + for (Measurement current : temperatures) { + long t = current.getTime(); + if (t >= t0 && t <= t1) { + double value = Double.valueOf(current.getValue()); + double dx = ((double) (t - t0)) * tscale; + double dy = (value - c0) * cscale; + gl.glVertex2d(gx + dx, gy + dy); + } + } + gl.glEnd(); + } + + { + gl.glColor3d(0.1, 0.1, 0.9); + gl.glLineWidth(2.5f); + gl.glBegin(GL.GL_LINE_STRIP); + + for (Measurement current : humidities) { + long t = current.getTime(); + if (t >= t0 && t <= t1) { + double value = Double.valueOf(current.getValue()); + double dx = ((double) (t - t0)) * tscale; + double dy = (value - h0) * hscale; + gl.glVertex2d(gx + dx, gy + dy); + } + } + + gl.glEnd(); + } + + } + } + } + } + String text = space.getDescription().toString(); BufferedReader reader = new BufferedReader(new StringReader(text)); *************** *** 1897,1900 **** --- 2210,2215 ---- } + + /** * *************** *** 1958,1961 **** --- 2273,2277 ---- clearNames(); if (surface != null) { + System.out.println("path: " + surface); return ((Surface)surface.getLastInPath()); } else { *************** *** 1964,1967 **** --- 2280,2353 ---- } } + + /** + * + * @param x x + * @param y y + * @return surface + */ + public Item getSelectedItem(double x, double y) { + this.x = x; + this.y = y; + + picking = 10; + + editor.repaint(true); + + { + int bufferOffset = 0; + int names = 0; + long zMax = 0xFFFFFFFFL; + double nearestSurface = 1.0; + SelectionPath surface = null; + + for (int i = 0; i < hits; i++) { + names = selectBuffer.get(bufferOffset); + if (names > 0) { + long z1 = 0xFFFFFFFFL & selectBuffer.get(bufferOffset + 1); + long z2 = 0xFFFFFFFFL & selectBuffer.get(bufferOffset + 2); + double near = (double) z1 / (double) zMax; + double far = (double) z2 / (double) zMax; + near = (near + far) / 2; + bufferOffset += 2; + SelectionPath currentPath = new SelectionPath(); + if (names > 1) { + for (int namesIndex = 1; namesIndex < names; namesIndex++) { + Instance instance = (Instance)getObject(selectBuffer.get(bufferOffset + namesIndex)); + currentPath.addGeometricToPath(instance); + } + if (currentPath == null) { + bufferOffset += names + 1; + continue; + } + } + int id = selectBuffer.get(bufferOffset + names); + bufferOffset += names + 1; + Object current = getObject(id); + + if (current instanceof Surface) { + Surface it = (Surface) current; + if (!Display.transparent(it)) { + if (near < nearestSurface) { + nearestSurface = near; + currentPath.addGeometricToPath((Surface) current); + surface = currentPath; + } + } + } + } else { + bufferOffset += 3; + } + } + clearNames(); + if (surface != null) { + return surface.getItem(); + } else { + return null; + } + } + } + + /** |