sort 及lambda表达式定制排序

void CDrawCircle::OnBnClickedBtnSelectinfo()
{
    // TODO:  在此添加控件通知处理程序代码
    UpdateData(TRUE);
    BeginEditorCommand();
    AcDbObjectIdArray idarr;
    bool b=CSelectUtil::SelectSomeEntityForBox(idarr, _T("\n选择需要提取的文字"));
    if (!b)
    {
        return;
    }
    std::map<CString, AcGePoint3d> mapTextToPt;
    
    int iNum = idarr.length();
    for (int i = 0; i < iNum;i++)
    {
        AcDbObjectId idTemp = idarr[i];
        AcDbEntity *pEnt = NULL;
        Acad::ErrorStatus es;
        es=acdbOpenAcDbEntity(pEnt, idTemp,AcDb::kForWrite);
        if (es!=eOk)
        {
            continue;
        }
        if (!pEnt->isKindOf(AcDbText::desc()))
        {
            continue;
        }
        AcDbText *pText = AcDbText::cast(pEnt);
        CString sText = pText->textString();
        AcGePoint3d pt = pText->position();
        mapTextToPt.insert(std::pair<CString, AcGePoint3d>(sText, pt));
        pText->close();
    }
    std::vector<std::pair<CString, AcGePoint3d>> vecInfo(mapTextToPt.begin(), mapTextToPt.end());
    std::sort(vecInfo.begin(), vecInfo.end(), [](const std::pair<CString, AcGePoint3d>&a, const std::pair<CString, AcGePoint3d>&b){return a.second.x<b.second.x; });
    int iCount = 1;
    for (size_t i = 0; i < vecInfo.size();i++)
    {
        CString sText = vecInfo[i].first;
        switch (iCount)
        {
        case 1:
            m_sNum1 = sText;
            break;
        case 2:
            m_sNum2 = sText;
            break;
        case 3:
            m_sNum3 = sText;
            break;
        case 4:
            m_sNum4 = sText;
            break;
        case 5:
            m_sNum5 = sText;
            break;
        case 6:
            m_sNum6 = sText;
            break;
        case 7:
            m_sNum7 = sText;
            break;
        case 8:
            m_sNum8 = sText;
            break;
        case 9:
            m_sNum9 = sText;
            break;
        case 10:
            m_sNum10 = sText;
            break;
        case 11:
            m_sNum11 = sText;
            break;
        case 12:
            m_sNum12 = sText;
            break;
        case 13:
            m_sNum13 = sText;
            break;
        case 14:
            m_sNum14 = sText;
            break;

        default:
            break;
        }
        iCount++;
    }
    CompleteEditorCommand(TRUE);
    UpdateData(FALSE);
}

 

posted @ 2017-04-11 14:57  xzh1993  阅读(4188)  评论(0编辑  收藏  举报