// // (C) Copyright 2003-2019 by Autodesk, Inc. // // 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 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 System; using System.Collections.Generic; using System.Text; using Autodesk.Revit; using Autodesk.Revit.DB; using System.Drawing.Design; namespace Revit.SDK.Samples.NewHostedSweep.CS { /// /// This class contains the data for hosted sweep creation. /// public class CreationData { /// /// Represents the method that will handle the EdgeAdded or EdgeRemoved events /// of CreationData /// /// Edge public delegate void EdgeEventHandler(Edge edge); /// /// Represents the method that will handle the SymbolChanged events /// of CreationData /// /// Symbol public delegate void SymbolChangedEventHandler(ElementType sym); /// /// Edge is added to HostedSweep. /// public event EdgeEventHandler EdgeAdded; /// /// Edge is removed from HostedSweep. /// public event EdgeEventHandler EdgeRemoved; /// /// HostedSweep symbol is changed. /// public event SymbolChangedEventHandler SymbolChanged; /// /// Creator contains the necessary data to fetch the edges and get the symbol. /// private HostedSweepCreator m_creator; /// /// Symbol for HostedSweep creation. /// private ElementType m_symbol; /// /// Edges which contains references for HostedSweep creation. /// private List m_edgesForHostedSweep = new List(); /// /// Back up of Symbol. /// private ElementType m_backUpSymbol; /// /// Back up of Edges. /// private List m_backUpEdges = new List(); /// /// Constructor. /// /// HostedSweepCreator public CreationData(HostedSweepCreator creator) { m_creator = creator; } /// /// Back up the Symbol and Edges. /// public void BackUp() { m_backUpSymbol = m_symbol; m_backUpEdges.Clear(); m_backUpEdges.AddRange(m_edgesForHostedSweep); } /// /// Restore the Symbol and Edges. /// public void Restore() { m_symbol = m_backUpSymbol; m_edgesForHostedSweep.Clear(); m_edgesForHostedSweep.AddRange(m_backUpEdges); } /// /// If CreationData changed, notify its observers. /// public void Update() { if (SymbolChanged != null && m_backUpSymbol != null && m_backUpSymbol.Id.IntegerValue != m_symbol.Id.IntegerValue) SymbolChanged(m_symbol); if (EdgeRemoved != null) { foreach (Edge edge in m_backUpEdges) { if (m_edgesForHostedSweep.IndexOf(edge) == -1) { EdgeRemoved(edge); } } } if(EdgeAdded != null) { foreach (Edge edge in m_edgesForHostedSweep) { if (m_backUpEdges.IndexOf(edge) == -1) { EdgeAdded(edge); } } } } /// /// Creator contains the necessary data to fetch the edges and get the symbol. /// public HostedSweepCreator Creator { get { return m_creator; } } /// /// Symbol for HostedSweep creation. /// public ElementType Symbol { get { return m_symbol; } set { m_symbol = value; } } /// /// Edges which contains references for HostedSweep creation. /// public List EdgesForHostedSweep { get { return m_edgesForHostedSweep; } } } }