// CLampDim.cpp: implementation of the CLampDim class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// ACRX_DXF_DEFINE_MEMBERS(CLampDim,AcDbEntity, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, AcDbProxyEntity::kEraseAllowed, ATS_EQUIPDIM, "ATS_EQUIPDIM,图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com"); CLampDim::CLampDim() { m_nType = -1; m_csX = _T("x"); // x X × m_bHasW = true; m_nTextHeight = 350; m_nWidthFactor = 0.8; m_csTextStyle = _T("_TEL_DIM"); m_ptIns.x = 0; m_ptIns.y = 0; m_nDimLen = -1; } CLampDim::CLampDim( AcGePoint3d ptIns, bool bHasW, int nNum, CString csX, CString csBulbNum, CString csSpec, CString csBulbPower, CString csSetupHeight, CString csSetupMode, CString csLightType) { m_nType = 0; m_nTextHeight = 350; m_nWidthFactor = 0.8; m_csTextStyle = _T("_TEL_DIM"); m_ptIns = ptIns; m_bHasW = bHasW; m_csX = csX; m_nNum = nNum; m_csBulbNum = csBulbNum; m_csSpec = csSpec; m_csBulbPower = csBulbPower; m_csSetupHeight = csSetupHeight; m_csSetupMode = csSetupMode; m_csLightType = csLightType; m_nDimLen = -1; InitData(); } CLampDim::CLampDim(AcGePoint3d ptIns, CString csBulbNum, CString csSetupHeight) { m_nType = 1; m_nNum = 0; m_nTextHeight = 350; m_nWidthFactor = 0.8; m_csTextStyle = _T("_TEL_DIM"); m_ptIns = ptIns; m_csBulbNum = csBulbNum; m_csSetupHeight = csSetupHeight; m_nDimLen = -1; InitData(); } CLampDim::CLampDim(AcGePoint3d ptIns, CString csBulbNum) { m_nType = 2; m_nNum = 0; m_nTextHeight = 350; m_nWidthFactor = 0.8; m_csTextStyle = _T("_TEL_DIM"); m_ptIns = ptIns; m_csSpec = csBulbNum; m_nDimLen = -1; InitData(); } CLampDim::~CLampDim() { } // *************************************** // csTitle2 // csTitle1 ------------ csTitle4 // csTitle3 //**************************************** void CLampDim::InitData() { m_csTitle1.Format(_T("%d"), m_nNum); if(m_csTitle1 != _T("") && m_csSpec != _T("") && m_nType == 0) m_csTitle1 += _T("-"); else if(m_nType != 0) m_csTitle1 = _T(""); m_csTitle1 += m_csSpec; if(m_csBulbNum == _T("")) m_csBulbNum = _T("1"); if(m_csBulbNum == _T("1")) m_csTitle2 = _T(""); else m_csTitle2 = m_csBulbNum; if(m_csBulbNum != _T("1") && (m_csBulbPower != _T("") || m_csLightType!=_T(""))) m_csTitle2 += m_csX; if(m_csBulbPower != _T("")){ m_csTitle2 += m_csBulbPower; if(m_bHasW && m_csX == _T("x")) m_csTitle2 += _T("w"); else if(m_bHasW && m_csX == _T("X")) m_csTitle2 += _T("W"); if(m_csLightType!=_T("")) m_csTitle2 += m_csX; } m_csTitle2 += m_csLightType; m_csTitle3 = m_csSetupHeight; if(m_csTitle3 == _T("") && m_nType == 0) m_csTitle3 = _T("-"); m_csTitle4 = m_csSetupMode; } double CLampDim::GetDimLength() { double nLen4, nLenRet(0); AcGePoint3d pMax, pMin; AcDbObjectId id = GetTextStyleId(m_csTextStyle); if(m_csTitle1 != _T("")){ AcDbText text1; text1.setPosition(m_ptIns); text1.setHeight(m_nTextHeight);//*DocGetPScale() text1.setTextString(m_csTitle1); text1.setTextStyle(id); text1.setWidthFactor(m_nWidthFactor); text1.setRotation(0); AcDbExtents extents; text1.getGeomExtents(extents); pMax = extents.maxPoint(); pMin = extents.minPoint(); m_nLen = fabs(pMax[0] - pMin[0]) + m_nTextHeight;//*DocGetPScale() nLenRet += m_nLen; } XPoint ptTmp, ptTmp2; if(m_csTitle2 != _T("") || m_csTitle3 != _T("-")){ ptTmp.x = m_ptIns.x + m_nLen; ptTmp.y = m_ptIns.y + m_nTextHeight;//*DocGetPScale() AcDbText text2, text3; text2.setPosition(m_ptIns); text2.setHeight(m_nTextHeight);//*DocGetPScale() text2.setTextString(m_csTitle2); text2.setTextStyle(id); text2.setWidthFactor(m_nWidthFactor); text2.setRotation(0); AcDbExtents extents1; text2.getGeomExtents(extents1); pMax = extents1.maxPoint(); pMin = extents1.minPoint(); m_nLen2 = fabs(pMax[0] - pMin[0]); text3.setPosition(m_ptIns); text3.setHeight(m_nTextHeight);//*DocGetPScale() text3.setTextString(m_csTitle3); text3.setTextStyle(id); text3.setWidthFactor(m_nWidthFactor); text3.setRotation(0); AcDbExtents extents2; text3.getGeomExtents(extents2); pMax = extents2.maxPoint(); pMin = extents2.minPoint(); m_nLen3 = fabs(pMax[0] - pMin[0]); if(m_nLen3 > m_nLen2) nLenRet += (m_nLen3 + m_nTextHeight);//*DocGetPScale() else nLenRet += (m_nLen2 + m_nTextHeight);//*DocGetPScale() } if(m_csTitle4 != _T("")){ ptTmp.x = m_ptIns.x + m_nLen + m_nLen2 + m_nTextHeight;//*DocGetPScale() ptTmp.y = m_ptIns.y; AcDbText text4; text4.setPosition(ptTmp); text4.setHeight(m_nTextHeight);//*DocGetPScale() text4.setTextString(m_csTitle4); text4.setTextStyle(id); text4.setWidthFactor(m_nWidthFactor); text4.setRotation(0); AcDbExtents extents4; text4.getGeomExtents(extents4); pMax = extents4.maxPoint(); pMin = extents4.minPoint(); nLen4 = fabs(pMax[0] - pMin[0]); nLenRet += (nLen4 + m_nTextHeight);//*DocGetPScale() } m_nDimLen = nLenRet; return nLenRet; } // *********************************************************************** // BulbNum X Power X LightType // LightNum - EquipType ------------------------------SetupMode // SetupHeight //************************************************************************ Adesk::Boolean CLampDim::subWorldDraw(AcGiWorldDraw *pWd) { if(m_ptIns.x == 0 && m_ptIns.y == 0) return Adesk::kTrue; XPoint ptTmp, ptTmp2, ptInsTmp; AcGePoint3d pMax, pMin; ptInsTmp = m_ptIns; if(m_ptStart != AcGePoint3d(0,0,0)){ AcGePoint3d ptArray2[2] = {m_ptStart, m_ptIns,}; pWd->geometry().polyline(2, ptArray2); double dimlen = GetDimLength(); ptInsTmp.y -= m_nTextHeight/2;//*DocGetPScale() ptInsTmp.x += m_nTextHeight/2;//*DocGetPScale() if(m_ptIns.x < m_ptStart.x) ptInsTmp.x -= dimlen; } ptTmp = ptInsTmp; double nLen(0), nLen2(0), nLen3(0); AcDbObjectId id = GetTextStyleId(m_csTextStyle); if(m_csTitle1 != _T("")){ AcDbText text1; text1.setPosition(ptInsTmp); text1.setHeight(m_nTextHeight);//*DocGetPScale() text1.setTextString(m_csTitle1); text1.setTextStyle(id); text1.setWidthFactor(m_nWidthFactor); text1.setRotation(0); text1.worldDraw(pWd); AcDbExtents extents; text1.getGeomExtents(extents); pMax = extents.maxPoint(); pMin = extents.minPoint(); nLen = fabs(pMax[0] - pMin[0]) + m_nTextHeight;//*DocGetPScale() ptTmp.x = ptInsTmp.x + nLen; } if(m_csTitle2 == _T("") && m_csTitle3 == _T("") && m_csTitle4 == _T("")) return Adesk::kTrue; if(m_csTitle2 != _T("") || m_csTitle3 != _T("-")){ AcDbText text2, text3; text2.setPosition(ptInsTmp); text2.setHeight(m_nTextHeight);//*DocGetPScale() text2.setTextString(m_csTitle2); text2.setTextStyle(id); text2.setWidthFactor(m_nWidthFactor); text2.setRotation(0); AcDbExtents extents1; text2.getGeomExtents(extents1); pMax = extents1.maxPoint(); pMin = extents1.minPoint(); nLen2 = fabs(pMax[0] - pMin[0]); text3.setPosition(ptInsTmp); text3.setHeight(m_nTextHeight);//*DocGetPScale() text3.setTextString(m_csTitle3); text3.setTextStyle(id); text3.setWidthFactor(m_nWidthFactor); text3.setRotation(0); AcDbExtents extents2; text3.getGeomExtents(extents2); pMax = extents2.maxPoint(); pMin = extents2.minPoint(); nLen3 = fabs(pMax[0] - pMin[0]); if(nLen3 > nLen2){ nLen2 = nLen3; ptTmp.x = ptInsTmp.x + nLen; ptTmp.y = ptInsTmp.y - m_nTextHeight;//*DocGetPScale() text3.setPosition(ptTmp); text3.worldDraw(pWd); ptTmp.x = ptInsTmp.x + nLen + nLen2 / 2 - nLen3 / 2; ptTmp.y = ptInsTmp.y + m_nTextHeight;//*DocGetPScale() text2.setPosition(ptTmp); text2.worldDraw(pWd); } else{ ptTmp.y = ptInsTmp.y + m_nTextHeight;//*DocGetPScale() text2.setPosition(ptTmp); text2.worldDraw(pWd); ptTmp.x = ptInsTmp.x + nLen + nLen2 / 2 - nLen3 / 2; ptTmp.y = ptInsTmp.y - m_nTextHeight;//*DocGetPScale() text3.setPosition(ptTmp); text3.worldDraw(pWd); } if(m_csTitle3 != _T("") || (m_ptStart != AcGePoint3d(0,0,0))){ ptTmp.x = ptInsTmp.x + nLen - m_nTextHeight/2;//*DocGetPScale() ptTmp.y = ptInsTmp.y + m_nTextHeight/2; //*DocGetPScale() ptTmp2.x = ptTmp.x + nLen2 + m_nTextHeight; //*DocGetPScale() ptTmp2.y = ptTmp.y; AcGePoint3d ptArray[2] = {ptTmp, ptTmp2,}; pWd->geometry().polyline(2, ptArray); } } if(m_csTitle4 != _T("")){ ptTmp.x = ptInsTmp.x + nLen + nLen2 + m_nTextHeight;//*DocGetPScale() ptTmp.y = ptInsTmp.y; AcDbText text4; text4.setPosition(ptTmp); text4.setHeight(m_nTextHeight);//*DocGetPScale() text4.setTextString(m_csTitle4); text4.setTextStyle(id); text4.setWidthFactor(m_nWidthFactor); text4.setRotation(0); text4.worldDraw(pWd); } return Adesk::kTrue; } Acad::ErrorStatus CLampDim::subGetGripPoints(AcGePoint3dArray& gripPoints, AcDbIntArray& osnapModes, AcDbIntArray& geomIds) const { assertReadEnabled(); gripPoints.append(m_ptIns); gripPoints.append(m_ptStart); return Acad::eOk; } Acad::ErrorStatus CLampDim::subMoveGripPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset) { if (indices.length()== 0 || offset.isZeroLength()) return Acad::eOk; //that's easy :-) assertWriteEnabled(); if (indices.length() > 1){ return Acad::eOk; } if (indices[0] == 0) { m_ptIns += offset; return Acad::eOk; } else if (indices[0] == 1) { m_ptStart += offset; return Acad::eOk; } return Acad::eOk; } Acad::ErrorStatus CLampDim::subTransformBy(const AcGeMatrix3d& xform) { assertWriteEnabled(); m_ptIns.transformBy(xform); if(m_ptStart != AcGePoint3d(0,0,0)) m_ptStart.transformBy(xform); return Acad::eOk; } Acad::ErrorStatus CLampDim::dwgOutFields(AcDbDwgFiler* filer) const { assertReadEnabled(); Acad::ErrorStatus es; if ((es = AcDbEntity::dwgOutFields(filer)) != Acad::eOk) { return es; } Adesk::Int16 version = 1; Adesk::Int16 val = m_nNum; Adesk::Int16 type = m_nType; filer->writeItem(version); filer->writePoint3d(m_ptStart); filer->writePoint3d(m_ptIns); filer->writeBool(m_bHasW); filer->writeDouble(m_nTextHeight); filer->writeDouble(m_nWidthFactor); filer->writeDouble(m_nDimLen); filer->writeInt16(val); filer->writeInt16(type); filer->writeString((LPCTSTR)m_csTextStyle); filer->writeString((LPCTSTR)m_csSpec); filer->writeString((LPCTSTR)m_csBulbNum); filer->writeString((LPCTSTR)m_csBulbPower); filer->writeString((LPCTSTR)m_csSetupHeight); filer->writeString((LPCTSTR)m_csSetupMode); filer->writeString((LPCTSTR)m_csLightType); filer->writeString((LPCTSTR)m_csX); return filer->filerStatus(); } Acad::ErrorStatus CLampDim::dwgInFields(AcDbDwgFiler* filer) { assertWriteEnabled(); Acad::ErrorStatus es; if ((es = AcDbEntity::dwgInFields(filer)) != Acad::eOk) { return es; } // Object Version - must always be the first item. // Adesk::Int16 version; AcGePoint3d ptTmp; Adesk::Int16 val; filer->readItem(&version); if (version > 1) return Acad::eMakeMeProxy; switch (version) { case 1: { filer->readPoint3d(&m_ptStart); filer->readPoint3d(&m_ptIns); filer->readBool(&m_bHasW); filer->readDouble(&m_nTextHeight); filer->readDouble(&m_nWidthFactor); filer->readDouble(&m_nDimLen); filer->readInt16(&val); m_nNum = val; filer->readInt16(&val); m_nType = val; XString xsContent; ReadString(filer, xsContent); m_csTextStyle = (const TCHAR*)xsContent; ReadString(filer, xsContent); m_csSpec = (const TCHAR*)xsContent; ReadString(filer, xsContent); m_csBulbNum = (const TCHAR*)xsContent; ReadString(filer, xsContent); m_csBulbPower = (const TCHAR*)xsContent; ReadString(filer, xsContent); m_csSetupHeight = (const TCHAR*)xsContent; ReadString(filer, xsContent); m_csSetupMode = (const TCHAR*)xsContent; ReadString(filer, xsContent); m_csLightType = (const TCHAR*)xsContent; ReadString(filer, xsContent); m_csX = (const TCHAR*)xsContent; break; } default: assert(false); } // if(m_nTextHeight > DocGetPScale()) // m_nTextHeight = m_nTextHeight/DocGetPScale(); if(m_nTextHeight < 10) m_nTextHeight = m_nTextHeight * 100; InitData(); return filer->filerStatus(); } Acad::ErrorStatus CLampDim::subExplode(AcDbVoidPtrArray& entitySet) const { assertReadEnabled(); if(m_ptIns == AcGePoint3d(0,0,0)) return Acad::eOk; XPoint ptTmp, ptTmp2, ptInsTmp; ptInsTmp = m_ptIns; double nLen(0), nLen2(0), nLen3(0); AcDbObjectId idLayer=layerId(); if(m_ptStart != AcGePoint3d(0,0,0)){ AcDbLine *Line = new AcDbLine; Line->setLayer(idLayer); Line->setStartPoint(m_ptStart); Line->setEndPoint(m_ptIns); entitySet.append(Line); ptInsTmp.y -= m_nTextHeight/2;//*DocGetPScale() ptInsTmp.x += m_nTextHeight/2;//*DocGetPScale() if(m_ptIns.x < m_ptStart.x) ptInsTmp.x -= m_nDimLen; } AcGePoint3d pMax, pMin; AcDbObjectId id = GetTextStyleId(m_csTextStyle,database()); if(m_csTitle1 != ""){ AcDbText *text1 = new AcDbText; text1->setPosition(ptInsTmp); text1->setLayer(idLayer); text1->setHeight(m_nTextHeight);//*DocGetPScale() text1->setTextString(m_csTitle1); text1->setTextStyle(id); text1->setWidthFactor(m_nWidthFactor); text1->setRotation(0); entitySet.append(text1); AcDbExtents extents; text1->getGeomExtents(extents); pMax = extents.maxPoint(); pMin = extents.minPoint(); nLen = fabs(pMax[0] - pMin[0]) + m_nTextHeight;//*DocGetPScale() } if(m_csTitle2 == "" && m_csTitle3 == "" && m_csTitle4 == "") return Acad::eOk; if(m_csTitle2 != "" || m_csTitle3 != "-"){ ptTmp.x = ptInsTmp.x + nLen; AcDbText *text2 = new AcDbText; AcDbText *text3 = new AcDbText; text2->setPosition(ptInsTmp); text2->setLayer(idLayer); text2->setHeight(m_nTextHeight);//*DocGetPScale() text2->setTextString(m_csTitle2); text2->setTextStyle(id); text2->setWidthFactor(m_nWidthFactor); text2->setRotation(0); AcDbExtents extents1; text2->getGeomExtents(extents1); pMax = extents1.maxPoint(); pMin = extents1.minPoint(); nLen2 = fabs(pMax[0] - pMin[0]); text3->setPosition(ptInsTmp); text3->setLayer(idLayer); text3->setHeight(m_nTextHeight);//*DocGetPScale() text3->setTextString(m_csTitle3); text3->setTextStyle(id); text3->setWidthFactor(m_nWidthFactor); text3->setRotation(0); AcDbExtents extents2; text3->getGeomExtents(extents2); pMax = extents2.maxPoint(); pMin = extents2.minPoint(); nLen3 = fabs(pMax[0] - pMin[0]); if(nLen3 > nLen2){ nLen2 = nLen3; ptTmp.x = ptInsTmp.x + nLen; ptTmp.y = ptInsTmp.y - m_nTextHeight;//*DocGetPScale() text3->setPosition(ptTmp); entitySet.append(text3); ptTmp.x = ptInsTmp.x + nLen + nLen2 / 2 - nLen3 / 2; ptTmp.y = ptInsTmp.y + m_nTextHeight;//*DocGetPScale() text2->setPosition(ptTmp); entitySet.append(text2); } else{ ptTmp.y = ptInsTmp.y + m_nTextHeight;//*DocGetPScale() text2->setPosition(ptTmp); entitySet.append(text2); ptTmp.x = ptInsTmp.x + nLen + nLen2 / 2 - nLen3 / 2; ptTmp.y = ptInsTmp.y - m_nTextHeight;//*DocGetPScale() text3->setPosition(ptTmp); entitySet.append(text3); } if(m_csTitle3 != "" || (m_ptStart != AcGePoint3d(0,0,0))){ ptTmp.x = ptInsTmp.x + nLen - m_nTextHeight/2;//*DocGetPScale() ptTmp.y = ptInsTmp.y + m_nTextHeight/2;//*DocGetPScale() ptTmp2.x = ptTmp.x + nLen2 + m_nTextHeight;//*DocGetPScale() ptTmp2.y = ptTmp.y; AcDbLine *Line = new AcDbLine; Line->setLayer(idLayer); Line->setStartPoint(ptTmp); Line->setEndPoint(ptTmp2); entitySet.append(Line); } } if(m_csTitle4 != ""){ ptTmp.x = ptInsTmp.x + nLen + nLen2 + m_nTextHeight;//*DocGetPScale() ptTmp.y = ptInsTmp.y; AcDbText *text4 = new AcDbText; text4->setPosition(ptTmp); text4->setLayer(idLayer); text4->setHeight(m_nTextHeight);//*DocGetPScale() text4->setTextString(m_csTitle4); text4->setTextStyle(id); text4->setWidthFactor(m_nWidthFactor); text4->setRotation(0); entitySet.append(text4); } return Acad::eOk; } void InitLampDim(BOOL bTrue) { if(bTrue) { CLampDim::rxInit(); } else { deleteAcRxClass(CLampDim::desc()); } }