Revision: 5224
Author:   hansonr
Date:     2006-06-14 14:10:07 -0700 (Wed, 14 Jun 2006)
ViewCVS:  http://svn.sourceforge.net/jmol/?rev=5224&view=rev

Log Message:
-----------
bob200603 measures -- better logic; code cleanup

Modified Paths:
--------------
    branches/bob200603/Jmol/src/org/jmol/viewer/Measures.java
Modified: branches/bob200603/Jmol/src/org/jmol/viewer/Measures.java
===================================================================
--- branches/bob200603/Jmol/src/org/jmol/viewer/Measures.java   2006-06-14 
18:03:21 UTC (rev 5223)
+++ branches/bob200603/Jmol/src/org/jmol/viewer/Measures.java   2006-06-14 
21:10:07 UTC (rev 5224)
@@ -50,14 +50,84 @@
     font3d = g3d.getFont3D(JmolConstants.MEASURE_DEFAULT_FONTSIZE);
   }
 
-  void clear() {
+  void setSize(int size, BitSet bsSelected) {
+    mad = (short)size;
+  }
+
+  void setProperty(String propertyName, Object value,
+                          BitSet bsSelected){
+   //System.out.println("Measures " + propertyName  + " " + value);
+    if ("color".equals(propertyName)) {
+      colix = (value == null ? 0 : Graphics3D.getColix(value));
+      for (int i = 0; i < measurements.length; i++)
+        if (measurements[i] != null 
+            && (colix == 0 || measurements[i].colix == 0))
+            measurements[i].colix = colix;
+      return; 
+    }
+    if ("font".equals(propertyName))
+      { font3d = (Font3D)value; }
+    else if ("delete".equals(propertyName))
+      { delete(value); }
+    else if ("toggle".equals(propertyName))
+      { toggle((int[])value); }
+    else if ("deleteVector".equals(propertyName))
+      { define((Vector)value, true, false, false); }
+    else if ("defineVector".equals(propertyName))
+      { define((Vector)value, false, false, false); }
+    else if ("showVector".equals(propertyName))
+      { define((Vector)value, false, true, false); }
+    else if ("hideVector".equals(propertyName))
+      { define((Vector)value, false, false, true); }
+    else if ("setRange".equals(propertyName))
+      { setRange((float[])value); }
+    else if ("setConnected".equals(propertyName))
+      { setConnected(((Boolean)value).booleanValue()); }
+    else if ("pending".equals(propertyName))
+      { pending((int[])value); }
+    else if ("clear".equals(propertyName))
+      { clear(); }
+    else if ("hideAll".equals(propertyName))
+      { showHide(((Boolean)value).booleanValue()); }
+    else if ("show".equals(propertyName))
+      { showHide((int[])value, false); }
+    else if ("hide".equals(propertyName))
+      { showHide((int[])value, true); }
+    else if ("showMeasurementNumbers".equals(propertyName))
+      { showMeasurementNumbers = ((Boolean)value).booleanValue(); }
+    else if ("reformatDistances".equals(propertyName))
+      { reformatDistances(); }
+  }
+
+  Object getProperty(String property, int index) {
+    //System.out.println("Measures.getProperty(" +property + "," + index +")");
+    if ("count".equals(property))
+      { return new Integer(measurementCount); }
+    if ("countPlusIndices".equals(property)) {
+      return index < measurementCount
+        ? measurements[index].countPlusIndices : null;
+    }
+    if ("stringValue".equals(property)) {
+      return index < measurementCount
+        ? measurements[index].strMeasurement : null;
+    }
+    if ("info".equals(property)) {
+      return getAllInfo();
+    }
+    if ("infostring".equals(property)) {
+      return getAllInfoAsString();
+    }
+    return null;
+  }
+
+  private void clear() {
     int countT = measurementCount;
     measurementCount = 0;
     for (int i = countT; --i >= 0; )
       measurements[i] = null;
   }
 
-  int defined(int[] atomCountPlusIndices) {
+  private int defined(int[] atomCountPlusIndices) {
     for (int i = measurementCount; --i >= 0; ) {
       if (measurements[i].sameAs(atomCountPlusIndices))
         return i;
@@ -65,33 +135,24 @@
     return -1;
   }
 
-  void toggle(int[] atomCountPlusIndices) {
+  private void toggle(int[] atomCountPlusIndices) {
     rangeMinMax[0] = Float.MAX_VALUE;
-    if (defined(atomCountPlusIndices) >= 0)
-      define(atomCountPlusIndices, true, false, false);
-    else
-      define(atomCountPlusIndices, false, false, false);
+    //toggling one that is hidden should be interpreted as DEFINE
+    int i = defined(atomCountPlusIndices);
+    if (i >= 0 && !measurements[i].isHidden) // delete it
+      define(atomCountPlusIndices, true, false);
+    else // define OR turn on if measureAllModels
+      define(atomCountPlusIndices, false, true);
   }
 
-  void define(int[] atomCountPlusIndices) {
-    define(atomCountPlusIndices, false, false, false);
+  private void delete(Object value) {
+    if (value instanceof int[])
+      define((int[])value, true, false);
+    else if (value instanceof Integer)
+      define(measurements[((Integer)value).intValue()].countPlusIndices, true, 
false);
   }
-  
-  void define(int[] atomCountPlusIndices, boolean isDelete, boolean isShow, 
boolean isHide) {
-    if (viewer.getMeasureAllModelsFlag()) {
-      Vector measureList = new Vector();
-      int nPoints = atomCountPlusIndices[0];
-      for (int i = 1; i <= nPoints; i++) {
-        Atom atom = frame.atoms[atomCountPlusIndices[i]];
-        measureList.add(viewer.getAtomBits("atomno", atom.getAtomNumber()));
-      }
-      define(measureList, isDelete, isShow, isHide);
-      return;
-    }    
-    defineOnly(atomCountPlusIndices, isDelete);
-  }
-  
-  void define(Vector monitorExpressions, boolean isDelete, boolean isShow, 
boolean isHide) {
+ 
+  private void define(Vector monitorExpressions, boolean isDelete, boolean 
isShow, boolean isHide) {
     /*
      * sets up measures based on an array of atom selection expressions -RMH 
3/06
      * 
@@ -111,37 +172,84 @@
         isOneToOne = false;
     int[] atomCountPlusIndices = new int[5];
     atomCountPlusIndices[0] = nPoints;
-    //System.out.println("measure define "+ nPoints + " " + isOneToOne);
     nextMeasure(0, nPoints, monitorExpressions, atomCountPlusIndices,
         isOneToOne ? -1 : 0, isDelete, isShow, isHide);
   }
 
-  void showHide(int[] atomCountPlusIndices, boolean isHide) {
+  private void define(int[] atomCountPlusIndices, boolean isDelete, boolean 
isShow) {
+    if (viewer.getMeasureAllModelsFlag()) {
+      if (isShow) { // make sure all like this are deleted, not just hidden
+        define(atomCountPlusIndices, true, false); // self-reference
+        if (isDelete)
+          return;
+      }
+      Vector measureList = new Vector();
+      int nPoints = atomCountPlusIndices[0];
+      for (int i = 1; i <= nPoints; i++) {
+        Atom atom = frame.atoms[atomCountPlusIndices[i]];
+        measureList.add(viewer.getAtomBits("atomno", atom.getAtomNumber()));
+      }
+      define(measureList, isDelete, false, false);
+      return;
+    }    
+    define(atomCountPlusIndices, isDelete);
+  }
+
+  private void define(int[] atomCountPlusIndices, boolean isDelete) {
     int i = defined(atomCountPlusIndices);
+    //System.out.println("define " + isDelete + " " + i + " [" + 
atomCountPlusIndices[0] + " " + atomCountPlusIndices[1] + " " + 
atomCountPlusIndices[2] + " " + atomCountPlusIndices[3] + " " + 
atomCountPlusIndices[4] + "]");
+    if (i < 0 && isDelete)
+      return;
+    float value;
+    value = frame.getMeasurement(atomCountPlusIndices);
+    if (rangeMinMax[0] != Float.MAX_VALUE
+        && (value < rangeMinMax[0] || value > rangeMinMax[1]))
+      return;
+    if (i >= 0) {
+      if (isDelete) {
+        viewer.setStatusNewDefaultModeMeasurement("measureDeleted", i, "");
+        System.arraycopy(measurements, i + 1, measurements, i, measurementCount
+            - i - 1);
+        --measurementCount;
+        measurements[measurementCount] = null;
+      } else {
+        measurements[i].isHidden = false;
+      }
+      return;
+    }
+    Measurement measureNew = new Measurement(frame, atomCountPlusIndices,
+        value, colix);
+    if (measurementCount == measurements.length) {
+      measurements = (Measurement[]) Util.setLength(measurements,
+          measurementCount + measurementGrowthIncrement);
+    }
+    viewer.setStatusNewDefaultModeMeasurement("measureCompleted",
+        measurementCount, measureNew.toVector().toString());
+    measurements[measurementCount++] = measureNew;
+  }
+
+  private void showHide(int[] atomCountPlusIndices, boolean isHide) {
+    int i = defined(atomCountPlusIndices);
     if (i < 0)
       return;
     measurements[i].isHidden = isHide;
   }
   
-  void showHide(boolean isHide) {
+  private void showHide(boolean isHide) {
     for (int i = measurementCount; --i >= 0; )
       measurements[i].isHidden = isHide;
   }
 
-  void nextMeasure(int thispt, int nPoints, Vector monitorExpressions,
+  private void nextMeasure(int thispt, int nPoints, Vector monitorExpressions,
                    int[] atomCountPlusIndices, int thisModel, boolean isDelete,
                    boolean isShow, boolean isHide) {
     BitSet bs = (BitSet) monitorExpressions.get(thispt);
-    //System.out.println("nextMeasure" + thispt + " acpi:" + 
atomCountPlusIndices
-    //+ " " + isDelete);
-    //System.out.println("bs "+ bs);
     int iMax = bs.size();
     for (int i = 0; i < iMax; i++) {
       if (bs.get(i)) {
         if (thispt > 0 && i == atomCountPlusIndices[thispt])
           continue;
         int modelIndex = frame.atoms[i].getModelIndex();
-        //System.out.println("nextMeasure i "+i+" modelIndex:"+modelIndex + " 
thismodel = "+thisModel);
         if (thisModel >= 0) {
           if (thispt == 0) {
             thisModel = modelIndex;
@@ -154,14 +262,14 @@
           if (isAllConnected && !isConnected(atomCountPlusIndices))
             continue;
           if (defined(atomCountPlusIndices) >= 0) {
-            if (isHide || isShow)
+            if (isDelete)
+              define(atomCountPlusIndices, true);
+            else
               showHide(atomCountPlusIndices, isHide);
-            else if (isDelete)
-              defineOnly(atomCountPlusIndices, true);
             continue;
           }
           if (!isDelete && !isHide && !isShow)
-            defineOnly(atomCountPlusIndices, false);
+            define(atomCountPlusIndices, false);
           continue;
         }
         nextMeasure(thispt + 1, nPoints, monitorExpressions,
@@ -170,7 +278,7 @@
     }
   }
     
-  boolean isConnected(int[] atomCountPlusIndices) {
+  private boolean isConnected(int[] atomCountPlusIndices) {
     Atom[] atoms = frame.atoms;
     for (int i = atomCountPlusIndices[0]; i > 1; --i)
       if 
(!atoms[atomCountPlusIndices[i]].isBonded(atoms[atomCountPlusIndices[i-1]]))
@@ -178,156 +286,28 @@
     return true;
   }
   
-  void defineOnly(int[] atomCountPlusIndices, boolean isDelete) {
-    float value = frame.getMeasurement(atomCountPlusIndices);
-    //System.out.println("measures define value,maxmin "+value+" 
"+rangeMinMax[0]+" "+rangeMinMax[1] + " " + isDelete);
-    
-    if (rangeMinMax[0] != Float.MAX_VALUE) {
-      if (value < rangeMinMax[0] || value > rangeMinMax[1])
-        return;
-    }
-
-    if (defined(atomCountPlusIndices) >= 0) {
-      if(isDelete)
-        delete(atomCountPlusIndices);
-      return;
-    }
-    if (isDelete)
-      return;
-    
-    //System.out.println("define " + rangeMinMax[0] + "-" + rangeMinMax[1] + 
";" + value);
-    Measurement measureNew = new Measurement(frame, atomCountPlusIndices, 
value, colix);
-    if (measurementCount == measurements.length) {
-      measurements =(Measurement[])Util.setLength(measurements,
-                                                  measurementCount +
-                                                  measurementGrowthIncrement);
-    }
-    viewer.setStatusNewDefaultModeMeasurement("measureCompleted" , 
measurementCount, measureNew.toVector().toString());
-    measurements[measurementCount++] = measureNew;    
-  }
-
-  boolean delete(Object value) {
-    if (value instanceof int[])
-      return delete((int[])value);
-    if (value instanceof Integer)
-      return delete(((Integer)value).intValue());
-    return false;
-  }
-
-  boolean delete(int[] atomCountPlusIndices) {
-    for (int i = measurementCount; --i >= 0; ) {
-      if (measurements[i].sameAs(atomCountPlusIndices))
-        return delete(i);
-    }
-    return false;
-  }
-
-  boolean delete(int i) {
-    if (i < measurementCount) {
-      viewer.setStatusNewDefaultModeMeasurement("measureDeleted" , i, "");
-      System.arraycopy(measurements, i+1,
-                       measurements, i,
-                       measurementCount - i - 1);
-      --measurementCount;
-      measurements[measurementCount] = null;
-      return true;
-    }
-    return false;
-  }
-  
-  void setRange(float[] rangeMinMax) {
+  private void setRange(float[] rangeMinMax) {
     //System.out.println("setRange"+rangeMinMax[0]+rangeMinMax[1]);
     this.rangeMinMax[0] = rangeMinMax[0];
     this.rangeMinMax[1] = rangeMinMax[1];
   }
   
-  void setConnected(boolean isAllConnected) {
+  private void setConnected(boolean isAllConnected) {
     this.isAllConnected = isAllConnected;  
   }
   
-  void pending(int[] countPlusIndices) {
+  private void pending(int[] countPlusIndices) {
     pendingMeasurement.setCountPlusIndices(countPlusIndices);
     if (pendingMeasurement.count > 1)
       viewer.setStatusNewDefaultModeMeasurement("measurePending" , 
pendingMeasurement.count, pendingMeasurement.strMeasurement);
   }
 
-  void setSize(int size, BitSet bsSelected) {
-    mad = (short)size;
+  private void reformatDistances() {
+    for (int i = measurementCount; --i >= 0; )
+      measurements[i].reformatDistanceIfSelected();    
   }
-
-  void setProperty(String propertyName, Object value,
-                          BitSet bsSelected){
-    
-    //System.out.println("Measures " + propertyName  + " " + value);
-    if ("color".equals(propertyName)) {
-        //System.out.println("Measures.color set to:" + value);
-      colix = (value == null ? 0 : Graphics3D.getColix(value));
-      for (int i = 0; i < measurements.length; i++)
-        if (measurements[i] != null 
-            && (colix == 0 || measurements[i].colix == 0))
-            measurements[i].colix = colix;
-      return; 
-     }
-    if ("font".equals(propertyName))
-      { font3d = (Font3D)value; return; }
-    else if ("define".equals(propertyName))
-      { define((int[])value); }
-    else if ("delete".equals(propertyName))
-      { delete(value); }
-    else if ("toggle".equals(propertyName))
-    { toggle((int[])value); }
-    else if ("deleteVector".equals(propertyName))
-    { define((Vector)value, true, false, false); }
-    else if ("defineVector".equals(propertyName))
-    { define((Vector)value, false, false, false); }
-    else if ("showVector".equals(propertyName))
-    { define((Vector)value, false, true, false); }
-    else if ("hideVector".equals(propertyName))
-    { define((Vector)value, false, false, true); }
-    else if ("setRange".equals(propertyName))
-    { setRange((float[])value); }
-    else if ("setConnected".equals(propertyName))
-    { setConnected(((Boolean)value).booleanValue()); }
-    else if ("pending".equals(propertyName))
-      { pending((int[])value); }
-    else if ("clear".equals(propertyName))
-      { clear(); }
-    else if ("hideAll".equals(propertyName))
-    { showHide(((Boolean)value).booleanValue()); }
-    else if ("show".equals(propertyName))
-    { showHide((int[])value, false); }
-    else if ("hide".equals(propertyName))
-    { showHide((int[])value, true); }
-    else if ("showMeasurementNumbers".equals(propertyName))
-      { showMeasurementNumbers = ((Boolean)value).booleanValue(); }
-    else if ("reformatDistances".equals(propertyName))
-      { reformatDistances(); }
-    else
-      return;
-  }
-
-  Object getProperty(String property, int index) {
-    //System.out.println("Measures.getProperty(" +property + "," + index +")");
-    if ("count".equals(property))
-      { return new Integer(measurementCount); }
-    if ("countPlusIndices".equals(property)) {
-      return index < measurementCount
-        ? measurements[index].countPlusIndices : null;
-    }
-    if ("stringValue".equals(property)) {
-      return index < measurementCount
-        ? measurements[index].strMeasurement : null;
-    }
-    if ("info".equals(property)) {
-      return getAllInfo();
-    }
-    if ("infostring".equals(property)) {
-      return getAllInfoAsString();
-    }
-    return null;
-  }
-
-  Vector getAllInfo() {
+  
+  private Vector getAllInfo() {
     Vector info = new Vector();
     for (int i = 0; i< measurementCount; i++) {
       info.add(getInfo(i));
@@ -335,7 +315,7 @@
     return info;
   }
   
-  String getAllInfoAsString() {
+  private String getAllInfoAsString() {
     String info = "Measurement Information";
     for (int i = 0; i< measurementCount; i++) {
       info += "\n" + getInfoAsString(i);
@@ -343,7 +323,7 @@
     return info;
   }
   
-  Hashtable getInfo(int index) {
+  private Hashtable getInfo(int index) {
     int count = measurements[index].count;
     Hashtable info = new Hashtable();
     info.put("index", new Integer(index));
@@ -365,7 +345,7 @@
     return info;
   }
 
-  String getInfoAsString(int index) {
+  private String getInfoAsString(int index) {
     int count = measurements[index].count;
     String info = (count == 2 ? "distance" : count == 3 ? "angle" : "dihedral")
         + " \t" + measurements[index].value + " \t"
@@ -377,11 +357,6 @@
     return info;
   }
   
-  void reformatDistances() {
-    for (int i = measurementCount; --i >= 0; )
-      measurements[i].reformatDistanceIfSelected();    
-  }
-  
   void setVisibilityInfo() {
     out:
     for (int i = measurementCount; --i >= 0; ) {


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



_______________________________________________
Jmol-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to