Search in sources :

Example 6 with StereoMolecule

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

the class AddRingAction method onMouseUp.

public boolean onMouseUp(IMouseEvent evt) {
    model.pushUndo();
    StereoMolecule mol = model.getMolecule();
    java.awt.geom.Point2D pt = new Point2D.Double(evt.getX(), evt.getY());
    boolean ok = false;
    if (mol != null) {
        int atom = getAtomAt(mol, pt);
        int bond = getBondAt(mol, pt);
        if (atom != -1) {
            ok = mol.addRing((float) pt.getX(), (float) pt.getY(), ringSize, aromatic);
            model.setSelectedBond(-1);
        } else if (bond != -1) {
            ok = mol.addRing((float) pt.getX(), (float) pt.getY(), ringSize, aromatic);
            model.setSelectedAtom(-1);
        } else {
            ok = mol.addRing((float) pt.getX(), (float) pt.getY(), ringSize, aromatic);
            if (model.isReaction())
                model.needsLayout(true);
        }
    } else {
        mol = new StereoMolecule();
        ok = mol.addRing((float) pt.getX(), (float) pt.getY(), ringSize, aromatic);
        model.setValue(mol, true);
    }
    if (ok)
        mol.ensureHelperArrays(Molecule.cHelperNeighbours);
    return ok;
}
Also used : Point2D(java.awt.geom.Point2D) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 7 with StereoMolecule

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

the class AtomHighlightAction method paint.

@Override
public boolean paint(IDrawContext _ctx) {
    boolean ok = false;
    int theAtom = model.getSelectedAtom();
    StereoMolecule mol = model.getMolecule();
    if (mol != null) {
        if (theAtom != -1) {
            drawAtomHighlight(_ctx, mol, theAtom);
            ok = true;
        }
    }
    return ok;
}
Also used : StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 8 with StereoMolecule

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

the class AtomHighlightAction method showAtomQFDialog.

private boolean showAtomQFDialog(int atom) {
    GeomFactory factory = model.getGeomFactory();
    StereoMolecule mol = model.getMolecule();
    if (mol != null) {
        IAtomQueryFeaturesDialog dlg = factory.createAtomQueryFeatureDialog(/*new AtomQueryFeaturesDialog*/
        mol, atom);
        return dlg.doModalAt(lastHightlightPoint.getX(), lastHightlightPoint.getY()) == DialogResult.IDOK;
    }
    return false;
}
Also used : IAtomQueryFeaturesDialog(com.actelion.research.share.gui.editor.dialogs.IAtomQueryFeaturesDialog) GeomFactory(com.actelion.research.share.gui.editor.geom.GeomFactory) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 9 with StereoMolecule

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

the class AtomMapAction method paint.

// private void assistedMap(int atom)
// {
// StereoMolecule mol = model.getSelectedMolecule();
// int freeMapNo = model.getNextMapNo();
// if (mol != null) {
// StereoMolecule source = model.getFragmentAt(firstPoint, false);
// StereoMolecule target = model.getFragmentAt(lastPoint, false);
// if (target != null && target != source) {
// int dest = mol.findAtom((int) lastPoint.getX(), (int) lastPoint.getY());
// if (dest != -1) {
// mol.setAtomMapNo(atom, freeMapNo, false);
// mol.setAtomMapNo(dest, freeMapNo, false);
// }
// model.tryAutoMapReaction();
// }
// }
// }
// 
@Override
public boolean paint(IDrawContext ctx) {
    boolean ok = false;
    ctx.save();
    if (model.isReaction()) {
        StereoMolecule mol = model.getMolecule();
        if (firstPoint != null && lastPoint != null) {
            StereoMolecule source = model.getFragmentAt(firstPoint, false);
            StereoMolecule target = model.getFragmentAt(lastPoint, false);
            if (target != null && target != source) {
                int theAtom = mol.findAtom((float) lastPoint.getX(), (float) lastPoint.getY());
                if (theAtom != -1)
                    drawAtomHighlight(ctx, mol, theAtom);
            }
            // ctx.setStroke(IColor.RED);
            GeomFactory builder = model.getGeomFactory();
            ctx.setStroke(builder.getMapToolColor());
            ctx.drawLine(firstPoint.getX(), firstPoint.getY(), lastPoint.getX(), lastPoint.getY());
        } else if (secondAtom != -1) {
            drawAtomHighlight(ctx, mol, secondAtom);
        }
    }
    ok = super.paint(ctx);
    ctx.restore();
    return ok;
}
Also used : GeomFactory(com.actelion.research.share.gui.editor.geom.GeomFactory) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 10 with StereoMolecule

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

the class BondBaseAction method onMouseUp.

public boolean onMouseUp(IMouseEvent evt) {
    boolean ok = true;
    java.awt.geom.Point2D pt = new Point2D.Double(evt.getX(), evt.getY());
    model.pushUndo();
    int sourceAtom = getAtomAt(origin);
    int selectedAtom = model.getSelectedAtom();
    model.setSelectedBond(-1);
    StereoMolecule mol = model.getMoleculeAt(origin, true);
    model.setSelectedAtom(sourceAtom);
    if (!dragging) {
        if (mol != null && sourceAtom != -1) {
            if (mol.getAllConnAtoms(sourceAtom) != Model.MAX_CONNATOMS) {
                java.awt.geom.Point2D targetPoint = suggestNewX2AndY2(sourceAtom);
                int stopAtom = mol.findAtom((float) targetPoint.getX(), (float) targetPoint.getY());
                if (stopAtom != -1) {
                    int bondType = getBondType();
                    if (bondType == Molecule.cBondTypeSingle)
                        bondType = mol.suggestBondType(sourceAtom, stopAtom);
                    mol.addOrChangeBond(sourceAtom, stopAtom, bondType);
                } else {
                    int targetAtom = mol.addAtom((float) targetPoint.getX(), (float) targetPoint.getY(), 0.0f);
                    onAddBond(sourceAtom, targetAtom);
                }
                ok = true;
            }
        } else if (mol != null) {
            int bond = getBondAt(mol, pt);
            if (bond != -1) {
                onChangeBond(bond);
            } else {
                sourceAtom = mol.addAtom((float) pt.getX(), (float) pt.getY());
                java.awt.geom.Point2D targetPoint = suggestNewX2AndY2(sourceAtom);
                int targetAtom = mol.addAtom((float) targetPoint.getX(), (float) targetPoint.getY(), 0.0f);
                onAddBond(sourceAtom, targetAtom);
            }
            ok = true;
        } else {
            mol = model.getMolecule();
            sourceAtom = mol.addAtom((float) evt.getX(), (float) evt.getY());
            java.awt.geom.Point2D p = suggestNewX2AndY2(sourceAtom);
            int t = mol.addAtom((float) p.getX(), /*+ mol.getAverageBondLength()*/
            (float) p.getY());
            onAddBond(sourceAtom, t);
            // This creates a new Fragment, so make sure scheme gets layouted (if in RXN mode)
            if (model.isReaction())
                model.needsLayout(true);
            ok = true;
        }
    } else {
        // dragging
        if (mol != null) {
            if (sourceAtom != -1) {
                int targetAtom = selectedAtom;
                if (targetAtom == -1) {
                    double dx = origin.getX() - pt.getX();
                    double dy = origin.getY() - pt.getY();
                    java.awt.geom.Point2D targetPoint = pt;
                    if (dx * dx + dy * dy < Model.MIN_BOND_LENGTH_SQUARE) {
                        targetPoint = suggestNewX2AndY2(sourceAtom);
                    }
                    targetAtom = mol.addAtom((float) targetPoint.getX(), (float) targetPoint.getY(), 0.0f);
                }
                StereoMolecule tm = model.getMoleculeAt(pt, true);
                if (mol == tm) {
                    onAddBond(sourceAtom, targetAtom);
                } else if (tm != null) {
                    mol.addMolecule(tm);
                    targetAtom = mol.findAtom((float) pt.getX(), (float) pt.getY());
                    model.deleteMolecule(tm);
                    onAddBond(sourceAtom, targetAtom);
                }
                ok = true;
            } else {
                // mol == null
                int startAtom = mol.addAtom((float) origin.getX(), (float) origin.getY());
                int endAtom = mol.addAtom((float) pt.getX(), (float) pt.getY());
                onAddBond(startAtom, endAtom);
                if (model.isReaction())
                    model.needsLayout(true);
                ok = true;
            }
        } else {
            mol = model.getMolecule();
            int startAtom = mol.addAtom((float) origin.getX(), (float) origin.getY());
            int endAtom = mol.addAtom((float) pt.getX(), (float) pt.getY());
            onAddBond(startAtom, endAtom);
            ok = true;
        }
    }
    dragging = false;
    return ok;
}
Also used : Point2D(java.awt.geom.Point2D) Point2D(java.awt.geom.Point2D) 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