472 lines
10 KiB
C++
472 lines
10 KiB
C++
#include "stdafx.h"
|
|
#include "AecAngleWatch.h"
|
|
#include "KTSetting.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
#define WATCHRA 50
|
|
|
|
const Adesk::UInt16 kRed = 1;
|
|
const Adesk::UInt16 kYellow = 2;
|
|
const Adesk::UInt16 kGreen = 3;
|
|
const Adesk::UInt16 kCyan = 4;
|
|
const Adesk::UInt16 kBlue = 5;
|
|
const Adesk::UInt16 kMagenta = 6;
|
|
|
|
namespace
|
|
{
|
|
double PixelToWcs(int nPixel)
|
|
{
|
|
double dGet;
|
|
ads_point ptScreenSize;
|
|
double nViewSize;
|
|
struct resbuf rb1, rb2;
|
|
acedGetVar(_T("ScreenSize"), &rb1);
|
|
acedGetVar(_T("ViewSize"), &rb2);
|
|
nViewSize = rb2.resval.rreal;
|
|
ads_point_set(rb1.resval.rpoint, ptScreenSize);
|
|
|
|
if (ptScreenSize[1] >= 1.0E-6 && nViewSize >= 1.0E-6)
|
|
dGet = (nViewSize / ptScreenSize[Y]) * nPixel;
|
|
|
|
return dGet;
|
|
}
|
|
}
|
|
|
|
AecAngleWatch::AecAngleWatch(BOOL bIsISO)
|
|
{
|
|
m_nWatchStep = 30;
|
|
m_bWatchPoint = TRUE;
|
|
m_bFallInSnap = FALSE;
|
|
m_dSnapAngle = 5.0 * PI / 180.0;
|
|
if (!bIsISO)
|
|
{
|
|
m_ptGeCen.set(0,0,0);
|
|
m_ptGeTo.set(100,0,0);
|
|
m_vtDir.set(1,0,0);
|
|
|
|
struct resbuf rbOth;
|
|
acedGetVar(_T("ORTHOMODE"),&rbOth);
|
|
if (rbOth.resval.rint == 0)
|
|
{
|
|
struct resbuf rb;
|
|
acedGetVar(_T("AUTOSNAP"),&rb);
|
|
acedGetVar(_T("AUTOSNAP"),&m_rbAutoSnap);
|
|
rb.resval.rint = 25;
|
|
acedSetVar(_T("AUTOSNAP"),&rb);
|
|
}
|
|
}
|
|
m_nAngMode = -1;
|
|
m_nAngle = 0;
|
|
|
|
KTSetting::InitTextStyle(_T("Pipe_Dim"));
|
|
}
|
|
|
|
AecAngleWatch::~AecAngleWatch()
|
|
{
|
|
struct resbuf rb;
|
|
acedGetVar(_T("ANGBASE"),&rb);
|
|
rb.resval.rreal = 0.0;
|
|
acedSetVar(_T("ANGBASE"),&rb);
|
|
acedSetVar(_T("ELEVATION"),&rb);
|
|
acedSetVar(_T("AUTOSNAP"),&m_rbAutoSnap);
|
|
}
|
|
|
|
void AecAngleWatch::SetISOMode(int nType, int nAngle)
|
|
{
|
|
m_nAngMode = nType;
|
|
m_nAngle = nAngle;
|
|
CString sPolAng;
|
|
|
|
//autosnap 需要 0 和 63 之间的整数
|
|
struct resbuf rb;
|
|
acedGetVar(_T("AUTOSNAP"), &rb);
|
|
|
|
rb.resval.rint = 30;
|
|
acedSetVar(_T("AUTOSNAP"), &rb);
|
|
|
|
struct resbuf rb1;
|
|
acedGetVar(_T("POLARANG"), &rb1);
|
|
rb1.resval.rreal = nAngle ? 45 : 30;
|
|
rb1.resval.rreal *= PI / 180.0;
|
|
acedSetVar(_T("POLARANG"), &rb1);
|
|
|
|
//"30;90"
|
|
sPolAng.Format(_T("%d;%d"), 180 - rb.resval.rint, 90);
|
|
|
|
struct resbuf rb2;
|
|
memset(&rb2, 0, sizeof(resbuf));
|
|
acedGetVar(_T("POLARADDANG"), &rb2);
|
|
if (rb2.resval.rstring != NULL)
|
|
acutDelString(rb2.resval.rstring);
|
|
rb2.resval.rstring = new TCHAR[166];
|
|
_tcscpy(rb2.resval.rstring, sPolAng);
|
|
acedSetVar(_T("POLARADDANG"), &rb2);
|
|
|
|
return;
|
|
/*
|
|
AcGeVector3d vtNorm;
|
|
switch (nType)
|
|
{
|
|
case 0: //西南 30,120 or 45
|
|
{
|
|
struct resbuf rb;
|
|
acedGetVar(_T("AUTOSNAP"), &rb);
|
|
|
|
rb.resval.rint = nAngle ? 45 : 30;
|
|
acedSetVar(_T("AUTOSNAP"), &rb);
|
|
|
|
//"30;90"
|
|
sPolAng.Format(_T("%d;%d"), 180 - rb.resval.rint,90);
|
|
|
|
struct resbuf rb2;
|
|
acedGetVar(_T("POLARADDANG"), &rb2);
|
|
rb2.resval.rstring = new TCHAR[166];
|
|
_tcscpy(rb2.resval.rstring, sPolAng);
|
|
acedSetVar(_T("POLARADDANG"), &rb2);
|
|
|
|
break;
|
|
}
|
|
case 1://东南 -30,30
|
|
{
|
|
struct resbuf rb;
|
|
acedGetVar(_T("AUTOSNAP"), &rb);
|
|
rb.resval.rint = nAngle ? 45 : 30;
|
|
acedSetVar(_T("AUTOSNAP"), &rb);
|
|
|
|
//"30;90"
|
|
sPolAng.Format(_T("%d;%d"), nAngle ? 315 : 330, 90);
|
|
|
|
struct resbuf rb2;
|
|
acedGetVar(_T("POLARADDANG"), &rb2);
|
|
rb2.resval.rstring = new TCHAR[166];
|
|
_tcscpy(rb2.resval.rstring, sPolAng);
|
|
acedSetVar(_T("POLARADDANG"), &rb2);
|
|
|
|
break;
|
|
}
|
|
case 2://东北 -150,-30
|
|
{
|
|
struct resbuf rb;
|
|
acedGetVar(_T("AUTOSNAP"), &rb);
|
|
rb.resval.rint = nAngle ? 45 : 30;
|
|
acedSetVar(_T("AUTOSNAP"), &rb);
|
|
|
|
//"30;90"
|
|
sPolAng.Format(_T("%d;%d"), PI + rb.resval.rint, 90);
|
|
|
|
struct resbuf rb2;
|
|
acedGetVar(_T("POLARADDANG"), &rb2);
|
|
rb2.resval.rstring = new TCHAR[166];
|
|
_tcscpy(rb2.resval.rstring, sPolAng);
|
|
acedSetVar(_T("POLARADDANG"), &rb2);
|
|
|
|
break;
|
|
}
|
|
case 3://西北 150,-150
|
|
{
|
|
struct resbuf rb;
|
|
acedGetVar(_T("AUTOSNAP"), &rb);
|
|
rb.resval.rint = nAngle ? 45 : 30;
|
|
acedSetVar(_T("AUTOSNAP"), &rb);
|
|
|
|
sPolAng.Format(_T("%d;%d"), 2 * (PI - rb.resval.rint), 90);
|
|
struct resbuf rb2;
|
|
acedGetVar(_T("POLARADDANG"), &rb2);
|
|
rb2.resval.rstring = new TCHAR[166];
|
|
_tcscpy(rb2.resval.rstring, sPolAng);
|
|
acedSetVar(_T("POLARADDANG"), &rb2);
|
|
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}*/
|
|
}
|
|
|
|
double AecAngleWatch::GetAngWatchSp() const
|
|
{
|
|
return m_dSnapAngle;
|
|
}
|
|
|
|
void AecAngleWatch::SetAngWatchSp(double nSp)
|
|
{
|
|
m_nWatchStep = nSp;
|
|
}
|
|
|
|
void AecAngleWatch::SetAngleWath(AcGePoint3d& ptCen,const AcGePoint3d& ptGeTo,const AcGeVector3d& vtDir)
|
|
{
|
|
m_ptGeCen = ptCen;
|
|
m_ptGeTo = ptGeTo;
|
|
m_vtDir = vtDir;
|
|
|
|
if (m_nAngMode > -1)
|
|
return;
|
|
|
|
struct resbuf rbOth;
|
|
acedGetVar(_T("ORTHOMODE"),&rbOth);
|
|
if (rbOth.resval.rint == 0)
|
|
{
|
|
struct resbuf rb;
|
|
acedGetVar(_T("AUTOSNAP"),&rb);
|
|
acedGetVar(_T("AUTOSNAP"),&m_rbAutoSnap);
|
|
rb.resval.rint = 25;
|
|
acedSetVar(_T("AUTOSNAP"),&rb);
|
|
}
|
|
else
|
|
{
|
|
//orth=1
|
|
}
|
|
}
|
|
|
|
void AecAngleWatch::SwitchAutoSnapOrF8()
|
|
{
|
|
struct resbuf rbOth;
|
|
acedGetVar(_T("ORTHOMODE"),&rbOth);
|
|
if (rbOth.resval.rint == 0)
|
|
{
|
|
struct resbuf rb;
|
|
acedGetVar(_T("AUTOSNAP"),&rb);
|
|
acedGetVar(_T("AUTOSNAP"),&m_rbAutoSnap);
|
|
rb.resval.rint = 25;
|
|
acedSetVar(_T("AUTOSNAP"),&rb);
|
|
}
|
|
else
|
|
{
|
|
//orth=1
|
|
}
|
|
}
|
|
|
|
Acad::ErrorStatus AecAngleWatch::Draw2d(AcGiDraw &mode) const
|
|
{
|
|
if (m_nAngMode > -1)
|
|
{
|
|
return DrawISOXYZ(mode);
|
|
}
|
|
|
|
//取屏幕像素
|
|
int nColorOld = 0;
|
|
double dVal = PixelToWcs(WATCHRA);
|
|
double dH = PixelToWcs(20);
|
|
|
|
nColorOld = mode.GetColor();
|
|
mode.SetColor(kGreen);
|
|
|
|
double dR = dVal - 10.0;
|
|
if (m_bWatchPoint)
|
|
{
|
|
mode.DrawCircle(m_ptGeCen, dR, AcGeVector3d::kZAxis);
|
|
}
|
|
|
|
//画圆盘
|
|
AcGeVector3d vtDirA = -m_vtDir;
|
|
if (vtDirA.isParallelTo(AcGeVector3d::kZAxis))
|
|
vtDirA = AcGeVector3d::kXAxis;
|
|
|
|
AcGeVector3d vtCurr = m_ptGeCen - m_ptGeTo;
|
|
vtDirA.normalize();
|
|
double dAngle = 0.0,dDot = 0.0;
|
|
CString sText;
|
|
|
|
AcGePoint3d ptGe[2];
|
|
ptGe[0] = m_ptGeCen;
|
|
|
|
int nLoop = 360 / m_nWatchStep;
|
|
for (int i = 0;i < nLoop;i++)
|
|
{
|
|
ptGe[1] = ptGe[0] + dR * vtDirA;
|
|
|
|
if (m_bWatchPoint)
|
|
{
|
|
mode.DrawLine(AcGeLineSeg3d(ptGe[0], ptGe[1]));
|
|
}
|
|
|
|
dAngle = vtCurr.angleTo(vtDirA);
|
|
dDot = vtCurr.dotProduct(vtDirA);
|
|
|
|
if (dDot > 1.e-3) //同向
|
|
{
|
|
if (dAngle - PI / 2.0 > 1.e-10)
|
|
dAngle = PI - dAngle;
|
|
|
|
//if ( (dAngle - 5.0 * PI / 180.0) < 1.e-10)
|
|
if ( (dAngle - m_dSnapAngle) < 1.e-10)
|
|
{
|
|
ptGe[1] = ptGe[0] - dR * vtDirA;
|
|
|
|
sText.Format(_T("%.1f"),i * m_nWatchStep);
|
|
sText.TrimRight(_T('0'));
|
|
sText.TrimRight(_T('.'));
|
|
sText += _T("%%d");
|
|
mode.DrawText(sText, ptGe[1], AcGiDraw::kTopLeft, dH, 0.7, 0.0, _T("standard"));
|
|
}
|
|
}
|
|
|
|
vtDirA.rotateBy(m_nWatchStep * PI / 180.0,AcGeVector3d::kZAxis);
|
|
}
|
|
mode.SetColor(nColorOld);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecAngleWatch::DrawISOXYZ(AcGiDraw &mode) const
|
|
{
|
|
struct resbuf rbOth;
|
|
acedGetVar(_T("ORTHOMODE"), &rbOth);
|
|
|
|
AcGeVector3d vtX(0, 0, 0), vtY(0, 0, 0), vtZ(0, 0, 0);
|
|
|
|
switch (m_nAngMode)
|
|
{
|
|
case 0: //西南 30,150 or 45
|
|
{
|
|
vtX = AcGeVector3d::kXAxis;
|
|
vtX.rotateBy(m_nAngle ? PI / 4.0 : PI / 6.0, AcGeVector3d::kZAxis);
|
|
|
|
vtY = AcGeVector3d::kXAxis;
|
|
vtY.rotateBy(m_nAngle ? (PI - PI / 4.0) : (PI - PI / 6.0), AcGeVector3d::kZAxis);
|
|
|
|
vtZ = AcGeVector3d::kYAxis;
|
|
|
|
break;
|
|
}
|
|
case 1://东南 -30,30
|
|
{
|
|
vtX = AcGeVector3d::kXAxis;
|
|
vtX.rotateBy(m_nAngle ? -PI / 4.0 : -PI / 6.0, AcGeVector3d::kZAxis);
|
|
|
|
vtY = vtX;
|
|
vtY.rotateBy(m_nAngle ? PI / 2.0 : PI / 3.0, AcGeVector3d::kZAxis);
|
|
|
|
vtZ = AcGeVector3d::kYAxis;
|
|
|
|
break;
|
|
}
|
|
case 2://东北 -150,-30
|
|
{
|
|
vtX = -AcGeVector3d::kXAxis;
|
|
vtX.rotateBy(m_nAngle ? PI / 4.0 : PI / 6.0, AcGeVector3d::kZAxis);
|
|
|
|
vtY = AcGeVector3d::kXAxis;;
|
|
vtY.rotateBy(m_nAngle ? (-PI / 4.0) : (-PI / 6.0), AcGeVector3d::kZAxis);
|
|
|
|
vtZ = AcGeVector3d::kYAxis;
|
|
|
|
break;
|
|
}
|
|
case 3://西北 150,-150
|
|
{
|
|
vtX = AcGeVector3d::kXAxis;
|
|
vtX.rotateBy(m_nAngle ? (PI - PI / 4.0) : (PI - PI / 6.0), AcGeVector3d::kZAxis);
|
|
|
|
vtY = vtX;
|
|
vtY.rotateBy(m_nAngle ? PI / 2.0 : PI / 3.0, AcGeVector3d::kZAxis);
|
|
|
|
vtZ = AcGeVector3d::kYAxis;
|
|
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (!vtX.isZeroLength())
|
|
{
|
|
//取屏幕像素
|
|
int nColorOld = 0;
|
|
double dVal = PixelToWcs(WATCHRA);
|
|
double dH = PixelToWcs(20);
|
|
|
|
nColorOld = mode.GetColor();
|
|
mode.SetColor(kGreen);
|
|
|
|
double dR = dVal - 10.0;
|
|
AcGePoint3d ptFr = m_ptGeCen;
|
|
AcGePoint3d ptTo = ptFr + vtX * dR;
|
|
|
|
//AcGiTextStyle st;
|
|
//fromAcDbTextStyle(st, m_idTextSty);
|
|
//st.setTextSize(2.0 * 100);
|
|
//st.setXScale(0.8);
|
|
|
|
//X
|
|
AcGeLineSeg3d lnX(ptFr, ptTo);
|
|
mode.DrawLine(lnX);
|
|
mode.DrawText(_T("X"), ptTo, AcGiDraw::kTopLeft, dH, 0.7, 0.0, _T("Pipe_Dim"));
|
|
|
|
//Y
|
|
ptTo = ptFr + vtY * dR;
|
|
AcGeLineSeg3d lnY(ptFr, ptTo);
|
|
mode.DrawLine(lnY);
|
|
mode.DrawText(_T("Y"), ptTo, AcGiDraw::kTopLeft, dH, 0.7, 0.0, _T("Pipe_Dim"));
|
|
|
|
//Z
|
|
ptTo = ptFr + vtZ * dR;
|
|
AcGeLineSeg3d lnZ(ptFr, ptTo);
|
|
mode.DrawLine(lnZ);
|
|
mode.DrawText(_T("Z"), ptTo, AcGiDraw::kTopLeft, dH, 0.7, 0.0, _T("Pipe_Dim"));
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
BOOL AecAngleWatch::snapWatch(AcGePoint3d& ptCen,AcGePoint3d& ptGeTo,const AcGeVector3d& vtDir)
|
|
{
|
|
if (m_nAngMode > -1)
|
|
return TRUE;
|
|
|
|
//取屏幕像素
|
|
double dVal = PixelToWcs(WATCHRA);
|
|
|
|
//画圆盘
|
|
AcGeVector3d vtDirA = vtDir;
|
|
if (vtDirA.isParallelTo(AcGeVector3d::kZAxis))
|
|
vtDirA = AcGeVector3d::kXAxis;
|
|
|
|
AcGeVector3d vtCurr = ptGeTo - ptCen;
|
|
double dLen = vtCurr.length();
|
|
|
|
double dAngle = 0.0,dAngleSta = 0.0,dDot = 0.0;
|
|
dAngleSta = AcGeVector3d::kXAxis.angleTo(vtDir);
|
|
vtDirA.normalize();
|
|
AcGePoint3d ptGe[2];
|
|
ptGe[0] = ptCen;
|
|
|
|
struct resbuf rb;
|
|
acedGetVar(_T("ANGBASE"),&rb);
|
|
|
|
BOOL bFind = FALSE;
|
|
int nLoop = 360 / m_nWatchStep;
|
|
for (int i = 0;i < nLoop;i++)
|
|
{
|
|
ptGe[1] = ptGe[0] + (dVal + dVal / 20.0) * vtDirA;
|
|
|
|
dAngle = vtCurr.angleTo(vtDirA);
|
|
dDot = vtCurr.dotProduct(vtDirA);
|
|
if (dDot > 1.e-10) //同向
|
|
{
|
|
if (dAngle - PI / 2.0 > 1.e-10) dAngle = PI - dAngle;
|
|
|
|
//10度
|
|
//if ( fabs(dAngle - 5.0 * PI / 180.0) < 1.e-10)
|
|
if ( (dAngle - m_dSnapAngle) < 1.e-10)
|
|
{
|
|
vtDirA.normalize();
|
|
ptGeTo = ptCen + dLen * vtDirA;
|
|
rb.resval.rreal = vtDirA.angleOnPlane(AcGePlane::kXYPlane);
|
|
|
|
if (rb.resval.rreal - PI > 1.e-6)
|
|
rb.resval.rreal -= PI;
|
|
//rb.resval.rreal *= 180.0 / PI;
|
|
acedSetVar(_T("ANGBASE"),&rb);
|
|
bFind = 1;
|
|
break;
|
|
}
|
|
}
|
|
vtDirA.rotateBy(m_nWatchStep * PI / 180.0,AcGeVector3d::kZAxis);
|
|
}
|
|
return bFind;
|
|
}
|