750 lines
13 KiB
C++
750 lines
13 KiB
C++
//-------------------------------------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TPickEntSet 类
|
|
// = Version : ver2.0
|
|
// = Author : wlw
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: TPickEntSet 定义
|
|
// = Maintainers:
|
|
//
|
|
//-------------------------------------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TPickEntSet.h"
|
|
#include "TEntitySet.h"
|
|
#include "TDragPickEntSet.h"
|
|
#include "TchGlobalFunc.h"
|
|
#include "TchPrivateGlobalFunc.h"
|
|
|
|
TPickEntSet::TPickEntSet(int createMode)
|
|
{
|
|
*name = name[1] = 0;
|
|
flag = createMode;
|
|
if (createMode & SS_CREATE)
|
|
{
|
|
if (ads_ssadd(NULL,NULL,name) == RTNORM)
|
|
{
|
|
return;
|
|
}
|
|
//ApplicationError(_T("\nError in creating selection set."));
|
|
}
|
|
}
|
|
|
|
TPickEntSet::TPickEntSet(const ads_name n)
|
|
: flag(0)
|
|
{
|
|
name[0] = n[0];
|
|
name[1] = n[1];
|
|
}
|
|
|
|
TPickEntSet::TPickEntSet(const TPickEntSet & n)
|
|
: flag(0)
|
|
{
|
|
*this = n;
|
|
}
|
|
|
|
TPickEntSet::operator TLong_ptr *()
|
|
{
|
|
return name;
|
|
}
|
|
|
|
TPickEntSet& TPickEntSet::operator = (const ads_name n)
|
|
{
|
|
name[0] = n[0];
|
|
name[1] = n[1];
|
|
return *this;
|
|
}
|
|
|
|
TPickEntSet& TPickEntSet::operator = (const TPickEntSet &n)
|
|
{
|
|
*this = n.name;
|
|
|
|
//if (n.flag&SS_FREE)
|
|
//{
|
|
// ads_printf(_T("\nDangerous TPickEntSet = !"));
|
|
//}
|
|
return *this;
|
|
}
|
|
|
|
int TPickEntSet::operator !() const
|
|
{
|
|
return !*name && !name[1];
|
|
}
|
|
|
|
int TPickEntSet::Get(LPCTSTR commandString, void *pt1, const ads_point pt2)
|
|
{
|
|
return ads_ssget(commandString,pt1,pt2,NULL, name);
|
|
}
|
|
|
|
int TPickEntSet::Get(LPCTSTR commandString, void *pt1, const ads_point pt2, const TRBList & entmask)
|
|
{
|
|
return ads_ssget(commandString,pt1,pt2,(resbuf *)(entmask.groups),name);
|
|
}
|
|
|
|
int TPickEntSet::Get(LPCTSTR commandString, void *pt1, const ads_point pt2, const resbuf * entmask)
|
|
{
|
|
return ads_ssget(commandString,pt1,pt2,(resbuf *)entmask,name);
|
|
}
|
|
|
|
TPickEntSet operator + (const TPickEntSet &ss1, const TPickEntSet &ss2)
|
|
{
|
|
TPickEntSet res(SS_CREATE);
|
|
long len1 = ss1.Length();
|
|
long len2 = ss2.Length();
|
|
for (long i = 0; i < len1; i++)
|
|
{
|
|
res += ss1[i];
|
|
}
|
|
for (i = 0; i < len2; i++)
|
|
{
|
|
res += ss2[i];
|
|
}
|
|
return res;
|
|
}
|
|
|
|
TPickEntSet operator - (const TPickEntSet &ss1, const TPickEntSet &ss2)
|
|
{
|
|
TPickEntSet res(SS_CREATE);
|
|
long len1 = ss1.Length();
|
|
long len2 = ss2.Length();
|
|
for (long i = 0; i < len1; i++)
|
|
{
|
|
res += ss1[i];
|
|
}
|
|
for (i = 0; i < len2; i++)
|
|
{
|
|
res -= ss2[i];
|
|
}
|
|
return res;
|
|
}
|
|
|
|
TPickEntSet operator * (const TPickEntSet &ss1, const TPickEntSet &ss2)
|
|
{
|
|
TPickEntSet res(SS_CREATE);
|
|
long len1 = ss1.Length();
|
|
TEntitySet ent;
|
|
for (long i = 0; i < len1; i++)
|
|
{
|
|
ent = ss1[i];
|
|
if (ads_ssmemb(ent, ss2.name) == RTNORM)
|
|
{
|
|
res += ent;
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
int TPickEntSet::operator += (const TPickEntSet &ss)
|
|
{
|
|
if (!ss)
|
|
{
|
|
return RTERROR;
|
|
}
|
|
long len = ss.Length();
|
|
for (long i = 0; i < len; i++)
|
|
{
|
|
*this += ss[i];
|
|
}
|
|
return RTNORM;
|
|
}
|
|
|
|
int TPickEntSet::operator -= (const TPickEntSet &ss)
|
|
{
|
|
if (!ss)
|
|
{
|
|
return RTERROR;
|
|
}
|
|
long len = ss.Length();
|
|
for (long i = 0; i < len; i++)
|
|
{
|
|
*this -= ss[i];
|
|
}
|
|
return RTNORM;
|
|
}
|
|
|
|
int TPickEntSet::Move(const TADSGePoint3d &bp,TADSGePoint3d &rp) const
|
|
{
|
|
TDragPickEntSet tempss(bp, *this);
|
|
return tempss.Move(bp, rp);
|
|
}
|
|
|
|
int TPickEntSet::Rotate(const TADSGePoint3d &bp, ads_real *res) const
|
|
{
|
|
TDragPickEntSet tempss(bp, *this);
|
|
return tempss.Rotate(bp,res);
|
|
}
|
|
|
|
int TPickEntSet::Scale(const TADSGePoint3d &bp, ads_real *res) const
|
|
{
|
|
TDragPickEntSet tempss(bp, *this);
|
|
return tempss.Scale(bp,res);
|
|
}
|
|
|
|
int TPickEntSet::operator += (const TEntitySet &ent)
|
|
{
|
|
if (!(*this))
|
|
{
|
|
ads_ssadd(NULL, NULL, name);
|
|
}
|
|
return (ads_ssadd(ent.name,name,name));
|
|
}
|
|
|
|
void TPickEntSet::Get(TADSGePoint3d ptUcs,const resbuf* entmask)
|
|
{
|
|
Get(_T(":E"),ptUcs,NULL,entmask);
|
|
}
|
|
|
|
/*wlw注掉,由于没有使用的地方
|
|
bool PrePick(CView* pView,CPoint pt)
|
|
{
|
|
int nSize = 1,nTileMode = 1;
|
|
TGGetVar(_T("PICKBOX"), &nSize);
|
|
TGGetVar(_T("TILEMODE"), &nTileMode);
|
|
|
|
AcColorSettings cs;
|
|
acedGetCurrentColors(&cs);
|
|
|
|
COLORREF bc;
|
|
if (nTileMode == 1)
|
|
{
|
|
bc = acedGetRGB(cs.dwGfxModelBkColor);
|
|
}
|
|
else
|
|
{
|
|
bc = acedGetRGB(cs.dwGfxLayoutBkColor);
|
|
}
|
|
|
|
CClientDC dc(pView);
|
|
long width = nSize * 2 + 1;
|
|
for (long i = pt.x - nSize; i <= pt.x + nSize; i++)
|
|
{
|
|
for (long j = pt.y - nSize; j <= pt.y + nSize; j++)
|
|
{
|
|
CPoint pt1(i,j);
|
|
dc.DPtoLP(&pt1);
|
|
|
|
COLORREF cc = dc.GetPixel(pt1);
|
|
if (cc >= 0 && cc != bc)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
*/
|
|
|
|
void TPickEntSet::GetPreSel(const resbuf* entmask)
|
|
{
|
|
//GEOAPI CView *GetCurDwgView();
|
|
CView *pView = GetCurDwgView();
|
|
if (pView != NULL)
|
|
{
|
|
int cvport = 0;
|
|
VERIFY(TGGetVar(_T("CVPORT"), &cvport) == RTNORM);
|
|
CPoint ptCursor;
|
|
GetCursorPos(&ptCursor);
|
|
pView->ScreenToClient(&ptCursor);
|
|
int nVpNum = acedGetWinNum(ptCursor.x, ptCursor.y);
|
|
if (nVpNum == cvport)
|
|
{
|
|
TADSGePoint3d pt;
|
|
acedCoordFromPixelToWorld(cvport,ptCursor,pt);
|
|
TADSGePoint3d ptUcs = Wcs2Ucs(pt);
|
|
Get(ptUcs,entmask);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 构造无名组
|
|
int TPickEntSet::MakeUnnamedGroup()
|
|
{
|
|
TPickEntSet &ss = *this;
|
|
Acad::ErrorStatus es;
|
|
AcDbObjectId groupobjId;
|
|
AcDbGroup *pGroup = NULL;
|
|
AcDbDictionary *pGroupDict = NULL;
|
|
|
|
es = acdbCurDwg()->getGroupDictionary(pGroupDict,AcDb::kForWrite);
|
|
if (es != Acad::eOk)
|
|
{
|
|
return RTERROR;
|
|
}
|
|
|
|
//新建一组,并添入字典
|
|
pGroup = new AcDbGroup;
|
|
pGroup->setSelectable(Adesk::kTrue);
|
|
es = pGroupDict->setAt(_T("*U"),pGroup,groupobjId);
|
|
assert(es == Acad::eOk);
|
|
pGroupDict->close();
|
|
|
|
//往组中添加选择集中的实体
|
|
AcDbObjectId objectId;
|
|
long nLen = ss.Length();
|
|
|
|
for (long i = 0L;i < nLen;i++)
|
|
{
|
|
TEntitySet en = ss[i];
|
|
if (acdbGetObjectId(objectId,en) != Acad::eOk)
|
|
{
|
|
pGroup->close();
|
|
return RTERROR;
|
|
}
|
|
if (pGroup->append(objectId) != Acad::eOk)
|
|
{
|
|
pGroup->close();
|
|
return RTERROR;
|
|
}
|
|
}
|
|
pGroup->close();
|
|
|
|
return RTNORM;
|
|
|
|
}
|
|
|
|
|
|
void TPickEntSet::AsIdArray(AcDbObjectIdArray &idArray)
|
|
{
|
|
long lCount = Length();
|
|
for (long i = 0L; i < lCount; i++)
|
|
{
|
|
TEntitySet ent = (*this)[i];
|
|
AcDbObjectId id;
|
|
VERIFY(acdbGetObjectId(id, ent.name) == Acad::eOk);
|
|
idArray.append(id);
|
|
}
|
|
}
|
|
|
|
int TPickEntSet::operator += (const AcDbObjectId &id)
|
|
{
|
|
TEntitySet ent;
|
|
VERIFY(acdbGetAdsName(ent.name, id) == Acad::eOk);
|
|
return (*this += ent);
|
|
}
|
|
|
|
int TPickEntSet::operator -= (const AcDbObjectId &id)
|
|
{
|
|
TEntitySet ent;
|
|
VERIFY(acdbGetAdsName(ent.name, id) == Acad::eOk);
|
|
return (*this -= ent);
|
|
}
|
|
|
|
int TPickEntSet::operator -= (const TEntitySet &ent)
|
|
{
|
|
if (!(*this))
|
|
{
|
|
return RTERROR;
|
|
}
|
|
return (ads_ssdel(ent.name,name));
|
|
}
|
|
|
|
long TPickEntSet::Length() const
|
|
{
|
|
Adesk::Int32 len = 0;
|
|
if (!!(*this))
|
|
{
|
|
ads_sslength(name,&len);
|
|
}
|
|
|
|
return len;
|
|
}
|
|
|
|
int TPickEntSet::Transform(ads_matrix genmat) const
|
|
{
|
|
return ads_xformss(name,genmat);
|
|
}
|
|
|
|
TEntitySet TPickEntSet::operator [](long index) const
|
|
{
|
|
TEntitySet ent;
|
|
ads_ssname(name,index,ent.name);
|
|
return ent;
|
|
}
|
|
|
|
bool TPickEntSet::IsInclude(TEntitySet ent)const
|
|
{
|
|
long count = Length();
|
|
for (long i = 0;i < count;i++)
|
|
{
|
|
TEntitySet ent1 = (*this)[i];
|
|
if (ent1 == ent)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Note: 不管如何, 总创建 mark实体, 以免最近产生的实体为复杂实体
|
|
void TPickEntSet::IncludeBegin()
|
|
{
|
|
if (!name[0] && !name[1])
|
|
{
|
|
if (ads_ssadd(NULL,NULL,name) != RTNORM)
|
|
{
|
|
//ApplicationError(_T("\nError in creating selection set."));
|
|
return;
|
|
}
|
|
}
|
|
|
|
AcDbPoint *pTemp = new AcDbPoint(AcGePoint3d(0,0,0));
|
|
AcDbObjectId idTemp = AddToModelSpace(pTemp, Adesk::kTrue);
|
|
if (!idTemp)
|
|
{
|
|
return;
|
|
}
|
|
VERIFY(acdbGetAdsName(mark.name, idTemp) == Acad::eOk);
|
|
flag |= SS_MARK;
|
|
}
|
|
|
|
void TPickEntSet::IncludeEnd()
|
|
{
|
|
if (!mark)
|
|
{
|
|
return;
|
|
}
|
|
TEntitySet m = mark;
|
|
while (m.GetNext() == RTNORM)
|
|
{
|
|
m.GetGroups(0);
|
|
if (!m.Is(_T("VERTEX")) && !m.Is(_T("SEQEND")) && !m.Is(_T("ATTRIB")))
|
|
{
|
|
*this += m;
|
|
}
|
|
}
|
|
|
|
*this -= mark;
|
|
|
|
if (flag & SS_MARK)
|
|
{
|
|
flag &= ~SS_MARK;
|
|
mark.Delete();
|
|
}
|
|
|
|
}
|
|
|
|
TPickEntSet::~TPickEntSet()
|
|
{
|
|
if ((flag & SS_FREE) && (name[0] || name[1]))
|
|
{
|
|
ads_ssfree(name);
|
|
}
|
|
}
|
|
|
|
void TPickEntSet::Redraw(int mode) const
|
|
{
|
|
long num, len = Length();
|
|
for (num = 0;num < len;num++)
|
|
{
|
|
(*this)[num].Redraw(mode);
|
|
}
|
|
}
|
|
|
|
int TPickEntSet::Erase() const
|
|
{
|
|
long len = Length();
|
|
for (long i = 0; i < len; i++)
|
|
{
|
|
TEntitySet ent = (*this)[i];
|
|
ent.Erase();
|
|
}
|
|
return RTNORM;
|
|
}
|
|
|
|
void TPickEntSet::Free()
|
|
{
|
|
if (*name || name[1])
|
|
{
|
|
ads_ssfree(name);
|
|
*name = name[1] = 0;
|
|
}
|
|
}
|
|
|
|
void TPickEntSet::Delete() const
|
|
{
|
|
long num, len = Length();
|
|
for (num = 0;num < len;num++)
|
|
{
|
|
(*this)[num].Delete();
|
|
}
|
|
}
|
|
|
|
|
|
void TPickEntSet::Bind(const TEntitySet &e)
|
|
{
|
|
long num, len = Length();
|
|
TCHAR keyWord[64];
|
|
TEntitySet key = e;
|
|
key.GetData(5,keyWord);
|
|
|
|
for (num = 0;num < len;num++)
|
|
{
|
|
TEntitySet ent;
|
|
ent = (*this)[num];
|
|
ent.SetString(EX_BIND,keyWord);
|
|
ent.Modify();
|
|
}
|
|
}
|
|
|
|
void TPickEntSet::ExFilter(const TRBList &exlist)
|
|
{
|
|
long num, len = Length();
|
|
TPickEntSet ss(SS_CREATE);
|
|
for (num = 0;num < len;num++)
|
|
{
|
|
TEntitySet ent;
|
|
ent = (*this)[num];
|
|
ent.GetGroups();
|
|
if (ent.Match(exlist))
|
|
{
|
|
ss += ent;
|
|
}
|
|
}
|
|
Free();
|
|
*this = ss;
|
|
}
|
|
|
|
void TPickEntSet::ExTagFilter(const int *tagList, int sz)
|
|
{
|
|
long num, len = Length();
|
|
TPickEntSet ss(SS_CREATE|SS_FREE);
|
|
for (num = 0;num < len;num++)
|
|
{
|
|
TEntitySet ent;
|
|
ent = (*this)[num];
|
|
ent.GetGroups();
|
|
for (int i = 0; i < sz; i++)
|
|
{
|
|
int tagCode = tagList[i];
|
|
if (ent.SearchDataByTag(tagCode))
|
|
{
|
|
;
|
|
}
|
|
else
|
|
{
|
|
ss += ent;
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
*this -= ss;
|
|
}
|
|
|
|
void TPickEntSet::BaseFilter(const TRBList &baseList)
|
|
{
|
|
AcDbObject* pObj = NULL;
|
|
AcDbObjectId id;
|
|
long num, len = Length();
|
|
TPickEntSet ss(SS_CREATE);
|
|
for (num = 0;num < len;num++)
|
|
{
|
|
TEntitySet ent;
|
|
ent = (*this)[num];
|
|
|
|
acdbGetObjectId(id,ent.name);
|
|
if (Acad::eOk == acdbOpenAcDbObject(pObj,id,AcDb::kForRead))
|
|
{
|
|
const TCHAR* pName = pObj->isA()->name();
|
|
pObj->close();
|
|
}
|
|
ent.GetGroups((int)0);
|
|
if (ent.MatchBase(baseList))
|
|
{
|
|
ss += ent;
|
|
}
|
|
}
|
|
Free();
|
|
*this = ss;
|
|
}
|
|
|
|
void TPickEntSet::BaseExclude(const TRBList &baseList)
|
|
{
|
|
long num, len = Length();
|
|
TPickEntSet ss(SS_CREATE);
|
|
for (num = 0;num < len;num++)
|
|
{
|
|
TEntitySet ent;
|
|
ent = (*this)[num];
|
|
ent.GetGroups((int)0);
|
|
if (ent.MatchBase(baseList))
|
|
{
|
|
ss += ent;
|
|
}
|
|
}
|
|
*this -= ss;
|
|
}
|
|
|
|
int TPickEntSet::GetExtend(ads_point lowPt, ads_point upPt) const
|
|
{
|
|
if (!(*this))
|
|
{
|
|
return RTNONE;
|
|
}
|
|
|
|
int findExtend = 0;
|
|
int res = RTNORM;
|
|
long len = Length();
|
|
TADSGePoint3d low, up;
|
|
for (long i = 0; i < len; i++)
|
|
{
|
|
TEntitySet ent = (*this)[i];
|
|
TADSGePoint3d pt1, pt2;
|
|
int rc = ent.GetExtend(pt1, pt2);
|
|
if (rc == RTNONE)
|
|
{
|
|
;
|
|
}
|
|
else
|
|
{
|
|
if (rc == RTERROR)
|
|
{
|
|
res = RTERROR;
|
|
}
|
|
|
|
if (findExtend)
|
|
{
|
|
low = Min(low, pt1);
|
|
up = Max(up, pt2);
|
|
}
|
|
else
|
|
{
|
|
low = pt1;
|
|
up = pt2;
|
|
findExtend = 1;
|
|
}
|
|
}
|
|
}
|
|
if (!findExtend)
|
|
{
|
|
return RTNONE;
|
|
}
|
|
low>lowPt;
|
|
up>upPt;
|
|
return res;
|
|
}
|
|
|
|
int TPickEntSet::GetExtend(ads_point cen, ads_real *x, ads_real *y, ads_real *z) const
|
|
{
|
|
TADSGePoint3d lowPt, upPt;
|
|
int rc = GetExtend(lowPt, upPt);
|
|
if (rc == RTNONE)
|
|
{
|
|
return rc;
|
|
}
|
|
TADSGePoint3d extSize = upPt-lowPt;
|
|
if (cen)
|
|
{
|
|
Midpoint(lowPt, upPt, cen);
|
|
}
|
|
if (x)
|
|
{
|
|
*x = extSize.x;
|
|
}
|
|
if (y)
|
|
{
|
|
*y = extSize.y;
|
|
}
|
|
if (z)
|
|
{
|
|
*z = extSize.z;
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
// 选择集变换: 允许不等比缩放
|
|
int TPickEntSet::XTransform(ads_matrix mat) const
|
|
{
|
|
long len = Length();
|
|
if (!len)
|
|
{
|
|
return RTNONE;
|
|
}
|
|
int rc = RTNORM;
|
|
for (long i = 0; i < len; i++)
|
|
{
|
|
if ((*this)[i].XTransform(mat) != RTNORM)
|
|
{
|
|
rc = RTERROR;
|
|
}
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
// 制作无名块
|
|
// base--基点
|
|
// blk--分配给无名块的图块名
|
|
// mkInstance--是否建立无名块的插入实例
|
|
int TPickEntSet::MakeAnonymous(const TADSGePoint3d &base, TCHAR *blk, int mkInstance) const
|
|
{
|
|
AcDbObjectId idBlock = MakeBlock(_T("*U"), *(TPickEntSet *)this, base);
|
|
if (mkInstance)
|
|
{
|
|
AcDbBlockReference *pInsert = new AcDbBlockReference(base, idBlock);
|
|
AddToModelSpace(pInsert, Adesk::kTrue);
|
|
}
|
|
if (blk)
|
|
{
|
|
_tcscpy(blk, TchExport::GetSymbolName(idBlock));
|
|
}
|
|
Delete();
|
|
return RTNORM;
|
|
}
|
|
|
|
int TPickEntSet::RemoveXData() const
|
|
{
|
|
long len = Length();
|
|
for (long i = 0; i < len; i++)
|
|
{
|
|
TEntitySet ent = (*this)[i];
|
|
ent.RemoveXData();
|
|
}
|
|
return RTNORM;
|
|
}
|
|
|
|
void TPickEntSet::RedrawAll(int mode) const
|
|
{
|
|
int nTileMode = 0;
|
|
TGGetVar(_T("TILEMODE"), &nTileMode);
|
|
|
|
resbuf * rbViewports = NULL;
|
|
VERIFY(ads_vports(&rbViewports) == RTNORM && rbViewports);
|
|
ASSERT(rbViewports->restype == RTLB && rbViewports->rbnext && rbViewports->rbnext->restype == RTSHORT);
|
|
|
|
int nCurVp = rbViewports->rbnext->resval.rint;
|
|
|
|
resbuf *rbNext = rbViewports->rbnext->rbnext->rbnext->rbnext->rbnext;
|
|
while(rbNext && !(nTileMode == 0 && nCurVp == 1))
|
|
{
|
|
ASSERT(rbNext->restype == RTLB && rbNext->rbnext->restype == RTSHORT);
|
|
if (TGSetVar(_T("CVPORT"), rbNext->rbnext->resval.rint) == RTNORM)
|
|
{
|
|
Redraw(mode);
|
|
}
|
|
rbNext = rbNext->rbnext->rbnext->rbnext->rbnext->rbnext;
|
|
}
|
|
ads_relrb(rbViewports);
|
|
|
|
TGSetVar(_T("CVPORT"), nCurVp);
|
|
Redraw(mode);
|
|
}
|
|
|
|
TRemoveDupEntByLayer::TRemoveDupEntByLayer(const TCHAR *pszLayer)
|
|
: m_sLayer(pszLayer), m_ss(SS_FREE)
|
|
{
|
|
|
|
}
|
|
|
|
TRemoveDupEntByLayer::~TRemoveDupEntByLayer()
|
|
{
|
|
|
|
}
|
|
|
|
int TRemoveDupEntByLayer::CompareForFindByLayer(const TRemoveDupEntByLayer *p1, const void *p2)
|
|
{
|
|
const TCHAR *psz = (const TCHAR *)p2;
|
|
return _tcsicmp(p1->m_sLayer, psz);
|
|
}
|
|
|