Пример #1
0
        public void PickFace()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Database db  = doc.Database;
                Editor   ed  = doc.Editor;

                Utils.Init();
                Utils.ChangeViewStyle("Hidden");

                while (true)
                {
                    //ClearDrawnGraphics();
                    PromptEntityOptions peo = new PromptEntityOptions("\nSelect face of solid:");
                    peo.SetRejectMessage("\nMust be a 3D solid.");
                    peo.AddAllowedClass(typeof(Solid3d), false);
                    PromptEntityResult per = ed.GetEntity(peo);
                    if (per.Status != PromptStatus.OK || per.Status == PromptStatus.Cancel)
                    {
                        Utils.End();
                        break;
                    }

                    Transaction tr = db.TransactionManager.StartTransaction();
                    using (tr)
                    {
                        Solid3d sol = tr.GetObject(per.ObjectId, OpenMode.ForRead) as Solid3d;
                        if (sol != null)
                        {
                            Brep brp = new Brep(sol);
                            using (brp)
                            {
                                // We're going to check interference between our
                                // solid and a line we're creating between the
                                // picked point and the user (we use the view
                                // direction to decide in which direction to
                                // draw the line)

                                Point3d dir = (Point3d)Application.GetSystemVariable("VIEWDIR");
                                Point3d picked = per.PickedPoint, nearerUser = per.PickedPoint - (dir - Point3d.Origin);

                                // Two hits should be enough (in and out)
                                const int numHits = 1;

                                // Create out line
                                Line3d ln   = new Line3d(picked, nearerUser);
                                Hit[]  hits = brp.GetLineContainment(ln, numHits);
                                ln.Dispose();

                                if (hits == null || hits.Length < numHits)
                                {
                                    Utils.End();
                                    return;
                                }

                                // Set the shortest distance to something large
                                // and the index to the first item in the list
                                double shortest = (picked - nearerUser).Length;
                                int    found    = 0;

                                // Loop through and check the distance to the
                                // user (the depth of field).
                                for (int idx = 0; idx < numHits; idx++)
                                {
                                    Hit    hit  = hits[idx];
                                    double dist = (hit.Point - nearerUser).Length;
                                    if (dist < shortest)
                                    {
                                        shortest = dist;
                                        found    = idx;
                                    }
                                }

                                // Once we have the nearest point to the screen,
                                // use that one to get the containing curves
                                //List<Curve3d> curves = new List<Curve3d>();
                                List <Point3d> faceBoundary = new List <Point3d>();

                                if (CheckContainment(ed, brp, hits[found].Point, ref faceBoundary))
                                {
                                    Utils.SetLayer("!FDS_MESH[open]");


                                    //Utils.CreateSurfaceinDB(faceBoundary[0], faceBoundary[1], faceBoundary[0].X, "X");
                                    if (faceBoundary[0].X == faceBoundary[1].X)
                                    {
                                        if (faceBoundary[0].X == sol.GeometricExtents.MinPoint.X)
                                        {
                                            Utils.CreateBox(faceBoundary[0], new Point3d(faceBoundary[1].X - 0.01, faceBoundary[1].Y, faceBoundary[1].Z));
                                        }
                                        else if (faceBoundary[0].X == sol.GeometricExtents.MaxPoint.X)
                                        {
                                            Utils.CreateBox(faceBoundary[0], new Point3d(faceBoundary[1].X + 0.01, faceBoundary[1].Y, faceBoundary[1].Z));
                                        }
                                    }
                                    //Utils.CreateSurfaceinDB(faceBoundary[0], faceBoundary[1], faceBoundary[0].Y, "Y");
                                    else if (faceBoundary[0].Y == faceBoundary[1].Y)
                                    {
                                        if (faceBoundary[0].Y == sol.GeometricExtents.MinPoint.Y)
                                        {
                                            Utils.CreateBox(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y - 0.01, faceBoundary[1].Z));
                                        }
                                        else if (faceBoundary[0].Y == sol.GeometricExtents.MaxPoint.Y)
                                        {
                                            Utils.CreateBox(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y + 0.01, faceBoundary[1].Z));
                                        }
                                    }
                                    if (faceBoundary[0].Z == faceBoundary[1].Z)
                                    {
                                        if (faceBoundary[0].Z == sol.GeometricExtents.MinPoint.Z)
                                        {
                                            Utils.CreateBox(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z - 0.01));
                                        }
                                        else if (faceBoundary[0].Z == sol.GeometricExtents.MaxPoint.Z)
                                        {
                                            Utils.CreateBox(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z + 0.01));
                                        }
                                    }
                                    //    Utils.CreateSurfaceinDB(faceBoundary[0], faceBoundary[1], faceBoundary[0].Z, "Z");
                                    // If we get some back, get drawables for them and
                                    // pass them through to the transient graphics API


                                    //TransientManager tm = TransientManager.CurrentTransientManager;
                                    //IntegerCollection ic = new IntegerCollection();


                                    //foreach (Curve3d curve in curves)
                                    //{
                                    //    ed.WriteMessage("\nCurve start: " + curve.StartPoint.ToString());
                                    //    ed.WriteMessage("\nCurve end: " + curve.EndPoint.ToString());
                                    //    Drawable d = GetDrawable(curve);
                                    //    tm.AddTransient(d, TransientDrawingMode.DirectTopmost, 0, ic);
                                    //    _drawn.Add(d);
                                    //}
                                }
                            }
                        }
                        tr.Commit();
                    }
                }
                Utils.End();
                return;
            }
            catch (System.Exception e)
            {
                ed.WriteMessage("Program error: " + e.ToString());
                Utils.End();
                return;
            }
        }
Пример #2
0
        public void fOPENVISUAL()
        {
            Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                Document doc = acApp.DocumentManager.MdiActiveDocument;
                Database db  = doc.Database;

                Utils.Utils.Init();
                Utils.Utils.ChangeViewStyle("X-Ray");

                while (true)
                {
                    PromptEntityOptions peo = new PromptEntityOptions("\nSelect mesh face:");
                    peo.SetRejectMessage("\nMust be a 3D solid.");
                    peo.AddAllowedClass(typeof(Solid3d), false);
                    PromptEntityResult per = ed.GetEntity(peo);
                    if (per.Status != PromptStatus.OK || per.Status == PromptStatus.Cancel)
                    {
                        Utils.Utils.End();
                        break;
                    }

                    Transaction tr = db.TransactionManager.StartTransaction();
                    using (tr)
                    {
                        Solid3d sol = tr.GetObject(per.ObjectId, OpenMode.ForRead) as Solid3d;
                        if (sol != null)
                        {
                            Brep brp = new Brep(sol);
                            using (brp)
                            {
                                // We're going to check interference between our
                                // solid and a line we're creating between the
                                // picked point and the user (we use the view
                                // direction to decide in which direction to
                                // draw the line)

                                Point3d dir = (Point3d)acApp.GetSystemVariable("VIEWDIR");
                                Point3d picked = per.PickedPoint, nearerUser = per.PickedPoint - (dir - Point3d.Origin);

                                // Two hits should be enough (in and out)
                                const int numHits = 1;

                                // Create out line
                                Line3d ln   = new Line3d(picked, nearerUser);
                                Hit[]  hits = brp.GetLineContainment(ln, numHits);
                                ln.Dispose();

                                if (hits == null || hits.Length < numHits)
                                {
                                    Utils.Utils.End();
                                    return;
                                }

                                // Set the shortest distance to something large
                                // and the index to the first item in the list
                                double shortest = (picked - nearerUser).Length;
                                int    found    = 0;

                                // Loop through and check the distance to the
                                // user (the depth of field).
                                for (int idx = 0; idx < numHits; idx++)
                                {
                                    Hit    hit  = hits[idx];
                                    double dist = (hit.Point - nearerUser).Length;
                                    if (dist < shortest)
                                    {
                                        shortest = dist;
                                        found    = idx;
                                    }
                                }

                                // Once we have the nearest point to the screen,
                                // use that one to get the containing curves
                                //List<Curve3d> curves = new List<Curve3d>();
                                List <Point3d> faceBoundary = new List <Point3d>();

                                if (CheckContainment(ed, brp, hits[found].Point, ref faceBoundary))
                                {
                                    Utils.Layers.SetLayer("!FDS_MESH[open]");

                                    if (faceBoundary[0].X == faceBoundary[1].X)
                                    {
                                        if (faceBoundary[0].X == sol.GeometricExtents.MinPoint.X)
                                        {
                                            Utils.Utils.CreateExtrudedSurface(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z), "!FDS_MESH[open]", 1, 1);
                                        }
                                        else if (faceBoundary[0].X == sol.GeometricExtents.MaxPoint.X)
                                        {
                                            Utils.Utils.CreateExtrudedSurface(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z), "!FDS_MESH[open]", 1, 1);
                                        }
                                    }
                                    else if (faceBoundary[0].Y == faceBoundary[1].Y)
                                    {
                                        if (faceBoundary[0].Y == sol.GeometricExtents.MinPoint.Y)
                                        {
                                            Utils.Utils.CreateExtrudedSurface(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z), "!FDS_MESH[open]", 1, 1);
                                        }
                                        else if (faceBoundary[0].Y == sol.GeometricExtents.MaxPoint.Y)
                                        {
                                            Utils.Utils.CreateExtrudedSurface(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z), "!FDS_MESH[open]", 1, 1);
                                        }
                                    }
                                    if (faceBoundary[0].Z == faceBoundary[1].Z)
                                    {
                                        if (faceBoundary[0].Z == sol.GeometricExtents.MinPoint.Z)
                                        {
                                            Utils.Utils.CreateExtrudedSurface(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z), "!FDS_MESH[open]", 1, 1);
                                        }
                                        else if (faceBoundary[0].Z == sol.GeometricExtents.MaxPoint.Z)
                                        {
                                            Utils.Utils.CreateExtrudedSurface(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z), "!FDS_MESH[open]", 1, 1);
                                        }
                                    }
                                }
                            }
                        }
                        tr.Commit();
                    }
                }
                Utils.Utils.End();
                Utils.Utils.ChangeViewStyle("2dWireframe");
                return;
            }
            catch (System.Exception e)
            {
                ed.WriteMessage("Program error: " + e.ToString());
                Utils.Utils.End();
                return;
            }
        }