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 ); }
AcDbObjectId CArxHelper::CreateMLeader(const CString& strText, const AcGePoint3d& ptArrow, const AcGePoint3d& ptBase, const AcGeVector3d& vectDir) { AcDbObjectId leaderId = AcDbObjectId::kNull; AcDbMText* pMText = new AcDbMText(); pMText->setContents(strText); pMText->setColorIndex(4); AcDbExtents extents; pMText->getGeomExtents(extents); AcDbMLeader *pEnt=new AcDbMLeader(); int i = 0; pEnt->setContentType(AcDbMLeaderStyle::kMTextContent); pEnt->addLeader(i); pEnt->addLeaderLine(ptArrow,i); pEnt->addLastVertex(i,ptBase); pEnt->setDoglegLength(1); pEnt->setDoglegDirection(i,vectDir); pEnt->setArrowSize(0.001); pEnt->setTextAttachmentType(AcDbMLeaderStyle::kAttachmentBottomLine,AcDbMLeaderStyle::kLeftLeader); pEnt->setTextAttachmentType(AcDbMLeaderStyle::kAttachmentBottomLine,AcDbMLeaderStyle::kRightLeader); pEnt->setTextAlignmentType(AcDbMLeaderStyle::kLeftAlignment); pEnt->setMText(pMText); AcGePoint3d pt = ptBase+vectDir*(extents.maxPoint().x-extents.minPoint().x)*1.1+AcGeVector3d::kYAxis*(extents.maxPoint().y-extents.minPoint().y)*1.1; pEnt->setTextLocation(pt); leaderId = AddToCAD(pEnt); return leaderId; }
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(); }
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; }
static void BlockToEntity( const AcDbObjectId& blkId, const AcGeMatrix3d& blkXform, const AcStringArray& names, const AcStringArray& attValues, AcGeVoidPointerArray& ents ) { // 将块定义分解成独立的图元 // 将属性替换成多行文字 AcTransaction* pTrans = actrTransactionManager->startTransaction(); AcDbObject* pObj; if( Acad::eOk != pTrans->getObject( pObj, blkId, AcDb::kForRead ) ) { actrTransactionManager->abortTransaction(); return; } AcDbBlockTableRecord* pBTR = AcDbBlockTableRecord::cast( pObj ); // BUG:不能调用hasAttributeDefinitions()方法 // 调用之后,如果没有在块编辑器中对块进行修改, // 那么进行移动、夹点编辑等操作,没有动态显示效果 //if(!pBTR->hasAttributeDefinitions()) //{ // // 没有属性定义 // acutPrintf(_T("\n没有属性定义")); // actrTransactionManager->abortTransaction(); // return; //} AcDbBlockTableRecordIterator* pIterator; if( Acad::eOk != pBTR->newIterator( pIterator ) ) { actrTransactionManager->abortTransaction(); return; } // 遍历块中的图元,查找AcDbAttributeDefinition for( pIterator->start( true ); !pIterator->done(); pIterator->step( true ) ) { AcDbObjectId objId; if( Acad::eOk != pIterator->getEntityId( objId ) ) continue; if( Acad::eOk != pTrans->getObject( pObj, objId, AcDb::kForWrite ) ) continue; AcDbEntity* pEnt = AcDbEntity::cast( pObj ); if( !pEnt->isKindOf( AcDbAttributeDefinition::desc() ) ) { AcDbEntity* pClone = AcDbEntity::cast( pEnt->clone() ); pClone->transformBy( blkXform ); // 添加到实体集合 ents.append( pClone ); } else { AcDbAttributeDefinition* pAttDef = AcDbAttributeDefinition::cast( pEnt ); pAttDef->convertIntoMTextAttributeDefinition( Adesk::kTrue ); // 获取标签名称 ACHAR* pTag = pAttDef->tag(); int pos = names.find( pTag ); if( pos != -1 ) { // 获取多行文本对象 AcDbMText* pMText = pAttDef->getMTextAttributeDefinition(); pMText->transformBy( blkXform ); pMText->setContents( attValues[pos].kACharPtr() ); // 添加到实体集合 ents.append( pMText ); } acutDelString( pTag ); } } delete pIterator; actrTransactionManager->endTransaction(); }