static void DrawZValue( AcGiWorldDraw* mode, double z, const AcGePoint3d& tpt, double angle, double height )
{
    AcGeVector3d v( AcGeVector3d::kXAxis );
    v.rotateBy( angle, AcGeVector3d::kZAxis );
    if( v.x < 0 )
    {
        angle += PI;
    }

    CString text;
    text.Format( _T( " %.5f " ), z );

    AcDbMText mt;
    mt.setLocation( tpt );
    mt.setTextHeight( height );
    mt.setAttachment( AcDbMText::kMiddleCenter );
    mt.setRotation( angle );
    mt.setBackgroundFill( true );
    mt.setUseBackgroundColor( true );
    mt.setBackgroundScaleFactor( 1.0 );
    mt.setContents( text );

    // 经过测试发现,AcDbMText调用worldDraw的同时会修改mode的一些属性
    mt.setColorIndex( mode->subEntityTraits().color() );

    mt.worldDraw( mode );
}
Exemple #2
0
void DrawMText( AcGiWorldDraw* mode, const AcGePoint3d& pt, double angle, const CString& str, double height, AcDbMText::AttachmentPoint ap, const CString& style )
{
    //acutPrintf(_T("\n绘制前--文字颜色:%d"), mode->subEntityTraits().color());
    AcDbMText mt;

 //   //AcDbObjectId style; // 文字样式
	AcDbObjectId fontId = GetTextStyle(style);
	if(!fontId.isNull())
	{
		acutPrintf(_T("\n设置样式为罗马字体"));
		mt.setTextStyle(fontId);
	}
    mt.setLocation( pt );
    mt.setTextHeight( height );

	mt.setAttachment( ap );
    mt.setRotation( angle );

    mt.setContents( str );

    // 经过测试发现,AcDbMText调用worldDraw的同时会修改mode的一些属性
    mt.setColorIndex( mode->subEntityTraits().color() );
	
    mt.worldDraw( mode );

    //acutPrintf(_T("\n绘制后--文字颜色:%d"), mode->subEntityTraits().color());
}
static void GetTextAndWidth( double z, double height, CString& text, double& width )
{
    AcDbMText mt;
    mt.setLocation( AcGePoint3d::kOrigin );
    mt.setRotation( 0 );
    mt.setTextHeight( height );
    mt.setAttachment( AcDbMText::kMiddleCenter ); // 默认居中

    // 获取文字内容
    text.Format( _T( " %.3f " ), z );
    mt.setContents( text );

    // 获取文字宽度
    width = mt.actualWidth();
}
Exemple #4
0
AcDbObjectId CArxHelper::CreateText(const CString& strText, const AcGePoint3d& pt1, const AcGePoint3d& pt2, double dDist, BOOL bUp /* = TRUE */)
{
	AcDbObjectId textId = AcDbObjectId::kNull;
	AcGePoint3d pt = (pt1 + pt2.asVector()) / 2.0;
	AcDbMText* pMText = new AcDbMText();
	pMText->setContents(strText);
	pMText->setLocation(pt);

	pMText->setDirection(pt2-pt1);

	textId = AddToCAD(pMText,4);

	AcDbExtents extents;
	pMText->getGeomExtents(extents);
	AcGeVector3d vect = (pt2-pt1).normal() * (extents.maxPoint().x - extents.minPoint().x) / 2.0;
	AcGeMatrix3d xform = AcGeMatrix3d::translation(-vect);
	acdbOpenObject(pMText,textId,AcDb::kForWrite);
	pMText->transformBy(xform);
	pMText->close();
	return textId;
}