|
11 | 11 | using System.Data; |
12 | 12 | using Microsoft.AspNetCore.Components; |
13 | 13 | using static FWO.Data.Modelling.ModellingTypes; |
| 14 | +using System.Collections.Generic; |
14 | 15 |
|
15 | 16 |
|
16 | 17 | namespace FWO.Services |
@@ -1020,12 +1021,37 @@ public bool CalcVisibility() |
1020 | 1021 | return true; |
1021 | 1022 | } |
1022 | 1023 |
|
1023 | | - public bool IsAreaForbiddenInDirection(Direction direction) |
| 1024 | + private List<ModellingNetworkArea> GetAreasInDirection(List<ModellingNetworkArea> networkAreas, Direction direction) |
| 1025 | + { |
| 1026 | + List<ModellingNetworkArea> directionNetworkAreas = []; |
| 1027 | + |
| 1028 | + foreach (ModellingNetworkArea area in networkAreas) |
| 1029 | + { |
| 1030 | + if (direction == Direction.Source) |
| 1031 | + { |
| 1032 | + if (ActConn.SourceAreas.FirstOrDefault(w => w.Content.Id == area.Id) == null && !SrcAreasToAdd.Contains(area)) |
| 1033 | + { |
| 1034 | + directionNetworkAreas.Add(area); |
| 1035 | + } |
| 1036 | + } |
| 1037 | + else if (direction == Direction.Destination) |
| 1038 | + { |
| 1039 | + if (ActConn.DestinationAreas.FirstOrDefault(w => w.Content.Id == area.Id) == null && !DstAreasToAdd.Contains(area)) |
| 1040 | + { |
| 1041 | + directionNetworkAreas.Add(area); |
| 1042 | + } |
| 1043 | + } |
| 1044 | + } |
| 1045 | + |
| 1046 | + return directionNetworkAreas; |
| 1047 | + } |
| 1048 | + |
| 1049 | + public bool IsAreaForbiddenInDirection(List<ModellingNetworkArea> networkAreas, Direction direction) |
1024 | 1050 | { |
1025 | 1051 | return direction switch |
1026 | 1052 | { |
1027 | | - Direction.Source => ActConn.DestinationAreas.Count > 0 || DstAreasToAdd.Count > 0, |
1028 | | - Direction.Destination => ActConn.SourceAreas.Count > 0 || SrcAreasToAdd.Count > 0, |
| 1053 | + Direction.Source => ActConn.DestinationAreas.Count > 0 || GetAreasInDirection(networkAreas, Direction.Destination).Count > 0, |
| 1054 | + Direction.Destination => ActConn.SourceAreas.Count > 0 || GetAreasInDirection(networkAreas, Direction.Source).Count > 0, |
1029 | 1055 | _ => false, |
1030 | 1056 | }; |
1031 | 1057 | } |
@@ -1053,7 +1079,7 @@ public bool NetworkAreaUseAllowed(List<ModellingNetworkArea> networkAreas, Direc |
1053 | 1079 | reason.Title = userConfig.GetText("edit_connection"); |
1054 | 1080 | } |
1055 | 1081 |
|
1056 | | - if (IsAreaForbiddenInDirection(direction)) |
| 1082 | + if (IsAreaForbiddenInDirection(networkAreas, direction)) |
1057 | 1083 | { |
1058 | 1084 | reason.Text = userConfig.GetText("direction_contain_nwarea"); |
1059 | 1085 | return false; |
|
0 commit comments