Ejemplo n.º 1
0
 public void setMolecule(Molecule molecule) {
   GeometryTools.translateAllPositive(molecule);
   GeometryTools.center(
       molecule, new Dimension(renderer.getCanvas().getWidth(), renderer.getCanvas().getHeight()));
   this.molecule = molecule;
   calcAverageBondLength();
   renderer.paintNewMolecule(molecule);
   //        renderer.getTransformer().dumpMatrix();
 }
Ejemplo n.º 2
0
 public void calcAverageBondLength() {
   double total = 0;
   for (int i = 0; i < molecule.countBonds(); i++) {
     Bond bond = molecule.getBond(i);
     total +=
         GeometryTools.calcDistance(
             new Point2D(bond.getSource().getX(), bond.getSource().getY()),
             new Point2D(bond.getTarget().getX(), bond.getTarget().getY()));
   }
   renderer.getRendererModel().setDefaultBondLength(total / molecule.countBonds());
 }
Ejemplo n.º 3
0
  public Atom getClosestAtom(Point2D graphCord) {
    Atom closestAtom = null;
    double closestDistance = Double.MAX_VALUE;

    for (int i = 0; i < molecule.countAtoms(); i++) {
      Atom currentAtom = molecule.getAtom(i);
      Point2D currentPointGraph =
          realCordToGraphCord(new Point2D(currentAtom.getX(), currentAtom.getY()));
      double distance = GeometryTools.calcDistance(graphCord, currentPointGraph);

      if (distance <= renderer.getRendererModel().getAtomRadius() && distance < closestDistance) {
        closestAtom = currentAtom;
        closestDistance = distance;
      }
    }
    return closestAtom;
  }
Ejemplo n.º 4
0
  public Bond getClosestBond(Point2D graphCord) {
    Bond closestBond = null;
    double closestDistance = Double.MAX_VALUE;
    for (int i = 0; i < molecule.countBonds(); i++) {
      Bond currentBond = molecule.getBond(i);
      Point2D currentCenterGraph =
          realCordToGraphCord(
              new Point2D(
                  (currentBond.getSource().getX() + currentBond.getTarget().getX()) / 2,
                  (currentBond.getSource().getY() + currentBond.getTarget().getY()) / 2));

      double distance = GeometryTools.calcDistance(graphCord, currentCenterGraph);

      if (distance <= renderer.getRendererModel().getAtomRadius() && distance < closestDistance) {
        closestBond = currentBond;
        closestDistance = distance;
      }
    }

    return closestBond;
  }
Ejemplo n.º 5
0
 public Point2D graphCordToRealCord(Point2D graphCord) {
   return renderer.getTransformer().inverseTransform(graphCord, null);
 }
Ejemplo n.º 6
0
 public Point2D realCordToGraphCord(Point2D realCord) {
   return renderer.getTransformer().transform(realCord, null);
 }
Ejemplo n.º 7
0
 public void zoomInOut(double factor) {
   renderer.getRendererModel().setZoomFactor(renderer.getRendererModel().getZoomFactor() * factor);
   renderer.paintNewMolecule(molecule);
 }
Ejemplo n.º 8
0
 public void refreshView() {
   renderer.paintMolecule(molecule);
 }