Revision: 20423
          http://sourceforge.net/p/jmol/code/20423
Author:   hansonr
Date:     2015-04-01 11:26:34 +0000 (Wed, 01 Apr 2015)
Log Message:
-----------
Jmol.___JmolVersion="14.3.13_2015.04.01" 

new feature: draw polygon [@1 @2 @3...]
  -- fills polygon with triangles
  -- order is important -- must be in order cw or ccw
  -- example:
    
                load $caffeine
                draw polygon [@5 @7 @12 @13 @1 @3]

new feature: ".[a]" notation extended to x.. and allows mixing with .a.
        function a(){return 1}
        x = [A:[1,2,3], a:[4,5,6]] 
        $ print x.a.[a()]
         4
        $ print x..a..[a()]
         4
        $ print x.a..[a()]
         4
        $ print x..a..[a()]
         4
        $ print x..a.[a()]
         4
        $ y = x.a[1][2]; show y
         y = [ 4,5 ]
  

Modified Paths:
--------------
    trunk/Jmol/src/org/jmol/script/ScriptCompiler.java
    trunk/Jmol/src/org/jmol/script/ScriptTokenParser.java
    trunk/Jmol/src/org/jmol/scriptext/IsoExt.java
    trunk/Jmol/src/org/jmol/util/MeshCapper.java
    trunk/Jmol/src/org/jmol/viewer/Jmol.properties

Modified: trunk/Jmol/src/org/jmol/script/ScriptCompiler.java
===================================================================
--- trunk/Jmol/src/org/jmol/script/ScriptCompiler.java  2015-03-31 22:34:43 UTC 
(rev 20422)
+++ trunk/Jmol/src/org/jmol/script/ScriptCompiler.java  2015-04-01 11:26:34 UTC 
(rev 20423)
@@ -1302,8 +1302,12 @@
     T token;
 
     if (isDotDot) {
-      addTokenToPrefix(T.o(T.string, ident));
-      addTokenToPrefix(T.tokenArrayClose);
+      if (theTok == T.leftsquare) {
+        bracketCount++;
+      } else {
+        addTokenToPrefix(T.o(T.string, ident));
+        addTokenToPrefix(T.tokenArrayClose);
+      }
       isDotDot = false;
       return CONTINUE;
     }

Modified: trunk/Jmol/src/org/jmol/script/ScriptTokenParser.java
===================================================================
--- trunk/Jmol/src/org/jmol/script/ScriptTokenParser.java       2015-03-31 
22:34:43 UTC (rev 20422)
+++ trunk/Jmol/src/org/jmol/script/ScriptTokenParser.java       2015-04-01 
11:26:34 UTC (rev 20423)
@@ -359,7 +359,7 @@
       return false;
     if (logMessages)
         Logger.debug("addTokenToPostfix" + token);
-    if (token.tok == T.leftsquare && lastToken.tok == T.per) {
+    if (token.tok == T.leftsquare && (lastToken.tok == T.per || lastToken.tok 
== T.perper)) {
       // new notation
       int ipt = ltokenPostfix.size() - 1;
       ltokenPostfix.remove(ipt);
@@ -382,6 +382,11 @@
           }
           break;
         default:
+          tok2 = (i == 0 ? T.nada : ltokenPostfix.get(i - 1).tok);
+          if (tok2 == T.per || tok2 == T.perper) {
+            ipt = i - 1;
+            break;
+          }
           if (i == ipt - 1) {
             ipt = i;
             pcount = -10;

Modified: trunk/Jmol/src/org/jmol/scriptext/IsoExt.java
===================================================================
--- trunk/Jmol/src/org/jmol/scriptext/IsoExt.java       2015-03-31 22:34:43 UTC 
(rev 20422)
+++ trunk/Jmol/src/org/jmol/scriptext/IsoExt.java       2015-04-01 11:26:34 UTC 
(rev 20423)
@@ -47,6 +47,7 @@
 import org.jmol.util.C;
 import org.jmol.util.ColorEncoder;
 import org.jmol.util.Escape;
+import org.jmol.util.MeshCapper;
 import org.jmol.util.Parser;
 
 import javajs.J2SIgnoreImport;
@@ -263,7 +264,8 @@
       if (tokAt(pt) == T.scale)
         scale = floatParameter(++pt);
       if (!chk)
-        eval.runScript(vwr.ms.getPointGroupAsString(vwr.bsA(), true, type, 
index, scale));
+        eval.runScript(vwr.ms.getPointGroupAsString(vwr.bsA(), true, type,
+            index, scale));
       return false;
     case T.helix:
     case T.quaternion:
@@ -374,30 +376,37 @@
           for (int j = 0; j < nVertices; j++)
             points[j] = centerParameter(++eval.iToken);
         }
-        switch (getToken(++eval.iToken).tok) {
-        case T.matrix3f:
-        case T.matrix4f:
-          SV sv = SV.newT(eval.theToken);
-          sv.toArray();
-          vpolygons = sv.getList();
-          nTriangles = vpolygons.size();
-          break;
-        case T.varray:
-          vpolygons = ((SV) eval.theToken).getList();
-          nTriangles = vpolygons.size();
-          break;
-        default:
-          nTriangles = Math.max(0, intParameter(eval.iToken));
+        int[][] polygons;
+        if (slen == ++eval.iToken) {
+          if (chk)
+            return false;
+          polygons = ((MeshCapper) 
Interface.getInterface("org.jmol.util.MeshCapper", vwr, 
"script")).set(null).triangulatePolygon(points);
+        } else {
+          switch (getToken(eval.iToken).tok) {
+          case T.matrix3f:
+          case T.matrix4f:
+            SV sv = SV.newT(eval.theToken);
+            sv.toArray();
+            vpolygons = sv.getList();
+            nTriangles = vpolygons.size();
+            break;
+          case T.varray:
+            vpolygons = ((SV) eval.theToken).getList();
+            nTriangles = vpolygons.size();
+            break;
+          default:
+            nTriangles = Math.max(0, intParameter(eval.iToken));
+          }
+          polygons = AU.newInt2(nTriangles);
+          for (int j = 0; j < nTriangles; j++) {
+            float[] f = (vpolygons == null ? eval.floatParameterSet(
+                ++eval.iToken, 3, 4) : SV.flistValue(vpolygons.get(j), 0));
+            if (f.length < 3 || f.length > 4)
+              invArg();
+            polygons[j] = new int[] { (int) f[0], (int) f[1], (int) f[2],
+                (f.length == 3 ? 7 : (int) f[3]) };
+          }
         }
-        int[][] polygons = AU.newInt2(nTriangles);
-        for (int j = 0; j < nTriangles; j++) {
-          float[] f = (vpolygons == null ? eval.floatParameterSet(
-              ++eval.iToken, 3, 4) : SV.flistValue(vpolygons.get(j), 0));
-          if (f.length < 3 || f.length > 4)
-            invArg();
-          polygons[j] = new int[] { (int) f[0], (int) f[1], (int) f[2],
-              (f.length == 3 ? 7 : (int) f[3]) };
-        }
         if (nVertices > 0) {
           v.addLast(points);
           v.addLast(polygons);
@@ -442,10 +451,11 @@
         }
         eval.checkLast(eval.iToken);
         if (!chk) {
-          String s = (String) 
vwr.ms.getSymTemp(false).getSymmetryInfoAtom(vwr.ms, bsAtoms, xyz, iSym,
-              center, target, thisId, T.draw);
+          String s = (String) vwr.ms.getSymTemp(false).getSymmetryInfoAtom(
+              vwr.ms, bsAtoms, xyz, iSym, center, target, thisId, T.draw);
           showString(s.substring(0, s.indexOf('\n') + 1));
-          eval.runScript(s.length() > 0 ? s : "draw ID \"sym_" + thisId + "*\" 
delete");
+          eval.runScript(s.length() > 0 ? s : "draw ID \"sym_" + thisId
+              + "*\" delete");
         }
         return false;
       case T.frame:

Modified: trunk/Jmol/src/org/jmol/util/MeshCapper.java
===================================================================
--- trunk/Jmol/src/org/jmol/util/MeshCapper.java        2015-03-31 22:34:43 UTC 
(rev 20422)
+++ trunk/Jmol/src/org/jmol/util/MeshCapper.java        2015-04-01 11:26:34 UTC 
(rev 20423)
@@ -82,13 +82,15 @@
    */
   private int nTriangles, nRegions;
 
+  private Lst<int[]> lstTriangles;
+
   /////////////// initialization //////////////////
 
   /**
    * @param slicer
    * @return this
    */
-  MeshCapper set(MeshSlicer slicer) {
+  public MeshCapper set(MeshSlicer slicer) {
     // resolution has not been necessary
     this.slicer = slicer;
     dumping = Logger.debugging;
@@ -101,6 +103,33 @@
   }
 
   /**
+   * generic entry for a polygon
+   * 
+   * @param points
+   * @return int[][i j k 7]
+   */
+  public int[][] triangulatePolygon(P3[] points) {
+    clear();
+    
+    int n = points.length;
+    CapVertex v0 = null;
+    for (int i = 0; i < n; i++) {
+      CapVertex v = new CapVertex(points[i], i);
+      vertices.addLast(v);
+      if (v0 != null)
+        v.link(v0);
+      v0 = v;
+    }
+    vertices.get(0).link(v0);
+    lstTriangles = new Lst<int[]>();
+    createCap(null);
+    int[][] a = new int[lstTriangles.size()][];
+    for (int i = lstTriangles.size(); --i >= 0;)
+      a[i] = lstTriangles.get(i);
+    return a;
+  }
+
+  /**
    * Input method from MeshSlicer. Pointers are into MeshSlicer.m.vs[]
    * 
    * @param ipt1
@@ -147,7 +176,7 @@
    * @return external point or test point
    */
   private T3 getInputPoint(CapVertex v) {
-    return (testing ? P3.newP(v) : slicer.m.vs[v.ipt]);
+    return (slicer == null ? P3.newP(v) : slicer.m.vs[v.ipt]);
   }
 
   /**
@@ -158,7 +187,10 @@
    * @param ipt3
    */
   private void outputTriangle(int ipt1, int ipt2, int ipt3) {
-    slicer.addTriangle(ipt1, ipt2, ipt3);
+    if (slicer == null)
+      lstTriangles.addLast(new int[] { ipt1, ipt2, ipt3, 7 });
+    else
+      slicer.addTriangle(ipt1, ipt2, ipt3);
   }
 
   private CapVertex[] test(CapVertex[] vs) {
@@ -207,8 +239,13 @@
     // to give best precision
 
     V3 vab = V3.newVsub(vertices.get(0), vertices.get(1));
-    V3 vac = V3.newV(norm);
-    vac.cross(vac, vab);
+    V3 vac;
+    if (norm == null) {
+      vac = V3.newVsub(vertices.get(vertices.size() - 1), vertices.get(0));
+    } else {
+      vac = V3.newV(norm);
+      vac.cross(vac, vab);
+    }
 
     //Get xy plane points
     Quat q = Quat.getQuaternionFrameV(vab, vac, null, false);
@@ -237,10 +274,15 @@
     // scan the plane
 
     CapVertex v = v0;
+    try {
     do {
       v = process(v);
     } while (v != v0);
-    clear();
+    } catch (Exception e) {
+      System.out.println("MeshCapper exception " + e);
+    }
+    if (slicer != null)
+      clear();
     Logger.info("MeshCapper created " + nTriangles + " triangles " + nRegions
         + " regions");
 
@@ -316,8 +358,9 @@
         // end vertex -- draw last triangle
         lstRegions.removeObj(v.region);
         addTriangle(v.prev, v, v.next, "end");
-        v.prev.clear();
-        v.next.clear();
+        
+        clearV(v.prev);
+        clearV(v.next);
       } else {
         // merge vertex -- linking two separate regions
         // just mark as having no region yet
@@ -328,6 +371,11 @@
     return q;
   }
 
+  private static void clearV(CapVertex v) {
+    if (v != null)
+      v.clear();
+  }
+
   /**
    * Process a standard monotonic region, cleaving off as many triangles as
    * possible.
@@ -825,8 +873,9 @@
           + " "
           + z
           + "} # "
-          + (prev == null ? null : (prev.id + " " + next.id)
-              + (region == null ? null : dumpRegion()));
+          + (prev == null ? "" : prev.id)
+          + (next == null ? "" : " " + next.id)
+              + (region == null ? "" : dumpRegion());
     }
 
   }

Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties
===================================================================
--- trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2015-03-31 22:34:43 UTC 
(rev 20422)
+++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2015-04-01 11:26:34 UTC 
(rev 20423)
@@ -14,8 +14,34 @@
 
 TODO: remove HTML5 dependency on synchronous file loading (check SCRIPT 
command for problems)
 
-Jmol.___JmolVersion="14.3.13_2015.03.30" 
+Jmol.___JmolVersion="14.3.13_2015.04.01" 
 
+new feature: draw polygon [@1 @2 @3...]
+  -- fills polygon with triangles
+  -- order is important -- must be in order cw or ccw
+  -- example:
+    
+               load $caffeine
+               draw polygon [@5 @7 @12 @13 @1 @3]
+
+new feature: ".[a]" notation extended to x.. and allows mixing with .a.
+       function a(){return 1}
+       x = [A:[1,2,3], a:[4,5,6]] 
+       $ print x.a.[a()]
+        4
+       $ print x..a..[a()]
+        4
+       $ print x.a..[a()]
+        4
+       $ print x..a..[a()]
+        4
+       $ print x..a.[a()]
+        4
+       $ y = x.a[1][2]; show y
+        y = [ 4,5 ]
+  
+JmolVersion="14.3.13_2015.03.30" 
+
 bug fix: {hash}.Key = value will be stored as "key" rather than "Key" if "key" 
is also a user-defined function.
 bug fix: {hash}.key will fail if "key" is also a user-defined function. 
 bug fix: print a  where a is an associative arrays fails in JavaScript (since 
jmol-14.3.7_2014.08.25) 

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


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to