//
// (C) Copyright 2003-2020 by Autodesk, Inc. All rights reserved.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM 'AS IS' AND WITH ALL ITS FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
using Autodesk.Revit.DB;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Revit.SDK.Samples.InCanvasControlAPI.CS
{
///
/// A class tracks all issue markers in a given document. It also tracks the index of the active selected marker.
///
public class IssueMarkerTracking
{
#region Class implementation
///
/// Creates IssueMarkerTracking for the opened document and initializes selected index
///
/// An opened Revit document
public IssueMarkerTracking(Document document)
{
this.document = document;
guid = Guid.NewGuid();
selectedIndex = -1;
}
///
/// Adds a marker to this tracking
///
/// Marker to be updated by selector or updater.
public void SubscribeMarker(IssueMarker marker)
{
issueMarkerSet.Add(marker);
}
///
/// Removes marker that tracks the element specified by id.
///
/// Tracked element id
public void RemoveMarkerByElement(ElementId elementId)
{
issueMarkerSet.RemoveWhere((m) => m.TrackedElementId == elementId);
}
///
/// Gets the issue marker that tracks element specified by id
///
/// Tracked element id
/// A corresponding Issue Marker
public IssueMarker GetMarkerByElementId(ElementId elementId)
{
return issueMarkerSet.Where((m) => m.TrackedElementId == elementId).FirstOrDefault();
}
///
/// Gets the issue marker by it's id in TemporaryGraphicsManager
///
/// Index of the in-canvas control
/// A corresponding Issue Marker
public IssueMarker GetMarkerByIndex(int index)
{
return issueMarkerSet.Where((m) => m.ControlIndex == index).FirstOrDefault();
}
///
/// Document this object tracks
///
public Document Document { get => document; }
///
/// Tracker's GUID. This is needed to safely clean up after document closes.
///
public Guid Id { get => guid; }
///
/// Gets the index of selected marker. This is used by selector
///
/// The index of selected marker
public int GetSelected()
{
return selectedIndex;
}
///
/// Sets the index of selected marker. This is used by selector
///
/// Index of the marker
public void SetSelected(int index)
{
selectedIndex = index;
}
#endregion
#region Class member variables
private int selectedIndex;
private HashSet issueMarkerSet = new HashSet();
private Document document;
private Guid guid;
#endregion
}
}