Ejemplo n.º 1
0
            public List <Entity> Explode()
            {
                List <Entity> inMemorySet = new List <Entity>();

                inMemorySet.Add((Entity)_pline.Clone());
                inMemorySet.Add((Entity)_text.Clone());

                return(inMemorySet);
            }
Ejemplo n.º 2
0
        public static Rectangle3d?GetTextBoxCorners(this DBText text)
        {
            if (!text.Bounds.HasValue)
            {
                return(null);
            }
            DBText cloneText = (DBText)text.Clone();

            Matrix3d mat = Matrix3d.Identity;

            mat = mat.PreMultiplyBy(Matrix3d.Rotation(-text.Rotation, text.Normal, text.Position));

            cloneText.TransformBy(mat);
            cloneText.AdjustAlignment(Tools.GetAcadDatabase());
            if (!cloneText.Bounds.HasValue)
            {
                return(null);
            }

            Extents3d bounds = cloneText.Bounds.Value;

            Point3d min = bounds.MinPoint;
            Point3d max = bounds.MaxPoint;

#if DEBUG1
            if (min.X >= max.X)
            {
                System.Diagnostics.Debugger.Break();
            }
#endif
            Vector3d diametr = max - min;

            //mat = Matrix3d.Identity.PreMultiplyBy(Matrix3d.Rotation(text.Rotation, text.Normal, text.Position));
            mat = mat.Inverse();

            Point3d upperLeft  = new Point3d(min.X, min.Y + diametr.Y, min.Z).TransformBy(mat);
            Point3d upperRight = max.TransformBy(mat);
            Point3d lowerLeft  = min.TransformBy(mat);
            Point3d lowerRight = new Point3d(max.X, max.Y - diametr.Y, max.Z).TransformBy(mat);

            Rectangle3d rec = new Rectangle3d(upperLeft, upperRight, lowerLeft, lowerRight);

#if DEBUG1
            if (rec.LowerLeft.X >= rec.UpperRight.X)
            {
                System.Diagnostics.Debugger.Break();
            }
#endif

            return(rec);
        }
Ejemplo n.º 3
0
        public void TextMirror()
        {
            Matrix3d ucs = CoordinateSystem.CoordinateTools.GetCurrentUcs();

            DBText text = new DBText();

            text.TextString     = "Test";
            text.Position       = new Point3d(0, 0, 0);
            text.HorizontalMode = TextHorizontalMode.TextMid;
            text.VerticalMode   = TextVerticalMode.TextBase;
            text.AlignmentPoint = text.Position;
            text.Rotation       = Math.PI / 4d;

            Tools.AppendEntityEx(text);

            Polyline pline = null;

            Tools.StartTransaction(() =>
            {
                text = text.Id.GetObjectForRead <DBText>();
                Rectangle3d?bounds = text.GetTextBoxCorners();

                if (bounds.HasValue)
                {
                    pline = new Polyline(5);
                    pline.AddVertexAt(0, bounds.Value.LowerLeft);
                    pline.AddVertexAt(1, bounds.Value.UpperLeft);
                    pline.AddVertexAt(2, bounds.Value.UpperRight);
                    pline.AddVertexAt(3, bounds.Value.LowerRight);
                    pline.AddVertexAt(4, bounds.Value.LowerLeft);
                }
            });
            if (pline != null)
            {
                Tools.AppendEntityEx(pline);
            }

            DBTextMirroringJig textJig = new DBTextMirroringJig((DBText)text.Clone());

            if (textJig.Run() != PromptStatus.OK)
            {
                return;
            }
        }
Ejemplo n.º 4
0
            private DBText _getMirrorClone()
            {
                var bounds = _text.GetTextBoxCorners();

                if (!bounds.HasValue)
                {
                    return(null);
                }

                Line3d line = new Line3d(_text.Position, _position);

                Matrix3d mat = Matrix3d.Mirroring(line);
                //mat = mat.PreMultiplyBy(Matrix3d.Mirroring(line));

                DBText res = (DBText)_text.Clone();

                res.TransformBy(mat);

                return(res);
            }
Ejemplo n.º 5
0
        public static Extents3d?GetNotRotatedBounds(this DBText text)
        {
            if (!text.Bounds.HasValue)
            {
                return(null);
            }
            DBText cloneText = (DBText)text.Clone();

            Matrix3d mat = Matrix3d.Identity;

            mat = mat.PreMultiplyBy(Matrix3d.Rotation(-text.Rotation, text.Normal, text.Position));

            cloneText.TransformBy(mat);
            cloneText.AdjustAlignment(Tools.GetAcadDatabase());
            if (!cloneText.Bounds.HasValue)
            {
                return(null);
            }

            Extents3d bounds = cloneText.Bounds.Value;

            return(bounds);
        }
Ejemplo n.º 6
0
        void MirrorText(DBText ent, Line3d mirrorLine)

        {
            Database db = ent.ObjectId.Database;



            using (Transaction tr = db.TransactionManager.StartTransaction())

            {
                // Get text entity

                DBText dbText = tr.GetObject(ent.ObjectId, OpenMode.ForRead)

                                as DBText;



                // Clone original entity

                DBText mirroredTxt = dbText.Clone() as DBText;



                // Create a mirror matrix

                Matrix3d mirrorMatrix = Matrix3d.Mirroring(mirrorLine);



                // Do a geometric mirror on the cloned text

                mirroredTxt.TransformBy(mirrorMatrix);



                // Get text bounding box

                Point3d pt1, pt2, pt3, pt4;

                GetTextBoxCorners(

                    dbText,

                    out pt1,

                    out pt2,

                    out pt3,

                    out pt4);



                // Get the perpendicular direction to the original text

                Vector3d rotDir =

                    pt4.Subtract(pt1.GetAsVector()).GetAsVector();



                // Get the colinear direction to the original text

                Vector3d linDir =

                    pt3.Subtract(pt1.GetAsVector()).GetAsVector();



                // Compute mirrored directions

                Vector3d mirRotDir = rotDir.TransformBy(mirrorMatrix);

                Vector3d mirLinDir = linDir.TransformBy(mirrorMatrix);



                //Check if we need to mirror in Y or in X

                if (Math.Abs(mirrorLine.Direction.Y) >

                    Math.Abs(mirrorLine.Direction.X))

                {
                    // Handle the case where text is mirrored twice

                    // instead of doing "oMirroredTxt.IsMirroredInX = true"

                    mirroredTxt.IsMirroredInX = !mirroredTxt.IsMirroredInX;

                    mirroredTxt.Position = mirroredTxt.Position + mirLinDir;
                }

                else

                {
                    mirroredTxt.IsMirroredInY = !mirroredTxt.IsMirroredInY;

                    mirroredTxt.Position = mirroredTxt.Position + mirRotDir;
                }



                // Add mirrored text to database

                //btr.AppendEntity(mirroredTxt);

                //tr.AddNewlyCreatedDBObject(mirroredTxt, true);

                //list.Add(mirroredTxt);
                mirroredTxt.ToSpace();
                tr.Commit();
            }
        }