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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations