// // (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 System.ComponentModel; using Autodesk.Revit.DB.Structure; namespace Revit.SDK.Samples.NewRebar.CS { /// /// Segment's ends reference enum. /// enum EndReference { /// /// Segment's start reference. /// Begin = 0, /// /// Segment's end reference. /// End = 1 } /// /// Constraint to be added to RebarShapeDefBySegment. /// abstract class ConstraintOnSegmentShape : ConstraintOnRebarShape { public ConstraintOnSegmentShape(RebarShapeDefBySegment def) : base(def) { } /// /// Update list value for property grid. /// protected void UpdateSegmentIdTypeConverter() { TypeConverterSegmentId.SegmentCount = GetRebarShapeDefinitionBySegments.NumberOfSegments; } /// /// Get RebarShapeDefinitionBySegments object. /// protected RebarShapeDefinitionBySegments GetRebarShapeDefinitionBySegments { get { return m_shapeDef.RebarshapeDefinition as RebarShapeDefinitionBySegments; } } } /// /// Default radius dimension of bend. /// class ConstraintBendDefaultRadius : ConstraintOnSegmentShape { /// /// Segment to be added constraint on. /// private int m_segment; /// /// Bend orientation field. /// private RebarShapeVertexTurn m_turn; /// /// Bend angle field. /// private RebarShapeBendAngle m_bendAngle; /// /// Constructor /// /// public ConstraintBendDefaultRadius(RebarShapeDefBySegment def) : base(def) { m_turn = RebarShapeVertexTurn.Left; m_bendAngle = RebarShapeBendAngle.Obtuse; } /// /// Segment to be added constraint on. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment { get { UpdateSegmentIdTypeConverter(); return m_segment; } set { m_segment = value; } } /// /// Bend orientation property. /// public RebarShapeVertexTurn Turn { get { return m_turn; } set { m_turn = value; } } /// /// Bend angle property. /// public RebarShapeBendAngle BendAngle { get { return m_bendAngle; } set { m_bendAngle = value; } } /// /// Add bend default radius constraint to RebarShapeDefinitionBySegments. /// public override void Commit() { GetRebarShapeDefinitionBySegments.AddBendDefaultRadius( m_segment, m_turn, m_bendAngle); } } /// /// Variable radius dimension of bend. /// class ConstraintBendVariableRadius : ConstraintOnSegmentShape { /// /// Segment to be added constraint on. /// private int m_segment; /// /// Bend orientation field. /// private RebarShapeVertexTurn m_turn; /// /// Bend angle field. /// private RebarShapeBendAngle m_bendAngle; /// /// Radius dimension field. /// private RebarShapeParameter m_radiusParameter; /// /// Measure length including bar thickness or not. /// private bool m_measureIncludingBarThickness; public ConstraintBendVariableRadius(RebarShapeDefBySegment def) : base(def) { m_bendAngle = RebarShapeBendAngle.Obtuse; m_turn = RebarShapeVertexTurn.Left; m_measureIncludingBarThickness = true; } /// /// Segment to be added constraint on. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment { get { UpdateSegmentIdTypeConverter(); return m_segment; } set { m_segment = value; } } /// /// Bend orientation property. /// public RebarShapeVertexTurn Turn { get { return m_turn; } set { m_turn = value; } } /// /// Bend angle property. /// public RebarShapeBendAngle BendAngle { get { return m_bendAngle; } set { m_bendAngle = value; } } /// /// Radius dimension property. /// [TypeConverter(typeof(TypeConverterRebarShapeParameter))] public RebarShapeParameter RadiusParameter { get { UpdateParameterTypeConverter(); return m_radiusParameter; } set { m_radiusParameter = value; } } /// /// Measure including bar thickness or not. /// public bool MeasureIncludingBarThickness { get { return m_measureIncludingBarThickness; } set { m_measureIncludingBarThickness = value; } } /// /// Add Dimension to constrain the bend radius. /// public override void Commit() { GetRebarShapeDefinitionBySegments.AddBendVariableRadius( m_segment, m_turn, m_bendAngle, m_radiusParameter.Parameter, m_measureIncludingBarThickness); } } /// /// Parallel dimension to segment. /// class ConstraintParallelToSegment : ConstraintOnSegmentShape { /// /// Segment to be added constraint on. /// private int m_segment; /// /// Dimension to constrain the length of segment. /// private RebarShapeParameter m_parameter; /// /// Measure segment's length to outside of bend 0 or not. /// private bool m_measureToOutsideOfBend0; /// /// Measure segment's length to outside of bend 1 or not. /// private bool m_measureToOutsideOfBend1; /// /// Constructor /// /// public ConstraintParallelToSegment(RebarShapeDefBySegment def) : base(def) { m_measureToOutsideOfBend0 = true; m_measureToOutsideOfBend1 = true; } /// /// Segment to be added constraint on. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment { get { UpdateSegmentIdTypeConverter(); return m_segment; } set { m_segment = value; } } /// /// Dimension to constrain the length of segment. /// [TypeConverter(typeof(TypeConverterRebarShapeParameter))] public RebarShapeParameter Parameter { get { UpdateParameterTypeConverter(); return m_parameter; } set { m_parameter = value; } } /// /// Measure segment's length to outside of bend 0 or not. /// public bool MeasureToOutsideOfBend0 { get { return m_measureToOutsideOfBend0; } set { m_measureToOutsideOfBend0 = value; } } /// /// Measure segment's length to outside of bend 1 or not. /// public bool MeasureToOutsideOfBend1 { get { return m_measureToOutsideOfBend1; } set { m_measureToOutsideOfBend1 = value; } } /// /// Add Dimension to constrain the segment length. /// public override void Commit() { GetRebarShapeDefinitionBySegments.AddConstraintParallelToSegment( m_segment, m_parameter.Parameter, m_measureToOutsideOfBend0, m_measureToOutsideOfBend1); } } /// /// Length dimension of segment in specified direction. /// class ConstraintToSegment : ConstraintOnSegmentShape { /// /// Segment to be added constraint on. /// private int m_segment; /// /// Dimension to constraint the length of segment in specified direction. /// private RebarShapeParameter m_parameter; /// /// X coordinate of constraint direction. /// private double m_constraintDirCoordX; /// /// Y coordinate of constraint direction. /// private double m_constraintDirCoordY; /// /// Sign of Z coordinate of cross product of constraint direction by segment direction. /// private int m_signOfZCoordOfCrossProductOfConstraintDirBySegmentDir; /// /// Measure segment's length to outside of bend 0 or not. /// private bool m_measureToOutsideOfBend0; /// /// Measure segment's length to outside of bend 1 or not. /// private bool m_measureToOutsideOfBend1; public ConstraintToSegment(RebarShapeDefBySegment def) : base(def) { m_measureToOutsideOfBend0 = true; m_measureToOutsideOfBend1 = false; m_signOfZCoordOfCrossProductOfConstraintDirBySegmentDir = -1; } /// /// Segment to be added constraint on. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment { get { UpdateSegmentIdTypeConverter(); return m_segment; } set { m_segment = value; } } /// /// Dimension to constraint the length of segment in specified direction. /// [TypeConverter(typeof(TypeConverterRebarShapeParameter))] public RebarShapeParameter Parameter { get { UpdateParameterTypeConverter(); return m_parameter; } set { m_parameter = value; } } /// /// X coordinate of constraint direction. /// public double ConstraintDirCoordX { get { return m_constraintDirCoordX; } set { m_constraintDirCoordX = value; } } /// /// Y coordinate of constraint direction. /// public double ConstraintDirCoordY { get { return m_constraintDirCoordY; } set { m_constraintDirCoordY = value; } } /// /// Sign of Z coordinate of cross product of constraint direction by segment direction. /// public int SignOfZCoordOfCrossProductOfConstraintDirBySegmentDir { get { return m_signOfZCoordOfCrossProductOfConstraintDirBySegmentDir; } set { m_signOfZCoordOfCrossProductOfConstraintDirBySegmentDir = value; } } /// /// Measure segment's length to outside of bend 0 or not. /// public bool MeasureToOutsideOfBend0 { get { return m_measureToOutsideOfBend0; } set { m_measureToOutsideOfBend0 = value; } } /// /// Measure segment's length to outside of bend 1 or not. /// public bool MeasureToOutsideOfBend1 { get { return m_measureToOutsideOfBend1; } set { m_measureToOutsideOfBend1 = value; } } /// /// Add dimension to constrain the length of segment in the specified direction. /// public override void Commit() { GetRebarShapeDefinitionBySegments.AddConstraintToSegment(m_segment, m_parameter.Parameter, m_constraintDirCoordX, m_constraintDirCoordY, m_signOfZCoordOfCrossProductOfConstraintDirBySegmentDir, m_measureToOutsideOfBend0, m_measureToOutsideOfBend1); } } /// /// Listening length dimension between two bends. /// class ListeningDimensionBendToBend : ConstraintOnSegmentShape { /// /// Dimension to constraint the length of two bends in the specified direction. /// private RebarShapeParameter m_parameter; /// /// X coordinate of constraint direction. /// private double m_constraintDirCoordX; /// /// Y coordinate of constraint direction. /// private double m_constraintDirCoordY; /// /// Reference of segment 0. /// private int m_segment; /// /// End reference of segment 0. /// private EndReference m_end; /// /// Reference of segment 1. /// private int m_segment1; /// /// End reference of segment 1. /// private EndReference m_end1; public ListeningDimensionBendToBend(RebarShapeDefBySegment def) : base(def) { m_end = EndReference.Begin; m_end1 = EndReference.End; m_constraintDirCoordX = 0; m_constraintDirCoordY = 0; } /// /// Dimension to constraint the length of two bends in the specified direction. /// [TypeConverter(typeof(TypeConverterRebarShapeParameter))] public RebarShapeParameter Parameter { get { UpdateParameterTypeConverter(); return m_parameter; } set { m_parameter = value; } } /// /// X coordinate of constraint direction. /// public double ConstraintDirCoordX { get { return m_constraintDirCoordX; } set { m_constraintDirCoordX = value; } } /// /// Y coordinate of constraint direction. /// public double ConstraintDirCoordY { get { return m_constraintDirCoordY; } set { m_constraintDirCoordY = value; } } /// /// Reference of segment 0. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment0 { get { UpdateSegmentIdTypeConverter(); return m_segment; } set { m_segment = value; } } /// /// End reference of segment 0. /// public EndReference End0 { get { return m_end; } set { m_end = value; } } /// /// Reference of segment 1. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment1 { get { UpdateSegmentIdTypeConverter(); return m_segment1; } set { m_segment1 = value; } } /// /// End reference of segment 1. /// public EndReference End1 { get { return m_end1; } set { m_end1 = value; } } /// /// Add listening dimension to constrain the length of two bend in the specified direction. /// public override void Commit() { GetRebarShapeDefinitionBySegments.AddListeningDimensionBendToBend( m_parameter.Parameter, m_constraintDirCoordX, m_constraintDirCoordY, m_segment, (int)m_end, m_segment1, (int)m_end1); } } /// /// Listening length dimension between a segment and a bend. /// class ListeningDimensionSegmentToBend : ConstraintOnSegmentShape { /// /// Dimension to constrain the length between a segment and a bend /// in the specified direction. /// private RebarShapeParameter m_parameter; /// /// X coordinate of constraint direction. /// private double m_constraintDirCoordX; /// /// Y coordinate of constraint direction. /// private double m_constraintDirCoordY; /// /// Reference of segment 0. /// private int m_segment; /// /// Reference of segment 1. /// private int m_segment1; /// /// End reference of segment 1. /// private EndReference m_end1; public ListeningDimensionSegmentToBend(RebarShapeDefBySegment def) : base(def) { m_constraintDirCoordX = 0; m_constraintDirCoordY = 0; m_end1 = EndReference.End; } /// /// Dimension to constrain the length between a segment and a bend /// in the specified direction. /// [TypeConverter(typeof(TypeConverterRebarShapeParameter))] public RebarShapeParameter Parameter { get { UpdateParameterTypeConverter(); return m_parameter; } set { m_parameter = value; } } /// /// X coordinate of constraint direction. /// public double ConstraintDirCoordX { get { return m_constraintDirCoordX; } set { m_constraintDirCoordX = value; } } /// /// Y coordinate of constraint direction. /// public double ConstraintDirCoordY { get { return m_constraintDirCoordY; } set { m_constraintDirCoordY = value; } } /// /// Reference of segment 0. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment0 { get { UpdateSegmentIdTypeConverter(); return m_segment; } set { m_segment = value; } } /// /// Reference of segment 1. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment1 { get { UpdateSegmentIdTypeConverter(); return m_segment1; } set { m_segment1 = value; } } /// /// End reference of segment 1. /// public EndReference End1 { get { return m_end1; } set { m_end1 = value; } } /// /// Add listening dimension to constrain the length between a segment and a bend /// in the specified direction. /// public override void Commit() { GetRebarShapeDefinitionBySegments.AddListeningDimensionSegmentToBend( m_parameter.Parameter, m_constraintDirCoordX, m_constraintDirCoordY, m_segment, m_segment1, (int)m_end1); } } /// /// Listening length dimension between two segments. /// class ListeningDimensionSegmentToSegment : ConstraintOnSegmentShape { /// /// Dimension to constrain the perpendicular distance between two segment. /// The two segment should be parallel. /// private RebarShapeParameter m_parameter; /// /// X coordinate of constraint direction. /// private double m_constraintDirCoordX; /// /// Y coordinate of constraint direction. /// private double m_constraintDirCoordY; /// /// The first segment to be constrained. /// private int m_segment; /// /// The second segment to be constrained. /// private int m_segment1; public ListeningDimensionSegmentToSegment(RebarShapeDefBySegment def) : base(def) { m_constraintDirCoordX = 1; m_constraintDirCoordY = 0; } /// /// Dimension to constrain the perpendicular distance between two segment. /// [TypeConverter(typeof(TypeConverterRebarShapeParameter))] public RebarShapeParameter Parameter { get { UpdateParameterTypeConverter(); return m_parameter; } set { m_parameter = value; } } /// /// X coordinate of constraint direction. /// public double ConstraintDirCoordX { get { return m_constraintDirCoordX; } set { m_constraintDirCoordX = value; } } /// /// Y coordinate of constraint direction. /// public double ConstraintDirCoordY { get { return m_constraintDirCoordY; } set { m_constraintDirCoordY = value; } } /// /// The second segment to be constrained. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment0 { get { UpdateSegmentIdTypeConverter(); return m_segment; } set { m_segment = value; } } /// /// The second segment to be constrained. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment1 { get { UpdateSegmentIdTypeConverter(); return m_segment1; } set { m_segment1 = value; } } /// /// Add dimension to constrain the perpendicular distance between two segment. /// public override void Commit() { GetRebarShapeDefinitionBySegments.AddListeningDimensionSegmentToSegment( m_parameter.Parameter, m_constraintDirCoordX, m_constraintDirCoordY, m_segment, m_segment1); } } /// /// Remove a dimension from a segment. /// class RemoveParameterFromSegment : ConstraintOnSegmentShape { /// /// Reference of segment. /// private int m_segment; /// /// Dimension to be removed. /// private RebarShapeParameter m_radiusParameter; public RemoveParameterFromSegment(RebarShapeDefBySegment def) : base(def) { } /// /// Reference of segment. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment { get { UpdateSegmentIdTypeConverter(); return m_segment; } set { m_segment = value; } } /// /// Dimension to be removed. /// [TypeConverter(typeof(TypeConverterRebarShapeParameter))] public RebarShapeParameter RadiusParameter { get { UpdateParameterTypeConverter(); return m_radiusParameter; } set { m_radiusParameter = value; } } /// /// Remove dimension from Rebar shape. /// public override void Commit() { GetRebarShapeDefinitionBySegments.RemoveParameterFromSegment( m_segment, m_radiusParameter.Parameter); } } /// /// A 180 degree bend dimension. /// class SetSegmentAs180DegreeBend : ConstraintOnSegmentShape { /// /// Reference of segment. /// private int m_segment; /// /// Dimension to constrain the bend's radius. /// private RebarShapeParameter m_radiusParameter; /// /// If measure to outside of bend. /// private bool m_measureToOutsideOfBend; public SetSegmentAs180DegreeBend(RebarShapeDefBySegment def) : base(def) { m_measureToOutsideOfBend = true; } /// /// Reference of segment. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment { get { UpdateSegmentIdTypeConverter(); return m_segment; } set { m_segment = value; } } /// /// Dimension to constrain the bend's radius. /// [TypeConverter(typeof(TypeConverterRebarShapeParameter))] public RebarShapeParameter RadiusParameter { get { UpdateParameterTypeConverter(); return m_radiusParameter; } set { m_radiusParameter = value; } } /// /// If measure the length to outside of bend. /// public bool MeasureToOutsideOfBend { get { return m_measureToOutsideOfBend; } set { m_measureToOutsideOfBend = value; } } /// /// Add a dimension of 180 degree bend for a segment. /// public override void Commit() { GetRebarShapeDefinitionBySegments.SetSegmentAs180DegreeBend( m_segment, m_radiusParameter.Parameter, m_measureToOutsideOfBend); } } /// /// Length dimension of segment in its parallel direction. /// class SetSegmentFixedDirection : ConstraintOnSegmentShape { /// /// Reference of segment. /// private int m_segment; /// /// X coordinate of constraint direction. /// private double m_vecCoordX; /// /// Y coordinate of constraint direction. /// private double m_vecCoordY; public SetSegmentFixedDirection(RebarShapeDefBySegment def) : base(def) { m_vecCoordX = 1; m_vecCoordY = 0; } /// /// Reference of segment. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment { get { UpdateSegmentIdTypeConverter(); return m_segment; } set { m_segment = value; } } /// /// X coordinate of constraint direction. /// public double VecCoordX { get { return m_vecCoordX; } set { m_vecCoordX = value; } } /// /// Y coordinate of constraint direction. /// public double VecCoordY { get { return m_vecCoordY; } set { m_vecCoordY = value; } } /// /// Add dimension to constrain the direction of the segment. /// public override void Commit() { GetRebarShapeDefinitionBySegments.SetSegmentFixedDirection( m_segment, m_vecCoordX, m_vecCoordY); } } /// /// Remove a dimension from a segment. /// class SetSegmentVariableDirection : ConstraintOnSegmentShape { /// /// Reference of segment. /// private int m_segment; public SetSegmentVariableDirection(RebarShapeDefBySegment def) : base(def) { } /// /// Reference of segment. /// [TypeConverter(typeof(TypeConverterSegmentId))] public int Segment { get { UpdateSegmentIdTypeConverter(); return m_segment; } set { m_segment = value; } } /// /// Remove the direction dimension of segment. /// public override void Commit() { GetRebarShapeDefinitionBySegments.SetSegmentVariableDirection(m_segment); } } }