// // (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.Drawing; using System.ComponentModel; using System.Collections.ObjectModel; using Autodesk.Revit; using Autodesk.Revit.DB; namespace Revit.SDK.Samples.NewRoof.RoofForms.CS { /// /// The Util class is used to translate Revit coordination to windows coordination. /// public class Util { /// /// Translate a Revit 3D point to a windows 2D point according the boundingbox. /// /// A Revit 3D point /// The boundingbox of the roof whose footprint lines will be displayed in GDI. /// A windows 2D point. static public PointF Translate(Autodesk.Revit.DB.XYZ pointXYZ, BoundingBoxXYZ boundingbox) { double centerX = (boundingbox.Min.X + boundingbox.Max.X) / 2; double centerY = (boundingbox.Min.Y + boundingbox.Max.Y) / 2; return new PointF((float)(pointXYZ.X - centerX), -(float)(pointXYZ.Y - centerY)); } }; /// /// The FootPrintRoofLine class is used to edit the foot print data of a footprint roof. /// public class FootPrintRoofLine { // To store the footprint roof which the foot print data belong to. private FootPrintRoof m_roof; // To store the model curve data which the foot print data stand for. private ModelCurve m_curve; // To store the boundingbox of the roof private BoundingBoxXYZ m_boundingbox; /// /// The construct of the FootPrintRoofLine class. /// /// The footprint roof which the foot print data belong to. /// The model curve data which the foot print data stand for. public FootPrintRoofLine(FootPrintRoof roof, ModelCurve curve) { m_roof = roof; m_curve = curve; m_boundingbox = m_roof.get_BoundingBox(Revit.SDK.Samples.NewRoof.CS.Command.ActiveView); } /// /// Draw the footprint line in GDI. /// /// /// public void Draw(System.Drawing.Graphics graphics, System.Drawing.Pen pen) { Curve curve = m_curve.GeometryCurve; DrawCurve(graphics, pen, curve); } /// /// Draw the curve in GDI. /// /// /// /// private void DrawCurve(Graphics graphics, System.Drawing.Pen pen, Curve curve) { List poinsts = new List(); foreach (Autodesk.Revit.DB.XYZ point in curve.Tessellate()) { poinsts.Add(Util.Translate(point,m_boundingbox)); } graphics.DrawCurve(pen, poinsts.ToArray()); } /// /// Get the model curve data which the foot print data stand for. /// [Browsable(false)] public ModelCurve ModelCurve { get { return m_curve; } } /// /// Get the id value of the model curve. /// [Browsable(false)] public int Id { get { return m_curve.Id.IntegerValue; } } /// /// Get the name of the model curve. /// [Browsable(false)] public String Name { get { return m_curve.Name; } } /// /// Get/Set the slope definition of a model curve of the roof. /// [Description("The slope definition of the FootPrintRoof line.")] public bool DefinesSlope { get { return m_roof.get_DefinesSlope(m_curve); } set { m_roof.set_DefinesSlope(m_curve, value); } } /// /// Get/Set the slope angle of the FootPrintRoof line.. /// [Description("The slope angle of the FootPrintRoof line.")] public double SlopeAngle { get { return m_roof.get_SlopeAngle(m_curve); } set { m_roof.set_SlopeAngle(m_curve, value); } } /// /// Get/Set the offset of the FootPrintRoof line. /// [Description("The offset of the FootPrintRoof line.")] public double Offset { get { return m_roof.get_Offset(m_curve); } set { m_roof.set_Offset(m_curve, value); } } /// /// Get/Set the overhang value of the FootPrintRoof line if the roof is created by picked wall. /// [Description("The overhang value of the FootPrintRoof line if the roof is created by picked wall.")] public double Overhang { get { return m_roof.get_Overhang(m_curve); } set { m_roof.set_Overhang(m_curve, value); } } /// /// Get/Set ExtendIntoWall value whether you want the overhang to be measured from the core of the wall or not. /// [Description("whether you want the overhang to be measured from the core of the wall or not.")] public bool ExtendIntoWall { get { return m_roof.get_ExtendIntoWall(m_curve); } set { m_roof.set_ExtendIntoWall(m_curve, value); } } }; /// /// The FootPrintRoofWrapper class is use to edit a footprint roof in a PropertyGrid. /// It contains a footprint roof. /// public class FootPrintRoofWrapper { // To store the footprint roof which will be edited in a PropertyGrid. private FootPrintRoof m_roof; // To store the footprint line data of the roof which will be edited. private FootPrintRoofLine m_footPrintLine; // To store the footprint lines data of the roof. private List m_roofLines; // To store the boundingbox of the roof private BoundingBoxXYZ m_boundingbox; public event EventHandler OnFootPrintRoofLineChanged; /// /// The construct of the FootPrintRoofWrapper class. /// /// The footprint roof which will be edited in a PropertyGrid. public FootPrintRoofWrapper(FootPrintRoof roof) { m_roof = roof; m_roofLines = new List(); ModelCurveArrArray curveloops = m_roof.GetProfiles(); foreach(ModelCurveArray curveloop in curveloops) { foreach(ModelCurve curve in curveloop) { m_roofLines.Add(new FootPrintRoofLine(m_roof, curve)); } } FootPrintRoofLineConverter.SetStandardValues(m_roofLines); m_footPrintLine = m_roofLines[0]; m_boundingbox = m_roof.get_BoundingBox(Revit.SDK.Samples.NewRoof.CS.Command.ActiveView); } /// /// Get the bounding box of the roof. /// [Browsable(false)] public BoundingBoxXYZ Boundingbox { get { return m_boundingbox; } } /// /// Get/Set the current footprint roof line which will be edited in the PropertyGrid. /// [TypeConverterAttribute(typeof(FootPrintRoofLineConverter)), Category("Footprint Roof Line Information")] public FootPrintRoofLine FootPrintLine { get { return m_footPrintLine; } set { m_footPrintLine = value; OnFootPrintRoofLineChanged(this, new EventArgs()); } } /// /// The base level of the footprint roof. /// [TypeConverterAttribute(typeof(LevelConverter)), Category("Constrains")] [DisplayName("Base Level")] public Level BaseLevel { get { Parameter para = m_roof.get_Parameter(BuiltInParameter.ROOF_BASE_LEVEL_PARAM); return LevelConverter.GetLevelByID(para.AsElementId().IntegerValue); } set { // update base level Parameter para = m_roof.get_Parameter(BuiltInParameter.ROOF_BASE_LEVEL_PARAM); Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(value.Id.IntegerValue); para.Set(id); } } /// /// The eave cutter type of the footprint roof. /// [Category("Construction")] [DisplayName("Rafter Cut")] [Description("The eave cutter type of the footprint roof.")] public EaveCutterType EaveCutterType { get { return m_roof.EaveCuts; } set { m_roof.EaveCuts = value; } } /// /// Get the footprint roof lines data. /// [Browsable(false)] public ReadOnlyCollection FootPrintRoofLines { get { return new ReadOnlyCollection(m_roofLines); } } /// /// Draw the footprint lines. /// /// The graphics object. /// A display pen. /// A highlight pen. public void DrawFootPrint(Graphics graphics, Pen displayPen, Pen highlightPen) { foreach (FootPrintRoofLine line in m_roofLines) { if (line.Id == m_footPrintLine.Id) { line.Draw(graphics, highlightPen); } else { line.Draw(graphics, displayPen); } } } } }