Files
envi-code/SourceCode/Code2026/PIDLineCmd/KTFitting.cpp
T
2026-09-28 15:28:50 +08:00

836 lines
23 KiB
C++

#include "stdafx.h"
#include "KTFitting.h"
#include "Resource.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
KTFitting::KTFitting()
{
m_pPipeParam = NULL;//管子参数
m_pInitXData = NULL;//初始化数据
m_bPipeParamCreated = FALSE;
}
KTFitting::~KTFitting()
{
if (m_bPipeParamCreated && m_pPipeParam != NULL)
{
delete m_pPipeParam;
}
}
void KTFitting::SetPipeParam(WPipe::PipeParam* pPipePar,BOOL bCopyFrom)
{
if (bCopyFrom)
{
m_pPipeParam = new WPipe::PipeParam;
memset(m_pPipeParam,0,sizeof(WPipe::PipeParam));
*m_pPipeParam = *pPipePar;
}
else
{
m_pPipeParam = pPipePar;
}
m_bPipeParamCreated = bCopyFrom;
}
WPipe::PipeParam* KTFitting::GetPipeParam()
{
return m_pPipeParam;
}
void KTFitting::SetInitXData(AecDbObjXDataMap* pInitXData)
{
m_pInitXData = pInitXData;
}
AecDbObjXDataMap* KTFitting::GetInitXData()
{
return m_pInitXData;
}
void KTFitting::GetName(CString& sName)
{
Fitting eType = KindOf();
switch(eType)
{
case KTFitting::kPipe:
{
sName = _T("直管");
break;
}
case KTFitting::kElbow:
{
sName = _T("弯头");
break;
}
case KTFitting::kReducer:
{
sName = _T("变径");
break;
}
case KTFitting::kCap:
{
sName = _T("封头");
break;
}
case KTFitting::kTee:
{
sName = _T("三通");
break;
}
case KTFitting::kCross:
{
sName = _T("四通");
break;
}
case KTFitting::kLateral:
{
sName = _T("三通");
break;
}
case KTFitting::kWye:
{
sName = _T("三通");
break;
}
default:
break;
}
}
void KTFitting::SetNormal(const AcGeVector3d& vtNormal)
{
}
AcDbCurve* KTFitting::CreateCurve(AcDbEntity* pEnt,AcRxClass* pRxClass)
{
if (pRxClass == NULL) return NULL;
if (pEnt == NULL)
{
pEnt = (AcDbEntity*)pRxClass->create();
}
else
{
if (pEnt->isA() != pRxClass)
{
delete pEnt;
pEnt = (AcDbEntity*)pRxClass->create();
}
}
return AcDbCurve::cast(pEnt);
}
BOOL KTFitting::FormatDot(AcGePoint3d& ptGeCen, double dPlotWidth,AcDbPolyline* pDot,AcGePlane& plane,const AcGeVector3d& vtNorm)
{
if (pDot == NULL) return FALSE;
double dDotRadius = dPlotWidth * 0.5;
AcGePoint2d ptGeCenDot = ptGeCen.convert2d(plane);
AcGePoint2d ptGe[4];
double dBulge = tan(PI / 8.0);
ptGe[0] = ptGeCenDot + dDotRadius * AcGeVector2d::kYAxis;
ptGe[1] = ptGeCenDot + dDotRadius * AcGeVector2d::kXAxis;
ptGe[2] = ptGeCenDot - dDotRadius * AcGeVector2d::kYAxis;
ptGe[3] = ptGeCenDot - dDotRadius * AcGeVector2d::kXAxis;
if (4 == pDot->numVerts())
{
pDot->setPointAt(0,ptGe[0]);
pDot->setBulgeAt(0,-dBulge);
pDot->setPointAt(1,ptGe[1]);
pDot->setBulgeAt(1,-dBulge);
pDot->setPointAt(2,ptGe[2]);
pDot->setBulgeAt(2,-dBulge);
pDot->setPointAt(3,ptGe[3]);
pDot->setBulgeAt(3,-dBulge);
pDot->setConstantWidth(dPlotWidth);
pDot->setClosed(Adesk::kTrue);
pDot->setNormal(vtNorm);
}
else
{
pDot->reset(Adesk::kFalse,0);
pDot->addVertexAt(0,ptGe[0],-dBulge);
pDot->addVertexAt(1,ptGe[1],-dBulge);
pDot->addVertexAt(2,ptGe[2],-dBulge);
pDot->addVertexAt(3,ptGe[3],-dBulge);
pDot->setConstantWidth(dPlotWidth);
pDot->setClosed(Adesk::kTrue);
pDot->setNormal(vtNorm);
}
return TRUE;
}
BOOL KTFitting::FormatArc(AcDbArc* pArc,const AcGePoint3d& ptGe1,AcGePoint3d& ptGeMid,
const AcGePoint3d& ptGe2,AcGeVector3d& vtNormalOut)
{
AcGeCircArc3d circArc;
circArc.set(ptGe1,ptGeMid,ptGe2);
AcGeVector3d vtNormal = circArc.normal();
if (vtNormal.isParallelTo(AcGeVector3d::kZAxis))
{
if (!vtNormal.isCodirectionalTo(AcGeVector3d::kZAxis))
{
vtNormal.negate();//相反
}
}
AcGePoint3d ptGeCen = circArc.center();
double dStartAngle = circArc.startAng();
double dEndAngle = circArc.endAng();
double dRadius = circArc.radius();
AcGeCircArc3d cir(ptGeCen,vtNormal,dRadius);
AcGePoint3d ptGeX;
ptGeX = cir.startPoint();
AcGeVector3d vtX = ptGeX - ptGeCen;
AcGeVector3d vt1 = ptGe1 - ptGeCen;
AcGeVector3d vt3 = ptGe2 - ptGeCen;
vtNormalOut = vtNormal;
double dAng1 = vtX.angleTo(vt1,vtNormal);
double dAng3 = vtX.angleTo(vt3,vtNormal);
if (pArc != NULL)
{
pArc->setStartAngle(dAng1);
pArc->setEndAngle(dAng3);
pArc->setCenter(ptGeCen);
pArc->setRadius(dRadius);
pArc->setNormal(vtNormalOut);
AcGePoint3d ptGeOn;
pArc->getClosestPointTo(ptGeMid,ptGeOn);
double dDis = ptGeOn.distanceTo(ptGeMid);
if (dDis > 1.e-3)
{
pArc->setStartAngle(dAng3);
pArc->setEndAngle(dAng1);
}
return TRUE;
}
return FALSE;
}
BOOL KTFitting::CreateCirBreakArc(AcDbCurve* pCurve,AcGePoint3d& ptGe3d,
AcGeVector3d& vtDir,double dBreakSpace,double dRadius,double dPlW)
{
if (dBreakSpace < 1.e-10) //圆
{
((AcDbCircle*)pCurve)->setCenter(ptGe3d);
((AcDbCircle*)pCurve)->setRadius(dRadius);
}
else
{
vtDir.normalize();
double dAng = PI / 6.0; //弯头的豁口为60
AcGeVector3d vtDir1 = vtDir;
vtDir1.rotateBy(dAng,AcGeVector3d::kZAxis);
AcGePoint3d ptGe1 = ptGe3d + dRadius * vtDir1;
vtDir1.rotateBy(-2.0 * dAng,AcGeVector3d::kZAxis);
AcGePoint3d ptGe3 = ptGe3d + dRadius * vtDir1;
AcGePoint3d ptGe2 = ptGe3d - dRadius * vtDir;
vtDir1 = AcGeVector3d::kZAxis;
KTFitting::FormatArc((AcDbArc*)pCurve,ptGe1,ptGe2,ptGe3,vtDir1);
}
return TRUE;
}
void KTFitting::WriteXData(AcDbEntity* pEnt)
{
AecDbObjXDataMap objXData;
objXData.SetAt(PIPE_D,m_pPipeParam->m_dD);
objXData.SetAt(PIPE_DSEL,(int)m_pPipeParam->m_eD);
objXData.SetAt(PIPE_DN,m_pPipeParam->m_dDN);
objXData.SetAt(PIPE_OD,m_pPipeParam->m_dOD);
objXData.SetAt(PIPE_INTERFACED,m_pPipeParam->m_dInterfaceD);
objXData.SetAt(PIPE_THICK,m_pPipeParam->m_dThick);
objXData.SetAt(PIPE_EL,m_pPipeParam->m_dEl);
objXData.SetAt(PIPE_RATIO,m_pPipeParam->m_dRRatio);
objXData.SetAt(PIPE_INTERFACEL,m_pPipeParam->m_dInterfaceL);
objXData.SetAt(PIPE_INTERFACED2,m_pPipeParam->m_dInterfaceD2);
objXData.SetAt(PIPE_INTERFACEL2,m_pPipeParam->m_dInterfaceL2);
//objXData.SetAt(PIPE_ZONE,m_pPipeParam->m_pszZone);
//objXData.SetAt(PIPE_EAPP,(int)m_pPipeParam->m_eAPP);
//objXData.SetAt(PIPE_MEDIA,m_pPipeParam->m_pszMedia);
//objXData.SetAt(PIPE_LEVEL,m_pPipeParam->m_pszLevel);
//objXData.SetAt(PIPE_NO,m_pPipeParam->m_pszNo);
//objXData.SetAt(PIPE_DESCR,m_pPipeParam->m_pszDesc);
//objXData.SetAt(PIPE_SPEC,m_pPipeParam->m_pszSpec);
//objXData.SetAt(PIPE_LINENO,m_pPipeParam->m_pszLineNo);
objXData.SetAt(PIPE_ELBASE,(int)m_pPipeParam->m_eElBase);
objXData.SetAt(PIPE_REDUCER,(int)m_pPipeParam->m_eRed);
objXData.SetAt(PIPE_REDECEN,AcGePoint3d(m_pPipeParam->m_vtECCen.x,m_pPipeParam->m_vtECCen.y,m_pPipeParam->m_vtECCen.z));
//objXData.SetAt(PIPE_CAP,(int)m_pPipeParam->m_eCAP);
//objXData.SetAt(PIPE_FITTYPE,m_pPipeParam->m_pszFitType);
//objXData.SetAt(PIPE_INSTHICK,m_pPipeParam->m_dInsThick);
//objXData.SetAt(PIPE_INSTAG,m_pPipeParam->m_pszInsTag);
//objXData.SetAt(DOC_INSTRATAG,m_pPipeParam->m_nInsAndHead);
//objXData.SetAt(DOC_INSDIM,m_pPipeParam->m_pszInsDim);
//objXData.SetAt(DOC_INSMATER,m_pPipeParam->m_pszInsMateral);
//objXData.SetAt(DOC_INSSPEC,m_pPipeParam->m_pszInsSpec);
//objXData.SetAt(DOC_TRAMTOINF,m_pPipeParam->m_pszTraMtoInfo);
//objXData.SetAt(DOC_TRADESCR,m_pPipeParam->m_pszTraDescr);
//objXData.SetAt(DOC_PIPECOLOR,m_pPipeParam->m_nPipeColor);
//objXData.SetAt(DOC_2DPIPE,m_pPipeParam->m_bIs2D);
AcGeVector3d vt = GetInterfaceVector(KTFitting::kEnd);
vt.normalize();
objXData.SetAt(PIPE_DIR,vt);
//objXData.SetAt(PIPE_MTOALL,m_pPipeParam->m_pszMtoInfo);
objXData.SetAt(PIPE_FITTING,(int)KindOf());
//写Interface;
KTInterface interF;
CString sIntF = _T("KTInterface"),sIndex,sKey;
for (int i = 0;i < m_arInterfaces.length();i++)
{
interF = m_arInterfaces.at(i);
sKey.Format(_T("%s_%d_D"),sIntF,i + 1);
objXData.SetAt(sKey,interF.m_dD);
sKey.Format(_T("%s_%d_P"),sIntF,i + 1);
objXData.SetAt(sKey,interF.m_ptGe);
sKey.Format(_T("%s_%d_E"),sIntF,i + 1);
objXData.SetAt(sKey,interF.m_dEl);
sKey.Format(_T("%s_%d_V"),sIntF,i + 1);
objXData.SetAt(sKey,interF.m_vtDir);
}
objXData.SetAt(_T("标志"),_T("1"));
objXData.Write(pEnt,PIDPIPE_APP);
}
void KTFitting::WriteXData(AcDbEntity* pEnt,WPipe::PipeParam* pPipePar,AcGeVector3d vtDir,KTFitting::Fitting eType)
{
AecDbObjXDataMap objXData;
objXData.SetAt(PIPE_D,pPipePar->m_dD);
objXData.SetAt(PIPE_DSEL,(int)pPipePar->m_eD);
objXData.SetAt(PIPE_DN,pPipePar->m_dDN);
objXData.SetAt(PIPE_OD,pPipePar->m_dOD);
objXData.SetAt(PIPE_INTERFACED,pPipePar->m_dInterfaceD);
objXData.SetAt(PIPE_INTERFACEL,pPipePar->m_dInterfaceL);
objXData.SetAt(PIPE_INTERFACED2,pPipePar->m_dInterfaceD2);
objXData.SetAt(PIPE_INTERFACEL2,pPipePar->m_dInterfaceL2);
objXData.SetAt(PIPE_THICK,pPipePar->m_dThick);
objXData.SetAt(PIPE_EL,pPipePar->m_dEl);
objXData.SetAt(PIPE_RATIO,pPipePar->m_dRRatio);
objXData.SetAt(PIPE_ZONE,pPipePar->szZone);
objXData.SetAt(PIPE_EAPP,pPipePar->m_nConnectType);
objXData.SetAt(PIPE_MEDIA,pPipePar->szMedia);
objXData.SetAt(PIPE_LEVEL,pPipePar->szLevel);
objXData.SetAt(PIPE_NO,pPipePar->szNo);
objXData.SetAt(PIPE_DESCR,pPipePar->szDescr);
objXData.SetAt(PIPE_SPEC,pPipePar->szSpec);
objXData.SetAt(PIPE_LINENO,pPipePar->szLineNo);
objXData.SetAt(PIPE_ELBASE,(int)pPipePar->m_eElBase);
objXData.SetAt(PIPE_INSTHICK,pPipePar->m_dInsThk);
objXData.SetAt(PIPE_INSTAG,pPipePar->szInsTag);
objXData.SetAt(DOC_INSTRATAG,pPipePar->m_nInsAndHead);
objXData.SetAt(DOC_INSDIM,pPipePar->szInsDim);
objXData.SetAt(DOC_INSMATER,pPipePar->szInsMateral);
objXData.SetAt(DOC_INSSPEC,pPipePar->szInsSpec);
objXData.SetAt(DOC_TRAMTOINF,pPipePar->szTraMtoInfo);
objXData.SetAt(DOC_TRADESCR,pPipePar->szTraDescr);
objXData.SetAt(DOC_PIPECOLOR,pPipePar->m_nPipeColor);
objXData.SetAt(PIPE_FITTYPE,pPipePar->szFitType);
objXData.SetAt(PIPE_MTOALL,pPipePar->szMtoInfo);
objXData.SetAt(DOC_2DPIPE,pPipePar->m_bIs2D);
objXData.SetAt(PIPE_TEEMAINDIR,pPipePar->m_bIsMain);
vtDir.normalize();
objXData.SetAt(PIPE_DIR,vtDir);
objXData.SetAt(PIPE_FITTING,eType);
CString sInfo;
GetFitMtoInfoAll(pPipePar,sInfo);
objXData.SetAt(PIPE_MTOALL,sInfo);
objXData.SetAt(PIPE_DESCR,pPipePar->szDescr);
//写Interface;
objXData.SetAt(_T("KTInterfaceN"),m_arInterfaces.length());
KTInterface interF;
CString sIntF = _T("KTInterface"),sIndex,sKey;
for (int i = 0;i < m_arInterfaces.length();i++)
{
interF = m_arInterfaces.at(i);
sKey.Format(_T("%s_%d_D"),sIntF,i + 1);
objXData.SetAt(sKey,interF.m_dD);
sKey.Format(_T("%s_%d_P"),sIntF,i + 1);
objXData.SetAt(sKey,interF.m_ptGe);
sKey.Format(_T("%s_%d_E"),sIntF,i + 1);
objXData.SetAt(sKey,interF.m_dEl);
sKey.Format(_T("%s_%d_V"),sIntF,i + 1);
objXData.SetAt(sKey,interF.m_vtDir);
}
objXData.SetAt(_T("标志"),_T("1"));
objXData.Write(pEnt,PIDPIPE_APP);
}
BOOL KTFitting::PipeParam2XData(WPipe::PipeParam* pPipePar,AecDbObjXDataMap& objXData,KTFitting* pFitting)
{
objXData.SetAt(PIPE_D,pPipePar->m_dD);
objXData.SetAt(PIPE_DSEL,(int)pPipePar->m_eD);
objXData.SetAt(PIPE_DN,pPipePar->m_dDN);
objXData.SetAt(PIPE_OD,pPipePar->m_dOD);
objXData.SetAt(PIPE_THICK,pPipePar->m_dThick);
objXData.SetAt(PIPE_EL,pPipePar->m_dEl);
objXData.SetAt(PIPE_RATIO,pPipePar->m_dRRatio);
objXData.SetAt(PIPE_ZONE,pPipePar->szZone);
objXData.SetAt(PIPE_EAPP,pPipePar->m_nConnectType);
objXData.SetAt(PIPE_MEDIA,pPipePar->szMedia);
objXData.SetAt(PIPE_LEVEL,pPipePar->szLevel);
objXData.SetAt(PIPE_NO,pPipePar->szNo);
objXData.SetAt(PIPE_DESCR,pPipePar->szDescr);
objXData.SetAt(PIPE_SPEC,pPipePar->szSpec);
objXData.SetAt(PIPE_LINENO,pPipePar->szLineNo);
objXData.SetAt(PIPE_ELBASE,(int)pPipePar->m_eElBase);
objXData.SetAt(PIPE_INTERFACED,pPipePar->m_dInterfaceD);
objXData.SetAt(PIPE_INTERFACEL,pPipePar->m_dInterfaceL);
objXData.SetAt(PIPE_INTERFACED2,pPipePar->m_dInterfaceD2);
objXData.SetAt(PIPE_INTERFACEL2,pPipePar->m_dInterfaceL2);
objXData.SetAt(PIPE_INSTHICK,pPipePar->m_dInsThk);
objXData.SetAt(PIPE_INSTAG,pPipePar->szInsTag);
objXData.SetAt(DOC_INSTRATAG,pPipePar->m_nInsAndHead);
objXData.SetAt(DOC_INSDIM,pPipePar->szInsDim);
objXData.SetAt(DOC_INSMATER,pPipePar->szInsMateral);
objXData.SetAt(DOC_INSSPEC,pPipePar->szInsSpec);
objXData.SetAt(DOC_TRAMTOINF,pPipePar->szTraMtoInfo);
objXData.SetAt(DOC_TRADESCR,pPipePar->szTraDescr);
objXData.SetAt(DOC_PIPECOLOR,pPipePar->m_nPipeColor);
objXData.SetAt(PIPE_FITTYPE,pPipePar->szFitType);
objXData.SetAt(PIPE_MTOALL,pPipePar->szMtoInfo);
objXData.SetAt(DOC_2DPIPE,pPipePar->m_bIs2D);
AcGeVector3d vtDir = pPipePar->m_vtDir;
vtDir.normalize();
objXData.SetAt(PIPE_DIR,vtDir);
if (pFitting != NULL)
{
objXData.SetAt(PIPE_FITTING,pFitting->KindOf());
//写Interface;
objXData.SetAt(_T("KTInterfaceN"),pFitting->m_arInterfaces.length());
KTInterface interF;
CString sIntF = _T("KTInterface"),sIndex,sKey;
for (int i = 0;i < pFitting->m_arInterfaces.length();i++)
{
interF = pFitting->m_arInterfaces.at(i);
sKey.Format(_T("%s_%d_D"),sIntF,i + 1);
objXData.SetAt(sKey,interF.m_dD);
sKey.Format(_T("%s_%d_P"),sIntF,i + 1);
objXData.SetAt(sKey,interF.m_ptGe);
sKey.Format(_T("%s_%d_E"),sIntF,i + 1);
objXData.SetAt(sKey,interF.m_dEl);
sKey.Format(_T("%s_%d_V"),sIntF,i + 1);
objXData.SetAt(sKey,interF.m_vtDir);
}
}
return TRUE;
}
BOOL KTFitting::XData2PipeParam(WPipe::PipeParam* pParamL,AecDbObjXDataMap* pObjXData,KTFitting* pFitting)
{
if (pParamL != NULL && pObjXData != NULL)
{
CString sText = _T("");
pObjXData->GetAt(PIPE_D,pParamL->m_dD);
pObjXData->GetAt(PIPE_DSEL,(int&)pParamL->m_eD);
pObjXData->GetAt(PIPE_DN,pParamL->m_dDN);
pObjXData->GetAt(PIPE_OD,pParamL->m_dOD);
pObjXData->GetAt(PIPE_INTERFACED,pParamL->m_dInterfaceD);
pObjXData->GetAt(PIPE_INTERFACED2,pParamL->m_dInterfaceD2);
pObjXData->GetAt(PIPE_THICK,pParamL->m_dThick);
pObjXData->GetAt(PIPE_EL,pParamL->m_dEl);
pObjXData->GetAt(PIPE_RATIO,pParamL->m_dRRatio);
pObjXData->GetAt(PIPE_INSTHICK,pParamL->m_dInsThk);
pObjXData->GetAt(PIPE_INTERFACEL,pParamL->m_dInterfaceL);
pObjXData->GetAt(PIPE_INTERFACEL2,pParamL->m_dInterfaceL2);
pObjXData->GetAt(PIPE_EAPP,pParamL->m_nConnectType);
sText = _T("");
pObjXData->GetAt(PIPE_MEDIA,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szMedia,sText);
sText = _T("");
pObjXData->GetAt(PIPE_ZONE,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szZone,sText);
sText = _T("");
pObjXData->GetAt(PIPE_LEVEL,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szLevel,sText);
sText = _T("");
pObjXData->GetAt(PIPE_INSTAG,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szInsTag,sText);
sText = _T("");
pObjXData->GetAt(PIPE_NO,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szNo,sText);
sText = _T("");
pObjXData->GetAt(PIPE_DESCR,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szDescr,sText);
sText = _T("");
pObjXData->GetAt(PIPE_SPEC,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szSpec,sText);
pObjXData->GetAt(PIPE_LINENO,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szLineNo,sText);
pObjXData->GetAt(PIPE_ELBASE,(int&)pParamL->m_eElBase);
pObjXData->GetAt(PIPE_REDUCER,(int&)pParamL->m_eRed);
AcGePoint3d ptGe;
pObjXData->GetAt(PIPE_REDECEN,pParamL->m_vtECCen);
pObjXData->GetAt(PIPE_CAP,pParamL->m_nConnectType);
pObjXData->GetAt(DOC_INSTRATAG,pParamL->m_nInsAndHead);
sText = _T("");
pObjXData->GetAt(DOC_INSDIM,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szInsDim,sText);
sText = _T("");
pObjXData->GetAt(DOC_INSMATER,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szInsMateral,sText);
sText = _T("");
pObjXData->GetAt(DOC_INSSPEC,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szInsSpec,sText);
sText = _T("");
pObjXData->GetAt(PIPE_MTOALL,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szMtoInfo,sText);
sText = _T("");
pObjXData->GetAt(PIPE_FITTYPE,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szFitType,sText);
sText = _T("");
pObjXData->GetAt(DOC_TRAMTOINF,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szTraMtoInfo,sText);
sText = _T("");
pObjXData->GetAt(DOC_TRADESCR,sText);
if (!sText.IsEmpty()) _tcscpy(pParamL->szTraDescr,sText);
pObjXData->GetAt(DOC_PIPECOLOR,pParamL->m_nPipeColor);
pObjXData->GetAt(DOC_2DPIPE,pParamL->m_bIs2D);
pObjXData->GetAt(PIPE_TEEMAINDIR,pParamL->m_bIsMain);
AcGeVector3d vtDirT;
pObjXData->GetAt(PIPE_DIR,vtDirT);
pParamL->m_vtDir = vtDirT;
//读接口
int nInterFs = 0;
pObjXData->GetAt(_T("KTInterfaceN"),nInterFs);
if (pFitting != NULL)
{
KTInterface interF;
CString sIntF = _T("KTInterface"),sIndex,sKey;
for (int i = 0;i < nInterFs;i++)
{
sKey.Format(_T("%s_%d_D"),sIntF,i + 1);
pObjXData->GetAt(sKey,interF.m_dD);
sKey.Format(_T("%s_%d_P"),sIntF,i + 1);
pObjXData->GetAt(sKey,interF.m_ptGe);
sKey.Format(_T("%s_%d_E"),sIntF,i + 1);
pObjXData->GetAt(sKey,interF.m_dEl);
sKey.Format(_T("%s_%d_V"),sIntF,i + 1);
pObjXData->GetAt(sKey,interF.m_vtDir);
pFitting->m_arInterfaces.append(interF);
}
}
return TRUE;
}
return FALSE;
}
void KTFitting::DesignEnterCap(WPipe::PipeParam* pParam,AcGePoint3d& ptGeFr,AcGeVector3d& vtDir2Out,
AcGeVector3d& vt2D,AcDbEntity** pSubEnt,int& nFr,BOOL bEndLine/* = NULL*/)
{
if (pSubEnt == NULL) return;
if (pParam == NULL) return;
vtDir2Out.normalize();
vt2D.normalize();
/*
3 --| 2
|____
|
0 --| 1
*/
AcGePoint3d ptGe[6];
ptGe[1] = ptGeFr + vt2D * pParam->m_dInterfaceD * 0.5;
ptGe[0] = ptGe[1] + vtDir2Out * pParam->m_dInterfaceL;
ptGe[2] = ptGeFr - vt2D * pParam->m_dInterfaceD * 0.5;
ptGe[3] = ptGe[2] + vtDir2Out * pParam->m_dInterfaceL;
AcGePoint3d ptGe1,ptGe2;
ptGe1 = ptGeFr;
ptGe2 = ptGeFr + vtDir2Out * pParam->m_dInterfaceL;
if (pParam->m_nConnectType == WPipe::eSanitary)
{
if (pSubEnt[nFr] == NULL)
pSubEnt[nFr] = new AcDbLine;
((AcDbLine*)pSubEnt[nFr])->setStartPoint(ptGe[0]);
((AcDbLine*)pSubEnt[nFr])->setEndPoint(ptGe[1]);
nFr++;
}
if (pSubEnt[nFr] == NULL)
pSubEnt[nFr] = new AcDbLine;
((AcDbLine*)pSubEnt[nFr])->setStartPoint(ptGe[1]);
((AcDbLine*)pSubEnt[nFr])->setEndPoint(ptGe[2]);
nFr++;
if (pParam->m_nConnectType == WPipe::eSanitary)
{
if (pSubEnt[nFr] == NULL)
pSubEnt[nFr] = new AcDbLine;
((AcDbLine*)pSubEnt[nFr])->setStartPoint(ptGe[2]);
((AcDbLine*)pSubEnt[nFr])->setEndPoint(ptGe[3]);
nFr++;
}
AcGeVector3d vtCr = vtDir2Out.crossProduct(vt2D);
if ( vtCr.isParallelTo(AcGeVector3d::kZAxis)) //XY面画
{
if (bEndLine)
{
nFr++;
if (pSubEnt[nFr] == NULL)
pSubEnt[nFr] = new AcDbLine;
((AcDbLine*)pSubEnt[nFr])->setStartPoint(ptGe[0]);
((AcDbLine*)pSubEnt[nFr])->setEndPoint(ptGe[3]);
nFr++;
}
}
else //空间,画圆
{
/*nFr++;
if (pSubEnt[nFr] == NULL)
pSubEnt[nFr] = new AcDbCircle;
((AcDbCircle*)pSubEnt[nFr])->setCenter(ptGeFr);
((AcDbCircle*)pSubEnt[nFr])->setRadius(pParam->m_dInterfaceD * 0.5);
((AcDbCircle*)pSubEnt[nFr])->setNormal(vtDir2Out);*/
if (pSubEnt[nFr] == NULL)
pSubEnt[nFr] = new AcDbCircle;
((AcDbCircle*)pSubEnt[nFr])->setCenter(ptGe2);
((AcDbCircle*)pSubEnt[nFr])->setRadius(pParam->m_dInterfaceD * 0.5);
((AcDbCircle*)pSubEnt[nFr])->setNormal(vtDir2Out);
nFr++;
}
}
BOOL KTFitting::GetInterface(int nIndex,KTFitting::KTInterface* pInterface)
{
if (pInterface == NULL) return FALSE;
int nCount = m_arInterfaces.length();
if (nIndex > -1 && nIndex < nCount )
{
memcpy(pInterface,&m_arInterfaces.at(nIndex),sizeof(KTInterface));
return TRUE;
}
return FALSE;
}
AcGePoint3d KTFitting::GetInteracePoint(int nIndex)
{
int nSize = m_arInterfaces.length();
if (nIndex > -1 && nIndex < nSize)
{
return m_arInterfaces.at(nIndex).m_ptGe;
}
return AcGePoint3d::kOrigin;
}
double KTFitting::GetInterfaceElevation(int nIndex)
{
int nSize = m_arInterfaces.length();
if (nIndex > -1 && nIndex < nSize)
{
return m_arInterfaces.at(nIndex).m_dEl;
}
return 0.0;
}
AcGeVector3d KTFitting::GetInterfaceVector(int nIndex)
{
int nSize = m_arInterfaces.length();
if (nIndex > -1 && nIndex < nSize)
{
return m_arInterfaces.at(nIndex).m_vtDir;
}
return AcGeVector3d::kXAxis;
}
int KTFitting::GetInterfaceCount()
{
return m_arInterfaces.length();
}
void KTFitting::AddDimPoint(AcGePoint3d& ptGe,LPCTSTR pszType,AcDbObjectIdArray& arIDs)
{
AcDbObjectId idDPt = KTSetting::InitLayer(_T("LAY_DPoint"));
//标注点,
AcDbPoint* pP1 = new AcDbPoint;
pP1->setPosition(ptGe);
pP1->setLayer(idDPt);
AecDbObjXDataMap xDataMap;
xDataMap.SetAt(_T("点类型"),_T("标注点"));
xDataMap.SetAt(_T("名称"),_T("管件"));
xDataMap.Write(pP1,_T("KTParampart"));
AcDbObjectId idT;
CKTCadUtility::AddToBlockTableRecord(idT,pP1);
arIDs.append(idT);
pP1->close();
}
void KTFitting::AddMetPoint(WPipe::PipeParam* pParam,AecDbObjXDataMap& xDataMap,AcGePoint3d& ptGe,
LPCTSTR pszType,AcDbObjectIdArray& arIDs,KTFitting* pFitting)
{
//材料点
AcDbObjectId idMPt = KTSetting::InitLayer(_T("LAY_MPoint"));
AcGePoint3d ptGeMid = ptGe;
AcDbPoint* pP1 = new AcDbPoint;
pP1->setPosition(ptGeMid);
pP1->setLayer(idMPt);
KTFitting::PipeParam2XData(pParam,xDataMap,pFitting);
xDataMap.SetAt(_T("点类型"),_T("材料点"));
xDataMap.SetAt(_T("名称"),pszType);
xDataMap.SetAt(_T("标志"),_T("1"));
CString sInfo;
GetFitMtoInfoAll(pParam,sInfo);
xDataMap.SetAt(PIPE_MTOALL,sInfo);
xDataMap.Write(pP1,_T("KTParampart"));
AcDbObjectId idT;
CKTCadUtility::AddToBlockTableRecord(idT,pP1);
arIDs.append(idT);
pP1->close();
}
BOOL KTFitting::GetFitMtoInfoAll(WPipe::PipeParam* pPipePar,CString& sInfo,WPipe::PipeParam* pPipePar2)
{
CString dbPath = FilePath::GetSysDir();
dbPath += _T("\\Plumbing.db");
CUIISQLiteServer sqlDb;
if (!sqlDb.InitADOServer(dbPath))
{
AfxMessageBox(IDS_LOADADOSERVERFAILED);
return FALSE;
}
CString sSQL,sProj,sLevel,sName;
m_pInitXData->GetAt(DOC_PROJECT,sProj);
//sLevel = pPipePar->szLevel;
Fitting eType = KindOf();
if (eType != KTFitting::kPipe)
{
GetName(sName);
sSQL.Format(_T("select * from AecSpecFit where [项目名称]='%s' and")
_T(" [等级名称]='%s' and [类别]='管件' and [类型]='%s'")
_T(" and [公称直径]=%d"),sProj,sLevel,sName,(int)pPipePar->m_dDN);
CStringArray arValues;
sqlDb.GetSelData(sSQL,arValues);
if (arValues.GetSize() >= 11 )
{
for (int i = 1;i <= 9;i++)//最后一个为描述
{
if (i == 1)
{
sInfo = arValues.GetAt(i);
}
else
{
sInfo += _T("^") + arValues.GetAt(i);
}
}
_tcscpy(pPipePar->szDescr,arValues.GetAt(10));
return TRUE;
}
}
else
{
sSQL.Format(_T("select * from AecSpecPipe where [项目名称]='%s' and")
_T(" [等级名称]='%s' and [公称直径]=%d"),sProj,sLevel,(int)pPipePar->m_dDN);
CStringArray arValues;
sqlDb.GetSelData(sSQL,arValues);
if (arValues.GetSize() >= 13 )
{
for (int i = 1;i <= 11;i++)//最后一个为描述
{
if (i == 1)
{
sInfo = arValues.GetAt(i);
}
else
{
sInfo += _T("^") + arValues.GetAt(i);
}
}
pPipePar->m_dOD = _ttof(arValues.GetAt(9)); //外径
_tcscpy(pPipePar->szDescr,arValues.GetAt(12));
return TRUE;
}
}
return FALSE;
}