#include "StdAfx.h" #include "FloorHoleOperation.h" #include "FloorHoleDlg.h" #include "dbxutil.h" #include "TFloorHoleLabelEdJig.h" #include "dbray.h" #include "DbEquipment.h" void InsFloorHole() { CTemporaryResourceOverride vTemp; //打开楼板洞设置对话框 CFloorHoleDlg floorHoleDlg(0,acedGetAcadFrame()); floorHoleDlg.Create(IDD_FLOOR_BASE); floorHoleDlg.ShowWindow(SW_SHOW); CFloorHoleOperation floorHoleOperation; while (TRUE) { RBList rbMask = ads_buildlist(RTDXF0, _T("LINE"), NULL); Entity entBaseLine1 , entBaseLine2, entWall; XPoint ptBaseLine1, ptBaseLine2; int nDist1 = 0, nDist2 = 0; int dRet = SelectEntity1(_T("\n请选择基准线<自由布置>:"), entBaseLine1,ptBaseLine1,rbMask); acdbUcs2Wcs(ptBaseLine1,ptBaseLine1,false); ptBaseLine1 = asPnt3d(ptBaseLine1); ads_point ptPick; AcGePoint3d ptPick3d; if ( dRet == RTNORM) { if (acedGetInt(_T("\n请输入楼板洞距基准线距离<退出>:"), &nDist1) != RTNORM) { continue; } if (SelectEntity1(_T("\n请选择基准线:"), entBaseLine2,ptBaseLine2,rbMask) != RTNORM) { continue; } acdbUcs2Wcs(ptBaseLine2,ptBaseLine2,false); ptBaseLine2 = asPnt3d(ptBaseLine2); if (acedGetInt(_T("\n请输入楼板洞距基准线距离<退出>:"), &nDist2) != RTNORM) { continue; } if (floorHoleOperation.CalcInsertPoint(floorHoleDlg, entBaseLine1, nDist1, entBaseLine2, nDist2, ptBaseLine1, ptBaseLine2)) { floorHoleOperation.AddHole(floorHoleDlg, floorHoleOperation.m_ptInsert); floorHoleOperation.AddLabel(floorHoleDlg, floorHoleOperation.m_ptInsert); floorHoleOperation.AddDimLabel(floorHoleDlg, floorHoleOperation.m_ptBaseLine2, floorHoleOperation.m_ptInsert); floorHoleOperation.AddDimLabel(floorHoleDlg, floorHoleOperation.m_ptBaseLine1, floorHoleOperation.m_ptInsert); } else { continue; } } else if (dRet == RTNONE) { if(acedGetPoint(NULL,_T("\n请楼板洞插入位置<退出>"), ptPick) != RTNORM) break; ptPick3d = asPnt3d(ptPick); ptPick3d = Ucs2Wcs(ptPick3d); floorHoleOperation.AddHole(floorHoleDlg, ptPick3d); floorHoleOperation.AddLabel(floorHoleDlg, ptPick3d); } else { break; } } if (!floorHoleDlg.IsDestroy()) { floorHoleDlg.DestroyWindow(); } } void MoveFlooorHole() { CFloorHoleOperation floorHoleOperation; floorHoleOperation.MoveFloorHole(); } CFloorHoleOperation::CFloorHoleOperation() { m_dLen1 = 0.0; m_dLen2 = 0.0; m_dRotation = Ucs2Wcs(0.0); } CFloorHoleOperation::~CFloorHoleOperation() { } BOOL CFloorHoleOperation::AddHole(CFloorHoleDlg &floorHoleDlg, AcGePoint3d ptIns) { AcDbObjectId id2d = NULL; CString sBlkName; AcGeScale3d scale; if (floorHoleDlg.m_nType == 0) { sBlkName = floorHoleDlg.m_wndArcHoleDlg.m_strInsBlkName; scale.set(floorHoleDlg.getRadius() * 2, floorHoleDlg.getRadius() * 2, floorHoleDlg.getRadius() * 2); } else { sBlkName = floorHoleDlg.m_wndRectHoleDlg.m_strInsBlkName; CString strW, strH; floorHoleDlg.m_wndRectHoleDlg.m_cmbW.GetWindowText(strW); floorHoleDlg.m_wndRectHoleDlg.m_cmbH.GetWindowText(strH); scale.set(_tstof(strW), _tstof(strH), 1); } id2d = GetBlkIdByName(sBlkName); if (!id2d.isValid()) { return FALSE; } AcDbBlockReference *pRef = new AcDbBlockReference(ptIns, id2d); // AcGeScale3d scale(floorHoleDlg.getRadius() * 2); pRef->setScaleFactors(scale); pRef->setRotation(m_dRotation); pRef->setLayer(InitLayer(LAY_TWT_HOLE)); AcDbObjectId idRef = AddToCurrentSpace(pRef, Adesk::kTrue); // ZXL 2013.07.10 ADD 添加扩展数据 ads_name ent; acdbGetAdsName(ent, idRef); CString sSpecType; if (floorHoleDlg.m_nType == 0) { floorHoleDlg.m_wndArcHoleDlg.m_cmbDiameter.GetWindowText(sSpecType); sSpecType = _T("%%c") + sSpecType; } else { CString strW, strH; floorHoleDlg.m_wndRectHoleDlg.m_cmbW.GetWindowText(strW); floorHoleDlg.m_wndRectHoleDlg.m_cmbH.GetWindowText(strH); sSpecType = strW + _T("×") + strH; } WriteXdata(ent, _T("SpecType"), sSpecType); acedUpdateDisplay(); actrTransactionManager->flushGraphics(); return TRUE; } BOOL CFloorHoleOperation::AddLabel(CFloorHoleDlg &floorHoleDlg, AcGePoint3d ptStart) { TDbSymbMultiLeader *pLeader = new TDbSymbMultiLeader; if (pLeader != NULL) { CString strSuperscript, strSubscript; if (floorHoleDlg.m_nType == 0) { strSuperscript = floorHoleDlg.getSuperscript(); strSubscript = floorHoleDlg.getSubscript(); } else { floorHoleDlg.m_wndRectHoleDlg.m_cmbSuperscript.GetWindowText(strSuperscript); floorHoleDlg.m_wndRectHoleDlg.m_edtSubscript.GetWindowText(strSubscript); } XPointList lstVertexes; lstVertexes.Append(new XPoint(ptStart)); pLeader->SetLeaderVertexes(lstVertexes); pLeader->SetLeaderPoint(ptStart); pLeader->SetLayoutRotation(Ucs2Wcs(0.0)); pLeader->SetArrow(TDbSymbMultiLeader::kNone); pLeader->SetTextAlign(TDbSymbMultiLeader::kAtMiddle); AcDbObjectId idTextStyle = InitTwtTextStyle(g_csTwtDimStyle); pLeader->SetTextStyleId(idTextStyle); pLeader->SetTextLayerId(InitLayer(LAY_TEXT)); pLeader->SetTextHeight(g_nVPipeHeight); pLeader->SetText1(strSuperscript); pLeader->SetText2(strSubscript); pLeader->SetTextBaseLen(pLeader->GetDefaultTextBaseLen() + 1); TFloorHoleLabelEdJig jig(pLeader); jig.SetDlgPtr(&floorHoleDlg); jig.SetOperCode(TLeaderEdJig::kLeader); jig.SetPrompt(_T("\n输入引线位置<退出>: ")); if(jig.DoIt()==RTNORM) { XPoint ptPick2 = pLeader->GetLeaderPoint(); lstVertexes.Reset(); lstVertexes.Append(new XPoint(ptStart)); pLeader->SetLeaderVertexes(lstVertexes); pLeader->AddToCSpace(Adesk::kFalse); pLeader->setLayer(LAY_VPIPE_DIM); pLeader->close(); } else { delete pLeader; return Adesk::kFalse; } } return Adesk::kTrue; } BOOL CFloorHoleOperation::CalcInsertPoint(CFloorHoleDlg &floorHoleDlg, Entity entBaseLine1, double nDist1, Entity entBaseLine2, double nDist2, XPoint ptBaseLine1, XPoint ptBaseLine2) { AcDbLine line1; AcDbObjectId idLine1 = AcDbObjectId::kNull; acdbGetObjectId(idLine1, entBaseLine1); if (idLine1.isNull()) { return FALSE; } AcDbLine *pLine1 = NULL; acdbOpenObject(pLine1, idLine1, AcDb::kForRead); if (pLine1 != NULL) { line1.setStartPoint(pLine1->startPoint()); line1.setEndPoint(pLine1->endPoint()); pLine1->close(); } else { return FALSE; } AcDbLine line2; AcDbObjectId idLine2 = AcDbObjectId::kNull; acdbGetObjectId(idLine2, entBaseLine2); if (idLine2.isNull()) { return FALSE; } AcDbLine *pLine2 = NULL; acdbOpenObject(pLine2, idLine2, AcDb::kForRead); if (pLine2 != NULL) { line2.setStartPoint(pLine2->startPoint()); line2.setEndPoint(pLine2->endPoint()); pLine2->close(); } else { return FALSE; } AcGePoint3dArray arPt; line1.intersectWith(&line2, AcDb::kExtendBoth, arPt); double dAng1 = 0.0, dAng2 = 0.0; if (arPt.length() == 1) { AcGeVector3d vtr1 = ptBaseLine1 - arPt[0]; AcGeVector3d vtr2 = ptBaseLine2 - arPt[0]; vtr1.normalize(); vtr2.normalize(); // zxl 2013.07.09 add dAng1 = vtr1.angleTo(AcGeVector3d::kXAxis, AcGeVector3d::kZAxis); if (dAng1 >= PI) { dAng1 = fabs(dAng1 - PI * 2); } if (dAng1 > PI / 2) { dAng1 = fabs(dAng1 - PI); } dAng2 = vtr2.angleTo(AcGeVector3d::kXAxis, AcGeVector3d::kZAxis); if (dAng2 >= PI) { dAng2 = fabs(dAng2 - PI * 2); } if (dAng2 > PI / 2) { dAng2 = fabs(dAng2 - PI); } double dAng = vtr1.angleTo(vtr2, AcGeVector3d::kZAxis); if (dAng >= PI) { dAng = fabs(dAng - PI * 2); } if (dAng > PI / 2) { dAng = fabs(dAng - PI); } if (floorHoleDlg.m_nType == 1 && fabs(fabs(dAng) - PI / 2) > 0.001) { acedPrompt(_T("\n两根基线没有正交,请重新选择!")); return FALSE; } if (floorHoleDlg.m_nType == 1) { CString strW, strH; floorHoleDlg.m_wndRectHoleDlg.m_cmbW.GetWindowText(strW); floorHoleDlg.m_wndRectHoleDlg.m_cmbH.GetWindowText(strH); if (dAng2 - dAng1 > 0.001) { nDist2 += _tstof(strW) / 2; nDist1 += _tstof(strH) / 2; m_dLen1 = _tstof(strH) / 2; m_dLen2 = _tstof(strW) / 2; } else if (dAng1 - dAng2 > 0.001) { nDist2 += _tstof(strH) / 2; nDist1 += _tstof(strW) / 2; m_dLen1 = _tstof(strW) / 2; m_dLen2 = _tstof(strH) / 2; } else if (fabs(dAng2 - dAng1) < 0.001) { if ((vtr1[0] > 0 && vtr1[1] < 0) || (vtr1[0] < 0 && vtr1[1] > 0)) { nDist2 += _tstof(strW) / 2; nDist1 += _tstof(strH) / 2; m_dLen1 = _tstof(strH) / 2; m_dLen2 = _tstof(strW) / 2; } else { nDist2 += _tstof(strH) / 2; nDist1 += _tstof(strW) / 2; m_dLen1 = _tstof(strW) / 2; m_dLen2 = _tstof(strH) / 2; } } } vtr1 = vtr1 * nDist2; vtr2 = vtr2 * nDist1; m_ptInsert = vtr1 + vtr2 + arPt[0]; } else { return FALSE; } acdbOpenObject(pLine1, idLine1, AcDb::kForRead); acdbOpenObject(pLine2, idLine2, AcDb::kForRead); AcGePoint3d ptLine1, ptLine2; if (pLine1 != NULL && pLine2 != NULL) { pLine2->getClosestPointTo(m_ptInsert, ptLine2); m_ptBaseLine2 = ptLine2; pLine1->getClosestPointTo(m_ptInsert, ptLine1); m_ptBaseLine1 = ptLine1; if (floorHoleDlg.m_nType == 1) { XPoint ptLoc = m_ptInsert, ptBase; if (dAng2 - dAng1 > 0.001) { ptBase = m_ptBaseLine2; } else if (dAng1 - dAng2 > 0.001) { ptBase = m_ptBaseLine1; } m_dRotation = ads_angle(ptLoc, ptBase); if (fabs(dAng2 - dAng1) < 0.001) { m_dRotation = - PI / 4; } } pLine1->close(); pLine2->close(); } else { if (pLine1 != NULL) { pLine1->close(); } if (pLine2 != NULL) { pLine2->close(); } return FALSE; } return TRUE; } void CFloorHoleOperation::AddDimLabel(CFloorHoleDlg &floorHoleDlg, XPoint ptStart, XPoint ptEnd) { XPoint ptLst; if (floorHoleDlg.m_nType == 1) { AcGeVector3d vt = ptEnd - ptStart; vt.normalize(); double dLen = 0.0; if (ptStart.Distance2d(m_ptBaseLine1) < 0.001) { dLen = m_dLen1; } else { dLen = m_dLen2; } ptEnd = ptEnd - vt * dLen; ptLst = ptEnd + vt * dLen * 2; } double m_dScale = 2.0; TDbDimension2* pDim = new TDbDimension2; pDim->setLayer(InitLayer(LAY_DIM)); pDim->SetPScale(g_nVPipeHeight*20); pDim->SetLocation(ptStart); pDim->SetStyleId(InitDimStyle(DS_LINEAR)); pDim->SetRotation(ads_angle(ptEnd, ptStart)); pDim->SetLayoutRotation(Ucs2Wcs(0.0)); CString sLabel; pDim->AddSegment(ptStart); pDim->AddSegment(ptEnd); if (floorHoleDlg.m_nType == 1) { pDim->AddSegment(ptLst); } double dDist2DimLine = 0.0; pDim->SetDist2DimLine(dDist2DimLine, FALSE); TDimensionEdJig jig(pDim, _T("\n请点取尺寸线位置<退出>:")); jig.m_nFlag=1; if(jig.doIt() != RTNORM){ delete pDim; return; } dDist2DimLine = pDim->GetDist2DimLine(FALSE); AddToModelSpace(pDim, Adesk::kTrue); } void CFloorHoleOperation::MoveFloorHole() { g_ssPickFirst.Free(); XPushVar vOrthoMode(_T("ORTHOMODE"), 1); //f8 RBList rbMask(RTDXF0, _T("INSERT"), 8, LAY_TWT_HOLE, NULL); PickSet ss(SS_FREE); if(SelectEntities(_T("\n请选择需要移动的设备<退出>"), ss, rbMask) != RTNORM) { return; } XPoint ptIns, ptTemp; double x,y,z; XPointList lstPT; ss.GetExtend(ptIns, &x, &y, &z); AcDbBlockReference *pRef = NULL; AcDbObjectId idEnt = AcDbObjectId::kNull; XPoint ptLoc; for(long i = 0; i < ss.Length(); i++) { Entity ent = ss[i]; acdbGetObjectId(idEnt, ent); if (idEnt.isValid()) { acdbOpenObject(pRef, idEnt, AcDb::kForRead); if (pRef != NULL) { ptLoc = pRef->position(); lstPT.NewAppend(ptLoc); pRef->close(); } } } XPoint ptUcs = Wcs2Ucs(ptIns); ptUcs.z = 0; int nRet = DragPickSet1(ss, ptUcs); if(nRet != RTNORM) return; for(i = 0; i < ss.Length(); i++) { Entity ent = ss[i]; acdbGetObjectId(idEnt, ent); if (!idEnt.isValid()) { continue; } acdbOpenObject(pRef, idEnt, AcDb::kForRead); if (pRef != NULL) { ptLoc = pRef->position(); PickSet ssDim(SS_FREE); RBList rbMaskDim(RTDXF0, _T("ATS_DIMENSION2"), NULL); XPoint ptOldLoc = *lstPT[i]; if(fabs(ptLoc.z - ptOldLoc.z) > 0.01) { ptLoc.z = ptOldLoc.z; } pRef->close(); ptOldLoc.z = 0; GetPointPickSet(ptOldLoc, ssDim, rbMaskDim, 650); long lenDim = ssDim.Length(); for(long i = 0; i < lenDim; i++) { Entity entDim = ssDim[i]; OPENOBJ_BEGIN(entDim, AcDb::kForWrite, TDbDimension2, pDim); if(pDim) { AcGeVector3d vectTmp = ptLoc - ptOldLoc; AcGePoint3dArray gripPoints; AcDbIntArray osnapModes; AcDbIntArray geomIds; pDim->getGripPoints(gripPoints,osnapModes,geomIds); int ptlen = gripPoints.length(); double dDist = pDim->GetDist2DimLine(FALSE); int nIndex; int n = 0; for (n = 0; n < ptlen; n++) { XPoint pti = gripPoints[n]; double dDistTemp = ptOldLoc.Distance(pti); if (fabs(fabs(dDist) - dDistTemp) < 1E-3) { nIndex = n; break; } } for (n = 0; n < ptlen; n++) { XPoint pti = gripPoints[n]; if(pti == ptOldLoc) { AcDbIntArray indices; indices.append(n); pDim->moveGripPointsAt(indices, vectTmp); indices.setLogicalLength(0); indices.append(nIndex); pDim->moveGripPointsAt(indices, vectTmp); break; } } } OPENOBJ_END(); } RBList rbMaskLabel(RTDXF0, _T("ATS_MULTILEADER"), NULL); ptOldLoc.z = 0; GetPointPickSet(ptOldLoc, ssDim, rbMaskLabel, 650); long lenLabel = ssDim.Length(); if (lenLabel == 1) { Entity entDim = ssDim[0L]; OPENOBJ_BEGIN(entDim, AcDb::kForWrite, TDbSymbMultiLeader, pLeader); if(pLeader) { AcGeVector3d vectTmp(ptLoc.x - ptOldLoc.x, ptLoc.y - ptOldLoc.y, 0); AcGeMatrix3d mat; mat.setToTranslation(vectTmp); pLeader->transformBy(mat); } OPENOBJ_END(); } } } }