Files
envi-code/SourceCode/Code2026/Dimension/PickEntSet.cpp
T
2026-09-28 15:28:50 +08:00

750 lines
13 KiB
C++

//-------------------------------------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : PickEntSet 类
// = Version : ver2.0
// = Author : wlw
// = CreateDate : 2002-09-09
// = Description: PickEntSet 定义
// = Maintainers:
//
//-------------------------------------------------------------------------------------------------------+
#include "StdAfx.h"
#include "PickEntSet.h"
#include "EntitySet.h"
#include "DragPickEntSet.h"
#include "globalFunc.h"
#include "ADSGePoint3d.h"
PickEntSet::PickEntSet(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."));
}
}
PickEntSet::PickEntSet(const ads_name n)
: flag(0)
{
name[0] = n[0];
name[1] = n[1];
}
PickEntSet::PickEntSet(const PickEntSet & n)
: flag(0)
{
*this = n;
}
PickEntSet::operator TLong_ptr *()
{
return name;
}
PickEntSet& PickEntSet::operator = (const ads_name n)
{
name[0] = n[0];
name[1] = n[1];
return *this;
}
PickEntSet& PickEntSet::operator = (const PickEntSet &n)
{
*this = n.name;
//if (n.flag&SS_FREE)
//{
// ads_printf(_T("\nDangerous PickEntSet = !"));
//}
return *this;
}
int PickEntSet::operator !() const
{
return !*name && !name[1];
}
int PickEntSet::Get(LPCTSTR commandString, void *pt1, const ads_point pt2)
{
return ads_ssget(commandString,pt1,pt2,NULL, name);
}
int PickEntSet::Get(LPCTSTR commandString, void *pt1, const ads_point pt2, const RBList & entmask)
{
return ads_ssget(commandString,pt1,pt2,(resbuf *)(entmask.groups),name);
}
int PickEntSet::Get(LPCTSTR commandString, void *pt1, const ads_point pt2, const resbuf * entmask)
{
return ads_ssget(commandString,pt1,pt2,(resbuf *)entmask,name);
}
PickEntSet operator + (const PickEntSet &ss1, const PickEntSet &ss2)
{
PickEntSet 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;
}
PickEntSet operator - (const PickEntSet &ss1, const PickEntSet &ss2)
{
PickEntSet 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;
}
PickEntSet operator * (const PickEntSet &ss1, const PickEntSet &ss2)
{
PickEntSet res(SS_CREATE);
long len1 = ss1.Length();
EntitySet ent;
for (long i = 0; i < len1; i++)
{
ent = ss1[i];
if (ads_ssmemb(ent, ss2.name) == RTNORM)
{
res += ent;
}
}
return res;
}
int PickEntSet::operator += (const PickEntSet &ss)
{
if (!ss)
{
return RTERROR;
}
long len = ss.Length();
for (long i = 0; i < len; i++)
{
*this += ss[i];
}
return RTNORM;
}
int PickEntSet::operator -= (const PickEntSet &ss)
{
if (!ss)
{
return RTERROR;
}
long len = ss.Length();
for (long i = 0; i < len; i++)
{
*this -= ss[i];
}
return RTNORM;
}
int PickEntSet::Move(const ADSGePoint3d &bp,ADSGePoint3d &rp) const
{
DragPickEntSet tempss(bp, *this);
return tempss.Move(bp, rp);
}
int PickEntSet::Rotate(const ADSGePoint3d &bp, ads_real *res) const
{
DragPickEntSet tempss(bp, *this);
return tempss.Rotate(bp,res);
}
int PickEntSet::Scale(const ADSGePoint3d &bp, ads_real *res) const
{
DragPickEntSet tempss(bp, *this);
return tempss.Scale(bp,res);
}
int PickEntSet::operator += (const EntitySet &ent)
{
if (!(*this))
{
ads_ssadd(NULL, NULL, name);
}
return (ads_ssadd(ent.name,name,name));
}
void PickEntSet::Get(ADSGePoint3d 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 PickEntSet::GetPreSel(const resbuf* entmask)
{
//GEOAPI CView *GetCurDwgView();
CView *pView = GlobalFunc::GetCurDwgView();
if (pView != NULL)
{
int cvport = 0;
VERIFY(GlobalFunc::TGGetVar(_T("CVPORT"), &cvport) == RTNORM);
CPoint ptCursor;
GetCursorPos(&ptCursor);
pView->ScreenToClient(&ptCursor);
int nVpNum = acedGetWinNum(ptCursor.x, ptCursor.y);
if (nVpNum == cvport)
{
ADSGePoint3d pt;
acedCoordFromPixelToWorld(cvport,ptCursor,pt);
ADSGePoint3d ptUcs = GlobalFunc::Wcs2Ucs(pt);
Get(ptUcs,entmask);
}
}
}
// 构造无名组
int PickEntSet::MakeUnnamedGroup()
{
PickEntSet &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++)
{
EntitySet 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 PickEntSet::AsIdArray(AcDbObjectIdArray &idArray)
{
long lCount = Length();
for (long i = 0L; i < lCount; i++)
{
EntitySet ent = (*this)[i];
AcDbObjectId id;
VERIFY(acdbGetObjectId(id, ent.name) == Acad::eOk);
idArray.append(id);
}
}
int PickEntSet::operator += (const AcDbObjectId &id)
{
EntitySet ent;
VERIFY(acdbGetAdsName(ent.name, id) == Acad::eOk);
return (*this += ent);
}
int PickEntSet::operator -= (const AcDbObjectId &id)
{
EntitySet ent;
VERIFY(acdbGetAdsName(ent.name, id) == Acad::eOk);
return (*this -= ent);
}
int PickEntSet::operator -= (const EntitySet &ent)
{
if (!(*this))
{
return RTERROR;
}
return (ads_ssdel(ent.name,name));
}
long PickEntSet::Length() const
{
Adesk::Int32 len = 0;
if (!!(*this))
{
ads_sslength(name,&len);
}
return len;
}
int PickEntSet::Transform(ads_matrix genmat) const
{
return ads_xformss(name,genmat);
}
EntitySet PickEntSet::operator [](long index) const
{
EntitySet ent;
ads_ssname(name,index,ent.name);
return ent;
}
bool PickEntSet::IsInclude(EntitySet ent)const
{
long count = Length();
for (long i = 0;i < count;i++)
{
EntitySet ent1 = (*this)[i];
if (ent1 == ent)
{
return true;
}
}
return false;
}
// Note: 不管如何, 总创建 mark实体, 以免最近产生的实体为复杂实体
void PickEntSet::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 = GlobalFunc::AddToModelSpace(pTemp, Adesk::kTrue);
if (!idTemp)
{
return;
}
VERIFY(acdbGetAdsName(mark.name, idTemp) == Acad::eOk);
flag |= SS_MARK;
}
void PickEntSet::IncludeEnd()
{
if (!mark)
{
return;
}
EntitySet 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();
}
}
PickEntSet::~PickEntSet()
{
if ((flag & SS_FREE) && (name[0] || name[1]))
{
ads_ssfree(name);
}
}
void PickEntSet::Redraw(int mode) const
{
long num, len = Length();
for (num = 0;num < len;num++)
{
(*this)[num].Redraw(mode);
}
}
int PickEntSet::Erase() const
{
long len = Length();
for (long i = 0; i < len; i++)
{
EntitySet ent = (*this)[i];
ent.Erase();
}
return RTNORM;
}
void PickEntSet::Free()
{
if (*name || name[1])
{
ads_ssfree(name);
*name = name[1] = 0;
}
}
void PickEntSet::Delete() const
{
long num, len = Length();
for (num = 0;num < len;num++)
{
(*this)[num].Delete();
}
}
void PickEntSet::Bind(const EntitySet &e)
{
long num, len = Length();
TCHAR keyWord[64];
EntitySet key = e;
key.GetData(5,keyWord);
for (num = 0;num < len;num++)
{
EntitySet ent;
ent = (*this)[num];
ent.SetString(EX_BIND,keyWord);
ent.Modify();
}
}
void PickEntSet::ExFilter(const RBList &exlist)
{
long num, len = Length();
PickEntSet ss(SS_CREATE);
for (num = 0;num < len;num++)
{
EntitySet ent;
ent = (*this)[num];
ent.GetGroups();
if (ent.Match(exlist))
{
ss += ent;
}
}
Free();
*this = ss;
}
void PickEntSet::ExTagFilter(const int *tagList, int sz)
{
long num, len = Length();
PickEntSet ss(SS_CREATE|SS_FREE);
for (num = 0;num < len;num++)
{
EntitySet 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 PickEntSet::BaseFilter(RBList &baseList)
{
AcDbObject* pObj = NULL;
AcDbObjectId id;
long num, len = Length();
PickEntSet ss(SS_CREATE);
for (num = 0;num < len;num++)
{
EntitySet 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 PickEntSet::BaseExclude(RBList &baseList)
{
long num, len = Length();
PickEntSet ss(SS_CREATE);
for (num = 0;num < len;num++)
{
EntitySet ent;
ent = (*this)[num];
ent.GetGroups((int)0);
if (ent.MatchBase(baseList))
{
ss += ent;
}
}
*this -= ss;
}
int PickEntSet::GetExtend(ads_point lowPt, ads_point upPt) const
{
if (!(*this))
{
return RTNONE;
}
int findExtend = 0;
int res = RTNORM;
long len = Length();
ADSGePoint3d low, up;
for (long i = 0; i < len; i++)
{
EntitySet ent = (*this)[i];
ADSGePoint3d 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 PickEntSet::GetExtend(ads_point cen, ads_real *x, ads_real *y, ads_real *z) const
{
ADSGePoint3d lowPt, upPt;
int rc = GetExtend(lowPt, upPt);
if (rc == RTNONE)
{
return rc;
}
ADSGePoint3d 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 PickEntSet::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 PickEntSet::MakeAnonymous(const ADSGePoint3d &base, TCHAR *blk, int mkInstance) const
{
AcDbObjectId idBlock = GlobalFunc::MakeBlock(_T("*U"), *(PickEntSet *)this, base);
if (mkInstance)
{
AcDbBlockReference *pInsert = new AcDbBlockReference(base, idBlock);
GlobalFunc::AddToModelSpace(pInsert, Adesk::kTrue);
}
if (blk)
{
_tcscpy(blk, GlobalFunc::GetSymbolName(idBlock));
}
Delete();
return RTNORM;
}
int PickEntSet::RemoveXData() const
{
long len = Length();
for (long i = 0; i < len; i++)
{
EntitySet ent = (*this)[i];
ent.RemoveXData();
}
return RTNORM;
}
void PickEntSet::RedrawAll(int mode) const
{
int nTileMode = 0;
GlobalFunc::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 (GlobalFunc::TGSetVar(_T("CVPORT"), rbNext->rbnext->resval.rint) == RTNORM)
{
Redraw(mode);
}
rbNext = rbNext->rbnext->rbnext->rbnext->rbnext->rbnext;
}
ads_relrb(rbViewports);
GlobalFunc::TGSetVar(_T("CVPORT"), nCurVp);
Redraw(mode);
}
RemoveDupEntByLayer::RemoveDupEntByLayer(const TCHAR *pszLayer)
: m_sLayer(pszLayer), m_ss(SS_FREE)
{
}
RemoveDupEntByLayer::~RemoveDupEntByLayer()
{
}
int RemoveDupEntByLayer::CompareForFindByLayer(const RemoveDupEntByLayer *p1, const void *p2)
{
const TCHAR *psz = (const TCHAR *)p2;
return _tcsicmp(p1->m_sLayer, psz);
}