Merge branch 'master' of https://git.code.tencent.com/jl-framework/rtss_simulation
This commit is contained in:
commit
3f5b459460
@ -62,3 +62,5 @@ type Counter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var CounterType = ecs.NewComponentType[Counter]()
|
var CounterType = ecs.NewComponentType[Counter]()
|
||||||
|
|
||||||
|
var LinkPositionType = ecs.NewComponentType[component_proto.LinkPosition]()
|
||||||
|
@ -9,8 +9,4 @@ type AirConditioning struct {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
AirConditioningType = ecs.NewComponentType[AirConditioning]() //空调
|
AirConditioningType = ecs.NewComponentType[AirConditioning]() //空调
|
||||||
|
|
||||||
CombinationAirConditionerTag = ecs.NewTag() //组合式空调(变频空调)
|
|
||||||
AirConditioningGroupTag = ecs.NewTag() //空调群控系统
|
|
||||||
AirConditionerTag = ecs.NewTag() //空调器
|
|
||||||
)
|
)
|
||||||
|
@ -8,7 +8,5 @@ type AirPavilion struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
AirPavilionType = ecs.NewComponentType[AirPavilion]() //风亭
|
AirPavilionType = ecs.NewComponentType[AirPavilion]() //风亭
|
||||||
ExhaustPavilionTag = ecs.NewTag() //排风亭
|
|
||||||
AirSupplyPavilionTag = ecs.NewTag() //送风亭
|
|
||||||
)
|
)
|
||||||
|
@ -115,10 +115,9 @@ func NewPipeFluid() *PipeFluid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
PipeType = ecs.NewComponentType[Pipe]() //电线
|
PipeType = ecs.NewComponentType[Pipe]() //电线
|
||||||
PipeElectricityType = ecs.NewComponentType[PipeElectricity]() //电线电力
|
PipeElectricityType = ecs.NewComponentType[PipeElectricity]() //电线电力
|
||||||
PipeFluidType = ecs.NewComponentType[PipeFluid]() //管线流体
|
PipeFluidType = ecs.NewComponentType[PipeFluid]() //管线流体
|
||||||
|
|
||||||
ElectricitySourceType = ecs.NewComponentType[ElectricitySource]() //电源
|
ElectricitySourceType = ecs.NewComponentType[ElectricitySource]() //电源
|
||||||
|
|
||||||
)
|
)
|
||||||
|
@ -3,6 +3,7 @@ package entity
|
|||||||
import (
|
import (
|
||||||
"joylink.club/ecs"
|
"joylink.club/ecs"
|
||||||
"joylink.club/rtsssimulation/component"
|
"joylink.club/rtsssimulation/component"
|
||||||
|
"joylink.club/rtsssimulation/component/component_proto"
|
||||||
"joylink.club/rtsssimulation/repository"
|
"joylink.club/rtsssimulation/repository"
|
||||||
"joylink.club/rtsssimulation/repository/model/proto"
|
"joylink.club/rtsssimulation/repository/model/proto"
|
||||||
)
|
)
|
||||||
@ -10,9 +11,16 @@ import (
|
|||||||
// LoadBalises 加载应答器实体
|
// LoadBalises 加载应答器实体
|
||||||
func LoadBalises(w ecs.World) error {
|
func LoadBalises(w ecs.World) error {
|
||||||
data := GetWorldData(w)
|
data := GetWorldData(w)
|
||||||
balises := data.Repo.ResponderList()
|
balises := data.Repo.TransponderList()
|
||||||
for _, b := range balises {
|
for _, b := range balises {
|
||||||
be := newBaliseEntity(w, b, data)
|
be := newBaliseEntity(w, b, data)
|
||||||
|
//应答器位置
|
||||||
|
be.AddComponent(component.LinkPositionType)
|
||||||
|
component.LinkPositionType.SetValue(be, component_proto.LinkPosition{
|
||||||
|
LinkId: b.LinkPosition().Link().Id(),
|
||||||
|
Offset: b.LinkPosition().Offset(),
|
||||||
|
})
|
||||||
|
//应答器类型
|
||||||
switch b.TransponderType() {
|
switch b.TransponderType() {
|
||||||
case proto.Transponder_FB:
|
case proto.Transponder_FB:
|
||||||
be.AddComponent(component.BaliseFB)
|
be.AddComponent(component.BaliseFB)
|
||||||
|
@ -34,19 +34,12 @@ func NewNetworkSwitchEntity(w ecs.World, id string) *ecs.Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewAirPavilionEntity 创建风亭实体
|
// NewAirPavilionEntity 创建风亭实体
|
||||||
func NewAirPavilionEntity(w ecs.World, id string, apType proto.AirPavilion_Type) *ecs.Entry {
|
func NewAirPavilionEntity(w ecs.World, id string) *ecs.Entry {
|
||||||
wd := GetWorldData(w)
|
wd := GetWorldData(w)
|
||||||
e, ok := wd.EntityMap[id]
|
e, ok := wd.EntityMap[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
e = w.Entry(w.Create(component.UidType, component.AirPavilionType))
|
e = w.Entry(w.Create(component.UidType, component.AirPavilionType))
|
||||||
//
|
//
|
||||||
switch apType {
|
|
||||||
case proto.AirPavilion_ExhaustPavilion:
|
|
||||||
e.AddComponent(component.ExhaustPavilionTag)
|
|
||||||
case proto.AirPavilion_AirSupplyPavilion:
|
|
||||||
e.AddComponent(component.AirSupplyPavilionTag)
|
|
||||||
}
|
|
||||||
//
|
|
||||||
component.UidType.SetValue(e, component.Uid{Id: id})
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
||||||
component.AirPavilionType.Set(e, &component.AirPavilion{Normal: true})
|
component.AirPavilionType.Set(e, &component.AirPavilion{Normal: true})
|
||||||
wd.EntityMap[id] = e
|
wd.EntityMap[id] = e
|
||||||
@ -93,15 +86,24 @@ func NewGasMixingChamberEntity(w ecs.World, id string) *ecs.Entry {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCombinationAirConditionerEntity 创建组合式空调实体
|
// NewCombinationAirConditionerEntity 创建组合式空调(变频)实体
|
||||||
func NewCombinationAirConditionerEntity(w ecs.World, id string) *ecs.Entry {
|
func NewCombinationAirConditionerEntity(w ecs.World, id string) *ecs.Entry {
|
||||||
return newAirConditioningEntity(w, id, component.CombinationAirConditionerTag)
|
|
||||||
}
|
|
||||||
func newAirConditioningEntity(w ecs.World, id string, tag *ecs.ComponentType[struct{}]) *ecs.Entry {
|
|
||||||
wd := GetWorldData(w)
|
wd := GetWorldData(w)
|
||||||
e, ok := wd.EntityMap[id]
|
e, ok := wd.EntityMap[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
e = w.Entry(w.Create(component.UidType, component.MotorType, component.AirConditioningType, component.DeviceExceptionType, tag))
|
e = w.Entry(w.Create(component.UidType, component.MotorType, component.MotorFcType, component.FluidDriverType, component.AirConditioningType, component.DeviceExceptionType))
|
||||||
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
||||||
|
wd.EntityMap[id] = e
|
||||||
|
}
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAirConditionerEntity 创建空调实体
|
||||||
|
func NewAirConditionerEntity(w ecs.World, id string) *ecs.Entry {
|
||||||
|
wd := GetWorldData(w)
|
||||||
|
e, ok := wd.EntityMap[id]
|
||||||
|
if !ok {
|
||||||
|
e = w.Entry(w.Create(component.UidType, component.MotorType, component.AirConditioningType, component.DeviceExceptionType))
|
||||||
component.UidType.SetValue(e, component.Uid{Id: id})
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
||||||
wd.EntityMap[id] = e
|
wd.EntityMap[id] = e
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ func LoadIscs(w ecs.World) error {
|
|||||||
}
|
}
|
||||||
//风亭(排风亭、送风亭)
|
//风亭(排风亭、送风亭)
|
||||||
for _, ap := range data.Repo.AirPavilionMap {
|
for _, ap := range data.Repo.AirPavilionMap {
|
||||||
NewAirPavilionEntity(w, ap.Id(), ap.PavilionType)
|
NewAirPavilionEntity(w, ap.Id())
|
||||||
}
|
}
|
||||||
//阀门
|
//阀门
|
||||||
for _, valve := range data.Repo.ValveMap {
|
for _, valve := range data.Repo.ValveMap {
|
||||||
|
@ -51,6 +51,14 @@ message Counter {
|
|||||||
int32 step = 2;
|
int32 step = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Link位置
|
||||||
|
message LinkPosition{
|
||||||
|
//Link的ID
|
||||||
|
string linkId = 1;
|
||||||
|
//Link的偏移量
|
||||||
|
int64 offset = 2;
|
||||||
|
}
|
||||||
|
|
||||||
// 倒数/倒计时组件
|
// 倒数/倒计时组件
|
||||||
message CounterDown {
|
message CounterDown {
|
||||||
int32 val = 1;
|
int32 val = 1;
|
||||||
|
3519
repository/message_proto/repo.pb.go
Normal file
3519
repository/message_proto/repo.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -15,7 +15,7 @@ type Repository struct {
|
|||||||
checkPointMap map[string]*CheckPoint
|
checkPointMap map[string]*CheckPoint
|
||||||
turnoutMap map[string]*Turnout
|
turnoutMap map[string]*Turnout
|
||||||
signalMap map[string]*Signal
|
signalMap map[string]*Signal
|
||||||
responderMap map[string]*Transponder
|
transponderMap map[string]*Transponder
|
||||||
slopeMap map[string]*Slope
|
slopeMap map[string]*Slope
|
||||||
sectionalCurvatureMap map[string]*SectionalCurvature
|
sectionalCurvatureMap map[string]*SectionalCurvature
|
||||||
kilometerConvertMap map[string]*proto.KilometerConvert
|
kilometerConvertMap map[string]*proto.KilometerConvert
|
||||||
@ -62,7 +62,7 @@ func newRepository(id string, version string) *Repository {
|
|||||||
checkPointMap: make(map[string]*CheckPoint),
|
checkPointMap: make(map[string]*CheckPoint),
|
||||||
turnoutMap: make(map[string]*Turnout),
|
turnoutMap: make(map[string]*Turnout),
|
||||||
signalMap: make(map[string]*Signal),
|
signalMap: make(map[string]*Signal),
|
||||||
responderMap: make(map[string]*Transponder),
|
transponderMap: make(map[string]*Transponder),
|
||||||
slopeMap: make(map[string]*Slope),
|
slopeMap: make(map[string]*Slope),
|
||||||
sectionalCurvatureMap: make(map[string]*SectionalCurvature),
|
sectionalCurvatureMap: make(map[string]*SectionalCurvature),
|
||||||
kilometerConvertMap: make(map[string]*proto.KilometerConvert),
|
kilometerConvertMap: make(map[string]*proto.KilometerConvert),
|
||||||
@ -119,7 +119,7 @@ func (repo *Repository) FindById(id string) Identity {
|
|||||||
if md, ok := repo.checkPointMap[id]; ok {
|
if md, ok := repo.checkPointMap[id]; ok {
|
||||||
return md
|
return md
|
||||||
}
|
}
|
||||||
if md, ok := repo.responderMap[id]; ok {
|
if md, ok := repo.transponderMap[id]; ok {
|
||||||
return md
|
return md
|
||||||
}
|
}
|
||||||
if md, ok := repo.stationMap[id]; ok {
|
if md, ok := repo.stationMap[id]; ok {
|
||||||
@ -225,16 +225,16 @@ func (repo *Repository) SignalList() []*Signal {
|
|||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
func (repo *Repository) ResponderList() []*Transponder {
|
func (repo *Repository) TransponderList() []*Transponder {
|
||||||
var list []*Transponder
|
var list []*Transponder
|
||||||
for _, model := range repo.responderMap {
|
for _, model := range repo.transponderMap {
|
||||||
list = append(list, model)
|
list = append(list, model)
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
func (repo *Repository) ResponderListByLink(linkId string) []*Transponder {
|
func (repo *Repository) ResponderListByLink(linkId string) []*Transponder {
|
||||||
var list []*Transponder
|
var list []*Transponder
|
||||||
for _, model := range repo.responderMap {
|
for _, model := range repo.transponderMap {
|
||||||
if model.linkPosition.link.Id() == linkId {
|
if model.linkPosition.link.Id() == linkId {
|
||||||
list = append(list, model)
|
list = append(list, model)
|
||||||
}
|
}
|
||||||
@ -336,7 +336,7 @@ func (repo *Repository) FindModel(deviceId string, deviceType proto.DeviceType)
|
|||||||
case proto.DeviceType_DeviceType_Signal:
|
case proto.DeviceType_DeviceType_Signal:
|
||||||
return repo.signalMap[deviceId], nil
|
return repo.signalMap[deviceId], nil
|
||||||
case proto.DeviceType_DeviceType_Transponder:
|
case proto.DeviceType_DeviceType_Transponder:
|
||||||
return repo.responderMap[deviceId], nil
|
return repo.transponderMap[deviceId], nil
|
||||||
case proto.DeviceType_DeviceType_Slope:
|
case proto.DeviceType_DeviceType_Slope:
|
||||||
return repo.slopeMap[deviceId], nil
|
return repo.slopeMap[deviceId], nil
|
||||||
case proto.DeviceType_DeviceType_SectionalCurvature:
|
case proto.DeviceType_DeviceType_SectionalCurvature:
|
||||||
@ -396,7 +396,7 @@ func (repo *Repository) FindLink(id string) *Link {
|
|||||||
return repo.linkMap[id]
|
return repo.linkMap[id]
|
||||||
}
|
}
|
||||||
func (repo *Repository) FindTransponder(id string) *Transponder {
|
func (repo *Repository) FindTransponder(id string) *Transponder {
|
||||||
return repo.responderMap[id]
|
return repo.transponderMap[id]
|
||||||
}
|
}
|
||||||
func (repo *Repository) FindTurnout(id string) *Turnout {
|
func (repo *Repository) FindTurnout(id string) *Turnout {
|
||||||
return repo.turnoutMap[id]
|
return repo.turnoutMap[id]
|
||||||
@ -419,7 +419,7 @@ func (repo *Repository) FindPsd(id string) *Psd {
|
|||||||
return repo.psdMap[id]
|
return repo.psdMap[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repository) FindPlatfrom(id string) *Platform {
|
func (repo *Repository) FindPlatform(id string) *Platform {
|
||||||
return repo.platformMap[id]
|
return repo.platformMap[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,7 +499,7 @@ func (repo *Repository) generateCoordinateInfo(coordinateSystem string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo Repository) GetCoordinateInfo() *MapCoordinate {
|
func (repo *Repository) GetCoordinateInfo() *MapCoordinate {
|
||||||
return repo.coordinate
|
return repo.coordinate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ func buildModels(source *proto.Repository, repository *Repository) error {
|
|||||||
}
|
}
|
||||||
for _, protoData := range source.Transponders {
|
for _, protoData := range source.Transponders {
|
||||||
m := NewTransponder(protoData.Id, protoData.Km, protoData.FixedTelegram, protoData.Type)
|
m := NewTransponder(protoData.Id, protoData.Km, protoData.FixedTelegram, protoData.Type)
|
||||||
repository.responderMap[m.Id()] = m
|
repository.transponderMap[m.Id()] = m
|
||||||
}
|
}
|
||||||
for _, protoData := range source.Slopes {
|
for _, protoData := range source.Slopes {
|
||||||
m := NewSlope(protoData.Id, protoData.Kms, protoData.Degree)
|
m := NewSlope(protoData.Id, protoData.Kms, protoData.Degree)
|
||||||
@ -346,7 +346,7 @@ func buildCheckPointRelationShip(source *proto.Repository, repo *Repository) err
|
|||||||
|
|
||||||
func buildResponderRelationShip(source *proto.Repository, repository *Repository) error {
|
func buildResponderRelationShip(source *proto.Repository, repository *Repository) error {
|
||||||
for _, protoData := range source.Transponders {
|
for _, protoData := range source.Transponders {
|
||||||
responder := repository.responderMap[protoData.Id]
|
responder := repository.transponderMap[protoData.Id]
|
||||||
//应答器和区段相互关联
|
//应答器和区段相互关联
|
||||||
if protoData.SectionId != "" {
|
if protoData.SectionId != "" {
|
||||||
interrelateResponderAndPhysicalSection(responder, repository.physicalSectionMap[protoData.SectionId])
|
interrelateResponderAndPhysicalSection(responder, repository.physicalSectionMap[protoData.SectionId])
|
||||||
@ -595,11 +595,7 @@ func buildLinks(repo *Repository) error {
|
|||||||
//以始端道岔的公里标作为Link零点的公里标
|
//以始端道岔的公里标作为Link零点的公里标
|
||||||
linkZeroKm := startTp.turnout.km
|
linkZeroKm := startTp.turnout.km
|
||||||
//创建基础Link
|
//创建基础Link
|
||||||
link := &Link{
|
link := NewLink(strconv.Itoa(linkIdGenerator)) //由于发给动力学的link的id是数字,所以这里也用数字
|
||||||
Identity: identity{
|
|
||||||
id: strconv.Itoa(linkIdGenerator), //由于发给动力学的link的id是数字,所以这里也用数字
|
|
||||||
deviceType: proto.DeviceType_DeviceType_Link,
|
|
||||||
}}
|
|
||||||
linkIdGenerator++
|
linkIdGenerator++
|
||||||
//以此道岔端口作为Link的A端节点
|
//以此道岔端口作为Link的A端节点
|
||||||
interrelateLinkAndTurnout(repo, linkZeroKm, startTp, &LinkPort{link, proto.Port_A})
|
interrelateLinkAndTurnout(repo, linkZeroKm, startTp, &LinkPort{link, proto.Port_A})
|
||||||
|
@ -8,7 +8,7 @@ type Transponder struct {
|
|||||||
km *proto.Kilometer
|
km *proto.Kilometer
|
||||||
//section *PhysicalSection
|
//section *PhysicalSection
|
||||||
//turnoutPort TurnoutPort
|
//turnoutPort TurnoutPort
|
||||||
linkPosition *LinkPosition
|
linkPosition *LinkPosition //此位置是应答器初始位置,当前位置需从应答器实体中获取
|
||||||
fixedTelegram []byte //无源应答器固定报文
|
fixedTelegram []byte //无源应答器固定报文
|
||||||
baliseType proto.Transponder_Type //应答器类型
|
baliseType proto.Transponder_Type //应答器类型
|
||||||
}
|
}
|
||||||
@ -31,13 +31,6 @@ func (t *Transponder) bindLinkPosition(position *LinkPosition) {
|
|||||||
t.linkPosition = position
|
t.linkPosition = position
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (r *Transponder) bindSection(section *PhysicalSection) {
|
|
||||||
// r.section = section
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// func (r *Transponder) bindTurnoutPort(turnoutPort TurnoutPort) {
|
|
||||||
// r.turnoutPort = turnoutPort
|
|
||||||
// }
|
|
||||||
func (t *Transponder) LinkPosition() *LinkPosition {
|
func (t *Transponder) LinkPosition() *LinkPosition {
|
||||||
return t.linkPosition
|
return t.linkPosition
|
||||||
}
|
}
|
||||||
|
@ -22,5 +22,10 @@ func (s *AirConditionerSystem) Update(w ecs.World) {
|
|||||||
air := component.AirConditioningType.Get(entry)
|
air := component.AirConditioningType.Get(entry)
|
||||||
//
|
//
|
||||||
air.Running = motor.Speed > 0
|
air.Running = motor.Speed > 0
|
||||||
|
//
|
||||||
|
if entry.HasComponent(component.FluidDriverType) {
|
||||||
|
fd := component.FluidDriverType.Get(entry)
|
||||||
|
fd.On = motor.Speed > 0
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -13,17 +13,17 @@ import (
|
|||||||
|
|
||||||
// FluidDriverSystem 流体驱动系统
|
// FluidDriverSystem 流体驱动系统
|
||||||
// 实现流体在设备、管线中流动
|
// 实现流体在设备、管线中流动
|
||||||
// 流体驱动源(风机、送风亭、泵)
|
// 流体驱动源(风机、泵、组合式空调)
|
||||||
type FluidDriverSystem struct {
|
type FluidDriverSystem struct {
|
||||||
query *ecs.Query //流体驱动源
|
queryFluidDriver *ecs.Query //流体驱动源
|
||||||
drivePathMap map[string][]*SearchedPath //key pipePortId,value 驱动源驱动流体的路径
|
drivePathMap map[string][]*SearchedPath //key pipePortId,value 驱动源驱动流体的路径
|
||||||
queryFluidPipe *ecs.Query
|
queryFluidPipe *ecs.Query
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFluidDriverSystem() *FluidDriverSystem {
|
func NewFluidDriverSystem() *FluidDriverSystem {
|
||||||
return &FluidDriverSystem{
|
return &FluidDriverSystem{
|
||||||
query: ecs.NewQuery(filter.Contains(component.UidType, component.FluidDriverType)),
|
queryFluidDriver: ecs.NewQuery(filter.Contains(component.UidType, component.FluidDriverType)),
|
||||||
queryFluidPipe: ecs.NewQuery(filter.Contains(component.UidType, component.PipeFluidType)),
|
queryFluidPipe: ecs.NewQuery(filter.Contains(component.UidType, component.PipeFluidType)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,9 @@ func (s *FluidDriverSystem) findFluidPath(fromDevice repository.Identity, fromDe
|
|||||||
return sp
|
return sp
|
||||||
}
|
}
|
||||||
func (s *FluidDriverSystem) Update(w ecs.World) {
|
func (s *FluidDriverSystem) Update(w ecs.World) {
|
||||||
|
s.queryFluidDriver.Each(w, func(entry *ecs.Entry) {
|
||||||
|
//fdId := component.UidType.Get(entry).Id
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断路径是否畅通
|
// 判断路径是否畅通
|
||||||
@ -110,7 +112,7 @@ func newFluidDriverPathSearcher(fromDevice repository.Identity, fromDevicePortPi
|
|||||||
func (s *fluidDriverPathSearcher) search() []*SearchedPath {
|
func (s *fluidDriverPathSearcher) search() []*SearchedPath {
|
||||||
var rt []*SearchedPath
|
var rt []*SearchedPath
|
||||||
if !s.exclude(s.fromDevicePortPipe.Device().Id()) {
|
if !s.exclude(s.fromDevicePortPipe.Device().Id()) {
|
||||||
searchContext := &fluidPath{}
|
searchContext := &fluidPath{viaPipeFittings: make(map[string]string)}
|
||||||
searchContext.addPipe(s.fromDevicePortPipe)
|
searchContext.addPipe(s.fromDevicePortPipe)
|
||||||
s.doSearch(searchContext)
|
s.doSearch(searchContext)
|
||||||
} else {
|
} else {
|
||||||
@ -149,50 +151,67 @@ func (s *fluidDriverPathSearcher) addSearchedPath(searchContext *fluidPath) {
|
|||||||
s.searchedPaths = append(s.searchedPaths, searchContext)
|
s.searchedPaths = append(s.searchedPaths, searchContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 递归搜索
|
// 搜索
|
||||||
func (s *fluidDriverPathSearcher) doSearch(searchContext *fluidPath) {
|
func (s *fluidDriverPathSearcher) doSearch(searchContext *fluidPath) {
|
||||||
nextViaPipes := searchContext.nextViaPathPipes()
|
nextViaPipes, end := searchContext.nextViaPathPipes()
|
||||||
lenNextPipes := len(nextViaPipes)
|
lenNextPipes := len(nextViaPipes)
|
||||||
if lenNextPipes == 0 {
|
if end {
|
||||||
s.addSearchedPath(searchContext)
|
s.addSearchedPath(searchContext)
|
||||||
} else if lenNextPipes == 1 {
|
|
||||||
if !searchContext.viaPipe(nextViaPipes[0].Device().Id()) && !s.exclude(nextViaPipes[0].Device().Id()) {
|
|
||||||
searchContext.addPipe(nextViaPipes[0])
|
|
||||||
s.doSearch(searchContext)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for _, nextViaPipe := range nextViaPipes {
|
if lenNextPipes == 1 {
|
||||||
if searchContext.viaPipe(nextViaPipe.Device().Id()) { //舍弃回头路径
|
if !searchContext.viaPipe(nextViaPipes[0].Device().Id()) && !s.exclude(nextViaPipes[0].Device().Id()) {
|
||||||
continue
|
searchContext.addPipe(nextViaPipes[0])
|
||||||
|
s.doSearch(searchContext)
|
||||||
}
|
}
|
||||||
if s.exclude(nextViaPipe.Device().Id()) { //舍弃排除路径
|
} else {
|
||||||
continue
|
for _, nextViaPipe := range nextViaPipes {
|
||||||
|
if searchContext.viaPipe(nextViaPipe.Device().Id()) { //舍弃回头路径
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if s.exclude(nextViaPipe.Device().Id()) { //舍弃排除路径
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
//
|
||||||
|
cp := searchContext.clone()
|
||||||
|
cp.addPipe(nextViaPipe)
|
||||||
|
s.doSearch(cp)
|
||||||
}
|
}
|
||||||
//
|
|
||||||
cp := searchContext.clone()
|
|
||||||
cp.addPipe(nextViaPipe)
|
|
||||||
s.doSearch(cp)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *fluidPath) nextViaPathPipes() []repository.PipePort {
|
// 从当前管线找下一个管线
|
||||||
|
// 泵、风机、空调 提供驱动力,承接进出
|
||||||
|
// 返回bool : true-搜索达终点
|
||||||
|
func (p *fluidPath) nextViaPathPipes() ([]repository.PipePort, bool) {
|
||||||
nextDevice := p.nextDevice()
|
nextDevice := p.nextDevice()
|
||||||
|
//
|
||||||
switch nextDevice.Type() {
|
switch nextDevice.Type() {
|
||||||
case proto.DeviceType_DeviceType_PipeFitting:
|
case proto.DeviceType_DeviceType_PipeFitting:
|
||||||
return p.nextDeviceViaPipes(nextDevice.(*repository.PipeFitting).Ports(), p.curPipe)
|
{
|
||||||
|
if _, has := p.viaPipeFittings[nextDevice.Id()]; has { //排除已经经过的管件的路径
|
||||||
|
return nil, false
|
||||||
|
} else {
|
||||||
|
p.viaPipeFittings[nextDevice.Id()] = nextDevice.Id()
|
||||||
|
return p.nextDeviceViaPipes(nextDevice.(*repository.PipeFitting).Ports(), p.curPipe), false
|
||||||
|
}
|
||||||
|
}
|
||||||
case proto.DeviceType_DeviceType_Valve:
|
case proto.DeviceType_DeviceType_Valve:
|
||||||
return p.nextDeviceViaPipes(nextDevice.(*repository.Valve).Ports(), p.curPipe)
|
return p.nextDeviceViaPipes(nextDevice.(*repository.Valve).Ports(), p.curPipe), false
|
||||||
case proto.DeviceType_DeviceType_GasMixingChamber:
|
case proto.DeviceType_DeviceType_GasMixingChamber: //静压箱
|
||||||
return p.nextGasMixingChamberViaPipes(nextDevice.(*repository.GasMixingChamber), p.curPipe)
|
return p.nextGasMixingChamberViaPipes(nextDevice.(*repository.GasMixingChamber), p.curPipe), false
|
||||||
case proto.DeviceType_DeviceType_CombinationAirConditioner:
|
case proto.DeviceType_DeviceType_AirPurificationDevice: //净化装置
|
||||||
return p.nextCombinationAirConditionerViaPipes(nextDevice.(*repository.CombinationAirConditioner), p.curPipe)
|
return p.nextDeviceViaPipes(nextDevice.(*repository.AirPurificationDevice).Ports(), p.curPipe), false
|
||||||
case proto.DeviceType_DeviceType_AirPurificationDevice:
|
case proto.DeviceType_DeviceType_Environment: //环境
|
||||||
return p.nextDeviceViaPipes(nextDevice.(*repository.AirPurificationDevice).Ports(), p.curPipe)
|
fallthrough
|
||||||
|
case proto.DeviceType_DeviceType_AirPavilion: //风亭
|
||||||
|
fallthrough
|
||||||
|
case proto.DeviceType_DeviceType_CombinationAirConditioner: //组合式空调
|
||||||
|
return nil, true //路径搜索终点
|
||||||
default:
|
default:
|
||||||
slog.Warn("管线路径中的设备[%d]无法处理", nextDevice.Type())
|
slog.Warn("管线路径中的设备[%d]无法处理", nextDevice.Type())
|
||||||
}
|
}
|
||||||
return nil
|
return nil, false //排除(舍弃)该路径搜索
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -240,8 +259,9 @@ func (p *fluidPath) nextGasMixingChamberViaPipes(nextDevice *repository.GasMixin
|
|||||||
}
|
}
|
||||||
|
|
||||||
type fluidPath struct {
|
type fluidPath struct {
|
||||||
curPipe repository.PipePort //路径中当前有向管线
|
curPipe repository.PipePort //路径中当前有向管线
|
||||||
viaPipes []repository.PipePort //路径所经过的有向管线
|
viaPipes []repository.PipePort //路径所经过的有向管线
|
||||||
|
viaPipeFittings map[string]string //经过的管件,用于排除闭环路径,key和value均为deviceId
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *fluidPath) addPipe(viaPipe repository.PipePort) {
|
func (p *fluidPath) addPipe(viaPipe repository.PipePort) {
|
||||||
@ -257,8 +277,11 @@ func (p *fluidPath) viaPipe(pipeId string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func (p *fluidPath) clone() *fluidPath {
|
func (p *fluidPath) clone() *fluidPath {
|
||||||
cp := &fluidPath{viaPipes: make([]repository.PipePort, 0, len(p.viaPipes)), curPipe: p.curPipe}
|
cp := &fluidPath{viaPipes: make([]repository.PipePort, 0, len(p.viaPipes)), curPipe: p.curPipe, viaPipeFittings: make(map[string]string)}
|
||||||
copy(cp.viaPipes, p.viaPipes)
|
copy(cp.viaPipes, p.viaPipes)
|
||||||
|
for k, v := range p.viaPipeFittings {
|
||||||
|
cp.viaPipeFittings[k] = v
|
||||||
|
}
|
||||||
return cp
|
return cp
|
||||||
}
|
}
|
||||||
func (p *fluidPath) nextDevice() repository.Identity {
|
func (p *fluidPath) nextDevice() repository.Identity {
|
||||||
|
Loading…
Reference in New Issue
Block a user