|
Acad::ErrorStatus setAlignmentPoint(AcDbText &text, const AcGePoint3d &pt)
{
if (!text.isWriteEnabled())
return Acad::eNotOpenForWrite;
AcDb::TextHorzMode hmode = text.horizontalMode();
AcDb::TextVertMode vmode = text.verticalMode();
if ((hmode == AcDb::kTextLeft) && (vmode == AcDb::kTextBase))
return text.setPosition(pt); // only here position() is relevant and alignmentPoint() not
else
return text.setAlignmentPoint(pt); // here alignmentPoint() is relevant
}
AcGePoint3d getAlignmentPoint(const AcDbText &text)
{
AcDb::TextHorzMode hmode = text.horizontalMode();
AcDb::TextVertMode vmode = text.verticalMode();
if ((hmode == AcDb::kTextLeft) && (vmode == AcDb::kTextBase))
return text.position(); // only here position() is relevant and alignmentPoint() not
else
return text.alignmentPoint(); // here alignmentPoint() is relevant
}
void cmdTestText()
{
ads_point pt;
ads_name ent;
AcDbObjectId objId;
if (acedEntSel(_T("\nSelect Text: "), ent, pt) != RTNORM)
return;
if (acdbGetObjectId(objId, ent) != Acad::eOk) //ads_name-->AcDbObjectId
return;
Acad::ErrorStatus es;
AcDbText *pText = NULL;
AcDbText *pText2 = NULL;
AcGePoint3d ptAlign;
AcGeVector3d vNormal;
double rot = 0.0;
Adesk::Boolean bMirrX=false, bMirrY=false;
if ( (es=acdbOpenObject(pText, objId, AcDb::kForRead)) == Acad::eOk )
{
pText2 = AcDbText::cast(pText->clone()); // Create a clone
pText2->setDatabaseDefaults();
pText2->setColorIndex(1); //red
pText2->mirrorInX(false);
pText2->mirrorInY(false);
ptAlign = getAlignmentPoint(*pText);
vNormal = pText->normal();
rot = pText->rotation();
bMirrX = pText->isMirroredInX();
bMirrY = pText->isMirroredInY();
pText->close();
}
AcGeVector3d vx, vy, vz(vNormal);
vx = vz.perpVector();
vy = (vz.crossProduct(vx)).normalize();
AcGeVector3d vxRot(vx);
vxRot.rotateBy(rot, vz); // The rotated x-Axis
AcGeMatrix3d mat;
mat.setCoordSystem(ptAlign, vx, vy, vz);
bool bNeedZMirror = false;
if (bMirrX)
{
bNeedZMirror = !bNeedZMirror;
AcGePlane planeXZ(ptAlign, AcGeVector3d::kYAxis);
AcGeMatrix3d matMirrY;
matMirrY.setToMirroring(planeXZ);
mat.preMultBy(matMirrY);
}
if (bMirrY)
{
bNeedZMirror = !bNeedZMirror;
AcGePlane plane(ptAlign, AcGeVector3d::kXAxis);
AcGeMatrix3d matMirr;
matMirr.setToMirroring(plane);
mat.preMultBy(matMirr);
}
if (bNeedZMirror)
{
// Make sure that mat is not mirroring
AcGePlane plane(AcGePoint3d::kOrigin, AcGeVector3d::kZAxis);
AcGeMatrix3d matMirr;
matMirr.setToMirroring(plane);
mat.preMultBy(matMirr);
}
AcGeVector3d vx2, vy2, vz2;
AcGePoint3d origin;
mat.getCoordSystem(origin, vx2, vy2, vz2);
// Calculate rotation value of vxRot with respect to vx2 and vz2
double rot2 = vx2.angleTo(vxRot, vz2);
// Create a second Text entity without mirroring
pText2->setNormal(vz2);
pText2->setRotation(rot2);
postToDb(pText2);
es = setAlignmentPoint(*pText2, ptAlign);
es = pText2->adjustAlignment();
pText2->close();
在下面的示例代码double rot2;中,是要查找的文本的旋转。
函数void cmdTestText()要求选择文本。然后创建一个外观相同的红色文本副本,该文本的两个镜像标志都设置为false,并将其添加到数据库中。 |
|