package repository import ( "fmt" "joylink.club/rtsssimulation/repository/model/proto" "joylink.club/rtsssimulation/util/number" ) // 物理区段 type PhysicalSection struct { Identity len int32 //长度 mm checkPoints []*CheckPoint //将此区段分隔出来的所有(非区段边界)检测点 // A/B端关联的设备端口(非道岔物理区段/道岔) aRelation DevicePort bRelation DevicePort // 非道岔物理区段A/B端的公里标 aKm *proto.Kilometer bKm *proto.Kilometer turnouts []*Turnout //道岔物理区段关联的道岔 // 关联的设备(目前有信号机、应答器、(非区段边界)检测点) devices []Identity //aKm/bKm对应的LinkPosition aLinkPosition *LinkPosition bLinkPosition *LinkPosition //在Link上的区间(start小于end) linkRanges []*LinkRange //物理区段所属集中站 centralizedStation string // 所属站台 platform *Platform } func NewPhysicalSection(id string) *PhysicalSection { return &PhysicalSection{ Identity: identity{id, proto.DeviceType_DeviceType_PhysicalSection}, } } func (p *PhysicalSection) bindLinkRange(link *Link, one int64, two int64) { p.linkRanges = append(p.linkRanges, &LinkRange{ link: link, start: number.Min(one, two), end: number.Max(one, two), }) } func (s *PhysicalSection) PortNum() int { return 2 } func (s *PhysicalSection) ALinkPosition() *LinkPosition { return s.aLinkPosition } func (s *PhysicalSection) BLinkPosition() *LinkPosition { return s.bLinkPosition } func (s *PhysicalSection) ARelation() DevicePort { return s.aRelation } func (s *PhysicalSection) BRelation() DevicePort { return s.bRelation } func (s *PhysicalSection) AKilometer() *proto.Kilometer { return s.aKm } func (s *PhysicalSection) BKilometer() *proto.Kilometer { return s.bKm } // IsAxleSection 判断是否为计轴区段 func (s *PhysicalSection) IsAxleSection() (bool, error) { if len(s.checkPoints) > 0 { axleCount := 0 for _, cp := range s.checkPoints { if cp.pointType == proto.CheckPointType_AxleCounter { axleCount++ } } if axleCount == len(s.checkPoints) { return true, nil } else if axleCount == 0 { return false, nil } else { //axleCount>0&&axleCount