Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

498 lines
13 KiB
C++

// PoolDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PoolDlg.h"
//#include "InsBlockDlg.h"
//#include "aecutil.h" // DragInsertBlock
//#include "DbBlockInsert.h"
#include <xtext.h>
#include <DbEquipment.h>
#include <DbPump.h>
#include <PipeWireMonitor.h>
#include "tapi.h"
#include "twtdef.h"
#include "TBlockInsertEdJig.h"
#include "DbPool.h"
#include "CesspoolCalcDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//extern TARCH_IMPEXP int DragInsertBlock(const TCHAR *szBlock, int nFlag, const AcGeScale3d &scales);
/////////////////////////////////////////////////////////////////////////////
// CPoolDlg dialog
//***************************************************************************************************
// 布置池
//***************************************************************************************************
void InsOutDoorPoolCmd()
{
// cet 2011.5.26 add 设置捕捉点
int nOsMode=0;
xg_getvar(_T("OSMODE"), &nOsMode);
nOsMode &= ~0x4000;
nOsMode |= OS_INT|OS_END|OS_NEA;
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
CString csDwb = g_csDwbPath + _T("TwtSys");
XString xsTmp1, xsTmp2, xsTmp3, xsTmp4, xsTmp5, xsTmp6;
if(LoadDwbBlock(csDwb, _T("00000353"), xsTmp1) != RTNORM) //化粪池
return;
if(LoadDwbBlock(csDwb, _T("00000354"), xsTmp2) != RTNORM) //隔油池
return;
if(LoadDwbBlock(csDwb, _T("00000355"), xsTmp3) != RTNORM) //沉淀池
return;
if(LoadDwbBlock(csDwb, _T("00000356"), xsTmp4) != RTNORM) //降温池
return;
if(LoadDwbBlock(csDwb, _T("00000357"), xsTmp5) != RTNORM) //中和池
return;
if(LoadDwbBlock(csDwb, _T("00000399"), xsTmp6) != RTNORM) //化粪池
return;
g_csInsBlkName = (const TCHAR*)xsTmp1;
AcDbObjectId idBlock=InitBlock(g_csInsBlkName);
if(!idBlock) {
return;
}
XPoint ptIns;
InitLayer(LAY_TWT_OUT);
XPushVarStr clayer(_T("CLAYER"), LAY_TWT_OUT);
xg_getvar(_T("VIEWCTR"), ptIns);
ptIns = Ucs2Wcs(ptIns);
XVector3D vtNormal=Ucs2Wcs(XVector3D(0,0,1), TRUE);
((AcGeVector3d &)vtNormal).normalize();
AcDbEntity *pDragEnt=NULL;
TDbBlockInsert *pInsert = new TDbBlockInsert;
pInsert->setBlockTableRecord(idBlock);
pInsert->setPosition(ptIns);
pInsert->setRotation(ads_angle(XPoint(), Ucs2Ecs(XVector3D(1,0,0), vtNormal, TRUE)));
pInsert->setNormal(vtNormal);
pInsert->setScaleFactors(AcGeScale3d(CPoolDlg::m_nX,CPoolDlg::m_nY,1));
pDragEnt=pInsert;
InitTwtTextStyle(g_csTwtDimStyle);
CPoolDlg dlg(pInsert, acedGetAcadFrame());
{
CTemporaryResourceOverride vTemp;
dlg.Create(IDD_POOL, acedGetAcadFrame());
}
pInsert->setScaleFactors(AcGeScale3d(CPoolDlg::m_nX,CPoolDlg::m_nY,1));
TBlockInsertEdJig2 jig(pInsert, ptIns);
jig.SetPrompt(_T("\n请点取池插入点[90度翻转(R)]<退出>:"));
// jig.SetKeyword(_T("A S D E R T W"));
jig.SetOperCode(TBlockInsertEdJig2::kMove);
dlg.ShowWindow(SW_SHOW);
acedGetAcadDwgView()->SetFocus();
CString csText;
int nRoTateNum = 0; // cet 2011.5.25 add 旋转次数
while(1){
dlg.UpdateData(TRUE);
if(dlg.m_iType == 0){
g_csInsBlkName = (const TCHAR*)xsTmp1;
csText = _T("HC");
}
else if(dlg.m_iType == 1){
g_csInsBlkName = (const TCHAR*)xsTmp2;
csText = _T("YC");
}
else if(dlg.m_iType == 2){
g_csInsBlkName = (const TCHAR*)xsTmp3;
csText = _T("CC");
}
else if(dlg.m_iType == 3){
g_csInsBlkName = (const TCHAR*)xsTmp4;
csText = _T("JC");
}
else if(dlg.m_iType == 4){
g_csInsBlkName = (const TCHAR*)xsTmp5;
csText = _T("ZC");
}
else if(dlg.m_iType == 5){
g_csInsBlkName = (const TCHAR*)xsTmp6;
csText = _T("HC");
}
idBlock=InitBlock(g_csInsBlkName);
if(idBlock == NULL)
break;
jig.SetBlockId(idBlock);
jig.SetKeyword(_T("W R"));
int nKeyIndex=0;
int nRet=jig.DoIt(&nKeyIndex);
ptIns=jig.GetPickPoint();
if(nRet==RTNORM) {
pInsert->setScaleFactors(AcGeScale3d(CPoolDlg::m_nX,CPoolDlg::m_nY,1));
double nRotate = pInsert->rotation();
double nElevation(0);
int iPipeIdx(0);
Entity entWire = GetPipeByPt(ptIns, nElevation, iPipeIdx);
if(!!entWire){
XPoint pt3, pt4;
GetPipePoint(entWire, pt3, pt4);
nRotate = ads_angle(pt3, pt4);
}
if(nRotate > (PI*2 - 0.001))
nRotate -= PI*2;
//放置位置有导线才旋转180度
if(!!entWire)
{
if(nRotate > (PI - 0.001))
nRotate -= PI;
}
XPoint ptText = ptIns;
XPoint ptPos = pInsert->position();
if (!DocGetMeterUnitDraw())
{
ads_polar(ptText, nRotate + PI/2, dlg.m_nY/2+g_nTwtDimHeight*DocGetPScale()/2, ptText);
ads_polar(ptText, nRotate, dlg.m_nX/2+g_nTwtDimHeight*DocGetPScale()/2, ptText);
}
else
{
ads_polar(ptText, nRotate + PI/2, dlg.m_nY/2+g_nTwtDimHeight*DocGetPScale()/2/10, ptText);
ads_polar(ptText, nRotate, dlg.m_nX/2+g_nTwtDimHeight*DocGetPScale()/2/10, ptText);
}
TDbPool *pEquip = new TDbPool;
pEquip->SetBlock2d(idBlock);
pEquip->SetPoolLength(dlg.m_nX);
pEquip->SetPoolWidth(dlg.m_nY);
pEquip->SetAngle(0.0);
pEquip->SetLabelLayer(InitLayer(LAY_TEXT));
pEquip->SetLabel(csText);
pEquip->SetTextStyleId(InitTextStyle(g_csTwtDimStyle));
double dTextRotate = Ucs2Wcs(0.0);
if (dTextRotate > PI/2 && dTextRotate < PI*3/2)
dTextRotate += PI;
pEquip->SetLocation(ptPos);
pEquip->SetLabelLocation(ptText);
pEquip->SetTextRotation(dTextRotate);
if (!DocGetMeterUnitDraw())
pEquip->SetTextHeight(g_nTwtDimHeight);
else
pEquip->SetTextHeight(g_nTwtDimHeight/10);
pEquip->EnableDrawLabel(TRUE);
AcDbExtents extents;
AcGeScale3d scale(1);
double x = 0, y = 0;
GetInsertExtend(idBlock, x, y);
if (x > 1.0E-3)
scale.sx *= dlg.m_nX*x;
if (y > 1.0E-3)
scale.sy *= dlg.m_nY*y;
//求图块边缘点
AcDbBlockReference insert(ptPos, idBlock);
insert.setScaleFactors(scale);
if(insert.geomExtentsBestFit(extents)==Acad::eOk)
{
XPoint ptMax = extents.maxPoint();
XPoint ptMin = extents.minPoint();
XPoint ptInter1,ptInter2;
AcGeVector3d vtDir = AcGeVector3d::kXAxis;
nRoTateNum %= 4;
double dLen = dlg.m_nX;
if (nRoTateNum == 1 || nRoTateNum == 3)
{
vtDir = AcGeVector3d::kYAxis;
dLen = dlg.m_nY;
}
AcGePoint3d ptPosT = ptPos;
ptPosT.z = 0;
AcDbLine line(ptPosT + vtDir*dLen*3/4,ptPosT - vtDir*dLen*3/4);
AcDbPolyline polyLine;
AcGePoint3d pt1 = ptMin;
AcGePoint3d pt2 = pt1 + vtDir*dLen*x;
AcGePoint3d pt3 = ptMax;
AcGePoint3d pt4 = pt3 - vtDir*dLen*x;
polyLine.addVertexAt(0,pt1.convert2d(AcGePlane::kXYPlane));
polyLine.addVertexAt(1,pt2.convert2d(AcGePlane::kXYPlane));
polyLine.addVertexAt(2,pt3.convert2d(AcGePlane::kXYPlane));
polyLine.addVertexAt(3,pt4.convert2d(AcGePlane::kXYPlane));
polyLine.addVertexAt(4,pt1.convert2d(AcGePlane::kXYPlane));
AcGePoint3dArray arPts;
polyLine.intersectWith(&line,AcDb::kOnBothOperands,arPts);
if (arPts.length() == 2)
{
pEquip->AddInterface(_T("1"),arPts[0],XVector3D(vtDir));
pEquip->AddInterface(_T("2"),arPts[1],XVector3D(vtDir));
}
}
// cet 2011.5.25 add
if(!!entWire)// zxl 2013.12.09 add
{
if (nRoTateNum == 1)
{
nRotate += PI / 2;
}
else if (nRoTateNum == 2)
{
nRotate += PI;
}
else if (nRoTateNum == 3)
{
nRotate += PI * 1.5;
}
}
pEquip->SetAngle(nRotate);
AcDbObjectId idPool = AddToCurrentSpace(pEquip, Adesk::kTrue);
TPipePerDocData *pData = GetCurPipeDocData();
pData->ApplyUpdates();
OPENOBJ_BEGIN(idPool, AcDb::kForWrite, TDbPool, pPool);
pPool->UpdataPipeInterface();
OPENOBJ_END();
// cet 2013.3.6 add 实时更新池与管线
pData->ApplyUpdates();
}
else if(nRet==RTKWORD)
{
if (nKeyIndex == 1)// zxl 2013.12.09 add 只有输入R时才旋转
{
++nRoTateNum;// cet 2011.5.25 add
}
continue;
}
else
break;
jig.SetRefPoint(ptIns);
}
delete pDragEnt;
dlg.DestroyWindow();
}
IMPLEMENT_DYNAMIC(CPoolDlg, CModelessDialog)
double CPoolDlg::m_nX = 1750;
double CPoolDlg::m_nY = 1050;
CPoolDlg::CPoolDlg(AcDbEntity *pInsert, CWnd* pParent /*=NULL*/)
: CModelessDialog(CPoolDlg::IDD, pParent), m_pInsert(pInsert)
{
//{{AFX_DATA_INIT(CPoolDlg)
m_iType = 0;
//}}AFX_DATA_INIT
}
void CPoolDlg::DoDataExchange(CDataExchange* pDX)
{
CModelessDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPoolDlg)
DDX_Radio(pDX, IDC_RADIO_TYPE1, m_iType);
DDX_Text(pDX, IDC_EDIT_LEN, m_nX);
DDX_Text(pDX, IDC_EDIT_WIDTH, m_nY);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPoolDlg, CModelessDialog)
//{{AFX_MSG_MAP(CPoolDlg)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_RADIO_TYPE1, OnRadioType1)
ON_BN_CLICKED(IDC_RADIO_TYPE2, OnRadioType2)
ON_BN_CLICKED(IDC_RADIO_TYPE3, OnRadioType3)
ON_BN_CLICKED(IDC_RADIO_TYPE4, OnRadioType4)
ON_BN_CLICKED(IDC_RADIO_TYPE5, OnRadioType5)
ON_WM_PAINT()
ON_EN_KILLFOCUS(IDC_EDIT_LEN, OnKillfocusEditLen)
ON_EN_KILLFOCUS(IDC_EDIT_WIDTH, OnKillfocusEditWidth)
ON_BN_CLICKED(IDC_BUTTON_CALC, OnButtonCalc)
ON_BN_CLICKED(IDC_RADIO_TYPE6, OnRadioType6)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPoolDlg message handlers
void CPoolDlg::OnClose()
{
CModelessDialog::OnClose();
acedPostCommand(_T("\33\33"));
}
void CPoolDlg::PostNcDestroy()
{
CModelessDialog::PostNcDestroy();
}
void CPoolDlg::OpenSlide()
{
UpdateData();
CWnd *pWnd = GetDlgItem(IDC_PREVIEW1);
CString csTmp;
csTmp.Format(_T("TWT(POOL%d)"), m_iType + 1);
DrawSlide(csTmp, pWnd);
}
void CPoolDlg::OnRadioType1()
{
CWnd *pWnd = GetDlgItem(IDC_BUTTON_CALC);
pWnd->EnableWindow(TRUE);
OpenSlide();
PostCommand(_T("W "), false);
}
void CPoolDlg::OnRadioType2()
{
CWnd *pWnd = GetDlgItem(IDC_BUTTON_CALC);
pWnd->EnableWindow(FALSE);
OpenSlide();
PostCommand(_T("W "), false);
}
void CPoolDlg::OnRadioType3()
{
CWnd *pWnd = GetDlgItem(IDC_BUTTON_CALC);
pWnd->EnableWindow(FALSE);
OpenSlide();
PostCommand(_T("W "), false);
}
void CPoolDlg::OnRadioType4()
{
CWnd *pWnd = GetDlgItem(IDC_BUTTON_CALC);
pWnd->EnableWindow(FALSE);
OpenSlide();
PostCommand(_T("W "), false);
}
void CPoolDlg::OnRadioType5()
{
CWnd *pWnd = GetDlgItem(IDC_BUTTON_CALC);
pWnd->EnableWindow(FALSE);
OpenSlide();
PostCommand(_T("W "), false);
}
void CPoolDlg::OnRadioType6()
{
CWnd *pWnd = GetDlgItem(IDC_BUTTON_CALC);
pWnd->EnableWindow(FALSE);
OpenSlide();
PostCommand(_T("W "), false);
}
BOOL CPoolDlg::OnInitDialog()
{
CModelessDialog::OnInitDialog();
OpenSlide();
if(DocGetMeterUnitDraw() && m_nX > 100 && m_nY > 100){
m_nX = m_nX / 1000;
m_nY = m_nY / 1000;
UpdateData(FALSE);
}
if(!DocGetMeterUnitDraw() && m_nX < 100 && m_nY < 100){
m_nX = m_nX * 1000;
m_nY = m_nY * 1000;
UpdateData(FALSE);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPoolDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
OpenSlide();
}
void CPoolDlg::SetFromBlockInfo()
{
if (m_pInsert == NULL)
return;
AcDbBlockReference *pBlockInsert=AcDbBlockReference::cast(m_pInsert);
AcDbBlockReference &entInsert=*pBlockInsert;
TBlockGeomInfo geom;
geom.SetFromInsert(&entInsert);
AcGeScale3d scales=entInsert.scaleFactors();
m_nX=scales[0];
m_nY=scales[1];
UpdateData(FALSE);
}
void CPoolDlg::UpdateInsert()
{
UpdateData(TRUE);
if (m_pInsert == NULL)
return;
AcDbBlockReference *pBlockInsert=AcDbBlockReference::cast(m_pInsert);
AcGeScale3d scales(1);
scales.sx *= m_nX;
scales.sy *= m_nY;
AcDbBlockReference &entInsert=*pBlockInsert;
entInsert.setScaleFactors(scales);
UpdateData(FALSE);
}
void CPoolDlg::OnKillfocusEditLen()
{
UpdateInsert();
}
void CPoolDlg::OnKillfocusEditWidth()
{
UpdateInsert();
}
void CPoolDlg::OnButtonCalc()
{
CTemporaryResourceOverride vTemp;
CCesspoolCalcDlg dlg;
dlg.SetPoolLen(m_nX);
dlg.SetPoolWidth(m_nY);
dlg.DoModal();
m_nX = dlg.GetPoolLen();
m_nY = dlg.GetPoolWidth();
if(DocGetMeterUnitDraw() && m_nX > 100 && m_nY > 100){
m_nX = m_nX / 1000;
m_nY = m_nY / 1000;
}
if(!DocGetMeterUnitDraw() && m_nX < 100 && m_nY < 100){
m_nX = m_nX * 1000;
m_nY = m_nY * 1000;
}
UpdateData(FALSE);
UpdateInsert();
//acedPostCommand(_T("\33\33"));
// PostCommand(_T("hfc "), false);
}