1128 lines
28 KiB
C++
1128 lines
28 KiB
C++
#include "stdafx.h"
|
||
#include "dbsymbolAnnotate.h"
|
||
#include "tsuperlist.h"
|
||
#include "SubText.h"
|
||
#include "XPushMemVar.h"
|
||
#include "XGeLibInc.h"
|
||
#include "dbtext.h"
|
||
|
||
static double g_nArrowLen=3.0;
|
||
static double g_nArrowWidth=0.8;
|
||
BOOL g_bDynamicCoord = TRUE;
|
||
|
||
//extern BOOL g_bLayoutRotate;
|
||
int g_nCutLineColor = 1;
|
||
BOOL g_bQuickDragMText = TRUE;
|
||
|
||
double g_dElevTextBaseLen = 16.0;
|
||
BOOL g_bElevFloorsOnRight = TRUE;
|
||
|
||
double g_dIndexPointerDia = 10;
|
||
|
||
double g_dSymbDrawingIndexDia = 14;
|
||
|
||
double g_dSectionSegLocLength = 10;
|
||
double g_dSectionSegDirLength = 6;
|
||
|
||
|
||
/////////////////////////////////////////////////////////////
|
||
// 符号标注类
|
||
/////////////////////////////////////////////////////////////
|
||
// ver:1-AEC5;2-AEC6;3,AEC7-3
|
||
|
||
#define LAY_TEXT _T("0")
|
||
|
||
const Adesk::UInt8 AecDbSymbWithText::g_nVersion = 3;
|
||
|
||
ACRX_NO_CONS_DEFINE_MEMBERS(AecDbSymbWithText, AecEntity);
|
||
|
||
//IMPLEMENT_XENTBASE(AecDbSymbWithText);
|
||
|
||
AecDbSymbWithText::AecDbSymbWithText()
|
||
{
|
||
m_nTextHeight = 3.5;
|
||
m_nTextRotation = 0.0;
|
||
m_colorText = 7;
|
||
}
|
||
|
||
AecDbSymbWithText::~AecDbSymbWithText()
|
||
{
|
||
}
|
||
|
||
//{ &LAY_OTHER_DIM , _T("符号"), _T("DIM_SYMB"), 3},
|
||
const TCHAR* AecDbSymbWithText::GetDefaultLayer()const
|
||
{
|
||
return _T("0");
|
||
}
|
||
|
||
BOOL AecDbSymbWithText::IsValid() const
|
||
{
|
||
BOOL bRet = AecEntity::IsValid();
|
||
if (!bRet)
|
||
return bRet;
|
||
bRet = (m_nTextHeight>1.0E-3 && !!m_idTextStyle);
|
||
return bRet;
|
||
}
|
||
|
||
// 提供对格式刷的支持
|
||
void AecDbSymbWithText::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
|
||
{
|
||
assertWriteEnabled();
|
||
AecEntity::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
|
||
AecDbSymbWithText *pSrc=AecDbSymbWithText::cast(pSrcEntity);
|
||
if (pSrc)
|
||
{
|
||
if (database()==NULL||
|
||
pSrcEntity->database()==NULL||
|
||
database()==pSrcEntity->database()) // add by aec on 060317
|
||
{
|
||
m_idTextStyle = pSrc->m_idTextStyle;
|
||
m_idTextLayer = pSrc->m_idTextLayer;
|
||
}
|
||
m_nTextHeight = pSrc->m_nTextHeight; // 第一端线距离端点, 第二端线距离第一端线
|
||
m_nTextRotation = pSrc->m_nTextRotation;
|
||
m_colorText=pSrc->m_colorText;
|
||
}
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecDbSymbWithText::DownGradeSave(int nDrawMode, AcDbVoidPtrArray &entSet, BOOL *bErase)
|
||
{
|
||
if (g_nSaveTArchVer < 7) // 7.0开始才有圆圈文字
|
||
{
|
||
BOOL bHasCircle = FALSE;
|
||
long num = GetSubTextNum();
|
||
for(long i=0; i<num; i++)
|
||
{
|
||
SubText* pSubText = GetSubText(i);
|
||
if (pSubText != NULL)
|
||
{
|
||
CString sText = pSubText->GetText();
|
||
delete pSubText;
|
||
if (sText.Find(_T("^C")) != -1)
|
||
{
|
||
bHasCircle = TRUE;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (bHasCircle)
|
||
{
|
||
XPushMemVar<BOOL> vTemp(XExplodeStream::m_bFullExplode, TRUE); // 完全分解
|
||
XExplodeStream dc(entSet);
|
||
if (!OnExplodeOrDraw(dc)) // aec add 090303,解决导出后,无遮挡关系的BUG
|
||
return Acad::eOk;
|
||
|
||
dc.SetPropertiesFrom(this);
|
||
Acad::ErrorStatus es = Acad::eOk;
|
||
if (nDrawMode == DRAW_2D)
|
||
es = ExplodeOrDraw2d(dc);
|
||
else
|
||
es = ExplodeOrDraw3d(dc);
|
||
if (bErase)
|
||
*bErase = TRUE;
|
||
return es;
|
||
}
|
||
}
|
||
return AecEntity::DownGradeSave(nDrawMode, entSet, bErase);
|
||
}
|
||
|
||
// 从DWG读入数据:
|
||
Acad::ErrorStatus AecDbSymbWithText::dwgInFields (AcDbDwgFiler* pFiler)
|
||
{
|
||
assertWriteEnabled();
|
||
Acad::ErrorStatus es = AecEntity::dwgInFields(pFiler);
|
||
if (es != Acad::eOk)
|
||
return es;
|
||
Adesk::UInt8 nVer;
|
||
pFiler->readItem(&nVer);
|
||
|
||
if (nVer>g_nVersion) { // Version is too new
|
||
return Acad::eMakeMeProxy;
|
||
}
|
||
|
||
pFiler->readItem(&m_idTextStyle);
|
||
pFiler->readItem(&m_nTextHeight);
|
||
|
||
if (nVer > 1)
|
||
{
|
||
pFiler->readItem(&m_nTextRotation);
|
||
pFiler->readItem(&m_idTextLayer);
|
||
}
|
||
else
|
||
{
|
||
m_nTextRotation = 0.0;
|
||
if (database() == acdbCurDwg())
|
||
m_idTextLayer = InitLayer(LAY_TEXT, FALSE);
|
||
else
|
||
m_idTextLayer = GetLayerIdFromString(LAY_TEXT, database());
|
||
}
|
||
|
||
if (nVer>2)
|
||
pFiler->readItem(&m_colorText);
|
||
else
|
||
{
|
||
m_colorText = 7; // aec add 090608,对于7以前的图纸,默认使用白色
|
||
}
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbSymbWithText::dwgOutFields(AcDbDwgFiler* pFiler) const
|
||
{
|
||
assertReadEnabled();
|
||
Acad::ErrorStatus es = AecEntity::dwgOutFields(pFiler);
|
||
if (es != Acad::eOk)
|
||
return es;
|
||
|
||
if (g_nSaveTArchVer == 5)
|
||
pFiler->writeItem((Adesk::UInt8)1);
|
||
else if(g_nSaveTArchVer == 6)
|
||
pFiler->writeItem((Adesk::UInt8)2);
|
||
else
|
||
pFiler->writeItem(g_nVersion);
|
||
|
||
pFiler->writeItem(m_idTextStyle);
|
||
pFiler->writeItem(m_nTextHeight);
|
||
if (g_nSaveTArchVer > 5)
|
||
{
|
||
pFiler->writeItem(m_nTextRotation);
|
||
pFiler->writeItem(m_idTextLayer);
|
||
}
|
||
|
||
if (g_nSaveTArchVer > 6)
|
||
pFiler->writeItem(m_colorText);
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbSymbWithText::dxfInFields (AcDbDxfFiler* pFiler)
|
||
{
|
||
assertWriteEnabled();
|
||
Acad::ErrorStatus es = AecEntity::dxfInFields(pFiler);
|
||
if (es != Acad::eOk)
|
||
return es;
|
||
if (!pFiler->atSubclassData(_T("AecDbSymbWithText"))) {
|
||
return Acad::eBadDxfSequence;
|
||
}
|
||
|
||
XString sName, sTextLayer;
|
||
double nHeight;
|
||
double nAng;
|
||
Adesk::UInt32 fieldsFlags = 0;
|
||
resbuf rb;
|
||
while ((es == Acad::eOk)
|
||
&& ((es = pFiler->readResBuf(&rb)) == Acad::eOk))
|
||
{
|
||
switch (rb.restype) {
|
||
case AcDb::kDxfTextStyleName:
|
||
sName=rb.resval.rstring;
|
||
fieldsFlags |= 0x01;
|
||
free(rb.resval.rstring);
|
||
break;
|
||
case AcDb::kDxfReal:
|
||
fieldsFlags |= 0x02;
|
||
nHeight = rb.resval.rreal;
|
||
break;
|
||
case 52:
|
||
fieldsFlags |= 0x04;
|
||
nAng = rb.resval.rreal;
|
||
break;
|
||
case 410:
|
||
sTextLayer=rb.resval.rstring;
|
||
fieldsFlags |= 0x08;
|
||
free(rb.resval.rstring);
|
||
// fall through intentional
|
||
default:
|
||
// An unrecognized group. Push it back so that
|
||
// the subclass can read it again.
|
||
pFiler->pushBackItem();
|
||
es = Acad::eEndOfFile;
|
||
break;
|
||
}
|
||
}
|
||
|
||
// At this point the es variable must contain eEndOfFile
|
||
// - either from readResBuf() or from pushback. If not,
|
||
// it indicates that an error happened and we should
|
||
// return immediately.
|
||
//
|
||
if (es != Acad::eEndOfFile)
|
||
return Acad::eInvalidResBuf;
|
||
|
||
AcDbObjectId id;
|
||
if (fieldsFlags&0x01) {
|
||
id = XExport::GetTextStyleId(sName, database());
|
||
}
|
||
if (!id)
|
||
{
|
||
XString style;
|
||
xg_getvar(_T("TEXTSTYLE"), style);
|
||
m_idTextStyle = XExport::GetTextStyleId(style, database());
|
||
}
|
||
else
|
||
m_idTextStyle = id;
|
||
if (fieldsFlags&0x02)
|
||
m_nTextHeight = nHeight;
|
||
if (fieldsFlags&0x04)
|
||
m_nTextRotation = nAng;
|
||
if (fieldsFlags&0x08)
|
||
m_idTextLayer = XExport::GetLayerIdFromString(sTextLayer, database());
|
||
return Acad::eOk;
|
||
// 不读入任何数据
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbSymbWithText::dxfOutFields(AcDbDxfFiler* pFiler) const
|
||
{
|
||
assertReadEnabled();
|
||
Acad::ErrorStatus es=AecEntity::dxfOutFields(pFiler);
|
||
assert(es == Acad::eOk);
|
||
|
||
es = pFiler->writeItem(AcDb::kDxfSubclass,_T("AecDbSymbWithText"));
|
||
assert(es == Acad::eOk);
|
||
|
||
XString sName=GetSymbolName(m_idTextStyle);
|
||
// XString sLayer=GetSymbolName(m_idTextLayer);
|
||
// if (!sLayer)
|
||
// sLayer=_T("0");
|
||
pFiler->writeString(AcDb::kDxfTextStyleName, (const TCHAR *)sName); //7
|
||
pFiler->writeDouble(AcDb::kDxfReal, m_nTextHeight);
|
||
pFiler->writeDouble(52, m_nTextRotation);
|
||
pFiler->writeString(410, (const TCHAR *)LayerId2String(m_idTextLayer));
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecDbSymbWithText::subTransformBy(const AcGeMatrix3d& xform)
|
||
{
|
||
AecEntity::subTransformBy(xform);
|
||
if (!g_bLayoutRotate)
|
||
{
|
||
AcGeVector3d vt(cos(m_nTextRotation), sin(m_nTextRotation), 0.0);
|
||
vt.transformBy(xform);
|
||
m_nTextRotation = ads_angle(XPoint(), XPoint(vt[0], vt[1]));
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
AEntityBase::DrawType
|
||
AecDbSymbWithText::GetDrawType() const
|
||
{
|
||
return AEntityBase::k2DOnly;
|
||
}
|
||
|
||
double AecDbSymbWithText::GetTextHeight() const
|
||
{
|
||
return m_nTextHeight;
|
||
}
|
||
|
||
AcDbObjectId AecDbSymbWithText::GetTextStyleId() const
|
||
{
|
||
return m_idTextStyle;
|
||
}
|
||
|
||
AcDbObjectId AecDbSymbWithText::GetTextLayerId() const
|
||
{
|
||
return m_idTextLayer;
|
||
}
|
||
|
||
void AecDbSymbWithText::SetTextHeight(double nHeight)
|
||
{
|
||
assertWriteEnabled();
|
||
m_nTextHeight=nHeight;
|
||
}
|
||
|
||
void AecDbSymbWithText::SetTextStyleId(AcDbObjectId id)
|
||
{
|
||
assertWriteEnabled();
|
||
m_idTextStyle=id;
|
||
}
|
||
|
||
void AecDbSymbWithText::SetTextLayerId(AcDbObjectId id)
|
||
{
|
||
assertWriteEnabled();
|
||
m_idTextLayer=id;
|
||
}
|
||
|
||
void AecDbSymbWithText::SetTextRotation(double nRot)
|
||
{
|
||
assertWriteEnabled();
|
||
m_nTextRotation=CT_std_angle(nRot);
|
||
}
|
||
|
||
double AecDbSymbWithText::GetTextRotation() const
|
||
{
|
||
return m_nTextRotation;
|
||
}
|
||
|
||
const static Adesk::UInt8 g_nVersion;
|
||
|
||
ACRX_DXF_DEFINE_MEMBERS(AecDbSymbSection,AecDbSymbWithText, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
||
1, AEC_SYMB_SECTION,"AEC_KERNAL|缺乏图形解释器, 请下载插件");
|
||
IMPLEMENT_TENTBASE(AecDbSymbSection);
|
||
|
||
const Adesk::UInt8 AecDbSymbSection::g_nVersion = 1;
|
||
double AecDbSymbSection::g_nLineWidth=0.5;
|
||
double AecDbSymbSection::g_nSegLength=10.0;
|
||
|
||
AecDbSymbSection::AecDbSymbSection()
|
||
{
|
||
m_nTextHeight=5.0;
|
||
m_nViewDir=0.0;
|
||
m_bViewLine=TRUE;
|
||
}
|
||
|
||
AecDbSymbSection::~AecDbSymbSection()
|
||
{
|
||
}
|
||
|
||
BOOL AecDbSymbSection::IsValid() const
|
||
{
|
||
BOOL bRet=AecDbSymbWithText::IsValid();
|
||
if(!bRet)
|
||
return bRet;
|
||
bRet=(m_poly.Length()>1 && !m_poly.IsClosed());
|
||
return bRet;
|
||
}
|
||
|
||
|
||
Acad::ErrorStatus
|
||
AecDbSymbSection::subGetClassID(CLSID* pClsid) const
|
||
{
|
||
return Acad::eOk;
|
||
}
|
||
|
||
// 提供对格式刷的支持
|
||
void AecDbSymbSection::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
|
||
{
|
||
assertWriteEnabled();
|
||
AecDbSymbWithText::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
|
||
AecDbSymbSection *pSrc=AecDbSymbSection::cast(pSrcEntity);
|
||
if(pSrc) {
|
||
m_bViewLine=pSrc->m_bViewLine;
|
||
}
|
||
}
|
||
|
||
|
||
Acad::ErrorStatus
|
||
AecDbSymbSection::dwgInFields(AcDbDwgFiler* filer)
|
||
{
|
||
assertWriteEnabled();
|
||
Acad::ErrorStatus es=AecDbSymbWithText::dwgInFields(filer);
|
||
if(es!=Acad::eOk)
|
||
return es;
|
||
|
||
Adesk::Int8 version;
|
||
filer->readItem(&version);
|
||
if (version > g_nVersion + 1)//TG2014
|
||
return Acad::eMakeMeProxy;
|
||
|
||
filer->readItem(&m_bViewLine);
|
||
filer->readItem(&m_nViewDir);
|
||
Adesk::UInt8 nVertNum;
|
||
filer->readItem(&nVertNum);
|
||
m_poly.Reset();
|
||
for (Adesk::UInt8 i =0; i < nVertNum; i++){
|
||
XPoint pnt;
|
||
filer->readItem(&(AcGePoint2d &)pnt);
|
||
m_poly.AppendNode(pnt);
|
||
}
|
||
|
||
ReadString(filer, m_sText);
|
||
filer->readItem(&(AcGePoint2d &)m_ptText1);
|
||
filer->readItem(&(AcGePoint2d &)m_ptText2);
|
||
|
||
if (version > 1)
|
||
{
|
||
XString sText;
|
||
ReadString(filer,sText);
|
||
|
||
AcGePoint2d pt1,pt2;
|
||
filer->readItem(&pt1);
|
||
filer->readItem(&pt2);
|
||
|
||
double dVal = 0.0;
|
||
filer->readDouble(&dVal);
|
||
|
||
Adesk::UInt16 nVal;
|
||
filer->readUInt16(&nVal);
|
||
|
||
AcDbHardPointerId id;
|
||
filer->readHardPointerId(&id);
|
||
|
||
filer->readDouble(&dVal);
|
||
filer->readDouble(&dVal);
|
||
}
|
||
|
||
if (version > g_nVersion) //TG2014
|
||
{
|
||
m_ptText1 = GetDefaultTextLocation(0);
|
||
m_ptText2 = GetDefaultTextLocation(1);
|
||
}
|
||
|
||
return filer->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecDbSymbSection::dwgOutFields(AcDbDwgFiler* filer) const
|
||
{
|
||
assertReadEnabled();
|
||
VERIFY(AecDbSymbWithText::dwgOutFields(filer)==Acad::eOk);
|
||
|
||
|
||
filer->writeItem(g_nVersion);
|
||
filer->writeItem(m_bViewLine);
|
||
filer->writeItem(m_nViewDir);
|
||
|
||
Adesk::UInt8 vexLen=m_poly.Length();
|
||
filer->writeItem(vexLen);
|
||
for (Adesk::UInt8 i =0; i < vexLen; i++){
|
||
filer->writeItem((const AcGePoint2d &)m_poly[i]);
|
||
}
|
||
|
||
filer->writeItem((const TCHAR *)m_sText);
|
||
filer->writeItem((const AcGePoint2d &)m_ptText1);
|
||
filer->writeItem((const AcGePoint2d &)m_ptText2);
|
||
|
||
return filer->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecDbSymbSection::dxfInFields(AcDbDxfFiler* filer)
|
||
{
|
||
assertWriteEnabled();
|
||
|
||
Acad::ErrorStatus es = AecDbSymbWithText::dxfInFields(filer);
|
||
|
||
if (es != Acad::eOk) {
|
||
return es;
|
||
}
|
||
|
||
if (!filer->atSubclassData(_T("AecDbSymbSection"))) {
|
||
return Acad::eBadDxfSequence;
|
||
}
|
||
|
||
int fieldsFlags=0;
|
||
resbuf rb;
|
||
XPoint pt1, pt2;
|
||
XString sText;
|
||
int nFlag;
|
||
double nAng;
|
||
XPointList lstVertexes;
|
||
while ((es == Acad::eOk)
|
||
&& ((es = filer->readResBuf(&rb)) == Acad::eOk)) {
|
||
switch (rb.restype) {
|
||
case AcDb::kDxfInt16:
|
||
fieldsFlags |= 0x01;
|
||
nFlag=rb.resval.rint;
|
||
break;
|
||
case AcDb::kDxfAngle:
|
||
fieldsFlags |= 0x02;
|
||
nAng=rb.resval.rreal;
|
||
break;
|
||
case AcDb::kDxfText:
|
||
fieldsFlags |= 0x04;
|
||
sText=rb.resval.rstring;
|
||
free(rb.resval.rstring);
|
||
break;
|
||
case AcDb::kDxfXCoord+1:
|
||
fieldsFlags |= 0x08;
|
||
pt1=rb.resval.rpoint;
|
||
break;
|
||
case AcDb::kDxfXCoord+2:
|
||
fieldsFlags |= 0x10;
|
||
pt2=rb.resval.rpoint;
|
||
break;
|
||
case AcDb::kDxfXCoord:
|
||
fieldsFlags |= 0x20;
|
||
lstVertexes.Append(new XPoint(rb.resval.rpoint));
|
||
break;
|
||
default:
|
||
// An unrecognized group. Push it back so that
|
||
// the subclass can read it again.
|
||
filer->pushBackItem();
|
||
es = Acad::eEndOfFile;
|
||
break;
|
||
}
|
||
}
|
||
if (es != Acad::eEndOfFile)
|
||
return Acad::eInvalidResBuf;
|
||
if (!(fieldsFlags & 0x08)) {
|
||
filer->setError(Acad::eMissingDxfField,
|
||
_T("\nMissing DXF group code: 11"));
|
||
return Acad::eMissingDxfField;
|
||
}
|
||
if (!(fieldsFlags & 0x10)) {
|
||
filer->setError(Acad::eMissingDxfField,
|
||
_T("\nMissing DXF group code: 12"));
|
||
return Acad::eMissingDxfField;
|
||
}
|
||
if(lstVertexes.Length()<2) {
|
||
filer->setError(_T("\nError DXF group code: 10"));
|
||
return Acad::eMissingDxfField;
|
||
}
|
||
if(fieldsFlags&0x01)
|
||
m_bViewLine=nFlag;
|
||
if(fieldsFlags&0x02)
|
||
m_nViewDir=nAng;
|
||
if(fieldsFlags&0x04)
|
||
m_sText=sText;
|
||
m_ptText1=pt1;
|
||
m_ptText2=pt2;
|
||
|
||
m_poly.Reset();
|
||
lstVertexes.SetDelFlag(FALSE);
|
||
for(int i=0; i<lstVertexes.Length(); i++) {
|
||
m_poly.Append(lstVertexes[i]);
|
||
}
|
||
|
||
return filer->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecDbSymbSection::dxfOutFields(AcDbDxfFiler* filer) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AecDbSymbWithText::dxfOutFields(filer);
|
||
|
||
filer->writeItem(AcDb::kDxfSubclass, _T("AecDbSymbSection"));
|
||
|
||
filer->writeInt16(AcDb::kDxfInt16, (Adesk::Int16)m_bViewLine);
|
||
filer->writeDouble(AcDb::kDxfAngle, m_nViewDir);
|
||
filer->writeString(AcDb::kDxfText, m_sText);
|
||
|
||
filer->writePoint2d(AcDb::kDxfXCoord+1, m_ptText1.AsAcGePoint2d());
|
||
filer->writePoint2d(AcDb::kDxfXCoord+2, m_ptText2.AsAcGePoint2d());
|
||
|
||
for(int i=0; i<m_poly.Length(); i++) {
|
||
filer->writePoint2d(AcDb::kDxfXCoord, m_poly[i].AsAcGePoint2d());
|
||
}
|
||
return filer->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbSymbSection::ExplodeOrDraw2d(XExplodeDraw &dc) const
|
||
{
|
||
double tempLineWidth = g_nLineWidth*GetPScale();
|
||
|
||
// aec modify 110408,剖线方向、位置长度,都改成支持在高级选项中进行设置
|
||
// double tempSegLen = g_nSegLength*GetPScale();
|
||
double tempSegLen = g_dSectionSegLocLength*GetPScale(),
|
||
tempSegDirLen = g_dSectionSegDirLength*GetPScale();
|
||
|
||
int vexNum = m_poly.Length();
|
||
for (int i =0; i<vexNum; i++)
|
||
{
|
||
XPoint ptVert = m_poly[i];
|
||
XPoint ptPrev, ptNext;
|
||
BOOL bPrev = FALSE, bNext = FALSE;
|
||
if (i==0 && m_bViewLine)
|
||
{
|
||
// aec modify 110408,剖线方向、位置长度,都改成支持在高级选项中进行设置
|
||
// ads_polar(ptVert, m_nViewDir, 0.6*tempSegLen, ptPrev);
|
||
ads_polar(ptVert, m_nViewDir, tempSegDirLen, ptPrev);
|
||
bPrev=TRUE;
|
||
}
|
||
else if (i>0)
|
||
{
|
||
double nSegLen=min(tempSegLen, ptVert.Distance2d(m_poly[i-1])/2);
|
||
ads_polar(ptVert, ads_angle(ptVert, m_poly[i-1]), nSegLen, ptPrev);
|
||
bPrev=TRUE;
|
||
}
|
||
|
||
if (i==vexNum-1 && m_bViewLine)
|
||
{
|
||
// aec modify 110408,剖线方向、位置长度,都改成支持在高级选项中进行设置
|
||
// ads_polar(ptVert, m_nViewDir, 0.6*tempSegLen, ptNext);
|
||
ads_polar(ptVert, m_nViewDir, tempSegDirLen, ptNext);
|
||
bNext=TRUE;
|
||
}
|
||
else if (i<vexNum-1)
|
||
{
|
||
double nSegLen=min(tempSegLen, ptVert.Distance2d(m_poly[i+1])/2);
|
||
ads_polar(ptVert, ads_angle(ptVert, m_poly[i+1]), nSegLen, ptNext);
|
||
bNext=TRUE;
|
||
}
|
||
|
||
AcDbPolyline pline;
|
||
pline.setPropertiesFrom(this);
|
||
int nVert = 0;
|
||
if (bPrev)
|
||
{
|
||
pline.addVertexAt(nVert, ptPrev);
|
||
nVert++;
|
||
}
|
||
|
||
pline.addVertexAt(nVert, ptVert);
|
||
nVert++;
|
||
if (bNext)
|
||
{
|
||
pline.addVertexAt(nVert, ptNext);
|
||
nVert++;
|
||
}
|
||
pline.setConstantWidth(tempLineWidth);
|
||
dc.Polyline(pline);
|
||
}
|
||
|
||
if (!!m_sText||g_bExplodeSubText)
|
||
{
|
||
AecDbText text;
|
||
text.setPropertiesFrom(this);
|
||
//text.SetRotation(m_nTextRotation);
|
||
text.SetAlignment(XExplodeDraw::kMiddleCenter);
|
||
text.SetStyleId(m_idTextStyle);
|
||
if (dc.IsExportTch4()) // aec modify 090608
|
||
{
|
||
if (!!m_idTextLayer)
|
||
text.setLayer(m_idTextLayer);
|
||
}
|
||
else
|
||
text.setColorIndex(m_colorText); // aec add 090608,将文字和标注放在同一层,文字的颜色为白色
|
||
|
||
PushProperty vProp(&text, dc);
|
||
text.SetHeight(m_nTextHeight);
|
||
text.SetText(m_sText);
|
||
text.SetLocation(m_ptText1);
|
||
if(dc.IsFullExplode())
|
||
text.ExplodeOrDraw2d(dc);
|
||
else
|
||
dc.DrawEntity(text);
|
||
text.SetLocation(m_ptText2);
|
||
if(dc.IsFullExplode())
|
||
text.ExplodeOrDraw2d(dc);
|
||
else
|
||
dc.DrawEntity(text);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
// aec add 110301,支持统一标高
|
||
bool AecDbSymbSection::UnifyElevation(double dElevation)
|
||
{
|
||
assertWriteEnabled();
|
||
m_poly.SetElevation(dElevation);
|
||
m_ptText1.z = dElevation;
|
||
m_ptText2.z = dElevation;
|
||
return true;
|
||
}
|
||
|
||
|
||
Acad::ErrorStatus AecDbSymbSection::subGetGripPoints(
|
||
AcGePoint3dArray& gripPoints,
|
||
AcDbIntArray& osnapMasks,
|
||
AcDbIntArray& geomIds) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
gripPoints.append(m_ptText1); //0
|
||
gripPoints.append(m_ptText2); //1
|
||
|
||
int nEdgeNum=m_poly.TotalSegments();
|
||
gripPoints.append(*m_poly.Head()); //2
|
||
gripPoints.append(*m_poly.Tail()); //3
|
||
for(int i=0; i<nEdgeNum; i++) {
|
||
XCurveSegment seg;
|
||
m_poly.Nth(i, seg);
|
||
XPoint ptMid=seg.MidPoint();
|
||
gripPoints.append(ptMid);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbSymbSection::subMoveGripPointsAt(
|
||
const AcDbIntArray& indices,
|
||
const AcGeVector3d& vtOffset)
|
||
{
|
||
assertWriteEnabled();
|
||
XPoint offset(vtOffset[0], vtOffset[1]);
|
||
|
||
XPoint ptDef1=GetDefaultTextLocation(0);
|
||
XPoint ptDef2=GetDefaultTextLocation(1);
|
||
BOOL bAtDefault1=(m_ptText1.Distance2d(ptDef1)<_DIST_SNAP);
|
||
BOOL bAtDefault2=(m_ptText2.Distance2d(ptDef2)<_DIST_SNAP);
|
||
BOOL bMoveText1=FALSE;
|
||
BOOL bMoveText2=FALSE;
|
||
BOOL bMT1=FALSE;
|
||
BOOL bMT2=FALSE;
|
||
|
||
XArc xa;
|
||
int nSeg=m_poly.TotalSegments();
|
||
for (int i = 0; i < indices.length(); i++) {
|
||
int idx = indices[i];
|
||
if(idx==0){
|
||
if(!bMT1) {
|
||
m_ptText1 +=offset;
|
||
bMoveText1=TRUE;
|
||
bMT1=TRUE;
|
||
}
|
||
}else if(idx==1){
|
||
if(!bMT2) {
|
||
m_ptText2 +=offset;
|
||
bMoveText2=TRUE;
|
||
bMT2=TRUE;
|
||
}
|
||
} else if(idx==2) {
|
||
XLine ln;
|
||
m_poly.Nth(0, ln, xa);
|
||
XVector3D vt=ln.StartPoint()-ln.EndPoint();
|
||
((AcGeVector3d &)vt).normalize();
|
||
double nInc=(offset&vt);
|
||
ads_polar(XPoint(ln.StartPoint()), ln.Direction() - PI, nInc, *m_poly.Head());
|
||
vt.Scale(nInc);
|
||
if(!bMT1) {
|
||
m_ptText1 += vt;
|
||
bMT1=TRUE;
|
||
}
|
||
} else if(idx==3) {
|
||
XLine ln;
|
||
m_poly.Nth(nSeg-1, ln, xa);
|
||
XVector3D vt=ln.EndPoint()-ln.StartPoint();
|
||
((AcGeVector3d &)vt).normalize();
|
||
double nInc=(offset&vt);
|
||
ads_polar(XPoint(ln.EndPoint()), ln.Direction(), nInc, *m_poly.Tail());
|
||
vt.Scale(nInc);
|
||
if(!bMT2) {
|
||
m_ptText2 += vt;
|
||
bMT2=TRUE;
|
||
}
|
||
} else { // Move Edge
|
||
int nEdgeIndex=idx-4;
|
||
int nTotalEdge=m_poly.TotalSegments();
|
||
|
||
XLine ln;
|
||
m_poly.Nth(nEdgeIndex, ln, xa);
|
||
ln.StartPoint() += offset;
|
||
ln.EndPoint() += offset;
|
||
ln.SetLineFlag(LS_INFINITE);
|
||
XDirectionCurve prevSeg, nextSeg;
|
||
int nPrev=nEdgeIndex-1, nNext=nEdgeIndex+1;
|
||
|
||
XPoint ptStart, ptEnd;
|
||
BOOL bUpdateIt=TRUE;
|
||
//更新起点
|
||
if(nPrev>=0 && nPrev<nTotalEdge) {
|
||
m_poly.Nth(nPrev, prevSeg);
|
||
prevSeg.SetLineFlag(LS_INFINITE);
|
||
XPoint ptInt[2];
|
||
int nIntNum=prevSeg.Intersection(ln, ptInt[0], ptInt[1]);
|
||
if(nIntNum==1) ptStart=ptInt[0];
|
||
else if(nIntNum==2) {
|
||
ptStart=XLine(ptInt[0], ptInt[1]).NearPoint(ln.StartPoint());
|
||
} else bUpdateIt=FALSE;
|
||
} else {
|
||
XVector3D vtView(cos(m_nViewDir), sin(m_nViewDir));
|
||
double nDot=(offset&vtView);
|
||
vtView *= nDot;
|
||
ptStart = *m_poly[nEdgeIndex] + vtView;
|
||
if(!bMT1) {
|
||
m_ptText1 += vtView;
|
||
bMT1=TRUE;
|
||
}
|
||
}
|
||
|
||
// 更新下一点
|
||
if(nNext>=0 && nNext<nTotalEdge) {
|
||
m_poly.Nth(nNext, nextSeg);
|
||
nextSeg.SetLineFlag(LS_INFINITE);
|
||
XPoint ptInt[2];
|
||
int nIntNum=nextSeg.Intersection(ln, ptInt[0], ptInt[1]);
|
||
if(nIntNum==1) ptEnd=ptInt[0];
|
||
else if(nIntNum==2) {
|
||
ptEnd=XLine(ptInt[0], ptInt[1]).NearPoint(ln.EndPoint());
|
||
} else bUpdateIt=FALSE;
|
||
} else {
|
||
XVector3D vtView(cos(m_nViewDir), sin(m_nViewDir));
|
||
double nDot=(offset&vtView);
|
||
vtView *= nDot;
|
||
ptEnd = *m_poly[nEdgeIndex+1] + vtView;
|
||
if(!bMT2) {
|
||
m_ptText2 += vtView;
|
||
bMT2=TRUE;
|
||
}
|
||
}
|
||
|
||
if(bUpdateIt) {
|
||
*m_poly[nEdgeIndex] = ptStart;
|
||
if(nNext>=0 && nNext<m_poly.Length()) {
|
||
*m_poly[nNext] = ptEnd;
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
if(bAtDefault1 && !bMoveText1) m_ptText1=GetDefaultTextLocation(0);
|
||
if(bAtDefault2 && !bMoveText2) m_ptText2=GetDefaultTextLocation(1);
|
||
|
||
if(bMoveText1) {
|
||
XCurveSegment segFirst;
|
||
m_poly.Nth(0, segFirst);
|
||
XPoint ptView;
|
||
ads_polar(segFirst.StartPoint(), m_nViewDir, 100.0, ptView);
|
||
if(segFirst.OnWhichSide(ptView)!=segFirst.OnWhichSide(m_ptText1)) {
|
||
m_nViewDir=CT_std_angle(m_nViewDir+PI);
|
||
m_ptText2=GetDefaultTextLocation(1);
|
||
}
|
||
} else if(bMoveText2) {
|
||
XCurveSegment segLast;
|
||
m_poly.Nth(m_poly.TotalSegments()-1, segLast);
|
||
XPoint ptView;
|
||
ads_polar(segLast.EndPoint(), m_nViewDir, 100.0, ptView);
|
||
if(segLast.OnWhichSide(ptView)!=segLast.OnWhichSide(m_ptText2)) {
|
||
m_nViewDir=CT_std_angle(m_nViewDir+PI);
|
||
m_ptText1=GetDefaultTextLocation(0);
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecDbSymbSection::subGetStretchPoints(AcGePoint3dArray& stretchPoints) const
|
||
{
|
||
AcDbIntArray osnapModes;
|
||
AcDbIntArray geomIds;
|
||
|
||
assertReadEnabled();
|
||
|
||
// getStretchPoints == getGripPoints
|
||
//
|
||
return subGetGripPoints(stretchPoints, osnapModes, geomIds);
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecDbSymbSection::subMoveStretchPointsAt(const AcDbIntArray& indices,
|
||
const AcGeVector3d& offset)
|
||
{
|
||
assertWriteEnabled();
|
||
|
||
// moveStretchPointsAt == moveGripPointsAt
|
||
//
|
||
return subMoveGripPointsAt(indices, offset);
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbSymbSection::subTransformBy(const AcGeMatrix3d& xform)
|
||
{
|
||
assertWriteEnabled();
|
||
AecEntity::subTransformBy(xform);
|
||
|
||
ads_matrix mat;
|
||
memcpy(mat, &xform, sizeof(AcGeMatrix3d));
|
||
|
||
int i,len;
|
||
len=m_poly.Length();
|
||
for (i =0; i < len; i++){
|
||
m_poly[i]->TransformBy(mat);
|
||
}
|
||
XPoint ptTemp1, ptTemp2;
|
||
ads_polar(ptTemp1, m_nViewDir, 1000.0, ptTemp2);
|
||
ptTemp1.TransformBy(mat);
|
||
ptTemp2.TransformBy(mat);
|
||
m_nViewDir = ads_angle(ptTemp1, ptTemp2);
|
||
|
||
m_ptText1.TransformBy(mat);
|
||
m_ptText2.TransformBy(mat);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
int AecDbSymbSection::ConvertText(TConvertTextPtr ptr, void *pData)
|
||
{
|
||
XString sText;
|
||
int nRet=ptr(m_sText, sText, pData);
|
||
if(nRet==RTNORM) {
|
||
assertWriteEnabled();
|
||
m_sText=sText;
|
||
}
|
||
return nRet;
|
||
}
|
||
|
||
// aec add 090626,解决需求平台问题1416,支持查找替换操作
|
||
BOOL AecDbSymbSection::GetText(Adesk::UInt32 cookies, AecDbText &text) const
|
||
{
|
||
if (cookies != 0)
|
||
return FALSE;
|
||
|
||
text.setPropertiesFrom(this);
|
||
text.SetAlignment(XExplodeDraw::kMiddleCenter);
|
||
text.SetStyleId(m_idTextStyle);
|
||
text.SetHeight(m_nTextHeight);
|
||
text.SetText(m_sText);
|
||
text.SetLocation(m_ptText1);
|
||
return TRUE;
|
||
}
|
||
|
||
TextPosition AecDbSymbSection::FindSubText(const TCHAR *sSubText, TextPosition &posStart,
|
||
TextRange *pRange) const
|
||
{
|
||
assertReadEnabled();
|
||
TextPosition pos;
|
||
if (!sSubText || !sSubText[0])
|
||
return pos;
|
||
|
||
TextPosition posNext = posStart;
|
||
while(1)
|
||
{
|
||
AecDbText text;
|
||
if (!GetText(posNext.m_nCookies, text))
|
||
break;
|
||
|
||
TextPosition posFind = text.FindSubText(sSubText, posNext, pRange);
|
||
if (!posFind)
|
||
{
|
||
posNext.m_nCookies++;
|
||
posNext.m_nTextPos = 0;
|
||
}
|
||
else
|
||
{
|
||
posStart = posNext;
|
||
if (!posStart)
|
||
{
|
||
posStart.m_nCookies++;
|
||
posStart.m_nTextPos = 0;
|
||
}
|
||
posFind.m_nCookies = posNext.m_nCookies;
|
||
pos = posFind;
|
||
break;
|
||
}
|
||
}
|
||
return pos;
|
||
}
|
||
|
||
TextPosition AecDbSymbSection::ReplaceSubText(const TextPosition &posRep,
|
||
const TCHAR *sRepText, TextRange *pRange)
|
||
{
|
||
assertWriteEnabled();
|
||
AecDbText text;
|
||
TextPosition posNext;
|
||
if (!sRepText || !GetText(posRep.m_nCookies, text))
|
||
return posNext;
|
||
|
||
posNext = text.ReplaceSubText(posRep, sRepText, pRange);
|
||
SetText(text.GetText());
|
||
|
||
if (!posNext)
|
||
{
|
||
posNext.m_nCookies = posRep.m_nCookies + 1;
|
||
posNext.m_nTextPos = 0;
|
||
}
|
||
return posNext;
|
||
}
|
||
|
||
void AecDbSymbSection::GetTips(DList<ObjInfoUnit> &lstInfo) const
|
||
{
|
||
lstInfo.Append(new ObjInfoUnit(_T("对象类型"), _T("剖切符号")));
|
||
lstInfo.Append(new ObjInfoUnit(_T("剖切号"), m_sText));
|
||
lstInfo.Append(new ObjInfoUnit(_T("字高"), XString(_T("%.1fP"), (double)m_nTextHeight)));
|
||
//lstInfo.Append(new ObjInfoUnit(_T("线宽"), XString(_T("%.1f"), (double)m_rLineWidth)));
|
||
return ;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbSymbSection::GetGripText(int idx, CString &cs) const
|
||
{
|
||
int vexLen;
|
||
vexLen=m_poly.Length();
|
||
|
||
if(idx<=1){
|
||
cs=_T("移动文字和改变方向");
|
||
}else {
|
||
cs=_T("改变剖切位置");
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Properties
|
||
|
||
XPoint AecDbSymbSection::GetDefaultTextLocation(int nPos) const
|
||
{
|
||
double nGap=m_nTextHeight*GetPScale()/2.0;
|
||
XPoint ptRet;
|
||
double nGap1=0.6*g_nSegLength*GetPScale();
|
||
if(!m_bViewLine) nGap1=0.0;
|
||
ads_polar(nPos==0? *m_poly.Head() : *m_poly.Tail(),
|
||
m_nViewDir, nGap1+nGap*2, ptRet);
|
||
return ptRet;
|
||
}
|
||
|
||
XPoint AecDbSymbSection::GetTextLocation(int nPos) const
|
||
{
|
||
return (nPos==0? m_ptText1 : m_ptText2);
|
||
}
|
||
|
||
void AecDbSymbSection::GetPoly2D(XPoly2D &poly) const
|
||
{
|
||
poly=m_poly;
|
||
}
|
||
|
||
|
||
|
||
double AecDbSymbSection::GetViewDirection() const
|
||
{
|
||
return m_nViewDir;
|
||
}
|
||
|
||
const TCHAR * AecDbSymbSection::GetText() const
|
||
{
|
||
return (const TCHAR *)m_sText;
|
||
}
|
||
|
||
|
||
BOOL AecDbSymbSection::HasViewLine() const
|
||
{
|
||
return (m_bViewLine!=0);
|
||
}
|
||
|
||
void AecDbSymbSection::SetTextLocation(int nPos, XPoint pt)
|
||
{
|
||
assertWriteEnabled();
|
||
if(nPos==0) m_ptText1=pt;
|
||
else m_ptText2=pt;
|
||
}
|
||
|
||
void AecDbSymbSection::SetPoly2D(const XPoly2D &poly)
|
||
{
|
||
assertWriteEnabled();
|
||
m_poly=poly;
|
||
}
|
||
|
||
void AecDbSymbSection::SetText(const TCHAR * pStr)
|
||
{
|
||
assertWriteEnabled();
|
||
m_sText=pStr;
|
||
}
|
||
|
||
void AecDbSymbSection::SetViewDirection(double vec)
|
||
{
|
||
assertWriteEnabled();
|
||
m_nViewDir=vec;
|
||
}
|
||
|
||
|
||
void AecDbSymbSection::SetViewLine(BOOL bTrue)
|
||
{
|
||
assertWriteEnabled();
|
||
m_bViewLine=bTrue;
|
||
}
|
||
|
||
SubText* AecDbSymbSection::HitTestText(XPoint pt)const
|
||
{
|
||
SubText*pSub=AecEntity::HitTestText(pt);
|
||
if(pSub!=NULL)
|
||
pSub->SetIndex(0);
|
||
return pSub;
|
||
}
|
||
|
||
void InitDbSymbolAnnotate(BOOL bTrue)
|
||
{
|
||
if(bTrue)
|
||
{
|
||
AecDbSymbWithText::rxInit();
|
||
AecDbSymbSection::rxInit();
|
||
acrxBuildClassHierarchy();
|
||
AecDbSymbSection::InitMatchProtocol(TRUE);
|
||
}
|
||
else
|
||
{
|
||
AecDbSymbSection::InitMatchProtocol(FALSE);
|
||
deleteAcRxClass(AecDbSymbSection::desc());
|
||
deleteAcRxClass(AecDbSymbWithText::desc());
|
||
}
|
||
} |