Files
envi-code/SourceCode/Code2026/tg_shs/shs_pipewire/DbLowVoltSys.cpp
T
2026-09-28 15:28:50 +08:00

998 lines
31 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// DbLowVoltSys.cpp: implementation of the TDbLowVoltSys class.
//
//////////////////////////////////////////////////////////////////////
#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,
"ATS_LOWVOLTSYS图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
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;
}
// 取得所有的夹点
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;
}
// 功能: 夹点操作
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);
//以下修改TDbSheet部分程序,如果2夹点合并,要删除抽屉柜
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
if(idx > 3) //头2列如果被删除,会崩溃 sr 2009-4-10
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;
}
// 从DWG读入数据:
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;
}
//在位编辑 如果是第一行,执行对象编辑
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);
if(csBlkName.Find(_T("00347")) > 0)//三相电流互感器 进线
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();
dWidth = (ptMax.x-ptMin.x) * dScale;// 第一次求得的宽度值
//dHeight = ptMax.y-ptMin.y;
dHeight = abs(ptMin.y); //高度只取从插入点到块底部的距离
}
//if(csDesName.Find(_T("进线")) > 0)
// dHeight = dHeight/1.5;
}
Acad::ErrorStatus TDbLowVoltSys::ExplodeOrDraw2d(XExplodeDraw &dc) const
{
// cet 2016.10.17 add 图层关闭时,实体不显示,不进行绘制(打印时,也不会绘制)
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;
if(g_bOsnapExpl && !g_bGetExtents)//不支持求交,速度太慢
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();
if(GetDrawerInsPoint(id, ptCir, ptCir2) > 0){ //返回多个点
AcDbBlockReference blkRef;
blkRef.setBlockTableRecord(id);
blkRef.setPosition(pt);
blkRef.setRotation(m_nLayoutRotation);
blkRef.setScaleFactors(AcGeScale3d(1,1,1));
AcGeMatrix3d matrixRef = blkRef.blockTransform();//得到图块那2个点的矩阵
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;
if(!!ptCir2){//母联
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);
}
//绘制母线
if(!m_bIsBusNull){//实心
ads_polar(ptLeft, m_nLayoutRotation+PI/2, dBusWidth/2, ptLeft);
ads_polar(ptRight, m_nLayoutRotation+PI/2, dBusWidth/2, ptRight);
if(!!ptCir2){//母联
DrawPLine(ptLeft, ptCirLeft, dc);
DrawPLine(ptCirRight, ptRight, dc);
}
else
DrawPLine(ptLeft, ptRight, dc);
}
else{ //空心
// 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);
}
if(!!ptCir2){//母联
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){
if(!m_bIsBusNull){//实心
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();
if(num > 1){//合并单元
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;
column.SetWidth(dLength/GetPScale()/num); //序号
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;
column.SetWidth(dWidth/GetPScale()); //序号
SetColumnAt(idx+1, column);
}
}
}
TSheetRow *row = GetRow(0);
row->SetRowHeightStyle(TSheetRow::kFree);
row->SetHeight(nLongLength/GetPScale()*1.2);
//表头
TSheetColumn column1;
column1.SetWidth(5);
SetColumnAt(0, column1);
TSheetColumn column2;
column2.SetWidth(25);
SetColumnAt(1, column2);
TGridCell &Cell1=*(*this)(0, 0);
Cell1.SetText(_T("低压单线图 额定电压~380 "));
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;
column.SetWidth(dWidth/GetPScale()); //序号
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;
}
}
//初始化表头
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);
if(csHead.Find(_T("开关柜编号")) > -1 || csHead.Find(_T("外形尺寸")) > -1){
int nCount = m_lstCabinet.Length();
int idx(0);
for(int j=0; j<nCount; j++) {
int num = m_lstCabinet[j]->m_lstDrawer.Length();
if(num > 1){//合并单元
MergeCells(i+1, idx+2, i+1, idx+num+1);
}
idx = idx+num;
}
}
}
if(iStart > 0 && iEnd > 0){
MergeCells(iStart, 0, iEnd, 0);//主要设备
}
}
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;
*pData = *lstCabinet[i];//值拷贝
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();
if(csText.Find(_T("设备容量")) > -1)
nPowerRow = n;
if(csText.Find(_T("需用系数")) > -1)
nKxRow = n;
if(csText.Find(_T("功率因数")) > -1)
nCosRow = n;
if(csText.Find(_T("计算电流")) > -1)
nCurrentRow = n;
}
if(nPowerRow < 0 || nKxRow < 0 || nCosRow < 0 || nCurrentRow < 0)//不需要计算
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);
// 有功功率 Pjs = 需用系数×额定容量*同时系数
double nCalcPower = _tstof(csPower) * _tstof(csKx) * m_dCalcFactor;
nAllCalaPower += nCalcPower;
double nTemp = acos(_tstof(csCos)); //φ
// ********* 无功功率 Qjs ************* Qjs = Pjs*tgφ*同时系数
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;
double nAllCos = cos(atan(nAllNoPower / nAllCalaPower)); //总功率因数 = cos(atan(无功功率/有功功率))
double nAllKx = nAllCalaPower / nAllPower; //有功功率 Pjs = Kx × Pe P2
if(nAllPower < 0.001 || nAllCalcCurrent < 0.001 || nAllCos < 0.001 || nAllKx < 0.001)//不需要计算
return;
for(i=0; i<nCount; i++) {
int num = m_lstCabinet[i]->m_lstDrawer.Length();
if(m_lstCabinet[i]->m_iType == 1 || m_lstCabinet[i]->m_iType == 5){ //进线
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;
}
//取动态属性显示数据
void TDbLowVoltSys::GetTips(DList<TObjInfoUnit> &info) const
{
info.Append(new TObjInfoUnit(_T("对象类型"), _T("低压单选系统图")));
}
void InitDbLowVoltSys(BOOL bTrue)
{
if(bTrue) {
TDbLowVoltSys::rxInit();
TDbLowVoltSys::InitMatchProtocol(TRUE);
} else {
TDbLowVoltSys::InitMatchProtocol(FALSE);
deleteAcRxClass(TDbLowVoltSys::desc());
}
}