2023-08-24 10:27:50 +08:00
|
|
|
|
package tmodel
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"joylink.club/rtsssimulation/umi"
|
|
|
|
|
)
|
|
|
|
|
|
2023-09-14 15:03:16 +08:00
|
|
|
|
// 道岔电路系统中的继电器
|
|
|
|
|
type SwitchRelay struct {
|
|
|
|
|
//继电器模型
|
|
|
|
|
Relay umi.IRelayModel
|
|
|
|
|
//该继电器在该道岔电路系统中的组合类型
|
|
|
|
|
RelayGroup string
|
|
|
|
|
//该继电器在该道岔电路系统中的功能名称
|
|
|
|
|
RelayName string
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-24 10:27:50 +08:00
|
|
|
|
// 道岔
|
|
|
|
|
type SwitchModel struct {
|
|
|
|
|
DeviceModel
|
|
|
|
|
//道岔A端口连接的轨道
|
|
|
|
|
PortA umi.ILinkRef
|
|
|
|
|
//道岔B端口连接的轨道
|
|
|
|
|
PortB umi.ILinkRef
|
|
|
|
|
//道岔C端口连接的轨道
|
|
|
|
|
PortC umi.ILinkRef
|
2023-09-14 15:03:16 +08:00
|
|
|
|
//道岔电路系统中的继电器
|
|
|
|
|
Relays []SwitchRelay
|
2023-08-24 10:27:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewSwitchModel(id string) *SwitchModel {
|
|
|
|
|
return &SwitchModel{DeviceModel: DeviceModel{Id: id, Type: umi.Switch}}
|
|
|
|
|
}
|
2023-09-15 10:13:25 +08:00
|
|
|
|
func (me *SwitchModel) AddRelay(relay *SwitchRelay) {
|
|
|
|
|
me.Relays = append(me.Relays, *relay)
|
|
|
|
|
}
|
2023-08-24 10:27:50 +08:00
|
|
|
|
|
|
|
|
|
// 道岔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
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-14 15:03:16 +08:00
|
|
|
|
// 根据继电器id获取在具体电路中的电路角色
|
|
|
|
|
// relayId-继电器id
|
|
|
|
|
// relayGroup-继电器组合类型
|
|
|
|
|
// relayName-继电器在电路中的名称
|
|
|
|
|
// find-true找到,false未找到
|
|
|
|
|
func (me *SwitchModel) FindCircuitRoleById(relayId string) (relayGroup string, relayName string, find bool) {
|
|
|
|
|
for _, sr := range me.Relays {
|
|
|
|
|
id := sr.Relay.(umi.IDeviceModel).GetId()
|
|
|
|
|
if id == relayId {
|
|
|
|
|
return sr.RelayGroup, sr.RelayName, true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "", "", false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据继电器具体电路角色来获取继电器设备模型
|
|
|
|
|
// relayGroup-继电器组合类型
|
|
|
|
|
// relayName-继电器在电路中的名称
|
|
|
|
|
func (me *SwitchModel) FindRelayModelByCRole(relayGroup string, relayName string) umi.IRelayModel {
|
|
|
|
|
for _, sr := range me.Relays {
|
|
|
|
|
if sr.RelayGroup == relayGroup && sr.RelayName == relayName {
|
|
|
|
|
return sr.Relay
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-24 10:27:50 +08:00
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
// 道岔端口引用
|
|
|
|
|
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
|
|
|
|
|
}
|