Skip to content

Commit 48e837d

Browse files
authored
RevitCheckingLevels: Код обновлен на C# 12 (#307)
1 parent 042e62f commit 48e837d

22 files changed

Lines changed: 1109 additions & 1151 deletions
Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
71
using Autodesk.Revit.DB;
82

9-
using dosymep.Bim4Everyone.ProjectConfigs;
103
using dosymep.Bim4Everyone;
4+
using dosymep.Bim4Everyone.ProjectConfigs;
115
using dosymep.Serializers;
6+
127
using pyRevitLabs.Json;
138

14-
namespace RevitCheckingLevels.Models {
15-
internal class CheckingLevelConfig : ProjectConfig<CheckingLevelSettings> {
16-
[JsonIgnore] public override string ProjectConfigPath { get; set; }
9+
namespace RevitCheckingLevels.Models;
10+
internal class CheckingLevelConfig : ProjectConfig<CheckingLevelSettings> {
11+
[JsonIgnore] public override string ProjectConfigPath { get; set; }
1712

18-
[JsonIgnore] public override IConfigSerializer Serializer { get; set; }
13+
[JsonIgnore] public override IConfigSerializer Serializer { get; set; }
1914

20-
public static CheckingLevelConfig GetCheckingLevelConfig() {
21-
return new ProjectConfigBuilder()
22-
.SetSerializer(new ConfigSerializer())
23-
.SetPluginName(nameof(RevitCheckingLevels))
24-
.SetRevitVersion(ModuleEnvironment.RevitVersion)
25-
.SetProjectConfigName(nameof(CheckingLevelConfig) + ".json")
26-
.Build<CheckingLevelConfig>();
27-
}
15+
public static CheckingLevelConfig GetCheckingLevelConfig() {
16+
return new ProjectConfigBuilder()
17+
.SetSerializer(new ConfigSerializer())
18+
.SetPluginName(nameof(RevitCheckingLevels))
19+
.SetRevitVersion(ModuleEnvironment.RevitVersion)
20+
.SetProjectConfigName(nameof(CheckingLevelConfig) + ".json")
21+
.Build<CheckingLevelConfig>();
2822
}
23+
}
2924

30-
internal class CheckingLevelSettings : ProjectSettings {
31-
public ElementId LinkTypeId { get; set; }
32-
public override string ProjectName { get; set; }
33-
}
25+
internal class CheckingLevelSettings : ProjectSettings {
26+
public ElementId LinkTypeId { get; set; }
27+
public override string ProjectName { get; set; }
3428
}
Lines changed: 127 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,197 +1,172 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44

55
using Autodesk.Revit.DB;
66

77
using RevitCheckingLevels.Models.LevelParser;
88

9-
namespace RevitCheckingLevels.Models {
10-
internal class ErrorType : IEquatable<ErrorType>, IComparable<ErrorType>, IComparable {
11-
public static readonly ErrorType NotStandard =
12-
new ErrorType(0) {
13-
Name = "Имена уровней не соответствуют стандарту",
14-
Description =
15-
"Имена уровней должны соответствовать данному формату: \"[Название этажа][\'_\'][Название блока][\'.\'][Номер уровня][\'_\'][Отметка уровня]\"."
16-
};
17-
18-
public static readonly ErrorType NotElevation =
19-
new ErrorType(1) {
20-
Name = "Отметки уровня не соответствуют фактическим",
21-
Description =
22-
$"Имена уровней должны оканчиваться значением параметра \"{LabelUtils.GetLabelFor(BuiltInParameter.LEVEL_ELEV)}\" в метрах с разделителем дробной части в виде точки."
23-
};
24-
25-
public static readonly ErrorType NotMillimeterElevation =
26-
new ErrorType(2) {
27-
Name = "Отметка уровня не округлена",
28-
Description =
29-
$"Значение параметра \"{LabelUtils.GetLabelFor(BuiltInParameter.LEVEL_ELEV)}\" (в миллиметрах) до 7 знака после запятой должно быть равно \"0\"."
30-
};
31-
32-
public static readonly ErrorType NotRangeElevation =
33-
new ErrorType(3) {
34-
Name = "Уровни замоделированы не по стандарту",
35-
Description =
36-
$"Значение параметра \"{LabelUtils.GetLabelFor(BuiltInParameter.LEVEL_ELEV)}\" должно отступать на 1500мм от предыдущего."
37-
};
38-
39-
public static readonly ErrorType NotFoundLevels =
40-
new ErrorType(4) {
41-
Name = "Уровни не найдены в координационном файле",
42-
Description = "Все уровни проекта должны присутствовать в координационном файле."
43-
};
44-
45-
public ErrorType(int id) {
46-
Id = id;
47-
}
48-
49-
public int Id { get; }
50-
public string Name { get; private set; }
51-
public string Description { get; private set; }
9+
namespace RevitCheckingLevels.Models;
10+
internal class ErrorType : IEquatable<ErrorType>, IComparable<ErrorType>, IComparable {
11+
public static readonly ErrorType NotStandard =
12+
new(0) {
13+
Name = "Имена уровней не соответствуют стандарту",
14+
Description =
15+
"Имена уровней должны соответствовать данному формату: \"[Название этажа][\'_\'][Название блока][\'.\'][Номер уровня][\'_\'][Отметка уровня]\"."
16+
};
17+
18+
public static readonly ErrorType NotElevation =
19+
new(1) {
20+
Name = "Отметки уровня не соответствуют фактическим",
21+
Description =
22+
$"Имена уровней должны оканчиваться значением параметра \"{LabelUtils.GetLabelFor(BuiltInParameter.LEVEL_ELEV)}\" в метрах с разделителем дробной части в виде точки."
23+
};
24+
25+
public static readonly ErrorType NotMillimeterElevation =
26+
new(2) {
27+
Name = "Отметка уровня не округлена",
28+
Description =
29+
$"Значение параметра \"{LabelUtils.GetLabelFor(BuiltInParameter.LEVEL_ELEV)}\" (в миллиметрах) до 7 знака после запятой должно быть равно \"0\"."
30+
};
31+
32+
public static readonly ErrorType NotRangeElevation =
33+
new(3) {
34+
Name = "Уровни замоделированы не по стандарту",
35+
Description =
36+
$"Значение параметра \"{LabelUtils.GetLabelFor(BuiltInParameter.LEVEL_ELEV)}\" должно отступать на 1500мм от предыдущего."
37+
};
38+
39+
public static readonly ErrorType NotFoundLevels =
40+
new(4) {
41+
Name = "Уровни не найдены в координационном файле",
42+
Description = "Все уровни проекта должны присутствовать в координационном файле."
43+
};
44+
45+
public ErrorType(int id) {
46+
Id = id;
47+
}
5248

53-
#region IEquatable<ErrorType>
49+
public int Id { get; }
50+
public string Name { get; private set; }
51+
public string Description { get; private set; }
5452

55-
public bool Equals(ErrorType other) {
56-
if(ReferenceEquals(null, other)) {
57-
return false;
58-
}
53+
#region IEquatable<ErrorType>
5954

60-
if(ReferenceEquals(this, other)) {
61-
return true;
62-
}
55+
public bool Equals(ErrorType other) {
56+
return other is not null && (ReferenceEquals(this, other) || Id == other.Id);
57+
}
6358

64-
return Id == other.Id;
59+
public override bool Equals(object obj) {
60+
if(obj is null) {
61+
return false;
6562
}
6663

67-
public override bool Equals(object obj) {
68-
if(ReferenceEquals(null, obj)) {
69-
return false;
70-
}
64+
return ReferenceEquals(this, obj) || obj.GetType() == GetType() && Equals((ErrorType) obj);
65+
}
7166

72-
if(ReferenceEquals(this, obj)) {
73-
return true;
74-
}
67+
public override int GetHashCode() {
68+
return Id;
69+
}
7570

76-
if(obj.GetType() != GetType()) {
77-
return false;
78-
}
71+
public static bool operator ==(ErrorType left, ErrorType right) {
72+
return Equals(left, right);
73+
}
7974

80-
return Equals((ErrorType) obj);
81-
}
75+
public static bool operator !=(ErrorType left, ErrorType right) {
76+
return !Equals(left, right);
77+
}
8278

83-
public override int GetHashCode() {
84-
return Id;
85-
}
79+
#endregion
8680

87-
public static bool operator ==(ErrorType left, ErrorType right) {
88-
return Equals(left, right);
89-
}
81+
#region IComparable<ErrorType>
9082

91-
public static bool operator !=(ErrorType left, ErrorType right) {
92-
return !Equals(left, right);
93-
}
83+
public int CompareTo(ErrorType other) {
84+
return ReferenceEquals(this, other) ? 0 : other is null ? 1 : Id.CompareTo(other.Id);
85+
}
9486

95-
#endregion
87+
public int CompareTo(object obj) {
88+
return CompareTo(obj as ErrorType);
89+
}
9690

97-
#region IComparable<ErrorType>
91+
#endregion
9892

99-
public int CompareTo(ErrorType other) {
100-
if(ReferenceEquals(this, other)) {
101-
return 0;
102-
}
93+
public override string ToString() {
94+
return Name;
95+
}
96+
}
10397

104-
if(ReferenceEquals(null, other)) {
105-
return 1;
106-
}
98+
internal static class LevelInfoExtensions {
99+
public static bool IsNotStandard(this LevelInfo levelInfo) {
100+
return levelInfo.Errors.Count > 0;
101+
}
107102

108-
return Id.CompareTo(other.Id);
103+
public static bool IsNotElevation(this LevelInfo levelInfo) {
104+
if(levelInfo.IsNotStandard()) {
105+
return false;
109106
}
110107

111-
public int CompareTo(object obj) {
112-
return CompareTo(obj as ErrorType);
108+
if(levelInfo.Elevation == null) {
109+
return false;
113110
}
114111

115-
#endregion
112+
double meterElevation = levelInfo.Level.GetMeterElevation();
113+
return !LevelExtensions.IsAlmostEqual(levelInfo.Elevation.Value, meterElevation, 0.001);
114+
}
116115

117-
public override string ToString() {
118-
return Name;
119-
}
116+
public static bool IsNotMillimeterElevation(this LevelInfo levelInfo) {
117+
double millimeterElevation = levelInfo.Level.GetMillimeterElevation();
118+
millimeterElevation = Math.Round(millimeterElevation, 7, MidpointRounding.AwayFromZero);
119+
return !LevelExtensions.IsAlmostEqual(millimeterElevation % 1, 0.0000001, 0.0000001);
120120
}
121121

122-
internal static class LevelInfoExtensions {
123-
public static bool IsNotStandard(this LevelInfo levelInfo) {
124-
return levelInfo.Errors.Count > 0;
122+
public static bool IsNotRangeElevation(this LevelInfo levelInfo, IEnumerable<LevelInfo> levelInfos) {
123+
if(levelInfo.Errors.Count > 0) {
124+
return false;
125125
}
126126

127-
public static bool IsNotElevation(this LevelInfo levelInfo) {
128-
if(levelInfo.IsNotStandard()) {
129-
return false;
130-
}
127+
var filtered = levelInfos
128+
.Where(item => item.Level.Id != levelInfo.Level.Id)
129+
.Where(item => item.Errors.Count == 0)
130+
.ToArray();
131131

132-
if(levelInfo.Elevation == null) {
133-
return false;
134-
}
135-
136-
double meterElevation = levelInfo.Level.GetMeterElevation();
137-
return !LevelExtensions.IsAlmostEqual(levelInfo.Elevation.Value, meterElevation, 0.001);
132+
if(levelInfo.HasSubLevel()) {
133+
return filtered
134+
.Where(item => item.HasSubLevel())
135+
.Where(item => item.IsEqualBlockName(levelInfo))
136+
.Any(item =>
137+
Math.Abs(levelInfo.Level.GetMillimeterElevation()
138+
- item.Level.GetMillimeterElevation()) < 1500);
138139
}
139140

140-
public static bool IsNotMillimeterElevation(this LevelInfo levelInfo) {
141-
double millimeterElevation = levelInfo.Level.GetMillimeterElevation();
142-
millimeterElevation = Math.Round(millimeterElevation, 7, MidpointRounding.AwayFromZero);
143-
return !LevelExtensions.IsAlmostEqual(millimeterElevation % 1, 0.0000001, 0.0000001);
144-
}
141+
if(!levelInfo.HasSubLevel()) {
142+
bool first = filtered
143+
.Where(item => !item.HasSubLevel())
144+
.Any(item => item.IsEqualLevelName(levelInfo) && item.IsEqualBlockName(levelInfo));
145145

146-
public static bool IsNotRangeElevation(this LevelInfo levelInfo, IEnumerable<LevelInfo> levelInfos) {
147-
if(levelInfo.Errors.Count > 0) {
148-
return false;
149-
}
150-
151-
var filtered = levelInfos
152-
.Where(item => item.Level.Id != levelInfo.Level.Id)
153-
.Where(item => item.Errors.Count == 0)
154-
.ToArray();
155-
156-
if(levelInfo.HasSubLevel()) {
157-
return filtered
158-
.Where(item => item.HasSubLevel())
159-
.Where(item => item.IsEqualBlockName(levelInfo))
160-
.Any(item =>
161-
Math.Abs(levelInfo.Level.GetMillimeterElevation()
162-
- item.Level.GetMillimeterElevation()) < 1500);
163-
}
164-
165-
if(!levelInfo.HasSubLevel()) {
166-
bool first = filtered
167-
.Where(item => !item.HasSubLevel())
168-
.Any(item => item.IsEqualLevelName(levelInfo) && item.IsEqualBlockName(levelInfo));
169-
170-
bool second = filtered
171-
.Where(item => !item.HasSubLevel())
172-
.Any(item => item.IsEqualBlockName(levelInfo) && item.IsEqualElevation(levelInfo));
173-
174-
return first || second;
175-
}
146+
bool second = filtered
147+
.Where(item => !item.HasSubLevel())
148+
.Any(item => item.IsEqualBlockName(levelInfo) && item.IsEqualElevation(levelInfo));
176149

177-
return false;
150+
return first || second;
178151
}
179152

180-
public static bool IsNotFoundLevels(this LevelInfo levelInfo, IEnumerable<LevelInfo> linkLevelInfos) {
181-
return !linkLevelInfos.Any(item => item.Level.Name.Equals(levelInfo.Level.Name));
182-
}
153+
return false;
154+
}
183155

184-
public static string GetNotStandardTooltip(this LevelInfo levelInfo) {
185-
return string.Join(Environment.NewLine, levelInfo.Errors);
186-
}
156+
public static bool IsNotFoundLevels(this LevelInfo levelInfo, IEnumerable<LevelInfo> linkLevelInfos) {
157+
return !linkLevelInfos.Any(item => item.Level.Name.Equals(levelInfo.Level.Name));
158+
}
187159

188-
public static string GetNotElevationTooltip(this LevelInfo levelInfo) {
189-
return $"Значение отметки: фактическое \"{levelInfo.Level.GetFormattedMeterElevation()}\", " +
190-
$"в имени уровня \"{levelInfo.ElevationName}\".";
191-
}
160+
public static string GetNotStandardTooltip(this LevelInfo levelInfo) {
161+
return string.Join(Environment.NewLine, levelInfo.Errors);
162+
}
192163

193-
public static string GetNotMillimeterElevationTooltip(this LevelInfo levelInfo) {
194-
return $"Значение отметки: фактическое \"{levelInfo.Level.GetFormattedMillimeterElevation()}\".";
195-
}
164+
public static string GetNotElevationTooltip(this LevelInfo levelInfo) {
165+
return $"Значение отметки: фактическое \"{levelInfo.Level.GetFormattedMeterElevation()}\", " +
166+
$"в имени уровня \"{levelInfo.ElevationName}\".";
167+
}
168+
169+
public static string GetNotMillimeterElevationTooltip(this LevelInfo levelInfo) {
170+
return $"Значение отметки: фактическое \"{levelInfo.Level.GetFormattedMillimeterElevation()}\".";
196171
}
197172
}

0 commit comments

Comments
 (0)