use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.
the class AtomHighlightAction method handleCharacter.
private boolean handleCharacter(IKeyEvent evt) {
int theAtom = model.getSelectedAtom();
StereoMolecule mol = model.getMolecule();
StringBuilder keyStrokeBuffer = model.getKeyStrokeBuffer();
if (mol == null) {
return false;
}
int newRadical;
String code = evt.getText();
if (theAtom != -1) /*&& !evt.isShiftDown()*/
{
char c = code != null && code.length() > 0 ? code.charAt(0) : 0;
boolean isFirst = (keyStrokeBuffer.length() == 0);
if (isFirst) {
switch(c) {
case '+':
case '-':
return mol.changeAtomCharge(theAtom, c == '+');
case '.':
newRadical = (mol.getAtomRadical(theAtom) == Molecule.cAtomRadicalStateD) ? 0 : Molecule.cAtomRadicalStateD;
mol.setAtomRadical(theAtom, newRadical);
return true;
case ':':
newRadical = (mol.getAtomRadical(theAtom) == Molecule.cAtomRadicalStateT) ? Molecule.cAtomRadicalStateS : (mol.getAtomRadical(theAtom) == Molecule.cAtomRadicalStateS) ? 0 : Molecule.cAtomRadicalStateT;
mol.setAtomRadical(theAtom, newRadical);
return true;
case 'q':
return mol.isFragment() ? showAtomQFDialog(theAtom) : false;
case '?':
return mol.changeAtom(theAtom, 0, 0, -1, 0);
default:
break;
}
}
return handleCharacter(mol, theAtom, evt);
} else {
return handleCharsNonSelected(code);
}
}
use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.
the class AtomHighlightAction method expandAtomKeyStrokes.
private void expandAtomKeyStrokes(StereoMolecule mol, int highliteAtom, String keyStrokes) {
int atomicNo = Molecule.getAtomicNoFromLabel(keyStrokes);
if (atomicNo != 0) {
if (mol.changeAtom(highliteAtom, atomicNo, 0, -1, 0)) {
model.changed();
return;
}
}
StereoMolecule substituent = NamedSubstituents.getSubstituent(keyStrokes);
if (substituent != null) {
// Copy the the fragment containing the attachment point into a new molecule.
// Then attach the substituent, create new atom coordinates for the substituent,
// while retaining coordinates of the fragment.
StereoMolecule fragment = new StereoMolecule();
fragment.addFragment(mol, highliteAtom, null);
double sourceAVBL = fragment.getAverageBondLength();
int firstAtomInFragment = fragment.getAllAtoms();
for (int atom = 0; atom < fragment.getAllAtoms(); atom++) {
fragment.setAtomMarker(atom, true);
}
fragment.addSubstituent(substituent, 0);
new CoordinateInventor(CoordinateInventor.MODE_KEEP_MARKED_ATOM_COORDS).invent(fragment);
double dx = mol.getAtomX(highliteAtom) - sourceAVBL * fragment.getAtomX(0);
double dy = mol.getAtomY(highliteAtom) - sourceAVBL * fragment.getAtomY(0);
// Attach the substituent to the complete molecule and take coodinates from the
// previously created fragment-substituent species.
int firstAtomInMol = mol.getAllAtoms();
mol.addSubstituent(substituent, highliteAtom);
int substituentAtoms = mol.getAllAtoms() - firstAtomInMol;
for (int i = 0; i < substituentAtoms; i++) {
mol.setAtomX(firstAtomInMol + i, sourceAVBL * fragment.getAtomX(firstAtomInFragment + i) + dx);
mol.setAtomY(firstAtomInMol + i, sourceAVBL * fragment.getAtomY(firstAtomInFragment + i) + dy);
}
mol.setStereoBondsFromParity();
model.changed();
}
}
use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.
the class AtomHighlightAction method onKeyPressed.
@Override
public boolean onKeyPressed(IKeyEvent evt) {
GeomFactory factory = model.getGeomFactory();
if (evt.getCode().equals(factory.getDeleteKey())) {
int theAtom = model.getSelectedAtom();
StereoMolecule mol = model.getMolecule();
if (theAtom != -1) {
mol.deleteAtom(theAtom);
setHighlightAtom(mol, -1);
return true;
} else {
boolean update = false;
StereoMolecule m = model.getMolecule();
if (m.deleteSelectedAtoms()) {
update = true;
}
return update;
}
} else if (handleCharacter(evt)) {
return true;
}
return false;
}
use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.
the class AtomMapAction method onKeyPressed.
// @Override
// public boolean onMouseDown(ACTMouseEvent evt)
// {
// origin = new Point2D.Double(evt.getX(),evt.getY());
// return super.onMouseDown(evt);
// }
@Override
public boolean onKeyPressed(IKeyEvent evt) {
GeomFactory builder = model.getGeomFactory();
if (evt.getCode().equals(builder.getDeleteKey())) {
StereoMolecule mMol = model.getMolecule();
boolean found = false;
for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
if (mMol.getAtomMapNo(atom) != 0) {
mMol.setAtomMapNo(atom, 0, false);
found = true;
}
}
return found;
}
return super.onKeyPressed(evt);
}
use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.
the class AtomMapAction method onMouseMove.
@Override
public boolean onMouseMove(IMouseEvent evt, boolean drag) {
firstPoint = lastPoint = null;
if (model.isReaction()) {
StereoMolecule mol = model.getMolecule();
if (!drag) {
java.awt.geom.Point2D pt = new Point2D.Double(evt.getX(), evt.getY());
secondAtom = -1;
if (trackHighLight(pt)) {
int mCurrentHiliteAtom = model.getSelectedAtom();
if (mCurrentHiliteAtom != -1) {
int mapNo = mol.getAtomMapNo(mCurrentHiliteAtom);
if (mapNo != 0) {
for (int atom = 0; atom < mol.getAtoms(); atom++) {
if (atom != mCurrentHiliteAtom && mol.getAtomMapNo(atom) == mapNo) {
secondAtom = atom;
break;
}
}
}
}
return true;
}
} else {
int atom = model.getSelectedAtom();
if (mol != null && atom != -1) {
java.awt.geom.Point2D pt = new Point2D.Double(evt.getX(), evt.getY());
firstPoint = new Point2D.Double(mol.getAtomX(atom), mol.getAtomY(atom));
lastPoint = pt;
return true;
}
}
}
return false;
}
Aggregations