rts-sim-testing-service/ats/verify/simulation/wayside/model/section/link_section_model.go
2023-07-31 15:59:23 +08:00

118 lines
2.6 KiB
Go
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.

package section
import (
"fmt"
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/face"
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/model/ref"
)
// 相邻端点(车档、计轴检测点、道岔岔心)定义的Link区段
// 地图做数据时link区段的A端在左link区段的B端在右即上行方向A->B,下行方向B->A
type LinkSectionModel struct {
//轨道基本信息
face.DeviceModel
//true - 上行false - 下行
Up bool
//link 的A端连接道岔
SwitchRefA *ref.SwitchRef
//link 的B端连接道岔
SwitchRefB *ref.SwitchRef
//link 的A端连接另一个link
LinkRefA *ref.LinkRef
//link 的B端连接另一个link
LinkRefB *ref.LinkRef
//link 的A端关联的计轴检测点
AxlePointA face.AxlePointDeviceModeller
//link 的B端关联的计轴检测点
AxlePointB face.AxlePointDeviceModeller
}
// 获取A端端点的图形id
func (dm *LinkSectionModel) FindPointAGraphicId() (string, error) {
if dm.SwitchRefA != nil {
return dm.SwitchRefA.SwitchDevice.GetGraphicId(), nil
}
if dm.AxlePointA != nil {
return dm.AxlePointA.GetGraphicId(), nil
}
return "", fmt.Errorf("gid为[%s]的A端端点不存在", dm.GraphicId)
}
// 获取B端端点的图形id
func (dm *LinkSectionModel) FindPointBGraphicId() (string, error) {
if dm.SwitchRefB != nil {
return dm.SwitchRefB.SwitchDevice.GetGraphicId(), nil
}
if dm.AxlePointB != nil {
return dm.AxlePointB.GetGraphicId(), nil
}
return "", fmt.Errorf("gid为[%s]的B端端点不存在", dm.GraphicId)
}
// 统计轨道端点数量值为2才是正确的
func (dm *LinkSectionModel) EndPointsCount() int {
var count int = 0
if dm.AxlePointA != nil {
count++
}
if dm.AxlePointB != nil {
count++
}
if dm.SwitchRefA != nil {
count++
}
if dm.SwitchRefB != nil {
count++
}
return count
}
// 统计轨道两端连接设备的数量,值为1或2
func (dm *LinkSectionModel) RelationCount() int {
var count int = 0
if dm.SwitchRefA != nil {
count++
}
if dm.SwitchRefB != nil {
count++
}
if dm.LinkRefA != nil {
count++
}
if dm.LinkRefB != nil {
count++
}
return count
}
// 获取该轨道某个端口连接的轨道,如果有
func (dm *LinkSectionModel) FindLinkRefByPort(portEnum face.PortEnum) *ref.LinkRef {
switch portEnum {
case face.A:
{
return dm.LinkRefA
}
case face.B:
{
return dm.LinkRefB
}
}
return nil
}
// 获取该轨道某个端口连接的道岔,如果有
func (dm *LinkSectionModel) FindSwitchRefByPort(portEnum face.PortEnum) *ref.SwitchRef {
switch portEnum {
case face.A:
{
return dm.SwitchRefA
}
case face.B:
{
return dm.SwitchRefB
}
}
return nil
}