【修改link构造逻辑】

This commit is contained in:
weizhihong 2023-08-11 16:48:21 +08:00
parent 9c57620f22
commit 350a94259b
4 changed files with 110 additions and 118 deletions

View File

@ -2718,7 +2718,7 @@ type Curvature struct {
Common *CommonInfo `protobuf:"bytes,1,opt,name=common,proto3" json:"common,omitempty"`
Points []*Point `protobuf:"bytes,2,rep,name=points,proto3" json:"points,omitempty"`
CurvatureNumber int32 `protobuf:"zigzag32,3,opt,name=curvatureNumber,proto3" json:"curvatureNumber,omitempty"` //曲线的半径--正代表外侧;负代表内侧
CurvatureNumber int32 `protobuf:"zigzag32,3,opt,name=curvatureNumber,proto3" json:"curvatureNumber,omitempty"` //曲线的半径mm--正代表外侧;负代表内侧
RefDeviceId []string `protobuf:"bytes,4,rep,name=refDeviceId,proto3" json:"refDeviceId,omitempty"` // 曲线关联的(曲度公里标)
}
@ -2791,11 +2791,10 @@ type CalculateLink struct {
Common *CommonInfo `protobuf:"bytes,1,opt,name=common,proto3" json:"common,omitempty"`
Points []*Point `protobuf:"bytes,2,rep,name=points,proto3" json:"points,omitempty"`
Length int32 `protobuf:"varint,3,opt,name=length,proto3" json:"length,omitempty"` //长度mm
ARelatedRef *RelatedRef `protobuf:"bytes,4,opt,name=aRelatedRef,proto3" json:"aRelatedRef,omitempty"` // A端最小端关联的端点
BRelatedRef *RelatedRef `protobuf:"bytes,5,opt,name=bRelatedRef,proto3" json:"bRelatedRef,omitempty"` // B端最大端关联的端点
ARelatedRef *RelatedRef `protobuf:"bytes,4,opt,name=aRelatedRef,proto3" json:"aRelatedRef,omitempty"` // A端最小端关联的端点 (道岔端点)
BRelatedRef *RelatedRef `protobuf:"bytes,5,opt,name=bRelatedRef,proto3" json:"bRelatedRef,omitempty"` // B端最大端关联的端点 (道岔端点)
DevicePositions []*CalculateLink_DevicePosition `protobuf:"bytes,6,rep,name=devicePositions,proto3" json:"devicePositions,omitempty"` //设备在link上的位置
Index int32 `protobuf:"varint,7,opt,name=index,proto3" json:"index,omitempty"` //link唯一标识
Ab bool `protobuf:"varint,8,opt,name=ab,proto3" json:"ab,omitempty"` // 是否是从A->B, 道岔直连为false
}
func (x *CalculateLink) Reset() {
@ -2879,13 +2878,6 @@ func (x *CalculateLink) GetIndex() int32 {
return 0
}
func (x *CalculateLink) GetAb() bool {
if x != nil {
return x.Ab
}
return false
}
type CalculateLink_DevicePosition struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -3412,7 +3404,7 @@ var file_stationLayoutGraphics_proto_rawDesc = []byte{
0x01, 0x28, 0x11, 0x52, 0x0f, 0x63, 0x75, 0x72, 0x76, 0x61, 0x74, 0x75, 0x72, 0x65, 0x4e, 0x75,
0x6d, 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x72, 0x65, 0x66, 0x44, 0x65, 0x76, 0x69, 0x63,
0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x72, 0x65, 0x66, 0x44, 0x65,
0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x22, 0xdb, 0x03, 0x0a, 0x0d, 0x43, 0x61, 0x6c, 0x63, 0x75,
0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x22, 0xcb, 0x03, 0x0a, 0x0d, 0x43, 0x61, 0x6c, 0x63, 0x75,
0x6c, 0x61, 0x74, 0x65, 0x4c, 0x69, 0x6e, 0x6b, 0x12, 0x2f, 0x0a, 0x06, 0x63, 0x6f, 0x6d, 0x6d,
0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68,
0x69, 0x63, 0x44, 0x61, 0x74, 0x61, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x49, 0x6e, 0x66,
@ -3434,8 +3426,7 @@ var file_stationLayoutGraphics_proto_rawDesc = []byte{
0x6c, 0x61, 0x74, 0x65, 0x4c, 0x69, 0x6e, 0x6b, 0x2e, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x50,
0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0f, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x50,
0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65,
0x78, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x0e,
0x0a, 0x02, 0x61, 0x62, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x02, 0x61, 0x62, 0x1a, 0x64,
0x78, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x1a, 0x64,
0x0a, 0x0e, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e,
0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05,
0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x76, 0x69,

View File

@ -64,19 +64,17 @@ func BuildCalculateLinkData(gd *graphicData.RtssGraphicStorage) []*graphicData.C
for index, refVal := range pathArr {
if refVal.DeviceType == graphicData.RelatedRef_Section {
allTurnout = false
// 连接点是A端
item.Ab = refVal.DevicePort == graphicData.RelatedRef_A
section := gm.SectionMap[refVal.Id]
// 计算长度
item.Length = item.Length + calcGraphicLenBySection(section)
// 放入设备偏移
offset, prevKm = getGraphicSectionRefDevices(refVal, devicePosistionMap, section, offset, prevKm)
// 区段时A点取小端B点取大端没有的话赋值 refVal
if index == 0 {
item.ARelatedRef = getGraphicSectionPointRef(section, true, refVal)
} else {
item.BRelatedRef = getGraphicSectionPointRef(section, false, refVal)
}
// 区段时A点取小端B点取大端没有的话赋值 refVal ,只会以道岔为端点
//if index == 0 {
// item.ARelatedRef = getGraphicSectionPointRef(section, true, refVal)
//} else {
// item.BRelatedRef = getGraphicSectionPointRef(section, false, refVal)
//}
} else {
allTurnout = allTurnout && true
turnout := gm.TurnoutMap[refVal.Id]

View File

@ -3,6 +3,7 @@ package memory
import (
"container/list"
"fmt"
"math"
"sort"
"strconv"
"sync"
@ -110,94 +111,96 @@ func QueryMapVerifyStructure(mapId int32) *VerifyStructure {
// 根据区段道岔偏移量返回linkID和link相对偏移量
func QueryMapCalcLinkByDeviceInfo(mapId int32, id string, devicePort string, offset int64) (int32, int64) {
vm := QueryMapVerifyStructure(mapId)
var tm face.SwitchDeviceModeller
var sm face.PhysicalSectionModeller
if devicePort == "" {
sm = vm.PhysicalSectionModelMap[id]
return sectionMapToLink(vm, id, offset)
} else {
tm = vm.SwitchDeviceModelMap[id]
return turnoutMapToLink(vm, id, devicePort, offset)
}
if sm == nil && tm == nil {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在ID【%s】的设备", id)})
}
// 根据物理区段上的偏移量基于区段A端找到所在link的linkId与偏移量
func sectionMapToLink(vm *VerifyStructure, id string, offset int64) (int32, int64) {
sm := vm.PhysicalSectionModelMap[id]
if sm == nil {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在区段【index:%s】", id)})
}
if sm != nil { // 区段添加
sectionModel := sm.(*section.PhysicalSectionModel)
pointA := sectionModel.PortAxlePoints[face.A.Name()]
pointB := sectionModel.PortAxlePoints[face.B.Name()]
if pointA == nil && pointB == nil {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("区段【%s】计轴缺失", sectionModel.GraphicId)})
}
// 获取计轴信息
axlePointMap := make(map[string]*ref.DevicePosition)
// 确定link信息
var linkId int32
for k, v := range vm.LinkModelMap {
lm := v.(*device.LinkModel)
for _, p := range lm.DevicePositions {
if sectionModel.AxlePoints[p.Device.GetIndex()] != nil {
axlePointMap[p.Device.GetIndex()] = p
}
}
// 如果已经找到计轴则退出
if len(axlePointMap) > 0 {
linkId = k
break
sectionModel := sm.(*section.PhysicalSectionModel)
// 确定link信息
var linkId int32
// 获取计轴信息
axlePointMap := make(map[string]*ref.DevicePosition)
for k, v := range vm.LinkModelMap {
lm := v.(*device.LinkModel)
for _, p := range lm.DevicePositions {
if sectionModel.AxlePoints[p.Device.GetIndex()] != nil {
axlePointMap[p.Device.GetIndex()] = p
}
}
if len(axlePointMap) == 0 {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("未找到【%s】所在link", id)})
// 如果已经找到计轴则退出
if len(axlePointMap) > 0 {
linkId = k
break
}
// 计算相对位置
if pointA != nil && pointB != nil {
linkA := axlePointMap[pointA.GetIndex()]
linkB := axlePointMap[pointB.GetIndex()]
if linkA == nil {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("link【%s】缺失计轴【%s】", id, pointA.GetGraphicId())})
}
if linkB == nil {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("link【%s】缺失计轴【%s】", id, pointB.GetGraphicId())})
}
if linkA.Offset > linkB.Offset {
return linkId, int64(linkA.Offset) - offset
} else {
return linkId, int64(linkA.Offset) + offset
}
} else if pointA != nil {
linkA := axlePointMap[pointA.GetIndex()]
if linkA == nil {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("link【%s】缺失计轴【%s】", id, pointA.GetGraphicId())})
}
return linkId, int64(linkA.Offset) + offset
}
if len(axlePointMap) == 0 { // 无计轴信息
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("未找到区段【id:%s,index:%s】所在link", sectionModel.GraphicId, id)})
}
pointA := sectionModel.PortAxlePoints[face.A.Name()] // 获取A计轴点
if pointA != nil {
ap := axlePointMap[pointA.GetIndex()]
if ap == nil {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("link【%d】缺失计轴【%s】", linkId, pointA.GetGraphicId())})
}
pointB := sectionModel.PortAxlePoints[face.B.Name()] // 获取B计轴点
abDirection := pointB == nil
p1, p2 := ap.Offset, int32(math.MaxInt32)
if !abDirection && axlePointMap[pointB.GetIndex()] != nil {
p2 = axlePointMap[pointB.GetIndex()].Offset
}
if p1 < p2 {
return linkId, int64(p1) + offset
} else {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("link【%s】缺失计轴【%s】", id, pointA.GetGraphicId())})
return linkId, int64(p1) - offset
}
} else {
turnoutModel := tm.(*device.SwitchDeviceModel)
var link *device.LinkModel
var linkId int32
var isStart bool
for i, v := range vm.LinkModelMap {
lm := v.(*device.LinkModel)
linkId = i
if lm.ARelatedSwitchRef.SwitchDevice.GetIndex() == turnoutModel.Index && lm.ARelatedSwitchRef.Port.Name() == devicePort {
isStart = true
link = lm
} else if lm.BRelatedSwitchRef.SwitchDevice.GetIndex() == turnoutModel.Index && lm.BRelatedSwitchRef.Port.Name() == devicePort {
link = lm
break
}
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("link【%d】缺失区段【id:%s,index:%s】A点缺失计轴", linkId, sectionModel.GraphicId, id)})
}
}
// 根据道岔上的偏移量基于岔心位置找到所在link的linkId与偏移量
func turnoutMapToLink(vm *VerifyStructure, id string, port string, offset int64) (int32, int64) {
tm := vm.SwitchDeviceModelMap[id]
if tm == nil {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在道岔【index:%s】", id)})
}
turnoutModel := tm.(*device.SwitchDeviceModel)
var link *device.LinkModel
var linkId int32
var isStart bool
for i, v := range vm.LinkModelMap {
lm := v.(*device.LinkModel)
linkId = i
if lm.ARelatedSwitchRef.SwitchDevice.GetIndex() == turnoutModel.Index && lm.ARelatedSwitchRef.Port.Name() == port {
isStart = true
link = lm
} else if lm.BRelatedSwitchRef.SwitchDevice.GetIndex() == turnoutModel.Index && lm.BRelatedSwitchRef.Port.Name() == port {
link = lm
break
}
for _, v := range link.DevicePositions {
if v.Device.GetIndex() == turnoutModel.GetIndex() {
if isStart {
return linkId, int64(v.Offset) + offset
} else {
return linkId, int64(v.Offset) - offset
}
}
if link == nil {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("未找到道岔【id:%s,index:%s】端口【%s】所在link", turnoutModel.GraphicId, id, port)})
}
for _, v := range link.DevicePositions {
if v.Device.GetIndex() == turnoutModel.GetIndex() {
if isStart {
return linkId, int64(v.Offset) + offset
} else {
return linkId, int64(v.Offset) - offset
}
}
}
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("未找到【%s】所在link", id)})
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("link【%d】缺失道岔【id:%s,index:%s】端口【%s】偏移量", linkId, turnoutModel.GraphicId, id, port)})
}
// 根据linkID和link相对偏移量返回区段道岔偏移量
@ -224,45 +227,45 @@ func QueryDeviceByCalcLink(vm *VerifyStructure, id int32, offset int64) (string,
devicePosition = v
}
}
var sectionModel *section.PhysicalSectionModel
for _, s := range vm.PhysicalSectionModelMap {
sectionModel = s.(*section.PhysicalSectionModel)
if sectionModel.AxlePoints[devicePosition.Device.GetIndex()] != nil {
break
}
}
tm := vm.SwitchDeviceModelMap[devicePosition.Device.GetIndex()]
if sectionModel == nil && tm == nil {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在ID【%s】的设备", devicePosition.Device.GetIndex())})
}
if sectionModel != nil {
// 判断AB走向
sectionModel, ok := linkOffsetQuerySection(vm, devicePosition)
if ok {
pointA := sectionModel.PortAxlePoints[face.A.Name()]
pointB := sectionModel.PortAxlePoints[face.B.Name()]
if pointA == nil && pointB == nil {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("区段【%s】计轴缺失", sectionModel.GraphicId)})
}
if pointA.GetIndex() == devicePosition.Device.GetIndex() { // A-B走向
if devicePosition.Device.GetIndex() == pointA.GetIndex() {
return sectionModel.Index, "", offset - int64(devicePosition.Offset)
} else if pointB.GetIndex() == devicePosition.Device.GetIndex() { // B-A走向偏移为A - offset
} else {
for _, v := range linkModel.DevicePositions {
if v.Device.GetIndex() == pointA.GetIndex() {
return sectionModel.Index, "", int64(devicePosition.Offset) - offset
}
}
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("区段【%s】A端计轴缺失", sectionModel.GraphicId)})
}
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("区段【%s】计轴缺失", sectionModel.GraphicId)})
} else {
tm := vm.SwitchDeviceModelMap[devicePosition.Device.GetIndex()]
if tm == nil {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在道岔【index:%s】", devicePosition.Device.GetIndex())})
}
if linkModel.ARelatedSwitchRef.SwitchDevice.GetIndex() == devicePosition.Device.GetIndex() { // 起始点
return devicePosition.Device.GetIndex(), linkModel.ARelatedSwitchRef.Port.Name(), offset - int64(devicePosition.Offset)
} else if linkModel.BRelatedSwitchRef.SwitchDevice.GetIndex() == devicePosition.Device.GetIndex() { // 结束点
return devicePosition.Device.GetIndex(), linkModel.BRelatedSwitchRef.Port.Name(), int64(devicePosition.Offset) - offset
} else {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在ID【%s】的设备", devicePosition.Device.GetIndex())})
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在道岔【index:%s】", devicePosition.Device.GetIndex())})
}
}
}
func linkOffsetQuerySection(vm *VerifyStructure, devicePosition *ref.DevicePosition) (*section.PhysicalSectionModel, bool) {
var sectionModel *section.PhysicalSectionModel
for _, s := range vm.PhysicalSectionModelMap {
sectionModel = s.(*section.PhysicalSectionModel)
if sectionModel.AxlePoints[devicePosition.Device.GetIndex()] != nil {
return sectionModel, true
}
}
return nil, false
}
// 初始化地图结构
func initGraphicStructure(graphicData *graphicData.RtssGraphicStorage, verifyStructure *VerifyStructure, graphicDataMap *GraphicInfoMapStructure) {
// 初始化计轴信息

@ -1 +1 @@
Subproject commit b301710b88a46b232bdeae5cd480f002342b01a5
Subproject commit 5618f0586e6862a174579fd14151b46f45d14cb3