Esempio n. 1
0
        //--------------------------------------------------------------------------------------------------

        public static bool RenderEdge(IDrawingRenderer renderer, TopoDS_Edge edge, bool reverse, TopoDS_Face face)
        {
            var res = true;

            reverse ^= edge.Orientation() == TopAbs_Orientation.TopAbs_REVERSED;

            double first = 0, last = 0;

            if (face != null)
            {
                var curve = BRep_Tool.CurveOnSurface(edge, new Geom_Plane(Ax3.XOY), new TopLoc_Location(), ref first, ref last);
                if (curve == null)
                {
                    return(false);
                }

                res &= RenderCurve(renderer, curve, first, last, reverse);
            }
            else
            {
                if (!(edge.TShape() is BRep_TEdge tedge))
                {
                    return(res);
                }

                var curves = tedge.CurvesList();
                if (reverse)
                {
                    curves.Reverse();
                }

                foreach (var curveOnSurface in curves.OfType <BRep_CurveOnSurface>())
                {
                    var curve = curveOnSurface.PCurve();
                    first = curveOnSurface.First();
                    last  = curveOnSurface.Last();
                    res  &= RenderCurve(renderer, curve, first, last, reverse);
                }
            }

            return(res);
        }
Esempio n. 2
0
        //--------------------------------------------------------------------------------------------------

        void _ExportEdge(TopoDS_Edge edge, bool reverse, TopoDS_Face face)
        {
            reverse ^= edge.Orientation() == TopAbs_Orientation.TopAbs_REVERSED;

            double first = 0, last = 0;

            if (face != null)
            {
                var curve = BRep_Tool.CurveOnSurface(edge, new Geom_Plane(Ax3.XOY), new TopLoc_Location(), ref first, ref last);
                if (curve == null)
                {
                    return;
                }

                AddCurve(curve, reverse, first, last);
            }
            else
            {
                var tedge = edge.TShape() as BRep_TEdge;
                if (tedge == null)
                {
                    return;
                }

                var curves = tedge.CurvesList();
                if (reverse)
                {
                    curves.Reverse();
                }

                foreach (var curveOnSurface in curves.Cast <BRep_CurveOnSurface>())
                {
                    var curve = curveOnSurface.PCurve();
                    first = curveOnSurface.First();
                    last  = curveOnSurface.Last();
                    AddCurve(curve, reverse, first, last);
                }
            }
        }
Esempio n. 3
0
        //--------------------------------------------------------------------------------------------------

        void _ExportLayer(VectorExportLayer layer)
        {
            _Document.Layers.Add(new DxfDomLayer(layer.Name, _Lineweights[layer.Type], layer.Type.ToString()));
            _CurrentLayer = layer.Name;

            foreach (var edge in layer.BRep.Edges())
            {
                var tedge = edge.TShape() as BRep_TEdge;
                if (tedge == null)
                {
                    return;
                }

                var curves = tedge.CurvesList();
                foreach (var curve in curves)
                {
                    Geom2d_Curve        geomCurve;
                    double              first          = 0;
                    double              last           = 0;
                    BRep_CurveOnSurface curveOnSurface = curve as BRep_CurveOnSurface;
                    if (curveOnSurface != null)
                    {
                        geomCurve = curveOnSurface.PCurve();
                        first     = curveOnSurface.First();
                        last      = curveOnSurface.Last();
                    }
                    else
                    {
                        geomCurve = BRep_Tool.CurveOnSurface(edge, new Geom_Plane(Ax3.XOY), new TopLoc_Location(), ref first, ref last);
                    }

                    if (geomCurve != null)
                    {
                        _AddCurve(geomCurve, first, last);
                    }
                }
            }
        }
Esempio n. 4
0
        //--------------------------------------------------------------------------------------------------

        public static bool ComputeAxisFromEdge(TopoDS_Face face, TopoDS_Edge edge, double parameter, out Ax1 axis)
        {
            axis = new Ax1();

            // Get edge point and tangent
            var adaptorEdge = edge.Adaptor();
            var edgeFirst   = adaptorEdge.FirstParameter();
            var edgeLast    = adaptorEdge.LastParameter();
            var centerParam = parameter.Clamp(edgeFirst, edgeLast);
            Pnt centerPoint = Pnt.Origin;
            Vec edgeTangent = Vec.Zero;

            adaptorEdge.D1(centerParam, ref centerPoint, ref edgeTangent);

            if (edge.Orientation() == TopAbs_Orientation.TopAbs_REVERSED)
            {
                edgeTangent.Reverse();
            }

            // Get normal at point of edge
            double first = 0, last = 0;
            var    curveOnSurface = BRep_Tool.CurveOnSurface(edge, face, ref first, ref last);

            if (curveOnSurface == null)
            {
                return(false);
            }

            var paramNormalized = (centerParam - edgeFirst) / (edgeLast - edgeFirst);
            var centerUV        = curveOnSurface.Value(first + (last - first) * paramNormalized);
            Vec faceNormal      = Vec.Zero;

            new BRepGProp_Face(face).Normal(centerUV.X, centerUV.Y, ref centerPoint, ref faceNormal);

            axis = new Ax1(centerPoint, faceNormal.ToDir().Crossed(edgeTangent.ToDir()));
            return(true);
        }