// Wire.cpp: implementation of the CWire class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "TApi.h" #include "TelDef.h" //#include #include "Wire.h" #include "TelDef.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CString GetWireRemarkByInfo(const TCHAR* szCaption, const TCHAR* szVal) { CString csVal = szVal; CString csCaption = szCaption; CodeBase db; int Number; CString csType, csValue, csRemark; XString fullFile; if(!FindFile(_T("DataStore.dbf"), fullFile)) { Callme(_T("对不起,没有发现DataStore.dbf文件!")); return CString(); } XDbfTable *pTable = db.Open(fullFile); if(!pTable) { Callme(_T("DataStore.dbf文件出错!")); return CString(); } pTable->MoveFirst(); while(!pTable->IsEOF()) { GET_FIELD(pTable, _T("TypeNumber"), Number); GET_FIELD(pTable, _T("TypeName"), csType); GET_FIELD(pTable, _T("TypeValue"), csValue); GET_FIELD(pTable, _T("REMARK"), csRemark); if(csType == csCaption && Number == 0 && csValue == csVal){ return csRemark; } pTable->MoveNext(); } return CString(); } CWire::CWire() { } CWire::CWire(Entity ent) { m_ent = ent; GetWire2Point(ent, m_ptStart, m_ptEnd); m_csType = ReadXdata(m_ent, _T("ltype")); //导线型号 m_csRadius = ReadXdata(m_ent, _T("ldm")); //穿管直径 m_csMode = ReadXdata(m_ent, _T("lmeth")); //配线方式 m_csPlace = ReadXdata(m_ent, _T("linst")); //敷设部位 m_csArea = ReadXdata(m_ent, _T("lnoar")); //导线规格 m_csNorm = ReadXdata(m_ent, _T("lnorm")); m_csName = ReadXdata(m_ent, _T("linenum")); //回路编号 if(m_csType == _T("") && m_csArea == _T("") && m_csMode == _T("") && m_csPlace == _T("")){ m_bIsInfoEmpty = TRUE; return; } m_bIsInfoEmpty = FALSE; if(m_csNorm == _T("0") && m_csType !=_T("")) m_csDim = m_csType; else if(m_csNorm == _T("1") && m_csType !=_T("")) m_csDim = _T("ZR-") + m_csType; else if(m_csNorm == _T("2") && m_csType !=_T("")) m_csDim = _T("NH-") + m_csType; if(m_csDim != _T("")) m_csDim += _T("-"); m_csDimSimple = m_csDim + m_csArea; //add comment liaoy 170725 最好的方法是调用TDbWireDimNew::MergeText(m_csDim,m_csArea,m_csMode,m_csRadius,m_csPlace); if(m_csArea!=_T("") && m_csMode !=_T("") && m_csRadius != _T("") && m_csPlace != _T("")) m_csDim = m_csDim + m_csArea + _T("-") + m_csMode + m_csRadius + _T("-") + m_csPlace; else if(m_csArea!=_T("") && m_csMode !=_T("") && m_csRadius != _T("") && m_csPlace == _T("")) m_csDim = m_csDim + m_csArea + _T("-") + m_csMode + m_csRadius; else if(m_csArea==_T("") && m_csMode !=_T("") && m_csRadius != _T("") && m_csPlace != _T("")) m_csDim = m_csDim + m_csMode + m_csRadius + _T("-") + m_csPlace; else if(m_csArea!=_T("") && m_csMode ==_T("") && m_csRadius == _T("") && m_csPlace == _T("")) m_csDim = m_csDim + m_csArea; else if(m_csArea!=_T("") && m_csMode ==_T("") && m_csRadius == _T("") && m_csPlace != _T("")) m_csDim = m_csDim + m_csArea + _T("-") + m_csPlace; else if(m_csArea!=_T("") && m_csMode !=_T("") && m_csRadius == _T("") && m_csPlace != _T("")) m_csDim = m_csDim + m_csArea + _T("-") + m_csMode + _T("-") + m_csPlace; else if(m_csArea ==_T("") && m_csMode !=_T("") && m_csRadius == _T("") && m_csPlace != _T("")) m_csDim = m_csDim + m_csMode + _T("-") + m_csPlace; else if(m_csArea ==_T("") && m_csMode !=_T("") && m_csRadius != _T("") && m_csPlace == _T("")) m_csDim = m_csDim + m_csMode + m_csRadius; //comment end m_csDim2 = m_csDim; if(m_csName != _T("")) m_csDim = m_csName + _T("-") + m_csDim; } CWire::~CWire() { } void CWire::GetTipInfo(DList &lstInfo) { if(m_bIsInfoEmpty){ CBlockStruct *pInfo = new CBlockStruct(); pInfo->m_csRecord = _T("此导线"); pInfo->m_csDesName = _T("无信息"); lstInfo.Append(pInfo); return; } CBlockStruct *pInfo = new CBlockStruct(); pInfo->m_csRecord = _T("回路编号"); pInfo->m_csDesName = m_csName; lstInfo.Append(pInfo); CBlockStruct *pInfo1 = new CBlockStruct(); pInfo1->m_csRecord = _T("导线型号"); if(m_csNorm == _T("1")) m_csType = _T("阻燃") + m_csType; else if(m_csNorm == _T("2")) m_csType = _T("耐火") + m_csType; pInfo1->m_csDesName = m_csType; lstInfo.Append(pInfo1); CBlockStruct *pInfo2 = new CBlockStruct(); pInfo2->m_csRecord = _T("配线方式"); m_csMode += GetWireRemarkByInfo(_T("配线方式"), m_csMode); pInfo2->m_csDesName = m_csMode; lstInfo.Append(pInfo2); CBlockStruct *pInfo3 = new CBlockStruct(); pInfo3->m_csRecord = _T("敷设部位"); m_csPlace += GetWireRemarkByInfo(_T("敷设部位"), m_csPlace); pInfo3->m_csDesName = m_csPlace; lstInfo.Append(pInfo3); CBlockStruct *pInfo4 = new CBlockStruct(); pInfo4->m_csRecord = _T("导线规格"); pInfo4->m_csDesName = m_csArea; lstInfo.Append(pInfo4); CBlockStruct *pInfo5 = new CBlockStruct(); pInfo5->m_csRecord = _T("穿管直径"); pInfo5->m_csDesName = m_csRadius; lstInfo.Append(pInfo5); } CString CWire::GetWireLayer() { CString csLayer; TCHAR szLayer[256]=_T(""); m_ent.GetData(8, szLayer); csLayer = szLayer; return csLayer; } CString CWire::GetLineType() { CString csLineType; TCHAR szLineType[256]=_T(""); m_ent.GetData(6, szLineType); csLineType = szLineType; return csLineType; } double CWire::GetLineThick() { if(m_ent.Is(_T("LINE")) || m_ent.Is(_T("ARC"))) return 0; double nLineThick; m_ent.GetData(40, &nLineThick); return nLineThick; } void CWire::GetWireFPick(PickSet &ss, RBList &rbMask) { if(m_ent.Is(_T("LINE"))){ XLine line(m_ent); AssureInCurrentView(line.StartPoint(), line.EndPoint()); line.TransUCS(Groups(0),Groups(1)); // 把 UCS 转为 WCS RBList rbPoint = ads_buildlist(RT3DPOINT, &line.StartPoint(), RT3DPOINT, &line.EndPoint(), NULL); ss.Get(_T("F"), rbPoint, NULL, rbMask); } else if(m_ent.Is(_T("ARC"))){ XArc arc(m_ent); XCurveSegment seg; seg = arc; XPoly2D xPline; seg.AsPoly2D(xPline); XPoint pt1, pt2; pt1 = *xPline[0]; xPline.Length(); pt2 = *xPline[xPline.Length()-1]; AssureInCurrentView(pt1, pt2); xPline.TransUCS(Groups(0),Groups(1)); // 把 UCS 转为 WCS RBList rbPoint = xPline.Polygon(); ss.Get(_T("F"), rbPoint, NULL, rbMask); } else{ XPoly2D xPline(m_ent); XPoint pt1, pt2; pt1 = *xPline[0]; xPline.Length(); pt2 = *xPline[xPline.Length()-1]; AssureInCurrentView_New(pt1, pt2); xPline.TransUCS(Groups(0),Groups(1)); // 把 UCS 转为 WCS RBList rbPoint = xPline.Polygon(); ss.Get(_T("F"), rbPoint, NULL, rbMask); } } void CWire::DrawLineWire(XPoint ptStart, XPoint ptEnd, const TCHAR* szLayer, const TCHAR* szLineType, double nWidth) { CString csLayer = szLayer; InitLayer(szLayer); XPushVarStr clayer(_T("CLAYER"), szLayer); CString csLineType = szLineType; if(csLineType != _T("BYLAYER") && csLineType != _T("")){ double nLtScale; xg_getvar(_T("LTSCALE"), &nLtScale); if(nLtScale < 100.0){ xg_setvar(_T("LTSCALE"), 1000); } } if(nWidth < 0.001){ AcDbLine *pline = new AcDbLine; pline->setStartPoint(ptStart); pline->setEndPoint(ptEnd); CString csLineType = szLineType; if(csLineType != _T("BYLAYER") && csLineType != _T("")){ if(AddLineType(szLineType)) pline->setLinetype(szLineType); } PostToDb(pline); pline->close(); } else{ AcDbPolyline *pll = new AcDbPolyline; pll->addVertexAt(0, ptStart); pll->addVertexAt(1, ptEnd); pll->setConstantWidth(nWidth); pll->setElevation(ptStart.z); if(csLineType != _T("BYLAYER") && csLineType != _T("")){ if(AddLineType(szLineType)) pll->setLinetype(szLineType); } PostToDb(pll); pll->close(); } Entity ent; ent.GetLast(); int iLayerIndex = 0; if(csLayer == LAY_WIRE_ILLUME) iLayerIndex = 0; else if(csLayer == LAY_WIRE_POWER) iLayerIndex = 1; else if(csLayer == LAY_WIRE_FIRE) iLayerIndex = 2; else if(csLayer == LAY_WIRE_WEAK) iLayerIndex = 3; else if(csLayer == LAY_WIRE_EMERG) iLayerIndex = 4; else if(csLayer == LAY_WIRE_TEL) iLayerIndex = 5; else if(csLayer == LAY_WIRE_BROAD) iLayerIndex = 6; else if(csLayer == LAY_WIRE_CTRL) iLayerIndex = 7; else if(csLayer == LAY_WIRE_SOURCE) iLayerIndex = 8; else return; WriteXdata(ent, _T("ltype"), (const TCHAR*)g_csWireDimType[iLayerIndex]); //导线型号 WriteXdata(ent, _T("ldm"), (const TCHAR*)g_csWireDimRadius[iLayerIndex]); //穿管直径 WriteXdata(ent, _T("lmeth"), (const TCHAR*)g_csWireDimMode[iLayerIndex]); //配线方式 WriteXdata(ent, _T("linst"), (const TCHAR*)g_csWireDimPlace[iLayerIndex]); //敷设部位 WriteXdata(ent, _T("lnoar"), (const TCHAR*)g_csWireDimArea[iLayerIndex]); //规格 WriteXdata(ent, _T("lnorm"), (const TCHAR*)Itoa(g_iWireDimNorm[iLayerIndex])); //规格 } void CWire::SetLineName(const TCHAR* szLineType) { if(!!m_ent) WriteXdata(m_ent, _T("linenum"), szLineType); } void CWire::SetLayer(const TCHAR* szNewLayer) { if(!m_ent) return; AcDbObjectId eId; if(m_ent.Is(_T("LINE"))){ AcDbEntity *pEnt = NULL; acdbGetObjectId(eId, m_ent); acdbOpenObject(pEnt, eId, AcDb::kForWrite); if(pEnt){ InitLayer(szNewLayer); pEnt->setLayer(szNewLayer); pEnt->setColorIndex(256); pEnt->close(); } } else{ AcDbPolyline *pEnt = NULL; acdbGetObjectId(eId, m_ent); acdbOpenObject(pEnt, eId, AcDb::kForWrite); if(pEnt){ InitLayer(szNewLayer); pEnt->setLayer(szNewLayer); double nWidth = g_nWireWidth[GetWireLayerIndex(szNewLayer)] * DocGetPScale(); pEnt->setConstantWidth(nWidth); pEnt->setColorIndex(256); pEnt->close(); } } } void CWire::SetColor(int iColor) { if(!m_ent) return; AcDbObjectId eId; AcDbEntity *pEnt = NULL; acdbGetObjectId(eId, m_ent); acdbOpenObject(pEnt, eId, AcDb::kForWrite); if(pEnt){ pEnt->setColorIndex(iColor); pEnt->close(); } } void CWire::SetWidth(double nWidth) { if(!m_ent) return; if(m_ent.Is(_T("LINE"))) return; AcDbObjectId eId; AcDbPolyline *pEnt = NULL; acdbGetObjectId(eId, m_ent); acdbOpenObject(pEnt, eId, AcDb::kForWrite); if(pEnt){ pEnt->setConstantWidth(nWidth); pEnt->close(); } } void CWire::SetInfo(const TCHAR* szType, const TCHAR* szMode, const TCHAR* szPlace, const TCHAR* szArea, const TCHAR* szNorm, const TCHAR* szRadius) { if(!m_ent) return; WriteXdata(m_ent, _T("ltype"), szType); //导线型号 WriteXdata(m_ent, _T("ldm"), szRadius); //穿管直径 WriteXdata(m_ent, _T("lmeth"), szMode); //配线方式 WriteXdata(m_ent, _T("linst"), szPlace); //敷设部位 WriteXdata(m_ent, _T("lnoar"), szArea); //规格 WriteXdata(m_ent, _T("lnorm"), szNorm); // } extern AcDbObjectId GetLinetypeIdFromString2(const TCHAR* pStr); void CWire::SetLineType(const TCHAR* szLineType) { AcDbObjectId id=LoadTgLineType(szLineType); OPENOBJ_BEGIN(m_ent, AcDb::kForWrite, AcDbEntity, pEnt); if(pEnt){ pEnt->setLinetype(id); } OPENOBJ_END(); } void CWire::GetBlkByLineWire(Entity& entBlk1, Entity& entBlk2) { RBList rbMask = ads_buildlist( -4, _T(""), -4, _T(""), -4, _T("or>"), NULL); PickSet ss(SS_FREE); GetPointPickSet(Wcs2Ucs(m_ptStart), ss, rbMask, 2); if(ss.Length() == 1) entBlk1 = ss[0L]; ss.Free(); GetPointPickSet(Wcs2Ucs(m_ptEnd), ss, rbMask, 2); if(ss.Length() == 1) entBlk2 = ss[0L]; } BOOL CWire::GetWireAllArea(XStringList &lstArea) { if(m_csArea == _T("")) return FALSE; CString csTmp = m_csArea; while(1){ int len = csTmp.GetLength(); int idx = csTmp.Find(_T("+"), 0); if(idx < 0){ lstArea.Append(tstrnew(csTmp)); break; } CString csLeft, csRight; csLeft = csTmp.Left(idx); csRight = csTmp.Right(len - idx - 1); csTmp = csRight; lstArea.Append(tstrnew(csLeft)); } return TRUE; } int CWire::GetWireNum() { int ret = 0; if(m_csArea == _T("")) return ret; XStringList lstArea; if(!GetWireAllArea(lstArea)) return ret; int length = lstArea.Length(); for(int i=0;isetStartPoint(ptStart); pEnt->setEndPoint(ptEnd); pEnt->close(); } } else{ XPoly2D xPline(m_ent); if(xPline.Length() > 2) return; AcDbPolyline *pEnt = NULL; acdbOpenObject(pEnt, eId, AcDb::kForWrite); if(pEnt){ pEnt->setPointAt(0, ptStart); pEnt->setPointAt(1, ptEnd); pEnt->close(); } } } //*************************************************************************************** //*************************************************************************************** //TWireEdJig::TWireEdJig(XPoint pt1, XPoint pt2, int iFixMode) //{ // m_bIsArc = FALSE; // m_pDrawEnt = NULL; // m_pDrawLine = NULL; // m_iFixMode = iFixMode; // m_ptStart = pt1; // m_ptEnd = pt2; // XLine line(pt1, pt2, 1); // XPoint ptCen; // line.MidPoint(ptCen); // m_pline = new AcDbPolyline; // m_pline->addVertexAt(0, m_ptStart); // m_pline->addVertexAt(1, ptCen); // m_pline->addVertexAt(2, m_ptEnd); // // XArc arc(m_ptStart, ptCen, m_ptEnd); // m_pDrawEnt = new AcDbArc(arc.center, arc.radius, arc.startAngle, arc.endAngle); // TWireEdJig::TWireEdJig(XPoint pt1, XPoint pt2) { m_nLockAng = 0; // m_iFixMode = -1; m_pDrawLine = NULL; // m_pline = NULL; m_bIsArc = TRUE; m_ptStart = pt1; m_ptEnd = pt2; XLine line(pt1, pt2, 1); XPoint ptCen; line.MidPoint(ptCen); XArc arc(m_ptStart, ptCen, m_ptEnd); m_pDrawEnt = new AcDbArc(arc.GetCenterPt(), arc.GetRadius(), arc.GetStarAngle(), arc.GetEndAngle()); AcCmColor color; color.setColorIndex(1); // m_pline = new AcDbPolyline; // m_pline->addVertexAt(0, m_ptStart); // m_pline->addVertexAt(1, ptCen); // m_pline->addVertexAt(2, m_ptEnd); // m_pline->setColor(color); // m_pline->setClosed(Adesk::kFalse); m_pDrawEnt->setColor(color); } TWireEdJig::TWireEdJig(XPoint pt) { m_nLockAng = 0; // m_iFixMode = -1; m_pDrawEnt = NULL; // m_pline = NULL; m_bIsArc = FALSE; m_ptStart = pt; m_pDrawLine = new AcDbLine(pt,pt); AcCmColor color; color.setColorIndex(1); m_pDrawLine->setColor(color); } TWireEdJig::~TWireEdJig() { if(m_pDrawEnt) delete m_pDrawEnt; if(m_pDrawLine) delete m_pDrawLine; // if(m_pline) // delete m_pline; } AcEdJig::DragStatus TWireEdJig::GetPoint(XPoint &pt) { // if(m_iFixMode > -1) // return acquirePoint(pt); if(m_bIsArc){ XPoint ptBase = m_ptStart; XLine line(m_ptStart, m_ptEnd, 1); line.MidPoint(ptBase); AcGePoint3d ptBase2 = asPnt3d(ptBase); return acquirePoint(pt, ptBase2); } if(!m_ptRef) return acquirePoint(pt); else return acquirePoint(pt, m_ptRef); } void TWireEdJig::SetStartPoint(XPoint pt) { if(m_bIsArc) return; m_ptStart = pt; m_pDrawLine->setStartPoint(m_ptStart); } int TWireEdJig::DoIt(int *keyIndex) { int nRet = TSymbEdJig::DoIt(keyIndex); return nRet; } XPoint TWireEdJig::GetCorrectPt() { XPoint ptTmp = m_ptResult; if(m_nLockAng > 0){ m_ptRef = XPoint(); XPoint ptTmp2 = m_ptStart; ptTmp2.z = 0; double nAngle = ads_angle(ptTmp2, m_ptResult) - m_nLockAng; double nDist = ads_distance(ptTmp2, m_ptResult); if(nAngle > PI/2 && nAngle < PI/2*3) ads_polar(m_ptStart, m_nLockAng, -nDist, ptTmp); else ads_polar(m_ptStart, m_nLockAng, nDist, ptTmp); } return ptTmp; } // 更新实体数据 Adesk::Boolean TWireEdJig::update() { Adesk::Boolean bRet=Adesk::kTrue; ptTmp = m_ptResult; if(m_bIsArc){ XArc arc(m_ptStart, m_ptResult, m_ptEnd); m_pDrawEnt->setCenter(arc.GetCenterPt()); m_pDrawEnt->setStartAngle(arc.GetStarAngle()); m_pDrawEnt->setEndAngle(arc.GetEndAngle()); m_pDrawEnt->setRadius(arc.GetRadius()); } else{ if(m_nLockAng > 0){ ptTmp = GetCorrectPt(); m_pDrawLine->setEndPoint(ptTmp); } else m_pDrawLine->setEndPoint(m_ptResult); } return bRet; } //Adesk::Boolean TWireEdJig::update() //{ // Adesk::Boolean bRet=Adesk::kTrue; // ptTmp = m_ptResult; // if(m_iFixMode > -1){ // double maxX, maxY, minX, minY; // maxX = m_ptStart.x > m_ptEnd.x ? m_ptStart.x : m_ptEnd.x; // maxY = m_ptStart.y > m_ptEnd.y ? m_ptStart.y : m_ptEnd.y; // minX = m_ptStart.x < m_ptEnd.x ? m_ptStart.x : m_ptEnd.x; // minY = m_ptStart.y < m_ptEnd.y ? m_ptStart.y : m_ptEnd.y; // if(m_ptResult.x > maxX) // ptTmp.x = maxX; // if(m_ptResult.y > maxY) // ptTmp.y = maxY; // if(m_ptResult.x < minX) // ptTmp.x = minX; // if(m_ptResult.y < minY) // ptTmp.y = minY; // } // if(m_iFixMode == 0){ // m_pline->setPointAt(0, m_ptStart); // m_pline->setPointAt(1, ptTmp); // m_pline->setPointAt(2, m_ptEnd); // } // else if(m_iFixMode == 1){ // // XLine xline(m_ptStart, m_ptEnd, 1); // ads_polar(ptTmp, 0, 1000, ptOnx); // ads_polar(ptTmp, PI/2, 1000, ptOny); // XLine line1(ptTmp, ptOnx, 0); // XLine line2(ptTmp, ptOny, 0); // line1.Intersection(xline, ptOnx); // line2.Intersection(xline, ptOny); // m_pline->setPointAt(0, ptOny); // m_pline->setPointAt(1, ptTmp); // m_pline->setPointAt(2, ptOnx); // } // else if(m_bIsArc){ // XArc arc(m_ptStart, m_ptResult, m_ptEnd); // m_pDrawEnt->setCenter(arc.center); // m_pDrawEnt->setStartAngle(arc.startAngle); // m_pDrawEnt->setEndAngle(arc.endAngle); // m_pDrawEnt->setRadius(arc.radius); // } // else{ // m_pDrawLine->setEndPoint(m_ptResult); // } // return bRet; //} AcDbEntity* TWireEdJig::entity() const { // if(m_iFixMode > -1) // return (AcDbEntity *)m_pline; if(m_bIsArc) return (AcDbEntity *)m_pDrawEnt; else return (AcDbEntity *)m_pDrawLine; }