411 lines
9.2 KiB
C++
411 lines
9.2 KiB
C++
#include "stdafx.h"
|
|
#include "KTMtoTool.h"
|
|
#include "KTCadUtility.h"
|
|
#include "EarThwormDef.h"
|
|
#include "KTModelLayoutXData.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
KTMtoTool::KTMtoTool()
|
|
{
|
|
m_pDbSrv = NULL;
|
|
CTime tNow = CTime::GetCurrentTime();
|
|
m_sDrawNo = tNow.Format("SH-%Y-%m-%d-%H%M%S");
|
|
}
|
|
|
|
KTMtoTool::~KTMtoTool()
|
|
{
|
|
|
|
}
|
|
|
|
int KTMtoTool::DoMto()
|
|
{
|
|
int nRes = AfxMessageBox(_T("是否清空上次报表数据?"), MB_YESNO);
|
|
if (nRes == IDYES)
|
|
{
|
|
EmptyTempTbl();
|
|
}
|
|
|
|
//获取初始化数据
|
|
KTModelLayoutXData::ReSet(m_xDataMap);
|
|
KTModelLayoutXData::ReadModelXData(KT_PIPEINIT,m_xDataMap);
|
|
|
|
CString sProj;
|
|
m_xDataMap.GetAt(DOC_PROJECT,sProj);
|
|
if (sProj.IsEmpty())
|
|
{
|
|
acutPrintf(_T("\n没有配置项目无法报料,请初始化配置!"));
|
|
return 0;
|
|
}
|
|
|
|
ads_name ss;
|
|
struct resbuf* pRb = NULL;
|
|
pRb = acutBuildList(RTDXF0,_T("POINT,LINE,LWPOLYLINE"),NULL);
|
|
|
|
nRes = RTNONE;
|
|
AcDbObjectIdArray arIDs;
|
|
ads_name ent;
|
|
AcDbObjectId id;
|
|
int nFount = -1;
|
|
|
|
while(TRUE)
|
|
{
|
|
nRes = CKTCadUtility::SelectEntities(_T("\n请选择报料实体:"),ss,pRb);
|
|
if (nRes == RTNONE )
|
|
{
|
|
break;
|
|
}
|
|
|
|
if (nRes == RTCAN)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
if (nRes == RTNORM)
|
|
{
|
|
Adesk::Int32 lLen = 0l;
|
|
acedSSLength(ss,&lLen);
|
|
for (int i = 0;i < lLen;i++)
|
|
{
|
|
acedSSName(ss,i,ent);
|
|
if ( Acad::eOk == acdbGetObjectId(id,ent))
|
|
{
|
|
if (!arIDs.find(id,nFount))
|
|
{
|
|
arIDs.append(id);
|
|
}
|
|
}
|
|
}
|
|
acedSSFree(ss);
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
acutRelRb(pRb);
|
|
return ImpMto(arIDs);
|
|
}
|
|
|
|
int KTMtoTool::ImpMto(const AcDbObjectIdArray& arIDs)
|
|
{
|
|
int nSize = arIDs.length();
|
|
AcDbObjectId id;
|
|
AcDbEntity* pEnt = NULL;
|
|
|
|
CMapStringToString mapKey2Len;
|
|
CString sFlag=_T("");
|
|
CString sName;
|
|
|
|
AcDbObjectIdArray arYBIds;
|
|
AcDbObjectIdArray arGrp,arGrpDons;
|
|
|
|
for (int i = 0;i < nSize;i++)
|
|
{
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,arIDs.at(i),AcDb::kForRead))
|
|
{
|
|
AcDbPoint* pPoint = AcDbPoint::cast(pEnt);
|
|
if (pPoint != NULL)
|
|
{
|
|
//判断组是否统计过
|
|
arGrp.removeAll();
|
|
CKTCadUtility::GetItemGroups(arIDs.at(i), arGrp);
|
|
if (!arGrp.isEmpty())
|
|
{
|
|
if (arGrpDons.find(arGrp.first()) == -1)
|
|
{
|
|
arGrpDons.append(arGrp.first());
|
|
}
|
|
else
|
|
{
|
|
pEnt->close();
|
|
continue;
|
|
}
|
|
}
|
|
|
|
AecDbObjXDataMap objXData;
|
|
if (objXData.Read(pEnt,KTPARAMPART))
|
|
{
|
|
CString sTag;
|
|
objXData.GetAt(_T("点类型"),sTag);
|
|
if (sTag.CompareNoCase(_T("材料点")) == 0)
|
|
{
|
|
sName = _T("");
|
|
objXData.GetAt(_T("名称"), sName);
|
|
|
|
if (sName.CompareNoCase(_T("仪表")) == 0)
|
|
{
|
|
arYBIds.append(arIDs.at(i));
|
|
}
|
|
else if (sName.CompareNoCase(_T("阀门")) == 0)
|
|
{
|
|
ImpPointMto(objXData,mapKey2Len);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
pEnt->close();
|
|
}
|
|
}
|
|
|
|
nSize = arYBIds.length();
|
|
for (int i = 0; i < nSize; i++)
|
|
{
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, arYBIds.at(i), AcDb::kForRead))
|
|
{
|
|
AcDbPoint *pPoint = AcDbPoint::cast(pEnt);
|
|
if (pPoint != NULL)
|
|
{
|
|
//判断组是否统计过
|
|
arGrp.removeAll();
|
|
CKTCadUtility::GetItemGroups(arIDs.at(i), arGrp);
|
|
if (!arGrp.isEmpty())
|
|
{
|
|
if (arGrpDons.find(arGrp.first()) == -1)
|
|
{
|
|
arGrpDons.append(arGrp.first());
|
|
}
|
|
else
|
|
{
|
|
pEnt->close();
|
|
continue;
|
|
}
|
|
}
|
|
|
|
AecDbObjXDataMap objXData;
|
|
if (objXData.Read(pEnt, KTPARAMPART))
|
|
{
|
|
CString sTag;
|
|
objXData.GetAt(_T("点类型"), sTag);
|
|
if (sTag.CompareNoCase(_T("材料点")) == 0)
|
|
{
|
|
sName = _T("");
|
|
objXData.GetAt(_T("名称"), sName);
|
|
|
|
if (sName.CompareNoCase(_T("仪表")) == 0)
|
|
{
|
|
ImpPointMto(objXData, mapKey2Len);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
pEnt->close();
|
|
}
|
|
}
|
|
|
|
//写表
|
|
CString sKey,sLen;
|
|
POSITION ps = NULL;
|
|
for (ps = mapKey2Len.GetStartPosition();ps != NULL;)
|
|
{
|
|
mapKey2Len.GetNextAssoc(ps,sKey,sLen);
|
|
sKey.Replace(_T("[$]"),_T("[数量]"));
|
|
sKey.Replace(_T("[~]"),sLen);
|
|
if (m_pDbSrv != NULL)
|
|
m_pDbSrv->ExecuteSQL(sKey);
|
|
}
|
|
|
|
//写list 表
|
|
CString sPipeNo, sSQL, sProj;
|
|
m_xDataMap.GetAt(DOC_PROJECT, sProj);
|
|
for (ps = m_lstPipeLineNos.GetHeadPosition(); ps != NULL;)
|
|
{
|
|
sPipeNo = m_lstPipeLineNos.GetNext(ps);
|
|
if (!sPipeNo.IsEmpty())
|
|
{
|
|
sSQL.Format(_T("insert into AecLineList ([项目名称],[管线名称]) values ('%s','%s')"), sProj, sPipeNo);
|
|
m_pDbSrv->ExecuteSQL(sSQL);
|
|
}
|
|
}
|
|
|
|
int nRes = AfxMessageBox(_T("材料统计完毕,是否执行BOM程序查看统计结果?"),MB_YESNO);
|
|
if (nRes == IDYES)
|
|
{
|
|
CString sMtoexe,sMtoPath;
|
|
sMtoPath = FilePath::GetSysDir();
|
|
|
|
sMtoexe = sMtoPath;
|
|
sMtoexe += _T("\\KTBOM.exe");
|
|
|
|
sMtoPath += _T("\\");
|
|
::ShellExecute(acedGetAcadFrame()->m_hWnd,_T("open"),sMtoexe,NULL,sMtoPath,SW_SHOWNORMAL);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int KTMtoTool::EmptyTempTbl()
|
|
{
|
|
CString sSQL;
|
|
|
|
sSQL = _T("delete from AecMTOValve");
|
|
m_pDbSrv->ExecuteSQL(sSQL);
|
|
sSQL = _T("delete from AecLineList");
|
|
m_pDbSrv->ExecuteSQL(sSQL);
|
|
|
|
/*
|
|
sSQL = _T("delete from AecMTOPipe");
|
|
m_pDbSrv->ExecuteSQL(sSQL);
|
|
|
|
sSQL = _T("delete from AecMTOFit");
|
|
m_pDbSrv->ExecuteSQL(sSQL);
|
|
|
|
sSQL = _T("delete from AecMTOBolt");
|
|
m_pDbSrv->ExecuteSQL(sSQL);
|
|
|
|
sSQL = _T("delete from AecMTOGasket");
|
|
m_pDbSrv->ExecuteSQL(sSQL);
|
|
|
|
sSQL = _T("delete from AecMTOFlange");
|
|
m_pDbSrv->ExecuteSQL(sSQL);
|
|
|
|
sSQL = _T("delete from AecMTOInsulation");
|
|
m_pDbSrv->ExecuteSQL(sSQL);
|
|
|
|
sSQL = _T("delete from AecMTOTracing");
|
|
m_pDbSrv->ExecuteSQL(sSQL);
|
|
*/
|
|
return 0;
|
|
}
|
|
|
|
static void ParsalToArray(CString& sMtoAll,CStringArray& arValues)
|
|
{
|
|
int nIndex = -1;
|
|
CString sTemp = sMtoAll,sText;
|
|
|
|
while(TRUE)
|
|
{
|
|
nIndex = sTemp.Find(_T("^"),0);
|
|
if (nIndex != -1)
|
|
{
|
|
arValues.Add(sTemp.Mid(0,nIndex));
|
|
sText = sTemp.Mid(nIndex + 1,sTemp.GetLength() - nIndex - 1);
|
|
sTemp = sText;
|
|
}
|
|
else
|
|
{
|
|
if (!sTemp.IsEmpty())
|
|
{
|
|
arValues.Add(sTemp);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
int KTMtoTool::ImpPointMto(AecDbObjXDataMap& objXData,CMapStringToString& mapKey2Len)
|
|
{
|
|
double dLen=1.0;//每一个点代表该种类元件一个
|
|
|
|
CString sName,sFlag;
|
|
objXData.GetAt(_T("名称"),sName);
|
|
|
|
CString sVal;
|
|
CString sSQL;
|
|
CString sProj,sPipeNo,sLevel,sType,sKind;
|
|
CString sDN,sMotInf,sDescr,sOD,sT;
|
|
m_xDataMap.GetAt(DOC_PROJECT,sProj);
|
|
|
|
objXData.GetAt(PIPE_DN,sDN); //公称直径
|
|
objXData.GetAt(PIPE_LINENO,sPipeNo); //管线名称
|
|
objXData.GetAt(PIPE_LEVEL,sLevel); //等级名称
|
|
objXData.GetAt(PIPE_DESCR,sDescr);
|
|
objXData.GetAt(PIPE_OD,sOD);
|
|
objXData.GetAt(PIPE_THICK,sT);
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
// "点类型","材料点","名称","$Tag","管线名称","$Line","等级名称","$Spec",
|
|
// "类别","$Name","类型","$Type","阀长",L,"阀高",H,"手轮直径",D,"公称直径",
|
|
// DN,"标准号","$Codes","材质","$Mat","端面","$Face","压力",Ps,"描述","$Des"
|
|
//,"垫片厚度",GT,"螺栓规格","$Blt"
|
|
|
|
// ID 项目名称 管线名称 等级名称 类别
|
|
// 210 KT-3 P-2000 1.6A1 闸阀
|
|
// 类型 公称直径 端面 压力 描述 数量 图纸号
|
|
// Z41H-16c 65 RF 1 .6 Z41H-16c,RF,1.6 2 A-1
|
|
CString sTxt1,sTxt2,sTxt3,sTxt4,sTxt5,sTxt6,sTxt7,sTxt8,sTxt9,sTxt10,sTxt11,sTxt12;
|
|
if (sName.CompareNoCase(_T("阀门"))== 0)
|
|
{
|
|
sTxt1 = sProj;
|
|
objXData.GetAt(_T("等级名称"),sTxt2);
|
|
if (m_LstLevels.Find(sTxt2) == NULL)
|
|
{
|
|
m_LstLevels.AddTail(sTxt2);
|
|
}
|
|
|
|
objXData.GetAt(_T("类别"),sTxt3);
|
|
objXData.GetAt(_T("类型"),sTxt4);
|
|
objXData.GetAt(_T("公称直径"),sTxt5);
|
|
objXData.GetAt(_T("端面"),sTxt6);
|
|
|
|
sTxt7 = _T("1.0");
|
|
objXData.GetAt(_T("压力"),sTxt7);
|
|
objXData.GetAt(_T("描述"),sTxt8);
|
|
objXData.GetAt(_T("管线名称"),sPipeNo);
|
|
if (m_lstPipeLineNos.Find(sPipeNo) == NULL)
|
|
{
|
|
m_lstPipeLineNos.AddTail(sPipeNo);
|
|
}
|
|
|
|
sSQL.Format(_T("insert into AecMTOValve ([项目名称],[等级名称],[类别],[类型],[公称直径],")
|
|
_T("[端面],[压力],[描述],[管线名称],[图纸号],[$])")
|
|
_T(" values ('%s','%s','%s','%s',%d,'%s',%g,'%s','%s','%s',[~])"),
|
|
sTxt1,sTxt2,sTxt3,sTxt4,
|
|
_ttoi(sTxt5),sTxt6,_ttof(sTxt7),sTxt8,
|
|
sPipeNo,m_sDrawNo);
|
|
if (mapKey2Len.Lookup(sSQL,sVal))
|
|
{
|
|
dLen += _ttof(sVal);
|
|
sVal.Format(_T("%g"),dLen);
|
|
mapKey2Len.SetAt(sSQL,sVal);
|
|
}
|
|
else
|
|
{
|
|
sVal.Format(_T("%g"),dLen);
|
|
mapKey2Len.SetAt(sSQL,sVal);
|
|
}
|
|
}
|
|
else if (sName.CompareNoCase(_T("仪表")) == 0)
|
|
{
|
|
sTxt1 = sProj;
|
|
if (!m_LstLevels.IsEmpty())
|
|
{
|
|
sTxt2 = m_LstLevels.GetTail();
|
|
}
|
|
sTxt3 = _T("仪表");
|
|
objXData.GetAt(_T("设备类型"), sTxt4);
|
|
|
|
sTxt5 = _T("0");//公称直径
|
|
sTxt6 = _T("SO");//端面
|
|
sTxt7 = _T("1.6");//压力
|
|
objXData.GetAt(_T("代号"), sTxt8);
|
|
|
|
if (!m_lstPipeLineNos.IsEmpty())
|
|
{
|
|
sPipeNo = m_lstPipeLineNos.GetTail();
|
|
}
|
|
|
|
sSQL.Format(_T("insert into AecMTOValve ([项目名称],[等级名称],[类别],[类型],[公称直径],")
|
|
_T("[端面],[压力],[描述],[管线名称],[图纸号],[$])")
|
|
_T(" values ('%s','%s','%s','%s',%d,'%s',%g,'%s','%s','%s',[~])"),
|
|
sTxt1, sTxt2, sTxt3, sTxt4,
|
|
_ttoi(sTxt5), sTxt6, _ttof(sTxt7), sTxt8,
|
|
sPipeNo, m_sDrawNo);
|
|
if (mapKey2Len.Lookup(sSQL, sVal))
|
|
{
|
|
dLen += _ttof(sVal);
|
|
sVal.Format(_T("%g"), dLen);
|
|
mapKey2Len.SetAt(sSQL, sVal);
|
|
}
|
|
else
|
|
{
|
|
sVal.Format(_T("%g"), dLen);
|
|
mapKey2Len.SetAt(sSQL, sVal);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|