//
// (C) Copyright 2003-2010 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.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit.Utility;
namespace Revit.SDK.Samples.Materials.CS
{
///
/// A Form used to display all Asset retrieved from Application
///
public partial class RenderAppearancesFrom : System.Windows.Forms.Form
{
#region Fields
///
/// A reference to Application's property "Assets"
///
private static AssetSet m_asssets;
///
/// A map between Asset and its name
///
private static Dictionary m_assetDict;
///
/// A list store names of all Asset retrieved from m_assets
///
private static List m_assetNameList;
///
/// RenderAppearanceDescriptor of current Asset
///
private RenderAppearanceDescriptor m_descriptor;
///
/// Current selected Asset
///
private Asset m_selectedAsset;
#endregion
#region Properties
///
/// Property to get selected Asset
///
public Asset SelectedAsset
{
get
{
return m_selectedAsset;
}
}
///
/// Property to get or set AssetSet
///
public static AssetSet Asssets
{
get
{
return m_asssets;
}
set
{
if(null == value)
{
return;
}
m_asssets = value;
LoadAssets();
}
}
#endregion
#region Methods
///
/// public class Constructor
///
public RenderAppearancesFrom()
{
InitializeComponent();
}
///
/// Occurs before a form is displayed for the first time.
///
///
///
private void RenderAppearancesFrom_Load(object sender, EventArgs e)
{
if(null == m_assetDict || null == m_assetNameList)
{
LoadAssets();
}
//Deal with ListBox used to display all Asset
renderAppearancesListBox.DataSource = m_assetNameList;
if (0 == renderAppearancesListBox.Items.Count)
{
m_selectedAsset = null;
return;
}
else
{
renderAppearancesListBox.SetSelected(0, true);
}
}
///
/// Occurs when the SelectedIndex property has changed.
///
///
///
private void renderAppearancesListBox_SelectedIndexChanged(object sender, EventArgs e)
{
//Get selected Asset's name
String selectedAssetName = renderAppearancesListBox.SelectedItem as String;
//Try to find the Asset with name in dictionary
if(m_assetDict.TryGetValue(selectedAssetName,out m_selectedAsset))
{
if(null != m_selectedAsset)
{
m_descriptor = new RenderAppearanceDescriptor(m_selectedAsset);
}
else
{
m_descriptor = null;
}
}
else
{
m_selectedAsset = null;
m_descriptor = null;
}
renderAppearancePropertyGrid.SelectedObject = m_descriptor;
}
///
/// Collect Asset information from AssetSet
///
private static void LoadAssets()
{
if (null == m_assetDict)
{
m_assetDict = new Dictionary();
}
if(null == m_assetNameList)
{
m_assetNameList = new List();
}
if(null == m_asssets)
{
return;
}
//Clear their members, prepare to add new members.
m_assetDict.Clear();
m_assetNameList.Clear();
if(0 == m_asssets.Size)
{
return;
}
//For each Asset, add their name to a list
//and build the map between Asset and its name;
foreach (Asset asset in m_asssets)
{
if (null != asset && null != asset.Name)
{
m_assetDict.Add(asset.Name, asset);
m_assetNameList.Add(asset.Name);
}
}
m_assetNameList.Sort();
}
#endregion
}
}