#include "stdafx.h" #include "AecDbPathSectionSymbDim.h" #include "dbgrip.h" #include "CoreTools.h" Adesk::UInt32 AecDbPathSectionSymbDim::kCurrentVersionNumber = 2; ACRX_DXF_DEFINE_MEMBERS (AecDbPathSectionSymbDim, AecDbCurveBase, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, AcDbProxyEntity::kNoOperation | AcDbProxyEntity::kDisableProxyWarning, AEC_DBPSSDIM, "AecDbPathSectionSymbDim" "|Product Desc: shanghua earthworm app obj" "|Company: shanghua inc" "|WEB Address: www.shanghuasoft.com") AecDbPathSectionSymbDim::AecDbPathSectionSymbDim(void) { _tcscpy(m_szSymb,_T("*")); m_dTxtH = 3.5 * 100.0; m_dDisOff = 7.5 * 100.0; m_dW = 0.5 * 100.0; m_idTxtStyle = acdbCurDwg()->textstyle(); } AecDbPathSectionSymbDim::~AecDbPathSectionSymbDim(void) { } AecDbObjXDataMap* AecDbPathSectionSymbDim::GetSpecialtyData(AcDb::OpenMode bMode/* = AcDb::kForWrite*/) { switch(bMode) { case AcDb::kForRead: { assertReadEnabled(); break; } case AcDb::kForWrite: { if (!isWriteEnabled()) { upgradeOpen(); } assertWriteEnabled(); break; } case AcDb::kForNotify: { if (!isWriteEnabled()) { upgradeOpen(); } } default: break; } return &m_xDataMap; } const AecDbObjXDataMap* AecDbPathSectionSymbDim::GetSpecialtyData() const { assertReadEnabled(); return &m_xDataMap; } void AecDbPathSectionSymbDim::SetDimTxt(LPCTSTR pszDim) { assertWriteEnabled(); if (pszDim != NULL) _tcscpy(m_szSymb,pszDim); } void AecDbPathSectionSymbDim::GetDimTxt(CString& sDim) const { assertReadEnabled(); sDim = m_szSymb; } void AecDbPathSectionSymbDim::SetTextH(double dH) { assertWriteEnabled(); m_dTxtH = dH; } double AecDbPathSectionSymbDim::GetTextH() const { assertReadEnabled(); return m_dTxtH; } void AecDbPathSectionSymbDim::SetDisOff(double dDisOff) { assertWriteEnabled(); m_dDisOff = dDisOff; } double AecDbPathSectionSymbDim::GetDisOff() const { assertReadEnabled(); return m_dDisOff; } void AecDbPathSectionSymbDim::SetWidth(double dW) { assertWriteEnabled(); m_dW = dW; } double AecDbPathSectionSymbDim::GetWidth() const { assertReadEnabled(); return m_dW; } void AecDbPathSectionSymbDim::SetTextStyle(const AcDbObjectId& idStyle) { assertWriteEnabled(); m_idTxtStyle = idStyle; } AcDbObjectId AecDbPathSectionSymbDim::GetTextStyle() const { assertReadEnabled(); return m_idTxtStyle; } void AecDbPathSectionSymbDim::SetPath(const AcArray& aPath) { assertWriteEnabled(); if (!aPath.isEmpty()) { m_arSecPath.removeAll(); m_arSecPath.append(aPath); } } int AecDbPathSectionSymbDim::GetPath(AcArray& aPath) const { assertReadEnabled(); aPath.append(m_arSecPath); return aPath.length(); } Acad::ErrorStatus AecDbPathSectionSymbDim::dwgInFields(AcDbDwgFiler* pFiler) { AssertWriteEnabled(); //----- Read parent class information first. Acad::ErrorStatus es = AecDbCurveBase::dwgInFields (pFiler) ; if ( es != Acad::eOk ) return (es) ; //----- Object version number needs to be read first Adesk::UInt32 version =0 ; if ( (es =pFiler->readUInt32 (&version)) != Acad::eOk ) return (es) ; if ( version > AecDbPathSectionSymbDim::kCurrentVersionNumber ) return (Acad::eMakeMeProxy); TCHAR* pszVal = NULL; pFiler->readString(&pszVal); if (pszVal != NULL) _tcscpy(m_szSymb,pszVal); pFiler->readDouble(&m_dTxtH); pFiler->readDouble(&m_dDisOff); AcDbSoftPointerId id; pFiler->readSoftPointerId(&id); m_idTxtStyle = id; Adesk::Int32 nLen = 0; pFiler->readInt32(&nLen); m_arSecPath.removeAll(); Adesk::Int32 nPts = 0; SecPath sP; for (int i = 0;i < nLen;i++) { pFiler->readInt32(&nPts); sP.nPoints = nPts; for (int j = 0;j < nPts;j++) { pFiler->readPoint3d(&sP.ptGe[j]); } m_arSecPath.append(sP); } if (version >= 2) { m_xDataMap.dwgInFields(pFiler); } return pFiler->filerStatus(); } Acad::ErrorStatus AecDbPathSectionSymbDim::dwgOutFields(AcDbDwgFiler* pFiler) const { assertReadEnabled(); //----- Save parent class information first. Acad::ErrorStatus es = AecDbCurveBase::dwgOutFields (pFiler) ; if ( es != Acad::eOk ) return (es) ; //----- Object version number needs to be saved first if ( (es =pFiler->writeUInt32 (AecDbPathSectionSymbDim::kCurrentVersionNumber)) != Acad::eOk ) return (es) ; pFiler->writeString(m_szSymb); pFiler->writeDouble(m_dTxtH); pFiler->writeDouble(m_dDisOff); pFiler->writeSoftPointerId(m_idTxtStyle); Adesk::Int32 nSize = m_arSecPath.length(); pFiler->writeInt32(nSize); for (int i = 0;i < nSize;i++) { const SecPath& sp = m_arSecPath.at(i); Adesk::Int32 nPts = sp.nPoints; pFiler->writeInt32(nPts); for (int j = 0;j < nPts;j++) { pFiler->writePoint3d(sp.ptGe[j]); } } if (AecDbPathSectionSymbDim::kCurrentVersionNumber >= 2) { m_xDataMap.dwgOutFields(pFiler); } return pFiler->filerStatus(); } Acad::ErrorStatus AecDbPathSectionSymbDim::dxfInFields(AcDbDxfFiler* pFiler) { return Acad::eOk; } Acad::ErrorStatus AecDbPathSectionSymbDim::dxfOutFields(AcDbDxfFiler* pFiler) const { return Acad::eOk; } Acad::ErrorStatus AecDbPathSectionSymbDim::copyFrom(const AcRxObject* pSrc) { assertWriteEnabled(); AecDbPathSectionSymbDim* pSrcDim = AecDbPathSectionSymbDim::cast(pSrc); if (pSrcDim != NULL) { _tcscpy(m_szSymb,pSrcDim->m_szSymb); m_arSecPath.removeAll(); m_arSecPath.append(pSrcDim->m_arSecPath); m_xDataMap.Empty(); m_xDataMap.CopyFrom(&pSrcDim->m_xDataMap); } return Acad::eOk; } #if ARX>16 void AecDbPathSectionSymbDim::subList() const { assertReadEnabled(); acutPrintf(_T("\n折线剖切标注:")); AecDbCurveBase::subList(); } Acad::ErrorStatus AecDbPathSectionSymbDim::subTransformBy(const AcGeMatrix3d& xform) { AssertWriteEnabled(); for (int i = 0;i < m_arSecPath.length();i++) { SecPath& sp = m_arSecPath.at(i); for(int j = 0;j < sp.nPoints;j++) { sp.ptGe[j].transformBy(xform); } } return Acad::eOk; } namespace { double PixelToWcs(int nPixel) { ads_point ptScreenSize; double nViewSize; struct resbuf rb1, rb2; acedGetVar(_T("ScreenSize"), &rb1); acedGetVar(_T("ViewSize"), &rb2); nViewSize = rb2.resval.rreal; ads_point_set(rb1.resval.rpoint, ptScreenSize); if (ptScreenSize[1] < 1.0e-6 || nViewSize < 1.0e-6) return 0.0; double hight = (nViewSize / ptScreenSize[Y]) * nPixel; return hight; } bool Grip_WorldDrawfunc(AcDbGripData *pThis, AcGiWorldDraw *pWd, const AcDbObjectId &entId, AcDbGripOperations::DrawType type, AcGePoint3d *cursor, double dGripSize) { AcGiFillType eOldFill = pWd->subEntityTraits().fillType(); int nOldColor = pWd->subEntityTraits().color(); AecDbPathSectionSymbDim::GripData *pGrip = (AecDbPathSectionSymbDim::GripData *)pThis->appData(); AcGePoint3d ptGe[5], ptBox[5]; AcGePoint3d ptGrip = pThis->gripPoint(); double dOne = PixelToWcs(1); ptGe[0] = ptGrip; ptGe[0].x -= 4 * dOne; ptGe[1] = ptGrip; ptGe[1].x += 4 * dOne; ptBox[0] = ptGe[0]; ptBox[0].y -= 4 * dOne; ptBox[1] = ptGe[0]; ptBox[1].y += 4 * dOne; ptBox[2] = ptGe[1]; ptBox[2].y += 4 * dOne; ptBox[3] = ptGe[1]; ptBox[3].y -= 4 * dOne; pWd->subEntityTraits().setFillType(kAcGiFillAlways); pWd->geometry().polygon(4, ptBox); pWd->subEntityTraits().setFillType(eOldFill); // 保护一下 if (pGrip->m_idx > 2 || pGrip->m_datas.size() > 2) return true; AcGePoint3d pt0, pt1, pt2, pt3; pWd->subEntityTraits().setColor(9); AcGePoint3d arFrame[4]; for (size_t i(0); i < pGrip->m_datas.size(); ++i) { AecDbPathSectionSymbDim::GripData::sectionData &sd = pGrip->m_datas[i]; pt0 = sd.m_pt0; pt3 = sd.m_pt1; pt1 = pt0 + sd.m_vtTo; pt2 = pt3 + sd.m_vtTo; arFrame[0] = sd.m_pt0; arFrame[3] = sd.m_pt1; arFrame[1] = arFrame[0] + sd.m_vtTo; arFrame[2] = arFrame[3] + sd.m_vtTo; pWd->geometry().polyline(4, arFrame); } pWd->subEntityTraits().setColor(nOldColor); return true; } } Acad::ErrorStatus AecDbPathSectionSymbDim::subGetGripPoints( AcDbGripDataPtrArray& grips, const double curViewUnitSize, const int gripSize, const AcGeVector3d& curViewDir, const int bitflags) const { assertReadEnabled(); AcGePoint3dArray gripPoints; AcDbIntArray osnapModes; AcDbIntArray geomIds; subGetGripPoints(gripPoints, osnapModes, geomIds); m_GripDatas.clear(); // 先把 grippoints 里的点都绘制出来 for (int i(0); i < gripPoints.length(); ++i) { GripData gpd; gpd.m_idx = i; AcDbGripData *pGripData = new AcDbGripData; pGripData->setGripPoint(gripPoints.at(i)); pGripData->setWorldDraw(Grip_WorldDrawfunc); m_GripDatas.push_back(gpd); void *p = &*m_GripDatas.rbegin(); pGripData->setAppData(p); grips.append(pGripData); } CString s; if (!GetSpecialtyData()->GetAt(_T("_SECTION_FRAME_"), s)) return Acad::eOk; GripData &gripData = *m_GripDatas.rbegin(); AcGePoint3d pt; std::vector datas, pts, ds; std::vector pnts; CoreTools::SplitString(s, _T('+'), datas); GripData::sectionData sd; for (size_t i(0); i < datas.size(); ++i) { pts.clear(); CString &sdata(datas[i]); CoreTools::SplitString(sdata, _T('|'), pts); if (pts.size() < 3) continue; pnts.clear(); for (int j(0); j < 3; ++j) { ds.clear(); CString &spt(pts[j]); CoreTools::SplitString(spt, _T(','), ds); if (ds.size() >= 3) { pt.x = TypeConvert::s2f(ds[0]); pt.y = TypeConvert::s2f(ds[1]); pt.z = TypeConvert::s2f(ds[2]); pnts.push_back(pt); } } if (pnts.size() >= 3) { sd.m_pt0 = pnts[0]; sd.m_pt1 = pnts[1]; sd.m_vtTo.set(pnts[2].x, pnts[2].y, pnts[2].z); gripData.m_datas.push_back(sd); } } return Acad::eOk; } Acad::ErrorStatus AecDbPathSectionSymbDim::subMoveGripPointsAt(const AcDbVoidPtrArray& appData, const AcGeVector3d& offset, const int bitflags) { return Acad::eNotImplemented; } Acad::ErrorStatus AecDbPathSectionSymbDim::subGetGripPoints (AcGePoint3dArray& gripPoints,AcDbIntArray& osnapModes,AcDbIntArray& geomIds) const { assertReadEnabled(); //暂时增加文字位置夹点 if ( m_arSecPath.length() > 2) { AcGePoint3d ptT = m_arSecPath.first().ptGe[0]; AcGePoint3d pt2 = m_arSecPath.first().ptGe[1]; AcGeVector3d vt = ptT - pt2; vt.normalize(); vt *= m_dDisOff; ptT += vt; gripPoints.append(ptT); ptT = m_arSecPath.last().ptGe[1]; pt2 = m_arSecPath.last().ptGe[0]; vt = pt2 - ptT; vt.normalize(); vt *= m_dDisOff; pt2 += vt; gripPoints.append(pt2); } return Acad::eOk; } Acad::ErrorStatus AecDbPathSectionSymbDim::subMoveGripPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset) { AssertWriteEnabled(); return Acad::eOk; } void AecDbPathSectionSymbDim::GetGripText(int nPos, CString& sText) { } Acad::ErrorStatus AecDbPathSectionSymbDim::subGetOsnapPoints(AcDb::OsnapMode osnapMode, INT_PTR gsSelectionMark, const AcGePoint3d& pickPoint, const AcGePoint3d& lastPoint, const AcGeMatrix3d& viewXform, AcGePoint3dArray& snapPoints, AcDbIntArray& geomIds) const { assertReadEnabled(); AcDbCurve* pBase = GetNativeCurve(); if (pBase != NULL) { pBase->getOsnapPoints(osnapMode,gsSelectionMark,pickPoint,lastPoint,viewXform,snapPoints,geomIds); delete pBase; } return Acad::eOk; } Acad::ErrorStatus AecDbPathSectionSymbDim::subGetGeomExtents(AcDbExtents& extents) const { assertReadEnabled(); AcDbCurve* pBase = GetNativeCurve(); if (pBase != NULL) { pBase->getGeomExtents(extents); delete pBase; } return Acad::eOk; } Acad::ErrorStatus AecDbPathSectionSymbDim::subIntersectWith(const AcDbEntity* pEnt, AcDb::Intersect intType, AcGePoint3dArray& points, INT_PTR thisGsMarker, INT_PTR otherGsMarker) const { assertReadEnabled(); AcDbCurve* pBase = GetNativeCurve(); if (pBase != NULL) { pBase->intersectWith(pEnt,intType,points,thisGsMarker,otherGsMarker); delete pBase; } return Acad::eOk; } Acad::ErrorStatus AecDbPathSectionSymbDim::subIntersectWith(const AcDbEntity* pEnt, AcDb::Intersect intType, const AcGePlane& projPlane, AcGePoint3dArray& points, INT_PTR thisGsMarker, INT_PTR otherGsMarker) const { AcDbCurve* pBase = GetNativeCurve(); if (pBase != NULL) { pBase->intersectWith(pEnt,intType,projPlane,points,thisGsMarker,otherGsMarker); delete pBase; } return Acad::eOk; } #endif AcDbCurve* AecDbPathSectionSymbDim::GetBaseCurve(bool bOrthoProjectToXY/* = false*/) const { assertReadEnabled(); AcDbPolyline* pPl = new AcDbPolyline; for (int i = 0;i < m_arSecPath.length();i++) { const SecPath& sp = m_arSecPath.at(i); for (int j = 0;j < sp.nPoints;j++) { pPl->addVertexAt(pPl->numVerts(),sp.ptGe[j].convert2d(AcGePlane::kXYPlane)); } } return pPl; } AcDbCurve* AecDbPathSectionSymbDim::GetNativeCurve() const { assertReadEnabled(); AcDbPolyline* pPl = new AcDbPolyline; for (int i = 0;i < m_arSecPath.length();i++) { const SecPath& sp = m_arSecPath.at(i); for (int ii = 0;ii < sp.nPoints;ii++) { pPl->addVertexAt(pPl->numVerts(),sp.ptGe[ii].convert2d(AcGePlane::kXYPlane)); } } return pPl; } Acad::ErrorStatus AecDbPathSectionSymbDim::Draw2d(AcGiDraw &dc) const { assertReadEnabled(); //管线系统屏蔽掉 if ( dc.IsDragging() ) { //return Acad::eOk; } AcDbObjectId idCurLay = dc.GetLayerId(); AcDbObjectId idCurLty = dc.GetLineTypeId(); Adesk::UInt16 nCrBk = colorIndex(); if (Has2DBuffer()) { AcDbObjectId idLn = linetypeId(); AcDbObjectId idLay = layerId(); int nColorE = nCrBk; AcDbEntity* pEnt = NULL; const AcDbVoidPtrArray &ar2D = Get2DBuffer(); for (int i = 0;i < ar2D.length();i++) { pEnt = (AcDbEntity*)ar2D.at(i); nColorE = pEnt->colorIndex(); idLn = pEnt->linetypeId(); idLay = pEnt->layerId(); dc.SetColor(nColorE); dc.SetLineType(idLn); dc.SetLayer(idLay); dc.DrawEntity(*pEnt); } dc.SetLayer(idCurLay); dc.SetLineType(idCurLty); dc.SetColor(nCrBk); return Acad::eOk; } for (int i = 0;i < m_arSecPath.length();i++) { const SecPath& sp = m_arSecPath.at(i); AcDbPolyline* pPl = new AcDbPolyline; for (int ii = 0;ii < sp.nPoints;ii++) { pPl->addVertexAt(pPl->numVerts(),sp.ptGe[ii].convert2d(AcGePlane::kXYPlane)); } pPl->setConstantWidth(m_dW); pPl->setLayer(layerId()); dc.DrawEntity(pPl); Add2DBuffer(pPl); } AcDbIntArray osnapModes,gemIds; AcGePoint3dArray arPts; getGripPoints(arPts,osnapModes,gemIds); for (int i = 0;i < arPts.length();i++) { AcDbText* pText = new AcDbText; pText->setTextString(m_szSymb); pText->setPosition(arPts.at(i)); pText->setHeight(m_dTxtH); pText->setRotation(0.0); pText->setTextStyle(m_idTxtStyle); pText->setLayer(layerId()); dc.DrawEntity(pText); Add2DBuffer(pText); } return Acad::eOk; } Acad::ErrorStatus AecDbPathSectionSymbDim::Draw3d(AcGiDraw &dc) const { return Draw2d(dc); }