// (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) ;
}