Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Полное обновление: Преобразование в выпадающий список #103

Merged
merged 7 commits into from
Oct 23, 2024
39 changes: 31 additions & 8 deletions src/RevitMechanicalSpecification/Models/RevitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class RevitRepository {
private readonly List<ElementParamFiller> _fillersSystemRefresh;
private readonly List<ElementParamFiller> _fillersFunctionRefresh;
private readonly CollectionFactory _collector;
private readonly List<Element> _elements;
private List<Element> _elements;
private readonly List<VisSystem> _visSystems;
private readonly SpecConfiguration _specConfiguration;
private readonly VisElementsCalculator _calculator;
Expand All @@ -37,11 +37,10 @@ public RevitRepository(UIApplication uiApplication) {
UIApplication = uiApplication;
_elementProcessor = new ElementProcessor(UIApplication.Application.Username, Document);
_specConfiguration = new SpecConfiguration(Document.ProjectInformation);
_collector = new CollectionFactory(Document, _specConfiguration);
_collector = new CollectionFactory(Document, _specConfiguration, ActiveUIDocument);
_calculator = new VisElementsCalculator(_specConfiguration, Document);
_maskReplacer = new MaskReplacer(_specConfiguration);

_elements = _collector.GetElementsToSpecificate();
_visSystems = _collector.GetVisSystems();

_fillersSpecRefresh = new List<ElementParamFiller>()
Expand Down Expand Up @@ -126,32 +125,48 @@ public RevitRepository(UIApplication uiApplication) {
/// Обновление только по филлерам спецификации
/// </summary>
public void SpecificationRefresh() {
_elements = _collector.GetElementsByCategories();
_elementProcessor.ProcessElements(_fillersSpecRefresh, _elements);
}

/// <summary>
/// Обновление только по филлерам системы
/// </summary>
public void RefreshSystemName() {
_elements = _collector.GetElementsByCategories();
_elementProcessor.ProcessElements(_fillersSystemRefresh, _elements);
}

/// <summary>
/// Обновление только по филлерам функции
/// </summary>
public void RefreshSystemFunction() {
_elements = _collector.GetElementsByCategories();
_elementProcessor.ProcessElements(_fillersFunctionRefresh, _elements);
}

/// <summary>
/// Здесь нужно провести полное обновление всех параметров, поэтому будут сложены все филлеры в один лист
/// </summary>
public void FullRefresh() {
List<ElementParamFiller> fillers = new List<ElementParamFiller>();
fillers.AddRange(_fillersSpecRefresh);
fillers.AddRange(_fillersFunctionRefresh);
fillers.AddRange(_fillersSystemRefresh);
_elementProcessor.ProcessElements(fillers, _elements);
_elements = _collector.GetElementsByCategories();
_elementProcessor.ProcessElements(FoldFillerLists(), _elements);
}

/// <summary>
/// Здесь нужно провести полное обновление видимых элементов и всех параметров, поэтому будут сложены все филлеры в один лист
/// </summary>
public void VisibleFullRefresh() {
_elements = _collector.GetVisibleElementsByCategories();
_elementProcessor.ProcessElements(FoldFillerLists(), _elements);
}

/// <summary>
/// Здесь нужно провести полное обновление выбранных элементов и всех параметров, поэтому будут сложены все филлеры в один лист
/// </summary>
public void SelectedFullRefresh() {
_elements = _collector.GetSelectedElementsByCategories();
_elementProcessor.ProcessElements(FoldFillerLists(), _elements);
}

/// <summary>
Expand All @@ -167,5 +182,13 @@ public void ReplaceMask() {
}
}

private List<ElementParamFiller> FoldFillerLists() {
List<ElementParamFiller> fillers = new List<ElementParamFiller>();
fillers.AddRange(_fillersSpecRefresh);
fillers.AddRange(_fillersFunctionRefresh);
fillers.AddRange(_fillersSystemRefresh);
return fillers;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace RevitMechanicalSpecification {
[Transaction(TransactionMode.Manual)]
public class RevitMechanicalCreateNameCmd : BasePluginCommand {
public RevitMechanicalCreateNameCmd() {
PluginName = "RevitMechanicalSpecification";
PluginName = "Сформировать имя";
}

protected override void Execute(UIApplication uiApplication) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace RevitMechanicalSpecification {
[Transaction(TransactionMode.Manual)]
public class RevitMechanicalFullRefreshCmd : BasePluginCommand {
public RevitMechanicalFullRefreshCmd() {
PluginName = "RevitMechanicalSpecification";
PluginName = "Полное обновление";
}

protected override void Execute(UIApplication uiApplication) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace RevitMechanicalSpecification {
[Transaction(TransactionMode.Manual)]
public class RevitMechanicalFunctionRefreshCmd : BasePluginCommand {
public RevitMechanicalFunctionRefreshCmd() {
PluginName = "RevitMechanicalSpecification";
PluginName = "Обновление функции";
}

protected override void Execute(UIApplication uiApplication) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 RevitMechanicalSpecification.Models;
using RevitMechanicalSpecification.ViewModels;
using RevitMechanicalSpecification.Views;

namespace RevitMechanicalSpecification {
[Transaction(TransactionMode.Manual)]
public class RevitMechanicalSelectedFullRefreshCmd : BasePluginCommand {
public RevitMechanicalSelectedFullRefreshCmd() {
PluginName = "Полное обновление выбранного";
}

protected override void Execute(UIApplication uiApplication) {
new RevitRepository(uiApplication).SelectedFullRefresh();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace RevitMechanicalSpecification {
[Transaction(TransactionMode.Manual)]
public class RevitMechanicalSpecificationRefreshCmd : BasePluginCommand {
public RevitMechanicalSpecificationRefreshCmd() {
PluginName = "RevitMechanicalSpecification";
PluginName = "Обновление спецификации";
}

protected override void Execute(UIApplication uiApplication) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace RevitMechanicalSpecification {
[Transaction(TransactionMode.Manual)]
public class RevitMechanicalSystemRefreshCmd : BasePluginCommand {
public RevitMechanicalSystemRefreshCmd() {
PluginName = "RevitMechanicalSpecification";
PluginName = "Обновление имени системы";
}

protected override void Execute(UIApplication uiApplication) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 RevitMechanicalSpecification.Models;
using RevitMechanicalSpecification.ViewModels;
using RevitMechanicalSpecification.Views;

namespace RevitMechanicalSpecification {
[Transaction(TransactionMode.Manual)]
public class RevitMechanicalVisibleFullRefreshCmd : BasePluginCommand {
public RevitMechanicalVisibleFullRefreshCmd() {
PluginName = "Полное обновление видимого";
}

protected override void Execute(UIApplication uiApplication) {
new RevitRepository(uiApplication).VisibleFullRefresh();
}
}
}
86 changes: 62 additions & 24 deletions src/RevitMechanicalSpecification/Service/CollectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,21 @@
using System.Windows.Forms;
using RevitMechanicalSpecification.Entities;
using RevitMechanicalSpecification.Models;
using Autodesk.Revit.UI;

namespace RevitMechanicalSpecification.Service {

internal class CollectionFactory {
private readonly Document _document;
private readonly SpecConfiguration _specConfiguration;
private readonly UIDocument _uidocument;
private readonly List<BuiltInCategory> _mechanicalCategories;

public CollectionFactory(Document doc, SpecConfiguration specConfiguration) {
public CollectionFactory(Document doc, SpecConfiguration specConfiguration, UIDocument uIDocument) {
_document = doc;
_uidocument = uIDocument;
_specConfiguration = specConfiguration;
}

/// <summary>
/// Получение специфицируемых элементов
/// </summary>
/// <returns></returns>
public List<Element> GetElementsToSpecificate() {
var mechanicalCategories = new List<BuiltInCategory>()
_mechanicalCategories = new List<BuiltInCategory>()
{
BuiltInCategory.OST_DuctFitting,
BuiltInCategory.OST_PipeFitting,
Expand All @@ -44,7 +41,6 @@ public List<Element> GetElementsToSpecificate() {
BuiltInCategory.OST_Sprinklers,
BuiltInCategory.OST_CableTray
};
return GetElementsByCategories(mechanicalCategories);
}

/// <summary>
Expand All @@ -70,41 +66,83 @@ public List<VisSystem> GetVisSystems() {

SystemForsedInstanceName = element
.GetSharedParamValueOrDefault<string>(_specConfiguration.ForcedSystemName)

}));

return mechanicalSystems;
}

/// <summary>
/// Логический фильтр на исключение текста модели
/// Получаем выбранные элементы по списку категорий
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
private bool ElementNotInGroupOrModelText(Element element) {
public List<Element> GetSelectedElementsByCategories() {
var filter = new ElementMulticategoryFilter(_mechanicalCategories);

if(element is ModelText) {
return false;
}
var selectedElements = _uidocument.GetSelectedElements();

if(element.GroupId.IsNull()) {
return true;
var filteredElements = selectedElements
.Where(e => filter.PassesFilter(e) && ElementNotInGroupOrModelText(e))
.ToList();

// Если выделять объект с вложениями, они не будут выделены. Нужно проверить в выборке на наличие
foreach(Element element in filteredElements) {
if(element is FamilyInstance instance) {
List<Element> subElements = DataOperator.GetSub(instance, _document);
if(subElements.Count > 0) {
filteredElements.Concat(subElements);
}
}
}
return false;

return filteredElements;
}

/// <summary>
/// Получаем видимые элементы по списку категорий
/// </summary>
public List<Element> GetVisibleElementsByCategories() {
var filter = new ElementMulticategoryFilter(_mechanicalCategories);
var view = _document.ActiveView;

var visibleElements = new FilteredElementCollector(_document, view.Id)
.WherePasses(filter)
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.ToElements();

return visibleElements.Where(e => ElementNotInGroupOrModelText(e)).ToList();
}

/// <summary>
/// Получаем элементы по списку категорий
/// </summary>
/// <param name="builtInCategories"></param>
/// <returns></returns>
private List<Element> GetElementsByCategories(List<BuiltInCategory> builtInCategories) {
public List<Element> GetElementsByCategories(List<BuiltInCategory> builtInCategories = null) {
if(builtInCategories == null) {
builtInCategories = _mechanicalCategories;
}
var filter = new ElementMulticategoryFilter(builtInCategories);
var elements = (List<Element>) new FilteredElementCollector(_document)
.WherePasses(filter)
.WhereElementIsNotElementType()
.ToElements();
return elements.Where(e => ElementNotInGroupOrModelText(e)).ToList();
}

/// <summary>
/// Логический фильтр на исключение текста модели
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
private bool ElementNotInGroupOrModelText(Element element) {

if(element is ModelText) {
return false;
}

if(element.GroupId.IsNull()) {
return true;
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@ public string GetDuctFittingName(Element element) {
return startName;
}


string size = element.GetParamValue<string>(BuiltInParameter.RBS_CALCULATED_SIZE);
//Ревит пишет размеры всех коннекторов. Для всего кроме тройника и перехода нам хватит первого размера
if(!(fitting.PartType is PartType.Transition) || !(fitting.PartType is PartType.Tee)) {

bool notTransition = !(fitting.PartType is PartType.Transition);
bool notTee = !(fitting.PartType is PartType.Tee);

if(notTransition && notTee) {
size = size.Split('-').First();
}
return startName + " " + size + ", с толщиной стенки " + thikness + " мм";
Expand Down
Loading