|
如果我从Autocad执行简单插入块,它总是以在UCS中绘制块的方式插入块。一、 e.如果块有一个控制柄,并且在绘制时该控制柄指向XY平面中的Y+,则默认情况下,Autocad将始终将块插入UCS的XY平面,并将控制柄指向Y+。
但在使用[code][code][code]Objectarx insert block插入块[/code][/code][/code]时,情况似乎并非如此。我可以设置UCS使Y+指向水平方向,但插入块时控制柄仍然指向垂直方向[code]if (m_BlockRef)
{
delete m_BlockRef;
m_BlockRef = nullptr;
}
m_DirPt = dir_pt;
m_BlockRef = new AcDbBlockReference();
m_BlockRef->setBlockTableRecord(blk_objid);
// Calcualte Normal : refactor as function
AcGeVector3d vec = endPoint().asVector() - startPoint().asVector();
AcGeVector3d vec1 =m_DirPt.asVector() - startPoint().asVector();
AcGeVector3d vec_normal = vec.crossProduct(vec1);
vec_normal.normalize();
// Get UCS, refactor as a function
AcGeMatrix3d myUCS;
acdbUcsMatrix(myUCS, nullptr);
AcGeVector3d xAxis, yAxis, zAxis;
AcGePoint3d myOrigin;
myUCS.getCoordSystem(myOrigin, xAxis, yAxis, zAxis);
bool AngleFlip = false;
if (fabs (vec_normal.dotProduct(zAxis) ) < 1e-8)
return;
else if (vec_normal.dotProduct(zAxis) < 0)
AngleFlip = true;
else
AngleFlip = false;
m_BlockRef->setNormal(zAxis) ; //(vec_normal);
m_BlockRef->setPosition(ins_pt);
AcGeScale3d scl;
if (scale < 0)
scale = 1.0;
scl.set(scale, scale, scale);
m_BlockRef->setScaleFactors(scl);
// calculate angle
ads_point p_start_wcs, p_end_wcs, p_start_ucs, p_end_ucs;
p_start_wcs[X] = startPoint().x ; p_start_wcs[Y] = startPoint().y ; p_start_wcs[Z] = startPoint().z;
p_end_wcs[X] = endPoint().x ; p_end_wcs[Y] = endPoint().y ; p_end_wcs[Z] = endPoint().z;
ConvertFromWCSToUCS(p_start_wcs, p_start_ucs);
ConvertFromWCSToUCS(p_end_wcs, p_end_ucs);
AcGePoint3d p_start(p_start_ucs[X], p_start_ucs[Y], p_start_ucs[Z]);
AcGePoint3d p_end(p_end_ucs[X], p_end_ucs[Y], p_end_ucs[Z]);
AcGeVector3d v1_ucs = p_end.asVector() - p_start.asVector();
AcGeVector3d v1 = endPoint().asVector() - startPoint().asVector();
AcGeVector3d ref_vector = AcGeVector3d::kZAxis;
double dangle = xAxis.angleTo(v1_ucs, zAxis); // this is not what I want?
double dangle1 = AcGeVector3d::kXAxis.angleTo(v1_ucs,AcGeVector3d::kZAxis);
if (m_AngleFlip )
{
dangle1 *= -1;
m_FlipHandle = !m_FlipHandle;
}
m_BlockRef->setRotation(dangle1 );[/code]。 |
|