注册 登录
明经CAD社区 返回首页

风树的个人空间 http://www.mjtd.com/?408117 [收藏] [复制] [分享] [RSS]

日志

(源码)被上一篇标题栏类调用的AcEdInputPointMonitor类

已有 4129 次阅读2013-11-20 20:49 |系统分类:应用

给初接触的同学一些参考例子。

实现相对很长,但都是些重复操作,禁用了多重显示。
//头文件
// (C) Copyright 2001-2007 by Autodesk, Inc. 
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted, 
// provided that the above copyright notice appears in all copies and 
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting 
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to 
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
//////////////////////////////////////////////////////////////////////////////
//
// AcEdInputPointMonitor

#if !defined(ARX__ASDKIPM_H__19990505_132529)
#define ARX__ASDKIPM_H__19990505_132529

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "acedinpt.h"
//特性:AcEdInputPointMonitor_xtcow对象每次可以用new AcEdInputPointMonitor_xtcow(std::wstring class_name_,AcApDocument* pDoc = curDoc());
//形式生成,但在进程中只存在一个实例,直到cad进程结束,实例销毁
using namespace xtcow;
namespace xtcow
{
class AcEdInputPointMonitor_xtcow : public AcEdInputPointMonitor
{
public:
//需要显示的类,这个某种程度上是多余的
static std::set<std::wstring> class_name;
static std::set<AcApDocument*> pDoc;//记录哪个文档AcEdInputPointMonitor_xtcow已经加入过
static AcEdInputPointMonitor_xtcow* m_pIPM;//记录cad进程中是否生成过AcEdInputPointMonitor_xtcow
static std::wstring text;
public:
AcEdInputPointMonitor_xtcow();
virtual ~AcEdInputPointMonitor_xtcow();

virtual bool excludeFromOsnapCalculation(const AcArray<AcDbObjectId>& nestedEntity,
INT_PTR gsSelectionMark);
virtual Acad::ErrorStatus monitorInputPoint(
bool& bAppendToTooltipStr,
TCHAR*& pAdditionalTooltipString,
AcGiViewportDraw* pDrawContext,
AcApDocument* pDocument,
bool pointComputed,
int history,
const AcGePoint3d& lastPoint,
const AcGePoint3d& rawPoint,
const AcGePoint3d& grippedPoint,
const AcGePoint3d& cartesianSnappedPoint,
const AcGePoint3d& osnappedPoint,
AcDb::OsnapMask osnapMask,
const AcArray<AcDbCustomOsnapMode*>& customOsnapModes,
AcDb::OsnapMask osnapOverrides,
const AcArray<AcDbCustomOsnapMode*>& customOsnapOverrides,
const AcArray<AcDbObjectId>& apertureEntities,
const AcArray< AcDbObjectIdArray,
AcArrayObjectCopyReallocator< AcDbObjectIdArray > >& nestedApertureEntities,
const AcArray<INT_PTR>& gsSelectionMark,
const AcArray<AcDbObjectId>& keyPointEntities,
const AcArray< AcDbObjectIdArray,
AcArrayObjectCopyReallocator< AcDbObjectIdArray > >& nestedKeyPointEntities,
const AcArray<INT_PTR>& keyPointGsSelectionMark,
const AcArray<AcGeCurve3d*>& alignmentPaths,
const AcGePoint3d& computedPoint,
const TCHAR* pTooltipString);
public:
//在文档建立时调用或手动被调用
void static build_AcEdInputPointMonitor_xtcow_in_curDoc(AcApDocument* pActivatedDoc=curDoc());
//在文档关闭时调用,也可手动调用
void static delete_AcEdInputPointMonitor_xtcow_in_curDoc(AcApDocument*pActivatedDoc=curDoc());

private:
AcApDocument* m_pDoc;
};
}
#endif // !defined(ARX__ASDKIPM_H__19990505_132529)

//实现文件

// (C) Copyright 2001-2007 by Autodesk, Inc. 
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted, 
// provided that the above copyright notice appears in all copies and 
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting 
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to 
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
//////////////////////////////////////////////////////////////////////////////
//
// AcEdInputPointMonitor

#include "StdAfx.h"
#include "..\..\编程2013\cad2012+arx\函数库\function_for_cad\function_for_cad.h"

#if defined(_DEBUG) && !defined(AC_FULL_DEBUG)
#error _DEBUG should not be defined except in internal Adesk debug builds
#endif
#include "AcEdInputPointMonitor_xtcow.h"
#include "tchar.h"
#ifdef    lower_than_cad_arx_2010
#include "..\..\编程2013\cad2012+arx\画图\dim_xyz\dim_xyz1_2008.h"
#include "..\..\编程2013\cad2012+arx\画图\dim_xyz\Dbx_BLOCK_2008.h"
#else
#include "..\..\编程2013\cad2012+arx\画图\dim_xyz\dim_xyz1.h"
#include "..\..\编程2013\cad2012+arx\画图\dim_xyz\Dbx_BLOCK.h"
#endif
using namespace xtcow;
namespace xtcow
{
std::set<std::wstring> AcEdInputPointMonitor_xtcow::class_name;
//记录哪个文档AcEdInputPointMonitor_xtcow已经加入过
std::set<AcApDocument*> AcEdInputPointMonitor_xtcow::pDoc;
//标记AcEdInputPointMonitor_xtcow是否被实例化过
AcEdInputPointMonitor_xtcow* AcEdInputPointMonitor_xtcow::m_pIPM=0;

std::wstring AcEdInputPointMonitor_xtcow::text;
void AcEdInputPointMonitor_xtcow::build_AcEdInputPointMonitor_xtcow_in_curDoc(AcApDocument* pDoc__)
{
if (m_pIPM == NULL) {
//AcEdInputPointMonitor_xtcow第一次在cad进程中被建立
//多余的,但留住
class_name.insert(AcDb2dPolyline::desc()->name());
class_name.insert(AcDb3dPolyline::desc()->name());
class_name.insert(AcDbArc::desc()->name());
class_name.insert(AcDbCircle::desc()->name());
class_name.insert(AcDbHatch::desc()->name());
class_name.insert(AcDbLine::desc()->name());
class_name.insert(AcDbMline::desc()->name());
class_name.insert(AcDbPolyline::desc()->name());
class_name.insert(AcDbRegion::desc()->name());
class_name.insert(AcDbSpline::desc()->name());
class_name.insert(AcDbEllipse::desc()->name());
class_name.insert(AcDbMText::desc()->name());
class_name.insert(AcDbText::desc()->name());
class_name.insert(AcDbBlockReference::desc()->name());
#ifdef    lower_than_cad_arx_2010
class_name.insert(dim_xyz1_2008::desc()->name());
class_name.insert(Dbx_BLOCK_2008::desc()->name());
#else
class_name.insert(dim_xyz1::desc()->name());
class_name.insert(Dbx_BLOCK::desc()->name());
#endif
int count= pDoc.size();
pDoc.insert(pDoc__);//登记加入过的文档信息
if (pDoc.size()>count)
{
m_pIPM= new AcEdInputPointMonitor_xtcow;//
pDoc__->inputPointManager()->addPointMonitor(m_pIPM);//在该文档加入AcEdInputPointMonitor_xtcow
}

} else
{ //AcEdInputPointMonitor_xtcow已经在cad进程中被建立过
int count= pDoc.size();//静态
pDoc.insert(pDoc__);//静态
if (pDoc.size()>count)//该文档未加入过AcEdInputPointMonitor_xtcow
{
pDoc__->inputPointManager()->addPointMonitor(m_pIPM);
}
}
}
//用来手动清除当前文档的AcEdInputPointMonitor_xtcow注册信息
void  AcEdInputPointMonitor_xtcow::delete_AcEdInputPointMonitor_xtcow_in_curDoc(AcApDocument* pDoc__)
{
//找到当前文档中曾经加入过AcEdInputPointMonitor_xtcow的文档,将AcEdInputPointMonitor_xtcow推出
if (pDoc.find(pDoc__)!=pDoc.end())
{
pDoc__->inputPointManager()->removePointMonitor(m_pIPM);
pDoc.erase(pDoc.find(pDoc__));//懒得写了
return ;
}
};
AcEdInputPointMonitor_xtcow::AcEdInputPointMonitor_xtcow()
{

}

AcEdInputPointMonitor_xtcow::~AcEdInputPointMonitor_xtcow()
{
}

bool
AcEdInputPointMonitor_xtcow::excludeFromOsnapCalculation(const AcArray<AcDbObjectId>& nestedEntity,
INT_PTR gsSelectionMark)
{
 return false;
}
//
// This is where we take advantage of quite a bit of information
// provide by this big function to display multiline tooltip
// (new feature in Acad 2002) under the cursor aperture.
//
// It gets even more interesting when you mix it with OSNAP info.
//
// Have fun!
//
Acad::ErrorStatus 
AcEdInputPointMonitor_xtcow::monitorInputPoint(
bool& bAppendToTooltipStr,
TCHAR*& pAdditionalTooltipString,
AcGiViewportDraw* pDrawContext,
AcApDocument* pDocument,
bool pointComputed,
int history,
const AcGePoint3d& lastPoint,
const AcGePoint3d& rawPoint,
const AcGePoint3d& grippedPoint,
const AcGePoint3d& cartesianSnappedPoint,
const AcGePoint3d& osnappedPoint,
AcDb::OsnapMask osnapMask,
const AcArray<AcDbCustomOsnapMode*>& customOsnapModes,
AcDb::OsnapMask osnapOverrides,
const AcArray<AcDbCustomOsnapMode*>& customOsnapOverrides,
const AcArray<AcDbObjectId>& apertureEntities,
const AcArray< AcDbObjectIdArray,
AcArrayObjectCopyReallocator< AcDbObjectIdArray > >& nestedApertureEntities,
const AcArray<INT_PTR>& gsSelectionMark,
const AcArray<AcDbObjectId>& keyPointEntities,
const AcArray< AcDbObjectIdArray,
AcArrayObjectCopyReallocator< AcDbObjectIdArray > >& nestedKeyPointEntities,
const AcArray<INT_PTR>& keyPointGsSelectionMark,
const AcArray<AcGeCurve3d*>& alignmentPaths,
const AcGePoint3d& computedPoint,
const TCHAR* pTooltipString)
{
TCHAR mtooltipStr[1024],
tempStr[1000];
mtooltipStr[0] = _T('\0');

Acad::ErrorStatus es;
AcDbEntity* pEnt;
AcDbObjectId highlightId = AcDbObjectId::kNull;
if (pointComputed)
{
// Analyze the aperture entities.
if (apertureEntities.length() > 0)
{
if(_tcslen(mtooltipStr) > 0)
_tcscpy(mtooltipStr, _T(""));
else
_tcscpy(mtooltipStr, _T(""));

for (int i = 0; i <1 ; ++i)//禁用了多重显示
{
if (Acad::eOk != (es = acdbOpenAcDbEntity(pEnt, apertureEntities[i], AcDb::kForRead)))
continue;
#ifdef    lower_than_cad_arx_2010
if (pEnt->isKindOf(dim_xyz1_2008::desc())||pEnt->isKindOf(Dbx_BLOCK_2008::desc()))
text.clear();
text.append(_T("\n "));
text.append(_T("类型: "));
if (pEnt->isKindOf(dim_xyz1_2008::desc()))
{
text.append(__T("动态坐标标注"));
}
else
{
text.append(__T("局部放大标注"));
}
text.append(_T("\n "));
text.append(_T("<图层:"));
text.append(pEnt->layer());
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<颜色:"));
if (pEnt->color().isByBlock())
{
text.append(_T("随块 "));
}
else if (pEnt->color().isByLayer())
{
text.append(_T("随层 "));
}else 
{
text.append(_T("自定义 "));
}
text.append(_T(">"));
//
_stprintf(tempStr, _T("%s"),text.c_str());
_tcscat(mtooltipStr, tempStr);
pEnt->close();
continue;
}
#else
if (pEnt->isKindOf(dim_xyz1::desc())||pEnt->isKindOf(Dbx_BLOCK::desc()))
text.clear();
text.append(_T("\n "));
text.append(_T("类型: "));
if (pEnt->isKindOf(dim_xyz1::desc()))
{
text.append(__T("动态坐标标注"));
}
else
{
text.append(__T("局部放大标注"));
}
//
//
text.append(_T("\n "));
text.append(_T("<图层:"));
text.append(pEnt->layer());
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<颜色:"));
if (pEnt->color().isByBlock())
{
text.append(_T("随块 "));
}
else if (pEnt->color().isByLayer())
{
text.append(_T("随层 "));
}else 
{
text.append(_T("自定义 "));
}
text.append(_T(">"));
//
_stprintf(tempStr, _T("%s"),text.c_str());
_tcscat(mtooltipStr, tempStr);
pEnt->close();
continue;
}

#endif
else if (pEnt->isKindOf(AcDbRegion::desc()))
text.clear();
text.append(_T("\n "));
text.append(_T("类型: "));
text.append(pEnt->isA()->name());
//
text.append(_T("\n "));
text.append(_T("<图层:"));
text.append(pEnt->layer());
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<颜色:"));
if (pEnt->color().isByBlock())
{
text.append(_T("随块 "));
}
else if (pEnt->color().isByLayer())
{
text.append(_T("随层 "));
}else 
{
text.append(_T("自定义 "));
}
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<边界线宽(mm):"));
if(pEnt->lineWeight()==-3)
{
text.append(_T("默认"));

}else if (pEnt->lineWeight()==-2)
{
text.append(_T("随块"));
}else if (pEnt->lineWeight()==-1)
{
text.append(_T("随层"));
}else
{
text.append(double_to_wstring(pEnt->lineWeight(),1));
}
text.append(_T(">"));
//分割线
text.append(_T("\n "));
text.append(_T("---------------------"));
//
text.append(_T("\n "));
text.append(_T("<面积:"));
double regionArea;
(((AcDbRegion*)pEnt))->getArea(regionArea);
text.append(double_to_wstring(regionArea,4));
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<周长:"));
double Perimeter;
(((AcDbRegion*)pEnt))->getPerimeter(Perimeter);
text.append(double_to_wstring(Perimeter,4));
text.append(_T(">"));
//
_stprintf(tempStr, _T("%s"),text.c_str());
_tcscat(mtooltipStr, tempStr);
pEnt->close();
continue;
}else if (pEnt->isKindOf(AcDbArc::desc()))
{
text.clear();
text.append(_T("\n "));
text.append(_T("类型: "));
text.append(pEnt->isA()->name());
//
text.append(_T("\n "));
text.append(_T("<图层:"));
text.append(pEnt->layer());
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<颜色:"));
if (pEnt->color().isByBlock())
{
text.append(_T("随块 "));
}
else if (pEnt->color().isByLayer())
{
text.append(_T("随层 "));
}else 
{
text.append(_T("自定义 "));
}
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<线宽:"));
if(pEnt->lineWeight()==-3)
{
text.append(_T("默认"));

}else if (pEnt->lineWeight()==-2)
{
text.append(_T("随块"));
}else if (pEnt->lineWeight()==-1)
{
text.append(_T("随层"));
}else
{
text.append(double_to_wstring(pEnt->lineWeight(),1));
}
text.append(_T(">"));
//分割线
text.append(_T("\n "));
text.append(_T("---------------------"));
//
text.append(_T("\n "));
text.append(_T("<弧长:"));
text.append(double_to_wstring(get_length_of_curve((AcDbCurve *)pEnt),4));
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<半径:"));
text.append(double_to_wstring(((AcDbArc *)pEnt)->radius(),4));
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<startAngle:"));
int xD,xM;
double xS,yS,t;
xD = (int)(((AcDbArc *)pEnt)->startAngle()/M_PI*180); //度
t = ((AcDbArc *)pEnt)->startAngle()/M_PI*180- xD;
xM = (int)(t * 60); //分
xS = ((t * 60) - xM) * 60;//秒
text.append(double_to_wstring(xD,0)+_T("度")+double_to_wstring(xM,0)+_T("分")+double_to_wstring(xS,1)+_T("秒"));
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("< endAngle:"));
xD = (int)(((AcDbArc *)pEnt)-> endAngle()/M_PI*180); //度
t = ((AcDbArc *)pEnt)->endAngle()/M_PI*180 - xD;
xM = (int)(t * 60); //分
xS = ((t * 60) - xM) * 60;//秒
text.append(double_to_wstring(xD,0)+_T("度")+double_to_wstring(xM,0)+_T("分")+double_to_wstring(xS,1)+_T("秒"));
text.append(_T(">"));
//
_stprintf(tempStr, _T("%s"),text.c_str());
_tcscat(mtooltipStr, tempStr);
pEnt->close();
continue;
}else if (pEnt->isKindOf(AcDbCircle::desc()))
{
text.clear();
text.append(_T("\n "));
text.append(_T("类型: "));
text.append(pEnt->isA()->name());
//
text.append(_T("\n "));
text.append(_T("<图层:"));
text.append(pEnt->layer());
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<颜色:"));
if (pEnt->color().isByBlock())
{
text.append(_T("随块 "));
}
else if (pEnt->color().isByLayer())
{
text.append(_T("随层 "));
}else 
{
text.append(_T("自定义 "));
}
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<线宽:"));
if(pEnt->lineWeight()==-3)
{
text.append(_T("默认"));

}else if (pEnt->lineWeight()==-2)
{
text.append(_T("随块"));
}else if (pEnt->lineWeight()==-1)
{
text.append(_T("随层"));
}else
{
text.append(double_to_wstring(pEnt->lineWeight(),1));
}
text.append(_T(">"));
//分割线
text.append(_T("\n "));
text.append(_T("---------------------"));
//
text.append(_T("\n "));
text.append(_T("<面积:"));
double a;
((AcDbCircle *)pEnt)->getArea(a);
text.append(double_to_wstring(a,4));
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<长度:"));
text.append(double_to_wstring(get_length_of_curve((AcDbCurve *)pEnt),4));
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<半径:"));
text.append(double_to_wstring(((AcDbCircle *)pEnt)->radius(),4));
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<直径:"));
text.append(double_to_wstring(((AcDbCircle *)pEnt)->radius()*2,4));
text.append(_T(">"));
//
_stprintf(tempStr, _T("%s"),text.c_str());
_tcscat(mtooltipStr, tempStr);
pEnt->close();
continue;
}else if (pEnt->isKindOf(AcDbLine::desc())\
||pEnt->isKindOf(AcDb2dPolyline::desc())\
||pEnt->isKindOf(AcDb3dPolyline::desc())\
||pEnt->isKindOf(AcDbMline::desc())\
||pEnt->isKindOf(AcDbPolyline::desc())\
||pEnt->isKindOf(AcDbSpline::desc())\
)
{
text.clear();
text.append(_T("\n "));
text.append(_T("类型: "));
text.append(pEnt->isA()->name());
//
text.append(_T("\n "));
text.append(_T("<图层:"));
text.append(pEnt->layer());
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<颜色:"));
if (pEnt->color().isByBlock())
{
text.append(_T("随块 "));
}
else if (pEnt->color().isByLayer())
{
text.append(_T("随层 "));
}else 
{
text.append(_T("自定义 "));
}
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<线宽:"));
if(pEnt->lineWeight()==-3)
{
text.append(_T("默认"));

}else if (pEnt->lineWeight()==-2)
{
text.append(_T("随块"));
}else if (pEnt->lineWeight()==-1)
{
text.append(_T("随层"));
}else
{
text.append(double_to_wstring(pEnt->lineWeight(),1));
}
text.append(_T(">"));
//分割线
text.append(_T("\n "));
text.append(_T("---------------------"));
//
//
AcGePoint3d st;
AcGePoint3d en;
((AcDbCurve *)pEnt)->getStartPoint(st); 
((AcDbCurve *)pEnt)->getEndPoint(en);
if (st==en)
{
text.append(_T("\n "));
text.append(_T("<形态闭合,面积:"));
double a;
((AcDbCurve *)pEnt)->getArea(a);
text.append(double_to_wstring(a,4));
text.append(_T(">"));
}
else
{
text.append(_T("\n "));
text.append(_T("<形态非闭合>"));
}
//
text.append(_T("\n "));
text.append(_T("<长度:"));
double length =get_length_of_curve((AcDbCurve *)pEnt);
if (length==0)
{
continue;
}
text.append(double_to_wstring(length,4));
text.append(_T(">"));
//
_stprintf(tempStr, _T("%s"),text.c_str());
_tcscat(mtooltipStr, tempStr);
pEnt->close();
continue;
}else if (pEnt->isKindOf(AcDbEllipse::desc()))
{
text.clear();
text.append(_T("\n "));
text.append(_T("类型: "));
text.append(pEnt->isA()->name());
//
text.append(_T("\n "));
text.append(_T("<图层:"));
text.append(pEnt->layer());
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<颜色:"));
if (pEnt->color().isByBlock())
{
text.append(_T("随块 "));
}
else if (pEnt->color().isByLayer())
{
text.append(_T("随层 "));
}else 
{
text.append(_T("自定义 "));
}
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<线宽:"));
if(pEnt->lineWeight()==-3)
{
text.append(_T("默认"));

}else if (pEnt->lineWeight()==-2)
{
text.append(_T("随块"));
}else if (pEnt->lineWeight()==-1)
{
text.append(_T("随层"));
}else
{
text.append(double_to_wstring(pEnt->lineWeight(),1));
}
text.append(_T(">"));
//分割线
text.append(_T("\n "));
text.append(_T("---------------------"));
//
text.append(_T("\n "));
text.append(_T("<面积:"));
double a;
((AcDbEllipse *)pEnt)->getArea(a);
text.append(double_to_wstring(a,4));
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<长度:"));
text.append(double_to_wstring(get_length_of_curve((AcDbEllipse *)pEnt),4));
text.append(_T(">"));
//
_stprintf(tempStr, _T("%s"),text.c_str());
_tcscat(mtooltipStr, tempStr);
pEnt->close();
continue;
}else if (pEnt->isKindOf(AcDbMText::desc()))
{
text.clear();
text.append(_T("\n "));
text.append(_T("类型: "));
text.append(pEnt->isA()->name());
//
text.append(_T("\n "));
text.append(_T("<图层:"));
text.append(pEnt->layer());
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<颜色:"));
if (pEnt->color().isByBlock())
{
text.append(_T("随块 "));
}
else if (pEnt->color().isByLayer())
{
text.append(_T("随层 "));
}else 
{
text.append(_T("自定义 "));
}
text.append(_T(">"));
//分割线
text.append(_T("\n "));
text.append(_T("---------------------"));
//
text.append(_T("\n "));
text.append(_T("<文字高度:"));
text.append(double_to_wstring(((AcDbMText *)pEnt)->textHeight(),2));
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<角度(度):"));
text.append(double_to_wstring(((AcDbMText *)pEnt)->rotation()/M_PI*180,5));
text.append(_T(">"));
_stprintf(tempStr, _T("%s"),text.c_str());
_tcscat(mtooltipStr, tempStr);
pEnt->close();
continue;
}
else if (pEnt->isKindOf(AcDbText::desc()))
{
text.clear();
text.append(_T("\n "));
text.append(_T("类型: "));
text.append(pEnt->isA()->name());
//
text.append(_T("\n "));
text.append(_T("<图层:"));
text.append(pEnt->layer());
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<颜色:"));
if (pEnt->color().isByBlock())
{
text.append(_T("随块 "));
}
else if (pEnt->color().isByLayer())
{
text.append(_T("随层 "));
}else 
{
text.append(_T("自定义 "));
}
text.append(_T(">"));
//分割线
text.append(_T("\n "));
text.append(_T("---------------------"));
//
text.append(_T("\n "));
text.append(_T("<文字高度:"));
text.append(double_to_wstring(((AcDbText *)pEnt)->height(),2));
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<角度(度):"));
text.append(double_to_wstring(((AcDbText *)pEnt)->rotation()/M_PI*180,5));
text.append(_T(">"));
//
_stprintf(tempStr, _T("%s"),text.c_str());
_tcscat(mtooltipStr, tempStr);
pEnt->close();
continue;
}else if (pEnt->isKindOf(AcDbBlockReference::desc()))
{
text.clear();
text.append(_T("\n "));
text.append(_T("类型: "));
text.append(pEnt->isA()->name());
//
text.append(_T("\n "));
text.append(_T("<图层:"));
text.append(pEnt->layer());
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<颜色:"));
if (pEnt->color().isByBlock())
{
text.append(_T("随块 "));
}
else if (pEnt->color().isByLayer())
{
text.append(_T("随层 "));
}else 
{
text.append(_T("自定义 "));
}
text.append(_T(">"));
//分割线
text.append(_T("\n "));
text.append(_T("---------------------"));
//
AcDbObjectId Id=((AcDbBlockReference*)pEnt)->blockTableRecord(); //得到AcDbBlockTableRecord 
AcDbBlockTable *pTable = NULL;
if ((es=acdbHostApplicationServices()->workingDatabase()->getBlockTable(pTable, AcDb::kForRead))==Acad::eOk)
{
//定义块表记录指针pBTableRec
AcDbBlockTableRecord *pBTableRec;
//定义遍历块表的浏览器,获得指向块表浏览器指针
AcDbBlockTableIterator *pBIterator = NULL;
pTable->newIterator(pBIterator);
//利用循环结构和块表浏览器遍历块表
for(pBIterator->start();!pBIterator->done();pBIterator->step())
{//调用块表浏览器的成员函数getRecord获得指向块表记录的指针
pBIterator->getRecord(pBTableRec,AcDb::kForRead,Adesk::kFalse);
if (pBTableRec->id()==Id)
{
ACHAR *blockname_=0;
pBTableRec->getName(blockname_);//得到块名
text.append(_T("\n "));
text.append(_T("<块名:"));
text.append(blockname_);
text.append(_T(">"));
pBTableRec->close();
break;
}
pBTableRec->close();        
}
delete pBIterator;
pTable->close();
}
//
AcGeScale3d  Scale= ((AcDbBlockReference*)pEnt)->scaleFactors();
text.append(_T("\n "));
text.append(_T("<比例X:"));
text.append(double_to_wstring(Scale.sx,2));
text.append(_T(">"));
text.append(_T("\n "));
text.append(_T("<比例Y:"));
text.append(double_to_wstring(Scale.sy,2));
text.append(_T(">"));
text.append(_T("\n "));
text.append(_T("<比例Z:"));
text.append(double_to_wstring(Scale.sz,2));
text.append(_T(">"));
_stprintf(tempStr, _T("%s"),text.c_str());
_tcscat(mtooltipStr, tempStr);
pEnt->close();
continue;
}else if (pEnt->isKindOf(AcDbCurve::desc()))
{
text.clear();
text.append(_T("\n "));
text.append(_T("类型: "));
text.append(pEnt->isA()->name());
//
text.append(_T("\n "));
text.append(_T("<图层:"));
text.append(pEnt->layer());
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<颜色:"));
if (pEnt->color().isByBlock())
{
text.append(_T("随块 "));
}
else if (pEnt->color().isByLayer())
{
text.append(_T("随层 "));
}else 
{
text.append(_T("自定义 "));
}
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<线宽:"));
if(pEnt->lineWeight()==-3)
{
text.append(_T("默认"));

}else if (pEnt->lineWeight()==-2)
{
text.append(_T("随块"));
}else if (pEnt->lineWeight()==-1)
{
text.append(_T("随层"));
}else
{
text.append(double_to_wstring(pEnt->lineWeight(),1));
}
text.append(_T(">"));
//分割线
text.append(_T("\n "));
text.append(_T("---------------------"));
//
//
AcGePoint3d st;
AcGePoint3d en;
((AcDbCurve *)pEnt)->getStartPoint(st); 
((AcDbCurve *)pEnt)->getEndPoint(en);
if (st==en)
{
text.append(_T("\n "));
text.append(_T("<形态闭合,面积:"));
double a;
((AcDbCurve *)pEnt)->getArea(a);
text.append(double_to_wstring(a,4));
text.append(_T(">"));
}
else
{
text.append(_T("\n "));
text.append(_T("<形态非闭合>"));
}
//
text.append(_T("\n "));
text.append(_T("<长度:"));
double length =get_length_of_curve((AcDbCurve *)pEnt);//get_length_of_curve时注意要辨别闭合曲线
if (length==0)
{
continue;
}
text.append(double_to_wstring(length,4));
text.append(_T(">"));
//
_stprintf(tempStr, _T("%s"),text.c_str());
_tcscat(mtooltipStr, tempStr);
pEnt->close();
continue;

}else if (pEnt->isKindOf(AcDb3dSolid::desc()))
{
text.clear();
text.append(_T("\n "));
text.append(_T("类型: "));
text.append(pEnt->isA()->name());
//
text.append(_T("\n "));
text.append(_T("<图层:"));
text.append(pEnt->layer());
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<颜色:"));
if (pEnt->color().isByBlock())
{
text.append(_T("随块 "));
}
else if (pEnt->color().isByLayer())
{
text.append(_T("随层 "));
}else 
{
text.append(_T("自定义 "));
}
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<线宽:"));
if(pEnt->lineWeight()==-3)
{
text.append(_T("默认"));

}else if (pEnt->lineWeight()==-2)
{
text.append(_T("随块"));
}else if (pEnt->lineWeight()==-1)
{
text.append(_T("随层"));
}else
{
text.append(double_to_wstring(pEnt->lineWeight(),1));
}
text.append(_T(">"));
//分割线
text.append(_T("\n "));
text.append(_T("---------------------"));
//
_stprintf(tempStr, _T("%s"),text.c_str());
_tcscat(mtooltipStr, tempStr);
pEnt->close();
continue;

}else if (pEnt->isKindOf(AcDbSolid::desc()))
{
text.clear();
text.append(_T("\n "));
text.append(_T("类型: "));
text.append(pEnt->isA()->name());
//
text.append(_T("\n "));
text.append(_T("<图层:"));
text.append(pEnt->layer());
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<颜色:"));
if (pEnt->color().isByBlock())
{
text.append(_T("随块 "));
}
else if (pEnt->color().isByLayer())
{
text.append(_T("随层 "));
}else 
{
text.append(_T("自定义 "));
}
text.append(_T(">"));
//
text.append(_T("\n "));
text.append(_T("<线宽:"));
if(pEnt->lineWeight()==-3)
{
text.append(_T("默认"));

}else if (pEnt->lineWeight()==-2)
{
text.append(_T("随块"));
}else if (pEnt->lineWeight()==-1)
{
text.append(_T("随层"));
}else
{
text.append(double_to_wstring(AcDbSolid::cast(pEnt)->lineWeight(),1));
}
text.append(_T(">"));
//分割线
text.append(_T("\n "));
text.append(_T("---------------------"));
text.append(_T("\n "));
text.append(_T("<厚度:"));
text.append(double_to_wstring(AcDbSolid::cast(pEnt)->thickness(),1));
text.append(_T(">"));
//
_stprintf(tempStr, _T("%s"),text.c_str());
_tcscat(mtooltipStr, tempStr);
pEnt->close();
continue;

}
// Analyze the nested aperture entities.
AcDbObjectIdArray nestedIds = nestedApertureEntities[i];
int length = nestedIds.length();
if (length > 1)
{
// There is a nested entitiy: get it.
AcDbEntity* pEnt2;
if (Acad::eOk == (es = acdbOpenAcDbEntity(pEnt2, nestedIds[length - 1], AcDb::kForRead))) {
_stprintf(tempStr, _T("\n  nested: %s"), pEnt2->isA()->name());
_tcscat(mtooltipStr, tempStr);
pEnt2->close();
}
}
else
{
pEnt->close();
}
}
highlightId = apertureEntities[0];
}
}
// Do highlighting, only the top level entity is highlighted.
static AcDbObjectId oldHighlightId = AcDbObjectId::kNull;
if(highlightId != oldHighlightId)
{
if (AcDbObjectId::kNull != oldHighlightId)
{
es = acdbOpenAcDbEntity(pEnt, oldHighlightId, AcDb::kForRead);
if (es == Acad::eOk)
{
es = pEnt->unhighlight();
pEnt->close();
oldHighlightId = AcDbObjectId::kNull;
}
}
es = acdbOpenAcDbEntity(pEnt, highlightId, AcDb::kForRead);
if (es == Acad::eOk)
{
es = pEnt->highlight();
pEnt->close();
oldHighlightId = highlightId;
}
}

// Turn on additional tooltip.
bAppendToTooltipStr = true;
pAdditionalTooltipString = _tcsdup(mtooltipStr);
return Acad::eOk;
}
}




路过

雷人

握手

鲜花

鸡蛋

发表评论 评论 (1 个评论)

回复 风树 2014-7-6 23:24
以上代码可以精简很多,当时复制粘贴用习惯了

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-12 04:24 , Processed in 0.117811 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部