Exemplo n.º 1
0
        /// <summary>
        /// select a SketchLine and SketchCircle and get  intersect points of LineSegment and circle
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button1_Click(object sender, EventArgs e)
        {
            if (((mApp.ActiveDocument != null)))
            {
                if ((mApp.ActiveDocument.DocumentType == DocumentTypeEnum.kPartDocumentObject))
                {
                    PartDocument oDoc = mApp.ActiveDocument as PartDocument;

                    if ((oDoc.SelectSet.Count == 2))
                    {
                        if (((oDoc.SelectSet[1]) is SketchLine & (oDoc.SelectSet[2]) is SketchCircle))
                        {
                            SketchLine   oSketchLine   = oDoc.SelectSet[1] as SketchLine;
                            SketchCircle oSketchCircle = oDoc.SelectSet[2] as SketchCircle;

                            LineSegment2d oLineSeg2d = oSketchLine.Geometry;
                            Circle2d      oCircle2d  = oSketchCircle.Geometry;

                            ObjectsEnumerator objectsEnum = oLineSeg2d.IntersectWithCurve(oCircle2d, 0.0001);

                            if ((objectsEnum == null))
                            {
                                System.Windows.Forms.MessageBox.Show("No physical intersection between Line and Circle");
                                return;
                            }

                            string strResult = "Intersection point(s): \n";

                            int i = 0;
                            for (i = 1; i <= objectsEnum.Count; i++)
                            {
                                Point2d oPoint = objectsEnum[i] as Point2d;
                                strResult += "[" + oPoint.X.ToString("F2") + ", " + oPoint.Y.ToString("F2") + "] \n";
                            }

                            System.Windows.Forms.MessageBox.Show(strResult, "BRep Sample");
                            return;
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show("Entity 1 must be a SketchLine, Entity 2 must be a SketchCircle", "BRep Sample");
                            return;
                        }
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("Incorrect selection of sketch entities", "BRep Sample");
                        return;
                    }
                }
            }
        }