From eb39b01bb58d84978861a87949cadfe70c98b54f Mon Sep 17 00:00:00 2001 From: DivinN Date: Wed, 6 Nov 2024 15:57:12 +0300 Subject: [PATCH 01/29] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=20?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BF=D0=BB=D0=B0=D0=B3=D0=B8?= =?UTF-8?q?=D0=BD=20RevitKrChecker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/publish.RevitKrChecker.yml | 37 +++++++++ .nuke/parameters.RevitKrChecker.json | 15 ++++ RevitPlugins.sln | 16 ++++ .../Localization/Language.cs-CZ.xaml | 14 ++++ .../Localization/Language.de-DE.xaml | 13 ++++ .../Localization/Language.en-GB.xaml | 13 ++++ .../Localization/Language.en-US.xaml | 13 ++++ .../Localization/Language.es-ES.xaml | 13 ++++ .../Localization/Language.fr-FR.xaml | 13 ++++ .../Localization/Language.hu-HU.xaml | 13 ++++ .../Localization/Language.it-IT.xaml | 13 ++++ .../Localization/Language.ja-JP.xaml | 13 ++++ .../Localization/Language.ko-KR.xaml | 13 ++++ .../Localization/Language.nl-NL.xaml | 13 ++++ .../Localization/Language.pl-PL.xaml | 13 ++++ .../Localization/Language.pt-BR.xaml | 13 ++++ .../Localization/Language.ru-RU.xaml | 13 ++++ .../Localization/Language.zh-CHS.xaml | 13 ++++ .../Localization/Language.zh-CHT.xaml | 13 ++++ src/RevitKrChecker/Models/PluginConfig.cs | 27 +++++++ src/RevitKrChecker/Models/RevitRepository.cs | 16 ++++ src/RevitKrChecker/README.md | 12 +++ src/RevitKrChecker/RevitKrChecker.csproj | 5 ++ src/RevitKrChecker/RevitKrCheckerCommand.cs | 61 +++++++++++++++ .../ViewModels/MainViewModel.cs | 76 +++++++++++++++++++ src/RevitKrChecker/Views/MainWindow.xaml | 69 +++++++++++++++++ src/RevitKrChecker/Views/MainWindow.xaml.cs | 20 +++++ 27 files changed, 563 insertions(+) create mode 100644 .github/workflows/publish.RevitKrChecker.yml create mode 100644 .nuke/parameters.RevitKrChecker.json create mode 100644 src/RevitKrChecker/Localization/Language.cs-CZ.xaml create mode 100644 src/RevitKrChecker/Localization/Language.de-DE.xaml create mode 100644 src/RevitKrChecker/Localization/Language.en-GB.xaml create mode 100644 src/RevitKrChecker/Localization/Language.en-US.xaml create mode 100644 src/RevitKrChecker/Localization/Language.es-ES.xaml create mode 100644 src/RevitKrChecker/Localization/Language.fr-FR.xaml create mode 100644 src/RevitKrChecker/Localization/Language.hu-HU.xaml create mode 100644 src/RevitKrChecker/Localization/Language.it-IT.xaml create mode 100644 src/RevitKrChecker/Localization/Language.ja-JP.xaml create mode 100644 src/RevitKrChecker/Localization/Language.ko-KR.xaml create mode 100644 src/RevitKrChecker/Localization/Language.nl-NL.xaml create mode 100644 src/RevitKrChecker/Localization/Language.pl-PL.xaml create mode 100644 src/RevitKrChecker/Localization/Language.pt-BR.xaml create mode 100644 src/RevitKrChecker/Localization/Language.ru-RU.xaml create mode 100644 src/RevitKrChecker/Localization/Language.zh-CHS.xaml create mode 100644 src/RevitKrChecker/Localization/Language.zh-CHT.xaml create mode 100644 src/RevitKrChecker/Models/PluginConfig.cs create mode 100644 src/RevitKrChecker/Models/RevitRepository.cs create mode 100644 src/RevitKrChecker/README.md create mode 100644 src/RevitKrChecker/RevitKrChecker.csproj create mode 100644 src/RevitKrChecker/RevitKrCheckerCommand.cs create mode 100644 src/RevitKrChecker/ViewModels/MainViewModel.cs create mode 100644 src/RevitKrChecker/Views/MainWindow.xaml create mode 100644 src/RevitKrChecker/Views/MainWindow.xaml.cs diff --git a/.github/workflows/publish.RevitKrChecker.yml b/.github/workflows/publish.RevitKrChecker.yml new file mode 100644 index 000000000..1d20d1894 --- /dev/null +++ b/.github/workflows/publish.RevitKrChecker.yml @@ -0,0 +1,37 @@ +name: publish RevitKrChecker + +on: + workflow_dispatch: + pull_request: + types: [ closed, synchronize, review_requested ] + branches: [ main, master ] + paths: + - '**RevitKrChecker**.cs' + - '**RevitKrChecker**.xaml' + +env: + plugin-name: "RevitKrChecker" + +jobs: + build: + name: build + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + # Install the .NET workload + - name: Install .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + # Add DevExrepress package source: https://nuget.devexpress.com/ + - name: Add DevExpress package source + run: dotnet nuget add source https://nuget.devexpress.com/api -n DXFeed -u DevExpress -p ${{ secrets.DEVEXPRESS_FEED_AUTHORIZATION_KEY }} + + - name: Run './build.cmd ' + run: ./build.cmd publish --profile ${{ env.plugin-name }} --pull-request-merged ${{ github.event.pull_request.merged }} --extensions-app-token ${{ secrets.EXTENSIONS_APP_TOKEN }} --revit-plugins-app-token ${{ secrets.REVIT_PLUGINS_APP_TOKEN }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.nuke/parameters.RevitKrChecker.json b/.nuke/parameters.RevitKrChecker.json new file mode 100644 index 000000000..49c6b4ceb --- /dev/null +++ b/.nuke/parameters.RevitKrChecker.json @@ -0,0 +1,15 @@ +{ + "$schema": "./build.schema.json", + "Solution": "RevitPlugins.sln", + "PluginName": "RevitKrChecker", + "PublishDirectory": "03.KR.extension\\КР.tab\\bin", + "RevitVersions": [ + "Rv2022", + "Rv2023", + "Rv2024" + ], + "IconUrl": "https://icons8.com/icon/LunGMFAtVtVk/financial-growth-analysis", + "BundleName": "Проверить модель", + "BundleType": "InvokeButton", + "BundleOutput": "03.KR.extension\\КР.tab\\ВОР.panel" +} diff --git a/RevitPlugins.sln b/RevitPlugins.sln index 0f4e6917d..13d06177d 100644 --- a/RevitPlugins.sln +++ b/RevitPlugins.sln @@ -314,6 +314,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RevitScheduleImport", "src\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RevitValueModifier", "src\RevitValueModifier\RevitValueModifier.csproj", "{5DC57D21-89E1-415D-AB2D-8ECCA7853219}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RevitKrChecker", "src\RevitKrChecker\RevitKrChecker.csproj", "{54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution D2020|x64 = D2020|x64 @@ -934,6 +936,20 @@ Global {5DC57D21-89E1-415D-AB2D-8ECCA7853219}.Debug|x64.Build.0 = Debug|x64 {5DC57D21-89E1-415D-AB2D-8ECCA7853219}.Release|x64.ActiveCfg = Release|x64 {5DC57D21-89E1-415D-AB2D-8ECCA7853219}.Release|x64.Build.0 = Release|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.D2020|x64.ActiveCfg = D2020|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.D2020|x64.Build.0 = D2020|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.D2021|x64.ActiveCfg = D2021|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.D2021|x64.Build.0 = D2021|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.D2022|x64.ActiveCfg = D2022|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.D2022|x64.Build.0 = D2022|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.D2023|x64.ActiveCfg = D2023|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.D2023|x64.Build.0 = D2023|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.D2024|x64.ActiveCfg = D2024|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.D2024|x64.Build.0 = D2024|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.Debug|x64.ActiveCfg = D2020|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.Debug|x64.Build.0 = D2020|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.Release|x64.ActiveCfg = D2020|x64 + {54B921FA-A2E3-41E4-94B9-8BE7D2F4AE3F}.Release|x64.Build.0 = D2020|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/RevitKrChecker/Localization/Language.cs-CZ.xaml b/src/RevitKrChecker/Localization/Language.cs-CZ.xaml new file mode 100644 index 000000000..2c6f5a9cd --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.cs-CZ.xaml @@ -0,0 +1,14 @@ + + + + + Příklad příkazu + Ahoj Revit! + Zadejte hodnotu vlastnosti, kterou chcete uložit. + + + OK + Zrušit + diff --git a/src/RevitKrChecker/Localization/Language.de-DE.xaml b/src/RevitKrChecker/Localization/Language.de-DE.xaml new file mode 100644 index 000000000..bc9ea91a3 --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.de-DE.xaml @@ -0,0 +1,13 @@ + + + + + Beispielbefehl + Hallo Revit! + Geben Sie einen Wert für die zu speichernde Eigenschaft ein. + + OK + Stornierung + diff --git a/src/RevitKrChecker/Localization/Language.en-GB.xaml b/src/RevitKrChecker/Localization/Language.en-GB.xaml new file mode 100644 index 000000000..6df22f0e2 --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.en-GB.xaml @@ -0,0 +1,13 @@ + + + + + Sample command + Hello Revit! + Enter a value for the property to save. + + OK + Cancel + diff --git a/src/RevitKrChecker/Localization/Language.en-US.xaml b/src/RevitKrChecker/Localization/Language.en-US.xaml new file mode 100644 index 000000000..30c94accd --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.en-US.xaml @@ -0,0 +1,13 @@ + + + + + Sample command + Hello Revit! + Enter a value for the property to save. + + OK + Cancel + diff --git a/src/RevitKrChecker/Localization/Language.es-ES.xaml b/src/RevitKrChecker/Localization/Language.es-ES.xaml new file mode 100644 index 000000000..d77967e5c --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.es-ES.xaml @@ -0,0 +1,13 @@ + + + + + Comando de ejemplo + Hola Revit! + Introduzca un valor para la propiedad que desea guardar. + + OK + Cancelar + diff --git a/src/RevitKrChecker/Localization/Language.fr-FR.xaml b/src/RevitKrChecker/Localization/Language.fr-FR.xaml new file mode 100644 index 000000000..8c859c56e --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.fr-FR.xaml @@ -0,0 +1,13 @@ + + + + + Exemple de commande + Bonjour Revit! + Entrez une valeur pour la propriété à enregistrer. + + OK + Annuler + diff --git a/src/RevitKrChecker/Localization/Language.hu-HU.xaml b/src/RevitKrChecker/Localization/Language.hu-HU.xaml new file mode 100644 index 000000000..4efb65f60 --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.hu-HU.xaml @@ -0,0 +1,13 @@ + + + + + Példa parancs + Helló Revit! + Adja meg a menteni kívánt tulajdonság értékét. + + OK + Mégse + diff --git a/src/RevitKrChecker/Localization/Language.it-IT.xaml b/src/RevitKrChecker/Localization/Language.it-IT.xaml new file mode 100644 index 000000000..6092abfd5 --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.it-IT.xaml @@ -0,0 +1,13 @@ + + + + + Comando di esempio + Ciao Revit! + Immettere un valore per la proprietà da salvare. + + OK + Annulla + diff --git a/src/RevitKrChecker/Localization/Language.ja-JP.xaml b/src/RevitKrChecker/Localization/Language.ja-JP.xaml new file mode 100644 index 000000000..dad56ba95 --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.ja-JP.xaml @@ -0,0 +1,13 @@ + + + + + コマンド例 + こんにちは Revit! + 保存するプロパティの値を入力します。 + + OK + キャンセル + diff --git a/src/RevitKrChecker/Localization/Language.ko-KR.xaml b/src/RevitKrChecker/Localization/Language.ko-KR.xaml new file mode 100644 index 000000000..e6d6468ea --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.ko-KR.xaml @@ -0,0 +1,13 @@ + + + + + 예제 명령 + 안녕하세요 Revit! + 저장할 속성의 값을 입력하세요. + + OK + 취소 + diff --git a/src/RevitKrChecker/Localization/Language.nl-NL.xaml b/src/RevitKrChecker/Localization/Language.nl-NL.xaml new file mode 100644 index 000000000..c5507844f --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.nl-NL.xaml @@ -0,0 +1,13 @@ + + + + + Voorbeeld commando + Hallo Revit! + Voer een waarde in voor de eigenschap die u wilt opslaan. + + OK + Annuleren + diff --git a/src/RevitKrChecker/Localization/Language.pl-PL.xaml b/src/RevitKrChecker/Localization/Language.pl-PL.xaml new file mode 100644 index 000000000..fa0aad4cb --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.pl-PL.xaml @@ -0,0 +1,13 @@ + + + + + Przykładowe polecenie + Cześć Revit! + Wprowadź wartość właściwości do zapisania. + + OK + Anulować + diff --git a/src/RevitKrChecker/Localization/Language.pt-BR.xaml b/src/RevitKrChecker/Localization/Language.pt-BR.xaml new file mode 100644 index 000000000..05757a7dc --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.pt-BR.xaml @@ -0,0 +1,13 @@ + + + + + Comando de exemplo + Olá Revit! + Insira um valor para a propriedade salvar. + + OK + Cancelar + diff --git a/src/RevitKrChecker/Localization/Language.ru-RU.xaml b/src/RevitKrChecker/Localization/Language.ru-RU.xaml new file mode 100644 index 000000000..f6e52c8ca --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.ru-RU.xaml @@ -0,0 +1,13 @@ + + + + + Пример команды + Привет Revit! + Введите значение сохраняемого свойства. + + ОК + Отмена + diff --git a/src/RevitKrChecker/Localization/Language.zh-CHS.xaml b/src/RevitKrChecker/Localization/Language.zh-CHS.xaml new file mode 100644 index 000000000..b3f8c5fbb --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.zh-CHS.xaml @@ -0,0 +1,13 @@ + + + + + 命令示例 + 你好 Revit! + 输入要保存的属性的值。 + + OK + 取消 + diff --git a/src/RevitKrChecker/Localization/Language.zh-CHT.xaml b/src/RevitKrChecker/Localization/Language.zh-CHT.xaml new file mode 100644 index 000000000..7a0ece806 --- /dev/null +++ b/src/RevitKrChecker/Localization/Language.zh-CHT.xaml @@ -0,0 +1,13 @@ + + + + + 命令範例 + 你好 Revit! + 輸入要儲存的屬性的值。 + + OK + 取消 + diff --git a/src/RevitKrChecker/Models/PluginConfig.cs b/src/RevitKrChecker/Models/PluginConfig.cs new file mode 100644 index 000000000..5410b8d5f --- /dev/null +++ b/src/RevitKrChecker/Models/PluginConfig.cs @@ -0,0 +1,27 @@ +using dosymep.Bim4Everyone; +using dosymep.Bim4Everyone.ProjectConfigs; +using dosymep.Serializers; + +using pyRevitLabs.Json; + +namespace RevitKrChecker.Models { + internal class PluginConfig : ProjectConfig { + [JsonIgnore] public override string ProjectConfigPath { get; set; } + + [JsonIgnore] public override IConfigSerializer Serializer { get; set; } + + public static PluginConfig GetPluginConfig() { + return new ProjectConfigBuilder() + .SetSerializer(new ConfigSerializer()) + .SetPluginName(nameof(RevitKrChecker)) + .SetRevitVersion(ModuleEnvironment.RevitVersion) + .SetProjectConfigName(nameof(PluginConfig) + ".json") + .Build(); + } + } + + internal class RevitSettings : ProjectSettings { + public override string ProjectName { get; set; } + public string SaveProperty { get; set; } + } +} diff --git a/src/RevitKrChecker/Models/RevitRepository.cs b/src/RevitKrChecker/Models/RevitRepository.cs new file mode 100644 index 000000000..59202f797 --- /dev/null +++ b/src/RevitKrChecker/Models/RevitRepository.cs @@ -0,0 +1,16 @@ +using Autodesk.Revit.ApplicationServices; +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; + +namespace RevitKrChecker.Models { + internal class RevitRepository { + public RevitRepository(UIApplication uiApplication) { + UIApplication = uiApplication; + } + + public UIApplication UIApplication { get; } + public UIDocument ActiveUIDocument => UIApplication.ActiveUIDocument; + public Application Application => UIApplication.Application; + public Document Document => ActiveUIDocument.Document; + } +} diff --git a/src/RevitKrChecker/README.md b/src/RevitKrChecker/README.md new file mode 100644 index 000000000..b3f4afc5a --- /dev/null +++ b/src/RevitKrChecker/README.md @@ -0,0 +1,12 @@ +# RevitKrChecker (Проверить модель) +Описание проекта + +# Сборка проекта +``` +nuke compile --profile RevitKrChecker +``` + +# Публикация проекта +``` +nuke publish --profile RevitKrChecker +``` diff --git a/src/RevitKrChecker/RevitKrChecker.csproj b/src/RevitKrChecker/RevitKrChecker.csproj new file mode 100644 index 000000000..efdb07ba9 --- /dev/null +++ b/src/RevitKrChecker/RevitKrChecker.csproj @@ -0,0 +1,5 @@ + + + true + + diff --git a/src/RevitKrChecker/RevitKrCheckerCommand.cs b/src/RevitKrChecker/RevitKrCheckerCommand.cs new file mode 100644 index 000000000..b5b8a09e9 --- /dev/null +++ b/src/RevitKrChecker/RevitKrCheckerCommand.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Interop; + +using Autodesk.Revit.ApplicationServices; +using Autodesk.Revit.Attributes; +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; + +using dosymep.Bim4Everyone; +using dosymep.Bim4Everyone.SimpleServices; +using dosymep.SimpleServices; +using dosymep.WPF.Views; +using dosymep.Xpf.Core.Ninject; + +using Ninject; + +using RevitKrChecker.Models; +using RevitKrChecker.ViewModels; +using RevitKrChecker.Views; + +namespace RevitKrChecker { + [Transaction(TransactionMode.Manual)] + public class RevitKrCheckerCommand : BasePluginCommand { + public RevitKrCheckerCommand() { + PluginName = "RevitKrChecker"; + } + + protected override void Execute(UIApplication uiApplication) { + using(IKernel kernel = uiApplication.CreatePlatformServices()) { + kernel.Bind() + .ToSelf() + .InSingletonScope(); + + kernel.Bind() + .ToMethod(c => PluginConfig.GetPluginConfig()); + + kernel.Bind().ToSelf(); + kernel.Bind().ToSelf() + .WithPropertyValue(nameof(Window.DataContext), + c => c.Kernel.Get()) + .WithPropertyValue(nameof(PlatformWindow.LocalizationService), + c => c.Kernel.Get()); + + string assemblyName = Assembly.GetExecutingAssembly().GetName().Name; + + kernel.UseXtraLocalization( + $"/{assemblyName};component/Localization/Language.xaml", + CultureInfo.GetCultureInfo("ru-RU")); + + Notification(kernel.Get()); + } + } + } +} diff --git a/src/RevitKrChecker/ViewModels/MainViewModel.cs b/src/RevitKrChecker/ViewModels/MainViewModel.cs new file mode 100644 index 000000000..2389ef891 --- /dev/null +++ b/src/RevitKrChecker/ViewModels/MainViewModel.cs @@ -0,0 +1,76 @@ +using System.Windows.Input; + +using dosymep.SimpleServices; +using dosymep.WPF.Commands; +using dosymep.WPF.ViewModels; + +using RevitKrChecker.Models; + +namespace RevitKrChecker.ViewModels { + internal class MainViewModel : BaseViewModel { + private readonly PluginConfig _pluginConfig; + private readonly RevitRepository _revitRepository; + private readonly ILocalizationService _localizationService; + + private string _errorText; + private string _saveProperty; + + public MainViewModel( + PluginConfig pluginConfig, + RevitRepository revitRepository, + ILocalizationService localizationService) { + + _pluginConfig = pluginConfig; + _revitRepository = revitRepository; + _localizationService = localizationService; + + LoadViewCommand = RelayCommand.Create(LoadView); + AcceptViewCommand = RelayCommand.Create(AcceptView, CanAcceptView); + } + + public ICommand LoadViewCommand { get; } + public ICommand AcceptViewCommand { get; } + + public string ErrorText { + get => _errorText; + set => this.RaiseAndSetIfChanged(ref _errorText, value); + } + + public string SaveProperty { + get => _saveProperty; + set => this.RaiseAndSetIfChanged(ref _saveProperty, value); + } + + private void LoadView() { + LoadConfig(); + } + + private void AcceptView() { + SaveConfig(); + } + + private bool CanAcceptView() { + if(string.IsNullOrEmpty(SaveProperty)) { + ErrorText = _localizationService.GetLocalizedString("MainWindow.HelloCheck"); + return false; + } + + ErrorText = null; + return true; + } + + private void LoadConfig() { + RevitSettings setting = _pluginConfig.GetSettings(_revitRepository.Document); + + SaveProperty = setting?.SaveProperty ?? _localizationService.GetLocalizedString("MainWindow.Hello"); + } + + private void SaveConfig() { + RevitSettings setting = _pluginConfig.GetSettings(_revitRepository.Document) + ?? _pluginConfig.AddSettings(_revitRepository.Document); + + setting.SaveProperty = SaveProperty; + _pluginConfig.SaveProjectConfig(); + } + } +} diff --git a/src/RevitKrChecker/Views/MainWindow.xaml b/src/RevitKrChecker/Views/MainWindow.xaml new file mode 100644 index 000000000..6c28c0a99 --- /dev/null +++ b/src/RevitKrChecker/Views/MainWindow.xaml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/RevitKrChecker/Views/MainWindow.xaml.cs b/src/RevitKrChecker/Views/MainWindow.xaml.cs new file mode 100644 index 000000000..83f82cc0a --- /dev/null +++ b/src/RevitKrChecker/Views/MainWindow.xaml.cs @@ -0,0 +1,20 @@ +using System.Windows; + +namespace RevitKrChecker.Views { + public partial class MainWindow { + public MainWindow() { + InitializeComponent(); + } + + public override string PluginName => nameof(RevitKrChecker); + public override string ProjectConfigName => nameof(MainWindow); + + private void ButtonOk_Click(object sender, RoutedEventArgs e) { + DialogResult = true; + } + + private void ButtonCancel_Click(object sender, RoutedEventArgs e) { + DialogResult = false; + } + } +} From 38bd2545a27f19cbd5d49aab96508816dc02ea4c Mon Sep 17 00:00:00 2001 From: DivinN Date: Thu, 7 Nov 2024 14:59:57 +0300 Subject: [PATCH 02/29] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B8=20=D0=BD=D0=B0=20?= =?UTF-8?q?Devexpress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RevitKrChecker/RevitKrChecker.csproj | 1 - src/RevitKrChecker/RevitKrCheckerCommand.cs | 9 +------ src/RevitKrChecker/Views/MainWindow.xaml | 28 +++++++++++---------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/RevitKrChecker/RevitKrChecker.csproj b/src/RevitKrChecker/RevitKrChecker.csproj index efdb07ba9..2ff5d4796 100644 --- a/src/RevitKrChecker/RevitKrChecker.csproj +++ b/src/RevitKrChecker/RevitKrChecker.csproj @@ -1,5 +1,4 @@ - true diff --git a/src/RevitKrChecker/RevitKrCheckerCommand.cs b/src/RevitKrChecker/RevitKrCheckerCommand.cs index b5b8a09e9..d512c05e0 100644 --- a/src/RevitKrChecker/RevitKrCheckerCommand.cs +++ b/src/RevitKrChecker/RevitKrCheckerCommand.cs @@ -1,14 +1,7 @@ -using System; -using System.Collections.Generic; using System.Globalization; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using System.Windows; -using System.Windows.Interop; -using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; @@ -29,7 +22,7 @@ namespace RevitKrChecker { [Transaction(TransactionMode.Manual)] public class RevitKrCheckerCommand : BasePluginCommand { public RevitKrCheckerCommand() { - PluginName = "RevitKrChecker"; + PluginName = "Проверить модель"; } protected override void Execute(UIApplication uiApplication) { diff --git a/src/RevitKrChecker/Views/MainWindow.xaml b/src/RevitKrChecker/Views/MainWindow.xaml index 6c28c0a99..f3533efb3 100644 --- a/src/RevitKrChecker/Views/MainWindow.xaml +++ b/src/RevitKrChecker/Views/MainWindow.xaml @@ -1,15 +1,15 @@ - - - - + + + + + @@ -31,7 +33,7 @@ Height="Auto" /> - - - - + From 383cc4e59ce7691d5f87462e3234edc9478f61d3 Mon Sep 17 00:00:00 2001 From: DivinN Date: Wed, 18 Dec 2024 15:24:32 +0300 Subject: [PATCH 03/29] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B8=D0=B7=D0=B2?= =?UTF-8?q?=D0=B5=D0=B4=D0=B5=D0=BD=D0=BE=20=D0=BE=D0=BF=D0=B8=D1=81=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2=20=D0=BF?= =?UTF-8?q?=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Check/CompareParamsCheck.cs | 41 ++++++ .../Models/Check/HasValueCheck.cs | 32 +++++ src/RevitKrChecker/Models/Check/ICheck.cs | 11 ++ src/RevitKrChecker/Models/Check/ParamCheck.cs | 62 ++++++++++ .../Check/TemplatesCompareParamsCheck.cs | 60 +++++++++ src/RevitKrChecker/Models/CheckInfo.cs | 18 +++ src/RevitKrChecker/Models/RevitRepository.cs | 63 ++++++++++ .../Models/Rule/ContainsCheckRule.cs | 14 +++ .../Models/Rule/EqualCheckRule.cs | 14 +++ src/RevitKrChecker/Models/Rule/ICheckRule.cs | 8 ++ .../Models/Rule/StartWithCheckRule.cs | 14 +++ src/RevitKrChecker/RevitKrCheckerCommand.cs | 4 +- src/RevitKrChecker/ViewModels/MainVM.cs | 54 ++++++++ .../ViewModels/MainViewModel.cs | 76 ------------ src/RevitKrChecker/ViewModels/ReportItemVM.cs | 23 ++++ src/RevitKrChecker/ViewModels/ReportVM.cs | 65 ++++++++++ src/RevitKrChecker/Views/MainWindow.xaml | 69 +++-------- src/RevitKrChecker/Views/ReportWindow.xaml | 117 ++++++++++++++++++ src/RevitKrChecker/Views/ReportWindow.xaml.cs | 111 +++++++++++++++++ 19 files changed, 728 insertions(+), 128 deletions(-) create mode 100644 src/RevitKrChecker/Models/Check/CompareParamsCheck.cs create mode 100644 src/RevitKrChecker/Models/Check/HasValueCheck.cs create mode 100644 src/RevitKrChecker/Models/Check/ICheck.cs create mode 100644 src/RevitKrChecker/Models/Check/ParamCheck.cs create mode 100644 src/RevitKrChecker/Models/Check/TemplatesCompareParamsCheck.cs create mode 100644 src/RevitKrChecker/Models/CheckInfo.cs create mode 100644 src/RevitKrChecker/Models/Rule/ContainsCheckRule.cs create mode 100644 src/RevitKrChecker/Models/Rule/EqualCheckRule.cs create mode 100644 src/RevitKrChecker/Models/Rule/ICheckRule.cs create mode 100644 src/RevitKrChecker/Models/Rule/StartWithCheckRule.cs create mode 100644 src/RevitKrChecker/ViewModels/MainVM.cs delete mode 100644 src/RevitKrChecker/ViewModels/MainViewModel.cs create mode 100644 src/RevitKrChecker/ViewModels/ReportItemVM.cs create mode 100644 src/RevitKrChecker/ViewModels/ReportVM.cs create mode 100644 src/RevitKrChecker/Views/ReportWindow.xaml create mode 100644 src/RevitKrChecker/Views/ReportWindow.xaml.cs diff --git a/src/RevitKrChecker/Models/Check/CompareParamsCheck.cs b/src/RevitKrChecker/Models/Check/CompareParamsCheck.cs new file mode 100644 index 000000000..538c4b56f --- /dev/null +++ b/src/RevitKrChecker/Models/Check/CompareParamsCheck.cs @@ -0,0 +1,41 @@ +using Autodesk.Revit.DB; + +using dosymep.Revit; + +using RevitKrChecker.Models.Rule; + +namespace RevitKrChecker.Models.Check { + public class CompareParamsCheck : ICheck { + public CompareParamsCheck(string checkName, + string targetParamName, + ICheckRule checkRule, + string sourceParamName) { + CheckName = checkName; + TargetParamName = targetParamName; + CheckRule = checkRule; + SourceParamName = sourceParamName; + } + + public string CheckName { get; } + public string TargetParamName { get; } + public ICheckRule CheckRule { get; } + private string SourceParamName { get; } + + public bool Check(Element element, out CheckInfo info) { + string targetParamValue = element.GetParamValue(TargetParamName); + string sourceParamValue = element.GetParamValue(SourceParamName); + + if(CheckRule.Check(targetParamValue, sourceParamValue)) { + info = null; + return true; + } + + info = new CheckInfo(CheckName, TargetParamName, element, GetTooltip()); + return false; + } + + public string GetTooltip() { + return $"{CheckName}: значение параметра \"{TargetParamName}\" {CheckRule.UnfulfilledRule} \"{SourceParamName}\""; + } + } +} diff --git a/src/RevitKrChecker/Models/Check/HasValueCheck.cs b/src/RevitKrChecker/Models/Check/HasValueCheck.cs new file mode 100644 index 000000000..379748314 --- /dev/null +++ b/src/RevitKrChecker/Models/Check/HasValueCheck.cs @@ -0,0 +1,32 @@ +using Autodesk.Revit.DB; + +using dosymep.Revit; + +namespace RevitKrChecker.Models.Check { + public class HasValueCheck : ICheck { + public HasValueCheck(string checkName, + string targetParamName) { + CheckName = checkName; + TargetParamName = targetParamName; + } + + public string CheckName { get; } + public string TargetParamName { get; } + + public bool Check(Element element, out CheckInfo info) { + string targetParamValue = element.GetParamValue(TargetParamName); + + if(string.IsNullOrEmpty(targetParamValue)) { + info = null; + return true; + } + + info = new CheckInfo(CheckName, TargetParamName, element, GetTooltip()); + return false; + } + + public string GetTooltip() { + return $"{CheckName}: значение параметра \"{TargetParamName}\" отсутствует"; + } + } +} diff --git a/src/RevitKrChecker/Models/Check/ICheck.cs b/src/RevitKrChecker/Models/Check/ICheck.cs new file mode 100644 index 000000000..4bc269452 --- /dev/null +++ b/src/RevitKrChecker/Models/Check/ICheck.cs @@ -0,0 +1,11 @@ +using Autodesk.Revit.DB; + +namespace RevitKrChecker.Models.Check { + public interface ICheck { + string CheckName { get; } + string TargetParamName { get; } + + string GetTooltip(); + bool Check(Element element, out CheckInfo info); + } +} diff --git a/src/RevitKrChecker/Models/Check/ParamCheck.cs b/src/RevitKrChecker/Models/Check/ParamCheck.cs new file mode 100644 index 000000000..88d4511b3 --- /dev/null +++ b/src/RevitKrChecker/Models/Check/ParamCheck.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; + +using Autodesk.Revit.DB; + +using dosymep.Revit; + +using RevitKrChecker.Models.Rule; + +namespace RevitKrChecker.Models.Check { + public class ParamCheck : ICheck { + + public ParamCheck(string checkName, + string targetParamName, + ICheckRule checkRule, + List trueValues) { + CheckName = checkName; + TargetParamName = targetParamName; + CheckRule = checkRule; + TrueValues = trueValues; + } + + public string CheckName { get; } + public string TargetParamName { get; } + public ICheckRule CheckRule { get; } + public List TrueValues { get; } + + + public bool Check(Element element, out CheckInfo info) { + string targetParamValue = element.GetParamValue(TargetParamName); + + if(TrueValues is null) { + throw new ArgumentNullException("The correct values were not passed."); + } + + foreach(var trueValue in TrueValues) { + if(CheckRule.Check(targetParamValue, trueValue)) { + info = null; + return true; + } + } + + info = new CheckInfo(CheckName, TargetParamName, element, GetTooltip()); + return false; + } + + public string GetTooltip() { + return $"{CheckName}: значение параметра \"{TargetParamName}\" {CheckRule.UnfulfilledRule} {GetTrueValuesAsStr()}"; + } + + private string GetTrueValuesAsStr() { + string answer = string.Empty; + string separator = ", "; + + foreach(string trueValue in TrueValues) { + answer += $"{trueValue}{separator}"; + } + answer = answer.Substring(0, answer.LastIndexOf(separator)); + return answer; + } + } +} diff --git a/src/RevitKrChecker/Models/Check/TemplatesCompareParamsCheck.cs b/src/RevitKrChecker/Models/Check/TemplatesCompareParamsCheck.cs new file mode 100644 index 000000000..5bb7d76f7 --- /dev/null +++ b/src/RevitKrChecker/Models/Check/TemplatesCompareParamsCheck.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; + +using Autodesk.Revit.DB; + +using dosymep.Revit; + +using RevitKrChecker.Models.Rule; + +namespace RevitKrChecker.Models.Check { + public class TemplatesCompareParamsCheck : ICheck { + + public TemplatesCompareParamsCheck(string checkName, + string targetParamName, + ICheckRule checkRule, + string sourceParamName, + Dictionary dictForCompare) { + CheckName = checkName; + TargetParamName = targetParamName; + CheckRule = checkRule; + SourceParamName = sourceParamName; + DictForCompare = dictForCompare; + } + + public string CheckName { get; } + public string TargetParamName { get; } + public ICheckRule CheckRule { get; } + private string SourceParamName { get; } + private Dictionary DictForCompare { get; } + + + public bool Check(Element element, out CheckInfo info) { + string targetParamValue = element.GetParamValue(TargetParamName); + string sourceParamValue = DictForCompare[element.GetParamValue(SourceParamName)]; + + if(CheckRule.Check(targetParamValue, sourceParamValue)) { + info = null; + return true; + } + + info = new CheckInfo(CheckName, TargetParamName, element, GetTooltip()); + return false; + } + + public string GetTooltip() { + return $"{CheckName}: значение параметра \"{TargetParamName}\" {CheckRule.UnfulfilledRule}" + + $" \"{SourceParamName}\" по правилу: {GetDictForCompareAsStr()}"; + } + + private string GetDictForCompareAsStr() { + string answer = string.Empty; + string separator = ", "; + + foreach(string dictKey in DictForCompare.Keys) { + answer += $"{dictKey}: {DictForCompare[dictKey]}{separator}"; + } + answer = answer.Substring(0, answer.LastIndexOf(separator)); + return answer; + } + } +} diff --git a/src/RevitKrChecker/Models/CheckInfo.cs b/src/RevitKrChecker/Models/CheckInfo.cs new file mode 100644 index 000000000..a7dbf97d8 --- /dev/null +++ b/src/RevitKrChecker/Models/CheckInfo.cs @@ -0,0 +1,18 @@ +using Autodesk.Revit.DB; + +namespace RevitKrChecker.Models { + public class CheckInfo { + + public CheckInfo(string checkName, string targetParamName, Element element, string tooltip) { + Elem = element; + TargetParamName = targetParamName; + СheckName = checkName; + ElementErrorTooltip = tooltip; + } + + public Element Elem { get; } + public string TargetParamName { get; } + public string СheckName { get; } + public string ElementErrorTooltip { get; } + } +} diff --git a/src/RevitKrChecker/Models/RevitRepository.cs b/src/RevitKrChecker/Models/RevitRepository.cs index 59202f797..a3bfa979a 100644 --- a/src/RevitKrChecker/Models/RevitRepository.cs +++ b/src/RevitKrChecker/Models/RevitRepository.cs @@ -1,9 +1,29 @@ +using System.Collections.Generic; +using System.Linq; + using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.DB; using Autodesk.Revit.UI; +using RevitKrChecker.Models.Check; +using RevitKrChecker.Models.Rule; + namespace RevitKrChecker.Models { internal class RevitRepository { + + private readonly List _categoriesForWork = new List() { + BuiltInCategory.OST_Walls, + BuiltInCategory.OST_Floors, + BuiltInCategory.OST_StructuralFoundation, + BuiltInCategory.OST_GenericModel, + BuiltInCategory.OST_StructuralFraming, + BuiltInCategory.OST_StructuralColumns, + BuiltInCategory.OST_Stairs, + BuiltInCategory.OST_StructConnections, + BuiltInCategory.OST_Roofs + }; + + public RevitRepository(UIApplication uiApplication) { UIApplication = uiApplication; } @@ -12,5 +32,48 @@ public RevitRepository(UIApplication uiApplication) { public UIDocument ActiveUIDocument => UIApplication.ActiveUIDocument; public Application Application => UIApplication.Application; public Document Document => ActiveUIDocument.Document; + + public List GetViewElements() { + var filter = new ElementMulticategoryFilter(_categoriesForWork); + return new FilteredElementCollector(Document, Document.ActiveView.Id) + .WherePasses(filter) + .WhereElementIsNotElementType() + .ToElements() + .ToList(); + } + + public List GetPjElements() { + var filter = new ElementMulticategoryFilter(_categoriesForWork); + return new FilteredElementCollector(Document) + .WherePasses(filter) + .WhereElementIsNotElementType() + .ToElements() + .ToList(); + } + + public List StoppingChecks() { + List stoppingChecks = new List(); + + //Параметр "ФОП_Блок СМР" должен содержать "Корпус", "Автостоянка", "Пристройка" + List trueValues = new List() { + "Корпус", + "Автостоянка", + "Пристройка" + }; + var FOP_BlockSMR_Check = new ParamCheck("ФОП_Блок СМР", "ФОП_Блок СМР", new ContainsCheckRule(), trueValues); + + stoppingChecks.Add(FOP_BlockSMR_Check); + return stoppingChecks; + } + + public List NonStoppingChecks() { + List nonStoppingChecks = new List(); + + //Параметр "Секция СМР" должен быть заполнен + var FOP_SekciaSMR_Check = new HasValueCheck("ФОП_Секция СМР", "ФОП_Секция СМР"); + + nonStoppingChecks.Add(FOP_SekciaSMR_Check); + return nonStoppingChecks; + } } } diff --git a/src/RevitKrChecker/Models/Rule/ContainsCheckRule.cs b/src/RevitKrChecker/Models/Rule/ContainsCheckRule.cs new file mode 100644 index 000000000..716452dea --- /dev/null +++ b/src/RevitKrChecker/Models/Rule/ContainsCheckRule.cs @@ -0,0 +1,14 @@ +namespace RevitKrChecker.Models.Rule { + public class ContainsCheckRule : ICheckRule { + + public ContainsCheckRule() { + CheckRuleName = "Содержит"; + UnfulfilledRule = "не содержит"; + } + + public string CheckRuleName { get; } + public string UnfulfilledRule { get; } + + public bool Check(string str1, string str2) => str1.Contains(str2); + } +} diff --git a/src/RevitKrChecker/Models/Rule/EqualCheckRule.cs b/src/RevitKrChecker/Models/Rule/EqualCheckRule.cs new file mode 100644 index 000000000..4832f74ce --- /dev/null +++ b/src/RevitKrChecker/Models/Rule/EqualCheckRule.cs @@ -0,0 +1,14 @@ +namespace RevitKrChecker.Models.Rule { + public class EqualCheckRule : ICheckRule { + + public EqualCheckRule() { + CheckRuleName = "Равно"; + UnfulfilledRule = "не равно"; + } + + public string CheckRuleName { get; } + public string UnfulfilledRule { get; } + + public bool Check(string str1, string str2) => str1.Equals(str2); + } +} diff --git a/src/RevitKrChecker/Models/Rule/ICheckRule.cs b/src/RevitKrChecker/Models/Rule/ICheckRule.cs new file mode 100644 index 000000000..a77f25f29 --- /dev/null +++ b/src/RevitKrChecker/Models/Rule/ICheckRule.cs @@ -0,0 +1,8 @@ +namespace RevitKrChecker.Models.Rule { + public interface ICheckRule { + string CheckRuleName { get; } + string UnfulfilledRule { get; } + + bool Check(string value1, string value2); + } +} diff --git a/src/RevitKrChecker/Models/Rule/StartWithCheckRule.cs b/src/RevitKrChecker/Models/Rule/StartWithCheckRule.cs new file mode 100644 index 000000000..68f8f75c4 --- /dev/null +++ b/src/RevitKrChecker/Models/Rule/StartWithCheckRule.cs @@ -0,0 +1,14 @@ +namespace RevitKrChecker.Models.Rule { + public class StartWithCheckRule : ICheckRule { + + public StartWithCheckRule() { + CheckRuleName = "Начинается с"; + UnfulfilledRule = "не начинается"; + } + + public string CheckRuleName { get; } + public string UnfulfilledRule { get; } + + public bool Check(string str1, string str2) => str1.StartsWith(str2); + } +} diff --git a/src/RevitKrChecker/RevitKrCheckerCommand.cs b/src/RevitKrChecker/RevitKrCheckerCommand.cs index d512c05e0..af4d8e710 100644 --- a/src/RevitKrChecker/RevitKrCheckerCommand.cs +++ b/src/RevitKrChecker/RevitKrCheckerCommand.cs @@ -34,10 +34,10 @@ protected override void Execute(UIApplication uiApplication) { kernel.Bind() .ToMethod(c => PluginConfig.GetPluginConfig()); - kernel.Bind().ToSelf(); + kernel.Bind().ToSelf(); kernel.Bind().ToSelf() .WithPropertyValue(nameof(Window.DataContext), - c => c.Kernel.Get()) + c => c.Kernel.Get()) .WithPropertyValue(nameof(PlatformWindow.LocalizationService), c => c.Kernel.Get()); diff --git a/src/RevitKrChecker/ViewModels/MainVM.cs b/src/RevitKrChecker/ViewModels/MainVM.cs new file mode 100644 index 000000000..6ba5eec4f --- /dev/null +++ b/src/RevitKrChecker/ViewModels/MainVM.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using System.Windows.Input; + +using Autodesk.Revit.DB; + +using dosymep.SimpleServices; +using dosymep.WPF.Commands; +using dosymep.WPF.ViewModels; + +using RevitKrChecker.Models; +using RevitKrChecker.Views; + +namespace RevitKrChecker.ViewModels { + internal class MainVM : BaseViewModel { + private readonly PluginConfig _pluginConfig; + private readonly RevitRepository _revitRepository; + private readonly ILocalizationService _localizationService; + + public MainVM( + PluginConfig pluginConfig, + RevitRepository revitRepository, + ILocalizationService localizationService) { + + _pluginConfig = pluginConfig; + _revitRepository = revitRepository; + _localizationService = localizationService; + + + CheckElemsFromViewCommand = RelayCommand.Create(CheckElemsFromView); + CheckElemsFromPjCommand = RelayCommand.Create(CheckElemsFromPj); + } + + + public ICommand CheckElemsFromViewCommand { get; } + public ICommand CheckElemsFromPjCommand { get; } + + private void CheckElemsFromView() { + List elements = _revitRepository.GetViewElements(); + GetReportVM(elements); + } + + private void CheckElemsFromPj() { + List elements = _revitRepository.GetPjElements(); + GetReportVM(elements); + } + + private void GetReportVM(List elements) { + ReportVM reportVM = new ReportVM(elements, _revitRepository.StoppingChecks(), _revitRepository.NonStoppingChecks()); + ReportWindow reportWindow = new ReportWindow(); + reportWindow.DataContext = reportVM; + reportWindow.Show(); + } + } +} diff --git a/src/RevitKrChecker/ViewModels/MainViewModel.cs b/src/RevitKrChecker/ViewModels/MainViewModel.cs deleted file mode 100644 index 2389ef891..000000000 --- a/src/RevitKrChecker/ViewModels/MainViewModel.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System.Windows.Input; - -using dosymep.SimpleServices; -using dosymep.WPF.Commands; -using dosymep.WPF.ViewModels; - -using RevitKrChecker.Models; - -namespace RevitKrChecker.ViewModels { - internal class MainViewModel : BaseViewModel { - private readonly PluginConfig _pluginConfig; - private readonly RevitRepository _revitRepository; - private readonly ILocalizationService _localizationService; - - private string _errorText; - private string _saveProperty; - - public MainViewModel( - PluginConfig pluginConfig, - RevitRepository revitRepository, - ILocalizationService localizationService) { - - _pluginConfig = pluginConfig; - _revitRepository = revitRepository; - _localizationService = localizationService; - - LoadViewCommand = RelayCommand.Create(LoadView); - AcceptViewCommand = RelayCommand.Create(AcceptView, CanAcceptView); - } - - public ICommand LoadViewCommand { get; } - public ICommand AcceptViewCommand { get; } - - public string ErrorText { - get => _errorText; - set => this.RaiseAndSetIfChanged(ref _errorText, value); - } - - public string SaveProperty { - get => _saveProperty; - set => this.RaiseAndSetIfChanged(ref _saveProperty, value); - } - - private void LoadView() { - LoadConfig(); - } - - private void AcceptView() { - SaveConfig(); - } - - private bool CanAcceptView() { - if(string.IsNullOrEmpty(SaveProperty)) { - ErrorText = _localizationService.GetLocalizedString("MainWindow.HelloCheck"); - return false; - } - - ErrorText = null; - return true; - } - - private void LoadConfig() { - RevitSettings setting = _pluginConfig.GetSettings(_revitRepository.Document); - - SaveProperty = setting?.SaveProperty ?? _localizationService.GetLocalizedString("MainWindow.Hello"); - } - - private void SaveConfig() { - RevitSettings setting = _pluginConfig.GetSettings(_revitRepository.Document) - ?? _pluginConfig.AddSettings(_revitRepository.Document); - - setting.SaveProperty = SaveProperty; - _pluginConfig.SaveProjectConfig(); - } - } -} diff --git a/src/RevitKrChecker/ViewModels/ReportItemVM.cs b/src/RevitKrChecker/ViewModels/ReportItemVM.cs new file mode 100644 index 000000000..1c5f3569f --- /dev/null +++ b/src/RevitKrChecker/ViewModels/ReportItemVM.cs @@ -0,0 +1,23 @@ +// Ignore Spelling: Tooltip Сheck + +using Autodesk.Revit.DB; + +using dosymep.WPF.ViewModels; + +using RevitKrChecker.Models; + +namespace RevitKrChecker.ViewModels { + internal class ReportItemVM : BaseViewModel { + public ReportItemVM(CheckInfo checkInfo) { + Elem = checkInfo.Elem; + TargetParamName = checkInfo.TargetParamName; + СheckName = checkInfo.СheckName; + ElementErrorTooltip = checkInfo.ElementErrorTooltip; + } + + public Element Elem { get; } + public string TargetParamName { get; } + public string СheckName { get; } + public string ElementErrorTooltip { get; } + } +} diff --git a/src/RevitKrChecker/ViewModels/ReportVM.cs b/src/RevitKrChecker/ViewModels/ReportVM.cs new file mode 100644 index 000000000..d2d3999f7 --- /dev/null +++ b/src/RevitKrChecker/ViewModels/ReportVM.cs @@ -0,0 +1,65 @@ +using System.Collections.Generic; +using System.Windows.Input; + +using Autodesk.Revit.DB; + +using dosymep.WPF.Commands; +using dosymep.WPF.ViewModels; + +using RevitKrChecker.Models; +using RevitKrChecker.Models.Check; + +namespace RevitKrChecker.ViewModels { + internal class ReportVM : BaseViewModel { + private List _reportResult; + + public ReportVM(List elements, List stoppingChecks, List nonStoppingChecks) { + Elems = elements; + StoppingChecks = stoppingChecks; + NonStoppingChecks = nonStoppingChecks; + + ReсheckCommand = RelayCommand.Create(Reсheck); + Reсheck(); + } + + public ICommand ReсheckCommand { get; } + + public List Elems { get; set; } + public List StoppingChecks { get; set; } + public List NonStoppingChecks { get; set; } + + + public List ReportResult { + get => _reportResult; + set => this.RaiseAndSetIfChanged(ref _reportResult, value); + } + + private void Reсheck() { + ReportResult = new List(); + + /* Существует два типа проверок: + 1. Проверки, которые не допускают элемент к другим проверкам в случае ошибки + _stoppingChecks = List(); + 2. Проверки, которые допускают элемент к другим проверкам в случае ошибки + _nonStoppingChecks = List();*/ + + for(int i = Elems.Count - 1; i >= 0; i--) { + foreach(ICheck check in StoppingChecks) { + if(!check.Check(Elems[i], out CheckInfo info)) { + ReportResult.Add(new ReportItemVM(info)); + Elems.Remove(Elems[i]); + break; + } + } + } + + foreach(Element element in Elems) { + foreach(ICheck check in NonStoppingChecks) { + if(!check.Check(element, out CheckInfo info)) { + ReportResult.Add(new ReportItemVM(info)); + } + } + } + } + } +} diff --git a/src/RevitKrChecker/Views/MainWindow.xaml b/src/RevitKrChecker/Views/MainWindow.xaml index f3533efb3..22d5b09ab 100644 --- a/src/RevitKrChecker/Views/MainWindow.xaml +++ b/src/RevitKrChecker/Views/MainWindow.xaml @@ -13,59 +13,28 @@ mc:Ignorable="d" WindowStartupLocation="CenterOwner" Title="{DynamicResource MainWindow.Title}" - Height="450" - Width="800" - d:DataContext="{d:DesignInstance vms:MainViewModel, IsDesignTimeCreatable=False}"> - - - - - - + Height="100" + Width="500" + d:DataContext="{d:DesignInstance vms:MainVM, IsDesignTimeCreatable=False}"> - - - - - - - - - + + + + -