rts-sim-module/storages/model/switch_model.go
2023-08-23 15:23:30 +08:00

67 lines
1.4 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 model
import (
"joylink.club/rtsssimulation/components/cstate"
"joylink.club/rtsssimulation/umi"
)
// 道岔
type SwitchModel struct {
DeviceModel
//道岔A端口连接的轨道
PortA umi.ILinkRef
//道岔B端口连接的轨道
PortB umi.ILinkRef
//道岔C端口连接的轨道
PortC umi.ILinkRef
//道岔转动需要的时间(从开度0-100的时间),单位ms
TurnTime int64
}
func NewSwitchModel(id string) *SwitchModel {
return &SwitchModel{DeviceModel: DeviceModel{Id: id, Type: cstate.DeviceType_Switch}}
}
// 道岔转动从0-100耗时单位ms
func (me *SwitchModel) TurningTime() int64 {
return me.TurnTime
}
// 道岔A端口连接的轨道
func (me *SwitchModel) PortALink() umi.ILinkRef {
return me.PortA
}
// 道岔B端口连接的轨道
func (me *SwitchModel) PortBLink() umi.ILinkRef {
return me.PortB
}
// 道岔C端口连接的轨道
func (me *SwitchModel) PortCLink() umi.ILinkRef {
return me.PortC
}
//////////////////////////////////////////////////////////
// 道岔端口引用
type SwitchRef struct {
Switch umi.ISwitchModel
//引用道岔的端口
Port umi.PortEnum
}
func NewSwitchRef(switchModel *SwitchModel, port umi.PortEnum) *SwitchRef {
return &SwitchRef{Switch: switchModel, Port: port}
}
// 被引用的道岔模型
func (me *SwitchRef) SwitchModel() umi.ISwitchModel {
return me.Switch
}
// 被引用的道岔的端口
func (me *SwitchRef) SwitchPort() umi.PortEnum {
return me.Port
}