Files
envi-code/SourceCode/Code2026/tg_shs/shs_siteplan/LayoutLegendCmd.cpp
T
2026-09-28 15:28:50 +08:00

234 lines
4.5 KiB
C++

#include "StdAfx.h"
#include "LayoutLegendDlg.h"
#include "TDbLayoutLegend.h"
class TDbLayoutLegendJig:public AcEdJig
{
public:
TDbLayoutLegendJig(TDbLayoutLegend *pLegend,TCHAR *pszPormat,TCHAR *pszKeyWord);
~TDbLayoutLegendJig();
virtual AcEdJig::DragStatus sampler();
virtual Adesk::Boolean update();
virtual AcDbEntity* entity() const;
AcEdJig::DragStatus doIt();
void SetOffetPt(AcGePoint3d &pt);
private:
TDbLayoutLegend *m_pLegend; //
AcGePoint3d m_ptCur; //鼠标当前坐标
AcGeVector3d m_vecOffet; //基点偏移向量
AcGePoint3d m_ptLast;
TCHAR *m_pszPormat; //提示语
TCHAR *m_pszKeyWord; //关键字
};
TDbLayoutLegendJig::TDbLayoutLegendJig(TDbLayoutLegend *pLegend,TCHAR *pszPormat,TCHAR *pszKeyWord):
m_pLegend(pLegend),
m_ptCur(0,0,0),
m_vecOffet(0,0,0),
m_ptLast(0,0,0),
m_pszPormat(pszPormat),
m_pszKeyWord(pszKeyWord)
{
}
TDbLayoutLegendJig::~TDbLayoutLegendJig()
{
}
AcEdJig::DragStatus TDbLayoutLegendJig::doIt()
{
AcEdJig::DragStatus status =AcEdJig::kNull;
setDispPrompt(m_pszPormat);
try
{
INITGET_BEG(0,m_pszKeyWord);
status = drag();
INITGET_END();
}
catch(...)
{
status = AcEdJig::kCancel;
}
return status;
}
AcEdJig::DragStatus TDbLayoutLegendJig::sampler()
{
setUserInputControls((UserInputControls)(AcEdJig::kAccept3dCoordinates|
AcEdJig::kNullResponseAccepted));
AcEdJig::DragStatus status =AcEdJig::kCancel;
setKeywordList(m_pszKeyWord);
status = acquirePoint(m_ptCur);
if (status == AcEdJig::kNormal)
{
if (m_ptCur.isEqualTo(m_ptLast))
{
return AcEdJig::kNoChange;
}
}
m_ptLast = m_ptCur;
return status;
}
Adesk::Boolean TDbLayoutLegendJig::update()
{
AcGePoint3d ptNew = m_ptCur - m_vecOffet;
m_pLegend->SetLocation(ptNew);
return Adesk::kTrue;
}
AcDbEntity * TDbLayoutLegendJig::entity() const
{
return(m_pLegend);
}
void TDbLayoutLegendJig::SetOffetPt(AcGePoint3d &pt)
{
m_vecOffet =pt-m_ptCur;
}
//////////////////////////////////////////////////////////////
//
// 命令函数:总平图例
//
//////////////////////////////////////////////////////////////
void LayoutLegendCmd()
{
ClayoutLegendDlg dlg;
if(dlg.DoModal() != IDOK)
{
return;
}
if (dlg.GetSize() <= 0 )
{
return;
}
//临时数据对象
CString sBlockName;
CString sText;
TDbLayoutLegend *pEnt = new TDbLayoutLegend;
CList<double> clistTextWidth;
int nCloumn = dlg.GetCloumnNum();
for (int i=0; i<dlg.GetSize(); ++i)
{
sBlockName.Format(_T("总图图例(%s)"), dlg[i].sDrawing);
sText = dlg[i].sItem;
pEnt->Push_Back(sBlockName.GetBuffer(sBlockName.GetLength()),sText.GetBuffer(sText.GetLength()));
sText.ReleaseBuffer();
TDbText text;
text.SetText(sText);
text.SetHeight(2.5);
text.SetLocation(TADSGePoint3d(0, 0, 0));
text.SetStyleId(acdbCurDwg()->textstyle());
XPoint ptEx = text.GetExtents();
int nNum = i % nCloumn;
if (clistTextWidth.FindIndex(nNum))
{
if (ptEx.x > clistTextWidth.GetAt(clistTextWidth.FindIndex(nNum)))
{
clistTextWidth.SetAt(clistTextWidth.FindIndex(nNum), ptEx.x);
}
}
else
{
clistTextWidth.AddTail(ptEx.x);
}
}
//添加到模型空间标志
bool bFlag = false;
pEnt->SetCloumnWidth(&clistTextWidth);
//JIG效果
TDbLayoutLegendJig jig(pEnt,(LPTSTR)_T("\n点取图例位置或[改基点(T)]<退出>:"),(LPTSTR)_T("T"));
while (true)
{
AcEdJig::DragStatus status = jig.doIt();
if(status == AcEdJig::kKW1)//改基点
{
//创建临时对象,作为改选基点参考
TDbLayoutLegend *pIns = new TDbLayoutLegend;
pIns->CopyPropertiesFrom(pEnt,AcDbMatchProperties::kSetAllFlagsOn);
AcDbObjectId idTemp = AddToModelSpace(pIns);
if (idTemp.isValid())
{
XPoint pt;
int rt=XGetPoint(NULL, _T("\n输入插入点"),pt);
//删除临时对象
OPENOBJ_BEGIN(idTemp, AcDb::kForWrite, AcDbEntity, pEntRemove);
if(pEntRemove)
{
pEntRemove->erase();
}
OPENOBJ_END();
if(rt==RTNORM)
{
pt=Ucs2Wcs(pt);
jig.SetOffetPt(pt);
}
else if (rt == RTCAN)//退出
{
break;
}
else//空格、右键、回车
{
continue;
}
}
else
{
delete pIns;
}
}
else if (status == AcEdJig::kNormal)
{
bFlag = true;
break;
}
else
{
break;
}
}//end of true
if (bFlag)
{
//炸开
AcDbVoidPtrArray entitySet;
AcDbObjectId idLayer = InitLayer(LAY_TEXT);
if(pEnt->explode(entitySet) == Acad::eOk)
{
for (int i=0;i<entitySet.length();i++)
{
AcDbObjectId id = AddToModelSpace((AcDbEntity*)entitySet[i]);
//设置图层
OPENOBJ_BEGIN(id,AcDb::kForWrite,AcDbEntity,pObj);
if (pObj)
{
pObj->setLayer(idLayer);
}
OPENOBJ_END();
}
}
}
delete pEnt;
}