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