200 lines
5.3 KiB
C++
200 lines
5.3 KiB
C++
// ValveEditDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include <DbPipeValve.h>
|
|
|
|
#include "ValveEditDlg.h"
|
|
#include "SelectBlkDlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
int EditValve(AcDbObjectId id)
|
|
{
|
|
if(!id)
|
|
return RTERROR;
|
|
CTemporaryResourceOverride vTemp;
|
|
CValveEditDlg dlg;
|
|
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipeValve, pValve);
|
|
if(pValve){
|
|
AcDbObjectId eqId = pValve->GetBlock2d();
|
|
dlg.m_csBlkName = GetBlkNameById(eqId);
|
|
dlg.m_nX = pValve->GetScale();
|
|
dlg.m_nY = pValve->GetYScale();
|
|
dlg.m_bFlange = pValve->HasFlange();
|
|
dlg.m_nFlange = pValve->GetFlangeDn();
|
|
dlg.m_nWidth = pValve->GetFlangeWidth();
|
|
dlg.m_dLen = GetValveWidth(dlg.m_csBlkName)*dlg.m_nX;
|
|
double dW = pValve->GetWidth();
|
|
if(fabs(dlg.m_nY) < 0.001)
|
|
dlg.m_nY = dlg.m_nX;
|
|
if(dlg.m_nWidth < 0.001)
|
|
dlg.m_nWidth = 0;
|
|
}
|
|
OPENOBJ_END();
|
|
if(dlg.DoModal() != IDOK)
|
|
return RTNORM;
|
|
OPENOBJ_BEGIN(id, AcDb::kForWrite, TDbPipeValve, pValve);
|
|
if(pValve){
|
|
double nWidth = GetValveWidth(dlg.m_csBlkName);
|
|
pValve->SetWidth(nWidth);
|
|
if(dlg.m_iType == 0)
|
|
pValve->SetScale(dlg.m_nX);
|
|
else{
|
|
double nScale = dlg.m_dLen/nWidth;
|
|
pValve->SetScale(nScale);
|
|
}
|
|
pValve->SetBlock2d(GetBlkIdByName(dlg.m_csBlkName));
|
|
pValve->SetYScale(dlg.m_nY);
|
|
pValve->SetHasFlange(dlg.m_bFlange);
|
|
pValve->SetFlangeDn(dlg.m_nFlange);
|
|
pValve->SetFlangeWidth(dlg.m_nWidth);
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
|
|
return RTNORM;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CValveEditDlg dialog
|
|
|
|
|
|
CValveEditDlg::CValveEditDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CValveEditDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CValveEditDlg)
|
|
m_nX = 0.0;
|
|
m_nY = 0.0;
|
|
m_bFlange = FALSE;
|
|
m_nFlange = 0.0;
|
|
m_nWidth = 0.0;
|
|
m_dLen = 0.0;
|
|
m_iType = 0;
|
|
//}}AFX_DATA_INIT
|
|
}
|
|
|
|
|
|
void CValveEditDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CValveEditDlg)
|
|
DDX_Text(pDX, IDC_EDIT_X, m_nX);
|
|
DDX_Text(pDX, IDC_EDIT_Y, m_nY);
|
|
DDX_Check(pDX, IDC_CHECK_FLANGE, m_bFlange);
|
|
DDX_Text(pDX, IDC_EDIT_FLANGE, m_nFlange);
|
|
DDX_Text(pDX, IDC_EDIT_FL_WIDTH, m_nWidth);
|
|
DDX_Text(pDX, IDC_EDIT_LEN, m_dLen);
|
|
DDX_Radio(pDX, IDC_RADIO_TYPE1, m_iType);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CValveEditDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CValveEditDlg)
|
|
ON_WM_PAINT()
|
|
ON_BN_CLICKED(IDC_PREVIEW, OnPreview)
|
|
ON_BN_CLICKED(IDC_CHECK_FLANGE, OnCheckFlange)
|
|
ON_BN_CLICKED(IDC_RADIO_TYPE1, OnRadioType1)
|
|
ON_BN_CLICKED(IDC_RADIO_TYPE2, OnRadioType2)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CValveEditDlg message handlers
|
|
|
|
void CValveEditDlg::OnPaint()
|
|
{
|
|
CPaintDC dc(this); // device context for painting
|
|
OpenSlide();
|
|
}
|
|
|
|
void CValveEditDlg::OpenSlide()
|
|
{
|
|
UpdateData(TRUE);
|
|
CWnd *pImageBox1 = GetDlgItem(IDC_PREVIEW);
|
|
CString csSldName;
|
|
CString csTK, csRecord;
|
|
SplitBlkStr(m_csBlkName, csTK, csRecord);
|
|
csSldName.Format(_T("%s(%s)"), csTK, csRecord);
|
|
DrawSlide((const TCHAR*)csSldName, pImageBox1);
|
|
}
|
|
|
|
BOOL CValveEditDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
OnCheckFlange();
|
|
OpenSlide();
|
|
OnRadioType1();
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CValveEditDlg::OnPreview()
|
|
{
|
|
CString csSldName;
|
|
CString csTK, csRecord;
|
|
SplitBlkStr(m_csBlkName, csTK, csRecord);
|
|
csSldName.Format(_T("VALVE(%s)"), csRecord);
|
|
CString csType = GetTgBlkTypeInTk(m_csBlkName);
|
|
CTemporaryResourceOverride vTemp;
|
|
CSelectBlkDlg dlg;
|
|
dlg.m_csTkName = _T("VALVE");
|
|
dlg.m_csType = csType;
|
|
CWnd *pWnd = GetDlgItem(IDC_PREVIEW);
|
|
CRect rect;
|
|
dlg.m_staticSlide.m_csCurRecord = csSldName;
|
|
pWnd->GetWindowRect(&rect);
|
|
dlg.m_ptBase = rect.TopLeft();
|
|
if(dlg.DoModal() == IDOK){
|
|
CString csRet = dlg.m_staticSlide.m_csCurRecord;
|
|
XString xsTKName, xsRocord, xsTmp;
|
|
SplitSlbName(csRet, xsTKName, xsRocord);
|
|
AcDbDatabase *dwg=acdbCurDwg();
|
|
AcAxDocLock docLock(dwg);
|
|
VERIFY(docLock.lockStatus() == Acad::eOk);
|
|
if(LoadDwbBlock((const TCHAR*)xsTKName, (const TCHAR*)xsRocord, xsTmp) != RTNORM)
|
|
return;
|
|
m_csBlkName = (const TCHAR*)xsTmp;
|
|
OpenSlide();
|
|
}
|
|
}
|
|
|
|
void CValveEditDlg::OnCheckFlange()
|
|
{
|
|
UpdateData(TRUE);
|
|
CWnd *pWnd1 = GetDlgItem(IDC_EDIT_FLANGE);
|
|
CWnd *pWnd2 = GetDlgItem(IDC_EDIT_FL_WIDTH);
|
|
if(m_bFlange){
|
|
pWnd1->EnableWindow(TRUE);
|
|
pWnd2->EnableWindow(TRUE);
|
|
}
|
|
else{
|
|
pWnd1->EnableWindow(FALSE);
|
|
pWnd2->EnableWindow(FALSE);
|
|
}
|
|
}
|
|
|
|
void CValveEditDlg::OnRadioType1()
|
|
{
|
|
UpdateData(TRUE);
|
|
CWnd *pWnd1 = GetDlgItem(IDC_EDIT_X);
|
|
CWnd *pWnd2 = GetDlgItem(IDC_EDIT_LEN);
|
|
pWnd1->EnableWindow(TRUE);
|
|
pWnd2->EnableWindow(FALSE);
|
|
}
|
|
|
|
void CValveEditDlg::OnRadioType2()
|
|
{
|
|
UpdateData(TRUE);
|
|
CWnd *pWnd1 = GetDlgItem(IDC_EDIT_X);
|
|
CWnd *pWnd2 = GetDlgItem(IDC_EDIT_LEN);
|
|
pWnd1->EnableWindow(FALSE);
|
|
pWnd2->EnableWindow(TRUE);
|
|
}
|