/// <inheritdoc/>
        void Core2D.Interfaces.IProjectExporter.Save(string path, Core2D.Project.XProject project)
        {
            _outputPath = System.IO.Path.GetDirectoryName(path);
            var dxf = new DxfDocument(DxfVersion.AutoCad2010);

            Add(dxf, project);

            dxf.Save(path);
            ClearCache(isZooming: false);
        }
        public Drawing ReadDrawing(string dxfFileName, Canvas canvas)
        {
            doc = new DxfDocument();
            doc.Load(dxfFileName);

            drawing = new Drawing(canvas);

            ReadLines();
            ReadPolylines();
            ReadArcs();
            ReadCircles();
            ReadInserts();

            drawing.Recalculate();
            return drawing;
        }
        private void Add(DxfDocument dxf, Core2D.Project.XDocument document)
        {
            foreach (var page in document.Pages)
            {
                var layout = new Layout(page.Name)
                {
                    PlotSettings = new PlotSettings()
                    {
                        PaperSizeName = $"{page.Template.Name}_({page.Template.Width}_x_{page.Template.Height}_MM)",
                        LeftMargin = 0.0,
                        BottomMargin = 0.0,
                        RightMargin = 0.0,
                        TopMargin = 0.0,
                        PaperSize = new Vector2(page.Template.Width, page.Template.Height),
                        Origin = new Vector2(0.0, 0.0),
                        PaperUnits = PlotPaperUnits.Milimeters,
                        PaperRotation = PlotRotation.NoRotation
                    }
                };
                dxf.Layouts.Add(layout);
                dxf.ActiveLayout = layout.Name;

                Add(dxf, page);
            }
        }
Beispiel #4
0
        void ButtonLoadDXFClick(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = @"C:\";
            openFileDialog1.Title = "Browse DXF Files";
            openFileDialog1.DefaultExt = "dxf";
            openFileDialog1.Filter = "DXF files (*.dxf)|*.dxf|All files (*.*)|*.*";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    dxfdata = DXFlibCS.LoadDXF(openFileDialog1.FileName);
                }
                catch
                {
                    dxfdata =null;
                }
                if (dxfdata==null)
                {
                    MessageBox.Show("netDXF extraction from DXF failed, trying line by line.");
                    dxfdata = DXFlibCS.LineByLineLoader(openFileDialog1.FileName);

                }
                if (dxfdata==null)
                {
                    MessageBox.Show("Line by line processing failed");
                }

                labelEntities.Text = "Entities: " + DXFlibCS.entity_count.ToString();
                labelfilename.Text = "Filename: "+ openFileDialog1.FileName;
            }
        }
        public Grid GetMainGrid(netDxf.DxfDocument dxfFile, bool avecGrille, bool avecOrigine, Color bgColor)
        {
            mainCanvas.Children.Clear();
            DrawEntities.RazMaxDim();
            DrawEntities.AddNewMaxDim();


            mainGrid.HorizontalAlignment = HorizontalAlignment.Stretch;
            mainGrid.VerticalAlignment   = VerticalAlignment.Stretch;
            mainGrid.Background          = new SolidColorBrush(bgColor);

            border.Height     = GridHeight;
            border.Width      = GridWidth;
            border.Background = new SolidColorBrush(bgColor);


            mainCanvas.Name = "mainCanvas";
            if (DxfDoc.DrawingVariables.AcadVer < netDxf.Header.DxfVersion.AutoCad2000)
            {
                DrawUtils.DrawText("Le format du fichier doit être dxf2000 ou supérieur.", 10, Colors.Red, 20, 50, mainCanvas);
            }
            GetCanvas(DxfDoc, mainCanvas);

            if (avecOrigine == true)
            {
                DrawEntities.AddNewMaxDim();
                DrawUtils.DrawOrigin(mainCanvas);
                DrawEntities.DeleteLastMaxDim();
            }

            if (avecGrille == true)
            {
                Canvas bgCanvas = new Canvas();
                if (border.Child == null)
                {
                    bgCanvas = CreateBgCanvas();
                    bgCanvas.Children.Add(mainCanvas);

                    border.Child = bgCanvas;
                }
            }
            else
            {
                border.Child = mainCanvas;
            }

            Canvas.SetTop(mainCanvas, GridHeight / 2);
            Canvas.SetLeft(mainCanvas, GridWidth / 2);

            //border.Reset(GridHeight,GridWidth,true,ViewHeight,ViewWidth,WinHeight,WinWidth);



            if (mainGrid.Children.Count == 0)
            {
                mainGrid.Children.Add(border);
            }

            return(mainGrid);
        }
Beispiel #6
0
        private void Add(DXF.DxfDocument dxf, IDocumentContainer document)
        {
            foreach (var page in document.Pages)
            {
                var layout = new DXFO.Layout(page.Name)
                {
                    PlotSettings = new DXFO.PlotSettings()
                    {
                        PaperSizeName = $"{page.Template.Name}_({page.Template.Width}_x_{page.Template.Height}_MM)",
                        LeftMargin    = 0.0,
                        BottomMargin  = 0.0,
                        RightMargin   = 0.0,
                        TopMargin     = 0.0,
                        PaperSize     = new DXF.Vector2(page.Template.Width, page.Template.Height),
                        Origin        = new DXF.Vector2(0.0, 0.0),
                        PaperUnits    = DXFO.PlotPaperUnits.Milimeters,
                        PaperRotation = DXFO.PlotRotation.NoRotation
                    }
                };
                dxf.Layouts.Add(layout);
                dxf.ActiveLayout = layout.Name;

                Add(dxf, page);
            }
        }
Beispiel #7
0
 private void Add(DXF.DxfDocument dxf, IProjectContainer project)
 {
     foreach (var document in project.Documents)
     {
         Add(dxf, document);
     }
 }
Beispiel #8
0
        /// <summary>
        /// 绘制风扇
        /// </summary>
        /// <param name="dxf"></param>
        /// <param name="startPoint">风扇起点,如果为横置,由左向右;如果为竖置,由下到上</param>
        /// <param name="endPoint">风扇终点,如果为横置,由左向右;如果为竖置,由下到上</param>
        /// <param name="pointerLocation">箭头位置,默认=0为无,=1代表箭头在中间,=2代表箭头在底部</param>
        public static void Draw(DxfDocument dxf, Vector3f startPoint, Vector3f endPoint,int pointerLocation=0)
        {
            Layer layer = new Layer("line");
            Line line = new Line(startPoint, endPoint);
            line.Layer = layer;
            dxf.AddEntity(line);

            //如果为横置
            if (startPoint.Y == endPoint.Y)
            {
                float segment = (endPoint.X - startPoint.X) / 4;
                Slash.Draw(dxf, new Location(startPoint.X + segment, startPoint.Y, startPoint.Z));
                Slash.Draw(dxf, new Location(startPoint.X + 2 * segment, startPoint.Y, startPoint.Z));
                Slash.Draw(dxf, new Location(startPoint.X + 3 * segment, startPoint.Y, startPoint.Z));
            }
            //如果为竖置
            else if (startPoint.X == endPoint.X)
            {
                float segment = (endPoint.Y - startPoint.Y) / 5;
                Slash.Draw(dxf, new Location(startPoint.X, startPoint.Y + segment, startPoint.Z));
                Slash.Draw(dxf, new Location(startPoint.X, startPoint.Y + 2 * segment, startPoint.Z));
                Slash.Draw(dxf, new Location(startPoint.X, startPoint.Y + 3 * segment, startPoint.Z));
                Slash.Draw(dxf, new Location(startPoint.X, startPoint.Y + 4 * segment, startPoint.Z));
                if (pointerLocation == 1)
                {
                    LinePointer.Draw(dxf,new Location(startPoint.X,(startPoint.Y+endPoint.Y)/2,startPoint.Z));
                }
                else if(pointerLocation==2)
                {
                    LinePointer.Draw(dxf, new Location(startPoint.X, startPoint.Y, startPoint.Z));
                }
            }
        }
Beispiel #9
0
 public Grid GetMainGrid(bool avecGrille, bool avecOrigine)
 {
     if (DxfDoc == null)
     {
         DxfDoc = new DxfDocument();
     }
     return(GetMainGrid(DxfDoc, avecGrille, avecOrigine, Window_bgColor));
 }
Beispiel #10
0
        protected override Task _save()
        {
            RecordSet layer = _layer as RecordSet;

            layer.Position           = transform.position.ToPoint();
            layer.Transform.Position = Vector3.zero;
            layer.Transform.Rotate   = transform.rotation;
            layer.Transform.Scale    = transform.localScale;
            EditableMesh[] meshes = GetComponentsInChildren <EditableMesh>();
            string         ex     = Path.GetExtension(layer.Source).ToLower();

            features = new List <DMesh3>();
            foreach (EditableMesh mesh in meshes)
            {
                features.Add(mesh.GetMesh());
            }
            if (ex == ".obj")
            {
                List <WriteMesh> wmeshes = new List <WriteMesh>();
                foreach (DMesh3 dmesh in features)
                {
                    DMesh3 mesh = new DMesh3(dmesh);
                    foreach (int idx in mesh.VertexIndices())
                    {
                        Vector3d vtx = mesh.GetVertex(idx);
                        mesh.SetVertex(idx, new Vector3d(vtx.x, vtx.z, vtx.y));
                    }
                    wmeshes.Add(new WriteMesh(mesh, ""));
                }
                saveObj(layer.Source, wmeshes);
            }
            if (ex == ".dxf")
            {
                DXF.DxfDocument          doc       = new DXF.DxfDocument();
                CoordinateTransformation transform = null;
                if (GetCrs() != null)
                {
                    transform = new CoordinateTransformation(AppState.instance.mapProj, GetCrs());
                }
                foreach (DMesh3 dmesh in features)
                {
                    foreach (Index3i tri in dmesh.Triangles())
                    {
                        DXF.Vector3 v1 = dmesh.GetVertex(tri.a).ToDxfVector3(transform);
                        DXF.Vector3 v2 = dmesh.GetVertex(tri.b).ToDxfVector3(transform);
                        DXF.Vector3 v3 = dmesh.GetVertex(tri.c).ToDxfVector3(transform);
                        doc.AddEntity(new Face3d(v1, v2, v3));
                    }
                }
                using (Stream stream = File.Open(layer.Source, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite)) {
                    doc.Save(stream);
                    stream.Close();
                }
            }
            return(Task.CompletedTask);
        }
Beispiel #11
0
        public static void Draw(DxfDocument dxf, Location location)
        {
            Vector3f v1 = new Vector3f(location.X - 2.0f, location.Y - 4.0f, location.Z);
            Vector3f v2 = new Vector3f(location.X + 2.0f, location.Y + 4.0f, location.Z);
            Layer layer = new Layer("line");

            Line line12 = new Line(v1, v2);
            line12.Layer = layer;
            dxf.AddEntity(line12);
        }
Beispiel #12
0
        /// <inheritdoc/>
        void IProjectExporter.Save(string path, IProjectContainer project)
        {
            _outputPath = System.IO.Path.GetDirectoryName(path);
            var dxf = new DXF.DxfDocument(DXFH.DxfVersion.AutoCad2010);

            Add(dxf, project);

            dxf.Save(path);
            ClearCache(isZooming: false);
        }
Beispiel #13
0
        /// <summary>
        /// 风向绘制
        /// </summary>
        /// <param name="dxf"></param>
        /// <param name="location"></param>
        /// <param name="isRight"></param>
        public static void Draw(DxfDocument dxf, Location location, bool isRight)
        {
            float factor = 0.5f;
            Vector3f v1 = new Vector3f();
            Vector3f v2 = new Vector3f();
            Vector3f v3 = new Vector3f();
            Vector3f v4 = new Vector3f();
            Vector3f v5 = new Vector3f();
            Vector3f v6 = new Vector3f();
            Vector3f v7 = new Vector3f();
            if (isRight)
            {
                v1 = new Vector3f(10*factor + location.X, location.Y, location.Z);
                v2 = new Vector3f(location.X, location.Y + 10 * factor, location.Z);
                v3 = new Vector3f(location.X + 10 * factor, location.Y + 10 * factor, location.Z);
                v4 = new Vector3f(location.X + 20 * factor, location.Y + 15 * factor, location.Z);
                v5 = new Vector3f(location.X, location.Y + 20 * factor, location.Z);
                v6 = new Vector3f(location.X + 10 * factor, location.Y + 20 * factor, location.Z);
                v7 = new Vector3f(location.X + 10 * factor, location.Y + 30 * factor, location.Z);
            }
            else
            {
                v1 = new Vector3f(10 * factor + location.X, location.Y, location.Z);
                v2 = new Vector3f(location.X + 20 * factor, location.Y + 10 * factor, location.Z);
                v3 = new Vector3f(location.X + 10 * factor, location.Y + 10 * factor, location.Z);
                v4 = new Vector3f(location.X, location.Y + 15 * factor, location.Z);
                v5 = new Vector3f(location.X + 20 * factor, location.Y + 20 * factor, location.Z);
                v6 = new Vector3f(location.X + 10 * factor, location.Y + 20 * factor, location.Z);
                v7 = new Vector3f(location.X + 10 * factor, location.Y + 30 * factor, location.Z);
            }
            Layer layer = new Layer("line");
            Line line23 = new Line(v2, v3);
            line23.Layer = layer;
            dxf.AddEntity(line23);

            Line line56 = new Line(v5, v6);
            line56.Layer = layer;
            dxf.AddEntity(line56);

            Line line14 = new Line(v1, v4);
            line14.Layer = layer;
            dxf.AddEntity(line14);

            Line line74 = new Line(v7, v4);
            line74.Layer = layer;
            dxf.AddEntity(line74);

            Line line25 = new Line(v2, v5);
            line25.Layer = layer;
            dxf.AddEntity(line25);

            Line line71 = new Line(v7, v1);
            line71.Layer = layer;
            dxf.AddEntity(line71);
        }
Beispiel #14
0
 public TopViewConfigure(List<PictureBoxInfo> imageNameList, DxfDocument dxf, string[] text, float height, float width, float outer_mid_space, float outer_in_space, float barHeight, float barWidth)
 {
     this.imageNameList = imageNameList;
     this.dxf = dxf;
     this.text = text;
     this.height = height;
     this.width = width;
     this.outer_mid_space = outer_mid_space;
     this.outer_in_space = outer_in_space;
     this.barHeight = barHeight;
     this.barWidth = barWidth;
 }
Beispiel #15
0
        public static DxfDocument generateDXF(StructuralModel structure)
        {
            var dxf = new netDxf.DxfDocument();

            var ColumnLayer = new netDxf.Tables.Layer("Column")
            {
                Color      = netDxf.AciColor.Red,
                Lineweight = netDxf.Lineweight.W50
            };
            var SlabLayer = new netDxf.Tables.Layer("Slab")
            {
                Color      = netDxf.AciColor.Yellow,
                Lineweight = netDxf.Lineweight.W50
            };
            var OpeningLayer = new netDxf.Tables.Layer("Opening")
            {
                Color      = netDxf.AciColor.Blue,
                Lineweight = netDxf.Lineweight.W50
            };
            var WallLayer = new netDxf.Tables.Layer("Wall")
            {
                Color      = netDxf.AciColor.Green,
                Lineweight = netDxf.Lineweight.W50
            };

            dxf.Layers.Add(ColumnLayer);
            dxf.Layers.Add(SlabLayer);
            dxf.Layers.Add(OpeningLayer);
            dxf.Layers.Add(WallLayer);

            foreach (var item in structure.Columns)
            {
                dxf.AddEntity(getPolylineFromPoints(item.Points, ColumnLayer));
            }
            foreach (var item in structure.Slabs)
            {
                dxf.AddEntity(getPolylineFromPoints(item.Points, SlabLayer));
            }
            foreach (var item in structure.Walls)
            {
                dxf.AddEntity(getPolylineFromPoints(item.Points, WallLayer, false));
            }
            foreach (var item in structure.Openings)
            {
                dxf.AddEntity(getPolylineFromPoints(item.Points, OpeningLayer));
            }

            return(dxf);
        }
        private void Add(DxfDocument dxf, Core2D.Project.XContainer container)
        {
            if (container.Template != null)
            {
                _pageWidth = container.Template.Width;
                _pageHeight = container.Template.Height;
                Draw(dxf, container.Template, 0.0, 0.0, container.Data.Properties, container.Data.Record);
            }
            else
            {
                throw new NullReferenceException("Container template must be set.");
            }

            Draw(dxf, container, 0.0, 0.0, container.Data.Properties, container.Data.Record);
        }
Beispiel #17
0
        private void Add(DXF.DxfDocument dxf, IPageContainer container)
        {
            if (container.Template != null)
            {
                _pageWidth  = container.Template.Width;
                _pageHeight = container.Template.Height;
                Draw(dxf, container.Template, 0.0, 0.0, (object)container.Data.Properties, (object)container.Data.Record);
            }
            else
            {
                throw new NullReferenceException("Container template must be set.");
            }

            Draw(dxf, container, 0.0, 0.0, (object)container.Data.Properties, (object)container.Data.Record);
        }
Beispiel #18
0
        /// <inheritdoc/>
        public void Save(Stream stream, IProjectContainer project)
        {
            if (stream is FileStream fileStream)
            {
                _outputPath = System.IO.Path.GetDirectoryName(fileStream.Name);
            }
            else
            {
                _outputPath = string.Empty;
            }

            var dxf = new DXF.DxfDocument(DXFH.DxfVersion.AutoCad2010);

            Add(dxf, project);

            dxf.Save(stream);
            ClearCache(isZooming: false);
        }
Beispiel #19
0
        static void DxfKitTimeline()
        {
            var dxf = new netDxf.DxfDocument();

            var ents = dxf.DrawTimeline(new List <(DateTime from, DateTime to)>()
            {
                (new DateTime(2000, 1, 1), new DateTime(2001, 7, 31)),
                (new DateTime(2004, 2, 1), new DateTime(2007, 4, 28)),
                (new DateTime(2007, 4, 1), new DateTime(2008, 12, 31)),
                (new DateTime(2008, 8, 1), new DateTime(2012, 10, 31)),
                (new DateTime(2012, 11, 1), new DateTime(2015, 10, 31)),
                (new DateTime(2016, 4, 1), new DateTime(2017, 12, 31))
            });

            dxf.AddEntities(ents);

            dxf.Viewport.ShowGrid = false;
            dxf.Save(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "timeline.dxf"), isBinary: true);
        }
Beispiel #20
0
        private void Add(DXF.DxfDocument dxf, IPageContainer container)
        {
            var dataFlow = _serviceProvider.GetService <IDataFlow>();
            var db       = (object)container.Data.Properties;
            var record   = (object)container.Data.Record;

            dataFlow.Bind(container.Template, db, record);
            dataFlow.Bind(container, db, record);

            if (container.Template != null)
            {
                _pageWidth  = container.Template.Width;
                _pageHeight = container.Template.Height;
                Draw(dxf, container.Template, 0.0, 0.0);
            }
            else
            {
                throw new NullReferenceException("Container template must be set.");
            }

            Draw(dxf, container, 0.0, 0.0);
        }
Beispiel #21
0
        public static void Draw(DxfDocument dxf, Location location,List<string> configurations)
        {
            Vector3f confStrVector3f = new Vector3f(location.X + 5.0f, location.Y - 5.0f, location.Z);
            TextStyle style = new TextStyle("True type font", "Arial.ttf");
            Text text1 = new Text("CONFIGURATION:                   NOTE:  Assembly drawing for overall dimesions,  actual door size and handle position may vary",
                confStrVector3f, 2.0f, style);
            Layer layer = new Layer("text");
            text1.Layer = layer;
            //text1.Layer.Color.Index = 8;
            text1.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(text1);

            for (int i = 0; i < configurations.Count(); i++)
            {
                Vector3f confVector3f = new Vector3f(location.X+10.0f, location.Y - 5.0f * (i + 2), location.Z);
                Text text = new Text(configurations[i], confVector3f, 2.0f, style);
                text.Layer = layer;
                //text.Layer.Color.Index = 8;
                text.Alignment = TextAlignment.TopLeft;
                dxf.AddEntity(text);
            }
        }
Beispiel #22
0
        private void DrawGridInternal(DxfDocument doc, Layer layer, Test2d.ShapeStyle style, double offsetX, double offsetY, double cellWidth, double cellHeight, ref Test2d.Rect2 rect)
        {
            var stroke = GetColor(style.Stroke);
            var strokeTansparency = GetTransparency(style.Stroke);
            var lineweight = ThicknessToLineweight(style.Thickness);

            double ox = rect.X;
            double oy = rect.Y;
            double sx = ox + offsetX;
            double sy = oy + offsetY;
            double ex = ox + rect.Width;
            double ey = oy + rect.Height;

            for (double gx = sx; gx < ex; gx += cellWidth)
            {
                var dxfLine = CreateLine(gx, oy, gx, ey);
                dxfLine.Layer = layer;
                dxfLine.Color = stroke;
                dxfLine.Transparency.Value = strokeTansparency;
                dxfLine.Lineweight.Value = lineweight;
                doc.AddEntity(dxfLine);
            }

            for (double gy = sy; gy < ey; gy += cellHeight)
            {
                var dxfLine = CreateLine(ox, gy, ex, gy);
                dxfLine.Layer = layer;
                dxfLine.Color = stroke;
                dxfLine.Transparency.Value = strokeTansparency;
                dxfLine.Lineweight.Value = lineweight;
                doc.AddEntity(dxfLine);
            }
        }
 private void Add(DxfDocument dxf, Core2D.Project.XProject project)
 {
     foreach (var document in project.Documents)
     {
         Add(dxf, document);
     }
 }
Beispiel #24
0
 public Grid GetMainGrid(netDxf.DxfDocument dxfFile)
 {
     return(GetMainGrid(dxfFile, true, true, Window_bgColor));
 }
Beispiel #25
0
 public Grid GetMainGrid(netDxf.DxfDocument dxfFile, bool avecGrille, bool avecOrigine)
 {
     return(GetMainGrid(dxfFile, avecGrille, avecOrigine, Window_bgColor));
 }
Beispiel #26
0
        public static List <DXFDrawData> ReadDXF(netDxf.DxfDocument dxf)
        {
            var    returnGroup    = new List <DXFDrawData>();
            double thicknessScale = 0.1;

            foreach (var layer in dxf.Layers)
            {
                var stroke = new SolidColorBrush(Color.FromRgb(layer.Color.R, layer.Color.G, layer.Color.B));
                var layerStrokeThickness = Math.Max((double)layer.Lineweight * thicknessScale, 2);
                foreach (var line in dxf.Lines)
                {
                    if (line.Layer == layer)
                    {
                        double strokeThickness = 0;
                        if (line.Lineweight == Lineweight.ByLayer)
                        {
                            strokeThickness = layerStrokeThickness;
                        }
                        else
                        {
                            strokeThickness = Math.Max((double)line.Lineweight * thicknessScale, 2);
                        }
                        returnGroup.Add(new DXFDrawData(stroke, strokeThickness, new LineGeometry(new System.Windows.Point(line.StartPoint.X, line.StartPoint.Y), new System.Windows.Point(line.EndPoint.X, line.EndPoint.Y))));
                    }
                }
                foreach (var arc in dxf.Arcs)
                {
                    double x          = arc.Center.X;
                    double y          = arc.Center.Y;
                    double start      = arc.StartAngle;
                    double end        = arc.EndAngle;
                    double r          = arc.Radius;
                    var    endPoint   = e(arc.Normal, arc.Center, (float)arc.Radius, (float)(arc.EndAngle * Math.PI / 180));
                    var    startPoint = e(arc.Normal, arc.Center, (float)arc.Radius, (float)(arc.StartAngle * Math.PI / 180));


                    ArcSegment newarc = new ArcSegment(endPoint, new Size(r, r), (end - start) * Math.PI / 180, false, SweepDirection.Clockwise, true);
                    PathFigure fig    = new PathFigure(startPoint, new List <PathSegment> {
                        newarc
                    }, false);
                    PathGeometry path = new PathGeometry(new List <PathFigure> {
                        fig
                    });
                    if (arc.Layer == layer)
                    {
                        double strokeThickness = 0;
                        if (arc.Lineweight == Lineweight.ByLayer)
                        {
                            strokeThickness = layerStrokeThickness;
                        }
                        else
                        {
                            strokeThickness = Math.Max((double)arc.Lineweight * thicknessScale, 2);
                        }
                        returnGroup.Add(new DXFDrawData(stroke, strokeThickness, path));
                    }


                    //returnGroup.Children.Add(new ArcSegment());
                }

                foreach (var circle in dxf.Circles)
                {
                    if (circle.Layer == layer)
                    {
                        double strokeThickness = 0;
                        if (circle.Lineweight == Lineweight.ByLayer)
                        {
                            strokeThickness = layerStrokeThickness;
                        }
                        else
                        {
                            strokeThickness = Math.Max((double)circle.Lineweight * thicknessScale, 2);
                        }
                        returnGroup.Add(new DXFDrawData(stroke, strokeThickness, new EllipseGeometry(new Point(circle.Center.X, circle.Center.Y), circle.Radius, circle.Radius)));
                    }
                }
            }


            return(returnGroup);
        }
Beispiel #27
0
        private void DrawRectangleInternal(DxfDocument doc, Layer layer, bool isFilled, bool isStroked, Test2d.BaseStyle style, ref Test2d.Rect2 rect)
        {
            double x = rect.X;
            double y = rect.Y;
            double w = rect.Width;
            double h = rect.Height;

            var dxfLine1 = CreateLine(x, y, x + w, y);
            var dxfLine2 = CreateLine(x + w, y, x + w, y + h);
            var dxfLine3 = CreateLine(x + w, y + h, x, y + h);
            var dxfLine4 = CreateLine(x, y + h, x, y);

            if (isFilled)
            {
                var fill = GetColor(style.Fill);
                var fillTransparency = GetTransparency(style.Fill);

                var bounds =
                    new List<HatchBoundaryPath>
                    {
                        new HatchBoundaryPath(
                            new List<EntityObject>
                            {
                                (Line)dxfLine1.Clone(),
                                (Line)dxfLine2.Clone(),
                                (Line)dxfLine3.Clone(),
                                (Line)dxfLine4.Clone()
                            })
                    };

                var hatch = new Hatch(HatchPattern.Solid, bounds, false);
                hatch.Layer = layer;
                hatch.Color = fill;
                hatch.Transparency.Value = fillTransparency;

                doc.AddEntity(hatch);
            }

            if (isStroked)
            {
                var stroke = GetColor(style.Stroke);
                var strokeTansparency = GetTransparency(style.Stroke);
                var lineweight = ThicknessToLineweight(style.Thickness);

                dxfLine1.Layer = layer;
                dxfLine1.Color = stroke;
                dxfLine1.Transparency.Value = strokeTansparency;
                dxfLine1.Lineweight.Value = lineweight;

                dxfLine2.Layer = layer;
                dxfLine2.Color = stroke;
                dxfLine2.Transparency.Value = strokeTansparency;
                dxfLine2.Lineweight.Value = lineweight;

                dxfLine3.Layer = layer;
                dxfLine3.Color = stroke;
                dxfLine3.Transparency.Value = strokeTansparency;
                dxfLine3.Lineweight.Value = lineweight;

                dxfLine4.Layer = layer;
                dxfLine4.Color = stroke;
                dxfLine4.Transparency.Value = strokeTansparency;
                dxfLine4.Lineweight.Value = lineweight;

                doc.AddEntity(dxfLine1);
                doc.AddEntity(dxfLine2);
                doc.AddEntity(dxfLine3);
                doc.AddEntity(dxfLine4);
            }
        }
Beispiel #28
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="container"></param>
        private void Add(DxfDocument doc, Test2d.Container container)
        {
            _pageWidth = container.Width;
            _pageHeight = container.Height;

            if (container.Template != null)
            {
                Draw(doc, container.Template, container.Properties, null);
            }

            Draw(doc, container, container.Properties, null);
        }
        static void doDXF(List<Polyline3dVertex> vertexes, double[] x)
        {
            // create a dxf for those who want to "see" the calibration
            DxfDocument dxf = new DxfDocument();

            Polyline3d polyline = new Polyline3d(vertexes, true);
            polyline.Layer = new Layer("polyline3d");
            polyline.Layer.Color.Index = 24;
            dxf.AddEntity(polyline);

            var pnt = new Point(new Vector3f(-(float) x[0], -(float) x[1], -(float) x[2]));
            pnt.Layer = new Layer("new offset");
            pnt.Layer.Color.Index = 21;
            dxf.AddEntity(pnt);

            dxf.Save("magoffset.dxf", DxfVersion.AutoCad2000);

            log.Info("dxf Done " + DateTime.Now);
        }
Beispiel #30
0
        /// <summary>
        /// 绘制订单信息块
        /// </summary>
        /// <param name="dxf"></param>
        /// <param name="location"></param>
        /// <param name="boxWidth"></param>
        /// <param name="configurations"></param>
        public static void Draw(DxfDocument dxf, Location location,float boxWidth, OrderEntity orderEntity)
        {
            float factor = 0.6f;
            Vector3f v1 = new Vector3f(location.X,location.Y,location.Z);
            Vector3f v2 = new Vector3f(location.X + boxWidth, location.Y, location.Z);
            Vector3f v3 = new Vector3f(location.X + boxWidth, location.Y + 40.0f * factor, location.Z);
            Vector3f v4 = new Vector3f(location.X, location.Y + 40.0f * factor, location.Z);

            Vector3f v5 = new Vector3f(location.X, location.Y + 10.0f * factor, location.Z);
            Vector3f v6 = new Vector3f(location.X + boxWidth / 4, location.Y + 10.0f * factor, location.Z);
            Vector3f v7 = new Vector3f(location.X + boxWidth / 2, location.Y + 10.0f * factor, location.Z);
            Vector3f v8 = new Vector3f(location.X + boxWidth * 3 / 4, location.Y + 10.0f * factor, location.Z);
            Vector3f v9 = new Vector3f(location.X + boxWidth * 7 / 8, location.Y + 10.0f * factor, location.Z);

            Vector3f v10 = new Vector3f(location.X + boxWidth / 4, location.Y + 20.0f * factor, location.Z);
            Vector3f v11 = new Vector3f(location.X + boxWidth / 2, location.Y + 20.0f * factor, location.Z);
            Vector3f v12 = new Vector3f(location.X + boxWidth * 3 / 4, location.Y + 20.0f * factor, location.Z);
            Vector3f v13 = new Vector3f(location.X + boxWidth * 7 / 8, location.Y + 20.0f * factor, location.Z);
            Vector3f v14 = new Vector3f(location.X + boxWidth, location.Y + 20.0f * factor, location.Z);

            Vector3f v15 = new Vector3f(location.X + boxWidth / 4, location.Y + 40.0f * factor, location.Z);
            Vector3f v16 = new Vector3f(location.X + boxWidth * 3 / 4, location.Y + 40.0f * factor, location.Z);

            Vector3f v17 = new Vector3f(location.X + boxWidth / 4, location.Y, location.Z);
            Vector3f v18 = new Vector3f(location.X + boxWidth / 2, location.Y, location.Z);
            Vector3f v19 = new Vector3f(location.X + boxWidth * 3 / 4, location.Y, location.Z);

            Vector3f v20 = new Vector3f(location.X + boxWidth, location.Y + 10.0f * factor, location.Z);

            Layer layer = new Layer("line");

            //横向四道
            Line line12 = new Line(v1, v2);
            line12.Layer = layer;
            dxf.AddEntity(line12);

            Line line520 = new Line(v5, v20);
            line520.Layer = layer;
            dxf.AddEntity(line520);

            Line line1014 = new Line(v10, v14);
            line1014.Layer = layer;
            dxf.AddEntity(line1014);

            Line line43 = new Line(v4, v3);
            line43.Layer = layer;
            dxf.AddEntity(line43);

            //纵向6道
            Line line41 = new Line(v4, v1);
            line41.Layer = layer;
            dxf.AddEntity(line41);

            Line line1517 = new Line(v15, v17);
            line1517.Layer = layer;
            dxf.AddEntity(line1517);

            Line line1118 = new Line(v11, v18);
            line1118.Layer = layer;
            dxf.AddEntity(line1118);

            Line line1619 = new Line(v16, v19);
            line1619.Layer = layer;
            dxf.AddEntity(line1619);

            Line line139 = new Line(v13, v9);
            line139.Layer = layer;
            dxf.AddEntity(line139);

            Line line32= new Line(v3, v2);
            line32.Layer = layer;
            dxf.AddEntity(line32);

            //文字

            TextStyle style = new TextStyle("True type font", "Arial.ttf");
            Vector3f vt1 = new Vector3f(v1.X + 1.0f, v1.Y + 2.5f, v1.Z);
            Text t1 = new Text("Celebrity 1.0.0", vt1, 2.0f, style);
            t1.Layer = layer;
            t1.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t1);

            Vector3f vt2 = new Vector3f(v17.X + 1.0f, v17.Y + 2.5f, v1.Z);
            Text t2 = new Text("PREPARER:  "+orderEntity.Preparer, vt2, 2.0f, style);
            t2.Layer = layer;
            t1.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t2);

            Vector3f vt3 = new Vector3f(v18.X + 1.0f, v18.Y + 2.5f, v1.Z);
            Text t3 = new Text("ENGINEER:  "+orderEntity.Engineer, vt3, 2.0f, style);
            t3.Layer = layer;
            t3.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t3);

            Vector3f vt4 = new Vector3f(v19.X + 1.0f, v19.Y + 2.5f, v1.Z);
            Text t4 = new Text("SHIP ORDER NO:  "+orderEntity.ShipOrderNo, vt4, 2.0f, style);
            t4.Layer = layer;
            t4.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t4);

            Vector3f vt5 = new Vector3f(v4.X + 1.0f, v10.Y + 2.5f, v1.Z);
            Text t5= new Text("     AAON  COIL  PRODUCTS  inc.", vt5, 3.0f, style);
            t5.Layer = layer;
            t5.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t5);

            Vector3f vt6 = new Vector3f(v5.X + 1.0f, v5.Y + 2.5f, v1.Z);
            Text t6 = new Text("LONGVIEW  TEXAS", vt6, 2.0f, style);
            t6.Layer = layer;
            t6.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t6);

            Vector3f vt7 = new Vector3f(v6.X + 1.0f, v6.Y + 2.5f, v1.Z);
            Text t7 = new Text("PURCHASER:  " + orderEntity.Purchaser, vt7, 2.0f, style);
            t7.Layer = layer;
            t7.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t7);

            Vector3f vt8 = new Vector3f(v7.X + 1.0f, v7.Y + 2.5f, v1.Z);
            Text t8 = new Text("PURCHASE ORDER:  " + orderEntity.PurchaseOrder, vt8, 2.0f, style);
            t8.Layer = layer;
            t8.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t8);

            Vector3f vt9 = new Vector3f(v8.X + 1.0f, v8.Y + 2.5f, v1.Z);
            Text t9 = new Text("SERIAL NO:  " + orderEntity.SeriaNo, vt9, 2.0f, style);
            t9.Layer = layer;
            t9.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t9);

            Vector3f vt10 = new Vector3f(v9.X + 1.0f, v9.Y + 2.5f, v1.Z);
            Text t10 = new Text("DATE: "+DateTime.Now.ToShortDateString(), vt10, 2.0f, style);
            t10.Layer = layer;
            t10.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t10);

            Vector3f vt11 = new Vector3f(v15.X + 1.0f, v15.Y - 7.5f, v1.Z);
            Text t11 = new Text("JOB NAME:", vt11, 2.0f, style);
            t11.Layer = layer;
            t11.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t11);

            Vector3f vt12 = new Vector3f(v10.X + 10.0f, v10.Y + 2.5f, v1.Z);
            Text t12 = new Text(orderEntity.JobName, vt12, 2.0f, style);
            t12.Layer = layer;
            t12.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t12);

            Vector3f vt13 = new Vector3f(v16.X + 1.0f, v16.Y - 7.5f, v1.Z);
            Text t13 = new Text("UNIT TAG:", vt13, 2.0f, style);
            t13.Layer = layer;
            t13.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t13);

            Vector3f vt14 = new Vector3f(v12.X + 20.0f, v12.Y + 2.5f, v1.Z);
            Text t14 = new Text(orderEntity.UnitTag, vt14, 2.0f, style);
            t14.Layer = layer;
            t14.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t14);
        }
Beispiel #31
0
        public Grid mainGrid     = new Grid();   //面板 grid

        public Grid GetMainGrid(netDxf.DxfDocument dxfFile, bool avecGrille, bool avecOrigine, Color bgColor)
        {
            try
            {
                mainCanvas.Children.Clear();
                DrawEntities.RazMaxDim();
                DrawEntities.AddNewMaxDim();

                ;
                //  mainGrid = new Grid();
                mainGrid.HorizontalAlignment = HorizontalAlignment.Stretch;
                mainGrid.VerticalAlignment   = VerticalAlignment.Stretch;


                Color m_Color = Color.FromArgb(255, (byte)128, (byte)128, (byte)128);
                mainGrid.Background = new SolidColorBrush(m_Color);


                border.Height = GridHeight;
                border.Width  = GridWidth;
                //

                border.Background          = new SolidColorBrush(m_Color); //UNdone::取消背景颜色
                border.HorizontalAlignment = HorizontalAlignment.Stretch;
                border.VerticalAlignment   = VerticalAlignment.Stretch;
                border.Scale = Scale;//增加比例


                mainCanvas.Name = "mainCanvas";
                if (DxfDoc.DrawingVariables.AcadVer < netDxf.Header.DxfVersion.AutoCad2000)
                {
                    DrawUtils.DrawText("Le format du fichier doit être dxf2000 ou supérieur.", 10, Colors.Red, 20, 50, mainCanvas);
                }
                GetCanvas(DxfDoc, mainCanvas);

                if (avecOrigine == true)
                {
                    DrawEntities.AddNewMaxDim();
                    DrawUtils.DrawOrigin(mainCanvas);
                    DrawEntities.DeleteLastMaxDim();
                }

                if (avecGrille == true)
                {
                    Canvas bgCanvas = new Canvas();
                    if (border.Child == null)
                    {
                        bgCanvas = CreateBgCanvas();
                        bgCanvas.Children.Add(mainCanvas);

                        border.Child = bgCanvas;
                    }
                }
                else
                {
                    border.Child = mainCanvas;
                }

                Canvas.SetTop(mainCanvas, GridHeight / 2);
                Canvas.SetLeft(mainCanvas, GridWidth / 2);

                //  Canvas.SetTop(mainCanvas, 0);
                //  Canvas.SetLeft(mainCanvas, 0);

                //border.Reset(GridHeight,GridWidth,true,ViewHeight,ViewWidth,WinHeight,WinWidth);



                if (mainGrid.Children.Count == 0)
                {
                    //bool res = mainGrid.Children.Contains(border);
                    // if(res==false)
                    mainGrid.Children.Add(border);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


            return(mainGrid);
        }
Beispiel #32
0
        public static void GetCanvas(netDxf.DxfDocument DxfDoc, Canvas mainCanvas)
        {
            mainCanvas.Width  = 250;
            mainCanvas.Height = 250;



            /*Dessin Line*/
            Debug.WriteLine("nb ligne=" + DxfDoc.Lines.Count.ToString());
            foreach (netDxf.Entities.Line xLine in DxfDoc.Lines)
            {
                DrawEntities.DrawLine(xLine, mainCanvas);
            }

            /*Dessin Polyline*/
            Debug.WriteLine("nb Polyline=" + DxfDoc.Polylines.Count.ToString());
            foreach (netDxf.Entities.Polyline xPoly in DxfDoc.Polylines)
            {
                DrawEntities.DrawPolyline(xPoly, mainCanvas);
            }

            /*Dessin LwPolyline*/
            Debug.WriteLine("nb LwPolyligne=" + DxfDoc.LwPolylines.Count.ToString());
            foreach (netDxf.Entities.LwPolyline xPoly in DxfDoc.LwPolylines)
            {
                DrawEntities.DrawLwPolyline(xPoly, mainCanvas);
            }

            /*Dessin Mlines*/
            Debug.WriteLine("nb MLines=" + DxfDoc.MLines.Count.ToString());
            foreach (netDxf.Entities.MLine xPoly in DxfDoc.MLines)
            {
                DrawEntities.DrawMLine(xPoly, mainCanvas);
            }

            /*Dessin Solid*/
            Debug.WriteLine("nb Solids=" + DxfDoc.Solids.Count.ToString());
            foreach (netDxf.Entities.Solid xPoly in DxfDoc.Solids)
            {
                DrawEntities.DrawSolid(xPoly, mainCanvas);
            }

            /*Dessin PolyfaceMesh*/
            Debug.WriteLine("nb PolyfaceMesh=" + DxfDoc.PolyfaceMeshes.Count.ToString());
            foreach (netDxf.Entities.PolyfaceMesh xPoly in DxfDoc.PolyfaceMeshes)
            {
                DrawEntities.DrawPolyfaceMesh(xPoly, mainCanvas);
            }

            /*Dessin Wipeout*/
            Debug.WriteLine("nb Wipeout=" + DxfDoc.PolyfaceMeshes.Count.ToString());
            foreach (netDxf.Entities.Wipeout xPoly in DxfDoc.Wipeouts)
            {
                DrawEntities.DrawWipeout(xPoly, mainCanvas);
            }

            /*Dessin Face3D*/
            Debug.WriteLine("nb Face3D=" + DxfDoc.Faces3d.Count.ToString());
            foreach (netDxf.Entities.Face3d xPoly in DxfDoc.Faces3d)
            {
                DrawEntities.DrawFace3d(xPoly, mainCanvas);
            }

            /*Dessin Circle*/
            Debug.WriteLine("nb Circles=" + DxfDoc.Circles.Count.ToString());
            foreach (netDxf.Entities.Circle xCircle in DxfDoc.Circles)
            {
                DrawEntities.DrawCircle(xCircle, mainCanvas);
            }

            /*Dessin Ellipse*/
            Debug.WriteLine("nb Ellipses=" + DxfDoc.Ellipses.Count.ToString());
            foreach (netDxf.Entities.Ellipse xEllipse in DxfDoc.Ellipses)
            {
                DrawEntities.DrawEllipse(xEllipse, mainCanvas);
            }

            /*Dessin Arc*/
            Debug.WriteLine("nb Arcs=" + DxfDoc.Arcs.Count.ToString());
            foreach (netDxf.Entities.Arc xArc in DxfDoc.Arcs)
            {
                DrawEntities.DrawArc(xArc, mainCanvas);
            }

            /*Dessin Text*/
            Debug.WriteLine("nb Text=" + DxfDoc.Texts.Count.ToString());
            foreach (netDxf.Entities.Text xTxt in DxfDoc.Texts)
            {
                DrawEntities.DrawText(xTxt, mainCanvas);
            }

            /*Dessin MText*/
            Debug.WriteLine("nb MText=" + DxfDoc.MTexts.Count.ToString());
            foreach (netDxf.Entities.MText xTxt in DxfDoc.MTexts)
            {
                Debug.WriteLine("Reactor=" + xTxt.Reactors.Count.ToString());
                if (xTxt.Reactors.Count == 0)
                {
                    DrawEntities.DrawMText(xTxt, mainCanvas);
                }
            }


            /*Dessin Point*/
            Debug.WriteLine("nb Points=" + DxfDoc.Points.Count.ToString());
            foreach (netDxf.Entities.Point xPoint in DxfDoc.Points)
            {
                DrawEntities.DrawPoint(xPoint, mainCanvas);
            }


            /*Dessin Dimension*/
            Debug.WriteLine("nb Dimensions=" + DxfDoc.Dimensions.Count.ToString());
            foreach (netDxf.Entities.Dimension xDim in DxfDoc.Dimensions)
            {
                xDim.Lineweight = Lineweight.W0;
                DrawEntities.DrawDimension(xDim, mainCanvas);
            }

            /*Dessin Insert*/
            Debug.WriteLine("nb Insert=" + DxfDoc.Inserts.Count.ToString());
            foreach (netDxf.Entities.Insert xInsert in DxfDoc.Inserts)
            {
                DrawEntities.DrawInsert(xInsert, mainCanvas);
            }


            /*Dessin Leader*/
            Debug.WriteLine("nb Leader=" + DxfDoc.Leaders.Count.ToString());
            foreach (netDxf.Entities.Leader xLeader in DxfDoc.Leaders)
            {
                DrawEntities.DrawLeader(xLeader, mainCanvas);
            }


            /*Dessin Spline*/
            Debug.WriteLine("nb Spline=" + DxfDoc.Splines.Count.ToString());
            foreach (netDxf.Entities.Spline xSpline in DxfDoc.Splines)
            {
                DrawEntities.DrawSpline(xSpline, mainCanvas);
            }



            /*Dessin Hatch*/
            Debug.WriteLine("nb Hatch=" + DxfDoc.Hatches.Count.ToString());
            foreach (netDxf.Entities.Hatch xHatch in DxfDoc.Hatches)
            {
                DrawEntities.DrawHatch(xHatch, mainCanvas);
            }


            /*Dessin Image*/
            Debug.WriteLine("nb Image=" + DxfDoc.Images.Count.ToString());
            foreach (netDxf.Entities.Image xImage in DxfDoc.Images)
            {
                DrawEntities.DrawImage(xImage, mainCanvas);
            }


            /*Dessin Underlay*/
            Debug.WriteLine("nb Underlay=" + DxfDoc.Underlays.Count.ToString());
            foreach (netDxf.Entities.Underlay xUnderlay in DxfDoc.Underlays)
            {
                DrawEntities.DrawUnderlay(xUnderlay, mainCanvas);
            }


            /*Dessin Mesh*/
            Debug.WriteLine("nb Mesh=" + DxfDoc.Meshes.Count.ToString());
            foreach (netDxf.Entities.Mesh xMesh in DxfDoc.Meshes)
            {
                DrawEntities.DrawMesh(xMesh, mainCanvas);
            }

            /*Debug.WriteLine("DXFDoc:"+DxfDoc.DrawingVariables.LUnits.ToString());
             * Debug.WriteLine("DXFDoc TextSize:"+DxfDoc.DrawingVariables.TextSize.ToString());
             * Debug.WriteLine("DXFDoc InsUnits:"+DxfDoc.DrawingVariables.InsUnits.ToString());*/
        }
Beispiel #33
0
 //画完整的带支架的设备矩形框
 public static void writeWholeMachine(DxfDocument dxf, Location location, string[] text, float height, float width, float outer_mid_space, float outer_in_space, float barHeight, float barWidth,string upOrDownLayer)
 {
     writeDoorRectangle(dxf,location,text,height,width,outer_mid_space,outer_in_space);
     //画小支架
     if (upOrDownLayer.Equals("downLayer"))
     {
         //左下角
         writeOuterDoorRectangle(dxf, new Location(location.X, location.Y - outer_in_space, location.Z), outer_in_space, outer_in_space - outer_mid_space);
         //右下角
         writeOuterDoorRectangle(dxf, new Location(location.X + width + outer_mid_space - outer_in_space, location.Y - outer_in_space, location.Z), outer_in_space, outer_in_space - outer_mid_space);
     }
 }
Beispiel #34
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="path"></param>
 /// <param name="container"></param>
 public void Save(string path, Test2d.Container container)
 {
     _outputPath = System.IO.Path.GetDirectoryName(path);
     var doc = new DxfDocument(DxfVersion.AutoCad2010);
     Add(doc, container);
     doc.Save(path);
     ClearCache(isZooming: false);
 }
Beispiel #35
0
 //画带有四个小矩形的俯视图矩形
 public static void writeTopViewRectangle(DxfDocument dxf, Location location, string[] text, float height, float width, float outer_mid_space, float outer_in_space)
 {
     //outer_in_space模拟height,outer_in_space - outer_mid_space模拟width
     //主要矩形
     writeOuterDoorRectangle(dxf, location, height, width);
     //左上角矩形
     writeOuterDoorRectangle(dxf, new Location(location.X, location.Y + height, location.Z), outer_in_space, outer_in_space - outer_mid_space);
     //右上角
     writeOuterDoorRectangle(dxf, new Location(location.X + width - outer_in_space + outer_mid_space, location.Y + height, location.Z), outer_in_space, outer_in_space - outer_mid_space);
     //左下角
     writeOuterDoorRectangle(dxf, new Location(location.X, location.Y - outer_in_space, location.Z), outer_in_space, outer_in_space - outer_mid_space);
     //右下角
     writeOuterDoorRectangle(dxf, new Location(location.X + width - outer_in_space + outer_mid_space, location.Y - outer_in_space, location.Z), outer_in_space, outer_in_space - outer_mid_space);
 }
Beispiel #36
0
        private void DrawEllipseInternal(DxfDocument doc, Layer layer, bool isFilled, bool isStroked, Test2d.BaseStyle style, ref Test2d.Rect2 rect)
        {
            var dxfEllipse = CreateEllipse(rect.X, rect.Y, rect.Width, rect.Height);

            if (isFilled)
            {
                var fill = GetColor(style.Fill);
                var fillTransparency = GetTransparency(style.Fill);

                // TODO: The netDxf does not create hatch for Ellipse with end angle equal to 360.
                var bounds =
                    new List<HatchBoundaryPath>
                    {
                        new HatchBoundaryPath(
                            new List<EntityObject>
                            {
                                (Ellipse)dxfEllipse.Clone()
                            })
                    };

                var hatch = new Hatch(HatchPattern.Solid, bounds, false);
                hatch.Layer = layer;
                hatch.Color = fill;
                hatch.Transparency.Value = fillTransparency;

                doc.AddEntity(hatch);
            }

            if (isStroked)
            {
                var stroke = GetColor(style.Stroke);
                var strokeTansparency = GetTransparency(style.Stroke);
                var lineweight = ThicknessToLineweight(style.Thickness);

                dxfEllipse.Layer = layer;
                dxfEllipse.Color = stroke;
                dxfEllipse.Transparency.Value = strokeTansparency;
                dxfEllipse.Lineweight.Value = lineweight;

                doc.AddEntity(dxfEllipse);
            }
        }
Beispiel #37
0
        public void Load(string filePath)
        {
            _dxf = new DxfDocument();
            _dxf.Load(filePath);

            foreach (netDxf.Tables.LineType lineType in _dxf.LineTypes)
            {
                _lineTypeDictionary.Add(lineType, PicGraphics.LT.LT_CUT);
                _lineType2GrpDictionary.Add(lineType, 0);
            }
        }
Beispiel #38
0
 public DetailMechineConfigure getDetailMechineCnfigure(List<PictureBoxInfo> pictureBoxNameList, DxfDocument dxf,
     Location location)
 {
     return new DetailMechineConfigure(pictureBoxNameList,
         new string[] { "hello", "world", "helloworld" }, 44.0f, 18, 2.0f, 2.86f, 2.0f, 2.0f);
 }
Beispiel #39
0
        /// <summary>
        /// 绘制左下角区域的Section块
        /// </summary>
        /// <param name="dxf"></param>
        /// <param name="location"></param>
        /// <param name="configurations"></param>
        public static void Draw(DxfDocument dxf, Location location,SectionEntity sectionEntity)
        {
            float factor=0.6f;
            Vector3f v1 = new Vector3f(location.X, location.Y + 40.0f*factor, location.Z);
            Vector3f v2 = new Vector3f(location.X + 50.0f * factor, location.Y + 40.0f * factor, location.Z);
            Vector3f v3 = new Vector3f(location.X + 90.0f * factor, location.Y + 40.0f * factor, location.Z);
            Vector3f v4 = new Vector3f(location.X + 140.0f * factor, location.Y + 40.0f * factor, location.Z);

            Vector3f v5 = new Vector3f(location.X, location.Y + 50.0f * factor, location.Z);
            Vector3f v6 = new Vector3f(location.X + 140.0f * factor, location.Y + 50.0f * factor, location.Z);

            Vector3f v7 = new Vector3f(location.X, location.Y + 60.0f * factor, location.Z);
            Vector3f v8 = new Vector3f(location.X + 140.0f * factor, location.Y + 60.0f * factor, location.Z);

            Vector3f v9 = new Vector3f(location.X, location.Y + 70.0f * factor, location.Z);
            Vector3f v10 = new Vector3f(location.X + 50.0f * factor, location.Y + 70.0f * factor, location.Z);
            Vector3f v11 = new Vector3f(location.X + 90.0f * factor, location.Y + 70.0f * factor, location.Z);
            Vector3f v12 = new Vector3f(location.X + 140.0f * factor, location.Y + 70.0f * factor, location.Z);

            Layer layer = new Layer("line");

            //横向四道
            Line line14 = new Line(v1, v4);
            line14.Layer = layer;
            dxf.AddEntity(line14);

            Line line56 = new Line(v5, v6);
            line56.Layer = layer;
            dxf.AddEntity(line56);

            Line line78 = new Line(v7, v8);
            line78.Layer = layer;
            dxf.AddEntity(line78);

            Line line912 = new Line(v9, v12);
            line912.Layer = layer;
            dxf.AddEntity(line912);

            //纵向四道
            Line line91 = new Line(v9, v1);
            line91.Layer = layer;
            dxf.AddEntity(line91);

            Line line210 = new Line(v2, v10);
            line210.Layer = layer;
            dxf.AddEntity(line210);

            Line line311 = new Line(v3, v11);
            line311.Layer = layer;
            dxf.AddEntity(line311);

            Line line412 = new Line(v4, v12);
            line412.Layer = layer;
            dxf.AddEntity(line412);

            TextStyle style = new TextStyle("True type font", "Arial.ttf");
            Vector3f vt1 = new Vector3f(v1.X+1.0f, v1.Y+2.5f, v1.Z);
            Text t1 = new Text("COIL", vt1, 2.0f, style);
            t1.Layer = layer;
            t1.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t1);

            Vector3f vt2 = new Vector3f(v2.X + 1.0f, v2.Y + 2.5f, v2.Z);
            Text t2 = new Text("CLF", vt2, 2.0f, style);
            t2.Layer = layer;
            t2.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t2);

            Vector3f vt3 = new Vector3f(v3.X + 1.0f, v3.Y + 2.5f, v3.Z);
            Text t3 = new Text(sectionEntity.CoolValue, vt3, 2.0f, style);
            t3.Layer = layer;
            t3.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t3);

            Vector3f vt4 = new Vector3f(v5.X + 1.0f, v5.Y + 2.5f, v5.Z);
            Text t4 = new Text("FILTER", vt4, 2.0f, style);
            t4.Layer = layer;
            t4.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t4);

            Vector3f vt5 = new Vector3f(v2.X + 1.0f, v5.Y + 2.5f, v5.Z);
            Text t5 = new Text("FTA", vt5, 2.0f, style);
            t5.Layer = layer;
            t5.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t5);

            Vector3f vt6 = new Vector3f(v3.X + 1.0f, v5.Y + 2.5f, v5.Z);
            Text t6 = new Text(sectionEntity.FilterValue, vt6, 2.0f, style);
            t6.Layer = layer;
            t6.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t6);

            Vector3f vt7 = new Vector3f(v7.X + 1.0f, v7.Y + 2.5f, v7.Z);
            Text t7 = new Text("SECTION", vt7, 2.0f, style);
            t7.Layer = layer;
            t7.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t7);

            Vector3f vt8 = new Vector3f(v2.X + 1.0f, v7.Y + 2.5f, v7.Z);
            Text t8 = new Text("MODULE", vt8, 2.0f, style);
            t8.Layer = layer;
            t8.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t8);

            Vector3f vt9 = new Vector3f(v3.X + 1.0f, v7.Y + 2.5f, v7.Z);
            Text t9 = new Text("CLEARANCE", vt9, 2.0f, style);
            t9.Layer = layer;
            t9.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t9);
        }
Beispiel #40
0
        static void Main(string[] args)
        {
            var dxf = new netDxf.DxfDocument();

            var rValues1 = new List <double>()
            {
                1, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9,
                4.7, 5.6, 6.8, 8.2, 10, 12, 15, 18, 22,
                27, 33, 39, 47, 56, 68, 82, 100,
                120, 150, 180, 220, 270, 330, 390, 470,
                560, 680, 820,

                1e3, 1.2e3, 1.5e3, 1.8e3, 2.2e3, 2.7e3,
                3.3e3, 3.9e3, 4.7e3, 5.5e3, 6.8e3, 7.2e3, 8.2e3, 10e3, 12e3,
                15e3, 18e3, 22e3, 27e3, 33e3, 39e3, 47e3, 56e3, 82e3, 100e3,
                120e3, 150e3, 180e3, 220e3, 270e3, 330e3, 380e3,
                470e3, 560e3, 680e3, 820e3,

                1e6, 1.2e6, 1.5e6, 1.8e6, 2.2e6, 2.7e6, 3.3e6, 3.9e6, 4.7e6,
                5.6e6, 6.8e6, 8.2e6, 10e6
            };

            var rValues2 = new List <double>()
            {
                7.5, 75, 200, 510,

                2e3, 3e3, 5.1e3, 7.5e3, 20e3, 51e3, 68e3, 75e3, 200e3, 510e3, 750e3,

                2e6
            };

            var rValues3 = new List <double>()
            {
                1.2, 1.5, 1.8, 2.7, 3.3, 3.9, 6.8, 12, 18, 560, 820,
                1.2e3, 1.8e3, 2.7e3, 12e3, 18e3, 27e3, 270e3, 380e3,
                5.6e3, 300e3,
                1.2e6, 1.8e6, 2.2e6, 2.7e6, 3.9e6, 6.8e6, 8.2e6
            };

            var DATA = rValues1.Union(rValues2).Union(rValues3).OrderBy(w => w).ToList();

            var PAGE_W = 210d;
            var PAGE_H = 297d;

            var LABEL_W = 25d;
            var LABEL_H = 20d;

            var MARGINS_LTRB = new[] { 10d, 10d, 10d, 10d };

            var COLS = Math.Truncate((PAGE_W - MARGINS_LTRB[0] - MARGINS_LTRB[2]) / LABEL_W);
            var ROWS = Math.Truncate((PAGE_H - MARGINS_LTRB[1] - MARGINS_LTRB[3]) / LABEL_H);

            var XORIGIN = 0d;
            var YORIGIN = 0d;

            var TXT_HEIGHT = 5d;
            var OHM_HEIGHT = 3d;
            var TXT_FONT   = new netDxf.Tables.TextStyle("Ubuntu Condensed", netDxf.Tables.FontStyle.Regular);

            var x = XORIGIN;
            var y = YORIGIN;

            int page = 0;

            for (int i = 0; i < DATA.Count; ++i)
            {
                var r = DATA[i];

                var prefix = "";
                if (r >= 1e6)
                {
                    prefix = " M";
                    r     /= 1e6;
                }
                else if (r >= 1e3)
                {
                    prefix = " k";
                    r     /= 1e3;
                }

                var txt = Invariant($"\\H{TXT_HEIGHT};{r}{prefix} \\H{OHM_HEIGHT};Ω");

                {
                    var ent = new LwPolyline(new[]
                    {
                        new Vector2(x, y),
                        new Vector2(x + LABEL_W, y),
                        new Vector2(x + LABEL_W, y + LABEL_H),
                        new Vector2(x, y + LABEL_H),
                    }, isClosed: true);
                    dxf.AddEntity(ent);
                }

                {
                    var ent = new MText(txt)
                    {
                        Position        = new Vector3(x + LABEL_W / 2, y + LABEL_H / 2, 0),
                        Height          = TXT_HEIGHT,
                        RectangleWidth  = LABEL_W,
                        AttachmentPoint = MTextAttachmentPoint.MiddleCenter,
                        Style           = TXT_FONT
                    };
                    dxf.AddEntity(ent);
                }

                x += LABEL_W;
                if ((i + 1) % COLS == 0)
                {
                    y += LABEL_H;

                    if (y >= ROWS * LABEL_H)
                    {
                        y = YORIGIN;
                        ++page;
                    }
                    x = XORIGIN + page * (PAGE_W + LABEL_W);
                }
            }

            dxf.Save("output.dxf", isBinary: false);

            Process.Start(new ProcessStartInfo("output.dxf")
            {
                UseShellExecute = true
            });
        }
Beispiel #41
0
        private void DrawRectangleInternal(DxfDocument doc, Layer layer, bool isFilled, bool isStroked, Core2D.BaseStyle style, ref Core2D.Rect2 rect)
        {
            double x = rect.X;
            double y = rect.Y;
            double w = rect.Width;
            double h = rect.Height;

            var dxfLine1 = CreateLine(x, y, x + w, y);
            var dxfLine2 = CreateLine(x + w, y, x + w, y + h);
            var dxfLine3 = CreateLine(x + w, y + h, x, y + h);
            var dxfLine4 = CreateLine(x, y + h, x, y);

            if (isFilled)
            {
                var fill             = GetColor(style.Fill);
                var fillTransparency = GetTransparency(style.Fill);

                var bounds =
                    new List <HatchBoundaryPath>
                {
                    new HatchBoundaryPath(
                        new List <EntityObject>
                    {
                        (Line)dxfLine1.Clone(),
                        (Line)dxfLine2.Clone(),
                        (Line)dxfLine3.Clone(),
                        (Line)dxfLine4.Clone()
                    })
                };

                var hatch = new Hatch(HatchPattern.Solid, bounds, false);
                hatch.Layer = layer;
                hatch.Color = fill;
                hatch.Transparency.Value = fillTransparency;

                doc.AddEntity(hatch);
            }

            if (isStroked)
            {
                var stroke            = GetColor(style.Stroke);
                var strokeTansparency = GetTransparency(style.Stroke);
                var lineweight        = ThicknessToLineweight(style.Thickness);

                dxfLine1.Layer = layer;
                dxfLine1.Color = stroke;
                dxfLine1.Transparency.Value = strokeTansparency;
                dxfLine1.Lineweight.Value   = lineweight;

                dxfLine2.Layer = layer;
                dxfLine2.Color = stroke;
                dxfLine2.Transparency.Value = strokeTansparency;
                dxfLine2.Lineweight.Value   = lineweight;

                dxfLine3.Layer = layer;
                dxfLine3.Color = stroke;
                dxfLine3.Transparency.Value = strokeTansparency;
                dxfLine3.Lineweight.Value   = lineweight;

                dxfLine4.Layer = layer;
                dxfLine4.Color = stroke;
                dxfLine4.Transparency.Value = strokeTansparency;
                dxfLine4.Lineweight.Value   = lineweight;

                doc.AddEntity(dxfLine1);
                doc.AddEntity(dxfLine2);
                doc.AddEntity(dxfLine3);
                doc.AddEntity(dxfLine4);
            }
        }
Beispiel #42
0
        //画表示门闩的小矩形
        public static void writeRepresentDoorBarRectangle(DxfDocument doc, Location location, string[] text, float height, float width, float outer_mid_space, float outer_in_space, float barHeight, float barWidth)
        {
            Layer representDoorBarRectangleLayer = new Layer("RepresentDoorBarRectangle");
            Line bottomLine = new Line(new Vector3f(location.X, location.Y, location.Z), new Vector3f(location.X + barWidth, location.Y, location.Z));
            bottomLine.Layer = representDoorBarRectangleLayer;
            Line leftLine = new Line(new Vector3f(location.X, location.Y, location.Z), new Vector3f(location.X, location.Y + barHeight, location.Z));
            leftLine.Layer = representDoorBarRectangleLayer;
            Line topLine = new Line(new Vector3f(location.X, location.Y + barHeight, location.Z), new Vector3f(location.X + barWidth, location.Y + barHeight, location.Z));
            topLine.Layer = representDoorBarRectangleLayer;
            Line rightLine = new Line(new Vector3f(location.X + barWidth, location.Y + barHeight, location.Z), new Vector3f(location.X + barWidth, location.Y, location.Z));
            rightLine.Layer = representDoorBarRectangleLayer;

               //内部折线
            Line upLine = new Line(new Vector3f(location.X + barWidth / 2-(outer_in_space-outer_mid_space)/2, location.Y + barHeight, location.Z), new Vector3f(location.X + barWidth / 2-(outer_in_space-outer_mid_space)/2, location.Y + barHeight / 2, location.Z));
            upLine.Layer = representDoorBarRectangleLayer;
            Line midLine = new Line(new Vector3f(location.X + barWidth / 2 - (outer_in_space - outer_mid_space) / 2, location.Y + barHeight / 2, location.Z), new Vector3f(location.X + barWidth / 2 + (outer_in_space - outer_mid_space) / 2,location.Y+barHeight/2,location.Z));
            midLine.Layer = representDoorBarRectangleLayer;
            Line downLine = new Line(new Vector3f(location.X + barWidth / 2 + (outer_in_space - outer_mid_space) / 2, location.Y + barHeight / 2, location.Z), new Vector3f(location.X+barWidth/2+(outer_in_space-outer_mid_space)/2, location.Y, location.Z));
            downLine.Layer = representDoorBarRectangleLayer;
            doc.AddEntity(bottomLine);
            doc.AddEntity(leftLine);
            doc.AddEntity(topLine);
            doc.AddEntity(rightLine);
            doc.AddEntity(upLine);
            doc.AddEntity(midLine);
            doc.AddEntity(downLine);
        }
Beispiel #43
0
 public Grid GetMainGrid(string dxfFile, bool avecGrille, bool avecOrigine, Color bgColor)
 {
     DxfDoc = netDxf.DxfDocument.Load(dxfFile);
     return(GetMainGrid(DxfDoc, avecGrille, avecGrille, Window_bgColor));
 }
Beispiel #44
0
 public TopViewConfigure getTopViewConfigure(List<PictureBoxInfo> pictureBoxNameList, DxfDocument dxf,
     Location location)
 {
     return new TopViewConfigure(pictureBoxNameList, dxf,
          null, 50.0f, 18.0f, 2.0f, 2.86f, 2.0f, 2.0f);
 }
Beispiel #45
0
        //最外围矩形
        public static void writeOuterDoorRectangle(DxfDocument doc, Location location,float height, float width)
        {
            //最外围矩形
            Layer doorRectangleLayer = new Layer("DoorRectangleLayer");
            Line outerBottomLine = new Line(new Vector3f(location.X, location.Y, location.Z), new Vector3f(location.X + width, location.Y, location.Z));
            outerBottomLine.Layer = doorRectangleLayer;
            Line outerLeftLine = new Line(new Vector3f(location.X, location.Y, location.Z), new Vector3f(location.X, location.Y + height, location.Z));
            outerLeftLine.Layer = doorRectangleLayer;
            Line outerTopLine = new Line(new Vector3f(location.X, location.Y + height, location.Z), new Vector3f(location.X + width, location.Y + height, location.Z));
            outerTopLine.Layer = doorRectangleLayer;
            Line outerRightLine = new Line(new Vector3f(location.X + width, location.Y + height, location.Z), new Vector3f(location.X + width, location.Y, location.Z));
            outerRightLine.Layer = doorRectangleLayer;

            doc.AddEntity(outerBottomLine);
            doc.AddEntity(outerLeftLine);
            doc.AddEntity(outerTopLine);
            doc.AddEntity(outerRightLine);
        }
        /// <summary>
        /// Processes a tlog to get the offsets - creates dxf of data
        /// </summary>
        /// <param name="fn">Filename</param>
        /// <returns>Offsets</returns>
        public static double[] getOffsets(string fn, int throttleThreshold = 0)
        {
            // based off tridge's work
            string logfile = fn;

            // old method
            float minx = 0;
            float maxx = 0;
            float miny = 0;
            float maxy = 0;
            float minz = 0;
            float maxz = 0;

            // this is for a dxf
            Polyline3dVertex vertex;
            List<Polyline3dVertex> vertexes = new List<Polyline3dVertex>();

            // data storage
            Tuple<float, float, float> offset = new Tuple<float, float, float>(0, 0, 0);
            List<Tuple<float, float, float>> data = new List<Tuple<float, float, float>>();

            Hashtable filter = new Hashtable();

            // track data to use
            bool useData = false;

            log.Info("Start log: " + DateTime.Now);

                MAVLink mine = new MAVLink();
                try
                {
                    mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read));
                }
                catch (Exception ex) { log.Debug(ex.ToString()); CustomMessageBox.Show("Log Can not be opened. Are you still connected?"); return new double[] {0}; }

                mine.logreadmode = true;

                mine.MAV.packets.Initialize(); // clear

                // gather data
                while (mine.logplaybackfile.BaseStream.Position < mine.logplaybackfile.BaseStream.Length)
                {
                    byte[] packetraw = mine.readPacket();

                    var packet = mine.DebugPacket(packetraw, false);

                    // this is for packets we dont know about
                    if (packet == null)
                        continue;

                    if (packet.GetType() == typeof(MAVLink.mavlink_vfr_hud_t))
                    {
                        if (((MAVLink.mavlink_vfr_hud_t)packet).throttle >= throttleThreshold)
                        {
                            useData = true;
                        }
                        else
                        {
                            useData = false;
                        }

                    }

                    if (packet.GetType() == typeof(MAVLink.mavlink_sensor_offsets_t))
                    {
                        offset = new Tuple<float, float, float>(
                            ((MAVLink.mavlink_sensor_offsets_t)packet).mag_ofs_x,
                            ((MAVLink.mavlink_sensor_offsets_t)packet).mag_ofs_y,
                            ((MAVLink.mavlink_sensor_offsets_t)packet).mag_ofs_z);
                    }
                    else if (packet.GetType() == typeof(MAVLink.mavlink_raw_imu_t) && useData)
                    {
                        int div = 20;

                        // fox dxf
                        vertex = new Polyline3dVertex(new Vector3f(
                            ((MAVLink.mavlink_raw_imu_t)packet).xmag - offset.Item1,
                            ((MAVLink.mavlink_raw_imu_t)packet).ymag - offset.Item2,
                            ((MAVLink.mavlink_raw_imu_t)packet).zmag - offset.Item3)
                            );
                        vertexes.Add(vertex);

                        // for old method
                        setMinorMax(((MAVLink.mavlink_raw_imu_t)packet).xmag - offset.Item1, ref minx, ref maxx);
                        setMinorMax(((MAVLink.mavlink_raw_imu_t)packet).ymag - offset.Item2, ref miny, ref maxy);
                        setMinorMax(((MAVLink.mavlink_raw_imu_t)packet).zmag - offset.Item3, ref minz, ref maxz);

                        // for new lease sq
                        string item = (int)(((MAVLink.mavlink_raw_imu_t)packet).xmag / div) + "," +
                            (int)(((MAVLink.mavlink_raw_imu_t)packet).ymag / div) + "," +
                            (int)(((MAVLink.mavlink_raw_imu_t)packet).zmag / div);

                        if (filter.ContainsKey(item))
                        {
                            filter[item] = (int)filter[item] + 1;

                            if ((int)filter[item] > 3)
                                continue;
                        }
                        else
                        {
                            filter[item] = 1;
                        }

                        data.Add(new Tuple<float, float, float>(
                            ((MAVLink.mavlink_raw_imu_t)packet).xmag - offset.Item1,
                            ((MAVLink.mavlink_raw_imu_t)packet).ymag - offset.Item2,
                            ((MAVLink.mavlink_raw_imu_t)packet).zmag - offset.Item3));

                    }

                }

                log.Info("Log Processed " + DateTime.Now);

                Console.WriteLine("Extracted " + data.Count + " data points");
                Console.WriteLine("Current offset: " + offset);

                mine.logreadmode = false;
                mine.logplaybackfile.Close();
                mine.logplaybackfile = null;

                if (data.Count < 10)
                {
                    CustomMessageBox.Show("Log does not contain enough data");
                    throw new Exception("Not Enough Data");
                }

                data.Sort(
                    delegate(Tuple<float, float, float> d1, Tuple<float, float, float> d2)
                    {
                        // get distance from 0,0,0
                        double ans1 = Math.Sqrt(d1.Item1 * d1.Item1 + d1.Item2 * d1.Item2+ d1.Item3 * d1.Item3);
                        double ans2 = Math.Sqrt(d2.Item1 * d2.Item1 + d2.Item2 * d2.Item2+ d2.Item3 * d2.Item3);
                        if (ans1 > ans2)
                            return 1;
                        if (ans1 < ans2)
                            return -1;
                        return 0;
                    }
                    );

                data.RemoveRange(data.Count - (data.Count / 16), data.Count / 16);

                double[] x = LeastSq(data);

                System.Console.WriteLine("Old Method {0} {1} {2}", -(maxx + minx) / 2, -(maxy + miny) / 2, -(maxz + minz) / 2);

                log.Info("Least Sq Done " + DateTime.Now);

                // create a dxf for those who want to "see" the calibration
                DxfDocument dxf = new DxfDocument();

                Polyline3d polyline = new Polyline3d(vertexes, true);
                polyline.Layer = new Layer("polyline3d");
                polyline.Layer.Color.Index = 24;
                dxf.AddEntity(polyline);

                Point pnt = new Point(new Vector3f(-offset.Item1, -offset.Item2, -offset.Item3));
                pnt.Layer = new Layer("old offset");
                pnt.Layer.Color.Index = 22;
                dxf.AddEntity(pnt);

                pnt = new Point(new Vector3f(-(float)x[0], -(float)x[1], -(float)x[2]));
                pnt.Layer = new Layer("new offset");
                pnt.Layer.Color.Index = 21;
                dxf.AddEntity(pnt);

                dxf.Save("magoffset.dxf", DxfVersion.AutoCad2000);

                log.Info("dxf Done " + DateTime.Now);

                Array.Resize<double>(ref x, 3);

                return x;
        }
Beispiel #47
0
        //画完整的一个单门(门闩,把手,支架)
        public static void writeWholeSingleDoor(DxfDocument dxf, Location location, string[] text, float height, float width, float outer_mid_space, float outer_in_space, float barHeight, float barWidth,string upOrDownLayer)
        {
            writeDoorBarRectangle(dxf, location, text, height, width, outer_mid_space, outer_in_space, barHeight, barWidth);
            float downLeftX=location.X+outer_mid_space-barWidth/2+(outer_in_space-outer_mid_space)/2;
            float downLeftY=location.Y + height / 4;
            writeRepresentDoorBarRectangle(dxf, new Location(downLeftX,downLeftY , location.Z), text, height, width, outer_mid_space, outer_in_space, barHeight, barWidth);
            float upLeftX = downLeftX;
            float upLeftY = location.Y + 3 * height / 4 - barHeight;
            writeRepresentDoorBarRectangle(dxf, new Location(upLeftX,upLeftY , location.Z), text, height, width, outer_mid_space, outer_in_space, barHeight, barWidth);

            //画小支架
            if (upOrDownLayer.Equals("downLayer"))
            {
                //左下角
                writeOuterDoorRectangle(dxf, new Location(location.X, location.Y - outer_in_space, location.Z), outer_in_space, outer_in_space - outer_mid_space);
                //右下角
                writeOuterDoorRectangle(dxf, new Location(location.X + width + outer_mid_space - outer_in_space, location.Y - outer_in_space, location.Z), outer_in_space, outer_in_space - outer_mid_space);
            }
            //画门把手
            Handle.Draw(dxf, new Location(location.X + 3 * width / 4, location.Y + 3 * height / 4 - barHeight, location.Z));
            Handle.Draw(dxf, new Location(location.X + 3 * width / 4, location.Y + height / 4, location.Z));
        }
Beispiel #48
0
        /// <summary>
        /// 门把手绘制
        /// </summary>
        /// <param name="dxf"></param>
        /// <param name="location"></param>
        public static void Draw(DxfDocument dxf, Location location)
        {
            float factor = 0.05f;
             float distance = 30;
            //底部小圆的圆心
             Vector3f sCircle = new Vector3f(location.X + 10 * factor, location.Y, location.Z);
            //上部同心圆圆心
             Vector3f bCircle = new Vector3f(location.X + 10 * factor, location.Y + 5 * factor + distance*factor, location.Z);

             double alpha = Math.Asin(3 / distance);
             double beta = Math.Acos(0.8);

             Vector3f v1 = new Vector3f(
                 location.X + 10 * factor - float.Parse((5 * factor * Math.Cos(alpha)).ToString()),
                 location.Y + 5 * factor - float.Parse((5 * factor * Math.Sin(alpha)).ToString()),
                 location.Z);

             Vector3f v2 = new Vector3f(
                  location.X + 10 * factor + float.Parse((5 * factor * Math.Cos(alpha)).ToString()),
                  location.Y + 5 * factor - float.Parse((5 * factor * Math.Sin(alpha)).ToString()),
                  location.Z);

             Vector3f v4 = new Vector3f(
                 location.X + 10 * factor -float.Parse((8*factor* Math.Cos(alpha)).ToString()),
                 location.Y + 5 * factor + distance * factor - float.Parse((8 * factor * Math.Sin(alpha)).ToString()),
                 location.Z
                 );

             Vector3f v5 = new Vector3f(
             location.X + 10 * factor  + float.Parse((8*factor*Math.Cos(alpha)).ToString()),
             location.Y + 5 * factor + distance * factor - float.Parse((8 * factor * Math.Sin(alpha)).ToString()),
             location.Z
             );
             Layer layer = new Layer("line");
             Line line14 = new Line(v1, v4);
             line14.Layer = layer;
             line14.Layer.Color.Index = 6;
             dxf.AddEntity(line14);

             Line line25 = new Line(v2, v5);
             line25.Layer = new Layer("line");
             line25.Layer = layer;
             dxf.AddEntity(line25);

             //arc
             Arc arc = new Arc(
                 new Vector3f(location.X + 10 * factor, location.Y + 5 * factor, location.Z),
                 5 * factor, Convert.ToInt32(180 + alpha * 180 / Math.PI), Convert.ToInt32(360 - alpha * 180 / Math.PI));
             arc.Layer = layer;
             dxf.AddEntity(arc);

             //arcup
             Arc arcup = new Arc(
                 new Vector3f(location.X + 10 * factor, location.Y + 5 * factor + distance * factor, location.Z),
                 8 * factor, Convert.ToInt32(-alpha * 180 / Math.PI), Convert.ToInt32(180 + alpha * 180 / Math.PI));
             arcup.Layer = layer;
             dxf.AddEntity(arcup);

             //arcround
             Arc arcround = new Arc(
                 new Vector3f(location.X + 10 * factor, location.Y + 5 * factor + distance * factor, location.Z),
                 10 * factor,
                 Convert.ToInt32(-(alpha +beta) * 180 / Math.PI),
                 Convert.ToInt32(180 + (alpha +beta) * 180 / Math.PI));
             arcround.Layer = layer;
             dxf.AddEntity(arcround);

             //circle
             Vector3f extrusion = new Vector3f(0, 0, 1);
             Vector3f centerWCS = new Vector3f(location.X+10*factor, location.Y+5*factor+distance*factor, location.Z);
             Vector3d centerOCS = MathHelper.Transform((Vector3d)centerWCS,
                                                       (Vector3d)extrusion,
                                                       MathHelper.CoordinateSystem.World,
                                                       MathHelper.CoordinateSystem.Object);

             Circle circle = new Circle((Vector3f)centerOCS, 7*factor);
             circle.Layer = layer;
             circle.LineType = LineType.Continuous;
             circle.Normal = extrusion;
             dxf.AddEntity(circle);

             //上部同心圆圆心
             Vector3f t1 = new Vector3f(
                 location.X + 8 * factor,
                 location.Y + 5 * factor + (distance - 7) * factor * 0.7f,
                 location.Z);
             Vector3f t2 = new Vector3f(
                 location.X + 8 * factor,
                 location.Y + 5 * factor + (distance - 7) * factor * 0.5f,
                 location.Z);
             Vector3f t3 = new Vector3f(
                 location.X + 8 * factor,
                 location.Y + 5 * factor + (distance - 7) * factor * 0.3f,
                 location.Z);
             Vector3f t4 = new Vector3f(
                 location.X + 8 * factor,
                 location.Y + 5 * factor + (distance - 7) * factor * 0.1f,
                 location.Z);

             //text
             TextStyle style = new TextStyle("True type font", "Arial.ttf");
             Text text1 = new Text("A", t1, 0.2f, style);
             text1.Layer = layer;
             text1.Alignment = TextAlignment.TopLeft;
             dxf.AddEntity(text1);

             //text
             Text text2 = new Text("A", t2, 0.2f, style);
             text2.Layer = layer;
             text2.Alignment = TextAlignment.TopLeft;
             dxf.AddEntity(text2);

             //text
             Text text3 = new Text("O", t3, 0.2f, style);
             text3.Layer = layer;
             text3.Alignment = TextAlignment.TopLeft;
             dxf.AddEntity(text3);

             //text
             Text text4 = new Text("N", t4, 0.2f, style);
             text4.Layer = layer;
             text4.Alignment = TextAlignment.TopLeft;
             dxf.AddEntity(text4);
        }
		public void WriteProject(WaveguideDesignerProjectData project)
			{
			if( project == null ) return;

			Type type;
			EntityObject obj = null;
			DxfDocument doc = new DxfDocument();

			doc.Name = project.Name;

			Layer dxfLayer;
			LayerData layerData;
			foreach( VirtualLayer vLayer in project.VirtualGraphics.Layers )
				{
				layerData = null;
				foreach( LayerData tmp in project.Layers )
					if( tmp.VirtualLayer == vLayer )
						{
						layerData = tmp;
						break;
						}
				if( layerData == null ) continue;
				dxfLayer = new Layer( layerData.Name );
				dxfLayer.Color.Index = (short)layerData.LayerNumber;
				doc.Layers.Add( dxfLayer );

				foreach( VirtualShapeBase vShape in vLayer.Shapes )
					{
					type = vShape.GetType();
					if( type == typeof( VirtualRectangle ) )
						{
						VirtualRectangle rect = (VirtualRectangle)vShape;
						Polyline dxfrect = new Polyline();
						obj = new Polyline();
						dxfrect.IsClosed = true;
						dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X, rect.Location.Y, 0 ) );
						dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X + rect.Size.W, rect.Location.Y, 0 ) );
						dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X + rect.Size.W, rect.Location.Y + rect.Size.H, 0 ) );
						dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X, rect.Location.Y + rect.Size.H, 0 ) );
						dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X, rect.Location.Y, 0 ) );
						obj = dxfrect;
						}
					else if( type == typeof( VirtualPolygon ) )
						{
						VirtualPolygon poly = (VirtualPolygon)vShape;
						Polyline dxfpoly = new Polyline();
						dxfpoly.IsClosed = true;
						foreach( PointD p in poly.Vertices )
							dxfpoly.Vertexes.Add( conv( p ) );
						dxfpoly.Vertexes.Add( conv( poly.Vertices[0] ) );
						obj = dxfpoly;
						}
					else if( type == typeof( VirtualEllipse ) )
						{
						VirtualEllipse elli = (VirtualEllipse)vShape;
						Ellipse dxfelli = new Ellipse();
						dxfelli.Center = new netDxf.Vector3( elli.Center.X, elli.Center.Y, 0 );
						dxfelli.StartAngle = 0;
						dxfelli.EndAngle = 360;
						dxfelli.MajorAxis = Math.Max( elli.Radius.W, elli.Radius.H );
						dxfelli.MinorAxis = Math.Min( elli.Radius.W, elli.Radius.H );
						dxfelli.Rotation = elli.Radius.W >= elli.Radius.H ? 0 : 90;
						obj = dxfelli;
						}
					else if( type == typeof( VirtualPie ) )
						{
						VirtualPie pie = (VirtualPie)vShape;
						Ellipse dxfelli = new Ellipse();
						dxfelli.Center = new netDxf.Vector3( pie.Center.X, pie.Center.Y, 0 );
						dxfelli.StartAngle = pie.StartAngle;
						dxfelli.EndAngle = pie.EndAngle;
						dxfelli.MajorAxis = Math.Max( pie.Radius.W, pie.Radius.H );
						dxfelli.MinorAxis = Math.Min( pie.Radius.W, pie.Radius.H );
						dxfelli.Rotation = pie.Radius.W >= pie.Radius.H ? 0 : 90;
						obj = dxfelli;
						}
					else obj = null;

					if( obj == null )
						continue;
					obj.Layer = dxfLayer;
					doc.AddEntity( obj );
					}
				}

			doc.Save( FileName );
			}