@@ -94,6 +94,72 @@ namespace
return false ;
}
// 断管:把管线在阀门两端各切一刀,原来的管留一段、克隆出来一段。
// 老代码里是 TDbPipeLine::SplitWPipe( PipelineCmd 模块,我们链不到),
// 但它收尾时用的就是 AecDbEwPipe::SetStartPoint/SetEndPoint 挪管端,
// 这里照那个思路做:靠起点的那端给原管、另一端给克隆出来的新管。
bool SplitPipeAtValve ( AecDbEwPipe * pPipe , AecDbEwEquipment * pEqu , std : : wstring & err )
{
if ( pPipe = = NULL | | pEqu = = NULL ) { err = L " 断管缺管线或阀门 " ; return false ; }
AcGePoint3d ptA ( 0.0 , 0.0 , 0.0 ) , ptB ( 0.0 , 0.0 , 0.0 ) ;
AecInterface inf1 , inf2 ;
: : memset ( & inf1 , 0 , sizeof ( AecInterface ) ) ;
: : memset ( & inf2 , 0 , sizeof ( AecInterface ) ) ;
AecMInterfaces * pInf = dynamic_cast < AecMInterfaces * > ( pEqu ) ;
if ( pInf = = NULL | | pInf - > GetInterfaceCount ( ) < 2 ) { err = L " 阀门取不到两个接口 " ; return false ; }
if ( ! pInf - > GetInterface ( 0 , inf1 ) | | ! pInf - > GetInterface ( 1 , inf2 ) )
{
err = L " 阀门接口取点失败 " ;
return false ;
}
AcGePoint3d ptSta ( 0.0 , 0.0 , 0.0 ) , ptEnd ( 0.0 , 0.0 , 0.0 ) ;
pPipe - > getStartPoint ( ptSta ) ;
pPipe - > getEndPoint ( ptEnd ) ;
// 哪一端离管起点近,就把那一端留给原管
if ( inf1 . ptPos . distanceTo ( ptSta ) < = inf2 . ptPos . distanceTo ( ptSta ) )
{
ptA = inf1 . ptPos ; // 原管 end
ptB = inf2 . ptPos ; // 新管 start
}
else
{
ptA = inf2 . ptPos ;
ptB = inf1 . ptPos ;
}
// 新的一段:从阀门另一端到原来的终点
AcDbEntity * pClone = ( AcDbEntity * ) pPipe - > clone ( ) ;
AecDbEwPipe * pNewPipe = ( pClone ! = NULL ) ? AecDbEwPipe : : cast ( pClone ) : NULL ;
if ( pNewPipe = = NULL )
{
delete pClone ;
err = L " 复制管线失败 " ;
return false ;
}
pNewPipe - > SetStartPoint ( ptB ) ;
pNewPipe - > SetEndPoint ( ptEnd ) ;
AcDbObjectId idNew ;
if ( addToSpace ( pNewPipe , & idNew ) ! = Acad : : eOk )
{
delete pNewPipe ;
err = L " 新管段入库失败 " ;
return false ;
}
touchEntity ( pNewPipe ) ;
pNewPipe - > close ( ) ;
// 原管:终点缩到阀门这一端
pPipe - > SetEndPoint ( ptA ) ;
touchEntity ( pPipe ) ;
return true ;
}
// 收尾:图层 + 管网系统 + 母体管线 + 入库
bool PlaceEquipment ( AecDbEwEquipment * pEqu , AcDbEntity * pPipe , const AcGePoint3d & ptIns ,
const AcGeVector3d & vtDir , const nlohmann : : json & a , std : : wstring & err )
@@ -160,6 +226,7 @@ public:
" dn_mm " : { " type " : " number " , " description " : " 公称直径 DN(毫米) " } ,
" pn " : { " type " : " number " , " description " : " 压力等级(MPa),缺省 1.0 " } ,
" has_flange " : { " type " : " boolean " , " description " : " 是否带法兰,缺省否 " } ,
" break_pipe " : { " type " : " boolean " , " description " : " 是否在插入处把管线断开(缺省是);法兰对接还没做 " } ,
" idx " : { " type " : " integer " , " description " : " 同类型有多个规格时选第几个(0 起),缺省 0 " } ,
" system " : { " type " : " string " , " description " : " 管网系统名(缺省跟管线) " } ,
" layer " : { " type " : " string " , " description " : " 图层,缺省 LAY_PIPE_OUTSIDE " } ,
@@ -185,7 +252,7 @@ public:
if ( hasKey ( args , " pipe " ) )
{
const std : : wstring sPipe = wstrOr ( args , " pipe " , L " " ) ;
pPipe = openByHandle ( acharToUtf8 ( sPipe . c_str ( ) ) , AcDb : : kForRead ) ;
pPipe = openByHandle ( acharToUtf8 ( sPipe . c_str ( ) ) , AcDb : : kForWrite ) ; // 断管要改端点
if ( pPipe = = NULL )
return errJson ( kErrNotFound , L " 按 handle 打不开管线: " + sPipe ) ;
}
@@ -256,6 +323,19 @@ public:
return errJson ( kErrInternal , std : : wstring ( L " 加入模型空间失败,err= " ) + std : : to_wstring ( ( int ) es ) ) ;
}
touchEntity ( pEqu ) ;
// 断管(老代码里的 SplitWPipe):缺省开,管线要在插入点断开
bool bSplit = hasKey ( args , " break_pipe " ) ? ( intOr ( args , " break_pipe " , 1 ) ! = 0 ) : true ;
bool bSplitOk = false ;
if ( bSplit & & pPipe ! = NULL )
{
AecDbEwPipe * pPW = AecDbEwPipe : : cast ( pPipe ) ;
if ( pPW ! = NULL )
bSplitOk = SplitPipeAtValve ( pPW , pEqu , err ) ;
else
err = L " pipe 不是管道(AecDbEwPipe),不打断管 " ;
}
pEqu - > close ( ) ;
if ( pPipe ! = NULL ) pPipe - > close ( ) ;
@@ -267,6 +347,8 @@ public:
body [ " position " ] = { ptIns . x , ptIns . y , ptIns . z } ;
body [ " direction " ] = { vtDir . x , vtDir . y , vtDir . z } ;
body [ " handle " ] = HandleOfId ( idNew ) ;
body [ " pipe_split " ] = bSplitOk ;
if ( ! bSplitOk & & bSplit ) body [ " split_error " ] = acharToUtf8 ( err . c_str ( ) ) ;
return okJson ( body ) ;
}
} ;