You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
(35) |
May
(67) |
Jun
(2) |
Jul
|
Aug
(12) |
Sep
(54) |
Oct
(91) |
Nov
(168) |
Dec
(100) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(209) |
Feb
(158) |
Mar
(19) |
Apr
(24) |
May
(184) |
Jun
(134) |
Jul
(54) |
Aug
(399) |
Sep
(218) |
Oct
(271) |
Nov
(207) |
Dec
(126) |
2004 |
Jan
(138) |
Feb
(249) |
Mar
(420) |
Apr
(100) |
May
(335) |
Jun
(143) |
Jul
(91) |
Aug
(129) |
Sep
(98) |
Oct
(170) |
Nov
(352) |
Dec
(355) |
2005 |
Jan
(256) |
Feb
(158) |
Mar
(163) |
Apr
(38) |
May
(217) |
Jun
(98) |
Jul
(213) |
Aug
(169) |
Sep
(260) |
Oct
(94) |
Nov
(87) |
Dec
(153) |
2006 |
Jan
(35) |
Feb
(176) |
Mar
(308) |
Apr
(168) |
May
(152) |
Jun
(67) |
Jul
(99) |
Aug
(90) |
Sep
(313) |
Oct
(266) |
Nov
(282) |
Dec
(189) |
2007 |
Jan
(118) |
Feb
(309) |
Mar
(289) |
Apr
(209) |
May
(268) |
Jun
(103) |
Jul
(91) |
Aug
(143) |
Sep
(146) |
Oct
(205) |
Nov
(157) |
Dec
(172) |
2008 |
Jan
(53) |
Feb
(87) |
Mar
(188) |
Apr
(99) |
May
(101) |
Jun
(91) |
Jul
(117) |
Aug
(158) |
Sep
(100) |
Oct
(221) |
Nov
(184) |
Dec
(127) |
2009 |
Jan
(64) |
Feb
(93) |
Mar
(60) |
Apr
(74) |
May
(76) |
Jun
(218) |
Jul
(130) |
Aug
(115) |
Sep
(142) |
Oct
(76) |
Nov
(160) |
Dec
(181) |
2010 |
Jan
(229) |
Feb
(231) |
Mar
(184) |
Apr
(243) |
May
(229) |
Jun
(204) |
Jul
(293) |
Aug
(370) |
Sep
(160) |
Oct
(164) |
Nov
(163) |
Dec
(161) |
2011 |
Jan
(145) |
Feb
(147) |
Mar
(117) |
Apr
(43) |
May
(102) |
Jun
(152) |
Jul
(204) |
Aug
(98) |
Sep
(162) |
Oct
(216) |
Nov
(107) |
Dec
(98) |
2012 |
Jan
(53) |
Feb
(131) |
Mar
(105) |
Apr
(109) |
May
(155) |
Jun
(88) |
Jul
(82) |
Aug
(69) |
Sep
(96) |
Oct
(83) |
Nov
(71) |
Dec
(50) |
2013 |
Jan
(51) |
Feb
(53) |
Mar
(81) |
Apr
(143) |
May
(75) |
Jun
(103) |
Jul
(126) |
Aug
(104) |
Sep
(73) |
Oct
(136) |
Nov
(148) |
Dec
(90) |
2014 |
Jan
(82) |
Feb
(146) |
Mar
(132) |
Apr
(125) |
May
(72) |
Jun
(84) |
Jul
(35) |
Aug
(68) |
Sep
(49) |
Oct
(54) |
Nov
(58) |
Dec
(15) |
2015 |
Jan
(76) |
Feb
(82) |
Mar
(74) |
Apr
(49) |
May
(48) |
Jun
(48) |
Jul
(57) |
Aug
(66) |
Sep
(45) |
Oct
(52) |
Nov
(18) |
Dec
(33) |
2016 |
Jan
(26) |
Feb
(27) |
Mar
(60) |
Apr
(30) |
May
(51) |
Jun
(25) |
Jul
(12) |
Aug
(47) |
Sep
(11) |
Oct
(26) |
Nov
(9) |
Dec
(27) |
2017 |
Jan
(44) |
Feb
(34) |
Mar
(22) |
Apr
(108) |
May
(42) |
Jun
(17) |
Jul
(38) |
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
2018 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2019 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2020 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2021 |
Jan
(3) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(13) |
Aug
(39) |
Sep
(8) |
Oct
(7) |
Nov
(25) |
Dec
(16) |
2022 |
Jan
(26) |
Feb
(30) |
Mar
(31) |
Apr
(16) |
May
(12) |
Jun
(7) |
Jul
(15) |
Aug
(24) |
Sep
(4) |
Oct
(10) |
Nov
(7) |
Dec
(5) |
2023 |
Jan
(7) |
Feb
(2) |
Mar
(4) |
Apr
(1) |
May
|
Jun
(3) |
Jul
(13) |
Aug
(14) |
Sep
(17) |
Oct
(3) |
Nov
(13) |
Dec
(6) |
2024 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Fabian D. <fd...@us...> - 2002-12-27 14:04:34
|
Update of /cvsroot/jmol/Jmol/samples In directory sc8-pr-cvs1:/tmp/cvs-serv31779/samples Added Files: Si_eband.out Log Message: Adding ABINIT sample file for energy band --- NEW FILE: Si_eband.out --- Version 3.4.3 of ABINIT (sequential version, prepared for a P6/Linux computer) Copyright (C) 1998-2002 ABINIT group . ABINIT comes with ABSOLUTELY NO WARRANTY. It is free software, and you are welcome to redistribute it under certain conditions (GNU General Public License, see ~ABINIT/Infos/copyright or http://www.gnu.org/copyleft/gpl.txt). ABINIT is a project of the Universite Catholique de Louvain, Corning Inc. and other collaborators, see ~ABINIT/Infos/contributors. Please read ~ABINIT/Infos/acknowledgments.htm for suggested acknowledgments of the ABINIT effort. For more information, see http://www.abinit.org . Starting date : Mon 9 Sep 2002. - input file -> ../t35.in [...975 lines suppressed...] - (-1=no count) - fourwf(pot) 21.240 56.4 21.538 56.6 9678 - nonlop(apply) 4.120 10.9 4.171 11.0 9678 - cgwf-O(npw) 2.770 7.3 2.447 6.4 -1 - getghc-other 2.750 7.3 2.832 7.4 -1 - projbd 2.350 6.2 2.528 6.6 14920 - vtowfk(ssdiag) 0.920 2.4 0.949 2.5 -1 - pspini 0.610 1.6 0.604 1.6 2 - fourwf(den) 0.390 1.0 0.408 1.1 280 - timing timab 0.380 1.0 0.376 1.0 8 - vtorho-kpt loop 0.210 0.6 0.208 0.5 8 - 39 others 1.120 3.0 1.170 3.1 - subtotal 36.860 97.8 37.231 97.8 ================================================================================ Calculation completed. Delivered 0 WARNINGs and 0 COMMENTs to log file. +Overall time at end (sec) : cpu= 37.7 wall= 38.1 |
From: Fabian D. <fd...@us...> - 2002-12-27 14:03:29
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol In directory sc8-pr-cvs1:/tmp/cvs-serv31339/src/org/openscience/jmol Added Files: TransformDialog.java Log Message: Adding a Transform dialog --- NEW FILE: TransformDialog.java --- package org.openscience.jmol; import org.openscience.jmol.render.*; import org.openscience.jmol.util.*; import javax.swing.JDialog; //DLG import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.Action; import java.util.Hashtable; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JPanel; //PNL import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Dimension; import javax.swing.JTextField; //TXF import javax.swing.JLabel; //LBL import javax.swing.border.TitledBorder; import javax.swing.JButton; //BUT import javax.vecmath.Point3d; import javax.vecmath.Vector3d; import javax.vecmath.AxisAngle4d; import javax.swing.table.AbstractTableModel; import javax.swing.JScrollPane; import java.awt.FlowLayout; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.JTable; import javax.swing.BoxLayout; import java.awt.BorderLayout; class TransformDialog extends JDialog implements ActionListener, PropertyChangeListener { protected Jmol program; private JmolModel model; private boolean hasFile; private Point3d center; private Point3d oldCenter; private Vector3d direction; private double angle; private JTextField pointTXF; private JTextField directionTXF; private JTextField angleTXF; // The actions: private TransformAction transformAction = new TransformAction(); private Hashtable commands; TransformDialog(JmolModel model, JFrame f, Jmol program) { // Invoke JDialog constructor super(f, "Transform...", false); this.model = model; commands = new Hashtable(); Action[] actions = getActions(); for (int i = 0; i < actions.length; i++) { Action a = actions[i]; commands.put(a.getValue(Action.NAME), a); } this.program=program; makeTransformDialog(); } void makeTransformDialog() { JmolResourceHandler resources = JmolResourceHandler.getInstance(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); JPanel containerPNL = new JPanel(); containerPNL.setLayout(gridbag); pointTXF = new JTextField(10); pointTXF.setText("0.0, 0.0, 0.0"); directionTXF = new JTextField(10); directionTXF.setText("1.0, 0.0, 0.0"); angleTXF = new JTextField(10); angleTXF.setText("90.0"); JPanel rotationPNL = new JPanel(); rotationPNL.setBorder(new TitledBorder (resources.getString("Transform.rotationLabel"))); rotationPNL.setLayout(gridbag); JPanel axisPNL = new JPanel(); // axisPNL.setBorder(new TitledBorder(resources //.getString("Crystprop.cartesianLabel"))); axisPNL.setBorder(new TitledBorder (resources.getString("Transform.axisLabel"))); axisPNL.setLayout(gridbag); JPanel anglePNL = new JPanel(); anglePNL.setBorder(new TitledBorder (resources.getString("Transform.anglePanelLabel"))); anglePNL.setLayout(gridbag); // axisPanel JLabel pointLBL = new JLabel (resources.getString("Transform.pointLabel")); JLabel directionLBL = new JLabel (resources.getString("Transform.directionLabel")); JButton pickPointBUT = new JButton("Pick atoms"); pickPointBUT.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //TODO } }); JButton pickDirBUT = new JButton("Pick atoms"); c.anchor = GridBagConstraints.NORTHWEST; c.fill = GridBagConstraints.NONE; c.weightx = 1; c.weighty = 1; c.gridheight = 2; //c.gridwidth = 3; c.gridwidth = 2; gridbag.setConstraints(pointLBL, c); axisPNL.add(pointLBL); c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints(pointTXF, c); axisPNL.add(pointTXF); //c.gridwidth = GridBagConstraints.REMAINDER; //gridbag.setConstraints(pickPointBUT, c); //axisPNL.add(pickPointBUT); c.gridwidth = 2; c.gridheight = GridBagConstraints.REMAINDER; gridbag.setConstraints(directionLBL, c); axisPNL.add(directionLBL); c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints(directionTXF, c); axisPNL.add(directionTXF); //c.gridwidth = GridBagConstraints.REMAINDER; //gridbag.setConstraints(pickDirBUT, c); //axisPNL.add(pickDirBUT); //anglePanel JLabel angleLBL = new JLabel (resources.getString("Transform.angleLabel")); c.gridwidth = 2; c.gridheight = GridBagConstraints.REMAINDER; gridbag.setConstraints(angleLBL, c); anglePNL.add(angleLBL); c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints(angleTXF, c); anglePNL.add(angleTXF); //rotationPanel c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight = 2; gridbag.setConstraints(axisPNL, c); rotationPNL.add(axisPNL); gridbag.setConstraints(anglePNL, c); rotationPNL.add(anglePNL); //main container c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight = 2; gridbag.setConstraints(rotationPNL, c); containerPNL.add(rotationPNL); JButton applyBUT = new JButton((resources.translate("Apply"))); applyBUT.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { center = MathUtil.arrayToPoint3d (FieldReader.readField3(pointTXF)); direction = MathUtil.arrayToVector3d (FieldReader.readField3(directionTXF)); if(direction.x==0.0f && direction.y==0.0f && direction.z==0.0f) { direction.x=1.0f; } angle = FieldReader.readField1(angleTXF); rotate(); } }); c.gridheight = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; gridbag.setConstraints(applyBUT, c); containerPNL.add(applyBUT); //Draw main container getContentPane().add(containerPNL); addWindowListener(new TransformWindowListener()); pack(); centerDialog(); } //makeTransformDialog void rotate() { //TODO program.control.setCenter(center); program.control.rotate(new AxisAngle4d(direction.x, direction.y, direction.z, (double)Math.toRadians(angle))); } public void setChemFile(ChemFile cf) { hasFile = true; transformAction.setEnabled(true); } public void close() { this.setVisible(false); transformAction.setEnabled(true); } protected void centerDialog() { Dimension screenSize = this.getToolkit().getScreenSize(); Dimension size = this.getSize(); screenSize.height = screenSize.height / 2; screenSize.width = screenSize.width / 2; size.height = size.height / 2; size.width = size.width / 2; int y = screenSize.height - size.height; int x = screenSize.width - size.width; this.setLocation(x, y); } public void actionPerformed(ActionEvent evt) { } public Action[] getActions() { Action[] defaultActions = { transformAction }; return defaultActions; } public void propertyChange(PropertyChangeEvent event) { if (event.getPropertyName().equals(JmolModel.chemFileProperty)) { setChemFile((ChemFile) event.getNewValue()); } } class TransformAction extends AbstractAction { public TransformAction() { super("transform"); //The transform dialog is available only if a file is loaded if (hasFile) { this.setEnabled(true); } else { this.setEnabled(false); } } public void actionPerformed(ActionEvent e) { //When the dialog View-->Transform is clicked, //this method is executed. //The transform dialog is no more available because already opened this.setEnabled(false); //Update the content of the dialog box //Show the dialog box show(); } } //end class TransformAction class TransformWindowListener extends WindowAdapter { public void windowClosing(WindowEvent e) { close(); } } class MeasureWindowListener extends WindowAdapter { public void windowClosing(WindowEvent e) { close(); } } } |
From: Fabian D. <fd...@us...> - 2002-12-27 14:02:45
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol In directory sc8-pr-cvs1:/tmp/cvs-serv30994/src/org/openscience/jmol Modified Files: Jmol.java Log Message: Adding a Transform dialog Index: Jmol.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/Jmol.java,v retrieving revision 1.82 retrieving revision 1.83 diff -C2 -r1.82 -r1.83 *** Jmol.java 27 Dec 2002 00:36:02 -0000 1.82 --- Jmol.java 27 Dec 2002 14:02:43 -0000 1.83 *************** *** 142,145 **** --- 142,146 ---- private CrystalPropertiesDialog crystprop; private MakeCrystal makecrystal; + private TransformDialog transform; private PropertyGraph pg; private Measure meas; *************** *** 256,259 **** --- 257,262 ---- makecrystal = new MakeCrystal(model, crystprop); model.addPropertyChangeListener(makecrystal); + transform = new TransformDialog(model, frame, this); + model.addPropertyChangeListener(transform); splash.showStatus(resourceHandler .translate("Initializing Recent Files...")); *************** *** 620,623 **** --- 623,627 ---- actions.addAll(Arrays.asList(crystprop.getActions())); actions.addAll(Arrays.asList(makecrystal.getActions())); + actions.addAll(Arrays.asList(transform.getActions())); actions.addAll(Arrays.asList(pg.getActions())); |
From: Fabian D. <fd...@us...> - 2002-12-27 14:02:07
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol In directory sc8-pr-cvs1:/tmp/cvs-serv30693/src/org/openscience/jmol Modified Files: CrystalFile.java ChemFrame.java Log Message: Work around for adding band plot feature Index: CrystalFile.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/CrystalFile.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** CrystalFile.java 1 Dec 2002 23:08:12 -0000 1.7 --- CrystalFile.java 27 Dec 2002 14:02:04 -0000 1.8 *************** *** 1,5 **** package org.openscience.jmol; ! import java.util.Vector; import javax.vecmath.Point3d; --- 1,5 ---- package org.openscience.jmol; ! import org.openscience.jmol.util.*; import java.util.Vector; import javax.vecmath.Point3d; *************** *** 234,239 **** generateAtoms(crystalFAtomRedPos, crystalFrame, frameEquivAtoms); - - //Compute the coordinates of the unit cell box frames. boxEdges = generateUnitBoxFrame(); --- 234,237 ---- *************** *** 253,256 **** --- 251,258 ---- this.crystalAtomRedPos.setElementAt(crystalFAtomRedPos, whichframe); + //store the PhysicalProperties + crystalFrame.setFrameProperties + (getFrame(whichframe).getFrameProperties()); + //store in cartesian coordinate in *super* object super.setFrame(crystalFrame, whichframe); *************** *** 300,304 **** //position (atomPos) ! op.transpose(arrayToMatrix3d(unitCellBoxS.getRprimd())); --- 302,306 ---- //position (atomPos) ! op.transpose(MathUtil.arrayToMatrix3d(unitCellBoxS.getRprimd())); *************** *** 318,327 **** maxc = 0; } else { ! mina = intSup(atomBox[0][0] - unitCellAtomRedPos[at][0]); ! maxa = intInf(atomBox[1][0] - unitCellAtomRedPos[at][0]); ! minb = intSup(atomBox[0][1] - unitCellAtomRedPos[at][1]); ! maxb = intInf(atomBox[1][1] - unitCellAtomRedPos[at][1]); ! minc = intSup(atomBox[0][2] - unitCellAtomRedPos[at][2]); ! maxc = intInf(atomBox[1][2] - unitCellAtomRedPos[at][2]); } --- 320,329 ---- maxc = 0; } else { ! mina = MathUtil.intSup(atomBox[0][0] - unitCellAtomRedPos[at][0]); ! maxa = MathUtil.intInf(atomBox[1][0] - unitCellAtomRedPos[at][0]); ! minb = MathUtil.intSup(atomBox[0][1] - unitCellAtomRedPos[at][1]); ! maxb = MathUtil.intInf(atomBox[1][1] - unitCellAtomRedPos[at][1]); ! minc = MathUtil.intSup(atomBox[0][2] - unitCellAtomRedPos[at][2]); ! maxc = MathUtil.intInf(atomBox[1][2] - unitCellAtomRedPos[at][2]); } *************** *** 338,342 **** double[] newAtomCartPos = new double[3]; ! newAtomCartPos = mulVec(op, newAtomRedPos); crystalFrame.addAtom(unitCellBoxS.getAtomType(at), --- 340,344 ---- double[] newAtomCartPos = new double[3]; ! newAtomCartPos = MathUtil.mulVec(op, newAtomRedPos); crystalFrame.addAtom(unitCellBoxS.getAtomType(at), *************** *** 408,420 **** //position (atomPos) ! op.transpose(arrayToMatrix3d(unitCellBoxS.getRprimd())); double[] redEdge = new double[3]; double[] cartEdge; ! for (int i = intSup(unitBox[0][0]); i <= intInf(unitBox[1][0]) - 1; i++) { ! for (int j = intSup(unitBox[0][1]); j <= intInf(unitBox[1][1]) - 1; j++) { ! for (int k = intSup(unitBox[0][2]); k <= intInf(unitBox[1][2]) - 1; k++) { --- 410,422 ---- //position (atomPos) ! op.transpose(MathUtil.arrayToMatrix3d(unitCellBoxS.getRprimd())); double[] redEdge = new double[3]; double[] cartEdge; ! for (int i = MathUtil.intSup(unitBox[0][0]); i <= MathUtil.intInf(unitBox[1][0]) - 1; i++) { ! for (int j = MathUtil.intSup(unitBox[0][1]); j <= MathUtil.intInf(unitBox[1][1]) - 1; j++) { ! for (int k = MathUtil.intSup(unitBox[0][2]); k <= MathUtil.intInf(unitBox[1][2]) - 1; k++) { *************** *** 424,428 **** redEdge[2] = ((Point3d) boxEdgesTemplate.elementAt(l)).z + k; ! cartEdge = mulVec(op, redEdge); boxEdges.addElement(new Point3d(cartEdge[0], cartEdge[1], --- 426,430 ---- redEdge[2] = ((Point3d) boxEdgesTemplate.elementAt(l)).z + k; ! cartEdge = MathUtil.mulVec(op, redEdge); boxEdges.addElement(new Point3d(cartEdge[0], cartEdge[1], *************** *** 494,581 **** - //Pure mathematical method - - /** - * Multiply the matrix "mat" by the vector "vec". - * The result is vector. - */ - private double[] mulVec(Matrix3d mat, double[] vec) { - - double[] result = new double[3]; - result[0] = mat.m00 * vec[0] + mat.m01 * vec[1] + mat.m02 * vec[2]; - result[1] = mat.m10 * vec[0] + mat.m11 * vec[1] + mat.m12 * vec[2]; - result[2] = mat.m20 * vec[0] + mat.m21 * vec[1] + mat.m22 * vec[2]; - return result; - } - - - /** - * Given a <code>double</code> f, return the closest superior integer - * - */ - private int intSup(double f) { - - if (f <= 0) { - return (int) f; - } else { - return (int) f + 1; - } - } - - int intInf(double f) { - - if (f < 0) { - return (int) f - 1; - } else { - return (int) f; - } - } - - /** - * Convert a <code>Matrix3d</code> to a <code>double[3][3]</code>. - * - */ - private double[][] matrix3fToArray(Matrix3d matrix3f) { - - double[][] array = new double[3][3]; - - array[0][0] = matrix3f.m00; - array[0][1] = matrix3f.m01; - array[0][2] = matrix3f.m02; - - array[1][0] = matrix3f.m10; - array[1][1] = matrix3f.m11; - array[1][2] = matrix3f.m12; - - array[2][0] = matrix3f.m20; - array[2][1] = matrix3f.m21; - array[2][2] = matrix3f.m22; - - return array; - } - - /** - * Convert a <code>double[3][3]</code> to a <code>Matrix3d</code>. - * - */ - private Matrix3d arrayToMatrix3d(double[][] array) { - - Matrix3d matrix3f = new Matrix3d(); - - matrix3f.m00 = array[0][0]; - matrix3f.m01 = array[0][1]; - matrix3f.m02 = array[0][2]; - - matrix3f.m10 = array[1][0]; - matrix3f.m11 = array[1][1]; - matrix3f.m12 = array[1][2]; - - matrix3f.m20 = array[2][0]; - matrix3f.m21 = array[2][1]; - matrix3f.m22 = array[2][2]; - - return matrix3f; - } --- 496,500 ---- Index: ChemFrame.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/ChemFrame.java,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -r1.72 -r1.73 *** ChemFrame.java 27 Dec 2002 00:36:02 -0000 1.72 --- ChemFrame.java 27 Dec 2002 14:02:04 -0000 1.73 *************** *** 123,126 **** --- 123,135 ---- /** + * Set the <code>PhysicalProperty</code>'s associated with this frame. + * + * @param a Vector of <code>PhysicalProperty</code> + */ + public void setFrameProperties(Vector properties) { + this.properties = properties; + } + + /** * Adds a <code>PhysicalProperty</code> to this frame if not already defined. * If a <code>PhysicalProperty</code> with the same description already |
From: Fabian D. <fd...@us...> - 2002-12-27 14:00:05
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol In directory sc8-pr-cvs1:/tmp/cvs-serv29724/src/org/openscience/jmol Modified Files: EnergyBand.java CrystalPropertiesDialog.java Log Message: Adding band plot feature Index: EnergyBand.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/EnergyBand.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** EnergyBand.java 1 Dec 2002 23:08:12 -0000 1.2 --- EnergyBand.java 27 Dec 2002 14:00:02 -0000 1.3 *************** *** 46,49 **** --- 46,53 ---- public class EnergyBand extends PhysicalProperty { + private int energyUnits; + private double maxE=0; + private double minE=0; + private double fermiE=0; private Vector kLines = new Vector(0); //a Vector of KLine *************** *** 56,61 **** * @param c The electronic energy bands of a frame */ ! public EnergyBand() { super("EnergyBand", null); System.out.println("New ENERGY Band set!!!!!!!!!!!!!!!!!!!!!!"); } --- 60,66 ---- * @param c The electronic energy bands of a frame */ ! public EnergyBand(int energyUnits) { super("EnergyBand", null); + this.energyUnits = energyUnits; System.out.println("New ENERGY Band set!!!!!!!!!!!!!!!!!!!!!!"); } *************** *** 95,98 **** --- 100,109 ---- .energy[kPosIndex][bandIndex] = energy; + if(energy > maxE) { + maxE = energy; + } else if (energy < minE) { + minE = energy; + } + } *************** *** 105,108 **** --- 116,139 ---- } + public int getEnergyUnits() { + return energyUnits; + } + + public double getMinE() { + return minE; + } + + public double getMaxE() { + return maxE; + } + + public double getFermiE() { + return fermiE; + } + + public void setFermiE(double fermiE) { + this.fermiE = fermiE; + } + public class KLine { *************** *** 113,117 **** private int nkpt; private int nband; ! //enrergy[k][n] is the enregy value at wave vector pos[k] and band n //pos[k] is the reduce coordinate along this KLine. --- 144,148 ---- private int nkpt; private int nband; ! //enrergy[k][n] is the enregy value at wave vector pos[k] and band n //pos[k] is the reduce coordinate along this KLine. *************** *** 134,137 **** --- 165,176 ---- return orig; } + + public String getOriginName() { + return origName; + } + + public void setOriginName(String origName) { + this.origName = origName; + } public Point3d getEnd() { *************** *** 139,146 **** } public int getNumberOfkPoints() { return nkpt; } ! public int getNumberOfBands() { return nband; --- 178,193 ---- } + public String getEndName() { + return endName; + } + + public void setEndName(String endName) { + this.endName = endName; + } + public int getNumberOfkPoints() { return nkpt; } ! public int getNumberOfBands() { return nband; *************** *** 151,154 **** --- 198,205 ---- } + /** + * Get the reduce coordinate of the k-point along the segment line. + */ + public double getkPoint(int index) { return pos[index]; *************** *** 158,162 **** --- 209,219 ---- return energy[index]; } + + public double getDistance(int indexa, int indexb) { + return orig.distance(end) * Math.abs(pos[indexa] - pos[indexb]); + } + } //end KLine + } //end class EnergyBand Index: CrystalPropertiesDialog.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/CrystalPropertiesDialog.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -r1.11 -r1.12 *** CrystalPropertiesDialog.java 2 Dec 2002 11:42:23 -0000 1.11 --- CrystalPropertiesDialog.java 27 Dec 2002 14:00:02 -0000 1.12 *************** *** 1,3 **** ! /* $RCSfile$ * $Author$ * $Date$ --- 1,5 ---- ! /** ! * Copyright 2002 The Jmol Development Team ! * $RCSfile$ * $Author$ * $Date$ *************** [...2569 lines suppressed...] --- 2140,2145 ---- // Workaround for documented bug 4246117 for JDK 1.2.2 if (System.getProperty("java.version").equals("1.2.2") ! && System.getProperty("java.vendor").startsWith("Sun Micro")) { ! overrideIsAdjusting = true; } } *************** *** 1741,1745 **** if (event.getPropertyName().equals(JmolModel.chemFileProperty)) { if (event.getNewValue() != chemFile) { ! setChemFile((ChemFile) event.getNewValue()); } } --- 2161,2165 ---- if (event.getPropertyName().equals(JmolModel.chemFileProperty)) { if (event.getNewValue() != chemFile) { ! setChemFile((ChemFile) event.getNewValue()); } } |
From: Fabian D. <fd...@us...> - 2002-12-27 13:58:57
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/Properties In directory sc8-pr-cvs1:/tmp/cvs-serv29102/src/org/openscience/jmol/Properties Modified Files: Jmol-resources.properties Jmol.properties Log Message: Adding band plot feature Index: Jmol-resources.properties =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/Properties/Jmol-resources.properties,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** Jmol-resources.properties 1 Dec 2002 11:17:12 -0000 1.8 --- Jmol-resources.properties 27 Dec 2002 13:58:54 -0000 1.9 *************** *** 81,85 **** # View menu # ! Jmol.view=front top bottom right left - definecenter perspective \ usegraphics2d doublebuffer test1 test2 test3 test4 Jmol.frontImage=frontButton.gif --- 81,85 ---- # View menu # ! Jmol.view=front top bottom right left transform - definecenter perspective \ usegraphics2d doublebuffer test1 test2 test3 test4 Jmol.frontImage=frontButton.gif Index: Jmol.properties =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/Properties/Jmol.properties,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -r1.51 -r1.52 *** Jmol.properties 2 Dec 2002 09:52:17 -0000 1.51 --- Jmol.properties 27 Dec 2002 13:58:54 -0000 1.52 *************** *** 132,135 **** --- 132,136 ---- Jmol.rightLabel=Right Jmol.leftLabel=Left + Jmol.transformLabel=Transform... Jmol.definecenterLabel=Define Center Jmol.perspectiveLabel=Perspective View *************** *** 143,146 **** --- 144,148 ---- Jmol.test4Label=Test 4 - rotate((1,1,1), pi/4) + # # Measure menu *************** *** 281,284 **** --- 283,320 ---- Crystprop.energyBandTooltip=Generate an energy band diagram if data is available Crystprop.origatomCheckBox=Original atoms only + + Crystalprop.ebTab.resolution=Resolution: + Crystalprop.ebTab.ratio=Ratio (y/x): + Crystalprop.ebTab.eunits=Energy units: + Crystalprop.ebTab.defplot=Define Plot: + Crystalprop.ebTab.defplotToolTip=A typical example is "0,1[0-10];-2,-1" + Crystalprop.ebTab.ffd=Fix fraction digits: + Crystalprop.ebTab.efd=Exp fraction digits: + Crystalprop.ebTab.emax=Maximum energy: + Crystalprop.ebTab.emin=Minimum energy: + Crystalprop.ebTab.efermi=Fermi level: + Crystalprop.ebTab.nvtics=Vertical tics #: + Crystalprop.ebTab.nhtics=Horizontal tics #: + Crystalprop.ebTab.ticsize=Tics' size: + Crystalprop.ebTab.fontsize1=Fontsize 1: + Crystalprop.ebTab.fontsize2=Fontsize 2: + Crystalprop.ebTab.fontsize3=Fontsize 3: + Crystalprop.ebTab.sepsize=Separator size: + Crystalprop.ebTab.ylabel=Y label: + Crystalprop.ebTab.ylabelToolTip=Formatted text: \\N : normal, \\S : Greeck symbols, ^ :superscript. + Crystalprop.ebTab.showBUT=Show + Crystalprop.ebTab.saveAs=Save As... + Crystalprop.ebTab.saveEPS=Save as EPS + + + # + # Transform dialog box + # + Transform.rotationPanelLabel=Rotation + Transform.axisLabel=Axis + Transform.anglePanelLabel=Angle + Transform.pointLabel=Point: + Transform.directionLabel=Direction: + Transform.angleLabel=Angle: # |
From: Fabian D. <fd...@us...> - 2002-12-27 13:57:50
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol In directory sc8-pr-cvs1:/tmp/cvs-serv28497/src/org/openscience/jmol Added Files: BandPlot.java BandPlotEPSRenderer.java BandPlotG2DRenderer.java BandPlotPanel.java BandPlotRenderer.java Log Message: Adding band plot feature --- NEW FILE: BandPlot.java --- /* * Copyright 2002 The Jmol Development Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. */ package org.openscience.jmol; import org.openscience.jmol.util.*; import java.util.StringTokenizer; import java.util.Vector; import javax.swing.JOptionPane; import java.io.File; public class BandPlot { EnergyBand energyBand; Vector bandPlotSections = new Vector(0); // a BandPlotSection vector String plotDef; int energyUnits; double conversionFactor; double fontsize1; // x (in pixel) double fontsize2; // y (in pixel) double fontsize3; // y label (in pixel) double ticSize; // (in pixel) // Y coordinate. We use an *absolute* behavior double minE; double maxE; double fermiE; int nvtics; int nhtics; String yLabel; //if true, rounds energies according to the number // of decimal figures. If false rounds energies according to // the number of significative figures int roundScheme=0; int nRound=2; int bigSepNumber=0; //Number of big separations in the plot. double bigSepSize; // String line; // To generate PostScript public BandPlot(EnergyBand energyBand, String plotDef, int energyUnits, double minE, double maxE, double fermiE, int nRound, int roundScheme, int nvtics, int nhtics, int ticSize, double fontsize1, double fontsize2, double fontsize3, double bigSepSize, String yLabel) throws ParseErrorException { this.energyBand = energyBand; this.plotDef = plotDef; this.energyUnits = energyUnits; conversionFactor = (double)Units.getConversionFactor (energyBand.getEnergyUnits(), energyUnits); this.nRound = nRound; this.roundScheme = roundScheme; this.nvtics = nvtics; this.nhtics = nhtics; this.ticSize = ticSize; this.fontsize1 = fontsize1; this.fontsize2 = fontsize2; this.fontsize3 = fontsize3; this.minE = minE; this.maxE = maxE; this.fermiE= fermiE; this.bigSepSize = bigSepSize; this.yLabel = yLabel; parse(); } public class ParseErrorException extends Exception { public ParseErrorException(int index) { //super("Parse Error. Position: " + index); } } private void parse() throws ParseErrorException { StringTokenizer st = new StringTokenizer(plotDef, "[],;-{}", true); String s=""; boolean isInt; boolean reverse=false; int value = 0; EnergyBand.KLine kLine=null; BandPlotSection section=null; final int WAIT_LINEINDEX = 0; final int WAIT_FIRSTINDEX = 1; final int WAIT_SECONDINDEX = 2; final int WAIT_LABEL = 3; final int WAIT_SEP = 4; int flag = WAIT_LINEINDEX; String sepString = ""; boolean isFirstIndex = true; boolean sepFound; int lineIndex; int parseIndex=0; //use to generate a ParseError try { while (st.hasMoreTokens()) { s = st.nextToken(); parseIndex = parseIndex+ s.length(); isInt = true; try { value = Integer.parseInt(s); } catch (NumberFormatException e){ isInt = false; } switch (flag) { case WAIT_SEP: sepFound= false; for (int i=0; i<sepString.length(); i++) { if (s.charAt(0) == (sepString.charAt(i))) { switch (s.charAt(0)) { case ',': flag = WAIT_LINEINDEX; section.endDelimiter = BandPlotSection.VLINE; reverse=false; break; case ';': flag = WAIT_LINEINDEX; section.endDelimiter = BandPlotSection.BIGSEP; bigSepNumber++; reverse=false; break; case '[': flag = WAIT_FIRSTINDEX; break; case '-': flag = WAIT_SECONDINDEX; break; case '{': flag = WAIT_LABEL; break; case ']': flag = WAIT_SEP; sepString=",;"; break; case '}': flag = WAIT_SEP; if (isFirstIndex) { sepString="-"; } else { sepString="]"; } break; } sepFound= true; } } if (sepFound == false) { throw new ParseErrorException(parseIndex); } break; case WAIT_LINEINDEX: if (s.equals("-")) { reverse = true; } else if (isInt) { lineIndex = value; section = new BandPlotSection(lineIndex, reverse); kLine = energyBand.getKLine(lineIndex); bandPlotSections.addElement(section); flag = WAIT_SEP; sepString=",;["; } else { throw new ParseErrorException(parseIndex); } break; case WAIT_FIRSTINDEX: section.origName=""; section.endName=""; if (isInt) { if (reverse) { section.endIndex = value; if (value == 0) { section.endName = kLine.getOriginName(); } else if (value == kLine.getNumberOfkPoints()-1){ section.endName = kLine.getEndName(); } } else { section.origIndex = value; if (value == 0) { section.origName = kLine.getOriginName(); } else if (value == kLine.getNumberOfkPoints()-1){ section.origName = kLine.getEndName(); } } flag = WAIT_SEP; sepString="{-"; isFirstIndex = true; } else { throw new ParseErrorException(parseIndex); } break; case WAIT_SECONDINDEX: if (isInt) { if (reverse) { section.origIndex = value; if (value == 0) { section.origName = kLine.getOriginName(); } else if (value == kLine.getNumberOfkPoints()-1){ section.origName = kLine.getEndName(); } } else { section.endIndex = value; if (value == 0) { section.endName = kLine.getOriginName(); } else if (value == kLine.getNumberOfkPoints()-1){ section.endName = kLine.getEndName(); } } flag = WAIT_SEP; sepString="{]"; isFirstIndex = false; } else { throw new ParseErrorException(parseIndex); } break; case WAIT_LABEL: if (isFirstIndex) { if (reverse) { section.endName = s; } else { section.origName = s; } } else { if (reverse) { section.origName = s; } else { section.endName = s; } } flag = WAIT_SEP; sepString="}"; break; } //end swith } //end while } catch (ParseErrorException parseError) { JOptionPane.showMessageDialog(null, plotDef + " !!Error at position "+ (parseIndex-1), "Parse Error", JOptionPane.ERROR_MESSAGE); throw new ParseErrorException(parseIndex); } } //end parse class BandPlotSection { int lineIndex; int origIndex; String origName; int endIndex; String endName; int endDelimiter; final static int NONE = 0; final static int VLINE = 1; final static int BIGSEP = 2; BandPlotSection(int lineIndex, boolean reverse) { this.lineIndex = lineIndex; //default value if (reverse) { origIndex = energyBand.getKLine(lineIndex).getNumberOfkPoints()-1; origName = energyBand.getKLine(lineIndex).getEndName(); endIndex = 0; endName = energyBand.getKLine(lineIndex).getOriginName(); } else { origIndex = 0; origName = energyBand.getKLine(lineIndex).getOriginName(); endIndex = energyBand.getKLine(lineIndex).getNumberOfkPoints()-1; endName = energyBand.getKLine(lineIndex).getEndName(); } } } //end class BandPlotSection } //end class BandPlot --- NEW FILE: BandPlotEPSRenderer.java --- package org.openscience.jmol; import java.io.IOException; import org.openscience.jmol.util.*; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.io.OutputStream; import java.io.FileOutputStream; import java.io.File; import java.io.FileNotFoundException; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.util.*; public class BandPlotEPSRenderer extends BandPlotRenderer { FileOutputStream file; BufferedWriter w; public BandPlotEPSRenderer(BandPlot bandPlot, double scalex, double ratio, File file) throws FileNotFoundException { super(bandPlot, scalex, ratio); //ebp = energyBandPlot; this.file = new FileOutputStream(file); w = new BufferedWriter(new OutputStreamWriter(this.file), 1024); } public void generateEPS() throws IOException { //Generate Encapsulated PostScript Header writeLine("%!PS-Adobe-2.0 EPSF-2.0"); writeLine("%%Title: Energy Band plot"); writeLine("%%Creator: Jmol"); writeLine("%%CreationDate: Mon Nov 11 11:26:46 2002"); //FIX writeLine("%%For: fabian@sandy (Fabian Dortu,,,)"); //FIX writeLine("%%BoundingBox: 0 0 " //Needed for EPS!!!! + plotLength + " " + plotHeight); //Generate core render(); // Finalize w.flush(); w.close(); file.flush(); file.close(); } //end render private void writeLine(String line) { try { w.write(line, 0, line.length()); w.newLine(); } catch (IOException ioe) { } } double getX() { return xorigin + x*scalex; } double getX(double x) { return xorigin + x*scalex; } double getY() { return yorigin + (y-ebp.minE)*scaley; } double getY(double y) { return yorigin + (y-ebp.minE)*scaley; } void setFont(String name, int size) { } void setLineWidth(int width) { } void drawLineR(double xorig, double yorig, double xend, double yend, int thickness) { String psLine=" gsave newpath " + thickness + " setlinewidth "; psLine = psLine + getX(xorig) + " " + getY(yorig) + " moveto "; psLine = psLine + getX(xend) + " " + getY(yend) + " lineto stroke"; psLine = psLine + " grestore "; writeLine(psLine); } void drawLineA(double xorig, double yorig, double xend, double yend, int thickness) { String psLine=" gsave newpath " + thickness + " setlinewidth "; psLine = psLine + xorig + " " + yorig + " moveto "; psLine = psLine + xend + " " + yend + " lineto stroke"; psLine = psLine + " grestore "; writeLine(psLine); } // Draw a vertical separation at the current x void drawVerticalSeparation(int linewidth) { drawLineR(x, ebp.minE, x, ebp.maxE, linewidth); } //Draw a horizontal separation at the current y void drawHorizontalSeparation(int linewidth, double orig, double end) { drawLineR(orig, y, end, y, linewidth); } //Draw vertical tics at current x to the left(right) direction //if direction is true(false) void drawVerticalTics(int ntics, boolean direction, int linewidth) { double step = (ebp.maxE - ebp.minE)/ntics; for (int i=0; i<= ntics ;i++) { if (direction) { drawLineA(getX(x), getY(ebp.minE + i*step), getX(x) - ebp.ticSize, getY(ebp.minE + i*step), linewidth); } else { drawLineA(getX(x), getY(ebp.minE + i*step), getX(x) + ebp.ticSize, getY(ebp.minE + i*step), linewidth); } } } void drawVerticalTicsLabels(int ntics, int fontsize) { String value; double step = (ebp.maxE - ebp.minE)/ntics; for (int i=0; i<= ntics ;i++) { value = Rounder.rounds((ebp.minE + i*step ), ebp.nRound, ebp.roundScheme); drawText(value, fontsize, getX() , getY(ebp.minE + i*step) - fontsize /3, 2, //Align right 0.0); //No rotation } } void drawHorizontalTics(int ntics, double orig, double end, int linewidth) { double step = (end-orig)/ntics; for (int i=0; i < ntics; i++){ drawLineA(getX(orig + i*step), getY(y), getX(orig + i*step), getY(y) + ebp.ticSize, linewidth); } } void drawHorizontalTicsLabel(double pos, String line, int fontsize) { drawText(line, fontsize, getX(pos), fontsize * .15f, 1, 0.0f); } void drawVerticalAxisLabel(String label, int fontsize) { drawText(label, fontsize, getMaxFontHeight("Times-Roman", fontsize), yorigin + (ebp.maxE-ebp.minE)/2 *scaley, 1, 90.0f); } void drawText(String text,int fontsize, double x, double y, int align, double rotation) { final int ALIGN_LEFT = 0; final int ALIGN_CENTER = 1; final int ALIGN_RIGHT = 2; FormatedText fText = new FormatedText(text, fontsize); double width = (double)fText.getWidth(); Vector textDef = fText.getTextDef(); Object token; String tokenPS; Font f = new Font("Times-Roman", Font.PLAIN, fontsize); String fontPS = "Times-Roman"; int sizePS = fontsize; double dx=0; double dy=0; switch(align) { case ALIGN_LEFT: dx=0; break; case ALIGN_CENTER: dx=-width/2.0; break; case ALIGN_RIGHT: dx=-width; break; } String psLine=" gsave "; psLine = psLine + x + " " + y + " translate " + rotation + " rotate 0 0 moveto "; for (Enumeration e = textDef.elements() ; e.hasMoreElements() ;) { token = e.nextElement(); if(token instanceof Integer) { switch (((Integer)token).intValue()) { case FormatedText.FONT_NORMAL: f = new Font("Times-Roman", Font.PLAIN, fontsize); fontPS = "Times-Roman"; sizePS = fontsize; break; case FormatedText.FONT_SYMBOL: f = new Font("Greek Poly Plain", Font.PLAIN, fontsize); fontPS = "Symbol"; sizePS = fontsize; break; case FormatedText.POS_NORMAL: f = new Font(f.getName(), Font.PLAIN, fontsize); sizePS = fontsize; dy=-dy; break; case FormatedText.POS_EXP: dy = (double)fontsize *2/3; f = new Font(f.getName(), Font.PLAIN, (int)((double)fontsize *1/2)); sizePS = (int)((double)fontsize *1/2); break; } } else if (token instanceof String) { FontMetrics fm = dummyFrame.getFontMetrics(f); // "(" and ")" must be "escaped" with "\(" and "\)" // because have PostScrip signification. // The regexp seems complicated // because: // *the escape character must escaped in both // java and in the regexp itself. // *the paranthesis must be escaped in regexp. tokenPS=(String)token; tokenPS=tokenPS.replaceAll("\\(","\\\\("); tokenPS=tokenPS.replaceAll("\\)","\\\\)"); psLine=psLine + "/" + fontPS + " findfont " + sizePS + " scalefont setfont " + dx + " " + dy + " rmoveto " + "(" + tokenPS + ")" + " show "; dx=0; // PostScript automaticaly increments its position } } //for on textDef elements psLine = psLine + " grestore "; writeLine(psLine); } } --- NEW FILE: BandPlotG2DRenderer.java --- package org.openscience.jmol; import org.openscience.jmol.util.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.lang.Integer; import java.util.*; import java.lang.reflect.Array; public class BandPlotG2DRenderer extends BandPlotRenderer { Graphics2D g2; JPanel bandPlotPanel; public BandPlotG2DRenderer(BandPlot bandPlot, double scalex, double ratio) { super(bandPlot, scalex, ratio); bandPlotPanel = new BandPlotPanel(this); } public JPanel getJPanel() { return bandPlotPanel; } void setGraphics2D(Graphics2D g2) { this.g2 = g2; } double getX() { return xorigin + x*scalex; } double getX(double x) { return xorigin + x*scalex; } double getY() { return (plotHeight - (yorigin + (y-ebp.minE)*scaley)); } double getY(double y) { return (plotHeight - (yorigin + (y-ebp.minE)*scaley)); } void setFont(String name, int size) { g2.setFont(new Font(name, Font.PLAIN, size)); } void setLineWidth(int width) { } //Draw line in relative coordinate. void drawLineR(double xorig, double yorig, double xend, double yend, int thickness) { g2.drawLine((int)getX(xorig), (int)getY(yorig), (int)getX(xend), (int)getY(yend)); } //Draw line in absolute coordinate. void drawLineA(double xorig, double yorig, double xend, double yend, int thickness) { g2.drawLine((int)xorig, (int)yorig, (int)xend, (int)yend); } // Draw a vertical separation at the current x void drawVerticalSeparation(int linewidth) { drawLineR(x, ebp.minE, x, ebp.maxE, linewidth); } //Draw a horizontal separation at the current y void drawHorizontalSeparation(int linewidth, double orig, double end) { drawLineR(orig, y, end, y, linewidth); } //Draw vertical tics at current x to the left(right) direction //if direction is true(false) void drawVerticalTics(int ntics, boolean direction, int linewidth) { double step = (ebp.maxE - ebp.minE)/ntics; for (int i=0; i<= ntics ;i++) { if (direction) { drawLineA(getX(x), getY(ebp.minE + i*step), getX(x) - ebp.ticSize, getY(ebp.minE + i*step), linewidth); } else { drawLineA(getX(x), getY(ebp.minE + i*step), getX(x) + ebp.ticSize, getY(ebp.minE + i*step), linewidth); } } } void drawVerticalTicsLabels(int ntics, int fontsize) { String value; double width; g2.setFont(new Font("Times-Roman", Font.PLAIN, fontsize)); double step = (ebp.maxE - ebp.minE)/ntics; for (int i=0; i<= ntics ;i++) { value = Rounder.rounds((ebp.minE + i*step ), ebp.nRound, ebp.roundScheme); width = getStringWidth(value, g2.getFont().getFontName(), g2.getFont().getSize()); g2.drawString(value, (int)(getX() - width), (int)(getY(ebp.minE + i*step) + ebp.fontsize2 /2)); } } void drawHorizontalTics(int ntics, double orig, double end, int linewidth) { double step = (end-orig)/ntics; for (int i=0; i < ntics; i++){ drawLineA(getX(orig + i*step), getY(y), getX(orig + i*step), getY(y) - ebp.ticSize, linewidth); } } void drawHorizontalTicsLabel(double pos, String label, int fontsize) { drawText(label, fontsize, (int)getX(pos), (int)(plotHeight), 1, //Align center); 0); } void drawVerticalAxisLabel(String label, int fontsize) { //The label is centered around the middle of the energy axis drawText(label, fontsize, getMaxFontHeight("Times-Roman", fontsize), (int)(plotHeight - (yorigin + (ebp.maxE-ebp.minE)/2 *scaley)) ,1 //Align center ,-90.0); } void drawText(String text,int fontsize, double x, double y, int align, double rotation) { final int ALIGN_LEFT = 0; final int ALIGN_CENTER = 1; final int ALIGN_RIGHT = 2; FormatedText fText = new FormatedText(text, fontsize); double width = (double)fText.getWidth(); Vector textDef = fText.getTextDef(); Object token; Font f = new Font("Times-Roman", Font.PLAIN, fontsize); double dx=0; double dy=0; switch(align) { case ALIGN_LEFT: dx=0; break; case ALIGN_CENTER: dx=-width/2.0; break; case ALIGN_RIGHT: dx=-width; break; } AffineTransform saveXform = g2.getTransform(); AffineTransform at = new AffineTransform(); at.rotate(Math.toRadians(rotation), x, y); g2.transform(at); for (Enumeration e = textDef.elements() ; e.hasMoreElements() ;) { token = e.nextElement(); if(token instanceof Integer) { switch (((Integer)token).intValue()) { case FormatedText.FONT_NORMAL: f = new Font("Times-Roman", Font.PLAIN, fontsize); g2.setFont(f); break; case FormatedText.FONT_SYMBOL: f = new Font("Greek Poly Plain", Font.PLAIN, fontsize); g2.setFont(f); break; case FormatedText.POS_NORMAL: f = new Font(f.getName(), Font.PLAIN, fontsize); dy=0; g2.setFont(f); break; case FormatedText.POS_EXP: dy=-(double)fontsize *2/3; f = new Font(f.getName(), Font.PLAIN, (int)((double)fontsize *1/2)); g2.setFont(f); break; } } else if (token instanceof String) { FontMetrics fm = g2.getFontMetrics(f); g2.drawString((String)token,(int)(x + dx), (int)(y + dy)); dx = dx + fm.stringWidth((String)token); } } //for on textDef elements g2.setTransform(saveXform); // DUBUG: Print font list //GraphicsEnvironment ge // = GraphicsEnvironment.getLocalGraphicsEnvironment(); //Font[] allFonts = ge.getAllFonts(); //for (int i=0; i < Array.getLength(allFonts); i++) { //System.out.println("Font "+ i +" : "+ allFonts[i].getFontName()); //} } } --- NEW FILE: BandPlotPanel.java --- package org.openscience.jmol; import javax.swing.*; import java.awt.*; public class BandPlotPanel extends JPanel { BandPlotG2DRenderer bpg2r; public BandPlotPanel(BandPlotG2DRenderer bpg2r) { this.bpg2r = bpg2r; } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; bpg2r.setGraphics2D(g2); super.paintComponent(g2); //paint background setBackground(Color.WHITE); bpg2r.render(); } } --- NEW FILE: BandPlotRenderer.java --- package org.openscience.jmol; import org.openscience.jmol.util.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; abstract class BandPlotRenderer { BandPlot ebp; JFrame dummyFrame = new JFrame(); //dummy Frame to compute string width. //coordinates: (0,0) is loxer left // x increase right // y increase up double x; double y; double xorigin; //origin of the plot (the band diagram) axis. double yorigin; //minimum energy position. Labels are below double plotLength; double plotHeight; double scalex; double scaley; double ratio; public BandPlotRenderer(BandPlot ebp, double scalex, double ratio) { this.ebp = ebp; this.scalex = scalex; this.ratio = ratio; // Set xorigin. Depends on width of the units label if ((Rounder.rounds(ebp.maxE, ebp.nRound, ebp.roundScheme)).length() > (Rounder.rounds(ebp.minE, ebp.nRound, ebp.roundScheme)).length()) { xorigin = 1.4*getStringWidth ((Rounder.rounds(ebp.maxE, ebp.nRound, ebp.roundScheme)), "Times-Roman", (int)ebp.fontsize2) + getMaxFontHeight("Times-Roman",(int)ebp.fontsize3); } else { xorigin = 1.4*getStringWidth ((Rounder.rounds(ebp.minE, ebp.nRound, ebp.roundScheme)), "Times-Roman" , (int)ebp.fontsize2) + getMaxFontHeight("Times-Roman",(int)ebp.fontsize3); } yorigin=getMaxFontHeight("Times-Roman",(int)ebp.fontsize1); plotLength = getPlotLength(); scaley = ratio / (ebp.maxE-ebp.minE) * scalex; plotHeight = getPlotHeight(); } public void render() { double xold; int sepFlag=0; BandPlot.BandPlotSection plotSection; boolean ticsLabel=true; x=0; // Be careful if modifying variable x (side effects bc relative behavior) // Variable y can be modified (absolute behavior) for (int i=0; i< ebp.bandPlotSections.size() ;i++) { ticsLabel = true; // Draw a thick vertical line if // *it is the first section // *a big separation has been done if (i==0 || sepFlag ==1) { sepFlag = 0; drawVerticalSeparation(2); drawVerticalTics(ebp.nvtics,false,1); if (i==0) { drawVerticalTicsLabels(ebp.nvtics, (int)ebp.fontsize2); } } plotSection = (BandPlot.BandPlotSection)ebp.bandPlotSections.elementAt(i); EnergyBand.KLine kLine = ebp.energyBand.getKLine(plotSection.lineIndex); xold = x; for (int eindex=0; eindex < kLine.getNumberOfBands(); eindex++) { x = xold; drawSectionLine(plotSection, kLine, eindex, ticsLabel); //x is modified ticsLabel = false; } //end for eindex y = ebp.minE; drawHorizontalSeparation(2, xold, x); drawHorizontalTics(ebp.nhtics, xold, x, 1); y = ebp.maxE; drawHorizontalSeparation(2, xold, x); y = ebp.fermiE; drawHorizontalSeparation(1, xold, x); switch (plotSection.endDelimiter) { case BandPlot.BandPlotSection.NONE: break; case BandPlot.BandPlotSection.VLINE: drawVerticalSeparation(1); break; case BandPlot.BandPlotSection.BIGSEP: sepFlag=1; drawVerticalSeparation(2); drawVerticalTics(ebp.nvtics,true,1); x = x + ebp.bigSepSize; break; } } //end for bandSection drawVerticalSeparation(2); drawVerticalTics(ebp.nvtics,true,1); drawVerticalAxisLabel(ebp.yLabel,(int)ebp.fontsize3); } //end render /** * draw the energy curve of the line kLine with index eindex * according to plotSection specifications. */ public void drawSectionLine(BandPlot.BandPlotSection plotSection, EnergyBand.KLine kLine, int eindex, boolean ticsLabel) { double energie; int kindexOld = plotSection.origIndex; double xtmp=0; double ytmp=0; if (plotSection.origIndex < plotSection.endIndex) { for (int kindex = plotSection.origIndex; kindex <= plotSection.endIndex; kindex++) { energie = kLine.getEnergies(kindex)[eindex] * ebp.conversionFactor; x = x+ kLine.getDistance(kindex, kindexOld); y = energie; if (kindex != kindexOld) { drawLineR(xtmp, ytmp, x, y, 0); } if (ticsLabel){ // draw only once if (kindex==plotSection.origIndex) { drawHorizontalTicsLabel(x, plotSection.origName, (int)ebp.fontsize1); } else if (kindex==plotSection.endIndex) { drawHorizontalTicsLabel(x, plotSection.endName, (int)ebp.fontsize1); } } kindexOld = kindex; xtmp = x; ytmp = y; } //end kindex } else { for (int kindex = plotSection.origIndex; kindex >= plotSection.endIndex; kindex--) { energie = kLine.getEnergies(kindex)[eindex] * ebp.conversionFactor; x = x+ kLine.getDistance(kindex, kindexOld); y = energie; if (kindex != kindexOld) { drawLineR(xtmp, ytmp, x, y, 0); } if (ticsLabel){ // draw only once if (kindex==plotSection.origIndex) { drawHorizontalTicsLabel(x, plotSection.origName, (int)ebp.fontsize1); } else if (kindex==plotSection.endIndex) { drawHorizontalTicsLabel(x, plotSection.endName, (int)ebp.fontsize1); } } kindexOld = kindex; xtmp = x; ytmp = y; } //end kindex } } public double getPlotLength() { BandPlot.BandPlotSection plotSection; double plotLength=0; for (int i=0; i< ebp.bandPlotSections.size() ;i++) { plotSection = (BandPlot.BandPlotSection)ebp.bandPlotSections.elementAt(i); EnergyBand.KLine kLine = ebp.energyBand.getKLine(plotSection.lineIndex); plotLength = plotLength + kLine.getDistance(plotSection.origIndex, plotSection.endIndex); } plotLength = plotLength*scalex + xorigin; plotLength = plotLength + (ebp.bigSepNumber*ebp.bigSepSize)*scalex; plotLength = plotLength + (double)getStringWidth("M","Times-Roman" , (int)ebp.fontsize1) /2 ; return plotLength; } public double getPlotHeight() { return (yorigin + (ebp.maxE - ebp.minE)*scaley + (double)getMaxFontHeight("Times-Roaman",(int)ebp.fontsize2) /2); } abstract double getX(); abstract double getX(double x); abstract double getY(); abstract double getY(double y); abstract void drawLineR(double xorig, double yorig, double xend, double yend, int thickness); abstract void drawLineA(double xorig, double yorig, double xend, double yend, int thickness); // Draw a vertical separation at the current x abstract void drawVerticalSeparation(int linewidth); //Draw a horizontal separation at the current y abstract void drawHorizontalSeparation(int linewidth, double orig, double end); //Draw vertical tics at current x to the left(right) direction //if direction is true(false) abstract void drawVerticalTics(int ntics, boolean direction, int linewidth); abstract void drawVerticalTicsLabels(int ntics, int fontsize); abstract void drawHorizontalTics(int ntics, double orig, double end, int linewidth); abstract void drawHorizontalTicsLabel(double pos, String label, int fontsize); abstract void drawVerticalAxisLabel(String label, int fontsize); abstract void setFont(String name, int size); abstract void setLineWidth(int width); //Alignment markers public final static int ALIGN_LEFT=0; public final static int ALIGN_RIGHT=1; public final static int ALIGN_CENTER=2; abstract void drawText(String text,int fontsize, double x, double y, int align, double rotation); public double getStringWidth(String string, String name, int size){ Font f = new Font(name, Font.PLAIN, size); FontMetrics fm = dummyFrame.getFontMetrics(f); return (double)fm.stringWidth(string); } public double getMaxFontHeight(String name, int size){ Font f = new Font(name, Font.PLAIN, size); FontMetrics fm = dummyFrame.getFontMetrics(f); return ((double)fm.getHeight())*1.1; } } //end class BandPlotRenderer |
From: Fabian D. <fd...@us...> - 2002-12-27 13:55:59
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/util In directory sc8-pr-cvs1:/tmp/cvs-serv27743/src/org/openscience/jmol/util Added Files: FieldReader.java FormatedText.java MathUtil.java Rounder.java Units.java Log Message: Adding some utilities --- NEW FILE: FieldReader.java --- package org.openscience.jmol.util; import java.util.StringTokenizer; import java.util.Vector; //VEC import java.lang.reflect.Array; import javax.swing.JTextField; //TXF import javax.swing.JOptionPane; public class FieldReader { /** * Read a vector of text fields of the form "double, double, double". */ static public double[][] readField3(Vector jTextField) throws NumberFormatException { StringTokenizer st; String sn; double matrix[][] = new double[jTextField.size()][3] ; for (int i = 0; i < jTextField.size(); i++) { st = new StringTokenizer(((JTextField) jTextField.elementAt(i)) .getText(), ","); for (int j = 0; j < 3; j++) { if (st.hasMoreTokens()) { sn = st.nextToken(); matrix[i][j] = Double.parseDouble(sn); } } } return matrix; } //end readField3(...) /** * Read a text fields of the form "double, double, double". */ static public double[] readField3(JTextField jTextField) throws NumberFormatException { StringTokenizer st; String sn; double matrix[] = new double[3] ; st = new StringTokenizer(jTextField.getText(), ","); for (int j = 0; j < 3; j++) { if (st.hasMoreTokens()) { sn = st.nextToken(); matrix[j] = Double.parseDouble(sn); } } return matrix; } //end readField3(...) /** * Read a vector of text fields of the form "double". */ static public double[] readField1(Vector jTextField) throws NumberFormatException { StringTokenizer st; String sn; int dim = jTextField.size(); double vect[] = (double[]) Array.newInstance(double.class, dim); for (int i = 0; i < jTextField.size(); i++) { st = new StringTokenizer(((JTextField) jTextField.elementAt(i)) .getText(), ","); if (st.hasMoreTokens()) { sn = st.nextToken(); vect[i] = Double.parseDouble(sn); } } return vect; } //end readField1(...) /** * Read a text fields of the form "double". */ static public double readField1(JTextField jTextField) throws NumberFormatException{ double value=0; StringTokenizer st; String sn; st = new StringTokenizer(jTextField.getText(), ","); if (st.hasMoreTokens()) { sn = st.nextToken(); value = Double.parseDouble(sn); } return value; } //end readField1(...) static protected void errorDialog(String s) { JOptionPane.showMessageDialog (null, s, "alert", JOptionPane.ERROR_MESSAGE); } //end errorDialog } --- NEW FILE: FormatedText.java --- package org.openscience.jmol.util; import java.util.Vector; import java.util.StringTokenizer; import java.lang.Integer; import java.util.*; import java.awt.*; public class FormatedText { //Font markers public final static int FONT_SYMBOL = 0; public final static int FONT_NORMAL = 1; //Position markers public final static int POS_NORMAL = 10; public final static int POS_EXP = 11; String text; int fontSize; int width; Vector textDef = new Vector(0); public FormatedText(String text, int fontSize) { this.text = text; this.fontSize = fontSize; parse(); computeWidth(); } /** * This methode parse the String passed in argument and * return a Vector containing easily usable formating information * * spaces are used as token separator * \N : switch to NORMAL font * \S : switch to SYMBOL font * ^ : put in exponent * \ : (backslash space) put a space character * * For instance: * * parse("Wavelength \ \S l \ \N ( cm^-1 )", 20) will return * * Vector(0) = FONT_NORMAL (int) * Vector(1) = POS_NORMAL * Vector(2) = "Wavelength" (String) * Vector(3) = " " * Vector(4) = FONT_SYMBOL * Vector(5) = "l" (this will give a lambda) * Vector(6) = " " * Vector(7) = FONT_NORMAL * Vector(8) = "(cm" * Vector(9) = POS_EXP * Vector(10) = "-1" * Vector(11)= POS_NORMAL * Vector(12)= ")" * Vector(13)= 234 (String width) * Vector(14)= 22 (String height) */ private Vector parse() { String s; StringTokenizer st; int length=0; int height=0; textDef.addElement(new Integer(FONT_NORMAL)); textDef.addElement(new Integer(POS_NORMAL)); st = new StringTokenizer(text, "\\^ ",true); while (st.hasMoreTokens()) { s = st.nextToken(); if (s.equals("\\")) { s = st.nextToken(); if (s.equals("S")) { textDef.addElement(new Integer(FONT_SYMBOL)); } else if (s.equals("N")) { textDef.addElement(new Integer(FONT_NORMAL)); } else if (s.equals(" ")) { textDef.addElement(" "); } } else if (s.equals("^")) { textDef.addElement(new Integer(POS_EXP)); } else if (s.equals(" ")) { //Do nothing } else { textDef.addElement(s); //Reset to normal textDef.addElement(new Integer(POS_NORMAL)); } } //end while return textDef; } //end parse private void computeWidth() { Frame dummyFrame = new Frame(); Object token; Font f = new Font("Times-Roman", Font.PLAIN, fontSize); width=0; for (Enumeration e = textDef.elements() ; e.hasMoreElements() ;) { token = e.nextElement(); if(token instanceof Integer) { switch (((Integer)token).intValue()) { case FONT_NORMAL: f = new Font("Times-Roman", Font.PLAIN, fontSize); break; case FONT_SYMBOL: f = new Font("Symbol", Font.PLAIN, fontSize); break; } } else if (token instanceof String) { FontMetrics fm = dummyFrame.getFontMetrics(f); width = width + fm.stringWidth((String)token); } } //for on textDef elements } //end computeWidth() public int getWidth() { return width; } public Vector getTextDef() { return textDef; } public int getFontSize() { return fontSize; } } // end class TextParser --- NEW FILE: MathUtil.java --- package org.openscience.jmol.util; import java.lang.reflect.Array; import javax.vecmath.Point3f; import javax.vecmath.Vector3f; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; import javax.vecmath.Matrix3d; public class MathUtil { public static Point3f arrayToPoint3f(float[] array) { return new Point3f(array[0], array[1], array[2]); } public static Vector3f arrayToVector3f(float[] array) { return new Vector3f(array[0], array[1], array[2]); } public static Point3d arrayToPoint3d(double[] array) { return new Point3d(array[0], array[1], array[2]); } public static Vector3d arrayToVector3d(double[] array) { return new Vector3d(array[0], array[1], array[2]); } /** * Multiply the matrix "mat" by the vector "vec". * The result is a vector. */ public static double[] mulVec(Matrix3d mat, double[] vec) { double[] result = new double[3]; result[0] = mat.m00 * vec[0] + mat.m01 * vec[1] + mat.m02 * vec[2]; result[1] = mat.m10 * vec[0] + mat.m11 * vec[1] + mat.m12 * vec[2]; result[2] = mat.m20 * vec[0] + mat.m21 * vec[1] + mat.m22 * vec[2]; return result; } /** * Given a <code>double</code> f, return the closest superior integer * */ public static int intSup(double f) { if (f <= 0) { return (int) f; } else { return (int) f + 1; } } /** * Given a <code>double</code> f, return the closest inferior integer * */ public static int intInf(double f) { if (f < 0) { return (int) f - 1; } else { return (int) f; } } /** * Convert a <code>Matrix3d</code> to a <code>double[3][3]</code>. * */ public static double[][] matrix3fToArray(Matrix3d matrix3f) { double[][] array = new double[3][3]; array[0][0] = matrix3f.m00; array[0][1] = matrix3f.m01; array[0][2] = matrix3f.m02; array[1][0] = matrix3f.m10; array[1][1] = matrix3f.m11; array[1][2] = matrix3f.m12; array[2][0] = matrix3f.m20; array[2][1] = matrix3f.m21; array[2][2] = matrix3f.m22; return array; } /** * Convert a <code>double[3][3]</code> to a <code>Matrix3d</code>. * */ public static Matrix3d arrayToMatrix3d(double[][] array) { Matrix3d matrix3f = new Matrix3d(); matrix3f.m00 = array[0][0]; matrix3f.m01 = array[0][1]; matrix3f.m02 = array[0][2]; matrix3f.m10 = array[1][0]; matrix3f.m11 = array[1][1]; matrix3f.m12 = array[1][2]; matrix3f.m20 = array[2][0]; matrix3f.m21 = array[2][1]; matrix3f.m22 = array[2][2]; return matrix3f; } } --- NEW FILE: Rounder.java --- package org.openscience.jmol.util; import java.text.DecimalFormat; public class Rounder { //Rounds according to... public final static int FIX = 0; // ...12334.345 -> 12334.345. public final static int EXP = 1; // ...12334.345 -> 1.2334E4 public static String rounds(double number, int ndec, int scheme) { String pattern="0"; switch(scheme) { case FIX: if (ndec !=0) { pattern = pattern +"."; } for (int i=0; i<ndec; i++) { pattern = pattern + "0"; } break; case EXP: pattern = pattern + "."; for (int i=0; i<ndec; i++) { pattern = pattern + "0"; } pattern = pattern + "E0"; break; } DecimalFormat myFormatter = new DecimalFormat(pattern); return myFormatter.format(number); } } //end class Rounder --- NEW FILE: Units.java --- package org.openscience.jmol.util; public class Units { //constant in SI public final static double C_PLANCK = 6.62606876E-34; // Plank constant (J.s) public final static double C_BOHR = 0.5291772083E-10; // Bohr radius (m) public final static double C_CE = 1.602176462E-19; // Elementary charge (Coulomb) public final static double C_C = 299792458 ; // Light velocity in vacuum (m/s) //UNITS //Length public final static int LENGTH_START_INDEX=0; public final static int ANGSTROM = 0; public final static int BOHR = 1; public final static int METER = 2; public final static int CENTI_METER = 3; public final static int MILLI_METER = 4; public final static int MICRO_METER = 5; public final static int NANO_METER = 6; //Energy public final static int ENERGY_START_INDEX=100; public final static int JOULE = 100; public final static int EV = 101; public final static int MILLI_EV = 102; // CMM1 == cm^1 ( The invert wavelength of a photon of a given energy) public final static int CENTI_METER_M1 = 103; public final static int MILLI_METER_M1 = 104; public final static int MICRO_METER_M1 = 105; public final static int NANO_METER_M1 = 106; public static double getConversionFactor(int inputUnit, int outputUnit) { double factor; // outputValue = inputValue * factor if (inputUnit == outputUnit) { factor = 1; return factor; } factor = getCF(inputUnit, outputUnit); if (factor == 0) { factor = getCF(outputUnit, inputUnit); if (factor != 0) { factor = 1/factor; } else { System.out.println("This conversion is not available"); } } return factor; } //end getConvertionFactor(...) private static double getCF(int inputUnit, int outputUnit) { double factor = 0; // We store only the superior part of the conversion table: // In this example, A, B, C ,D, E are length and // F, G, H, I are energies for exampe // // ------------------- // |A|B|C|D|E|F|G|H|I| // --------------------- // A |1|x|x|x|x| | | | | // B | |1|x|x|x| | | | | // C | | |1|x|x| | | | | // D | | | |1|x| | | | | // E | | | | |1| | | | | // F | | | | | |1|x|x|x| // F | | | | | | |1|x|x| // H | | | | | | | |1|x| // I | | | | | | | | |1| // // We get this structure // // switch (inputUnit) { // case B: // switch(outputUnit) { // case A: // } // case C: // switch(outputUnit) { // case A: // case B: // } // case D: // switch(outputUnit) { // case A: // case B: // case C: // } // case E: // switch(outputUnit) { // case A: // case B: // case C: // case D: // } // case F: // ... // ...you get it I think // } switch (inputUnit) { // Lengths case BOHR: switch (outputUnit) { case ANGSTROM: factor = C_BOHR; break; } break; case METER: switch (outputUnit) { case ANGSTROM: factor = 1E10; break; case BOHR: factor = 1E10/C_BOHR; break; } break; case CENTI_METER: switch (outputUnit) { case ANGSTROM: factor = 1E8; break; case BOHR: factor = 1E8/C_BOHR; break; case METER: factor = 1/100; break; } break; case MILLI_METER: switch (outputUnit) { case ANGSTROM: factor = 1E7; break; case BOHR: factor = 1E7/C_BOHR; break; case METER: factor = 1E-3; break; case CENTI_METER: factor = 1E-1; break; } break; case MICRO_METER: switch (outputUnit) { case ANGSTROM: factor = 1E10; break; case BOHR: factor = 1E10/C_BOHR; break; case METER: factor = 1E-6 ; break; case CENTI_METER: factor = 1E-4; break; case MILLI_METER: factor = 1E-3; break; } break; case NANO_METER: switch (outputUnit) { case ANGSTROM: factor = 1E10; break; case BOHR: factor = 1E10/C_BOHR; break; case METER: factor = 1E-9 ; break; case CENTI_METER: factor = 1E-7; break; case MILLI_METER: factor = 1E-6; break; case MICRO_METER: factor = 1E-3; break; } break; // Energies case EV: switch (outputUnit) { case JOULE: factor = C_CE; break; } break; case MILLI_EV: switch (outputUnit) { case JOULE: factor = C_CE / 1E3; break; case EV: factor = 1E-3; break; } break; case CENTI_METER_M1: switch (outputUnit) { case JOULE: factor = C_PLANCK * C_C * 1E2; break; case EV: factor = (C_PLANCK/ C_CE) * C_C * 1E2; break; case MILLI_EV: factor = (C_PLANCK/ C_CE) * C_C * 1E5; break; } break; case MILLI_METER_M1: switch (outputUnit) { case JOULE: factor = C_PLANCK * C_C * 1E3; break; case EV: factor = (C_PLANCK/ C_CE) * C_C * 1E3; break; case MILLI_EV: factor = (C_PLANCK/ C_CE) * C_C * 1E6; break; case CENTI_METER_M1: factor = 1E1; break; } break; case MICRO_METER_M1: switch (outputUnit) { case JOULE: factor = C_PLANCK * C_C * 1E6; break; case EV: factor = (C_PLANCK/ C_CE) * C_C * 1E6; break; case MILLI_EV: factor = (C_PLANCK/ C_CE) * C_C * 1E9; break; case CENTI_METER_M1: factor = 1E4; break; case MILLI_METER_M1: factor = 1E3; break; } break; case NANO_METER_M1: switch (outputUnit) { case JOULE: factor = C_PLANCK * C_C * 1E9; break; case EV: factor = (C_PLANCK/ C_CE) * C_C * 1E9; break; case MILLI_EV: factor = (C_PLANCK/ C_CE) * C_C * 1E12; break; case CENTI_METER_M1: factor = 1E7; break; case MILLI_METER_M1: factor = 1E6; break; case MICRO_METER_M1: factor = 1E3; break; } break; } return factor; } //end getCF() public static String[] getLengthList() { String[] list = {"angstrom", "bohr", "meter", "centimeter", "millimeter", "micrometer", "nanometer"}; return list; } public static String[] getEnergyList() { String[] list={"Joule", "eV", "meV", "centimeter^-1", "millimeter^-1", "micrometer^-1", "nanometer^-1"}; return list; } public static String[] getFormatedEnergyList() { String[] list={"Energy \\ (J)", "Energy \\ (eV)", "Energy \\ (meV)", "\\S l \\N \\ ( cm^-1 )", "\\S l \\N \\ ( mm^-1 )", "\\S l \\N \\ ( \\S m \\N m^-1 )", "\\S l \\N \\ ( nm^-1 )"}; return list; } } //end class Units |
From: Fabian D. <fd...@us...> - 2002-12-27 13:55:22
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/util In directory sc8-pr-cvs1:/tmp/cvs-serv27479/src/org/openscience/jmol/util Log Message: Directory /cvsroot/jmol/Jmol/src/org/openscience/jmol/util added to the repository |
From: Fabian D. <fd...@us...> - 2002-12-27 13:48:57
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/io In directory sc8-pr-cvs1:/tmp/cvs-serv24447/src/org/openscience/jmol/io Modified Files: ABINITReader.java ABINITOutputReader.java Log Message: Support for energy band reading Index: ABINITReader.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/io/ABINITReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** ABINITReader.java 1 Dec 2002 23:08:12 -0000 1.2 --- ABINITReader.java 27 Dec 2002 13:48:54 -0000 1.3 *************** *** 86,90 **** // The resulting CrystalFile ! CrystalFile crystalFile = new CrystalFile(); --- 86,90 ---- // The resulting CrystalFile ! CrystalFile crystalFile; *************** *** 97,100 **** --- 97,101 ---- super(input); this.inputBuffer = (BufferedReader) input; + crystalFile = new CrystalFile(); } Index: ABINITOutputReader.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/io/ABINITOutputReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** ABINITOutputReader.java 1 Dec 2002 23:08:12 -0000 1.2 --- ABINITOutputReader.java 27 Dec 2002 13:48:54 -0000 1.3 *************** *** 20,28 **** import org.openscience.jmol.ChemFile; import org.openscience.jmol.FortranFormat; import org.openscience.jmol.Energy; import org.openscience.jmol.EnergyBand; ! import org.openscience.jmol.CrystalBox; ! import org.openscience.jmol.UnitCellBox; import java.util.Vector; import java.util.StringTokenizer; --- 20,32 ---- import org.openscience.jmol.ChemFile; + import org.openscience.jmol.CrystalFile; + import org.openscience.jmol.CrystalBox; + import org.openscience.jmol.UnitCellBox; import org.openscience.jmol.FortranFormat; import org.openscience.jmol.Energy; import org.openscience.jmol.EnergyBand; ! ! import org.openscience.jmol.util.*; ! import java.util.Vector; import java.util.StringTokenizer; *************** *** 90,94 **** String line; int count = 0; ! double energy = 0.0f; Vector dataset = new Vector(0); //Store the dataset numbers as a string int selectedDataset = 0; --- 94,98 ---- String line; int count = 0; ! double energy = 1000000; Vector dataset = new Vector(0); //Store the dataset numbers as a string int selectedDataset = 0; *************** *** 346,351 **** //Add the Energy Property to the frame ! crystalFile.getFrame(crystalFile.getNumberOfFrames()-1) ! .addProperty(new Energy(energy)); } //end setFrame() --- 350,357 ---- //Add the Energy Property to the frame ! if (energy != 1000000) { ! crystalFile.getFrame(crystalFile.getNumberOfFrames()-1) ! .addProperty(new Energy(energy)); ! } } //end setFrame() *************** *** 414,418 **** private void readEnergyBand() throws IOException { ! EnergyBand energyBand = new EnergyBand(); Point3d a = new Point3d(); --- 420,424 ---- private void readEnergyBand() throws IOException { ! EnergyBand energyBand = new EnergyBand(Units.EV); Point3d a = new Point3d(); *************** *** 421,425 **** Point3d orig = new Point3d(); Point3d end = new Point3d(); ! //Go to "Eigenvalues" --- 427,432 ---- Point3d orig = new Point3d(); Point3d end = new Point3d(); ! String origName =""; ! String endName = ""; //Go to "Eigenvalues" *************** *** 473,478 **** nkptRead = nkptRead - nkptReadSinceLastMark; nkptReadSinceLastMark=0; ! energyBand.addKLine(orig,"",end,"",lkpt,nband); //create a new line System.out.println("New K Line"); --- 480,497 ---- nkptRead = nkptRead - nkptReadSinceLastMark; nkptReadSinceLastMark=0; + + + if (orig.x == 0.0f && orig.y == 0.0f && orig.z == 0.0f){ + origName="\\S G"; + } else { + origName=""; + } + if (end.x == 0.0f && end.y == 0.0f && end.z == 0.0f){ + endName="\\S G"; + } else { + endName=""; + } ! energyBand.addKLine(orig,origName,end,endName,lkpt,nband); //create a new line System.out.println("New K Line"); |
From: Michael T H. <mic...@us...> - 2002-12-27 00:36:06
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol In directory sc8-pr-cvs1:/tmp/cvs-serv10761/src/org/openscience/jmol Modified Files: ChemFrame.java DisplayControl.java DisplayPanel.java Jmol.java PreferencesDialog.java Log Message: misc cleanup of DisplayControl setting & method names Index: ChemFrame.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/ChemFrame.java,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -r1.71 -r1.72 *** ChemFrame.java 12 Dec 2002 18:05:53 -0000 1.71 --- ChemFrame.java 27 Dec 2002 00:36:02 -0000 1.72 *************** *** 510,514 **** // examples of crystal vectors samples/estron.cml samples/bulk_Si.in double radius = 0.0f; ! double atomSphereFactor = Jmol.control.getAtomSphereFactor(); for (int i = 0; i < numberAtoms; ++i) { Atom atom = atoms[i]; --- 510,514 ---- // examples of crystal vectors samples/estron.cml samples/bulk_Si.in double radius = 0.0f; ! double atomSphereFactor = Jmol.control.percentVdwAtom / 100.0; for (int i = 0; i < numberAtoms; ++i) { Atom atom = atoms[i]; Index: DisplayControl.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/DisplayControl.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -r1.28 -r1.29 *** DisplayControl.java 26 Dec 2002 22:41:48 -0000 1.28 --- DisplayControl.java 27 Dec 2002 00:36:02 -0000 1.29 *************** *** 90,114 **** } ! public int labelMode = NOLABELS; ! public void setLabelMode(int mode) { ! if (labelMode != mode) { ! labelMode = mode; recalc(); } } - public int getLabelMode() { - return labelMode; - } ! public int atomDrawMode = QUICKDRAW; ! public void setAtomDrawMode(int mode) { ! if (atomDrawMode != mode) { ! atomDrawMode = mode; recalc(); } } - public int getAtomDrawMode() { - return atomDrawMode; - } AtomColorer colorProfile = AtomColors.getInstance(); --- 90,108 ---- } ! public int modeLabel = NOLABELS; ! public void setModeLabel(int mode) { ! if (modeLabel != mode) { ! modeLabel = mode; recalc(); } } ! public int modeAtomDraw = QUICKDRAW; ! public void setModeAtomDraw(int mode) { ! if (modeAtomDraw != mode) { ! modeAtomDraw = mode; recalc(); } } AtomColorer colorProfile = AtomColors.getInstance(); *************** *** 129,151 **** } ! public int bondDrawMode = QUICKDRAW; ! public void setBondDrawMode(int mode) { ! if (bondDrawMode != mode) { ! bondDrawMode = mode; recalc(); } } - public int getBondDrawMode() { - return bondDrawMode; - } ! public double bondWidth = .1; ! public void setBondWidth(double width) { ! bondWidth = width; recalc(); } - public double getBondWidth() { - return bondWidth; - } public Color outlineColor = Color.black; --- 123,139 ---- } ! public int modeBondDraw = QUICKDRAW; ! public void setModeBondDraw(int mode) { ! if (modeBondDraw != mode) { ! modeBondDraw = mode; recalc(); } } ! public int percentAngBond = 10; ! public void setPercentAngBond(int percentAngBond) { ! this.percentAngBond = percentAngBond; recalc(); } public Color outlineColor = Color.black; *************** *** 270,282 **** } ! // FIXME -- change me to be a percentage ! public double atomSphereFactor = 0.2; ! public void setAtomSphereFactor(double d) { ! atomSphereFactor = d; recalc(); } - public double getAtomSphereFactor() { - return atomSphereFactor; - } public boolean fastRendering = false;; --- 258,266 ---- } ! public int percentVdwAtom = 20; ! public void setPercentVdwAtom(int percentVdwAtom) { ! this.percentVdwAtom = percentVdwAtom; recalc(); } public boolean fastRendering = false;; *************** *** 357,364 **** } - public double getScalePixelsPerAngstrom() { - return scalePixelsPerAngstrom; - } - public void translateBy(int xDelta, int yDelta) { xTranslation += xDelta; --- 341,344 ---- *************** *** 639,643 **** if (this.mouseDragged && !mouseDragged) { if ((useGraphics2D && wantsAntialias && !wantsAntialiasAlways) || ! (bondDrawMode == SHADING)) recalc(); } --- 619,623 ---- if (this.mouseDragged && !mouseDragged) { if ((useGraphics2D && wantsAntialias && !wantsAntialiasAlways) || ! (modeBondDraw == SHADING)) recalc(); } *************** *** 772,780 **** } ! public int getScreenDiameter(int z, double vdwRadius) { if (z > 0) System.out.println("--?QUE? no way that z > 0--"); int d = (int)(2 * vdwRadius * ! scalePixelsPerAngstrom * getAtomSphereFactor()); if (perspectiveDepth) d = (d * cameraZ) / (cameraZ - z); --- 752,760 ---- } ! public int screenAtomDiameter(int z, double vdwRadius) { if (z > 0) System.out.println("--?QUE? no way that z > 0--"); int d = (int)(2 * vdwRadius * ! scalePixelsPerAngstrom * percentVdwAtom / 100); if (perspectiveDepth) d = (d * cameraZ) / (cameraZ - z); *************** *** 782,785 **** --- 762,772 ---- } + public int screenBondWidth(int z) { + int w = (int)(scalePixelsPerAngstrom * percentAngBond / 100); + if (perspectiveDepth) + w = (w * cameraZ) / (cameraZ - z); + return w; + } + public double scaleToScreen(int z, double sizeAngstroms) { // all z's are <= 0 *************** *** 901,905 **** public Color getAtomOutlineColor(Color color) { ! Color outline = (showDarkerOutline || atomDrawMode == SHADING) ? getDarker(color) : outlineColor; if (modeTransparentColors) --- 888,892 ---- public Color getAtomOutlineColor(Color color) { ! Color outline = (showDarkerOutline || modeAtomDraw == SHADING) ? getDarker(color) : outlineColor; if (modeTransparentColors) Index: DisplayPanel.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/DisplayPanel.java,v retrieving revision 1.70 retrieving revision 1.71 diff -C2 -r1.70 -r1.71 *** DisplayPanel.java 24 Dec 2002 14:50:36 -0000 1.70 --- DisplayPanel.java 27 Dec 2002 00:36:02 -0000 1.71 *************** *** 432,436 **** public void actionPerformed(ActionEvent e) { ! control.setAtomDrawMode(DisplayControl.QUICKDRAW); repaint(); } --- 432,436 ---- public void actionPerformed(ActionEvent e) { ! control.setModeAtomDraw(DisplayControl.QUICKDRAW); repaint(); } *************** *** 445,449 **** public void actionPerformed(ActionEvent e) { ! control.setAtomDrawMode(DisplayControl.SHADING); } } --- 445,449 ---- public void actionPerformed(ActionEvent e) { ! control.setModeAtomDraw(DisplayControl.SHADING); } } *************** *** 457,461 **** public void actionPerformed(ActionEvent e) { ! control.setAtomDrawMode(DisplayControl.WIREFRAME); repaint(); } --- 457,461 ---- public void actionPerformed(ActionEvent e) { ! control.setModeAtomDraw(DisplayControl.WIREFRAME); repaint(); } *************** *** 496,500 **** public void actionPerformed(ActionEvent e) { ! control.setBondDrawMode(DisplayControl.QUICKDRAW); repaint(); } --- 496,500 ---- public void actionPerformed(ActionEvent e) { ! control.setModeBondDraw(DisplayControl.QUICKDRAW); repaint(); } *************** *** 509,513 **** public void actionPerformed(ActionEvent e) { ! control.setBondDrawMode(DisplayControl.SHADING); repaint(); } --- 509,513 ---- public void actionPerformed(ActionEvent e) { ! control.setModeBondDraw(DisplayControl.SHADING); repaint(); } *************** *** 522,526 **** public void actionPerformed(ActionEvent e) { ! control.setBondDrawMode(DisplayControl.LINE); repaint(); } --- 522,526 ---- public void actionPerformed(ActionEvent e) { ! control.setModeBondDraw(DisplayControl.LINE); repaint(); } *************** *** 535,539 **** public void actionPerformed(ActionEvent e) { ! control.setBondDrawMode(DisplayControl.WIREFRAME); repaint(); } --- 535,539 ---- public void actionPerformed(ActionEvent e) { ! control.setModeBondDraw(DisplayControl.WIREFRAME); repaint(); } *************** *** 784,788 **** public void actionPerformed(ActionEvent e) { ! control.setLabelMode(DisplayControl.NOLABELS); repaint(); } --- 784,788 ---- public void actionPerformed(ActionEvent e) { ! control.setModeLabel(DisplayControl.NOLABELS); repaint(); } *************** *** 797,801 **** public void actionPerformed(ActionEvent e) { ! control.setLabelMode(DisplayControl.SYMBOLS); repaint(); } --- 797,801 ---- public void actionPerformed(ActionEvent e) { ! control.setModeLabel(DisplayControl.SYMBOLS); repaint(); } *************** *** 810,814 **** public void actionPerformed(ActionEvent e) { ! control.setLabelMode(DisplayControl.TYPES); repaint(); } --- 810,814 ---- public void actionPerformed(ActionEvent e) { ! control.setModeLabel(DisplayControl.TYPES); repaint(); } *************** *** 823,827 **** public void actionPerformed(ActionEvent e) { ! control.setLabelMode(DisplayControl.NUMBERS); repaint(); } --- 823,827 ---- public void actionPerformed(ActionEvent e) { ! control.setModeLabel(DisplayControl.NUMBERS); repaint(); } *************** *** 879,889 **** final String[] modeLabel = {"Jmol.plain", "Jmol.symbols", "Jmol.types", "Jmol.numbers"}; ! guimap.setSelected(modeLabel[control.labelMode], true); final String[] modeAtom = {"Jmol.aquickdraw", "Jmol.ashading", "Jmol.awireframe"}; ! guimap.setSelected(modeAtom[control.atomDrawMode], true); final String[] modeBond = {"Jmol.bquickdraw", "Jmol.bshading", "Jmol.bwireframe","Jmol.bline"}; ! guimap.setSelected(modeBond[control.bondDrawMode], true); final String[] modeColor = {"Jmol.actype", "Jmol.accharge"}; --- 879,889 ---- final String[] modeLabel = {"Jmol.plain", "Jmol.symbols", "Jmol.types", "Jmol.numbers"}; ! guimap.setSelected(modeLabel[control.modeLabel], true); final String[] modeAtom = {"Jmol.aquickdraw", "Jmol.ashading", "Jmol.awireframe"}; ! guimap.setSelected(modeAtom[control.modeAtomDraw], true); final String[] modeBond = {"Jmol.bquickdraw", "Jmol.bshading", "Jmol.bwireframe","Jmol.bline"}; ! guimap.setSelected(modeBond[control.modeBondDraw], true); final String[] modeColor = {"Jmol.actype", "Jmol.accharge"}; Index: Jmol.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/Jmol.java,v retrieving revision 1.81 retrieving revision 1.82 diff -C2 -r1.81 -r1.82 *** Jmol.java 25 Dec 2002 22:05:54 -0000 1.81 --- Jmol.java 27 Dec 2002 00:36:02 -0000 1.82 *************** *** 1296,1300 **** // GIF doesn't support more than 8 bits: ! if (control.getAtomDrawMode() == DisplayControl.SHADING) { it.disableGIF(); } --- 1296,1300 ---- // GIF doesn't support more than 8 bits: ! if (control.modeAtomDraw == DisplayControl.SHADING) { it.disableGIF(); } Index: PreferencesDialog.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/PreferencesDialog.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** PreferencesDialog.java 4 Dec 2002 10:46:46 -0000 1.12 --- PreferencesDialog.java 27 Dec 2002 00:36:02 -0000 1.13 *************** *** 82,102 **** private static boolean showVectors; private static boolean showDarkerOutline; ! private static Color backgroundColor; ! private static Color outlineColor; ! private static Color pickedColor; ! private static Color textColor; ! private static Color vectorColor; ! private static int AtomRenderMode; private static int AtomColorProfile; ! private static int AtomLabelMode; private static String AtomPropsMode; ! private static int BondRenderMode; private static double ArrowHeadSize; private static double ArrowHeadRadius; private static double ArrowLengthScale; private static double BondFudge; ! private static double BondWidth; private static double FieldOfView; ! private static double SphereFactor; private static double VibrateAmplitudeScale; private static double VibrateVectorScale; --- 82,102 ---- private static boolean showVectors; private static boolean showDarkerOutline; ! private static Color colorBackground; ! private static Color colorOutline; ! private static Color colorSelection; ! private static Color colorText; ! private static Color colorVector; ! private static int modeAtomDraw; private static int AtomColorProfile; ! private static int modeLabel; private static String AtomPropsMode; ! private static int modeBondDraw; private static double ArrowHeadSize; private static double ArrowHeadRadius; private static double ArrowLengthScale; private static double BondFudge; ! private static int percentAngBond; private static double FieldOfView; ! private static int percentVdwAtom; private static double VibrateAmplitudeScale; private static double VibrateVectorScale; *************** *** 144,163 **** props.put("Perspective", "false"); props.put("FieldOfView", "20.0"); ! props.put("AtomRenderMode", "0"); ! props.put("AtomLabelMode", "0"); props.put("AtomPropsMode", ""); ! props.put("SphereFactor", "0.2"); ! props.put("BondRenderMode", "0"); props.put("AutoBond", "true"); ! props.put("BondWidth", "0.1"); props.put("BondFudge", "1.12"); props.put("ArrowHeadSize", "1.0"); props.put("ArrowHeadRadius", "1.0"); props.put("ArrowLengthScale", "1.0"); ! props.put("backgroundColor", "16777215"); ! props.put("outlineColor", "0"); ! props.put("pickedColor", "16762880"); ! props.put("textColor", "0"); ! props.put("vectorColor", "0"); props.put("VibrateAmplitudeScale", "0.7"); props.put("VibrateVectorScale", "1.0"); --- 144,163 ---- props.put("Perspective", "false"); props.put("FieldOfView", "20.0"); ! props.put("modeAtomDraw", "0"); ! props.put("modeLabel", "0"); props.put("AtomPropsMode", ""); ! props.put("percentVdwAtom", "20"); ! props.put("modeBondDraw", "0"); props.put("AutoBond", "true"); ! props.put("percentAngBond", "10"); props.put("BondFudge", "1.12"); props.put("ArrowHeadSize", "1.0"); props.put("ArrowHeadRadius", "1.0"); props.put("ArrowLengthScale", "1.0"); ! props.put("colorBackground", "16777215"); ! props.put("colorOutline", "0"); ! props.put("colorSelection", "16762880"); ! props.put("colorText", "0"); ! props.put("colorVector", "0"); props.put("VibrateAmplitudeScale", "0.7"); props.put("VibrateVectorScale", "1.0"); *************** *** 325,329 **** aRender.addItem(JmolResourceHandler.getInstance() .getString("Prefs.aWFChoice")); ! aRender.setSelectedIndex(control.getAtomDrawMode()); aRender.addItemListener(new ItemListener() { --- 325,329 ---- aRender.addItem(JmolResourceHandler.getInstance() .getString("Prefs.aWFChoice")); ! aRender.setSelectedIndex(control.modeAtomDraw); aRender.addItemListener(new ItemListener() { *************** *** 331,337 **** JComboBox source = (JComboBox) e.getSource(); ! AtomRenderMode = source.getSelectedIndex(); ! control.setAtomDrawMode(AtomRenderMode); ! props.put("AtomRenderMode", Integer.toString(AtomRenderMode)); } }); --- 331,337 ---- JComboBox source = (JComboBox) e.getSource(); ! modeAtomDraw = source.getSelectedIndex(); ! control.setModeAtomDraw(modeAtomDraw); ! props.put("modeAtomDraw", Integer.toString(modeAtomDraw)); } }); *************** *** 380,384 **** aLabel.addItem(JmolResourceHandler.getInstance() .getString("Prefs.aNLChoice")); ! aLabel.setSelectedIndex(control.getLabelMode()); aLabel.addItemListener(new ItemListener() { --- 380,384 ---- aLabel.addItem(JmolResourceHandler.getInstance() .getString("Prefs.aNLChoice")); ! aLabel.setSelectedIndex(control.modeLabel); aLabel.addItemListener(new ItemListener() { *************** *** 386,392 **** JComboBox source = (JComboBox) e.getSource(); ! AtomLabelMode = source.getSelectedIndex(); ! control.setLabelMode(AtomLabelMode); ! props.put("AtomLabelMode", Integer.toString(AtomLabelMode)); } }); --- 386,392 ---- JComboBox source = (JComboBox) e.getSource(); ! modeLabel = source.getSelectedIndex(); ! control.setModeLabel(modeLabel); ! props.put("modeLabel", Integer.toString(modeLabel)); } }); *************** *** 433,438 **** .getString("Prefs.atomSizeExpl"), JLabel.CENTER); sfPanel.add(sfLabel, BorderLayout.NORTH); ! sfSlider = new JSlider(JSlider.HORIZONTAL, 0, 100, ! (int) (100.0 * control.getAtomSphereFactor())); sfSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE); sfSlider.setPaintTicks(true); --- 433,438 ---- .getString("Prefs.atomSizeExpl"), JLabel.CENTER); sfPanel.add(sfLabel, BorderLayout.NORTH); ! sfSlider = ! new JSlider(JSlider.HORIZONTAL, 0, 100, control.percentVdwAtom); sfSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE); sfSlider.setPaintTicks(true); *************** *** 445,451 **** JSlider source = (JSlider) e.getSource(); ! SphereFactor = source.getValue() / 100.0; ! control.setAtomSphereFactor(SphereFactor); ! props.put("SphereFactor", Double.toString(SphereFactor)); } }); --- 445,451 ---- JSlider source = (JSlider) e.getSource(); ! percentVdwAtom = source.getValue(); ! control.setPercentVdwAtom(percentVdwAtom); ! props.put("percentVdwAtom", "" + percentVdwAtom); } }); *************** *** 493,497 **** bRender.addItem(JmolResourceHandler.getInstance() .getString("Prefs.bLChoice")); ! bRender.setSelectedIndex(control.getBondDrawMode()); bRender.addItemListener(new ItemListener() { --- 493,497 ---- bRender.addItem(JmolResourceHandler.getInstance() .getString("Prefs.bLChoice")); ! bRender.setSelectedIndex(control.modeBondDraw); bRender.addItemListener(new ItemListener() { *************** *** 499,505 **** JComboBox source = (JComboBox) e.getSource(); ! BondRenderMode = source.getSelectedIndex(); ! control.setBondDrawMode(BondRenderMode); ! props.put("BondRenderMode", Integer.toString(BondRenderMode)); } }); --- 499,505 ---- JComboBox source = (JComboBox) e.getSource(); ! modeBondDraw = source.getSelectedIndex(); ! control.setModeBondDraw(modeBondDraw); ! props.put("modeBondDraw", Integer.toString(modeBondDraw)); } }); *************** *** 551,556 **** .getString("Prefs.bondWidthExpl"), JLabel.CENTER); bwPanel.add(bwLabel, BorderLayout.NORTH); ! bwSlider = new JSlider(JSlider.HORIZONTAL, 0, 100, ! (int) (100.0 * control.getBondWidth())); bwSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE); bwSlider.setPaintTicks(true); --- 551,556 ---- .getString("Prefs.bondWidthExpl"), JLabel.CENTER); bwPanel.add(bwLabel, BorderLayout.NORTH); ! bwSlider = ! new JSlider(JSlider.HORIZONTAL, 0, 100, control.percentAngBond); bwSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE); bwSlider.setPaintTicks(true); *************** *** 582,588 **** JSlider source = (JSlider) e.getSource(); ! BondWidth = source.getValue() / 100.0; ! control.setBondWidth(BondWidth); ! props.put("BondWidth", Double.toString(BondWidth)); } }); --- 582,588 ---- JSlider source = (JSlider) e.getSource(); ! percentAngBond = source.getValue(); ! control.setPercentAngBond(percentAngBond); ! props.put("percentAngBond", "" + percentAngBond); } }); *************** *** 810,814 **** .getString("Prefs.bgLabel"))); bButton = new JButton(); ! bButton.setBackground(backgroundColor); bButton.setToolTipText(JmolResourceHandler.getInstance() .getString("Prefs.bgToolTip")); --- 810,814 ---- .getString("Prefs.bgLabel"))); bButton = new JButton(); ! bButton.setBackground(colorBackground); bButton.setToolTipText(JmolResourceHandler.getInstance() .getString("Prefs.bgToolTip")); *************** *** 820,829 **** JColorChooser .showDialog(bButton, JmolResourceHandler.getInstance() ! .getString("Prefs.bgChooserTitle"), backgroundColor); ! backgroundColor = color; ! bButton.setBackground(backgroundColor); ! control.setBackgroundColor(backgroundColor); ! props.put("backgroundColor", ! Integer.toString(backgroundColor.getRGB())); } }; --- 820,829 ---- JColorChooser .showDialog(bButton, JmolResourceHandler.getInstance() ! .getString("Prefs.bgChooserTitle"), colorBackground); ! colorBackground = color; ! bButton.setBackground(colorBackground); ! control.setBackgroundColor(colorBackground); ! props.put("colorBackground", ! Integer.toString(colorBackground.getRGB())); } }; *************** *** 845,849 **** oButton = new JButton(); ! oButton.setBackground(outlineColor); oButton.setToolTipText(JmolResourceHandler.getInstance() .getString("Prefs.outlineToolTip")); --- 845,849 ---- oButton = new JButton(); ! oButton.setBackground(colorOutline); oButton.setToolTipText(JmolResourceHandler.getInstance() .getString("Prefs.outlineToolTip")); *************** *** 855,863 **** JColorChooser .showDialog(oButton, JmolResourceHandler.getInstance() ! .getString("Prefs.outlineChooserTitle"), outlineColor); ! outlineColor = color; ! oButton.setBackground(outlineColor); ! control.setOutlineColor(outlineColor); ! props.put("outlineColor", Integer.toString(outlineColor.getRGB())); } }; --- 855,863 ---- JColorChooser .showDialog(oButton, JmolResourceHandler.getInstance() ! .getString("Prefs.outlineChooserTitle"), colorOutline); ! colorOutline = color; ! oButton.setBackground(colorOutline); ! control.setOutlineColor(colorOutline); ! props.put("colorOutline", Integer.toString(colorOutline.getRGB())); } }; *************** *** 872,876 **** .getString("Prefs.pickedLabel"))); pButton = new JButton(); ! pButton.setBackground(pickedColor); pButton.setToolTipText(JmolResourceHandler.getInstance() .getString("Prefs.pickedToolTip")); --- 872,876 ---- .getString("Prefs.pickedLabel"))); pButton = new JButton(); ! pButton.setBackground(colorSelection); pButton.setToolTipText(JmolResourceHandler.getInstance() .getString("Prefs.pickedToolTip")); *************** *** 882,890 **** JColorChooser .showDialog(pButton, JmolResourceHandler.getInstance() ! .getString("Prefs.pickedChooserTitle"), pickedColor); ! pickedColor = color; ! pButton.setBackground(pickedColor); ! control.setPickedColor(pickedColor); ! props.put("pickedColor", Integer.toString(pickedColor.getRGB())); } }; --- 882,890 ---- JColorChooser .showDialog(pButton, JmolResourceHandler.getInstance() ! .getString("Prefs.pickedChooserTitle"), colorSelection); ! colorSelection = color; ! pButton.setBackground(colorSelection); ! control.setPickedColor(colorSelection); ! props.put("colorSelection", Integer.toString(colorSelection.getRGB())); } }; *************** *** 899,903 **** .getString("Prefs.textLabel"))); tButton = new JButton(); ! tButton.setBackground(textColor); tButton.setToolTipText(JmolResourceHandler.getInstance() .getString("Prefs.textToolTip")); --- 899,903 ---- .getString("Prefs.textLabel"))); tButton = new JButton(); ! tButton.setBackground(colorText); tButton.setToolTipText(JmolResourceHandler.getInstance() .getString("Prefs.textToolTip")); *************** *** 909,917 **** JColorChooser .showDialog(tButton, JmolResourceHandler.getInstance() ! .getString("Prefs.textChooserTitle"), textColor); ! textColor = color; ! tButton.setBackground(textColor); ! control.setTextColor(textColor); ! props.put("textColor", Integer.toString(textColor.getRGB())); } }; --- 909,917 ---- JColorChooser .showDialog(tButton, JmolResourceHandler.getInstance() ! .getString("Prefs.textChooserTitle"), colorText); ! colorText = color; ! tButton.setBackground(colorText); ! control.setTextColor(colorText); ! props.put("colorText", Integer.toString(colorText.getRGB())); } }; *************** *** 926,930 **** .getString("Prefs.vectorLabel"))); vButton = new JButton(); ! vButton.setBackground(vectorColor); vButton.setToolTipText(JmolResourceHandler.getInstance() .getString("Prefs.vectorToolTip")); --- 926,930 ---- .getString("Prefs.vectorLabel"))); vButton = new JButton(); ! vButton.setBackground(colorVector); vButton.setToolTipText(JmolResourceHandler.getInstance() .getString("Prefs.vectorToolTip")); *************** *** 936,944 **** JColorChooser .showDialog(vButton, JmolResourceHandler.getInstance() ! .getString("Prefs.vectorChooserTitle"), vectorColor); ! vectorColor = color; ! vButton.setBackground(vectorColor); ! control.setVectorColor(vectorColor); ! props.put("vectorColor", Integer.toString(vectorColor.getRGB())); control.refresh(); } --- 936,944 ---- JColorChooser .showDialog(vButton, JmolResourceHandler.getInstance() ! .getString("Prefs.vectorChooserTitle"), colorVector); ! colorVector = color; ! vButton.setBackground(colorVector); ! control.setVectorColor(colorVector); ! props.put("colorVector", Integer.toString(colorVector.getRGB())); control.refresh(); } *************** *** 1113,1125 **** // Atom panel controls: ! aRender.setSelectedIndex(control.getAtomDrawMode()); ! aLabel.setSelectedIndex(control.getLabelMode()); ! sfSlider.setValue((int) (100.0 ! * control.getAtomSphereFactor())); // Bond panel controls: ! bRender.setSelectedIndex(control.getBondDrawMode()); abYes.setSelected(control.getAutoBond()); ! bwSlider.setValue((int) (100.0 * control.getBondWidth())); bfSlider.setValue((int) (50.0 * control.getBondFudge())); --- 1113,1124 ---- // Atom panel controls: ! aRender.setSelectedIndex(control.modeAtomDraw); ! aLabel.setSelectedIndex(control.modeLabel); ! sfSlider.setValue(control.percentVdwAtom); // Bond panel controls: ! bRender.setSelectedIndex(control.modeBondDraw); abYes.setSelected(control.getAutoBond()); ! bwSlider.setValue(control.percentAngBond); bfSlider.setValue((int) (50.0 * control.getBondFudge())); *************** *** 1130,1139 **** // Color panel controls: ! bButton.setBackground(backgroundColor); cbDarkerOutline.setSelected(control.getShowDarkerOutline()); ! oButton.setBackground(outlineColor); ! pButton.setBackground(pickedColor); ! tButton.setBackground(textColor); ! vButton.setBackground(vectorColor); // Vibrate panel controls --- 1129,1138 ---- // Color panel controls: ! bButton.setBackground(colorBackground); cbDarkerOutline.setSelected(control.getShowDarkerOutline()); ! oButton.setBackground(colorOutline); ! pButton.setBackground(colorSelection); ! tButton.setBackground(colorText); ! vButton.setBackground(colorVector); // Vibrate panel controls *************** *** 1180,1192 **** showVectors = Boolean.getBoolean("showVectors"); showDarkerOutline = Boolean.getBoolean("showDarkerOutline"); ! backgroundColor = Color.getColor("backgroundColor"); ! outlineColor = Color.getColor("outlineColor"); ! pickedColor = Color.getColor("pickedColor"); ! textColor = Color.getColor("textColor"); ! vectorColor = Color.getColor("vectorColor"); ! AtomRenderMode = Integer.getInteger("AtomRenderMode").intValue(); ! AtomLabelMode = Integer.getInteger("AtomLabelMode").intValue(); AtomPropsMode = props.getProperty("AtomPropsMode"); ! BondRenderMode = Integer.getInteger("BondRenderMode").intValue(); VibrationFrames = Integer.getInteger("VibrationFrames").intValue(); --- 1179,1191 ---- showVectors = Boolean.getBoolean("showVectors"); showDarkerOutline = Boolean.getBoolean("showDarkerOutline"); ! colorBackground = Color.getColor("colorBackground"); ! colorOutline = Color.getColor("colorOutline"); ! colorSelection = Color.getColor("colorSelection"); ! colorText = Color.getColor("colorText"); ! colorVector = Color.getColor("colorVector"); ! modeAtomDraw = Integer.getInteger("modeAtomDraw").intValue(); ! modeLabel = Integer.getInteger("modeLabel").intValue(); AtomPropsMode = props.getProperty("AtomPropsMode"); ! modeBondDraw = Integer.getInteger("modeBondDraw").intValue(); VibrationFrames = Integer.getInteger("VibrationFrames").intValue(); *************** *** 1199,1206 **** new Double(props.getProperty("ArrowLengthScale")).doubleValue(); BondFudge = new Double(props.getProperty("BondFudge")).doubleValue(); ! BondWidth = new Double(props.getProperty("BondWidth")).doubleValue(); FieldOfView = new Double(props.getProperty("FieldOfView")).doubleValue(); ! SphereFactor = ! new Double(props.getProperty("SphereFactor")).doubleValue(); VibrateAmplitudeScale = new Double(props.getProperty("VibrateAmplitudeScale")).doubleValue(); --- 1198,1206 ---- new Double(props.getProperty("ArrowLengthScale")).doubleValue(); BondFudge = new Double(props.getProperty("BondFudge")).doubleValue(); ! percentAngBond = ! Integer.parseInt(props.getProperty("percentAngBond")); FieldOfView = new Double(props.getProperty("FieldOfView")).doubleValue(); ! percentVdwAtom = ! Integer.parseInt(props.getProperty("percentVdwAtom")); VibrateAmplitudeScale = new Double(props.getProperty("VibrateAmplitudeScale")).doubleValue(); *************** *** 1208,1225 **** new Double(props.getProperty("VibrateVectorScale")).doubleValue(); ! control.setOutlineColor(outlineColor); ! control.setPickedColor(pickedColor); ! control.setTextColor(textColor); ! control.setAtomSphereFactor(SphereFactor); ! control.setAtomDrawMode(AtomRenderMode); ! control.setLabelMode(AtomLabelMode); control.setPropertyMode(AtomPropsMode); ! control.setBondWidth(BondWidth); ! control.setBondDrawMode(BondRenderMode); ! control.setVectorColor(vectorColor); control.setArrowHeadRadius(ArrowHeadRadius); control.setArrowHeadSize(ArrowHeadSize); control.setArrowLengthScale(ArrowLengthScale); ! control.setBackgroundColor(backgroundColor); control.setWantsGraphics2D(graphics2D); control.setWantsAntialias(antialias); --- 1208,1225 ---- new Double(props.getProperty("VibrateVectorScale")).doubleValue(); ! control.setOutlineColor(colorOutline); ! control.setPickedColor(colorSelection); ! control.setTextColor(colorText); ! control.setPercentVdwAtom(percentVdwAtom); ! control.setModeAtomDraw(modeAtomDraw); ! control.setModeLabel(modeLabel); control.setPropertyMode(AtomPropsMode); ! control.setPercentAngBond(percentAngBond); ! control.setModeBondDraw(modeBondDraw); ! control.setVectorColor(colorVector); control.setArrowHeadRadius(ArrowHeadRadius); control.setArrowHeadSize(ArrowHeadSize); control.setArrowLengthScale(ArrowLengthScale); ! control.setBackgroundColor(colorBackground); control.setWantsGraphics2D(graphics2D); control.setWantsAntialias(antialias); |
From: Michael T H. <mic...@us...> - 2002-12-27 00:36:06
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/render In directory sc8-pr-cvs1:/tmp/cvs-serv10761/src/org/openscience/jmol/render Modified Files: AtomRenderer.java AtomShape.java BondRenderer.java Log Message: misc cleanup of DisplayControl setting & method names Index: AtomRenderer.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/render/AtomRenderer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** AtomRenderer.java 17 Dec 2002 23:19:11 -0000 1.1 --- AtomRenderer.java 27 Dec 2002 00:36:02 -0000 1.2 *************** *** 97,101 **** renderAtom(); ! if (control.labelMode != control.NOLABELS) renderLabel(); } --- 97,101 ---- renderAtom(); ! if (control.modeLabel != control.NOLABELS) renderLabel(); } *************** *** 114,118 **** if (diameter <= 2) { if (diameter > 0) { ! g.setColor(control.atomDrawMode==control.WIREFRAME ? color : colorOutline); g.fillRect(xUpperLeft, yUpperLeft, diameter, diameter); --- 114,118 ---- if (diameter <= 2) { if (diameter > 0) { ! g.setColor(control.modeAtomDraw == control.WIREFRAME ? color : colorOutline); g.fillRect(xUpperLeft, yUpperLeft, diameter, diameter); *************** *** 120,124 **** return; } ! if (control.atomDrawMode == control.SHADING && diameter >= minCachedSize && !control.fastRendering) { --- 120,124 ---- return; } ! if (control.modeAtomDraw == control.SHADING && diameter >= minCachedSize && !control.fastRendering) { *************** *** 130,134 **** int diamT = diameter-1; g.setColor(color); ! if (!control.fastRendering && control.atomDrawMode!=control.WIREFRAME) { // diamT should work here, but if background dots are appearing // just inside the circles then change the parameter to *diameter* --- 130,134 ---- int diamT = diameter-1; g.setColor(color); ! if (!control.fastRendering && control.modeAtomDraw != control.WIREFRAME) { // diamT should work here, but if background dots are appearing // just inside the circles then change the parameter to *diameter* *************** *** 376,380 **** String label = null; ! switch (control.labelMode) { case DisplayControl.SYMBOLS: label = atom.getSymbol(); --- 376,380 ---- String label = null; ! switch (control.modeLabel) { case DisplayControl.SYMBOLS: label = atom.getSymbol(); Index: AtomShape.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/render/AtomShape.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -r1.33 -r1.34 *** AtomShape.java 17 Dec 2002 23:19:11 -0000 1.33 --- AtomShape.java 27 Dec 2002 00:36:02 -0000 1.34 *************** *** 80,84 **** y = (int)screen.y; z = (int)screen.z; ! diameter = control.getScreenDiameter(z, atom.getType().getVdwRadius()); } --- 80,84 ---- y = (int)screen.y; z = (int)screen.z; ! diameter = control.screenAtomDiameter(z, atom.getType().getVdwRadius()); } Index: BondRenderer.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/render/BondRenderer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** BondRenderer.java 22 Dec 2002 12:51:43 -0000 1.3 --- BondRenderer.java 27 Dec 2002 00:36:02 -0000 1.4 *************** *** 99,103 **** return; // the pixels from the atoms will nearly cover the bond if (!control.showAtoms && ! (control.fastRendering || control.bondDrawMode==control.LINE)) { // the trivial case of no atoms and only single lines // in this case double & triple bonds are not drawn --- 99,103 ---- return; // the pixels from the atoms will nearly cover the bond if (!control.showAtoms && ! (control.fastRendering || control.modeBondDraw==control.LINE)) { // the trivial case of no atoms and only single lines // in this case double & triple bonds are not drawn *************** *** 132,137 **** outline2 = control.getAtomOutlineColor(color2); ! width1 = (int)control.scaleToScreen(z1, control.bondWidth); ! width2 = (int)control.scaleToScreen(z2, control.bondWidth); if (width1 < 4 && width2 < 4) { --- 132,137 ---- outline2 = control.getAtomOutlineColor(color2); ! width1 = control.screenBondWidth(z1); ! width2 = control.screenBondWidth(z2); if (width1 < 4 && width2 < 4) { *************** *** 142,146 **** boolean lineBond = ! control.bondDrawMode == control.LINE || control.fastRendering; if (!lineBond && width1 < 2 && width2 < 2) { // if the bonds are narrow ... --- 142,146 ---- boolean lineBond = ! control.modeBondDraw == control.LINE || control.fastRendering; if (!lineBond && width1 < 2 && width2 < 2) { // if the bonds are narrow ... *************** *** 233,237 **** void polyBond1(Color color, Color outline) { g.setColor(color); ! switch(control.bondDrawMode) { case DisplayControl.WIREFRAME: g.drawPolygon(axPoly, ayPoly, 4); --- 233,237 ---- void polyBond1(Color color, Color outline) { g.setColor(color); ! switch(control.modeBondDraw) { case DisplayControl.WIREFRAME: g.drawPolygon(axPoly, ayPoly, 4); |
From: Michael T H. <mic...@us...> - 2002-12-27 00:36:06
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/io In directory sc8-pr-cvs1:/tmp/cvs-serv10761/src/org/openscience/jmol/io Modified Files: PovraySaver.java Log Message: misc cleanup of DisplayControl setting & method names Index: PovraySaver.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/io/PovraySaver.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** PovraySaver.java 12 Dec 2002 23:02:55 -0000 1.8 --- PovraySaver.java 27 Dec 2002 00:36:02 -0000 1.9 *************** *** 147,152 **** w.write("\n"); ! style.writeAtomsAndBondsMacros(w, cf, control.getAtomSphereFactor(), ! control.getBondWidth()); boolean drawHydrogen = control.getShowHydrogens(); --- 147,152 ---- w.write("\n"); ! style.writeAtomsAndBondsMacros(w, cf, control.percentVdwAtom / 100.0, ! control.percentAngBond / 100.0); boolean drawHydrogen = control.getShowHydrogens(); |
From: Michael T H. <mic...@us...> - 2002-12-26 22:41:52
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol In directory sc8-pr-cvs1:/tmp/cvs-serv15051 Modified Files: DisplayControl.java Removed Files: SelectionSet.java Log Message: converted selection to use Java 1.1 version of BitSet Index: DisplayControl.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/DisplayControl.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -r1.27 -r1.28 *** DisplayControl.java 26 Dec 2002 01:14:03 -0000 1.27 --- DisplayControl.java 26 Dec 2002 22:41:48 -0000 1.28 *************** *** 300,312 **** } ! private final SelectionSet setPicked = new SelectionSet(); public void addSelection(Atom atom) { ! setPicked.addSelection(atom.getAtomNumber()); recalc(); } public void removeSelection(Atom atom) { ! setPicked.removeSelection(atom.getAtomNumber()); recalc(); } --- 300,313 ---- } ! private final BitSet bsNull = new BitSet(); ! private final BitSet bsSelection = new BitSet(); public void addSelection(Atom atom) { ! bsSelection.set(atom.getAtomNumber()); recalc(); } public void removeSelection(Atom atom) { ! bsSelection.clear(atom.getAtomNumber()); recalc(); } *************** *** 314,321 **** public void toggleSelection(Atom atom) { int atomNum = atom.getAtomNumber(); ! if (setPicked.isSelected(atomNum)) ! setPicked.removeSelection(atomNum); else ! setPicked.addSelection(atomNum); recalc(); } --- 315,322 ---- public void toggleSelection(Atom atom) { int atomNum = atom.getAtomNumber(); ! if (bsSelection.get(atomNum)) ! bsSelection.clear(atomNum); else ! bsSelection.set(atomNum); recalc(); } *************** *** 323,327 **** public void addSelection(Atom[] atoms) { for (int i = 0; i < atoms.length; ++i) ! setPicked.addSelection(atoms[i].getAtomNumber()); recalc(); } --- 324,328 ---- public void addSelection(Atom[] atoms) { for (int i = 0; i < atoms.length; ++i) ! bsSelection.set(atoms[i].getAtomNumber()); recalc(); } *************** *** 329,359 **** public void removeSelection(Atom[] atoms) { for (int i = 0; i < atoms.length; ++i) ! setPicked.removeSelection(atoms[i].getAtomNumber()); recalc(); } - public int[] getSelection() { - return setPicked.getSelection(); - } - public void clearSelection() { ! setPicked.clearSelection(); recalc(); } public int countSelection() { ! return setPicked.countSelection(); } public boolean isSelected(Atom atom) { ! return setPicked.isSelected(atom.getAtomNumber()); } public void setSelectionSet(BitSet set) { ! clearSelection(); ! int num = numberOfAtoms(); // FIXME -- probably should store this someplace ! for (int i = 0; i < num; ++i) ! if (set.get(i)) ! setPicked.addSelection(i); recalc(); } --- 330,357 ---- public void removeSelection(Atom[] atoms) { for (int i = 0; i < atoms.length; ++i) ! bsSelection.clear(atoms[i].getAtomNumber()); recalc(); } public void clearSelection() { ! bsSelection.and(bsNull); recalc(); } public int countSelection() { ! int count = 0; ! for (int i = 0, size = bsSelection.size(); i < size; ++i) ! if (bsSelection.get(i)) ! ++count; ! return count; } public boolean isSelected(Atom atom) { ! return bsSelection.get(atom.getAtomNumber()); } public void setSelectionSet(BitSet set) { ! bsSelection.and(bsNull); ! bsSelection.or(set); recalc(); } *************** *** 753,766 **** } - public void setCenterAsSelected() { ! int[] picked = setPicked.getSelection(); ! Point3d center = null; ! if (picked.length > 0) { ! // just take the average of all the points ! center = new Point3d(); // defaults to 0,0,0 ! for (int i = 0; i < picked.length; ++i) ! center.add(new Point3d(getFrame().getAtomAt(picked[i]).getPosition())); ! center.scale(1.0f / picked.length); // just divide by the quantity } getFrame().setRotationCenter(center); --- 751,768 ---- } public void setCenterAsSelected() { ! int numberOfAtoms = numberOfAtoms(); ! int countSelected = 0; ! Point3d center = new Point3d(); // defaults to 0,00, ! for (int i = 0; i < numberOfAtoms; ++i) { ! if (!bsSelection.get(i)) ! continue; ! ++countSelected; ! center.add(getFrame().getAtomAt(i).getPosition()); ! } ! if (countSelected > 0) { ! center.scale(1.0f / countSelected); // just divide by the quantity ! } else { ! center = null; } getFrame().setRotationCenter(center); --- SelectionSet.java DELETED --- |
From: Michael T H. <mic...@us...> - 2002-12-26 18:09:42
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/script In directory sc8-pr-cvs1:/tmp/cvs-serv741 Modified Files: Token.java Log Message: rearrangment of keyword definitions to prepare for predefinedset support Index: Token.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/script/Token.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** Token.java 26 Dec 2002 01:14:03 -0000 1.2 --- Token.java 26 Dec 2002 18:09:38 -0000 1.3 *************** *** 89,213 **** // rasmol commands ! final static int backbone = command | 0 | predefinedset | bool; ! final static int background = command | 1 | colorparam | setspecial; ! final static int bond = command | 2 | bool; ! final static int cartoon = command | 3 | setspecial; ! final static int center = command | 4 | showparam | expression; ! final static int clipboard = command | 5; ! final static int color = command | 6 | colorparam; ! final static int connect = command | 7 | bool; ! final static int cpk = command | 8; ! final static int define = command | 9 | expression; ! final static int dots = command | 10 | bool; ! final static int echo = command | 11 | specialstring; ! final static int exit = command | 12; ! final static int hbonds = command | 13 | setparam | bool; ! final static int help = command | 14; ! final static int label = command | 15 | bool; // FIXME -- why did I have load tagged as a setparam? ! final static int load = command | 16 | specialstring; // setparam; ! final static int molecule = command | 17; ! final static int monitor = command | 18 | setspecial | bool; ! final static int pause = command | 19; ! final static int print = command | 20; ! final static int quit = command | 21; ! final static int refresh = command | 22; ! final static int renumber = command | 23 | negativeints; ! final static int reset = command | 24; ! final static int restrict = command | 25 | expression; ! final static int ribbons = command | 26 | bool; ! final static int rotate = command | 27 | bool | negativeints; ! final static int save = command | 28; ! final static int script = command | 29 | specialstring; ! final static int select = command | 30 | expression; ! final static int set = command | 31 | bool | negativeints; ! final static int show = command | 32; ! final static int slab = command | 33 | bool; ! final static int source = command | 34 | specialstring; ! final static int spacefill = command | 35 | bool; ! final static int ssbonds = command | 36 | setparam | bool; ! final static int star = command | 37 | bool; ! final static int stereo = command | 38 | setspecial | bool | negativeints; ! final static int strands = command | 39 | setspecial | bool; ! final static int structure = command | 40; ! final static int trace = command | 41 | bool; ! final static int translate = command | 42 | negativeints; ! final static int unbond = command | 43; ! final static int wireframe = command | 44 | bool; ! final static int write = command | 45 | setparam; ! final static int zap = command | 46; ! final static int zoom = command | 47 | showparam | bool; // chime commands ! final static int delay = command | 48; ! final static int loop = command | 49; ! final static int move = command | 50 | negativeints; ! final static int view = command | 51; ! final static int restore = command | 52; ! final static int spin = command | 53 | showparam | bool; ! final static int list = command | 54 | showparam; ! final static int display3d = command | 55; // parameters ! final static int ambient = setparam | 0; ! final static int axes = setparam | 1; // background ! final static int backfade = setparam | 2; ! final static int bondmode = setparam | 3; ! final static int bonds = setparam | 4; ! final static int boundbox = setparam | 5; // cartoon ! final static int cisangle = setparam | 6; ! final static int display = setparam | 7; ! final static int fontsize = setparam | 8; ! final static int fontstroke = setparam | 9; // hbonds ! final static int hetero = setparam | 10 | predefinedset; ! final static int hourglass = setparam | 11; ! final static int hydrogen = setparam | 12 | predefinedset; ! final static int kinemage = setparam | 13; ! final static int menus = setparam | 14; // monitor ! final static int mouse = setparam | 15; ! final static int picking = setparam | 16; ! final static int radius = setparam | 17 | atomproperty; ! final static int shadow = setparam | 18; ! final static int slabmode = setparam | 19; ! final static int solvent = setparam | 20 | predefinedset; ! final static int specular = setparam | 21; ! final static int specpower = setparam | 22; // ssbonds // stereo // strands ! final static int transparent = setparam | 23; ! final static int unitcell = setparam | 24; ! final static int vectps = setparam | 25; // write // chime set parameters ! final static int charge = setparam | 26; ! final static int clear = setparam | 27; ! final static int gaussian = setparam | 28; // load ! final static int mep = setparam | 29; ! final static int mlp = setparam | 30 | showparam; ! final static int molsurface = setparam | 31; ! final static int information = showparam | 0; ! final static int phipsi = showparam | 1; // center centre ! final static int ramprint = showparam | 2; ! final static int rotation = showparam | 3; // selected ! final static int group = showparam | 4; ! final static int chain = showparam | 5; ! final static int atom = showparam | 6; ! final static int sequence = showparam | 7; ! final static int symmetry = showparam | 8; ! final static int translation = showparam | 9; // zoom // chime show parameters ! final static int residue = showparam | 10; ! final static int model = showparam | 11; // mlp // list --- 89,213 ---- // rasmol commands ! // backbone ! final static int background = command | 0 | colorparam | setspecial; ! final static int bond = command | 1 | bool; ! final static int cartoon = command | 2 | setspecial; ! final static int center = command | 3 | showparam | expression; ! final static int clipboard = command | 4; ! final static int color = command | 5 | colorparam; ! final static int connect = command | 6 | bool; ! final static int cpk = command | 7; ! final static int define = command | 8 | expression; ! final static int dots = command | 9 | bool; ! final static int echo = command | 10 | specialstring; ! final static int exit = command | 11; ! final static int hbonds = command | 12 | setparam | bool; ! final static int help = command | 13; ! final static int label = command | 14 | bool; // FIXME -- why did I have load tagged as a setparam? ! final static int load = command | 15 | specialstring; // setparam; ! final static int molecule = command | 16; ! final static int monitor = command | 17 | setspecial | bool; ! final static int pause = command | 18; ! final static int print = command | 19; ! final static int quit = command | 20; ! final static int refresh = command | 21; ! final static int renumber = command | 22 | negativeints; ! final static int reset = command | 23; ! final static int restrict = command | 24 | expression; ! final static int ribbons = command | 25 | bool; ! final static int rotate = command | 26 | bool | negativeints; ! final static int save = command | 27; ! final static int script = command | 28 | specialstring; ! final static int select = command | 29 | expression; ! final static int set = command | 30 | bool | negativeints; ! final static int show = command | 31; ! final static int slab = command | 32 | bool; ! final static int source = command | 33 | specialstring; ! final static int spacefill = command | 34 | bool; ! final static int ssbonds = command | 35 | setparam | bool; ! final static int star = command | 36 | bool; ! final static int stereo = command | 37 | setspecial | bool | negativeints; ! final static int strands = command | 38 | setspecial | bool; ! final static int structure = command | 39; ! final static int trace = command | 40 | bool; ! final static int translate = command | 41 | negativeints; ! final static int unbond = command | 42; ! final static int wireframe = command | 43 | bool; ! final static int write = command | 44 | setparam; ! final static int zap = command | 45; ! final static int zoom = command | 46 | showparam | bool; // chime commands ! final static int delay = command | 47; ! final static int loop = command | 48; ! final static int move = command | 49 | negativeints; ! final static int view = command | 50; ! final static int restore = command | 51; ! final static int spin = command | 52 | showparam | bool; ! final static int list = command | 53 | showparam; ! final static int display3d = command | 54; // parameters ! final static int ambient = setparam | 0; ! final static int axes = setparam | 1; // background ! final static int backfade = setparam | 2; ! final static int bondmode = setparam | 3; ! final static int bonds = setparam | 4; ! final static int boundbox = setparam | 5; // cartoon ! final static int cisangle = setparam | 6; ! final static int display = setparam | 7; ! final static int fontsize = setparam | 8; ! final static int fontstroke = setparam | 9; // hbonds ! // hetero ! final static int hourglass = setparam | 10; ! // hydrogen ! final static int kinemage = setparam | 11; ! final static int menus = setparam | 12; // monitor ! final static int mouse = setparam | 13; ! final static int picking = setparam | 14; ! final static int radius = setparam | 15 | atomproperty; ! final static int shadow = setparam | 16; ! final static int slabmode = setparam | 17; ! // solvent ! final static int specular = setparam | 18; ! final static int specpower = setparam | 19; // ssbonds // stereo // strands ! final static int transparent = setparam | 20; ! final static int unitcell = setparam | 21; ! final static int vectps = setparam | 22; // write // chime set parameters ! final static int charge = setparam | 23; ! final static int clear = setparam | 24; ! final static int gaussian = setparam | 25; // load ! final static int mep = setparam | 26; ! final static int mlp = setparam | 27 | showparam; ! final static int molsurface = setparam | 28; ! final static int information = showparam | 0; ! final static int phipsi = showparam | 1; // center centre ! final static int ramprint = showparam | 2; ! final static int rotation = showparam | 3; // selected ! final static int group = showparam | 4; ! final static int chain = showparam | 5; ! final static int atom = showparam | 6; ! final static int sequence = showparam | 7; ! final static int symmetry = showparam | 8; ! final static int translation = showparam | 9; // zoom // chime show parameters ! final static int residue = showparam | 10; ! final static int model = showparam | 11; // mlp // list *************** *** 216,260 **** // atom expression operators ! final static int leftparen = expression | 0; ! final static int rightparen = expression | 1; ! final static int hyphen = expression | 2; ! final static int opAnd = expression | 3; ! final static int opOr = expression | 4; ! final static int opNot = expression | 5; ! final static int within = expression | 12; ! final static int plus = expression | 13; ! final static int pick = expression | 14; ! ! final static int atomno = atomproperty | 0; ! final static int elemno = atomproperty | 1; ! final static int resno = atomproperty | 2; // radius; ! final static int temperature = atomproperty | 3; ! final static int opGT = comparator | 0; ! final static int opGE = comparator | 1; ! final static int opLE = comparator | 2; ! final static int opLT = comparator | 3; ! final static int opEQ = comparator | 4; ! final static int opNE = comparator | 5; ! ! final static int off = bool | 0; ! final static int on = bool | 1; ! ! final static int dash = misc | 0; //backbone ! final static int user = misc | 1; //spacefill & star ! final static int x = misc | 2; ! final static int y = misc | 3; ! final static int z = misc | 4; ! final static int none = misc | 5 | expression; ! final static int normal = misc | 7; ! final static int rasmol = misc | 8; ! final static int insight = misc | 9; ! final static int quanta = misc | 10; ! final static int ident = misc | 11; ! final static int distance = misc | 12; ! final static int angle = misc | 13; ! final static int torsion = misc | 14; ! final static int coord = misc | 15; final static int at = predefinedset | 0; --- 216,260 ---- // atom expression operators ! final static int leftparen = expression | 0; ! final static int rightparen = expression | 1; ! final static int hyphen = expression | 2; ! final static int opAnd = expression | 3; ! final static int opOr = expression | 4; ! final static int opNot = expression | 5; ! final static int within = expression | 12; ! final static int plus = expression | 13; ! final static int pick = expression | 14; ! ! final static int atomno = atomproperty | 0; ! final static int elemno = atomproperty | 1; ! final static int resno = atomproperty | 2; // radius; ! final static int temperature = atomproperty | 3; ! final static int opGT = comparator | 0; ! final static int opGE = comparator | 1; ! final static int opLE = comparator | 2; ! final static int opLT = comparator | 3; ! final static int opEQ = comparator | 4; ! final static int opNE = comparator | 5; ! ! final static int off = bool | 0; ! final static int on = bool | 1; ! ! final static int dash = misc | 0; //backbone ! final static int user = misc | 1; //spacefill & star ! final static int x = misc | 2; ! // y ! final static int z = misc | 4; ! final static int none = misc | 5 | expression; ! final static int normal = misc | 7; ! final static int rasmol = misc | 8; ! final static int insight = misc | 9; ! final static int quanta = misc | 10; ! final static int ident = misc | 11; ! final static int distance = misc | 12; ! final static int angle = misc | 13; ! final static int torsion = misc | 14; ! final static int coord = misc | 15; final static int at = predefinedset | 0; *************** *** 265,319 **** final static int amino = predefinedset | 5; final static int aromatic = predefinedset | 6; ! // backbone ! final static int basic = predefinedset | 7; ! final static int bonded = predefinedset | 8; ! final static int buried = predefinedset | 9; ! final static int cg = predefinedset | 10; ! final static int charged = predefinedset | 11; ! final static int cyclic = predefinedset | 12; ! final static int cystine = predefinedset | 13; ! final static int helix = predefinedset | 14; ! // hetero ! // hydrogen ! final static int hydrophobic = predefinedset | 15; ! final static int ions = predefinedset | 16; ! final static int large = predefinedset | 17; ! final static int ligand = predefinedset | 18; ! final static int medium = predefinedset | 19; ! final static int neutral = predefinedset | 20; ! final static int nucleic = predefinedset | 21; ! final static int polar = predefinedset | 22; ! final static int protein = predefinedset | 23; ! final static int purine = predefinedset | 24; ! final static int pyrimidine = predefinedset | 25; ! final static int selected = predefinedset | 26 | showparam; ! final static int sheet = predefinedset | 27; ! final static int sidechain = predefinedset | 28; ! final static int small = predefinedset | 29; ! // solvent ! final static int surface = predefinedset | 30; ! final static int turn = predefinedset | 31; ! final static int water = predefinedset | 32; // amino acids ! final static int ala = predefinedset | 33; ! final static int arg = predefinedset | 34; ! final static int asn = predefinedset | 35; ! final static int asp = predefinedset | 36; ! final static int cys = predefinedset | 37; ! final static int glu = predefinedset | 38; ! final static int gln = predefinedset | 39; ! final static int gly = predefinedset | 40; ! final static int his = predefinedset | 41; ! final static int ile = predefinedset | 42; ! final static int leu = predefinedset | 43; ! final static int lys = predefinedset | 44; ! final static int met = predefinedset | 45; ! final static int phe = predefinedset | 46; ! final static int pro = predefinedset | 47; ! final static int ser = predefinedset | 48; ! final static int thr = predefinedset | 49; ! final static int trp = predefinedset | 50; ! final static int tyr = predefinedset | 51; ! final static int val = predefinedset | 52; final static int black = colorparam | 0; --- 265,320 ---- final static int amino = predefinedset | 5; final static int aromatic = predefinedset | 6; ! final static int backbone = predefinedset | 7 | command | bool; ! final static int basic = predefinedset | 8; ! final static int bonded = predefinedset | 9; ! final static int buried = predefinedset | 10; ! final static int cg = predefinedset | 11; ! final static int charged = predefinedset | 12; ! final static int cyclic = predefinedset | 13; ! final static int cystine = predefinedset | 14; ! final static int helix = predefinedset | 15; ! final static int hetero = predefinedset | 16 | setparam; ! final static int hydrogen = predefinedset | 17 | setparam; ! final static int hydrophobic = predefinedset | 18; ! final static int ions = predefinedset | 19; ! final static int large = predefinedset | 20; ! final static int ligand = predefinedset | 21; ! final static int medium = predefinedset | 22; ! final static int neutral = predefinedset | 23; ! final static int nucleic = predefinedset | 24; ! final static int polar = predefinedset | 25; ! final static int protein = predefinedset | 26; ! final static int purine = predefinedset | 27; ! final static int pyrimidine = predefinedset | 28; ! final static int selected = predefinedset | 29 | showparam; ! final static int sheet = predefinedset | 30; ! final static int sidechain = predefinedset | 31; ! final static int small = predefinedset | 32; ! final static int solvent = predefinedset | 33 | setparam; ! final static int surface = predefinedset | 34; ! final static int turn = predefinedset | 35; ! final static int water = predefinedset | 36; // amino acids ! final static int ala = predefinedset | 37; ! final static int arg = predefinedset | 38; ! final static int asn = predefinedset | 39; ! final static int asp = predefinedset | 40; ! final static int cys = predefinedset | 41; ! final static int glu = predefinedset | 42; ! final static int gln = predefinedset | 43; ! final static int gly = predefinedset | 44; ! final static int his = predefinedset | 45; ! final static int ile = predefinedset | 46; ! final static int leu = predefinedset | 47; ! final static int lys = predefinedset | 48; ! final static int met = predefinedset | 49; ! final static int phe = predefinedset | 50; ! final static int pro = predefinedset | 51; ! final static int ser = predefinedset | 52; ! final static int thr = predefinedset | 53; ! final static int trp = predefinedset | 54; ! final static int y = predefinedset | 55 | misc; ! final static int tyr = y; ! final static int val = predefinedset | 56; final static int black = colorparam | 0; *************** *** 344,348 **** final static Object[] arrayPairs = { // commands ! "backbone", new Token(backbone, "backbone"), "background", new Token(background, "background"), "bond", new Token(bond, "bond"), --- 345,349 ---- final static Object[] arrayPairs = { // commands ! // backbone "background", new Token(background, "background"), "bond", new Token(bond, "bond"), *************** *** 416,422 **** "fontsize", new Token(fontsize, "fontsize"), "fontstroke", new Token(fontstroke, "fontstroke"), ! "hetero", new Token(hetero, "hetero"), "hourglass", new Token(hourglass, "hourglass"), ! "hydrogen", new Token(hydrogen, "hydrogen"), "kinemage", new Token(kinemage, "kinemage"), "menus", new Token(menus, "menus"), --- 417,423 ---- "fontsize", new Token(fontsize, "fontsize"), "fontstroke", new Token(fontstroke, "fontstroke"), ! // hetero "hourglass", new Token(hourglass, "hourglass"), ! // hydrogen "kinemage", new Token(kinemage, "kinemage"), "menus", new Token(menus, "menus"), *************** *** 426,430 **** "shadow", new Token(shadow, "shadow"), "slabmode", new Token(slabmode, "slabmode"), ! "solvent", new Token(solvent, "solvent"), "specular", new Token(specular, "specular"), "specpower", new Token(specpower, "specpower"), --- 427,431 ---- "shadow", new Token(shadow, "shadow"), "slabmode", new Token(slabmode, "slabmode"), ! // solvent "specular", new Token(specular, "specular"), "specpower", new Token(specpower, "specpower"), *************** *** 512,581 **** "amino", new Token(amino, "amino"), "aromatic", new Token(aromatic, "aromatic"), "basic", new Token(basic, "basic"), "bonded", new Token(bonded, "bonded"), "buried", new Token(buried, "buried"), ! "cg", new Token(cg, "cg"), ! "charged", new Token(charged, "charged"), ! "cyclic", new Token(cyclic, "cyclic"), ! "cystine", new Token(cystine, "cystine"), ! "helix", new Token(helix, "helix"), ! "hydrophobic", new Token(hydrophobic, "hydrophobic"), ! "ions", new Token(ions, "ions"), ! "large", new Token(large, "large"), ! "ligand", new Token(ligand, "ligand"), ! "medium", new Token(medium, "medium"), ! "neutral", new Token(neutral, "neutral"), ! "nucleic", new Token(nucleic, "nucleic"), ! "polar", new Token(polar, "polar"), ! "protein", new Token(protein, "protein"), ! "purine", new Token(purine, "purine"), ! "pyrimidine", new Token(pyrimidine, "pyrimidine"), ! "selected", new Token(selected, "selected"), ! "sheet", new Token(sheet, "sheet"), ! "sidechain", new Token(sidechain, "sidechain"), ! "small", new Token(small, "small"), ! "surface", new Token(surface, "surface"), ! "turn", new Token(turn, "turn"), ! "water", new Token(water, "water"), ! "ala", new Token(ala, "ala"), "a", null, ! "arg", new Token(arg, "arg"), "r", null, ! "asn", new Token(asn, "asn"), "n", null, ! "asp", new Token(asp, "asp"), "d", null, ! "cys", new Token(cys, "cys"), "c", null, ! "glu", new Token(glu, "glu"), "e", null, ! "gln", new Token(gln, "gln"), "q", null, ! "gly", new Token(gly, "gly"), "g", null, ! "his", new Token(his, "his"), "h", null, ! "ile", new Token(ile, "ile"), "i", null, ! "leu", new Token(leu, "leu"), "l", null, ! "lys", new Token(lys, "lys"), "k", null, ! "met", new Token(met, "met"), "m", null, ! "phe", new Token(phe, "phe"), "f", null, ! "pro", new Token(pro, "pro"), "p", null, ! "ser", new Token(ser, "ser"), "s", null, ! "thr", new Token(thr, "thr"), "t", null, ! "trp", new Token(trp, "trp"), "w", null, ! "tyr", new Token(tyr, "tyr"), ! // "y", new Token(tyr, "y"), // what to do about this? ! "val", new Token(val, "val"), "v", null, --- 513,586 ---- "amino", new Token(amino, "amino"), "aromatic", new Token(aromatic, "aromatic"), + "backbone", new Token(backbone, "backbone"), "basic", new Token(basic, "basic"), "bonded", new Token(bonded, "bonded"), "buried", new Token(buried, "buried"), ! "cg", new Token(cg, "cg"), ! "charged", new Token(charged, "charged"), ! "cyclic", new Token(cyclic, "cyclic"), ! "cystine", new Token(cystine, "cystine"), ! "helix", new Token(helix, "helix"), ! "hetero", new Token(hetero, "hetero"), ! "hydrogen", new Token(hydrogen, "hydrogen"), ! "hydrophobic", new Token(hydrophobic, "hydrophobic"), ! "ions", new Token(ions, "ions"), ! "large", new Token(large, "large"), ! "ligand", new Token(ligand, "ligand"), ! "medium", new Token(medium, "medium"), ! "neutral", new Token(neutral, "neutral"), ! "nucleic", new Token(nucleic, "nucleic"), ! "polar", new Token(polar, "polar"), ! "protein", new Token(protein, "protein"), ! "purine", new Token(purine, "purine"), ! "pyrimidine", new Token(pyrimidine, "pyrimidine"), ! "selected", new Token(selected, "selected"), ! "sheet", new Token(sheet, "sheet"), ! "sidechain", new Token(sidechain, "sidechain"), ! "small", new Token(small, "small"), ! "solvent", new Token(solvent, "solvent"), ! "surface", new Token(surface, "surface"), ! "turn", new Token(turn, "turn"), ! "water", new Token(water, "water"), ! "ala", new Token(ala, "ala"), "a", null, ! "arg", new Token(arg, "arg"), "r", null, ! "asn", new Token(asn, "asn"), "n", null, ! "asp", new Token(asp, "asp"), "d", null, ! "cys", new Token(cys, "cys"), "c", null, ! "glu", new Token(glu, "glu"), "e", null, ! "gln", new Token(gln, "gln"), "q", null, ! "gly", new Token(gly, "gly"), "g", null, ! "his", new Token(his, "his"), "h", null, ! "ile", new Token(ile, "ile"), "i", null, ! "leu", new Token(leu, "leu"), "l", null, ! "lys", new Token(lys, "lys"), "k", null, ! "met", new Token(met, "met"), "m", null, ! "phe", new Token(phe, "phe"), "f", null, ! "pro", new Token(pro, "pro"), "p", null, ! "ser", new Token(ser, "ser"), "s", null, ! "thr", new Token(thr, "thr"), "t", null, ! "trp", new Token(trp, "trp"), "w", null, ! "tyr", new Token(tyr, "tyr"), ! "y", new Token(y, "y"), ! "val", new Token(val, "val"), "v", null, |
From: Michael T H. <mic...@us...> - 2002-12-26 01:14:08
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol In directory sc8-pr-cvs1:/tmp/cvs-serv28433/src/org/openscience/jmol Modified Files: Atom.java DisplayControl.java Log Message: continued development on scripting. atom expressions are now limping! Index: Atom.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/Atom.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -r1.36 -r1.37 *** Atom.java 13 Dec 2002 23:54:54 -0000 1.36 --- Atom.java 26 Dec 2002 01:14:03 -0000 1.37 *************** *** 76,79 **** --- 76,83 ---- } + public double getVdwRadius() { + return atomType.getBaseAtomType().getVdwRadius(); + } + /** * Returns whether this atom is a hydrogen atom. Index: DisplayControl.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/DisplayControl.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -r1.26 -r1.27 *** DisplayControl.java 25 Dec 2002 22:05:53 -0000 1.26 --- DisplayControl.java 26 Dec 2002 01:14:03 -0000 1.27 *************** *** 38,41 **** --- 38,42 ---- import java.awt.Dimension; import java.util.Hashtable; + import java.util.BitSet; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; *************** *** 299,303 **** } ! private SelectionSet setPicked = new SelectionSet(); public void addSelection(Atom atom) { --- 300,304 ---- } ! private final SelectionSet setPicked = new SelectionSet(); public void addSelection(Atom atom) { *************** *** 349,354 **** } ! public void setSelectionSet(SelectionSet set) { ! setPicked = set; recalc(); } --- 350,359 ---- } ! public void setSelectionSet(BitSet set) { ! clearSelection(); ! int num = numberOfAtoms(); // FIXME -- probably should store this someplace ! for (int i = 0; i < num; ++i) ! if (set.get(i)) ! setPicked.addSelection(i); recalc(); } |
From: Michael T H. <mic...@us...> - 2002-12-26 01:14:08
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/script In directory sc8-pr-cvs1:/tmp/cvs-serv28433/src/org/openscience/jmol/script Modified Files: Eval.java Token.java Log Message: continued development on scripting. atom expressions are now limping! Index: Eval.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/script/Eval.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** Eval.java 25 Dec 2002 22:05:55 -0000 1.1 --- Eval.java 26 Dec 2002 01:14:03 -0000 1.2 *************** *** 26,32 **** import org.openscience.jmol.DisplayControl; ! import org.openscience.jmol.SelectionSet; import java.io.*; import java.awt.Color; public class Eval { --- 26,35 ---- import org.openscience.jmol.DisplayControl; ! import org.openscience.jmol.ChemFrame; ! import org.openscience.jmol.Atom; import java.io.*; import java.awt.Color; + import java.util.BitSet; + import java.util.Hashtable; public class Eval { *************** *** 111,114 **** --- 114,120 ---- background(); break; + case Token.define: + define(); + break; case Token.echo: echo(); *************** *** 136,140 **** case Token.connect: case Token.cpk: - case Token.define: case Token.dots: case Token.exit: --- 142,145 ---- *************** *** 196,200 **** void UnrecognizedExpression() throws ScriptException { ! throw new ScriptException("unrecognized expression"); } --- 201,209 ---- void UnrecognizedExpression() throws ScriptException { ! throw new ScriptException("runtime unrecognized expression"); ! } ! ! void UndefinedVariable() throws ScriptException { ! throw new ScriptException("variable undefined"); } *************** *** 203,235 **** } ! SelectionSet expression(int iStart) throws ScriptException { ! // FIXME -- this is a mega-kludge - need a real expression evaluator ! int lastInt = 0; ! boolean rangeSelection = false; ! SelectionSet set = new SelectionSet(); ! for (int i = iStart; i < statement.length; ++i) { ! System.out.println("expression token:" + statement[i]); ! switch (statement[i].tok) { case Token.all: ! for (int j = 0, num = control.numberOfAtoms(); j < num; ++j) ! set.addSelection(j); break; case Token.none: ! set.clearSelection(); break; case Token.integer: ! int thisInt = statement[i].intValue; ! if (rangeSelection) { ! for (int j = lastInt + 1; j <= thisInt - 1; ++j) ! set.addSelection(j); ! rangeSelection = false; ! } ! set.addSelection(thisInt); ! lastInt = thisInt; break; case Token.opOr: break; case Token.hyphen: ! rangeSelection = true; break; default: --- 212,280 ---- } ! BitSet expression(Token[] code, int pcStart) throws ScriptException { ! int numberOfAtoms = control.numberOfAtoms(); ! BitSet bs; ! BitSet[] stack = new BitSet[10]; ! int sp = 0; ! for (int pc = pcStart; pc < code.length; ++pc) { ! Token instruction = code[pc]; ! switch (instruction.tok) { case Token.all: ! bs = stack[sp++] = new BitSet(numberOfAtoms); ! for (int i = 0; i < numberOfAtoms; ++i) ! bs.set(i); break; case Token.none: ! stack[sp++] = new BitSet(); break; case Token.integer: ! int thisInt = instruction.intValue; ! bs = new BitSet(); ! if (thisInt >= 0 && thisInt < numberOfAtoms) ! bs.set(thisInt); ! stack[sp++] = bs; break; case Token.opOr: + bs = stack[--sp]; + stack[sp-1].or(bs); + break; + case Token.opAnd: + bs = stack[--sp]; + stack[sp-1].and(bs); + break; + case Token.opNot: + bs = stack[sp - 1]; + for (int i = 0; i < numberOfAtoms; ++i) { + if (bs.get(i)) + bs.clear(i); + else + bs.set(i); + } break; case Token.hyphen: ! int min = instruction.intValue; ! int last = ((Integer)instruction.value).intValue(); ! int max = last + 1; ! if (max > numberOfAtoms) ! max = numberOfAtoms; ! bs = stack[sp++] = new BitSet(max); ! for (int i = min; i < max; ++i) ! bs.set(i); ! break; ! case Token.identifier: ! String variable = (String)instruction.value; ! Token[] definition = (Token[])variables.get(variable); ! if (definition == null) ! UndefinedVariable(); ! stack[sp++] = expression(definition, 2); ! break; ! case Token.opLT: ! case Token.opLE: ! case Token.opGE: ! case Token.opGT: ! case Token.opEQ: ! case Token.opNE: ! bs = stack[sp++] = new BitSet(); ! comparatorInstruction(instruction, bs); break; default: *************** *** 237,241 **** } } ! return set; } --- 282,342 ---- } } ! if (sp != 1) ! throw new ScriptException("atom expression compiler error" + ! " - stack over/underflow"); ! return stack[0]; ! } ! ! void comparatorInstruction(Token instruction, BitSet bs) ! throws ScriptException { ! int comparator = instruction.tok; ! int property = instruction.intValue; ! int propertyValue = 0; ! int comparisonValue = ((Integer)instruction.value).intValue(); ! int numberOfAtoms = control.numberOfAtoms(); ! ChemFrame frame = control.getFrame(); ! for (int i = 0; i < numberOfAtoms; ++i) { ! Atom atom = frame.getAtomAt(i); ! switch (property) { ! case Token.atomno: ! propertyValue = i; ! break; ! case Token.elemno: ! propertyValue = atom.getAtomicNumber(); ! break; ! case Token.temperature: ! case Token.resno: ! // FIXME -- what is resno? ! propertyValue = -1; ! break; ! case Token.radius: ! // FIXME -- confirm that RasMol units are 250 per angstrom ! propertyValue = (int)(atom.getVdwRadius() * 250); ! break; ! } ! boolean match = false; ! switch (comparator) { ! case Token.opLT: ! match = propertyValue < comparisonValue; ! break; ! case Token.opLE: ! match = propertyValue <= comparisonValue; ! break; ! case Token.opGE: ! match = propertyValue >= comparisonValue; ! break; ! case Token.opGT: ! match = propertyValue > comparisonValue; ! break; ! case Token.opEQ: ! match = propertyValue == comparisonValue; ! break; ! case Token.opNE: ! match = propertyValue != comparisonValue; ! break; ! } ! if (match) ! bs.set(i); ! } } *************** *** 275,278 **** --- 376,386 ---- } + Hashtable variables = new Hashtable(); + + void define() throws ScriptException { + String variable = (String)statement[1].value; + variables.put(variable, statement); + } + void echo() throws ScriptException { if (statement.length == 2 && statement[1].tok == Token.string) *************** *** 334,338 **** // FIXME -- what is behavior when there are no arguments to select } else { ! control.setSelectionSet(expression(1)); } } --- 442,446 ---- // FIXME -- what is behavior when there are no arguments to select } else { ! control.setSelectionSet(expression(statement, 1)); } } Index: Token.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/script/Token.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** Token.java 25 Dec 2002 22:05:55 -0000 1.1 --- Token.java 26 Dec 2002 01:14:03 -0000 1.2 *************** *** 35,39 **** int tok; Object value; ! int intValue; static String str; --- 35,39 ---- int tok; Object value; ! int intValue = Integer.MAX_VALUE; static String str; *************** *** 64,69 **** final static String[] astrType = { ! "nada", "identifier", "integer", "decimal", "string", "unknown", "keyword", ! "range" }; --- 64,68 ---- final static String[] astrType = { ! "nada", "identifier", "integer", "decimal", "string", "unknown", "keyword" }; *************** *** 676,679 **** --- 675,680 ---- Token[] atoken = new Token[ltoken.size()]; ltoken.copyInto(atoken); + if ((atoken[0].tok & expression) != 0) + atoken = compileExpression(atoken); lltoken.add(atoken); ltoken.setSize(0); *************** *** 711,717 **** String ident = m.group().toLowerCase(); Token token = (Token) map.get(ident); ! if (token == null) { ! throw new ScriptException("get to work buddy:" + ident); ! } switch (tokCommand) { case nada: --- 712,717 ---- String ident = m.group().toLowerCase(); Token token = (Token) map.get(ident); ! if (token == null) ! token = new Token(identifier, ident); switch (tokCommand) { case nada: *************** *** 738,744 **** break; case define: ! if ((ltoken.size() == 1) && (token == null)) ! token = new Token(Token.identifier, ident); ! else if ((ltoken.size() >= 2) && ((token.tok & expression) == 0)) throw new ScriptException("Invalid expression token:" + ident); break; --- 738,742 ---- break; case define: ! if ((ltoken.size() >= 2) && ((token.tok & expression) == 0)) throw new ScriptException("Invalid expression token:" + ident); break; *************** *** 746,750 **** case restrict: case select: ! if ((token.tok & expression) == 0) throw new ScriptException("Invalid expression token:" + ident); break; --- 744,748 ---- case restrict: case select: ! if (token.tok != identifier && (token.tok & expression) == 0) throw new ScriptException("Invalid expression token:" + ident); break; *************** *** 765,769 **** public String toString() { return "Token[" + astrType[tok<=keyword ? tok : keyword] + ! ":" + value + "]"; } --- 763,769 ---- public String toString() { return "Token[" + astrType[tok<=keyword ? tok : keyword] + ! "-" + tok + ! ((intValue == Integer.MAX_VALUE) ? "" : ":" + intValue) + ! ((value == null) ? "" : ":" + value) + "]"; } *************** *** 785,788 **** --- 785,789 ---- clausePrimitive ::= clauseInteger | clauseComparator | + all | none | identifier ( clauseOr ) *************** *** 793,796 **** --- 794,805 ---- */ + public static Token[] compileExpression(Token[] atoken) + throws ScriptException { + int i = 1; + if (atoken[0].tok == define) + i = 2; + return compileExpression(atoken, i); + } + static Vector ltokenPostfix = null; static Token[] atokenInfix; *************** *** 800,803 **** --- 809,814 ---- throws ScriptException { ltokenPostfix = new Vector(); + for (int i = 0; i < itoken; ++i) + ltokenPostfix.add(atoken[i]); atokenInfix = atoken; itokenInfix = itoken; *************** *** 807,810 **** --- 818,826 ---- Token[] atokenPostfix = new Token[ltokenPostfix.size()]; ltokenPostfix.copyInto(atokenPostfix); + System.out.println("compiled expression:"); + for (int i = 0; i < atokenPostfix.length; ++i) { + System.out.print(" " + atokenPostfix[i]); + } + System.out.println(""); return atokenPostfix; } *************** *** 862,865 **** --- 878,883 ---- clauseComparator(); break; + case all: + case none: case identifier: ltokenPostfix.add(tokenNext()); *************** *** 904,907 **** --- 922,927 ---- Token tokenValue = tokenNext(); int val = tokenValue.intValue; + System.out.println("atomProperty=" + tokenAtomProperty + + " comparator=" + tokenComparator); ltokenPostfix.add(new Token(tokenComparator.tok, tokenAtomProperty.tok, |
From: Michael T H. <mic...@us...> - 2002-12-25 22:05:59
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/script In directory sc8-pr-cvs1:/tmp/cvs-serv24573/src/org/openscience/jmol/script Modified Files: ScriptWindow.java Added Files: Eval.java ScriptException.java Token.java Removed Files: RasMolScriptException.java RasMolScriptHandler.java Log Message: initial check-in of new script interpreter framework --- NEW FILE: Eval.java --- /* $RCSfile: Eval.java,v $ * $Author: michaelthoward $ * $Date: 2002/12/25 22:05:55 $ * $Revision: 1.1 $ * * Copyright (C) 2002 The Jmol Development Team * * Contact: jmo...@li... * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. */ package org.openscience.jmol.script; import org.openscience.jmol.DisplayControl; import org.openscience.jmol.SelectionSet; import java.io.*; import java.awt.Color; public class Eval { Token[][] aatoken; int iStatement; Token[] statement; DisplayControl control; String filename; final static int scriptLevelMax = 10; int scriptLevel; public Eval(DisplayControl control) { this.control = control; } void load(String filename, String script) throws ScriptException { this.filename = filename; iStatement = 0; aatoken = Token.tokenize(script); } void executeString(String script) throws ScriptException { load(null, script); run(); } public void executeFile(String filename) throws ScriptException { executeFile(filename, 0); } void executeFile(String filename, int scriptLevel) throws ScriptException { this.scriptLevel = scriptLevel; if (scriptLevel == scriptLevelMax) throw new ScriptException("too many script levels:" + filename); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(filename)); } catch (FileNotFoundException e) { throw new ScriptException("file not found:" + filename); } String script = ""; try { while (true) { String command = reader.readLine(); if (command == null) break; script += command + "\n"; } } catch (IOException e) { throw new ScriptException("io error reading file:" + filename); } System.out.println("script:" + script + ":"); load(filename, script); run(); } public String toString() { String str; str = "Eval\n"; str += aatoken.length + " statements\n"; for (int i = 0; i < aatoken.length; ++i) { str += " |"; Token[] atoken = aatoken[i]; for (int j = 0; j < atoken.length; ++j) { str += " " + atoken[j]; } str += "\n"; } str += "END\n"; return str; } void run() throws ScriptException { System.out.println("running!"); System.out.println(toString()); while (iStatement < aatoken.length) { statement = aatoken[iStatement++]; Token token = statement[0]; switch (token.tok) { case Token.background: background(); break; case Token.echo: echo(); break; case Token.load: load(); break; case Token.refresh: break; case Token.rotate: rotate(); break; case Token.script: script(); break; case Token.select: select(); break; case Token.backbone: case Token.bond: case Token.cartoon: case Token.center: case Token.clipboard: case Token.color: case Token.connect: case Token.cpk: case Token.define: case Token.dots: case Token.exit: case Token.hbonds: case Token.help: case Token.label: case Token.molecule: case Token.monitor: case Token.pause: case Token.print: case Token.quit: case Token.renumber: case Token.reset: case Token.restrict: case Token.ribbons: case Token.save: case Token.set: case Token.show: case Token.slab: case Token.source: case Token.spacefill: case Token.ssbonds: case Token.star: case Token.stereo: case Token.strands: case Token.structure: case Token.trace: case Token.translate: case Token.unbond: case Token.wireframe: case Token.write: case Token.zap: case Token.zoom: System.out.println("Script command not implemented:" + token.value); break; default: System.out.println("Eval error - not a command " + token.value); return; } } System.out.println("done!"); } void FilenameExpected() throws ScriptException { throw new ScriptException("filename expected"); } void IntegerExpected() throws ScriptException { throw new ScriptException("integer expected"); } void AxisExpected() throws ScriptException { throw new ScriptException("x y z axis expected"); } void ColorExpected() throws ScriptException { throw new ScriptException("color expected"); } void UnrecognizedExpression() throws ScriptException { throw new ScriptException("unrecognized expression"); } void BadArgumentCount() throws ScriptException { throw new ScriptException("bad argument count"); } SelectionSet expression(int iStart) throws ScriptException { // FIXME -- this is a mega-kludge - need a real expression evaluator int lastInt = 0; boolean rangeSelection = false; SelectionSet set = new SelectionSet(); for (int i = iStart; i < statement.length; ++i) { System.out.println("expression token:" + statement[i]); switch (statement[i].tok) { case Token.all: for (int j = 0, num = control.numberOfAtoms(); j < num; ++j) set.addSelection(j); break; case Token.none: set.clearSelection(); break; case Token.integer: int thisInt = statement[i].intValue; if (rangeSelection) { for (int j = lastInt + 1; j <= thisInt - 1; ++j) set.addSelection(j); rangeSelection = false; } set.addSelection(thisInt); lastInt = thisInt; break; case Token.opOr: break; case Token.hyphen: rangeSelection = true; break; default: UnrecognizedExpression(); } } return set; } Color colorsRasmol[] = { /* black */ Color.black, /* blue */ Color.blue, /* bluetint */ new Color( 58 << 16 | 144 << 8 | 255), /* brown */ new Color(175 << 16 | 117 << 8 | 89), /* cyan */ Color.cyan, /* gold */ new Color(255 << 16 | 156 << 8 | 0), /* grey */ Color.gray, /* green */ Color.green, /* greenblue */ new Color(0x002E8B57), /* greentint */ new Color(152 << 16 | 214 << 8 | 179), /* hotpink */ new Color(255 << 16 | 0 << 8 | 101), /* magenta */ Color.magenta, /* orange */ Color.orange, /* pink */ Color.pink, /* pinktint */ new Color(255 << 16 | 171 << 8 | 187), /* purple */ new Color(0xA020F0), /* red */ Color.red, /* redorange */ new Color(0x00FF4500), /* seagreen */ new Color( 0 << 16 | 250 << 8 | 109), /* skyblue */ new Color( 58 << 16 | 144 << 8 | 255), /* violet */ new Color(0x00EE82EE), /* white */ Color.white, /* yellow */ Color.yellow, /* yellowtint */ new Color(246 << 16 | 246 << 8 | 117) }; void background() throws ScriptException { if (statement.length != 2) BadArgumentCount(); if ((statement[1].tok & Token.colorparam) == 0) ColorExpected(); control.setBackgroundColor(colorsRasmol[statement[1].intValue]); } void echo() throws ScriptException { if (statement.length == 2 && statement[1].tok == Token.string) control.scriptEcho((String)statement[1].value); else control.scriptEcho(""); } void load() throws ScriptException { if (statement.length != 2) BadArgumentCount(); if (statement[1].tok != Token.string) FilenameExpected(); String filename = (String)statement[1].value; if (!control.openFile(filename)) { // FIXME -- should I throw an exception here? what does rasmol do? } } void refresh() throws ScriptException { if (statement.length != 1) BadArgumentCount(); control.refresh(); } void rotate() throws ScriptException { if (statement.length != 3) BadArgumentCount(); if (statement[2].tok != Token.integer) IntegerExpected(); int degrees = statement[2].intValue; switch (statement[1].tok) { case Token.x: control.rotateByX(degrees); break; case Token.y: control.rotateByY(degrees); break; case Token.z: control.rotateByZ(degrees); break; default: AxisExpected(); } } void script() throws ScriptException { if (statement.length != 2) BadArgumentCount(); if (statement[1].tok != Token.string) FilenameExpected(); String filename = (String)statement[1].value; Eval eval = new Eval(control); eval.executeFile(filename, scriptLevel+1); } void select() throws ScriptException { if (statement.length == 1) { // FIXME -- what is behavior when there are no arguments to select } else { control.setSelectionSet(expression(1)); } } } --- NEW FILE: ScriptException.java --- /* * Copyright 2002 The Jmol Development Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. */ package org.openscience.jmol.script; import org.openscience.jmol.JmolException; public class ScriptException extends JmolException { public ScriptException(String message) { super("ScriptException:", message); } } --- NEW FILE: Token.java --- /* $RCSfile: Token.java,v $ * $Author: michaelthoward $ * $Date: 2002/12/25 22:05:55 $ * $Revision: 1.1 $ * * Copyright (C) 2002 The Jmol Development Team * * Contact: jmo...@li... * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. */ package org.openscience.jmol.script; import java.io.*; import java.util.Hashtable; import java.util.regex.*; import java.util.Vector; class Token { int tok; Object value; int intValue; static String str; static Matcher m; Token(int tok, int intValue, Object value) { this.tok = tok; this.intValue = intValue; this.value = value; } Token(int tok) { this.tok = tok; } Token(int tok, Object value) { this.tok = tok; this.value = value; } final static int nada = 0; final static int identifier = 1; final static int integer = 2; final static int decimal = 3; final static int string = 4; final static int unknown = 5; final static int keyword = 6; final static String[] astrType = { "nada", "identifier", "integer", "decimal", "string", "unknown", "keyword", "range" }; final static int command = (1 << 8); final static int setparam = (1 << 9); // parameter to set command final static int showparam = (1 << 10); // parameter to show command final static int bool = (1 << 11); final static int misc = (1 << 12); // misc parameter final static int expression = (1 << 13); // every property is also valid in an expression context final static int atomproperty = (1 << 14) | expression; // every predefined is also valid in an expression context final static int comparator = (1 << 15) | expression; final static int predefinedset = (1 << 16) | expression; final static int colorparam = (1 << 17); final static int specialstring = (1 << 18); // load and echo // generally, the minus sign is used to denote atom ranges // this property is used for the few commands which allow negative integers final static int negativeints = (1 << 19); // for some commands the 'set' is optional // so, just delete the set command from the token list // but not for hbonds nor ssbonds final static int setspecial = (1 << 20); // rasmol commands final static int backbone = command | 0 | predefinedset | bool; final static int background = command | 1 | colorparam | setspecial; final static int bond = command | 2 | bool; final static int cartoon = command | 3 | setspecial; final static int center = command | 4 | showparam | expression; final static int clipboard = command | 5; final static int color = command | 6 | colorparam; final static int connect = command | 7 | bool; final static int cpk = command | 8; final static int define = command | 9 | expression; final static int dots = command | 10 | bool; final static int echo = command | 11 | specialstring; final static int exit = command | 12; final static int hbonds = command | 13 | setparam | bool; final static int help = command | 14; final static int label = command | 15 | bool; // FIXME -- why did I have load tagged as a setparam? final static int load = command | 16 | specialstring; // setparam; final static int molecule = command | 17; final static int monitor = command | 18 | setspecial | bool; final static int pause = command | 19; final static int print = command | 20; final static int quit = command | 21; final static int refresh = command | 22; final static int renumber = command | 23 | negativeints; final static int reset = command | 24; final static int restrict = command | 25 | expression; final static int ribbons = command | 26 | bool; final static int rotate = command | 27 | bool | negativeints; final static int save = command | 28; final static int script = command | 29 | specialstring; final static int select = command | 30 | expression; final static int set = command | 31 | bool | negativeints; final static int show = command | 32; final static int slab = command | 33 | bool; final static int source = command | 34 | specialstring; final static int spacefill = command | 35 | bool; final static int ssbonds = command | 36 | setparam | bool; final static int star = command | 37 | bool; final static int stereo = command | 38 | setspecial | bool | negativeints; final static int strands = command | 39 | setspecial | bool; final static int structure = command | 40; final static int trace = command | 41 | bool; final static int translate = command | 42 | negativeints; final static int unbond = command | 43; final static int wireframe = command | 44 | bool; final static int write = command | 45 | setparam; final static int zap = command | 46; final static int zoom = command | 47 | showparam | bool; // chime commands final static int delay = command | 48; final static int loop = command | 49; final static int move = command | 50 | negativeints; final static int view = command | 51; final static int restore = command | 52; final static int spin = command | 53 | showparam | bool; final static int list = command | 54 | showparam; final static int display3d = command | 55; // parameters final static int ambient = setparam | 0; final static int axes = setparam | 1; // background final static int backfade = setparam | 2; final static int bondmode = setparam | 3; final static int bonds = setparam | 4; final static int boundbox = setparam | 5; // cartoon final static int cisangle = setparam | 6; final static int display = setparam | 7; final static int fontsize = setparam | 8; final static int fontstroke = setparam | 9; // hbonds final static int hetero = setparam | 10 | predefinedset; final static int hourglass = setparam | 11; final static int hydrogen = setparam | 12 | predefinedset; final static int kinemage = setparam | 13; final static int menus = setparam | 14; // monitor final static int mouse = setparam | 15; final static int picking = setparam | 16; final static int radius = setparam | 17 | atomproperty; final static int shadow = setparam | 18; final static int slabmode = setparam | 19; final static int solvent = setparam | 20 | predefinedset; final static int specular = setparam | 21; final static int specpower = setparam | 22; // ssbonds // stereo // strands final static int transparent = setparam | 23; final static int unitcell = setparam | 24; final static int vectps = setparam | 25; // write // chime set parameters final static int charge = setparam | 26; final static int clear = setparam | 27; final static int gaussian = setparam | 28; // load final static int mep = setparam | 29; final static int mlp = setparam | 30 | showparam; final static int molsurface = setparam | 31; final static int information = showparam | 0; final static int phipsi = showparam | 1; // center centre final static int ramprint = showparam | 2; final static int rotation = showparam | 3; // selected final static int group = showparam | 4; final static int chain = showparam | 5; final static int atom = showparam | 6; final static int sequence = showparam | 7; final static int symmetry = showparam | 8; final static int translation = showparam | 9; // zoom // chime show parameters final static int residue = showparam | 10; final static int model = showparam | 11; // mlp // list // spin final static int all = showparam | 13 | expression; // atom expression operators final static int leftparen = expression | 0; final static int rightparen = expression | 1; final static int hyphen = expression | 2; final static int opAnd = expression | 3; final static int opOr = expression | 4; final static int opNot = expression | 5; final static int within = expression | 12; final static int plus = expression | 13; final static int pick = expression | 14; final static int atomno = atomproperty | 0; final static int elemno = atomproperty | 1; final static int resno = atomproperty | 2; // radius; final static int temperature = atomproperty | 3; final static int opGT = comparator | 0; final static int opGE = comparator | 1; final static int opLE = comparator | 2; final static int opLT = comparator | 3; final static int opEQ = comparator | 4; final static int opNE = comparator | 5; final static int off = bool | 0; final static int on = bool | 1; final static int dash = misc | 0; //backbone final static int user = misc | 1; //spacefill & star final static int x = misc | 2; final static int y = misc | 3; final static int z = misc | 4; final static int none = misc | 5 | expression; final static int normal = misc | 7; final static int rasmol = misc | 8; final static int insight = misc | 9; final static int quanta = misc | 10; final static int ident = misc | 11; final static int distance = misc | 12; final static int angle = misc | 13; final static int torsion = misc | 14; final static int coord = misc | 15; final static int at = predefinedset | 0; final static int acidic = predefinedset | 1; final static int acyclic = predefinedset | 2; final static int aliphatic = predefinedset | 3; final static int alpha = predefinedset | 4; final static int amino = predefinedset | 5; final static int aromatic = predefinedset | 6; // backbone final static int basic = predefinedset | 7; final static int bonded = predefinedset | 8; final static int buried = predefinedset | 9; final static int cg = predefinedset | 10; final static int charged = predefinedset | 11; final static int cyclic = predefinedset | 12; final static int cystine = predefinedset | 13; final static int helix = predefinedset | 14; // hetero // hydrogen final static int hydrophobic = predefinedset | 15; final static int ions = predefinedset | 16; final static int large = predefinedset | 17; final static int ligand = predefinedset | 18; final static int medium = predefinedset | 19; final static int neutral = predefinedset | 20; final static int nucleic = predefinedset | 21; final static int polar = predefinedset | 22; final static int protein = predefinedset | 23; final static int purine = predefinedset | 24; final static int pyrimidine = predefinedset | 25; final static int selected = predefinedset | 26 | showparam; final static int sheet = predefinedset | 27; final static int sidechain = predefinedset | 28; final static int small = predefinedset | 29; // solvent final static int surface = predefinedset | 30; final static int turn = predefinedset | 31; final static int water = predefinedset | 32; // amino acids final static int ala = predefinedset | 33; final static int arg = predefinedset | 34; final static int asn = predefinedset | 35; final static int asp = predefinedset | 36; final static int cys = predefinedset | 37; final static int glu = predefinedset | 38; final static int gln = predefinedset | 39; final static int gly = predefinedset | 40; final static int his = predefinedset | 41; final static int ile = predefinedset | 42; final static int leu = predefinedset | 43; final static int lys = predefinedset | 44; final static int met = predefinedset | 45; final static int phe = predefinedset | 46; final static int pro = predefinedset | 47; final static int ser = predefinedset | 48; final static int thr = predefinedset | 49; final static int trp = predefinedset | 50; final static int tyr = predefinedset | 51; final static int val = predefinedset | 52; final static int black = colorparam | 0; final static int blue = colorparam | 1; final static int bluetint = colorparam | 2; final static int brown = colorparam | 3; final static int cyan = colorparam | 4; final static int gold = colorparam | 5; final static int grey = colorparam | 6; final static int green = colorparam | 7; final static int greenblue = colorparam | 8; final static int greentint = colorparam | 9; final static int hotpink = colorparam | 10; final static int magenta = colorparam | 11; final static int orange = colorparam | 12; final static int pink = colorparam | 13; final static int pinktint = colorparam | 14; final static int purple = colorparam | 15; final static int red = colorparam | 16; final static int redorange = colorparam | 17; final static int seagreen = colorparam | 18; final static int skyblue = colorparam | 19; final static int violet = colorparam | 20; final static int white = colorparam | 21; final static int yellow = colorparam | 22; final static int yellowtint = colorparam | 23; final static Object[] arrayPairs = { // commands "backbone", new Token(backbone, "backbone"), "background", new Token(background, "background"), "bond", new Token(bond, "bond"), "cartoon", new Token(cartoon, "cartoon"), "center", new Token(center, "center"), "centre", null, "clipboard", new Token(clipboard, "clipboard"), "color", new Token(color, "color"), "colour", null, "connect", new Token(connect, "connect"), "cpk", new Token(cpk, "cpk"), "define", new Token(define, "define"), "dots", new Token(dots, "dots"), "echo", new Token(echo, "echo"), "exit", new Token(exit, "exit"), "hbonds", new Token(hbonds, "hbonds"), "help", new Token(help, "help"), "label", new Token(label, "label"), "load", new Token(load, "load"), "molecule", new Token(molecule, "molecule"), "monitor", new Token(monitor, "monitor"), "monitors", null, "pause", new Token(pause, "pause"), "print", new Token(print, "print"), "quit", new Token(quit, "quit"), "refresh", new Token(refresh, "refresh"), "renumber", new Token(renumber, "renumber"), "reset", new Token(reset, "reset"), "restrict", new Token(restrict, "restrict"), "ribbons", new Token(ribbons, "ribbons"), "rotate", new Token(rotate, "rotate"), "save", new Token(save, "save"), "script", new Token(script, "script"), "select", new Token(select, "select"), "set", new Token(set, "set"), "show", new Token(show, "show"), "slab", new Token(slab, "slab"), "source", new Token(source, "source"), "spacefill", new Token(spacefill, "spacefill"), "ssbonds", new Token(ssbonds, "ssbonds"), "star", new Token(star, "star"), "stereo", new Token(stereo, "stereo"), "strands", new Token(strands, "strands"), "structure", new Token(structure, "structure"), "trace", new Token(trace, "trace"), "translate", new Token(translate, "translate"), "unbond", new Token(unbond, "unbond"), "wireframe", new Token(wireframe, "wireframe"), "write", new Token(write, "write"), "zap", new Token(zap, "zap"), "zoom", new Token(zoom, "zoom"), // chime commands "delay", new Token(delay, "delay"), "loop", new Token(loop, "loop"), "move", new Token(move, "move"), "view", new Token(view, "view"), "restore", new Token(restore, "restore"), "spin", new Token(spin, "spin"), "list", new Token(list, "list"), "display3d", new Token(display3d, "display3d"), // setparams "ambient", new Token(ambient, "ambient"), "axes", new Token(axes, "axes"), "backfade", new Token(backfade, "backfade"), "bondmode", new Token(bondmode, "bondmode"), "bonds", new Token(bonds, "bonds"), "boundbox", new Token(boundbox, "boundbox"), "cisangle", new Token(cisangle, "cisangle"), "display", new Token(display, "display"), "fontsize", new Token(fontsize, "fontsize"), "fontstroke", new Token(fontstroke, "fontstroke"), "hetero", new Token(hetero, "hetero"), "hourglass", new Token(hourglass, "hourglass"), "hydrogen", new Token(hydrogen, "hydrogen"), "kinemage", new Token(kinemage, "kinemage"), "menus", new Token(menus, "menus"), "mouse", new Token(mouse, "mouse"), "picking", new Token(picking, "picking"), "radius", new Token(radius, "radius"), "shadow", new Token(shadow, "shadow"), "slabmode", new Token(slabmode, "slabmode"), "solvent", new Token(solvent, "solvent"), "specular", new Token(specular, "specular"), "specpower", new Token(specpower, "specpower"), "transparent", new Token(transparent, "transparent"), "unitcell", new Token(unitcell, "unitcell"), "vectps", new Token(vectps, "vectps"), // chime setparams "charge", new Token(charge, "charge"), "clear", new Token(clear, "clear"), "gaussian", new Token(gaussian, "gaussian"), "mep", new Token(mep, "mep"), "mlp", new Token(mlp, "mlp"), "molsurface", new Token(molsurface, "molsurface"), // show parameters "information", new Token(information, "information"), "phipsi", new Token(phipsi, "phipsi"), "ramprint", new Token(ramprint, "ramprint"), "rotation", new Token(rotation, "rotation"), "sequence", new Token(sequence, "sequence"), "symmetry", new Token(symmetry, "symmetry"), "translation", new Token(translation, "translation"), // chime show parameters "residue", new Token(residue, "residue"), "model", new Token(model, "model"), // atom expressions "(", new Token(leftparen, "("), ")", new Token(rightparen, ")"), "-", new Token(hyphen, "-"), "and", new Token(opAnd, "and"), "&", null, "or", new Token(opOr, "or"), ",", null, "|", null, "not", new Token(opNot, "not"), "!", null, "<", new Token(opLT, "<"), "<=", new Token(opLE, "<="), ">=", new Token(opGE, ">="), ">", new Token(opGT, ">="), "==", new Token(opEQ, "=="), "=", null, "!=", new Token(opNE, "!="), "<>", null, "/=", null, "within", new Token(within, "within"), "+", new Token(plus, "+"), "pick", new Token(pick, "pick"), "atomno", new Token(atomno, "atomno"), "elemno", new Token(elemno, "elemno"), "resno", new Token(resno, "resno"), "temperature", new Token(temperature, "temperature"), "false", new Token(off, "false"), "off", null, "no", null, "true", new Token(on, "true"), "on", null, "yes", null, "dash", new Token(dash, "dash"), "user", new Token(user, "user"), "x", new Token(x, "x"), "y", new Token(y, "y"), "z", new Token(z, "z"), "all", new Token(all, "all"), "*", null, "none", new Token(none, "none"), "normal", new Token(normal, "normal"), "rasmol", new Token(rasmol, "rasmol"), "insight", new Token(insight, "insight"), "quanta", new Token(quanta, "quanta"), "ident", new Token(ident, "ident"), "distance", new Token(distance, "distance"), "angle", new Token(angle, "angle"), "torsion", new Token(torsion, "torsion"), "coord", new Token(coord, "coord"), "at", new Token(at, "at"), "acidic", new Token(acidic, "acidic"), "acyclic", new Token(acyclic, "acyclic"), "aliphatic", new Token(aliphatic, "aliphatic"), "alpha", new Token(alpha, "alpha"), "amino", new Token(amino, "amino"), "aromatic", new Token(aromatic, "aromatic"), "basic", new Token(basic, "basic"), "bonded", new Token(bonded, "bonded"), "buried", new Token(buried, "buried"), "cg", new Token(cg, "cg"), "charged", new Token(charged, "charged"), "cyclic", new Token(cyclic, "cyclic"), "cystine", new Token(cystine, "cystine"), "helix", new Token(helix, "helix"), "hydrophobic", new Token(hydrophobic, "hydrophobic"), "ions", new Token(ions, "ions"), "large", new Token(large, "large"), "ligand", new Token(ligand, "ligand"), "medium", new Token(medium, "medium"), "neutral", new Token(neutral, "neutral"), "nucleic", new Token(nucleic, "nucleic"), "polar", new Token(polar, "polar"), "protein", new Token(protein, "protein"), "purine", new Token(purine, "purine"), "pyrimidine", new Token(pyrimidine, "pyrimidine"), "selected", new Token(selected, "selected"), "sheet", new Token(sheet, "sheet"), "sidechain", new Token(sidechain, "sidechain"), "small", new Token(small, "small"), "surface", new Token(surface, "surface"), "turn", new Token(turn, "turn"), "water", new Token(water, "water"), "ala", new Token(ala, "ala"), "a", null, "arg", new Token(arg, "arg"), "r", null, "asn", new Token(asn, "asn"), "n", null, "asp", new Token(asp, "asp"), "d", null, "cys", new Token(cys, "cys"), "c", null, "glu", new Token(glu, "glu"), "e", null, "gln", new Token(gln, "gln"), "q", null, "gly", new Token(gly, "gly"), "g", null, "his", new Token(his, "his"), "h", null, "ile", new Token(ile, "ile"), "i", null, "leu", new Token(leu, "leu"), "l", null, "lys", new Token(lys, "lys"), "k", null, "met", new Token(met, "met"), "m", null, "phe", new Token(phe, "phe"), "f", null, "pro", new Token(pro, "pro"), "p", null, "ser", new Token(ser, "ser"), "s", null, "thr", new Token(thr, "thr"), "t", null, "trp", new Token(trp, "trp"), "w", null, "tyr", new Token(tyr, "tyr"), // "y", new Token(tyr, "y"), // what to do about this? "val", new Token(val, "val"), "v", null, "black", new Token(black, black &(colorparam-1), "black"), "blue", new Token(blue, blue &(colorparam-1), "blue"), "bluetint", new Token(bluetint, bluetint &(colorparam-1), "bluetint"), "brown", new Token(brown, brown &(colorparam-1), "brown"), "cyan", new Token(cyan, cyan &(colorparam-1), "cyan"), "gold", new Token(gold, gold &(colorparam-1), "gold"), "grey", new Token(grey, grey &(colorparam-1), "grey"), "green", new Token(green, green &(colorparam-1), "green"), "greenblue", new Token(greenblue, greenblue &(colorparam-1), "greenblue"), "greentint", new Token(greentint, greentint &(colorparam-1), "greentint"), "hotpink", new Token(hotpink, hotpink &(colorparam-1), "hotpink"), "magenta", new Token(magenta, magenta &(colorparam-1), "magenta"), "orange", new Token(orange, orange &(colorparam-1), "orange"), "pink", new Token(pink, pink &(colorparam-1), "pink"), "pinktint", new Token(pinktint, pinktint &(colorparam-1), "pinktint"), "purple", new Token(purple, purple &(colorparam-1), "purple"), "red", new Token(red, red &(colorparam-1), "red"), "redorange", new Token(redorange, redorange &(colorparam-1), "redorange"), "seagreen", new Token(seagreen, seagreen &(colorparam-1), "seagreen"), "skyblue", new Token(skyblue, skyblue &(colorparam-1), "skyblue"), "violet", new Token(violet, violet &(colorparam-1), "violet"), "white", new Token(white, white &(colorparam-1), "white"), "yellow", new Token(yellow, yellow &(colorparam-1), "yellow"), "yellowtint", new Token(yellowtint,yellowtint&(colorparam-1), "yellowtint") }; static Hashtable map = new Hashtable(); static { Token tokenLast = null; String stringThis; Token tokenThis; for (int i = 0; i + 1 < arrayPairs.length; i += 2) { stringThis = (String) arrayPairs[i]; tokenThis = (Token) arrayPairs[i + 1]; if (tokenThis == null) tokenThis = tokenLast; if (map.get(stringThis) != null) System.out.println("duplicate token definition:" + stringThis); map.put(stringThis, tokenThis); tokenLast = tokenThis; } } final static Pattern patternLeadingWhiteSpace = Pattern.compile("[\\s&&[^\\r\\n]]+"); final static Pattern patternComment = Pattern.compile("#[^;\\r\\n]*"); final static Pattern patternEndOfStatement = Pattern.compile(";|\\r?\\n|\\r|$", Pattern.MULTILINE); final static Pattern patternDecimal = Pattern.compile("-?\\d+\\.(\\d*)?|-?\\.\\d+"); final static Pattern patternPositiveInteger = Pattern.compile("\\d+"); final static Pattern patternPossibleNegativeInteger = Pattern.compile("-?\\d+"); final static Pattern patternString = Pattern.compile("([\"'`])(.*?)\\1"); final static Pattern patternSpecialString = Pattern.compile("[^;\\r\\n]+"); final static Pattern patternLookup = Pattern.compile("\\(|\\)|," + "|<=|<|>=|>|==|=|!=|<>|/=" + "|&|\\||!" + "|\\*" + // select * "|-" + // range "|\\+" + // bond "|\\?" + // help command "|[a-zA-Z_][a-zA-Z_0-9]*" ); static boolean lookingAt(Pattern pattern, String description) { m = pattern.matcher(str); boolean looking = m.lookingAt(); if (looking) { System.out.println("lookingAt:" + description + ":" + m.group() + ":"); } return looking; } public static Token[][] tokenize(String strScript) throws ScriptException { Vector lltoken = new Vector(); Vector ltoken = new Vector(); Token tokenCommand = null; int tokCommand = nada; str = strScript; for ( ; true; str = str.substring(m.end())) { if (lookingAt(patternLeadingWhiteSpace, "leading whitespace")) continue; if (lookingAt(patternComment, "comment")) continue; if (lookingAt(patternEndOfStatement, "end of statement")) { if (tokCommand != nada) { System.out.println("tokCommand != nada"); Token[] atoken = new Token[ltoken.size()]; ltoken.copyInto(atoken); lltoken.add(atoken); ltoken.setSize(0); tokCommand = nada; } if (str.length() > 0) continue; break; } if (tokCommand != nada) { if (lookingAt(patternString, "string")) { System.out.println("lookingAt end of Statement"); ltoken.add(new Token(Token.string, m.group(2))); continue; } if ((tokCommand & specialstring) != 0 && lookingAt(patternSpecialString, "special string")) { ltoken.add(new Token(Token.string, m.group())); continue; } if (lookingAt(patternDecimal, "decimal")) { double value = Float.parseFloat(m.group()); ltoken.add(new Token(Token.decimal, new Double(value))); continue; } if (lookingAt(patternPositiveInteger, "positive integer") || ((tokCommand & negativeints) != 0 && lookingAt(patternPossibleNegativeInteger, "negative integer"))) { int val = Integer.parseInt(m.group()); ltoken.add(new Token(integer, val, null)); continue; } } if (lookingAt(patternLookup, "lookup")) { String ident = m.group().toLowerCase(); Token token = (Token) map.get(ident); if (token == null) { throw new ScriptException("get to work buddy:" + ident); } switch (tokCommand) { case nada: tokenCommand = token; tokCommand = token.tok; if ((tokCommand & command) == 0) throw new ScriptException("Command expected - found:" + ident); break; case set: if (ltoken.size() == 1) { if ((token.tok & setspecial) != 0) { tokenCommand = token; tokCommand = token.tok; ltoken.clear(); break; } if ((token.tok & setparam) == 0) throw new ScriptException("Cannot set:" + ident); } break; case show: if ((token.tok & showparam) == 0) throw new ScriptException("Cannot show:" + ident); break; case define: if ((ltoken.size() == 1) && (token == null)) token = new Token(Token.identifier, ident); else if ((ltoken.size() >= 2) && ((token.tok & expression) == 0)) throw new ScriptException("Invalid expression token:" + ident); break; case center: case restrict: case select: if ((token.tok & expression) == 0) throw new ScriptException("Invalid expression token:" + ident); break; } ltoken.add(token); continue; } throw new ScriptException(((ltoken.size() == 0) ? "Command Expected:" : "Unrecognized token:") + str.substring(0,Math.min(str.length(),32))); } Token[][] aatoken = new Token[lltoken.size()][]; lltoken.copyInto(aatoken); return aatoken; } public String toString() { return "Token[" + astrType[tok<=keyword ? tok : keyword] + ":" + value + "]"; } Token lookAhead(Token[] atoken, int i) { if (atoken.length <= i) return null; return atoken[i]; } /* expression :: = clauseOr clauseOr ::= clauseAnd {OR clauseAnd}* clauseAnd ::= clauseNot {AND clauseNot}* clauseNot ::= {NOT}? | clausePrimitive clausePrimitive ::= clauseInteger | clauseComparator | identifier ( clauseOr ) clauseInteger ::= integer | integer - integer clauseComparator ::= atomproperty comparatorop integer */ static Vector ltokenPostfix = null; static Token[] atokenInfix; static int itokenInfix; public static Token[] compileExpression(Token[] atoken, int itoken) throws ScriptException { ltokenPostfix = new Vector(); atokenInfix = atoken; itokenInfix = itoken; clauseOr(); if (itokenInfix != atokenInfix.length) throw new ScriptException("end of expression expected"); Token[] atokenPostfix = new Token[ltokenPostfix.size()]; ltokenPostfix.copyInto(atokenPostfix); return atokenPostfix; } static Token tokenNext() { if (itokenInfix == atokenInfix.length) return null; return atokenInfix[itokenInfix++]; } static int tokPeek() { if (itokenInfix == atokenInfix.length) return 0; return atokenInfix[itokenInfix].tok; } static void clauseOr() throws ScriptException { clauseAnd(); while (tokPeek() == opOr) { Token tokenOr = tokenNext(); clauseAnd(); ltokenPostfix.add(tokenOr); } } static void clauseAnd() throws ScriptException { clauseNot(); while (tokPeek() == opAnd) { Token tokenAnd = tokenNext(); clauseNot(); ltokenPostfix.add(tokenAnd); } } static void clauseNot() throws ScriptException { if (tokPeek() == opNot) { Token tokenNot = tokenNext(); clauseNot(); ltokenPostfix.add(tokenNot); } else { clausePrimitive(); } } static void clausePrimitive() throws ScriptException { switch (tokPeek()) { case integer: clauseInteger(); break; case atomno: case elemno: case resno: case radius: case temperature: clauseComparator(); break; case identifier: ltokenPostfix.add(tokenNext()); break; case leftparen: tokenNext(); clauseOr(); if (tokPeek() != rightparen) throw new ScriptException("right parenthesis expected"); tokenNext(); break; default: throw new ScriptException("unrecognized expression token"); } } static void clauseInteger() throws ScriptException { Token tokenInt1 = tokenNext(); if (tokPeek() != hyphen) { ltokenPostfix.add(tokenInt1); return; } tokenNext(); if (tokPeek() != integer) throw new ScriptException("integer expected after hyphen"); Token tokenInt2 = tokenNext(); int min = tokenInt1.intValue; int max = tokenInt2.intValue; if (max < min) { int intT = max; max = min; min = intT; } ltokenPostfix.add(new Token(hyphen, min, new Integer(max))); } static void clauseComparator() throws ScriptException { Token tokenAtomProperty = tokenNext(); if ((tokPeek() & comparator) == 0) throw new ScriptException("comparison operator expected"); Token tokenComparator = tokenNext(); if (tokPeek() != integer) throw new ScriptException("integer expected after comparison operator"); Token tokenValue = tokenNext(); int val = tokenValue.intValue; ltokenPostfix.add(new Token(tokenComparator.tok, tokenAtomProperty.tok, new Integer(val))); } public static void main (String arg[] ) { System.out.println("hola " + y); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String lines = ""; String line; try { while ((line = in.readLine()) != null) lines += line + "\n"; System.out.println("----"); System.out.println(lines); System.out.println("----"); Token[][] aatoken = Token.tokenize(lines); System.out.println("" + aatoken.length + " statements"); for (int i = 0; i < aatoken.length; ++i) { Token[] atoken = aatoken[i]; if (atoken.length == 0) { System.out.println("null"); continue; } System.out.println("" + atoken.length + " tokens in the line"); for (int j = 0; j < atoken.length; ++j) { System.out.print(atoken[j] + " "); } System.out.println(); } } catch (Exception e) { System.out.println(e); System.out.println("que?"); } System.out.println("adios"); } } Index: ScriptWindow.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/script/ScriptWindow.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** ScriptWindow.java 23 Nov 2002 17:40:27 -0000 1.1 --- ScriptWindow.java 25 Dec 2002 22:05:55 -0000 1.2 *************** *** 1,3 **** - /* * Copyright 2002 The Jmol Development Team --- 1,2 ---- *************** *** 20,23 **** --- 19,24 ---- package org.openscience.jmol.script; + import org.openscience.jmol.DisplayControl; + import java.awt.BorderLayout; import javax.swing.JButton; *************** *** 44,53 **** private JTextField input; private JButton closeButton; ! private RasMolScriptHandler scriptHandler; ! public ScriptWindow(JFrame frame, RasMolScriptHandler scriptHandler) { super(frame, "Rasmol Scripts", false); ! this.scriptHandler = scriptHandler; getContentPane().setLayout(new BorderLayout()); output = new JTextArea(20, 30); --- 45,56 ---- private JTextField input; private JButton closeButton; ! DisplayControl control; ! Eval eval; ! public ScriptWindow(DisplayControl control, JFrame frame) { super(frame, "Rasmol Scripts", false); ! this.control = control; ! this.eval = new Eval(control); getContentPane().setLayout(new BorderLayout()); output = new JTextArea(20, 30); *************** *** 57,61 **** getContentPane().add(scrollPane, BorderLayout.NORTH); ! scriptHandler.setOutput(output); input = new JTextField(); --- 60,64 ---- getContentPane().add(scrollPane, BorderLayout.NORTH); ! //scriptHandler.setOutput(output); input = new JTextField(); *************** *** 81,91 **** // execute script try { ! scriptHandler.handle(command); ! } catch (RasMolScriptException rasmolerror) { ! output.append(rasmolerror.getMessage()); ! output.append("\n"); ! } catch (Exception exp) { ! output.append("Error: " + exp.toString()); ! output.append("\n"); } --- 84,90 ---- // execute script try { ! eval.executeString(command); ! } catch (ScriptException se) { ! System.out.println("ScriptException thrown:" + se.getMessage()); } --- RasMolScriptException.java DELETED --- --- RasMolScriptHandler.java DELETED --- |
From: Michael T H. <mic...@us...> - 2002-12-25 22:05:59
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol In directory sc8-pr-cvs1:/tmp/cvs-serv24573/src/org/openscience/jmol Modified Files: DisplayControl.java Jmol.java Log Message: initial check-in of new script interpreter framework Index: DisplayControl.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/DisplayControl.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -r1.25 -r1.26 *** DisplayControl.java 22 Dec 2002 12:51:43 -0000 1.25 --- DisplayControl.java 25 Dec 2002 22:05:53 -0000 1.26 *************** *** 299,303 **** } ! private final SelectionSet setPicked = new SelectionSet(); public void addSelection(Atom atom) { --- 299,303 ---- } ! private SelectionSet setPicked = new SelectionSet(); public void addSelection(Atom atom) { *************** *** 349,352 **** --- 349,357 ---- } + public void setSelectionSet(SelectionSet set) { + setPicked = set; + recalc(); + } + public double getScalePixelsPerAngstrom() { return scalePixelsPerAngstrom; *************** *** 595,598 **** --- 600,607 ---- } + public int numberOfAtoms() { + return (chemframe == null) ? 0 : chemframe.getNumberOfAtoms(); + } + public void mlistChanged(MeasurementListEvent mle) { MeasurementList source = (MeasurementList) mle.getSource(); *************** *** 917,920 **** --- 926,939 ---- } return transparent; + } + + public boolean openFile(String filename) { + return Jmol.openFilename(filename); + } + + public void scriptEcho(String str) { + // FIXME -- if there is a script window it should go there + // for an applet it needs to go someplace else + System.out.println(str); } } Index: Jmol.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/Jmol.java,v retrieving revision 1.80 retrieving revision 1.81 diff -C2 -r1.80 -r1.81 *** Jmol.java 4 Dec 2002 10:46:46 -0000 1.80 --- Jmol.java 25 Dec 2002 22:05:54 -0000 1.81 *************** *** 31,36 **** import org.openscience.jmol.io.XYZSaver; import org.openscience.jmol.script.ScriptWindow; ! import org.openscience.jmol.script.RasMolScriptHandler; ! import org.openscience.jmol.script.RasMolScriptException; import org.openscience.cdk.tools.IsotopeFactory; import Acme.JPM.Encoders.GifEncoder; --- 31,36 ---- import org.openscience.jmol.io.XYZSaver; import org.openscience.jmol.script.ScriptWindow; ! import org.openscience.jmol.script.ScriptException; ! import org.openscience.jmol.script.Eval; import org.openscience.cdk.tools.IsotopeFactory; import Acme.JPM.Encoders.GifEncoder; *************** *** 262,266 **** splash.showStatus(resourceHandler .translate("Initializing Script Window...")); ! scriptWindow = new ScriptWindow(frame, new RasMolScriptHandler(this)); splash.showStatus(resourceHandler .translate("Initializing Property Graph...")); --- 262,267 ---- splash.showStatus(resourceHandler .translate("Initializing Script Window...")); ! scriptWindow = new ScriptWindow(control, frame); ! //scriptWindow = new ScriptWindow(frame, new RasMolScriptHandler(this)); splash.showStatus(resourceHandler .translate("Initializing Property Graph...")); *************** *** 369,387 **** } public static void main(String[] args) { // Read the first argument as a file name: File initialFile = null; ! File script = null; if (args.length == 2) { String s = args[0]; ! if (s.equals("-script")) { ! script = new File(getUserDirectory(), args[1]); ! if (!script.exists()) { ! System.out.println("Script not found: " + script.toString()); ! System.exit(1); ! } ! } } if (args.length == 1) { --- 370,385 ---- } + static Jmol jmol; + public static void main(String[] args) { // Read the first argument as a file name: File initialFile = null; ! String scriptFilename = null; if (args.length == 2) { String s = args[0]; ! if (s.equals("-script")) ! scriptFilename = args[1]; } if (args.length == 1) { *************** *** 404,444 **** frame = new JFrame(); ! Jmol window = getJmol(frame); // Open a file if on is given as an argument if (initialFile != null) { ! window.openFile(initialFile); } // Oke, by now it is time to execute the script ! if (script != null) { try { ! System.out.println("Executing script: " + script.toString()); ! window.splash ! .showStatus(JmolResourceHandler.getInstance() ! .getString("Executing script...")); ! RasMolScriptHandler scripthandler = new RasMolScriptHandler(window); ! BufferedReader reader = new BufferedReader(new FileReader(script)); ! String command = reader.readLine(); ! while (command != null) { ! try { ! scripthandler.handle(command); ! command = reader.readLine(); ! } catch (RasMolScriptException e) { ! ! // error in script. no user feedback at this moment ! System.out.println(e.toString()); ! command = null; ! } ! } ! } catch (FileNotFoundException e) { ! ! // since this is tested earlier, this should not happen ! } catch (IOException e) { ! // just stop handling the script } } - } catch (Throwable t) { System.out.println("uncaught exception: " + t); --- 402,426 ---- frame = new JFrame(); ! jmol = getJmol(frame); // Open a file if on is given as an argument if (initialFile != null) { ! jmol.openFile(initialFile); } // Oke, by now it is time to execute the script ! if (scriptFilename != null) { ! System.out.println("Executing script: " + scriptFilename); ! jmol.splash ! .showStatus(JmolResourceHandler.getInstance() ! .getString("Executing script...")); ! Eval eval = new Eval(control); try { ! eval.executeFile(scriptFilename); ! } catch (ScriptException e) { // just stop handling the script + // or should we exit here? } } } catch (Throwable t) { System.out.println("uncaught exception: " + t); *************** *** 473,476 **** --- 455,463 ---- } + public static boolean openFilename(String filename) { + return jmol.openFile(new File(getUserDirectory(), filename)); + } + + /** * Opens a file. *************** *** 478,482 **** * @param file the file to open. */ ! public void openFile(File file) { if (file != null) { --- 465,470 ---- * @param file the file to open. */ ! public boolean openFile(File file) { ! boolean successFlag = false; if (file != null) { *************** *** 494,498 **** firePropertyChange(openFileProperty, oldFile, currentFile); ! } catch (java.io.FileNotFoundException ex) { JOptionPane.showMessageDialog(Jmol.this, --- 482,486 ---- firePropertyChange(openFileProperty, oldFile, currentFile); ! successFlag = true; } catch (java.io.FileNotFoundException ex) { JOptionPane.showMessageDialog(Jmol.this, *************** *** 513,518 **** frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } - return; } } --- 501,506 ---- frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } + return successFlag; } |
From: Egon W. <eg...@us...> - 2002-12-24 14:50:40
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol In directory sc8-pr-cvs1:/tmp/cvs-serv29824/src/org/openscience/jmol Modified Files: DisplayPanel.java Log Message: Fixed problem with FPS patch. Index: DisplayPanel.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/DisplayPanel.java,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -r1.69 -r1.70 *** DisplayPanel.java 23 Dec 2002 13:30:22 -0000 1.69 --- DisplayPanel.java 24 Dec 2002 14:50:36 -0000 1.70 *************** *** 53,56 **** --- 53,58 ---- private GuiMap guimap; private DisplayControl control; + + private String displaySpeed; public DisplayPanel(StatusBar status, GuiMap guimap, *************** *** 61,64 **** --- 63,70 ---- if (System.getProperty("painttime", "false").equals("true")) showPaintTime = true; + displaySpeed = System.getProperty("display.speed"); + if (displaySpeed == null) { + displaySpeed = "ms"; + } } *************** *** 959,963 **** ? -1 : (timeTotal + timeCount/2) / timeCount; // round, don't truncate ! if (System.getProperty("display.speed").equalsIgnoreCase("fps")) { status.setStatus(3, fmt(1000/timeLast) + "FPS : " + fmt(1000/timeAverage) + "FPS"); } else { --- 965,969 ---- ? -1 : (timeTotal + timeCount/2) / timeCount; // round, don't truncate ! if (displaySpeed.equalsIgnoreCase("fps")) { status.setStatus(3, fmt(1000/timeLast) + "FPS : " + fmt(1000/timeAverage) + "FPS"); } else { |
From: Egon W. <eg...@us...> - 2002-12-23 13:30:25
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol In directory sc8-pr-cvs1:/tmp/cvs-serv20505/src/org/openscience/jmol Modified Files: DisplayPanel.java Log Message: Commited patch to display the rendering speed in FPS in addition to ms/frame. See documentation. Index: DisplayPanel.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/DisplayPanel.java,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -r1.68 -r1.69 *** DisplayPanel.java 12 Dec 2002 22:40:10 -0000 1.68 --- DisplayPanel.java 23 Dec 2002 13:30:22 -0000 1.69 *************** *** 959,963 **** ? -1 : (timeTotal + timeCount/2) / timeCount; // round, don't truncate ! status.setStatus(3, fmt(timeLast) + "ms : " + fmt(timeAverage) + "ms"); } --- 959,967 ---- ? -1 : (timeTotal + timeCount/2) / timeCount; // round, don't truncate ! if (System.getProperty("display.speed").equalsIgnoreCase("fps")) { ! status.setStatus(3, fmt(1000/timeLast) + "FPS : " + fmt(1000/timeAverage) + "FPS"); ! } else { ! status.setStatus(3, fmt(timeLast) + "ms : " + fmt(timeAverage) + "ms"); ! } } |
From: Egon W. <eg...@us...> - 2002-12-23 13:30:25
|
Update of /cvsroot/jmol/Jmol/doc/source In directory sc8-pr-cvs1:/tmp/cvs-serv20505/doc/source Modified Files: JmolGuide.docbook.xml JmolHistory.xml Log Message: Commited patch to display the rendering speed in FPS in addition to ms/frame. See documentation. Index: JmolGuide.docbook.xml =================================================================== RCS file: /cvsroot/jmol/Jmol/doc/source/JmolGuide.docbook.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** JmolGuide.docbook.xml 19 Nov 2002 16:46:39 -0000 1.6 --- JmolGuide.docbook.xml 23 Dec 2002 13:30:22 -0000 1.7 *************** *** 35,53 **** <section> <title>Java Options</title> ! <para> ! In addition to the above command line options there is also one ! important Java option: <cmdsynopsis><arg>-Duser.language</arg></cmdsynopsis>. ! With this option the GUI language can be set. At this moment ! these languages are supported: ! <literal>en</literal>, ! <literal>es</literal>, and ! <literal>nl</literal>. ! </para> ! <para> ! Alternatively, you can also use the <envar>LANG</envar> environment variable ! for setting the prefered language. This is common in many UNIX systems, like ! Linux. However, it is known not to work on Solaris and the above command line ! option must be used. ! </para> </section> </chapter> --- 35,64 ---- <section> <title>Java Options</title> ! <section> ! <title>-Duser.language</title> ! <para> ! In addition to the above command line options there is also one ! important Java option: <cmdsynopsis><arg>-Duser.language</arg></cmdsynopsis>. ! With this option the GUI language can be set. At this moment ! these languages are supported: ! <literal>en</literal>, ! <literal>es</literal>, and ! <literal>nl</literal>. ! </para> ! <para> ! Alternatively, you can also use the <envar>LANG</envar> environment variable ! for setting the prefered language. This is common in many UNIX systems, like ! Linux. However, it is known not to work on Solaris and the above command line ! option must be used. ! </para> ! </section> ! <section> ! <title>-Ddisplay.speed</title> ! <para> ! The <cmdsynopsis><arg>-Ddisplay.speed=fps</arg></cmdsynopsis> option can be used ! to reporting the display speed in <emphasis>frames per second</emphasis> instead ! of milliseconds per frame. ! </para> ! </section> </section> </chapter> Index: JmolHistory.xml =================================================================== RCS file: /cvsroot/jmol/Jmol/doc/source/JmolHistory.xml,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -r1.32 -r1.33 *** JmolHistory.xml 2 Dec 2002 15:41:56 -0000 1.32 --- JmolHistory.xml 23 Dec 2002 13:30:22 -0000 1.33 *************** *** 30,33 **** --- 30,36 ---- Jmol is now based on CDK. </change> + <change contributor="EW"> + Display speed can be displayed in milliseconds and in frames per second. + </change> </changes> |
From: Michael T H. <mic...@us...> - 2002-12-22 12:51:47
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/render In directory sc8-pr-cvs1:/tmp/cvs-serv2153/src/org/openscience/jmol/render Modified Files: BondRenderer.java Log Message: bonds now connect with surfaces/edges of atoms and have perspective depth Index: BondRenderer.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/render/BondRenderer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** BondRenderer.java 17 Dec 2002 23:19:11 -0000 1.2 --- BondRenderer.java 22 Dec 2002 12:51:43 -0000 1.3 *************** *** 61,64 **** --- 61,79 ---- DisplayControl control; + int x1, y1, z1; + int x2, y2, z2; + int dx, dy, dz; + int dx2, dy2, dz2; + int sgndx, sgndy; + int mag2d, mag2d2, halfMag2d; + int mag3d, mag3d2; + Color color1, color2; + boolean sameColor; + int radius1, diameter1; + int radius2, diameter2; + int width1, width2; + Color outline1, outline2; + int bondOrder; + public void setContext(Graphics g, Rectangle clip, DisplayControl control) { this.g = g; *************** *** 69,88 **** public void render(AtomShape atomShape1, AtomShape atomShape2, int bondOrder) { ! int x1 = atomShape1.x, y1 = atomShape1.y; ! int x2 = atomShape2.x, y2 = atomShape2.y; ! int dx = x2 - x1, dx2 = dx * dx; ! int dy = y2 - y1, dy2 = dy * dy; ! int magnitude2 = dx2 + dy2; ! Color color1 = control.getAtomColor(atomShape1.atom); ! Color color2 = control.getAtomColor(atomShape2.atom); ! if ((magnitude2 <= 2) || (control.fastRendering && magnitude2 <= 49)) ! return; // also avoid divide by zero when magnitude == 0 ! if (control.showAtoms && (magnitude2 <= 16)) return; // the pixels from the atoms will nearly cover the bond if (!control.showAtoms && (control.fastRendering || control.bondDrawMode==control.LINE)) { // the trivial case of no atoms and only single lines ! // in this case double & triple bonds are not shown ! if (color1.equals(color2)) { drawLineInside(g, color1, x1, y1, x2, y2); } else { --- 84,106 ---- public void render(AtomShape atomShape1, AtomShape atomShape2, int bondOrder) { ! x1 = atomShape1.x; y1 = atomShape1.y; z1 = atomShape1.z; ! x2 = atomShape2.x; y2 = atomShape2.y; z2 = atomShape2.z; ! dx = x2 - x1; dx2 = dx * dx; sgndx = (dx > 0) ? 1 : (dx < 0) ? -1 : 0; ! dy = y2 - y1; dy2 = dy * dy; sgndy = (dy > 0) ? 1 : (dy < 0) ? -1 : 0; ! dz = z2 - z1; dz2 = dz * dz; ! mag2d2 = dx2 + dy2; ! mag3d2 = mag2d2 + dz2; ! color1 = control.getAtomColor(atomShape1.atom); ! color2 = control.getAtomColor(atomShape2.atom); ! sameColor = color1.equals(color2); ! if (mag2d2 <= 2 || control.fastRendering && mag2d2 <= 49) ! return; // also avoids divide by zero when magnitude == 0 ! if (control.showAtoms && (mag2d2 <= 16)) return; // the pixels from the atoms will nearly cover the bond if (!control.showAtoms && (control.fastRendering || control.bondDrawMode==control.LINE)) { // the trivial case of no atoms and only single lines ! // in this case double & triple bonds are not drawn ! if (sameColor) { drawLineInside(g, color1, x1, y1, x2, y2); } else { *************** *** 94,98 **** return; } - int diameter1, radius1, diameter2, radius2; if (!control.showAtoms) { diameter1 = radius1 = diameter2 = radius2 = 0; --- 112,115 ---- *************** *** 103,360 **** radius2 = diameter2 >> 1; } ! ! int z1 = atomShape1.z; ! int z2 = atomShape2.z; ! int dz = z2 - z1; ! int dz2 = dz * dz; ! int magnitude = (int) Math.sqrt(magnitude2); ! double cosine = magnitude / Math.sqrt(magnitude2 + dz2); ! int radius1Bond = (int)(radius1 * cosine); ! int radius2Bond = (int)(radius2 * cosine); ! if (magnitude < radius1 + radius2Bond) { ! // the front atom (radius1) has completely obscured the bond return; } ! // FIXME -- kludge until I calculate accurate positions for ! // bond intersections ! // single line is correct without arcFactor ! int arcFactor = bondOrder - 1; ! int x1Bond = x1 + ((radius1Bond - arcFactor) * dx) / magnitude; ! int y1Bond = y1 + ((radius1Bond - arcFactor) * dy) / magnitude; ! int x2Bond = x2 - ((radius2Bond - arcFactor) * dx) / magnitude; ! int y2Bond = y2 - ((radius2Bond - arcFactor) * dy) / magnitude; ! int x1Edge = x1 + ((radius1 - arcFactor) * dx) / magnitude; ! int y1Edge = y1 + ((radius1 - arcFactor) * dy) / magnitude; ! // technically, this bond width is not correct in that it is ! // not in perspective. the width at z1 should be wider than the ! // width at z2. but ... ! // just take the average of the two z's and don't worry about it ! int avgZ = (z1 + z2) / 2; ! double halfBondWidth = control.scaleToScreen(avgZ, control.bondWidth/2); ! ! if (control.fastRendering || control.bondDrawMode==control.LINE) { ! drawLineBond(g, control, ! x1Bond, y1Bond, color1, ! x1Edge, y1Edge, ! x2Bond, y2Bond, color2, ! dx, dy, magnitude, bondOrder, halfBondWidth); return; } ! Color outline1 = control.getAtomOutlineColor(color1); ! Color outline2 = control.getAtomOutlineColor(color2); ! if (control.bondDrawMode != control.SHADING || ! control.mouseDragged ! || (int)halfBondWidth < 2) { ! if (halfBondWidth < .75) { ! drawLineBond(g, control, ! x1Bond, y1Bond, (control.bondDrawMode == control.WIREFRAME ! ? color1 : outline1), ! x1Edge, y1Edge, ! x2Bond, y2Bond, (control.bondDrawMode == control.WIREFRAME ! ? color2 : outline2), ! dx, dy, magnitude, bondOrder, halfBondWidth); return; - } - drawRectBond(g, control, - x1Bond, y1Bond, color1, outline1, - x1Edge, y1Edge, - x2Bond, y2Bond, color2, outline2, - control.bondDrawMode != control.WIREFRAME, - dx, dy, magnitude, bondOrder, halfBondWidth, halfBondWidth); - return; } - Color[] shades1 = getShades(color1, outline1); - Color[] shades2 = getShades(color2, outline2); ! int numPasses = (int)halfBondWidth; ! double widthT = halfBondWidth; ! for (int i = numPasses; --i >= 0; widthT -= 1.0) { ! int index = i * maxShade / numPasses; ! drawRectBond(g, control, ! x1Bond, y1Bond, shades1[index], null, ! x1Edge, y1Edge, ! x2Bond, y2Bond, shades2[index], null, ! true, dx, dy, magnitude, bondOrder, ! widthT, halfBondWidth); } - } ! private boolean isVisible(int x1, int y1, int xEdge, int yEdge, ! int x2, int y2) { ! int dxEdge = xEdge - x1, dyEdge = yEdge - y1; ! int dx2 = x2 - x1, dy2 = y2 - y1; ! return (dx2*dx2 + dy2*dy2) > (dxEdge*dxEdge + dyEdge*dyEdge); ! } ! ! private static final int separationIncrement = 4; ! ! private void drawLineBond(final Graphics g, DisplayControl control, ! int x1, int y1, final Color color1, ! int xEdge, int yEdge, ! int x2, int y2, final Color color2, ! final int dx, final int dy, final int magnitude, ! int bondOrder, final double halfBondWidth) { ! if (! isVisible(x1, y1, xEdge, yEdge, x2, y2)) ! return; ! int sepUp = (int) (separationIncrement * halfBondWidth); ! int sepDn = sepUp - (int)((separationIncrement * 2) * halfBondWidth); ! int xOffset = (sepDn * dy) / magnitude; ! int yOffset = (sepUp * dx) / magnitude; ! if (bondOrder == 2) { ! int xHalfOffset = xOffset/2, yHalfOffset = yOffset/2; ! x1 -= xHalfOffset; y1 -= yHalfOffset; ! x2 -= xHalfOffset; y2 -= yHalfOffset; ! xEdge -= xHalfOffset; yEdge -= yHalfOffset; ! } else if (bondOrder == 3) { ! x1 -= xOffset; y1 -= yOffset; ! x2 -= xOffset; y2 -= yOffset; ! xEdge -= xOffset; yEdge -= yOffset; ! } else if (bondOrder > 3) { ! bondOrder = 3; // just for protection against a wild parameter value ! } ! while (true) { ! int xTemp, yTemp; ! int xMid = (x1 + x2) / 2; ! int yMid = (y1 + y2) / 2; ! if (color1.equals(color2) || ! !isVisible(x1, y1, xEdge, yEdge, xMid, yMid)) { ! xTemp = xEdge; yTemp = yEdge; ! } else { ! drawLineInside(g, color1, xEdge, yEdge, xMid, yMid); ! xTemp = xMid; yTemp = yMid; } ! drawLineInside(g, color2, xTemp, yTemp, x2, y2); ! if (--bondOrder <= 0) // also catch initial parameter values <= 0 ! return; ! x1 += xOffset; y1 += yOffset; ! x2 += xOffset; y2 += yOffset; ! xEdge += xOffset; yEdge += yOffset; } } ! private static final int[] xBondRectPoints = new int[4]; ! private static final int[] yBondRectPoints = new int[4]; ! ! private void drawRectBond(final Graphics g, DisplayControl control, ! final int x1, final int y1, ! Color color1, Color color1Outline, ! final int xEdge, final int yEdge, ! final int x2, final int y2, ! Color color2, Color color2Outline, ! final boolean boolFill, ! final int dx, final int dy, final int magnitude, ! int bondOrder, final double halfBondWidth, ! final double separationWidth) { ! if (! isVisible(x1, y1, xEdge, yEdge, x2, y2)) ! return; ! // offsets for the width of the bond rectangle ! int width = (int)(2*halfBondWidth); ! int xHalfWidth = (int)(halfBondWidth * dy / magnitude); ! int yHalfWidth = (int)(halfBondWidth * dx / magnitude); ! int xFullWidth = (int)(halfBondWidth * 2 * dy / magnitude); ! int yFullWidth = (int)(halfBondWidth * 2 * dx / magnitude); ! ! int x1Top = x1 + xHalfWidth, x1Bot = x1Top - xFullWidth; ! int y1Top = y1 - yHalfWidth, y1Bot = y1Top + yFullWidth; ! int x2Top = x2 + xHalfWidth, x2Bot = x2Top - xFullWidth; ! int y2Top = y2 - yHalfWidth, y2Bot = y2Top + yFullWidth; ! int xEdgeTop = xEdge + xHalfWidth, xEdgeBot = xEdgeTop - xFullWidth; ! int yEdgeTop = yEdge - yHalfWidth, yEdgeBot = yEdgeTop + yFullWidth; ! int xMidTop = (x1Top + x2Top) / 2, yMidTop = (y1Top + y2Top + 1) / 2; ! int xMidBot = (x1Bot + x2Bot) / 2, yMidBot = (y1Bot + y2Bot + 1) / 2; ! ! int sepUp = (int) (separationIncrement * separationWidth); ! int sepDn = sepUp - (int)((separationIncrement * 2) * separationWidth); ! int xOffset = (sepDn * dy) / magnitude; ! int yOffset = (sepUp * dx) / magnitude; ! if (bondOrder == 2) { ! int xHalfOffset = xOffset/2; ! x1Top -= xHalfOffset; x1Bot -= xHalfOffset; ! x2Top -= xHalfOffset; x2Bot -= xHalfOffset; ! xEdgeTop -= xHalfOffset; xEdgeBot -= xHalfOffset; ! xMidTop -= xHalfOffset; xMidBot -= xHalfOffset; ! int yHalfOffset = yOffset/2; ! y1Top -= yHalfOffset; y1Bot -= yHalfOffset; ! y2Top -= yHalfOffset; y2Bot -= yHalfOffset; ! yEdgeTop -= yHalfOffset; yEdgeBot -= yHalfOffset; ! yMidTop -= yHalfOffset; yMidBot -= yHalfOffset; ! } else if (bondOrder == 3) { ! x1Top -= xOffset; x1Bot -= xOffset; ! x2Top -= xOffset; x2Bot -= xOffset; ! xEdgeTop -= xOffset; xEdgeBot -= xOffset; ! xMidTop -= xOffset; xMidBot -= xOffset; ! ! y1Top -= yOffset; y1Bot -= yOffset; ! y2Top -= yOffset; y2Bot -= yOffset; ! yEdgeTop -= yOffset; yEdgeBot -= yOffset; ! yMidTop -= yOffset; yMidBot -= yOffset; ! } else if (bondOrder > 3) { ! bondOrder = 3; // just in case ! } ! ! ! while (true) { ! xBondRectPoints[0] = xEdgeTop; yBondRectPoints[0] = yEdgeTop; ! xBondRectPoints[3] = xEdgeBot; yBondRectPoints[3] = yEdgeBot; ! if (!color1.equals(color2) && ! isVisible(x1Top, y1Top, xEdgeTop, yEdgeTop, xMidTop, yMidTop)) { ! // two different bond colors ! xBondRectPoints[1] = xMidTop; yBondRectPoints[1] = yMidTop; ! xBondRectPoints[2] = xMidBot; yBondRectPoints[2] = yMidBot; ! g.setColor(color1); ! if (boolFill) { ! g.fillPolygon(xBondRectPoints, yBondRectPoints, 4); ! drawInside(g, color1Outline, width,xBondRectPoints, yBondRectPoints); ! } else { ! g.drawPolygon(xBondRectPoints, yBondRectPoints, 4); ! } ! xBondRectPoints[0] = xMidTop; yBondRectPoints[0] = yMidTop; ! xBondRectPoints[3] = xMidBot; yBondRectPoints[3] = yMidBot; ! } ! xBondRectPoints[1] = x2Top; yBondRectPoints[1] = y2Top; ! xBondRectPoints[2] = x2Bot; yBondRectPoints[2] = y2Bot; ! g.setColor(color2); ! if (boolFill) { ! g.fillPolygon(xBondRectPoints, yBondRectPoints, 4); ! drawInside(g, color2Outline, width, xBondRectPoints, yBondRectPoints); ! } else { ! g.drawPolygon(xBondRectPoints, yBondRectPoints, 4); } ! /* ! // don't draw outlines if we did not fill ! if (boolFill && color1Outline != null) { ! int xOutlineTop, yOutlineTop, xOutlineBot, yOutlineBot; ! if (color1Outline.equals(color2Outline) || ! !isVisible(x1Top, y1Top, xEdgeTop, yEdgeTop, xMidTop, yMidTop)) { ! xOutlineTop = xEdgeTop; yOutlineTop = yEdgeTop; ! xOutlineBot = xEdgeBot; yOutlineBot = yEdgeBot; ! } else { ! g.setColor(color1Outline); ! drawInside(g, (int)halfBondWidth*2, ! xEdgeTop, yEdgeTop, xMidTop, yMidTop, ! xEdgeBot, yEdgeBot, xMidBot, yMidBot); ! xOutlineTop = xMidTop; yOutlineTop = yMidTop; ! xOutlineBot = xMidBot; yOutlineBot = yMidBot; ! } ! g.setColor(color2Outline); ! drawInside(g, (int)halfBondWidth*2, ! xOutlineTop, yOutlineTop, x2Top, y2Top, ! xOutlineBot, yOutlineBot, x2Bot, y2Bot); ! } ! */ ! if (--bondOrder <= 0) // also catch a crazy parameter value ! return; ! x1Top += xOffset; x1Bot += xOffset; ! x2Top += xOffset; x2Bot += xOffset; ! xEdgeTop += xOffset; xEdgeBot += xOffset; ! xMidTop += xOffset; xMidBot += xOffset; ! ! y1Top += yOffset; y1Bot += yOffset; ! y2Top += yOffset; y2Bot += yOffset; ! yEdgeTop += yOffset; yEdgeBot += yOffset; ! yMidTop += yOffset; yMidBot += yOffset; } } --- 120,273 ---- radius2 = diameter2 >> 1; } ! mag2d = (int)Math.sqrt(mag2d2); ! // if the front atom (radius1) has completely obscured the bond, stop ! if (radius1 >= mag2d) return; + halfMag2d = mag2d / 2; + mag3d = (int)Math.sqrt(mag3d2); + int radius1Bond = radius1 * mag2d / mag3d; + int radius2Bond = radius2 * mag2d / mag3d; + + outline1 = control.getAtomOutlineColor(color1); + outline2 = control.getAtomOutlineColor(color2); + + width1 = (int)control.scaleToScreen(z1, control.bondWidth); + width2 = (int)control.scaleToScreen(z2, control.bondWidth); + + if (width1 < 4 && width2 < 4) { + // to smooth out narrow bonds + width1 = width2 = (width1 + width2) / 2; + } + this.bondOrder = bondOrder; + + boolean lineBond = + control.bondDrawMode == control.LINE || control.fastRendering; + if (!lineBond && width1 < 2 && width2 < 2) { + // if the bonds are narrow ... + // just draw lines that are the color of the outline + color1 = outline1; + color2 = outline2; + lineBond = true; + } + if (lineBond && width1 <= 1) + width1 = width2 = 2; + resetAxisCoordinates(lineBond); + while (true) { + if (lineBond) + lineBond(); + else + polyBond(); + if (--bondOrder == 0) + return; + stepAxisCoordinates(); } + } ! int[] axPoly = new int[4]; ! int[] ayPoly = new int[4]; ! int xExit, yExit; ! ! void lineBond() { ! calcSurfaceIntersections(); ! calcExitPoint(); ! if (sameColor || distanceExit >= mag2dLine / 2 ) { ! if (distanceExit < (mag2dLine - distanceSurface2)) ! drawLineInside(g, color2, xExit, yExit, xSurface2, ySurface2); return; } ! int xMid = (xAxis1 + xAxis2) / 2; ! int yMid = (yAxis1 + yAxis2) / 2; ! drawLineInside(g, color1, xExit, yExit, xMid, yMid); ! drawLineInside(g, color2, xMid, yMid, xSurface2, ySurface2); ! } ! ! void polyBond() { ! boolean bothColors = !sameColor; ! ! calcSurfaceIntersections(); ! calcExitPoint(); ! int xExitTop = xExit, yExitTop = yExit; ! int xMidTop = (xAxis1 + xAxis2) / 2, yMidTop = (yAxis1 + yAxis2) / 2; ! int xSurfaceTop = xSurface2, ySurfaceTop = ySurface2; ! if (distanceExit >= mag2dLine / 2) { ! bothColors = false; ! if (distanceExit >= (mag2dLine - distanceSurface2 + 1)) return; } ! stepAxisCoordinates(); ! calcSurfaceIntersections(); ! calcExitPoint(); ! int xExitBot = xExit, yExitBot = yExit; ! int xMidBot = (xAxis1 + xAxis2) / 2, yMidBot = (yAxis1 + yAxis2) / 2; ! int xSurfaceBot = xSurface2, ySurfaceBot = ySurface2; ! if (distanceExit >= mag2dLine / 2) { ! bothColors = false; ! if (distanceExit > (mag2dLine - distanceSurface2 + 1)) ! return; } ! if (! bothColors) { ! if (distanceExit < mag2dLine) { ! axPoly[0] = xExitTop; ayPoly[0] = yExitTop; ! axPoly[1] = xSurfaceTop; ayPoly[1] = ySurfaceTop; ! axPoly[2] = xSurfaceBot; ayPoly[2] = ySurfaceBot; ! axPoly[3] = xExitBot; ayPoly[3] = yExitBot; ! polyBond1(color2, outline2); } ! } else { ! axPoly[0] = xExitTop; ayPoly[0] = yExitTop; ! axPoly[1] = xMidTop; ayPoly[1] = yMidTop; ! axPoly[2] = xMidBot; ayPoly[2] = yMidBot; ! axPoly[3] = xExitBot; ayPoly[3] = yExitBot; ! polyBond1(color1, outline1); ! ! axPoly[0] = xMidTop; ayPoly[0] = yMidTop; ! axPoly[1] = xSurfaceTop; ayPoly[1] = ySurfaceTop; ! axPoly[2] = xSurfaceBot; ayPoly[2] = ySurfaceBot; ! axPoly[3] = xMidBot; ayPoly[3] = yMidBot; ! polyBond1(color2, outline2); } } ! void polyBond1(Color color, Color outline) { ! g.setColor(color); ! switch(control.bondDrawMode) { ! case DisplayControl.WIREFRAME: ! g.drawPolygon(axPoly, ayPoly, 4); ! break; ! case DisplayControl.SHADING: ! int numPasses = calcNumShadeSteps(); ! Color[] shades = getShades(color, Color.black); ! for (int i = numPasses; --i >= 0; ) { ! g.setColor(shades[i * maxShade / numPasses]); ! g.fillPolygon(axPoly, ayPoly, 4); ! stepPolygon(); } + break; + case DisplayControl.QUICKDRAW: + g.fillPolygon(axPoly, ayPoly, 4); + drawInside(g, outline, 2, axPoly, ayPoly); + break; + } + } ! int offset1, offset2, doffset; ! void lineBond1(int offset1, int offset2) { ! this.offset1 = offset1; ! this.offset2 = offset2; ! doffset = offset2 - offset1; ! calcAxisCoordinates(); ! calcSurfaceIntersections(); ! calcExitPoint(); ! if (sameColor || distanceExit >= mag2dLine / 2 ) { ! if (distanceExit < mag2dLine) ! drawLineInside(g, color2, xExit, yExit, xSurface2, ySurface2); ! return; } + int xMid = (xAxis1 + xAxis2) / 2; + int yMid = (yAxis1 + yAxis2) / 2; + drawLineInside(g, color1, xExit, yExit, xMid, yMid); + drawLineInside(g, color2, xMid, yMid, xSurface2, ySurface2); } *************** *** 495,497 **** --- 408,683 ---- return shades; } + + // u stands for unscaled - unscaled by the magnitude + int dxLine, dyLine, mag2dLine; + + int uxAxis1, uyAxis1; + int uxAxis2, uyAxis2; + + int xAxis1, yAxis1; + int xAxis2, yAxis2; + + void calcAxisCoordinates() { + uxAxis1 = -offset1 * dy; + xAxis1 = x1 + uxAxis1 / mag2d; + uyAxis1 = offset1 * dx; + yAxis1 = y1 + uyAxis1 / mag2d; + uxAxis2 = offset2 * -dy; + xAxis2 = x2 + uxAxis2 / mag2d; + uyAxis2 = -offset2 * -dx; + yAxis2 = y2 + uyAxis2 / mag2d; + + dxLine = xAxis2 - xAxis1; + dyLine = yAxis2 - yAxis1; + mag2dLine = (int)Math.sqrt(dxLine*dxLine + dyLine*dyLine); + } + + // I currently have an 'accurate method' and a 'regular method' + // accurate rounds each point to the nearest pixel + // regular makes regular steps along the axis + // this propogates errors, but the distances between the lines are fixed + static final boolean accurateMethod = false; + boolean showAxis = false; + + int lines, steps, halfSteps, currentStep; + int dxWidth1, dyWidth1, dxWidth2, dyWidth2; + + void resetAxisCoordinates(boolean lineBond) { + lines = bondOrder; + if (! lineBond) + lines *= 2; + steps = lines-1; + halfSteps = steps / 2; + + if (accurateMethod) { + currentStep = 0; + } else { + dxWidth1 = -(width1 * dy + halfMag2d * sgndy) / mag2d; + dyWidth1 = (width1 * dx + halfMag2d * sgndx) / mag2d; + dxWidth2 = (width2 * -dy - halfMag2d * sgndy) / mag2d; + dyWidth2 = -(width2 * -dx - halfMag2d * sgndx) / mag2d; + + xAxis1 = x1 - dxWidth1*halfSteps; + yAxis1 = y1 - dyWidth1*halfSteps; + xAxis2 = x2 - dxWidth2*halfSteps; + yAxis2 = y2 - dyWidth2*halfSteps; + if (steps % 2 == 1) { + xAxis1 -= dxWidth1/2; + yAxis1 -= dyWidth2/2; + xAxis2 -= dxWidth2/2; + yAxis2 -= dyWidth2/2; + } + } + calcLineSlope(); + } + + void stepAxisCoordinates() { + if (accurateMethod) { + ++currentStep; + } else { + xAxis1 += dxWidth1; + yAxis1 += dyWidth1; + xAxis2 += dxWidth2; + yAxis2 += dyWidth2; + } + calcLineSlope(); + } + + void calcLineSlope() { + if (accurateMethod) { + offset1 = (currentStep - halfSteps) * width1; + offset2 = (currentStep - halfSteps) * width2; + if (steps % 2 == 1) { + offset1 -= width1 / 2; + offset2 -= width2 / 2; + } + xAxis1 = x1 - (offset1 * dy + sgndy * halfMag2d) / mag2d; + yAxis1 = y1 + (offset1 * dx + sgndx * halfMag2d) / mag2d; + xAxis2 = x2 - (offset2 * dy + sgndy * halfMag2d) / mag2d; + yAxis2 = y2 + (offset2 * dx + sgndx * halfMag2d) / mag2d; + } + dxLine = xAxis2 - xAxis1; + dyLine = yAxis2 - yAxis1; + mag2dLine = (int)Math.sqrt(dxLine*dxLine + dyLine*dyLine); + if (!accurateMethod) { + dxLine = xAxis2 - xAxis1; + dyLine = yAxis2 - yAxis1; + mag2dLine = (int)Math.sqrt(dxLine*dxLine + dyLine*dyLine); + int dxOffset1 = xAxis1 - x1; + int dyOffset1 = yAxis1 - y1; + offset1 = (int)Math.sqrt(dxOffset1*dxOffset1 + dyOffset1*dyOffset1); + int dxOffset2 = xAxis2 - x2; + int dyOffset2 = yAxis2 - y2; + offset2 = (int)Math.sqrt(dxOffset2*dxOffset2 + dyOffset2*dyOffset2); + } + if (showAxis) { + g.setColor(Color.lightGray); + g.drawLine(x1 + dy, y1 - dx, x1 - dy, y1 + dx); + g.drawLine(x2 + dy, y2 - dx, x2 - dy, y2 + dx); + g.setColor(Color.cyan); + g.drawLine(xAxis1, yAxis1, xAxis2, yAxis2); + } + } + + int xSurface1, ySurface1, xSurface2, ySurface2; + int distanceSurface2; + + int radius1Squared; + + public static final boolean calcSurface1 = false; + void calcSurfaceIntersections() { + if (calcSurface1) { + radius1Squared = radius1*radius1; + int offset1Squared = offset1*offset1; + int radius1Slice = 0; + if (offset1Squared < radius1Squared) { + radius1Slice = (int)(Math.sqrt(radius1Squared-offset1Squared)); + radius1Slice = radius1Slice * mag2d / mag3d; + } + int dxSlice1 = radius1Slice * dxLine / mag2dLine; + int dySlice1 = radius1Slice * dyLine / mag2dLine; + xSurface1 = xAxis1 + dxSlice1; + ySurface1 = yAxis1 + dySlice1; + } + + // ensure that we stay inside; + int radius2Squared = radius2*radius2 - 1; + int offset2Squared = offset2*offset2; + distanceSurface2 = 0; + if (offset2Squared < radius2Squared) { + distanceSurface2 = (int)(Math.sqrt(radius2Squared-offset2Squared)); + distanceSurface2 = distanceSurface2 * mag2d / mag3d; + } + int dxSlice2 = distanceSurface2 * -dxLine / mag2dLine; + int dySlice2 = distanceSurface2 * -dyLine / mag2dLine; + xSurface2 = xAxis2 + dxSlice2; + ySurface2 = yAxis2 + dySlice2; + + if (showAxis) { + dot(xSurface1, ySurface1, Color.red); + dot(xSurface2, ySurface2, Color.red); + } + } + + Color colorGreenTrans = new Color(0x4000FF00, true); + Color colorBlueTrans = new Color(0x400000FF, true); + Color colorRedTrans = new Color(0x40FF0000, true); + Color colorGreyTrans = new Color(0x40808080, true); + + void dot(int x, int y, Color co) { + g.setColor(co); + g.fillRect(x-1, y-1, 2, 2); + } + + double[] intersectionCoords = new double[4]; + int distanceExit; + void calcExitPoint() { + int count = intersectCircleLine(x1, y1, diameter1, + xAxis1, yAxis1, xAxis2, yAxis2, + intersectionCoords); + if (count == 0) { + xExit = xAxis1; + yExit = yAxis1; + } else { + // as currently implemented, the "interesting" point is the first + // point returned. However, if you make changes you need to be careful + // or you will end up breaking that. If the bonds are drawn from the + // opposite side of the atom then that is the problem. + // you need to either 1) be more careful about the signs on the + // things that you did, or 2) put in a test here to determine which + // of the two points should be assigned to Exit + // + if (lines == 1) { + xExit = (int)(intersectionCoords[0] + 0.5); + yExit = (int)(intersectionCoords[1] + 0.5); + } else { + // unfortunately, we have to do this calculation to ensure that + // the end points are exactly on the axis lines + // otherwise the results look terrible when things get small + // because 'parallel' lines are not parallel + double dx = intersectionCoords[0] - xAxis1; + double dy = intersectionCoords[1] - yAxis1; + distanceExit = (int)Math.sqrt(dx*dx + dy*dy); + xExit = xAxis1 + distanceExit * dxLine / mag2dLine; + yExit = yAxis1 + distanceExit * dyLine / mag2dLine; + } + } + } + + int intersectCircleLine(int x, int y, int d, int xA, int yA, int xB, int yB, + double[] coords) { + int dxA = xA - x, dxA2 = dxA * dxA; + int dyA = yA - y, dyA2 = dyA * dyA; + int dxB = xB - x, dxB2 = dxB * dxB; + int dyB = yB - y, dyB2 = dyB * dyB; + int dxAdxB = dxA * dxB; + int dyAdyB = dyA * dyB; + // gamma can get pretty large, so turn it into a double before multiplying + int gamma = dxA2 + dyA2 + dxB2 + dyB2 - 2*dxAdxB - 2*dyAdyB; + boolean tangent = gamma == 0; + int delta = 2*dxAdxB + 2*dyAdyB - 2*dxA2 - 2*dyA2; + double lambda0 = (d*d)/4.0 - (dxA2 + dyA2); + double lambda1, lambda2; + if (tangent) { + if (delta == 0) { + return 0; + } + lambda1 = lambda0 / delta; + lambda2 = 0; + } else { + // delta stays small, so don't worry. gamma gets big, so worry + lambda0 = lambda0 / gamma + (delta*delta)/(4.0*gamma*gamma); + if (lambda0 < 0) { + return 0; + } + lambda1 = Math.sqrt(lambda0); + lambda2 = delta / (2.0 * gamma); + } + double lambda = lambda1 - lambda2; + coords[0] = x + (1 - lambda) * dxA + lambda * dxB; + coords[1] = y + (1 - lambda) * dyA + lambda * dyB; + if (tangent) + return 1; + lambda = -lambda1 - lambda2; + coords[2] = x + (1 - lambda) * dxA + lambda * dxB; + coords[3] = y + (1 - lambda) * dyA + lambda * dyB; + return 2; + } + + + int xL, yL, dxL, dyL, lenL; + int xR, yR, dxR, dyR, lenR; + int step, lenMax; + + int calcNumShadeSteps() { + xL = axPoly[0]; yL = ayPoly[0]; + dxL = axPoly[3] - xL; dyL = ayPoly[3] - yL; + lenL = (int)Math.sqrt(dxL*dxL + dyL*dyL); + xR = axPoly[1]; yR = ayPoly[1]; + dxR = axPoly[2] - xR; dyR = ayPoly[2] - yR; + lenR = (int)Math.sqrt(dxR*dxR + dyR+dyR); + lenMax = lenL; + if (lenR > lenMax) + lenMax = lenR; + step = 0; + return lenMax / 2; + } + + void stepPolygon() { + ++step; + int dxStepL = dxL * step / (lenMax - 1); + int dyStepL = dyL * step / (lenMax - 1); + int dxStepR = dxR * step / (lenMax - 1); + int dyStepR = dyR * step / (lenMax - 1); + + axPoly[0] = xL + dxStepL; + ayPoly[0] = yL + dyStepL; + axPoly[1] = xR + dxStepR; + ayPoly[1] = yR + dyStepR; + axPoly[2] = xR + dxR - dxStepR; + ayPoly[2] = yR + dyR - dyStepR; + axPoly[3] = xL + dxL - dxStepL; + ayPoly[3] = yL + dyL - dyStepL; + } } + |
From: Michael T H. <mic...@us...> - 2002-12-22 12:51:47
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol In directory sc8-pr-cvs1:/tmp/cvs-serv2153/src/org/openscience/jmol Modified Files: DisplayControl.java Log Message: bonds now connect with surfaces/edges of atoms and have perspective depth Index: DisplayControl.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/DisplayControl.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -r1.24 -r1.25 *** DisplayControl.java 17 Dec 2002 23:19:11 -0000 1.24 --- DisplayControl.java 22 Dec 2002 12:51:43 -0000 1.25 *************** *** 878,887 **** public Color getAtomColor(Atom atom) { ! return colorProfile.getAtomColor((org.openscience.cdk.Atom)atom); } public Color getAtomOutlineColor(Color color) { ! return (showDarkerOutline || atomDrawMode == SHADING) ? getDarker(color) : outlineColor; } --- 878,893 ---- public Color getAtomColor(Atom atom) { ! Color color = colorProfile.getAtomColor((org.openscience.cdk.Atom)atom); ! if (modeTransparentColors) ! color = getTransparent(color); ! return color; } public Color getAtomOutlineColor(Color color) { ! Color outline = (showDarkerOutline || atomDrawMode == SHADING) ? getDarker(color) : outlineColor; + if (modeTransparentColors) + outline = getTransparent(outline); + return outline; } *************** *** 894,897 **** --- 900,920 ---- } return darker; + } + + private boolean modeTransparentColors = false; + public void setModeTransparentColors(boolean modeTransparentColors) { + this.modeTransparentColors = modeTransparentColors; + } + + private final static int transparency = 0x40; + private Hashtable htTransparent = new Hashtable(); + public Color getTransparent(Color color) { + Color transparent = (Color) htTransparent.get(color); + if (transparent == null) { + int argb = (color.getRGB() & 0x00FFFFFF) | (transparency << 24); + transparent = new Color (argb, true); + htTransparent.put(color, transparent); + } + return transparent; } } |
From: Michael T H. <mic...@us...> - 2002-12-17 23:39:29
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/render In directory sc8-pr-cvs1:/tmp/cvs-serv23381/render Modified Files: AtomShape.java BondRenderer.java Added Files: AtomRenderer.java Log Message: split out AtomRenderer.java. reworked shaded bond rendering. --- NEW FILE: AtomRenderer.java --- /* $RCSfile: AtomRenderer.java,v $ * $Author: michaelthoward $ * $Date: 2002/12/17 23:19:11 $ * $Revision: 1.1 $ * * Copyright (C) 2002 The Jmol Development Team * * Contact: jmo...@li... * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. */ package org.openscience.jmol.render; import org.openscience.jmol.*; import java.awt.Component; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.image.MemoryImageSource; import java.awt.image.Kernel; import java.awt.image.IndexColorModel; import java.awt.image.WritableRaster; import java.awt.Composite; import java.awt.AlphaComposite; import java.awt.Polygon; import java.awt.Color; import java.awt.geom.Ellipse2D; import java.awt.geom.Ellipse2D.Double; import java.awt.RenderingHints; import java.util.Enumeration; import java.util.Hashtable; import java.awt.GradientPaint; import java.awt.Paint; import java.awt.Point; import javax.vecmath.Point3d; import javax.vecmath.Matrix4d; /** * Graphical representation of an atom. * * @author Bradley A. Smith (br...@ba...) */ public class AtomRenderer { Graphics g; Rectangle clip; DisplayControl control; Atom atom; int x; int y; int z; int diameter; int radius; int xUpperLeft; int yUpperLeft; Color color; Color colorOutline; public void setContext(Graphics g, Rectangle clip, DisplayControl control) { this.g = g; this.clip = clip; this.control = control; } public void render(AtomShape atomShape) { atom = atomShape.atom; x = atomShape.x; y = atomShape.y; z = atomShape.z; diameter = atomShape.diameter; radius = diameter / 2; xUpperLeft = x - radius; yUpperLeft = y - radius; color = control.getAtomColor(atom); colorOutline = control.getAtomOutlineColor(color); renderAtom(); if (control.labelMode != control.NOLABELS) renderLabel(); } private void renderAtom() { if (!control.fastRendering && control.isSelected(atom)) { int halowidth = diameter / 3; if (halowidth < 2) halowidth = 2; int halodiameter = diameter + 2 * halowidth; int haloradius = halodiameter / 2; g.setColor(control.getPickedColor()); g.fillOval(x - haloradius, y - haloradius, halodiameter, halodiameter); } if (diameter <= 2) { if (diameter > 0) { g.setColor(control.atomDrawMode==control.WIREFRAME ? color : colorOutline); g.fillRect(xUpperLeft, yUpperLeft, diameter, diameter); } return; } if (control.atomDrawMode == control.SHADING && diameter >= minCachedSize && !control.fastRendering) { renderShadedAtom(); return; } // the area *drawn* by an oval is 1 larger than the area // *filled* by an oval because of the stroke offset int diamT = diameter-1; g.setColor(color); if (!control.fastRendering && control.atomDrawMode!=control.WIREFRAME) { // diamT should work here, but if background dots are appearing // just inside the circles then change the parameter to *diameter* g.fillOval(xUpperLeft, yUpperLeft, diamT, diamT); g.setColor(colorOutline); } g.drawOval(xUpperLeft, yUpperLeft, diamT, diamT); } private static final int minCachedSize = 4; private static final int maxCachedSize = 50; private static final int scalableSize = 47; private static final int maxSmoothedSize = 200; // I am getting severe graphical artifacts around the edges when // rendering hints are turned on. Therefore, I am adding a margin // to shaded rendering in order to cut down on edge effects private static final int artifactMargin = 4; private static final int minShadingBufferSize = maxCachedSize; private static final int maxShadingBufferSize = maxSmoothedSize + artifactMargin*2; private void renderShadedAtom() { if (! control.imageCache.containsKey(color)) { loadShadedSphereCache(control, color); } Image[] shadedImages = (Image[]) control.imageCache.get(color); if (diameter < maxCachedSize) { // images in the cache have a clear margin of 1 g.drawImage(shadedImages[diameter], xUpperLeft - 1, yUpperLeft - 1, null); } else { renderLargeShadedAtom(shadedImages[0]); } } private void renderLargeShadedAtom(Image imgSphere) { if (! control.useGraphics2D) { g.drawImage(imgSphere, xUpperLeft, yUpperLeft, diameter, diameter, null); return; } if (diameter < maxSmoothedSize) { drawScaledShadedAtom((Graphics2D) g, imgSphere, x, y, diameter, artifactMargin); } else { // too big ... just forget the smoothing // but we *can* clip it to eliminate fat pixels Ellipse2D circle = new Ellipse2D.Double(xUpperLeft, yUpperLeft, diameter, diameter); g.setClip(circle); g.drawImage(imgSphere, xUpperLeft, yUpperLeft, diameter, diameter, null); g.setClip(null); } } private static final double[] lightSource = { -1.0f, -1.0f, 2.0f }; private void loadShadedSphereCache(DisplayControl control, Color color) { Image shadedImages[] = new Image[maxCachedSize]; Component component = control.getDisplayPanel(); control.imageCache.put(color, shadedImages); if (! control.useGraphics2D) { for (int d = minCachedSize; d < maxCachedSize; ++d) { shadedImages[d] = sphereSetup(component, color, d+2, lightSource); } shadedImages[0] = sphereSetup(component,color,scalableSize,lightSource); return; } shadedImages[0] = sphereSetup(component, color, scalableSize, lightSource); for (int d = minCachedSize; d < maxCachedSize; ++d) { BufferedImage bi = new BufferedImage(d+2, d+2, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bi.createGraphics(); drawScaledShadedAtom(g2, shadedImages[0], d/2+1, d/2+1, d, 1); shadedImages[d] = bi; } } private static byte[] mapRGBA; private static IndexColorModel cmMask; private static int sizeMask = 0; private static BufferedImage biMask = null; private static Graphics2D g2Mask; private static WritableRaster rasterMask; private static BufferedImage biAlphaMask; private void applyCircleMask(Graphics2D g, int diameter, int margin) { // mth 2002 nov 12 // a 4 bit greyscale mask would/should be sufficient here, but there // was a bug in my JVM (or a bug in my head) which prevented it // from working if (mapRGBA == null) { mapRGBA = new byte[256]; for (int i = 0; i < 256; ++ i) { mapRGBA[i] = (byte) i; } cmMask = new IndexColorModel(8, 256, mapRGBA, mapRGBA, mapRGBA, mapRGBA); } int size = diameter + 2*margin; if (size > sizeMask) { sizeMask = size * 2; if (sizeMask < minShadingBufferSize) sizeMask = minShadingBufferSize; if (sizeMask > maxShadingBufferSize) sizeMask = maxShadingBufferSize; biMask = new BufferedImage(sizeMask, sizeMask, BufferedImage.TYPE_BYTE_GRAY); g2Mask = biMask.createGraphics(); g2Mask.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rasterMask = biMask.getRaster(); biAlphaMask = new BufferedImage(cmMask, rasterMask, false, null); } g2Mask.setColor(Color.black); g2Mask.fillRect(0, 0, size, size); g2Mask.setColor(Color.white); g2Mask.fillOval(margin, margin, diameter, diameter); Composite foo = g.getComposite(); g.setComposite(AlphaComposite.DstIn); g.drawImage(biAlphaMask, 0, 0, null); g.setComposite(foo); } private static int sizeShadingBuffer = 0; private static BufferedImage biShadingBuffer = null; private static Graphics2D g2ShadingBuffer = null; void drawScaledShadedAtom(Graphics2D g2, Image image, int x, int y, int diameter, int margin) { final int size = diameter + 2*margin; if (size > sizeShadingBuffer) { sizeShadingBuffer = size * 2; // leave some room to grow if (sizeShadingBuffer < minShadingBufferSize) sizeShadingBuffer = minShadingBufferSize; if (sizeShadingBuffer > maxShadingBufferSize) sizeShadingBuffer = maxShadingBufferSize; biShadingBuffer = new BufferedImage(sizeShadingBuffer, sizeShadingBuffer, BufferedImage.TYPE_INT_ARGB); g2ShadingBuffer = biShadingBuffer.createGraphics(); g2ShadingBuffer.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); } g2ShadingBuffer.drawImage(image, 0, 0, size, size, null); applyCircleMask(g2ShadingBuffer, diameter, margin); int radius = diameter / 2; int xUpperLeft = x - radius - margin; int yUpperLeft = y - radius - margin; g2.setClip(xUpperLeft, yUpperLeft, size, size); g2.drawImage(biShadingBuffer, xUpperLeft, yUpperLeft, null); g2.setClip(null); } /** * Creates a shaded atom image. */ private static Image sphereSetup(Component component, Color ballColor, int diameter, double[] lightSource) { double v1[] = new double[3]; double v2[] = new double[3]; int radius = (diameter + 1) / 2; // round it up int j = -1; // Create our own version of an IndexColorModel: int model[] = new int[diameter*diameter]; // Normalize the lightsource vector: double[] lightsource = new double[3]; for (int i = 0; i < 3; ++ i) lightsource[i] = lightSource[i]; normalize(lightsource); for (int k1 = -(diameter - radius); k1 < radius; k1++) { for (int k2 = -(diameter - radius); k2 < radius; k2++) { j++; v1[0] = k2; v1[1] = k1; double len1 = Math.sqrt(k2 * k2 + k1 * k1); if (len1 <= radius) { int red2 = 0; int green2 = 0; int blue2 = 0; v1[2] = radius * Math.cos(Math.asin(len1 / radius)); normalize(v1); double len2 = Math.abs((v1[0] * lightsource[0] + v1[1] * lightsource[1] + v1[2] * lightsource[2])); if (len2 < 0.995f) { red2 = (int) (ballColor.getRed() * len2); green2 = (int) (ballColor.getGreen() * len2); blue2 = (int) (ballColor.getBlue() * len2); } else { v2[0] = lightsource[0] + 0.0f; v2[1] = lightsource[1] + 0.0f; v2[2] = lightsource[2] + 1.0f; normalize(v2); double len3 = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; double len4 = 8.0f * len3 * len3 - 7.0f; double len5 = 100.0f * len4; len5 = Math.max(len5, 0.0f); red2 = (int) (ballColor.getRed() * 155 * len2 + 100.0 + len5); green2 = (int) (ballColor.getGreen() * 155 * len2 + 100.0 + len5); blue2 = (int) (ballColor.getBlue() * 155 * len2 + 100.0 + len5); } red2 = Math.min(red2 + 32, 255); green2 = Math.min(green2 + 32, 255); blue2 = Math.min(blue2 + 32, 255); // Bitwise masking to make model: model[j] = 0xff000000 | red2 << 16 | green2 << 8 | blue2; } else { model[j] = 0x00000000; } } } return component.createImage(new MemoryImageSource(diameter, diameter, model, 0, diameter)); } /** * normalizes the double[3] vector in place */ private static void normalize(double v[]) { double len = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); if (Math.abs(len - 0.0) < java.lang.Double.MIN_VALUE) { v[0] = 0.0; v[1] = 0.0; v[2] = 0.0; } else { v[0] = v[0] / len; v[1] = v[1] / len; v[2] = v[2] / len; } } public void renderLabel() { int j = 0; String s = null; Font font = new Font("Helvetica", Font.PLAIN, radius); g.setFont(font); FontMetrics fontMetrics = g.getFontMetrics(font); int k = fontMetrics.getAscent(); g.setColor(control.getTextColor()); String label = null; switch (control.labelMode) { case DisplayControl.SYMBOLS: label = atom.getSymbol(); break; case DisplayControl.TYPES: label = atom.getID(); break; case DisplayControl.NUMBERS: label = Integer.toString(atom.getAtomNumber() + 1); break; } if (label != null) { j = fontMetrics.stringWidth(label); g.drawString(label, x - j / 2, y + k / 2); } if (!control.getPropertyMode().equals("")) { // check to make sure this atom has this property: Enumeration propIter = atom.getProperties().elements(); while (propIter.hasMoreElements()) { PhysicalProperty p = (PhysicalProperty) propIter.nextElement(); if (p.getDescriptor().equals(control.getPropertyMode())) { // OK, we had this property. Let's draw the value on // screen: font = new Font("Helvetica", Font.PLAIN, radius / 2); g.setFont(font); g.setColor(control.getTextColor()); s = p.stringValue(); if (s.length() > 5) { s = s.substring(0, 5); } k = 2 + (int) (radius / 1.4142136f); g.drawString(s, x + k, y - k); } } } } } Index: AtomShape.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/render/AtomShape.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -r1.32 -r1.33 *** AtomShape.java 13 Dec 2002 23:54:54 -0000 1.32 --- AtomShape.java 17 Dec 2002 23:19:11 -0000 1.33 *************** *** 84,94 **** public void render(Graphics g, Rectangle clip, DisplayControl control) { ! renderBonds(g, clip, control); ! renderAtom(g, clip, control); ! renderLabel(g, clip, control); } public void renderBonds(Graphics g, Rectangle clip, DisplayControl control) { ! if (!control.showBonds || (!control.showHydrogens && atom.isHydrogen())) return; // FIXME -- the one instance of BondRenderer needs to be stored-in --- 84,101 ---- public void render(Graphics g, Rectangle clip, DisplayControl control) { ! if (!control.showHydrogens && atom.isHydrogen()) ! return; ! if (control.showBonds) ! renderBonds(g, clip, control); ! if (control.showAtoms && isClipVisible(clip)) { ! AtomRenderer atomRenderer = new AtomRenderer(); ! atomRenderer.setContext(g, clip, control); ! atomRenderer.render(this); ! } } public void renderBonds(Graphics g, Rectangle clip, DisplayControl control) { ! Atom[] bondedAtoms = atom.getBondedAtoms(); ! if (bondedAtoms == null) return; // FIXME -- the one instance of BondRenderer needs to be stored-in *************** *** 97,182 **** BondRenderer bondRenderer = new BondRenderer(); bondRenderer.setContext(g, clip, control); - Atom[] bondedAtoms = atom.getBondedAtoms(); - if (bondedAtoms == null) - return; for (int i = 0; i < bondedAtoms.length; ++i) { ! Atom otherAtom = bondedAtoms[i]; ! int zOther = otherAtom.getScreenZ(); ! if ((control.showHydrogens || !otherAtom.isHydrogen()) && ! (z > zOther) || ! ((z==zOther) && (atom.getAtomNumber() > otherAtom.getAtomNumber()))) ! bondRenderer.render(this, otherAtom.getAtomShape(), ! atom.getBondOrder(otherAtom)); ! } ! } ! ! static Hashtable htDarker = new Hashtable(); ! private Color getDarker(Color color) { ! Color darker = (Color) htDarker.get(color); ! if (darker == null) { ! darker = color.darker(); ! htDarker.put(color, darker); ! } ! return darker; ! } ! ! private Color getAtomColor(DisplayControl control, Atom atom) { ! org.openscience.cdk.renderer.color.AtomColorer colorProfile; ! if (control.getAtomColorProfile() == DisplayControl.ATOMCHARGE) ! colorProfile = ! new org.openscience.cdk.renderer.color.PartialAtomicChargeColors(); ! else ! colorProfile = AtomColors.getInstance(); ! return colorProfile.getAtomColor((org.openscience.cdk.Atom)atom); ! } ! ! private Color getOutline(DisplayControl control, Color color) { ! return control.showDarkerOutline ? getDarker(color) : control.outlineColor; ! } ! ! private void renderAtom(Graphics g, Rectangle clip, DisplayControl control) { ! if (!control.showAtoms || ! (!control.showHydrogens && atom.isHydrogen()) || ! !isVisible(clip)) ! return; ! ! if (!control.fastRendering && control.isSelected(atom)) { ! int halowidth = diameter / 3; ! if (halowidth < 2) ! halowidth = 2; ! int halodiameter = diameter + 2 * halowidth; ! int haloradius = halodiameter / 2; ! g.setColor(control.getPickedColor()); ! g.fillOval(x - haloradius, y - haloradius, halodiameter, halodiameter); ! } ! Color color = getAtomColor(control, atom); ! int radius = diameter / 2; ! g.setColor(color); ! if (diameter <= 3) { ! if (diameter > 0) { ! if (control.atomDrawMode==control.WIREFRAME && diameter==3) ! g.drawRect(x - radius, y - radius, 2, 2); ! else ! g.fillRect(x - radius, y - radius, diameter, diameter); } - } else { - if (!control.fastRendering && control.atomDrawMode==control.SHADING) { - renderShadedAtom(g, control, color); - return; - } - // the area *drawn* by an oval is 1 larger than the area - // *filled* by an oval - int diamT = diameter-1; - if (!control.fastRendering && control.atomDrawMode!=control.WIREFRAME) { - g.fillOval(x - radius, y - radius, diamT, diamT); - g.setColor(getOutline(control, color)); - } - g.drawOval(x - radius, y - radius, diamT, diamT); } } private static Rectangle rectTemp = new Rectangle(); ! private boolean isVisible(Rectangle clip) { ! int radius = diameter/2; rectTemp.setRect(x - radius, y - radius, diameter, diameter); // note that this is not correct if the atom is selected --- 104,124 ---- BondRenderer bondRenderer = new BondRenderer(); bondRenderer.setContext(g, clip, control); for (int i = 0; i < bondedAtoms.length; ++i) { ! Atom atomOther = bondedAtoms[i]; ! AtomShape atomShapeOther = atomOther.getAtomShape(); ! int zOther = atomShapeOther.z; ! if ((control.showHydrogens || !atomOther.isHydrogen()) && ! ((z > zOther) || ! (z==zOther && atom.getAtomNumber()>atomOther.getAtomNumber())) && ! isBondClipVisible(clip, x, y, atomShapeOther.x, atomShapeOther.y)) { ! bondRenderer.render(this, atomShapeOther, ! atom.getBondOrder(atomOther)); } } } private static Rectangle rectTemp = new Rectangle(); ! private boolean isClipVisible(Rectangle clip) { ! int radius = diameter / 2; rectTemp.setRect(x - radius, y - radius, diameter, diameter); // note that this is not correct if the atom is selected *************** *** 185,209 **** } ! private boolean isVisible(Rectangle clip, int x2, int y2) { // this is not actually correct, but quick & dirty int xMin, width, yMin, height; ! if (x < x2) { ! xMin = x; ! width = x2 - x; ! } else if (x2 < x) { xMin = x2; ! width = x - x2; } else { ! xMin = x; width = 1; } ! if (y < y2) { ! yMin = y; ! height = y2 - y; ! } else if (y2 < y) { yMin = y2; ! height = y - y2; } else { ! yMin = y; height = 1; } --- 127,152 ---- } ! private boolean isBondClipVisible(Rectangle clip, ! int x1, int y1, int x2, int y2) { // this is not actually correct, but quick & dirty int xMin, width, yMin, height; ! if (x1 < x2) { ! xMin = x1; ! width = x2 - x1; ! } else if (x2 < x1) { xMin = x2; ! width = x1 - x2; } else { ! xMin = x1; width = 1; } ! if (y1 < y2) { ! yMin = y1; ! height = y2 - y1; ! } else if (y2 < y1) { yMin = y2; ! height = y1 - y2; } else { ! yMin = y1; height = 1; } *************** *** 225,529 **** } - private static final int minCachedSize = 4; - private static final int maxCachedSize = 50; - private static final int scalableSize = 47; - private static final int maxSmoothedSize = 200; - // I am getting severe graphical artifacts around the edges when - // rendering hints are turned on. Therefore, I am adding a margin - // to shaded rendering in order to cut down on edge effects - private static final int artifactMargin = 4; - private static final int minShadingBufferSize = maxCachedSize; - private static final int maxShadingBufferSize = - maxSmoothedSize + artifactMargin*2; - - - private void renderShadedAtom(Graphics g, DisplayControl control, - Color color) { - if (! control.imageCache.containsKey(color)) { - loadShadedSphereCache(control, color); - } - Image[] shadedImages = (Image[]) control.imageCache.get(color); - int radius = diameter / 2; - if (diameter < minCachedSize) { - // the area drawn by an oval is 1 larger than the area - // filled by an oval - int diamTemp = diameter-1; - g.setColor(color); - g.fillOval(x - radius, y - radius, diamTemp, diamTemp); - g.setColor(getDarker(color)); - g.drawOval(x - radius, y - radius, diamTemp, diamTemp); - } else if (diameter < maxCachedSize) { - // images in the cache have a margin of 1 - g.drawImage(shadedImages[diameter], - x - radius - 1, y - radius - 1, null); - } else { - renderLargeShadedAtom(g, control, shadedImages[0]); - } - } - - private void renderLargeShadedAtom(Graphics g, DisplayControl control, - Image imgSphere) { - int radius = diameter / 2; - if (! control.useGraphics2D) { - g.drawImage(imgSphere, x - radius, y - radius, - diameter, diameter, null); - return; - } - if (diameter < maxSmoothedSize) { - drawScaledShadedAtom((Graphics2D) g, - imgSphere, x, y, diameter, artifactMargin); - } else { - // too big ... just forget the smoothing - // but we *can* clip it to eliminate fat pixels - Ellipse2D circle = - new Ellipse2D.Double(x-radius, y-radius, diameter, diameter); - g.setClip(circle); - g.drawImage(imgSphere, x - radius, y - radius, - diameter, diameter, null); - g.setClip(null); - } - } - - private static final double[] lightSource = { -1.0f, -1.0f, 2.0f }; - private void loadShadedSphereCache(DisplayControl control, Color color) { - Image shadedImages[] = new Image[maxCachedSize]; - Component component = control.getDisplayPanel(); - control.imageCache.put(color, shadedImages); - if (! control.useGraphics2D) { - for (int d = minCachedSize; d < maxCachedSize; ++d) { - shadedImages[d] = sphereSetup(component, color, d+2, lightSource); - } - shadedImages[0] = sphereSetup(component,color,scalableSize,lightSource); - return; - } - shadedImages[0] = sphereSetup(component, color, scalableSize, lightSource); - for (int d = minCachedSize; d < maxCachedSize; ++d) { - BufferedImage bi = new BufferedImage(d+2, d+2, - BufferedImage.TYPE_INT_ARGB); - Graphics2D g2 = bi.createGraphics(); - drawScaledShadedAtom(g2, shadedImages[0], d/2+1, d/2+1, d, 1); - shadedImages[d] = bi; - } - } - - private static byte[] mapRGBA; - private static IndexColorModel cmMask; - private static int sizeMask = 0; - private static BufferedImage biMask = null; - private static Graphics2D g2Mask; - private static WritableRaster rasterMask; - private static BufferedImage biAlphaMask; - - private void applyCircleMask(Graphics2D g, int diameter, int margin) { - // mth 2002 nov 12 - // a 4 bit greyscale mask would/should be sufficient here, but there - // was a bug in my JVM (or a bug in my head) which prevented it - // from working - if (mapRGBA == null) { - mapRGBA = new byte[256]; - for (int i = 0; i < 256; ++ i) { - mapRGBA[i] = (byte) i; - } - cmMask = new IndexColorModel(8, 256, mapRGBA, mapRGBA, mapRGBA, mapRGBA); - } - int size = diameter + 2*margin; - if (size > sizeMask) { - sizeMask = size * 2; - if (sizeMask < minShadingBufferSize) - sizeMask = minShadingBufferSize; - if (sizeMask > maxShadingBufferSize) - sizeMask = maxShadingBufferSize; - biMask = new BufferedImage(sizeMask, sizeMask, - BufferedImage.TYPE_BYTE_GRAY); - g2Mask = biMask.createGraphics(); - g2Mask.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - rasterMask = biMask.getRaster(); - biAlphaMask = new BufferedImage(cmMask, rasterMask, false, null); - } - g2Mask.setColor(Color.black); - g2Mask.fillRect(0, 0, size, size); - g2Mask.setColor(Color.white); - g2Mask.fillOval(margin, margin, diameter, diameter); - - Composite foo = g.getComposite(); - g.setComposite(AlphaComposite.DstIn); - g.drawImage(biAlphaMask, 0, 0, null); - g.setComposite(foo); - } - - private static int sizeShadingBuffer = 0; - private static BufferedImage biShadingBuffer = null; - private static Graphics2D g2ShadingBuffer = null; - - void drawScaledShadedAtom(Graphics2D g2, Image image, - int x, int y, int diameter, int margin) { - final int size = diameter + 2*margin; - if (size > sizeShadingBuffer) { - sizeShadingBuffer = size * 2; // leave some room to grow - if (sizeShadingBuffer < minShadingBufferSize) - sizeShadingBuffer = minShadingBufferSize; - if (sizeShadingBuffer > maxShadingBufferSize) - sizeShadingBuffer = maxShadingBufferSize; - biShadingBuffer = new BufferedImage(sizeShadingBuffer, sizeShadingBuffer, - BufferedImage.TYPE_INT_ARGB); - g2ShadingBuffer = biShadingBuffer.createGraphics(); - g2ShadingBuffer.setRenderingHint(RenderingHints.KEY_INTERPOLATION, - RenderingHints.VALUE_INTERPOLATION_BILINEAR); - } - g2ShadingBuffer.drawImage(image, 0, 0, size, size, null); - applyCircleMask(g2ShadingBuffer, diameter, margin); - int radius = diameter / 2; - int upperleftX = x - radius - margin; - int upperleftY = y - radius - margin; - int lowerrightX = upperleftX + diameter + margin; - int lowerrightY = upperleftY + diameter + margin; - g2.setClip(upperleftX, upperleftY, size, size); - g2.drawImage(biShadingBuffer, upperleftX, upperleftY, null); - g2.setClip(null); - // g2.drawImage(biShadingBuffer, - // upperleftX, upperleftY, lowerrightX, lowerrightY, - // 0, 0, size, size, - // null); - } - - /** - * Creates a shaded atom image. - */ - private static Image sphereSetup(Component component, Color ballColor, - int diameter, double[] lightSource) { - - double v1[] = new double[3]; - double v2[] = new double[3]; - int radius = (diameter + 1) / 2; // round it up - int j = -1; - - // Create our own version of an IndexColorModel: - int model[] = new int[diameter*diameter]; - - // Normalize the lightsource vector: - double[] lightsource = new double[3]; - for (int i = 0; i < 3; ++ i) - lightsource[i] = lightSource[i]; - normalize(lightsource); - for (int k1 = -(diameter - radius); k1 < radius; k1++) { - for (int k2 = -(diameter - radius); k2 < radius; k2++) { - j++; - v1[0] = k2; - v1[1] = k1; - double len1 = Math.sqrt(k2 * k2 + k1 * k1); - if (len1 <= radius) { - int red2 = 0; - int green2 = 0; - int blue2 = 0; - v1[2] = radius * Math.cos(Math.asin(len1 / radius)); - normalize(v1); - double len2 = Math.abs((v1[0] * lightsource[0] - + v1[1] * lightsource[1] + v1[2] * lightsource[2])); - if (len2 < 0.995f) { - red2 = (int) (ballColor.getRed() * len2); - green2 = (int) (ballColor.getGreen() * len2); - blue2 = (int) (ballColor.getBlue() * len2); - } else { - v2[0] = lightsource[0] + 0.0f; - v2[1] = lightsource[1] + 0.0f; - v2[2] = lightsource[2] + 1.0f; - normalize(v2); - double len3 = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; - double len4 = 8.0f * len3 * len3 - 7.0f; - double len5 = 100.0f * len4; - len5 = Math.max(len5, 0.0f); - red2 = (int) (ballColor.getRed() * 155 * len2 + 100.0 + len5); - green2 = (int) (ballColor.getGreen() * 155 * len2 + 100.0 + len5); - blue2 = (int) (ballColor.getBlue() * 155 * len2 + 100.0 + len5); - } - red2 = Math.min(red2 + 32, 255); - green2 = Math.min(green2 + 32, 255); - blue2 = Math.min(blue2 + 32, 255); - - - // Bitwise masking to make model: - model[j] = 0xff000000 | red2 << 16 | green2 << 8 | blue2; - } else { - model[j] = 0x00000000; - } - } - } - return component.createImage(new MemoryImageSource(diameter, diameter, - model, 0, diameter)); - } - - /** - * normalizes the double[3] vector in place - */ - private static void normalize(double v[]) { - - double len = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); - if (Math.abs(len - 0.0) < java.lang.Double.MIN_VALUE) { - v[0] = 0.0; - v[1] = 0.0; - v[2] = 0.0; - } else { - v[0] = v[0] / len; - v[1] = v[1] / len; - v[2] = v[2] / len; - } - } - - public void renderLabel(Graphics g, Rectangle clip, DisplayControl control) { - if (control.labelMode == control.NOLABELS) - return; - - int radius=diameter/2; - int j = 0; - String s = null; - Font font = new Font("Helvetica", Font.PLAIN, radius); - g.setFont(font); - FontMetrics fontMetrics = g.getFontMetrics(font); - int k = fontMetrics.getAscent(); - g.setColor(control.getTextColor()); - - String label = null; - switch (control.labelMode) { - case DisplayControl.SYMBOLS: - label = atom.getSymbol(); - break; - - case DisplayControl.TYPES: - label = atom.getID(); - break; - - case DisplayControl.NUMBERS: - label = Integer.toString(atom.getAtomNumber() + 1); - break; - - } - if (label != null) { - j = fontMetrics.stringWidth(label); - g.drawString(label, x - j / 2, y + k / 2); - } - if (!control.getPropertyMode().equals("")) { - - // check to make sure this atom has this property: - Enumeration propIter = atom.getProperties().elements(); - while (propIter.hasMoreElements()) { - PhysicalProperty p = (PhysicalProperty) propIter.nextElement(); - if (p.getDescriptor().equals(control.getPropertyMode())) { - - // OK, we had this property. Let's draw the value on - // screen: - font = new Font("Helvetica", Font.PLAIN, radius / 2); - g.setFont(font); - g.setColor(control.getTextColor()); - s = p.stringValue(); - if (s.length() > 5) { - s = s.substring(0, 5); - } - k = 2 + (int) (radius / 1.4142136f); - g.drawString(s, x + k, y - k); - } - } - } - } } --- 168,171 ---- Index: BondRenderer.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/render/BondRenderer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** BondRenderer.java 13 Dec 2002 23:54:54 -0000 1.1 --- BondRenderer.java 17 Dec 2002 23:19:11 -0000 1.2 *************** *** 71,81 **** int x1 = atomShape1.x, y1 = atomShape1.y; int x2 = atomShape2.x, y2 = atomShape2.y; - if (!isInsideClip(clip, x1, y1, x2, y2)) - return; int dx = x2 - x1, dx2 = dx * dx; int dy = y2 - y1, dy2 = dy * dy; int magnitude2 = dx2 + dy2; ! Color color1 = getAtomColor(control, atomShape1.atom); ! Color color2 = getAtomColor(control, atomShape2.atom); if ((magnitude2 <= 2) || (control.fastRendering && magnitude2 <= 49)) return; // also avoid divide by zero when magnitude == 0 --- 71,79 ---- int x1 = atomShape1.x, y1 = atomShape1.y; int x2 = atomShape2.x, y2 = atomShape2.y; int dx = x2 - x1, dx2 = dx * dx; int dy = y2 - y1, dy2 = dy * dy; int magnitude2 = dx2 + dy2; ! Color color1 = control.getAtomColor(atomShape1.atom); ! Color color2 = control.getAtomColor(atomShape2.atom); if ((magnitude2 <= 2) || (control.fastRendering && magnitude2 <= 49)) return; // also avoid divide by zero when magnitude == 0 *************** *** 144,150 **** return; } ! if (control.bondDrawMode != control.SHADING) { ! Color outline1 = getOutline(control, color1); ! Color outline2 = getOutline(control, color2); if (halfBondWidth < .75) { drawLineBond(g, control, --- 142,150 ---- return; } ! Color outline1 = control.getAtomOutlineColor(color1); ! Color outline2 = control.getAtomOutlineColor(color2); ! if (control.bondDrawMode != control.SHADING || ! control.mouseDragged ! || (int)halfBondWidth < 2) { if (halfBondWidth < .75) { drawLineBond(g, control, *************** *** 165,216 **** return; } ! // drawing shaded bonds ! if (control.mouseDragged || (int)halfBondWidth < 2) { ! drawRectBond(g, control, ! x1Bond, y1Bond, color1, getDarker(color1), ! x1Edge, y1Edge, ! x2Bond, y2Bond, color2, getDarker(color2), ! true, ! dx, dy, magnitude, bondOrder, halfBondWidth, halfBondWidth); ! return; ! } ! Color darker1 = getDarker(color1), outline1 = darker1; ! Color bright1 = color1; ! Color darker2 = getDarker(color2), outline2 = darker2; ! Color bright2 = color2; ! ! int atom1R = darker1.getRed(), range1R = bright1.getRed() - atom1R; ! int atom1G = darker1.getGreen(), range1G = bright1.getGreen() - atom1G; ! int atom1B = darker1.getBlue(), range1B = bright1.getBlue() - atom1B; ! int atom2R = darker2.getRed(), range2R = bright2.getRed() - atom2R; ! int atom2G = darker2.getGreen(), range2G = bright2.getGreen() - atom2G; ! int atom2B = darker2.getBlue(), range2B = bright2.getBlue() - atom2B; int numPasses = (int)halfBondWidth; double widthT = halfBondWidth; ! for (int i = 0; i < numPasses; ++i, widthT -= 1.0) { ! // numPasses must be > 1 because of test above ! double pct = (double) i / (numPasses - 1); ! int r1 = atom1R + (int)(pct * range1R); ! int g1 = atom1G + (int)(pct * range1G); ! int b1 = atom1B + (int)(pct * range1B); ! int r2 = atom2R + (int)(pct * range2R); ! int g2 = atom2G + (int)(pct * range2G); ! int b2 = atom2B + (int)(pct * range2B); ! ! // Bitwise masking to make color model: ! int model1 = 0xFF << 24 | r1 << 16 | g1 << 8 | b1; ! Color co1 = new Color(model1); ! int model2 = 0xFF << 24 | r2 << 16 | g2 << 8 | b2; ! Color co2 = new Color(model2); ! drawRectBond(g, control, ! x1Bond, y1Bond, co1, outline1, x1Edge, y1Edge, ! x2Bond, y2Bond, co2, outline2, true, dx, dy, magnitude, bondOrder, widthT, halfBondWidth); - // only draw the outline the first time around - outline1 = outline2 = null; } } --- 165,181 ---- return; } ! Color[] shades1 = getShades(color1, outline1); ! Color[] shades2 = getShades(color2, outline2); int numPasses = (int)halfBondWidth; double widthT = halfBondWidth; ! for (int i = numPasses; --i >= 0; widthT -= 1.0) { ! int index = i * maxShade / numPasses; drawRectBond(g, control, ! x1Bond, y1Bond, shades1[index], null, x1Edge, y1Edge, ! x2Bond, y2Bond, shades2[index], null, true, dx, dy, magnitude, bondOrder, widthT, halfBondWidth); } } *************** *** 508,578 **** } ! static Hashtable htDarker = new Hashtable(); ! private Color getDarker(Color color) { ! Color darker = (Color) htDarker.get(color); ! if (darker == null) { ! darker = color.darker(); ! htDarker.put(color, darker); ! } ! return darker; ! } ! ! private Color getAtomColor(DisplayControl control, Atom atom) { ! org.openscience.cdk.renderer.color.AtomColorer colorProfile; ! if (control.getAtomColorProfile() == DisplayControl.ATOMCHARGE) ! colorProfile = ! new org.openscience.cdk.renderer.color.PartialAtomicChargeColors(); ! else ! colorProfile = AtomColors.getInstance(); ! return colorProfile.getAtomColor((org.openscience.cdk.Atom)atom); ! } ! ! private Color getOutline(DisplayControl control, Color color) { ! return control.showDarkerOutline ? getDarker(color) : control.outlineColor; ! } ! ! private static Rectangle rectTemp = new Rectangle(); ! ! private boolean isInsideClip(Rectangle clip, ! int x1, int y1, int x2, int y2) { ! // this is not actually correct, but quick & dirty ! int xMin, width, yMin, height; ! if (x1 < x2) { ! xMin = x1; ! width = x2 - x1; ! } else if (x2 < x1) { ! xMin = x2; ! width = x1 - x2; ! } else { ! xMin = x1; ! width = 1; ! } ! if (y1 < y2) { ! yMin = y1; ! height = y2 - y1; ! } else if (y2 < y1) { ! yMin = y2; ! height = y1 - y2; ! } else { ! yMin = y1; ! height = 1; } ! // there are some problems with this quick&dirty implementation ! // so I am going to throw in some slop ! xMin -= 5; ! yMin -= 5; ! width += 10; ! height += 10; ! rectTemp.setRect(xMin, yMin, width, height); ! boolean visible = clip.intersects(rectTemp); ! /* ! System.out.println("bond " + x + "," + y + "->" + x2 + "," + y2 + ! " & " + clip.x + "," + clip.y + ! " W " + clip.width + " H " + clip.height + ! "->" + visible); ! */ ! return visible; } - } - --- 473,497 ---- } ! private final Hashtable htShades = new Hashtable(); ! final static int maxShade = 16; ! Color[] getShades(Color color, Color darker) { ! Color[] shades = (Color[])htShades.get(color); ! if (shades == null) { ! int darkerR = darker.getRed(), rangeR = color.getRed() - darkerR; ! int darkerG = darker.getGreen(), rangeG = color.getGreen() - darkerG; ! int darkerB = darker.getBlue(), rangeB = color.getBlue() - darkerB; ! shades = new Color[maxShade]; ! for (int i = 0; i < maxShade; ++i) { ! double distance = (float)i / (maxShade - 1); ! double percentage = Math.sqrt(1 - distance); ! int r = darkerR + (int)(percentage * rangeR); ! int g = darkerG + (int)(percentage * rangeG); ! int b = darkerB + (int)(percentage * rangeB); ! int rgb = 0xFF << 24 | r << 16 | g << 8 | b; ! shades[i] = new Color(rgb); ! } ! htShades.put(color, shades); } ! return shades; } } |