Exemplo n.º 1
0
 public RGroupEdit(
     String _type,
     boolean _isNewRgrp,
     IChemModelRelay _hub,
     RGroupHandler _rgrpHandler,
     Map<IAtom, IAtomContainer> _existingAtomDistr,
     Map<IBond, IAtomContainer> _existingBondDistr,
     IAtomContainer _existingRoot,
     Map<IAtom, Map<Integer, IBond>> _existingRootAttachmentPoints,
     Map<RGroup, Map<Integer, IAtom>> _existingRGroupApo,
     Map<Integer, RGroupList> _existingRgroupLists,
     IAtomContainer _userSelection) {
   this.type = _type;
   this.isNewRgrp = _isNewRgrp;
   this.hub = _hub;
   this.rgrpHandler = _rgrpHandler;
   this.existingRoot = _existingRoot;
   this.existingRootAttachmentPoints = _existingRootAttachmentPoints;
   this.existingRGroupApo = _existingRGroupApo;
   this.existingAtomDistr = _existingAtomDistr;
   this.existingBondDistr = _existingBondDistr;
   this.existingRgroupLists = _existingRgroupLists;
   this.redoRootStructure = rgrpHandler.getrGroupQuery().getRootStructure();
   this.userSelection = (IMolecule) _userSelection;
   if (_existingRgroupLists != null) {
     redoRgroupLists = new HashMap<Integer, RGroupList>();
     for (Iterator<Integer> itr =
             rgrpHandler.getrGroupQuery().getRGroupDefinitions().keySet().iterator();
         itr.hasNext(); ) {
       int rNum = itr.next();
       redoRgroupLists.put(rNum, rgrpHandler.getrGroupQuery().getRGroupDefinitions().get(rNum));
     }
   }
   if (existingRGroupApo != null) {
     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)) {
           redoRGroupApo = new HashMap<RGroup, Map<Integer, IAtom>>();
           HashMap<Integer, IAtom> map = new HashMap<Integer, IAtom>();
           map.put(1, rgrp.getFirstAttachmentPoint());
           map.put(2, rgrp.getSecondAttachmentPoint());
           redoRGroupApo.put(rgrp, map);
         }
       }
     }
   }
 }
Exemplo n.º 2
0
  /** Redo actions */
  public void redo() {

    if (type.equals("setRoot") || type.equals("setSubstitute")) {

      if (isNewRgrp) {
        hub.setRGroupHandler(rgrpHandler);
      }

      IRGroupQuery rgrpQ = rgrpHandler.getrGroupQuery();
      for (Iterator<IAtom> atItr = existingAtomDistr.keySet().iterator(); atItr.hasNext(); ) {
        IAtom atom = atItr.next();
        existingAtomDistr.get(atom).removeAtom(atom);
      }
      for (Iterator<IBond> bndItr = existingBondDistr.keySet().iterator(); bndItr.hasNext(); ) {
        IBond bond = bndItr.next();
        existingBondDistr.get(bond).removeBond(bond);
      }
      hub.getChemModel().getMoleculeSet().addAtomContainer(userSelection);

      if (type.equals("setRoot")) {
        rgrpQ.setRootStructure(redoRootStructure);
        rgrpQ.getRootStructure().setProperty(CDKConstants.TITLE, RGroup.ROOT_LABEL);
        rgrpQ.setRootAttachmentPoints(redoRootAttachmentPoints);
      } else if (type.equals("setSubstitute")) {
        if (redoRgroupLists != null) {
          for (Iterator<Integer> rNums = redoRgroupLists.keySet().iterator(); rNums.hasNext(); ) {
            int rNum = rNums.next();
            rgrpQ.getRGroupDefinitions().put(rNum, redoRgroupLists.get(rNum));
          }
        }
      }
    } else if (type.startsWith("setAtomApoAction")) {
      RGroup redoRGroup = redoRGroupApo.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(redoRGroup)) {
            IAtom apo1 = redoRGroupApo.get(redoRGroup).get(1);
            IAtom apo2 = redoRGroupApo.get(redoRGroup).get(2);
            rgrp.setFirstAttachmentPoint(apo1);
            rgrp.setSecondAttachmentPoint(apo2);
          }
        }
      }
    } else if (type.startsWith("setBondApoAction")) {
      for (Iterator<IAtom> atItr = redoRootAttachmentPoints.keySet().iterator();
          atItr.hasNext(); ) {
        IAtom rAtom = atItr.next();
        Map<Integer, IBond> apoBonds =
            hub.getRGroupHandler().getrGroupQuery().getRootAttachmentPoints().get(rAtom);

        apoBonds.remove(1);
        apoBonds.remove(2);
        Map<Integer, IBond> redoApo = redoRootAttachmentPoints.get(rAtom);

        if (redoApo.get(1) != null) {
          apoBonds.put(1, redoApo.get(1));
        }
        if (redoApo.get(2) != null) {
          apoBonds.put(2, redoApo.get(2));
        }
      }
    } else if (type.equals("clearRgroup")) {
      hub.unsetRGroupHandler();
    }
  }