admin 发表于 2024-2-23 22:55:06

[每日一码] AcDbText::getTransformedCopy 不能预期的解决方案

Acad::ErrorStatus safeGetTransformedCopy(const AcDbText* pText,const
AcGeMatrix3d xform, AcDbEntity*& pNewEntity)
{
   static AcDbText text;
   Acad::ErrorStatus es;
   text.copyFrom(pText);
   AcGePoint3d posorig(text.position());
   AcGePoint3d alignorig(text.alignmentPoint());
   AcGePoint3d pos,align;
   AcGeVector3d norm(text.normal());

acdbWcs2Ecs(asDblArray(posorig),asDblArray(pos),asDblArray(norm),Adesk::kFalse);

   double elev = pos.z;
   if (fabs(elev)>1E-10)
   {
      pos.z = 0;
      align.z =0;

acdbEcs2Wcs(asDblArray(pos),asDblArray(pos),asDblArray(norm),Adesk::kFalse);

acdbEcs2Wcs(asDblArray(align),asDblArray(align),asDblArray(norm),Adesk::kFalse);
      text.setPosition(pos);
      text.setAlignmentPoint(align);
   }
   if ((es = text.getTransformedCopy(xform,pNewEntity))==Acad::eOk)
   {
      AcDbText* pNewText = NULL;
      if ((pNewText = AcDbText::cast(pNewEntity)) && fabs(elev)>1E-10)
      {
            posorig.transformBy(xform);
            alignorig.transformBy(xform);
            pNewText->setPosition(posorig);
            pNewText->setAlignmentPoint(alignorig);
      }
   }
   return es;
}
acdbWcs2Ecs(asDblArray(alignorig),asDblArray(align),asDblArray(norm),Adesk::kFalse);
页: [1]
查看完整版本: [每日一码] AcDbText::getTransformedCopy 不能预期的解决方案