void CGridAnalysis::UpdateGrid( COARfile *pFile, COARsampleSort *pSort, int nLabelType, int nLabelTypeName, const wxDateTime *pHistory, wxDC *pDC) { nwxGridBatch xBatch(this); wxDC *pDCuse = (pDC != NULL) ? pDC : GetDC(); DCholder xx(this,pDCuse); wxString sChannel; wxString sCell; int iRow; int nCol; int nReviewCount; int nAcceptCount; int nReviewNeeded; int nAcceptNeeded; size_t nRowCount = pSort->GetCount(); size_t nAlleleColCount = pFile->GetLocusCount(); size_t i; COARlocus *pLocus; COARsample *pSample; const COARmessages *pMsgs = pFile->GetMessages(); GRID_FLAG flagBase; GRID_FLAG flag; bool bAlert; bool bEdited; bool bSampleHasAlert; bool bSampleEdited; bool bNeedsAttention; bool bSampleDisabled; m_nLabelSize = 0; m_nLabelType = nLabelTypeName; #if 0 // moved to next loop // Set up row labels for(iRow = 0; iRow < (int)nRowCount; ++iRow) { pSample = pSort->GetSample((size_t)iRow); sName = pSample->GetName(); if(pSample->IsSampleLevelEdited(pFile->GetMessages(),pHistory)) { sName.Append(COARsample::g_sCellChannelEdited); } SetRowLabel(iRow,sName); } #endif // set up cells pFile->GetReviewerCounts(&nReviewNeeded,&nAcceptNeeded,CLabReview::REVIEW_SAMPLE); for(iRow = 0; iRow < (int)nRowCount; ++iRow) { // setup sample info flagBase = GRID_NORMAL; bNeedsAttention = false; pSample = pSort->GetSample((size_t)iRow); bSampleHasAlert = pSample->HasAnyAlerts(pMsgs,pHistory); bSampleEdited = pSample->IsEdited(pMsgs,pHistory); bSampleDisabled = pSample->IsDisabled(pHistory); const COARsampleReviewAccept &accept(pSample->GetAcceptance()); const COARsampleReviewAccept &review(pSample->GetReviews()); if(bSampleDisabled) { flagBase |= GRID_DISABLED; } else { if(bSampleHasAlert) { flagBase |= GRID_ALERT_SAMPLE; } if(bSampleEdited) { flagBase |= GRID_EDITED_SAMPLE; } } // Setup Row Label for sample bEdited = pSample->IsSampleLevelEdited(pMsgs,pHistory); bAlert = pSample->HasSampleAlert(pMsgs,pHistory); nAcceptCount = accept.GetSampleCount(pHistory); nReviewCount = review.GetSampleCount(pHistory); _SetupCellFlag( flagBase, bSampleDisabled,bEdited,bAlert, nAcceptCount, nAcceptNeeded, nReviewCount, nReviewNeeded, &flag,&bNeedsAttention); SetupRowLabel(pSample,iRow,nLabelTypeName,bEdited,bNeedsAttention); // ILS alert column bAlert = bSampleHasAlert && pSample->HasILSAlert(pMsgs,pHistory); bEdited = pSample->IsCellILSEdited(pMsgs,pHistory); nAcceptCount = accept.GetILSCount(pHistory); nReviewCount = review.GetILSCount(pHistory); pFile->GetReviewerCounts(&nReviewNeeded,&nAcceptNeeded,CLabReview::REVIEW_ILS); _SetupCellFlag( flagBase, bSampleDisabled,bEdited,bAlert, nAcceptCount, nAcceptNeeded, nReviewCount, nReviewNeeded, &flag,&bNeedsAttention); SetCellValue(iRow,CFrameAnalysis::ILS_COLUMN,pSample->GetCellILS(pMsgs,pHistory)); SetCellStyle( iRow,CFrameAnalysis::ILS_COLUMN,flag); // channel alert column sChannel = pSample->GetCellChannel(pMsgs,pHistory); bAlert = bSampleHasAlert && COARsample::HasChannelAlert(sChannel); bEdited = bSampleEdited && pSample->IsCellChannelEdited(pMsgs,pHistory); nAcceptCount = accept.GetChannelCount(pHistory); nReviewCount = review.GetChannelCount(pHistory); pFile->GetReviewerCounts(&nReviewNeeded,&nAcceptNeeded,CLabReview::REVIEW_CHANNEL); _SetupCellFlag( flagBase, bSampleDisabled,bEdited,bAlert, nAcceptCount, nAcceptNeeded, nReviewCount, nReviewNeeded, &flag,&bNeedsAttention); SetCellValue(iRow,CFrameAnalysis::CHANNEL_ALERT_COLUMN,sChannel); SetCellStyle(iRow,CFrameAnalysis::CHANNEL_ALERT_COLUMN,flag); SetReadOnly(iRow,CFrameAnalysis::ILS_COLUMN,true); SetReadOnly(iRow,CFrameAnalysis::CHANNEL_ALERT_COLUMN,true); SetReadOnly(iRow,CFrameAnalysis::STATUS_COLUMN,true); pFile->GetReviewerCounts(&nReviewNeeded,&nAcceptNeeded,CLabReview::REVIEW_LOCUS); for(i = 0, nCol = CFrameAnalysis::FIRST_LOCUS_COLUMN; i < nAlleleColCount; ++i, ++nCol) { SetReadOnly(iRow,nCol,true); pLocus = pSample->FindLocus(pFile->GetLocusName(i)); if(pLocus != NULL) { sCell = pLocus->GetCell(nLabelType,pHistory); bAlert = bSampleHasAlert && pLocus->HasAlerts(pMsgs,pHistory); const COARchannel *pChannel = pFile->GetChannelFromLocus(pLocus->GetName()); int nChannel = pChannel->GetChannelNr(); nAcceptCount = pLocus->GetAcceptanceCount(pHistory); nReviewCount = pLocus->GetReviewCount(pHistory); bEdited = pLocus->HasBeenEdited( pMsgs,pSample,nChannel,pHistory); _SetupCellFlag(flagBase, bSampleDisabled,bEdited,bAlert, nAcceptCount,nAcceptNeeded, nReviewCount,nReviewNeeded, &flag,&bNeedsAttention); if(sCell.IsEmpty()) { if(bAlert) { sCell = _T("?"); } else if(bEdited) { sCell = COARsample::g_sCellChannelEdited; } } SetCellValue(iRow,nCol,sCell); SetCellStyle(iRow,nCol,flag); } else { SetCellValue(iRow,nCol,wxEmptyString); SetCellStyle(iRow,nCol,flagBase); } } // setup control cell SetReadOnly(iRow,nCol,true); SetCellValue(iRow,nCol,pSample->GetPositiveControl()); SetCellStyle(iRow,nCol,flagBase); // setup status cell SetReadOnly(iRow,CFrameAnalysis::STATUS_COLUMN,true); if(bSampleDisabled) { SetCellValue(iRow,CFrameAnalysis::STATUS_COLUMN,_T("")); SetCellStyle(iRow,CFrameAnalysis::STATUS_COLUMN,flagBase); } else { CParmOsirisGlobal parm; const wxColour &clFg(parm->GetStatusForeground(bNeedsAttention)); const wxColour &clBg(parm->GetStatusBackground(bNeedsAttention)); const wxString &s( bNeedsAttention ? g_sStatusNeedsAttention : g_sStatusOK); SetCellValue(iRow,CFrameAnalysis::STATUS_COLUMN,s); SetCellFont(iRow,CFrameAnalysis::STATUS_COLUMN,g_fontStatus); SetCellBackgroundColour(iRow,CFrameAnalysis::STATUS_COLUMN,clBg); SetCellTextColour(iRow,CFrameAnalysis::STATUS_COLUMN,clFg); SetCellAlignment( iRow,CFrameAnalysis::STATUS_COLUMN, wxALIGN_CENTRE,wxALIGN_CENTRE); SetCellAlignment( iRow,CFrameAnalysis::ILS_COLUMN, wxALIGN_CENTRE,wxALIGN_CENTRE); } } AutoSize(); UpdateLabelSize(); }
bool CGridCMF::TransferDataFromGrid( const wxString &sDefaultSpecimen, COARsample2CMFSpecimen *pMap, vector<wxString> *pMsgs) { wxString s; wxString sMsg; size_t nRows = m_vpSample.size(); size_t i; COARsample *pSample; nwxXmlCMFSpecimen *pCMFSpecimen; bool bRtn = true; bool bExclude; for(i = 0; i < nRows; i++) { bExclude = GetBoolValue((int)i,EXCLUDE); pSample = m_vpSample.at(i); pCMFSpecimen = pMap->Find(pSample); if(pCMFSpecimen == NULL) { if(!bExclude) { bRtn = false; s = GetCellValue((int)i,SAMPLE); if(s.IsEmpty()) { s = pSample->GetName(); } sMsg = "Internal error:\nCannot find specimen, "; sMsg.Append(s); sMsg.Append(", in CMF file"); pMsgs->push_back(sMsg); } } else if(bExclude) { pCMFSpecimen->SetExclude(true); } else { pCMFSpecimen->SetExclude(false); s = GetCellValue((int)i,SAMPLE); if( (!s.IsEmpty()) && (s != pSample->GetName()) ) { pCMFSpecimen->SetSpecimenID(s); } s = GetCellValue((int)i,SPECIMEN_TYPE); if(s.IsEmpty() || !s.Cmp(DEFAULT)) { s = sDefaultSpecimen; } pCMFSpecimen->SetSpecimenCategory(s); s = GetCellValue((int)i,SOURCE_ID); if(!s.IsEmpty()) { pCMFSpecimen->SetSourceID(s); } s = GetCellValue((int)i,CASE_ID); if(!s.IsEmpty()) { pCMFSpecimen->SetCaseID(s); } s = GetCellValue((int)i,COMMENT); if(!s.IsEmpty()) { pCMFSpecimen->SetSpecimenComment(s); } pCMFSpecimen->SetPartial(GetBoolValue((int)i,PARTIAL)); } } return bRtn; }
CGridCMF::CGridCMF( CDialogCMF *parent, wxWindowID id, COARfile *pFile, COARsampleSort *pSort) : _CGridEdit(parent,id,false), m_pParent(parent), m_pFile(pFile), m_pSort(pSort) { wxString s; vector<int> vnSample; COARsample *pSample; size_t n = m_pFile->GetSampleCount(); size_t i; int j = 0; m_vpSample.reserve(n); vnSample.reserve(n); // a little overkill because of ladders and controls for(i = 0; i < n; i++) { j++; pSample = m_pSort->GetSample(i); if(pSample->IsSampleType() && !pSample->IsDisabled()) { m_vpSample.push_back(pSample); vnSample.push_back(j); } } n = m_vpSample.size(); if(!n) { CreateGrid(1,1); SetCellValue(0,0,"There are no samples"); SetReadOnly(0,0,true); AutoSize(); } else { int ii; CreateGrid((int)n, (int)COLUMN_COUNT); SetRowLabelAlignment(wxALIGN_LEFT,wxALIGN_CENTRE); for(i = 0; i < n; i++) { ii = (int)i; pSample = m_vpSample.at(i); s = CGridAnalysis::FormatRowLabel( vnSample.at(i), (int)n, pSample->GetName()); SetRowLabelValue((int)i,s); SetBoolCell(ii,EXCLUDE); SetBoolCell(ii,PARTIAL); SetCellEditor(ii,SPECIMEN_TYPE,_CreateTypeEditor()); SetReadOnly(ii,EMPTY_LOCI,true); } for(i = 0; i < (size_t) COLUMN_COUNT; i++) { s = COL_LABELS[i]; SetColLabelValue((int)i,s); } SetColLabelAlignment(wxALIGN_LEFT,wxALIGN_CENTRE); } }
bool CGridCMF::TransferDataToGrid() { size_t n = m_vpSample.size(); bool bRtn = (n > 0); if(bRtn) { // loop through samples const CLabSettings &lab(m_pFile->GetLabSettings()); wxString sName; wxString sCat; COARsample *pSample; const CLabNameStrings *pNameStr; size_t i; for(i = 0; i < n; i++) { pSample = m_vpSample.at(i); // sample name and category sName = pSample->GetName(); pNameStr = lab.GetLabStrings(); if(pNameStr == NULL) { sCat = DEFAULT; } else { sCat = pNameStr->GetCategory(sName); if(sCat.IsEmpty()) { sCat = DEFAULT; } } // now set cell values SetBoolValue((int)i,EXCLUDE,false); SetCellValue((int)i,SPECIMEN_TYPE,sCat); SetCellValue((int)i,SAMPLE,pSample->GetName()); SetTextLength((int)i,SAMPLE,nwxXmlCMFSpecimen::LEN_SPECIMEN_ID); SetTextLength((int)i,SOURCE_ID,nwxXmlCMFSpecimen::LEN_SOURCE_ID); SetTextLength((int)i,CASE_ID,nwxXmlCMFSpecimen::LEN_CASE_ID); SetTextLength((int)i,COMMENT,nwxXmlCMFSpecimen::LEN_SPECIMEN_COMMENT); } UpdateEmptyLoci(); nwxGrid::UpdateLabelSizes(this); AutoSizeColumn(EXCLUDE); AutoSizeColumn(SAMPLE); AutoSizeColumn(PARTIAL); // compute size of SPECIMENT_TYPE columns int nWidth = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); const char *ps = CLabSpecimenCategory::LongestType(); wxClientDC dc(this); dc.SetFont(GetDefaultCellFont()); wxSize sz = dc.GetTextExtent(ps); if(!nWidth) { nWidth = 20; } nWidth += sz.GetWidth(); nWidth += 6; SetColSize(SPECIMEN_TYPE,nWidth); sz = dc.GetTextExtent( "This is sample text to determine the width of the comment column."); nWidth = sz.GetWidth(); nWidth += 2; SetColSize(COMMENT,nWidth); } return bRtn; }