#include "stdafx.h" #include "TSectionEdJig.h" #include "PickEntSet.h" #include "layerdef.h" extern AcDbObjectId InitTextStyle(TTextStyle ts, AcDbDatabase *pDb = NULL); extern AcDbObjectId InitLayer(const TCHAR *szLayer, BOOL bApplyChange = FALSE); TSectionEdJig::TSectionEdJig() { m_pDrawEnt = NULL; m_pVirDrawEnt = NULL; } TSectionEdJig::~TSectionEdJig() { if (m_pVirDrawEnt) { delete m_pVirDrawEnt; m_pVirDrawEnt = NULL; } } TSectionEdJig::TSectionEdJig(AecXDbSymbSection* pSec) { m_pDrawEnt = pSec; m_pVirDrawEnt = new TVirtualSection; } // 开始执行拖动 int TSectionEdJig::DoIt(int *keyIndex) { XPushVar osmode(_T("OSMODE"), 0); if(m_nOperCode==kSectPoint || m_nOperCode==kViewDirection) { XPoly2D poly; if (m_pDrawEnt != NULL) { m_pDrawEnt->GetPoly2D(poly); ASSERT(poly.Length() >= 2); m_ptResult=*poly.Tail(); } } int nRet = TSymbEdJig::DoIt(keyIndex); return nRet; } AcEdJig::DragStatus TSectionEdJig::GetPoint(XPoint &pt) { XPoint ptBase; XPoly2D poly; DragStatus stat; m_pDrawEnt->GetPoly2D(poly); if(m_nOperCode == kSectPoint) { ASSERT(poly.Length() == 2); ptBase = *poly.Head(); stat = acquirePoint(pt, ptBase); } else { stat = acquirePoint(pt); } m_ptCur = pt.AsAcGePoint3d(); return stat; } // 更新实体数据 Adesk::Boolean TSectionEdJig::update() { if(m_nOperCode == TSectionEdJig::kSectPoint) { XPoly2D poly; m_pDrawEnt->GetPoly2D(poly); ASSERT(poly.Length()==2); XPoint pt1 = *poly[0]; *poly[1] = m_ptResult; double nViewDir=ads_angle(pt1, m_ptResult)-PI/2.0; m_pDrawEnt->SetPoly2D(poly); m_pDrawEnt->SetViewDirection(nViewDir); m_pDrawEnt->SetTextLocation(0, m_pDrawEnt->GetDefaultTextLocation(0)); m_pDrawEnt->SetTextLocation(1, m_pDrawEnt->GetDefaultTextLocation(1)); } else if(m_nOperCode == TSectionEdJig::kViewDirection) { XPoly2D poly; m_pDrawEnt->GetPoly2D(poly); int nLen=poly.Length(); ASSERT(nLen >= 2); XLine ln(*poly[nLen-2], *poly[nLen-1]); int nSide=ln.OnWhichSide(m_ptResult); double dAngle = 0.0; if(nSide == OFFSET_LEFT) { dAngle = CT_std_angle(ln.Direction()+PI/2); } else { dAngle = CT_std_angle(ln.Direction()-PI/2); } m_pDrawEnt->SetViewDirection(dAngle); m_pDrawEnt->SetTextLocation(0, m_pDrawEnt->GetDefaultTextLocation(0)); m_pDrawEnt->SetTextLocation(1, m_pDrawEnt->GetDefaultTextLocation(1)); if (m_pVirDrawEnt) { m_vtDir = AcGeVector3d::kXAxis; m_vtDir.rotateBy(dAngle,AcGeVector3d::kZAxis); m_pVirDrawEnt->SetCurPtAndDir(m_ptCur,m_vtDir); } } if (m_pVirDrawEnt) { m_pVirDrawEnt->SetSectionPtr(m_pDrawEnt); } return Adesk::kTrue; } AcDbEntity* TSectionEdJig::entity() const { return (AcDbEntity*)m_pVirDrawEnt; } //Command: 绘制一条剖线 void TSectionEdJig::SymbSectionArg(BOOL bViewLine) { XString sName; int rc=ads_getstring(0, _T("\n请输入剖切编号<1>:"), sName); if(rc!=RTNORM) return; if(!_tcscmp(sName,_T(""))) { _tcscpy(sName,_T("1")); } m_strName = sName; // cet 2010.4.23 add XPoint ptFirst; if(ads_getpoint(NULL,_T("\n点取第一个剖切点<退出>: "),ptFirst)!=RTNORM) return; ptFirst = GlobalFunc::Ucs2Wcs(ptFirst); m_ptFir = ptFirst.AsAcGePoint3d(); XPoly2D poly(0); poly.AppendNode(ptFirst); poly.AppendNode(ptFirst); AecXDbSymbSection ent; ent.SetText(sName); ent.SetLayoutRotation(GlobalFunc::Ucs2Wcs(0.0)); ent.setLayer(ent.GetDefaultLayer()); ent.SetTextStyleId(InitTextStyle(TS_LABEL)); ent.SetTextLayerId(InitLayer(LAY_TEXT, FALSE)); ent.SetViewLine(bViewLine); ent.SetPoly2D(poly); TSectionEdJig jig(&ent); jig.SetPrompt(_T("\n点取第二个剖切点<退出>:")); jig.SetOperCode(TSectionEdJig::kSectPoint); if(jig.DoIt() != RTNORM) return; int nRet; ent.GetPoly2D(poly); m_ptSec = (*poly.Tail()).AsAcGePoint3d(); jig.SetBasePoints(m_ptFir,m_ptSec); jig.SetPrompt(_T("\n点取剖视方向<当前方向>:")); jig.SetOperCode(TSectionEdJig::kViewDirection); nRet = jig.DoIt(); jig.GetCornerPoint(m_ptCorner); if((nRet==RTNORM || nRet==RTNONE) && ent.IsValid()) { ent.SetTextLocation(0, ent.GetDefaultTextLocation(0)); ent.SetTextLocation(1, ent.GetDefaultTextLocation(1)); double dAngle = ent.GetViewDirection(); m_vtDir = AcGeVector3d::kXAxis; m_vtDir.rotateBy(dAngle,AcGeVector3d::kZAxis); GlobalFunc::AddToCurrentSpace((AcDbEntity*)ent.clone(), Adesk::kTrue); //((TDbEntity*)ent.clone())->AddToCSpace(Adesk::kTrue); } } void TSectionEdJig::GetCornerPoint(AcGePoint3d& ptCorner) { m_vtDir.normalize(); AcDbLine line(m_ptFir,m_ptSec); AcGePoint3d ptT; line.getClosestPointTo(m_ptCur,ptT,Adesk::kTrue); double dDist = ptT.distanceTo(m_ptCur); ptCorner = m_ptSec + m_vtDir * dDist; } void TSectionEdJig::GetPickset(PickSet& ssEnt) { // cet 2010.3.30 del // RBList mask = ads_buildlist( -4, _T(""), // -4, _T(""), // -4, _T("or>"), NULL); // cet 2010.3.30 add 增加大小接头 RBList mask = ads_buildlist( -4, _T(""), -4, _T(""), -4, _T("or>"), NULL); AcGePoint3d pt1 = m_ptFir; AcGePoint3d pt2 = m_ptCorner; pt1 = GlobalFunc::Wcs2Ucs(pt1); pt2 = GlobalFunc::Wcs2Ucs(pt2); acedSSGet(_T("C"),&pt1,&pt2,mask,ssEnt); } XPoint TSectionEdJig::GetSecPoint() { return m_ptFir; } // cet 2010.4.19 add XPoint TSectionEdJig::GetSecPoint2() { return m_ptSec; } // cet 2010.4.23 add CString TSectionEdJig::GetNumber() { return m_strName; } AcGeVector3d TSectionEdJig::GetSecDir() { return m_vtDir; } void TSectionEdJig::SetBasePoints(const AcGePoint3d& ptFir,const AcGePoint3d& ptSec) { if (m_pVirDrawEnt) { m_pVirDrawEnt->SetBasePoints(ptFir,ptSec); m_ptFir = ptFir; m_ptSec = ptSec; } } // Command: 剖面剖切 void TSectionEdJig::SymbSection() { SymbSectionArg(TRUE); } void TSectionEdJig::SetOperCode(TSectionEdJig::TSectionOper opCode) { m_nOperCode = opCode; } // 剖切线类 TVirtualSection::TVirtualSection() { } TVirtualSection::~TVirtualSection() { } Acad::ErrorStatus TVirtualSection::Draw2d(AcGiDraw& dc) const { Acad::ErrorStatus stat; if (m_pDrawEnt) { DrawBaseEx(dc, *m_pDrawEnt); //stat = m_pDrawEnt->ExplodeOrDraw2d(dc); } stat = ExplodeOrDraw2dLineBox(dc); return stat; } Acad::ErrorStatus TVirtualSection::ExplodeOrDraw2dLineBox(AcGiDraw& dc) const { //XAcGiViewDraw* pXDraw = (XAcGiViewDraw*)&dc; AcGiCommonDraw* pCDraw = dc.GetCommonDraw(); if (pCDraw == NULL) { return Acad::eInvalidInput; } AcGePoint3d arPt[2]; AcGePoint3d ptT; AcGeVector3d vtT = m_vtDir; vtT.normalize(); AcDbLine line(m_ptFir,m_ptSec); line.getClosestPointTo(m_ptPos,ptT,Adesk::kTrue); double dDist = ptT.distanceTo(m_ptPos); // 设置颜色 dc.SetColor(3); arPt[0] = m_ptFir; arPt[1] = m_ptFir + vtT * dDist; //pCDraw->rawGeometry()->worldLine(arPt); DrawLine(dc, arPt[0], arPt[1]); arPt[0] = m_ptSec; arPt[1] = m_ptSec + vtT * dDist; //pCDraw->rawGeometry()->worldLine(arPt); DrawLine(dc, arPt[0], arPt[1]); arPt[0] = m_ptFir + vtT * dDist; arPt[1] = m_ptSec + vtT * dDist; //pCDraw->rawGeometry()->worldLine(arPt); DrawLine(dc, arPt[0], arPt[1]); return Acad::eOk; } void TVirtualSection::SetSectionPtr(AecXDbSymbSection* pSec) { m_pDrawEnt = pSec; } void TVirtualSection::SetBasePoints(const AcGePoint3d& ptFir,const AcGePoint3d& ptSec) { m_ptFir = ptFir; m_ptSec = ptSec; } void TVirtualSection::SetCurPtAndDir(const AcGePoint3d& ptCur,const AcGeVector3d& vtCur) { m_ptPos = ptCur; m_vtDir = vtCur; }