//
// (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.
//
namespace Revit.SDK.Samples.CreateBeamSystem.CS
{
using System;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using Autodesk.Revit;
using Autodesk.Revit.DB;
///
/// describes the type of beam layout method in beam system
///
public enum LayoutMethod
{
///
/// the beam's layout method in beam System is clear the spacing among beams
///
ClearSpacing,
///
/// maximum the space among beams
///
MaximumSpacing,
///
/// has fixed beams number and user appoint the number
///
FixedNumber,
///
/// has fixed distance among beams and user appoint this distance
///
FixedDistance
}
///
/// declares a delegate for a method that takes in a LayoutMethod
///
///
public delegate void LayoutRuleChangedHandler(ref LayoutMethod layoutMethod);
///
/// the properties of beam system;
/// can be displayed in PropertyGrid
///
public abstract class BeamSystemParam
{
///
/// layout method
///
protected LayoutMethod m_layoutType;
///
/// space between beams; buffer for subclass
///
protected double m_fixedSpacing;
///
/// justify type; buffer for subclass
///
protected BeamSystemJustifyType m_justifyType;
///
/// number of beams
///
protected int m_numberOfLines;
private LayoutRuleChangedHandler m_layoutRuleChanged;
private FamilySymbol m_beamType; // beam type of beam system
///
/// layout method of beam system is changed
///
[Browsable(false)]
public LayoutRuleChangedHandler LayoutRuleChanged
{
get
{
return m_layoutRuleChanged;
}
set
{
m_layoutRuleChanged = value;
}
}
///
/// kind of layout rule
///
[Category("Pattern"),
Description("Specify the layout rule")]
public LayoutMethod LayoutRuleMethod
{
get
{
return m_layoutType;
}
set
{
if (m_layoutType != value)
{
// invokes the delegate
LayoutRuleChanged(ref value);
}
}
}
///
/// type of beam used to create beam system
///
[Category("Pattern"), TypeConverter(typeof(BeamTypeItem)),
Description("Select a value for the Beam Type used in the beam system")]
public FamilySymbol BeamType
{
get
{
return m_beamType;
}
set
{
m_beamType = value;
}
}
///
/// initial general members for its subclass
///
protected BeamSystemParam()
{
m_fixedSpacing = 2000.0;
m_justifyType = BeamSystemJustifyType.Center;
m_numberOfLines = 6;
}
///
/// create BeamSystemParam's subclass according to LayoutMethod
///
/// LayoutMethod
/// created BeamSystemParam's subclass
public static BeamSystemParam CreateInstance(LayoutMethod layoutType)
{
BeamSystemParam param = null;
switch (layoutType)
{
case LayoutMethod.ClearSpacing:
param = new ClearSpacingParam();
break;
case LayoutMethod.FixedDistance:
param = new FixedDistanceParam();
break;
case LayoutMethod.FixedNumber:
param = new FixedNumberParam();
break;
case LayoutMethod.MaximumSpacing:
param = new MaximumSpacingParam();
break;
default:
break;
}
// it is absolutely impossible unless layoutType is wrong
Debug.Assert(null != param);
return param;
}
///
/// clone BeamSystemParam to one of its subclass according to LayoutMethod
///
/// LayoutMethod
/// cloned BeamSystemParam's subclass
public BeamSystemParam CloneInstance(LayoutMethod layoutType)
{
// create a BeamSystemParam instance and set its properties
BeamSystemParam param = CreateInstance(layoutType);
param.m_fixedSpacing = m_fixedSpacing;
param.m_justifyType = m_justifyType;
param.m_numberOfLines = m_numberOfLines;
param.m_beamType = m_beamType;
return param;
}
///
/// subclass of LayoutRule
///
[Browsable(false)]
public abstract LayoutRule Layout
{
get;
}
///
/// properties related to LayoutRule when it's clear spacing
/// only visible for class BeamSystemParam
///
class ClearSpacingParam : BeamSystemParam, IDisposable
{
protected LayoutRuleClearSpacing m_layout;
///
/// wrapped LayoutRuleClearSpacing object
///
public override LayoutRule Layout
{
get
{
return m_layout;
}
}
///
/// FixedSpacing value of beam system
///
[Category("Pattern"),
Description("representing the distance between each beam")]
public double ClearSpacing
{
get
{
return m_fixedSpacing;
}
set
{
try
{
m_layout.Spacing = value;
m_fixedSpacing = value;
}
catch
{
}
}
}
///
/// JustifyType value of beam system
///
[Category("Pattern"),
Description("This value determines the placement of the first beam"
+ " and each subsequent beam is spaced a fixed distance from it.")]
public BeamSystemJustifyType JustifyType
{
get
{
return m_justifyType;
}
set
{
m_layout.JustifyType = value;
m_justifyType = value;
}
}
///
/// constructor
///
public ClearSpacingParam()
: base()
{
m_layout = new LayoutRuleClearSpacing(m_fixedSpacing, m_justifyType);
m_layoutType = LayoutMethod.ClearSpacing;
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (m_layout != null)
m_layout.Dispose();
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
///
/// properties related to LayoutRule when it's fixed distance
/// only visible for class BeamSystemParam
///
class FixedDistanceParam : BeamSystemParam, IDisposable
{
protected LayoutRuleFixedDistance m_layout;
///
/// wrapped LayoutRuleFixedDistance object
///
public override LayoutRule Layout
{
get
{
return m_layout;
}
}
///
/// constructor
///
public FixedDistanceParam()
: base()
{
m_layout = new LayoutRuleFixedDistance(m_fixedSpacing, m_justifyType);
m_layoutType = LayoutMethod.FixedDistance;
}
///
/// FixedSpacing value of beam system
///
[Category("Pattern"),
Description("allows you to specify the distance between beams"
+ " based on the justification you specify.")]
public double FixedSpacing
{
get
{
return m_fixedSpacing;
}
set
{
try
{
m_layout.Spacing = value;
m_fixedSpacing = value;
}
catch
{
}
}
}
///
/// JustifyType value of beam system
///
[Category("Pattern"),
Description("determines the placement of the first beam in the system"
+ " and each subsequent beam is spaced a fixed distance from that point.")]
public BeamSystemJustifyType JustifyType
{
get
{
return m_justifyType;
}
set
{
m_layout.JustifyType = value;
m_justifyType = value;
}
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (m_layout != null)
m_layout.Dispose();
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
///
/// properties related to LayoutRule when it's fixed number
/// only visible for class BeamSystemParam
///
class FixedNumberParam : BeamSystemParam, IDisposable
{
protected LayoutRuleFixedNumber m_layout;
///
/// NumberOfLines value of beam system
///
[Category("Pattern"),
Description("allows you to specify the number of beams within the beam system.")]
public int NumberOfLines
{
get
{
return m_numberOfLines;
}
set
{
try
{
m_layout.NumberOfLines = value;
m_numberOfLines = value;
}
catch
{
}
}
}
///
/// wrapped LayoutRuleFixedNumber object
///
public override LayoutRule Layout
{
get
{
return m_layout;
}
}
///
/// constructor
///
public FixedNumberParam()
: base()
{
m_layout = new LayoutRuleFixedNumber(m_numberOfLines);
m_layoutType = LayoutMethod.FixedNumber;
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (m_layout != null)
m_layout.Dispose();
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
///
/// properties related to LayoutRule when it's maximum spacing
/// only visible for class BeamSystemParam
///
class MaximumSpacingParam : BeamSystemParam, IDisposable
{
protected LayoutRuleMaximumSpacing m_layout;
///
/// FixedSpacing value of beam system
///
[Category("Pattern"),
Description("allows you to specify the maximum distance between beams.")]
public double MaximumSpacing
{
get
{
return m_fixedSpacing;
}
set
{
try
{
m_layout.Spacing = value;
m_fixedSpacing = value;
}
catch
{
}
}
}
///
/// wrapped LayoutRuleMaximumSpacing object
///
public override LayoutRule Layout
{
get
{
return m_layout;
}
}
///
/// constructor
///
public MaximumSpacingParam()
: base()
{
m_layout = new LayoutRuleMaximumSpacing(m_fixedSpacing);
m_layoutType = LayoutMethod.MaximumSpacing;
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (m_layout != null)
m_layout.Dispose();
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
}