Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions src/RevitCheckingLevels/Models/CheckingLevelConfig.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.Revit.DB;

using dosymep.Bim4Everyone.ProjectConfigs;
using dosymep.Bim4Everyone;
using dosymep.Bim4Everyone.ProjectConfigs;
using dosymep.Serializers;

using pyRevitLabs.Json;

namespace RevitCheckingLevels.Models {
internal class CheckingLevelConfig : ProjectConfig<CheckingLevelSettings> {
[JsonIgnore] public override string ProjectConfigPath { get; set; }
namespace RevitCheckingLevels.Models;
internal class CheckingLevelConfig : ProjectConfig<CheckingLevelSettings> {
[JsonIgnore] public override string ProjectConfigPath { get; set; }

[JsonIgnore] public override IConfigSerializer Serializer { get; set; }
[JsonIgnore] public override IConfigSerializer Serializer { get; set; }

public static CheckingLevelConfig GetCheckingLevelConfig() {
return new ProjectConfigBuilder()
.SetSerializer(new ConfigSerializer())
.SetPluginName(nameof(RevitCheckingLevels))
.SetRevitVersion(ModuleEnvironment.RevitVersion)
.SetProjectConfigName(nameof(CheckingLevelConfig) + ".json")
.Build<CheckingLevelConfig>();
}
public static CheckingLevelConfig GetCheckingLevelConfig() {
return new ProjectConfigBuilder()
.SetSerializer(new ConfigSerializer())
.SetPluginName(nameof(RevitCheckingLevels))
.SetRevitVersion(ModuleEnvironment.RevitVersion)
.SetProjectConfigName(nameof(CheckingLevelConfig) + ".json")
.Build<CheckingLevelConfig>();
}
}

internal class CheckingLevelSettings : ProjectSettings {
public ElementId LinkTypeId { get; set; }
public override string ProjectName { get; set; }
}
internal class CheckingLevelSettings : ProjectSettings {
public ElementId LinkTypeId { get; set; }
public override string ProjectName { get; set; }
}
279 changes: 127 additions & 152 deletions src/RevitCheckingLevels/Models/ErrorType.cs
Original file line number Diff line number Diff line change
@@ -1,197 +1,172 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;

using Autodesk.Revit.DB;

using RevitCheckingLevels.Models.LevelParser;

namespace RevitCheckingLevels.Models {
internal class ErrorType : IEquatable<ErrorType>, IComparable<ErrorType>, IComparable {
public static readonly ErrorType NotStandard =
new ErrorType(0) {
Name = "Имена уровней не соответствуют стандарту",
Description =
"Имена уровней должны соответствовать данному формату: \"[Название этажа][\'_\'][Название блока][\'.\'][Номер уровня][\'_\'][Отметка уровня]\"."
};

public static readonly ErrorType NotElevation =
new ErrorType(1) {
Name = "Отметки уровня не соответствуют фактическим",
Description =
$"Имена уровней должны оканчиваться значением параметра \"{LabelUtils.GetLabelFor(BuiltInParameter.LEVEL_ELEV)}\" в метрах с разделителем дробной части в виде точки."
};

public static readonly ErrorType NotMillimeterElevation =
new ErrorType(2) {
Name = "Отметка уровня не округлена",
Description =
$"Значение параметра \"{LabelUtils.GetLabelFor(BuiltInParameter.LEVEL_ELEV)}\" (в миллиметрах) до 7 знака после запятой должно быть равно \"0\"."
};

public static readonly ErrorType NotRangeElevation =
new ErrorType(3) {
Name = "Уровни замоделированы не по стандарту",
Description =
$"Значение параметра \"{LabelUtils.GetLabelFor(BuiltInParameter.LEVEL_ELEV)}\" должно отступать на 1500мм от предыдущего."
};

public static readonly ErrorType NotFoundLevels =
new ErrorType(4) {
Name = "Уровни не найдены в координационном файле",
Description = "Все уровни проекта должны присутствовать в координационном файле."
};

public ErrorType(int id) {
Id = id;
}

public int Id { get; }
public string Name { get; private set; }
public string Description { get; private set; }
namespace RevitCheckingLevels.Models;
internal class ErrorType : IEquatable<ErrorType>, IComparable<ErrorType>, IComparable {
public static readonly ErrorType NotStandard =
new(0) {
Name = "Имена уровней не соответствуют стандарту",
Description =
"Имена уровней должны соответствовать данному формату: \"[Название этажа][\'_\'][Название блока][\'.\'][Номер уровня][\'_\'][Отметка уровня]\"."
};

public static readonly ErrorType NotElevation =
new(1) {
Name = "Отметки уровня не соответствуют фактическим",
Description =
$"Имена уровней должны оканчиваться значением параметра \"{LabelUtils.GetLabelFor(BuiltInParameter.LEVEL_ELEV)}\" в метрах с разделителем дробной части в виде точки."
};

public static readonly ErrorType NotMillimeterElevation =
new(2) {
Name = "Отметка уровня не округлена",
Description =
$"Значение параметра \"{LabelUtils.GetLabelFor(BuiltInParameter.LEVEL_ELEV)}\" (в миллиметрах) до 7 знака после запятой должно быть равно \"0\"."
};

public static readonly ErrorType NotRangeElevation =
new(3) {
Name = "Уровни замоделированы не по стандарту",
Description =
$"Значение параметра \"{LabelUtils.GetLabelFor(BuiltInParameter.LEVEL_ELEV)}\" должно отступать на 1500мм от предыдущего."
};

public static readonly ErrorType NotFoundLevels =
new(4) {
Name = "Уровни не найдены в координационном файле",
Description = "Все уровни проекта должны присутствовать в координационном файле."
};

public ErrorType(int id) {
Id = id;
}

#region IEquatable<ErrorType>
public int Id { get; }
public string Name { get; private set; }
public string Description { get; private set; }

public bool Equals(ErrorType other) {
if(ReferenceEquals(null, other)) {
return false;
}
#region IEquatable<ErrorType>

if(ReferenceEquals(this, other)) {
return true;
}
public bool Equals(ErrorType other) {
return other is not null && (ReferenceEquals(this, other) || Id == other.Id);
}

return Id == other.Id;
public override bool Equals(object obj) {
if(obj is null) {
return false;
}

public override bool Equals(object obj) {
if(ReferenceEquals(null, obj)) {
return false;
}
return ReferenceEquals(this, obj) || obj.GetType() == GetType() && Equals((ErrorType) obj);
}

if(ReferenceEquals(this, obj)) {
return true;
}
public override int GetHashCode() {
return Id;
}

if(obj.GetType() != GetType()) {
return false;
}
public static bool operator ==(ErrorType left, ErrorType right) {
return Equals(left, right);
}

return Equals((ErrorType) obj);
}
public static bool operator !=(ErrorType left, ErrorType right) {
return !Equals(left, right);
}

public override int GetHashCode() {
return Id;
}
#endregion

public static bool operator ==(ErrorType left, ErrorType right) {
return Equals(left, right);
}
#region IComparable<ErrorType>

public static bool operator !=(ErrorType left, ErrorType right) {
return !Equals(left, right);
}
public int CompareTo(ErrorType other) {
return ReferenceEquals(this, other) ? 0 : other is null ? 1 : Id.CompareTo(other.Id);
}

#endregion
public int CompareTo(object obj) {
return CompareTo(obj as ErrorType);
}

#region IComparable<ErrorType>
#endregion

public int CompareTo(ErrorType other) {
if(ReferenceEquals(this, other)) {
return 0;
}
public override string ToString() {
return Name;
}
}

if(ReferenceEquals(null, other)) {
return 1;
}
internal static class LevelInfoExtensions {
public static bool IsNotStandard(this LevelInfo levelInfo) {
return levelInfo.Errors.Count > 0;
}

return Id.CompareTo(other.Id);
public static bool IsNotElevation(this LevelInfo levelInfo) {
if(levelInfo.IsNotStandard()) {
return false;
}

public int CompareTo(object obj) {
return CompareTo(obj as ErrorType);
if(levelInfo.Elevation == null) {
return false;
}

#endregion
double meterElevation = levelInfo.Level.GetMeterElevation();
return !LevelExtensions.IsAlmostEqual(levelInfo.Elevation.Value, meterElevation, 0.001);
}

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

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

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

if(levelInfo.Elevation == null) {
return false;
}

double meterElevation = levelInfo.Level.GetMeterElevation();
return !LevelExtensions.IsAlmostEqual(levelInfo.Elevation.Value, meterElevation, 0.001);
if(levelInfo.HasSubLevel()) {
return filtered
.Where(item => item.HasSubLevel())
.Where(item => item.IsEqualBlockName(levelInfo))
.Any(item =>
Math.Abs(levelInfo.Level.GetMillimeterElevation()
- item.Level.GetMillimeterElevation()) < 1500);
}

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

public static bool IsNotRangeElevation(this LevelInfo levelInfo, IEnumerable<LevelInfo> levelInfos) {
if(levelInfo.Errors.Count > 0) {
return false;
}

var filtered = levelInfos
.Where(item => item.Level.Id != levelInfo.Level.Id)
.Where(item => item.Errors.Count == 0)
.ToArray();

if(levelInfo.HasSubLevel()) {
return filtered
.Where(item => item.HasSubLevel())
.Where(item => item.IsEqualBlockName(levelInfo))
.Any(item =>
Math.Abs(levelInfo.Level.GetMillimeterElevation()
- item.Level.GetMillimeterElevation()) < 1500);
}

if(!levelInfo.HasSubLevel()) {
bool first = filtered
.Where(item => !item.HasSubLevel())
.Any(item => item.IsEqualLevelName(levelInfo) && item.IsEqualBlockName(levelInfo));

bool second = filtered
.Where(item => !item.HasSubLevel())
.Any(item => item.IsEqualBlockName(levelInfo) && item.IsEqualElevation(levelInfo));

return first || second;
}
bool second = filtered
.Where(item => !item.HasSubLevel())
.Any(item => item.IsEqualBlockName(levelInfo) && item.IsEqualElevation(levelInfo));

return false;
return first || second;
}

public static bool IsNotFoundLevels(this LevelInfo levelInfo, IEnumerable<LevelInfo> linkLevelInfos) {
return !linkLevelInfos.Any(item => item.Level.Name.Equals(levelInfo.Level.Name));
}
return false;
}

public static string GetNotStandardTooltip(this LevelInfo levelInfo) {
return string.Join(Environment.NewLine, levelInfo.Errors);
}
public static bool IsNotFoundLevels(this LevelInfo levelInfo, IEnumerable<LevelInfo> linkLevelInfos) {
return !linkLevelInfos.Any(item => item.Level.Name.Equals(levelInfo.Level.Name));
}

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

public static string GetNotMillimeterElevationTooltip(this LevelInfo levelInfo) {
return $"Значение отметки: фактическое \"{levelInfo.Level.GetFormattedMillimeterElevation()}\".";
}
public static string GetNotElevationTooltip(this LevelInfo levelInfo) {
return $"Значение отметки: фактическое \"{levelInfo.Level.GetFormattedMeterElevation()}\", " +
$"в имени уровня \"{levelInfo.ElevationName}\".";
}

public static string GetNotMillimeterElevationTooltip(this LevelInfo levelInfo) {
return $"Значение отметки: фактическое \"{levelInfo.Level.GetFormattedMillimeterElevation()}\".";
}
}
Loading