void CResiduePane::SetGridCtrlText()
{
	CSTLArrayPDBRenderer & arrayPDBRenderer = m_pProteinVistaRenderer->m_arrayPDBRenderer;
	if ( arrayPDBRenderer.size() == 0 )
		return;

	long vertIndex = 0;
	for ( int iPDB = 0; iPDB < arrayPDBRenderer.size() ; iPDB++ )
	{
		CPDBInst * pPDBInst = arrayPDBRenderer[iPDB]->GetPDBInst();

		for ( int iModel = 0 ; iModel < pPDBInst->m_arrayModelInst.size() ; iModel ++ )
		{
			CModelInst * pModelInst = pPDBInst->m_arrayModelInst[iModel];

			long nChain = pModelInst->m_arrayChainInst.size();
			for ( int iChain = 0 ; iChain < nChain ; iChain ++ )
			{
				CChainInst * pChainInst = pPDBInst->GetChainInst(iModel ,iChain);

				CGridCellBase * pCell = m_residueGridCtrl->GetCell(vertIndex, 0 );
				if ( pCell != NULL )
				{
					if ( pPDBInst->m_arrayModelInst.size() == 1 )
					{
						pCell->SetText(pChainInst->GetChain()->m_strPDBID);
					}
					else
					{
						CString strChain;
						strChain.Format("[%d]%s", iModel, pChainInst->GetChain()->m_strPDBID);
						pCell->SetText(strChain);
					}
					pCell->SetData((LPARAM)(pChainInst));
				}

				for ( int j = 0 ; j < pChainInst->m_arrayResidueInst.size() ; j++ )
				{
					CGridCellBase * pCell = m_residueGridCtrl->GetCell(vertIndex, j+1);
					if ( pCell != NULL )
					{
						BOOL selectColor = 30;
						 

						long ss = pChainInst->m_arrayResidueInst[j]->GetResidue()->GetSS();
						if ( ss == SS_NONE )
							pCell->SetBackClr(RGB(min(180+selectColor,255), min(180+selectColor,255) , min(180+selectColor,255) ));
						else if ( ss == SS_HELIX )
							pCell->SetBackClr(RGB(min(180+selectColor,255), min(selectColor,255), min(selectColor,255) ));
						else if ( ss == SS_SHEET )
							pCell->SetBackClr(RGB(min(selectColor,255) ,min (180+selectColor, 255) ,min(selectColor,255) ));

						CString strText;
						CResidueInst * pResidueInst = pChainInst->m_arrayResidueInst[j];
						if ( m_displayStyle == 0 )
							strText.Format("%s" , pResidueInst->GetResidue()->m_residueNameOneChar);
						if ( m_displayStyle == 1 )
							strText.Format("%d %s" , pResidueInst->GetResidue()->GetResidueNum(), pResidueInst->GetResidue()->m_residueNameOneChar );
						if ( m_displayStyle == 2 )
							strText.Format("%d(%d) %s" , pResidueInst->GetResidue()->GetResidueNum(), j, pResidueInst->GetResidue()->m_residueNameOneChar );
						if ( m_displayStyle == 3 )
							strText.Format("%s" , pResidueInst->GetResidue()->GetResidueName() );
						if ( m_displayStyle == 4 )
							strText.Format("%d %s" , pResidueInst->GetResidue()->GetResidueNum(), pResidueInst->GetResidue()->GetResidueName() );
						if ( m_displayStyle == 5 )
							strText.Format("%d(%d) %s" , pResidueInst->GetResidue()->GetResidueNum(), j, pResidueInst->GetResidue()->GetResidueName() );
						pCell->SetText(strText);
						pCell->SetData((LPARAM)(pResidueInst));
					}
				}
				vertIndex ++;
			}
		}
	}
}