From: <ha...@us...> - 2008-11-25 20:08:05
|
Revision: 10364 http://jmol.svn.sourceforge.net/jmol/?rev=10364&view=rev Author: hansonr Date: 2008-11-25 20:07:58 +0000 (Tue, 25 Nov 2008) Log Message: ----------- version=11.7.13_dev # new feature: sync * stereo Modified Paths: -------------- trunk/Jmol/src/JmolApplet.java trunk/Jmol/src/org/jmol/api/JmolAppletInterface.java trunk/Jmol/src/org/jmol/api/JmolViewer.java trunk/Jmol/src/org/jmol/applet/Jmol.java trunk/Jmol/src/org/jmol/appletwrapper/AppletWrapper.java trunk/Jmol/src/org/jmol/viewer/Eval.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/StateManager.java trunk/Jmol/src/org/jmol/viewer/StatusManager.java trunk/Jmol/src/org/jmol/viewer/TransformManager.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/JmolApplet.java =================================================================== --- trunk/Jmol/src/JmolApplet.java 2008-11-24 21:10:40 UTC (rev 10363) +++ trunk/Jmol/src/JmolApplet.java 2008-11-25 20:07:58 UTC (rev 10364) @@ -31,6 +31,8 @@ * */ +import java.awt.Graphics; + import org.jmol.api.JmolAppletInterface; import netscape.javascript.JSObject; @@ -169,6 +171,11 @@ wrappedApplet.syncScript("" + script); } + public Graphics setStereoGraphics(boolean isStereo) { + return (wrappedApplet == null ? null : + wrappedApplet.setStereoGraphics(isStereo)); + } + public String scriptNoWait(String script) { if (wrappedApplet != null) return "" + (wrappedApplet.scriptNoWait("" + script)); Modified: trunk/Jmol/src/org/jmol/api/JmolAppletInterface.java =================================================================== --- trunk/Jmol/src/org/jmol/api/JmolAppletInterface.java 2008-11-24 21:10:40 UTC (rev 10363) +++ trunk/Jmol/src/org/jmol/api/JmolAppletInterface.java 2008-11-25 20:07:58 UTC (rev 10364) @@ -23,6 +23,8 @@ */ package org.jmol.api; +import java.awt.Graphics; + import netscape.javascript.JSObject; /** @@ -35,6 +37,7 @@ public interface JmolAppletInterface { + public Graphics setStereoGraphics(boolean isStereo); public String getPropertyAsString(String infoType); public String getPropertyAsString(String infoType, String paramInfo); public String getPropertyAsJSON(String infoType); @@ -50,7 +53,7 @@ public String scriptCheck(String script); public String scriptWait(String script); public String scriptWait(String script, String statusParams); - public void syncScript(String script); + public void syncScript(String script); /** * @deprecated Modified: trunk/Jmol/src/org/jmol/api/JmolViewer.java =================================================================== --- trunk/Jmol/src/org/jmol/api/JmolViewer.java 2008-11-24 21:10:40 UTC (rev 10363) +++ trunk/Jmol/src/org/jmol/api/JmolViewer.java 2008-11-25 20:07:58 UTC (rev 10364) @@ -27,7 +27,9 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.Event; +import java.awt.Graphics; import java.awt.Image; +import java.awt.Rectangle; import java.net.URL; import java.util.BitSet; import java.util.Properties; @@ -84,6 +86,17 @@ } /** + * an added class for rendering stereo in two independent applets + * + * @param gLeft + * @param gRight + * @param size + * @param clip + */ + abstract public void renderScreenImage(Graphics gLeft, Graphics gRight, Dimension size, + Rectangle clip); + + /** * OK, but safer to assign htmlName, URL bases, comandOptions, and statusListener now. * * @deprecated Modified: trunk/Jmol/src/org/jmol/applet/Jmol.java =================================================================== --- trunk/Jmol/src/org/jmol/applet/Jmol.java 2008-11-24 21:10:40 UTC (rev 10363) +++ trunk/Jmol/src/org/jmol/applet/Jmol.java 2008-11-25 20:07:58 UTC (rev 10364) @@ -220,6 +220,7 @@ } public void destroy() { + gRight = null; JmolAppletRegistry.checkOut(fullName); viewer.setModeMouse(JmolConstants.MOUSE_NONE); viewer = null; @@ -234,6 +235,11 @@ return appletWrapper.getParameter(paramName); } + public Graphics setStereoGraphics(boolean isStereo) { + isStereoSlave = isStereo; + return (isStereo ? appletWrapper.getGraphics() : null); + } + boolean isSigned; JmolAdapter modelAdapter; @@ -471,21 +477,22 @@ } public boolean showPaintTime = false; - public void paint(Graphics g) { //paint is invoked for system-based updates (obscurring, for example) //Opera has a bug in relation to displaying the Java Console. - update(g, "paint "); } private boolean isUpdating; public void update(Graphics g) { - //update is called in response to repaintManager's repaint() request. + //update is called in response to repaintManager's repaint() request. update(g, "update"); } + protected Graphics gRight; + protected boolean isStereoSlave; + private void update(Graphics g, String source) { if (viewer == null) // it seems that this can happen at startup sometimes return; @@ -510,7 +517,9 @@ viewer.repaintView(); } else { //System.out.println("UPDATE1: " + source + " " + Thread.currentThread()); - viewer.renderScreenImage(g, size, null);//rectClip); + //System.out.println(fullName + " update gRight = " + gRight); + if (!isStereoSlave) + viewer.renderScreenImage(g, gRight, size, null);//rectClip); //System.out.println("UPDATE2: " + source + " " + Thread.currentThread()); } @@ -1203,6 +1212,10 @@ return ""; } StringBuffer sb = (isSync ? null : new StringBuffer()); + boolean getGraphics = (isSync && script.equals(Viewer.SYNC_GRAPHICS_MESSAGE)); + boolean setNoGraphics = (isSync && script.equals(Viewer.SYNC_NO_GRAPHICS_MESSAGE)); + if (getGraphics) + gRight = null; for (int i = 0; i < nApplets; i++) { String theApplet = (String) apps.elementAt(i); JmolAppletInterface app = (JmolAppletInterface) JmolAppletRegistry.htRegistry @@ -1210,6 +1223,10 @@ if (Logger.debugging) Logger.debug(fullName + " sending to " + theApplet + ": " + script); try { + if (getGraphics || setNoGraphics) { + gRight = app.setStereoGraphics(getGraphics); + return ""; + } if (isSync) app.syncScript(script); else Modified: trunk/Jmol/src/org/jmol/appletwrapper/AppletWrapper.java =================================================================== --- trunk/Jmol/src/org/jmol/appletwrapper/AppletWrapper.java 2008-11-24 21:10:40 UTC (rev 10363) +++ trunk/Jmol/src/org/jmol/appletwrapper/AppletWrapper.java 2008-11-25 20:07:58 UTC (rev 10364) @@ -59,7 +59,6 @@ private int clockBaseline; private int clockWidth; - private static int MINIMUM_ELAPSED_SECONDS = 1; private static String fontFace = "sansserif"; Modified: trunk/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Eval.java 2008-11-24 21:10:40 UTC (rev 10363) +++ trunk/Jmol/src/org/jmol/viewer/Eval.java 2008-11-25 20:07:58 UTC (rev 10364) @@ -5263,7 +5263,7 @@ break; case 3: applet = parameterAsString(1); - text = parameterAsString(2); + text = (tokAt(2) == Token.stereo ? Viewer.SYNC_GRAPHICS_MESSAGE : parameterAsString(2)); break; } if (isSyntaxCheck) Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2008-11-24 21:10:40 UTC (rev 10363) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2008-11-25 20:07:58 UTC (rev 10364) @@ -3,6 +3,7 @@ version=11.7.13_dev +# new feature: sync * stereo # bug fix: applet improperly reporting status of "quiet" commands # bug fix: stereo not in state # bug fix: stereoDegrees parameter not reported correctly Modified: trunk/Jmol/src/org/jmol/viewer/StateManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/StateManager.java 2008-11-24 21:10:40 UTC (rev 10363) +++ trunk/Jmol/src/org/jmol/viewer/StateManager.java 2008-11-25 20:07:58 UTC (rev 10364) @@ -756,7 +756,7 @@ + ";unitcellcolor;windowcentered;zerobasedxyzrasmol;zoomenabled" + // saved in the hash table but not considered part of the state: - ";scriptqueue;scriptreportinglevel;syncscript;syncmouse;currentlocalpath;defaultdirectorylocal" + ";scriptqueue;scriptreportinglevel;syncscript;syncmouse;syncstereo;currentlocalpath;defaultdirectorylocal" + // more settable Jmol variables ";ambient;bonds;colorrasmol;diffuse;frank;hetero;hidenotselected" @@ -1242,6 +1242,7 @@ setParameterValue("strandCountForMeshRibbon", strandCountForMeshRibbon); setParameterValue("syncMouse", false); setParameterValue("syncScript", false); + setParameterValue("syncStereo", false); setParameterValue("testFlag1", testFlag1); setParameterValue("testFlag2", testFlag2); setParameterValue("testFlag3", testFlag3); Modified: trunk/Jmol/src/org/jmol/viewer/StatusManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/StatusManager.java 2008-11-24 21:10:40 UTC (rev 10363) +++ trunk/Jmol/src/org/jmol/viewer/StatusManager.java 2008-11-25 20:07:58 UTC (rev 10364) @@ -298,12 +298,14 @@ boolean drivingSync = false; boolean isSynced = false; boolean syncDisabled = false; + boolean stereoSync = false; final static int SYNC_OFF = 0; final static int SYNC_DRIVER = 1; final static int SYNC_SLAVE = 2; final static int SYNC_DISABLE = 3; final static int SYNC_ENABLE = 4; + final static int SYNC_STEREO = 5; void setSyncDriver(int syncMode) { @@ -311,7 +313,12 @@ // 0 off // 1 driving on as driver // 2 sync turn on, but set as slave + // 5 stereo //System.out.println(viewer.getHtmlName() +" setting mode=" + syncMode); + if (stereoSync && syncMode != SYNC_ENABLE) { + syncSend(Viewer.SYNC_NO_GRAPHICS_MESSAGE, "*"); + stereoSync = false; + } switch (syncMode) { case SYNC_ENABLE: if (!syncDisabled) @@ -321,6 +328,11 @@ case SYNC_DISABLE: syncDisabled = true; break; + case SYNC_STEREO: + drivingSync = true; + isSynced = true; + stereoSync = true; + break; case SYNC_DRIVER: drivingSync = true; isSynced = true; Modified: trunk/Jmol/src/org/jmol/viewer/TransformManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/TransformManager.java 2008-11-24 21:10:40 UTC (rev 10363) +++ trunk/Jmol/src/org/jmol/viewer/TransformManager.java 2008-11-25 20:07:58 UTC (rev 10364) @@ -169,7 +169,7 @@ JmolConstants.getStereoModeName(stereoMode) : Escape.escapeColor(stereoColors[0]) + " " + Escape.escapeColor(stereoColors[1])) - + " " + viewer.getStereoDegrees()); + + " " + stereoDegrees); if (!isNavigationMode && !zoomEnabled) StateManager.appendCmd(commands, "zoom off"); commands.append(" slab ").append(slabPercentSetting).append(";depth ") @@ -2026,12 +2026,12 @@ this.stereoMode = stereoMode; } - float stereoDegrees; // set in state manager - float stereoRadians = 5 * radiansPerDegree; + float stereoDegrees = Float.NaN; // set in state manager + float stereoRadians; void setStereoDegrees(float stereoDegrees) { this.stereoDegrees = stereoDegrees; - this.stereoRadians = stereoDegrees * radiansPerDegree; + stereoRadians = stereoDegrees * radiansPerDegree; } boolean stereoFrame; @@ -2040,12 +2040,10 @@ synchronized Matrix3f getStereoRotationMatrix(boolean stereoFrame) { this.stereoFrame = stereoFrame; - if (stereoFrame) { - matrixTemp3.rotY(-stereoRadians); - matrixStereo.mul(matrixTemp3, matrixRotate); - } else { - matrixStereo.set(matrixRotate); - } + if (!stereoFrame) + return matrixRotate; + matrixTemp3.rotY(-stereoRadians); + matrixStereo.mul(matrixTemp3, matrixRotate); return matrixStereo; } Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2008-11-24 21:10:40 UTC (rev 10363) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2008-11-25 20:07:58 UTC (rev 10364) @@ -3154,7 +3154,7 @@ dim.width = Math.min(dim.width, maximumSize); int height = dim.height; int width = dim.width; - if (getStereoMode() == JmolConstants.STEREO_DOUBLE) + if (transformManager.stereoMode == JmolConstants.STEREO_DOUBLE) width = (width + 1) / 2; if (dimScreen.width == width && dimScreen.height == height) return; @@ -3224,8 +3224,14 @@ return data; } - public void renderScreenImage(Graphics g, Dimension size, Rectangle clip) { + public void renderScreenImage(Graphics gLeft, Graphics gRight, + Dimension size, Rectangle clip) { // from paint/update event + // gRight is for second stereo applet + // when this is the stereoSlave, no rendering occurs through this applet + // directly, only from the other applet. + // this is for relatively specialized geoWall-type installations + if (creatingImage) return; if (isTainted || getSlabEnabled()) @@ -3233,23 +3239,24 @@ isTainted = false; if (size != null) setScreenDimension(size); - int stereoMode = getStereoMode(); - switch (stereoMode) { - case JmolConstants.STEREO_DOUBLE: - render1(g, getImage(true), dimScreen.width, 0); - case JmolConstants.STEREO_NONE: - render1(g, getImage(false), 0, 0); - break; - case JmolConstants.STEREO_REDCYAN: - case JmolConstants.STEREO_REDBLUE: - case JmolConstants.STEREO_REDGREEN: - case JmolConstants.STEREO_CUSTOM: - render1(g, getStereoImage(stereoMode), 0, 0); - break; + if (gRight == null) { + Image image = getScreenImage(); + if (transformManager.stereoMode == JmolConstants.STEREO_DOUBLE) { + render1(gLeft, image, dimScreen.width, 0); + image = getImage(false); + } + render1(gLeft, image, 0, 0); + } else { + render1(gRight, getImage(true), 0, 0); + render1(gLeft, getImage(false), 0, 0); } repaintView(); } + public void renderScreenImage(Graphics g, Dimension size, Rectangle clip) { + renderScreenImage(g, null, size, clip); + } + private Image getImage(boolean isDouble) { g3d.beginRendering(transformManager.getStereoRotationMatrix(isDouble)); render(); @@ -3305,22 +3312,9 @@ } public Image getScreenImage() { - boolean isStereo = false; - //setRectClip(null); - int stereoMode = getStereoMode(); - switch (stereoMode) { - case JmolConstants.STEREO_DOUBLE: - // this allows for getting both eye views in two images - // because you can adjust using "stereo -2.5", then "stereo +2.5" - isStereo = true; - break; - case JmolConstants.STEREO_REDCYAN: - case JmolConstants.STEREO_REDBLUE: - case JmolConstants.STEREO_REDGREEN: - case JmolConstants.STEREO_CUSTOM: - return getStereoImage(stereoMode); - } - return getImage(isStereo); + return (transformManager.stereoMode <= JmolConstants.STEREO_DOUBLE ? + getImage(transformManager.stereoMode == JmolConstants.STEREO_DOUBLE) + : getStereoImage(transformManager.stereoMode)); } /** @@ -5962,14 +5956,6 @@ transformManager.setStereoMode(stereoMode); } - int getStereoMode() { - return transformManager.stereoMode; - } - - float getStereoDegrees() { - return transformManager.stereoDegrees; - } - // ////////////////////////////////////////////////////////////// // // ////////////////////////////////////////////////////////////// @@ -6532,13 +6518,32 @@ case 1: statusManager.syncingScripts = TF; break; + case 2: + statusManager.syncSend(TF ? SYNC_GRAPHICS_MESSAGE : SYNC_NO_GRAPHICS_MESSAGE, "*"); + if (Float.isNaN(transformManager.stereoDegrees)) + setFloatProperty("stereoDegrees", TransformManager.DEFAULT_STEREO_DEGREES); + if (TF) { + setBooleanProperty("syncMouse", false); + setBooleanProperty("syncScript", false); + } + return; } // if turning both off, sync the orientation now if (!statusManager.syncingScripts && !statusManager.syncingMouse) refresh(-1, "set sync"); } + public final static String SYNC_GRAPHICS_MESSAGE = "GET_GRAPHICS"; + public final static String SYNC_NO_GRAPHICS_MESSAGE = "SET_GRAPHICS_OFF"; + public void syncScript(String script, String applet) { + if (script.equalsIgnoreCase(SYNC_GRAPHICS_MESSAGE)) { + statusManager.setSyncDriver(StatusManager.SYNC_STEREO); + statusManager.syncSend(script, applet); + setBooleanProperty("syncMouse", false); + setBooleanProperty("syncScript", false); + return; + } // * : all applets // > : all OTHER applets // . : just me @@ -6551,7 +6556,7 @@ return; } if (script.equalsIgnoreCase("on")) { - statusManager.setSyncDriver(StatusManager.SYNC_DRIVER); + statusManager.setSyncDriver(StatusManager.SYNC_DRIVER); return; } if (script.equalsIgnoreCase("off")) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |