Revision: 21246
          http://sourceforge.net/p/jmol/code/21246
Author:   hansonr
Date:     2016-09-19 01:10:23 +0000 (Mon, 19 Sep 2016)
Log Message:
-----------
Jmol.___JmolVersion="14.7.3_2016.09.18"

new feature: show chemical formula reads formula from CIF

bug fix: write MENU broken for non-English language (UTF-8 strings not 
correctly encoded using base64)
bug fix: write PNGJ should not store "#_DOCACHE_" in PNGJ file
bug fix: JSmol echo image loading from PNGJ can fail
bug fix: load "" after pasting in structure to load fails

Modified Paths:
--------------
    trunk/Jmol/src/javajs/util/SB.java
    trunk/Jmol/src/org/jmol/scriptext/CmdExt.java
    trunk/Jmol/src/org/jmol/viewer/FileManager.java
    trunk/Jmol/src/org/jmol/viewer/Jmol.properties
    trunk/Jmol/src/org/jmol/viewer/OutputManager.java

Modified: trunk/Jmol/src/javajs/util/SB.java
===================================================================
--- trunk/Jmol/src/javajs/util/SB.java  2016-09-15 03:14:17 UTC (rev 21245)
+++ trunk/Jmol/src/javajs/util/SB.java  2016-09-19 01:10:23 UTC (rev 21246)
@@ -1,6 +1,8 @@
 
 package javajs.util;
 
+import java.nio.charset.Charset;
+
 import javajs.J2SIgnoreImport;
 
 /**
@@ -12,7 +14,7 @@
  * 
  */
 
-@J2SIgnoreImport({java.lang.StringBuilder.class})
+@J2SIgnoreImport({java.lang.StringBuilder.class, 
java.nio.charset.Charset.class})
 public class SB {
   
   private java.lang.StringBuilder sb;
@@ -308,19 +310,33 @@
   }
 
   /**
-   * simple byte conversion not allowing for unicode.
-   * Used for base64 conversion and allows for offset
-   * @param off 
-   * @param len or -1 for full length (then off must = 0)
+   * simple byte conversion properly implementing UTF-8. * Used for base64
+   * conversion and allows for offset
+   * 
+   * @param off
+   * @param len
+   *        or -1 for full length (then off must = 0)
    * @return byte[]
    */
   public byte[] toBytes(int off, int len) {
-    if (len < 0)
-      len = length() - off;
-    byte[] b = new byte[len];
-    for (int i = off + len, j = i - off; --i >= off;)
-      b[--j] = (byte) charAt(i);
-    return b;
+    if (len == 0)
+      return new byte[0];
+    Charset cs;
+    /**
+     * 
+     * just a string in JavaScript
+     * 
+     * @j2sNative
+     * 
+     *            cs = "UTF-8";
+     * 
+     */
+    {
+      cs = Charset.forName("UTF-8");
+    }
+    return (len > 0 ? substring2(off, off + len) 
+        : off == 0 ? toString()
+        : substring2(off, length() - off)).getBytes(cs);
   }
 
        public void replace(int start, int end, String str) {

Modified: trunk/Jmol/src/org/jmol/scriptext/CmdExt.java
===================================================================
--- trunk/Jmol/src/org/jmol/scriptext/CmdExt.java       2016-09-15 03:14:17 UTC 
(rev 21245)
+++ trunk/Jmol/src/org/jmol/scriptext/CmdExt.java       2016-09-19 01:10:23 UTC 
(rev 21246)
@@ -4244,52 +4244,61 @@
           + filterLen);
       if (chk)
         return;
-      try {
-        if (tok != T.smiles) {
-          msg = vwr.ms.getModelDataBaseName(vwr.bsA());
-          // this does not work for NCI, because, for example, "$menthol" 
returns an enantiomer, but menthol/smiles uses nonstereo option
-          // but we don't want to be generating our own SMILES here, do we?
-          // what is the solution?
-          if (msg != null && (msg.startsWith("$") || msg.startsWith(":"))) {
-            msg = msg.substring(1);
+      String param2 = eval.optParameterAsString(2);
+      if (tok == T.chemical && "formula".equals(param2)) {
+        msg = (String) vwr.ms.getInfo(vwr.am.cmi, "formula");
+        // cif files will have formula already
+        if (msg != null)
+          msg = PT.rep(msg, " ", "");
+      }
+      if (msg == null) {
+        try {
+          if (tok != T.smiles) {
+            msg = vwr.ms.getModelDataBaseName(vwr.bsA());
+            // this does not work for NCI, because, for example, "$menthol" 
returns an enantiomer, but menthol/smiles uses nonstereo option
+            // but we don't want to be generating our own SMILES here, do we?
+            // what is the solution?
+            if (msg != null && (msg.startsWith("$") || msg.startsWith(":"))) {
+              msg = msg.substring(1);
+            } else {
+              msg = null;
+            }
+          } else if (param2.equalsIgnoreCase("true")) {
+            msg = vwr.getBioSmiles(null);
+            filter = null;
+          } else if (filter != null) {
+            msg = vwr.getSmilesOpt(null, -1, -1, JC.SMILES_TYPE_SMILES, filter
+                + "///");
+            filter = null;
+          }
+          if (msg == null)
+            msg = (tok == T.smiles ? vwr.getSmiles(null) : vwr
+                .getOpenSmiles(null));
+        } catch (Exception ex) {
+          msg = ex.getMessage();
+        }
+        switch (tok) {
+        case T.smiles:
+          break;
+        case T.drawing:
+          if (msg.length() > 0) {
+            vwr.fm.loadImage(vwr.setLoadFormat("_" + msg, '2', false), "\1"
+                + msg, false);
+            return;
+          }
+          msg = "Could not show drawing -- Either insufficient atoms are 
selected or the model is a PDB file.";
+          break;
+        case T.chemical:
+          len = 3;
+          if (msg.length() > 0) {
+            msg = vwr.getChemicalInfo(msg, param2);
+            if (msg.indexOf("FileNotFound") >= 0)
+              msg = "?";
           } else {
-            msg = null;
+            msg = "Could not show name -- Either insufficient atoms are 
selected or the model is a PDB file.";
           }
-        } else if (eval.optParameterAsString(2).equalsIgnoreCase("true")) {
-          msg = vwr.getBioSmiles(null);
-          filter = null;
-        } else if (filter != null) {
-          msg = vwr.getSmilesOpt(null, -1, -1, JC.SMILES_TYPE_SMILES, filter
-              + "///");
-          filter = null;
         }
-        if (msg == null)
-          msg = (tok == T.smiles ? vwr.getSmiles(null) : vwr
-              .getOpenSmiles(null));
-      } catch (Exception ex) {
-        msg = ex.getMessage();
       }
-      switch (tok) {
-      case T.smiles:
-        break;
-      case T.drawing:
-        if (msg.length() > 0) {
-          vwr.fm.loadImage(vwr.setLoadFormat("_" + msg, '2', false),
-              "\1" + msg, false);
-          return;
-        }
-        msg = "Could not show drawing -- Either insufficient atoms are 
selected or the model is a PDB file.";
-        break;
-      case T.chemical:
-        len = 3;
-        if (msg.length() > 0) {
-          msg = vwr.getChemicalInfo(msg, getToken(2).value.toString());
-          if (msg.indexOf("FileNotFound") >= 0)
-            msg = "?";
-        } else {
-          msg = "Could not show name -- Either insufficient atoms are selected 
or the model is a PDB file.";
-        }
-      }
       break;
     case T.spacegroup:
     case T.symop:

Modified: trunk/Jmol/src/org/jmol/viewer/FileManager.java
===================================================================
--- trunk/Jmol/src/org/jmol/viewer/FileManager.java     2016-09-15 03:14:17 UTC 
(rev 21245)
+++ trunk/Jmol/src/org/jmol/viewer/FileManager.java     2016-09-19 01:10:23 UTC 
(rev 21246)
@@ -882,7 +882,8 @@
     }
     if (!vwr.isJS && image != null && bytes != null)
       nameOrError = ";base64," + Base64.getBase64(bytes).toString();
-    if (!vwr.isJS || isPopupImage && nameOrError == null)
+    if (!vwr.isJS || isPopupImage && nameOrError == null
+        || !isPopupImage && image != null)
       return vwr.loadImageData(image, nameOrError, echoName, null);
     return isAsynchronous;
     // JSmol will call that from awtjs2d.Platform.java asynchronously

Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties
===================================================================
--- trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2016-09-15 03:14:17 UTC 
(rev 21245)
+++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2016-09-19 01:10:23 UTC 
(rev 21246)
@@ -47,8 +47,13 @@
  -- sets the echo offset to a specific screen pixel offset
  -- TODO not saved in state
  
-Jmol.___JmolVersion="14.7.2_2016.09.14"
+Jmol.___JmolVersion="14.7.3_2016.09.18"
 
+new feature: show chemical formula reads formula from CIF
+
+bug fix: write MENU broken for non-English language (UTF-8 strings not 
correctly encoded using base64)
+bug fix: write PNGJ should not store "#_DOCACHE_" in PNGJ file
+bug fix: JSmol echo image loading from PNGJ can fail
 bug fix: load "" after pasting in structure to load fails
 
 JmolVersion="14.7.2_2016.09.12"

Modified: trunk/Jmol/src/org/jmol/viewer/OutputManager.java
===================================================================
--- trunk/Jmol/src/org/jmol/viewer/OutputManager.java   2016-09-15 03:14:17 UTC 
(rev 21245)
+++ trunk/Jmol/src/org/jmol/viewer/OutputManager.java   2016-09-19 01:10:23 UTC 
(rev 21246)
@@ -934,6 +934,7 @@
             .replaceAllCharacters(name, "/:?\"'=&", "_") : FileManager
             .stripPath(name));
         newName = PT.replaceAllCharacters(newName, "[]", "_");
+        newName = PT.rep(newName, "#_DOCACHE_", "");
         boolean isSparDir = (fm.spardirCache != null && fm.spardirCache
             .containsKey(name));
         if (isLocal && name.indexOf("|") < 0 && !isSparDir) {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to