Example #1
0
        private void DrawToLeft(int x, int y, CADShape shape, List <CADShape> shapes, DxfDocument dxf)
        {
            var line = new Line(new Vector2(x, y), new Vector2(shape.X, shape.Y2)); //Desenhando o lado de baixo para esquerda

            line.Layer = _layerParede;
            dxf.AddEntity(line);

            //Tentando ir para baixo
            var bottomShape = shapes.FirstOrDefault(s => s.X2 == shape.X && s.Y >= shape.Y2 && s.Y2 < shape.Y2);

            if (bottomShape != null)
            {
                DrawToBottom(shape.X, shape.Y2, bottomShape, shapes, dxf);
                return;
            }

            //Tentando ir para esquerda
            var leftShape = shapes.FirstOrDefault(s => s.X2 == x && s.Y2 == y);

            if (leftShape != null)
            {
                DrawToLeft(shape.X, shape.Y2, leftShape, shapes, dxf);
                return;
            }

            DrawToTop(shape.X, shape.Y2, shape, shapes, dxf);
        }
Example #2
0
        public static CADShape ToCADShape(this ObjectId objId)
        {
            CADShape sp       = new CADShape();
            var      dbObject = objId.QOpenForRead();
            var      entity   = objId.QOpenForRead <Entity>();

            sp.Name  = entity.GetType().Name;
            sp.Type  = entity.GetType().Name;
            sp.Layer = entity.Layer;
            if (entity is BlockReference)
            {
                sp.Name = "Block";
                sp.AddPoints(entity.GeometricExtents);
            }
            else if (entity is Line)
            {
                sp.AddPoints(entity as Line);
            }
            else if (entity is Polyline)
            {
                sp.AddPoints(entity as Polyline);
            }
            else
            {
                sp = null;
            }

            return(sp);
        }
 public static CADShape AddPoints(this CADShape sp, Line line, bool isToUCS)
 {
     sp.AddPoint(line.StartPoint, isToUCS);
     sp.AddPoint(line.EndPoint, isToUCS);
     sp.Entity = line;
     return(sp);
 }
Example #4
0
        public static CADPoint AddPoint(this CADShape sp, Point3d pt)
        {
            var point = pt.ToCADPoint();

            sp.Points.Add(point);
            return(point);
        }
Example #5
0
        private void DrawToTop(int x, int y, CADShape shape, List <CADShape> shapes, DxfDocument dxf)
        {
            var line = new Line(new Vector2(x, y), new Vector2(shape.X, shape.Y)); //Desenhando lado esquerdo para cima

            line.Layer = _layerParede;
            dxf.AddEntity(line);

            if (shape == shape.Place.OriginShape) //Terminou de desenhar todo o comodo
            {
                return;
            }

            //Tentando ir para esquerda
            var leftShape = shapes.FirstOrDefault(s => s.X2 == x && s.Y2 == y);

            if (leftShape != null)
            {
                DrawToLeft(shape.X, shape.Y, leftShape, shapes, dxf);
                return;
            }

            //Tentando ir para direita
            var topShape = shapes.FirstOrDefault(s => s.X == x && s.Y2 == y);

            if (topShape != null)
            {
                DrawToTop(shape.X, shape.Y, topShape, shapes, dxf);
                return;
            }

            DrawToRight(shape.X, shape.Y, shape, shapes, dxf);
        }
Example #6
0
        private void DrawToRight(int x, int y, CADShape shape, List <CADShape> shapes, DxfDocument dxf)
        {
            var line = new Line(new Vector2(x, y), new Vector2(shape.X2, shape.Y)); //Desenhando o topo para direita

            line.Layer = _layerParede;
            dxf.AddEntity(line);

            //Tentando ir para cima
            var topShape = shapes.FirstOrDefault(s => s.X == shape.X2 && s.Y2 == y);

            if (topShape != null)
            {
                DrawToTop(shape.X2, shape.Y, topShape, shapes, dxf);
                return;
            }

            //Tentando ir para direita
            var rightShape = shapes.FirstOrDefault(s => s.X == shape.X2 && s.Y == y);

            if (rightShape != null)
            {
                DrawToRight(shape.X2, shape.Y, rightShape, shapes, dxf);
                return;
            }

            DrawToBottom(shape.X2, shape.Y, shape, shapes, dxf);
        }
        public static CADPoint AddPoint(this CADShape sp, Point3d pt, bool isToUCS)
        {
            var point = pt.ToCADPoint(isToUCS);

            sp.Points.Add(point);
            return(point);
        }
Example #8
0
        private void DrawToBottom(int x, int y, CADShape shape, List <CADShape> shapes, DxfDocument dxf)
        {
            var line = new Line(new Vector2(x, y), new Vector2(shape.X2, shape.Y2)); //Desenhando o lado direito para baixo

            line.Layer = _layerParede;
            dxf.AddEntity(line);

            //Tentando ir para direita
            var rightShape = shapes.FirstOrDefault(s => s.X <= shape.X2 && s.X2 > shape.X2 && s.Y == shape.Y2);

            if (rightShape != null)
            {
                DrawToRight(shape.X2, shape.Y2, rightShape, shapes, dxf);
                return;
            }

            //Tentando ir para baixo
            var bottomShape = shapes.FirstOrDefault(s => s.X2 == shape.X2 && s.Y == shape.Y2);

            if (bottomShape != null)
            {
                DrawToBottom(shape.X2, shape.Y2, bottomShape, shapes, dxf);
                return;
            }

            DrawToLeft(shape.X2, shape.Y2, shape, shapes, dxf);
        }
        public static CADShape AddPoints(this CADShape sp, MText mText, bool isToUCS)
        {
            var center = mText.GetCenter();

            sp.AddPoint(mText.Location, isToUCS);
            sp.Entity = mText;
            return(sp);
        }
Example #10
0
        public static CADShape AddPoints(this CADShape sp, Polyline line)
        {
            var points = line.GetPoints();

            foreach (var point in points)
            {
                sp.AddPoint(point);
            }
            return(sp);
        }
Example #11
0
        public static CADShape AddPoints(this CADShape sp, Polyline line, bool isToUCS)
        {
            var points = line.GetPoints();

            foreach (var point in points)
            {
                sp.AddPoint(point, isToUCS);
            }
            sp.Entity = line;
            return(sp);
        }
Example #12
0
        //public static CADShape AddPoints(this CADShape sp, BlockReference block)
        //{
        //    sp.AddPoints(block.GeometricExtents);
        //    sp.Entity = block;
        //    return sp;
        //}

        public static CADShape AddPoints(this CADShape sp, Entity entity, bool isToUCS)
        {
            if (entity.GeometricExtents != null)
            {
                sp.AddPoints(entity.GeometricExtents, isToUCS);
                sp.Entity = entity;
            }


            return(sp);
        }
Example #13
0
        public static CADShape AddPoints(this CADShape sp, Extents3d extents, bool isToUCS)
        {
            var p11 = extents.MinPoint;
            var p22 = extents.MaxPoint;
            var p21 = new Point3d(p22.X, p11.Y, p11.Z);
            var p12 = new Point3d(p11.X, p22.Y, p22.Z);

            sp.AddPoint(p11, isToUCS);
            sp.AddPoint(p21, isToUCS);
            sp.AddPoint(p22, isToUCS);
            sp.AddPoint(p12, isToUCS);
            return(sp);
        }
Example #14
0
        public static void GetExtentPoints()
        {
            var      objId = Interaction.GetEntity("Entity");
            CADShape shape = objId.ToCADShape(true);

            if (shape != null)
            {
                string xml = shape.ToXml();
                MyTool.TextReport("Points", xml, 700, 500);
            }
            else
            {
                MyTool.TextReport("Points", "NULL", 700, 500);
            }
        }
Example #15
0
        /// <summary>
        /// 根据图形获取该图形内的名称
        /// </summary>
        /// <param name="sp"></param>
        /// <returns></returns>
        public static string getShapeName(CADShape sp)
        {
            string name = "";

            double pMinX = double.MaxValue;
            double pMinY = double.MaxValue;
            double pMaxX = double.MinValue;
            double pMaxY = double.MinValue;

            //查找 多边型 最小的点,和最大点的坐标
            foreach (CADPoint p1 in sp.Points)
            {
                if (p1.X < pMinX)
                {
                    pMinX = p1.X;
                }
                if (p1.Y < pMinY)
                {
                    pMinY = p1.Y;
                }

                if (p1.Y > pMaxY)
                {
                    pMaxY = p1.Y;
                }
                if (p1.X > pMaxX)
                {
                    pMaxX = p1.X;
                }
            }

            Point3d pMin = new Point3d(pMinX, pMinY, 0);
            Point3d pMax = new Point3d(pMaxX, pMaxY, 0);

            if (sp.Points.Count == 2)
            {
                pMin = new Point3d(sp.Points[0].X, sp.Points[0].Y, 0);
                pMax = new Point3d(sp.Points[1].X, sp.Points[1].Y, 0);
            }



            name = GetRoomsCommand.GetText(pMin, pMax);


            return(name);
        }
Example #16
0
 public void addShape(CADShape P)
 {
     shapelist.Add(P);
 }
        private void Worker2_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker1  = sender as BackgroundWorker;
            string           basePath = AppDomain.CurrentDomain.BaseDirectory;
            string           filePath = basePath + "Data\\CADAreaInfo.xml";

            CADAreaList list = XmlSerializeHelper.LoadFromFile <CADAreaList>(filePath);

            list.LineToBlock();

            Bll          bll       = new Bll();
            var          areas     = bll.Areas.ToList(false);
            List <Point> newPoints = new List <Point>();
            List <Area>  newBounds = new List <Area>();
            List <Area>  newAreas  = new List <Area>();
            int          count     = 0;

            for (int i1 = 0; i1 < list.Count; i1++)
            {
                CADArea item = list[i1];
                var     area = areas.Find(i => i.Name == item.Name);
                if (area != null)
                {
                    count += item.Shapes.Count;
                }
            }



            int index = 0;

            for (int i1 = 0; i1 < list.Count; i1++)
            {
                CADArea item = list[i1];
                var     area = areas.Find(i => i.Name == item.Name);
                if (area != null)
                {
                    for (int i = 0; i < item.Shapes.Count; i++)
                    {
                        index++;
                        CADShape sp    = item.Shapes[i];
                        Bound    bound = new Bound();
                        bool     r1    = bll.Bounds.Add(bound);
                        if (r1)
                        {
                            Area newArea = new Area();
                            newArea.Name      = sp.Name;
                            newArea.Type      = AreaTypes.CAD;
                            newArea.ParentId  = area.Id;
                            newArea.InitBound = bound;
                            var r2 = bll.Areas.Add(newArea);
                            if (r2)
                            {
                                var pointList = new List <Point>();
                                foreach (var pt in sp.Points)
                                {
                                    var point = new Point();
                                    point.X       = (float)pt.X / 1000 - 0.1f;
                                    point.Y       = (float)pt.Y / 1000 - 0.1f;
                                    point.BoundId = bound.Id;
                                    var r3 = bll.Points.Add(point);
                                    pointList.Add(point);
                                }
                                bound.Shape      = 0;
                                bound.IsRelative = true;
                                bound.SetInitBound(pointList.ToArray(), area.InitBound.MinZ, (float)area.InitBound.GetHeight());

                                bool r4 = bll.Bounds.Edit(bound);
                                newArea.SetBound(bound);
                                bll.Areas.Edit(newArea);
                            }
                        }

                        int percent = (int)((index + 0.0) / count * 100);
                        worker1.ReportProgress(percent);
                    }
                }
            }

            //bll.Areas.AddRange(newAreas);
        }
Example #18
0
 public static CADShape AddPoints(this CADShape sp, Circle circle, bool isToUCS)
 {
     sp.AddPoint(circle.Center, isToUCS);
     sp.Entity = circle;
     return(sp);
 }
Example #19
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            List <CADShape> shapes = new List <CADShape>();
            List <CADPlace> places = new List <CADPlace>();

            var cozinha = new CADPlace("Cozinha");

            places.Add(cozinha);

            var cozinhaShape1 = new CADShape(cozinha)
            {
                Width  = 6800,
                Height = 3000
            };

            shapes.Add(cozinhaShape1);

            var cozinhaShape2 = new CADShape(cozinha)
            {
                Width  = 1700,
                Height = 2500
            };

            shapes.Add(cozinhaShape2);
            cozinhaShape1.RightShape = cozinhaShape2;

            var cozinhaShape3 = new CADShape(cozinha)
            {
                Width  = 2450,
                Height = 1500
            };

            shapes.Add(cozinhaShape3);
            cozinhaShape2.RightShape = cozinhaShape3;

            var elevador = new CADPlace("Elevador");

            places.Add(elevador);
            var elevadorShape = new CADShape(elevador)
            {
                Width  = 1500,
                Height = 1500
            };

            shapes.Add(elevadorShape);
            cozinhaShape2.BottomShape = elevadorShape;

            var suite = new CADPlace("Suite");

            places.Add(suite);
            var suiteShape = new CADShape(suite)
            {
                Width  = 3000,
                Height = 1500
            };

            shapes.Add(suiteShape);
            cozinhaShape3.RightShape = suiteShape;

            var quarto = new CADPlace("Quarto");

            places.Add(quarto);
            var quartoShape = new CADShape(quarto)
            {
                Width  = 3000,
                Height = 5900
            };

            shapes.Add(quartoShape);
            suiteShape.RightShape = quartoShape;

            var musculacao = new CADPlace("Musculacao");

            places.Add(musculacao);
            var musculacaoShape = new CADShape(musculacao)
            {
                Width  = 3000,
                Height = 3000
            };

            shapes.Add(musculacaoShape);
            suiteShape.BottomShape = musculacaoShape;

            var sala = new CADPlace("Sala");

            places.Add(sala);
            var salaShape1 = new CADShape(sala)
            {
                Width  = 6800,
                Height = 1200
            };

            shapes.Add(salaShape1);
            cozinhaShape1.BottomShape = salaShape1;

            var salaShape2 = new CADShape(sala)
            {
                Width  = 8500,
                Height = 500
            };

            shapes.Add(salaShape2);
            salaShape1.BottomShape = salaShape2;

            var salaShape3 = new CADShape(sala)
            {
                Width  = 8500,
                Height = 9500
            };

            shapes.Add(salaShape3);
            salaShape2.BottomShape = salaShape3;

            var corredor = new CADPlace("Corredor");

            places.Add(corredor);
            var corredorShape1 = new CADShape(corredor)
            {
                Width  = 1250,
                Height = 1000
            };

            shapes.Add(corredorShape1);
            salaShape3.RightShape = corredorShape1;

            var corredorShape2 = new CADShape(corredor)
            {
                Width  = 4200,
                Height = 1000
            };

            shapes.Add(corredorShape2);
            corredorShape1.RightShape = corredorShape2;

            var banheiro = new CADPlace("Banheiro");

            places.Add(banheiro);
            var banheiroShape1 = new CADShape(banheiro)
            {
                Width  = 1000,
                Height = 1500
            };

            shapes.Add(banheiroShape1);
            corredorShape2.TopShape = banheiroShape1;

            var designer = new Designer();

            designer.DesignCAD(@"D:/Niteroi/Projetos/CADs/teste.dxf", shapes, places);

            Console.WriteLine("Design finish !");
        }
Example #20
0
 public static CADShape AddPoints(this CADShape sp, Line line)
 {
     sp.AddPoint(line.StartPoint);
     sp.AddPoint(line.EndPoint);
     return(sp);
 }
Example #21
0
        /// <summary>
        /// 判断是否是封闭的的图形
        /// </summary>
        /// <param name="old"></param>
        /// <returns></returns>
        public static bool ifColseShape(CADShape sp)
        {
            bool     bret = false;
            CADShape sp1  = new CADShape();

            Dictionary <string, CADPoint> dicPoint    = new Dictionary <string, CADPoint>();
            Dictionary <string, CADPoint> dicPointtmp = new Dictionary <string, CADPoint>();

            Dictionary <string, int> dicPointtmp1 = new Dictionary <string, int>();

            //去除相同的点
            foreach (CADPoint vl in sp.Points)
            {
                string tmp = vl.ToString();

                if (dicPoint.ContainsKey(tmp))
                {
                    dicPointtmp[tmp] = vl;
                }
                else
                {
                    dicPoint[tmp] = vl;
                }
            }
            //去除相同的点
            foreach (KeyValuePair <string, CADPoint> vl in dicPointtmp)
            {
                sp.Points.Remove(vl.Value);
            }

            //表示线的数量为偶数,如果是奇数的话,表示非 闭环的环境
            if ((sp.Points.Count & 1) != 1)
            {
                foreach (CADPoint vl in sp.Points)
                {
                    string xpos = "x_" + Math.Round(vl.X).ToString();
                    string ypos = "y_" + Math.Round(vl.Y).ToString();

                    int ncount = 1;
                    if (dicPointtmp1.ContainsKey(xpos))
                    {
                        ncount = dicPointtmp1[xpos];
                        ncount++;
                    }

                    dicPointtmp1[xpos] = ncount;

                    ncount = 1;
                    if (dicPointtmp1.ContainsKey(ypos))
                    {
                        ncount = dicPointtmp1[ypos];
                        ncount++;
                    }

                    dicPointtmp1[ypos] = ncount;
                }

                bret = true;
                foreach (KeyValuePair <string, int> vl in dicPointtmp1)
                {
                    if (vl.Value != 2)
                    {
                        bret = false;
                        break;
                    }
                }
            }

            return(bret);
        }
Example #22
0
        public static CADShape ToCADShape(this ObjectId objId, bool isToUCS)
        {
            CADShape sp = new CADShape();

            try
            {
                //var dbObject = objId.QOpenForRead();
                var entity = objId.QOpenForRead <Entity>();
                sp.Name  = entity.GetType().Name;
                sp.Type  = entity.GetType().Name;
                sp.Layer = entity.Layer;
                if (entity is BlockReference)
                {
                    sp.Name = "Block";
                    sp.AddPoints(entity as BlockReference, isToUCS);
                }
                else if (entity is Line)
                {
                    sp.AddPoints(entity as Line, isToUCS);
                }
                else if (entity is Polyline)
                {
                    sp.AddPoints(entity as Polyline, isToUCS);

                    // string name = GetRoomsCommand.GetText(entity.Bounds.MinPoint, entity.Bounds.MaxPoint);
                }
                else if (entity is MLeader)
                {
                    MLeader mleader = entity as MLeader;
                    if (mleader.MText != null)
                    {
                        sp.Text = mleader.MText.Text;
                    }
                    //sp.AddPoints(entity as MLeader);
                }
                else if (entity is Circle)
                {
                    Circle circle = entity as Circle;
                    //if (mleader.MText != null)
                    //    sp.Text = mleader.MText.Text;
                    sp.AddPoints(circle, isToUCS);
                }
                else if (entity is MText)
                {
                    MText text = entity as MText;
                    sp.Text = text.Text;
                    //text.InsertionPoint(0);
                    sp.AddPoints(text, isToUCS);
                }
                else if (entity is DBText)
                {
                    DBText text = entity as DBText;
                    sp.Text = text.TextString;
                    //text.InsertionPoint(0);
                    sp.AddPoints(text, isToUCS);
                }

                else if (entity is Hatch)
                {
                    Hatch hatch = entity as Hatch;
                    //sp.Text = text.Text;
                    //text.InsertionPoint(0);
                    sp.AddPoints(hatch, isToUCS);
                }
                else if (entity is ProxyEntity)
                {
                    ProxyEntity pe = entity as ProxyEntity;
                    sp.Name = pe.OriginalDxfName;
                    sp.Type = "ProxyEntity";
                    sp.Text = pe.OriginalClassName;
                }
                else
                {
                    //sp = null;
                    sp.AddPoints(entity, isToUCS);
                }

                // objId.q
            }
            catch (Exception ex)
            {
                sp.Name = "Exception";
                sp.Text = ex.Message;
            }

            return(sp);
        }