Skip to content

Commit

Permalink
Создал плагин отображающий название помещений на виде
Browse files Browse the repository at this point in the history
  • Loading branch information
KGubin committed Oct 24, 2024
1 parent f6ef585 commit 980ae32
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 55 deletions.
9 changes: 4 additions & 5 deletions src/RevitPlugins/Models/PluginConfig.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using dosymep.Bim4Everyone;
using dosymep.Bim4Everyone;
using dosymep.Bim4Everyone.ProjectConfigs;
using dosymep.Serializers;

using pyRevitLabs.Json;

namespace RevitPlugins.Models
{
namespace RevitPlugins.Models {
public class PluginConfig : ProjectConfig<RevitSettings> {
[JsonIgnore] public override string ProjectConfigPath { get; set; }

Expand All @@ -20,9 +19,9 @@ public static PluginConfig GetPluginConfig() {
.Build<PluginConfig>();
}
}

public class RevitSettings : ProjectSettings {
public string SaveProperty { get; set; }
public override string ProjectName { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion src/RevitRoomViewer/Localization/Language.ru-RU.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<system:String x:Key="MainWindow.Title">Пример команды</system:String>
<system:String x:Key="MainWindow.Hello">Привет Revit!</system:String>
<system:String x:Key="MainWindow.HelloCheck">Введите значение сохраняемого свойства.</system:String>

<system:String x:Key="MainWindow.Description">Введите описание.</system:String>
<system:String x:Key="MainWindow.ButtonOk">ОК</system:String>
<system:String x:Key="MainWindow.ButtonCancel">Отмена</system:String>
</ResourceDictionary>
4 changes: 3 additions & 1 deletion src/RevitRoomViewer/Models/PluginConfig.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;

using dosymep.Bim4Everyone;
using dosymep.Bim4Everyone.ProjectConfigs;
using dosymep.Serializers;
Expand All @@ -22,6 +24,6 @@ public static PluginConfig GetPluginConfig() {

internal class RevitSettings : ProjectSettings {
public override string ProjectName { get; set; }
public string SaveProperty { get; set; }
public Dictionary<string, RoomSettings> RoomsWithSettings { get; set; }
}
}
12 changes: 12 additions & 0 deletions src/RevitRoomViewer/Models/RevitRepository.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System.Collections.Generic;
using System.Linq;

using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
Expand All @@ -13,5 +16,14 @@ public RevitRepository(UIApplication uiApplication) {

public Application Application => UIApplication.Application;
public Document Document => ActiveUIDocument.Document;


public List<Element> GetAllRoomName() {
return new FilteredElementCollector(Document)
.OfCategory(BuiltInCategory.OST_Rooms)
.WhereElementIsNotElementType()
.ToList();
}

}
}
8 changes: 8 additions & 0 deletions src/RevitRoomViewer/Models/RoomSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace RevitRoomViewer.Models {
internal class RoomSettings {
public string RoomName { get; set; }
public string Description { get; set; }
public bool NeedMeasuring { get; set; }

}
}
2 changes: 1 addition & 1 deletion src/RevitRoomViewer/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RevitRoomViewer (Просмотр помещения)
Описание проекта
Отображения названий помещений на уровне

# Сборка проекта
```
Expand Down
4 changes: 2 additions & 2 deletions src/RevitRoomViewer/RevitRoomViewer.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<UseDevExpress>true</UseDevExpress>
<UseDevExpress>false</UseDevExpress>
</PropertyGroup>
</Project>
102 changes: 80 additions & 22 deletions src/RevitRoomViewer/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;

using dosymep.SimpleServices;
Expand All @@ -12,65 +14,121 @@ internal class MainViewModel : BaseViewModel {
private readonly RevitRepository _revitRepository;
private readonly ILocalizationService _localizationService;

private string _errorText;
private string _saveProperty;
private string _descriptionText;
private string _roomDescription;
private bool _needMeasuring;
private string _revitVersion;

public Dictionary<string, RoomSettings> RoomsWithSettings { get; set; } = new Dictionary<string, RoomSettings>();

public MainViewModel(
PluginConfig pluginConfig,
RevitRepository revitRepository,
PluginConfig pluginConfig,
RevitRepository revitRepository,
ILocalizationService localizationService) {

_pluginConfig = pluginConfig;
_revitRepository = revitRepository;
_localizationService = localizationService;

#if REVIT_2023_OR_LESS
RevitVersion = "Revit 2023";
#else
RevitVersion = "Revit 2024";
#endif


LoadViewCommand = RelayCommand.Create(LoadView);
AcceptViewCommand = RelayCommand.Create(AcceptView, CanAcceptView);
AcceptViewCommand = RelayCommand.Create(AcceptView);
}

public ICommand LoadViewCommand { get; }
public ICommand AcceptViewCommand { get; }

public string ErrorText {
get => _errorText;
set => this.RaiseAndSetIfChanged(ref _errorText, value);

public string RevitVersion {
get => _revitVersion;
set => this.RaiseAndSetIfChanged(ref _revitVersion, value);
}
public string DescriptionText {
get => _descriptionText;
set => this.RaiseAndSetIfChanged(ref _descriptionText, value);
}


public string SaveProperty {
get => _saveProperty;
set => this.RaiseAndSetIfChanged(ref _saveProperty, value);
public string RoomDescription {
get => _roomDescription;
set => this.RaiseAndSetIfChanged(ref _roomDescription, value);
}

public bool NeedMeasuring {
get => _needMeasuring;
set => this.RaiseAndSetIfChanged(ref _needMeasuring, value);
}

private List<RoomSettings> _allRooms;
public List<RoomSettings> AllRooms {
get => _allRooms;
set => this.RaiseAndSetIfChanged(ref _allRooms, value);
}


private void LoadView() {

LoadConfig();
LoadRooms();
}

private void AcceptView() {
UpdateRoomSettings();
SaveConfig();
}

private bool CanAcceptView() {
if(string.IsNullOrEmpty(SaveProperty)) {
ErrorText = _localizationService.GetLocalizedString("MainWindow.HelloCheck");
return false;
}

ErrorText = null;
return true;
private void LoadRooms() {

AllRooms = _revitRepository.GetAllRoomName()
.Select(e => new RoomSettings {
RoomName = e.Name,
Description = RoomsWithSettings.ContainsKey(e.Name)
? RoomsWithSettings[e.Name].Description
: "",
NeedMeasuring = RoomsWithSettings.ContainsKey(e.Name)
? RoomsWithSettings[e.Name].NeedMeasuring
: false
}).ToList();
}

private void UpdateRoomSettings() {
foreach(var room in AllRooms) {
if(RoomsWithSettings.ContainsKey(room.RoomName)) {
RoomsWithSettings[room.RoomName].Description = room.Description;
RoomsWithSettings[room.RoomName].NeedMeasuring = room.NeedMeasuring;
} else {
RoomsWithSettings[room.RoomName] = new RoomSettings {
RoomName = room.RoomName,
Description = room.Description,
NeedMeasuring = room.NeedMeasuring
};
}
}
}

private void LoadConfig() {
RevitSettings setting = _pluginConfig.GetSettings(_revitRepository.Document);

SaveProperty = setting?.SaveProperty ?? _localizationService.GetLocalizedString("MainWindow.Hello");
if(setting != null && setting.RoomsWithSettings != null) {
RoomsWithSettings = setting.RoomsWithSettings;
} else {
RoomsWithSettings = new Dictionary<string, RoomSettings>();
}
}

private void SaveConfig() {
RevitSettings setting = _pluginConfig.GetSettings(_revitRepository.Document)
?? _pluginConfig.AddSettings(_revitRepository.Document);

setting.SaveProperty = SaveProperty;
setting.RoomsWithSettings = RoomsWithSettings;
_pluginConfig.SaveProjectConfig();
}
}
}

78 changes: 55 additions & 23 deletions src/RevitRoomViewer/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<base:ThemedPlatformWindow
<base:PlatformWindow
x:Class="RevitRoomViewer.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand All @@ -8,10 +8,7 @@
xmlns:base="clr-namespace:dosymep.WPF.Views"
xmlns:local="clr-namespace:RevitRoomViewer.Views"
xmlns:vms="clr-namespace:RevitRoomViewer.ViewModels"

xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"

mc:Ignorable="d"
WindowStartupLocation="CenterOwner"
Expand All @@ -20,51 +17,86 @@
Height="450" Width="800"

d:DataContext="{d:DesignInstance vms:MainViewModel, IsDesignTimeCreatable=False}">

<dxmvvm:Interaction.Behaviors>
<dxmvvm:EventToCommand EventName="Loaded" Command="{Binding LoadViewCommand}"/>
</dxmvvm:Interaction.Behaviors>

<b:Interaction.Triggers>
<b:EventTrigger EventName="Loaded">
<b:InvokeCommandAction
Command="{Binding LoadViewCommand}" />
</b:EventTrigger>
</b:Interaction.Triggers>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<dxe:TextEdit
Grid.Row="0"
Width="200"
VerticalAlignment="Center"
HorizontalAlignment="Center"

Text="{Binding SaveProperty,
UpdateSourceTrigger=PropertyChanged}" />
<DataGrid x:Name="AllRoomsDataGrid"
ItemsSource="{Binding AllRooms}"
AutoGenerateColumns="False"
SelectionMode="Single"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">

<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGrid.ColumnHeaderStyle>

<DataGrid.Columns>
<DataGridTextColumn
Header="Имя"
Binding="{Binding RoomName}"
IsReadOnly="True"/>


<DataGridTemplateColumn Header="Описание">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

<DataGridCheckBoxColumn Header="Нужен замер"
Binding="{Binding NeedMeasuring, Mode=TwoWay}" />
</DataGrid.Columns>
</DataGrid>


<StackPanel
Grid.Row="1"
Height="45"
Orientation="Horizontal"
HorizontalAlignment="Right">

<TextBlock
Margin="10"
Foreground="Orange"
Foreground="Black"
VerticalAlignment="Center"
Text="{Binding ErrorText}" />

<dx:SimpleButton
Text="{DynamicResource MainWindow.Description}" />

<TextBlock
Margin="30,0,0,0"
Foreground="Black"
VerticalAlignment="Center"
Text="{Binding RevitVersion}" />

<Button
Margin="10"
Width="80"
Content="{DynamicResource MainWindow.ButtonOk}"
IsDefault="True"
Click="ButtonOk_Click"
Command="{Binding AcceptViewCommand}" />

<dx:SimpleButton
<Button
Margin="10"
Width="80"
Content="{DynamicResource MainWindow.ButtonCancel}"
IsCancel="True"
Click="ButtonCancel_Click" />
</StackPanel>
</Grid>
</base:ThemedPlatformWindow>
</base:PlatformWindow>

0 comments on commit 980ae32

Please sign in to comment.