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
11 changes: 7 additions & 4 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,27 +125,31 @@ public RevitRepository(UIApplication uiApplication) {
/// Обновление только по филлерам спецификации
/// </summary>
public void SpecificationRefresh() {
_elements = _collector.GetElementsToSpecificate();
_elementProcessor.ProcessElements(_fillersSpecRefresh, _elements);
}

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

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

/// <summary>
/// Здесь нужно провести полное обновление всех параметров, поэтому будут сложены все филлеры в один лист
/// </summary>
public void FullRefresh() {
public void FullRefresh(bool visible = false, bool selected = false) {
_elements = _collector.GetElementsToSpecificate(visible, selected);
List<ElementParamFiller> fillers = new List<ElementParamFiller>();
fillers.AddRange(_fillersSpecRefresh);
fillers.AddRange(_fillersFunctionRefresh);
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 = "RevitMechanicalSpecification";
dosymep marked this conversation as resolved.
Show resolved Hide resolved
}

protected override void Execute(UIApplication uiApplication) {
new RevitRepository(uiApplication).FullRefresh(selected: true);
}
}
}
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 = "RevitMechanicalSpecification";
dosymep marked this conversation as resolved.
Show resolved Hide resolved
}

protected override void Execute(UIApplication uiApplication) {
new RevitRepository(uiApplication).FullRefresh(visible: true);
}
}
}
52 changes: 50 additions & 2 deletions src/RevitMechanicalSpecification/Service/CollectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@
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;

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() {
public List<Element> GetElementsToSpecificate(bool visible = false, bool selected = false) {
dosymep marked this conversation as resolved.
Show resolved Hide resolved
var mechanicalCategories = new List<BuiltInCategory>()
{
BuiltInCategory.OST_DuctFitting,
Expand All @@ -44,6 +47,15 @@ public List<Element> GetElementsToSpecificate() {
BuiltInCategory.OST_Sprinklers,
BuiltInCategory.OST_CableTray
};

if (visible) {
return GetVisibleElementsByCategories(mechanicalCategories);
}

if(selected) {
return GetSelectedElementsByCategories(mechanicalCategories);
}

return GetElementsByCategories(mechanicalCategories);
}

Expand Down Expand Up @@ -93,6 +105,42 @@ private bool ElementNotInGroupOrModelText(Element element) {
return false;
}

private List<Element> GetSelectedElementsByCategories(List<BuiltInCategory> builtInCategories) {
var filter = new ElementMulticategoryFilter(builtInCategories);
var elementIds = _uidocument.Selection.GetElementIds();

var selectedElements = elementIds.Select(elemId => _uidocument.Document.GetElement(elemId)).ToList();
dosymep marked this conversation as resolved.
Show resolved Hide resolved

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 filteredElements;
}

private List<Element> GetVisibleElementsByCategories(List<BuiltInCategory> builtInCategories) {
var filter = new ElementMulticategoryFilter(builtInCategories);
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ 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)) {
if(!(fitting.PartType is PartType.Transition) & !(fitting.PartType is PartType.Tee)) {
dosymep marked this conversation as resolved.
Show resolved Hide resolved
size = size.Split('-').First();
}
return startName + " " + size + ", с толщиной стенки " + thikness + " мм";
Expand Down
Loading