Files
envi-code/SourceCode/Code2026/tg_shs/shs_pipewire/DbLowVoltSys.cpp
T

997 lines
32 KiB
C++
Raw Normal View History

2026-10-04 00:04:20 +08:00
// DbLowVoltSys.cpp: implementation of the TDbLowVoltSys class.
2026-09-28 15:28:50 +08:00
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DbLowVoltSys.h"
#include "PipeWireMonitor.h"
extern void SplitBlkStr(const TCHAR *pszInput, CString &sTK, CString &sRecord);
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Acad::ErrorStatus TDrawerData::dwgInFields (AcDbDwgFiler* pFiler)
{
XString xsName;
ReadString(pFiler, xsName);
m_csLoopName = (const TCHAR*)xsName;
ReadString(pFiler, xsName);
m_csPurpose = (const TCHAR*)xsName;
// pFiler->readItem(&m_nPower);
// pFiler->readItem(&m_nKx);
// pFiler->readItem(&m_nCos);
// pFiler->readItem(&m_nCalcPower);
// pFiler->readItem(&m_nCalcCurrent);
pFiler->readItem(&m_nLength);
pFiler->readItem(&m_ID);
// pFiler->readItem((AcGePoint3d *)&m_ptIns);
// pFiler->readItem((AcGePoint3d *)&m_ptSheetCol);
return pFiler->filerStatus();
}
Acad::ErrorStatus TDrawerData::dwgOutFields(AcDbDwgFiler* pFiler) const
{
pFiler->writeItem((const TCHAR *)m_csLoopName);
pFiler->writeItem((const TCHAR *)m_csPurpose);
// pFiler->writeItem(m_nPower);
// pFiler->writeItem(m_nKx);
// pFiler->writeItem(m_nCos);
// pFiler->writeItem(m_nCalcPower);
// pFiler->writeItem(m_nCalcCurrent);
pFiler->writeItem(m_nLength);
pFiler->writeItem(m_ID);
// pFiler->writeItem((const AcGePoint3d &)m_ptIns);
// pFiler->writeItem((const AcGePoint3d &)m_ptSheetCol);
return pFiler->filerStatus();
}
Acad::ErrorStatus TCabinetData::dwgInFields (AcDbDwgFiler* pFiler)
{
XString xsName;
ReadString(pFiler, xsName);
m_csName = (const TCHAR*)xsName;
ReadString(pFiler, xsName);
m_csSpec = (const TCHAR*)xsName;
pFiler->readItem(&m_iType);
Adesk::UInt16 nNum=0;
pFiler->readItem(&nNum);
m_lstDrawer.Reset();
for(Adesk::UInt16 i=0; i<nNum; i++) {
TDrawerData *pData = new TDrawerData;
pData->dwgInFields(pFiler);
m_lstDrawer.Append(pData);
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TCabinetData::dwgOutFields(AcDbDwgFiler* pFiler) const
{
pFiler->writeItem((const TCHAR *)m_csName);
pFiler->writeItem((const TCHAR *)m_csSpec);
pFiler->writeItem(m_iType);
Adesk::UInt16 nCount=(Adesk::UInt16)m_lstDrawer.Length();
pFiler->writeItem(nCount);
for(Adesk::UInt16 i=0; i<nCount; i++) {
m_lstDrawer[i].dwgOutFields(pFiler);
}
return pFiler->filerStatus();
}
TCabinetData & TCabinetData::operator = (const TCabinetData &src)
{
CopyObject(src, *this);
return *this;
}
TCabinetData::TCabinetData(const TCabinetData &src)
{
*this = src;
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ACRX_DXF_DEFINE_MEMBERS(ATSLowVoltSys, ATSSheet, AcDb::kDHL_CURRENT,
AcDb::kMReleaseCurrent, 1, ATS_LOWVOLTSYS,
2026-10-04 00:04:20 +08:00
"ATS_LOWVOLTSYS图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
2026-09-28 15:28:50 +08:00
IMPLEMENT_TENTBASE(TDbLowVoltSys);
const Adesk::UInt8 TDbLowVoltSys::g_nVersion = 1;
TDbLowVoltSys::TDbLowVoltSys()
{
m_dBusWidth = 2;
m_bIsBusNull = TRUE;
m_bNeedCalc = TRUE;
m_dSpare = 0;
m_dCalcFactor = 1;
m_bIsVerOutLine = TRUE;
}
TDbLowVoltSys::~TDbLowVoltSys()
{
}
void TDbLowVoltSys::CopyPropertiesFrom(AcDbEntity *pSrc,unsigned gMatchFlag)
{
assertWriteEnabled();
TDbLowVoltSys *pSect = TDbLowVoltSys::cast(pSrc);
if(pSect) {
}
TDbEntity::CopyPropertiesFrom(pSrc, gMatchFlag);
}
Acad::ErrorStatus TDbLowVoltSys::subGetClassID(CLSID* pClsid) const
{
// *pClsid = CLSID_ComVerticalSection;
return Acad::eOk;
}
2026-10-04 00:04:20 +08:00
// 取得所有的夹点
2026-09-28 15:28:50 +08:00
Acad::ErrorStatus
TDbLowVoltSys::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
Acad::ErrorStatus es=Acad::eOk;
assertReadEnabled();
es=TDbSheet::subGetGripPoints(gripPoints,osnapModes,geomIds);
return es;
}
2026-10-04 00:04:20 +08:00
// 功能: 夹点操作
2026-09-28 15:28:50 +08:00
Acad::ErrorStatus
TDbLowVoltSys::subMoveGripPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset)
{
// assertWriteEnabled();
// Acad::ErrorStatus es=Acad::eOk;
// es=TDbSheet::subMoveGripPointsAt(indices,offset);
// return es;
assertWriteEnabled();
XPoint vtOffset(offset[0], offset[1]);
if(indices.length()>1) {
m_ptLocation += vtOffset;
return Acad::eOk;
}
double nRotWcs=Layout2Wcs(m_nRotation);
int idx = indices[0];
if(idx == 0)
return TDbSheet::subMoveGripPointsAt(indices,offset);
2026-10-04 00:04:20 +08:00
//以下修改TDbSheet部分程序,如果2夹点合并,要删除抽屉柜
2026-09-28 15:28:50 +08:00
XVector3D vt(cos(nRotWcs), sin(nRotWcs));
double nWidth = (vt&vtOffset);
int nColNum=GetColumnNum();
int iVert=1;
for(int iCol=0; iCol<nColNum; iCol++) {
TSheetColumn &column=*m_columns[iCol];
if(column.AllowSizing()) {
iVert++;
if(idx==iVert) {
if(column.GetWidth()*GetPScale()+nWidth<_distSnap) { //Delete column
2026-10-04 00:04:20 +08:00
if(idx > 3) //头2列如果被删除,会崩溃 sr 2009-4-10
2026-09-28 15:28:50 +08:00
RemoveDrawer(iCol);
return Acad::eOk;
// RemoveColumn(iCol);
} else {
column.SetWidth(column.GetWidth()+nWidth/GetPScale());
CalculateRowHeight(0, GetRowNum()-1);
}
return Acad::eOk;
}
}
}
XVector3D vt1(cos(nRotWcs-PI/2), sin(nRotWcs-PI/2));
double nHeight = (vt1&vtOffset);
int nRowNum=GetRowNum();
for(int iRow=0; iRow<nRowNum; iRow++) {
TSheetRow &row=*m_rows[iRow];
if(row.GetRowHeightStyle()==TSheetRow::kFree ||
row.GetRowHeightStyle()==TSheetRow::kAtLeast ||
(row.GetRowHeightStyle()==TSheetRow::kParent &&
(m_rowHeightStyle==TSheetRow::kFree || m_rowHeightStyle==TSheetRow::kAtLeast))
) {
iVert++;
if(idx==iVert) {
if(row.GetHeight()*GetPScale()+nHeight<_distSnap){
RemoveDrawer(iCol);
return Acad::eOk;
// RemoveRow(iRow);
}
else {
double h=row.GetHeight()+nHeight/GetPScale();
if(row.GetRowHeightStyle()==TSheetRow::kAtLeast ||
(row.GetRowHeightStyle()==TSheetRow::kParent &&
m_rowHeightStyle==TSheetRow::kAtLeast)
) {
if(h>GetRowHeight(TRUE))
row.SetHeight(h);
else
row.SetHeight(GetRowHeight(TRUE));
} else
row.SetHeight(h);
}
return Acad::eOk;
}
}
}
return Acad::eOk;
}
Acad::ErrorStatus
TDbLowVoltSys::GetGripText(int idx, CString &cs) const
{
Acad::ErrorStatus es=Acad::eOk;
es=TDbSheet::GetGripText(idx, cs);
return es;
}
2026-10-04 00:04:20 +08:00
// 从DWG读入数据:
2026-09-28 15:28:50 +08:00
Acad::ErrorStatus TDbLowVoltSys::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = TDbEntity::dwgInFields(pFiler);
if(es != Acad::eOk) return es;
es = TDbSheet::dwgInFields(pFiler);
if(es != Acad::eOk) return es;
Adesk::UInt8 nVer;
pFiler->readItem(&nVer);
if(nVer>g_nVersion) {// Version is too new
return Acad::eMakeMeProxy;
}
pFiler->readItem(&m_dBusWidth);
pFiler->readItem(&m_dSpare);
pFiler->readItem(&m_dCalcFactor);
//pFiler->readItem(&m_bIsBusNull);
//pFiler->readItem(&m_bNeedCalc);
//pFiler->readItem(&m_bIsVerOutLine);
FilerRead(pFiler, m_bIsBusNull);
FilerRead(pFiler, m_bNeedCalc);
FilerRead(pFiler, m_bIsVerOutLine);
pFiler->readItem(&m_idBusLayer);
ReadString(pFiler,m_sSpare);
Adesk::UInt16 nNum=0;
pFiler->readItem(&nNum);
m_lstCabinet.Reset();
for(Adesk::UInt16 i=0; i<nNum; i++) {
TCabinetData *pData = new TCabinetData;
pData->dwgInFields(pFiler);
m_lstCabinet.Append(pData);
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbLowVoltSys::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = TDbEntity::dwgOutFields(pFiler);
if(es != Acad::eOk) return es;
es = TDbSheet::dwgOutFields(pFiler);
if(es != Acad::eOk) return es;
pFiler->writeItem(g_nVersion);
pFiler->writeItem(m_dBusWidth);
pFiler->writeItem(m_dSpare);
pFiler->writeItem(m_dCalcFactor);
//pFiler->writeItem(m_bIsBusNull);
//pFiler->writeItem(m_bNeedCalc);
//pFiler->writeItem(m_bIsVerOutLine);
FilerWrite(pFiler, m_bIsBusNull);
FilerWrite(pFiler, m_bNeedCalc);
FilerWrite(pFiler, m_bIsVerOutLine);
pFiler->writeItem(m_idBusLayer);
pFiler->writeItem((const TCHAR *)m_sSpare);
Adesk::UInt16 nCount=(Adesk::UInt16)m_lstCabinet.Length();
pFiler->writeItem(nCount);
for(Adesk::UInt16 i=0; i<nCount; i++) {
m_lstCabinet[i].dwgOutFields(pFiler);
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbLowVoltSys::dxfInFields(AcDbDxfFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es=Acad::eOk;
es=TDbSheet::dxfInFields(pFiler);
return es;
}
Acad::ErrorStatus TDbLowVoltSys::dxfOutFields(AcDbDxfFiler* pFiler) const
{
Acad::ErrorStatus es=Acad::eOk;
es=TDbSheet::dxfOutFields(pFiler);
pFiler->writeUInt8(AcDb::kDxfInt8, 1);
return es;
}
Acad::ErrorStatus
TDbLowVoltSys::subTransformBy(const AcGeMatrix3d& xform)
{
assertWriteEnabled();
Acad::ErrorStatus es=Acad::eOk;
es=TDbSheet::subTransformBy(xform);
// int nCount = m_lstCabinet.Length();
// for(int i=0; i<nCount; i++) {
// int num = m_lstCabinet[i]->m_lstDrawer.Length();
// for(int j=0;j<num;j++){
// XPoint pt = m_lstCabinet[i]->m_lstDrawer[j]->m_ptIns;
// pt.TransformBy(xform);
// m_lstCabinet[i]->m_lstDrawer[j]->m_ptIns = pt;
// }
// }
return es;
}
2026-10-04 00:04:20 +08:00
//在位编辑 如果是第一行,执行对象编辑
2026-09-28 15:28:50 +08:00
TSubText* TDbLowVoltSys::GetSubText(long iText)const
{
long i = iText;
if(i > 0)
{
i--;
if(i<GetRowNum()*GetColumnNum())
{
long row=iText/GetColumnNum(),col=iText%GetColumnNum();
if(row == 0)
return NULL;
}
else
{
i-=GetRowNum()*GetColumnNum();
const TGridRange*pRange=&m_ranges[i];
if(pRange->GetCoord(TRUE) == 0)
return NULL;
}
}
return TDbSheet::GetSubText(iText);
}
int GetDrawerInsPoint(AcDbHardPointerId id, XPoint &ptCir, XPoint &ptCir2)
{
int idx2(0);
OPENOBJ_BEGIN(id, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
if(pBlock) {
AcDbBlockTableRecordIterator *pIterator = NULL;
pBlock->newIterator(pIterator);
for(pIterator->start(); !pIterator->done(); pIterator->step()){
AcDbEntity *pEnt = NULL;
pIterator->getEntity(pEnt, AcDb::kForRead);
if(pEnt){
AcDbPoint *pll = NULL;
if(pll = AcDbPoint::cast(pEnt)){
idx2++;
if(idx2 == 1)
ptCir = pll->position();
else
ptCir2 = pll->position();
}
pEnt->close();
}
}
delete pIterator;
}
OPENOBJ_END();
return idx2;
}
XPoint TDbLowVoltSys::GetCellLeftUpPoint(int nRow, int nCol) const
{
const TGridCell *pCell=(*this)(nRow, nCol);
double x=GetColumnsWidth(0, nCol-1, FALSE);
double y=GetRowsHeight(0, nRow-1, FALSE);
XPoint ptTopLeft=GetTopLeft(FALSE);
XPoint ptDest;
ads_polar(ptTopLeft, Layout2Wcs(m_nRotation), x, ptDest);
ads_polar(XPoint(ptDest), Layout2Wcs(m_nRotation)-PI/2, y, ptDest);
return ptDest;
}
XPoint TDbLowVoltSys::GetDrawerCellSize(int nRow, int nCol) const
{
const TGridCell &cell=*(*this)(nRow, nCol);
double w, h;
w=GetColumnWidth(nCol, FALSE);
h=GetRowHeight(nRow, FALSE);
return XPoint(w, h);
}
void TDbLowVoltSys::DrawPLine(XPoint ptStart, XPoint ptEnd, XExplodeDraw &dc) const
{
AcDbObjectId idLayerOld=dc.GetLayerId();
dc.SetLayer(m_idBusLayer);
XLine pLine(ptStart, ptEnd, 1);
XCurveSegment seg;
seg = pLine;
XPoly2D poly;
seg.AsPoly2D(poly);
double nWeight = m_dBusWidth*GetPScale();
AcDbPolyline pline;
PolyConvert(poly, pline);
XAcGiViewDraw &viewDraw = (XAcGiViewDraw &)dc;
int nNum = pline.numVerts();
if (nNum > 0) {
for (int k=0;k<nNum; k++) {
pline.setWidthsAt(k,nWeight,nWeight);
}
viewDraw.Polyline(pline);
}
dc.SetLayer(idLayerOld);
}
void GetBlkWidthHeight(AcDbObjectId id, double &dWidth, double &dHeight)
{
CString csBlkName, csDesName;
GetBlkNameById(id, csBlkName, csDesName);
double dScale(2.0);
2026-10-04 00:04:20 +08:00
if(csBlkName.Find(_T("00347")) > 0)//三相电流互感器 进线
2026-09-28 15:28:50 +08:00
dScale = 1.1;
AcDbExtents extents;
AcDbBlockReference insert(AcGePoint3d(0,0,0), id);
if(insert.geomExtentsBestFit(extents)==Acad::eOk) {
XPoint ptMax = extents.maxPoint();
XPoint ptMin = extents.minPoint();
2026-10-04 00:04:20 +08:00
dWidth = (ptMax.x-ptMin.x) * dScale;// 第一次求得的宽度值
2026-09-28 15:28:50 +08:00
//dHeight = ptMax.y-ptMin.y;
2026-10-04 00:04:20 +08:00
dHeight = abs(ptMin.y); //高度只取从插入点到块底部的距离
2026-09-28 15:28:50 +08:00
}
2026-10-04 00:04:20 +08:00
//if(csDesName.Find(_T("进线")) > 0)
2026-09-28 15:28:50 +08:00
// dHeight = dHeight/1.5;
}
Acad::ErrorStatus TDbLowVoltSys::ExplodeOrDraw2d(XExplodeDraw &dc) const
{
2026-10-04 00:04:20 +08:00
// cet 2016.10.17 add 图层关闭时,实体不显示,不进行绘制(打印时,也不会绘制)
2026-09-28 15:28:50 +08:00
AcDbLayerTableRecordPointer player(this->layerId(), AcDb::kForRead);
if (player.openStatus() == Acad::eOk && player->isOff())
{
return Acad::eOk;
}
assertReadEnabled();
TDbSheet::ExplodeOrDraw2d(dc);
if(!objectId())
return Acad::eOk;
2026-10-04 00:04:20 +08:00
if(g_bOsnapExpl && !g_bGetExtents)//不支持求交,速度太慢
2026-09-28 15:28:50 +08:00
return Acad::eOk;
double dBusWidth = m_dBusWidth*GetPScale();
int nCount = m_lstCabinet.Length();
// int nSheetColNum = GetColumnNum();
// return Acad::eOk;
int idx = 0;
for(int i=0; i<nCount; i++) {
int num = m_lstCabinet[i].m_lstDrawer.Length();
BOOL bIsOutLine = FALSE;
if(m_lstCabinet[i].m_iType == 4 && !m_bIsVerOutLine){
bIsOutLine = TRUE;
}
XPoint ptTopLeft0 = GetCellLeftUpPoint(0, idx+2);
ads_polar(ptTopLeft0, m_nLayoutRotation, 10*GetPScale(), ptTopLeft0);
ads_polar(ptTopLeft0, m_nLayoutRotation+PI/2*3, 10*GetPScale(), ptTopLeft0);
AcDbObjectId idLayerOld=dc.GetLayerId();
dc.SetLayer(m_idBusLayer);
XPoint ptTopLeft1 = ptTopLeft0;
for(int j=0;j<num;j++){
XPoint ptTopLeft = GetCellLeftUpPoint(0, idx+2);
XPoint szCell = GetDrawerCellSize(0, idx+2);
XPoint pt, ptCir, ptCir2, ptRight, ptRight2, ptLeft, ptLeft2;
ads_polar(ptTopLeft, m_nLayoutRotation+PI/2*3, 10*GetPScale(), ptLeft);
ads_polar(ptLeft, m_nLayoutRotation, szCell.x/2, pt);
ads_polar(pt, m_nLayoutRotation+PI/2, dBusWidth/2, ptCir);
AcDbHardPointerId id = m_lstCabinet[i].m_lstDrawer[j].m_ID;
if(bIsOutLine){
double dWidth(0), dLength(0);
GetBlkWidthHeight(id, dWidth, dLength);
ads_polar(ptTopLeft0, m_nLayoutRotation+PI/2*3, dWidth, ptTopLeft0);
pt = ptTopLeft0;
ads_polar(pt, m_nLayoutRotation+PI, dBusWidth/2, ptCir);
}
OPENOBJ_BEGIN(id, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
if(pBlock) {
AcGeScale3d scale(1,1,1);
if(bIsOutLine)
dc.DrawBlock(*pBlock, pt ,scale, m_nLayoutRotation+PI/2, TRUE);
else
dc.DrawBlock(*pBlock, pt ,scale, m_nLayoutRotation, TRUE);
}
OPENOBJ_END();
2026-10-04 00:04:20 +08:00
if(GetDrawerInsPoint(id, ptCir, ptCir2) > 0){ //返回多个点
2026-09-28 15:28:50 +08:00
AcDbBlockReference blkRef;
blkRef.setBlockTableRecord(id);
blkRef.setPosition(pt);
blkRef.setRotation(m_nLayoutRotation);
blkRef.setScaleFactors(AcGeScale3d(1,1,1));
2026-10-04 00:04:20 +08:00
AcGeMatrix3d matrixRef = blkRef.blockTransform();//得到图块那2个点的矩阵
2026-09-28 15:28:50 +08:00
ptCir.TransformBy(matrixRef);
ads_polar(ptCir, m_nLayoutRotation+PI/2, dBusWidth/2, ptCir);
if(!!ptCir2){
ptCir2.TransformBy(matrixRef);
ads_polar(ptCir2, m_nLayoutRotation+PI/2, dBusWidth/2, ptCir2);
if(m_bIsBusNull)
dc << XCircle(ptCir2, dBusWidth/2);
}
}
ads_polar(ptLeft, m_nLayoutRotation, szCell.x, ptRight);
ads_polar(ptLeft, m_nLayoutRotation+PI/2, dBusWidth, ptLeft2);
ads_polar(ptRight, m_nLayoutRotation+PI/2, dBusWidth, ptRight2);
if(i == 0 && j == 0){
ads_polar(ptLeft, m_nLayoutRotation, GetPScale()*2, ptLeft);
}
if(i == nCount - 1 && j == num - 1){
ads_polar(ptRight, m_nLayoutRotation+PI, GetPScale()*2, ptRight);
}
XPoint ptMid, ptMid2, ptCirLeft, ptCirRight;
2026-10-04 00:04:20 +08:00
if(!!ptCir2){//母联
2026-09-28 15:28:50 +08:00
if(ptCir.x < ptCir2.x){
ptCirLeft = ptCir;
ptCirRight = ptCir2;
}
else{
ptCirLeft = ptCir2;
ptCirRight = ptCir;
}
ads_polar(ptCirLeft, m_nLayoutRotation, GetPScale()*2, ptCirLeft);
ads_polar(ptCirRight, m_nLayoutRotation+PI, GetPScale()*2, ptCirRight);
}
2026-10-04 00:04:20 +08:00
//绘制母线
if(!m_bIsBusNull){//实心
2026-09-28 15:28:50 +08:00
ads_polar(ptLeft, m_nLayoutRotation+PI/2, dBusWidth/2, ptLeft);
ads_polar(ptRight, m_nLayoutRotation+PI/2, dBusWidth/2, ptRight);
2026-10-04 00:04:20 +08:00
if(!!ptCir2){//母联
2026-09-28 15:28:50 +08:00
DrawPLine(ptLeft, ptCirLeft, dc);
DrawPLine(ptCirRight, ptRight, dc);
}
else
DrawPLine(ptLeft, ptRight, dc);
}
2026-10-04 00:04:20 +08:00
else{ //空心
2026-09-28 15:28:50 +08:00
// if(!bIsOutLine)
dc << XCircle(ptCir, dBusWidth/2);
if(i == 0 && j == 0){
ads_polar(ptLeft2, m_nLayoutRotation, GetPScale()*2, ptLeft2);
dc << XLine(ptLeft, ptLeft2);
}
if(i == nCount - 1 && j == num - 1){
ads_polar(ptRight2, m_nLayoutRotation+PI, GetPScale()*2, ptRight2);
dc << XLine(ptRight, ptRight2);
}
2026-10-04 00:04:20 +08:00
if(!!ptCir2){//母联
2026-09-28 15:28:50 +08:00
ads_polar(ptCirLeft, m_nLayoutRotation+PI/2*3, dBusWidth/2, ptMid);
ads_polar(ptCirLeft, m_nLayoutRotation+PI/2, dBusWidth/2, ptMid2);
dc << XLine(ptLeft, ptMid);
dc << XLine(ptLeft2, ptMid2);
dc << XLine(ptMid, ptMid2);
ads_polar(ptCirRight, m_nLayoutRotation+PI/2*3, dBusWidth/2, ptMid);
ads_polar(ptCirRight, m_nLayoutRotation+PI/2, dBusWidth/2, ptMid2);
dc << XLine(ptRight, ptMid);
dc << XLine(ptRight2, ptMid2);
dc << XLine(ptMid, ptMid2);
}
else{
dc << XLine(ptLeft, ptRight);
dc << XLine(ptLeft2, ptRight2);
}
}
idx++;
// dc.SetLayer(idLayerOld);
}
ads_polar(ptTopLeft0, m_nLayoutRotation+PI/2*3, 10*GetPScale(), ptTopLeft0);
if(bIsOutLine){
2026-10-04 00:04:20 +08:00
if(!m_bIsBusNull){//实心
2026-09-28 15:28:50 +08:00
DrawPLine(ptTopLeft1, ptTopLeft0, dc);
}
else{
XPoint ptUpLeft, ptLowLeft;
ads_polar(ptTopLeft1, m_nLayoutRotation+PI, dBusWidth, ptUpLeft);
ads_polar(ptTopLeft0, m_nLayoutRotation+PI, dBusWidth, ptLowLeft);
dc << XLine(ptUpLeft, ptLowLeft);
dc << XLine(ptTopLeft1, ptTopLeft0);
dc << XLine(ptLowLeft, ptTopLeft0);
}
}
dc.SetLayer(idLayerOld);
}
return Acad::eOk;
}
void TDbLowVoltSys::GetDatas(DList<TCabinetData>& lstCabinet) const
{
int nCount = m_lstCabinet.Length();
for(int i=0; i<nCount; i++) {
TCabinetData *pData = new TCabinetData;
*pData = m_lstCabinet[i];
lstCabinet.Append(pData);
}
}
void TDbLowVoltSys::Reset()
{
assertWriteEnabled();
XPoint ptIns = m_ptLocation;
ads_polar(ptIns, PI/2*3, 10*GetPScale(), ptIns);
ads_polar(ptIns, 0, 30*GetPScale(), ptIns);
int nCount = m_lstCabinet.Length();
double nLongLength(0);
int nColNum = GetDrawerNum();
InitSheet(14, nColNum+2, 7, 50);
int idx(0);
for(int i=0; i<nCount; i++) {
int num = m_lstCabinet[i]->m_lstDrawer.Length();
2026-10-04 00:04:20 +08:00
if(num > 1){//合并单元
2026-09-28 15:28:50 +08:00
MergeCells(0, idx+2, 0, idx+num+1);
}
if(m_lstCabinet[i]->m_iType == 4 && !m_bIsVerOutLine){
double dWidth(0), dLength(0);
AcDbHardPointerId id = m_lstCabinet[i]->m_lstDrawer[0]->m_ID;
GetBlkWidthHeight(id, dWidth, dLength);
dLength += 20*GetPScale();
for(int j=0;j<num;j++){
idx++;
TSheetColumn column;
2026-10-04 00:04:20 +08:00
column.SetWidth(dLength/GetPScale()/num); //序号
2026-09-28 15:28:50 +08:00
SetColumnAt(idx+1, column);
}
}
else{
for(int j=0;j<num;j++){
idx++;
double dWidth(0), dLength(0);
AcDbHardPointerId id = m_lstCabinet[i]->m_lstDrawer[j]->m_ID;
GetBlkWidthHeight(id, dWidth, dLength);
if(dLength > nLongLength)
nLongLength = dLength;
TSheetColumn column;
2026-10-04 00:04:20 +08:00
column.SetWidth(dWidth/GetPScale()); //序号
2026-09-28 15:28:50 +08:00
SetColumnAt(idx+1, column);
}
}
}
TSheetRow *row = GetRow(0);
row->SetRowHeightStyle(TSheetRow::kFree);
row->SetHeight(nLongLength/GetPScale()*1.2);
2026-10-04 00:04:20 +08:00
//表头
2026-09-28 15:28:50 +08:00
TSheetColumn column1;
column1.SetWidth(5);
SetColumnAt(0, column1);
TSheetColumn column2;
column2.SetWidth(25);
SetColumnAt(1, column2);
TGridCell &Cell1=*(*this)(0, 0);
2026-10-04 00:04:20 +08:00
Cell1.SetText(_T("低压单线图 额定电压~380 "));
2026-09-28 15:28:50 +08:00
MergeCells(0, 0, 0, 1);
}
int TDbLowVoltSys::GetDrawerNum()
{
int nCount = m_lstCabinet.Length();
int nColNum(0);
for(int i=0; i<nCount; i++) {
int num = m_lstCabinet[i]->m_lstDrawer.Length();
nColNum += num;
}
return nColNum;
}
void TDbLowVoltSys::ModifyDrawer(int iCol, AcDbObjectId idBlk)
{
assertWriteEnabled();
iCol = iCol - 2;
int nCount = m_lstCabinet.Length();
int idx(0);
BOOL bFlag = FALSE;
for(int i=0; i<nCount; i++) {
int num = m_lstCabinet[i]->m_lstDrawer.Length();
for(int j=0;j<num;j++){
if(iCol == idx){
m_lstCabinet[i]->m_lstDrawer[j]->m_ID = idBlk;
bFlag = TRUE;
break;
}
idx++;
}
if(bFlag)
break;
}
}
void TDbLowVoltSys::InsertDrawer(int iCol, AcDbObjectId idBlk, int iType, BOOL bNewCabinet)
{
assertWriteEnabled();
AddColumnAt(iCol);
double dWidth(0), dLength(0);
GetBlkWidthHeight(idBlk, dWidth, dLength);
TSheetColumn column;
2026-10-04 00:04:20 +08:00
column.SetWidth(dWidth/GetPScale()); //序号
2026-09-28 15:28:50 +08:00
SetColumnAt(iCol, column);
iCol = iCol - 2;
int nCount = m_lstCabinet.Length();
int idx(0);
BOOL bFlag = FALSE;
for(int i=0; i<nCount; i++) {
int num = m_lstCabinet[i]->m_lstDrawer.Length();
for(int j=0;j<num;j++){
if(iCol == idx){
if(bNewCabinet){
TCabinetData *pCabinet = new TCabinetData;
pCabinet->m_iType = iType;
TDrawerData *pDrawer = new TDrawerData;
pDrawer->m_ID = idBlk;
pCabinet->m_lstDrawer.Append(pDrawer);
m_lstCabinet[i];
m_lstCabinet.Insert(pCabinet);
}
else{
TDrawerData *pDrawer = new TDrawerData;
pDrawer->m_ID = idBlk;
m_lstCabinet[i]->m_lstDrawer[j];
m_lstCabinet[i]->m_lstDrawer.Insert(pDrawer);
}
bFlag = TRUE;
break;
}
idx++;
}
if(bFlag)
break;
}
}
void TDbLowVoltSys::RemoveDrawer(int iCol)
{
assertWriteEnabled();
RemoveColumn(iCol);
iCol = iCol - 2;
int nCount = m_lstCabinet.Length();
int idx(0);
BOOL bFlag = FALSE;
for(int i=0; i<nCount; i++) {
int num = m_lstCabinet[i]->m_lstDrawer.Length();
for(int j=0;j<num;j++){
if(iCol == idx){
m_lstCabinet[i]->m_lstDrawer.Remove(j);
if(num == 1)
m_lstCabinet.Remove(i);
bFlag = TRUE;
break;
}
idx++;
}
if(bFlag)
break;
}
}
2026-10-04 00:04:20 +08:00
//初始化表头
2026-09-28 15:28:50 +08:00
void TDbLowVoltSys::SetSheetHead(XStringList &lstHead)
{
assertWriteEnabled();
int nRow = GetRowNum();
int len = lstHead.Length();
int n = len - nRow + 1;
if(n > 0){
for(int j=0;j<n;j++)
AddRowAt(nRow);
}
else if(n < 0){
for(int j=0;j<abs(n);j++)
RemoveRow(len);
}
int iStart(-1), iEnd(-1);
CString csOldTmp;
for(int i=0;i<len;i++){
CString csHead = lstHead[i];
if(csHead.Find(_T("$")) >= 0){
CString csTmp1, csTmp2;
SplitBlkStr(csHead, csTmp1, csTmp2);
if(iStart < 0){
csOldTmp = csTmp1;
iStart = i+1;
}
else if(csOldTmp != csTmp1){
MergeCells(iStart, 0, iEnd, 0);
iStart = i+1;
iEnd = -1;
csOldTmp = csTmp1;
}
else
iEnd = i+1;
TGridCell &Cell1=*(*this)(i+1, 0);
Cell1.SetText(csTmp1);
TGridCell &Cell0=*(*this)(i+1, 1);
Cell0.SetText(csTmp2);
continue;
}
else if(iStart>0 && iEnd>0){
MergeCells(iStart, 0, iEnd, 0);
iStart = -1;
iEnd = -1;
}
TGridCell &Cell2=*(*this)(i+1, 0);
Cell2.SetText(csHead);
MergeCells(i+1, 0, i+1, 1);
2026-10-04 00:04:20 +08:00
if(csHead.Find(_T("开关柜编号")) > -1 || csHead.Find(_T("外形尺寸")) > -1){
2026-09-28 15:28:50 +08:00
int nCount = m_lstCabinet.Length();
int idx(0);
for(int j=0; j<nCount; j++) {
int num = m_lstCabinet[j]->m_lstDrawer.Length();
2026-10-04 00:04:20 +08:00
if(num > 1){//合并单元
2026-09-28 15:28:50 +08:00
MergeCells(i+1, idx+2, i+1, idx+num+1);
}
idx = idx+num;
}
}
}
if(iStart > 0 && iEnd > 0){
2026-10-04 00:04:20 +08:00
MergeCells(iStart, 0, iEnd, 0);//主要设备
2026-09-28 15:28:50 +08:00
}
}
void TDbLowVoltSys::SetDatas(DList<TCabinetData>& lstCabinet)
{
assertWriteEnabled();
m_lstCabinet.Reset();
int nCount = lstCabinet.Length();
int nColNum(0);
for(int i=0; i<nCount; i++) {
TCabinetData *pData = new TCabinetData;
2026-10-04 00:04:20 +08:00
*pData = *lstCabinet[i];//值拷贝
2026-09-28 15:28:50 +08:00
int num = pData->m_lstDrawer.Length();
m_lstCabinet.Append(pData);
nColNum += num;
}
Reset();
}
void TDbLowVoltSys::Calc()
{
assertWriteEnabled();
int nRow = GetRowNum();
int nPowerRow(-1), nKxRow(-1), nCosRow(-1), nCurrentRow(-1);
for(int n=0;n<nRow;n++){
TGridCell &Cell1=*(*this)(n, 0);
CString csText = Cell1.GetText();
2026-10-04 00:04:20 +08:00
if(csText.Find(_T("设备容量")) > -1)
2026-09-28 15:28:50 +08:00
nPowerRow = n;
2026-10-04 00:04:20 +08:00
if(csText.Find(_T("需用系数")) > -1)
2026-09-28 15:28:50 +08:00
nKxRow = n;
2026-10-04 00:04:20 +08:00
if(csText.Find(_T("功率因数")) > -1)
2026-09-28 15:28:50 +08:00
nCosRow = n;
2026-10-04 00:04:20 +08:00
if(csText.Find(_T("计算电流")) > -1)
2026-09-28 15:28:50 +08:00
nCurrentRow = n;
}
2026-10-04 00:04:20 +08:00
if(nPowerRow < 0 || nKxRow < 0 || nCosRow < 0 || nCurrentRow < 0)//不需要计算
2026-09-28 15:28:50 +08:00
return;
int idx(2);
int nCount = m_lstCabinet.Length();
double nAllPower(0), nAllCalaPower(0), nAllNoPower(0);
for(int i=0; i<nCount; i++) {
int num = m_lstCabinet[i]->m_lstDrawer.Length();
if(m_lstCabinet[i]->m_iType == 4){
for(int j=0;j<num;j++){
TGridCell &Cell1=*(*this)(nPowerRow, idx);
CString csPower = Cell1.GetText();
TGridCell &Cell2=*(*this)(nKxRow, idx);
CString csKx = Cell2.GetText();
TGridCell &Cell3=*(*this)(nCosRow, idx);
CString csCos = Cell3.GetText();
if(csPower == _T("") || csKx == _T("") || csCos == _T("")){
idx++;
continue;
}
nAllPower += _tstof(csPower);
2026-10-04 00:04:20 +08:00
// 有功功率 Pjs = 需用系数×额定容量*同时系数
2026-09-28 15:28:50 +08:00
double nCalcPower = _tstof(csPower) * _tstof(csKx) * m_dCalcFactor;
nAllCalaPower += nCalcPower;
2026-10-04 00:04:20 +08:00
double nTemp = acos(_tstof(csCos)); //φ
// ********* 无功功率 Qjs ************* Qjs = Pjs*tgφ*同时系数
2026-09-28 15:28:50 +08:00
double singlePowerNo = nCalcPower * tan(nTemp)*m_dCalcFactor;
nAllNoPower += singlePowerNo;
double nCalcCurrent = nCalcPower / sqrt(3.0) / 0.38 / _tstof(csCos);
TGridCell &Cell4=*(*this)(nCurrentRow, idx);
Cell4.SetText(XString(_T("%.1f"), nCalcCurrent));
idx++;
}
}
else
idx += num;
}
idx = 2;
double nCountPowerView = sqrt(nAllNoPower*nAllNoPower + nAllCalaPower*nAllCalaPower);
double nAllCalcCurrent = nCountPowerView /sqrt(3.0)/ 380 * 1000;
2026-10-04 00:04:20 +08:00
double nAllCos = cos(atan(nAllNoPower / nAllCalaPower)); //总功率因数 = cos(atan(无功功率/有功功率))
double nAllKx = nAllCalaPower / nAllPower; //有功功率 Pjs = Kx × Pe P2
2026-09-28 15:28:50 +08:00
2026-10-04 00:04:20 +08:00
if(nAllPower < 0.001 || nAllCalcCurrent < 0.001 || nAllCos < 0.001 || nAllKx < 0.001)//不需要计算
2026-09-28 15:28:50 +08:00
return;
for(i=0; i<nCount; i++) {
int num = m_lstCabinet[i]->m_lstDrawer.Length();
2026-10-04 00:04:20 +08:00
if(m_lstCabinet[i]->m_iType == 1 || m_lstCabinet[i]->m_iType == 5){ //进线
2026-09-28 15:28:50 +08:00
TGridCell &Cell1=*(*this)(nPowerRow, idx);
Cell1.SetText(XString(_T("%.0f"), nAllPower));
TGridCell &Cell2=*(*this)(nCurrentRow, idx);
Cell2.SetText(XString(_T("%.1f"), nAllCalcCurrent));
TGridCell &Cell3=*(*this)(nCosRow, idx);
Cell3.SetText(XString(_T("%.2f"), nAllCos));
TGridCell &Cell4=*(*this)(nKxRow, idx);
Cell4.SetText(XString(_T("%.2f"), nAllKx));
}
idx += num;
}
}
Acad::ErrorStatus TDbLowVoltSys::subClose()
{
Acad::ErrorStatus es = TDbSheet::subClose();
if(es==Acad::eOk && g_nCmdReactor!=CMD_UPDATE
&& isModified() && database()==acdbCurDwg() && m_bNeedCalc)
{
Calc();
}
return es;
}
2026-10-04 00:04:20 +08:00
//取动态属性显示数据
2026-09-28 15:28:50 +08:00
void TDbLowVoltSys::GetTips(DList<TObjInfoUnit> &info) const
{
2026-10-04 00:04:20 +08:00
info.Append(new TObjInfoUnit(_T("对象类型"), _T("低压单选系统图")));
2026-09-28 15:28:50 +08:00
}
void InitDbLowVoltSys(BOOL bTrue)
{
if(bTrue) {
TDbLowVoltSys::rxInit();
TDbLowVoltSys::InitMatchProtocol(TRUE);
} else {
TDbLowVoltSys::InitMatchProtocol(FALSE);
deleteAcRxClass(TDbLowVoltSys::desc());
}
}