def _anotherDraw(self, layerColor): """ The original way of selecting cookies, but do it layer by layer, so we can control how to display each layer. """ if self.havelist: glCallList(self.displist.dl) return glNewList(self.displist.dl, GL_COMPILE_AND_EXECUTE) for layer in self.layeredCurves.keys(): bbox = self.layeredCurves[layer][0] curves = self.layeredCurves[layer][1:] if not curves: continue color = layerColor[layer] for c in curves: c.draw() try: bblo, bbhi = bbox.data[1], bbox.data[0] allCells = genDiam(bblo - 1.6, bbhi + 1.6, self.latticeType) for cell in allCells: for pp in cell: p1 = p2 = None if self.isin(pp[0], curves): if self.isin(pp[1], curves): p1 = pp[0] p2 = pp[1] else: p1 = pp[0] p2 = ((pp[1] + pp[0]) / 2, ) elif self.isin(pp[1], curves): p1 = pp[1] p2 = ((pp[1] + pp[0]) / 2, ) if p1 and p2: self._cellDraw(color, p1, p2) except: # bruce 041028 -- protect against exceptions while making display # list, or OpenGL will be left in an unusable state (due to the lack # of a matching glEndList) in which any subsequent glNewList is an # invalid operation. (Also done in chem.py; see more comments there.) print_compact_traceback( "bug: exception in shape.draw's displist; ignored: ") glEndList() self.havelist = 1 # return
def _anotherDraw(self, layerColor): """ The original way of selecting cookies, but do it layer by layer, so we can control how to display each layer. """ if self.havelist: glCallList(self.displist.dl) return glNewList(self.displist.dl, GL_COMPILE_AND_EXECUTE) for layer in self.layeredCurves.keys(): bbox = self.layeredCurves[layer][0] curves = self.layeredCurves[layer][1:] if not curves: continue color = layerColor[layer] for c in curves: c.draw() try: bblo, bbhi = bbox.data[1], bbox.data[0] allCells = genDiam(bblo - 1.6, bbhi + 1.6, self.latticeType) for cell in allCells: for pp in cell: p1 = p2 = None if self.isin(pp[0], curves): if self.isin(pp[1], curves): p1 = pp[0] p2 = pp[1] else: p1 = pp[0] p2 = ((pp[1] + pp[0]) / 2,) elif self.isin(pp[1], curves): p1 = pp[1] p2 = ((pp[1] + pp[0]) / 2,) if p1 and p2: self._cellDraw(color, p1, p2) except: # bruce 041028 -- protect against exceptions while making display # list, or OpenGL will be left in an unusable state (due to the lack # of a matching glEndList) in which any subsequent glNewList is an # invalid operation. (Also done in chem.py; see more comments there.) print_compact_traceback("bug: exception in shape.draw's displist; ignored: ") glEndList() self.havelist = 1 # return
def _cutCookie(self, layer, c): """ For each user defined curve, cut the crystal for it, store carbon postion into a global dictionary, store the bond information into each layer. """ self.havelist = 0 bblo, bbhi = c.bbox.data[1], c.bbox.data[0] # Without +(-) 1.6, crystal for lonsdaileite may not be right allCells = genDiam(bblo - 1.6, bbhi + 1.6, self.latticeType) if self.carbonPosDict.has_key(layer): carbons = self.carbonPosDict[layer] else: carbons = {} if self.hedroPosDict.has_key(layer): hedrons = self.hedroPosDict[layer] else: hedrons = {} if c.selSense == SUBTRACT_FROM_SELECTION: markedAtoms = self.markedAtoms if not self.bondLayers or not self.bondLayers.has_key(layer): return else: bonds = self.bondLayers[layer] for cell in allCells: for pp in cell: ppInside = [False, False] for ii in range(2): if c.isin(pp[ii]): ppInside[ii] = True if ppInside[0] or ppInside[1]: self._logic0Bond(carbons, bonds, markedAtoms, hedrons, ppInside, pp) self._removeMarkedAtoms(bonds, markedAtoms, carbons, hedrons) elif c.selSense == OUTSIDE_SUBTRACT_FROM_SELECTION: # & This differs from the standard selection scheme for Shift + Drag. mark 060211. # & This is marked for removal. mark 060320. if not self.bondLayers or not self.bondLayers.has_key(layer): return bonds = self.bondLayers[layer] newBonds = {} newCarbons = {} newHedrons = {} insideAtoms = {} newStorage = (newBonds, newCarbons, newHedrons) for cell in allCells: for pp in cell: pph = [None, None] for ii in range(2): if c.isin(pp[ii]): pph[ii] = self._hashAtomPos(pp[ii]) if bonds.has_key(pph[ii]): insideAtoms[pph[ii]] = pp[ii] if (not pph[0]) and pph[1] and carbons.has_key(pph[1]): pph[0] = self._hashAtomPos(pp[0]) if bonds.has_key(pph[0]): newCarbons[pph[1]] = pp[1] newHedrons[pph[0]] = pp[0] if not newBonds.has_key(pph[0]): newBonds[pph[0]] = [(pph[1], 1)] else: newBonds[pph[0]] += [(pph[1], 1)] if insideAtoms: self._logic2Bond(carbons, bonds, hedrons, insideAtoms, newStorage) bonds, carbons, hedrons = newStorage elif c.selSense == ADD_TO_SELECTION: if self.bondLayers.has_key(layer): bonds = self.bondLayers[layer] else: bonds = {} for cell in allCells: for pp in cell: pph = [None, None] ppInside = [False, False] for ii in range(2): pph[ii] = self._hashAtomPos(pp[ii]) if c.isin(pp[ii]): ppInside[ii] = True if ppInside[0] or ppInside[1]: self._logic1Bond(carbons, hedrons, bonds, pp, pph, ppInside) elif c.selSense == START_NEW_SELECTION: # Added to make crystal cutter selection behavior # consistent when no modkeys pressed. mark 060320. carbons = {} bonds = {} hedrons = {} for cell in allCells: for pp in cell: pph = [None, None] ppInside = [False, False] for ii in range(2): pph[ii] = self._hashAtomPos(pp[ii]) if c.isin(pp[ii]): ppInside[ii] = True if ppInside[0] or ppInside[1]: self._logic1Bond(carbons, hedrons, bonds, pp, pph, ppInside) self.bondLayers[layer] = bonds self.carbonPosDict[layer] = carbons self.hedroPosDict[layer] = hedrons # print "bonds", bonds self.havelist = 1 return
def _cutCookie(self, layer, c): """ For each user defined curve, cut the crystal for it, store carbon postion into a global dictionary, store the bond information into each layer. """ self.havelist = 0 bblo, bbhi = c.bbox.data[1], c.bbox.data[0] #Without +(-) 1.6, crystal for lonsdaileite may not be right allCells = genDiam(bblo - 1.6, bbhi + 1.6, self.latticeType) if self.carbonPosDict.has_key(layer): carbons = self.carbonPosDict[layer] else: carbons = {} if self.hedroPosDict.has_key(layer): hedrons = self.hedroPosDict[layer] else: hedrons = {} if c.selSense == SUBTRACT_FROM_SELECTION: markedAtoms = self.markedAtoms if not self.bondLayers or not self.bondLayers.has_key(layer): return else: bonds = self.bondLayers[layer] for cell in allCells: for pp in cell: ppInside = [False, False] for ii in range(2): if c.isin(pp[ii]): ppInside[ii] = True if ppInside[0] or ppInside[1]: self._logic0Bond(carbons, bonds, markedAtoms, hedrons, ppInside, pp) self. _removeMarkedAtoms(bonds, markedAtoms, carbons, hedrons) elif c.selSense == OUTSIDE_SUBTRACT_FROM_SELECTION: #& This differs from the standard selection scheme for Shift + Drag. mark 060211. #& This is marked for removal. mark 060320. if not self.bondLayers or not self.bondLayers.has_key(layer): return bonds = self.bondLayers[layer] newBonds = {}; newCarbons = {}; newHedrons = {}; insideAtoms = {} newStorage = (newBonds, newCarbons, newHedrons) for cell in allCells: for pp in cell: pph = [None, None] for ii in range(2): if c.isin(pp[ii]): pph[ii] = self._hashAtomPos(pp[ii]) if bonds.has_key(pph[ii]): insideAtoms[pph[ii]] = pp[ii] if (not pph[0]) and pph[1] and carbons.has_key(pph[1]): pph[0] = self._hashAtomPos(pp[0]) if bonds.has_key(pph[0]): newCarbons[pph[1]] = pp[1] newHedrons[pph[0]] = pp[0] if not newBonds.has_key(pph[0]): newBonds[pph[0]] = [(pph[1], 1)] else: newBonds[pph[0]] += [(pph[1], 1)] if insideAtoms: self._logic2Bond(carbons, bonds, hedrons, insideAtoms, newStorage) bonds, carbons, hedrons = newStorage elif c.selSense == ADD_TO_SELECTION: if self.bondLayers.has_key(layer): bonds = self.bondLayers[layer] else: bonds = {} for cell in allCells: for pp in cell: pph=[None, None] ppInside = [False, False] for ii in range(2): pph[ii] = self._hashAtomPos(pp[ii]) if c.isin(pp[ii]): ppInside[ii] = True if ppInside[0] or ppInside[1]: self._logic1Bond(carbons, hedrons, bonds, pp, pph, ppInside) elif c.selSense == START_NEW_SELECTION: # Added to make crystal cutter selection behavior # consistent when no modkeys pressed. mark 060320. carbons = {} bonds = {} hedrons = {} for cell in allCells: for pp in cell: pph = [None, None] ppInside = [False, False] for ii in range(2): pph[ii] = self._hashAtomPos(pp[ii]) if c.isin(pp[ii]): ppInside[ii] = True if ppInside[0] or ppInside[1]: self._logic1Bond(carbons, hedrons, bonds, pp, pph, ppInside) self.bondLayers[layer] = bonds self.carbonPosDict[layer] = carbons self.hedroPosDict[layer] = hedrons #print "bonds", bonds self.havelist = 1 return