- 积分
- 14526
- 明经币
- 个
- 注册时间
- 2011-12-24
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
//-----------------------------------------------------------------------------
#include "dbmain.h"
//-----------------------------------------------------------------------------
class DLLIMPEXP dim_xyz1 : public AcDbEntity {
public:
ACRX_DECLARE_MEMBERS(dim_xyz1) ;
protected:
static Adesk::UInt32 kCurrentVersionNumber ;
public:
dim_xyz1 () ;
virtual ~dim_xyz1 () ;
//----- AcDbObject protocols
//- Dwg Filing protocol
virtual Acad::ErrorStatus dwgOutFields (AcDbDwgFiler *pFiler) const ;
virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler *pFiler) ;
//----- AcDbEntity protocols
//- Graphics protocol
protected:
virtual Adesk::Boolean subWorldDraw (AcGiWorldDraw *mode) ;
virtual Adesk::UInt32 subSetAttributes (AcGiDrawableTraits *traits) ;
//- Osnap points protocol
public:
virtual Acad::ErrorStatus subGetOsnapPoints (
AcDb::OsnapMode osnapMode,
int gsSelectionMark,
const AcGePoint3d &pickPoint,
const AcGePoint3d &lastPoint,
const AcGeMatrix3d &viewXform,
AcGePoint3dArray &snapPoints,
AcDbIntArray &geomIds) const ;
//- Grip points protocol
virtual Acad::ErrorStatus subGetGripPoints (AcGePoint3dArray &gripPoints, AcDbIntArray &osnapModes, AcDbIntArray &geomIds) const ;
virtual Acad::ErrorStatus subMoveGripPointsAt (const AcDbIntArray &indices, const AcGeVector3d &offset) ;
virtual Acad::ErrorStatus subTransformBy(const AcGeMatrix3d & xform);
AcGePoint3d m_line_begin;
AcGePoint3d m_line_mid;
AcGePoint3d m_line_end;
CString m_Text1;
CString m_Text2;
AcGePoint3d m_textbase_s;
AcGePoint3d m_textbase_x;
double TextSize;
} ;
#ifdef My_MODULE
ACDB_REGISTER_OBJECT_ENTRY_AUTO(dim_xyz1)
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//----- dim_xyz1.cpp : Implementation of dim_xyz1
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "dim_xyz1.h"
//-----------------------------------------------------------------------------
Adesk::UInt32 dim_xyz1::kCurrentVersionNumber =1 ;
//-----------------------------------------------------------------------------
ACRX_DXF_DEFINE_MEMBERS (
dim_xyz1, AcDbEntity,
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
AcDbProxyEntity::kNoOperation, DIM_XYZ1,
XTCOWMYAPP
|Product Desc: A description for your object
|Company: Your company name
|WEB Address: Your company WEB site address
)
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
dim_xyz1::dim_xyz1 () : AcDbEntity () {
}
dim_xyz1::~dim_xyz1 () {
}
//-----------------------------------------------------------------------------
//----- AcDbObject protocols
//- Dwg Filing protocol
Acad::ErrorStatus dim_xyz1::dwgOutFields (AcDbDwgFiler *pFiler) const {
assertReadEnabled () ;
//----- Save parent class information first.
Acad::ErrorStatus es =AcDbEntity::dwgOutFields (pFiler) ;
if ( es != Acad::eOk )
return (es) ;
//----- Object version number needs to be saved first
if ( (es =pFiler->writeUInt32 (dim_xyz1::kCurrentVersionNumber)) != Acad::eOk )
return (es) ;
//----- Output params
//.....
return (pFiler->filerStatus ()) ;
}
Acad::ErrorStatus dim_xyz1::dwgInFields (AcDbDwgFiler *pFiler) {
assertWriteEnabled () ;
//----- Read parent class information first.
Acad::ErrorStatus es =AcDbEntity::dwgInFields (pFiler) ;
if ( es != Acad::eOk )
return (es) ;
//----- Object version number needs to be read first
Adesk::UInt32 version =0 ;
if ( (es =pFiler->readUInt32 (&version)) != Acad::eOk )
return (es) ;
if ( version > dim_xyz1::kCurrentVersionNumber )
return (Acad::eMakeMeProxy) ;
//- Uncomment the 2 following lines if your current object implementation cannot
//- support previous version of that object.
//if ( version < dim_xyz::kCurrentVersionNumber )
// return (Acad::eMakeMeProxy) ;
//----- Read params
//.....
return (pFiler->filerStatus ()) ;
}
//-----------------------------------------------------------------------------
//----- AcDbEntity protocols
Adesk::Boolean dim_xyz1::subWorldDraw (AcGiWorldDraw *mode) {//AcGiWorldDraw类提供产生几何体对而不随视口改变的功能。
assertReadEnabled () ;
// Bounding Polyline
AcGePoint3d pts[3];
pts[0] = m_line_begin;
pts[1] = m_line_mid;
pts[2] = m_line_end;
AcGePoint3d text[2];
text[0] = m_textbase_s;
text[1] = m_textbase_x;
// mode->subEntityTraits()提取AcGiSubEntityTraits类,此类用于控制图形元素当前的颜色、层、线型、填充类型和图形系统标记的属性值。
mode->subEntityTraits().setSelectionMarker(1);// Mark 1
//设置AcGiSubEntityTraits对象使所有已绘出的图形元素使用markerId作为图形标记,这个图形元素的标记一直作用至再次调用这个函数或当前的worldDraw()
//或viewportDraw()执行结束后。
//警告:基于AutoCAD图形系统的性能优化,在自己的worldDraw()或viewportDraw()方法中设置选择标记定制的实体类必须在任何AcGiWorldGeometry或AcGiViewprotGeometry
//几何体创建方法(包括mesh()或shell())被调用之前通过调用AcGiSubEntityTraits::setSelectionMarker()设置第一个选择标记。
mode->subEntityTraits().setColor(1); // Red
mode->geometry().polyline(3,pts);//mode->geometry()调出AcGiWorldGeometry类画线
// Entity's Text
mode->subEntityTraits().setSelectionMarker(2); // Mark 2
mode->subEntityTraits().setColor(1); // Red
AcGiTextStyle style;//注意此类用于设置设置文本的显示属性。它作为一个参数传递给一个AcGiGeometry::text()的成员函数。
style.setFileName(_T("txt.shx"));//设置"txt.shx" style
style.setBigFontFileName(_T(""));//
style.setTextSize(TextSize);//设置文字大小
style.loadStyleRec();//此函数加载一个字体(不是一个样式),在AcGiTextStyle::setFileName()或 AcGiTextStyle::setBigFontFileName()设置了字体文件名后运行。此函数必须在加载一个True Type字体(TTF)后运行。
AcGePoint3d txtPt1(text[0].x+1,text[0].y+1,text[0].z) ;
mode->geometry().text(txtPt1, AcGeVector3d::kZAxis,pts[2]-pts[1],m_Text1,m_Text1.GetLength(),Adesk::kFalse, style);
mode->subEntityTraits().setSelectionMarker(3); // Mark 3
mode->subEntityTraits().setColor(1); // Red
//AcGiTextStyle style;//注意此类用于设置设置文本的显示属性。它作为一个参数传递给一个AcGiGeometry::text()的成员函数。
style.setFileName(_T("txt.shx"));//设置"txt.shx" style
style.setBigFontFileName(_T(""));//
style.setTextSize(TextSize);//设置文字大小
style.loadStyleRec();//此函数加载一个字体(不是一个样式),在AcGiTextStyle::setFileName()或 AcGiTextStyle::setBigFontFileName()设置了字体文件名后运行。此函数必须在加载一个True Type字体(TTF)后运行。
AcGePoint3d txtPt2(text[0].x+1,text[0].y-1-TextSize,text[0].z) ;
mode->geometry().text(txtPt2, AcGeVector3d::kZAxis,pts[2]-pts[1],m_Text1,m_Text1.GetLength(),Adesk::kFalse, style);
return (AcDbEntity::subWorldDraw (mode)) ;
}
Adesk::UInt32 dim_xyz1::subSetAttributes (AcGiDrawableTraits *traits) {
assertReadEnabled () ;
return (AcDbEntity::subSetAttributes (traits)) ;
}
//- Osnap points protocol
/** 获得捕捉点,这里添加一个中心点
* @param -
* @author
* @date
* @retval -
* @note 这里仅用第一个变量,虽捕捉到,但是有点问题,鼠标移开后就没有了
* This OSNAP solution handles only simple OSNAP types like CENTER, MIDPOINT and
* ENDPOINT. Complex OSNAP modes like INTERSECTION require other methods implementations and
* some additional procedures
* 求解步聚:-
*/
Acad::ErrorStatus dim_xyz1::subGetOsnapPoints (
AcDb::OsnapMode osnapMode,
int gsSelectionMark,
const AcGePoint3d &pickPoint,
const AcGePoint3d &lastPoint,
const AcGeMatrix3d &viewXform,
AcGePoint3dArray &snapPoints,
AcDbIntArray &geomIds) const
{
assertReadEnabled () ;
switch (osnapMode) {
case AcDb::kOsModeEnd://端点
snapPoints.append(m_line_begin);
snapPoints.append(m_line_mid);
break;
}
return (AcDbEntity::subGetOsnapPoints (osnapMode, gsSelectionMark, pickPoint, lastPoint, viewXform, snapPoints, geomIds)) ;
}
/** 获得夹点,
* @param -
* @author
* @date
* @retval -
* @note -
* 求解步聚:-
*/
//- Grip points protocol
Acad::ErrorStatus dim_xyz1::subGetGripPoints (
AcGePoint3dArray &gripPoints, AcDbIntArray &osnapModes, AcDbIntArray &geomIds) const {
assertReadEnabled () ;
//----- This method is never called unless you return eNotImplemented
//----- from the new getGripPoints() method below (which is the default implementation)
gripPoints.append(m_line_begin);
return (AcDbEntity::subGetGripPoints (gripPoints, osnapModes, geomIds)) ;
}
/** 移动夹点
* @param -
* @author CG
* @date 11/4/2011
* @retval -
* @note -
* 求解步聚:-
*/
Acad::ErrorStatus dim_xyz1::subMoveGripPointsAt (const AcDbIntArray &indices, const AcGeVector3d &offset) {
assertWriteEnabled () ;
//----- This method is never called unless you return eNotImplemented
//----- from the new moveGripPointsAt() method below (which is the default implementation)
assertWriteEnabled();
for(int i=0; i<indices.length(); i++)
{
int idx = indices.at(i);
//
if (idx==0) m_line_begin += offset;
//
if (idx==1) {m_line_mid += offset;m_line_end += offset;}
//
//if (idx==2) m_line_end += offset;
}
return (AcDbEntity::subMoveGripPointsAt (indices, offset)) ;
}
/** 实体的移动、旋转、缩放等等
* @param -
* @author
* @date
* @retval -
* @note -
* 求解步聚:-
*/
Acad::ErrorStatus dim_xyz1::subTransformBy(const AcGeMatrix3d & xform)
{
m_line_begin.transformBy(xform);
m_line_mid.transformBy(xform);
m_line_end.transformBy(xform);
m_textbase_s.transformBy(xform);
m_textbase_x.transformBy(xform);
return (Acad::eOk) ;
}
|
|