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