// SPSheet.cpp : implementation file // #include "stdafx.h" #include "CurtainWallSet.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSPSheet IMPLEMENT_DYNAMIC(CSPSheet, CPropertySheet) int CSPSheet::cur=0; CSPSheet::CSPSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage) :CPropertySheet(nIDCaption, pParentWnd, iSelectPage) { CSPSheet::cur=0; } CSPSheet::CSPSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage) :CPropertySheet(pszCaption, pParentWnd, iSelectPage) { CSPSheet::cur=0; } CSPSheet::~CSPSheet() { } BEGIN_MESSAGE_MAP(CSPSheet, CPropertySheet) ON_BN_CLICKED(IDOK, OnOK) ON_WM_DESTROY() END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSPSheet message handlers void CSPSheet::OnOK() { BOOL bOK=true; for(long i=0;iGetSafeHwnd()!=NULL) bOK=pageList[i]->UpdateData(); } if (bOK) { cur=pageList.Find(GetActivePage()); EndDialog(IDOK); } } void CSPSheet::AddPage(CPropertyPage*pPage) { pageList.AddTail(pPage); CPropertySheet::AddPage(pPage); } BOOL CSPSheet::OnInitDialog() { BOOL bResult = CPropertySheet::OnInitDialog(); HWND hWnd = ::GetDlgItem(m_hWnd, ID_APPLY_NOW); if (hWnd != NULL) { ::ShowWindow(hWnd, SW_HIDE); ::EnableWindow(hWnd, FALSE); } hWnd = ::GetDlgItem(m_hWnd, IDHELP); if (hWnd != NULL) { ::ShowWindow(hWnd, SW_HIDE); ::EnableWindow(hWnd, FALSE); } if (pageList.IsValidIndex(cur)) SetActivePage(pageList[cur]); return bResult; } void CSPSheet::OnDestroy() { while(GetPageCount() > 0) { RemovePage(0); } for(long i=0;iGetSafeHwnd()!=NULL) { pageList[i]->DestroyWindow(); } } CPropertySheet::OnDestroy(); } ///////////////////////////////////////////////////////////////////////////// // CCurtainWallSet property page extern bool SelectString(CComboBox&cb,CString s); BOOL CCurtainWallSet::bHAverage = TRUE; BOOL CCurtainWallSet::bVAverage = TRUE; BOOL CCurtainWallSet::bBotFrame = FALSE; BOOL CCurtainWallSet::bTopFrame = FALSE; int CCurtainWallSet::hNum = 6; int CCurtainWallSet::vNum = 6; CString CCurtainWallSet::layer =LAY_3DGLASS; IMPLEMENT_DYNCREATE(CCurtainWallSet, CPropertyPage) CCurtainWallSet::CCurtainWallSet() : CPropertyPage(CCurtainWallSet::IDD),hListBox(false,30),vListBox(false,30)//modified { sHeight = (const TCHAR *)Dist2Str(DocGetLHeight()); vListBox.SetRowSel(false); hListBox.SetRowSel(false); vListBox.SetColFixLength(); vListBox.SetRowFixLength(); hListBox.SetColFixLength(); hListBox.SetRowFixLength(); hListBox.SetColPosFix(); vListBox.SetColPosFix(); hListBox.SetSortEnable(false); vListBox.SetSortEnable(false); hListBox.SetColNum(2); vListBox.SetColNum(2); hListBox.SetRowNum(hNum); vListBox.SetRowNum(vNum); hListBox.GetCol(0).SetReadOnly(); hListBox.GetCol(0).SetName(_T("行号")); hListBox.GetCol(1).SetName(_T("行高")); vListBox.GetCol(0).SetReadOnly(); vListBox.GetCol(0).SetName(_T("列号")); vListBox.GetCol(1).SetName(_T("列宽")); InitLayer(LAY_3DGLASS, FALSE); bCreate=true; } CCurtainWallSet::~CCurtainWallSet() { } void CCurtainWallSet::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); DDX_Control(pDX, IDC_LAYER, layerCombo); DDX_Control(pDX, IDC_VSPIN, vSpin); DDX_Control(pDX, IDC_HSPIN, hSpin); DDX_Check(pDX, IDC_HCHECK, bHAverage); // DDX_Text(pDX, IDC_HNUM, hNum);//del by fxj 090409 // DDV_MinMaxInt(pDX, hNum, 1, 10000);//del by fxj 090331 DDX_Text(pDX, IDC_HEIGHT, sHeight); DDX_Text(pDX, IDC_LENGTH, sLength); DDX_Check(pDX, IDC_VCHECK, bVAverage); // DDX_Text(pDX, IDC_VNUM, vNum);//del by fxj 090409 // DDV_MinMaxInt(pDX, vNum, 1, 10000);//del by fxj 090331 DDX_Check(pDX, IDC_BOTFRAME, bBotFrame); DDX_Check(pDX, IDC_TOPFRAME, bTopFrame); DDX_CBString(pDX, IDC_LAYER, layer); if (pDX->m_bSaveAndValidate) { //---------add by fxj 090409--- CString sHnum,sVnum; int iHnum,iVnum; DDX_Text(pDX, IDC_HNUM, sHnum); DDX_Text(pDX, IDC_VNUM, sVnum); #ifdef UNICODE iHnum=_wtoi(sHnum); iVnum=_wtoi(sVnum); #else iHnum=atoi(sHnum); iVnum=atoi(sVnum); #endif if (iHnum>0&&iHnum<10000) hNum=iHnum; if (iVnum>0&&iVnum<10000) vNum=iVnum; //--------------------------- CString text; for(long i=0;iFail(); } } for(i=0;iFail(); } } } else {//add by fxj 090409 CString sHnum,sVnum; sHnum.Format(_T("%d"),hNum); sVnum.Format(_T("%d"),vNum); DDX_Text(pDX, IDC_HNUM, sHnum); DDX_Text(pDX, IDC_VNUM, sVnum); } } void CCurtainWallSet::Init(TDbCurtainWall&cWall,bool bOut) { if (bOut) { cWall.SetHeight(_tstof(sHeight)); cWall.SetRowAverage(bHAverage); cWall.SetColAverage(bVAverage); cWall.SetRowNum(hNum); cWall.SetColNum(vNum); cWall.SetBotRow(bBotFrame); cWall.SetTopRow(bTopFrame); CString l0=_T("0"); cWall.SetLayerGlass3d(layer==l0?NULL:InitLayer(layer, FALSE)); cWall.m_rowSpaces.Reset(); cWall.m_colSpaces.Reset(); if (!bHAverage) for(int i=0;iGetWindowText(str); #ifdef UNICODE num=_wtoi(str); #else num=atoi(str); #endif if (num<1||num>10000) { // AfxMessageBox(_T("请输入一个整数")); CDataExchange dxOut(this,false); DDX_Text(&dxOut, IDC_HNUM, hNum); GetDlgItem(IDC_HNUM)->SetFocus(); } } void CCurtainWallSet::OnKillFocusVnum()//add by fxj 090423 { CString str; int num; GetDlgItem(IDC_VNUM)->GetWindowText(str); #ifdef UNICODE num=_wtoi(str); #else num=atoi(str); #endif if (num<1||num>10000) { // AfxMessageBox(_T("请输入一个整数")); CDataExchange dxOut(this,false); DDX_Text(&dxOut, IDC_VNUM, vNum); GetDlgItem(IDC_VNUM)->SetFocus(); } } void CCurtainWallSet::OnChangeHnum()//modified { //---------modified by fxj 090409--------- int num; CString snum; CDataExchange dx(this,true); DDX_Text(&dx,IDC_HNUM,snum); #ifdef UNICODE num=_wtoi(snum); #else num=atoi(snum); #endif //---------------------------------- if (num>0&&num<1000) { if (hListBox.IsValidRow(hNum-1)) hListBox.GetRow(hNum-1).SetReadOnly(false); hNum=num; hListBox.SetRowNum(num); hListBox.GetRow(hNum-1).SetReadOnly(); CString sNum,sSpace; sSpace=Dist2Str(_tstof(sHeight)/num); for(long i=0;i0&&num<1000) { if (vListBox.IsValidRow(vNum-1)) vListBox.GetRow(vNum-1).SetReadOnly(false); vNum=num; vListBox.SetRowNum(vNum); vListBox.GetRow(vNum-1).SetReadOnly(); CString sNum,sWidth; sWidth=Dist2Str(_tstof(sLength)/vNum);//modified for(long i=0;i1E-9) { double temp=(double)hListBox.GetCell(hNum-1,1); hListBox.GetCell(hNum-1,1).SetText(Dist2Str(temp+_tstof(sHeight)-oldHeight)); hListBox.GetCell(hNum-1,1).Refresh(); } } void CCurtainWallSet::OnChangeRowHeight()//modidied { bHAverage=false; double height=0; for(long i=0;i0) sWidth=Dist2Str(cWall.GetColU()); //else // sWidth.Format(_T("%d"),(int)cWall.m_uCol); //if (cWall.m_vCol-(int)cWall.m_vCol>0) // modify by xly on 101101 设置竖挺截面长=左宽+右宽 //sLength=Dist2Str(cWall.GetColV()); double dWith = cWall.GetColV(); sLength=Dist2Str(dWith); //else // sLength.Format(_T("%d"),(int)cWall.m_vCol); layer=cWall.GetLayerCol3d()?GetSymbolName(cWall.GetLayerCol3d()):_T("0"); } else { bHide=cWall.IsRowHide(); //if (cWall.m_uRow-(int)cWall.m_uRow>0) sWidth=Dist2Str(cWall.GetRowU()); //else // sWidth.Format(_T("%d"),(int)cWall.m_uRow); //if (cWall.m_vRow-(int)cWall.m_vRow>0) sLength=Dist2Str(cWall.GetRowV()); //else // sLength.Format(_T("%d"),(int)cWall.m_vRow); if (!bHide) offset=(int)cWall.GetRowDist(); layer=cWall.GetLayerRow3d()?GetSymbolName(cWall.GetLayerRow3d()):_T("0"); } } } void CGlassFrameSet::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); DDX_Control(pDX, IDC_LAYER, layCombo); DDX_Control(pDX, IDC_LENGTH, lengthCombo); DDX_Control(pDX, IDC_WIDTH, widthCombo); DDX_Control(pDX, IDC_BASELINE,baseCombo); DDX_Control(pDX, IDC_OFFSET_SPIN, offsetSpin); DDX_Control(pDX, IDC_PREVIEW, preViewWnd); DDX_Check(pDX, IDC_HIDE, bHide); DDX_CBString(pDX, IDC_LENGTH, sLength); DDX_Text(pDX, IDC_OFFSET, offset); DDX_CBString(pDX, IDC_WIDTH, sWidth); DDX_CBString(pDX, IDC_LAYER, layer); } BEGIN_MESSAGE_MAP(CGlassFrameSet, CPropertyPage) //{{AFX_MSG_MAP(CGlassFrameSet) ON_EN_CHANGE(IDC_OFFSET, OnChangeOffset) ON_CBN_EDITCHANGE(IDC_LENGTH, OnEditchangeLength) ON_CBN_SELCHANGE(IDC_LENGTH, OnSelchangeLength) ON_CBN_SELCHANGE(IDC_BASELINE, OnSelchangeBase) ON_BN_CLICKED(IDC_HIDE, OnHide) ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() void CGlassFrameSet::OnDestroy() { CPropertyPage::OnDestroy(); bValidWnd=false; } void CGlassFrameSet::SetBaseType(int t,int pos) { baseType=t; baseCombo.SetCurSel(baseType); if (bVFrame) { preViewWnd.SetBaseLine(pos); if (pBuddy != NULL && ::IsWindow(pBuddy->m_hWnd)) pBuddy->SetBaseType(t,pos); } } void CGlassFrameSet::SetGlassOffset(int of) {//处理玻璃偏移值变化,以及由此发生的所有相关变化 if (bVFrame) { SetOffset(of);//更新玻璃偏移记录 if (bHide)//调整演示窗中的玻璃偏移。 preViewWnd.SetFrameHide(); else preViewWnd.SetGlassOffset(of); preViewWnd.Invalidate();//显示刷新 if (pBuddy != NULL && ::IsWindow(pBuddy->m_hWnd)) pBuddy->SetGlassOffset(of);//更新横框设置 } else { offsetSpin.SetRange(-_ttoi(sLength)/2+of,_ttoi(sLength)/2+of);//调整横框偏移区间 int newOf=offset+of-oldGlassOffset;//,oldGlassOffset必须始终有效。 if (newOf>=(-_ttoi(sLength)/2+of)&&newOf<=(_ttoi(sLength)/2+of)) SetOffset(newOf);//横框与玻璃相对位置不变,更新横框偏移记录 //否则已经无法保持原相对位置,则取最近点. else if (newOf<-_ttoi(sLength)/2+of) SetOffset(-_ttoi(sLength)/2+of); else SetOffset(_ttoi(sLength)/2+of); oldGlassOffset=of; preViewWnd.SetGlassOffset(of);//更新演示窗中的玻璃位置 if (bHide)//调整演示窗中的横框偏移。 preViewWnd.SetFrameHide(); else preViewWnd.SetFrameOffset(offset); } } BOOL CGlassFrameSet::OnInitDialog() { CPropertyPage::OnInitDialog(); bValidWnd=true; XSymbolList lstLayer(_T("LAYER")); lstLayer.QuickSort(_tcsicmp); for(int i=0;iGetDlgItemText(IDC_OFFSET,temp); if (temp!="-" && temp!="")// [11/16/2007 nsh] { CDataExchange dx(this,true); DDX_Text(&dx, IDC_OFFSET, offset); if (bVFrame) SetGlassOffset(offset); else { preViewWnd.SetFrameOffset(offset); preViewWnd.Invalidate(); } }// [11/16/2007 nsh] } void CGlassFrameSet::OnEditchangeLength() { CDataExchange dx(this,true); DDX_CBString(&dx, IDC_LENGTH, sLength); if (_tstof(sLength)<=0) return; preViewWnd.SetLength(_ttoi(sLength)); if (bVFrame) OnSelchangeBase(); else { offsetSpin.SetRange(-_ttoi(sLength)/2+GetGlassOffset(),_ttoi(sLength)/2+GetGlassOffset()); if (bHide) { bHide=false; OnHide(); } else { SetOffset(GetGlassOffset());//玻璃居中 preViewWnd.SetFrameOffset(offset); } preViewWnd.Invalidate(); } } void CGlassFrameSet::OnSelchangeLength() { if (lengthCombo.GetCurSel()>=0) lengthCombo.GetLBText(lengthCombo.GetCurSel(),sLength); if (_tstof(sLength)<=0) return; preViewWnd.SetLength(_ttoi(sLength)); if (bVFrame) OnSelchangeBase(); else { offsetSpin.SetRange(-_ttoi(sLength)/2+GetGlassOffset(),_ttoi(sLength)/2+GetGlassOffset()); if (bHide) { bHide=false; OnHide(); } else { SetOffset(GetGlassOffset());//玻璃居中 preViewWnd.SetFrameOffset(offset); } preViewWnd.Invalidate(); } } void CGlassFrameSet::OnSelchangeBase() {//处理基线位置变化而引起的所有相关变化 if (!bVFrame) return; if (baseCombo.GetCurSel()==0) { SetBaseType(baseCombo.GetCurSel(),-_ttoi(sLength)/2); offsetSpin.SetRange(0,_ttoi(sLength)); } else if (baseCombo.GetCurSel()==2) { SetBaseType(baseCombo.GetCurSel(),_ttoi(sLength)/2); offsetSpin.SetRange(-_ttoi(sLength),0); } else { SetBaseType(baseCombo.GetCurSel(),0); offsetSpin.SetRange(-_ttoi(sLength)/2,_ttoi(sLength)/2); } if (bHide)//维持隐框状态 { bHide=false; OnHide(); } else//偏移回零 SetGlassOffset(0); } void CGlassFrameSet::OnHide() {//处理隐框动作,也可用来初始化隐框状态。 bHide=!bHide; if (bHide) { if (bVFrame) { //对话框中的偏移数据保持真实偏移,不计玻璃厚度 if (baseType==0) SetGlassOffset(_ttoi(sLength)); else if (baseType==2) SetGlassOffset(0); else SetGlassOffset(_ttoi(sLength)/2); } else { //对话框中的偏移数据保持真实偏移,不计玻璃厚度 SetOffset(GetGlassOffset()-_ttoi(sLength)/2); preViewWnd.SetFrameHide(); preViewWnd.Invalidate(); } GetDlgItem(IDC_OFFSET)->EnableWindow(false); GetDlgItem(IDC_OFFSET_SPIN)->EnableWindow(false); } else { //显示真实值 if (bVFrame) preViewWnd.SetGlassOffset(offset); else preViewWnd.SetFrameOffset(offset); preViewWnd.Invalidate(); GetDlgItem(IDC_OFFSET)->EnableWindow(true); GetDlgItem(IDC_OFFSET_SPIN)->EnableWindow(true); } } ///////////////////////////////////////////////////////////////////////////// // CWndPreView CWndPreView::CWndPreView() { glassBrush.CreateSolidBrush(RGB(0,255,255)); frameBrush.CreateSolidBrush(RGB(170,150,50)); glassOffset=frameOffset=0; basePos=0; SetLength(100); bVFrame=true; } CWndPreView::~CWndPreView() { } BEGIN_MESSAGE_MAP(CWndPreView, CWnd) //{{AFX_MSG_MAP(CWndPreView) ON_WM_PAINT() ON_WM_ERASEBKGND() ON_WM_CREATE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CWndPreView message handlers void CWndPreView::OnPaint() { CPaintDC dc(this); // device context for painting CRect rect; GetClientRect(&rect); dc.IntersectClipRect(rect); double cy=rect.bottom/extent,cx=rect.right/extent; if (bVFrame) dc.SetViewportOrg(rect.right/2,rect.bottom/2); else dc.SetViewportOrg((int)(rect.right/2-glassOffset*cx),rect.bottom/2); dc.SelectObject(&glassBrush); dc.Rectangle(int(cx*(-thick/2+glassOffset+basePos)),rect.bottom/2,int(cx*(thick/2+glassOffset+basePos)),-rect.bottom/2); dc.SelectObject(&frameBrush); if (bVFrame) dc.Rectangle(int(-cx*length/2),int(cy*width/2),int(cx*length/2),int(-cy*width/2)); else dc.Rectangle(int(cx*(-length/2+frameOffset)),int(cy*width/2),int(cx*(length/2+frameOffset)),int(-cy*width/2)); CFont font1,font2; font1.CreateFont(15,7,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,18,_T("Arial")); font2.CreateFont(15,7,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,18,_T("Arial")); dc.SetBkMode(TRANSPARENT); dc.SetTextColor(RGB(255,255,255)); dc.SelectObject(&font1); dc.SetTextAlign(TA_LEFT|TA_BOTTOM); dc.TextOut(int(cx*(-length/2+frameOffset)),int(-cy*width/2),_T("长")); dc.SetTextColor(RGB(255,255,255)); dc.SelectObject(&font2); dc.TextOut(int(cx*(length/2+frameOffset)),int(cy*width/2),_T("宽")); CPen pen(2,1,RGB(255,0,0)); dc.SelectObject(&pen); dc.MoveTo(int(basePos*cx),rect.bottom/2); dc.LineTo(int(basePos*cx),-rect.bottom/2); } BOOL CWndPreView::OnEraseBkgnd(CDC* pDC) { CBrush brush; brush.CreateSolidBrush(RGB(0,0,0)); pDC->SelectObject(&brush); CRect rect; GetClientRect(&rect); pDC->Rectangle(rect); return true; } int CWndPreView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CWnd::OnCreate(lpCreateStruct) == -1) return -1; return 0; }