Package org.openscience.cdk.interfaces

Examples of org.openscience.cdk.interfaces.IAtom


    public void undo() {
        Set<IAtom> keys = atomCoordsMap.keySet();
        Iterator<IAtom> it = keys.iterator();
        while (it.hasNext()) {
            IAtom atom = (IAtom) it.next();
            Point2d[] coords = atomCoordsMap.get(atom);
            atom.setPoint2d(coords[1]);
        }
    }
View Full Code Here


         *         by this action. Otherwise <code>null</code>.
         */
        protected IAtomContainer getSelectedAtomContainer(Point2d worldCoord) {
                JChemPaintRendererModel rModel =
                                                        chemModelRelay.getRenderer().getRenderer2DModel();
                IAtom atom = chemModelRelay.getClosestAtom(worldCoord);
                IBond bond = chemModelRelay.getClosestBond(worldCoord);

                IChemObjectSelection localSelection = rModel.getSelection();
                IChemObject chemObject = getHighlighted(worldCoord, atom, bond);

View Full Code Here

    public void mouseClickedDown(Point2d worldCoord) {
       
        IChemObject singleSelected = getHighlighted( worldCoord,
                                                     chemModelRelay.getClosestAtom(worldCoord) );
        IAtom closestAtom;
        if(singleSelected instanceof IAtom) {
            closestAtom = (IAtom) singleSelected;
        }else {
            setSelection( AbstractSelection.EMPTY_SELECTION );
            return;
        }


        String symbol = closestAtom.getSymbol();
        boolean changed = false;
        String[] elements =
            chemModelRelay.getController2DModel().getCommonElements();
        for (int i = 0; i < elements.length; i++) {
            if (elements[i].equals(symbol)) {
                if (i < elements.length - 2) {
                    chemModelRelay.setSymbol( closestAtom,elements[i + 1]);
                } else {
                    chemModelRelay.setSymbol( closestAtom, elements[0]);
                }
                changed = true;
                break;
            }
        }
        if (!changed)
            closestAtom.setSymbol("C");
        setSelection( new SingleSelection<IAtom>(closestAtom) );
        chemModelRelay.updateView();
    }
View Full Code Here

    public void redo() {
        Set<IAtom> keys = atomHydrogenCountsMap.keySet();
        Iterator<IAtom> it = keys.iterator();
        while (it.hasNext()) {
            IAtom atom = it.next();
            Integer[] counts = atomHydrogenCountsMap.get(atom);
            atom.setNotification(false);
            atom.setImplicitHydrogenCount(counts[0]);
            atom.setNotification(true);
        }
    }
View Full Code Here

    public void undo() {
        Set<IAtom> keys = atomHydrogenCountsMap.keySet();
        Iterator<IAtom> it = keys.iterator();
        while (it.hasNext()) {
            IAtom atom = (IAtom) it.next();
            Integer[] counts = atomHydrogenCountsMap.get(atom);
            atom.setImplicitHydrogenCount(counts[1]);
        }
    }
View Full Code Here

        // in case we are starting on an empty canvas
        if(bondLength==0|| Double.isNaN(bondLength))
            bondLength=1.5;
       
        start = new Point2d(worldCoord);
        IAtom closestAtom = chemModelRelay.getClosestAtom(worldCoord);
        IBond closestBond = chemModelRelay.getClosestBond( worldCoord );

        IChemObject singleSelection = getHighlighted( worldCoord,
                                                      closestAtom,
                                                      closestBond );

        if(singleSelection instanceof IAtom ) {
            source =  (IAtom) getHighlighted(worldCoord, closestAtom);

            if(source == null) {
                source = getBuilder().newInstance(IAtom.class, chemModelRelay.getController2DModel().getDrawElement(), start );
            }
            else {
                // Take the true (x,y) of the atom, not the click point
                // otherwise it's very hard to draw a regular ring
                start = closestAtom.getPoint2d();
            }

        }
    }
View Full Code Here

        double distance = start.distance(worldCoordTo);
        int numberofbonds = (int)(distance / (bondLength*.8660254)); // constant is sqrt(3)/4
        if(numberofbonds>0){
          //add start atom
          IAtomContainer phantoms = getBuilder().newInstance(IAtomContainer.class);
          IAtom startAtom;
          if(source==null){
            startAtom = getBuilder().newInstance(IAtom.class, chemModelRelay.getController2DModel().getDrawElement(), start );
          }else{
            startAtom=source;
          }  
          phantoms.addAtom(startAtom);
          //make atoms and bonds as needed
          for(int i=0;i<numberofbonds;i++){
            IAtom nextAtom = getBuilder().newInstance(IAtom.class, chemModelRelay.getController2DModel().getDrawElement(), new Point2d(startAtom.getPoint2d().x+bondLength, startAtom.getPoint2d().y));
            phantoms.addAtom(nextAtom);
            phantoms.addBond(getBuilder().newInstance(IBond.class, startAtom, nextAtom, IBond.Order.SINGLE));
            startAtom = nextAtom;
          }
         
          // The algorithm is 1. calc point a bondlength away in the mouse direction
          // 2. calc point rotating the above 30° down, then the same 30° up
          // 3. chain the points alternatively
            Point2d point = new Point2d(worldCoordTo);
            Point2d center = new Point2d(start);
            double dx = (point.x - center.x)/numberofbonds;
            double dy = (point.y - center.y)/numberofbonds;
            double angle = Math.PI / 6;
            double cosangle = Math.cos(angle);
            double sinangle = Math.sin(angle);
            double firstx = dx*cosangle - dy*sinangle;
            double firsty = dx*sinangle + dy*cosangle;
            double secx = dx*cosangle + dy*sinangle;
            double secy = -dx*sinangle + dy*cosangle;
        Point2d p1 = new Point2d(start);
        phantoms.getAtom(0).setPoint2d(p1);
        double currx = p1.x;
        double curry = p1.y;
            for(int i=1; i<phantoms.getAtomCount(); i++){
            Point2d p = new Point2d(currx,curry);
              if(i % 2 == 1){
                p.x += firstx;
                p.y += firsty;
              }else{
                p.x += secx;
                p.y += secy;
                }
              currx = p.x;
              curry = p.y;
            phantoms.getAtom(i).setPoint2d(p);
            }
            chemModelRelay.setPhantoms(phantoms);
            chemModelRelay.setPhantomText(""+phantoms.getAtomCount(), worldCoordTo);
            IAtom closestAtom = chemModelRelay.getClosestAtom(phantoms.getAtom(phantoms.getAtomCount()-1));
            chemModelRelay.getRenderer().getRenderer2DModel().getMerge().remove(merge);
            merge =  (IAtom) getHighlighted(phantoms.getAtom(phantoms.getAtomCount()-1).getPoint2d(), closestAtom);
            if(merge!=null){
              chemModelRelay.getRenderer().getRenderer2DModel().getMerge().put(merge,phantoms.getAtom(phantoms.getAtomCount()-1));
              chemModelRelay.getPhantoms().getConnectedBondsList(phantoms.getAtom(phantoms.getAtomCount()-1)).get(0).setAtom(merge,1);
View Full Code Here

          chemModelRelay.updateView();
      }
  }

  public void mouseMove(Point2d worldCoord) {
    IAtom atom = chemModelRelay.getClosestAtom(worldCoord);
    IBond bond = chemModelRelay.getClosestBond(worldCoord);
    JChemPaintRendererModel model =
        chemModelRelay.getRenderer().getRenderer2DModel();
   
    IChemObject obj = getHighlighted( worldCoord, atom,bond );
View Full Code Here

   
    /* (non-Javadoc)
     * @see org.openscience.cdk.controller.ControllerModuleAdapter#mouseClickedDouble(javax.vecmath.Point2d)
     */
    public void mouseClickedDouble(Point2d p){
        IAtom closestAtom = chemModelRelay.getClosestAtom(p);
        IBond closestBond = chemModelRelay.getClosestBond(p);
        IChemObject singleSelection = getHighlighted( p,
                closestAtom,
                closestBond );
        if(singleSelection!=null){
View Full Code Here

        bondLength = Renderer.calculateAverageBondLength( chemModelRelay.getIChemModel() );
        // in case we are starting on an empty canvas
        if(bondLength==0 || Double.isNaN(bondLength))
            bondLength=1.5;
        start = new Point2d(worldCoord);
        IAtom closestAtom = chemModelRelay.getClosestAtom(worldCoord);
        IBond closestBond = chemModelRelay.getClosestBond( worldCoord );

        IChemObject singleSelection = getHighlighted( worldCoord,
                                                      closestAtom,
                                                      closestBond );
View Full Code Here

TOP

Related Classes of org.openscience.cdk.interfaces.IAtom

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.