From: <ha...@us...> - 2006-12-20 03:11:53
|
Revision: 6518 http://svn.sourceforge.net/jmol/?rev=6518&view=rev Author: hansonr Date: 2006-12-19 19:11:52 -0800 (Tue, 19 Dec 2006) Log Message: ----------- adds script commands set showNavigationPointAlways set hideNavigationPoint navigation depth x.x #percent navigation center {x y z} navigation center (atom expression) navigation center $object navigation translate {x y z} navigation translate (atom expression) navigation translate $object navigation translate x.x y.y #percent; 0 0 is center navigation translate X x.x navigation translate Y y.y still no state definition for this Modified Paths: -------------- trunk/Jmol/src/org/jmol/viewer/BallsRenderer.java trunk/Jmol/src/org/jmol/viewer/Eval.java trunk/Jmol/src/org/jmol/viewer/StateManager.java trunk/Jmol/src/org/jmol/viewer/Token.java trunk/Jmol/src/org/jmol/viewer/TransformManager.java trunk/Jmol/src/org/jmol/viewer/TransformManager11.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/viewer/BallsRenderer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/BallsRenderer.java 2006-12-19 22:38:49 UTC (rev 6517) +++ trunk/Jmol/src/org/jmol/viewer/BallsRenderer.java 2006-12-20 03:11:52 UTC (rev 6518) @@ -69,9 +69,7 @@ renderBall(atom); } - if (frame.atomCount > 0 - && (viewer.getNavigating() || viewer.getNavigationMode() - && viewer.getInMotion())) { + if (frame.atomCount > 0 && viewer.getShowNavigationPoint()) { //testing here Point3f T = new Point3f(viewer.getNavigationOffset()); int x = (int) T.x; Modified: trunk/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Eval.java 2006-12-19 22:38:49 UTC (rev 6517) +++ trunk/Jmol/src/org/jmol/viewer/Eval.java 2006-12-20 03:11:52 UTC (rev 6518) @@ -1615,6 +1615,27 @@ return null; } + Point3f centerParameter(int i) throws ScriptException { + Point3f center = null; + switch (statement[i].tok) { + case Token.dollarsign: + String id = objectNameParameter(++i); + center = viewer.getDrawObjectCenter(id); + pcLastExpressionInstruction = i; + if (!isSyntaxCheck && center == null) + drawObjectNotDefined(id); + break; + case Token.expressionBegin: + case Token.leftbrace: + center = atomCenterOrCoordinateParameter(i); + break; + default: + coordinateOrNameOrExpressionRequired(); + } + i = pcLastExpressionInstruction; + return center; + } + Point4f planeParameter(int i) throws ScriptException { Vector3f vAB = new Vector3f(); Vector3f vAC = new Vector3f(); @@ -2044,27 +2065,99 @@ } void navigate() throws ScriptException { - //navigate time $drawObject(for now) - if (statementLength < 3) - badArgumentCount(); - float timeSec = floatParameter(1); - if (statement[2].tok == Token.dollarsign) { - //center $ id - String pathID = objectNameParameter(3); - if (isSyntaxCheck) - return; - setShapeProperty(JmolConstants.SHAPE_DRAW, "thisID", pathID); - Point3f[] path = (Point3f[]) viewer.getShapeProperty( - JmolConstants.SHAPE_DRAW, "path"); - refresh(); - if (path == null) - invalidArgument(); - viewer.navigate(timeSec, path); + /* + navigation on/off + navigation depth p # would be as a depth value, like slab, in percent, but could be negative + navigation nSec translate X Y # could be percentages + navigation nSec translate $object # could be a draw object + navigation nSec translate (atom selection) #average of values + navigation nSec center {x y z} + navigation nSec center $object + navigation nSec center (atom selection) + navigation nSec path $object + navigation nSec path {x y z theta} {x y z theta}{x y z theta}{x y z theta}... + */ + if (statementLength == 1) { + setBooleanProperty("navigationMode", true); return; } - invalidArgument(); + int tok; + Point3f pt; + if (statementLength == 2) { + switch (tok = statement[1].tok) { + case Token.on: + case Token.off: + setBooleanProperty("navigationMode", tok == Token.on); + default: + invalidArgument(); + } + } + int i = 1; + float timeSec = (isFloatParameter(i) ? floatParameter(i++) : 0); + if (statementLength < i + 2) + badArgumentCount(); + switch (statement[i].tok) { + case Token.depth: + float depth = floatParameter(++i); + if (!isSyntaxCheck) + viewer.setNavigationDepthPercent(depth); + break; + case Token.center: + pt = centerParameter(++i); + if (!isSyntaxCheck) + viewer.navigate(timeSec, pt); + break; + case Token.translate: + i++; + if (statementLength == i) + badArgumentCount(); + float x = Float.NaN; + float y = Float.NaN; + if (isFloatParameter(i)) { + x = floatParameter(i); + y = floatParameter(i + 1); + } else if (statement[i].tok == Token.identifier) { + String str = (String) statement[i++].value; + if (str.equalsIgnoreCase("x")) + x = floatParameter(i); + else if (str.equalsIgnoreCase("y")) + y = floatParameter(i); + else + invalidArgument(); + } else { + pt = centerParameter(i); + if (!isSyntaxCheck) + viewer.navTranslate(timeSec, pt); + break; + } + if (!isSyntaxCheck) + viewer.navTranslatePercent(timeSec, x, y); + break; + case Token.identifier: + if (((String) statement[2].value).equalsIgnoreCase("path")) { + if (statement[3].tok == Token.dollarsign) { + //center $ id + String pathID = objectNameParameter(3); + if (isSyntaxCheck) + return; + setShapeProperty(JmolConstants.SHAPE_DRAW, "thisID", pathID); + Point3f[] path = (Point3f[]) viewer.getShapeProperty( + JmolConstants.SHAPE_DRAW, "path"); + refresh(); + if (path == null) + invalidArgument(); + if (!isSyntaxCheck) + viewer.navigate(timeSec, path, null); // for now, no orientation + return; + } + //possibility here of multiple coord4 + } + //fall through; + default: + invalidArgument(); + } } - + void bondorder() throws ScriptException { Token tokenArg = statement[1]; short order = 0; @@ -2338,28 +2431,14 @@ void center(int i) throws ScriptException { // from center (atom) or from zoomTo under conditions of not windowCentered() if (statementLength == 1) { - viewer.setCenterBitSet(null, true); + viewer.setNewRotationCenter((Point3f) null); return; } - - if (statement[i].tok == Token.dollarsign) { - //center $ id - String axisID = objectNameParameter(i + 1); - if (!isSyntaxCheck) - viewer.setNewRotationCenter(axisID); - return; - } - - if (statement[i].tok == Token.leftbrace) { - //center { x y z } - Point3f pt = getCoordinate(i, true); - if (!isSyntaxCheck) - viewer.setNewRotationCenter(pt); - return; - } - BitSet bs = expression(statement, i); + Point3f center = centerParameter(i); + if (center == null) + invalidArgument(); if (!isSyntaxCheck) - viewer.setCenterBitSet(bs, true); + viewer.setNewRotationCenter(center); } void color() throws ScriptException { @@ -6070,21 +6149,8 @@ break; case Token.center: propertyName = "center"; - switch (statement[++i].tok) { - case Token.dollarsign: - String id = objectNameParameter(++i); - propertyValue = viewer.getDrawObjectCenter(id); - if (!isSyntaxCheck && propertyValue == null) - drawObjectNotDefined(id); - break; - case Token.expressionBegin: - case Token.leftbrace: - propertyValue = atomCenterOrCoordinateParameter(i); - i = pcLastExpressionInstruction; - break; - default: - coordinateOrNameOrExpressionRequired(); - } + propertyValue = centerParameter(i + 1); + i = pcLastExpressionInstruction; break; case Token.color: /* Modified: trunk/Jmol/src/org/jmol/viewer/StateManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/StateManager.java 2006-12-19 22:38:49 UTC (rev 6517) +++ trunk/Jmol/src/org/jmol/viewer/StateManager.java 2006-12-20 03:11:52 UTC (rev 6518) @@ -456,6 +456,8 @@ float defaultVectorScale = 1f; int scriptDelay = 0; int hoverDelayMs = 500; + boolean hideNavigationPoint = false; + boolean showNavigationPointAlways = false; // window Modified: trunk/Jmol/src/org/jmol/viewer/Token.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Token.java 2006-12-19 22:38:49 UTC (rev 6517) +++ trunk/Jmol/src/org/jmol/viewer/Token.java 2006-12-20 03:11:52 UTC (rev 6518) @@ -497,8 +497,6 @@ "load", new Token(load, varArgCount, "load"), "molecule", new Token(molecule, "molecule"), "molecules", null, - "navigate", new Token(navigate, "navigate"), - "nav", null, "altloc", new Token(altloc, "altloc"), "altlocs", null, "insertion", new Token(insertion, "insertion"), @@ -575,6 +573,8 @@ "rocket", new Token(rocket, onDefault1, "rocket"), "rockets", null, "moveto", new Token(moveto, varArgCount, "moveto"), + "navigate", new Token(navigate, varArgCount, "navigate"), + "navigation", null, "bondorder", new Token(bondorder, 1, "bondorder"), "console", new Token(console, onDefault1, "console"), "pmesh", new Token(pmesh, varArgCount, "pmesh"), Modified: trunk/Jmol/src/org/jmol/viewer/TransformManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/TransformManager.java 2006-12-19 22:38:49 UTC (rev 6517) +++ trunk/Jmol/src/org/jmol/viewer/TransformManager.java 2006-12-20 03:11:52 UTC (rev 6518) @@ -29,7 +29,6 @@ import javax.vecmath.Matrix4f; import javax.vecmath.Matrix3f; import javax.vecmath.AxisAngle4f; -import java.util.BitSet; import java.util.Hashtable; abstract class TransformManager { @@ -100,7 +99,7 @@ clearSpin(); fixedRotationCenter.set(0, 0, 0); navigating = false; - unsetNavigationPoint(); + resetNavigationPoint(); } String getState() { @@ -836,8 +835,15 @@ return perspectiveDepth; } - void setCameraDepth(float screenMultiples) { - if (screenMultiples <= 0) + /** + * either as a percent -300, or as a float 3.0 + * note this percent is of zoom=100 size of model + * + * @param percent + */ + void setCameraDepthPercent(float percent) { + float screenMultiples = (percent < 0 ? -percent / 100 : percent); + if (screenMultiples == 0) return; cameraDepth = screenMultiples; } @@ -893,7 +899,7 @@ private void setTranslationCenterToScreen() { // translate to the middle of the screen translateCenterTo(width / 2, height / 2); - unsetNavigationPoint(); + resetNavigationPoint(); // 2005 02 22 // switch to finding larger screen dimension // find smaller screen dimension @@ -989,7 +995,7 @@ void setNavigationMode(boolean TF) { isNavigationMode = (TF && canNavigate()); - unsetNavigationPoint(); + resetNavigationPoint(); } boolean getNavigating() { @@ -1764,7 +1770,7 @@ void setWindowCentered(boolean TF) { windowCentered = TF; - unsetNavigationPoint(); + resetNavigationPoint(); } void setDefaultRotation() { @@ -1785,7 +1791,7 @@ private void setRotationCenterAndRadiusXYZ(Point3f newCenterOfRotation, boolean andRadius) { - unsetNavigationPoint(); + resetNavigationPoint(); if (newCenterOfRotation == null) { setFixedRotationCenter(rotationCenterDefault); rotationRadius = rotationRadiusDefault; @@ -1807,18 +1813,11 @@ setRotationCenterAndRadiusXYZ(pointT, true); } - //from ModelManager: - - void setCenterBitSet(BitSet bsCenter, boolean doScale) { - Point3f center = (bsCenter != null && viewer.cardinalityOf(bsCenter) > 0 ? viewer - .getAtomSetCenter(bsCenter) - : rotationCenterDefault); - setNewRotationCenter(center, doScale); - } - void setNewRotationCenter(Point3f center, boolean doScale) { // once we have the center, we need to optionally move it to // the proper XY position and possibly scale + if (center == null) + center = rotationCenterDefault; if (windowCentered) { translateToXPercent(0); translateToYPercent(0);///CenterTo(0, 0); @@ -1854,10 +1853,10 @@ } /** - * keyboard entry point for navigation + * entry point for keyboard-based navigation * - * @param keyCode - * @param modifiers + * @param keyCode 0 indicates key released + * @param modifiers shift,alt,ctrl */ synchronized void navigate(int keyCode, int modifiers) { } @@ -1866,13 +1865,47 @@ * scripted entry point for navigation * * @param seconds - * @param path - * @param theta + * @param pt */ + synchronized void navigate(float seconds, Point3f pt) { + //unimplemented + } + + /** + * scripted navigation + * + * @param seconds number of seconds to allow for total movement, like moveTo + * @param path sequence of points to turn into a hermetian path + * @param theta orientation angle along path (0 aligns with window Y axis) + * [or Z axis if path is vertical] + * + * not implemented yet + */ void navigate(float seconds, Point3f[] path, float[] theta) { } /** + * scripted entry point for navigation + * + * @param seconds + * @param pt + */ + synchronized void navTranslate(float seconds, Point3f pt) { + //unimplemented + } + + /** + * scripted entry point for navigation + * + * @param seconds + * @param x + * @param y + */ + synchronized void navTranslatePercent(float seconds, float x, float y) { + //unimplemented + } + + /** * all navigation effects go through this method * */ @@ -1882,7 +1915,7 @@ /** * something has arisen that requires resetting of the navigation point. */ - protected void unsetNavigationPoint() { + protected void resetNavigationPoint() { } /** @@ -1894,4 +1927,13 @@ return ""; } + /** + * sets the position of the navigation offset relative + * to the model (50% center; 0% rear, 100% front; can be <0 or >100) + * + * @param percent + */ + void setNavigationDepthPercent(float percent) { + } + } Modified: trunk/Jmol/src/org/jmol/viewer/TransformManager11.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/TransformManager11.java 2006-12-19 22:38:49 UTC (rev 6517) +++ trunk/Jmol/src/org/jmol/viewer/TransformManager11.java 2006-12-20 03:11:52 UTC (rev 6518) @@ -77,7 +77,6 @@ // + " " + visualRange); if (slabEnabled) { float radius = rotationRadius * scalePixelsPerAngstrom; - float center = cameraDistance + screenPixelCount / 2f; if (perspectiveDepth && visualRange > 0 && slabPercentSetting == 0) { slabValue = (int) observerOffset; depthValue = Integer.MAX_VALUE; @@ -87,8 +86,8 @@ } // a slab percentage of 100 should map to zero // a slab percentage of 0 should map to -diameter - slabValue = (int) (((50 - slabPercentSetting) * radius / 50) + center); - depthValue = (int) (((50 - depthPercentSetting) * radius / 50) + center); + slabValue = (int) (((50 - slabPercentSetting) * radius / 50) + modelCenterOffset); + depthValue = (int) (((50 - depthPercentSetting) * radius / 50) + modelCenterOffset); //System.out.println("sv=" + slabValue + ","+slabPercentSetting+" dv=" + depthValue +","+depthPercentSetting+ " cent=" + center + " cdist=" + cameraDistance + " ps="+ perspectiveScale+" cdepth=" + cameraDepth + " radius="+radius ); } } @@ -159,21 +158,36 @@ return true; } - /** - * entry point for keyboard-based navigation - * - * @param keyCode 0 indicates key released - * @param modifiers shift,alt,ctrl - */ + void setNavigationDepthPercent(float percent) { + // navigation depth 0 # place user at front plane of the model + // navigation depth 100 # place user at rear plane of the model + + // scalePixelsPerAngstrom takes into account any zoom + + // perspectiveScale + navigationZOffset = observerOffset + dz + + calcCameraFactors(); //current + float dz = ((50 - percent) / 100) * rotationRadius * scalePixelsPerAngstrom; + navigationZOffset = observerOffset + dz - perspectiveScale; + calcCameraFactors(); //updated + } + + int nHits; + int multiplier = 1; synchronized void navigate(int keyCode, int modifiers) { if (!isNavigationMode) return; if (keyCode == 0) { + nHits = 0; + multiplier = 1; if (!navigating) return; navigating = false; return; } + nHits++; + if (nHits % 10 == 0) + multiplier *= (multiplier == 8 ? 1 : 2); boolean isOffsetShifted = ((modifiers & InputEvent.SHIFT_MASK) > 0); boolean isAltKey = ((modifiers & InputEvent.ALT_MASK) > 0); newNavigationOffset.set(navigationOffset); @@ -181,44 +195,46 @@ switch (keyCode) { case KeyEvent.VK_UP: if (isOffsetShifted) - newNavigationOffset.y -= 2; + newNavigationOffset.y -= 2 * multiplier; else if (isAltKey) - rotateXRadians(radiansPerDegree * -.2f); + rotateXRadians(radiansPerDegree * -.2f * multiplier); else if (isNavigationDistant()) - zoomBy(1); + zoomBy(multiplier); else - navigationZOffset -= 5; + navigationZOffset -= 5 * multiplier; ptNav.z = Float.NaN; break; case KeyEvent.VK_DOWN: if (isOffsetShifted) - newNavigationOffset.y += 2; + newNavigationOffset.y += 2 * multiplier; else if (isAltKey) - rotateXRadians(radiansPerDegree * .2f); + rotateXRadians(radiansPerDegree * .2f * multiplier); else if (isNavigationDistant()) - zoomBy(-1); + zoomBy(-multiplier); else - navigationZOffset += 5; + navigationZOffset += 5 * multiplier; ptNav.z = Float.NaN; break; case KeyEvent.VK_LEFT: if (isOffsetShifted) - newNavigationOffset.x -= 2; + newNavigationOffset.x -= 2 * multiplier; else - rotateYRadians(radiansPerDegree * 3 * -.2f); + rotateYRadians(radiansPerDegree * 3 * -.2f * multiplier); break; case KeyEvent.VK_RIGHT: if (isOffsetShifted) - newNavigationOffset.x += 2; + newNavigationOffset.x += 2 * multiplier; else - rotateYRadians(radiansPerDegree * 3 * .2f); + rotateYRadians(radiansPerDegree * 3 * .2f * multiplier); break; default: navigating = false; return; } - if (isOffsetShifted) + if (isOffsetShifted) { + navigationOffset.set(newNavigationOffset); ptNav.y = Float.NaN; + } navigating = true; } @@ -233,24 +249,41 @@ return (fixedRotationOffset.z - rotationRadius * scalePixelsPerAngstrom > observerOffset); } - /** - * scripted navigation - * - * @param seconds number of seconds to allow for total movement, like moveTo - * @param path sequence of points to turn into a hermetian path - * @param theta orientation angle along path (0 aligns with window Y axis) - * [or Z axis if path is vertical] - * - * not implemented yet - */ + synchronized void navTranslate(float seconds, Point3f pt) { + //seconds unimplemented + transformPoint(pt, pointT); + transformPoint(navigationCenter, navigationOffset); + navigationOffset.x = pointT.x; + navigationOffset.y = pointT.y; + ptNav.set(0, Float.NaN, 0); + } + + synchronized void navTranslatePercent(float seconds, float x, float y) { + //seconds unimplemented + transformPoint(navigationCenter, navigationOffset); + if (!Float.isNaN(x)) + navigationOffset.x = (width / 2) + width * x / 100; + if (!Float.isNaN(y)) + navigationOffset.y = (height / 2) + height * y / 100; + ptNav.set(0, Float.NaN, 0); + } + + void navigate(float seconds, Point3f pt) { + //seconds unimplemented + navigationCenter.set(pt); + transformPoint(pt, navigationOffset); + } + void navigate(float seconds, Point3f[] path, float[] theta) { // TODO } - protected void unsetNavigationPoint() { + protected void resetNavigationPoint() { if (ptNav == null) - return; + return; //just initializing subclass ptNav.x = Float.NaN; + slabPercentSetting = (isNavigationMode ? 0 : 100); + slabEnabled = isNavigationMode; } /** @@ -272,9 +305,7 @@ navigationOffset.z = observerOffset; findCenterAt(fixedRotationCenter, navigationOffset, navigationCenter); } else if (isNewXY || !navigating) { - // redefine the navigation center based on its new or old screen position - if (navigating) - navigationOffset.set(newNavigationOffset); + // redefine the navigation center based on its old screen position findCenterAt(fixedRotationCenter, navigationOffset, navigationCenter); } else if (isNewZ) { // nothing special to do -- navigationZOffset has changed. Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2006-12-19 22:38:49 UTC (rev 6517) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2006-12-20 03:11:52 UTC (rev 6518) @@ -380,20 +380,15 @@ } void setCenterBitSet(BitSet bsCenter, boolean doScale) { - //Eval ??? + //Eval //setCenterSelected - transformManager.setCenterBitSet(bsCenter, doScale); + + Point3f center = (bsCenter != null && cardinalityOf(bsCenter) > 0 ? + getAtomSetCenter(bsCenter) : null); + transformManager.setNewRotationCenter(center, doScale); refresh(0, "Viewer:setCenterBitSet()"); } - void setNewRotationCenter(String axisID) { - //eval for center [line1] ??? - Point3f center = getDrawObjectCenter(axisID); - if (center == null) - return; - setNewRotationCenter(center); - } - void setNewRotationCenter(Point3f center) { // eval ??? transformManager.setNewRotationCenter(center, true); @@ -426,10 +421,26 @@ return transformManager.getMoveToText(timespan); } - void navigate(float timeSeconds, Point3f[] path) { - transformManager.navigate(timeSeconds, path, null); + void navigate(float timeSeconds, Point3f[] path, float[] theta) { + transformManager.navigate(timeSeconds, path, theta); + refresh(1, "navigate"); } + void navigate(float timeSeconds, Point3f center) { + transformManager.navigate(timeSeconds, center); + refresh(1, "navigate"); + } + + void navTranslate(float timeSeconds, Point3f center) { + transformManager.navTranslate(timeSeconds, center); + refresh(1, "navigate"); + } + + void navTranslatePercent(float timeSeconds, float x, float y) { + transformManager.navTranslatePercent(timeSeconds, x, y); + refresh(1, "navigate"); + } + boolean pointToCenter = true; boolean getPointToCenter() { @@ -3366,6 +3377,14 @@ setNavigationMode(value); break; } + if (key.equalsIgnoreCase("hideNavigationPoint")) { + setHideNavigationPoint(value); + break; + } + if (key.equalsIgnoreCase("showNavigationPointAlways")) { + setShowNavigationPointAlways(value); + break; + } ///11.0/// if (key.equalsIgnoreCase("refreshing")) { setRefreshing(value); @@ -3676,11 +3695,31 @@ transformManager.setWindowCentered(TF); } - public void setCameraDepth(float screenMultiples) { - transformManager.setCameraDepth(screenMultiples); + private void setCameraDepth(float percent) { + transformManager.setCameraDepthPercent(percent); refresh(1, "set cameraDepth"); } + void setNavigationDepthPercent(float percent) { + transformManager.setNavigationDepthPercent(percent); + refresh(1, "set navigationdDepth"); + } + + private void setShowNavigationPointAlways(boolean TF) { + global.showNavigationPointAlways = TF; + } + + private void setHideNavigationPoint(boolean TF) { + global.hideNavigationPoint = TF; + } + + boolean getShowNavigationPoint() { + if (!global.navigationMode) + return false; + return (getNavigating() && !global.hideNavigationPoint + || global.showNavigationPointAlways || getInMotion()); + } + public void setVisualRange(float angstroms) { transformManager.setVisualRange(angstroms); refresh(1, "set visualRange"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |