Beispiel #1
0
        private List <_Ge.Point3d> getPolylinePoints(_Db.Polyline poly)
        {
            List <_Ge.Point3d> points = new List <_Ge.Point3d>();

            int verts = poly.NumberOfVertices;

            for (int i = 1; i < verts; i++)
            {
                _Ge.Point3d start = poly.GetPoint3dAt(i - 1);
                _Ge.Point3d end   = poly.GetPoint3dAt(i);

                double midX = start.X + ((end.X - start.X) / 2);
                double midY = start.Y + ((end.Y - start.Y) / 2);

                _Ge.Point3d mid = new _Ge.Point3d(midX, midY, 0);

                points.Add(start);
                points.Add(end);
                points.Add(mid);
            }

            if (poly.Closed)
            {
                _Ge.Point3d start = poly.GetPoint3dAt(verts - 1);
                _Ge.Point3d end   = poly.GetPoint3dAt(0);

                double midX = start.X + ((end.X - start.X) / 2);
                double midY = start.Y + ((end.Y - start.Y) / 2);

                _Ge.Point3d mid = new _Ge.Point3d(midX, midY, 0);

                points.Add(mid);
            }

            return(points);
        }
        private static bool PolyInPoly(_AcDb.TransactionManager tm, _AcDb.ObjectId oid, _AcDb.ObjectId elFG)
        {
            using (_AcDb.DBObject pEntity = tm.GetObject(oid, _AcDb.OpenMode.ForRead, false))
            {
                using (_AcDb.DBObject pElFG = tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false))
                {
                    if (pEntity is _AcDb.Polyline2d)
                    {
                        _AcDb.Polyline2d oldPolyline = (_AcDb.Polyline2d)pEntity;
                        foreach (_AcDb.ObjectId Vertex2d in oldPolyline)
                        {
                            using (_AcDb.DBObject dbobj = tm.GetObject(Vertex2d, _AcDb.OpenMode.ForRead, false))
                            {
                                _AcDb.Vertex2d vertex = dbobj as _AcDb.Vertex2d;

                                if (vertex == null)
                                {
                                    string msg = string.Format(CultureInfo.CurrentCulture, "Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", oldPolyline.Handle.ToString(), dbobj.GetType().ToString());
                                    throw new InvalidOperationException(string.Format(msg));
                                }

                                _AcGe.Point3d vertexPoint = oldPolyline.VertexPosition(vertex);
                                if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)pElFG))
                                {
                                    return(false);
                                }
                            }
                        }
                        return(true);
                    }
                    else if (pEntity is _AcDb.Polyline3d)
                    {
                        _AcDb.Polyline3d poly3d = (_AcDb.Polyline3d)pEntity;
                        foreach (_AcDb.ObjectId Vertex3d in poly3d)
                        {
                            using (_AcDb.DBObject dbobj = tm.GetObject(Vertex3d, _AcDb.OpenMode.ForRead, false))
                            {
                                _AcDb.PolylineVertex3d vertex = dbobj as _AcDb.PolylineVertex3d;

                                if (vertex == null)
                                {
                                    string msg = string.Format(CultureInfo.CurrentCulture, "3D-Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", poly3d.Handle.ToString(), dbobj.GetType().ToString());
                                    throw new InvalidOperationException(string.Format(msg));
                                }

                                _AcGe.Point3d vertexPoint = vertex.Position;
                                if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)pElFG))
                                {
                                    return(false);
                                }
                            }
                        }
                        return(true);
                    }
                    else if (pEntity is _AcDb.Polyline)
                    {
                        _AcDb.Polyline poly = pEntity as _AcDb.Polyline;
                        for (int i = 0; i < poly.NumberOfVertices; i++)
                        {
                            _AcGe.Point3d vertexPoint = poly.GetPoint3dAt(i);
                            if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)pElFG))
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #3
0
        private static bool PolyInPoly(_AcDb.Transaction tm, _AcDb.Entity inner, _AcDb.Entity outer)
        {
            if (inner == outer)
            {
                return(false);
            }
            if (!OverlapExtents(inner, outer))
            {
                return(false);
            }

            NrOfOverlaps++;

            if (inner is _AcDb.Polyline)
            {
                _AcDb.Polyline poly = inner as _AcDb.Polyline;
                for (int i = 0; i < poly.NumberOfVertices; i++)
                {
                    _AcGe.Point3d vertexPoint = poly.GetPoint3dAt(i);
                    if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)outer))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            else if (inner is _AcDb.Polyline2d)
            {
                _AcDb.Polyline2d oldPolyline = (_AcDb.Polyline2d)inner;
                foreach (_AcDb.ObjectId Vertex2d in oldPolyline)
                {
                    using (_AcDb.DBObject dbobj = tm.GetObject(Vertex2d, _AcDb.OpenMode.ForRead, false))
                    {
                        _AcDb.Vertex2d vertex = dbobj as _AcDb.Vertex2d;

                        if (vertex == null)
                        {
                            string msg = string.Format(CultureInfo.CurrentCulture, "Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", oldPolyline.Handle.ToString(), dbobj.GetType().ToString());
                            throw new InvalidOperationException(string.Format(msg));
                        }

                        _AcGe.Point3d vertexPoint = oldPolyline.VertexPosition(vertex);
                        if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)outer))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            else if (inner is _AcDb.Polyline3d)
            {
                _AcDb.Polyline3d poly3d = (_AcDb.Polyline3d)inner;
                foreach (_AcDb.ObjectId Vertex3d in poly3d)
                {
                    using (_AcDb.DBObject dbobj = tm.GetObject(Vertex3d, _AcDb.OpenMode.ForRead, false))
                    {
                        _AcDb.PolylineVertex3d vertex = dbobj as _AcDb.PolylineVertex3d;

                        if (vertex == null)
                        {
                            string msg = string.Format(CultureInfo.CurrentCulture, "3D-Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", poly3d.Handle.ToString(), dbobj.GetType().ToString());
                            throw new InvalidOperationException(string.Format(msg));
                        }

                        _AcGe.Point3d vertexPoint = vertex.Position;
                        if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)outer))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unknown entitytype '{0}'!", inner.GetType().Name));
        }