#include "stdafx.h" #include "resource.h" #include "DormerDlg.h" /* int SelectUpFace(AcGePlane &plane) { Entity ent; XPoint pt; if (ent.FilterSelect1(GetApertureWcs(), _T("\n请选择三维坡屋顶坡面<退出>:"), RBList(), pt)!=RTNORM) return RTERROR; BOOL bUp=TRUE; if (ent.Is(_T("3DFACE")) || ent.Is(_T("POLYLINE"))) bUp=FALSE; pt=Ucs2Wcs(pt); AcDbVoidPtrArray entSet; int nDrawMode=DocGetDrawMode(); DocSetDrawMode(DRAW_3D); OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbEntity, pEnt); InitModel(TMasterProperties(), pEnt, NULL, entSet); OPENOBJ_END(); DocSetDrawMode(nDrawMode); int num=entSet.length(); for(int i=0; iisA()==AcDbFace::desc()) { AcDbFace *pFace=AcDbFace::cast(pEnt); int nHitFlag=HitTestOnEdge(pFace, pt, TRUE); if (nHitFlag>=0) { X3DFace faceUcs, faceWcs; for(int n=0; n<4; n++) { pFace->getVertexAt(n, faceWcs.GetVertex(n)); } XVector3D vtNorm=faceWcs.GetNormal(); if (vtNorm.z<1.0E-9 && bUp) continue; //法向不正确 for(n=0; n<4; n++) faceUcs.GetVertex(n)=Wcs2Ucs(faceWcs.GetVertex(n)); if (faceUcs.IsLinear() || faceUcs.IsPoint()) continue; XScreenDc dc(7, 1); dc << faceUcs; int nCode=YesNoQuestion(_T("\n是否为加亮的坡面")); ads_redraw(NULL,0); if (nCode==RTCAN) return nCode; else if (nCode==Q_YES) { if (vtNorm.z<1.0E-9) plane.set((AcGePoint3d &)faceWcs.GetVertex(2), (AcGePoint3d &)faceWcs.GetVertex(1), (AcGePoint3d &)faceWcs.GetVertex(0)); else plane.set((AcGePoint3d &)faceWcs.GetVertex(0), (AcGePoint3d &)faceWcs.GetVertex(1), (AcGePoint3d &)faceWcs.GetVertex(2)); return RTNORM; } } } } ReleaseEntSet(entSet); ads_retnil(); return RTNONE; }*/ class TDbDormerJig: public AcEdJig { public: TDbDormerJig(TDbDormer *m_pDrawEnt,PickSet *ss,CDormerDlg *dlg); ~TDbDormerJig(); virtual DragStatus sampler(); virtual Adesk::Boolean update(); virtual AcDbEntity* entity() const; void SetPrompt(const TCHAR *m_pTemp); int GetRetCode() const; int doIt(); void CalcLabelForDlg(); int m_nRetCode; //返回码 const TCHAR *m_pszPrompt; //提示信息 const TCHAR *m_pszKeyword; //关键字 AcDbVoidPtrArray entSet; AcGePoint3d m_point; AcGePoint3d m_PrePoint; BOOL m_bFlag; AcGePlane plane; TDbDormer *m_DbDormer; CDormerDlg *m_dlg; CString m_strLabel; }; TDbDormerJig::TDbDormerJig(TDbDormer *pDrawEnt,PickSet *ss,CDormerDlg *dlg) { m_bFlag = FALSE; m_DbDormer = pDrawEnt; m_dlg = dlg; int nDrawMode=DocGetDrawMode(); DocSetDrawMode(DRAW_3D); for (long i = 0; i < ss->Length();i++) { Entity ent = (*ss)[i]; OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbEntity, pEnt); InitModel(TMasterProperties(), pEnt, NULL, entSet); OPENOBJ_END(); } DocSetDrawMode(nDrawMode); } TDbDormerJig::~TDbDormerJig() { ReleaseEntSet(entSet); } void TDbDormerJig::SetPrompt(const TCHAR *m_pTemp) { m_pszPrompt = m_pTemp; acutPrintf(m_pTemp); } int TDbDormerJig::GetRetCode() const { int ret = m_nRetCode; if (ret == AcEdJig::kCancel) ret = RTCAN; else if (ret == AcEdJig::kNull) ret = RTNONE; else if (ret == AcEdJig::kNormal) ret = RTNORM; else ret = RTKWORD; return ret; } int TDbDormerJig::doIt() { m_nRetCode = drag(); int nRet = GetRetCode(); return nRet; } void TDbDormerJig::CalcLabelForDlg() { m_strLabel = m_dlg->GetDormerLabel(*m_DbDormer); m_DbDormer->SetLabel(m_strLabel); } Adesk::Boolean TDbDormerJig::update() { int num=entSet.length(); for(int i=0; iisA()==AcDbFace::desc()) { AcDbFace *pFace=AcDbFace::cast(pEnt); XPoly2D poly(1); for(int n=0; n<4; n++) { AcGePoint3d pt; pFace->getVertexAt(n, pt); poly.AppendNode(pt); } poly.SetElevation(0); poly.Compress(); if ((m_point&poly)==PR_INSIDE) { X3DFace faceUcs, faceWcs; for(int n=0; n<4; n++) pFace->getVertexAt(n, faceWcs.GetVertex(n)); XVector3D vtNorm=faceWcs.GetNormal(); if (vtNorm.z<1.0E-9) continue; for(n=0; n<4; n++) faceUcs.GetVertex(n)=Wcs2Ucs(faceWcs.GetVertex(n)); if (faceUcs.IsLinear() || faceUcs.IsPoint()) continue; if (vtNorm.z<1.0E-9) plane.set((AcGePoint3d &)faceWcs.GetVertex(2), (AcGePoint3d &)faceWcs.GetVertex(1), (AcGePoint3d &)faceWcs.GetVertex(0)); else plane.set((AcGePoint3d &)faceWcs.GetVertex(0), (AcGePoint3d &)faceWcs.GetVertex(1), (AcGePoint3d &)faceWcs.GetVertex(2)); break; } } } AcGePlane planXY(AcGePoint3d(0,0,0), AcGeVector3d(0,0,1)); AcGeLine3d lnIntersect; if (!plane.intersectWith(planXY, lnIntersect)) return Adesk::kFalse; AcGeVector3d vtNormal=plane.normal(); AcGeVector3d vtIntersect=lnIntersect.direction(); AcGeVector3d vtDormerDir(0,2,1);//老虎窗方向 XPoint ptDormerBase; //老虎窗基点 TDormerLayer dormerLayer; dormerLayer.InitDefaults(); vtDormerDir=vtNormal.crossProduct(vtIntersect); if (vtDormerDir.z<0) vtDormerDir.negate(); if ((fabs(vtDormerDir.z)<1.0E-5) || (fabs(vtDormerDir.x)<1.0E-5 && fabs(vtDormerDir.y)<1.0E-5)) //adsout << _T("\n坡度不合适!") return Adesk::kFalse; vtDormerDir.normalize(); XPoint ptInsert = m_point; //ptInsert=Ucs2Wcs(ptInsert);removed by whl on 070608 XPoint ptUp=ptInsert+XPoint(0,0,100); AcGeLine3d linEnt((AcGePoint3d &)ptInsert, (AcGePoint3d &)ptUp); if (!plane.intersectWith(linEnt, ptDormerBase)) return Adesk::kFalse; TDormerPar dormerPar; m_dlg->GetDormerPar(dormerPar); m_dlg->GetDormerLayer(dormerLayer); BOOL bShowWindow = m_dlg->IsShowWindow(); if (dormerPar.IsValid()) { if (m_DbDormer != NULL) { m_DbDormer->assertWriteEnabled(); m_DbDormer->SetDormerDir(vtDormerDir); m_DbDormer->SetDormerBase(ptDormerBase); m_DbDormer->SetDormerPar(dormerPar); m_DbDormer->SetDormerLayer(dormerLayer); m_DbDormer->ShowWindow(bShowWindow); m_DbDormer->SetLayerText(InitLayer(LAY_OPENING_DIM)); m_DbDormer->setLayer(InitLayer(LAY_ROOF)); m_DbDormer->SetTextStyle(InitTextStyle(TS_WINDOW)); m_DbDormer->SetLabel(m_strLabel); m_DbDormer->SetLabelPos(m_DbDormer->GetDefaultLabPos()); } } else return Adesk::kFalse; return Adesk::kTrue; } AcEdJig::DragStatus TDbDormerJig::sampler() { DragStatus stat; setUserInputControls((UserInputControls) (AcEdJig::kAccept3dCoordinates|AcEdJig::kNullResponseAccepted)); if (m_pszKeyword) setKeywordList(m_pszKeyword); AcGePoint3d m_Temp; if (m_bFlag) stat = acquirePoint(m_Temp,m_PrePoint); else stat = acquirePoint(m_Temp); if (stat == AcEdJig::kNormal) { if (m_point == m_Temp) return AcEdJig::kNoChange; m_point = m_Temp; } return stat; } AcDbEntity* TDbDormerJig::entity() const { return (AcDbEntity*)m_DbDormer; } //创建老虎窗 void CreateDormer() { //static TDormerPar dormerPar;//老虎窗参数 // [11/9/2007 nsh] TDormerPar dormerPar; TDormerLayer dormerLayer;//老虎窗图层 dormerLayer.InitDefaults(); static BOOL bShowWindow=TRUE; //墙上开窗否 PickSet ss(SS_FREE); RBList mask(RTDXF0, _T("*"), NULL); if (SelectEntities(_T("\n请选择屋顶: "), ss, mask) != RTNORM) return; CAcModuleResourceOverride vTemp; CDormerDlg dlg(_T("加老虎窗"),acedGetAcadFrame()); dlg.SetDormerPar(dormerPar); dlg.SetDormerLayer(dormerLayer); dlg.SetShowWindow(bShowWindow); if (dlg.DoModal() == IDOK) { AcGePoint3d point; BOOL bFlag = FALSE; while (1) { TDbDormer* pDormer = new TDbDormer(); TDbDormerJig jig(pDormer,&ss,&dlg); jig.CalcLabelForDlg(); CAcModuleResourceOverride resOverride(acedGetAcadResourceInstance()); jig.SetPrompt(_T("\n请点取插入点或 [修改参数(S)]<退出>:")); jig.m_pszKeyword = _T("S"); jig.m_bFlag = bFlag; jig.m_PrePoint = point; int nRet; INITGET_BEG(-1, _T("S")); nRet = jig.doIt(); INITGET_END(); if ( nRet == RTNORM) { pDormer->AddToMSpace(Adesk::kTrue); dlg.AfterModelAdded(pDormer); } else if (nRet == RTKWORD) { dlg.DoModal(); } else if (pDormer != NULL) { delete pDormer; pDormer = NULL; break; } point = jig.m_point; bFlag = TRUE; } } } // 编辑老虎窗 int EditDormer0(AcDbObjectId id) { OPENOBJ_BEGIN(id,AcDb::kForRead,TDbDormer,pDormer); if (!pDormer) return RTERROR; TDormerPar dormerPar; TDormerLayer dormerLayer; dormerPar = pDormer->GetDormerPar(); dormerLayer = pDormer->GetDormerLayer(); BOOL bShowWindow = pDormer->IsShowWindow(); CAcModuleResourceOverride vTemp; CDormerDlg dlg(_T("编辑老虎窗"),acedGetAcadFrame()); dlg.SetDefaultLabel(true, pDormer->GetLabel()); dlg.SetDormerPar(dormerPar); dlg.SetDormerLayer(dormerLayer); dlg.SetShowWindow(bShowWindow); dlg.m_csLabel = pDormer->GetLabel(); if (dlg.DoModal() == IDOK) { dlg.GetDormerPar(dormerPar); dlg.GetDormerLayer(dormerLayer); bShowWindow = dlg.IsShowWindow(); if (dormerPar.IsValid()) { if (pDormer->upgradeOpen()==Acad::eOk) { pDormer->assertWriteEnabled(); pDormer->SetDormerPar(dormerPar); pDormer->SetDormerLayer(dormerLayer); pDormer->ShowWindow(bShowWindow); // pDormer->SetLabel(dlg.m_csLabel); pDormer->SetLabel(dlg.GetDormerLabel(*pDormer)); pDormer->downgradeOpen(); } } else { AfxMessageBox(_T("老虎窗参数不对!")); } } OPENOBJ_END(); return RTNORM; } //add by zyu on 100118 double g_dDiameter = 200;//管径 double g_dWidth = 140;//洞口宽 // Zyu modify on 100824,始终进行编组 //extern TARCH_IMPEXP BOOL g_bMakeGroup;//是否编组 //加雨水管 void RainPipe() { int iRetCode = RTNORM; //返回值 ads_point ptStart; //起始点 ads_point ptEnd; //结束点 ads_point ptRef; //参考点 bool bOuterLoop = true; //是否循环,外层的. bool bInnerLoop = true; //是否循环,内层的. bool bIsRefPntUsed = false; //记录是否使用参考点 bool bDrawRainPipe = false; //记录是否画雨水管 bool bIsChanged = true; //记录是否更改过管径和洞口宽 CString sPrompt; //提示文字 AcDbObjectId idLineType = InitLineType(_T("DASH")); //线型ID AcDbObjectId idLayer = InitLayer(LAY_ARCH_STRM); //图层ID double dCeltScale = 1; //线型比例 VERIFY(RTNORM == xg_getvar(_T("CELTSCALE"), &dCeltScale)); //获得当前线型比例 // 错误说明:在设置捕捉点时,更改了用户已设置的捕捉点 // 解决方法:设置新捕捉点时,保持原来的设置 // 修改人,修改时间:Zyu modify on 100319 // Begin int iOsMode = 0; // 原来的捕捉点设置 VERIFY(RTNORM == TGGetVar(_T("OSMODE"), &iOsMode)); // 获得原来的捕捉点设置 // End while (bOuterLoop) { //指定起始点时的循环 // Zyu modify on 100319 // XPushVar iMode(_T("OSMODE"), 512);//设置捕获参数 XPushVar iMode(_T("OSMODE"), iOsMode | 512); // 设置捕获参数 if (bIsChanged) { //当更改过管径和洞口宽这两个参数时,显示更改后的结果 bIsChanged = false; sPrompt.Format(_T("\n当前管径为%.0f,洞口宽%.0f"), g_dDiameter, g_dWidth); ads_printf(sPrompt); } if (bIsRefPntUsed) { //如果指定过参考点,则不再提示指定参考点 INITGET_BEG(0, _T("D W")); iRetCode = ads_getpoint(ptRef, _T("\n请给出雨水管入水洞口的起始点[管径(D)/洞口宽(W)]<退出>:"), ptStart); INITGET_END(); } else { INITGET_BEG(0, _T("R D W")); iRetCode = ads_getpoint(NULL, _T("\n请给出雨水管入水洞口的起始点[参考点(R)/管径(D)/洞口宽(W)]<退出>:"), ptStart); INITGET_END(); } switch (iRetCode) { case RTKWORD: { TCHAR szBuf[256]; acedGetInput(szBuf); switch (szBuf[0]) { case _T('D'): { sPrompt.Format(_T("\n请指定雨水管直径<%.0f>:"), g_dDiameter); INITGET_BEG(RSG_NONEG | RSG_NOZERO, _T("")); bIsChanged = (RTNORM == ads_getreal(sPrompt, &g_dDiameter));//记录是否更改过参数 INITGET_END(); } break ; case _T('W'): { sPrompt.Format(_T("\n请指定洞口宽度<%.0f>:"), g_dWidth); INITGET_BEG(RSG_NONEG | RSG_NOZERO, _T("")); bIsChanged = (RTNORM == ads_getreal(sPrompt, &g_dWidth));//记录是否更改过参数 INITGET_END(); } break ; case _T('R'): { bIsRefPntUsed = (RTNORM == ads_getpoint(NULL, _T("\n请指定雨水管的参考点:"), ptRef)); } break ; default: { } } } break ; case RTNORM: { bInnerLoop = true; while (bInnerLoop) { if (bIsChanged) { bIsChanged = false; adsout << _T("\n当前管径为") << g_dDiameter << _T(",洞口宽") << g_dWidth; } // Zyu modify on 100319 // XPushVar iOsMode(_T("OSMODE"), 128);//设置捕获参数 XPushVar iOsMode(_T("OSMODE"), iOsMode | 128);//设置捕获参数 INITGET_BEG(0, _T("D W")); iRetCode = ads_getpoint(ptStart, _T("\n出水口结束点[管径(D)/洞口宽(W)]<退出>:"), ptEnd); INITGET_END(); switch (iRetCode) { case RTKWORD: { TCHAR szBuf[256]; acedGetInput(szBuf); switch (szBuf[0]) { case _T('D'): { sPrompt.Format(_T("\n请指定雨水管直径<%.0f>:"), g_dDiameter); INITGET_BEG(RSG_NONEG | RSG_NOZERO, _T("")); bIsChanged = (RTNORM == ads_getreal(sPrompt, &g_dDiameter)); INITGET_END(); } break ; case _T('W'): { sPrompt.Format(_T("\n请指定洞口宽度<%.0f>:"), g_dWidth); INITGET_BEG(RSG_NONEG | RSG_NOZERO, _T("")); bIsChanged = (RTNORM == ads_getreal(sPrompt, &g_dWidth)); INITGET_END(); } break ; } } break ; case RTNORM: { //退出内层循环,画线,参考点是否指定置为false bInnerLoop = false; bDrawRainPipe = true; bIsRefPntUsed = false; } break ; default: { //退出内外循环,不画线 bInnerLoop = false; bOuterLoop = false; bDrawRainPipe = false; } } } } break ; default: { //退出循环,不画线. bOuterLoop = false; bDrawRainPipe = false; } } if (bDrawRainPipe) { //画雨水管 bDrawRainPipe = false; bIsChanged = true; //Ucs to Wcs ads_trans(ptStart, (resbuf *)&Groups(1), (resbuf *)&Groups(0), false, ptStart); ads_trans(ptEnd, (resbuf *)&Groups(1), (resbuf *)&Groups(0), false, ptEnd); AcGePoint3d ptStart3d = asPnt3d(ptStart); AcGePoint3d ptEnd3d = asPnt3d(ptEnd); AcGeVector3d vtDirection = (ptStart3d - ptEnd3d).rotateBy(PI / 2, AcGeVector3d::kZAxis).normalize() * g_dWidth / 2; AcDbVoidPtrArray ptrArray; AcDbObjectIdArray arObjId; //画线 AcDbLine *pLine = new AcDbLine((ptStart3d + vtDirection), (ptEnd3d + vtDirection)); pLine->setLinetype(idLineType); pLine->setLayer(idLayer); pLine->setLinetypeScale(dCeltScale); ptrArray.append(pLine); pLine = new AcDbLine((ptStart3d - vtDirection), (ptEnd3d - vtDirection)); pLine->setLinetype(idLineType); pLine->setLayer(idLayer); pLine->setLinetypeScale(dCeltScale); ptrArray.append(pLine); //画圆 //AcGePoint3d ptCenter(ptEnd3d + (ptEnd3d - ptStart3d).normal() * (1.7 * g_dDiameter)); AcGePoint3d ptCenter(ptEnd3d + (ptEnd3d - ptStart3d).normal() * (g_dDiameter + g_dWidth) / 2); AcDbCircle *pCircle = new AcDbCircle(ptCenter, AcGeVector3d::kZAxis, g_dDiameter / 2); pCircle->setLayer(idLayer); ptrArray.append(pCircle); if (RTNORM != TchExport::AddArrayToModelSpace(ptrArray, arObjId, true)) { //当不能添加数据库时,回收分配的内存 int iNum = ptrArray.length(); for (int i = 0; i < iNum; i++) { delete ptrArray.at(i); } } // Zyu modify on 100824,始终进行编组 //else if (g_bMakeGroup) else { //添加编组 TchExport::MakeGroup(arObjId, AcDbObjectId()); } } } }