Example #1
0
        /// <summary>
        /// Get the first curve associated to this IfcGridAxis.
        /// </summary>
        /// <returns>The first curve, or null if there isn't one.</returns>
        /// <remarks>This expected IfcGridAxis to have only one associated curve, but
        /// will warn and return the first curve if there is more than one.</remarks>
        private Curve GetAxisCurve()
        {
            if (!IsValidForCreation)
            {
                return(null);
            }

            IsValidForCreation = false;

            if (AxisCurve == null)
            {
                Importer.TheLog.LogError(Id, "Couldn't find axis curve for grid line, ignoring.", false);
                return(null);
            }

            IList <Curve> curves    = AxisCurve.GetCurves();
            int           numCurves = curves.Count;

            if (numCurves == 0)
            {
                Importer.TheLog.LogError(AxisCurve.Id, "Couldn't find axis curve for grid line, ignoring.", false);
                return(null);
            }

            if (numCurves > 1)
            {
                Importer.TheLog.LogError(AxisCurve.Id, "Found multiple curve segments for grid line, ignoring all but first.", false);
            }

            IsValidForCreation = true;
            return(curves[0]);
        }
Example #2
0
 protected override void setJSON(JObject obj, BaseClassIfc host, SetJsonOptions options)
 {
     base.setJSON(obj, host, options);
     setAttribute(obj, "AxisTag", AxisTag);
     obj["AxisCurve"] = AxisCurve.getJson(this, options);
     obj["SameSense"] = SameSense;
 }
Example #3
0
 internal override void SetXML(XmlElement xml, BaseClassIfc host, HashSet <int> processed)
 {
     base.SetXML(xml, host, processed);
     if (mAxisTag != "$")
     {
         xml.SetAttribute("AxisTag", mAxisTag);
     }
     xml.SetAttribute("SameSense", mSameSense.ToString().ToLower());
     xml.AppendChild(AxisCurve.GetXML(xml.OwnerDocument, "AxisCurve", this, processed));
 }
Example #4
0
        public override string GetStepParameters()
        {
            var parameters = new List <string>();

            parameters.Add(AxisTag != null ? AxisTag.ToStepValue() : "$");
            parameters.Add(AxisCurve != null ? AxisCurve.ToStepValue() : "$");
            parameters.Add(SameSense != null ? SameSense.ToStepValue() : "$");

            return(string.Join(", ", parameters.ToArray()));
        }
Example #5
0
        private int FindMatchingGrid(IList <Curve> otherCurves, int id, ref IList <Curve> curves, ref int curveCount)
        {
            if (curves == null)
            {
                curves     = AxisCurve.GetCurves();
                curveCount = curves.Count;
            }

            // Check that the base curves are the same type.
            int otherCurveCount = otherCurves.Count;

            if (curveCount != otherCurveCount)
            {
                return(-1);
            }

            bool sameCurves = true;

            for (int ii = 0; (ii < curveCount) && sameCurves; ii++)
            {
                if ((curves[ii] is Line) && (otherCurves[ii] is Line))
                {
                    sameCurves = AreLinesEqual(curves[ii] as Line, otherCurves[ii] as Line);
                }
                else if ((curves[ii] is Arc) && (otherCurves[ii] is Arc))
                {
                    sameCurves = AreArcsEqual(curves[ii] as Arc, otherCurves[ii] as Arc);
                }
                else
                {
                    // No supported.
                    sameCurves = false;
                }
            }

            return(sameCurves ? id : -1);
        }
        internal Curve Curve(double tol)
        {
            Curve c = AxisCurve.Curve(tol);

            if (c == null)
            {
                return(null);
            }
            IfcGrid grid = mPartOfU;

            if (grid == null)
            {
                grid = mPartOfV;
            }
            if (grid == null)
            {
                grid = mPartOfW;
            }
            if (grid != null)
            {
                c.Transform(grid.PlacementTransform());
            }
            return(c);
        }
Example #7
0
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="lcs">The local coordinate system transform.</param>
        public void Create(Document doc, Transform lcs)
        {
            if (!IsValidForCreation)
            {
                return;
            }

            // These are hardwired values to ensure that the Grid is visible in the
            // current view, in feet.  Note that there is an assumption that building stories
            // would not be placed too close to one another; if they are, and they use different
            // grid structures, then the plan views may have overlapping grid lines.  This seems
            // more likely in theory than practice.
            const double bottomOffset = -1.0 / 12.0; // 1" =   2.54 cm
            const double topOffset    = 4.0;         // 4' = 121.92 cm

            double originalZ = (lcs != null) ? lcs.Origin.Z : 0.0;

            if (CreatedElementId != ElementId.InvalidElementId)
            {
                Grid existingGrid = doc.GetElement(CreatedElementId) as Grid;
                if (existingGrid != null)
                {
                    Outline outline = existingGrid.GetExtents();
                    existingGrid.SetVerticalExtents(Math.Min(originalZ - bottomOffset, outline.MinimumPoint.Z),
                                                    Math.Max(originalZ + topOffset, outline.MaximumPoint.Z));
                }
                return;
            }

            if (AxisCurve == null)
            {
                Importer.TheLog.LogError(Id, "Couldn't find axis curve for grid line, ignoring.", false);
                IsValidForCreation = false;
                return;
            }

            IList <Curve> curves    = AxisCurve.GetCurves();
            int           numCurves = curves.Count;

            if (numCurves == 0)
            {
                Importer.TheLog.LogError(AxisCurve.Id, "Couldn't find axis curve for grid line, ignoring.", false);
                IsValidForCreation = false;
                return;
            }

            if (numCurves > 1)
            {
                Importer.TheLog.LogError(AxisCurve.Id, "Found multiple curve segments for grid line, ignoring all but first.", false);
            }

            Grid grid = null;

            Curve curve = curves[0].CreateTransformed(lcs);

            if (curve == null)
            {
                Importer.TheLog.LogError(AxisCurve.Id, "Couldn't create transformed axis curve for grid line, ignoring.", false);
                IsValidForCreation = false;
                return;
            }

            if (!curve.IsBound)
            {
                curve.MakeBound(-100, 100);
                Importer.TheLog.LogWarning(AxisCurve.Id, "Creating arbitrary bounds for unbounded grid line.", false);
            }

            // Grid.create can throw, so catch the exception if it does.
            try
            {
                if (curve is Arc)
                {
                    // This will potentially make a small modification in the curve if it is unbounded,
                    // as Revit doesn't allow unbounded grid lines.
                    grid = CreateArcGridAxis(doc, curve as Arc);
                }
                else if (curve is Line)
                {
                    grid = Grid.Create(doc, curve as Line);
                }
                else
                {
                    Importer.TheLog.LogError(AxisCurve.Id, "Couldn't create grid line from curve of type " + curve.GetType().ToString() + ", expected line or arc.", false);
                    IsValidForCreation = false;
                    return;
                }
            }
            catch (Exception ex)
            {
                Importer.TheLog.LogError(AxisCurve.Id, ex.Message, false);
                IsValidForCreation = false;
                return;
            }

            if (grid != null)
            {
                SetAxisTagUnique(grid, AxisTag);

                // We will try to "grid match" as much as possible to avoid duplicate grid lines.  As such,
                // we want the remaining grid lines to extend to the current level.
                // A limitation here is that if a grid axis in the IFC file were visible on Level 1 and Level 3
                // but not Level 2, this will make it visibile on Level 2 also.  As above, this seems
                // more likely in theory than practice.
                grid.SetVerticalExtents(originalZ - bottomOffset, originalZ + topOffset);

                CreatedElementId = grid.Id;
            }
        }
Example #8
0
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="lcs">The local coordinate system transform.</param>
        public void Create(Document doc, Transform lcs)
        {
            if (!IsValidForCreation)
            {
                return;
            }

            double originalZ = (lcs != null) ? lcs.Origin.Z : 0.0;

            if (CreatedElementId != ElementId.InvalidElementId)
            {
                return;
            }

            if (AxisCurve == null)
            {
                Importer.TheLog.LogError(Id, "Couldn't find axis curve for grid line, ignoring.", false);
                IsValidForCreation = false;
                return;
            }

            IList <Curve> curves    = AxisCurve.GetCurves();
            int           numCurves = curves.Count;

            if (numCurves == 0)
            {
                Importer.TheLog.LogError(AxisCurve.Id, "Couldn't find axis curve for grid line, ignoring.", false);
                IsValidForCreation = false;
                return;
            }

            if (numCurves > 1)
            {
                Importer.TheLog.LogError(AxisCurve.Id, "Found multiple curve segments for grid line, ignoring all but first.", false);
            }

            Grid grid = null;

            Curve curve = curves[0].CreateTransformed(lcs);

            if (curve == null)
            {
                Importer.TheLog.LogError(AxisCurve.Id, "Couldn't create transformed axis curve for grid line, ignoring.", false);
                IsValidForCreation = false;
                return;
            }

            if (!curve.IsBound)
            {
                curve.MakeBound(-100, 100);
                Importer.TheLog.LogWarning(AxisCurve.Id, "Creating arbitrary bounds for unbounded grid line.", false);
            }

            // Grid.create can throw, so catch the exception if it does.
            try
            {
                if (curve is Arc)
                {
                    // This will potentially make a small modification in the curve if it is unbounded,
                    // as Revit doesn't allow unbounded grid lines.
                    grid = CreateArcGridAxis(doc, curve as Arc);
                }
                else if (curve is Line)
                {
                    grid = doc.Create.NewGrid(curve as Line);
                }
                else
                {
                    Importer.TheLog.LogError(AxisCurve.Id, "Couldn't create grid line from curve of type " + curve.GetType().ToString() + ", expected line or arc.", false);
                    IsValidForCreation = false;
                    return;
                }
            }
            catch (Exception ex)
            {
                Importer.TheLog.LogError(AxisCurve.Id, ex.Message, false);
                IsValidForCreation = false;
                return;
            }

            if (grid != null)
            {
                SetAxisTagUnique(grid, AxisTag);

                CreatedElementId = grid.Id;
            }
        }
Example #9
0
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="lcs">The local coordinate system transform.</param>
        public void Create(Document doc, Transform lcs)
        {
            if (!IsValidForCreation)
            {
                return;
            }

            double originalZ = (lcs != null) ? lcs.Origin.Z : 0.0;

            if (CreatedElementId != ElementId.InvalidElementId)
            {
                return;
            }

            if (AxisCurve == null)
            {
                IFCImportFile.TheLog.LogError(Id, "Couldn't find axis curve for grid line, ignoring.", false);
                IsValidForCreation = false;
                return;
            }

            IList <Curve> curves    = AxisCurve.GetCurves();
            int           numCurves = curves.Count;

            if (numCurves == 0)
            {
                IFCImportFile.TheLog.LogError(AxisCurve.Id, "Couldn't find axis curve for grid line, ignoring.", false);
                IsValidForCreation = false;
                return;
            }

            if (numCurves > 1)
            {
                IFCImportFile.TheLog.LogError(AxisCurve.Id, "Found multiple curve segments for grid line, ignoring all but first.", false);
            }

            Grid grid = null;

            Curve curve = curves[0].CreateTransformed(lcs);

            if (curve == null)
            {
                IFCImportFile.TheLog.LogError(AxisCurve.Id, "Couldn't create transformed axis curve for grid line, ignoring.", false);
                IsValidForCreation = false;
                return;
            }

            if (curve is Arc)
            {
                grid = doc.Create.NewGrid(curve as Arc);
            }
            else if (curve is Line)
            {
                grid = doc.Create.NewGrid(curve as Line);
            }
            else
            {
                IFCImportFile.TheLog.LogError(AxisCurve.Id, "Couldn't create grid line from curve of type " + curve.GetType().ToString() + ", expected line or arc.", false);
                IsValidForCreation = false;
            }

            if (grid != null)
            {
                if (AxisTag != null)
                {
                    int counter = 1;
                    do
                    {
                        try
                        {
                            grid.Name = (counter == 1) ? AxisTag : AxisTag + "-" + counter;
                            break;
                        }
                        catch
                        {
                            counter++;
                        }
                    }while (counter < 500);

                    if (counter >= 500)
                    {
                        IFCImportFile.TheLog.LogWarning(Id, "Couldn't set name: '" + AxisTag + "' for Grid, reverting to default.", false);
                    }
                }

                CreatedElementId = grid.Id;
            }
        }