From: <ha...@us...> - 2007-05-18 19:16:25
|
Revision: 7744 http://svn.sourceforge.net/jmol/?rev=7744&view=rev Author: hansonr Date: 2007-05-18 12:16:21 -0700 (Fri, 18 May 2007) Log Message: ----------- 11.1.42 Frame refactoring Modified Paths: -------------- trunk/Jmol/src/org/jmol/modelframe/Frame.java trunk/Jmol/src/org/jmol/modelframe/FrameLoader.java trunk/Jmol/src/org/jmol/modelframe/ModelManager.java trunk/Jmol/src/org/jmol/shapespecial/Polyhedra.java Modified: trunk/Jmol/src/org/jmol/modelframe/Frame.java =================================================================== --- trunk/Jmol/src/org/jmol/modelframe/Frame.java 2007-05-18 18:19:58 UTC (rev 7743) +++ trunk/Jmol/src/org/jmol/modelframe/Frame.java 2007-05-18 19:16:21 UTC (rev 7744) @@ -59,6 +59,28 @@ import java.util.Vector; import java.awt.Rectangle; + +/* + * An abstract class always created using new FrameLoader(...) + * + * FrameLoader simply pulls out all private classes that are + * necessary only for file loading (and structure recalculation). + * + * What is left here are all the methods that are + * necessary AFTER a model is loaded, when it is being + * accessed by ModelManager or other classes. + * + * Please: + * + * 1) designate any methods accessed only by ModelManager as default + * 2) designate any methods accessed only by FrameLoader as protected + * 3) designate any methods used only here as private + * + * methods needing access outside this package, of course, are designated public + * + * Bob Hanson, 5/2007 + * + */ abstract public class Frame { Viewer viewer; @@ -107,6 +129,24 @@ return atomNames; } + private final WithinModelIterator withinModelIterator = new WithinModelIterator(); + + AtomIterator getWithinModelIterator(Atom atomCenter, float radius) { + //Polyhedra + initializeBspf(); + withinModelIterator.initialize(bspf, atomCenter.modelIndex, atomCenter, radius); + return withinModelIterator; + } + + private final WithinAtomSetIterator withinAtomSetIterator = new WithinAtomSetIterator(); + + AtomIndexIterator getWithinAtomSetIterator(int atomIndex, float distance, BitSet bsSelected, boolean isGreaterOnly) { + //EnvelopeCalculation, IsoSolventReader + initializeBspf(); + withinAtomSetIterator.initialize(this, bspf, atoms[atomIndex].modelIndex, atomIndex, distance, bsSelected, isGreaterOnly); + return withinAtomSetIterator; + } + Bond[] bonds; int bondCount; @@ -127,6 +167,16 @@ return bondCount; } + public BondIterator getBondIterator(short bondType, BitSet bsSelected) { + //Dipoles, Sticks + return new SelectedBondIterator(this, bondType, bsSelected, viewer.getBondSelectionModeOr()); + } + + public BondIterator getBondIterator(BitSet bsSelected) { + //Sticks + return new SelectedBondIterator(this, bsSelected); + } + //note: Molecules is set up to only be calculated WHEN NEEDED protected Molecule[] molecules = new Molecule[4]; protected int moleculeCount; @@ -2689,33 +2739,4 @@ return cmd.toString(); } - - /////////// iterators //////////// - - private final WithinModelIterator withinModelIterator = new WithinModelIterator(); - - public AtomIterator getWithinModelIterator(Atom atomCenter, float radius) { - initializeBspf(); - withinModelIterator.initialize(bspf, atomCenter.modelIndex, atomCenter, radius); - return withinModelIterator; - } - - private final WithinAtomSetIterator withinAtomSetIterator = new WithinAtomSetIterator(); - - AtomIndexIterator getWithinAtomSetIterator(int atomIndex, float distance, BitSet bsSelected, boolean isGreaterOnly) { - initializeBspf(); - withinAtomSetIterator.initialize(this, bspf, atoms[atomIndex].modelIndex, atomIndex, distance, bsSelected, isGreaterOnly); - return withinAtomSetIterator; - } - - public BondIterator getBondIterator(short bondType, BitSet bsSelected) { - //Dipoles, Sticks - return new SelectedBondIterator(this, bondType, bsSelected, viewer.getBondSelectionModeOr()); - } - - public BondIterator getBondIterator(BitSet bsSelected) { - //Sticks - return new SelectedBondIterator(this, bsSelected); - } - } Modified: trunk/Jmol/src/org/jmol/modelframe/FrameLoader.java =================================================================== --- trunk/Jmol/src/org/jmol/modelframe/FrameLoader.java 2007-05-18 18:19:58 UTC (rev 7743) +++ trunk/Jmol/src/org/jmol/modelframe/FrameLoader.java 2007-05-18 19:16:21 UTC (rev 7744) @@ -41,12 +41,16 @@ import java.util.Vector; /* - * This subclass contains all of the methods used to - * load a model. Methods only after model loading - * are not included here. * + * Except for calculateStructures this subclass contains + * only the private methods used to load a model. + * Methods exclusively after file loading are included + * only in the superclass, Frame. + * + * Bob Hanson, 5/2007 * */ + public final class FrameLoader extends Frame { private FrameLoader mergeFrame; @@ -60,7 +64,6 @@ private Group[] groups; private int groupCount; - FrameLoader(Viewer viewer, String name) { this.viewer = viewer; initializeFrame(name, 1, null, null); @@ -223,7 +226,6 @@ finalizeGroupBuild(); // set group offsets and build monomers //only now can we access all of the atom's properties - buildBioPolymers(); freeze(); calcAverageAtomPoint(); calcBoundBoxDimensions(); @@ -669,6 +671,18 @@ info.put("group3Counts", group3Counts); } } + + group3Counts = null; + group3Lists = null; + + for (int i = 0; i < groupCount; ++i) { + Group group = groups[i]; + if (merging) + group.setFrame(this); + if (jbr != null) + jbr.buildBioPolymer(group, groups, i); + } + } private boolean haveBioClasses = true; @@ -758,16 +772,6 @@ countGroup(modelCount, code, group3); } - private void buildBioPolymers() { - for (int i = 0; i < groupCount; ++i) { - Group group = groups[i]; - if (merging) - group.setFrame(this); - if (jbr != null) - jbr.buildBioPolymer(group, groups, i); - } - } - private void freeze() { // resize arrays @@ -847,6 +851,36 @@ } } + private void calcAverageAtomPoint() { + averageAtomPoint.set(0, 0, 0); + if (atomCount == 0) + return; + for (int i = atomCount; --i >= 0;) + averageAtomPoint.add(atoms[i]); + averageAtomPoint.scale(1f / atomCount); + } + + + /////////////// shapes /////////////// + + private void finalizeShapes() { + if (merging) { + for (int i = 0; i < JmolConstants.SHAPE_MAX; i++) + if ((shapes[i] = mergeFrame.shapes[i]) != null) + shapes[i].setFrame(this); + viewer.getFrameRenderer().clear(); + merging = false; + return; + } + loadShape(JmolConstants.SHAPE_BALLS); + loadShape(JmolConstants.SHAPE_STICKS); + loadShape(JmolConstants.SHAPE_MEASURES); + loadShape(JmolConstants.SHAPE_BBCAGE); + loadShape(JmolConstants.SHAPE_UCCAGE); + } + + // the ONLY nonprivate method in this class + /** * allows rebuilding of PDB structures; * also accessed by ModelManager from Eval @@ -872,7 +906,6 @@ atom.getGroup3(), atom.getSeqNumber(), atom.getInsertionCode()); } finalizeGroupBuild(); - buildBioPolymers(); fileHadDefinedStructures = false; moleculeCount = 0; } @@ -881,31 +914,4 @@ mmset.freeze(); } - private void calcAverageAtomPoint() { - averageAtomPoint.set(0, 0, 0); - if (atomCount == 0) - return; - for (int i = atomCount; --i >= 0;) - averageAtomPoint.add(atoms[i]); - averageAtomPoint.scale(1f / atomCount); - } - - - /////////////// shapes /////////////// - - private void finalizeShapes() { - if (merging) { - for (int i = 0; i < JmolConstants.SHAPE_MAX; i++) - if ((shapes[i] = mergeFrame.shapes[i]) != null) - shapes[i].setFrame(this); - viewer.getFrameRenderer().clear(); - merging = false; - return; - } - loadShape(JmolConstants.SHAPE_BALLS); - loadShape(JmolConstants.SHAPE_STICKS); - loadShape(JmolConstants.SHAPE_MEASURES); - loadShape(JmolConstants.SHAPE_BBCAGE); - loadShape(JmolConstants.SHAPE_UCCAGE); - } } Modified: trunk/Jmol/src/org/jmol/modelframe/ModelManager.java =================================================================== --- trunk/Jmol/src/org/jmol/modelframe/ModelManager.java 2007-05-18 18:19:58 UTC (rev 7743) +++ trunk/Jmol/src/org/jmol/modelframe/ModelManager.java 2007-05-18 19:16:21 UTC (rev 7744) @@ -52,7 +52,8 @@ public class ModelManager { private final Viewer viewer; - private FrameLoader frame; + private FrameLoader frameLoader; + private Frame frame; private String fullPathName; private String fileName; @@ -73,17 +74,18 @@ void clearFrame() { //just a bit cleaner -- never two frames in memory, //even if one would always be "empty" - frame = null; + frame = frameLoader = null; //System.gc(); } public void zap() { clear(); fullPathName = fileName = modelSetName = "zapped"; - frame = new FrameLoader(viewer, "empty"); + frame = frameLoader = new FrameLoader(viewer, "empty"); } public void merge(JmolAdapter adapter, Object clientFile ) { - frame = new FrameLoader(viewer, adapter, clientFile, frame); + frame = frameLoader = new FrameLoader(viewer, adapter, clientFile, + frameLoader); //haveFile = true; if (frame.getAtomCount() == 0) zap(); @@ -105,7 +107,7 @@ if (modelSetName == null) modelSetName = reduceFilename(fileName); clearFrame(); - frame = new FrameLoader(viewer, adapter, clientFile, null); + frame = frameLoader = new FrameLoader(viewer, adapter, clientFile, null); //haveFile = true; if (frame.getAtomCount() == 0) zap(); @@ -1401,7 +1403,7 @@ } public void calculateStructures() { - frame.calculateStructures(true); + frameLoader.calculateStructures(true); } public boolean getEchoStateActive() { Modified: trunk/Jmol/src/org/jmol/shapespecial/Polyhedra.java =================================================================== --- trunk/Jmol/src/org/jmol/shapespecial/Polyhedra.java 2007-05-18 18:19:58 UTC (rev 7743) +++ trunk/Jmol/src/org/jmol/shapespecial/Polyhedra.java 2007-05-18 19:16:21 UTC (rev 7744) @@ -268,7 +268,7 @@ Polyhedron constructRadiusPolyhedron(int atomIndex) { Atom atom = atoms[atomIndex]; int otherAtomCount = 0; - AtomIterator withinIterator = frame.getWithinModelIterator(atom, radius); + AtomIterator withinIterator = viewer.getWithinModelIterator(atom, radius); while (withinIterator.hasNext()) { Atom other = withinIterator.next(); if (other == atom || bsVertices != null This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |