420 lines
11 KiB
C++
420 lines
11 KiB
C++
// XText.cpp: implementation of the XText class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "XText.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static TCHAR THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
XText::XText()
|
|
{
|
|
|
|
}
|
|
|
|
XText::XText(const TCHAR* szText, XPoint ptPosition, double nHeight, double nScale, CString csTextStyle, CString csLayer)
|
|
{
|
|
xg_setvar(_T("TEXTSTYLE"), (const TCHAR*)csTextStyle);
|
|
AcDbObjectId idTextStyle = GetTextStyleId(csTextStyle);
|
|
m_ptInsert = ptPosition;
|
|
m_pText = new AcDbText;
|
|
|
|
m_pText->setPosition(ptPosition);
|
|
m_pText->setHeight(nHeight);
|
|
m_pText->setRotation(0);
|
|
m_pText->setTextString(szText);
|
|
m_pText->setTextStyle(idTextStyle);
|
|
m_pText->setWidthFactor(nScale);
|
|
/*CString strText = szText;
|
|
int nLen = strText.GetLength();
|
|
int i=0;
|
|
for (i=0;i<nLen;i++)
|
|
{
|
|
TCHAR ch = strText.GetAt(i);
|
|
}*/
|
|
CString szTemp(szText);
|
|
if(szTemp.Find(_T("\n"))>=0||szTemp.Find(_T("\r"))>=0)
|
|
{
|
|
TDbMText *pMText=new TDbMText;
|
|
pMText->SetLineSpace(1);
|
|
pMText->SetAlignment(XExplodeDraw::kLeft);
|
|
m_pTgText=pMText;
|
|
m_pTgText->SetStyleId(idTextStyle);
|
|
m_pTgText->SetHeight(nHeight/DocGetPScale());
|
|
m_pTgText->SetText(szText);
|
|
m_pTgText->SetLocation(ptPosition);
|
|
XPoint ptMin,ptMax;
|
|
if(pMText->GetExtents2d(ptMin,ptMax)==Acad::eOk)
|
|
{
|
|
//ptMin = Wcs2Ucs(ptMin);
|
|
//ptMax = Wcs2Ucs(ptMax);
|
|
double width=ptMax.x-ptMin.x+100;
|
|
pMText->SetPageWidth(width,FALSE);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_pTgText = new TDbText;
|
|
m_pTgText->SetStyleId(idTextStyle);
|
|
m_pTgText->SetHeight(nHeight/DocGetPScale());
|
|
m_pTgText->SetText(szText);
|
|
m_pTgText->SetLocation(ptPosition);
|
|
}
|
|
|
|
m_csLayer = csLayer;
|
|
m_nScale = nScale;
|
|
m_nTextLength = 0.0;
|
|
m_nRotate = 0.0;
|
|
}
|
|
|
|
XText::XText(Entity ent, BOOL bNew)
|
|
{
|
|
m_pTgText = NULL;
|
|
m_pText = NULL;
|
|
if(ent.Is(_T("TEXT"))){
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbText, pEnt);
|
|
if(pEnt){
|
|
m_idStyle = pEnt->textStyle();
|
|
m_nScale = pEnt->widthFactor();
|
|
m_nRotate = pEnt->rotation();
|
|
m_nHeight = pEnt->height();
|
|
m_vertMode = pEnt->verticalMode();
|
|
m_horzMode = pEnt->horizontalMode();
|
|
m_ptInsert = pEnt->position();
|
|
TCHAR *chlayer = pEnt->layer();
|
|
m_csLayer = chlayer;
|
|
delete [] chlayer;
|
|
TCHAR* pval = pEnt->textString();
|
|
m_csText = (const TCHAR*)pval;
|
|
delete[] pval;
|
|
}
|
|
OPENOBJ_END();
|
|
if(bNew){
|
|
m_pText = new AcDbText;
|
|
m_pText->setVerticalMode(m_vertMode);
|
|
m_pText->setHorizontalMode(m_horzMode);
|
|
m_pText->setLayer(m_csLayer);
|
|
m_pText->setPosition(m_ptInsert);
|
|
m_pText->setHeight(m_nHeight);
|
|
m_pText->setRotation(m_nRotate);
|
|
m_pText->setTextString(m_csText);
|
|
m_pText->setTextStyle(m_idStyle);
|
|
}
|
|
}
|
|
else if(ent.Is(_T("ATS_TEXT")))
|
|
{
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbText, pEnt);
|
|
if(pEnt)
|
|
{
|
|
m_idStyle = pEnt->GetStyleId();
|
|
m_nRotate = pEnt->GetRotation();
|
|
m_nHeight = pEnt->GetHeight();
|
|
m_Align = pEnt->GetAlignment();
|
|
m_csText = (const TCHAR*)pEnt->GetText();
|
|
m_ptInsert = pEnt->GetLocation();
|
|
m_csLayer = (const TCHAR*)pEnt->layer();
|
|
TCHAR *chlayer = pEnt->layer();
|
|
m_csLayer = chlayer;
|
|
delete [] chlayer;
|
|
}
|
|
OPENOBJ_END();
|
|
if(bNew)
|
|
{
|
|
m_pTgText = new TDbText;
|
|
m_pTgText->setLayer(m_csLayer);
|
|
m_pTgText->SetStyleId(m_idStyle);
|
|
m_pTgText->SetHeight(m_nHeight);
|
|
m_pTgText->SetAlignment(m_Align);
|
|
m_pTgText->SetRotation(m_nRotate);
|
|
m_pTgText->SetText(m_csText);
|
|
m_pTgText->SetLocation(m_ptInsert);
|
|
}
|
|
}
|
|
else if (ent.Is(_T("ATS_MTEXT")))
|
|
{
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbMText, pEnt);
|
|
if(pEnt)
|
|
{
|
|
m_idStyle = pEnt->GetStyleId();
|
|
m_nRotate = pEnt->GetRotation();
|
|
m_nHeight = pEnt->GetHeight();
|
|
m_Align = pEnt->GetAlignment();
|
|
m_csText = (const TCHAR*)pEnt->GetText();
|
|
m_ptInsert = pEnt->GetLocation();
|
|
m_csLayer = (const TCHAR*)pEnt->layer();
|
|
TCHAR *chlayer = pEnt->layer();
|
|
m_csLayer = chlayer;
|
|
delete [] chlayer;
|
|
}
|
|
OPENOBJ_END();
|
|
if(bNew)
|
|
{
|
|
TDbMText *pMText=new TDbMText;
|
|
pMText->SetLineSpace(1);
|
|
pMText->SetAlignment(XExplodeDraw::kLeft);
|
|
m_pTgText = pMText;
|
|
m_pTgText->setLayer(m_csLayer);
|
|
m_pTgText->SetStyleId(m_idStyle);
|
|
m_pTgText->SetHeight(m_nHeight);
|
|
m_pTgText->SetAlignment(m_Align);
|
|
m_pTgText->SetRotation(m_nRotate);
|
|
m_pTgText->SetText(m_csText);
|
|
m_pTgText->SetLocation(m_ptInsert);
|
|
}
|
|
}
|
|
}
|
|
|
|
XText::~XText()
|
|
{
|
|
if(m_pText)
|
|
m_pText->close();
|
|
if(m_pTgText)
|
|
m_pTgText->close();
|
|
}
|
|
|
|
|
|
void XText::Draw(AcDb::TextVertMode vVerMode, AcDb::TextHorzMode nHorzMode)
|
|
{
|
|
InitLayer(m_csLayer);
|
|
XPushVarStr clayer(_T("LAYER"), m_csLayer);
|
|
m_pText->setVerticalMode(vVerMode);
|
|
m_pText->setHorizontalMode(nHorzMode);
|
|
m_pText->setPosition(m_ptInsert);
|
|
m_pText->setAlignmentPoint(m_ptInsert);
|
|
m_pText->setLayer(m_csLayer);
|
|
AddToCurrentSpace(m_pText, Adesk::kTrue);
|
|
|
|
m_pText = NULL;
|
|
Entity ent;
|
|
ent.GetLast();
|
|
XPoint ptLow, ptUp;
|
|
ent.GetExtend(ptLow, ptUp);
|
|
m_nTextLength = fabs(ptLow[0] - ptUp[0]);
|
|
}
|
|
|
|
void XText::TgDraw(XExplodeDraw::TextAlignment Align)
|
|
{
|
|
InitLayer(m_csLayer);
|
|
if(!m_pTgText->isKindOf(TDbMText::desc()))//多行文字不变
|
|
m_pTgText->SetAlignment(Align);
|
|
m_pTgText->setLayer(m_csLayer);
|
|
AddToModelSpace(m_pTgText, Adesk::kTrue);
|
|
m_pTgText = NULL;
|
|
}
|
|
|
|
double XText::GetEntTextLength()
|
|
{
|
|
AcDbExtents extents;
|
|
if(m_pText){
|
|
m_pText->getGeomExtents(extents);
|
|
AcGePoint3d pMax = extents.maxPoint();
|
|
AcGePoint3d pMin = extents.minPoint();
|
|
double nTextLength = fabs(pMax[0] - pMin[0]);
|
|
return nTextLength * m_nScale;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
void XText::SetInsertPoint(XPoint ptIns)
|
|
{
|
|
m_ptInsert = ptIns;
|
|
if(m_pText){
|
|
m_pText->setPosition(ptIns);
|
|
m_pText->setAlignmentPoint(ptIns);
|
|
}
|
|
if(m_pTgText)
|
|
m_pTgText->SetLocation(ptIns);
|
|
};
|
|
|
|
void XText::SetText(const TCHAR* szText)
|
|
{
|
|
m_csText = szText;
|
|
if(m_pText)
|
|
m_pText->setTextString(m_csText);
|
|
if(m_pTgText)
|
|
m_pTgText->SetText(m_csText);
|
|
}
|
|
|
|
void XText::SetHeight(double nHeight)
|
|
{
|
|
m_nHeight = nHeight;
|
|
if(m_pText)
|
|
m_pText->setHeight(m_nHeight);
|
|
if(m_pTgText)
|
|
m_pTgText->SetHeight(m_nHeight/DocGetPScale());
|
|
}
|
|
|
|
void XText::SetRotate(double nRotate)
|
|
{
|
|
m_nRotate = nRotate;
|
|
if(m_pText)
|
|
m_pText->setRotation(m_nRotate);
|
|
if(m_pTgText)
|
|
{
|
|
m_pTgText->SetLayoutRotation(m_nRotate);
|
|
}
|
|
//m_pTgText->SetRotation(m_nRotate);
|
|
}
|
|
|
|
|
|
BOOL SetLayer0UnLocked()
|
|
{
|
|
AcDbLayerTable *pLayertable = NULL;
|
|
AcDbLayerTableRecord *pLayerRec = NULL;
|
|
acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead);
|
|
if(!pLayertable)
|
|
return FALSE;
|
|
|
|
if((pLayertable->getAt(_T("0"), pLayerRec, AcDb::kForRead)) == Acad::eOk) {
|
|
if(pLayerRec->isLocked() && pLayerRec->upgradeOpen()==Acad::eOk) {
|
|
pLayerRec->setIsLocked(false); // 关
|
|
pLayerRec->downgradeOpen();
|
|
}
|
|
pLayerRec->close();
|
|
}
|
|
pLayertable->close();
|
|
return TRUE;
|
|
}
|
|
void SetBlkAttrHeight(Entity entBlk, const TCHAR*szTag, double nHeight)
|
|
{
|
|
SetLayer0UnLocked();
|
|
AcDbBlockReference *pBlockRef = NULL;// 定义块表指针
|
|
AcDbObjectId eId;
|
|
acdbGetObjectId(eId, entBlk);
|
|
acdbOpenObject(pBlockRef, eId, AcDb::kForRead);
|
|
if(!pBlockRef)
|
|
return;
|
|
AcDbObjectIterator *pIterator;
|
|
pIterator = pBlockRef -> attributeIterator();
|
|
for (pIterator -> start(); !pIterator -> done(); pIterator -> step())
|
|
{
|
|
//遍历块中实体
|
|
AcDbObjectId att_id;
|
|
att_id = pIterator -> objectId();
|
|
AcDbEntity *pEnt;
|
|
AcDbAttribute *pAtt;
|
|
acdbOpenAcDbEntity(pEnt, att_id, AcDb::kForWrite);
|
|
pAtt = AcDbAttribute::cast(pEnt);
|
|
if(pAtt != NULL)
|
|
{
|
|
TCHAR *cname = pAtt->tag();//得到标记
|
|
if(_tcsicmp(cname, szTag) == 0){
|
|
pAtt->setHeight(nHeight*DocGetPScale());
|
|
}
|
|
delete[] cname;
|
|
}
|
|
pEnt->close();
|
|
}
|
|
delete pIterator;
|
|
pBlockRef->close();
|
|
}
|
|
//COMMAND 统一字高
|
|
void EqualTextHeight()
|
|
{
|
|
RBList rbMask = ads_buildlist( -4, _T("<or"), RTDXF0, _T("ATS_TEXT"),
|
|
RTDXF0, _T("ATS_MTEXT"),
|
|
RTDXF0, _T("ATS_PIPEMULTDIM"),
|
|
RTDXF0, _T("TEXT"),
|
|
RTDXF0, _T("INSERT"), 8, _T("DIM*"), 2, _T("$TelecSys$*"),
|
|
RTDXF0, _T("ATS_PIPE"),
|
|
RTDXF0, _T("ATS_ARROW"),
|
|
RTDXF0, _T("ATS_PIPETEXT"),
|
|
RTDXF0, _T("ATS_EQUIPDIM"),
|
|
RTDXF0, _T("ATS_WIREDIM2"),
|
|
RTDXF0, _T("ATS_WIREDIM"), -4, _T("or>"), NULL);
|
|
PickSet ss(SS_FREE);
|
|
if(SelectEntities(_T("\n请选择要修改的文字(ACAD文字,上华文字)<退出>"), ss, rbMask) != RTNORM)
|
|
return;
|
|
double nHeight(3.5);
|
|
ads_getreal(_T("\n字高() <3.5mm>"), &nHeight);
|
|
if(nHeight > 20){
|
|
AfxMessageBox(_T("输入字高太大了!应为实际出图字高"));
|
|
return;
|
|
}
|
|
|
|
long len = ss.Length();
|
|
for(long i=0;i<len;i++){
|
|
Entity ent = ss[i];
|
|
if(ent.Is(_T("ATS_TEXT"))){
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbText, pEnt);
|
|
if(pEnt){
|
|
pEnt->SetHeight(nHeight);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else if(ent.Is(_T("ATS_PIPETEXT"))){
|
|
ent.SetData(140, nHeight);
|
|
ent.Modify();
|
|
}
|
|
else if(ent.Is(_T("ATS_PIPEMULTDIM"))){
|
|
ent.SetData(40, nHeight);
|
|
ent.Modify();
|
|
}
|
|
else if(ent.Is(_T("ATS_PIPE"))){
|
|
ent.SetData(141, nHeight);
|
|
ent.Modify();
|
|
}
|
|
else if(ent.Is(_T("ATS_ARROW"))){
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbSymbArrow, pEnt);
|
|
if(pEnt){
|
|
pEnt->SetTextHeight(nHeight);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else if(ent.Is(_T("ATS_MTEXT"))){
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbMText, pEnt);
|
|
if(pEnt){
|
|
// sg add 090629,解决需求平台问题919,修改字高后,行间距系数,不应该改变
|
|
double dLineSpaceOld = pEnt->GetLineSpace(),
|
|
dHeightOld = pEnt->GetHeight();
|
|
pEnt->SetHeight(nHeight);
|
|
|
|
// sg add 090629,解决需求平台问题919,修改字高后,行间距系数,不应该改变
|
|
double dLineSpaceNew = dLineSpaceOld*nHeight/dHeightOld;
|
|
pEnt->SetLineSpace(dLineSpaceNew);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else if(ent.Is(_T("TEXT"))){
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, AcDbText, pEnt);
|
|
if(pEnt){
|
|
pEnt->setHeight(nHeight*DocGetPScale());
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else if(ent.Is(_T("ATS_EQUIPDIM"))){
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, CLampDim, pEnt);
|
|
if(pEnt){
|
|
pEnt->SetTextHeight(nHeight*DocGetPScale());
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else if(ent.Is(_T("ATS_WIREDIM2"))){
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, CMutiWireDim, pEnt);
|
|
if(pEnt){
|
|
pEnt->SetTextHeight(nHeight*DocGetPScale());
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else if(ent.Is(_T("ATS_WIREDIM"))){
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, CWireDim, pEnt);
|
|
if(pEnt){
|
|
pEnt->SetTextHeight(nHeight*DocGetPScale());
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else if(ent.Is(_T("INSERT"))){
|
|
SetBlkAttrHeight(ent, _T("N"), nHeight);
|
|
}
|
|
}
|
|
} |