Пример #1
0
        //Find the index of the endpoints of a line in the list of bending planes
        public static int[] findEndIndexes(Line ln, List <Point3d> planeOrigins)
        {
            Point3d lnStart = new Point3d(Math.Round(ln.FromX, 3), Math.Round(ln.FromY, 3), Math.Round(ln.FromZ, 3));
            Point3d lnEnd   = new Point3d(Math.Round(ln.ToX, 3), Math.Round(ln.ToY, 3), Math.Round(ln.ToZ, 3));

            int indexStart = -1;
            int indexEnd   = -1;

            for (int i = 0; i < planeOrigins.Count; i++)
            {
                Point3d o = planeOrigins[i];

                if (o.Equals(lnStart))
                {
                    indexStart = i;
                }

                if (o.Equals(lnEnd))
                {
                    indexEnd = i;
                }
            }

            int[] indexes = new int[2] {
                indexStart, indexEnd
            };

            if (indexStart == -1 && indexEnd == -1)
            {
                throw new System.InvalidOperationException("Not able to find both start and end index for one or more lines");
            }

            return(indexes);
        }
Пример #2
0
        public override bool Equals(object obj)
        {
            // If parameter cannot be cast to ThreeDPoint return false:
            PointEmitterType p = obj as PointEmitterType;

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

            return(base.Equals(obj) && pt.Equals(p.pt));
        }
Пример #3
0
        protected override bool Update()
        {
            try
            {
                // Set the last vertex to the new value
                Leader leader = Entity as Leader;

                if (_mIsJigStarted)
                {
                    leader.RemoveLastVertex();
                }

                Point3d lastVertex = leader.VertexAt(leader.NumVertices - 1);
                if (!_mTempPoint.Equals(lastVertex))
                {
                    leader.AppendVertex(_mTempPoint);
                    _mIsJigStarted = true;
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(string.Format("{0} BB_JigSplineLeader.cs: line: 165", ex.Message));
            }
            return(true);
        }
Пример #4
0
        void editor_PointMonitor(object sender, PointMonitorEventArgs e)
        {
            Document activeDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            double   viewSize
                = (double)Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("VIEWSIZE");

            Point3d viewCtr
                = (Point3d)Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("VIEWCTR");

            Point3d viewDir
                = (Point3d)Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("VIEWDIR");

            // Simple check to verify if the view parameters changed
            // since we last drew the transient graphics
            if (viewSize != _viewSize ||
                viewCtr.Equals(_viewCtr) == false ||
                viewDir.Equals(_viewDir) == false
                )
            {
                _viewSize = viewSize;

                _viewCtr = (Point3d)Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("VIEWCTR");

                _viewDir = viewDir;
                Editor edit = sender as Editor;
                edit.WriteMessage(_viewCtr.ToString());
                // Draw the transient graphics again since
                // the view parameters seem to have changed
                // DrawTransientRectMethod();
            }
            //throw new NotImplementedException();
        }
Пример #5
0
            private void FindRaumBlocks(List <ObjectId> raumBlocks)
            {
                using (var myTrans = _TransMan.StartTransaction())
                {
                    Entity poly = _TransMan.GetObject(Polygon, OpenMode.ForRead) as Entity;
                    if (poly != null)
                    {
                        List <ObjectId> toRemove = new List <ObjectId>();
                        foreach (var oid in raumBlocks)
                        {
                            Entity  ent = _TransMan.GetObject(oid, OpenMode.ForRead) as Entity;
                            Point3d pos = GetRbPosition(ent);

                            if (!pos.Equals(default(Point3d)))
                            {
                                if (AreaEngine.InPoly(ClonePointSetZ(pos, _Height), poly))
                                {
                                    toRemove.Add(oid);
                                }
                            }
                        }

                        foreach (var oid in toRemove)
                        {
                            raumBlocks.Remove(oid);
                        }

                        RaumBlocks.AddRange(toRemove);
                        TheStatus = Status.Ok;
                    }

                    myTrans.Commit();
                }
            }
Пример #6
0
        protected override bool Update()
        {
            try
            {
                Leader leader = (Leader)Entity;

                if (_mIsJigStarted)
                {
                    if (leader.NumVertices > 1)
                    {
                        leader.RemoveLastVertex();
                    }
                }

                Point3d lastVertex = leader.VertexAt(leader.NumVertices - 1);
                if (!_mTempPoint.Equals(lastVertex))
                {
                    leader.AppendVertex(_mTempPoint);
                    _mIsJigStarted = true;
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " LdrText_JigLeader0.cs: line: 199");
            }
            return(true);
        }
Пример #7
0
        public void Point3dAndBadPoint3d_WithSameValues_AreNotEqual()
        {
            var value1 = new Point3d(4, 8, 15);
            var value2 = new BadPoint3d(4, 8, 15);

            Assert.IsFalse(value1.Equals(value2));
            Assert.IsFalse(value2.Equals(value1));
            Assert.IsFalse(value1 == value2);
            Assert.IsFalse(value2 == value1);
            Assert.IsTrue(value1 != value2);
            Assert.IsTrue(value2 != value1);
        }
Пример #8
0
        private int?GetJoint(Point3d joint, IEnumerable <Point3d> joints)
        {
            int?jointNode = null;

            for (int j = 0; j < joints.Count(); j++)
            {
                if (joint.Equals(joints.ElementAt(j)))
                {
                    jointNode = j;
                    break;
                }
            }

            return(jointNode);
        }
Пример #9
0
        public static void SetViewTo(Autodesk.AutoCAD.GraphicsSystem.View view, Database db)
        {
            if (_extMax.Equals(Point3d.Origin) && _extMin.Equals(Point3d.Origin))
            {
                // just check we have valid extents
                if (db.Extmax.X < db.Extmin.X || db.Extmax.Y < db.Extmin.Y || db.Extmax.Z < db.Extmax.Z)
                {
                    db.Extmin = new Point3d(0, 0, 0);
                    db.Extmax = new Point3d(400, 400, 400);
                }
                // get the dwg extents
                _extMax = db.Extmax;
                _extMin = db.Extmin;
            }

            // now the active viewport info
            double   height = 0.0, width = 0.0, viewTwist = 0.0;
            Point3d  targetView = new Point3d();
            Vector3d viewDir    = new Vector3d();

            GetActiveViewPortInfo(ref height, ref width, ref targetView, ref viewDir, ref viewTwist, true);
            // from the data returned let's work out the viewmatrix
            viewDir = viewDir.GetNormal();

            Vector3d viewXDir = viewDir.GetPerpendicularVector().GetNormal();

            viewXDir = viewXDir.RotateBy(viewTwist, -viewDir);
            Vector3d viewYDir  = viewDir.CrossProduct(viewXDir);
            Point3d  boxCenter = _extMin + 0.5 * (_extMax - _extMin);
            Matrix3d viewMat;

            viewMat = Matrix3d.AlignCoordinateSystem(boxCenter, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
                                                     boxCenter, viewXDir, viewYDir, viewDir).Inverse();
            Extents3d wcsExtents  = new Extents3d(_extMin, _extMax);
            Extents3d viewExtents = wcsExtents;

            viewExtents.TransformBy(viewMat);
            double  xMax = System.Math.Abs(viewExtents.MaxPoint.X - viewExtents.MinPoint.X);
            double  yMax = System.Math.Abs(viewExtents.MaxPoint.Y - viewExtents.MinPoint.Y);
            Point3d eye  = boxCenter + viewDir;

            view.SetView(eye, boxCenter, viewYDir, xMax, yMax);

            view.Invalidate();
            view.Update();
        }
Пример #10
0
        protected override bool Update()
        {
            try
            {
                Leader leader = Entity as Leader;

                Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
                if (_mIsJigStarted)
                {
                    leader.RemoveLastVertex();
                }

                Point3d lastVertex = leader.VertexAt(leader.NumVertices - 1);
                if (!_mTempPoint.Equals(lastVertex))
                {
                    leader.AppendVertex(_mTempPoint);
                    _mIsJigStarted = true;
                }
            }
            catch (System.Exception ex) {
                BaseObjs.writeDebug(ex.Message + " BB_Jig.cs: line: 81");
            }
            return(true);
        }
Пример #11
0
        /// <summary>
        /// Merge co-linear consecutive segments in a polyline.
        /// This method will automatically remove any zero-length segments as well.
        /// </summary>
        /// <param name="angleTolerance">The angle tolerance between adjacent segments for collinearity test.</param>
        /// <param name="includeSeam">If true, the seam point of a closed polyline will be moved forwards if it is collinear too.</param>
        /// <returns>Number of segments removed from the entire polyline.</returns>
        /// <since>6.3</since>
        public int MergeColinearSegments(double angleTolerance, bool includeSeam)
        {
            bool AreColinear(int i0, int i1, int i2)
            {
                Point3d p0 = this[i0];
                Point3d p1 = this[i1];
                Point3d p2 = this[i2];

                // Test for zero length on either side.
                if (p1.Equals(p0) || p1.Equals(p2))
                {
                    return(true);
                }

                // Test for colinearity
                Vector3d t0    = p1 - p0;
                Vector3d t1    = p2 - p1;
                double   angle = Vector3d.VectorAngle(t0, t1);

                if (angle <= angleTolerance)
                {
                    return(true);
                }
                return(false);
            }

            int beforeCount = SegmentCount;

            if (beforeCount < 2)
            {
                return(0);
            }

            // Remove interior vertices.
            for (int i = beforeCount - 1; i > 0; i--)
            {
                if (AreColinear(i - 1, i, i + 1))
                {
                    RemoveAt(i);
                }
            }

            // Iteratively remove seam, by removing the first point and
            // setting the last point equal to the new startpoint.
            if (includeSeam && IsClosed)
            {
                while (true)
                {
                    // The entire polyline has collapsed, which is what inevitably happens
                    // for closed curves that have a high enough angle tolerance.
                    int n = Count;
                    if (n <= 1)
                    {
                        Clear();
                        break;
                    }

                    if (AreColinear(n - 2, 0, 1))
                    {
                        RemoveAt(0);
                        this[n - 2] = this[0];
                    }
                    else
                    {
                        break;
                    }
                }
            }

            int afterCount = SegmentCount;

            return(beforeCount - afterCount);
        }
        //------------------------------------------------------------------------//
        //
        public static void Zoom(Point3d pMin, Point3d pMax, Point3d pCenter, double dFactor)
        {
            // Get de current document and database
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            int nCurVport = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

            // Get the extents of the current space no points
            // or only a center point is provided.
            //Check to see if Model space is current
            if (acCurDb.TileMode)
            {
                if (pMin.Equals(new Point3d()) && pMax.Equals(new Point3d()))
                {
                    pMin = acCurDb.Extmin;
                    pMax = acCurDb.Extmax;
                }
            }
            else
            {
                // Check to see if Paper space is current
                if (nCurVport == 1)
                {
                    // Get the extents of Papers space
                    if (pMin.Equals(new Point3d()) && pMax.Equals(new Point3d()))
                    {
                        pMin = acCurDb.Pextmin;
                        pMax = acCurDb.Pextmax;
                    }
                }
                else
                {
                    // Get the extents of Model space
                    if (pMin.Equals(new Point3d()) && pMax.Equals(new Point3d()))
                    {
                        pMin = acCurDb.Extmin;
                        pMax = acCurDb.Extmax;
                    }
                }
            }

            // Start transation
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Get the current view
                using (ViewTableRecord acView = acDoc.Editor.GetCurrentView())
                {
                    // Translate WCS coordinates to DCS
                    Matrix3d matWCS2DCS;
                    matWCS2DCS = Matrix3d.PlaneToWorld(acView.ViewDirection);
                    matWCS2DCS = Matrix3d.Displacement(acView.Target - Point3d.Origin) * matWCS2DCS;
                    matWCS2DCS = Matrix3d.Rotation(-acView.ViewTwist, acView.ViewDirection, acView.Target) * matWCS2DCS;

                    // If a center point specified, define the min and max
                    // point of extents for Center and Scale modes
                    if (!pCenter.DistanceTo(Point3d.Origin).Equals(0))
                    {
                        pMin = new Point3d(pCenter.X - (acView.Width / 2),
                                           pCenter.Y - (acView.Height / 2), 0);

                        pMax = new Point3d((acView.Width / 2) + pCenter.X,
                                           (acView.Height / 2) + pCenter.Y, 0);
                    }

                    // Create an extents object using a line
                    Line acLine = new Line(pMin, pMax);
                    if (acLine.Bounds != null)
                    {
                        Extents3d eExtents = new Extents3d(acLine.Bounds.Value.MinPoint, acLine.Bounds.Value.MaxPoint);

                        // Calculate the ratio between the width and height of the current View
                        double dViewRatio = (acView.Width / acView.Height);

                        // Transform teh extents of the view
                        matWCS2DCS = matWCS2DCS.Inverse();
                        eExtents.TransformBy(matWCS2DCS);

                        double  dWidth;
                        double  dHeight;
                        Point2d pNewCentPt;

                        // Check see if a center point was provided (Center an dScale modes)
                        if (!pCenter.DistanceTo(Point3d.Origin).Equals(0.0))
                        {
                            dWidth  = acView.Width;
                            dHeight = acView.Height;

                            if (dFactor.Equals(0.0))
                            {
                                pCenter = pCenter.TransformBy(matWCS2DCS);
                            }

                            pNewCentPt = new Point2d(pCenter.X, pCenter.Y);
                        }
                        else // Working in window, Extents and Limits mode
                        {
                            // Calculate the new width and height of current view
                            dWidth  = eExtents.MaxPoint.X - eExtents.MinPoint.X;
                            dHeight = eExtents.MaxPoint.Y - eExtents.MinPoint.Y;

                            //Get te center of the view
                            pNewCentPt = new Point2d(((eExtents.MaxPoint.X + eExtents.MinPoint.X) * 0.5),
                                                     ((eExtents.MaxPoint.Y + eExtents.MinPoint.Y) * 0.5));
                        }

                        // Check to see if the new width fits in current window
                        if (dWidth > (dHeight * dViewRatio))
                        {
                            dHeight = dWidth / dViewRatio;
                        }

                        // Resize and scale the view
                        if (!dFactor.Equals(0.0))
                        {
                            acView.Height = dHeight * dFactor;
                            acView.Width  = dWidth * dFactor;
                        }

                        // Set teh center of the view
                        acView.CenterPoint = pNewCentPt;

                        // Set the current view
                        acDoc.Editor.SetCurrentView(acView);
                    }
                }

                acTrans.Commit();
            }
        }
Пример #13
0
        private static NGonsCore.Graphs.UndirectedGraph LinesToUndirectedGrap(List <Line> lines)
        {
            List <Point3d> pts = new List <Point3d>();

            foreach (Line l in lines)
            {
                pts.Add(l.From);
                pts.Add(l.To);
            }

            //Sorting
            var edges = new List <int>();

            var allPoints = new List <Point3d>(pts); //naked points

            int i = 0;

            while (allPoints.Count != 0)
            {
                Point3d pt = allPoints[0];
                allPoints.RemoveAt(0);


                for (int d = 0; d < pts.Count; d++)
                {
                    if (pt.Equals(pts[d]))
                    {
                        edges.Add(d);
                        break;
                    }
                }

                i++;
            }

            var uniqueVertices = new HashSet <int>(edges).ToList();

            //Creating typological points
            var topologyPoints = new PointCloud();

            foreach (int k in uniqueVertices)
            {
                topologyPoints.Add(pts[k]);
            }

            //var vertices = Enumerable.Range(0, uniqueVertices.Count);

            for (int k = 0; k < uniqueVertices.Count; k++)
            {
                if (uniqueVertices.ElementAt(k) != k)
                {
                    for (int l = 0; l < edges.Count; l++)
                    {
                        if (edges[l] == uniqueVertices[k])
                        {
                            edges[l] = k;
                        }
                    }
                }
            }

            //Create graph
            NGonsCore.Graphs.UndirectedGraph g = new NGonsCore.Graphs.UndirectedGraph(uniqueVertices.Count);

            for (int k = 0; k < uniqueVertices.Count; k++)
            {
                g.InsertVertex(k.ToString());
            }


            for (int k = 0; k < edges.Count; k += 2)
            {
                g.InsertEdge(edges[k].ToString(), edges[k + 1].ToString());
            }

            g.SetAttribute((object)topologyPoints);


            return(g);
        }
Пример #14
0
        /// <summary>
        /// The internal Zoom() method (credit: AutoCAD .NET Developer's Guide).
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="center"></param>
        /// <param name="factor"></param>
        internal static void Zoom(Point3d min, Point3d max, Point3d center, double factor)
        {
            // Get the current document and database
            var document = Application.DocumentManager.MdiActiveDocument;
            var database = document.Database;

            int currentViewport = Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

            // Get the extents of the current space no points
            // or only a center point is provided
            // Check to see if Model space is current
            if (database.TileMode)
            {
                if (min.Equals(new Point3d()) && max.Equals(new Point3d()))
                {
                    min = database.Extmin;
                    max = database.Extmax;
                }
            }
            else
            {
                // Check to see if Paper space is current
                if (currentViewport == 1)
                {
                    // Get the extents of Paper space
                    if (min.Equals(new Point3d()) && max.Equals(new Point3d()))
                    {
                        min = database.Pextmin;
                        max = database.Pextmax;
                    }
                }
                else
                {
                    // Get the extents of Model space
                    if (min.Equals(new Point3d()) && max.Equals(new Point3d()))
                    {
                        min = database.Extmin;
                        max = database.Extmax;
                    }
                }
            }

            // Start a transaction
            using (var trans = database.TransactionManager.StartTransaction())
            {
                // Get the current view
                using (var currentView = document.Editor.GetCurrentView())
                {
                    Extents3d extents;

                    // Translate WCS coordinates to DCS
                    var matWCS2DCS = Matrix3d.PlaneToWorld(currentView.ViewDirection);
                    matWCS2DCS = Matrix3d.Displacement(currentView.Target - Point3d.Origin) * matWCS2DCS;
                    matWCS2DCS = Matrix3d.Rotation(
                        angle: -currentView.ViewTwist,
                        axis: currentView.ViewDirection,
                        center: currentView.Target) * matWCS2DCS;

                    // If a center point is specified, define the min and max
                    // point of the extents
                    // for Center and Scale modes
                    if (center.DistanceTo(Point3d.Origin) != 0)
                    {
                        min = new Point3d(center.X - (currentView.Width / 2), center.Y - (currentView.Height / 2), 0);
                        max = new Point3d((currentView.Width / 2) + center.X, (currentView.Height / 2) + center.Y, 0);
                    }

                    // Create an extents object using a line
                    using (Line line = new Line(min, max))
                    {
                        extents = new Extents3d(line.Bounds.Value.MinPoint, line.Bounds.Value.MaxPoint);
                    }

                    // Calculate the ratio between the width and height of the current view
                    double viewRatio = currentView.Width / currentView.Height;

                    // Tranform the extents of the view
                    matWCS2DCS = matWCS2DCS.Inverse();
                    extents.TransformBy(matWCS2DCS);

                    double  width;
                    double  height;
                    Point2d newCenter;

                    // Check to see if a center point was provided (Center and Scale modes)
                    if (center.DistanceTo(Point3d.Origin) != 0)
                    {
                        width  = currentView.Width;
                        height = currentView.Height;

                        if (factor == 0)
                        {
                            center = center.TransformBy(matWCS2DCS);
                        }

                        newCenter = new Point2d(center.X, center.Y);
                    }
                    else // Working in Window, Extents and Limits mode
                    {
                        // Calculate the new width and height of the current view
                        width  = extents.MaxPoint.X - extents.MinPoint.X;
                        height = extents.MaxPoint.Y - extents.MinPoint.Y;

                        // Get the center of the view
                        newCenter = new Point2d(
                            ((extents.MaxPoint.X + extents.MinPoint.X) * 0.5),
                            ((extents.MaxPoint.Y + extents.MinPoint.Y) * 0.5));
                    }

                    // Check to see if the new width fits in current window
                    if (width > (height * viewRatio))
                    {
                        height = width / viewRatio;
                    }

                    // Resize and scale the view
                    if (factor != 0)
                    {
                        currentView.Height = height * factor;
                        currentView.Width  = width * factor;
                    }

                    // Set the center of the view
                    currentView.CenterPoint = newCenter;

                    // Set the current view
                    document.Editor.SetCurrentView(currentView);
                }

                // Commit the changes
                trans.Commit();
            }
        }
Пример #15
0
 private Point3d AddUniqueVert(Point3d pnt) 
 {
     foreach (Point3d p in m_lstpoints) 
     {
         if (pnt.Equals(p)) // if it's already in the list, return it
             return p;
     }
     m_lstpoints.Add(pnt); // otherwise add it to the list
     return pnt;
 }
Пример #16
0
        /// <summary>
        /// 用来操作当前视图的函数
        /// <param name="pMin"></param>
        /// <param name="pMax"></param>
        /// <param name="pCenter"></param>
        /// <param name="dFactor"></param>
        public static void Zoom(Point3d pMin, Point3d pMax, Point3d pCenter, double dFactor)
        {//获取当前文档及数据库
            Document acDoc     = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb   = acDoc.Database;
            int      nCurVport = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

            //没提供点或只提供了一个中心点时,获取当前空间的范围
            //检查当前空间是否为模型空间
            if (acCurDb.TileMode == true)
            {
                if (pMin.Equals(new Point3d()) == true &&
                    pMax.Equals(new Point3d()) == true)
                {
                    pMin = acCurDb.Extmin;
                    pMax = acCurDb.Extmax;
                }
            }
            else
            {
                //检查当前空间是否为图纸空间
                if (nCurVport == 1)
                {
                    //获取图纸空间范围
                    if (pMin.Equals(new Point3d()) == true &&
                        pMax.Equals(new Point3d()) == true)
                    {
                        pMin = acCurDb.Pextmin;
                        pMax = acCurDb.Pextmax;
                    }
                }
                else
                {
                    //获取模型空间范围
                    if (pMin.Equals(new Point3d()) == true &&
                        pMax.Equals(new Point3d()) == true)
                    {
                        pMin = acCurDb.Extmin;
                        pMax = acCurDb.Extmax;
                    }
                }
            }
            //启动事务
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                //获取当前视图
                using (ViewTableRecord acView = acDoc.Editor.GetCurrentView())
                {
                    Extents3d eExtents;
                    //将WCS坐标变换为DCS坐标
                    Matrix3d matWCS2DCS;
                    matWCS2DCS = Matrix3d.PlaneToWorld(acView.ViewDirection);
                    matWCS2DCS = Matrix3d.Displacement(acView.Target - Point3d.Origin) * matWCS2DCS;
                    matWCS2DCS = Matrix3d.Rotation(-acView.ViewTwist,
                                                   acView.ViewDirection,
                                                   acView.Target) * matWCS2DCS;
                    //如果指定了中心点,就为中心模式和比例模式
                    //设置显示范围的最小点和最大点;
                    if (pCenter.DistanceTo(Point3d.Origin) != 0)
                    {
                        pMin = new Point3d(pCenter.X - (acView.Width / 2),
                                           pCenter.Y - (acView.Height / 2), 0);
                        pMax = new Point3d((acView.Width / 2) + pCenter.X,
                                           (acView.Height / 2) + pCenter.Y, 0);
                    }
                    //用直线创建范围对象;
                    using (Line acLine = new Line(pMin, pMax))
                    {
                        eExtents = new Extents3d(acLine.Bounds.Value.MinPoint,
                                                 acLine.Bounds.Value.MaxPoint);
                    }
                    //计算当前视图的宽高比
                    double dViewRatio;
                    dViewRatio = (acView.Width / acView.Height);
                    //变换视图范围
                    matWCS2DCS = matWCS2DCS.Inverse();
                    eExtents.TransformBy(matWCS2DCS);
                    double  dWidth;
                    double  dHeight;
                    Point2d pNewCentPt;
                    //检查是否提供了中心点(中心模式和比例模式)
                    if (pCenter.DistanceTo(Point3d.Origin) != 0)
                    {
                        dWidth  = acView.Width;
                        dHeight = acView.Height;
                        if (dFactor == 0)
                        {
                            pCenter = pCenter.TransformBy(matWCS2DCS);
                        }
                        pNewCentPt = new Point2d(pCenter.X, pCenter.Y);
                    }
                    else //窗口、范围和界限模式下
                    {
                        //计算当前视图的宽高新值;
                        dWidth  = eExtents.MaxPoint.X - eExtents.MinPoint.X;
                        dHeight = eExtents.MaxPoint.Y - eExtents.MinPoint.Y;
                        //获取视图中心点
                        pNewCentPt = new Point2d(((eExtents.MaxPoint.X + eExtents.MinPoint.X) * 0.5),
                                                 ((eExtents.MaxPoint.Y + eExtents.MinPoint.Y) * 0.5));
                    }
                    //检查宽度新值是否适于当前窗口
                    if (dWidth > (dHeight * dViewRatio))
                    {
                        dHeight = dWidth / dViewRatio;
                    }
                    //调整视图大小;
                    if (dFactor != 0)
                    {
                        acView.Height = dHeight * dFactor;
                        acView.Width  = dWidth * dFactor;
                    }
                    //设置视图中心;
                    acView.CenterPoint = pNewCentPt;
                    //更新当前视图;
                    acDoc.Editor.SetCurrentView(acView);
                }
                //提交更改;
                acTrans.Commit();
            }
        }
Пример #17
0
        internal static void Zoom(Point3d min, Point3d max, Point3d center, double factor)
        {
            // Mevcut belgeyi ve veritabanını alın
            var document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            var database = document.Database;

            int currentViewport = Convert.ToInt32(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("CVPORT"));

            // Mevcut boşluğun kapsamını alın nokta yok veya sadece bir merkez noktası sağlanmış Model uzayının güncel olup olmadığını kontrol edin
            if (database.TileMode)
            {
                if (min.Equals(new Point3d()) && max.Equals(new Point3d()))
                {
                    min = database.Extmin;
                    max = database.Extmax;
                }
            }
            else
            {
                //Kağıt alanının mevcut olup olmadığını kontrol edin
                if (currentViewport == 1)
                {
                    // Kağıt alanının kapsamını alın
                    if (min.Equals(new Point3d()) && max.Equals(new Point3d()))
                    {
                        min = database.Pextmin;
                        max = database.Pextmax;
                    }
                }
                else
                {
                    // Model alanının kapsamlarını öğrenin
                    if (min.Equals(new Point3d()) && max.Equals(new Point3d()))
                    {
                        min = database.Extmin;
                        max = database.Extmax;
                    }
                }
            }

            // Bir işlem başlatın
            using (var trans = database.TransactionManager.StartTransaction())
            {
                // Mevcut görünümü alın
                using (var currentView = document.Editor.GetCurrentView())
                {
                    Extents3d extents;

                    // WCS koordinatlarını DCS'ye çevir
                    var matWCS2DCS = Matrix3d.PlaneToWorld(currentView.ViewDirection);
                    matWCS2DCS = Matrix3d.Displacement(currentView.Target - Point3d.Origin) * matWCS2DCS;
                    matWCS2DCS = Matrix3d.Rotation(
                        angle: -currentView.ViewTwist,
                        axis: currentView.ViewDirection,
                        center: currentView.Target) * matWCS2DCS;

                    /* Bir merkez noktası belirtilmişse, minimum ve maks.
                     * kapsam noktası
                     * Merkez ve Ölçek modları için*/
                    if (center.DistanceTo(Point3d.Origin) != 0)
                    {
                        min = new Point3d(center.X - (currentView.Width / 2), center.Y - (currentView.Height / 2), 0);
                        max = new Point3d((currentView.Width / 2) + center.X, (currentView.Height / 2) + center.Y, 0);
                    }

                    // Bir çizgi kullanarak bir kapsam nesnesi oluşturun
                    using (Line line = new Line(min, max))
                    {
                        extents = new Extents3d(line.Bounds.Value.MinPoint, line.Bounds.Value.MaxPoint);
                    }

                    // Calculate the ratio between the width and height of the current view
                    double viewRatio = currentView.Width / currentView.Height;

                    // Tranform the extents of the view
                    matWCS2DCS = matWCS2DCS.Inverse();
                    extents.TransformBy(matWCS2DCS);

                    double  width;
                    double  height;
                    Point2d newCenter;

                    // Check to see if a center point was provided (Center and Scale modes)
                    if (center.DistanceTo(Point3d.Origin) != 0)
                    {
                        width  = currentView.Width;
                        height = currentView.Height;

                        if (factor == 0)
                        {
                            center = center.TransformBy(matWCS2DCS);
                        }

                        newCenter = new Point2d(center.X, center.Y);
                    }
                    else // Working in Window, Extents and Limits mode
                    {
                        // Calculate the new width and height of the current view
                        width  = extents.MaxPoint.X - extents.MinPoint.X;
                        height = extents.MaxPoint.Y - extents.MinPoint.Y;

                        // Get the center of the view
                        newCenter = new Point2d(
                            ((extents.MaxPoint.X + extents.MinPoint.X) * 0.5),
                            ((extents.MaxPoint.Y + extents.MinPoint.Y) * 0.5));
                    }

                    // Check to see if the new width fits in current window
                    if (width > (height * viewRatio))
                    {
                        height = width / viewRatio;
                    }

                    // Resize and scale the view
                    if (factor != 0)
                    {
                        currentView.Height = height * factor;
                        currentView.Width  = width * factor;
                    }

                    // Set the center of the view
                    currentView.CenterPoint = newCenter;

                    // Set the current view
                    document.Editor.SetCurrentView(currentView);
                }

                // Commit the changes
                trans.Commit();
            }
        }
Пример #18
0
 public bool Equals(Panel other)
 {
     return(_insPt.Equals(other._insPt));
 }
Пример #19
0
        Zoom(Point3d pnt3dMin, Point3d pnt3dMax, Point3d pnt3dCen, double scaleFactor)
        {
            Document doc = BaseObjs._acadDoc;
            Database db  = doc.Database;

            int nCurVport = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

            if (db.TileMode == true)
            {
                if (pnt3dMin.Equals(new Point3d()) && pnt3dMax.Equals(new Point3d()))
                {
                    pnt3dMin = db.Extmin;
                    pnt3dMax = db.Extmax;
                }
            }
            else
            {
                if (nCurVport == 1)
                {
                    if (pnt3dMin.Equals(new Point3d()) && pnt3dMax.Equals(new Point3d()))
                    {
                        pnt3dMin = db.Pextmin;
                        pnt3dMax = db.Pextmax;
                    }
                }
                else
                {
                    if (pnt3dMin.Equals(new Point3d()) && pnt3dMax.Equals(new Point3d()))
                    {
                        pnt3dMin = db.Extmin;
                        pnt3dMax = db.Extmax;
                    }
                }
            }

            using (var tr = BaseObjs.startTransactionDb()){
                using (var acView = doc.Editor.GetCurrentView()){
                    Extents3d ext3d;
                    Matrix3d  mtxWCS2DCS;
                    mtxWCS2DCS = Matrix3d.PlaneToWorld(acView.ViewDirection);
                    mtxWCS2DCS = Matrix3d.Displacement(acView.Target - Point3d.Origin) * mtxWCS2DCS;
                    mtxWCS2DCS = Matrix3d.Rotation(-acView.ViewTwist, acView.ViewDirection, acView.Target) * mtxWCS2DCS;

                    if (pnt3dCen.DistanceTo(Point3d.Origin) != 0)
                    {
                        pnt3dMin = new Point3d(pnt3dCen.X - (acView.Width / 2),
                                               pnt3dCen.Y - (acView.Height / 2),
                                               0);
                        pnt3dMax = new Point3d(pnt3dCen.X + (acView.Width / 2),
                                               pnt3dCen.Y + (acView.Height / 2),
                                               0);
                    }

                    using (Line line = new Line(pnt3dMin, pnt3dMax)){
                        ext3d = new Extents3d(line.Bounds.Value.MinPoint,
                                              line.Bounds.Value.MaxPoint);
                    }

                    double viewRatio = (acView.Width / acView.Height);
                    mtxWCS2DCS = mtxWCS2DCS.Inverse();
                    ext3d.TransformBy(mtxWCS2DCS);

                    double  width, height;
                    Point2d pnt2dCenNew;

                    if (pnt3dCen.DistanceTo(Point3d.Origin) != 0)
                    {
                        width  = acView.Width;
                        height = acView.Height;

                        if (scaleFactor == 0)
                        {
                            pnt3dCen = pnt3dCen.TransformBy(mtxWCS2DCS);
                        }

                        pnt2dCenNew = new Point2d(pnt3dCen.X, pnt3dCen.Y);
                    }
                    else
                    {
                        width  = ext3d.MaxPoint.X - ext3d.MinPoint.X;
                        height = ext3d.MaxPoint.Y - ext3d.MinPoint.Y;

                        pnt2dCenNew = new Point2d(((ext3d.MaxPoint.X + ext3d.MinPoint.X) / 2),
                                                  ((ext3d.MaxPoint.Y + ext3d.MinPoint.Y) / 2));
                    }

                    if (width > (height * viewRatio))
                    {
                        height = width / viewRatio;
                    }

                    if (scaleFactor != 0)
                    {
                        acView.Height = height * scaleFactor;
                        acView.Width  = width * scaleFactor;
                    }

                    acView.CenterPoint = pnt2dCenNew;

                    doc.Editor.SetCurrentView(acView);
                }
                tr.Commit();
            }
        }
Пример #20
0
        public static void Use(Point3d pMin, Point3d pMax, Point3d pCenter, double dFactor)
        {
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDB = acDoc.Database;

            int nCurVport = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

            if (acCurDB.TileMode == true) //model space
            {
                if (pMin.Equals(new Point3d()) == true && pMax.Equals(new Point3d()) == true)
                {
                    pMin = acCurDB.Extmin; //Get the extends of model space
                    pMax = acCurDB.Extmax;
                }
            }
            else
            {
                if (nCurVport == 1) //paper space
                {
                    if (pMin.Equals(new Point3d()) == true && pMax.Equals(new Point3d()) == true)
                    {
                        pMin = acCurDB.Pextmin; //Get the extends of paper space
                        pMax = acCurDB.Pextmax;
                    }
                }
                else
                {
                    if (pMin.Equals(new Point3d()) == true && pMax.Equals(new Point3d()) == true)
                    {
                        pMin = acCurDB.Extmin; //Get the extends of model space
                        pMax = acCurDB.Extmax;
                    }
                }
            }
            using (Transaction acTrans = acCurDB.TransactionManager.StartTransaction())
            {
                using (ViewTableRecord acView = acDoc.Editor.GetCurrentView())
                {
                    Extents3d eExtents;

                    Matrix3d matWCStoDCS;
                    matWCStoDCS = Matrix3d.PlaneToWorld(acView.ViewDirection);
                    matWCStoDCS = Matrix3d.Displacement(acView.Target - Point3d.Origin) * matWCStoDCS;
                    matWCStoDCS = Matrix3d.Rotation(-acView.ViewTwist, acView.ViewDirection, acView.Target) * matWCStoDCS;

                    if (pCenter.DistanceTo(Point3d.Origin) != 0)
                    {
                        pMin = new Point3d(pCenter.X - (acView.Width / 2), pCenter.Y - (acView.Height / 2), 0);
                        pMax = new Point3d((acView.Width / 2) + pCenter.X, (acView.Height / 2) + pCenter.Y, 0);
                    }
                    using (Line acLine = new Line(pMin, pMax))
                    {
                        eExtents = new Extents3d(acLine.Bounds.Value.MinPoint, acLine.Bounds.Value.MaxPoint);
                    }
                    double dViewRatio;
                    dViewRatio = (acView.Width / acView.Height);

                    matWCStoDCS = matWCStoDCS.Inverse();
                    eExtents.TransformBy(matWCStoDCS);

                    double  dWidth;
                    double  dHeight;
                    Point2d pNewCentPt;

                    if (pCenter.DistanceTo(Point3d.Origin) != 0)
                    {
                        dWidth  = acView.Width;
                        dHeight = acView.Height;

                        if (dFactor == 0)
                        {
                            pCenter = pCenter.TransformBy(matWCStoDCS);
                        }
                        pNewCentPt = new Point2d(pCenter.X, pCenter.Y);
                    }
                    else
                    {
                        dWidth  = eExtents.MaxPoint.X - eExtents.MinPoint.X;
                        dHeight = eExtents.MaxPoint.Y - eExtents.MinPoint.Y;

                        pNewCentPt = new Point2d((eExtents.MaxPoint.X + eExtents.MinPoint.X) * 0.5, (eExtents.MaxPoint.Y + eExtents.MinPoint.Y) * 0.5);
                    }
                    if (dWidth > (dHeight * dViewRatio))
                    {
                        dHeight = dWidth / dViewRatio;
                    }
                    if (dFactor != 0)
                    {
                        acView.Height = dHeight * dFactor;
                        acView.Width  = dWidth * dFactor;
                    }
                    acView.CenterPoint = pNewCentPt;
                    acDoc.Editor.SetCurrentView(acView);
                }
                acTrans.Commit();
            }
        }
Пример #21
0
        /// <summary>
        /// 视图缩放
        /// </summary>
        /// <param name="ed">命令行对象</param>
        /// <param name="ptMin">要显示区域的左下角点</param>
        /// <param name="ptMax">要显示区域的右上角点</param>
        /// <param name="ptCenter">要显示区域的中心点</param>
        /// <param name="factor">缩放比例</param>
        public static void Zoom(this Editor ed, Point3d ptMin, Point3d ptMax, Point3d ptCenter, double factor)
        {
            Extents3d extents;
            Document  doc    = ed.Document;
            Database  db     = doc.Database;
            int       cvport = Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

            if (db.TileMode == true)
            {
                if (ptMin.Equals(Point3d.Origin) == true && ptMax.Equals(Point3d.Origin) == true)
                {
                    ptMin = db.Extmin;
                    ptMax = db.Extmax;
                }
            }
            else
            {
                if (cvport == 1)
                {
                    if (ptMin.Equals(Point3d.Origin) == true && ptMax.Equals(Point3d.Origin) == true)
                    {
                        ptMin = db.Pextmin;
                        ptMax = db.Pextmax;
                    }
                }
                else
                {
                    if (ptMin.Equals(Point3d.Origin) == true && ptMax.Equals(Point3d.Origin) == true)
                    {
                        ptMin = db.Extmin;
                        ptMax = db.Extmax;
                    }
                }
            }
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                ViewTableRecord view       = ed.GetCurrentView();
                Matrix3d        matWCS2DCS = view.Wcs2Dcs();
                if (ptCenter.DistanceTo(Point3d.Origin) != 0)
                {
                    ptMin = new Point3d(ptCenter.X - view.Width / 2, ptCenter.Y - view.Height / 2, 0);
                    ptMax = new Point3d(ptCenter.X + view.Width / 2, ptCenter.Y + view.Height / 2, 0);
                }
                using (Line line = new Line(ptMin, ptMax))
                {
                    extents = new Extents3d(line.GeometricExtents.MinPoint, line.GeometricExtents.MaxPoint);
                }
                double viewRatio = view.Width / view.Height;
                extents.TransformBy(matWCS2DCS);
                double  width, height;
                Point2d newCenter;
                if (ptCenter.DistanceTo(Point3d.Origin) != 0)
                {
                    width  = view.Width;
                    height = view.Height;
                    if (factor == 0)
                    {
                        ptCenter = ptCenter.TransformBy(matWCS2DCS);
                    }
                    newCenter = new Point2d(ptCenter.X, ptCenter.Y);
                }
                else
                {
                    width     = extents.MaxPoint.X - extents.MinPoint.X;
                    height    = extents.MaxPoint.Y - extents.MinPoint.Y;
                    newCenter = new Point2d((extents.MaxPoint.X + extents.MinPoint.X) * 0.5, (extents.MaxPoint.Y + extents.MinPoint.Y) * 0.5);
                }
                if (width > height * viewRatio)
                {
                    height = width / viewRatio;
                }
                if (factor != 0)
                {
                    view.Height = height * factor;
                    view.Width  = width * factor;
                }
                view.CenterPoint = newCenter;
                ed.SetCurrentView(view);
                trans.Commit();
            }
        }
Пример #22
0
        public static void TXZoom(Point3d pMin, Point3d pMax, Point3d pCenter, double dFactor)
        {
            //  获得当前文档和数据库   Get the current document and database
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            int nCurVport = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

            // Get the extents of the current space no points
            // or only a center point is provided
            // 检查当前是否是模型空间  Check to see if Model space is current
            if (acCurDb.TileMode == true)
            {
                if (pMin.Equals(new Point3d()) == true &&
                    pMax.Equals(new Point3d()) == true)
                {
                    pMin = acCurDb.Extmin;
                    pMax = acCurDb.Extmax;
                }
            }
            else
            {
                // 检查当前是否是图纸空间  Check to see if Paper space is current
                if (nCurVport == 1)
                {
                    // Get the extents of Paper space
                    if (pMin.Equals(new Point3d()) == true &&
                        pMax.Equals(new Point3d()) == true)
                    {
                        pMin = acCurDb.Pextmin;
                        pMax = acCurDb.Pextmax;
                    }
                }
                else
                {
                    // 获得模型空间的范围  Get the extents of Model space
                    if (pMin.Equals(new Point3d()) == true &&
                        pMax.Equals(new Point3d()) == true)
                    {
                        pMin = acCurDb.Extmin;
                        pMax = acCurDb.Extmax;
                    }
                }
            }

            // 启动一个事务  Start a transaction
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Get the current view
                using (ViewTableRecord acView = acDoc.Editor.GetCurrentView())
                {
                    Extents3d eExtents;

                    // Translate WCS coordinates to DCS
                    Matrix3d matWCS2DCS;
                    matWCS2DCS = Matrix3d.PlaneToWorld(acView.ViewDirection);
                    matWCS2DCS = Matrix3d.Displacement(acView.Target - Point3d.Origin) * matWCS2DCS;
                    matWCS2DCS = Matrix3d.Rotation(-acView.ViewTwist,
                                                   acView.ViewDirection,
                                                   acView.Target) * matWCS2DCS;

                    // If a center point is specified, define the min and max
                    // point of the extents
                    // for Center and Scale modes
                    if (pCenter.DistanceTo(Point3d.Origin) != 0)
                    {
                        pMin = new Point3d(pCenter.X - (acView.Width / 2),
                                           pCenter.Y - (acView.Height / 2), 0);

                        pMax = new Point3d((acView.Width / 2) + pCenter.X,
                                           (acView.Height / 2) + pCenter.Y, 0);
                    }

                    // 使用一个直线创建一个范围对象 译者注:此处可能有错误,因为直线只有GeometricExtents属性表示范围  Create an extents object using a line
                    using (Line acLine = new Line(pMin, pMax))
                    {
                        eExtents = new Extents3d(pMin,
                                                 pMax);
                    }

                    // 计算当前视图的宽度与高度的比率  Calculate the ratio between the width and height of the current view
                    double dViewRatio;
                    dViewRatio = (acView.Width / acView.Height);

                    // 转换视图的范围  Tranform the extents of the view
                    matWCS2DCS = matWCS2DCS.Inverse();
                    eExtents.TransformBy(matWCS2DCS);

                    double  dWidth;
                    double  dHeight;
                    Point2d pNewCentPt;

                    // 检查中心点是否已提供(中心和缩放模式)  Check to see if a center point was provided (Center and Scale modes)
                    if (pCenter.DistanceTo(Point3d.Origin) != 0)
                    {
                        dWidth  = acView.Width;
                        dHeight = acView.Height;

                        if (dFactor == 0)
                        {
                            pCenter = pCenter.TransformBy(matWCS2DCS);
                        }

                        pNewCentPt = new Point2d(pCenter.X, pCenter.Y);
                    }
                    else // 配合窗口、范围和界限模式计算当前视图新的宽度和高度  Working in Window, Extents and Limits mode
                    {
                        // Calculate the new width and height of the current view
                        dWidth  = eExtents.MaxPoint.X - eExtents.MinPoint.X;
                        dHeight = eExtents.MaxPoint.Y - eExtents.MinPoint.Y;

                        // 获得视图的中心点  Get the center of the view
                        pNewCentPt = new Point2d(((eExtents.MaxPoint.X + eExtents.MinPoint.X) * 0.5),
                                                 ((eExtents.MaxPoint.Y + eExtents.MinPoint.Y) * 0.5));
                    }

                    // 检查新的宽度是否适合当前窗口 Check to see if the new width fits in current window
                    if (dWidth > (dHeight * dViewRatio))
                    {
                        dHeight = dWidth / dViewRatio;
                    }

                    // 调整大小并缩放视图  Resize and scale the view
                    if (dFactor != 0)
                    {
                        acView.Height = dHeight * dFactor;
                        acView.Width  = dWidth * dFactor;
                    }

                    // Set the center of the view
                    acView.CenterPoint = pNewCentPt;

                    // Set the current view
                    acDoc.Editor.SetCurrentView(acView);
                }

                // Commit the changes
                acTrans.Commit();
            }
        }