The AcDbEntity class offers two transformation functions. The transformBy() function applies a matrix to an entity. The getTransformedCopy() function enables an entity to return a copy of itself with the transformation applied to it.
If an entity is uniformly scaled and orthogonal, the default implementation of the AcDbEntity::getTransformedCopy() function clones the entity and then invokes the transformBy() function on the cloned entity. (Use the AcGeMatrix3d::isUniScaledOrtho() function to determine if the input matrix is uniformly scaled and orthogonal.)
To modify the default behavior, override your custom entity’s subGetTransformedCopy() and subTransformBy() functions, which are called by getTransformedCopy() and transformBy(), respectively.
The custom AsdkPoly class overrides both the subTransformBy() function and the subGetTransformedCopy() function. When AsdkPoly is nonuniformly scaled, it becomes a polyline.
Acad::ErrorStatus AsdkPoly::subTransformBy(const AcGeMatrix3d& xform) { // If we're dragging, we aren't really going to change our // data, so we don't want to make an undo recording nor do // we really care if the object's open for write. // if (mDragDataFlags & kCloneMeForDraggingCalled) { mDragDataFlags |= kUseDragCache; mDragPlaneNormal = mPlaneNormal; mDragElevation = mElevation; AcGeMatrix2d xform2d(xform.convertToLocal(mDragPlaneNormal, mDragElevation)); mDragCenter = mCenter; mDragCenter.transformBy(xform2d); mDragStartPoint = mStartPoint; mDragStartPoint.transformBy(xform2d); mDragPlaneNormal.normalize(); } else { assertWriteEnabled(); AcGeMatrix2d xform2d(xform.convertToLocal(mPlaneNormal, mElevation)); mCenter.transformBy(xform2d); mStartPoint.transformBy(xform2d); mPlaneNormal.normalize(); } return Acad::eOk; }
// Transform points and create a polyline out of them. // Acad::ErrorStatus AsdkPoly::subGetTransformedCopy( const AcGeMatrix3d& mat, AcDbEntity*& ent) const { assertReadEnabled(); Acad::ErrorStatus es = Acad::eOk; AcGePoint3dArray vertexArray; if ((es = getVertices3d(vertexArray)) != Acad::eOk) { return es; } for (int i = 0; i < vertexArray.length(); i++) { vertexArray[i].transformBy(mat); } AcDbSpline *pSpline = NULL; if ((es = rx_makeSpline(vertexArray, pSpline)) != Acad::eOk) { return es; } assert(pSpline != NULL); pSpline->setPropertiesFrom(this); ent = pSpline; return es; }