Exemplo n.º 1
0
void CReportCtrl::RemoveEditOptions(CXTPReportRecordItem *pItem,DWORD_PTR dwData)
{
	CXTPReportRecordItemEditOptions *pEditOptions = pItem->GetEditOptions(NULL);
	ASSERT(pEditOptions != NULL);

	CXTPReportRecordItemConstraints *pConstraints = pEditOptions->GetConstraints();
	ASSERT(pConstraints != NULL);

	CXTPReportRecordItemConstraint *pConstraint = pEditOptions->FindConstraint(dwData);
	ASSERT (pConstraint != NULL);

	CDWordArray dwDatas;
	CStringArray strConstraints;

	for (int i=0; i<pConstraints->GetCount(); ++i)
	{
		CXTPReportRecordItemConstraint *pConstraint = pConstraints->GetAt(i);
		if (pConstraint->m_dwData != dwData)
		{
			dwDatas.Add(pConstraint->m_dwData);
			strConstraints.Add(pConstraint->m_strConstraint);
		}
	}

	pConstraints->RemoveAll();
	for (int i=0; i<dwDatas.GetCount(); ++i)
		pEditOptions->AddConstraint(strConstraints[i],dwDatas[i]);
}
Exemplo n.º 2
0
BOOL CALLBACK EnumMonitorProc(HMONITOR hMonitor, HDC hdc, LPRECT prc, LPARAM lParam)
{
    CDWordArray *parrHMonitor = (CDWordArray *)lParam;

	parrHMonitor->Add((DWORD)hMonitor);

    return TRUE;
}
int CTDLFindResultsListCtrl::GetResultIDs(const CFilteredToDoCtrl* pTDC, CDWordArray& aTaskIDs) const
{
	CFTDResultsArray aResults;
	int nNumRes = GetResults(pTDC, aResults);

	for (int nRes = 0; nRes < nNumRes; nRes++)
		aTaskIDs.Add(aResults[nRes].dwTaskID);

	return aResults.GetSize();
}
bool CAcceleratorManager::Write()
{
	CDWordArray AccelsDatasArray;
	CDWordArray CmdDatasArray;

	int         iCount = 0;
	CCmdAccelOb*pCmdAccel;
	CAccelsOb*  pAccel;
	DWORD       dwAccelData;

	WORD     wKey;
	POSITION pos = m_mapAccelTable.GetStartPosition();
	while (pos != NULL)
	{
		m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
		CmdDatasArray.RemoveAll();

		POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
		while (pos != NULL)
		{
			pAccel = pCmdAccel->m_Accels.GetNext(pos);
			//      if (!pAccel->m_bLocked) {
			dwAccelData = pAccel->GetData();
			CmdDatasArray.Add(dwAccelData);
			//      }
		}

		if (CmdDatasArray.GetSize() > 0)
		{
			CmdDatasArray.InsertAt(0, MAKELONG(pCmdAccel->m_wIDCommand, CmdDatasArray.GetSize()));

			AccelsDatasArray.Append(CmdDatasArray);
			iCount++;
		}
	}
	//  AccelsDatasArray.InsertAt(0, MAKELONG(65535, iCount));

	int    count = AccelsDatasArray.GetSize();
	DWORD *data  = (DWORD *)malloc(count * sizeof(DWORD));
	ASSERT(data != NULL);

	for (int index = 0; index < count; index++)
		data[index] = AccelsDatasArray[index];

	regSetBinaryValue("keyboard", (char *)data, count*sizeof(DWORD));

	AccelsDatasArray.RemoveAll();
	CmdDatasArray.RemoveAll();

	free(data);

	return true;
}
Exemplo n.º 5
0
// When starting a mouse-key select, the anchor point, and all contiguous 
// selections that are not in the path of the current item can remain 
// selected.  All other selections are tossed, like Exploder does.
void CMultiSelTreeCtrl::DoKeyedDeselect( BOOL scrollingDown )
{
	CDWordArray keepSet;
	HTREEITEM currentItem= m_AnchorItem;
	
	// Record the contiguous selection's we're keeping
	keepSet.Add( (DWORD) m_AnchorItem );
	while(1)
	{
		if( scrollingDown )
			currentItem= GetPrevSiblingItem( currentItem);
		else
			currentItem= GetNextSiblingItem( currentItem);

		if( currentItem == NULL || !IsSelected( currentItem ) )
			break;

		keepSet.Add( (DWORD) currentItem );
	}

	// Unselect everything
	//
	int i;
	for( i= m_SelectionSet.GetSize()-1; i >= 0; i-- )
	{
		currentItem= (HTREEITEM) m_SelectionSet.GetAt(i);	
		// Undo any display atts
		SetItemState(currentItem, 0, TVIS_CUT | TVIS_BOLD | TVIS_SELECTED);
	}

	// Then select everything in the keepset
	//
	m_SelectionSet.RemoveAll();
	for( i= keepSet.GetSize()-1; i>=0; i-- )
		SetSelectState( (HTREEITEM) keepSet.GetAt(i), TRUE );

	m_PendingKeyedDeselect= FALSE;
	ShowNbrSelected();
}
Exemplo n.º 6
0
BOOL CTDCTaskListCtrl::SelectItem(int nItem)
{
	m_lcTasks.SetSelectionMark(nItem);
	m_lcColumns.SetSelectionMark(nItem);
	
	// avoid unnecessary selections
	if ((GetSelectedCount() == 1) && (GetSelectedItem() == nItem))
		return TRUE;

	CDWordArray aTaskIDs;
	aTaskIDs.Add(GetTaskID(nItem));

	return SelectTasks(aTaskIDs);
}
Exemplo n.º 7
0
CDWordArray *CGhostTextBuffer::			/* virtual override */
CopyRevisionNumbers(int nStartLine, int nEndLine) const
{
	CDWordArray *paSavedRevisionNumbers = CCrystalTextBuffer::CopyRevisionNumbers(nStartLine, nEndLine);
	for (int nLine = nEndLine; nLine >= nStartLine; --nLine)
	{
		if ((GetLineFlags(nLine) & LF_GHOST) != 0)
			paSavedRevisionNumbers->RemoveAt(nLine - nStartLine);
	}
	if ((GetLineFlags(nEndLine) & LF_GHOST) != 0)
	{
		for (int nLine = nEndLine + 1; nLine < GetLineCount(); ++nLine)
			if ((GetLineFlags(nLine) & LF_GHOST) == 0)
			{
				paSavedRevisionNumbers->Add(GetLineFlags(nLine));
				break;
			}
	}
	return paSavedRevisionNumbers;
}
Exemplo n.º 8
0
void CCLLKDlg::StartNewGame(void)
{
	CTime t=CTime::GetCurrentTime();
	tGameTime=t;
	strTiShi1="系统时间:"+t.Format("%H:%M:%S");
	m_StatusBar.SetText(strTiShi1,2,0);
	strTiShi2.Format(" 该局时间:00:00:00");
	m_StatusBar.SetText(strTiShi2,1,0);
	strTiShi3.Format("当前游戏:%d行%d列%d种方块",m_nRow-2,m_nCol-2,m_Kind);
	m_StatusBar.SetText(strTiShi3,0,0);

	delete[] m_map;
	m_map=new int[m_nCol*m_nRow];
	for (int iNum=0;iNum<(m_nCol*m_nRow);iNum++)
	{
		m_map[iNum]=BLANK_STATE;
	}
	srand(time(NULL));
	CDWordArray tmpMap;

	for (int i=0;i<(m_nRow-2)*(m_nCol-2)/2;i++)
	{
		int x=rand()%m_Kind;
		tmpMap.Add(x);
		tmpMap.Add(x);

	}

	for (int i=1;i<(m_nCol-1);i++)
	{
		for (int j=1;j<(m_nRow-1);j++)
		{
			INT_PTR nIndex=(int(rand()*0.1+rand()*0.01+rand()))%tmpMap.GetSize();
			m_map[i+j*m_nCol]=tmpMap.GetAt(nIndex);
			tmpMap.RemoveAt(nIndex);

		}
	}
	Invalidate(false);
}
Exemplo n.º 9
0
void CHexEdit :: GetNumbers ( CDWordArray & cArray )
{
    // Get the array into shape.
    cArray.RemoveAll ( ) ;

    CString strRaw ;
    GetWindowText ( strRaw ) ;

    TCHAR * szBuff = (TCHAR*)new TCHAR[ strRaw.GetLength ( ) +
                                        1 * sizeof ( TCHAR )   ] ;

    _tcscpy ( szBuff , (LPCTSTR)strRaw ) ;

    // Use good ol' strtok to do the deed.
    TCHAR * pCurr = _tcstok ( szBuff , k_DELIMS ) ;
    while ( NULL != pCurr )
    {

        // Try and convert it to an value.  I'm taking the easy way out.
        DWORD dwAddr ;
        int iRet = _stscanf ( pCurr       ,
                              _T ( "%x" ) ,
                              &dwAddr       ) ;

        if ( 1 != iRet )
        {
            CString sMsg ;
            sMsg.FormatMessage ( IDS_LOADADDRBADCONVERSION ,
                                 pCurr                      ) ;
            AfxMessageBox ( sMsg ) ;
        }
        else
        {
            cArray.Add (  dwAddr ) ;
        }

        pCurr = _tcstok ( NULL , k_DELIMS ) ;
    }
    delete [] szBuff ;
}
Exemplo n.º 10
0
void CTDCTaskListCtrl::RestoreSelection(const TDCSELECTIONCACHE& cache)
{
	if (cache.aSelTaskIDs.GetSize() == 0)
	{
		DeselectAll();
		return;
	}

	DWORD dwFocusedTaskID = cache.dwFocusedTaskID;
	ASSERT(dwFocusedTaskID);
	
	if (FindTaskItem(dwFocusedTaskID) == -1)
	{
		dwFocusedTaskID = 0;
		int nID = cache.aBreadcrumbs.GetSize();
		
		while (nID--)
		{
			dwFocusedTaskID = cache.aBreadcrumbs[nID];
			
			if (FindTaskItem(dwFocusedTaskID) != -1)
				break;
			else
				dwFocusedTaskID = 0;
		}
	}
	
	// add focused task if it isn't already
	CDWordArray aTaskIDs;
	aTaskIDs.Copy(cache.aSelTaskIDs);

	if (Misc::FindT(aTaskIDs, dwFocusedTaskID) == -1)
		aTaskIDs.Add(dwFocusedTaskID);

	SetSelectedTasks(aTaskIDs, dwFocusedTaskID);
	
	// restore pos
	if (cache.dwFirstVisibleTaskID)
		SetTopIndex(FindTaskItem(cache.dwFirstVisibleTaskID));
}
Exemplo n.º 11
0
BOOL CWindowGroups::ArrangeWindows(CWnd *pParentWindow)
{
	int i;
	RECT rect = { 0, 0, 0, 0 };

	const DWORD dwYStep = static_cast<DWORD>(NewGUI_Scale(WG_Y_STEP, pParentWindow));

	CDWordArray aPos;
	aPos.RemoveAll();

	const DWORD dwXOffset = static_cast<DWORD>(NewGUI_Scale(WG_OFFSET_LEFT, pParentWindow));
	const DWORD dwYOffset = static_cast<DWORD>(NewGUI_Scale(WG_OFFSET_TOP, pParentWindow));
	for(i = 0; i < m_aWindows.GetSize(); i++) aPos.Add(dwYOffset);

	for(i = 0; i < m_aWindows.GetSize(); i++)
	{
		if((m_aFlags.GetAt(i) & WGF_REPOSITION) == 0) continue;

		CWnd *p = (CWnd *)m_aWindows.GetAt(i);

		if(p != NULL)
		{
			p->GetWindowRect(&rect);
			rect.right = rect.right - rect.left; // Coords to sizes
			rect.bottom = rect.bottom - rect.top;
		}
		rect.top = (LONG)aPos.GetAt((int)m_aGroupIDs.GetAt(i));
		rect.left = dwXOffset;

		if(p != NULL)
			p->MoveWindow(rect.left, rect.top, rect.right, rect.bottom, TRUE);

		aPos.SetAt((int)m_aGroupIDs.GetAt(i), (DWORD)rect.top + dwYStep);
	}

	aPos.RemoveAll();
	return TRUE;
}
Exemplo n.º 12
0
int
HoldemWinnerCalculator::GetBestHandCardValue(int nCard1, int nCard2, int nCard3, int nCard4, 
											int nTableCard1, int nTableCard2, int nTableCard3, int nTableCard4, int nTableCard5, 
											PokerHandCardsClass& cardsClass, CDWordArray& arrCardsIdx){

	UNUSED(nCard3);
	UNUSED(nCard4);

	if( nTableCard1 <= -1 || nTableCard2 <= -1 || nTableCard3 <= -1 ){
		cardsClass = PokerHandCardsClass::CardsClass_None;
		return PokerHandCardsClass::CardsClass_None;
		}

	int				arrCards[]			= {	GetCardValue(nTableCard1), GetCardValue(nTableCard2), 
											GetCardValue(nTableCard3), GetCardValue(nTableCard4), 
											GetCardValue(nTableCard5)};
	int				arrCardsReplaced[]	= {	arrCards[0], arrCards[1], arrCards[2], arrCards[3], arrCards[4]}; 
	int				arrWinnerCardsIdx[]	= {	4, 5, 6, 7, 8 }; // Copy best combinations card indexes.((0, 1, 2, 3) - identifies hand cards (4, 5, 6, 7, 8) = identifies table cards)


	int nHandCardVal1			= GetCardValue(nCard1);
	int nHandCardVal2			= GetCardValue(nCard2);
	int nBestHandCardsVal		= 0x7fffffff;
	int nBestHandCardsValTemp	= 0;

	// 3 table cards
	if( nTableCard4 <= -1 ){
		arrCardsReplaced[3]		= nHandCardVal1;
		arrCardsReplaced[4]		= nHandCardVal2;
		nBestHandCardsValTemp	= GetHandValue(arrCardsReplaced[0], arrCardsReplaced[1], arrCardsReplaced[2], arrCardsReplaced[3], arrCardsReplaced[4]);
		if( nBestHandCardsVal > nBestHandCardsValTemp ){
			nBestHandCardsVal = nBestHandCardsValTemp;

			arrWinnerCardsIdx[0] = 4; // table card 1 index
			arrWinnerCardsIdx[1] = 5; // table card 2 index
			arrWinnerCardsIdx[2] = 6; // table card 3 index
			arrWinnerCardsIdx[3] = 0; // hand card 1
			arrWinnerCardsIdx[4] = 1; // hand card 2
			}
		}
	else
	// 4 table cards.
	if( nTableCard5 <= -1 ){
		arrCardsReplaced[4]		= nHandCardVal1;
		nBestHandCardsValTemp	= GetHandValue(arrCardsReplaced[0], arrCardsReplaced[1], arrCardsReplaced[2], arrCardsReplaced[3], arrCardsReplaced[4]);
		if( nBestHandCardsVal > nBestHandCardsValTemp ){
			nBestHandCardsVal = nBestHandCardsValTemp;

			arrWinnerCardsIdx[0] = 4; // table card 1 index
			arrWinnerCardsIdx[1] = 5; // table card 2 index
			arrWinnerCardsIdx[2] = 6; // table card 3 index
			arrWinnerCardsIdx[3] = 7; // table card 4 index
			arrWinnerCardsIdx[4] = 0; // hand card 1
			}

		for( int j=0; j<4; j++ ){
			// Copy cards array.
			memcpy(arrCardsReplaced, arrCards, sizeof(arrCards));

			arrCardsReplaced[j] = nHandCardVal2;
			arrCardsReplaced[4] = nHandCardVal1;

			nBestHandCardsValTemp	= GetHandValue(arrCardsReplaced[0], arrCardsReplaced[1], arrCardsReplaced[2], arrCardsReplaced[3], arrCardsReplaced[4]);
			if( nBestHandCardsVal > nBestHandCardsValTemp ){
				nBestHandCardsVal = nBestHandCardsValTemp;

				arrWinnerCardsIdx[0] = 4; // table card 1 index
				arrWinnerCardsIdx[1] = 5; // table card 2 index
				arrWinnerCardsIdx[2] = 6; // table card 3 index
				arrWinnerCardsIdx[3] = 7; // table card 4 index
				arrWinnerCardsIdx[4] = 8; // table card 5 index

				arrWinnerCardsIdx[j] = 1; // hand card 2 index
				arrWinnerCardsIdx[4] = 0; // hand card 1 index
				}
			}

		memcpy(arrCardsReplaced, arrCards, sizeof(arrCards));
		arrCardsReplaced[4] = nHandCardVal2;

		nBestHandCardsValTemp	= GetHandValue(arrCardsReplaced[0], arrCardsReplaced[1], arrCardsReplaced[2], arrCardsReplaced[3], arrCardsReplaced[4]);
		if( nBestHandCardsVal > nBestHandCardsValTemp ){
			nBestHandCardsVal = nBestHandCardsValTemp;

			arrWinnerCardsIdx[0] = 4; // table card 1 index
			arrWinnerCardsIdx[1] = 5; // table card 2 index
			arrWinnerCardsIdx[2] = 6; // table card 3 index
			arrWinnerCardsIdx[3] = 7; // table card 4 index
			arrWinnerCardsIdx[4] = 1; // hand card 2 index
			}

		for( int j=0; j<4; j++ ){
			// Copy cards array.
			memcpy(arrCardsReplaced, arrCards, sizeof(arrCards));

			arrCardsReplaced[j] = nHandCardVal1;
			arrCardsReplaced[4] = nHandCardVal2;

			nBestHandCardsValTemp	= GetHandValue(arrCardsReplaced[0], arrCardsReplaced[1], arrCardsReplaced[2], arrCardsReplaced[3], arrCardsReplaced[4]);
			if( nBestHandCardsVal > nBestHandCardsValTemp ){
				nBestHandCardsVal = nBestHandCardsValTemp;

				arrWinnerCardsIdx[0] = 4; // table card 1 index
				arrWinnerCardsIdx[1] = 5; // table card 2 index
				arrWinnerCardsIdx[2] = 6; // table card 3 index
				arrWinnerCardsIdx[3] = 7; // table card 4 index
				arrWinnerCardsIdx[4] = 1; // hand card 2 index
				arrWinnerCardsIdx[j] = 0; // hand card 1 index
				}
			}
		}
	// 5 table cards.
	else{
		for( int j=0; j<5; j++ ){
			// Copy cards array.
			memcpy(arrCardsReplaced, arrCards, sizeof(arrCards));
			arrCardsReplaced[j] = nHandCardVal1;

			nBestHandCardsValTemp	= GetHandValue(arrCardsReplaced[0], arrCardsReplaced[1], arrCardsReplaced[2], arrCardsReplaced[3], arrCardsReplaced[4]);
			if( nBestHandCardsVal > nBestHandCardsValTemp ){
				nBestHandCardsVal = nBestHandCardsValTemp;

				arrWinnerCardsIdx[0] = 4; // table card 1 index
				arrWinnerCardsIdx[1] = 5; // table card 2 index
				arrWinnerCardsIdx[2] = 6; // table card 3 index
				arrWinnerCardsIdx[3] = 7; // table card 4 index
				arrWinnerCardsIdx[4] = 8; // table card 5 index

				arrWinnerCardsIdx[j] = 0; // hand card 1 index
				}
			}

		for( int j=0; j<5; j++ ){
			// Copy cards array.
			memcpy(arrCardsReplaced, arrCards, sizeof(arrCards));
			arrCardsReplaced[j] = nHandCardVal2;

			nBestHandCardsValTemp	= GetHandValue(arrCardsReplaced[0], arrCardsReplaced[1], arrCardsReplaced[2], arrCardsReplaced[3], arrCardsReplaced[4]);
			if( nBestHandCardsVal > nBestHandCardsValTemp ){
				nBestHandCardsVal = nBestHandCardsValTemp;

				arrWinnerCardsIdx[0] = 4; // table card 1 index
				arrWinnerCardsIdx[1] = 5; // table card 2 index
				arrWinnerCardsIdx[2] = 6; // table card 3 index
				arrWinnerCardsIdx[3] = 7; // table card 4 index
				arrWinnerCardsIdx[4] = 8; // table card 5 index
				arrWinnerCardsIdx[j] = 1; // hand card 2 index
				}
			}

		for( int j=0; j<5; j++ ){
			for( int k=j+1; k<5; k++ ){
				// Copy cards array.
				memcpy(arrCardsReplaced, arrCards, sizeof(arrCards));

				arrCardsReplaced[j] = nHandCardVal1;
				arrCardsReplaced[k] = nHandCardVal2;

				nBestHandCardsValTemp	= GetHandValue(arrCardsReplaced[0], arrCardsReplaced[1], arrCardsReplaced[2], arrCardsReplaced[3], arrCardsReplaced[4]);
				if( nBestHandCardsVal > nBestHandCardsValTemp ){
					nBestHandCardsVal = nBestHandCardsValTemp;

					arrWinnerCardsIdx[0] = 4; // table card 1 index
					arrWinnerCardsIdx[1] = 5; // table card 2 index
					arrWinnerCardsIdx[2] = 6; // table card 3 index
					arrWinnerCardsIdx[3] = 7; // table card 4 index
					arrWinnerCardsIdx[4] = 8; // table card 5 index

					arrWinnerCardsIdx[j] = 0; // hand card 1 index
					arrWinnerCardsIdx[k] = 1; // hand card 2 index
					}
				}
			}
		}

	_String sClassName;
	cardsClass = CardsHandClass(nBestHandCardsVal, &sClassName);
	if( cardsClass != PokerHandCardsClass::CardsClass_None ){
		arrCardsIdx.Add(arrWinnerCardsIdx[0]);
		arrCardsIdx.Add(arrWinnerCardsIdx[1]);
		arrCardsIdx.Add(arrWinnerCardsIdx[2]);
		arrCardsIdx.Add(arrWinnerCardsIdx[3]);
		arrCardsIdx.Add(arrWinnerCardsIdx[4]);
		}
	return nBestHandCardsVal;
	}
Exemplo n.º 13
0
CResult * CMarkovChain::OnCMarkovChain(CDataInterface *pDataInterface, string VO)
{
	CResult * pResult;
	pResult = new CResult("马尔可夫链");
	m_pResult = pResult;
	m_pDataInterface = pDataInterface;

	if (!GetValueFromVo(pDataInterface, VO))
	{
		CTString strWarning = "读取参数发生错误,请重新运行!";
		CRsltElementText * pWarningTextRslt = new CRsltElementText( "错误!" );
		pWarningTextRslt->AddString( strWarning );
		m_pResult->Add( pWarningTextRslt );
		return pResult;
	}
	
	CDWordArray indexary;
	CDoubleMatrix Data_Matrix;
	indexary.Add(m_nUserID);
	indexary.Add(m_nPath);
//	if (m_nTime > -1)
//		indexary.Add(m_nTime);

	m_nRow = pDataInterface->GetColsData(indexary, Data_Matrix, 0);//取回界面数据
//	if (m_nTime > -1)
//	{
//		CDoubleVector tempSort_vec = Data_Matrix(2);
//		CIntVector tempSort_id(m_nRow);
//		tempSort_vec.Sort(tempSort_id);
//		m_ID_vec.create(m_nRow);
//		m_Path_vec.create(m_nRow);
//		for (int j=0; j<m_nRow; j++)
//		{
//			m_ID_vec(j) = Data_Matrix(0, tempSort_id(j)-1);
//			m_Path_vec(j) = Data_Matrix(1, tempSort_id(j)-1);
//		}
//	}
//	else
	{
		m_ID_vec = Data_Matrix(0);
		m_Path_vec = Data_Matrix(1);
	}
	
	if (Main() )
	{
		DrawResult();
	}
	else
	{
		CTString strWarning = "数据无法计算,请重新运行!";
		CRsltElementText * pWarningTextRslt = new CRsltElementText( "错误!" );
		pWarningTextRslt->AddString( strWarning );
		m_pResult->Add( pWarningTextRslt );
		return pResult;
	}

//	if (m_bSaveModle)
//	{
//		...
//	}

	return pResult;
}
Exemplo n.º 14
0
CResult * CMarkovChain::OnMorkovChainPred(CDataInterface *pDataInterface, string VO)//外部调用预测函数
{
	m_pResult = new CResult("线性回归模型预测结果");
	m_pDataInterface = pDataInterface;
	if (!GetPredValueVo(pDataInterface, VO))//读参数及模型
	{
		CRsltElementText * pWarningTextRslt = new CRsltElementText( "错误!" );
		pWarningTextRslt->AddString( "模型参数有误,无法运行。" );
		m_pResult->Add( pWarningTextRslt );
		return m_pResult;
	}
//读取数据
	CDWordArray indexary;
	CDoubleMatrix Data_Matrix;
	indexary.Add(m_nUserID);
	indexary.Add(m_nPath);
	m_nRow = pDataInterface->GetColsData(indexary, Data_Matrix, 0);//取回界面数据
	m_ID_vec = Data_Matrix(0);
	m_Path_vec = Data_Matrix(1);
	CDoubleVector start_vec(m_nRow);
	CDoubleVector pairID_vec(m_nRow);
	CDoubleVector length_vec(m_nRow, 0);
	int i=0, L, id=0;
// 数据准备(Preprocessing) begin
//
	while (i < m_nRow) 
	{
		L=0;
		start_vec(id) = i;
		pairID_vec(id) = m_ID_vec(i);
		while (pairID_vec(id) == m_ID_vec(i)) 
		{
			length_vec(id)++;
			i++;
			if (i >= m_nRow) 
			{
				break;
			}
		}
		id++;
	}
	m_nTotalID = id;
    start_vec.resize(m_nTotalID);
	pairID_vec.resize(m_nTotalID);
	length_vec.resize(m_nTotalID);
//数据准备(Preprocessing) end

//开始计算
	int k, t;
	CDoubleMatrix responsibility(m_nTotalID, m_nCluster);
	for (i=0; i<m_nTotalID; i++)
	{
		L=length_vec(i);
		for (k=0; k<m_nCluster; k++)
		{
			double temp = 1;
			for (t=start_vec(i); t<start_vec(i)+L-1; t++)
			{
				temp *= m_Theta_Trans[k](m_Path_vec(t)-1,m_Path_vec(t+1)-1);
			}
			responsibility(i,k) = temp;
		}
	}
	for (i=0; i<m_nCluster; i++) // Normalization of the responsibilities
	{
		double s = 0;
		for (k=0; k<m_nCluster; k++)
		{
			s = s + responsibility(i,k);
		}
		for (k=0; k<m_nCluster; k++)
		{
			responsibility(i,k) = responsibility(i,k)/s;
		}
	}

	m_VecClus.create(m_nTotalID);
	for (i=0; i<m_nTotalID; i++)
	{
		int which = 0;
		for (k=0; k<m_nCluster; k++)
		{
			if (responsibility(i, which) > responsibility(i,k))
			{
				which = k;
			}
		}
		m_VecClus(i) = which;
	}
//完成计算
	DrawResult();
	return m_pResult;
}
Exemplo n.º 15
0
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, CDWordArray& avalue)
{
	HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC);
	CString value;

	if (pDX->m_bSaveAndValidate)
	{
		int nLen = ::GetWindowTextLength(hWndCtrl);
		::GetWindowText(hWndCtrl, value.GetBufferSetLength(nLen), nLen+1);
		value.ReleaseBuffer();

		//all this loop should be replaced by a regular expression search engine
		std::string svalue(value);

		int idata1,idata2=0;
		int index=0;
		WORD first,last;
		bool bFlag;

		do{

			bFlag=false;

			do{
				idata1=svalue.find_first_of("0123456789",idata2);
				first=svalue[idata1]-'0';

				if(idata1==std::string::npos){
					break;
				}

				idata1=svalue.find_first_of("-",idata1);

				if(idata1==std::string::npos){
					break;
				}

				idata1=svalue.find_first_of("0123456789",idata1);
				last=svalue[idata1]-'0';

				if(idata1==std::string::npos){
					break;
				}

				if(idata1-idata2>2){
					break;
				}

				avalue.Add(MAKELONG(first,last));

				idata2+=3;

				bFlag=true;

			}while(0);

			do{
				idata1=svalue.find_first_of("0123456789",idata2);
				first=svalue[idata1]-'0';

				if(idata1==std::string::npos){
					break;
				}

				idata1=svalue.find_first_of(",",idata1);

				if(idata1==std::string::npos){
					break;
				}

				if(idata1-idata2>1){
					break;
				}

				avalue.Add(MAKELONG(first,first));

				idata2+=2;

				bFlag=true;

			}while(0);

		}while(bFlag);
	}
	else
	{
		//AfxSetWindowText(hWndCtrl, value);
	}

}
Exemplo n.º 16
0
bool CHistogram::CalcHistogram()
{
	int i=0, j=0, k=0;
	int nIndex=0, nPtCnt=0, nGroupIndex=0;
	int nColIndex=0, nRowCount=0, nDataType=0;
	double fTmp=0;
	CDWordArray arrCol;
	CMapManager dataMap;
	CDoubleMatrix dataMatrix;
	CIntVector vIndex;
	CDoubleVector v;
	CTString szTemp("");
	CTString szFldNameX("");
	CTString szFldNameY("");

	if (m_tVarY.iCount > 0)
	{
		for (i=0; i<m_tVarY.iCount; i++)
		{
			nGroupIndex = m_tVarY.pValue[i];
			szFldNameY = m_pDataInterface->GetFieldName(nGroupIndex); 
			for (j=0; j<m_tVarX.iCount; j++)
			{
				nColIndex = m_tVarX.pValue[j];
				arrCol.Add(nGroupIndex);
				arrCol.Add(nColIndex);
				szFldNameX = m_pDataInterface->GetFieldName(nColIndex); 
				nRowCount = m_pDataInterface->GetColsData(arrCol,dataMatrix,dataMap);
				if (nRowCount < 1)
				{
					szTemp.Format("%s中的有效数据太少(分组变量=%s,数据变量=%s),无法绘图,请检查,Line=%d,File=%s",m_szChartName.GetData(),szFldNameY.GetData(),szFldNameX.GetData(),__LINE__,__FILE__);
					m_szErrMsg += szTemp;
					arrCol.RemoveAll();
					dataMap.Clear();
					dataMatrix.destroy();
					continue;
				}
				//有效数据
				v.create(nRowCount);
				CDoubleVector v1 = dataMatrix(0);
				CDoubleVector v2 = dataMatrix(1);
				v1.Sort(vIndex);
				fTmp = v1(0);
				nIndex = 0;
				for (k=0; k<nRowCount; k++)
				{
					if (fTmp == v1(k))
					{
						v(nIndex) = v2(vIndex(k)-1);
						nIndex ++;
						continue;
					}
					szTemp = GetLabel(dataMap,0,nGroupIndex,fTmp);
					szTemp = "\n" + szTemp;
					//直方图
					v.resize(nIndex);
					CalcHistogram(v,szFldNameX+szTemp);
					v.destroy();
					v.create(nRowCount);
					fTmp = v1(k);
					nIndex =0;
					v(nIndex) = v2(vIndex(k)-1);
				}
				//最后
				szTemp = GetLabel(dataMap,0,nGroupIndex,fTmp);
				szTemp = "\n" + szTemp;
				//直方图
				v.resize(nIndex);
				CalcHistogram(v,szFldNameX+szTemp);
				v.destroy();
				v.create(nRowCount);
				//释放内存
				vIndex.destroy();
				dataMap.Clear();
				arrCol.RemoveAll();
				dataMatrix.destroy();
			}
		}
	}
	else
	{
		for (i=0; i<m_tVarX.iCount; i++)
		{
			nColIndex = m_tVarX.pValue[i];
			arrCol.Add(nColIndex);
			szFldNameX = m_pDataInterface->GetFieldName(nColIndex); 
			nRowCount = m_pDataInterface->GetColsData(arrCol,dataMatrix,0);
			if (nRowCount < 1)
			{
				szTemp.Format("%s中的有效数据太少(%s),无法绘图,请检查,Line=%d,File=%s",m_szChartName.GetData(),szFldNameX.GetData(),__LINE__,__FILE__);
				m_szErrMsg += szTemp;
				arrCol.RemoveAll();
				dataMatrix.destroy();
				continue;
			}
			//有效数据
			v = dataMatrix(0);
			//直方图
			CalcHistogram(v,szFldNameX);
			//释放内存
			arrCol.RemoveAll();
			dataMatrix.destroy();
		}
	}
	return true;
}
Exemplo n.º 17
0
int
OmahaWinnerCalculator::GetBestHandCardValue(int nCard1, int nCard2, int nCard3, int nCard4, 
											int nTableCard1, int nTableCard2, int nTableCard3, int nTableCard4, int nTableCard5, 
											PokerHandCardsClass& cardsClass, CDWordArray& arrCardsIdx){
	if( nTableCard1 <= -1 || nTableCard2 <= -1 || nTableCard3 <= -1 ){
		cardsClass = PokerHandCardsClass::CardsClass_None;
		return PokerHandCardsClass::CardsClass_None;
		}

	int				arrCards[]			= {	GetCardValue(nTableCard1), GetCardValue(nTableCard2), 
											GetCardValue(nTableCard3), GetCardValue(nTableCard4), 
											GetCardValue(nTableCard5)};
	int				arrCardsReplaced[]	= {	arrCards[0], arrCards[1], arrCards[2], arrCards[3], arrCards[4]}; 
	int				arrWinnerCardsIdx[]	= {	4, 5, 6, 7, 8 }; // Copy best combinations card indexes.((0, 1, 2, 3) - identifies hand cards (4, 5, 6, 7, 8) = identifies table cards)

	struct HandCardsCombination{
		int nHandCardVal1;
		int nHandCardVal2;
		int nHandCardIndex1;
		int nHandCardIndex2;
		};

	int nHandCardVal1			= GetCardValue(nCard1);
	int nHandCardVal2			= GetCardValue(nCard2);
	int nHandCardVal3			= GetCardValue(nCard3);
	int nHandCardVal4			= GetCardValue(nCard4);
	int nBestHandCardsVal		= 0x7fffffff;
	int nBestHandCardsValTemp	= 0;

	HandCardsCombination	comb[] = 
		{
		{nHandCardVal1, nHandCardVal2, 0, 1}, 
		{nHandCardVal1, nHandCardVal3, 0, 2}, 
		{nHandCardVal1, nHandCardVal4, 0, 3}, 
		{nHandCardVal2, nHandCardVal3, 1, 2}, 
		{nHandCardVal2, nHandCardVal4, 1, 3}, 
		{nHandCardVal3, nHandCardVal4, 2, 3}
		};

	// 3 table cards
	if( nTableCard4 <= -1 ){
		for( int x=0; x<6; x++){
			HandCardsCombination* pComb = &comb[x];
			// Copy cards array.
			memcpy(arrCardsReplaced, arrCards, sizeof(arrCards));
			arrCardsReplaced[3]			= pComb->nHandCardVal1;
			arrCardsReplaced[4]			= pComb->nHandCardVal2;

			nBestHandCardsValTemp = GetHandValue(arrCardsReplaced[0], arrCardsReplaced[1], arrCardsReplaced[2], arrCardsReplaced[3], arrCardsReplaced[4]);
			if( nBestHandCardsVal > nBestHandCardsValTemp ){
				nBestHandCardsVal		= nBestHandCardsValTemp;
				arrWinnerCardsIdx[0]	= 4;						// table card 1 index
				arrWinnerCardsIdx[1]	= 5;						// table card 2 index
				arrWinnerCardsIdx[2]	= 6;						// table card 3 index
				arrWinnerCardsIdx[3]	= pComb->nHandCardIndex1;	// hand card index
				arrWinnerCardsIdx[4]	= pComb->nHandCardIndex2;	// hand card index
				}
			}

		}
	else
	// 4 table cards.
	if( nTableCard5 <= -1 ){
		for( int x=0; x<6; x++){
			HandCardsCombination* pComb = &comb[x];
			for( int j=0; j<4; j++ ){
				// Copy cards array.
				memcpy(arrCardsReplaced, arrCards, sizeof(arrCards));
				arrCardsReplaced[j]			= pComb->nHandCardVal1;
				arrCardsReplaced[4]			= pComb->nHandCardVal2;

				nBestHandCardsValTemp = GetHandValue(arrCardsReplaced[0], arrCardsReplaced[1], arrCardsReplaced[2], arrCardsReplaced[3], arrCardsReplaced[4]);
				if( nBestHandCardsVal > nBestHandCardsValTemp ){
					nBestHandCardsVal		= nBestHandCardsValTemp;
					arrWinnerCardsIdx[0]	= 4;						// table card 1 index
					arrWinnerCardsIdx[1]	= 5;						// table card 2 index
					arrWinnerCardsIdx[2]	= 6;						// table card 3 index
					arrWinnerCardsIdx[3]	= 7;						// table card 4 index
					arrWinnerCardsIdx[4]	= pComb->nHandCardIndex2;	// hand card index
					arrWinnerCardsIdx[j]	= pComb->nHandCardIndex1;	// hand card index
					}
				}
			}
		}
	// 5 table cards.
	else{
		for( int x=0; x<6; x++){
			HandCardsCombination* pComb = &comb[x];
			for( int j=0; j<5; j++ ){
				for( int k=j+1; k<5; k++ ){
					// Copy cards array.
					memcpy(arrCardsReplaced, arrCards, sizeof(arrCards));
					arrCardsReplaced[j] = pComb->nHandCardVal1;
					arrCardsReplaced[k] = pComb->nHandCardVal2;

					nBestHandCardsValTemp = GetHandValue(arrCardsReplaced[0], arrCardsReplaced[1], arrCardsReplaced[2], arrCardsReplaced[3], arrCardsReplaced[4]);
					if( nBestHandCardsVal > nBestHandCardsValTemp ){
						nBestHandCardsVal		= nBestHandCardsValTemp;
						arrWinnerCardsIdx[0]	= 4;						// table card 1 index
						arrWinnerCardsIdx[1]	= 5;						// table card 2 index
						arrWinnerCardsIdx[2]	= 6;						// table card 3 index
						arrWinnerCardsIdx[3]	= 7;						// table card 4 index
						arrWinnerCardsIdx[4]	= 8;						// table card 5 index
						arrWinnerCardsIdx[j]	= pComb->nHandCardIndex1;	// hand card index
						arrWinnerCardsIdx[k]	= pComb->nHandCardIndex2;	// hand card index
						}
					}
				}
			}
		}

	_String sClassName;
	cardsClass = CardsHandClass(nBestHandCardsVal, &sClassName);
	if( cardsClass != PokerHandCardsClass::CardsClass_None ){
		arrCardsIdx.Add(arrWinnerCardsIdx[0]);
		arrCardsIdx.Add(arrWinnerCardsIdx[1]);
		arrCardsIdx.Add(arrWinnerCardsIdx[2]);
		arrCardsIdx.Add(arrWinnerCardsIdx[3]);
		arrCardsIdx.Add(arrWinnerCardsIdx[4]);
		}
	return nBestHandCardsVal;
	}
Exemplo n.º 18
0
bool
EmbedeedFontMan::AddFont(const CString sFontFolder, const CString sFontName){
	CString sDir = sFontFolder;
	if( sDir.GetAt(sDir.GetLength() - 1) != '\\' )
		sDir += _T("\\");

	EmbedeedFont* pFont = new EmbedeedFont();

	// Load characters code map. {{
	BYTE*	lpContent	= NULL;
	int		nSize		= 0;
	if( Path::ReadFileContent(sDir + _T("codes.txt"), lpContent, nSize) && nSize > 0 ){
		CString sContent;
		memcpy(sContent.GetBufferSetLength(nSize), lpContent, nSize);

		CStringArray arrStrings;
		StringHelper::Split(&sContent, _T(";"), arrStrings);

		CString sCharCode;
		for(int i=0; i<arrStrings.GetCount(); i++){
			sCharCode		= arrStrings.GetAt(i);
			int nCharCode	= 0;
			// Hex value
			if( sCharCode.GetAt(0) == '#' )
				nCharCode = StringHelper::HexStringIntoInt(&((TCHAR*)sCharCode.GetBuffer())[1], sCharCode.GetLength() - 1);
			else
				nCharCode = _ttoi(sCharCode.GetBuffer());
			pFont->m_arrCharacters.Add((void*)nCharCode, (void*)i);
			}
		}
	else{
#ifdef _DEBUG
		CString sMsg;
		sMsg.Format(_T("Couldn't find %s"), sDir + _T("codes.txt"));
		AfxMessageBox(sMsg);
#endif
		if( lpContent )
			delete [] lpContent;
		delete pFont;
		return false;
		}
	// }}

	if( lpContent ){
		delete [] lpContent;
		lpContent = NULL;
		}

	CStringArray arrFileNames;
	if( Path::GetFilesByExtention(sDir, _T("*.bmp"), arrFileNames, true) == 0 ){
		delete pFont;
		return false;
		}
	
	for(int i=0; i<arrFileNames.GetCount(); i++){
		CString sName = arrFileNames.GetAt(i);
		CString sName2 = sName;
		CString sFile = sDir + sName;

		if( sName.Left(sFontName.GetLength()) != sFontName )
			continue; // Skip wrong file name.

		sName.Delete	(0, sFontName.GetLength());
		sName.MakeLower	();

		int nIndex = 0;
		EmbedeedFontItemInfo* pInfo = new EmbedeedFontItemInfo();
		pInfo->ZeroInit();

		// Bold
		if( sName.GetAt(nIndex) == 'b' ){
			pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_BOLD;
			nIndex ++;
			}
		// Underline
		if( sName.GetAt(nIndex) == 'u' ){
			pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_UNDERLINE;
			nIndex ++;
			}
		// Italic
		if( sName.GetAt(nIndex) == 'i' ){
			pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_ITALIC;
			nIndex ++;
			}

		// Load characters map image and detect characters left offset and width (in pixels). {{
		CImage* pImage = ImageHelper::LoadImage(sFile, -1, -1, false);
		if( pImage ){
			BITMAP bmImage;
			GetObject(*pImage, sizeof(BITMAP), &bmImage);

			int			nWidthLimit				= bmImage.bmWidth;
			int			nSymbolCt				= 0;
			BYTE*		pBits					= (BYTE*)bmImage.bmBits;
			int			nXOffset				= 0;
			int			nBPP					= bmImage.bmBitsPixel/8;
			int			nSymbolMostLeftOffset	= -1;
			int			nSymbolMostRightOffset	= -1;
			CDWordArray arrSymbolLeftOffsetAndWidth;
			CString		sSymbolStartPointAndWidth;

			int nMaxXOffset = bmImage.bmWidth;
			for(int x=nXOffset; x<nMaxXOffset; x++){
				bool bClearLine = true;
				for(int y=0; y<bmImage.bmHeight; y++){
					BYTE* pLineStartingBits = &pBits[((bmImage.bmHeight - y - 1)*bmImage.bmWidthBytes)];
					BYTE* pPixel			= &pLineStartingBits[x*nBPP];

					// Is pixel visible.
					if( pPixel[0] > 10 ){
						bClearLine = false;
						if( nSymbolMostLeftOffset > -1 )
							nSymbolMostRightOffset = x;
						else
							nSymbolMostLeftOffset = x;
						continue;
						}
		
					pPixel = &pPixel[nBPP];
					}

				if( bClearLine && nSymbolMostLeftOffset > -1 ){
					if( nSymbolMostRightOffset == -1 )
						nSymbolMostRightOffset = nSymbolMostLeftOffset;
					DWORD dwCombineVal = (nSymbolMostLeftOffset << 16) | ((nSymbolMostRightOffset - nSymbolMostLeftOffset + 1)&0xFFFF);
					arrSymbolLeftOffsetAndWidth.Add(dwCombineVal);

#ifdef _DEBUG
					CString sFormat;
					sFormat.Format(_T("%d:%d;"), nSymbolMostLeftOffset, nSymbolMostRightOffset - nSymbolMostLeftOffset + 1);
					sSymbolStartPointAndWidth += sFormat;
#endif
					nSymbolMostLeftOffset	= -1;
					nSymbolMostRightOffset	= -1;
					}
				}

			pInfo->m_imageCharacters.Attach(pImage->Detach());
			delete pImage;

			if( (arrSymbolLeftOffsetAndWidth.GetCount() == pFont->m_arrCharacters.GetCount()) ){
				pInfo->m_pCharPoints = new CPoint[arrSymbolLeftOffsetAndWidth.GetCount()];
				for(int j=0; j<arrSymbolLeftOffsetAndWidth.GetCount(); j++){
					DWORD dwCombineVal = arrSymbolLeftOffsetAndWidth.GetAt(j);
					pInfo->m_pCharPoints[j].x = (int)(dwCombineVal>>16);
					pInfo->m_pCharPoints[j].y = (int)(dwCombineVal&0xFFFF);
					}
				}
			else{
#ifdef _DEBUG
				CBitmap bmImg;
				ImageHelper::CreateDIBBitmap(pInfo->m_imageCharacters.GetBPP(), bmImg, RGB(0, 0, 0), pInfo->m_imageCharacters.GetWidth(),
					pInfo->m_imageCharacters.GetHeight()*2, 0);

				CDC memDC;
				memDC.CreateCompatibleDC(NULL);
				::SelectObject(memDC, bmImg.m_hObject);

				CDC srcDC;
				srcDC.CreateCompatibleDC(NULL);
				::SelectObject(srcDC, pInfo->m_imageCharacters);
				memDC.BitBlt(0, 0, pInfo->m_imageCharacters.GetWidth(), pInfo->m_imageCharacters.GetHeight(), &srcDC, 0, 0, SRCCOPY);

				int nHeight = pInfo->m_imageCharacters.GetHeight();
				for(int j=0; j<arrSymbolLeftOffsetAndWidth.GetCount(); j++){
					DWORD dwCombineVal = arrSymbolLeftOffsetAndWidth.GetAt(j);
					int nLeft = (int)(dwCombineVal>>16);
					int nWidth = (int)(dwCombineVal&0xFFFF);

					memDC.FillSolidRect(nLeft, nHeight, nWidth, nHeight, RGB(255, 255, 0));
					}

				DeleteFile(sDir + _T("__") + sName2);
				CImage img;
				img.Attach((HBITMAP)bmImg.Detach());
				img.Save(sDir + _T("__") + sName2);
				img.Destroy();
				
				CString sMsg;
				sMsg.Format(_T("Characters count is not the same for font '%s' item '%s'"), sFontName, sName);
				AfxMessageBox(sMsg);
#endif
				delete pInfo;
				continue;
				}

			pInfo->m_nCharCount = arrSymbolLeftOffsetAndWidth.GetCount();
			}
Exemplo n.º 19
0
bool CBox::CalcBox2()
{
	int i=0, nCount=0;
	int nDataType = 0, nColIndex=0, nRowCount=0;
	CDWordArray arrCol;
	CDoubleMatrix dataMatrix;
	CTString szTemp("");
	CTString szFldName("");
	bool bHasBox=false;
	CTStringArray arrFldName;
	
	if (m_tVarX.iCount < 1)
	{
		m_szErrMsg.Format("盒状图中的数据不完整,至少需要一个变量,请检查!Line=%d,File=%s",__LINE__,__FILE__);
		return false;
	}
	m_szErrMsg.Empty();
	//数据处理
	TDataPointStrArr *pDPFB = NULL;
	CTChartBoxplot *pBox = new CTChartBoxplot;
	if (m_bSplit) //分开
	{
		for (i=0; i<m_tVarX.iCount; i++)
		{
			nColIndex = m_tVarX.pValue[i];
			nDataType = m_pDataInterface->GetFieldType(nColIndex);
			szFldName = m_pDataInterface->GetFieldName(nColIndex);
			if (nDataType != fInt && nDataType != fDouble && 
				nDataType != fBoolean && nDataType != fCurrency)
			{
				szTemp.Format("盒状图中的X轴参数(%s)不是数字型,无法绘图,请检查!Line=%d,File=%s",szFldName.GetData(),__LINE__,__FILE__);
				m_szErrMsg += szTemp;
				continue;
			}
			arrCol.RemoveAll();
			dataMatrix.destroy();
			arrCol.Add(nColIndex);
			nRowCount = m_pDataInterface->GetColsData(arrCol,dataMatrix,0);
			if (nRowCount < 1)
			{
				szTemp.Format("盒状图中的X轴变量(%s)有效数据太少,无法绘图,请检查!Line=%d,File=%s",szFldName.GetData(),__LINE__,__FILE__);
				m_szErrMsg += szTemp;
				continue;
			}
			//计算盒状图
			CIntVector vecInd;
			CDoubleVector w;
			CDoubleVector v = dataMatrix(0);
			pBox->SetParam(false,false,false);
			pBox->CalcPercent(v,w,vecInd);
			pBox->CalcBoxPlot(v,(void **)&pDPFB,nCount);
			pDPFB->strName += SEP_RISER + szFldName;
			pBox->SetBoxplot(pDPFB,1,StrArr);
			delete pDPFB;
			bHasBox = true;
		}
	}
	else
	{
		for (i=0; i<m_tVarX.iCount; i++)
		{
			nColIndex = m_tVarX.pValue[i];
			nDataType = m_pDataInterface->GetFieldType(nColIndex);
			szFldName = m_pDataInterface->GetFieldName(nColIndex);
			if (nDataType != fInt && nDataType != fDouble && 
				nDataType != fBoolean && nDataType != fCurrency)
			{
				szTemp.Format("盒状图中的X轴参数(%s)不是数字型,无法绘图,请检查!Line=%d,File=%s\n",szFldName.GetData(),__LINE__,__FILE__);
				m_szErrMsg += szTemp;
				continue;
			}
			arrCol.Add(nColIndex);
			arrFldName.Add(szFldName);
		}
		if (arrCol.GetSize() < 1)
		{
			m_szErrMsg.Format("盒状图中的X轴参数均为非数字型,无法绘图,请检查!Line=%d,File=%s\n",__LINE__,__FILE__);
			return false;
		}
		//读数据
		nRowCount = m_pDataInterface->GetColsData(arrCol,dataMatrix,0);
		if (nRowCount < 1)
		{
			m_szErrMsg.Format("盒状图中的X轴变量有效数据太少,无法绘图,请检查!Line=%d,File=%s\n",__LINE__,__FILE__);
			return false;
		}
		for (i=0; i<arrCol.GetSize(); i++)
		{
			//计算盒状图
			CIntVector vecInd;
			CDoubleVector w;
			CDoubleVector v = dataMatrix(i);
			pBox->SetParam(false,false,false);
			pBox->CalcPercent(v,w,vecInd);
			pBox->CalcBoxPlot(v,(void **)&pDPFB,nCount);
			pDPFB->strName += SEP_RISER + arrFldName.GetAt(i);
			pBox->SetBoxplot(pDPFB,1,StrArr);
			delete pDPFB;
			bHasBox = true;
		}
	}
	if (m_szErrMsg.GetLength() > 0)
	{
		CRsltElementText *pText = new CRsltElementText(MSG_TITLE_STR);
		CTString szMsg = GetLastErrMsg();
		pText->AddString(szMsg);
		m_pResult->Add(pText);
	}
	//Add
	if (bHasBox)
	{
		CRsltElementChart *pChart = new CRsltElementChart("盒状图",pBox);
		pBox->SetXAxilLabel("组项");
		m_pResult->SetName("盒状图"); 
		m_pResult->Add(pChart); 
	}
	else
	{
		delete pBox;
		pBox = NULL;
	}
	return true;
}
Exemplo n.º 20
0
void COscillogram::OnMouseMove(UINT nFlags, CPoint point) 
{
	CStringArray valArray;
	CDWordArray colArray;
	CString     strVal;
	CRect		mRect;
	CClientDC	dc(this);
	float		length;		//鼠标位置绝对象素数
	float		gValue;
	int			oldMode;
	int			curCell;	//所在单元格
	CPen pen(PS_SOLID,0,RGB(0,0,0));
	BOOL		PtState = FALSE;

	//(整个函数过程的功能)计算所有线所在单元格的数值
	oldMode = dc.SetMapMode(MM_LOMETRIC);
	SetOscillogramRect(&dc);
	dc.SelectObject(&pen);
	dc.SetROP2(R2_NOTXORPEN);
	dc.DPtoLP(&point);

	//如果 鼠标不在波形图内 或者 没有曲线 不做处理返回
	if(!(point.x >= m_GridRect.left  && point.x <= m_GridRect.right+3
		&& point.y <= m_GridRect.top && point.y >= m_GridRect.bottom)
		|| GetCurveCount() < 1 || m_showTitle == FALSE)
	{
		if(m_bPt.x != -1)
		{
			DrawMouseLine(&dc,m_bPt);
			m_bPt =-1;
		}
		m_TitleTip.ShowWindow(SW_HIDE);
		return;
	}
	
	//绘画跟随鼠标的十字线
	if(m_bPt.x == -1)
	{
		m_bPt = point;
		DrawMouseLine(&dc,point);
	}
	else
	{	
		DrawMouseLine(&dc,m_bPt);
		m_bPt = point;
		DrawMouseLine(&dc,point);
	}

	//计算个单元格数值
	length  = (float)( point.x - m_GridRect.left );
	curCell = (int)( length / m_xSpan );
	
	if(!m_showTime)
	{
		float n1 = (m_xMaxVal - m_xMinVal)/(m_xCount-1);
		float n2 = m_xMinVal + curCell*n1;
		strVal.Format("%s: %.2f",m_xText,n2);
	}
	else
	{
		CTimeSpan m_xTimeSpan = 0;
		CTimeSpan sc    = m_endTime - m_beginTime;
		CTime	cnTime  = m_beginTime;
		
		double secCount = (sc.GetDays()*86400) + (sc.GetHours()*3600) + 
			(sc.GetMinutes()*60) + sc.GetSeconds();
		secCount = secCount / (m_xCount-1);
		
		int day    = (int)secCount/86400;	//天
		secCount  -= day*86400;
		int hour   = (int)secCount/3600;	//小时
		secCount  -= hour*3600;
		int minute = (int)secCount/60;		//分钟
		secCount  -= minute*60;
		int second = (int)secCount;			//秒
		m_xTimeSpan = CTimeSpan(day,hour,minute,second);

		for(int j=0;j<curCell;j++)
			cnTime += m_xTimeSpan;
		strVal.Format("%s: %s",m_xText,cnTime.Format("%Y/%m/%d  %H:%M:%S"));
	}
	colArray.Add(RGB(0,0,0));
	valArray.Add(strVal);

	for(int i=0;i<GetCurveCount();i++)
	{
		gValue = GetCurve(i)->ptVal.GetPointValue(curCell,PtState);
		
		if(PtState)
			strVal.Format("%s: %.2f",GetCurveName(i),gValue);
		else
			strVal.Format("%s: ",GetCurveName(i));
		colArray.Add(GetCurve(i)->lColor);
		valArray.Add(strVal);
	}

	//显示浮动窗体
	dc.LPtoDP(&point);
	dc.SetMapMode(oldMode);

	//窗口跟随鼠标位置移动
	GetClientRect(mRect);
	mRect.left   += CS_LMARGIN;
	mRect.top    += CS_LMARGIN;
	mRect.right  -= CS_LMARGIN;
	mRect.bottom -= CS_LMARGIN;
	ClientToScreen(&point);
	ClientToScreen(&mRect);

	m_TitleTip.SetParentRect(mRect);
	m_TitleTip.SetStrArray(valArray,colArray);
	m_TitleTip.SetPos(&point);
	ScreenToClient(&point);
	
	CWnd::OnMouseMove(nFlags, point);
}