1 /* $RCSfile$
2  * $Author: hansonr $
3  * $Date: 2013-12-11 16:07:42 -0600 (Wed, 11 Dec 2013) $
4  * $Revision: 19081 $
5  *
6  * Copyright (C) 2002-2005  The Jmol Development Team
7  *
8  * Contact: jmol-developers@lists.sf.net
9  *
10  *  This library is free software; you can redistribute it and/or
11  *  modify it under the terms of the GNU Lesser General Public
12  *  License as published by the Free Software Foundation; either
13  *  version 2.1 of the License, or (at your option) any later version.
14  *
15  *  This library is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  *  Lesser General Public License for more details.
19  *
20  *  You should have received a copy of the GNU Lesser General Public
21  *  License along with this library; if not, write to the Free Software
22  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 package org.jmol.modelset;
25 
26 import org.jmol.util.Point3fi;
27 
28 public class MeasurementPending extends Measurement {
29 
30   /*
31    * a class to maintain the pending measurement after
32    * the user initiates this with a mouse action
33    *
34    */
35   public boolean haveTarget;
36   public boolean haveModified;
37   public int numSet = 0;
38 
set(ModelSet modelSet)39   public MeasurementPending set(ModelSet modelSet) {
40     return (MeasurementPending) setM(modelSet, null, Float.NaN, (short) 0,
41         null, 0);
42   }
43 
checkPoint(Point3fi ptClicked)44   private boolean checkPoint(Point3fi ptClicked) {
45     for (int i = 1; i <= numSet; i++)
46       if (countPlusIndices[i] == -1 - i
47           && pts[i - 1].distance(ptClicked) < 0.01)
48         return false;
49     return true;
50   }
51 
getIndexOf(int atomIndex)52   public int getIndexOf(int atomIndex) {
53     for (int i = 1; i <= numSet; i++)
54       if (countPlusIndices[i] == atomIndex)
55         return i;
56     return 0;
57   }
58 
59   @Override
setCount(int count)60   public void setCount(int count) {
61     setCountM(count);
62     numSet = count;
63   }
64 
65   private int lastIndex = -1;
66 
addPoint(int atomIndex, Point3fi ptClicked, boolean doSet)67   synchronized public int addPoint(int atomIndex, Point3fi ptClicked, boolean doSet) {
68     haveModified = (atomIndex != lastIndex);
69     lastIndex = atomIndex;
70     if (ptClicked == null) {
71       if (getIndexOf(atomIndex) > 0) {
72         if (doSet)
73           numSet = count;
74         return count;
75       }
76       haveTarget = (atomIndex >= 0);
77       if (!haveTarget)
78         return count = numSet;
79       count = numSet + 1;
80       countPlusIndices[count] = atomIndex;
81     } else {
82       if (!checkPoint(ptClicked)) {
83         if (doSet)
84           numSet = count;
85         return count;
86       }
87       int pt = numSet;
88       haveModified = haveTarget = true;
89       count = numSet + 1;
90       pts[pt] = ptClicked;
91       countPlusIndices[count] = -2 - pt;
92     }
93     countPlusIndices[0] = count;
94     if (doSet)
95       numSet = count;
96     value = getMeasurement(null);
97     strFormat = null;
98     formatMeasurement(null);
99     return count;
100   }
101 
102 }
103