// SplitDwgDlg.cpp : implementation file // #include "stdafx.h" //#include #include "dbidmap.h" #include "tapi.h" #include "SplitDwgDlg.h" #include "BrowseForFolder2.h" #include "DbPsConfig.h" #include #include "CompareDwg.h" #include #include #ifdef _WIN64 #import "msxml6.dll" #else #import "msxml4.dll" #endif // WIN64 #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //extern GEOAPI int SearchOutRegions(const DList &lstSeg1In, DList &lstDest); //extern GEOAPI BOOL arxWBlock(PickSet &ss, const TCHAR* szFileName, XPoint ptIns); extern TARCH_IMPEXP bool OpenProjectDwg(CString szDwgFullName);//打开工程文件,不存在则尝试新建 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 备档拆图 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void SplitPath(const TCHAR* pathName, CString &filePath, CString &fileName) { TCHAR drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]=_T(""); _tsplitpath(pathName, drive, dir, fname, ext); filePath.Format(_T("%s%s"), drive, dir); fileName.Format(_T("%s"), fname); } CString GetCurDwgPath() { const TCHAR* sBuf=NULL; acdbCurDwg()->getFilename(sBuf); if(sBuf==NULL) return _T(""); CString sDwgFilePath(sBuf); CString sPrjPath,sPrjName,sDwgPath,sDwgName; sDwgFilePath.MakeUpper(); SplitPath(sDwgFilePath,sDwgPath,sDwgName); sDwgPath += sDwgName; return sDwgPath; } //打开工程文件,并ZOOM E void OpenDwgFile(void *pData) { TContextOpen *pContext = (TContextOpen *)pData; //如果调用之前使用本应用的资源重载,这里必须push/pop ACAD的资源 acDocManager->pushAcadResourceHandle(); AcApDocument *pOldDoc=curDoc(); if (acDocManager->isApplicationContext()) { if(pContext->bClose) acDocManager->enableDocumentActivation(); if(acDocManager->appContextOpenDocument(pContext->szFileName)==Acad::eOk) { if(pContext->bClose) acDocManager->activateDocument(curDoc()); PostCommand(_T("zoom e "), false); acedPostCommand(_T("QSAVE\n")); if(pContext->bClose) acedPostCommand(_T("close\n")); // sr remove it 2008-9-12 06以上平台崩溃,TAB冲突 } } // if(!pContext->bClose) // sr remove it 2010-5-4 acDocManager->activateDocument(pOldDoc); acDocManager->popResourceHandle(); return; } // 把指定的文档置为活动文档 2006-12-7 UINT ActiveDoc(LPVOID pParam) { //传进来的参数必须是 TCHAR *pStr = (TCHAR *)pParam; CString csParam = (LPCTSTR)pParam; delete[] pStr; AcApDocumentIterator*pIter=acDocManager->newAcApDocumentIterator(); if(pIter!=NULL) { for(;!pIter->done();pIter->step()) { AcApDocument*pDoc2=pIter->document(); CString csName = pDoc2->fileName(); if(_tcsicmp(csName, csParam) == 0){ CDocument *pDoc3 = pDoc2->cDoc(); POSITION pos = pDoc3->GetFirstViewPosition(); CView* pView = pDoc3->GetNextView(pos); acedGetAcadFrame()->MDIActivate(pView->GetParent()); acDocManager->activateDocument(acDocManager->mdiActiveDocument()); break; } } delete pIter; } return 1; } void GetTitleBlkOutRegion(Entity ent, XPoly2D &poly) { DList lstSegs; GetCurveFromInsert2D(ent, lstSegs); for(int i=0; i lstPoly; //得到所以外框闭合poly SearchOutRegions(lstSegs, lstPoly); if(lstPoly.Length() == 1){ poly = *lstPoly[0]; } } void SplitDwg3() { AcDbDatabase db; Acad::ErrorStatus esDist=Acad::eOk; AcDbDictionary* pRootDict=NULL; esDist=db.getNamedObjectsDictionary(pRootDict,AcDb::kForWrite); if (esDist==Acad::eOk) { AcDbObjectId idRet; TDbConfig *pConfig3 = new TDbConfig; pRootDict->setAt(_T("ATS_DBCONFIG"), pConfig3, idRet); pConfig3->close(); pRootDict->close(); } db.saveAs(_T("d:\\abc.dwg")); return; } bool GetPolyById(AcDbObjectId &id, AcDbPolyline *&polyEnt) { AcDbBlockReference *pBlkRef = NULL; AcDbExtents ext; XPoint ptLow, ptUp; acdbOpenObject(pBlkRef, id, AcDb::kForWrite); if (!pBlkRef) { return false; } double dAngle = pBlkRef->rotation(); pBlkRef->setRotation(Wcs2Ucs(0.0)); pBlkRef->getGeomExtents(ext); AcGeMatrix3d mat; mat.setToRotation(dAngle - Wcs2Ucs(0.0), AcGeVector3d::kZAxis, pBlkRef->position()); pBlkRef->transformBy(mat); pBlkRef->close(); ptUp = ext.maxPoint(); ptLow = ext.minPoint(); ptLow.z = 0; ptUp.z =0; XPoint ptMaxLeft(ptLow[0], ptUp[1], 0); XPoint ptMinRight(ptUp[0], ptLow[1], 0); polyEnt->addVertexAt(0, ptLow); polyEnt->addVertexAt(1, ptMinRight); polyEnt->addVertexAt(2, ptUp); polyEnt->addVertexAt(3, ptMaxLeft); polyEnt->setClosed(Adesk::kTrue); polyEnt->transformBy(mat); return true; } // 利用ss中的圆和闭合PLINE,过滤掉集合ss中的图块 // 过滤条件:图块完全在圆内或闭合PLINE时包括有重合边界的图块 void EarseBlkByPloy(PickSet &ss) { // 过滤图块类型 INSERT,AEC_BLOCK_INSERT,ATS_MVINSERT Entity ent; TDPtrList lstPLine; TDPtrList lstCir; std::map mapEnt; AcDbPolyline *pLine = NULL; AcDbCircle *pCir = NULL; for (long l = 0; l < ss.Length(); l++) { ent = ss[l]; // 找出ss中的圆和闭合PLINE if (ent.Is(_T("LWPOLYLINE")) || ent.Is(_T("CIRCLE"))) { if (ent.Is(_T("LWPOLYLINE"))) { XPoly2D poly(ent); if (!poly.IsClosed()) { continue; } pLine = new AcDbPolyline; for (int i = 0; i < poly.Length(); i++) { XPoint *pt = poly.GetPointListAt(i); AcGePoint2d pt2d(pt->x, pt->y); pLine->addVertexAt(i, pt2d); } pLine->setClosed(Adesk::kTrue); lstPLine.Append(pLine); } else { XCircle cir(ent); pCir = new AcDbCircle; pCir->setRadius(cir.GetRadius()); pCir->setCenter(cir.GetCenterPt()); lstCir.Append(pCir); } } else { AcDbEntity *pEnt = NULL; AcDbObjectId id; AcDbPolyline *polyEnt = new AcDbPolyline; acdbGetObjectId(id, ent); if (GetPolyById(id, polyEnt)) { mapEnt.insert(std::make_pair(id, polyEnt)); } } } // 利用图块外包框当作图块边界 std::map::iterator itMap = mapEnt.begin(); AcGePoint3dArray ptArry; for (; itMap != mapEnt.end(); itMap++) { bool bIsDel = false; for (int i = 0; i < lstPLine.Length(); i++)//和闭合Pline线比较 { pLine = lstPLine[i]; ptArry.setLogicalLength(0); (*itMap).second->intersectWith(pLine, AcDb::kOnBothOperands, ptArry); if (ptArry.length() < 1 || ptArry.length() > 2) { AcGePoint3d ptStart, ptEnd; (*itMap).second->getPointAt(0, ptStart); (*itMap).second->getPointAt(2, ptEnd); AcDbLine line; line.setStartPoint(ptStart); line.setEndPoint(ptEnd); ptArry.setLogicalLength(0); line.intersectWith(pLine, AcDb::kExtendThis, ptArry); if (ptArry.length() == 2) { AcGeVector3d vec1 = ptStart - ptArry[0]; AcGeVector3d vec2 = ptStart - ptArry[1]; vec1.normalize(); vec2.normalize(); if (vec1 != vec2) { ads_name name; Entity entDel; acdbGetAdsName(name, itMap->first); entDel = name; ss -= entDel; bIsDel = true; } } } } if (bIsDel) { continue; } for (int j = 0; j < lstCir.Length(); j++)//和圆比较 { pCir = lstCir[j]; ptArry.setLogicalLength(0); (*itMap).second->intersectWith(pCir, AcDb::kOnBothOperands, ptArry); if (ptArry.length() < 1 || ptArry.length() > 2) { AcGePoint3d ptStart, ptEnd; (*itMap).second->getPointAt(0, ptStart); (*itMap).second->getPointAt(2, ptEnd); AcDbLine line; line.setStartPoint(ptStart); line.setEndPoint(ptEnd); ptArry.setLogicalLength(0); line.intersectWith(pCir, AcDb::kExtendThis, ptArry); if (ptArry.length() == 2) { AcGeVector3d vec1 = ptStart - ptArry[0]; AcGeVector3d vec2 = ptStart - ptArry[1]; vec1.normalize(); vec2.normalize(); if (vec1 != vec2) { ads_name name; Entity entDel; acdbGetAdsName(name, itMap->first); entDel = name; ss -= entDel; } } } } } for (itMap = mapEnt.begin(); itMap != mapEnt.end(); itMap++) { delete (*itMap).second; (*itMap).second = NULL; } } ////////////////////////////////////////////////////////////////////////////////////////////////////// MSXML2::IXMLDOMDocument2Ptr LoadXMLFile( LPCTSTR path) { do{ ::CoInitialize(NULL); MSXML2::IXMLDOMDocument2Ptr pXMLDoc; HRESULT hr; #ifndef _WIN64 hr = pXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40)); #else hr = pXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60)); #endif if (!SUCCEEDED(hr)) break; pXMLDoc->async = false; pXMLDoc->validateOnParse = true; if (pXMLDoc->load(_bstr_t(path)) != VARIANT_TRUE) break; return pXMLDoc; }while(false); return NULL; } void GetTitleTag(CString &csDawingNoTag, CString &csDawingNameTag, CString &csDawingSplitSign, CString &csDawingNoSign) { XString sTitlename; csDawingNoTag = _T("图号"); csDawingNameTag = _T("图名"); if (FindFile(_T("TTitleFrame.xml"), sTitlename)) { MSXML2::IXMLDOMDocument2Ptr pXMLDoc = LoadXMLFile(sTitlename); if(!pXMLDoc) { return; } MSXML2::IXMLDOMElementPtr pXMLEl = pXMLDoc->GetdocumentElement(); if (!pXMLEl) return; MSXML2::IXMLDOMNamedNodeMapPtr pMap(NULL); MSXML2::IXMLDOMNodePtr pNodePtrValue(NULL); pMap = pXMLEl->Getattributes(); if (pMap) { pNodePtrValue = pMap->getNamedItem(_T("NameTag")); if (pNodePtrValue) { csDawingNameTag = pNodePtrValue->GetnodeValue(); } pNodePtrValue = pMap->getNamedItem(_T("NoTag")); if (pNodePtrValue) { csDawingNoTag = pNodePtrValue->GetnodeValue(); } pNodePtrValue = pMap->getNamedItem(_T("SplitSign")); if (pNodePtrValue) { csDawingSplitSign = pNodePtrValue->GetnodeValue(); } pNodePtrValue = pMap->getNamedItem(_T("SpNoSign")); if (pNodePtrValue) { csDawingNoSign = pNodePtrValue->GetnodeValue(); } } } } // 遍历所有图块得到属性定义 BOOL GetBlockAttribute(AcDbBlockReference *pRef, CString csDawingNoTag, CString csDawingNameTag, CString csDawingSplitSign, CString &csDawingNo, CString &csDawingName) { /* BOOL bFlag = FALSE; CString szName; AcDbVoidPtrArray arEnts; pRef->explode(arEnts); for (int j = 0; j < arEnts.length(); ++j) { AcDbEntity *pEnt = (AcDbEntity*)arEnts[j]; AcDbAttributeDefinition *pAtt = NULL; AcDbBlockReference *pBlock = NULL; if(pAtt = AcDbAttributeDefinition::cast(pEnt)) { CString szTag = pAtt->tag(); if(csDawingNoTag.Find(szTag) > -1) { csDawingNo = pAtt->textString(); bFlag = TRUE; } else if(csDawingNameTag.Find(szTag) > -1) { csDawingName += pAtt->textString(); bFlag = TRUE; } } else if(pBlock = AcDbBlockReference::cast(pEnt)) { GetBlockAttribute(pBlock,csDawingNoTag, csDawingNameTag, csDawingNo, csDawingName); } } ReleaseEntSet(arEnts); return bFlag; */ AcDbObjectIterator *pAttIter = NULL; pAttIter = pRef->attributeIterator(); if(pAttIter == NULL) return FALSE; BOOL bFlag = FALSE; CString szName; for(pAttIter->start(); !pAttIter->done(); pAttIter->step()) { AcDbEntity *pEnt = NULL; AcDbObjectId eId = pAttIter->objectId(); if(acdbOpenAcDbEntity(pEnt, eId, AcDb::kForRead) != Acad::eOk) continue; AcDbAttribute *pAtt = AcDbAttribute::cast(pEnt); if(pAtt == NULL) continue; CString szTag = pAtt->tag(); if(csDawingNoTag.Find(szTag) > -1) { csDawingNo = pAtt->textString(); bFlag = TRUE; } else if(csDawingNameTag.Find(szTag) > -1) { CString stext; #if ADS > 17 // cad 17平台不支持多行属性文字 if (pAtt->isMTextAttribute()) {//支持多行文字 stext = pAtt->getMTextAttribute()->text(); if (!stext.IsEmpty()) { if (!csDawingName.IsEmpty()) { csDawingName += csDawingSplitSign;//加分隔符 } csDawingName += stext; } } else #endif { stext = pAtt->textString(); if (!stext.IsEmpty()) { if (!csDawingName.IsEmpty()) { csDawingName += csDawingSplitSign;//加分隔符 } csDawingName += stext; } } bFlag = TRUE; } pEnt->close(); } delete pAttIter; return bFlag; } //获得克隆块的新ID //add by xlc on 160202 AcDbObjectId WblockCloneObjects(AcDbObjectId idOldBlock,AcDbDatabase *pDb) { AcDbObjectIdArray list; list.append(idOldBlock); // 将实体ID存入数组 AcDbIdMapping idMap; acdbCurDwg()->wblockCloneObjects(list,pDb->blockTableId(),idMap,AcDb::kDrcReplace);//复制块到当前打开的文档 AcDbIdPair idPair; idPair.setKey(idOldBlock); idMap.compute(idPair); AcDbObjectId idNewBlock=idPair.value(); return idNewBlock; } void SplitDwg() { PickSet ss(SS_FREE); //add16.1.11支持公框图层LINE,ARC,CIRCLE, XString sLayer; sLayer<<_T("*TITLE,*BORDER,*图框,")<"), ss, mask) != RTNORM) { ZOOME; ss.Get(_T("X"), NULL, NULL, mask); } TDPtrList lstPolyTmp;//图框范围 AcDbObjectIdArray idsTmp;//保存图框的id,为了以后判断过滤掉相连接的其他图框id,因为ssget -=函数有bug,所以只能用+=来做。 long lCount=ss.Length(); if(lCount < 1) { acutPrintf(_T("\n未发现上华图框!")); return; } for(long i=0L; igetGeomExtents(extents); TGGePoly2D poly2d(1); poly2d.AppendNode(TADSGePoint3d(extents.minPoint().x, extents.minPoint().y)); poly2d.AppendNode(TADSGePoint3d(extents.maxPoint().x, extents.minPoint().y)); poly2d.AppendNode(TADSGePoint3d(extents.maxPoint().x, extents.maxPoint().y)); poly2d.AppendNode(TADSGePoint3d(extents.minPoint().x, extents.maxPoint().y)); lstPolyTmp.Append(new TGGePoly2D(poly2d)); idsTmp.append(pEnt->id()); } OPENOBJ_END() } TDPtrList lstPoly;//图框范围 AcDbObjectIdArray ids;//图框id //过滤掉被大框包含的小框 lCount=lstPolyTmp.Length(); for (long j=0L; jdatabase(); if (pDb!=NULL) { Acad::ErrorStatus es=Acad::eOk; AcDbDictionary* pRootDict=NULL; es=pDb->getNamedObjectsDictionary(pRootDict,AcDb::kForRead); if (es==Acad::eOk) { AcDbObjectId idExist; es=pRootDict->getAt(_T("TCH_DBPSCONFIG"), idExist); if (es==Acad::eOk) { TDbPsConfig *pConfig=NULL; es=acdbOpenObject(pConfig, idExist, AcDb::kForRead); pConfigNew = (TDbPsConfig *)pConfig->clone(); pConfig->close(); } //add by lgy 20120207 支持建筑 es=pRootDict->getAt(_T("ATS_DBCONFIG"), idExist); if (es==Acad::eOk) { TDbConfig *pArchConfig = NULL; es=acdbOpenObject(pArchConfig, idExist, AcDb::kForRead); pDbConfig = (TDbConfig *)pArchConfig->clone(); pArchConfig->close(); } pRootDict->close(); } } CString csBigFont, csEngFont; AcDbObjectId idTextStyleOld = GetTextStyleId(_T("STANDARD")); OPENOBJ_BEGIN(idTextStyleOld, AcDb::kForRead, AcDbTextStyleTableRecord, pStyle); if(pStyle){ const TCHAR* pbigFontFileName = NULL; pStyle->bigFontFileName(pbigFontFileName); csBigFont = pbigFontFileName; const TCHAR* pShxName = NULL; pStyle->fileName(pShxName); csEngFont = pShxName; } OPENOBJ_END(); ///////////////////////////////////////////////////////////////////////////////////////////// if(dlg.DoModal() == IDOK) { ZOOME; for(size_t l = 0; l < dlg.m_lstCell.size(); ++l) { CString csFileName = dlg.m_csPath + dlg.m_lstCell[l].m_sDWGName; XPoly2D poly = dlg.m_lstCell[l].m_poly; XPoint p1 = *poly[0]; XPoint p2 = *poly[2]; //得到拾取框大小 double dAperture = GetPickBoxWcs() * 0.5; p1.x += dAperture; p1.y += dAperture; p2.x -= dAperture; p2.y -= dAperture; XPoint ptCen; Midpoint(p1, p2, ptCen); double dXlen = p2.x - p1.x; double dYlen = p2.y - p1.y; arxZoomTo(ptCen, dXlen, dYlen); PickSet ssPoly(SS_FREE); ssPoly.Get(_T("C"), p1, p2, NULL); ssPoly += dlg.m_lstCell[l].m_id; int len22 = ssPoly.Length(); //wlw 16.0616导出的cad全局变量不一致 ,使用wblock方式进行导出 //BOOL ret = arxWBlock(ssPoly, csFileName, *poly[0]); AcDbDatabase *pNewDb = NULL; AcDbObjectIdArray idAllArray; ssPoly.AsIdArray(idAllArray); // AcDbObjectId idAxiso = InitBlock(_T("_AXISO1")); // if (idAxiso.isValid()) // { // idAllArray.append(idAxiso); // } BOOL ret = acdbCurDwg()->wblock(pNewDb, idAllArray, AcGePoint3d::kOrigin); if(ret != 0) continue; //写全局变量 2009-4-3 sr //////////////////////////////////////////////////////////////// //AcDbDatabase db(Adesk::kFalse, true); //Acad::ErrorStatus es = db.readDwgFile(csFileName, _SH_DENYNO, false); //1.修改比例因子 pNewDb->setLtscale(nLtScale); //2.设置管线全局变量 if(pConfigNew != NULL) { Acad::ErrorStatus esDist=Acad::eOk; AcDbDictionary* pRootDict=NULL; esDist=pNewDb->getNamedObjectsDictionary(pRootDict,AcDb::kForWrite); TDbPsConfig *pConfigNew2 = NULL; pConfigNew2 = (TDbPsConfig *)pConfigNew->clone(); if (esDist==Acad::eOk) { AcDbObjectId idRet; pRootDict->setAt(_T("TCH_DBPSCONFIG"), pConfigNew2, idRet); pConfigNew2->close(); pRootDict->close(); } } //add by lgy 20120207 支持上华建筑 if(pDbConfig != NULL) { Acad::ErrorStatus esDist=Acad::eOk; AcDbDictionary* pRootDict=NULL; esDist=pNewDb->getNamedObjectsDictionary(pRootDict,AcDb::kForWrite); // pConfig2 = (TDbConfig *)pDbConfig->clone();//sr 2012-6-21 修改为以下若干行,采用clone的方法,saveas会弹出“警告:保存时出错” SYS17 18 if (esDist==Acad::eOk) { //TDbConfig *pConfig2 = new TDbConfig; //pConfig2->SetHighBold(pDbConfig->GetHighBold()); //pConfig2->SetPScale(pDbConfig->GetPScale()); //pConfig2->SetLineWeight(pDbConfig->IsLineWeight()); //pConfig2->SetSolidFill(pDbConfig->IsSolidFill()); //pConfig2->SetMeterUnitDim(pDbConfig->IsMeterUnitDim()); // TDbConfig *p0 =GetDwgGlobal(AcDb::kForRead); if(p0 != NULL) { TDbConfig *p1=TDbConfig::cast(p0->clone()); if(p1!=NULL) { p1->SetHighBold(p0->GetHighBold()); p1->SetPScale(p0->GetPScale()); p1->SetLineWeight(p0->IsLineWeight()); p1->SetSolidFill(p0->IsSolidFill()); p1->SetMeterUnitDim(p0->IsMeterUnitDim()); //add by wlw on 160102 解决线图案填充不导出的问题 p1->SetHatchDividerId(AcDbObjectId::kNull); p1->SetHatchFillId(AcDbObjectId::kNull); p1->SetHatchFill1Id(AcDbObjectId::kNull); p1->SetHatchFill2Id(AcDbObjectId::kNull); if(p0->IsDividerLineHatch()) { p1->SetHatchDividerId(WblockCloneObjects(p0->GetHatchDividerId(),pNewDb)); } if(p0->IsFillLineHatch()) { p1->SetHatchFillId(WblockCloneObjects(p0->GetHatchFillId(),pNewDb)); } if(p0->IsFill1LineHatch()) { p1->SetHatchFill1Id(WblockCloneObjects(p0->GetHatchFill1Id(),pNewDb)); } if(p0->IsFill2LineHatch()) { p1->SetHatchFill2Id(WblockCloneObjects(p0->GetHatchFill2Id(),pNewDb)); } p1->SetHatchBrickId(AcDbObjectId::kNull); p1->SetHatchRocketId(AcDbObjectId::kNull); p1->SetHatchConcreteId(AcDbObjectId::kNull); p1->SetHatchSteelId(AcDbObjectId::kNull); p1->SetLinetypeDote(GetLinetypeIdFromString(_T("DOTE"),pNewDb)); p1->SetLinetypeDash(GetLinetypeIdFromString(_T("DASH"),pNewDb)); // sg add 090519,导出T7、T6后,应该将文字距基线系数,转化为文字距基线距离 double dText2BaseRatio = p0->GetText2BaseRatio(); // sg modify 090527,将文字距离基线距离与系数间的换算关系由0.3精确到0.286 dText2BaseRatio /= 0.286; p1->SetText2Base(dText2BaseRatio); //wlw add 16.6.17当前dbcofig指针必须关闭,否则全局配置文件将被初始化 p0->close(); AcDbObjectId idRet; Acad::ErrorStatus es2 = pRootDict->setAt(_T("ATS_DBCONFIG"), p1, idRet); p1->close(); pRootDict->close(); } } } } //////////////////////////////////////////////////////////////////////////////////////// //3.修改文字样式STANDARD AcDbObjectId idTextStyle = GetTextStyleId(_T("STANDARD"), pNewDb); OPENOBJ_BEGIN(idTextStyle, AcDb::kForWrite, AcDbTextStyleTableRecord, pStyle); if(pStyle){ pStyle->setBigFontFileName(csBigFont); pStyle->setFileName(csEngFont); } OPENOBJ_END(); pNewDb->saveAs(csFileName); ////////////////////////////////////////////////////////////////////////////////////////// // cet 2018.1.25 add 直接保存图纸,不打开图纸 if (!dlg.m_bOpen) { continue; } static TContextOpen sContext; _tcscpy(sContext.szFileName, (const TCHAR *)csFileName); sContext.bClose = !dlg.m_bOpen; AcApDocument* pDoc = acDocManager->curDocument(); if (pDoc) { acDocManager->lockDocument(pDoc); acDocManager->executeInApplicationContext(OpenDwgFile, (void *)&sContext); Acad::ErrorStatus es=acDocManager->unlockDocument(pDoc); //如果需要打开后立即置为活动,把以下3行打开 // char *pStr = new char[256]; //防止命令结束,csFileName消亡 // strcpy(pStr, csFileName); // AfxBeginThread(ActiveDoc, (LPVOID)pStr); } } } if(pConfigNew != NULL) delete pConfigNew; if (pDbConfig != NULL)//add by lgy 20120207 支持建筑 delete pDbConfig; TPipePerDocData *pData = GetCurPipeDocData(); pData->EnableWork(FALSE); } TGridSplitDwg::TGridSplitDwg() { AppendCol(_T("文件名"), 190); AppendCol(_T("图名"), 115); AppendCol(_T("图号"), 75); AppendCol(_T("查看"), 35); SetColPosFix(); SetColFixLength(); SetNoPaste(); GetCol(3).SetRightButton(); } void TGridSplitDwg::GetFileList() { m_lstName.Reset(); for(MoveToFirst(); !IsOut(); MoveToNext()){ WDGridRow *pRow = CurRow(); CString csName = (*pRow)[0].GetText(); m_lstName.Append(tstrnew(csName)); } } void HideDialog(CWnd *pWnd, BOOL Flag) { if (Flag) { pWnd->GetParent()->EnableWindow(TRUE); pWnd->GetParent()->SetFocus(); pWnd->GetParent()->SetActiveWindow(); pWnd->ShowWindow(SW_HIDE); } else { pWnd->GetParent()->EnableWindow(FALSE); pWnd->EnableWindow(TRUE); pWnd->SetActiveWindow(); pWnd->ShowWindow(SW_SHOW); } } bool TGridSplitDwg::OnCellButtonDown(WDGridCell &cell, CString &res) { if(cell.GetColIndex() == 3) { CSplitDwgDlg* pdlg = (CSplitDwgDlg*)this->GetParent(); if (pdlg == NULL) { return false; } HideDialog(this->GetParent(), TRUE); WDGridRow &row = cell.GetRow(); long nrow = cell.GetRowIndex(); if(nrow > pdlg->m_lstCell.size()) { HideDialog(this->GetParent(), FALSE); return false; } XPoly2D poly = pdlg->m_lstCell[nrow].m_poly; XPoint p1 = *poly[0]; XPoint p2 = *poly[2]; XPoint ptCen; Midpoint(p1, p2, ptCen); double dXlen = p2.x - p1.x; double dYlen = p2.y - p1.y; arxZoomTo(ptCen, dXlen, dYlen); Entity ent; RBList mask=ads_buildlist(RTDXF0, _T("TEXT,ATS_TEXT,MTEXT,ATS_DRAWINGNAME"), NULL); if(SelectEntity(_T("\n请选择图名对象:<退出>"), ent, mask) != RTNORM){ HideDialog(this->GetParent(), FALSE); return true; } TCHAR szText[256]; CString csText, csFileName; ent.GetData(1, szText); csText = szText; csFileName = csText + _T(".dwg"); pdlg->m_lstCell[nrow].m_sDWGName = csFileName; pdlg->m_lstCell[nrow].m_sName = csText; pdlg->m_grid.GetCell(nrow, 1).SetText(csText); pdlg->GetFinalFileName(); HideDialog(this->GetParent(), FALSE); return true; } return false; } ///////////////////////////////////////////////////////////////////////////// // CSplitDwgDlg dialog static BOOL gbckName = TRUE; static BOOL gbckNum = TRUE; CSplitDwgDlg::CSplitDwgDlg(CWnd* pParent /*=NULL*/) : CDialog(CSplitDwgDlg::IDD, pParent), m_bckName(gbckName) , m_bckNum(gbckNum) , m_nNameType(0) { //{{AFX_DATA_INIT(CSplitDwgDlg) m_csPath = _T(""); m_bOpen = FALSE; //}}AFX_DATA_INIT } void CSplitDwgDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSplitDwgDlg) DDX_Text(pDX, IDC_EDIT_PATH, m_csPath); DDX_Check(pDX, IDC_CHECK_OPEN, m_bOpen); //}}AFX_DATA_MAP DDX_Check(pDX, IDC_CHECK_NAME, m_bckName); DDX_Check(pDX, IDC_CHECK_NUM, m_bckNum); DDX_Radio(pDX, IDC_RADIO_NAME, m_nNameType); } BEGIN_MESSAGE_MAP(CSplitDwgDlg, CDialog) //{{AFX_MSG_MAP(CSplitDwgDlg) ON_BN_CLICKED(IDC_BUTTON_PATH, OnButtonPath) //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_CHECK_NAME, &CSplitDwgDlg::OnBnClickedCheckName) ON_BN_CLICKED(IDC_CHECK_NUM, &CSplitDwgDlg::OnBnClickedCheckNum) ON_BN_CLICKED(IDC_RADIO_NAME, &CSplitDwgDlg::OnBnClickedRadioName) ON_BN_CLICKED(IDC_RADIO_NUM, &CSplitDwgDlg::OnBnClickedRadioNum) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSplitDwgDlg message handlers BOOL CSplitDwgDlg::OnInitDialog() { CDialog::OnInitDialog(); const TCHAR* sBuf=NULL; acdbCurDwg()->getFilename(sBuf); CString sDwgFilePath(sBuf); sDwgFilePath.MakeUpper(); SplitPath(sDwgFilePath,m_sDwgPath, m_sDwgName); m_csPath = m_sDwgPath; UpdateData(FALSE); m_grid.Clear(); m_grid.Create(this, IDC_LIST_FILE); m_grid.SetNoDefaultMenu(true); m_grid.SetNoAppendButton(TRUE); m_grid.GetCol(1).SetReadOnly(TRUE); m_grid.GetCol(2).SetReadOnly(TRUE); UpdateGrid(); GetFinalFileName(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } int CSplitDwgDlg::GetDigitFromStr(CString str) { CString strT; int nlen = str.GetLength(); bool b1st = false;//防止第一位0 for (int i = 0; i < nlen; ++i) { if (isdigit(str[i])) { strT += str[i]; } } int nnn = _ttoi(strT); return _ttoi(strT); } bool CSplitDwgDlg::SortByNumber(const TSplitDwgCell& element1, const TSplitDwgCell& element2) { if (GetDigitFromStr(element1.m_sNumber) < GetDigitFromStr(element2.m_sNumber)) { return true; } return false; } void CSplitDwgDlg::UpdateGrid() { std::sort(m_lstCell.begin(), m_lstCell.end(), SortByNumber); for(size_t j = 0; j < m_lstCell.size();j++) { XPoly2D poly = m_lstCell[j].m_poly; CString csFileName; csFileName.Format(_T("%s%d.dwg"), m_sDwgName, j+1); m_grid.AppendRow(); m_grid.GetCell(j, 0).SetText(csFileName); m_grid.GetCell(j, 1).SetText(m_lstCell[j].m_sName); m_grid.GetCell(j, 2).SetText(m_lstCell[j].m_sNumber); } } void CSplitDwgDlg::OnButtonPath() { //指定目录 BOOL bSuccess = CBrowseForFolder2::BrowseForFolder2(m_hWnd,m_csPath,_T("指定工作目录"),0); CString csRight = m_csPath.Right(1); if(csRight != _T("\\")) m_csPath += _T("\\"); UpdateData(FALSE); } void CSplitDwgDlg::OnOK() { size_t ncount = m_grid.GetRowNum(); if (ncount != m_lstCell.size()) { AfxMessageBox(_T("选择失败,重新选择图形")); return; } CString smess; for (long i = 0; i < m_grid.GetRowNum(); i++) { WDGridRow* pgridRow = &m_grid[i]; m_lstCell[i].m_sDWGName = (*pgridRow)[0].GetText(); if (!IsValidFileName(m_lstCell[i].m_sDWGName)) { smess.Format(_T("第 %d 行dwg文件名称包含“\/:;*?\<>|”,请修改!"), i + 1); AfxMessageBox(smess); return; } } for (size_t j = 0; j < m_lstCell.size() - 1; j++) { for (size_t k = j + 1; k < m_lstCell.size(); k++) { if (m_lstCell[j].m_sDWGName == m_lstCell[k].m_sDWGName) { AfxMessageBox(_T("dwg文件名称有相同的,请修改!")); return; } } } CDialog::OnOK(); gbckName = m_bckName; gbckNum = m_bckNum; } void CSplitDwgDlg::GetFinalFileName() { UpdateData(TRUE); CString csDawingNoTag, csDawingNameTag,csDawingSplitSign, csDawingNoSign; GetTitleTag(csDawingNoTag, csDawingNameTag,csDawingSplitSign, csDawingNoSign);//得到图名和图号Tag的名字 if (m_bckNum && m_bckName) { for (size_t i = 0; i < m_lstCell.size(); ++i) { if (!m_lstCell[i].m_sName.IsEmpty() && !m_lstCell[i].m_sNumber.IsEmpty()) { // cet 2018.1.25 modify 根据命名顺序确定名称 // m_lstCell[i].m_sDWGName = m_lstCell[i].m_sName + csDawingNoSign + m_lstCell[i].m_sNumber + _T(".dwg"); if (m_nNameType == 0) // 图名在前 { m_lstCell[i].m_sDWGName = m_lstCell[i].m_sName + csDawingNoSign + m_lstCell[i].m_sNumber + _T(".dwg"); } else // 图号在前 { m_lstCell[i].m_sDWGName = m_lstCell[i].m_sNumber + csDawingNoSign + m_lstCell[i].m_sName + _T(".dwg"); } m_grid.GetCell(i, 0).SetText(m_lstCell[i].m_sDWGName); } else if (!m_lstCell[i].m_sNumber.IsEmpty()) { m_lstCell[i].m_sDWGName = m_lstCell[i].m_sNumber + _T(".dwg"); m_grid.GetCell(i, 0).SetText(m_lstCell[i].m_sDWGName); } else if (!m_lstCell[i].m_sName.IsEmpty()) { m_lstCell[i].m_sDWGName = m_lstCell[i].m_sName + _T(".dwg"); m_grid.GetCell(i, 0).SetText(m_lstCell[i].m_sDWGName); } } m_grid.Refresh(); return; } if (m_bckNum) { for (size_t i = 0; i < m_lstCell.size(); ++i) { if (!m_lstCell[i].m_sNumber.IsEmpty()) { m_lstCell[i].m_sDWGName = m_lstCell[i].m_sNumber + _T(".dwg"); m_grid.GetCell(i, 0).SetText(m_lstCell[i].m_sDWGName); } } m_grid.Refresh(); return; } if (m_bckName) { for (size_t i = 0; i < m_lstCell.size(); ++i) { if (!m_lstCell[i].m_sName.IsEmpty()) { m_lstCell[i].m_sDWGName = m_lstCell[i].m_sName + _T(".dwg"); m_grid.GetCell(i, 0).SetText(m_lstCell[i].m_sDWGName); } } m_grid.Refresh(); return; } } void CSplitDwgDlg::OnBnClickedCheckName() { GetFinalFileName(); } void CSplitDwgDlg::OnBnClickedCheckNum() { GetFinalFileName(); } BOOL CSplitDwgDlg::IsValidFileName(CString strP) { if (strP.IsEmpty()) return FALSE; strP.TrimLeft(); strP.TrimRight(); CString strR = strP.Right(4); strR.MakeUpper(); if (strR.CompareNoCase(_T(".DWG"))) { return FALSE; } // valid file name if(strP.FindOneOf(_T("\/:;*?\"<>|")) > -1) { return FALSE; } return TRUE; } void CSplitDwgDlg::OnBnClickedRadioName() { GetFinalFileName(); } void CSplitDwgDlg::OnBnClickedRadioNum() { GetFinalFileName(); }