281 lines
8.9 KiB
C++
281 lines
8.9 KiB
C++
#include "StdAfx.h"
|
|
#include "TDbLayoutLegend.h"
|
|
#include "dbproxy.h"
|
|
#define SPACE_LENGEND_IN 3
|
|
#define SPACE_LENGEND_OUT 5
|
|
ACRX_DXF_DEFINE_MEMBERS(TDbLayoutLegend, ATSEntity, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
|
AcDbProxyEntity::kNoOperation, ATS_LAYOUTLEGEND, "ATS_LAYOUTLEGEND缺乏解释器图形看不见, 请下载上华软件|网址: www.shanghuasoft.com");
|
|
|
|
IMPLEMENT_TENTBASE(TDbLayoutLegend);
|
|
|
|
TDbLayoutLegend::TDbLayoutLegend ():TDbEntity (),
|
|
m_dPtImageXOffet(4.25),
|
|
m_dPtImageYOffet(6.25),
|
|
m_dPtImageYStepOffet(6.3),
|
|
m_dptTextXOffet(0),
|
|
m_dptTextYOffet(7.5),
|
|
m_dptTextYStepOffet(6.3),
|
|
m_ptLocation(0,0,0),
|
|
n_idTextStyle(acdbCurDwg()->textstyle()),
|
|
m_dRot(Ucs2Wcs(0))
|
|
{
|
|
m_dWidthStd = 8.5*DocGetPScale();
|
|
m_dHeightStd = 4.5*DocGetPScale();
|
|
}
|
|
|
|
TDbLayoutLegend::~TDbLayoutLegend ()
|
|
{
|
|
}
|
|
|
|
void TDbLayoutLegend::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
|
|
{
|
|
TDbEntity::CopyPropertiesFrom(pSrcEntity,gMatchFlag);
|
|
//
|
|
TDbLayoutLegend *pDest = (TDbLayoutLegend*)pSrcEntity;
|
|
this->m_ptLocation = pDest->m_ptLocation;
|
|
this->m_vecDrawData = pDest->m_vecDrawData;
|
|
this->m_vecCoordinateData =pDest->m_vecCoordinateData;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbLayoutLegend::ExplodeOrDraw2d(XExplodeDraw &dc) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
int iLen = (int)m_vecDrawData.size();
|
|
if (iLen <= 0)
|
|
{
|
|
return Acad::eOk;
|
|
}
|
|
|
|
//画图例标题
|
|
//图例标题
|
|
TDbText text;
|
|
XString sValue(256);
|
|
sValue<<_T("图例");
|
|
text.SetText(sValue);
|
|
text.SetHeight(3);
|
|
text.SetLocation(m_ptLocation);
|
|
text.SetLayoutRotation(m_dRot);
|
|
text.SetStyleId(n_idTextStyle);
|
|
text.SetAlignment(XExplodeDraw::kBottomCenter);
|
|
dc.DrawEntity(text);
|
|
|
|
//画图标
|
|
for (int i=0;i<iLen;i++)
|
|
{
|
|
//画块
|
|
TAcDbBlockRefData blockdata(m_vecDrawData[i].idBlock,
|
|
(m_vecCoordinateData[i].ptImage + m_vecDrawData[i].vecOffet),
|
|
m_vecDrawData[i].scale,
|
|
m_dRot,TRUE);
|
|
dc<<blockdata;
|
|
|
|
//画注释
|
|
XString sValue(256);
|
|
sValue<<m_vecDrawData[i].sText;
|
|
text.SetText(sValue);
|
|
text.SetLocation(m_vecCoordinateData[i].ptText);
|
|
text.SetHeight(2.5);
|
|
text.SetAlignment(XExplodeDraw::kBottomLeft);
|
|
dc.DrawEntity(text);
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
void TDbLayoutLegend::SetLocation(AcGePoint3d &pt)
|
|
{
|
|
m_ptLocation = pt;
|
|
|
|
//生成坐标表
|
|
MakeCoordinateTable((int)m_vecDrawData.size());
|
|
|
|
}
|
|
|
|
void TDbLayoutLegend::Push_Back(TCHAR* pszBlockName,TCHAR* pszText)
|
|
{
|
|
//压缩比初值
|
|
double dMinFact = 1;
|
|
|
|
//初始化块
|
|
XString sBlockName = pszBlockName;
|
|
CString szFileName = (const TCHAR *)(XPathParser(sBlockName).m_sFileName);
|
|
CString sLibFile = g_sDwbPath;
|
|
CString csPath = sLibFile + szFileName;
|
|
|
|
//文档锁定
|
|
AcApDocument *pDoc = acDocManager->curDocument();
|
|
acDocManager->lockDocument(pDoc);
|
|
AcDbObjectId idBlock;
|
|
int nRet = LoadDwbBlock(csPath,sBlockName);
|
|
if(nRet == RTNORM)
|
|
{
|
|
idBlock = InitBlock(sBlockName);
|
|
}
|
|
acDocManager->unlockDocument(pDoc);
|
|
|
|
//计算压缩比
|
|
if (idBlock.isValid())
|
|
{
|
|
TADSGePoint3d ptBase(0,0,0);
|
|
double nRot = 0;
|
|
TADSGePoint3d ptCen(0,0,0);
|
|
double nSizeX = 0;
|
|
double nSizeY = 0;
|
|
double nSizeZ = 0;
|
|
|
|
AcDbBlockReference *pRef = new AcDbBlockReference;
|
|
if (pRef)
|
|
{
|
|
//关联块
|
|
pRef->setBlockTableRecord(idBlock);
|
|
|
|
GetBlockRefSizeInfo(pRef, ptBase, &nRot,ptCen, &nSizeX, &nSizeY, &nSizeZ);
|
|
|
|
//超出范围,算压缩比例
|
|
if (nSizeX > m_dWidthStd || nSizeY > m_dHeightStd)
|
|
{
|
|
double dScale1 = m_dWidthStd/nSizeX;
|
|
double dScale2 = m_dHeightStd/nSizeY;
|
|
if (dScale1>dScale2)
|
|
{
|
|
dMinFact = dScale2;
|
|
}
|
|
else
|
|
{
|
|
dMinFact = dScale1;
|
|
}
|
|
}
|
|
|
|
delete pRef;
|
|
}
|
|
|
|
AcGeScale3d scale(dMinFact,dMinFact,dMinFact);
|
|
AcGeVector3d vec = ptBase - ptCen;
|
|
|
|
//数据入列
|
|
DRAWDATA temp;
|
|
temp.idBlock = idBlock;
|
|
temp.scale = scale;
|
|
temp.sText = pszText;
|
|
temp.vecOffet = vec*dMinFact;
|
|
m_vecDrawData.push_back(temp);
|
|
}
|
|
}
|
|
|
|
void TDbLayoutLegend::MakeCoordinateTable(int iSize)
|
|
{
|
|
while (!m_vecCoordinateData.empty())
|
|
{
|
|
m_vecCoordinateData.pop_back();
|
|
}
|
|
int nMid, nCloumn, nTemp;
|
|
double dOffset;
|
|
nCloumn = m_listCloumnWdith->GetCount();
|
|
if (nCloumn % 2)//奇数排
|
|
{
|
|
nMid = nCloumn / 2;
|
|
for (int i=0;i<iSize;i++)
|
|
{
|
|
dOffset = 0.5 * (2 * m_dPtImageXOffet * DocGetPScale() + m_listCloumnWdith->GetAt(m_listCloumnWdith->FindIndex(nMid)) + SPACE_LENGEND_IN * DocGetPScale());
|
|
nTemp = i;
|
|
COORDINATEDATA temp;
|
|
if (nTemp >= nCloumn)//换行
|
|
{
|
|
nTemp = nTemp % nCloumn;
|
|
}
|
|
if ((nTemp % nCloumn) < (nCloumn / 2))//插入点左边列
|
|
{
|
|
for (int n = (nCloumn / 2) -1 ; n >= nTemp; --n)
|
|
{
|
|
dOffset = dOffset + m_listCloumnWdith->GetAt(m_listCloumnWdith->FindIndex(n)) + 2 * SPACE_LENGEND_OUT * DocGetPScale();
|
|
}
|
|
for (int k = 1; k < ((nCloumn / 2) - nTemp); ++k)
|
|
{
|
|
dOffset = dOffset + 2 * m_dPtImageXOffet*DocGetPScale() + SPACE_LENGEND_IN * DocGetPScale();
|
|
}
|
|
temp.ptImage.x = (Wcs2Ucs(m_ptLocation).x - (dOffset + (m_dPtImageXOffet + SPACE_LENGEND_IN) * DocGetPScale()));
|
|
temp.ptImage.y = (Wcs2Ucs(m_ptLocation).y - m_dPtImageYOffet*DocGetPScale())-(i / nCloumn )*m_dPtImageYStepOffet*DocGetPScale();
|
|
temp.ptText.x = (Wcs2Ucs(m_ptLocation).x - dOffset);
|
|
temp.ptText.y = (Wcs2Ucs(m_ptLocation).y-m_dptTextYOffet*DocGetPScale())-(i / nCloumn )*m_dptTextYStepOffet*DocGetPScale();
|
|
temp.ptImage = Ucs2Wcs(temp.ptImage);
|
|
temp.ptText = Ucs2Wcs(temp.ptText);
|
|
}
|
|
else if ((nTemp % nCloumn) == (nCloumn / 2))//中间列,因为是以0为开始的
|
|
{
|
|
temp.ptImage.x = (Wcs2Ucs(m_ptLocation).x - (dOffset - m_dPtImageXOffet*DocGetPScale()));
|
|
temp.ptImage.y = (Wcs2Ucs(m_ptLocation).y - m_dPtImageYOffet*DocGetPScale())-(i / nCloumn )*m_dPtImageYStepOffet*DocGetPScale();
|
|
temp.ptText.x = (Wcs2Ucs(m_ptLocation).x + (SPACE_LENGEND_IN * DocGetPScale() + 2 * m_dPtImageXOffet*DocGetPScale() - dOffset));
|
|
temp.ptText.y = (Wcs2Ucs(m_ptLocation).y-m_dptTextYOffet*DocGetPScale())-(i / nCloumn )*m_dptTextYStepOffet*DocGetPScale();
|
|
temp.ptImage = Ucs2Wcs(temp.ptImage);
|
|
temp.ptText = Ucs2Wcs(temp.ptText);
|
|
}
|
|
else//右边列
|
|
{
|
|
for (int n = nCloumn /2; n < (nTemp % nCloumn); ++n)
|
|
{
|
|
dOffset += 2 * SPACE_LENGEND_OUT * DocGetPScale();
|
|
}
|
|
for (int k = nCloumn /2 + 1; k < (nTemp % nCloumn); ++k)
|
|
{
|
|
dOffset = dOffset + m_listCloumnWdith->GetAt(m_listCloumnWdith->FindIndex(k)) + 2 * m_dPtImageXOffet*DocGetPScale() + SPACE_LENGEND_IN * DocGetPScale();
|
|
}
|
|
temp.ptImage.x = (Wcs2Ucs(m_ptLocation).x + (dOffset + m_dPtImageXOffet*DocGetPScale()));
|
|
temp.ptImage.y = (Wcs2Ucs(m_ptLocation).y - m_dPtImageYOffet*DocGetPScale())-(i / nCloumn )*m_dPtImageYStepOffet*DocGetPScale();
|
|
temp.ptText.x = (Wcs2Ucs(m_ptLocation).x + (dOffset + SPACE_LENGEND_IN * DocGetPScale() + 2 * m_dPtImageXOffet*DocGetPScale()));
|
|
temp.ptText.y = (Wcs2Ucs(m_ptLocation).y-m_dptTextYOffet*DocGetPScale())-(i / nCloumn )*m_dptTextYStepOffet*DocGetPScale();
|
|
temp.ptImage = Ucs2Wcs(temp.ptImage);
|
|
temp.ptText = Ucs2Wcs(temp.ptText);
|
|
}
|
|
m_vecCoordinateData.push_back(temp);
|
|
}
|
|
}
|
|
else//偶数排
|
|
{
|
|
for (int i=0;i<iSize;i++)
|
|
{
|
|
nTemp = i;
|
|
COORDINATEDATA temp;
|
|
double dOffset = SPACE_LENGEND_OUT * DocGetPScale();
|
|
if (nTemp >= nCloumn)
|
|
{
|
|
nTemp = nTemp % nCloumn;
|
|
}
|
|
if ((nTemp % nCloumn) < (nCloumn / 2))
|
|
{
|
|
for (int n = (nCloumn / 2) -1 ; n >= (nTemp % (2 * nCloumn)); --n)
|
|
{
|
|
dOffset += m_listCloumnWdith->GetAt(m_listCloumnWdith->FindIndex(n)) + SPACE_LENGEND_IN * DocGetPScale();
|
|
}
|
|
for (int k = 0; k < ((nCloumn / 2) - nTemp -1); ++k)
|
|
{
|
|
dOffset = dOffset + 2 * m_dPtImageXOffet*DocGetPScale() + 2 * SPACE_LENGEND_OUT * DocGetPScale();
|
|
}
|
|
temp.ptImage.x = (Wcs2Ucs(m_ptLocation).x - (dOffset + m_dPtImageXOffet*DocGetPScale()));
|
|
temp.ptImage.y = (Wcs2Ucs(m_ptLocation).y - m_dPtImageYOffet*DocGetPScale())-(i / nCloumn )*m_dPtImageYStepOffet*DocGetPScale();
|
|
temp.ptText.x = (Wcs2Ucs(m_ptLocation).x - ( dOffset - SPACE_LENGEND_IN * DocGetPScale()));
|
|
temp.ptText.y = (Wcs2Ucs(m_ptLocation).y-m_dptTextYOffet*DocGetPScale())-(i / nCloumn )*m_dptTextYStepOffet*DocGetPScale();
|
|
temp.ptImage = Ucs2Wcs(temp.ptImage);
|
|
temp.ptText = Ucs2Wcs(temp.ptText);
|
|
}
|
|
else
|
|
{
|
|
for (int n = nCloumn /2; n < (nTemp % nCloumn); ++n)
|
|
{
|
|
dOffset += m_listCloumnWdith->GetAt(m_listCloumnWdith->FindIndex(n)) + 2 * SPACE_LENGEND_OUT * DocGetPScale();
|
|
}
|
|
for (int k = 0; k < ((nTemp % nCloumn) - (nCloumn / 2)); ++k)
|
|
{
|
|
dOffset = dOffset + 2 * m_dPtImageXOffet*DocGetPScale() + SPACE_LENGEND_IN * DocGetPScale();
|
|
}
|
|
temp.ptImage.x = (Wcs2Ucs(m_ptLocation).x + (dOffset + m_dPtImageXOffet*DocGetPScale()));
|
|
temp.ptImage.y = (Wcs2Ucs(m_ptLocation).y - m_dPtImageYOffet*DocGetPScale())-(i / nCloumn )*m_dPtImageYStepOffet*DocGetPScale();
|
|
temp.ptText.x = (Wcs2Ucs(m_ptLocation).x+(dOffset + SPACE_LENGEND_IN * DocGetPScale() + 2 * m_dPtImageXOffet*DocGetPScale()));
|
|
temp.ptText.y = (Wcs2Ucs(m_ptLocation).y-m_dptTextYOffet*DocGetPScale())-(i / nCloumn)*m_dptTextYStepOffet*DocGetPScale();
|
|
temp.ptImage = Ucs2Wcs(temp.ptImage);
|
|
temp.ptText = Ucs2Wcs(temp.ptText);
|
|
}
|
|
m_vecCoordinateData.push_back(temp);
|
|
}
|
|
}
|
|
}
|