Пример #1
0
        //--------------------------------------------------------------------------------------------------

        MemoryStream _Export(Drawing drawing, DxfVersion version, DxfFlags flags, double precision)
        {
            _Precision = precision;
            _Document  = new DxfDomDocument(version, flags);

            // Export
            drawing.Render(this);

            var stream = _Document.WriteToStream();

            _Document = null;
            return(stream);
        }
Пример #2
0
        //--------------------------------------------------------------------------------------------------

        MemoryStream _Export(Sketch sketch, DxfVersion version, DxfFlags flags, double precision)
        {
            _Sketch    = sketch;
            _Precision = precision;
            _Document  = new DxfDomDocument(version, flags);

            foreach (var segment in _Sketch.Segments.Values)
            {
                switch (segment)
                {
                case SketchSegmentLine line:
                    _AddLineSegment(line);
                    break;

                case SketchSegmentCircle circle:
                    _AddCircleSegment(circle);
                    break;

                case SketchSegmentArc arc:
                    _AddArcSegment(arc);
                    break;

                case SketchSegmentEllipse ellipse:
                    _AddEllipseSegment(ellipse);
                    break;

                case SketchSegmentEllipticalArc ellipArc:
                    _AddEllipticalArcSegment(ellipArc);
                    break;

                case SketchSegmentBezier bezier:
                    _AddBezierSegment(bezier);
                    break;
                }
            }

            var stream = _Document.WriteToStream();

            _Document = null;
            return(stream);
        }
Пример #3
0
        //--------------------------------------------------------------------------------------------------

        #endregion

        #region Importer

        bool _Import(Stream stream, out IDictionary <int, Pnt2d> points, out IDictionary <int, SketchSegment> segments,
                     DxfFlags flags, double precision, double scale)
        {
            points   = null;
            segments = null;

            try
            {
                _MergePrecision = precision;
                _Document       = new DxfDomDocument(DxfVersion.Latest, flags);
                if (!_Document.ReadFromStream(stream, scale))
                {
                    Messages.Error("DxfImporter: The DXF document is invalid or does not contain any importable entities.");
                    _Document = null;
                    return(false);
                }

                // Iterate through children
                foreach (var entity in _Document.Entities)
                {
                    _ImportEntity(entity);
                }

                if (_Segments.Count == 0)
                {
                    Messages.Error("DxfImporter: Could not find any usable elements in DXF data.");
                    return(false);
                }

                points   = _Points;
                segments = _Segments.ToIndexedDictionary();
                return(true);
            }
            catch (Exception e)
            {
                Messages.Exception("DxfImporter: An exception occured while importing the dxf file.", e);
                return(false);
            }
        }