#include "stdafx.h" #include "SinglePlaceTreeDlg.h" #include "rxregsvc.h" #include #include #include "GlwGlobalVariable.h" #include "GlwPlaceTreeDataManage.h" //#include "GlwUIDefine.h" //#define UIFRAME_API __declspec( dllimport ) //#include "GlwUtility.h" #if ADS < 18 #define DBL_MAX 1.7976931348623158e+308 #endif #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // ԭʼԲͼƬelev(00001730) # define SYS_CIRCLETREE _T("TARCH(MULTPLACETREE01)") extern AcDbObjectId InsertBlock(CString &csBlkName, int &iTreeType); double GetRandomSize(double dOrigRad) { double dRand = 0; dRand = (((double) rand() / (double) RAND_MAX) * dOrigRad + dOrigRad*0.5); return dRand; } CSinglePlaceTreeDlg::CSinglePlaceTreeDlg(CWnd* pParent /*=NULL*/) : CModelessDialog(CSinglePlaceTreeDlg::IDD, pParent) { if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); m_iTreeType = pDataManage->GetTreeType(); m_iDrawStyle = pDataManage->GetDrawType(); m_csRad = GetFormatData(pDataManage->GetTreeRad(FALSE)); m_csDis = GetFormatData(pDataManage->GetTreeDis()); m_csOffset = GetFormatData(pDataManage->GetTreeOffset()); m_bIsRandSize = pDataManage->GetIsSetRandomSize(); m_bIsRotation = pDataManage->GetIsSetRotation(); m_bIsSetDis = pDataManage->GetIsSetDis(); m_idTreeStyle = pDataManage->GetTreeId(); m_hIcon = NULL; } // ¸ù¾ÝÐèÇóÐ޸ı༭¿òÖÐÊý¾ÝµÄÏÔʾ¸ñʽ CString CSinglePlaceTreeDlg::GetFormatData(double dData) { CString csTemp; if (DocGetMeterUnitDraw()) { csTemp.Format(_T("%.3f"), dData); } else { csTemp.Format(_T("%.0f"), dData); } return csTemp; } namespace { enum GlwEnum { eLayerName = 0, eLayerOpen, eLayerFrozen, eLayerLocked, eLayerColor, eLayerLType, eLayerLWeight, eLayerPlottable, eLayerDesc, eWinVerOld, eWinVerXp, eWinVerVista, eWinVerWin7, eWinVerWin8, eCADVer2007, eCADVer2008, eCADVer2009, eCADVer2010, eCADVer2011, eCADVer2012, eCADVer2013, eCADVer2014, eCADVer2015, eCADVer2016, eCADVerUnknow, EV_TOP, // ¸©ÊÓ EV_BOTTOM, // ÑöÊÓ EV_LEFT, // ×óÊÓ EV_RIGHT, // ÓÒÊÓ EV_FORNT, // ǰÊÓ EV_BACK, // ºóÊÓ EV_WS, // Î÷ÄÏ EV_ES, // ¶«ÄÏ EV_EN, // ¶«±± EV_WN, // Î÷±± EV_NONE, // ɶҲ²»ÊÇ }; GlwEnum GetCadVer() { TCHAR strVer[20]; TGGetVar(_T("ACADVER"), strVer); CString str = strVer; str = str.Left(4); if (_T("17.0") == str) return eCADVer2007; else if (_T("17.1") == str) return eCADVer2008; else if (_T("17.2") == str) return eCADVer2009; else if (_T("18.0") == str) return eCADVer2010; else if (_T("18.1") == str) return eCADVer2011; else if (_T("18.2") == str) return eCADVer2012; else if (_T("19.0") == str) return eCADVer2013; else if (_T("19.1") == str) return eCADVer2014; else if (_T("20.0") == str) return eCADVer2015; else if (_T("20.1") == str) return eCADVer2016; return eCADVerUnknow; } } //add by yyc Ôö¼Ó´ò¿ªµÄͼֽºÍµ±Ç°´ò¿ªµÄCAD°æ±¾¶Ô±È£¬Í¼Ö½°æ±¾±ÈCAD°æ±¾µÍµÄ½øÐÐÌáʾ //AC1015£ºCAD2000°æ AC1018£ºCAD2004°æ AC1021£ºCAD2007°æ //AC1027£ºCAD2013°æ AC1024£ºCAD2010°æ BOOL JudgeVersion(CString strFile)//Åжϰ汾 { CStdioFile file; file.Open(strFile, CFile::modeRead); CString strFileVersion; file.ReadString(strFileVersion); file.Close(); strFileVersion = strFileVersion.Mid(0, 6); if (strFileVersion.IsEmpty()) return FALSE; if (GetCadVer() == eCADVer2007 && (strFileVersion != _T("AC1027") && strFileVersion != _T("AC1024"))) return TRUE; else if (GetCadVer() == eCADVer2008 && (strFileVersion != _T("AC1027") && strFileVersion != _T("AC1024"))) return TRUE; else if (GetCadVer() == eCADVer2009 && (strFileVersion != _T("AC1027") && strFileVersion != _T("AC1024"))) return TRUE; else if (GetCadVer() == eCADVer2010 && strFileVersion != _T("AC1027")) return TRUE; else if (GetCadVer() == eCADVer2011 && strFileVersion != _T("AC1027")) return TRUE; else if (GetCadVer() == eCADVer2012 && strFileVersion != _T("AC1027")) return TRUE; else if (GetCadVer() == eCADVer2013 ) return TRUE; else if (GetCadVer() == eCADVer2014) return TRUE; else if (GetCadVer() == eCADVer2015) return TRUE; else if (GetCadVer() == eCADVer2016) return TRUE; else return FALSE; } CSinglePlaceTreeDlg::~CSinglePlaceTreeDlg() { // °´Å¥Í¼±êÏú»Ù if (m_hIcon) { ::DestroyIcon(m_hIcon); } // ±£´æÊý¾Ýmmµ¥Î» if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); pDataManage->SetTreeType(m_iTreeType); pDataManage->SetDrawType(m_iDrawStyle); pDataManage->SetTreeRad(_tstof(m_csRad)); pDataManage->SetTreeDis(_tstof(m_csDis)); pDataManage->SetTreeOffset(_tstof(m_csOffset)); pDataManage->SetIsSetRotation(m_bIsRotation); pDataManage->SetIsSetRandSize(m_bIsRandSize); pDataManage->SetIsSetDis(m_bIsSetDis); pDataManage->SetTreeId(m_idTreeStyle); m_PreviewCtrl.clearAll(); } void CSinglePlaceTreeDlg::DoDataExchange(CDataExchange* pDX) { CModelessDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSinglePlaceTreeDlg) DDX_Radio(pDX, IDC_RAD_FROMBLK, m_iTreeType); DDX_Radio(pDX, IDC_RAD_POINT, m_iDrawStyle); DDX_Text(pDX, IDC_EDT_RAD, m_csRad); DDX_Text(pDX, IDC_EDT_DIS, m_csDis); DDX_Text(pDX, IDC_EDT_OFFSET, m_csOffset); //DDV_MinMaxDouble(pDX, m_dOffset, 0, DBL_MAX ); DDX_Check(pDX, IDC_CHK_ROTATION, m_bIsRotation); DDX_Check(pDX, IDC_CHK_SETDIS, m_bIsSetDis); DDX_Check(pDX, IDC_CHK_RAND_SIZE, m_bIsRandSize); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSinglePlaceTreeDlg, CModelessDialog) //{{AFX_MSG_MAP(CMultPlaceTreeDlg) ON_BN_CLICKED(IDC_BUT_PICK, OnBnClickedButPick) ON_BN_CLICKED(IDC_BUT_RAD, OnBnClickedButRad) ON_BN_CLICKED(IDC_BUT_DIS, OnBnClickedButDis) ON_BN_CLICKED(IDC_CHK_RAND_SIZE, OnChkRandSize) ON_BN_CLICKED(IDC_CHK_ROTATION, OnChkRotation) ON_BN_CLICKED(IDC_CHK_SETDIS, OnChkSetDis) ON_WM_PAINT() ON_WM_CLOSE() ON_BN_CLICKED(IDC_RAD_POINT, OnBnClickedDrawStyle) ON_BN_CLICKED(IDC_RAD_JIG, OnBnClickedDrawStyle) ON_BN_CLICKED(IDC_RAD_PATH, OnBnClickedDrawStyle) ON_BN_CLICKED(IDC_RAD_AREA_LAYOUT, OnBnClickedDrawStyle) ON_BN_CLICKED(IDC_RAD_FROMBLK, OnBnClickedTreeFormSelect) ON_BN_CLICKED(IDC_RAD_FROMGALLERY, OnBnClickedTreeFormSelect) ON_BN_CLICKED(IDC_RAD_FROMFILE, OnBnClickedTreeFormSelect) //}}AFX_MSG_MAP //ON_BN_CLICKED(IDC_BUT_OFFSET, OnBnClickedButOffset) ON_EN_CHANGE(IDC_EDT_OFFSET, OnEnChangeEdtOffset) ON_EN_CHANGE(IDC_EDT_RAD, OnEnChangeEdtRad) ON_EN_CHANGE(IDC_EDT_DIS, OnEnChangeEdtDis) END_MESSAGE_MAP() BOOL CSinglePlaceTreeDlg::OnInitDialog() { CModelessDialog::OnInitDialog(); UpdateData(FALSE); UpdateData(TRUE); // °´Å¥Í¼±ê m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON_PICK); if (!m_hIcon) { AfxMessageBox(_T("ÎÞ·¨ÕÒµ½Ö¸¶¨ICONÎļþ¡£")); } else { ((CButton*)GetDlgItem(IDC_BUT_PICK))->SetIcon(m_hIcon); } // »ñÈ¡µ±Ç°µÄ»æÍ¼µ¥Î»£¬¶Ô»°¿ò±êÌâÉèÖà if (DocGetMeterUnitDraw()) { this->SetWindowText(_T("ÈÎÒâ²¼Ê÷(µ¥Î»:M)")); } else { this->SetWindowText(_T("ÈÎÒâ²¼Ê÷(µ¥Î»:mm)")); } AcDbObjectId idBlk; int n = 0; CString csBlkName = _T("tree1"); while(!m_idTreeStyle.isValid())// Óû§Ã»ÓÐÉèֵеÄÊ÷ÐΣ¬Ê¹ÓÃĬÈÏÖµ { m_idTreeStyle = InsertBlock(csBlkName, n); } // add by xly on 110329 ½â¾öͼֽÇл»Ê±£¬·¢Éú±ÀÀ£ if (m_idTreeStyle.database()!=curDoc()->database()) { m_idTreeStyle = InsertBlock(csBlkName, n); } AcDbBlockTableRecord *pBTRecord = NULL; if(acdbOpenObject(pBTRecord, m_idTreeStyle, AcDb::kForRead) != Acad::eOk) { m_idTreeStyle = InsertBlock(csBlkName, n); } else pBTRecord->close(); GetDlgItem(IDC_CHK_SETDIS)->EnableWindow(m_iDrawStyle==2); GetDlgItem(IDC_BUT_DIS)->EnableWindow(!(m_iDrawStyle==0 || m_iDrawStyle==3)); GetDlgItem(IDC_EDT_DIS)->EnableWindow(!(m_iDrawStyle==0 || m_iDrawStyle==3)); UpdateControlState(); GetDlgItem(IDC_BUT_PICK)->SetFocus(); // Ô¤ÀÀ if (!m_PreviewCtrl.SubclassDlgItem(IDC_STATIC_PREVIEW, this)) return FALSE; m_PreviewCtrl.SetOrbitFlag(OBF_ZOOM|OBF_PAN); // add by xly on 110325 ÉèÖÃÏÔʾ·½Ê½ UpdatePreview(); UpdateData(FALSE); return TRUE; } Adesk::Boolean acedPostCommand(const TCHAR * ); void CSinglePlaceTreeDlg::OnClose() { m_bUseEsc = true; if (m_bModeless) { acedPostCommand(_T("\33\33")); } else { CModelessDialog::OnClose(); } } // µ÷Óù¹¼þ¿â BOOL InvokeTkwMan(const TCHAR *pszLib, BOOL bSelOnly, XString &sBlockName) { if (!AT_loaded(_T("wfB"))) { #ifndef ZWCAD int nRet = acrxLoadModule(_T("wfB.arx"), Adesk::kTrue, true); #else int nRet = acrxLoadModule(_T("wfB.zrx"), Adesk::kTrue, true); #endif if (!nRet) { return FALSE; } } int nCode = bSelOnly ? RTT : RTNIL; RBList rbCmd = ads_buildlist(RTSTR, _T("ITkw"), RTSTR, pszLib, nCode, RTSTR, (const TCHAR *)sBlockName, NULL); resbuf *rbRes = NULL; if (ads_invoke(rbCmd, &rbRes)==RTNORM && rbRes) { if (rbRes && rbRes->restype==RTSTR) sBlockName = rbRes->resval.rstring; ads_relrb(rbRes); return TRUE; } return FALSE; } extern AcDbObjectId InsertBlock(CString &csBlkName, int &iTreeType); // »ñµÃÌìÕýͼ¿âÖÐͼ¿éµÄID AcDbObjectId CSinglePlaceTreeDlg::GetTgTreeBlockId(XString sBlockName) { AcDbObjectId idBlock; AcDbBlockTable *pBlockTab = NULL; if (acdbCurDwg()->getSymbolTable(pBlockTab, AcDb::kForWrite) != Acad::eOk) // »ñµÃ¿é±í { return idBlock; } if (pBlockTab->getAt(sBlockName, idBlock, false) == Acad::eOk) // ¼ì²é¿éÊÇ·ñ´æ { pBlockTab->close(); return idBlock; } AcDbBlockTableRecord* pBlkRecord = new AcDbBlockTableRecord; pBlkRecord->setName(sBlockName); if (pBlockTab->add(idBlock, pBlkRecord) != Acad::eOk) { pBlockTab->close(); delete pBlkRecord; return AcDbObjectId::kNull; } pBlkRecord->close(); pBlockTab->close(); return idBlock; } // Ê÷µÄ»æÖÆÀàÐÍ int CSinglePlaceTreeDlg::GetDrawType() { UpdateData(true); return m_iDrawStyle; } // ´°¿ÚÖØ»æÏûÏ¢. void CSinglePlaceTreeDlg::OnPaint() { UpdateData(TRUE); CPaintDC dc(this); CRect rcClip, rcImage; dc.GetClipBox(&rcClip); CWnd *pImageBox = GetDlgItem(IDC_STATIC_PREVIEW); if (pImageBox) { pImageBox->GetWindowRect(&rcImage); ScreenToClient(&rcImage); if (!rcImage.IntersectRect(&rcImage, &rcClip)) return; CDC *pDC = pImageBox->GetDC(); m_imgPreview.SetDC(pDC); m_imgPreview.Redraw(); m_imgPreview.SetDC(NULL); pImageBox->ReleaseDC(pDC); } } // ÉèÖÃ»ÃµÆÆ¬ void CSinglePlaceTreeDlg::SetPicture(CString &csFile) { UpdateData(TRUE); XString sFilePath(256); sFilePath << csFile; // »ñµÃͼƬ¿Ø¼þ CWnd* pWndBmp = GetDlgItem(IDC_STATIC_PREVIEW); ASSERT(pWndBmp); // »ñµÃÍ¼Æ¬ÇøÓò CDC *pDC = pWndBmp->GetDC(); CRect rect; pWndBmp->GetClientRect(rect); m_imgPreview.InitDC(pDC, rect, GetAcadBackColor()); m_imgPreview.PaintSlide(sFilePath); m_imgPreview.SetDC(NULL); pWndBmp->ReleaseDC(pDC); } // »ñµÃ¿éµÄÔ¤ÀÀ void CSinglePlaceTreeDlg::UpdatePreview() { UpdateData(TRUE); m_PreviewCtrl.clearAll(); m_PreviewCtrl.init(true); // Ëø¶¨µ±Ç°Îĵµ acDocManager->lockDocument(curDoc()); // ¿é±í¼Ç¼ AcDbBlockTableRecord *pBTRecord = NULL; if(acdbOpenObject(pBTRecord, m_idTreeStyle, AcDb::kForRead) != Acad::eOk) { return; } // ¶¨Òå±¾Êý¾Ý¿âµÄ¿é±í¼Ç¼ AcDbBlockTableRecordIterator *pItor = NULL; pBTRecord->newIterator(pItor); // Ô¤ÀÀÊý¾Ý¿â AcDbBlockTable *pBlockTab = NULL; Acad::ErrorStatus es = m_PreviewDb.getSymbolTable(pBlockTab, AcDb::kForWrite); if( es !=Acad::eOk) return; // ¶¨ÒåÔ¤ÀÀÊý¾Ý¿âµÄ¿é¼Ç¼ AcDbBlockTableRecord *pBlockTabRecord = new AcDbBlockTableRecord; pBlockTabRecord->setName(_T("*U")); // ½«¿é±íÖÐʵÌåÌí¼Óµ½ÐµÄÊý¾Ý¿âµÄ¿é±í¼Ç¼ÖÐ AcDbEntity *pClone = NULL, *pEnt = NULL; for (; !pItor->done(); pItor->step()) { es = pItor->getEntity(pEnt,AcDb::kForRead,false); if (es != Acad::eOk) { delete pBlockTabRecord; pBlockTab->close(); return; } pClone = (AcDbEntity*)pEnt->clone(); es = pBlockTabRecord->appendAcDbEntity(pClone); if (es != Acad::eOk) { delete pBlockTabRecord; pBlockTab->close(); return; } pClone->close(); pEnt->close(); } delete pItor; pBTRecord->close(); AcDbBlockReference *pRef = new AcDbBlockReference(AcGePoint3d(0,0,0), m_idTreeStyle); // »ñµÃ¿éµÄ°üΧºÐ AcDbExtents extents; pRef->getGeomExtents(extents); // ¿éµÄÍâ°üºÐµÄ½Çµã AcGePoint3d ptLow, ptUp; // »ñµÃͼ¿éµÄ´óС ptLow = extents.minPoint(); ptUp = extents.maxPoint(); double dXWidth = (ptUp.x-ptLow.x), dYHeigh = (ptUp.y-ptLow.y); //pBlockTab->add(pBlockTabRecord); pBlockTab->close(); pBlockTabRecord->close(); // ÉèÖù۲ìλÖà AcGePoint3d ptIns(extents.minPoint()/2 +extents.maxPoint()/2), target = ptIns; AcGePoint3d position(target.x, target.y, 1); m_PreviewCtrl.view()->setView(position, target, AcGeVector3d(0, 1, 0),dXWidth *2, dYHeigh*2); m_PreviewCtrl.view()->add(pBTRecord,m_PreviewCtrl.model()); m_PreviewCtrl.Invalidate(); acDocManager->unlockDocument(curDoc()); UpdateData(FALSE); } // ÉèÖöԻ°¿òÒþ²Ø void CSinglePlaceTreeDlg::SetWindowHide(bool bHide) { if (bHide) // Òþ²Ø { GetParent()->EnableWindow(TRUE); GetParent()->SetFocus(); GetParent()->SetActiveWindow(); ShowWindow(SW_HIDE); } else // ÏÔʾ { GetParent()->EnableWindow(FALSE); EnableWindow(TRUE); SetActiveWindow(); ShowWindow(SW_SHOW); GetParent()->EnableWindow(TRUE); } } // µãȡʰȡ°´Å¥ÊµÏÖ void CSinglePlaceTreeDlg::OnBnClickedButPick() { UpdateData(TRUE); // ͼ¿éµÄID AcDbObjectId endId; AcApDocument *pDoc = acDocManager->curDocument(); // Ñ¡Ôñ²»Í¬µÄÊ÷ÐÎÑ¡Ôñ·½Ê½ switch(m_iTreeType) { case 0: // µãÈ¡±¾Í¼Í¼¿é { SetWindowHide(true); // Ñ¡Ôñͼ¿é Entity ent; int iRet; TADSGePoint3d ptPick; RBList rbList(RTDXF0, _T("INSERT,TCH_BLOCK_INSERT"), NULL); iRet = SelectEntity1(_T("\nÇëÑ¡ÔñÒª²¼ÖõÄͼ¿é<·µ»Ø>£º"), ent,ptPick,rbList); while(iRet == RTERROR) { iRet = SelectEntity1(_T("\nÇëÑ¡ÔñÒª²¼ÖõÄͼ¿é<·µ»Ø>£º"), ent, ptPick,rbList); /*if(iRet == RTNORM) { break; }*/ } if(iRet == RTNORM) // »ñȡͼ¿é³É¹¦ { // Ëø¶¨Îĵµ //acDocManager->lockDocument(pDoc); // »ñµÃ¿é±í¼Ç¼µÄID OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbBlockReference, pBlkRef); m_idTreeStyle = pBlkRef->blockTableRecord(); OPENOBJ_END(); //acDocManager->unlockDocument(pDoc); // Ô¤ÀÀ¿é UpdatePreview(); } /*else if (iRet!=RTNONE)//delete by xly on 110325 Í˳öʱ·µ»Ø¶Ô»°¿ò { return; }*/ SetWindowHide(false); acedGetAcadDwgView()->SetFocus(); // add by xly on 110327 ¸üÐÂÃüÁîÐÐÌáʾ if (m_iDrawStyle==0) { acutPrintf(_T("\nÇëµãÈ¡²åÈëµã<Í˳ö>:")); } else if (m_iDrawStyle==1) { acutPrintf(_T("\nÇëÊäÈëÆðʼµã<Í˳ö>:")); } else if(m_iDrawStyle==2) { acutPrintf(_T("\nÇëÑ¡Ôñ×÷Ϊ·¾¶µÄÇúÏߣ¨Ö±Ïß¡¢Ô²»¡¡¢¶à¶ÎÏߣ©<Í˳ö>:")); } } break; case 1: // ´Óͼ¿âÑ¡Ôñ { // ÕÒµ½sys·¾¶ÏµÄdwgÎļþ CString szFileName = _T("Ö²Îï.TKW"), sLibFile = g_sDwbPath; sLibFile = sLibFile.Left(sLibFile.GetLength() - 5) + _T("\\DWB\\") + szFileName; XString sBlockName; // modify by xly on 110325 ÐÞ¸ÄĬÈÏÖµ //sBlockName= m_csTreeStyle; sBlockName = _T("Ö²Îï(00000092)"); if (InvokeTkwMan(sLibFile, TRUE, sBlockName)) { szFileName = (const TCHAR *)(XPathParser(sBlockName).m_sFileName); sLibFile = g_sDwbPath; CString csPath = sLibFile.Left(sLibFile.GetLength() - 5) + _T("\\DWB\\"); csPath += szFileName; // Ëø¶¨Îĵµ acDocManager->lockDocument(pDoc); int nRet = LoadDwbBlock(csPath,sBlockName); if(nRet == RTNORM) { m_idTreeStyle = InitBlock(sBlockName); //m_csTreeStyle = csPath; } acDocManager->unlockDocument(pDoc); UpdatePreview(); } } break; case 2: // ´ÓÎļþѡȡ { // ¶¨Òå´ò¿ªÎļþ¶Ô»°¿ò CString csFilter = _T("CADͼÐÎÎļþ(*.dwg)|*.dwg"); CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, csFilter, NULL); // ÉèÖöԻ°¿òĬÈϳÊÏֵķ¾¶ CString sLibFile = g_sDwbPath; sLibFile = sLibFile.Left(sLibFile.GetLength() - 5); dlg.m_ofn.lpstrInitialDir = sLibFile; if (dlg.DoModal() != IDOK) return; // »ñµÃÎļþÃû CString strFilePath = dlg.GetPathName(); if (strFilePath.IsEmpty()) return; //ÅжÏͼֽ°æ±¾ºÍµ±Ç°CAD°æ±¾ÊÇ·ñÆ¥Åä if (!JudgeVersion(strFilePath)) { acutPrintf(_T("²»ÄÜ´ò¿ª´Ë DWG Îļþ£¬ÒòΪËüÊÇʹÓøüа汾µÄ AutoCAD ´´½¨µÄ¡£")); acutPrintf(_T("Çë´Ó Autodesk ÏÂÔØ DWG TrueConvert ¹¤¾ß£¬Òѽ« DWG Îļþת»»Îª²»Í¬°æ±¾")); return; } // Ëø¶¨Îĵµ acDocManager->lockDocument(pDoc); // ´ò¿ªdwgÎļþ AcDbDatabase *pXrefDb = new AcDbDatabase(Adesk::kFalse); #if ADS < 21 Acad::ErrorStatus es = pXrefDb->readDwgFile(strFilePath,_SH_DENYNO, false); #else Acad::ErrorStatus es = pXrefDb->readDwgFile(strFilePath, AcDbDatabase::kForReadAndAllShare, false); #endif if (es != Acad::eOk) { delete pXrefDb; return; } // ½«Ê÷ÐÎÎļþÒÔ¿éµÄÐÎʽ²åÈëÊý¾Ý¿â if (acdbCurDwg()->insert(m_idTreeStyle, _T("*UT"), pXrefDb, true) != Acad::eOk) { delete pXrefDb; return ; } delete pXrefDb; acDocManager->unlockDocument(pDoc); // Ô¤ÀÀdwgͼֽ UpdatePreview(); } break; default: break; } if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); pDataManage->SetTreeId(m_idTreeStyle); UpdateData(FALSE); } // Çл»»æÖÆ·½Ê½ void CSinglePlaceTreeDlg::OnBnClickedDrawStyle() { if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); UpdateData(TRUE); GetDlgItem(IDC_CHK_SETDIS)->EnableWindow(m_iDrawStyle==2); // add by xly on 110324 ÈÎÒâ»æÖÆÊ±Ê÷¼ä¾à²»¿ÉÓà if (m_iDrawStyle==0 || m_iDrawStyle==3) GetDlgItem(IDC_BUT_DIS)->EnableWindow(false); if (m_iDrawStyle==0 || m_iDrawStyle==3) { GetDlgItem(IDC_BUT_DIS)->EnableWindow(FALSE); GetDlgItem(IDC_EDT_DIS)->EnableWindow(FALSE); } else { GetDlgItem(IDC_BUT_DIS)->EnableWindow(TRUE); GetDlgItem(IDC_EDT_DIS)->EnableWindow(TRUE); } UpdateControlState(); pDataManage->SetDrawType(m_iDrawStyle); m_bUseEsc = false; acedPostCommand(_T("\33")); } void CSinglePlaceTreeDlg::OnBnClickedTreeFormSelect() { UpdateData(TRUE); if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); pDataManage->SetTreeType(m_iTreeType); } void CSinglePlaceTreeDlg::OnBnClickedButRad() { UpdateData(TRUE); if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); GetDis(m_csRad, true); pDataManage->SetTreeRad(_tstof(m_csRad)); UpdateData(FALSE); } void CSinglePlaceTreeDlg::OnBnClickedButDis() { UpdateData(TRUE); if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); GetDis(m_csDis, false); pDataManage->SetTreeDis(_tstof(m_csDis)); UpdateData(FALSE); } void CSinglePlaceTreeDlg::OnChkRandSize() { UpdateData(TRUE); if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); pDataManage->SetIsSetRandSize(m_bIsRandSize); } void CSinglePlaceTreeDlg::OnChkRotation() { UpdateData(TRUE); if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); pDataManage->SetIsSetRotation(m_bIsRotation); } void CSinglePlaceTreeDlg::OnChkSetDis() { UpdateData(TRUE); if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); pDataManage->SetIsSetDis(m_bIsSetDis); } void CSinglePlaceTreeDlg::OnEnChangeEdtRad() { UpdateData(TRUE); if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); pDataManage->SetTreeRad(_tstof(m_csRad)); } void CSinglePlaceTreeDlg::OnEnChangeEdtDis() { UpdateData(TRUE); if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); pDataManage->SetTreeDis(_tstof(m_csDis)); } // »ñÈ¡µãÈ¡µÄ¾àÀë void CSinglePlaceTreeDlg::GetDis(CString &csLength, bool isRadOrDis) { double nHeight = _tstof(csLength); CString csPrompt = isRadOrDis ? _T("\nÇëµãÈ¡Ê÷°ë¾¶") : _T("\nÇëµãÈ¡Ê÷¼ä¾à"); BeginEditorCommand(); if (GetDist(csPrompt, nHeight, RSG_NOZERO|RSG_NONEG) == RTNORM) { csLength = GetFormatData(nHeight); } CompleteEditorCommand(); } /* void CSinglePlaceTreeDlg::OnBnClickedButOffset() { UpdateData(TRUE); if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); SetWindowHide(TRUE); ads_real dDist; double dOffset = _tstof(m_csOffset); int i=0; CString strTip = _T(""); strTip.Format(_T("ÇëµãÈ¡Æ«ÒÆ¾àÀë<%d>:"), dOffset); if (acedGetDist(NULL, strTip, &dDist) == RTNORM) { dOffset = dDist; } m_csOffset = GetFormatData(dOffset); pDataManage->SetTreeOffset(_tstof(m_csOffset)); UpdateData(FALSE); SetWindowHide(FALSE); } */ int is_digit(WCHAR *str) { size_t len = wcslen(str); size_t lenPre = len; bool bDoubleFlag = false; while(len > 0) { if (len != lenPre && *str == '.' && bDoubleFlag == false)//ÅжÏÊÇ·ñÊÇdoubleÖµ { bDoubleFlag = true; } else if (*str < '0' || *str > '9') { return -1; } str++; len--; } return 0; } void CSinglePlaceTreeDlg::OnEnChangeEdtOffset() { if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage)) SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage); GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage); CString strOffset = _T(""); BOOL bIsNum = FALSE; GetDlgItem(IDC_EDT_OFFSET)->GetWindowText(strOffset); if (strOffset.GetLength() > 0) { if (strOffset.GetAt(0) < '0' || strOffset.GetAt(0) > '9') { AfxMessageBox(_T("ÇëÊäÈë¡Ý0µÄÊýÖµ!")); UpdateData(FALSE); } else { if (strOffset.GetLength() >= 2) { if (strOffset.GetAt(0) == '0') { if (strOffset.GetAt(1) == '.') { CString strTemp; strTemp = strOffset.Right(1); WCHAR *wch = (WCHAR*)strTemp.GetBuffer(strTemp.GetLength()); if (strOffset.GetLength() > 2) { if (is_digit(wch) == -1) { AfxMessageBox(_T("ÇëÊäÈë¡Ý0µÄÊýÖµ!")); UpdateData(FALSE); } else { UpdateData(TRUE); pDataManage->SetTreeOffset(_tstof(m_csOffset)); } } } else { AfxMessageBox(_T("ÇëÊäÈë¡Ý0µÄÊýÖµ!")); UpdateData(FALSE); } } else { WCHAR *wch = (WCHAR*)strOffset.GetBuffer(strOffset.GetLength()); strOffset.ReleaseBuffer(strOffset.GetLength()); //¹ØÓÚСÊýµãµÄÎÊÌâ if (is_digit(wch) == -1) { AfxMessageBox(_T("ÇëÊäÈë¡Ý0µÄÊýÖµ!")); UpdateData(FALSE); } else { UpdateData(TRUE); pDataManage->SetTreeOffset(_tstof(m_csOffset)); } } } else { UpdateData(TRUE); pDataManage->SetTreeOffset(_tstof(m_csOffset)); } } } } void CSinglePlaceTreeDlg::UpdateControlState() { GetDlgItem(IDC_CHK_RAND_SIZE)->EnableWindow(m_iDrawStyle == 0 || m_iDrawStyle == 3); //GetDlgItem(IDC_BUT_OFFSET)->EnableWindow(m_iDrawStyle == 1 || m_iDrawStyle == 2); GetDlgItem(IDC_EDT_OFFSET)->EnableWindow(m_iDrawStyle == 1 || m_iDrawStyle == 2); }