//
// (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 Autodesk.Revit.DB.Structure;
using System.Windows.Forms;
namespace Revit.SDK.Samples.NewRebar.CS
{
///
/// This class wraps RebarShapeDefinition object.
///
public abstract class RebarShapeDef
{
///
/// RebarShape definition, the real object to be wrapped.
///
protected RebarShapeDefinition m_rebarshapeDefinition;
///
/// All the parameters will be added to RebarShapeDefinition.
///
protected List m_parameters;
///
/// All the dimensions will be added to RebarShapeDefinition.
///
protected List m_constraints;
///
/// Return the real object RebarShapeDefinition.
///
public RebarShapeDefinition RebarshapeDefinition
{
get { return m_rebarshapeDefinition; }
}
///
/// Return all the parameters.
///
public List Parameters
{
get { return m_parameters; }
}
///
/// Return all the dimensions.
///
public List Constraints
{
get { return m_constraints; }
}
///
/// Constructor, initialize the fields.
///
/// RebarShapeDefinition object to be wrapped
public RebarShapeDef(RebarShapeDefinition shapeDef)
{
m_rebarshapeDefinition = shapeDef;
m_parameters = new List();
m_constraints = new List();
}
///
/// Add a parameter to RebarShapeDefinition.
///
/// Parameter type:
/// (type of RebarShapeParameterDouble or type of RebarShapeParameterFormula)
/// Parameter name
/// Parameter value (double value or formula string)
///
public RebarShapeParameter AddParameter(Type parameterType, object name, object value)
{
RebarShapeParameter param =
Activator.CreateInstance(parameterType, this, name, value) as RebarShapeParameter;
m_parameters.Add(param);
return param;
}
///
/// Add a constraint to RebarShapeDefinition.
///
/// Type of constraint
/// (the class must be subclass of ConstraintOnRebarShape).
///
public ConstraintOnRebarShape AddConstraint(Type constraintType)
{
ConstraintOnRebarShape constraintIns =
Activator.CreateInstance(constraintType, this) as ConstraintOnRebarShape;
m_constraints.Add(constraintIns);
return constraintIns;
}
///
/// Submit RebarShapeDefinition. All the parameters and constraints
/// will be added to RebarShape. The RebarShape will be added to Revit document after
/// successfully submitted.
///
/// Parameter definition group
public void Commit(Document rvtDoc, DefinitionGroup defGroup)
{
// Submit all the parameters.
foreach (RebarShapeParameter param in m_parameters)
{
param.Commit(rvtDoc, defGroup);
}
// Submit all the constraints.
foreach (ConstraintOnRebarShape constraint in m_constraints)
{
constraint.Commit();
}
// Submit the RebarShape.
if (m_rebarshapeDefinition.Complete)
{
m_rebarshapeDefinition.CheckDefaultParameterValues(0, 0);
}
else
{
throw new Exception("The Rebar shape definition is not completed.");
}
}
///
/// Return all the parameter types supported by RebarShape definition.
///
/// All the parameter types supported by RebarShape definition
public List AllParameterTypes()
{
List types = new List();
types.Add(typeof(RebarShapeParameterDouble));
types.Add(typeof(RebarShapeParameterFormula));
return types;
}
///
/// Return all the constraint types supported by RebarShapeDefinition.
///
/// all the constraint types supported by RebarShapeDefinition
public virtual List AllowedConstraintTypes()
{
return new List();
}
}
}