Esempio n. 1
0
        public override DBObject DeepClone(
            DBObject dbObject, DBObject ownerObject,
            IdMapping idMap, bool isPrimary
            )
        {
            // First we deep clone the object via the parent

            DBObject res =
                base.DeepClone(dbObject, ownerObject, idMap, isPrimary);

            // Then we check for our XData

            if (PipeDrawOverrule.PipeRadiusForObject(res) > 0.0)
            {
                // A transaction is needed by the set function to access
                // the RegApp table - we could also assume the app name
                // is registered and have a separate implementation
                // not taking the transaction...
                // Just as we might also have chosen to remove the XData

                Transaction tr =
                    dbObject.Database.TransactionManager.StartTransaction();
                using (tr)
                {
                    PipeDrawOverrule.SetPipeRadiusOnObject(tr, res, 0.0);
                    tr.Commit();
                }
            }
            return(res);
        }
Esempio n. 2
0
        public override void Explode(Entity e, DBObjectCollection objs)
        {
            double radius = 0.0;

            if (e is DBObject)
            {
                radius = PipeDrawOverrule.PipeRadiusForObject(e);
            }

            if (radius > 0.0)
            {
                Line line = e as Line;

                if (line != null)
                {
                    if (!line.Id.IsNull && line.Length > 0.0)
                    {
                        // Draw a pipe around the line

                        Circle clr =
                            new Circle(
                                line.StartPoint,
                                line.EndPoint - line.StartPoint,
                                radius
                                );
                        ExtrudedSurface pipe = new ExtrudedSurface();
                        try
                        {
                            pipe.CreateExtrudedSurface(
                                clr, line.EndPoint - line.StartPoint, sweepOpts
                                );
                        }
                        catch
                        {
                            Document doc =
                                Application.DocumentManager.MdiActiveDocument;
                            doc.Editor.WriteMessage(
                                "\nFailed with CreateExtrudedSurface."
                                );
                        }
                        clr.Dispose();
                        objs.Add(pipe);
                    }
                    return;
                }
            }
            base.Explode(e, objs);
        }
Esempio n. 3
0
        public override void Explode(Entity e, DBObjectCollection objs)
        {
            double radius = 0.0;

            if (e is DBObject)
            {
                radius = PipeDrawOverrule.PipeRadiusForObject(e);
            }

            if (radius > 0.0)
            {
                Circle circle = e as Circle;

                if (circle != null)
                {
                    // Needed to avoid ill-formed swept surface

                    if (circle.Radius > radius)
                    {
                        // Draw a pipe around the cirle

                        Vector3d normal =
                            (circle.Center - circle.StartPoint).
                            CrossProduct(circle.Normal);
                        Circle clr =
                            new Circle(
                                circle.StartPoint, normal, radius
                                );
                        SweptSurface pipe = new SweptSurface();
                        pipe.CreateSweptSurface(clr, circle, sweepOpts);
                        clr.Dispose();
                        objs.Add(pipe);
                    }
                    return;
                }
            }
            base.Explode(e, objs);
        }
Esempio n. 4
0
        public void MakePipe()
        {
            Document doc =
                Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor   ed = doc.Editor;

            // Ask the user to select the entities to make into pipes

            PromptSelectionOptions pso =
                new PromptSelectionOptions();

            pso.AllowDuplicates  = false;
            pso.MessageForAdding =
                "\n选择对象变为管道: ";

            PromptSelectionResult selRes =
                doc.Editor.GetSelection(pso);

            // If the user didn't make valid selection, we return

            if (selRes.Status != PromptStatus.OK)
            {
                return;
            }

            SelectionSet ss = selRes.Value;

            // Ask the user for the pipe radius to set

            PromptDoubleOptions pdo =
                new PromptDoubleOptions(
                    "\n指定管道半径:"
                    );

            // Use the previous value, if if already called

            if (_radius > 0.0)
            {
                pdo.DefaultValue    = _radius;
                pdo.UseDefaultValue = true;
            }
            pdo.AllowNegative = false;
            pdo.AllowZero     = false;

            PromptDoubleResult pdr =
                ed.GetDouble(pdo);

            // Return if something went wrong

            if (pdr.Status != PromptStatus.OK)
            {
                return;
            }

            // Set the "last radius" value for when
            // the command is called next

            _radius = pdr.Value;

            // Use a transaction to edit our various objects

            Transaction tr =
                db.TransactionManager.StartTransaction();

            using (tr)
            {
                // Loop through the selected objects

                foreach (SelectedObject o in ss)
                {
                    // We could choose only to add XData to the objects
                    // we know will use it (Lines and Circles, for now)

                    DBObject obj =
                        tr.GetObject(o.ObjectId, OpenMode.ForWrite);
                    PipeDrawOverrule.SetPipeRadiusOnObject(tr, obj, _radius);
                }
                tr.Commit();
            }
        }