361 lines
11 KiB
C++
361 lines
11 KiB
C++
#include "stdafx.h"
|
|
#include "AecTip.h"
|
|
|
|
//extern TARCH_IMPEXP Acad::ErrorStatus GetExbTips(AcDbEntity *pEnt, CString &csText);
|
|
//extern TARCH_IMPEXP Acad::ErrorStatus GetUnitHatchTips(AcDbObjectId id, CString &csText);
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// TextStatic
|
|
|
|
IMPLEMENT_DYNAMIC(CObjectTipWnd, CWnd)
|
|
|
|
CObjectTipWnd::CObjectTipWnd()
|
|
{
|
|
}
|
|
|
|
CObjectTipWnd::~CObjectTipWnd()
|
|
{
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CObjectTipWnd, CWnd)
|
|
//{{AFX_MSG_MAP(CObjectTipWnd)
|
|
ON_WM_PAINT()
|
|
ON_WM_TIMER()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
void CObjectTipWnd::OnTimer(UINT_PTR nIDEvent)
|
|
{
|
|
CWnd::OnTimer(nIDEvent);
|
|
KillTimer(1);
|
|
Invalidate();
|
|
}
|
|
void CObjectTipWnd::OnPaint()
|
|
{
|
|
if (!m_lstInfo)
|
|
return;
|
|
CRect Rect;
|
|
GetClientRect(Rect);
|
|
|
|
CPaintDC dc(this); // device context for painting
|
|
CFont *pFont=dc.SelectObject(&m_font);
|
|
{
|
|
CBrush hb1;
|
|
hb1.CreateSolidBrush(::GetSysColor(COLOR_INFOBK));
|
|
CBrush *pBrush1=dc.SelectObject(&hb1);
|
|
dc.Rectangle(0,0,Rect.right,Rect.bottom);
|
|
dc.SelectObject(pBrush1);
|
|
}
|
|
|
|
CBrush hb2;
|
|
hb2.CreateSolidBrush(RGB(0,0,0));
|
|
dc.FrameRect(&Rect,&hb2);
|
|
|
|
int nGap=4;
|
|
CPoint pos(0,0);
|
|
pos.x = nGap + m_sizeLab.cx + nGap;
|
|
|
|
{
|
|
CPen pen(PS_DOT, 1, RGB(0,0,0));
|
|
CPen *pOldPen=dc.SelectObject(&pen);
|
|
dc.MoveTo(pos.x, Rect.top);
|
|
dc.LineTo(pos.x, Rect.bottom);
|
|
dc.SelectObject(pOldPen);
|
|
}
|
|
|
|
dc.SetTextColor(::GetSysColor(COLOR_INFOTEXT));
|
|
dc.SetBkColor(::GetSysColor(COLOR_INFOBK));
|
|
|
|
for(int i=0; i<m_lstInfo.Length();i++) {
|
|
TObjInfoUnit *pObjUnit=m_lstInfo[i];
|
|
pos.y += nGap;
|
|
CString csLab=pObjUnit->m_sLabel;
|
|
CString csVal=pObjUnit->m_sValue;
|
|
CRect rectLab(nGap, pos.y, pos.x-nGap, pos.y+max(m_sizeLab.cy, m_sizeVal.cy));
|
|
dc.DrawText(csLab, rectLab, DT_RIGHT);
|
|
CRect rectVal(pos.x+nGap, pos.y, nGap*3+m_sizeLab.cx+m_sizeVal.cx, pos.y+max(m_sizeLab.cy,m_sizeVal.cy));
|
|
dc.DrawText(csVal, rectVal, DT_LEFT);
|
|
pos.y += max(m_sizeLab.cy,m_sizeVal.cy);
|
|
}
|
|
//axc add 2015-10-23 当对象查询的窗口与底行的坐标重合时会把坐标显示出来 使其显示在顶端
|
|
BringWindowToTop();
|
|
|
|
//dc.DrawText(m_sText,-1,CRect(2,2,Rect.right-4,Rect.bottom-4),DT_LEFT);
|
|
// Do not call CWnd::OnPaint() for painting messages
|
|
}
|
|
|
|
|
|
|
|
BOOL CObjectTipWnd::Create(DList<TObjInfoUnit> &lstInfo,int x,int y)
|
|
{
|
|
LOGFONT m_lf;
|
|
ZeroMemory ((PVOID) &m_lf,sizeof (LOGFONT));
|
|
NONCLIENTMETRICS nm;
|
|
|
|
//modify by xlc on 090902 R18添加菜单崩溃
|
|
#if ADS<18
|
|
nm.cbSize = sizeof (NONCLIENTMETRICS);
|
|
#else
|
|
nm.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(nm.iPaddedBorderWidth);
|
|
#endif
|
|
VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
|
|
nm.cbSize,&nm,0));
|
|
m_lf = nm.lfMenuFont;
|
|
m_font.CreateFontIndirect (&m_lf);
|
|
|
|
|
|
// Obtain the width of the text:
|
|
CWnd *pWnd = AfxGetMainWnd(); // Get main window
|
|
CDC *pDC = pWnd->GetDC(); // Get device context
|
|
CFont* pFont=NULL; // Select menu font in...
|
|
pFont = pDC->SelectObject (&m_font);// Select menu font in...
|
|
|
|
lstInfo.SetDelFlag(FALSE);
|
|
m_lstInfo.Reset();
|
|
m_sizeLab=CSize(0,0);
|
|
m_sizeVal=CSize(0,0);
|
|
for(int i=0; i<lstInfo.Length();i++) {
|
|
TObjInfoUnit *pObjUnit=lstInfo[i];
|
|
m_lstInfo.Append(pObjUnit);
|
|
CSize size=pDC->GetTextExtent(CString(pObjUnit->m_sLabel));
|
|
m_sizeLab.cx = max(m_sizeLab.cx, size.cx);
|
|
m_sizeLab.cy = max(m_sizeLab.cy, size.cy);
|
|
size=pDC->GetTextExtent(CString(pObjUnit->m_sValue));
|
|
m_sizeVal.cx = max(m_sizeVal.cx, size.cx);
|
|
m_sizeVal.cy = max(m_sizeVal.cy, size.cy);
|
|
}
|
|
|
|
pDC->SelectObject (pFont); // Select old font in
|
|
pWnd->ReleaseDC(pDC); // Release the DC
|
|
|
|
if (m_sizeLab.cx>300) m_sizeLab.cx=300;
|
|
if (m_sizeVal.cx>300) m_sizeVal.cx=300;
|
|
|
|
CSize sizeWnd;
|
|
int nGap=4;
|
|
sizeWnd.cx = nGap + m_sizeLab.cx + nGap*2 + m_sizeVal.cx + nGap;
|
|
sizeWnd.cy = nGap + (max(m_sizeLab.cy, m_sizeVal.cy) + nGap)*lstInfo.Length();
|
|
|
|
CRect rect;
|
|
rect.left = x;
|
|
rect.top = y;
|
|
rect.right = x + sizeWnd.cx;
|
|
rect.bottom = y + sizeWnd.cy;
|
|
|
|
CWnd *pFrameWnd=acedGetAcadFrame();
|
|
ASSERT(pFrameWnd);
|
|
CRect rectClient;
|
|
pFrameWnd->GetClientRect(&rectClient);
|
|
if (rect.bottom > rectClient.bottom) {
|
|
rect.top -= rect.bottom-rectClient.bottom;
|
|
rect.bottom = rectClient.bottom;
|
|
}
|
|
if (rect.right > rectClient.right) {
|
|
rect.left -= rect.right-rectClient.right;
|
|
rect.right = rectClient.right;
|
|
}
|
|
BOOL bRet=CWnd::Create(NULL,NULL,WS_CHILD|WS_VISIBLE,rect,pFrameWnd,6100);
|
|
|
|
GEOAPI double g_nAcadVer;
|
|
if (g_nAcadVer>16.11)//2006平台下要多画一次
|
|
SetTimer(1,200,NULL);
|
|
return bRet;
|
|
}
|
|
|
|
// 求最近点
|
|
BOOL GetNearestPoint(const AcGePoint3dArray &points, const XPoint &ptWcs, XPoint &ptNearest)
|
|
{
|
|
double nMinDist=0.0;
|
|
int numPoints=points.length();
|
|
if (numPoints<=0)
|
|
return FALSE;
|
|
|
|
for(int k=0; k<numPoints; k++) {
|
|
XPoint ptCur=points[k];
|
|
ptCur.z=ptWcs.z;
|
|
double nDist=ptWcs.Distance(ptCur);
|
|
if (k>0) {
|
|
if (nDist<nMinDist) {
|
|
nMinDist=nDist;
|
|
ptNearest=ptCur;
|
|
}
|
|
} else {
|
|
nMinDist=nDist;
|
|
ptNearest=ptCur;
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
extern void EditObject(Entity ent);
|
|
/* * * * * * * * * * 动 态 显 示 墙 体 属 性 的 函 数 * * * * * * * * * */
|
|
void ObjTip()
|
|
{
|
|
int type;
|
|
XPoint pt1,pt2;
|
|
int OsnapWallType = g_nOsnapType;
|
|
|
|
DocSetWallOsnapType(TRUE);
|
|
|
|
CObjectTipWnd *TextDlg = NULL;
|
|
int pickbox;
|
|
VERIFY(xg_getvar(_T("PICKBOX"), &pickbox)==RTNORM);
|
|
|
|
for (;;) {
|
|
resbuf result;
|
|
type = 2;
|
|
//if (ads_grread(5,&type,&result) != RTNORM) break;//modified by whl on 041103
|
|
if (ads_grread(13,&type,&result) != RTNORM) break;
|
|
if (type != 5 && type!=3) break;
|
|
pt1[0] = result.resval.rpoint[0];
|
|
pt1[1] = result.resval.rpoint[1];
|
|
pt1[2] = 0.0;
|
|
|
|
if (type==3) {
|
|
if (TextDlg) {
|
|
TextDlg->DestroyWindow();
|
|
delete TextDlg;
|
|
TextDlg = NULL;
|
|
}
|
|
|
|
PickSet s(SS_FREE);
|
|
if (ads_ssget(NULL,pt1,NULL,NULL,s) == RTNORM ) {
|
|
Entity ent=s[0L];
|
|
EditObject(ent);
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (ads_distance(pt1,pt2) > 0) {
|
|
pt2[0] = pt1[0]; pt2[1] = pt1[1]; pt2[2] = pt1[2];
|
|
if (TextDlg) {
|
|
TextDlg->DestroyWindow();
|
|
delete TextDlg;
|
|
TextDlg = NULL;
|
|
}
|
|
PickSet s(SS_FREE);
|
|
if (ads_ssget(NULL,pt1,NULL,NULL,s) != RTNORM ) {
|
|
continue;
|
|
}
|
|
|
|
ads_trans(XPoint(pt1), (resbuf *)&Groups(1), (resbuf *)&Groups(0), 0, pt1);
|
|
|
|
// 构造WCS到Dcs的转换矩阵
|
|
AcGeMatrix3d transWcsToDcs;
|
|
XPoint xAxesWcs(1,0,0), yAxesWcs(0,1,0), zAxesWcs(0,0,1),
|
|
xAxesDcs, yAxesDcs, zAxesDcs;
|
|
XPoint ptOrginWcs(0,0,0), ptOrginDcs(0,0,0);
|
|
Groups fromWcs(0), toDcs(2);
|
|
ads_trans(ptOrginWcs, (resbuf *)&fromWcs, (resbuf *)&toDcs, 0, ptOrginDcs);
|
|
ads_trans(xAxesWcs, (resbuf *)&fromWcs, (resbuf *)&toDcs, 1, xAxesDcs);
|
|
ads_trans(yAxesWcs, (resbuf *)&fromWcs, (resbuf *)&toDcs, 1, yAxesDcs);
|
|
ads_trans(zAxesWcs, (resbuf *)&fromWcs, (resbuf *)&toDcs, 1, zAxesDcs);
|
|
transWcsToDcs.setCoordSystem(ptOrginDcs, xAxesDcs, yAxesDcs, zAxesDcs);
|
|
|
|
|
|
|
|
double nMinDist=0.0;
|
|
Entity entNearest;
|
|
long lCount=s.Length();
|
|
for(long i=0L; i<lCount; i++) {
|
|
Entity ent=s[i];
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbEntity, pEnt);
|
|
if (!pEnt)
|
|
continue;
|
|
AcGePoint3dArray points;
|
|
XPoint ptTemp;
|
|
pEnt->getOsnapPoints(AcDb::kOsModeNear, 0, pt1, ptTemp, transWcsToDcs, points, AcDbIntArray());
|
|
XPoint ptNear;
|
|
if (!GetNearestPoint(points, pt1, ptNear))
|
|
continue;
|
|
ptNear.z=pt1.z;
|
|
double nDist=ptNear.Distance(pt1);
|
|
if (!entNearest || nDist<nMinDist) {
|
|
entNearest=ent;
|
|
nMinDist=nDist;
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
if (!entNearest) {
|
|
if (lCount>0)
|
|
entNearest=s[0L];
|
|
if (!entNearest)
|
|
continue;
|
|
}
|
|
|
|
DList<TObjInfoUnit> lstInfo;
|
|
OPENOBJ_BEGIN(entNearest, AcDb::kForRead, AcDbEntity, pEnt);
|
|
if (!pEnt)
|
|
continue;
|
|
|
|
if (pEnt->isKindOf(TDbEntity::desc())) {
|
|
TDbEntity *pDbEntity = (TDbEntity *) pEnt;
|
|
pDbEntity->GetTips(lstInfo);
|
|
lstInfo.Append(new TObjInfoUnit(_T("比例"), XString(_T("%.0f"), pDbEntity->GetPScale())));
|
|
|
|
} else if (pEnt->isKindOf(TDbCurveEntity::desc())) {
|
|
TDbCurveEntity *pDbEntity = (TDbCurveEntity *) pEnt;
|
|
pDbEntity->GetTips(lstInfo);
|
|
lstInfo.Append(new TObjInfoUnit(_T("比例"), XString(_T("%.0f"), pDbEntity->GetPScale())));
|
|
} else if (pEnt->isKindOf(TDbBlockInsert::desc())) {
|
|
((TDbBlockInsert *) pEnt)->GetTips(lstInfo);
|
|
//} else if (GetUnitHatchTips(pEnt->objectId(), Text)==Acad::eOk) {
|
|
}
|
|
|
|
//if (!Text.IsEmpty())
|
|
// Text += _T("\n-------------\n");
|
|
|
|
AcRxClass *pRxClass=pEnt->isA();
|
|
lstInfo.Append(new TObjInfoUnit(_T("DXF类型"), pRxClass->dxfName()));
|
|
|
|
TCHAR *pszLayer=pEnt->layer();
|
|
if (pszLayer) {
|
|
lstInfo.Append(new TObjInfoUnit(_T("图层"), pszLayer));
|
|
delete [] pszLayer;
|
|
}
|
|
|
|
int nColor=pEnt->colorIndex();
|
|
XString sColorDesc;
|
|
switch(nColor) {
|
|
case 0: sColorDesc=_T("随块"); break;
|
|
case 1: sColorDesc=_T("红色(1)"); break;
|
|
case 2: sColorDesc=_T("黄色(2)"); break;
|
|
case 3: sColorDesc=_T("绿色(3)"); break;
|
|
case 4: sColorDesc=_T("青色(4)"); break;
|
|
case 5: sColorDesc=_T("蓝色(5)"); break;
|
|
case 6: sColorDesc=_T("粉红(6)"); break;
|
|
case 7: sColorDesc=_T("白色(7)"); break;
|
|
case 256: sColorDesc=_T("随层"); break;
|
|
default: sColorDesc<<nColor; break;
|
|
}
|
|
lstInfo.Append(new TObjInfoUnit(_T("颜色"), sColorDesc));
|
|
|
|
TCHAR *pszLType=pEnt->linetype();
|
|
if (pszLType) {
|
|
lstInfo.Append(new TObjInfoUnit(_T("线型"), pszLType));
|
|
delete [] pszLType;
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
CPoint pt;
|
|
int cvport;
|
|
VERIFY(xg_getvar(_T("CVPORT"), &cvport)==RTNORM);
|
|
acedCoordFromWorldToPixel(cvport, pt1, pt);
|
|
acedGetAcadDwgView()->ClientToScreen(&pt);
|
|
acedGetAcadFrame()->ScreenToClient(&pt);
|
|
TextDlg = new CObjectTipWnd();
|
|
TextDlg->Create(lstInfo,pt.x+pickbox*2,pt.y+pickbox*2);
|
|
}
|
|
}
|
|
|
|
if (TextDlg != NULL) {
|
|
TextDlg->DestroyWindow();
|
|
delete TextDlg;
|
|
}
|
|
DocSetWallOsnapType(OsnapWallType);
|
|
}
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|