2024-06-07 18:38:38 +08:00
|
|
|
|
package model
|
|
|
|
|
|
2024-07-10 18:09:16 +08:00
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"log/slog"
|
|
|
|
|
)
|
|
|
|
|
|
2024-06-17 19:45:38 +08:00
|
|
|
|
// 区段
|
2024-06-07 18:38:38 +08:00
|
|
|
|
type Section interface {
|
2024-07-08 19:47:30 +08:00
|
|
|
|
RtssModel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 物理区段(非道岔区段)
|
2024-07-10 18:09:16 +08:00
|
|
|
|
// 用于和道岔连接构成轨道网络
|
|
|
|
|
// 然后使用轨道网络构建link和linkNode形成新的以道岔岔心为节点的网络,用于路径计算等
|
2024-07-08 19:47:30 +08:00
|
|
|
|
type PhysicalSection interface {
|
2024-07-02 18:30:12 +08:00
|
|
|
|
TwoPortsPipeElement
|
2024-07-04 20:16:10 +08:00
|
|
|
|
// 获取A端和B端的公里标
|
2024-07-05 13:22:01 +08:00
|
|
|
|
GetPaKm() *KilometerMark
|
|
|
|
|
GetPbKm() *KilometerMark
|
2024-07-10 18:09:16 +08:00
|
|
|
|
// 计算各个端口到岔心的距离
|
|
|
|
|
CalculateDistance(calculateKmDistance func(km1, km2 *KilometerMark) (int64, error)) error
|
|
|
|
|
GetLength() int64
|
2024-06-17 19:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 18:09:16 +08:00
|
|
|
|
// 道岔区段(道岔物理区段)
|
|
|
|
|
// 道岔处的由至少3个及以上的计轴或绝缘节所确定的区段
|
2024-07-08 19:47:30 +08:00
|
|
|
|
type TurnoutSection interface {
|
|
|
|
|
Section
|
|
|
|
|
// 获取关联的道岔列表
|
|
|
|
|
GetTurnouts() []Turnout
|
2024-07-10 18:09:16 +08:00
|
|
|
|
// 添加关联道岔
|
|
|
|
|
AddTurnout(turnout Turnout)
|
2024-07-08 19:47:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 逻辑区段
|
2024-07-10 18:09:16 +08:00
|
|
|
|
// 是在物理区段基础上进一步细分的区段,为了相对更精细的列车追踪和进路触发等控制
|
|
|
|
|
// 最终映射到link上,做相应的逻辑处理
|
2024-07-08 19:47:30 +08:00
|
|
|
|
type LogicalSection interface {
|
|
|
|
|
Section
|
2024-07-10 18:09:16 +08:00
|
|
|
|
// 所属物理区段(可能是一般物理区段也可能是道岔区段)
|
|
|
|
|
BelongSection() Section
|
2024-07-08 19:47:30 +08:00
|
|
|
|
// 获取A端和B端的公里标
|
|
|
|
|
GetPaKm() *KilometerMark
|
|
|
|
|
GetPbKm() *KilometerMark
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PhysicalSectionImpl struct {
|
2024-07-02 18:30:12 +08:00
|
|
|
|
*TwoPortsPipeElementImpl
|
2024-07-05 13:22:01 +08:00
|
|
|
|
PaKm *KilometerMark
|
|
|
|
|
PbKm *KilometerMark
|
2024-07-10 18:09:16 +08:00
|
|
|
|
len int64
|
2024-06-17 19:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-08 19:47:30 +08:00
|
|
|
|
var _ PhysicalSection = (*PhysicalSectionImpl)(nil)
|
2024-06-24 18:20:11 +08:00
|
|
|
|
|
2024-07-08 19:47:30 +08:00
|
|
|
|
func NewPhysicalSection(uid string) *PhysicalSectionImpl {
|
|
|
|
|
return &PhysicalSectionImpl{
|
2024-07-02 18:30:12 +08:00
|
|
|
|
TwoPortsPipeElementImpl: &TwoPortsPipeElementImpl{
|
2024-06-27 19:59:13 +08:00
|
|
|
|
uid: uid,
|
|
|
|
|
},
|
2024-06-17 19:45:38 +08:00
|
|
|
|
}
|
2024-06-07 18:38:38 +08:00
|
|
|
|
}
|
2024-07-04 20:16:10 +08:00
|
|
|
|
|
2024-07-10 18:09:16 +08:00
|
|
|
|
func (s *PhysicalSectionImpl) GetLength() int64 {
|
|
|
|
|
return s.len
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *PhysicalSectionImpl) CalculateDistance(calculateKmDistance func(km1, km2 *KilometerMark) (int64, error)) error {
|
|
|
|
|
if s.PaKm == nil || s.PbKm == nil {
|
|
|
|
|
return fmt.Errorf("区段公里标不能为空")
|
|
|
|
|
}
|
|
|
|
|
var err error
|
|
|
|
|
s.len, err = calculateKmDistance(s.PaKm, s.PbKm)
|
|
|
|
|
slog.Debug("计算物理区段公里标距离", "uid", s.Uid(), "length", s.len)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-08 19:47:30 +08:00
|
|
|
|
func (s *PhysicalSectionImpl) GetPaKm() *KilometerMark {
|
2024-07-04 20:16:10 +08:00
|
|
|
|
return s.PaKm
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-08 19:47:30 +08:00
|
|
|
|
func (s *PhysicalSectionImpl) GetPbKm() *KilometerMark {
|
2024-07-04 20:16:10 +08:00
|
|
|
|
return s.PbKm
|
|
|
|
|
}
|
2024-07-08 19:47:30 +08:00
|
|
|
|
|
|
|
|
|
type SectionImpl struct {
|
|
|
|
|
uid string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *SectionImpl) Uid() string {
|
|
|
|
|
return s.uid
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _ TurnoutSection = (*TurnoutSectionImpl)(nil)
|
|
|
|
|
|
|
|
|
|
type TurnoutSectionImpl struct {
|
|
|
|
|
*SectionImpl
|
|
|
|
|
Turnouts []Turnout
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewTurnoutSection(uid string) *TurnoutSectionImpl {
|
|
|
|
|
return &TurnoutSectionImpl{
|
|
|
|
|
SectionImpl: &SectionImpl{
|
|
|
|
|
uid: uid,
|
|
|
|
|
},
|
|
|
|
|
Turnouts: make([]Turnout, 0),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *TurnoutSectionImpl) AddTurnout(turnout Turnout) {
|
2024-07-10 18:09:16 +08:00
|
|
|
|
for _, exist := range t.Turnouts {
|
|
|
|
|
if exist.Uid() == turnout.Uid() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-08 19:47:30 +08:00
|
|
|
|
t.Turnouts = append(t.Turnouts, turnout)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *TurnoutSectionImpl) GetTurnouts() []Turnout {
|
|
|
|
|
return t.Turnouts
|
|
|
|
|
}
|