Esempio n. 1
0
  /** Undo actions */
  public void undo() {

    IRGroupQuery rgrpQ = rgrpHandler.getrGroupQuery();

    if (type.equals("setSubstitute") || type.equals("setRoot")) {
      this.redoRootAttachmentPoints = rgrpHandler.getrGroupQuery().getRootAttachmentPoints();
      for (Iterator<IAtom> atItr = existingAtomDistr.keySet().iterator(); atItr.hasNext(); ) {
        IAtom atom = atItr.next();
        existingAtomDistr.get(atom).addAtom(atom);
      }
      for (Iterator<IBond> bndItr = existingBondDistr.keySet().iterator(); bndItr.hasNext(); ) {
        IBond bond = bndItr.next();
        existingBondDistr.get(bond).addBond(bond);
      }
      hub.getChemModel().getMoleculeSet().removeAtomContainer(userSelection);

      if (type.equals("setRoot")) {
        if (isNewRgrp) {
          rgrpQ.setRootStructure(null);
          rgrpQ.setRootAttachmentPoints(null);
          for (IAtomContainer atc : hub.getIChemModel().getMoleculeSet().atomContainers()) {
            atc.removeProperty(CDKConstants.TITLE);
          }
          hub.unsetRGroupHandler();
        } else {
          existingRoot.setProperty(CDKConstants.TITLE, RGroup.ROOT_LABEL);
          rgrpQ.setRootStructure(existingRoot);
          rgrpQ.setRootAttachmentPoints(existingRootAttachmentPoints);
        }
      } else if (type.equals("setSubstitute")) {
        if (existingRgroupLists != null) {
          for (Iterator<Integer> rNums = existingRgroupLists.keySet().iterator();
              rNums.hasNext(); ) {
            int rNum = rNums.next();
            rgrpQ.getRGroupDefinitions().put(rNum, existingRgroupLists.get(rNum));
          }
        }
      }
    } else if (type.startsWith("setAtomApoAction")) {
      RGroup undoRGroup = existingRGroupApo.keySet().iterator().next();
      for (Iterator<Integer> rnumItr =
              hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().keySet().iterator();
          rnumItr.hasNext(); ) {
        for (RGroup rgrp :
            hub.getRGroupHandler()
                .getrGroupQuery()
                .getRGroupDefinitions()
                .get(rnumItr.next())
                .getRGroups()) {
          if (rgrp.equals(undoRGroup)) {
            IAtom apo1 = existingRGroupApo.get(undoRGroup).get(1);
            IAtom apo2 = existingRGroupApo.get(undoRGroup).get(2);
            rgrp.setFirstAttachmentPoint(apo1);
            rgrp.setSecondAttachmentPoint(apo2);
          }
        }
      }
    } else if (type.startsWith("setBondApoAction")) {
      for (Iterator<IAtom> atItr = existingRootAttachmentPoints.keySet().iterator();
          atItr.hasNext(); ) {
        IAtom rAtom = atItr.next();
        Map<Integer, IBond> undoApo = existingRootAttachmentPoints.get(rAtom);
        Map<Integer, IBond> apoBonds = rgrpQ.getRootAttachmentPoints().get(rAtom);

        redoRootAttachmentPoints = new HashMap<IAtom, Map<Integer, IBond>>();
        Map<Integer, IBond> redoApo = new HashMap<Integer, IBond>();
        if (apoBonds.get(1) != null) redoApo.put(1, apoBonds.get(1));
        if (apoBonds.get(2) != null) redoApo.put(2, apoBonds.get(2));
        redoRootAttachmentPoints.put(rAtom, redoApo);

        apoBonds.remove(1);
        apoBonds.remove(2);
        if (undoApo.get(1) != null) {
          apoBonds.put(1, undoApo.get(1));
        }
        if (undoApo.get(2) != null) {
          apoBonds.put(2, undoApo.get(2));
        }
      }
    } else if (type.equals("clearRgroup")) {
      hub.setRGroupHandler(rgrpHandler);
      rgrpQ.getRootStructure().setProperty(CDKConstants.TITLE, RGroup.ROOT_LABEL);
      for (Iterator<Integer> rnumItr =
              hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().keySet().iterator();
          rnumItr.hasNext(); ) {
        int rNum = rnumItr.next();
        for (RGroup rgrp :
            hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().get(rNum).getRGroups()) {
          rgrp.getGroup().setProperty(CDKConstants.TITLE, RGroup.makeLabel(rNum));
        }
      }
    }
  }
Esempio n. 2
0
File: Misc.java Progetto: egonw/cdkr
 public static void removeProperty(IAtomContainer molecule, String key) {
   molecule.removeProperty(key);
 }