示例#1
0
    def constructModel(self, elm, pos, dispMode):
        """
        This is to try to repeat what 'make_Atom_and_bondpoints()' method does,
        but hope to remove some stuff not needed here.
        The main purpose is to build the geometry model for element display.

        @param elm: An object of class Elem
        @param elm: L{Elem}

        @param dispMode: the display mode of the atom
        @type  dispMode: int

        @return: the Chunk which contains the geometry model.
        @rtype: L{Chunk}
        """
        assy = Assembly(None, run_updaters=False)
        assy.set_glpane(self)  # sets .o and .glpane
        mol = Chunk(assy, 'dummy')
        atm = Atom(elm.symbol, pos, mol)
        atm.display = dispMode
        ## bruce 050510 comment: this is approximately how you should change the atom type (e.g. to sp2) for this new atom:
        if self.hybrid_type_name:
            atm.set_atomtype_but_dont_revise_singlets(self.hybrid_type_name)
        ## see also atm.element.atomtypes -> a list of available atomtype objects for that element
        ## (which can be passed to set_atomtype_but_dont_revise_singlets)
        atm.make_bondpoints_when_no_bonds()

        self.elementMode = True
        return mol
示例#2
0
    def constructModel(self, elm, pos, dispMode):
        """
        This is to try to repeat what 'make_Atom_and_bondpoints()' method does,
        but hope to remove some stuff not needed here.
        The main purpose is to build the geometry model for element display. 

        @param elm: An object of class Elem
        @param elm: L{Elem}
        
        @param dispMode: the display mode of the atom
        @type  dispMode: int
        
        @return: the Chunk which contains the geometry model.
        @rtype: L{Chunk}
        """
        assy = Assembly(None, run_updaters = False)
        assy.set_glpane(self) # sets .o and .glpane
        mol = Chunk(assy, 'dummy') 
        atm = Atom(elm.symbol, pos, mol)
        atm.display = dispMode
        ## bruce 050510 comment: this is approximately how you should change the atom type (e.g. to sp2) for this new atom:
        if self.hybrid_type_name:
            atm.set_atomtype_but_dont_revise_singlets(self.hybrid_type_name)
        ## see also atm.element.atomtypes -> a list of available atomtype objects for that element
        ## (which can be passed to set_atomtype_but_dont_revise_singlets)
        atm.make_bondpoints_when_no_bonds()
        
        self.elementMode = True
        return mol
示例#3
0
class PM_PartLib(PM_GroupBox):
    """
    The PM_PartLib class provides a groupbox containing a partlib directory
    The selected part in this list is shown by its elementViewer 
    (an instance of L{PM_PreviewGroupBox})
    The part being previewed can then be deposited into the 3D workspace.
    """
    def __init__(self, 
                 parentWidget,
                 title = 'Part Library',
                 win   = None,
                 elementViewer = None
                 ):            
        self.w = win
        self.elementViewer = elementViewer
        # piotr 080410 changed diTUBES to diTrueCPK
        self.elementViewer.setDisplay(diTrueCPK)
        self.partLib = None
        self.newModel = None

        PM_GroupBox.__init__(self, parentWidget, title)

        self._loadPartLibGroupBox()

    def connect_or_disconnect_signals(self, isConnect):         
        """
        Connect or disconnect widget signals sent to their slot methods.
        @param isConnect: If True the widget will send the signals to the slot 
                          method. 
        @type  isConnect: boolean
        """
        ##if isConnect:
        ##    change_connect = self.w.connect
        ##else:
        ##    change_connect = self.w.disconnect

        #Following doesn't work for some reasons so this call is disabled. 
        #Instead , see PM_TreeView.mouseReleaseEvent where self.partChanged is 
        #called. 
        ##change_connect(self.partLib, 
        ##               SIGNAL("selectionChanged(QItemSelection *,\
        ##               QItemSelection *)"),
        ##               self.partChanged)
        pass


    def _loadPartLibGroupBox(self):
        """
        """
        self.partLib = PM_TreeView(self)                    
        self.gridLayout.addWidget(self.partLib)
        #Append to the widget list. This is important for expand -collapse 
        #functions (of the groupbox) to work properly.
        self._widgetList.append(self.partLib)

    def _updateElementViewer(self, newModel = None):
        """
        Update the view of L{self.elementViewer}
        @param newModel: The model correseponding to the item selected 
                         in L{self.clipboardListWidget}. 
        @type  newModel: L{molecule} or L{Group}
        """
        if not self.elementViewer:
            return  

        assert isinstance(self.elementViewer, MMKitView)  

        self.elementViewer.resetView()             
        if newModel:
            self.elementViewer.updateModel(newModel)

    def partChanged(self, selectedItem):
        """
        Method called when user changed the partlib browser tree.

        @param selectedItem: Item currently selected in the L{self.partLib}
        @type  selectedItem: L{self.partLib.FileItem} 

        @attention: This is called in the L{PM_TreeView.mouseReleaseEvent}. The 
        'selectionChanged' signal for self.partLib apparently was not emitted
        so that code has been removed.                        
        """    
        #Copying some old code from deprecated MMKit.py -- ninad 2007-09-06
        item = selectedItem
        self.newModel = None
        if isinstance(item, self.partLib.FileItem):
            mmpFile = str(item.getFileObj())
            if os.path.isfile(mmpFile):
                self.newModel = \
                    Assembly(self.w, 
                             os.path.normpath(mmpFile),
                             run_updaters = True # desirable for PartLib [bruce 080403]
                         )
                self.newModel.set_glpane(self.elementViewer) # sets its .o and .glpane
                readmmp(self.newModel, mmpFile)
                self.newModel.update_parts() #k not sure if needed after readmmp
                self.newModel.checkparts()
                if self.newModel.shelf.members:
                    for m in self.newModel.shelf.members[:]:
                        m.kill() #k guess about a correct way to handle them
                    self.newModel.update_parts() #k probably not needed
                    self.newModel.checkparts() #k probably not needed

        self._updateElementViewer(self.newModel)
示例#4
0
class PM_PartLib(PM_GroupBox):
    """
    The PM_PartLib class provides a groupbox containing a partlib directory
    The selected part in this list is shown by its elementViewer
    (an instance of L{PM_PreviewGroupBox})
    The part being previewed can then be deposited into the 3D workspace.
    """
    def __init__(self,
                 parentWidget,
                 title='Part Library',
                 win=None,
                 elementViewer=None):
        self.w = win
        self.elementViewer = elementViewer
        # piotr 080410 changed diTUBES to diTrueCPK
        self.elementViewer.setDisplay(diTrueCPK)
        self.partLib = None
        self.newModel = None

        PM_GroupBox.__init__(self, parentWidget, title)

        self._loadPartLibGroupBox()

    def connect_or_disconnect_signals(self, isConnect):
        """
        Connect or disconnect widget signals sent to their slot methods.
        @param isConnect: If True the widget will send the signals to the slot
                          method.
        @type  isConnect: boolean
        """
        ##if isConnect:
        ##    change_connect = self.w.connect
        ##else:
        ##    change_connect = self.w.disconnect

        #Following doesn't work for some reasons so this call is disabled.
        #Instead , see PM_TreeView.mouseReleaseEvent where self.partChanged is
        #called.
        ##change_connect(self.partLib,
        ##               SIGNAL("selectionChanged(QItemSelection *,\
        ##               QItemSelection *)"),
        ##               self.partChanged)
        pass

    def _loadPartLibGroupBox(self):
        """
        """
        self.partLib = PM_TreeView(self)
        self.gridLayout.addWidget(self.partLib)
        #Append to the widget list. This is important for expand -collapse
        #functions (of the groupbox) to work properly.
        self._widgetList.append(self.partLib)

    def _updateElementViewer(self, newModel=None):
        """
        Update the view of L{self.elementViewer}
        @param newModel: The model correseponding to the item selected
                         in L{self.clipboardListWidget}.
        @type  newModel: L{molecule} or L{Group}
        """
        if not self.elementViewer:
            return

        assert isinstance(self.elementViewer, MMKitView)

        self.elementViewer.resetView()
        if newModel:
            self.elementViewer.updateModel(newModel)

    def partChanged(self, selectedItem):
        """
        Method called when user changed the partlib browser tree.

        @param selectedItem: Item currently selected in the L{self.partLib}
        @type  selectedItem: L{self.partLib.FileItem}

        @attention: This is called in the L{PM_TreeView.mouseReleaseEvent}. The
        'selectionChanged' signal for self.partLib apparently was not emitted
        so that code has been removed.
        """
        #Copying some old code from deprecated MMKit.py -- ninad 2007-09-06
        item = selectedItem
        self.newModel = None
        if isinstance(item, self.partLib.FileItem):
            mmpFile = str(item.getFileObj())
            if os.path.isfile(mmpFile):
                self.newModel = \
                    Assembly(self.w,
                             os.path.normpath(mmpFile),
                             run_updaters = True # desirable for PartLib [bruce 080403]
                         )
                self.newModel.set_glpane(
                    self.elementViewer)  # sets its .o and .glpane
                readmmp(self.newModel, mmpFile)
                self.newModel.update_parts(
                )  #k not sure if needed after readmmp
                self.newModel.checkparts()
                if self.newModel.shelf.members:
                    for m in self.newModel.shelf.members[:]:
                        m.kill()  #k guess about a correct way to handle them
                    self.newModel.update_parts()  #k probably not needed
                    self.newModel.checkparts()  #k probably not needed

        self._updateElementViewer(self.newModel)