编码转换问题

1.unicode编码字符转 utf-8中文汉字:

#include <atlstr.h>
bool UnicodeToChinese(string str, CString&  cstr)
{
	int i = 0;
	int j = 0;
	int len = 0;

	len = str.length();
	if (len <= 0)
	{
		return false;
	}

	int nValue = 0;
	WCHAR * pWchar;
	wchar_t* szHex;
	char strchar[6] = { '0','x','\0' };

	for (i = 0; i < len; i++)
	{
		if (str[i] == 'u')
		{
			for (j = 2; j < 6; j++)
			{
				i++;
				strchar[j] = str[i];
			}

			USES_CONVERSION;
			szHex = A2W(strchar);

			StrToIntExW(szHex, STIF_SUPPORT_HEX, &nValue);
			pWchar = (WCHAR*)& nValue;

			cstr = cstr + pWchar;

		}
	}
	return true;
}

void test3() {
	//待雪初平和望断秋高
	string  m_Unicode = "\\u5f85\\u96ea\\u521d\\u5e73\\u548c\\u671b\\u65ad\\u79cb\\u9ad8";
	CString m_UnicodeToChinese;

	UnicodeToChinese(m_Unicode, m_UnicodeToChinese);

	cout << m_Unicode << "\n" << "UnicodeToChinese:" << "\n";
	wcout << m_UnicodeToChinese.GetString() << endl;

	//CString c_name = _T("li");
	//所以CT2A其实就是CW2A就是将Unicode转换为多字符集ASCII,也可写成CW2A
	std::string str = CT2A(m_UnicodeToChinese.GetString());
}

###################################################
occ动画:
TopoDS_Shape aTopoBox1 = BRepPrimAPI_MakeBox(10,20,30).Shape();
    Handle(AIS_Shape) hBox1 = new AIS_Shape(aTopoBox1);

    hBox1->SetColor(Quantity_NOC_RED);
    myOccView->getContext()->Display(hBox1,Standard_True);


    //animation
    TCollection_AsciiString name("anim");
    Handle(AIS_Animation) anim = new AIS_Animation(name);

    double durationTime =20;
    anim->SetOwnDuration(durationTime);
    //anim->StartTimer(0,1.0,true);

    gp_Trsf start_pnt, end_pnt;

    start_pnt.SetValues(1, 0, 0, 0,
                        0, 1, 0, 0,
                        0, 0, 1, 0);
    end_pnt.SetValues(5, 0, 0, 800,
                      0, 5, 0, 0,
                      0, 0, 5, 0);

    Handle(AIS_AnimationObject) aisObj = new AIS_AnimationObject("boxObj", myOccView->getContext(), hBox1, start_pnt, end_pnt);
    aisObj->SetOwnDuration(durationTime);
    aisObj->SetStartPts(0);//?
    anim->Add(aisObj);

    anim->StartTimer(0, 1.0, true);
    //anim->Start(true);
    aisObj->Start(true);

    int i=1;
    while (!anim->IsStopped())
    {
       qDebug() << i++ << " " << aisObj->ElapsedTime() << endl;
       anim->UpdateTimer();
       anim->UpdateTotalDuration();

       //anim->
       //myOccView->getContext()->SetLocation();

       //aisObj->Update(0.01*i);
       myOccView->getContext()->UpdateCurrentViewer();

       if(myOccView->myView->IsInvalidated()){
            myOccView->myView->Redraw();
            qDebug() << " IsInvalidated ";
       }
       else{
            myOccView->myView->RedrawImmediate();
       }


       //myOccView->getContext()->DisplayAll(true);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值