10196 lines
234 KiB
C++
10196 lines
234 KiB
C++
//-------------------------------------------------------------------------------------------------------+
|
||
// Copyright (C), 1998-2007, SH Software Co. Ltd.
|
||
// = FileName : 导出全局函数实现文件
|
||
// = Version : ver2.0
|
||
// = Author : zjq
|
||
// = CreateDate : 2002-09-09
|
||
// = Description: 全局函数的声明
|
||
// = Maintainers:
|
||
//
|
||
//-------------------------------------------------------------------------------------------------------+
|
||
#include "StdAfx.h"
|
||
#include "acgs.h"
|
||
#include "XGlobalFunc.h"
|
||
#include "XAdvanceSampler.h"
|
||
|
||
#include "XScreenDc.h"
|
||
#include "XBlockTableRecPtr.h"
|
||
#include "XPushVar.h"
|
||
#include "XPushMemVar.h"
|
||
#include "XDbObject.h"
|
||
#include "XPathParser.h"
|
||
#include "XPushPrec.h"
|
||
#include "XDrawingLib.h"
|
||
#include "XAsdkCustomWorldDraw.h"
|
||
|
||
#include "XDbLayerTableRec.h"
|
||
#include "XHoleModel.h"
|
||
#include "AEntityBase.h"
|
||
|
||
#include "XAsdkShellData.h"
|
||
#include "XBlockTable.h"
|
||
#include "CTempTol.h"
|
||
#include "RegProperty.h"
|
||
#include "CImageDC.h"
|
||
#include "CImageDCEx.h"
|
||
#include "AString.h"
|
||
#include "UString.h"
|
||
#include "imgdef.h"
|
||
#include "imgent.h"
|
||
#include "direct.h"
|
||
#include "errno.h"
|
||
#include "dbregion.h"
|
||
#include "SymbolTable.h"
|
||
#include "dbltrans.h"
|
||
#include "lngtrans.h"
|
||
#include "dbhatch.h"
|
||
#include "StyleTable.h"
|
||
#include "DragPickEntSet.h"
|
||
#include "XWcsStream.h"
|
||
#include "XUcsStream.h"
|
||
#include "TextRange.h"
|
||
#include "XPushMMUnit.h"
|
||
#include "SqlQuiry.h"
|
||
#include "SafeResource.h"
|
||
#include "XConfigBase.h"
|
||
#include "io.h"
|
||
#include "afxdisp.h"
|
||
#include "XRectAngle.h"
|
||
#include "WValList.h"
|
||
|
||
//#include "dwgcplib.h"
|
||
#include "XBlockTableRecordZone.h"
|
||
#include "XPrivateGlobalFunc.h"
|
||
#include "comutil.h"
|
||
|
||
static const TCHAR *sMsgPrompt[] =
|
||
{
|
||
/*MSG0*/ _T("\n目标位置:"),
|
||
/*MSG1*/ _T("\n缩放比例<1.0>: "),
|
||
/*MSG2*/ _T("\n输入无效!"),
|
||
/*MSG3*/ _T("\n旋转角度<0.0>: "),
|
||
};
|
||
|
||
static int KwIndex = NOP; /* Index into kwtab */
|
||
static int m_nPos = 0;
|
||
static int g_nFlag = 0;
|
||
static int g_nDragFlag = 0; //默认为非移动
|
||
|
||
static XPoint g_ptCursorWcs; //热键发生时的光标位置
|
||
|
||
static ads_point Base; /* Base point for xform */
|
||
static double scr_h; /* current vport height */
|
||
static ads_matrix CTM; /* Current Transformation Matrix */
|
||
|
||
static TCHAR g_szKeyTable[256] = _T("");
|
||
static TCHAR m_szCommandStr[1024] = _T("");
|
||
|
||
static int CompareDouble(const double *p1, const double *p2)
|
||
{
|
||
if(*p1>*p2)
|
||
return 1;
|
||
return -1;
|
||
}
|
||
|
||
// 根据绕X轴旋转的点初始化矩阵
|
||
// 参数: VSINX: 旋转角度的正弦值
|
||
// VCOSX: 旋转角度的余弦值
|
||
static void rota_X_init(ads_matrix rota_X,double VSINX,double VCOSX)
|
||
{
|
||
|
||
AT_InitIdenMat(rota_X);
|
||
|
||
rota_X[1][1] = rota_X[2][2] = VCOSX;
|
||
rota_X[2][1] = VSINX;
|
||
rota_X[1][2] = 0.0 - VSINX;
|
||
}
|
||
|
||
// 根据绕Z轴旋转的点初始化矩阵
|
||
// 参数: VSINZ: 旋转角度的正弦值
|
||
// VCOSZ: 旋转角度的余弦值
|
||
static void rota_Z_init(ads_matrix rota_Z,double VSINZ,double VCOSZ)
|
||
{
|
||
AT_InitIdenMat(rota_Z);
|
||
|
||
rota_Z[0][0] = rota_Z[1][1] = VCOSZ;
|
||
rota_Z[1][0] = VSINZ;
|
||
rota_Z[0][1] = 0.0 - VSINZ;
|
||
}
|
||
|
||
static double ads_fabsv(ads_point ap)
|
||
{
|
||
return sqrt(ap[X] * ap[X] + ap[Y] * ap[Y] + ap[Z] * ap[Z]);
|
||
}
|
||
|
||
static void ads_subvec(ads_point ap, ads_point bp, ads_point dp)
|
||
{
|
||
dp[X] = ap[X] - bp[X];
|
||
dp[Y] = ap[Y] - bp[Y];
|
||
dp[Z] = ap[Z] - bp[Z];
|
||
}
|
||
|
||
static double ads_dist(ads_point p1, ads_point p2)
|
||
{
|
||
ads_point pd;
|
||
ads_subvec(p1, p2, pd);
|
||
return ads_fabsv(pd);
|
||
}
|
||
|
||
static void ads_mat_ident(ads_matrix matrix)
|
||
{
|
||
memcpy(matrix, ads_identmat, sizeof(ads_matrix));
|
||
}
|
||
|
||
static void ads_mat_rot(double angle, int axis, ads_matrix m)
|
||
{
|
||
int axp1, axp2;
|
||
|
||
axp1 = (axis + 1) % 3;
|
||
axp2 = (axis + 2) % 3;
|
||
ads_mat_ident(m);
|
||
m[axp1][axp1] = m[axp2][axp2] = cos(angle);
|
||
m[axp1][axp2] = -(m[axp2][axp1] = sin(angle));
|
||
}
|
||
|
||
static void ads_mat_scale(double xscale, double yscale, double zscale, ads_matrix m)
|
||
{
|
||
ads_mat_ident(m);
|
||
m[X][X] = xscale;
|
||
m[Y][Y] = yscale;
|
||
m[Z][Z] = zscale;
|
||
}
|
||
|
||
static void ads_mat_x_vec(ads_matrix mat, ads_point pin, ads_point pout)
|
||
{
|
||
int i;
|
||
ads_point temp;
|
||
for (i = X; i <= Z; i++)
|
||
{
|
||
temp[i] = mat[i][X] * pin[X] + mat[i][Y] * pin[Y] + mat[i][Z] * pin[Z];
|
||
}
|
||
memcpy(pout, temp, sizeof(ads_point));
|
||
}
|
||
|
||
static int IsDigit(const char *str)
|
||
{
|
||
int len = strlen(str);
|
||
for(int i = 0; i < len; i++)
|
||
{
|
||
if(!isdigit(str[i]))
|
||
{
|
||
return 0;
|
||
}
|
||
}
|
||
return 1;
|
||
}
|
||
|
||
static int AT_mod_arcp(ads_name ent_arc, int code, ads_point pt)
|
||
{
|
||
struct resbuf *ebuf, *rb;
|
||
ads_point cenpt;
|
||
|
||
ebuf = ads_entget(ent_arc);
|
||
rb = AT_get_resbuf(ebuf, 10);
|
||
Cpoint(cenpt, rb->resval.rpoint);
|
||
rb = AT_get_resbuf(ebuf, code);
|
||
rb->resval.rreal = ads_angle(cenpt, pt);
|
||
ads_entmod(ebuf);
|
||
ads_relrb(ebuf);
|
||
|
||
return 1;
|
||
}
|
||
|
||
static int init_cir(ads_name all_set)
|
||
{
|
||
Entity cir1, cir2;
|
||
double ang1, ang2, rad1, rad2;
|
||
ads_point cen1, cen2;
|
||
long i,j;
|
||
long len;
|
||
|
||
PickSet ssAll = all_set, cir_set(SS_FREE|SS_CREATE), del_set(SS_FREE|SS_CREATE);
|
||
len = ssAll.Length();
|
||
for (i = 0; i<len; i++)
|
||
{
|
||
Entity ent = ssAll[i];
|
||
if (ent.Is(_T("CIRCLE")))
|
||
{
|
||
cir_set += ent;
|
||
}
|
||
}
|
||
|
||
len = cir_set.Length();
|
||
for (i = 0; i < len; i++)
|
||
{
|
||
ads_ssname(cir_set,i,cir1);
|
||
Entity cir1 = cir_set[i];
|
||
if (cir1.In(&del_set))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
AT_get_cirarcp(cir1, cen1, &rad1, &ang1, &ang2);
|
||
if (rad1<_DIST_SNAP)
|
||
{ // zero radius
|
||
del_set += cir1;
|
||
ads_ssadd(cir1, del_set, del_set);
|
||
continue;
|
||
}
|
||
|
||
for (j = 0; j < len; j++)
|
||
{
|
||
Entity cir2 = cir_set[j];
|
||
if (cir1 == cir2 || cir2.In(&del_set))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
|
||
AT_get_cirarcp(cir2, cen2, &rad2, &ang1, &ang2);
|
||
if ( ads_distance(cen1,cen2) <= _DIST_SNAP && fabs(rad1 - rad2) < _DIST_SNAP)
|
||
{
|
||
del_set += cir2;
|
||
}
|
||
}
|
||
}
|
||
ssAll -= del_set;
|
||
del_set.Erase();
|
||
return RTNORM;
|
||
}
|
||
|
||
static int init_arc(ads_name all_set)
|
||
{
|
||
|
||
Entity arc1, arc2;
|
||
double s_ang1, s_ang2, e_ang1, e_ang2, rad1, rad2;
|
||
ads_point cen1, cen2;
|
||
long i,j;
|
||
long len;
|
||
ads_point a2_pt1, a2_pt2, a1_pt1, a1_pt2;
|
||
|
||
PickSet ssAll = all_set, arc_set(SS_FREE|SS_CREATE), del_set(SS_FREE|SS_CREATE);
|
||
len = ssAll.Length();
|
||
for (i = 0; i<len; i++)
|
||
{
|
||
Entity ent = ssAll[i];
|
||
if (ent.Is(_T("ARC")))
|
||
{
|
||
arc_set += ent;
|
||
}
|
||
}
|
||
|
||
len = arc_set.Length();
|
||
for (i = 0; i<len; i++)
|
||
{
|
||
arc1 = arc_set[i];
|
||
if (arc1.In(&del_set))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
AT_get_cirarcp(arc1, cen1, &rad1, &s_ang1, &e_ang1);
|
||
if (rad1 < _DIST_SNAP && fabs(sin(s_ang1 - e_ang1)) < 0.01)
|
||
{ // zero radius or zero length
|
||
del_set += arc1;
|
||
continue;
|
||
}
|
||
|
||
ads_polar(cen1, s_ang1, rad1, a1_pt1);
|
||
ads_polar(cen1, e_ang1, rad1, a1_pt2);
|
||
|
||
for (j = 0; j < len; j++)
|
||
{
|
||
arc2 = arc_set[j];
|
||
if (arc1 == arc2)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (arc2.In(&del_set))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
AT_get_cirarcp(arc2, cen2, &rad2, &s_ang2, &e_ang2);
|
||
if ( ads_distance(cen1,cen2) <= _DIST_SNAP && fabs(rad1-rad2) < _DIST_SNAP)
|
||
{
|
||
ads_polar(cen1, s_ang2, rad1, a2_pt1);
|
||
ads_polar(cen1, e_ang2, rad1, a2_pt2);
|
||
|
||
if (AT_in_arc(a2_pt1, cen1, rad1, s_ang1, e_ang1))
|
||
{ /* start point on within arc1*/
|
||
ads_ssadd(arc2,del_set,del_set);
|
||
if (!AT_in_arc(a2_pt2,cen1,rad1,s_ang1,e_ang1))
|
||
{ /*endpoint on extension arc1 */
|
||
AT_mod_arcp(arc1, 51, a2_pt2);
|
||
}
|
||
// else end point also on within arc1, only del arc2 is enough
|
||
}
|
||
|
||
else if (AT_in_arc(a2_pt2,cen1,rad1,s_ang1,e_ang1))
|
||
{//endpoint on within arc1
|
||
ads_ssadd(arc2,del_set,del_set);
|
||
if (!AT_in_arc(a2_pt1,cen1,rad1,s_ang1,e_ang1))
|
||
{// start point on extension arc1
|
||
AT_mod_arcp(arc1, 50, a2_pt1);
|
||
}
|
||
// else start point also on within arc1, only del arc2 is enough
|
||
}
|
||
|
||
else if (AT_in_arc(a1_pt1,cen2,rad2,s_ang2,e_ang2) && // whole arc1
|
||
AT_in_arc(a1_pt2,cen2,rad2,s_ang2,e_ang2) )
|
||
{ // is within arc2
|
||
ads_ssadd(arc2, del_set, del_set); // then change arc1 to
|
||
AT_mod_arcp(arc1, 50, a2_pt1); // arc2, and del arc2
|
||
AT_mod_arcp(arc1, 51, a2_pt2);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
ssAll -= del_set;
|
||
del_set.Erase();
|
||
return RTNORM;
|
||
}
|
||
|
||
static void acadrgb(int hsv, struct r_g_b *rgp)
|
||
{
|
||
static double brightfac[5] = { 1.0, 0.65, 0.5, 0.3, 0.15 }; /* Brightness levels */
|
||
static double halfsat = .5; /* Halfway saturation */
|
||
int ih, vs;
|
||
double h, s, f, value;
|
||
|
||
// assert(hsv > 0 || hsv < 256);
|
||
|
||
switch (hsv)
|
||
{
|
||
case 0:
|
||
rgp->red = 0.0;
|
||
rgp->blue = 0.0;
|
||
rgp->green = 0.0;
|
||
value = 0.0;
|
||
break;
|
||
|
||
case 1:
|
||
rgp->red = 1.0;
|
||
rgp->green = 0.0;
|
||
rgp->blue = 0.0;
|
||
value = 1.0;
|
||
break;
|
||
|
||
case 2:
|
||
rgp->red = 1.0;
|
||
rgp->green = 1.0;
|
||
rgp->blue = 0.0;
|
||
value = 1.0;
|
||
break;
|
||
|
||
case 3:
|
||
rgp->red = 0.0;
|
||
rgp->green = 1.0;
|
||
rgp->blue = 0.0;
|
||
value = 1.0;
|
||
break;
|
||
|
||
case 4:
|
||
rgp->red = 0.0;
|
||
rgp->green = 1.0;
|
||
rgp->blue = 1.0;
|
||
value = 1.0;
|
||
break;
|
||
|
||
case 5:
|
||
rgp->red = 0.0;
|
||
rgp->green = 0.0;
|
||
rgp->blue = 1.0;
|
||
value = 1.0;
|
||
break;
|
||
|
||
case 6:
|
||
rgp->red = 1.0;
|
||
rgp->green = 0.0;
|
||
rgp->blue = 1.0;
|
||
value = 1.0;
|
||
break;
|
||
|
||
case 7:
|
||
case 8:
|
||
case 9:
|
||
rgp->red = 1.0;
|
||
rgp->green = 1.0;
|
||
rgp->blue = 1.0;
|
||
value = 1.0;
|
||
break;
|
||
|
||
default:
|
||
if (hsv > 9 && hsv < 250)
|
||
{
|
||
/* Apply the algorithm from Foley & van Dam to turn HSV into RGB values */
|
||
ih = (hsv - 10) / 10; /* Integer hue value. */
|
||
if (ih >= 24) /* Range is 0-23. */
|
||
{
|
||
ih -= 24;
|
||
}
|
||
vs = hsv % 10; /* Encoded value and saturation */
|
||
h = ih / 4.; /* Map into range [0.0,6.0) */
|
||
ih = (int)h; /* The integer part. */
|
||
f = h - ih; /* Fractional part. */
|
||
value = brightfac[vs >> 1]; /* Value in [0,1] */
|
||
s = vs & 1 ? halfsat : 1.0; /* Saturation */
|
||
|
||
switch (ih)
|
||
{
|
||
case 0:
|
||
rgp->red = 1.0;
|
||
rgp->green = (double) (1.0 - s * (1.0 - f));
|
||
rgp->blue = (double) (1.0 - s);
|
||
break;
|
||
|
||
case 1:
|
||
rgp->red = (double) (1.0 - s * f);
|
||
rgp->green = 1.0;
|
||
rgp->blue = (double) (1 - s);
|
||
break;
|
||
|
||
case 2:
|
||
rgp->red = (double) (1.0 - s);
|
||
rgp->green = 1.0;
|
||
rgp->blue = (double) (1.0 - s *(1.0 - f));
|
||
break;
|
||
|
||
case 3:
|
||
rgp->red = (double) (1.0 - s);
|
||
rgp->green = (double) (1.0 - s * f);
|
||
rgp->blue = 1.0;
|
||
break;
|
||
|
||
case 4:
|
||
rgp->red = (double) (1.0 - s * (1.0 - f));
|
||
rgp->green = (double) (1.0 - s);
|
||
rgp->blue = 1.0;
|
||
break;
|
||
|
||
case 5:
|
||
rgp->red = 1.0;
|
||
rgp->green = (double) (1.0 - s);
|
||
rgp->blue = (double) (1.0 - s * f);
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
/* Define some extra colours from dark grey to white in the 250 to 255 slots */
|
||
value = 0.33 + (hsv - 250) * 0.134;
|
||
rgp->red = 1.0;
|
||
rgp->green = 1.0;
|
||
rgp->blue = 1.0;
|
||
}
|
||
break; /* Default */
|
||
}
|
||
rgp->red *= value; /* Apply lightness scale factor */
|
||
rgp->green *= value; /* to components resulting from */
|
||
rgp->blue *= value; /* hue and saturation. */
|
||
}
|
||
|
||
static int dragsampler(ads_point pt0, ads_matrix mat)
|
||
{
|
||
double D;
|
||
double angle;
|
||
ads_point pt, tp;
|
||
int axis;
|
||
|
||
// Move操作时,没有基点,正交不起作用
|
||
//使得正交(Ortho)和捕捉(SNAP)起作用
|
||
CapturePoint(g_nDragFlag ? NULL:Base, pt0, pt);
|
||
switch(KwIndex)
|
||
{
|
||
case MXYZ:
|
||
/* generate translation matrix */
|
||
ads_subvec(pt, Base, tp);
|
||
ads_mat_x_vec(mat, tp, tp);
|
||
mat[X][T] = tp[X];
|
||
mat[Y][T] = tp[Y];
|
||
mat[Z][T] = tp[Z];
|
||
break;
|
||
case SXYZ:
|
||
/* generate uniformly scaled matrix */
|
||
D = ads_dist(pt, Base)/scr_h*10; // SCALE = DIST / (SCR_H/10)
|
||
if (D < .0001)
|
||
{
|
||
D = .0001;
|
||
}
|
||
ads_mat_scale(D,D, D, mat);
|
||
|
||
/* calculate new translation point */
|
||
ads_mat_x_vec(mat, Base, tp);
|
||
ads_subvec(Base, tp, tp);
|
||
mat[X][T] = tp[X];
|
||
mat[Y][T] = tp[Y];
|
||
mat[Z][T] = tp[Z];
|
||
break;
|
||
|
||
case RX:
|
||
case RY:
|
||
case RZ:
|
||
switch (KwIndex)
|
||
{
|
||
case RX:
|
||
axis = X;
|
||
break;
|
||
case RY:
|
||
axis = Y;
|
||
break;
|
||
case RZ:
|
||
axis = Z;
|
||
break;
|
||
}
|
||
/* calculate angle of line between LastPoint and tp */
|
||
ads_subvec(pt, Base, tp);
|
||
angle = ads_angle(Base, pt);
|
||
|
||
/* generate rotation matrix about axis */
|
||
ads_mat_rot(angle, axis, mat);
|
||
|
||
/* calculate new translation point */
|
||
ads_mat_x_vec(mat, Base, tp);
|
||
ads_subvec(Base, tp, tp);
|
||
mat[X][T] = tp[X];
|
||
mat[Y][T] = tp[Y];
|
||
mat[Z][T] = tp[Z];
|
||
|
||
break;
|
||
case EXIT:
|
||
return RTCAN;
|
||
case NOP:
|
||
default:
|
||
return RTNONE;
|
||
}
|
||
|
||
memcpy(CTM, mat, sizeof(ads_matrix));
|
||
return RTNORM;
|
||
}
|
||
|
||
static int MoveSampler(ads_point pt0, ads_matrix mat)
|
||
{
|
||
// Move操作时,没有基点,正交不起作用
|
||
XPoint pt;
|
||
pt = Ucs2Wcs(pt);
|
||
CapturePoint(NULL, pt0, pt); //使得正交(Ortho)和捕捉(SNAP)起作用
|
||
pt = Ucs2Wcs(pt);
|
||
Ucs2Wcs(g_ptBase).GetMoveMatrix(pt, mat);
|
||
return RTNORM;
|
||
}
|
||
|
||
static int DragRotateCallBack(ads_point pt0, ads_matrix mat)
|
||
{
|
||
// Move操作时,没有基点,正交不起作用
|
||
XPoint pt;
|
||
CapturePoint(&g_ptBase.x, pt0, pt); //使得正交(Ortho)和捕捉(SNAP)起作用
|
||
pt = Ucs2Wcs(pt);
|
||
Ucs2Wcs(g_ptBase).GetRotationMatrix(ads_angle(Ucs2Wcs(g_ptBase), pt), mat);
|
||
return RTNORM;
|
||
}
|
||
|
||
|
||
/*static int CompareAcRxClass(const AcRxClass *p1, const void *p2)
|
||
{
|
||
const AcRxClass *pp2 = (const AcRxClass *)p2;
|
||
if (p1 == pp2)
|
||
{
|
||
return 0;
|
||
}
|
||
return 1;
|
||
}
|
||
*/
|
||
|
||
int XExport::MoveSamplerStatic(ads_point pt0, ads_matrix mat)
|
||
{
|
||
return MoveSampler(pt0, mat);
|
||
}
|
||
|
||
AcDbObjectId XExport::AddToModelSpace(AcDbEntity *pEntity, Adesk::Boolean bDoneClose ,Adesk::Boolean bWorkset)
|
||
{
|
||
AcDbObjectId idEnt;
|
||
AcDbDatabase* pDb = acdbCurDwg();
|
||
if (pDb != NULL)
|
||
{
|
||
AcDbBlockTable* pTable = NULL;
|
||
if (Acad::eOk == pDb->getBlockTable(pTable,AcDb::kForRead))
|
||
{
|
||
AcDbBlockTableRecord* pRecord = NULL;
|
||
if (Acad::eOk == pTable->getAt(ACDB_MODEL_SPACE,pRecord,AcDb::kForWrite))
|
||
{
|
||
pRecord->appendAcDbEntity(idEnt,pEntity);
|
||
if (bDoneClose)
|
||
{
|
||
pEntity->close();
|
||
}
|
||
pRecord->close();
|
||
}
|
||
pTable->close();
|
||
}
|
||
}
|
||
|
||
// add by zjq on 100824 考虑工作集
|
||
if (bWorkset)
|
||
{
|
||
//get current work set
|
||
AcApDocument *pCurDoc = curDoc();
|
||
if (pCurDoc != NULL)
|
||
{
|
||
AcDbObjectId idLT = acapLongTransactionManagerPtr()->currentLongTransactionFor (pCurDoc);
|
||
AcDbLongTransaction *pLT = NULL;
|
||
acdbOpenObject(pLT,idLT,AcDb::kForWrite);
|
||
if (pLT != NULL)
|
||
{
|
||
pLT->addToWorkSet(idEnt);
|
||
pLT->close();
|
||
}
|
||
}
|
||
}
|
||
|
||
return idEnt;
|
||
}
|
||
|
||
AcDbObjectId XExport::AddToPaperSpace(AcDbEntity *pEntity, Adesk::Boolean bDoneClose ,Adesk::Boolean bWorkset)
|
||
{
|
||
XBlockTableRecPtr mspace(ACDB_PAPER_SPACE, AcDb::kForWrite);
|
||
if (!mspace)
|
||
{
|
||
return AcDbObjectId::kNull;
|
||
}
|
||
|
||
AcDbBlockTableRecord &rec = mspace;
|
||
rec.appendAcDbEntity(pEntity);
|
||
if (bDoneClose)
|
||
{
|
||
pEntity->close();
|
||
}
|
||
|
||
// modify by zjq on 100824 考虑工作集
|
||
//return pEntity->objectId();
|
||
AcDbObjectId idEnt = pEntity->objectId();
|
||
if (bWorkset)
|
||
{
|
||
//get current work set
|
||
AcApDocument *pCurDoc = curDoc();
|
||
if (pCurDoc != NULL)
|
||
{
|
||
AcDbObjectId idLT = acapLongTransactionManagerPtr()->currentLongTransactionFor (pCurDoc);
|
||
AcDbLongTransaction *pLT = NULL;
|
||
acdbOpenObject(pLT,idLT,AcDb::kForWrite);
|
||
if (pLT != NULL)
|
||
{
|
||
pLT->addToWorkSet(idEnt);
|
||
pLT->close();
|
||
}
|
||
}
|
||
}
|
||
return idEnt;
|
||
}
|
||
|
||
|
||
AcDbObjectId XExport::AddToCurrentSpace(AcDbEntity *pEntity, Adesk::Boolean bDoneClose ,Adesk::Boolean bWorkset)
|
||
{
|
||
int cvport = 0;
|
||
int tilemode;
|
||
xg_getvar(_T("TILEMODE"), &tilemode);
|
||
xg_getvar(_T("CVPORT"), &cvport);
|
||
|
||
// modify by zjq on 100824 考虑工作集
|
||
//return ((tilemode == 0 && cvport == 1) ? XExport::AddToPaperSpace(pEntity, bDoneClose) : XExport::AddToModelSpace(pEntity, bDoneClose));
|
||
return ((tilemode == 0 && cvport == 1) ? XExport::AddToPaperSpace(pEntity, bDoneClose, bWorkset) : XExport::AddToModelSpace(pEntity, bDoneClose,bWorkset));
|
||
}
|
||
|
||
#if (ARX>15)
|
||
bool XExport::FindRT_MANIFEST()
|
||
{
|
||
HMODULE hExe = AfxGetInstanceHandle();
|
||
if (hExe == NULL)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
HRSRC hRes = FindResource(hExe,MAKEINTRESOURCE(1),RT_MANIFEST);
|
||
if (hRes == NULL)
|
||
{
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
#endif
|
||
|
||
|
||
BOOL XExport::GetBlcCtrlPoint(AcDbObjectId id, XPoint &ptMax)
|
||
{
|
||
AcDbBlockTableRecord *pBlockTableRecord = NULL;
|
||
if (acdbOpenObject(pBlockTableRecord, id, AcDb::kForRead) != Acad::eOk)
|
||
{
|
||
return FALSE;
|
||
}
|
||
|
||
AcDbBlockTableRecordIterator *pIter = NULL;
|
||
pBlockTableRecord->newIterator(pIter);
|
||
pBlockTableRecord->close();
|
||
|
||
AcGePoint3dArray points;
|
||
for (pIter->start(); !pIter->done(); pIter->step())
|
||
{
|
||
AcDbEntity *pEnt = NULL;
|
||
if (pIter->getEntity(pEnt, AcDb::kForRead) != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
|
||
if (pEnt->isKindOf(AcDbPoint::desc()))
|
||
{
|
||
TCHAR *layer = pEnt->layer();
|
||
{
|
||
AcGePoint3d pt = ((AcDbPoint*)pEnt)->position();
|
||
points.append(pt);
|
||
}
|
||
delete []layer;
|
||
}
|
||
pEnt->close();
|
||
}
|
||
delete pIter;
|
||
|
||
int numPt = points.length();
|
||
if (numPt == 1)
|
||
{
|
||
ptMax = points[0];
|
||
}
|
||
else if (numPt == 2)
|
||
{
|
||
ptMax = points[0];
|
||
if (points[0].x < points[1].x)
|
||
{
|
||
ptMax = points[1];
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AcDbExtents ext;
|
||
AcDbBlockReference block;
|
||
block.setBlockTableRecord(id);
|
||
block.getGeomExtents(ext);
|
||
ptMax = ext.maxPoint();
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
int XExport::ConvertDwgCodePage(const TCHAR *tmpFile)
|
||
{
|
||
#if (ARX<16)
|
||
XPathParser parser(tmpFile);
|
||
BOOL bDwg = (_tcsicmp(parser.m_sExt, _T(".DWG")) == 0);
|
||
BOOL bDxf = (_tcsicmp(parser.m_sExt, _T(".DXF")) == 0);
|
||
if (!bDwg && !bDxf)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
int nRet = RTNONE;
|
||
AcDbDwgVersion dwgVer = bDwg ? getDwgVersion(tmpFile) : getDxfVersion(tmpFile);
|
||
if (dwgVer != kDHL_Unknown && dwgVer >= kDHL_1009 && dwgVer <= kDHL_1014)
|
||
{
|
||
CString cpName;
|
||
XString sSysCodePage;
|
||
if (xg_getvar(_T("SYSCODEPAGE"), sSysCodePage) == RTNORM)
|
||
{
|
||
CString csTmpFile = tmpFile, csSysCodePage = sSysCodePage;
|
||
BOOL bRet = bDwg ? getDwgCodePage(csTmpFile, cpName) : getDxfCodePage(csTmpFile, cpName);
|
||
if (!bRet)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
if (_tcsicmp(cpName, csSysCodePage) != 0)
|
||
{
|
||
if (bDwg)
|
||
{
|
||
setDwgCodePage(csTmpFile, csSysCodePage);
|
||
}
|
||
else
|
||
{
|
||
setDxfCodePage(csTmpFile, csSysCodePage);
|
||
}
|
||
return RTNORM;
|
||
}
|
||
}
|
||
}
|
||
else if (dwgVer == kDHL_Unknown && bDwg)
|
||
{
|
||
XString sSysCodePage;
|
||
VERIFY(xg_getvar(_T("SYSCODEPAGE"), sSysCodePage) == RTNORM);
|
||
if (sSysCodePage == _T("ANSI_936"))
|
||
{
|
||
FILE *fp = _tfopen(tmpFile, _T("r+b"));
|
||
if (fp)
|
||
{
|
||
TCHAR szBuf[21];
|
||
if (fread(szBuf, 1, 21, fp) == 21)
|
||
{
|
||
TCHAR *pTo = szBuf;
|
||
pTo += 7;
|
||
TCHAR szHead[7];
|
||
StrCpy(szHead, szBuf, pTo);
|
||
szHead[7] = EOS;
|
||
if (strcmp(szHead, _T("AC1015")) == 0 && szBuf[19] != 0x27)
|
||
{
|
||
szBuf[19] = 0x27;
|
||
fseek( fp, 0L, SEEK_SET );
|
||
fwrite(szBuf, 1, 21, fp);
|
||
nRet = RTNORM;
|
||
}
|
||
}
|
||
fclose(fp);
|
||
}
|
||
}
|
||
}
|
||
return nRet;
|
||
#else
|
||
return RTNONE;
|
||
#endif
|
||
}
|
||
|
||
/* * * 定 义 对 给 定 的 目 标 点 进 行 正 交 和 咬 住 捕 捉 的 函 数 * * */
|
||
// ptBase(IN) -- 参考基点
|
||
// ptDest(IN) -- 目标点
|
||
// ptCapture(OUT) -- 对ptDest进行捕捉修正后的点
|
||
void XExport::CapturePoint(const ads_point ptBase, const ads_point ptDest, ads_point ptCapture)
|
||
{
|
||
double nSnapAngle = 0.0;
|
||
int nOthoMode = 0, nSnapMode = 0, nSnapStyl = 0;
|
||
XPoint ptSnapUnit, ptSnapBase;
|
||
xg_getvar(_T("SNAPANG"), &nSnapAngle);
|
||
xg_getvar(_T("ORTHOMODE"), &nOthoMode);
|
||
xg_getvar(_T("SNAPSTYL"), &nSnapStyl);
|
||
xg_getvar(_T("SNAPMODE"), &nSnapMode);
|
||
xg_getvar(_T("SNAPUNIT"), &ptSnapUnit);
|
||
xg_getvar(_T("SNAPBASE"), &ptSnapBase);
|
||
|
||
XPoint ptResult = ptDest;
|
||
if (nSnapStyl)
|
||
{
|
||
ptResult > ptCapture;
|
||
return;
|
||
}
|
||
|
||
XPoint ptDest1 = ptDest;
|
||
|
||
if (nOthoMode && ptBase)
|
||
{ //正交方式打开
|
||
XLine lnX(ptBase, nSnapAngle),
|
||
lnY(ptBase, XExport::CT_std_angle(nSnapAngle+PI/2.0));
|
||
XPoint ptProjectX, ptProjectY;
|
||
ptDest1.Project(&lnX, ptProjectX);
|
||
ptDest1.Project(&lnY, ptProjectY);
|
||
|
||
if (ads_distance(ptDest, ptProjectX) < ads_distance(ptDest, ptProjectY))
|
||
{
|
||
ptResult = ptProjectX;
|
||
}
|
||
else
|
||
{
|
||
ptResult = ptProjectY;
|
||
}
|
||
}
|
||
|
||
if (nSnapMode)
|
||
{ //咬住方式打开
|
||
XLine lnX(ptSnapBase, nSnapAngle),
|
||
lnY(ptSnapBase, XExport::CT_std_angle(nSnapAngle + PI / 2.0));
|
||
XPoint ptProjectX, ptProjectY;
|
||
ptResult.Project(&lnX, ptProjectX);
|
||
ptResult.Project(&lnY, ptProjectY);
|
||
|
||
double nDistToSnapBaseX = ads_distance(ptSnapBase, ptProjectX),
|
||
nDistToSnapBaseY = ads_distance(ptSnapBase, ptProjectY);
|
||
if (fabs(ptSnapUnit.x) > 1.0E-6)
|
||
{
|
||
int nStepX = (int)(nDistToSnapBaseX / ptSnapUnit.x);
|
||
double nLeftX = nDistToSnapBaseX - nStepX * ptSnapUnit.x;
|
||
if (nLeftX > ptSnapUnit.x / 2.0)
|
||
{
|
||
nStepX += 1;
|
||
}
|
||
nDistToSnapBaseX = nStepX*ptSnapUnit.x;
|
||
}
|
||
|
||
if (fabs(ptSnapUnit.y) > 1.0E-6)
|
||
{
|
||
int nStepY = (int)(nDistToSnapBaseY/ptSnapUnit.y);
|
||
double nLeftY = nDistToSnapBaseY - nStepY * ptSnapUnit.y;
|
||
if (nLeftY>ptSnapUnit.y/2.0)
|
||
{
|
||
nStepY += 1;
|
||
}
|
||
nDistToSnapBaseY = nStepY*ptSnapUnit.y;
|
||
}
|
||
|
||
XPoint ptOnAxisX, ptOnAxisY;
|
||
ads_polar(ptSnapBase, ads_angle(ptSnapBase, ptProjectX), nDistToSnapBaseX, ptOnAxisX);
|
||
ads_polar(ptSnapBase, ads_angle(ptSnapBase, ptProjectY), nDistToSnapBaseY, ptOnAxisY);
|
||
|
||
XLine lnYY(ptOnAxisX, nSnapAngle + PI / 2.0);
|
||
XLine lnXX(ptOnAxisY, nSnapAngle);
|
||
|
||
int nInters = lnXX.Intersection(&lnYY, ptResult);
|
||
assert(nInters == 1);
|
||
}
|
||
ptResult.z = ptDest1.z;
|
||
ptResult > ptCapture;
|
||
}
|
||
|
||
|
||
// ptBase--UCS
|
||
int XExport::DragMovePickSet(PickSet &ss, const TCHAR *pszPrompt, const XPoint &ptBase, XPoint &ptFinal)
|
||
{
|
||
ptFinal = ptBase;
|
||
g_ptBase = ptBase;
|
||
ss.RedrawAll(2);
|
||
|
||
int rc = ads_draggen(ss, pszPrompt, 0, MoveSampler, ptFinal);
|
||
switch (rc)
|
||
{
|
||
case RTNORM:
|
||
{
|
||
ads_matrix mat;
|
||
Ucs2Wcs(g_ptBase).GetMoveMatrix(Ucs2Wcs(ptFinal), mat);
|
||
if (ads_xformss(ss, mat) != RTNORM)
|
||
{
|
||
XPushVar<int> vOsMode(_T("OSMODE"), 0);
|
||
SHads_command(RTSTR, _T("MOVE"), RTPICKS, (LONG_PTR *)ss, RTSTR, _T(""),
|
||
RT3DPOINT, &g_ptBase, RT3DPOINT, &ptFinal, RTNONE);
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
ss.RedrawAll(1);
|
||
return rc;
|
||
}
|
||
|
||
// ptBase--UCS
|
||
int XExport::DragMovePickSet(PickSet &ss, const TCHAR *pszPrompt, const XPoint &ptBase, XPoint &ptFinal,const TCHAR* sKeyword)
|
||
{
|
||
ptFinal = ptBase;
|
||
g_ptBase = ptBase;
|
||
ss.RedrawAll(2);
|
||
|
||
int rc;
|
||
INITGET_BEG(0,sKeyword);
|
||
rc = ads_draggen(ss, pszPrompt, 0, MoveSampler, ptFinal);
|
||
INITGET_END();
|
||
|
||
switch (rc)
|
||
{
|
||
case RTNORM:
|
||
{
|
||
ads_matrix mat;
|
||
Ucs2Wcs(g_ptBase).GetMoveMatrix(Ucs2Wcs(ptFinal), mat);
|
||
if (ads_xformss(ss, mat) != RTNORM)
|
||
{
|
||
XPushVar<int> vOsMode(_T("OSMODE"), 0);
|
||
SHads_command(RTSTR, _T("MOVE"), RTPICKS, (LONG_PTR *)ss, RTSTR, _T(""),
|
||
RT3DPOINT, &g_ptBase, RT3DPOINT, &ptFinal, RTNONE);
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
ss.RedrawAll(1);
|
||
return rc;
|
||
}
|
||
|
||
int XExport::DragRotatePickSet(PickSet &ss, const TCHAR *pszPrompt, XPoint ptBase)
|
||
{
|
||
g_ptBase = ptBase;
|
||
XPoint ptFinal;
|
||
ss.RedrawAll(2);
|
||
ads_initget(RSG_OTHER, NULL);
|
||
int rc = ads_draggen(ss, pszPrompt, 0, DragRotateCallBack, ptFinal);
|
||
switch (rc)
|
||
{
|
||
case RTNORM:
|
||
{
|
||
XExport::CapturePoint(g_ptBase, XPoint(ptFinal), ptFinal);
|
||
|
||
ads_matrix mat;
|
||
Ucs2Wcs(g_ptBase).GetRotationMatrix(ads_angle(Ucs2Wcs(g_ptBase), Ucs2Wcs(ptFinal)), mat);
|
||
VERIFY(ads_xformss(ss, mat) == RTNORM);
|
||
}
|
||
break;
|
||
case RTSTR:
|
||
{
|
||
XString tstr;
|
||
double res;
|
||
ads_getinput(tstr);
|
||
if (ads_distof(tstr, 2, &res) != RTNORM)
|
||
{
|
||
rc = RTERROR;
|
||
}
|
||
else
|
||
{
|
||
SHads_command(RTSTR, _T("ROTATE"), RTPICKS, (LONG_PTR *)ss, RTSTR, _T(""),
|
||
RT3DPOINT, &g_ptBase, RTREAL, res, RTNONE);
|
||
rc = RTNORM;
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return rc;
|
||
}
|
||
|
||
int XExport::DragPickSet(PickSet &ss, XPoint &ptBase)
|
||
{
|
||
int rc;
|
||
TCHAR draggenprompt[512] = _T("");
|
||
const TCHAR *szPrompt = _T("\n点取位置或 [转90度(A)/左右翻(S)/上下翻(D)/对齐(F)/改转角(R)/改基点(T)]<退出>:");
|
||
int cur = 0;
|
||
XPoint ptFinal;
|
||
cur = 0;
|
||
g_ptBase = ptBase;
|
||
XGeLib::adsout << szPrompt;
|
||
LAB_DRAG:
|
||
ss.Redraw(2);
|
||
INITGET_BEG(RSG_OTHER, _T("A S D F R T"));
|
||
rc = ads_draggen(ss,draggenprompt, cur, MoveSampler, ptFinal);
|
||
INITGET_END();
|
||
if (rc == RTKWORD)
|
||
{
|
||
XPoint g_ptNewBase = GetCursorWcs();
|
||
XString sKeyChar;
|
||
VERIFY(ads_getinput(sKeyChar) == RTNORM);
|
||
double nScale = 1.0;
|
||
XPoint vtMove = g_ptNewBase-Ucs2Wcs(g_ptBase);
|
||
ads_matrix mat = { {1.0, 0.0, 0.0, vtMove.x},
|
||
{0.0, 1.0, 0.0, vtMove.y},
|
||
{0.0, 0.0, 1.0, vtMove.z},
|
||
{0.0, 0.0, 0.0, 1.0}};
|
||
VERIFY(ads_xformss(ss, mat) == RTNORM);
|
||
|
||
ads_printf(_T("%c%c %c"), 8,8,8);
|
||
g_ptBase = Wcs2Ucs(g_ptNewBase);
|
||
if (sKeyChar[0] == _T('A') || sKeyChar[0] == _T('S') || sKeyChar[0] == _T('D'))
|
||
{
|
||
XPushVar<int> nMode(_T("OSMODE"), 0);
|
||
if (sKeyChar[0] == _T('S'))
|
||
{
|
||
XPoint ptOther = g_ptBase+XPoint(0,100,0);
|
||
SHads_command(RTSTR, _T(".MIRROR"), RTPICKS, (LONG_PTR *)ss, RTSTR, _T(""),
|
||
RT3DPOINT, &g_ptBase, RT3DPOINT, &ptOther, RTSTR, _T("Y"), RTNONE);
|
||
}
|
||
else if (sKeyChar[0] == _T('D'))
|
||
{
|
||
XPoint ptOther = g_ptBase+XPoint(100,0,0);
|
||
SHads_command(RTSTR, _T(".MIRROR"), RTPICKS, (LONG_PTR *)ss, RTSTR, _T(""),
|
||
RT3DPOINT, &g_ptBase, RT3DPOINT, &ptOther, RTSTR, _T("Y"), RTNONE);
|
||
|
||
}
|
||
else if (sKeyChar[0] == _T('A'))
|
||
{
|
||
SHads_command(RTSTR, _T(".ROTATE"), RTPICKS, (LONG_PTR *)ss, RTSTR, _T(""),
|
||
RT3DPOINT, &g_ptBase, RTREAL, 90.0, RTNONE);
|
||
|
||
}
|
||
rc = RTNORM;
|
||
}
|
||
else if (sKeyChar[0] == _T('F'))
|
||
{
|
||
int nOsMode = 0;
|
||
xg_getvar(_T("OSMODE"), &nOsMode);
|
||
nOsMode &= ~0x4000;
|
||
nOsMode |= OS_INT|OS_NEA|OS_PER|OS_END|OS_MID|OS_CEN;
|
||
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
||
XPoint pt1 = g_ptBase, pt2, qt1, qt2;
|
||
if (ads_getpoint(NULL, _T("\n对齐参考点:"), pt1) == RTNORM &&
|
||
ads_getpoint(pt1, _T("\n对齐参考轴:"), pt2) == RTNORM &&
|
||
ads_getpoint(NULL, _T("\n对齐目标点:"), qt1) == RTNORM &&
|
||
ads_getpoint(qt1, _T("\n对齐目标轴:"), qt2) == RTNORM)
|
||
{
|
||
XPushVar<int> osmode(_T("OSMODE"), 0);
|
||
double nRot = XExport::CT_std_angle(ads_angle(qt1, qt2)-ads_angle(pt1, pt2));
|
||
SHads_command(RTSTR, _T(".MOVE"), RTPICKS, (LONG_PTR *)ss, RTSTR, _T(""),
|
||
RT3DPOINT, &pt1, RT3DPOINT, &qt1, RTNONE);
|
||
SHads_command(RTSTR, _T(".ROTATE"), RTPICKS, (LONG_PTR *)ss, RTSTR, _T(""),
|
||
RT3DPOINT, &qt1, RTREAL, nRot*180/PI, RTNONE);
|
||
rc = RTNORM;
|
||
return rc;
|
||
}
|
||
rc = RTNORM;
|
||
}
|
||
else if (sKeyChar[0] == _T('R'))
|
||
{
|
||
double nRot = 0.0;
|
||
XGeLib::adsout << _T("\n旋转角度: ");
|
||
rc = SHads_command(RTSTR, _T(".ROTATE"), RTPICKS, (LONG_PTR *)ss,
|
||
RTSTR, _T(""), RT3DPOINT, &g_ptBase, RTSTR, _T("\\"), RTNONE);
|
||
if (rc == RTNORM)
|
||
{
|
||
XGeLib::adsout << szPrompt;
|
||
}
|
||
}
|
||
else if (sKeyChar[0] == _T('T'))
|
||
{
|
||
int nOsMode = 0;
|
||
xg_getvar(_T("OSMODE"), &nOsMode);
|
||
nOsMode &= ~0x4000;
|
||
nOsMode |= OS_INT|OS_NEA|OS_PER|OS_END|OS_MID|OS_CEN;
|
||
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
||
rc = XGetPoint(NULL, _T("\n输入插入点"), g_ptBase);
|
||
if (rc == RTNORM)
|
||
{
|
||
XGeLib::adsout << szPrompt;
|
||
ptBase = g_ptBase;
|
||
}
|
||
}
|
||
if (rc == RTNORM)
|
||
{
|
||
goto LAB_DRAG;
|
||
}
|
||
}
|
||
ptBase = g_ptBase;
|
||
|
||
switch (rc)
|
||
{
|
||
case RTNORM:
|
||
{
|
||
ptFinal = Ucs2Wcs(ptFinal);
|
||
XPoint vtMove = ptFinal-Ucs2Wcs(g_ptBase);
|
||
ads_matrix mat = { {1.0, 0.0, 0.0, vtMove.x},
|
||
{0.0, 1.0, 0.0, vtMove.y},
|
||
{0.0, 0.0, 1.0, vtMove.z},
|
||
{0.0, 0.0, 0.0, 1.0}};
|
||
|
||
VERIFY(ads_xformss(ss, mat) == RTNORM);
|
||
XPoint pt0 = Ucs2Wcs(ptBase);
|
||
ptBase = pt0.TransformAs(mat);
|
||
ptBase = Wcs2Ucs(ptBase);
|
||
}
|
||
break;
|
||
case RTCAN:
|
||
case RTNONE:
|
||
case RTERROR:
|
||
break;
|
||
}
|
||
ss.Redraw(1);
|
||
|
||
return rc;
|
||
}
|
||
|
||
int XExport::DragPickSet1(PickSet &ss, XPoint &ptBase)
|
||
{
|
||
int rc;
|
||
TCHAR draggenprompt[512] = _T("");
|
||
const TCHAR *szPrompt = _T("\n点取位置或 [转90度(A)/左右翻(S)/上下翻(D)/对齐(F)/改转角(R)/改基点(T)]<退出>:");
|
||
int cur = 0;
|
||
XPoint ptFinal;
|
||
XAdvanceSampler::Init(ptBase, 1);
|
||
XGeLib::adsout << szPrompt;
|
||
|
||
LAB_DRAG:
|
||
ss.Redraw(2);
|
||
INITGET_BEG(RSG_OTHER, _T("A S D F R T"));
|
||
rc = ads_draggen(ss,draggenprompt,cur,XAdvanceSampler::MoveSampler,ptFinal);
|
||
INITGET_END();
|
||
XScreenDc dc(-1);
|
||
dc << XLine(XAdvanceSampler::g_ptBase, XAdvanceSampler::g_ptLastTemp);
|
||
|
||
if (rc == RTKWORD)
|
||
{
|
||
XString sKeyChar;
|
||
VERIFY(ads_getinput(sKeyChar) == RTNORM);
|
||
ads_printf(_T("%c%c %c"), 8,8,8);
|
||
|
||
if (sKeyChar[0] == _T('A') || sKeyChar[0] == _T('S') || sKeyChar[0] == _T('D'))
|
||
{
|
||
XPushVar<int> nMode(_T("OSMODE"), 0);
|
||
if (sKeyChar[0] == _T('S'))
|
||
{
|
||
XPoint ptOther = XAdvanceSampler::g_ptBase+XPoint(0,100,0);
|
||
SHads_command(RTSTR, _T(".MIRROR"), RTPICKS, (LONG_PTR *)ss, RTSTR, _T(""),
|
||
RT3DPOINT, &XAdvanceSampler::g_ptBase, RT3DPOINT, &ptOther, RTSTR, _T("Y"), RTNONE);
|
||
}
|
||
else if (sKeyChar[0] == _T('D'))
|
||
{
|
||
XPoint ptOther = XAdvanceSampler::g_ptBase+XPoint(100,0,0);
|
||
SHads_command(RTSTR, _T(".MIRROR"), RTPICKS, (LONG_PTR *)ss, RTSTR, _T(""),
|
||
RT3DPOINT, &XAdvanceSampler::g_ptBase, RT3DPOINT, &ptOther, RTSTR, _T("Y"), RTNONE);
|
||
}
|
||
else if (sKeyChar[0] == _T('A'))
|
||
{
|
||
SHads_command(RTSTR, _T(".ROTATE"), RTPICKS, (LONG_PTR *)ss, RTSTR, _T(""),
|
||
RT3DPOINT, &XAdvanceSampler::g_ptBase, RTREAL, 90.0, RTNONE);
|
||
}
|
||
rc = RTNORM;
|
||
}
|
||
else if (sKeyChar[0] == _T('F'))
|
||
{
|
||
int nOsMode = 0;
|
||
xg_getvar(_T("OSMODE"), &nOsMode);
|
||
nOsMode &= ~0x4000;
|
||
nOsMode |= OS_INT|OS_NEA|OS_PER|OS_END|OS_MID|OS_CEN;
|
||
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
||
XPoint pt1 = XAdvanceSampler::g_ptBase, pt2, qt1, qt2;
|
||
if (ads_getpoint(NULL, _T("\n对齐参考点:"), pt1) == RTNORM &&
|
||
ads_getpoint(pt1, _T("\n对齐参考轴:"), pt2) == RTNORM &&
|
||
ads_getpoint(NULL, _T("\n对齐目标点:"), qt1) == RTNORM &&
|
||
ads_getpoint(qt1, _T("\n对齐目标轴:"), qt2) == RTNORM)
|
||
{
|
||
XPushVar<int> osmode(_T("OSMODE"), 0);
|
||
double nRot = XExport::CT_std_angle(ads_angle(qt1, qt2)-ads_angle(pt1, pt2));
|
||
SHads_command(RTSTR, _T(".MOVE"), RTPICKS, (LONG_PTR *)ss, RTSTR, _T(""),
|
||
RT3DPOINT, &pt1, RT3DPOINT, &qt1, RTNONE);
|
||
SHads_command(RTSTR, _T(".ROTATE"), RTPICKS, (LONG_PTR *)ss, RTSTR, _T(""),
|
||
RT3DPOINT, &qt1, RTREAL, nRot*180/PI, RTNONE);
|
||
rc = RTNORM;
|
||
return rc;
|
||
}
|
||
rc = RTNORM;
|
||
}
|
||
else if (sKeyChar[0] == _T('R'))
|
||
{
|
||
double nRot = 0.0;
|
||
XGeLib::adsout << _T("\n旋转角度: ");
|
||
rc = SHads_command(RTSTR, _T(".ROTATE"), RTPICKS, (LONG_PTR *)ss,
|
||
RTSTR, _T(""), RT3DPOINT, &XAdvanceSampler::g_ptBase, RTSTR, _T("\\"), RTNONE); //ss.Rotate(g_ptBase, &nRot);
|
||
if (rc == RTNORM)
|
||
{
|
||
XGeLib::adsout << szPrompt;
|
||
}
|
||
}
|
||
else if (sKeyChar[0] == _T('T'))
|
||
{
|
||
ss.Redraw(1);
|
||
|
||
int nOsMode = 0;
|
||
xg_getvar(_T("OSMODE"), &nOsMode);
|
||
nOsMode &= ~0x4000;
|
||
nOsMode |= OS_INT|OS_NEA|OS_PER|OS_END|OS_MID|OS_CEN;
|
||
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
||
rc = XGetPoint(NULL, _T("\n输入插入点"), XAdvanceSampler::g_ptBase);
|
||
if (rc == RTNORM)
|
||
{
|
||
XGeLib::adsout << szPrompt;
|
||
ptBase = XAdvanceSampler::g_ptBase;
|
||
}
|
||
}
|
||
if (rc == RTNORM)
|
||
{
|
||
XAdvanceSampler::g_ptLastTemp = XAdvanceSampler::g_ptBase;
|
||
goto LAB_DRAG;
|
||
}
|
||
}
|
||
ptBase = XAdvanceSampler::g_ptBase;
|
||
|
||
switch (rc)
|
||
{
|
||
case RTSTR:
|
||
case RTNORM:
|
||
{
|
||
if (rc == RTSTR)
|
||
{
|
||
XString str;
|
||
ads_getinput(str);
|
||
ads_polar(XAdvanceSampler::g_ptBase, XAdvanceSampler::g_nDirection, _tstof(str), ptFinal);
|
||
}
|
||
else
|
||
{
|
||
XExport::CapturePoint(XAdvanceSampler::g_ptBase, XPoint(ptFinal), ptFinal);
|
||
}
|
||
ptFinal = Ucs2Wcs(ptFinal);
|
||
XPoint vtMove = ptFinal-Ucs2Wcs(XAdvanceSampler::g_ptBase);
|
||
ads_matrix mat = { {1.0, 0.0, 0.0, vtMove.x},
|
||
{0.0, 1.0, 0.0, vtMove.y},
|
||
{0.0, 0.0, 1.0, vtMove.z},
|
||
{0.0, 0.0, 0.0, 1.0}};
|
||
|
||
VERIFY(ads_xformss(ss, mat) == RTNORM);
|
||
XPoint pt0 = Ucs2Wcs(ptBase);
|
||
ptBase = pt0.TransformAs(mat);
|
||
ptBase = Wcs2Ucs(ptBase);
|
||
rc = RTNORM;
|
||
}
|
||
break;
|
||
case RTCAN:
|
||
case RTNONE:
|
||
case RTERROR:
|
||
break;
|
||
}
|
||
ss.Redraw(1);
|
||
return rc;
|
||
}
|
||
|
||
int XExport::AT_scale(ads_name ssname, ads_point bpt, double *res)
|
||
{
|
||
int rc, ret_tag;
|
||
long i;
|
||
Adesk::Int32 slen;
|
||
TCHAR tstr[512];
|
||
TCHAR draggenprompt[512];
|
||
int cur;
|
||
ads_point tp, p3;
|
||
struct resbuf viewsize;
|
||
ads_name ett;
|
||
|
||
ads_mat_ident(CTM);
|
||
cur = 0;
|
||
ads_getvar(_T("VIEWSIZE"), &viewsize);
|
||
scr_h = viewsize.resval.rreal;
|
||
KwIndex = SXYZ; //NOP;
|
||
rc = ads_sslength(ssname, &slen);
|
||
if (rc != RTNORM || slen == 0L)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
for (i = 0; i<slen; i++)
|
||
{
|
||
ads_ssname(ssname, i, ett);
|
||
ads_redraw(ett, 2);
|
||
}
|
||
|
||
Base[0] = bpt[0]; Base[1] = bpt[1]; Base[2] = bpt[2];
|
||
_tcscpy(draggenprompt, sMsgPrompt[1]);
|
||
ads_initget(RSG_OTHER, NULL);
|
||
rc = ads_draggen(ssname,draggenprompt,cur,dragsampler,p3);
|
||
for (i = 0; i < slen; i++)
|
||
{
|
||
ads_ssname(ssname, i, ett);
|
||
ads_redraw(ett, 1);
|
||
}
|
||
|
||
switch (rc)
|
||
{
|
||
case RTNORM:
|
||
{
|
||
ret_tag = rc;
|
||
*res = ads_distance(bpt, p3)/scr_h*10.0;
|
||
if (ads_xformss(ssname, CTM) != RTNORM)
|
||
{
|
||
XPushVar<int> vOsMode(_T("OSMODE"), 0);
|
||
SHads_command(RTSTR, _T("SCALE"), RTPICKS, ssname,
|
||
RTSTR, _T(""), RT3DPOINT, bpt, RTREAL, (*res), RTNONE);
|
||
}
|
||
}
|
||
break;
|
||
case RTCAN:
|
||
ret_tag = RTCAN;
|
||
break;
|
||
case RTNONE:
|
||
*res = 1.0;
|
||
ret_tag = RTNORM;
|
||
break;
|
||
case RTSTR:
|
||
{
|
||
ads_getinput(tstr);
|
||
if (ads_distof(tstr, 2, res) != RTNORM)
|
||
{
|
||
ads_printf(sMsgPrompt[2]);
|
||
ret_tag = XExport::AT_scale(ssname, bpt, res);
|
||
}
|
||
else
|
||
{
|
||
ads_mat_ident(CTM);
|
||
ads_mat_scale(*res, *res, *res, CTM);
|
||
ads_mat_x_vec(CTM, bpt, tp);
|
||
ads_subvec(bpt, tp, tp);
|
||
CTM[X][T] = tp[X];
|
||
CTM[Y][T] = tp[Y];
|
||
CTM[Z][T] = tp[Z];
|
||
if (ads_xformss(ssname, CTM) != RTNORM)
|
||
{
|
||
XPushVar<int> vOsMode(_T("OSMODE"), 0);
|
||
SHads_command(RTSTR, _T("SCALE"), RTPICKS, ssname,
|
||
RTSTR, _T(""), RT3DPOINT, bpt, RTREAL, (*res), RTNONE);
|
||
}
|
||
ret_tag = RTNORM;
|
||
}
|
||
}
|
||
break;
|
||
case RTERROR:
|
||
default:
|
||
ads_printf(_T("\nDrag operation failed\n"));
|
||
ret_tag = RTERROR;
|
||
break;
|
||
}
|
||
return ret_tag;
|
||
}
|
||
|
||
int XExport::AT_rotate(ads_name ssname, ads_point bpt, double *res)
|
||
{
|
||
int rc, ret_tag;
|
||
long i;
|
||
Adesk::Int32 slen;
|
||
TCHAR tstr[512];
|
||
TCHAR draggenprompt[512];
|
||
int cur;
|
||
ads_point tp, p3;
|
||
ads_name ett;
|
||
|
||
ads_mat_ident(CTM);
|
||
cur = 0;
|
||
|
||
KwIndex = RZ;
|
||
rc = ads_sslength(ssname, &slen);
|
||
if (rc != RTNORM || slen == 0L)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
for (i = 0; i<slen; i++)
|
||
{
|
||
ads_ssname(ssname, i, ett);
|
||
ads_redraw(ett, 2);
|
||
}
|
||
|
||
Base[0] = bpt[0]; Base[1] = bpt[1]; Base[2] = bpt[2];
|
||
_tcscpy(draggenprompt, sMsgPrompt[3]);
|
||
ads_initget(RSG_OTHER, NULL);
|
||
rc = ads_draggen(ssname,draggenprompt,cur,dragsampler,p3);
|
||
for (i = 0; i<slen; i++)
|
||
{
|
||
ads_ssname(ssname, i, ett);
|
||
ads_redraw(ett, 1);
|
||
}
|
||
|
||
switch (rc)
|
||
{
|
||
case RTNORM:
|
||
ret_tag = rc;
|
||
*res = ads_angle(bpt, p3)*180.0/3.1415926897932;
|
||
if (ads_xformss(ssname, CTM) != RTNORM)
|
||
{
|
||
XPushVar<int> vOsMode(_T("OSMODE"), 0);
|
||
SHads_command(RTSTR, _T("ROTATE"), RTPICKS, ssname, RTSTR, _T(""),
|
||
RT3DPOINT, bpt, RTREAL, *res, RTNONE);
|
||
}
|
||
break;
|
||
case RTCAN:
|
||
ret_tag = RTCAN;
|
||
break;
|
||
case RTNONE:
|
||
*res = 0.0;
|
||
ret_tag = RTNORM;
|
||
break;
|
||
case RTSTR:
|
||
ads_getinput(tstr);
|
||
if (ads_distof(tstr, 2, res) != RTNORM)
|
||
{
|
||
ads_printf(sMsgPrompt[2]); // Invalid input
|
||
ret_tag = XExport::AT_rotate(ssname, bpt, res);
|
||
}
|
||
else
|
||
{
|
||
ads_mat_ident(CTM);
|
||
ads_mat_rot((*res)*3.14159/180.0, Z, CTM);
|
||
ads_mat_x_vec(CTM, bpt, tp);
|
||
ads_subvec(bpt, tp, tp);
|
||
CTM[X][T] = tp[X];
|
||
CTM[Y][T] = tp[Y];
|
||
CTM[Z][T] = tp[Z];
|
||
if (ads_xformss(ssname, CTM) != RTNORM)
|
||
{
|
||
SHads_command(RTSTR, _T("ROTATE"), RTPICKS, ssname, RTSTR, _T(""),
|
||
RT3DPOINT, bpt, RTREAL, *res, RTNONE);
|
||
}
|
||
ret_tag = RTNORM;
|
||
}
|
||
break;
|
||
|
||
case RTERROR:
|
||
default:
|
||
ads_printf(/*MSG20*/_T("\nDrag operation failed\n"));
|
||
ret_tag = RTERROR;
|
||
break;
|
||
}
|
||
return ret_tag;
|
||
}
|
||
|
||
int XExport::AT_move(ads_name ssname, ads_point bpt, ads_point res)
|
||
{
|
||
int rc, ret_tag;
|
||
Adesk::Int32 slen;
|
||
long i;
|
||
TCHAR draggenprompt[512];
|
||
int cur, nOldFlag;
|
||
ads_name ett;
|
||
|
||
ads_mat_ident(CTM);
|
||
cur = 0;
|
||
|
||
KwIndex = MXYZ; //NOP;
|
||
rc = ads_sslength(ssname, &slen);
|
||
if (rc != RTNORM || slen == 0L)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
for (i = 0; i<slen; i++)
|
||
{
|
||
ads_ssname(ssname, i, ett);
|
||
ads_redraw(ett, 2);
|
||
}
|
||
|
||
Base[0] = bpt[0];
|
||
Base[1] = bpt[1];
|
||
Base[2] = bpt[2];
|
||
_tcscpy(draggenprompt, sMsgPrompt[0]);
|
||
nOldFlag = g_nDragFlag;
|
||
g_nDragFlag = 1; //Move
|
||
ads_initget(0, NULL);
|
||
rc = ads_draggen(ssname,draggenprompt,cur,dragsampler,res);
|
||
g_nDragFlag = nOldFlag;
|
||
for (i = 0; i<slen; i++)
|
||
{
|
||
ads_ssname(ssname, i, ett);
|
||
ads_redraw(ett, 1);
|
||
}
|
||
|
||
switch (rc)
|
||
{
|
||
case RTNORM:
|
||
if (ads_xformss(ssname, CTM) != RTNORM)
|
||
{
|
||
XPushVar<int> vOsMode(_T("OSMODE"), 0);
|
||
SHads_command(RTSTR, _T("MOVE"), RTPICKS, ssname, RTSTR, _T(""),
|
||
RT3DPOINT, bpt, RT3DPOINT, res, RTNONE);
|
||
}
|
||
ret_tag = rc;
|
||
break;
|
||
case RTCAN:
|
||
ret_tag = RTCAN;
|
||
break;
|
||
case RTNONE:
|
||
ret_tag = RTNONE;
|
||
break;
|
||
case RTERROR:
|
||
default:
|
||
ads_printf(_T("\nDrag operation failed\n"));
|
||
ret_tag = RTERROR;
|
||
break;
|
||
}
|
||
return ret_tag;
|
||
}
|
||
|
||
void XExport::arxZoomCursor(XPoint ptDcs, double nScale)
|
||
{
|
||
int viewmode;
|
||
VERIFY(xg_getvar(_T("VIEWMODE"), &viewmode) == RTNORM);
|
||
|
||
double nWidth, nHeight;
|
||
AT_ScrSize(&nWidth, &nHeight);
|
||
nWidth *= nScale;
|
||
nHeight *= nScale;
|
||
Groups g1(1), g0(0);
|
||
if (!viewmode)
|
||
{
|
||
AcDbViewTableRecord view;
|
||
XPoint vtViewDir;
|
||
view.setCenterPoint(ptDcs.AsAcGePoint2d());
|
||
view.setHeight( nHeight);
|
||
view.setWidth( nWidth );
|
||
VERIFY(xg_getvar(_T("VIEWDIR"), &vtViewDir) == RTNORM);
|
||
ads_trans(XPoint(vtViewDir), (resbuf *)&g1, (resbuf *)&g0, 1, vtViewDir);
|
||
view.setViewDirection(vtViewDir);
|
||
|
||
double viewtwist = 0.0;
|
||
VERIFY(xg_getvar(_T("VIEWTWIST"), &viewtwist) == RTNORM);
|
||
view.setViewTwist(viewtwist);
|
||
|
||
XPoint target;
|
||
VERIFY(xg_getvar(_T("TARGET"), &target) == RTNORM);
|
||
ads_trans(XPoint(target), (resbuf *)&g1, (resbuf *)&g0, 0, target);
|
||
view.setTarget(target);
|
||
|
||
int nCurVp;
|
||
VERIFY(xg_getvar(_T("CVPORT"), &nCurVp) == RTNORM);
|
||
view.setIsPaperspaceView(nCurVp == 1);
|
||
Acad::ErrorStatus es = Acad::eOk;
|
||
es = acdbSetCurrentView( &view, NULL );
|
||
}
|
||
else
|
||
{ //透视方式
|
||
AcDbViewTableRecord view;
|
||
XPoint vtViewDir;
|
||
view.setCenterPoint(ptDcs.AsAcGePoint2d());
|
||
view.setHeight( nHeight);
|
||
view.setWidth( nWidth );
|
||
VERIFY(xg_getvar(_T("VIEWDIR"), &vtViewDir) == RTNORM);
|
||
ads_trans(XPoint(vtViewDir), (resbuf *)&g1, (resbuf *)&g0, 1, vtViewDir);
|
||
vtViewDir.x *= nScale;
|
||
vtViewDir.y *= nScale;
|
||
vtViewDir.z *= nScale;
|
||
view.setViewDirection(vtViewDir);
|
||
|
||
//view.setElevation(ptDcs.z); // New added
|
||
if (viewmode&0x01)
|
||
{
|
||
view.setPerspectiveEnabled(true);
|
||
if (viewmode&0x04)
|
||
{// Back Clip On
|
||
double backz = 0.0;
|
||
VERIFY(xg_getvar(_T("BACKZ"), &backz) == RTNORM);
|
||
view.setBackClipEnabled(true);
|
||
view.setBackClipDistance(backz);
|
||
}
|
||
if (viewmode&0x02)
|
||
{ // Front Clip On
|
||
view.setFrontClipEnabled(true);
|
||
if (viewmode&0x10)
|
||
{ // front clip not at eye
|
||
view.setFrontClipAtEye(false);
|
||
double frontz = 0.0;
|
||
VERIFY(xg_getvar(_T("FRONTZ"), &frontz) == RTNORM);
|
||
view.setFrontClipDistance(frontz);
|
||
}
|
||
else
|
||
{
|
||
view.setFrontClipAtEye(true);
|
||
}
|
||
}
|
||
double lenslength = 0.0;
|
||
VERIFY(xg_getvar(_T("LENSLENGTH"), &lenslength) == RTNORM);
|
||
view.setLensLength(lenslength);
|
||
|
||
double viewtwist = 0.0;
|
||
VERIFY(xg_getvar(_T("VIEWTWIST"), &viewtwist) == RTNORM);
|
||
view.setViewTwist(viewtwist);
|
||
|
||
XPoint target;
|
||
VERIFY(xg_getvar(_T("TARGET"), &target) == RTNORM);
|
||
ads_trans(XPoint(target), (resbuf *)&g1, (resbuf *)&g0, 0, target);
|
||
view.setTarget(target);
|
||
}
|
||
|
||
Acad::ErrorStatus es = Acad::eOk;
|
||
es = acdbSetCurrentView( &view, NULL );
|
||
}
|
||
}
|
||
|
||
// 让GsView固定下来
|
||
BOOL XExport::PersistGsView(AcGsView *pGsView)
|
||
{
|
||
if (!pGsView)
|
||
{
|
||
int nVportId = 0;
|
||
xg_getvar(_T("CVPORT"), &nVportId);
|
||
#if ARX < 20
|
||
pGsView = acgsGetGsView(nVportId, false);
|
||
#else
|
||
pGsView = NULL;
|
||
#endif
|
||
}
|
||
if (pGsView)
|
||
{
|
||
AcDbViewTableRecord view;
|
||
AcGeVector3d vtViewDir = pGsView->position() - pGsView->target();
|
||
view.setCenterPoint(AcGePoint2d(0,0));
|
||
view.setHeight(pGsView->fieldHeight());
|
||
view.setWidth(pGsView->fieldWidth());
|
||
view.setViewDirection(vtViewDir);
|
||
view.setPerspectiveEnabled(pGsView->isPerspective());
|
||
view.setBackClipEnabled(pGsView->isBackClipped());
|
||
view.setBackClipDistance(pGsView->backClip());
|
||
view.setFrontClipEnabled(pGsView->isFrontClipped());
|
||
view.setFrontClipAtEye(!pGsView->isFrontClipped() ? true : false);
|
||
view.setFrontClipDistance(pGsView->frontClip());
|
||
double nLens = 25;
|
||
xg_getvar(_T("LENSLENGTH"), &nLens);
|
||
view.setLensLength(nLens);
|
||
view.setViewTwist(0.0);
|
||
view.setTarget(pGsView->target());
|
||
|
||
BOOL bRet = (acedSetCurrentView( &view, NULL ) == Acad::eOk);
|
||
return bRet;
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::ExplodeBlockRef(const AcDbBlockTableRecord &blockRec, const AcGeMatrix3d &mat, AcDbVoidPtrArray &entSet)
|
||
{
|
||
AcDbBlockTableRecordIterator* pBlockIterator;
|
||
Acad::ErrorStatus es = ((AcDbBlockTableRecord &)blockRec).newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead, Adesk::kTrue);
|
||
ASSERT(es == Acad::eOk);
|
||
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
pEntity->close();
|
||
continue;
|
||
}
|
||
|
||
AcDbEntity *pEntCopy = NULL;
|
||
Acad::ErrorStatus es1;
|
||
if ((es1 = pEntity->getTransformedCopy(mat, pEntCopy)) == Acad::eOk && pEntCopy)
|
||
{
|
||
entSet.append(pEntCopy);
|
||
}
|
||
else
|
||
{
|
||
es = es1;
|
||
}
|
||
pEntity->close();
|
||
}
|
||
delete pBlockIterator;
|
||
return es;
|
||
}
|
||
|
||
|
||
|
||
// 从块表中取所有的曲线: 包括LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,以及在INSERT中的前述实体
|
||
void XExport::Get2DCurveFromBlock(AcDbBlockTableRecord &blockRec, ads_matrix matForInsert)
|
||
{
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
Acad::ErrorStatus es = blockRec.newIterator(pBlockIterator, Adesk::kTrue, Adesk::kFalse);
|
||
ASSERT(es == Acad::eOk && !!pBlockIterator);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
pBlockIterator->getEntity(pEntity, AcDb::kForRead, Adesk::kTrue);
|
||
if (pEntity == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (pEntity->isKindOf(AcDbPolyline::desc()) || pEntity->isKindOf(AcDb2dPolyline::desc()))
|
||
{
|
||
AcDbVoidPtrArray entSet;
|
||
pEntity->explode(entSet);
|
||
for (long i = 0;i<entSet.length();i++)
|
||
{
|
||
AcDbEntity*pEnt = (AcDbEntity*)entSet[i],*pNewEnt = NULL;
|
||
pEnt->getTransformedCopy(AsAcGeMatrix3d(matForInsert),pNewEnt);
|
||
if (pNewEnt != NULL)
|
||
{
|
||
if (XExport::AddToCurrentSpace(pNewEnt,Adesk::kTrue) == AcDbObjectId::kNull)
|
||
{
|
||
delete pNewEnt;
|
||
}
|
||
}
|
||
}
|
||
ReleaseEntSet(entSet);
|
||
}
|
||
else if (pEntity->isKindOf(AcDbBlockReference::desc()))
|
||
{ //嵌套图块
|
||
AcDbBlockReference *pInsert = AcDbBlockReference::cast(pEntity);
|
||
ASSERT(pInsert);
|
||
XPoint ptLoc = pInsert->position();
|
||
double nRot = pInsert->rotation();
|
||
AcGeScale3d scale = pInsert->scaleFactors();
|
||
AcDbObjectId idBlock = pInsert->blockTableRecord();
|
||
XDbObject objBlock(idBlock, AcDb::kForRead);
|
||
ASSERT(!!objBlock);
|
||
AcDbBlockTableRecord *pRec = AcDbBlockTableRecord::cast(objBlock.m_pObject);
|
||
ASSERT(pRec);
|
||
XPoint ptBase = pRec->origin();
|
||
ads_matrix mat1, mat2;
|
||
get_matrix(ptBase, ptLoc, scale[0], scale[1], scale[2], nRot, mat1);
|
||
AT_multiply_matrix(matForInsert, mat1, mat2);
|
||
XExport::Get2DCurveFromBlock(*pRec, mat2);
|
||
}
|
||
else
|
||
{
|
||
AcDbEntity* pNewEnt = NULL;
|
||
pEntity->getTransformedCopy(AsAcGeMatrix3d(matForInsert),pNewEnt);
|
||
if (pNewEnt != NULL)
|
||
{
|
||
if (XExport::AddToCurrentSpace(pNewEnt,Adesk::kTrue) == AcDbObjectId::kNull)
|
||
{
|
||
delete pNewEnt;
|
||
}
|
||
}
|
||
}
|
||
pEntity->close();
|
||
}
|
||
delete pBlockIterator;
|
||
}
|
||
|
||
|
||
|
||
// 由二维图块提取二维曲线段,ssRes中将加入当前数据库空间
|
||
int XExport::GetCurveFromInsert2D(Entity &ent, PickSet &ssRes)
|
||
{
|
||
if (!ent.Is(_T("INSERT")) && !ent.Is(_T("AEC_BLOCK_INSERT")) && !ent.Is(_T("AEC_MVINSERT")))
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
ads_matrix mat;
|
||
GetInsertMatrix(ent, mat);
|
||
XString sBlockName(256);
|
||
int nCode = (ent.Is(_T("AEC_MVINSERT"))? 1 : 2);
|
||
VERIFY(ent.GetData(nCode, (TCHAR *)sBlockName) == RTNORM);
|
||
XBlockTableRecPtr rec(sBlockName, AcDb::kForRead);
|
||
ASSERT(!!rec);
|
||
|
||
ssRes.IncludeBegin();
|
||
XExport::Get2DCurveFromBlock(*rec.m_pBlockTableRec, mat);
|
||
ssRes.IncludeEnd();
|
||
|
||
return RTNORM;
|
||
}
|
||
|
||
|
||
|
||
|
||
//模拟insert命令,可以处理属性
|
||
void XExport::InsertInCurrentSpace(AcDbObjectId idBlockRecord,AcGePoint3d ptIns,AcGeScale3d scale,double angle)
|
||
{
|
||
AcDbBlockReference *pBlockRef = new AcDbBlockReference;
|
||
pBlockRef->setBlockTableRecord(idBlockRecord);
|
||
pBlockRef->setPosition(ptIns);
|
||
pBlockRef->setScaleFactors(scale);
|
||
pBlockRef->setRotation(angle);
|
||
XExport::AddToCurrentSpace(pBlockRef,Adesk::kFalse);
|
||
|
||
AcDbBlockTableRecord *pBlockRecord = NULL;
|
||
acdbOpenObject(pBlockRecord,idBlockRecord,AcDb::kForRead);
|
||
if (pBlockRecord != NULL)
|
||
{
|
||
if (pBlockRecord->hasAttributeDefinitions())//有属性
|
||
{
|
||
AcDbBlockTableRecordIterator *pIter = NULL;
|
||
pBlockRecord->newIterator(pIter);
|
||
if (pIter != NULL)
|
||
{
|
||
AcGeMatrix3d mat = pBlockRef->blockTransform();
|
||
|
||
for (pIter->start();!pIter->done();pIter->step())
|
||
{
|
||
AcDbEntity *pEnt = NULL;
|
||
pIter->getEntity(pEnt,AcDb::kForRead);
|
||
if (pEnt != NULL)
|
||
{
|
||
AcDbAttributeDefinition*pAttDef = AcDbAttributeDefinition::cast(pEnt);
|
||
if (pAttDef != NULL)
|
||
{
|
||
AcDbAttribute *pAttr = new AcDbAttribute;
|
||
pAttr->setAttributeFromBlock(pAttDef,mat);
|
||
pBlockRef->appendAttribute(pAttr);
|
||
pAttr->close();
|
||
}
|
||
|
||
pEnt->close();
|
||
}
|
||
}
|
||
|
||
delete pIter;
|
||
}
|
||
}
|
||
pBlockRecord->close();
|
||
}
|
||
|
||
pBlockRef->close();
|
||
}
|
||
|
||
int XExport::GetPickSetByGroup(const TCHAR *szGroup, PickSet &ss)
|
||
{
|
||
AcDbDictionary* pGroupDict;
|
||
if (acdbCurDwg()->getGroupDictionary(pGroupDict, AcDb::kForRead) != Acad::eOk)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
assert(pGroupDict);
|
||
AcDbObjectId groupId;
|
||
int nRet = RTERROR;
|
||
if (pGroupDict->getAt(szGroup, groupId) == Acad::eOk)
|
||
{
|
||
AcDbGroup *pGroup;
|
||
acdbOpenObject(pGroup, groupId, AcDb::kForRead);
|
||
assert(pGroup);
|
||
AcDbGroupIterator *pIter = pGroup->newIterator();
|
||
for ( ; !pIter->done(); pIter->next())
|
||
{
|
||
ads_name ent;
|
||
acdbGetAdsName(ent, pIter->objectId());
|
||
ss += Entity(ent);
|
||
}
|
||
delete pIter;
|
||
pGroup->close();
|
||
nRet = RTNORM;
|
||
}
|
||
pGroupDict->close();
|
||
return nRet;
|
||
}
|
||
|
||
int XExport::MakeGroup(PickSet &ss, const TCHAR *pGroupName, BOOL bClearOld)
|
||
{
|
||
Acad::ErrorStatus es;
|
||
AcDbObjectId groupobjId;
|
||
AcDbGroup *pGroup = NULL;
|
||
AcDbDictionary *pGroupDict = NULL;
|
||
|
||
es = acdbCurDwg()->getGroupDictionary(pGroupDict,AcDb::kForWrite);
|
||
if (es != Acad::eOk)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
es = pGroupDict->getAt(pGroupName,groupobjId);
|
||
if (es == Acad::eOk)
|
||
{
|
||
// 取得pGroup并清空
|
||
es = acdbOpenObject(pGroup, groupobjId, AcDb::kForWrite);
|
||
if (es != Acad::eOk)
|
||
{
|
||
pGroupDict->close();
|
||
return RTERROR;
|
||
}
|
||
pGroup->setSelectable(Adesk::kFalse);
|
||
if (bClearOld)
|
||
{
|
||
pGroup->clear();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//新建一组,并添入字典
|
||
pGroup = new AcDbGroup;
|
||
pGroup->setSelectable(Adesk::kFalse);
|
||
es = pGroupDict->setAt(pGroupName,pGroup,groupobjId);
|
||
assert(es == Acad::eOk);
|
||
}
|
||
pGroupDict->close();
|
||
|
||
//往组中添加选择集中的实体
|
||
AcDbObjectId objectId;
|
||
long nLen = ss.Length();
|
||
|
||
for (long i = 0L; i < nLen; i++)
|
||
{
|
||
Entity en = ss[i];
|
||
if (acdbGetObjectId(objectId,en) != Acad::eOk)
|
||
{
|
||
pGroup->close();
|
||
return RTERROR;
|
||
}
|
||
if (pGroup->append(objectId) != Acad::eOk)
|
||
{
|
||
pGroup->close();
|
||
return RTERROR;
|
||
}
|
||
}
|
||
pGroup->close();
|
||
|
||
return RTNORM;
|
||
|
||
}
|
||
|
||
// 把象素值转化为当前坐标系下的长度
|
||
double XExport::PixelToWcs(int nPixel)
|
||
{
|
||
XPoint ptScreenSize;
|
||
double nViewSize;
|
||
xg_getvar(_T("ScreenSize"), &ptScreenSize);
|
||
xg_getvar(_T("ViewSize"), &nViewSize);
|
||
if (ptScreenSize.y < 1.0E-6 || nViewSize < 1.0E-6)
|
||
{
|
||
return 0.0;
|
||
}
|
||
double hight = (nViewSize / ptScreenSize.y) * nPixel;
|
||
return hight;
|
||
}
|
||
|
||
// 得到耙区在WCS下的大小
|
||
double XExport::GetApertureWcs()
|
||
{
|
||
int nAperture = 1;
|
||
VERIFY(xg_getvar(_T("APERTURE"), &nAperture) == RTNORM);
|
||
if (nAperture < 1)
|
||
{
|
||
return 0.0;
|
||
}
|
||
double nApertureWcs = XExport::PixelToWcs(nAperture);
|
||
ASSERT(nApertureWcs > 0.0);
|
||
return nApertureWcs;
|
||
}
|
||
|
||
double XExport::GetPickBoxWcs()
|
||
{
|
||
int nAperture = 1;
|
||
VERIFY(xg_getvar(_T("PICKBOX"), &nAperture) == RTNORM);
|
||
if (nAperture < 1)
|
||
{
|
||
return 0.0;
|
||
}
|
||
double nApertureWcs = XExport::PixelToWcs(nAperture);
|
||
ASSERT(nApertureWcs > 0.0);
|
||
return nApertureWcs;
|
||
}
|
||
|
||
void XExport::get_matrix(const XPoint &ptBase, const XPoint &ptInsert,
|
||
double sx, double sy, double sz, double rot, ads_matrix result)
|
||
{
|
||
// XPoint mv = insPt-blkTab.base;
|
||
// 先移动base到原点, Scale, Rotation, 再平移到insPt
|
||
ads_matrix mvMat1 = { {1, 0, 0, -ptBase.x},
|
||
{0, 1, 0, -ptBase.y},
|
||
{0, 0, 1, -ptBase.z},
|
||
{0, 0, 0, 1},};
|
||
|
||
ads_matrix sclMat = { {sx, 0, 0, 0},
|
||
{0, sy, 0, 0},
|
||
{0, 0, sz, 0},
|
||
{0, 0, 0, 1},};
|
||
|
||
ads_matrix rotMat = { {cos(rot), -sin(rot), 0, 0},
|
||
{sin(rot), cos(rot), 0, 0},
|
||
{0, 0, 1, 0},
|
||
{0, 0, 0, 1},};
|
||
|
||
ads_matrix mvMat2 = { {1, 0, 0, ptInsert.x},
|
||
{0, 1, 0, ptInsert.y},
|
||
{0, 0, 1, ptInsert.z},
|
||
{0, 0, 0, 1},};
|
||
|
||
MatrixMultiply(result, mvMat2, rotMat, sclMat, mvMat1, NULL);
|
||
}
|
||
|
||
int XExport::GetBlockExtents(AcDbObjectId idBlock, XPoint &ptLow, XPoint &ptUp)
|
||
{
|
||
XPoint ptMin, ptMax;
|
||
BOOL bInit = FALSE;
|
||
|
||
OPENOBJ_BEGIN(idBlock, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
|
||
ASSERT(pBlock);
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
Acad::ErrorStatus es = pBlock->newIterator(pBlockIterator, Adesk::kTrue, Adesk::kFalse);
|
||
ASSERT(es == Acad::eOk && pBlockIterator);
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead, Adesk::kTrue);
|
||
ASSERT(es == Acad::eOk);
|
||
XDbObject obj(pEntity);
|
||
XPoint pt1, pt2;
|
||
if (pEntity->isKindOf(AcDbRasterImage::desc()) || pEntity->isKindOf(AcDbAttributeDefinition::desc()))
|
||
{
|
||
continue;
|
||
}
|
||
else if (pEntity->isKindOf(AcDbBlockReference::desc()))
|
||
{
|
||
AcDbBlockReference *pInsert = AcDbBlockReference::cast(pEntity);
|
||
AcGeMatrix3d mat = BlockTransform(pInsert);
|
||
if (XExport::GetBlockExtents(pInsert->blockTableRecord(), pt1, pt2) != RTNORM)
|
||
{
|
||
continue;
|
||
}
|
||
((AcGePoint3d &)pt1).transformBy(mat);
|
||
((AcGePoint3d &)pt2).transformBy(mat);
|
||
}
|
||
else
|
||
{
|
||
AcDbExtents extent;
|
||
if (pEntity->getGeomExtents(extent) != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
pt1 = extent.minPoint();
|
||
pt2 = extent.maxPoint();
|
||
}
|
||
if (!bInit)
|
||
{
|
||
ptMin = pt1;
|
||
ptMax = pt2;
|
||
bInit = TRUE;
|
||
}
|
||
else
|
||
{
|
||
ptMin = Min(pt1, ptMin);
|
||
ptMax = Max(pt2, ptMax);
|
||
}
|
||
}
|
||
delete pBlockIterator;
|
||
OPENOBJ_END();
|
||
|
||
if (bInit)
|
||
{
|
||
ptLow = ptMin;
|
||
ptUp = ptMax;
|
||
}
|
||
return (bInit? RTNORM : RTERROR);
|
||
}
|
||
|
||
// 取图块的尺寸信息
|
||
int XExport::GetBlockRefSizeInfo(const AcDbBlockReference *pBlkRef, XPoint &ptBase, double *nRot,
|
||
XPoint &ptCen, double *nSizeX, double *nSizeY, double *nSizeZ)
|
||
{
|
||
ASSERT(pBlkRef);
|
||
if (!pBlkRef)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
*nRot = pBlkRef->rotation();
|
||
ptBase = pBlkRef->position();
|
||
|
||
ads_matrix mat;
|
||
ptBase.GetRotationMatrix(*nRot, mat);
|
||
|
||
XPoint ptMin, ptMax;
|
||
if (XExport::GetBlockExtents(pBlkRef->blockTableRecord(), ptMin, ptMax) != RTNORM)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
AcGeScale3d scale = pBlkRef->scaleFactors();
|
||
*nSizeX = fabs(ptMax.x - ptMin.x)*scale[0];
|
||
*nSizeY = fabs(ptMax.y - ptMin.y)*scale[1];
|
||
*nSizeZ = fabs(ptMax.z - ptMin.z)*scale[2];
|
||
|
||
AcGeMatrix3d mat3d = BlockTransform(pBlkRef);
|
||
((AcGePoint3d &)ptMin).transformBy(mat3d);
|
||
((AcGePoint3d &)ptMax).transformBy(mat3d);
|
||
Midpoint(ptMin, ptMax, ptCen);
|
||
return RTNORM;
|
||
}
|
||
|
||
// 由字符串换算线型的id
|
||
AcDbObjectId XExport::GetLinetypeIdFromString(const TCHAR* pStr, AcDbDatabase *pDb)
|
||
{
|
||
if (!pDb)
|
||
{
|
||
pDb = acdbCurDwg();
|
||
}
|
||
AcDbObjectId id;
|
||
if (pStr)
|
||
{
|
||
AcDbLinetypeTable* pLinetypeTable = NULL;
|
||
|
||
Acad::ErrorStatus err = pDb->getLinetypeTable(pLinetypeTable, AcDb::kForRead);
|
||
if (err == Acad::eOk && pLinetypeTable)
|
||
{
|
||
err = pLinetypeTable->getAt(pStr, id);
|
||
pLinetypeTable->close();
|
||
}
|
||
}
|
||
return id;
|
||
}
|
||
|
||
// 由字符串换算层的id
|
||
AcDbObjectId XExport::GetLayerIdFromString(const TCHAR* pStr, AcDbDatabase *pDb)
|
||
{
|
||
if (!pDb)
|
||
{
|
||
pDb = acdbCurDwg();
|
||
}
|
||
AcDbObjectId id;
|
||
if (pStr)
|
||
{
|
||
AcDbLayerTable* pLayerTable = NULL;
|
||
Acad::ErrorStatus err = pDb->getLayerTable(pLayerTable,AcDb::kForRead);
|
||
if (err == Acad::eOk && pLayerTable)
|
||
{
|
||
err = pLayerTable->getAt(pStr, id);
|
||
pLayerTable->close();
|
||
}
|
||
}
|
||
return id;
|
||
}
|
||
|
||
// 由字型名称求ID
|
||
AcDbObjectId XExport::GetTextStyleId(const TCHAR *styleName, AcDbDatabase *pDb)
|
||
{
|
||
if (!pDb)
|
||
{
|
||
pDb = acdbCurDwg();
|
||
}
|
||
AcDbTextStyleTable *pStyleTable;
|
||
Acad::ErrorStatus es = pDb->getTextStyleTable(pStyleTable, AcDb::kForRead);
|
||
AcDbObjectId styleId;
|
||
if (es == Acad::eOk)
|
||
{
|
||
es = pStyleTable->getAt(styleName, styleId);
|
||
pStyleTable->close();
|
||
}
|
||
return styleId;
|
||
}
|
||
|
||
AcDbObjectId XExport::GetDimStyleId(const TCHAR *styleName, AcDbDatabase *pDb)
|
||
{
|
||
if (!pDb)
|
||
{
|
||
pDb = acdbCurDwg();
|
||
}
|
||
|
||
AcDbDimStyleTable *pStyleTable;
|
||
Acad::ErrorStatus es = pDb->getDimStyleTable(pStyleTable, AcDb::kForRead);
|
||
AcDbObjectId styleId;
|
||
if (es == Acad::eOk)
|
||
{
|
||
es = pStyleTable->getAt(styleName, styleId);
|
||
pStyleTable->close();
|
||
}
|
||
return styleId;
|
||
}
|
||
|
||
AcDbObjectId XExport::InitLineType(const TCHAR *szLineType, AcDbDatabase *pDb)
|
||
{
|
||
if (!pDb)
|
||
{
|
||
pDb = acdbCurDwg();
|
||
}
|
||
AcDbObjectId idLineType = XExport::GetLinetypeIdFromString(szLineType, pDb);
|
||
if (!idLineType)
|
||
{
|
||
pDb->loadLineTypeFile(szLineType, _T("acad.lin"));
|
||
idLineType = XExport::GetLinetypeIdFromString(szLineType, pDb);
|
||
}
|
||
return idLineType;
|
||
}
|
||
|
||
AcDbObjectId XExport::InitTchLineType(const TCHAR *szLineType, AcDbDatabase *pDb)
|
||
{
|
||
if (!pDb)
|
||
{
|
||
pDb = acdbCurDwg();
|
||
}
|
||
AcDbObjectId idLineType = XExport::GetLinetypeIdFromString(szLineType, pDb);
|
||
if (!idLineType)
|
||
{
|
||
pDb->loadLineTypeFile(szLineType, _T("Aec.lin"));
|
||
idLineType = XExport::GetLinetypeIdFromString(szLineType, pDb);
|
||
}
|
||
return idLineType;
|
||
}
|
||
|
||
AcDbObjectId XExport::GetBlockIdFromString(const TCHAR *pszBlock, AcDbDatabase *pDb)
|
||
{
|
||
XBlockTableRecPtr blk(pszBlock, AcDb::kForRead, pDb);
|
||
AcDbObjectId id;
|
||
if (!!blk)
|
||
{
|
||
id = blk.m_pBlockTableRec->objectId();
|
||
}
|
||
return id;
|
||
}
|
||
|
||
extern Acad::ErrorStatus fromAcDbTextStyle(AcGiTextStyle& style, const AcDbObjectId& AcDbStyleId);
|
||
// 把AcDbTextStyle转成AcGiTextStyle
|
||
Acad::ErrorStatus XExport::GetAcGiTextStyle(AcDbObjectId styleId, AcGiTextStyle &newStyle)
|
||
{
|
||
return fromAcDbTextStyle(newStyle, styleId);
|
||
}
|
||
|
||
// 确定文字尺寸, 优先顺序
|
||
// style默认尺寸--当前字型尺寸--当前文字尺寸
|
||
double XExport::GetTextSize(const TCHAR *m_sTextStyle)
|
||
{
|
||
double dTextSize = 0.0;
|
||
VERIFY(xg_getvar(_T("TEXTSIZE"), &dTextSize) == RTNORM);
|
||
|
||
XString sTextStyle;
|
||
if (!m_sTextStyle)
|
||
{
|
||
xg_getvar(_T("TEXTSTYLE"), sTextStyle);
|
||
}
|
||
else
|
||
{
|
||
sTextStyle = m_sTextStyle;
|
||
}
|
||
|
||
AcDbObjectId idTextStyle = GetTextStyleId(sTextStyle);
|
||
if (!idTextStyle)
|
||
{
|
||
return dTextSize;
|
||
}
|
||
XDbObject obj(idTextStyle, AcDb::kForRead);
|
||
if (!obj)
|
||
{
|
||
return dTextSize;
|
||
}
|
||
|
||
AcDbTextStyleTableRecord *newStyle = AcDbTextStyleTableRecord::cast(obj.m_pObject);
|
||
ASSERT(newStyle);
|
||
|
||
|
||
if (newStyle->textSize() > 1.0E-6)
|
||
{
|
||
dTextSize = newStyle->textSize();
|
||
}
|
||
return dTextSize;
|
||
}
|
||
|
||
// 释放实体集合 entSet通常是炸碎的结果
|
||
void XExport::ReleaseEntSet(AcDbVoidPtrArray &entSet)
|
||
{
|
||
while(!entSet.isEmpty())
|
||
{
|
||
AcDbEntity *pEnt = AcDbEntity::cast((AcDbEntity *)entSet[0]);
|
||
if (pEnt != NULL)
|
||
{
|
||
delete pEnt;
|
||
}
|
||
entSet.removeAt(0);
|
||
}
|
||
}
|
||
|
||
void XExport::InitView(AcDbViewTableRecord &view)
|
||
{
|
||
int viewmode;
|
||
VERIFY(xg_getvar(_T("VIEWMODE"), &viewmode) == RTNORM);
|
||
|
||
XPoint ptViewCtr;
|
||
VERIFY(xg_getvar(_T("VIEWCTR"), &ptViewCtr) == RTNORM);
|
||
XPoint ptDcs;
|
||
ads_trans(ptViewCtr, Groups(1), Groups(2), 0, ptDcs);
|
||
|
||
int nCurVp;
|
||
VERIFY(xg_getvar(_T("CVPORT"), &nCurVp) == RTNORM);
|
||
view.setIsPaperspaceView(nCurVp == 1);
|
||
view.setCenterPoint(ptDcs.AsAcGePoint2d());
|
||
|
||
double nWidth, nHeight;
|
||
AT_ScrSize(&nWidth, &nHeight);
|
||
view.setHeight( nHeight);
|
||
view.setWidth( nWidth );
|
||
|
||
XPoint vtViewDir;
|
||
VERIFY(xg_getvar(_T("VIEWDIR"), &vtViewDir) == RTNORM);
|
||
|
||
Groups g0(0), g1(1);
|
||
|
||
ads_trans(XPoint(vtViewDir), (resbuf *)&g1, (resbuf *)&g0, 1, vtViewDir);
|
||
view.setViewDirection(vtViewDir);
|
||
|
||
double viewtwist = 0.0;
|
||
VERIFY(xg_getvar(_T("VIEWTWIST"), &viewtwist) == RTNORM);
|
||
view.setViewTwist(viewtwist);
|
||
|
||
XPoint target;
|
||
VERIFY(xg_getvar(_T("TARGET"), &target) == RTNORM);
|
||
ads_trans(XPoint(target), (resbuf *)&g1, (resbuf *)&g0, 0, target);
|
||
view.setTarget(target);
|
||
|
||
if (viewmode&0x01)
|
||
{
|
||
view.setPerspectiveEnabled(true);
|
||
if (viewmode&0x04)
|
||
{// Back Clip On
|
||
double backz = 0.0;
|
||
VERIFY(xg_getvar(_T("BACKZ"), &backz) == RTNORM);
|
||
view.setBackClipEnabled(true);
|
||
view.setBackClipDistance(backz);
|
||
}
|
||
if (viewmode&0x02)
|
||
{ // Front Clip On
|
||
view.setFrontClipEnabled(true);
|
||
if (viewmode&0x10)
|
||
{ // front clip not at eye
|
||
view.setFrontClipAtEye(false);
|
||
double frontz = 0.0;
|
||
VERIFY(xg_getvar(_T("FRONTZ"), &frontz) == RTNORM);
|
||
view.setFrontClipDistance(frontz);
|
||
}
|
||
else
|
||
{
|
||
view.setFrontClipAtEye(true);
|
||
}
|
||
}
|
||
double lenslength = 0.0;
|
||
VERIFY(xg_getvar(_T("LENSLENGTH"), &lenslength) == RTNORM);
|
||
view.setLensLength(lenslength);
|
||
}
|
||
}
|
||
|
||
// 用ARX实现ZOOM, 不调用'ZOOM命令
|
||
Acad::ErrorStatus XExport::arxZoom(const XPoint &ptLow, const XPoint &ptUp)
|
||
{
|
||
AcDbViewTableRecord view;
|
||
InitView(view);
|
||
AcGePoint2d max_2d = ptUp, min_2d = ptLow;
|
||
XPoint ptCen, vtViewDir;
|
||
Midpoint(ptLow, ptUp, ptCen);
|
||
XPoint ptDcs;
|
||
ads_trans(ptCen, Groups(0), Groups(2), 0, ptDcs);
|
||
view.setCenterPoint(ptDcs.AsAcGePoint2d());
|
||
view.setHeight( fabs(ptUp.y-ptLow.y) );
|
||
view.setWidth( fabs(ptUp.x - ptLow.x) );
|
||
|
||
Acad::ErrorStatus es = acedSetCurrentView( &view, NULL );
|
||
return es;
|
||
}
|
||
|
||
//add by zjq 100520 优化获取选择集速度
|
||
CMapPtrToPtr g_mapDbToModelRecZone;
|
||
void XExport::BeginModelRecordZone()
|
||
{
|
||
XBlockTableRecordZone* pZone = NULL;
|
||
if (g_mapDbToModelRecZone.Lookup((void*)acdbCurDwg(),(void*&)pZone))
|
||
{
|
||
}
|
||
else
|
||
{
|
||
pZone = new XBlockTableRecordZone;
|
||
g_mapDbToModelRecZone.SetAt((void*)acdbCurDwg(),pZone);
|
||
}
|
||
pZone->setActive(true);
|
||
}
|
||
|
||
void XExport::ModifyModelRecordZone(const AcDbObject* pObj)
|
||
{
|
||
AcDbEntity* pEnt = AcDbEntity::cast(pObj);
|
||
if (pEnt == NULL) return;
|
||
|
||
XBlockTableRecordZone* pZone = NULL;
|
||
if (g_mapDbToModelRecZone.Lookup((void*)acdbCurDwg(),(void*&)pZone))
|
||
{
|
||
if (pObj->objectId().isValid())
|
||
{
|
||
pZone->remove(pObj->objectId());
|
||
}
|
||
}
|
||
}
|
||
|
||
bool XExport::GetGeomExtentsInRecordZone(AcDbObjectId& id,AcDbExtents& ext)
|
||
{
|
||
XBlockTableRecordZone* pZone = NULL;
|
||
g_mapDbToModelRecZone.Lookup((void*)acdbCurDwg(),(void*&)pZone);
|
||
if (pZone != NULL)
|
||
{
|
||
return pZone->getGeomExtents(id,ext);
|
||
}
|
||
return false;
|
||
}
|
||
|
||
|
||
|
||
//选单个实体,优先从全局选择集中筛选
|
||
int XExport::SelectEntity(const TCHAR *szPrompt, Entity &entResult, RBList &rbBaseMask)
|
||
{
|
||
Entity ent;
|
||
int nRet = RTERROR;
|
||
nRet = ent.FilterSelect(szPrompt, rbBaseMask);
|
||
if (nRet == RTNORM)
|
||
{
|
||
entResult = ent;
|
||
}
|
||
return nRet;
|
||
}
|
||
|
||
// 选单个实体,优先从全局选择集中筛选, ptPick--UCS
|
||
int XExport::SelectEntity(const TCHAR *szPrompt, Entity &entResult, XPoint &ptPick, RBList &rbBaseMask)
|
||
{
|
||
Entity ent;
|
||
int nRet = RTERROR;
|
||
nRet = ent.FilterSelect(szPrompt, rbBaseMask, ptPick);
|
||
if (nRet == RTNORM)
|
||
{
|
||
entResult = ent;
|
||
}
|
||
return nRet;
|
||
}
|
||
|
||
// 选单个实体,优先从全局选择集中筛选
|
||
int XExport::SelectEntity1(const TCHAR *szPrompt, Entity &entResult, XPoint &ptPick, RBList &rbBaseMask)
|
||
{
|
||
Entity ent;
|
||
int nRet = RTERROR;
|
||
nRet = ent.FilterSelect1(GetPickBoxWcs()/2, szPrompt, rbBaseMask, ptPick);
|
||
if (nRet == RTNORM)
|
||
{
|
||
entResult = ent;
|
||
}
|
||
return nRet;
|
||
}
|
||
|
||
// 选单个实体,优先从全局选择集中筛选
|
||
int XExport::SelectEntity1(double nPrec, const TCHAR *szPrompt, Entity &entResult, XPoint &ptPick, RBList &rbBaseMask)
|
||
{
|
||
Entity ent;
|
||
int nRet = RTERROR;
|
||
nRet = ent.FilterSelect1(nPrec, szPrompt, rbBaseMask, ptPick);
|
||
if (nRet == RTNORM)
|
||
{
|
||
entResult = ent;
|
||
}
|
||
return nRet;
|
||
}
|
||
|
||
//选多个实体,优先从全局选择集中筛选
|
||
int XExport::SelectEntities(const TCHAR *szPrompt, PickSet &ssResult, RBList &rbBaseMask)
|
||
{
|
||
PickSet ssPickFirst(SS_FREE|SS_CREATE);
|
||
ssPickFirst.BaseFilter(rbBaseMask);
|
||
|
||
int nRetCode = RTNORM;
|
||
int nCount = ssPickFirst.Length();
|
||
if (!ssPickFirst || !ssPickFirst.Length())
|
||
{
|
||
const TCHAR *szPrompts[2] = { szPrompt, _T("移除物体") };
|
||
ads_sssetfirst(NULL, NULL);
|
||
nRetCode = ssResult.Get(_T(":$"), szPrompts,NULL,rbBaseMask);
|
||
}
|
||
else
|
||
{
|
||
ads_sssetfirst(NULL, NULL);
|
||
ssResult += ssPickFirst;
|
||
}
|
||
return nRetCode;
|
||
}
|
||
|
||
|
||
int XExport::SelectEntities(const TCHAR *szPrompt, PickSet &ssResult, RBList &rbBaseMask,const TCHAR* szKeyword,TCHAR& cRet)
|
||
{
|
||
int nRet;
|
||
INITGET_BEG(-2,szKeyword)
|
||
nRet = XExport::SelectEntities(szPrompt, ssResult, rbBaseMask);
|
||
INITGET_END();
|
||
if (g_cKeyword != 0)
|
||
{
|
||
cRet = g_cKeyword;
|
||
ssResult.Free();
|
||
return RTKWORD;
|
||
}
|
||
return nRet;
|
||
}
|
||
|
||
int XExport::SelectEntity(const TCHAR *szPrompt, Entity &entResult, XPoint &ptPick, RBList &rbBaseMask,const TCHAR* szKeyword,TCHAR& cRet)
|
||
{
|
||
int nRet;
|
||
INITGET_BEG(-2,szKeyword)
|
||
nRet = XExport::SelectEntity(szPrompt, entResult,ptPick, rbBaseMask);
|
||
INITGET_END();
|
||
if (g_cKeyword != 0)
|
||
{
|
||
cRet = g_cKeyword;
|
||
return RTKWORD;
|
||
}
|
||
return nRet;
|
||
}
|
||
|
||
void XExport::EndModelRecordZone()
|
||
{
|
||
XBlockTableRecordZone* pZone = NULL;
|
||
if (g_mapDbToModelRecZone.Lookup((void*)acdbCurDwg(),(void*&)pZone))
|
||
{
|
||
pZone->setActive(false);
|
||
}
|
||
}
|
||
|
||
//real cross corner select
|
||
void RealCornerSel(PickSet &ss,BOOL bCrossing,const XPoint &ptLow,const XPoint &ptUp,AcDbEntity* pEntity)
|
||
{
|
||
AcDbExtents ext;
|
||
pEntity->getGeomExtents(ext);
|
||
|
||
if ( ptLow.x - ext.minPoint().x < 1.e-10 && ptLow.y - ext.minPoint().y < 1.e-10 &&
|
||
ptUp.x - ext.maxPoint().x > -1.e-10 && ptUp.y - ext.maxPoint().y > 1.e-10 )
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pEntity->objectId()) == Acad::eOk);
|
||
ss += ent;
|
||
}
|
||
else if(bCrossing)//intersect with
|
||
{
|
||
AcDbLine line[4];
|
||
AcGePoint3d pt1,pt2;
|
||
|
||
//
|
||
// +---------------+ ptup
|
||
// | |
|
||
// | |
|
||
// | |
|
||
// +---------------+
|
||
// ptlow
|
||
double dW = ptUp.x - ptLow.x;
|
||
double dH = ptUp.y - ptLow.y;
|
||
|
||
pt1 = ptLow.AsAcGePoint3d();
|
||
pt2 = ptLow;
|
||
pt2 += AcGeVector3d::kXAxis * dW;
|
||
line[0].setStartPoint(pt1);
|
||
line[0].setEndPoint(pt2);
|
||
|
||
pt2 = ptLow;
|
||
pt2 += AcGeVector3d::kYAxis * dH;
|
||
line[1].setStartPoint(pt1);
|
||
line[1].setEndPoint(pt2);
|
||
|
||
pt1 = ptUp.AsAcGePoint3d();
|
||
pt2 = ptUp - AcGeVector3d::kXAxis * dW;
|
||
line[2].setStartPoint(pt1);
|
||
line[2].setEndPoint(pt2);
|
||
|
||
pt2 = ptUp - AcGeVector3d::kYAxis * dH;
|
||
line[3].setStartPoint(pt1);
|
||
line[3].setEndPoint(pt2);
|
||
|
||
AcGePoint3dArray pts;
|
||
for (int i = 0;i < 4;i++)
|
||
{
|
||
line[i].intersectWith(pEntity,AcDb::kOnBothOperands,pts);
|
||
|
||
if (pts.length() > 0)
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pEntity->objectId()) == Acad::eOk);
|
||
ss += ent;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void RealCornerSel(AcDbObjectIdArray &arIDs,BOOL bCrossing,const XPoint &ptLow,const XPoint &ptUp,AcDbEntity* pEntity)
|
||
{
|
||
AcDbExtents ext;
|
||
pEntity->getGeomExtents(ext);
|
||
|
||
if ( ptLow.x - ext.minPoint().x < 1.e-10 && ptLow.y - ext.minPoint().y < 1.e-10 &&
|
||
ptUp.x - ext.maxPoint().x > -1.e-10 && ptUp.y - ext.maxPoint().y > 1.e-10 )
|
||
{
|
||
arIDs.append(pEntity->objectId());
|
||
}
|
||
else if(bCrossing)//intersect with
|
||
{
|
||
AcDbLine line[4];
|
||
AcGePoint3d pt1,pt2;
|
||
|
||
//
|
||
// +---------------+ ptup
|
||
// | |
|
||
// | |
|
||
// | |
|
||
// +---------------+
|
||
// ptlow
|
||
double dW = ptUp.x - ptLow.x;
|
||
double dH = ptUp.y - ptLow.y;
|
||
|
||
pt1 = ptLow.AsAcGePoint3d();
|
||
pt2 = ptLow;
|
||
pt2 += AcGeVector3d::kXAxis * dW;
|
||
line[0].setStartPoint(pt1);
|
||
line[0].setEndPoint(pt2);
|
||
|
||
pt2 = ptLow;
|
||
pt2 += AcGeVector3d::kYAxis * dH;
|
||
line[1].setStartPoint(pt1);
|
||
line[1].setEndPoint(pt2);
|
||
|
||
pt1 = ptUp.AsAcGePoint3d();
|
||
pt2 = ptUp - AcGeVector3d::kXAxis * dW;
|
||
line[2].setStartPoint(pt1);
|
||
line[2].setEndPoint(pt2);
|
||
|
||
pt2 = ptUp - AcGeVector3d::kYAxis * dH;
|
||
line[3].setStartPoint(pt1);
|
||
line[3].setEndPoint(pt2);
|
||
|
||
AcGePoint3dArray pts;
|
||
for (int i = 0;i < 4;i++)
|
||
{
|
||
line[i].intersectWith(pEntity,AcDb::kOnBothOperands,pts);
|
||
|
||
if (pts.length() > 0)
|
||
{
|
||
arIDs.append(pEntity->objectId());
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//Acad::ErrorStatus XExport::GetViewSafeSelection(AcDbObjectIdArray &arIDs, BOOL bCrossing, const XPoint &ptLow, const XPoint &ptUp,const TCHAR* pszDxf,BOOL bRealCornerSel)
|
||
//{
|
||
// XPoint ptLow0 = ptLow;
|
||
// XPoint ptUp0 = ptUp;
|
||
//
|
||
// //1.first select ent normaly
|
||
// PickSet ss(SS_CREATE);
|
||
// GetSafeSelection(ss,bCrossing,ptLow0,ptUp0,pszDxf,bRealCornerSel);
|
||
//
|
||
// //2.sepc deal with blk ref
|
||
// ss.AsIdArray(arIDs);
|
||
//
|
||
// //3.mat- inv
|
||
// AcGeMatrix3d mat;
|
||
// AcDbEntity* pEnt = NULL;
|
||
// XPoint ptLow1,ptUp1;
|
||
//
|
||
// for (long i = 0;i < arIDs.length();i++)
|
||
// {
|
||
// if ( Acad::eOk == acdbOpenAcDbEntity(pEnt,arIDs.at(i),AcDb::kForRead))
|
||
// {
|
||
// AcDbBlockReference* pRef = AcDbBlockReference::cast(pEnt);
|
||
// if (pRef != NULL)
|
||
// {
|
||
// mat = pRef->blockTransform();
|
||
// mat.invert();
|
||
//
|
||
// ptLow1 = ptLow0;
|
||
// ptUp1 = ptUp0;
|
||
// ptLow1.TransformBy(mat);
|
||
// ptUp1.TransformBy(mat);
|
||
//
|
||
// //add by zjq on 110315重新计算包围盒
|
||
// double dX0 = __min(ptLow1.x,ptUp1.x);
|
||
// double dY0 = __min(ptLow1.y,ptUp1.y);
|
||
//
|
||
// double dX1 = __max(ptLow1.x,ptUp1.x);
|
||
// double dY1 = __max(ptLow1.y,ptUp1.y);
|
||
//
|
||
// ptLow1.x = dX0;
|
||
// ptLow1.y = dY0;
|
||
// ptUp1.x = dX1;
|
||
// ptUp1.y = dY1;
|
||
//
|
||
// //3.1 safe select inside record
|
||
// AcDbObjectIdArray arIDs2;
|
||
// XExport::GetSafeSelection(arIDs2,bCrossing,ptLow1,ptUp1,pszDxf,pRef->blockTableRecord(),bRealCornerSel);
|
||
//
|
||
// arIDs.removeAt(i);
|
||
//
|
||
// for (long j = 0;j < arIDs2.length();j++)
|
||
// {
|
||
// arIDs.append(arIDs2.at(j));
|
||
// }
|
||
//
|
||
// i--;
|
||
// }
|
||
// pEnt->close();
|
||
// }
|
||
// }
|
||
// return Acad::eOk;
|
||
//}
|
||
|
||
//Acad::ErrorStatus XExport::GetViewSafeSelection(AcDbObjectIdArray &arIDs, BOOL bCrossing, const XPoint &ptLow, const XPoint &ptUp,
|
||
// const AcRxClass* pClass,BOOL bRealCornerSel)
|
||
//{
|
||
// XPoint ptLow0 = ptLow;
|
||
// XPoint ptUp0 = ptUp;
|
||
//
|
||
// //1.first select ent normaly
|
||
// PickSet ss(SS_CREATE);
|
||
// GetSafeSelection(ss,bCrossing,ptLow0,ptUp0,pClass);
|
||
//
|
||
// //2.sepc deal with blk ref
|
||
// ss.AsIdArray(arIDs);
|
||
//
|
||
// //3.mat- inv
|
||
// AcGeMatrix3d mat;
|
||
// AcDbEntity* pEnt = NULL;
|
||
// XPoint ptLow1,ptUp1;
|
||
//
|
||
// for (long i = 0;i < arIDs.length();i++)
|
||
// {
|
||
// if ( Acad::eOk == acdbOpenAcDbEntity(pEnt,arIDs.at(i),AcDb::kForRead))
|
||
// {
|
||
// AcDbBlockReference* pRef = AcDbBlockReference::cast(pEnt);
|
||
// if (pRef != NULL)
|
||
// {
|
||
// mat = pRef->blockTransform();
|
||
// mat.invert();
|
||
//
|
||
// ptLow1 = ptLow0;
|
||
// ptUp1 = ptUp0;
|
||
//
|
||
// ptLow1.TransformBy(mat);
|
||
// ptUp1.TransformBy(mat);
|
||
//
|
||
// //add by zjq on 110315重新计算包围盒
|
||
// double dX0 = __min(ptLow1.x,ptUp1.x);
|
||
// double dY0 = __min(ptLow1.y,ptUp1.y);
|
||
//
|
||
// double dX1 = __max(ptLow1.x,ptUp1.x);
|
||
// double dY1 = __max(ptLow1.y,ptUp1.y);
|
||
//
|
||
// ptLow1.x = dX0;
|
||
// ptLow1.y = dY0;
|
||
// ptUp1.x = dX1;
|
||
// ptUp1.y = dY1;
|
||
//
|
||
// //3.1 safe select inside record
|
||
// AcDbObjectIdArray arIDs2;
|
||
// XExport::GetSafeSelection(arIDs2,bCrossing,ptLow1,ptUp1,pClass,pRef->blockTableRecord(),bRealCornerSel);
|
||
//
|
||
// arIDs.removeAt(i);
|
||
//
|
||
// for (long j = 0;j < arIDs2.length();j++)
|
||
// {
|
||
// arIDs.append(arIDs2.at(j));
|
||
// }
|
||
//
|
||
// i--;
|
||
// }
|
||
// pEnt->close();
|
||
// }
|
||
// }
|
||
// return Acad::eOk;
|
||
//}
|
||
|
||
//Acad::ErrorStatus XExport::GetSafeSelection(AcDbObjectIdArray &arIDs, BOOL bCrossing, const XPoint &ptLow,
|
||
// const XPoint &ptUp, const TCHAR *pDxfWizard,
|
||
// AcDbObjectId idBlock,BOOL bRealCornerSel)
|
||
//{
|
||
// XBlockTableRecordZone* pZone = NULL;
|
||
// Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
// XBlockTableRecPtr objMSpace(idBlock);
|
||
// if (!objMSpace)
|
||
// {
|
||
// return esRet;
|
||
// }
|
||
//
|
||
// CString sDxfWiz;
|
||
// if (pDxfWizard)
|
||
// {
|
||
// sDxfWiz = pDxfWizard;
|
||
// }
|
||
//
|
||
// XPoint ptMid;
|
||
// Midpoint(ptLow, ptUp, ptMid);
|
||
// XRectAngle rect(ptLow, ptUp);
|
||
//
|
||
// AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
// Acad::ErrorStatus es = objMSpace.m_pBlockTableRec->newIterator(pBlockIterator);
|
||
// ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
//
|
||
// for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
// {
|
||
// AcDbEntity *pEntity = NULL;
|
||
// es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
// if (es != Acad::eOk)
|
||
// {
|
||
// continue;
|
||
// }
|
||
// ASSERT(pEntity);
|
||
//
|
||
// XDbObject vTemp(pEntity);
|
||
// if (pEntity->visibility() == AcDb::kInvisible)
|
||
// {
|
||
// continue;
|
||
// }
|
||
//
|
||
// AcRxClass *pRxInfo = pEntity->isA();
|
||
// CString str=pRxInfo->dxfName();
|
||
// if (!pDxfWizard || /*ads_wcmatch(pRxInfo->dxfName(), sDxfWiz) == RTNORM*/ sDxfWiz.Find(pRxInfo->dxfName(),0) != -1)
|
||
// {
|
||
// if (!bCrossing && pEntity->isKindOf(AcDbCurve::desc()))
|
||
// {
|
||
// AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
// XPoint ptCurve;
|
||
// if (pCurve->getClosestPointTo(ptMid, ptCurve) == Acad::eOk &&
|
||
// ptCurve.x>rect.lowLeft.x && ptCurve.x<rect.upRight.x &&
|
||
// ptCurve.y>rect.lowLeft.y && ptCurve.y<rect.upRight.y)
|
||
// {
|
||
// /*Entity ent;
|
||
// VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
// ss += ent;*/
|
||
// bRealCornerSel ? RealCornerSel(arIDs,bCrossing,ptLow,ptUp,pEntity) : arIDs.append(pCurve->objectId());
|
||
// esRet = Acad::eOk;
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// bool bHasExt = false;
|
||
// AcDbExtents ext;
|
||
//
|
||
// //modify by zjq
|
||
// if (pZone != NULL)
|
||
// {
|
||
// if (pZone->getGeomExtents(pEntity->objectId(),ext))
|
||
// {
|
||
// bHasExt = true;
|
||
// }
|
||
// }
|
||
//
|
||
// if (bHasExt)
|
||
// {
|
||
// XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
// ptExtMin.z = ptExtMax.z = 0;
|
||
// if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
// {
|
||
// }
|
||
// else
|
||
// {
|
||
// /*Entity ent;
|
||
// acdbGetAdsName(ent.name, pEntity->objectId());
|
||
// ss += ent;*/
|
||
// bRealCornerSel ? RealCornerSel(arIDs,bCrossing,ptLow,ptUp,pEntity) : arIDs.append(pEntity->objectId());
|
||
//
|
||
// esRet = Acad::eOk;
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// if ( pEntity->getGeomExtents(ext) == Acad::eOk)
|
||
// {
|
||
// if (pZone != NULL) pZone->setGeomExtents(pEntity->objectId(),ext);
|
||
//
|
||
// XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
// ptExtMin.z = ptExtMax.z = 0;
|
||
// if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
// {
|
||
// }
|
||
// else
|
||
// {
|
||
// /*Entity ent;
|
||
// acdbGetAdsName(ent.name, pEntity->objectId());
|
||
// ss += ent;*/
|
||
// bRealCornerSel ? RealCornerSel(arIDs,bCrossing,ptLow,ptUp,pEntity) : arIDs.append(pEntity->objectId());
|
||
// esRet = Acad::eOk;
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// delete pBlockIterator;
|
||
// return esRet;
|
||
//}
|
||
|
||
//Acad::ErrorStatus XExport::GetSafeSelection(AcDbObjectIdArray &arIDs, BOOL bCrossing, const XPoint &ptLow,
|
||
// const XPoint &ptUp, const AcRxClass *pClass,AcDbObjectId idBlock,
|
||
// BOOL bRealCornerSel)
|
||
//{
|
||
// XBlockTableRecordZone* pZone = NULL;
|
||
// Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
// XBlockTableRecPtr objMSpace(idBlock);
|
||
// if (!objMSpace)
|
||
// {
|
||
// return esRet;
|
||
// }
|
||
//
|
||
// XPoint ptMid;
|
||
// Midpoint(ptLow, ptUp, ptMid);
|
||
// XRectAngle rect(ptLow, ptUp);
|
||
//
|
||
// AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
// Acad::ErrorStatus es = objMSpace.m_pBlockTableRec->newIterator(pBlockIterator);
|
||
// ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
//
|
||
// for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
// {
|
||
// AcDbEntity *pEntity = NULL;
|
||
// es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
// if (es != Acad::eOk)
|
||
// {
|
||
// continue;
|
||
// }
|
||
// ASSERT(pEntity);
|
||
//
|
||
// XDbObject vTemp(pEntity);
|
||
// if (pEntity->visibility() == AcDb::kInvisible)
|
||
// {
|
||
// continue;
|
||
// }
|
||
// AcRxClass *pRxInfo = pEntity->isA();
|
||
//
|
||
// if (!pClass || pRxInfo == pClass)
|
||
// {
|
||
// if (!bCrossing && pEntity->isKindOf(AcDbCurve::desc()))
|
||
// {
|
||
// AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
// XPoint ptCurve;
|
||
// if (pCurve->getClosestPointTo(ptMid, ptCurve) == Acad::eOk &&
|
||
// ptCurve.x>rect.lowLeft.x && ptCurve.x<rect.upRight.x &&
|
||
// ptCurve.y>rect.lowLeft.y && ptCurve.y<rect.upRight.y)
|
||
// {
|
||
// /*Entity ent;
|
||
// VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
// ss += ent;*/
|
||
// bRealCornerSel ? RealCornerSel(arIDs,bCrossing,ptLow,ptUp,pEntity) : arIDs.append(pEntity->objectId());
|
||
// esRet = Acad::eOk;
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// bool bHasExt = false;
|
||
// AcDbExtents ext;
|
||
//
|
||
// //modify by zjq
|
||
// if (pZone != NULL)
|
||
// {
|
||
// if (pZone->getGeomExtents(pEntity->objectId(),ext))
|
||
// {
|
||
// bHasExt = true;
|
||
// }
|
||
// }
|
||
//
|
||
// if (bHasExt)
|
||
// {
|
||
// XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
// ptExtMin.z = ptExtMax.z = 0;
|
||
// if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
// {
|
||
// }
|
||
// else
|
||
// {
|
||
// /*Entity ent;
|
||
// acdbGetAdsName(ent.name, pEntity->objectId());
|
||
// ss += ent;*/
|
||
// bRealCornerSel ? RealCornerSel(arIDs,bCrossing,ptLow,ptUp,pEntity) : arIDs.append(pEntity->objectId());
|
||
// esRet = Acad::eOk;
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// if ( pEntity->getGeomExtents(ext) == Acad::eOk)
|
||
// {
|
||
// if (pZone != NULL) pZone->setGeomExtents(pEntity->objectId(),ext);
|
||
//
|
||
// XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
// ptExtMin.z = ptExtMax.z = 0;
|
||
// if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
// {
|
||
// }
|
||
// else
|
||
// {
|
||
// /*Entity ent;
|
||
// acdbGetAdsName(ent.name, pEntity->objectId());
|
||
// ss += ent;*/
|
||
// bRealCornerSel ? RealCornerSel(arIDs,bCrossing,ptLow,ptUp,pEntity) : arIDs.append(pEntity->objectId());
|
||
// esRet = Acad::eOk;
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// delete pBlockIterator;
|
||
// return esRet;
|
||
//}
|
||
|
||
|
||
//安全模式开窗口搜索选择集
|
||
//目前只验证过"C"方式
|
||
//bCrossing : FALSE-对曲线加速
|
||
Acad::ErrorStatus XExport::GetSafeSelection(PickSet &ss, BOOL bCrossing, const XPoint &ptLow,
|
||
const XPoint &ptUp, const AcRxClass *pClass,BOOL bRealCornerSel)
|
||
{
|
||
XBlockTableRecordZone* pZone = NULL;
|
||
g_mapDbToModelRecZone.Lookup((void*)acdbCurDwg(),(void*&)pZone);
|
||
if (pZone != NULL && !pZone->isActive())
|
||
{
|
||
pZone = NULL;
|
||
}
|
||
|
||
Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
XBlockTableRecPtr objMSpace;
|
||
if (!objMSpace)
|
||
{
|
||
return esRet;
|
||
}
|
||
|
||
XPoint ptMid;
|
||
Midpoint(ptLow, ptUp, ptMid);
|
||
XRectAngle rect(ptLow, ptUp);
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
Acad::ErrorStatus es = objMSpace.m_pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
ASSERT(pEntity);
|
||
|
||
//pEntity没有close? zjq
|
||
|
||
XDbObject vTemp(pEntity);
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
|
||
if (!pClass || pRxInfo == pClass)
|
||
{
|
||
if (!bCrossing && pEntity->isKindOf(AcDbCurve::desc()))
|
||
{ //用于加速目的,光标移动时自动捕捉时使用
|
||
AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
XPoint ptCurve;
|
||
if (pCurve->getClosestPointTo(ptMid, ptCurve) == Acad::eOk &&
|
||
ptCurve.x>rect.lowLeft.x && ptCurve.x<rect.upRight.x &&
|
||
ptCurve.y>rect.lowLeft.y && ptCurve.y<rect.upRight.y)
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
|
||
if (bRealCornerSel)
|
||
RealCornerSel(ss, bCrossing, ptLow, ptUp, pEntity);
|
||
else
|
||
ss += ent;
|
||
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
bool bHasExt = false;
|
||
AcDbExtents ext;
|
||
|
||
//modify by zjq on 100520 优化求包围盒算法
|
||
if ( pZone != NULL )
|
||
{
|
||
if (pZone->getGeomExtents(pEntity->objectId(),ext))
|
||
{
|
||
bHasExt = true;
|
||
}
|
||
}
|
||
|
||
if (bHasExt)
|
||
{
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
|
||
if (bRealCornerSel)
|
||
RealCornerSel(ss, bCrossing, ptLow, ptUp, pEntity);
|
||
else
|
||
ss += ent;
|
||
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (pEntity->getGeomExtents(ext) == Acad::eOk)
|
||
{
|
||
if (pZone != NULL) pZone->setGeomExtents(pEntity->objectId(),ext);
|
||
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
|
||
if (bRealCornerSel)
|
||
RealCornerSel(ss, bCrossing, ptLow, ptUp, pEntity);
|
||
else
|
||
ss += ent;
|
||
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
delete pBlockIterator;
|
||
return esRet;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::GetSafeSelection(PickSet &ss, BOOL bCrossing, const XPoint &ptLow,
|
||
const XPoint &ptUp, const AcRxClass *pClass,AcDbObjectId idBlock)
|
||
{
|
||
XBlockTableRecordZone* pZone = NULL;
|
||
g_mapDbToModelRecZone.Lookup((void*)acdbCurDwg(),(void*&)pZone);
|
||
if (pZone != NULL && !pZone->isActive())
|
||
{
|
||
pZone = NULL;
|
||
}
|
||
|
||
Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
XBlockTableRecPtr objMSpace(idBlock);
|
||
if (!objMSpace)
|
||
{
|
||
return esRet;
|
||
}
|
||
|
||
XPoint ptMid;
|
||
Midpoint(ptLow, ptUp, ptMid);
|
||
XRectAngle rect(ptLow, ptUp);
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
Acad::ErrorStatus es = objMSpace.m_pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
ASSERT(pEntity);
|
||
//pEntity没有close? zjq
|
||
|
||
XDbObject vTemp(pEntity);
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
|
||
if (!pClass || pRxInfo == pClass)
|
||
{
|
||
if (!bCrossing && pEntity->isKindOf(AcDbCurve::desc()))
|
||
{ //用于加速目的,光标移动时自动捕捉时使用
|
||
AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
XPoint ptCurve;
|
||
if (pCurve->getClosestPointTo(ptMid, ptCurve) == Acad::eOk &&
|
||
ptCurve.x>rect.lowLeft.x && ptCurve.x<rect.upRight.x &&
|
||
ptCurve.y>rect.lowLeft.y && ptCurve.y<rect.upRight.y)
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
bool bHasExt = false;
|
||
AcDbExtents ext;
|
||
|
||
//modify by zjq on 100520 优化求包围盒算法
|
||
if (pZone != NULL)
|
||
{
|
||
if (pZone->getGeomExtents(pEntity->objectId(),ext))
|
||
{
|
||
bHasExt = true;
|
||
}
|
||
}
|
||
|
||
if (bHasExt)
|
||
{
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if ( pEntity->getGeomExtents(ext) == Acad::eOk)
|
||
{
|
||
if (pZone != NULL) pZone->setGeomExtents(pEntity->objectId(),ext);
|
||
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
delete pBlockIterator;
|
||
return esRet;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::GetSafeSelectionEx(PickSet &ss, BOOL bCrossing, const XPoint &ptLow,
|
||
const XPoint &ptUp, const AcRxClass *pClass)
|
||
{
|
||
XBlockTableRecordZone* pZone = NULL;
|
||
g_mapDbToModelRecZone.Lookup((void*)acdbCurDwg(),(void*&)pZone);
|
||
if (pZone != NULL && !pZone->isActive())
|
||
{
|
||
pZone = NULL;
|
||
}
|
||
|
||
Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
XBlockTableRecPtr objMSpace;
|
||
if (!objMSpace)
|
||
{
|
||
return esRet;
|
||
}
|
||
|
||
XPoint ptMid;
|
||
Midpoint(ptLow, ptUp, ptMid);
|
||
XRectAngle rect(ptLow, ptUp);
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
Acad::ErrorStatus es = objMSpace.m_pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk) continue;
|
||
ASSERT(pEntity);
|
||
|
||
XDbObject vTemp(pEntity);
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
if (!pClass || pEntity->isKindOf(pClass))
|
||
{
|
||
if (!bCrossing && pEntity->isKindOf(AcDbCurve::desc()))
|
||
{ //用于加速目的,光标移动时自动捕捉时使用
|
||
AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
XPoint ptCurve;
|
||
if (pCurve->getClosestPointTo(ptMid, ptCurve) == Acad::eOk &&
|
||
ptCurve.x>rect.lowLeft.x && ptCurve.x<rect.upRight.x &&
|
||
ptCurve.y>rect.lowLeft.y && ptCurve.y<rect.upRight.y)
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
bool bHasExt = false;
|
||
AcDbExtents ext;
|
||
|
||
//modify by zjq on 100520 优化求包围盒算法
|
||
if (pZone != NULL)
|
||
{
|
||
if (pZone->getGeomExtents(pEntity->objectId(),ext) )
|
||
{
|
||
bHasExt = true;
|
||
}
|
||
}
|
||
|
||
if (bHasExt)
|
||
{
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (pEntity->getGeomExtents(ext) == Acad::eOk)
|
||
{
|
||
if (pZone != NULL) pZone->setGeomExtents(pEntity->objectId(),ext);
|
||
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
delete pBlockIterator;
|
||
return esRet;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::GetSafeSelectionEx(PickSet &ss, BOOL bCrossing, const XPoint &ptLow,
|
||
const XPoint &ptUp, const AcRxClass *pClass,AcDbObjectId idBlock)
|
||
{
|
||
XBlockTableRecordZone* pZone = NULL;
|
||
g_mapDbToModelRecZone.Lookup((void*)acdbCurDwg(),(void*&)pZone);
|
||
if (pZone != NULL && !pZone->isActive())
|
||
{
|
||
pZone = NULL;
|
||
}
|
||
|
||
Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
XBlockTableRecPtr objMSpace(idBlock);
|
||
if (!objMSpace)
|
||
return esRet;
|
||
|
||
XPoint ptMid;
|
||
Midpoint(ptLow, ptUp, ptMid);
|
||
XRectAngle rect(ptLow, ptUp);
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
Acad::ErrorStatus es = objMSpace.m_pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk) continue;
|
||
ASSERT(pEntity);
|
||
|
||
XDbObject vTemp(pEntity);
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
if (!pClass || pEntity->isKindOf(pClass))
|
||
{
|
||
if (!bCrossing && pEntity->isKindOf(AcDbCurve::desc()))
|
||
{ //用于加速目的,光标移动时自动捕捉时使用
|
||
AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
XPoint ptCurve;
|
||
if (pCurve->getClosestPointTo(ptMid, ptCurve) == Acad::eOk &&
|
||
ptCurve.x>rect.lowLeft.x && ptCurve.x<rect.upRight.x &&
|
||
ptCurve.y>rect.lowLeft.y && ptCurve.y<rect.upRight.y)
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
bool bHasExt = false;
|
||
AcDbExtents ext;
|
||
|
||
//modify by zjq on 100520 优化求包围盒算法
|
||
if (pZone != NULL)
|
||
{
|
||
if (pZone->getGeomExtents(pEntity->objectId(),ext))
|
||
{
|
||
bHasExt = true;
|
||
}
|
||
}
|
||
|
||
if (bHasExt)
|
||
{
|
||
//加速2003/9/12
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (pEntity->getGeomExtents(ext) == Acad::eOk)
|
||
{
|
||
if (pZone != NULL) pZone->setGeomExtents(pEntity->objectId(),ext);
|
||
|
||
//加速2003/9/12
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
delete pBlockIterator;
|
||
return esRet;
|
||
}
|
||
|
||
// 确保点在屏幕之内
|
||
Acad::ErrorStatus XExport::AssureInCurrentView(const XPoint &ptLow, const XPoint &ptUp)
|
||
{
|
||
XPoint lowCorner, upCorner;
|
||
AT_ScrCorner(lowCorner, upCorner);
|
||
XPoint pt1 = ptLow, pt2 = ptUp;
|
||
pt1.z = pt2.z = lowCorner.z;
|
||
XPoint ptMin = Min(pt1, lowCorner), ptMax = Max(pt2, upCorner);
|
||
Acad::ErrorStatus es = Acad::eNotApplicable;
|
||
|
||
if (ptMin != lowCorner || ptMax != upCorner)
|
||
{ //点不在屏幕当前视图之内
|
||
if (fabs(ptUp.x-ptLow.x) < fabs(upCorner.x-lowCorner.x) &&
|
||
fabs(ptUp.y-ptLow.y) < fabs(upCorner.y-lowCorner.y))
|
||
{
|
||
//目标矩形的尺寸小于当前视图的尺寸, 用PAN的方式
|
||
XPoint ptFrom, ptTo;
|
||
Midpoint(lowCorner, upCorner, ptFrom);
|
||
Midpoint(ptLow, ptUp, ptTo);
|
||
XPoint vtPan = ptTo-ptFrom;
|
||
es = arxPan(vtPan);
|
||
}
|
||
else
|
||
{
|
||
XPoint ptCen;
|
||
Midpoint(ptLow, ptUp, ptCen);
|
||
es = arxZoomTo(ptCen, ptUp.x-ptLow.x, ptUp.y-ptLow.y);
|
||
}
|
||
}
|
||
return es;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::GetSafeSelection(PickSet &ss, const XPoint &ptLow, const XPoint &ptUp,
|
||
std::list<AcRxClass*> &lstClass, AcDbObjectId idLayer)
|
||
{
|
||
XBlockTableRecordZone* pZone = NULL;
|
||
g_mapDbToModelRecZone.Lookup((void*)acdbCurDwg(),(void*&)pZone);
|
||
if (pZone != NULL && !pZone->isActive())
|
||
{
|
||
pZone = NULL;
|
||
}
|
||
|
||
Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
XBlockTableRecPtr objMSpace;
|
||
if (!objMSpace)
|
||
{
|
||
return esRet;
|
||
}
|
||
|
||
XPoint ptMid;
|
||
Midpoint(ptLow, ptUp, ptMid);
|
||
XRectAngle rect(ptLow, ptUp);
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
Acad::ErrorStatus es = objMSpace.m_pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk) continue;
|
||
ASSERT(pEntity);
|
||
|
||
XDbObject vTemp(pEntity);
|
||
//不处理不可见的实体zjq
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
if (!!idLayer)
|
||
{
|
||
AcDbObjectId idLay = pEntity->layerId();
|
||
if (idLayer != idLay)
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
|
||
//if (lstClass.FindNode(pRxInfo, CompareAcRxClass))
|
||
if (std::find(lstClass.begin(),lstClass.end(),pRxInfo) != lstClass.end() )
|
||
{
|
||
if (pEntity->isKindOf(AcDbCurve::desc()))
|
||
{ //用于加速目的,光标移动时自动捕捉时使用
|
||
AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
XPoint ptCurve;
|
||
if (pCurve->getClosestPointTo(ptMid, ptCurve) == Acad::eOk &&
|
||
ptCurve.x>rect.lowLeft.x && ptCurve.x<rect.upRight.x &&
|
||
ptCurve.y>rect.lowLeft.y && ptCurve.y<rect.upRight.y)
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
bool bHasExt = false;
|
||
AcDbExtents ext;
|
||
|
||
//modify by zjq on 100520 优化求包围盒算法
|
||
if (pZone != NULL)
|
||
{
|
||
if (pZone->getGeomExtents(pEntity->objectId(),ext))
|
||
{
|
||
bHasExt = true;
|
||
}
|
||
}
|
||
|
||
if (bHasExt)
|
||
{
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (pEntity->getGeomExtents(ext) == Acad::eOk)
|
||
{
|
||
if (pZone != NULL) pZone->setGeomExtents(pEntity->objectId(),ext);
|
||
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
delete pBlockIterator;
|
||
return esRet;
|
||
}
|
||
|
||
BOOL XExport::MakeDir(const TCHAR *pDir)
|
||
{
|
||
XString sDir(pDir);
|
||
TCHAR *p = sDir;
|
||
while(p = _tcschr(p, _T('\\')))
|
||
{
|
||
*p = 0;
|
||
if (_tmkdir(sDir) != 0)
|
||
{
|
||
if (errno == ENOENT)
|
||
{
|
||
return FALSE;
|
||
}
|
||
}
|
||
*p = _T('\\');
|
||
p++;
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::GetEntFromBlockByClass(DList<AcDbObjectId> &lstObjects, AcRxClass *pClass,
|
||
int nCmpMethod, AcDbObjectId idBlock,LPVOID pReserve)
|
||
{
|
||
XBlockTableRecPtr objMSpace(idBlock);
|
||
if (!objMSpace)
|
||
{
|
||
return Acad::eNotApplicable;
|
||
}
|
||
|
||
bool bLookUpExt = false;
|
||
AcDbExtents ext,ext2;
|
||
if (pReserve != NULL)
|
||
{
|
||
typedef CMap<LONG_PTR,LONG_PTR,AcDbExtents,AcDbExtents> CMapLongToExtents;
|
||
CMapLongToExtents* pMap = (CMapLongToExtents*)pReserve;
|
||
if (pMap->Lookup(idBlock.asOldId(),ext))
|
||
{
|
||
bLookUpExt = true;
|
||
}
|
||
}
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
Acad::ErrorStatus es = objMSpace.m_pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
ASSERT(pEntity);
|
||
|
||
XDbObject vTemp(pEntity);
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
if (nCmpMethod == 0)
|
||
{
|
||
if (pRxInfo == pClass)
|
||
{
|
||
if (bLookUpExt)
|
||
{
|
||
if (pEntity->getGeomExtents(ext2) == Acad::eOk)
|
||
{
|
||
XPoint ptExtMin = ext2.minPoint(), ptExtMax = ext2.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ext.maxPoint().x<ptExtMin.x || ext.maxPoint().y<ptExtMin.y ||
|
||
ext.minPoint().x>ptExtMax.x || ext.minPoint().y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (pEntity->isKindOf(pClass))
|
||
{
|
||
if (bLookUpExt)
|
||
{
|
||
if (pEntity->getGeomExtents(ext2) == Acad::eOk)
|
||
{
|
||
XPoint ptExtMin = ext2.minPoint(), ptExtMax = ext2.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ext.maxPoint().x<ptExtMin.x || ext.maxPoint().y<ptExtMin.y ||
|
||
ext.minPoint().x>ptExtMax.x || ext.minPoint().y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
delete pBlockIterator;
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::GetEntFromBlockByClass(DList<AcDbObjectId> &lstObjects, AcRxClass *pClass,
|
||
int nCmpMethod, const TCHAR *pszBlk,LPVOID pReserve)
|
||
{
|
||
XBlockTableRecPtr objMSpace(pszBlk);
|
||
if (!objMSpace)
|
||
{
|
||
return Acad::eNotApplicable;
|
||
}
|
||
|
||
bool bLookUpExt = false;
|
||
AcDbExtents ext,ext2;
|
||
if (pReserve != NULL)
|
||
{
|
||
typedef CMap<LONG_PTR,LONG_PTR,AcDbExtents,AcDbExtents> CMapLongToExtents;
|
||
CMapLongToExtents* pMap = (CMapLongToExtents*)pReserve;
|
||
if (pMap->Lookup(objMSpace.m_pBlockTableRec->objectId().asOldId(),ext))
|
||
{
|
||
bLookUpExt = true;
|
||
}
|
||
}
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
Acad::ErrorStatus es = objMSpace.m_pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
ASSERT(pEntity);
|
||
|
||
XDbObject vTemp(pEntity);
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
if (nCmpMethod == 0)
|
||
{
|
||
if (pRxInfo == pClass)
|
||
{
|
||
if (bLookUpExt)
|
||
{
|
||
if (pEntity->getGeomExtents(ext2) == Acad::eOk)
|
||
{
|
||
XPoint ptExtMin = ext2.minPoint(), ptExtMax = ext2.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ext.maxPoint().x<ptExtMin.x || ext.maxPoint().y<ptExtMin.y ||
|
||
ext.minPoint().x>ptExtMax.x || ext.minPoint().y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (pEntity->isKindOf(pClass))
|
||
{
|
||
if (bLookUpExt)
|
||
{
|
||
if (pEntity->getGeomExtents(ext2) == Acad::eOk)
|
||
{
|
||
XPoint ptExtMin = ext2.minPoint(), ptExtMax = ext2.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ext.maxPoint().x<ptExtMin.x || ext.maxPoint().y<ptExtMin.y ||
|
||
ext.minPoint().x>ptExtMax.x || ext.minPoint().y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
delete pBlockIterator;
|
||
return Acad::eOk;
|
||
}
|
||
|
||
|
||
CView *XExport::GetCurDwgView()
|
||
{
|
||
if (g_nAcadVer>15.0001)
|
||
{
|
||
return acedGetAcadDwgView();
|
||
}
|
||
|
||
CDocument *pDoc = curDoc()->cDoc();
|
||
if (!pDoc)
|
||
{
|
||
return NULL;
|
||
}
|
||
POSITION pos = pDoc->GetFirstViewPosition();
|
||
if (!pos)
|
||
{
|
||
return NULL;
|
||
}
|
||
CView *pView = pDoc->GetNextView(pos);
|
||
return pView;
|
||
}
|
||
|
||
// 判断是否是DwgView窗口
|
||
// 在OpenGL加速窗口下,窗口类名称是CTempWnd
|
||
BOOL XExport::IsAcadDwgView(HWND hwnd)
|
||
{
|
||
if (acedGetAcadDwgView() == NULL)
|
||
return FALSE;
|
||
|
||
if ( acedGetAcadDwgView()->m_hWnd == hwnd)
|
||
{
|
||
return TRUE;
|
||
}
|
||
CWnd *pFromWnd = CWnd::FromHandle(hwnd);
|
||
CRuntimeClass *pClassInfo = pFromWnd->GetRuntimeClass();
|
||
|
||
ASSERT(pFromWnd && pClassInfo);
|
||
|
||
const char *pClassName = pClassInfo->m_lpszClassName;
|
||
BOOL bTrue = FALSE;
|
||
TCHAR szClassName[256] = _T("");
|
||
if (pClassName)
|
||
{
|
||
if(strcmp(pClassName, "CDwgView") == 0)
|
||
{
|
||
bTrue = TRUE;
|
||
}
|
||
#if (ARX>15)
|
||
else if(GetClassName(hwnd, szClassName, 255))
|
||
{
|
||
if(_tcscmp(szClassName, _T("GsTransparentWindow")) == 0)
|
||
{ //OpenGL透视图
|
||
return TRUE;
|
||
}
|
||
#else
|
||
else if(_tcscmp(pClassName, _T("CTempWnd")) == 0)
|
||
{
|
||
CWnd *pParent = pFromWnd->GetParent();
|
||
if(pParent)
|
||
{
|
||
CRuntimeClass *pClass = pParent->GetRuntimeClass();
|
||
if(pClass && pClass->m_lpszClassName && _tcsicmp(pClass->m_lpszClassName, _T("CTempWnd")) == 0)
|
||
{
|
||
bTrue = TRUE;
|
||
}
|
||
}
|
||
#endif
|
||
}
|
||
}
|
||
|
||
return bTrue;
|
||
}
|
||
|
||
BOOL XExport::IsCurDwgView(HWND hwnd)
|
||
{
|
||
CView *pView = GetCurDwgView();
|
||
if (!pView)
|
||
{
|
||
return FALSE;
|
||
}
|
||
if (hwnd == pView->m_hWnd)
|
||
{
|
||
return TRUE;
|
||
}
|
||
TCHAR szClassName[256] = _T("");
|
||
if (GetClassName(hwnd, szClassName, 255))
|
||
{ //OpenGL透视图
|
||
if (_tcscmp(szClassName, _T("GsTransparentWindow")) == 0)
|
||
{
|
||
return TRUE;
|
||
}
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
void XExport::PostCommand(const TCHAR *pszCmd, bool bEcho)
|
||
{
|
||
acDocManager->sendStringToExecute(curDoc(), pszCmd, true, false, bEcho);
|
||
}
|
||
|
||
XString XExport::GetSymbolName(AcDbObjectId idSymbolRec)
|
||
{
|
||
XString sName;
|
||
OPENOBJ_BEGIN(idSymbolRec, AcDb::kForRead, AcDbSymbolTableRecord, pStyleRec);
|
||
if (pStyleRec)
|
||
{
|
||
const TCHAR *pszName = NULL;
|
||
pStyleRec->getName(pszName);
|
||
if (pszName)
|
||
{
|
||
sName = pszName;
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
return sName;
|
||
}
|
||
|
||
XString XExport::GetTempSymbolName(const TCHAR *symb)
|
||
{
|
||
XString sName;
|
||
int i = 0;
|
||
do
|
||
{
|
||
sName[0] = EOS;
|
||
sName << _T("TMP");
|
||
sName<<i;
|
||
i++;
|
||
} while(!!XSymbolTable(symb, sName));
|
||
|
||
return sName;
|
||
}
|
||
|
||
XString XExport::GetTempSymbolName(const TCHAR *symb, const TCHAR *prefix)
|
||
{
|
||
XString sName;
|
||
int i = 0;
|
||
do
|
||
{
|
||
sName[0] = EOS;
|
||
sName << prefix;
|
||
sName<<i;
|
||
i++;
|
||
} while(!!XSymbolTable(symb, sName));
|
||
|
||
return sName;
|
||
}
|
||
|
||
XString XExport::GetTempFileName(const TCHAR *pExt)
|
||
{
|
||
ASSERT(pExt);
|
||
XString sPath(256), sFullPath(256);
|
||
GetTempPath(255, sPath);
|
||
int i = 1;
|
||
do
|
||
{
|
||
sFullPath[0] = EOS;
|
||
sFullPath << sPath << _T("tmp") << i << pExt;
|
||
i++;
|
||
} while(FindFile(sFullPath));
|
||
|
||
return sFullPath;
|
||
}
|
||
|
||
BOOL XExport::GetWcsCursor(XPoint &ptLoc)
|
||
{
|
||
CPoint ptCursor;
|
||
if (GetCursorPos(&ptCursor))
|
||
{
|
||
acedGetAcadDwgView()->ScreenToClient(&ptCursor);
|
||
int nCurVp = 0;
|
||
VERIFY(xg_getvar(_T("CVPORT"), &nCurVp) == RTNORM);
|
||
BOOL bRetCode = acedCoordFromPixelToWorld(nCurVp, ptCursor, ptLoc);
|
||
return bRetCode;
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
int XExport::ExpInsertDwg(const TCHAR *pszDwg, XPoint ptInsert)
|
||
{
|
||
AcDbDatabase db(false, true);
|
||
#if ARX >= 21
|
||
if (db.readDwgFile(pszDwg, AcDbDatabase::kForReadAndAllShare) != Acad::eOk)
|
||
#else
|
||
if (db.readDwgFile(pszDwg, _SH_DENYNO) != Acad::eOk)
|
||
#endif
|
||
{
|
||
return RTERROR;
|
||
}
|
||
XPoint ptOrg = db.insbase();
|
||
ads_matrix mat;
|
||
ptOrg.GetMoveMatrix(ptInsert, mat);
|
||
|
||
if (acdbCurDwg()->insert(AsAcGeMatrix3d(mat), &db, Adesk::kFalse) != Acad::eOk)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
return RTNORM;
|
||
}
|
||
|
||
int XExport::ExpInsertDwg0(const TCHAR* pszDwg,XPoint ptBase,XPoint ptMin,XPoint ptMax,XPoint ptInsert)
|
||
{
|
||
AcDbDatabase db(false, true);
|
||
#if ARX >= 21
|
||
if (db.readDwgFile(pszDwg, AcDbDatabase::kForReadAndAllShare) != Acad::eOk)
|
||
#else
|
||
if (db.readDwgFile(pszDwg, _SH_DENYNO) != Acad::eOk)
|
||
#endif
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
DList<AcDbObjectId> idList;
|
||
GetEntityFromDatabase(idList,db,ACDB_MODEL_SPACE,ptMin,ptMax);
|
||
if (idList.Length() <= 0)
|
||
{
|
||
return RTNORM;
|
||
}
|
||
|
||
AcDbObjectIdArray idArray;
|
||
idArray.setLogicalLength(idList.Length());
|
||
for (long i = 0; i < idList.Length();i++)
|
||
{
|
||
idArray[i] = *idList[i];
|
||
}
|
||
|
||
AcDbDatabase* pDbTemp = NULL;
|
||
Acad::ErrorStatus es = db.wblock(pDbTemp,idArray,ptBase);//有的图第二次失败!
|
||
if (es != Acad::eOk || pDbTemp == NULL)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
ads_matrix mat;
|
||
ptBase.GetMoveMatrix(ptInsert, mat);
|
||
|
||
if (acdbCurDwg()->insert(AsAcGeMatrix3d(mat), pDbTemp, Adesk::kFalse) != Acad::eOk)
|
||
{
|
||
delete pDbTemp;
|
||
return RTERROR;
|
||
}
|
||
delete pDbTemp;
|
||
return RTNORM;
|
||
}
|
||
|
||
//删除模型空间包围盒外的内容
|
||
Acad::ErrorStatus XExport::EraseEntityFromDatabase(AcDbDatabase &db,XPoint ptMin,XPoint ptMax)
|
||
{
|
||
AcDbBlockTable *pBlockTable = NULL;
|
||
Acad::ErrorStatus es = db.getBlockTable(pBlockTable, AcDb::kForRead);
|
||
if (!pBlockTable)
|
||
{
|
||
return es;
|
||
}
|
||
ASSERT(es == Acad::eOk);
|
||
|
||
AcDbBlockTableRecord *pBlockTableRec = NULL;
|
||
es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRec, AcDb::kForRead);
|
||
pBlockTable->close();
|
||
|
||
if (!pBlockTableRec)
|
||
{
|
||
return es;
|
||
}
|
||
ASSERT(pBlockTableRec);
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
es = pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
ASSERT(pEntity);
|
||
|
||
XDbObject vTemp(pEntity);
|
||
|
||
AcDbExtents ext;
|
||
if (pEntity->getGeomExtents(ext) != Acad::eOk ||
|
||
ext.minPoint().x < ptMin.x - 1E-6 ||
|
||
ext.minPoint().y < ptMin.y - 1E-6 ||
|
||
ext.maxPoint().x > ptMax.x + 1E-6 ||
|
||
ext.maxPoint().y > ptMax.y + 1E-6)
|
||
{
|
||
if (pEntity->upgradeOpen() == Acad::eOk)
|
||
{
|
||
pEntity->erase();
|
||
}
|
||
}
|
||
}
|
||
delete pBlockIterator;
|
||
|
||
pBlockTableRec->close();
|
||
return Acad::eOk;
|
||
}
|
||
|
||
int XExport::ExpInsertDwg(const TCHAR *pszDwg,XPoint ptBase,XPoint ptMin,XPoint ptMax,XPoint ptInsert)
|
||
{
|
||
AcDbDatabase db(false, true);
|
||
#if ARX >= 21
|
||
if (db.readDwgFile(pszDwg, AcDbDatabase::kForReadAndAllShare) != Acad::eOk)
|
||
#else
|
||
if (db.readDwgFile(pszDwg, _SH_DENYNO) != Acad::eOk)
|
||
#endif
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
EraseEntityFromDatabase(db,ptMin,ptMax);
|
||
|
||
ads_matrix mat;
|
||
ptBase.GetMoveMatrix(ptInsert, mat);
|
||
|
||
if (acdbCurDwg()->insert(AsAcGeMatrix3d(mat), &db, Adesk::kFalse) != Acad::eOk)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
return RTNORM;
|
||
}
|
||
|
||
BOOL XExport::IsKeyPressed(int vk)
|
||
{
|
||
SHORT nState = GetKeyState(vk);
|
||
return ((nState&256) != 0);
|
||
}
|
||
|
||
void XExport::MakeVisible(PickSet &ss, bool bTrue)
|
||
{
|
||
long len = ss.Length();
|
||
for (long i = 0;i<len;i++)
|
||
{
|
||
Entity ent = ss[i];
|
||
OPENOBJ_BEGIN(ent, AcDb::kForWrite, AcDbEntity, pEnt);
|
||
if (pEnt)
|
||
{
|
||
pEnt->setVisibility(bTrue ? AcDb::kVisible : AcDb::kInvisible);
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
}
|
||
|
||
AcDbObjectId XExport::AddLayer(AcDbLayerTableRecord *pLay, BOOL bDoneClosed, AcDbDatabase *pDb)
|
||
{
|
||
AcDbDatabase *pCurDwg = pDb ? pDb : acdbCurDwg();
|
||
AcDbLayerTable *pVPTable = NULL;
|
||
AcDbObjectId id;
|
||
if (pCurDwg->getSymbolTable(pVPTable, AcDb::kForWrite) == Acad::eOk)
|
||
{
|
||
Acad::ErrorStatus es = pVPTable->add(id, pLay);
|
||
pVPTable->close();
|
||
if (es == Acad::eOk && bDoneClosed)
|
||
{
|
||
pLay->close();
|
||
}
|
||
}
|
||
return id;
|
||
}
|
||
|
||
|
||
BOOL XExport::IsValidPath(const TCHAR *szPath)
|
||
{
|
||
XString csGatherLoc = szPath;
|
||
int nStrLen = _tcslen(csGatherLoc);
|
||
if (!nStrLen)
|
||
{
|
||
return FALSE;
|
||
}
|
||
if (csGatherLoc[nStrLen-1] == _T('\\'))
|
||
{
|
||
csGatherLoc[nStrLen-1] = 0;
|
||
}
|
||
return FindFile(csGatherLoc);
|
||
}
|
||
|
||
BOOL XExport::AsStdPath(XString &sPath)
|
||
{
|
||
XString csPath(256);
|
||
csPath << sPath;
|
||
if (!IsValidPath(csPath))
|
||
{
|
||
return FALSE;
|
||
}
|
||
int nLen = _tcslen(csPath);
|
||
if (csPath[nLen-1] != _T('\\'))
|
||
{
|
||
csPath << _T("\\");
|
||
}
|
||
sPath = csPath;
|
||
return TRUE;
|
||
}
|
||
|
||
BOOL XExport::arxWBlock(PickSet &ss, const TCHAR* szFileName, XPoint ptIns)
|
||
{
|
||
AcDbObjectIdArray cloneSet;
|
||
|
||
long len = ss.Length();
|
||
for (long i = 0;i<len;i++)
|
||
{
|
||
Entity ent = ss[i];
|
||
AcDbObjectId id;
|
||
acdbGetObjectId(id, ent);
|
||
cloneSet.append(id);
|
||
}
|
||
AcDbDatabase db;
|
||
AcDbObjectId idMSpace = db.currentSpaceId();
|
||
AcDbIdMapping idMap;
|
||
acdbCurDwg()->wblockCloneObjects(cloneSet, idMSpace, idMap, AcDb::kDrcIgnore, false);
|
||
AcDbBlockTable *pTable = NULL;
|
||
db.getBlockTable(pTable, AcDb::kForRead);
|
||
if (!pTable)
|
||
{
|
||
return FALSE;
|
||
}
|
||
|
||
AcGeMatrix3d mat;
|
||
mat.setToTranslation(AcGeVector3d(-ptIns[0], -ptIns[1], -ptIns[2]));
|
||
AcDbBlockTableRecord *pBlockTableRecord = NULL;
|
||
VERIFY(pTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForRead) == Acad::eOk);
|
||
pTable->close();
|
||
if (!pBlockTableRecord)
|
||
{
|
||
return FALSE;
|
||
}
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
|
||
pBlockTableRecord->newIterator(pBlockIterator);
|
||
if (!pBlockIterator)
|
||
{
|
||
pBlockTableRecord->close();
|
||
return FALSE;
|
||
}
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEnt = NULL;
|
||
pBlockIterator->getEntity(pEnt,AcDb::kForWrite);
|
||
if (pEnt)
|
||
{
|
||
pEnt->transformBy(mat);
|
||
pEnt->close();
|
||
}
|
||
}
|
||
delete pBlockIterator;
|
||
pBlockTableRecord->close();
|
||
#if (ARX>15)
|
||
return (acdbSaveAs2000(&db, szFileName) == Acad::eOk);
|
||
#else
|
||
return (db.saveAs(szFileName) == Acad::eOk);
|
||
#endif
|
||
}
|
||
|
||
BOOL XExport::IsModelSpace(AcDbObjectId idBlock)
|
||
{
|
||
const TCHAR* sName = NULL;
|
||
AcDbBlockTableRecord *pRecord = NULL;
|
||
acdbOpenObject(pRecord,idBlock,AcDb::kForRead);
|
||
if (pRecord != NULL)
|
||
{
|
||
pRecord->getName(sName);
|
||
pRecord->close();
|
||
}
|
||
|
||
if (sName == NULL)
|
||
{
|
||
return FALSE;
|
||
}
|
||
|
||
return _tcsicmp(sName,ACDB_MODEL_SPACE) == 0;
|
||
}
|
||
|
||
#ifdef _REF_EDIT_PATCH
|
||
AcDbLongTransWorkSetIterator* XExport::GetCurrentWorkSet()
|
||
{
|
||
AcDbLongTransWorkSetIterator *pIter = NULL;
|
||
AcApDocument *pCurDoc = curDoc();
|
||
if (pCurDoc == NULL)
|
||
{
|
||
return pIter;
|
||
}
|
||
|
||
AcDbObjectId idLT = acapLongTransactionManagerPtr()->currentLongTransactionFor (pCurDoc);
|
||
AcDbLongTransaction *pLT = NULL;
|
||
acdbOpenObject(pLT,idLT,AcDb::kForRead);
|
||
if (pLT != NULL)
|
||
{
|
||
pLT->newWorkSetIterator(pIter);
|
||
pLT->close();
|
||
}
|
||
|
||
return pIter;
|
||
}
|
||
|
||
BOOL XExport::WorkSetHas(AcDbObjectId idEnt)
|
||
{
|
||
AcDbLongTransWorkSetIterator *pIter = NULL;
|
||
AcApDocument *pCurDoc = curDoc();
|
||
if (pCurDoc == NULL)
|
||
{
|
||
return FALSE;
|
||
}
|
||
|
||
AcDbObjectId idLT = acapLongTransactionManagerPtr()->currentLongTransactionFor (pCurDoc);
|
||
AcDbLongTransaction *pLT = NULL;
|
||
acdbOpenObject(pLT,idLT,AcDb::kForRead);
|
||
if (pLT != NULL)
|
||
{
|
||
BOOL bRet = pLT->workSetHas(idEnt);
|
||
pLT->close();
|
||
|
||
return bRet;
|
||
}
|
||
else
|
||
{
|
||
return TRUE;
|
||
}
|
||
}
|
||
#endif //#ifdef _REF_EDIT_PATCH
|
||
|
||
Acad::ErrorStatus XExport::GetSafeSelection2(PickSet &ss, BOOL bCrossing, const XPoint &ptLow,
|
||
const XPoint &ptUp, const AcRxClass *pClass)
|
||
{
|
||
#ifdef _REF_EDIT_PATCH
|
||
AcDbLongTransWorkSetIterator* pBlockIterator = GetCurrentWorkSet();
|
||
if (pBlockIterator != NULL)//当前工作集存在
|
||
{
|
||
Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
|
||
XBlockTableRecPtr mspace(ACDB_MODEL_SPACE, AcDb::kForRead);
|
||
AcDbObjectId idMSpace;
|
||
if (mspace.m_pBlockTableRec != NULL)
|
||
{
|
||
idMSpace = mspace.m_pBlockTableRec->objectId();
|
||
mspace.Close();
|
||
}
|
||
|
||
XPoint ptMid;
|
||
Midpoint(ptLow, ptUp, ptMid);
|
||
XRectAngle rect(ptLow, ptUp);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
acdbOpenObject(pEntity,pBlockIterator->objectId(),AcDb::kForRead);
|
||
if (pEntity == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
XDbObject vTemp(pEntity);
|
||
|
||
//防止有非模型空间的的混入
|
||
if (pEntity->ownerId() != idMSpace)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
|
||
if (!pClass || pRxInfo == pClass)
|
||
{
|
||
if (!bCrossing && pEntity->isKindOf(AcDbCurve::desc()))
|
||
{ //用于加速目的,光标移动时自动捕捉时使用
|
||
AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
XPoint ptCurve;
|
||
if (pCurve->getClosestPointTo(ptMid, ptCurve) == Acad::eOk &&
|
||
ptCurve.x > rect.lowLeft.x && ptCurve.x < rect.upRight.x &&
|
||
ptCurve.y > rect.lowLeft.y && ptCurve.y < rect.upRight.y)
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AcDbExtents ext;
|
||
if (pEntity->getGeomExtents(ext) == Acad::eOk) { //加速2003/9/12
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
delete pBlockIterator;
|
||
return esRet;
|
||
}
|
||
#endif //#ifdef _REF_EDIT_PATCH
|
||
return XExport::GetSafeSelection(ss, bCrossing, ptLow, ptUp,pClass);
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::GetSafeSelection2(PickSet &ss, BOOL bCrossing, const XPoint &ptLow,
|
||
const XPoint &ptUp, const AcRxClass *pClass,AcDbObjectId idBlock)
|
||
{
|
||
#ifdef _REF_EDIT_PATCH
|
||
if (IsModelSpace(idBlock))
|
||
{
|
||
AcDbLongTransWorkSetIterator* pBlockIterator = GetCurrentWorkSet();
|
||
if (pBlockIterator != NULL)//当前工作集存在
|
||
{
|
||
Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
|
||
XPoint ptMid;
|
||
Midpoint(ptLow, ptUp, ptMid);
|
||
XRectAngle rect(ptLow, ptUp);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
acdbOpenObject(pEntity,pBlockIterator->objectId(),AcDb::kForRead);
|
||
if (pEntity == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
XDbObject vTemp(pEntity);
|
||
|
||
//防止有非模型空间的的混入
|
||
if (pEntity->ownerId() != idBlock)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
|
||
if (!pClass || pRxInfo == pClass)
|
||
{
|
||
if (!bCrossing && pEntity->isKindOf(AcDbCurve::desc()))
|
||
{ //用于加速目的,光标移动时自动捕捉时使用
|
||
AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
XPoint ptCurve;
|
||
if (pCurve->getClosestPointTo(ptMid, ptCurve) == Acad::eOk &&
|
||
ptCurve.x>rect.lowLeft.x && ptCurve.x<rect.upRight.x &&
|
||
ptCurve.y>rect.lowLeft.y && ptCurve.y<rect.upRight.y)
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AcDbExtents ext;
|
||
if (pEntity->getGeomExtents(ext) == Acad::eOk)
|
||
{
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
delete pBlockIterator;
|
||
return esRet;
|
||
}
|
||
}
|
||
#endif#ifdef _REF_EDIT_PATCH
|
||
|
||
return XExport::GetSafeSelection(ss, bCrossing, ptLow, ptUp,pClass,idBlock);
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::GetSafeSelectionEx2(PickSet &ss, BOOL bCrossing, const XPoint &ptLow, const XPoint &ptUp,
|
||
const AcRxClass *pClass)
|
||
{
|
||
#ifdef _REF_EDIT_PATCH
|
||
AcDbLongTransWorkSetIterator* pBlockIterator = GetCurrentWorkSet();
|
||
if (pBlockIterator != NULL)//当前工作集存在
|
||
{
|
||
Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
|
||
XBlockTableRecPtr mspace(ACDB_MODEL_SPACE, AcDb::kForRead);
|
||
AcDbObjectId idMSpace;
|
||
if (mspace.m_pBlockTableRec != NULL)
|
||
{
|
||
idMSpace = mspace.m_pBlockTableRec->objectId();
|
||
mspace.Close();
|
||
}
|
||
|
||
XPoint ptMid;
|
||
Midpoint(ptLow, ptUp, ptMid);
|
||
XRectAngle rect(ptLow, ptUp);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
acdbOpenObject(pEntity,pBlockIterator->objectId(),AcDb::kForRead);
|
||
if (pEntity == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
XDbObject vTemp(pEntity);
|
||
|
||
//防止有非模型空间的的混入
|
||
if (pEntity->ownerId() != idMSpace)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (!pClass || pEntity->isKindOf(pClass))
|
||
{
|
||
if (!bCrossing && pEntity->isKindOf(AcDbCurve::desc()))
|
||
{ //用于加速目的,光标移动时自动捕捉时使用
|
||
AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
XPoint ptCurve;
|
||
if (pCurve->getClosestPointTo(ptMid, ptCurve) == Acad::eOk &&
|
||
ptCurve.x>rect.lowLeft.x && ptCurve.x<rect.upRight.x &&
|
||
ptCurve.y>rect.lowLeft.y && ptCurve.y<rect.upRight.y)
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AcDbExtents ext;
|
||
if (pEntity->getGeomExtents(ext) == Acad::eOk)
|
||
{
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
delete pBlockIterator;
|
||
return esRet;
|
||
}
|
||
#endif//#ifdef _REF_EDIT_PATCH
|
||
|
||
return XExport::GetSafeSelectionEx(ss, bCrossing, ptLow, ptUp,pClass);
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::GetSafeSelectionEx2(PickSet &ss, BOOL bCrossing, const XPoint &ptLow,
|
||
const XPoint &ptUp, const AcRxClass *pClass,AcDbObjectId idBlock)
|
||
{
|
||
#ifdef _REF_EDIT_PATCH
|
||
if (IsModelSpace(idBlock))
|
||
{
|
||
AcDbLongTransWorkSetIterator* pBlockIterator = GetCurrentWorkSet();
|
||
if (pBlockIterator != NULL)//当前工作集存在
|
||
{
|
||
Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
|
||
XPoint ptMid;
|
||
Midpoint(ptLow, ptUp, ptMid);
|
||
XRectAngle rect(ptLow, ptUp);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
acdbOpenObject(pEntity,pBlockIterator->objectId(),AcDb::kForRead);
|
||
if (pEntity == NULL)
|
||
continue;
|
||
|
||
XDbObject vTemp(pEntity);
|
||
|
||
//防止有非模型空间的的混入
|
||
if (pEntity->ownerId() != idBlock)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (!pClass || pEntity->isKindOf(pClass))
|
||
{
|
||
if (!bCrossing && pEntity->isKindOf(AcDbCurve::desc()))
|
||
{ //用于加速目的,光标移动时自动捕捉时使用
|
||
AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
XPoint ptCurve;
|
||
if (pCurve->getClosestPointTo(ptMid, ptCurve) == Acad::eOk &&
|
||
ptCurve.x>rect.lowLeft.x && ptCurve.x<rect.upRight.x &&
|
||
ptCurve.y>rect.lowLeft.y && ptCurve.y<rect.upRight.y)
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AcDbExtents ext;
|
||
if (pEntity->getGeomExtents(ext) == Acad::eOk)
|
||
{
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
delete pBlockIterator;
|
||
return esRet;
|
||
}
|
||
}
|
||
#endif//#ifdef _REF_EDIT_PATCH
|
||
|
||
return XExport::GetSafeSelectionEx(ss, bCrossing, ptLow, ptUp,pClass,idBlock);
|
||
}
|
||
|
||
// 安全模式开窗口搜索选择集
|
||
// 目前只验证过"C"方式
|
||
// bCrossing : FALSE-对曲线加速
|
||
Acad::ErrorStatus XExport::GetSafeSelection2(PickSet &ss, const XPoint &ptLow, const XPoint &ptUp,
|
||
std::list<AcRxClass*> &lstClass, AcDbObjectId idLayer)
|
||
{
|
||
#ifdef _REF_EDIT_PATCH
|
||
AcDbLongTransWorkSetIterator* pBlockIterator = GetCurrentWorkSet();
|
||
if (pBlockIterator != NULL)//当前工作集存在
|
||
{
|
||
Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
|
||
XBlockTableRecPtr mspace(ACDB_MODEL_SPACE, AcDb::kForRead);
|
||
AcDbObjectId idMSpace;
|
||
if (mspace.m_pBlockTableRec != NULL)
|
||
{
|
||
idMSpace = mspace.m_pBlockTableRec->objectId();
|
||
mspace.Close();
|
||
}
|
||
|
||
XPoint ptMid;
|
||
Midpoint(ptLow, ptUp, ptMid);
|
||
XRectAngle rect(ptLow, ptUp);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
acdbOpenObject(pEntity,pBlockIterator->objectId(),AcDb::kForRead);
|
||
if (pEntity == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
XDbObject vTemp(pEntity);
|
||
|
||
//防止有非模型空间的的混入
|
||
if (pEntity->ownerId() != idMSpace)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (!!idLayer)
|
||
{
|
||
AcDbObjectId idLay = pEntity->layerId();
|
||
if (idLayer != idLay)
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
|
||
//if (lstClass.FindNode(pRxInfo, CompareAcRxClass))
|
||
if (std::find(lstClass.begin(),lstClass.end(),pRxInfo) != lstClass.end())
|
||
{
|
||
if (pEntity->isKindOf(AcDbCurve::desc()))
|
||
{ //用于加速目的,光标移动时自动捕捉时使用
|
||
AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
XPoint ptCurve;
|
||
if (pCurve->getClosestPointTo(ptMid, ptCurve) == Acad::eOk &&
|
||
ptCurve.x>rect.lowLeft.x && ptCurve.x<rect.upRight.x &&
|
||
ptCurve.y>rect.lowLeft.y && ptCurve.y<rect.upRight.y)
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AcDbExtents ext;
|
||
if (pEntity->getGeomExtents(ext) == Acad::eOk)
|
||
{
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x ||
|
||
ptUp.y<ptExtMin.y ||
|
||
ptLow.x>ptExtMax.x ||
|
||
ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
delete pBlockIterator;
|
||
return esRet;
|
||
}
|
||
#endif//#ifdef _REF_EDIT_PATCH
|
||
|
||
return XExport::GetSafeSelection(ss, ptLow, ptUp,lstClass,idLayer);
|
||
}
|
||
|
||
// nCmpMethod: 0--use equal; 1--Use isKindOf
|
||
Acad::ErrorStatus XExport::GetEntFromBlockByClass2(DList<AcDbObjectId> &lstObjects,AcRxClass *pClass,
|
||
int nCmpMethod, AcDbObjectId idBlock,LPVOID pReserve)
|
||
{
|
||
#ifdef _REF_EDIT_PATCH
|
||
if (IsModelSpace(idBlock))
|
||
{
|
||
bool bLookUpExt = false;
|
||
AcDbExtents ext,ext2;
|
||
if (pReserve != NULL)
|
||
{
|
||
typedef CMap<LONG_PTR,LONG_PTR,AcDbExtents,AcDbExtents> CMapLongToExtents;
|
||
CMapLongToExtents* pMap = (CMapLongToExtents*)pReserve;
|
||
if (pMap->Lookup(idBlock.asOldId(),ext))
|
||
{
|
||
bLookUpExt = true;
|
||
}
|
||
}
|
||
|
||
AcDbLongTransWorkSetIterator* pBlockIterator = GetCurrentWorkSet();
|
||
if (pBlockIterator != NULL)//当前工作集存在
|
||
{
|
||
Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
acdbOpenObject(pEntity,pBlockIterator->objectId(),AcDb::kForRead);
|
||
if (pEntity == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
XDbObject vTemp(pEntity);
|
||
|
||
//防止有非模型空间的的混入
|
||
if (pEntity->ownerId() != idBlock)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
if (nCmpMethod == 0)
|
||
{
|
||
if (pRxInfo == pClass)
|
||
{
|
||
if (bLookUpExt)
|
||
{
|
||
if (pEntity->getGeomExtents(ext2) == Acad::eOk)
|
||
{
|
||
XPoint ptExtMin = ext2.minPoint(), ptExtMax = ext2.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ext.maxPoint().x<ptExtMin.x || ext.maxPoint().y<ptExtMin.y ||
|
||
ext.minPoint().x>ptExtMax.x || ext.minPoint().y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (pEntity->isKindOf(pClass))
|
||
{
|
||
if (bLookUpExt)
|
||
{
|
||
if (pEntity->getGeomExtents(ext2) == Acad::eOk)
|
||
{
|
||
XPoint ptExtMin = ext2.minPoint(), ptExtMax = ext2.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ext.maxPoint().x<ptExtMin.x || ext.maxPoint().y<ptExtMin.y ||
|
||
ext.minPoint().x>ptExtMax.x || ext.minPoint().y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
delete pBlockIterator;
|
||
return esRet;
|
||
}
|
||
}
|
||
#endif//#ifdef _REF_EDIT_PATCH
|
||
|
||
return XExport::GetEntFromBlockByClass(lstObjects,pClass,nCmpMethod,idBlock,pReserve);
|
||
}
|
||
|
||
//得到块内可见对象
|
||
void XExport::GetVisibleEnts(AcDbObjectIdArray &idArray,AcDbObjectId idBlock,bool bAEntityBaseCast,LPVOID pReserve)
|
||
{
|
||
bool bLookUpExt = false;
|
||
AcDbExtents ext,ext2;
|
||
if (pReserve != NULL)
|
||
{
|
||
typedef CMap<LONG_PTR,LONG_PTR,AcDbExtents,AcDbExtents> CMapLongToExtents;
|
||
CMapLongToExtents* pMap = (CMapLongToExtents*)pReserve;
|
||
if (pMap->Lookup(idBlock.asOldId(),ext))
|
||
{
|
||
bLookUpExt = true;
|
||
}
|
||
}
|
||
|
||
AEntityBase* pEntBase = NULL;
|
||
#ifdef _REF_EDIT_PATCH
|
||
if (idBlock.isNull()||IsModelSpace(idBlock))
|
||
{
|
||
AcDbLongTransWorkSetIterator* pBlockIterator = GetCurrentWorkSet();
|
||
if (pBlockIterator != NULL)//当前工作集存在
|
||
{
|
||
if (idBlock.isNull())
|
||
{
|
||
XBlockTableRecPtr mspace(ACDB_MODEL_SPACE, AcDb::kForRead);
|
||
AcDbObjectId idMSpace;
|
||
if (mspace.m_pBlockTableRec != NULL)
|
||
{
|
||
idBlock = mspace.m_pBlockTableRec->objectId();
|
||
}
|
||
}
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
acdbOpenObject(pEntity,pBlockIterator->objectId(),AcDb::kForRead);
|
||
if (pEntity != NULL)
|
||
{
|
||
if (bAEntityBaseCast)
|
||
{
|
||
pEntBase = AEntityBase::Cast(pEntity);
|
||
if (pEntBase == NULL)
|
||
{
|
||
pEntity->close();
|
||
continue;
|
||
}
|
||
}
|
||
if (pEntity->ownerId() == idBlock&&//防止有非模型空间的的混入
|
||
pEntity->visibility() == AcDb::kVisible)
|
||
{
|
||
|
||
if (bLookUpExt)
|
||
{
|
||
if (pEntity->getGeomExtents(ext2) == Acad::eOk)
|
||
{
|
||
XPoint ptExtMin = ext2.minPoint(), ptExtMax = ext2.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ext.maxPoint().x<ptExtMin.x || ext.maxPoint().y<ptExtMin.y ||
|
||
ext.minPoint().x>ptExtMax.x || ext.minPoint().y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
idArray.append(pEntity->objectId());
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
idArray.append(pEntity->objectId());
|
||
}
|
||
}
|
||
|
||
pEntity->close();
|
||
}
|
||
}
|
||
|
||
delete pBlockIterator;
|
||
return;
|
||
}
|
||
}
|
||
#endif //#ifdef _REF_EDIT_PATCH
|
||
|
||
if (idBlock.isNull())
|
||
{
|
||
XBlockTableRecPtr mspace(ACDB_MODEL_SPACE, AcDb::kForRead);
|
||
AcDbObjectId idMSpace;
|
||
if (mspace.m_pBlockTableRec != NULL)
|
||
{
|
||
idBlock = mspace.m_pBlockTableRec->objectId();
|
||
}
|
||
}
|
||
|
||
Acad::ErrorStatus es;
|
||
AcDbBlockTableRecord *pRecord = NULL;
|
||
acdbOpenObject(pRecord,idBlock,AcDb::kForRead);
|
||
if (pRecord != NULL)
|
||
{
|
||
AcDbBlockTableRecordIterator*pBlockIterator = NULL;
|
||
pRecord->newIterator(pBlockIterator);
|
||
pRecord->close();
|
||
|
||
if (pBlockIterator != NULL)
|
||
{
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity,AcDb::kForRead);
|
||
|
||
|
||
if (pEntity != NULL)
|
||
{
|
||
if (bAEntityBaseCast)
|
||
{
|
||
pEntBase = AEntityBase::Cast(pEntity);
|
||
if (pEntBase == NULL)
|
||
{
|
||
pEntity->close();
|
||
continue;
|
||
}
|
||
}
|
||
|
||
if (pEntity->visibility() == AcDb::kVisible)
|
||
{
|
||
|
||
if (bLookUpExt)
|
||
{
|
||
if (pEntity->getGeomExtents(ext2) == Acad::eOk)
|
||
{
|
||
XPoint ptExtMin = ext2.minPoint(), ptExtMax = ext2.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ext.maxPoint().x<ptExtMin.x || ext.maxPoint().y<ptExtMin.y ||
|
||
ext.minPoint().x>ptExtMax.x || ext.minPoint().y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
idArray.append(pEntity->objectId());
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
idArray.append(pEntity->objectId());
|
||
}
|
||
}
|
||
|
||
pEntity->close();
|
||
}
|
||
else
|
||
{
|
||
//如果对象之前以写的方式已经打开,此处就不判断范围,直接加入 zjq 2009-7-12
|
||
AcDbObjectId idT;
|
||
pBlockIterator->getEntityId(idT);
|
||
idArray.append(idT);
|
||
}
|
||
}
|
||
|
||
delete pBlockIterator;
|
||
}
|
||
}
|
||
}
|
||
|
||
int XExport::SplitSlbName(const TCHAR *totalName, TCHAR *slbFile, TCHAR *sldFile)
|
||
{
|
||
if (!totalName || !slbFile || !sldFile)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
XString fullName = totalName;
|
||
TCHAR *p1 = fullName.StrChr(_T('('));
|
||
//acutPrintf(_T("\nfullname= %s"),totalName);
|
||
|
||
TCHAR dwgFile[256] = _T("");
|
||
if (p1)
|
||
{
|
||
*p1 = 0;
|
||
p1++;
|
||
_tcscpy(dwgFile, p1);
|
||
TCHAR *p2 = _tcschr(dwgFile, _T(')'));
|
||
if (p2)
|
||
{
|
||
*p2 = 0;
|
||
}
|
||
else
|
||
{
|
||
return RTERROR;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
_tcscpy(slbFile, fullName);
|
||
_tcscpy(sldFile, dwgFile);
|
||
return RTNORM;
|
||
}
|
||
|
||
BOOL XExport::SplitLibraryPath(const TCHAR *totalName, TCHAR *slbFile, TCHAR *sldFile)
|
||
{
|
||
if (!totalName || !slbFile || !sldFile)
|
||
{
|
||
return FALSE;
|
||
}
|
||
|
||
XString fullName = totalName;
|
||
TCHAR *p1 = fullName.StrChr(_T('('));
|
||
//acutPrintf(_T("\nfullname= %s"),totalName);
|
||
|
||
TCHAR dwgFile[256] = _T("");
|
||
if (p1)
|
||
{
|
||
*p1 = 0;
|
||
p1++;
|
||
_tcscpy(dwgFile, p1);
|
||
TCHAR *p2 = _tcschr(dwgFile, _T(')'));
|
||
if (p2)
|
||
{
|
||
*p2 = 0;
|
||
}
|
||
else
|
||
{
|
||
return FALSE;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return FALSE;
|
||
}
|
||
|
||
_tcscpy(slbFile, fullName);
|
||
_tcscpy(sldFile, dwgFile);
|
||
return TRUE;
|
||
}
|
||
|
||
int XExport::TypeOfCode(int code)
|
||
{
|
||
int type = RTNONE;
|
||
if (code >= RTNONE && code <= RTT)
|
||
{
|
||
return code;
|
||
}
|
||
if (code >= EX_INT)
|
||
{ // extended tag, AOL约定的组码
|
||
if (code < EX_REAL)
|
||
{
|
||
return RTSHORT;
|
||
}
|
||
else if (code < EX_STRING)
|
||
{
|
||
return RTREAL;
|
||
}
|
||
else if (code < EX_HANDLE)
|
||
{
|
||
return RTSTR;
|
||
}
|
||
else if (code < EX_STRUCT)
|
||
{
|
||
return RTSTR;
|
||
}
|
||
else if (code < EX_END)
|
||
{
|
||
return RTSTRUCT;
|
||
}
|
||
else
|
||
{
|
||
return RTNONE;
|
||
}
|
||
}
|
||
|
||
if (code >= 1000 )
|
||
{
|
||
if (code == 1071)
|
||
{
|
||
return RTLONG;
|
||
}
|
||
code %= 1000;
|
||
};
|
||
|
||
if (code <= 49)
|
||
{
|
||
if (code >= 20)
|
||
{
|
||
type = RTREAL; /* 20~49 */
|
||
}
|
||
else if (code >= 10)
|
||
{
|
||
type = RT3DPOINT; // 10~19
|
||
}
|
||
else if (code >= 0)
|
||
{
|
||
type = RTSTR; // 0~ 9
|
||
}
|
||
else if (code >= -2)
|
||
{
|
||
type = RTENAME; // -1, -2
|
||
}
|
||
else if (code == -3)
|
||
{
|
||
type = RTSHORT;
|
||
}
|
||
else if (code == -4)
|
||
{
|
||
type = RTSTR;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (code <= 59)
|
||
{
|
||
type = RTANG; // 50~59
|
||
}
|
||
else if (code <= 79)
|
||
{
|
||
type = RTSHORT; // 60~79
|
||
}
|
||
else if (code <= 89)
|
||
{
|
||
; //80~89 unknown
|
||
}
|
||
else if (code <= 99)
|
||
{
|
||
type = RTLONG; //90~99
|
||
}
|
||
else if (code == 100 || code == 102 || code == 105)
|
||
{
|
||
type = RTSTR;
|
||
}
|
||
else if (code<110)
|
||
{
|
||
;
|
||
}
|
||
else if (code <= 119)
|
||
{
|
||
type = RT3DPOINT; // 110~119
|
||
}
|
||
else if (code <= 149)
|
||
{
|
||
type = RTREAL; // 120~149
|
||
}
|
||
else if (code < 170)
|
||
{
|
||
; // 150~169
|
||
}
|
||
else if (code <= 179)
|
||
{
|
||
type = RTSHORT; //170~179
|
||
}
|
||
else if (code < 210)
|
||
{
|
||
; // 180~209
|
||
}
|
||
else if (code <= 219)
|
||
{
|
||
type = RT3DPOINT; // 210~219
|
||
}
|
||
else if (code <= 239)
|
||
{
|
||
type = RTREAL; //220~239
|
||
}
|
||
else if (code < 270)
|
||
{
|
||
; // 240~269
|
||
}
|
||
else if (code <= 289)
|
||
{
|
||
type = RTSHORT; //270~289
|
||
}
|
||
else if (code <= 299)
|
||
{
|
||
; //290~299, bool
|
||
}
|
||
else if (code <= 369)
|
||
{
|
||
type = RTSTR; //300~369
|
||
}
|
||
else if (code <= 389)
|
||
{
|
||
type = RTSHORT; //370~389
|
||
}
|
||
else if (code <= 399)
|
||
{
|
||
type = RTSTR; // 390~399
|
||
}
|
||
else if (code <= 409)
|
||
{
|
||
type = RTSHORT; //400~409
|
||
}
|
||
else if (code <= 419)
|
||
{
|
||
type = RTSTR; //410~419
|
||
}
|
||
else if (code == 999)
|
||
{
|
||
type = RTSTR;
|
||
}
|
||
}
|
||
|
||
return type;
|
||
}
|
||
|
||
void XExport::ApplicationError(const TCHAR *msg,...)
|
||
{
|
||
TCHAR temps[256];
|
||
va_list vlist;
|
||
va_start(vlist, msg);
|
||
_vstprintf(temps, msg, vlist);
|
||
va_end(vlist);
|
||
ads_fail(temps);
|
||
}
|
||
|
||
int XExport::MakeEntity(int type,...)
|
||
{
|
||
PGroups list = VBuildList(&type);
|
||
|
||
if (list)
|
||
{
|
||
return ads_entmake((struct resbuf *)list);
|
||
}
|
||
return RTERROR;
|
||
}
|
||
|
||
void XExport::PrintList(const PGroups headList)
|
||
{
|
||
PGroups list = headList;
|
||
while (list)
|
||
{
|
||
ads_printf(_T("(%d: "),list->code);
|
||
switch(XExport::TypeOfCode(list->code))
|
||
{
|
||
case RTSTR : ads_printf(_T("\"%s\")"),list->string);
|
||
break;
|
||
case RTSHORT: ads_printf(_T("%d)"),list->shortInt);
|
||
break;
|
||
case RTLONG :
|
||
ads_printf(_T("%ld)"),list->longInt);
|
||
break;
|
||
case RTREAL : ads_printf(_T("%lg)"),list->real);
|
||
break;
|
||
case RT3DPOINT:
|
||
ads_printf(_T("%lg,%lg,%lg)"),list->point[0],list->point[1], list->point[2]);
|
||
break;
|
||
default :
|
||
ads_printf(_T(" ?)"));
|
||
}
|
||
list = list->next;
|
||
}
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::arxZoomTo(const XPoint &ptCen, double nWidth, double nHeight)
|
||
{
|
||
AcDbViewTableRecord view;
|
||
InitView(view);
|
||
XPoint ptDcs;
|
||
ads_trans(ptCen, Groups(0), Groups(2), 0, ptDcs);
|
||
view.setCenterPoint(ptDcs.AsAcGePoint2d());
|
||
view.setHeight( nHeight);
|
||
view.setWidth( nWidth );
|
||
|
||
Acad::ErrorStatus es = acedSetCurrentView( &view, NULL );
|
||
return es;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::arxPan(const XPoint &vtPan)
|
||
{
|
||
AcDbViewTableRecord view;
|
||
InitView(view);
|
||
|
||
XPoint ptViewCtr = view.centerPoint();
|
||
ptViewCtr += vtPan;
|
||
view.setCenterPoint(ptViewCtr.AsAcGePoint2d());
|
||
|
||
Acad::ErrorStatus es = acedSetCurrentView( &view, NULL );
|
||
return es;
|
||
}
|
||
|
||
extern int operator & (const XPoint &pt, const XRectAngle &box);
|
||
|
||
Acad::ErrorStatus XExport::GetSafeSelection(PickSet &ss, BOOL bCrossing, const XPoint &ptLow,
|
||
const XPoint &ptUp, const TCHAR *pDxfWizard,BOOL bRealCornerSel)
|
||
{
|
||
XBlockTableRecordZone* pZone = NULL;
|
||
g_mapDbToModelRecZone.Lookup((void*)acdbCurDwg(),(void*&)pZone);
|
||
if (pZone != NULL && !pZone->isActive())
|
||
{
|
||
pZone = NULL;
|
||
}
|
||
|
||
Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
XBlockTableRecPtr objMSpace;
|
||
if (!objMSpace)
|
||
{
|
||
return esRet;
|
||
}
|
||
|
||
XPoint ptMid;
|
||
Midpoint(ptLow, ptUp, ptMid);
|
||
XRectAngle rect(ptLow, ptUp);
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
Acad::ErrorStatus es = objMSpace.m_pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
CString sDxfWiz;
|
||
if (pDxfWizard)
|
||
{
|
||
sDxfWiz = pDxfWizard;
|
||
}
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
ASSERT(pEntity);
|
||
|
||
XDbObject vTemp(pEntity);
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
CString str = pRxInfo->dxfName();
|
||
if (!pDxfWizard || /*ads_wcmatch(pRxInfo->dxfName(), sDxfWiz) == RTNORM*/sDxfWiz.Find(pRxInfo->dxfName(),0) != -1)
|
||
{
|
||
if (!bCrossing && pEntity->isKindOf(AcDbCurve::desc()))
|
||
{
|
||
AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
XPoint ptCloseToCurve;
|
||
if (pCurve->getClosestPointTo(ptMid, ptCloseToCurve) == Acad::eOk && (ptCloseToCurve & rect) == PR_INSIDE)
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
|
||
if (bRealCornerSel)
|
||
RealCornerSel(ss, bCrossing, ptLow, ptUp, pEntity);
|
||
else
|
||
ss += ent;
|
||
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
bool bHasExt = false;
|
||
AcDbExtents ext;
|
||
|
||
//modify by zjq on 100520 优化求包围盒算法
|
||
if (pZone != NULL)
|
||
{
|
||
AcDbObjectId id(pEntity->objectId());
|
||
if (pZone->getGeomExtents(id,ext))
|
||
{
|
||
bHasExt = true;
|
||
}
|
||
}
|
||
|
||
if (bHasExt)
|
||
{
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
|
||
if (bRealCornerSel)
|
||
RealCornerSel(ss, bCrossing, ptLow, ptUp, pEntity);
|
||
else
|
||
ss += ent;
|
||
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (pEntity->getGeomExtents(ext) == Acad::eOk)
|
||
{
|
||
if (pZone != NULL) pZone->setGeomExtents(pEntity->objectId(),ext);
|
||
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
|
||
if (bRealCornerSel)
|
||
RealCornerSel(ss, bCrossing, ptLow, ptUp, pEntity);
|
||
else
|
||
ss += ent;
|
||
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
delete pBlockIterator;
|
||
return esRet;
|
||
}
|
||
|
||
// nCmpMethod: 0--Use _tcsicmp; 1--Use ads_wcmatch
|
||
Acad::ErrorStatus XExport::GetEntityFromDatabase(DList<AcDbObjectId> &lstObjects, AcDbDatabase &db, const TCHAR *pDxfWizard, int nCmpMethod, const TCHAR *pszBlock)
|
||
{
|
||
AcDbBlockTable *pBlockTable = NULL;
|
||
Acad::ErrorStatus es = db.getBlockTable(pBlockTable, AcDb::kForRead);
|
||
if (!pBlockTable)
|
||
{
|
||
return es;
|
||
}
|
||
ASSERT(es == Acad::eOk);
|
||
|
||
AcDbBlockTableRecord *pBlockTableRec = NULL;
|
||
es = pBlockTable->getAt(pszBlock, pBlockTableRec, AcDb::kForRead);
|
||
pBlockTable->close();
|
||
|
||
if (!pBlockTableRec)
|
||
{
|
||
return es;
|
||
}
|
||
ASSERT(pBlockTableRec);
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
es = pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
|
||
CString sDxfWiz;
|
||
if (pDxfWizard)
|
||
{
|
||
sDxfWiz = pDxfWizard;
|
||
}
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
ASSERT(pEntity);
|
||
|
||
XDbObject vTemp(pEntity);
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
if (nCmpMethod == 0)
|
||
{
|
||
if (_tcsicmp(pRxInfo->dxfName(), pDxfWizard) == 0)
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (/*ads_wcmatch(pRxInfo->dxfName(), pDxfWizard) == RTNORM*/sDxfWiz.Find(pRxInfo->dxfName(),0) != -1)
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
delete pBlockIterator;
|
||
|
||
pBlockTableRec->close();
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::GetEntityFromDatabase(DList<AcDbObjectId> &lstObjects, AcDbDatabase &db, const TCHAR *pDxfWizard, int nCmpMethod, const TCHAR *pszBlock,XPoint ptMin,XPoint ptMax)
|
||
{
|
||
AcDbBlockTable *pBlockTable = NULL;
|
||
Acad::ErrorStatus es = db.getBlockTable(pBlockTable, AcDb::kForRead);
|
||
if (!pBlockTable)
|
||
{
|
||
return es;
|
||
}
|
||
|
||
ASSERT(es == Acad::eOk);
|
||
|
||
AcDbBlockTableRecord *pBlockTableRec = NULL;
|
||
es = pBlockTable->getAt(pszBlock, pBlockTableRec, AcDb::kForRead);
|
||
pBlockTable->close();
|
||
|
||
if (!pBlockTableRec)
|
||
{
|
||
return es;
|
||
}
|
||
ASSERT(pBlockTableRec);
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
es = pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
|
||
CString sDxfWiz;
|
||
if (pDxfWizard)
|
||
{
|
||
sDxfWiz = pDxfWizard;
|
||
}
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
ASSERT(pEntity);
|
||
|
||
XDbObject vTemp(pEntity);
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
if (nCmpMethod == 0)
|
||
{
|
||
if (_tcsicmp(pRxInfo->dxfName(), pDxfWizard) != 0)
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (/*ads_wcmatch(pRxInfo->dxfName(), pDxfWizard) != RTNORM*/sDxfWiz.Find(pRxInfo->dxfName(),0) == -1)
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
|
||
AcDbExtents ext;
|
||
if (pEntity->getGeomExtents(ext) != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
if (ext.minPoint().x<ptMin.x-1E-6)
|
||
{
|
||
continue;
|
||
}
|
||
if (ext.minPoint().y<ptMin.y-1E-6)
|
||
{
|
||
continue;
|
||
}
|
||
if (ext.maxPoint().x>ptMax.x+1E-6)
|
||
{
|
||
continue;
|
||
}
|
||
if (ext.maxPoint().y>ptMax.y+1E-6)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
delete pBlockIterator;
|
||
|
||
pBlockTableRec->close();
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::GetEntityFromDatabase(DList<AcDbObjectId> &lstObjects,AcDbDatabase &db, const TCHAR *pszBlock,XPoint ptMin,XPoint ptMax)
|
||
{
|
||
AcDbBlockTable *pBlockTable = NULL;
|
||
Acad::ErrorStatus es = db.getBlockTable(pBlockTable, AcDb::kForRead);
|
||
if (!pBlockTable)
|
||
{
|
||
return es;
|
||
}
|
||
ASSERT(es == Acad::eOk);
|
||
|
||
AcDbBlockTableRecord *pBlockTableRec = NULL;
|
||
es = pBlockTable->getAt(pszBlock, pBlockTableRec, AcDb::kForRead);
|
||
pBlockTable->close();
|
||
|
||
if (!pBlockTableRec)
|
||
{
|
||
return es;
|
||
}
|
||
ASSERT(pBlockTableRec);
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
es = pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
ASSERT(pEntity);
|
||
|
||
XDbObject vTemp(pEntity);
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
AcDbExtents ext;
|
||
if (pEntity->getGeomExtents(ext) != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
if (ext.minPoint().x<ptMin.x-1E-6)
|
||
{
|
||
continue;
|
||
}
|
||
if (ext.minPoint().y<ptMin.y-1E-6)
|
||
{
|
||
continue;
|
||
}
|
||
if (ext.maxPoint().x>ptMax.x+1E-6)
|
||
{
|
||
continue;
|
||
}
|
||
if (ext.maxPoint().y>ptMax.y+1E-6)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
|
||
delete pBlockIterator;
|
||
pBlockTableRec->close();
|
||
return Acad::eOk;
|
||
}
|
||
|
||
// nCmpMethod: 0--Use _tcsicmp; 1--Use ads_wcmatch
|
||
Acad::ErrorStatus XExport::GetEntFromBlockByDxf(DList<AcDbObjectId> &lstObjects, const TCHAR *pDxfWizard, int nCmpMethod, const TCHAR *pszBlk)
|
||
{
|
||
XBlockTableRecPtr objMSpace(pszBlk);
|
||
if (!objMSpace)
|
||
{
|
||
return Acad::eNotApplicable;
|
||
}
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
Acad::ErrorStatus es = objMSpace.m_pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
|
||
CString sDxfWiz;
|
||
if (pDxfWizard)
|
||
{
|
||
sDxfWiz = pDxfWizard;
|
||
}
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
ASSERT(pEntity);
|
||
|
||
XDbObject vTemp(pEntity);
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
if (nCmpMethod == 0)
|
||
{
|
||
if (_tcsicmp(pRxInfo->dxfName(), pDxfWizard) == 0)
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (/*ads_wcmatch(pRxInfo->dxfName(), pDxfWizard) == RTNORM*/sDxfWiz.Find(pRxInfo->dxfName(),0) != -1)
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
delete pBlockIterator;
|
||
return Acad::eOk;
|
||
}
|
||
|
||
// nCmpMethod: 0--Use _tcsicmp; 1--Use ads_wcmatch
|
||
Acad::ErrorStatus XExport::GetEntByDxf(PickSet &lstObjects, const TCHAR *pDxfWizard, int nCmpMethod)
|
||
{
|
||
XBlockTableRecPtr objMSpace;
|
||
if (!objMSpace)
|
||
{
|
||
return Acad::eNotApplicable;
|
||
}
|
||
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
Acad::ErrorStatus es = objMSpace.m_pBlockTableRec->newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator != NULL);
|
||
|
||
CString sDxfWiz;
|
||
if (pDxfWizard)
|
||
{
|
||
sDxfWiz = pDxfWizard;
|
||
}
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
||
if (es != Acad::eOk)
|
||
{
|
||
continue;
|
||
}
|
||
ASSERT(pEntity);
|
||
|
||
XDbObject vTemp(pEntity);
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
if (nCmpMethod == 0)
|
||
{
|
||
if (_tcsicmp(pRxInfo->dxfName(), pDxfWizard) == 0)
|
||
{
|
||
Entity ent;
|
||
if (acdbGetAdsName(ent.name, pEntity->objectId()) == Acad::eOk)
|
||
{
|
||
lstObjects += ent;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
const TCHAR *pDxf = pRxInfo->dxfName();
|
||
ASSERT(pDxf);
|
||
XString xsDxfName(256);
|
||
xsDxfName << pDxf;
|
||
if (/*ads_wcmatch(pDxf, pDxfWizard) == RTNORM*/sDxfWiz.Find(pRxInfo->dxfName(),0) != -1)
|
||
{
|
||
Entity ent;
|
||
if (acdbGetAdsName(ent.name, pEntity->objectId()) == Acad::eOk)
|
||
{
|
||
lstObjects += ent;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
delete pBlockIterator;
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::SplitBlockName(const TCHAR *sName, XString &sDwb, XString &sDwg)
|
||
{
|
||
TCHAR szStyle[80] = _T("");
|
||
_tcscpy(szStyle, sName);
|
||
if (szStyle[0] != _T('$'))
|
||
{
|
||
return Acad::eInvalidInput;
|
||
}
|
||
|
||
TCHAR *pSep = _tcschr(&szStyle[1], _T('$'));
|
||
if (!pSep)
|
||
{
|
||
return Acad::eInvalidInput;
|
||
}
|
||
if (pSep)
|
||
{
|
||
sDwg = &pSep[1];
|
||
*pSep = 0;
|
||
sDwb = &szStyle[1];
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
//pszFileName 传入全路径或文件名
|
||
BOOL XExport::IsArxLoaded(const TCHAR *pszFileName)
|
||
{
|
||
CString sFullPathFileName = pszFileName;
|
||
TCHAR szFullPathFileName[512];
|
||
memset(szFullPathFileName,0,sizeof(szFullPathFileName));
|
||
|
||
//到当前cad 支持路径下找文件
|
||
if (acedFindFile(sFullPathFileName, szFullPathFileName) != RTNORM)
|
||
{
|
||
return FALSE;
|
||
}
|
||
sFullPathFileName = szFullPathFileName;
|
||
sFullPathFileName.Replace(_T("//"),_T("\\"));
|
||
CString sFileName;
|
||
int nIndex = sFullPathFileName.ReverseFind(_T('\\'));
|
||
if (nIndex == -1)
|
||
{
|
||
//不正常
|
||
sFileName = sFullPathFileName;
|
||
}
|
||
else
|
||
{
|
||
sFileName = sFullPathFileName.Mid(nIndex+1);
|
||
}
|
||
|
||
//OBJECTARX 2002\samples\polysamp\compoly\compoly.cpp(45):bool isModuleLoaded(const char* str)
|
||
AcDbVoidPtrArray* pApps = reinterpret_cast<AcDbVoidPtrArray*>(acrxLoadedApps());
|
||
if (pApps==NULL)
|
||
return FALSE;
|
||
|
||
BOOL bFound = FALSE;
|
||
for (int i=0;i<pApps->length();i++)
|
||
{
|
||
if (_tcsicmp(reinterpret_cast<const TCHAR*>(pApps->at(i)),sFileName)==0)
|
||
{
|
||
bFound = TRUE;
|
||
break;
|
||
}
|
||
}
|
||
for (;pApps->length()>0;)
|
||
{
|
||
delete reinterpret_cast<TCHAR*>(pApps->at(0));
|
||
pApps->removeAt(0);
|
||
}
|
||
delete pApps;
|
||
return bFound;
|
||
}
|
||
|
||
int XExport::LoadArxApp(const TCHAR *pszAppReg, const TCHAR *pszFileName)
|
||
{
|
||
if (IsArxLoaded(pszFileName))
|
||
{
|
||
return 1;
|
||
}
|
||
if (!acrxLoadApp(pszAppReg))
|
||
{
|
||
return 0;
|
||
}
|
||
return 2;
|
||
}
|
||
|
||
AcDbObjectId XExport::GetMSpaceId(AcDbDatabase *pDb)
|
||
{
|
||
if (!pDb)
|
||
{
|
||
pDb = acdbCurDwg();
|
||
}
|
||
|
||
XBlockTableRecPtr rec(ACDB_MODEL_SPACE, AcDb::kForRead, pDb); //MSPACE
|
||
if (!rec)
|
||
{
|
||
return AcDbObjectId::kNull;
|
||
}
|
||
AcDbObjectId id = rec.m_pBlockTableRec->objectId();
|
||
return id;
|
||
}
|
||
|
||
XPoint XExport::GetCursorWcs()
|
||
{
|
||
return g_ptCursorWcs;
|
||
}
|
||
|
||
BOOL XExport::OnCharAsHotKey(UINT_PTR nChar, UINT_PTR nRepCnt, CPoint ptScreen)
|
||
{
|
||
BOOL bRet = FALSE;
|
||
if (!m_nPos)
|
||
{ //没有其它字符输入时
|
||
int nUpChar = toupper(nChar);
|
||
int nLen = _tcslen(g_szKeyTable);
|
||
for (int i = 0; i<nLen; i++)
|
||
{
|
||
if (g_szKeyTable[i] == _T(' '))
|
||
{
|
||
continue;
|
||
}
|
||
if (g_szKeyTable[i] == nUpChar)
|
||
{
|
||
CPoint ptClient = ptScreen;
|
||
acedGetAcadDwgView()->ScreenToClient(&ptClient);
|
||
int nCurVp = 0;
|
||
VERIFY(XExport::xg_getvar(_T("CVPORT"), &nCurVp) == RTNORM);
|
||
acedCoordFromPixelToWorld(nCurVp, ptClient, g_ptCursorWcs);
|
||
|
||
if (g_nFlag == -2)
|
||
{
|
||
g_cKeyword = nUpChar;
|
||
acedPostCommand(_T(" "));
|
||
}
|
||
else
|
||
{
|
||
TCHAR szPost[3] = _T("");
|
||
szPost[0] = nUpChar; szPost[1] = _T(' '); szPost[2] = EOS;
|
||
acedPostCommand(szPost);
|
||
}
|
||
bRet = TRUE;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if (!bRet)
|
||
{
|
||
unsigned char cChar = LOBYTE(nChar);
|
||
//为了防止键盘缓冲区溢出
|
||
if (cChar == 8)
|
||
{ //退格键
|
||
if (m_nPos<(int)nRepCnt)
|
||
{
|
||
return FALSE;
|
||
}
|
||
}
|
||
else if (cChar<33 || cChar>126)
|
||
{ //控制字符
|
||
return FALSE;
|
||
}
|
||
else
|
||
{ //正常字符
|
||
if (m_nPos+nRepCnt >= 1020)
|
||
{
|
||
return FALSE;
|
||
}
|
||
}
|
||
for (UINT i = 0U; i<nRepCnt; i++)
|
||
{
|
||
ASSERT(m_nPos >= 0 && m_nPos < 1023);
|
||
if (cChar == 8)
|
||
{//退格键
|
||
m_szCommandStr[m_nPos] = EOS;
|
||
m_nPos--;
|
||
}
|
||
else
|
||
{
|
||
m_szCommandStr[m_nPos] = cChar;
|
||
m_nPos++;
|
||
}
|
||
}
|
||
ASSERT(m_nPos >= 0 && m_nPos < 1023);
|
||
m_szCommandStr[m_nPos] = EOS;
|
||
}
|
||
return bRet;
|
||
}
|
||
|
||
BOOL XExport::IsOfAcadWindows(HWND hwnd)
|
||
{
|
||
CWnd *pFromWnd = CWnd::FromHandle(hwnd);
|
||
if (!pFromWnd)
|
||
{
|
||
return FALSE;
|
||
}
|
||
CRuntimeClass *pClassInfo = pFromWnd->GetRuntimeClass();
|
||
ASSERT(pFromWnd && pClassInfo);
|
||
const char *pClassName = pClassInfo->m_lpszClassName;
|
||
//AfxMessageBox(pClassName);
|
||
return (strcmp(pClassName, "CExpandoEditWnd") == 0 ||
|
||
strcmp(pClassName,"CTextTerminalWnd") == 0 ||
|
||
XExport::IsAcadDwgView(hwnd));
|
||
}
|
||
|
||
#if ARX > 22
|
||
inline bool XExport::LocalHotKeyMonitor(MSG* msg)
|
||
#else
|
||
inline BOOL XExport::LocalHotKeyMonitor(MSG* msg)
|
||
#endif
|
||
{
|
||
if (!acdbCurDwg())
|
||
{
|
||
return FALSE;
|
||
}
|
||
BOOL bRet = FALSE;
|
||
switch(msg->message)
|
||
{
|
||
case WM_CHAR:
|
||
if (XExport::IsOfAcadWindows(msg->hwnd))
|
||
{
|
||
CPoint ptClient = msg->pt;
|
||
bRet = OnCharAsHotKey(msg->wParam, LOWORD(msg->lParam), ptClient);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return bRet;
|
||
}
|
||
|
||
void XExport::InitLocalMsg(BOOL bTrue)
|
||
{
|
||
|
||
static BOOL bLocalMsgOn = FALSE;
|
||
if (bTrue)
|
||
{
|
||
ASSERT(bLocalMsgOn == FALSE);
|
||
bLocalMsgOn = acedRegisterFilterWinMsg(LocalHotKeyMonitor);
|
||
if (bLocalMsgOn)
|
||
{
|
||
m_nPos = 0;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ASSERT(bLocalMsgOn == TRUE);
|
||
bLocalMsgOn = !acedRemoveFilterWinMsg(LocalHotKeyMonitor);
|
||
m_nPos = 0;
|
||
g_nFlag = 0;
|
||
}
|
||
}
|
||
|
||
void XExport::InitGetBegin(int nFlag, const TCHAR *szKeyTable)
|
||
{
|
||
ASSERT(szKeyTable);
|
||
_tcscpy(g_szKeyTable, szKeyTable);
|
||
if (nFlag >= 0)
|
||
{
|
||
ads_initget(nFlag, szKeyTable);
|
||
}
|
||
g_nFlag = nFlag;
|
||
g_cKeyword = 0;
|
||
|
||
//中望不支持
|
||
XExport::InitLocalMsg(TRUE);
|
||
}
|
||
|
||
int XExport::GetLayerColor(AcDbObjectId idLay)
|
||
{
|
||
int nColor = 0;
|
||
OPENOBJ_BEGIN(idLay, AcDb::kForRead, AcDbLayerTableRecord, pLay);
|
||
if (pLay)
|
||
{
|
||
nColor = pLay->color().colorIndex();
|
||
}
|
||
OPENOBJ_END();
|
||
return nColor;
|
||
}
|
||
|
||
AcDbObjectId XExport::AddBlock(AcDbBlockTableRecord *pRec, BOOL bDoneClosed, AcDbDatabase *pDb)
|
||
{
|
||
AcDbDatabase *pCurDwg = pDb? pDb : acdbCurDwg();
|
||
AcDbBlockTable *pVPTable = NULL;
|
||
AcDbObjectId id;
|
||
if (pCurDwg->getSymbolTable(pVPTable, AcDb::kForWrite) == Acad::eOk)
|
||
{
|
||
Acad::ErrorStatus es = pVPTable->add(id, pRec);
|
||
pVPTable->close();
|
||
if (es == Acad::eOk && bDoneClosed)
|
||
{
|
||
pRec->close();
|
||
}
|
||
}
|
||
return id;
|
||
}
|
||
|
||
AcDbObjectId XExport::AddTextStyle(AcDbTextStyleTableRecord *pRec, BOOL bDoneClosed, AcDbDatabase *pDb)
|
||
{
|
||
AcDbDatabase *pCurDwg = pDb? pDb : acdbCurDwg();
|
||
AcDbTextStyleTable *pVPTable = NULL;
|
||
AcDbObjectId id;
|
||
if (pCurDwg->getSymbolTable(pVPTable, AcDb::kForWrite) == Acad::eOk)
|
||
{
|
||
Acad::ErrorStatus es = pVPTable->add(id, pRec);
|
||
pVPTable->close();
|
||
if (es == Acad::eOk && bDoneClosed)
|
||
{
|
||
pRec->close();
|
||
}
|
||
}
|
||
return id;
|
||
}
|
||
|
||
AcDbObjectId XExport::AddDimStyle(AcDbDimStyleTableRecord *pRec, BOOL bDoneClosed, AcDbDatabase *pDb)
|
||
{
|
||
AcDbDatabase *pCurDwg = pDb ? pDb : acdbCurDwg();
|
||
AcDbDimStyleTable *pVPTable = NULL;
|
||
AcDbObjectId id;
|
||
if (pCurDwg->getSymbolTable(pVPTable, AcDb::kForWrite) == Acad::eOk)
|
||
{
|
||
Acad::ErrorStatus es = pVPTable->add(id, pRec);
|
||
pVPTable->close();
|
||
if (es == Acad::eOk && bDoneClosed)
|
||
{
|
||
pRec->close();
|
||
}
|
||
}
|
||
return id;
|
||
}
|
||
|
||
// 是否应当排除ss中的子对象
|
||
AcDbObjectId XExport::MakeBlock(const TCHAR *szBlock, PickSet &ss, XPoint ptInsert)
|
||
{
|
||
AcDbObjectId idBlock;
|
||
AcDbObjectIdArray idArray;
|
||
ss.AsIdArray(idArray);
|
||
if (idArray.isEmpty())
|
||
{
|
||
return idBlock;
|
||
}
|
||
|
||
AcDbBlockTableRecord *pTempBlock = new AcDbBlockTableRecord;
|
||
pTempBlock->setName(szBlock);
|
||
idBlock = AddBlock(pTempBlock, TRUE);
|
||
if (!idBlock)
|
||
{
|
||
delete pTempBlock;
|
||
return idBlock;
|
||
}
|
||
|
||
AcDbIdMapping idMap;
|
||
VERIFY(acdbCurDwg()->deepCloneObjects(idArray, idBlock, idMap, false) == Acad::eOk);
|
||
if (ptInsert.Distance(XPoint(0,0,0)) > _DIST_SNAP)
|
||
{
|
||
AcGeMatrix3d mat;
|
||
mat.setToTranslation(AcGeVector3d(-ptInsert.x, -ptInsert.y, -ptInsert.z));
|
||
|
||
AcDbBlockTableRecordIterator *pIter = NULL;
|
||
|
||
OPENOBJ_BEGIN(idBlock, AcDb::kForWrite, AcDbBlockTableRecord, pBlock);
|
||
VERIFY(pBlock->newIterator(pIter) == Acad::eOk);
|
||
OPENOBJ_END();
|
||
|
||
for (pIter->start(); !pIter->done(); pIter->step())
|
||
{
|
||
AcDbEntity *pEnt = NULL;
|
||
VERIFY(pIter->getEntity(pEnt, AcDb::kForWrite) == Acad::eOk);
|
||
ASSERT(pEnt);
|
||
VERIFY(pEnt->transformBy(mat) == Acad::eOk);
|
||
pEnt->close();
|
||
}
|
||
delete pIter;
|
||
}
|
||
return idBlock;
|
||
}
|
||
|
||
|
||
|
||
// nCmpMethod: 0--Use _tcsicmp; 1--Use ads_wcmatch
|
||
Acad::ErrorStatus XExport::GetEntFromBlockByDxf2(DList<AcDbObjectId> &lstObjects, const TCHAR *pDxfWizard, int nCmpMethod, const TCHAR *pszBlk)
|
||
{
|
||
#ifdef _REF_EDIT_PATCH
|
||
if (_tcsicmp(pszBlk,ACDB_MODEL_SPACE) == 0)
|
||
{
|
||
AcDbLongTransWorkSetIterator* pBlockIterator = GetCurrentWorkSet();
|
||
if (pBlockIterator != NULL)//当前工作集存在
|
||
{
|
||
XBlockTableRecPtr mspace(ACDB_MODEL_SPACE, AcDb::kForRead);
|
||
AcDbObjectId idMSpace;
|
||
if (mspace.m_pBlockTableRec != NULL)
|
||
{
|
||
idMSpace = mspace.m_pBlockTableRec->objectId();
|
||
mspace.Close();
|
||
}
|
||
|
||
CString sDxfWiz;
|
||
if (pDxfWizard)
|
||
{
|
||
sDxfWiz = pDxfWizard;
|
||
}
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
acdbOpenObject(pEntity,pBlockIterator->objectId(),AcDb::kForRead);
|
||
if (pEntity == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
XDbObject vTemp(pEntity);
|
||
|
||
//防止有非模型空间的的混入
|
||
if (pEntity->ownerId() != idMSpace)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
if (nCmpMethod == 0)
|
||
{
|
||
if (_tcsicmp(pRxInfo->dxfName(), pDxfWizard) == 0)
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (/*ads_wcmatch(pRxInfo->dxfName(), pDxfWizard) == RTNORM*/sDxfWiz.Find(pRxInfo->dxfName(),0) != -1)
|
||
{
|
||
lstObjects.Append(new AcDbObjectId(pEntity->objectId()));
|
||
}
|
||
}
|
||
}
|
||
|
||
delete pBlockIterator;
|
||
return Acad::eOk;
|
||
}
|
||
}
|
||
#endif
|
||
return XExport::GetEntFromBlockByDxf(lstObjects,pDxfWizard,nCmpMethod,pszBlk);
|
||
}
|
||
|
||
// nCmpMethod: 0--Use _tcsicmp; 1--Use ads_wcmatch
|
||
Acad::ErrorStatus XExport::GetEntByDxf2(PickSet &lstObjects, const TCHAR *pDxfWizard, int nCmpMethod)
|
||
{
|
||
#ifdef _REF_EDIT_PATCH
|
||
AcDbLongTransWorkSetIterator* pBlockIterator = GetCurrentWorkSet();
|
||
if (pBlockIterator != NULL)//当前工作集存在
|
||
{
|
||
XBlockTableRecPtr mspace(ACDB_MODEL_SPACE, AcDb::kForRead);
|
||
AcDbObjectId idMSpace;
|
||
if (mspace.m_pBlockTableRec != NULL)
|
||
{
|
||
idMSpace = mspace.m_pBlockTableRec->objectId();
|
||
mspace.Close();
|
||
}
|
||
|
||
CString sDxfWiz;
|
||
if (pDxfWizard)
|
||
{
|
||
sDxfWiz = pDxfWizard;
|
||
}
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
acdbOpenObject(pEntity,pBlockIterator->objectId(),AcDb::kForRead);
|
||
if (pEntity == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
XDbObject vTemp(pEntity);
|
||
|
||
//防止有非模型空间的的混入
|
||
if (pEntity->ownerId() != idMSpace)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
if (nCmpMethod == 0)
|
||
{
|
||
if (_tcsicmp(pRxInfo->dxfName(), pDxfWizard) == 0)
|
||
{
|
||
Entity ent;
|
||
if (acdbGetAdsName(ent.name, pEntity->objectId()) == Acad::eOk)
|
||
{
|
||
lstObjects += ent;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
const TCHAR *pDxf = pRxInfo->dxfName();
|
||
ASSERT(pDxf);
|
||
XString xsDxfName(256);
|
||
xsDxfName << pDxf;
|
||
if (/*ads_wcmatch(pDxf, pDxfWizard) == RTNORM*/sDxfWiz.Find(pRxInfo->dxfName(),0) != -1)
|
||
{
|
||
Entity ent;
|
||
if (acdbGetAdsName(ent.name, pEntity->objectId()) == Acad::eOk)
|
||
{
|
||
lstObjects += ent;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
delete pBlockIterator;
|
||
return Acad::eOk;
|
||
}
|
||
#endif
|
||
return XExport::GetEntByDxf(lstObjects, pDxfWizard, nCmpMethod);
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::GetSafeSelection(PickSet &ss, BOOL bCrossing, const XPoint &ptLow,
|
||
const XPoint &ptUp, const TCHAR *pDxfWizard)
|
||
{
|
||
return GetSafeSelection2(ss,bCrossing,ptLow,ptUp,pDxfWizard);
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::GetSafeSelection2(PickSet &ss, BOOL bCrossing, const XPoint &ptLow,
|
||
const XPoint &ptUp, const TCHAR *pDxfWizard)
|
||
{
|
||
#ifdef _REF_EDIT_PATCH
|
||
AcDbLongTransWorkSetIterator* pBlockIterator = GetCurrentWorkSet();
|
||
if (pBlockIterator != NULL)//当前工作集存在
|
||
{
|
||
Acad::ErrorStatus esRet = Acad::eNotApplicable;
|
||
|
||
XBlockTableRecPtr mspace(ACDB_MODEL_SPACE, AcDb::kForRead);
|
||
AcDbObjectId idMSpace;
|
||
if (mspace.m_pBlockTableRec != NULL)
|
||
{
|
||
idMSpace = mspace.m_pBlockTableRec->objectId();
|
||
mspace.Close();
|
||
}
|
||
|
||
XPoint ptMid;
|
||
Midpoint(ptLow, ptUp, ptMid);
|
||
XRectAngle rect(ptLow, ptUp);
|
||
|
||
CString sDxfWiz;
|
||
if (pDxfWizard)
|
||
{
|
||
sDxfWiz = pDxfWizard;
|
||
}
|
||
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
AcDbEntity *pEntity = NULL;
|
||
acdbOpenObject(pEntity,pBlockIterator->objectId(),AcDb::kForRead);
|
||
if (pEntity == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
XDbObject vTemp(pEntity);
|
||
|
||
//防止有非模型空间的的混入
|
||
if (pEntity->ownerId() != idMSpace)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
//不处理不可见的实体
|
||
if (pEntity->visibility() == AcDb::kInvisible)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
AcRxClass *pRxInfo = pEntity->isA();
|
||
if (!pDxfWizard || /*ads_wcmatch(pRxInfo->dxfName(), sDxfWiz) == RTNORM*/sDxfWiz.Find(pRxInfo->dxfName(),0) != -1)
|
||
{
|
||
if (!bCrossing && pEntity->isKindOf(AcDbCurve::desc()))
|
||
{
|
||
AcDbCurve *pCurve = AcDbCurve::cast(pEntity);
|
||
XPoint ptCloseToCurve;
|
||
if (pCurve->getClosestPointTo(ptMid, ptCloseToCurve) == Acad::eOk && (ptCloseToCurve&rect) == PR_INSIDE)
|
||
{
|
||
Entity ent;
|
||
VERIFY(acdbGetAdsName(ent.name, pCurve->objectId()) == Acad::eOk);
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AcDbExtents ext;
|
||
if (pEntity->getGeomExtents(ext) == Acad::eOk)
|
||
{
|
||
XPoint ptExtMin = ext.minPoint(), ptExtMax = ext.maxPoint();
|
||
ptExtMin.z = ptExtMax.z = 0;
|
||
if (ptUp.x<ptExtMin.x || ptUp.y<ptExtMin.y || ptLow.x>ptExtMax.x || ptLow.y>ptExtMax.y)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
Entity ent;
|
||
acdbGetAdsName(ent.name, pEntity->objectId());
|
||
ss += ent;
|
||
esRet = Acad::eOk;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
delete pBlockIterator;
|
||
return esRet;
|
||
}
|
||
#endif
|
||
return XExport::GetSafeSelection(ss, bCrossing, ptLow, ptUp,pDxfWizard,FALSE);
|
||
}
|
||
|
||
int XExport::YesNoQuestion(const TCHAR *s, int nDefaultAnswer)
|
||
{
|
||
int nRet;
|
||
TCHAR answer[256] = _T("");
|
||
XString sPrompt(256);
|
||
sPrompt << s << (nDefaultAnswer == Q_YES ? _T("?[是(Y)/否(N)]<Y>: ") : _T("?[是(Y)/否(N)]<N>: "));
|
||
INITGET_BEG(0, _T("Y N"));
|
||
nRet = ads_getkword(sPrompt, answer);
|
||
INITGET_END();
|
||
|
||
if (nRet == RTCAN)
|
||
{
|
||
return RTCAN;
|
||
}
|
||
if (nRet == RTNONE)
|
||
{
|
||
return nDefaultAnswer;
|
||
}
|
||
|
||
if (_tcsicmp(answer, _T("N")) == 0)
|
||
{
|
||
return Q_NO;
|
||
}
|
||
return Q_YES;
|
||
}
|
||
|
||
int XExport::XGetPoint(const ads_point ref, const TCHAR *prompt, ads_point res)
|
||
{
|
||
TCHAR prmt[256] = _T("");
|
||
if (!prompt)
|
||
{
|
||
_tcscpy(prmt, _T("\n请在屏幕上点取一点"));
|
||
}
|
||
else
|
||
{
|
||
_tcscpy(prmt, prompt);
|
||
}
|
||
|
||
XString prmt1(256);
|
||
prmt1 << prmt << _T("或 [参考点(R)]<退出>:");
|
||
|
||
int rt = RTKWORD;
|
||
|
||
XPoint refPt;
|
||
const double *base = ref;
|
||
while(rt == RTKWORD)
|
||
{
|
||
INITGET_BEG(0, _T("R"));
|
||
rt = ads_getpoint(base, prmt1, res);
|
||
INITGET_END();
|
||
if (rt == RTKWORD)
|
||
{
|
||
int rc = ads_getpoint(NULL, _T("\n参考点: "), refPt);
|
||
if (rc == RTCAN)
|
||
{
|
||
return rc;
|
||
}
|
||
else if (rc == RTNORM)
|
||
{
|
||
base = &refPt.x;
|
||
}
|
||
}
|
||
}
|
||
return rt;
|
||
}
|
||
|
||
resbuf* XExport::GetLineFence(double dist, ads_point startPoint, ads_point endPoint)
|
||
{
|
||
ads_point pt1, pt2, pt3, pt4;
|
||
double drt = ads_angle(startPoint, endPoint);
|
||
ads_polar(startPoint, drt+PI/2.0, dist, pt1);
|
||
ads_polar(startPoint, drt-PI/2.0, dist, pt2);
|
||
ads_polar(endPoint, drt-PI/2.0, dist, pt3);
|
||
ads_polar(endPoint, drt+PI/2.0, dist, pt4);
|
||
resbuf *res = ads_buildlist(RT3DPOINT, pt1,
|
||
RT3DPOINT, pt2,
|
||
RT3DPOINT, pt3,
|
||
RT3DPOINT, pt4,
|
||
RT3DPOINT, pt1, NULL);
|
||
return res;
|
||
}
|
||
|
||
resbuf* XExport::GetLinePoly(double dist, ads_point startPoint, ads_point endPoint)
|
||
{
|
||
ads_point pt1, pt2, pt3, pt4;
|
||
double drt = ads_angle(startPoint, endPoint);
|
||
ads_polar(startPoint, drt+PI/2.0, dist, pt1);
|
||
ads_polar(startPoint, drt-PI/2.0, dist, pt2);
|
||
ads_polar(endPoint, drt-PI/2.0, dist, pt3);
|
||
ads_polar(endPoint, drt+PI/2.0, dist, pt4);
|
||
resbuf *res = ads_buildlist(RT3DPOINT, pt1,
|
||
RT3DPOINT, pt2,
|
||
RT3DPOINT, pt3,
|
||
RT3DPOINT, pt4,
|
||
NULL);
|
||
return res;
|
||
}
|
||
|
||
int XExport::TextGeometry(Entity & textEnt, ads_point cen, double *w, double *h, double *ang)
|
||
{
|
||
Point org;
|
||
if (!textEnt.Is(_T("TEXT")))
|
||
{
|
||
return RTERROR;
|
||
}
|
||
textEnt.GetData(10, &org.x);
|
||
textEnt.GetData(50, ang);
|
||
Point lowLeft, upRight;
|
||
if (ads_textbox(textEnt, lowLeft, upRight) != RTNORM)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
lowLeft.Rotate(*ang);
|
||
upRight.Rotate(*ang);
|
||
*w = fabs(upRight.x-lowLeft.x);
|
||
*h = fabs(upRight.y-lowLeft.y);
|
||
cen[X] = org.x + (lowLeft.x+upRight.x)/2.0;
|
||
cen[Y] = org.y + (lowLeft.y+upRight.y)/2.0;
|
||
cen[Z] = org.z;
|
||
return RTNORM;
|
||
}
|
||
|
||
int XExport::TextGeometry(const TCHAR *text, double *w)
|
||
{
|
||
Point p;
|
||
TCHAR style[80];
|
||
XExport::xg_getvar(_T("TEXTSTYLE"), style);
|
||
|
||
StyleTable textStyle(style);
|
||
XExport::xg_getvar(_T("VIEWCTR"), &p);
|
||
|
||
Entity ent;
|
||
RBList tmp = ads_buildlist(RTDXF0, _T("TEXT"),
|
||
1, text,
|
||
7, style,
|
||
40, textStyle.height,
|
||
41, textStyle.widthFactor,
|
||
10, &p,
|
||
40, 1.0,
|
||
50, 0.0,
|
||
NULL);
|
||
double h;
|
||
return XExport::TextGeometry(tmp, w, &h);
|
||
}
|
||
|
||
int XExport::IsWCS()
|
||
{
|
||
XPoint ucsOrg, ucsXDir, ucsYDir;
|
||
XExport::xg_getvar(_T("UCSORG"), &ucsOrg);
|
||
XExport::xg_getvar(_T("UCSXDIR"), &ucsXDir);
|
||
XExport::xg_getvar(_T("UCSYDIR"), &ucsYDir);
|
||
|
||
XPushPrec var(_AS_SYS_UNIT(1.0E-5), 1.0E-3);
|
||
return (ucsOrg == XPoint() && ucsXDir == XPoint(1,0,0) && ucsYDir == XPoint(0,1,0));
|
||
}
|
||
|
||
// Migrate from ASHOME-Insert.cpp
|
||
int XExport::LoadDwbBlock(const TCHAR *sDwbFile, const TCHAR *sDwgName, TCHAR *sBlockName)
|
||
{
|
||
TCHAR drive[_MAX_DRIVE] = _T(""), dir[_MAX_DIR] = _T(""), file[_MAX_FNAME], ext[_MAX_EXT];
|
||
_tsplitpath(sDwbFile, drive, dir, file, ext);
|
||
_stprintf(sBlockName, _T("$%s$%s"), file, sDwgName);
|
||
|
||
if (!XSymbolTable(_T("BLOCK"), sBlockName))
|
||
{
|
||
;
|
||
}
|
||
else
|
||
{
|
||
return RTNORM;
|
||
}
|
||
|
||
if (!XSymbolTable(_T("BLOCK"), BLOCK_SWAP))
|
||
{
|
||
;
|
||
}
|
||
else
|
||
{
|
||
ads_alert(XString(_T("\n图块'%s'已经存在,请清除掉它或改名!"), BLOCK_SWAP));
|
||
return RTERROR;
|
||
}
|
||
|
||
XString sDwbFileExt, sFullDwbFile;
|
||
sDwbFileExt << sDwbFile;
|
||
if (!tstrchr_new(sDwbFile, _T('.')))
|
||
{
|
||
sDwbFileExt << _T(".DWB");
|
||
}
|
||
|
||
if (ads_findfile(sDwbFileExt, sFullDwbFile) != RTNORM)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
XDrawingLib dwb(sFullDwbFile, _ios::binary|_ios::in);
|
||
int nIndex = 0;
|
||
if (!dwb.IsExist(sDwgName, &nIndex))
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
XString sTempFile(256);
|
||
sTempFile = XExport::GetTempFileName(_T(".dwg"));
|
||
if (!dwb.Copy(nIndex, sTempFile))
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
int nRet = RTNORM;
|
||
AcDbDatabase db(false, true);
|
||
//acutPrintf(sTempFile);
|
||
|
||
Acad::ErrorStatus es;
|
||
#if ARX >= 21
|
||
es = db.readDwgFile(sTempFile, AcDbDatabase::kForReadAndAllShare,false);
|
||
#else
|
||
es = db.readDwgFile(sTempFile,_SH_DENYNO,false);
|
||
#endif
|
||
if(es == Acad::eOk)
|
||
{
|
||
AcDbObjectId _id(AcDbObjectId::kNull);
|
||
es = acdbCurDwg()->insert(_id, sBlockName, &db,false);
|
||
if (es == Acad::eOk)
|
||
{
|
||
nRet = RTNORM;
|
||
}
|
||
else
|
||
{
|
||
nRet = RTERROR;
|
||
}
|
||
}
|
||
_tremove(sTempFile);
|
||
return nRet;
|
||
}
|
||
|
||
int XExport::LoadDwbBlock(const TCHAR *sDwbFile, TCHAR *sBlockName)
|
||
{
|
||
XString sDwb, sDwg;
|
||
if (XExport::SplitSlbName(sDwbFile, sDwb, sDwg) != RTNORM)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
return XExport::LoadDwbBlock(sDwb, sDwg, sBlockName);
|
||
}
|
||
|
||
int XExport::LoadDwbBlock(const TCHAR *sDwbFile, const TCHAR *sDwgName, TCHAR *sBlockName,AcDbDatabase*pDb)
|
||
{
|
||
TCHAR drive[_MAX_DRIVE] = _T(""), dir[_MAX_DIR] = _T(""), file[_MAX_FNAME], ext[_MAX_EXT];
|
||
_tsplitpath(sDwbFile, drive, dir, file, ext);
|
||
_stprintf(sBlockName, _T("$%s$%s"), file, sDwgName);
|
||
if (!XBlockTableRecPtr(sBlockName, AcDb::kForRead, pDb))
|
||
{
|
||
;
|
||
}
|
||
else
|
||
{
|
||
return RTNORM;
|
||
}
|
||
|
||
XString sDwbFileExt, sFullDwbFile;
|
||
sDwbFileExt << sDwbFile;
|
||
if (!tstrchr_new(sDwbFile, _T('.')))
|
||
{
|
||
sDwbFileExt << _T(".DWB");
|
||
}
|
||
|
||
if (ads_findfile(sDwbFileExt, sFullDwbFile) != RTNORM)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
XDrawingLib dwb(sFullDwbFile, _ios::binary|_ios::in);
|
||
int nIndex = 0;
|
||
if (!dwb.IsExist(sDwgName, &nIndex))
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
XString sTempFile(256);
|
||
sTempFile = XExport::GetTempFileName(_T(".dwg"));
|
||
if (!dwb.Copy(nIndex, sTempFile))
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
int nRet = RTNORM;
|
||
AcDbDatabase db(false, true);
|
||
#if ARX >= 21
|
||
AcDbObjectId __id(AcDbObjectId::kNull);
|
||
if (db.readDwgFile(sTempFile, AcDbDatabase::kForReadAndAllShare, false) == Acad::eOk &&
|
||
pDb->insert(__id, sBlockName, &db, false) == Acad::eOk)
|
||
#else
|
||
if (db.readDwgFile(sTempFile, _SH_DENYNO, false) == Acad::eOk &&
|
||
pDb->insert(AcDbObjectId(), sBlockName, &db, false) == Acad::eOk)
|
||
#endif
|
||
{
|
||
nRet = RTNORM;
|
||
}
|
||
else
|
||
{
|
||
nRet = RTERROR;
|
||
}
|
||
_tremove(sTempFile);
|
||
return nRet;
|
||
}
|
||
|
||
int XExport::LoadDwbBlock(const TCHAR *sDwbFile, TCHAR *sBlockName,AcDbDatabase*pDb)
|
||
{
|
||
XString sDwb, sDwg;
|
||
if (XExport::SplitSlbName(sDwbFile, sDwb, sDwg) != RTNORM)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
return LoadDwbBlock(sDwb, sDwg, sBlockName,pDb);
|
||
}
|
||
|
||
void XExport::GetSearchPath(XStringList &lstSearchPath)
|
||
{
|
||
XString sAcadPath;
|
||
if (ads_findfile(_T("zwcad.exe"), sAcadPath) != RTNORM)
|
||
{
|
||
return;
|
||
}
|
||
|
||
TCHAR drive[_MAX_DRIVE] = _T(""), dir[_MAX_DIR] = _T(""), file[_MAX_FNAME], ext[_MAX_EXT];
|
||
_tsplitpath(sAcadPath, drive, dir, file, ext);
|
||
XString sDwgPrefix(256), sAcadPrefix(1024);
|
||
XExport::xg_getvar(_T("DWGPREFIX"), sDwgPrefix);
|
||
XExport::xg_getvar(_T("ACADPREFIX"), sAcadPrefix);
|
||
|
||
lstSearchPath.Append(tstrnew(sDwgPrefix));
|
||
lstSearchPath.Append(tstrnew(XString(_T("%s%s"),drive, dir)));
|
||
|
||
TCHAR *pBeg = sAcadPrefix, *pEnd = NULL;
|
||
do
|
||
{
|
||
XString sPath(256);
|
||
pEnd = _tcschr(pBeg, _T(';'));
|
||
StrCpy(sPath, pBeg, pEnd);
|
||
if (AsStdPath(sPath))
|
||
{
|
||
lstSearchPath.Append(tstrnew(sPath));
|
||
}
|
||
if (pEnd)
|
||
{
|
||
pBeg = pEnd+1;
|
||
}
|
||
} while(pEnd);
|
||
|
||
}
|
||
|
||
int XExport::GetColorDlg(int color)
|
||
{
|
||
RBList cmdList = ads_buildlist(RTSTR, _T("acad_colordlg"), RTSHORT, 7, NULL);
|
||
resbuf *rb = NULL;
|
||
int res = color;
|
||
if (ads_invoke(cmdList, &rb) == RTNORM && rb)
|
||
{
|
||
res = rb->resval.rint;
|
||
ads_relrb(rb);
|
||
}
|
||
|
||
return res;
|
||
}
|
||
|
||
// Make full path file name, with prefix same as curdwg, and different ext
|
||
void XExport::MakeFullPath(const TCHAR *pExt, XString &sFileBm1)
|
||
{
|
||
TCHAR szDwg[80] = _T("");
|
||
AT_GetCurDwg(szDwg);
|
||
|
||
XString sDwgPrefix;
|
||
XExport::xg_getvar(_T("DWGPREFIX"), sDwgPrefix);
|
||
|
||
XString sFullPath(256);
|
||
sFullPath << sDwgPrefix << szDwg << pExt;
|
||
sFileBm1 = sFullPath;
|
||
}
|
||
|
||
int XExport::GetViewport(int vp, Entity &res)
|
||
{
|
||
RBList mask = ads_buildlist(RTDXF0, _T("VIEWPORT"), NULL);
|
||
PickSet vports(SS_FREE);
|
||
if (vports.Get(_T("X"), NULL, NULL, mask) == RTNORM)
|
||
{
|
||
long len = vports.Length();
|
||
for (long i = 0; i<len; i++)
|
||
{
|
||
Entity ent = vports[i];
|
||
int id;
|
||
if (ent.GetData(69, &id) == RTNORM && id == vp)
|
||
{
|
||
res = ent;
|
||
return RTNORM;
|
||
}
|
||
}
|
||
}
|
||
return RTERROR;
|
||
}
|
||
|
||
AcDbObjectId XExport::MakeLayer(const TCHAR *LayName, BOOL bApplyChange)
|
||
{
|
||
AcDbLayerTable *pLayerTable;
|
||
AcDbObjectId idLay;
|
||
if (acdbCurDwg()->getLayerTable(pLayerTable,AcDb::kForWrite) != Acad::eOk)
|
||
{
|
||
return idLay;
|
||
}
|
||
if (pLayerTable->getAt(LayName, idLay) == Acad::eOk)
|
||
{ //层名已经存在!
|
||
pLayerTable->close();
|
||
return idLay;
|
||
}
|
||
|
||
AcDbLayerTableRecord *pLayerTableRecord = new AcDbLayerTableRecord;
|
||
|
||
pLayerTableRecord->setName(LayName);
|
||
|
||
pLayerTable->add(idLay, pLayerTableRecord);
|
||
pLayerTableRecord->close();
|
||
pLayerTable->close();
|
||
if (bApplyChange)
|
||
{
|
||
Acad::ErrorStatus es = applyCurDwgLayerTableChanges();
|
||
assert(es == Acad::eOk);
|
||
}
|
||
return idLay;
|
||
}
|
||
|
||
AcDbObjectId XExport::MakeLayer(const TCHAR *LayName,AcDbDatabase *pDb)
|
||
{
|
||
if (pDb == NULL||pDb == acdbCurDwg())
|
||
{
|
||
return XExport::MakeLayer(LayName,FALSE);
|
||
}
|
||
|
||
AcDbLayerTable *pLayerTable;
|
||
AcDbObjectId idLay;
|
||
if (pDb->getLayerTable(pLayerTable,AcDb::kForWrite) != Acad::eOk)
|
||
{
|
||
return idLay;
|
||
}
|
||
if (pLayerTable->getAt(LayName, idLay) == Acad::eOk)
|
||
{ //层名已经存在!
|
||
pLayerTable->close();
|
||
return idLay;
|
||
}
|
||
|
||
AcDbLayerTableRecord *pLayerTableRecord = new AcDbLayerTableRecord;
|
||
|
||
pLayerTableRecord->setName(LayName);
|
||
|
||
pLayerTable->add(idLay, pLayerTableRecord);
|
||
pLayerTableRecord->close();
|
||
pLayerTable->close();
|
||
|
||
return idLay;
|
||
}
|
||
|
||
int XExport::arxAssureLayer(const TCHAR *szLayer, int nFlag)
|
||
{
|
||
XExport::MakeLayer(szLayer, TRUE);
|
||
|
||
XDbLayerTableRec tLayer(szLayer, AcDb::kForWrite);
|
||
if (!tLayer)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
AcDbLayerTableRecord &lay = tLayer;
|
||
|
||
if ((nFlag&LAYSTAT_ON) && lay.isOff())
|
||
{
|
||
lay.setIsOff(Adesk::kFalse);
|
||
}
|
||
if ((nFlag&LAYSTAT_OFF) && !lay.isOff())
|
||
{
|
||
lay.setIsOff(Adesk::kTrue);
|
||
}
|
||
|
||
if ((nFlag&LAYSTAT_THAW) && lay.isFrozen())
|
||
{
|
||
lay.setIsFrozen(Adesk::kFalse);
|
||
}
|
||
if ((nFlag&LAYSTAT_FREEZE) && !lay.isFrozen())
|
||
{
|
||
lay.setIsFrozen(Adesk::kTrue);
|
||
}
|
||
|
||
if ((nFlag&LAYSTAT_UNLOCK) && lay.isLocked())
|
||
{
|
||
lay.setIsLocked(Adesk::kFalse);
|
||
}
|
||
if ((nFlag&LAYSTAT_LOCK) && !lay.isLocked())
|
||
{
|
||
lay.setIsLocked(Adesk::kTrue);
|
||
}
|
||
if ((nFlag&LAYSTAT_CURRENT))
|
||
{
|
||
xg_setvar(_T("CLAYER"), szLayer);
|
||
}
|
||
return RTNORM;
|
||
}
|
||
|
||
// Assure layer status
|
||
int XExport::AssureLayer(const TCHAR *szLayer, int nFlag)
|
||
{
|
||
return XExport::arxAssureLayer(szLayer, nFlag);
|
||
}
|
||
|
||
void XExport::AssureOnScreen(const XPoint &ptLow, const XPoint &ptUp)
|
||
{
|
||
XPoint lowCorner, upCorner;
|
||
AT_ScrCorner(lowCorner, upCorner);
|
||
XPoint pt1 = ptLow, pt2 = ptUp;
|
||
pt1.z = pt2.z = lowCorner.z;
|
||
XPoint ptMin = Min(pt1, lowCorner), ptMax = Max(pt2, upCorner);
|
||
if (ptMin != lowCorner || ptMax != upCorner)
|
||
{
|
||
XExport::arxZoom(ptMin, ptMax);
|
||
}
|
||
}
|
||
|
||
void XExport::AssureTileMode(int nMode)
|
||
{
|
||
int nTileMode;
|
||
XExport::xg_getvar(_T("TILEMODE"), &nTileMode);
|
||
if (nTileMode != nMode)
|
||
{
|
||
xg_setvar(_T("TILEMODE"), nMode);
|
||
}
|
||
}
|
||
|
||
|
||
int XExport::GetFileDia(XString &fullName, int nFlag, const TCHAR *ext, const TCHAR *title)
|
||
{
|
||
resbuf result;
|
||
result.resval.rstring = NULL;
|
||
int rc = ads_getfiled((title ? title:_T("Input File Name")), fullName, ext, nFlag, &result);
|
||
if (rc == RTNORM)
|
||
{
|
||
fullName = result.resval.rstring;
|
||
free(result.resval.rstring);
|
||
}
|
||
return rc;
|
||
}
|
||
|
||
//是否全部为数字
|
||
BOOL XExport::IsDigital(const TCHAR *pStr)
|
||
{
|
||
ASSERT(pStr);
|
||
int nLen=_tcslen(pStr);
|
||
if(!nLen)
|
||
return FALSE;
|
||
for(int i=0; i<nLen; i++) {
|
||
if(!isdigit(pStr[i]))
|
||
return FALSE;
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
int XExport::GetNextItem(const TCHAR *dwb, TCHAR *sld)
|
||
{
|
||
// extern BOOL IsDigital(const TCHAR *pStr);
|
||
XASLibMan lib(dwb, LZW_EXT, DWB_TITLE, _ios::binary|_ios::in);
|
||
XStringList recs;
|
||
if (!lib.GetAll(recs))
|
||
{
|
||
_tcscpy(sld, _T("00000001"));
|
||
return RTNORM;
|
||
}
|
||
TCHAR *maxStr = recs.MaxValue(0);
|
||
if (IsDigital(maxStr))
|
||
{
|
||
int nIndex = _ttoi(maxStr);
|
||
nIndex++;
|
||
XString sIndex = Int2Char8((unsigned)nIndex);
|
||
_tcscpy(sld, sIndex);
|
||
}
|
||
else if (maxStr && _tcslen(maxStr)>3)
|
||
{
|
||
int slen = _tcslen(maxStr);
|
||
TCHAR a1 = maxStr[slen-1], a2 = maxStr[slen-2], a3 = maxStr[slen-3];
|
||
if (a1 >= _T('0') && a1<_T('9'))
|
||
{
|
||
a1++;
|
||
}
|
||
else if (a1 == _T('9') && a2 >= _T('0') && a2<_T('9'))
|
||
{
|
||
a1 = _T('0');
|
||
a2++;
|
||
}
|
||
else if (a1 == _T('9') && a2 == _T('9') && a3 >= _T('0') && a3<_T('9'))
|
||
{
|
||
a1 = a2 = _T('0');
|
||
a3++;
|
||
}
|
||
else
|
||
{
|
||
a1++;
|
||
if (!isalpha(a1) && !isdigit(a1))
|
||
{
|
||
_tcscpy(sld, _T("00000001"));
|
||
return RTNORM;
|
||
}
|
||
}
|
||
_tcscpy(sld, maxStr);
|
||
sld[slen-1] = a1;
|
||
sld[slen-2] = a2;
|
||
sld[slen-3] = a3;
|
||
}
|
||
else
|
||
{
|
||
_tcscpy(sld, _T("00000001"));
|
||
return RTNORM;
|
||
}
|
||
return RTNORM;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::ConvertToDouble(const VARIANT *val, double *pRes)
|
||
{
|
||
double nVal = 0.0;
|
||
switch(V_VT(val))
|
||
{
|
||
case VT_R8:
|
||
nVal = V_R8(val);
|
||
break;
|
||
case VT_R4:
|
||
nVal = V_R4(val);
|
||
break;
|
||
case VT_I4:
|
||
nVal = V_I4(val);
|
||
break;
|
||
case VT_I2:
|
||
nVal = V_I2(val);
|
||
break;
|
||
case VT_BSTR:
|
||
{
|
||
CString csVal = (LPCTSTR)_bstr_t(val);//V_BSTR(val);
|
||
nVal = _tstof(csVal);
|
||
break;
|
||
}
|
||
default:
|
||
return Acad::eInvalidInput;
|
||
}
|
||
*pRes = nVal;
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::ConvertToInteger(const VARIANT *val, int *pInt)
|
||
{
|
||
int nVal = 0;
|
||
switch(V_VT(val))
|
||
{
|
||
case VT_R8:
|
||
nVal = AS_INT(V_R8(val));
|
||
break;
|
||
case VT_R4:
|
||
nVal = AS_INT(V_R4(val));
|
||
break;
|
||
case VT_I4:
|
||
nVal = V_I4(val);
|
||
break;
|
||
case VT_I2:
|
||
nVal = V_I2(val);
|
||
break;
|
||
case VT_BSTR:
|
||
{
|
||
CString csVal = (LPCTSTR)_bstr_t(val);//V_BSTR(val);
|
||
nVal = AS_INT(_tstof(csVal));
|
||
break;
|
||
}
|
||
default:
|
||
return Acad::eInvalidInput;
|
||
}
|
||
*pInt = nVal;
|
||
return Acad::eOk;
|
||
}
|
||
|
||
// 把可行的曲线转换为AcDbPolyline
|
||
AcDbPolyline * XExport::AsPolyline(const AcDbEntity *pEntity)
|
||
{
|
||
AcDbPolyline *pline = NULL;
|
||
if (pEntity->isKindOf(AcDbLine::desc()))
|
||
{
|
||
AcDbLine *pLine = AcDbLine::cast(pEntity);
|
||
pline = new AcDbPolyline;
|
||
XPrivate::AsPolyline(*pLine, *pline);
|
||
}
|
||
else if (pEntity->isKindOf(AcDbArc::desc()))
|
||
{ //取弧上的三点进行变换,再构成弧
|
||
AcDbArc *pArc = AcDbArc::cast(pEntity);
|
||
pline = new AcDbPolyline;
|
||
XPrivate::AsPolyline(*pArc, *pline);
|
||
}
|
||
else if (pEntity->isKindOf(AcDbCircle::desc()))
|
||
{ //维持圆心和X+象限点满足变换规律
|
||
AcDbCircle *pCir = AcDbCircle::cast(pEntity);
|
||
pline = new AcDbPolyline;
|
||
XPrivate::AsPolyline(*pCir, *pline);
|
||
}
|
||
else if (pEntity->isKindOf(AcDbPolyline::desc()))
|
||
{
|
||
pline = (AcDbPolyline *)pEntity->clone();
|
||
}
|
||
else if (pEntity->isKindOf(AcDb2dPolyline::desc()))
|
||
{
|
||
AcDb2dPolyline *pline2d = AcDb2dPolyline::cast(pEntity);
|
||
if (pline2d->polyType() == AcDb::k2dSimplePoly)
|
||
{
|
||
pline = new AcDbPolyline ;
|
||
pline-> convertFrom((AcDbEntity * &)pEntity, Adesk::kFalse);
|
||
}
|
||
}
|
||
return pline;
|
||
}
|
||
|
||
|
||
int XExport::DisplaySlide(CWnd *pWnd, const TCHAR *pszSlide)
|
||
{
|
||
XString szSlide, szLib;
|
||
if (!XExport::SplitLibraryPath(pszSlide, szLib, szSlide))
|
||
{
|
||
szSlide = pszSlide;
|
||
szLib = _T("");
|
||
}
|
||
|
||
CImageDC image;
|
||
CRect rect;
|
||
pWnd->GetClientRect(rect);
|
||
CDC *pDC = pWnd->GetDC();
|
||
image.InitDC(pDC, rect, GetAcadBackColor());
|
||
BOOL bRet = RTNORM;
|
||
if (!szLib)
|
||
{
|
||
XPathParser parser(szSlide);
|
||
XString sPath1(256), sPath2(256);
|
||
sPath1 << parser.m_sDrive << parser.m_sDir << parser.m_sFileName << _T(".SLD");
|
||
if (FindFile(sPath1, sPath2))
|
||
{
|
||
image.PaintSlide(sPath2);
|
||
}
|
||
else
|
||
{
|
||
bRet = RTERROR;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
XPathParser parser(szLib);
|
||
XString sPath1(256), sPath2(256);
|
||
sPath1 << parser.m_sDrive << parser.m_sDir << parser.m_sFileName << _T(".SLB");
|
||
if (FindFile(sPath1, sPath2))
|
||
{
|
||
XPathParser parser1(sPath2);
|
||
XString sFullPath(256);
|
||
sFullPath << parser1.m_sDrive << parser1.m_sDir << parser1.m_sFileName << _T("(") << szSlide << _T(")");
|
||
image.PaintSlide(sFullPath);
|
||
}
|
||
else
|
||
{
|
||
bRet = RTERROR;
|
||
}
|
||
}
|
||
if (!bRet)
|
||
{
|
||
image.PaintSlide(_T(""));
|
||
}
|
||
pWnd->ReleaseDC(pDC);
|
||
return bRet;
|
||
}
|
||
|
||
int XExport::FindFile(const TCHAR *szFile, TCHAR * szPath)
|
||
{
|
||
XString sFullPath(256);
|
||
memset(sFullPath,0,256);
|
||
|
||
if (ads_findfile(szFile, sFullPath) != RTNORM)
|
||
{
|
||
sFullPath << g_sAppPath << szFile;
|
||
if (FindFile(sFullPath))
|
||
{
|
||
_tcscpy(szPath, sFullPath);
|
||
}
|
||
else
|
||
{
|
||
return 0;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_tcscpy(szPath, sFullPath);
|
||
}
|
||
return 1;
|
||
}
|
||
|
||
void XExport::FindDirs(const TCHAR *sDir, XStringList &lstSubDirs)
|
||
{
|
||
XString sSubDirFilter(256);
|
||
sSubDirFilter << sDir << _T("*.*");
|
||
|
||
struct _tfinddata_t fb1;
|
||
intptr_t hand1;
|
||
hand1 = _tfindfirst(sSubDirFilter,&fb1);
|
||
if (hand1 == -1L)
|
||
{
|
||
return;
|
||
}
|
||
|
||
//XStringList lstSubDirs;
|
||
if (fb1.attrib & _A_SUBDIR)
|
||
{
|
||
if (fb1.name[0] != _T('.'))
|
||
{
|
||
lstSubDirs.Append(tstrnew(fb1.name));
|
||
}
|
||
}
|
||
|
||
while (!_tfindnext(hand1,&fb1))
|
||
{
|
||
if (fb1.attrib & _A_SUBDIR)
|
||
{
|
||
if (fb1.name[0] != _T('.'))
|
||
{
|
||
lstSubDirs.Append(tstrnew(fb1.name));
|
||
}
|
||
}
|
||
}
|
||
_findclose(hand1);
|
||
}
|
||
|
||
void XExport::FindFiles(const TCHAR *sDir, const TCHAR *sFilter, XStringList &lstRes, int bIncludeSubDir, time_t tLastModify)
|
||
{
|
||
if (sDir[_tcslen(sDir)-1] != _T('\\'))
|
||
{
|
||
return;
|
||
}
|
||
|
||
XString filter(256);
|
||
filter << sDir << sFilter;
|
||
|
||
struct _tfinddata_t fb;
|
||
intptr_t hand;
|
||
hand = _tfindfirst(filter,&fb);
|
||
if (hand == -1L)
|
||
{
|
||
;
|
||
}
|
||
else
|
||
{
|
||
if (!tLastModify || difftime(fb.time_write, tLastModify)>0)
|
||
{
|
||
if (fb.attrib & _A_SUBDIR)
|
||
{
|
||
; // It's a dir name, ignore
|
||
}
|
||
else
|
||
{
|
||
lstRes.Append(tstrnew(fb.name));
|
||
}
|
||
}
|
||
|
||
while (!_tfindnext(hand,&fb))
|
||
{
|
||
if (!tLastModify || difftime(fb.time_write, tLastModify)>0)
|
||
{
|
||
if (fb.attrib & _A_SUBDIR)
|
||
{
|
||
;
|
||
}
|
||
else
|
||
{
|
||
lstRes.Append(tstrnew(fb.name));
|
||
}
|
||
}
|
||
}
|
||
_findclose(hand);
|
||
}
|
||
|
||
if (bIncludeSubDir)
|
||
{
|
||
XStringList lstSubDirs;
|
||
XExport::FindDirs(sDir, lstSubDirs);
|
||
|
||
for (int i = 0; i<lstSubDirs.Length(); i++)
|
||
{
|
||
XStringList lstFilesInSubDir;
|
||
XString sSubDir;
|
||
sSubDir << sDir << lstSubDirs[i] << _T("\\");
|
||
XExport::FindFiles(sSubDir, sFilter, lstFilesInSubDir, bIncludeSubDir, tLastModify);
|
||
|
||
for (int n = 0; n<lstFilesInSubDir.Length(); n++)
|
||
{
|
||
XString sName(256);
|
||
sName << lstSubDirs[i] << _T("\\") << lstFilesInSubDir[n];
|
||
lstRes.Append(tstrnew(sName));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
int XExport::FindFile(const TCHAR *sDbfPath)
|
||
{
|
||
int bFind = 0;
|
||
struct _tfinddata_t fb;
|
||
intptr_t hand;
|
||
hand = _tfindfirst((TCHAR *)sDbfPath,&fb);
|
||
if (hand != -1L)
|
||
{
|
||
bFind = 1;
|
||
_findclose(hand);
|
||
}
|
||
|
||
return bFind;
|
||
}
|
||
|
||
TCHAR * XExport::CT_strnth(const TCHAR *string, int i, TCHAR *item)
|
||
{
|
||
int num = 1;
|
||
TCHAR *p1, *p2, *ip, str1[1000];
|
||
|
||
_tcscpy(str1, string);
|
||
p1 = str1;
|
||
ip = item;
|
||
|
||
if ( *p1 == _T('\0') || *p1 == _T('\n'))
|
||
{
|
||
return NULL;
|
||
}
|
||
while(*p1 != _T('\0'))
|
||
{
|
||
if (*p1 == _T(',') || *p1 == _T('\t'))
|
||
{
|
||
*p1 = _T(' ');
|
||
}
|
||
else if (*p1 == _T('\n'))
|
||
{
|
||
*p1 = _T('\0');
|
||
break;
|
||
}
|
||
p1++;
|
||
}
|
||
|
||
p1 = str1;
|
||
while(*p1 == _T(' '))
|
||
{
|
||
p1++;
|
||
}
|
||
|
||
if (i <= 1)
|
||
{
|
||
for (;(*p1 != _T(' ') && *p1 != _T('\0'));p1++)
|
||
{
|
||
*ip = *p1;
|
||
ip++;
|
||
}
|
||
*ip = _T('\0');
|
||
return item;
|
||
}
|
||
|
||
else for (p2 = p1; *p2 != _T('\0'); p2++)
|
||
{
|
||
if (*p1 == _T(' ') && *p2 != _T(' '))
|
||
{
|
||
num++;
|
||
}
|
||
|
||
if (num == i)
|
||
{
|
||
for (;*p2 != _T(' ') && *p2 != _T('\0');p2++)
|
||
{
|
||
*ip = *p2;
|
||
ip++;
|
||
}
|
||
*ip = _T('\0');
|
||
return item;
|
||
}
|
||
p1 = p2;
|
||
}
|
||
|
||
return NULL;
|
||
}
|
||
|
||
int XExport::CT_get_INIs(const TCHAR *ini_file, const TCHAR *topic, struct INI_struct **res)
|
||
{
|
||
TCHAR id[80], val[80], line_rec[200];
|
||
TCHAR tpc[80], line_r[200];
|
||
FILE *fp;
|
||
struct INI_struct *p, *last;
|
||
|
||
*res = NULL;
|
||
_tcscpy(tpc, _T("["));
|
||
_tcscat(tpc, topic);
|
||
_tcscat(tpc, _T("]"));
|
||
fp = _tfopen(ini_file, _T("r"));
|
||
if (!fp)
|
||
{
|
||
return FALSE;
|
||
}
|
||
while(!feof(fp))
|
||
{
|
||
if (_fgetts(line_rec, 199, fp) == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
if (XExport::CT_strnth(line_rec, 1, line_r) == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
if (line_r[0] == _T(';'))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (_tcsicmp(tpc, line_r) == 0)
|
||
{
|
||
while(!feof(fp))
|
||
{ //Under this topic
|
||
if (_fgetts(line_rec, 199, fp) == NULL
|
||
|| XExport::CT_strnth(line_rec, 1, line_r) == NULL
|
||
|| line_r[0] == _T(';') )
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (line_r[0] == _T('['))
|
||
{
|
||
fclose(fp);
|
||
return TRUE;
|
||
}
|
||
|
||
if (CT_ini_item(line_rec, 1, id))
|
||
{
|
||
p = (struct INI_struct *) malloc(sizeof(struct INI_struct));
|
||
if (*res == NULL)
|
||
{
|
||
*res = last = p;
|
||
}
|
||
else last->next = p;
|
||
p->next = NULL;
|
||
p->desc_handle = (TCHAR *)malloc((_tcslen(id)+1)*sizeof(TCHAR));
|
||
_tcscpy(p->desc_handle, id);
|
||
if (CT_ini_item(line_rec, 2, val))
|
||
{
|
||
p->desc_value = (TCHAR *)malloc((_tcslen(val)+1)*sizeof(TCHAR));
|
||
_tcscpy(p->desc_value, val);
|
||
}
|
||
else
|
||
{
|
||
p->desc_value = NULL;
|
||
}
|
||
last = p;
|
||
}
|
||
}
|
||
fclose(fp);
|
||
return TRUE;
|
||
}
|
||
}
|
||
|
||
fclose(fp);
|
||
return FALSE;
|
||
}
|
||
|
||
// INI tools: get description value
|
||
// ini_file -- the file *.ini
|
||
// topic -- the topic(section) name
|
||
// item_id -- the description handle
|
||
// item_value -- the result description value
|
||
// Return:
|
||
// TRUE -- normal case
|
||
// FALSE -- error detected
|
||
int XExport::CT_get_INIA(const TCHAR *ini_file, const TCHAR *topic, const TCHAR *item_id, TCHAR *item_value)
|
||
{
|
||
TCHAR id[80], val[80], line_rec[200];
|
||
TCHAR tpc[80], line_r[200];
|
||
FILE *fp;
|
||
_tcscpy(tpc, _T("["));
|
||
_tcscat(tpc, topic);
|
||
_tcscat(tpc, _T("]"));
|
||
fp = _tfopen(ini_file, _T("r"));
|
||
if (!fp)
|
||
{
|
||
return FALSE;
|
||
}
|
||
while(!feof(fp))
|
||
{
|
||
if (_fgetts(line_rec, 199, fp) == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (XExport::CT_strnth(line_rec, 1, line_r) == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (line_r[0] == _T(';'))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (_tcsicmp(tpc, line_r) == 0)
|
||
{
|
||
while(!feof(fp))
|
||
{
|
||
if (_fgetts(line_rec, 255, fp) == NULL
|
||
|| XExport::CT_strnth(line_rec, 1, line_r) == NULL
|
||
|| line_r[0] == _T(';') )
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (line_r[0] == _T('['))
|
||
{
|
||
fclose(fp);
|
||
return FALSE;
|
||
}
|
||
|
||
if (CT_ini_item(line_rec, 1, id))
|
||
{
|
||
if (_tcsicmp(item_id, id) == 0)
|
||
{
|
||
if (CT_ini_item(line_rec, 2, val))
|
||
{
|
||
_tcscpy(item_value, val);
|
||
}
|
||
else
|
||
{
|
||
_tcscpy(item_value, _T(""));
|
||
}
|
||
|
||
fclose(fp);
|
||
return TRUE;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
fclose(fp);
|
||
return FALSE;
|
||
}
|
||
|
||
// INI tools: get description value
|
||
// fp -- the file pointer of *.ini, readonly file pointer
|
||
// topic -- the topic(section) name
|
||
// item_id -- the description handle
|
||
// item_value -- the result description value
|
||
// Return:
|
||
// TRUE -- normal case
|
||
// FALSE -- error detected
|
||
int XExport::CT_get_INIB(FILE *fp, const TCHAR *topic, const TCHAR *item_id, TCHAR *item_value)
|
||
{
|
||
TCHAR id[80], val[80], line_rec[200];
|
||
TCHAR tpc[80], line_r[200];
|
||
|
||
_tcscpy(tpc, _T("["));
|
||
_tcscat(tpc, topic);
|
||
_tcscat(tpc, _T("]"));
|
||
fseek(fp, 0L, SEEK_SET);
|
||
while(!feof(fp))
|
||
{
|
||
if (_fgetts(line_rec, 199, fp) == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (XExport::CT_strnth(line_rec, 1, line_r) == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (line_r[0] == _T(';'))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (_tcsicmp(tpc, line_r) == 0)
|
||
{
|
||
while(!feof(fp))
|
||
{ //Under this topic
|
||
if (_fgetts(line_rec, 255, fp) == NULL
|
||
|| XExport::CT_strnth(line_rec, 1, line_r) == NULL
|
||
|| line_r[0] == _T(';') )
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (line_r[0] == _T('['))
|
||
{
|
||
return FALSE;
|
||
}
|
||
|
||
if (CT_ini_item(line_rec, 1, id))
|
||
{
|
||
if (_tcsicmp(item_id, id) == 0)
|
||
{
|
||
if (CT_ini_item(line_rec, 2, val))
|
||
{
|
||
_tcscpy(item_value, val);
|
||
}
|
||
else
|
||
{
|
||
_tcscpy(item_value, _T(""));
|
||
}
|
||
return TRUE;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return FALSE;
|
||
}
|
||
|
||
// INI tools: get description value
|
||
// buf -- the result buffers
|
||
// desc_handle -- the description handle
|
||
// Return:
|
||
// the description value if not NULL;
|
||
TCHAR * XExport::CT_get_INI2(const struct INI_struct *buf, const TCHAR *desc_handle)
|
||
{
|
||
const struct INI_struct *p;
|
||
|
||
for (p = buf; p != NULL; p = p->next)
|
||
{
|
||
if (_tcscmp(desc_handle, p->desc_handle) == 0)
|
||
{
|
||
return p->desc_value;
|
||
}
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
// INI tools: set description value
|
||
// ini_file -- the file *.ini
|
||
// topic -- the topic(section) name
|
||
// item_id -- the description handle
|
||
// item_value -- the description value
|
||
// Return:
|
||
// TRUE -- normal case
|
||
// FALSE -- error detected
|
||
// Note: if no such item exist in INI file, the create the item
|
||
int XExport::CT_set_INI(const TCHAR *ini_file, const TCHAR *topic, const TCHAR *item_id, const TCHAR *item_value)
|
||
{
|
||
TCHAR id[80], line_rec[200];
|
||
TCHAR tpc[80], line_r[200];
|
||
FILE *fp1, *fp2;
|
||
|
||
_tcscpy(tpc, _T("["));
|
||
_tcscat(tpc, topic);
|
||
_tcscat(tpc, _T("]"));
|
||
CT_cp_file(ini_file, _T("temp$$$$.tmp"));
|
||
fp1 = _tfopen(_T("temp$$$$.tmp"), _T("r"));
|
||
fp2 = _tfopen(ini_file, _T("w"));
|
||
if (fp1 == NULL || fp2 == NULL)
|
||
{
|
||
return 0;
|
||
}
|
||
while(!feof(fp1))
|
||
{
|
||
if (_fgetts(line_rec, 199, fp1) == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (XExport::CT_strnth(line_rec, 1, line_r) == NULL)
|
||
{
|
||
_ftprintf(fp2, _T("\n"));
|
||
continue;
|
||
}
|
||
|
||
if (_tcsicmp(tpc, line_r) == 0)
|
||
{
|
||
_ftprintf(fp2, line_rec);
|
||
while(!feof(fp1))
|
||
{ //Under this topic
|
||
if (_fgetts(line_rec, 199, fp1) == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
if (XExport::CT_strnth(line_rec, 1, line_r) == NULL)
|
||
{
|
||
_ftprintf(fp2, _T("\n"));
|
||
continue;
|
||
}
|
||
if (line_r[0] == _T('['))
|
||
{ // Add
|
||
_ftprintf(fp2, _T("%s = %s\n"), item_id, item_value);
|
||
_ftprintf(fp2, line_rec);
|
||
break;
|
||
}
|
||
if (CT_ini_item(line_rec, 1, id) == TRUE)
|
||
{ // replace
|
||
if (_tcsicmp(item_id, id) == 0)
|
||
{
|
||
_ftprintf(fp2, _T("%s = %s\n"), item_id, item_value);
|
||
break;
|
||
}
|
||
}
|
||
_ftprintf(fp2, line_rec);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_ftprintf(fp2, line_rec);
|
||
}
|
||
|
||
}
|
||
fclose(fp1);
|
||
fclose(fp2);
|
||
_tremove(_T("temp$$$$.tmp"));
|
||
return TRUE;
|
||
}
|
||
|
||
// INI tools: set sereral descriptions under a topic
|
||
// ini_file -- the file *.ini
|
||
// topic -- the topic(section) name
|
||
// item_id -- the description handle
|
||
// item_value -- the description value
|
||
// Return:
|
||
// TRUE -- normal case
|
||
// FALSE -- error detected
|
||
// Note: if no such item exist in INI file, the create the item
|
||
int XExport::CT_set_INIB(const TCHAR *ini_file, const TCHAR *topic, const struct INI_struct *desc)
|
||
{
|
||
TCHAR id[80], line_rec[200];
|
||
TCHAR tpc[80], line_r[200];
|
||
FILE *fp1, *fp2;
|
||
const struct INI_struct *ip;
|
||
int rep_tag;
|
||
|
||
_tcscpy(tpc, _T("["));
|
||
_tcscat(tpc, topic);
|
||
_tcscat(tpc, _T("]"));
|
||
CT_cp_file(ini_file, _T("temp$$$$.tmp"));
|
||
fp1 = _tfopen(_T("temp$$$$.tmp"), _T("r"));
|
||
fp2 = _tfopen(ini_file, _T("w"));
|
||
if (fp1 == NULL || fp2 == NULL)
|
||
{
|
||
return 0;
|
||
}
|
||
while(!feof(fp1))
|
||
{
|
||
if (_fgetts(line_rec, 199, fp1) == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
if (XExport::CT_strnth(line_rec, 1, line_r) == NULL)
|
||
{
|
||
_ftprintf(fp2, _T("\n"));
|
||
continue;
|
||
}
|
||
|
||
if (_tcsicmp(tpc, line_r) == 0)
|
||
{ // 找到 Topic
|
||
_ftprintf(fp2, line_rec);
|
||
for (ip = desc; ip != NULL; ip = ip->next)
|
||
{
|
||
_ftprintf(fp2, _T("%s = %s\n"), ip->desc_handle, ip->desc_value);
|
||
}
|
||
while(!feof(fp1))
|
||
{ //Under this topic
|
||
if (_fgetts(line_rec, 199, fp1) == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (XExport::CT_strnth(line_rec, 1, line_r) == NULL)
|
||
{
|
||
_ftprintf(fp2, _T("\n"));
|
||
continue;
|
||
}
|
||
|
||
if (line_r[0] == _T('['))
|
||
{
|
||
_ftprintf(fp2, line_rec);
|
||
break; // End This Topic and start another topic
|
||
}
|
||
rep_tag = 0;
|
||
if (CT_ini_item(line_rec, 1, id) == TRUE)
|
||
{
|
||
for (ip = desc; ip != NULL; ip = ip->next)
|
||
{
|
||
if (_tcsicmp(ip->desc_handle, id) == 0)
|
||
{
|
||
rep_tag = 1;
|
||
break;
|
||
}
|
||
}
|
||
if (rep_tag)
|
||
{
|
||
continue; // has been replaced, skip it
|
||
}
|
||
}
|
||
_ftprintf(fp2, line_rec); // keep it
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_ftprintf(fp2, line_rec); // Continue Writing
|
||
}
|
||
}
|
||
fclose(fp1);
|
||
fclose(fp2);
|
||
_tremove(_T("temp$$$$.tmp"));
|
||
return TRUE;
|
||
}
|
||
|
||
// 释放 INI描述链表
|
||
int XExport::CT_free_INIs(struct INI_struct *res)
|
||
{
|
||
struct INI_struct *p = res, *nextp;
|
||
while(p)
|
||
{
|
||
nextp = p->next;
|
||
free(p->desc_handle);
|
||
free(p->desc_value);
|
||
free(p);
|
||
p = nextp;
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
// Get ini item for string like '<i1 >= <i2>,<i3>...'
|
||
// string -- the full description item
|
||
// i -- the subitem index based on 1
|
||
// item -- the result subitem
|
||
// Return:
|
||
// TRUE -- normal case
|
||
// FALSE -- error detected
|
||
int XExport::CT_ini_item(const TCHAR *string, int i, TCHAR *item)
|
||
{
|
||
int c = _T('=');
|
||
TCHAR *ip, str1[200];
|
||
_tcscpy(str1, string);
|
||
ip = str1;
|
||
while(*ip)
|
||
{
|
||
if (*ip == _T('\n'))
|
||
{
|
||
*ip = _T('\0');
|
||
break;
|
||
}
|
||
ip++;
|
||
}
|
||
|
||
ip = _tcschr(str1, c);
|
||
if (ip)
|
||
{
|
||
if (i == 1)
|
||
{
|
||
*ip = _T('\0');
|
||
_tcscpy(item, str1);
|
||
}
|
||
else
|
||
{
|
||
ip++;
|
||
_tcscpy(item, ip);
|
||
}
|
||
return TRUE;
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
// Copy file from f1 to f2
|
||
// Return:
|
||
// TRUE -- normal case
|
||
// FALSE -- error detected
|
||
int XExport::CT_cp_file(const TCHAR *f1, const TCHAR *f2)
|
||
{
|
||
FILE *fp1,*fp2;
|
||
long fsize;
|
||
long cursize;
|
||
TCHAR buf[501];
|
||
if ((fp1 = _tfopen(f1,_T("rb"))) == NULL)
|
||
{
|
||
return FALSE;
|
||
}
|
||
//remove(f2);
|
||
fp2 = _tfopen(f2,_T("wb"));
|
||
if (!fp2)
|
||
{
|
||
fclose(fp1);
|
||
return FALSE;
|
||
}
|
||
|
||
fseek(fp1,0L,2);
|
||
fsize = ftell(fp1);
|
||
fseek(fp1,0L,0);
|
||
while (1)
|
||
{
|
||
cursize = ftell(fp1);
|
||
long size = cursize+500*sizeof(TCHAR);
|
||
if (size>fsize)
|
||
{
|
||
fread(buf, sizeof(TCHAR), (int)(fsize-cursize),fp1);
|
||
fwrite(buf,sizeof(TCHAR), (int)(fsize-cursize),fp2);
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
fread(buf,sizeof(TCHAR),500,fp1);
|
||
fwrite(buf,sizeof(TCHAR),500,fp2);
|
||
}
|
||
}
|
||
fclose(fp1);
|
||
fclose(fp2);
|
||
return TRUE;
|
||
}
|
||
|
||
// translate a integer to a string, such as 3 --> _T("3").
|
||
// num -- source integer
|
||
// nn -- object string
|
||
// return:
|
||
// NULL -- error detected
|
||
// other -- normal case
|
||
int XExport::CT_itoa(int num, TCHAR *nn)
|
||
{
|
||
int r, dec;
|
||
TCHAR s, str[10], ss[10];
|
||
|
||
if (num < 0)
|
||
{
|
||
num = abs(num);
|
||
_tcscpy(nn, _T("-"));
|
||
}
|
||
else
|
||
{
|
||
nn[0] = _T('\0');
|
||
}
|
||
|
||
r = num % 10;
|
||
dec = num / 10;
|
||
s = 48 + r;
|
||
|
||
str[0] = s;
|
||
str[1] = _T('\0');
|
||
while(dec)
|
||
{
|
||
r = dec % 10;
|
||
dec = dec / 10;
|
||
s = 48 + r;
|
||
ss[0] = s;
|
||
ss[1] = _T('\0');
|
||
_tcscat(ss,str);
|
||
_tcscpy(str,ss);
|
||
}
|
||
_tcscat(nn, str);
|
||
return TRUE;
|
||
}
|
||
|
||
// 改变字符串长度
|
||
// str -- the object string
|
||
// len -- the expected length
|
||
// Return:
|
||
// TRUE -- normal case
|
||
// FALSE -- error detected
|
||
int XExport::CT_stradj(TCHAR *str, int len)
|
||
{
|
||
TCHAR *p;
|
||
int i, slen, dlen;
|
||
|
||
slen = _tcslen(str);
|
||
dlen = len - slen;
|
||
p = str + slen;
|
||
if (dlen > 0)
|
||
{
|
||
for (i = 0; i < dlen; i++)
|
||
{
|
||
*p = _T(' ');
|
||
p++;
|
||
}
|
||
*p = _T('\0');
|
||
}
|
||
else
|
||
{
|
||
*(p - dlen) = _T('\0');
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
// 改变向量格式从点格式到长度,角度格式
|
||
// vt -- 向量
|
||
// direction -- 向量角度(弧度单位)
|
||
// dist -- 向量长度
|
||
// 返回值:
|
||
// TRUE -- 正常
|
||
// FALSE -- 错误
|
||
int XExport::CT_XYZtoRsita(const ads_point vt, double *direct, double *dist)
|
||
{
|
||
*dist = sqrt(vt[0] * vt[0] + vt[1] * vt[1]);
|
||
if (fabs(vt[0] / (*dist)) < 1.0E-4)
|
||
{
|
||
if (vt[1] > 0.0)
|
||
{
|
||
*direct = PI / 2.0;
|
||
}
|
||
else
|
||
{
|
||
*direct = 1.5 * PI;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
*direct = atan(vt[1] / vt[0]);
|
||
if (vt[0] < 0.0)
|
||
{
|
||
*direct += PI; //2,4象限
|
||
}
|
||
|
||
if (*direct < -1.0E-6)
|
||
{
|
||
*direct += 2.0 * PI;
|
||
}
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
// 三点确定的平面法向量
|
||
// pt1, pt2, pt3 -- 决定一个平面的三个点
|
||
// result -- 平面向量
|
||
int XExport::CT_vector_plan3p(const ads_point pt1, const ads_point pt2, const ads_point pt3, ads_vector result)
|
||
{
|
||
double a1, a2, a3, b1, b2, b3;
|
||
|
||
a1 = pt2[0] - pt1[0];
|
||
a2 = pt2[1] - pt1[1];
|
||
a3 = pt2[2] - pt1[2];
|
||
|
||
b1 = pt3[0] - pt1[0];
|
||
b2 = pt3[1] - pt1[1];
|
||
b3 = pt3[2] - pt1[2];
|
||
|
||
result[0] = a2 * b3 - a3 * b2;
|
||
result[1] = a3 * b1 - a1 * b3;
|
||
result[2] = a1 * b2 - a2 * b1;
|
||
|
||
if (fabs(result[0]) < 0.00001 && fabs(result[1]) < 0.00001
|
||
&& fabs(result[2]) < 0.00001)
|
||
{
|
||
return FALSE;
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
// 由点和法向量计算平面的标准方程
|
||
// 参数: pt--点; vt--向量
|
||
// 结果: plan--存储平面的标准参数
|
||
// 返回值:
|
||
int XExport::CT_plan_equation(const ads_point pt, const ads_vector vt, struct plan_para *plan)
|
||
{
|
||
plan->A = vt[0];
|
||
plan->B = vt[1];
|
||
plan->C = vt[2];
|
||
plan->D = 0.0 - (vt[0] * pt[0] + vt[1] * pt[1] + vt[2] * pt[2]);
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
// 求线与平面的交点
|
||
// 参数: pt1, pt2 -- 线的两个端点
|
||
// plan -- 平面
|
||
// 结果: result -- 交点
|
||
int XExport::CT_inter_line_plan1(const ads_point pt1, const ads_point pt2, const struct plan_para *plan, ads_point result)
|
||
{
|
||
double l, m, n, t;
|
||
double mid_var1, mid_var2;
|
||
|
||
l = pt2[0] - pt1[0];
|
||
m = pt2[1] - pt1[1];
|
||
n = pt2[2] - pt1[2];
|
||
|
||
mid_var1 = l * (plan->A) + m * (plan->B) + n * (plan->C);
|
||
if (fabs(mid_var1) < 0.000001)
|
||
{
|
||
return FALSE;
|
||
}
|
||
|
||
mid_var2 = (plan->D) + pt1[0] * (plan->A) + pt1[1] * (plan->B) + pt1[2] * (plan->C);
|
||
t = 0.0 - mid_var2 / mid_var1;
|
||
|
||
result[0] = pt1[0] + l * t;
|
||
result[1] = pt1[1] + m * t;
|
||
result[2] = pt1[2] + n * t;
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
// 求线与平面的交点
|
||
// 参数: pt1 -- 线上一点
|
||
// vt -- 线的方向向量
|
||
// plan -- 平面
|
||
// 结果: result -- 交点
|
||
int XExport::CT_inter_line_plan2(const ads_point pt1, const ads_vector vt, const struct plan_para *plan, ads_point result)
|
||
{
|
||
double l, m, n, t;
|
||
double mid_var1, mid_var2;
|
||
|
||
// 直线的参数方程
|
||
l = vt[0];
|
||
m = vt[1];
|
||
n = vt[2];
|
||
|
||
mid_var1 = l * (plan->A) + m * (plan->B) + n * (plan->C);
|
||
if (fabs(mid_var1) < 0.000001)
|
||
{
|
||
return FALSE;
|
||
}
|
||
|
||
mid_var2 = (plan->D) + pt1[0] * (plan->A) + pt1[1] * (plan->B) + pt1[2] * (plan->C);
|
||
t = 0.0 - mid_var2/mid_var1;
|
||
|
||
result[0] = pt1[0] + l * t;
|
||
result[1] = pt1[1] + m * t;
|
||
result[2] = pt1[2] + n * t;
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
// 点到平面的投影
|
||
// 参数: pt -- 点
|
||
// plan -- 平面
|
||
// 结果: qt -- 投影点
|
||
int XExport::CT_point_prj_plan(const ads_point pt, const struct plan_para *plan, ads_point qt)
|
||
{
|
||
ads_vector vt;
|
||
|
||
vt[0] = plan->A;
|
||
vt[1] = plan->B;
|
||
vt[2] = plan->C;
|
||
|
||
return XExport::CT_inter_line_plan2(pt, vt, plan, qt);
|
||
}
|
||
|
||
// 求两向量的夹角
|
||
double XExport::CT_VectorAngle(ads_vector pt1, ads_vector pt2)
|
||
{
|
||
double a, b, c, d, ang;
|
||
a = pt1[0] * pt1[0] + pt1[2] * pt1[2] + pt1[1] * pt1[1];
|
||
b = pt2[0] * pt2[0] + pt2[2] * pt2[2] + pt2[1] * pt2[1];
|
||
c = CT_VectorDotPlus(pt1,pt2);
|
||
|
||
if ((a <= 0.0001) || (b <= 0.0001))
|
||
{
|
||
return 0.0;
|
||
}
|
||
|
||
d = c / (sqrt(a * b));
|
||
|
||
if (CT_RealEqual(d, 1.0, 1E-5))
|
||
{
|
||
return 0.0;
|
||
}
|
||
else if (CT_RealEqual(d, -1.0, 1E-5))
|
||
{
|
||
return PI;
|
||
}
|
||
|
||
ang = acos(d);
|
||
|
||
return ang;
|
||
}
|
||
|
||
int XExport::CT_Inverse_mat(double *A, int order, double ep)
|
||
{
|
||
int i, j, k, l, i2, j2, k1, k2, *me, *mf;
|
||
double y, w, *b, *c;
|
||
|
||
if ((b = (double *)malloc(order * sizeof(double))) == NULL)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
if ((c = (double *)malloc(order * sizeof(double))) == NULL)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
if ((me = (int *)malloc(order * sizeof(int))) == NULL)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
if ((mf = (int *)malloc(order * sizeof(int))) == NULL)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
int nRet = TRUE;
|
||
for (k = 0; k < order; k++)
|
||
{
|
||
for (i = k, y = 0; i < order; i++)
|
||
{
|
||
for (j = k; j < order; j++)
|
||
{
|
||
if (fabs(A[j * order + i]) > fabs(y))
|
||
{
|
||
y = A[j * order + i];
|
||
i2 = i;
|
||
j2 = j;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (fabs(y) < ep)
|
||
{
|
||
nRet = FALSE;
|
||
break;
|
||
}
|
||
|
||
if (i2 != k)
|
||
{
|
||
for (j = 0; j < order; j++)
|
||
{
|
||
w = A[j * order + i2];
|
||
A[j * order + i2] = A[j * order + k];
|
||
A[j * order + k] = w;
|
||
}
|
||
}
|
||
|
||
if (j2 != k)
|
||
{
|
||
for (j = 0; j < order; j++)
|
||
{
|
||
w = A[j2 * order + j];
|
||
A[j2 * order + j] = A[k * order + j];
|
||
A[k * order + j] = w;
|
||
}
|
||
}
|
||
|
||
me[k] = i2;
|
||
mf[k] = j2;
|
||
|
||
for (j = 0; j < order; j++)
|
||
{
|
||
if (j == k)
|
||
{
|
||
b[j] = 1.0 / y;
|
||
c[j] = 1.0;
|
||
}
|
||
else
|
||
{
|
||
b[j] = -A[j * order + k] / y;
|
||
c[j] = A[k * order + j];
|
||
}
|
||
|
||
A[k * order + j] = 0.0;
|
||
A[j * order + k] = 0.0;
|
||
}
|
||
|
||
for (i = 0; i < order; i++)
|
||
{
|
||
for (j = 0; j < order; j++)
|
||
{
|
||
A[j * order + i] = A[j * order + i] + c[i] * b[j];
|
||
}
|
||
}
|
||
}
|
||
|
||
for (l = 0; l < order; l++)
|
||
{
|
||
k = order - l - 1;
|
||
k1 = me[k];
|
||
k2 = mf[k];
|
||
|
||
if (k1 != k)
|
||
{
|
||
for (i = 0; i < order; i++)
|
||
{
|
||
w = A[k1 * order + i];
|
||
A[k1 * order + i] = A[k * order + i];
|
||
A[k * order + i] = w;
|
||
}
|
||
}
|
||
|
||
if (k2 != k)
|
||
{
|
||
for (j = 0; j < order; j++)
|
||
{
|
||
w = A[j * order + k2];
|
||
A[j * order + k2] = A[j * order + k];
|
||
A[j * order + k] = w;
|
||
}
|
||
}
|
||
}
|
||
|
||
free(b);
|
||
free(c);
|
||
free(me);
|
||
free(mf);
|
||
|
||
return nRet;
|
||
}
|
||
|
||
// change a string to alphabet string
|
||
// str -- the source string
|
||
// res -- the result string
|
||
// res_size -- the size of the result string buffer
|
||
// Return:
|
||
// TRUE -- normal case
|
||
// FALSE -- error detected
|
||
int XExport::CT_alphabet_str(const TCHAR *str, TCHAR *res, int res_size)
|
||
{
|
||
int i;
|
||
int nStrLen = _tcslen(str);
|
||
for (i = 0; i<nStrLen; i++)
|
||
{
|
||
if (i == res_size)
|
||
{
|
||
res[res_size-1] = _T('\0');
|
||
return TRUE;
|
||
}
|
||
res[i] = abs(str[i]%52);
|
||
if (res[i]<26)
|
||
{
|
||
res[i] = res[i] + 65; // toloupper
|
||
}
|
||
else
|
||
{
|
||
res[i] = res[i] + 71; // tolower
|
||
}
|
||
}
|
||
res[i] = _T('\0');
|
||
return TRUE;
|
||
}
|
||
|
||
// 清除字符数组
|
||
// strbeg -- 字符缓冲区的起始地址
|
||
// strsize -- 要清零的缓冲区的大小
|
||
void XExport::CT_clear_strbuf(char *strbeg, int strsize)
|
||
{
|
||
int i;
|
||
for (i = 0; i<strsize; i++)
|
||
{
|
||
strbeg[i] = 0;
|
||
}
|
||
}
|
||
|
||
// 去除文件名的路径, (并不改变 FileName串)
|
||
// 返回指向文件名的位置,
|
||
// 如: FileName = _T("d:\abc\exam.dat"), 返回 _T("exam.dat")
|
||
TCHAR * XExport::CT_NoPath_FileName(TCHAR *FileName)
|
||
{
|
||
int i;
|
||
for (i = _tcslen(FileName)-1; i >= 0; i--)
|
||
{
|
||
if (FileName[i] == _T('\\'))
|
||
{
|
||
return &FileName[i+1];
|
||
}
|
||
}
|
||
return FileName;
|
||
}
|
||
|
||
|
||
void XExport::get_matrix(ads_point pt1,ads_point pt2,ads_point pt3, ads_matrix tran_mt)
|
||
{
|
||
double vsin,vcos,c;
|
||
ads_point t_pt2,t_pt3,r1_pt2,r1_pt3,r2_pt3,pt10,pt20,pt30;
|
||
ads_matrix Mt,Mrx1,Mrx2,Mrz,M1,M2;
|
||
|
||
Cpoint(pt10,pt1);
|
||
Cpoint(pt20,pt2);
|
||
Cpoint(pt30,pt3);
|
||
|
||
AT_InitTranMat(Mt, 0.0 - pt10[X], 0.0 - pt10[Y], 0.0 - pt10[Z]);
|
||
AT_xformpt(Mt,pt20,t_pt2);
|
||
AT_xformpt(Mt,pt30,t_pt3);
|
||
|
||
c = sqrt(t_pt2[Y] * t_pt2[Y] + t_pt2[Z] * t_pt2[Z]);
|
||
if (c > 0.01)
|
||
{
|
||
vsin = 0.0 - t_pt2[Z] / c;
|
||
vcos = t_pt2[Y] / c;
|
||
rota_X_init(Mrx1,vsin,vcos);
|
||
}
|
||
else
|
||
{
|
||
AT_InitIdenMat(Mrx1);
|
||
}
|
||
|
||
AT_multiply_matrix(Mrx1,Mt,M1);
|
||
AT_xformpt(Mrx1,t_pt2,r1_pt2);
|
||
AT_xformpt(Mrx1,t_pt3,r1_pt3);
|
||
|
||
c = sqrt(r1_pt2[X] * r1_pt2[X] + r1_pt2[Y] * r1_pt2[Y]);
|
||
if (c > 0.01)
|
||
{
|
||
vsin = 0.0 - r1_pt2[Y] / c;
|
||
vcos = r1_pt2[X] / c;
|
||
rota_Z_init(Mrz,vsin,vcos);
|
||
}
|
||
else
|
||
{
|
||
AT_InitIdenMat(Mrz);
|
||
}
|
||
|
||
AT_multiply_matrix(Mrz,M1,M2);
|
||
AT_xformpt(Mrz,r1_pt3,r2_pt3);
|
||
|
||
c = sqrt(r2_pt3[Y] * r2_pt3[Y] + r2_pt3[Z] * r2_pt3[Z]);
|
||
if (c > 0.01)
|
||
{
|
||
vsin = 0.0 - r2_pt3[Z] / c;
|
||
vcos = r2_pt3[Y] / c;
|
||
rota_X_init(Mrx2,vsin,vcos);
|
||
}
|
||
else
|
||
{
|
||
AT_InitIdenMat(Mrx2);
|
||
}
|
||
|
||
AT_multiply_matrix(Mrx2,M2,tran_mt);
|
||
}
|
||
|
||
|
||
BOOL XExport::IsWindowsNT()
|
||
{
|
||
OSVERSIONINFO osVer;
|
||
osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||
VERIFY(GetVersionEx(&osVer) == TRUE);
|
||
return (osVer.dwPlatformId == VER_PLATFORM_WIN32_NT);
|
||
}
|
||
|
||
extern void xdRemoveDupLines(PickSet &ss);
|
||
int XExport::HandleCurveDup(PickSet &ss)
|
||
{
|
||
xdRemoveDupLines(ss);
|
||
init_cir(ss);
|
||
init_arc(ss);
|
||
ads_redraw(NULL,0);
|
||
return RTNORM;
|
||
}
|
||
|
||
void XExport::MatrixMultiply(ads_matrix result, ads_matrix m1, ads_matrix m2, ...)
|
||
{
|
||
ads_matrix mat1, mat2, res;
|
||
memcpy(mat1, m1, sizeof(ads_matrix));
|
||
memcpy(mat2, m2, sizeof(ads_matrix));
|
||
AT_multiply_matrix(m1, m2, result);
|
||
memcpy(res, result, sizeof(ads_matrix));
|
||
va_list vlst;
|
||
va_start(vlst, m2);
|
||
while(1)
|
||
{
|
||
MatrixPointer r = va_arg(vlst, MatrixPointer);
|
||
if (!r)
|
||
{
|
||
break;
|
||
}
|
||
|
||
ads_matrix mat;
|
||
memcpy(mat, result, sizeof(ads_matrix));
|
||
AT_multiply_matrix(mat, r, result);
|
||
}
|
||
va_end(vlst);
|
||
return;
|
||
}
|
||
|
||
int XExport::GetInsertMatrix(const Entity & e, ads_matrix result)
|
||
{
|
||
Entity insertEnt = e;
|
||
if (insertEnt.Is(_T("INSERT")) || insertEnt.Is(_T("AEC_BLOCK_INSERT")))
|
||
{
|
||
OPENOBJ_BEGIN(insertEnt,AcDb::kForRead,AcDbBlockReference,pBlock)
|
||
if (pBlock != NULL)
|
||
{
|
||
AsAdsMatrix(pBlock->blockTransform(),result);
|
||
return RTNORM;
|
||
}
|
||
OPENOBJ_END()
|
||
}
|
||
|
||
if (!insertEnt.Is(_T("AEC_MVINSERT")))
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
XPoint insPt;
|
||
double rot, sx = 1, sy = 1, sz = 1;
|
||
insertEnt.GetData(10, insPt); insertEnt.GetData(50, &rot);
|
||
insertEnt.GetData(41, &sx); insertEnt.GetData(42, &sy); insertEnt.GetData(43, &sz);
|
||
|
||
TCHAR blk[80];
|
||
insertEnt.GetData(2, blk);
|
||
|
||
XBlockTable blkTab(blk);
|
||
// XPoint mv = insPt-blkTab.base;
|
||
// 先移动base到原点, Scale, Rotation, 再平移到insPt
|
||
ads_matrix mvMat1 = {
|
||
{1, 0, 0, -blkTab.base.x},
|
||
{0, 1, 0, -blkTab.base.y},
|
||
{0, 0, 1, -blkTab.base.z},
|
||
{0, 0, 0, 1},
|
||
};
|
||
ads_matrix sclMat = {
|
||
{sx, 0, 0, 0},
|
||
{0, sy, 0, 0},
|
||
{0, 0, sz, 0},
|
||
{0, 0, 0, 1},
|
||
};
|
||
ads_matrix rotMat = {
|
||
{cos(rot), -sin(rot), 0, 0},
|
||
{sin(rot), cos(rot), 0, 0},
|
||
{0, 0, 1, 0},
|
||
{0, 0, 0, 1},
|
||
};
|
||
|
||
ads_matrix mvMat2 = {
|
||
{1, 0, 0, insPt.x},
|
||
{0, 1, 0, insPt.y},
|
||
{0, 0, 1, insPt.z},
|
||
{0, 0, 0, 1},
|
||
};
|
||
|
||
XExport::MatrixMultiply(result, mvMat2, rotMat, sclMat, mvMat1, NULL);
|
||
return RTNORM;
|
||
}
|
||
|
||
int XExport::GetCirDivNum(double r, double h)
|
||
{
|
||
ASSERT(r>0.0 && h>0.0);
|
||
double dVal = 1.0-h/r;
|
||
if (dVal<1.0E-6)
|
||
{
|
||
return 1;
|
||
}
|
||
double nArgCos = acos(dVal);
|
||
int nVal = AS_INT(PI/nArgCos);
|
||
if (nVal<1)
|
||
{
|
||
nVal = 1;
|
||
}
|
||
else if (nVal > g_nMaxCirDivNum)
|
||
{
|
||
nVal = g_nMaxCirDivNum;
|
||
}
|
||
|
||
return nVal;
|
||
}
|
||
|
||
int XExport::ACmpLabel(const char* sLabel1,const char* sLabel2)
|
||
{
|
||
AString s1(sLabel1),s2(sLabel2);
|
||
AString sName1(s1.Length()),sName2(s2.Length());
|
||
AString sDigit1(s1.Length()),sDigit2(s2.Length());
|
||
|
||
long len1 = s1.Length();
|
||
for (long i = 0;i<len1;i++)
|
||
{
|
||
char c = s1.GetAt(i);
|
||
if (c >= '0'&&c <= '9')
|
||
{//数字
|
||
sDigit1 << c;
|
||
}
|
||
else
|
||
{//字符
|
||
sName1 << c;
|
||
if (c<0)
|
||
{//汉字占两位
|
||
sName1 << s1[++i];
|
||
}
|
||
}
|
||
}
|
||
|
||
long len2 = s2.Length();
|
||
for (int i = 0;i<len2;i++)
|
||
{
|
||
char c = s2.GetAt(i);
|
||
if (c >= '0'&&c <= '9')
|
||
{//数字
|
||
sDigit2 << c;
|
||
}
|
||
else//字符
|
||
{
|
||
sName2 << c;
|
||
if (c<0)
|
||
{//汉字占两位
|
||
sName2<<s2[++i];
|
||
}
|
||
}
|
||
}
|
||
int iRet = strcmp(sName1,sName2);
|
||
if (iRet<0)
|
||
{
|
||
return -1;
|
||
}
|
||
else if (iRet>0)
|
||
{
|
||
return 1;
|
||
}
|
||
else
|
||
{
|
||
int num1 = atoi(sDigit1),num2 = atoi(sDigit2);
|
||
if (num1<num2)
|
||
{
|
||
return -1;
|
||
}
|
||
else if (num1>num2)
|
||
{
|
||
return 1;
|
||
}
|
||
else
|
||
{
|
||
return 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
int XExport::UCmpLabel(const wchar_t* sLabel1,const wchar_t* sLabel2)
|
||
{
|
||
UString s1(sLabel1),s2(sLabel2);
|
||
UString sName1(s1.Length()),sName2(s2.Length());
|
||
UString sDigit1(s1.Length()),sDigit2(s2.Length());
|
||
|
||
long len1 = s1.Length();
|
||
for (long i = 0;i<len1;i++)
|
||
{
|
||
wchar_t c = s1.GetAt(i);
|
||
if (c >= '0'&&c <= '9')
|
||
{//数字
|
||
sDigit1<<c;
|
||
}
|
||
else//字符
|
||
{
|
||
sName1<<c;
|
||
if (c<0)
|
||
{//汉字占两位
|
||
sName1<<s1[++i];
|
||
}
|
||
}
|
||
}
|
||
|
||
long len2 = s2.Length();
|
||
for (int i = 0;i<len2;i++)
|
||
{
|
||
wchar_t c = s2.GetAt(i);
|
||
if (c >= '0'&&c <= '9')
|
||
{//数字
|
||
sDigit2<<c;
|
||
}
|
||
else//字符
|
||
{
|
||
sName2<<c;
|
||
if (c<0)
|
||
{//汉字占两位
|
||
sName2<<s2[++i];
|
||
}
|
||
}
|
||
}
|
||
int iRet = wcscmp(sName1,sName2);
|
||
if (iRet<0)
|
||
{
|
||
return -1;
|
||
}
|
||
else if (iRet>0)
|
||
{
|
||
return 1;
|
||
}
|
||
else
|
||
{
|
||
int num1 = _wtoi(sDigit1),num2 = _wtoi(sDigit2);
|
||
if (num1<num2)
|
||
{
|
||
return -1;
|
||
}
|
||
else if (num1>num2)
|
||
{
|
||
return 1;
|
||
}
|
||
else
|
||
{
|
||
return 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
char * XExport::strnew(const char *src)
|
||
{
|
||
if (src == NULL)
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
int len = strlen(src)+1;
|
||
char *res = new char[len];
|
||
memcpy(res, src, len*sizeof(char));
|
||
return res;
|
||
}
|
||
|
||
wchar_t * XExport::wstrnew(const wchar_t *src)
|
||
{
|
||
if (src == NULL)
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
int len = wcslen(src)+1;
|
||
wchar_t *res = new wchar_t[len];
|
||
memcpy(res, src, len*sizeof(wchar_t));
|
||
return res;
|
||
}
|
||
|
||
char * XExport::strchr_new(const char *string, int c,bool bToFile)
|
||
{
|
||
char *pstr = (char*)strchr(string,c);
|
||
if (pstr == NULL)
|
||
{
|
||
return NULL;
|
||
}
|
||
char *pstr1 = NULL,*pstr2 = NULL;
|
||
pstr1 = ++pstr;
|
||
while(1)
|
||
{
|
||
pstr2 = strchr(pstr1,c);
|
||
if (pstr2 == NULL)
|
||
{
|
||
//文件名不能有系列字符
|
||
if (bToFile && c != '\\' && c != '/' && c != ':' && c != '*' && c != '?' && c != '"' && c != '<' && c != '>' && c != '|')
|
||
{
|
||
if ((pstr2 = strchr(pstr1,'\\')) != NULL)
|
||
{
|
||
return NULL;
|
||
}
|
||
}
|
||
return --pstr;
|
||
}
|
||
else
|
||
{
|
||
pstr = pstr2;
|
||
pstr1 = ++pstr;
|
||
}
|
||
}
|
||
}
|
||
|
||
wchar_t * XExport::wstrchr_new(const wchar_t *string, int c,bool bToFile)
|
||
{
|
||
wchar_t *pstr = (wchar_t*)wcschr(string,c);
|
||
if (pstr == NULL)
|
||
{
|
||
return NULL;
|
||
}
|
||
wchar_t *pstr1 = NULL,*pstr2 = NULL;
|
||
pstr1 = ++pstr;
|
||
while(1)
|
||
{
|
||
pstr2 = wcschr(pstr1,c);
|
||
if (pstr2 == NULL)
|
||
{
|
||
if (bToFile && c != '\\' && c != '/' && c != ':' && c != '*' && c != '?' && c != '"' && c != '<' && c != '>' && c != '|')
|
||
{
|
||
if ((pstr2 = wcschr(pstr1,'\\')) != NULL)
|
||
{
|
||
return NULL;
|
||
}
|
||
}
|
||
return --pstr;
|
||
}
|
||
else
|
||
{
|
||
pstr = pstr2;
|
||
pstr1 = ++pstr;
|
||
}
|
||
}
|
||
}
|
||
|
||
// General tools
|
||
// substr string from another string
|
||
// <= from < to, the dest include from but not include to
|
||
wchar_t * XExport::StrCpy(wchar_t *dest, const wchar_t *from, const wchar_t *to)
|
||
{
|
||
for (const wchar_t *p = from; p != to && *p; p++, dest++)
|
||
{
|
||
*dest = *p;
|
||
}
|
||
*dest = 0;
|
||
return dest;
|
||
}
|
||
|
||
// General tools
|
||
// substr string from another string
|
||
// <= from < to, the dest include from but not include to
|
||
char * XExport::StrCpy(char *dest, const char *from, const char *to)
|
||
{
|
||
for (const char *p = from; p != to && *p; p++, dest++)
|
||
{
|
||
*dest = *p;
|
||
}
|
||
*dest = 0;
|
||
return dest;
|
||
}
|
||
|
||
void XExport::getdate(STDate *curDate)
|
||
{
|
||
TCHAR sDate[9] = _T(""), mm[3] = _T(""), dd[3] = _T(""), yy[3] = _T("");
|
||
_tstrdate(sDate);
|
||
mm[0] = sDate[0];
|
||
mm[1] = sDate[1];
|
||
mm[2] = 0;
|
||
|
||
dd[0] = sDate[3];
|
||
dd[1] = sDate[4];
|
||
dd[2] = 0;
|
||
|
||
yy[0] = sDate[6];
|
||
yy[1] = sDate[7];
|
||
yy[2] = 0;
|
||
if (yy[0]<_T('9'))
|
||
{
|
||
if (yy[0] == _T('0'))
|
||
{
|
||
curDate->da_year = 2000+yy[1]-_T('0');
|
||
}
|
||
else
|
||
{
|
||
curDate->da_year = 2000+_ttoi(yy);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (yy[0] == _T('0'))
|
||
{
|
||
curDate->da_year = 1900+yy[1]-_T('0');
|
||
}
|
||
else
|
||
{
|
||
curDate->da_year = 1900+_ttoi(yy);
|
||
}
|
||
}
|
||
if (dd[0] == _T('0'))
|
||
{
|
||
curDate->da_day = dd[1]-_T('0');
|
||
}
|
||
else
|
||
{
|
||
curDate->da_day = _ttoi(dd);
|
||
}
|
||
if (mm[0] == _T('0'))
|
||
{
|
||
curDate->da_mon = mm[1]-_T('0');
|
||
}
|
||
else
|
||
{
|
||
curDate->da_mon = _ttoi(mm);
|
||
}
|
||
}
|
||
|
||
STDate XExport::operator - (STDate &d1, STDate &d2)
|
||
{
|
||
STDate res;
|
||
int mon = 0, year = 0;
|
||
res.da_day = d1.da_day - d2.da_day;
|
||
if (res.da_day<0)
|
||
{
|
||
res.da_day += 30;
|
||
mon = -1;
|
||
}
|
||
res.da_mon = d1.da_mon - d2.da_mon+mon;
|
||
if (res.da_mon<0)
|
||
{
|
||
res.da_mon += 12;
|
||
year = -1;
|
||
}
|
||
res.da_year = d1.da_year - d2.da_year + year;
|
||
return res;
|
||
}
|
||
|
||
//yyyymmdd
|
||
void XExport::GetDate(TCHAR *pDate)
|
||
{
|
||
STDate curDate;
|
||
XExport::getdate(&curDate);
|
||
|
||
TCHAR dd[3] = _T(""), mm[3] = _T("");
|
||
dd[2] = mm[2] = 0;
|
||
_itot(curDate.da_mon, mm, 10);
|
||
_itot(curDate.da_day, dd, 10);
|
||
if (curDate.da_mon<10)
|
||
{
|
||
mm[1] = mm[0];
|
||
mm[0] = _T('0');
|
||
}
|
||
if (curDate.da_day<10)
|
||
{
|
||
dd[1] = dd[0];
|
||
dd[0] = _T('0');
|
||
}
|
||
_stprintf(pDate, _T("%d%s%s"), curDate.da_year, mm, dd);
|
||
}
|
||
|
||
//yyyymmdd
|
||
int XExport::StrToDate(const TCHAR *strDate, STDate &res )
|
||
{
|
||
if (_tcslen(strDate) != 8)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
TCHAR year[5], mon[3], day[3];
|
||
for (int i = 0; i<4; i++)
|
||
{
|
||
year[i] = strDate[i];
|
||
}
|
||
year[4] = 0;
|
||
mon[0] = strDate[4]; mon[1] = strDate[5]; mon[3] = 0;
|
||
day[0] = strDate[6]; day[1] = strDate[7]; day[3] = 0;
|
||
res.da_year = _ttoi(year);
|
||
res.da_mon = _ttoi(mon);
|
||
res.da_day = _ttoi(day);
|
||
return RTNORM;
|
||
}
|
||
|
||
int XExport::StringToList(const TCHAR *s, XStringList &res)
|
||
{
|
||
TCHAR sWord[128] = _T("");
|
||
int i = 1;
|
||
while(XExport::CT_strnth(s, i, sWord))
|
||
{
|
||
res.Append(XExport::tstrnew(sWord));
|
||
i++;
|
||
}
|
||
return RTNORM;
|
||
}
|
||
|
||
Acad::ErrorStatus XExport::ExplodeAcis(const AcDbEntity *pEnt, AcDbVoidPtrArray &entSet)
|
||
{
|
||
XPushVar<int> dispsilh(_T("DISPSILH"), 1); //确保隐藏线不露出来
|
||
Acad::ErrorStatus es = Acad::eOk;
|
||
int nOldNum = entSet.length();
|
||
XAsdkCustomWorldDraw dc;
|
||
dc.setDeviation(_AS_SYS_UNIT(g_nCirDeviation));
|
||
|
||
// 以AsdkCustomWorldDraw调用实体的worldDraw函数并得到实体的外形(shell)数据
|
||
((AcDbEntity *)pEnt)->worldDraw(&dc);
|
||
DList<XAsdkShellData> &lstShell = dc.shellData();
|
||
for (int i = 0; i<lstShell.Length(); i++)
|
||
{
|
||
lstShell[i]->ConvertTo3DFace(entSet);
|
||
}
|
||
|
||
|
||
int nInc = entSet.length()-nOldNum;
|
||
if (nInc <= 0)
|
||
{
|
||
es = Acad::eNotApplicable;
|
||
}
|
||
return es;
|
||
}
|
||
|
||
double XExport::GetBulgeBy3Pt(const AcGePoint3d& ptStart, const AcGePoint3d& ptEnd, const AcGePoint3d& ptSample)
|
||
{
|
||
XPoint vecXDir, vecYDir;
|
||
xg_getvar(_T("UCSXDIR"), vecXDir);
|
||
xg_getvar(_T("UCSYDIR"), vecYDir);
|
||
|
||
AcGeVector3d vecZDir = vecXDir.AsAcGeVector3d().crossProduct(vecYDir.AsAcGeVector3d());
|
||
|
||
if (ptStart == ptEnd)
|
||
{
|
||
return 0.0;
|
||
}
|
||
|
||
if (ptStart == ptSample || ptEnd == ptSample)
|
||
{
|
||
return 1.0;
|
||
}
|
||
|
||
AcGeVector3d vec = ptEnd - ptStart;
|
||
vec.normalize();
|
||
vec.rotateBy(vec.angleTo(ptSample - ptStart), vecZDir);
|
||
|
||
AcGeCircArc3d arc(ptStart, ptSample, ptEnd);
|
||
AcGePlane plane(ptStart, (ptEnd - ptStart).rotateBy(PI/2.0, vecZDir));
|
||
|
||
double dLen = ptStart.distanceTo(ptEnd);
|
||
|
||
// 091118,在调用acos函数之前,首先保证参数值在[-1, 1]范围内
|
||
double dCosValue = 1 - (dLen * dLen) / (2.0 * arc.radius() * arc.radius());
|
||
if (fabs(dCosValue - 1.0) < g_globleSnap)
|
||
{
|
||
dCosValue = 1.0;
|
||
}
|
||
else if (fabs(dCosValue + 1.0) < g_globleSnap)
|
||
{
|
||
dCosValue = -1.0;
|
||
}
|
||
else if (dCosValue > 1.0 + g_globleSnap)
|
||
{
|
||
return 0.0;
|
||
}
|
||
else if (dCosValue < -1.0 - g_globleSnap)
|
||
{
|
||
return 0.0;
|
||
}
|
||
|
||
// 091118,在调用acos函数之前,首先保证参数值在[-1, 1]范围内
|
||
// 使用了三角函数公式:cos(2α) = 1 - 2*sin(α)
|
||
// double dAngle = acos(1 - (dLen * dLen) / (2.0 * arc.radius() * arc.radius()));
|
||
double dAngle = acos(dCosValue);
|
||
|
||
if (IsPointAtSameSide(plane, arc.center(), ptSample))
|
||
{
|
||
dAngle = PI * 2.0 - dAngle;
|
||
}
|
||
|
||
double dBulge = tan(dAngle / 4.0);
|
||
return ((ptStart + vec * ptSample.distanceTo(ptStart) == ptSample) ? -dBulge : dBulge);
|
||
}
|
||
|
||
// 求由一组曲线组成的边界,返回polyline线,用后需要删除
|
||
AcDbCurve* XExport::ConvertCurves2Loops(const AcDbVoidPtrArray& arpCurve, AcDbVoidPtrArray& arpResult)
|
||
{
|
||
if (arpCurve.length() <= 0)
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
AcDbCurve* pRetCurve = NULL;
|
||
|
||
AcDbVoidPtrArray arpEnt(arpCurve);
|
||
AcDbCurve* pCurve = (AcDbCurve*)arpEnt.first();
|
||
// 091111,遇到出错的情况,此类型的错误提示,也不能解决问题,推荐还是继续操作下去,减少崩溃
|
||
// assert(pCurve != NULL && pCurve->isKindOf(AcDbCurve::desc()));
|
||
if (pCurve == NULL || !pCurve->isKindOf(AcDbCurve::desc()))
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
arpEnt.removeFirst();
|
||
arpResult.append(pCurve);
|
||
if (pCurve->isClosed())
|
||
{
|
||
pRetCurve = (AcDbCurve*)pCurve->isA()->create();
|
||
CopyObject(*pCurve, *pRetCurve); // 复杂实体可能需要Deepclone
|
||
return pRetCurve;
|
||
}
|
||
|
||
AcGePoint3d ptStart, ptEnd;
|
||
pCurve->getStartPoint(ptStart);
|
||
pCurve->getEndPoint(ptEnd);
|
||
|
||
AcGePlane plane;
|
||
AcGePoint3d pt3d;
|
||
AcDbPolyline* pPline;
|
||
double dParam1, dParam2;
|
||
if (pCurve->isKindOf(AcDbLine::desc()))
|
||
{
|
||
plane.set(AcGePoint3d::kOrigin, ((AcDbLine*)pCurve)->normal());
|
||
pPline = new AcDbPolyline;
|
||
assert(pPline != NULL);
|
||
pPline->setNormal(plane.normal());
|
||
pPline->addVertexAt(0, ptStart.convert2d(plane));
|
||
pPline->addVertexAt(1, ptEnd.convert2d(plane));
|
||
}
|
||
else if (pCurve->isKindOf(AcDbArc::desc()))
|
||
{
|
||
plane.set(AcGePoint3d::kOrigin, ((AcDbArc*)pCurve)->normal());
|
||
pPline = new AcDbPolyline;
|
||
assert(pPline != NULL);
|
||
pPline->setNormal(plane.normal());
|
||
pCurve->getStartParam(dParam1);
|
||
pCurve->getEndParam(dParam2);
|
||
pCurve->getPointAtParam((dParam1 + dParam2) / 2.0, pt3d);
|
||
pPline->addVertexAt(0, ptStart.convert2d(plane), XExport::GetBulgeBy3Pt(ptStart, ptEnd, pt3d));
|
||
pPline->addVertexAt(1, ptEnd.convert2d(plane));
|
||
}
|
||
else if (pCurve->isKindOf(AcDbPolyline::desc()))
|
||
{
|
||
plane.set(AcGePoint3d::kOrigin, ((AcDbPolyline*)pCurve)->normal());
|
||
pPline = new AcDbPolyline;
|
||
assert(pPline != NULL);
|
||
CopyObject((const AcDbPolyline&)*pCurve, *pPline);
|
||
}
|
||
else
|
||
{
|
||
pRetCurve = (AcDbCurve*)pCurve->isA()->create();
|
||
CopyObject(*pCurve, *pRetCurve);
|
||
return pRetCurve;
|
||
}
|
||
|
||
pRetCurve = pPline;
|
||
|
||
int iLen;
|
||
double dBulge;
|
||
AcGePoint2d pt2d;
|
||
AcGePoint3d pt1, pt2;
|
||
int n, iNum, iIndex;
|
||
while ((iLen = arpEnt.length()) >= 0)
|
||
{
|
||
int i = 0;
|
||
for (i = 0; i < iLen; i++)
|
||
{
|
||
pCurve = (AcDbCurve*)arpEnt[i];
|
||
assert(pCurve != NULL);
|
||
pCurve->getStartPoint(pt1);
|
||
pCurve->getEndPoint(pt2);
|
||
if (pt1 == ptStart)
|
||
{
|
||
if (pCurve->isKindOf(AcDbLine::desc()))
|
||
{
|
||
pPline->addVertexAt(0, pt2.convert2d(plane));
|
||
}
|
||
else if (pCurve->isKindOf(AcDbArc::desc()))
|
||
{
|
||
pCurve->getStartParam(dParam1);
|
||
pCurve->getEndParam(dParam2);
|
||
pCurve->getPointAtParam((dParam1 + dParam2) / 2.0, pt3d);
|
||
pPline->addVertexAt(0, pt2.convert2d(plane), XExport::GetBulgeBy3Pt(pt2, pt1, pt3d));
|
||
}
|
||
else if (pCurve->isKindOf(AcDbPolyline::desc()))
|
||
{
|
||
iNum = ((AcDbPolyline*)pCurve)->numVerts() - 1;
|
||
for (n = 0; n < iNum; n++)
|
||
{
|
||
((AcDbPolyline*)pCurve)->getBulgeAt(n, dBulge);
|
||
((AcDbPolyline*)pCurve)->getPointAt(n+1, pt2d);
|
||
pPline->addVertexAt(0, pt2d, -dBulge);
|
||
}
|
||
}
|
||
ptStart = pt2;
|
||
arpEnt.removeAt(i);
|
||
arpResult.append(pCurve);
|
||
break;
|
||
}
|
||
else if (pt1 == ptEnd)
|
||
{
|
||
iIndex = pPline->numVerts();
|
||
if (pCurve->isKindOf(AcDbLine::desc()))
|
||
{
|
||
pPline->addVertexAt(iIndex, pt2.convert2d(plane));
|
||
}
|
||
else if (pCurve->isKindOf(AcDbArc::desc()))
|
||
{
|
||
pCurve->getStartParam(dParam1);
|
||
pCurve->getEndParam(dParam2);
|
||
pCurve->getPointAtParam((dParam1 + dParam2) / 2.0, pt3d);
|
||
//pPline->addVertexAt(iIndex, pt2.convert2d(plane), GetBulgeBy3Pt(pt1, pt2, pt3d));
|
||
// 091111,此情况需要修改ptEnd点的bulge
|
||
pPline->setBulgeAt(iIndex-1, XExport::GetBulgeBy3Pt(pt1, pt2, pt3d));
|
||
pPline->addVertexAt(iIndex, pt2.convert2d(plane));
|
||
}
|
||
else if (pCurve->isKindOf(AcDbPolyline::desc()))
|
||
{
|
||
iNum = ((AcDbPolyline*)pCurve)->numVerts();
|
||
((AcDbPolyline*)pCurve)->getBulgeAt(0, dBulge);
|
||
pPline->setBulgeAt(iIndex-1, dBulge);
|
||
for (n = 1; n < iNum; n++, iIndex++)
|
||
{
|
||
((AcDbPolyline*)pCurve)->getBulgeAt(n, dBulge);
|
||
((AcDbPolyline*)pCurve)->getPointAt(n, pt2d);
|
||
pPline->addVertexAt(iIndex, pt2d, dBulge);
|
||
}
|
||
}
|
||
ptEnd = pt2;
|
||
arpEnt.removeAt(i);
|
||
arpResult.append(pCurve);
|
||
break;
|
||
}
|
||
else if (pt2 == ptStart)
|
||
{
|
||
if (pCurve->isKindOf(AcDbLine::desc()))
|
||
{
|
||
pPline->addVertexAt(0, pt1.convert2d(plane));
|
||
}
|
||
else if (pCurve->isKindOf(AcDbArc::desc()))
|
||
{
|
||
pCurve->getStartParam(dParam1);
|
||
pCurve->getEndParam(dParam2);
|
||
pCurve->getPointAtParam((dParam1 + dParam2) / 2.0, pt3d);
|
||
pPline->addVertexAt(0, pt1.convert2d(plane), XExport::GetBulgeBy3Pt(pt1, pt2, pt3d));
|
||
}
|
||
else if (pCurve->isKindOf(AcDbPolyline::desc()))
|
||
{
|
||
iNum = ((AcDbPolyline*)pCurve)->numVerts() - 2;
|
||
for (n = iNum; n >= 0; n--)
|
||
{
|
||
((AcDbPolyline*)pCurve)->getBulgeAt(n, dBulge);
|
||
((AcDbPolyline*)pCurve)->getPointAt(n, pt2d);
|
||
pPline->addVertexAt(0, pt2d, dBulge);
|
||
}
|
||
}
|
||
ptStart = pt1;
|
||
arpEnt.removeAt(i);
|
||
arpResult.append(pCurve);
|
||
break;
|
||
}
|
||
else if (pt2 == ptEnd)
|
||
{
|
||
iIndex = pPline->numVerts();
|
||
if (pCurve->isKindOf(AcDbLine::desc()))
|
||
{
|
||
pPline->addVertexAt(iIndex, pt1.convert2d(plane));
|
||
}
|
||
else if (pCurve->isKindOf(AcDbArc::desc()))
|
||
{
|
||
pCurve->getStartParam(dParam1);
|
||
pCurve->getEndParam(dParam2);
|
||
pCurve->getPointAtParam((dParam1 + dParam2) / 2.0, pt3d);
|
||
pPline->setBulgeAt(iIndex-1, XExport::GetBulgeBy3Pt(pt2, pt1, pt3d));
|
||
pPline->addVertexAt(iIndex, pt1.convert2d(plane));
|
||
}
|
||
else if (pCurve->isKindOf(AcDbPolyline::desc()))
|
||
{
|
||
iNum = ((AcDbPolyline*)pCurve)->numVerts() - 2;
|
||
((AcDbPolyline*)pCurve)->getBulgeAt(iNum, dBulge);
|
||
pPline->setBulgeAt(iIndex-1, -dBulge);
|
||
for (n = iNum; n > 0; n--, iIndex++)
|
||
{
|
||
((AcDbPolyline*)pCurve)->getBulgeAt(n-1, dBulge);
|
||
((AcDbPolyline*)pCurve)->getPointAt(n, pt2d);
|
||
pPline->addVertexAt(iIndex, pt2d, -dBulge);
|
||
}
|
||
((AcDbPolyline*)pCurve)->getPointAt(n, pt2d);
|
||
pPline->addVertexAt(iIndex, pt2d);
|
||
}
|
||
ptEnd = pt1;
|
||
arpEnt.removeAt(i);
|
||
arpResult.append(pCurve);
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (i >= iLen)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
// 091119,判断起点、终点是否相同的精确度改为g_globleSnap
|
||
double dS2EDist = ptStart.distanceTo(ptEnd);
|
||
BOOL bEqual = fabs(dS2EDist) < g_globleSnap;
|
||
|
||
// 如果起点、终点相同,去掉终点,减少错误
|
||
if (bEqual)
|
||
{
|
||
int nVertexNum = pPline->numVerts();
|
||
pPline->removeVertexAt(nVertexNum-1);
|
||
}
|
||
|
||
// pPline->setClosed(ptStart == ptEnd);
|
||
pPline->setClosed(bEqual);
|
||
|
||
return pRetCurve;
|
||
}
|
||
|
||
//判断应用程序是否被调入
|
||
// AppName -- 应用程序名, 无路径和后缀
|
||
// 返回: 0--没有; 1--已调入
|
||
int XExport::AT_loaded(const TCHAR * AppName)
|
||
{
|
||
struct resbuf *rb, *apps;
|
||
TCHAR file[_MAX_FNAME], dir[_MAX_DIR], ext[_MAX_EXT], drive[_MAX_DRIVE];
|
||
int flag = 0;
|
||
apps = ads_arxloaded();
|
||
for (rb = apps; rb != NULL; rb = rb->rbnext)
|
||
{
|
||
_tsplitpath(rb->resval.rstring, drive, dir, file, ext);
|
||
if (_tcsicmp(AppName, file) == 0)
|
||
{
|
||
flag = 1;
|
||
break;
|
||
}
|
||
}
|
||
ads_relrb(apps);
|
||
|
||
return flag;
|
||
}
|
||
|
||
// 取得当前图形的文件名(不包括路径和后缀, 如: "DEMO", "TEST1")
|
||
// curDwg -- 存放结果
|
||
// 注: 结果内存大小不能小于 9 Byte
|
||
// Delete the suffix .DWG from ACAD R14
|
||
// 为支持长文件名, 取消8个字符的限制
|
||
void XExport::AT_GetCurDwg(TCHAR *curDwg)
|
||
{
|
||
TCHAR drive[_MAX_DRIVE], dir[_MAX_DIR], filename[_MAX_FNAME], ext[_MAX_EXT];
|
||
struct resbuf dwgname;
|
||
int nRet;
|
||
nRet = ads_getvar(_T("DWGNAME"), &dwgname);
|
||
assert(nRet == RTNORM);
|
||
filename[0] = 0;
|
||
_tsplitpath(dwgname.resval.rstring, drive, dir, filename, ext);
|
||
_tcscpy(curDwg, filename);
|
||
free(dwgname.resval.rstring);
|
||
}
|
||
|
||
// Reverse the ads_matrix
|
||
// a -- the source matrix
|
||
// aa -- the result matrix
|
||
// Return:
|
||
// RTNORM -- normal case
|
||
// RTERROR -- error detected
|
||
int XExport::AT_amatrix(const ads_matrix a, ads_matrix aa)
|
||
{
|
||
memcpy(aa, a, sizeof(ads_matrix));
|
||
if (XExport::CT_Inverse_mat(&aa[0][0], 4, 1.0E-9))
|
||
{
|
||
return RTNORM;
|
||
}
|
||
return RTERROR;
|
||
}
|
||
|
||
// Get current viewport Screen corner with WCS
|
||
// lowerpt -- lower corner
|
||
// upperpt -- upper corner
|
||
// Return:
|
||
// RTNORM -- normal case
|
||
// RTERROR -- error detected
|
||
int XExport::AT_ScrCorner(ads_point lowerpt, ads_point upperpt)
|
||
{
|
||
struct resbuf screensize, viewsize, viewctr;
|
||
double h, w;
|
||
|
||
ads_getvar(_T("SCREENSIZE"), &screensize);
|
||
ads_getvar(_T("viewsize"), &viewsize);
|
||
ads_getvar(_T("VIEWCTR"), &viewctr);
|
||
|
||
XPoint ptUcs = viewctr.resval.rpoint;
|
||
XPoint ptWcs = Ucs2Wcs(ptUcs);
|
||
ptWcs > viewctr.resval.rpoint;
|
||
|
||
h = viewsize.resval.rreal;
|
||
w = screensize.resval.rpoint[X]/screensize.resval.rpoint[Y]*h;
|
||
Spoint(lowerpt, viewctr.resval.rpoint[X]-w/2.0,
|
||
viewctr.resval.rpoint[Y]-h/2.0,
|
||
viewctr.resval.rpoint[Z]);
|
||
|
||
Spoint(upperpt, viewctr.resval.rpoint[X]+w/2.0,
|
||
viewctr.resval.rpoint[Y]+h/2.0,
|
||
viewctr.resval.rpoint[Z]);
|
||
|
||
return RTNORM;
|
||
}
|
||
|
||
|
||
// Get Screen current viewport Size
|
||
// width -- view port width
|
||
// height -- viewport height
|
||
// Return:
|
||
// RTNORM -- normal case
|
||
// RTERROR -- error detected
|
||
int XExport::AT_ScrSize(double *width, double *height)
|
||
{
|
||
struct resbuf screensize, viewsize;
|
||
|
||
ads_getvar(_T("SCREENSIZE"), &screensize);
|
||
ads_getvar(_T("viewsize"), &viewsize);
|
||
|
||
*height = viewsize.resval.rreal;
|
||
*width = screensize.resval.rpoint[X]/screensize.resval.rpoint[Y]*(*height);
|
||
|
||
return RTNORM;
|
||
}
|
||
|
||
// Get a name that doesn't exist for a block
|
||
// prefix -- the specific block prefix
|
||
// blk_name -- the result name for the block
|
||
int XExport::AT_get_blkname(const TCHAR *prefix, TCHAR *blk_name)
|
||
{
|
||
int j;
|
||
TCHAR name[40];
|
||
TCHAR index[10];
|
||
struct resbuf *ebuf;
|
||
|
||
for (j = 0; j<1000; j++)
|
||
{
|
||
_tcscpy(name, prefix);
|
||
_itot(j, index, 10);
|
||
_tcscat(name, index);
|
||
ebuf = ads_tblsearch(_T("BLOCK"), name, 0);
|
||
if (ebuf == NULL)
|
||
{
|
||
_tcscpy(blk_name, name);
|
||
return RTNORM;
|
||
}
|
||
ads_relrb(ebuf);
|
||
}
|
||
return RTERROR;
|
||
}
|
||
|
||
// get a node of a resbuf list
|
||
// p -- the head of resbuf list
|
||
// code -- the specific resbuf node dxf code
|
||
// Return: the address of the resbuf node, if null no such node found.
|
||
struct resbuf * XExport::AT_get_resbuf(struct resbuf *p,int code)
|
||
{
|
||
struct resbuf *head2;
|
||
|
||
for (head2 = p;(head2 != NULL)&&(head2->restype != code);head2 = head2->rbnext);
|
||
|
||
return (head2);
|
||
}
|
||
|
||
|
||
BOOL XExport::IsMaskBlock(AcDbBlockTableRecord &block, AcRxClass *pClass)
|
||
{
|
||
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
||
Acad::ErrorStatus es = block.newIterator(pBlockIterator);
|
||
ASSERT(es == Acad::eOk && pBlockIterator);
|
||
AcDbEntity *pEnt = NULL;
|
||
BOOL bTrue = FALSE;
|
||
if (pBlockIterator->getEntity(pEnt, AcDb::kForRead) == Acad::eOk)
|
||
{
|
||
if (pEnt->isA() == pClass)
|
||
{
|
||
bTrue = TRUE;
|
||
}
|
||
pEnt->close();
|
||
}
|
||
delete pBlockIterator;
|
||
return bTrue;
|
||
}
|
||
|
||
int XExport::GetProtectCode()
|
||
{
|
||
return XGeLib::g_nProtectCode;
|
||
}
|
||
|
||
struct resbuf * XExport::AT_link_list(struct resbuf *list1, struct resbuf *list2)
|
||
{
|
||
struct resbuf *p1, *p, *p2;
|
||
|
||
p1 = list1;
|
||
p2 = list2;
|
||
|
||
if(p1 == NULL)
|
||
{
|
||
return p2;
|
||
}
|
||
|
||
for(p = p1; p->rbnext != NULL; p = p->rbnext)
|
||
{
|
||
;
|
||
}
|
||
|
||
p->rbnext = p2;
|
||
|
||
return p1;
|
||
}
|
||
|
||
int XExport::LimitCycle(int n, int nLen)
|
||
{
|
||
if (n < 0)
|
||
{
|
||
n += nLen;
|
||
}
|
||
else if (n >= nLen)
|
||
{
|
||
n -= nLen;
|
||
}
|
||
else
|
||
{
|
||
return n;
|
||
}
|
||
|
||
return XExport::LimitCycle(n, nLen);
|
||
}
|
||
|
||
int XExport::IsEqual(double prec, int n, double num1, double num2, ...)
|
||
{
|
||
if (!CT_RealEqual(num1, num2, prec))
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
va_list vlst;
|
||
va_start(vlst, num2);
|
||
int res = 1;
|
||
|
||
for (int i = 0; i < n - 2; i++)
|
||
{
|
||
double r = va_arg(vlst, double);
|
||
if (!CT_RealEqual(num1, r, prec))
|
||
{
|
||
res = 0;
|
||
break;
|
||
}
|
||
}
|
||
|
||
va_end(vlst);
|
||
|
||
return res;
|
||
}
|
||
|
||
int XExport::IsEqual(int n, int num1, int num2, ...)
|
||
{
|
||
if (num1 != num2)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
va_list vlst;
|
||
va_start(vlst, num2);
|
||
int res = 1;
|
||
for (int i = 0; i < n - 2; i++)
|
||
{
|
||
int r = va_arg(vlst, int);
|
||
if (num1 != r)
|
||
{
|
||
res = 0;
|
||
break;
|
||
}
|
||
}
|
||
|
||
va_end(vlst);
|
||
|
||
return res;
|
||
}
|
||
|
||
// 初始化平面旋转变换的矩阵
|
||
// rotAngle -- 转角(弧度)
|
||
// rotMat -- 要被初始化的矩阵
|
||
void XExport::AT_InitRotMatrix(double rotAngle, ads_matrix rotMat)
|
||
{
|
||
// extern ads_matrix ads_identmat;
|
||
memcpy(rotMat, ads_identmat, sizeof(ads_matrix));
|
||
rotMat[0][0] = cos(rotAngle);
|
||
rotMat[0][1] = -sin(rotAngle);
|
||
rotMat[1][0] = sin(rotAngle);
|
||
rotMat[1][1] = cos(rotAngle);
|
||
}
|
||
|
||
// 初始化单位矩阵
|
||
void XExport::AT_InitIdenMat(ads_matrix id)
|
||
{
|
||
int i,j;
|
||
|
||
for (i = 0; i <= 3; i++)
|
||
{
|
||
for (j = 0; j <= 3; j++)
|
||
{
|
||
id[i][j] = 0.0;
|
||
}
|
||
}
|
||
|
||
for (i = 0; i <= 3; i++)
|
||
{
|
||
id[i][i] = 1.0;
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
// 根据变换点初始化矩阵
|
||
// Tx: X轴方向变换距离
|
||
// Ty: Y轴方向变换距离
|
||
// Tz: Z轴方向变换距离
|
||
void XExport::AT_InitTranMat(ads_matrix tran,double Tx,double Ty,double Tz)
|
||
{
|
||
XExport::AT_InitIdenMat(tran);
|
||
|
||
tran[X][T] = Tx;
|
||
tran[Y][T] = Ty;
|
||
tran[Z][T] = Tz;
|
||
}
|
||
|
||
int XExport::AT_multiply_matrix(ads_matrix mat1, ads_matrix mat2, ads_matrix result)
|
||
{
|
||
int i,j,k;
|
||
for (j = 0; j <= 3; j++)
|
||
{
|
||
for (i = 0; i <= 3;i++)
|
||
{
|
||
result[i][j] = 0.0;
|
||
}
|
||
}
|
||
|
||
for (j = 0; j <= 3; j++)
|
||
{
|
||
for (i = 0; i <= 3; i++)
|
||
{
|
||
for (k = 0; k <= 3;k++)
|
||
{
|
||
result[i][j] += mat1[i][k] * mat2[k][j];
|
||
}
|
||
}
|
||
}
|
||
|
||
return 1;
|
||
}
|
||
|
||
// Move this to ADSTOOL.LIB
|
||
// 把 pt绕 base旋转 ang 弧度后的结果放回 pt
|
||
void XExport::AT_PointRotation(ads_point pt, ads_point base, double ang)
|
||
{
|
||
// 先执行平移, 使得base成为原点
|
||
ads_point oldpt;
|
||
ads_matrix moveMat, rotMat;
|
||
Cpoint(oldpt, pt);
|
||
XExport::AT_InitTranMat(moveMat, -base[X], -base[Y], -base[Z]);
|
||
XExport::AT_InitRotMatrix(ang, rotMat);
|
||
AT_xformpt(moveMat, oldpt, pt); // pt--被平移厚的点
|
||
|
||
AT_xformpt(rotMat, pt, oldpt); // oldpt -- 被旋转后的点
|
||
XExport::AT_InitTranMat(moveMat, base[X], base[Y], base[Z]);
|
||
AT_xformpt(moveMat, oldpt, pt); // pt -- 被恢复平移后的点
|
||
}
|
||
|
||
// 100115,增加了与编组有关的两个全句函数,后续应调整到GEO工程中
|
||
// 把一组实体添加成组,若为无名组,pGroupName为_T("*")
|
||
int XExport::MakeGroup(AcDbObjectIdArray &arObjId, AcDbObjectId &objId, const TCHAR *pGroupName, bool bClearOld, bool bSelectable)
|
||
{
|
||
int nLength = arObjId.length();
|
||
if (0 == nLength) // 当数组为空时,直接返回
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
AcDbDictionary *pGroupDict = NULL;
|
||
Acad::ErrorStatus es = acdbCurDwg()->getGroupDictionary(pGroupDict, AcDb::kForWrite);
|
||
if (Acad::eOk != es)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
AcDbGroup *pGroup = NULL;
|
||
es = pGroupDict->getAt(pGroupName, objId);
|
||
if (Acad::eOk == es) // 存在同名组
|
||
{
|
||
// 取得pGroup并清空
|
||
es = acdbOpenObject(pGroup, objId, AcDb::kForWrite);
|
||
if (Acad::eOk != es)
|
||
{
|
||
pGroupDict->close();
|
||
return RTERROR;
|
||
}
|
||
|
||
pGroup->setSelectable(bSelectable);
|
||
if (bClearOld)
|
||
{
|
||
pGroup->clear();
|
||
}
|
||
}
|
||
else // 不存在, 新建一组,并添入字典
|
||
{
|
||
pGroup = new AcDbGroup;
|
||
pGroup->setSelectable(bSelectable);
|
||
|
||
es = pGroupDict->setAt(pGroupName, pGroup, objId);
|
||
if (Acad::eOk != es) // 创建不成功
|
||
{
|
||
pGroupDict->close();
|
||
delete pGroup;
|
||
|
||
return RTERROR;
|
||
}
|
||
}
|
||
|
||
pGroupDict->close();
|
||
|
||
// 往组中添加选择集中的实体
|
||
for (short i = 0; i < nLength; i++)
|
||
{
|
||
pGroup->append(arObjId.at(i));
|
||
}
|
||
|
||
pGroup->close();
|
||
return RTNORM;
|
||
}
|
||
|
||
// 把一组新创建的实体添加到模型空间中去
|
||
// bDelWhenfail:当某实体添加不成功时,是否删除已成功添加的对象;
|
||
// arEntitySet:当返回的状态不正确时,arEntitySet中遗留的对象,需要调用处,负责delete;
|
||
int XExport::AddArrayToModelSpace(AcDbVoidPtrArray& arEntitySet, AcDbObjectIdArray &arObjId, bool bDelWhenfail)
|
||
{
|
||
AcDbBlockTable *pBlkTbl = NULL;
|
||
// 打开块表
|
||
Acad::ErrorStatus errorStatus = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForRead);
|
||
if (Acad::eOk != errorStatus)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
|
||
AcDbBlockTableRecord *pBlkTblRcd = NULL;
|
||
// 打开块表记录
|
||
errorStatus = pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForWrite);
|
||
if (Acad::eOk != errorStatus)
|
||
{
|
||
pBlkTbl->close();
|
||
return RTERROR;
|
||
}
|
||
pBlkTbl->close();
|
||
|
||
int nCount = arEntitySet.length();
|
||
for (short i = 0; i < nCount; i++)
|
||
{
|
||
AcDbObjectId objIdEnt;
|
||
AcDbEntity *pEnt = (AcDbEntity *)arEntitySet[i];
|
||
|
||
errorStatus = pBlkTblRcd->appendAcDbEntity(objIdEnt, pEnt);
|
||
if (Acad::eOk != errorStatus) // 添加失败
|
||
{
|
||
if (bDelWhenfail) // 删除已成功添加的对象
|
||
{
|
||
AcDbEntity *pEnt = NULL;
|
||
for (short j = 0; j < i; j++)
|
||
{
|
||
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, arObjId.at(j), AcDb::kForWrite))
|
||
{
|
||
pEnt->erase(true);
|
||
pEnt->close();
|
||
}
|
||
}
|
||
}
|
||
|
||
pBlkTblRcd->close();
|
||
return RTERROR;
|
||
}
|
||
else // 添加成功的对象,从AcDbVoidPtrArray中,删除
|
||
{
|
||
arEntitySet.removeAt(i);
|
||
i--;
|
||
nCount--;
|
||
}
|
||
|
||
pEnt->close();
|
||
arObjId.append(objIdEnt);
|
||
}
|
||
|
||
pBlkTblRcd->close();
|
||
return RTNORM;
|
||
}
|
||
|
||
AcDbObjectId XExport::GetTempEntityId(AcRxClass *pClass, const TCHAR *szBlockName, BOOL *bFirstNew)
|
||
{
|
||
AcDbEntity *pEnt;
|
||
AcDbBlockTable *pBlockTable;
|
||
AcDbBlockTableRecord *pBlockTableRecord;
|
||
acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForRead);
|
||
|
||
AcDbObjectId idResult;
|
||
if (pBlockTable->has(szBlockName)) //图块已经存在!
|
||
{
|
||
pBlockTable->getAt(szBlockName,pBlockTableRecord,AcDb::kForRead);
|
||
AcDbBlockTableRecordIterator* pBlockIterator;
|
||
pBlockTableRecord->newIterator(pBlockIterator,Adesk::kTrue,Adesk::kFalse);
|
||
|
||
int id = 0;
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
pBlockIterator->getEntity(pEnt,AcDb::kForRead, Adesk::kTrue);
|
||
if (pEnt->isKindOf(pClass))
|
||
{
|
||
idResult = pEnt->objectId();
|
||
id = 1;
|
||
}
|
||
|
||
pEnt->close();
|
||
|
||
if (id)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
pBlockTable->close();
|
||
pBlockTableRecord->close();
|
||
|
||
if (id == 0)
|
||
{
|
||
acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForWrite);
|
||
VERIFY(pBlockTable->getAt(szBlockName,pBlockTableRecord,AcDb::kForWrite) == Acad::eOk);
|
||
|
||
//构造实体
|
||
AcRxObject *pObj = pClass->create();
|
||
if (bFirstNew)
|
||
{
|
||
*bFirstNew = TRUE;
|
||
}
|
||
|
||
pEnt = AcDbEntity::cast(pObj);
|
||
VERIFY(pBlockTableRecord->appendAcDbEntity(pEnt) == Acad::eOk);
|
||
|
||
idResult = pEnt->objectId();
|
||
pEnt->close();
|
||
pBlockTable->close();
|
||
pBlockTableRecord->close();
|
||
}
|
||
|
||
delete pBlockIterator;
|
||
}
|
||
else
|
||
{
|
||
pBlockTable->close();
|
||
|
||
acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForWrite);
|
||
pBlockTableRecord = new AcDbBlockTableRecord;
|
||
|
||
AcGePoint3d origin(0.0,0.0,0.0);
|
||
pBlockTableRecord->setOrigin(origin);
|
||
pBlockTableRecord->setName(szBlockName);
|
||
|
||
//构造实体
|
||
AcRxObject *pObj = pClass->create();
|
||
if (bFirstNew)
|
||
{
|
||
*bFirstNew = TRUE;
|
||
}
|
||
|
||
pEnt = AcDbEntity::cast(pObj);
|
||
pBlockTable->add(pBlockTableRecord);
|
||
pBlockTable->close();
|
||
|
||
pBlockTableRecord->appendAcDbEntity(idResult, pEnt);
|
||
pBlockTableRecord->close();
|
||
pEnt->close();
|
||
}
|
||
|
||
return idResult;
|
||
}
|
||
|
||
// 取得矩形的几何参数
|
||
int GetRectTangle(resbuf *ptList, Point &cen, ads_real *width, ads_real *height)
|
||
{
|
||
if(!ptList)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
Point pt[4];
|
||
resbuf *rb = ptList;
|
||
for(int i = 0; i < 4; i++)
|
||
{
|
||
if(rb == NULL || rb->restype != RT3DPOINT)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
pt[i] = rb->resval.rpoint;
|
||
rb = rb->rbnext;
|
||
}
|
||
|
||
XLine line1(pt[0], pt[1]), line2(pt[1], pt[2]);
|
||
XLine line3(pt[2], pt[3]), line4(pt[3], pt[0]);
|
||
|
||
if (CT_IsOrthDrt(line1.Direction(), line2.Direction(), _angSnap) &&
|
||
CT_IsOrthDrt(line3.Direction(), line4.Direction(), _angSnap) &&
|
||
CT_IsSameDrt(line1.Direction(), line3.Direction(), _angSnap))
|
||
{
|
||
if (CT_RealEqual(line1.GetLength(),line3.GetLength(),_DIST_SNAP) &&
|
||
CT_RealEqual(line2.GetLength(), line4.GetLength(),_DIST_SNAP))
|
||
{
|
||
if (CT_IsSameDrt(line1.Direction(), 0, _angSnap))
|
||
{
|
||
XLine ln(pt[0], pt[2]);
|
||
cen = ln.MidPoint();
|
||
*width = line1.GetLength();
|
||
*height = line2.GetLength();
|
||
return RTNORM;
|
||
}
|
||
else if (CT_IsSameDrt(line2.Direction(), 0, _angSnap))
|
||
{
|
||
XLine ln(pt[0], pt[2]);
|
||
cen = ln.MidPoint();
|
||
*width = line2.GetLength();
|
||
*height = line1.GetLength();
|
||
return RTNORM;
|
||
}
|
||
}
|
||
}
|
||
return RTERROR;
|
||
}
|
||
/*
|
||
#include "XEntityImp.h"
|
||
#include "XSectorImp.h"
|
||
#include "XCircleImp.h"
|
||
#include "XPoly2DImp.h"
|
||
#include "XCurveSegmentImp.h"
|
||
|
||
static void FreeBufferPool(CArray<XEntityImp*,XEntityImp*>& arBuffer)
|
||
{
|
||
for (int i = 0;i < arBuffer.GetSize();i++)
|
||
{
|
||
delete arBuffer.GetAt(i);
|
||
}
|
||
}
|
||
|
||
static void FreeBufferPool(CArray<XSectorImp*,XSectorImp*>& arBuffer)
|
||
{
|
||
for (int i = 0;i < arBuffer.GetSize();i++)
|
||
{
|
||
delete arBuffer.GetAt(i);
|
||
}
|
||
}
|
||
*/
|
||
void XExport::InitGeLib(bool bAttach)
|
||
{
|
||
//加载时调用
|
||
if (bAttach)
|
||
{
|
||
SqlQuiry InitTemp_2;
|
||
SafeResource InitTemp_3;
|
||
WValList InitTemp_4("","");//构造函数只认char*
|
||
XUcsStream InitTemp_5;
|
||
XWcsStream InitTemp_6;
|
||
TextRange InitTemp_7;
|
||
XPushMMUnit setTempMMUnit;
|
||
}
|
||
else
|
||
{
|
||
//卸载范围分区
|
||
AcDbDatabase* pDb = NULL;
|
||
XBlockTableRecordZone* pZone = NULL;
|
||
for (POSITION ps = g_mapDbToModelRecZone.GetStartPosition();ps != NULL;)
|
||
{
|
||
g_mapDbToModelRecZone.GetNextAssoc(ps,(void*&)pDb,(void*&)pZone);
|
||
if (pZone != NULL)
|
||
{
|
||
delete pZone;
|
||
}
|
||
}
|
||
/*
|
||
//卸载内存池
|
||
FreeBufferPool(XCurveSegmentImp::s_arBufferPool);
|
||
FreeBufferPool(XCircleImp::s_arBufferPool);
|
||
FreeBufferPool(XSectorImp::s_arBufferPool);
|
||
FreeBufferPool(XPoly2DImp::s_arBufferPool);*/
|
||
}
|
||
}
|
||
|
||
BOOL XExport::IsPaperSpace()
|
||
{
|
||
int cvport = 0;
|
||
xg_getvar(_T("CVPORT"), &cvport);
|
||
|
||
return (cvport == 1);
|
||
}
|
||
|
||
// add by zjq on 101118 由对象的id获得对象ownerId
|
||
AcDbObjectId XExport::GetOwnerIdFromId(AcDbObjectId idObj)
|
||
{
|
||
XDbObject pObj(idObj,AcDb::kForRead, Adesk::kTrue);
|
||
if (!pObj)
|
||
{
|
||
return AcDbObjectId::kNull;
|
||
}
|
||
else
|
||
{
|
||
return pObj.m_pObject->ownerId();
|
||
}
|
||
|
||
}
|
||
|
||
BOOL XExport::IsUpdateMVBlock()
|
||
{
|
||
return g_bUpdateMViewBlock;
|
||
}
|
||
|
||
void XExport::UpdateMVBlockVal(BOOL bTrue)
|
||
{
|
||
g_bUpdateMViewBlock = bTrue;
|
||
}
|
||
|
||
// 0--2D; 1--3D
|
||
int XExport::IsExplode3D()
|
||
{
|
||
int nMode = 0;
|
||
int nDraw = 3;
|
||
|
||
XConfigBase* pBase = GetGlobalConfigBase();
|
||
|
||
if (pBase != NULL)
|
||
{
|
||
nDraw = pBase->DocGetDrawMode();
|
||
pBase->Close();
|
||
}
|
||
|
||
if (nDraw == 1)
|
||
{
|
||
;
|
||
}
|
||
else if (nDraw == 2)
|
||
{
|
||
nMode = 1;
|
||
}
|
||
else if (nDraw == 3)
|
||
{
|
||
XPoint viewDir;
|
||
xg_getvar(_T("VIEWDIR"), &viewDir);
|
||
viewDir = Ucs2Wcs(viewDir, TRUE);
|
||
if (fabs(viewDir.x) > 1.0E-6 || fabs(viewDir.y) > 1.0E-6)
|
||
{
|
||
nMode = 1;
|
||
}
|
||
}
|
||
return nMode;
|
||
}
|
||
|
||
void XExport::ColorToRGB(int nAcadColor, int *nR, int *nG, int *nB)
|
||
{
|
||
r_g_b rgb;
|
||
acadrgb(nAcadColor, &rgb);
|
||
*nR = AS_INT(255*rgb.red);
|
||
*nG = AS_INT(255*rgb.green);
|
||
*nB = AS_INT(255*rgb.blue);
|
||
}
|
||
|