Search in sources :

Example 56 with StereoMolecule

use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.

the class SelectionAction method onMouseDown.

@Override
public boolean onMouseDown(IMouseEvent evt) {
    java.awt.geom.Point2D pt = new Point2D.Double(evt.getX(), evt.getY());
    StereoMolecule mol = model.getMoleculeAt(pt, true);
    polygon = factory.createPolygon();
    polygon.add(pt);
    duplicate = false;
    changed = false;
    model.pushUndo();
    last = origin = new Point2D.Double(pt.getX(), pt.getY());
    atom = getAtomAt(mol, origin);
    bond = getBondAt(mol, origin);
    if (atom != -1) {
        if (!mol.isSelectedAtom(atom)) {
            if (!shift)
                deselectAllAtoms();
            mol.setAtomSelection(atom, true);
        }
    } else if (bond != -1) {
        if (!mol.isSelectedBond(bond)) {
            if (!shift)
                deselectAllAtoms();
            int a1 = mol.getBondAtom(0, bond);
            int a2 = mol.getBondAtom(1, bond);
            mol.setAtomSelection(a1, true);
            mol.setAtomSelection(a2, true);
        }
    }
    return false;
}
Also used : Point2D(java.awt.geom.Point2D) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 57 with StereoMolecule

use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.

the class UnknownParityAction method onMouseUp.

@Override
public boolean onMouseUp(IMouseEvent evt) {
    model.pushUndo();
    boolean ok = false;
    int theAtom = model.getSelectedAtom();
    StereoMolecule mol = model.getMolecule();
    if (mol != null && theAtom != -1) {
        mol.setAtomConfigurationUnknown(theAtom, !mol.isAtomConfigurationUnknown(theAtom));
        ok = true;
    }
    return ok;
}
Also used : StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 58 with StereoMolecule

use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.

the class ZoomRotateAction method onMouseMove.

@Override
public boolean onMouseMove(IMouseEvent ev, boolean drag) {
    if (drag) {
        boolean selectedOnly = false;
        StereoMolecule mol = model.getMolecule();
        for (int i = 0; i < mol.getAllAtoms(); i++) {
            if (mol.isSelectedAtom(i))
                selectedOnly = true;
        }
        java.awt.geom.Point2D pt = new Point2D.Double(ev.getX(), ev.getY());
        float magnification = (Math.abs(pt.getY() - origin.getY()) < 20 ? 1.0f : (float) Math.exp((pt.getY() - origin.getY()) / 100f));
        float angleChange = (Math.abs(pt.getX() - origin.getX()) < 20 ? 0.0f : (float) (pt.getX() - origin.getX()) / 50.0f);
        mol.zoomAndRotate(magnification, angleChange, selectedOnly);
        return true;
    }
    return false;
}
Also used : Point2D(java.awt.geom.Point2D) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 59 with StereoMolecule

use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.

the class DownBondAction method onChangeBond.

public void onChangeBond(int bond) {
    StereoMolecule mol = model.getMolecule();
    if (mol != null) {
        mol.changeBond(bond, Molecule.cBondTypeDown);
        mol.ensureHelperArrays(Molecule.cHelperNeighbours);
    }
}
Also used : StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 60 with StereoMolecule

use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.

the class DrawAction method suggestNewX2AndY2.

protected java.awt.geom.Point2D suggestNewX2AndY2(int atom) {
    // .getSelectedMolecule();
    StereoMolecule mol = model.getMolecule();
    mol.ensureHelperArrays(Molecule.cHelperNeighbours);
    double newAngle = Math.PI * 2 / 3;
    if (atom != -1) {
        double[] angle = new double[DrawAction.MAX_CONNATOMS + 1];
        // angle[0] = Math.PI * 3 / 4;
        for (int i = 0; i < mol.getAllConnAtoms(atom); i++) {
            angle[i] = mol.getBondAngle(atom, mol.getConnAtom(atom, i));
        }
        if (mol.getAllConnAtoms(atom) == 0) {
            newAngle = Math.PI * 2 / 3;
        } else if (mol.getAllConnAtoms(atom) == 1) {
            if (angle[0] < -Math.PI * 5 / 6) {
                newAngle = Math.PI / 3;
            } else if (angle[0] < -Math.PI / 2) {
                newAngle = Math.PI * 2 / 3;
            } else if (angle[0] < -Math.PI / 6) {
                newAngle = Math.PI / 3;
            } else if (angle[0] < 0.0) {
                newAngle = Math.PI * 2 / 3;
            } else if (angle[0] < Math.PI / 6) {
                newAngle = -Math.PI * 2 / 3;
            } else if (angle[0] < Math.PI / 2) {
                newAngle = -Math.PI / 3;
            } else if (angle[0] < Math.PI * 5 / 6) {
                newAngle = -Math.PI * 2 / 3;
            } else {
                newAngle = -Math.PI / 3;
            }
        } else {
            for (int i = mol.getAllConnAtoms(atom) - 1; i > 0; i--) {
                // bubble sort
                for (int j = 0; j < i; j++) {
                    if (angle[j] > angle[j + 1]) {
                        double temp = angle[j];
                        angle[j] = angle[j + 1];
                        angle[j + 1] = temp;
                    }
                }
            }
            angle[mol.getAllConnAtoms(atom)] = angle[0] + Math.PI * 2;
            int largestNo = 0;
            double largestDiff = 0.0;
            for (int i = 0; i < mol.getAllConnAtoms(atom); i++) {
                double angleDiff = angle[i + 1] - angle[i];
                if (largestDiff < angleDiff) {
                    largestDiff = angleDiff;
                    largestNo = i;
                }
            }
            newAngle = (angle[largestNo] + angle[largestNo + 1]) / 2;
        }
    }
    double avbl = mol.getAverageBondLength();
    return new Point2D.Double(mol.getAtomX(atom) + avbl * Math.sin(newAngle), mol.getAtomY(atom) + avbl * Math.cos(newAngle));
}
Also used : StereoMolecule(com.actelion.research.chem.StereoMolecule)

Aggregations

StereoMolecule (com.actelion.research.chem.StereoMolecule)62 Point2D (java.awt.geom.Point2D)11 Canonizer (com.actelion.research.chem.Canonizer)8 IDCodeParser (com.actelion.research.chem.IDCodeParser)8 GeomFactory (com.actelion.research.share.gui.editor.geom.GeomFactory)7 SSSearcher (com.actelion.research.chem.SSSearcher)4 Rectangle2D (java.awt.geom.Rectangle2D)3 IDrawingObject (com.actelion.research.share.gui.editor.chem.IDrawingObject)2 IOException (java.io.IOException)2 Depictor2D (com.actelion.research.chem.Depictor2D)1 DrawingObjectList (com.actelion.research.chem.DrawingObjectList)1 CoordinateInventor (com.actelion.research.chem.coords.CoordinateInventor)1 IAtomPropertiesDialog (com.actelion.research.share.gui.editor.dialogs.IAtomPropertiesDialog)1 IAtomQueryFeaturesDialog (com.actelion.research.share.gui.editor.dialogs.IAtomQueryFeaturesDialog)1 IBondQueryFeaturesDialog (com.actelion.research.share.gui.editor.dialogs.IBondQueryFeaturesDialog)1 LittleEndianDataOutputStream (com.actelion.research.util.LittleEndianDataOutputStream)1 IntVec (com.actelion.research.util.datamodel.IntVec)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1