236 lines
5.2 KiB
C++
236 lines
5.2 KiB
C++
#include "StdAfx.h"
|
|
#include "FireExtinguisherJig.h"
|
|
#include "LayFireExtinguisherDlg.h"
|
|
|
|
/////////////////////////////////////////////////////
|
|
FireExtinguisherJig::FireExtinguisherJig( CLayFireExtinguisherDlg *pDlg, CDbFireExtinguisher *pEnt, int nType)
|
|
{
|
|
m_pDlg = pDlg;
|
|
m_pEnt = pEnt;
|
|
m_nKeyWordIndex = -1;
|
|
m_nType = nType;
|
|
}
|
|
|
|
int FireExtinguisherJig::doIt()
|
|
{
|
|
acedGetAcadDwgView()->SetFocus(); //屏幕菜单点取时, 命令焦点没有在图形窗口
|
|
DragStatus st;
|
|
m_nKeyWordIndex = -1;
|
|
setDispPrompt(m_sTip);
|
|
bool bKeyWord = !m_sKeyWord.IsEmpty();
|
|
if (bKeyWord)
|
|
{
|
|
INITGET_BEG(-1, m_sKeyWord);
|
|
}
|
|
st = drag();
|
|
if (bKeyWord)
|
|
{
|
|
INITGET_END();
|
|
}
|
|
return GetRetCode(st);
|
|
}
|
|
|
|
AcEdJig::DragStatus FireExtinguisherJig::sampler()
|
|
{
|
|
setUserInputControls((UserInputControls)
|
|
(AcEdJig::kAccept3dCoordinates|AcEdJig::kNullResponseAccepted));
|
|
if (!m_sKeyWord.IsEmpty())
|
|
{
|
|
setKeywordList(m_sKeyWord);
|
|
}
|
|
else
|
|
{
|
|
setKeywordList(NULL);
|
|
}
|
|
|
|
AcGePoint3d ptTemp;
|
|
DragStatus st = acquirePoint(ptTemp);
|
|
if (st == AcEdJig::kNormal)
|
|
{
|
|
if (ptTemp.distanceTo(m_ptIns) > 0.001)
|
|
{
|
|
m_ptIns = ptTemp;
|
|
}
|
|
else
|
|
{
|
|
return AcEdJig::kNoChange;
|
|
}
|
|
}
|
|
return st;
|
|
}
|
|
|
|
extern bool GetBlkSize(const CString &sBlkName, const AcGeScale3d &scale, double &dWidth, double &dHeight);
|
|
extern double GetPtinsToExtentBottomDist(const CString &sBlkName);
|
|
Adesk::Boolean FireExtinguisherJig::update()
|
|
{
|
|
// zxl 2014.01.15 add
|
|
m_pDlg->UpdateData(TRUE);
|
|
double dScale = m_pDlg->GetScale();
|
|
if (m_pDlg->m_nScale == 0)
|
|
{
|
|
dScale *= (GlobalFunc::DocGetPScale() / 100);
|
|
}
|
|
XPoint pt = m_ptIns;
|
|
if (m_nType == 0)
|
|
{
|
|
m_pEnt->SetLocation(pt);
|
|
}
|
|
|
|
double dAngle = m_pEnt->GetAngle();
|
|
if (m_nType == 1)
|
|
{
|
|
pt = m_pEnt->GetLocation();
|
|
AcGeVector3d vt = (XPoint)m_ptIns - m_pEnt->GetLocation();
|
|
AcGeVector3d vtLoc = AcGeVector3d::kXAxis;
|
|
vtLoc.rotateBy(dAngle, AcGeVector3d::kZAxis);
|
|
if (fabs(vtLoc.angleTo(vt, AcGeVector3d::kZAxis)) >= PI)
|
|
{
|
|
dAngle = GlobalFunc::AngleRangeTo2PI(dAngle + PI);
|
|
m_pEnt->SetAngle(dAngle);
|
|
}
|
|
|
|
double dScale = m_pDlg->GetScale() * GlobalFunc::DocGetPScale() / 100;
|
|
double dDist = GetPtinsToExtentBottomDist(m_pDlg->GetSelBlkName()) * dScale;
|
|
AcGeVector3d vtMove = AcGeVector3d::kXAxis;
|
|
vtMove = vtMove.rotateBy(dAngle + PI / 2, AcGeVector3d::kZAxis);
|
|
pt = m_ptOnLine + vtMove * dDist;
|
|
m_pEnt->SetLocation(pt);
|
|
}
|
|
AcGeScale3d scale(dScale);
|
|
double dWidth = 0.0, dHeight = 0.0;
|
|
CString sBlkName = m_pDlg->GetSelBlkName();
|
|
GetBlkSize(sBlkName, scale, dWidth, dHeight);
|
|
|
|
XPoint ptTextIns;
|
|
AcGeVector3d vtDir = AcGeVector3d::kXAxis;
|
|
vtDir.rotateBy(dAngle, AcGeVector3d::kZAxis);
|
|
if (m_pDlg->GetLayDimType() == 0) // 按数量布置
|
|
{
|
|
if (m_pEnt->GetDimTextPos()) // 文字在上方
|
|
{
|
|
vtDir.rotateBy(PI/2, AcGeVector3d::kZAxis);
|
|
ptTextIns = pt + vtDir * dHeight * 1.2;
|
|
}
|
|
else // 文字在下方
|
|
{
|
|
vtDir.rotateBy(-PI/2, AcGeVector3d::kZAxis);
|
|
ptTextIns = pt + vtDir * dHeight * 0.2;
|
|
}
|
|
}
|
|
else // 单布
|
|
{
|
|
ptTextIns = pt + vtDir * dWidth * 0.7;
|
|
}
|
|
|
|
dAngle = GlobalFunc::Wcs2Ucs(dAngle);
|
|
if(m_pDlg->GetLayDimType() != 0)
|
|
{
|
|
if (dAngle - 7 * PI / 4 < 0.001 && dAngle - PI * 3 / 4 > 0.001)
|
|
{
|
|
ptTextIns = pt - vtDir * dWidth * 0.7;
|
|
}
|
|
else
|
|
{
|
|
ptTextIns = pt + vtDir * dWidth * 0.7;
|
|
}
|
|
}
|
|
|
|
double dAngUcs = dAngle;
|
|
AcGiViewDraw::TextAlignment align = AcGiViewDraw::kCenter;
|
|
if (dAngUcs - 7 * PI / 4 < 0.001 && dAngUcs - PI * 3 / 4 > 0.001)
|
|
{
|
|
dAngUcs -= PI;
|
|
if (m_pDlg->GetLayDimType() == 1)
|
|
{
|
|
align = AcGiViewDraw::kTopLeft;
|
|
}
|
|
else
|
|
{
|
|
align = AcGiViewDraw::kTopCenter;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (m_pDlg->GetLayDimType() == 1)
|
|
{
|
|
align = AcGiViewDraw::kBottomLeft;
|
|
}
|
|
else
|
|
{
|
|
align = AcGiViewDraw::kBottomCenter;
|
|
}
|
|
}
|
|
m_pEnt->SetTextRotation(GlobalFunc::Ucs2Wcs(dAngUcs));
|
|
m_pEnt->SetTextAlignment(align);
|
|
|
|
m_pEnt->SetLayType(m_pDlg->GetLayDimType());
|
|
m_pEnt->SetBlock2d(GlobalFunc::GetBlkIdByName(m_pDlg->GetSelBlkName()));
|
|
m_pEnt->SetTextHeight(m_pDlg->GetTextHeight());
|
|
m_pEnt->SetTextStyleId(GlobalFunc::GetTextStyleId(m_pDlg->GetTextStyle()));
|
|
CString sProtectRadius;
|
|
sProtectRadius.Format(_T("%.3f"), m_pDlg->GetProtectRadius());
|
|
m_pEnt->SetProtectRadius(_tstof(sProtectRadius));
|
|
m_pEnt->SetSpec(m_pDlg->GetSpecification());
|
|
m_pEnt->SetLabelLoc(ptTextIns);
|
|
|
|
m_pEnt->SetNum(m_pDlg->GetCount());
|
|
m_pEnt->SetIsDim(m_pDlg->IsDim()? true:false);
|
|
m_pEnt->SetScale(m_pDlg->GetScale());
|
|
m_pEnt->SetScaleType(m_pDlg->m_nScale);
|
|
return Adesk::kTrue;
|
|
}
|
|
|
|
AcDbEntity* FireExtinguisherJig::entity() const
|
|
{
|
|
return m_pEnt;
|
|
}
|
|
|
|
void FireExtinguisherJig::SetScale( double dScale )
|
|
{
|
|
m_pEnt->SetScale(dScale);
|
|
}
|
|
|
|
void FireExtinguisherJig::SetRotate( double dAngle )
|
|
{
|
|
m_pEnt->SetAngle(dAngle);
|
|
}
|
|
|
|
void FireExtinguisherJig::SetKeyWord( const CString &sKeyWord )
|
|
{
|
|
m_sKeyWord = sKeyWord;
|
|
}
|
|
|
|
void FireExtinguisherJig::SetTipPrompt( const CString &sTip )
|
|
{
|
|
m_sTip = sTip;
|
|
}
|
|
|
|
int FireExtinguisherJig::GetRetCode( int nRetCode)
|
|
{
|
|
int nRet = nRetCode;
|
|
if (nRet == AcEdJig::kCancel)
|
|
{
|
|
nRet = RTCAN;
|
|
}
|
|
else if(nRet == AcEdJig::kNull)
|
|
{
|
|
nRet = RTNONE;
|
|
}
|
|
else if (nRet <= 0)
|
|
{
|
|
nRet = RTNORM;
|
|
}
|
|
else
|
|
{
|
|
m_nKeyWordIndex = nRet-1;
|
|
nRet = RTKWORD;
|
|
}
|
|
return nRet;
|
|
}
|
|
|
|
int FireExtinguisherJig::GetKeyWordIndex()
|
|
{
|
|
return m_nKeyWordIndex;
|
|
}
|
|
|