From: <gil...@us...> - 2009-03-16 15:18:08
|
Revision: 14497 http://cdk.svn.sourceforge.net/cdk/?rev=14497&view=rev Author: gilleain Date: 2009-03-16 15:17:54 +0000 (Mon, 16 Mar 2009) Log Message: ----------- - Altered makeNewStereoBond to return a reference to the new bond. - Fixed AlterBondStereoModule so that it does what it did before. Modified Paths: -------------- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/AddRingModule.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/AlterBondStereoModule.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/ControllerHub.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/ControllerModuleAdapter.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/IChemModelRelay.java Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/AddRingModule.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/AddRingModule.java 2009-03-16 13:26:48 UTC (rev 14496) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/AddRingModule.java 2009-03-16 15:17:54 UTC (rev 14497) @@ -35,8 +35,8 @@ /** * Adds an atom on the given location on mouseclick - * - * @author Gilleain Torrance + * + * @author maclean * @cdk.module control */ public class AddRingModule extends ControllerModuleAdapter { @@ -50,15 +50,15 @@ this.ringSize = ringSize; this.addingBenzene = addingBenzene; } - + private IRing addRingToEmptyCanvas(Point2d p) { - if (this.addingBenzene) { + if (addingBenzene) { return chemModelRelay.addPhenyl(p); } else { return chemModelRelay.addRing(ringSize, p); } } - + private IRing addRingToAtom(IAtom closestAtom) { IRing newring; if (addingBenzene) { @@ -69,7 +69,7 @@ newring.removeAtom(closestAtom); return newring; } - + private IRing addRingToBond(IBond bond) { IRing newring; if (addingBenzene) { @@ -86,36 +86,35 @@ public void mouseClickedDown(Point2d worldCoord) { IAtom closestAtom = chemModelRelay.getClosestAtom(worldCoord); IBond closestBond = chemModelRelay.getClosestBond(worldCoord); - + IChemObject singleSelection = getHighlighted( worldCoord, closestAtom,closestBond ); - - if(singleSelection==null) { - this.addRingToEmptyCanvas(worldCoord); - }else - if( singleSelection instanceof IAtom) { - this.addRingToAtom((IAtom)singleSelection); - }else - if(singleSelection instanceof IBond) { - this.addRingToBond((IBond)singleSelection); - } - if(singleSelection == null) - setSelection( AbstractSelection.EMPTY_SELECTION ); - else - setSelection( new SingleSelection<IChemObject>(singleSelection) ); - - chemModelRelay.updateView(); - } + if (singleSelection == null) { + this.addRingToEmptyCanvas(worldCoord); + } else if (singleSelection instanceof IAtom) { + this.addRingToAtom((IAtom) singleSelection); + } else if (singleSelection instanceof IBond) { + this.addRingToBond((IBond) singleSelection); + } + if (singleSelection == null) + setSelection(AbstractSelection.EMPTY_SELECTION); + else + setSelection(new SingleSelection<IChemObject>(singleSelection)); + + chemModelRelay.updateView(); + } + public void setChemModelRelay(IChemModelRelay relay) { this.chemModelRelay = relay; } public String getDrawModeString() { - if(addingBenzene) - return "Benzene"; - else - return "Ring" + " " + ringSize; + if (addingBenzene) { + return "Benzene"; + } else { + return "Ring" + " " + ringSize; + } } } Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/AlterBondStereoModule.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/AlterBondStereoModule.java 2009-03-16 13:26:48 UTC (rev 14496) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/AlterBondStereoModule.java 2009-03-16 15:17:54 UTC (rev 14497) @@ -25,42 +25,58 @@ */ package org.openscience.cdk.controller; -import java.util.HashSet; -import java.util.Set; import javax.vecmath.Point2d; import org.openscience.cdk.controller.ControllerHub.Direction; -import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IBond; +import org.openscience.cdk.interfaces.IChemObject; +import org.openscience.cdk.renderer.selection.AbstractSelection; +import org.openscience.cdk.renderer.selection.SingleSelection; /** - * Alters the chirality of a bond, setting it to be into or outof the plane. - * - * @author Gilleain Torrance + * Alters the chirality of a bond, setting it to be into or out of the plane. + * + * @author maclean * @cdk.svnrev $Revision$ * @cdk.module control */ public class AlterBondStereoModule extends ControllerModuleAdapter { - + private Direction desiredDirection; - public AlterBondStereoModule(IChemModelRelay chemModelRelay, Direction desiredDirection) { + public AlterBondStereoModule( + IChemModelRelay chemModelRelay, Direction desiredDirection) { super(chemModelRelay); this.desiredDirection = desiredDirection; } + public void mouseClickedDown(Point2d worldCoord) { + IAtom atom = this.chemModelRelay.getClosestAtom(worldCoord); + IBond bond = this.chemModelRelay.getClosestBond(worldCoord); - public void mouseClickedDown(Point2d worldCoord) { - - IAtomContainer selectedAC = getSelectedAtomContainer( worldCoord ); - Set<IBond> newSelection = new HashSet<IBond>(); - if(selectedAC == null) return; - for(IBond bond:selectedAC.bonds()) { - newSelection.add( bond ); - chemModelRelay.makeBondStereo( bond, desiredDirection ); - } + IChemObject singleSelection = getHighlighted(worldCoord, atom, bond); + + if (singleSelection == null) { + setSelection(AbstractSelection.EMPTY_SELECTION); + } else if (singleSelection instanceof IAtom) { + IBond newBond = + super.chemModelRelay.makeNewStereoBond(atom, desiredDirection); + IAtom otherAtom = newBond.getConnectedAtom(atom); + super.setSelection(new SingleSelection<IChemObject>(otherAtom)); + } else if (singleSelection instanceof IBond) { + super.chemModelRelay.makeBondStereo(bond, desiredDirection); + + // FIXME : highlighting a wedge bond looks bad at the moment +// setSelection(new SingleSelection<IChemObject>(bond)); + } else { + // by default, change the bond + super.chemModelRelay.makeBondStereo(bond, desiredDirection);; + } + + super.chemModelRelay.updateView(); } public void setChemModelRelay(IChemModelRelay relay) { @@ -68,11 +84,10 @@ } public String getDrawModeString() { - if (desiredDirection==Direction.UP) { + if (desiredDirection == Direction.UP) { return "Add or convert to bond up"; } else { return "Add or convert to bond down"; } } - } Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/ControllerHub.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/ControllerHub.java 2009-03-16 13:26:48 UTC (rev 14496) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/ControllerHub.java 2009-03-16 15:17:54 UTC (rev 14497) @@ -73,12 +73,9 @@ import org.openscience.cdk.nonotify.NoNotificationChemObjectBuilder; import org.openscience.cdk.renderer.Renderer; import org.openscience.cdk.renderer.RendererModel; -import org.openscience.cdk.renderer.selection.IChemObjectSelection; import org.openscience.cdk.renderer.selection.IncrementalSelection; -import org.openscience.cdk.tools.CDKHydrogenAdder; import org.openscience.cdk.tools.SaturationChecker; import org.openscience.cdk.tools.manipulator.AtomContainerManipulator; -import org.openscience.cdk.tools.manipulator.AtomTypeManipulator; import org.openscience.cdk.tools.manipulator.BondManipulator; import org.openscience.cdk.tools.manipulator.ChemModelManipulator; import org.openscience.cdk.tools.manipulator.ReactionSetManipulator; @@ -87,40 +84,40 @@ /** * Class that will central interaction point between a mouse event throwing * widget (SWT or Swing) and the Controller2D modules. - * + * * <p>FIXME: will replace the old Controller2D class. - * + * * @cdk.svnrev $Revision: 9162 $ * @cdk.module control * @author Niels Out * @author egonw */ public class ControllerHub implements IMouseEventRelay, IChemModelRelay { - + public enum Direction { UP, DOWN }; private IChemModel chemModel; - - private IControllerModel controllerModel; + + private IControllerModel controllerModel; private Renderer renderer; private IViewEventRelay eventRelay; - + private List<IControllerModule> generalModules; - + private StructureDiagramGenerator diagramGenerator; private IControllerModule activeDrawModule; private final static RingPlacer ringPlacer = new RingPlacer(); - + private IAtomContainer phantoms; private IChemModelEventRelayHandler changeHandler; - + private IUndoRedoFactory undoredofactory; - + private UndoRedoHandler undoredohandler; - + CDKAtomTypeMatcher matcher; - + public ControllerHub(IControllerModel controllerModel, Renderer renderer, IChemModel chemModel, @@ -134,22 +131,22 @@ this.phantoms = chemModel.getBuilder().newAtomContainer(); this.undoredofactory=undoredofactory; this.undoredohandler=undoredohandler; - + generalModules = new ArrayList<IControllerModule>(); - + registerGeneralControllerModule(new HighlightModule(this)); registerGeneralControllerModule(new ZoomModule(this)); matcher = CDKAtomTypeMatcher.getInstance(chemModel.getBuilder()); } - + public IControllerModel getController2DModel() { return controllerModel; } - + public Renderer getRenderer() { return renderer; } - + public IChemModel getIChemModel() { return chemModel; } @@ -166,7 +163,7 @@ public void unRegisterAllControllerModule() { generalModules.clear(); } - + /** * Adds a general IController2DModule which will catch all mouse events. */ @@ -174,14 +171,14 @@ module.setChemModelRelay(this); generalModules.add(module); } - + public void mouseWheelMovedBackward(int clicks) { for (IControllerModule module : generalModules) { module.mouseWheelMovedBackward(clicks); } IControllerModule activeModule = getActiveDrawModule(); if (activeModule != null) activeModule.mouseWheelMovedBackward(clicks); - + } public void mouseWheelMovedForward(int clicks) { @@ -190,19 +187,19 @@ } IControllerModule activeModule = getActiveDrawModule(); if (activeModule != null) activeModule.mouseWheelMovedForward(clicks); - + } public void mouseClickedDouble(int screenCoordX, int screenCoordY) { - Point2d worldCoord = + Point2d worldCoord = renderer.toModelCoordinates(screenCoordX, screenCoordY); - + // Relay the mouse event to the general handlers for (IControllerModule module : generalModules) { module.mouseClickedDouble(worldCoord); } - // Relay the mouse event to the active + // Relay the mouse event to the active IControllerModule activeModule = getActiveDrawModule(); if (activeModule != null) activeModule.mouseClickedDouble(worldCoord); } @@ -210,123 +207,123 @@ public void mouseClickedDownRight(int screenX, int screenY) { Point2d modelCoord = renderer.toModelCoordinates(screenX, screenY); - + // Relay the mouse event to the general handlers for (IControllerModule module : generalModules) { module.mouseClickedDownRight(modelCoord); } - // Relay the mouse event to the active + // Relay the mouse event to the active IControllerModule activeModule = getActiveDrawModule(); if (activeModule != null) activeModule.mouseClickedDownRight(modelCoord); } public void mouseClickedUpRight(int screenX, int screenY) { Point2d modelCoord = renderer.toModelCoordinates(screenX, screenY); - + // Relay the mouse event to the general handlers for (IControllerModule module : generalModules) { module.mouseClickedUpRight(modelCoord); } - // Relay the mouse event to the active + // Relay the mouse event to the active IControllerModule activeModule = getActiveDrawModule(); if (activeModule != null) activeModule.mouseClickedUpRight(modelCoord); } - + public void mouseClickedDown(int screenX, int screenY) { Point2d modelCoord = renderer.toModelCoordinates(screenX, screenY); - + // Relay the mouse event to the general handlers for (IControllerModule module : generalModules) { module.mouseClickedDown(modelCoord); } - // Relay the mouse event to the active + // Relay the mouse event to the active IControllerModule activeModule = getActiveDrawModule(); if (activeModule != null) activeModule.mouseClickedDown(modelCoord); } public void mouseClickedUp(int screenX, int screenY) { Point2d modelCoord = renderer.toModelCoordinates(screenX, screenY); - + // Relay the mouse event to the general handlers for (IControllerModule module : generalModules) { module.mouseClickedUp(modelCoord); } - // Relay the mouse event to the active + // Relay the mouse event to the active IControllerModule activeModule = getActiveDrawModule(); if (activeModule != null) activeModule.mouseClickedUp(modelCoord); } public void mouseDrag( int screenXFrom, int screenYFrom, int screenXTo, int screenYTo) { - Point2d modelCoordFrom = + Point2d modelCoordFrom = renderer.toModelCoordinates(screenXFrom, screenYFrom); - Point2d modelCoordTo = + Point2d modelCoordTo = renderer.toModelCoordinates(screenXTo, screenYTo); - + // Relay the mouse event to the general handlers for (IControllerModule module : generalModules) { module.mouseDrag(modelCoordFrom, modelCoordTo); } - // Relay the mouse event to the active + // Relay the mouse event to the active IControllerModule activeModule = getActiveDrawModule(); - if (activeModule != null) { + if (activeModule != null) { activeModule.mouseDrag(modelCoordFrom, modelCoordTo); } } public void mouseEnter(int screenX, int screenY) { Point2d worldCoord = renderer.toModelCoordinates(screenX, screenY); - + // Relay the mouse event to the general handlers for (IControllerModule module : generalModules) { module.mouseEnter(worldCoord); } - // Relay the mouse event to the active + // Relay the mouse event to the active IControllerModule activeModule = getActiveDrawModule(); if (activeModule != null) activeModule.mouseEnter(worldCoord); } public void mouseExit(int screenX, int screenY) { Point2d worldCoord = renderer.toModelCoordinates(screenX, screenY); - + // Relay the mouse event to the general handlers for (IControllerModule module : generalModules) { module.mouseExit(worldCoord); } - // Relay the mouse event to the active + // Relay the mouse event to the active IControllerModule activeModule = getActiveDrawModule(); if (activeModule != null) activeModule.mouseExit(worldCoord); } public void mouseMove(int screenX, int screenY) { Point2d worldCoord = renderer.toModelCoordinates(screenX, screenY); - + // Relay the mouse event to the general handlers for (IControllerModule module : generalModules) { module.mouseMove(worldCoord); } - // Relay the mouse event to the active + // Relay the mouse event to the active IControllerModule activeModule = getActiveDrawModule(); if (activeModule != null) activeModule.mouseMove(worldCoord); } - + public void updateView() { //call the eventRelay method here to update the view.. eventRelay.updateView(); } - + public IControllerModule getActiveDrawModule() { return activeDrawModule; } - + public void setActiveDrawModule(IControllerModule activeDrawModule){ this.activeDrawModule=activeDrawModule; } @@ -352,7 +349,7 @@ return closestAtom; } - + public IBond getClosestBond(Point2d worldCoord) { IBond closestBond = null; double closestDistanceSQ = Double.MAX_VALUE; @@ -377,7 +374,7 @@ return closestBond; } - + public IAtomContainer removeAtomWithoutUndo(IAtom atom) { IAtomContainer ac = atom.getBuilder().newAtomContainer(); ac.addAtom(atom); @@ -394,7 +391,7 @@ structureChanged(); return ac; } - + public IAtomContainer removeAtom(IAtom atom) { IAtomContainer ac = removeAtomWithoutUndo(atom); if(getUndoRedoFactory()!=null && getUndoRedoHandler()!=null){ @@ -403,7 +400,7 @@ } return ac; } - + public IAtom addAtom(String atomType, Point2d worldCoord) { IAtomContainer undoRedoContainer = chemModel.getBuilder().newAtomContainer(); undoRedoContainer.addAtom(addAtomWithoutUndo(atomType, worldCoord)); @@ -413,10 +410,10 @@ } return undoRedoContainer.getAtom(0); } - + public IAtom addAtomWithoutUndo(String atomType, Point2d worldCoord) { IAtom newAtom = chemModel.getBuilder().newAtom(atomType, worldCoord); - + //FIXME : there should be an initial hierarchy? IMoleculeSet molSet = chemModel.getMoleculeSet(); if (molSet == null) { @@ -439,7 +436,7 @@ public IAtom addAtom(String atomType, IAtom atom) { IAtomContainer undoRedoContainer = atom.getBuilder().newAtomContainer(); undoRedoContainer.addAtom(addAtomWithoutUndo(atomType, atom)); - IAtomContainer atomContainer = + IAtomContainer atomContainer = ChemModelManipulator.getRelevantAtomContainer( getIChemModel(), undoRedoContainer.getAtom(0)); IBond newBond = atomContainer.getBond(atom, undoRedoContainer.getAtom(0)); @@ -450,11 +447,11 @@ } return undoRedoContainer.getAtom(0); } - + public IAtom addAtomWithoutUndo(String atomType, IAtom atom) { IAtom newAtom = chemModel.getBuilder().newAtom(atomType); IBond newBond = chemModel.getBuilder().newBond(atom, newAtom); - IAtomContainer atomCon = + IAtomContainer atomCon = ChemModelManipulator.getRelevantAtomContainer(chemModel, atom); if (atomCon == null) { atomCon = chemModel.getBuilder().newAtomContainer(); @@ -465,7 +462,7 @@ } moleculeSet.addAtomContainer(atomCon); } - + // The AtomPlacer generates coordinates for the new atom AtomPlacer atomPlacer = new AtomPlacer(); atomPlacer.setMolecule(chemModel.getBuilder().newMolecule(atomCon)); @@ -475,8 +472,8 @@ } else { bondLength = 1.4; // XXX Or some sensible default? } - - // determine the atoms which define where the + + // determine the atoms which define where the // new atom should not be placed List<IAtom> connectedAtoms = atomCon.getConnectedAtomsList(atom); @@ -497,10 +494,10 @@ IAtomContainer placedAtoms = atomCon.getBuilder().newAtomContainer(); for (IAtom conAtom : connectedAtoms) placedAtoms.addAtom(conAtom); Point2d center2D = GeometryTools.get2DCenter(placedAtoms); - + IAtomContainer unplacedAtoms = atomCon.getBuilder().newAtomContainer(); unplacedAtoms.addAtom(newAtom); - + atomPlacer.distributePartners( atom, placedAtoms, center2D, unplacedAtoms, bondLength); } @@ -514,16 +511,16 @@ structureChanged(); return newAtom; } - + public void addNewBond(Point2d worldCoordinate) { IAtomContainer undoRedoContainer = getIChemModel().getBuilder().newAtomContainer(); - String atomType = + String atomType = getController2DModel().getDrawElement(); IAtom atom = addAtomWithoutUndo(atomType, worldCoordinate); undoRedoContainer.addAtom(atom); IAtom newAtom = addAtomWithoutUndo(atomType, atom); undoRedoContainer.addAtom(newAtom); - IAtomContainer atomContainer = + IAtomContainer atomContainer = ChemModelManipulator.getRelevantAtomContainer( getIChemModel(), newAtom); IBond newBond = atomContainer.getBond(atom, newAtom); @@ -536,7 +533,7 @@ undoredohandler.postEdit(undoredo); } } - + public void cycleBondValence(IBond bond) { IBond.Order[] orders=new IBond.Order[2]; Integer[] stereos=new Integer[2]; @@ -547,7 +544,7 @@ bond.setStereo(STEREO_BOND_NONE); }else{ // cycle the bond order up to maxOrder - IBond.Order maxOrder = + IBond.Order maxOrder = getController2DModel().getMaxOrder(); if (BondManipulator.isLowerOrder(bond.getOrder(), maxOrder)) { BondManipulator.increaseBondOrder(bond); @@ -569,15 +566,15 @@ undoredohandler.postEdit(undoredo); } } - - public void makeNewStereoBond(IAtom atom, Direction desiredDirection) { - String atomType = + + public IBond makeNewStereoBond(IAtom atom, Direction desiredDirection) { + String atomType = getController2DModel().getDrawElement(); IAtom newAtom = addAtomWithoutUndo(atomType, atom); IAtomContainer undoRedoContainer=getIChemModel().getBuilder().newAtomContainer(); - + // XXX these calls would not be necessary if addAtom returned a bond - IAtomContainer atomContainer = + IAtomContainer atomContainer = ChemModelManipulator.getRelevantAtomContainer( getIChemModel(), newAtom); IBond newBond = atomContainer.getBond(atom, newAtom); @@ -593,8 +590,9 @@ IUndoRedoable undoredo = getUndoRedoFactory().getAddAtomsAndBondsEdit(getIChemModel(), undoRedoContainer, "Add Stereo Bond",this); getUndoRedoHandler().postEdit(undoredo); } + return newBond; } - + public void moveToWithoutUndo( IAtom atom, Point2d worldCoords ) { if ( atom != null ) { Point2d atomCoord = new Point2d( worldCoords ); @@ -646,7 +644,7 @@ moveToWithoutUndo(bond, point); } } - + public IBond addBond(IAtom fromAtom, IAtom toAtom) { IBond newBond = chemModel.getBuilder().newBond(fromAtom, toAtom); chemModel.getMoleculeSet().getAtomContainer(0).addBond(newBond); @@ -754,7 +752,7 @@ chemModel.setReactionSet(chemModel.getBuilder().newReactionSet()); structureChanged(); } - + public void makeBondStereo(IBond bond, Direction desiredDirection) { int stereo = bond.getStereo(); boolean isUp = isUp(stereo); @@ -787,10 +785,10 @@ getUndoRedoHandler().postEdit(undoredo); } } - + /** * Change the stereo bond from start->end to start<-end. - * + * * @param bond the bond to change * @param stereo the current stereo of that bond */ @@ -800,8 +798,8 @@ else if (stereo == STEREO_BOND_DOWN_INV) bond.setStereo(STEREO_BOND_DOWN); else if (stereo == STEREO_BOND_DOWN) bond.setStereo(STEREO_BOND_DOWN_INV); } - - + + /** * Change the stereo of the bond from UP<->DOWN. * @param bond the bond to change @@ -813,15 +811,15 @@ else if (stereo == STEREO_BOND_DOWN_INV) bond.setStereo(STEREO_BOND_UP); else if (stereo == STEREO_BOND_DOWN) bond.setStereo(STEREO_BOND_UP_INV); } - + private boolean isUp(int stereo) { return stereo == STEREO_BOND_UP || stereo == STEREO_BOND_UP_INV; } - + private boolean isDown(int stereo) { return stereo == STEREO_BOND_DOWN || stereo == STEREO_BOND_DOWN_INV; } - + private boolean noStereo(int stereo) { return stereo == STEREO_BOND_NONE || stereo == CDKConstants.STEREO_BOND_UNDEFINED; } @@ -830,37 +828,37 @@ Map<IAtom, Point2d[]> coords = new HashMap<IAtom, Point2d[]>(); for (IAtomContainer container : ChemModelManipulator.getAllAtomContainers(chemModel)) { - + for (IAtom atom : container.atoms()){ Point2d[] coordsforatom = new Point2d[2]; coordsforatom[1] = atom.getPoint2d(); coords.put(atom, coordsforatom); atom.setPoint2d(null); } - + if (ConnectivityChecker.isConnected(container)) { generateNewCoordinates(container); } else { // deal with disconnected atom containers - IMoleculeSet molecules = + IMoleculeSet molecules = ConnectivityChecker.partitionIntoMolecules(container); Rectangle2D usedBounds = null; for (IAtomContainer subContainer : molecules.molecules()) { generateNewCoordinates(subContainer); - + // now move it so that they don't overlap Rectangle2D bounds = Renderer.calculateBounds(subContainer); if (usedBounds != null) { - Rectangle2D shiftedBounds = + Rectangle2D shiftedBounds = shiftContainer(subContainer, bounds, usedBounds); usedBounds = usedBounds.createUnion(shiftedBounds); } else { usedBounds = bounds; } } - + } - + for (IAtom atom : container.atoms()) { Point2d[] coordsforatom = coords.get(atom); coordsforatom[0] = atom.getPoint2d(); @@ -868,12 +866,12 @@ } coordinatesChanged(); if (getUndoRedoFactory() != null && getUndoRedoHandler() != null) { - IUndoRedoable undoredo = + IUndoRedoable undoredo = getUndoRedoFactory().getChangeCoordsEdit(coords, "Clean Up"); getUndoRedoHandler().postEdit(undoredo); } } - + /** * Shift the container so that it does not overlap with the previous. * XXX this is a very crude layout technique! @@ -883,15 +881,15 @@ */ private Rectangle2D shiftContainer( IAtomContainer container, Rectangle2D bounds, Rectangle2D last) { - - RendererModel model = renderer.getRenderer2DModel(); - double gap = model.getBondLength() / model.getScale(); - + + RendererModel model = renderer.getRenderer2DModel(); + double gap = model.getBondLength() / model.getScale(); + if (bounds.intersects(last)) { - + // XXX always displace across width - could be improved double d = bounds.getWidth() + last.getWidth() + gap; - + Point2d p = new Point2d(last.getCenterX() + d, last.getCenterY()); GeometryTools.translate2DCenterTo(container, p); return new Rectangle2D.Double(bounds.getX() + d, @@ -902,11 +900,11 @@ return bounds; } } - + private void generateNewCoordinates(IAtomContainer container) { - IChemObjectBuilder builder = + IChemObjectBuilder builder = NoNotificationChemObjectBuilder.getInstance(); - + if (diagramGenerator == null) { diagramGenerator = new StructureDiagramGenerator(); diagramGenerator.setTemplateHandler( @@ -933,13 +931,13 @@ e.printStackTrace(); } } - + public IRing addRing(int ringSize, Point2d worldcoord) { IRing ring = chemModel.getBuilder().newRing(ringSize, "C"); double bondLength = 1.4; ringPlacer.placeRing(ring, worldcoord, bondLength); IMoleculeSet set = chemModel.getMoleculeSet(); - + // the molecule set should not be null, but just in case... if (set == null) { set = chemModel.getBuilder().newMoleculeSet(); @@ -992,25 +990,25 @@ } public IRing addRing(IAtom atom, int ringSize) { - IAtomContainer sourceContainer + IAtomContainer sourceContainer = ChemModelManipulator.getRelevantAtomContainer(chemModel, atom); IAtomContainer sharedAtoms = atom.getBuilder().newAtomContainer(); sharedAtoms.addAtom(atom); - + IRing newRing = createAttachRing(sharedAtoms, ringSize, "C"); double bondLength = GeometryTools.getBondLengthAverage(sourceContainer); Point2d conAtomsCenter = getConnectedAtomsCenter(sharedAtoms, chemModel); - + Point2d sharedAtomsCenter = atom.getPoint2d(); Vector2d ringCenterVector = new Vector2d(sharedAtomsCenter); ringCenterVector.sub(conAtomsCenter); ringPlacer.placeSpiroRing( newRing, sharedAtoms, sharedAtomsCenter, ringCenterVector, bondLength); - + for (IAtom ringAtom : newRing.atoms()) { if (ringAtom != atom) sourceContainer.addAtom(ringAtom); } - + for (IBond ringBond : newRing.bonds()) { sourceContainer.addBond(ringBond); } @@ -1024,18 +1022,18 @@ } public IRing addPhenyl(IAtom atom) { - IAtomContainer sourceContainer + IAtomContainer sourceContainer = ChemModelManipulator.getRelevantAtomContainer(chemModel, atom); IAtomContainer sharedAtoms = atom.getBuilder().newAtomContainer(); sharedAtoms.addAtom(atom); - + // make a benzene ring IRing newRing = createAttachRing(sharedAtoms, 6, "C"); newRing.getBond(0).setOrder(IBond.Order.DOUBLE); newRing.getBond(2).setOrder(IBond.Order.DOUBLE); newRing.getBond(4).setOrder(IBond.Order.DOUBLE); makeRingAromatic(newRing); - + double bondLength; if (sourceContainer.getBondCount() == 0) { /* @@ -1048,7 +1046,7 @@ } else { bondLength = GeometryTools.getBondLengthAverage(sourceContainer); Point2d conAtomsCenter = getConnectedAtomsCenter(sharedAtoms, chemModel); - + Point2d sharedAtomsCenter = atom.getPoint2d(); Vector2d ringCenterVector = new Vector2d(sharedAtomsCenter); ringCenterVector.sub(conAtomsCenter); @@ -1058,12 +1056,12 @@ ringCenterVector, bondLength); } - + // add the ring to the source container for (IAtom ringAtom : newRing.atoms()) { if (ringAtom != atom) sourceContainer.addAtom(ringAtom); } - + for (IBond ringBond : newRing.bonds()) { sourceContainer.addBond(ringBond); } @@ -1082,7 +1080,7 @@ for (IBond bond : newRing.bonds()) bond.setFlag(CDKConstants.ISAROMATIC, true); } - + /** * Constructs a new Ring of a certain size that contains all the atoms and * bonds of the given AtomContainer and is filled up with new Atoms and Bonds. @@ -1131,13 +1129,13 @@ * @param sharedAtoms The Atoms the attached partners are searched of * @return The Center Point of all the atoms found */ - private Point2d getConnectedAtomsCenter(IAtomContainer sharedAtoms, + private Point2d getConnectedAtomsCenter(IAtomContainer sharedAtoms, IChemModel chemModel) { IAtomContainer conAtoms = sharedAtoms.getBuilder().newAtomContainer(); for (IAtom sharedAtom : sharedAtoms.atoms()) { conAtoms.addAtom(sharedAtom); - IAtomContainer atomCon = - ChemModelManipulator.getRelevantAtomContainer(chemModel, + IAtomContainer atomCon = + ChemModelManipulator.getRelevantAtomContainer(chemModel, sharedAtom); for (IAtom atom : atomCon.getConnectedAtomsList(sharedAtom)) { conAtoms.addAtom(atom); @@ -1216,23 +1214,23 @@ structureChanged(); return newRing; } - + public IAtom getAtomInRange(Point2d worldCoord, Collection<IAtom> toignore, IAtom atomtoignore) { - + IAtom superClosestAtom=null; // TODO Use highlighted atom instead for(IAtomContainer atomContainer: ChemModelManipulator.getAllAtomContainers(getIChemModel())){ - IAtom closestAtom = GeometryTools.getClosestAtom( worldCoord.x,worldCoord.y, - atomContainer, + IAtom closestAtom = GeometryTools.getClosestAtom( worldCoord.x,worldCoord.y, + atomContainer, atomtoignore); if (closestAtom != null) { RendererModel rModel = this.getRenderer().getRenderer2DModel(); if ((closestAtom.getPoint2d().distance( worldCoord ) - > rModel.getHighlightDistance()/rModel.getScale()) + > rModel.getHighlightDistance()/rModel.getScale()) || (toignore!=null && toignore.contains(closestAtom))) { closestAtom = null; @@ -1334,7 +1332,7 @@ updateAtom(bond.getAtom(1)); structureChanged(); } - + public void removeBond(IBond bond) { removeBondWithoutUndo(bond); IAtomContainer undAtomContainer = bond.getBuilder().newAtomContainer(); @@ -1405,7 +1403,7 @@ changedBonds.put(bond,orders); bond.setOrder(Order.SINGLE); } - } + } if(this.getController2DModel().getAutoUpdateImplicitHydrogens()) updateImplicitHydrogenCounts(); if(undoredofactory!=null && undoredohandler!=null){ @@ -1416,7 +1414,7 @@ public void replaceAtom(IAtom atomnew, IAtom atomold) { IAtomContainer relevantContainer = ChemModelManipulator.getRelevantAtomContainer(chemModel, atomold); - AtomContainerManipulator.replaceAtomByAtom(relevantContainer, + AtomContainerManipulator.replaceAtomByAtom(relevantContainer, atomold, atomnew); updateAtom(atomnew); structureChanged(); @@ -1444,9 +1442,9 @@ { ProblemMarker.unmark(atoms.getAtom(i)); } - } + } } - + public void flip(boolean horizontal){ HashMap<IAtom, Point2d[]> atomCoordsMap = new HashMap<IAtom, Point2d[]>(); RendererModel renderModel = renderer.getRenderer2DModel(); @@ -1515,14 +1513,14 @@ if (changeHandler != null) changeHandler.selectionChanged(); } - /* + /* * Fill a selection by passing it to the hub, which uses its internal * chem model to do so. */ public void select(IncrementalSelection selection) { - if(selection != null) - selection.select(this.chemModel); - selectionChanged(); + if (selection != null) + selection.select(this.chemModel); + selectionChanged(); } public void addFragment(IAtomContainer toPaste) { @@ -1629,7 +1627,7 @@ } structureChanged(); } - + /** * Updates an array of atoms with respect to its hydrogen count * @@ -1657,7 +1655,7 @@ if(container != null) updateAtom(container, atom); } - + /** * Updates an atom with respect to its hydrogen count * @@ -1717,13 +1715,13 @@ int hcount=atom.getHydrogenCount(); for(int k=0;k<hcount;k++){ IAtom newAtom = this.addAtomWithoutUndo("H", atom); - IAtomContainer atomContainer = + IAtomContainer atomContainer = ChemModelManipulator.getRelevantAtomContainer( getIChemModel(), newAtom); IBond newBond = atomContainer.getBond(atom, newAtom); undoRedoContainer.addAtom(newAtom); undoRedoContainer.addBond(newBond); - } + } } } if(getUndoRedoFactory()!=null && getUndoRedoHandler()!=null){ @@ -1740,7 +1738,7 @@ IUndoRedoable undoredo = getUndoRedoFactory().getChangeHydrogenCountEdit(atomhydrogenmap, "Change hydrogen count to "+intValue); getUndoRedoHandler().postEdit(undoredo); } - atom.setHydrogenCount(intValue); + atom.setHydrogenCount(intValue); structureChanged(); } } Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/ControllerModuleAdapter.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/ControllerModuleAdapter.java 2009-03-16 13:26:48 UTC (rev 14496) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/ControllerModuleAdapter.java 2009-03-16 15:17:54 UTC (rev 14497) @@ -114,42 +114,43 @@ return null; } - /** - * Handles selection behavior. - * When noting is within the highlight radius null is return and the selection - * is cleared. If a atom/bond is selected and part of the current selection - * the returned atom container contains the selection. If the atom/bond is not - * part of the selection the selection is updated to contained only the - * atom/bond and is returned in the atom container. - * an AtomContaienr is return containing the - * - * @param worldCoord - * @return a AtomContainer containing the atoms/bond that should be affected - * by this action. Otherwise <code>null</code>. - */ - protected IAtomContainer getSelectedAtomContainer( Point2d worldCoord ) { - RendererModel rModel =chemModelRelay.getRenderer().getRenderer2DModel(); - IAtom atom = chemModelRelay.getClosestAtom(worldCoord); - IBond bond = chemModelRelay.getClosestBond(worldCoord); + /** + * Handles selection behavior. When nothing is within the highlight radius, + * null is returned and the selection is cleared. If an atom or bond is + * selected that is part of the current selection, the returned atom + * container contains the selection. If the atom or bond is not part of the + * selection, the selection is updated to contain only the atom or bond + * and is returned in the atom container. + * + * @param worldCoord + * @return a AtomContainer containing the atoms/bond that should be affected + * by this action. Otherwise <code>null</code>. + */ + protected IAtomContainer getSelectedAtomContainer(Point2d worldCoord) { + RendererModel rModel = + chemModelRelay.getRenderer().getRenderer2DModel(); + IAtom atom = chemModelRelay.getClosestAtom(worldCoord); + IBond bond = chemModelRelay.getClosestBond(worldCoord); - IChemObjectSelection localSelection = rModel.getSelection(); - IChemObject chemObject = getHighlighted( worldCoord, atom, bond ); + IChemObjectSelection localSelection = rModel.getSelection(); + IChemObject chemObject = getHighlighted(worldCoord, atom, bond); - if(!localSelection.contains( chemObject )) { - if(chemObject != null) - localSelection = new SingleSelection<IChemObject>(chemObject); - else - localSelection = AbstractSelection.EMPTY_SELECTION; - - } - setSelection( localSelection ); - return selection.getConnectedAtomContainer(); - } - + if (!localSelection.contains(chemObject)) { + if (chemObject != null) { + localSelection = new SingleSelection<IChemObject>(chemObject); + } else { + localSelection = AbstractSelection.EMPTY_SELECTION; + } + } + setSelection(localSelection); + return selection.getConnectedAtomContainer(); + } + protected void setSelection(IChemObjectSelection selection) { this.selection = selection; chemModelRelay.getRenderer().getRenderer2DModel().setSelection(selection); - chemModelRelay.select( null ); /* FIXME setSelection on IChemModelRelay + chemModelRelay.select( null ); + /* FIXME setSelection on IChemModelRelay the selection should probably be in the ControllerHub and not in the RendererModel */ chemModelRelay.updateView(); Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/IChemModelRelay.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/IChemModelRelay.java 2009-03-16 13:26:48 UTC (rev 14496) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/IChemModelRelay.java 2009-03-16 15:17:54 UTC (rev 14497) @@ -1,9 +1,9 @@ /* $Revision: 7636 $ $Author: nielsout $ $Date: 2007-09-02 11:46:10 +0100 (su, 02 sep 2007) $ - * + * * Copyright (C) 2007 Egon Willighagen <eg...@us...sts.sf> - * + * * Contact: cdk...@li... - * + * * This program 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 @@ -12,12 +12,12 @@ * - but is not limited to - adding the above copyright notice to the beginning * of your source code files, and to any copyright notice that you may distribute * with programs based on this work. - * + * * This program 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 program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. @@ -56,7 +56,7 @@ public IAtom getAtomInRange(Point2d worldCoord, Collection<IAtom> toignore, IAtom atomtoignore); public void updateView(); public void select(IncrementalSelection selection); - + /* Event model */ public void setEventHandler(IChemModelEventRelayHandler handler); @@ -64,7 +64,7 @@ * Adds an temporary atom which might be cleared later, when the final * atom is added. Controllers can use this to draw temporary atoms, for * example while drawing new bonds. - * + * * @param atom atom to add as phantom */ public void addPhantomAtom(IAtom atom); @@ -72,7 +72,7 @@ * Adds an temporary bond which might be cleared later, when the final * bond is added. Controllers can use this to draw temporary bonds, for * example while drawing new bonds. - * + * * @param bond bond to add as phantom */ public void addPhantomBond(IBond bond); @@ -119,17 +119,17 @@ // public abstract void cleanupSelection(Selector sectionIdentifier); /* Editing actions for atoms */ - public abstract IAtomContainer removeAtom(IAtom atom); - public abstract IAtomContainer removeAtomWithoutUndo(IAtom atom); - public abstract IAtom addAtom(String element, Point2d worldcoord); - public abstract IAtom addAtomWithoutUndo(String element, Point2d worldcoord); - public abstract IAtom addAtom(String element, IAtom atom); - public abstract IAtom addAtomWithoutUndo(String element, IAtom atom); - public abstract void moveToWithoutUndo(IAtom atom, Point2d point); - public abstract void moveTo(IAtom atom, Point2d point); - public abstract void setSymbol(IAtom atom, String symbol); - public abstract void setCharge(IAtom atom, int charge); - public abstract void setMassNumber(IAtom atom, int charge); + public IAtomContainer removeAtom(IAtom atom); + public IAtomContainer removeAtomWithoutUndo(IAtom atom); + public IAtom addAtom(String element, Point2d worldcoord); + public IAtom addAtomWithoutUndo(String element, Point2d worldcoord); + public IAtom addAtom(String element, IAtom atom); + public IAtom addAtomWithoutUndo(String element, IAtom atom); + public void moveToWithoutUndo(IAtom atom, Point2d point); + public void moveTo(IAtom atom, Point2d point); + public void setSymbol(IAtom atom, String symbol); + public void setCharge(IAtom atom, int charge); + public void setMassNumber(IAtom atom, int charge); public void setHydrogenCount(IAtom atom, int intValue); public void replaceAtom(IAtom atomnew, IAtom atomold); public void addSingleElectron(IAtom atom); @@ -137,18 +137,18 @@ public void updateAtom(IAtom atom); /* Editing actions for bonds */ - public abstract IBond addBond(IAtom fromAtom, IAtom toAtom); - public abstract void removeBondWithoutUndo(IBond bond); - public abstract void removeBond(IBond bond); - public abstract void moveToWithoutUndo(IBond bond, Point2d point); - public abstract void moveTo(IBond bond, Point2d point); - public abstract void setOrder(IBond bond, IBond.Order order); - public abstract void setWedgeType(IBond bond, int type); - public abstract void addNewBond(Point2d worldCoordinate); + public IBond addBond(IAtom fromAtom, IAtom toAtom); + public void removeBondWithoutUndo(IBond bond); + public void removeBond(IBond bond); + public void moveToWithoutUndo(IBond bond, Point2d point); + public void moveTo(IBond bond, Point2d point); + public void setOrder(IBond bond, IBond.Order order); + public void setWedgeType(IBond bond, int type); + public void addNewBond(Point2d worldCoordinate); public void cycleBondValence(IBond bond); public void makeBondStereo(IBond bond, Direction desiredDirection); - public void makeNewStereoBond(IAtom atom, Direction desiredDirection); - + public IBond makeNewStereoBond(IAtom atom, Direction desiredDirection); + public IUndoRedoFactory getUndoRedoFactory(); - public UndoRedoHandler getUndoRedoHandler(); + public UndoRedoHandler getUndoRedoHandler(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |