Example #1
0
    def _find_and_set_hotSpotAtom_in_new_model(self, newModel):
        """
        If the model being viewed in the thumbView window already has a hotspot,
        set it as self.hotSpotAtom (which then will be used by client code)

        @see: self.updateModel
        @Note that , in self.leftDown, we can actually temporarily change the
        the hotspot for the partlib model. But then if you view another part and
        go back to this model, the hotspot will be reset to the one that already
        exists in the model (or None if one doesn't exist)
        """
        assert isinstance(newModel, Assembly)
        chunkList = []

        def func(node):
            if isinstance(node, Chunk):
                chunkList.append(node)

        newModel.part.topnode.apply2all(func)

        ok = False
        if len(chunkList) == 1:
            ok, hotspot_or_whynot = find_hotspot_for_pasting(chunkList[0])
        elif len(chunkList) > 1:
            for chunk in chunkList:
                ok, hotspot_or_whynot = find_hotspot_for_pasting(chunk)
                if ok:
                    break
        if ok:
            self.hotspotAtom = hotspot_or_whynot
            self.lastHotspotChunk = self.hotspotAtom.molecule
        else:
            self.hotspotAtom = None
            self.lastHotspotChunk = None
        return
Example #2
0
 def _find_and_set_hotSpotAtom_in_new_model(self, newModel):
     """
     If the model being viewed in the thumbView window already has a hotspot,
     set it as self.hotSpotAtom (which then will be used by client code) 
     
     @see: self.updateModel
     @Note that , in self.leftDown, we can actually temporarily change the 
     the hotspot for the partlib model. But then if you view another part and
     go back to this model, the hotspot will be reset to the one that already 
     exists in the model (or None if one doesn't exist)        
     """
     assert isinstance(newModel, Assembly)
     chunkList = []
     def func(node):
         if isinstance(node, Chunk):
             chunkList.append(node)                    
     newModel.part.topnode.apply2all(func)
              
     
     ok = False
     if len(chunkList) == 1:
         ok, hotspot_or_whynot = find_hotspot_for_pasting(chunkList[0])
     elif len(chunkList) > 1:
         for chunk in chunkList:
             ok, hotspot_or_whynot = find_hotspot_for_pasting(chunk)
             if ok:
                 break
     if ok:
         self.hotspotAtom = hotspot_or_whynot
         self.lastHotspotChunk = self.hotspotAtom.molecule
     else:
         self.hotspotAtom = None                
         self.lastHotspotChunk = None
     return
Example #3
0
    def pasteBond(self, sing):
        """
        If self.pastable has an unambiguous hotspot,
        paste a copy of self.pastable onto the given singlet;
        return (the copy, description) or (None, whynot)
        """
        self.update_pastable()
        pastable = self.pastable
        # as of 050316 addmol can change self.pastable! See comments in
        #pasteFree.
        # bruce 041123 added return values (and guessed docstring).
        # bruce 050121 using subr split out from this code
        ok, hotspot_or_whynot = find_hotspot_for_pasting(pastable)
        if not ok:
            whynot = hotspot_or_whynot
            return None, whynot

        hotspot = hotspot_or_whynot

        if isinstance(pastable, Chunk):
            numol = pastable.copy_single_chunk(None)
            #bruce 080314 use new name copy_single_chunk
            # bruce 041116 added (implicitly, by default) cauterize = 1
            # to mol.copy() above; change this to cauterize = 0 here if
            # unwanted, and for other uses of mol.copy in this file.
            # For this use, there's an issue that new singlets make it harder to
            # find a default hotspot! Hmm... I think copy should set one then.
            # So now it does [041123].
            hs = numol.hotspot or numol.singlets[0]  #e should use
            #find_hotspot_for_pasting again
            bond_at_singlets(hs, sing)  # this will move hs.molecule (numol) to
            #match
            # bruce 050217 comment: hs is now an invalid hotspot for numol,
            # and that used to cause bug 312, but this is now fixed in getattr
            # every time the
            # hotspot is retrieved (since it can become invalid in many other
            # ways too),so there's no need to explicitly forget it here.
            if self.pickit():
                numol.pickatoms()
                #bruce 060412 worries whether pickatoms is illegal or
                #ineffective (in both pasteBond and pasteFree)
                # given that numol.part is presumably not yet set (until after
                #addmol). But these seem to work
                # (assuming I'm testing them properly), so I'm not changing
                #this. [Why do they work?? ###@@@]
            self.o.assy.addmol(numol)  # do this last, in case it computes bbox
            return numol, "copy of %r" % pastable.name
        elif isinstance(pastable, Group):
            msg = "Pasting a group with hotspot onto a bond point " \
                  "is not implemented"
            return None, msg
Example #4
0
    def pasteBond(self, sing):
        """
        If self.pastable has an unambiguous hotspot,
        paste a copy of self.pastable onto the given singlet;
        return (the copy, description) or (None, whynot)
        """
        self.update_pastable()
        pastable = self.pastable
            # as of 050316 addmol can change self.pastable! See comments in 
            #pasteFree.
        # bruce 041123 added return values (and guessed docstring).
        # bruce 050121 using subr split out from this code
        ok, hotspot_or_whynot = find_hotspot_for_pasting(pastable)
        if not ok:
            whynot = hotspot_or_whynot
            return None, whynot

        hotspot = hotspot_or_whynot

        if isinstance(pastable, Chunk):
            numol = pastable.copy_single_chunk(None)
            #bruce 080314 use new name copy_single_chunk
            # bruce 041116 added (implicitly, by default) cauterize = 1
            # to mol.copy() above; change this to cauterize = 0 here if 
            # unwanted, and for other uses of mol.copy in this file.
            # For this use, there's an issue that new singlets make it harder to
            # find a default hotspot! Hmm... I think copy should set one then.
            # So now it does [041123].
            hs = numol.hotspot or numol.singlets[0] #e should use 
            #find_hotspot_for_pasting again
            bond_at_singlets(hs,sing) # this will move hs.molecule (numol) to 
            #match
            # bruce 050217 comment: hs is now an invalid hotspot for numol, 
            # and that used to cause bug 312, but this is now fixed in getattr 
            # every time the
            # hotspot is retrieved (since it can become invalid in many other
            # ways too),so there's no need to explicitly forget it here.
            if self.pickit():
                numol.pickatoms()
                #bruce 060412 worries whether pickatoms is illegal or 
                #ineffective (in both pasteBond and pasteFree)
                # given that numol.part is presumably not yet set (until after 
                #addmol). But these seem to work
                # (assuming I'm testing them properly), so I'm not changing 
                #this. [Why do they work?? ###@@@]
            self.o.assy.addmol(numol) # do this last, in case it computes bbox
            return numol, "copy of %r" % pastable.name
        elif isinstance(pastable, Group):
            msg = "Pasting a group with hotspot onto a bond point " \
                  "is not implemented"
            return None, msg