Files
envi-code/SourceCode/Code2026/CoreLibrary/AecDbAssembleWell.cpp
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

2001 lines
44 KiB
C++

#include "stdafx.h"
#include "stdarx.h"
#include "AecDbAssembleWell.h"
#include "dbgrip.h"
#include "AecGripCback.h"
#include "MFCDbDwgFiler.h"
#include "KTExpressCalc.h"
Adesk::UInt32 AecDbAssembleWell::kCurrentVersionNumber = 2;
static const Adesk::UInt16 kColorByBlock = 0;
static const Adesk::UInt16 kRed = 1;
static const Adesk::UInt16 kYellow = 2;
static const Adesk::UInt16 kGreen = 3;
static const Adesk::UInt16 kCyan = 4;
static const Adesk::UInt16 kBlue = 5;
static const Adesk::UInt16 kMagenta = 6;
static const Adesk::UInt16 kWhite = 7;
static const Adesk::UInt16 kColorByLayer = 256;
extern AcDbPolyline *FormatPolyline(AcGePoint3d *ppPts, int nCount);
extern AcGePoint3d MidPoint(const AcGePoint3d &pt1, const AcGePoint3d &pt2);
static void FreeBuffer(int n, AcDbVoidPtrArray &arEntPtrs)
{
AcDbEntity *pEnt = NULL;
while (arEntPtrs.length() > n)
{
pEnt = (AcDbEntity *)arEntPtrs.last();
pEnt->erase();
pEnt->close();
DELETE_PTR(pEnt);
arEntPtrs.removeLast();
}
}
ACRX_DXF_DEFINE_MEMBERS(AecDbAssembleWell, AecDbEntityBase,
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
AcDbProxyEntity::kNoOperation | AcDbProxyEntity::kDisableProxyWarning,
AEC_ASMBLWELL,
"AecDbAssembleWell"
"|Product Desc: shanghua earthworm app obj"
"|Company: shanghua inc"
"|WEB Address: www.shanghuasoft.com")
AecDbAssembleWell::AecDbAssembleWell(void)
{
m_pGripAppData = new AecGripData[6];
}
AecDbAssembleWell::~AecDbAssembleWell(void)
{
delete[] m_pGripAppData;
}
bool AecDbAssembleWell::AppendScriptLine(const TCHAR *pszLine, bool bIs3D)
{
AssertWriteEnabled();
//Programming language syntax check
if ( IsPLSyntaxCheck(pszLine))
{
if (bIs3D)
m_arScrLines3d.Add(pszLine);
else
m_arScrLines2d.Add(pszLine);
return true;
}
acutPrintf(_T("Programming language syntax check error!"));
return false;
}
void AecDbAssembleWell::ResetContent()
{
AssertWriteEnabled();
m_arScrLines3d.RemoveAll();
m_arScrLines2d.RemoveAll();
}
bool AecDbAssembleWell::GetScriptLines(CStringArray &arLines, bool bIs3D) const
{
assertReadEnabled();
if (bIs3D)
{
if (!m_arScrLines3d.IsEmpty())
{
arLines.Append(m_arScrLines3d);
return true;
}
}
else
{
if (!m_arScrLines2d.IsEmpty())
{
arLines.Append(m_arScrLines2d);
return true;
}
}
return false;
}
bool AecDbAssembleWell::IsEmpty() const
{
assertReadEnabled();
return m_arScrLines3d.IsEmpty() ? true : false;
}
void AecDbAssembleWell::SetPosition(const AcGePoint3d &ptIns)
{
AssertWriteEnabled();
m_ptIns = ptIns;
}
bool AecDbAssembleWell::GetPosition(AcGePoint3d &ptIns) const
{
assertReadEnabled();
ptIns = m_ptIns;
return true;
}
void AecDbAssembleWell::SetRotation(double dAng)
{
AssertWriteEnabled();
m_dRotate = dAng;
}
double AecDbAssembleWell::GetRotation() const
{
assertReadEnabled();
return m_dRotate;
}
//专业数据 和绘制设置
AecDbObjXDataMap *AecDbAssembleWell::GetSpecialtyData(AcDb::OpenMode bMode /*= AcDb::kForWrite*/)
{
switch (bMode)
{
case AcDb::kForRead:
{
assertReadEnabled();
break;
}
case AcDb::kForWrite:
{
if (!isWriteEnabled())
{
upgradeOpen();
}
assertWriteEnabled();
break;
}
case AcDb::kForNotify:
{
assertReadEnabled();
}
default:
break;
}
return &m_mapSpecXData;
}
const AecDbObjXDataMap *AecDbAssembleWell::GetSpecialtyData() const
{
assertReadEnabled();
return &m_mapSpecXData;
}
void AecDbAssembleWell::subList() const
{
assertReadEnabled();
acutPrintf(_T("\n名称:井"));
AecDbEntityBase::subList();
m_mapSpecXData.List();
acutPrintf(_T("\nSML 3D"));
CString sLn;
for (int i = 0;i < m_arScrLines3d.GetSize();i++)
{
sLn = m_arScrLines3d.GetAt(i);
acutPrintf(_T("\n%s"), sLn);
}
acutPrintf(_T("\nSML 2D"));
for (int i = 0; i < m_arScrLines2d.GetSize(); i++)
{
sLn = m_arScrLines2d.GetAt(i);
acutPrintf(_T("\n%s"), sLn);
}
}
Acad::ErrorStatus AecDbAssembleWell::copyFrom(const AcRxObject *pSrc)
{
AecDbEntityBase::copyFrom(pSrc);
AecDbAssembleWell *pSrcOp = AecDbAssembleWell::cast(pSrc);
if (pSrcOp != NULL)
{
m_mapSpecXData.CopyFrom(&pSrcOp->m_mapSpecXData);
}
return Acad::eOk;
}
Acad::ErrorStatus AecDbAssembleWell::subTransformBy(const AcGeMatrix3d &xform)
{
AssertWriteEnabled();
m_ptIns.transformBy(xform);
AcGeVector3d vt;
vt.rotateBy(m_dRotate, AcGeVector3d::kZAxis);
vt.transformBy(xform);
vt.z = 0.0;//始终水平
m_dRotate = AcGeVector3d::kXAxis.angleTo(vt, AcGeVector3d::kZAxis);
return Acad::eOk;
}
#if ARX>16
Acad::ErrorStatus AecDbAssembleWell::subGetGripPoints(AcDbGripDataPtrArray &grips,
const double curViewUnitSize,
const int gripSize,
const AcGeVector3d &curViewDir,
const int bitflags) const
{
assertReadEnabled();
int i = 0;
memset(&m_pGripAppData[i], 0, sizeof(AecGripData));
m_pGripAppData[i].nIndex = i;
m_pGripAppData[i].nSegIndex = -1;
m_pGripAppData[i].ePos = eMid;
m_pGripAppData[i].nColor = kBlue;
m_pGripAppData[i].ptGrip = m_ptIns;
_tcscpy(m_pGripAppData[i].szTip, _T("插入点"));
//_tcscpy(m_pGripAppData[i].szID,m_sGUID);
m_pGripAppData[i].pOwner = (AcDbEntity *)this;
AcDbGripData* pGripData = new AcDbGripData;
pGripData->setGripPoint(m_ptIns);
pGripData->setAppData((void *)&m_pGripAppData[i]);
pGripData->setWorldDraw(AecGripCback::WorldDrawfunc);
pGripData->setToolTipFunc(AecGripCback::GripToolTipFunc);
grips.append(pGripData);
return Acad::eOk;
}
Acad::ErrorStatus AecDbAssembleWell::subMoveGripPointsAt(const AcDbVoidPtrArray &appData, const AcGeVector3d &offset, const int bitflags)
{
AssertWriteEnabled();
m_ptIns += offset;
return Acad::eOk;
}
Acad::ErrorStatus AecDbAssembleWell::subGetStretchPoints(AcGePoint3dArray &stretchPoints) const
{
assertReadEnabled();
stretchPoints.append(m_ptIns);
return Acad::eOk;
}
Acad::ErrorStatus AecDbAssembleWell::subMoveStretchPointsAt(const AcDbIntArray &indices, const AcGeVector3d &offset)
{
AssertWriteEnabled();
m_ptIns += offset;
return Acad::eOk;
}
#endif
Acad::ErrorStatus AecDbAssembleWell::Draw2d(AcGiDraw &dc) const
{
assertReadEnabled();
//图层
AcDbObjectId idLay = dc.GetLayerId();
AcDbObjectId idLt = dc.GetLineTypeId();
dc.SetLayer(layerId());
dc.SetLineType(linetypeId());
if (Has2DBuffer())
{
Draw2DBuffers(dc);
return Acad::eOk;
}
AcGeVector3d vtM = m_ptIns.asVector();
AcGeMatrix3d xM;
xM.setToTranslation(vtM);
AcGeMatrix3d xR;
xR.setToRotation(m_dRotate, AcGeVector3d::kZAxis);
CString sSml;
AcDbEntity *pEnt = NULL;
//绘制二维
AcDbVoidPtrArray arEntPtrs;
for (int i = 0; i < m_arScrLines2d.GetSize(); i++)
{
sSml = m_arScrLines2d.GetAt(i);
NewAcDbEntity(arEntPtrs, sSml);
}
for (int i = 0;i < arEntPtrs.length();i++)
{
pEnt = (AcDbEntity*)arEntPtrs.at(i);
pEnt->transformBy(xR);
pEnt->transformBy(xM);
dc.DrawEntity(pEnt);
Add2DBuffer(pEnt);
}
return Acad::eOk;
}
typedef CMap<CString, LPCTSTR, int, int> CMapString2Int;
bool AecDbAssembleWell::NewAcDbEntity(AcDbVoidPtrArray& arEntPtrs, CString& sSml) const
{
//关键字
CMapString2Int mapClass2Type;
mapClass2Type.SetAt(_T("RECT"), 1);
mapClass2Type.SetAt(_T("CIR"), 2);
mapClass2Type.SetAt(_T("ARC"), 3);
mapClass2Type.SetAt(_T("LINE"), 4);
mapClass2Type.SetAt(_T("PLINE"), 5);
sSml.TrimLeft();
sSml.TrimRight();
int nPos = sSml.Find(_T(" "), 0);
if (nPos == -1)
{
acutPrintf(_T("\n脚本语法错误!没有发现关键字!"));
return NULL;
}
CString sClass = sSml.Mid(0, nPos);
int nType = 0;
if (!mapClass2Type.Lookup(sClass, nType))
{
acutPrintf(_T("\n脚本语法错误!没有发现关键字类型!"));
return NULL;
}
CStringArray arInfo;
AecDbEntityBase::SplitStrintToArray(sSml, arInfo, _T(' '));
double dX = 0, dY = 0;
int nColor = 0;
double dRotate = 0,dSA = 0,dEA = 0;
CString sXYOff;
AcGePoint3d ptGe[10];
AcGeVector3d vM;
AcGeMatrix3d xM;
ads_point pt;
//RECT
double dL = 0, dW = 0;
switch (nType)
{
case 1://RECT
{
//RECT L W (dx,dy) DIR COLOR
if (arInfo.GetSize() < 6)
{
acutPrintf(_T("\n二维矩形数据位缺失!"));
return false;
}
if (!CalValue(arInfo.GetAt(1), dL))
return false;
if (!CalValue(arInfo.GetAt(2), dW))
return false;
sXYOff = arInfo.GetAt(3);
CalXYOffset(sXYOff, dX, dY);
vM.set(dX, dY, 0);
xM.setToTranslation(vM);
if (!CalValue(arInfo.GetAt(4), dRotate))
return false;
dRotate *= PI / 180.0;
nColor = _ttoi(arInfo.GetAt(5));
ptGe[0].set(-0.5 * dL, -0.5 * dW, 0);
ptGe[1].set(-0.5 * dL, 0.5 * dW, 0);
ptGe[2].set( 0.5 * dL, 0.5 * dW, 0);
ptGe[3].set( 0.5 * dL, -0.5 * dW, 0);
ptGe[4] = ptGe[0];
for (int ii = 0;ii < 5;ii++)
{
ptGe[ii].rotateBy(dRotate, AcGeVector3d::kZAxis);
}
AcDbPolyline *pPl = FormatPolyline(ptGe, 5);
if (pPl != NULL)
{
pPl->setColorIndex(nColor);
pPl->transformBy(xM);
arEntPtrs.append(pPl);
}
break;
}
case 2://CIR
{
//CIR D (dx,dy) COLOR
if (arInfo.GetSize() < 4)
{
acutPrintf(_T("\n二维圆数据位缺失!"));
return false;
}
if (!CalValue(arInfo.GetAt(1), dL))
return false;
sXYOff = arInfo.GetAt(2);
CalXYOffset(sXYOff, dX, dY);
vM.set(dX, dY, 0);
xM.setToTranslation(vM);
nColor = _ttoi(arInfo.GetAt(3));
AcDbCircle *pCir = new AcDbCircle;
pCir->setCenter(AcGePoint3d::kOrigin);
pCir->setRadius(0.5 * dL);
pCir->setNormal(AcGeVector3d::kZAxis);
pCir->transformBy(xM);
pCir->setColorIndex(nColor);
arEntPtrs.append(pCir);
break;
}
case 3://ARC
{
//ARC D SA EA (dx,dy) COLOR
if (arInfo.GetSize() < 6)
{
acutPrintf(_T("\n二维圆弧数据位缺失!"));
return false;
}
if (!CalValue(arInfo.GetAt(1), dL))
return false;
if (!CalValue(arInfo.GetAt(2), dSA))
return false;
dSA *= PI / 180.0;
if (!CalValue(arInfo.GetAt(3), dEA))
return false;
dEA *= PI / 180.0;
sXYOff = arInfo.GetAt(4);
CalXYOffset(sXYOff, dX, dY);
vM.set(dX, dY, 0);
xM.setToTranslation(vM);
nColor = _ttoi(arInfo.GetAt(5));
AcDbArc *pArc = new AcDbArc;
pArc->setCenter(AcGePoint3d::kOrigin);
pArc->setRadius(0.5 * dL);
pArc->setStartAngle(dSA);
pArc->setEndAngle(dEA);
pArc->setNormal(AcGeVector3d::kZAxis);
pArc->setColorIndex(nColor);
pArc->transformBy(xM);
arEntPtrs.append(pArc);
break;
}
case 4://LINE
{
//LINE pt1 pt2 (dx,dy) COLOR
if (arInfo.GetSize() < 5)
{
acutPrintf(_T("\n二维直线数据位缺失!"));
return false;
}
sXYOff = arInfo.GetAt(1);
CalXYOffset(sXYOff, dX, dY);
ptGe[0].set(dX, dY, 0.0);
sXYOff = arInfo.GetAt(2);
CalXYOffset(sXYOff, dX, dY);
ptGe[1].set(dX, dY, 0.0);
sXYOff = arInfo.GetAt(3);
CalXYOffset(sXYOff, dX, dY);
vM.set(dX, dY, 0);
xM.setToTranslation(vM);
nColor = _ttoi(arInfo.GetAt(4));
AcDbLine *pLn = new AcDbLine;
pLn->setStartPoint(ptGe[0]);
pLn->setEndPoint(ptGe[1]);
pLn->transformBy(xM);
arEntPtrs.append(pLn);
break;
}
case 5://PLINE
{
//PLINE pt1,pt2,pt3,pt4... (dx,dy) COLOR
if (arInfo.GetSize() < 5)//至少2个点
{
acutPrintf(_T("\n二维PLINE数据位缺失!"));
return false;
}
int nTo = arInfo.GetSize() - 2;//偏移 颜色
int nFr = 1;
int nEnd = arInfo.GetSize() - 1;
AcDbPolyline *pPl = new AcDbPolyline;
AcGePoint2dArray arPts;
for (int j = nFr; j < nTo; j++)
{
sXYOff = arInfo.GetAt(j);
CalPoint2d(sXYOff, pt);
pPl->addVertexAt(j - nFr, asPnt2d(pt));
}
sXYOff = arInfo.GetAt(nTo);
CalXYOffset(sXYOff, dX, dY);
vM.set(dX, dY, 0);
xM.setToTranslation(vM);
nColor = _ttoi( arInfo.GetAt(nEnd));
pPl->transformBy(xM);
pPl->setColorIndex(nColor);
break;
}
default:
break;
}
return true;
}
Acad::ErrorStatus AecDbAssembleWell::Draw3d(AcGiDraw &dc) const
{
assertReadEnabled();
//图层
AcDbObjectId idLay = dc.GetLayerId();
AcDbObjectId idLt = dc.GetLineTypeId();
dc.SetLayer(layerId());
dc.SetLineType(linetypeId());
int nCrBk = dc.GetColor();
int nColor = nCrBk;
if (m_mapSpecXData.GetAt(_T("COLOR"), nColor))
{
dc.SetColor(nColor);
}
AcDbEntity *pEnt = NULL;
if (Has3DBuffer())
{
const AcDbVoidPtrArray &ar3D = Get3DBuffer();
for (int i = 0; i < ar3D.length(); i++)
{
pEnt = (AcDbEntity *)ar3D.at(i);
pEnt->setColorIndex(nColor);
dc.DrawEntity(*pEnt);
}
return Acad::eOk;
}
AcGeVector3d vtM = m_ptIns.asVector();
AcGeMatrix3d xM;
xM.setToTranslation(vtM);
AcGeMatrix3d xR;
xR.setToRotation(m_dRotate, AcGeVector3d::kZAxis);
CString sSml;
AcDbVoidPtrArray arUnt,arSub;
int nAddOrSub = 0;
AecDbEntityBase *pAecEntBase = NULL;
AecDbCurveBase* pAecCurBase = NULL;
for (int i = 0;i < m_arScrLines3d.GetSize();i++)
{
sSml = m_arScrLines3d.GetAt(i);
AcDbVoidPtrArray arEntPtrs;
NewAecEntity(arEntPtrs,sSml,nAddOrSub);
for (int j = 0; j < arEntPtrs.length(); j++)
{
pEnt = (AcDbEntity *)arEntPtrs.at(j);
if (pEnt != NULL)
{
pAecEntBase = AecDbEntityBase::cast(pEnt);
if (pAecEntBase != NULL)
{
pAecEntBase->setLayer(layerId());
//pAecEntBase->Draw3d(dc);
dc.DrawEntity(pAecEntBase);
if (nAddOrSub)
arUnt.append(pAecEntBase->Get3DBuffer());
else
arSub.append(pAecEntBase->Get3DBuffer());
pAecEntBase->Clean3DBufferNoDel();
delete pEnt;
continue;
}
pAecCurBase = AecDbCurveBase::cast(pEnt);
if (pAecCurBase != NULL)
{
pAecCurBase->setLayer(layerId());
//pAecCurBase->Draw3d(dc);
dc.DrawEntity(pAecCurBase);
if (nAddOrSub)
arUnt.append(pAecCurBase->Get3DBuffer());
else
arSub.append(pAecCurBase->Get3DBuffer());
pAecCurBase->Clean3DBufferNoDel();
delete pEnt;
continue;
}
//其他 旋转并移到指定位置
pEnt->transformBy(xR);
pEnt->transformBy(xM);
dc.DrawEntity(pEnt);
Add3DBuffer(pEnt);
}
}
}
//然后执行布尔运算减
Acad::ErrorStatus es;
AcDbEntity *pSub = NULL;
for (int i = 0;i < arUnt.length();i++)
{
pEnt = (AcDbEntity*)arUnt.at(i);
AcDb3dSolid *pSolid = AcDb3dSolid::cast(pEnt);
if (pSolid != NULL)
{
//去除洞口
for (int j = 0;j < arSub.length();j++)
{
pSub = (AcDbEntity*)arSub.at(j);
acutPrintf(_T("\n%s"),pSub->isA()->name());
AcDb3dSolid *pSolid2 = AcDb3dSolid::cast(pSub->clone());
if (pSolid2 != NULL)
{
es = pSolid->booleanOper(AcDb::kBoolSubtract, pSolid2);
if (pSolid2 != NULL) delete pSolid2;
}
}
}
//旋转并移到指定位置
pEnt->transformBy(xR);
pEnt->transformBy(xM);
dc.DrawEntity(pEnt);
Add3DBuffer(pEnt);
}
FreeBuffer(0, arSub);
return Acad::eOk;
}
Acad::ErrorStatus AecDbAssembleWell::dwgInFields(AcDbDwgFiler *pFiler)
{
AssertWriteEnabled();
//----- Read parent class information first.
Acad::ErrorStatus es = Acad::eOk;
if (!pFiler->isKindOf(CMFCDbDwgFiler::desc()))
{
es = AecDbEntityBase::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 > AecDbAssembleWell::kCurrentVersionNumber)
return (Acad::eMakeMeProxy);
//2D
m_mapSpecXData.dwgInFields(pFiler);
Adesk::Int32 nLines = 0;
pFiler->readInt32(&nLines);
m_arScrLines2d.RemoveAll();
TCHAR *pszLine = NULL;
for (int i = 0;i < nLines;i++)
{
pszLine = NULL;
pFiler->readString(&pszLine);
if (pszLine != NULL)
m_arScrLines2d.Add(pszLine);
}
nLines = 0;
pFiler->readInt32(&nLines);
m_arScrLines3d.RemoveAll();
for (int i = 0; i < nLines; i++)
{
pszLine = NULL;
pFiler->readString(&pszLine);
if (pszLine != NULL)
m_arScrLines3d.Add(pszLine);
}
return Acad::eOk;
}
Acad::ErrorStatus AecDbAssembleWell::dwgOutFields(AcDbDwgFiler *pFiler) const
{
assertReadEnabled();
//----- Save parent class information first.
Acad::ErrorStatus es = Acad::eOk;
if (!pFiler->isKindOf(CMFCDbDwgFiler::desc()))
{
es = AecDbEntityBase::dwgOutFields(pFiler);
if (es != Acad::eOk)
return (es);
}
//----- Object version number needs to be saved first
if ((es = pFiler->writeUInt32(AecDbAssembleWell::kCurrentVersionNumber)) != Acad::eOk)
return (es);
//2D
m_mapSpecXData.dwgOutFields(pFiler);
Adesk::Int32 nLines = m_arScrLines2d.GetSize();
pFiler->writeInt32(nLines);
CString sLine;
for (int i = 0;i < nLines;i++)
{
sLine = m_arScrLines2d.GetAt(i);
pFiler->writeString((const TCHAR*)sLine);
}
nLines = m_arScrLines3d.GetSize();
pFiler->writeInt32(nLines);
for (int i = 0; i < nLines; i++)
{
sLine = m_arScrLines3d.GetAt(i);
pFiler->writeString((const TCHAR *)sLine);
}
return Acad::eOk;
}
Acad::ErrorStatus AecDbAssembleWell::dxfInFields(AcDbDxfFiler *pFiler)
{
return Acad::eOk;
}
Acad::ErrorStatus AecDbAssembleWell::dxfOutFields(AcDbDxfFiler *pFiler) const
{
return Acad::eOk;
}
int AecDbAssembleWell::GetSectionDraw(const AcGePoint3d &ptFr, const AcGePoint3d &ptTo, const AcGeVector3d &vtViewDir, const AcGeVector3d &vtTo, AcDbVoidPtrArray &arRegionPtrs) const
{
return 0;
}
bool AecDbAssembleWell::IsPLSyntaxCheck(const TCHAR *pLine) const
{
return true;
}
bool AecDbAssembleWell::NewAecEntity(AcDbVoidPtrArray &arEntPtrs, CString& sSml, int& nAddOrSub) const
{
//关键字WALL SLAB PIPE HOLE CON.
CMapString2Int mapClass2Type;
mapClass2Type.SetAt(_T("WALL"),1);
mapClass2Type.SetAt(_T("SLAB"),2);
mapClass2Type.SetAt(_T("PIPE"),3);
mapClass2Type.SetAt(_T("HOLE"),4);
mapClass2Type.SetAt(_T("CON"),5);
sSml.TrimLeft();
sSml.TrimRight();
int nPos = sSml.Find(_T(" "),0);
if (nPos == -1)
{
acutPrintf(_T("\n脚本语法错误!没有发现关键字!"));
return NULL;
}
CString sClass = sSml.Mid(0, nPos);
int nType = 0;
if (!mapClass2Type.Lookup(sClass, nType))
{
acutPrintf(_T("\n脚本语法错误!没有发现关键字类型!"));
return NULL;
}
CStringArray arInfo;
AecDbEntityBase::SplitStrintToArray(sSml, arInfo, _T(' '));
nAddOrSub = 1;
bool bFailed = false;
switch (nType)
{
case 1://WALL
{
bFailed = NewWall(arEntPtrs,arInfo);
break;
}
case 2://SLAB
{
bFailed = NewSlab(arEntPtrs, arInfo);
break;
}
case 3://PIPE
{
bFailed = NewPipe(arEntPtrs, arInfo);
break;
}
case 4://HOLE
{
bFailed = NewHole(arEntPtrs, arInfo);
nAddOrSub = 0;
break;
}
case 5://CON
{
bFailed = NewCon(arEntPtrs, arInfo);
break;
}
default:
break;
}
if (bFailed)
{
acutPrintf(_T("\n%s"), sSml);
}
return bFailed;
}
typedef struct RectWall
{
double dt;
double dH;
double dL;
double dW;
double dBomEl;
double dX, dY;
TCHAR szName[33];
int nColor;
}RECTWALL;
//t h D 标高 偏移(X,Y) 井筒 0
typedef struct CirWall
{
double dt;
double dH;
double dD;
double dBomEl;
double dX, dY;
TCHAR szName[33];
int nColor;
}CIRWALL;
typedef struct ArcWall
{
double dt;
double dH;
double dD;
double dStaAng;
double dEndAng;
double dBomEl;
double dX, dY;
TCHAR szName[33];
int nColor;
}ARCWALL;
typedef struct PWall
{
double dt;
double dH;
ads_point pt[65];//默认最多64个点
double dBomEl;
TCHAR szName[33];
int nColor;
}PWALL;
BOOL AecDbAssembleWell::CalValue(const CString &sExp,double& dRes) const
{
//公式计算器
KTExpressCalc cal;
AecDbObjXDataMap *pMap = (AecDbObjXDataMap *)&m_mapSpecXData;
AecDbObjXDataMap::It it = pMap->Begin();
AecDbObjXDataMap::It end = pMap->End();
AecXData cVal;
memset(&cVal, 0, sizeof(AecXData));
CString sKey,sVal;
for (; it != end; )
{
if (!pMap->GetNext(it, sKey, cVal))
break;
//替换
if (cVal.nVt == VT_I4)
{
cal.SetVariableData(sKey, 1.0 * cVal.nVal);
}
if (cVal.nVt == VT_R8)
{
cal.SetVariableData(sKey, cVal.dVal[0]);
}
}
dRes = 0;
if (!cal.Calculate(sExp, dRes))
{
CString sEr;
KTExpressCalc::EErrorCode eE = cal.GetErrorCode();
switch (eE)
{
case KTExpressCalc::eVarialbeNotFind:
sEr = _T("变量没有找到");
break;
case KTExpressCalc::eNullExpress:
sEr = _T("表达式为空");
break;
case KTExpressCalc::eMissLeftPthis:
sEr = _T("缺少左括号");
break;
case KTExpressCalc::eMissVariable:
sEr = _T("缺少操作数");
break;
case KTExpressCalc::eMissOperator:
sEr = _T("缺少操作符");
break;
case KTExpressCalc::eMissIf:
sEr = _T("缺少if");
break;
case KTExpressCalc::eMissThen:
sEr = _T("缺少then");
break;
case KTExpressCalc::eMissElse:
sEr = _T("缺少else");
break;
case KTExpressCalc::eInvalidOperator:
sEr = _T("错误的操作符");
break;
case KTExpressCalc::eInvalidVariable:
sEr = _T("错误的操作数");
break;
case KTExpressCalc::eOutOfBound:
sEr = _T("计算值溢出");
break;
}
acutPrintf(_T("\n表达式:%s错误:%s"),sExp,sEr);
return FALSE;
}
return TRUE;
}
BOOL AecDbAssembleWell::CalXYOffset(CString& sXYOff, double& dX, double &dY) const
{
sXYOff.TrimLeft(_T('('));
sXYOff.TrimRight(_T(')'));
int nPos = sXYOff.Find(_T(','));
if (nPos == -1)
{
acutPrintf(_T("\n偏移数据位缺失!"));
return FALSE;
}
if (!CalValue(sXYOff.Left(nPos), dX))
return FALSE;
if (!CalValue(sXYOff.Mid(nPos + 1),dY))
return FALSE;
return TRUE;
}
BOOL AecDbAssembleWell::CalPoint2d(CString &sPt, ads_point &pt) const
{
return CalXYOffset(sPt,pt[X], pt[Y]);
}
bool AecDbAssembleWell::NewWall(AcDbVoidPtrArray &arEntPtrs ,CStringArray &arInfo) const
{
//R / C / A / P / L
CMapString2Int map2Type;
map2Type.SetAt(_T("R"), 0);
map2Type.SetAt(_T("C"), 1);
map2Type.SetAt(_T("A"), 2);
map2Type.SetAt(_T("P"), 3);
map2Type.SetAt(_T("L"), 4);
CString sType = arInfo.GetAt(1);
sType.TrimLeft();
sType.TrimRight();
int nType = 0, nPos = -1;
map2Type.Lookup(sType, nType);
AecDbXWall *pWall = NULL;
AcGePoint3d ptGe[5],ptS,ptE;
CString sXYOff;
AcGeMatrix3d xM;
AcGeVector3d vM;
switch (nType)
{
case 0://R
{
//WALL R b H A B 0 (0 ,0) 井筒 0
if (arInfo.GetSize() < 10)
{
acutPrintf(_T("\n矩形墙体数据位缺失!"));
return false;
}
RectWall rW;
memset(&rW, 0, sizeof(RectWall));
//计算表达式
if (!CalValue(arInfo.GetAt(2), rW.dt))
return false;
if (!CalValue(arInfo.GetAt(3), rW.dH))
return false;
if (!CalValue(arInfo.GetAt(4), rW.dL))
return false;
if (!CalValue(arInfo.GetAt(5), rW.dW))
return false;
if (!CalValue(arInfo.GetAt(6), rW.dBomEl))
return false;
sXYOff = arInfo.GetAt(7);
CalXYOffset(sXYOff, rW.dX, rW.dY);
vM.set(rW.dX, rW.dY,0);
xM.setToTranslation(vM);
_tcscpy(rW.szName, arInfo.GetAt(8));
rW.nColor = _ttoi(arInfo.GetAt(9));
ptGe[0].set(0, 0, 0);
ptGe[0].x -= 0.5 * rW.dL;
ptGe[0].y += 0.5 * rW.dW;
ptGe[1] = ptGe[0];
ptGe[1].x += rW.dL;
ptGe[2] = ptGe[1];
ptGe[2].y -= rW.dW;
ptGe[3] = ptGe[0];
ptGe[3].y -= rW.dW;
ptGe[4] = ptGe[0];
AcDbLine ln[4];
ptS = ptGe[0]; ptS.x -= 0.5 *rW.dt;
ptE = ptGe[1]; ptE.x += 0.5 * rW.dt;
ln[0].setStartPoint(ptS);
ln[0].setEndPoint(ptE);
ptS = ptGe[1]; ptS.y += 0.5 * rW.dt;
ptE = ptGe[2]; ptE.y -= 0.5 * rW.dt;
ln[1].setStartPoint(ptS);
ln[1].setEndPoint(ptE);
ptS = ptGe[2]; ptS.x += 0.5 * rW.dt;
ptE = ptGe[3]; ptE.x -= 0.5 * rW.dt;
ln[2].setStartPoint(ptS);
ln[2].setEndPoint(ptE);
ptS = ptGe[3]; ptS.y -= 0.5 * rW.dt;
ptE = ptGe[4]; ptE.y += 0.5 * rW.dt;
ln[3].setStartPoint(ptS);
ln[3].setEndPoint(ptE);
for (int j = 0;j < 4;j++)
{
ln[j].setNormal(AcGeVector3d::kZAxis);
ln[j].transformBy(xM);
pWall = new AecDbXWall;
pWall->SetWallData(rW.dt, rW.dH, rW.dBomEl, kMid);
pWall->SetBaseCurve(&ln[j]);//clone
pWall->setColorIndex(rW.nColor);
pWall->GetSpecialtyData()->SetAt(KEY_NAME, rW.szName);
pWall->GetSpecialtyData()->SetAt(_T("COLOR"), rW.nColor);
arEntPtrs.append(pWall);
}
break;
}
case 1://C
{
//WALL C t h D 标高 偏移(X,Y) 井筒 0
if (arInfo.GetSize() < 9)
{
acutPrintf(_T("\n圆形墙体数据位缺失!"));
return false;
}
CirWall cW;
memset(&cW, 0, sizeof(CirWall));
//计算表达式
if (!CalValue(arInfo.GetAt(2), cW.dt))
return false;
if (!CalValue(arInfo.GetAt(3), cW.dH))
return false;
if (!CalValue(arInfo.GetAt(4), cW.dD))
return false;
if (!CalValue(arInfo.GetAt(5), cW.dBomEl))
return false;
sXYOff = arInfo.GetAt(6);
CalXYOffset(sXYOff, cW.dX,cW.dY);
vM.set(cW.dX, cW.dY, 0);
xM.setToTranslation(vM);
_tcscpy(cW.szName, arInfo.GetAt(7));
cW.nColor = _ttoi(arInfo.GetAt(8));
AcDbCircle cir;
cir.setCenter(AcGePoint3d::kOrigin);
cir.setRadius(0.5 * cW.dD);
cir.setNormal(AcGeVector3d::kZAxis);
cir.transformBy(xM);
pWall = new AecDbXWall;
pWall->SetWallData(cW.dt, cW.dH, cW.dBomEl, kMid);
pWall->SetBaseCurve(&cir);//clone
pWall->setColorIndex(cW.nColor);
pWall->GetSpecialtyData()->SetAt(_T("COLOR"), cW.nColor);
pWall->GetSpecialtyData()->SetAt(KEY_NAME, cW.szName);
arEntPtrs.append(pWall);
break;
}
case 2://A
{
//WALL A t h D 90 270 0 (0,0) 井筒 0
if (arInfo.GetSize() < 11)
{
acutPrintf(_T("\n弧墙体数据位缺失!"));
return false;
}
ArcWall aW;
memset(&aW, 0, sizeof(ArcWall));
//计算表达式
if (!CalValue(arInfo.GetAt(2), aW.dt))
return false;
if (!CalValue(arInfo.GetAt(3), aW.dH))
return false;
if (!CalValue(arInfo.GetAt(4), aW.dD))
return false;
if (!CalValue(arInfo.GetAt(5), aW.dStaAng))
return false;
aW.dStaAng *= PI / 180.0;
if (!CalValue(arInfo.GetAt(6), aW.dEndAng))
return false;
aW.dEndAng *= PI / 180.0;
if (!CalValue(arInfo.GetAt(7), aW.dBomEl))
return false;
sXYOff = arInfo.GetAt(8);
CalXYOffset(sXYOff, aW.dX, aW.dY);
_tcscpy(aW.szName, arInfo.GetAt(9));
aW.nColor = _ttoi(arInfo.GetAt(10));
vM.set(aW.dX, aW.dY, 0);
xM.setToTranslation(vM);
AcDbArc arc;
arc.setCenter(AcGePoint3d::kOrigin);
arc.setRadius(0.5 * aW.dD);
arc.setNormal(AcGeVector3d::kZAxis);
arc.setStartAngle(aW.dStaAng);
arc.setEndAngle(aW.dEndAng);
arc.transformBy(xM);
pWall = new AecDbXWall;
pWall->SetWallData(aW.dt, aW.dH, aW.dBomEl, kMid);
pWall->SetBaseCurve(&arc);//clone
pWall->setColorIndex(aW.nColor);
pWall->GetSpecialtyData()->SetAt(_T("COLOR"), aW.nColor);
pWall->GetSpecialtyData()->SetAt(KEY_NAME, aW.szName);
arEntPtrs.append(pWall);
break;
}
case 3://P
{
//WALL P t H 点 点 点 标高 井筒 颜色
if (arInfo.GetSize() < 10)//至少3点
{
acutPrintf(_T("\n区域墙体数据位缺失!"));
return false;
}
PWall pW;
memset(&pW, 0, sizeof(PWall));
//计算表达式
if (!CalValue(arInfo.GetAt(2), pW.dt))
return false;
if (!CalValue(arInfo.GetAt(3), pW.dH))
return false;
int nTo = arInfo.GetSize() - 3;//标高 井筒 颜色
int nFr = 4;
AcDbPolyline pl;
for (int j = nFr;j < nTo;j++)
{
sXYOff = arInfo.GetAt(j);
CalPoint2d(sXYOff,pW.pt[j - nFr]);
pl.addVertexAt(j - nFr, asPnt2d(pW.pt[j-nFr]));
}
if (!CalValue(arInfo.GetAt(nTo), pW.dBomEl))
return false;
_tcscpy(pW.szName, arInfo.GetAt(nTo+1));
pW.nColor = _ttoi(arInfo.GetAt(nTo+2));
AcDbVoidPtrArray arCurPtrs;
pl.explode(arCurPtrs);
AcDbCurve *pCur = NULL;
for (int i = 0; i < arCurPtrs.length(); i++)
{
pCur = (AcDbCurve*)arCurPtrs.at(i);
pWall = new AecDbXWall;
pWall->SetWallData(pW.dt, pW.dH, pW.dBomEl, kMid);
pWall->SetBaseCurve(pCur);//clone
pWall->setColorIndex(pW.nColor);
pWall->GetSpecialtyData()->SetAt(_T("COLOR"), pW.nColor);
pWall->GetSpecialtyData()->SetAt(KEY_NAME, pW.szName);
delete pCur;
arEntPtrs.append(pWall);
}
break;
}
case 4://L
{
//WALL L t H 点 点 标高 井筒 颜色
if (arInfo.GetSize() < 8)//至少3点
{
acutPrintf(_T("\n直墙体数据位缺失!"));
return false;
}
PWall pW;
memset(&pW, 0, sizeof(PWall));
//计算表达式
if (!CalValue(arInfo.GetAt(2), pW.dt))
return false;
if (!CalValue(arInfo.GetAt(3), pW.dH))
return false;
sXYOff = arInfo.GetAt(4);
CalPoint2d(sXYOff, pW.pt[0]);
sXYOff = arInfo.GetAt(5);
CalPoint2d(sXYOff, pW.pt[1]);
if (!CalValue(arInfo.GetAt(6), pW.dBomEl))
return false;
_tcscpy(pW.szName, arInfo.GetAt(7));
pW.nColor = _ttoi(arInfo.GetAt(8));
AcDbLine ln;
ln.setStartPoint(asPnt3d(pW.pt[0]));
ln.setEndPoint(asPnt3d(pW.pt[1]));
ln.setNormal(AcGeVector3d::kZAxis);
pWall = new AecDbXWall;
pWall->SetWallData(pW.dt, pW.dH, pW.dBomEl, kMid);
pWall->SetBaseCurve(&ln);//clone
pWall->setColorIndex(pW.nColor);
pWall->GetSpecialtyData()->SetAt(_T("COLOR"), pW.nColor);
pWall->GetSpecialtyData()->SetAt(KEY_NAME, pW.szName);
arEntPtrs.append(pWall);
break;
}
default:
break;
}
return true;
}
typedef struct RSlab
{
double dt;
double dL;
double dW;
double dBomEl;
double dX;
double dY;
TCHAR szName[33];
int nColor;
}RSLAB;
typedef struct CirSlab
{
double dt;
double dD;
double dBomEl;
double dX;
double dY;
TCHAR szName[33];
int nColor;
}CIRSLAB;
typedef struct ArcSlab
{
double dt;
double dD;
double dStaAng;
double dEndAng;
double dBomEl;
double dX;
double dY;
TCHAR szName[33];
int nColor;
}ARCSLAB;
typedef struct PSlab
{
double dt;
ads_point pt[65];//默认最多64个点
double dBomEl;
TCHAR szName[33];
int nColor;
}PSLAB;
bool AecDbAssembleWell::NewSlab(AcDbVoidPtrArray &arEntPtrs, CStringArray &arInfo) const
{
//SLAB R / A / C / P DATA E 偏移[名称]板 颜色
CMapString2Int map2Type;
map2Type.SetAt(_T("R"), 0);
map2Type.SetAt(_T("C"), 1);
map2Type.SetAt(_T("A"), 2);
map2Type.SetAt(_T("P"), 3);
CString sType = arInfo.GetAt(1);
sType.TrimLeft();
sType.TrimRight();
int nType = 0, nPos = -1;
map2Type.Lookup(sType, nType);
AecDbXSlab *pSlab = NULL;
AcGePoint3d ptGe[5], ptS, ptE;
CString sXYOff;
AcGeMatrix3d xM;
AcGeVector3d vM;
switch (nType)
{
case 0://R
{
//SLAB R t L W E (X, Y) [名称] 1
//SLAB R t L W 1200 (100,300) 底板 1
if (arInfo.GetSize() < 9)
{
acutPrintf(_T("\n矩形板数据位缺失!"));
return false;
}
RSlab rS;
memset(&rS, 0, sizeof(RSlab));
//计算表达式
if (!CalValue(arInfo.GetAt(2), rS.dt))
return false;
if (!CalValue(arInfo.GetAt(3), rS.dL))
return false;
if (!CalValue(arInfo.GetAt(4), rS.dW))
return false;
if (!CalValue(arInfo.GetAt(5), rS.dBomEl))
return false;
sXYOff = arInfo.GetAt(6);
CalXYOffset(sXYOff, rS.dX, rS.dY);
vM.set(rS.dX, rS.dY, 0);
xM.setToTranslation(vM);
_tcscpy(rS.szName, arInfo.GetAt(7));
rS.nColor = _ttoi(arInfo.GetAt(8));
AcGePoint3d ptCen(0,0,0);
ptCen.transformBy(xM);
pSlab = new AecDbXSlab;
pSlab->SetRectSlab(rS.dL, rS.dW, rS.dt, rS.dBomEl,ptCen);
pSlab->setColorIndex(rS.nColor);
pSlab->GetSpecialtyData()->SetAt(KEY_NAME, rS.szName);
pSlab->GetSpecialtyData()->SetAt(_T("COLOR"), rS.nColor);
arEntPtrs.append(pSlab);
break;
}
case 1://C
{
//SLAB C t D 0 (0,0) 盖板 1
if (arInfo.GetSize() < 8)
{
acutPrintf(_T("\n圆形底板数据位缺失!"));
return false;
}
CirSlab cS;
memset(&cS, 0, sizeof(CirSlab));
//计算表达式
if (!CalValue(arInfo.GetAt(2), cS.dt))
return false;
if (!CalValue(arInfo.GetAt(3), cS.dD))
return false;
if (!CalValue(arInfo.GetAt(4), cS.dBomEl))
return false;
sXYOff = arInfo.GetAt(5);
CalXYOffset(sXYOff, cS.dX, cS.dY);
vM.set(cS.dX, cS.dY, 0);
xM.setToTranslation(vM);
_tcscpy(cS.szName, arInfo.GetAt(6));
cS.nColor = _ttoi(arInfo.GetAt(7));
AcGePoint3d ptCen(0, 0, 0);
ptCen.transformBy(xM);
pSlab = new AecDbXSlab;
pSlab->SetCircleSlab(0.5 * cS.dD, cS.dt, cS.dBomEl,ptCen);
pSlab->setColorIndex(cS.nColor);
pSlab->GetSpecialtyData()->SetAt(KEY_NAME, cS.szName);
pSlab->GetSpecialtyData()->SetAt(_T("COLOR"), cS.nColor);
arEntPtrs.append(pSlab);
break;
}
case 2://A
{
//SLAB A t D 90 270 0 (0,0) 盖板 1
if (arInfo.GetSize() < 10)
{
acutPrintf(_T("\n扇形底板数据位缺失!"));
return false;
}
ArcSlab aS;
memset(&aS, 0, sizeof(ArcSlab));
//计算表达式
if (!CalValue(arInfo.GetAt(2), aS.dt))
return false;
if (!CalValue(arInfo.GetAt(3), aS.dD))
return false;
if (!CalValue(arInfo.GetAt(4), aS.dStaAng))
return false;
aS.dStaAng *= PI / 180.0;
if (!CalValue(arInfo.GetAt(5), aS.dEndAng))
return false;
aS.dEndAng *= PI / 180.0;
if (!CalValue(arInfo.GetAt(6), aS.dBomEl))
return false;
sXYOff = arInfo.GetAt(7);
CalXYOffset(sXYOff, aS.dX, aS.dY);
vM.set(aS.dX, aS.dY, 0);
xM.setToTranslation(vM);
_tcscpy(aS.szName, arInfo.GetAt(8));
aS.nColor = _ttoi(arInfo.GetAt(9));
AcGePoint3d ptCen(0, 0, 0);
ptCen.transformBy(xM);
pSlab = new AecDbXSlab;
pSlab->SetSectorSlab(0.5 * aS.dD, aS.dt, aS.dBomEl,aS.dStaAng,aS.dEndAng, ptCen);
pSlab->setColorIndex(aS.nColor);
pSlab->GetSpecialtyData()->SetAt(KEY_NAME, aS.szName);
pSlab->GetSpecialtyData()->SetAt(_T("COLOR"), aS.nColor);
arEntPtrs.append(pSlab);
break;
}
case 3://P
{
//SLAB P t 点 点 … 底标高 名称 颜色
if (arInfo.GetSize() < 9)//至少3点
{
acutPrintf(_T("\n区域板数据位缺失!"));
return false;
}
PSlab pS;
memset(&pS, 0, sizeof(PSlab));
//计算表达式
if (!CalValue(arInfo.GetAt(2), pS.dt))
return false;
int nTo = arInfo.GetSize() - 3;//标高 名称 颜色
int nFr = 4;
AcGePoint2dArray arPts;
AcDbExtents ext;
for (int j = nFr; j < nTo; j++)
{
sXYOff = arInfo.GetAt(j);
CalPoint2d(sXYOff, pS.pt[j - nFr]);
arPts.append(asPnt2d(pS.pt[j - nFr]));
ext.addPoint(asPnt3d(pS.pt[j - nFr]));
}
if (!CalValue(arInfo.GetAt(nTo), pS.dBomEl))
return false;
_tcscpy(pS.szName, arInfo.GetAt(nTo + 1));
pS.nColor = _ttoi(arInfo.GetAt(nTo + 2));
AcGePoint3d ptCen;
ptCen = MidPoint(ext.minPoint(), ext.maxPoint());
pSlab = new AecDbXSlab;
pSlab->SetRegionSlab(arPts, pS.dt, pS.dBomEl, ptCen);
pSlab->setColorIndex(pS.nColor);
pSlab->GetSpecialtyData()->SetAt(KEY_NAME, pS.szName);
pSlab->GetSpecialtyData()->SetAt(_T("COLOR"), pS.nColor);
arEntPtrs.append(pSlab);
break;
}
default:
break;
}
return true;
}
typedef struct XPipe
{
double dt;
double dS[2];
ads_point pt;
double dLen;
double dAng;
double dBomEl;
TCHAR szName[33];
int nColor;
}XPIPE;
bool AecDbAssembleWell::NewPipe(AcDbVoidPtrArray &arEntPtrs, CStringArray &arInfo) const
{
//PIPE R / C DATA E 管 颜色
CMapString2Int map2Type;
map2Type.SetAt(_T("R"), 0);
map2Type.SetAt(_T("C"), 1);
CString sPt;
CString sType = arInfo.GetAt(1);
sType.TrimLeft();
sType.TrimRight();
int nType = 0, nPos = -1;
map2Type.Lookup(sType, nType);
AecDbEwPipeBase *pPipe = NULL;
switch (nType)
{
case 0://R
{
//PIPE R t L W (0,0) D 0.5*D 45 套管 1
if (arInfo.GetSize() < 11)
{
acutPrintf(_T("\n矩形管数据位缺失!"));
return false;
}
XPipe xp;
memset(&xp, 0, sizeof(XPipe));
//计算表达式
if (!CalValue(arInfo.GetAt(2), xp.dt))
return false;
if (!CalValue(arInfo.GetAt(3), xp.dS[0]))
return false;
if (!CalValue(arInfo.GetAt(4), xp.dS[1]))
return false;
sPt = arInfo.GetAt(5);
CalXYOffset(sPt, xp.pt[X],xp.pt[Y]);
if (!CalValue(arInfo.GetAt(6), xp.dLen))
return false;
if (!CalValue(arInfo.GetAt(7), xp.dBomEl))
return false;
if (!CalValue(arInfo.GetAt(8), xp.dAng))
return false;
xp.dAng *= PI / 180.0;
_tcscpy(xp.szName, arInfo.GetAt(9));
xp.nColor = _ttoi(arInfo.GetAt(10));
AcGePoint3d pt2;
AcGeVector3d vt(1,0,0);
vt.rotateBy(xp.dAng, AcGeVector3d::kZAxis);
vt.normalize();
vt *= xp.dLen;
pt2 = asPnt3d(xp.pt) + vt;
pt2.z = xp.dBomEl;
xp.pt[Z] = xp.dBomEl;
AcDbLine ln;
ln.setStartPoint(asPnt3d(xp.pt));
ln.setEndPoint(pt2);
pPipe = new AecDbEwPipeBase;
pPipe->SetSection(xp.dS[0], xp.dS[1], xp.dt);
pPipe->SetBaseCurve(&ln);
pPipe->setColorIndex(xp.nColor);
pPipe->GetSpecialtyData()->SetAt(KEY_2DSTYLE, 1);
pPipe->GetSpecialtyData()->SetAt(KEY_SECSHAPE, eRect);
pPipe->GetSpecialtyData()->SetAt(PIPE_DN, xp.dS[0]);
pPipe->GetSpecialtyData()->SetAt(PIPE_OD, xp.dS[0]);
pPipe->GetSpecialtyData()->SetAt(PIPE_EL, xp.dBomEl);
pPipe->GetSpecialtyData()->SetAt(PIPE_DRAWDIR, WPipe::eOD);
pPipe->GetSpecialtyData()->SetAt(KEY_NAME, xp.szName);
pPipe->GetSpecialtyData()->SetAt(_T("COLOR"), xp.nColor);
arEntPtrs.append(pPipe);
break;
}
case 1://C
{
//PIPE C t D (0,0) L 0.5*D 60 套管 2
if (arInfo.GetSize() < 10)
{
acutPrintf(_T("\n圆管数据位缺失!"));
return false;
}
XPipe xp;
memset(&xp, 0, sizeof(XPipe));
//计算表达式
if (!CalValue(arInfo.GetAt(2), xp.dt))
return false;
if (!CalValue(arInfo.GetAt(3), xp.dS[0]))
return false;
sPt = arInfo.GetAt(4);
CalXYOffset(sPt, xp.pt[X], xp.pt[Y]);
if (!CalValue(arInfo.GetAt(5), xp.dLen))
return false;
if (!CalValue(arInfo.GetAt(6), xp.dBomEl))
return false;
if (!CalValue(arInfo.GetAt(7), xp.dAng))
return false;
xp.dAng *= PI / 180.0;
_tcscpy(xp.szName, arInfo.GetAt(8));
xp.nColor = _ttoi(arInfo.GetAt(9));
AcGePoint3d pt2;
AcGeVector3d vt(1, 0, 0);
vt.rotateBy(xp.dAng, AcGeVector3d::kZAxis);
vt.normalize();
vt *= xp.dLen;
pt2 = asPnt3d(xp.pt) + vt;
pt2.z = xp.dBomEl;
xp.pt[Z] = xp.dBomEl;
AcDbLine ln;
ln.setStartPoint(asPnt3d(xp.pt));
ln.setEndPoint(pt2);
pPipe = new AecDbEwPipeBase;
pPipe->SetSection(xp.dS[0], xp.dt);
pPipe->SetBaseCurve(&ln);
pPipe->setColorIndex(xp.nColor);
pPipe->GetSpecialtyData()->SetAt(KEY_2DSTYLE, 1);
pPipe->GetSpecialtyData()->SetAt(KEY_SECSHAPE, eCircle);
pPipe->GetSpecialtyData()->SetAt(PIPE_DN, xp.dS[0]);
pPipe->GetSpecialtyData()->SetAt(PIPE_OD, xp.dS[0]);
pPipe->GetSpecialtyData()->SetAt(PIPE_EL, xp.dBomEl);
pPipe->GetSpecialtyData()->SetAt(PIPE_DRAWDIR, WPipe::eOD);
pPipe->GetSpecialtyData()->SetAt(KEY_NAME, xp.szName);
pPipe->GetSpecialtyData()->SetAt(_T("COLOR"), xp.nColor);
arEntPtrs.append(pPipe);
break;
}
default:
break;
}
return true;
}
typedef struct XHole
{
double dS[2];
ads_point pt;
double dBomEl;
double dDeep;
double dAng;
TCHAR szName[33];
int nColor;
}XHOLE;
bool AecDbAssembleWell::NewHole(AcDbVoidPtrArray &arEntPtrs, CStringArray &arInfo) const
{
//HOLE R/C DATA E 洞
CMapString2Int map2Type;
map2Type.SetAt(_T("R"), 0);
map2Type.SetAt(_T("C"), 1);
CString sPt;
CString sType = arInfo.GetAt(1);
sType.TrimLeft();
sType.TrimRight();
int nType = 0, nPos = -1;
map2Type.Lookup(sType, nType);
XHole xh;
memset(&xh, 0, sizeof(XHole));
AecDbEwPipeBase *pPipe = NULL;
switch(nType)
{
case 0://R
{
//HOLE R L W (0,0) 0.5*W 0.5*B 45 出水口
if (arInfo.GetSize() < 9)
{
acutPrintf(_T("\n矩形洞口数据位缺失!"));
return false;
}
//计算表达式
if (!CalValue(arInfo.GetAt(2), xh.dS[0]))
return false;
if (!CalValue(arInfo.GetAt(3), xh.dS[1]))
return false;
sPt = arInfo.GetAt(4);
CalXYOffset(sPt, xh.pt[X], xh.pt[Y]);
if (!CalValue(arInfo.GetAt(5), xh.dDeep))
return false;
if (!CalValue(arInfo.GetAt(6), xh.dBomEl))
return false;
if (!CalValue(arInfo.GetAt(7), xh.dAng))
return false;
xh.dAng *= PI / 180.0;
_tcscpy(xh.szName, arInfo.GetAt(8));
AcGePoint3d pt2;
AcGeVector3d vt(1, 0, 0);
vt.rotateBy(xh.dAng, AcGeVector3d::kZAxis);
vt.normalize();
vt *= xh.dDeep;
pt2 = asPnt3d(xh.pt) + vt;
pt2.z = xh.dBomEl;
xh.pt[Z] = xh.dBomEl;
AcDbLine ln;
ln.setStartPoint(asPnt3d(xh.pt));
ln.setEndPoint(pt2);
pPipe = new AecDbEwPipeBase;
pPipe->SetSection(xh.dS[0], xh.dS[1],0);
pPipe->SetBaseCurve(&ln);
pPipe->GetSpecialtyData()->SetAt(KEY_2DSTYLE, 1);
pPipe->GetSpecialtyData()->SetAt(KEY_SECSHAPE, eRect);
pPipe->GetSpecialtyData()->SetAt(PIPE_DN, xh.dS[0]);
pPipe->GetSpecialtyData()->SetAt(PIPE_OD, xh.dS[0]);
pPipe->GetSpecialtyData()->SetAt(PIPE_EL, xh.dBomEl);
pPipe->GetSpecialtyData()->SetAt(PIPE_DRAWDIR, WPipe::eOD);
pPipe->GetSpecialtyData()->SetAt(KEY_NAME, xh.szName);
arEntPtrs.append(pPipe);
break;
}
case 1://C
{
//HOLE C D pt DEEP E DIR NAME
if (arInfo.GetSize() < 7)
{
acutPrintf(_T("\n圆形洞口数据位缺失!"));
return false;
}
//计算表达式
if (!CalValue(arInfo.GetAt(2), xh.dS[0]))
return false;
sPt = arInfo.GetAt(3);
CalXYOffset(sPt, xh.pt[X], xh.pt[Y]);
if (!CalValue(arInfo.GetAt(4), xh.dDeep))
return false;
if (!CalValue(arInfo.GetAt(5), xh.dBomEl))
return false;
if (!CalValue(arInfo.GetAt(6), xh.dAng))
return false;
xh.dAng *= PI / 180.0;
_tcscpy(xh.szName, arInfo.GetAt(7));
AcGePoint3d pt2;
AcGeVector3d vt(1, 0, 0);
vt.rotateBy(xh.dAng, AcGeVector3d::kZAxis);
vt.normalize();
vt *= xh.dDeep;
pt2 = asPnt3d(xh.pt) + vt;
pt2.z = xh.dBomEl;
xh.pt[Z] = xh.dBomEl;
AcDbLine ln;
ln.setStartPoint(asPnt3d(xh.pt));
ln.setEndPoint(pt2);
pPipe = new AecDbEwPipeBase;
pPipe->SetSection(xh.dS[0], 0);
pPipe->SetBaseCurve(&ln);
pPipe->GetSpecialtyData()->SetAt(KEY_2DSTYLE, 1);
pPipe->GetSpecialtyData()->SetAt(KEY_SECSHAPE, eRect);
pPipe->GetSpecialtyData()->SetAt(PIPE_DN, xh.dS[0]);
pPipe->GetSpecialtyData()->SetAt(PIPE_OD, xh.dS[0]);
pPipe->GetSpecialtyData()->SetAt(PIPE_EL, xh.dBomEl);
pPipe->GetSpecialtyData()->SetAt(PIPE_DRAWDIR, WPipe::eOD);
pPipe->GetSpecialtyData()->SetAt(KEY_NAME, xh.szName);
arEntPtrs.append(pPipe);
break;
}
default:
break;
}
return false;
}
bool AecDbAssembleWell::NewCon(AcDbVoidPtrArray &arEntPtrs, CStringArray &arInfo) const
{
//CON R/C/P/A DATA E 偏移(X,Y) P DIR 素砼 颜
//1.先创建板.
//2.然后切割板
//SLAB R / A / C / P DATA E 偏移[名称]板 颜色
CMapString2Int map2Type;
map2Type.SetAt(_T("R"), 0);
map2Type.SetAt(_T("C"), 1);
map2Type.SetAt(_T("A"), 2);
map2Type.SetAt(_T("P"), 3);
if (arInfo.GetSize() < 5)
{
acutPrintf(_T("\n素砼数据位缺失!"));
return false;
}
//确认倒数第5为是偏移数据
CString sXYOff = arInfo.GetAt(arInfo.GetSize() - 5);
if (sXYOff.Find(_T('(')) == -1)
{
acutPrintf(_T("\n素砼偏移数据位缺失!"));
return false;
}
int nEnd = arInfo.GetSize() - 1;
CString sDir = arInfo.GetAt(nEnd - 2);
ads_point ptDir;
if (!CalPoint2d(sDir, ptDir))
return false;
double dGrade = 0;
CString sP = arInfo.GetAt(nEnd - 3);
if (!CalValue(sP, dGrade) )
return false;
CString sType = arInfo.GetAt(1);
sType.TrimLeft();
sType.TrimRight();
int nType = 0, nPos = -1;
map2Type.Lookup(sType, nType);
CStringArray arInf2;
arInf2.Add(_T("SLAB"));
for (int i = 1;i < arInfo.GetSize() - 4;i++)
{
arInf2.Add(arInfo.GetAt(i));
}
arInf2.Add(_T("板"));
arInf2.Add(_T("1"));
AcDbVoidPtrArray arSlab;
NewSlab(arSlab, arInf2);
if (arSlab.length() == 1)
{
AecDbXSlab *pSlab = AecDbXSlab::cast((AcDbEntity*)arSlab.first());
if (pSlab != NULL)
{
AcDb3dSolid* pSolid = pSlab->GetDraw3dSolid(false, 0, false);
if (pSolid != NULL)
{
//从最高位置沿着坡度方向切割
AcDbExtents ext;
pSolid->getGeomExtents(ext);
//坡度转角度
AcGeVector3d vtP(ptDir[X], ptDir[Y], 0.0);
AcGeVector3d vtZ(0, 0, 1);
AcGeVector3d vtV = vtZ.crossProduct(vtP);
vtP.z = vtP.length() * dGrade;
vtP.normalize();
AcGePlane plan;
plan.set(ext.minPoint(), vtP, vtV);
AcGeVector3d vtN = plan.normal();
AcGeVector3d vtM(0,0,pSlab->GetThick());
AcGeMatrix3d xM;
xM.setToTranslation(vtM);
plan.transformBy(xM);
AcGePoint3d ptOrg;
AcGeVector3d vt1, vt2;
plan.getCoordSystem(ptOrg, vt1, vt2);
vt1.normalize(); vt2.normalize();
AcGePoint3d ptGe[5];
ptGe[0] = ptOrg;
ptGe[0] -= 1000 * vt1;
ptGe[0] += 1000 * vt2;
ptGe[1] = ptGe[0] + 2000 * vt1;
ptGe[2] = ptGe[1] - 2000 * vt2;
ptGe[3] = ptGe[0] - 2000 * vt2;
ptGe[4] = ptGe[0];
AcDbRegion *pReg = AecDbEarthWorm::CreatePolygonRegionOnly(ptGe, 5);
if (pReg != NULL)
{
pReg->setColorIndex(2);
arEntPtrs.append(pReg);
}
AcDb3dSolid *pNegHalfSolid = NULL;
if (Acad::eOk == pSolid->getSlice(plan, Adesk::kFalse, pNegHalfSolid))
{
arEntPtrs.append(pSolid);
}
}
delete pSlab;
}
return true;
}
return false;
}