Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Updated components visibility and selection workflow in Revit
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo Cominetti committed Aug 7, 2017
1 parent 8586631 commit 58e2029
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 94 deletions.
87 changes: 43 additions & 44 deletions Bcfier.Revit/Data/RevitView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,53 +153,52 @@ public static VisualizationInfo GenerateViewpoint(UIDocument uidoc)
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.Where(x => x.IsHidden(doc.ActiveView)
|| !doc.ActiveView.IsElementVisibleInTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate, x.Id)).ToList();//would need to check how much this is affecting performance
|| !doc.ActiveView.IsElementVisibleInTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate, x.Id)).Select(x=>x.Id)
;//would need to check how much this is affecting performance

var selectedElems = uidoc.Selection.GetElementIds();

//TODO: FIX visibility/selection
//include only hidden elements and selected in the BCF
//if (visibleElems.Count() > hiddenElems.Count())
//{
// foreach (var elem in hiddenElems)
// {
// v.Components.Add(new Component
// {
// OriginatingSystem = versionName,
// IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem.Id)),
// Visible = false,
// Selected = false,
// AuthoringToolId = elem.Id.IntegerValue.ToString()
// });
// }
// foreach (var elem in selectedElems)
// {
// v.Components.Add(new Component
// {
// OriginatingSystem = versionName,
// IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem)),
// Visible = true,
// Selected = true,
// AuthoringToolId = elem.IntegerValue.ToString()
// });
// }
//}
//include only visible elements
//all the others are hidden
//else
//{
// foreach (var elem in visibleElems)
// {
// v.Components.Add(new Component
// {
// OriginatingSystem = versionName,
// IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem)),
// Visible = true,
// Selected = selectedElems.Contains(elem),
// AuthoringToolId = elem.IntegerValue.ToString()
// });
// }
//}
v.Components = new Components();
v.Components.Visibility = new ComponentVisibility();

//TODO: set ViewSetupHints
//TODO: create clipping planes
//list of hidden components is smaller than the list of visible components
if (visibleElems.Count() > hiddenElems.Count())
{
v.Components.Visibility.DefaultVisibility = true;
v.Components.Visibility.DefaultVisibilitySpecified = true;
v.Components.Visibility.Exceptions = hiddenElems.Select(x => new Component
{
OriginatingSystem = versionName,
IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, x)),
AuthoringToolId = x.IntegerValue.ToString()
}).ToArray();

}
//list of visible components is smaller or equals the list of hidden components
else
{
v.Components.Visibility.DefaultVisibility = false;
v.Components.Visibility.DefaultVisibilitySpecified = true;
v.Components.Visibility.Exceptions = visibleElems.Select(x => new Component
{
OriginatingSystem = versionName,
IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, x)),
AuthoringToolId = x.IntegerValue.ToString()
}).ToArray();
}

//selected elements
v.Components.Selection = selectedElems.Select(x => new Component
{
OriginatingSystem = versionName,
IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, x)),
AuthoringToolId = x.IntegerValue.ToString()
}).ToArray();



return v;

}
Expand Down
115 changes: 68 additions & 47 deletions Bcfier.Revit/Entry/ExtEvntOpenView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,53 +174,74 @@ public void Execute(UIApplication app)
else
return;

//TODO: FIX visibility/selection opening a view
//select/hide elements
//if (v.Components != null && v.Components.Any())
//{
// var elementsToSelect = new List<ElementId>();
// var elementsToHide = new List<ElementId>();
// var elementsToShow = new List<ElementId>();

// //Assuming that
// var visibleElems = new FilteredElementCollector(doc, doc.ActiveView.Id)
// .WhereElementIsNotElementType()
// .WhereElementIsViewIndependent()
// .ToElementIds()
// .Where(e => doc.GetElement(e).CanBeHidden(doc.ActiveView)); //might affect performance, but it's necessary

// foreach (var e in visibleElems)
// {
// //elements to select
// var guid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, e));
// if (v.Components.Any(x => x.IfcGuid == guid && x.Selected))
// elementsToSelect.Add(e);

// //elements to hide
// if (v.Components.Any(x => x.IfcGuid == guid && !x.Visible))
// elementsToHide.Add(e);

// //elements to show //could be optional
// if (v.Components.Any(x => x.IfcGuid == guid && x.Visible))
// elementsToShow.Add(e);
// }

// using (var trans = new Transaction(uidoc.Document))
// {
// if (trans.Start("Show/Hide and select elements") == TransactionStatus.Started)
// {
// if (elementsToHide.Any())
// doc.ActiveView.HideElementsTemporary(elementsToHide);
// //there are no items to hide, therefore hide everything and just show the visible ones
// else if (elementsToShow.Any())
// doc.ActiveView.IsolateElementsTemporary(elementsToShow);

// if (elementsToSelect.Any())
// uidoc.Selection.SetElementIds(elementsToSelect);
// }
// trans.Commit();
// }
//}
if (v.Components == null)
return;


var elementsToSelect = new List<ElementId>();
var elementsToHide = new List<ElementId>();
var elementsToShow = new List<ElementId>();

var visibleElems = new FilteredElementCollector(doc, doc.ActiveView.Id)
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.ToElementIds()
.Where(e => doc.GetElement(e).CanBeHidden(doc.ActiveView)); //might affect performance, but it's necessary


bool canSetVisibility = (v.Components.Visibility != null &&
v.Components.Visibility.DefaultVisibilitySpecified &&
v.Components.Visibility.Exceptions.Any())
;
bool canSetSelection = (v.Components.Selection != null && v.Components.Selection.Any());



//loop elements
foreach (var e in visibleElems)
{
var guid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, e));

if (canSetVisibility)
{
if (v.Components.Visibility.DefaultVisibility)
{
if (v.Components.Visibility.Exceptions.Any(x => x.IfcGuid == guid))
elementsToHide.Add(e);
}
else
{
if (v.Components.Visibility.Exceptions.Any(x => x.IfcGuid == guid))
elementsToShow.Add(e);
}
}

if (canSetSelection)
{
if (v.Components.Selection.Any(x => x.IfcGuid == guid))
elementsToSelect.Add(e);
}
}





using (var trans = new Transaction(uidoc.Document))
{
if (trans.Start("Apply BCF visibility and selection") == TransactionStatus.Started)
{
if (elementsToHide.Any())
doc.ActiveView.HideElementsTemporary(elementsToHide);
//there are no items to hide, therefore hide everything and just show the visible ones
else if (elementsToShow.Any())
doc.ActiveView.IsolateElementsTemporary(elementsToShow);

if (elementsToSelect.Any())
uidoc.Selection.SetElementIds(elementsToSelect);
}
trans.Commit();
}


uidoc.RefreshActiveView();
Expand Down
16 changes: 16 additions & 0 deletions Bcfier/Bcf/Bcf2/Visinfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,14 @@ public partial class PerspectiveCamera

private double fieldOfViewField;

//initialize fields
public PerspectiveCamera()
{
CameraViewPoint = new Point();
CameraDirection = new Direction();
CameraUpVector = new Direction();
}

/// <remarks/>
public Point CameraViewPoint
{
Expand Down Expand Up @@ -401,6 +409,14 @@ public partial class OrthogonalCamera

private double viewToWorldScaleField;

//initialize fields
public OrthogonalCamera()
{
CameraViewPoint = new Point();
CameraDirection = new Direction();
CameraUpVector = new Direction();
}

/// <remarks/>
public Point CameraViewPoint
{
Expand Down
3 changes: 2 additions & 1 deletion Bcfier/Themes/ViewCommentDataTemplate.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@
</Style.Triggers>
</Style>
</StackPanel.Style>
<!-- components are now disabled
<themes:ButtonIcon
Style="{StaticResource OverlayButton}"
Command="data:Commands.OpenComponents"
CommandParameter="{Binding Viewpoint}"
IconPath="{StaticResource IconList}"
ToolTip="Show Components" />
ToolTip="Show Components" />-->
<themes:ButtonIcon
Style="{StaticResource OverlayButton}"
Command="data:Commands.OpenSnapshot"
Expand Down
4 changes: 2 additions & 2 deletions Bcfier/Windows/ComponentsList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace Bcfier.Windows
/// </summary>
public partial class ComponentsList : Window
{
//disabled for now
public ComponentsList(Components components)
{
InitializeComponent();
//TODO: properly display components info
componentsList.ItemsSource = components.Selection;
//componentsList.ItemsSource = components.Selection;

}
}
Expand Down

0 comments on commit 58e2029

Please sign in to comment.