rts-sim-module/examples/test1/tmodel/link_model.go
2023-08-24 10:27:50 +08:00

82 lines
1.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 tmodel
import (
"joylink.club/rtsssimulation/umi"
)
// 长轨道,道岔端点间的轨道
type LinkModel struct {
DeviceModel
//轨道A端口连接的道岔
PortA umi.ISwitchRef
//轨道B端口连接的道岔
PortB umi.ISwitchRef
//长度,单位mm
Length int64
}
func NewLinkModel(id string) *LinkModel {
return &LinkModel{DeviceModel: DeviceModel{Id: id, Type: umi.Link}}
}
// 获取轨道长度单位mm
func (me *LinkModel) Len() int64 {
return me.Length
}
// 轨道A端连接的道岔
func (me *LinkModel) PortASwitch() umi.ISwitchRef {
return me.PortA
}
// 轨道B端连接的道岔
func (me *LinkModel) PortBSwitch() umi.ISwitchRef {
return me.PortB
}
///////////////////////////////////////////////////////
// 轨道端口引用
type LinkRef struct {
Link umi.ILinkModel
//引用轨道的端口
Port umi.PortEnum
}
func NewLinkRef(link *LinkModel, port umi.PortEnum) *LinkRef {
return &LinkRef{Link: link, Port: port}
}
// 被引用的轨道模型
func (me *LinkRef) LinkModel() umi.ILinkModel {
return me.Link
}
// 被引用的轨道的端口
func (me *LinkRef) LinkPort() umi.PortEnum {
return me.Port
}
///////////////////////////////////////////////////////////
// 轨道偏移位置引用轨道A端为偏移起始位置
type LinkOffsetRef struct {
Link umi.ILinkModel
//偏移位置单位mm
Offset int64
}
func NewLinkOffsetRef(link *LinkModel, offset int64) *LinkOffsetRef {
return &LinkOffsetRef{Link: link, Offset: offset}
}
// 被引用的轨道模型
func (me *LinkOffsetRef) LinkModel() umi.ILinkModel {
return me.Link
}
// 偏移量单位mm
func (me *LinkOffsetRef) GetOffset() int64 {
return me.Offset
}