Beispiel #1
0
        /// <summary>
        /// Add the oriented edge to the current loop
        /// </summary>
        /// <param name="id">the id of the edge, corresponding to the StepID of the IfcOrientedEdge</param>
        /// <param name="curve">the curve, which represents the geometry of the edge</param>
        /// <param name="startPoint">the start point of the curve</param>
        /// <param name="endPoint">the end point of the curve</param>
        /// <param name="orientation">the orientation of the edge</param>
        /// <returns>true if the edge is successfully added to the boundary</returns>
        public bool AddOrientedEdgeToTheBoundary(int id, Curve curve, XYZ startPoint, XYZ endPoint, bool orientation)
        {
            if (m_CurrentBrepBuilderLoop == null)
            {
                throw new InvalidOperationException("StartCollectingLoopForBrepBuilder hasn't been called");
            }

            BRepBuilderGeometryId edgeId = null;

            if (m_EdgeIdToBrepId.ContainsKey(id) && m_EdgeIdToBrepId[id] != null)
            {
                edgeId = m_EdgeIdToBrepId[id];
            }
            else
            {
                //TODO: create an utility function MakeBound(Curve, XYZ, XYZ) and factor out this code
                BRepBuilderEdgeGeometry edge = null;
                if (curve is Line)
                {
                    edge = BRepBuilderEdgeGeometry.Create(startPoint, endPoint);
                }
                else if (curve is Arc)
                {
                    Arc arc = curve as Arc;

                    // The curve we receive is an unbound arc, so we have to bound it by the startPoint and the endPoint
                    IntersectionResult start = arc.Project(startPoint);
                    IntersectionResult end   = arc.Project(endPoint);

                    double startParameter = start.Parameter;
                    double endParameter   = end.Parameter;

                    if (endParameter < startParameter)
                    {
                        endParameter += Math.PI * 2;
                    }

                    arc.MakeBound(startParameter, endParameter);

                    edge = BRepBuilderEdgeGeometry.Create(arc);
                }
                else if (curve is Ellipse)
                {
                    Ellipse ellipse = curve as Ellipse;

                    IntersectionResult start = ellipse.Project(startPoint);
                    IntersectionResult end   = ellipse.Project(endPoint);

                    double startParameter = start.Parameter;
                    double endParameter   = end.Parameter;

                    if (endParameter < startParameter)
                    {
                        endParameter += Math.PI * 2;
                    }

                    ellipse.MakeBound(startParameter, endParameter);
                    edge = BRepBuilderEdgeGeometry.Create(ellipse);
                }
                else if (curve is NurbSpline)
                {
                    NurbSpline nurbs = curve as NurbSpline;

                    // Bound the NurbSpline based on the start and end points.
                    // As mentioned above, there should be a function to bound
                    // a curve based on two 3D points and it should be used here
                    // instead of duplicating manual code.
                    IntersectionResult start          = nurbs.Project(startPoint);
                    IntersectionResult end            = nurbs.Project(endPoint);
                    double             startParameter = start.Parameter;
                    double             endParameter   = end.Parameter;
                    if (endParameter < startParameter)
                    {
                        Importer.TheLog.LogError(id, "Inverted start/end parameters for NurbSpline.", false /*throwError*/);
                        return(false);
                    }
                    else
                    {
                        nurbs.MakeBound(startParameter, endParameter);
                    }

                    edge = BRepBuilderEdgeGeometry.Create(nurbs);
                }
                else
                {
                    Importer.TheLog.LogError(id, "Unsupported edge curve type: " + curve.GetType().ToString(), false);
                    return(false);
                }

                edgeId = m_BrepBuilder.AddEdge(edge);
                m_EdgeIdToBrepId.Add(id, edgeId);
            }
            try
            {
                m_BrepBuilder.AddCoEdge(m_CurrentBrepBuilderLoop, edgeId, !orientation);
            }
            catch
            {
                return(false);
            }
            return(true);
        }