#include "StdAfx.h" #include "StdArx.h" #include "EarThwormDef.h" #include "CISODraftDlg.h" #include "AcISOPolylineJig.h" #include "CoreTools.h" #include "KTSetting.h" #include "AecDbEwEquipment.h" #include "CValLstDlg.h" #include "AcGiExplodeDraw.h" #include "AcISOCrdWatch.h" #include "AecISOMatrix.h" #include "KTCadUtility.h" #include "KTCADUtilityEx.h" #include "KTCADSysVar.h" #include "AecDbEwFitting.h" #include "CDimTxtDlg.h" #include "AecDbEwPipeDim.h" #include "KTModelLayoutXData.h" #include "CTKViewDlg.h" #define DXF_ISOENT _T("LINE,ARC,CIRCLE,INSERT,LWPOLYLINE") static const Adesk::UInt16 kColorByBlock = 0; static const Adesk::UInt16 kRed = 1; static const Adesk::UInt16 kYellow = 2; static const Adesk::UInt16 kGreen = 3; static const Adesk::UInt16 kCyan = 4; static const Adesk::UInt16 kBlue = 5; static const Adesk::UInt16 kMagenta = 6; static const Adesk::UInt16 kWhite = 7; static const Adesk::UInt16 kColorByLayer = 256; DLLIMPEXP AcDbPolyline *FormatPolyline(AcGePoint3d *ppPts, int nCount); AcDbObjectId AddToModelSpace(AcDbEntity *pEnt, bool bClose = true) { if (!pEnt) return AcDbObjectId::kNull; AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase(); AcDbObjectId id(AcDbObjectId::kNull); AcDbBlockTable *pTbl = NULL; Acad::ErrorStatus es; if (Acad::eOk == (es = pDb->getBlockTable(pTbl, AcDb::kForRead))) { AcDbBlockTableRecord *pBTR = NULL; if (Acad::eOk == (es = pTbl->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForWrite))) { pTbl->close();//调整到此处,便于反应器检测record es = pBTR->appendAcDbEntity(id, pEnt); pBTR->close();//调整到此处,便于反应器检测record if (bClose) pEnt->close(); } } return id; } void MoveRecordToZ0(AcDbBlockTable *pBlockTable, CString &sBlockName) { //整体移动,最低为点0,0 AcDbBlockTableRecord *pRec = NULL; if (Acad::eOk == pBlockTable->getAt(sBlockName, pRec, AcDb::kForRead)) { AcDbBlockTableRecordIterator *pIt = NULL; pRec->newIterator(pIt); if (pIt != NULL) { AcGePoint3d ptMin; double dMinZ = 999999999.0; AcDbExtents extT; AcDbEntity *pEnt = NULL; for (pIt->start(); !pIt->done(); pIt->step()) { if (Acad::eOk == pIt->getEntity(pEnt, AcDb::kForRead)) { pEnt->getGeomExtents(extT); ptMin = extT.minPoint(); if (dMinZ > ptMin.z) { dMinZ = ptMin.z; } pEnt->close(); } } AcGeVector3d vtM(0, 0, -dMinZ); AcGeMatrix3d xform; xform.setToTranslation(vtM); for (pIt->start(); !pIt->done(); pIt->step()) { if (Acad::eOk == pIt->getEntity(pEnt, AcDb::kForWrite)) { pEnt->transformBy(xform); pEnt->close(); } } delete pIt; } pRec->close(); } } BOOL InSertBlockFromDwgToCurDb(CString sDwgPath, CString sBlockName, AcDbObjectId &BlockId) { Acad::ErrorStatus es; AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase(); AcDbBlockTable *pBlockTable = NULL; if (pDb->getBlockTable(pBlockTable, AcDb::kForRead) != Acad::eOk) return FALSE; if (pBlockTable->getAt(sBlockName, BlockId) == Acad::eOk) { pBlockTable->close(); pBlockTable = NULL; return TRUE; } pBlockTable->close(); pBlockTable = NULL; acDocManagerPtr()->lockDocument(curDoc()); AcDbDatabase *pNewDb = new AcDbDatabase(Adesk::kFalse); pNewDb->readDwgFile(sDwgPath); AcDbObjectId RcdId; if (pNewDb->getBlockTable(pBlockTable, AcDb::kForRead) != Acad::eOk) { delete pNewDb; acDocManagerPtr()->unlockDocument(curDoc()); return FALSE; } #if ARX > 24 if (pBlockTable->getAt(sBlockName, RcdId) != Acad::eOk) #else if (pBlockTable->getAt(sBlockName, RcdId, AcDb::kForRead) != Acad::eOk) #endif { pBlockTable->close(); pBlockTable = NULL; delete pNewDb; acDocManagerPtr()->unlockDocument(curDoc()); return FALSE; } MoveRecordToZ0(pBlockTable, sBlockName); pBlockTable->close(); pBlockTable = NULL; AcDbDatabase *pInsertDb = new AcDbDatabase; if ((es = pNewDb->wblock(pInsertDb, RcdId)) != Acad::eOk) { delete pInsertDb; delete pNewDb; acDocManagerPtr()->unlockDocument(curDoc()); return FALSE; } es = pDb->insert(BlockId, sBlockName, pInsertDb); delete pNewDb; delete pInsertDb; acDocManagerPtr()->unlockDocument(curDoc()); return TRUE; } static AcGePoint3d MidPoint(const AcGePoint3d &pt1, const AcGePoint3d &pt2) { return AcGePoint3d((pt1.x + pt2.x) / 2.0, (pt1.y + pt2.y) / 2.0, (pt1.z + pt2.z) / 2.0); } void PL_ZCHZCmd() { //弹出对话框,请选择系统 CAcModuleResourceOverride myResources; CISODraftDlg dlg; if (IDOK != dlg.DoModal()) { return; } KTCADSysVar var(_T("OSMODE"), 999); WPipe::PipeParam param; memset(¶m, 0, sizeof(WPipe::PipeParam)); ISODrawCfg isodrcfg; memset(&isodrcfg, 0, sizeof(ISODrawCfg)); dlg.GetISODrawCFG(isodrcfg,param); AcISOPolylineJig jig; jig.SetDb(dlg.m_pDb,¶m); if (jig.DoItISO(isodrcfg.m_nView,isodrcfg.m_nAngle, isodrcfg))// { jig.Commit(TRUE); } } //测试 void PL_GTSTCmd() { CAcModuleResourceOverride myResources; CUIISQLiteServer sqlDb; CString dbPath = FilePath::GetSysDir(); dbPath += _T("\\Plumbing.db"); if (!sqlDb.InitADOServer(dbPath)) { AfxMessageBox(_T("数据库驱动加载数据库Plumbing.db失败!")); return; } CTKViewDlg dlg; dlg.SetDefaultFolderShow(_T("阀门"), _T("平面阀门.dwg")); if (IDOK == dlg.DoModal()) { CString strInsertDwgPath = dlg.m_sDwgPath; CString strInsertBlockName = dlg.m_sRcdName; AcDbObjectId idBlkRec; if (InSertBlockFromDwgToCurDb(strInsertDwgPath, strInsertBlockName, idBlkRec)) { ads_point pt; if (RTNORM == acedGetPoint(NULL, _T("\nPick point:"), pt)) { AcDbBlockReference *pRef = new AcDbBlockReference; pRef->setBlockTableRecord(idBlkRec); pRef->setPosition(asPnt3d(pt)); pRef->setScaleFactors(AcGeScale3d(1, 1, 1)); AcDbExtents ext; pRef->geomExtentsBestFit(ext); CString sSQL,sOD = _T("440"); sSQL.Format(_T("select distinct [法兰外径] from [AecFlangeData] where [公称直径]=%d"),300); sqlDb.GetSelData(sSQL, sOD); //DN=200 按法兰外径匹配放大 double dScale = _ttof(sOD) / (ext.maxPoint().y - ext.minPoint().y); AcGeScale3d sc(dScale, dScale, dScale); pRef->setScaleFactors(sc); AddToModelSpace(pRef); } } return; } } static void MakeWDot(AcGePoint3d ptGeCen, AcDbObjectId &idLay, double dPlotDotD) { double dDotRadius = dPlotDotD; static const Adesk::UInt16 kYellow = 2; AcGePoint2d ptGeCenDot = ptGeCen.convert2d(AcGePlane::kXYPlane); AcGePoint2d ptGe[4]; double dBulge = tan(PI / 8.0); ptGe[0] = ptGeCenDot + dDotRadius * AcGeVector2d::kYAxis; ptGe[1] = ptGeCenDot + dDotRadius * AcGeVector2d::kXAxis; ptGe[2] = ptGeCenDot - dDotRadius * AcGeVector2d::kYAxis; ptGe[3] = ptGeCenDot - dDotRadius * AcGeVector2d::kXAxis; AcDbPolyline *pDot = new AcDbPolyline; pDot->addVertexAt(0, ptGe[0], -dBulge); pDot->addVertexAt(1, ptGe[1], -dBulge); pDot->addVertexAt(2, ptGe[2], -dBulge); pDot->addVertexAt(3, ptGe[3], -dBulge); pDot->addVertexAt(4, ptGe[0], 0.0); pDot->setConstantWidth(2.0*dPlotDotD); pDot->setClosed(Adesk::kTrue); pDot->setNormal(AcGeVector3d::kZAxis); pDot->setLayer(idLay); pDot->setColorIndex(kYellow); AddToModelSpace(pDot); } static double GetISOScale(LPCTSTR szScale) { CString sDocScale = szScale; int nIndex = sDocScale.Find(_T(':'), 0); double dPScale = 1.0; if (nIndex != -1) { dPScale = _ttof(sDocScale.Mid(nIndex + 1)) / _ttof(sDocScale.Mid(0, nIndex)); } return dPScale; } void PL_TJHDCmd() { ads_point pt; int nRes = 0; ads_point ptC[2], ptWCS; //在本点选 TCHAR szBuf[256]; struct resbuf eb1; eb1.restype = 0; _tcscpy(szBuf, _T("LWPOLYLINE")); eb1.resval.rstring = szBuf; eb1.rbnext = NULL; ads_name ss, ent; AcDbObjectId id, idCurSys, idLineType; while (true) { nRes = acedGetPoint(NULL, _T("\n请选择位置添加焊点:"), pt); if (nRes == RTNORM) { ads_point_set(pt, ptC[0]); ads_point_set(pt, ptC[1]); acdbUcs2Wcs(pt, ptWCS, false); ptC[0][X] -= CoreTools::PixelToWcs(10); ptC[0][Y] -= CoreTools::PixelToWcs(10); ptC[1][X] += CoreTools::PixelToWcs(10); ptC[1][Y] += CoreTools::PixelToWcs(10); nRes = acedSSGet(_T("C"), ptC[0], ptC[1], &eb1, ss); if (nRes == RTNORM) { Adesk::Int32 lLen = 0; acedSSLength(ss, &lLen); if (lLen == 0) { acutPrintf(_T("\n没有选择到系统管线!")); } acedSSName(ss, 0, ent); acdbGetObjectId(id, ent); acedSSFree(ss); AcDbEntity *pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead)) { ISODrawCfg isodrcfg; memset(&isodrcfg, 0, sizeof(ISODrawCfg)); _tcscpy(isodrcfg.m_sScale, _T("1:100")); if (AcISOPolyline::ReadISOXData(pEnt, isodrcfg)) { AcDbObjectId idCurSys = CoreTools::getLyForPipe(isodrcfg.m_sCurrSys); AcDbObjectId idLineType = KTSetting::InitLineStyle(_T("CONTINUOUS")); MakeWDot(asPnt3d(ptWCS), idCurSys, isodrcfg.m_dPipeW * GetISOScale(isodrcfg.m_sScale)); } pEnt->close(); } } } else { break; } } } static void Rotate90(AecComplexCurve &cplCurve, const AcGePoint3d &ptIns, AcGeVector3d &vtDir2) { AcGeMatrix3d xm; xm.setToRotation(PI / 2.0, vtDir2, ptIns); cplCurve.transformBy(xm); } static void Rotate90(AcDbEntity* pCrv, const AcGePoint3d &ptIns, AcGeVector3d &vtDir2) { AcGeMatrix3d xm; xm.setToRotation(PI / 2.0, vtDir2, ptIns); pCrv->transformBy(xm); } static void CovertToISO(AcDbEntity *pEnt, AecDbObjXDataMap *pXDataMap, AcDbVoidPtrArray &arEntPtrs, ISODrawCfg &isodrcfg,bool bISOCrd = true) { BOOL bIs45 = isodrcfg.m_nAngle > 0 ? true : false; AecISOMatrix m_xform; double dAng = isodrcfg.m_nAngle > 0 ? PI / 4.0 : PI / 6.0; m_xform.Set(AcGePoint3d::kOrigin, dAng, isodrcfg.m_nView, bIs45); AcGePoint3d ptSta, ptEnd,ptGe; AcDbLine *pLine = AcDbLine::cast(pEnt); if (pLine != NULL) { ptSta = pLine->startPoint(); ptEnd = pLine->endPoint(); if (bISOCrd) { m_xform.GetTransformByThis(ptSta); m_xform.GetTransformByThis(ptEnd); } AcDbLine *pLine2 = new AcDbLine; pLine2->setStartPoint(ptSta); pLine2->setEndPoint(ptEnd); pLine2->setLayer(pEnt->layerId()); pLine2->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pLine2->setNormal(AcGeVector3d::kZAxis); if (pXDataMap != NULL) { pXDataMap->Write(pLine2, BIMDATA_APP); } AcISOPolyline::WriteISOXData(pLine2, isodrcfg); arEntPtrs.append(pLine2); return; } AcDbArc *pArc = AcDbArc::cast(pEnt); if (pArc != NULL) { //取6个点 double dSta = 0.0, dEnd = 0.0; pArc->getStartParam(dSta); pArc->getEndParam(dEnd); AcGeVector3d vtNom = pArc->normal(); double dStep = (dEnd - dSta) / 6.0;//6等分 AcDbPolyline *pPl = new AcDbPolyline; for (int i = 0; i <= 6; i++) { pArc->getPointAtParam(dSta + i * dStep, ptGe); if (bISOCrd) m_xform.GetTransformByThis(ptGe); pPl->addVertexAt(i, ptGe.convert2d(AcGePlane::kXYPlane)); } pPl->setNormal(AcGeVector3d::kZAxis); pPl->setLayer(pEnt->layerId()); if (pXDataMap != NULL) { pXDataMap->Write(pPl, BIMDATA_APP); } AcISOPolyline::WriteISOXData(pPl, isodrcfg); arEntPtrs.append(pPl); return; } AcDbPolyline *pPl = AcDbPolyline::cast(pEnt); if (pPl != NULL) { AcDbPolyline *pPl2 = new AcDbPolyline; for (int n = 0;n < pPl->numVerts();n++) { pPl->getPointAt(n, ptGe); if (bISOCrd) m_xform.GetTransformByThis(ptGe); pPl2->addVertexAt(n, ptGe.convert2d(AcGePlane::kXYPlane)); } pPl2->setNormal(AcGeVector3d::kZAxis); pPl2->setLayer(pEnt->layerId()); if (pPl->isClosed()) pPl2->setClosed(Adesk::kTrue); if (pXDataMap != NULL) { pXDataMap->Write(pPl2, BIMDATA_APP); } AcISOPolyline::WriteISOXData(pPl2, isodrcfg); arEntPtrs.append(pPl2); } AcDbCircle *pCir = AcDbCircle::cast(pEnt); if (pCir != NULL) { AcGePoint3d ptCen = pCir->center(); if (bISOCrd) m_xform.GetTransformByThis(ptCen); AcDbCircle *pCir2 = new AcDbCircle; pCir2->setCenter(ptCen); pCir2->setRadius(pCir->radius()); pCir2->setLayer(pEnt->layerId()); pCir2->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pCir2->setNormal(AcGeVector3d::kZAxis); if (pXDataMap != NULL) { pXDataMap->Write(pCir2, BIMDATA_APP); } AcISOPolyline::WriteISOXData(pCir2, isodrcfg); arEntPtrs.append(pCir2); return; } AcDbText *pTxt = AcDbText::cast(pEnt); if (pTxt != NULL) { AcGePoint3d ptGe = pTxt->position(); AcGePoint3d ptAg = pTxt->alignmentPoint(); if (bISOCrd) { m_xform.GetTransformByThis(ptGe); m_xform.GetTransformByThis(ptAg); } double dRot = pTxt->rotation(); AcGeVector3d vt = AcGeVector3d::kXAxis; vt.rotateBy(dRot, AcGeVector3d::kZAxis); if (bISOCrd) m_xform.GetTransformByThis(vt); dRot = AcGeVector3d::kXAxis.angleTo(vt, AcGeVector3d::kZAxis); AcDbText *pTxt2 = new AcDbText; pTxt2->setPosition(ptGe); pTxt2->setHorizontalMode(pTxt->horizontalMode()); pTxt2->setVerticalMode(pTxt->verticalMode()); pTxt2->setAlignmentPoint(ptAg); pTxt2->setRotation(dRot); pTxt2->setTextString(pTxt->textStringConst()); pTxt2->setTextStyle(pTxt->textStyle()); pTxt2->setHeight(pTxt->height()); pTxt2->setWidthFactor(pTxt->widthFactor()); pTxt2->setLayer(pTxt->layerId()); pTxt2->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pTxt2->setNormal(AcGeVector3d::kZAxis); if (pXDataMap != NULL) { pXDataMap->Write(pTxt2, BIMDATA_APP); } AcISOPolyline::WriteISOXData(pTxt2, isodrcfg); arEntPtrs.append(pTxt2); return; } } static bool CovertToISO(AecDbEwEquipment* pEqu,AcDbVoidPtrArray& arEntPtrs, ISODrawCfg& isodrcfg,bool bISOCrd = true) { AecDbObjXDataMap* pXDataMap = pEqu->GetSpecialtyData(AcDb::kForWrite); pXDataMap->RemoveAt(_T("_SRC_STRING_")); bool bIs45 = isodrcfg.m_nAngle > 0 ? true : false; BOOL bVlvISOV = isodrcfg.m_bVlvISOV; //提取ISO阀门 AcDbCurve *pCurve = NULL; AecComplexCurve cplCurve; if (bISOCrd) { pEqu->DrawValveForISO(cplCurve, true, bIs45); } else { pEqu->DrawValveForISO(cplCurve, false, false); } AcDbVoidPtrArray arHdFlg; AcGiExplodeDraw dc(arHdFlg); pEqu->DrawHandFlg(dc); //如果水平阀门需求竖直放置 AcGePoint3d ptIns; AcGeVector3d vtDir2; pEqu->GetInsert(ptIns, vtDir2); if (vtDir2.isPerpendicularTo(AcGeVector3d::kZAxis) && bVlvISOV && bISOCrd) { Rotate90(cplCurve, ptIns, vtDir2); } for (int j = 0; j < cplCurve.length(); j++) { pCurve = cplCurve.segat(j); if (pCurve != NULL) { pCurve->setLayer(pEqu->layerId()); pCurve->setColorIndex(kColorByLayer); CovertToISO(pCurve, pXDataMap, arEntPtrs,isodrcfg, bISOCrd); } if (pCurve != NULL) delete pCurve; } AcDbEntity *pSubEnt2 = NULL; for (int j = 0; j < arHdFlg.length(); j++) { pSubEnt2 = (AcDbEntity *)arHdFlg.at(j); pSubEnt2->setLayer(pEqu->layerId()); pSubEnt2->setColorIndex(kColorByLayer); CovertToISO(pSubEnt2, pXDataMap, arEntPtrs,isodrcfg, bISOCrd); delete pSubEnt2; } return false; } static bool CovertToISO(AecDbEwFitting* pFit, AcDbVoidPtrArray &arEntPtrs, ISODrawCfg &isodrcfg) { AecDbObjXDataMap *pXDataMap = pFit->GetSpecialtyData(AcDb::kForWrite); AecInterface inf; pFit->GetInterface(0, inf); AcDbCurve *pCurve = NULL; AcDbVoidPtrArray cplCurve; AcGiExplodeDraw dc(cplCurve); pFit->Draw2d(dc); AcGePoint3d ptIns; AcGeVector3d vtDir2 = inf.vtDir; for (int j = 0; j < cplCurve.length(); j++) { pCurve = (AcDbCurve *)cplCurve.at(j); if (pCurve != NULL) { if (vtDir2.isPerpendicularTo(AcGeVector3d::kZAxis)) { Rotate90(pCurve, AcGePoint3d(0, 0, 0), vtDir2); } pCurve->setLayer(pFit->layerId()); pCurve->setColorIndex(1);//kColorByLayer CovertToISO(pCurve, pXDataMap, arEntPtrs, isodrcfg); } if (pCurve != NULL) delete pCurve; } return true; } static bool CovertEquFlangToISO(AecDbEwEquipment *pEqu, double dWh,AcDbVoidPtrArray &arEntPtrs, ISODrawCfg &isodrcfg,bool bISOCrd) { AecDbObjXDataMap *pXDataMap = pEqu->GetSpecialtyData(AcDb::kForWrite); bool bIs45 = isodrcfg.m_nAngle > 0 ? true : false; BOOL bVlvISOV = isodrcfg.m_bVlvISOV; //提取ISO阀门 AcDbCurve *pCurve = NULL; AecComplexCurve cplCurve; if (bISOCrd) { pEqu->MakeFlange2d(cplCurve, dWh, true, bIs45); } else { pEqu->MakeFlange2d(cplCurve, dWh, false, false); } //如果水平阀门需求竖直放置 AcGePoint3d ptIns; AcGeVector3d vtDir2; pEqu->GetInsert(ptIns, vtDir2); if (vtDir2.isPerpendicularTo(AcGeVector3d::kZAxis) && bVlvISOV && bISOCrd) { Rotate90(cplCurve, ptIns, vtDir2); } for (int j = 0; j < cplCurve.length(); j++) { pCurve = cplCurve.segat(j); if (pCurve != NULL) { pCurve->setLayer(pEqu->layerId()); pCurve->setColorIndex(kColorByLayer); CovertToISO(pCurve, pXDataMap, arEntPtrs, isodrcfg, bISOCrd); } if (pCurve != NULL) delete pCurve; } return true; } BOOL BreakPIDPipe(AcDbPolyline *pPline, const AcGePoint3d &ptBreak, double dLength,double dETDn = 0.0) { // 找到管线组 double dLeft = 0, dRight = 0; AcDbObjectIdArray aridPoly; if (NULL == pPline) return FALSE; // 判断在该点处曲线是否可以裁减(看是否裁超过拐点, 包括多线时) // 确保是曲线上的点 AcGePoint3d pt, pt1, pt2, pt3; pPline->getClosestPointTo(ptBreak, pt); // 去点所在处参数值 double dParam, dAngle; pPline->getParamAtPoint(pt, dParam); // 取前后节点 int iParam = int(dParam); pPline->getPointAtParam(iParam, pt1); pPline->getPointAtParam(iParam + 1, pt2); // 该点所在线段方向 AcGeVector3d vt = (pt2 - pt1).normal(); AcGeVector3d vtNormal = pPline->normal(); // 去除多线拐弯宽度 if (Acad::eOk == pPline->getPointAtParam(iParam - 1, pt3)) { dAngle = vt.angleTo(pt1 - pt3, vtNormal); pt1 += vt * fabs(dAngle > PI ? fabs(dLeft) : fabs(dRight)); } // 去除多线拐弯宽度 if (Acad::eOk == pPline->getPointAtParam(iParam + 2, pt3)) { dAngle = vt.angleTo(pt3 - pt2, vtNormal); pt2 -= vt * fabs(dAngle < PI ? fabs(dLeft) : fabs(dRight)); } // 判断是否够裁减 if (pt1.distanceTo(pt) < dLength / 2.0 || pt2.distanceTo(pt) < dLength / 2.0) return FALSE; // 将pt1, pt2定位到断开位置 pt1 = pt - vt * dLength / 2.0; pt2 = pt + vt * dLength / 2.0; // 裁减出曲线, 修改保留旧曲线 AcGePlane plane(AcGePoint3d::kOrigin, vtNormal); // AcDbObjectId idEnt; AcDbPolyline *pNew; AcDbObjectIdArray arid; // int iVert; double dWidth; struct resbuf *pRb = NULL; { // 创建裁剪的新对象 pNew = new AcDbPolyline; ASSERT(NULL != pNew); // 复制属新和扩展数据 pNew->setNormal(pPline->normal()); pNew->setElevation(pPline->elevation()); pPline->getConstantWidth(dWidth); pNew->setConstantWidth(dWidth); pNew->setPropertiesFrom(pPline); pRb = pPline->xData(); if (NULL != pRb) { pNew->setXData(pRb); CKTCadUtility::FreeRbList(pRb); } // iVert = 0; pPline->getClosestPointTo(pt2, pt3); pNew->addVertexAt(iVert, pt3.convert2d(plane)); ++iVert; // pPline->getPointAt(iParam + 1, pt3); pNew->addVertexAt(iVert, pt3.convert2d(plane)); ++iVert; pPline->getClosestPointTo(pt1, pt3); pPline->setPointAt(iParam + 1, pt3.convert2d(plane)); // while (Acad::eOk == pPline->getPointAt(iParam + 2, pt3)) { pNew->addVertexAt(iVert, pt3.convert2d(plane)); ++iVert; pPline->removeVertexAt(iParam + 2); } // 加入数据库 ISODrawCfg isodrcfg; memset(&isodrcfg, 0, sizeof(ISODrawCfg)); isodrcfg.m_bVlvISOV = TRUE; _tcscpy(isodrcfg.m_sScale, _T("1:100")); if (AcISOPolyline::ReadISOXData(pPline, isodrcfg)) { if (dETDn > 0) { isodrcfg.m_dDn = dETDn; } AcISOPolyline::WriteISOXData(pNew, isodrcfg); } CKTCadUtility::AddToCurrentSpace(pNew, idEnt); pNew->close(); } return TRUE; } void InsertValve(CUIISQLiteServer &sqlDb, ads_point pt, CString &sValName, AecEqui::ValveType vt, BOOL bParamEqu) { ads_point ptC[2], ptWCS; AcDbObjectId id, idCurSys, idLineType; //在本点选 TCHAR szBuf[256]; struct resbuf eb1; eb1.restype = 0; _tcscpy(szBuf, _T("LWPOLYLINE")); eb1.resval.rstring = szBuf; eb1.rbnext = NULL; ads_name ss, ent; ads_point_set(pt, ptC[0]); ads_point_set(pt, ptC[1]); acdbUcs2Wcs(pt, ptWCS, false); ptC[0][X] -= CoreTools::PixelToWcs(10); ptC[0][Y] -= CoreTools::PixelToWcs(10); ptC[1][X] += CoreTools::PixelToWcs(10); ptC[1][Y] += CoreTools::PixelToWcs(10); int nRes = acedSSGet(_T("C"), ptC[0], ptC[1], &eb1, ss); if (nRes == RTNORM) { Adesk::Int32 lLen = 0; acedSSLength(ss, &lLen); if (lLen == 0) { acutPrintf(_T("\n没有选择到系统管线!")); } acedSSName(ss, 0, ent); acdbGetObjectId(id, ent); acedSSFree(ss); AcDbEntity *pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForWrite)) { ISODrawCfg isodrcfg; memset(&isodrcfg, 0, sizeof(ISODrawCfg)); isodrcfg.m_bVlvISOV = TRUE; _tcscpy(isodrcfg.m_sScale, _T("1:100")); if (AcISOPolyline::ReadISOXData(pEnt, isodrcfg)) { AcGePoint3d ptHit; AcGeVector3d vtDir(1, 0, 0); AcDbPolyline *pPl = AcDbPolyline::cast(pEnt); if (pPl != NULL) { pPl->getClosestPointTo(asPnt3d(ptWCS), ptHit); ptHit.z = 0.0;//2dplye pPl->getFirstDeriv(asPnt3d(ptWCS), vtDir); } AcDbObjectId idCurSys = CoreTools::getLyForPipe(isodrcfg.m_sCurrSys); AcDbObjectId idLineType = KTSetting::InitLineStyle(_T("CONTINUOUS")); struct resbuf *result = NULL, *list = NULL, *pTmp; list = acutBuildList(RTSTR, _T("newValEqu"), RTSTR, sValName, RTREAL, isodrcfg.m_dDn,RTSHORT, bParamEqu, RTNONE); //调用 nRes = acedInvoke(list, &result); //acutPrintf(_T("\nacedInvoke RS=%d"),nRes); pTmp = result; if (pTmp == NULL) { pEnt->close(); return; } if (pTmp->restype == RTINT64 && pTmp->resval.mnInt64 > 0) { AecDbEwEquipment *pEqu = (AecDbEwEquipment *)pTmp->resval.mnInt64; if (pEqu != NULL) { AecDbObjXDataMap *pXDataMap = pEqu->GetSpecialtyData(AcDb::kForWrite); //还原,ptHit,vtDir原始坐标 AecISOCrdWatch watch(TRUE); watch.SetISOMode(isodrcfg.m_nView, isodrcfg.m_nAngle); AcGeVector3d vtX, vtY, vtZ; watch.GetISOCrd(vtX, vtY, vtZ); bool bISOCrd = true; //TEST if (vtDir.isParallelTo(vtZ))//Z { pEqu->SetInsert(AcGePoint3d::kOrigin, AcGeVector3d::kZAxis);//?? AcGeMatrix3d xR; xR.setToRotation(PI / 2.0, AcGeVector3d::kYAxis); pEqu->AddTransform(xR); xR.setToRotation(PI / 2.0, AcGeVector3d::kZAxis); pEqu->AddTransform(xR); } else if (vtDir.isParallelTo(vtX))//X { pEqu->SetInsert(AcGePoint3d::kOrigin, AcGeVector3d::kXAxis); } else if (vtDir.isParallelTo(vtY))//Y { pEqu->SetInsert(AcGePoint3d::kOrigin, AcGeVector3d::kYAxis); } else { if (vtDir.isParallelTo(AcGeVector3d::kXAxis)) { //不是ISO 坐标系; 水平时不ISO bISOCrd = false; } } BOOL bVolHasFlang = FALSE; struct resbuf *rbFlange = pTmp->rbnext; if (rbFlange != NULL) { bVolHasFlang = rbFlange->resval.rint; } double dWD = 0.0, dWh = 0.0, dThk = 0.0, dPre = 1.0, dN = 0.0; if (bVolHasFlang) { //两头插入法兰 CoreTools::QueryFlangData(&sqlDb, isodrcfg.m_dDn, 1.0, dWD, dWh, dThk, dN, NULL, NULL); } //两头法兰定位参考线 AcGeVector3d vtIns; AcGePoint3d ptIns; AecInterface inf1, inf2; pEqu->GetInterface(0, inf1); pEqu->GetInterface(1, inf2); pEqu->GetInsert(ptIns,vtIns); //ISO提取... AcDbVoidPtrArray arEntPtrs; CovertToISO(pEqu, arEntPtrs, isodrcfg, bISOCrd); //法兰 if (bVolHasFlang) { CovertEquFlangToISO(pEqu, 2.0*dWh, arEntPtrs, isodrcfg, bISOCrd); } AcGeVector3d vtMove; vtMove = ptHit.asVector(); AcGeMatrix3d xMove; xMove.setToTranslation(vtMove); AcDbEntity *pSubEnt = NULL; AcGeMatrix3d xRot; bool bIs45 = isodrcfg.m_nAngle > 0 ? true : false; AcDbObjectId idSub, idGrp; AcDbObjectIdArray arIds; for (int n = 0; n < arEntPtrs.length(); n++) { pSubEnt = (AcDbEntity *)arEntPtrs.at(n); pSubEnt->transformBy(xMove); } //45 ISO if (vtDir.isParallelTo(vtY) && bIs45)//Y) { double dRot = 0.75 * PI; xRot.setToRotation(dRot, AcGeVector3d::kZAxis, ptHit); for (int n = 0; n < arEntPtrs.length(); n++) { pSubEnt = (AcDbEntity *)arEntPtrs.at(n); pSubEnt->transformBy(xRot); } } for (int n = 0; n < arEntPtrs.length(); n++) { pSubEnt = (AcDbEntity *)arEntPtrs.at(n); idSub = CoreTools::AddToModelSpace(pSubEnt); arIds.append(idSub); } double dLen = 330; pEqu->GetInterface(0, inf1); pEqu->GetInterface(1, inf2); dLen = inf1.ptPos.distanceTo(inf2.ptPos); //如果含法兰,则... dLen += 4.0 * dWh;//可以放大 BreakPIDPipe(pPl,ptHit,dLen); CKTCadUtility::CreateAcDbGroup(arIds); //TEST //CoreTools::AddToModelSpace(pEqu); delete pEqu; } } if (result != NULL) { acutRelRb(result); } if (list != NULL) { acutRelRb(list); } } pEnt->close(); } } } //插入阀门 void PL_CRFMCmd() { KTCADSysVar var(_T("OSMODE"), 999); //阀门调用 SHads_command(RTSTR, _T("PL_INVKEQU"), RTNONE); //弹出对话框,选择阀门类型... struct resbuf *rsGet = NULL, *lstAsk = NULL,*pTmp = NULL; lstAsk = acutBuildList(RTSTR, _T("getValNames"), RTSTR, _T("阀门"),RTNONE); //调用 int nRes = acedInvoke(lstAsk, &rsGet); //acutPrintf(_T("\nacedInvoke RS=%d"), nRes); AcArray arVals; AecEqui::VlvType valt; pTmp = rsGet; while (pTmp != NULL) { if (pTmp->restype == RTSHORT) { memset(&valt,0,sizeof(AecEqui::VlvType)); valt.eType = (AecEqui::ValveType)pTmp->resval.rint; arVals.append(valt); } else if (pTmp->restype == RTSTR) { if (!arVals.isEmpty()) { AecEqui::VlvType &vl = arVals.last(); _tcscpy(vl.szNameCn, pTmp->resval.rstring); acutDelString(pTmp->resval.rstring); } } pTmp = pTmp->rbnext; } if (rsGet != NULL) acutRelRb(rsGet); acutRelRb(lstAsk); CAcModuleResourceOverride myResources; CValLstDlg dlg; dlg.SetValNames(arVals); if (IDOK != dlg.DoModal()) return; CString sValName; AecEqui::ValveType vt = dlg.GetSelValName(sValName); BOOL bParamEqu = dlg.m_bParaEqu; ads_point pt,ptBase; CUIISQLiteServer sqlDb; CString dbPath = FilePath::GetSysDir(); dbPath += _T("\\Plumbing.db"); if (!sqlDb.InitADOServer(dbPath)) { AfxMessageBox(_T("数据库驱动加载数据库Plumbing.db失败!")); return; } while (true) { acedInitGet(RSG_NONULL, _T("R V")); nRes = acedGetPoint(NULL, _T("\n请选择位置添加阀门[参考点(R)/阀门类型(V)]<退出>:"), pt); if (nRes == RTNORM) { InsertValve(sqlDb,pt,sValName,vt, bParamEqu); } else if (nRes == RTKWORD) { TCHAR szKey[3]; acedGetInput(szKey); if (_tcsicmp(_T("R"), szKey) == 0) { //参考点<退出>: nRes = acedGetPoint(NULL, _T("\n请选择参考点<退出>:"), ptBase); if (nRes == RTNORM) { nRes = acedGetPoint(ptBase, _T("\n请选择位置添加阀门<退出>:"), pt); if (nRes == RTNORM) { InsertValve(sqlDb, pt, sValName, vt, bParamEqu); } else { break; } } else { break; } } else if (_tcsicmp(_T("V"), szKey) == 0) { if (IDOK != dlg.DoModal()) return; vt = dlg.GetSelValName(sValName); bParamEqu = dlg.m_bParaEqu; } } else if (nRes == RTCAN || nRes == RTNONE) { break; } } } bool SorFunc(PointDir &ptdir1, PointDir &ptdir2) { AcGeVector3d vt = ptdir2.pt - ptdir1.pt; if (vt.dotProduct(ptdir1.vt) > 0) { return true; } return false; } void SortPoints(std::vector &arPts, AcGeVector3d &vtDir) { PointDir ptDir; std::vector vtPtDir; for (int i = 0; i < arPts.size(); i++) { ptDir.pt = arPts.at(i); ptDir.vt = vtDir; vtPtDir.push_back(ptDir); } std::sort(vtPtDir.begin(), vtPtDir.end(), SorFunc); arPts.clear(); for (int i = 0; i < vtPtDir.size(); i++) { arPts.push_back(vtPtDir.at(i).pt); } } void SortPoints(AcGePoint3dArray& arPts, AcGeVector3d& vtDir) { std::vector vPts; for (int i = 0;i < arPts.length();i++) { vPts.push_back(arPts.at(i)); } SortPoints(vPts, vtDir); arPts.removeAll(); for (int i = 0; i < vPts.size(); i++) { arPts.append(vPts.at(i)); } } void XlineIntsWith(AcDbLine* pLine, AcDbVoidPtrArray& arEnts, AcGePoint3dArray& arPts) { Acad::ErrorStatus es; AcDbEntity *pEnt = NULL; for (int i = 0;i < arEnts.length();i++) { pEnt = (AcDbEntity *)arEnts.at(i); if (pEnt != NULL) { AcDbCurve *pCrv = AcDbCurve::cast(pEnt); if (pCrv != NULL) { es = pLine->intersectWith(pCrv, AcDb::kOnBothOperands, AcGePlane::kXYPlane,arPts); } delete pEnt; } } } void InsertSysValve(CUIISQLiteServer &sqlDb, ads_point pt, AcDbObjectId &idBlkRec) { ads_point ptC[2], ptWCS; AcDbObjectId id, idCurSys, idLineType; //在本点选 TCHAR szBuf[256]; struct resbuf eb1; eb1.restype = 0; _tcscpy(szBuf, _T("LWPOLYLINE")); eb1.resval.rstring = szBuf; eb1.rbnext = NULL; ads_name ss, ent; ads_point_set(pt, ptC[0]); ads_point_set(pt, ptC[1]); acdbUcs2Wcs(pt, ptWCS, false); ptC[0][X] -= CoreTools::PixelToWcs(10); ptC[0][Y] -= CoreTools::PixelToWcs(10); ptC[1][X] += CoreTools::PixelToWcs(10); ptC[1][Y] += CoreTools::PixelToWcs(10); int nRes = acedSSGet(_T("C"), ptC[0], ptC[1], &eb1, ss); if (nRes == RTNORM) { Adesk::Int32 lLen = 0; acedSSLength(ss, &lLen); if (lLen == 0) { acutPrintf(_T("\n没有选择到系统管线!")); } acedSSName(ss, 0, ent); acdbGetObjectId(id, ent); acedSSFree(ss); AcDbEntity *pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForWrite)) { ISODrawCfg isodrcfg; memset(&isodrcfg, 0, sizeof(ISODrawCfg)); isodrcfg.m_bVlvISOV = TRUE; _tcscpy(isodrcfg.m_sScale, _T("1:100")); if (AcISOPolyline::ReadISOXData(pEnt, isodrcfg)) { AcGePoint3d ptHit, ptM; AcGeVector3d vtDir(1, 0, 0); AcDbPolyline *pPl = AcDbPolyline::cast(pEnt); if (pPl != NULL) { pPl->getClosestPointTo(asPnt3d(ptWCS), ptHit); ptHit.z = 0.0;//2dplye pPl->getFirstDeriv(asPnt3d(ptWCS), vtDir); } AcDbObjectId idCurSys = CoreTools::getLyForPipe(isodrcfg.m_sCurrSys); AcDbObjectId idLineType = KTSetting::InitLineStyle(_T("CONTINUOUS")); AcDbBlockReference *pRef = new AcDbBlockReference; pRef->setBlockTableRecord(idBlkRec); pRef->setPosition(asPnt3d(pt)); pRef->setScaleFactors(AcGeScale3d(1, 1, 1)); AcDbExtents ext; pRef->geomExtentsBestFit(ext); CString sSQL, sOD = _T("440"); sSQL.Format(_T("select distinct [法兰外径] from [AecFlangeData] where [公称直径]=%d"), (int)(isodrcfg.m_dDn +0.5)); sqlDb.GetSelData(sSQL, sOD); //DN=200 按法兰外径匹配放大 double dScale = _ttof(sOD) / (ext.maxPoint().y - ext.minPoint().y); AcGeScale3d sc(dScale, dScale, dScale); pRef->setScaleFactors(sc); pRef->setLayer(idCurSys); pRef->setPosition(ptHit); double dRo = AcGeVector3d::kXAxis.angleTo(vtDir, AcGeVector3d::kZAxis); if (vtDir.x < 0 && vtDir.y < 0)//III 变成 III->I { dRo = AcGeVector3d::kXAxis.angleTo(-vtDir, AcGeVector3d::kZAxis); } if (vtDir.x < 0 && vtDir.y > 0)//II 变成 II->IV { dRo = AcGeVector3d::kXAxis.angleTo(-vtDir, AcGeVector3d::kZAxis); } pRef->setRotation(dRo); AcGePoint3dArray arPts; vtDir.normalize(); AcDbLine ln; ln.setStartPoint(ptHit + 2000 * vtDir); ln.setEndPoint(ptHit - 2000 * vtDir); AcDbVoidPtrArray arEnts; pRef->explode(arEnts); //xln.intersectWith(pRef, AcDb::kOnBothOperands, arPts); XlineIntsWith(&ln, arEnts, arPts); //居中调节 ptM = ptHit; if (arPts.length() >= 2) { ptM = MidPoint(arPts.first(), arPts.last()); AcGeVector3d vtOff = ptHit - ptM; ptHit -= vtOff; pRef->setPosition(ptHit); } pRef->setColorIndex(kGreen); CoreTools::AddToModelSpace(pRef); if (!arPts.isEmpty()) { SortPoints(arPts, vtDir); double dLen = arPts.last().distanceTo(arPts.first()); BreakPIDPipe(pPl, ptM, dLen); } } pEnt->close(); } } } void PL_XTFMCmd() { CAcModuleResourceOverride myResources; CUIISQLiteServer sqlDb; CString dbPath = FilePath::GetSysDir(); dbPath += _T("\\Plumbing.db"); if (!sqlDb.InitADOServer(dbPath)) { AfxMessageBox(_T("数据库驱动加载数据库Plumbing.db失败!")); return; } CTKViewDlg dlg; dlg.SetDefaultFolderShow(_T("阀门"), _T("系统阀门.dwg")); if (IDOK == dlg.DoModal()) { CString strInsertDwgPath = dlg.m_sDwgPath; CString strInsertBlockName = dlg.m_sRcdName; AcDbObjectId idBlkRec; if (InSertBlockFromDwgToCurDb(strInsertDwgPath, strInsertBlockName, idBlkRec)) { ads_point pt, ptBase; /*acedGetPoint(NULL, _T("\nPick point\;"), pt)) AcDbBlockReference *pRef = new AcDbBlockReference; pRef->setBlockTableRecord(idBlkRec); pRef->setPosition(asPnt3d(pt)); pRef->setScaleFactors(AcGeScale3d(1, 1, 1)); AcDbExtents ext; pRef->geomExtentsBestFit(ext); CString sSQL, sOD = _T("440"); sSQL.Format(_T("select distinct [法兰外径] from [AecFlangeData] where [公称直径]=%d"), 300); sqlDb.GetSelData(sSQL, sOD); //DN=200 按法兰外径匹配放大 double dScale = _ttof(sOD) / (ext.maxPoint().y - ext.minPoint().y); AcGeScale3d sc(dScale, dScale, dScale); pRef->setScaleFactors(sc); */ int nRes = 0; while (true) { acedInitGet(RSG_NONULL, _T("R")); nRes = acedGetPoint(NULL, _T("\n请选择位置添加阀门[参考点(R)]<退出>:"), pt); if (nRes == RTNORM) { InsertSysValve(sqlDb, pt, idBlkRec); } else if (nRes == RTKWORD) { TCHAR szKey[3]; acedGetInput(szKey); if (_tcsicmp(_T("R"), szKey) == 0) { //参考点<退出>: nRes = acedGetPoint(NULL, _T("\n请选择参考点<退出>:"), ptBase); if (nRes == RTNORM) { nRes = acedGetPoint(ptBase, _T("\n请选择位置添加阀门<退出>:"), pt); if (nRes == RTNORM) { InsertSysValve(sqlDb, pt, idBlkRec); } else { break; } } else { break; } } } else if (nRes == RTCAN || nRes == RTNONE) { break; } } } } } static bool HasBimDataApp(const AcDbObjectId& id, AecDbObjXDataMap& xDataMap, ISODrawCfg &isodrcfg) { bool bHas = false; AcDbEntity *pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead)) { if (xDataMap.Read(pEnt, BIMDATA_APP)) { bHas = true; } if (AcISOPolyline::ReadISOXData(pEnt, isodrcfg)) { bHas = true; } pEnt->close(); } return bHas; } //标注阀门 void PL_BZFMCmd() { if (!CoreTools::hasCSSZ(true)) { acedAlert(_T("\n系统没有初始化!请运行初始化命令!")); return; } ads_point pt,pt2; ads_name ent; struct resbuf *pRb = acutBuildList(RTDXF0, DXF_ISOENT, 0); int nRes = 0; //LPCTSTR PipelineTools::gLayer_Pipe_Dim = _T("LAY_PP3D_DIM"); //LPCTSTR PipelineTools::gTextStyle_Pipe_Dim = _T("Pipe_Dim"); //pXDataMap->Write(pPoly, BIMDATA_APP); AcDbObjectId idDimLay = KTSetting::InitLayer(_T("LAY_PP3D_DIM")); AcDbObjectId idTSty = CKTCadUtility::InitTextStyle(_T("Pipe_Dim")); AcDbObjectId id; AecDbObjXDataMap xDataMap; CAcModuleResourceOverride myResources; CDimTxtDlg dimtxtDlg; ISODrawCfg isodrcfg; while (true) { nRes = CKTCadUtility::SelectEntity(_T("\n请选择要标注的阀门实体:"), ent, pRb, pt); if (nRes == RTNORM) { acdbGetObjectId(id, ent); if (HasBimDataApp(id,xDataMap, isodrcfg)) { nRes = acedGetPoint(pt, _T("\n请选择位置:"), pt2); if (nRes == RTNORM) { dimtxtDlg.m_sDimTxt = _T(""); xDataMap.GetAt(KEY_NAME, dimtxtDlg.m_sDimTxt); //弹出界面 if (IDOK == dimtxtDlg.DoModal()) { ads_point pt11, pt22; acdbUcs2Wcs(pt, pt11, false); acdbUcs2Wcs(pt2, pt22, false); AcGePoint3d ptFr = asPnt3d(pt11); AcGePoint3d ptTo = asPnt3d(pt22); AecDbEwPipeDim *pDim = new AecDbEwPipeDim; pDim->AddAecDbWEntity(id); pDim->SetDimStyle(0); pDim->SetDimDir(0); pDim->SetDimTextUporDownFlag(1); pDim->SetTextStyleId(idTSty); pDim->SetTextLayerId(idDimLay); pDim->SetPScale( GetISOScale(dimtxtDlg.m_sScale)); pDim->SetDimTextUporDownFlag(0); CString sDimDwn = _T(""); pDim->AddDimText(dimtxtDlg.m_sDimTxt, sDimDwn); pDim->SetTextHeight(dimtxtDlg.m_dTxtH); pDim->SetTextWidthScale(dimtxtDlg.m_dWScale); pDim->AppendPoint(ptFr); pDim->AppendPoint(ptTo); pDim->SetDimupdownSpace(0.0); pDim->SetTextLayerId(idDimLay); CoreTools::AddToModelSpace(pDim); } } } else { acutPrintf(_T("\n选择的实体没有阀门信息!")); } } else { break; } } acutRelRb(pRb); } static double UnderLineLength(LPCTSTR pszDimup,double dTxtH,double dScale,AcDbObjectId&idDimSty) { AcGiTextStyle giTxtStyle; fromAcDbTextStyle(giTxtStyle, idDimSty); giTxtStyle.setTextSize(dTxtH * dScale); giTxtStyle.setXScale(0.75); CString sDimup = pszDimup; int nLen = sDimup.GetLength(); AcGePoint2d pt2d = giTxtStyle.extents(sDimup, Adesk::kFalse, nLen, Adesk::kTrue); return pt2d.x; } static AcGePoint3d MakeTr(AcGePoint3d& ptM,const AcGeVector3d& vtDir, double dTxtH,double dScale, int bElStyle, AcDbObjectId& idLay) { AcGeVector3d vtV = vtDir; vtV.rotateBy(PI / 2.0, AcGeVector3d::kZAxis); double dH = dTxtH * dScale; double dL = 1.41421357 * dH; AcGePoint3d ptGe[4],ptT; ptT = ptM; if (bElStyle == 1) ptT += 0.24 * dScale * vtDir; ptGe[0] = ptT; ptGe[1] = ptGe[0] + dH * vtDir; ptGe[1] += vtV * dH; ptGe[2] = ptGe[1] - 2.0 * dH * vtDir; ptGe[3] = ptGe[0]; AcDbPolyline* pPoly = new AcDbPolyline; for(int i = 0;i < 4;i++) pPoly->addVertexAt(i, ptGe[i].convert2d(AcGePlane::kXYPlane)); pPoly->setConstantWidth(0); pPoly->setLayer(idLay); pPoly->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pPoly->setNormal(AcGeVector3d::kZAxis); CoreTools::AddToModelSpace(pPoly); //文字开始点 if (bElStyle == 0)//尾巴 { ptM = ptGe[1]; ptT = ptM + 0.24 * dScale * vtV; } else if(bElStyle == 1)//三角 { ptM = ptGe[0]; ptT = ptGe[0] + 0.9 * dL * vtDir; ptT += 0.25 * dScale * vtV; } return ptT; } static void MakeDim44(AcGePoint3d ptPos, AcGeVector3d vtDir, double dEl, double dRefEl, double dScale, int bElStyle, AcDbObjectId &idLay, AcDbObjectId &idDimSty) { AcGePoint3d ptS = ptPos; AcGePoint3d ptE = ptPos + vtDir; AcGePoint3d ptT,ptM,ptT2; AcGeVector3d vtOff = vtDir; vtOff.normalize(); double dTxtH = 3.5, dTxWS = 1.0; double dDimoffset = 3.5 * dScale; ptS += vtOff * dDimoffset; double dRo = AcGeVector3d::kXAxis.angleTo(vtDir, AcGeVector3d::kZAxis); if (vtDir.x < 0 && vtDir.y < 0)//III 变成 III->I { dRo = AcGeVector3d::kXAxis.angleTo(-vtDir, AcGeVector3d::kZAxis); vtDir.negate(); ptT = ptS; ptS = ptE; ptE = ptT; vtOff.negate(); } if (vtDir.x < 0 && vtDir.y > 0)//II 变成 II->IV { dRo = AcGeVector3d::kXAxis.angleTo(-vtDir, AcGeVector3d::kZAxis); vtDir.negate(); ptT = ptS; ptS = ptE; ptE = ptT; vtOff.negate(); } CString sDimTxt; sDimTxt.Format(_T("%.3f"), dEl); double dTxtLen = UnderLineLength(sDimTxt, dTxtH, dScale, idDimSty); ptM = MidPoint(ptS, ptE); AcDbPolyline *pPoly = NULL; if (bElStyle == 0)//带尾巴标高 { ptT = MakeTr(ptM, vtOff,dTxtH,dScale,bElStyle, idLay); } else if (bElStyle == 1)//三角形标高 { ptT = MakeTr(ptM, vtOff,dTxtH,dScale,bElStyle, idLay); } AcDbText *pText = new AcDbText; pText->setPosition(ptT); pText->setRotation(dRo); pText->setHeight(dTxtH * dScale); pText->setWidthFactor(0.75); pText->setNormal(AcGeVector3d::kZAxis); pText->setHorizontalMode(AcDb::kTextLeft); pText->setVerticalMode(AcDb::kTextBottom); pText->setAlignmentPoint(ptT); sDimTxt.TrimRight(_T('0')); if (sDimTxt.CompareNoCase(_T("0.")) == 0) sDimTxt = _T("0"); if (sDimTxt.Right(1).CompareNoCase(_T(".")) == 0) sDimTxt += _T("0"); pText->setTextString(sDimTxt); pText->setTextStyle(idDimSty); pText->setLayer(idLay); CoreTools::AddToModelSpace(pText); if (bElStyle == 0)//带尾巴标高 { ptT2 = ptM + vtOff * dTxtLen; pPoly = new AcDbPolyline; pPoly->addVertexAt(0, ptM.convert2d(AcGePlane::kXYPlane)); pPoly->addVertexAt(1, ptT2.convert2d(AcGePlane::kXYPlane)); pPoly->setConstantWidth(0); pPoly->setLayer(idLay); pPoly->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pPoly->setNormal(AcGeVector3d::kZAxis); CoreTools::AddToModelSpace(pPoly); } //底线 pPoly = new AcDbPolyline; pPoly->addVertexAt(0, ptS.convert2d(AcGePlane::kXYPlane)); pPoly->addVertexAt(1, ptE.convert2d(AcGePlane::kXYPlane)); pPoly->setConstantWidth(0); pPoly->setLayer(idLay); pPoly->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pPoly->setNormal(AcGeVector3d::kZAxis); CoreTools::AddToModelSpace(pPoly); } //标注标高 void PL_BZBGCmd() { if (!CoreTools::hasCSSZ(true)) { acedAlert(_T("\n系统没有初始化!请运行初始化命令!")); return; } AcDbObjectId idDimLay = KTSetting::InitLayer(_T("LAY_PP3D_DIM")); AcDbObjectId idTextStyle = CKTCadUtility::InitTextStyle(_T("Pipe_Dim")); struct resbuf *pRb = acutBuildList(RTDXF0, _T("LINE,LWPOLYLINE"), 0); ads_name ss, ent; ads_point pt1, pt2, pt3,ptC[2]; ads_point pt11, pt22, pt33; int nRes = 0, nRes2 = 0; double dEl = 0.0; ISODrawCfg isodrcfg; memset(&isodrcfg, 0, sizeof(ISODrawCfg)); isodrcfg.m_bVlvISOV = TRUE; AcGeVector3d vtDir; AcDbObjectId id; CAcModuleResourceOverride myResources; CDimTxtDlg dimtxtDlg; AecISOCrdWatch watch; while (true) { nRes = acedGetPoint(NULL, _T("\n选择轴测管线标高标注线起点:"), pt1); if (nRes == RTNORM) { //获取isodrcfg ads_point_set(pt1, ptC[0]); ads_point_set(pt1, ptC[1]); ptC[0][X] -= CoreTools::PixelToWcs(10); ptC[0][Y] -= CoreTools::PixelToWcs(10); ptC[1][X] += CoreTools::PixelToWcs(10); ptC[1][Y] += CoreTools::PixelToWcs(10); nRes2 = acedSSGet(_T("C"), ptC[0], ptC[1], pRb, ss); if (nRes2 == RTNORM) { Adesk::Int32 lLen = 0; acedSSLength(ss, &lLen); if (lLen >= 0) { acedSSName(ss, 0, ent); acdbGetObjectId(id, ent); acedSSFree(ss); AcDbEntity *pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead)) { _tcscpy(isodrcfg.m_sScale, _T("1:100")); if (AcISOPolyline::ReadISOXData(pEnt, isodrcfg)) { watch.SetISOMode(isodrcfg.m_nView, isodrcfg.m_nAngle); } pEnt->close(); } } } nRes = acedGetPoint(pt1, _T("\n选择轴测标高标注线末端点:"), pt2); if (nRes == RTNORM) { acdbUcs2Wcs(pt1, pt11, false); acdbUcs2Wcs(pt2, pt22, false); dimtxtDlg.m_sDimTxt = _T(""); dimtxtDlg.SetElDimtxt(TRUE); if (IDOK == dimtxtDlg.DoModal()) { dEl = _ttof(dimtxtDlg.m_sDimTxt); vtDir = asPnt3d(pt22) - asPnt3d(pt11); MakeDim44(asPnt3d(pt11), vtDir,dEl, 0.0, GetISOScale(isodrcfg.m_sScale), dimtxtDlg.m_bElStyle, idDimLay, idTextStyle); } } } else { break; } } } //标注长度 void PL_BZZCCmd() { if (!CoreTools::hasCSSZ(true)) { acedAlert(_T("\n系统没有初始化!请运行初始化命令!")); return; } //在本点选 TCHAR szBuf[256]; struct resbuf eb1; eb1.restype = 0; _tcscpy(szBuf, _T("LWPOLYLINE,LINE")); eb1.resval.rstring = szBuf; eb1.rbnext = NULL; ads_name ss, ent; ads_point pt1, pt2,pt3,ptm; ads_point pt11, pt22, pt33, ptC[2]; AcGePoint3d ptOn; AcGeVector3d vt; int nRes = 0, nRes2 = 0; double dDist = 0,dAng = 0; CString sDimTxt; AcDbObjectId idDimLay = KTSetting::InitLayer(_T("LAY_PP3D_DIM")); AcDbObjectId idDimStyle = KTSetting::InitDimStyle(_T("GL_DIM")); AcDbObjectId idTextStyle = CKTCadUtility::InitTextStyle(_T("Pipe_Dim")); AcDbObjectId id; CAcModuleResourceOverride myResources; CDimTxtDlg dimtxtDlg; ISODrawCfg isodrcfg; memset(&isodrcfg, 0, sizeof(ISODrawCfg)); isodrcfg.m_bVlvISOV = TRUE; while (true) { nRes = acedGetPoint(NULL, _T("\n选择标注起点:"), pt1); if (nRes == RTNORM) { //获取isodrcfg ads_point_set(pt1, ptC[0]); ads_point_set(pt1, ptC[1]); ptC[0][X] -= CoreTools::PixelToWcs(10); ptC[0][Y] -= CoreTools::PixelToWcs(10); ptC[1][X] += CoreTools::PixelToWcs(10); ptC[1][Y] += CoreTools::PixelToWcs(10); nRes2 = acedSSGet(_T("C"), ptC[0], ptC[1], &eb1, ss); if (nRes2 == RTNORM) { Adesk::Int32 lLen = 0; acedSSLength(ss, &lLen); if (lLen >= 0) { acedSSName(ss, 0, ent); acdbGetObjectId(id, ent); acedSSFree(ss); AcDbEntity *pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead)) { _tcscpy(isodrcfg.m_sScale,_T("1:100")); if (AcISOPolyline::ReadISOXData(pEnt, isodrcfg)) { } pEnt->close(); } } } nRes = acedGetPoint(pt1, _T("\n选择标注终点:"), pt2); if (nRes == RTNORM) { //Midpoint(pt1, pt2, ptm); nRes = acedGetPoint(pt2, _T("\n选择标注文字放置点:"), pt3); if (nRes == RTNORM) { double dDimoffset = asPnt3d(pt3).distanceTo(asPnt3d(ptm)); dDist = asPnt3d(pt1).distanceTo(asPnt3d(pt2)); sDimTxt.Format(_T("%d"),(int)(dDist+0.5)); dimtxtDlg.m_sDimTxt = sDimTxt; dimtxtDlg.m_sScale = isodrcfg.m_sScale; if (dimtxtDlg.m_sScale.IsEmpty()) dimtxtDlg.m_sScale = _T("1:100"); if (IDOK == dimtxtDlg.DoModal()) { acdbUcs2Wcs(pt1, pt11, false); acdbUcs2Wcs(pt2, pt22, false); acdbUcs2Wcs(pt3, pt33, false); AcDbLine ln(asPnt3d(pt11), asPnt3d(pt22)); ln.getClosestPointTo(asPnt3d(pt33), ptOn); vt = asPnt3d(pt33) - ptOn; vt.normalize(); ptOn += vt * 7.0 * GetISOScale(dimtxtDlg.m_sScale); AcDbAlignedDimension *pDim = new AcDbAlignedDimension; pDim->setDimscale(GetISOScale(dimtxtDlg.m_sScale)); pDim->setXLine1Point(asPnt3d(pt11)); pDim->setXLine2Point(asPnt3d(pt22)); pDim->setDimLinePoint(ptOn); pDim->setDimensionText(dimtxtDlg.m_sDimTxt); pDim->setLayer(idDimLay); pDim->setDimensionStyle(idDimStyle); pDim->setDimblk(_T("")); vt = asPnt3d(pt22) - asPnt3d(pt11); dAng = AcGeVector3d::kXAxis.angleTo(vt,AcGeVector3d::kZAxis); pDim->setTextRotation(dAng); CoreTools::AddToModelSpace(pDim); } } else { break; } } else { break; } } else { break; } } } //尺寸标注 void PL_ZCBZCmd() { if (!CoreTools::hasCSSZ(true)) { acedAlert(_T("\n系统没有初始化!请运行初始化命令!")); return; } AcDbObjectId idDimLay = KTSetting::InitLayer(_T("LAY_PP3D_DIM")); AcDbObjectId idDimStyle = KTSetting::InitDimStyle(_T("GL_DIM")); AcDbObjectId idTextStyle = CKTCadUtility::InitTextStyle(_T("Pipe_Dim")); AcDbObjectId id; ads_name ent; ads_point pt; ISODrawCfg isodrcfg; memset(&isodrcfg, 0, sizeof(ISODrawCfg)); isodrcfg.m_bVlvISOV = TRUE; CAcModuleResourceOverride myResources; CDimTxtDlg dimtxtDlg; double dDist = 0.0; AcGePoint3d ptS, ptE,ptOn; ads_point pt1, pt2, pt3; double dPx = CoreTools::PixelToWcs(10); CString sDimTxt; struct resbuf *pRb = acutBuildList(RTDXF0, _T("LINE,LWPOLYLINE"), 0); int nRes = 0; while (true) { nRes = CKTCadUtility::SelectEntity(_T("\n请选择要标注的轴测管线实体:"), ent, pRb, pt); if (nRes == RTNORM) { acdbGetObjectId(id, ent); AcDbEntity *pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead)) { _tcscpy(isodrcfg.m_sScale, _T("1:100")); if (AcISOPolyline::ReadISOXData(pEnt, isodrcfg)) { } AcDbCurve *pCrv = AcDbCurve::cast(pEnt); if (pCrv != NULL) { AcDbLine *pLn = AcDbLine::cast(pCrv); if (pLn != NULL) { pCrv->getStartPoint(ptS); pCrv->getEndPoint(ptE); dDist = ptS.distanceTo(ptE); } AcDbPolyline *pPl = AcDbPolyline::cast(pCrv); if (pPl != NULL) { acdbUcs2Wcs(pt, pt3, false); AcDbLine ln; for (int i = 0;i < pPl->numVerts() - 1;i++) { pPl->getPointAt(i, ptS); pPl->getPointAt(i + 1, ptE); ln.setStartPoint(ptS); ln.setEndPoint(ptE); ln.getClosestPointTo(asPnt3d(pt3), ptOn); if (ptOn.distanceTo(asPnt3d(pt3)) < __max(dPx,10.0)) { dDist = ptS.distanceTo(ptE); break; } } } } pEnt->close(); sDimTxt.Format(_T("%d"), (int)(dDist + 0.5)); dimtxtDlg.m_sDimTxt = sDimTxt; dimtxtDlg.m_sScale = isodrcfg.m_sScale; if (dimtxtDlg.m_sScale.IsEmpty()) dimtxtDlg.m_sScale = _T("1:100"); if (IDOK == dimtxtDlg.DoModal()) { acdbWcs2Ucs(asDblArray(ptE), pt2, false); nRes = acedGetPoint(pt2, _T("\n选择标注文字放置点:"), pt3); if (nRes == RTNORM) { ads_point pt33; acdbUcs2Wcs(pt3, pt33, false); AcDbLine ln(ptS,ptE); ln.getClosestPointTo(asPnt3d(pt33), ptOn); AcGeVector3d vt = asPnt3d(pt33) - ptOn; vt.normalize(); ptOn += vt * 7.0 * GetISOScale(dimtxtDlg.m_sScale); AcDbAlignedDimension *pDim = new AcDbAlignedDimension; pDim->setDimscale(GetISOScale(dimtxtDlg.m_sScale)); pDim->setXLine1Point(ptS); pDim->setXLine2Point(ptE); pDim->setDimLinePoint(ptOn); pDim->setDimensionText(dimtxtDlg.m_sDimTxt); pDim->setLayer(idDimLay); pDim->setDimensionStyle(idDimStyle); pDim->setDimblk(_T("")); vt = ptE - ptS; double dAng = AcGeVector3d::kXAxis.angleTo(vt,AcGeVector3d::kZAxis); pDim->setTextRotation(dAng); CoreTools::AddToModelSpace(pDim); } } } } else { break; } } acutRelRb(pRb); } //标注管径 void PL_BZGJCmd() { ads_name ent; ads_point pt,pt1,pt3; int nRes = 0; struct resbuf *pRb = acutBuildList(RTDXF0, DXF_ISOENT, 0); AcDbObjectId idDimLay = KTSetting::InitLayer(_T("LAY_PP3D_DIM")); AcDbObjectId idDimSty = CKTCadUtility::InitTextStyle(_T("Pipe_Dim")); AcDbObjectId id; AecDbObjXDataMap xDataMap; ISODrawCfg isodrcfg; AcDbEntity *pEnt = NULL; AcGeVector3d vtDir,vtV; AcGePoint3d ptS, ptE,ptOn; double dPx = CoreTools::PixelToWcs(10); bool bHit = false; CString sDimTxt; while (true) { nRes = CKTCadUtility::SelectEntity(_T("\n请选择要标注的轴测管线:"), ent, pRb, pt); if (nRes == RTNORM) { acdbGetObjectId(id, ent); memset(&isodrcfg, 0, sizeof(ISODrawCfg)); _tcscpy(isodrcfg.m_sScale, _T("1:100")); if (HasBimDataApp(id, xDataMap, isodrcfg)) { if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead)) { AcDbCurve *pCrv = AcDbCurve::cast(pEnt); if (pCrv != NULL) { AcDbLine *pLn = AcDbLine::cast(pCrv); if (pLn != NULL) { acdbUcs2Wcs(pt, pt3, false); pLn->getClosestPointTo(asPnt3d(pt3), ptOn); bHit = true; ptS = pLn->startPoint(); ptE = pLn->endPoint(); } AcDbPolyline *pPl = AcDbPolyline::cast(pCrv); if (pPl != NULL) { acdbUcs2Wcs(pt, pt3, false); AcDbLine ln; for (int i = 0; i < pPl->numVerts() - 1; i++) { pPl->getPointAt(i, ptS); pPl->getPointAt(i + 1, ptE); ln.setStartPoint(ptS); ln.setEndPoint(ptE); ln.getClosestPointTo(asPnt3d(pt3), ptOn); if (ptOn.distanceTo(asPnt3d(pt3)) < __max(dPx, 10.0)) { bHit = true; break; } } if (bHit) { vtDir = ptE - ptS; double dRo = AcGeVector3d::kXAxis.angleTo(vtDir, AcGeVector3d::kZAxis); if (vtDir.x < 0 && vtDir.y < 0)//III 变成 III->I { dRo = AcGeVector3d::kXAxis.angleTo(-vtDir, AcGeVector3d::kZAxis); vtDir.negate(); } if (vtDir.x < 0 && vtDir.y > 0)//II 变成 II->IV { dRo = AcGeVector3d::kXAxis.angleTo(-vtDir, AcGeVector3d::kZAxis); vtDir.negate(); } vtDir.normalize(); vtV = vtDir; vtV.rotateBy(PI / 2.0, AcGeVector3d::kZAxis); ptOn += 1.0 * GetISOScale(isodrcfg.m_sScale) * vtV; //DODxt sDimTxt.Format(_T("D%dx%.1f"), (int)(isodrcfg.m_dOD+0.5), isodrcfg.m_dThk); AcDbText *pText = new AcDbText; pText->setPosition(ptOn); pText->setRotation(dRo); pText->setHeight(3.5 * GetISOScale(isodrcfg.m_sScale)); pText->setWidthFactor(0.75); pText->setNormal(AcGeVector3d::kZAxis); pText->setHorizontalMode(AcDb::kTextLeft); pText->setVerticalMode(AcDb::kTextBottom); pText->setAlignmentPoint(ptOn); sDimTxt.TrimRight(_T('0')); if (sDimTxt.CompareNoCase(_T("0.")) == 0) sDimTxt = _T("0"); if (sDimTxt.Right(1).CompareNoCase(_T(".")) == 0) sDimTxt += _T("0"); pText->setTextString(sDimTxt); pText->setTextStyle(idDimSty); pText->setLayer(idDimLay); CoreTools::AddToModelSpace(pText); } } } pEnt->close(); } } else { acedAlert(_T("选择的实体没有轴测信息!")); } } else { break; } } } //垫片间隙 void PL_DPJXCmd() { } static void MakeISOFlange(AecDbEwFitting *pFlang1,const AcGePoint3d& ptPos, const AcGeVector3d& vtDir, AcDbObjectIdArray &arIds, const ISODrawCfg &isodrcfg) { double dWD = 0.0; pFlang1->GetAt(PIPE_WD, dWD); double dTh = 0; pFlang1->GetAt(PIPE_THICK, dTh); AecInterface inf; pFlang1->GetInterface(0,inf); AcGePoint3d ptGe[6]; ptGe[0] = ptPos + vtDir * dWD * 0.5; ptGe[1] = ptPos - vtDir * dWD * 0.5; AcDbObjectId idCurSys = CoreTools::getLyForPipe(isodrcfg.m_sCurrSys); AcDbPolyline *pPoly = new AcDbPolyline; pPoly->addVertexAt(0, ptGe[0].convert2d(AcGePlane::kXYPlane)); pPoly->addVertexAt(1, ptGe[1].convert2d(AcGePlane::kXYPlane)); pPoly->setConstantWidth(isodrcfg.m_dPipeW*GetISOScale(isodrcfg.m_sScale)); pPoly->setLayer(idCurSys); pPoly->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pPoly->setNormal(AcGeVector3d::kZAxis); AecDbObjXDataMap *pXDataMap = pFlang1->GetSpecialtyData(AcDb::kForWrite); if (pXDataMap != NULL) { pXDataMap->Write(pPoly, BIMDATA_APP); } arIds.append(CoreTools::AddToModelSpace(pPoly)); } void InsertSFlang(CUIISQLiteServer &sqlDb, ads_point pt,int nFlangs) { ads_point ptC[2], ptWCS; AcDbObjectId id, idCurSys, idLineType; //在本点选 TCHAR szBuf[256]; struct resbuf eb1; eb1.restype = 0; _tcscpy(szBuf, _T("LWPOLYLINE")); eb1.resval.rstring = szBuf; eb1.rbnext = NULL; ads_name ss, ent; ads_point_set(pt, ptC[0]); ads_point_set(pt, ptC[1]); acdbUcs2Wcs(pt, ptWCS, false); ptC[0][X] -= CoreTools::PixelToWcs(10); ptC[0][Y] -= CoreTools::PixelToWcs(10); ptC[1][X] += CoreTools::PixelToWcs(10); ptC[1][Y] += CoreTools::PixelToWcs(10); int nRes = acedSSGet(_T("C"), ptC[0], ptC[1], &eb1, ss); if (nRes == RTNORM) { Adesk::Int32 lLen = 0; acedSSLength(ss, &lLen); if (lLen == 0) { acutPrintf(_T("\n没有选择到系统管线!")); } acedSSName(ss, 0, ent); acdbGetObjectId(id, ent); acedSSFree(ss); AcDbEntity *pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForWrite)) { ISODrawCfg isodrcfg; memset(&isodrcfg, 0, sizeof(ISODrawCfg)); isodrcfg.m_bVlvISOV = TRUE; _tcscpy(isodrcfg.m_sScale, _T("1:100")); if (AcISOPolyline::ReadISOXData(pEnt, isodrcfg)) { AcGePoint3d ptHit,ptPos; AcGeVector3d vtDir(1, 0, 0); AcDbPolyline *pPl = AcDbPolyline::cast(pEnt); if (pPl != NULL) { pPl->getClosestPointTo(asPnt3d(ptWCS), ptHit); ptHit.z = 0.0;//2dplye pPl->getFirstDeriv(asPnt3d(ptWCS), vtDir); vtDir.normalize(); } AcDbObjectId idCurSys = CoreTools::getLyForPipe(isodrcfg.m_sCurrSys); AcDbObjectId idLineType = KTSetting::InitLineStyle(_T("CONTINUOUS")); //原点2法兰 struct resbuf *result = NULL, *list = NULL, *pTmp; list = acutBuildList(RTSTR, _T("newFlang"), RTREAL, isodrcfg.m_dDn,RTSHORT,2,RTNONE); //调用 nRes = acedInvoke(list, &result); pTmp = result; if (pTmp == NULL ) { pEnt->close(); return; } //还原,ptHit,vtDir原始坐标 AecISOCrdWatch watch(TRUE); watch.SetISOMode(isodrcfg.m_nView, isodrcfg.m_nAngle); AcGeVector3d vtX, vtY, vtZ; watch.GetISOCrd(vtX, vtY, vtZ); AecDbEwFitting *pFlang1 = NULL; AecDbEwFitting *pFlang2 = NULL; if (pTmp->restype == RTINT64 && pTmp->resval.mnInt64 > 0) { pFlang1 = (AecDbEwFitting *)pTmp->resval.mnInt64; pTmp = pTmp->rbnext; if (pTmp->restype == RTINT64 && pTmp->resval.mnInt64 > 0) { pFlang2 = (AecDbEwFitting *)pTmp->resval.mnInt64; } } if (pFlang1 != NULL && pFlang2 != NULL) { AcGeVector3d vtX, vtY, vtZ; watch.GetISOCrd(vtX, vtY, vtZ); double dWh = 0.0; pFlang1->GetAt(PIPE_THICK, dWh);//总厚 AcDbObjectIdArray arIds; double dThick = dWh; pFlang1->GetAt(PIPE_THICK, dThick); //TEST if (vtDir.isParallelTo(vtZ))//Z { //此处绘制 if (nFlangs == 2) { ptPos = ptHit - vtDir * dThick; MakeISOFlange(pFlang1, ptPos, vtX, arIds,isodrcfg); ptPos = ptHit + vtDir * dThick; MakeISOFlange(pFlang1, ptPos, vtX, arIds, isodrcfg); } else { ptPos = ptHit; MakeISOFlange(pFlang1, ptPos, vtX, arIds, isodrcfg); } } else if (vtDir.isParallelTo(vtX))//X { if (isodrcfg.m_bVlvISOV) { //此处绘制 if (nFlangs == 2) { ptPos = ptHit - vtDir * dThick; MakeISOFlange(pFlang1, ptPos, AcGeVector3d::kYAxis, arIds, isodrcfg); ptPos = ptHit + vtDir * dThick; MakeISOFlange(pFlang1, ptPos, AcGeVector3d::kYAxis, arIds, isodrcfg); } else { ptPos = ptHit; MakeISOFlange(pFlang1, ptPos, AcGeVector3d::kYAxis, arIds, isodrcfg); } } else { //此处绘制 if (nFlangs == 2) { ptPos = ptHit - vtDir * dThick; MakeISOFlange(pFlang1, ptPos, vtY, arIds, isodrcfg); ptPos = ptHit + vtDir * dThick; MakeISOFlange(pFlang1, ptPos, vtY, arIds, isodrcfg); } else { ptPos = ptHit; MakeISOFlange(pFlang1, ptPos, vtY, arIds, isodrcfg); } } } else if (vtDir.isParallelTo(vtY))//Y { if (isodrcfg.m_bVlvISOV) { //此处绘制 if (nFlangs == 2) { ptPos = ptHit - vtDir * dThick; MakeISOFlange(pFlang1, ptPos, AcGeVector3d::kYAxis, arIds, isodrcfg); ptPos = ptHit + vtDir * dThick; MakeISOFlange(pFlang1, ptPos, AcGeVector3d::kYAxis, arIds, isodrcfg); } else { ptPos = ptHit; MakeISOFlange(pFlang1, ptPos, AcGeVector3d::kYAxis, arIds, isodrcfg); } } else { //此处绘制 if (nFlangs == 2) { ptPos = ptHit - vtDir * dThick; MakeISOFlange(pFlang1, ptPos, vtX, arIds, isodrcfg); ptPos = ptHit + vtDir * dThick; MakeISOFlange(pFlang1, ptPos, vtX, arIds, isodrcfg); } else { ptPos = ptHit; MakeISOFlange(pFlang1, ptPos, vtX, arIds, isodrcfg); } } } //如果含法兰,则... double dLen = 2.0 * dThick;//可以放大 if (nFlangs == 1) dLen = dThick; BreakPIDPipe(pPl, ptHit, dLen); CKTCadUtility::CreateAcDbGroup(arIds); //TEST //CoreTools::AddToModelSpace(pFlang1); //CoreTools::AddToModelSpace(pFlang2); delete pFlang1; delete pFlang2; } if (list) acutRelRb(list); if (result) acutRelRb(result); } pEnt->close(); } } } //插单法兰 void PL_CDFLCmd() { KTCADSysVar var(_T("OSMODE"), 999); //阀门调用 SHads_command(RTSTR, _T("PL_INVKEQU"), RTNONE); int nRes = 0; ads_point pt, ptBase; CUIISQLiteServer sqlDb; CString dbPath = FilePath::GetSysDir(); dbPath += _T("\\Plumbing.db"); if (!sqlDb.InitADOServer(dbPath)) { AfxMessageBox(_T("数据库驱动加载数据库Plumbing.db失败!")); return; } while (true) { acedInitGet(RSG_NONULL, _T("R")); nRes = acedGetPoint(NULL, _T("\n请选择位置添加阀门[参考点(R)]<退出>:"), pt); if (nRes == RTNORM) { InsertSFlang(sqlDb, pt,1); } else if (nRes == RTKWORD) { //参考点<退出>: nRes = acedGetPoint(NULL, _T("\n请选择参考点<退出>:"), ptBase); if (nRes == RTNORM) { nRes = acedGetPoint(ptBase, _T("\n请选择位置添加阀门<退出>:"), pt); if (nRes == RTNORM) { InsertSFlang(sqlDb, pt,1); } else { break; } } else { break; } } else if (nRes == RTCAN || nRes == RTNONE) { break; } } } //插双法兰 void PL_CSFLCmd() { KTCADSysVar var(_T("OSMODE"), 999); //阀门调用 SHads_command(RTSTR, _T("PL_INVKEQU"), RTNONE); int nRes = 0; ads_point pt, ptBase; CUIISQLiteServer sqlDb; CString dbPath = FilePath::GetSysDir(); dbPath += _T("\\Plumbing.db"); if (!sqlDb.InitADOServer(dbPath)) { AfxMessageBox(_T("数据库驱动加载数据库Plumbing.db失败!")); return; } while (true) { acedInitGet(RSG_NONULL, _T("R")); nRes = acedGetPoint(NULL, _T("\n请选择位置添加阀门[参考点(R)]<退出>:"), pt); if (nRes == RTNORM) { InsertSFlang(sqlDb, pt,2); } else if (nRes == RTKWORD) { //参考点<退出>: nRes = acedGetPoint(NULL, _T("\n请选择参考点<退出>:"), ptBase); if (nRes == RTNORM) { nRes = acedGetPoint(ptBase, _T("\n请选择位置添加阀门<退出>:"), pt); if (nRes == RTNORM) { InsertSFlang(sqlDb, pt,2); } else { break; } } else { break; } } else if (nRes == RTCAN || nRes == RTNONE) { break; } } } static void MakeISOReducer(AecDbEwFitting *pReducer, const AcGePoint3d &ptPos, const AcGeVector3d &vtDir, const AcGeVector3d& vtIso,AcDbObjectIdArray &arIds, const ISODrawCfg &isodrcfg,int nPos) { AecInterface inf1, inf2; pReducer->GetInterface(0, inf1); pReducer->GetInterface(1, inf2); double dLen = inf1.ptPos.distanceTo(inf2.ptPos); AcGePoint3d ptHit = ptPos; if (nPos >= 0) ptHit += vtIso * 0.5 * dLen; AcGePoint3d ptGe[5]; ptGe[0] = ptHit; ptGe[0] -= vtIso * 0.5 * dLen; ptGe[0] += vtDir * 0.5 * inf1.dSize1; ptGe[3] = ptGe[0] - vtDir * inf1.dSize1; ptGe[1] = ptHit; ptGe[1] += vtIso * 0.5 * dLen; ptGe[1] += vtDir * 0.5 * inf2.dSize1; ptGe[2] = ptGe[1] - vtDir * inf2.dSize1; ptGe[4] = ptGe[0]; AcDbPolyline *pPoly = FormatPolyline(ptGe, 5); if (pPoly != NULL) { AcDbObjectId idCurSys = CoreTools::getLyForPipe(isodrcfg.m_sCurrSys); pPoly->setConstantWidth(isodrcfg.m_dPipeW * GetISOScale(isodrcfg.m_sScale)); pPoly->setLayer(idCurSys); pPoly->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pPoly->setNormal(AcGeVector3d::kZAxis); AecDbObjXDataMap *pXDataMap = pReducer->GetSpecialtyData(AcDb::kForWrite); if (pXDataMap != NULL) { pXDataMap->Write(pPoly, BIMDATA_APP); } arIds.append(CoreTools::AddToModelSpace(pPoly)); } } void InsertReducer(CUIISQLiteServer &sqlDb, ads_point pt) { ads_point ptC[2], ptWCS; AcDbObjectId id, idCurSys, idLineType; //在本点选 TCHAR szBuf[256]; struct resbuf eb1; eb1.restype = 0; _tcscpy(szBuf, _T("LWPOLYLINE")); eb1.resval.rstring = szBuf; eb1.rbnext = NULL; ads_name ss, ent; ads_point_set(pt, ptC[0]); ads_point_set(pt, ptC[1]); acdbUcs2Wcs(pt, ptWCS, false); ptC[0][X] -= CoreTools::PixelToWcs(10); ptC[0][Y] -= CoreTools::PixelToWcs(10); ptC[1][X] += CoreTools::PixelToWcs(10); ptC[1][Y] += CoreTools::PixelToWcs(10); int nRes = acedSSGet(_T("C"), ptC[0], ptC[1], &eb1, ss); if (nRes == RTNORM) { Adesk::Int32 lLen = 0; acedSSLength(ss, &lLen); if (lLen == 0) { acutPrintf(_T("\n没有选择到系统管线!")); } acedSSName(ss, 0, ent); acdbGetObjectId(id, ent); acedSSFree(ss); AcDbEntity *pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForWrite)) { ISODrawCfg isodrcfg; memset(&isodrcfg, 0, sizeof(ISODrawCfg)); isodrcfg.m_bVlvISOV = TRUE; _tcscpy(isodrcfg.m_sScale, _T("1:100")); if (AcISOPolyline::ReadISOXData(pEnt, isodrcfg)) { int nPos = -1; AcGePoint3d ptHit, ptPos; AcGeVector3d vtDir(1, 0, 0); AcDbPolyline *pPl = AcDbPolyline::cast(pEnt); if (pPl != NULL) { pPl->getClosestPointTo(asPnt3d(ptWCS), ptHit); ptHit.z = 0.0;//2dplye pPl->getFirstDeriv(asPnt3d(ptWCS), vtDir); vtDir.normalize(); AcGePoint3d ptS, ptE; pPl->getStartPoint(ptS); pPl->getEndPoint(ptE); if (ptS.distanceTo(ptHit) < 1.0) { nPos = 0; vtDir.negate();//to out } if (ptE.distanceTo(ptHit) < 1.0) { nPos = 1; } } AcDbObjectId idCurSys = CoreTools::getLyForPipe(isodrcfg.m_sCurrSys); AcDbObjectId idLineType = KTSetting::InitLineStyle(_T("CONTINUOUS")); //原点2法兰 struct resbuf *result = NULL, *list = NULL, *pTmp; list = acutBuildList(RTSTR, _T("newReducer"), RTREAL, isodrcfg.m_dDn, RTNONE); //调用 nRes = acedInvoke(list, &result); pTmp = result; if (pTmp == NULL) { pEnt->close(); return; } //还原,ptHit,vtDir原始坐标 AecISOCrdWatch watch(TRUE); watch.SetISOMode(isodrcfg.m_nView, isodrcfg.m_nAngle); AcGeVector3d vtX, vtY, vtZ; watch.GetISOCrd(vtX, vtY, vtZ); AecDbEwFitting *pReducer = NULL; if (pTmp->restype == RTINT64 && pTmp->resval.mnInt64 > 0) { pReducer = (AecDbEwFitting *)pTmp->resval.mnInt64; } if (pReducer != NULL) { AcGeVector3d vtX, vtY, vtZ; watch.GetISOCrd(vtX, vtY, vtZ); AcDbObjectIdArray arIds; double dLen = 0; pReducer->GetAt(KEY_Length, dLen); //TEST if (vtDir.isParallelTo(vtZ))//Z { //此处绘制 ptPos = ptHit; MakeISOReducer(pReducer, ptPos, vtX, vtDir,arIds, isodrcfg, nPos); } else if (vtDir.isParallelTo(vtX))//X { if (isodrcfg.m_bVlvISOV) { ptPos = ptHit; MakeISOReducer(pReducer, ptPos, AcGeVector3d::kYAxis, vtDir, arIds, isodrcfg, nPos); } else { //此处绘制 ptPos = ptHit; MakeISOReducer(pReducer, ptPos, vtY, vtDir, arIds, isodrcfg, nPos); } } else if (vtDir.isParallelTo(vtY))//Y { if (isodrcfg.m_bVlvISOV) { ptPos = ptHit; MakeISOReducer(pReducer, ptPos, AcGeVector3d::kYAxis, vtDir, arIds, isodrcfg, nPos); } else { ptPos = ptHit; MakeISOReducer(pReducer, ptPos, vtX, vtDir, arIds, isodrcfg, nPos); } } //如果含法兰,则... if (nPos == -1) { double dEDn = 0.0; pReducer->GetAt(PIPE_EDN, dEDn); BreakPIDPipe(pPl, ptHit, dLen, dEDn); } CKTCadUtility::CreateAcDbGroup(arIds); //TEST //CoreTools::AddToModelSpace(pFlang1); //CoreTools::AddToModelSpace(pFlang2); delete pReducer; } if (list) acutRelRb(list); if (result) acutRelRb(result); } else { //不是iso线 } pEnt->close(); } } } //插入变径 void PL_CRBJCmd() { KTCADSysVar var(_T("OSMODE"), 999); //阀门调用 SHads_command(RTSTR, _T("PL_INVKEQU"), RTNONE); int nRes = 0; ads_point pt, ptBase; CUIISQLiteServer sqlDb; CString dbPath = FilePath::GetSysDir(); dbPath += _T("\\Plumbing.db"); if (!sqlDb.InitADOServer(dbPath)) { AfxMessageBox(_T("数据库驱动加载数据库Plumbing.db失败!")); return; } while (true) { acedInitGet(RSG_NONULL, _T("R")); nRes = acedGetPoint(NULL, _T("\n请选择位置添加变径[参考点(R)]<退出>:"), pt); if (nRes == RTNORM) { InsertReducer(sqlDb, pt); } else if (nRes == RTKWORD) { //参考点<退出>: nRes = acedGetPoint(NULL, _T("\n请选择参考点<退出>:"), ptBase); if (nRes == RTNORM) { nRes = acedGetPoint(ptBase, _T("\n请选择位置添加变径<退出>:"), pt); if (nRes == RTNORM) { InsertReducer(sqlDb, pt); } else { break; } } else { break; } } else if (nRes == RTCAN || nRes == RTNONE) { break; } } } //标注管件 void PL_GZGJCmd() { if (!CoreTools::hasCSSZ(true)) { acedAlert(_T("\n系统没有初始化!请运行初始化命令!")); return; } ads_point pt, pt2; ads_name ent; struct resbuf *pRb = acutBuildList(RTDXF0, DXF_ISOENT, 0); int nRes = 0,nType = 0; AcDbObjectId idDimLay = KTSetting::InitLayer(_T("LAY_PP3D_DIM")); AcDbObjectId idTSty = CKTCadUtility::InitTextStyle(_T("Pipe_Dim")); AcDbObjectId id; AecDbObjXDataMap xDataMap; CAcModuleResourceOverride myResources; CDimTxtDlg dimtxtDlg; ISODrawCfg isodrcfg; AcGeVector3d vtOff; double dOd = 0, dEOd = 0, dThk = 0,dAng = 0; while (true) { nRes = CKTCadUtility::SelectEntity(_T("\n请选择要标注的管件:"), ent, pRb, pt); if (nRes == RTNORM) { acdbGetObjectId(id, ent); if (HasBimDataApp(id, xDataMap, isodrcfg)) { nRes = acedGetPoint(pt, _T("\n请选择位置:"), pt2); if (nRes == RTNORM) { dimtxtDlg.m_sDimTxt = _T(""); xDataMap.GetAt(KEY_NAME, dimtxtDlg.m_sDimTxt); //弹出界面 nType = 0; xDataMap.GetAt(KEY_RUNTIME, nType); vtOff.set(0, 0, 0); xDataMap.GetAt(KEY_OFFSET, vtOff); EFittingType eType = (EFittingType)nType; if (eType == eReduce) { dimtxtDlg.m_sDimTxt = _T("异径管"); if (!vtOff.isZeroLength()) { dimtxtDlg.m_sDimTxt = _T("偏心异径管"); } } if (IDOK == dimtxtDlg.DoModal()) { ads_point pt11, pt22; acdbUcs2Wcs(pt, pt11, false); acdbUcs2Wcs(pt2, pt22, false); AcGePoint3d ptFr = asPnt3d(pt11); AcGePoint3d ptTo = asPnt3d(pt22); AecDbEwPipeDim *pDim = new AecDbEwPipeDim; pDim->AddAecDbWEntity(id); pDim->SetDimStyle(0); pDim->SetDimDir(0); pDim->SetDimTextUporDownFlag(1); pDim->SetTextStyleId(idTSty); pDim->SetTextLayerId(idDimLay); pDim->SetPScale(GetISOScale(dimtxtDlg.m_sScale)); pDim->SetDimTextUporDownFlag(0); CString sDimDwn = _T(""); xDataMap.GetAt(PIPE_OD, dOd); xDataMap.GetAt(PIPE_THICK, dThk); xDataMap.GetAt(PIPE_ELBOWANG, dAng); dAng *= 180 / PI; xDataMap.GetAt(PIPE_EOD, dEOd); xDataMap.GetAt(PIPE_TOD, dEOd); switch (eType) { case eElbow: { sDimDwn.Format(_T("%d度 D%dx%.1f"),(int)(dAng+0.5),(int)(dOd + 0.5), dThk); } break; case eReduceElbow: { sDimDwn.Format(_T("D%dx%d"),(int)(dOd+0.5),(int)(dEOd+0.5)); } break; case eTee: { sDimDwn.Format(_T("D%dx%d"), (int)(dOd + 0.5), (int)(dEOd + 0.5)); } break; case eCross: { sDimDwn.Format(_T("D%dx%d"), (int)(dOd + 0.5), (int)(dEOd + 0.5)); } break; case eWye: { sDimDwn.Format(_T("D%dx%d"), (int)(dOd + 0.5), (int)(dEOd + 0.5)); } break; case eReduce: { sDimDwn.Format(_T("D%dx%d"), (int)(dOd + 0.5), (int)(dEOd + 0.5)); } break; case eLateral: { sDimDwn.Format(_T("D%dx%d"), (int)(dOd + 0.5), (int)(dEOd + 0.5)); } break; case eFlange: case eWcap: case eFlxJoin: case eThrough: //直通 case eUJoin: //活接 case eRJoin: //缩接 case eOJoin: //外螺纹接头 case eIJoin: //内螺纹接头 case eRP: //补强圈 case eHP: //半管接头 case eSPB: //八字盲板 case eGastket: break; default: break; } pDim->AddDimText(dimtxtDlg.m_sDimTxt, sDimDwn); pDim->SetTextHeight(dimtxtDlg.m_dTxtH); pDim->SetTextWidthScale(dimtxtDlg.m_dWScale); pDim->AppendPoint(ptFr); pDim->AppendPoint(ptTo); pDim->SetDimupdownSpace(0.0); pDim->SetTextLayerId(idDimLay); CoreTools::AddToModelSpace(pDim); } } } else { acutPrintf(_T("\n选择的实体没有阀门信息!")); } } else { break; } } acutRelRb(pRb); } //序号标注 void PL_XHBZCmd() { ads_point pt, pt1, pt2, pt22; int nRes = 0; ads_point ptC[2], ptWCS; //在本点选 TCHAR szBuf[256]; struct resbuf eb1; eb1.restype = 0; _tcscpy(szBuf, _T("LWPOLYLINE,LINE")); eb1.resval.rstring = szBuf; eb1.rbnext = NULL; ads_name ss, ent; AcDbObjectId id, idCurSys, idLineType; AcDbObjectId idDimLay = KTSetting::InitLayer(_T("LAY_PP3D_DIM")); AcDbObjectId idTextStyle = CKTCadUtility::InitTextStyle(_T("Pipe_Dim")); CAcModuleResourceOverride myResources; CDimTxtDlg dimtxtDlg; dimtxtDlg.SetElDimtxt(FALSE); AcGePoint3d ptGe[5], ptT; AcGeVector3d vt; while (true) { nRes = acedGetPoint(NULL, _T("\n请选择位置起点:"), pt); if (nRes == RTNORM) { ads_point_set(pt, ptC[0]); ads_point_set(pt, ptC[1]); acdbUcs2Wcs(pt, ptWCS, false); ptC[0][X] -= CoreTools::PixelToWcs(10); ptC[0][Y] -= CoreTools::PixelToWcs(10); ptC[1][X] += CoreTools::PixelToWcs(10); ptC[1][Y] += CoreTools::PixelToWcs(10); nRes = acedSSGet(_T("C"), ptC[0], ptC[1], &eb1, ss); if (nRes == RTNORM) { Adesk::Int32 lLen = 0; acedSSLength(ss, &lLen); if (lLen == 0) { acutPrintf(_T("\n没有选择到系统管线!")); } acedSSName(ss, 0, ent); acdbGetObjectId(id, ent); acedSSFree(ss); AcDbEntity *pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead)) { ISODrawCfg isodrcfg; memset(&isodrcfg, 0, sizeof(ISODrawCfg)); _tcscpy(isodrcfg.m_sScale, _T("1:100")); AcDbObjectId idLineType = KTSetting::InitLineStyle(_T("CONTINUOUS")); if (AcISOPolyline::ReadISOXData(pEnt, isodrcfg)) { } nRes = acedGetPoint(pt, _T("\n请选择序号位置点:"), pt2); if (nRes == RTNORM) { if (IDOK == dimtxtDlg.DoModal()) { acdbUcs2Wcs(pt2, pt22, false); AcDbText *pText = new AcDbText; ptT = asPnt3d(pt22); ptT += 0.5 * GetISOScale(isodrcfg.m_sScale) * AcGeVector3d::kXAxis; pText->setPosition(ptT); pText->setRotation(0.0); pText->setHeight(dimtxtDlg.m_dTxtH * GetISOScale(isodrcfg.m_sScale)); pText->setWidthFactor(0.75); pText->setNormal(AcGeVector3d::kZAxis); pText->setHorizontalMode(AcDb::kTextLeft); pText->setVerticalMode(AcDb::kTextBottom); pText->setAlignmentPoint(ptT); pText->setTextString(dimtxtDlg.m_sDimTxt); pText->setTextStyle(idTextStyle); pText->setLayer(idDimLay); CoreTools::AddToModelSpace(pText); AcGiTextStyle giTxtStyle; fromAcDbTextStyle(giTxtStyle, idTextStyle); giTxtStyle.setTextSize(dimtxtDlg.m_dTxtH * GetISOScale(isodrcfg.m_sScale)); giTxtStyle.setXScale(0.75); int nLen = dimtxtDlg.m_sDimTxt.GetLength(); AcGePoint2d pt2d = giTxtStyle.extents(dimtxtDlg.m_sDimTxt, Adesk::kFalse, nLen, Adesk::kTrue); ptGe[0] = asPnt3d(pt22); ptGe[0].y -= 1.0 * GetISOScale(isodrcfg.m_sScale); ptGe[1] = ptGe[0] + (pt2d.x + 1.0 * GetISOScale(isodrcfg.m_sScale)) * AcGeVector3d::kXAxis; ptGe[2] = ptGe[1] + (pt2d.y + 2.0 * GetISOScale(isodrcfg.m_sScale)) * AcGeVector3d::kYAxis; ptGe[3] = ptGe[0] + (pt2d.y + 2.0 * GetISOScale(isodrcfg.m_sScale)) * AcGeVector3d::kYAxis; ptGe[4] = ptGe[0]; AcDbPolyline *pPl = FormatPolyline(ptGe, 5); pPl->setLayer(idDimLay); CoreTools::AddToModelSpace(pPl); acdbUcs2Wcs(pt, pt1, false); ptT = ptGe[0]; ptGe[0] = asPnt3d(pt1); vt = ptT - ptGe[0]; vt.normalize(); if (vt.x < 0 && vt.y > 0) ptT = ptGe[1]; else if (vt.x < 0 && vt.y < 0) ptT = ptGe[2]; else if (vt.x > 0 && vt.y < 0) ptT = ptGe[3]; ptGe[1] = ptGe[0] + 2.53 * GetISOScale(isodrcfg.m_sScale) * vt; ptGe[2] = ptT; pPl = FormatPolyline(ptGe, 3); pPl->setWidthsAt(0, 0, 0.83 * GetISOScale(isodrcfg.m_sScale)); pPl->setWidthsAt(1, 0,0); pPl->setWidthsAt(2, 0, 0); pPl->setLayer(idDimLay); CoreTools::AddToModelSpace(pPl); } } pEnt->close(); } } } else { break; } } } void MakeISOPipeHanger(CString& sName,const AcGePoint3d& ptPos, const AcGeVector3d& vtDir, const AcGeVector3d& vtV,AcDbObjectIdArray& arIds, const ISODrawCfg& isodrcfg) { double dWD = 3.0 * GetISOScale(isodrcfg.m_sScale);//默认长度 AcGePoint3d ptGe[6]; ptGe[0] = ptPos + vtDir * dWD * 0.5; ptGe[1] = ptPos - vtDir * dWD * 0.5; AcGeVector3d vt12 = ptGe[1] - ptGe[0]; vt12.normalize(); AcDbObjectId idCurSys = CoreTools::getLyForPipe(isodrcfg.m_sCurrSys); AcDbPolyline *pPoly = new AcDbPolyline; pPoly->addVertexAt(0, ptGe[0].convert2d(AcGePlane::kXYPlane)); pPoly->addVertexAt(1, ptGe[1].convert2d(AcGePlane::kXYPlane)); pPoly->setConstantWidth(0); pPoly->setLayer(idCurSys); pPoly->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pPoly->setNormal(AcGeVector3d::kZAxis); pPoly->setColorIndex(2); AecDbObjXDataMap xData; xData.SetAt(KEY_NAME, sName); xData.Write(pPoly, BIMDATA_APP); arIds.append(CoreTools::AddToModelSpace(pPoly)); //X AcGeVector3d vt1 = vtDir; vt1.rotateBy(PI / 3.0, AcGeVector3d::kZAxis); AcGeVector3d vt2 = vtDir; vt2.rotateBy(-PI / 3.0, AcGeVector3d::kZAxis); ptGe[0] += vt12 * 0.15 * GetISOScale(isodrcfg.m_sScale); ptGe[2] = ptGe[0] - vt1 * 0.15 * GetISOScale(isodrcfg.m_sScale); ptGe[3] = ptGe[0] + vt1 * 0.15 * GetISOScale(isodrcfg.m_sScale); pPoly = new AcDbPolyline; pPoly->addVertexAt(0, ptGe[2].convert2d(AcGePlane::kXYPlane)); pPoly->addVertexAt(1, ptGe[3].convert2d(AcGePlane::kXYPlane)); pPoly->setConstantWidth(0); pPoly->setLayer(idCurSys); pPoly->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pPoly->setNormal(AcGeVector3d::kZAxis); pPoly->setColorIndex(2); xData.Write(pPoly, BIMDATA_APP); arIds.append(CoreTools::AddToModelSpace(pPoly)); ptGe[2] = ptGe[0] - vt2 * 0.15 * GetISOScale(isodrcfg.m_sScale); ptGe[3] = ptGe[0] + vt2 * 0.15 * GetISOScale(isodrcfg.m_sScale); pPoly = new AcDbPolyline; pPoly->addVertexAt(0, ptGe[2].convert2d(AcGePlane::kXYPlane)); pPoly->addVertexAt(1, ptGe[3].convert2d(AcGePlane::kXYPlane)); pPoly->setConstantWidth(0); pPoly->setLayer(idCurSys); pPoly->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pPoly->setNormal(AcGeVector3d::kZAxis); pPoly->setColorIndex(2); xData.Write(pPoly, BIMDATA_APP); arIds.append(CoreTools::AddToModelSpace(pPoly)); ptGe[1] -= vt12 * 0.15 * GetISOScale(isodrcfg.m_sScale); ptGe[2] = ptGe[1] - vt1 * 0.15 * GetISOScale(isodrcfg.m_sScale); ptGe[3] = ptGe[1] + vt1 * 0.15 * GetISOScale(isodrcfg.m_sScale); pPoly = new AcDbPolyline; pPoly->addVertexAt(0, ptGe[2].convert2d(AcGePlane::kXYPlane)); pPoly->addVertexAt(1, ptGe[3].convert2d(AcGePlane::kXYPlane)); pPoly->setConstantWidth(0); pPoly->setLayer(idCurSys); pPoly->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pPoly->setNormal(AcGeVector3d::kZAxis); pPoly->setColorIndex(2); xData.Write(pPoly, BIMDATA_APP); arIds.append(CoreTools::AddToModelSpace(pPoly)); ptGe[2] = ptGe[1] - vt2 * 0.15 * GetISOScale(isodrcfg.m_sScale); ptGe[3] = ptGe[1] + vt2 * 0.15 * GetISOScale(isodrcfg.m_sScale); pPoly = new AcDbPolyline; pPoly->addVertexAt(0, ptGe[2].convert2d(AcGePlane::kXYPlane)); pPoly->addVertexAt(1, ptGe[3].convert2d(AcGePlane::kXYPlane)); pPoly->setConstantWidth(0); pPoly->setLayer(idCurSys); pPoly->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pPoly->setNormal(AcGeVector3d::kZAxis); xData.Write(pPoly, BIMDATA_APP); arIds.append(CoreTools::AddToModelSpace(pPoly)); } //布支吊架 void PL_BZDJCmd() { if (!CoreTools::hasCSSZ(true)) { acedAlert(_T("\n系统没有初始化!请运行初始化命令!")); return; } //在本点选 TCHAR szBuf[256]; struct resbuf eb1; eb1.restype = 0; _tcscpy(szBuf, _T("LWPOLYLINE,LINE")); eb1.resval.rstring = szBuf; eb1.rbnext = NULL; ads_name ss, ent; ads_point pt1, pt2, pt3, ptm; ads_point pt11, pt22, pt33, ptC[2], ptWCS; AcGePoint3d ptOn, ptHit, ptPos; AcGeVector3d vt,vtDir; int nRes = 0, nRes2 = 0, nCount = 0; double dDist = 0, dAng = 0; CString sDimTxt; AcDbObjectId idDimLay = KTSetting::InitLayer(_T("LAY_PP3D_DIM")); AcDbObjectId idDimStyle = KTSetting::InitDimStyle(_T("GL_DIM")); AcDbObjectId idTextStyle = CKTCadUtility::InitTextStyle(_T("Pipe_Dim")); AcDbObjectId id; AcDbObjectIdArray arIds; CAcModuleResourceOverride myResources; CDimTxtDlg dimtxtDlg; ISODrawCfg isodrcfg; memset(&isodrcfg, 0, sizeof(ISODrawCfg)); isodrcfg.m_bVlvISOV = TRUE; dimtxtDlg.SetElDimtxt(FALSE); AcGeVector3d vtX, vtY, vtZ; while (true) { nRes = acedGetPoint(NULL, _T("\n选择起点:"), pt1); if (nRes == RTNORM) { //获取isodrcfg ads_point_set(pt1, ptC[0]); ads_point_set(pt1, ptC[1]); ptC[0][X] -= CoreTools::PixelToWcs(10); ptC[0][Y] -= CoreTools::PixelToWcs(10); ptC[1][X] += CoreTools::PixelToWcs(10); ptC[1][Y] += CoreTools::PixelToWcs(10); nRes2 = acedSSGet(_T("C"), ptC[0], ptC[1], &eb1, ss); if (nRes2 == RTNORM) { Adesk::Int32 lLen = 0; acedSSLength(ss, &lLen); if (lLen >= 0) { acedSSName(ss, 0, ent); acdbGetObjectId(id, ent); acedSSFree(ss); AcDbEntity *pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead)) { _tcscpy(isodrcfg.m_sScale, _T("1:100")); if (AcISOPolyline::ReadISOXData(pEnt, isodrcfg)) { //还原,ptHit,vtDir原始坐标 AecISOCrdWatch watch(TRUE); watch.SetISOMode(isodrcfg.m_nView, isodrcfg.m_nAngle); watch.GetISOCrd(vtX, vtY, vtZ); AcDbPolyline *pPl = AcDbPolyline::cast(pEnt); if (pPl != NULL) { acdbUcs2Wcs(pt1, ptWCS, false); pPl->getClosestPointTo(asPnt3d(ptWCS), ptHit); ptHit.z = 0.0;//2dplye pPl->getFirstDeriv(asPnt3d(ptWCS), vtDir); vtDir.normalize(); } } pEnt->close(); } } } nRes = acedGetPoint(pt1, _T("\n选择终点:"), pt2); if (nRes == RTNORM) { //弹出界面,名称 dimtxtDlg.m_sDimTxt = _T("管道固定支架 "); if (IDOK == dimtxtDlg.DoModal()) { nRes = acedGetPoint(pt1, _T("\n选择布置间隙:"), pt3); if (nRes == RTNORM) { dDist = acutDistance(pt1, pt3); nCount = (int)(acutDistance(pt1, pt2) / dDist + 0.5); acdbUcs2Wcs(pt1, ptWCS, false); acdbUcs2Wcs(pt2, pt22, false); vt = asPnt3d(pt22) - asPnt3d(ptWCS); vt.normalize(); for (int n = 0;n < nCount-1;n++) { ptPos = asPnt3d(ptWCS) + (n + 1) * dDist * vt; arIds.removeAll(); //TEST if (vtDir.isParallelTo(vtZ))//Z { //此处绘制 MakeISOPipeHanger(dimtxtDlg.m_sDimTxt,ptPos, vtX,AcGeVector3d::kXAxis,arIds, isodrcfg); } else if (vtDir.isParallelTo(vtX))//X { MakeISOPipeHanger(dimtxtDlg.m_sDimTxt,ptPos, vtY, vtX,arIds, isodrcfg); } else if (vtDir.isParallelTo(vtY))//Y { MakeISOPipeHanger(dimtxtDlg.m_sDimTxt,ptPos, vtX, vtY,arIds, isodrcfg); } CKTCadUtility::CreateAcDbGroup(arIds); } } } } else { break; } } else { break; } } } void PL_LXJTCmd() { ads_point pt; int nRes = acedGetPoint(NULL, _T("\n请选择位置添加流向箭头<退出>:"), pt); if (nRes == RTNORM) { ads_point ptC[2], ptWCS; AcDbObjectId id, idCurSys, idLineType; //在本点选 TCHAR szBuf[256]; struct resbuf eb1; eb1.restype = 0; _tcscpy(szBuf, _T("LWPOLYLINE")); eb1.resval.rstring = szBuf; eb1.rbnext = NULL; ads_name ss, ent; ads_point_set(pt, ptC[0]); ads_point_set(pt, ptC[1]); acdbUcs2Wcs(pt, ptWCS, false); ptC[0][X] -= CoreTools::PixelToWcs(10); ptC[0][Y] -= CoreTools::PixelToWcs(10); ptC[1][X] += CoreTools::PixelToWcs(10); ptC[1][Y] += CoreTools::PixelToWcs(10); int nRes = acedSSGet(_T("C"), ptC[0], ptC[1], &eb1, ss); if (nRes == RTNORM) { Adesk::Int32 lLen = 0; acedSSLength(ss, &lLen); if (lLen == 0) { acutPrintf(_T("\n没有选择到系统管线!")); } ads_point pt2; nRes = acedGetPoint(pt, _T("\n请选择箭头流向<退出>:"), pt2); if (nRes == RTNORM) { acedSSName(ss, 0, ent); acdbGetObjectId(id, ent); acedSSFree(ss); AcDbEntity *pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForWrite)) { ISODrawCfg isodrcfg; memset(&isodrcfg, 0, sizeof(ISODrawCfg)); isodrcfg.m_bVlvISOV = TRUE; _tcscpy(isodrcfg.m_sScale, _T("1:100")); if (AcISOPolyline::ReadISOXData(pEnt, isodrcfg)) { acdbUcs2Wcs(pt, ptC[0], false); acdbUcs2Wcs(pt2,ptC[1], false); AcGeVector3d vt = asPnt3d(ptC[1]) - asPnt3d(ptC[0]); vt.normalize(); double dLen = GetISOScale(isodrcfg.m_sScale) * 2.0 * isodrcfg.m_dPipeW * tan(76.0 * PI / 180.0); double dStW = GetISOScale(isodrcfg.m_sScale) * 4.0 * isodrcfg.m_dPipeW; AcGePoint3d ptG2 = asPnt3d(ptC[0]) + dLen * vt; AcDbPolyline *pPl = new AcDbPolyline; pPl->setLayer(pEnt->layerId()); pPl->setLinetype(KTSetting::InitLineStyle(_T("Continuous"))); pPl->addVertexAt(0, asPnt3d(ptC[0]).convert2d(AcGePlane::kXYPlane), 0, dStW,0); pPl->addVertexAt(1, ptG2.convert2d(AcGePlane::kXYPlane), 0, 0,0); CoreTools::AddToModelSpace(pPl); AcDbPolyline *pPlISO = AcDbPolyline::cast(pEnt); if (pPlISO != NULL) { AcGePoint3d ptMid; Midpoint(ptC[0], ptG2, ptMid); BreakPIDPipe(pPlISO, ptMid, dLen); } } pEnt->close(); } } } } }