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

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

日志

(源码)动态标注平面坐标

已有 1261 次阅读2013-11-19 12:32 |系统分类:应用| 动态, 平面

      自己做的第一个cad自定义实体的例子,提供给想学习的同学一些参考。
      程序能正常运行,但有的变量、处理并不一定需要这样做,也不想再动这个类了,知道意思就可以,不好的地方请包涵。
以下是2007-2009版本的代码:
//调用例子
//acedGetReal判断输入结果部分写繁琐了(局部重复),但无逻辑错误
static void xtcowcad86(void)
{
acDocManager->lockDocument(acDocManager->curDocument(),AcAp::kWrite);//解除上面的锁定
for(;;)
{
   int i=0;
double nReturn_=0;
int Re = acedGetReal(_T("\n请输入标注的文字高度,如需转换精度请输入(-1)\n"), &nReturn_);
if(nReturn_!=-1)
{//空格或esc时,或数值
if((nReturn_>0))//正常输入返回值不为0(空格,0)
{
#ifdef lower_than_cad_arx_2010  
dim_xyz1_2008::texthigh_=nReturn_;
#else
dim_xyz1::texthigh_=nReturn_;
#endif


}else  if(nReturn_== 0)//空格或esc键
{
if(Re == RTNONE)
{
;//空格
}
else if(Re != RTNORM)
{
acutPrintf(_T("用户取消操作1\n"));
break ;
}
}

}
else
{//nReturn==1
i=1;
}
#ifdef lower_than_cad_arx_2010  
if((dim_xyz1_2008::prec_==0)||(i==1))
{
#else
if((dim_xyz1::prec_==0)||(i==1))
{
#endif

double nReturn=0;
int Re = acedGetReal(_T("\n请输入标注精度\n"), &nReturn);
if (Re != RTNORM)
{
acutPrintf(_T("用户取消操作1\n"));
break ;
}
#ifdef lower_than_cad_arx_2010  
dim_xyz1_2008::prec_=nReturn;
#else
dim_xyz1::prec_=nReturn;
#endif
}
#ifdef lower_than_cad_arx_2010  
if(dim_xyz1_2008::texthigh_!=0)
{
dim_xyz1_2008 *H =new dim_xyz1_2008();
if(H->initial(dim_xyz1_2008::prec_,dim_xyz1_2008::texthigh_))
{
AcDbObjectId ObjectId;
ObjectId=AddToModelSpace(H);
H->close();
}else
{
H->close();
}
}
#else
if(dim_xyz1::texthigh_!=0)
{
dim_xyz1 *H =new dim_xyz1();
if(H->initial(dim_xyz1::prec_,dim_xyz1::texthigh_))
{
AcDbObjectId ObjectId;
ObjectId=AddToModelSpace(H);
H->close();
}else
{
H->close();
}
}
#endif
}
SendCmdToAcad((std::wstring)_T("\033\033"));
acDocManager->unlockDocument(acDocManager->curDocument());//解除上面的锁定
}


//头文件
// (C) Copyright 2002-2005 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.
//

//-----------------------------------------------------------------------------
//----- dim_xyz1_2008.h : Declaration of the dim_xyz1_2008
//-----------------------------------------------------------------------------
#pragma once

#ifdef CAD8_MODULE
#define DLLIMPEXP __declspec(dllexport)
#else
//----- Note: we don't use __declspec(dllimport) here, because of the
//----- "local vtable" problem with msvc. If you use __declspec(dllimport),
//----- then, when a client dll does a new on the class, the object's
//----- vtable pointer points to a vtable allocated in that client
//----- dll. If the client dll then passes the object to another dll,
//----- and the client dll is then unloaded, the vtable becomes invalid
//----- and any virtual calls on the object will access invalid memory.
//-----
//----- By not using __declspec(dllimport), we guarantee that the
//----- vtable is allocated in the server dll during the ctor and the
//----- client dll does not overwrite the vtable pointer after calling
//----- the ctor. And, since we expect the server dll to remain in
//----- memory indefinitely, there is no problem with vtables unexpectedly
//----- going away.
#define DLLIMPEXP
#endif

//-----------------------------------------------------------------------------
#include "dbpl.h"

//-----------------------------------------------------------------------------

class DLLIMPEXP dim_xyz1_2008 : public AcDbPolyline {

public:
ACRX_DECLARE_MEMBERS(dim_xyz1_2008) ;

protected:
static Adesk::UInt32 kCurrentVersionNumber ;

public:
dim_xyz1_2008 () ;
virtual ~dim_xyz1_2008 () ;
public:
Acad::ErrorStatus transformBy(const AcGeMatrix3d & xform);
bool get_AcGeMatrix3d_wcs_to_usc (AcGeMatrix3d &);
Acad::ErrorStatus Entity_change(const AcGeMatrix3d & xform);//必需在父类被调用后进行
bool initial(int prec_,double texthigh_);//初始化
protected:
   //以下变量有的并不必须
AcGeMatrix3d mat1;AcGeVector3d vec1;//临时变量
AcGeMatrix3d mat2;AcGeVector3d vec2;//临时变量
AcGeMatrix3d mat3;AcGeVector3d vec3;//临时变量
AcGeMatrix3d mat4;AcGeVector3d vec4;//临时变量

wchar_t dim_x[50];//临时变量
wchar_t dim_y[50];//临时变量
public:
CString format;//初始化标注输出格式
double texthigh;//文字高度
int prec;//输出精度
//提供标记功能
static double texthigh_;//文字高度
static int prec_;//输出精度
//
std::wstring textx;//保存显示的坐标文字标注
std::wstring texty;//保存显示的坐标文字标注

AcGePoint3d Origin;//保存世界坐标系的原点
AcGeVector3d XAxis;//保存世界坐标系的x轴
AcGeVector3d YAxis;//保存世界坐标系的y轴
AcGeVector3d ZAxis;//保存世界坐标系的z轴

AcGePoint3d text_x;//世界坐标系
AcGePoint3d text_y;//世界坐标系

AcGePoint3d point;//世界坐标系,直线第三点
//
public:
enum m_text_type
{
KeXueJiShu=1,
Double=2,
} ;
//----- AcDbObject protocols
//- Dwg Filing protocol
virtual Acad::ErrorStatus dwgOutFields (AcDbDwgFiler *pFiler) const ;
virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler *pFiler) ;
virtual Acad::ErrorStatus explode(AcDbVoidPtrArray & entitySet)const;
virtual Adesk::Boolean worldDraw (AcGiWorldDraw *mode) ;


//- Grip points protocol
virtual Acad::ErrorStatus moveGripPointsAt (const AcDbIntArray &indices, const AcGeVector3d &offset) ;
virtual Acad::ErrorStatus getGripPoints (
AcDbGripDataPtrArray &grips, const double curViewUnitSize, const int gripSize, 
const AcGeVector3d &curViewDir, const int bitflags) const ;
virtual Acad::ErrorStatus moveGripPointsAt (const AcDbVoidPtrArray &gripAppData, const AcGeVector3d &offset, const int bitflags) ;
virtual Acad::ErrorStatus moveStretchPointsAt(const AcDbIntArray& 
                                                 indices,
                                                 const AcGeVector3d& offset);
} ;


#ifdef CAD8_MODULE
ACDB_REGISTER_OBJECT_ENTRY_AUTO(dim_xyz1_2008)
#endif


//实现

// (C) Copyright 2002-2005 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.
//

//-----------------------------------------------------------------------------
//----- dim_xyz1_2008.cpp : Implementation of dim_xyz1_2008
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "dim_xyz1_2008.h"
#include "..\..\..\cad2012+arx\cad系统操作\Select\Select.h"
#include "..\..\..\cad2012+arx\转换\format_change\format_change.h "
using namespace xtcow;
//-----------------------------------------------------------------------------
Adesk::UInt32 dim_xyz1_2008::kCurrentVersionNumber =1 ;

//-----------------------------------------------------------------------------
ACRX_DXF_DEFINE_MEMBERS (
dim_xyz1_2008, AcDbPolyline,
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 
AcDbProxyEntity::kNoOperation, dim_xyz1_2008,
"XTCOWARXPROJECT1APP"
"|Product Desc:     A description for your object"
"|Company:          Your company name"
"|WEB Address:      Your company WEB site address"
)


double dim_xyz1_2008::texthigh_=0;//文字高度
int dim_xyz1_2008::prec_=0;//输出精度
//-----------------------------------------------------------------------------
dim_xyz1_2008::dim_xyz1_2008 () : AcDbPolyline () {
//世界坐标系
Origin.set(0,0,0);
XAxis=AcGeVector3d::kXAxis;
YAxis=AcGeVector3d::kYAxis;
ZAxis=AcGeVector3d::kZAxis;
}
bool dim_xyz1_2008::initial(int prec_,double texthigh_)
{ //

AcGePoint3d Origin1;
AcGeVector3d XAxis1;
AcGeVector3d YAxis1;
AcGeVector3d ZAxis1;
AcGeMatrix3d Matrix;
//
//初始化
prec=prec_;//精度
//格式
format.Append(_T("%0."));
CString a;
a.Format(_T("%d"),prec);
format.Append(a);
format.Append(_T("f"));
//文字高度
texthigh=texthigh_;
// Input information
ads_point pt1,pt2;
if (acedGetPoint(NULL,_T("\n请制定基点:"),pt1) != RTNORM)
return 0;
if (acedGetPoint(pt1,_T("\n请指定引线位置:"),pt2) != RTNORM)
return 0;

//获得从当期坐标系xform到世界坐标系的转换矩阵form。
AcGeMatrix3d xform;
acdbUcsMatrix(xform);
xform.getCoordSystem(Origin1,XAxis1,YAxis1,ZAxis1);
AcGeMatrix3d form;
form.setCoordSystem(Origin1,XAxis1,YAxis1,ZAxis1);
//点转换
AcGePoint3d P1=asPnt3d(pt1);
AcGePoint3d P2=asPnt3d(pt2);
P1.transformBy(form);
P2.transformBy(form);
AcDbPolyline::addVertexAt(0,AcGePoint2d(P1.x,P1.y));//第一点世界坐标
AcDbPolyline::addVertexAt(1,AcGePoint2d(P2.x,P2.y));//第二点世界坐标*/
////文字标注
AcGePoint3d Pn=P1;
if (get_AcGeMatrix3d_wcs_to_usc (Matrix))
{
Pn.transformBy(Matrix);
}
std:: wstring linshi(_T("T"));

textx=double_to_wstring(Pn.x,prec);
texty=double_to_wstring(Pn.y,prec);

//其它点为的计算
text_x.set(P2.x,P2.y,P2.z);//初始化
text_y.set(P2.x,P2.y,P2.z);//初始化
//point  x方向转换矩阵
int c=textx.length()>texty.length()?textx.length():texty.length();

  vec1.set(c*texthigh*0.8,0,0);//向量
mat1.setToTranslation(vec1);//平移转换矩阵
//m_text_x  y方向转换矩阵
vec2.set(0,texthigh*0.5,0);//向量
mat2.setToTranslation(vec2);//平移转换矩阵
//m_text_xy  x方向转换矩阵
vec3.set(texthigh*0.5,0,0);//向量
mat3.setToTranslation(vec3);//平移转换矩阵

vec4.set(0,-texthigh*1.5,0);//向量
mat4.setToTranslation(vec4);//平移转换矩阵
////第三点计算
point=text_x;//初始化
point.transformBy(mat1);
//
text_x.transformBy(mat2);//文字基点1
text_x.transformBy(mat3);
//
text_y.transformBy(mat4);//文字基点2
text_y.transformBy(mat3);
//
return 1;

}
/************************************************************************
函数名称:get_AcGeMatrix3d_wcs_to_usc
函数类型:bool 
返回值:
功能描述:返回Matrix,Matrix.inverse()为世界坐标到当期cad用户坐标的转换矩阵
依靠函数:
其它说明:
*************************************************************************/
bool dim_xyz1_2008::get_AcGeMatrix3d_wcs_to_usc (AcGeMatrix3d &Matrix)//Matrix为返回值,Matrix.inverse()
{



AcGeMatrix3d xform;
acdbUcsMatrix(xform);////获得使用者坐标系

AcGePoint3d Origin1;//原点
AcGeVector3d XAxis1;//x 轴
AcGeVector3d YAxis1;//y 轴
AcGeVector3d ZAxis1;//z 轴

//提取客户坐标参数Origin1,XAxis1,YAxis1,ZAxis1
xform.getCoordSystem(Origin1,XAxis1,YAxis1,ZAxis1);

if ((Origin1==Origin)&&(XAxis1==XAxis)&&(YAxis1==YAxis)&&(ZAxis1==ZAxis))
{
return false;//目前使用的是世界坐标
}
//求世界坐标到用户坐标的转换矩阵Matrix(Matrix.inverse())
Matrix.setToAlignCoordSys(Origin,XAxis,YAxis,ZAxis,Origin1,XAxis1,YAxis1,ZAxis1);//这里将Origin1、XAxis1,YAxis1,ZAxis1和Origin,XAxis,YAxis,ZAxis,换个位置就好理解了,就不用Matrix.inverse()

return true;//需要投影
}
dim_xyz1_2008::~dim_xyz1_2008 () {
}

//-----------------------------------------------------------------------------
//----- AcDbObject protocols
//- Dwg Filing protocol
Acad::ErrorStatus dim_xyz1_2008::dwgOutFields (AcDbDwgFiler *pFiler) const {
assertReadEnabled () ;
//----- Save parent class information first.
Acad::ErrorStatus es =AcDbPolyline::dwgOutFields (pFiler) ;
if ( es != Acad::eOk )
return (es) ;
//----- Object version number needs to be saved first
if ( (es =pFiler->writeUInt32 (dim_xyz1_2008::kCurrentVersionNumber)) != Acad::eOk )
return (es) ;
//----- Output params
//.....
//.....
////////////////////////////////
//保存父辈和组件变换矩阵的数据
pFiler->writeItem (vec1);
pFiler->writeItem (vec2);
pFiler->writeItem (vec3);
pFiler->writeItem (vec4);

pFiler->writeItem (point) ;//世界坐标
pFiler->writeItem (text_x) ;//世界坐标
pFiler->writeItem (text_y) ;//世界坐标
pFiler->writeItem (texthigh);
pFiler->writeItem (prec);
//

pFiler->writeItem (format);
//
pFiler->writeItem (textx.c_str());
pFiler->writeItem (texty.c_str());
return (pFiler->filerStatus ()) ;
}

Acad::ErrorStatus dim_xyz1_2008::dwgInFields (AcDbDwgFiler *pFiler) {
assertWriteEnabled () ;
//----- Read parent class information first.
Acad::ErrorStatus es =AcDbPolyline::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_2008::kCurrentVersionNumber )
return (Acad::eMakeMeProxy) ;
//- Uncomment the 2 following lines if your current object implementation cannot
//- support previous version of that object.
//if ( version < dim_xyz1_2008::kCurrentVersionNumber )
// return (Acad::eMakeMeProxy) ;
//----- Read params
//.....
pFiler->readItem (&vec1);
pFiler->readItem (&vec2);
pFiler->readItem (&vec3);
pFiler->readItem (&vec4);

pFiler->readItem (&point) ;//世界坐标
pFiler->readItem (&text_x) ;//世界坐标
pFiler->readItem (&text_y) ;//世界坐标
pFiler->readItem (&texthigh);
pFiler->readItem (&prec);
//
wchar_t *text2=new wchar_t[100];
pFiler->readItem (&text2);//
format=(text2);
delete text2;
//
wchar_t *text=new wchar_t[50];
pFiler->readItem (&text);//保存当前坐标系(相对世界坐标系)
textx.assign(text);

wchar_t *text1=new wchar_t[50];
pFiler->readItem (&text1) ;//保存当前坐标系(相对世界坐标系)
texty.assign(text1);
delete text;
delete text1;
//

return (pFiler->filerStatus ()) ;
}

//-----------------------------------------------------------------------------
//----- AcDbEntity protocols
Adesk::Boolean dim_xyz1_2008::worldDraw (AcGiWorldDraw *mode) {
assertReadEnabled () ;
//------ Returning Adesk::kFalse here will force viewportDraw() call
mode->subEntityTraits().setSelectionMarker(1);//第1段
mode->subEntityTraits().setColor(7); // 黄
AcDbPolyline::worldDraw (mode);
///////////////////////////////////////////////////////////////////////////////////////////////////////////
mode->subEntityTraits().setSelectionMarker(2);//
mode->subEntityTraits().setColor(7); // 黄

AcGePoint3d p1;
AcDbPolyline::getPointAt(0,p1);//获得第一点
AcGePoint3d p;
AcDbPolyline::getPointAt(1,p);//获得第二点
AcGePoint3d ptArr[2];
ptArr[0] = p;
ptArr[1] =point;//第三点
mode->geometry().polyline(2,ptArr);
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//动态文字标注
mode->subEntityTraits().setSelectionMarker(3);
mode->subEntityTraits().setColor(7);
AcGiTextStyle style;
style.setTextSize(texthigh);
style.loadStyleRec();
//提取坐标文字内容并保存到dim_x,dim_y中
wmemset(dim_x,'\0',50);
wmemset(dim_y,'\0',50);
AcGeMatrix3d xform;
bool pe=get_AcGeMatrix3d_wcs_to_usc(xform);
if(pe==1)//当前使用用户坐标
{
p1.transformBy(xform.inverse());
}
swprintf(dim_x,format,p1.x);
swprintf(dim_y,format,p1.y);
textx.assign(dim_x);
texty.assign(dim_y);
//描绘文字
mode->geometry().text(text_x,AcGeVector3d::kZAxis,(point-p),textx.c_str(),textx.length(),Adesk::kFalse,style);
mode->geometry().text(text_y,AcGeVector3d::kZAxis,(point-p),texty.c_str(),texty.length(),Adesk::kFalse,style);
return 1 ;
}

Acad::ErrorStatus dim_xyz1_2008::moveGripPointsAt (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)

return (AcDbPolyline::moveGripPointsAt (indices, offset)) ;
}

Acad::ErrorStatus dim_xyz1_2008::getGripPoints (
AcDbGripDataPtrArray &grips, const double curViewUnitSize, const int gripSize, 
const AcGeVector3d &curViewDir, const int bitflags
) const {
assertReadEnabled () ;
Acad::ErrorStatus es;
//es=AcDbPolyline::subGetGripPoints (grips, curViewUnitSize, gripSize, curViewDir, bitflags);//这次我把它屏蔽了
//
AcDbGripData* gpd = new AcDbGripData();
gpd->setAppData((void*)9999); // 标志;第4点       2--------3---4
AcGePoint3d i(point.x,point.y,0);                //
gpd->setGripPoint(i);                           //
grips.append(gpd);                             // 1

gpd = new AcDbGripData();
gpd->setAppData((void*)9998); // 第2点
AcGePoint3d j;
es=AcDbPolyline::getPointAt(1,j);
gpd->setGripPoint(j);
grips.append(gpd);

gpd = new AcDbGripData();
gpd->setAppData((void*)9997); // 标志 ,第1点
AcGePoint3d k;
es=AcDbPolyline::getPointAt(0,k);
gpd->setGripPoint(k);
grips.append(gpd);

return (AcDbPolyline::getGripPoints (grips, curViewUnitSize, gripSize, curViewDir, bitflags)) ;
}

Acad::ErrorStatus dim_xyz1_2008::moveGripPointsAt (
const AcDbVoidPtrArray &gripAppData, const AcGeVector3d &offset,
const int bitflags
) {
assertWriteEnabled () ;
Acad::ErrorStatus es=Acad::eOk;
////标注变换
AcGeMatrix3d xform;
bool p=get_AcGeMatrix3d_wcs_to_usc (xform);
for (int g=0; g<gripAppData.length(); g++)//对每个被移动的夹点分类操作
{
// 
int i = (int)gripAppData.at(g);
// 临时变量
AcGePoint3d i9999;
AcGePoint3d j9999;
AcGePoint3d k9999;

AcGeMatrix3d mat1;AcGeVector3d vec1;
AcGePoint3d m;
//
int l1;
int l;
//std::wistringstream is;
switch (i)
{
case 9999://调整角度
//直线第4点设置
es=AcDbPolyline::getPointAt(1,j9999);
j9999.transformBy(offset);
k9999=j9999;
es=AcDbPolyline::removeVertexAt(1);
es=AcDbPolyline::addVertexAt(1,AcGePoint2d(k9999.x,k9999.y));
//point点变换
i9999=point;
i9999.transformBy(offset);
point=i9999;
//文字基点
text_x.transformBy(offset);
text_y.transformBy(offset);
break; 

case 9998://整体移动

es=dim_xyz1_2008::transformBy(offset);//父辈先来将offset作为变换矩阵
break; 
case 9997:
//基准点移动
es=AcDbPolyline::getPointAt(0,i9999);
i9999.transformBy(offset);
k9999=i9999;
es=AcDbPolyline::removeVertexAt(0);
es=AcDbPolyline::addVertexAt(0,AcGePoint2d(k9999.x,k9999.y));

l=(textx.length()>texty.length())?textx.length():texty.length();

//文字内容
wmemset(dim_x,'\0',50);
wmemset(dim_x,'\0',50);
if(p==1)
{
i9999.transformBy(xform.inverse());
swprintf(dim_x,format,i9999.x);
swprintf(dim_y,format,i9999.y);

}
else
{
swprintf(dim_x,format,i9999.x);
swprintf(dim_y,format,i9999.y);
}
textx.assign(dim_x);
texty.assign(dim_x);

l1=(textx.length()>texty.length())?textx.length():texty.length();
//修正第三点偏移量
es=AcDbPolyline::getPointAt(1,m);
vec1=(m-point)*(l-l1)/l;
mat1.setToTranslation(vec1);
point.transformBy(mat1 );

break; 
case 9996:  
  
break; 

}
}
return es;

}
/************************************************************************
功能描述:被系统或用户调用实现实体的移动、旋转,如果被系统调用时是不会调用上面的subMoveGripPointsAt等函数
*************************************************************************/
Acad::ErrorStatus dim_xyz1_2008::transformBy(const AcGeMatrix3d & xform)
{
Acad::ErrorStatus retCode =AcDbPolyline::transformBy (xform) ;//父辈先行
retCode =Entity_change( xform);
return (retCode) ;
}
/************************************************************************
自定义的
功能描述:对其它实体进行变换
*************************************************************************/
Acad::ErrorStatus dim_xyz1_2008::Entity_change(const AcGeMatrix3d & xform)
{
Acad::ErrorStatus es;
AcGeMatrix3d ma;

//计算文字的世界坐标
//
text_x.transformBy(xform);
text_y.transformBy(xform);
////////////////////////////////////
//按xform计算point点的世界坐标
point.transformBy(xform);
///////////////////////////////////
//提取原标注信息
int l=(textx.length()>texty.length())?textx.length():texty.length();

////////////////////////////////////
//根据坐标系统变换标注文字内容,
//提取直线第1点原坐标
AcGePoint3d i9999;
es=AcDbPolyline::getPointAt(0,i9999);//提取父辈点的世界坐标

if(get_AcGeMatrix3d_wcs_to_usc(ma))
{ //在用户坐标下::
//建立变换矩阵改变文字标注内容
i9999.transformBy(ma.inverse());
}

textx=double_to_wstring(i9999.x,prec);
texty=double_to_wstring(i9999.y,prec);
/////////////////////////////////////
//提取更改后的标注信息
int l1=(textx.length()>texty.length())?textx.length():texty.length();
//
//修正第三点偏移量
AcGeMatrix3d mat1;AcGeVector3d vec1;
AcGePoint3d m;
es=AcDbPolyline::getPointAt(1,m);
vec1=(m-point)*(l-l1)/l;
mat1.setToTranslation(vec1);
point.transformBy(mat1 );
//修正文字高度
texthigh*=xform.scale();
return (es) ;
}

/************************************************************************
功能描述:响应拉伸,//用修改命令中的延伸时该函数运行,在subGetStretchPoints被调用后执行
依靠函数:
其它说明:我在这里重载,只想让他变成和移动一样的功能
*************************************************************************/
Acad::ErrorStatus dim_xyz1_2008::moveStretchPointsAt(const AcDbIntArray & indices, const AcGeVector3d & offset)
{ assertReadEnabled(); 
Acad::ErrorStatus es=AcDbPolyline::moveStretchPointsAt (indices, offset);//调用父辈的功能函数
//根据AcGeVector3d
//建立变换矩阵(这里是平移)
AcGeMatrix3d mat;
mat.setToTranslation(offset);
Entity_change(mat);
//
return ( es) ;
}

Acad::ErrorStatus dim_xyz1_2008::explode(AcDbVoidPtrArray & entitySet) const
{
Acad::ErrorStatus retCode ;
AcGePoint3d p1;
retCode=AcDbPolyline::getPointAt(0,p1);//获得第一点
AcGePoint3d p;
retCode=AcDbPolyline::getPointAt(1,p);//获得第二点
//
AcDbText *text1 ;
AcDbText *text2 ;
//动态文字标注
AcGeVector3d direction = point - p;
//描绘文字
text1=new AcDbText(text_x,textx.c_str(),0,texthigh,direction.angleTo (AcGeVector3d (1, 0, 0)));
text2=new AcDbText(text_y,texty.c_str(),0,texthigh,direction.angleTo (AcGeVector3d (1, 0, 0)));
entitySet.append (text1) ;
entitySet.append (text2) ;
//
AcDbPolyline* line;
line= new AcDbPolyline;

AcGePoint2d b1(p.x,p.y);
AcGePoint2d b2(point.x,point.y);

retCode=line->addVertexAt(0,b1);
retCode=line->addVertexAt(1,b2);
entitySet.append (line) ;

retCode=AcDbPolyline::explode (entitySet) ;
return (retCode) ;
}



路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist doodle 涂鸦板

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

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

GMT+8, 2024-5-12 11:31 , Processed in 0.114532 second(s), 15 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部