229 lines
5.4 KiB
C++
229 lines
5.4 KiB
C++
// TWellJig.cpp: implementation of the TWellJig class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "globalFunc.h"
|
|
#include "globalDefine.h"
|
|
#include "GeArc.h"
|
|
#include "TWellJig.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
TWellJig::TWellJig(XPoint pt1)
|
|
{
|
|
m_ptStart = pt1;
|
|
m_ptEnd = pt1;
|
|
m_iPipeType = 0;
|
|
m_nDist = 0;
|
|
m_nLockAng =-1;
|
|
m_pDrawEnt = new CWellPreview(m_ptStart, m_ptEnd);
|
|
}
|
|
|
|
//TWellJig::TWellJig(XPoint pt1, double dDist)
|
|
//{
|
|
// m_ptStart = pt1;
|
|
// m_ptEnd = pt1;
|
|
// m_iPipeType = 0;
|
|
// m_nDist = 0;
|
|
// m_nLockAng =-1;
|
|
// m_pDrawEnt = new CWellPreview(m_ptStart, m_ptEnd, dDist);
|
|
//}
|
|
|
|
|
|
TWellJig::~TWellJig()
|
|
{
|
|
if(m_pDrawEnt)
|
|
delete m_pDrawEnt;
|
|
}
|
|
|
|
void TWellJig::SetStartPoint(XPoint pt)
|
|
{
|
|
m_ptStart = pt;
|
|
m_pDrawEnt->m_ptStart = m_ptStart;
|
|
}
|
|
|
|
//void TWellJig::SetDist(double dDist)//定距布置
|
|
//{
|
|
// m_nDist = dDist;
|
|
//}
|
|
//
|
|
//void TWellJig::SetDist2(double dDist)//两点均布
|
|
//{
|
|
//
|
|
// m_pDrawEnt->m_dDist = dDist;
|
|
|
|
|
|
AcEdJig::DragStatus
|
|
TWellJig::GetPoint(XPoint &pt)
|
|
{
|
|
if(m_nLockAng > -1)
|
|
return acquirePoint(pt);
|
|
if(!!m_ptMid){ //扇形布置
|
|
XArc arc(m_ptStart, m_ptMid, m_ptEnd);
|
|
XPoint ptBase;
|
|
arc.MidPoint(ptBase);
|
|
AcGePoint3d ptBase2 = asPnt3d(ptBase);
|
|
return acquirePoint(pt, ptBase2);
|
|
}
|
|
return acquirePoint(pt, m_ptStart.AsAcGePoint3d());
|
|
}
|
|
|
|
|
|
int TWellJig::DoIt(int *keyIndex)
|
|
{
|
|
int nRet = TSymbEdJig::DoIt(keyIndex);
|
|
return nRet;
|
|
}
|
|
|
|
|
|
XPoint TWellJig::GetCorrectPt()
|
|
{
|
|
XPoint ptTmp = m_ptResult;
|
|
if(m_nLockAng > -1){
|
|
// m_ptRef = XPoint();
|
|
XPoint ptTmp2 = m_ptStart;
|
|
ptTmp2.z = 0;
|
|
double nAngle = ads_angle(ptTmp2, m_ptResult) - m_nLockAng;
|
|
double nDist = ads_distance(ptTmp2, m_ptResult);
|
|
if(nAngle > PI/2 && nAngle < PI/2*3)
|
|
ads_polar(m_ptStart, m_nLockAng, -nDist, ptTmp);
|
|
else
|
|
ads_polar(m_ptStart, m_nLockAng, nDist, ptTmp);
|
|
}
|
|
return ptTmp;
|
|
}
|
|
|
|
|
|
// 更新实体数据
|
|
Adesk::Boolean TWellJig::update()
|
|
{
|
|
Adesk::Boolean bRet=Adesk::kTrue;
|
|
|
|
if(!!m_ptMid){ //扇形布置
|
|
XArc arc(m_ptStart, m_ptMid, m_ptEnd);
|
|
XPoint ptBase;
|
|
arc.MidPoint(ptBase);
|
|
double nDist = ads_distance(arc.GetCenterPt(), m_ptResult);
|
|
double nDist2 = ads_distance(ptBase, m_ptResult);
|
|
if(nDist < arc.GetRadius() && nDist2 < arc.GetRadius())
|
|
nDist = arc.GetRadius() - nDist;
|
|
else
|
|
nDist = arc.GetRadius();
|
|
m_pDrawEnt->m_nRadius = nDist;
|
|
}
|
|
else{
|
|
XPoint ptTmp = m_ptResult;
|
|
if(m_nLockAng > -1){
|
|
ptTmp = GetCorrectPt();
|
|
}
|
|
if(m_nDist > 1){
|
|
double nAng = ads_angle(m_ptStart, ptTmp);
|
|
ads_polar(m_ptStart, nAng, m_nDist, ptTmp);
|
|
m_pDrawEnt->m_bNeedText = FALSE;
|
|
}
|
|
else
|
|
m_pDrawEnt->m_bNeedText = TRUE;
|
|
m_ptResult = ptTmp;
|
|
m_pDrawEnt->m_ptEnd = ptTmp;
|
|
}
|
|
return bRet;
|
|
}
|
|
|
|
AcDbEntity* TWellJig::entity() const
|
|
{
|
|
return (AcDbEntity *)m_pDrawEnt;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
CWellPreview::CWellPreview(XPoint ptStart, XPoint ptEnd)
|
|
{
|
|
m_ptStart = ptStart;
|
|
m_ptEnd = ptEnd;
|
|
m_pDrawLine = NULL;
|
|
m_bNeedText = TRUE;
|
|
m_dDist = 0;
|
|
}
|
|
|
|
CWellPreview::~CWellPreview()
|
|
{
|
|
if(m_pDrawLine)
|
|
delete m_pDrawLine;
|
|
}
|
|
|
|
|
|
|
|
Adesk::Boolean CWellPreview::subWorldDraw(AcGiWorldDraw *pWd)
|
|
{
|
|
double nSprinklerRadius = 1;
|
|
//if(g_bEquipByScale)
|
|
// nSprinklerRadius = g_nSprinklerRadius *GlobalFunc::DocGetPScale()/100;
|
|
// else
|
|
// nSprinklerRadius = g_nSprinklerRadius;
|
|
|
|
|
|
if(m_dDist > 0){//两点定距
|
|
if(m_pDrawLine)
|
|
delete m_pDrawLine;
|
|
XLine line(m_ptStart, m_ptEnd, 1);
|
|
XCurveSegment seg;
|
|
m_lstPt.Reset();
|
|
seg = line;
|
|
if(!pWd->isDragging()){
|
|
m_pDrawLine = new AcDbLine(m_ptStart, m_ptEnd);
|
|
m_pDrawLine->worldDraw(pWd);
|
|
}
|
|
GlobalFunc::GetPointList(seg, m_dDist, m_lstPt);
|
|
int len = m_lstPt.Length();
|
|
|
|
for(int i=0;i<len;i++){
|
|
XPoint pt = *m_lstPt[i];
|
|
AcDbCircle cir(pt, AcGeVector3d::kZAxis, nSprinklerRadius);
|
|
cir.worldDraw(pWd);
|
|
}
|
|
}
|
|
else{//任意布置
|
|
XPoint pt = m_ptEnd;
|
|
AcDbCircle cir(pt, AcGeVector3d::kZAxis, nSprinklerRadius);
|
|
cir.worldDraw(pWd);
|
|
|
|
double nDist = ads_distance(m_ptStart, m_ptEnd);
|
|
double nAng = ads_angle(m_ptStart, m_ptEnd);
|
|
XPoint ptText;
|
|
if (nAng > PI/2 && nAng <= PI+PI/2)
|
|
ads_polar(m_ptStart, nAng, nDist/2+3*GlobalFunc::DocGetPScale(), ptText);
|
|
else
|
|
ads_polar(m_ptStart, nAng, nDist/2-3*GlobalFunc::DocGetPScale(), ptText);
|
|
ads_polar(ptText, nAng+PI/2, GlobalFunc::DocGetPScale(), ptText);
|
|
if (nAng > PI/2 && nAng <= PI+PI/2) {
|
|
ads_polar(ptText, nAng-PI/2, GlobalFunc::DocGetPScale()*2, ptText);
|
|
nAng += PI;
|
|
}
|
|
if(m_bNeedText){
|
|
CString csDist;
|
|
csDist.Format(_T("%.0f"), nDist);
|
|
AcDbText text;
|
|
text.setRotation(nAng);
|
|
text.setHeight(3.5*GlobalFunc::DocGetPScale());
|
|
text.setTextString(csDist);
|
|
text.setTextStyle(GlobalFunc::GetTextStyleId(_T("STANDARD")));
|
|
text.setPosition(ptText);
|
|
text.setAlignmentPoint(ptText);
|
|
text.worldDraw(pWd);
|
|
}
|
|
}
|
|
|
|
return Adesk::kTrue;
|
|
}
|